links in man2hlp

David Martin dmartina at excite.com
Mon Oct 21 10:00:25 UTC 2002


I tried this to get punctuation marks out the link references
avoiding extra spaces (ala .BR or .IR). The best idea I got
was using "\&" as separator because it seems to have no side
effects for groff in the man page. I read something about
"\&" preventing kerning between characters but that doesn't
seem anything to worry about.

I invented a LINK3 entry but if you trust the code it could go
as LINK2. I was careful with strings but I don't know if
glib functions must be used anyway.

Is there anyway to get the date into the help/groff files?
I (me again :) wanted to complete the header and the footer
(in .TH at the head of the file). @VERSION@ seems to do the
job for the version (like @prefix@) in mc.1.in.

*8-) David

------------------

--- /man2hlp.c	2002-10-18 04:22:34.000000000 +0200
+++ man2hlp.c	2002-10-20 17:19:55.000000000 +0200
@@ -482,6 +482,9 @@
     } else if (strcmp (buffer, ".\\\"LINK2\"") == 0) {
 	/* Next two input lines form a link */
 	link_flag = 2;
+    } else if (strcmp (buffer, ".\\\"LINK3\"") == 0) {
+	/* Next two input lines form a link */
+	link_flag = 4;
     } else if ((strcmp (buffer, ".PP") == 0) || (strcmp (buffer, ".P") == 0)
 	       || (strcmp (buffer, ".LP") == 0)) {
 	indentation = 0;
@@ -591,7 +594,9 @@
 static void
 handle_link (char *buffer)
 {
-    static char old[80];
+    static char old[BUFFER_SIZE];
+    static char rest[BUFFER_SIZE];
+    char *endlink;
     int len;
 
     switch (link_flag) {
@@ -601,9 +606,31 @@
     case 2:
 	/* First part of new format link */
 	/* Bold text or italics text */
+
+	/* FIXME: Take care of .XX as .IR, .BR, etc. */
+	if (buffer[0] == '.' && (buffer[1] == 'I' || buffer[1] == 'B'))
+	    for (buffer += 2; *buffer == ' ' || *buffer == '\t'; buffer++);
+	snprintf (old, BUFFER_SIZE, "%s", buffer);
+	strcpy (rest, "");
+	link_flag = 3;
+	break;
+    case 4:
+	/* Same as previous but using a mark to end link */
+
+	/* FIXME: Take care of .XX as .IR, .BR, etc. */
 	if (buffer[0] == '.' && (buffer[1] == 'I' || buffer[1] == 'B'))
 	    for (buffer += 2; *buffer == ' ' || *buffer == '\t'; buffer++);
-	strcpy (old, buffer);
+
+	endlink = strstr(buffer,"\\&");
+
+	if (endlink) {
+	    snprintf(old, BUFFER_SIZE, "%.*s", endlink-buffer, buffer);
+	    snprintf(rest, BUFFER_SIZE, "%s", endlink+2);
+	} else {
+	    snprintf (old, BUFFER_SIZE, "%s", buffer);
+	    strcpy (rest, "");
+	}
+
 	link_flag = 3;
 	break;
     case 3:
@@ -618,8 +645,8 @@
 	if (len && buffer[len - 1] == '"') {
 	    buffer[--len] = 0;
 	}
-	printf_string ("%c%s%c%s%c\n", CHAR_LINK_START, old,
-		       CHAR_LINK_POINTER, buffer, CHAR_LINK_END);
+	printf_string ("%c%s%c%s%c%s\n", CHAR_LINK_START, old,
+		       CHAR_LINK_POINTER, buffer, CHAR_LINK_END, rest);
 	link_flag = 0;
 	/* Add to the linked list */
 	if (current_link) {



_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!



More information about the mc-devel mailing list