/****************************************************************************** * This file is part of TinTin++ * * * * Copyright 2004-2019 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)he K(I)cki(N) (T)ickin D(I)kumud Clie(N)t * * * * coded by Igor van den Hoven 2004 * ******************************************************************************/ #include "tintin.h" #define DO_ARRAY(array) struct session *array (struct session *ses, struct listnode *list, char *arg, char *var, char *arg1, char *arg2) extern DO_ARRAY(array_add); extern DO_ARRAY(array_clear); extern DO_ARRAY(array_collapse); extern DO_ARRAY(array_copy); extern DO_ARRAY(array_create); extern DO_ARRAY(array_delete); extern DO_ARRAY(array_explode); extern DO_ARRAY(array_filter); extern DO_ARRAY(array_find); extern DO_ARRAY(array_get); extern DO_ARRAY(array_indexate); extern DO_ARRAY(array_insert); extern DO_ARRAY(array_numerate); extern DO_ARRAY(array_order); extern DO_ARRAY(array_reverse); extern DO_ARRAY(array_refine); extern DO_ARRAY(array_set); extern DO_ARRAY(array_shuffle); extern DO_ARRAY(array_simplify); extern DO_ARRAY(array_size); extern DO_ARRAY(array_sort); extern DO_ARRAY(array_swap); extern DO_ARRAY(array_tokenize); typedef struct session *ARRAY(struct session *ses, struct listnode *list, char *arg, char *var, char *arg1, char *arg2); struct array_type { char * name; ARRAY * fun; char * desc; }; struct array_type array_table[] = { { "ADD", array_add, "Add items to a list" }, { "CLEAR", array_clear, "Clear a list" }, { "CLR", array_clear, NULL }, { "COLLAPSE", array_collapse, "Collapse the list into a variable" }, { "COPY", array_copy, "Copy a list to a list" }, { "CREATE", array_create, "Create a list with given items" }, { "DELETE", array_delete, "Delete a list item with given index" }, { "EXPLODE", array_explode, "Explode the variable into a list" }, { "FILTER", array_filter, "Filter a list with given regex" }, { "FIND", array_find, "Find a list item with given regex" }, { "FND", array_find, NULL }, { "GET", array_get, "Retrieve a list item with given index" }, { "INDEXATE", array_indexate, "Indexate a list table for sorting" }, { "INSERT", array_insert, "Insert an item at given index" }, { "NUMERATE", array_numerate, "Turn a table into a list" }, { "ORDER", array_order, "Sort a list table numerically" }, { "LENGTH", array_size, NULL }, { "REFINE", array_refine, "Filter a list with given math" }, { "REVERSE", array_reverse, "Sort a list table in reverse order" }, { "SET", array_set, "Change a list item at given index" }, { "SHUFFLE", array_shuffle, "Sort a list table in random order" }, { "SIMPLIFY", array_simplify, "Turn a list table into a simple list" }, { "SIZE", array_size, NULL }, { "SORT", array_sort, "Sort a list table alphabetically" }, { "SRT", array_sort, NULL }, { "SWAP", array_swap, "Swap two list items" }, { "TOKENIZE", array_tokenize, "Create a list with given characters" }, { "", NULL, "" } }; DO_COMMAND(do_list) { struct listnode *node; int index, cnt; arg = sub_arg_in_braces(ses, arg, arg1, GET_NST, SUB_VAR|SUB_FUN); arg = sub_arg_in_braces(ses, arg, arg2, GET_ONE, SUB_VAR|SUB_FUN); if (*arg1 == 0) { tintin_header(ses, 80, " LIST OPTIONS "); for (index = 0 ; *array_table[index].fun ; index++) { if (array_table[index].desc && *array_table[index].name) { tintin_printf2(ses, " [%-24s] %s", array_table[index].name, array_table[index].desc); } } tintin_header(ses, 80, ""); } else if (*arg2 == 0) { show_error(ses, LIST_VARIABLE, "#SYNTAX: #LIST