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

  1. /*---------------------------------------------------------------------------*/
  2. /*                                                                           */
  3. /* Module Name:   AMAXMISC.C                                                 */
  4. /* Program Name:  AMAX                                                       */
  5. /* Revision:      2.xx                                                       */
  6. /* Purpose:       Miscellaneous Routines 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 <dos.h>
  28. #include "cbtree.h"
  29. #include "amax.h"
  30.  
  31. extern char fullinfo;
  32.  
  33. char *parseaddress(char *);
  34. int extractnet(char *);
  35. int extractnode(char *);
  36. void pressanykey();
  37. void clearline();
  38. void cleareol();
  39. char *findaddress(char *);
  40. void display_nl_info();
  41. char delete_file_ref(int, char*);
  42. char strfir(char *, char *);
  43.  
  44. char *parseaddress(char *address)
  45. {
  46.  
  47.     int x;
  48.     int counter;
  49.     int to_node;
  50.     int to_net;
  51.     int zone;
  52.  
  53.     unsigned char prenet[10];
  54.     unsigned char prenode[10];
  55.     unsigned char prezone[10];
  56.     unsigned char finnet[10];
  57.     unsigned char finnode[10];
  58.     unsigned char returnval[15];
  59.     unsigned char system[30];
  60.  
  61.  
  62.     int colon_offset = 0;
  63.     int point_offset;
  64.  
  65.     strcpy(system, address);
  66.  
  67.     zone = our_zone;
  68.  
  69.     if (! strchr(system, '/')) {
  70.         strcpy(system, findaddress(address));
  71.         if (! strchr(system, '/')) return "00000000";
  72.     }
  73.      
  74.     for (x = 0; x < strlen(system); x++) {
  75.         if(! strchr("0123456789/.:\x00", system[x])) return "00000000";
  76.     }
  77.  
  78.     if (strchr(system, ':')) {
  79.         colon_offset = strlen(system) - strlen(strchr(system, ':'));
  80.         for (x = 0; x < colon_offset; x++) {
  81.             prezone[x] = system[x];
  82.         }
  83.         prezone[x] = NULL;
  84.         zone = atoi(prezone);
  85.         ++colon_offset;
  86.         if (zone != zone_num) newzone(zone);
  87.     }
  88.  
  89.     for (x = colon_offset; x <= strlen(system); x++) {
  90.         if (system[x] == '/') break;
  91.         prenet[x - colon_offset] = system[x];
  92.         }
  93.  
  94.     prenet[x - colon_offset] = NULL;
  95.  
  96.     counter = ++x;
  97.  
  98.     for (x = 0; x <= (strlen(system) - counter); x++) {
  99.         prenode[x] = system[x + counter];
  100.         }
  101.  
  102.     to_net = atoi(prenet);
  103.     to_node = atoi(prenode);
  104.  
  105.     if (to_net < 0 || to_node < 0 || to_net > 32766 || to_node > 32766) return "00000000";
  106.  
  107.     itoa(to_net, prenet, 16);
  108.     itoa(to_node, prenode, 16);
  109.  
  110.     for (x = 0; x < (4 - strlen(prenet)); x++) {
  111.         finnet[x] = '0';
  112.         }
  113.     finnet[x] = 0x00;
  114.     strcat(finnet, prenet);
  115.  
  116.     for (x = 0; x < (4 - strlen(prenode)); x++) {
  117.         finnode[x] = '0';
  118.         }
  119.     finnode[x] = 0x00;
  120.     strcat(finnode, prenode);
  121.  
  122.     strcpy(returnval, finnet);
  123.     strcat(returnval, finnode);
  124.  
  125.     return returnval;
  126.  
  127. }
  128.  
  129. int extractnet(char *filename)
  130. {
  131.     int x;
  132.     unsigned int final;
  133.  
  134.     unsigned char hex[15];
  135.     unsigned char to_net[10];
  136.  
  137.     strcpy(hex, filename);
  138.  
  139.     for (x = 0; x < 4; x++) {
  140.         to_net[x] = hex[x];
  141.         }
  142.  
  143.     to_net[x] = 0x00;
  144.  
  145.     sscanf(to_net, "%x", &final);
  146.  
  147.     return final;
  148. }
  149.  
  150.  
  151. int extractnode(char *filename)
  152. {
  153.     int x;
  154.     unsigned int final;
  155.  
  156.     unsigned char hex[15];
  157.     unsigned char to_node[10];
  158.  
  159.     strcpy(hex, filename);
  160.  
  161.     for (x = 0; x < 4; x++) {
  162.         to_node[x] = hex[x + 4];
  163.         }
  164.  
  165.     to_node[x] = 0x00;
  166.  
  167.     sscanf(to_node, "%x", &final);
  168.  
  169.     return final;
  170. }
  171.  
  172.  
  173. void pressanykey()
  174. {
  175.     output("press any key...");
  176.     agetch();
  177. }
  178.  
  179. void clearline()
  180. {
  181.     if (! direct) output("\r\x1B[K");
  182.     else {
  183.         output("\r");
  184.         clreol();
  185.         }
  186. }
  187.  
  188. void cleareol()
  189. {
  190.     if (! direct) output("\x1B[K");
  191.     else {
  192.         clreol();
  193.     }
  194. }
  195.  
  196.  
  197. void display_nl_info()
  198. {
  199.     unsigned int x;
  200.     unsigned int y;
  201.     unsigned int a;
  202.     unsigned int b;
  203.     unsigned int c;
  204.     unsigned long seekval;
  205.     int counter;
  206.  
  207.     int address[3];
  208.     char table[50] = " EANROSTILCHBDMUGPKYWFVJXZQ-'0123456789";
  209.  
  210.     char temp[100] = "";
  211.     char input[100] = "";
  212.     char disp[100];
  213.     char retstring[100];
  214.     char ch;
  215.  
  216.     FILE *stream;
  217.  
  218.     struct v7fixed {
  219.         unsigned int zone;
  220.         unsigned int net;
  221.         unsigned int node;
  222.         unsigned int hubnode;
  223.         unsigned int callcost;
  224.         unsigned int msgfee;
  225.         unsigned int nodeflags;
  226.         unsigned char modemtype;
  227.         unsigned char phonelen;
  228.         unsigned char passwordlen;
  229.         unsigned char bnamelen;
  230.         unsigned char snamelen;
  231.         unsigned char cnamelen;
  232.         unsigned char packlen;
  233.         unsigned char baudrate;
  234.     } n;
  235.  
  236.  
  237.     unsigned char system[60] = "";
  238.     unsigned char hexname[15] = "";
  239.     unsigned int to_net;
  240.     unsigned int to_node;
  241.  
  242.  
  243.  
  244.  
  245.     cls();
  246.     output("$1AMAX $4Display Nodelist Record$0");
  247.     cursor(2, 0);
  248.  
  249.     output("Destination System     <net/node> ");
  250.     vpanel(45);
  251.     getln(input, 45);
  252.  
  253.     strcpy(system, input);
  254.  
  255.     if (strlen(system) == 0) return;
  256.  
  257.     if (strchr(system, '/') == NULL) {
  258.         strcpy(system, findaddress(input));
  259.         if (strlen(system) == 0) {
  260.             output("\r\nExpected a Sysop name or node address in the form NET/NODE...press a key...");
  261.             agetch();
  262.             return;
  263.         }
  264.     }
  265.  
  266.     strcpy(hexname, parseaddress(system));
  267.  
  268.     to_net = extractnet(hexname);
  269.     to_node = extractnode(hexname);
  270.  
  271.     output("\r\nInformation as found in compiled nodelist...\r\n\r\n");
  272.  
  273.     address[0] = zone_num;
  274.     address[1] = to_net;
  275.     address[2] = to_node;
  276.  
  277.  
  278.     status = cbfind(nodexindex, address, sizeof(address), &item);
  279.     if (status != FOUND && status != NOTFOUND) {
  280.         output("End of nodelist reached.  To continue, ");
  281.         pressanykey();
  282.     }
  283.     else {
  284.         while(0x01) {
  285.             fseek(nodexdata, item, SEEK_SET);
  286.             fread(&n, sizeof(n), 1, nodexdata);
  287.  
  288.             sprintf(disp, "System:     %d:%d/%d", n.zone, n.net, n.node);
  289.             strcat(disp, "\r\n");
  290.             output(disp);
  291.  
  292.             for (x = 0; x < n.phonelen; x++) {
  293.                 ch = fgetc(nodexdata);
  294.                 temp[x] = ch;
  295.             }
  296.             temp[x] = 0x00;
  297.  
  298.             strcpy(disp, "Phone:      ");
  299.             strcat(disp, temp);
  300.             strcat(disp, "\r\n");
  301.             output(disp);
  302.  
  303.             sprintf(disp, "Baud:       %lu\r\n", (unsigned long) n.baudrate * 300);
  304.             output(disp);
  305.  
  306.  
  307.             for (x = 0; x < n.passwordlen; x++) {
  308.                 ch = fgetc(nodexdata);
  309.                 temp[x] = ch;
  310.             }
  311.             temp[x] = 0x00;
  312.  
  313.             strcpy(disp, "Password:   ");
  314.             strcat(disp, temp);
  315.             strcat(disp, "\r\n");
  316.             output(disp);
  317.  
  318.  
  319.             for (x = 0; x < n.packlen && x < 30; x++) {
  320.                 a = getw(nodexdata);
  321.                 b = a / 40;
  322.                 c = a - (b * 40);
  323.                 temp[(x * 3) + 2] = (char) table[c];
  324.  
  325.                 a = b;
  326.                 b = a / 40;
  327.                 c = a - (b * 40);
  328.                 temp[(x * 3) + 1] = (char) table[c];
  329.  
  330.                 a = b;
  331.                 b = a / 40;
  332.                 c = a - (b * 40);
  333.                 temp[(x * 3) + 0] = (char) table[c];
  334.             }
  335.             temp[n.snamelen + n.cnamelen + n.bnamelen] = 0x00;
  336.  
  337.             for (x = 0; x < n.bnamelen; x++) {
  338.                 input[x] = temp[x];
  339.             }
  340.             input[x] = 0x00;
  341.  
  342.             strcpy(disp, "Board:      ");
  343.             strcat(disp, input);
  344.             strcat(disp, "\r\n");
  345.             output(disp);
  346.  
  347.             strcpy(retstring, input);
  348.  
  349.             for (x = 0; x < n.snamelen; x++) {
  350.                 input[x] = temp[x + n.bnamelen];
  351.             }
  352.             input[x] = 0x00;
  353.  
  354.             strcpy(disp, "Sysop:      ");
  355.             strcat(disp, input);
  356.             strcat(disp, "\r\n");
  357.             output(disp);
  358.  
  359.  
  360.             for (x = 0; x < n.cnamelen; x++) {
  361.                 input[x] = temp[x + n.bnamelen + n.snamelen];
  362.             }
  363.             input[x] = 0x00;
  364.  
  365.  
  366.             strcpy(disp, "Location:   ");
  367.             strcat(disp, input);
  368.             strcat(disp, "\r\n");
  369.             output(disp);
  370.  
  371.             cursor(14, 0);
  372.             output("$1Q$0)uit   $1P$0)revious Entry   $1N$0)ext Entry");
  373.             ch = menu_select("QPN\x1B\r");
  374.             if (ch == 'Q' || ch == 0x1B) return;
  375.             if (ch == 'P') {
  376.                 status = cbprev(nodexindex, &item);
  377.                 if (status != OK) {
  378.                     return;
  379.                 }
  380.             }
  381.             if (ch == 'N' || ch == '\r') {
  382.                 status = cbnext(nodexindex, &item);
  383.                 if (status != OK) {
  384.                     return;
  385.                 }
  386.             }
  387.             bottomcls(6);
  388.             cursor(6, 0);
  389.         }
  390.     }
  391. }
  392.  
  393.  
  394. char delete_file_ref(int line, char *filename)
  395. {
  396.     char path[100];
  397.     char temppath[100];
  398.     char string[100];
  399.     char eolarea[3];
  400.     int x = 1;
  401.     FILE *stream;
  402.     FILE *stream2;
  403.  
  404.     strcpy(path, outbound);
  405.     strcat(path, filename);
  406.     strcpy(temppath, outbound);
  407.     strcat(temppath, tmpnam(NULL));
  408.  
  409.     stream = fopen(path, "r+b");
  410.     if (stream == NULL) return 0x00;
  411.     stream2 = fopen(temppath, "w+b");
  412.     if (stream2 == NULL) {
  413.         fclose(stream);
  414.         return 0x00;
  415.     }
  416.  
  417.     while(! feof(stream)) {
  418.         fgetln(string, sizeof(string), eolarea, stream);
  419.         if (x != line && strlen(string) != 0) fprintf(stream2, "%s\n", string);
  420.         ++x;
  421.     }
  422.     fclose(stream);
  423.     fclose(stream2);
  424.     unlink(path);
  425.     rename(temppath, path);
  426.     return 0x01;
  427. }
  428.  
  429.  
  430. /*------------------------------------------------------------------------*/
  431. /*  strfir                                                                */
  432. /*                                                                        */
  433. /*  This function makes certain first[0] to strlen(second) characters     */
  434. /*  of first match, with case sensitivity.  A space MUST be encountered   */
  435. /*  somewhere during the match in first, or a false is returned.  True    */
  436. /*  is returned on a match, false on no match.                            */
  437. /*------------------------------------------------------------------------*/
  438.  
  439.  
  440. char strfir(char *first, char *second)
  441. {
  442.     int x;
  443.     char flag = 0;
  444.  
  445.     for (x = 0; x < strlen(second); x++) {
  446.         if (first[x] != second[x]) return 0;
  447.         if (first[x + 1] == ' ') flag = 1;
  448.     }
  449.     if (flag) return 1;
  450.     else return 0;
  451. }
  452.  
  453. // This routine returns a node address in string form (1:104/36)
  454. // after performing a lookup for the name.  If not found, or if
  455. // other errors occur, it returns a null string.
  456. // This routine has been corrected for V7 support.
  457.  
  458.  
  459. char *findaddress(char *input)
  460. {
  461.     int status;
  462.     unsigned int x;
  463.     unsigned int y;
  464.     unsigned int a;
  465.     unsigned int b;
  466.     unsigned int c;
  467.     unsigned long seekval;
  468.     int counter;
  469.     char temp[100] = "";
  470.     char name[100] = "";
  471.     char firstname[50];
  472.     char lastname[50];
  473.     unsigned char ch;
  474. //    char table[50] = " EANROSTILCHBDMUGPKYWFVJXZQ-'0123456789";
  475.  
  476.     struct v7fixed {
  477.         unsigned int zone;
  478.         unsigned int net;
  479.         unsigned int node;
  480.         unsigned int hubnode;
  481.         unsigned int callcost;
  482.         unsigned int msgfee;
  483.         unsigned int nodeflags;
  484.         unsigned char modemtype;
  485.         unsigned char phonelen;
  486.         unsigned char passwordlen;
  487.         unsigned char bnamelen;
  488.         unsigned char snamelen;
  489.         unsigned char cnamelen;
  490.         unsigned char packlen;
  491.         unsigned char baudrate;
  492.     } n;
  493.  
  494.     if (sysopindex == NULL) return "";
  495.  
  496.  
  497.     strcpy(name, input);
  498.     strupr(name);
  499.  
  500.  
  501.     if (strchr(name, '_')) {
  502.         for (x = 0; x < strlen(name); x++) {
  503.             if (name[x] == '_') name[x] = ' ';
  504.         }
  505.     }
  506.  
  507.     strcpy(lastname, strrchr(name, ' ') + 1);
  508.  
  509.     strncpy(firstname, name, strlen(name) - strlen(lastname - 1));
  510.     firstname[strlen(name) - strlen(lastname - 1)] = 0x00;
  511.  
  512.     if (strlen(lastname) == 0) strcpy(name, firstname);
  513.     else {
  514.         strcpy(name, lastname);
  515.         strcat(name, ", ");
  516.         strcat(name, firstname);
  517.     }
  518.  
  519.     status = cbfind(sysopindex, name, strlen(name), &item);
  520.     if (status == FOUND) {
  521.         rewind(nodexdata);
  522.         fseek(nodexdata, item, SEEK_SET);
  523.         fread(&n, sizeof(n), 1, nodexdata);
  524.     }
  525.     else {
  526.         return "";
  527.     }
  528.  
  529.     sprintf(temp, "%d:%d/%d", n.zone, n.net, n.node);
  530.     return temp;
  531.  
  532. }
  533.  
  534.  
  535.