int DisassemblyWindow::ReadOnlyEditorX::handle(int Event) { unsigned int LineNumber; string sFileName; FileWindow *pFW; int RetVal = ReadOnlyEditor::handle(Event); switch(Event) { case FL_RELEASE: if(Fl::event_clicks() && Fl::event_button() == FL_LEFT_MOUSE) //Double click { if(!GetFileLine(sFileName, LineNumber)) break; //Open the file TheMainWindow.OpenFile(sFileName); //Highlight the line if(pFW = FileWindow::IsOpen(sFileName)) { pFW->SelectLine(LineNumber); } } if(Fl::event_button() == FL_RIGHT_MOUSE) ((DisassemblyWindow *)parent())->pPopupMenu->popup(); break; } return RetVal; }
int ProgramsWindow::ReadOnlyEditorX::handle(int Event) { unsigned int LineNumber; string sFileName; FileWindow *pFW; int RetVal = ReadOnlyEditor::handle(Event); switch(Event) { case FL_RELEASE: if(Fl::event_clicks()) //Double click { if(!GetFileLine(sFileName, LineNumber)) break; //Open the file TheMainWindow.OpenFile(sFileName); //Highlight the line if(pFW = FileWindow::IsOpen(sFileName)) { pFW->SelectLine(LineNumber); } } break; } return RetVal; }
// int ReadINIFile(char *Fname, RS_232 *COMM232eeee) int ReadINIFile(char *Fname) { FILE *fptr; #define MAXLINE 1000 char Work[MAXLINE]; char *Line; char *Parms = "PORTNUM BAUDRATE NUMEROBIT STOPBIT PARITYBIT"; enum {PORTNUM=1, BAUDRATE, NUMEROBIT, STOPBIT, PARITYBIT} ParmKey; char *KeyName; char *KeyValue; int Rcode = 0; // Set DEFAULT Values if (FileExists(Fname) < 0) { /* if file doesn't exist. Create it (return FileSize */ if (WriteINIFile(Fname) == FALSE) return FALSE; } // ------------------------- // Read the .ini File // ------------------------- if ((fptr = fopen(Fname, "r")) == NULL) { MessageBox(NULL, "Errore nella apertura del File", "Error!", MB_ICONEXCLAMATION | MB_OK); Rcode = FALSE; } /* End if */ while (GetFileLine(Work, MAXLINE, fptr, 'u') != EOF) { Line = CleanString(Work, "=", ' '); /* togli '=' */ KeyName = Word(Line, 1); /* get parameter name */ KeyValue = Word(Line, 2); /* get parameter value */ ParmKey = WordPos(KeyName, Parms); /* get value for switch */ switch (ParmKey) { case PORTNUM: //COMM232->PortNum = atoi(KeyValue); //COMM232->PortName[3] = COMM232->PortNum+'0'; break; case BAUDRATE: //COMM232->BaudRate = atoi(KeyValue); break; case NUMEROBIT: //COMM232->NumeroBits = atoi(KeyValue); break; case STOPBIT: //COMM232->StopBit = atoi(KeyValue); break; case PARITYBIT: //COMM232->ParityBit = atoi(KeyValue); break; default: break; } /* End switch */ } /* End while */ fclose(fptr); /* close file.ini */ return TRUE; }
int RebuildCppInst(OpcodeInfo *theOp) { int ip = theOp->rip; char str[256]; #ifdef CPP_DEBUG str[0] = 0; DisassembleFromSource(ip, str); RebuildEmit("\t\t\t\t\t\t//%s\n", str); #endif #ifdef CPP_SHOW_LINES { int line = ArrayGet(&SLD_Line_Array, ip); int file = ArrayGet(&SLD_File_Array, ip); if(line!=0) { RebuildEmit("\n // %s:%d\n", GetFileNumString(file), line); RebuildEmit(" // %s\n", GetFileLine(file, line)); } } #endif switch (theOp->op) { case _PUSH: RebuildEmit(" //push %s,%d\n",Cpp_reg[theOp->rd], theOp->rs); if (REGUSED(funcprop.reg_used, REG_sp)) { RebuildEmit(" sp -= %d;\n",theOp->rs*4); } return 1; case _POP: RebuildEmit(" //pop %s,%d\n",Cpp_reg[theOp->rd], theOp->rs); if (REGUSED(funcprop.reg_used, REG_sp)) { RebuildEmit(" sp += %d;\n",theOp->rs*4); } return 1; case _CASE: CppDecodeSwitch(theOp); break; case _CALLI: CppDecodeCall(theOp); break; case _SYSCALL: CppDecodeSysCall(theOp); break; case _CALL: CppDecodeCallReg(theOp); break; case _LDI: RebuildEmit(" %s = 0x%x;", Cpp_reg[theOp->rd], theOp->imm); break; case _LDR: { if (IsRegConst(theOp->rs)) RebuildEmit(" %s = 0x%x;", Cpp_reg[theOp->rd], ConstRegValue(theOp->rs)); else RebuildEmit(" %s = %s;", Cpp_reg[theOp->rd], Cpp_reg[theOp->rs]); } break; // Arithmatic case _ADD: CppEmitArith(theOp,"+", 0); break; case _ADDI: CppEmitArith(theOp,"+", 1); break; case _MUL: CppEmitArith(theOp,"*", 0); break; case _MULI: CppEmitArith(theOp,"*", 1); break; case _SUB: CppEmitArith(theOp,"-", 0); break; case _SUBI: CppEmitArith(theOp,"-", 1); break; case _AND: CppEmitArith(theOp,"&", 0); break; case _ANDI: CppEmitArith(theOp,"&", 1); break; case _OR: CppEmitArith(theOp,"|", 0); break; case _ORI: CppEmitArith(theOp,"|", 1); break; case _XOR: CppEmitArith(theOp,"^", 0); break; case _XORI: CppEmitArith(theOp,"^", 1); break; case _DIVU: CppEmitDivu(theOp, 0); break; case _DIVUI: CppEmitDivu(theOp, 1); break; case _DIV: CppEmitArith(theOp,"/", 0); break; case _DIVI: CppEmitArith(theOp,"/", 1); break; // Shifts case _SLL: CppEmitShift(theOp,"<<", 0, 0); break; case _SLLI: CppEmitShift(theOp,"<<", 1, 0); break; case _SRA: CppEmitShift(theOp,">>", 0, 0); break; case _SRAI: CppEmitShift(theOp,">>", 1, 0); break; case _SRL: CppEmitShift(theOp,">>", 0, 1); // Unsigned break; case _SRLI: CppEmitShift(theOp,">>", 1, 1); // Unsigned break; case _NOT: RebuildEmit(" %s = ~%s;", Cpp_reg[theOp->rd], Cpp_reg[theOp->rs]); break; case _NEG: RebuildEmit(" %s = -%s;", Cpp_reg[theOp->rd], Cpp_reg[theOp->rs]); break; case _RET: { if (ThisFunctionExit == 0) // Don't output a return jump on last instruction { RebuildEmit(" goto label_0; // return"); ReturnCount++; } } break; // Conditional jumps case _JC_EQ: CppEmitJumpCond(theOp, "==", 0); break; case _JC_NE: CppEmitJumpCond(theOp, "!=", 0); break; case _JC_GE: CppEmitJumpCond(theOp, ">=", 0); break; case _JC_GEU: CppEmitJumpCond(theOp, ">=", 1); break; case _JC_GT: CppEmitJumpCond(theOp, ">", 0); break; case _JC_GTU: CppEmitJumpCond(theOp, ">", 1); break; case _JC_LE: CppEmitJumpCond(theOp, "<=", 0); break; case _JC_LEU: CppEmitJumpCond(theOp, "<=", 1); break; case _JC_LT: CppEmitJumpCond(theOp, "<", 0); break; case _JC_LTU: CppEmitJumpCond(theOp, "<", 1); break; case _JPI: CppDecodeLabel(theOp, " goto label_%d;"); break; // Memory instructions case _LDW: Cpp_LoadMem(theOp, "RINT"); break; case _LDH: Cpp_LoadMem(theOp, "RSHORT"); break; case _LDB: Cpp_LoadMem(theOp, "RBYTE"); break; case _STW: Cpp_StoreMem(theOp, "WINT"); break; case _STH: Cpp_StoreMem(theOp, "WSHORT"); break; case _STB: Cpp_StoreMem(theOp, "WBYTE"); break; case _XB: RebuildEmit(" %s = (int)((char) %s);", Cpp_reg[theOp->rd], Cpp_reg[theOp->rs]); break; case _XH: RebuildEmit(" %s = (int)((short) %s);", Cpp_reg[theOp->rd], Cpp_reg[theOp->rs]); break; default: str[0] = 0; DisassembleFromSource(ip, str); ErrorOnIP(Error_Fatal, ip, "Missing instruction in Cpp rebuilder '%s'\n", str); } // ArraySet(&SLD_Line_Array, CodeIP, line); // ArraySet(&SLD_File_Array, CodeIP, This_SLD_File); // RebuildEmit("\n"); RebuildEmit("\n"); #ifdef LOG_REGISTER_STATE_CHANGES if (funcprop.reg_used) { /* int n; for (n=0;n<32;n++) { if (reg_used & (1 << n)) { RebuildEmit("if(last_%s != %s) { LOG_REGISTER(%s); last_%s = %s;}\n", Cpp_reg[n], Cpp_reg[n], Cpp_reg[n], Cpp_reg[n], Cpp_reg[n]); } } RebuildEmit(";\n\n"); */ RebuildEmit("\tLOG_REGISTER_STATE_CHANGES(0x%x)\n", funcprop.reg_used); } #endif return 1; }
//DONE vector<string>* GetStringsFileline(ifstream &Input, const char* Delim, bool TreatConsecutiveDelimAsOne) { string Buff = GetFileLine(Input); return StringToStrings(Buff, Delim, TreatConsecutiveDelimAsOne); }
/*---------------------------------------------------------------------------------------------------------------------- | Reads characters from in until a complete token has been read and stored in token. GetNextToken performs a number | of useful operations in the process of retrieving tokens: |~ | o any underscore characters encountered are stored as blank spaces (unless the labile flag bit preserveUnderscores | is set) | o if the first character of the next token is an isolated single quote, then the entire quoted NxsString is saved | as the next token | o paired single quotes are automatically converted to single quotes before being stored | o comments are handled automatically (normal comments are treated as whitespace and output comments are passed to | the function OutputComment which does nothing in the NxsToken class but can be overridden in a derived class to | handle these in an appropriate fashion) | o leading whitespace (including comments) is automatically skipped | o if the end of the file is reached on reading this token, the atEOF flag is set and may be queried using the AtEOF | member function | o punctuation characters are always returned as individual tokens (see the Maddison, Swofford, and Maddison paper | for the definition of punctuation characters) unless the flag ignorePunctuation is set in labileFlags, | in which case the normal punctuation symbols are treated just like any other darkspace character. |~ | The behavior of GetNextToken may be altered by using labile flags. For example, the labile flag saveCommandComments | can be set using the member function SetLabileFlagBit. This will cause comments of the form [&X] to be saved as | tokens (without the square brackets), but only for the aquisition of the next token. Labile flags are cleared after | each application. */ void NxsToken::GetNextToken() { ResetToken(); char ch = ' '; if (saved == '\0' || IsWhitespace(saved)) { // Skip leading whitespace // while( IsWhitespace(ch) && !atEOF) ch = GetNextChar(); saved = ch; } for(;;) { // Break now if singleCharacterToken mode on and token length > 0. // if (labileFlags & singleCharacterToken && token.size() > 0) break; // Get next character either from saved or from input stream. // if (saved != '\0') { ch = saved; saved = '\0'; } else ch = GetNextChar(); // Break now if we've hit EOF. // if (atEOF) break; if (ch == '\n' && labileFlags & newlineIsToken) { if (token.size() > 0) { // Newline came after token, save newline until next time when it will be // reported as a separate token. // atEOL = 0; saved = ch; } else { atEOL = 1; AppendToToken(ch); } break; } else if (IsWhitespace(ch)) { // Break only if we've begun adding to token (remember, if we hit a comment before a token, // there might be further white space between the comment and the next token). // if (token.size() > 0) break; } else if (ch == '_') { // If underscores are discovered in unquoted tokens, they should be // automatically converted to spaces. // if (!(labileFlags & preserveUnderscores)) ch = ' '; AppendToToken(ch); } else if (ch == '[') { // Get rest of comment and deal with it, but notice that we only break if the comment ends a token, // not if it starts one (comment counts as whitespace). In the case of command comments // (if saveCommandComment) GetComment will add to the token NxsString, causing us to break because // token.size() will be greater than 0. comment.clear(); GetComment(); if (token.size() > 0) break; } else if (ch == '(' && labileFlags & parentheticalToken) { AppendToToken(ch); // Get rest of parenthetical token. // GetParentheticalToken(); break; } else if (ch == '{' && labileFlags & curlyBracketedToken) { AppendToToken(ch); // Get rest of curly-bracketed token. // GetCurlyBracketedToken(); break; } else if (ch == '\"' && labileFlags & doubleQuotedToken) { // Get rest of double-quoted token. // GetDoubleQuotedToken(); break; } else if (ch == '\'') { if (token.size() > 0) { // We've encountered a single quote after a token has // already begun to be read; should be another tandem // single quote character immediately following. // ch = GetNextChar(); if (ch == '\'') AppendToToken(ch); else { errormsg = "Expecting second single quote character"; throw NxsException( errormsg, GetFilePosition(), GetFileLine(), GetFileColumn()); } } else { // Get rest of quoted NEXUS word and break, since // we will have eaten one token after calling GetQuoted. // GetQuoted(); } break; } else if (IsPunctuation(ch)) { if (token.size() > 0) { // If we've already begun reading the token, encountering // a punctuation character means we should stop, saving // the punctuation character for the next token. // saved = ch; break; } else { // If we haven't already begun reading the token, encountering // a punctuation character means we should stop and return // the punctuation character as this token (i.e., the token // is just the single punctuation character. // AppendToToken(ch); break; } } else { AppendToToken(ch); } } labileFlags = 0; }
/*---------------------------------------------------------------------------------------------------------------------- | Reads rest of comment (starting '[' already input) and acts accordingly. If comment is an output comment, and if | an output stream has been attached, writes the output comment to the output stream. Otherwise, output comments are | simply ignored like regular comments. If the labileFlag bit saveCommandComments is in effect, the comment (without | the square brackets) will be stored in token. */ void NxsToken::GetComment() { // Set comment level to 1 initially. Every ']' encountered reduces // level by one, so that we know we can stop when level becomes 0. // int level = 1; // Get first character // char ch = GetNextChar(); if (atEOF) { errormsg = "Unexpected end of file inside comment"; throw NxsException( errormsg, GetFilePosition(), GetFileLine(), GetFileColumn()); } // See if first character is the output comment symbol ('!') // or command comment symbol (&) // int printing = 0; int command = 0; if (ch == '!') printing = 1; else if (ch == '&' && labileFlags & saveCommandComments) { command = 1; AppendToToken(ch); } else if (ch == ']') return; // Now read the rest of the comment // for(;;) { ch = GetNextChar(); if (atEOF) break; if (ch == ']') level--; else if (ch == '[') level++; if (level == 0) break; if (printing) AppendToComment(ch); else if (command) AppendToToken(ch); } if (printing) { // Allow output comment to be printed or displayed in most appropriate // manner for target operating system // OutputComment(comment); } }