about summary refs log tree commit diff stats
path: root/src/LYShowInfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/LYShowInfo.c')
-rw-r--r--src/LYShowInfo.c299
1 files changed, 160 insertions, 139 deletions
diff --git a/src/LYShowInfo.c b/src/LYShowInfo.c
index 4686dc7a..9a763cd8 100644
--- a/src/LYShowInfo.c
+++ b/src/LYShowInfo.c
@@ -24,6 +24,14 @@
 
 #define ADVANCED_INFO 1		/* to get more info in advanced mode */
 
+#define BEGIN_DL(text) fprintf(fp0, "<h2>%s</h2>\n<dl compact>", text)
+#define END_DL()       fprintf(fp0, "\n</dl>\n")
+
+#define ADD_SS(label,value)       dt_String(fp0, label, value)
+#define ADD_NN(label,value,units) dt_Number(fp0, label, value, units)
+
+static int label_columns;
+
 /*
  * LYNX_VERSION and LYNX_DATE are automatically generated by PRCS, the tool
  * which we use to archive versions of Lynx.  We use a convention for naming
@@ -56,6 +64,45 @@ char *LYVersionDate(void)
     return temp;
 }
 
+static void dt_String(FILE *fp,
+		      const char *label,
+		      const char *value)
+{
+    int have;
+    int need;
+    char *the_label = 0;
+    char *the_value = 0;
+
+    StrAllocCopy(the_label, label);
+    StrAllocCopy(the_value, value);
+
+    have = strlen(the_label);
+    need = LYstrExtent(the_label, have, label_columns);
+
+    LYEntify(&the_label, TRUE);
+    LYEntify(&the_value, TRUE);
+
+    fprintf(fp, "<dt>");
+    while (need++ < label_columns)
+	fprintf(fp, "&nbsp;");
+    fprintf(fp, "<em>%s</em> %s\n", the_label, the_value);
+
+    FREE(the_label);
+    FREE(the_value);
+}
+
+static void dt_Number(FILE *fp0,
+		      const char *label,
+		      long number,
+		      const char *units)
+{
+    char *value = NULL;
+
+    HTSprintf(&value, "%ld %s", number, units);
+    ADD_SS(label, value);
+    FREE(value);
+}
+
 /*
  * LYShowInfo prints a page of info about the current file and the link that
  * the cursor is on.
@@ -68,9 +115,10 @@ int LYShowInfo(DocInfo *doc,
     static char tempfile[LY_MAXPATH] = "\0";
     int url_type;
     FILE *fp0;
-    char *Address = NULL, *Title = NULL;
+    char *Title = NULL;
     char *name;
     const char *cp;
+    char *temp = 0;
 
 #ifdef ADVANCED_INFO
     BOOLEAN LYInfoAdvanced = (BOOL) (user_mode == ADVANCED_MODE);
@@ -107,10 +155,9 @@ int LYShowInfo(DocInfo *doc,
 	}
     }
 
-    fprintf(fp0, "<html>\n<head>\n");
-    LYAddMETAcharsetToFD(fp0, -1);
-    fprintf(fp0, "<title>%s</title>\n</head>\n<body>\n",
-	    SHOWINFO_TITLE);
+    label_columns = 9;
+
+    WriteInternalTitle(fp0, SHOWINFO_TITLE);
 
     fprintf(fp0, "<h1>%s %s (%s) (<a href=\"%s\">%s</a>)",
 	    LYNX_NAME, LYNX_VERSION,
@@ -122,17 +169,16 @@ int LYShowInfo(DocInfo *doc,
 
 #ifdef DIRED_SUPPORT
     if (lynx_edit_mode && nlinks > 0) {
-	char *temp;
 
-	fprintf(fp0, "<pre>\n");
-	fprintf(fp0, "\n%s\n\n",
-		gettext("Directory that you are currently viewing"));
+	BEGIN_DL(gettext("Directory that you are currently viewing"));
 
 	temp = HTfullURL_toFile(doc->address);
-	fprintf(fp0, "   <em>%4s</em>  %s\n", gettext("Name:"), temp);
+	ADD_SS(gettext("Name:"), temp);
 	FREE(temp);
 
-	fprintf(fp0, "   <em>%4s</em>  %s\n", gettext("URL:"), doc->address);
+	ADD_SS(gettext("URL:"), doc->address);
+
+	END_DL();
 
 	temp = HTfullURL_toFile(links[doc->link].lname);
 
@@ -142,22 +188,19 @@ int LYShowInfo(DocInfo *doc,
 	} else {
 	    char modes[80];
 
+	    label_columns = 16;
 	    if (S_ISDIR(dir_info.st_mode)) {
-		fprintf(fp0, "\n%s\n\n",
-			gettext("Directory that you have currently selected"));
+		BEGIN_DL(gettext("Directory that you have currently selected"));
 	    } else if (S_ISREG(dir_info.st_mode)) {
-		fprintf(fp0, "\n%s\n\n",
-			gettext("File that you have currently selected"));
+		BEGIN_DL(gettext("File that you have currently selected"));
 #ifdef S_IFLNK
 	    } else if (S_ISLNK(dir_info.st_mode)) {
-		fprintf(fp0, "\n%s\n\n",
-			gettext("Symbolic link that you have currently selected"));
+		BEGIN_DL(gettext("Symbolic link that you have currently selected"));
 #endif
 	    } else {
-		fprintf(fp0, "\n%s\n\n",
-			gettext("Item that you have currently selected"));
+		BEGIN_DL(gettext("Item that you have currently selected"));
 	    }
-	    fprintf(fp0, "       <em>%s</em>  %s\n", gettext("Full name:"), temp);
+	    ADD_SS(gettext("Full name:"), temp);
 #ifdef S_IFLNK
 	    if (S_ISLNK(dir_info.st_mode)) {
 		char buf[1025];
@@ -168,36 +211,36 @@ int LYShowInfo(DocInfo *doc,
 		} else {
 		    sprintf(buf, "%.1024s", gettext("Unable to follow link"));
 		}
-		fprintf(fp0, "  <em>%s</em>  %s\n",
-			gettext("Points to file:"), buf);
+		ADD_SS(gettext("Points to file:"), buf);
 	    }
 #endif
 	    name = HTAA_UidToName(dir_info.st_uid);
 	    if (*name)
-		fprintf(fp0, "   <em>%s</em>  %s\n",
-			gettext("Name of owner:"), name);
+		ADD_SS(gettext("Name of owner:"), name);
 	    name = HTAA_GidToName(dir_info.st_gid);
 	    if (*name)
-		fprintf(fp0, "      <em>%s</em>  %s\n",
-			gettext("Group name:"), name);
+		ADD_SS(gettext("Group name:"), name);
 	    if (S_ISREG(dir_info.st_mode)) {
-		fprintf(fp0, "       <em>%s</em>  %ld (bytes)\n",
-			gettext("File size:"), (long) dir_info.st_size);
+		ADD_NN(gettext("File size:"),
+		       (long) dir_info.st_size,
+		       gettext("(bytes)"));
 	    }
 	    /*
 	     * Include date and time information.
 	     */
