static Boolean ReadMakefile( const char *fname, /* makefile to read */ Boolean isSystem) /* system makefile */ { FILE *stream; string_t name; if (!strcmp(fname, "-")) { Var_Set(sMAKEFILE, sNULL, VAR_GLOBAL); Parse_File(string_create("(stdin)"), stdin); } else { string_t sfname = string_create(fname); if (!isSystem) { name = Dir_FindFile(sfname, dirSearchPath); } else { name = Dir_FindFile(sfname, parseIncPath); if (name == (string_t) NULL) name = Dir_FindFile(sfname, sysIncPath); } string_deref(sfname); if (name == (string_t) NULL || (stream = fopen(name->data, "r")) == NULL) return(FALSE); /* * set the MAKEFILE variable desired by System V fans -- the * placement of the setting here means it gets set to the last * makefile specified, as it is set by SysV make. */ Var_Set(sMAKEFILE, name, VAR_GLOBAL); Parse_File(name, stream); (void)fclose(stream); } return(TRUE); }
int main (int argc, char * argv[]) { char * filename = argv[1]; Program_Module m = Program_ModuleNew(); Program_ParseArguments (m, argc, argv); printf ("Compiling %s\n", String_Data (m->options.file)); if (Parse_File (m, m->options.file) != 0) { printf ("Lex errors: %lu\n", Vector_Size (&m->errors.lexer)); VECTOR_FOREACH (struct Error_t, error, &m->errors.lexer) { Error_Print (stdout, error); } printf ("Parse errors: %lu\n", Vector_Size (&m->errors.parser)); VECTOR_FOREACH (struct Error_t, error, &m->errors.parser) { Error_Print (stdout, error); } VECTOR_FOREACH (struct Program_Option_t, o, &m->options.debug) { if (String_Equal (&o->key, "parse-only")) { printf ("Exiting, because of '%s'.\n", o->key.data); exit (0); } } printf ("Exiting, fix the errors and try again."); exit (0); }
/** * Open and parse the given makefile. * * Results: * TRUE if ok. FALSE if couldn't open file. */ static Boolean ReadMakefile(const char p[]) { char *fname, *fnamesave; /* makefile to read */ FILE *stream; char *name, path[MAXPATHLEN]; char *MAKEFILE; int setMAKEFILE; /* XXX - remove this once constification is done */ fnamesave = fname = estrdup(p); if (!strcmp(fname, "-")) { Parse_File("(stdin)", stdin); Var_SetGlobal("MAKEFILE", ""); } else { setMAKEFILE = strcmp(fname, ".depend"); /* if we've chdir'd, rebuild the path name */ if (curdir != objdir && *fname != '/') { snprintf(path, MAXPATHLEN, "%s/%s", curdir, fname); /* * XXX The realpath stuff breaks relative includes * XXX in some cases. The problem likely is in * XXX parse.c where it does special things in * XXX ParseDoInclude if the file is relative * XXX or absolute and not a system file. There * XXX it assumes that if the current file that's * XXX being included is absolute, that any files * XXX that it includes shouldn't do the -I path * XXX stuff, which is inconsistent with historical * XXX behavior. However, I can't penetrate the mists * XXX further, so I'm putting this workaround in * XXX here until such time as the underlying bug * XXX can be fixed. */ #if THIS_BREAKS_THINGS if (realpath(path, path) != NULL && (stream = fopen(path, "r")) != NULL) { MAKEFILE = fname; fname = path; goto found; } } else if (realpath(fname, path) != NULL) { MAKEFILE = fname; fname = path; if ((stream = fopen(fname, "r")) != NULL) goto found; } #else if ((stream = fopen(path, "r")) != NULL) { MAKEFILE = fname; fname = path; goto found; } } else {
/*- * ReadMakefile -- * Open and parse the given makefile. * * Results: * true if ok. false if couldn't open file. * * Side Effects: * lots */ static bool ReadMakefile(void *p, void *q) { const char *fname = p; /* makefile to read */ struct dirs *d = q; FILE *stream; char *name; if (!strcmp(fname, "-")) { Var_Set("MAKEFILE", ""); Parse_File(estrdup("(stdin)"), stdin); } else { if ((stream = fopen(fname, "r")) != NULL) goto found; /* if we've chdir'd, rebuild the path name */ if (d->current != d->object && *fname != '/') { char *path; path = Str_concat(d->current, fname, '/'); if ((stream = fopen(path, "r")) == NULL) free(path); else { fname = path; goto found; } } /* look in -I and system include directories. */ name = Dir_FindFile(fname, userIncludePath); if (!name) name = Dir_FindFile(fname, systemIncludePath); if (!name || !(stream = fopen(name, "r"))) return false; fname = name; /* * set the MAKEFILE variable desired by System V fans -- the * placement of the setting here means it gets set to the last * makefile specified, as it is set by SysV make. */ found: Var_Set("MAKEFILE", fname); Parse_File(fname, stream); } return true; }
int main(int argc, char **argv) { // 1.test arguments is valid or not // if (argc != 2) { printf("Usage: %s <input_file>\n", argv[0]); exit(1); } // 1.1 Initialize all parameters and allocate memory, (some memory are allocated in Parse_File()) char *file_name = argv[1]; struct RS_line *RS; // register station int RS_size; struct ALU_line *ALU; int ALU_size; struct input_instr *instr_mem = (struct input_instr *) malloc(MEM_SIZE * sizeof(struct input_instr)); memset(instr_mem, 0, MEM_SIZE * sizeof(struct input_instr)); float *data_mem = (float *) malloc(MEM_SIZE * sizeof(float)); memset(data_mem, 0, MEM_SIZE * sizeof(float)); float *float_RF = (float *) malloc(ARF_SIZE * sizeof(float)); memset(float_RF, 0, ARF_SIZE * sizeof(float)); int *int_RF = (int *) malloc(ARF_SIZE * sizeof(int)); memset(int_RF, 0, ARF_SIZE * sizeof(int)); struct RAT_line *RAT = (struct RAT_line *) malloc(2 * ARF_SIZE * sizeof(struct RAT_line)); memset(RAT, 0, 2 * ARF_SIZE * sizeof(struct RAT_line)); struct ROB_line *ROB; int ROB_size; int cycles = 0; int PC = 0; // next commit ROB int ROB_nextcommit = 0; // next available ROB int ROB_nextfree = 0; // CDB int cdb_free = 1; // 2.parse arguments load instr to memory // 3.initialize: RS, ROB, ARF, Timing Table, Memory if (Parse_File(file_name, instr_mem, data_mem, &RS, &RS_size, float_RF, int_RF, &ROB, &ROB_size, &ALU, &ALU_size)) { printf("Read file failed.\n"); exit(1); } //DEBUG: print status if (printStatus(instr_mem, data_mem, RS, RS_size, float_RF, int_RF, ROB, ROB_size, ALU, ALU_size, RAT)) { printf("Print Status failed.\n"); exit(1); } // 4.Start simulate until PC point to NULL while (has_instr(instr_mem, PC) || !ROB_empty(ROB, ROB_size)) { // 4.1 ISSUE to RS instr2RS(instr_mem, &PC, RS, RS_size, ROB, ROB_size, RAT, &ROB_nextfree); // 4.2 issue stage to exec stage // Requirement: // 1.issue exe 1 cycle // 2.have room in ALU // 3.all data are ready toExec(RS, RS_size, ALU, ALU_size, ROB, ROB_size); //exec stage to writeback //Requirement: //1.exec is complete //2.cdb is free (?) toWback(RS, RS_size, ALU, ALU_size, ROB, ROB_size, cdb_free); //writeback stage to commit toCommit(ROB, &ROB_nextcommit, RAT, int_RF, float_RF); cycles++; } /* ** while (has_next(instr_array) || not_empty(ROB)) { get next_instr; // insert this instr into RS and update RAT & ROB if (has_seat(RS, next_instr) && has_seat(ROB, next_instr)) { // use RAT to update instr if (operandof(next_instr) is in ARF) { load value directly. } else { load ROB location. } // insert this instr into RS insert(next_instr, RS); // update ROB & RAT update dest of next_instr in RAT. update dest of next_instr in ROB. } //update all buffer in this function add_cycle(RS) if (any_instr in RS ready to exec) { start_exec(this_instr); } if (any_instr in RS ready to write back && CDB is free) { start_writeback(this_instr); } if (write back in CDB is complete) { update ROB; remove this instr from RS; update RS waiting for this result; } } **/ return 0; }
void UI_LoadScript(void) { Parse_File("q2pro.menu", 0); }
static qboolean Parse_File(const char *path, int depth) { char *raw, *data, *p, *cmd; int argc; menuFrameWork_t *menu = NULL; qerror_t ret; ret = FS_LoadFile(path, (void **)&raw); if (!raw) { if (ret != Q_ERR_NOENT || depth) { Com_WPrintf("Couldn't %s %s: %s\n", depth ? "include" : "load", path, Q_ErrorString(ret)); } return qfalse; } data = raw; COM_Compress(data); while (*data) { p = strchr(data, '\n'); if (p) { *p = 0; } Cmd_TokenizeString(data, qtrue); argc = Cmd_Argc(); if (argc) { cmd = Cmd_Argv(0); if (menu) { if (!strcmp(cmd, "end")) { if (menu->nitems) { List_Append(&ui_menus, &menu->entry); } else { Com_WPrintf("Menu entry without items\n"); menu->free(menu); } menu = NULL; } else if (!strcmp(cmd, "title")) { if (menu->title) { Z_Free(menu->title); } menu->title = UI_CopyString(Cmd_Argv(1)); } else if (!strcmp(cmd, "plaque")) { Parse_Plaque(menu); } else if (!strcmp(cmd, "banner")) { Parse_Banner(menu); } else if (!strcmp(cmd, "background")) { Parse_Background(menu); } else if (!strcmp(cmd, "style")) { Parse_Style(menu); } else if (!strcmp(cmd, "values")) { Parse_Spin(menu, MTYPE_SPINCONTROL); } else if (!strcmp(cmd, "strings")) { Parse_Spin(menu, MTYPE_STRINGS); } else if (!strcmp(cmd, "pairs")) { Parse_Pairs(menu); } else if (!strcmp(cmd, "range")) { Parse_Range(menu); } else if (!strcmp(cmd, "action")) { Parse_Action(menu); } else if (!strcmp(cmd, "bitmap")) { Parse_Bitmap(menu); } else if (!strcmp(cmd, "bind")) { Parse_Bind(menu); } else if (!strcmp(cmd, "savegame")) { Parse_Savegame(menu, MTYPE_SAVEGAME); } else if (!strcmp(cmd, "loadgame")) { Parse_Savegame(menu, MTYPE_LOADGAME); } else if (!strcmp(cmd, "toggle")) { Parse_Toggle(menu); } else if (!strcmp(cmd, "field")) { Parse_Field(menu); } else if (!strcmp(cmd, "blank")) { Parse_Blank(menu); } else { Com_WPrintf("Unknown keyword '%s'\n", cmd); } } else { if (!strcmp(cmd, "begin")) { char *s = Cmd_Argv(1); if (!*s) { Com_WPrintf("Expected menu name after '%s'\n", cmd); break; } menu = UI_FindMenu(s); if (menu) { if (menu->free) { menu->free(menu); } List_Remove(&menu->entry); } menu = UI_Mallocz(sizeof(*menu)); menu->name = UI_CopyString(s); menu->push = Menu_Push; menu->pop = Menu_Pop; menu->free = Menu_Free; menu->image = uis.backgroundHandle; menu->color.u32 = uis.color.background.u32; menu->transparent = uis.transparent; } else if (!strcmp(cmd, "include")) { char *s = Cmd_Argv(1); if (!*s) { Com_WPrintf("Expected file name after '%s'\n", cmd); break; } if (depth == 16) { Com_WPrintf("Includes too deeply nested\n"); } else { Parse_File(s, depth + 1); } } else if (!strcmp(cmd, "color")) { Parse_Color(); } else if (!strcmp(cmd, "background")) { char *s = Cmd_Argv(1); if (SCR_ParseColor(s, &uis.color.background)) { uis.backgroundHandle = 0; uis.transparent = uis.color.background.u8[3] != 255; } else { uis.backgroundHandle = R_RegisterPic(s); uis.transparent = R_GetPicSize(NULL, NULL, uis.backgroundHandle); } } else if (!strcmp(cmd, "font")) { uis.fontHandle = R_RegisterFont(Cmd_Argv(1)); } else if (!strcmp(cmd, "cursor")) { uis.cursorHandle = R_RegisterPic(Cmd_Argv(1)); R_GetPicSize(&uis.cursorWidth, &uis.cursorHeight, uis.cursorHandle); } else if (!strcmp(cmd, "weapon")) { Cmd_ArgvBuffer(1, uis.weaponModel, sizeof(uis.weaponModel)); } else { Com_WPrintf("Unknown keyword '%s'\n", cmd); break; } } } if (!p) { break; } data = p + 1; } FS_FreeFile(raw); if (menu) { Com_WPrintf("Menu entry without 'end' terminator\n"); menu->free(menu); } return qtrue; }
/*- * ReadMakefile -- * Open and parse the given makefile. * * Results: * TRUE if ok. FALSE if couldn't open file. * * Side Effects: * lots */ static Boolean ReadMakefile(ClientData p, ClientData q __unused) { char *fname = p; /* makefile to read */ FILE *stream; size_t len = MAXPATHLEN; char *name, *path = emalloc(len); int setMAKEFILE; if (!strcmp(fname, "-")) { Parse_File("(stdin)", stdin); Var_Set("MAKEFILE", "", VAR_GLOBAL, 0); } else { setMAKEFILE = strcmp(fname, ".depend"); /* if we've chdir'd, rebuild the path name */ if (strcmp(curdir, objdir) && *fname != '/') { size_t plen = strlen(curdir) + strlen(fname) + 2; if (len < plen) path = erealloc(path, len = 2 * plen); (void)snprintf(path, len, "%s/%s", curdir, fname); if ((stream = fopen(path, "r")) != NULL) { fname = path; goto found; } /* If curdir failed, try objdir (ala .depend) */ plen = strlen(objdir) + strlen(fname) + 2; if (len < plen) path = erealloc(path, len = 2 * plen); (void)snprintf(path, len, "%s/%s", objdir, fname); if ((stream = fopen(path, "r")) != NULL) { fname = path; goto found; } } else if ((stream = fopen(fname, "r")) != NULL) goto found; /* look in -I and system include directories. */ name = Dir_FindFile(fname, parseIncPath); if (!name) name = Dir_FindFile(fname, Lst_IsEmpty(sysIncPath) ? defIncPath : sysIncPath); if (!name || !(stream = fopen(name, "r"))) { free(path); return(FALSE); } fname = name; /* * set the MAKEFILE variable desired by System V fans -- the * placement of the setting here means it gets set to the last * makefile specified, as it is set by SysV make. */ found: if (setMAKEFILE) Var_Set("MAKEFILE", fname, VAR_GLOBAL, 0); Parse_File(fname, stream); (void)fclose(stream); } free(path); return(TRUE); }