The Error Codes Generator project allows you to define error codes in a structured YAML file and automatically generate corresponding C header files. This ensures consistency and ease of maintenance across your C projects.
- YAML Configuration: Define modules, submodules, and their associated error codes in a readable YAML format.
- Automated Header Generation: Use
parser.py
to parse the YAML file and generateerror_codes.h
. - Example Program: An example C program demonstrates how to utilize the generated error codes.
.
├── error_codes.c
├── error_codes_def.h
├── error_codes.yml
├── example.c
├── LICENSE
├── Makefile
└── parser.py
error_codes.yml
: YAML configuration file defining modules, submodules, and error codes.parser.py
: Python script that parseserror_codes.yml
and generateserror_codes.h
.error_codes.h
: Generated C header file containing defined error codes.error_codes.c
: C source file related to error code handling.example.c
: Example C program demonstrating the usage of error codes.Makefile
: Build script to automate the generation and compilation process.LICENSE
: MIT License file.
- Python 3.x: Required to run
parser.py
. - GCC: C compiler to build the example program.
- Make: Build automation tool.
-
Clone the Repository
git clone https://github.com/fervagar/Error-Codes-Generator.git
-
Ensure
parser.py
is ExecutableIf not already executable, set the appropriate permissions:
chmod +x parser.py
The Makefile automates the process of generating error_codes.h
and compiling the example program.
-
Build the Project
Simply run:
make
This command performs the following:
- Parses
error_codes.yml
usingparser.py
to generateerror_codes.h
. - Compiles
example.c
anderror_codes.c
into theexample
executable.
- Parses
-
Run the Example Program
After a successful build, execute the example program:
./example
Edit the error_codes.yml
file to define your modules, submodules, and error codes. Here's an example structure:
# This YAML file configures modules, their errors, and submodules with their own errors.
modules:
TestMod1:
errors:
E_OPEN_DEV: "Error opening device"
E_CLOSE_DEV: "Error closing device"
submodules:
TestMod1SubMod1:
errors:
E_READ_DEV: "Error reading from device"
E_WRITE_DEV: "Error writing to device"
TestMod2:
errors:
E_INIT_MOD: "Error initializing module"
submodules:
TestMod2SubMod1:
errors:
E_CONFIG_FAIL: "Configuration failure"
After updating error_codes.yml
, rebuild the project to regenerate error_codes.h
:
make
This project is licensed under the MIT License. You are free to use, modify, and distribute this code in both open-source and commercial projects, provided that you preserve the original license and attribution notices.