int main(int argc, char **argv) { int i; if (argc<2) showusage (1); if (!strcmp (argv[1], "-v")) showversion (); if (!strcmp (argv[1], "-h")) showusage (0); if (argc == 2) return sdb_dump (argv[1]); #if USE_MMAN signal (SIGINT, terminate); signal (SIGHUP, syncronize); #endif if (!strcmp (argv[2], "=")) { createdb (argv[1]); } else if (!strcmp (argv[2], "-")) { char line[SDB_VALUESIZE]; if ((s = sdb_new (argv[1], 0))) for (;;) { fgets (line, sizeof line, stdin); if (feof (stdin)) break; line[strlen (line)-1] = 0; runline (s, line); } } else if ((s = sdb_new (argv[1], 0))) for (i=2; i<argc; i++) runline (s, argv[i]); terminate (0); return 0; }
int main(int argc, char *argv[]) { int pid = runline("sort &"); char buf[50]; sprintf(buf,"%s %d","join",pid); runline(buf); }
int main(int argc, char *argv[]) { //char prompt[] = "nachos% "; //while (1) { //printf("%s", prompt); //readline(buffer, BUFFERSIZE); //char buffer[BUFFERSIZE]; //runline("sort &"); //runline("sort &"); runline("connect &"); runline("accept &"); //} }
void shell(void) { printf("\n%s\n",eval_version); /* shell constants */ const char _shell_arrow[] =">>"; const char _shell_exit[]="exit"; /* shell variables */ char *cmd = NULL; char *str = NULL; char *err = NULL; void runline(const char *cmd, char *err); /* shell system */ if((cmd=(char *)(malloc(1)))==NULL) allocerr(); if((err=(char *)(malloc(1)))==NULL) allocerr(); while(strcmp(cmd,_shell_exit)) { strcpy(err,""); /* empty err string */ /* allocate (max_str_length) bytes to str for input */ stralloc: if((cp=(char *)(realloc(str,sizeof(char)* (max_str_length))))!=NULL) { str = cp; } else { /* if the system is very very low on memory */ if(max_str_length>=255) { max_str_length -= 1; goto stralloc; } else { allocerr(); } } printf("\n%s",_shell_arrow); gets(str); /* re-allocate cmd for reuse */ if((cp=(char *)(realloc(cmd,sizeof(char)*(strlen(str)+1))))!=NULL) { cmd = cp; } else { allocerr(); } strcpy(cmd,str); /* destroy str to free (max_str_length) bytes of memory space */ free(str); str = NULL; /* truncuate the string cmd */ strtrm(cmd,' ','s'); if(*cmd==0) continue; /* if cmd is empty then continue */ if(!strlen(cmd)) continue; /* allocate variable to store error information */ if((cp=(char *)(realloc(err,sizeof(char)*(strlen(cmd)+256))))!=NULL) { err = cp; } else { allocerr(); } /* cmd should not be exit */ if(strcmp(cmd,_shell_exit)) /* now run line string cmd */ runline(cmd,err); /* check for any errors */ if(strlen(err)) printf("\nError: %s\n",err); } /* while exiting, free used memeory */ free(cmd); cmd = NULL; free(err); err = NULL; }
//if/then/else, for/next, let, goto, gosub, print void runprogram(char* program) { int i = 0; for (char* line = strtok(program, "\n"); line != NULL && i < 128; line = strtok(NULL, "\n"), i++) { programPointers[i] = line; } if (i >= 256) { printf("program too long!\n"); return; } programPointers[i++] = NULL; int pc = 0; runline(programPointers[pc], &pc); }
void shell(void) { /* shell constants */ const char _shell_arrow[] =">>"; const char _shell_exit[]="exit"; /* shell variables */ char *cmd = NULL; char *str = NULL; void runline(const char *cmd, char *err); char err[KB]=""; /* shell system */ if((cmd=(char *)(malloc(1)))==NULL) allocerr(); while(strcmp(cmd,_shell_exit)) { strcpy(err,""); /* empty err string */ /* allocate 1MB to str for input */ if((cp=(char *)(realloc(str,sizeof(char)*(MB))))!=NULL) { str = cp; } else { allocerr(); } printf("\n%s",_shell_arrow); gets(str); /* re-allocate cmd for reuse */ if((cp=(char *)(realloc(cmd,sizeof(char)*(strlen(str)+1))))!=NULL) { cmd = cp; } else { allocerr(); } strcpy(cmd,str); /* destroy str to free memory space */ free(str); str = NULL; /* truncuate the string cmd */ if(strtrims(cmd,' ')) continue; if(!strlen(cmd)) continue; /* cmd should not be exit */ if(strcmp(cmd,_shell_exit)) /* now evaluate string cmd */ runline(cmd,err); /* check for any errors */ if(strlen(err)) printf("\nError: %s\n",err); } /* while exiting, free used memeory */ free(cmd); cmd=NULL; }
FLOAT runExpr(FLOAT *x,scan_t *theScan) { x--;/*The patch, for historical reasons the rest of the function assumes that the array indices are started from 1, not 0*/ /*copy x to the scratch:*/ memcpy(theScan->x+1,x+1,sizeof(FLOAT)*(theScan->nx - 1)); if(theScan->wasCut){ int i; if(theScan->ep[0] > 0.0){/*"Global" cut*/ for(i=1;i<theScan->nx; i++)if(x[i]<theScan->ep[0]) theScan->x[i]=theScan->ep[0]; }else /*"local" cut, imopse it individually for each x:*/ for(i=1;i<theScan->nx; i++)if(theScan->ep_i[i]){ if(x[i]<theScan->ep[i]){ theScan->x[i]=theScan->ep[i]; } }/*for(i=1;i<theScan->nx; i++)if(theScan->ep_i[i])*/ }/*if(theScan->wasCut)*/ return runline(&theScan->rtTriad); }/*runExpr*/
int exec(const char *cmd, char *err) { int runline(const char *str, char *err); char _err[KB]=_NULL; if(*cmd==';') /* if statemnt is a comment. */ return 0; char purity_check(const char *str); char impurity = purity_check(cmd); if(!impurity) /* if cmd is pure */ { char statement[KB]=_NULL; // remove comments from the statement int l = 0; /* to store length of spointer */ l = strlen(cmd); int i = 0; /* loop counter */ for(i=0;i<l;i++) { if(*cmd==';') break; statement[i] = *cmd; cmd++; } statement[i]='\0'; // now run the statement if(!runline(statement,_err)) /* if eval was succesfull. */ return 0; else /* if eval was un-succesfull. */ strcpy(err,_err); /* transfer eval's err to err */ return 1; } else /* if cmd is impure */ { stradd(err,"Character ["); straddc(err,impurity); stradd(err,"] is not allowed."); return 1; } return 1; }