static void* cmd_save (int argc,char **argv, void *data) { Node *pos = (Node *) data; if(prefs.readonly){ docmd (pos, "status \"readonly mode, not writing to disk\"\n"); return pos; } if (prefs.db_file[0] != (char) 255) { /* magic value of tutorial */ { char buf[4096]; char swapfile[4096]; sprintf(swapfile,"%s_tines_rescue",prefs.db_file); /* remove(swapfile); when not removing it works as a lockfile */ docmd (pos, "autosave_threshold_nodes_changed 0"); if (!strcmp(prefs.format,"hnb") || !strcmp(prefs.format,"opml")) { sprintf (buf, "export_%s %s %i", prefs.format, prefs.db_file, node_no (pos) - 1); } else { sprintf (buf, "export_%s %s", prefs.format, prefs.db_file); } docmd (node_root (pos), buf); } } else { /* make tutorial users initial database, if initial database dont exist */ } return pos; }
dofile() { char word[WORDSIZE], *wp; char cmd[WORDSIZE] , sub[WORDSIZE] ; int n ; log_lev++; /* one file deeper */ pen = G_MOVE ; /* pick up the pen for each new file. */ while ( (n = getword(word, W_MUST)) > 0) { *cmd = 0; *sub = 0; /* see if it is a system call out */ if (n == SYS_W || n == SIN_W) { /* so shell gets replaced */ char *ex = "exec " ; /* char *ex = "" ; */ strcpy(word, ex); wp = (word + strlen(ex)) ; (void)getword(wp, W_LITR) ; /*collect litteral string*/ docmd("sys" , (n==SIN_W ? "in" : "") , word); } /* see if it is a command */ else if (*word == cmd_char) { wp = word + 1; if (!mkcmd(wp, cmd, sub)) continue; /* get the (possible) argument */ (void)getword(word, W_ANY ) ; /* got a command, so no arg */ if (*word == cmd_char || *word == sys_char) { putback(word); *word = 0; /* null argument */ } /* interpret the command, if word not used, putback */ if (docmd(cmd, sub, word) == DOBACK) putback(word); } /* a number or some word that we don't care about */ else { docmd("" , "" , word); } }/* of loop through file */ log_lev--; /* back from a file depth */ }/* of dofile */
void main(int argc, char *argv[]) { int n; Biobuf in; char *p; char *f[4]; strcpy(mntpt, "/net"); cfg.inside = 1; ARGBEGIN{ case 'f': dbfile = EARGF(usage()); break; case 'r': cfg.resolver = 1; break; case 'x': dbfile = "/lib/ndb/external"; strcpy(mntpt, "/net.alt"); break; default: usage(); }ARGEND now = time(nil); nowns = nsec(); dninit(); fmtinstall('R', prettyrrfmt); if(myipaddr(ipaddr, mntpt) < 0) sysfatal("can't read my ip address"); opendatabase(); if(cfg.resolver) squirrelserveraddrs(); debug = 1; if(argc > 0){ docmd(argc, argv); exits(0); } Binit(&in, 0, OREAD); for(print("> "); p = Brdline(&in, '\n'); print("> ")){ p[Blinelen(&in)-1] = 0; n = tokenize(p, f, 3); if(n>=1) { dnpurge(); /* flush the cache */ docmd(n, f); } } exits(0); }
void threadmain(int argc, char *argv[]) { int n; Biobuf in; char *p; char *f[4]; strcpy(mntpt, "/net"); ARGBEGIN{ case 'r': resolver = 1; break; case 'f': dbfile = EARGF(usage()); break; default: usage(); }ARGEND now = time(0); dninit(); fmtinstall('R', prettyrrfmt); if(myipaddr(ipaddr, mntpt) < 0) sysfatal("can't read my ip address"); opendatabase(); if(resolver) squirrelserveraddrs(); debug = 1; if(argc > 0){ docmd(argc, argv); threadexitsall(0); } Binit(&in, 0, OREAD); for(print("> "); p = Brdline(&in, '\n'); print("> ")){ p[Blinelen(&in)-1] = 0; n = tokenize(p, f, 3); if(n<1) continue; /* flush the cache */ dnpurge(); docmd(n, f); } threadexitsall(0); }
mloop() { while (!quit) { if (incmd) { docmd(); } else if (wwcurwin->ww_state != WWS_HASPROC) { if (!wwcurwin->ww_keepopen) closewin(wwcurwin); setcmd(1); if (wwpeekc() == escapec) (void) wwgetc(); error("Process died."); } else { register struct ww *w = wwcurwin; register char *p; register n; if (wwibp >= wwibq) wwiomux(); for (p = wwibp; p < wwibq && *p != escapec; p++) ; if ((n = p - wwibp) > 0) { if (!w->ww_ispty && w->ww_stopped) startwin(w); (void) write(w->ww_pty, wwibp, n); wwibp = p; } if (wwpeekc() == escapec) { (void) wwgetc(); setcmd(1); } } } }
/* i'm not even going to try to justify this. -pgf */ static void personals(int n) { #if !SMALLER const char **cmdp = NULL; static const char *pgfcmds[] = { "bind-key split-current-window ^T", "bind-key next-window ^N", "bind-key previous-window ^P", "set ai atp nobl ul=0 sw=4 csw=4 timeoutlen=50 check-modtime visual-matches=underline", NULL }; if (n == 11) cmdp = pgfcmds; if (n == -11) *(int *) (1) = 42; /* test core dumps */ if (!cmdp) return; while (*cmdp) { char *line = strmalloc(*cmdp); (void) docmd(line, TRUE, FALSE, 1); free(line); cmdp++; } #else (void) n; #endif }
static int cbf(const char *pathname, const struct stat *statptr, int type){ switch(type){ case FTW_F: switch(statptr->st_mode & S_IFMT){ case S_IFREG: docmd(pathname, statptr); nreg++; break; case S_IFBLK:nblk++;break; case S_IFCHR:nchr++;break; case S_IFIFO:nfifo++;break; case S_IFLNK:nslink++;break; case S_IFSOCK:nsock++;break; case S_IFDIR:printf("for S_IFDIR for %s", pathname); } break; case FTW_D: ndir++; break; case FTW_DNR: printf("can't read directory %s", pathname); break; case FTW_NS: printf("stat error for %s", pathname); break; default: printf("unknown type %d for pathname %s", type, pathname); } return(0); }
void MonitorItem::get_status() { switch (d->type) { case R_DIRECTOR: docmd("status dir"); break; case R_CLIENT: if (!docmd("status")) emit jobIsRunning(false); break; case R_STORAGE: docmd("status"); break; default: break; } }
static Chan* segmentopen(Chan *c, int omode) { Globalseg *g; switch(TYPE(c)){ case Qtopdir: case Qsegdir: if(omode != 0) error(Eisdir); break; case Qctl: case Qfree: g = getgseg(c); if(waserror()){ putgseg(g); nexterror(); } devpermcheck(g->uid, g->perm, omode); c->aux = g; poperror(); c->flag |= COPEN; break; case Qdata: g = getgseg(c); if(waserror()){ putgseg(g); nexterror(); } devpermcheck(g->uid, g->perm, omode); if(g->s == nil) error("segment not yet allocated"); if(g->kproc == nil){ qlock(&g->l); if(waserror()){ qunlock(&g->l); nexterror(); } if(g->kproc == nil){ g->cmd = Cnone; kproc(g->name, segmentkproc, g); docmd(g, Cstart); } poperror(); qunlock(&g->l); } c->aux = g; poperror(); c->flag |= COPEN; break; default: panic("segmentopen"); } c->mode = openmode(omode); c->offset = 0; return c; }
int getcmd(void) { cmd.cmd = NULL; if (!readline(cmd_buf, sizeof(cmd_buf), cmd.timeout)) cmd.cmd = cmd_table; return docmd(); }
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; }
/* removes *pos if it is a temporary node, then returns 1 * otherwize returns 0 */ static int remove_temp (Node **pos) { if (node_getflag (*pos, F_temp)) { *pos = node_remove ((*pos)); node_update_parents_todo ((*pos)); docmd(*pos,"tree_changed"); return 1; } return 0; }
Node *docmdf (Node *pos,char *format, ...){ va_list arglist; char buf[128]; va_start( arglist, format ); vsnprintf(buf,127,format,arglist); va_end(arglist); buf[127]=0; return docmd(pos,buf); }
static long segmentwrite(Chan *c, void *a, long n, vlong voff) { Cmdbuf *cb; Globalseg *g; ulong va, len, top; if(c->qid.type == QTDIR) error(Eperm); switch(TYPE(c)){ case Qctl: g = c->aux; cb = parsecmd(a, n); if(strcmp(cb->f[0], "va") == 0){ if(g->s != nil) error("already has a virtual address"); if(cb->nf < 3) error(Ebadarg); va = strtoul(cb->f[1], 0, 0); len = strtoul(cb->f[2], 0, 0); top = PGROUND(va + len); va = va&~(BY2PG-1); len = (top - va) / BY2PG; if(len == 0) error(Ebadarg); g->s = newseg(SG_SHARED, va, len); } else error(Ebadctl); break; case Qdata: g = c->aux; if(voff + n > g->s->top - g->s->base) error(Ebadarg); qlock(&g->l); g->off = voff + g->s->base; g->data = smalloc(n); if(waserror()){ free(g->data); qunlock(&g->l); nexterror(); } g->dlen = n; memmove(g->data, a, g->dlen); docmd(g, Cwrite); free(g->data); qunlock(&g->l); poperror(); return g->dlen; default: panic("segmentwrite"); } return 0; /* not reached */ }
/* * execcmd: * Execute a command line command to be typed in * by the user * * int f, n; default Flag and Numeric argument */ int execcmd(int f, int n) { int status; /* status return */ char *cmdstr; /* string holding command to execute */ cmdstr = alloca(NSTRING * sizeof(char)); /* get the line wanted */ if ((status = mlreply(": ", cmdstr, NSTRING)) != TRUE) return status; execlevel = 0; return docmd(cmdstr); }
static void putgseg(Globalseg *g) { if(decref(g) > 0) return; if(g->s != nil) putseg(g->s); if(g->kproc) docmd(g, Cdie); free(g->name); free(g->uid); free(g); }
static int 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; temp = node_insert_down (pos); tree_duplicate (clipboard, temp); } return (int) pos; }
void console_read(void) { char buf[CONSOLE_BUFSIZ], *cp; if ((cp = fgets(buf, CONSOLE_BUFSIZ, infile)) == NULL) { exit_handler(); return; } docmd(cp); fprintf(outfile, "%s", cons_prompt); fflush(outfile); }
static void cmdline(Win *w) { static char buf[4096]; Rune *q; char *p; q = w->runes + w->opoint; p = buf; while(q < w->runes + w->nrunes && p < buf + nelem(buf) + 1) p += runetochar(p, q++); *p = 0; w->opoint = w->nrunes; docmd(buf); }
static void do_something() { char *q; if ((q = memnewline(buf, bytes_in_buf))) { do_something_server(q); } else { fd_set fdlist; FD_ZERO(&fdlist); FD_SET(0, &fdlist); FD_SET(serverfd, &fdlist); if (select(serverfd+1, &fdlist, NULL, NULL, NULL) < 0) { perror("select"); } else { if (FD_ISSET(serverfd, &fdlist)) { int n = read(serverfd, buf+bytes_in_buf, sizeof buf - bytes_in_buf); if (n == 0) { printf("\nserver dropped the connection\n"); exit(0); } else if (n < 0) { perror("read"); exit(1); } else { bytes_in_buf += n; if ((q = memnewline(buf, bytes_in_buf))) do_something_server(q); } } if (FD_ISSET(0, &fdlist)) { char buf[80]; if (fgets(buf, sizeof buf, stdin) == NULL) exit(0); //step 3 char buf1[80]; int l = strlen(lang_say); strncpy(buf1,buf,l); buf1[l]= 0; if (strcmp (buf1,lang_say) == 0){ strncpy(buf1, buf + l + 1, strlen(buf) - l); sprintf(buf,"say %s\n",buf1); send_string(buf); }else{ docmd(explode(buf)); } } } } }
void dotest() { for (int i = 0; i < nitems; i++) { const char *cmd; switch (items[i].type) { case R_DIRECTOR: cmd = ".jobs type=B"; tray->clearText(items[i].get_name()); docmd(&items[i], cmd); break; default: break; } } }
void * shell(void *arg) { int c; int rc=1; int menu=1; while (1) { if ((c=prompt(menu))!=0) rc=docmd(c); if (rc<0) break; if (rc==1) menu=1; else menu=0; } fprintf(stderr, "terminating\n"); fflush(stdout); return NULL; }
static void* cmd_revert (int argc,char **argv, void *data) { Node *pos = (Node *) data; if (prefs.db_file[0] != (char) 255) { { char buf[4096]; sprintf (buf, "import_%s %s", prefs.format, prefs.db_file); node_free(pos); pos=tree_new(); pos=docmd (pos, buf); } } return pos; }
void shell(CURL *h) { char buf[128]; char **av; int rc = 0; while (rc == 0) { printf("httppower> "); fflush(stdout); if (fgets(buf, sizeof(buf), stdin)) { av = argv_create(buf, ""); rc = docmd(h, av); argv_destroy(av); } else rc = 1; } }
void * shell(void *arg) { Client *C = arg; char input[INPUTSIZE]; int rc; int menu=1; //the following is done in order to change the prompt for the user to X or O while (1) { // Clear input each time bzero(&input, INPUTSIZE); prompt(menu, input); if (strlen(input)>0) { rc=docmd(C, input); menu = 1; } if (rc<0) { killConnection(C->ph); break; } if (rc==1) { menu=1; // Proto_Game_State *gs = proto_client_game_state(C->ph); } if (((Proto_Client *) C->ph)->game.status == IN_PROGRESS && DISPLAYUI == 1) { // launchUI(C); return NULL; } else menu=1; } if (PROTO_PRINT_DUMPS==1) fprintf(stderr, "terminating\n"); fflush(stdout); return NULL; }
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; }
/* * getcmds - read commands from the standard input and execute them */ static void getcmds(void) { char * line; int count; ntp_readline_init(interactive ? prompt : NULL); for (;;) { line = ntp_readline(&count); if (NULL == line) break; docmd(line); free(line); } ntp_readline_uninit(); }
void getstr(void) { s8 buf[1024]; u16 bufptr = 0; memset(buf, 0, sizeof(buf)); while (1) { if (getport(PORT_KEYBOARD_READY) & 0x01) { u8 scancode = getport(PORT_KEYBOARD_CHAR); if (scancode == 0x1c) { docmd(buf); bufptr = 0; break; } if (!(scancode & 0x80)) { printch(KEYMAP[scancode]); buf[bufptr++] = KEYMAP[scancode]; } } } }
static long segmentread(Chan *c, void *a, long n, vlong voff) { Globalseg *g; char buf[32]; if(c->qid.type == QTDIR) return devdirread(c, a, n, (Dirtab *)0, 0L, segmentgen); switch(TYPE(c)){ case Qctl: g = c->aux; if(g->s == nil) error("segment not yet allocated"); sprint(buf, "va %#lux %#lux\n", g->s->base, g->s->top-g->s->base); return readstr(voff, a, n, buf); case Qdata: g = c->aux; if(voff > g->s->top - g->s->base) error(Ebadarg); if(voff + n > g->s->top - g->s->base) n = g->s->top - g->s->base - voff; qlock(&g->l); g->off = voff + g->s->base; g->data = smalloc(n); if(waserror()){ free(g->data); qunlock(&g->l); nexterror(); } g->dlen = n; docmd(g, Cread); memmove(a, g->data, g->dlen); free(g->data); qunlock(&g->l); poperror(); return g->dlen; default: panic("segmentread"); } return 0; /* not reached */ }
static void handle_rlinput(char *rd) { if (rd == NULL) { exit_handler(); #if RL_VERSION_MAJOR >= 4 rl_cleanup_after_signal(); #endif rl_reset_terminal(NULL); #ifdef THREADS pthread_exit(NULL); #else exit(0); #endif } if (*rd != 0) { add_history(rd); } docmd(rd); free(rd); }