diff options
Diffstat (limited to 'WWW/Library/Implementation')
-rw-r--r-- | WWW/Library/Implementation/HTDOS.c | 21 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTFTP.c | 363 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTFile.c | 20 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTFormat.c | 4 | ||||
-rw-r--r-- | WWW/Library/Implementation/HTUtils.h | 17 | ||||
-rw-r--r-- | WWW/Library/Implementation/www_tcp.h | 6 |
6 files changed, 345 insertions, 86 deletions
diff --git a/WWW/Library/Implementation/HTDOS.c b/WWW/Library/Implementation/HTDOS.c index d560954c..abf24dfb 100644 --- a/WWW/Library/Implementation/HTDOS.c +++ b/WWW/Library/Implementation/HTDOS.c @@ -1,5 +1,6 @@ -/* DOS specific routines - +/* + * $LynxId: HTDOS.c,v 1.35 2008/12/26 18:07:02 tom Exp $ + * DOS specific routines */ #include <HTUtils.h> @@ -20,8 +21,15 @@ static char *copy_plus(char **result, const char *source) { int length = strlen(source); + int extra = 10; + int n; + + for (n = 0; n < length; ++n) { + if (source[n] == ' ') + ++extra; + } - HTSprintf0(result, "%-*s", length + 10, source); + HTSprintf0(result, "%-*s", length + extra, source); (*result)[length] = 0; return (*result); } @@ -40,8 +48,6 @@ const char *HTDOS_wwwName(const char *dosname) static char *wwwname = NULL; char *cp_url = copy_plus(&wwwname, dosname); int wwwname_len; - -#ifdef SH_EX char ch; while ((ch = *dosname) != '\0') { @@ -62,11 +68,6 @@ const char *HTDOS_wwwName(const char *dosname) dosname++; } *cp_url = '\0'; -#else - for (; *cp_url != '\0'; cp_url++) - if (*cp_url == '\\') - *cp_url = '/'; /* convert dos backslash to unix-style */ -#endif wwwname_len = strlen(wwwname); if (wwwname_len > 1) diff --git a/WWW/Library/Implementation/HTFTP.c b/WWW/Library/Implementation/HTFTP.c index 1ca9f47a..bbf5e35a 100644 --- a/WWW/Library/Implementation/HTFTP.c +++ b/WWW/Library/Implementation/HTFTP.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTFTP.c,v 1.81 2008/09/18 21:34:25 tom Exp $ + * $LynxId: HTFTP.c,v 1.86 2008/12/26 22:19:03 tom Exp $ * * File Transfer Protocol (FTP) Client * for a WorldWideWeb browser @@ -148,12 +148,12 @@ typedef struct _connection { # define LY_SOCKLEN socklen_t #endif -#define PUTC(c) (*targetClass.put_character) (target, c) -#define PUTS(s) (*targetClass.put_string) (target, s) -#define START(e) (*targetClass.start_element) (target, e, 0, 0, -1, 0) -#define END(e) (*targetClass.end_element) (target, e, 0) -#define FREE_TARGET (*targetClass._free) (target) -#define ABORT_TARGET (*targetClass._free) (target) +#define PUTC(c) (*target->isa->put_character) (target, c) +#define PUTS(s) (*target->isa->put_string) (target, s) +#define START(e) (*target->isa->start_element) (target, e, 0, 0, -1, 0) +#define END(e) (*target->isa->end_element) (target, e, 0) +#define FREE_TARGET (*target->isa->_free) (target) +#define ABORT_TARGET (*target->isa->_free) (target) struct _HTStructured { const HTStructuredClass *isa; @@ -1469,11 +1469,17 @@ static void set_years_and_date(void) typedef struct _EntryInfo { char *filename; - char *linkname; + char *linkname; /* symbolic link, if any */ char *type; char *date; - unsigned int size; + unsigned long size; BOOLEAN display; /* show this entry? */ +#ifdef LONG_LIST + unsigned long file_links; + char *file_mode; + char *file_user; + char *file_group; +#endif } EntryInfo; static void free_entryinfo_struct_contents(EntryInfo *entry_info) @@ -1623,25 +1629,29 @@ static void parse_eplf_line(char *line, * Extract the name, size, and date from an ls -l line. */ static void parse_ls_line(char *line, - EntryInfo *entry_info) + EntryInfo *entry) { + char *next; + char *cp; int i, j; - int base = 1; - int size_num = 0; + unsigned long base = 1; + unsigned long size_num = 0; for (i = strlen(line) - 1; (i > 13) && (!isspace(UCH(line[i])) || !is_ls_date(&line[i - 12])); - i--) ; /* null body */ + i--) { + ; /* null body */ + } line[i] = '\0'; if (i > 13) { - StrAllocCopy(entry_info->date, &line[i - 12]); + StrAllocCopy(entry->date, &line[i - 12]); /* replace the 4th location with nbsp if it is a space or zero */ - if (entry_info->date[4] == ' ' || entry_info->date[4] == '0') - entry_info->date[4] = HT_NON_BREAK_SPACE; + if (entry->date[4] == ' ' || entry->date[4] == '0') + entry->date[4] = HT_NON_BREAK_SPACE; /* make sure year or time is flush right */ - if (entry_info->date[11] == ' ') { + if (entry->date[11] == ' ') { for (j = 11; j > 6; j--) { - entry_info->date[j] = entry_info->date[j - 1]; + entry->date[j] = entry->date[j - 1]; } } } @@ -1651,9 +1661,56 @@ static void parse_ls_line(char *line, base *= 10; j--; } - entry_info->size = size_num; - StrAllocCopy(entry_info->filename, &line[i + 1]); -} /* parse_ls_line() */ + entry->size = size_num; + StrAllocCopy(entry->filename, &line[i + 1]); + +#ifdef LONG_LIST + line[j] = '\0'; + + /* + * Extract the file-permissions, as a string. + */ + if ((cp = strchr(line, ' ')) != 0 + && (cp - line) == 10) { + *cp = '\0'; + StrAllocCopy(entry->file_mode, line); + *cp = ' '; + } + + /* + * Next is the link-count. + */ + next = 0; + entry->file_links = strtol(cp, &next, 10); + if (next == 0 || *next != ' ') { + entry->file_links = 0; + next = cp; + } else { + cp = next; + } + /* + * Next is the user-name. + */ + while (isspace(UCH(*cp))) + ++cp; + if ((next = strchr(cp, ' ')) != 0) + *next = '\0'; + if (*cp != '\0') + StrAllocCopy(entry->file_user, cp); + /* + * Next is the group-name (perhaps). + */ + if (next != NULL) { + cp = (next + 1); + while (isspace(UCH(*cp))) + ++cp; + if ((next = strchr(cp, ' ')) != 0) + *next = '\0'; + if (*cp != '\0') + StrAllocCopy(entry->file_group, cp); + } +#endif +} /* * Extract the name and size info and whether it refers to a directory from a @@ -1730,7 +1787,7 @@ static void parse_dls_line(char *line, cps = LYSkipBlanks(&line[23]); if (!strncmp(cps, "-> ", 3) && cps[3] != '\0' && cps[3] != ' ') { - StrAllocCopy(entry_info->type, gettext("Symbolic Link")); + StrAllocCopy(entry_info->type, ENTRY_IS_SYMBOLIC_LINK); StrAllocCopy(entry_info->linkname, LYSkipBlanks(cps + 3)); entry_info->size = 0; /* don't display size */ } @@ -1893,7 +1950,7 @@ static void parse_vms_dir_entry(char *line, } /* Wrap it up */ - CTRACE((tfp, "HTFTP: VMS filename: %s date: %s size: %u\n", + CTRACE((tfp, "HTFTP: VMS filename: %s date: %s size: %lu\n", entry_info->filename, NonNull(entry_info->date), entry_info->size)); @@ -1965,7 +2022,7 @@ static void parse_ms_windows_dir_entry(char *line, } /* Wrap it up */ - CTRACE((tfp, "HTFTP: MS Windows filename: %s date: %s size: %u\n", + CTRACE((tfp, "HTFTP: MS Windows filename: %s date: %s size: %lu\n", entry_info->filename, NonNull(entry_info->date), entry_info->size)); @@ -2213,7 +2270,7 @@ static void parse_cms_dir_entry(char *line, } /* Wrap it up. */ - CTRACE((tfp, "HTFTP: VM/CMS filename: %s date: %s size: %u\n", + CTRACE((tfp, "HTFTP: VM/CMS filename: %s date: %s size: %lu\n", entry_info->filename, NonNull(entry_info->date), entry_info->size)); @@ -2236,15 +2293,10 @@ static EntryInfo *parse_dir_entry(char *entry, BOOLEAN remove_size = FALSE; char *cp; - entry_info = (EntryInfo *) malloc(sizeof(EntryInfo)); + entry_info = typecalloc(EntryInfo); if (entry_info == NULL) outofmem(__FILE__, "parse_dir_entry"); - entry_info->filename = NULL; - entry_info->linkname = NULL; - entry_info->type = NULL; - entry_info->date = NULL; - entry_info->size = 0; entry_info->display = TRUE; switch (server_type) { @@ -2347,7 +2399,7 @@ static EntryInfo *parse_dir_entry(char *entry, * It's a symbolic link, does the user care about knowing if it is * symbolic? I think so since it might be a directory. */ - StrAllocCopy(entry_info->type, gettext("Symbolic Link")); + StrAllocCopy(entry_info->type, ENTRY_IS_SYMBOLIC_LINK); remove_size = TRUE; /* size is not useful */ /* @@ -2499,9 +2551,11 @@ static EntryInfo *parse_dir_entry(char *entry, } /* switch (server_type) */ +#ifndef LONG_LIST if (remove_size && entry_info->size) { entry_info->size = 0; } +#endif if (entry_info->filename && strlen(entry_info->filename) > 3) { if (((cp = strrchr(entry_info->filename, '.')) != NULL && @@ -2544,7 +2598,7 @@ static EntryInfo *parse_dir_entry(char *entry, } return (entry_info); -} /* parse_dir_entry */ +} static int compare_EntryInfo_structs(EntryInfo *entry1, EntryInfo *entry2) { @@ -2675,6 +2729,219 @@ static int compare_EntryInfo_structs(EntryInfo *entry1, EntryInfo *entry2) } } +#ifdef LONG_LIST +static char *FormatStr(char **bufp, + char *start, + const char *value) +{ + char fmt[512]; + + if (*start) { + sprintf(fmt, "%%%.*ss", (int) sizeof(fmt) - 3, start); + HTSprintf(bufp, fmt, value); + } else if (*bufp && !(value && *value)) { + ; + } else if (value) { + StrAllocCat(*bufp, value); + } + return *bufp; +} + +static char *FormatNum(char **bufp, + char *start, + long value) +{ + char fmt[512]; + + if (*start) { + sprintf(fmt, "%%%.*sld", (int) sizeof(fmt) - 3, start); + HTSprintf(bufp, fmt, value); + } else { + sprintf(fmt, "%ld", value); + StrAllocCat(*bufp, fmt); + } + return *bufp; +} + +static void FlushParse(HTStructured * target, char **buf) +{ + if (*buf && **buf) { + PUTS(*buf); + **buf = '\0'; + } +} + +static void LYListFmtParse(const char *fmtstr, + EntryInfo *data, + HTStructured * target, + char *tail) +{ + char c; + char *s; + char *end; + char *start; + char *str = NULL; + char *buf = NULL; + BOOL is_directory = (data->file_mode != 0 && + (TOUPPER(data->file_mode[0]) == 'D')); + BOOL is_symlinked = (data->file_mode != 0 && + (TOUPPER(data->file_mode[0]) == 'L')); + BOOL remove_size = (is_directory || is_symlinked); + + StrAllocCopy(str, fmtstr); + s = str; + end = str + strlen(str); + while (*s) { + start = s; + while (*s) { + if (*s == '%') { + if (*(s + 1) == '%') /* literal % */ + s++; + else + break; + } + s++; + } + /* s is positioned either at a % or at \0 */ + *s = '\0'; + if (s > start) { /* some literal chars. */ + StrAllocCat(buf, start); + } + if (s == end) + break; + start = ++s; + while (isdigit(UCH(*s)) || *s == '.' || *s == '-' || *s == ' ' || + *s == '#' || *s == '+' || *s == '\'') + s++; + c = *s; /* the format char. or \0 */ + *s = '\0'; + + switch (c) { + case '\0': + StrAllocCat(buf, start); + continue; + + case 'A': + case 'a': /* anchor */ + FlushParse(target, &buf); + HTDirEntry(target, tail, data->filename); + FormatStr(&buf, start, data->filename); + PUTS(buf); + END(HTML_A); + *buf = '\0'; + if (c != 'A' && data->linkname != 0) { + PUTS(" -> "); + PUTS(data->linkname); + } + break; + + case 'T': /* MIME type */ + case 't': /* MIME type description */ + if (is_directory) { + if (c != 'T') { + FormatStr(&buf, start, ENTRY_IS_DIRECTORY); + } else { + FormatStr(&buf, start, ""); + } + } else if (is_symlinked) { + if (c != 'T') { + FormatStr(&buf, start, ENTRY_IS_SYMBOLIC_LINK); + } else { + FormatStr(&buf, start, ""); + } + } else { + const char *cp2; + HTFormat format; + + format = HTFileFormat(data->filename, NULL, &cp2); + + if (c != 'T') { + if (cp2 == NULL) { + if (!strncmp(HTAtom_name(format), + "application", 11)) { + cp2 = HTAtom_name(format) + 12; + if (!strncmp(cp2, "x-", 2)) + cp2 += 2; + } else { + cp2 = HTAtom_name(format); + } + } + FormatStr(&buf, start, cp2); + } else { + FormatStr(&buf, start, HTAtom_name(format)); + } + } + break; + + case 'd': /* date */ + if (data->date) { + FormatStr(&buf, start, data->date); + } else { + FormatStr(&buf, start, " * "); + } + break; + + case 's': /* size in bytes */ + FormatNum(&buf, start, data->size); + break; + + case 'K': /* size in Kilobytes but not for directories */ + if (remove_size) { + FormatStr(&buf, start, ""); + StrAllocCat(buf, " "); + break; + } + /* FALL THROUGH */ + case 'k': /* size in Kilobytes */ + /* FIXME - this is inconsistent with HTFile.c, but historical */ + if (data->size < 1024) { + FormatNum(&buf, start, data->size); + StrAllocCat(buf, " bytes"); + } else { + FormatNum(&buf, start, data->size / 1024); + StrAllocCat(buf, "Kb"); + } + break; + +#ifdef LONG_LIST + case 'p': /* unix-style permission bits */ + FormatStr(&buf, start, NonNull(data->file_mode)); + break; + + case 'o': /* owner */ + FormatStr(&buf, start, NonNull(data->file_user)); + break; + + case 'g': /* group */ + FormatStr(&buf, start, NonNull(data->file_group)); + break; + + case 'l': /* link count */ + FormatNum(&buf, start, data->file_links); + break; +#endif + + case '%': /* literal % with flags/width */ + FormatStr(&buf, start, "%"); + break; + + default: + fprintf(stderr, + "Unknown format character `%c' in list format\n", c); + break; + } + + s++; + } + if (buf) { + LYTrimTrailing(buf); + FlushParse(target, &buf); + FREE(buf); + } + PUTC('\n'); + FREE(str); +} +#endif /* LONG_LIST */ /* Read a directory into an hypertext object from the data socket * -------------------------------------------------------------- * @@ -2697,11 +2964,14 @@ static int read_directory(HTParentAnchor *parent, char *filename = HTParse(address, "", PARSE_PATH + PARSE_PUNCTUATION); EntryInfo *entry_info; BOOLEAN first = TRUE; - char string_buffer[64]; char *lastpath = NULL; /* prefix for link, either "" (for root) or xxx */ BOOL need_parent_link = FALSE; BOOL tildeIsTop = FALSE; +#ifndef LONG_LIST + char string_buffer[64]; +#endif + targetClass = *(target->isa); _HTProgress(gettext("Receiving FTP directory.")); @@ -2887,14 +3157,10 @@ static int read_directory(HTParentAnchor *parent, PUTC('\n'); } - /* Put up header - */ - /* PUTS(" Date Type Size Filename\n"); - */ - /* Run through tree printing out in order */ { +#ifndef LONG_LIST #ifdef SH_EX /* 1997/10/18 (Sat) 14:14:28 */ char *p, name_buff[256]; int name_len, dot_len; @@ -2903,14 +3169,21 @@ static int read_directory(HTParentAnchor *parent, #define FILE_GAP 1 #endif - HTBTElement *ele; int i; +#endif + HTBTElement *ele; for (ele = HTBTree_next(bt, NULL); ele != NULL; ele = HTBTree_next(bt, ele)) { entry_info = (EntryInfo *) HTBTree_object(ele); +#ifdef LONG_LIST + LYListFmtParse(ftp_format, + entry_info, + target, + lastpath); +#else if (entry_info->date) { PUTS(entry_info->date); PUTS(" "); @@ -2924,7 +3197,6 @@ static int read_directory(HTParentAnchor *parent, for (; i < 17; i++) PUTC(' '); } - /* start the anchor */ HTDirEntry(target, lastpath, entry_info->filename); #ifdef SH_EX /* 1997/10/18 (Sat) 16:00 */ @@ -2952,17 +3224,17 @@ static int read_directory(HTParentAnchor *parent, if (entry_info->size) { #ifdef SH_EX /* 1998/02/02 (Mon) 16:34:52 */ if (entry_info->size < 1024) - sprintf(string_buffer, "%6d bytes", + sprintf(string_buffer, "%6ld bytes", entry_info->size); else - sprintf(string_buffer, "%6d Kb", + sprintf(string_buffer, "%6ld Kb", entry_info->size / 1024); #else if (entry_info->size < 1024) - sprintf(string_buffer, " %u bytes", + sprintf(string_buffer, " %lu bytes", entry_info->size); else - sprintf(string_buffer, " %uKb", + sprintf(string_buffer, " %luKb", entry_info->size / 1024); #endif PUTS(string_buffer); @@ -2972,6 +3244,7 @@ static int read_directory(HTParentAnchor *parent, } PUTC('\n'); /* end of this entry */ +#endif free_entryinfo_struct_contents(entry_info); } diff --git a/WWW/Library/Implementation/HTFile.c b/WWW/Library/Implementation/HTFile.c index 680cc3a2..6143c068 100644 --- a/WWW/Library/Implementation/HTFile.c +++ b/WWW/Library/Implementation/HTFile.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTFile.c,v 1.114 2008/12/24 13:18:35 tom Exp $ + * $LynxId: HTFile.c,v 1.115 2008/12/26 22:13:13 tom Exp $ * * File Access HTFile.c * =========== @@ -112,13 +112,13 @@ typedef struct { #include <HTML.h> /* For directory object building */ -#define PUTC(c) (*target->isa->put_character)(target, c) -#define PUTS(s) (*target->isa->put_string)(target, s) -#define START(e) (*target->isa->start_element)(target, e, 0, 0, -1, 0) -#define END(e) (*target->isa->end_element)(target, e, 0) +#define PUTC(c) (*target->isa->put_character)(target, c) +#define PUTS(s) (*target->isa->put_string)(target, s) +#define START(e) (*target->isa->start_element)(target, e, 0, 0, -1, 0) +#define END(e) (*target->isa->end_element)(target, e, 0) #define MAYBE_END(e) if (HTML_dtd.tags[e].contents != SGML_EMPTY) \ (*target->isa->end_element)(target, e, 0) -#define FREE_TARGET (*target->isa->_free)(target) +#define FREE_TARGET (*target->isa->_free)(target) #define ABORT_TARGET (*targetClass._abort)(target, NULL); struct _HTStructured { @@ -927,9 +927,11 @@ HTFormat HTFileFormat(const char *filename, /* defaults tree */ - suff = strchr(filename, '.') ? /* Unknown suffix */ - (unknown_suffix.rep ? &unknown_suffix : &no_suffix) - : &no_suffix; + suff = (strchr(filename, '.') + ? (unknown_suffix.rep + ? &unknown_suffix + : &no_suffix) + : &no_suffix); /* * Set default encoding unless found with suffix already. diff --git a/WWW/Library/Implementation/HTFormat.c b/WWW/Library/Implementation/HTFormat.c index 4a02c57e..1999e10e 100644 --- a/WWW/Library/Implementation/HTFormat.c +++ b/WWW/Library/Implementation/HTFormat.c @@ -1,5 +1,5 @@ /* - * $LynxId: HTFormat.c,v 1.65 2008/12/14 17:11:58 tom Exp $ + * $LynxId: HTFormat.c,v 1.66 2008/12/26 18:08:32 tom Exp $ * * Manage different file formats HTFormat.c * ============================= @@ -1441,10 +1441,8 @@ int HTParseFile(HTFormat rep_in, HTStreamClass targetClass; int rv; -#ifdef SH_EX /* 1998/01/04 (Sun) 16:04:09 */ if (fp == NULL) return HT_LOADED; -#endif stream = HTStreamStack(rep_in, format_out, sink, anchor); diff --git a/WWW/Library/Implementation/HTUtils.h b/WWW/Library/Implementation/HTUtils.h index 5cd1bef6..16137deb 100644 --- a/WWW/Library/Implementation/HTUtils.h +++ b/WWW/Library/Implementation/HTUtils.h @@ -1,5 +1,5 @@ /* - * $LynxId: HTUtils.h,v 1.90 2008/12/14 19:34:34 tom Exp $ + * $LynxId: HTUtils.h,v 1.92 2008/12/29 18:35:59 tom Exp $ * * Utility macros for the W3 code library * MACROS FOR GENERAL USE @@ -74,11 +74,6 @@ char *alloca(); #define DISP_PARTIAL /* experimental */ #endif -/* since 2.8.6dev.1, Lynx requires an ANSI C (c89) compiler */ -#define ANSI_VARARGS 1 -#undef HAVE_STDARG_H -#define HAVE_STDARG_H 1 - #if defined(VMS) || defined(_WINDOWS) #define HAVE_STDLIB_H 1 #endif @@ -426,20 +421,10 @@ are generally not the response status from any specific protocol. #define HT_NOT_LOADED -29999 #ifndef va_arg -# if defined(HAVE_STDARG_H) && defined(ANSI_VARARGS) # include <stdarg.h> -# else -# if HAVE_VARARGS_H -# include <varargs.h> -# endif -# endif #endif -#if defined(ANSI_VARARGS) #define LYva_start(ap,format) va_start(ap,format) -#else -#define LYva_start(ap,format) va_start(ap) -#endif /* * GCC can be told that some functions are like printf (and do type-checking on diff --git a/WWW/Library/Implementation/www_tcp.h b/WWW/Library/Implementation/www_tcp.h index c17fe4ae..45216f7f 100644 --- a/WWW/Library/Implementation/www_tcp.h +++ b/WWW/Library/Implementation/www_tcp.h @@ -1,5 +1,5 @@ /* System dependencies in the W3 library - * $LynxId: www_tcp.h,v 1.37 2007/08/02 20:06:10 tom Exp $ + * $LynxId: www_tcp.h,v 1.38 2008/12/30 01:01:34 Paul.Gilmartin Exp $ * SYSTEM DEPENDENCIES @@ -149,8 +149,8 @@ Default values #ifndef TOASCII #ifdef EBCDIC /* S/390 -- gil -- 1327 */ -extern char un_IBM1047[]; -extern unsigned char IBM1047[]; +extern const char un_IBM1047[]; +extern const unsigned char IBM1047[]; /* For debugging #include <assert.h> |