{"id":16603824,"url":"https://github.com/shundhammer/commented-config-file","last_synced_at":"2025-07-07T13:34:32.206Z","repository":{"id":95539134,"uuid":"83728577","full_name":"shundhammer/commented-config-file","owner":"shundhammer","description":"CommentedConfigFile for C++ / STL / Boost","archived":false,"fork":false,"pushed_at":"2018-02-06T14:55:52.000Z","size":71,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-17T09:47:26.269Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shundhammer.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}},"created_at":"2017-03-02T21:55:37.000Z","updated_at":"2024-04-27T16:53:56.000Z","dependencies_parsed_at":"2023-08-30T22:37:02.793Z","dependency_job_id":null,"html_url":"https://github.com/shundhammer/commented-config-file","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shundhammer%2Fcommented-config-file","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shundhammer%2Fcommented-config-file/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shundhammer%2Fcommented-config-file/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shundhammer%2Fcommented-config-file/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shundhammer","download_url":"https://codeload.github.com/shundhammer/commented-config-file/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242729460,"owners_count":20175945,"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":[],"created_at":"2024-10-12T00:53:14.264Z","updated_at":"2025-03-09T17:39:01.500Z","avatar_url":"https://github.com/shundhammer.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CommentedConfigFile C++ Class\n\n(c) 2017 Stefan Hundhammer \u003cStefan.Hundhammer@gmx.de\u003e\n\nLicense: GPL V2\n\n## Overview\n\n- CommentedConfigFile class\n- ColumnConfigFile class\n- Generic Diff class for string vectors\n\n\n## System Requirements:\n\n- C++\n- STL\n- Boost\n- Autotools (just for the demo programs and the test suite)\n\nThis class should work on Linux/BSD/Unix-like systems and on all kinds of MS\nWindows. It's just some C++ classes after all.\n\n\n## CommentedConfigFile\n\nThis is a utility class for C++ to read and write config files that might\ncontain comments.  This class tries to preserve any existing comments and keep\nthem together with the content line immediately following them.\n\nThis class supports the notion of a header comment block, a footer comment\nblock, a comment block preceding any content line and a line comment on the\ncontent line itself.\n\nA comment preceding a content line is stored together with the content line,\nso moving around entries in the file will keep the comment with the content\nline it belongs to.\n\nThe default comment marker is '#' like in most Linux config files, but it\ncan be set with setCommentMarker().\n\n## Example\n\n(line numbers added for easier reference)\n\n    001\t   # Header comment 1\n    002\t   # Header comment 2\n    003\t   # Header comment 3\n    004\n    005\n    006\t   # Header comment 4\n    007\t   # Header comment 5\n    008\n    009\t   # Content line 1 comment 1\n    010\t   # Content line 1 comment 2\n    011\t   content line 1\n    012\t   content line 2\n    013\n    014\t   content line 3\n    015\n    016\t   content line 4\n    017\t   content line 5 # Line comment 5\n    018\t   # Content line 6 comment 1\n    019\n    020\t   content line 6 # Line comment 6\n    021\t   content line 7\n    022\n    023\t   # Footer comment 1\n    024\t   # Footer comment 2\n    025\n    026\t   # Footer comment 3\n\n\nEmpty lines or lines that have only whitespace belong to the next comment\nblock: The footer comment consists of lines 022..026.\n\nThe only exception is the header comment that stretches from the start of\nthe file to the last empty line preceding a content line. This is what\nseparates the header comment from the comment that belongs to the first\ncontent line. In this example, the header comment consists of lines\n001..008.\n\n- Content line 1 in line 011 has comments 009..010.\n- Content line 2 in line 012 has no comment.\n- Content line 3 in line 014 has comment 013 (an empty line).\n- Content line 5 in line 017 has a line comment \"# Line comment 5\".\n- Content line 6 in line 020 has comments 018..019 and a line comment.\n\nApplications using this class can largely just ignore all the comment stuff;\nthe class will handle the comments automagically.\n\n\n## Building\n\nOnce:\n\n    ./build-all\n\nAfter that:\n\n    make\n\n\n## Installing\n\nThere is nothing to install: It's just C++ classes.\nYou can add them to a library or to an application.\n\n\n## Installing Boost Headers\n\nUbuntu:\n\n    sudo apt-get install libboost-dev libboost-test-dev\n\n\n## Running the Test Suite\n\n    make check\n\nTo run just one single test (to get more output if it failed):\n\n    cd test\n    ./container_ops.test\n\n(or whichever of them failed)\n\n\n## Sample Output\n\nThe `ccf_demo` program in `src/main.cc` produces this output from my `/etc/fstab` file:\n\n    \u003cHeader\u003e\n       1: # /etc/fstab: static file system information.\n       2: #\n       3: # [sh @ balrog] ~ %  sudo blkid | column -t\n       4: #\n       5: # /dev/sda1:  LABEL=\"Win-Boot\"    UUID=\"C6CC71BDCC71A877\"                      TYPE=\"ntfs\"\n       6: # /dev/sda2:  LABEL=\"Win-App\"     UUID=\"3E5E77515E770147\"                      TYPE=\"ntfs\"\n       7: #\n       8: # /dev/sdb1:  LABEL=\"swap\"        UUID=\"be72e905-a417-41a4-a75f-12c0cf774f6a\"  TYPE=\"swap\"\n       9: # /dev/sdb2:  LABEL=\"openSUSE\"    UUID=\"1d0bc24c-ae68-4c4e-82af-b3e184b2ac9d\"  TYPE=\"ext4\"\n      10: # /dev/sdb3:  LABEL=\"Ubuntu\"      UUID=\"f5c15fbd-0417-4711-a0b7-f66b608bad0c\"  TYPE=\"ext4\"\n      11: # /dev/sdb5:  LABEL=\"work\"        UUID=\"7e1d65c8-c6e3-4824-ac1c-c3a4ba90f54f\"  TYPE=\"ext4\"\n      12: #\n      13: #\n      14: # \u003cfile system\u003e              \u003cmount point\u003e   \u003ctype\u003e \u003coptions\u003e         \u003cdump\u003e  \u003cpass\u003e\n      15:\n    \u003c/Header\u003e\n\n    \u003cContent\u003e\n      Entry #1 content  : /dev/disk/by-label/swap      none             swap  sw                         0  0\n      Entry #2 content  : /dev/disk/by-label/openSUSE  /alternate-root  ext4  defaults                   0  2\n      Entry #3 content  : /dev/disk/by-label/Ubuntu    /                ext4  errors=remount-ro          0  1\n      Entry #4 content  : /dev/disk/by-label/work      /work            ext4  defaults                   0  2\n\n      Entry #5 comment 1:\n      Entry #5 comment 2: # Windows disk\n      Entry #5 content  : /dev/disk/by-label/Win-Boot  /win/boot        ntfs  defaults,umask=007,gid=46  0  0\n      Entry #6 content  : /dev/disk/by-label/Win-App   /win/app         ntfs  defaults,umask=007,gid=46  0  0\n    \u003c/Content\u003e\n\n    \u003cFooter\u003e\n      1:\n      2:\n      3: # nas:/share/sh              /nas/sh          nfs   bg,intr,soft,retry=6       0  0\n      4: # nas:/share/work            /nas/work        nfs   bg,intr,soft,retry=6       0  0\n      5:\n    \u003c/Footer\u003e\n\nI.e. it correctly detected the header comments, the footer comments and the\ncomment that belongs to _Entry #5_. When the entries are rearranged, e.g. the\nentries for the Windows disk are moved above the Linux disk, that comment\nremains attached to that entry, i.e. it is moved together with that entry.\n\nOf course that has limitations. If a comment does not belong to the next entry,\nbut to the previous one, it is moved to the wrong location. That's life. But\nit's much better than throwing away all comments every time a program touches a\nconfig file.\n\n\n## ColumnConfigFile\n\nThis class is derived from CommentedConfigFile. In addition to the comment\nhandling, this class also manages splitting up column-oriented config files\ninto the columns.\n\nThe content lines may all have the same number of columns (like in\n`/etc/fstab`), or they might have different numbers of columns.\n\n\n## Diff\n\nThis is a generic Diff class for STL `vector\u003cstring\u003e` that works just like the\nLinux `diff -u` command - with or without context lines, as configured.\n\nThe `ccf_diff` example can be used pretty much as a drop-in replacement for\n`diff -u`.\n\nThis Diff class may not always return the absolute minimum diff (or \"edit\nscript\"), but it will always be a human readable one.\n\nI had wondered why there is no ready-made class for this anywhere in STL or\neven Boost (or is there?); this is useful in many cases; for example, when\nwriting just the changes done to a config file to the log. This is why this\nclass is part of this little class library: It is ready to be used on the\nCommentedConfigFile level if you just configure diffs to be enabled there\n(which just saves the old lines at tactical points such as reading and parsing\nfile content).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshundhammer%2Fcommented-config-file","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshundhammer%2Fcommented-config-file","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshundhammer%2Fcommented-config-file/lists"}