home *** CD-ROM | disk | FTP | other *** search
/ synchro.net / synchro.net.tar / synchro.net / modem.madness / SMMNETML / AMAX_230.ZIP / SOURCES.ZIP / AMAXCHEK.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-15  |  36.1 KB  |  1,224 lines

  1. /*---------------------------------------------------------------------------*/
  2. /*                                                                           */
  3. /* Module Name:   AMAXCHEK.C                                                 */
  4. /* Program Name:  AMAX                                                       */
  5. /* Revision:      2.xx                                                       */
  6. /* Purpose:       Outbound Area Examine / Edit Module                        */
  7. /* Programmer:    Alan D. Bryant                                             */
  8. /*                                                                           */
  9. /* Copyright (C) 1988, 89, 90, 92 Alan D. Bryant, All Rights Reserved.       */
  10. /*                                                                           */
  11. /* NOTICE:  This source code is copyrighted material.  You are granted a     */
  12. /* limited license to use and distribute the code.  The complete text of     */
  13. /* the license can be found in the document LICENSE.DOC which accompanies    */
  14. /* this source code, or can be obtained directly from the author.            */
  15. /*                                                                           */
  16. /* Inquiries regarding this package should be directed to:                   */
  17. /*                                                                           */
  18. /*     AMAX                                                                  */
  19. /*     Alan D. Bryant                                                        */
  20. /*     P. O. Box 101612                                                      */
  21. /*     Denver, CO  80250                                                     */
  22. /*     USA                                                                   */
  23. /*                                                                           */
  24. /*---------------------------------------------------------------------------*/
  25.  
  26. #include <stdio.h>
  27. #include <dir.h>
  28. #include <dos.h>
  29. #include <ctype.h>
  30. #include <sys\stat.h>
  31. #include <string.h>
  32. #include "amax.h"
  33.  
  34. /*  function declarations  */
  35.  
  36. int chek(unsigned int, unsigned int, char, char *, char, int);
  37. void display_section(struct list_style  *, int, int);
  38. char delete_entry(struct list_style  *, int);
  39. char flavor_change(struct list_style *, int);
  40. char reroute(struct list_style  *, int);
  41. char append_packet(char *, char *);
  42. char append_attach(char *, char *);
  43. char *return_type_file(int);
  44. char *return_type_flavor(int);
  45. void print_header();
  46.  
  47. int compare_items_address(struct list_style *, struct list_style *);
  48. int compare_items_type(struct list_style *, struct list_style *);
  49. int compare_items_flavor(struct list_style *, struct list_style *);
  50.  
  51. char *get_fext(char *, char *);
  52.  
  53. extern char displzero;
  54.  
  55. int chek(unsigned int our_net, unsigned int our_node, char ARCmail, char *outbound, char sortmode, int location)
  56. {
  57.     FILE *stream;
  58.  
  59.     /*  integer declarations  */
  60.  
  61.     int done = 0;               /* used for findfirst function */
  62.     unsigned int to_net = 0;                /* used to temporarily store net number */
  63.     unsigned int to_node = 0;               /* used to temporarily store node number */
  64.     int number_of_items = 0;    /* number of items counted  */
  65.     int eligible_items = 0;     /* number of items we can process  */
  66.     int x = 0;                  /* general incrementing counter */
  67.     int entry_number = 0;       /* used in entry selection process  */
  68.     int start_place = 1;
  69.     int page_num = 1;
  70.     int total_pages = 1;
  71.  
  72.     /*  char declarations  */
  73.  
  74.     char open[100];
  75.     char search[60] = "";       /* search string */
  76.     char string[80] = "";       /* general purpose string  */
  77.     char filename[13] = "";     /* takes name of file when found  */
  78.     char hexname[10] = "";      /* gets first eight digits of filename  */
  79.     char stamp[10] = "";        /* first few chars of archive  */
  80.     char fext[5] = "";          /* filename extension storage  */
  81.     char ch;                    /* general purpose char  */
  82.     char result;                /* used for function return values  */
  83.     char t;
  84.     char f;
  85.     static char display_limit = 0;     /* used for limited displays  */
  86.     char disin;
  87.  
  88.     /*  struct declarations  */
  89.  
  90.     struct list_style  *list;    /* primary pointer to allocated memory  */
  91.     struct list_style  *offset;  /* secondary pointer, may be indexed  */
  92.     struct ffblk ffblk;         /* used with findfirst() and findnext ()  */
  93.  
  94.     /*  output screen for user  */
  95.  
  96.     cls();
  97.     output("$1AMAX $4View/Edit Outbound Area$0\r\n\r\n");
  98.  
  99.     output("AMAX: Reading outbound area...\r");
  100.  
  101.     /*  setup and count all items in outbound area  */
  102.  
  103.     strcpy(search, outbound);
  104.     strcat(search, "*.*");
  105.  
  106.     done = findfirst(search, &ffblk, 0);
  107.  
  108.     while (! done) {
  109.         ++number_of_items;
  110.         done = findnext(&ffblk);
  111.         }
  112.  
  113.     /*  number_of_items is the number of files in outbound area  */
  114.  
  115.     if (number_of_items == 0) {
  116.         output("Your outbound holding area seems to be empty...");
  117.         pressanykey();
  118.         return 0x00;
  119.         }
  120.  
  121.     /*  allocate contiguous memory block for structure times files  */
  122.  
  123.     list = (struct list_style  *) malloc(number_of_items * sizeof(struct list_style));
  124.     offset = list;
  125.  
  126.     /*  not enough memory  */
  127.  
  128.     if (list == NULL) {
  129.         output("Insufficient memory to Examine/Edit Outbound Area...");
  130.         pressanykey();
  131.         return 0x00;
  132.         }
  133.  
  134.  
  135.     /*  The following section of code scans the outbound holding area,   */
  136.     /*  attempting to make some sort of half-assed guess at what might   */
  137.     /*  be hiding there.  The routine is not intelligent in the least    */
  138.     /*  since it depends entirely on the assumption that only net files  */
  139.     /*  that are known to Opus and/or BinkleyTerm will be there.         */
  140.     /*  A strong chance exists that if someone tries to break AMAX       */
  141.     /*  by placing other crap in the outbound area that they will        */
  142.     /*  succeed in their efforts.  All the information found is placed   */
  143.     /*  in the allocated memory in a structure of type list_style.       */
  144.     /*                                                                   */
  145.     /*  Here are the codes used for file and flavor types:               */
  146.     /*                                                                   */
  147.     /*  File Types                      Flavor Types                     */
  148.     /*  ----------------------          --------------------             */
  149.     /*  1 - Packet                      0 - N/A                          */
  150.     /*  2 - Attach                      1 - Normal                       */
  151.     /*  3 - Request                     2 - Direct                       */
  152.     /*  4 - Call Progress               3 - Continuous                   */
  153.     /*  5 - ARCmail                     4 - Hold                         */
  154.     /*  6 - Bad WaZOO                   5 - Normal Leave                 */
  155.     /*  7 - ZOOmail (Not Used)          6 - Direct Leave                 */
  156.     /*  8 - Update Req Log              7 - Continuous Leave             */
  157.     /*  9 - LZHmail                     8 - Hold Leave                   */
  158.     /*  A - ZIPmail                     9 - Stray                        */
  159.  
  160.  
  161.     bottomcls(2);
  162.     cursor(2, 0);
  163.  
  164.     done = findfirst(search, &ffblk, 0);
  165.  
  166.     while (! done) {
  167.         strcpy(filename, ffblk.ff_name);
  168.         strupr(filename);
  169.  
  170.         /*  if there are not 8 characters in the base name continue  */
  171.  
  172.         if (strlen(filename) < 10) {
  173.             done = findnext(&ffblk);
  174.             continue;
  175.             }
  176.  
  177.         /*  get (hopefully) the net and node number for the entry  */
  178.  
  179.         strncpy(hexname, filename, 8);
  180.         to_net = extractnet(hexname);
  181.         to_node = extractnode(hexname);
  182.  
  183.         t = 0;
  184.         f = 0;
  185.  
  186.         get_fext(filename, fext);
  187.  
  188.         if (! strcmpi(fext, ".OUT")) {
  189.             t = 1;
  190.             f = 1;
  191.         }
  192.         if (! strcmpi(fext, ".DUT")) {
  193.             t = 1;
  194.             f = 2;
  195.         }
  196.         if (! strcmpi(fext, ".CUT")) {
  197.             t = 1;
  198.             f = 3;
  199.         }
  200.         if (! strcmpi(fext, ".HUT")) {
  201.             t = 1;
  202.             f = 4;
  203.         }
  204.         if (! strcmpi(fext, ".NOT")) {
  205.             t = 1;
  206.             f = 5;
  207.         }
  208.         if (! strcmpi(fext, ".NDT")) {
  209.             t = 1;
  210.             f = 6;
  211.         }
  212.         if (! strcmpi(fext, ".NCT")) {
  213.             t = 1;
  214.             f = 7;
  215.         }
  216.         if (! strcmpi(fext, ".NHT")) {
  217.             t = 1;
  218.             f = 8;
  219.         }
  220.         if (! strcmpi(fext, ".FLO")) {
  221.             t = 2;
  222.             f = 1;
  223.         }
  224.         if (! strcmpi(fext, ".DLO")) {
  225.             t = 2;
  226.             f = 2;
  227.         }
  228.         if (! strcmpi(fext, ".CLO")) {
  229.             t = 2;
  230.             f = 3;
  231.         }
  232.         if (! strcmpi(fext, ".HLO")) {
  233.             t = 2;
  234.             f = 4;
  235.         }
  236.         if (! strcmpi(fext, ".NFO")) {
  237.             t = 2;
  238.             f = 5;
  239.         }
  240.         if (! strcmpi(fext, ".NDO")) {
  241.             t = 2;
  242.             f = 6;
  243.         }
  244.         if (! strcmpi(fext, ".NCO")) {
  245.             t = 2;
  246.             f = 7;
  247.         }
  248.         if (! strcmpi(fext, ".NHO")) {
  249.             t = 2;
  250.             f = 8;
  251.         }
  252.         if (! strcmpi(fext, ".REQ")) {
  253.             t = 3;
  254.             f = 0;
  255.         }
  256.         if (strstr(fext, ".$$")) {
  257.             t = 4;
  258.             f = 0;
  259.         }
  260.         if (! strcmpi(fext, ".Z")) {
  261.             t = 6;
  262.             f = 0;
  263.         }
  264.         if (! strcmpi(fext, ".PKT")) {
  265.             t = 1;
  266.             f = 9;
  267.             to_net = 0;
  268.             to_node = 0;
  269.         }
  270.         if (strstr(fext, ".MO")) {
  271.             t = 5;
  272.             f = 0;
  273.         }
  274.         if (strstr(fext, ".TU")) {
  275.             t = 5;
  276.             f = 0;
  277.         }
  278.         if (strstr(fext, ".WE")) {
  279.             t = 5;
  280.             f = 0;
  281.         }
  282.         if (strstr(fext, ".TH")) {
  283.             t = 5;
  284.             f = 0;
  285.         }
  286.         if (strstr(fext, ".FR")) {
  287.             t = 5;
  288.             f = 0;
  289.         }
  290.         if (strstr(fext, ".SA")) {
  291.             t = 5;
  292.             f = 0;
  293.         }
  294.         if (strstr(fext, ".SU")) {
  295.             t = 5;
  296.             f = 0;
  297.         }
  298.         if (strstr(filename, "UPDATE")) {
  299.             t = 8;
  300.             f = 0;
  301.             to_net = 0;
  302.             to_node = 0;
  303.         }
  304.  
  305.         if (display_limit) {
  306.             if (t == 1 && (display_limit & 1)) t = 0;
  307.             if (t == 2 && (display_limit & 2)) t = 0;
  308.             if (t == 3 && (display_limit & 4)) t = 0;
  309.             if (t == 4 && (display_limit & 8)) t = 0;
  310.             if (t == 5 && (display_limit & 16)) t = 0;
  311.             if (t == 6 && (display_limit & 32)) t = 0;
  312.         }
  313.  
  314.  
  315.         if (t == 5) {
  316.             if (ffblk.ff_fsize > 0L) {
  317.                 strcpy(open, outbound);
  318.                 strcat(open, ffblk.ff_name);
  319.                 stream = fopen(open, "rb");
  320.                 if (stream == NULL) {
  321.                     t = 0;
  322.                 }
  323.                 else {
  324.                     for (x = 0; x < 8; x++) {
  325.                         stamp[x] = fgetc(stream);
  326.                     }
  327.                     fclose(stream);
  328.                     t = 0;
  329.                     if (stamp[2] == '-' && stamp[3] == 'l' && stamp[4] == 'h') t = 9;
  330.                     if (stamp[0] == 'Z') {
  331.                         if (t == 0) t = 7;
  332.                     }
  333.                     if (stamp[0] == 0x1A) {
  334.                         if (t == 0) t = 5;
  335.                     }
  336.                     if (stamp[0] == 'P' && stamp[1] == 'K') {
  337.                         if (t == 0) t = 0x0A;
  338.                     }
  339.                 }
  340.             }
  341.             to_net = our_net - to_net;
  342.             to_node = our_node - to_node;
  343.  
  344.             if (! ARCmail) t = 0;
  345.             if (! displzero && ffblk.ff_fsize == 0L) t = 0;
  346.         }
  347.  
  348.         if (t != 0) {
  349.             offset -> type_file = t;
  350.             offset -> type_flavor = f;
  351.             offset -> net = to_net;
  352.             offset -> node = to_node;
  353.             strcpy(offset -> filename, ffblk.ff_name);
  354.             ++offset;
  355.             ++eligible_items;
  356.             done = findnext(&ffblk);
  357.             continue;
  358.         }
  359.  
  360.         done = findnext(&ffblk);
  361.  
  362.         /*  if we don't find what it is, then it'll continue  */
  363.  
  364.     }  /* end of while loop  */
  365.  
  366.         /*  In this section, we'll display the items in the outbound area   */
  367.         /*  in blocks of 16 items.  A menu is displayed, and the user can   */
  368.         /*  select what he wants to do, and to what entry.                  */
  369.  
  370.         if (eligible_items == 0) {
  371.             output("The outbound area appears to be empty right now...");
  372.             pressanykey();
  373.             display_limit = 0;
  374.             return 0x00;
  375.         }
  376.  
  377.         sortmode = toupper(sortmode);
  378.         if (strchr("ATFN", sortmode)) ch = sortmode;
  379.         else {
  380.             outputi("Sort:  $1A$0)ddress  $1T$0)ype  $1F$0)lavor  $1N$0)one");
  381.             ch = menu_select("ATFN\r\x1B");
  382.         }
  383.  
  384.         switch(ch) {
  385.             case '\x1B':
  386.                 return 0x00;
  387.             case 'N':
  388.                 break;
  389.             case 'A':
  390.             case '\r':
  391.                 qsort(list, eligible_items, sizeof(struct list_style), compare_items_address);
  392.                 break;
  393.             case 'T':
  394.                 qsort(list, eligible_items, sizeof(struct list_style), compare_items_type);
  395.                 break;
  396.             case 'F':
  397.                 qsort(list, eligible_items, sizeof(struct list_style), compare_items_flavor);
  398.                 break;
  399.         }
  400.  
  401.  
  402.  
  403.  
  404.  
  405.  
  406.         print_header();
  407.  
  408.         start_place = (location - 1) * 16;
  409.         if (start_place >= eligible_items) start_place = start_place - 16;
  410.  
  411.         for (x = start_place; x <= eligible_items; x += 16) {
  412.             if (x >= eligible_items) return 0x00;
  413. /*            display_section(list, eligible_items, x);  */
  414.  
  415.             cursor(0, 29);
  416.             page_num = (x / 16) + 1;
  417.             total_pages = eligible_items / 16;
  418.             if (eligible_items % 16) ++total_pages;
  419.             sprintf(string, "$0Page %d of %d", page_num, total_pages);
  420.             output(string);
  421.  
  422.             cursor(4, 0);
  423.             display_section(list, eligible_items, x);
  424.  
  425.             cursor(22, 0);
  426.             output("$1D$0)elete  $1R$0)eroute  $1F$0)lavor  $1M$0)ore  $1L$0)imit  $1C$0)ontinue  $1P$0)revious  $1Q$0)uit ");
  427.             ch = menu_select("DRFMCQPL\x1B\x1E\x1F\r");
  428.  
  429.             /*  process the choice made  */
  430.  
  431.             switch (ch) {
  432.                 case 'd':
  433.                 case 'D':
  434.                     entry_number = select_entry(list, eligible_items, x);
  435.                     result = delete_entry(list, entry_number);
  436.                     if (result) {       /*  if an entry is deleted, then  */
  437.                         free(list);     /*  we'll start over with the     */
  438.                         return page_num;    /*  read since info has changed   */
  439.                     }
  440.                     else {
  441.                         x = x - 16;     /*  if a delete operation is not  */
  442.                         bottomcls(4);   /*  successful, simply re-display */
  443.                         cursor(4, 0);   /*  the current page of info      */
  444.                         break;
  445.                     }
  446.                 case 'L':
  447.                     disin = 0x00;
  448.                     while (disin != '\r') {
  449.                         bottomcls(4);
  450.                         cursor(4, 0);
  451.                         outputi("\r\nLimit display of items marked below:\r\n\r\n");
  452.                         outputi("    0 - Don't Limit Display\r\n");
  453.                         if (display_limit & 1) output("*");
  454.                         else output(" ");
  455.                         outputi("   1 - Packets\r\n");
  456.                         if (display_limit & 2) output("*");
  457.                         else output(" ");
  458.                         outputi("   2 - Attaches\r\n");
  459.                         if (display_limit & 4) output("*");
  460.                         else output(" ");
  461.                         outputi("   3 - Requests\r\n");
  462.                         if (display_limit & 8) output("*");
  463.                         else output(" ");
  464.                         outputi("   4 - Call Progress Files\r\n");
  465.                         if (display_limit & 16) output("*");
  466.                         else output(" ");
  467.                         outputi("   5 - Compressed Mail (Must be Enabled)\r\n");
  468.                         if (display_limit & 32) output("*");
  469.                         else output(" ");
  470.                         outputi("   6 - Bad WaZOO Files\r\n");
  471.                         disin = agetch();
  472.                         if (disin == '0') {
  473.                             display_limit = 0;
  474.                             disin = '\r';
  475.                         }
  476.                         if (disin == '1') display_limit = display_limit ^ 1;
  477.                         if (disin == '2') display_limit = display_limit ^ 2;
  478.                         if (disin == '3') display_limit = display_limit ^ 4;
  479.                         if (disin == '4') display_limit = display_limit ^ 8;
  480.                         if (disin == '5') display_limit = display_limit ^ 16;
  481.                         if (disin == '6') display_limit = display_limit ^ 32;
  482.                     }
  483.                     free(list);
  484.                     return page_num;
  485.  
  486. #if FULLVERSION
  487.                 case 'r':
  488.                 case 'R':
  489.                     entry_number = select_entry(list, eligible_items, x);
  490.                     result = reroute(list, entry_number);
  491.                     if (result) {       /*  if a reroute operation is     */
  492.                         free(list);     /*  successful, then start over   */
  493.                         return page_num;    /*  from the beginning            */
  494.                     }
  495.                     else {
  496.                         x = x - 16;     /*  if a reroute operation is not */
  497.                         bottomcls(4);   /*  successful, or if it's a      */
  498.                         cursor(4, 0);   /*  simple rename, re-display the */
  499.                         break;          /*  current page                  */
  500.                     }
  501.  
  502.  
  503.                 case 'f':
  504.                 case 'F':
  505.                     entry_number = select_entry(list, eligible_items, x);
  506.                     result = flavor_change(list, entry_number);
  507.                     if (result) {
  508.                         free(list);
  509.                         return page_num;
  510.                     }
  511.                     else {
  512.                         x = x - 16;
  513.                         bottomcls(4);
  514.                         cursor(4, 0);
  515.                         break;
  516.                     }
  517.  
  518. #endif
  519.  
  520.                 case 'm':
  521.                 case 'M':
  522.                     result = moreinfo(list, eligible_items, x);
  523.                     if (result) {
  524.                         free(list);
  525.                         return page_num;
  526.                     }
  527.                     else {
  528.                         x = x - 16;
  529.                         bottomcls(4);        /*  redisplay the current page   */
  530.                         cursor(4, 0);        /*  when completed               */
  531.                         break;
  532.                     }
  533.                 case 'c':
  534.                 case 'C':
  535.                 case 0x1F:
  536.                 case 0x0D:
  537.                     bottomcls(4);
  538.                     cursor(4, 0);
  539.                     break;
  540.                 case 'q':
  541.                 case 'Q':
  542.                 case 0x1B:
  543.                     free(list);
  544.                     return 0x00;
  545.                 case 'p':
  546.                 case 'P':
  547.                 case 0x1E:
  548.                     if (x == 0) x = x - 16;
  549.                     else x = x - 32;
  550.                     bottomcls(4);
  551.                     cursor(4, 0);
  552.                     break;
  553.                 }  /* end switch */
  554.             }  /* end for loop  */
  555.  
  556. /*  free allocated memory and return  */
  557.  
  558. free(list);
  559. return 0x00;
  560. }  /*  end of main  */
  561.  
  562.  
  563.  
  564. void display_section(struct list_style  *list, int eligible_items, int offset)
  565. {
  566.     int x = 0;
  567.     int count = 1;
  568.     struct list_style  *p;
  569.     char info[60];
  570.     char type[15];
  571.     char flav[25];
  572.     char out[100];
  573.     char address[20];
  574.     char color = 1;
  575.  
  576.     if (offset >= eligible_items) return;
  577.     x = offset;
  578.  
  579.     for (p = list + offset; x <= eligible_items; p++) {
  580.         ++x;
  581.         strcpy(info, (char *) lookinfo(p -> net, p -> node, 0));
  582.         if (p -> type_file == 8) strcpy(info, "Update Request Log");
  583.         if (p -> type_flavor == 9) strcpy(info, "Stray Packet");
  584.         strcpy(type, (char *) return_type_file(p -> type_file));
  585.         strcpy(flav, (char *) return_type_flavor(p -> type_flavor));
  586.         sprintf(address, "%d:%d/%d", zone_num, p -> net, p -> node);
  587.         if (p -> net == 0 && p -> node == 0) sprintf(address, "");
  588.         switch(p -> type_file) {
  589.             case 1:
  590.                 color = 1;
  591.                 break;
  592.             case 2:
  593.                 color = 3;
  594.                 break;
  595.             case 3:
  596.                 color = 5;
  597.                 break;
  598.             case 4:
  599.                 color = 7;
  600.                 break;
  601.             case 5:
  602.             case 7:
  603.             case 9:
  604.             case 0x0A:
  605.                 color = 2;
  606.                 break;
  607.             case 6:
  608.                 color = 8;
  609.                 break;
  610.             default:
  611.                 color = 0;
  612.                 break;
  613.         }
  614.         if (usenl) sprintf(out, "$%d%03d %-13s %-32.32s %-10s %-14.14s\r\n", color, x, address, info, type, flav);
  615.         else sprintf(out, "$%d%03d %-13s %-10s %-14.14s\r\n", color, x, address, type, flav);
  616.         outputi(out);
  617.         ++count;
  618.         if (count % 17 == 0 || x == eligible_items) return;
  619.     }
  620. }
  621.  
  622.  
  623.  
  624. char delete_entry(struct list_style *list, int entry_number)
  625. {
  626.     FILE *stream;
  627.     FILE *stream2;
  628.  
  629.     char out[100] = "";
  630.     char open[100] = "";
  631.     char line[80] = "";
  632.     char eolarea[3];
  633.     char ch = 0x00;
  634.  
  635.     int x = 0;
  636.  
  637.     struct list_style *p;
  638.  
  639.     p = list + entry_number;
  640.  
  641.     if (entry_number == -1) return 0;
  642.  
  643.     output("Delete this entry? ");
  644.     ch = menu_select("YN");
  645.     aputch(ch);
  646.     if (ch == 'N') return 0;
  647.     output("  Are you sure? ");
  648.     ch = menu_select("YN");
  649.     aputch(ch);
  650.     if (ch == 'N') return 0;
  651.  
  652.     strcpy(open, outbound);
  653.     strcat(open, p -> filename);
  654.  
  655.     if (p -> type_file == 2) {
  656.         stream = fopen(open, "rb");
  657.         while (! feof(stream)) {
  658.             fgetln(line, sizeof(line), eolarea, stream);
  659.             if (line[0] == '#') {
  660.                 for (x = 0; x < strlen(line); x++) {
  661.                     line[x] = line[x + 1];
  662.                 }
  663.                 sprintf(out, "\r\nTruncate %s? ", line);
  664.                 output(out);
  665.                 ch = menu_select("YN");
  666.                 aputch(ch);
  667.                 if (ch == 'Y') {
  668.                     output("  Are you sure? ");
  669.                     ch = menu_select("YN");
  670.                     aputch(ch);
  671.                     if (ch == 'Y') {
  672.                         stream2 = fopen(line, "wb");
  673.                         fclose(stream2);
  674.                     }
  675.                 }
  676.             }
  677.             if (line[0] == '^') {
  678.                 for (x = 0; x < strlen(line); x++) {
  679.                     line[x] = line [x + 1];
  680.                 }
  681.                 sprintf(out, "\r\nDelete %s? ", line);
  682.                 output(out);
  683.                 ch = menu_select("YN");
  684.                 aputch(ch);
  685.                 if (ch == 'Y') {
  686.                     output("  Are you sure? ");
  687.                     ch = menu_select("YN");
  688.                     aputch(ch);
  689.                     if (ch == 'Y') {
  690.                         unlink(line);
  691.                     }
  692.                 }
  693.             }
  694.         }
  695.         fclose(stream);
  696.     }
  697.     unlink(open);
  698.     return 1;
  699. }
  700.  
  701.  
  702. char *return_type_file(int typenumber)
  703. {
  704.     switch (typenumber) {
  705.         case 1:
  706.             return "Packet";
  707.         case 2:
  708.             return "Attach";
  709.         case 3:
  710.             return "Request";
  711.         case 4:
  712.             return "Progress";
  713.         case 5:
  714.             return "ARCmail";
  715.         case 6:
  716.             return "Bad WaZOO";
  717.         case 7:
  718.             return "ZOOmail";
  719.         case 8:
  720.             return "Upd Reqs";
  721.         case 9:
  722.             return "LZHmail";
  723.         case 0x0A:
  724.             return "ZIPmail";
  725.         }
  726.     return "";
  727. }
  728.  
  729.  
  730.  
  731. char *return_type_flavor(int flavornumber)
  732. {
  733.     switch (flavornumber) {
  734.         case 0:
  735.             return " ";
  736.         case 1:
  737.             return "Normal";
  738.         case 2:
  739.             return "Direct";
  740.         case 3:
  741.             return "Continuous";
  742.         case 4:
  743.             return "Hold";
  744.         case 5:
  745.             return "Leave Normal";
  746.         case 6:
  747.             return "Leave Direct";
  748.         case 7:
  749.             return "Leave Continuous";
  750.         case 8:
  751.             return "Leave Hold";
  752.         case 9:
  753.             return "Stray";
  754.         }
  755.     return "";
  756. }
  757.  
  758.  
  759. #if FULLVERSION
  760.  
  761. char reroute(struct list_style  *list, int entry_number)
  762. {
  763.     char out[100] = "";
  764.     char compare[100] = "";
  765.     char newpath[80] = "";
  766.     char oldpath[80] = "";
  767.     char lookup[70] = "";
  768.     char address[50] = "";
  769.     char hexname[12] = "";
  770.     char filename[13] = "";
  771.     char input[50] = "";
  772.     char ch = 0x00;
  773.     char result = 0x00;
  774.     char ending[5] = "";
  775.  
  776.     int x = 0;
  777.     int zorig;
  778.  
  779.     struct list_style  *p;
  780.     struct ffblk ffblk;
  781.  
  782.     zorig = zone_num;
  783.  
  784.     if (entry_number == -1) return 0;
  785.  
  786.     p = list;
  787.  
  788.     p = p + entry_number;
  789.  
  790.     strcpy(oldpath, outbound);
  791.     strcat(oldpath, p -> filename);
  792.     strcpy(newpath, oldpath);
  793.  
  794.  
  795.     if (p -> type_file > 2) {
  796.         output("\r\nCannot reroute this type of file...");
  797.         pressanykey();
  798.         return 0;
  799.     }
  800.  
  801.     output("Reroute this entry? ");
  802.  
  803.     ch = menu_select("YN");
  804.     aputch(ch);
  805.  
  806.     if (ch == 'N')  return 0;
  807.  
  808.     output("\r\n\r\n");
  809.  
  810.     if (p -> type_flavor == 9) {
  811.         strcpy(newpath, outbound);
  812.         strcat(newpath, "00000000.OUT");
  813.         rename(oldpath, newpath);
  814.         strcpy(oldpath, newpath);
  815.     }
  816.  
  817.  
  818.     strcpy(compare, outbound);
  819.  
  820.     output("Reroute this to where (who)? ");
  821.     vpanel(45);
  822.     getln(input, 45);
  823.  
  824.     strcpy(address, input);
  825.  
  826.     if (strlen(address) == 0) return 0;
  827.  
  828.     if (strchr(address, '/') == NULL) {
  829.         strcpy(address, (char *) findaddress(input));
  830.         if (strlen(address) == 0) {
  831.             output("\r\nExpected a Sysop name or node address in the form NET/NODE...press a key...");
  832.             agetch();
  833.             return 0;
  834.         }
  835.     }
  836.  
  837.     strcpy(hexname, (char *) parseaddress(address));
  838.     if (strlen(address) == 0) return 0;
  839.     if (! strcmpi(compare, outbound)) {
  840.         if (p -> net == extractnet(hexname) && p -> node == extractnode(hexname)) {
  841.             output("\r\nWhy reroute this to its current destination?\r\n");
  842.             output("Press any key...  ");
  843.             agetch();
  844.             return 0;
  845.         }
  846.     }
  847.     strcpy(lookup, (char *) lookinfo(extractnet(hexname), extractnode(hexname), 0));
  848.     sprintf(out, "Looks like: %s  Reroute? ", lookup);
  849.     output(out);
  850.     ch = menu_select("YN");
  851.     aputch(ch);
  852.     if (ch == 'N') {
  853.         newzone(zorig);
  854.         return 0;
  855.     }
  856.  
  857.     strcpy(newpath, outbound);
  858.     strcat(newpath, hexname);
  859.  
  860.     for (x = 0; x < 5; x++ ) {
  861.         ending[x] = oldpath[(strlen(oldpath) - 4) + x];
  862.     }
  863.     ending[x] = 0x00;
  864.  
  865.     strcat(newpath, ending);
  866.  
  867.  
  868.     /*  packet  */
  869.     /*  packet append  */
  870.  
  871.     if (p -> type_file == 1 && !findfirst(newpath, &ffblk, 0)) {
  872.         result = append_packet(oldpath, newpath);
  873.         if (result == 0) return 0;
  874.         else {
  875.             newzone(zorig);
  876.             return 1;
  877.         }
  878.     }
  879.  
  880.     /*  packet rename  */
  881.  
  882.     if (p -> type_file == 1) {
  883.         rename(oldpath, newpath);
  884.         for (x = 0; x < 12; x++) {
  885.             filename[x] = newpath[strlen(newpath) - 12 + x];
  886.         }
  887.         filename[12] = 0x00;
  888.  
  889.         p -> net = extractnet(hexname);
  890.         p -> node = extractnode(hexname);
  891.         strcpy(p -> filename, filename);
  892.         newzone(zorig);
  893.         return 1;
  894.     }
  895.  
  896.     /*  attach  */
  897.     /*  attach append  */
  898.  
  899.     if (p -> type_file == 2 && !findfirst(newpath, &ffblk, 0)) {
  900.         result = append_attach(oldpath, newpath);
  901.         if (result == 0) return 0;
  902.         else {
  903.             newzone(zorig);
  904.             return 1;
  905.         }
  906.     }
  907.  
  908.     /* attach rename  */
  909.  
  910.     if (p -> type_file == 2) {
  911.         rename(oldpath, newpath);
  912.         for (x = 0; x < 12; x++) {
  913.             filename[x] = newpath[strlen(newpath) - 12 + x];
  914.         }
  915.         filename[12] = 0x00;
  916.  
  917.         p -> net = extractnet(hexname);
  918.         p -> node = extractnode(hexname);
  919.         strcpy(p -> filename, filename);
  920.         newzone(zorig);
  921.         return 1;
  922.     }
  923. return 0;
  924.  
  925.  
  926. }
  927.  
  928.  
  929.  
  930. #endif
  931.  
  932.  
  933.  
  934. #include <io.h>
  935.  
  936. char append_packet(char *source_file, char *destin_file)
  937. {
  938.     FILE *stream;
  939.     FILE *stream2;
  940.     FILE *stream3;
  941.  
  942.     char ch = 0x00;
  943.     char tempfile[13];
  944.     char open[100];
  945.     int x;
  946.     long position;
  947.     long size;
  948.  
  949.  
  950.     if (! stricmp(source_file, destin_file)) return 0;
  951.  
  952.     tmpnam(tempfile);
  953.     strcpy(open, outbound);
  954.     strcat(open, tempfile);
  955.  
  956.     stream = fopen(source_file, "rb");
  957.     if (stream == NULL) return 0;
  958.  
  959.     stream2 = fopen(destin_file, "rb");
  960.     if (stream2 == NULL) {
  961.         fclose(stream);
  962.         return 0;
  963.     }
  964.  
  965.     stream3 = fopen(open, "wb");
  966.     if (stream3 == NULL) {
  967.         fclose(stream);
  968.         fclose(stream2);
  969.         return 0;
  970.     }
  971.  
  972.  
  973.     /*  transfer header of destin file to temp  */
  974.  
  975.     for (x = 0; x < 58; x++) {
  976.         ch = getc(stream);
  977.         ch = getc(stream2);
  978.         putc(ch, stream3);
  979.     }
  980.  
  981.     while (! feof(stream2)) {
  982.         ch = getc(stream2);
  983.         if (ch == 0x00) {
  984.             if (filelength(fileno(stream2)) - ftell(stream2) > (long) 5) putc(ch, stream3);
  985.         }
  986.         else putc(ch, stream3);
  987.     }
  988.  
  989.     putc(0x00, stream3);
  990.  
  991.     while (! feof(stream)) {
  992.         ch = getc(stream);
  993.         putc(ch, stream3);
  994.     }
  995.  
  996.     fclose(stream);
  997.     fclose(stream2);
  998.     fclose(stream3);
  999.  
  1000.     unlink(source_file);
  1001.     unlink(destin_file);
  1002.     rename(open, destin_file);
  1003.  
  1004.     return 1;
  1005. }
  1006.  
  1007.  
  1008. char append_attach(char *source_file, char *destin_file)
  1009. {
  1010.     FILE *stream;
  1011.     FILE *stream2;
  1012.  
  1013.     char line[100];
  1014.     char eolarea[3];
  1015.  
  1016.     /*  check and see if the source and destination are the same  */
  1017.     /*  and if so, abort the operation and return                 */
  1018.  
  1019.     if (! stricmp(source_file, destin_file)) return 0;
  1020.  
  1021.     /*  open files  */
  1022.  
  1023.  
  1024.     stream = fopen(source_file, "rb");
  1025.  
  1026.     if (stream == NULL) {
  1027.         return 0;
  1028.     }
  1029.  
  1030.     stream2 = fopen(destin_file, "r+b");
  1031.  
  1032.     if (stream2 == NULL) {
  1033.         fclose(stream);
  1034.         return 0;
  1035.     }
  1036.  
  1037.     fseek(stream2, 0L, SEEK_END);
  1038.  
  1039.     while (! feof(stream)) {
  1040.         fgetln(line, sizeof(line), eolarea, stream);
  1041.         fprintf(stream2, "%s", line);
  1042.         fprintf(stream2, "%c", 0x0A);
  1043.     }
  1044.  
  1045.     fclose(stream);
  1046.     fclose(stream2);
  1047.     unlink(source_file);
  1048.     return 1;
  1049.  
  1050. }
  1051.  
  1052.  
  1053. #if FULLVERSION
  1054.  
  1055. char flavor_change(struct list_style *list, int entry_number)
  1056. {
  1057.     char ch = 0x00;
  1058.  
  1059.     char oldname[100] = "";
  1060.     char newname[100] = "";
  1061.  
  1062.     int result;
  1063.  
  1064.     struct list_style *p;
  1065.  
  1066.     p = list + entry_number;
  1067.  
  1068.     if (entry_number == -1) return 0;
  1069.  
  1070.     if (p -> type_flavor == 0 || p -> type_file > 2 || p -> type_flavor == 9) {
  1071.         output("Cannot change flavor of this entry...");
  1072.         pressanykey();
  1073.         return 0;
  1074.     }
  1075.  
  1076.     output("Change flavor of this entry? ");
  1077.     ch = menu_select("YN");
  1078.     aputch(ch);
  1079.     if (ch == 'N') return 0;
  1080.  
  1081.     output("\r\n\r\nFlavor:  $1N$0)ormal  $1D$0)irect  $1C$0)ontinuous  $1H$0)old  $1A$0)bort  ");
  1082.     ch = menu_select("NDCHA\x1B");
  1083.  
  1084.     if (ch == 'A' || ch == 0x1B) return 0;
  1085.  
  1086.     strcpy(oldname, outbound);
  1087.     strcat(oldname, p -> filename);
  1088.  
  1089.     strcpy(newname, oldname);
  1090.  
  1091.     switch (ch) {
  1092.         case 'N':
  1093.             if (p -> type_file == 1) {
  1094.                 if (p -> type_flavor > 4) newname[strlen(newname) - 2] = 'O';
  1095.                 else newname[strlen(newname) - 3] = 'O';
  1096.             }
  1097.             else {
  1098.                 if (p -> type_flavor > 4) newname[strlen(newname) - 2] = 'F';
  1099.                 else newname[strlen(newname) - 3] = 'F';
  1100.             }
  1101.             output("Normal");
  1102.             break;
  1103.         case 'D':
  1104.             if (p -> type_flavor > 4) newname[strlen(newname) - 2] = 'D';
  1105.             else newname[strlen(newname) - 3] = 'D';
  1106.             output("Direct");
  1107.             break;
  1108.         case 'C':
  1109.             if (p -> type_flavor > 4) newname[strlen(newname) - 2] = 'C';
  1110.             else newname[strlen(newname) - 3] = 'C';
  1111.             output("Continuous");
  1112.             break;
  1113.         case 'H':
  1114.             if (p -> type_flavor > 4) newname[strlen(newname) - 2] = 'H';
  1115.             else newname[strlen(newname) - 3] = 'H';
  1116.             output("Hold");
  1117.             break;
  1118.     }
  1119.  
  1120.     result = rename(oldname, newname);
  1121.  
  1122.     if (! result) {
  1123.         output("\r\n\r\nFlavor changed...");
  1124.         pressanykey();
  1125.         return 1;
  1126.     }
  1127.  
  1128.     if (p -> type_file == 1) {
  1129.         if (append_packet(oldname, newname)) {
  1130.             output("\r\n\r\nAppended packet to existing packet of same type.  ");
  1131.         }
  1132.         else {
  1133.             output("\r\n\r\nPacket is already designated flavor!  ");
  1134.         }
  1135.     }
  1136.     else {
  1137.         if (append_attach(oldname, newname)) {
  1138.             output("\r\n\r\nAppended attach to existing attach of same type.  ");
  1139.         }
  1140.         else {
  1141.             output("\r\n\r\nAttach is already designated flavor!  ");
  1142.         }
  1143.     }
  1144.  
  1145.     output("Press any key... ");
  1146.     agetch();
  1147.  
  1148.     return 1;
  1149.  
  1150. }
  1151.  
  1152.  
  1153. #endif
  1154.  
  1155. void print_header()
  1156. {
  1157.         /*  output header  */
  1158.  
  1159.         cursor(2, 0);
  1160.  
  1161.         if (usenl) {
  1162.             output("No  Zone:Net/Node System Name and Location         Type       Flavor\r\n");
  1163.             output("--- ------------- -------------------------------- ---------- --------------$0\r\n");
  1164.         }               
  1165.  
  1166.         if (! usenl) {
  1167.             output("No  Zone:Net/Node Type       Flavor        \r\n");
  1168.             output("--- ------------- ---------- --------------\r\n");
  1169.         }
  1170.  
  1171.  
  1172.  
  1173.  
  1174. }
  1175.  
  1176.  
  1177. int compare_items_address(struct list_style *x, struct list_style *y)
  1178. {
  1179.     if (x -> net > y -> net) return 1;
  1180.     if (x -> net < y -> net) return -1;
  1181.     if (x -> node > y -> node) return 1;
  1182.     if (x -> node < y -> node) return -1;
  1183.     if (x -> type_file > y -> type_file) return 1;
  1184.     if (x -> type_file < y -> type_file) return -1;
  1185.     if (x -> type_flavor > y -> type_flavor) return 1;
  1186.     if (x -> type_flavor < y -> type_flavor) return -1;
  1187.     return 0;
  1188. }
  1189.  
  1190. int compare_items_type(struct list_style *x, struct list_style *y)
  1191. {
  1192.     if (x -> type_file > y -> type_file) return 1;
  1193.     if (x -> type_file < y -> type_file) return -1;
  1194.     if (x -> type_flavor > y -> type_flavor) return 1;
  1195.     if (x -> type_flavor < y -> type_flavor) return -1;
  1196.     if (x -> net > y -> net) return 1;
  1197.     if (x -> net < y -> net) return -1;
  1198.     if (x -> node > y -> node) return 1;
  1199.     if (x -> node < y -> node) return -1;
  1200.     return 0;
  1201. }
  1202.  
  1203.  
  1204. int compare_items_flavor(struct list_style *x, struct list_style *y)
  1205. {
  1206.     if (x -> type_flavor > y -> type_flavor) return 1;
  1207.     if (x -> type_flavor < y -> type_flavor) return -1;
  1208.     if (x -> type_file > y -> type_file) return 1;
  1209.     if (x -> type_file < y -> type_file) return -1;
  1210.     if (x -> net > y -> net) return 1;
  1211.     if (x -> net < y -> net) return -1;
  1212.     if (x -> node > y -> node) return 1;
  1213.     if (x -> node < y -> node) return -1;
  1214.     return 0;
  1215. }
  1216.  
  1217. char *get_fext(char *filename, char *fileext)
  1218. {
  1219.     fnsplit(filename, NULL, NULL, NULL, fileext);
  1220.  
  1221.     return "";
  1222. }
  1223.  
  1224.