|
machinatrix
A very silly Matrix bot written in C
|
Main robot implementation. More...
#include <errno.h>#include <stdint.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <fcntl.h>#include <getopt.h>#include <sys/wait.h>#include <unistd.h>#include "common.h"#include <tidybuffio.h>#include "config.h"#include "dlpo.h"#include "hash.h"#include "html.h"#include "numeraria.h"#include "utils.h"#include "wikt.h"
Data Structures | |
| struct | config |
machinatrix-specific configuration. More... | |
| struct | mtrix_cmd |
| Structure that associates a mtrix_cmd_f to a command. More... | |
| struct | stats |
| Accumulates lookup statistics. More... | |
Macros | |
| #define | DICT_FILE "/usr/share/dict/words" |
| Dictionary file used for commands that require a list of words. | |
Typedefs | |
| typedef bool | mtrix_cmd_f(const struct config *, const char *const *) |
| Function that handles a command. | |
Enumerations | |
| enum | { MAX_PATH = MTRIX_MAX_PATH , MAX_UNIX_PATH = MTRIX_MAX_UNIX_PATH , STATS_WIKT = 0 , STATS_DLPO = 1 } |
Functions | |
| int | main (int argc, const char *const *argv) |
| Program entry point. | |
| static bool | parse_args (int argc, char *const **argv, struct config *config) |
Parses command-line arguments and fills config. | |
| static void | usage (FILE *f) |
| Prints a usage message. | |
| static void | config_init (struct config *config) |
Initializes values in config. | |
| static bool | config_init_numeraria (struct config *config) |
Initializes values in config. | |
| static bool | config_destroy (struct config *config) |
Destructs config. | |
| static bool | config_record_command (const struct config *config, const char *const *argv) |
| Records that a command will be executed, along with its arguments. | |
| static bool | handle_cmd (const struct config *config, const char *const *argv) |
| Handles a command passed via the command line. | |
| static bool | handle_file (const struct config *config, FILE *f) |
| Handles commands read as lines from a file. | |
| static bool | str_to_args (char *str, size_t max_args, char **argv) |
| Breaks string into space-separated parts. | |
| static bool | cmd_help (const struct config *config, const char *const *argv) |
Implements the help command. | |
| static bool | cmd_ping (const struct config *config, const char *const *argv) |
Implements the ping command. | |
| static bool | cmd_word (const struct config *config, const char *const *argv) |
Implements the word command. | |
| static bool | cmd_abbr (const struct config *config, const char *const *argv) |
Implements the abbr command. | |
| static bool | cmd_damn (const struct config *config, const char *const *argv) |
Implements the damn command. | |
| static bool | cmd_parl (const struct config *config, const char *const *argv) |
Implements the parl command. | |
| static bool | cmd_bard (const struct config *config, const char *const *argv) |
Implements the bard command. | |
| static bool | cmd_dlpo (const struct config *config, const char *const *argv) |
Implements the dlpo command. | |
| static bool | cmd_wikt (const struct config *config, const char *const *argv) |
Implements the wikt command. | |
| static bool | cmd_tr (const struct config *config, const char *const *argv) |
Implements the tr command. | |
| static bool | cmd_stats (const struct config *config, const char *const *argv) |
Implements the stats command. | |
| static bool | stats_increment (const struct config *config, uint8_t opt) |
| Increments the count on wikt and dlpo lookups. | |
| static bool | stats_file (const struct config *config) |
| Print stats from local file. | |
| static bool | stats_numeraria (const struct config *config) |
| Print stats from numeraria. | |
Variables | |
| const char * | PROG_NAME = NULL |
To be filled by argv[0] later, for logging. | |
| const char * | CMD_NAME = NULL |
| Set while processing a command. | |
| struct mtrix_cmd | COMMANDS [] |
| Maps a command name to the function that handles it. | |
Main robot implementation.
| #define DICT_FILE "/usr/share/dict/words" |
Dictionary file used for commands that require a list of words.
| typedef bool mtrix_cmd_f(const struct config *, const char *const *) |
Function that handles a command.
|
static |
Implements the abbr command.
|
static |
Implements the bard command.
|
static |
Implements the damn command.
|
static |
Implements the dlpo command.

|
static |
Implements the help command.

|
static |
Implements the parl command.
|
static |
Implements the ping command.
|
static |
Implements the stats command.

|
static |
Implements the tr command.

|
static |
Implements the wikt command.

|
static |
Implements the word command.
|
static |
Destructs config.


|
static |
Initializes values in config.

|
static |
Initializes values in config.

|
static |
Records that a command will be executed, along with its arguments.

|
static |
Handles a command passed via the command line.


|
static |
Handles commands read as lines from a file.


| int main | ( | int | argc, |
| const char *const * | argv ) |
Program entry point.

|
static |
Parses command-line arguments and fills config.


|
static |
Print stats from local file.

|
static |
Increments the count on wikt and dlpo lookups.


|
static |
Print stats from numeraria.

|
static |
Breaks string into space-separated parts.
| str | Input string, modified to include null terminators. |
| max_args | Maximum length for argv, including the null terminator. |
| argv | Populated with pointers to the null-terminated strings in str. |
false if str contains more than max_args 
|
static |
Prints a usage message.

| const char* CMD_NAME = NULL |
Set while processing a command.
Command name, used as a second prefix for log messages if non-NULL.
| struct mtrix_cmd COMMANDS[] |
Maps a command name to the function that handles it.
Terminated by a {NULL, NULL} entry.
| const char* PROG_NAME = NULL |
To be filled by argv[0] later, for logging.
Program name, used as a prefix for log messages if non-NULL.