nsresult AnnotateCrashReport(const nsACString& key, const nsACString& data) { if (!gExceptionHandler) return NS_ERROR_NOT_INITIALIZED; if (DoFindInReadable(key, NS_LITERAL_CSTRING("=")) || DoFindInReadable(key, NS_LITERAL_CSTRING("\n"))) return NS_ERROR_INVALID_ARG; if (DoFindInReadable(data, NS_LITERAL_CSTRING("\0"))) return NS_ERROR_INVALID_ARG; nsCString escapedData(data); // escape backslashes ReplaceChar(escapedData, NS_LITERAL_CSTRING("\\"), NS_LITERAL_CSTRING("\\\\")); // escape newlines ReplaceChar(escapedData, NS_LITERAL_CSTRING("\n"), NS_LITERAL_CSTRING("\\n")); nsresult rv = crashReporterAPIData_Hash->Put(key, escapedData); NS_ENSURE_SUCCESS(rv, rv); // now rebuild the file contents crashReporterAPIData->Truncate(0); crashReporterAPIData_Hash->EnumerateRead(EnumerateEntries, crashReporterAPIData); return NS_OK; }
void fabmaster_baca_fab_header (char *teks, boardptr bptr) { char fld[64]; ReplaceChar (&teks[2],'!',0); ReplaceChar (teks, ' ', '-'); board_tambahversi(bptr, &teks[2]); }
std::wstring Base64Encode(const std::wstring& str, bool for_filename) { std::wstring output = StrToWstr(Base64Encode(WstrToStr(str))); if (for_filename) ReplaceChar(output, '/', '-'); return output; }
void nsTString_CharT::CompressWhitespace( bool aTrimLeading, bool aTrimTrailing ) { const char* set = kWhitespace; ReplaceChar(set, ' '); Trim(set, aTrimLeading, aTrimTrailing); // this one does some questionable fu... just copying the old code! mLength = nsBufferRoutines<char_type>::compress_chars(mData, mLength, set); }
char * ProfilerLabelInterval ( int duration ) { int interval, hhh, mm; char buf[10], *retstr; interval = (duration * 60) / 8; hhh = interval / 60; mm = interval % 60; sprintf ( buf, "%3d%2d", hhh, mm ); ReplaceChar ( buf, ' ', '0' ); retstr = strdup ( buf ); return retstr; }
char * ProfilerTimeInterval ( char *time_int ) { int interval, hhh, mm; char buf[10], *retstr; interval = str2int ( time_int ); hhh = interval / 60; mm = interval % 60; sprintf ( buf, "%3d%2d", hhh, mm ); ReplaceChar ( buf, ' ', '0' ); retstr = strdup ( buf ); return retstr; }
std::string NormalizePath(const char* path) { std::string result; const char* t = path; // Handle path prefixes: C:, C:/, /, //server/ if (ExtractPathPrefix(path, &result)) { t += result.size(); #ifdef CFG_OS_WINDOWS ReplaceChar(result, '/', '\\'); #endif } // Split path into elements std::string token; TValueArray<std::string> elements; MultiString ms(t, FILE_PATH_DELIMITERS, NULL); for (int i = 0; i < ms.word_count(); ++i) { token = ms.word(i); if (!token.empty() && token != ".") { if (token == "..") { if (elements.Count() > 0 && elements[elements.Count() - 1] != "..") elements.SetCount(elements.Count() - 1); else if (result.empty()) elements.Add(token); else throw new ArgumentException(FormattedString( "path '%s' cannot be normalized", path)); } else elements.Add(token); } } // Join remaining elements if (elements.Count() > 0) { result.append(elements.Item(0)); for (int i = 1; i < elements.Count(); ++i) { result.append(1, FILE_PATH_DELIMITERS[0]); result.append(elements.Item(i)); } } return result; }
/***************************************************************************** DWORD WriteHashLine(CONST HANDLE hFile, CONST TCHAR szFilename[MAX_PATH_EX], CONST TCHAR szHashResult[RESULT_AS_STRING_MAX_LENGTH], BOOL bIsSfv) hFile : (IN) handle to an open file szFilename : (IN) string of the filename that we want to write into the hash file szHashResult : (IN) string of the hash result bIsSfv : (IN) is this a sfv hash Return Value: - returns NOERROR or GetLastError() *****************************************************************************/ DWORD WriteHashLine(CONST HANDLE hFile, CONST TCHAR szFilename[MAX_PATH_EX], CONST TCHAR szHashResult[RESULT_AS_STRING_MAX_LENGTH], BOOL bIsSfv) { TCHAR szFilenameTemp[MAX_PATH_EX]; TCHAR szLine[MAX_LINE_LENGTH]; #ifdef UNICODE CHAR szLineAnsi[MAX_LINE_LENGTH]; #endif DWORD dwNumberOfBytesWritten; size_t stStringLength; VOID *szOutLine=szLine; if(!RegularFromLongFilename(szFilenameTemp, szFilename)) { if(g_program_options.bCreateUnixStyle) ReplaceChar(szFilenameTemp, MAX_PATH_EX, TEXT('\\'), TEXT('/')); } if(bIsSfv) StringCchPrintf(szLine, MAX_LINE_LENGTH, TEXT("%s %s%s"), szFilenameTemp, szHashResult, g_program_options.bCreateUnixStyle ? TEXT("\n") : TEXT("\r\n")); else StringCchPrintf(szLine, MAX_LINE_LENGTH, TEXT("%s *%s%s"), szHashResult, szFilenameTemp, g_program_options.bCreateUnixStyle ? TEXT("\n") : TEXT("\r\n")); StringCbLength(szLine, MAX_LINE_LENGTH, & stStringLength); #ifdef UNICODE // we only need the conversion if we don't write unicode data if(!g_program_options.bCreateUnicodeFiles) { if(!WideCharToMultiByte(CP_ACP, 0, szLine, -1, szLineAnsi, MAX_UTF8_PATH, NULL, NULL) ) return GetLastError(); StringCbLengthA(szLineAnsi, MAX_LINE_LENGTH, & stStringLength); szOutLine=szLineAnsi; } else if(g_program_options.iUnicodeSaveType == UTF_8 || g_program_options.iUnicodeSaveType==UTF_8_BOM) { if(!WideCharToMultiByte(CP_UTF8, 0, szLine, -1, szLineAnsi, MAX_UTF8_PATH, NULL, NULL) ) return GetLastError(); StringCbLengthA(szLineAnsi, MAX_LINE_LENGTH, & stStringLength); szOutLine=szLineAnsi; } #endif if(!WriteFile(hFile, szOutLine, (DWORD)stStringLength, & dwNumberOfBytesWritten, NULL) ) return GetLastError(); return NOERROR; }
BOOL InterpretSFVLine(TCHAR *szLine, UINT uiStringLength, lFILEINFO *fileList, UINT uiHashMode) { BOOL bCrcOK, bWasAbsolute = FALSE; FILEINFO fileinfoTmp = {0}; fileinfoTmp.parentList=fileList; if(uiStringLength < 9) return FALSE; //delete trailing spaces while( (szLine[uiStringLength - 1] == TEXT(' ')) && (uiStringLength > 8) ){ szLine[uiStringLength - 1] = NULL; uiStringLength--; } if( (szLine[0] != TEXT(';')) && (szLine[0] != TEXT('\0')) ){ bCrcOK = TRUE; for(int i=1; i <= 8; ++i) if(! IsLegalHexSymbol(szLine[uiStringLength-i])) bCrcOK = FALSE; if(bCrcOK){ fileinfoTmp.hashInfo[uiHashMode].dwFound = HASH_FOUND_FILE; fileinfoTmp.hashInfo[uiHashMode].f.dwCrc32Found = HexToDword(szLine + uiStringLength - 8, 8); fileinfoTmp.dwError = NOERROR; } else fileinfoTmp.dwError = APPL_ERROR_ILLEGAL_CRC; uiStringLength -= 8; szLine[uiStringLength] = NULL; // keep only the filename //delete trailing spaces while( (szLine[uiStringLength - 1] == TEXT(' ')) && (uiStringLength > 0) ){ szLine[uiStringLength - 1] = NULL; uiStringLength--; } ReplaceChar(szLine, MAX_PATH_EX, TEXT('/'), TEXT('\\')); bWasAbsolute = !ConstructCompleteFilename(fileinfoTmp.szFilename, fileList->g_szBasePath, szLine); fileList->fInfos.push_back(fileinfoTmp); } return bWasAbsolute; }
BOOL InterpretMDSHALine(TCHAR *szLine, UINT uiStringLength, UINT uiMode, lFILEINFO *fileList) { UINT uiHashLengthChars = g_hash_lengths[uiMode] * 2; UINT uiIndex; BOOL bHashOK, bWasAbsolute = FALSE; FILEINFO fileinfoTmp = {0}; fileinfoTmp.parentList=fileList; if(uiStringLength < uiHashLengthChars) return FALSE; if( IsLegalHexSymbol(szLine[0]) ){ bHashOK = TRUE; for(uiIndex=0; uiIndex < uiHashLengthChars; ++uiIndex) if(! IsLegalHexSymbol(szLine[uiIndex])) bHashOK = FALSE; if(bHashOK){ fileinfoTmp.hashInfo[uiMode].dwFound = TRUE; for(uiIndex=0; uiIndex < g_hash_lengths[uiMode]; ++uiIndex) *((BYTE *)&fileinfoTmp.hashInfo[uiMode].f + uiIndex) = (BYTE)HexToDword(szLine + uiIndex * 2, 2); fileinfoTmp.dwError = NOERROR; } else fileinfoTmp.dwError = APPL_ERROR_ILLEGAL_CRC; //delete trailing spaces while(szLine[uiStringLength - 1] == TEXT(' ')){ szLine[uiStringLength - 1] = NULL; uiStringLength--; } //find leading spaces and '*' uiIndex = uiHashLengthChars; // szLine[uiHashLengthChars] is the first char after the hash while( (uiIndex < uiStringLength) && ((szLine[uiIndex] == TEXT(' ')) || (szLine[uiIndex] == TEXT('*'))) ) uiIndex++; ReplaceChar(szLine, MAX_PATH_EX, TEXT('/'), TEXT('\\')); bWasAbsolute = !ConstructCompleteFilename(fileinfoTmp.szFilename, fileList->g_szBasePath, szLine + uiIndex); fileList->fInfos.push_back(fileinfoTmp); } return bWasAbsolute; }
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; }
char *Pxf::DuplicateReplaceChar(const char *str, const char find, const char replace) { char *p = StringDuplicate(str); ReplaceChar(p, find, replace); return p; }
BOOL InterpretBSDLine(TCHAR *szLine, UINT uiStringLength, lFILEINFO *fileList) { BOOL bHashOK, bWasAbsolute = FALSE; int iHashIndex = -1; FILEINFO fileinfoTmp = {0}; fileinfoTmp.parentList=fileList; if(uiStringLength < 5) return FALSE; for(int i=0; i < NUM_HASH_TYPES; i++) { if(!_tcsncmp(szLine, g_hash_names[i], lstrlen(g_hash_names[i]))) { iHashIndex = i; break; } } if(iHashIndex<0) return FALSE; TCHAR *szFirstBrace = _tcschr(szLine, TEXT('(')); TCHAR *szLastBrace = _tcsrchr(szLine, TEXT(')')); if(!szFirstBrace || !szLastBrace || szFirstBrace > szLastBrace) return FALSE; *szLastBrace = TEXT('\0'); szLastBrace++; ReplaceChar(szFirstBrace + 1, MAX_PATH_EX, TEXT('/'), TEXT('\\')); bWasAbsolute = !ConstructCompleteFilename(fileinfoTmp.szFilename, fileList->g_szBasePath, szFirstBrace + 1); while(!IsLegalHexSymbol(*szLastBrace) && *szLastBrace != TEXT('\0') ) szLastBrace++; UINT uiHashLengthChars = g_hash_lengths[iHashIndex] * 2; if(lstrlen(szLastBrace) < (int)uiHashLengthChars) return FALSE; FILEINFO *fileInfo = &fileinfoTmp; bool alreadyInList = false; for(list<FILEINFO>::reverse_iterator it = fileList->fInfos.rbegin(); it != fileList->fInfos.rend(); it++) { if(it->szFilename == fileinfoTmp.szFilename) { fileInfo = &(*it); alreadyInList = true; break; } } if( IsLegalHexSymbol(*szLastBrace) ){ bHashOK = TRUE; for(UINT uiIndex=0; uiIndex < uiHashLengthChars; ++uiIndex) if(! IsLegalHexSymbol(szLastBrace[uiIndex])) bHashOK = FALSE; if(bHashOK){ fileInfo->hashInfo[iHashIndex].dwFound = TRUE; if(iHashIndex == HASH_TYPE_CRC32) { fileInfo->hashInfo[HASH_TYPE_CRC32].f.dwCrc32Found = HexToDword(szLastBrace, 8); } else { for(UINT uiIndex=0; uiIndex < g_hash_lengths[iHashIndex]; ++uiIndex) *((BYTE *)&fileInfo->hashInfo[iHashIndex].f + uiIndex) = (BYTE)HexToDword(szLastBrace + uiIndex * 2, 2); } fileInfo->dwError = NOERROR; } else fileInfo->dwError = APPL_ERROR_ILLEGAL_CRC; if(!alreadyInList) fileList->fInfos.push_back(fileinfoTmp); fileList->bDoCalculate[iHashIndex] = true; } return bWasAbsolute; }
// X-Y Plot given C-Code style (GLSL) expressions x and y. void Plotter::PlotSeries::CreatePlot(const std::string &x, const std::string &y, Colour colour, std::string title) { static const std::string vs_header = "uniform float u_id_offset;\n" "uniform vec4 u_color;\n" "uniform vec2 u_scale;\n" "uniform vec2 u_offset;\n" "varying vec4 v_color;\n" "void main() {\n"; static const std::string vs_footer = " vec2 pos = vec2(x, y);\n" " gl_Position = vec4(u_scale * (pos + u_offset),0,1);\n" " v_color = u_color;\n" "}\n"; static const std::string fs = #ifdef HAVE_GLES_2 "precision mediump float;\n" #endif // HAVE_GLES_2 "varying vec4 v_color;\n" "void main() {\n" " gl_FragColor = v_color;\n" "}\n"; attribs.clear(); this->colour = colour; this->title = GlFont::I().Text(title.c_str()); const std::set<int> ax = ConvertSequences(x); const std::set<int> ay = ConvertSequences(y); std::set<int> as; as.insert(ax.begin(), ax.end()); as.insert(ay.begin(), ay.end()); contains_id = ( as.find(-1) != as.end() ); std::ostringstream oss_prog; for(std::set<int>::const_iterator i=as.begin(); i != as.end(); ++i) { std::ostringstream oss; oss << "s" << *i; const std::string name = *i >= 0 ? oss.str() : "sn"; attribs.push_back( PlotAttrib(name, *i) ); oss_prog << "attribute float " + name + ";\n"; } oss_prog << vs_header; if(contains_id) { oss_prog << "float si = sn + u_id_offset;\n"; } oss_prog << "float x = " + ReplaceChar(x,'$','s') + ";\n"; oss_prog << "float y = " + ReplaceChar(y,'$','s') + ";\n"; oss_prog << vs_footer; prog.AddShader( GlSlVertexShader, oss_prog.str() ); prog.AddShader( GlSlFragmentShader, fs ); prog.Link(); // Lookup attribute locations in compiled shader prog.SaveBind(); for(size_t i=0; i<attribs.size(); ++i) { attribs[i].location = prog.GetAttributeHandle( attribs[i].name ); } prog.Unbind(); }
int fabmaster_baca_fab (const char *namafile, boardptr bptr) { FILE *f; char teks[256]; char line[256]; //char nama[64]; int p=0; //int i=0; FABM_AKSI2 aksi = FABM_NONE; //int node_id = -1; #ifdef _BEEVEE_VERBOSE_ printf ("fabmaster_baca_fab %s ...\n", namafile); #endif if ( (f=fopen(namafile,"r"))!=NULL ) { //nama[0] = 0; line[0] = 0; while (1) { if (p==0 || line[p]==0) { p = 0; memset (line,0,256); fgets (line, 255, f); if (line[0]==0 && line[1]!=0) line[0] = ' '; //if (i++<4) printf ("%d: %s",i,line); if (feof(f)) break; } //else // printf (line); ReplaceChar (line, '\t',' '); ReplaceChar (line, 0xa, 0xd); TrimLeft(line); TrimRight(line); UpperText(line); if (GetLine(line,teks,&p)) { if (teks[0]=='R') aksi = FABM_HEADER; else if (teks[0]=='A') { if (strcmp (teks, FABM_PLACES_STR)==0) aksi = FABM_PLACES; else if (strcmp (teks, FABM_CONNECTIONS_STR)==0) aksi = FABM_CONNECTIONS; else if (strcmp (teks, FABM_ASSEMBLY_STR)==0) aksi = FABM_ASSEMBLY; else if (strcmp (teks, FABM_PINS_STR)==0) aksi = FABM_PINS; else if (strcmp (teks, FABM_VIAS_STR)==0) aksi = FABM_VIAS; else if (strcmp (teks, FABM_TRACES_STR)==0) aksi = FABM_TRACES; else aksi = FABM_NONE; //printf ("%d %s\n",aksi,teks); teks[0] = 0; } //if (aksi == FABM_NONE) // printf ("%s\n", teks); if (aksi != FABM_NONE && teks[0]=='S') { //printf (teks); switch (aksi) { case FABM_PLACES: fabmaster_baca_fab_place (teks, &bptr->skomp); break; case FABM_CONNECTIONS: fabmaster_baca_fab_connection (teks, &bptr->snode, &bptr->skonek); break; case FABM_ASSEMBLY: fabmaster_baca_fab_assembly (teks, &bptr->skomp); break; case FABM_PINS: fabmaster_baca_fab_pins (teks, &bptr->skonek, &bptr->stestpoint); break; case FABM_VIAS: fabmaster_baca_fab_vias (teks, &bptr->snode, &bptr->stestpoint, &bptr->strace); break; case FABM_TRACES: fabmaster_baca_fab_traces (teks, &bptr->snode, &bptr->strace); break; } } else if (aksi==FABM_HEADER) { fabmaster_baca_fab_header (teks, bptr); } } else { //aksi = FABM_NONE; p = 0; } } fclose (f); } else { #ifdef _BEEVEE_VERBOSE_ printf ("Ga bisa baca %s\n", namafile); #endif return 0; } #ifdef _BEEVEE_VERBOSE_ printf ("Jumlah Node %d\n", sdata_jumlahdata(&bptr->snode)); printf ("Jumlah Komponen %d\n", sdata_jumlahdata(&bptr->skomp)); printf ("Jumlah Trace %d\n", sdata_jumlahdata(&bptr->strace)); printf ("Jumlah Koneksi %d\n", sdata_jumlahdata(&bptr->skonek)); #endif if (sdata_jumlahdata(&bptr->snode)==0 || sdata_jumlahdata(&bptr->skomp)==0 || sdata_jumlahdata(&bptr->strace)==0 || sdata_jumlahdata(&bptr->skonek)==0) { board_hapus(bptr); return 0; } board_hitung_ataskiri (bptr); bptr->punya_tempat = 1; return 1; }
/**************************************************************************** * Function : EncodeLZSSByFile * Description: This function will read an input file and write an output * file encoded according to the traditional LZSS algorithm. * This algorithm encodes strings as 16 bits (a 12 bit offset * + a 4 bit length). * Parameters : fpIn - pointer to the open binary file to encode * fpOut - pointer to the open binary file to write encoded * output * Effects : fpIn is encoded and written to fpOut. Neither file is * closed after exit. * Returned : EXIT_SUCCESS or EXIT_FAILURE ****************************************************************************/ int EncodeLZSSByFile(FILE *fpIn, FILE *fpOut) { bit_file_t *bfpOut; encoded_string_t matchData; unsigned int i, c; unsigned int len; /* length of string */ /* head of sliding window and lookahead */ unsigned int windowHead, uncodedHead; /* use stdin if no input file */ if (fpIn == NULL) { fpIn = stdin; } if (fpOut == NULL) { /* use stdout if no output file */ bfpOut = MakeBitFile(stdout, BF_WRITE); } else { /* convert output file to bitfile */ bfpOut = MakeBitFile(fpOut, BF_WRITE); } windowHead = 0; uncodedHead = 0; /* Window Size : 2^12 same as offset */ /************************************************************************ * Fill the sliding window buffer with some known vales. DecodeLZSS must * use the same values. If common characters are used, there's an * increased chance of matching to the earlier strings. ************************************************************************/ memset(slidingWindow, ' ', WINDOW_SIZE * sizeof(unsigned char)); /* MAX_CODED : 2 to 17 because we cant have 0 to 1 */ /************************************************************************ * Copy MAX_CODED bytes from the input file into the uncoded lookahead * buffer. ************************************************************************/ for (len = 0; len < MAX_CODED && (c = getc(fpIn)) != EOF; len++) { uncodedLookahead[len] = c; } if (len == 0) { return (EXIT_SUCCESS); /* inFile was empty */ } /* Look for matching string in sliding window */ InitializeSearchStructures(); matchData = FindMatch(windowHead, uncodedHead); /* now encoded the rest of the file until an EOF is read */ while (len > 0) { if (matchData.length > len) { /* garbage beyond last data happened to extend match length */ matchData.length = len; } if (matchData.length <= MAX_UNCODED) { /* not long enough match. write uncoded flag and character */ BitFilePutBit(UNCODED, bfpOut); BitFilePutChar(uncodedLookahead[uncodedHead], bfpOut); matchData.length = 1; /* set to 1 for 1 byte uncoded */ } else { unsigned int adjustedLen; /* adjust the length of the match so minimun encoded len is 0*/ adjustedLen = matchData.length - (MAX_UNCODED + 1); /* match length > MAX_UNCODED. Encode as offset and length. */ BitFilePutBit(ENCODED, bfpOut); BitFilePutBitsInt(bfpOut, &matchData.offset, OFFSET_BITS, sizeof(unsigned int)); BitFilePutBitsInt(bfpOut, &adjustedLen, LENGTH_BITS, sizeof(unsigned int)); } /******************************************************************** * Replace the matchData.length worth of bytes we've matched in the * sliding window with new bytes from the input file. ********************************************************************/ i = 0; while ((i < matchData.length) && ((c = getc(fpIn)) != EOF)) { /* add old byte into sliding window and new into lookahead */ ReplaceChar(windowHead, uncodedLookahead[uncodedHead]); uncodedLookahead[uncodedHead] = c; windowHead = Wrap((windowHead + 1), WINDOW_SIZE); uncodedHead = Wrap((uncodedHead + 1), MAX_CODED); i++; } /* handle case where we hit EOF before filling lookahead */ while (i < matchData.length) { ReplaceChar(windowHead, uncodedLookahead[uncodedHead]); /* nothing to add to lookahead here */ windowHead = Wrap((windowHead + 1), WINDOW_SIZE); uncodedHead = Wrap((uncodedHead + 1), MAX_CODED); len--; i++; } /* find match for the remaining characters */ matchData = FindMatch(windowHead, uncodedHead); } /* we've decoded everything, free bitfile structure */ BitFileToFILE(bfpOut); return (EXIT_SUCCESS); }
uint8_t GoLine(void) { register uint8_t li; register uint8_t *lp; register unsigned int bi; //printf("\n#%d:%s\n",CLine,CmdInp); //printf("\n*lnum=%d A=%d\n",CLine,Vars[0]); Gp = CmdInp + 1; switch(CmdInp[0]){ case STOP: STOPPROG(ESTOP); case BEEP: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; bi = ExpPars1(); Gp=lp+1; Beep(bi,ExpPars1()); } return(0); case DIM: Gp+=2;//( li = ExpPars1(); if(CmdInp[1] != SIGNEDBYTE && CmdInp[1] != UNSIGNEDBYTE)//type of array li = li << 1;//two byte on item if(li <= (MAXBMEMSIZE-1)){ /* lp = Vars[TOVAR(CmdInp[1])]; if(lp > FirstPrgLine) lfree(lp);*/ lp = lmalloc(li+1,LlP); if(!lp) STOPPROG(EALLOC); *lp = CmdInp[1];//type of array lp++; //printf("\n*%p %c %d %d %s\n",lp,*(lp-1),*(lp-2),li,CmdInp); li = CmdInp[2];//name of array // if(SYMISVAR(li)) Vars[TOVAR(li)] = (unsigned int)lp; return(0); } STOPPROG(EERROR); return(0); case LET: lp = findchar(CmdInp, '='); Gp = lp+1; bi = ExpPars1(); // if(!SYMISVAR(li)) if(*(lp-1) == ')'){ *lp = 0; Gp = CmdInp+2;// '(' li = ExpPars1();//array index lp = (uint8_t *)Vars[TOVAR(CmdInp[1])]; //printf("\n+%p %c %d %d %d\n",lp,*(lp-1),*(lp-2),li,bi); if(*(lp-2) > (li+2)){// switch(*(lp-1)){//type of array case SIGNEDBYTE: *(((char *)lp + li)) = bi; break; case UNSIGNEDBYTE: *(((uint8_t *)lp + li)) = bi; break; default: // case SIGNEDWORD: *(((int *)lp + li)) = bi; break; /* case UNSIGNEDWORD: *(((unsigned int *)lp + li)) = bi; break; */ } } else STOPPROG(EERROR);//TODO } else Vars[TOVAR(CmdInp[1])] = bi; return(0); case AT: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; li = ExpPars1();//x if(li< LCDTWIDTH) #ifdef AVR xt=li*LCDSYMWIDTH; else xt=(LCDTWIDTH-1)*LCDSYMWIDTH; #else xt=li; else xt=(LCDTWIDTH-1); #endif Gp=lp+1; li = ExpPars1();//y if(li< LCDTHEIGHT) yt=li; else yt=LCDTHEIGHT-1; #ifdef AVR st7565_command(CMD_SET_DISP_START_LINE | ((LCDTHEIGHT-1)*8)+8); #else printf( "%c[%d;%dH", 27, yt+1, xt+1 ); // установили курсор в позицию fflush( stdout ); #endif } return(0); case OUT: lp = findchar(CmdInp, ','); if(lp) { *lp = 0; li = ExpPars1();//port Gp=lp+1; out_port(li,ExpPars1()); } return(0); case REM: return(0); case LOAD: FreePrg(); ReplaceChar(CmdInp+2, '"', 0); loadprg((const char *)(CmdInp+2)); PrgLineP = FirstPrgLine; return(1); case INPUT: lp = (uint8_t *)(Vars + TOVAR(CmdInp[1]));//pointer to var Gp++;//to '(' or 0 if(*Gp == '(') li = ExpPars1();//index else li = 255; lgets(CmdInp); if(CmdInp[0]==BREAK_KEY) STOPPROG(EINTERUPT); Gp=CmdInp; bi = ExpPars1(); if(li < MAXBMEMSIZE){ lp = (uint8_t *)(*((unsigned int *)lp)); if(*(lp-2) > (li+2)){// switch(*(lp-1)){//type of array case SIGNEDBYTE: *(((char *)lp + li)) = bi; break; case UNSIGNEDBYTE: *(((uint8_t *)lp + li)) = bi; break; default: *(((int *)lp + li)) = bi; break; } } else STOPPROG(EERROR);//TODO } else *lp = (int)bi; return(0); case IF: lp = findchar(CmdInp, THEN); if(lp){ *lp = 0; if(ExpPars1()){ strcpy((char *)CmdInp,(const char *)(lp+1)); return(2);; } }else STOPPROG(EERROR); return(0); case PRINT: li = strlen((const char *)CmdInp); while(Gp && *Gp){ if(*Gp == '"'){ Gp++; lp =findchar(Gp ,'"'); *lp = 0; lputs((char *)(Gp)); Gp = lp+1; } else{ if(*Gp == '$'){ Gp++; lputchar(ExpPars1()); } else lputint(ExpPars1()); } //printf("\n++ %s\n",Gp); Gp =findchar(Gp ,','); if(Gp) Gp++; } if(CmdInp[li-1]!=';') lputchar('\n'); return(0); case PAUSE: bi = ExpPars1(); delay_ms(bi); return(0); case GOTO: PrgLineP = GetPrgLine(ExpPars1(),0); if(!PrgLineP){ STOPPROG(EGOTONOWHERE); } return(1) ; case GOSUB: SubStack[SubStackP] = PrgLineP->next; SubStackP++; if(SubStackP >= SMAX){ STOPPROG(EGSOVF); } PrgLineP = GetPrgLine(ExpPars1(),0); if(!PrgLineP){ STOPPROG(EGOTONOWHERE); } return(1); case RETURN: if(SubStackP < 1){ STOPPROG(ERETWOG); } --SubStackP; PrgLineP = SubStack[SubStackP]; return(1); case FOR : lp = findchar(CmdInp, TO); if(lp){ *lp = 0; Gp = CmdInp+ 3; li = TOVAR(CmdInp[1]); if(li>LMAX) STOPPROG(ELOPSOVF); Vars[li] = ExpPars1(); Gp = lp + 1; LoopVar[li].var_to = ExpPars1(); LoopVar[li].line_begin = PrgLineP->next; }else STOPPROG(EERROR); return(0); case NEXT: li = TOVAR(CmdInp[1]); if(++Vars[li] <= LoopVar[li].var_to){ PrgLineP = LoopVar[li].line_begin; return(1); } break; }