-	    cp = ctime(&dir_info.st_ctime);
-	    fprintf(fp0, "   <em>%s</em>  %s", gettext("Creation date:"), cp);
+	    ADD_SS(gettext("Creation date:"),
+		   ctime(&dir_info.st_ctime));
 
-	    cp = ctime(&dir_info.st_mtime);
-	    fprintf(fp0, "   <em>%s</em>  %s", gettext("Last modified:"), cp);
+	    ADD_SS(gettext("Last modified:"),
+		   ctime(&dir_info.st_mtime));
 
-	    cp = ctime(&dir_info.st_atime);
-	    fprintf(fp0, "   <em>%s</em>  %s\n", gettext("Last accessed:"), cp);
+	    ADD_SS(gettext("Last accessed:"),
+		   ctime(&dir_info.st_atime));
 
-	    fprintf(fp0, "   %s\n", gettext("Access Permissions"));
-	    fprintf(fp0, "      <em>%s</em>  ", gettext("Owner:"));
+	    END_DL();
+
+	    label_columns = 9;
+	    BEGIN_DL(gettext("Access Permissions"));
 	    modes[0] = '\0';
 	    modes[1] = '\0';	/* In case there are no permissions */
 	    modes[2] = '\0';
@@ -214,9 +257,8 @@ int LYShowInfo(DocInfo *doc,
 			strcat(modes, ", setuid");
 		}
 	    }
