{"id":30085120,"url":"https://github.com/d3bvstack/c-declare-top","last_synced_at":"2025-08-09T00:10:42.671Z","repository":{"id":287709399,"uuid":"965561468","full_name":"d3bvstack/c-declare-top","owner":"d3bvstack","description":"Script to parse .c files and add function declarations at the top of each file","archived":false,"fork":false,"pushed_at":"2025-05-06T20:53:41.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-14T21:17:57.070Z","etag":null,"topics":["c-programming","code-parsing","code-refactoring","shell-scripting","text-processing","unix"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d3bvstack.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-13T12:44:04.000Z","updated_at":"2025-05-06T20:53:45.000Z","dependencies_parsed_at":"2025-04-23T11:38:45.199Z","dependency_job_id":null,"html_url":"https://github.com/d3bvstack/c-declare-top","commit_stats":null,"previous_names":["d3bvstack/top-declaration","d3bvstack/declarations_script","d3bvstack/declare-top","d3bvstack/c-declare-top"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/d3bvstack/c-declare-top","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d3bvstack%2Fc-declare-top","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d3bvstack%2Fc-declare-top/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d3bvstack%2Fc-declare-top/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d3bvstack%2Fc-declare-top/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d3bvstack","download_url":"https://codeload.github.com/d3bvstack/c-declare-top/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d3bvstack%2Fc-declare-top/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269508713,"owners_count":24428743,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-programming","code-parsing","code-refactoring","shell-scripting","text-processing","unix"],"created_at":"2025-08-09T00:10:40.920Z","updated_at":"2025-08-09T00:10:42.619Z","avatar_url":"https://github.com/d3bvstack.png","language":"Shell","readme":"# Function Declarations Script\n\nA bash script that automatically parses C files, extracts function definitions, and adds their declarations at the top of the file. This helps maintain proper function prototypes in C codebases and avoid implicit declarations.\n\n## Introduction\n\nThe `add_declaration.sh` script is designed to help C developers maintain clean and organized code by automatically generating function declarations for their C files. This script simplifies the process of managing function prototypes and ensures that all necessary declarations are present at the top of the file.\n\n## Purpose\n\nThe `add_declaration.sh` script helps C developers maintain clean code by:\n- Automatically finding all function definitions in C files\n- Creating appropriate function declarations (prototypes)\n- Adding these declarations at the top of the file in an organized manner\n- Avoiding duplicate declarations by managing existing declaration sections\n\n## Features\n\n- Parses C files to extract function definitions\n- Generates function declarations and adds them to the top of the file\n- Handles multiple function formatting styles\n- Manages existing declaration sections to avoid duplicates\n- Creates backup files before making changes\n\n## Installation\n\n1. Clone this repository:\n   ```\n   git clone https://github.com/yourusername/declarations_script.git\n   cd declarations_script\n   ```\n\n2. Make the script executable:\n   ```\n   chmod +x add_declaration.sh\n   ```\n\n## Usage\n\nThe script can be used in several ways:\n\n### 1. Process all C files in the src directory:\n\n```bash\n./add_declaration.sh\n```\n\nThis will process all `.c` files found in the `src` directory (the directory must exist).\n\n### 2. Process a specific C file:\n\n```bash\n./add_declaration.sh path/to/your/file.c\n```\n\n### 3. Process all C files in a specific directory:\n\n```bash\n./add_declaration.sh path/to/directory\n```\n\n## How It Works\n\nThe script performs the following operations:\n\n1. Locates C files based on the provided arguments\n2. For each file:\n   - Uses AWK to extract function definitions\n   - Converts these definitions into proper declarations by adding semicolons\n   - Checks if the file already has a declarations section\n   - If it exists, removes the old declarations to avoid duplicates\n   - Inserts the new declarations section at the appropriate location:\n     - After the last `#include` statement if includes exist\n     - After header comments if no includes exist\n     - At the beginning of the file otherwise\n   - Creates a backup of the original file (`.bak` extension)\n\n## Example\n\nGiven a C file like this:\n\n```c\n#include \u003cstdio.h\u003e\n\nvoid print_hello() {\n    printf(\"Hello, world!\\n\");\n}\n\nint calculate_sum(int a, int b) {\n    return a + b;\n}\n```\n\nThe script will transform it to:\n\n```c\n#include \u003cstdio.h\u003e\n\n/* Function declarations */\nvoid print_hello();\nint calculate_sum(int a, int b);\n\nvoid print_hello() {\n    printf(\"Hello, world!\\n\");\n}\n\nint calculate_sum(int a, int b) {\n    return a + b;\n}\n```\n\n## Notes\n\n- The script creates backup files with `.bak` extension before making changes\n- It handles multiple function formatting styles\n- It properly manages existing declaration sections\n- Comments in function definitions are properly removed from declarations\n\n## Requirements\n\n- Bash shell\n- AWK (comes pre-installed on most Unix-like systems)\n- Standard Unix tools (grep, find, etc.)\n\n## License\n\nSee the [LICENSE](LICENSE) file for details.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd3bvstack%2Fc-declare-top","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd3bvstack%2Fc-declare-top","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd3bvstack%2Fc-declare-top/lists"}