void map_manager(t_map **map, t_path **antpit) { int i; i = 0; while ((*map)->cleanfile[i] != NULL) { if ((*map)->nb_ants == 0) check_ants(map, i, 0); i++; } i = (*map)->antindex + 1; while ((*map)->error != 1 && (*map)->cleanfile[i] != NULL) { if ((isroom(map, i, antpit)) == 0 && (istube(map, i, antpit)) == 0) { if (iscommand(map, i, antpit) <= 0) (*map)->error = 1; } i++; } error_manager(map, antpit); max_paths(antpit); matrix_duplicator(antpit); }
static int tellmewhat(struct wordent *lexp, Char *str) { struct biltins *bptr; struct wordent *sp; Char *cmd, *s0, *s1, *s2; int i; int aliased, found; Char qc; aliased = 0; sp = lexp->next; if (adrof1(sp->word, &aliases)) { alias(lexp); sp = lexp->next; aliased = 1; } s0 = sp->word; /* to get the memory freeing right... */ /* handle quoted alias hack */ if ((*(sp->word) & (QUOTE | TRIM)) == QUOTE) (sp->word)++; /* do quoting, if it hasn't been done */ s1 = s2 = sp->word; while (*s2) switch (*s2) { case '\'': case '"': qc = *s2++; while (*s2 && *s2 != qc) *s1++ = (Char)(*s2++ | QUOTE); if (*s2) s2++; break; case '\\': if (*++s2) *s1++ = (Char)(*s2++ | QUOTE); break; default: *s1++ = *s2++; } *s1 = '\0'; for (bptr = bfunc; bptr < &bfunc[nbfunc]; bptr++) { if (eq(sp->word, str2short(bptr->bname))) { if (str == NULL) { if (aliased) prlex(cshout, lexp); (void)fprintf(cshout, "%s: shell built-in command.\n", vis_str(sp->word)); } else (void)Strcpy(str, sp->word); sp->word = s0; /* we save and then restore this */ return 1; } } sp->word = cmd = globone(sp->word, G_IGNORE); if ((i = iscommand(sp->word)) != 0) { Char **pv; struct varent *v; int slash = any(short2str(sp->word), '/'); v = adrof(STRpath); if (v == 0 || v->vec[0] == 0 || slash) pv = justabs; else pv = v->vec; while (--i) pv++; if (pv[0][0] == 0 || eq(pv[0], STRdot)) { if (!slash) { sp->word = Strspl(STRdotsl, sp->word); prlex(cshout, lexp); free(sp->word); } else prlex(cshout, lexp); } else { s1 = Strspl(*pv, STRslash); sp->word = Strspl(s1, sp->word); free(s1); if (str == NULL) prlex(cshout, lexp); else (void)Strcpy(str, sp->word); free(sp->word); } found = 1; } else { if (str == NULL) { if (aliased) prlex(cshout, lexp); (void)fprintf(csherr, "%s: Command not found.\n", vis_str(sp->word)); } else (void)Strcpy(str, sp->word); found = 0; } sp->word = s0; /* we save and then restore this */ free(cmd); return found; }
void processinput() { const char *inptr( g_iobuf ); Serial.print(CMNT); Serial.println( g_iobuf ); if( iscommand( inptr, F("dl"))) { g_logger.dump( &Serial ); } else if( iscommand( inptr, F("tl"))) { // truncate log g_logger.truncate(); } else if( iscommand( inptr, F("get") )) { // get database::dbrecord rec; int id( getintparam( inptr )); if( id != -1 && g_db.getParams( id, rec )) { rec.serialize( g_iobuf ); serialoutln( RESP, g_iobuf ); } else Serial.println( F(ERRS "ERR")); } else if( iscommand( inptr, F("set") )) { // set database::dbrecord rec; int id( getintparam( inptr )); if( id != -1 && rec.parse( inptr )) { if( g_db.setParams( id, rec )) Serial.println( F( RESPS "OK")); else Serial.println( F(ERRS "ERR")); } else Serial.println( F(ERRS "ERR")); } else if( iscommand( inptr, F("imp"))) { // import thindb tdb( g_sd ); uint16_t from( getintparam( inptr )); uint16_t to( getintparam( inptr )); if( from == 0xffff ) from = 0; if( to == 0xffff ) to = 1023; uint16_t imported(importdb(from, to)); if( imported != (uint16_t)-1 ) { serialoutln(F(RESPS "OK "), imported); } else serialoutln(F(ERRS "ERR "), imported); } else if( iscommand( inptr, F("dmp"))) { // dump database::dbrecord rec; uint16_t from( getintparam( inptr )); uint16_t to( getintparam( inptr )); uint16_t id; g_iobuf[3] = ' '; if( from == 0xffff ) from = 0; if( to == 0xffff ) to = 1023; for( id = from; id <= to; ++id ) { if( g_db.getParams( id, rec )) { uitohex( g_iobuf, id, 3 ); rec.serialize( g_iobuf + 4 ); serialoutln( RESP, g_iobuf ); } else break; } if( id == to + 1 ) Serial.println( RESP ); else Serial.println( F(ERRS "ERR" )); } else { Serial.println( F(ERRS "CMD")); } g_inidx = 0; }
/*this is the main routine*/ void doshell() { char line[80]; /*run forever - the shell shouldn't end*/ while(1==1) { /*read in a line*/ printstring("SHELL>\0"); readstring(line); /*match it against each possible command*/ /*if the user presses return, ignore it*/ if (line[0]==0xd) continue; else if (iscommand(line,"CLS\0")==1) doclear(); else if (iscommand(line,"cls\0")==1) doclear(); else if (iscommand(line,"COPY\0")==1) docopy(); else if (iscommand(line,"copy\0")==1) docopy(); else if (iscommand(line,"CREATE \0")==1) docreate(line); else if (iscommand(line,"create \0")==1) docreate(line); else if (iscommand(line,"DELETE \0")==1) dodelete(line); else if (iscommand(line,"delete \0")==1) dodelete(line); else if (iscommand(line,"DIR\0")==1) dodir(); else if (iscommand(line,"dir\0")==1) dodir(); else if (iscommand(line,"EXEC \0")==1) doexecute(line,1); else if (iscommand(line,"exec \0")==1) doexecute(line,1); else if (iscommand(line,"EXECBACK \0")==1) doexecute(line,0); else if (iscommand(line,"execback \0")==1) doexecute(line,0); else if (iscommand(line,"HELP\0")==1) dohelp(); else if (iscommand(line,"help\0")==1) dohelp(); else if (line[0]=='?') dohelp(); else if (iscommand(line,"TYPE \0")==1) dotype(line); else if (iscommand(line,"type \0")==1) dotype(line); else if (iscommand(line,"KILL \0")==1) dokill(line); else if (iscommand(line,"kill \0")==1) dokill(line); else if (iscommand(line,"mkdir \0")==1) domkdir(line); else if (iscommand(line,"MKDIR\0")==1) domkdir(line); else if (iscommand(line,"FORMAT\0")==1) doFormat(); else if (iscommand(line,"format\0")==1) doFormat(); else if (iscommand(line,"remove\0")==1) doRemove(line); else if (iscommand(line,"REMOVE\0")==1) doRemove(line); else if (iscommand(line,"list\0")==1) doList(); else if (iscommand(line,"LIST\0")==1) doList(); else if (iscommand(line,"count\0")==1) doCount(line); else if (iscommand(line,"WRITE\0")==1) doCreateFile(line); else if (iscommand(line,"write\0")==1) doCreateFile(line); else if (iscommand(line,"READ\0")==1) doEcho(line); else if (iscommand(line,"read\0")==1) doEcho(line); else printstring("Command not found\r\n\0"); printstring("\r\n\0"); } }
int main(int argc, char **argv) { char c; FILE *f; while ((c = getopt(argc, argv, "dhi:ns:")) != -1) { switch (c) { case 'd': debugmode = 1; break; case 'i': increment = strtol(optarg, NULL, 10); if (increment == 0) errx(1, "increment must be grater than 0"); break; case 'n': noalloc = 1; break; case 's': startsize = strtol(optarg, NULL, 10); if (startsize == 0) errx(1, "startsize must be greater than 0"); break; case 'h': default: usage(); } } argc -= optind; argv += optind; if (argc > 1) usage(); if (argc == 1) { if (argv[0][0] == '-' && argv[0][1] == '\0') f = stdin; else if ((f = fopen(argv[0], "r")) == NULL) err(1, "cannot open file `%s'", argv[0]); } else f = stdin; commands_size = startsize; commands = calloc(1, commands_size); if (commands == NULL) err(1, "cannot alloc commands array"); data_size = startsize; data = ptr = calloc(1, data_size); if (data == NULL) err(1, "cannot alloc data memory"); while ((c = fgetc(f)) != EOF) if (iscommand(c)) addcommand(c); fclose(f); run(); free(commands); free(data); return (0); }