-	    fprintf(fp0, "%s\n", (char *) &modes[2]);	/* Skip leading ', ' */
+	    ADD_SS(gettext("Owner:"), &modes[2]);
 
-	    fprintf(fp0, "      <em>Group:</em>  ");
 	    modes[0] = '\0';
 	    modes[1] = '\0';	/* In case there are no permissions */
 	    modes[2] = '\0';
@@ -233,9 +275,8 @@ int LYShowInfo(DocInfo *doc,
 			strcat(modes, ", setgid");
 		}
 	    }
-	    fprintf(fp0, "%s\n", (char *) &modes[2]);	/* Skip leading ', ' */
+	    ADD_SS(gettext("Group:"), &modes[2]);
 
-	    fprintf(fp0, "      <em>World:</em>  ");
 	    modes[0] = '\0';
 	    modes[1] = '\0';	/* In case there are no permissions */
 	    modes[2] = '\0';
@@ -254,34 +295,29 @@ int LYShowInfo(DocInfo *doc,
 #endif
 		}
 	    }
-	    fprintf(fp0, "%s\n", (char *) &modes[2]);	/* Skip leading ', ' */
+	    ADD_SS(gettext("World:"), &modes[2]);
+	    END_DL();
 	}
 	FREE(temp);
-	fprintf(fp0, "</pre>\n");
     } else {
 #endif /* DIRED_SUPPORT */
 
-	fprintf(fp0, "<h2>%s</h2>\n<dl compact>",
-		gettext("File that you are currently viewing"));
+	BEGIN_DL(gettext("File that you are currently viewing"));
 
 	LYformTitle(&Title, doc->title);
-	LYEntify(&Title, TRUE);
-	fprintf(fp0, "<dt><em>%s</em> %s%s\n",
-		gettext("Linkname:"),
-		Title,
-		((doc->isHEAD &&
-		  !strstr(Title, " (HEAD)") &&
-		  !strstr(Title, " - HEAD")) ? " (HEAD)" : ""));
-
-	StrAllocCopy(Address, doc->address);
-	LYEntify(&Address, TRUE);
-	fprintf(fp0,
-		"<dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>URL:</em> %s\n", Address);
+	HTSprintf(&temp, "%s%s",
+		  Title,
+		  ((doc->isHEAD &&
+		    !strstr(Title, " (HEAD)") &&
+		    !strstr(Title, " - HEAD")) ? " (HEAD)" : ""));
+	ADD_SS(gettext("Linkname:"), temp);
+	FREE(temp);
+
+	ADD_SS("URL:", doc->address);
 
 	if (HTLoadedDocumentCharset()) {
-	    fprintf(fp0, "<dt><em>&nbsp;%s</em> %s\n",
-		    gettext("Charset:"),
-		    HTLoadedDocumentCharset());
+	    ADD_SS(gettext("Charset:"),
+		   HTLoadedDocumentCharset());
 	} else {
 	    LYUCcharset *p_in = HTAnchor_getUCInfoStage(HTMainAnchor,
 							UCT_STAGE_PARSER);
@@ -292,41 +328,38 @@ int LYShowInfo(DocInfo *doc,
 	    }
 	    if (p_in && p_in->MIMEname && *(p_in->MIMEname) &&
 		HTAnchor_getUCLYhndl(HTMainAnchor, UCT_STAGE_MIME) >= 0) {
-		fprintf(fp0, "<dt><em>&nbsp;%s</em> %s (assumed)\n",
-			gettext("Charset:"),
-			p_in->MIMEname);
+		HTSprintf(&temp, "%s %s",
+			  p_in->MIMEname,
+			  gettext("(assumed)"));
+		ADD_SS(gettext("Charset:"), p_in->MIMEname);
+		FREE(temp);
 	    }
 	}
 
 	if ((cp = HText_getServer()) != NULL && *cp != '\0')
-	    fprintf(fp0, "<dt><em>&nbsp;&nbsp;%s</em> %s\n",
-		    gettext("Server:"), cp);
+	    ADD_SS(gettext("Server:"), cp);
 
 	if ((cp = HText_getDate()) != NULL && *cp != '\0')
-	    fprintf(fp0, "<dt><em>&nbsp;&nbsp;&nbsp;&nbsp;%s</em> %s\n",
-		    gettext("Date:"), cp);
+	    ADD_SS(gettext("Date:"), cp);
 
 	if ((cp = HText_getLastModified()) != NULL && *cp != '\0')
-	    fprintf(fp0, "<dt><em>%s</em> %s\n", gettext("Last Mod:"), cp);
+	    ADD_SS(gettext("Last Mod:"), cp);
 
 #ifdef ADVANCED_INFO
 	if (LYInfoAdvanced) {
 	    if (HTMainAnchor && HTMainAnchor->expires) {
-		fprintf(fp0, "<dt><em>%s</em> %s\n",
-			gettext("&nbsp;Expires:"), HTMainAnchor->expires);
+		ADD_SS(gettext("Expires:"), HTMainAnchor->expires);
 	    }
 	    if (HTMainAnchor && HTMainAnchor->cache_control) {
-		fprintf(fp0, "<dt><em>%s</em> %s\n",
-			gettext("Cache-Control:"), HTMainAnchor->cache_control);
+		ADD_SS(gettext("Cache-Control:"), HTMainAnchor->cache_control);
 	    }
 	    if (HTMainAnchor && HTMainAnchor->content_length > 0) {
-		fprintf(fp0, "<dt><em>%s</em> %d %s\n",
-			gettext("Content-Length:"),
-			HTMainAnchor->content_length, gettext("bytes"));
+		ADD_NN(gettext("Content-Length:"),
+		       HTMainAnchor->content_length,
+		       gettext("bytes"));
 	    }
 	    if (HTMainAnchor && HTMainAnchor->content_language) {
-		fprintf(fp0, "<dt><em>%s</em> %s\n",
-			gettext("Language:"), HTMainAnchor->content_language);
+		ADD_SS(gettext("Language:"), HTMainAnchor->content_language);
 	    }
 	}
 #endif /* ADVANCED_INFO */
@@ -336,94 +369,83 @@ int LYShowInfo(DocInfo *doc,
 		    gettext("Post Data:"),
 		    BStrLen(doc->post_data),
 		    BStrData(doc->post_data));
-	    fprintf(fp0, "<dt><em>%s</em> %s\n",
-		    gettext("Post Content Type:"), doc->post_content_type);
+	    ADD_SS(gettext("Post Content Type:"), doc->post_content_type);
 	}
 
