www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1998/02/25/00:39:18

Date: Wed, 25 Feb 1998 05:38:17 +0000 (GMT)
From: George Foot <george DOT foot AT merton DOT oxford DOT ac DOT uk>
To: djgpp-workers AT delorie DOT com
Subject: Patch for mkdoc.cc
Message-ID: <Pine.OSF.3.95.980225042750.12874A-100000@sable.ox.ac.uk>
MIME-Version: 1.0

Here's a patch for v2.02's mkdoc.cc to make it read portability
information in .txh files.  Apply with "patch -p 1" from the base djgpp
directory.

-- 
george DOT foot AT merton DOT oxford DOT ac DOT uk


diff -C 2 -r old/src/mkdoc/mkdoc.cc new/src/mkdoc/mkdoc.cc
*** old/src/mkdoc/mkdoc.cc	Sun Nov 16 14:08:36 1997
--- new/src/mkdoc/mkdoc.cc	Wed Feb 25 04:15:00 1998
***************
*** 5,8 ****
--- 5,10 ----
  #include <sys/stat.h>
  #include <unistd.h>
+ #include <stdlib.h>
+ #include <ctype.h>
  
  char *dj_strlwr(char *s)
***************
*** 24,27 ****
--- 26,42 ----
  typedef void (*TFunc)(Node *);
  
+ 
+ #define NUM_PORT_TARGETS 2
+ 
+ #define PORT_NO      0
+ #define PORT_PARTIAL 1
+ #define PORT_YES     2
+ 
+ /* Tokens for use in .txh files */
+ char *port_target[NUM_PORT_TARGETS] = { "ansi", "posix" };
+ /* Strings to output in .txi files */
+ char *port_target_string[NUM_PORT_TARGETS] = { "ANSI", "POSIX" };
+ 
+ 
  struct Tree {
    TreeNode *nodes;
***************
*** 38,41 ****
--- 53,63 ----
  };
  
+ struct PortNote {
+   struct PortNote *next;
+   int target;
+   int number;
+   char *note;
+ };
+ 
  struct Node {
    Node *prev, *next;
***************
*** 47,52 ****
--- 69,80 ----
    Tree subnodes;
    char *filename;
+   int port_info[NUM_PORT_TARGETS];
+   PortNote *port_notes;
    Node(char *name, char *cat);
    void add(char *line);
+   void process(char *line);
+   void read_portability_note(char *str);
+   void read_portability(char *str);
+   void write_portability();
  };
  
***************
*** 72,75 ****
--- 100,105 ----
    lines = 0;
    lastline = 0;
+   for (int i = 0; i < NUM_PORT_TARGETS; i++) port_info[i] = PORT_NO;
+   port_notes = NULL;
  }
  
***************
*** 87,90 ****
--- 117,287 ----
  }
  
