void DlgCompareDir::DoTreeCursor() { String s = GetTreePath(); if(IsNull(s)) return; String fa = AppendFileName(pa, s), fb = AppendFileName(pb, s); String da = LoadFile(fa), db = LoadFile(fb); if(!IsNull(da) || !IsNull(db)) { if(IsNull(da) || IsNull(db)) { qtf.Hide(); lineedit.Show(); lineedit <<= Nvl(db, da); } else { lineedit.Hide(); qtf.Show(); String comptext = "[C2 "; Vector<String> la = GetStringLineMap(da), lb = GetStringLineMap(db); Array<TextSection> sections = CompareLineMaps(la, lb); for(int s = 0; s < sections.GetCount(); s++) { const TextSection& sec = sections[s]; if(sec.same) { comptext << "[@(0.0.0) \1"; if(sec.count1 <= 6) for(int i = 0; i < sec.count1; i++) comptext << ExpandTabs(la[i + sec.start1]) << '\n'; else { for(int i = 0; i < 3; i++) comptext << ExpandTabs(la[i + sec.start1]) << '\n'; comptext << "...\n"; for(int i = -3; i < 0; i++) comptext << ExpandTabs(la[i + sec.start1 + sec.count1]) << '\n'; } comptext << "\1]"; } else { if(sec.count1) { comptext << "[@(0.160.0) \1"; for(int i = 0; i < sec.count1; i++) comptext << ExpandTabs(la[sec.start1 + i]) << '\n'; comptext << "\1]"; } if(sec.count2) { comptext << "[@(0.0.255) \1"; for(int i = 0; i < sec.count2; i++) comptext << ExpandTabs(lb[sec.start2 + i]) << '\n'; comptext << "\1]"; } } } qtf.SetQTF(comptext); } } }
char* EditToWhitespace(char *p_pszEdit) { int iI; /* work integer */ char pszLine[MAXLINE]; /* source line */ char pszWork[WORKSZ]; /* work buffer */ if (p_pszEdit == NULL) /* q. null request? */ return AMSG; /* a. yes .. return display message */ strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ ExpandTabs(pszLine, pszWork, gaiPlainTabs); /* expand the tabs */ strncpy(gszOutput, pszWork, MAXLINE-1); /* copy the line back */ for (iI = strlen(gszOutput); iI--;) /* look at each character */ { if (*(gszOutput + iI) <= ' ') /* q. space or less? */ *(gszOutput + iI) = 0; /* a. yes .. remove it */ else /* otherwise */ break; /* .. done. Leave loop. */ } return gszOutput; /* ... return buffer */ }
char *EditToAsm (char* p_pszEdit) /* convert line to 1130 assembler */ { char pszLine[MAXLINE]; /* source line */ char pszWork[WORKSZ]; /* work buffer */ char acTFWrk[2]; /* tag/format work area */ size_t iI; /* work integer */ if (p_pszEdit == NULL) /* q. null request? */ return AMSG; /* a. yes .. return display message */ if (*p_pszEdit == '!') /* leave lines starting with ! alone */ return EditToWhitespace(p_pszEdit+1); if (*p_pszEdit == '*') /* q. comment line? */ { /* a. yes.. */ strncpy(pszWork, EditToWhitespace(p_pszEdit), MAXLINE); /* .. convert any tabs */ sprintf(gszOutput, ACOMMENTFMT, pszWork); /* .. put the comment out there in the opcode column */ return gszOutput; /* .. and return it */ } strncpy(pszLine, p_pszEdit, MAXLINE-1); /* copy the line local */ ExpandTabs(pszLine, pszWork, gaiAsmTabs); /* expand the tabs */ strncpy(pszLine, pszWork, MAXLINE-1); /* copy the line back */ for (iI = strlen(pszLine); iI--;) /* trim trailing whitespace */ { if (*(pszLine + iI) <= ' ') /* q. space or less? */ *(pszLine + iI) = 0; /* a. yes .. remove it */ else /* otherwise */ break; /* .. done. Leave loop. */ } if (strlen(pszLine) == 0) /* q. blank line? */ { /* a. yes .. Assembler abhors these so */ sprintf(gszOutput, ABLANKLINE); /* format as comment statement */ return gszOutput; /* .. and return it */ } /* TODO: Add code to process a strip switch * comment? */ if (strlen(pszLine) > (TAGOFFSET + 1)) /* q. line long enough? */ { /* a. yes.. reorder tag/format */ memcpy(acTFWrk, pszLine + FMTOFFSET, 2); /* get tag/format */ memset((pszLine + FMTOFFSET), ' ', 2); /* .. blank 'em out */ for (iI = 0; iI < 2; iI ++) if (isalpha(acTFWrk[iI])) /* q. alpha char? */ *(pszLine + FMTOFFSET) = acTFWrk[iI]; /* a. yes .. make it format */ else if (isdigit(acTFWrk[iI])) /* q. digit? */ *(pszLine + TAGOFFSET) = acTFWrk[iI]; /* a. yes .. make it the tag */ } sprintf(gszOutput, AFORMAT, pszLine); /* format the line */ return gszOutput; /* return formatted line */ }
OGRFeature *OGRSEGP1Layer::GetNextRawFeature() { if( bEOF ) return nullptr; const char* pszLine = nullptr; while( true ) { pszLine = CPLReadLine2L(fp,81,nullptr); if (pszLine == nullptr || STARTS_WITH_CI(pszLine, "EOF")) { bEOF = true; return nullptr; } int nLineLen = static_cast<int>(strlen(pszLine)); while(nLineLen > 0 && pszLine[nLineLen-1] == ' ') { ((char*)pszLine)[nLineLen-1] = '\0'; nLineLen --; } char* pszExpandedLine = ExpandTabs(pszLine); pszLine = pszExpandedLine; nLineLen = static_cast<int>(strlen(pszLine)); OGRFeature* poFeature = new OGRFeature(poFeatureDefn); poFeature->SetFID(nNextFID ++); OGRGeometry* poGeom = nullptr; if (nLatitudeCol-1 + 19 <= nLineLen) { char szDeg[3+1]; char szMin[2+1]; char szSec[4+1]; ExtractField(szDeg, pszLine, nLatitudeCol-1, 2); ExtractField(szMin, pszLine, nLatitudeCol+2-1, 2); ExtractField(szSec, pszLine, nLatitudeCol+2+2-1, 4); double dfLat = atoi(szDeg) + atoi(szMin) / 60.0 + atoi(szSec) / 100.0 / 3600.0; if (pszLine[nLatitudeCol+2+2+4-1] == 'S') dfLat = -dfLat; poFeature->SetField(SEGP1_FIELD_LATITUDE, dfLat); ExtractField(szDeg, pszLine, nLatitudeCol+9-1, 3); ExtractField(szMin, pszLine, nLatitudeCol+9+3-1, 2); ExtractField(szSec, pszLine, nLatitudeCol+9+3+2-1, 4); double dfLon = atoi(szDeg) + atoi(szMin) / 60.0 + atoi(szSec) / 100.0 / 3600.0; if (pszLine[nLatitudeCol+9+3+2+4-1] == 'W') dfLon = -dfLon; poFeature->SetField(SEGP1_FIELD_LONGITUDE, dfLon); if (!bUseEastingNorthingAsGeometry) poGeom = new OGRPoint(dfLon, dfLat); } /* Normal layout -> extract other fields */ if (nLatitudeCol == 27 && nLineLen >= 26-1+1) { char szLineName[16 + 1]; ExtractField(szLineName, pszLine, 2-1, 16); int i = 15; while (i >= 0) { if (szLineName[i] == ' ') szLineName[i] = '\0'; else break; i --; } poFeature->SetField(SEGP1_FIELD_LINENAME, szLineName); char szPointNumber[8+1]; ExtractField(szPointNumber, pszLine, 18-1, 8); poFeature->SetField(SEGP1_FIELD_POINTNUMBER, atoi(szPointNumber)); char szReshootCode[1+1]; ExtractField(szReshootCode, pszLine, 26-1, 1); poFeature->SetField(SEGP1_FIELD_RESHOOTCODE, szReshootCode); if (nLineLen >= 61) { char szEasting[8+1]; ExtractField(szEasting, pszLine, 46-1, 8); double dfEasting = CPLAtof(szEasting); poFeature->SetField(SEGP1_FIELD_EASTING, dfEasting); char szNorthing[8+1]; ExtractField(szNorthing, pszLine, 54-1, 8); double dfNorthing = CPLAtof(szNorthing); poFeature->SetField(SEGP1_FIELD_NORTHING, dfNorthing); if (bUseEastingNorthingAsGeometry) poGeom = new OGRPoint(dfEasting, dfNorthing); } if (nLineLen >= 66) { char szDepth[5+1]; ExtractField(szDepth, pszLine, 62-1, 5); double dfDepth = CPLAtof(szDepth); poFeature->SetField(SEGP1_FIELD_DEPTH, dfDepth); } } if (poGeom) { if (poSRS) poGeom->assignSpatialReference(poSRS); poFeature->SetGeometryDirectly(poGeom); } CPLFree(pszExpandedLine); return poFeature; } }
int OpenDocument( WORD mode, WORD type, int doc, LPSTR FileName, int dupView, int Preference, BOOL bUserActivated ) /*++ Routine Description: This routine is used to create a new document or to duplicate the view of an existing document. Arguments: mode - Supplies MODE_DUPLICATE if the document is to be duplicated MODE_RELOAD if the file is to be reloaded MODE_CREATE if the document is to be created type - Supplies the document type doc - Supplies FileName - Supplies a pointer to the name of the file for the document dupView - Supplies the view to be duplicated (mode == MODE_DUPLICATE) Preference - Supplies the view preference (-1 if none) bUserActivated - Indicates whether this action was initiated by the user or by windbg. The value is to determine the Z order of any windows that are opened. Return Value: -1 on failure view number on success (>= 0) return-value - Description of conditions needed to return value. - or - --*/ { LPLINEREC pl; int nView = 0; BOOL create; int n; int language; LPDOCREC d; LPVIEWREC views; // // In mode duplicate, we create a new nView being a copy of the previous // nView of the same document // if (mode == MODE_DUPLICATE) { // // Search a free entry for the nView we will create // if ( (Preference != -1) && Views[ Preference ].Doc == -1 ) { nView = Preference; } else { for (nView = 0; (nView < MAX_VIEWS) && (Views[nView].Doc != -1); nView++); } if (nView == MAX_VIEWS) { ErrorBox(ERR_Too_Many_Opened_Views); return -1; } // // Copy parameters from previous nView // Assert( Docs[Views[dupView].Doc].FirstView >= 0); // // Find the last nView for this document // n = dupView; while (Views[n].NextView != -1) { n = Views[n].NextView; } Assert(n < MAX_VIEWS); // // Attach new nView to last one found // Views[nView] = Views[n]; Views[n].NextView = nView; Views[nView].hwndClient = NULL; // // // Views[nView].iYTop = Views[dupView].iYTop; // // Enlist nView in window menu // AddWindowMenuItem(Views[dupView].Doc, nView); return nView; } else if (mode == MODE_RELOAD) { nView = Docs[doc].FirstView; } // // First search a free entry for the document // if (mode != MODE_RELOAD) { for (doc = 0; (doc < MAX_DOCUMENTS) && (Docs[doc].FirstView != -1); doc++); } if (doc >= MAX_DOCUMENTS) { ErrorBox(ERR_Too_Many_Opened_Documents); return -1; } d = &Docs[doc]; if (type == DOC_WIN) { // // Check if file is not already loaded // if (mode == MODE_RELOAD) { DestroyDocument(doc); language = SetLanguage(doc); } else { if (FileName != NULL) { TCHAR szAbsolutePath[_MAX_PATH] = {0}; Assert(sizeof(szAbsolutePath) == sizeof(d->szFileName)); // We may have a relative path name to a file. Try to get the absolute path. if ( _fullpath(szAbsolutePath, FileName, sizeof(szAbsolutePath) ) ) { // success _tcscpy(d->szFileName, szAbsolutePath); } else { // error. Use as is. _tcscpy(d->szFileName, FileName); } for (n = 0; n < MAX_DOCUMENTS; n++) { if (Docs[n].FirstView != -1 && _strcmpi(Docs[n].szFileName, d->szFileName) == 0) { SetMessageText_StatusBar(ERR_File_Already_Loaded, STATUS_INFOTEXT, FileName); MessageBeep(0); // // Reactivate window // //SendMessage(g_hwndMDIClient, WM_MDIACTIVATE, (WPARAM) Views[Docs[n].FirstView].hwndFrame, 0L); ActivateMDIChild(Views[Docs[n].FirstView].hwndFrame, bUserActivated); return -1; } } language = SetLanguage(doc); } else { // shouldn't happen anymore Assert(0); // BUGBUG - dead code - kcarlos #if 0 // // Initialize document record and first nView // register int i, j; for (i = 0; i < MAX_DOCUMENTS; i++) { CreateUntitled(d->FileName, i + 1); for (j = 0; j < MAX_DOCUMENTS; j++) { if (j != doc && _strcmpi (d->szFileName, Docs[j].szFileName) == 0) { break; } } if (j >= MAX_DOCUMENTS) { break; } } language = C_LANGUAGE; #endif } } } else { WORD winTitle; char rgch[MAX_MSG_TXT]; language = NO_LANGUAGE; // // Non Document type, Load window title from ressource // switch (type) { case DISASM_WIN: winTitle = SYS_DisasmWin_Title; break; case COMMAND_WIN: winTitle = SYS_CmdWin_Title; break; case MEMORY_WIN: winTitle = SYS_MemoryWin_Title; break; default: Assert(FALSE); return -1; break; } Dbg(LoadString(g_hInst, winTitle, rgch, MAX_MSG_TXT)); RemoveMnemonic(rgch, d->szFileName); if (type == MEMORY_WIN) { lstrcat (d->szFileName,"("); lstrcat (d->szFileName,TempMemWinDesc.szAddress); lstrcat (d->szFileName,")"); } } // // Then search a free entry for the first nView we will create // if (mode != MODE_RELOAD) { if ( (Preference != -1) && Views[ Preference ].Doc == -1 ) { nView = Preference; } else { for (nView = 0; nView < MAX_VIEWS && Views[nView].Doc != -1; nView++); } if (nView == MAX_VIEWS) { ErrorBox(ERR_Too_Many_Opened_Views); return -1; } } // // Check if file exist // if (mode == MODE_CREATE || type != DOC_WIN) { create = TRUE; } else { if (mode == MODE_OPEN || FileExist(FileName)) { create = FALSE; } else { if (mode == MODE_OPENCREATE) { // Tell the user that the file does not exist. // kcarlos // BUGBUG // Quick hack. To fix a bug, hopefully this all disappear soon. VarMsgBox(hwndFrame, SYS_Does_Not_Exist_Create, MB_OK, FileName); return -1; } else { create = FALSE; } } } d->readOnly = FALSE; d->docType = type; d->language = (WORD) language; d->untitled = (FileName == NULL); d->ismodified = FALSE; if (create) { LPBLOCKDEF pb; // // Initialize the file with a null-string // d->LastBlock = d->FirstBlock = (LPBLOCKDEF)DocAlloc(sizeof(BLOCKDEF)); GetSystemTimeAsFileTime(&d->time); if (d->FirstBlock == NULL) { ErrorBox(SYS_Allocate_Memory); return -1; } pb = d->FirstBlock; // // Initialize first block // pb->PrevBlock = pb->NextBlock = NULL; pb->LastLineOffset = 0; // // Initialize first line // pl = (LPLINEREC)pb->Data; pl->PrevLength = 0; pl->Length = LHD; pl->Status = 0; d->NbLines = 1; // We start with one null line } else { // // Load the file and check if it's a valid one // if (!LoadFile(doc)) { return -1; } } // // Initialize current pointers // d->CurrentBlock = d->FirstBlock; d->CurrentLine = 0; d->CurrentLineOffset = 0; pl = (LPLINEREC)(d->FirstBlock->Data); ExpandTabs(&pl); // // Undo/redo part // d->undo.h = 0; d->redo.h = 0; d->playCount = REC_CANNOTUNDO; if (g_contGlobalPreferences_WkSp.m_dwUndoResize == 0 || type != DOC_WIN) { d->recType = REC_STOPPED; } else { d->recType = REC_UNDO; } CreateRecBuf(doc, REC_UNDO, g_contGlobalPreferences_WkSp.m_dwUndoResize); if (mode == MODE_RELOAD) { RefreshWindowsTitle(doc); } else { // // Initialize nView part // views = &Views[nView]; views->NextView = -1; views->X = views->Y = 0; views->hwndClient = views->hwndFrame = NULL; views->hScrollBar = g_contGlobalPreferences_WkSp.m_bHorzScrollBars; views->vScrollBar = g_contGlobalPreferences_WkSp.m_bVertScrollBars; views->scrollFactor = 0; views->iYTop = -1; // // Everything is OK, add title in window menu and return the nView // d->FirstView = nView; views->Doc = doc; AddWindowMenuItem(doc, nView); } // // Check syntax if C // if (d->language == C_LANGUAGE) { d->lineTop = 0; d->lineBottom = d->NbLines; CheckSyntax(doc); } return nView; } // OpenDocument()
void CWedDoc::Serialize(CArchive& ar, const char *docname) { CString num, str; CString filename = docname; PathToFname(filename); if (ar.IsStoring()) { // Writing CWaitCursor cursor; POSITION pos; pos = strlist.GetHeadPosition(); origlines = 0; while(TRUE) { CString line; if(!(origlines % 100)) { num.Format("Writing %s line %d", filename, origlines); message(num); } origlines++; if (!pos) break; line = strlist.GetNext(pos); // Obey tab save option if(Tab2Space || spaceify) ExpandTabs(line); // Dispose space from EOL line.TrimRight(); // Write out to file ar.WriteString(line); // Do end of line according to settings if(unix) ar.WriteString("\n"); else ar.WriteString("\r\n"); } num.Format("Wrote %s", filename); message(num); // If user decides to save, save undo/redo info as well SaveUndo(); SaveRedo(); } else { // Reading CWaitCursor cursor; char buff[DETECTSIZE]; strlist.RemoveAll(); // Determine file type CFile* fp = ar.GetFile(); int rlen = fp->Read(buff, DETECTSIZE); // File without a newline ---> default to DOS if(!strstr(buff, "\n")) unix = FALSE; else if (strstr(buff, "\r\n")) unix = FALSE; else unix = TRUE; // Take a wild guess for tabs if(!strstr(buff, "\t") && rlen > DETECTSIZE/2 ) { spaceify = TRUE; } // Start over on file fp->Seek(0,CFile::begin); origlines = 0; // Load file while(TRUE) { str = ""; if(!(origlines % 100)) { CString num; num.Format("Reading %s line %d", filename, origlines); message(num); } if(YieldToWinEx()) { readonly = TRUE; AfxMessageBox("Aborted load, partial buffer is readonly."); break; } TRY { if(!ar.ReadString(str)) break; } CATCH_ALL(ee); END_CATCH_ALL origlines++; TRY { strlist.AddTail(str); } CATCH(CMemoryException, ee) { //P2N("Memory exception\r\n"); break; } END_CATCH } // So unix can see an unlocked file // Let others see it // ReleaseFile(fp, 1); // Patch things up if( strlist.IsEmpty()) { //P2N("Empty file\r\n"); strlist.AddTail(""); } } }