Skip to content

OUIsolutions/MDeclare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

38 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”§ MDeclare

GitHub release (latest by date) GitHub GitHub Repo stars GitHub issues GitHub Downloads C Platform Build Status Code Quality Security Maintenance

A magical C tool that transforms function definitions into header declarations automatically! ✨

Perfect for generating header files, creating APIs, and maintaining clean code structure!


🎯 What is MDeclare? (Super Simple Explanation!)

Imagine you have a recipe book with detailed cooking instructions scattered everywhere. πŸ“š

MDeclare is like a magic tool that:

  1. Reads your detailed recipes (C function definitions) πŸ“–
  2. Creates a quick reference index (header declarations) πŸ—‚οΈ
  3. Gives you a clean table of contents (header file) ✨

πŸ“š In Programming Terms:

If you have C code with functions like:

  • int add(int a, int b) { return a + b; }
  • void print_hello() { printf("Hello!"); }
  • double calculate_area(double radius) { return 3.14 * radius * radius; }

MDeclare transforms ALL of these into clean header declarations! πŸŽ‰

πŸ€” Why is this AMAZING for beginners?

βœ… AUTOMATIC Header Generation

  • Before: Manually write declarations for every function 😰
  • After: One command creates all your headers automatically! πŸš€

βœ… NO More Copy-Paste Errors

  • Before: Copy function signature, forget to add semicolon, mess up types...
  • After: Perfect declarations every time! ✨

βœ… Perfect for Learning

  • Understand the difference between definitions and declarations
  • See clean header structure instantly
  • Learn proper C project organization

βœ… Great for Big Projects

  • Quickly generate headers for entire directories
  • Keep your code organized and professional
  • Easy API documentation generation

🌟 See The Magic In Action!

🎬 BEFORE (Your messy C file):

// calc.c - Basic arithmetic operations
int add(int a, int b) {
    return a + b;
}

// subtract two integers
int subtract(int a, int b) {
    return a - b;
}

// perform basic arithmetic operations
int multiply(int a, int b) {
    return a * b;
}

int divide(int a, int b) {
    if (b == 0) {
        fprintf(stderr, "Error: Division by zero.\n");
        return 0; // or handle error appropriately
    }
    return a / b;
}

πŸͺ„ Run the magic command:

mdeclare calc.c -o calc.h

πŸŽ‰ AFTER (Clean header file):

// calc.c - Basic arithmetic operations
int add(int a, int b);

// subtract two integers
int subtract(int a, int b);
// perform basic arithmetic operations
int multiply(int a, int b);
int divide(int a, int b);

✨ BOOM! Perfect header declarations with comments preserved!


πŸ“₯ Download & Installation

πŸš€ Quick Downloads (Choose Your Platform)

πŸ–₯️ Platform πŸ“¦ Download πŸ“ Description
🐧 Linux MDeclare.out Ready-to-run executable
πŸͺŸ Windows 32-bit MDeclarei32.exe Windows executable
οΏ½ Ubuntu/Debian MDeclare.deb DEB package
οΏ½ RHEL/Fedora MDeclare.rpm RPM package

πŸ§‘β€πŸ’» Developer Resources

πŸ“ File 🎯 Purpose
⚑ MDeclare.c Single-file source code
πŸ“š MDeclareApiOne.c API full for integration
πŸ”§ MDeclareApiNoDependenciesIncluded.h Amalgamator API

⚑ Quick Installation

Linux:

# Download and make executable
curl -L https://github.com/OUIsolutions/MDeclare/releases/download/0.2.0/MDeclare.out -o mdeclare && chmod +x mdeclare

Ubuntu/Debian:

# Install DEB package
wget https://github.com/OUIsolutions/MDeclare/releases/download/0.2.0/MDeclare.deb && sudo dpkg -i MDeclare.deb

πŸƒβ€β™‚οΈ Quick Start Guide (For Total Beginners!)

Don't panic! This is easier than making instant noodles! 🍜

