home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS 1997 March / Simtel-MSDOS-Mar1997-CD2.iso / 00_info / simserch.c < prev    next >
C/C++ Source or Header  |  1997-01-27  |  8KB  |  282 lines

  1. /******************************************************************************
  2.  
  3. SIMSERCH:   This program facilitates searching through the SIMIBM.IDX file
  4.             available from the SIMTEL archives.  It supports keyword searches
  5.             within selectable fields, starting and ending date boundaries,
  6.             and user specified index files.  It can also create (or append to)
  7.             a SIMTEL request file which is suitable for e-mailing to the
  8.             SIMTEL list servers.
  9.  
  10.             This program will compile and run under Turbo-C 2.0 and
  11.             VAX/VMS C.
  12.  
  13.             This program is FREEWARE, and comes with NO WARRANTEES,
  14.             expressed or implied.
  15.  
  16.    Author:  Richard W. Hull <hull@skvax1.csc.ti.com>
  17.  
  18.    Acknowledgements:
  19.             Ed. Mueller and Larry Johnson for providing valuable inputs and
  20.             for insisting that I submit the results to SIMTEL.
  21.  
  22.    Usage:   simserch [?]
  23.                      [-s[fdnx] search-string]
  24.                      [-d[se] start/end date]
  25.                      [-i index-file]
  26.                      [-r[a] simtel-request-file]
  27.  
  28. ******************************************************************************/
  29.  
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #ifdef VAX11C
  34. char *strlwr( char *arg )
  35. {
  36.    char *arg_save = arg;
  37.  
  38.    while( *arg )
  39.    {
  40.       *arg = tolower( *arg );
  41.       arg++;
  42.    }
  43.    return( arg_save );
  44. }
  45. #endif
  46.  
  47. int main( int argc, char *argv[] )
  48.  
  49. {
  50. FILE  *index_file, *simreq_file;         /* input file */
  51. char  fs[10],dir[60],name[15],descr[60]; /* input variables */
  52. char  inputline[257];                    /* for initial read */
  53. int   rev,bits;                          /* input variables */
  54. long  length,date,sdate,edate;           /* input variables */
  55. char  lfs[10],ldir[60];                  /* stores last filesystem/directory */
  56. char  type;                              /* output variable for 'A' or 'B' */
  57. char  searchstr[40];                     /* string to qualify entries */
  58. int   search_fs, search_dir,
  59.       search_name, search_desc;          /* indicates which fields to search */
  60. char  teststr[257];                      /* combo of fs,dir,name,descr */
  61. char  ndxfilnam[100];                    /* name of input index file */
  62. char  reqfilnam[100];                    /* SIMTEL request file */
  63. int   append_to_req;                     /* Flag for opening SIMTEL req file */
  64. long  tot_files, sel_files;              /* total, selected files */
  65. long  tot_ldate, sel_ldate;              /* total, selected last date */
  66. char  c;                                 /* picks off EOF,",linefeed */
  67. int   i,j;
  68.  
  69. sdate = 0;
  70. edate = 999999;
  71. searchstr[0] = '\0';
  72. #ifdef VAX11C
  73. strcpy( ndxfilnam, "USER2:[HULL]SIMIBM.IDX" );
  74. #else
  75. strcpy( ndxfilnam, "simibm.idx" );
  76. #endif
  77. reqfilnam[0] = '\0';
  78. tot_files = sel_files = tot_ldate = sel_ldate = 0;
  79.  
  80. if (argc > 1 && strstr( argv[1], "?" ))
  81. {
  82.    printf( "Usage:  simserch [?]\n" );
  83.    printf( "                 [-s[fdnx] search-string]\n" );
  84.    printf( "                 [-i index-file-name]\n" );
  85.    printf( "                 [-d[se] start/end date]\n" );
  86.    printf( "                 [-r[a] simtel-request-file]\n" );
  87.    printf( "\n" );
  88.    printf( "  -s [f search FILE-SYSTEM\n" );
  89.    printf( "      d        DIRECTORY\n" );
  90.    printf( "      n        NAME\n" );
  91.    printf( "      x        DESCRIPTION]\n" );
  92.    printf( "     Default is to search ALL fields.\n" );
  93.    printf( "\n" );
  94.    printf( "  -d [s starting date\n" );
  95.    printf( "      e ending date]\n" );
  96.    printf( "     Default is Starting-Date\n" );
  97.    printf( "     Date format is YYMMDD.\n" );
  98.    printf( "\n" );
  99.    printf( "  -r [a append to Request File]\n" );
  100.    printf( "     Default is to Overwrite Request File.\n" );
  101.  
  102.    exit(0);
  103. }
  104.  
  105. if (!(argc % 2))
  106. {
  107.    printf( "Invalid number of parameters\n\n" );
  108.    exit(0);
  109. }
  110.  
  111. printf("Simtel.Net Public Domain, Freeware and Shareware listing\n\n");
  112.  
  113. for (i=1; i<argc; i+=2)
  114. {
  115.    if (strstr( argv[i], "-s" ))
  116.    {
  117.       search_fs = search_dir = search_name = search_desc = 0;
  118.       strcpy( searchstr, argv[i+1] );
  119.       strlwr( searchstr );
  120.  
  121.       /* Look for mention of specific fields to search */
  122.  
  123.       if (strstr( argv[i], "f" )) search_fs   = 1;
  124.       if (strstr( argv[i], "d" )) search_dir  = 1;
  125.       if (strstr( argv[i], "n" )) search_name = 1;
  126.       if (strstr( argv[i], "x" )) search_desc = 1;
  127.  
  128.       /* If no specific fields were mentioned, search everything */
  129.  
  130.       if (!(search_fs || search_dir || search_name || search_desc))
  131.          search_fs = search_dir = search_name = search_desc = 1;
  132.    }
  133.  
  134.    if (strstr( argv[i], "-d" ))
  135.    {
  136.       if (strstr( argv[i], "e" ))
  137.          sscanf( argv[i+1], "%ld", &edate );
  138.       else
  139.          sscanf( argv[i+1], "%ld", &sdate );
  140.  
  141.       if (strstr( argv[i], "s" ))
  142.          sscanf( argv[i+1], "%ld", &sdate );
  143.    }
  144.  
  145.    if (!strcmp( "-i", argv[i] ))
  146.    {
  147.       strcpy( ndxfilnam, argv[i+1] );
  148.       strlwr( ndxfilnam );
  149.    }
  150.  
  151.    if (strstr( argv[i], "-r" ))
  152.    {
  153.       strcpy( reqfilnam, argv[i+1] );
  154.       strlwr( reqfilnam );
  155.       append_to_req = (argv[i][2] == 'a');
  156.    }
  157. }
  158.  
  159. if (searchstr[0])
  160. {
  161.    printf( "Will search " );
  162.    if (search_fs)   printf( "FILE-SYSTEM " );
  163.    if (search_dir)  printf( "DIRECTORY " );
  164.    if (search_name) printf( "NAME " );
  165.    if (search_desc) printf( "DESCRIPTION " );
  166.    printf( "for: %s\n", searchstr );
  167. }
  168.  
  169. if (sdate > 0)
  170.    printf( "Starting Date: %ld\n", sdate );
  171.  
  172. if (edate < 999999)
  173.    printf( "Ending Date:   %ld\n", edate );
  174.  
  175. printf( "Index File to be searched is: %s\n", ndxfilnam );
  176.  
  177. if (!(index_file = fopen( ndxfilnam, "r" )))
  178. {
  179.    printf( "\nCould not open Index File: %s\n", ndxfilnam );
  180.    exit(0);
  181. }
  182.  
  183. if (reqfilnam[0])
  184. {
  185.    char open_mode[4];
  186.  
  187.    if (append_to_req)
  188.    {
  189.       strcpy( open_mode, "a" );
  190.       printf( "Selected Files will be appended to: %s\n", reqfilnam );
  191.    }
  192.    else
  193.    {
  194.       strcpy( open_mode, "w" );
  195.       printf( "Selected Files will be written to: %s\n", reqfilnam );
  196.    }
  197.  
  198.    if (!(simreq_file = fopen( reqfilnam, open_mode )))
  199.    {
  200.       printf( "\nCould not open Request File: %s\n", reqfilnam );
  201.       exit(0);
  202.    }
  203. }
  204.  
  205. printf("\nNOTE: Type B is Binary; Type A is ASCII\n");
  206.  
  207. inputline[256] = 0;
  208.  
  209. while (fgets(inputline, 256, index_file) != NULL)  {
  210.  
  211.    sscanf(inputline,
  212.             "\"%[^\"]\",\"%[^\"]\",\"%[^\"]\",%d,%ld,%d,%ld,\"%[^\"]\"",
  213.             fs, dir, name, &rev, &length, &bits, &date, descr);
  214.  
  215.    tot_files++;
  216.    if (date > tot_ldate) tot_ldate = date;
  217.  
  218.    if (date < sdate) continue;
  219.    if (date > edate) continue;
  220.  
  221.    teststr[0] = '\0';
  222.    if (search_fs)
  223.    {
  224.       strcat( teststr, fs );
  225.       strcat( teststr, " " );
  226.    }
  227.    if (search_dir)
  228.    {
  229.       strcat( teststr, dir );
  230.       strcat( teststr, " " );
  231.    }
  232.    if (search_name)
  233.    {
  234.       strcat( teststr, name );
  235.       strcat( teststr, " " );
  236.    }
  237.    if (search_desc)
  238.    {
  239.       strcat( teststr, descr );
  240.       strcat( teststr, " " );
  241.    }
  242. /*
  243.    sprintf( teststr, "%s %s %s %s", fs, dir, name, descr );
  244. */
  245.    strlwr( teststr );
  246.  
  247.    if (  (searchstr[0]) && !( strstr( teststr, searchstr ) ) )
  248.       continue;
  249.  
  250.    sel_files++;
  251.    if (date > sel_ldate) sel_ldate = date;
  252.  
  253.    type = 'B';                           /* Binary 8-bit */
  254.    if (bits == 7) type = 'A';            /* ASCII  7-bit */
  255.  
  256.    if (strcmp(ldir,dir) || strcmp(lfs,fs)) {  /* New Directory */
  257.       printf("\nDirectory %s%s\n",fs,dir);
  258.       printf(" Filename   Type Length   Date    Description\n");
  259.       printf("==============================================\n");
  260.       strcpy(ldir, dir);          /* Remember last directory with ldir  */
  261.       strcpy(lfs,fs);             /* Remember last file system with lfs */
  262.    }                              /* End of the New Directory routine   */
  263.  
  264.  
  265.    printf("%-12.12s  %c %7ld  %6ld  %s\n",name,type,length,date,descr);
  266.  
  267.    if (reqfilnam[0]) fprintf( simreq_file, "/PDGET %s%s%s UUENCODE\n",
  268.                                              fs, dir, name );
  269.    }
  270.  
  271. if (reqfilnam[0]) fclose( simreq_file );
  272.  
  273. printf( "\n\nNumber of Files (Total/Processed): %ld / %ld\n",
  274.         tot_files, sel_files );
  275. printf( "Last Date for Files (Total/Processed): %ld / %ld\n",
  276.         tot_ldate, sel_ldate );
  277.  
  278. return (1) ;
  279.  
  280. } /* end of main() */
  281.  
  282.