-	if (owner_address) {
-	    StrAllocCopy(Address, owner_address);
-	    LYEntify(&Address, TRUE);
-	} else {
-	    StrAllocCopy(Address, NO_NOTHING);
-	}
-	fprintf(fp0, "<dt><em>%s</em> %s\n", gettext("Owner(s):"), Address);
-
-	fprintf(fp0, "<dt>&nbsp;&nbsp;&nbsp;&nbsp;<em>%s</em> %d %s\n",
-		gettext("size:"), size_of_file, gettext("lines"));
-
-	fprintf(fp0, "<dt>&nbsp;&nbsp;&nbsp;&nbsp;<em>%s</em> %s%s%s",
-		gettext("mode:"),
-		((lynx_mode == FORMS_LYNX_MODE)
-		 ? gettext("forms mode")
-		 : (HTisDocumentSource()
-		    ? gettext("source")
-		    : gettext("normal"))),
-		(doc->safe ? gettext(", safe") : ""),
-		(doc->internal_link ? gettext(", via internal link") : "")
-	    );
+	ADD_SS(gettext("Owner(s):"),
+	       (owner_address
+		? owner_address
+		: NO_NOTHING));
+
+	ADD_NN(gettext("size:"),
+	       size_of_file,
+	       gettext("lines"));
+
+	StrAllocCopy(temp,
+		     ((lynx_mode == FORMS_LYNX_MODE)
+		      ? gettext("forms mode")
+		      : (HTisDocumentSource()
+			 ? gettext("source")
+			 : gettext("normal"))));
+	if (doc->safe)
+	    StrAllocCat(temp, gettext(", safe"));
+	if (doc->internal_link)
+	    StrAllocCat(temp, gettext(", via internal link"));
+
 #ifdef ADVANCED_INFO
 	if (LYInfoAdvanced) {
-	    fprintf(fp0, "%s%s%s\n",
-		    (HText_hasNoCacheSet(HTMainText) ?
-		     gettext(", no-cache") : ""),
-		    (HTAnchor_isISMAPScript((HTAnchor *) HTMainAnchor) ?
-		     gettext(", ISMAP script") : ""),
-		    (doc->bookmark ?
-		     gettext(", bookmark file") : "")
-		);
+	    if (HText_hasNoCacheSet(HTMainText))
+		StrAllocCat(temp, gettext(", no-cache"));
+	    if (HTAnchor_isISMAPScript((HTAnchor *) HTMainAnchor))
+		StrAllocCat(temp, gettext(", ISMAP script"));
+	    if (doc->bookmark)
+		StrAllocCat(temp, gettext(", bookmark file"));
 	}
 #endif /* ADVANCED_INFO */
 
