int main(int argc, char** argv) { readFileList(PATH_SHM); struct event timeout; struct timeval tv; /* Initalize the event library */ //初始化event环境 event_init(); /* Initalize one event */ //设置事件 evtimer_set(&timeout, timeout_cb, &timeout); evutil_timerclear(&tv); tv.tv_sec = TIME_INTERVAL; //注册事件 event_add(&timeout, &tv); //等待,分发,处理事件 event_dispatch(); return 0; }
int main(int argc, char **argv) { if (argc < 2) { printHelp(argv[0]); return -1; } std::ifstream pgfFile; pgfFile.open(argv[1]); if (!pgfFile.is_open()) { printf("Error opening file \"%s\"\n", argv[1]); return -1; } uint32 fileCount = readUint32BE(pgfFile); printf("Number of file: %d\n", fileCount); std::list<FileInfo> files; readFileList(pgfFile, files, fileCount); extractFiles(pgfFile, files); files.clear(); pgfFile.close(); return 0; }
int readFileList(char *basePath, int dir_id) { DIR *dir; struct dirent *ptr; char base[1000]; if ((dir=opendir(basePath)) == NULL) { return 0; } while ((ptr=readdir(dir)) != NULL) { if(strcmp(ptr->d_name,".")==0 || strcmp(ptr->d_name,"..")==0) //current dir OR parrent dir continue; memset(base,'\0',sizeof(base)); strcpy(base,basePath); strcat(base,"/"); strcat(base,ptr->d_name); if(ptr->d_type == 8) { //file create_file(base, dir_id); // printf("%s/%s : %lld %ld\n",basePath, ptr->d_name, size, ptr->d_ino); } else if(ptr->d_type == 4) { //dir dir_tot ++; int tmp = readFileList(base, dir_tot); strcpy(d[dir_id].entry[c[dir_id]].filename, ptr->d_name); d[dir_id].entry[c[dir_id]].inode_off = tot; c[dir_id] ++; create_dir(tmp); } } closedir(dir); return dir_id; }
int readFileList(char *basePath) { DIR *dir; struct dirent *ptr; char base[1000]; if ((dir=opendir(basePath)) == NULL) { perror("Open dir error..."); exit(1); } while ((ptr=readdir(dir)) != NULL) { if(strcmp(ptr->d_name,".")==0 || strcmp(ptr->d_name,"..")==0) ///current dir OR parrent dir continue; else if(ptr->d_type == 8) ///file printf("d_name:%s/%s\n",basePath,ptr->d_name); else if(ptr->d_type == 10) ///link file printf("d_name:%s/%s\n",basePath,ptr->d_name); else if(ptr->d_type == 4) ///dir { memset(base,'\0',sizeof(base)); strcpy(base,basePath); strcat(base,"/"); strcat(base,ptr->d_name); readFileList(base); } } closedir(dir); return 1; }
static void addToFdc(const NLMISC::CSString& filespec, CFileDescriptionContainer& result) { if (filespec.left(1)=="@") { readFileList(filespec.leftCrop(1),result); } else { result.addFileSpec(filespec); } }
virtual ReadResult readObject(std::istream& fin, const osgDB::ReaderWriter::Options* options) const { std::string fileName = options->getPluginStringData("filename"); if (fileName.empty()) { OSG_NOTICE<<"Error: ReaderWriterRevision unable to determine stream type, cannot not read file."<<std::endl; return ReadResult::FILE_NOT_HANDLED; } std::string ext = osgDB::getLowerCaseFileExtension(fileName); if (!acceptsExtension(ext)) return ReadResult::FILE_NOT_HANDLED; if (ext=="revisions") return readRevisions(fin, fileName, options); else return readFileList(fin, fileName, options); }
int main(void) { DIR *dir; char basePath[1000]; ///get the current absoulte path memset(basePath,'\0',sizeof(basePath)); getcwd(basePath, 999); printf("the current dir is : %s\n",basePath); ///get the file list memset(basePath,'\0',sizeof(basePath)); strcpy(basePath,"./XL"); readFileList(basePath); return 0; }
int main(int argc, char ** args) { int i; memset(buf, 0, sizeof buf); size = atoi(args[1]); fout = fopen("obj/disk", "wb"); conf.disk_size = 1024 * 1024 * size; tot = 2 + conf.disk_size / 512 / 512 / 8; for(i = 0; i < 1024 * 1024 * size / 512; ++ i) fwrite(buf, 1, 512, fout); /* for(i = 2; i < argc; ++ i) { create_file(args[i]); } */ readFileList(args[2], 0); for(i = 0; i < tot; ++ i) { map[i / 8] |= 1 << (i & 0x7); } fseek(fout, 0, SEEK_SET); fwrite(&conf, 1, 512, fout); for(i = 0; i < conf.disk_size / 512 / 512 / 8; ++ i) fwrite(&map[i * 512], 1, 512, fout); // printf("%d\n", i); fwrite(&d[0], 1, 512, fout); return 0; }
DDR_RC getOptions(OMRPortLibrary *portLibrary, int argc, char *argv[], const char **macroFile, const char **supersetFile, const char **blobFile, const char **overrideFile, vector<string> *debugFiles) { DDR_RC rc = DDR_RC_OK; bool showHelp = (argc < 2); bool showVersion = false; for (int i = 1; i < argc; i += 1) { if ((0 == strcmp(argv[i], "--filelist")) || (0 == strcmp(argv[i], "-f")) ) { if (argc < i + 2) { showHelp = true; } else { rc = readFileList(portLibrary, argv[++i], debugFiles); if (DDR_RC_OK != rc) { break; } } } else if ((0 == strcmp(argv[i], "--macrolist")) || (0 == strcmp(argv[i], "-m")) ) { if (argc < i + 2) { showHelp = true; } else { *macroFile = argv[++i]; } } else if ((0 == strcmp(argv[i], "--superset")) || (0 == strcmp(argv[i], "-s")) ) { if (argc < i + 2) { showHelp = true; } else { *supersetFile = argv[++i]; } } else if ((0 == strcmp(argv[i], "--blob")) || (0 == strcmp(argv[i], "-b")) ) { if (argc < i + 2) { showHelp = true; } else { *blobFile = argv[++i]; } } else if ((0 == strcmp(argv[i], "--overrides")) || (0 == strcmp(argv[i], "-o")) ) { if (argc < i + 2) { showHelp = true; } else { *overrideFile = argv[++i]; } } else if ((0 == strcmp(argv[i], "--help")) || (0 == strcmp(argv[i], "-h")) ) { showHelp = true; } else if ((0 == strcmp(argv[i], "--version")) || (0 == strcmp(argv[i], "-v")) ) { showVersion = true; } else { debugFiles->push_back(argv[i]); } } if (showHelp) { printf( "USAGE\n" " ddrgen [OPTIONS] files ...\n" "OPTIONS\n" " -h, --help\n" " Prints this message\n" " -v, --version\n" " Prints the version information.\n" " -f FILE, --filelist FILE\n" " Specify file containing list of input files\n" " -m FILE, --macrolist FILE\n" " Specify input list of macros. See macro tool for format. Default is macroList in current directory.\n" " -s FILE, --superset FILE\n" " Output superset file. Default is superset.out in current directory.\n" " -b FILE, --blob FILE\n" " Output binary blob file. Default is blob.dat in current directory.\n" " -o FILE, --overrides FILE\n" " Optional. File containing a list of files which contain type and field overrides for specific fields.\n" " Overrides are of the format 'typeoverride.STRUCT_NAME.FIELD_NAME=TypeToChangeTo' or\n" " 'fieldoverride.STRUCT_NAME.FIELD_NAME=NewFieldName'\n" ); } else if (showVersion) { printf("Version 0.1\n"); } return rc; }
/*************************************************** * Main */ int main() { bool rereadDir = false, redrawScr = true, redrawDir = false; SystemStartup(); #if (USE_SDCARD == 1) rereadDir = true; FRESULT fres = f_mount(0, &fatfs); if (fres != FR_OK) { showCriticalStatus( " Mount SD error [code:%d]\n" " SD card used for any CNC process\n" " Only RESET possible at now", fres); WAIT_KEY_C(); } #elif (USE_SDCARD == 2) && (USE_KEYBOARD != 0) FRESULT fres; #endif initSmParam(); while (1) { if (SystemProcess() == SYS_READ_FLASH) rereadDir = true; if (rereadDir) { rereadDir = false; readFileList(); redrawScr = true; } if (redrawScr) { redrawScr = false; LCD_Clear(Black); #if (USE_KEYBOARD == 1) win_showMenu(0, 144, 40, 4); scr_puts( "0 - start gcode 1 - manual mode\n" "2 - show gcode 3 - delete file\n" "4 - set time 5 - file info\n" //"6 - scan mode\t " "7 - save conf.file (v1.1)"); #endif #if (USE_KEYBOARD == 2) SetTouchKeys(kbdSelectFile); #endif redrawDir = true; } if (redrawDir) { redrawDir = false; drawFileList(); } showStatusString(); #if (USE_KEYBOARD != 0) switch (kbd_getKey()) { case KEY_A: currentFile--; redrawDir = true; break; case KEY_B: currentFile++; redrawDir = true; break; #if (USE_KEYBOARD == 1) case KEY_STAR: currentFile += FILE_LIST_ROWS; redrawDir = true; break; case KEY_DIES: currentFile -= FILE_LIST_ROWS; redrawDir = true; break; #endif // // Start GCode // case KEY_0: { FLASH_KEYS(); #if (USE_LCD == 1) uint32_t stime; stime = Seconds(); #endif cnc_gfile(&fileList[currentFile][0], GFILE_MODE_MASK_EXEC); while (stepm_inProc()) { scr_fontColor(Yellow, Blue); scr_gotoxy(1, 13); scr_printf(" remain moves: %d", stepm_getRemainLines()); scr_clrEndl(); } stepm_EmergeStop(); #if (USE_LCD == 1) scr_fontColor(Yellow, Blue); scr_gotoxy(0, 13); scr_puts(" FINISH. PRESS C-KEY"); scr_clrEndl(); stime = Seconds() - stime; scr_fontColor(Yellow, Blue); scr_gotoxy(0, 14); scr_printf(" work time: %02d:%02d", stime / 60, stime % 60); scr_clrEndl(); #endif #if (USE_LCD == 2) SetTouchKeys(kbdLast2Lines); #endif FLASH_KEYS(); WAIT_KEY_C(); redrawScr = true; break; } // // Manual Mode // case KEY_1: manualMode(); redrawScr = true; break; #if (USE_SDCARD == 1) // // Show GCode // case KEY_2: FLASH_KEYS(); cnc_gfile(&fileList[currentFile][0], GFILE_MODE_MASK_SHOW | GFILE_MODE_MASK_CHK); scr_printf("\n PRESS C-KEY"); FLASH_KEYS(); while (kbd_getKey() != KEY_C); redrawScr = true; break; // // Delete file // case KEY_3: if (questionYesNo("Delete file:\n'%s'?", &fileList[currentFile][0])) { rereadDir = true; f_unlink(&fileList[currentFile][0]); } else redrawScr = true; break; #endif #if (USE_RTC == 1) // // Set time // case KEY_4: setTime(); redrawScr = true; break; // // Save conf. file // case KEY_7: win_showMsgWin(); saveSmParam(); scr_printf("\n\n\n PRESS C-KEY"); WAIT_KEY_C(); redrawScr = true; break; #endif #if (USE_SDCARD != 0) // // File info // case KEY_5: { FILINFO finf; FIL fid; int c, n; memset(&finf, 0, sizeof(finf)); win_showMsgWin(); scr_setScroll(false); scr_printf("File:%s", &fileList[currentFile][0]); f_stat(&fileList[currentFile][0], &finf); scr_gotoxy(0, 1); scr_printf("Size:%d\n", (uint32_t)finf.fsize); fres = f_open(&fid, &fileList[currentFile][0], FA_READ); if (fres != FR_OK) { #if (USE_SDCARD == 1) scr_printf("Error open file: '%s'\nStatus:%d [%d]", &fileList[currentFile][0], fres, SD_errno); #elif (USE_SDCARD == 2) scr_printf("Error open file: '%s'\nStatus:%d", &fileList[currentFile][0], fres); #endif } else { char str[150]; scr_fontColorInvers(); scr_setScroll(false); // Read lines from 3 to 6 from file and display it for (n = 2; n < 7 && f_gets(str, sizeof(str), &fid) != NULL; n++) { scr_gotoxy(0, n); scr_puts(str_trim(str)); } } scr_fontColorNormal(); scr_gotoxy(8, 7); scr_printf("PRESS C-KEY"); redrawScr = true; do { c = kbd_getKey(); if (c == KEY_B) { char str[150]; scr_fontColorInvers(); for (n = 2; n < 7 && f_gets(str, sizeof(str), &fid) != NULL; n++) { scr_gotoxy(0, n); scr_puts(str_trim(str)); scr_clrEndl(); } } } while (c != KEY_C); f_close(&fid); rereadDir = true; } break; #endif } #endif } }