//------------------------------------------------------------------------- // //------------------------------------------------------------------------- const char* SettingsFile::GetNextLine(const char *cur_line) { if(!cur_line) return cur_line; while(1) { // Skip whitespace, carriage returns, line feed, etc. while((*cur_line > 0) && (*cur_line <= ' ')) { cur_line++; } switch(*cur_line) { case 0: return 0; case ';': // Comment cur_line = SkipLine(cur_line); break; default: // Not a comment, not whitespace, not a blank line return cur_line; } } // Shouldn't ever get here return 0; }
short HeaderCommands() { int v; SkipWhiteSpace(); //------------------------------------ // //------------------------------------ if (QToken("#define")) { SkipWhiteSpace(); GetAsmName(); strcpy(DefineNameCopy, Name); if (NextToken("#")) { // Just define a script RedefENum(DefineNameCopy, 1); rhprint("HeaderRead: .set %s = 1\n", DefineNameCopy); SkipWhiteSpace(); return 1; } // Test for strings if (QToken("\"")) { GetStringName(128); RedefENumString(DefineNameCopy, Name); printf("HeaderRead: .set %s = '%s'\n", DefineNameCopy, Name); SkipWhiteSpace(); return 1; } v = GetExpression(); RedefENum(DefineNameCopy, v); SkipWhiteSpace(); rhprint("Profile: unknown define '%s'\n", DefineNameCopy); return 1; } //------------------------------------ // Line not understood, skip line //------------------------------------ SkipLine(); return 0; }
void SkipWhiteSpace() { register char c; PrevFilePtr = FilePtr; while (WS[(unsigned char)*FilePtr]) FilePtr++; while(1) { while (WS[(unsigned char)*FilePtr]) FilePtr++; if (SkipCommentOn == 1) { if (*FilePtr == ';') { SkipLine(); continue; } if (*FilePtr == '/') { c = *(FilePtr+1); if ( c == '/') { SkipLine(); continue; } if (c == '*') { SkipComment(); continue; } } } break; } }
static int trace = 0; #define T_TOP 0001 /* top level tracing */ #define T_HDR 0002 /* show header processing */ #define T_HASH 0004 /* hash table tracing */
char * TokenSearch(char *token, char *theFilePtr, char **eof) { char *ptr; PushTokenPtr(theFilePtr, 1); while(1) { if (*FilePtr == 0) { break; } SkipWhiteSpace(); if (*FilePtr == '.') { if (NextToken(token)) { ptr = FilePtr; // Restore file ptr PopTokenPtr(); return ptr; // Found something } } SkipLine(); } if (eof) *eof = FilePtr; PopTokenPtr(); // Say nothing found return 0; }
void GetCOdict(char *name) { /* This subroutine populates the cut-off dictionary for each bond and throws an error if any possible combination of atoms do not have a specified bond*/ FILE *fp; int i,j,iatom,jatom; double cut; #define BUFLEN 1000 char buffer[BUFLEN]; fp=fopen(name,"r"); FileOpenError(fp,name); for(i=0;i<Natomtypes;i++) { for(j=0;j<Natomtypes;j++) COdic[i][j]=-1; } while(fscanf(fp,"%s",buffer)!=EOF) { if (strcmp(buffer,"#") == 0) { SkipLine(fp); continue; } iatom=AtomIndicator(buffer); fscanf(fp,"%s",buffer); jatom=AtomIndicator(buffer); fscanf(fp,"%lf",&cut); COdic[iatom][jatom]=cut; COdic[jatom][iatom]=cut; } for(i=0;i<Natomtypes;i++) { for(j=0;j<Natomtypes;j++) { if(COdic[i][j]==-1) { printf("Can't fine a certain pair for cut off dictionary!\n"); exit(0); } } } close(fp); }
void SkipWhiteSpace() { while(1) { while (iswhite(*FilePtr)) FilePtr++; if (*FilePtr == '/' && *(FilePtr+1) == '/') { SkipLine(); continue; } if (*FilePtr == '/' && *(FilePtr+1) == '*') { SkipComment(); continue; } break; } }
void Indexer::Build() { if (!m_chunks.empty()) { return; } if (m_maxChunkSize > 0) { auto fileSize = filesize(m_file); m_chunks.reserve((fileSize + m_maxChunkSize - 1) / m_maxChunkSize); } m_chunks.push_back({}); RefillBuffer(); // read the first block of data if (m_done) { RuntimeError("Input file is empty"); } if ((m_bufferEnd - m_bufferStart > 3) && (m_bufferStart[0] == '\xEF' && m_bufferStart[1] == '\xBB' && m_bufferStart[2] == '\xBF')) { // input file contains UTF-8 BOM value, skip it. m_pos += 3; m_fileOffsetStart += 3; m_bufferStart += 3; } // check the first byte and decide what to do next if (!m_hasSequenceIds || m_bufferStart[0] == NAME_PREFIX) { // skip sequence id parsing, treat lines as individual sequences BuildFromLines(); return; } size_t id = 0; int64_t offset = GetFileOffset(); // read the very first sequence id if (!GetNextSequenceId(id)) { RuntimeError("Expected a sequence id at the offset %" PRIi64 ", none was found.", offset); } SequenceDescriptor sd = {}; sd.m_id = id; sd.m_fileOffsetBytes = offset; sd.m_isValid = true; while (!m_done) { SkipLine(); // ignore whatever is left on this line. offset = GetFileOffset(); // a new line starts at this offset; sd.m_numberOfSamples++; if (!m_done && GetNextSequenceId(id) && id != sd.m_id) { // found a new sequence, which starts at the [offset] bytes into the file sd.m_byteSize = offset - sd.m_fileOffsetBytes; AddSequence(sd); sd = {}; sd.m_id = id; sd.m_fileOffsetBytes = offset; sd.m_isValid = true; } } // calculate the byte size for the last sequence sd.m_byteSize = m_fileOffsetEnd - sd.m_fileOffsetBytes; AddSequence(sd); }
static struct Acl * ParseAcl(char *a_str) { /*ParseAcl */ int nplus, nminus, i, trights; char tname[MAXNAME]; struct AclEntry *first, *last, *tl; struct Acl *ta; /* * Pull out the number of positive & negative entries in the externalized * ACL. */ sscanf(a_str, "%d", &nplus); a_str = SkipLine(a_str); sscanf(a_str, "%d", &nminus); a_str = SkipLine(a_str); /* * Allocate and initialize the first entry. */ ta = malloc(sizeof(struct Acl)); ta->nplus = nplus; ta->nminus = nminus; /* * Translate the positive entries. */ last = 0; first = 0; for (i = 0; i < nplus; i++) { sscanf(a_str, "%100s %d", tname, &trights); a_str = SkipLine(a_str); tl = malloc(sizeof(struct AclEntry)); if (!first) first = tl; strcpy(tl->name, tname); tl->rights = trights; tl->next = 0; if (last) last->next = tl; last = tl; } ta->pluslist = first; /* * Translate the negative entries. */ last = 0; first = 0; for (i = 0; i < nminus; i++) { sscanf(a_str, "%100s %d", tname, &trights); a_str = SkipLine(a_str); tl = malloc(sizeof(struct AclEntry)); if (!first) first = tl; strcpy(tl->name, tname); tl->rights = trights; tl->next = 0; if (last) last->next = tl; last = tl; } ta->minuslist = first; return (ta); } /*ParseAcl */
short Directives() { int t; SkipWhiteSpace(); if (*FilePtr != '.') return 0; DataCharPtr = FilePtr; if (QToken(".eof")) { // mark end of label array as end of bss strcpy(Name, "_________eof_________"); Section = SECT_bss; DefineLabel(label_Local); SourceFileCheckEOF(LastTokenPtr() - FileTop); EndFile = 1; return 1; } GetToken(); t = ScanAsmToken(); switch(t) { //--------------------------------------------------------- case 0: Error(Error_Skip, "Illegal directive '%s'",Name); //--------------------------------------------------------- case dir_sourcefile: { int file; SkipWhiteSpace(); GetLFileName(); // SetCSourceFile(Name); file = SetSLD_Name(Name); SetCSourceFile(Name, file); return 1; } //--------------------------------------------------------- case dir_model: { int model=0; if (Token("full")) // Get return type model = MODEL_full; else if (Token("half")) // Get return type model = MODEL_half; else if (Token("compact")) // Get return type model = MODEL_compact; else if (Token("mini")) // Get return type model = MODEL_mini; else if (Token("tiny")) // Get return type model = MODEL_tiny; else Error(Error_Fatal, "invalid model type"); // if model is not set then set it if (!CurrentModel) CurrentModel = model; else { if (model != CurrentModel) Error(Error_Fatal, "multiple architectual models defined"); } return 1; } //--------------------------------------------------------- case dir_ctor: { SYMBOL* ref; imm = GetExpression(); // Get the number ref = GetLastSymbolRef(); if(pass_count > 1) { if (!ref) Error(Error_Fatal, "Constructor has bad reference"); ArraySet(&CtorArrayImm, CtorCount, imm); ArraySet(&CtorArray, CtorCount++, (int) ref); } return 1; } //--------------------------------------------------------- case dir_dtor: { SYMBOL* ref; imm = GetExpression(); // Get the number ref = GetLastSymbolRef(); if(pass_count > 1) { if (!ref) Error(Error_Fatal, "Destructor has bad reference"); ArraySet(&DtorArrayImm, DtorCount, imm); ArraySet(&DtorArray, DtorCount++, (int) ref); } return 1; } //--------------------------------------------------------- case dir_sourcedir: { SkipWhiteSpace(); GetLFileName(); SetCSourceDir(Name); return 1; } //--------------------------------------------------------- case dir_line: { int v; SkipWhiteSpace(); v = GetNum(); SetCSourceLine(v); SetSLD_Line(v); return 1; } //--------------------------------------------------------- case dir_dlab: { if (!ArgUseStabs) { SkipLine(); // Skip excess debug labels return 1; } // Define a label Section = SECT_code; GetAsmName(); DefineLabel(label_Local); return 1; } //--------------------------------------------------------- case dir_library: { SkipLine(); return 1; } //--------------------------------------------------------- case dir_exit: { if (NextToken("\"")) { GetStringName(1024); Error(Error_Fatal, "User: %s", Name); return 1; } Error(Error_Fatal, "Exiting with user error"); return 1; } //--------------------------------------------------------- case dir_asm_on: { return 1; } //--------------------------------------------------------- case dir_asm_off: { /* if (QToken(".asm_off")) { return 1; } */ return 1; } //--------------------------------------------------------- case dir_AllowFarBranches: { AllowFarBranches = 1; return 1; } //--------------------------------------------------------- case dir_bp: { return 1; } //--------------------------------------------------------- case dir_localscope: { SkipWhiteSpace(); if (Token("+")) { LocalScope++; return 1; } if (Token("reset")) { LocalScope = 1; return 1; } Error(Error_Fatal, "Bad .localscope type"); return 1; } //--------------------------------------------------------- case dir_func: { Function_Return_Type = RET_void; GetName(); ReplaceChar(Name, '.', '_'); Function_Param_Count = -1; if (Token(",")) { Function_Param_Count = GetNum(); if (Token(",")) // Get param count { if (Token("int")) // Get return type Function_Return_Type = RET_int; else if (Token("float")) Function_Return_Type = RET_float; else if (Token("double")) Function_Return_Type = RET_double; else if (Token("void")) Function_Return_Type = RET_void; else if (Token("?")) Function_Return_Type = RET_double; //patch fix } } DefineLabel(label_Function); return 1; } //--------------------------------------------------------- case dir_local: { GetName(); return 1; } //--------------------------------------------------------- case dir_vec_elt: { GetName(); return 1; } //--------------------------------------------------------- case dir_syscall: { char SysCallName[256]; char istr[4096]; char *iptr = 0; int v, p, r; p = 0; r = RET_void; GetName(); strcpy(SysCallName,Name); SkipWhiteSpace(); v = GetExpression(); if (Token(",")) // Get param count { p = GetExpression(); NeedToken(","); if (Token("int")) // Get return type r = RET_int; else if (Token("float")) r = RET_float; else if (Token("double")) r = RET_double; else if (Token("void")) r = RET_void; if (Token(",")) // Get interface { GetStringName(2048); strcpy(istr,Name); iptr = istr; } } if (Pass == 1) MapSysCall(SysCallName, v, p, r, iptr); return 1; } //--------------------------------------------------------- case dir_lfile: { SkipWhiteSpace(); GetLFileName(); strcpy(CurrentFile, Name); // CurrentFileLine = GetLineNumber(FileTop,GetPrevFilePtr()); AddFileSym(Name, LocalScope+1); GetRelPath(CurrentFile); return 1; } //--------------------------------------------------------- case dir_org: { int v = GetExpression(); if (v >= MAX_CODE_MEM) Error(Error_Fatal, ".org has illegal address"); CodeIP = v; //! CodePtr = &CodeMem[v]; printf("*Warning* org %x\n", v); return 1; } //--------------------------------------------------------- case dir_set: { SkipWhiteSpace(); // Catch Thunks if (Token("%")) { SYMBOL *ThunkSym; int v; v = GetDecNum(5); if (GetDecNumDigitCount() == 0) Error(Error_Fatal, "Missing Thunk Number"); NeedToken("="); SkipWhiteSpace(); GetName(); // Get the name of the thunk alias GetEnumValue(Name); // Evaluate the symbol ThunkSym = GetLastSymbolRef(); //N_FUN 141 4935 '_Z7XPClosev:F(0,6)' StabsEmit("N_THUNK %d %d '%s'\n", v, ThunkSym, Name); RegisterThunk(v, ThunkSym); return 1; } // Catch normal sets GetName(); // Get the new type Name NeedToken("="); RedefENum(Name, GetExpression()); return 1; } //--------------------------------------------------------- case dir_debug: { DEBUG = (short)GetExpression(); return 1; } //--------------------------------------------------------- case dir_info: { INFO = (short)GetExpression(); return 1; } //--------------------------------------------------------- case dir_list: { LIST = (short)GetExpression(); return 1; } //--------------------------------------------------------- case dir_show: { int exp = GetExpression(); if (Pass == 1) printf("%d",exp); if (!Token(";")) if (Pass == 1) printf("\n"); return 1; } //--------------------------------------------------------- case dir_print: //if (QToken(".print") || QToken(".?")) { int exp; char v; if (Token("\"")) { while(1) { v = *FilePtr; if (v == 0 || v == '"') break; printf("%c",v); FilePtr++; } NeedToken("\""); if (!Token(";")) printf("\n"); return 1; } exp = GetExpression(); printf("%d",exp); if (!Token(";")) printf("\n"); return 1; } //--------------------------------------------------------- case dir_ifdef: { GetName(); // Get the new type Name SkipWhiteSpace(); if (!SymbolExists(Name, section_Script, -1)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //--------------------------------------------------------- case dir_ifdefglobal: { GetName(); // Get the new type Name SkipWhiteSpace(); if (!SymbolExists(Name, section_Enum, 0)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //--------------------------------------------------------- case dir_ifndefglobal: { GetName(); // Get the new type Name SkipWhiteSpace(); if (SymbolExists(Name, section_Enum, 0)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //--------------------------------------------------------- case dir_ifndef: { GetName(); // Get the new type Name SkipWhiteSpace(); if (SymbolExists(Name, section_Script, -1)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //--------------------------------------------------------- case dir_if: { if (!GetExpression()) { SkipWhiteSpace(); if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //--------------------------------------------------------- case dir_do: { // If we have a '{' just ignore it an keep going if (Token("{")) return 1; // Must be an expression then // if false then skip to while if (!GetExpression()) { SearchScopeForward(); NeedToken(".enddo"); } return 1; } //--------------------------------------------------------- case dir_enddo: { FilePtr = SearchScope(FilePtr); return 1; } //--------------------------------------------------------- case dir_while: { if (GetExpression()) { FilePtr = SearchScope(FilePtr); } return 1; } //--------------------------------------------------------- case dir_enum: { AsmEnums(); return 1; } //--------------------------------------------------------- case dir_breakpoint: { SkipWhiteSpace(); return 1; } //--------------------------------------------------------- case dir_globals_in_code: { GlobalsInCode = 1; SkipWhiteSpace(); return 1; } //--------------------------------------------------------- case dir_globl: // if (QToken(".globl") || QToken(".global") || QToken(".weak")) { unsigned int n; GetAsmName(); if (GlobalsInCode && (Section == SECT_code)) { //! *CodePtr++ = '*'; ArraySet(&CodeMemArray, CodeIP, '*'); CodeIP++; for (n=0;n<strlen(Name);n++) { //! *CodePtr++ = Name[n]; ArraySet(&CodeMemArray, CodeIP, Name[n]); CodeIP++; } //! *CodePtr++ = '*'; ArraySet(&CodeMemArray, CodeIP, '*'); CodeIP++; } if (LIST) printf("Found global '%s'\n",Name); DefineLabelGlobal(); //#ifdef INCLUDE_JAVAGEN // if (JavaPass) // JavaGen_Global(Name); //#endif SkipWhiteSpace(); return 1; } //--------------------------------------------------------- case dir_extern: // if (QToken(".extern") || QToken(".extrn")) { GetAsmName(); if (LIST) printf("Found external '%s'\n",Name); // SHOULD DO NOTHING //ExternDecl(Name); SkipWhiteSpace(); return 1; } //--------------------------------------------------------- case dir_byte: { SetAsmDataChar(); do { imm = GetExpression(); // Get the number WriteDataTypeArray(dir_byte, 1); WriteByte(imm); } while (QToken(",")); return 1; } //--------------------------------------------------------- case dir_half: { SetAsmDataChar(); do { imm = GetExpression(); // Get the number WriteDataTypeArray(dir_half, 2); WriteWord(imm); } while (QToken(",")); return 1; } //--------------------------------------------------------- case dir_word: { SYMBOL *ref; if (Section != SECT_data) Error(Error_Skip,"data word in not in data section"); SetAsmDataChar(); do { imm = GetExpression(); // Get the number WriteDataTypeArray(dir_word, 4); ref = GetLastSymbolRef(); WriteLongRef(imm, ref); } while (QToken(",")); return 1; } //--------------------------------------------------------- case dir_space: { SetAsmDataChar(); imm = GetExpression(); // Get the number if (LIST) printf("space %d\n",imm); if (!imm) return 1; WriteDataTypeArray(dir_space, imm); do { WriteByteSpace(0); } while(--imm); return 1; } //--------------------------------------------------------- case dir_string: { SetAsmDataChar(); WriteDataTypeArray(dir_string, 1); GetStrings(); return 1; } //--------------------------------------------------------- case dir_comm: { int LastSect = Section; SetAsmDataChar(); Section = SECT_bss; GetAsmName(); //!! make this global too DefineLabelGlobal(); DefineLabel(label_Local); NeedToken(","); imm = GetExpression(); // Get the number if (LIST) printf("comm %d to .bss\n",imm); if (imm == 0) return 1; WriteDataTypeArray(dir_comm, imm); BssIP += imm; Section = LastSect; return 1; } //--------------------------------------------------------- case dir_lcomm: { int LastSect = Section; SetAsmDataChar(); Section = SECT_bss; GetAsmName(); DefineLabel(label_Local); NeedToken(","); imm = GetExpression(); // Get the number if (LIST) printf("lcomm %d to .bss\n",imm); if (imm == 0) return 1; WriteDataTypeArray(dir_lcomm, imm); BssIP += imm; Section = LastSect; return 1; } //--------------------------------------------------------- case dir_align: { imm = GetExpression(); // Get the number if (Section == SECT_code) return 1; AddAlignRef(imm); return 1; } //--------------------------------------------------------- case dir_bss: { Section = SECT_bss; if (LIST) printf("** Section .bss IP = %x\n",BssIP); return 1; } //--------------------------------------------------------- case dir_data: { Section = SECT_data; if (LIST) printf("** Section .data IP = %x\n",DataIP); return 1; } //--------------------------------------------------------- case dir_code: // if (QToken(".code") || QToken(".text")) { Section = SECT_code; if (LIST) printf("** Section .code IP = %x\n",CodeIP); return 1; } //--------------------------------------------------------- case dir_ent: { SkipLine(); return 1; } //--------------------------------------------------------- case dir_end: return 1; //--------------------------------------------------------- case dir_stabs: { Parse_stabs(); //SkipLine(); return 1; } //--------------------------------------------------------- case dir_stabn: { Parse_stabn(); //SkipLine(); return 1; } //--------------------------------------------------------- case dir_stabd: { SkipLine(); return 1; } //--------------------------------------------------------- } // End of switch return 0; }
struct Acl * ParseAcl (char *astr, int astr_size) { int nplus, nminus, i, trights, ret; size_t len; char tname[ACL_MAXNAME]; struct AclEntry *first, *next, *last, *tl; struct Acl *ta; ta = EmptyAcl(NULL); if( FAILED(StringCbLength(astr, astr_size, &len))) { fprintf (stderr, "StringCbLength failure on astr"); exit(1); } if (astr == NULL || len == 0) return ta; #if _MSC_VER < 1400 ret = sscanf(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell); #else ret = sscanf_s(astr, "%d dfs:%d %s", &ta->nplus, &ta->dfs, ta->cell, sizeof(ta->cell)); #endif if (ret <= 0) { free(ta); return NULL; } astr = SkipLine(astr); #if _MSC_VER < 1400 ret = sscanf(astr, "%d", &ta->nminus); #else ret = sscanf_s(astr, "%d", &ta->nminus); #endif if (ret <= 0) { free(ta); return NULL; } astr = SkipLine(astr); nplus = ta->nplus; nminus = ta->nminus; last = 0; first = 0; for(i=0;i<nplus;i++) { #if _MSC_VER < 1400 ret = sscanf(astr, "%100s %d", tname, &trights); #else ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights); #endif if (ret <= 0) goto nplus_err; astr = SkipLine(astr); tl = (struct AclEntry *) malloc(sizeof (struct AclEntry)); if (tl == NULL) goto nplus_err; if (!first) first = tl; if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) { fprintf (stderr, "name - not enough space"); exit(1); } tl->rights = trights; tl->next = 0; if (last) last->next = tl; last = tl; } ta->pluslist = first; last = 0; first = 0; for(i=0;i<nminus;i++) { #if _MSC_VER < 1400 ret = sscanf(astr, "%100s %d", tname, &trights); #else ret = sscanf_s(astr, "%100s %d", tname, sizeof(tname), &trights); #endif if (ret <= 0) goto nminus_err; astr = SkipLine(astr); tl = (struct AclEntry *) malloc(sizeof (struct AclEntry)); if (tl == NULL) goto nminus_err; if (!first) first = tl; if( FAILED(StringCbCopy(tl->name, sizeof(tl->name), tname))) { fprintf (stderr, "name - not enough space"); exit(1); } tl->rights = trights; tl->next = 0; if (last) last->next = tl; last = tl; } ta->minuslist = first; return ta; nminus_err: for (;first; first = next) { next = first->next; free(first); } first = ta->pluslist; nplus_err: for (;first; first = next) { next = first->next; free(first); } free(ta); return NULL; }
short ResourceCommands() { char *filemem; int filelen; int n,v; SkipWhiteSpace(); //--------------------------------------------------------- if (QToken(".library")) { SkipLine(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".lfile")) { SkipWhiteSpace(); GetLFileName(); GetRelPath(Name); return 1; } if (QToken(".localscope")) { SkipWhiteSpace(); NeedToken("+"); // LocalScope++; return 1; } if (QToken(".res")) { // If there is previous data to be written out // do it here !! if (ResType != 0) { FinalizeResource(); } SkipWhiteSpace(); ResName[0] = 0; Name[0] = 0; if (isalpha(*FilePtr)) { GetName(); // Get the new type Name strcpy(ResName, Name); } // Clear index table IndexCount = 0; IndexWidth = 0; MakeNewResource(Name); // Make this symbolic return 1; } //------------------------------------ // //------------------------------------ if (QToken(".index")) { int IndexOffset = GetDataIndex(); SkipWhiteSpace(); Name[0] = 0; if (isalpha(*FilePtr)) GetName(); // Get the index ref name // add index to table IndexTable[IndexCount] = IndexOffset; // MakeIndexedResource(IndexName, IndexCount); infoprintf("%d: index = %d ('%s')\n",IndexCount, IndexOffset, Name); if (Pass == 2) if (Name[0]) fprintf(HeaderFile,"#define idx_%s %d\n", Name, IndexCount); IndexCount++; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".wideindex")) { IndexWidth = 1; SkipWhiteSpace(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".extension")) { SkipWhiteSpace(); v = GetExpression(); // x ResType = v; infoprintf("%d: Prototype = %d\n",CurrentResource, ResType); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".dispose")) { SkipWhiteSpace(); ResDispose = 1; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".placeholder")) { ResType = ResType_PlaceHolder; infoprintf("%d: Placeholder\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".skip")) { ResType = ResType_Skip; infoprintf("%d: Skip\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".bin")) { ResType = ResType_Binary; infoprintf("%d: Binary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".ubin")) { ResType = ResType_UBinary; infoprintf("%d: UBinary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".media")) { int slen; SkipWhiteSpace(); ResType = ResType_Binary; //ResType_Media; GetStringName(128); slen = strlen(Name) + 1; for (n=0;n<slen;n++) WriteByte(Name[n]); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); GetStringName(128); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading data file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) { WriteByte(filemem[n]); } Free_File(filemem); infoprintf("%d: Media Binary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".umedia")) { int slen; SkipWhiteSpace(); ResType = ResType_UBinary; //ResType_UMedia; GetStringName(128); slen = strlen(Name) + 1; for (n=0;n<slen;n++) WriteByte(Name[n]); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); GetStringName(128); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading data file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) { WriteByte(filemem[n]); } Free_File(filemem); infoprintf("%d: Media Binary\n",CurrentResource); return 1; } //------------------------------------ // //------------------------------------ /* if (QToken(".file")) { SkipWhiteSpace(); ResType = ResType_File; GetStringName(128); filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error("Error reading data file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) { WriteByte(filemem[n]); } Free_File(filemem); printf("%d: File '%s' size %d\n", CurrentResource, Name, filelen); return 1; } */ //------------------------------------ // //------------------------------------ if (QToken(".label")) // filename { int slen; SkipWhiteSpace(); ResType = ResType_Label; GetStringName(128); slen = strlen(Name) + 1; for (n=0;n<slen;n++) WriteByte(Name[n]); return 1; } //------------------------------------ // //------------------------------------ // ResType_TileSet = 7 // ushort xsize, ysize // bytes png_image if (QToken(".tileset")) // filename { int xsize,ysize; SkipWhiteSpace(); ResType = ResType_TileSet; GetStringName(128); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); xsize = GetExpression(); // xsize SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); ysize = GetExpression(); // ysize WriteWord(xsize); WriteWord(ysize); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading tileset file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("%d: Tileset '%s' cxy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen); return 1; } //------------------------------------ // //------------------------------------ // ResType_TileMap = 8 // ushort mapWidth, mapHeight // ushort map[mapWidth*mapHeight] if (QToken(".tilemap")) // filename { int xsize,ysize; SkipWhiteSpace(); ResType = ResType_TileMap; GetStringName(128); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); xsize = GetExpression(); // xsize SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); ysize = GetExpression(); // ysize if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading tilemap file '%s'", Name); return 1; } filelen = FileAlloc_Len(); if (filelen != (xsize * ysize * 2)) { Error(Error_Fatal, "%d: Tilemap '%s' xy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen); return 1; } WriteWord(xsize); WriteWord(ysize); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("%d: Tilemap '%s' cxy %d,%d size %d\n", CurrentResource, Name, xsize, ysize, filelen); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".image")) // filename { SkipWhiteSpace(); ResType = ResType_Image; GetStringName(128); /* spr_cx = spr_cy = 0; SkipWhiteSpace(); if (QToken(",")) { spr_cx = GetExpression(); // cx SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_cy = GetExpression(); // cy } WriteWord(spr_cx); WriteWord(spr_cy); */ if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading image file '%s'", Name); return 1; } filelen = FileAlloc_Len(); // write the length //WriteEncodedInt(filelen); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("%d: Image '%s' cxy %d,%d size %d\n", CurrentResource, Name, spr_cx, spr_cy, filelen); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".sprite")) // index, x,y,w,h,cx,cy { ResType = ResType_Sprite; SkipWhiteSpace(); spr_ind = v = GetExpression(); // ind WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_x = v = GetExpression(); // x WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_y = v = GetExpression(); // y WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_w = v = GetExpression(); // w WriteWord(v); SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_h = v = GetExpression(); // h WriteWord(v); spr_cx = spr_cy = 0; SkipWhiteSpace(); if (QToken(",")) { spr_cx = (short)GetExpression(); // cx SkipWhiteSpace(); NeedToken(","); SkipWhiteSpace(); spr_cy = (short)GetExpression(); // cy } WriteWord(spr_cx); WriteWord(spr_cy); infoprintf("%d: Sprite ind %d, xy %d,%d, wh %d,%d cxy %d,%d\n", CurrentResource, spr_ind, spr_x, spr_y, spr_w, spr_h, spr_cx, spr_cy); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".end")) { SkipLine(); // EndComp = 1; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".eof")) { SkipLine(); EndComp = 1; return 1; } //------------------------------------ // //------------------------------------ if (QToken(".parseheader")) { GetStringName(128); ReadAndParseHeaders(Name); return 1; } //------------------------------------ // Other directives //------------------------------------ if (QToken(".set")) { if (QToken("$")) { char VarName[256]; // Accept a string GetName(); // Get the new type Name strcpy(VarName, Name); NeedToken("="); GetStringName(128); printf("string set %s = '%s'\n", VarName, Name); RedefENumString(VarName, Name); return 1; } GetName(); // Get the new type Name NeedToken("="); RedefENum(Name, GetExpression()); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".debug")) { DEBUG = (short)GetExpression(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".info")) { INFO = (short)GetExpression(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".list")) { LIST = (short)GetExpression(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".show")) { int exp = GetExpression(); printf("%d",exp); if (!Token(";")) printf("\n"); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".print") || QToken(".?")) { int exp; char c; if (Token("\"")) { while(1) { c = *FilePtr; if (c == 0 || c == '"') break; printf("%c",c); FilePtr++; } NeedToken("\""); if (!Token(";")) printf("\n"); return 1; } exp = GetExpression(); printf("%d",exp); if (!Token(";")) printf("\n"); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".if")) { if (!GetExpression()) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".ifdef")) { GetName(); // Get the new type Name SkipWhiteSpace(); if (!SymbolExists(Name, section_Script, -1)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".ifndef")) { GetName(); // Get the new type Name SkipWhiteSpace(); if (SymbolExists(Name, section_Script, -1)) { if (NextToken("{")) { SkipPair('{','}'); } } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".while")) { if (GetExpression()) { FilePtr = SearchScope(FilePtr); } return 1; } //------------------------------------ // //------------------------------------ if (QToken(".enum")) { AsmEnums(); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".include")) // filename { SkipWhiteSpace(); GetStringName(128); if(Do_Export_Dependencies && Pass == 2) { ExportFileDependency(Name); } filemem = Open_FileAlloc(AddRelPrefix(Name)); if (!filemem) { Error(Error_Fatal, "Error reading include file '%s'", Name); return 1; } filelen = FileAlloc_Len(); for (n=0;n<filelen;n++) WriteByte(filemem[n]); Free_File(filemem); infoprintf("bin include '%s' size %d\n", Name, filelen); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".varint")) { do { imm = GetExpression(); // Get the number WriteEncodedInt(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".varsint")) { do { imm = GetExpression(); // Get the number WriteEncodedSignedInt(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".byte")) { do { imm = GetExpression(); // Get the number WriteByte(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".half")) { do { imm = GetExpression(); // Get the number WriteWord(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".word")) { do { imm = GetExpression(); // Get the number WriteLong(imm); } while (QToken(",")); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".fill")) { imm = GetExpression(); // Get the number if (!imm) return 1; NeedToken(","); v = GetExpression(); do { WriteByte(v); } while(--imm); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".pstring")) { int dataStart; int len; // Write length byte WriteByte(0); // Get current data location dataStart = DataIP; // read string to mem GetStrings(); // find the string length len = DataIP - dataStart; if (len > 255) { Error(Error_Skip, "pstring is longer that 255 chars\n"); return 1; } // Patch the string length ArraySet(&DataMemArray, dataStart-1, len); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".cstring")) { GetStrings(); WriteByte(0); return 1; } //------------------------------------ // //------------------------------------ if (QToken(".string")) { GetStrings(); return 1; } //------------------------------------ // //------------------------------------ // Error GetAsmName(); Error(Error_Fatal, "Illegal resource directive '%s'",Name); return 0; }
int main (int argc, char *argv[]) { #include "tsil_names.h" TSIL_REAL x, y, z, u, v, s, qq; TSIL_COMPLEX val; TSIL_DATA result; int i, j, k, p, foo, tally[3], nwarn, nfail, npass; char c; TSIL_COMPLEX Mvalue, Uvalue[4], Vvalue[4], Svalue[2], Tvalue[6], Bvalue[2]; TSIL_COMPLEX Tbarvalue[6], UUvalue[4][3], VVvalue[4][3], SSvalue[2][3]; TSIL_COMPLEX TTvalue[6][3]; TSIL_REAL xx, yy, zz, uu, vv; /* gcc complains unless the following are initialized; this may be a gcc bug? Fortunately, it doesn't hurt to initialize them. */ int permU = 0; int permS = 0; int permT11 = 0; int permT12 = 0; int permT21 = 0; int permT22 = 0; int permT31 = 0; int permT32 = 0; if (argc == 1) TSIL_Error ("main", "Must supply test data filename(s)...", 2); nwarn = nfail = npass = 0; printf("===== TSIL TEST SUITE =====\n"); #if defined (TSIL_TEST_STU) printf("** Testing STU Evaluation only!\n"); #elif defined (TSIL_TEST_ST) printf("** Testing ST Evaluation only!\n"); #endif /* We don't need no stinkin' TSIL_Warnings here. */ fclose (stderr); /* Loop over input files */ for (i = 1; i < argc; i++) { if ((fp = fopen(argv[i], "r")) == NULL) { TSIL_Warn ("Test program", "Invalid file name"); continue; } printf ("\nTest %d: ", i); printf ("%s\n", argv[i]); fflush (stdout); /* Skip any lines starting with '(' (comments): */ while ((c = fgetc (fp)) == '(') SkipLine (fp); /* Put back the last character after we find a non-comment line */ ungetc ((int) c, fp); /* Read in parameters */ xx = x = GetReal (); yy = y = GetReal (); zz = z = GetReal (); uu = u = GetReal (); vv = v = GetReal (); s = GetReal (); qq = GetReal (); /* Calculate everything... */ #if defined(TSIL_TEST_STU) TSIL_SetParametersSTU (&result, x, z, u, v, qq); #elif defined(TSIL_TEST_ST) TSIL_SetParametersST (&result, x, u, v, qq); #else TSIL_SetParameters (&result, x, y, z, u, v, qq); #endif TSIL_Evaluate (&result, s); for (j = 0; j < 3; j++) tally[j] = 0; /* ...and test results: */ #if defined(TSIL_TEST_STU) val = GetComplex (); val = GetComplex (); val = GetComplex (); /* U */ for (j = 2; j < 4; j+=2) { val = GetComplex (); Uvalue[j] = result.U[j].value; TSIL_Compare (uname[j], val, Uvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Uvalue[2], TSIL_GetFunction(&result,"Uxzuv")); val = GetComplex (); val = GetComplex (); /* T */ for (j = 1; j < 6; j+=2) { val = GetComplex (); Tvalue[j] = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } CheckConsistent (Tvalue[1], TSIL_GetFunction(&result,"Tuxv")); CheckConsistent (Tvalue[3], TSIL_GetFunction(&result,"Txuv")); CheckConsistent (Tvalue[5], TSIL_GetFunction(&result,"Tvxu")); /* S */ for (j = 1; j < 2; j+=2) { val = GetComplex (); Svalue[j] = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Svalue[1], TSIL_GetFunction(&result,"Suxv")); /* B */ for (j = 0; j < 2; j+=2) { val = GetComplex (); Bvalue[j] = result.B[j].value; TSIL_Compare (bname[j], val, Bvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Bvalue[0], TSIL_GetFunction(&result,"Bxz")); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* V */ for (j = 2; j < 4; j+=2) { val = GetComplex (); Vvalue[j] = result.V[j].value; TSIL_Compare (vname[j], val, Vvalue[j], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } CheckConsistent (Vvalue[2], TSIL_GetFunction(&result,"Vxzuv")); val = GetComplex (); /* Tbar */ val = GetComplex (); for (j = 1; j < 6; j+=2) { val = GetComplex (); Tbarvalue[j] = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* UU */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); UUvalue[j][k] = result.U[j].bold[k]; TSIL_Compare (uuname[j][k], val, UUvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* VV */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); VVvalue[j][k] = result.V[j].bold[k]; TSIL_Compare (vvname[j][k], val, VVvalue[j][k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* TT */ for (j = 1; j < 6; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); TTvalue[j][k] = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } val = GetComplex (); val = GetComplex (); val = GetComplex (); } /* SS */ for (j = 1; j < 2; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); SSvalue[j][k] = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } #elif defined(TSIL_TEST_ST) val = GetComplex (); val = GetComplex (); val = GetComplex (); /* U */ for (j = 2; j < 4; j+=2) { val = GetComplex (); } val = GetComplex (); val = GetComplex (); /* T */ for (j = 1; j < 6; j+=2) { val = GetComplex (); Tvalue[j] = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } CheckConsistent (Tvalue[1], TSIL_GetFunction(&result,"Tuxv")); CheckConsistent (Tvalue[3], TSIL_GetFunction(&result,"Txuv")); CheckConsistent (Tvalue[5], TSIL_GetFunction(&result,"Tvxu")); /* S */ for (j = 1; j < 2; j+=2) { val = GetComplex (); Svalue[j] = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Svalue[1], TSIL_GetFunction(&result,"Suxv")); /* B */ for (j = 0; j < 2; j+=2) { val = GetComplex (); } val = GetComplex (); val = GetComplex (); val = GetComplex (); /* V */ for (j = 2; j < 4; j+=2) { val = GetComplex (); } val = GetComplex (); /* Tbar */ val = GetComplex (); for (j = 1; j < 6; j+=2) { val = GetComplex (); Tbarvalue[j] = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; val = GetComplex (); } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* UU */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* VV */ for (j = 2; j < 4; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); } } val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); val = GetComplex (); /* TT */ for (j = 1; j < 6; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); TTvalue[j][k] = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } val = GetComplex (); val = GetComplex (); val = GetComplex (); } /* SS */ for (j = 1; j < 2; j+=2) { for (k = 0; k < 3; k++) { val = GetComplex (); SSvalue[j][k] = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } #else /* M */ val = GetComplex (); Mvalue = result.M.value; CheckConsistent (Mvalue, TSIL_GetFunction(&result,"M")); TSIL_Compare ("M", val, Mvalue, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; /* U */ for (j = 0; j < 4; j++) { val = GetComplex (); Uvalue[j] = result.U[j].value; TSIL_Compare (uname[j], val, Uvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Uvalue[0], TSIL_GetFunction(&result,"Uzxyv")); CheckConsistent (Uvalue[1], TSIL_GetFunction(&result,"Uuyxv")); CheckConsistent (Uvalue[2], TSIL_GetFunction(&result,"Uxzuv")); CheckConsistent (Uvalue[3], TSIL_GetFunction(&result,"Uyuzv")); /* T */ for (j = 0; j < 6; j++) { val = GetComplex (); Tvalue[j] = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Tvalue[0], TSIL_GetFunction(&result,"Tvyz")); CheckConsistent (Tvalue[1], TSIL_GetFunction(&result,"Tuxv")); CheckConsistent (Tvalue[2], TSIL_GetFunction(&result,"Tyzv")); CheckConsistent (Tvalue[3], TSIL_GetFunction(&result,"Txuv")); CheckConsistent (Tvalue[4], TSIL_GetFunction(&result,"Tzyv")); CheckConsistent (Tvalue[5], TSIL_GetFunction(&result,"Tvxu")); /* S */ for (j = 0; j < 2; j++) { val = GetComplex (); Svalue[j] = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Svalue[0], TSIL_GetFunction(&result,"Svyz")); CheckConsistent (Svalue[1], TSIL_GetFunction(&result,"Suxv")); /* B */ for (j = 0; j < 2; j++) { val = GetComplex (); Bvalue[j] = result.B[j].value; TSIL_Compare (bname[j], val, Bvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } CheckConsistent (Bvalue[0], TSIL_GetFunction(&result,"Bxz")); CheckConsistent (Bvalue[1], TSIL_GetFunction(&result,"Byu")); /* V */ for (j = 0; j < 4; j++) { val = GetComplex (); Vvalue[j] = result.V[j].value; TSIL_Compare (vname[j], val, Vvalue[j], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } CheckConsistent (Vvalue[0], TSIL_GetFunction(&result,"Vzxyv")); CheckConsistent (Vvalue[1], TSIL_GetFunction(&result,"Vuyxv")); CheckConsistent (Vvalue[2], TSIL_GetFunction(&result,"Vxzuv")); CheckConsistent (Vvalue[3], TSIL_GetFunction(&result,"Vyuzv")); /* Tbar */ for (j = 0; j < 6; j++) { val = GetComplex (); Tbarvalue[j] = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* UU */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); UUvalue[j][k] = result.U[j].bold[k]; TSIL_Compare (uuname[j][k], val, UUvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* VV */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); VVvalue[j][k] = result.V[j].bold[k]; TSIL_Compare (vvname[j][k], val, VVvalue[j][k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } /* TT */ for (j = 0; j < 6; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); TTvalue[j][k] = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* SS */ for (j = 0; j < 2; j++) { for (k = 0; k < 3; k++) { val = GetComplex (); SSvalue[j][k] = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } #endif if (tally[FAIL] > 0) { nfail++; printf ("FAILED FOR INPUT PARAMETERS:\n"); printf ("x = %.6lf;\n", (double) x); printf ("y = %.6lf;\n", (double) y); printf ("z = %.6lf;\n", (double) z); printf ("u = %.6lf;\n", (double) u); printf ("v = %.6lf;\n", (double) v); printf ("s = %.6lf;\n", (double) s); printf ("qq = %.6lf;\n", (double) qq); } else if (tally[WARN] > 0) { printf ("PASS WITH WARNING\n"); nwarn++; } else { printf ("PASS\n"); npass++; } if (1 == Doperms) { for (p = 0; p < 4; p++) { for (j = 0; j < 3; j++) tally[j] = 0; x = xx; y = yy; z = zz; u = uu; v = vv; if (1 == p) { swapR (&x, &y); swapR (&z, &u); } if (2 == p) { swapR (&x, &z); swapR (&y, &u); } if (3 == p) { swapR (&x, &u); swapR (&y, &z); } /* Calculate everything... */ TSIL_SetParameters (&result, x, y, z, u, v, qq); TSIL_Evaluate (&result, s); Permuteresults (&result, p); printf ("\nTest %d, permutation %d (", i, p); printf ("%s", argv[i]); printf ("): "); /* ...and check that permuted results agree as they should: */ /* M */ val = result.M.value; TSIL_Compare ("M", val, Mvalue, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; /* U */ for (j = 0; j < 4; j++) { val = result.U[j].value; TSIL_Compare (uname[j], val, Uvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* T */ for (j = 0; j < 6; j++) { val = result.T[j].value; TSIL_Compare (tname[j], val, Tvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* S */ for (j = 0; j < 2; j++) { val = result.S[j].value; TSIL_Compare (sname[j], val, Svalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* B */ for (j = 0; j < 2; j++) { val = result.B[j].value; TSIL_Compare (bname[j], val, Bvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* V */ for (j = 0; j < 4; j++) { val = result.V[j].value; TSIL_Compare (vname[j], val, Vvalue[j], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } /* Tbar */ for (j = 0; j < 6; j++) { val = result.Tbar[j].value; TSIL_Compare (tbarname[j], val, Tbarvalue[j], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } /* UU */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = result.U[j].bold[k]; TSIL_Compare (uuname[j][k], val, UUvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* VV */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = result.V[j].bold[k]; TSIL_Compare (vvname[j][k], val, VVvalue[j][k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } /* TT */ for (j = 0; j < 6; j++) { for (k = 0; k < 3; k++) { val = result.T[j].bold[k]; TSIL_Compare (ttname[j][k], val, TTvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* SS */ for (j = 0; j < 2; j++) { for (k = 0; k < 3; k++) { val = result.S[j].bold[k]; TSIL_Compare (ssname[j][k], val, SSvalue[j][k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } if (tally[FAIL] > 0) { nfail++; printf ("\nFAILED FOR INPUT PARAMETERS:\n"); printf ("x = %.3lf;\n", (double) x); printf ("y = %.3lf;\n", (double) y); printf ("z = %.3lf;\n", (double) z); printf ("u = %.3lf;\n", (double) u); printf ("v = %.3lf;\n", (double) v); printf ("s = %.3lf;\n", (double) s); printf ("qq = %.3lf;\n", (double) qq); } else if (tally[WARN] > 0) { nwarn++; printf ("\nPASS WITH WARNING\n"); } else { printf ("\nPASS\n"); npass++; } } } if (1 == Doextraperms) { for (p = 4; p < 8; p++) { x = xx; y = yy; z = zz; u = uu; v = vv; if (p == 4) { swapR (&x, &v); permU = 1; permT11 = 1; permT12 = 1; permT21 = 3; permT22 = 5; permT31 = 5; permT32 = 3; permS = 1; } if (p == 5) { swapR (&y, &v); permU = 0; permT11 = 0; permT12 = 2; permT21 = 2; permT22 = 0; permT31 = 4; permT32 = 4; permS = 0; } if (p == 6) { swapR (&z, &v); permU = 3; permT11 = 0; permT12 = 4; permT21 = 4; permT22 = 0; permT31 = 2; permT32 = 2; permS = 0; } if (p == 7) { swapR (&u, &v); permU = 2; permT11 = 1; permT12 = 5; permT21 = 5; permT22 = 1; permT31 = 3; permT32 = 3; permS = 1; } for (j = 0; j < 3; j++) tally[j] = 0; /* Calculate everything... */ TSIL_SetParameters (&result, x, y, z, u, v, qq); TSIL_Evaluate (&result, s); printf ("\nTest %d, permutation %d (", i, p); printf ("%s", argv[i]); printf ("): "); /* ...and check results: */ /* U */ for (j = 0; j < 4; j++) { val = Uvalue[j]; if (j == permU) { TSIL_Compare (uname[j], val, result.U[j].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* T */ for (j = 0; j < 6; j++) { val = Tvalue[j]; if (j == permT11) { TSIL_Compare (tname[j], val, result.T[permT12].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT21) { TSIL_Compare (tname[j], val, result.T[permT22].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT31) { TSIL_Compare (tname[j], val, result.T[permT32].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* S */ for (j = 0; j < 2; j++) { val = Svalue[j]; if (j == permS) { TSIL_Compare (sname[j], val, result.S[j].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* V */ for (j = 0; j < 4; j++) { val = Vvalue[j]; if (j == permU) { TSIL_Compare (vname[j], val, result.V[j].value, TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } /* Tbar */ for (j = 0; j < 6; j++) { val = Tbarvalue[j]; if (j == permT11) { TSIL_Compare (tbarname[j], val, result.Tbar[permT12].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT21) { TSIL_Compare (tbarname[j], val, result.Tbar[permT22].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT31) { TSIL_Compare (tbarname[j], val, result.Tbar[permT32].value, TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } /* UU */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = UUvalue[j][k]; if (j == permU) { TSIL_Compare (uuname[j][k], val, result.U[j].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } } /* VV */ for (j = 0; j < 4; j++) { for (k = 0; k < 3; k++) { val = VVvalue[j][k]; if (j == permU) { TSIL_Compare (vvname[j][k], val, result.V[j].bold[k], TSIL_PASS_V, TSIL_WARN_V, &foo); tally[foo]++; } } } /* TT */ for (j = 0; j < 6; j++) { for (k = 0; k < 3; k++) { val = TTvalue[j][k]; if (j == permT11) { TSIL_Compare (ttname[j][k], val, result.T[permT12].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT21) { TSIL_Compare (ttname[j][k], val, result.T[permT22].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } if (j == permT31) { TSIL_Compare (ttname[j][k], val, result.T[permT32].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } } /* SS */ for (j = 0; j < 2; j++) { for (k = 0; k < 3; k++) { val = SSvalue[j][k]; if (j == permS) { TSIL_Compare (ssname[j][k], val, result.S[j].bold[k], TSIL_PASS, TSIL_WARN, &foo); tally[foo]++; } } } if (tally[FAIL] > 0) { nfail++; printf ("\nFAILED FOR INPUT PARAMETERS:\n"); printf ("x = %.16lf;\n", (double) x); printf ("y = %.16lf;\n", (double) y); printf ("z = %.16lf;\n", (double) z); printf ("u = %.16lf;\n", (double) u); printf ("v = %.16lf;\n", (double) v); printf ("s = %.16lf;\n", (double) s); printf ("qq = %.16lf;\n", (double) qq); } else if (tally[WARN] > 0) { nwarn++; printf ("\nPASS\n"); } else { printf ("\nPASS\n"); npass++; } } } fclose (fp); printf ("\n===== Done with input file "); printf ("%s", argv[i]); printf (" =====\n"); } printf ("\n== FINAL RESULTS ==\n"); printf ("Total input files: %d\n", (argc - 1)); printf ("Total tests performed: %d\n", (1 + Doperms * 3 + Doextraperms * 4) * (argc - 1)); printf ("Pass: %d\n", npass); printf ("Warn: %d\n", nwarn); printf ("Fail: %d\n", nfail); return 0; }
//------------------------------------------------------------------------- // //------------------------------------------------------------------------- bool SettingsFile::ParseSettingsString(const char *settings) { if(!settings) return false; const char *first; std::string section; // Iterate through all the lines for(first = GetNextLine(settings); first && *first; first = GetNextLine(first)) { if((first[0] == '[') && FindCharacter(first + 1, ']')) { // Found a section head, so create an entry for it const char *last = FindCharacter(first + 1, ']'); if(last - first > 2) { const char *start = first + 1; const char *end = last - 1; TrimString(start, end); section.assign(start, end - start + 1); } // Skip what was scanned first = last + 1; } else if((first[0] == ';') || (first[0] == '#')) { first = SkipLine(first); } else { if(section.length() > 0) { const char *middle = FindCharacter(first + 1, '='); if(middle) { const char *start = first; const char *end = middle - 1; TrimString(start, end); if(end >= start) { std::string key; key.assign(start, end - start + 1); start = middle + 1; end = SkipLine(middle + 1); TrimString(start, end); if(end >= start) { std::string value; value.assign(start, end - start + 1); m_settings[section][key] = value; } } } } // Skip the line first = SkipLine(first); } } return false; }
/* GetTrSym: get next symbol from f, remember that f might be an MLF in which case EOF is a period on its own line */ static void GetTrSym(Source *src, Boolean htk) { int nxtch; Boolean trSOL; trNum = 0.0; trStr[0]='\0'; if (trSym==TRNULL) curch = GetCh(src); if (trSym==TREOL || trSym==TRNULL) trSOL=TRUE; else trSOL=FALSE; while (curch == ' ' || curch == '\t') { trSOL=FALSE; curch = GetCh(src); } if (!htk && curch == COMMCHAR) SkipLine(src); switch (curch) { case EOF: trSym = TREOF; break; case LFEED: curch = GetCh(src); trSym = TREOL; break; case CRETURN: curch = GetCh(src); if (curch == LFEED) curch = GetCh(src); trSym = TREOL; break; case ',': if (!htk) { curch = GetCh(src); trSym = TRCOMMA; break; } case '.': if (curch=='.' && trSOL==TRUE && mlfUsed>0 && htk) { nxtch = GetCh(src); if (nxtch == LFEED || nxtch == CRETURN) { trSym = TREOF; break; } UnGetCh(nxtch,src); /* Requires more than one character pushback */ } default: if (htk) { UnGetCh(curch,src); if (!ReadString(src,trStr)) { trSym=TREOF; break; } curch=GetCh(src); if (trSOL && strcmp(LEVELSEP,trStr)==0) { if (curch == LFEED || curch == CRETURN) { trSym = TRLEV; break; } } } else { nxtch=0; do { if (nxtch>=255) break; trStr[nxtch++]=curch; curch=GetCh(src); } while (!isspace(curch) && curch != ',' && curch != EOF); trStr[nxtch]='\0'; src->wasQuoted=FALSE; } if (!src->wasQuoted && IsNumeric(trStr)){ sscanf(trStr,"%lf",&trNum); trSym = TRNUM; break; } if (htk && compatMode && (strcmp(LEVELSEP,trStr)==0 || strcmp(".",trStr)==0)) { src->wasNewline=FALSE; SkipWhiteSpace(src); if (src->wasNewline) { curch = CRETURN; trSym=(strcmp(LEVELSEP,trStr)==0?TRLEV:TREOF); break; } curch = GetCh(src); } if (stripTriPhones) TriStrip(trStr); trSym = TRSTR; break; } }
// preprocessor directives BOOL FASTCALL comProc_Preprocess(U16 flags, S16 *brackCnt) { BOOL PREP_OK=FALSE; int code; S32 index; char *label,*enumClass; if(*szTemp != '#') { if(!STRCMP(szTemp,"enum")) { if(IsStringLabel(GetNextWord())) { enumClass = strdup(szTemp); GetNextWord(); } else enumClass = NULL; if(szTemp[0]!='{') { ssFree(enumClass); error(ERR_ENUMBRACK); SkipLine(FALSE); return TRUE; } GetNextWord(); index = 0; while(szTemp[0]!='}') { label = strdup(szTemp); if(GetNextWord()[0]=='=') { if(!IsStrNum(GetNextWord())) { error(ERR_INTEXP); } else { index = ConfirmWord(StrToInt(szTemp)); } if(*szTemp!='}' && *szTemp!=',') GetNextWord(); } AddEnum(enumClass,label,index++); ssFree(label); if(szTemp[0]!=',') break; GetNextWord(); } if(szTemp[0]!='}') { error(ERR_ENUMBRACK); SkipLine(FALSE); return TRUE; } ssFree(enumClass); return TRUE; } return FALSE; } switch(code = StrInPrep(GetNextWord(),szPreprocess)) { /**********************************************************************/ case PREPROCESS_SETPAD: if(InFalseIfDef()) break; if(GetNextWord()[0]=='"') { if(!DoString()) { error(ERR_INTEXP); } else { strncpy(szPadding,szString,sizeof(szPadding)-1); szPadding[sizeof(szPadding)-1] = '\0'; } } else if(IsStrNum(szTemp)) { index = StrToInt(szTemp); szPadding[0] = ConfirmChar(index); szPadding[1] = '\0'; PREP_OK = TRUE; } else error(ERR_INTEXP); break; /*--------------------------------------------------------------------*/ case PREPROCESS_ALIGN: if(InFalseIfDef()) break; if(IsStrNum(GetNextWord())) { index = StrToInt(szTemp); AlignCode(ConfirmWord(index)); PREP_OK = TRUE; } else error(ERR_INTEXP); break; /**********************************************************************/ case PREPROCESS_INCLUDE: if(InFalseIfDef()) break; if(GetNextWord()[0]=='"' && DoStringDirect()) { if(CompileScript(szString,NULL,NULL)) PREP_OK = TRUE; break; } error(ERR_STRINGEXP); break; /*--------------------------------------------------------------------*/ case PREPROCESS_INCBIN: // "filename"[,maxsize] if(InFalseIfDef()) break; if(GetNextWord()[0]=='"' && DoStringDirect()) { index = -1; if(PeekNextWord()[0]==',') { GetNextWord(); if(IsStrNum(GetNextWord())) { index = ConfirmWord(StrToInt(szTemp)); } else { error(ERR_INTEXP); PREP_OK = FALSE; } } if(IncBin(szString,index)) PREP_OK = TRUE; break; } error(ERR_STRINGEXP); break; /*--------------------------------------------------------------------*/ case PREPROCESS_USEPATH: // "pathname" if(InFalseIfDef()) break; if(GetNextWord()[0]=='"' && DoStringDirect()) { if(PRECOMPILING && !AddDirList(&includeDirList, szString)) { error(ERR_ADDINGPATH,szString); } PREP_OK = TRUE; break; } error(ERR_STRINGEXP); break; /**********************************************************************/ case PREPROCESS_DEFINE: if(InFalseIfDef()) break; USE_DEFS = FALSE; AddDefine(GetNextWord(),NULL); USE_DEFS = TRUE; PREP_OK = TRUE; break; /*--------------------------------------------------------------------*/ case PREPROCESS_UNDEF: if(InFalseIfDef()) break; USE_DEFS = FALSE; if(!DelDefine(GetNextWord())) error(ERR_UNDEFINE,szTemp); USE_DEFS = TRUE; PREP_OK = TRUE; break; /*--------------------------------------------------------------------*/ case PREPROCESS_IFDEF: if(InFalseIfDef()) break; USE_DEFS = FALSE; EnterIfDef(FindDefine(defList,GetNextWord())!=NULL); USE_DEFS = TRUE; PREP_OK = TRUE; break; /*--------------------------------------------------------------------*/ case PREPROCESS_IFNDEF: if(InFalseIfDef()) break; USE_DEFS = FALSE; EnterIfDef(FindDefine(defList,GetNextWord())==NULL); USE_DEFS = TRUE; PREP_OK = TRUE; break; /*--------------------------------------------------------------------*/ case PREPROCESS_ELSE: if(!curScript->ifdefTrack || curScript->ifdefTrack->ELSE) { error(ERR_PREPELSEUNEXP); } else { curScript->ifdefTrack->RESULT = !curScript->ifdefTrack->RESULT; curScript->ifdefTrack->ELSE = TRUE; } PREP_OK = TRUE; break; /*--------------------------------------------------------------------*/ case PREPROCESS_ENDIF: //TODO fix this ReleaseIfDef(); PREP_OK = TRUE; break; /**********************************************************************/ case PREPROCESS_TODO: case PREPROCESS_WARNING: case PREPROCESS_ERROR: case PREPROCESS_FATAL: if(InFalseIfDef()) break; if(GetNextWord()[0]!='"' || !DoString()) strcpy(szString,"<user message>"); switch(code) { case PREPROCESS_TODO: todo(szString); break; case PREPROCESS_WARNING: warning(WRN_USERPREP,szString); break; case PREPROCESS_ERROR: error(ERR_USERPREP,szString); break; case PREPROCESS_FATAL: fatal(FTL_USERPREP,szString); break; } PREP_OK = TRUE; break; /**********************************************************************/ case PREPROCESS_TELL: if(InFalseIfDef()) break; PREP_OK = TRUE; switch(code=CheckSubList(code)) { case PREPROCESS_TELL_BANK: CheckCurBank(); notice(code,"Current Bank: %s (#%d)", curBank->label, curBank->bank); break; case PREPROCESS_TELL_BANKOFFSET: CheckCurBank(); notice(code,"Current Bank: %s (#%d); Offset: $%04X (%d)", curBank->label, curBank->bank, (BANK_OFFSET(curBank)+curBank->org), (BANK_OFFSET(curBank)+curBank->org)); break; case PREPROCESS_TELL_BANKSIZE: CheckCurBank(); notice(code,"Current Bank: %s (#%d); Current Size: $%04X (%d bytes)", curBank->label, curBank->bank, (BANK_OFFSET(curBank)), (BANK_OFFSET(curBank))); break; case PREPROCESS_TELL_BANKFREE: CheckCurBank(); notice(code,"Current Bank: %s (#%d); Current Bytes Free In Bank: $%04X (%d)", curBank->label, curBank->bank, (BANK_OFFSET(curBank)), (BANK_OFFSET(curBank))); break; case PREPROCESS_TELL_BANKTYPE: CheckCurBank(); notice(code,"Current Bank: %s (#%d); Type: %s", curBank->label, curBank->bank, szBankTypes[curBank->type]); break; default: error(ERR_PREPROCESSORID,szTemp); PREP_OK = FALSE; } break; /**********************************************************************/ case PREPROCESS_RAM: if(InFalseIfDef()) break; PREP_OK = TRUE; switch(code=CheckSubList(code)) { case PREPROCESS_RAM_ORG: // blockaddress[, maxsize] if(IsStrNum(GetNextWord())) { ramBank.org = 0; ramBank.ptr = ramBank.buffer+ConfirmWord(StrToInt(szTemp)); curBank = &ramBank; PREP_OK = TRUE; } else error(ERR_INTEXP); if(PeekNextWord()[0]==',') { GetNextWord(); if(IsStrNum(GetNextWord())) { ramBank.maxsize = BANK_OFFSET(curBank)+ConfirmWord(StrToInt(szTemp)); } else { error(ERR_INTEXP); PREP_OK = FALSE; } } curBank->end = curBank->buffer+ramBank.maxsize; break; case PREPROCESS_RAM_END: curBank = NULL; break; default: error(ERR_PREPROCESSORID,szTemp); PREP_OK = FALSE; } break; /**********************************************************************/ case PREPROCESS_ROM: if(InFalseIfDef()) break; PREP_OK = TRUE; switch(code=CheckSubList(code)) { case PREPROCESS_ROM_ORG: // blockaddress[, maxsize] CheckRomBank(); if(IsStrNum(GetNextWord())) { #if 0 curBank->org = ConfirmWord(StrToInt(szTemp)); #else curBank->org = ConfirmWord(StrToInt(szTemp))-BANK_OFFSET(curBank); #endif PREP_OK = TRUE; } else error(ERR_INTEXP); if(PeekNextWord()[0]==',') { GetNextWord(); if(IsStrNum(GetNextWord())) { curBank->maxsize = ConfirmWord(StrToInt(szTemp)); } else { error(ERR_INTEXP); PREP_OK = FALSE; } } break; case PREPROCESS_ROM_END: CheckRomBank(); curBank = NULL; break; case PREPROCESS_ROM_BANKSIZE: // size if(IsStrNum(GetNextWord())) { bankSizes[BANKTYPE_ROM] = StrToInt(szTemp); if(bankSizes[BANKTYPE_ROM] > MAX_BANKSIZE) { error(ERR_BANKSIZE,bankSizes[BANKTYPE_ROM],MAX_BANKSIZE); bankSizes[BANKTYPE_ROM] = MAX_BANKSIZE; } PREP_OK = TRUE; } else error(ERR_INTEXP); if(PeekNextWord()[0]==',') { GetNextWord(); CheckRomBank(); if(IsStrNum(GetNextWord())) { curBank->maxsize = (StrToInt(szTemp)); } else { error(ERR_INTEXP); PREP_OK = FALSE; } } break; case PREPROCESS_ROM_BANK: // label if(!IsStringLabel(GetNextWord())) { error(ERR_BADLABEL,szTemp); strcpy(szTemp,""); } SetBank(BANKTYPE_ROM, szTemp); break; default: error(ERR_PREPROCESSORID,szTemp); PREP_OK = FALSE; } break; /**********************************************************************/ case PREPROCESS_CHR: if(InFalseIfDef()) break; PREP_OK = TRUE; switch(code=CheckSubList(code)) { case PREPROCESS_CHR_BANKSIZE: // size if(IsStrNum(GetNextWord())) { bankSizes[BANKTYPE_CHR] = (StrToInt(szTemp)); if(bankSizes[BANKTYPE_CHR] > MAX_BANKSIZE) { error(ERR_BANKSIZE,bankSizes[BANKTYPE_CHR],MAX_BANKSIZE); bankSizes[BANKTYPE_CHR] = MAX_BANKSIZE; } PREP_OK = TRUE; } else error(ERR_INTEXP); if(PeekNextWord()[0]==',') { GetNextWord(); if(IsStrNum(GetNextWord())) { curBank->maxsize = (StrToInt(szTemp)); } else { error(ERR_INTEXP); PREP_OK = FALSE; } } break; case PREPROCESS_CHR_BANK: // label if(!IsStringLabel(GetNextWord())) { error(ERR_BADLABEL,szTemp); strcpy(szTemp,""); } SetBank(BANKTYPE_CHR, szTemp); break; case PREPROCESS_CHR_END: CheckChrBank(); curBank = NULL; break; default: error(ERR_PREPROCESSORID,szTemp); PREP_OK = FALSE; } break; /**********************************************************************/ case PREPROCESS_INES: if(InFalseIfDef()) break; PREP_OK = TRUE; switch(code=CheckSubList(code)) { case PREPROCESS_INES_MAPPER: // (number|"name") if(GetNextWord()[0]=='"') { if(DoString()) { if((index=StrInStrint(szString, siMappers))==-1) error(ERR_UNKMAPPER,szString); else { romHeader.mapper = siMappers[index].index; PREP_OK = TRUE; } } } else if(IsStrNum(szTemp)) { romHeader.mapper = ConfirmChar(StrToInt(szTemp)); PREP_OK = TRUE; } else error(ERR_INTEXP); break; case PREPROCESS_INES_MIRRORING: // (number|"name") if(GetNextWord()[0]=='"') { if(DoString()) { if((index=StrInStrint(szString, siMirroring))==-1) error(ERR_UNKMIRRORING,szString); else { romHeader.mirroring = siMirroring[index].index; PREP_OK = TRUE; } } } else if(IsStrNum(szTemp)) { romHeader.mirroring = ConfirmChar(StrToInt(szTemp)); PREP_OK = TRUE; } else error(ERR_INTEXP); break; case PREPROCESS_INES_BATTERY: romHeader.battery = PreprocessCheckYesNo(&PREP_OK); break; case PREPROCESS_INES_TRAINER: romHeader.trainer = PreprocessCheckYesNo(&PREP_OK); break; case PREPROCESS_INES_FOURSCREEN: romHeader.fourscreen = PreprocessCheckYesNo(&PREP_OK); break; case PREPROCESS_INES_PRGREPEAT: if(IsStrNum(GetNextWord())) { romHeader.prgrepeat = ConfirmChar(StrToInt(szTemp)); PREP_OK = TRUE; } else error(ERR_INTEXP); break; case PREPROCESS_INES_CHRREPEAT: if(IsStrNum(GetNextWord())) { romHeader.chrrepeat = ConfirmChar(StrToInt(szTemp)); PREP_OK = TRUE; } else error(ERR_INTEXP); break; case PREPROCESS_INES_OFF: cfg.output.enableHeader = FALSE; break; default: error(ERR_PREPROCESSORID,szTemp); PREP_OK = FALSE; } break; /**********************************************************************/ case PREPROCESS_INTERRUPT: if(InFalseIfDef()) break; PREP_OK = TRUE; if(!PRECOMPILING) switch(code=CheckSubList(code)) { case PREPROCESS_INTERRUPT_NMI: case PREPROCESS_INTERRUPT_START: case PREPROCESS_INTERRUPT_IRQ: PREP_OK = PreprocessInterrupt(code); break; default: error(ERR_PREPROCESSORID,szTemp); PREP_OK = FALSE; } break; /**********************************************************************/ default: error(ERR_PREPROCESSORID,szTemp); } if(!PREP_OK) SkipLine(TRUE); // if there was an error, skip to the next line return TRUE; }
// //--------------------------------------------------------- // BOOL CEasyBDoc::WriteFile(CArchive& ar) { pFile = ar.GetFile(); ASSERT(pFile != NULL); int i,j,numCards; CString strTemp,strHand; // write the data // //----------------------------------------------------- // // first the file ID // WriteBlockHeader(BLOCK_FILEINFO); WriteString(ITEM_PROGRAM_ID,(LPCTSTR)theApp.GetValue(tstrProgramTitle)); WriteInt(ITEM_MAJOR_VERSIONNO,theApp.GetValue(tnProgramMajorVersion)); WriteInt(ITEM_MINOR_VERSIONNO,theApp.GetValue(tnProgramMinorVersion)); WriteInt(ITEM_INCREMENT_VERSIONNO,theApp.GetValue(tnProgramIncrementVersion)); WriteInt(ITEM_BUILD_NUMBER,theApp.GetValue(tnProgramBuildNumber)); WriteString(ITEM_BUILD_DATE,(LPCTSTR)theApp.GetValue(tstrProgramBuildDate)); CTime time = CTime::GetCurrentTime(); strTemp.Format(" %s",(LPCTSTR)time.Format("%c")); WriteString(ITEM_FILE_DATE,strTemp); SkipLine(); // then the file description WriteBlockHeader(BLOCK_FILEDESC); WriteString(ITEM_NONE,m_strFileDescription); // SkipLine(); // //----------------------------------------------------- // // hand information // WriteBlockHeader(BLOCK_HANDINFO); // first the current hand for(i=0;i<4;i++) { numCards = PLAYER(i).GetNumCards(); strHand.Empty(); for(j=0;j<numCards;j++) { strHand += PLAYER(i).GetCardByPosition(j)->GetName(); strHand += " "; } switch(i) { case NORTH: WriteString(ITEM_CURRHAND_NORTH,strHand); break; case EAST: WriteString(ITEM_CURRHAND_EAST,strHand); break; case SOUTH: WriteString(ITEM_CURRHAND_SOUTH,strHand); break; case WEST: WriteString(ITEM_CURRHAND_WEST,strHand); break; } } // then the original hand for(i=0;i<4;i++) { if (pVIEW->GetCurrentMode() == CEasyBView::MODE_CARDLAYOUT) { numCards = PLAYER(i).GetNumCards(); strHand.Empty(); for(j=0;j<numCards;j++) { strHand += PLAYER(i).GetCardByPosition(j)->GetName(); strHand += " "; } } else { strHand.Empty(); for(j=0;j<13;j++) { strHand += PLAYER(i).GetInitialHandCard(j)->GetName(); strHand += " "; } } switch(i) { case NORTH: WriteString(ITEM_ORIGHAND_NORTH,strHand); break; case EAST: WriteString(ITEM_ORIGHAND_EAST,strHand); break; case SOUTH: WriteString(ITEM_ORIGHAND_SOUTH,strHand); break; case WEST: WriteString(ITEM_ORIGHAND_WEST,strHand); break; } } SkipLine(); // //----------------------------------------------------- // // current round information // WriteBlockHeader(BLOCK_ROUNDINFO); /* WriteString(ITEM_CURR_ROUND_LEAD, PositionToString(m_nRoundLead)); // WriteInt(ITEM_NUM_CARDS_PLAYED_IN_ROUND, m_numCardsPlayedInRound); // tricks in current round for(i=0;i<m_numCardsPlayedInRound;i++) WriteString(ITEM_TRICK_CARD_1+i,m_pCurrTrick[i]->GetName()); */ // SkipLine(); // //----------------------------------------------------- // // game status info // WriteBlockHeader(BLOCK_GAMEINFO); WriteInt(ITEM_VIEW_STATUS_CODE,pVIEW->GetCurrentMode()); WriteBool(ITEM_RUBBER_IN_PROGRESS,theApp.IsRubberInProgress()); WriteBool(ITEM_GAME_IN_PROGRESS,theApp.IsGameInProgress()); WriteBool(ITEM_BIDDING_IN_PROGRESS,theApp.IsBiddingInProgress()); WriteBool(ITEM_HANDS_DEALT,m_bHandsDealt); strTemp.Format("%s",SuitToString(m_nContractSuit)); WriteString(ITEM_CONTRACT_SUIT,strTemp); WriteInt(ITEM_CONTRACT_LEVEL,m_nContractLevel); WriteInt(ITEM_CONTRACT_MODIFIER, m_bRedoubled? 2 : m_bDoubled? 1 : 0); WriteString(ITEM_DEALER,PositionToString(m_nDealer)); WriteInt(ITEM_NUM_BIDS,m_numBidsMade); // declarer & bidding history strTemp.Empty(); int nIndex = 0; for(i=0;i<=m_numBidsMade;i++) { strTemp += BidToShortString(m_nBiddingHistory[i]); strTemp += " "; } WriteString(ITEM_DECLARER,PositionToString(m_nDeclarer)); WriteString(ITEM_BIDDING_HISTORY,strTemp); SkipLine(); // //----------------------------------------------------- // // game play record // WriteBlockHeader(BLOCK_GAMERECORD); if (m_bSaveIntermediatePositions) { // write the # tricks played int numTricks = m_numTricksPlayed; // see if the current trick is incomplete if ((pDOC->GetNumCardsPlayedInRound() > 0) && (numTricks < 13)) numTricks++; WriteInt(ITEM_NUM_TRICKS_PLAYED,numTricks); // # tricks won by each side WriteInt(ITEM_NUM_TRICKS_WON_NS,m_numTricksWon[0]); WriteInt(ITEM_NUM_TRICKS_WON_EW,m_numTricksWon[1]); WriteString(ITEM_GAME_LEAD,PositionToString(m_nGameLead)); // and the record of tricks for(i=0;i<13;i++) { if (i <= m_numTricksPlayed) { strTemp.Empty(); strTemp += PositionToString(m_nTrickLead[i]); strTemp += " "; for(j=0;j<4;j++) { CCard* pCard = NULL; if (i < m_numTricksPlayed) pCard = m_pGameTrick[i][j]; else pCard = m_pCurrTrick[j]; // if (pCard != NULL) { strTemp += pCard->GetName(); strTemp += " "; } else { strTemp += "-- "; } } strTemp += PositionToString(m_nTrickWinner[i]); } else { strTemp = ""; } WriteString(ITEM_GAME_TRICK_1+i,strTemp); } } else { WriteInt(ITEM_NUM_TRICKS_PLAYED, 0); } // SkipLine(); // //----------------------------------------------------- // // match info // if (theApp.IsRubberInProgress()) { // write block header WriteBlockHeader(BLOCK_MATCHINFO); // write out scores WriteInt(ITEM_SCORE_NS_BONUS, m_nBonusScore[NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAME0, m_nGameScore[0][NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAME1, m_nGameScore[1][NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAME2, m_nGameScore[2][NORTH_SOUTH]); WriteInt(ITEM_SCORE_NS_GAMES_WON, m_numGamesWon[NORTH_SOUTH]); // WriteInt(ITEM_SCORE_EW_BONUS, m_nBonusScore[EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAME0, m_nGameScore[0][EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAME1, m_nGameScore[1][EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAME2, m_nGameScore[2][EAST_WEST]); WriteInt(ITEM_SCORE_EW_GAMES_WON, m_numGamesWon[EAST_WEST]); // write out current game WriteInt(ITEM_CURRENT_GAME_INDEX, m_nCurrGame+1); // write out score record int numBonusScoreRecords = m_strArrayBonusPointsRecord.GetSize(); for(int i=0;i<numBonusScoreRecords;i++) WriteString(ITEM_BONUS_SCORE_RECORD, WrapInQuotes(m_strArrayBonusPointsRecord.GetAt(i))); // int numGameScoreRecords = m_strArrayTrickPointsRecord.GetSize(); for(i=0;i<numGameScoreRecords;i++) WriteString(ITEM_GAME_SCORE_RECORD, WrapInQuotes(m_strArrayTrickPointsRecord.GetAt(i))); // SkipLine(); } // //----------------------------------------------------- // // misc info // WriteBlockHeader(BLOCK_MISCINFO); WriteBool(ITEM_AUTOSHOW_COMMENTS,m_bShowCommentsUponOpen); WriteBool(ITEM_AUTOSHOW_BID_HISTORY,m_bShowBidHistoryUponOpen); WriteBool(ITEM_AUTOSHOW_PLAY_HISTORY,m_bShowPlayHistoryUponOpen); WriteBool(ITEM_AUTOSHOW_ANALYSES,m_bShowAnalysesUponOpen); SkipLine(); // //----------------------------------------------------- // // file comments // WriteBlockHeader(BLOCK_COMMENTS); // get the current file comments text if the dialog is open CWnd* pWnd = pMAINFRAME->GetDialog(twFileCommentsDialog); if (pWnd) pWnd->SendMessage(WM_COMMAND, WMS_UPDATE_TEXT, TRUE); WriteString(0,m_strFileComments); SkipLine(); // //----------------------------------------------------- // // PlayerAnalysis, if appropriate // for(i=0;i<4;i++) { if (m_bSavePlayerAnalysis[i]) { // save out the player analysis text WriteBlockHeader(BLOCK_PLAYER_ANALYSIS + i); WriteString(0, m_pPlayer[i]->GetValueString(tszAnalysis)); SkipLine(); } } // //----------------------------------------------------- // // All done // ar.Flush(); return TRUE; }
bool FastqParser::Analyze(const FastqDataChunk& chunk_, FastqDatasetType& header_, bool estimateQualityOffset_) { uchar minQuality = (uchar)-1; uchar maxQuality = 0; memory = (byte*)chunk_.data.Pointer(); memoryPos = 0; memorySize = chunk_.size; header_.colorSpace = false; header_.plusRepetition = false; //header_.qualityOffset = 0; uint32 recCount = 0; while (memoryPos < memorySize) { // read stuff // byte* title = memory + memoryPos; uint32 titleLen = SkipLine(); if (titleLen == 0 || title[0] != '@') break; byte* sequence = memory + memoryPos; uint32 seqLen = SkipLine(); if (seqLen == 0) break; byte* plus = memory + memoryPos; bool plusRep = SkipLine() > 1; if (plus[0] != '+') break; if (estimateQualityOffset_) { byte* qua = memory + memoryPos; uint32 quaLen = SkipLine(); for (uint32 i = 0; i < quaLen; ++i) { minQuality = MIN(minQuality, qua[i]); maxQuality = MAX(maxQuality, qua[i]); } } else { if (SkipLine() == 0) // read quality break; } // analyze stuff // bool colorEnc = (sequence[1] >= '0' && sequence[1] <= '3') || sequence[1] == '.'; if (recCount != 0) { if (header_.colorSpace != colorEnc) { //throw std::runtime_error("Inconsistent sequence (ColorSpace / Normal) format"); return false; } if (header_.colorSpace) { //throw std::runtime_error("Invalid color-space format"); if (sequence[0] >= '0' && sequence[0] <= '3') return false; } if (header_.plusRepetition != plusRep) { //throw std::runtime_error("Inconsistent plus field format"); return false; } } else { header_.plusRepetition = plusRep; header_.colorSpace = colorEnc; } recCount++; } if (estimateQualityOffset_) { // standard quality scores if (maxQuality <= 74) { if (minQuality >= 33) header_.qualityOffset = 33; // standard Sanger / Illumina 1.8+ } else if (maxQuality <= 105) { if (minQuality >= 64) header_.qualityOffset = 64; // Illumina 1.3-1.8 else if (minQuality >= 59) header_.qualityOffset = 59; // Solexa } // check non-standard if (header_.qualityOffset == 0) { if (minQuality >= 33) header_.qualityOffset = 33; else return false; } } return recCount > 1; }
void Indexer::Build(CorpusDescriptorPtr corpus) { if (!m_index.IsEmpty()) { return; } m_index.Reserve(filesize(m_file)); RefillBuffer(); // read the first block of data if (m_done) { RuntimeError("Input file is empty"); } if ((m_bufferEnd - m_bufferStart > 3) && (m_bufferStart[0] == '\xEF' && m_bufferStart[1] == '\xBB' && m_bufferStart[2] == '\xBF')) { // input file contains UTF-8 BOM value, skip it. m_pos += 3; m_fileOffsetStart += 3; m_bufferStart += 3; } // check the first byte and decide what to do next if (!m_hasSequenceIds || m_bufferStart[0] == NAME_PREFIX) { // skip sequence id parsing, treat lines as individual sequences BuildFromLines(corpus); return; } size_t id = 0; int64_t offset = GetFileOffset(); // read the very first sequence id if (!TryGetSequenceId(id)) { RuntimeError("Expected a sequence id at the offset %" PRIi64 ", none was found.", offset); } SequenceDescriptor sd = {}; sd.m_fileOffsetBytes = offset; size_t currentKey = id; while (!m_done) { SkipLine(); // ignore whatever is left on this line. offset = GetFileOffset(); // a new line starts at this offset; sd.m_numberOfSamples++; if (!m_done && TryGetSequenceId(id) && id != currentKey) { // found a new sequence, which starts at the [offset] bytes into the file sd.m_byteSize = offset - sd.m_fileOffsetBytes; AddSequenceIfIncluded(corpus, currentKey, sd); sd = {}; sd.m_fileOffsetBytes = offset; currentKey = id; } } // calculate the byte size for the last sequence sd.m_byteSize = m_fileOffsetEnd - sd.m_fileOffsetBytes; AddSequenceIfIncluded(corpus, currentKey, sd); }