[net.news] mkpath update

mcm@ncsu.UUCP (07/07/83)

Well, it's time for another update to mkpath.  The 'fixes' included
here are not critical; but they might be nice to have.  The first
one fixes a problem with the input data.  mkpath can get confused
if the "News:" or "Mail:" fields have tabs or blanks, but no site names.
I am enclosing a new getcon() routine that fixes the problem.

The second 'fix' adds the starting site to the output.  It's  not necessary,
but some people think it's nice to have.

I honestly don't know how it happened, but there are some spelling errors in
the nmail manual page.  Please change all occurences of 'explanation point'
to 'exclamation point'.

Thanks to Alan Silverstein for the pointers to the problems.

	Here is the replacement getcon() routine.......

#include <stdio.h>
#include <ctype.h>
extern FILE *map;

/*
 * getcon() grabs a site name from the "News:" field or the "Mail:"
 * field.  If the buffer passed is empty, it reads from the map file.
 * if it reads a "Name:" field, it returns false.  If it reads a line
 * with a colon in it and the passed flag is false, it returns false.
 * It reads until there is something on the line that is not a blank,
 * tab, comma, or a newline.  Once there is something useful in the
 * buffer, it removes the first "word" terminated by a blank, tab, comma,
 * or newline and returns true.
 */

getcon(buf, name, flag)
char *buf;
register char *name;
int flag;
{
	register char *cp0, *cp1;
	char *fgets(), *wrdpos();
	int strlen();

	cp0 = buf;
/*
 * if 'flag' is set, read until we find a "Name:" field, "News:"
 * field, or a "Mail:" field.  We can ignore anything else.
 */
	while((flag) && (fgets(buf, BUFSIZ, map) != NULL)) {
		if (upcase(buf)) {
			if (strncmp(buf, "NAME:", 5) == 0) {
/*
 * We've gone too far if we find a "Name:" field, so we'll have
 * to back up.
 */
				fseek(map, (long)(-strlen(buf)), 1);
				return(0);
				}

			else if (strncmp(buf, "NEWS:", 5) == 0) {
				flag = 0;
				cp0 = &buf[5];
				}
			else if (strncmp(buf, "MAIL:", 5) == 0) {
				flag = 0;
				cp0 = &buf[5];
				}
			}
		}

	cp1 = wrdpos(cp0);
/*
 * read until there is some useful data in buf
 */
	while((cp1==NULL)&&((cp0=fgets(buf,BUFSIZ,map))!=NULL)) {
/*
 * if there is a colon on this line, see if its a "Name:" field, "News:"
 * field, or a "Mail:" field.
 */
		if (upcase(cp0)) {
			if (strncmp(cp0, "NAME:", 5) == 0) {
				fseek(map, (long)(-strlen(buf)), 1);
				return(0);
				}
			else if (strncmp(cp0, "NEWS:", 5) == 0)
				cp0 += 5;
			else if (strncmp(cp0, "MAIL:", 5) == 0)
				cp0 += 5;
			else return(0);
			}
/*
 * leave if the line is not a continuation line (first char not blank or tab)
 */
		else if ((*cp0 != '\t') && (*cp0 != ' '))
			return(0);

		cp1 = wrdpos(cp0);
		}
	if (cp0 == NULL)
		return(0);
/*
 * now that there is some data, we copy the first "word" into name, and
 * remove the "word" from buf, returning true.
 */
	while((*cp1) && (!isspace(*cp1)) && (*cp1 != ','))
		*name++ = *cp1++;
	*name = '\0';
	cp1 = wrdpos(cp1);
	if (cp1 == NULL)
		*buf = '\0';
	else strcpy(buf, cp1);
	return(1);
	}

*************************************************************************
	Here is a 'diff -c' of the changes for adding the current site to
	the output

*** mkpath.c	Tue Jun  7 15:08:09 1983
--- mkpath.new.c	Thu Jul  7 11:16:54 1983
***************
*** 40,45
   * Version 3.5	5/3/83		Changed to use Mark's new format.  Also
   *				forced continuation lines to start with
   *				a blank or a tab.
   *
   * Written by Mike Mitchell	decvax!duke!mcnc!ncsu!mcm
   *

--- 40,49 -----
   * Version 3.5	5/3/83		Changed to use Mark's new format.  Also
   *				forced continuation lines to start with
   *				a blank or a tab.
+  * Version 3.6  5/15/83		changed the getcon() routine so it handles
+  *				lines like 'News:(tab)\n' better.
+  *				added code so that the starting site is
+  *				listed in the database.
   *
   * Written by Mike Mitchell	decvax!duke!mcnc!ncsu!mcm
   *
***************
*** 322,327
   * now that paths has finished, output the routing information.
   * All we have to do is traverse the "route" pointers!
   */
  	curptr = Begsite;
  	while(curptr != NULL) {
  		if (curptr->route != NULL) {

--- 326,332 -----
   * now that paths has finished, output the routing information.
   * All we have to do is traverse the "route" pointers!
   */
+ 	printf("%s\t%%s\n", stnam);
  	curptr = Begsite;
  	while(curptr != NULL) {
  		if (curptr->route != NULL) {
***************

	Mike Mitchell
	duke!mcnc!ncsu!mcm