| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159 |
- /******************************************************************************
- * 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"
- 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,%p)",ses,sourcelist,type);
- 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->flags = sourcelist->list[i]->flags;
- 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:
- node->val16[0] = sourcelist->list[i]->val16[0];
- node->val16[1] = sourcelist->list[i]->val16[1];
- node->val16[2] = sourcelist->list[i]->val16[2];
- node->val16[3] = sourcelist->list[i]->val16[3];
- break;
- case LIST_VARIABLE:
- copy_nest_node(ses->list[type], node, sourcelist->list[i]);
- 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 *insert_node_list(struct listroot *root, char *arg1, char *arg2, char *arg3, char *arg4)
- {
- int index;
- struct listnode *node;
- node = (struct listnode *) calloc(1, sizeof(struct listnode));
- if (list_table[root->type].priority_arg == 3 && *arg3 == 0)
- {
- strcpy(arg3, "5");
- }
- node->arg1 = str_dup(arg1);
- node->arg2 = str_dup(arg2);
- node->arg3 = str_dup(arg3);
- node->arg4 = str_dup(arg4);
- if (gtd->level->oneshot)
- {
- SET_BIT(node->flags, NODE_FLAG_ONESHOT);
- }
- 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;
- }
- index = locate_index_list(root, arg1, 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)
- {
- if (list_table[root->type].mode == SORT_DELAY && is_number(arg1))
- {
- return insert_node_list(root, arg1, arg2, arg3, arg4);
- }
- node = root->list[index];
- if (gtd->level->oneshot)
- {
- SET_BIT(node->flags, NODE_FLAG_ONESHOT);
- }
- if (strcmp(node->arg2, arg2) != 0)
- {
- node->arg2 = str_cpy(&node->arg2, arg2);
- }
- switch (root->type)
- {
- case LIST_DELAY:
- case LIST_TICKER:
- node->val64 = 0;
- break;
- }
- if (list_table[root->type].priority_arg == 3 && *arg3 == 0)
- {
- strcpy(arg3, "5");
- }
- switch (list_table[root->type].mode)
- {
- case SORT_PRIORITY:
- if (atof(node->arg3) != atof(arg3))
- {
- delete_index_list(root, index);
- return insert_node_list(root, arg1, arg2, arg3, arg4);
- }
- break;
- case SORT_APPEND:
- delete_index_list(root, index);
- return insert_node_list(root, arg1, arg2, arg3, arg4);
- break;
- case SORT_ALPHA:
- case SORT_DELAY:
- if (strcmp(node->arg3, arg3) != 0)
- {
- str_cpy(&node->arg3, arg3);
- }
- break;
- default:
- tintin_printf2(root->ses, "#BUG: update_node_list: unknown mode: %d", list_table[root->type].mode);
- break;
- }
- return node;
- }
- else
- {
- return insert_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 *));
- }
- memmove(&root->list[index + 1], &root->list[index], (root->used - index) * sizeof(struct listnode *));
- root->list[index] = node;
- return node;
- }
- 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 (node->root)
- {
- free_list(node->root);
- }
- if (index <= root->update)
- {
- root->update--;
- }
- str_free(node->arg1);
- str_free(node->arg2);
- str_free(node->arg3);
- str_free(node->arg4);
- free(node->group);
- if (HAS_BIT(list_table[root->type].flags, LIST_FLAG_REGEX))
- {
- if (node->regex)
- {
- free(node->regex);
- }
- }
- switch (root->type)
- {
- case LIST_TERRAIN:
- free(node->room);
- break;
- case LIST_CLASS:
- if (node->data)
- {
- free(node->data);
- }
- break;
- }
- free(node);
- memmove(&root->list[index], &root->list[index + 1], (root->used - index) * sizeof(struct listnode *));
- root->used--;
- return;
- }
- 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_DELAY:
- index = bsearch_alpha_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)
- {
- if (list_table[root->type].mode == SORT_ALPHA || list_table[root->type].mode == SORT_DELAY)
- {
- return bsearch_alpha_list(root, text, 0);
- }
- if (list_table[root->type].mode == SORT_PRIORITY && priority)
- {
- return bsearch_priority_list(root, text, priority, 0);
- }
- 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:
- case SORT_DELAY:
- return bsearch_alpha_list(root, text, 1);
- case SORT_PRIORITY:
- return bsearch_priority_list(root, text, priority, 1);
- default:
- return root->used;
- }
- }
- /*
- binary search on alphabetically sorted list
- */
- int bsearch_alpha_list(struct listroot *root, char *text, int seek)
- {
- long long bot, top, val;
- long double toi, toj, srt;
- push_call("bsearch_alpha_list(%p,%p,%d)",root,text,seek);
- bot = 0;
- top = root->used - 1;
- val = top;
- // toi = get_number(root->ses, text);
- if (seek == 0 && (*text == '+' || *text == '-') && is_math(root->ses, text) && HAS_BIT(root->flags, LIST_FLAG_NEST))
- {
- toi = get_number(root->ses, text);
- if (toi > 0 && toi <= root->used)
- {
- pop_call();
- return toi - 1;
- }
- if (toi < 0 && toi + root->used >= 0)
- {
- pop_call();
- return root->used + toi;
- }
- else
- {
- pop_call();
- return -1;
- }
- }
- toi = is_number(text) ? tintoi(text) : 0;
- while (bot <= top)
- {
- toj = is_number(root->list[val]->arg1) ? tintoi(root->list[val]->arg1) : 0;
- if (toi)
- {
- srt = toi - toj;
- }
- else if (toj)
- {
- 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;
- double srt;
- bot = 0;
- top = root->used - 1;
- val = top;
- while (bot <= top)
- {
- srt = atof(priority) - atof(root->list[val]->arg3);
- if (!srt)
- {
- 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);
- }
- 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 = str_dup("");
- 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;
- }
- str_free(str_arg2);
- }
- /*
- 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, " %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 i, found = FALSE;
- push_call("show_node_with_wild(%p,%p,%p)",ses,text,root);
- node = search_node_list(root, text);
- if (node)
- {
- 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 (i = 0 ; i < root->used ; i++)
- {
- if (match(ses, root->list[i]->arg1, text, SUB_VAR|SUB_FUN))
- {
- show_node(root, root->list[i], 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 i, found = FALSE;
- sub_arg_in_braces(ses, text, arg1, GET_ALL, SUB_VAR|SUB_FUN);
- node = search_node_list(root, arg1);
- if (node)
- {
- 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_node_list(ses, type, node);
- return TRUE;
- }
- for (i = root->used - 1 ; i >= 0 ; i--)
- {
- if (match(ses, root->list[i]->arg1, arg1, SUB_VAR|SUB_FUN))
- {
- show_message(ses, type, "#OK. {%s} IS NO LONGER %s %s.", root->list[i]->arg1, (*list_table[type].name == 'A' || *list_table[type].name == 'E') ? "AN" : "A", list_table[type].name);
- delete_index_list(root, i);
- 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);
- return ses;
- }
- DO_COMMAND(do_kill)
- {
- char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
- 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 (!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)
- {
- char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
- 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, " 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, "");
- }
- 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) && !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: #%s MESSAGES HAVE BEEN SET TO: %s.", list_table[index].name, 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)
- {
- char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
- 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, " 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, "");
- }
- 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) && !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: #%s IGNORE STATUS HAS BEEN SET TO: %s.", list_table[index].name, 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)
- {
- char arg1[BUFFER_SIZE], arg2[BUFFER_SIZE];
- 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, " 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, "");
- }
- 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) && !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: #%s DEBUG STATUS HAS BEEN SET TO: %s.", list_table[index].name, 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 arg1[BUFFER_SIZE], arg2[BUFFER_SIZE], 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, " 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 %3s",
- 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, "");
- }
- 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) && !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} {flags}{%d}", list_table[index].name, cnt, root->list[cnt]->arg1, root->list[cnt]->arg2, root->list[cnt]->arg3, root->list[cnt]->arg4, root->list[cnt]->group, root->list[cnt]->flags);
- }
- }
- else if (is_abbrev(arg2, "SAVE"))
- {
- sprintf(name, "info[%s]", list_table[index].name);
- // delete_nest_node(ses->list[LIST_VARIABLE], name);
- for (cnt = 0 ; cnt < root->used ; cnt++)
- {
- sprintf(name, "info[%s][%d]", list_table[index].name, cnt);
- set_nest_node_ses(ses, name, "{arg1}{%s}{arg2}{%s}{arg3}{%s}{arg4}{%s}{class}{%s}{flags}{%d}", root->list[cnt]->arg1, root->list[cnt]->arg2, root->list[cnt]->arg3, root->list[cnt]->arg4, root->list[cnt]->group, root->list[cnt]->flags);
- }
- show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[%s]}", list_table[index].name);
- }
- else
- {
- show_error(ses, LIST_COMMAND, "#SYNTAX: #INFO {%s} [ON|OFF|LIST|SAVE|SYSTEM]", arg1);
- }
- return ses;
- }
- show_message(ses, LIST_COMMAND, "#OK: #%s INFO STATUS HAS BEEN SET TO: %s.", list_table[index].name, HAS_BIT(ses->list[index]->flags, LIST_FLAG_INFO) ? "ON" : "OFF");
- found = TRUE;
- }
- if (found == FALSE)
- {
- if (is_abbrev(arg1, "CPU"))
- {
- show_cpu(ses);
- }
- else if (is_abbrev(arg1, "MCCP"))
- {
- if (ses->mccp2)
- {
- tintin_printf2(ses, "#INFO MCCP2: TOTAL IN: %9ull TOTAL OUT: %9ull RATIO: %3d", ses->mccp2->total_in, ses->mccp2->total_out, 100 * ses->mccp2->total_out / ses->mccp2->total_in);
- }
- if (ses->mccp3)
- {
- tintin_printf2(ses, "#INFO MCCP3: TOTAL IN: %9ull TOTAL OUT: %9ull RATIO: %3d", ses->mccp3->total_in, ses->mccp3->total_out, 100 * ses->mccp3->total_out / ses->mccp3->total_in);
- }
- }
- else if (is_abbrev(arg1, "SESSION"))
- {
- if (is_abbrev(arg2, "SAVE"))
- {
- sprintf(name, "info[SESSION]");
- set_nest_node_ses(ses, name, "{SESSION_NAME}{%s}", ses->name);
- add_nest_node_ses(ses, name, "{SESSION_CLASS}{%s}", ses->group);
- add_nest_node_ses(ses, name, "{SESSION_CREATED}{%d}", ses->created);
- add_nest_node_ses(ses, name, "{SESSION_HOST} {%s}", ses->session_host);
- add_nest_node_ses(ses, name, "{SESSION_IP} {%s}", ses->session_ip);
- add_nest_node_ses(ses, name, "{SESSION_PORT} {%s}", ses->session_port);
- show_message(ses, LIST_COMMAND, "#INFO: DATA WRITTEN TO {info[SESSION]}");
- }
- else
- {
- tintin_printf2(ses, "{SESSION_NAME}{%s}", ses->name);
- tintin_printf2(ses, "{SESSION_CLASS}{%s}", ses->group);
- tintin_printf2(ses, "{SESSION_CREATED}{%d}", ses->created);
- tintin_printf2(ses, "{SESSION_HOST} {%s}", ses->session_host);
- tintin_printf2(ses, "{SESSION_IP} {%s}", ses->session_ip);
- tintin_printf2(ses, "{SESSION_PORT} {%s}", ses->session_port);
- }
- }
- else if (is_abbrev(arg1, "STACK"))
- {
- dump_stack();
- }
- else if (is_abbrev(arg1, "SYSTEM"))
- {
- 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, "{CLIENT}{{NAME}{%s}{VERSION}{%s}}", CLIENT_NAME, CLIENT_VERSION);
- add_nest_node_ses(ses, name, "{EXEC}{%s}{HOME}{%s}{LANG}{%s}{OS}{%s}{TERM}{%s}", gtd->exec, gtd->home, gtd->lang, gtd->os, gtd->term);
- 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: EXEC = %s", gtd->exec);
- tintin_printf2(ses, "#INFO SYSTEM: HOME = %s", gtd->home);
- tintin_printf2(ses, "#INFO SYSTEM: LANG = %s", gtd->lang);
- tintin_printf2(ses, "#INFO SYSTEM: OS = %s", gtd->os);
- tintin_printf2(ses, "#INFO SYSTEM: TERM = %s", gtd->term);
- tintin_printf2(ses, "#INFO SYSTEM: DETACH_PORT = %d", gtd->detach_port);
- tintin_printf2(ses, "#INFO SYSTEM: DETACH_FILE = %s", gtd->detach_port ? gtd->detach_file : "");
- tintin_printf2(ses, "#INFO SYSTEM: ATTACH_SOCK = %d", gtd->attach_sock);
- tintin_printf2(ses, "#INFO SYSTEM: ATTACH_FILE = %s", gtd->attach_sock ? gtd->attach_file : "");
- }
- }
- else
- {
- show_error(ses, LIST_COMMAND, "#INFO {%s} - NO MATCH FOUND.", arg1);
- }
- }
- }
- return ses;
- }
|