| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752 |
- /******************************************************************************
- * This file is part of TinTin++ *
- * *
- * Copyright 2004-2020 Igor van den Hoven *
- * *
- * TinTin++ is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 3 of the License, or *
- * (at your option) any later version. *
- * *
- * This program is distributed in the hope that it will be useful, *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
- * GNU General Public License for more details. *
- * *
- * You should have received a copy of the GNU General Public License *
- * along with TinTin++. If not, see https://www.gnu.org/licenses. *
- ******************************************************************************/
- /******************************************************************************
- * T I N T I N + + *
- * *
- * coded by Igor van den Hoven 2004 *
- ******************************************************************************/
- #include "tintin.h"
- #include <limits.h>
- extern char **environ;
- struct listroot *init_list(struct session *ses, int type, int size)
- {
- struct listroot *listhead;
- if ((listhead = (struct listroot *) calloc(1, sizeof(struct listroot))) == NULL)
- {
- syserr_fatal(-1, "init_list: calloc");
- }
- listhead->ses = ses;
- listhead->list = (struct listnode **) calloc(size, sizeof(struct listnode *));
- listhead->size = size;
- listhead->type = type;
- listhead->flags = list_table[type].flags;
- return listhead;
- }
- void kill_list(struct listroot *root)
- {
- while (root->used)
- {
- delete_index_list(root, root->used - 1);
- }
- root->update = 0;
- }
- void free_list(struct listroot *root)
- {
- kill_list(root);
- free(root->list);
- free(root);
- }
- struct listroot *copy_list(struct session *ses, struct listroot *sourcelist, int type)
- {
- int i;
- struct listnode *node;
- push_call("copy_list(%p,%p,%s)",ses,sourcelist,list_table[type].name);
- ses->list[type] = init_list(ses, type, sourcelist->size);
- if (HAS_BIT(sourcelist->flags, LIST_FLAG_INHERIT))
- {
- for (i = 0 ; i < sourcelist->used ; i++)
- {
- node = (struct listnode *) calloc(1, sizeof(struct listnode));
- node->arg1 = str_dup_clone(sourcelist->list[i]->arg1);
- node->arg2 = str_dup_clone(sourcelist->list[i]->arg2);
- node->arg3 = str_dup_clone(sourcelist->list[i]->arg3);
- node->arg4 = str_dup_clone(sourcelist->list[i]->arg4);
- node->shots = sourcelist->list[i]->shots;
- node->group = strdup(sourcelist->list[i]->group);
- switch (type)
- {
- case LIST_ALIAS:
- node->regex = tintin_regexp_compile(ses, node, node->arg1, PCRE_ANCHORED);
- break;
- case LIST_ACTION:
- case LIST_GAG:
- case LIST_HIGHLIGHT:
- case LIST_PROMPT:
- case LIST_SUBSTITUTE:
- node->regex = tintin_regexp_compile(ses, node, node->arg1, 0);
- break;
- case LIST_BUTTON:
- case LIST_EVENT:
- // case LIST_TICKER:
- case LIST_PATHDIR:
- node->val64 = sourcelist->list[i]->val64;
- break;
- case LIST_VARIABLE:
- copy_nest_node(ses->list[type], node, sourcelist->list[i]);
- break;
- case LIST_TICKER:
- node->val64 = gtd->utime + (long long) (tintoi(node->arg3) * 1000000.0);
- if (node->val64 < gtd->utime_next_tick)
- {
- gtd->utime_next_tick = node->val64;
- }
- break;
- default:
- if (sourcelist->list[i]->val64)
- {
- printf("copy_list: unhandled val64 (%d).\n", type);
- }
- break;
- }
- ses->list[type]->list[i] = node;
- }
- ses->list[type]->used = sourcelist->used;
- }
- ses->list[type]->flags = sourcelist->flags;
- pop_call();
- return ses->list[type];
- }
- struct listnode *create_node_list(struct listroot *root, char *arg1, char *arg2, char *arg3, char *arg4)
- {
- struct listnode *node;
- node = (struct listnode *) calloc(1, sizeof(struct listnode));
- if (list_table[root->type].priority_arg == 3 && *arg3 == 0)
- {
- strcpy(arg3, "5");
- }
- if (HAS_BIT(root->flags, LIST_FLAG_NEST) && *arg1 == '\\')
- {
- node->arg1 = str_dup(arg1+1);
- }
- else
- {
- node->arg1 = str_dup(arg1);
- }
- node->arg2 = str_dup(arg2);
- node->arg3 = str_dup(arg3);
- node->arg4 = str_dup(arg4);
- // printf("debug: %p [%p] (%d) (%s) (%s)\n", root, root->ses, root->type, node->arg1, node->arg3);
- if (gtd->level->shots)
- {
- node->shots = gtd->level->mshot;
- }
- node->group = HAS_BIT(root->flags, LIST_FLAG_CLASS) ? strdup(root->ses->group) : strdup("");
- switch (root->type)
- {
- case LIST_ALIAS:
- node->regex = tintin_regexp_compile(root->ses, node, node->arg1, PCRE_ANCHORED);
- break;
- case LIST_ACTION:
- case LIST_GAG:
- case LIST_HIGHLIGHT:
- case LIST_PROMPT:
- case LIST_SUBSTITUTE:
- node->regex = tintin_regexp_compile(root->ses, node, node->arg1, 0);
- break;
- case LIST_DELAY:
- node->val64 = (long long) tintoi(node->arg1);
- if (node->val64 < gtd->utime_next_delay)
- {
- gtd->utime_next_delay = node->val64;
- }
- break;
- case LIST_TICKER:
- node->val64 = gtd->utime + (long long) (tintoi(arg3) * 1000000.0);
- if (node->val64 < gtd->utime_next_tick)
- {
- gtd->utime_next_tick = node->val64;
- }
- break;
- }
- return insert_node_list(root, node);
- }
- struct listnode *insert_node_list(struct listroot *root, struct listnode *node)
- {
- int index;
- index = locate_index_list(root, node->arg1, node->arg3);
- return insert_index_list(root, node, index);
- }
- struct listnode *update_node_list(struct listroot *root, char *arg1, char *arg2, char *arg3, char *arg4)
- {
- int index;
- struct listnode *node;
- index = search_index_list(root, arg1, NULL);
- if (index != -1)
- {
- node = root->list[index];
- if (gtd->level->shots)
- {
- node->shots = gtd->level->mshot;
- }
- if (strcmp(node->arg2, arg2) != 0)
- {
- str_cpy(&node->arg2, arg2);
- }
- switch (root->type)
- {
- case LIST_TICKER:
- node->val64 = gtd->utime + (long long) tintoi(arg3) * 1000000;
- if (node->val64 < gtd->utime_next_tick)
- {
- gtd->utime_next_tick = node->val64;
- }
- break;
- }
- if (list_table[root->type].priority_arg == 3 && *arg3 == 0)
- {
- strcpy(arg3, "5");
- }
- if (list_table[root->type].mode != SORT_PRIORITY)
- {
- if (strcmp(node->arg3, arg3) != 0)
- {
- str_cpy(&node->arg3, arg3);
- }
- }
- if (strcmp(node->arg4, arg4) != 0)
- {
- str_cpy(&node->arg4, arg4);
- }
- switch (list_table[root->type].mode)
- {
- case SORT_PRIORITY:
- if (strcmp(node->arg3, arg3))
- {
- remove_index_list(root, index);
- str_cpy(&node->arg3, arg3);
- insert_node_list(root, node);
- }
- break;
- case SORT_APPEND:
- remove_index_list(root, index);
- insert_node_list(root, node);
- break;
- case SORT_ALPHA:
- case SORT_ALNUM:
- case SORT_STABLE:
- break;
- default:
- tintin_printf2(root->ses, "#BUG: update_node_list: unknown sort: %d", list_table[root->type].mode);
- break;
- }
- return node;
- }
- else
- {
- return create_node_list(root, arg1, arg2, arg3, arg4);
- }
- }
- struct listnode *insert_index_list(struct listroot *root, struct listnode *node, int index)
- {
- root->used++;
- if (root->used == root->size)
- {
- root->size *= 2;
- root->list = (struct listnode **) realloc(root->list, (root->size) * sizeof(struct listnode *));
- }
- if (index + 1 < root->used)
- {
- memmove(&root->list[index + 1], &root->list[index], (root->used - index) * sizeof(struct listnode *));
- }
- root->list[index] = node;
- return node;
- }
- void remove_node_list(struct session *ses, int type, struct listnode *node)
- {
- int index = search_index_list(ses->list[type], node->arg1, node->arg3);
- remove_index_list(ses->list[type], index);
- }
- void remove_index_list(struct listroot *root, int index)
- {
- if (index <= root->update)
- {
- root->update--;
- }
- memmove(&root->list[index], &root->list[index + 1], (root->used - index) * sizeof(struct listnode *));
- root->used--;
- return;
- }
- void delete_node_list(struct session *ses, int type, struct listnode *node)
- {
- int index = search_index_list(ses->list[type], node->arg1, node->arg3);
- delete_index_list(ses->list[type], index);
- }
- void delete_index_list(struct listroot *root, int index)
- {
- struct listnode *node = root->list[index];
- if (HAS_BIT(list_table[root->type].flags, LIST_FLAG_REGEX))
- {
- if (node->regex)
- {
- free(node->regex);
- }
- }
- switch (root->type)
- {
- case LIST_TERRAIN:
- delete_room_data(node->room);
- free(node->room);
- break;
- case LIST_CLASS:
- if (node->data)
- {
- free(node->data);
- }
- break;
- case LIST_EVENT:
- event_table[node->val32[0]].level--;
- break;
- }
- remove_index_list(root, index);
- // dispose in memory update for one shot handling
- insert_index_list(gtd->dispose_list, node, gtd->dispose_list->used);
- }
- void dispose_node(struct listnode *node)
- {
- if (node->root)
- {
- free_list(node->root);
- }
- str_free(node->arg1);
- str_free(node->arg2);
- str_free(node->arg3);
- str_free(node->arg4);
- free(node->group);
- free(node);
- }
- struct listnode *search_node_list(struct listroot *root, char *text)
- {
- int index;
- push_call("search_node_list(%p,%p)",root,text);
- switch (list_table[root->type].mode)
- {
- case SORT_ALPHA:
- case SORT_STABLE:
- index = bsearch_alpha_list(root, text, 0);
- break;
- case SORT_ALNUM:
- index = bsearch_alnum_list(root, text, 0);
- break;
- default:
- index = nsearch_list(root, text);
- break;
- }
- if (index != -1)
- {
- pop_call();
- return root->list[index];
- }
- pop_call();
- return NULL;
- }
- int search_index_list(struct listroot *root, char *text, char *priority)
- {
- switch (list_table[root->type].mode)
- {
- case SORT_ALPHA:
- case SORT_STABLE:
- return bsearch_alpha_list(root, text, 0);
-
- case SORT_ALNUM:
- return bsearch_alnum_list(root, text, 0);
- case SORT_PRIORITY:
- if (priority)
- {
- bsearch_priority_list(root, text, priority, 0);
- }
- break;
- }
- return nsearch_list(root, text);
- }
-
- /*
- Return insertion index.
- */
- int locate_index_list(struct listroot *root, char *text, char *priority)
- {
- switch (list_table[root->type].mode)
- {
- case SORT_ALPHA:
- return bsearch_alpha_list(root, text, SEEK_REPLACE);
- case SORT_STABLE:
- return bsearch_alpha_list(root, text, SEEK_APPEND);
- case SORT_ALNUM:
- return bsearch_alnum_list(root, text, SEEK_REPLACE);
- case SORT_PRIORITY:
- return bsearch_priority_list(root, text, priority, SEEK_REPLACE);
- default:
- return root->used;
- }
- }
- int bsearch_alpha_list(struct listroot *root, char *text, int seek)
- {
- int bot, mid, top;
- if (root->used == 0)
- {
- return seek ? 0 : -1;
- }
- bot = 0;
- top = root->used;
- if (HAS_BIT(root->flags, LIST_FLAG_CASE))
- {
- while (top > 1)
- {
- mid = top / 2;
- if (strcasecmp(text, root->list[bot + mid]->arg1) >= 0)
- {
- bot += mid;
- }
- top -= mid;
- }
- if (strcasecmp(text, root->list[bot]->arg1) == 0)
- {
- return bot + (seek == SEEK_APPEND);
- }
- if (seek)
- {
- return bot + (strcasecmp(text, root->list[bot]->arg1) > 0);
- }
- return -1;
- }
- while (top > 1)
- {
- mid = top / 2;
- if (strcmp(text, root->list[bot + mid]->arg1) >= 0)
- {
- bot += mid;
- }
- top -= mid;
- }
- if (strcmp(text, root->list[bot]->arg1) == 0)
- {
- return bot + (seek == SEEK_APPEND);
- }
- if (seek)
- {
- return bot + (strcmp(text, root->list[bot]->arg1) > 0);
- }
- return -1;
- }
- /*
- int bsearch_alpha_list(struct listroot *root, char *text, int seek)
- {
- int bot, top, val, srt;
- bot = 0;
- top = root->used - 1;
- val = top;
- while (bot <= top)
- {
- srt = strcmp(text, root->list[val]->arg1);
- if (srt == 0)
- {
- return val;
- }
- if (srt < 0)
- {
- top = val - 1;
- }
- else
- {
- bot = val + 1;
- }
- val = bot + (top - bot) / 2;
- }
- if (seek)
- {
- return UMAX(0, val);
- }
- return -1;
- }
- */
- int bsearch_alnum_list(struct listroot *root, char *text, int seek)
- {
- long double toi, toj;
- int bot, top, val, noi, noj, srt;
- push_call("bsearch_alpha_list(%p,%p,%d)",root,text,seek);
- if (seek == 0 && HAS_BIT(root->flags, LIST_FLAG_NEST))
- {
- switch (*text)
- {
- case '+':
- toi = get_number(root->ses, text);
- if (seek == 0)
- {
- if (toi > 0 && toi <= root->used)
- {
- pop_call();
- return toi - 1;
- }
- }
- else
- {
- if (toi >= 0 && toi <= root->used)
- {
- pop_call();
- return UMAX(0, toi - 1);
- }
- }
- break;
- case '-':
- toi = get_number(root->ses, text);
- if (toi < 0 && root->used + toi >= 0)
- {
- pop_call();
- return root->used + toi;
- }
- break;
- case '\\':
- text++;
- break;
- }
- }
- bot = 0;
- top = root->used - 1;
- val = top;
- noi = is_number(text);
- toi = noi ? tintoi(text) : 0;
- while (bot <= top)
- {
- noj = is_number(root->list[val]->arg1);
- toj = noj ? tintoi(root->list[val]->arg1) : 0;
- if (noi)
- {
- srt = !noj ? 1 : (toi < toj) ? -1 : (toi > toj) ? 1 : 0;
- }
- else if (noj)
- {
- srt = -1;
- }
- else
- {
- srt = strcmp(text, root->list[val]->arg1);
- }
- if (srt == 0)
- {
- pop_call();
- return val;
- }
- if (srt < 0)
- {
- top = val - 1;
- }
- else
- {
- bot = val + 1;
- }
- val = bot + (top - bot) / 2;
- }
- if (seek)
- {
- pop_call();
- return UMAX(0, val);
- }
- pop_call();
- return -1;
- }
- /*
- Binary search on priorially and alphabetically sorted list
- */
- int bsearch_priority_list(struct listroot *root, char *text, char *priority, int seek)
- {
- int bot, top, val;
- long double prt, srt;
- bot = 0;
- top = root->used - 1;
- val = top;
- prt = tintoi(priority);
- while (bot <= top)
- {
- srt = tintoi(root->list[val]->arg3);
- if (srt == prt)
- {
- srt = strcmp(text, root->list[val]->arg1);
- if (srt == 0)
- {
- return val;
- }
- if (srt < 0)
- {
- top = val - 1;
- }
- else
- {
- bot = val + 1;
- }
- }
- else
- {
- if (prt < srt)
- {
- top = val - 1;
- }
- else
- {
- bot = val + 1;
- }
- }
- val = bot + (top - bot) / 2;
- }
- if (seek)
- {
- return UMAX(0, val);
- }
- else
- {
- return -1;
- }
- }
- /*
- Linear search
- */
- int nsearch_list(struct listroot *root, char *text)
- {
- int i;
- for (i = 0 ; i < root->used ; i++)
- {
- if (!strcmp(text, root->list[i]->arg1))
- {
- return i;
- }
- }
- return -1;
- }
- /*
- show content of a node on screen
- */
- void show_node(struct listroot *root, struct listnode *node, int level)
- {
- char *str_arg2;
- push_call("show_node(%p,%p,%d)",root,node,level);
- str_arg2 = str_alloc_stack(0);
- show_nest_node(node, &str_arg2, TRUE);
- switch (list_table[root->type].args)
- {
- case 4:
- tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2, node->arg3, node->arg4);
- break;
- case 3:
- if (list_table[root->type].priority_arg == 3 && !strcmp(node->arg3, "5"))
- {
- tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2);
- }
- else
- {
- tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2, node->arg3);
- }
- break;
- case 2:
- tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "} {" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1, str_arg2);
- break;
- case 1:
- tintin_printf2(root->ses, "%s" COLOR_TINTIN "#" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}", indent(level), list_table[root->type].name, node->arg1);
- break;
- }
- pop_call();
- return;
- }
- /*
- list content of a list on screen
- */
- void show_list(struct listroot *root, int level)
- {
- int i;
- if (root == root->ses->list[root->type])
- {
- tintin_header(root->ses, 80, " %s ", list_table[root->type].name_multi);
- }
- for (i = 0 ; i < root->used ; i++)
- {
- show_node(root, root->list[i], level);
- }
- }
- int show_node_with_wild(struct session *ses, char *text, struct listroot *root)
- {
- struct listnode *node;
- int index, found = FALSE;
- push_call("show_node_with_wild(%p,%p,%p)",ses,text,root);
- switch (list_table[root->type].mode)
- {
- case SORT_ALPHA:
- case SORT_STABLE:
- index = bsearch_alpha_list(root, text, 0);
- break;
- case SORT_ALNUM:
- index = bsearch_alnum_list(root, text, 0);
- break;
- default:
- index = nsearch_list(root, text);
- break;
- }
- if (index != -1)
- {
- node = root->list[index];
- if (list_table[root->type].script_arg == 2)
- {
- if (list_table[root->type].args == 2)
- {
- tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2));
- }
- else if (list_table[root->type].args == 3)
- {
- if (list_table[root->type].priority_arg == 3)
- {
- if (!strcmp(node->arg3, "5"))
- {
- tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2));
- }
- else
- {
- tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n{" COLOR_STRING "%s" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2), node->arg3);
- }
- }
- else
- {
- tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n{" COLOR_STRING "%s" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2), node->arg3);
- }
- }
- }
- else
- {
- show_node(root, node, 0);
- }
- switch(root->type)
- {
- // case LIST_EVENT:
- // case LIST_FUNCTION:
- // case LIST_MACRO:
- // tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2));
- // break;
- // case LIST_ACTION:
- // case LIST_ALIAS:
- // case LIST_BUTTON:
- // if (!strcmp(node->arg3, "5"))
- // {
- // tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2));
- // }
- // else
- // {
- // tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n{" COLOR_STRING "%s" COLOR_BRACE "}\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2), node->arg3);
- // }
- // break;
- // case LIST_DELAY:
- // case LIST_TICKER:
- // tintin_printf2(ses, COLOR_TINTIN "%c" COLOR_COMMAND "%s " COLOR_BRACE "{" COLOR_STRING "%s" COLOR_BRACE "}\n{\n" COLOR_STRING "%s\n" COLOR_BRACE "}\n{" COLOR_STRING "%s" COLOR_BRACE "}\n\n", gtd->tintin_char, list_table[root->type].name, node->arg1, script_viewer(ses, node->arg2), node->arg3);
- // break;
- // default:
- // show_node(root, node, 0);
- // break;
- }
- pop_call();
- return TRUE;
- }
- for (index = 0 ; index < root->used ; index++)
- {
- if (match(ses, root->list[index]->arg1, text, SUB_VAR|SUB_FUN))
- {
- show_node(root, root->list[index], 0);
- found = TRUE;
- }
- }
- pop_call();
- return found;
- }
- int delete_node_with_wild(struct session *ses, int type, char *text)
- {
- struct listroot *root = ses->list[type];
- struct listnode *node;
- char arg1[BUFFER_SIZE];
- int index, found = FALSE;
- sub_arg_in_braces(ses, text, arg1, GET_ALL, SUB_VAR|SUB_FUN);
- switch (list_table[type].mode)
- {
- case SORT_ALPHA:
- case SORT_STABLE:
- index = bsearch_alpha_list(root, arg1, 0);
- break;
- case SORT_ALNUM:
- index = bsearch_alnum_list(root, arg1, 0);
- break;
- default:
- index = nsearch_list(root, arg1);
- break;
- }
- if (index != -1)
- {
- node = root->list[index];
- show_message(ses, type, "#OK. {%s} IS NO LONGER %s %s.", node->arg1, (*list_table[type].name == 'A' || *list_table[type].name == 'E') ? "AN" : "A", list_table[type].name);
- delete_index_list(root, index);
- return TRUE;
- }
- for (index = root->used - 1 ; index >= 0 ; index--)
- {
- if (match(ses, root->list[index]->arg1, arg1, SUB_VAR|SUB_FUN))
- {
- show_message(ses, type, "#OK. {%s} IS NO LONGER %s %s.", root->list[index]->arg1, is_vowel(list_table[type].name) ? "AN" : "A", list_table[type].name);
- delete_index_list(root, index);
- found = TRUE;
- }
- }
- if (found == 0)
- {
- show_message(ses, type, "#KILL: NO MATCHES FOUND FOR %s {%s}.", list_table[type].name, arg1);
- return FALSE;
- }
- return TRUE;
- }
- DO_COMMAND(do_killall)
- {
- tintin_printf2(ses, "\e[1;31m#NOTICE: PLEASE CHANGE #KILLALL TO #KILL ALL.");
- do_kill(ses, arg, arg1, arg2, arg3, arg4);
- return ses;
- }
- DO_COMMAND(do_kill)
- {
- int index;
- arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
- get_arg_in_braces(ses, arg, arg2, GET_ALL);
- if (*arg1 == 0 || !strcasecmp(arg1, "ALL"))
- {
- for (index = 0 ; index < LIST_MAX ; index++)
- {
- if (index == LIST_PATHDIR)
- {
- continue;
- }
- if (!HAS_BIT(ses->list[index]->flags, LIST_FLAG_HIDE))
- {
- kill_list(ses->list[index]);
- }
- }
- show_message(ses, LIST_COMMAND, "#KILL - ALL LISTS CLEARED.");
- return ses;
- }
- for (index = 0 ; index < LIST_MAX ; index++)
- {
- if (!is_abbrev(arg1, list_table[index].name) && !is_abbrev(arg1, list_table[index].name_multi))
- {
- continue;
- }
- if (*arg2 == 0 || !strcasecmp(arg2, "ALL"))
- {
- kill_list(ses->list[index]);
- show_message(ses, LIST_COMMAND, "#OK: #%s LIST CLEARED.", list_table[index].name);
- }
- else
- {
- delete_node_with_wild(ses, index, arg);
- }
- break;
- }
- if (index == LIST_MAX)
- {
- show_error(ses, LIST_COMMAND, "#ERROR: #KILL {%s} {%s} - NO MATCH FOUND.", arg1, arg2);
- }
- return ses;
- }
- DO_COMMAND(do_message)
- {
- int index, found = FALSE;
- arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
- arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
- if (*arg1 == 0)
- {
- tintin_header(ses, 80, " MESSAGES ");
- for (index = 0 ; index < LIST_MAX ; index++)
- {
- if (!HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
- {
- tintin_printf2(ses, " %-20s %3s", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE) ? "ON" : "OFF");
- }
- }
- tintin_header(ses, 80, "");
- }
- else
- {
- for (index = found = 0 ; index < LIST_MAX ; index++)
- {
- if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
- {
- continue;
- }
- if (!is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
- {
- continue;
- }
- if (*arg2 == 0)
- {
- TOG_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE);
- }
- else if (is_abbrev(arg2, "ON"))
- {
- SET_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE);
- }
- else if (is_abbrev(arg2, "OFF"))
- {
- DEL_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE);
- }
- else
- {
- show_error(ses, LIST_COMMAND, "#SYNTAX: #MESSAGE {%s} [ON|OFF]", arg1);
-
- return ses;
- }
- show_message(ses, LIST_COMMAND, "#OK: #MESSAGE STATUS FOR %s HAS BEEN SET TO: %s.", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE) ? "ON" : "OFF");
- found = TRUE;
- }
- if (found == FALSE)
- {
- show_error(ses, LIST_COMMAND, "#ERROR: #MESSAGE {%s} - NO MATCH FOUND.", arg1);
- }
- }
- return ses;
- }
- DO_COMMAND(do_ignore)
- {
- int index, found = FALSE;
- arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
- arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
- if (*arg1 == 0)
- {
- tintin_header(ses, 80, " IGNORES ");
- for (index = 0 ; index < LIST_MAX ; index++)
- {
- if (!HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
- {
- tintin_printf2(ses, " %-20s %3s", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE) ? "ON" : "OFF");
- }
- }
- tintin_header(ses, 80, "");
- }
- else
- {
- for (index = found = 0 ; index < LIST_MAX ; index++)
- {
- if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
- {
- continue;
- }
- if (!is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
- {
- continue;
- }
- if (*arg2 == 0)
- {
- TOG_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE);
- }
- else if (is_abbrev(arg2, "ON"))
- {
- SET_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE);
- }
- else if (is_abbrev(arg2, "OFF"))
- {
- DEL_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE);
- }
- else
- {
- show_error(ses, LIST_COMMAND, "#SYNTAX: #IGNORE {%s} [ON|OFF]", arg1);
-
- return ses;
- }
- show_message(ses, LIST_COMMAND, "#OK: #IGNORE STATUS FOR %s HAS BEEN SET TO: %s.", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE) ? "ON" : "OFF");
- found = TRUE;
- }
- if (found == FALSE)
- {
- show_error(ses, LIST_COMMAND, "#ERROR: #IGNORE {%s} - NO MATCH FOUND.", arg1);
- }
- }
- return ses;
- }
- DO_COMMAND(do_debug)
- {
- int index, found = FALSE;
- arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
- arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
- if (*arg1 == 0)
- {
- tintin_header(ses, 80, " DEBUGS ");
- for (index = 0 ; index < LIST_MAX ; index++)
- {
- if (!HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
- {
- tintin_printf2(ses, " %-20s %3s", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG) ? "ON" : "OFF");
- }
- }
- tintin_header(ses, 80, "");
- }
- else
- {
- for (index = found = 0 ; index < LIST_MAX ; index++)
- {
- if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
- {
- continue;
- }
- if (!is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
- {
- continue;
- }
- if (*arg2 == 0)
- {
- TOG_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG);
- }
- else if (is_abbrev(arg2, "ON"))
- {
- SET_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG);
- }
- else if (is_abbrev(arg2, "OFF"))
- {
- DEL_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG);
- DEL_BIT(ses->list[index]->flags, LIST_FLAG_LOG);
- }
- else if (is_abbrev(arg2, "LOG"))
- {
- SET_BIT(ses->list[index]->flags, LIST_FLAG_LOG);
- }
- else
- {
- show_error(ses, LIST_COMMAND, "#SYNTAX: #DEBUG {%s} [ON|OFF|LOG]", arg1);
-
- return ses;
- }
- show_message(ses, LIST_COMMAND, "#OK: #DEBUG STATUS FOR %s HAS BEEN SET TO: %s.", list_table[index].name_multi, is_abbrev(arg2, "LOG") ? "LOG" : HAS_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG) ? "ON" : "OFF");
- found = TRUE;
- }
- if (found == FALSE)
- {
- show_error(ses, LIST_COMMAND, "#DEBUG {%s} - NO MATCH FOUND.", arg1);
- }
- }
- return ses;
- }
- DO_COMMAND(do_info)
- {
- char name[BUFFER_SIZE];
- int cnt, index, found = FALSE;
- struct listroot *root;
- arg = get_arg_in_braces(ses, arg, arg1, GET_ONE);
- arg = get_arg_in_braces(ses, arg, arg2, GET_ONE);
- if (*arg1 == 0)
- {
- tintin_header(ses, 80, " INFORMATION ");
- for (index = 0 ; index < LIST_MAX ; index++)
- {
- if (!HAS_BIT(ses->list[index]->flags, LIST_FLAG_HIDE))
- {
- tintin_printf2(ses, "%-15s %5d IGNORE %3s MESSAGE %3s INFO %3s DEBUG %3s%s",
- list_table[index].name_multi,
- ses->list[index]->used,
- HAS_BIT(ses->list[index]->flags, LIST_FLAG_IGNORE) ? "ON" : "OFF",
- HAS_BIT(ses->list[index]->flags, LIST_FLAG_MESSAGE) ? "ON" : "OFF",
- HAS_BIT(ses->list[index]->flags, LIST_FLAG_INFO) ? "ON" : "OFF",
- HAS_BIT(ses->list[index]->flags, LIST_FLAG_DEBUG) ? "ON" : "OFF",
- HAS_BIT(ses->list[index]->flags, LIST_FLAG_LOG) ? " LOG" : "");
- }
- }
- tintin_header(ses, 80, "");
- }
- else
- {
- for (index = found = 0 ; index < LIST_MAX ; index++)
- {
- if (HAS_BIT(list_table[index].flags, LIST_FLAG_HIDE))
- {
- continue;
- }
- if (!is_abbrev(arg1, list_table[index].name_multi) && strcasecmp(arg1, "ALL"))
- {
- continue;
- }
- if (*arg2 == 0)
- {
- TOG_BIT(ses->list[index]->flags, LIST_FLAG_INFO);
- }
- else if (is_abbrev(arg2, "ON"))
- {
- SET_BIT(ses->list[index]->flags, LIST_FLAG_INFO);
- }
- else if (is_abbrev(arg2, "OFF"))
- {
- DEL_BIT(ses->list[index]->flags, LIST_FLAG_INFO);
- }
- else
- {
- root = ses->list[index];
- if (is_abbrev(arg2, "LIST"))
- {
- for (cnt = 0 ; cnt < root->used ; cnt++)
- {
- tintin_printf2(ses, "#INFO %s %4d {arg1}{%s} {arg2}{%s} {arg3}{%s} {arg4}{%s} {class}{%s} {shots}{%u}", list_table[index].name_multi, cnt+1, root->list[cnt]->arg1, root->list[cnt]->arg2, root->list[cnt]->arg3, root->list[cnt]->arg4, root->list[cnt]->group, root->list[cnt]->shots);
- }
- }
- else if (is_abbrev(arg2, "SAVE"))
- {
- sprintf(name, "info[%s]", list_table[index].name_multi);
- set_nest_node_ses(ses, name, "");
- for (cnt = 0 ; cnt < root->used ; cnt++)
- {
- sprintf(name, "info[%s][%d]", list_table[index].name_multi, cnt + 1);
- set_nest_node_ses(ses, name, "{arg1}{%s}{arg2}{%s}{arg3}{%s}{arg4}{%s}{class}{%s}{nest}{%d}{shots}{%u}", root->list[cnt]->arg1, root->list[cnt]->arg2, root->list[cnt]->arg3, root->list[cnt]->arg4, root->list[cnt]->group, root->list[cnt]->root ? root->list[cnt]->root->used : 0, root->list[cnt]->shots);
- }
- show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[%s]}", list_table[index].name_multi);
- }
- else
- {
- show_error(ses, LIST_COMMAND, "#SYNTAX: #INFO {%s} [ON|OFF|LIST|SAVE|SYSTEM]", arg1);
- }
- return ses;
- }
- show_message(ses, LIST_COMMAND, "#OK: #INFO STATUS FOR %s HAS BEEN SET TO: %s.", list_table[index].name_multi, HAS_BIT(ses->list[index]->flags, LIST_FLAG_INFO) ? "ON" : "OFF");
- if (strcasecmp(arg1, "ALL"))
- {
- return ses;
- }
- found = TRUE;
- }
- if (found)
- {
- return ses;
- }
- *gtd->is_result = 0;
- switch (*arg1 % 32)
- {
- case CTRL_A:
- if (is_abbrev(arg1, "ARGUMENTS"))
- {
- if (is_abbrev(arg2, "SAVE"))
- {
- set_nest_node_ses(ses, "info[ARGUMENTS]", "");
- for (index = 0 ; index < gtd->varc ; index++)
- {
- add_nest_node_ses(ses, "info[ARGUMENTS]", "{%d}{%s}", index, gtd->vars[index]);
- }
- }
- else
- {
- for (index = 0 ; index < gtd->varc ; index++)
- {
- tintin_printf2(ses, "#INFO ARGUMENTS: %2d: %s", index, gtd->vars[index]);
- }
- }
- }
- break;
- case CTRL_B:
- if (is_abbrev(arg1, "BIG5TOUTF8"))
- {
- big5toutf8_info(ses);
- }
- break;
- case CTRL_C:
- if (is_abbrev(arg1, "CPU"))
- {
- show_cpu(ses);
- }
- break;
- case CTRL_D:
- if (is_abbrev(arg1, "DAEMON"))
- {
- if (is_abbrev(arg2, "SAVE"))
- {
- sprintf(name, "info[DAEMON]");
- set_nest_node_ses(ses, name, "{DETACH_FILE}{%s}{ATTACH_FILE}{%s}", gtd->detach_port > 0 ? gtd->detach_file : "", gtd->attach_sock > 0 ? gtd->attach_file : "");
- show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[SYSTEM]}");
- }
- else
- {
- tintin_printf2(ses, "#INFO DAEMON: DETACH UID = %d", gtd->detach_info.uid);
- tintin_printf2(ses, "#INFO DAEMON: DETACH GID = %d", gtd->detach_info.gid);
- tintin_printf2(ses, "#INFO DAEMON: DETACH PID = %d", gtd->detach_info.pid);
- tintin_printf2(ses, "#INFO DAEMON: DETACH_SOCK = %d", gtd->detach_sock);
- tintin_printf2(ses, "#INFO DAEMON: DETACH_PORT = %d", gtd->detach_port);
- tintin_printf2(ses, "#INFO DAEMON: DETACH_FILE = %s", gtd->detach_port ? gtd->detach_file : "");
- tintin_printf2(ses, "#INFO DAEMON: ATTACH_SOCK = %d", gtd->attach_sock);
- tintin_printf2(ses, "#INFO DAEMON: ATTACH_FILE = %s", gtd->attach_sock ? gtd->attach_file : "");
- }
- }
- break;
- case CTRL_E:
- if (is_abbrev(arg1, "ENVIRON"))
- {
- char **env, *sep;
- if (is_abbrev(arg2, "SAVE"))
- {
- set_nest_node_ses(ses, "info[ENVIRON]", "");
- for (env = environ ; *env ; env++)
- {
- sep = strchr(*env, '=');
- *sep = 0;
- add_nest_node_ses(ses, "info[ENVIRON]", "{%s}{%s}", *env, sep + 1);
- *sep = '=';
- }
- }
- else
- {
- for (env = environ ; *env ; env++)
- {
- tintin_printf2(ses, "%s", *env);
- }
- }
- }
- break;
- case CTRL_I:
- if (is_abbrev(arg1, "INPUT"))
- {
- if (is_abbrev(arg2, "SAVE"))
- {
- set_nest_node_ses(ses, "info[INPUT]", "{BUFFER}{%s}", gtd->ses->input->buf);
- add_nest_node_ses(ses, "info[INPUT]", "{CUT}{%s}", gtd->ses->input->cut);
- add_nest_node_ses(ses, "info[INPUT]", "{COL}{%d}", inputline_cur_col());
- add_nest_node_ses(ses, "info[INPUT]", "{HEIGHT}{%d}", inputline_max_row());
- add_nest_node_ses(ses, "info[INPUT]", "{LENGTH}{%d}", inputline_cur_str_len());
- add_nest_node_ses(ses, "info[INPUT]", "{NAME}{%s}", gtd->ses->input->line_name);
- add_nest_node_ses(ses, "info[INPUT]", "{OFFSET}{%d}", inputline_cur_off());
- add_nest_node_ses(ses, "info[INPUT]", "{ROW}{%d}", inputline_cur_row());
- add_nest_node_ses(ses, "info[INPUT]", "{WIDTH}{%d}", inputline_max_str_len());
- }
- else
- {
- tintin_printf2(ses, "#INFO INPUT: BUFFER: %s", gtd->ses->input->buf);
- tintin_printf2(ses, "#INFO INPUT: CUT: %s", gtd->ses->input->cut);
- tintin_printf2(ses, "#INFO INPUT: COL: %d", inputline_cur_col());
- tintin_printf2(ses, "#INFO INPUT: HEIGHT: %d", inputline_max_row());
- tintin_printf2(ses, "#INFO INPUT: LENGTH: %d", inputline_cur_str_len());
- tintin_printf2(ses, "#INFO INPUT: NAME: %s", gtd->ses->input->line_name);
- tintin_printf2(ses, "#INFO INPUT: OFFSET: %d", inputline_cur_off());
- tintin_printf2(ses, "#INFO INPUT: ROW: %d", inputline_cur_row());
- tintin_printf2(ses, "#INFO INPUT: WIDTH: %d", inputline_max_str_len());
- }
- }
- break;
- case CTRL_M:
- if (is_abbrev(arg1, "MATCHES"))
- {
- if (is_abbrev(arg2, "SAVE"))
- {
- set_nest_node_ses(ses, "info[MATCHES]", "");
- for (index = 0 ; index < gtd->cmdc ; index++)
- {
- add_nest_node_ses(ses, "info[MATCHES]", "{%d}{%s}", index, gtd->cmds[index]);
- }
- }
- else
- {
- for (index = 0 ; index < gtd->cmdc ; index++)
- {
- tintin_printf2(ses, "#INFO MATCHES: %2d: %s", index, gtd->cmds[index]);
- }
- }
- }
- else if (is_abbrev(arg1, "MCCP"))
- {
- if (ses->mccp2)
- {
- tintin_printf2(ses, "#INFO MCCP2: TOTAL IN: %9u TOTAL OUT: %9u PERCENT: %3d", ses->mccp2->total_in, ses->mccp2->total_out, ses->mccp2->total_out ? 100 * ses->mccp2->total_in / ses->mccp2->total_out : 0);
- }
- if (ses->mccp3)
- {
- tintin_printf2(ses, "#INFO MCCP3: TOTAL IN: %9u TOTAL OUT: %9u PERCENT: %3d", ses->mccp3->total_in, ses->mccp3->total_out, ses->mccp3->total_in ? 100 * ses->mccp3->total_out / ses->mccp3->total_in : 0);
- }
- }
- else if (is_abbrev(arg1, "MEMORY"))
- {
- struct str_data *str_ptr;
- long long quan, used, max;
- max = 0;
- quan = 0;
- used = 0;
- for (index = 0 ; index < gtd->memory->stack_cap ; index++)
- {
- max++;
- quan += gtd->memory->stack[index]->max;
- used += gtd->memory->stack[index]->len;
- }
- tintin_printf2(ses, "#INFO MEMORY: STACK SIZE: %d", quan);
- tintin_printf2(ses, "#INFO MEMORY: STACK MAX: %d", gtd->memory->stack_max);
- tintin_printf2(ses, "#INFO MEMORY: STACK CAP: %d", gtd->memory->stack_cap);
- tintin_printf2(ses, "#INFO MEMORY: STACK LEN: %d", gtd->memory->stack_len);
- tintin_printf2(ses, "");
- max = 0;
- quan = 0;
- used = 0;
- for (index = 0 ; index < gtd->memory->list_len ; index++)
- {
- str_ptr = gtd->memory->list[index];
- if (str_ptr->max != NAME_SIZE + 1 && strlen(get_str_str(str_ptr)) != str_ptr->len)
- {
- tintin_printf2(ses, "#ERROR: index %d len = %d/%d max = %d flags = %d (%s)", index, strlen(get_str_str(str_ptr)), str_ptr->len, str_ptr->max, str_ptr->flags, get_str_str(str_ptr));
- }
- if (!HAS_BIT(str_ptr->flags, STR_FLAG_FREE))
- {
- max++;
- quan += str_ptr->max;
- used += str_ptr->len;
- }
- }
- tintin_printf2(ses, "#INFO MEMORY: ALLOC SIZE: %d", quan);
- tintin_printf2(ses, "#INFO MEMORY: ALLOC USED: %d", used);
- tintin_printf2(ses, "#INFO MEMORY: ALLOC MAX: %d", gtd->memory->list_max);
- tintin_printf2(ses, "#INFO MEMORY: ALLOC LEN: %d", gtd->memory->list_len);
- tintin_printf2(ses, "");
- quan = 0;
- used = 0;
- for (index = 0 ; index < gtd->memory->free_len ; index++)
- {
- str_ptr = gtd->memory->list[gtd->memory->free[index]];
- if (HAS_BIT(str_ptr->flags, STR_FLAG_FREE))
- {
- quan += str_ptr->max;
- used += str_ptr->len;
- }
- else
- {
- tintin_printf2(ses, "error: found freed memory not marked as free.");
- }
- }
- tintin_printf2(ses, "#INFO MEMORY: FREED SIZE: %d", quan);
- tintin_printf2(ses, "#INFO MEMORY: FREED MAX: %d", gtd->memory->free_max);
- tintin_printf2(ses, "#INFO MEMORY: FREED LEN: %d", gtd->memory->free_len);
- tintin_printf2(ses, "");
- quan = 0;
- used = 0;
- for (index = 0 ; index < gtd->memory->debug_len ; index++)
- {
- quan += NAME_SIZE;
- }
- tintin_printf2(ses, "#INFO MEMORY: DEBUG SIZE: %d", quan);
- tintin_printf2(ses, "#INFO MEMORY: DEBUG MAX: %d", gtd->memory->debug_max);
- tintin_printf2(ses, "#INFO MEMORY: DEBUG LEN: %d", gtd->memory->debug_len);
- }
- break;
- case CTRL_S:
- if (is_abbrev(arg1, "SESSION"))
- {
- if (is_abbrev(arg2, "SAVE"))
- {
- set_nest_node_ses(ses, "info[SESSION]", "{NAME}{%s}", ses->name);
- add_nest_node_ses(ses, "info[SESSION]", "{ACTIVE}{%d}", gtd->ses == ses);
- add_nest_node_ses(ses, "info[SESSION]", "{CLASS}{%s}", ses->group);
- add_nest_node_ses(ses, "info[SESSION]", "{CREATED}{%d}", ses->created);
- add_nest_node_ses(ses, "info[SESSION]", "{HOST} {%s}", ses->session_host);
- add_nest_node_ses(ses, "info[SESSION]", "{IP} {%s}", ses->session_ip);
- add_nest_node_ses(ses, "info[SESSION]", "{PORT} {%s}", ses->session_port);
- show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[SESSION]}");
- }
- else
- {
- tintin_printf2(ses, "{NAME}{%s}", ses->name);
- tintin_printf2(ses, "{ACTIVE}{%d}", gtd->ses == ses);
- tintin_printf2(ses, "{CLASS}{%s}", ses->group);
- tintin_printf2(ses, "{CREATED}{%d}", ses->created);
- tintin_printf2(ses, "{HOST} {%s}", ses->session_host);
- tintin_printf2(ses, "{IP} {%s}", ses->session_ip);
- tintin_printf2(ses, "{PORT} {%s}", ses->session_port);
- }
- }
- else if (is_abbrev(arg1, "SESSIONS"))
- {
- struct session *sesptr;
- if (is_abbrev(arg2, "SAVE"))
- {
- set_nest_node_ses(ses, "info[SESSIONS]", "");
- for (sesptr = gts ; sesptr ; sesptr = sesptr->next)
- {
- sprintf(name, "info[SESSIONS][%s]", sesptr->name);
- add_nest_node_ses(ses, name, "{NAME}{%s}", sesptr->name);
- add_nest_node_ses(ses, name, "{ACTIVE}{%d}", gtd->ses == sesptr);
- add_nest_node_ses(ses, name, "{CLASS}{%s}", sesptr->group);
- add_nest_node_ses(ses, name, "{CREATED}{%d}", sesptr->created);
- add_nest_node_ses(ses, name, "{HOST} {%s}", sesptr->session_host);
- add_nest_node_ses(ses, name, "{IP} {%s}", sesptr->session_ip);
- add_nest_node_ses(ses, name, "{PORT} {%s}", sesptr->session_port);
- }
- show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[SESSIONS]}");
- }
- else
- {
- for (sesptr = gts ; sesptr ; sesptr = sesptr->next)
- {
- tintin_printf2(ses, "{%s}{NAME}{%s}", sesptr->name, sesptr->name);
- tintin_printf2(ses, "{%s}{ACTIVE}{%d}", sesptr->name, gtd->ses == sesptr);
- tintin_printf2(ses, "{%s}{CLASS}{%s}", sesptr->name, sesptr->group);
- tintin_printf2(ses, "{%s}{CREATED}{%d}", sesptr->name, sesptr->created);
- tintin_printf2(ses, "{%s}{HOST} {%s}", sesptr->name, sesptr->session_host);
- tintin_printf2(ses, "{%s}{IP} {%s}", sesptr->name, sesptr->session_ip);
- tintin_printf2(ses, "{%s}{PORT} {%s}", sesptr->name, sesptr->session_port);
- }
- }
- }
- else if (is_abbrev(arg1, "STACK"))
- {
- dump_stack();
- }
- else if (is_abbrev(arg1, "SYSTEM"))
- {
- char cwd[PATH_MAX];
- if (getcwd(cwd, PATH_MAX) == NULL)
- {
- syserr_printf(ses, "do_info: getcwd:");
- cwd[0] = 0;
- }
- if (is_abbrev(arg2, "SAVE"))
- {
- sprintf(name, "info[SYSTEM]");
- set_nest_node_ses(ses, name, "{CLIENT_NAME}{%s}{CLIENT_VERSION}{%s}", CLIENT_NAME, CLIENT_VERSION);
- add_nest_node_ses(ses, name, "{CWD}{%s}{EXEC}{%s}{HOME}{%s}{LANG}{%s}{OS}{%s}{PID}{%d}{TERM}{%s}{TINTIN}{%s}", cwd, gtd->system->exec, gtd->system->home, gtd->system->lang, gtd->system->os, getpid(), gtd->system->term, gtd->system->tt_dir);
- add_nest_node_ses(ses, name, "{DETACH_FILE}{%s}{ATTACH_FILE}{%s}", gtd->detach_port > 0 ? gtd->detach_file : "", gtd->attach_sock > 0 ? gtd->attach_file : "");
- show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[SYSTEM]}");
- }
- else
- {
- tintin_printf2(ses, "#INFO SYSTEM: CLIENT_NAME = %s", CLIENT_NAME);
- tintin_printf2(ses, "#INFO SYSTEM: CLIENT_VERSION = %s", CLIENT_VERSION);
- tintin_printf2(ses, "#INFO SYSTEM: CWD = %s", cwd);
- tintin_printf2(ses, "#INFO SYSTEM: EXEC = %s", gtd->system->exec);
- tintin_printf2(ses, "#INFO SYSTEM: HOME = %s", gtd->system->home);
- tintin_printf2(ses, "#INFO SYSTEM: LANG = %s", gtd->system->lang);
- tintin_printf2(ses, "#INFO SYSTEM: OS = %s", gtd->system->os);
- tintin_printf2(ses, "#INFO SYSTEM: PID = %d", getpid());
- tintin_printf2(ses, "#INFO SYSTEM: TERM = %s", gtd->system->term);
- tintin_printf2(ses, "#INFO SYSTEM: TINTIN = %s", gtd->system->tt_dir);
- }
- }
- break;
- case CTRL_T:
- if (is_abbrev(arg1, "TOKENIZER"))
- {
- int index = URANGE(0, gtd->script_index + atoi(arg2), gtd->script_index);
- struct scriptroot *root = gtd->script_stack[index];
- tintin_printf2(ses, "#INFO TOKENIZER: SCRIPT_INDEX = %d", index);
- tintin_printf2(ses, "#INFO TOKENIZER: SESSION_NAME = %s", root->ses->name);
- tintin_printf2(ses, "#INFO TOKENIZER: LIST_TYPE = %s", list_table[root->list].name);
- tintin_printf2(ses, "#INFO TOKENIZER: LOCAL_VARS = %d", root->local->used);
- tintin_printf2(ses, "#INFO TOKENIZER: SCRIPT =\n%s", view_script(ses, root));
- }
- break;
- case CTRL_U:
- if (is_abbrev(arg1, "UNICODE"))
- {
- int size, width, index;
- size = get_utf8_size(arg2);
- get_utf8_width(arg2, &width, NULL);
- get_utf8_index(arg2, &index);
- tintin_printf2(ses, "#INFO UNICODE: %s: is_utf8_head = %d (%s)", arg2, is_utf8_head(arg2), is_utf8_head(arg2) ? "true" : "false");
- tintin_printf2(ses, "#INFO UNICODE: %s: get_utf8_size = %d", arg2, size);
- tintin_printf2(ses, "#INFO UNICODE: %s: get_utf8_width = %d", arg2, width);
- tintin_printf2(ses, "#INFO UNICODE: %s: get_utf8_index = %d (decimal)", arg2, index);
- tintin_printf2(ses, "#INFO UNICODE: %s: get_utf8_index = %x (hexadecimal)", arg2, index);
- }
- else if (is_abbrev(arg1, "UTF8TOBIG5"))
- {
- utf8tobig5_info(ses);
- }
- break;
- }
- if (*gtd->is_result == 0)
- {
- show_error(ses, LIST_COMMAND, "#INFO {%s} - NO MATCH FOUND.", arg1);
- }
- }
- return ses;
- }
|