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

  1. /*---------------------------------------------------------------------------*/
  2. /*                                                                           */
  3. /* Module Name:   AMAXFREQ.C                                                 */
  4. /* Program Name:  AMAX                                                       */
  5. /* Revision:      2.xx                                                       */
  6. /* Purpose:       File Request Generator 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 <io.h>
  30. #include <time.h>
  31. #include <sys\stat.h>
  32. #include "amax.h"
  33.  
  34. extern int daylight;
  35. extern long timezone;
  36. extern char series[80];
  37.  
  38.  
  39. void freq(char, int, int, char *);
  40.  
  41. void freq(char courtesy, int from_net, int from_node, char *sysop)
  42. {
  43.     FILE *stream;
  44.  
  45.     unsigned char sysopname[50] = "Sysop";
  46.     unsigned char info[70] = "";
  47.     unsigned char system[50] = "";
  48.     unsigned char name[90] = "";
  49.     unsigned char password[20] = "";
  50.     unsigned char first[20] = "";
  51.     unsigned char hexname[20] = "";
  52.     unsigned char out[100] = "";
  53.     unsigned char text[20][85];
  54.     unsigned char pass[60] = "";
  55.     unsigned char msgpath[100] = "";
  56.     unsigned char alt[100] = "";
  57.     unsigned char line[100] = "";
  58.     unsigned char eolarea[3] = "";
  59.     unsigned char input[50] = "";
  60.     unsigned char tempfile[13] = "";
  61.     unsigned char update[25] = "";
  62.     unsigned char update_file[90] = "";
  63.     unsigned char drive[MAXDRIVE];
  64.     unsigned char dir[MAXDIR];
  65.     unsigned char file[MAXFILE];
  66.     unsigned char ext[MAXEXT];
  67.     char ch = 0x00;
  68.     char append_msg = 0;
  69.     char typeupd = 0;
  70.     char ret = 0;
  71.  
  72.     int to_net;
  73.     int to_node;
  74.     int counter = 0;
  75.     int thiscount = 0;
  76.     int x;
  77.     int y;
  78.     int flag;
  79.     int done;
  80.  
  81.     struct ffblk ffblk;
  82.     struct stat finfo;
  83.  
  84.     long outtime;
  85.     long timenow;
  86.     long filesize;
  87.  
  88.     for (x = 0; x < 20; x++) {
  89.         text[x][0] = 0x00;
  90.     }
  91.  
  92.     do {
  93.  
  94.     cls();
  95.     output("$1AMAX $4Request a File$0");
  96.     cursor(2, 0);
  97.  
  98.     input[0] = 0x00;
  99.  
  100.     output("Destination System     <net/node> ");
  101.     vpanel(45);
  102.     getln(input, 45);
  103.  
  104.     strcpy(system, input);
  105.  
  106.     counter = 0;
  107.  
  108.     if (strlen(system) == 0) return;
  109.  
  110.     if (strchr(system, '/') == NULL) {
  111.         strcpy(system, findaddress(input));
  112.         if (strlen(system) == 0) {
  113.             output("\r\nExpected a Sysop name or node address in the form NET/NODE...press a key...");
  114.             agetch();
  115.             return;
  116.         }
  117.         strcpy(sysopname, input);
  118.     }
  119.  
  120.     strcpy(hexname, parseaddress(system));
  121.  
  122.     to_net = extractnet(hexname);
  123.     to_node = extractnode(hexname);
  124.  
  125.     strcpy(info, lookinfo(to_net, to_node, 0));
  126.     sprintf(out, "   Looks Like: %s\r\n\r\n", info);
  127.     if (usenl) output(out);
  128.  
  129.     strcpy(pass, outbound);
  130.     strcat(pass, hexname);
  131.     strcat(pass, ".REQ");
  132.  
  133.  
  134.     if (! findfirst(pass, &ffblk, 0)) {
  135.         if (! strlen(series)) {
  136.             cursor(5, 0);
  137.             output("File requests are pending for this system.  Display?  $1Y$0)es  $1N$0)o  ");
  138.             ch = menu_select("YN\x1B\x0D");
  139.             if (ch == 0x1B) return;
  140.             if (ch == 'Y') {
  141.                 aputch(ch);
  142.                 stream = fopen(pass, "rb");
  143.                 if (stream != NULL) {
  144.                     counter = list_contents(stream, 7, 3);
  145.                     fclose(stream);
  146.                     output("\r\nPress any key to continue...");
  147.                     agetch();
  148.                 }
  149.             }
  150.         }
  151.         stream = fopen(pass, "rb");
  152.         if (stream != NULL) {
  153.             while (! feof(stream)) {
  154.                 fgetln(line, sizeof(line), eolarea, stream);
  155.                 ++counter;
  156.             }
  157.             --counter;
  158.             fclose(stream);
  159.         }
  160.     }
  161.  
  162.     bottomcls(5);
  163.     cursor(5, 0);
  164.     output("Files Requested = ");
  165.  
  166.  
  167.  
  168.     do {
  169.  
  170.         cursor(5, 18);
  171.         sprintf(line, "%d", counter);
  172.         output(line);
  173.         bottomcls(7);
  174.  
  175.         cursor(5, 25);
  176.         output("For update request, specify drive and path.");
  177.  
  178.         cursor(7, 0);
  179.  
  180.         output("File Desired           <filename> \r\n  ");
  181.         name[0] = 0x00;
  182.         vpanel(75);
  183.         getln(name, 75);
  184.         if (strlen(name) < 1) break;
  185.         flag = fnsplit(name, drive, dir, file, ext);
  186.         update[0] = 0x00;
  187.         if ((flag & DRIVE) && (flag & DIRECTORY)) {
  188.             typeupd = 1;
  189.             done = findfirst(name, &ffblk, 0);
  190.             if (done) {
  191.                 output("Cannot update non-existent file, ");
  192.                 pressanykey();
  193.                 continue;
  194.             }
  195.             stat(name, &finfo);
  196.             outtime = finfo.st_atime;
  197.             filesize = finfo.st_size;
  198.             output("Update Request Mode.  Do you want files that are:  N)ewer  O)lder  ");
  199.             output("\r\n");
  200.             ch = menu_select("NO\r\x1B");
  201.             if (ch == 0x1B) return;
  202.             if (ch == 'N' || ch == '\r') sprintf(update, " +%ld", outtime);
  203.             else sprintf(update, " -%ld", outtime);
  204.             strcpy(name, file);
  205.             strcat(name, ext);
  206.             strcpy(update_file, outbound);
  207.             strcat(update_file, "updates.req");
  208.             stream = fopen(update_file, "a+");
  209.             if (stream != NULL) {
  210.                 time(&timenow);
  211.                 fprintf(stream, "%s %s%s%s %d:%d/%d %ld %ld %ld\n", name, drive, dir, update, our_zone, net, node, outtime, filesize, timenow);
  212.                 fclose(stream);
  213.             }
  214.         }
  215.         output("Password (if any)      <password> ");
  216.         first[0] = 0x00;
  217.         vpanel(15);
  218.         getln(first, 15);
  219.         strcpy(password, "!");
  220.         strcat(password, first);
  221.  
  222.         output("\r\n");
  223.  
  224.  
  225.         if (findfirst(pass, &ffblk, 0) != 0) output("Creating new file request...\r\n");
  226.         else output("Appending existing file request...\r\n");
  227.  
  228.         stream = fopen(pass, "a+b");
  229.         if (stream == NULL) {
  230.             cursor(12, 0);
  231.             output("Cannot open .REQ file.  Press any key...");
  232.             agetch();
  233.             return;
  234.         }
  235.  
  236.  
  237.         strcpy(out, name);
  238.  
  239.         for (x = 0; x < strlen(name); x++) {
  240.             if (name[x] == ' ') break;
  241.         }
  242.         name[x] = 0x00;
  243.  
  244.         flag = 0;
  245.         for (y = x + 1; y < strlen(out); y++) {
  246.             out[flag] = out[y];
  247.             ++flag;
  248.         }
  249.         out[flag] = 0x00;
  250.  
  251.         fprintf(stream, "%s", name);
  252.         if (strlen(first) > 0) fprintf(stream, " %s", password);
  253.         if (strlen(out) > 0) fprintf(stream, " %s", out);
  254.         if (strlen(update) > 0) fprintf(stream, "%s", update);
  255.         fprintf(stream, "%c%c", 0x0D, 0x0A);
  256.  
  257.         ++counter;
  258.         ++thiscount;
  259.         if (thiscount < 18) sprintf(text[thiscount + 1], "File %d - %s\r\n", thiscount, name);
  260.  
  261.         fclose(stream);
  262.  
  263.     } while (strlen(name) > 0);
  264.  
  265.         if (courtesy) {
  266.  
  267.             output("Generating courtesy message packet...\r\n");
  268.  
  269.             strcpy(msgpath, outbound);
  270.             strcat(msgpath, hexname);
  271.             strcat(msgpath, ".OUT");
  272.  
  273.             tmpnam(tempfile);
  274.  
  275.             strcpy(alt, outbound);
  276.             strcat(alt, tempfile);
  277.  
  278.             if (! typeupd) sprintf(text[0], "File request generated by AMAX Version %s\r\n", VERSION);
  279.             else sprintf(text[0], "File update request generated by AMAX Version %s\r\n", VERSION);
  280.  
  281.             sprintf(text[1], "\r\n");
  282.  
  283.             if (findfirst(msgpath, &ffblk, 0) != 0) append_msg = 0;
  284.             else append_msg = 1;
  285.  
  286.             strcpy(name, "Files Listed Below");
  287.  
  288.             if (thiscount < 17) {
  289.                 strcat(text[thiscount + 1], "\r\n");
  290.             }
  291.             else {
  292.                 strcat(text[18], "\r\n");
  293.                 thiscount = 18;
  294.             }
  295.  
  296.             if (append_msg) {
  297.                 save_msg(alt, from_node, extractnode(hexname), from_net,
  298.                         extractnet(hexname), text, sysopname, sysop, name,
  299.                         thiscount + 2, 2049, "amaxfreq.txt");
  300.                 append_packet(alt, msgpath);
  301.             }
  302.  
  303.             else {
  304.                 save_msg(msgpath, from_node, extractnode(hexname), from_net,
  305.                         extractnet(hexname), text, sysopname, sysop, name,
  306.                         thiscount + 2, 2049, "amaxfreq.txt");
  307.             }
  308.         }
  309.  
  310.  
  311.     output("\r\n\r\nPress ENTER to return to Main Menu, any other key to enter more requests... ");
  312.     ret = agetch();
  313. } while (ret != 0x0D);
  314.  
  315. return;
  316.  
  317. }
  318.