From 74619df7e506372cff6ff04a9f00b68771a54a0a Mon Sep 17 00:00:00 2001 From: Neil Date: Fri, 11 Jun 2021 23:34:54 -0700 Subject: [PATCH] Documentation. --- readme.md | 31 ++++++++++++++++++++++++++++++- src/vote.c | 9 +++++++-- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 0727423..951d731 100644 --- a/readme.md +++ b/readme.md @@ -1 +1,30 @@ -These are hard-coded CGI programmes for simple voting. +# vote\.c # + +## Vote ## + + * [Description](#user-content-preamble) + * [Struct, Union, and Enum Definitions](#user-content-tag): [vote](#user-content-tag-6b81ce15) + * [License](#user-content-license) + +## Description ## + +These are hard\-coded CGI programmes for simple voting\. Compile with different headers to change the voting scheme\. + + + +## Struct, Union, and Enum Definitions ## + +### vote ### + +struct vote { const char *name; unsigned vote; const char token; }; + +Vote structure\. + + + +## License ## + +2007 Neil Edelman, distributed under the terms of the [GNU General Public License 3](https://opensource.org/licenses/GPL-3.0)\. + + + diff --git a/src/vote.c b/src/vote.c index 4ba7824..59a928c 100644 --- a/src/vote.c +++ b/src/vote.c @@ -1,4 +1,4 @@ -/* @license 2007 Neil Edelman, distributed under the terms of the +/** @license 2007 Neil Edelman, distributed under the terms of the [GNU General Public License 3](https://opensource.org/licenses/GPL-3.0). @subtitle Vote @@ -11,6 +11,7 @@ #include /* strstr() */ #include /* time() */ +/** Vote structure. */ struct vote { const char *name; unsigned vote; @@ -27,11 +28,13 @@ struct vote { /* `votes` defined in header. */ static const size_t votes_size = sizeof votes / sizeof *votes; +/** @param[vote] Address of the variable that receives the `vote.vote` letter + or '\0'. */ static char *extract_vote(char *const vote) { FILE *fp; char *env, *var; /* at least it will zero */ - *vote = 0; + *vote = '\0'; /* check env vars */ if(!(env = getenv("REQUEST_METHOD")) || strcmp(env, "GET")) return "Invalid request method."; @@ -109,6 +112,7 @@ static char *votes_write(void) { return 0; } +/** @param[vote] The `vote.vote` letter of the struct. */ static char *votes_inc(char vote) { struct vote *votep; /* search for a match for the first letter of vote as a token */ @@ -163,6 +167,7 @@ static char *votes_html(void) { return 0; } +/** Reads and, possibly writes an incremented vote. */ int main(void) { char vote, *error = 0; if((error = votes_read()) ||