int in_from_stdin(t_execdata *data, char ***avptra) { char b[BUFF_SIZE]; int pipedfd[2]; int ret; if (!ft_strcmp(*((*avptra) + 1), "EOF")) { free(*((*avptra) + 1)); *((*avptra) + 1) = ft_strnew(0); } pipe(pipedfd); signal(SIGINT, ctrlhandlstdin); while (1) { ft_bzero(b, BUFF_SIZE); ft_putstr("heredoc > "); if ((ret = getinputs(b, NULL)) < 1 || !ft_strcmp(b, *(*avptra + 1))) break ; ft_putstr_fd(b, pipedfd[1]); ft_putchar_fd('\n', pipedfd[1]); } signal(SIGINT, handler); close(pipedfd[1]); data->fd[0] = pipedfd[0]; rmv_entries_in_avtable(avptra); return (0); }
int main(int argc, char **argv, char **env) { t_history *history; t_execdata *child; if (init(&g_buff, &child, env, &history) == -1) return (-1); (void)argc; (void)argv; if (isatty(0)) ft_welcome(); while (1) { checkcanonmode(); getcwd(g_buff, BUFF_SIZE); showprompt(g_buff); ft_bzero(g_buff, BUFF_SIZE); if ((getinputs(g_buff, history) == -1)) break ; else if (launchcommands(g_buff, child) == 0) return (0); } if (isatty(0)) ft_goodbye(); ft_deinit(child, history); return (1); }
void main() { NODE header,rev; header=createempty(); getinputs(5,header); displaylist(header); rev=reverselist(header); }
int main(int argc, char ** argv) { /* BEGIN DECLARATIONS */ WINFO wi; /* struct for command line input */ /* workspace */ float * v; /* velocity field */ float * p1; /* pressure field, current time step */ float * p0; /* pressure field, last time step */ float * tr; /* storage for traces */ float * tmp; /* used to swap p1 and p0 */ int ix, it; /* counters */ int isrc; /* source counter */ int imf; /* movie frame counter */ int isx; /* source location, in units of dx */ int nxz; /* number of spatial grid points */ /* int nz; local number of gridpoints */ int ntr; /* number of traces */ int nsam; /* number of trace samples */ int nsrc; /* number of shots */ float rz,rx,s; /* precomputed coefficients */ float vmax,vmin; /* max, min velocity values */ /* float two; two */ /* END DECLARATIONS */ sf_init(argc,argv); /* read inputs from command line */ getinputs(true,&wi); /* compute number of shots */ nsrc = (wi.isxend-wi.isxbeg)/(wi.iskip); nsrc++; /* compute number of spatial grid points */ nxz=wi.nx * wi.nz; /* compute number of traces, samples in each record */ ntr=wi.igxend-wi.igxbeg+1; nsam=ntr*wi.nt; /* allocate, initialize p0, p1, v, traces */ p0=sf_floatalloc(nxz); p1=sf_floatalloc(nxz); v =sf_floatalloc(nxz); tr=sf_floatalloc(nsam); /* read velocity */ sf_floatread(v,nxz,wi.vfile); /* CFL, sanity checks */ vmax=fgetmax(v,nxz); vmin=fgetmin(v,nxz); if (vmax*wi.dt>CFL*fmaxf(wi.dx,wi.dz)) { sf_warning("CFL criterion violated"); sf_warning("vmax=%e dx=%e dz=%e dt=%e\n",vmax,wi.dx,wi.dz,wi.dt); sf_error("max permitted dt=%e\n",CFL*fmaxf(wi.dx,wi.dz)/vmax); } if (vmin<=0.0) sf_error("min velocity nonpositive"); /* only square of velocity array needed from here on */ fsquare(v,nxz); /* precalculate some coefficients */ rz=wi.dt*wi.dt/(wi.dz*wi.dz); rx=wi.dt*wi.dt/(wi.dx*wi.dx); s =2.0*(rz+rx); /* two=2.0; nz=wi.nz; */ /* shot loop */ isrc=0; isx=wi.isxbeg; while (isx <= wi.isxend) { /* initialize pressure fields, traces */ fzeros(p0,nxz); fzeros(p1,nxz); fzeros(tr,nsam); /* initialize movie frame counter */ imf=0; /* time loop */ for (it=0;it<wi.nt;it++) { /* construct next time step, overwrite on p0 */ step_forward(p0,p1,v,wi.nz,wi.nx,rz,rx,s); /* tack on source */ p0[wi.isz+isx*wi.nz]+=fgetrick(it*wi.dt,wi.freq); /* swap pointers */ tmp=p0; p0=p1; p1=tmp; /* store trace samples if necessary */ if (NULL != wi.tfile) for (ix=0;ix<ntr;ix++) tr[ix*wi.nt+it]=p1[(wi.igxbeg+ix)*wi.nz+wi.igz]; /* write movie snap to file if necessary */ if (NULL != wi.mfile && wi.nm && !(it%wi.nm)) { sf_floatwrite(p1,nxz,wi.mfile); imf++; } /* next t */ } /* write traces to file if necessary */ if (NULL != wi.tfile) sf_floatwrite(tr,nsam,wi.tfile); isx += wi.iskip; isrc++; } exit(0); }
int main(int argc,char * argv[]){ while(1){ printf("mysh%% "); init(); getinputs(); printf("Show the command:\n"); printf("command:%s",token); while( (token = strtok_r(NULL," ",&save_ptr)) != NULL){ if(*token == '<'){ iof[0] = SET; if( isgraph(*(token + 1))){ ios[0] = token + 1; state = NORMAL; } else { state = INPUT; } } else if(*token == '>'){ iof[1] = SET; if( isgraph(*(token + 1))){ ios[1] = token + 1; state = NORMAL; }else{ state = OUTPUT; } } else { switch(state){ case NORMAL: if((found = strchr(token,'<'))){ *found = '\0'; args[args_i++] = token; iof[0] = SET; if( isgraph(*(found+1))) { ios[0] = found + 1; state = NORMAL; }else{ state = INPUT; } }else if((found = strchr(token,'>'))){ *found = '\0'; args[args_i++] = token; iof[1] = SET; if( isgraph(*(found+1))) { ios[1] = found + 1; state = NORMAL; }else{ state = OUTPUT; } }else{ args[args_i++] = token; } break; case INPUT: if(! isspace(*token) ){ ios[0] = token; state = NORMAL; } break; case OUTPUT: if(! isspace(*token) ){ ios[1] = token; state = NORMAL; } break; default: break; } } } print_args(); } return 0; }
main(int argc, char *argv[]) { int i, m; char cwd[128]; char pathName[255]; FILE* tmp; int failed = 0; m = getinputs(); // get user inputs name=value into entry[ ] getcwd(cwd, 128); // get CWD pathname printf("Content-type: text/html\n\n"); printf("<p>pid=%d uid=%d cwd=%s\n", getpid(), getuid(), cwd); printf("<H1>Echo Your Inputs</H1>"); printf("You submitted the following name/value pairs:<p>"); for(i=0; i <= m; i++) printf("%s = %s<p>", entry[i].name, entry[i].value); printf("<p>"); /***************************************************************** Write YOUR C code here to processs the command mkdir dirname rmdir dirname rm filename cat filename cp file1 file2 ls [dirname] <== ls CWD if no dirname *****************************************************************/ // failed = 0; if(strcmp(entry[0].value, "mkdir") == 0){ // mkdir for(i = 1; i <= m; i++) { if(strcmp(entry[i].value, "\0") != 0){ // checks to make sure it's not a NULL, strcpy(pathName, cwd); strcat(pathName, "/"); strcat(pathName, entry[i].value); printf("command is %s, Dir name is \"%s\"\n", entry[0].value, pathName); failed = mkdir(pathName, 0777); // was going to use "mode_t mode" from sys/stat.h (S_IRWXU, S_IRWXG, S_IROTH, S_IXOTH) but friend suggested 0x16D instead and it works if(failed != 0){ i = m; // this ends the loop, in hind sight I could have made a while function, but this works } } } } else if(strcmp(entry[0].value, "rmdir") == 0){ for(i = 1; i <= m; i++) { if(strcmp(entry[i].value, "\0") != 0){ // again, compares to NULL "0\" strcpy(pathName, cwd); strcat(pathName, "/"); strcat(pathName, entry[i].value); printf("command is %s, Dir name is \"%s\"\n", entry[0].value, pathName); failed = rmdir(pathName); } } } else if(strcmp(entry[0].value, "rm") == 0){ for(i = 1; i <= m; i++){ if(strcmp(entry[i].value, "\0") != 0){ strcpy(pathName, cwd); strcat(pathName, "/"); strcat(pathName, entry[i].value); printf("command is %s, file name is \"%s\"\n", entry[0].value, pathName); printf("Failed to remove\n"); failed = 1; failed = remove(pathName); } } } else if(strcmp(entry[0].value, "cat") == 0){ char buffer[1024] = {'\0'}; for(i = 1; i <= m; i++){ tmp = fopen(entry[i].value, "r"); if(tmp == NULL){ failed = 1; } else{ while(fgets(buffer, 1024, tmp) != NULL){ printf("%s <br/>", buffer); } } if(failed != 0){ i = m; } } failed = 0; } else if(strcmp(entry[0].value, "cp") == 0){ FILE *src, *dest; char buffer[1024] = {'\0'}; src = fopen(entry[1].value, "r"); dest = fopen(entry[2].value, "w"); if(src == NULL || dest == NULL){ printf("Could not open file"); } else { while(fgets(buffer, 1024, src) != NULL){ fputs(buffer, dest); } } failed = 0; } else if(strcmp(entry[0].value, "ls") == 0){ //printf("need to getdents"); if(strlen(entry[1].value) != 0){ myls(entry[1].value, cwd); } else{ myls(".", cwd); } failed = 0; // this make it so system knows that command succeeded } else { printf("Command not programmed yet"); } if(failed) { printf("<h2>%s failed</h2>", entry[0].value); // printf("Error: %s<br/><br/>", strerror(errno)); //If I want to include error decoding } else { printf("<h2>Command succeeded!</h2>"); } failed = 0; // create a FORM webpage for user to submit again printf("</title>"); printf("</head>"); printf("<body bgcolor=\"#c49561\" link=\"#330033\" leftmargin=8 topmargin=8"); printf("<p>------------------ DO IT AGAIN ----------------\n"); printf("<FORM METHOD=\"POST\" ACTION=\"http://cs360.eecs.wsu.edu/~juel/cgi-bin/mycgi\">"); //------ NOTE : CHANGE ACTION to YOUR login name ---------------------------- //printf("<FORM METHOD=\"POST\" ACTION=\"http://cs560.eecs.wsu.edu/~YOURNAME/cgi-bin/mycgi\">"); printf("Enter command : <INPUT NAME=\"command\"> <P>"); printf("Enter filename1: <INPUT NAME=\"filename1\"> <P>"); printf("Enter filename2: <INPUT NAME=\"filename2\"> <P>"); printf("Submit command: <INPUT TYPE=\"submit\" VALUE=\"Click to Submit\"><P>"); printf("</form>"); printf("------------------------------------------------<p>"); printf("</body>"); printf("</html>"); }