Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattcrmx/cprotogen
Generate C headers from source file
https://github.com/mattcrmx/cprotogen
generator headers parser
Last synced: about 1 month ago
JSON representation
Generate C headers from source file
- Host: GitHub
- URL: https://github.com/mattcrmx/cprotogen
- Owner: Mattcrmx
- License: mit
- Created: 2024-11-07T14:47:40.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-08T17:17:22.000Z (3 months ago)
- Last Synced: 2024-12-10T08:57:05.136Z (about 1 month ago)
- Topics: generator, headers, parser
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# CProtoGen
A simple Python library and command-line tool for generating C function prototypes from source files.
## Installation
To install it, use pip:
```bash
pip install cprotogen
```## Usage
### Library
You can use the exposed API:
```python
from cprotogen.generator import generate_prototypes# Generate prototypes for multiple files
source_files = ["file1.c", "file2.c", "file3.c"]
for source in source_files:
header = source.replace(".c", ".h")
generate_prototypes(source, header, overwrite=True)
print(f"Updated {header} with prototypes from {source}")
```### As a Command-Line Tool
CProtoGen can be used directly from the command line:
```bash
# Generate prototypes and create/update a header file
cprotogen path/to/source.c --header path/to/header.h# Generate prototypes and overwrite existing header file
cprotogen path/to/source.c --header path/to/existing_header.h --overwrite# Show help
cprotogen -h
```## Examples
### Generating Prototypes for a Simple File
```python
from cprotogen.generator import generate_prototypes# Input file: hello.c
"""
#includevoid hello_world() {
printf("Hello, World!\n");
}
"""# Generate prototypes and create a header file
generate_prototypes("hello.c", "hello.h")# Output file: hello.h
"""
#ifndef HELLO_H
#define HELLO_Hvoid hello_world(void);
#endif // HELLO_H
"""
```### Updating Existing Header with New Function
```python
from cprotogen.generator import generate_prototypes# Updated input file: hello.c
"""
#includevoid hello_world() {
printf("Hello, World!\n");
}int add_numbers(int a, int b) {
return a + b;
}
"""# Generate prototypes and update the header file
generate_prototypes("hello.c", "hello.h", overwrite=True)# Updated output file: hello.h
"""
#ifndef HELLO_H
#define HELLO_Hvoid hello_world(void);
int add_numbers(int a, int b);#endif // HELLO_H
"""
```### Generating Prototypes Without Creating a Header File
```python
from cprotogen.generator import generate_prototypes# Generate prototypes without creating a header file
prototypes = generate_prototypes("hello.c")
print(prototypes)
# Output:
# ['void hello_world(void);\n', 'int add_numbers(int a, int b);\n']
```