static int pwd (int argc,char **argv, void *data) { Node *pos = (Node *) data; cli_outfun (path_strip (node2path (pos))); cli_outfun ("\n"); return (int) pos; }
static int addc (int argc,char **argv, void *data) { Node *pos = (Node *) data; Node *tnode; if(argc==1){ cli_outfunf("usage: %s <entry> [new subentry]",argv[0]); return 0; } tnode = node_exact_match (argv[1], pos); if (!tnode) { cli_outfun ("specified parent not found"); return (int) pos; } if (node_right (tnode)) { tnode=node_bottom(tnode); } else { tnode=node_insert_right(tnode); } if(argc==2) node_set (tnode, TEXT, ""); else node_set (tnode, TEXT, argv[2]); return (int) pos; }
static int cd (int argc, char **argv, void *data) { Node *pos = (Node *) data; Node *tnode = pos; if(argc==1){ return (int)node_root(pos); } if (!strcmp (argv[1], "..")){ if (node_left (tnode) != 0) return (int) (node_left (tnode)); } tnode = path2node (argv[1], pos); if (tnode) { tnode = node_right (tnode); } if (!tnode) { cli_outfun ("no such node\n"); return (int) pos; } return (int) tnode; return (int) pos; }
void cli_outfunf(char *format, ...){ va_list arglist; char buf[128]; va_start( arglist, format ); vsnprintf(buf,127,format,arglist); va_end(arglist); buf[127]=0; cli_outfun(buf); }
static void* help (int argc,char **argv, void *data) { if (argc == 1) { /* show all help */ ItemT *titem = items; cli_outfunf ("available commands:"); while (titem) { #ifdef HIDE_NULL_HELP if(titem->usage) #endif if (is_command (titem)) cli_outfunf ("%14s %s", titem->name, titem->usage); titem = titem->next; }; } else { /* show help for specified command */ ItemT *titem = items; cli_outfunf ("HELP for '%s'", argv[1] ); while (titem) { if (is_command (titem)) { if (!strcmp (argv[1], titem->name)) { cli_outfunf ("usage: %s %s", titem->name, titem->usage); if(titem->help[0]){ cli_outfun (""); cli_outfun(titem->help); } return data; } } titem = titem->next; } cli_outfunf ("unknown command '%s'", argv[1]); } return data; }
void *cmd_att_get (int argc, char **argv, void *data) { Node *pos = (Node *) data; char *cdata; if(argc!=2){ cli_outfunf("usage: %s <attribute>",argv[0]); return pos; } cdata = node_get (pos, argv[1]); if (cdata) cli_outfun (cdata); return pos; }
static void* cut_cmd (int argc,char **argv, void *data) { Node *pos = (Node *) data; if(prefs.readonly){ cli_outfun("readonly flag set, avoiding tree change"); return data; } if (clipboard != NULL) { tree_free (clipboard); } clipboard = node_new (); clipboard = tree_duplicate (pos, clipboard); pos = node_remove (pos); docmd(pos,"tree_changed"); return pos; }
static int add (int argc,char **argv, void *data) { Node *pos = (Node *) data; Node *tnode; if(argc==1){ cli_outfunf("usage: %s <new entry>",argv[0]); return 0; } if (argc==2) { cli_outfun ("empty node added\n"); } tnode = node_insert_down (node_bottom (pos)); node_set (tnode, TEXT, argv[1]); return (int) pos; }
static void* paste_cmd (int argc,char **argv, void *data) { Node *pos = (Node *) data; if (clipboard == NULL) { docmd (pos, "status no data in clipboard"); } else { Node *temp; if(prefs.readonly){ cli_outfun("readonly flag set, avoiding insertion"); return data; } temp = node_insert_down (pos); tree_duplicate (clipboard, temp); docmd(pos,"tree_changed"); } return pos; }
char *cli_complete (const char *commandline) { int matches = 0; char str_matches[4096]=""; strncpy (newcommand, commandline, 99); newcommand[99] = 0; if (commandline[0]) { matches = item_matches (newcommand); if (matches == 1) { ItemT *titem = items; while (titem) { if (!strncmp (newcommand, titem->name, strlen (newcommand))) { int pos; strcpy (newcommand, titem->name); pos = strlen (newcommand); newcommand[pos++] = ' '; newcommand[pos] = '\0'; break; } titem = titem->next; } } else if (matches > 1) { ItemT *titem = items; strcpy(str_matches,"matches: "); while (titem) { if (!strncmp (newcommand, titem->name, strlen (newcommand))) { strcat (str_matches,titem->name); strcat (str_matches," "); } titem = titem->next; } cli_outfun(str_matches); while (item_matches (newcommand) == matches) { ItemT *titem = items; while (titem) { int len = strlen (newcommand); if (!strncmp (newcommand, titem->name, len)) { strcpy (newcommand, titem->name); newcommand[len + 1] = '\0'; if(!strcmp(newcommand,titem->name)){ return newcommand; } break; } titem = titem->next; } } newcommand[strlen (newcommand) - 1] = '\0'; } else { cli_outfunf ("no match"); } } return newcommand; }
static void* insert_cal(int argc, char **argv, void *data){ Node *pos=(void *)data; int year; int month; import_state_t ist; if( (argc!=3) || (atoi(argv[1])>12 )){ cli_outfunf("usage: %s <month> <year>", argv[0]); return data; } month=atoi(argv[1]); year=atoi(argv[2]); if(prefs.readonly){ cli_outfun("readonly flag set, avoiding insertion"); return data; } if(year<2000){ /* nasty,.. y2k like fix,.. but,.. it's just here */ year+=2000; } init_import(&ist, pos); { char tmpstr[40]; sprintf(tmpstr,"%i %s", year, mname[month]); import_node_text(&ist, 0, tmpstr); { struct tm tdata; tdata.tm_year = year - 1900; tdata.tm_mon = month - 1; tdata.tm_mday = 1; tdata.tm_hour = 0; tdata.tm_min = 0; tdata.tm_sec = 1; tdata.tm_isdst = -1; mktime (&tdata); while(tdata.tm_mon==month-1){ sprintf (tmpstr,"%s%c%02i\n", wday[tdata.tm_wday], (tdata.tm_wday==0 || tdata.tm_wday==6)?'_':' ', tdata.tm_mday); import_node_text(&ist, 1, tmpstr); /* I prefer not to plan on this level import_node_text(&ist, 2, "08:00"); import_node_text(&ist, 2, "09:00"); import_node_text(&ist, 2, "10:00"); import_node_text(&ist, 2, "11:00"); import_node_text(&ist, 2, "12:00"); import_node_text(&ist, 2, "13:00"); import_node_text(&ist, 2, "14:00"); import_node_text(&ist, 2, "15:00"); import_node_text(&ist, 2, "16:00"); import_node_text(&ist, 2, "17:00"); */ tdata.tm_mday++; mktime (&tdata); } } } docmd(pos,"tree_changed"); return pos; }