[Pinfo-devel] r44 - pinfo/branches/cxx/src

Nathanael Nerode neroden-guest at costa.debian.org
Fri Aug 26 09:51:23 UTC 2005


Author: neroden-guest
Date: 2005-08-26 09:51:20 +0000 (Fri, 26 Aug 2005)
New Revision: 44

Modified:
   pinfo/branches/cxx/src/manual.cxx
   pinfo/branches/cxx/src/pinfo.cxx
Log:
Remove dead ignore_macros code from manual.cxx.
Make handlemanual take a const argument.
Convert some low-hanging fruit in getopts (pinfo.cxx) to std::string.


Modified: pinfo/branches/cxx/src/manual.cxx
===================================================================
--- pinfo/branches/cxx/src/manual.cxx	2005-08-26 09:31:51 UTC (rev 43)
+++ pinfo/branches/cxx/src/manual.cxx	2005-08-26 09:51:20 UTC (rev 44)
@@ -244,7 +244,7 @@
 
 /* this is something like main() function for the manual viewer code.  */
 int
-handlemanual(char *name)
+handlemanual(char * const name)
 {
 	int return_value = 0;
 	struct stat statbuf;
@@ -287,159 +287,7 @@
 	maxx = 80;
 	maxy = 25;
 #endif /* getmaxyx */
-#ifdef NIETS
-	/****************************************************************************
-	 *                    Ignore macros part: BEGIN                             *
-	 * PS: Siewca: I still expect that you'll isolate it to a single procedure  *
-	 * Description(by PB): This code opens a manpage file, and filters it from *
-	 * dangerous macros. The output is put into a temporary file, which is then *
-	 * used as the `name' filename argument of this(handlemanual) procedure.   *
-	 * There is a stored variable raw_tempfilename to allow unlinking this temp *
-	 * file after usage							    *
-	 ****************************************************************************/
-	/* if the pointer is non-null */
-	if (ignoredmacros)
-		/* if there are some macros */
-		if (*ignoredmacros && strlen(ignoredmacros))
-		{				/* that should be ignored   */
-			*location = '\0';
-			/* we need to know the path */
-			snprintf(cmd, 255, "man -W %s %s",
-					ManOptions,
-					name);
-			id = popen(cmd, "r");
-			if (!id)
-			{
-				printf(_("Error: Cannot call man command.\n"));
-				return 1;
-			}
-			fflush(id);
-			fgets(location, 255, id);
-			pclose(id);
 
-			if (*location == '\0')
-			{
-				printf(_("Error: No manual page found either.\n"));
-				if (use_apropos)
-				{
-					printf(_("Appropriate pages:\n"));
-					snprintf(cmd, 255, "apropos %s|cat %s", name, StderrRedirection);
-					system(cmd);
-				}
-				return 1;
-			}
-
-
-			ignored_items++;
-			prev = ignoredmacros;
-			/* counting items */
-			while ((end = strchr(prev, ':')))
-			{
-				ignored_items++;
-				prev = end + 1;
-			}
-
-			ignored_entries =(char **) (char*)xmalloc(ignored_items * sizeof(char **));
-			ignored_entries[0] = ignoredmacros;
-			prev = ignoredmacros;
-			i = 0;
-			/* creating pointers */
-			while ((end = strchr(prev, ':')))
-			{
-				*end = '\0';
-				prev = end + 1;
-				i++;
-				ignored_entries[i] = prev;
-			}
-
-			/* removing newline */
-			if ((prev = rindex(location, '\n')))
-				*prev = '\0';
-
-			/* checking if it's compressed */
-			prev = index(location, '\0');
-			if ((strlen(location)) > 3
-					&&((*(prev - 1) == 'Z' && *(prev - 2) == '.')
-						||(*(prev - 1) == 'z' && *(prev - 2) == 'g' && *(prev - 3) == '.')
-					   )
-			   )
-			{
-				if (verbose)
-					printf("%s %s\n", _("Calling gunzip for"), location);
-				snprintf(cmd, 255, "gunzip -c %s", location);
-				source = popen(cmd, "r");
-				zipped = 1;
-				if (!source)
-				{
-					printf(_("Couldn't call gunzip.\n"));
-					return 1;
-				}
-			}
-			else /* from cmd output  */
-				source = fopen(location, "r");
-			name = tempnam("/tmp", NULL);
-			raw_tempfilename = name;
-			id = fopen(name, "w");
-
-			/* we read until eof */
-			while (!feof(source))
-			{
-				if (fgets(line, 1024, source) == NULL)
-					line[0] = '\0';
-
-				/* macro starts with a dot*/
-				if (line[0] != '.' ||(strlen(line)) <(size_t) 2)
-				{
-					fprintf(id, "%s", line);
-					continue;
-				}
-				else
-					while (i >= 0)
-					{
-						macroline_size = strlen(ignored_entries[i]);
-						if (strlen(line + 1) < macroline_size)
-							macroline_size = strlen(line + 1);
-						if ((strncmp(ignored_entries[i], line + 1, macroline_size)) == 0
-								&&(*(line + 1 +(int) macroline_size) == ' '
-									|| *(line + 1 +(int) macroline_size) == '\n'
-									|| *(line + 1 +(int) macroline_size) == '\t'))
-						{
-							if (quote_ignored)
-							{
-								if ((prev = rindex(line, '\n')))
-									*prev = '\0';
-								sprintf(cmd, "\n.br\n.nf\n[ [pinfo] - %s: %.42s", _("IGNORING"), line);
-								if ((strlen(line)) >(size_t) 42)
-									strcat(cmd, "(...)]\n.fi\n");
-								else
-									strcat(cmd, " ]\n.fi\n");
-							}
-							else
-							{
-								sprintf(cmd, ".\\\" removed macro: %.42s", line);
-								if ((strlen(line)) >(size_t) 42)
-									strcat(cmd, "(...)");
-							}
-							strcpy(line, cmd);
-							break;
-						}
-						i--;
-					}
-
-				fprintf(id, "%s", line);
-				i = ignored_items - 1;
-			}			/* while (!feof(source)) */
-			if (zipped)
-				pclose(source);
-			else
-				fclose(source);
-			fclose(id);
-			free(ignored_entries);
-		}				/* if (ignored_macros... */
-	/****************************************************************************
-	 *                    Ignore macros part: END                               *
-	 ****************************************************************************/
-#endif
 	if (!plain_apropos)
 		snprintf(cmd, 255, "man %s %s %s > %s",
 				ManOptions,

Modified: pinfo/branches/cxx/src/pinfo.cxx
===================================================================
--- pinfo/branches/cxx/src/pinfo.cxx	2005-08-26 09:31:51 UTC (rev 43)
+++ pinfo/branches/cxx/src/pinfo.cxx	2005-08-26 09:51:20 UTC (rev 44)
@@ -135,16 +135,17 @@
 				exit(0);
 			case 'm':
 				{
-					char filename[256];
 					checksu();
 					if (verbose)
 						printf(_("Looking for man page...\n"));
-					strcpy(filename, "");
+					filename_string = "";
 					for (int i = optind; i < argc; i++)
 					{
-						strcat(filename, argv[i]);
-						strcat(filename, " ");
+						filename_string.append(argv[i]);
+						filename_string.append(" ");
 					}
+					char filename[256];
+					strncpy(filename, filename_string.c_str(), 200);
 					exit(handlemanual(filename));
 					/* This is weird in the extreme!!! Fixme. */
 				}




More information about the Pinfo-devel mailing list