home *** CD-ROM | disk | FTP | other *** search
/ Toolkit for DOOM / DOOMTOOL.ISO / _bbs / pcbtool / dirlst.c < prev    next >
Text File  |  1994-09-12  |  2KB  |  113 lines

  1. /*
  2.  * build pcboard dir.lst
  3.  */
  4.  
  5.  
  6. // xxx two trailing \\'s.
  7.  
  8. #include <ctype.h>
  9. #include <string.h>
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12.  
  13. #if 0
  14. 123456789012345678901234567890
  15. J:\BBS\PCB\ADA                
  16. 12345678901234567890123456789012345678901234567890123456789012345
  17. E:\MSDOS\ADA\                                                    
  18. #endif
  19.  
  20.  
  21.  
  22. /*
  23.  * output:
  24.  *
  25.  * 1) path of index file    buf1
  26.  * 2) path of file area        buf2
  27.  * 3) file description        (from area path && dir)
  28.  */
  29.  
  30. #if 0
  31. old:
  32. dirlst %output%\dir%2 %cdrom%%1\ %1 < %cdrom%\_bbs\dirs.txt >> dir.lst
  33.  
  34. new:
  35. dirlst %output%\dir%2 %cdrom% %1 < %cdrom%\_bbs\dirs.txt >> dir.lst
  36. #endif
  37.  
  38. void
  39. usage(void) {
  40.     fprintf(stderr,
  41.     "usage: dirlst <index file path> <cdrom drive letter> <file area path>\n");
  42.     exit(1);
  43. }
  44.  
  45. /*
  46.  * description file, directory where files are, directory description
  47.  */
  48. void _Cdecl
  49. main(int argc, char *argv[]) {
  50.     char buf[200];
  51.     char buf1[80];
  52.     char buf2[80];
  53.     char buf3[80];
  54.     int len;
  55.     char *p;
  56.     
  57.     strcpy(buf1, argv[1]);
  58.     buf1[30] = '\0';
  59.     len = strlen(buf1);
  60.     if (buf1[len - 1] == '\\' && buf1[len - 2] == '\\')
  61.         buf1[len - 2] = '\0';
  62.  
  63.     sprintf(buf2, "%s%s", argv[2], argv[3]);
  64.     buf2[30] = '\0';
  65.     len = strlen(buf2);
  66.     if (buf2[len - 1] == '\\' && buf2[len - 2] == '\\')
  67.         buf2[len - 2] = '\0';
  68.  
  69.  
  70.     strcpy(buf3, argv[3]);
  71.     buf3[35] = '\0';
  72.     len = strlen(buf3);
  73.     if (!len) {
  74.         fprintf(stderr, "dirlst: no area path found.\n");
  75.         usage();
  76.     }
  77.     if (buf3[len - 1] == '\\' && buf3[len - 2] == '\\')
  78.         buf3[len - 2] = '\0';
  79.     else if (buf3[len - 1] != '\\') {
  80.         buf3[len] = '\\';
  81.         buf3[len + 1] = '\0';
  82.     }
  83.     buf3[35] = '\0';
  84.  
  85. #if 0        
  86.     sprintf(buf, "%s\\00_index.txt", argv[4]);
  87.     if (NULL == (in_fp = fopen(buf, "r"))) {
  88.         print_err("failed opening input file '%s'\n", buf);
  89.         exit(1);
  90.     }
  91. #endif    
  92.  
  93.     /* find area description in dirs.txt */
  94.     buf3[0] = '\0';
  95.     while (NULL != gets(buf)) {
  96.         if (0 == strncmpi(argv[3], buf, len)) {
  97.             p = buf + len;
  98.             while (isspace(*p))
  99.                 ++p;
  100.             strcpy(buf3, p);
  101.             buf3[35] = '\0';
  102.             break;
  103.         }
  104.     }
  105.     if (! buf3[0]) {
  106.         fprintf(stderr, "no area found:\n%s\n", argv[3]);
  107.         exit(1);
  108.     }
  109.     
  110.     printf("%-30s%-30s%-35s", buf1, buf2, buf3);
  111.     exit(0);
  112. }
  113.