home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 15 / CD_ASCQ_15_070894.iso / vrac / extr_net.zip / EXTR_NET.C next >
C/C++ Source or Header  |  1994-05-29  |  23KB  |  723 lines

  1. #define TITLE   "EXTR_NET"                /*  Program Name    */
  2. #define DATES   "1988-94"                 /*  Copyright Date  */
  3. #define VERSION "2.20"                    /*  Version Number  */
  4. /*
  5.  
  6.                                   EXTR_NET
  7.                                 Version 2.20
  8.             Copyright (c) Bob Swift, 1988-94.  All Rights Reserved.
  9.                    Compiled with the Borland C++ compiler.
  10.  
  11.    This program is designed to read an input nodelist file and extract
  12.    selected Networks, Regions and/or Zones.  The extracted portions of
  13.    the nodelist are stored in a file specified on the command line.
  14.  
  15.    The format for using this program is as follows:
  16.  
  17.  
  18.         EXTR_NET <srcfile> <destfile> [I] <net1> <net2>...<net20>
  19.  
  20.    where <srcfile>    is the name of the nodelist file to be read
  21.          <destfile>   is the name of the output file created
  22.          [I]          optionally include all Zone entries
  23.          <net..>      are the numbers of the Net/Region/Zones to be extracted
  24.                       and may include zone specifiers for Nets and Regions
  25.                       (the program is presently set to handle 20 numbers).
  26.                       These numbers may be preceded by a N, R or Z in order
  27.                       to extract the entire Net, Region or Zone.  Examples
  28.                       are: 123 N342 n2:201 r17 Z1
  29.  
  30.  
  31.    The nodelist may be specified with a full drive and path.  The destination
  32.    file must not have a drive or path specified.  It will be output to the
  33.    current directory.
  34.  
  35.    The program will display a VERY brief set of instructions if it is called
  36.    without any arguments or if it encounters an error.  The following is a
  37.    list of the error codes returned by the program:
  38.  
  39.                   0 - No errors.  Normal termination.
  40.                   1 - Bad or missing command line argument.
  41.                   2 - Unable to open the input file.
  42.                   3 - Unable to open the output file.
  43.                   4 - Problem writing to output file.
  44.                   5 - Problem closing input file.
  45.                   6 - Problem closing output file.
  46.                   7 - Unable to open configuration file.
  47.                   8 - Unable to create backup file.
  48.  
  49.    When an error is encountered, the program will exit immediately and will
  50.    attempt to properly close all files.
  51.  
  52.    Although I have chosen to retain all rights to this program, you are free
  53.    to use it under the following conditions:
  54.  
  55.             - You realize that there is NO Warrantee of any sort.
  56.               It was tested pretty thoroughly here before release
  57.               but who knows what bugs may be lurking within.
  58.  
  59.             - You will not modify the code and release a new version
  60.               of the program.  I welcome suggestions for improvement
  61.               (especially when accompanied by code) but I make no
  62.               guarantee of future releases.
  63.  
  64.             - If you find the program useful, I ask that you do
  65.               something to brighten somebody else's day.  Just
  66.               exactly what, I will leave up to you.
  67.  
  68.  
  69.    You may freely distribute this program provided that you distribute only
  70.    the complete archive which includes the EXTR_NET.EXE, EXTR_NET.C and
  71.    EXTR_NET.DOC.  In addition, You MUST NOT charge for the program nor can
  72.    you charge a copy fee over $4.00 (including the price of the diskette).
  73.  
  74.  
  75.                                                    Bob Swift (1:342/5)
  76.  
  77.  
  78. */
  79.  
  80. #include <stdio.h>
  81. #include <string.h>
  82. #include <time.h>
  83. #include <mem.h>
  84.  
  85.     /* the CRC polynomial. This is used by XMODEM (almost CCITT).
  86.      * If you change P, you must change crctab[]'s initial value to what is
  87.      * printed by initcrctab()
  88.      */
  89. #define   P    0x1021
  90.  
  91.     /* number of bits in CRC: don't change it. */
  92. #define W 16
  93.  
  94.     /* this the number of bits per char: don't change it. */
  95. #define B 8
  96.  
  97. static unsigned short crctab[1<<B] = { /* as calculated by initcrctab() */
  98.     0x0000,  0x1021,  0x2042,  0x3063,  0x4084,  0x50a5,  0x60c6,  0x70e7,
  99.     0x8108,  0x9129,  0xa14a,  0xb16b,  0xc18c,  0xd1ad,  0xe1ce,  0xf1ef,
  100.     0x1231,  0x0210,  0x3273,  0x2252,  0x52b5,  0x4294,  0x72f7,  0x62d6,
  101.     0x9339,  0x8318,  0xb37b,  0xa35a,  0xd3bd,  0xc39c,  0xf3ff,  0xe3de,
  102.     0x2462,  0x3443,  0x0420,  0x1401,  0x64e6,  0x74c7,  0x44a4,  0x5485,
  103.     0xa56a,  0xb54b,  0x8528,  0x9509,  0xe5ee,  0xf5cf,  0xc5ac,  0xd58d,
  104.     0x3653,  0x2672,  0x1611,  0x0630,  0x76d7,  0x66f6,  0x5695,  0x46b4,
  105.     0xb75b,  0xa77a,  0x9719,  0x8738,  0xf7df,  0xe7fe,  0xd79d,  0xc7bc,
  106.     0x48c4,  0x58e5,  0x6886,  0x78a7,  0x0840,  0x1861,  0x2802,  0x3823,
  107.     0xc9cc,  0xd9ed,  0xe98e,  0xf9af,  0x8948,  0x9969,  0xa90a,  0xb92b,
  108.     0x5af5,  0x4ad4,  0x7ab7,  0x6a96,  0x1a71,  0x0a50,  0x3a33,  0x2a12,
  109.     0xdbfd,  0xcbdc,  0xfbbf,  0xeb9e,  0x9b79,  0x8b58,  0xbb3b,  0xab1a,
  110.     0x6ca6,  0x7c87,  0x4ce4,  0x5cc5,  0x2c22,  0x3c03,  0x0c60,  0x1c41,
  111.     0xedae,  0xfd8f,  0xcdec,  0xddcd,  0xad2a,  0xbd0b,  0x8d68,  0x9d49,
  112.     0x7e97,  0x6eb6,  0x5ed5,  0x4ef4,  0x3e13,  0x2e32,  0x1e51,  0x0e70,
  113.     0xff9f,  0xefbe,  0xdfdd,  0xcffc,  0xbf1b,  0xaf3a,  0x9f59,  0x8f78,
  114.     0x9188,  0x81a9,  0xb1ca,  0xa1eb,  0xd10c,  0xc12d,  0xf14e,  0xe16f,
  115.     0x1080,  0x00a1,  0x30c2,  0x20e3,  0x5004,  0x4025,  0x7046,  0x6067,
  116.     0x83b9,  0x9398,  0xa3fb,  0xb3da,  0xc33d,  0xd31c,  0xe37f,  0xf35e,
  117.     0x02b1,  0x1290,  0x22f3,  0x32d2,  0x4235,  0x5214,  0x6277,  0x7256,
  118.     0xb5ea,  0xa5cb,  0x95a8,  0x8589,  0xf56e,  0xe54f,  0xd52c,  0xc50d,
  119.     0x34e2,  0x24c3,  0x14a0,  0x0481,  0x7466,  0x6447,  0x5424,  0x4405,
  120.     0xa7db,  0xb7fa,  0x8799,  0x97b8,  0xe75f,  0xf77e,  0xc71d,  0xd73c,
  121.     0x26d3,  0x36f2,  0x0691,  0x16b0,  0x6657,  0x7676,  0x4615,  0x5634,
  122.     0xd94c,  0xc96d,  0xf90e,  0xe92f,  0x99c8,  0x89e9,  0xb98a,  0xa9ab,
  123.     0x5844,  0x4865,  0x7806,  0x6827,  0x18c0,  0x08e1,  0x3882,  0x28a3,
  124.     0xcb7d,  0xdb5c,  0xeb3f,  0xfb1e,  0x8bf9,  0x9bd8,  0xabbb,  0xbb9a,
  125.     0x4a75,  0x5a54,  0x6a37,  0x7a16,  0x0af1,  0x1ad0,  0x2ab3,  0x3a92,
  126.     0xfd2e,  0xed0f,  0xdd6c,  0xcd4d,  0xbdaa,  0xad8b,  0x9de8,  0x8dc9,
  127.     0x7c26,  0x6c07,  0x5c64,  0x4c45,  0x3ca2,  0x2c83,  0x1ce0,  0x0cc1,
  128.     0xef1f,  0xff3e,  0xcf5d,  0xdf7c,  0xaf9b,  0xbfba,  0x8fd9,  0x9ff8,
  129.     0x6e17,  0x7e36,  0x4e55,  0x5e74,  0x2e93,  0x3eb2,  0x0ed1,  0x1ef0
  130.     };
  131.  
  132. int cfputs(char *s,FILE *stream);
  133. unsigned short updcrc(unsigned short icrc,unsigned char *icp,unsigned int icnt);
  134. void helpscrn(int ernum);
  135. void add_period(char filename[]);
  136. void build_bak_name(char filename[]);
  137. int is_in_dir(char *filename);
  138. int del_backup(char *filename);
  139. int linetest(char *linetst1, char *inline);
  140. int make_backup(char *srcfile, char *destfile);
  141. char version[] = {VERSION};  /* Current Version Number */
  142. char title[] = {TITLE};
  143. char dates[] = {DATES};
  144. unsigned short crc;
  145.  
  146. /*******************************************************************/
  147.  
  148. void main(int argc, char *argv[])
  149. {
  150.  
  151. FILE *infile,*outfile;
  152. char flnames[3][40];
  153. char inline[358];
  154. char linetst1[20];
  155. char lintest[21][20];
  156. char zontest[21][10];
  157. char linshow[21][40];
  158. int  lineflag[21];
  159. char semi[20];
  160. char temp[20];
  161. char spaces[80];
  162. char curzone[10];
  163. time_t t;
  164. fpos_t filepos;
  165. char *pntr;
  166. int i,j;
  167. int sub1;
  168. int count;
  169. int flag;
  170. int zoneflag;
  171.  
  172. memset(spaces,' ',79);
  173. spaces[79] = '\0';
  174. strcpy(curzone,"0");
  175. zoneflag = 0;
  176. t = time(NULL);
  177.  
  178. printf("\n\n%s Version %s\n",title,version);
  179. printf("Copyright (c) Bob Swift, %s.  All Rights Reserved.\n",dates);
  180.  
  181. if (argc < 4 || argc > 14) helpscrn(1);
  182. strcpy(flnames[1],strupr(argv[1]));             /*  Input File  */
  183. strcpy(flnames[2],strupr(argv[2]));             /* Output File  */
  184. strcpy(flnames[3],strupr(argv[2]));             /* Backup File  */
  185.  
  186. if (is_in_dir(flnames[2]) == 1)
  187.     helpscrn(7);
  188.  
  189. add_period(flnames[3]);
  190. build_bak_name(flnames[3]);
  191.  
  192. if (del_backup(flnames[3]) == 1)
  193.     helpscrn(8);
  194.  
  195. /*  Exit if output file has an extension of BAK  */
  196. if (strcmp(flnames[2],flnames[3])==0)
  197.    helpscrn(8);
  198.  
  199. if (make_backup(flnames[2],flnames[3]) == 1)
  200.     helpscrn(8);
  201.  
  202. infile=fopen(flnames[1],"rt");
  203. if (infile == NULL)
  204.     helpscrn(2);
  205.  
  206. if ((outfile=fopen(flnames[2],"wt")) == NULL)
  207.     helpscrn(3);
  208.  
  209. count = 3;
  210. sub1 = 0;
  211. while (count < argc)      /*  Set Up Search Strings  */
  212.   {
  213.     strcpy(semi,argv[count]);
  214.     switch(semi[0])
  215.       {
  216.       case 'i': ;
  217.       case 'I': sub1++;
  218.                 strcpy(lintest[sub1],"I,");
  219.                 strcpy(zontest[sub1],"0");
  220.                 strcpy(linshow[sub1],"Include all ZONE entries.");
  221.                 lineflag[sub1] = 'I';
  222.                 zoneflag = 1;
  223.                 break;
  224.       case 'n': ;
  225.       case 'N': sub1++;
  226.                 strcpy(lintest[sub1],"Host,");
  227.                 strcpy(zontest[sub1],"0");
  228.                 strcpy(linshow[sub1],"Net ");
  229.                 lineflag[sub1] = 'N';
  230.                 i = 0;
  231.                 j = 1;
  232.                 strcpy(temp,"0");
  233.                 while (semi[j] != '\0')
  234.                   {
  235.                   temp[i] = semi[j];
  236.                   i++;
  237.                   j++;
  238.                   temp[i] = '\0';
  239.                   if (semi[j] == ':')
  240.                     {
  241.                     j++;
  242.                     strcpy(zontest[sub1],temp);
  243.                     i = 0;
  244.                     strcpy(temp,"0");
  245.                     }
  246.                   }
  247.                 strcat(lintest[sub1],temp);
  248.                 strcat(lintest[sub1],",");
  249.                 strcat(linshow[sub1],temp);
  250.                 if (zontest[sub1][0] != '0')
  251.                   {
  252.                   strcat(linshow[sub1],"  (Zone ");
  253.                   strcat(linshow[sub1],zontest[sub1]);
  254.                   strcat(linshow[sub1],")");
  255.                   }
  256.                 break;
  257.       case 'r': ;
  258.       case 'R': sub1++;
  259.                 strcpy(lintest[sub1],"Region,");
  260.                 strcpy(zontest[sub1],"0");
  261.                 strcpy(linshow[sub1],"Region ");
  262.                 lineflag[sub1] = 'R';
  263.                 i = 0;
  264.                 j = 1;
  265.                 strcpy(temp,"0");
  266.                 while (semi[j] != '\0')
  267.                   {
  268.                   temp[i] = semi[j];
  269.                   i++;
  270.                   j++;
  271.                   temp[i] = '\0';
  272.                   if (semi[j] == ':')
  273.                     {
  274.                     j++;
  275.                     strcpy(zontest[sub1],temp);
  276.                     i = 0;
  277.                     strcpy(temp,"0");
  278.                     }
  279.                   }
  280.                 strcat(lintest[sub1],temp);
  281.                 strcat(lintest[sub1],",");
  282.                 strcat(linshow[sub1],temp);
  283.                 if (zontest[sub1][0] != '0')
  284.                   {
  285.                   strcat(linshow[sub1],"  (Zone ");
  286.                   strcat(linshow[sub1],zontest[sub1]);
  287.                   strcat(linshow[sub1],")");
  288.                   }
  289.                 break;
  290.       case 'z': ;
  291.       case 'Z': sub1++;
  292.                 strcpy(lintest[sub1],"Zone,");
  293.                 strcpy(zontest[sub1],"0");
  294.                 strcpy(linshow[sub1],"Zone ");
  295.                 lineflag[sub1] = 'Z';
  296.                 i = 5;
  297.                 j = 1;
  298.                 strcpy(temp,"0");
  299.                 while (semi[j] != '\0')
  300.                   {
  301.                   lintest[sub1][i] = semi[j];
  302.                   linshow[sub1][i] = semi[j];
  303.                   i++;
  304.                   j++;
  305.                   }
  306.                 lintest[sub1][i] = '\0';
  307.                 linshow[sub1][i] = '\0';
  308.                 strcat(lintest[sub1],",");
  309.                 break;
  310.       default:
  311.           {
  312.             sub1++;
  313.             lineflag[sub1] = 'A';
  314.             strcpy(lintest[sub1],"Zone,");
  315.                 strcpy(zontest[sub1],"0");
  316.             strcpy(linshow[sub1],"Zone ");
  317.                 i = 0;
  318.                 j = 0;
  319.                 strcpy(temp,"0");
  320.                 while (semi[j] != '\0')
  321.                   {
  322.                   temp[i] = semi[j];
  323.                   i++;
  324.                   j++;
  325.                   temp[i] = '\0';
  326.                   if (semi[j] == ':')
  327.                     {
  328.                     j++;
  329.                     strcpy(zontest[sub1],temp);
  330.                     i = 0;
  331.                     strcpy(temp,"0");
  332.                     }
  333.                   }
  334.                 strcat(lintest[sub1],temp);
  335.                 strcat(lintest[sub1],",");
  336.                 strcat(linshow[sub1],temp);
  337.             sub1++;
  338.             lineflag[sub1] = 'A';
  339.             strcpy(lintest[sub1],"Region,");
  340.                 strcpy(zontest[sub1],zontest[sub1-1]);
  341.                 strcpy(zontest[sub1-1],"0");
  342.             strcpy(linshow[sub1],"Region ");
  343.                 strcat(lintest[sub1],temp);
  344.                 strcat(lintest[sub1],",");
  345.                 strcat(linshow[sub1],temp);
  346.                 if (zontest[sub1][0] != '0')
  347.                   {
  348.                   strcat(linshow[sub1],"  (Zone ");
  349.                   strcat(linshow[sub1],zontest[sub1]);
  350.                   strcat(linshow[sub1],")");
  351.                   }
  352.             sub1++;
  353.             lineflag[sub1] = 'A';
  354.             strcpy(lintest[sub1],"Host,");
  355.                 strcpy(zontest[sub1],zontest[sub1-1]);
  356.             strcpy(linshow[sub1],"Net ");
  357.                 strcat(lintest[sub1],temp);
  358.                 strcat(lintest[sub1],",");
  359.                 strcat(linshow[sub1],temp);
  360.                 if (zontest[sub1][0] != '0')
  361.                   {
  362.                   strcat(linshow[sub1],"  (Zone ");
  363.                   strcat(linshow[sub1],zontest[sub1]);
  364.                   strcat(linshow[sub1],")");
  365.                   }
  366.           }
  367.       }
  368.   count++;
  369.   }
  370. printf("Extracting:   ");    /*  Echo Input To User  */
  371. for (count=1;count<=sub1;count++)
  372. {
  373.   printf("%s\n              ",linshow[count]);
  374. }
  375. printf("\n");
  376.  
  377. /*  Get first line of source nodelist file  */
  378. /*  and print header to output file.        */
  379. if (fgets(inline,256,infile) == NULL)
  380.   {
  381.   if (fputs(";A Extracted Nodelist Segment : 00000\n",outfile) == EOF) helpscrn(4);
  382.   }
  383. else
  384.   {
  385.   if (fputs(";A Extracted ",outfile) == EOF) helpscrn(4);
  386.   if (fputs(inline+3,outfile) == EOF) helpscrn(4);
  387.   }
  388. crc = 0;
  389. if (fgetpos(outfile,&filepos) != 0) helpscrn(4);
  390. filepos = filepos - 7L;
  391.  
  392. /*  Print extraction info to output file  */
  393. if (cfputs(";A \n;A Extracted with ",outfile) == EOF) helpscrn(4);
  394. if (cfputs(title,outfile) == EOF) helpscrn(4);
  395. if (cfputs(" Version ",outfile) == EOF) helpscrn(4);
  396. if (cfputs(version,outfile) == EOF) helpscrn(4);
  397. if (cfputs("\n;A ",outfile) == EOF) helpscrn(4);
  398. if (cfputs("Copyright (c) Bob Swift, ",outfile) == EOF) helpscrn(4);
  399. if (cfputs(dates,outfile) == EOF) helpscrn(4);
  400. if (cfputs(".  All Rights Reserved.",outfile) == EOF) helpscrn(4);
  401. if (cfputs("\n;A \n;A Extracted from ",outfile) == EOF) helpscrn(4);
  402. if (cfputs(flnames[1],outfile) == EOF) helpscrn(4);
  403. if (cfputs(" on ",outfile) == EOF) helpscrn(4);
  404. if (cfputs(ctime(&t),outfile) == EOF) helpscrn(4);
  405. if (cfputs(";A \n;A Extracting:     ",outfile) == EOF) helpscrn(4);
  406. if (cfputs(linshow[1],outfile) == EOF) helpscrn(4);
  407. for (count=2;count<=sub1;count++)
  408.   {
  409.   if(cfputs("\n;A                 ",outfile) == EOF) helpscrn(4);
  410.   if(cfputs(linshow[count],outfile) == EOF) helpscrn(4);
  411.   }
  412. if (cfputs("\n;A \n;\n",outfile) == EOF) helpscrn(4);
  413.  
  414. /*  Initialize  */
  415. count = sub1;
  416. flag = 1;
  417. j = 0;
  418.  
  419. /*  Get line from source file  */
  420. while (fgets(inline,256,infile) != NULL)
  421.   {
  422.   if (inline[0] == 'Z')
  423.     {
  424.       i = 0;
  425.       for (sub1=5;(inline[sub1] != ',') && (sub1 < strlen(inline));sub1++)
  426.         {
  427.           curzone[i] = inline[sub1];
  428.           i++;
  429.           curzone[i] = '\0';
  430.         }
  431.     }
  432.     strcpy(semi,";");
  433.     i = linetest(semi,inline);
  434.     strcpy(semi,";\n");
  435.     if ((linetest(semi,inline) == 1 && flag == 0) || i == 0)
  436.     {
  437.  
  438.       if (flag == 0)
  439.       {
  440.         strcpy(semi,"Host");
  441.         i = linetest(semi,inline);
  442.         if (i == 1 && (j == 'N' || j == 'A')) flag = 1;
  443.         if (flag == 1) if (cfputs(";\n",outfile) == EOF) helpscrn(4);
  444.       }
  445.  
  446.       if (flag == 0)
  447.       {
  448.         strcpy(semi,"Region");
  449.         i = linetest(semi,inline);
  450.         if (i == 1 && (j == 'N' || j == 'R' || j == 'A')) flag = 1;
  451.         if (flag == 1) if (cfputs(";\n",outfile) == EOF) helpscrn(4);
  452.       }
  453.  
  454.  
  455.       if (flag == 0)
  456.       {
  457.         strcpy(semi,"Zone");
  458.         flag = linetest(semi,inline);
  459.         if (flag == 1) if (cfputs(";\n",outfile) == EOF) helpscrn(4);
  460.       }
  461.  
  462.       if (flag == 0)
  463.       {
  464.         if (cfputs(inline,outfile) == EOF)
  465.            helpscrn(4);
  466.       }
  467.  
  468.       if (flag == 1)
  469.       {
  470.  
  471.         /*  Cycle through the search patterns  */
  472.         for (sub1=1;sub1<=count && linetest(lintest[sub1],inline)==0;sub1++)
  473.         {
  474.             /*  Null Line  */
  475.         }
  476.  
  477.         if (sub1 <= count) i = linetest(curzone,zontest[sub1]);
  478.         if ((sub1 <= count) && ((zontest[sub1][0] == '0') || (i == 1)))
  479.         {
  480.           if (cfputs(inline,outfile) == EOF)
  481.              helpscrn(4);
  482.           flag = 0;
  483.           j = lineflag[sub1];
  484.         }
  485.       }
  486.  
  487.       if (flag == 1)
  488.       {
  489.  
  490.         /*  Check if Zone and print if all Zones selected  */
  491.         strcpy(semi,"Zone");
  492.         if (linetest(semi,inline) == 1)
  493.         {
  494.           i = 0;
  495.           for (sub1=1;sub1<=count;sub1++)
  496.           {
  497.             if (linetest(zontest[sub1],curzone) == 1) i = 1;
  498.           }
  499.           if ((i == 1) || (zoneflag == 1))
  500.           {
  501.             if (cfputs(inline,outfile) == EOF) helpscrn(4);
  502.             if (cfputs(";\n",outfile) == EOF) helpscrn(4);
  503.           }
  504.         }
  505.  
  506.       }
  507.     }
  508.   if (inline[0] == 'Z' || inline[0] == 'R' || (inline[0] == 'H' && inline[2] == 's'))
  509.     {
  510.       inline[strlen(inline)-1] = '\0';
  511.       i = 0;
  512.       for (sub1=0;sub1<=strlen(inline) && i<3;sub1++)
  513.         {
  514.           if (inline[sub1] == ',')
  515.             {
  516.               i++;
  517.               if (i >= 3)
  518.                 inline[sub1] = '\0';
  519.               if (i == 1)
  520.                 inline[sub1] = ' ';
  521.             }
  522.           if (inline[sub1] == '_')
  523.             inline[sub1] = ' ';
  524.         }
  525.       strcat(inline,spaces);
  526.       inline[79] = '\0';
  527.       printf("%s",inline);
  528.       if (inline[0] == 'Z')
  529.         printf("\n");
  530.       else
  531.         printf("\r");
  532.     }
  533.   }
  534. if (cfputs(";S End of extracted file.\n;S \n",outfile) == EOF) helpscrn(4);
  535.  
  536. /*  Close the source file  */
  537. if (fclose(infile) != 0)
  538.    helpscrn(5);
  539.  
  540. /*  Update the CRC value in the output file  */
  541. if (fsetpos(outfile,&filepos) != 0) helpscrn(4);
  542. fprintf(outfile,"%05u",crc);
  543.  
  544. /*  Close the destination file  */
  545. if (fclose(outfile) != 0)
  546.    helpscrn(6);
  547.  
  548. /*  Thank the user and exit gracefully  */
  549. printf("%s",spaces);
  550. printf("\nExtraction complete.  Thank-you for using %s.\n\n",title);
  551. exit(0);
  552. }
  553.  
  554.  
  555. /*******************************************************************/
  556.  
  557. int cfputs(char *s,FILE *stream)
  558. {
  559. char string[256];
  560. int i,j;
  561.  
  562. i = 0;
  563. j = 0;
  564. string[0] = '\0';
  565. while (s[j] != '\0')
  566.   {
  567.   if (s[j] == '\n')
  568.     {
  569.     string[i] = 13;
  570.     i++;
  571.     string[i] = 10;
  572.     i++;
  573.     string[i] = '\0';
  574.     }
  575.   else
  576.     {
  577.     string[i] = s[j];
  578.     i++;
  579.     string[i] = '\0';
  580.     }
  581.   j++;
  582. }
  583. crc = updcrc(crc,string,i);
  584. return (fputs(s,stream));
  585. }
  586.  
  587.  
  588. /*******************************************************************/
  589.  
  590. unsigned short updcrc(unsigned short icrc,unsigned char *icp,unsigned int icnt)
  591. {
  592. register unsigned short crc1 = icrc;
  593. register unsigned char *cp = icp;
  594. register unsigned int cnt = icnt;
  595.  
  596. while (cnt--)  crc1 = (crc1<<B) ^ crctab[(crc1>>(W-B)) ^ *cp++];
  597.  
  598. return(crc1);
  599. }
  600.  
  601.  
  602. /*******************************************************************/
  603.  
  604.  
  605. int is_in_dir(char *filename)
  606. /*  Check if input file in current directory  */
  607. {
  608. if (strchr(filename,'\\')!=NULL || strchr(filename,':')!=NULL)
  609.    return(1);
  610.  else
  611.    return(0);
  612. }
  613.  
  614.  
  615.  
  616. void add_period(char filename[])
  617. /*  If input file has no extension finish it with a period  */
  618. {
  619. if (strchr(filename,'.')==NULL)
  620.    strcat(filename,".");
  621. }
  622.  
  623. void build_bak_name(char filename[])
  624. /*  Build file name for backup file  */
  625. {
  626. int flag;
  627. for (flag=0;filename[flag]!='.';flag++)
  628.    {
  629.    /*  NULL Line  */
  630.    }
  631. filename[flag] = '\0';
  632. strcat(filename,".BAK");
  633. }
  634.  
  635.  
  636. int del_backup(char *filename)
  637. /*  Check for existing backup file and delete  */
  638. {
  639. FILE *tempfile;
  640. tempfile=fopen(filename,"r");
  641. fclose(tempfile);
  642. if (tempfile != NULL)
  643.    {
  644.    if (unlink(filename) != 0)
  645.       return(1);
  646.    }
  647. return(0);
  648. }
  649.  
  650.  
  651. int make_backup(char *srcfile, char *destfile)
  652. /*  Rename source file to destination file  */
  653. {
  654. FILE *tempfile;
  655. tempfile=fopen(srcfile,"r");
  656. fclose(tempfile);
  657. if (tempfile != NULL)
  658.    {
  659.    if (rename(srcfile,destfile) != 0)
  660.       return(1);
  661.    }
  662. return(0);
  663. }
  664.  
  665.  
  666. int linetest(char *linetst1, char *inline)
  667. /*  This is the routine that actually checks for a match  */
  668. {
  669. int j;
  670. for ( j=0; linetst1[j] == inline[j]; j++ )
  671.     if (linetst1[j+1] == '\0') return(1);
  672. return(0);
  673. }
  674.  
  675.  
  676. void helpscrn(int ernum)
  677. /*  Here are the error messages and VERY brief instructions  */
  678. {
  679. cprintf("\n");
  680. switch (ernum) {
  681.  
  682. case  1 : printf("     **  Bad or missing command line argument  **\n\n");
  683.           break;
  684.  
  685. case  2 : printf("     **  Unable to open input file  **\n\n");
  686.           break;
  687.  
  688. case  3 : printf("     **  Unable to open output file  **\n\n");
  689.           break;
  690.  
  691. case  4 : printf("     **  Problem writing to output file  **\n\n");
  692.           break;
  693.  
  694. case  5 : printf("     **  Problem closing input file  **\n\n");
  695.           break;
  696.  
  697. case  6 : printf("     **  Problem closing output file  **\n\n");
  698.           break;
  699.  
  700. case  7 : printf("     **  Output file not in current directory  **\n\n");
  701.           break;
  702.  
  703. case  8 : printf("     **  Unable to create backup file  **\n\n");
  704.           break;
  705.     }
  706. printf("This program is designed to read an input nodelist file and extract");
  707. printf("\nselected Networks, Regions and/or Zones.  The extracted portions ");
  708. printf("of\nthe nodelist are stored in a file specified on the command line");
  709. printf(".\n\nThe format for using this program is as follows:\n\n");
  710. printf("     EXTR_NET <srcfile> <destfile> [I] <net1> <net2>...<net20>\n\n");
  711. printf("where <srcfile>    is the name of the nodelist file to be read\n");
  712. printf("      <destfile>   is the name of the output file created\n");
  713. printf("      [I]          optionally include all Zone entries\n");
  714. printf("      <net..>      are the numbers of the Net/Region/Zones to be extracted\n");
  715. printf("                   and may include zone specifiers for Nets and Regions\n");
  716. printf("                   (the program is presently set to handle 20 numbers).\n");
  717. printf("                   These numbers may be preceded by a N, R or Z in order\n");
  718. printf("                   to extract the entire Net, Region or Zone.  Examples\n");
  719. printf("                   are: 123 N342 n2:201 r17 Z1\n");
  720. exit(ernum);
  721. }
  722.  
  723.