BotRwxModel* bot_rwx_model_create( const char *fname ) { BotRwxModel *model = calloc(1, sizeof(BotRwxModel)); tokenize_t *tok = tokenize_create( fname ); int status; if (NULL==tok) { perror(fname); free(model); return NULL; } parse_require( tok, "ModelBegin" ); parse_require( tok, "ClumpBegin" ); while (tokenize_next(tok)!=EOF) { if( 0 == strcmp( tok->token, "ClumpBegin" ) ) { BotRwxClump *clump = (BotRwxClump*)calloc(1, sizeof(BotRwxClump)); model->clumps = g_list_append( model->clumps, clump ); status = parse_clump( clump, tok ); if( 0 != status ) { tokenize_destroy(tok); bot_rwx_model_destroy(model); return NULL; } } else if( 0 == strcmp( tok->token, "ClumpEnd" ) ) { parse_require( tok, "ModelEnd" ); break; } } tokenize_destroy( tok ); return model; }
char *moby_get_syn(DB * db, char *tok, int opt) { dlist_t *dl = NULL, *dptr = NULL; xdb_pair_t *pair = NULL; char *str = NULL; debug(NULL, "moby_get_syn: Entered\n"); if (!tok || !moby_info.initialized) return NULL; str_apply(tok, tolower); pair = xdb_get(db, tok); if (!pair) return NULL; if (opt == MOBY_SINGLE) { dl = tokenize(NULL, pair->value, TOKENIZE_NORMAL | TOKENIZE_EATWHITESPACE, ","); if (!dl) goto cleanup; dptr = dlist_node_rand(dl); if (!dptr) goto cleanup; str = str_unite_static("%s", (char *)dlist_data(dptr)); } else if (opt == MOBY_LIST) { str = str_unite_static("%s,%s", pair->key, pair->value); } cleanup: if (dl) tokenize_destroy(NULL, &dl); xdb_pair_destroy(pair); return str; }
char *quiz_change_string(bot_t * bot, char *string, int opt) { unique_t *bu = NULL; quiz_active_t **qa = NULL; dlist_t *dl = NULL; char **arg_array = NULL; char *str = NULL; char buf[MAX_BUF_SZ]; char *sep_ptr; debug(bot, "quiz_change_string: Entered\n"); if (!bot || !string) return NULL; sep_ptr = str_find_sep(string); if (sep_ptr) string = sep_ptr; bu = unique_create(bot, &dl_quiz_active_unique, UNIQUE_ID_TAG | UNIQUE_ID_CHAN); if (!bu) return NULL; qa = (quiz_active_t **) & bu->data; if (!qa) { } _memset(buf, 0, sizeof(buf)); if (strlen(string)) { dl = tokenize(bot, string, TOKENIZE_NORMAL | TOKENIZE_EATWHITESPACE, " "); if (!dl) return NULL; arg_array = (char **)dlist_convert_dlist_to_array(dl); if (!arg_array) goto cleanup; capsup(arg_array[0]); } switch (opt) { case QUIZ_OPT_LIST: { str = quiz_op_list(bot); break; } case QUIZ_OPT_INFO: { str = quiz_op_info(bot, *qa); break; } case QUIZ_OPT_CLEAR: { str = quiz_op_clear(bot, *qa); break; } case QUIZ_OPT_CLEAR_WINNERS: { str = quiz_op_clear_winners(bot, *qa); break; } case QUIZ_OPT_WINNERS: { str = quiz_op_winners(bot, *qa); break; } case QUIZ_OPT_SETUP: { str = quiz_op_setup(bot, qa, string); if (str) { module_t *m_ptr = NULL; mod_quiz_info.timer = quiz_timer; m_ptr = module_find_by_name("mod_quiz"); if (m_ptr) { m_ptr->timer = quiz_timer; module_update(m_ptr, "mod_quiz"); } } if (*qa) bu->data = *qa; break; } case QUIZ_OPT_ANSWER: { str = quiz_op_answer(bot, *qa, string); break; } case QUIZ_OPT_GET: { if (!arg_array[1]) return NULL; str = quiz_op_get(bot, arg_array[0], atoi(arg_array[1])); break; } case QUIZ_OPT_DEL: { break; } case QUIZ_OPT_TIMEOUT: { str = quiz_op_timeout(bot, *qa, atoi(arg_array[0])); break; } case QUIZ_OPT_SIZE: { str = quiz_op_size(bot, arg_array[0]); break; } case QUIZ_OPT_MULTI: { str = quiz_op_multi(bot, *qa, arg_array[0]); break; } case QUIZ_OPT_NEWLINES: { str = quiz_op_newlines(bot, *qa, arg_array[0]); break; } case QUIZ_OPT_HIDEKEY: { str = quiz_op_hidekey(bot, *qa, arg_array[1]); break; } default: break; } cleanup: if (dl) tokenize_destroy(bot, &dl); if (arg_array) free(arg_array); if (str) bot->shouldsend = 1; return str; }