Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cprotogen-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cprotogen-0.1.0-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

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

Hashes for cprotogen-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4dabc9b8b7629d21ebaeb40c92ad4b4b1c94f145b72f7334213ae01ec70f5687
MD5 360d1a44a9f220f76dd7d955ab5590bb
BLAKE2b-256 dbc5b841b1d4b306e8de84601dcd7f7fd8975a96f1920ed2abbfc0d1c2013f50

See more details on using hashes here.

Provenance

The following attestation bundles were made for cprotogen-0.1.0.tar.gz:

Publisher: publish.yaml on Mattcrmx/cprotogen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for cprotogen-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 542b6a347dc30bef197580e5f19ba47bae18bf4c3c0a64dd5ee308991cdb5532
MD5 f5fc96d31f27435806989b754e19732b
BLAKE2b-256 302eb96005a29a5c103aaff97bd0867de03965810dc259ab48303a38b76a0737

See more details on using hashes here.

Provenance

The following attestation bundles were made for cprotogen-0.1.0-py3-none-any.whl:

Publisher: publish.yaml on Mattcrmx/cprotogen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page