home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / com / bbs / downsrt / source / downsort.c < prev    next >
C/C++ Source or Header  |  1991-06-16  |  9KB  |  193 lines

  1. /* ============================================================= */
  2. /*  Rob Hamerling's MAXIMUS download file scan and sort utility  */
  3. /* ============================================================= */
  4.  
  5. // #define DEBUG_MODE
  6.  
  7. #define INCL_BASE
  8. #include <os2.h>
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <time.h>
  13.  
  14. #include "downsort.h"
  15.  
  16. /* Global variables definitions all in mainline-module      */
  17. /* Submodules will get external declarations via downsort.h */
  18.  
  19. char PROGNAME[]   = "DOWNSORT";         // program name (and filenames)
  20. char VERSION      = '5';                // current version
  21. char SUBVERS      = '1';                // current release
  22. char SUFFIX       = ' ';                // development suffix
  23. char PROGDESC[]   = "DOWNload file SORT and list utility";
  24. char AUTHOR[]     = "Rob Hamerling";    // program author
  25. char CITY[]       = "Vianen, The Netherlands";
  26. char PHONE[]      = "Phone 31.3473.72136 (voice)";
  27. char FIDO[]       = "Fido-net 2:512/4.1098";
  28. char MAX[]        = "MAXIMUS CBCS";
  29. char MSG_MEM[]    = "\nInsufficient memory, %s terminated\n";
  30. char MSG_SRT[]    = "\nSorting %u files from %u directories for %s";
  31. char MSG_RST[]    = "\nRe-sorting first %u entries on filename";
  32. char MSG_TRL[]    = "\n       Include-file - %s - not found!";
  33. char MSG_REC[]    = "\n       file entries written to: %s";
  34. char OPEN_FAIL[]  = "\nCould not open file: %s\n";
  35. char DESC_MISS[]  = "\n       Description file %s not found";
  36. char HS[]         = "────────────────────────────────────────";
  37. char HD[]         = "════════════════════════════════════════";
  38. char FN[]         = "Filename";
  39. char AC[]         = "Area";
  40. char DT[]         = "Date";
  41. char SZ[]         = "Size";
  42. char DS[]         = "Description";
  43. char FP[]         = "FilePath";
  44. char EMPTY[]      = "";                 // empty string
  45. char NDS[46]      = "--- no description available ---";
  46. char ORPHAN[46]   = "************ ORPHAN ************";
  47. char BAK[]        = "BAK";              // backup file extension
  48. char CFG[]        = "CFG";              // config      "
  49. char *priv_name[] = {"Twit"," ","Disgrace","Limited","Normal",
  50.                     "Worthy","Privil","Favored","Extra","Clerk",
  51.                     "AsstSysop"," ","Sysop","Hidden"};
  52.  
  53. char today[26];                         // output timestamp
  54. char list_title[21]    = "";            // ALL/IPF/NEW/GBL BLOCK title
  55. char *pre_title[MAXTIT]= {NULL,NULL,NULL,NULL,NULL,  // ptrs to pretitles
  56.                           NULL,NULL,NULL,NULL,NULL,
  57.                           NULL,NULL,NULL,NULL,NULL,
  58.                           NULL,NULL,NULL,NULL,NULL};
  59. char *sub_title[MAXTIT]= {NULL,NULL,NULL,NULL,NULL,  // ptrs to subtitles
  60.                           NULL,NULL,NULL,NULL,NULL,
  61.                           NULL,NULL,NULL,NULL,NULL,
  62.                           NULL,NULL,NULL,NULL,NULL};
  63. char *bot_lines[MAXTIT]= {NULL,NULL,NULL,NULL,NULL,  // ptrs to bottomlines
  64.                           NULL,NULL,NULL,NULL,NULL,
  65.                           NULL,NULL,NULL,NULL,NULL,
  66.                           NULL,NULL,NULL,NULL,NULL};
  67. USHORT title_lines[]   = {0,3,5,4,5};   // # of lines per title-font
  68.                                         // See DOWNFNT.C for 'real' table.
  69. char areadat_path[128] = "AREA.DAT";    // (default) AREA.DAT filespec
  70. char cfg_path[128]     = "DOWNSORT.CFG";// (default) config filespec
  71. char filesbbs_path[128]= "";            // path to FILES.bbs output
  72. char oper_mode         = ' ';           // V: verbose: talk a lot
  73.                                         // Q: only error messages
  74.                                         // H: display help-screen
  75. USHORT area_count      = 0;             // number of download directories
  76. USHORT file_count      = 0;             // counter for number of files
  77. ULONG  byte_count      = 0;             // counter for file sizes
  78. int    MAX_level       = 0;             // version of MAX from AREA.DAT
  79. int    ABS_MAX_priv    = TWIT;          // overall max report-privilege
  80. struct _filechain *first_element = NULL; // ptr first chain element
  81. struct _COUNTRYCODE c_code;             // country code buffer
  82. struct _COUNTRYINFO c_info;             // country information buffer
  83.  
  84. struct _listparm lp[]  = {
  85.       {                                 // BBS-list (P_BBS)
  86.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  87.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  88.         FONT2, 65535, TIMESTAMP, TRUNC, ' ',
  89.         "DOWNSORT", "BBS", NULL},
  90.  
  91.       {                                 // FILES.BBS (P_FIL)
  92.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  93.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  94.         FONT2, 65535, ALPHA, TRUNC, ' ',
  95.         "FILES", "BBS", NULL},
  96.  
  97.       {                                 // GBL-list (P_GBL)
  98.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  99.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  100.         FONT2, 65535, ALPHA, WRAP, ' ',
  101.         "DOWNSORT", "G~", NULL},
  102.  
  103.       {                                 // NEW-list (P_NEW)
  104.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  105.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  106.         FONT2, 65535, TIMESTAMP, TRUNC, ' ',
  107.         "DOWNSORT", "N~", NULL},
  108.  
  109.       {                                 // ALL-list (P_ALL)
  110.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  111.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  112.         FONT2, 65535, ALPHA, WRAP, ' ',
  113.         "DOWNSORT", "A~", NULL},
  114.  
  115.       {                                 // IPF-list (P_IPF)
  116.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  117.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  118.         FONT2, 65535, ALPHA, WRAP, ' ',
  119.         "DOWNSORT", "I~", NULL},
  120.  
  121.       {                                 // ORP-list (P_ORP)
  122.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  123.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  124.         FONT2, 65535, ALPHA, TRUNC, ' ',
  125.         "DOWNSORT", "ORP", NULL},
  126.          };
  127.  
  128. /* ====================== */
  129. /*   M A I N    L I N E   */
  130. /* ====================== */
  131. int  main(argc,argv)
  132. int  argc;
  133. char *argv[];
  134. {
  135.   struct  _downpath  *area;             // pointer to area-info arrays
  136.   struct  _filechain **dm;              // pointer to file-sort array
  137.   USHORT   i;                           // counter
  138.   long     start_time,run_time;         // for execution time measurement
  139.  
  140.   start_time = time(NULL);              // system time at start
  141.   sprintf(list_title,"%s%c%c%c",PROGNAME,VERSION,SUBVERS,SUFFIX);
  142.                                         // default title
  143.   get_parm(argc,argv);                  // system and oper. parameters
  144.                                         // and display welcome msg
  145.   if (oper_mode == VERBOSE)
  146.     printf("\nCollecting file-area information");
  147.   area_count = collect_down(&area);     // build arrays with area-info
  148.  
  149.   if (oper_mode == VERBOSE)
  150.     printf("\nCollecting download file information");
  151.   file_count = collect_file(area_count,area);  // collect all file info
  152.  
  153.   if (file_count == 0) {                // no files
  154.     printf("\nNot a single file falls withing report criteria, or");
  155.     printf("\nno download paths found at all, %s terminated\n",PROGNAME);
  156.     exit(10);
  157.     }
  158.  
  159.   dm = prep_sort(file_count,first_element); // make sort array
  160.  
  161.   if (lp[P_ORP].priv[0] <= HIDDEN)      // OPRHAN-report
  162.     make_orp(dm);
  163.  
  164.   if (lp[P_BBS].priv[0] <= HIDDEN)      // BBS-list
  165.     make_bbs(dm,lp[P_BBS].max_fil,lp[P_BBS].priv[0]);
  166.  
  167.   for (i=0; i<10 && lp[P_NEW].priv[i] <= HIDDEN; i++) // NEW-list(s)
  168.     make_new(dm,lp[P_NEW].max_fil,lp[P_NEW].priv[i]);
  169.  
  170.   for (i=0; i<10 && lp[P_GBL].priv[i] <= HIDDEN; i++) // GBL-list(s)
  171.     make_gbl(dm,lp[P_GBL].priv[i]);
  172.  
  173.   for (i=0; i<10 && lp[P_ALL].priv[i] <= HIDDEN; i++) // ALL-list(s)
  174.     make_all(dm,area,lp[P_ALL].priv[i]);
  175.  
  176.   for (i=0; i<10 && lp[P_IPF].priv[i] <= HIDDEN; i++) // IPF-list(s)
  177.     make_ipf(dm,area,lp[P_IPF].priv[i]);
  178.  
  179.   if (lp[P_FIL].priv[0] <= HIDDEN)      // FILES.BBS
  180.     make_fil(dm,lp[P_FIL].priv[0]);
  181.  
  182.   printf("\n");
  183.   if (oper_mode != QUIET)
  184.     printf("\n%s version %c.%c%c by %s ",
  185.              PROGNAME,VERSION,SUBVERS,SUFFIX,AUTHOR);
  186.   run_time = time(NULL) - start_time;   // execution time in seconds
  187.   printf("completed in %ld minutes and %ld seconds.\n\n",
  188.           run_time/60,run_time%60);     // report execution time
  189.  
  190.   return(0);                            // OS will release all storage!
  191.   }
  192.  
  193.