-	fprintf(fp0, "\n</dl>\n");	/* end of list */
+	ADD_SS(gettext("mode:"), temp);
+	FREE(temp);
+
+	END_DL();
 
 	if (nlinks > 0) {
-	    fprintf(fp0, "<h2>%s</h2>\n<dl compact>",
-		    gettext("Link that you currently have selected"));
-	    StrAllocCopy(Title, LYGetHiliteStr(doc->link, 0));
-	    LYEntify(&Title, TRUE);
-	    fprintf(fp0, "<dt><em>%s</em> %s\n",
-		    gettext("Linkname:"),
-		    Title);
+	    BEGIN_DL(gettext("Link that you currently have selected"));
+	    ADD_SS(gettext("Linkname:"),
+		   LYGetHiliteStr(doc->link, 0));
 	    if (lynx_mode == FORMS_LYNX_MODE &&
 		links[doc->link].type == WWW_FORM_LINK_TYPE) {
 		if (links[doc->link].l_form->submit_method) {
 		    int method = links[doc->link].l_form->submit_method;
 		    char *enctype = links[doc->link].l_form->submit_enctype;
 
-		    fprintf(fp0, "<dt>&nbsp;&nbsp;<em>%s</em> %s\n",
-			    gettext("Method:"),
-			    ((method == URL_POST_METHOD) ? "POST" :
-			     ((method == URL_MAIL_METHOD) ? "(email)" :
-			      "GET")));
-		    fprintf(fp0, "<dt>&nbsp;<em>%s</em> %s\n",
-			    gettext("Enctype:"),
-			    (enctype &&
-			     *enctype ?
-			     enctype : "application/x-www-form-urlencoded"));
+		    ADD_SS(gettext("Method:"),
+			   ((method == URL_POST_METHOD) ? "POST" :
+			    ((method == URL_MAIL_METHOD) ? "(email)" :
+			     "GET")));
+		    ADD_SS(gettext("Enctype:"),
+			   (non_empty(enctype)
+			    ? enctype
+			    : "application/x-www-form-urlencoded"));
 		}
 		if (links[doc->link].l_form->submit_action) {
-		    StrAllocCopy(Address, links[doc->link].l_form->submit_action);
-		    LYEntify(&Address, TRUE);
-		    fprintf(fp0, "<dt>&nbsp;&nbsp;<em>Action:</em> %s\n", Address);
+		    ADD_SS(gettext("Action:"),
+			   links[doc->link].l_form->submit_action);
 		}
 		if (!(links[doc->link].l_form->submit_method &&
 		      links[doc->link].l_form->submit_action)) {
 		    fprintf(fp0, "<dt>&nbsp;%s\n", gettext("(Form field)"));
 		}
 	    } else {
-		if (links[doc->link].lname) {
-		    StrAllocCopy(Title, links[doc->link].lname);
-		    LYEntify(&Title, TRUE);
-		} else {
-		    StrAllocCopy(Title, "");
-		}
-		fprintf(fp0,
-			"<dt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<em>URL:</em> %s\n", Title);
+		ADD_SS("URL:",
+		       (links[doc->link].lname
+			? links[doc->link].lname
+			: ""));
 	    }
-	    fprintf(fp0, "</dl>\n");	/* end of list */
+	    END_DL();
 
-	} else
+	} else {
 	    fprintf(fp0, "<h2>%s</h2>", gettext("No Links on the current page"));
+	}
 
 #ifdef EXP_HTTP_HEADERS
 	if ((cp = HText_getHttpHeaders()) != 0) {
@@ -440,7 +462,6 @@ int LYShowInfo(DocInfo *doc,
     LYrefresh();
 
     LYCloseTemp(tempfile);
-    FREE(Address);
     FREE(Title);
 
     return (0);