{"id":17633324,"url":"https://github.com/cgmb/guardonce","last_synced_at":"2025-04-09T12:05:58.346Z","repository":{"id":9240813,"uuid":"11060724","full_name":"cgmb/guardonce","owner":"cgmb","description":"Utilities for converting from C/C++ include guards to #pragma once and back again.","archived":false,"fork":false,"pushed_at":"2020-01-28T23:26:51.000Z","size":148,"stargazers_count":148,"open_issues_count":6,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-02T09:09:21.660Z","etag":null,"topics":["c","c-plus-plus","converter","cpp","include-guards","pragma-once"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cgmb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-29T22:31:41.000Z","updated_at":"2025-02-28T21:50:14.000Z","dependencies_parsed_at":"2022-09-02T08:14:43.089Z","dependency_job_id":null,"html_url":"https://github.com/cgmb/guardonce","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgmb%2Fguardonce","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgmb%2Fguardonce/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgmb%2Fguardonce/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cgmb%2Fguardonce/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cgmb","download_url":"https://codeload.github.com/cgmb/guardonce/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248036063,"owners_count":21037092,"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","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","c-plus-plus","converter","cpp","include-guards","pragma-once"],"created_at":"2024-10-23T01:48:20.909Z","updated_at":"2025-04-09T12:05:58.322Z","avatar_url":"https://github.com/cgmb.png","language":"Python","readme":"guardonce\n=========\n\nUtilities for converting from C/C++ include guards to #pragma once and\nback again.\n\n## Why Convert?\nInclude guards suck. They're tiring to type and tedious to update. Worse, the\ntask of updating boilerplate leaves room for copy/paste errors, or other\nmistakes. #pragma once is simpler and less error prone. That's why you should\nconvert to #pragma once.\n\nAlas, though #pragma once is available on all the most commonly used\ncompilers, it's not available on _every_ compiler. Perhaps one day you'll add\nsupport for a platform with a barebones compiler with no support for #pragma\nonce and you'll have to convert back. That's ok. It's easy!\n\n## What exactly is guardonce?\nThere are three main tools provided by guardonce:\n\n1. `checkguard` helps find any broken include guards you may already have in\nyour project. These should be addressed before converting.\n\n2. `guard2once` converts files with include guards into files with #pragma\nonce directives. This ensures your entire project is consistently using #pragma\nonce.\n\n3. `once2guard` converts files with #pragma once directives back into files\nwith include guards. This ensures your entire project is consistently using\ninclude guards.\n\n## How to use:\nFirst, check your project for broken headers. To recursively search your\nproject directories for the names of all files that lack proper include guards,\nuse the following command, substituting your project's directory for the\nquoted string:\n\n`checkguard -r \"source_directory\"`\n\nBy default, checkguard is very forgiving. It accepts either #pragma once or\nanything that looks like an include guard. If you know that all your guards\nshould match some format, you can be more strict by using `-p` to specify\n[a pattern](docs/PatternLanguage.md) to check against.\n\nIf certain files are not supposed to have include guards, feel free to leave\nthem be. Files without include guards are ignored by this next step.\n\nNow, all that remains is converting the headers to use #pragma once:\n\n`guard2once -r \"source_directory\"`\n\nYou're done! Double check that the result matches your expectations and start\nusing #pragma once in your new code. Know that if you ever need to switch back,\nit's as simple as:\n\n`once2guard -r \"source_directory\"`\n\nIf the default guard style doesn't appeal to you, there are a few options to\ncustomize it. Maybe take a look through `once2guard --help` or check out a\n[walkthrough](docs/Walkthrough.md) for some examples.\n\n## How to Install:\nWhether you use Python 2 or Python 3, these tools can be installed with pip.\nRun `python -m pip install guardonce` and you're off to the races.\n\nIf you'd rather not use pip, it is possible to instead just run from the\nrepository. However, you'll need to use slightly different commands. Add the\nrepository to your `PYTHONPATH` and invoke the tools as python modules, as\nillustrated below.\n\n### Linux / OSX\n```\ngit clone https://github.com/cgmb/guardonce.git\nexport PYTHONPATH=\"$(pwd)/guardonce\"\npython -m guardonce.checkguard -r ~/myproject\n```\n\n### Windows\n```\ngit clone https://github.com/cgmb/guardonce.git\nset \"PYTHONPATH=%CD%\\guardonce\"\npython -m guardonce.checkguard -r ~/myproject\n```\n\nNote that on Windows you might need to invoke guardonce via `python -m` even if\nyou install with pip.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgmb%2Fguardonce","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcgmb%2Fguardonce","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcgmb%2Fguardonce/lists"}