home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / BBS / FBBSPC11.ZIP / FBBSPCB.CPP next >
C/C++ Source or Header  |  1995-01-02  |  11KB  |  339 lines

  1. /*                              FBBSPCB.CPP                                 */
  2. /*                     FILES.BBS to PCBoard DIR v1.1                        */
  3. /*                     by Steve Walcher Jan 1995                            */
  4. /*                     Compiled w/ Borland C++                              */
  5. /*                                                                          */
  6. /*   Syntax: FBBSPCB <drive:> <pcbdir_path> <desc_col#>                     */
  7. /*                                                                          */
  8. /*    where: <drive:>      = drive letter of the CD-ROM                     */
  9. /*           <pcbdir_path> = path to directory to save DIR files            */
  10. /*                           (uses directory name for DIR filename)         */
  11. /*           <desc_col#>   = column # of description  (start from 0)        */
  12. /*                                                                          */
  13. /*   example:                                                               */
  14. /*           FBBSPCB G: c:\pcb\dir\cd1\ 17                                  */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*             This utility will convert the FILES.BBS                      */
  18. /*             descriptions from many CD-ROMs and create a DIR Text File    */
  19. /*             that can be used by PCBoard14.x/15.x.  A separate file       */
  20. /*             will be created for each directory on the CD-ROM. They       */
  21. /*             will be placed in the directory you specify.                 */
  22. /*                                                                          */
  23. /*                                                                          */
  24. /* FILES.BBS sample:                                                2       */
  25. /*           1         2         3         4         5         6    5       */
  26. /* 0123456789012345678901234567890123456789012345678901234567890....5       */
  27. /* ASTROFAQ.ZIP [0] How to become an Astronaut? Internet FAQ.               */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /*           o File names must start in column 0.                           */
  31. /*           o File descriptions must be limited to one line and it must    */
  32. /*             be the same line as the file name.                           */
  33. /*           o File descriptions over 255 characters in length will be      */
  34. /*             truncated.                                                   */
  35. /*                                                                          */
  36. /*             Special thanks to:                                           */
  37. /*             Paul Kromann, and Dan Renfrow for their help.                */
  38. /*                                                                          */
  39. /*             Use this program at your own risk!!                          */
  40. /*                                                                          */
  41. /*             I have used this program without problems on my own system   */
  42. /*             but make warrantee as to how it will work for you.           */
  43. /*                                                                          */
  44. /*             Dedicated to the Public Domain                               */
  45. /*             You may borrow, use, abuse this source code to your hearts   */
  46. /*             content....                                                  */
  47. /*                                                                          */
  48. /*             You can reach me at:                                         */
  49. /*                                                                          */
  50. /*             Internet: steve.walcher@tpalley.eskimo.com                   */
  51. /*                 RIME: ->TPALLEY #1285                                    */
  52. /*                       Tin Pan Alley BBS                                  */
  53. /*                       Mukilteo, WA  USA                                  */
  54. /*                       (206)742-7782 USR DS                               */
  55. /*                                                                          */
  56. /*                                                                          */
  57.  
  58. #include <string.h>
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <conio.h>
  62. #include <fcntl.h>
  63. #include <io.h>
  64. #include <dos.h>
  65. #include <dir.h>
  66.  
  67. #define D_LENGTH 45 /* number of characters in description */
  68. #define LINES 3     /* number of lines in description */
  69.  
  70. void find_sp(char *str);
  71. void find_nl(char *str);
  72. void set_col(FILE *fp, int col);
  73.  
  74. int main(int argc, char **argv)
  75. {
  76.  
  77. FILE *fileptr;
  78. FILE *fileptr2;
  79. FILE *stream;
  80.  
  81. struct ffblk ffblk, dir;
  82. struct ftime ft;
  83.  
  84. char ch[1], filename[80], filename2[80];
  85. char name[12],junk[5],desc[255], desc3[LINES][D_LENGTH];
  86. char fname[80], s[8];
  87.  
  88. char cd_drv[3],cd_drv1[5],pcbdir[80];
  89. char *ptr;
  90.  
  91. int handle;
  92. unsigned date, time;
  93. int done = 0;
  94. long size;
  95. int length;
  96. int line, d_length;
  97.  
  98. int dircount = 0;
  99. int i, i2, yr, mo, dy;
  100. int name_col, desc_col;
  101.  
  102. desc3[0][0]='\0';       // may be unnecessary but better safe than sorry
  103. desc3[1][0]='\0';
  104. desc3[2][0]='\0';
  105.  
  106.  
  107. if (argc != 4)
  108.   {
  109.    printf("  Usage: FBBSPCB <cd-rom_drive:> <PCBdirpath> <desc_col#>\n\n");
  110.    printf("Example: FBBSPCB G: c:\\pcb\\files\\cd1\\ 17\n");
  111.    return 1;
  112.   }
  113.  
  114. strcpy (pcbdir,argv[2]);        // directory name for
  115. strcpy (s,argv[3]);        // column number for description
  116. desc_col = atoi(s);
  117. name_col = 0;            // column number for filename
  118.  
  119. while(!done) {
  120.    strcpy(cd_drv1,argv[1]);
  121.    strcat(cd_drv1, "/*.*");
  122.    done = findfirst(cd_drv1, &dir, FA_DIREC);
  123.    for (i = dircount; i > 0; i--) {
  124.     done = findnext(&dir);
  125.     }
  126.    if (dir.ff_attrib != '\1') {
  127.     dircount++;
  128.     // open FILES.BBS in found directory
  129.     strcpy(cd_drv,argv[1]);
  130.     strcat(cd_drv, "/");
  131.     filename[0] ='\0';
  132.     strcpy(filename, cd_drv);
  133.     strcat(filename, dir.ff_name);
  134.     strcat(filename, "/FILES.BBS");
  135.  
  136.  
  137.     if ((fileptr =fopen(filename,"r")) == NULL)
  138.     {
  139.     printf("Error: cannot open input file\n");
  140.     printf("%s", filename);
  141.     exit(1);
  142.     }
  143.  
  144.     /* open file for writing output to */
  145.     /* use directory name for file name */
  146.     filename2[0] ='\0';
  147.     strcpy(filename2, pcbdir);
  148.     strcat(filename2, dir.ff_name);
  149.  
  150.     if ((fileptr2 =fopen(filename2,"w")) == NULL)
  151.     {
  152.     printf("Error: cannot open output file\n");
  153.     exit(0);
  154.     }
  155.      printf("\nFilename       Size      Date    Description of File Contents\n");
  156.        printf("============ ========  ========  ============================================");
  157. fprintf(fileptr2, "Filename       Size      Date    Description of File Contents\n");
  158. fprintf(fileptr2, "============ ========  ========  ============================================");
  159.  
  160.     /* set fileptr to beginning of file */
  161.     fseek(fileptr, 0, SEEK_SET);
  162.  
  163.     while(!feof(fileptr)) {
  164.         name[0]='\0';
  165.         junk[0]='\0';
  166.         desc[0]='\0';
  167.         set_col(fileptr, name_col);
  168.         fgets(name, 13, fileptr);
  169.         find_sp(name);
  170.         //fgets(junk, 6,  fileptr);
  171.         set_col(fileptr, desc_col);
  172.         fgets(desc, 255, fileptr);
  173.         strcpy(fname, cd_drv);
  174.         strcat(fname, dir.ff_name);
  175.         strcat(fname, "/");
  176.         strcat(fname, name);
  177.         //printf("%s\n", fname);
  178.         findfirst(fname, &ffblk, 0);
  179.  
  180. /*
  181.   ff_fdate ║15..........9║8.....5║4.......0║
  182.   ▄▄▄▄▄▄▄▄ ╠═╤═╤═╤═╤═╤═╤═╬═╤═╤═╤═╬═╤═╤═╤═╤═╣
  183.        ╚═╧═╧═╧═╧═╧═╧═╩═╧═╧═╧═╩═╧═╧═╧═╧═╝
  184.          Years since   Month     Day
  185.         1980
  186. */
  187.         yr = (ffblk.ff_fdate >> 9) + 80;
  188.         mo = (ffblk.ff_fdate >> 5) & 0x0F;
  189.         dy = ffblk.ff_fdate & 0x1F;
  190.  
  191. /*  format of output
  192.  
  193. Filename       Size      Date    Description of File Contents
  194. ============ ========  ========  ============================================
  195. 0803PR3.TXT      3316  09-22-93  August 3, 1993 CLI2NTON ADMINISTRATION ACTS TO
  196.                    | MOVE TIMBER SALES
  197. */
  198.  
  199.         /* print name, size, date */
  200.  
  201.         printf("\n%-12s %8lu  %02i-%02i-%02i  ",ffblk.ff_name, ffblk.ff_fsize, mo, dy, yr);
  202.      fprintf(fileptr2, "\n%-12s %8lu  %02i-%02i-%02i  ",ffblk.ff_name, ffblk.ff_fsize, mo, dy, yr);
  203.  
  204.  
  205. /*  convert desc strings > 45 in length */
  206. /*  put it into array desc3[LINE][D_LENGTH] */
  207.  
  208.         length = strlen(desc);
  209.         ptr = desc;
  210.           if(length > D_LENGTH-1)
  211.           {
  212.              for(line=0; line < LINES; line++)
  213.              {
  214.  
  215.  
  216.                for(d_length=0; d_length < D_LENGTH; d_length++)
  217.                {
  218.              if(*ptr != '\n')
  219.              {
  220.                  desc3[line][d_length] = *ptr++;
  221.                  if(d_length+1 == D_LENGTH)
  222.                  {
  223.                    /* search for truncated words, back up if found */
  224.                    while((*ptr != ' ')&&(*ptr != '\n'))
  225.                    {
  226.                 d_length--;
  227.                 ptr--;
  228.                    }
  229.                    if(*ptr == ' ')
  230.                  ptr++; /* get off of ' '(sp) */
  231.                    desc3[line][d_length+1] = '\0';
  232.                    break;
  233.                  }
  234.              }
  235.              else /* replace '\n' with NULL */
  236.              {
  237.                desc3[line][d_length] = '\0';
  238.                break;
  239.              }
  240.                }//end for
  241.  
  242.                 /* print desc */
  243.                if(*desc3[line] != '\0')
  244.              {
  245.                if(line!=0)
  246.                {
  247.                  printf("\n                               | %s", desc3[line]);
  248.           fprintf(fileptr2, "\n                               | %s", desc3[line]);
  249.                }
  250.                else
  251.                {
  252.                  printf("%s", desc3[line]);
  253.                  fprintf(fileptr2, "%s", desc3[line]);
  254.                }
  255.              }
  256.              }//end for
  257.           }
  258.           else
  259.           {
  260.             find_nl(desc);
  261.             printf("%s", desc);
  262.             fprintf(fileptr2, "%s", desc);
  263.           }
  264.  
  265.     }
  266.     fclose(fileptr);
  267.  
  268.    }
  269.    else dircount++;
  270.    fclose(fileptr2);
  271.  
  272. }
  273. return 0;
  274. }
  275.  
  276. /* Function:  find_sp(char *str)  */
  277. /* parameters: string                */
  278. /* find first space in string, convert to '\0'(NULL) */
  279.  
  280. void find_sp(char *str)
  281. {
  282.    while (*str != '\0')
  283.    {
  284.     if (*str == ' ')
  285.     {
  286.        *str = '\0';
  287.     }
  288.     str++;
  289.    }
  290. }
  291. /* ----------------------------= END =------------------------------- */
  292.  
  293.  
  294. /* Function:  find_nl(char *str)  */
  295. /* parameters: string                */
  296. /* find first '\n'(new line) in string, convert to '\0'(NULL) */
  297.  
  298. void find_nl(char *str)
  299. {
  300.    while (*str != '\0')
  301.    {
  302.     if (*str == '\n')
  303.     {
  304.        *str = '\0';
  305.     }
  306.     str++;
  307.    }
  308. }
  309. /* ----------------------------= END =------------------------------- */
  310.  
  311. /* Function: set_col(FILE *fp, int col)                      */
  312. /* parameters: fp, col <column number to set>                */
  313. /* set file pointer to column 'col' for a given line in file */
  314. void set_col(FILE *fp, int col)
  315. {
  316.   long curpos;
  317.   char ch;
  318.  
  319.   // first, set pointer to column 0
  320.  
  321.   curpos = ftell(fp);
  322.   if (curpos != 0)            // check for begining of file
  323.   {
  324.     do
  325.     {
  326.       fseek (fp, -1, SEEK_CUR);        // move backwards 1 char
  327.       ch = fgetc(fp);
  328.       fseek (fp, -1, SEEK_CUR);        // move backwards 1 char
  329.       curpos = ftell(fp);
  330.     } while ((ch != '\n') && (curpos != 0));  // check for '\n' (newline)
  331.     if (curpos != 0)            // check fo begining
  332.     {
  333.       fseek (fp, 1, SEEK_CUR);          // move forward to column 0
  334.     }
  335.   }
  336.   fseek (fp, col, SEEK_CUR);        // set to column 'col'
  337. }
  338. /* ----------------------------= END =------------------------------- */
  339.