int main(int argc, char *argv[]) { char *input_file, *output_file; /* the program needs to be called as: * binconv <input_file> <output_file> */ if (argc != 3){ printf("Wrong parameters! Exit!!\n"); exit(1); } if(strcmp(get_filename_ext(argv[1]), "dat")!=0){ printf("First argument must be a dat file\n"); exit(1); } if(strcmp(get_filename_ext(argv[2]), "bin")!=0){ printf("Second argument must be a bin file\n"); exit(1); } input_file = argv[1]; output_file = argv[2]; binconv(input_file, output_file); printf("%s created\n", output_file); return 0; }
int main(void) { printf("%s\n", get_filename_ext("test.tiff")); printf("%s\n", get_filename_ext("test.blah.tiff")); printf("%s\n", get_filename_ext("test.")); printf("%s\n", get_filename_ext("test")); printf("%s\n", get_filename_ext("...")); return 0; }
vector<string> ofxRemoteUIServer::getAvailablePresets(){ vector<string> presets; #ifdef OF_AVAILABLE ofDirectory dir; dir.listDir(ofToDataPath(OFXREMOTEUI_PRESET_DIR)); vector<ofFile> files = dir.getFiles(); for(int i = 0; i < files.size(); i++){ string fileName = files[i].getFileName(); string extension = files[i].getExtension(); std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower); if (files[i].isFile() && extension == "xml"){ //cout << "preset name: " << fileName << endl; string presetName = fileName.substr(0, fileName.size()-4); presets.push_back(presetName); } } #else DIR *dir; struct dirent *ent; if ((dir = opendir (OFXREMOTEUI_PRESET_DIR)) != NULL) { while ((ent = readdir (dir)) != NULL) { if ( strcmp( get_filename_ext(ent->d_name), "xml") == 0 ){ string fileName = string(ent->d_name); string presetName = fileName.substr(0, fileName.size()-4); presets.push_back(presetName); } } closedir (dir); } #endif return presets; }
int is_allowed_file_type (char *name) { char delim[] = ","; char *exclude = NULL; char *result = NULL; char *ext = NULL; int ret = 0; if(exclude_extensions != NULL) { exclude = malloc(sizeof(char) * strlen(exclude_extensions) + 1); strcpy(exclude, exclude_extensions); ext = stolower(get_filename_ext(name)); if (ext != NULL && ext != "") { result = strtok(exclude, delim); while(result != NULL) { if(strcmp(result, ext) ==0) { ret = 1; break; } else result = strtok(NULL, delim); } } free(exclude); } return (ret); }
int is_image_file(const char *filename) { const char* ext = get_filename_ext(filename); int lenExt = strlen(ext); if (lenExt==3) { if ( ((ext[0]=='b' || ext[0]=='B') && (ext[1]=='m' || ext[1]=='M') && (ext[2]=='p' || ext[2]=='P') ) || ((ext[0]=='j' || ext[0]=='J') && (ext[1]=='p' || ext[1]=='P') && (ext[2]=='g' || ext[2]=='G') ) || ((ext[0]=='p' || ext[0]=='P') && (ext[1]=='n' || ext[1]=='N') && (ext[2]=='g' || ext[2]=='G') ) ) { return 1; } } else if (lenExt==4) { if ( ((ext[0]=='j' || ext[0]=='J') && (ext[1]=='p' || ext[1]=='P') && (ext[2]=='e' || ext[2]=='E') && (ext[3]=='g' || ext[3]=='G') ) ) { return 1; } } return 0; }
void get_dir(const char *path) { DIR *fd; struct dirent *file; char new_path[512]; strncpy(new_path, path, 512); if (NULL == (fd = opendir(new_path))) { printf("\xb[3;1HDirectory empty..."); return; } memset(picker, 0, sizeof(picker_s)); strncpy(picker->now_path, new_path, 512); while ((file = readdir(fd))) { if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, "..")) continue; if (file->d_type != DT_DIR) { const char *ext = get_filename_ext(file->d_name); if (strcasecmp(ext, "bin") != 0 && strcasecmp(ext, "dat") != 0 && strcasecmp(ext, "3dsx") != 0) continue; } // file name strncpy(picker->files[picker->file_count].name, file->d_name, 512); // build absolute path if (end_with(new_path, '/')) { snprintf(picker->files[picker->file_count].path, 512, "%s%s", new_path, file->d_name); } else { snprintf(picker->files[picker->file_count].path, 512, "%s/%s", new_path, file->d_name); } // dir vs file if (file->d_type != DT_DIR) { picker->files[picker->file_count].isDir = false; // file size struct stat st; stat(picker->files[picker->file_count].path, &st); picker->files[picker->file_count].size = (u64) st.st_size; } else { picker->files[picker->file_count].isDir = true; } picker->file_count++; } if (picker->file_count > 1) { qsort(picker->files, (size_t) picker->file_count, sizeof(*picker->files), alphasort); } closedir(fd); }
static FRESULT play_directory (const char* path, unsigned char seek) { FRESULT res; FILINFO fno; DIR dir; char *fn; /* This function is assuming non-Unicode cfg. */ char buffer[200]; #if _USE_LFN static char lfn[_MAX_LFN + 1]; fno.lfname = lfn; fno.lfsize = sizeof(lfn); #endif res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { for (;;) { if(0 == exitMp3) { res = f_readdir(&dir, &fno); /* Read a directory item */ if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ if (fno.fname[0] == '.') continue; /* Ignore dot entry */ #if _USE_LFN fn = *fno.lfname ? fno.lfname : fno.fname; #else fn = fno.fname; #endif if (fno.fattrib & AM_DIR) { /* It is a directory */ } else { /* It is a file. */ sprintf(buffer, "%s/%s", path, fn); // Check if it is an mp3 file if (strcmp("MP3", get_filename_ext(buffer)) == 0) { // Skip "seek" number of mp3 files... if (seek) { seek--; continue; } play_mp3(buffer); } } } else { break; } } } return res; }
char loadCustomElements(void) { char loadLoc[256]; char saveLoc[256]; //Load the file names of everything in the loading directory strcpy(loadLoc, ROOT_FOLDER); strcpy(saveLoc, ROOT_FOLDER); strcat(loadLoc, ELEMENTS_FOLDER); strcat(saveLoc, ELEMENTS_FOLDER); strcat(saveLoc, LIST_SAVE); strcat(saveLoc, LIST_EXTENSION); FILE* sp = fopen(saveLoc, "wb"); if (sp == NULL) { __android_log_write(ANDROID_LOG_ERROR, "LOG", "loadCustomElements: Unable to open file"); return FALSE; } struct stat sb; if (!stat(loadLoc, &sb) == 0 || !S_ISDIR(sb.st_mode)) { __android_log_write(ANDROID_LOG_ERROR, "LOG", "loadCustomElements: Directory doesn't exist!"); return FALSE; } DIR* mydir = opendir(loadLoc); if (!mydir) { __android_log_write(ANDROID_LOG_ERROR, "LOG", "loadCustomElements: Null directory! Quitting."); __android_log_write(ANDROID_LOG_ERROR, "LOG", strerror(errno)); return FALSE; } struct dirent *entry = NULL; while((entry = readdir(mydir))) /* If we get EOF, the expression is 0 and the loop stops. */ { if (!strcmp(get_filename_ext(entry->d_name), ELEMENT_EXTENSION)) { char location[256]; strcpy(location, loadLoc); strcat(location, entry->d_name); loadCustomElement(location); fprintf(sp, entry->d_name); fprintf(sp, "\n"); } } closedir(mydir); fclose(sp); return TRUE; }
dictionary * iniparser_load_from_file(const char * ininame) { enum FILE_EXT ext = get_filename_ext(ininame); if(FILE_EXT_SH == ext) { return iniparser_load_sh(ininame); } else if(FILE_EXT_INI == ext) { return iniparser_load(ininame); } else { return NULL; } }
int sendHeader(int fd, int returncode, char* filename) { char header[2048]; switch (returncode) { case 200: if (connClose){ if (strcmp(get_filename_ext(filename), "jpeg") == 0){ sprintf(header, header200Fmt, "Content-Type: image\r\n", "Connection: close\r\n"); } else { sprintf(header, header200Fmt, "Content-Type: text/html\r\n", "Connection: close\r\n"); } } else { if (strcmp(get_filename_ext(filename), "jpeg") == 0){ sprintf(header, header200Fmt, "Content-Type: image\r\nKeep-Alive: timeout=30, max=100\r\n", ""); } else { sprintf(header, header200Fmt, "Content-Type: text/html\r\nKeep-Alive: timeout=30, max=100\r\n", ""); } } sendMessage(fd, header); return strlen(header); break; case 400: sprintf(header, header400Fmt, "Connection: close\r\n"); sendMessage(fd, header); return strlen(header); break; case 404: sprintf(header, header404Fmt, "Connection: close\r\n"); sendMessage(fd, header); return strlen(header); break; } return -1; }
static void test_folder(const char *folder) { char **files; int num_files, i; files = NULL; num_files = 0; listdir(folder, &files, &num_files); for (i = 0; i < num_files; ++i) { if (strcmp("cs", get_filename_ext(files[i]))) continue; test_file(files[i]); } }
int how_many_files_directory_by_extension(const char *path, const char *ext){ const char *ext_aux = NULL; struct dirent *ent = NULL; int r = 0; DIR *dir = opendir(path); while (ent = readdir(dir)) { ext_aux = get_filename_ext(ent->d_name); if (strcmp (ext_aux, ext) == 0){ r++; } } closedir(dir); return r; }
void insert_files_directory_by_extension(owner_file_t *file_names, const char *path, const char *ext){ const char *ext_aux = NULL; int index = -1; DIR *dir = opendir(path); struct dirent *ent; while (ent = readdir(dir)) { ext_aux = get_filename_ext(ent->d_name); if (strcmp (ext_aux, ext) == 0){ index = index +1; strcpy(file_names[index].file_name, ent->d_name); } } closedir(dir); }
int is_sig_file(const char *filename) { const char* ext = get_filename_ext(filename); size_t lenExt = strlen(ext); if (lenExt==3) { if ( ((ext[0]=='s' || ext[0]=='S') && (ext[1]=='i' || ext[1]=='I') && (ext[2]=='g' || ext[2]=='G') ) ) { return 1; } } return 0; }
/* abc.def -> abc.beertorrent abcdef -> abcdef.beertorrent .abcdef -> abcdef.beertorrent */ char *beertorrent_extension(char *s) { char *bt ; char tmp ; char *dot = get_filename_ext(s) ; size_t size = strlen(s) ; if(dot == NULL) dot = s+size ; else dot-- ; bt = (char*) malloc(sizeof(char)*(size+13)) ; tmp = *dot ; *dot = '\0' ; strcpy(bt,s) ; *dot = tmp ; bt = strcat(bt,".beertorrent"); return bt ; }
void run(char *path, int argc, char* argv[], int display, int wait, char* ext) { int file_count, children_file_count; char *entry_path; DIR *dir; dirent_t *entry; file_count = 0; dir = opendir(path); if(dir == NULL) { perror("Invalid directory name\n"); exit(-1); } while(entry = readdir(dir)) { if(!strcmp(entry->d_name, ".") || !strcmp(entry->d_name, "..")) continue; if(entry->d_type == DT_DIR) { entry_path = malloc(strlen(path) + strlen(entry->d_name) + 2); sprintf(entry_path, "%s/%s", path, entry->d_name); insert_argv_path(argc, argv, entry_path); execute_child_process(entry_path, argv); free(entry_path); } else if(entry->d_type == DT_REG) { if(ext == NULL || strcmp(get_filename_ext(entry->d_name), ext) == 0) { file_count += 1; } } } if(wait) sleep(15); children_file_count = collect_children_file_count(); if(display) { printf("Directory: %s \nFile count: %d\nChildren file count: %d\n-----------\n", path, file_count, children_file_count); } closedir(dir); exit(file_count + children_file_count); }
int load(char *path, long offset) { // check for reboot/poweroff if (strcasecmp(path, "reboot") == 0) { reboot(); } else if (strcasecmp(path, "shutdown") == 0) { poweroff(); } else { const char *ext = get_filename_ext(path); if (strcasecmp(ext, "bin") == 0 || strcasecmp(ext, "dat") == 0) { return load_bin(path, offset); } else if (strcasecmp(ext, "3dsx") == 0) { return load_3dsx(path); } else { debug("Invalid file: %s\n", path); return -1; } } return 0; }
/** * serve a static file to the client as a very simple http server */ int callback_static_file (const struct _u_request * request, struct _u_response * response, void * user_data) { void * buffer = NULL; long length; FILE * f; char * file_path = malloc(strlen(request->http_url)+strlen(STATIC_FOLDER)+sizeof(char)); const char * content_type; snprintf(file_path, (strlen(request->http_url)+strlen(STATIC_FOLDER)+sizeof(char)), "%s%s", STATIC_FOLDER, request->http_url); if (access(file_path, F_OK) != -1) { f = fopen (file_path, "rb"); if (f) { fseek (f, 0, SEEK_END); length = ftell (f); fseek (f, 0, SEEK_SET); buffer = malloc(length*sizeof(void)); if (buffer) { fread (buffer, 1, length, f); } fclose (f); } if (buffer) { content_type = u_map_get((struct _u_map *)user_data, get_filename_ext(request->http_url)); response->binary_body = buffer; response->binary_body_length = length; u_map_put(response->map_header, "Content-Type", content_type); response->status = 200; } else { response->string_body = u_strdup(""); response->status = 404; } } else { response->string_body = u_strdup(""); response->status = 404; } free(file_path); return U_OK; }
int32_t minpf_load_from_dir(const char* directory_path, minpf_invoke_service_func func) { DIR *dir; struct dirent* content; char libraryPath[MINPF_MAX_PATH_LEN]; minpf_plugin_manager* mgr = minpf_get_plugin_manager(); if (!directory_path || directory_path[0] == '\0') // Check that the path is non-empty. return -1; mgr->platformServices.invokeService = func; dir= opendir(directory_path); if(!dir) { fprintf(stderr,"Unable to open folder %s\n",directory_path); return -1; } int32_t rc = -1; while((content=readdir(dir))!=NULL) { if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) continue; //ignore files with incorrect extensions if ( strcmp(get_filename_ext(content->d_name), minpf_get_dynamic_library_extension()) != 0) continue; strcpy(libraryPath, directory_path); strcat(libraryPath, MINPF_FILE_SEPARATOR); strcat(libraryPath, content->d_name); if (minpf_load(libraryPath) != 0) continue; rc = 0; } auto dir_rc = closedir(dir); return rc || dir_rc; }
void pick_file(file_s *picked, const char *path) { picker = malloc(sizeof(picker_s)); get_dir(path); // key repeat timer static time_t t_start = 0, t_end = 0, t_elapsed = 0; while (aptMainLoop()) { hidScanInput(); u32 kHeld = hidKeysHeld(); u32 kDown = hidKeysDown(); if (hidKeysUp()) { time(&t_start); // reset held timer } if (kDown & KEY_DOWN) { picker->file_index++; if (picker->file_index >= picker->file_count) picker->file_index = 0; time(&t_start); } else if (kHeld & KEY_DOWN) { time(&t_end); t_elapsed = t_end - t_start; if (t_elapsed > 0) { picker->file_index++; if (picker->file_index >= picker->file_count) picker->file_index = 0; svcSleep(100); } } if (kDown & KEY_UP) { picker->file_index--; if (picker->file_index < 0) picker->file_index = picker->file_count - 1; time(&t_start); } else if (kHeld & KEY_UP) { time(&t_end); t_elapsed = t_end - t_start; if (t_elapsed > 0) { picker->file_index--; if (picker->file_index < 0) picker->file_index = picker->file_count - 1; svcSleep(100); } } if (kDown & KEY_A) { int index = picker->file_index; if (!picker->files[index].isDir) { if (confirm(0, "Launch \"%s\" ?", picker->files[index].name)) { strncpy(picked->name, picker->files[index].name, 512); strncpy(picked->path, picker->files[index].path, 512); picked->isDir = picker->files[index].isDir; picked->size = picker->files[index].size; break; } } else { get_dir(picker->files[index].path); } } else if (kDown & KEY_X) { int index = picker->file_index; if (!picker->files[index].isDir) { const char *ext = get_filename_ext(picker->files[index].name); if (strcasecmp(ext, "3dsx") == 0) { if (confirm(3, "Add entry to boot menu: \"%s\" ?", picker->files[index].name)) { if (config->count > CONFIG_MAX_ENTRIES - 1) { debug("Maximum entries reached (%i)\n", CONFIG_MAX_ENTRIES); } else if (configAddEntry(picker->files[index].name, picker->files[index].path, 0) == 0) { debug("Added entry: %s\n", picker->files[index].name); } else { debug("Error adding entry: %s\n", picker->files[index].name); } } } } } else if (kDown & KEY_B) { // exit if we can't go back if (strlen(picker->now_path) <= 1) break; // remove slash if needed if (end_with(picker->now_path, '/')) picker->now_path[strlen(picker->now_path) - 1] = '\0'; // build path char *slash = strrchr(picker->now_path, '/'); if (slash == NULL) break; int len = (int) (slash - picker->now_path); picker->now_path[len] = '\0'; // enter new dir get_dir(picker->now_path); } gfxClear(); gfxDrawText(GFX_TOP, GFX_LEFT, &fontTitle, "*** Select a file ***", 130, 20); int minX = 16; int maxX = 400 - 16; int minY = 32; int maxY = 240 - 16; drawRect(GFX_TOP, GFX_LEFT, minX, minY, maxX, maxY, (u8) 0xFF, (u8) 0xFF, (u8) 0xFF); minY += 20; int i, y = 0; int page = picker->file_index / MAX_LINE; for (i = page * MAX_LINE; i < page * MAX_LINE + MAX_LINE; i++) { if (i >= picker->file_count) break; if (i == picker->file_index) { gfxDrawRectangle(GFX_TOP, GFX_LEFT, (u8[]) {0xDC, 0xDC, 0xDC}, minX + 4, minY + 16 * y, maxX - 23, 15); gfxDrawTextN(GFX_TOP, GFX_LEFT, &fontSelected, picker->files[i].name, 47, minX + 6, minY + 16 * y); if (!picker->files[i].isDir) { gfxDrawText(GFX_BOTTOM, GFX_LEFT, &fontTitle, "Informations", minX + 6, 20); gfxDrawText(GFX_BOTTOM, GFX_LEFT, &fontDefault, "Press (A) to launch\nPress (X) to add to boot menu", minX + 12, 40); } } else { gfxDrawTextN(GFX_TOP, GFX_LEFT, &fontDefault, picker->files[i].name, 47, minX + 6, minY + 16 * y); } y++; }
int main(int argc, char *argv[]) { if (argc < 2) { printf("Usage: %s <image file> <output image>\n", argv[0]); return 1; } if (SDL_Init(SDL_INIT_EVERYTHING) == -1) { printf("Failed to init SDL\n"); return -1; } int sdlimgflags = IMG_INIT_JPG|IMG_INIT_PNG|IMG_INIT_TIF; if (IMG_Init(sdlimgflags) != sdlimgflags) { printf("Warning: failed to init support for some image formats\n"); printf("IMG_Init: %s\n", IMG_GetError()); } printf("press spacebar to re-sort the picture once it's done.\n"); start:; // LOOLLOLOLOLOLOLO SDL_Surface *rawimg = IMG_Load(argv[1]); if (!rawimg) { printf("Could not load image: %s\n", argv[1]); return -1; } screen = SDL_SetVideoMode(rawimg->w, rawimg->h, 32, SDL_SWSURFACE); if (!screen) { printf("Failed to initialize screen\n"); return -1; } SDL_Surface *img = SDL_ConvertSurface(rawimg, screen->format, screen->flags); if (!img) { printf("Failed to convert input image to 32bit color\n"); return -1; } SDL_FreeSurface(rawimg); SDL_BlitSurface(img,NULL,screen,NULL); SDL_Flip(screen); SDL_Delay(500); sort_pixels(img->pixels, img->w * img->h, img); SDL_Flip(img); SDL_BlitSurface(img, NULL, screen, NULL); SDL_Flip(screen); if (argc >= 3) if (!strcmp(get_filename_ext(argv[2]), "bmp")) SDL_SaveBMP(img, argv[2]); else { printf("Cannot save image if the format is not .bmp\n"); fflush(stdout); } SDL_Event e; int paused = 1; while (paused) { while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT) paused = 0; if (e.type == SDL_KEYDOWN) { if (e.key.keysym.sym == SDLK_SPACE) { SDL_FreeSurface(img); goto start; // LOLOLOLOLOLOLOLOLO } } } } IMG_Quit(); SDL_FreeSurface(img); SDL_Quit(); }
output_file_list(server *srv, connection *con, char* fullpath, char* filename, buffer *out) { buffer* buffer_filename = buffer_init(); buffer_copy_string(buffer_filename,filename); buffer_urldecode_path(buffer_filename); buffer_append_string_len(out, CONST_STR_LEN("<div class='albumDiv' title=''>\n")); buffer_append_string_len(out, CONST_STR_LEN("<table class='thumb-table-parent'>\n")); buffer_append_string_len(out, CONST_STR_LEN("<tbody><tr><td>\n")); buffer_append_string_len(out, CONST_STR_LEN("<div class='picDiv'>")); int use_http_connect = 0; char* aa = get_filename_ext(fullpath); int len = strlen(aa)+1; char* file_ext = (char*)malloc(len); memset(file_ext,'\0', len); strcpy(file_ext, aa); for (int i = 0; file_ext[i]; i++) file_ext[i] = tolower(file_ext[i]); if( strcmp(file_ext,"jpg")==0 || strcmp(file_ext,"jpeg")==0|| strcmp(file_ext,"png")==0 || strcmp(file_ext,"gif")==0 || strcmp(file_ext,"bmp")==0 ){ buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='imgfileDiv bicon'>")); } else if( strcmp(file_ext,"mp3")==0 || strcmp(file_ext,"m4a")==0 || strcmp(file_ext,"m4r")==0 || strcmp(file_ext,"wav")==0 ){ use_http_connect = 1; buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='audiofileDiv bicon'>")); } else if( strcmp(file_ext,"mp4")==0 || strcmp(file_ext,"rmvb")==0 || strcmp(file_ext,"m4v")==0 || strcmp(file_ext,"wmv")==0 || strcmp(file_ext,"avi")==0 || strcmp(file_ext,"mpg")==0 || strcmp(file_ext,"mpeg")==0 || strcmp(file_ext,"mkv")==0 || strcmp(file_ext,"mov")==0 || strcmp(file_ext,"flv")==0 || strcmp(file_ext,"3gp")==0 || strcmp(file_ext,"m2v")==0 || strcmp(file_ext,"rm")==0 ){ use_http_connect = 1; buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='videofileDiv bicon'>")); } else if(strcmp(file_ext,"doc")==0||strcmp(file_ext,"docx")==0) buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='docfileDiv bicon'>")); else if(strcmp(file_ext,"ppt")==0||strcmp(file_ext,"pptx")==0) buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='pptfileDiv bicon'>")); else if(strcmp(file_ext,"xls")==0||strcmp(file_ext,"xlsx")==0) buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='xlsfileDiv bicon'>")); else if(strcmp(file_ext,"pdf")==0) buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='pdffileDiv bicon'>")); else buffer_append_string_len(out, CONST_STR_LEN("<div id='fileviewicon' class='fileDiv bicon'>")); buffer_append_string_len(out, CONST_STR_LEN("<div class='selectDiv sicon'></div>")); buffer_append_string_len(out, CONST_STR_LEN("<div class='selectHintDiv sicon'></div>")); buffer_append_string_len(out, CONST_STR_LEN("</div></div></td></tr><tr><td><div class='albuminfo' style='font-size:80%'>")); buffer_append_string_len(out, CONST_STR_LEN("<a id='list_item' qtype='1' isdir='0' playhref='")); #if EMBEDDED_EANBLE char* webdav_http_port = nvram_get_webdav_http_port(); #else char* webdav_http_port = "8082"; #endif if(use_http_connect==1){ buffer_append_string_len(out, CONST_STR_LEN("http://")); buffer_append_string_buffer(out, con->uri.authority); if( !strstr( con->uri.authority->ptr, ":" ) ){ buffer_append_string_len(out, CONST_STR_LEN(":")); buffer_append_string(out, webdav_http_port); } } else{ buffer_append_string_buffer(out, con->uri.scheme); buffer_append_string_len(out, CONST_STR_LEN("://")); buffer_append_string_buffer(out, con->uri.authority); } buffer_append_string_len(out, CONST_STR_LEN("/")); buffer_append_string_buffer(out, con->share_link_shortpath); buffer_append_string_len(out, CONST_STR_LEN("/")); buffer_append_string_buffer(out, con->share_link_filename); buffer_append_string_len(out, CONST_STR_LEN("/")); buffer_append_string(out, filename); buffer_append_string_len(out, CONST_STR_LEN("' uhref='")); buffer_append_string_buffer(out, con->uri.scheme); buffer_append_string_len(out, CONST_STR_LEN("://")); buffer_append_string_buffer(out, con->uri.authority); buffer_append_string_len(out, CONST_STR_LEN("/")); buffer_append_string_buffer(out, con->share_link_shortpath); buffer_append_string_len(out, CONST_STR_LEN("/")); buffer_append_string_buffer(out, con->share_link_filename); buffer_append_string_len(out, CONST_STR_LEN("/")); buffer_append_string(out, filename); buffer_append_string_len(out, CONST_STR_LEN("' title='")); buffer_append_string_buffer(out, buffer_filename); buffer_append_string_len(out, CONST_STR_LEN("' ext='")); buffer_append_string(out, file_ext); free(file_ext); buffer_append_string_len(out, CONST_STR_LEN("' freadonly='true' fhidden='false'>")); buffer_append_string_buffer( out, buffer_filename ); buffer_append_string_len(out, CONST_STR_LEN("</a></div></td></tr>")); buffer_append_string_len(out, CONST_STR_LEN("<tr><td>")); buffer_append_string_len(out, CONST_STR_LEN("<input type='button' class='btnDownload' value='Downloads!'>")); buffer_append_string_len(out, CONST_STR_LEN("</td></tr>")); buffer_append_string_len(out, CONST_STR_LEN("</tbody></table></div>")); buffer_free(buffer_filename); }
static int dispatch_entry(const char *filepath, const struct stat *info, const int typeflag, struct FTW *pathinfo) { const off_t filesize = info->st_size; const char *extension; struct filename fn; char *final_path; /* Don't bother to handle links */ if (typeflag == FTW_SL) return 0; if (typeflag == FTW_SLN) { DPRINTF(2, "%s (dangling symlink)\n", filepath); return 0; } if (typeflag == FTW_D || typeflag == FTW_DP) { DPRINTF(2, "directory: %s/\n", filepath); return 0; } if (typeflag == FTW_DNR) { DPRINTF(2, "%s/ (unreadable)\n", filepath); return 0; } if (typeflag == FTW_F) { extension = get_filename_ext(filepath); if (!extension) { DPRINTF(1, "'%s' doesn't have an extension.\n", filepath); return 0; } /* Check that the extension is valid */ if (!strstr(ALLOWED_EXTENSIONS, extension)) { DPRINTF(1, "'%s' doesn't have a valid extension.\n" "Valid extension are: " "mp3, m4a, flac and ogg\n", filepath); return 0; } /* Okey, so we are should be able to treat this file */ fn.path = calloc(PATH_MAX, sizeof(*fn.path)); if (!fn.path) return -ENOMEM; fn.used = 0; if (build_path_from_tag(filepath, &fn)) { free(fn.path); return 0; } final_path = calloc(PATH_MAX, sizeof(*final_path)); sprintf(final_path, "%s/%s.%s", DST, fn.path, extension); free(fn.path); fn.path = NULL; /* We have a path, yeah ! Now copy that sucker to its final destination */ printf("%s => %s\n", filepath, final_path); mkdir_p(final_path); if (copy(filepath, final_path, filesize)) fprintf(stderr, "Could not copy %s to %s\n", filepath, final_path); free(final_path); final_path = NULL; } else DPRINTF(2, "%s/ (unreadable)\n", filepath); return 0; }
flut::string get_filename_without_ext( const string& str ) { auto ext_len = get_filename_ext( str ).size(); if ( ext_len > 0 ) ++ext_len; // add dot return str.substr( 0, str.size() - ext_len ); }
/* content handler */ static int sass_handler(request_rec *r) { int retval = OK; sass_dir_config_t *config; struct sass_file_context *context; char *css_name, *map_name, *sass_name, *scss_name; int is_css = 0; int is_map = 0; int is_sass = 0; const char *ext = get_filename_ext(r->filename); const char *fbase = apr_pstrndup(r->pool, r->filename, ext - r->filename); if (apr_strnatcasecmp(r->handler, "sass-script") != 0) { return DECLINED; } if (apr_strnatcasecmp(ext, ".css") == 0) { is_css = 1; } else if (apr_strnatcasecmp(ext, ".map") == 0) { is_map = 1; } if (!is_css && !is_map) { return DECLINED; } css_name = apr_psprintf(r->pool, "%s.css", fbase); map_name = apr_psprintf(r->pool, "%s.map", fbase); sass_name = apr_psprintf(r->pool, "%s.sass", fbase); scss_name = apr_psprintf(r->pool, "%s.scss", fbase); if (exists(sass_name)) { is_sass = 1; } if (!is_sass && !exists(scss_name)) { return DECLINED; } if (M_GET != r->method_number) { return HTTP_METHOD_NOT_ALLOWED; } config = ap_get_module_config(r->per_dir_config, &sass_module); if (config->source_map < 1 && is_map) { return DECLINED; } context = sass_new_file_context(); if (!context) { return HTTP_INTERNAL_SERVER_ERROR; } if (apr_strnatcasecmp(config->output_style, "expanded") == 0) { context->options.output_style = SASS_STYLE_EXPANDED; } else if (apr_strnatcasecmp(config->output_style, "compact") == 0) { context->options.output_style = SASS_STYLE_COMPACT; } else if (apr_strnatcasecmp(config->output_style, "compressed") == 0) { context->options.output_style = SASS_STYLE_COMPRESSED; } else { context->options.output_style = SASS_STYLE_NESTED; } context->options.source_comments = (config->source_comments > 0); context->options.omit_source_map_url = (config->omit_source_map_url > 0); context->options.source_map_embed = (config->source_map_embed > 0); context->options.source_map_contents = (config->source_map_contents > 0); context->options.source_map_root = config->source_map_root; context->options.include_paths = config->include_paths; context->options.plugin_paths = config->plugin_paths; if (config->precision > 0) { context->options.precision = config->precision; } context->options.is_indented_syntax_src = is_sass; if (is_sass) { context->input_path = sass_name; } else { context->input_path = scss_name; } if (config->source_map > 0) { context->options.source_map_file = map_name; } context->output_path = css_name; sass_compile_file(context); if (context->error_status) { r->content_type = SASS_CONTENT_TYPE_ERROR; if (context->error_message) { ap_rprintf(r, "%s", context->error_message); } else { ap_rputs("An error occured; no error message available.", r); } if (config->display_error < 1) { retval = HTTP_INTERNAL_SERVER_ERROR; } } else if (is_map && context->source_map_string) { r->content_type = SASS_CONTENT_TYPE_SOURCE_MAP; ap_rprintf(r, "%s", context->source_map_string); if (config->save_output > 0) { sass_output_file(r, map_name, context->source_map_string); if (context->output_string) { sass_output_file(r, css_name, context->output_string); } } } else if (context->output_string) { r->content_type = SASS_CONTENT_TYPE_CSS; ap_rprintf(r, "%s", context->output_string); if (config->save_output > 0) { if ((config->source_map > 0) && context->source_map_string) { sass_output_file(r, map_name, context->source_map_string); } sass_output_file(r, css_name, context->output_string); } } else { r->content_type = SASS_CONTENT_TYPE_ERROR; ap_rputs("Unknown internal error.", r); if (config->display_error < 1) { retval = HTTP_INTERNAL_SERVER_ERROR; } } sass_free_file_context(context); return retval; }
int main(void){ char *path = "/etc/proyecto_so_1/proy1.ini"; char *line = NULL; size_t len = 0; ssize_t reading; openlog("ALERT_DAEMON", LOG_PID, LOG_DAEMON); FILE *fp; fp = fopen(path,"r"); if (fp == NULL){ syslog(LOG_ERR,"Fallo en la lectura del archivo de conf proy1.ini"); closelog(); exit(EXIT_FAILURE); //notificar por medio de syslog que no se encontro el proy1.ini }else{ while(!feof(fp)){ while ((reading = getline(&line, &len, fp)) != -1) { if(line[0] != ';'){ if(line[0] != '[' && line != NULL){ //printf("Linea %s\n",line); char *buf; buf = strsep(&line,"="); if((strcmp(buf,"log_tag"))==0){ tag = strsep(&line,"\0"); } if((strcmp(buf,"interval"))==0){ buf = strsep(&line,"\0"); interval = atoi(buf); } } } } } } openlog(tag, LOG_PID, LOG_DAEMON); if ((lista = (Lista *) malloc (sizeof (Lista))) == NULL){ syslog(LOG_ERR,"Error, no se pudo inicializar la lista"); exit(EXIT_FAILURE); } incializacion(lista); while(1==1){ sleep(interval); char *dir="/var/log"; struct dirent *dp; DIR *fd; char *val,**paragraph; paragraph = (char**)malloc(1*sizeof(char*)); int position=0; if ((fd = opendir(dir)) == NULL) { syslog(LOG_INFO,"Error, no se pudo abrir el directorio /var/log"); closelog(); return; } while ((dp = readdir(fd)) != NULL) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) continue; /* skip self and parent */ char *aux = get_filename_ext(dp->d_name); // printf("Val--------> %d type dir %d type file regular %d\n ",dp->d_type,DT_DIR,DT_REG); if(dp->d_type == DT_REG){ if(strcmp(aux,"gz")!=0){ //agregar a la lista paragraph = ObtenerPalabras(dp->d_name,paragraph,position); position++; } } } (void) signal(SIGUSR1,manejadorDeSenales); int pos=0; //printf("Num pal %d\n",position); for(pos; pos < position; pos++){ int i, fds[2]; if (pipe(fds) == -1) { syslog(LOG_ERR,"Error, no se pudo crear la tuberia anonima"); exit(EXIT_FAILURE); } pmd5sum = fork(); if (pmd5sum == 0) { hijo(fds,paragraph[pos]); kill(pmd5sum,SIGKILL); } else if (pmd5sum > 0) { /* tratamiento del padre */ papa(fds); close(fds[0]); close(fds[1]); kill(pmd5sum,SIGKILL); } else if (pmd5sum == -1) { syslog(LOG_ERR,"Error, fallo en la llamada fork"); exit(EXIT_FAILURE); } /* tratamiento del padre una vez lanzado su hijo. */ pmd5sum = wait(NULL); while (pmd5sum > 0) { pmd5sum = wait(NULL); } if (pmd5sum == -1 && errno != ECHILD) { syslog(LOG_ERR,"Error, fallo en la llamada wait"); exit(EXIT_FAILURE); } }//fin for que crea hijos // libero el paragragh memset(paragraph,0,sizeof(char*)*position); // visualizacion(lista); // verifico si algun archivo cambio llamando a cambio ? char *namepak; int cambio = file_change(lista); if(cambio==1){//algun archivo cambio //procesar .pak namepak = (char*)proccesingPak(lista); set_change(lista); pgzip = fork(); if (pgzip == 0) { comprimir(namepak); kill(pgzip,SIGKILL); } else if (pgzip > 0) { /* tratamiento del padre */ pgzip = wait(NULL); while (pgzip > 0) { pgzip = wait(NULL); } }else if (pgzip == -1) { syslog(LOG_ERR,"Error, fallo en fork"); exit(EXIT_FAILURE); } if (pgzip == -1 && errno != ECHILD) { syslog(LOG_ERR,"Error, fallo en wait"); exit(EXIT_FAILURE); } }//FIN IF CAMBIO }//FIN WHILE TRUE }//FIN MAIN
int main(int argc, char **argv) { FILE *map_file, *output_file; int lineData[4]; isla *new_isla; list *isla_list; map *active_map; stack *got_stack; bool fuck_up = FALSE; if(argc != 2 || strcmp(get_filename_ext(argv[1]), "map")) file_error("Missing arguments or wrong extension specified on file input"); map_file = fopen(argv[1], "r"); if(map_file == NULL) file_error("Unable to open file specified"); output_file = change_file_ext(argv[1]); while(read_line(map_file, lineData) != 0) { /*Create new map*/ active_map = create_map(lineData[1], lineData[0], lineData[2], lineData[3]); isla_list = create_list(); /*Read isla, create struct isla, add to the map matrix, line by line*/ while(read_line(map_file, lineData) == 1) { new_isla = NULL; setup_isla(new_isla, active_map, lineData, isla_list); } #ifdef DEBUG /*tester: print map, print list*/ print_list(isla_list, print_isla); printf("\n"); print_map(active_map); print_map_graphic(active_map); printf("\n"); /* end of test */ #endif find_adj(active_map); #ifdef DEBUG print_adj(isla_list); #endif fuck_up = initial_fuck_up(isla_list); /* verify if initial f**k up, if yes: rage quit */ if(fuck_up != TRUE) { /*Play the game*/ got_stack = DFS_manager(isla_list, active_map); #ifdef DEBUG print_stack(got_stack, print_bridge); #endif } /*Write in output file*/ print_output_per_map(active_map, output_file, isla_list); /*free stuff, start over*/ if(fuck_up != TRUE) free_stack(got_stack, already_free); free_list(isla_list, free_isla); free_map(active_map); } fclose(map_file); fclose(output_file); exit(EXIT_SUCCESS); }
void pick_file(file_s *picked, const char *path) { picker = malloc(sizeof(picker_s)); get_dir(path); // key repeat timer static time_t t_start = 0, t_end = 0, t_elapsed = 0; while (aptMainLoop()) { hidScanInput(); u32 kHeld = hidKeysHeld(); u32 kDown = hidKeysDown(); if (hidKeysUp()) { time(&t_start); // reset held timer } if (kDown & KEY_DOWN) { picker->file_index++; if (picker->file_index >= picker->file_count) picker->file_index = 0; time(&t_start); } else if (kHeld & KEY_DOWN) { time(&t_end); t_elapsed = t_end - t_start; if (t_elapsed > 0) { picker->file_index++; if (picker->file_index >= picker->file_count) picker->file_index = 0; svcSleep(100); } } if (kDown & KEY_UP) { picker->file_index--; if (picker->file_index < 0) picker->file_index = picker->file_count - 1; time(&t_start); } else if (kHeld & KEY_UP) { time(&t_end); t_elapsed = t_end - t_start; if (t_elapsed > 0) { picker->file_index--; if (picker->file_index < 0) picker->file_index = picker->file_count - 1; svcSleep(100); } } if (kDown & KEY_A) { if (picker->file_count > 0) { int index = picker->file_index; if (!picker->files[index].isDir) { if (confirm(0, "Launch \"%s\" ?", picker->files[index].name)) { strncpy(picked->name, picker->files[index].name, 512); strncpy(picked->path, picker->files[index].path, 512); picked->isDir = picker->files[index].isDir; picked->size = picker->files[index].size; break; } } else { get_dir(picker->files[index].path); } } } else if (kDown & KEY_X) { int index = picker->file_index; if (!picker->files[index].isDir) { const char *ext = get_filename_ext(picker->files[index].name); if (strcasecmp(ext, "3dsx") == 0) { if (confirm(3, "Add entry to boot menu: \"%s\" ?", picker->files[index].name)) { if (config->count > CONFIG_MAX_ENTRIES - 1) { debug("Maximum entries reached (%i)\n", CONFIG_MAX_ENTRIES); } else if (configAddEntry(picker->files[index].name, picker->files[index].path, 0) == 0) { debug("Added entry: %s\n", picker->files[index].name); } else { debug("Error adding entry: %s\n", picker->files[index].name); } } } } } else if (kDown & KEY_B) { // exit if we can't go back if (strlen(picker->now_path) <= 1) break; // remove slash if needed if (end_with(picker->now_path, '/')) picker->now_path[strlen(picker->now_path) - 1] = '\0'; // build path char *slash = strrchr(picker->now_path, '/'); if (slash == NULL) break; int len = (int) (slash - picker->now_path); picker->now_path[len] = '\0'; // enter new dir get_dir(picker->now_path); } drawBg(); drawTitle("*** Select a file ***"); int i, y = 0; int page = picker->file_index / MAX_LINE; for (i = page * MAX_LINE; i < page * MAX_LINE + MAX_LINE; i++) { if (i >= picker->file_count) break; drawItemN(i == picker->file_index, 47, 16 * i, picker->files[i].name); if (i == picker->file_index && !picker->files[i].isDir) { drawInfo("Press (A) to launch\nPress (X) to add to boot menu"); } y++; } gfxSwap(); } free(picker); }