void _openslide_tiffdump_print(GSList *tiffdump) { int i = 0; while (tiffdump != NULL) { printf("Directory %d\n", i); print_directory((GHashTable *) tiffdump->data); i++; tiffdump = tiffdump->next; } }
void * handle_request(void * args){ int * fd = (int *)args; int run = 1; int ptr = 0; ssize_t got_bytes = 0; char * buf = malloc(BUFFER_SIZE); while( run ) { got_bytes = read( *fd, buf + ptr, BUFFER_SIZE - ptr); if(got_bytes <= 0){ buf[ptr] = 0; // Terminate string break; } ptr += got_bytes; if( get_line(buf, ptr) ){ break; } } struct request_t * req = malloc(sizeof(struct request_t)); req->fd = *fd; req->selector = buf; req->selector_len = strlen(req->selector); req->path = resolve_selector(NULL, req->selector); req->path_len = strlen(req->path); plog("Request: %s", buf); if( is_menu( req ) ) { char * gopherfile; asprintf(&gopherfile, "%s%s", req->path, GOPHERMAP_FILENAME); plog("Sending menu @ %s", gopherfile); menu_item * items[1024]; int item_count = parse_gophermap( gopherfile, &items[0], DEFAULT_HOST, DEFAULT_PORT ); plog("Gophermap parsed, items: %u", item_count); for( int i = 0; i < item_count; i++ ){ print_menu_item( req->fd, items[i] ); } free( gopherfile) ; } else if ( is_file( req->path ) ) { plog("Sending file"); print_file(req); } else if ( is_dir( req->path ) ) { plog("Sending dir"); print_directory(req); } close_socket(req->fd, 1); free(req->selector); free(req->path); free(args); pthread_exit(NULL); }
// Generate a slist of directory entries in specified path. Then // print the to stdout. void list (char *path) { DIR *dir = opendir (path); struct dirent *ent; slist_ref slist = new_slist (); if (dir != NULL) { for (;;) { ent = readdir (dir); if (ent == NULL) break; insert (slist, path, ent->d_name); } closedir (dir); if (flags.recursive) push_subdir (slist, path); if (flags.opct > 1 && !flags.recursive) printf ("%s:\n", path); print_directory (slist); }else { print_error (path, strerror (errno)); } free_slist (slist); }
void directory_read(FILE *file, long cur_buf_pos, int count_3){ // printf("current cur_buf_pos%d\n",cur_buf_pos); int DIRECTORY_SIZE = 32; int i; char* buf_ = malloc(512); sec_read(file, cur_buf_pos,buf_); int curpos = cur_buf_pos; // read 512 bytes each time int j; for (j = 0; j<16; j++) { cur_buf_pos = j * 32; // if first byte of directory is 0 means end of file if(buf_[cur_buf_pos] == 0){ free(buf_); return; } root_directory* rd = malloc(sizeof(root_directory)); rd->file_name[0] = buf_[cur_buf_pos]; rd->file_name[1] = buf_[cur_buf_pos+1]; rd->file_name[2] = buf_[cur_buf_pos+2]; rd->file_name[3] = buf_[cur_buf_pos+3]; rd->file_name[4] = buf_[cur_buf_pos+4]; rd->file_name[5] = buf_[cur_buf_pos+5]; rd->file_name[6] = buf_[cur_buf_pos+6]; rd->file_name[7] = buf_[cur_buf_pos+7]; rd->ext[0] = buf_[cur_buf_pos+8]; rd->ext[1] = buf_[cur_buf_pos+9]; rd->ext[2] = buf_[cur_buf_pos+10]; rd->attri = buf_[cur_buf_pos+11]; rd->start_cluster [0] = buf_[cur_buf_pos+26]; rd->start_cluster [1] = buf_[cur_buf_pos+27]; rd->file_size[0] = buf_[cur_buf_pos+28]; rd->file_size[1] = buf_[cur_buf_pos+29]; rd->file_size[2] = buf_[cur_buf_pos+30]; rd->file_size[3] = buf_[cur_buf_pos+31]; //cur_buf_pos = cur_buf_pos + DIRECTORY_SIZE; char first = rd->file_name[0]; int start_cluster; if(first!=229){ char * name_buf; start_cluster = print_directory(rd, name_buf); } else{ break; } uint8_t attri = rd->attri; free(rd); if ((attri & 0x10)&&(start_cluster>0)){ // if has subdirectory, go read FAT int* clusters = FAT_read(start_cluster, file);//FAT_read return an array of clusters //int count_2 = 0; count_3 = 0; for (count_3; count_3<10; count_3++) { // condition: if a valid cluster number and not subdirectory if ((clusters[count_3] >= 2)&&(clusters[count_3]<4095)&&first!='.'){ long new_pos = ((clusters[count_3] - 2) * csize )*ssize + (sec_num_first_data * ssize); directory_read(file, new_pos,count_3+1); }else{ } } }else{ } } // } }
static void print_directory(GMenuTreeDirectory *directory) { GSList *items; GSList *tmp; const char *path; char *freeme; freeme = make_path(directory); if (!strcmp(freeme, "/")) path = freeme; else path = freeme + 1; items = gmenu_tree_directory_get_contents(directory); tmp = items; while (tmp != NULL) { GMenuTreeItem *item = tmp->data; switch (gmenu_tree_item_get_type(item)) { case GMENU_TREE_ITEM_ENTRY: print_entry(GMENU_TREE_ENTRY(item), path); break; case GMENU_TREE_ITEM_DIRECTORY: print_directory(GMENU_TREE_DIRECTORY(item)); break; case GMENU_TREE_ITEM_HEADER: case GMENU_TREE_ITEM_SEPARATOR: break; case GMENU_TREE_ITEM_ALIAS: { GMenuTreeItem *aliased_item; aliased_item = gmenu_tree_alias_get_item(GMENU_TREE_ALIAS(item)); if (gmenu_tree_item_get_type(aliased_item) == GMENU_TREE_ITEM_ENTRY) print_entry(GMENU_TREE_ENTRY(aliased_item), path); } break; default: g_assert_not_reached(); break; } gmenu_tree_item_unref(tmp->data); tmp = tmp->next; } g_slist_free(items); g_free(freeme); }
/** * makefileindex: make file index. * * @param[in] file output file name * @param[out] a_files top level file index */ int makefileindex(const char *file, STRBUF *a_files) { STATIC_STRBUF(sb); FILE *filesop; int flags = REG_EXTENDED; /* * Basedir is a directory to which we are paying attention on each * occasion. It starts with ".", grows and shrink according to the * progress of processing. It isn't copied each every recursive call * not to waste the stack. */ char basedir[MAXPATHLEN]; /* * Initialize data. */ indexlink = (Fflag) ? "../files" : "../mains"; src_count = 0; gp = gfind_open(dbpath, NULL, other_files ? GPATH_BOTH : GPATH_SOURCE); /* * for collecting include files. */ if (w32) flags |= REG_ICASE; strbuf_clear(sb); strbuf_puts(sb, "\\.("); { const char *p = include_file_suffixes; int c; while ((c = (unsigned char)*p++) != '\0') { if (isregexchar(c)) strbuf_putc(sb, '\\'); else if (c == ',') c = '|'; strbuf_putc(sb, c); } } strbuf_puts(sb, ")$"); if (regcomp(&is_include_file, strbuf_value(sb), flags) != 0) die("cannot compile regular expression '%s'.", strbuf_value(sb)); /* * Write to files.html. */ if ((filesop = fopen(makepath(distpath, file, NULL), "w")) == NULL) die("cannot open file '%s'.", file); fputs_nl(gen_page_index_begin(title_file_index, jscode), filesop); fputs_nl(body_begin, filesop); fputs(header_begin, filesop); fputs(gen_href_begin(NULL, "files", normal_suffix, NULL), filesop); fputs(title_file_index, filesop); fputs(gen_href_end(), filesop); fputs_nl(header_end, filesop); if (tree_view) { fputs_nl(tree_control, filesop); fputs_nl(tree_loading, filesop); if (tree_view_type) { fprintf(filesop, tree_begin_using, tree_view_type); fputc('\n', filesop); } else { fputs_nl(tree_begin, filesop); } } else if (table_flist) fputs_nl(flist_begin, filesop); else if (!no_order_list) fputs_nl(list_begin, filesop); FILEMAP = NULL; if (filemap_file) { if (!(FILEMAP = fopen(makepath(distpath, "FILEMAP", NULL), "w"))) die("cannot open '%s'.", makepath(distpath, "FILEMAP", NULL)); } /* * print whole directory tree. */ files = a_files; strcpy(basedir, "."); (void)print_directory(0, basedir); if (tree_view) strbuf_puts(files, tree_end); if (filemap_file) fclose(FILEMAP); gfind_close(gp); regfree(&is_include_file); fputs(strbuf_value(files), filesop); if (tree_view) fputs_nl(tree_end, filesop); else if (table_flist) fputs_nl(flist_end, filesop); else if (!no_order_list) fputs_nl(list_end, filesop); fputs_nl(body_end, filesop); fputs_nl(gen_page_end(), filesop); fclose(filesop); html_count++; return src_count; }
static int print_directory(int level, char *basedir) { const char *path; FILEOP *fileop = NULL; FILE *op = NULL; int flist_items = 0; int count = 0; if (level > 0) { char name[MAXPATHLEN]; snprintf(name, sizeof(name), "%s/files/%s.%s", distpath, path2fid(basedir), HTML); fileop = open_output_file(name, 0); op = get_descripter(fileop); print_directory_header(op, level, basedir); if (tree_view) { char *target = (Fflag) ? "mains" : "_top"; strbuf_puts(files, dir_begin); strbuf_puts(files, gen_href_begin_with_title_target("files", path2fid(basedir), HTML, NULL, NULL, target)); strbuf_puts(files, full_path ? removedotslash(basedir) : lastpart(basedir)); strbuf_puts(files, gen_href_end()); strbuf_puts_nl(files, dir_title_end); strbuf_puts_nl(files, "<ul>"); } } while ((path = getpath()) != NULL) { const char *p, *local = localpath(path, basedir); /* * Path is outside of basedir. */ if (local == NULL) { ungetpath(); /* read again by upper level print_directory(). */ break; } /* * Path is inside of basedir. */ else { char *slash = strchr(local, '/'); if (table_flist && flist_items++ % flist_fields == 0) PUT(fline_begin); /* * Print directory. */ if (slash) { int baselen = strlen(basedir); char *q, *last = basedir + baselen; int subcount; if (baselen + 1 + (slash - local) > MAXPATHLEN) { fprintf(stderr, "Too long path name.\n"); exit(1); } /* * Append new directory to the basedir. */ p = local; q = last; *q++ = '/'; while (p < slash) *q++ = *p++; *q = '\0'; /* * print tree for this directory. */ ungetpath(); /* read again by lower level print_directory(). */ subcount = print_directory(level + 1, basedir); PUT(print_directory_name(level, basedir, subcount)); count += subcount; /* * Shrink the basedir. */ *last = '\0'; } /* * Print file. */ else { const char *file_name = print_file_name(level, path); if (tree_view) { int size = filesize(path); char *target = (Fflag) ? "mains" : "_top"; char tips[80]; if (size > 1) snprintf(tips, sizeof(tips), "%s bytes", insert_comma(size)); else snprintf(tips, sizeof(tips), "%s byte", insert_comma(size)); strbuf_sprintf(files, "%s%s%s%s%s\n", file_begin, gen_href_begin_with_title_target(SRCS, path2fid(path), HTML, NULL, tips, target), full_path ? removedotslash(path) : lastpart(path), gen_href_end(), file_end); } PUT(file_name); if (filemap_file) fprintf(FILEMAP, "%s\t%s/%s.%s\n", removedotslash(path), SRCS, path2fid(path), HTML); count++; } if (table_flist && flist_items % flist_fields == 0) PUT(fline_end); } } if (flist_items % flist_fields != 0) PUT(fline_end); if (level > 0) { print_directory_footer(op, level, basedir); close_file(fileop); if (tree_view) { strbuf_puts_nl(files, "</ul>"); strbuf_puts_nl(files, dir_end); } } html_count++; return count; }