🎬 Step 1: Your First Header Generation (The Basics)

Let's start with the simplest possible example:

# This is THE most basic command you'll ever need!
mdeclare my_functions.c -o my_functions.h

πŸ€” What just happened?

  • my_functions.c β†’ "Hey MDeclare, read this C file!"
  • -o my_functions.h β†’ "Put the header declarations in this file!"

That's it! MDeclare will:

  1. πŸ” Look at my_functions.c
  2. πŸ•΅οΈβ€β™‚οΈ Find all function definitions
  3. πŸ”— Extract the function signatures
  4. πŸ“ Create clean header declarations in my_functions.h

🎬 Step 2: Real-World Example (Let's Do This Together!)

Imagine you have this C file:

math_utils.c:

#include <stdio.h>

// Calculate the square of a number
int square(int x) {
    return x * x;
}

// Check if a number is even
bool is_even(int number) {
    return (number % 2 == 0);
}

// Print a greeting message
void greet_user(const char* name) {
    printf("Hello, %s! Welcome to our program!\n", name);
}

// Calculate factorial recursively
long factorial(int n) {
    if (n <= 1) return 1;
    return n * factorial(n - 1);
}

πŸš€ Generate the header file:

mdeclare math_utils.c -o math_utils.h

πŸŽ‰ BOOM! You get this beautiful header:

math_utils.h:

// Calculate the square of a number
int square(int x);

// Check if a number is even
bool is_even(int number);

// Print a greeting message
void greet_user(const char* name);

// Calculate factorial recursively
long factorial(int n);

Now you can include this header in other files:

#include "math_utils.h"

int main() {
    int result = square(5);
    printf("Square of 5 is: %d\n", result);
    return 0;
}

🎬 Step 3: Generate Headers for Entire Projects!

Got a whole directory of C files? No problem!

# Generate headers for ALL .c files in the src/ directory
mdeclare src/ -o project_headers.h --endswith ".c"

πŸ€” What this does:

  • Looks in the src/ directory
  • Finds all files ending with .c
  • Extracts declarations from ALL of them
  • Puts everything in one project_headers.h file

πŸ“ Example project structure:

my_project/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ calculator.c
β”‚   β”œβ”€β”€ file_utils.c
β”‚   β”œβ”€β”€ string_helpers.c
β”‚   └── math_functions.c
└── headers/

πŸš€ One command generates everything:

mdeclare src/ -o headers/all_functions.h --endswith ".c" --include-path

✨ The --include-path flag adds helpful comments showing which file each function comes from!


βš™οΈ Command-Line Options (All the Cool Features!)

🎯 Beginner Tip: Start with just the basic syntax: mdeclare input.c -o output.h. Learn the other options later!

πŸ”₯ Essential Options (You NEED These!)

🏷️ Flag πŸ“ What It Does 🚨 Required? πŸ’‘ Example
input_file The C file to read βœ… YES mdeclare main.c
-o, --output, --out Where to save the header βœ… YES -o functions.h

πŸ›‘οΈ Filter Options (Control What Gets Processed!)

🏷️ Flag πŸ“ What It Does πŸ’‘ When to Use πŸ’‘ Example
--startswith, --sw Only process files starting with this Filter by filename prefix --startswith "api_"
--endswith, --ew Only process files ending with this Filter by file extension --endswith ".c"
--include-path, --ip Add file path comments Track which file each function comes from --include-path

πŸŽ›οΈ Special Options (For Power Users!)

🏷️ Flag πŸ“ What It Does 🎯 Perfect For πŸ’‘ Example
version, --version, -v Show MDeclare version Checking what version you have mdeclare version

🌟 Real-World Examples:

πŸ₯‡ Beginner Example:

# Just convert one file - simple!
mdeclare calculator.c -o calculator.h

πŸ₯ˆ Intermediate Example:

# Process all C files in a directory with path tracking
mdeclare src/ -o all_headers.h --endswith ".c" --include-path

πŸ₯‰ Advanced Example:

# Process only API files starting with "api_" 
mdeclare src/ -o api_headers.h --startswith "api_" --endswith ".c" --include-path

🚨 Common Beginner Mistakes (And How to Avoid Them!)

❌ DON'T DO THIS:

# Missing output flag - this will fail!
mdeclare main.c

βœ… DO THIS INSTEAD:

# Always include the -o flag
mdeclare main.c -o main.h

❌ DON'T DO THIS:

# Using same name for input and output - BAD!
mdeclare functions.c -o functions.c

βœ… DO THIS INSTEAD:

# Use different names to avoid overwriting
mdeclare functions.c -o functions.h

πŸ§‘β€πŸ’» API Usage (For Programmers Who Want to Integrate!)

🎯 Beginner Note: This section is for people who want to use MDeclare inside their own C programs. If you just want to use the command-line tool, you can skip this section!

πŸš€ Quick Setup (Get the API Library)

Download the API header file:

# Get the complete API (easiest way)
curl -L https://github.com/OUIsolutions/MDeclare/releases/download/0.2.0/MDeclareApiOne.h -o MDeclareApiOne.c

🎬 Simple Example (Transform a Single File!)

Create a file called my_header_generator.c:

#include <stdio.h>
#include <stdlib.h>
#include "MDeclareApiOne.h"

int main() {
    // Example C code with function definitions
    const char *c_code = 
        "// Math utilities\n"
        "int add(int a, int b) {\n"
        "    return a + b;\n"
        "}\n"
        "\n"
        "// String utilities\n"
        "void print_hello() {\n"
        "    printf(\"Hello, World!\\n\");\n"
        "}\n";
    
    // Transform it to header declarations! ✨
    char *header_result = mdeclare_transform_content(c_code);
    
    if (header_result == NULL) {
        printf("❌ Oops! Something went wrong!\n");
        return 1;
    }
    
    // Success! Print the header declarations
    printf("βœ… Success! Here are your header declarations:\n\n%s", header_result);
    
    // Clean up memory (important!)
    free(header_result);
    
    printf("\nπŸŽ‰ All done!\n");
    return 0;
}

Compile and run:

gcc my_header_generator.c -o my_header_generator
./my_header_generator

Expected output:

βœ… Success! Here are your header declarations:

// Math utilities
int add(int a, int b);

// String utilities
void print_hello();

πŸŽ‰ All done!

πŸŽ›οΈ Advanced Example (Process Entire Directories!)

Want to process a whole directory? Here's how:

#include <stdio.h>
#include <stdlib.h>
#include "MDeclareApiOne.h"

int main() {
    // Directory settings
    const char *source_dir = "src/";           // Where your C files are
    bool include_path = true;                  // Add file path comments
    const char *starts_with = NULL;           // Filter: files starting with...
    const char *ends_with = ".c";             // Filter: files ending with...
    
    // Process the entire directory! ✨
    char *result = mdeclare_transform_dir(source_dir, include_path, starts_with, ends_with);
    
    if (result == NULL) {
        printf("❌ Oops! Something went wrong processing the directory!\n");
        return 1;
    }
    
    // Write the result to a file
    FILE *output_file = fopen("headers.h", "w");
    if (output_file == NULL) {
        printf("❌ Failed to create output file!\n");
        free(result);
        return 1;
    }
    fprintf(output_file, "%s", result);
    fclose(output_file);
    
    // Success! Print the combined headers
    printf("βœ… Success! Processed directory '%s'\n", source_dir);
    printf("πŸ“„ Generated headers saved to 'headers.h'\n");
    printf("Preview:\n\n%s", result);
    
    // Clean up memory (important!)
    free(result);
    
    printf("\nπŸŽ‰ Directory processing complete!\n");
    return 0;
}

🎯 API Functions Reference

πŸ”§ Function πŸ“ What It Does πŸ’‘ Example
mdeclare_transform_content(content) Transform C code to header declarations For single files or code strings
mdeclare_transform_dir(dir_path, include_path, starts_with, ends_with) Process entire directories For batch processing multiple files

🚨 Important Notes for Beginners:

  1. Always check for NULL! The API functions can return NULL if something goes wrong.
  2. Don't forget to free memory! Always call free() on the returned strings when done.
  3. Start simple! Use mdeclare_transform_content() first, then try the directory function.

πŸ”¨ Building from Scratch (For Advanced Users!)

🎯 Beginner Note: You don't need this section if you just downloaded the ready-made executables above! This is only for people who want to compile MDeclare themselves.

πŸ“‹ Prerequisites (What You Need First)

You'll need these tools installed:

  1. πŸ¦„ Darwin Build System (Version 0.8.0+)
  2. 🐳 Docker OR πŸ«– Podman (for containerized builds)
  3. 🐧 Linux Environment (recommended)

πŸš€ One-Line Darwin Installation (Linux Only!)

# Install Darwin build system in one command
curl -L https://github.com/OUIsolutions/Darwin/releases/download/0.8.0/darwin.out -o darwin.out && sudo chmod +x darwin.out && sudo mv darwin.out /usr/bin/darwin

πŸ“ Clone and Build

# 1. Clone the repository
git clone https://github.com/OUIsolutions/MDeclare.git
cd MDeclare

# 2. Build all variants (this will take a while!)
darwin run_blueprint build/ --mode folder amalgamation_build alpine_static_build windowsi32_build windowsi64_build rpm_static_build debian_static_build --provider podman

πŸŽ‰ After building, you'll have:

  • Linux executables
  • Windows executables (32-bit and 64-bit)
  • RPM packages
  • DEB packages
  • Static builds
  • And more!

πŸ€” What Gets Built?

πŸ—οΈ Build Target πŸ“ Description 🎯 Output
amalgamation_build Single C file version MDeclare.c
alpine_static_build Static Linux binary Linux executable
windowsi32_build 32-bit Windows .exe file
windowsi64_build 64-bit Windows .exe file
rpm_static_build RPM package .rpm file
debian_static_build Debian package .deb file

🚨 Troubleshooting Common Build Issues

❌ "darwin: command not found"

  • Solution: Make sure Darwin is installed and in your PATH

❌ "Docker/Podman not found"

  • Solution: Install Docker or Podman for containerized builds

❌ "Permission denied"

  • Solution: Make sure you have execute permissions on build scripts

πŸ†˜ Need Help? (We've Got You Covered!)

🀝 Community Support

πŸ“š Common Questions

Q: "Can I use this with C++?" A: MDeclare is designed for C, but it might work with simple C++ code. Try it and see!

Q: "What about very complex function definitions?" A: MDeclare handles most standard C functions. For very complex cases, you might need to manually adjust the output.

Q: "Can I process only specific files in a directory?" A: Yes! Use --startswith and --endswith flags to filter which files get processed.

Q: "Is it safe to use in production?" A: Absolutely! Many developers use MDeclare for generating headers. Just test thoroughly first.


πŸŽ‰ Success Stories & Use Cases

🌟 Perfect For:

  • πŸŽ“ Students: Generate clean headers for assignments and projects
  • πŸ† Professional Development: Maintain consistent API documentation
  • πŸ“¦ Library Creation: Quickly generate header files for C libraries
  • πŸš€ Large Projects: Automatically maintain headers across multiple files
  • πŸ“± Embedded Systems: Clean interface definitions for hardware projects

πŸ’¬ What Users Say:

"MDeclare saved me hours of manually creating header files!" - DevStudent2024

"Perfect for keeping my C projects organized and professional!" - CodeMaster

"Made generating API documentation so much easier!" - LibraryDev


🌟 Ready to Transform Your C Development?

Made with ❀️ by OUIsolutions

Transforming C definitions into perfect headers, one function at a time! ✨

About

Transform every C definition into a headder

Resources

License

Stars

Watchers

Forks

Packages

No packages published