TFile *SearchFile(char *catalog_name, char *file_to_search, int *catalog_counter, int *file_counter, TFile *file_list) { DIR *current_catalog; struct dirent *current_element; char *current_way = NULL; static int flag = TRUE; static int count = 0; current_catalog = opendir(catalog_name); while ((current_element = readdir(current_catalog)) != NULL && flag) { if ((strcmp(current_element->d_name,"..") != 0) && (strcmp(current_element->d_name,".") != 0)) { current_way = EditAdress(current_way, catalog_name, current_element->d_name); if (opendir(current_way) != NULL) { (*catalog_counter)++; file_list = SearchFile(current_way, file_to_search, catalog_counter, file_counter, file_list); } else { printf("%s\n", current_way); (*file_counter)++; if (strcmp(current_element->d_name, file_to_search) == 0) { file_list = AddToList(file_list, current_way); count++; } } } } return file_list; }
int main(int argc, char *argv[]) { char *way_to_file; char *parent_catalog = NULL; int catalog_counter = 1, file_counter = 0; TFile *file_list = NULL; //check for errors, if found - exit program if (CheckErrors(argc, argv)) return 1; //edit parent path(if the last letter = '/' - delete it parent_catalog = EditArgv(parent_catalog, argv[1]); //recursive function of searching file. if file wasn`t found - exit if ((file_list = SearchFile(parent_catalog, argv[2], &catalog_counter, &file_counter, file_list)) == NULL) { fprintf(stderr, "%s: Such file not found...\n", argv[1]); return 0; } //print the information about file PrintFile(way_to_file, argv[2], catalog_counter, file_counter); while(file_list != NULL) { printf("\n%s\n", file_list->path); file_list = file_list->next; } return 0; }
void __fastcall TfrmOpenFTPDialog::menuSearchFileClick(TObject *Sender) { if(tvFolder->Selected == NULL) return; frmSearchFile->chkSearchChildDir->Checked = Recursion; if(frmSearchFile->ShowModal() != mrOk) return; Recursion = frmSearchFile->chkSearchChildDir->Checked; Screen->Cursor = crHourGlass; lvFiles->Items->Clear(); lvFiles->Hide(); TList * NodeList = new TList; TStringList * PathList = new TStringList; GetSelectedNodes(tvFolder->Items->GetFirstNode(),NodeList); for(int n = 0;n < NodeList->Count;n++) { CreateListPaths((TTreeNode *)NodeList->Items[n],PathList,Recursion); } for(int n = 0;n < PathList->Count;n++) { SearchFile(PathList->Strings[n],"",0); } delete PathList; delete NodeList; lvFiles->Show(); Screen->Cursor = crDefault; }
search_result DIPENTRY DIPImpAddrCue( imp_image_handle *ii, imp_mod_handle im, address addr, imp_cue_handle *ic ) { cv_directory_entry *cde; cv_sst_src_module_header *hdr; unsigned_32 *files; virt_mem file_base; unsigned num_files; unsigned file_idx; addr_off best_offset; unsigned file_tab_size; search_result rc; cde = FindDirEntry( ii, im, sstSrcModule ); if( cde == NULL ) return( SR_NONE ); hdr = VMBlock( ii, cde->lfo, sizeof( *hdr ) ); if( hdr == NULL ) return( SR_NONE ); ic->im = im; num_files = hdr->cFile; file_tab_size = num_files * sizeof( unsigned_32 ); hdr = VMBlock( ii, cde->lfo, sizeof( *hdr ) + file_tab_size ); files = __alloca( file_tab_size ); memcpy( files, &hdr->baseSrcFile[0], file_tab_size ); best_offset = (addr_off)-1UL; for( file_idx = 0; file_idx < num_files; ++file_idx ) { file_base = files[file_idx] + cde->lfo; rc = SearchFile( ii, addr, ic, file_base, cde, &best_offset ); if( rc != SR_FAIL ) return( rc ); /* see comment in SearchFile above */ } if( best_offset == (addr_off)-1UL ) return( SR_NONE ); return( SR_CLOSEST ); }
int main(int argc, char *argv[]){ if(argc != 3){ Usage(argv[0]); exit(1); } if(SearchFile(argv[1], argv[2]) == -1){ perror("Error on running search!"); exit(1); } return EXIT_SUCCESS; }
static void SearchFile(const TCHAR * path, const TCHAR * filter, TCHAR** list, int* index) { WIN32_FIND_DATA find_data; HANDLE hFind; TCHAR search_path[_MAX_PATH] = _T(""); TCHAR next_path[_MAX_PATH] = _T(""); TCHAR file_name[_MAX_PATH] = _T(""); BOOL result; size_t last_index = _tcslen(path) - 1; if (path[last_index] == _T('\\') || path[last_index] == _T('/')) _stprintf(search_path, _T("%s*.*"), path); else _stprintf(search_path, _T("%s\\*.*"), path); hFind = FindFirstFile(search_path, &find_data); result = (hFind != INVALID_HANDLE_VALUE); while (result) { if (_tcscmp(find_data.cFileName, _T(".")) && _tcscmp(find_data.cFileName, _T(".."))) { if (path[last_index] == _T('\\') || path[last_index] == _T('/')) _stprintf(file_name, _T("%s%s"), path, find_data.cFileName); else _stprintf(file_name, _T("%s\\%s"), path, find_data.cFileName); if (find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { _stprintf(next_path, _T("%s\\"), file_name); SearchFile(next_path, filter, list, index); } else { if (_tcsicmp(filter, _T("*.*")) == 0) { TCHAR* ptr = malloc(sizeof(TCHAR) * MAX_PATH); _stprintf(ptr, _T("%s"), file_name); list[(*index)++] = ptr; } else { TCHAR ext_name[_MAX_PATH] = _T(""); _stprintf(ext_name, _T("*.%s"), GetFileExtName(file_name)); if (_tcsicmp(ext_name, filter) == 0) { TCHAR* ptr = malloc(sizeof(TCHAR) * MAX_PATH); _stprintf(ptr, _T("%s"), file_name); list[(*index)++] = ptr; } } } } result = FindNextFile(hFind, &find_data); } FindClose(hFind); }
//根据后缀名,返回一个文件夹下的所有名称 vector<string> & AutoSearchFile::GetAllFiles(const string& path_, const string& postfix) { if( m_strPrePath != path_ ) { m_strPrePath = path_; SearchFile(path_, postfix); } return _co_file; }
NAMESPACE_UPP #ifdef PLATFORM_POSIX bool GetBatteryStatus(bool &discharging, int &percentage, int &remainingMin) { /* This is only if acpi package is present StringParse data = Sys("acpi -V"); data.GoAfter("AC Adapter", ":"); String sacStatus = data.GetText(); discharging = sacStatus != "on-line"; data.GoInit(); data.GoAfter("Battery", ":"); data.GoAfter(","); percentage = data.GetInt("%"); data.GoAfter(","); String remaining; if (discharging) { remaining = data.GetText(" "); int hour, min; double secs; StringToHMS(remaining, hour, min, secs); // It is really days:hour:min in this case remainingMin = int(secs) + min*60 + hour*24*60; } else remainingMin = Null; */ percentage = 100; Array<String> files = SearchFile("/proc/acpi/battery", "state"); if (files.GetCount() == 0) return false; StringParse state = LoadFile_Safe(files[0]); if (state == "") return false; bool present; if(!state.GoAfter_Init("present", ":")) return false; present = state.GetText() == "yes"; if (!present) return false; // No battery inserted state.GoAfter_Init("charging state", ":"); discharging = state.GetText() == "discharging"; int presentRate, remainingCapacity; state.GoAfter_Init("present rate", ":"); presentRate = state.GetInt(); state.GoAfter_Init("remaining capacity", ":"); remainingCapacity = state.GetInt(); if (presentRate == 0 || !discharging) remainingMin = Null; else remainingMin = (int)((60.*remainingCapacity)/presentRate); int designCapacity,lastFullCapacity; String vendor, type, model, serial; if (!GetBatteryInfo(present/*, designCapacity, lastFullCapacity, vendor, type, model, serial*/)) percentage = (int)((100.*remainingCapacity)/lastFullCapacity); return true; }
STDMETHODIMP CDevAssistCOM::GetFilePath(BSTR pFileName, BSTR* lFilePath_o, LONG* lStatus_o) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); TCHAR FilePath[MAX_PATH]; *lStatus_o = SearchFile( pFileName, MAX_PATH, FilePath ); if( BRIDGE_SUCCESS == *lStatus_o ) { *lFilePath_o = SysAllocString( FilePath ); } return S_OK; }
gboolean CertUtil_FindCert(const gchar *certFile, // IN const gchar *certDir, // IN const gchar *hash, // IN int *num, // OUT int *last) // OUT { gboolean ret = FALSE; const GList *node; GList *list = NULL; gchar *path = NULL; *last = *num = -1; if (!SearchFile(certDir, hash, &list)) { goto exit; } ret = TRUE; if (!list) { goto exit; } /* *last = the highest file version */ node = g_list_last(list); *last = GPOINTER_TO_INT(node->data); for (node = g_list_first(list); node; node = g_list_next(node)) { gboolean same = FALSE; int ext = GPOINTER_TO_INT(node->data); g_free(path); path = CertUtil_CreateCertFileName(certDir, hash, ext); if (!CompareFile(certFile, path, &same)) { ret = FALSE; goto exit; } if (same) { *num = ext; break; } } exit: g_free(path); if (list) { g_list_free(list); } return ret; }
void ClassBuffer::Search (const char* path) { struct stat filestats; if (IsADirectory(path, filestats)) { if (_recursive) { SearchDirs(path); } else { SearchDir(path); } } else if (HeaderFile(path) || (_CPlusPlusFiles && CPlusPlusFile(path))) { SearchFile(path, filestats); } }
static void SearchFolder(const char *szFolderPath) { char szFilePath[1024]; WIN32_FIND_DATA wfd; HANDLE hFind; char *lpFilePath; strcpy(szFilePath, szFolderPath); lpFilePath = szFilePath + strlen(szFolderPath); if (*(lpFilePath - 1) == '\\') { lpFilePath --; } strcpy(lpFilePath, "\\*"); lpFilePath ++; hFind = FindFirstFile(szFilePath, &wfd); if (hFind != INVALID_HANDLE_VALUE) { strcpy(lpFilePath, wfd.cFileName); SearchFile(szFilePath, wfd); while (FindNextFile(hFind, &wfd)) { strcpy(lpFilePath, wfd.cFileName); SearchFile(szFilePath, wfd); } } FindClose(hFind); }
void OpenIncludeFile (const char* Name, InputType IT) /* Open an include file and insert it into the tables. */ { char* N; FILE* F; IFile* IF; /* Check for the maximum include nesting */ if (CollCount (&AFiles) > MAX_INC_NESTING) { PPError ("Include nesting too deep"); return; } /* Search for the file */ N = SearchFile ((IT == IT_SYSINC)? SysIncSearchPath : UsrIncSearchPath, Name); if (N == 0) { PPError ("Include file `%s' not found", Name); return; } /* Search the list of all input files for this file. If we don't find * it, create a new IFile object. */ IF = FindFile (N); if (IF == 0) { IF = NewIFile (N, IT); } /* We don't need N any longer, since we may now use IF->Name */ xfree (N); /* Open the file */ F = fopen (IF->Name, "r"); if (F == 0) { /* Error opening the file */ PPError ("Cannot open include file `%s': %s", IF->Name, strerror (errno)); return; } /* Debugging output */ Print (stdout, 1, "Opened include file `%s'\n", IF->Name); /* Allocate a new AFile structure */ (void) NewAFile (IF, F); }
int __stdcall CompressFolder(const TCHAR* path, const TCHAR* zip_filename) { int i; int status = 1; int index = 0; TCHAR* list[0xefff]; SearchFile(path, _T("*.*"), list, &index); if (index > 0) status = zipfile(zip_filename, index, list, path); //release the memory for (i = 0; i < index; ++i) free(list[i]); return (status == 0); }
bool GetBatteryInfo(bool &present/*, int &designCapacity, int &lastFullCapacity, String &vendor, String &type, String &model, String &serial*/) { Array<String> files = SearchFile("/proc/acpi/battery", "info"); if (files.GetCount() == 0) return false; StringParse info = LoadFile_Safe(files[0]); if (info == "") return false; info.GoAfter_Init("present", ":"); present = info.GetText() == "yes"; /* info.GoAfter_Init("design capacity", ":"); designCapacity = info.GetInt(); info.GoAfter_Init("last full capacity", ":");lastFullCapacity = info.GetInt(); info.GoAfter_Init("OEM info", ":"); vendor = info.GetText(); info.GoAfter_Init("battery type", ":"); type = info.GetText(); info.GoAfter_Init("model number", ":"); model = info.GetText(); info.GoAfter_Init("serial number", ":"); serial = info.GetText(); */ return true; }
bool SearchFile(const char * searchpath, const char * searched_filename, char * outfilepath) { struct stat st; DIR_ITER *dir = NULL; bool result = false; char filename[1024]; char pathptr[strlen(searchpath)+1]; snprintf(pathptr, sizeof(pathptr), "%s", searchpath); if(pathptr[strlen(pathptr)-1] == '/') { pathptr[strlen(pathptr)-1] = '\0'; } dir = diropen(pathptr); if(!dir) return false; while (dirnext(dir,filename,&st) == 0 && result == false) { if(strcasecmp(filename, searched_filename) == 0) { if(outfilepath) { sprintf(outfilepath, "%s/%s", pathptr, filename); } result = true; } else if((st.st_mode & S_IFDIR) != 0) { if(strcmp(filename, ".") != 0 && strcmp(filename, "..") != 0) { char newpath[1024]; snprintf(newpath, sizeof(newpath), "%s/%s", pathptr, filename); result = SearchFile(newpath, searched_filename, outfilepath); } } } dirclose(dir); return result; }
//搜索到一个后,立马返回值 string AutoSearchFile::FindCatalogName(string path_, string matchname) { string fext = "*.bmp; *.tga"; if( m_strPrePath != path_ ) { m_strPrePath = path_; SearchFile(path_, fext); } for(size_t i = 0; i < _co_dir.size(); ++i) { if( _co_dir[i].find(matchname) != -1 ) { return _co_dir[i]; } } return ""; }
void ClassBuffer::SearchDir (const char* path) { Directory dir(path); if (_verbose) { printf("searching directory %s\n", path); } for (int i = 0; i < dir.Count(); ++i) { const char* file = dir.File(i); if (HeaderFile(file) || (_CPlusPlusFiles && CPlusPlusFile(path))) { struct stat filestats; char filePath[MAXPATHLEN+1]; strcpy(filePath, dir.Normalize(path)); strcat(filePath, file); if (!IsADirectory(filePath, filestats)) { SearchFile(filePath, filestats); } } } }
static FileName getScreenShotFileName(const string &prefix) { int highestNumber = 0; const string ext = string(".jpg"); vector<FileName> files = SearchFile(FileName("sshots/"), ext); for (vector<FileName>::const_iterator iter=files.begin(); iter!=files.end(); ++iter) { const string &fileName = iter->str(); const string strNum = fileName.substr(prefix.length(), fileName.length() - prefix.length() - ext.length()); const int number = stoi(strNum); if (number>highestNumber) { highestNumber = number; } } string numberPart = fitToFieldSize(itos(++highestNumber), '0', 5, JUSTIFY_RIGHT); return FileName(string("sshots/") + prefix + numberPart + ext); }
static void LinkFile (const char* Name, FILETYPE Type) /* Handle one file */ { char* PathName; FILE* F; unsigned long Magic; /* If we don't know the file type, determine it from the extension */ if (Type == FILETYPE_UNKNOWN) { Type = GetFileType (Name); } /* For known file types, search the file in the directory list */ switch (Type) { case FILETYPE_LIB: PathName = SearchFile (LibSearchPath, Name); if (PathName == 0) { PathName = SearchFile (LibDefaultPath, Name); } break; case FILETYPE_OBJ: PathName = SearchFile (ObjSearchPath, Name); if (PathName == 0) { PathName = SearchFile (ObjDefaultPath, Name); } break; default: PathName = xstrdup (Name); /* Use the name as is */ break; } /* We must have a valid name now */ if (PathName == 0) { Error ("Input file `%s' not found", Name); } /* Try to open the file */ F = fopen (PathName, "rb"); if (F == 0) { Error ("Cannot open `%s': %s", PathName, strerror (errno)); } /* Read the magic word */ Magic = Read32 (F); /* Check the magic for known file types. The handling is somewhat weird ** since we may have given a file with a ".lib" extension, which was ** searched and found in a directory for library files, but we now find ** out (by looking at the magic) that it's indeed an object file. We just ** ignore the problem and hope no one will notice... */ switch (Magic) { case OBJ_MAGIC: ObjAdd (F, PathName); ++ObjFiles; break; case LIB_MAGIC: LibAdd (F, PathName); ++LibFiles; break; default: fclose (F); Error ("File `%s' has unknown type", PathName); } /* Free allocated memory. */ xfree (PathName); }
//This is the main function of the Client int main(int argc, char *argv[]) { int qHandlerPID, fMonitorPID, RC; if(argc <= 1) { printf("--ERROR, incomplete parameter list\n"); printf("--Correct Format\n\t./FndFl <<Server IP>> [<<Current Port>>]\n"); return 0; } strcpy(ServerIP, argv[1]); if(argc >= 3) { strcpy(MyPort, argv[2]); qPort = atoi(MyPort); } uPort = 40000; if(InitializeClient() < 0) { printf("--ERROR - Could not start the peer application, please restart the application or retry after restarting the system if problem persists\n"); exit(0); } //Start the query handler if((qHandlerPID = fork()) == 0) { StartQHandler(); } //Start the file monitor if((fMonitorPID = fork()) == 0) { fMonitor(); } printf("\n---------------------Node Ready------------------------\n"); printf("\tSearch and get the files you want.\n \tThe app is read ,enjoy!\n"); //Stay in this loop forever while(1) { if(GetUserInPut() == 0) { if((RC = SearchFile()) == 0) { printf("--Could not locate the file \"%s\"\n",InFileName); } else if(RC < 0) { printf("--Could not locate the file \"%s\"\n, RC was %d",InFileName, RC); } else { printf("--\tFile found, transfer started from %s\n",SourceIP); if((RC = GetFile()) == 0) { printf("--ERROR - File transfer was interrupted, restart the search\n"); } else if(RC < 0) { printf("--ERROR - File transfer was interrupted, restart the search\n"); } else { printf("--\tSuccess: file \"%s\" copied to the shared directory\n--\n", InFileName); } } } } //The program control should never come here printf("Program is in an inconsistant state, terminating the Node application\n"); exit(0); }
/*---------------------------------------------------------------------- InitTranslations intializes the keybord encoding. ----------------------------------------------------------------------*/ void InitTranslations (char *appliname) { char *appHome; /* fichier de translation */ char fullName[200]; /* ligne en construction pour motif */ char home[200], name[80]; char *addr; char transText[MAX_LENGTH], ch[MAX_LENGTH]; char equiv[MAX_LENGTH]; /* equivalents caracteres pour motif */ unsigned int key1, key2; /* 1ere & 2eme cles sous forme de keysym X */ int e, i, j; int mod1, mod2; /* 1er/ 2eme modifieurs : voir THOT_MOD_xx */ int len, max, value; FILE *file; ThotBool isSpecialKey1, isSpecialKey2, show_sequence = FALSE; /* clean up the access key table */ memset(DocAccessKey, 0, sizeof(KEY *) * MAX_DOCUMENTS); #ifdef _MACOS TtaSetEnvBoolean ("SHOW_SEQUENCES", FALSE, FALSE); #else /* _MACOS */ TtaSetEnvBoolean ("SHOW_SEQUENCES", TRUE, FALSE); #endif /* _MACOS */ TtaGetEnvBoolean ("SHOW_SEQUENCES", &show_sequence); appHome = TtaGetEnvString ("APP_HOME"); strcpy (name, appliname); #ifdef _WINDOWS strcat (name, ".kb"); #else /* _WINDOWS */ #ifdef _MACOS // change the unix choice for MacOS platforms strcat (name, ".kb-mac"); #else /* _MACOS */ strcat (name, ".keyboard"); #endif /* _MACOS */ #endif /* _WINDOWS */ strcpy (home, appHome); strcat (home, DIR_STR); strcat (home, name); if (!SearchFile (home, 0, fullName)) SearchFile (name, 2, fullName); file = TtaReadOpen (fullName); if (file) { /* beginning of the file */ fseek (file, 0L, 0); e = 1; max = MaxMenuAction; len = strlen ("TtcInsertChar") + 2; /* Test if sequences are allowed */ ch[0] = EOS; fscanf (file, "%80s", ch); do { /* Initialisation */ mod1 = mod2 = THOT_NO_MOD; key1 = key2 = 0; equiv[0] = EOS; /* Est-ce la fin de fichier ? */ if (strlen (ch) == 0 || EndOfString (ch, "^")) e = 0; else if (ch[0] != '#') { /* it is not a comment */ while ((!strcmp (ch, "Shift")) || (!strcmp (ch, "Ctrl")) || (!strcmp (ch, "Alt")) ) { if (!strcmp (ch, "Shift")) mod1 += THOT_MOD_SHIFT; else if (!strcmp (ch, "Ctrl")) mod1 += THOT_MOD_CTRL; else if (!strcmp (ch, "Alt")) mod1 += THOT_MOD_ALT; ch[0] = EOS; fscanf (file, "%80s", ch); } /* remove the end colon */ sscanf (ch, "<Key>%80s", transText); if (transText[0] != EOS) { i = strlen (transText) - 1; if (i > 0 && transText[i] == ':') transText[i] = EOS; } /* convert to keysym for the automata */ key1 = SpecialKey (transText, (mod1 & THOT_MOD_SHIFT) != 0, &isSpecialKey1); /* Get the following word in the line */ ch[0] = EOS; fscanf (file, "%80s", ch); /* Register the equiv string */ if (show_sequence || ch[0] != ',') { #ifdef _MACOS if (ch[0] != ',') /* it's not a sequence */ strcpy (equiv, "\t"); if ((mod1 & THOT_MOD_CTRL) && (mod1 & THOT_MOD_ALT)) /* specific to MacOS */ strcat (equiv, "Ctrl-Alt"); #else /* _MACOS */ if (!(mod1 & THOT_MOD_CTRL)) /* it's not a sequence */ strcpy (equiv, "\t"); #endif /* _MACOS */ if (ch[0] == ',') strcpy (equiv, "("); if (mod1 & THOT_MOD_CTRL) strcat (equiv, "Ctrl"); else if (mod1 & THOT_MOD_ALT) strcat (equiv, "Alt"); if (mod1 & THOT_MOD_SHIFT) { if (mod1 != THOT_MOD_SHIFT) strcat (equiv, "-"); strcat (equiv, "Shift"); } if (mod1 != THOT_NO_MOD) { if (ch[0] == ',') strcat (equiv, " "); else strcat (equiv, "-"); } if (ch[0] != ',' && transText[0] >= 'a' && transText[0] <= 'z') SetCapital (transText); strcat (equiv, transText); } if (ch[0] == ',') { /* the shortcut is a sequence */ ch[0] = EOS; fscanf (file, "%80s", ch); while ((!strcmp (ch, "Shift")) || (!strcmp (ch, "Ctrl")) || (!strcmp (ch, "Alt")) ) { if (!strcmp (ch, "Shift")) mod2 += THOT_MOD_SHIFT; else if (!strcmp (ch, "Ctrl")) mod2 += THOT_MOD_CTRL; else if (!strcmp (ch, "Alt")) mod2 += THOT_MOD_ALT; ch[0] = EOS; fscanf (file, "%80s", ch); } /* remove the end colon */ sscanf (ch, "<Key>%80s", transText); if (transText[0] != EOS) { i = strlen (transText) - 1; if (i > 0 && transText[i] == ':') transText[i] = EOS; } key2 = SpecialKey (transText, (mod2 & THOT_MOD_SHIFT) != 0, &isSpecialKey2); /* register the second part of the equiv string */ if (show_sequence) { strcat (equiv, " "); strcat (equiv, transText); strcat (equiv, ")"); } /* Get the next word in the line */ fscanf (file, "%80s", ch); } /* Get the commande name */ addr = strchr (ch, '('); if (addr == NULL) addr = strchr (ch, SPACE); if (addr) addr[0] = EOS; else do i = fgetc (file); while (i != ')'); /* Locate the action name */ for (i = 0; i < max; i++) if (!strcmp (ch, MenuActionList[i].ActionName)) break; if (i == 0) { /* action insert-string */ if (ch[len] == '&' && ch[len + 1] == '#') { /* it's an entity */ j = 2; while (ch[len + j] != EOS && ch[len + j] != ';' && ch[len + j] != ')' && ch[len + j] != '"') j++; ch[len + j] = EOS; if (ch[len + 2] == 'x') sscanf (&ch[len + 3], "%x", &value); else sscanf (&ch[len + 2], "%d", &value); } else { addr = (char *)AsciiTranslate (&ch[len]); value = (unsigned char) addr[0]; } MemoKey (mod1, key1, isSpecialKey1, mod2, key2, isSpecialKey2, value, 0); } else if (i < max) { /* another action */ if (MemoKey (mod1, key1, isSpecialKey1, mod2, key2, isSpecialKey2, /*255+i */ 0, i)) { /* display the equiv shortcut */ TtaFreeMemory (MenuActionList[i].ActionEquiv); MenuActionList[i].ActionEquiv = TtaStrdup (equiv); } } } else { /* comment line */ //fscanf (file, "%80s", ch); /* skip this line */ do i = fgetc (file); while (i != NEW_LINE); } ch[0] = 0; fscanf (file, "%80s", ch); } while (e != 0); TtaReadClose (file); } }
//--------------------------------------------------------------------------- void __fastcall TfrmOpenFTPDialog::SearchFile(AnsiString APath,AnsiString SearchFileName,int Level) { TStringList * DirList = new TStringList; AnsiString FileName; TListItem * Item; AnsiString FileType; try { IdFTP1->ChangeDir(APath); AnsiString CurPath = IdFTP1->RetrieveCurrentDir(); IdFTP1->List(NULL,SearchFileName,true); for(int n = 0;n < IdFTP1->DirectoryListing->Count;n++) { FileName = IdFTP1->DirectoryListing->Items[n]->FileName; if(FileName == "." || FileName == "..") continue; if(IdFTP1->DirectoryListing->Items[n]->ItemType == ditDirectory) { DirList->Add(APath + FileName); } else { //Item = lvFiles->FindCaption(-1,FileName,false,false,false); //if(Item != NULL && strcmp(Item->SubItems->Strings[3].c_str(),CurPath.c_str()) == 0) //{ // continue; //} Item = lvFiles->Items->Add(); Item->Caption = FileName; Item->ImageIndex = IMAGE_FILE; if(IdFTP1->DirectoryListing->Items[n]->Size > 1048576) Item->SubItems->Add(FloatToStr(RoundTo((float)IdFTP1->DirectoryListing->Items[n]->Size / 1048576,-2)) + "MB"); else if(IdFTP1->DirectoryListing->Items[n]->Size > 1024) Item->SubItems->Add(FloatToStr(RoundTo((float)IdFTP1->DirectoryListing->Items[n]->Size / 1024,-2)) + "KB"); else Item->SubItems->Add(IntToStr(IdFTP1->DirectoryListing->Items[n]->Size) +"B"); FileType = ExtractFileExt(FileName); if(FileType != "") Item->SubItems->Add(FileType.SubString(2,FileType.Length() - 1) + "文件"); else Item->SubItems->Add(""); Item->SubItems->Add(IdFTP1->DirectoryListing->Items[n]->ModifiedDate.FormatString("yyyy-mm-dd hh:nn:ss")); Item->SubItems->Add(CurPath); Item->Data = (void *)IdFTP1->DirectoryListing->Items[n]->Size; } } } catch(Exception * E) { Screen->Cursor = crDefault; MessageBox(Handle,E->Message.c_str(),"错误",MB_OK | MB_ICONSTOP); } if(Level > 0) { for(int n = 0;n < DirList->Count;n++) { SearchFile(DirList->Strings[n],SearchFileName,Level - 1); } } delete DirList; }
int Interpret(const char *cmd, int redirect,char *target,int bg) { //解析执行一条命令 //cmd中包含两部分,一是命令执行文件本省,第二是argv[] if(strlen(cmd)==0) return 1; int argc; char **argv=ResolveCmd(cmd,&argc); if(!strcmp(argv[0],"cd")) { if(argc>1) ChangeDir(argv[1]); else //开启文件导航系统 { char finalpath[path_max]; Navigation(finalpath); ChangeDir(finalpath); } } else if(!strcmp(argv[0],"jobs")) { ShowJobs(); } else if(!strcmp(argv[0],"fg")) { //前台运行 ForeGround(argv[1]); } else if(!strcmp(argv[0],"stop")) StopPid(argv[1]); else if(!strcmp(argv[0],"continue")) ContinuePid(argv[1]); else if(!strcmp(argv[0],"bg")) //后台继续运行 ContinuePid(argv[1]); else if(!strcmp(argv[0],"history")) catHistory(); else if(!strcmp(argv[0],"echopath")) EchoPath(); else if(!strcmp(argv[0],"addpath")) AddPath(argv[1]); else if(!strcmp(argv[0],"exit")) return Exit(); else { int i=0,find=0; char filepath[PATH_MAX+1]={'\0'}; find=isEXE(argv[0]); //输入的命令是否带'/',可能指向EXEfile if(find) strcpy(filepath,argv[0]); else //从环境变量的目录中搜索 { while(!find && i<envpath_num) { //依次从各个环境变量的路径中寻找 find=SearchFile(envpath[i++],argv[0],filepath); } } if(find && bg==0) //找到命令,前台运行 { int pid=fork(); run_pid=pid; strcpy(run_cmd,cmd); if(pid>0) { waitpid(pid,NULL,WUNTRACED); run_pid=0; run_cmd[0]='\0'; } else { if(redirect==1) OutputRedirect(target); else if(redirect==0) InputRedirect(target); mask_signals(); //子进程屏蔽信号 if(execv(filepath,argv)==-1) printf("不能打开指定文件\n"); exit(0); } } else if(find && bg==1) //找到命令,后台运行 { //后台运行 int pid=fork(); if(pid>0) { //父进程把后台进程添加到job管理系统中 int pos=0; //找空位置,优先填满前面被删掉的位置 while(pos<jobmanager.jobnum && jobmanager.jobs[pos].status>0) pos++; //结果是pos占到了jobnum之前的被删位置,或者是pos==jobnum jobmanager.jobs[pos].pid=pid; int i=0; for(;i<strlen(cmd);i++) jobmanager.jobs[pos].cmd[i]=cmd[i]; //保存cmd信息 jobmanager.jobs[pos].cmd[i++]='&'; //保存cmd信息 jobmanager.jobs[pos].cmd[i]='\0'; //结尾 jobmanager.jobs[pos].status=1; //正常运行 if(pos==jobmanager.jobnum) { jobmanager.jobnum++; //只有pos开辟了新的坑位时,才占位 if(jobmanager.jobnum>jobnum_max) printf("jobs中的后台程序即将达到上限\n"); } printf("[%d] %d\n",pos+1,pid); } else { //子进程负责后台执行 if(redirect==1) OutputRedirect(target); else if(redirect==0) InputRedirect(target); mask_signals(); //信号屏蔽 if(execv(filepath,argv)==-1) printf("不能打开指定文件\n"); exit(0); //有个问题:子进程退了之后,父进程怎么查询?会出现相同pid的情况吗?貌似不会 } } else printf("Unknwon cmd.\n"); } //程序结束后要清理argv int i=0; for(;i<argc;i++) { free(argv[i]); } free(argv); return 1; }
void CTestSetBatchView::OnBtnTest() { CMainFrame* pFrame = (CMainFrame*)GetParentFrame(); #ifndef SELF_TEST // 检查有无pcie板卡 if ( !((CAdcTestPlatApp*)AfxGetApp())->DetectedCards() ) { // 更新到工具栏 if ( pFrame != NULL ) { pFrame->m_bRunning = FALSE; } AfxMessageBox( "未找到PCIE设备!" ); return; } else #endif { // 能够开始测试 if ( m_bTestBegin ) { // 获取控件数据 UpdateData( TRUE ); // 电路ID检查 if ( m_strID.GetLength() == 0 ) { AfxMessageBox( "必须输入芯片批号(8位数字),才能开始测试!" ); GetDlgItem( IDC_EDIT_ID )->SetFocus(); //m_bTestBegin = !m_bTestBegin; // 更新到工具栏 if ( pFrame != NULL ) { pFrame->m_bRunning = FALSE; } return; } else if ( m_strID.GetLength() != 8 ) { AfxMessageBox( "芯片批号为8位数字!" ); //GetDlgItem( IDC_EDIT_ID )->SetWindowText( "" ); GetDlgItem( IDC_EDIT_ID )->SetFocus(); //m_bTestBegin = !m_bTestBegin; // 更新到工具栏 if ( pFrame != NULL ) { pFrame->m_bRunning = FALSE; } return; } // 检查有无相同ID的文件存在 CString strFileName = m_strID + ".atp"; if ( SearchFile( strFileName ) ) { int nRet = AfxMessageBox( "该芯片批号已经测试过,是否覆盖?", MB_YESNO | MB_ICONQUESTION ); // 不覆盖需要用户重新输入 if ( nRet == IDNO ) { //GetDlgItem( IDC_EDIT_ID )->SetWindowText( "" ); GetDlgItem( IDC_EDIT_ID )->SetFocus(); //m_bTestBegin = !m_bTestBegin; // 更新到工具栏 if ( pFrame != NULL ) { pFrame->m_bRunning = FALSE; } return; } } // 保存文件名 m_strCurFileName = strFileName; // 更新到工具栏 if ( pFrame != NULL ) { pFrame->m_bRunning = TRUE; } // 状态改变 m_bTestBegin = FALSE; GetDlgItem( ID_BTN_TEST )->SetWindowText( "测试停止" ); InitStaticColor(); // 用于刷新视图 SetTimer( 2, 500, NULL ); // 批量测试 CAdcTestPlatDoc* pDoc = (CAdcTestPlatDoc*)GetDocument(); if ( pDoc != NULL ) { // 测试开始时自动上电 pDoc->PowerOn(); Sleep(400); } DoTestBatch(); } else { // 测试过程中点击测试结束,关闭已经打开的窗口 if ( m_pJudgeDlgBack != NULL ) { m_pJudgeDlgBack->SendMessage( WM_CLOSE ); } // 更新到工具栏 if ( pFrame != NULL ) { pFrame->m_bRunning = FALSE; } // 状态改变 m_bTestBegin = TRUE; GetDlgItem( ID_BTN_TEST )->SetWindowText( "测试开始" ); // 测试停止,关闭定时器 KillTimer( 1 ); } } }
int NewInputFile (const char* Name) /* Open a new input file. Returns true if the file could be successfully opened ** and false otherwise. */ { int RetCode = 0; /* Return code. Assume an error. */ char* PathName = 0; FILE* F; struct stat Buf; StrBuf NameBuf; /* No need to initialize */ StrBuf Path = AUTO_STRBUF_INITIALIZER; unsigned FileIdx; CharSource* S; /* If this is the main file, just try to open it. If it's an include file, ** search for it using the include path list. */ if (FCount == 0) { /* Main file */ F = fopen (Name, "r"); if (F == 0) { Fatal ("Cannot open input file '%s': %s", Name, strerror (errno)); } } else { /* We are on include level. Search for the file in the include ** directories. */ PathName = SearchFile (IncSearchPath, Name); if (PathName == 0 || (F = fopen (PathName, "r")) == 0) { /* Not found or cannot open, print an error and bail out */ Error ("Cannot open include file '%s': %s", Name, strerror (errno)); goto ExitPoint; } /* Use the path name from now on */ Name = PathName; } /* Stat the file and remember the values. There's a race condition here, ** since we cannot use fileno() (non-standard identifier in standard ** header file), and therefore not fstat. When using stat with the ** file name, there's a risk that the file was deleted and recreated ** while it was open. Since mtime and size are only used to check ** if a file has changed in the debugger, we will ignore this problem ** here. */ if (FileStat (Name, &Buf) != 0) { Fatal ("Cannot stat input file '%s': %s", Name, strerror (errno)); } /* Add the file to the input file table and remember the index */ FileIdx = AddFile (SB_InitFromString (&NameBuf, Name), (FCount == 0)? FT_MAIN : FT_INCLUDE, Buf.st_size, (unsigned long) Buf.st_mtime); /* Create a new input source variable and initialize it */ S = xmalloc (sizeof (*S)); S->Func = &IFFunc; S->V.File.F = F; S->V.File.Pos.Line = 0; S->V.File.Pos.Col = 0; S->V.File.Pos.Name = FileIdx; SB_Init (&S->V.File.Line); /* Push the path for this file onto the include search lists */ SB_CopyBuf (&Path, Name, FindName (Name) - Name); SB_Terminate (&Path); S->V.File.IncSearchPath = PushSearchPath (IncSearchPath, SB_GetConstBuf (&Path)); S->V.File.BinSearchPath = PushSearchPath (BinSearchPath, SB_GetConstBuf (&Path)); SB_Done (&Path); /* Count active input files */ ++FCount; /* Use this input source */ UseCharSource (S); /* File successfully opened */ RetCode = 1; ExitPoint: /* Free an allocated name buffer */ xfree (PathName); /* Return the success code */ return RetCode; }
int main(int argc, char **argv) { int sockfd, n; char recvline[MAXLINE + 1]; struct sockaddr_in servaddr; char buff[MAXLINE + 1]; if (argc != 1) perror("usage: a.out <IPaddress>"); if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) perror("socket error"); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; servaddr.sin_port = htons(2000); /* daytime server */ servaddr.sin_addr.s_addr = inet_addr("127.0.0.1"); //if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) // printf("inet_pton error for %s", argv[1]); if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) perror("connect error"); memset(buff,0,sizeof(buff)); login(buff); write(sockfd,buff,strlen(buff)+1); if ( (n = read(sockfd, recvline, MAXLINE)) > 0) { printf("%s\n",recvline); } if (n < 0) perror("read error"); int quit=1; if(recvline[0]=='L') quit=0; while(quit==0) { printf("Enter your choice(S for Share, F for Search, Q for Quit): "); char c=getchar(); switch(c) { case 's': case 'S': ShareFile(buff); write(sockfd,buff,strlen(buff)+1); if ( (n = read(sockfd, recvline, MAXLINE)) > 0) { printf("%s\n",recvline); } if (n < 0) perror("read error"); break; case 'f': case 'F': SearchFile(buff); write(sockfd,buff,strlen(buff)+1); while( (n = read(sockfd, recvline, MAXLINE)) > 0) { printf("%s",recvline); if(recvline[4]=='\n') break; } if (n < 0) perror("read error\n"); break; case 'q': case 'Q': strcpy(buff,"QUIT\n"); write(sockfd,buff,strlen(buff)+1); quit=1; break; default: break; } } close(sockfd); exit(0); }
static int _fastcall _list( LPTSTR pszFileName ) { register int c, i; TCHAR szDescription[512], szHeader[132], szLine[32]; long lTemp, lRow; POPWINDOWPTR wn = NULL; FILESEARCH dir; // get default normal and inverse attributes if ( gpIniptr->ListColor != 0 ) { SetScrColor( nScreenRows, nScreenColumns, gpIniptr->ListColor ); } // set colors GetAtt( (unsigned int *)&nNormal, (unsigned int *)&nInverse ); if ( gpIniptr->ListStatusColor != 0 ) nInverse = gpIniptr->ListStatusColor; // flip the first line to inverse video clear_header(); // open the file & initialize buffers if ( ListOpenFile( pszFileName )) return ERROR_EXIT; // kludge for empty files or pipes if ( LFile.lSize == 0L ) LFile.lSize = 1L; for ( ; ; ) { // display header if ( fDirtyHeader ) { clear_header(); sprintf( szHeader, LIST_HEADER, fname_part(LFile.szName), gchVerticalBar, gchVerticalBar, gchVerticalBar ); WriteStrAtt( 0, 0, nInverse, szHeader ); fDirtyHeader = 0; } // display location within file // (don't use color_printf() so we won't have // problems with windowed sessions) i = sprintf( szHeader, LIST_LINE, LFile.nListHorizOffset, LFile.lCurrentLine + gpIniptr->ListRowStart, (int)((( LFile.lViewPtr + 1 ) * 100 ) / LFile.lSize )); WriteStrAtt( 0, ( nScreenColumns - i ), nInverse, szHeader ); SetCurPos( 0, 0 ); if ( lListFlags & LIST_SEARCH ) { lListFlags &= ~LIST_SEARCH; fSearchFlags = 0; if ( lListFlags & LIST_REVERSE ) { c = LIST_FIND_CHAR_REVERSE; fSearchFlags |= FFIND_REVERSE_SEARCH; // goto the last row while ( ListMoveLine( 1 ) != 0 ) ; } else c = LIST_FIND_CHAR; if ( lListFlags & LIST_NOWILDCARDS ) fSearchFlags |= FFIND_NOWILDCARDS; bListSkipLine = 0; goto FindNext; } // get the key from the BIOS, because // STDIN might be redirected if ((( c = cvtkey( GetKeystroke( EDIT_NO_ECHO | EDIT_BIOS_KEY | EDIT_UC_SHIFT), MAP_GEN | MAP_LIST)) == (TCHAR)ESC )) break; switch ( c ) { case CTRLC: return CTRLC; case CUR_LEFT: case CTL_LEFT: if (( lListFlags & LIST_WRAP ) || ( LFile.nListHorizOffset == 0 )) goto bad_key; if (( LFile.nListHorizOffset -= (( c == CUR_LEFT ) ? 8 : 40 )) < 0 ) LFile.nListHorizOffset = 0; break; case CUR_RIGHT: case CTL_RIGHT: if (( lListFlags & LIST_WRAP ) || ( LFile.nListHorizOffset >= MAXLISTLINE + 1 )) goto bad_key; if ((LFile.nListHorizOffset += ((c == CUR_RIGHT) ? 8 : 40 )) > MAXLISTLINE + 1 ) LFile.nListHorizOffset = MAXLISTLINE+1; break; case CUR_UP: if ( ListMoveLine( -1 ) == 0 ) goto bad_key; Scroll(1, 0, nScreenRows, nScreenColumns, -1, nNormal); DisplayLine( 1, LFile.lViewPtr ); continue; case CUR_DOWN: if ( ListMoveLine( 1 ) == 0 ) goto bad_key; Scroll( 1, 0, nScreenRows, nScreenColumns, 1, nNormal ); // display last line lTemp = LFile.lViewPtr; lRow = (nScreenRows - 1); lTemp += MoveViewPtr( lTemp, &lRow ); if ( lRow == ( nScreenRows - 1 )) DisplayLine( nScreenRows, lTemp ); continue; case HOME: ListHome(); break; case END: // goto the last row list_wait( LIST_WAIT ); while ( ListMoveLine( 1 ) != 0 ) ; case PgUp: // already at TOF? if ( LFile.lViewPtr == 0L ) goto bad_key; for ( i = 1; (( i < nScreenRows ) && ( ListMoveLine( -1 ) != 0 )); i++ ) ; break; case PgDn: case SPACE: if ( ListMoveLine( nScreenRows - 1 ) == 0 ) goto bad_key; break; case F1: // help // don't allow a ^X exit from HELP _help( gpInternalName, HELP_NX ); continue; case TAB: // change tab size // disable ^C / ^BREAK handling HoldSignals(); wn = wOpen( 2, 5, 4, strlen( LIST_TABSIZE ) + 10, nInverse, LIST_TABSIZE_TITLE, NULL ); wn->nAttrib = nNormal; wClear(); wWriteListStr( 0, 1, wn, LIST_TABSIZE ); egets( szLine, 2, (EDIT_DIALOG | EDIT_BIOS_KEY | EDIT_NO_CRLF | EDIT_DIGITS)); wRemove( wn ); if (( i = atoi( szLine )) > 0 ) TABSIZE = i; // enable ^C / ^BREAK handling EnableSignals(); break; case DEL: // delete this file if (( lListFlags & LIST_STDIN ) == 0 ) { // disable ^C / ^BREAK handling HoldSignals(); wn = wOpen( 2, 5, 4, strlen( LIST_DELETE ) + 10, nInverse, LIST_DELETE_TITLE, NULL ); wn->nAttrib = nNormal; wClear(); wWriteListStr( 0, 1, wn, LIST_DELETE ); i = GetKeystroke( EDIT_ECHO | EDIT_BIOS_KEY | EDIT_UC_SHIFT ); wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); if ( i == (TCHAR)YES_CHAR ) { if ( LFile.hHandle > 0 ) _close( LFile.hHandle ); LFile.hHandle = -1; remove( pszFileName ); return 0; } } break; case INS: // save to a file ListSaveFile(); break; case LIST_INFO_CHAR: { unsigned int uSize = 1024; TCHAR _far *lpszText, _far *lpszArg; int fFSType, fSFN = 1; TCHAR szBuf[16]; DOSFILEDATE laDir, crDir; // disable ^C / ^BREAK handling HoldSignals(); memset( &dir, '\0', sizeof(FILESEARCH) ); if (( lListFlags & LIST_STDIN ) == 0 ) { if ( find_file( FIND_FIRST, LFile.szName, 0x07 | FIND_CLOSE | FIND_EXACTLY, &dir, NULL ) == NULL ) { honk(); continue; } } // display info on the current file i = (( lListFlags & LIST_STDIN ) ? 5 : 10 ); if (( fFSType = ifs_type( LFile.szName )) != FAT ) i = 11; wn = wOpen( 2, 1, i, 77, nInverse, gpInternalName, NULL ); wn->nAttrib = nNormal; wClear(); i = 0; if ( lListFlags & LIST_STDIN ) wWriteStrAtt( 0, 1, nNormal, LIST_INFO_PIPE ); else { szDescription[0] = _TEXT('\0'); process_descriptions( LFile.szName, szDescription, DESCRIPTION_READ ); lpszText = lpszArg = (TCHAR _far *)AllocMem( &uSize ); strcpy(szBuf, FormatDate( dir.fd.file_date.months, dir.fd.file_date.days, dir.fd.file_date.years + 80, 0 )); if (fFSType != FAT) { FileTimeToDOSTime( &(dir.ftLastAccessTime), &( laDir.ft.wr_time), &( laDir.fd.wr_date) ); FileTimeToDOSTime( &(dir.ftCreationTime), &(crDir.ft.wr_time), &(crDir.fd.wr_date) ); strcpy( szLine, FormatDate( laDir.fd.file_date.months, laDir.fd.file_date.days, laDir.fd.file_date.years + 80, 0 )); sprintf_far( lpszText, LIST_INFO_LFN, LFile.szName, szDescription, dir.ulSize, szBuf, dir.ft.file_time.hours, gaCountryInfo.szTimeSeparator[0],dir.ft.file_time.minutes, szLine, laDir.ft.file_time.hours, gaCountryInfo.szTimeSeparator[0], laDir.ft.file_time.minutes, FormatDate( crDir.fd.file_date.months, crDir.fd.file_date.days, crDir.fd.file_date.years + 80, 0 ), crDir.ft.file_time.hours, gaCountryInfo.szTimeSeparator[0], crDir.ft.file_time.minutes); } else { sprintf_far( lpszText, LIST_INFO_FAT, LFile.szName, szDescription, dir.ulSize, szBuf, dir.ft.file_time.hours, gaCountryInfo.szTimeSeparator[0],dir.ft.file_time.minutes ); } // print the text for ( ; ( *lpszArg != _TEXT('\0') ); i++ ) { sscanf_far( lpszArg, _TEXT("%[^\n]%*c%n"), szHeader, &uSize ); // allow for long filenames ... if (( i == 0 ) && ( strlen( szHeader ) > 73 )) { c = szHeader[73]; szHeader[73] = _TEXT('\0'); wWriteStrAtt( i++, 1, nNormal, szHeader ); szHeader[73] = (TCHAR)c; wWriteStrAtt( i, 15, nNormal, szHeader+73 ); fSFN = 0; } else wWriteStrAtt( i, 1, nNormal, szHeader ); lpszArg += uSize; } FreeMem( lpszText ); } wWriteListStr( i+fSFN, 1, wn, PAUSE_PROMPT ); GetKeystroke( EDIT_NO_ECHO | EDIT_BIOS_KEY ); wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); continue; } case LIST_GOTO_CHAR: // goto the specified line / hex offset // disable ^C / ^BREAK handling HoldSignals(); wn = wOpen( 2, 5, 4, strlen( LIST_GOTO_OFFSET ) + 20, nInverse, LIST_GOTO_TITLE, NULL ); wn->nAttrib = nNormal; wClear(); wWriteListStr( 0, 1, wn, (( lListFlags & LIST_HEX) ? LIST_GOTO_OFFSET : LIST_GOTO)); i = egets( szLine, 10, (EDIT_DIALOG | EDIT_BIOS_KEY | EDIT_NO_CRLF)); wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); if ( i == 0 ) break; list_wait( LIST_WAIT ); // if in hex mode, jump to offset if ( lListFlags & LIST_HEX ) { strupr( szLine ); sscanf( szLine, _TEXT("%lx"), &lRow ); lRow = lRow / 0x10; } else if ( sscanf( szLine, FMT_LONG, &lRow ) == 0 ) continue; lRow -= gpIniptr->ListRowStart; if ( lRow >= 0 ) { LFile.lViewPtr = MoveViewPtr( 0L, &lRow ); LFile.lCurrentLine = lRow; } else { LFile.lViewPtr += MoveViewPtr( LFile.lViewPtr, &lRow ); LFile.lCurrentLine += lRow; } break; case LIST_HIBIT_CHAR: // toggle high bit filter lListFlags ^= LIST_HIBIT; break; case LIST_WRAP_CHAR: // toggle line wrap lListFlags ^= LIST_WRAP; nRightMargin = (( lListFlags & LIST_WRAP ) ? GetScrCols() : MAXLISTLINE ); // recalculate current line list_wait( LIST_WAIT ); // get start of line LFile.nListHorizOffset = 0; // line number probably changed, so recompute everything LFile.lCurrentLine = ComputeLines( 0L, LFile.lViewPtr ); LFile.lViewPtr = MoveViewPtr( 0L, &(LFile.lCurrentLine )); break; case LIST_HEX_CHAR: // toggle hex display lListFlags ^= LIST_HEX; // if hex, reset to previous 16-byte // boundary if ( lListFlags & LIST_HEX ) { LFile.lViewPtr -= ( LFile.lViewPtr % 16 ); } else { // if not hex, reset to start of line ListMoveLine( 1 ); ListMoveLine( -1 ); } // recalculate current line list_wait( LIST_WAIT ); LFile.lCurrentLine = ComputeLines( 0L, LFile.lViewPtr ); break; case LIST_FIND_CHAR: case LIST_FIND_CHAR_REVERSE: // find first matching string bListSkipLine = 0; //lint -fallthrough case LIST_FIND_NEXT_CHAR: case LIST_FIND_NEXT_CHAR_REVERSE: // find next matching string if (( c == LIST_FIND_CHAR ) || ( c == LIST_FIND_CHAR_REVERSE )) { // disable ^C / ^BREAK handling HoldSignals(); fSearchFlags = 0; wn = wOpen( 2, 1, 4, 75, nInverse, (( c == LIST_FIND_NEXT_CHAR_REVERSE ) ? LIST_FIND_TITLE_REVERSE : LIST_FIND_TITLE ), NULL ); wn->nAttrib = nNormal; wClear(); if ( lListFlags & LIST_HEX ) { wWriteListStr( 0, 1, wn, LIST_FIND_HEX ); if ( GetKeystroke( EDIT_ECHO | EDIT_BIOS_KEY | EDIT_UC_SHIFT ) == YES_CHAR ) fSearchFlags |= FFIND_HEX_SEARCH; wClear(); } wWriteListStr( 0, 1, wn, LIST_FIND ); egets( szListFindWhat, 64, (EDIT_DIALOG | EDIT_BIOS_KEY | EDIT_NO_CRLF)); wRemove( wn ); // enable ^C / ^BREAK handling EnableSignals(); } else { FindNext: // a "Next" has to be from current position fSearchFlags &= ~FFIND_TOPSEARCH; } if ( szListFindWhat[0] == _TEXT('\0') ) continue; sprintf( szDescription, LIST_FIND_WAIT, szListFindWhat ); list_wait( szDescription ); // save start position lTemp = LFile.lViewPtr; lRow = LFile.lCurrentLine; if (( c == LIST_FIND_CHAR_REVERSE ) || ( c == LIST_FIND_NEXT_CHAR_REVERSE )) { // start on the previous line fSearchFlags |= FFIND_REVERSE_SEARCH; } else { fSearchFlags &= ~FFIND_REVERSE_SEARCH; // skip the first line (except on /T"xxx") if ( bListSkipLine ) ListMoveLine( 1 ); } bListSkipLine = 1; if ( SearchFile( fSearchFlags ) != 1 ) { ListSetCurrent( lTemp ); LFile.lViewPtr = lTemp; LFile.lCurrentLine = lRow; } else LFile.fDisplaySearch = (( fSearchFlags & FFIND_CHECK_CASE ) ? 2 : 1 ); break; case LIST_PRINT_CHAR: // print the file ListPrintFile(); continue; case LIST_CONTINUE_CHAR: case CTL_PgDn: return 0; case LIST_PREVIOUS_CHAR: case CTL_PgUp: // previous file if ( nCurrent > 0 ) { nCurrent--; return 0; } //lint -fallthrough default: bad_key: honk(); continue; } // rewrite the display ListUpdateScreen(); } return 0; }