/* FIXME: This is really broken. */ nebu_List* readDirectoryContents(const char *dirname, const char *prefix) { WIN32_FIND_DATA search; HANDLE hSearch; nebu_List *l, *p; char *searchStr; int prefixLen = 0; l = malloc(sizeof(nebu_List)); l->next= NULL; p = l; if(prefix != NULL) { prefixLen = strlen(prefix); } searchStr = malloc(strlen(dirname) + prefixLen + 3); memcpy(searchStr, dirname, strlen(dirname) + 1); strcat(searchStr, "\\"); if(prefix != NULL) { strcat(searchStr, prefix); } strcat(searchStr, "*"); hSearch = FindFirstFile(searchStr, &search); if(hSearch == INVALID_HANDLE_VALUE) { free(l); free(searchStr); return NULL; } else if(!isHiddenFile(&search)) { pushFile(&search, &p); } while( FindNextFile(hSearch, &search) ) { if(!isHiddenFile(&search)) { pushFile(&search, &p); } } if(GetLastError() != ERROR_NO_MORE_FILES) { fprintf(stderr, "[directory] Error: something bad happened\n"); } FindClose(hSearch); free(searchStr); return l; }
int l_Directory(lua_State* L) { const char* path = luaL_checkstring(L, 1); std::shared_ptr<Directory> directory = Directory::open(path); pushFile(L, directory); return 1; }
int l_File(lua_State* L) { const char* path = luaL_checkstring(L, 1); std::shared_ptr<File> file = File::open(path); pushFile(L, file); return 1; }
/* a "File" object can be different things under the hood. It can either be a FILE_T from wtap struct, which it is during read operations, or it can be a wtap_dumper struct during write operations. A wtap_dumper struct has a WFILE_T member, but we can't only store its pointer here because dump operations need the whole thing to write out with. Ugh. */ File* push_File(lua_State* L, FILE_T ft) { File f = (File) g_malloc(sizeof(struct _wslua_file)); f->file = ft; f->wdh = NULL; f->expired = FALSE; return pushFile(L,f); }
File* push_Wdh(lua_State* L, wtap_dumper *wdh) { File f = (File) g_malloc(sizeof(struct _wslua_file)); f->file = (FILE_T)wdh->fh; f->wdh = wdh; f->expired = FALSE; return pushFile(L,f); }
bool ppInclude::CheckInclude(int token, const std::string &args) { if (token == INCLUDE) { std::string line1 = args; define->Process(line1); ParseName(line1); FindFile(args); pushFile(name); return true; } return false; }
int l_Directory_getSubFiles(lua_State* L) { Directory& directory = getFileOfType<Directory>(L, 1); std::vector<std::shared_ptr<File>> files; directory.getSubFiles(files); const int fileCount = static_cast<int>(files.size()); lua_createtable(L, fileCount, 0); for (int i = 0; i < fileCount; ++i) { pushFile(L, files[i]); lua_rawseti(L, -2, i); } return 1; }
void HceParse::parse(const string& sFileName) { clear(); _contains.push(new Container("")); if(!(yyin = fopen(sFileName.c_str(), "r"))) { error("open file '" + sFileName + "' error :" + string(strerror(errno))); } pushFile(sFileName); yyparse(); }
int l_Directory_eachSubFile(lua_State* L) { Directory& directory = getFileOfType<Directory>(L, 1); luaL_checktype(L, 2, LUA_TFUNCTION); directory.eachSubFile( [L](const std::shared_ptr<File>& file) { FLAT_LUA_EXPECT_STACK_GROWTH(L, 0); lua_pushvalue(L, 2); pushFile(L, file); lua_call(L, 1, 0); } ); return 0; }
//Assumes normalisedDirectoryName ends with the directory name, e.g. "c:\foo" NOT "c:\foo\" bool listFiles(const char *normalisedDirectoryName, std::vector<FileEntry *> *&files) { if (!isDirectory(normalisedDirectoryName)) { return false; } files = new std::vector<FileEntry *>(); DIR *dir; struct dirent *dirp; dir = opendir(normalisedDirectoryName); if (dir == NULL) { return false; } while ((dirp = readdir(dir)) != NULL) { pushFile(files, dirp); } closedir(dir); return true; }
void AdbRunner::run() { switch (m_commandID) { case REBOOT: reboot(); break; case SHELL: shell(); break; case PUSHFILE: pushFile(); break; case PULLFILE: pullFile(); break; case DEVICELIST: deviceList(); break; default: break; } }