BOOL cmdlne_SetFlags(FLAGSTORE flagstore) /**************************************************************** INPUT: a FLAGSTORE RETURNS: TRUE if all arguments of <cmdlne_ArgumentsList> are valid arguments and the respective flags of <flagstore> could be set and FALSE otherwise. EFFECT: Set flags of <flagstore> according to arguments stored in <cmdlne_ArgumentsList> *****************************************************************/ { int id, tk; LIST Scan; BOOL found; for(Scan=cmdlne_ArgumentsList; !list_Empty(Scan); Scan = list_Cdr(Scan)) { found = FALSE; for (id=0; id < flag_GetMaxFlag() && !found; id++) { if (!flag_IsUndefined(id) && string_Equal(flag_Name(id), (char*) list_PairFirst(list_Car(Scan))) ) { if (flag_IsOfValueType(id, flag_INTEGER)) { if(!string_StringIsInteger(list_PairSecond(list_Car(Scan)))){ misc_StartUserErrorReport(); misc_UserErrorReport("\nError: Argument of option %s must be an integer.\n\n", flag_Name(id)); misc_FinishUserErrorReport(); return FALSE; } tk = atoi((char*) list_PairSecond(list_Car(Scan))); flag_SetFlagIntValue(flagstore, id, tk); } else { flag_SetFlagStringValue(flagstore, id, string_StringCopy((char*)list_PairSecond(list_Car(Scan)))); } found = TRUE; } } if(!found) { misc_StartUserErrorReport(); misc_UserErrorReport("\n Unrecognized option %s\n\n", (char*) list_PairFirst(list_Car(Scan))); misc_FinishUserErrorReport(); return FALSE; } } return TRUE; }
BOOL cmdlne_SetArgument(const char* token, const char* value) /************************************************************** INPUT: two pointers RETURNS: TRUE if the argument <token> has not been added to the list of arguments before and FALSE otherwise. EFFECT: Adds argument <token> with value <value> to list of arguments (<cmdlne_ArgumentsList>) CAUTION: <value> has to be a character pointer pointing to a string representing an integer ***************************************************************/ { LIST Pair; LIST Scan; /* Check if Argument has already been defined */ for(Scan=cmdlne_ArgumentsList; !list_Empty(Scan); Scan = list_Cdr(Scan)) { if(string_Equal(list_PairFirst(list_Car(Scan)),token)) { misc_StartUserErrorReport(); misc_UserErrorReport("\n Option %s is multiply defined.\n\n", token); misc_FinishUserErrorReport(); return FALSE; } } /* Add <token> to argument list with value <value>*/ Pair = list_PairCreate(string_StringCopy(token), string_StringCopy(value)); cmdlne_ArgumentsList = list_Cons(Pair, cmdlne_ArgumentsList); return TRUE; }
FILE* misc_OpenFile(const char* Name, const char* Mode) /************************************************************** INPUT: The name of a file and a string containing the mode for opening the file (see fopen(3)). Examples for Mode are "r" for reading and "w" for writing. RETURNS: The FILE pointer, if the file was successfully opened. EFFECT: If it wasn't possible to open the file with the requested mode, an error message is printed and the program exits. ***************************************************************/ { FILE* File; File = fopen(Name,Mode); if (File == (FILE*)NULL) { misc_StartUserErrorReport(); misc_UserErrorReport("\n\tError in opening file %s for %s !\n\n", Name, (Mode[0] == 'r' ? "reading" : (Mode[0] == 'w' ? "writing" : "i/o operations"))); misc_FinishUserErrorReport(); } return File; }
void misc_CloseFile(FILE* File, const char* Name) /************************************************************** INPUT: A FILE and its name. RETURNS: Nothing. EFFECT: Closes the file. If an error occurs, a message is printed and the program exits. ***************************************************************/ { int Result; Result = fclose(File); if (Result != 0) { misc_StartUserErrorReport(); misc_UserErrorReport("\n\tError in closing file %s !\n\n", Name); misc_FinishUserErrorReport(); } }
void tab_AddClauseOnItsLevel(CLAUSE C, TABPATH Path) /************************************************************** INPUT: A clause, a tableau path RETURNS: Nothing EFFECTS: Adds the clause on its split level which must belong to <Path> ***************************************************************/ { int Level; Level = clause_SplitLevel(C); if (Level > tab_PathLength(Path)) { misc_StartUserErrorReport(); misc_UserErrorReport("\nError: Split level of some clause "); misc_UserErrorReport("\nis higher than existing level."); misc_UserErrorReport("\nThis may be a bug in the proof file."); misc_FinishUserErrorReport(); } tab_AddClause(C, tab_PathNthNode(Path, clause_SplitLevel(C))); }
void tab_WriteTableau(TABLEAU T, const char* Filename, GRAPHFORMAT Format) /************************************************************** INPUT: A tableau, a filename RETURNS: Nothing. ***************************************************************/ { FILE* File; if (Format != DAVINCI && Format != XVCG) { misc_StartUserErrorReport(); misc_UserErrorReport("\nError: unknown output format for tableau.\n"); misc_FinishUserErrorReport(); } File = misc_OpenFile(Filename, "w"); if (Format == DAVINCI) tab_FPrintDaVinciFormat(File, T); else if (Format == XVCG) tab_FPrintCgFormat(File, T); misc_CloseFile(File, Filename); }
static SYMBOL symbol_SignatureCreate(char* String, int Type, int Arity, int Status, PRECEDENCE Precedence) /************************************************************** INPUT: A pointer to a string, a type, the arity and the status RETURNS: The symbol containing the passed parameters. SUMMARY: Establishes a new symbol in the symbol table and returns the internal representation (pointer and type). CAUTION: The string is not copied! ***************************************************************/ { SIGNATURE Entry; #ifdef CHECK if (!symbol_SignatureExists()) { misc_StartErrorReport(); misc_ErrorReport("\n In symbol_SignatureCreate:"); misc_ErrorReport(" Module was initialized with no signature.\n"); misc_FinishErrorReport(); } if (Type < 0 || Type >= symbol_SIGTYPES) { misc_StartErrorReport(); misc_ErrorReport("\n In symbol_SignatureCreate: Illegal input.\n"); misc_FinishErrorReport(); } #endif if ((int)symbol_ACTINDEX >= symbol__MAXSIGNATURE && list_Empty(symbol_FREEDSYMBOLS)) { misc_StartUserErrorReport(); misc_UserErrorReport("\n In symbol_SignatureCreate: No more symbols available.\n"); misc_FinishUserErrorReport(); } if (strlen(String)>=symbol__SYMBOLMAXLEN) { misc_StartUserErrorReport(); misc_UserErrorReport("\n In symbol_SignatureCreate: String too long.\n"); misc_FinishUserErrorReport(); } Entry = symbol_GetSignature(); Entry->weight = 1; Entry->props = 0; Entry->name = String; Entry->length = strlen(String); Entry->arity = Arity; Entry->generatedBy = list_Nil(); if (list_Empty(symbol_FREEDSYMBOLS)) { Entry->info = symbol_SignatureSymbol(symbol_ACTINDEX, Type, Status); symbol_SetSignature(symbol_ACTINDEX++, Entry); } else { int Index; Index = (int)list_Car(symbol_FREEDSYMBOLS); symbol_FREEDSYMBOLS = list_PointerDeleteElement(symbol_FREEDSYMBOLS, (POINTER)Index); Entry->info = symbol_SignatureSymbol(Index, Type, Status); symbol_SetSignature(Index, Entry); } /* Define precedence of symbol */ symbol_SetIncreasedOrdering(Precedence, Entry->info); return Entry->info; }
BOOL cmdlne_LexScan(const char* string) /***************************************************************** INPUT: FLAGSTORE, a string containing program parameter data RETURNS: TRUE iff <string> contains a valid option and returns FALSE if <string> is not a valid option EFFECT: Scan the cmdlne arguments ****************************************************************/ { int cp,tp1,tp2,tp3; char c; char token1[cmdlne_MAXTOKENLENGTH]; char token2[cmdlne_MAXTOKENLENGTH]; tp1 = tp2 = tp3 = 0; if (string[0] == '-') { cp = 1; c = string[cp]; if (isalpha(c)) { while(isalpha(c)) { token1[tp1] = c; tp1++; cp++; c = string[cp]; } if (c == '\0') { token1[tp1] = '\0'; if(cmdlne_HandleShortArg(token1)) { return TRUE; } else { misc_StartUserErrorReport(); misc_UserErrorReport("\nUnrecognized option: -%s\n\n",token1); misc_FinishUserErrorReport(); return FALSE; } } else if (c == '=') { /*For long type of arguments*/ cp++; c = string[cp]; token1[tp1] = '\0'; if (cmdlne_isArgSym(c)) { token2[tp2]= c; tp2++; cp++; c=string[cp]; while (cmdlne_isArgSym(c)) { token2[tp2]=c; tp2++; cp++; c = string[cp]; } if(c == '\0') { token2[tp2] = '\0'; if(cmdlne_HandleArg(token1, token2)) { return TRUE; } else { misc_StartUserErrorReport(); misc_UserErrorReport("\nUnrecognized option: -%s=%s\n\n",token1, token2); misc_FinishUserErrorReport(); return FALSE; } } else { misc_StartUserErrorReport(); misc_UserErrorReport("\nError: Invalid argument of option %s.\n\n", token1); misc_FinishUserErrorReport(); return FALSE; } } else { misc_StartUserErrorReport(); misc_UserErrorReport("\n Invalid argument of option %s.\n\n", token1); misc_FinishUserErrorReport(); return FALSE; } } else { while (!c == '\0') { token1[tp1]=c; tp1++; cp++; c = string[cp]; } token1[tp1] = '\0'; printf("\nUnrecognized option: -%s\n\n",token1); return FALSE; } } else { while (!c == '\0') { token1[tp1]=c; tp1++; cp++; c = string[cp]; } token1[tp1] = '\0'; printf("\nUnrecognized option: -%s\n\n",token1); return FALSE; } } else { if(cmdlne_InputFile == (char*)NULL) { cmdlne_InputFile = string; /*printf("\nInput File: %s", cmdlne_InputFile);*/ return TRUE; } else if(cmdlne_OutputFile == (char*)NULL) { cmdlne_OutputFile = string; /*printf("\nOutput File: %s", cmdlne_OutputFile);*/ return TRUE; } } /* This function should never execute this code */ misc_StartUserErrorReport(); misc_UserErrorReport("\n Parse error in cmdlne_LexScan.\n\n"); misc_FinishUserErrorReport(); return FALSE; }