int main(int argc, char **argv) { struct TokBuf * tb; /* Llamar a la función de inicialización del shell */ user_inicializar(); /* Establecer modo no interpretado en la entrada */ modoInterpretado(0, 0); /* Procesar órdenes */ while ((tb = userin()) != NULL) { procline(tb); /* Liberar el TokBuf que creó la llamada a userin() */ liberaTokBuf(tb); } /* Restaurar el modo de la entrada */ modoInterpretado(0, 1); /* Finalmente, a la función de finalización */ user_finalizar(); /* Retornar una salida sin error */ return 0; }
/* a2pa.c: 'minsh-J-E' mini shell main function * CS481online, Univ. of New Mexico, Fall 2012 * * VERSION: b(0.1) (execv, no background) * AUTHOR: Joseph Edwards <*****@*****.**> */ int main() { /* print prompt and read a line*/ while ((userin(prompt)) != EOF) { /* process the input, execute the command and output the results */ if (procline() == -1) break; } printf("\n\nTerminating mini-shell [%s].\n", prompt); exit(EXIT_SUCCESS); }
int main(int argc, char *argv[]) { set_folders(); initialize(); set_signals(); //Iniciar el cliente como servidor de ficheros if (init_client() == -1) error("Error on init client"); while(1) { userin(); procline(); } }
/* * Opens a file and processes it. Each file is processed line-by-line * passing the lines to procline(). */ int procfile(const char *fn) { struct file *f; struct stat sb; struct str ln; mode_t s; int c, t; mcount = mlimit; if (strcmp(fn, "-") == 0) { fn = label != NULL ? label : getstr(1); f = grep_open(NULL); } else { if (!stat(fn, &sb)) { /* Check if we need to process the file */ s = sb.st_mode & S_IFMT; if (s == S_IFDIR && dirbehave == DIR_SKIP) return (0); if ((s == S_IFIFO || s == S_IFCHR || s == S_IFBLK || s == S_IFSOCK) && devbehave == DEV_SKIP) return (0); } f = grep_open(fn); } if (f == NULL) { file_err = true; if (!sflag) warn("%s", fn); return (0); } ln.file = grep_malloc(strlen(fn) + 1); strcpy(ln.file, fn); ln.line_no = 0; ln.len = 0; linesqueued = 0; tail = 0; ln.off = -1; for (c = 0; c == 0 || !(lflag || qflag); ) { ln.off += ln.len + 1; if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL || ln.len == 0) { if (ln.line_no == 0 && matchall) exit(0); else break; } if (ln.len > 0 && ln.dat[ln.len - 1] == '\n') --ln.len; ln.line_no++; /* Return if we need to skip a binary file */ if (f->binary && binbehave == BINFILE_SKIP) { grep_close(f); free(ln.file); free(f); return (0); } /* Process the file line-by-line */ if ((t = procline(&ln, f->binary)) == 0 && Bflag > 0) { enqueue(&ln); linesqueued++; } c += t; if (mflag && mcount <= 0) break; } if (Bflag > 0) clearqueue(); grep_close(f); if (cflag) { if (!hflag) printf("%s:", ln.file); printf("%u\n", c); } if (lflag && !qflag && c != 0) printf("%s%c", fn, nullflag ? 0 : '\n'); if (Lflag && !qflag && c == 0) printf("%s%c", fn, nullflag ? 0 : '\n'); if (c && !cflag && !lflag && !Lflag && binbehave == BINFILE_BIN && f->binary && !qflag) printf(getstr(8), fn); free(ln.file); free(f); return (c); }
int main(int argc, char *argv[]) { FILE *input, *outiibs, *outfuncs, *outproto; char buf[BUFLEN], *p; int lineno = 0; (void)argc; (void)argv; /* open output files and write headers */ if ((outiibs = fopen(FNAME_OUTIIBS, "w")) == NULL) { perror("fopen outiibs"); exit(1); } fprintf(outiibs, "/* automatically generated by def68k.c */\n\n"); fprintf(outiibs, "t_iib iibs[] = {\n"); fprintf(outiibs, " /* mask, bits, mnemonic, { priv, endblk, zero, "); fprintf(outiibs, "used, set },\n"); fprintf(outiibs, " size, stype, dtype, sbitpos, dbitpos, immvalue, "); fprintf(outiibs, "cc, funcnum */\n"); if ((outfuncs = fopen(FNAME_OUTFUNCS, "w")) == NULL) { perror("fopen outfuncs"); exit(1); } fprintf(outfuncs, "/* automatically generated by def68k.c */\n\n"); fprintf(outfuncs, "void (*cpu68k_funcindex[])(t_ipc *ipc) = {\n"); fprintf(outfuncs, " /* function */\n"); if ((outproto = fopen(FNAME_OUTPROTO, "w")) == NULL) { perror("fopen outproto"); exit(1); } fprintf(outproto, "/* automatically generated by def68k.c */\n\n"); /* open input file */ if ((input = fopen(FNAME_CPUDEF, "r")) == NULL) { perror("fopen input"); exit(1); } /* loop until end of file */ printf("Writing CPU definitions... "); fflush(stdout); while (!feof(input)) { /* use unix line numbering from 1 */ lineno++; /* read a line */ if (ferror(input)) { break; } if (fgets(buf, BUFLEN, input) == NULL) { break; /* huh? why does this cause fgets to say 'Unknown error'?! */ perror("fgets"); exit(1); } /* remove newline */ buf[strlen(buf)-1] = '\0'; /* remove comment */ if ((p = strchr(buf, ';')) != NULL) { *p = '\0'; } /* remove leading spaces */ p = buf; while (*p == ' ') p++; /* blank line? */ if (!*p) continue; /* process line */ procline(buf, lineno, outiibs, outfuncs, outproto); } /* close input */ if (fclose(input)) { perror("fclose input"); exit(1); } /* output footer */ fprintf(outiibs, " { 0, 0, 0, { 0, 0, 0, 0, 0 }, " "0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }\n"); fprintf(outiibs, "};\n"); fprintf(outiibs, "int iibs_num = %d;\n", total); fprintf(outfuncs, "};\n"); /* close outputs */ if (fclose(outiibs)) { perror("fclose outiibs"); exit(1); } if (fclose(outfuncs)) { perror("fclose outfuncs"); exit(1); } if (fclose(outproto)) { perror("fclose outproto"); exit(1); } printf("done.\n"); fflush(stdout); return(0); }
int procfile(char *fn) { str_t ln; file_t *f; int c, t, z, nottext; if (fn == NULL) { fn = "(standard input)"; f = grep_fdopen(STDIN_FILENO, "r"); } else { f = grep_open(fn, "r"); } if (f == NULL) { file_err = 1; if (!sflag) warn("%s", fn); return 0; } nottext = grep_bin_file(f); if (nottext && binbehave == BIN_FILE_SKIP) { grep_close(f); return 0; } ln.file = fn; ln.line_no = 0; ln.len = 0; linesqueued = 0; tail = 0; ln.off = -1; if (Bflag > 0) initqueue(); for (c = 0; c == 0 || !(lflag || qflag); ) { ln.off += ln.len + 1; if ((ln.dat = grep_fgetln(f, &ln.len)) == NULL) break; if (ln.len > 0 && ln.dat[ln.len - 1] == '\n') --ln.len; ln.line_no++; z = tail; if ((t = procline(&ln, nottext)) == 0 && Bflag > 0 && z == 0) { enqueue(&ln); linesqueued++; } c += t; } if (Bflag > 0) clearqueue(); grep_close(f); if (cflag) { if (!hflag) printf("%s:", ln.file); printf("%u\n", c); } if (lflag && c != 0) printf("%s\n", fn); if (Lflag && c == 0) printf("%s\n", fn); if (c && !cflag && !lflag && !Lflag && binbehave == BIN_FILE_BIN && nottext && !qflag) printf("Binary file %s matches\n", fn); return c; }