📄 htfile.c
字号:
FREE(fullparentpath); FREE(relative); FREE(path); return(need_parent_link); } closedir(dp); FREE(fullparentpath);#ifdef LONG_LIST need_parent_link = TRUE; FREE(path); FREE(relative); return(need_parent_link);#endif /* LONG_LIST */ } }#endif /* !VMS */ HTStartAnchor(target, "", relative); FREE(relative); PUTS(SEGMENT_UP_TO); if (parent) { if ((0 == strcmp(current,".")) || (0 == strcmp(current,".."))) { /* ** Should not happen, but if it does, ** at least avoid giving misleading info. - KW */ PUTS(".."); } else { char * printable = NULL; StrAllocCopy(printable, parent + 1); HTUnEscape(printable); PUTS(printable); FREE(printable); } } else { PUTC('/'); } END(HTML_A); PUTC('\n'); }#endif /* !NO_PARENT_DIR_REFERENCE */ FREE(path); return(need_parent_link);}#if defined HAVE_READDIR/* Send README file.** -----------------**** If a README file exists, then it is inserted into the document here.*/PRIVATE void do_readme ARGS2(HTStructured *, target, CONST char *, localname){ FILE * fp; char * readme_file_name = NULL; int ch; HTSprintf0(&readme_file_name, "%s/%s", localname, HT_DIR_README_FILE); fp = fopen(readme_file_name, "r"); if (fp) { HTStructuredClass targetClass; targetClass = *target->isa; /* (Can't init agregate in K&R) */ START(HTML_PRE); while ((ch = fgetc(fp)) != EOF) { PUTC((char)ch); } END(HTML_PRE); HTDisplayPartial(); fclose(fp); } FREE(readme_file_name);}#define DIRED_BLOK(obj) (((DIRED *)(obj))->sort_tags)#define DIRED_NAME(obj) (((DIRED *)(obj))->file_name)#define NM_cmp(a,b) ((a) < (b) ? -1 : ((a) > (b) ? 1 : 0))#if defined(LONG_LIST) && defined(DIRED_SUPPORT)PRIVATE char *file_type ARGS1(char *, path){ char *type; while (*path == '.') ++path; type = strchr(path, '.'); if (type == NULL) type = ""; return type;}#endif /* LONG_LIST && DIRED_SUPPORT */PRIVATE int dired_cmp ARGS2(void *, a, void *, b){ DIRED *p = (DIRED *)a; DIRED *q = (DIRED *)b; int code = p->sort_tags - q->sort_tags;#if defined(LONG_LIST) && defined(DIRED_SUPPORT) if (code == 0) { switch (dir_list_order) { case ORDER_BY_SIZE: code = -NM_cmp(p->file_info.st_size, q->file_info.st_size); break; case ORDER_BY_DATE: code = -NM_cmp(p->file_info.st_mtime, q->file_info.st_mtime); break; case ORDER_BY_MODE: code = NM_cmp(p->file_info.st_mode, q->file_info.st_mode); break; case ORDER_BY_USER: code = NM_cmp(p->file_info.st_uid, q->file_info.st_uid); break; case ORDER_BY_GROUP: code = NM_cmp(p->file_info.st_gid, q->file_info.st_gid); break; case ORDER_BY_TYPE: code = AS_cmp(file_type(p->file_name), file_type(q->file_name)); break; default: code = 0; break; } }#endif /* LONG_LIST && DIRED_SUPPORT */ if (code == 0) code = AS_cmp(p->file_name, q->file_name);#if 0 CTRACE((tfp, "dired_cmp(%d) ->%d\n\t%c:%s (%s)\n\t%c:%s (%s)\n", dir_list_order, code, p->sort_tags, p->file_name, file_type(p->file_name), q->sort_tags, q->file_name, file_type(q->file_name)));#endif return code;}PRIVATE int print_local_dir ARGS5( DIR *, dp, char *, localname, HTParentAnchor *, anchor, HTFormat, format_out, HTStream *, sink){ HTStructured *target; /* HTML object */ HTStructuredClass targetClass; STRUCT_DIRENT * dirbuf; char *pathname = NULL; char *tail = NULL; BOOL present[HTML_A_ATTRIBUTES]; char * tmpfilename = NULL; BOOL need_parent_link = FALSE; int status; int i; CTRACE((tfp, "print_local_dir() started\n")); pathname = HTParse(anchor->address, "", PARSE_PATH + PARSE_PUNCTUATION); if (!strcmp(pathname,"/")) { /* ** Root path. */ StrAllocCopy (tail, "/foo/.."); } else { char *p = strrchr(pathname, '/'); /* find last slash */ if (!p) { /* ** This probably should not happen, ** but be prepared if it does. - KW */ StrAllocCopy (tail, "/foo/.."); } else { /* ** Take slash off the beginning. */ StrAllocCopy(tail, (p + 1)); } } FREE(pathname); if (UCLYhndl_HTFile_for_unspec >= 0) { HTAnchor_setUCInfoStage(anchor, UCLYhndl_HTFile_for_unspec, UCT_STAGE_PARSER, UCT_SETBY_DEFAULT); } target = HTML_new(anchor, format_out, sink); targetClass = *target->isa; /* Copy routine entry points */ for (i = 0; i < HTML_A_ATTRIBUTES; i++) present[i] = (BOOL) (i == HTML_A_HREF); /* ** The need_parent_link flag will be set if an ** "Up to <parent>" link was not created for a ** readable parent in HTDirTitles() because ** LONG_LIST is defined and NO_PARENT_DIR_REFERENCE ** is not defined so that need we to create the ** link via an LYListFmtParse() call. - FM */ need_parent_link = HTDirTitles(target, anchor, FALSE);#ifdef DIRED_SUPPORT if (!isLYNXCGI(anchor->address)) { HTAnchor_setFormat(anchor, WWW_DIRED); lynx_edit_mode = TRUE; }#endif /* DIRED_SUPPORT */ if (HTDirReadme == HT_DIR_README_TOP) do_readme(target, localname); { HTBTree * bt = HTBTree_new(dired_cmp); int num_of_entries = 0; /* lines counter */ _HTProgress (READING_DIRECTORY); status = HT_LOADED; /* assume we don't get interrupted */ while ((dirbuf = readdir(dp)) != NULL) { /* ** While there are directory entries to be read... */ DIRED *data = NULL;#if !(defined(DOSPATH) || defined(__EMX__)) if (dirbuf->d_ino == 0) /* ** If the entry is not being used, skip it. */ continue;#endif /* ** Skip self, parent if handled in HTDirTitles() ** or if NO_PARENT_DIR_REFERENCE is not defined, ** and any dot files if no_dotfiles is set or ** show_dotfiles is not set. - FM */ if (!strcmp(dirbuf->d_name, ".") /* self */ || (!strcmp(dirbuf->d_name, "..") /* parent */ && need_parent_link == FALSE) || ((strcmp(dirbuf->d_name, "..")) && (dirbuf->d_name[0] == '.' && (no_dotfiles || !show_dotfiles)))) continue; StrAllocCopy(tmpfilename, localname); /* ** If filename is not root directory, add trailing separator. */ LYAddPathSep(&tmpfilename); StrAllocCat(tmpfilename, dirbuf->d_name); data = (DIRED *)malloc(sizeof(DIRED) + strlen(dirbuf->d_name) + 4); if (data == NULL) { /* FIXME */ } LYTrimPathSep (tmpfilename); if (lstat(tmpfilename, &(data->file_info)) < 0) data->file_info.st_mode = 0; strcpy(data->file_name, dirbuf->d_name);#ifndef DIRED_SUPPORT if (S_ISDIR(data->file_info.st_mode)) { data->sort_tags = 'D'; } else { data->sort_tags = 'F'; /* D & F to have first directories, then files */ }#else if (S_ISDIR(data->file_info.st_mode)) { if (dir_list_style == MIXED_STYLE) { data->sort_tags = ' '; LYAddPathSep0(data->file_name); } else if (!strcmp(dirbuf->d_name, "..")) { data->sort_tags = 'A'; } else { data->sort_tags = 'D'; } } else if (dir_list_style == MIXED_STYLE) { data->sort_tags = ' '; } else if (dir_list_style == FILES_FIRST) { data->sort_tags = 'C'; /* C & D to have first files, then directories */ } else { data->sort_tags = 'F'; }#endif /* !DIRED_SUPPORT */ /* ** Sort dirname in the tree bt. */ HTBTree_add(bt, data);#ifdef DISP_PARTIAL /* optimize for expensive operation: */ if (num_of_entries % (partial_threshold > 0 ? partial_threshold : display_lines) == 0) { if (HTCheckForInterrupt()) { status = HT_PARTIAL_CONTENT; break; } } num_of_entries++;#endif /* DISP_PARTIAL */ } /* end while directory entries left to read */ if (status != HT_PARTIAL_CONTENT) _HTProgress (OPERATION_OK); else CTRACE((tfp, "Reading the directory interrupted by user\n")); /* ** Run through tree printing out in order. */ { HTBTElement * next_element = HTBTree_next(bt,NULL); /* pick up the first element of the list */ int num_of_entries_output = 0; /* lines counter */ char state; /* I for initial (.. file), D for directory file, F for file */#ifdef DIRED_SUPPORT char test;#endif /* DIRED_SUPPORT */ state = 'I'; while (next_element != NULL) { DIRED *entry;#ifndef DISP_PARTIAL if (num_of_entries_output % HTMAX(display_lines,10) == 0) { if (HTCheckForInterrupt()) { _HTProgress (TRANSFER_INTERRUPTED); status = HT_PARTIAL_CONTENT; break; } }#endif StrAllocCopy(tmpfilename, localname); /* ** If filename is not root directory. */ LYAddPathSep(&tmpfilename); entry = (DIRED *)(HTBTree_object(next_element)); /* ** Append the current entry's filename ** to the path. */ StrAllocCat(tmpfilename, entry->file_name); HTSimplify(tmpfilename); /* ** Output the directory entry. */ if (strcmp(DIRED_NAME(HTBTree_object(next_element)), "..")) {#ifdef DIRED_SUPPORT test = (DIRED_BLOK(HTBTree_object(next_element)) == 'D' ? 'D' : 'F'); if (state != test) {#ifndef LONG_LIST if (dir_list_style == FILES_FIRST) { if (state == 'F') { END(HTML_DIR); PUTC('\n'); } } else if (dir_list_style != MIXED_STYLE) if (state == 'D') { END(HTML_DIR); PUTC('\n'); }#endif /* !LONG_LIST */ state = (char) (DIRED_BLOK(HTBTree_object(next_element)) == 'D' ? 'D' : 'F'); START(HTML_H2); if (dir_list_style != MIXED_STYLE) { START(HTML_EM); PUTS(state == 'D' ? LABEL_SUBDIRECTORIES : LABEL_FILES); END(HTML_EM); } END(HTML_H2); PUTC('\n');#ifndef LONG_LIST START(HTML_DIR); PUTC('\n');#endif /* !LONG_LIST */ }#else if (state != DIRED_BLOK(HTBTree_object(next_element))) {#ifndef LONG_LIST if (state == 'D') { END(HTML_DIR); PUTC('\n'); }#endif /* !LONG_LIST */ state = (char) (DIRED_BLOK(HTBTree_object(next_element)) == 'D' ? 'D' : 'F'); START(HTML_H2); START(HTML_EM); PUTS(state == 'D' ? LABEL_SUBDIRECTORIES : LABEL_FILES); END(HTML_EM); END(HTML_H2); PUTC('\n');#ifndef LONG_LIST START(HTML_DIR); PUTC('\n');#endif /* !LONG_LIST */ }#endif /* DIRED_SUPPORT */#ifndef LONG_LIST START(HTML_LI);#endif /* !LONG_LIST */ }#ifdef LONG_LIST LYListFmtParse(list_format, entry, tmpfilename, target, tail);#else HTDirEntry(target, tail, entry->file_name); PUTS(entry->file_name); END(HTML_A); MAYBE_END(HTML_LI); PUTC('\n');#endif /* LONG_LIST */ next_element = HTBTree_next(bt, next_element); /* pick up the next element of the list; if none, return NULL*/ /* optimize for expensive operation: */#ifdef DISP_PARTIAL if (num_of_entries_output % (partial_threshold > 0 ? partial_threshold : display_lines) == 0) { /* num_of_entries, num_of_entries_output... */ /* HTReadProgress...(bytes, 0); */ HTDisplayPartial(); if (HTCheckForInterrupt()) { _HTProgress (TRANSFER_INTERRUPTED); status = HT_PARTIAL_CONTENT; break; } } num_of_entries_output++;#endif /* DISP_PARTIAL */ } /* end while next_element */ if (status == HT_LOADED) { if (state == 'I') { START(HTML_P); PUTS("Empty Directory"); }#ifndef LONG_LIST else END(HTML_DIR);#endif /* !LONG_LIST */ } } /* end printing out the tree in order */ FREE(tmpfilename); FREE(tail); HTBTreeAndObject_free(bt); if (status == HT_LOADED) { if (HTDirReadme == HT_DIR_README_BOTTOM) do_readme(target, localname); FREE_TARGET; } else { ABORT_TARGET; } } HTFinishDisplayPartial(); return status; /* document loaded, maybe partial */}#endif /* HAVE_READDIR */#ifndef VMSPUBLIC int HTStat ARGS2( CONST char *, filename, struct stat *, data){ int result = -1; size_t len = strlen(filename); if (len != 0 && LYIsPathSep(filename[len-1])) { char *temp_name = NULL; HTSprintf0(&temp_name, "%s.", filename); result = HTStat(temp_name, data); FREE(temp_name); } else { result = stat(filename, data);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -