about summary refs log tree commit diff stats
path: root/WWW/Library/Implementation/HTWSRC.c
diff options
context:
space:
mode:
Diffstat (limited to 'WWW/Library/Implementation/HTWSRC.c')
-rw-r--r--WWW/Library/Implementation/HTWSRC.c365
1 files changed, 188 insertions, 177 deletions
diff --git a/WWW/Library/Implementation/HTWSRC.c b/WWW/Library/Implementation/HTWSRC.c
index 55d6dea6..31822b8e 100644
--- a/WWW/Library/Implementation/HTWSRC.c
+++ b/WWW/Library/Implementation/HTWSRC.c
@@ -1,12 +1,12 @@
 /*			Parse WAIS Source file			HTWSRC.c
-**			======================
-**
-**	This module parses a stream with WAIS source file
-**	format information on it and creates a structured stream.
-**	That structured stream is then converted into whatever.
-**
-**	3 June 93	Bug fix: Won't crash if no description
-*/
+ *			======================
+ *
+ *	This module parses a stream with WAIS source file
+ *	format information on it and creates a structured stream.
+ *	That structured stream is then converted into whatever.
+ *
+ *	3 June 93	Bug fix: Won't crash if no description
+ */
 
 #include <HTUtils.h>
 
@@ -23,8 +23,8 @@
 #define CACHE_PERIOD (7*86400)	/* Time to keep .src file in seconds */
 
 struct _HTStructured {
-	const HTStructuredClass *	isa;
-	/* ... */
+    const HTStructuredClass *isa;
+    /* ... */
 };
 
 #define PUTC(c) (*me->target->isa->put_character)(me->target, c)
@@ -34,154 +34,161 @@ struct _HTStructured {
 #define MAYBE_END(e) if (HTML_dtd.tags[e].contents != SGML_EMPTY) \
 			(*me->target->isa->end_element)(me->target, e, 0)
 
-
 /*	Here are the parameters which can be specified in a  source file
 */
-static const char* par_name[] = {
-	"version",
-	"ip-address",
+static const char *par_name[] =
+{
+    "version",
+    "ip-address",
 #define PAR_IP_NAME 2
-	"ip-name",
+    "ip-name",
 #define PAR_TCP_PORT 3
-	"tcp-port",
+    "tcp-port",
 #define PAR_DATABASE_NAME 4
-	"database-name",
+    "database-name",
 #define PAR_COST 5
-	"cost",
+    "cost",
 #define PAR_COST_UNIT 6
-	"cost-unit",
+    "cost-unit",
 #define PAR_FREE 7
-	"free",
+    "free",
 #define PAR_MAINTAINER 8
-	"maintainer",
+    "maintainer",
 #define PAR_DESCRIPTION 9
-	"description",
-	"keyword-list",
-	"source",
-	"window-geometry",
-	"configuration",
-	"script",
-	"update-time",
-	"contact-at",
-	"last-contacted",
-	"confidence",
-	"num-docs-to-request",
-	"font",
-	"font-size",
+    "description",
+    "keyword-list",
+    "source",
+    "window-geometry",
+    "configuration",
+    "script",
+    "update-time",
+    "contact-at",
+    "last-contacted",
+    "confidence",
+    "num-docs-to-request",
+    "font",
+    "font-size",
 #define PAR_UNKNOWN 22
-	"unknown",
-	0,				/* Terminate list */
+    "unknown",
+    0,				/* Terminate list */
 #define PAR_COUNT 23
-} ;
-
-
-enum tokenstate { beginning, before_tag, colon, before_value,
-		value, bracketed_value, quoted_value, escape_in_quoted, done };
+};
 
+enum tokenstate {
+    beginning,
+    before_tag,
+    colon,
+    before_value,
+    value,
+    bracketed_value,
+    quoted_value,
+    escape_in_quoted,
+    done
+};
 
 /*		Stream Object
-**		------------
-**
-**	The target is the structured stream down which the
-**	parsed results will go.
-**
-**	all the static stuff below should go in here to make it reentrant
-*/
+ *		------------
+ *
+ *	The target is the structured stream down which the
+ *	parsed results will go.
+ *
+ *	all the static stuff below should go in here to make it reentrant
+ */
 
 struct _HTStream {
-	const HTStreamClass *	isa;
-	HTStructured *		target;
-	char *			par_value[PAR_COUNT];
-	enum tokenstate		state;
-	char			param[BIG+1];
-	int			param_number;
-	int			param_count;
+    const HTStreamClass *isa;
+    HTStructured *target;
+    char *par_value[PAR_COUNT];
+    enum tokenstate state;
+    char param[BIG + 1];
+    int param_number;
+    int param_count;
 };
 
-
-
-
-const char * hex = "0123456789ABCDEF";
+const char *hex = "0123456789ABCDEF";
 
 /*	Decode one hex character
 */
 
-char from_hex (char  c)
+char from_hex(char c)
 {
-    return  (char) (      (c>='0')&&(c<='9') ? c-'0'
-			: (c>='A')&&(c<='F') ? c-'A'+10
-			: (c>='a')&&(c<='f') ? c-'a'+10
-			:		       0);
+    return (char) ((c >= '0') && (c <= '9') ? c - '0'
+		   : (c >= 'A') && (c <= 'F') ? c - 'A' + 10
+		   : (c >= 'a') && (c <= 'f') ? c - 'a' + 10
+		   : 0);
 }
 
-
 /*			State machine
-**			-------------
-**
-** On entry,
-**	me->state	is a valid state (see WSRC_init)
-**	c		is the next character
-** On exit,
-**	returns 1	Done with file
-**		0	Continue. me->state is updated if necessary.
-**		-1	Syntax error error
-*/
-
+ *			-------------
+ *
+ * On entry,
+ *	me->state	is a valid state (see WSRC_init)
+ *	c		is the next character
+ * On exit,
+ *	returns 1	Done with file
+ *		0	Continue. me->state is updated if necessary.
+ *		-1	Syntax error error
+ */
 
 /*		Treat One Character
-**		-------------------
-*/
-static void WSRCParser_put_character (HTStream*  me, char  c)
+ *		-------------------
+ */
+static void WSRCParser_put_character(HTStream *me, char c)
 {
     switch (me->state) {
     case beginning:
-	if (c=='(') me->state = before_tag;
+	if (c == '(')
+	    me->state = before_tag;
 	break;
 
     case before_tag:
-	if (c==')') {
+	if (c == ')') {
 	    me->state = done;
-	    return;			/* Done with input file */
-	} else if (c==':') {
+	    return;		/* Done with input file */
+	} else if (c == ':') {
 	    me->param_count = 0;
 	    me->state = colon;
-	}				/* Ignore other text */
+	}			/* Ignore other text */
 	break;
 
     case colon:
 	if (WHITE(c)) {
 	    me->param[me->param_count++] = 0;	/* Terminate */
-	    for(me->param_number = 0; par_name[me->param_number]; me->param_number++) {
-		if (0==strcmp(par_name[me->param_number], me->param)) {
+	    for (me->param_number = 0;
+		 par_name[me->param_number];
+		 me->param_number++) {
+		if (0 == strcmp(par_name[me->param_number], me->param)) {
 		    break;
 		}
 	    }
 	    if (!par_name[me->param_number]) {	/* Unknown field */
 		CTRACE((tfp, "HTWSRC: Unknown field `%s' in source file\n",
-			    me->param));
+			me->param));
 		me->param_number = PAR_UNKNOWN;
 		me->state = before_value;	/* Could be better ignore */
 		return;
 	    }
 	    me->state = before_value;
 	} else {
-	    if (me->param_count < PARAM_MAX)  me->param[me->param_count++] = c;
+	    if (me->param_count < PARAM_MAX)
+		me->param[me->param_count++] = c;
 	}
 	break;
 
     case before_value:
-	if (c==')') {
+	if (c == ')') {
 	    me->state = done;
-	    return;			/* Done with input file */
+	    return;		/* Done with input file */
 	}
-	if (WHITE(c)) return;		/* Skip white space */
+	if (WHITE(c))
+	    return;		/* Skip white space */
 	me->param_count = 0;
-	if (c=='"') {
+	if (c == '"') {
 	    me->state = quoted_value;
 	    break;
 	}
-	me->state = (c=='"') ? quoted_value :
-		    (c=='(') ? bracketed_value : value;
+	me->state = (c == '"') ? quoted_value :
+	    (c == '(') ? bracketed_value : value;
 	me->param[me->param_count++] = c;	/* Don't miss first character */
 	break;
 
@@ -191,71 +198,76 @@ static void WSRCParser_put_character (HTStream*  me, char  c)
 	    StrAllocCopy(me->par_value[me->param_number], me->param);
 	    me->state = before_tag;
 	} else {
-	    if (me->param_count < PARAM_MAX)  me->param[me->param_count++] = c;
+	    if (me->param_count < PARAM_MAX)
+		me->param[me->param_count++] = c;
 	}
 	break;
 
     case bracketed_value:
-	if (c==')') {
+	if (c == ')') {
 	    me->param[me->param_count] = 0;
 	    StrAllocCopy(me->par_value[me->param_number], me->param);
 	    me->state = before_tag;
 	    break;
 	}
-	if (me->param_count < PARAM_MAX)  me->param[me->param_count++] = c;
+	if (me->param_count < PARAM_MAX)
+	    me->param[me->param_count++] = c;
 	break;
 
     case quoted_value:
-	if (c=='"') {
+	if (c == '"') {
 	    me->param[me->param_count] = 0;
 	    StrAllocCopy(me->par_value[me->param_number], me->param);
 	    me->state = before_tag;
 	    break;
 	}
 
-	if (c=='\\') {		/* Ignore escape but switch state */
+	if (c == '\\') {	/* Ignore escape but switch state */
 	    me->state = escape_in_quoted;
 	    break;
 	}
 	/* Fall through! */
 
     case escape_in_quoted:
-	if (me->param_count < PARAM_MAX)  me->param[me->param_count++] = c;
+	if (me->param_count < PARAM_MAX)
+	    me->param[me->param_count++] = c;
 	me->state = quoted_value;
 	break;
 
-    case done:				/* Ignore anything after EOF */
+    case done:			/* Ignore anything after EOF */
 	return;
 
-    } /* switch me->state */
+    }				/* switch me->state */
 }
 
-
 /*			Open Cache file
-**			===============
-**
-**   Bugs: Maybe for filesystem-challenged platforms (MSDOS for example) we
-**   should make a hash code for the filename.
-*/
+ *			===============
+ *
+ *   Bugs: Maybe for filesystem-challenged platforms (MSDOS for example) we
+ *   should make a hash code for the filename.
+ */
 
 #ifdef CACHE_FILE_PREFIX
-static BOOL write_cache (HTStream *  me)
+static BOOL write_cache(HTStream *me)
 {
-    FILE * fp;
-    char * cache_file_name = NULL;
-    char * www_database;
+    FILE *fp;
+    char *cache_file_name = NULL;
+    char *www_database;
     int result = NO;
 
     if (!me->par_value[PAR_DATABASE_NAME]
 	|| !me->par_value[PAR_IP_NAME]
-	) return NO;
+	)
+	return NO;
 
     www_database = HTEscape(me->par_value[PAR_DATABASE_NAME], URL_XALPHAS);
     HTSprintf0(&cache_file_name, "%sWSRC-%s:%s:%.100s.txt",
-	CACHE_FILE_PREFIX,
-	me->par_value[PAR_IP_NAME],
-	me->par_value[PAR_TCP_PORT] ? me->par_value[PAR_TCP_PORT] : "210",
-	www_database);
+	       CACHE_FILE_PREFIX,
+	       me->par_value[PAR_IP_NAME],
+	       (me->par_value[PAR_TCP_PORT]
+		? me->par_value[PAR_TCP_PORT]
+		: "210"),
+	       www_database);
 
     if ((fp = fopen(cache_file_name, TXT_W)) != 0) {
 	result = YES;
@@ -272,11 +284,11 @@ static BOOL write_cache (HTStream *  me)
 #endif
 
 /*			Output equivalent HTML
-**			----------------------
-**
-*/
+ *			----------------------
+ *
+ */
 
-static void give_parameter (HTStream *  me, int  p)
+static void give_parameter(HTStream *me, int p)
 {
     PUTS(par_name[p]);
     if (me->par_value[p]) {
@@ -288,20 +300,19 @@ static void give_parameter (HTStream *  me, int  p)
     }
 }
 
-
 /*			Generate Outout
-**			===============
-*/
-static void WSRC_gen_html (HTStream *  me, BOOL  source_file)
-
+ *			===============
+ */
+static void WSRC_gen_html(HTStream *me, BOOL source_file)
 {
     if (me->par_value[PAR_DATABASE_NAME]) {
-	char * shortname = 0;
+	char *shortname = 0;
 	int l;
+
 	StrAllocCopy(shortname, me->par_value[PAR_DATABASE_NAME]);
 	l = strlen(shortname);
-	if ( l > 4 && !strcasecomp(shortname + l -4, ".src")) {
-	    shortname[l-4] = 0; /* Chop of .src -- boring! */
+	if (l > 4 && !strcasecomp(shortname + l - 4, ".src")) {
+	    shortname[l - 4] = 0;	/* Chop of .src -- boring! */
 	}
 
 	START(HTML_HEAD);
@@ -331,16 +342,19 @@ static void WSRC_gen_html (HTStream *  me, BOOL  source_file)
 	if (me->par_value[PAR_IP_NAME] &&
 	    me->par_value[PAR_DATABASE_NAME]) {
 
-	    char * WSRC_address = NULL;
-	    char * www_database;
+	    char *WSRC_address = NULL;
+	    char *www_database;
+
 	    www_database = HTEscape(me->par_value[PAR_DATABASE_NAME],
-		URL_XALPHAS);
+				    URL_XALPHAS);
 	    HTSprintf0(&WSRC_address, "%s//%s%s%s/%s",
-		STR_WAIS_URL,
-		me->par_value[PAR_IP_NAME],
-		me->par_value[PAR_TCP_PORT] ? ":" : "",
-		me->par_value[PAR_TCP_PORT] ? me->par_value[PAR_TCP_PORT] :"",
-		www_database);
+		       STR_WAIS_URL,
+		       me->par_value[PAR_IP_NAME],
+		       me->par_value[PAR_TCP_PORT] ? ":" : "",
+		       (me->par_value[PAR_TCP_PORT]
+			? me->par_value[PAR_TCP_PORT]
+			: ""),
+		       www_database);
 
 	    HTStartAnchor(me->target, NULL, WSRC_address);
 	    PUTS(gettext("Direct access"));
@@ -357,8 +371,8 @@ static void WSRC_gen_html (HTStream *  me, BOOL  source_file)
 	}
 	MAYBE_END(HTML_DD);
 
-    } /* end if source_file */
-
+    }
+    /* end if source_file */
     if (me->par_value[PAR_MAINTAINER]) {
 	START(HTML_DT);
 	PUTS(gettext("Maintainer"));
@@ -379,38 +393,35 @@ static void WSRC_gen_html (HTStream *  me, BOOL  source_file)
     END(HTML_DL);
 
     if (me->par_value[PAR_DESCRIPTION]) {
-	START(HTML_PRE);		/* Preformatted description */
+	START(HTML_PRE);	/* Preformatted description */
 	PUTS(me->par_value[PAR_DESCRIPTION]);
 	END(HTML_PRE);
     }
 
-    (*me->target->isa->_free)(me->target);
+    (*me->target->isa->_free) (me->target);
 
     return;
-} /* generate html */
-
+}				/* generate html */
 
-static void WSRCParser_put_string (HTStream *  context, const char*  str)
+static void WSRCParser_put_string(HTStream *context, const char *str)
 {
     const char *p;
-    for(p=str; *p; p++)
+
+    for (p = str; *p; p++)
 	WSRCParser_put_character(context, *p);
 }
 
-
-static void WSRCParser_write (
-		HTStream *	context,
-		const char*	str,
-		int		l)
+static void WSRCParser_write(HTStream *context, const char *str,
+			     int l)
 {
     const char *p;
-    const char *e = str+l;
-    for(p=str; p<e; p++)
+    const char *e = str + l;
+
+    for (p = str; p < e; p++)
 	WSRCParser_put_character(context, *p);
 }
 
-
-static void WSRCParser_free (HTStream *  me)
+static void WSRCParser_free(HTStream *me)
 {
     WSRC_gen_html(me, YES);
 #ifdef CACHE_FILE_PREFIX
@@ -418,51 +429,52 @@ static void WSRCParser_free (HTStream *  me)
 #endif
     {
 	int p;
-	for (p = 0; par_name[p]; p++) { /* Clear out old values */
+
+	for (p = 0; par_name[p]; p++) {		/* Clear out old values */
 	    FREE(me->par_value[p]);
 	}
     }
     FREE(me);
 }
 
-static void WSRCParser_abort (HTStream *  me, HTError  e GCC_UNUSED)
+static void WSRCParser_abort(HTStream *me, HTError e GCC_UNUSED)
 {
     WSRCParser_free(me);
 }
 
-
 /*		Stream subclass		-- method routines
-**		---------------
-*/
+ *		---------------
+ */
 
-HTStreamClass WSRCParserClass = {
-	"WSRCParser",
-	WSRCParser_free,
-	WSRCParser_abort,
-	WSRCParser_put_character,
-	WSRCParser_put_string,
-	WSRCParser_write
+HTStreamClass WSRCParserClass =
+{
+    "WSRCParser",
+    WSRCParser_free,
+    WSRCParser_abort,
+    WSRCParser_put_character,
+    WSRCParser_put_string,
+    WSRCParser_write
 
 };
 
-
 /*		Converter from WAIS Source to whatever
-**		--------------------------------------
-*/
-HTStream* HTWSRCConvert (
-	HTPresentation *	pres,
-	HTParentAnchor *	anchor,
-	HTStream *		sink)
+ *		--------------------------------------
+ */
+HTStream *HTWSRCConvert(HTPresentation *pres, HTParentAnchor *anchor,
+			HTStream *sink)
 {
-    HTStream * me = (HTStream*) malloc(sizeof(*me));
-    if (!me) outofmem(__FILE__, "HTWSRCConvert");
+    HTStream *me = (HTStream *) malloc(sizeof(*me));
+
+    if (!me)
+	outofmem(__FILE__, "HTWSRCConvert");
 
     me->isa = &WSRCParserClass;
     me->target = HTML_new(anchor, pres->rep_out, sink);
 
     {
 	int p;
-	for(p=0; p < PAR_COUNT; p++) {	/* Clear out parameter values */
+
+	for (p = 0; p < PAR_COUNT; p++) {	/* Clear out parameter values */
 	    me->par_value[p] = 0;
 	}
     }
@@ -470,4 +482,3 @@ HTStream* HTWSRCConvert (
 
     return me;
 }
-