bool Load(ARGUMENTSINFO & value) override { return getString("module", value.mod) && getHex("start", value.start) && getHex("end", value.end) && getBool("manual", value.manual) && getHex("icount", value.instructioncount) && value.end >= value.start; }
int main() { int N; scanf("%s%n", a, &N); scanf("%s", b); unsigned char p = 32; unsigned char k = p^getHex(b); printf("%02X", (unsigned char) k); for(int i = 0; i < N; i+=2) { unsigned char d = k^getHex(a+i); k = d^getHex(b+i+2); printf("%02X", (unsigned char) k); } }
int GetHexValue(char *src) { int i, j, flag; static char temp[1024]; for (i = 0, j = 0; src[i] != 0; i++) { if ((src[i] <= 'F' && src[i] >= 'A') || (src[i] <= 'f' && src[i] >= 'a') || (src[i] <= '9' && src[i] >= '0')) { if (src[i] != ' ') { temp[j++] = src[i]; } } } temp[j] = 0; src[0] = 0; for (i = 0, j = 0, flag = 1; temp[i] != 0; i++) { char ch = getHex(temp[i]); if (ch != -1) { if (flag == 1) src[j] = ch << 4; else src[j++] += ch; flag *= -1; } } src[j] = 0; return j; }
void ofApp::setup() { ofSetWindowPosition(0, 0); // create a vector of colors to populate our dropdown // colors.push_back(ofColor::fromHex(0xFFD00B)); colors.push_back(ofColor::fromHex(0x2FA1D6)); colors.push_back(ofColor::fromHex(0x1ED36F)); colors.push_back(ofColor::fromHex(0xC63256)); // convert the hex values of those colors to strings for the menu labels // vector<string> options; for (int i=0; i<colors.size(); i++) options.push_back(getHex(colors[i].getHex())); // instantiate the dropdown // menu = new ofxDatGuiDropdown("SELECT A COLOR", options); // and position it in the middle of the screen // menu->setPosition(ofGetWidth()/2 - menu->getWidth()/2, ofGetHeight()/2 - menu->getHeight()/2 - 100); // let's set the stripe of each option to its respective color // for (int i=0; i<menu->size(); i++) menu->getChildAt(i)->setStripeColor(colors[i]); // register to listen for change events // menu->onDropdownEvent(this, &ofApp::onDropdownEvent); // finally let's have it open by default // menu->expand(); }
bool Uri::Private::parsePctEncoded() { if (expectChar('%')) { Char curr = m_uri[m_parserPos]; size_t currValue = curr.value(); if (!currValue || currValue > 127 || !isHexdig[currValue]) { return false; } m_parserAux += curr; ++m_parserPos; curr = m_uri[m_parserPos]; currValue = curr.value(); if (!currValue || currValue > 127 || !isHexdig[currValue]) { return false; } m_parserAux += curr; ++m_parserPos; } else { const Char curr = m_uri[m_parserPos]; const iuint32 currValue = curr.value(); if (curr.octetsRequired() > 1) { m_parserAux += curr; ++m_parserPos; } else if (currValue && currValue < 128 && (!isUnreserved[currValue] && !isGendelim[currValue] && !isSubdelim[currValue] && curr != ':' && curr != '@')) { m_parserTrick = true; m_parserAux += getHex(curr); ++m_parserPos; } else { return false; } } return true; }
void HashStreamTest::hmacstream_test01() { { std::string key = "1234557890123456"; ibrcommon::HMacStream hstream((unsigned char*)key.c_str(), key.length()); hstream << "Hello World" << std::flush; if ("b3:7a:c5:9f:6d:2:60:bd:da:51:cc:d3:95:2:11:7:c0:f1:7b:f9:" != getHex(hstream)) { throw ibrcommon::Exception("unexpected hash value"); } } { std::string key = "1234557890123456"; ibrcommon::HMacStream hstream((unsigned char*)key.c_str(), key.length()); hstream << "Hello again my World!" << std::flush; if ("a0:1d:99:f2:99:a4:b9:dc:b7:44:df:7b:b5:75:19:c6:20:8:bc:da:" != getHex(hstream)) { throw ibrcommon::Exception("unexpected hash value"); } } }
char* TvDevice::PrintHex(const BYTE *pBuf,USHORT BufSize) { static char s[1024]; USHORT i=0; s[0]='\t'; for( i=0; (i<BufSize) && ((i*3+2)<1024); i++) { s[1+i*3+0]=getHex(pBuf[i]>>4); s[1+i*3+1]=getHex(pBuf[i]&0xf); s[1+i*3+2]=' '; s[1+i*3+3]=0; } s[1023]='\0'; return s; }
char *TKGetNextToken( TokenizerT * tk ) { if(tk->str[tk->pindex] == ' ' || tk->str[tk->pindex] == '\t' || tk->str[tk->pindex] == '\v' || tk->str[tk->pindex] == '\f' || tk->str[tk->pindex] == '\n' || tk->str[tk->pindex] == '\r'){ tk->pindex++; return NULL; } int charIndex = 0; char *tmp = (char*)malloc(sizeof(char)*strlen(tk->str)); if(isalnum(tk->str[tk->pindex])){ if(isalpha(tk->str[tk->pindex])){ //checks for word tmp[charIndex] = tk->str[tk->pindex]; charIndex++; tk->pindex++; tmp = getWord(tk, tmp, charIndex); return tmp; }else{ if(tk->str[tk->pindex] == '0' && isalnum(tk->str[tk->pindex + 1])){ //checks for hex if(tk->str[tk->pindex + 1] == 'x' || tk->str[tk->pindex + 1] == 'X'){ if(isdigit(tk->str[tk->pindex + 2]) || tk->str[tk->pindex + 2] == 'a' || tk->str[tk->pindex + 2] == 'b' || tk->str[tk->pindex + 2] == 'c' || tk->str[tk->pindex + 2] == 'd' || tk->str[tk->pindex + 2] == 'e' || tk->str[tk->pindex + 2] == 'f'){ tmp[charIndex] = tk->str[tk->pindex]; charIndex++; tk->pindex++; tmp = getHex(tk, tmp, charIndex); return tmp; } }else if(tk->str[tk->pindex + 1] == '0' || tk->str[tk->pindex + 1] == '1' || tk->str[tk->pindex + 1] == '2' || tk->str[tk->pindex + 1] == '3' || tk->str[tk->pindex + 1] == '4' || tk->str[tk->pindex + 1] == '5' || tk->str[tk->pindex + 1] == '6' || tk->str[tk->pindex + 1] == '7'){ // checks for octal tmp[charIndex] = tk->str[tk->pindex]; charIndex++; tk->pindex++; tmp = getOctal(tk, tmp, charIndex); return tmp; } } } //if not sends to number(decimal or floats) tmp[charIndex] = tk->str[tk->pindex]; charIndex++; tk->pindex++; tmp = getNumber(tk, tmp, charIndex); return tmp; }else{ // C-Operators tmp = getOp(tk, tmp, charIndex); } return tmp; }
JsonValueStringPtr YAC_Json::getString(BufferJsonReader & reader,char head) { JsonValueStringPtr p = new JsonValueString(); const char * pChar=reader.getPoint(); char c; uint32_t i=0; while(1) { c=reader.read(); if(c == '\\') { p->value.append(pChar,i); pChar=pChar+i+2; i=0; c=reader.read(); if(c == '\\' || c == '\"' || c == '/') p->value.append(1,c); else if(c == 'b') p->value.append(1,'\b'); else if(c == 'f') p->value.append(1,'\f'); else if(c == 'n') p->value.append(1,'\n'); else if(c == 'r') p->value.append(1,'\r'); else if(c == 't') p->value.append(1,'\t'); else if(c == 'u') { uint16_t iCode=getHex(reader); if(iCode>0xff) { char s[64]; snprintf(s, sizeof(s), "get string error(\\u)[pos:%u]", (uint32_t)reader.getCur()); throw YAC_Json_Exception(s); } pChar+=4; p->value.append(1,(char)iCode); #if 0 //还要再读一个 if(iCode<0xd800) { p->value.append(1,(char)(iCode>>2&0x00ff)); p->value.append(1,(char)(iCode&0x00ff)); } else {
int parse_color (char *arg, PColor c, int a) { if (arg[0] != '#') return 1; if ((strlen (arg) != 7) && (strlen (arg) != 9)) return 1; c->r = getHex (arg[1]) * 16 + getHex (arg[2]); c->g = getHex (arg[3]) * 16 + getHex (arg[4]); c->b = getHex (arg[5]) * 16 + getHex (arg[6]); c->a = a; if (strlen (arg) == 9) c->a = getHex (arg[7]) * 16 + getHex (arg[8]); return 0; }
/**************************************************************** * Description: print char. * Input: char* * buffer size * Return: char* ****************************************************************/ char *PrintHex(const BYTE *pBuf,USHORT BufSize) { static char s[1024]; s[0]=' '; if(pBuf==NULL || BufSize == 0) { s[0]=0; return s; } for(int i=0; (i<BufSize) && ((i*3+2)<1024); i++) { s[1+i*3+0]=getHex(pBuf[i]>>4); s[1+i*3+1]=getHex(pBuf[i]&0xf); s[1+i*3+2]=' '; s[1+i*3+3]=0; } s[1023]='\0'; return s; }
void HTTPObject::expandPath(char *dest, const char *path, U32 destSize) { static bool asciiEscapeTableBuilt = false; static bool asciiEscapeTable[256]; if(!asciiEscapeTableBuilt) { asciiEscapeTableBuilt = true; U32 i; for(i = 0; i <= ' '; i++) asciiEscapeTable[i] = true; for(;i <= 0x7F; i++) asciiEscapeTable[i] = false; for(;i <= 0xFF; i++) asciiEscapeTable[i] = true; asciiEscapeTable[static_cast<U32>('\"')] = true; asciiEscapeTable[static_cast<U32>('_')] = true; asciiEscapeTable[static_cast<U32>('\'')] = true; asciiEscapeTable[static_cast<U32>('#')] = true; asciiEscapeTable[static_cast<U32>('$')] = true; asciiEscapeTable[static_cast<U32>('%')] = true; asciiEscapeTable[static_cast<U32>('&')] = false; asciiEscapeTable[static_cast<U32>('+')] = true; asciiEscapeTable[static_cast<U32>('-')] = true; asciiEscapeTable[static_cast<U32>('~')] = true; } U32 destIndex = 0; U32 srcIndex = 0; while(path[srcIndex] && destIndex < destSize - 3) { char c = path[srcIndex++]; if(asciiEscapeTable[static_cast<U32>(c)]) { dest[destIndex++] = '%'; dest[destIndex++] = getHex((c >> 4) & 0xF); dest[destIndex++] = getHex(c & 0xF); } else dest[destIndex++] = c; }
int main(int argc, char **argv){ static ARGS args; initArgs(&args); parseArgs(argc, argv, &args); if(args.conversionModule == -1) { printf("Select a conversion module\n"); return 0; } if(args.hexValue == 0) getHex(&args); if((short)args.hexValue == -1 && args.filename[0] == '\0'){ printf("Input a hex value or file containing a hex value"); } swapEndian((char*)&(args.hexValue)); if(args.conversionModule == date){ DATE_STRUCT *dateS = (DATE_STRUCT*)&(args.hexValue); printf("Date: %s, %i, %i\n", months[dateS->month], dateS->day, dateS->year + YEAR_OFFSET); } else if(args.conversionModule == time){ TIME_STRUCT *timeS = (TIME_STRUCT*)&(args.hexValue); printf("Time: %i:%i:%i %s\n", timeS->hour%12, timeS->minute, timeS->second*2, timeS->hour > 12 ? "PM" : "AM"); } return 1; }
Ostream & operator<<(Ostream &out,const ExpressionResult &data) { // out.format(IOstream::ASCII); if(ExpressionResult::debug) { Pout << "operator<<(Ostream &out,const ExpressionResult &data) " << getHex(&data) << endl; Pout << "Format: " << (out.format()==IOstream::ASCII ? "ASCII" : "BINARY") << endl; } out << token::BEGIN_BLOCK << endl; out.writeKeyword("resultType"); out << word(data.type()) << token::END_STATEMENT << nl; out.writeKeyword("noReset"); out << data.noReset_ << token::END_STATEMENT << nl; if( data.valPtr_ ) { out.writeKeyword("valueType"); out << word(data.valType_) << token::END_STATEMENT << nl; out.writeKeyword("isPoint"); out << data.isPoint_ << token::END_STATEMENT << nl; out.writeKeyword("isSingleValue"); out << data.isSingleValue_ << token::END_STATEMENT << nl; out.writeKeyword("fieldSize"); out << data.size() << token::END_STATEMENT << nl; if(data.isSingleValue_) { out.writeKeyword("value"); if(data.valType_==pTraits<scalar>::typeName) { out << (*static_cast<Field<scalar>*>(data.valPtr_))[0]; } else if(data.valType_==vector::typeName) { out << (*static_cast<Field<vector>*>(data.valPtr_))[0]; } else if(data.valType_==tensor::typeName) { out << (*static_cast<Field<tensor>*>(data.valPtr_))[0]; } else if(data.valType_==symmTensor::typeName) { out << (*static_cast<Field<symmTensor>*>(data.valPtr_))[0]; } else if(data.valType_==sphericalTensor::typeName) { out << (*static_cast<Field<sphericalTensor>*>(data.valPtr_))[0]; } else if(data.valType_==pTraits<bool>::typeName) { out << (*static_cast<Field<bool>*>(data.valPtr_))[0]; } else { out << "ExpressionResult: unknown data type " << data.valType_ << endl; } out << token::END_STATEMENT << nl; } else { out.writeKeyword("value"); if(data.valType_==pTraits<scalar>::typeName) { out << "nonuniform " << (*static_cast<Field<scalar>*>(data.valPtr_)); // static_cast<Field<scalar>*>(data.valPtr_)->writeEntry("value",out); } else if(data.valType_==vector::typeName) { out << "nonuniform " << (*static_cast<Field<vector>*>(data.valPtr_)); // static_cast<Field<vector>*>(data.valPtr_)->writeEntry("value",out); } else if(data.valType_==tensor::typeName) { out << "nonuniform " << (*static_cast<Field<tensor>*>(data.valPtr_)); // static_cast<Field<tensor>*>(data.valPtr_)->writeEntry("value",out); } else if(data.valType_==symmTensor::typeName) { out << "nonuniform " << (*static_cast<Field<symmTensor>*>(data.valPtr_)); // static_cast<Field<symmTensor>*>(data.valPtr_)->writeEntry("value",out); } else if(data.valType_==sphericalTensor::typeName) { out << "nonuniform " << (*static_cast<Field<sphericalTensor>*>(data.valPtr_)); // static_cast<Field<sphericalTensor>*>(data.valPtr_)->writeEntry("value",out); } else if(data.valType_==pTraits<bool>::typeName) { out << "nonuniform " << (*static_cast<Field<bool>*>(data.valPtr_)); // static_cast<Field<bool>*>(data.valPtr_)->writeEntry("value",out); } else { out << "ExpressionResult: unknown data type " << data.valType_ << endl; } out << token::END_STATEMENT << nl; } } else { out.writeKeyword("unsetValue"); out << true << token::END_STATEMENT << nl; } out << token::END_BLOCK << endl; return out; }
pythonInterpreterWrapper::pythonInterpreterWrapper ( const objectRegistry& obr, const dictionary& dict, bool forceToNamespace ): generalInterpreterWrapperCRTP<pythonInterpreterWrapper>( obr, dict, forceToNamespace, "python" ), pythonState_(NULL), useNumpy_(dict.lookupOrDefault<bool>("useNumpy",true)), useIPython_(dict.lookupOrDefault<bool>("useIPython",true)), triedIPython_(false), oldIPython_(false) { if(generalInterpreterWrapper::debug>debug) { debug=1; } Pbug << "Starting constructor" << endl; syncParallel(); #ifdef FOAM_HAS_LOCAL_DEBUGSWITCHES debug=dict.lookupOrDefault<label>("debugPythonWrapper",debug()); #else debug=dict.lookupOrDefault<label>("debugPythonWrapper",debug); #endif if(!dict.found("useNumpy")) { WarningIn("pythonInterpreterWrapper::pythonInterpreterWrapper") << "Switch 'useNumpy' not found in " << dict.name() << nl << "Assuming it to be 'true' (if that is not what you want " << "set it. Also set it to make this warning go away)" << endl; } if(!dict.found("useIPython")) { WarningIn("pythonInterpreterWrapper::pythonInterpreterWrapper") << "Switch 'useIPython' not found in " << dict.name() << nl << "Assuming it to be 'true' (if that is not what you want " << "set it. Also set it to make this warning go away)" << endl; } if(interpreterCount==0) { Pbug << "Initializing Python" << endl; Py_Initialize(); if(debug) { PyThreadState *current=PyGILState_GetThisThreadState(); Pbug << "GIL-state before thread" << getHex(current) << endl; } PyEval_InitThreads(); if(debug) { PyThreadState *current=PyGILState_GetThisThreadState(); Pbug << "GIL-state after thread" << getHex(current) << endl; } // importLib("scipy.stats","stats"); - OK mainThreadState = PyEval_SaveThread(); // importLib("scipy.stats","stats"); - segFault Pbug << "Main thread state: " << getHex(mainThreadState) << endl; // PyRun_SimpleString("import IPython\n" // here it works as expected // "IPython.embed()\n"); } if(Pstream::parRun()) { Pbug << "This is a parallel run" << endl; parallelMasterOnly_=readBool(dict.lookup("parallelMasterOnly")); } if(parallelNoRun(true)) { Pbug << "Getting out because of 'parallelNoRun'" << endl; return; } interpreterCount++; Pbug << "Getting new interpreter" << endl; pythonState_=Py_NewInterpreter(); Pbug << "Interpreter state: " << getHex(pythonState_) << endl; // interactiveLoop("Clean"); initIPython(); Pbug << "Currently " << interpreterCount << " Python interpreters (created one)" << endl; if( interactiveAfterExecute_ || interactiveAfterException_ ) { } else { if(useIPython_) { WarningIn("pythonInterpreterWrapper::pythonInterpreterWrapper") << "'useIPython' not needed in " << dict.name() << " if there is no interactivity" << endl; } } if(useNumpy_) { Dbug << "Attempting to import numpy" << endl; static bool warnedNumpy=false; if(!warnedNumpy) { if(getEnv("FOAM_SIGFPE")!="false") { WarningInFunction << "Attempting to import numpy. On some platforms that will raise a " << "(harmless) floating point exception. To avoid switch off " << "by setting the environment variable 'FOAM_SIGFPE' to 'false'" << endl; } warnedNumpy=true; } int fail=!importLib("numpy"); if(fail) { FatalErrorIn("pythonInterpreterWrapper::pythonInterpreterWrapper") << "Problem during import of numpy." << nl << "Switch if off with 'useNumpy false;' if it is not needed" << endl << exit(FatalError); } fail=PyRun_SimpleString( // "def _swak_wrapOpenFOAMField_intoNumpy(address,typestr,size,nr=None):\n" // " class iWrap(object):\n" // " def __init__(self):\n" // " self.__array_interface__={}\n" // " self.__array_interface__['data']=(int(address,16),False)\n" // " if nr:\n" // " self.__array_interface__['shape']=(size,nr)\n" // " else:\n" // " self.__array_interface__['shape']=(size,)\n" // " self.__array_interface__['version']=3\n" // " self.__array_interface__['typestr']=typestr\n" // " return numpy.asarray(iWrap())\n" "class OpenFOAMFieldArray(numpy.ndarray):\n" " def __new__(cls,address,typestr,size,nr=None,names=None):\n" " obj=type('Temporary',(object,),{})\n" " obj.__array_interface__={}\n" " obj.__array_interface__['data']=(address,False)\n" " if nr:\n" " obj.__array_interface__['shape']=(size,nr)\n" " else:\n" " obj.__array_interface__['shape']=(size,)\n" // " obj.__array_interface__['descr']=[('x',typestr)]\n" " obj.__array_interface__['version']=3\n" " obj.__array_interface__['typestr']=typestr\n" " obj=numpy.asarray(obj).view(cls)\n" " if names:\n" " for i,n in enumerate(names):\n" " def f(ind):\n" " return obj[:,ind]\n" " setattr(obj,n,f(i))\n" " return obj\n" " def __array_finalize__(self,obj):\n" " if obj is None: return\n" ); } if(dict.found("importLibs")) { const dictionary &libList=dict.subDict("importLibs"); forAllConstIter(dictionary,libList,iter) { word as=(*iter).keyword(); word full((*iter).stream()); if(full=="") { full=as; } importLib(full,as,true); } } else {
uint32_t operandHandler(char *operand, char *shift, char *reg) { int imm = 0; //set initial values to zero int counter = 0; int rm = 0; int rs = 0; if(operand[0] == '#') { //Operand 2 is an expression immediate = 1 << immediatePos; if(operand[2] == 'x') { imm = getHex(operand + 1); // #0x...hex } else { imm = atoi(operand + 1); //imm = decimal representation } if(imm <= MAX_EIGHT_BIT) { //if immediate is already < 255, no need for rotation return imm; } //rotate while immediate is >255 and the number of rotation is less than 15 while((imm > MAX_EIGHT_BIT && counter < MAX_COUNTER) || (rotateRTwo(imm) <= MAX_EIGHT_BIT && counter < MAX_COUNTER)) { /*if the number have to be rotated to be represented, it will be rotated as much as possible */ imm = rotateRTwo(imm); counter++; } if(imm > MAX_EIGHT_BIT) { // if imm > 255 after rotating more than perror("Error: Number can't be represented"); // 15 times, then the number is not supported exit(EXIT_FAILURE); } counter = 16 - counter; //0 instead of 16 so when counter = 0, it won't be 10000(bin) if(counter == 16) {counter = 0;} counter <<= rotatePos; return (uint32_t)counter + imm; } else { //Operand 2 is a register immediate = 0; if(shift == NULL) { // in cpsr cases return atoi(operand + 1); } int shiftType = 0; rm = atoi(operand + 1); char *shiftname = shift; //separating shift type and reg/const char *exp = reg; if(!strcmp(shiftname, "lsl")) { shiftType = 0; } else if(!strcmp(shiftname, "lsr")) { shiftType = 1 << shiftTypePos; //01 } else if(!strcmp(shiftname, "asr")) { shiftType = 2 << shiftTypePos; //10 } else if(!strcmp(shiftname, "ror")) { shiftType = 3 << shiftTypePos; //11 } else { printf("Shift Type invalid"); } if(exp == NULL) {exp = reg;} if(exp[0] == '#') { if(exp[2] == 'x') { imm = getHex(exp + 1); //get hex value } else { imm = atoi(exp + 1); //get decimal value } imm <<= rotatePos - 1; //integer position when shift by a constant amount } else { shiftType += 1 << (shiftTypePos - 1); rs = atoi(exp + 1); rs <<= rotatePos; //shift specified by register } return rm + rs + shiftType + imm; } }
void GetRexxBlock( ss_block *ss_new, char *start, line *line, linenum line_no ) { line = line; line_no = line_no; if( start[0] == '\0' ) { if( firstNonWS == start ) { // line is empty - // do not flag following line as having anything to do // with an unterminated " or # or // from previous line flags.inString = flags.inPreprocessor = flags.inCPPComment = false; } getBeyondText( ss_new ); return; } if( flags.inCComment ) { getCComment( ss_new, start, 0 ); return; } if( flags.inCPPComment ) { getCPPComment( ss_new, start ); return; } if( flags.inPreprocessor ) { getPreprocessor( ss_new, start ); return; } if( flags.inString ) { getString( ss_new, start, 0 ); return; } if( isspace( start[0] ) ) { getWhiteSpace( ss_new, start ); return; } if( *firstNonWS == '#' && (!EditFlags.PPKeywordOnly || firstNonWS == start) ) { getPreprocessor( ss_new, start ); return; } switch( start[0] ) { case '"': getString( ss_new, start, 1 ); return; case '/': if( start[1] == '*' ) { getCComment( ss_new, start, 2 ); return; } else if( start[1] == '/' ) { getCPPComment( ss_new, start ); return; } break; case '\'': getChar( ss_new, start, 1 ); return; case 'L': if( start[1] == '\'' ) { // wide char constant getChar( ss_new, start, 2 ); return; } break; case '.': if( isdigit( start[1] ) ) { getFloat( ss_new, start, 1, AFTER_DOT ); return; } break; case '0': if( start[1] == 'x' || start[1] == 'X' ) { getHex( ss_new, start ); return; } else { getNumber( ss_new, start, '7' ); return; } break; } if( issymbol( start[0] ) ) { getSymbol( ss_new ); return; } if( isdigit( start[0] ) ) { getNumber( ss_new, start, '9' ); return; } if( isalpha( *start ) || ( *start == '_' ) ) { getText( ss_new, start ); return; } getInvalidChar( ss_new ); }
/* Motorola S-Record reader * Format: * type 2 Bytes (S0, S1, S2, S3, S5, S7, S8, S9) * reclength 2 Bytes * address 4,6,8 Bytes * data 0...2n * checksum 2 Bytes (lsb of 1'comp of fields reclength-data */ static t_stat m68k_sread(FILE* fptr) { int typ; t_addr addr=0, a; int d, len, chksum, i; int end = FALSE; int line = 0; fseek(fptr,0l,SEEK_SET); for(;;) { while ((i = fgetc(fptr)) == '\r' || i == '\n'); line++; if (end && i == EOF) return SCPE_OK; if (i != 'S') { printf("Line %d: expected S but did not find one (found %x)\n",line,i); return SCPE_FMT; } typ = fgetc(fptr); chksum = 0; len = getHex(fptr,&chksum); addr = getHex(fptr,&chksum); a = getHex(fptr,&chksum); if (len==EOF || addr==EOF || a==EOF) { typ = 'X'; goto error; } addr = (addr << 8) | a; i = 3; switch (typ) { case '0': for (i=2; i<len; i++) (void)getHex(fptr,&chksum); break; case '1': i = 2; goto dread; case '3': if ((a = getHex(fptr,&chksum))==EOF) goto error; addr = (addr << 8) | a; i = 4; /*fallthru*/ case '2': if ((a = getHex(fptr,&chksum))==EOF) goto error; addr = (addr << 8) | a; dread: for (; i<len; i++) { d = getHex(fptr,&chksum); WritePB(addr,d); addr++; } break; case '7': if ((a = getHex(fptr,&chksum))==EOF) goto error; addr = (addr << 8) | a; /*fallthru*/ case '8': if ((a = getHex(fptr,&chksum))==EOF) goto error; addr = (addr << 8) | a; /*fallthru*/ case '9': end = TRUE; /*fallthru*/ case '5': if((d = getHex(fptr,&chksum))==EOF) goto error; break; } if ((chksum & 0xff) != 0) return SCPE_CSUM; saved_PC = addr; } error: printf("S%c at line %d: Unexpected EOF/Invalid character\n",typ,line); return SCPE_FMT; }
void GetPerlBlock( ss_block *ss_new, char *start, line *line, linenum line_no ) { line = line; line_no = line_no; if( start[0] == '\0' ) { if( firstNonWS == start ) { // line is empty - // do not flag following line as having anything to do // with an unterminated " or # or // from previous line flags.inString = false; } getBeyondText( ss_new ); return; } if( flags.inString ) { getString( ss_new, start, 0 ); return; } if( isspace( start[0] ) ) { getWhiteSpace( ss_new, start ); return; } switch( start[0] ) { case '#': getPerlComment( ss_new, start ); return; case '"': getString( ss_new, start, 1 ); return; case '/': if( flags.beforeRegExp ) { getRegExp( ss_new, start ); return; } break; case '$': case '@': case '%': if( isalpha( start[1] ) || (start[0] == '$' && start[1] == '#') ) { getVariable( ss_new, start ); return; } else if( start[0] == '$' && (isdigit( start[1] ) || isspecvar( start[1] )) ) { getSpecialVariable( ss_new, start ); return; } break; case '\'': getChar( ss_new, start, 1 ); return; case '.': if( isdigit( start[1] ) ) { getFloat( ss_new, start, 1, AFTER_DOT ); return; } break; case '0': if( start[1] == 'x' || start[1] == 'X' ) { getHex( ss_new, start ); return; } else { getNumber( ss_new, start, '7' ); return; } break; } if( issymbol( start[0] ) ) { getSymbol( ss_new, start ); return; } if( isdigit( start[0] ) ) { getNumber( ss_new, start, '9' ); return; } if( isalpha( *start ) || (*start == '_') ) { getText( ss_new, start ); return; } getInvalidChar( ss_new ); }
bool TextContent::writeToEditCtrl() { if (endoffile_) { return false; } if (textctrl_ == NULL) { return false; } if (position_ > kMaxLength) { endoffile_ = true; return false; } //textctrl_->Clear(); wxFile fs (filepath_); if (!fs.IsOpened()) { if (position_ == 0) { textctrl_->WriteText (msg_no_content); } return false; } fs.Seek (position_); if (fs.Eof()) { endoffile_ = true; return false; } char bbuf[2] = {0,0}; char buf[1000]; ssize_t rcount = 0; wxString line; bool wasLF = false; bool wasCR = false; int numread = 0; int linecount = 0; int cl = 0; wxString tx; if (binary_) do { rcount = fs.Read (bbuf, 1); if (fs.Eof()) { endoffile_ = true; } if (rcount < 1) { endoffile_ = true; } else { if (cl == 0) { textctrl_->WriteText (getFixString (position_ + numread)); textctrl_->WriteText (L" "); textctrl_->WriteText (getHex (bbuf[0])); textctrl_->WriteText (L" "); } else if (cl == 7) { textctrl_->WriteText (getHex (bbuf[0])); textctrl_->WriteText (L" "); } else { textctrl_->WriteText (getHex (bbuf[0])); textctrl_->WriteText (L" "); } if (bbuf[0] < 32 || bbuf[0] > 126) { tx += L"."; } else { tx += (wchar_t)bbuf[0]; } ++cl; if (cl == 16 || endoffile_) { for (int i = 0; i < 16 - cl; ++i) { textctrl_->WriteText (L" "); if (i == 7) { textctrl_->WriteText (L" "); } } cl = 0; textctrl_->WriteText (L" "); textctrl_->WriteText (tx); textctrl_->WriteText (L"\n"); ++linecount; tx.erase(); } ++numread; } if (linecount > kMaxLineCountPerReadBinary || numread >= kMaxLengthPerRead || endoffile_) { position_ += numread; break; } } while (true); else do { rcount = fs.Read (buf, 1000); for (int ix = 0; ix < rcount; ++ix) { ++numread; if (linecount <= kMaxLineCountPerRead && numread <= kMaxLengthPerRead) { if (buf[ix] == 10) { if (!wasCR) { line += L'\n'; textctrl_->WriteText (line); line.erase(); ++linecount; } wasLF = true; wasCR = false; } else if (buf[ix] == 13) { line += L'\n'; textctrl_->WriteText (line); line.erase(); ++linecount; wasLF = false; wasCR = true; } else if (buf[ix] == 9) { line += L" "; wasLF = false; wasCR = false; } else if (buf[ix] < 32 || buf[ix] > 126) { line += L'.'; wasLF = false; wasCR = false; } else { wchar_t wc = buf[ix]; line += wc; wasLF = false; wasCR = false; } if (line.size() > 2000) { line += L'\n'; textctrl_->WriteText (line); line.erase(); ++linecount; } } else { textctrl_->WriteText (line); break; } } if (fs.Eof()) { endoffile_ = true; } if (linecount > kMaxLineCountPerRead || numread <= kMaxLengthPerRead || endoffile_) { position_ += numread; break; } } while (true); // restore text cursor //textctrl_->SetInsertionPoint (oldInsPt); return true; }