Documentation.
This commit is contained in:
parent
5c9512ce27
commit
74619df7e5
31
readme.md
31
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)
|
||||
|
||||
## <a id = "user-content-preamble" name = "user-content-preamble">Description</a> ##
|
||||
|
||||
These are hard\-coded CGI programmes for simple voting\. Compile with different headers to change the voting scheme\.
|
||||
|
||||
|
||||
|
||||
## <a id = "user-content-tag" name = "user-content-tag">Struct, Union, and Enum Definitions</a> ##
|
||||
|
||||
### <a id = "user-content-tag-6b81ce15" name = "user-content-tag-6b81ce15">vote</a> ###
|
||||
|
||||
<code>struct <strong>vote</strong> { const char *name; unsigned vote; const char token; };</code>
|
||||
|
||||
Vote structure\.
|
||||
|
||||
|
||||
|
||||
## <a id = "user-content-license" name = "user-content-license">License</a> ##
|
||||
|
||||
2007 Neil Edelman, distributed under the terms of the [GNU General Public License 3](https://opensource.org/licenses/GPL-3.0)\.
|
||||
|
||||
|
||||
|
||||
|
@ -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 <string.h> /* strstr() */
|
||||
#include <time.h> /* 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()) ||
|
||||
|
Loading…
Reference in New Issue
Block a user