home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / MISC / OS2 / DWNSRT47.ZIP / DOWNSORT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-01  |  7.2 KB  |  164 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 "downsort.h"
  11.  
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <time.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      = 4;                  // current version
  21. char SUBVERS      = 7;                  // 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";
  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 in %u directories for %s";
  31. char MSG_RST[]    = "\nRe-sorting first %u entries on filename";
  32. char MSG_TRL[]    = "\n%sfile - %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 HS[]         = "────────────────────────────────────────";
  36. char HD[]         = "════════════════════════════════════════";
  37. char FN[]         = "Filename";
  38. char AC[]         = "Area";
  39. char DT[]         = "Date";
  40. char SZ[]         = "Size";
  41. char DS[]         = "Description";
  42. char FP[]         = "FilePath";
  43. char EMPTY[]      = "";                 // empty string
  44. char NDS[46]      = "--- no description available ---";
  45. char ORPHAN[46]   = "************ ORPHAN ************";
  46. char BAK[]        = "BAK";              // backup file extension
  47. char CFG[]        = "CFG";              // config      "
  48. char *priv_name[] = {"Twit"," ","Disgrace","Limited","Normal",
  49.                     "Worthy","Privil","Favored","Extra","Clerk",
  50.                     "AsstSysop"," ","Sysop","Hidden"};
  51.  
  52. char today[26];                         // output timestamp
  53. char list_title[21]    = "";            // ALL/NEW/GBL list title
  54. char *pre_title[MAXTIT]= {NULL,NULL,NULL,NULL,NULL,  // ptrs to pretitles
  55.                           NULL,NULL,NULL,NULL,NULL};
  56. char *sub_title[MAXTIT]= {NULL,NULL,NULL,NULL,NULL,  // ptrs to subtitles
  57.                           NULL,NULL,NULL,NULL,NULL};
  58. char *bot_lines[MAXTIT]= {NULL,NULL,NULL,NULL,NULL,  // ptrs to bottomlines
  59.                           NULL,NULL,NULL,NULL,NULL};
  60. USHORT title_lines[]   = {0,3,5,4,5};   // # of lines per title-font
  61.                                         // See DOWNFNT.C for 'real' table.
  62. char areadat_path[128] = "AREA.DAT";    // (default) AREA.DAT filespec
  63. char cfg_path[128]     = "DOWNSORT.CFG";// (default) config filespec
  64. char filesbbs_path[128]= "";            // path to FILES.bbs output
  65. char oper_mode         = ' ';           // V: verbose: talk a lot
  66.                                         // Q: only error messages
  67.                                         // H: display help-screen
  68. USHORT area_count      = 0;             // number of download directories
  69. USHORT file_count      = 0;             // counter for number of files
  70. ULONG  byte_count      = 0;             // counter for file sizes
  71. int    MAX_level       = 0;             // version of MAX from AREA.DAT
  72. struct _filechain *first_element = NULL; // ptr first chain element
  73. struct _COUNTRYCODE c_code;             // country code buffer
  74. struct _COUNTRYINFO c_info;             // country information buffer
  75.  
  76. struct _listparm lp[]  = {
  77.       {                                 // BBS-list (P_BBS)
  78.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  79.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  80.         FONT2, 65535, TIMESTAMP, TRUNC, "DOWNSORT", "BBS"},
  81.  
  82.       {                                 // FILES.BBS (P_FIL)
  83.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  84.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  85.         FONT2, 65535, ALPHA, TRUNC, "FILES", "BBS"},
  86.  
  87.       {                                 // GBL-list (P_GBL)
  88.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  89.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  90.         FONT2, 65535, ALPHA, WRAP, "DOWNSORT", "G~"},
  91.  
  92.       {                                 // NEW-list (P_NEW)
  93.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  94.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  95.         FONT2, 65535, TIMESTAMP, TRUNC, "DOWNSORT", "N~"},
  96.  
  97.       {                                 // ALL-list (P_ALL)
  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, "DOWNSORT", "A~"},
  101.  
  102.       {                                 // ORP-list (P_ORP)
  103.        {HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,
  104.         HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1,HIDDEN+1},
  105.         FONT2, 65535, ALPHA, TRUNC, "DOWNSORT", "ORP"},
  106.          };
  107.  
  108. /* ====================== */
  109. /*   M A I N    L I N E   */
  110. /* ====================== */
  111. int  main(argc,argv)
  112. int  argc;
  113. char *argv[];
  114. {
  115.   struct  _downpath  *area;             // pointer to area-info arrays
  116.   struct  _filechain **dm;              // pointer to file-sort array
  117.   USHORT   i;                           // counter
  118.   long     start_time,run_time;         // for execution time measurement
  119.  
  120.   start_time = time(NULL);              // system time at start
  121.   sprintf(list_title,"%s%d%d%c",PROGNAME,VERSION,SUBVERS,SUFFIX);
  122.                                         // default title
  123.   get_parm(argc,argv);                  // system and oper. parameters
  124.                                         // and display welcome msg
  125.   area_count = collect_down(&area);     // build arrays with area-info
  126.  
  127.   file_count = collect_file(area_count,area);  // collect all file info
  128.  
  129.   if (file_count == 0) {                // no files
  130.     printf("\nNot a single file found in any download directory, or");
  131.     printf("\nno download paths found at all, %s terminated\n",PROGNAME);
  132.     exit(10);
  133.     }
  134.  
  135.   dm = prep_sort(file_count,first_element); // make sort array
  136.  
  137.   make_orp(dm);                         // Orphan report
  138.  
  139.   if (lp[P_BBS].priv[0] <= HIDDEN)      // BBS-list
  140.     make_bbs(dm,lp[P_BBS].max_fil,lp[P_BBS].priv[0]);
  141.  
  142.   for (i=0; i<10 && lp[P_NEW].priv[i] <= HIDDEN; i++) // NEW-list(s)
  143.     make_new(dm,lp[P_NEW].max_fil,lp[P_NEW].priv[i]);
  144.  
  145.   for (i=0; i<10 && lp[P_GBL].priv[i] <= HIDDEN; i++) // GBL-list(s)
  146.     make_gbl(dm,lp[P_GBL].priv[i]);
  147.  
  148.   for (i=0; i<10 && lp[P_ALL].priv[i] <= HIDDEN; i++) // ALL-list(s)
  149.     make_all(dm,area,lp[P_ALL].priv[i]);
  150.  
  151.   if (lp[P_FIL].priv[0] <= HIDDEN)      // FILES.BBS
  152.     make_fil(dm,lp[P_FIL].priv[0]);
  153.  
  154.   if (oper_mode != QUIET)
  155.     printf("\n\n%s version %d.%d%c by %s ",
  156.              PROGNAME,VERSION,SUBVERS,SUFFIX,AUTHOR);
  157.   run_time = time(NULL) - start_time;   // execution time in seconds
  158.   printf("completed in %ld minutes and %ld seconds.\n\n",
  159.           run_time/60,run_time%60);     // report execution time
  160.  
  161.   return(0);                            // OS will release all storage!
  162.   }
  163.  
  164.