+ void
+ Node::read_portability_note(char *str)
+ {
+   char *work_str = strdup (str);
+   char *s = work_str;
+   char *target;
+ 
+   while (isspace(*s)) s++;
+   target = s;
+   while (*s && !isspace(*s)) s++;
+   if (*s) *s++ = 0;
+   while (isspace(*s)) s++;
+   dj_strlwr (target);
+ 
+   int targ_num;
+   for (targ_num = 0; targ_num < NUM_PORT_TARGETS; targ_num++)
+     if (!strcmp (target, port_target[targ_num])) break;
+ 
+   if (targ_num == NUM_PORT_TARGETS)
+   {
+     fprintf (stderr, "%s: unrecognised portability note target `%s' ignored.\n", filename, target);
+   }
+   else
+   {
+     if (!*s)
+     {
+       fprintf (stderr, "%s: empty portability note for target `%s' ignored.\n", filename, target);
+     }
+     else
+     {
+       PortNote *p = new PortNote;
+       p->next = NULL;
+       p->number = 0;
+       p->target = targ_num;
+       p->note = strdup (s);
+       if (port_notes)
+       {
+ 	PortNote *q = port_notes;
+ 	while (q->next) q = q->next;
+ 	q->next = p;
+       }
+       else
+       {
+ 	port_notes = p;
+       }
+     }
+   }
+   free (work_str);
+ }
+ 
+ void
+ Node::read_portability(char *str)
+ {
+   char *targets = dj_strlwr (strdup (str));
+   char *x, *target = targets;
+   int type,i;
+ 
+   while (isspace (*target)) target++;
+   while (*target) {
+ 
+     type = PORT_YES;
+     if (*target == '~')
+     {
+       type = PORT_PARTIAL;
+       target++;
+     }
+ 
+     for (x = target; *x && !isspace(*x); x++);
+     if (*x) *x++ = 0;
+ 
+     for (i = 0; i < NUM_PORT_TARGETS; i++)
+       if (!strcmp (target, port_target[i])) break;
+ 
+     if (i < NUM_PORT_TARGETS)
+       port_info[i] = type;
+     else
+       fprintf (stderr, "%s: unrecognised portability target `%s' ignored.\n", filename, target);
+ 
+     target = x;
+     while (isspace (*target)) target++;
+   }
+ 
+   free (targets);
+ }
+ 
+ void
+ Node::write_portability()
+ {
+   char buffer[1024] = { 0 };
+   int note_number = 1;
+ 
+   for (int i = 0; i < NUM_PORT_TARGETS; i++)
+   {
+     switch (port_info[i])
+     {
+       case PORT_NO:
+ 	strcat (buffer, "not ");
+ 	strcat (buffer, port_target_string[i]);
+ 	break;
+       case PORT_YES:
+ 	strcat (buffer, port_target_string[i]);
+ 	break;
+       case PORT_PARTIAL:
+ 	strcat (buffer, "partially ");
+ 	strcat (buffer, port_target_string[i]);
+ 	break;
+     }
+     for (PortNote *p = port_notes; p; p = p->next)
+     {
+       if (p->target == i)
+       {
+ 	char smallbuffer[10];
+ 	p->number = note_number++;
+ 	sprintf (smallbuffer, " (%d)", p->number);
+ 	strcat (buffer, smallbuffer);
+       }
+     }
+     strcat (buffer, ", ");
+   }
+ 
+   char *ch = strchr (buffer, 0) - 2;
+   if (*ch == ',')
+     *ch = 0;
+   else
+     strcpy (buffer, "Not portable.");
+ 
+   strcat (buffer, "\n");
+   add(buffer);
+ 
+   for (int i = 1; i < note_number; i++)
+     for (PortNote *p = port_notes; p; p = p->next)
+       if (p->number == i)
+       {
+ 	sprintf (buffer, "(%d) %s\n", i, p->note);
+ 	add("\n");
+ 	add(buffer);
+       }
+ 
+   /* Now free the portability notes */
+   while (port_notes) {
+     PortNote *p = port_notes;
+     port_notes = p->next;
+     free (p->note);
+     delete p;
+   }
+ 
+   free(buffer);
+ }
+ 
+ void
+ Node::process(char *line)
+ {
+   if ((strncmp (line, "@portability", 12) == 0) && isspace (line[12]))
+   {
+     read_portability(line+13);
+     write_portability();
+   }
+   else if (strncmp (line, "@port-note ", 11) == 0)
+   {
+     read_portability_note(line+11);
+   }
+   else
+   {
+     add(line);
+   }
+ }
+ 
  //-----------------------------------------------------------------------------
  
***************
*** 232,238 ****
        result = stat(name, &statbuf);
        if(result < 0)
!               return 0;
        if(S_ISDIR(statbuf.st_mode))
!               return 1;
        else    return 0;
  }
--- 429,435 ----
        result = stat(name, &statbuf);
        if(result < 0)
! 	      return 0;
        if(S_ISDIR(statbuf.st_mode))
! 	      return 1;
        else    return 0;
  }
***************
*** 240,244 ****
  //-----------------------------------------------------------------------------
  
! scan_directory(char *which)
  {
    Node *curnode;
--- 437,441 ----
  //-----------------------------------------------------------------------------
  
! void scan_directory(char *which)
  {
    Node *curnode;
***************
*** 300,304 ****
  	{
  	  if (curnode)
! 	    curnode->add(buf);
  	}
        }
--- 497,501 ----
  	{
  	  if (curnode)
! 	    curnode->process(buf);
  	}
        }

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019