<img alt="Version" src="https://img.shields.io/badge/version-0.1.0--alpha.2-blue.svg?cacheSeconds=604800" />
<a href="https://gitlab.com/felingineer/cwriter/-/blob/master/LICENSE.txt" target="_blank"><img alt="License:BSD" src="https://img.shields.io/badge/License-BSD-yellow.svg" /></a>
# cwriter
# Project Description
The package facilitates the creation of C (.h) files from Python. It's not designed to generate every possible C file or cover the entire C syntax. Rather, its primary focus is to generate files that contain elements like arrays or strings as well as constants, defines, and typedefs that can be imported from other sources or linked into a project.
# Example
This code
```python
numbers = list(range(100))
f = CFile("example.h")
f.openGuard()
f.define("THIS", 0)
f.newLine()
f.comment("A variable definition with intialization")
an = {5: "This is an annotation for the element at position 5", 30: ("Another annotation, but with single=True for the element at position 30", True)}
f.varDefinition("const int[]", "values", numbers, to_str_fn=paddedHex(2), annotations=an)
f.newLine(2)
f.comment("A variable declaration")
f.varDeclaration("const int", "size", extern=True)
f.newLine()
f.varDeclaration("const int[]", "values")
f.newLine()
f.comment(["Now a multilne", "comment", "here"])
f.newLine()
f.comment("Another comment with a backslash at the end (note the added dot) -> \\")
f.newLine()
f.comment("Another array")
f.varDefinition("const char[]", "other", [1, 2, 3, 4, 5])
f.comment("A variable definition, with extra attributes")
f.varDefinition(["const", "char[]"],
"var_name", "this is a string",
extra_attribs="__attribute__ ((aligned (16)))")
f.closeGuard()
f.print()
f.write()
```
Prints and generates this file
```c
#ifndef EXAMPLE_H_GUARD
#define EXAMPLE_H_GUARD
#define THIS 0
// A variable definition with intialization
const int values[] = {
0x00, 0x01, 0x02, 0x03, 0x04,
// This is an annotation for the element at position 5
0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
// Another annotation, but with single=True for the element at position 30
0x1e,
0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,
0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,
0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,
0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e,
0x5f, 0x60, 0x61, 0x62, 0x63
};
// A variable declaration
extern const int size;
extern const int values[];
/*
* Now a multilne
* comment
* here
*/
// Another comment with a backslash at the end (note the added dot) -> \.
// Another array
const char other[] = {1, 2, 3, 4, 5};
// A variable definition, with extra attributes
const char var_name[] __attribute__ ((aligned (16))) = "this is a string";
#endif /* EXAMPLE_H_GUARD */
```
NOTE: The generated code above is only meant as an example, and doesn't intend to show what should be placed in an .h file.
# Licensing and Copyright
BSD 2-Clause License
Copyright © 2023, Guillermo Romero (Gato)
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/felingineer/cwriter",
"name": "cwriter",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "C,C++,GENERATE",
"author": "Guillermo Romero (Gato)",
"author_email": "gato@felingineering.com",
"download_url": "https://files.pythonhosted.org/packages/11/5b/ad9d921bda3c47e678638fcb74429077a755ace6273d0d9da3aa1b254f80/cwriter-0.1.0a3.tar.gz",
"platform": null,
"description": "<img alt=\"Version\" src=\"https://img.shields.io/badge/version-0.1.0--alpha.2-blue.svg?cacheSeconds=604800\" />\n<a href=\"https://gitlab.com/felingineer/cwriter/-/blob/master/LICENSE.txt\" target=\"_blank\"><img alt=\"License:BSD\" src=\"https://img.shields.io/badge/License-BSD-yellow.svg\" /></a>\n\n# cwriter\n\n# Project Description\nThe package facilitates the creation of C (.h) files from Python. It's not designed to generate every possible C file or cover the entire C syntax. Rather, its primary focus is to generate files that contain elements like arrays or strings as well as constants, defines, and typedefs that can be imported from other sources or linked into a project.\n\n# Example\n\nThis code\n\n```python\n numbers = list(range(100))\n\n f = CFile(\"example.h\")\n\n f.openGuard()\n f.define(\"THIS\", 0)\n f.newLine()\n f.comment(\"A variable definition with intialization\")\n an = {5: \"This is an annotation for the element at position 5\", 30: (\"Another annotation, but with single=True for the element at position 30\", True)}\n f.varDefinition(\"const int[]\", \"values\", numbers, to_str_fn=paddedHex(2), annotations=an)\n f.newLine(2)\n f.comment(\"A variable declaration\")\n f.varDeclaration(\"const int\", \"size\", extern=True)\n f.newLine()\n f.varDeclaration(\"const int[]\", \"values\")\n f.newLine()\n\n f.comment([\"Now a multilne\", \"comment\", \"here\"])\n f.newLine()\n f.comment(\"Another comment with a backslash at the end (note the added dot) -> \\\\\")\n f.newLine()\n f.comment(\"Another array\")\n f.varDefinition(\"const char[]\", \"other\", [1, 2, 3, 4, 5])\n f.comment(\"A variable definition, with extra attributes\")\n f.varDefinition([\"const\", \"char[]\"],\n \"var_name\", \"this is a string\",\n extra_attribs=\"__attribute__ ((aligned (16)))\")\n f.closeGuard()\n\n f.print()\n f.write()\n\n```\n\n\nPrints and generates this file\n```c\n#ifndef EXAMPLE_H_GUARD\n#define EXAMPLE_H_GUARD\n\n#define THIS 0\n\n// A variable definition with intialization\nconst int values[] = {\n 0x00, 0x01, 0x02, 0x03, 0x04,\n // This is an annotation for the element at position 5\n 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,\n 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,\n // Another annotation, but with single=True for the element at position 30\n 0x1e,\n 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e,\n 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e,\n 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e,\n 0x4f, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e,\n 0x5f, 0x60, 0x61, 0x62, 0x63\n };\n\n\n\n// A variable declaration\nextern const int size;\n\nextern const int values[];\n\n/*\n * Now a multilne\n * comment\n * here\n */\n\n// Another comment with a backslash at the end (note the added dot) -> \\.\n\n// Another array\nconst char other[] = {1, 2, 3, 4, 5};\n\n// A variable definition, with extra attributes\nconst char var_name[] __attribute__ ((aligned (16))) = \"this is a string\";\n\n\n#endif /* EXAMPLE_H_GUARD */\n\n```\n\nNOTE: The generated code above is only meant as an example, and doesn't intend to show what should be placed in an .h file.\n \n\n# Licensing and Copyright \n\nBSD 2-Clause License\n\nCopyright \u00a9 2023, Guillermo Romero (Gato)\n\n\n\n\n\n",
"bugtrack_url": null,
"license": "BSD-2-Clause",
"summary": "C/C++ file generator",
"version": "0.1.0a3",
"project_urls": {
"Download": "https://gitlab.com/felingineer/cwriter",
"Homepage": "https://gitlab.com/felingineer/cwriter"
},
"split_keywords": [
"c",
"c++",
"generate"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "18e30a88862d42ab42b1f892f843ebb5bd0dc838d385c84bb413e00d81073096",
"md5": "25b5e4ad9790353f0e88265650aef8a8",
"sha256": "e3f256677db4dc90d781e57fe39121b3adb2d1a9dfd22b62e7e27aa72fa0e210"
},
"downloads": -1,
"filename": "cwriter-0.1.0a3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "25b5e4ad9790353f0e88265650aef8a8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 8743,
"upload_time": "2023-11-15T00:28:32",
"upload_time_iso_8601": "2023-11-15T00:28:32.909393Z",
"url": "https://files.pythonhosted.org/packages/18/e3/0a88862d42ab42b1f892f843ebb5bd0dc838d385c84bb413e00d81073096/cwriter-0.1.0a3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "115bad9d921bda3c47e678638fcb74429077a755ace6273d0d9da3aa1b254f80",
"md5": "e4365bff1f68a7509f90ddc3d8c9dba6",
"sha256": "8b50a68e3e93e782d0a149a691bd7bfda68df4e2ec8e553febe15bb1e4ae8735"
},
"downloads": -1,
"filename": "cwriter-0.1.0a3.tar.gz",
"has_sig": false,
"md5_digest": "e4365bff1f68a7509f90ddc3d8c9dba6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 8543,
"upload_time": "2023-11-15T00:28:34",
"upload_time_iso_8601": "2023-11-15T00:28:34.446530Z",
"url": "https://files.pythonhosted.org/packages/11/5b/ad9d921bda3c47e678638fcb74429077a755ace6273d0d9da3aa1b254f80/cwriter-0.1.0a3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-15 00:28:34",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "felingineer",
"gitlab_project": "cwriter",
"lcname": "cwriter"
}