home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / GENDOM.C < prev    next >
C/C++ Source or Header  |  1994-04-17  |  2KB  |  71 lines

  1. /* Here is a program to convert your hosts.net to domain.txt */
  2. #include <stdio.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.   
  6. #define LINELEN 256
  7. /* copyright 1989 - John D. Hays, KD7UW */
  8. main(int argc,char *argv[])
  9. {
  10.   
  11.     FILE *fi,*fo;
  12.     char string[LINELEN-1];
  13.     char addr[20],hname1[80],hname2[80];
  14.     char *x,*y,*z;
  15.   
  16.     fprintf(stderr,"COPYRIGHT 1989 - John D. Hays, KD7UW\n");
  17.     if (argc != 3)
  18.     {
  19.         fprintf(stderr,"Usage: %s input-hosts.net output-domain.txt\n\007",
  20.         argv[0]);
  21.         exit(0);
  22.     }
  23.   
  24.     if ((fi=fopen(argv[1],"r")) != NULL)
  25.     {
  26.         fo = fopen(argv[2],"w");
  27.         while (fgets(string,LINELEN,fi) != NULL)
  28.         {
  29.   
  30.             y = strchr(string,'\n');
  31.             *y = '\0';
  32.             addr[0] = '\0';
  33.             hname1[0] = '\0';
  34.             hname2[0] = '\0';
  35.   
  36.             if ((string[0] == '#') || (strlen(string) < 3))
  37.             {
  38.                 fprintf(fo,"%s\n",string);
  39.                 goto foo;
  40.             }
  41.             y = strchr(string,'#');
  42.             if (y != NULL)
  43.             {
  44.                 fprintf(fo,"#%s\n",y);
  45.                 *y = '\0';
  46.             }
  47.             sscanf(string,"%s%s%s",addr,hname1,hname2);
  48.             if (strchr(hname1,'.'))
  49.             {
  50.                 x = hname1;
  51.                 z = hname2;
  52.             }
  53.             else
  54.             {
  55.                 x = hname2;
  56.                 z = hname1;
  57.             }
  58.             if ((*x == '\0') || (*z == '\0'))
  59.             {
  60.                 fprintf(fo,"%s.\tIN\tA\t%s\n",hname1,addr);
  61.             }
  62.             else
  63.             {
  64.                 fprintf(fo,"%s.\tIN\tA\t%s\n",x,addr);
  65.                 fprintf(fo,"%s.\tIN\tCNAME\t%s.\n",z,x);
  66.             }
  67.             foo:            fprintf(stderr,"%s\n",string);
  68.         }
  69.     }
  70. }
  71.