/* tournd.c Accepts as input a TOUR outline file which has been processed by ROFFTOUR. Produces as output a file which has had the leading index numbers removed. turns 1. xxxxxxxxxxx into 1. xxxxxxxxxxx 1.1 xxxxxxxxxx 1 xxxxxxxxxx 2. xxxxxxxxxxx 2. xxxxxxxxxxx 2.1 xxxxxxxxxx 1 xxxxxxxxxx 2.1.1 xxxxxxxx 1 xxxxxxxx 2.1.2 xxxxxxxx 2 xxxxxxxx Syntax: tournd file.nam Produces: file.ind If blank_line is TRUE, blank lines will appear in the output file. Richard Webb 74005,1265 */ #include char in_buf[BUFSIZ], out_buf[BUFSIZ]; char in_name[18], out_name[18]; char line[MAXLINE]; main(argc, argv) int argc; char *argv[]; { char c0, c1, c2; char blank_line; int i; blank_line = TRUE; /* if TRUE, include blank lines in output file */ if (argc != 2) { printf("Removes leading numbers from TOUR outlines.\n"); printf("Usage: tournd file.nam\n"); exit(); } strcpy(in_name,argv[1]); if (fopen(in_name,in_buf) == ERROR) { printf("\n ERROR on input file: %s\n",errmsg(errno())); exit(); } namefile(in_name,out_name,"IND"); if (fcreat(out_name,out_buf) == ERROR) { printf("\n ERROR on output file: %s\n", errmsg(errno())); exit(); } while ( fgets(line,in_buf) ) { i = 0; c0 = line[0]; while ( ( c0 != ' ') && c0 ) { c1 = line[i+1]; c2 = line[i+2]; if ( isdigit(c1) || ( (c1 == '.') && isdigit(c2) ) ) line[i] = ' '; c0 = line[++i]; } if (blank_line) fputs(line, out_buf); else if (line[0] != '\n') fputs(line, out_buf); } putc(CPMEOF,out_buf); if ( fclose(out_buf) == ERROR) { printf("\n ERROR while closing output file: %s\n",errmsg(errno())); exit(); } } namefile(in_name, out_name, ext) char *in_name, *out_name, *ext; { int pos; char name_buf[18]; strcpy(name_buf,in_name); if ((pos = index(name_buf,".")) == 0) pos = strlen(name_buf); name_buf[pos] = '\0'; strcat(name_buf,"."); strcat(name_buf,ext); strcpy(out_name,name_buf); }