Comments: Authenticated sender is From: "George Foot" To: djgpp-workers AT delorie DOT com Date: Sun, 23 Aug 1998 22:17:28 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: mkdoc.cc patch Reply-to: george DOT foot AT merton DOT oxford DOT ac DOT uk Message-Id: Precedence: bulk Sorry, forgot to include the patch! It follows. *** mkdoc.old Sun Jun 28 22:39:06 1998 --- mkdoc.cc Sun Aug 23 20:38:14 1998 *************** *** 8,13 **** --- 8,14 ---- #include #include #include + #include char *dj_strlwr(char *s) { *************** *** 30,38 **** #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" }; --- 31,40 ---- #define NUM_PORT_TARGETS 2 ! #define PORT_UNKNOWN 0 ! #define PORT_NO 1 ! #define PORT_PARTIAL 2 ! #define PORT_YES 3 /* Tokens for use in .txh files */ char *port_target[NUM_PORT_TARGETS] = { "ansi", "posix" }; *************** *** 72,80 **** --- 74,85 ---- char *filename; int port_info[NUM_PORT_TARGETS]; PortNote *port_notes; + PortNote *last_port_note; Node(char *name, char *cat); void add(char *line); void process(char *line); + void error(char *str, ...); + void extend_portability_note(char *str); void read_portability_note(char *str); void read_portability(char *str); void write_portability(); *************** *** 101,108 **** cat = strdup(Pcat); lines = 0; lastline = 0; ! for (int i = 0; i < NUM_PORT_TARGETS; i++) port_info[i] = PORT_NO; port_notes = NULL; } void --- 106,114 ---- cat = strdup(Pcat); lines = 0; lastline = 0; ! for (int i = 0; i < NUM_PORT_TARGETS; i++) port_info[i] = PORT_UNKNOWN; port_notes = NULL; + last_port_note = NULL; } void *************** *** 119,129 **** --- 125,158 ---- } void + Node::error (char *str, ...) + { + va_list arg; + char s[1024]; + + va_start (arg, str); + vsprintf (s, str, arg); + va_end (arg); + + fprintf (stderr, "Error (file %s, node %s): %s\n", filename, name, s); + } + + void + Node::extend_portability_note(char *str) + { + int newsize = strlen (last_port_note->note) + strlen (str) + 1; + char *newstring = (char *) realloc (last_port_note->note, newsize); + strcat (newstring, str); + last_port_note->note = newstring; + } + + void Node::read_portability_note(char *str) { char *work_str = strdup (str); char *s = work_str; char *target; + int targ_num; while (isspace(*s)) s++; target = s; *************** *** 132,169 **** 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); } --- 161,192 ---- while (isspace(*s)) s++; dj_strlwr (target); 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) { ! error ("unrecognised portability note target `%s' ignored.\n", target); } else { ! PortNote *p = new PortNote; ! p->next = NULL; ! p->number = 0; ! p->target = targ_num; ! p->note = strdup (""); ! ! if (port_notes) { ! last_port_note->next = p; } else { ! port_notes = p; } + last_port_note = p; + + if (*s) extend_portability_note (s); } free (work_str); } *************** *** 183,188 **** --- 206,215 ---- { type = PORT_PARTIAL; target++; + } else if (*target == '!') + { + type = PORT_NO; + target++; } for (x = target; *x && !isspace(*x); x++); *************** *** 194,200 **** 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++; --- 221,227 ---- if (i < NUM_PORT_TARGETS) port_info[i] = type; else ! error ("unrecognised portability target `%s' ignored.\n", target); target = x; while (isspace (*target)) target++; *************** *** 225,260 **** 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) { --- 252,302 ---- strcat (buffer, port_target_string[i]); break; } ! if (port_info[i] != PORT_UNKNOWN) { ! for (PortNote *p = port_notes; p; p = p->next) { ! if (p->target == i) ! { ! char smallbuffer[20]; ! p->number = note_number++; ! sprintf (smallbuffer, " (see note %d)", p->number); ! strcat (buffer, smallbuffer); ! break; ! } } + strcat (buffer, ", "); } } ! { ! char *ch = strchr (buffer, 0) - 2; ! if (*ch == ',') ! *ch = 0; ! else ! strcpy (buffer, "Unknown."); ! } ! strcat (buffer, "\n\n"); add(buffer); ! if (note_number > 1) ! { ! add("@noindent\n"); ! add("Notes:\n"); ! add("\n"); ! add("@enumerate\n"); ! ! for (int i = 1; i < note_number; i++) ! { ! add("@item\n"); ! for (PortNote *p = port_notes; p; p = p->next) ! if (p->number == i) ! add(p->note); ! } ! ! add("@end enumerate\n"); ! } /* Now free the portability notes */ while (port_notes) { *************** *** 263,283 **** 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 { --- 305,334 ---- free (p->note); delete p; } ! last_port_note = NULL; } void Node::process(char *line) { ! if (line[0] == '@') { ! if ((strncmp (line, "@portability", 12) == 0) && isspace (line[12])) ! { ! read_portability(line+13); ! write_portability(); ! return; ! } ! else if ((strncmp (line, "@port-note", 10) == 0) && isspace (line[10])) ! { ! read_portability_note(line+11); ! return; ! } } ! ! /* If `last_port_note' is not NULL, we're in the middle of a note */ ! if (last_port_note) { ! extend_portability_note(line); } else { -- george DOT foot AT merton DOT oxford DOT ac DOT uk