A simple Python library and command-line tool for generating C function prototypes from source files.
Project description
CProtoGen
A simple Python library and command-line tool for generating C function prototypes from source files.
Installation
To install it, use pip:
pip install cprotogen
Usage
Library
You can use the exposed API:
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:
# 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
from cprotogen.generator import generate_prototypes
# Input file: hello.c
"""
#include <stdio.h>
void 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_H
void hello_world();
#endif // HELLO_H
"""
Updating Existing Header with New Function
from cprotogen.generator import generate_prototypes
# Updated input file: hello.c
"""
#include <stdio.h>
void 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_H
void hello_world();
int add_numbers(int a, int b);
#endif // HELLO_H
"""
Generating Prototypes Without Creating a Header File
from cprotogen.generator import generate_prototypes
# Generate prototypes without creating a header file
prototypes = generate_prototypes("hello.c")
print(prototypes)
# Output:
# ['void hello_world();\n', 'int add_numbers(int a, int b);\n']
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file cprotogen-0.1.0.tar.gz
.
File metadata
- Download URL: cprotogen-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dabc9b8b7629d21ebaeb40c92ad4b4b1c94f145b72f7334213ae01ec70f5687 |
|
MD5 | 360d1a44a9f220f76dd7d955ab5590bb |
|
BLAKE2b-256 | dbc5b841b1d4b306e8de84601dcd7f7fd8975a96f1920ed2abbfc0d1c2013f50 |
Provenance
The following attestation bundles were made for cprotogen-0.1.0.tar.gz
:
Publisher:
publish.yaml
on Mattcrmx/cprotogen
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
cprotogen-0.1.0.tar.gz
- Subject digest:
4dabc9b8b7629d21ebaeb40c92ad4b4b1c94f145b72f7334213ae01ec70f5687
- Sigstore transparency entry: 147612816
- Sigstore integration time:
- Predicate type:
File details
Details for the file cprotogen-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: cprotogen-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 542b6a347dc30bef197580e5f19ba47bae18bf4c3c0a64dd5ee308991cdb5532 |
|
MD5 | f5fc96d31f27435806989b754e19732b |
|
BLAKE2b-256 | 302eb96005a29a5c103aaff97bd0867de03965810dc259ab48303a38b76a0737 |
Provenance
The following attestation bundles were made for cprotogen-0.1.0-py3-none-any.whl
:
Publisher:
publish.yaml
on Mattcrmx/cprotogen
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
cprotogen-0.1.0-py3-none-any.whl
- Subject digest:
542b6a347dc30bef197580e5f19ba47bae18bf4c3c0a64dd5ee308991cdb5532
- Sigstore transparency entry: 147612818
- Sigstore integration time:
- Predicate type: