diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ff9e935 --- /dev/null +++ b/LICENSE @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar + +Everyone is permitted to copy and distribute verbatim or modified +copies of this license document, and changing it is allowed as long +as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e90082f --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# The (un)Official Lain's Diction Book + +Quote / Definition / Pastebin bot + +it takes text from irc and stores it in a database + + 13:56 <@kashire> We need to make our own dictionary. + 13:56 <@kashire> The (un)Official Lain's Diction Book. diff --git a/db.c b/db.c new file mode 100644 index 0000000..37e623d --- /dev/null +++ b/db.c @@ -0,0 +1,89 @@ +/* */ + +#include /* assert */ +#include +#include /* size_t */ +#include /* malloc */ +#include /* strdup */ +/* TODO: libircclient for basic IRC functionality. + * Perhaps a database backend and a client frontend that's separate. */ + +#ifndef UNUSED +#define UNUSED(x) (void)(x) +#endif + +#include "io.c" + +static int callback(void *NotUsed, int argc, char **argv, char **azColName) { + int i; + UNUSED(NotUsed); + for (i = 0; i < argc; i++) { + printf(" => %s = %s\n", azColName[i], (argv[i] ? argv[i] : "NULL")); + } + return 0; +} + +int test_db(char *script_filename) { + char *orig_statements; + char *saveptr1; + char *statements; + char *str1, *token; + char *zErrMsg; + const char *db_name; + int j; + int rc; + int nstatements; + sqlite3 *db; + + nstatements = 0; + zErrMsg = 0; + orig_statements = file_read(script_filename); + if (orig_statements) { + statements = strndup(orig_statements, 4096); + } else { + fprintf(stderr, "Error reading file: %s\n", script_filename); + return -1; + } + + db_name = "familyGuy.db"; + rc = sqlite3_open(db_name, &db); + if (rc) { + fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); + } else { + fprintf(stderr, "Open database successfully\n"); + } + + for (j = 1, str1 = statements;; j++, str1 = NULL) { + token = strtok_r(str1, "\n", &saveptr1); + if (token == NULL) + break; + printf("%d: %s\n", j, token); + rc = sqlite3_exec(db, token, callback, 0, &zErrMsg); + if (rc != SQLITE_OK) { + fprintf(stderr, "SQL error: %s\n", sqlite3_errmsg(db)); + sqlite3_free(zErrMsg); + break; + } + nstatements++; /* Number of successfully executed statements */ + } + + free(orig_statements); + free(statements); + sqlite3_close(db); + fprintf(stderr, "Bye!\n"); + + return 0; +} + +#ifdef TEST_DB +int main(int argc, char **argv) { + char *script_filename; + if (argc > 1) { + script_filename = argv[1]; + } else { + fprintf(stderr, "Usage: %s