/** /* $Id: oset.c,v 1.1 2001/08/03 08:56:07 ttk Exp $ /* OSET.C variable setting for orcus icb client /**/ #define _OSET_C_ #include "config.h" #include #include #include #include #include "orcus.h" #include "show.h" #include "defs.h" #include "oset.h" // #include "xt_tsf_t.h" static char *deletion; static int last_builtin = 0; extern int do_free_idlecmd; extern char *idlecmd; xt_oset_t oset_list; // oset variables // xt_tsf_t tsf_list; // timestamp formats int idlecmd_f ( char *buf ) { if ( buf == NULL ) return 1; if ( strlen(buf) < 1 ) return 0; if ( do_free_idlecmd ) scrub_free ( idlecmd, strlen ( idlecmd ) ); idlecmd = strdup ( buf ); do_free_idlecmd = 1; return 0; } static int nuking_index; // UGLY HACK -- SHOOT ME NOW! void oset_nuker ( oset_t *r ) { if ( r->type == 's' ) free ( *((char**)(r->d)) ); if ( nuking_index > last_builtin ) { free ( r->name ); free ( r->d ); } } int deletecmd_f ( char *cmd ) { int i, j, k; if ( cmd == NULL ) return 0; if ( strlen ( cmd ) < 1 ) return 0; for ( i = 0, j = -1, k = oset_list.n; ( i < k ) && ( j < 0 ); i++ ) if ( strcmp ( oset_list.d[i].name, cmd ) == 0 ) j = i; if ( j < 0 ) { oprint ( "[=ORCUS=] Cannot find variable named '%s'\n", cmd ); return 0; } nuking_index = j; xt_oset_del ( &(oset_list), j, (xt_oset_nuker_ft) oset_nuker ); if ( j <= last_builtin ) last_builtin--; oprint ( "[=ORCUS=] deleted variable named '%s'\n", cmd ); return 0; } /* terminating record has a type of 'X' */ oset_t oset_list_builtins[] = { { &rows, 'w', "rows", NULL }, { &cols, 'w', "cols", NULL }, { &nobeep, 'b', "nobeep", NULL }, { &bmessage, 'b', "bmessage", NULL }, { &breturn, 'b', "breturn", NULL }, { &bretnag, 's', "bretnag", NULL }, { &widle, 'b', "widle", NULL }, { &wdate, 'b', "wdate", NULL }, { &military, 'b', "military", NULL }, { &commandchar, 'c', "cc", NULL }, { &noidle, 'b', "noidle", NULL }, { &idleperiod, 'w', "idlep", NULL }, { &idlecmd, 's', "idlecmd", (oset_ft) idlecmd_f }, { &confirm_quit,'b', "confirmquit",NULL }, { &debug, 'b', "debug", NULL }, { &display_idle_threshold, 'w', "displayidle", NULL }, { &squelch_status,'w', "squelch", NULL }, { &no_tabhistory,'b', "no_tabhist",NULL }, { &stamping, 'w', "stamp", NULL }, // zzapp - 'b' when tsf works // { &stampmeth, 's', "stampmethod", NULL }, // { &stampform, 's', "stampformat", NULL }, { &logstate, 'b', "logging", NULL }, { &logfname, 's', "logname", NULL }, { &logtimes, 'w', "logtimes", NULL }, { &deletion, 'S', "delete", (oset_ft) deletecmd_f }, { NULL, 'X', "sentry", NULL } }; #define TSF_NOLEAD0 ((int)(0x0001)) /* No 0 at absolute position 0 */ #define TSF_NOLEADWS0 ((int)(0x0002)) /* No " 0" anywhere in string */ #define TSF_CLIP0 ((int)(0x0004)) /* Shorten string if 0 at pos 0 */ #define TSF_CLIPEND ((int)(0x0008)) /* Shorten string by 1 char on rt */ // zzapp /* tsf_t tsf_list_builtins[] = { // name pos format format modifications { "1", 1, "%H:%M ", TSF_NOLEAD0 }, { "on", 1, "%H:%M " TSF_NOLEAD0 }, { "2", 1, "%H:%M:%S ", TSF_NOLEAD0 }, { "3", 1, "%d %H:%M:%S ", TSF_NOLEAD0 | TSF_NOLEADWS0 }, { "4", 1, "%b %d %H:%M:%S ", TSF_NOLEADWS0 }, { "5", 1, "%a %b %d %H:%M:%S ", TSF_NOLEADWS0 }, { "6", 1, "%a %b %d %H:%M:%S %Y ", TSF_NOLEADWS0 }, { "dutra", 1, "%H:%M%P ", TSF_CLIP0 | TSF_CLIPEND }, { "mct", 1, "[%H:%M] ", 0 }, { "poly", 1, "%Y.%m.%d.%H:%M:%S ", 0 }, { "ttk", 1, "%Y-%m-%d.%H:%M:%S ", 0 }, { "cicb", 2, "[%H:%M]", 0 }, { "irc", 1, "%H%M ", TSF_NOLEAD0 }, { "zen", 1, "[time] %a %b %d %H:%M:%S %Y\n", TSF_NOLEADWS0 }, { NULL, 0, NULL, 0 } }; */ int oset_init() { int i; // tsf_t fmt; zzapp xt_oset_init ( &oset_list, 32 ); for ( i = 0; oset_list_builtins[i].type != 'X'; i++ ) xt_oset_addp ( &oset_list, &(oset_list_builtins[i]) ); last_builtin = i-1; deletion = strdup("'/oset delete ' to delete oset variable"); // zzapp // xt_tsf_init ( &tsf_list, 32 ); // for ( i = 0; tsf_list_builtins[i].name != NULL; i++ ) // xt_tsf_addp ( &tsf_list, &(tsf_list_builtins[i]) ); } char *oset_get ( char *name, char *type ) { int i, k; for ( i = 0, k = oset_list.n; i < k; i++ ) if ( strcmp ( oset_list.d[i].name, name ) == 0 ) { type[0] = oset_list.d[i].type; return ( oset_list.d[i].d ); } type[0] = 'X'; return NULL; } // FIXME -- expand on this int oset_cmd ( char *name, char *data ) { return -1; } int oset ( char *opt_, char *data ) { int i, j, k, k0; int n; char c; char *opt = opt_; char empty[1]; empty[0] = 0; if ( data == NULL ) { data = empty; } if ( strlen(data) > 1023 ) data[1023] = 0; // FIXME -- should warn! if ( opt == NULL ) opt = "?"; if ( ( opt[0] == '?' ) || ( opt[0] == 0 ) ) { oprint ("oset options: (w number, b bool, s str, i integer)\n"); for ( j = 0, k = oset_list.n; j < k; j++ ) { char *filler = ""; if ( strlen(oset_list.d[j].name) < 8 ) filler = " "; oprint ( "%s%s\t %c \t ", oset_list.d[j].name, filler, (unsigned char)(tolower(oset_list.d[j].type)) ); switch ( oset_list.d[j].type ) { case 'w': case 'W': case 'i': oprint ("%d\n",*((int*)(oset_list.d[j].d))); break; case 's': case 'S': if ( *((char**)(oset_list.d[j].d)) != NULL ) oprint ( "%s\n", *((char**)(oset_list.d[j].d)) ); else oprint ( "NULL\n" ); break; case 'b': if ( *((int*)(oset_list.d[j].d)) ) oprint ("TRUE\n"); else oprint ("FALSE\n"); break; case 'c': oprint ("%c\n", *((char*)(oset_list.d[j].d)) ); break; default: oprint ("?\n"); break; } /* end of switch */ } /* end of for */ return 0; } /* end of if opt[0] == '?' */ i = -1; for ( j = 0, k = oset_list.n; ( j < k ) && ( i < 0 ); j++ ) if ( strcasecmp ( oset_list.d[j].name, opt ) == 0 ) i = j; if ( i < 0 ) { // creating new variable oset_t r; r.d = (char**)malloc(sizeof(char*)); *((char**)(r.d)) = (char*)malloc(1024); // FIXME -- use xt_char type strcpy ( *((char**)(r.d)), data ); r.name = strdup ( opt ); r.type = 's'; r.func = NULL; xt_oset_addp ( &oset_list, &r ); return 0; } if ( strlen(data) < 1 ) { if ( oset_list.d[i].func != NULL ) return ( oset_list.d[i].func ( data ) ); return ( 0 ); } c = oset_list.d[i].type; if ( ( c == 'w' ) || ( c == 'W' ) || ( c == 'i' ) ) for ( j = 0, k0 = strlen ( data ); j < k0; j++ ) if ( ( data[j] < '0' ) && ( data[j] > '9' ) && ( data[j] != '-' ) ) return 0; if ( oset_list.d[i].func != NULL ) return ( oset_list.d[i].func ( data ) ); switch ( c ) { case 'b' : if ( strcasecmp ( data, "yes" ) == 0 ) *((int*)(oset_list.d[i].d)) = 1; else if ( strcasecmp ( data, "y" ) == 0 ) *((int*)(oset_list.d[i].d)) = 1; else if ( atoi ( data ) > 0 ) *((int*)(oset_list.d[i].d)) = 1; else *((int*)(oset_list.d[i].d)) = 0; break; case 's' : if ( *((char**)(oset_list.d[i].d)) != NULL ) scrub_free ( *((char**)(oset_list.d[i].d)), strlen(*((char**)(oset_list.d[i].d))) ); *((char**)(oset_list.d[i].d)) = strdup ( data ); break; case 'S' : if ( strlen ( data ) > 31 ) return 0; k0 = strlen ( *((char**)(oset_list.d[i].d)) ); for ( j = 0; j < k0; j++ ) (*((char**)oset_list.d[i].d))[j] = 0; strcpy ( oset_list.d[i].d, data ); break; case 'i' : *((int*)oset_list.d[i].d) = atoi ( data ); break; case 'w' : n = atoi ( data ); if ( n < 0 ) return 0; *((int*)oset_list.d[i].d) = n; break; case 'W' : n = atoi ( data ); if ( n < 1 ) return 0; *((int*)oset_list.d[i].d) = n; break; } return 1; } /* end of function oset() */