void CTilesetManager::Init(const char * szGfxPack) { //Remove all existing tilesets std::vector<CTileset*>::iterator iter = tilesetlist.begin(), lim = tilesetlist.end(); while (iter != lim) { delete (*iter); iter = tilesetlist.erase(iter); lim = tilesetlist.end(); } //Add in tilesets from the new gfxpack (if the gfxpack isn't "Classic") if (strcmp(getFileFromPath(szGfxPack).c_str(), "Classic")) { std::string s = convertPath("gfx/packs/tilesets", szGfxPack) + getDirectorySeperator(); SimpleDirectoryList dirlist(s); short iLength = dirlist.GetCount(); for (short i = 0; i < iLength; i++) { CTileset * tileset = new CTileset(dirlist.current_name()); tilesetlist.push_back(tileset); //If the tileset is "classic" then keep it's index for common operations if (!strcmp(tileset->GetName(), "Classic")) { tClassicTileset = tileset; iClassicTilesetIndex = i; } dirlist.next(); } } //Add in tilesets from the classic tileset to fill the gaps short iLength = filelist.size(); char szTilesetName[128]; for (short i = 0; i < iLength; i++) { strncpy(szTilesetName, getFileFromPath(filelist[i]).c_str(), 128); szTilesetName[127] = 0; //See if the new tileset already exists and if it does, skip it short iTilesetSize = tilesetlist.size(); bool fFound = false; for (short iTileset = 0; iTileset < iTilesetSize; iTileset++) { if (!strcmp(tilesetlist[iTileset]->GetName(), szTilesetName)) { fFound = true; break; } } //Add the tileset if another one by the same name isn't already in the tileset if (!fFound) { CTileset * tileset = new CTileset(filelist[i].c_str()); tilesetlist.push_back(tileset); if (!strcmp(tileset->GetName(), "Classic")) { tClassicTileset = tileset; iClassicTilesetIndex = i; } } } }
//--------------------------------------------------------------------------------- void dirlist(const char* path) { //--------------------------------------------------------------------------------- DIR* pdir = opendir(path); char *dnbuf; if (pdir != NULL) { while(true) { struct dirent* pent = readdir(pdir); if(pent == NULL) break; if(strcmp(".", pent->d_name) != 0 && strcmp("..", pent->d_name) != 0) { dnbuf = (char *)malloc(strlen(pent->d_name)+strlen(path)+2); sprintf(dnbuf, "%s/%s", (strcmp("/",path) == 0)?"":path, pent->d_name); struct stat *statbuf = (struct stat*)malloc(sizeof(statbuf)); stat(dnbuf, statbuf); if(S_ISDIR(statbuf->st_mode)) { printf("%s <DIR>\n", dnbuf); dirlist(dnbuf); } else { printf("%s (%d)\n", dnbuf, (int)statbuf->st_size); } free(dnbuf); free(statbuf); } } closedir(pdir); } else { printf("opendir() failure.\n"); } }
int dirlist(char *pathname) { DIR *dirp; struct dirent *dt; char *currentpath; long max_pathname, namelen, orig_offset; int olderrno; dirp = opendir(pathname); if (dirp == NULL) { perror(":: opendir "); return RET_ERROR; } max_pathname = dirent_buf_size(dirp); namelen = strlen(pathname) + max_pathname + 1; currentpath = malloc(namelen); if (currentpath == NULL) { perror(":: malloc "); closedir(dirp); return RET_ERROR; } memset(currentpath, 0, namelen); orig_offset = sprintf(currentpath, "%s/", pathname); for (;;) { olderrno = errno; dt = readdir(dirp); if (dt == NULL) { /* error detected when errno changed with readdir return NULL. */ if (errno != olderrno) perror(":: readdir "); /* else, end of stream reached */ break; } /* hide . & .. */ if (is_dot_or_dotdot(dt->d_name)) continue; sprintf(currentpath + orig_offset, "%s", dt->d_name); printf("%s\n", currentpath); #ifdef DIRLIST_RECURSIVE if (is_directory(currentpath)) dirlist(currentpath); #endif } free(currentpath); closedir(dirp); return RET_OKAY; }
void zaDir10::porcess(zaWorker * wk) { m_dirty = true; if (wk->m_task ==2) { if (wk->m_len < 20) { soundplayer_play_sound("input_keypress"); if (m_index_log != 0) { m_index_log = 0; return; } if(m_index != 0) { dirlist(m_output[m_index]); } else { strcpy(m_path,m_output[m_index]); int n = 0; for (int i = strlen(m_path) -1;i >=0 ; i --) { if ( m_path[i] == '/') { n ++; if (i==0) m_path[1] = 0; else m_path[i] = 0; } if (n ==2) { break; } } fprintf(stderr,"pwd 2 %s \n",m_path); dirlist(m_path); } } } else m_y -= wk->m_dy; }
// // Search and load plugins // void App::initPlugins() { QString path; QString dir; settings()->get(KEY_SYSTEM_DIR, dir); dir += QString("/") + PLUGINPATH + QString("/"); // First of all, add the dummy output plugin m_dummyOutPlugin = new DummyOutPlugin(NextPluginID++); connect(m_dummyOutPlugin, SIGNAL(activated(Plugin*)), this, SLOT(slotPluginActivated(Plugin*))); addPlugin(m_dummyOutPlugin); QDir d(dir); d.setFilter(QDir::Files); if (d.exists() == false || d.isReadable() == false) { fprintf(stderr, "Unable to access plugin directory %s.\n", (const char*) dir); return; } QStringList dirlist(d.entryList()); QStringList::Iterator it; for (it = dirlist.begin(); it != dirlist.end(); ++it) { // Ignore everything else than .so files if ((*it).right(2) != QString("so")) { continue; } path = dir + *it; probePlugin(path); } // // Use the output plugin that user has selected previously // QString config; settings()->get(KEY_OUTPUT_PLUGIN, config); Plugin* plugin = searchPlugin(config, Plugin::OutputType); if (plugin != NULL) { m_outputPlugin = static_cast<OutputPlugin*> (plugin); } else { m_outputPlugin = m_dummyOutPlugin; } slotPluginActivated(m_outputPlugin); }
/** * Prepare for running workunits, get tmpdir stuff set up, divide video * fragments between threads and create VideoSegment instances for each video * fragment */ int Balancer::prepare_work_units() { int i, images_per_thread, remainder; char cmd[256], message[256]; // Create video fragments sprintf(cmd, "ffmpeg -i %s -r %i -f image2 %s/frame-%%04d.jpg " "-loglevel quiet", this->config->input, this->config->framerate, this->tmp); runcmd(cmd, this->log); // Get list of input images dirlist(this->tmp, &this->input_images_count, &this->input_image_paths); // Figure out what the processed image paths should be this->processed_image_paths = (char**)malloc(sizeof(char[256]) * this->config->threads); for (i = 0; i < this->config->threads; i++) { this->processed_image_paths[i] = (char*)malloc(sizeof(char[256])); sprintf(this->processed_image_paths[i], "res-%i.jpg", i); } // How many images is each thread going to handle. Note that the last // thread will likely have a couple extra if this division is not even images_per_thread = this->input_images_count / this->config->threads; // Allocate space for workunits and input image counts this->workunits = (WorkUnit**)malloc(sizeof(WorkUnit*) * this->config->threads); // Loop throught this->segments and set up the work units that // each thread will be processing. Note that this stops 1 before the end of // this->workunits, as the last member of this->workunits will have a // different number of images to process for (i = 0; i < this->config->threads - 1; i++) { // Create workunit this->workunits[i] = new WorkUnit(this->config, this->tmp, &this->input_image_paths[i * images_per_thread], images_per_thread, this->processed_image_paths[i]); sprintf(message, "Workunit %i with %i inputs", i, images_per_thread); this->log->log(message, DEBUG_V); } // Now we need to find how many input images are left and process them with // the last thread remainder = this->input_images_count - (images_per_thread * (this->config->threads - 1)); this->workunits[i] = new WorkUnit(this->config, this->tmp, &this->input_image_paths[input_images_count - remainder - 1], remainder, this->processed_image_paths[this->config->threads - 1]); sprintf(message, "Workunit %i with %i inputs", this->config->threads - 1, remainder); this->log->log(message, DEBUG_V); return 0; }
log_pattern find_greatest_index(std::string dir, size_t boot_count) { std::vector<log_pattern> d; dirlist(dir, std::back_inserter(d)); auto it = std::remove_if(std::begin(d), std::end(d), [&](log_pattern const & a){ return a.boot_count != boot_count; }); d.resize(it - std::begin(d)); if(d.size() == 0) throw std::out_of_range("No file available."); return *std::max_element(std::begin(d), std::end(d)); }
bool Doc::readDeviceClasses() { DeviceClass* dc = NULL; QString path = QString::null; QString dir; _app->settings()->get(KEY_SYSTEM_DIR, dir); dir += QString("/") + DEVICECLASSPATH + QString("/"); QDir d(dir); d.setFilter(QDir::Files); d.setNameFilter("*.deviceclass"); if (d.exists() == false || d.isReadable() == false) { QMessageBox::warning(_app, "QLC", "Unable to open or read from device directory! Check settings and permissions."); return false; } QStringList dirlist(d.entryList()); QStringList::Iterator it; QList <QString> list; // Our stringlist that contains the files' contents // Put a slash to the end of the directory name if it isn't there if (dir.right(1) != QString("/")) { dir = dir + QString("/"); } // Go thru all files for (it = dirlist.begin(); it != dirlist.end(); ++it) { path = dir + *it; FileHandler::readFileToList(path, list); dc = createDeviceClass(list); if (dc != NULL) { dc->setFile(path); m_deviceClassList.append(dc); } // 03-Jan-2002 / HJu // The list wasn't cleared between files while (list.isEmpty() == false) { list.first(); delete list.take(); } } return true; }
//////////////////////// // Device Class stuff // //////////////////////// // // Read all device classes from files // void App::initDeviceClasses() { DeviceClass* dc = NULL; QString path = QString::null; QString dir; settings()->get(KEY_SYSTEM_DIR, dir); dir += QString("/") + DEVICECLASSPATH + QString("/"); QDir d(dir); d.setFilter(QDir::Files); d.setNameFilter("*.deviceclass"); if (d.exists() == false || d.isReadable() == false) { QString msg("Unable to read from device directory!"); QMessageBox::warning(this, KApplicationNameShort, msg); return; } QStringList dirlist(d.entryList()); QStringList::Iterator it; QPtrList <QString> list; // Our stringlist that contains the files' contents // Put a slash to the end of the directory name if it isn't there if (dir.right(1) != QString("/")) { dir = dir + QString("/"); } // Go thru all files for (it = dirlist.begin(); it != dirlist.end(); ++it) { path = dir + *it; FileHandler::readFileToList(path, list); dc = DeviceClass::createDeviceClass(list); if (dc != NULL) { addDeviceClass(dc); } // The list needs to be cleared between files while (list.isEmpty() == false) { list.first(); delete list.take(); } } }
/** * Files are ordered by log.XXX.YYY where XXX is the boot count and YYY is the sequence number * Files are rotated by incrementing the YYY within a single boot count. * The oldest file is then the least XXX and the least YYY * * busyrotate assumes the system time is corrupt, and starts over at each * power cycle. * */ log_pattern find_oldest_file(std::string dir) { std::priority_queue<log_pattern, std::vector<log_pattern>, std::greater<log_pattern>> q; dirlist(dir, pusher(q)); auto t = q.top(); while(t.is_active) { q.pop(); t = q.top(); } return t; }
//--------------------------------------------------------------------------------- int main(int argc, char **argv) { //--------------------------------------------------------------------------------- // Initialise the console, required for printf consoleDemoInit(); if (nitroFSInit()) { dirlist("/"); } else { iprintf("nitroFSInit failure: terminating\n"); } while(1) { swiWaitForVBlank(); } return 0; }
int main( int argc, char **argv ){ string header_file( "header.mak" ); string programs_file( "programs.mak" ); // Flag indicates whether the CCFLAGS and CFLAGS output should // have -g debugging option omitted bool noDebugFlag( false ); // Flag indicates using gnu compiler // bool useGCC = false; bool useGCC = true; // check gnu compiler make or sun compiler make // if first letter of executable is 'g' then gnu otherwise sun char *exename = argv[0]; char c; while((c = *exename++)) { if(c == '/') { argv[0] = exename; } } if(argv[0][0] == 'g') { useGCC = true; } // // Process command line options // while( argc--, *++argv != 0 && **argv == '-' ){ if( strcmp( *argv, "-header" ) == 0 && argv[ 1 ] != 0 ){ header_file = *++argv; argc--; } else if( strcmp( *argv, "-no-header" ) == 0 ){ header_file = "//"; } else if( strcmp( *argv, "-programs" ) == 0 && argv[ 1 ] != 0 ){ programs_file = *++argv; argc--; } else if( strcmp( *argv, "-no-programs" ) == 0 ){ programs_file = "//"; } else if(strcmp("-no-debug",*argv) == 0){ noDebugFlag = true; } else { switch( *++*argv ){ case 'd': debug = true; break; default: cerr << "Invalid option: -" << **argv << endl; exit( 1 ); } } } // // Read the current directory (and cmd line arguments) to find // file names. // DirList dirlist( argc, argv ); // // Now write the makefile // Write write( dirlist, noDebugFlag, useGCC, header_file, programs_file ); return 0; }
void Doc::initializeJoystickPlugin() { QString path; QString dir = _app->settings()->pluginPath(); void* handle = NULL; JoystickPlugin* plugin = NULL; if (m_joystickPlugin != NULL) { return; } qDebug("Probing %s for plugin objects...", (const char*) dir); QDir d(dir); d.setFilter(QDir::Files); if (d.exists() == false || d.isReadable() == false) { fprintf(stderr, "Unable to access plugin directory %s.\n", (const char*) dir); return; } QStringList dirlist(d.entryList()); QStringList::Iterator it; for (it = dirlist.begin(); it != dirlist.end(); ++it) { // Ignore everything else than .so files if ((*it).right(2) != QString("so")) { continue; } path = dir + *it; qDebug("Probing file: " + path); handle = ::dlopen((const char*) path, RTLD_LAZY); if (handle == NULL) { fprintf(stderr, "dlopen: %s\n", dlerror()); } else { typedef QObject* create_t(); typedef void destroy_t(QObject*); create_t* create = (create_t*) ::dlsym(handle, "create"); destroy_t* destroy = (destroy_t*) ::dlsym(handle, "destroy"); if (create == NULL || destroy == NULL) { fprintf(stderr, "dlsym(init): %s\n", dlerror()); } else { plugin = (JoystickPlugin*) create(); PluginInfo info; plugin->info(info); fprintf(stderr, "Plugin: %s\nType: %s\nVersion: %ld.%ld.%ld-%ld\n\n", (const char*) info.name, (const char*) info.type, info.version >> 24, info.version >> 16, info.version >> 8, info.version & 0xff); m_joystickPlugin = plugin; m_joystickPlugin->init(); break; } } } }
/* Lesen der Datei vom Socket und schreiben der Reponse */ void handleGETrequest(int sockfd) { int n; char in[MAXLINE], tout[MAXLINE]; char *ptr, *method, *uri, *version; char *request[2]; char *mime; char status[256], date[256], language[256], charset[256], *changeDate=NULL, *html="\0"; char *fullPath; long length; memset ((void *)in, '\0', MAXLINE); for(;;){ // Daten vom Socket lesen n = read (sockfd, in, MAXLINE); if (n == 0){ return; } else if (n < 0){ err_abort("Fehler beim Lesen des Sockets!"); } printf("Client message %s \n", in); //cut strings in ein array von char pointern ptr = strtok(in, " \r"); method = ptr; ptr = strtok (NULL, " \r"); uri = ptr; ptr = strtok (NULL, " \r"); version = ptr; char file[256]; strcpy(file,uri); //create full Path fullPath = (char *)malloc(strlen(path) + strlen(uri)); strcpy(fullPath,path); strcat(fullPath,uri); printf("fullPath: %s\n", fullPath); printf("path: %s\n", path); printf("uri: %s\n", uri); FILE *pFile; DIR *pDir; pFile = fopen(fullPath,"r"); printf("opening directory: %s\n",fullPath); pDir = opendir (fullPath); changeDate = get_file_mod_time(fullPath); //Prüfung ob file oder directory if ((pFile!=NULL)&&(pDir==NULL)){ printf("uri: %s",fullPath); fseek(pFile,0,SEEK_END); length=ftell(pFile); fseek(pFile, 0, SEEK_SET); html = malloc (length); if (html){ fread (html, 1, length, pFile); } fclose (pFile); strcpy(status, "HTTP/1.1 200 OK\r\n"); printf("Status content: %s\n", status); } else if(pDir!=NULL){ closedir(pDir); printf("DEBUG1: %s \n",path); char* t=dirlist(uri); printf("DEBUG2: %s \n",path); strcpy(status, "HTTP/1.1 200 OK\r\n"); html = malloc (strlen(t)); strcpy(html,t); } else{ printf("the file or directory %s was not available \n", uri); printf("FullPath: %s \n",path); strcpy(status, "HTTP/1.1 404 Not Found\r\n"); } // Anpassung des mime-typs if(pDir==NULL){ mime = strtok(file,"."); mime = strtok(NULL,"."); printf("mime: %s\n", mime); if (strcmp(mime, "html")==0) strcpy(mime, "text/html"); if (strcmp(mime, "txt")==0) strcpy(mime, "text/plain"); if (strcmp(mime, "jpg")==0) strcpy(mime, "image/jpeg"); printf("mime: %s\n",mime); } else{ mime = strtok(file,"."); strcpy(mime, "text/html"); } // Behandlung des Headers für Content-Type und Zeichensatz strcpy(language, "Content-Language: de\r\nContent-Type: "); strcpy(charset, "; charset=iso-8859-1\r\n\n"); char out[2048]; strcpy(out,status); strcat(out,timestamp()); if(changeDate!=NULL){ strcat(out,changeDate); } else{ printf("ChangeDate = NULL \n"); } strcat(out,language); strcat(out,mime); strcat(out,charset); if (strcmp(mime,"image/jpeg")!=0) strcat(out,html); printf("\n\n\nServer response:\n%s\n",out); printf("------------------------------------ mime: %s ------------------------------------- \n",mime); printf("size: %zu \n", strlen(out)); // Daten schreiben if(write (sockfd, out, sizeof(char[strlen(out)])) != sizeof(char[strlen(out)])){ printf("error: sizeof(out): %lu != write\n",sizeof(char[strlen(out)])); err_abort ("Fehler beim Schreiben des Sockets!"); } if (strcmp(mime,"image/jpeg")==0){ write (sockfd, html, length); } free(fullPath); printf("ende \n\n"); } }