diff lib-src/sorted-doc.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents 74fd4e045ea6
children
line wrap: on
line diff
--- a/lib-src/sorted-doc.c	Mon Aug 13 11:19:22 2007 +0200
+++ b/lib-src/sorted-doc.c	Mon Aug 13 11:20:41 2007 +0200
@@ -7,22 +7,33 @@
 
 /* Synched up with: FSF 19.28. */
 
-#include <config.h>
+#include <../src/config.h>
 
 #include <stdio.h>
 #include <ctype.h>
-#include <stdlib.h> /* for qsort() and malloc() */
-#include <string.h>
-static void *xmalloc (size_t);
+#if __STDC__ || defined(STDC_HEADERS)
+# include <stdlib.h> /* for qsort() and malloc() */
+# include <string.h>
+static void *xmalloc (int);
+# ifndef CONST
+#  define CONST const
+# endif
+#else
+extern char *malloc ();
+static void *xmalloc ();
+# ifndef CONST
+#  define CONST
+# endif
+#endif
 
 #define NUL	'\0'
 #define MARKER '\037'
 
 #define DEBUG 0
 
-typedef struct LINE LINE;
+typedef struct line LINE;
 
-struct LINE
+struct line
 {
   LINE *next;			/* ptr to next or NULL */
   char *line;			/* text of the line */
@@ -61,9 +72,9 @@
 /* Like malloc but get fatal error if memory is exhausted.  */
 
 static void *
-xmalloc (size_t size)
+xmalloc (int size)
 {
-  void *result = malloc (size);
+  char *result = malloc ((unsigned)size);
   if (result == NULL)
     fatal ("%s", "virtual memory exhausted");
   return result;
@@ -72,9 +83,9 @@
 static char *
 strsav (char *str)
 {
-  char *buf = (char *) xmalloc (strlen (str) + 1);
-  strcpy (buf, str);
-  return buf;
+  char *buf = xmalloc (strlen (str) + 1);
+  (void) strcpy (buf, str);
+  return (buf);
 }
 
 /* Comparison function for qsort to call.  */
@@ -93,7 +104,7 @@
   WAITING, BEG_NAME, NAME_GET, BEG_DESC, DESC_GET
 };
 
-const char *states[] =
+CONST char *states[] =
 {
   "WAITING", "BEG_NAME", "NAME_GET", "BEG_DESC", "DESC_GET"
 };
@@ -198,7 +209,12 @@
     /* sort the array by name; within each name, by type */
 
     qsort ((char*)array, cnt, sizeof (DOCSTR*),
-	   (int (*)(const void *, const void *)) cmpdoc);
+	   /* was cast to (int (*)(CONST void *, CONST void *))
+	      but that loses on HP because CONST_IS_LOSING. */
+	   /* This one loses too: (int (*)()) */
+	   /* Ok, so let's try const instead of CONST.  Fuck me!!! */
+	   (int (*)(const void *, const void *))
+	   cmpdoc);
 
     /* write the output header */