home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*/
- /* */
- /* Module Name: AMAXMISC.C */
- /* Program Name: AMAX */
- /* Revision: 2.xx */
- /* Purpose: Miscellaneous Routines Module */
- /* Programmer: Alan D. Bryant */
- /* */
- /* Copyright (C) 1988, 89, 90, 92 Alan D. Bryant, All Rights Reserved. */
- /* */
- /* NOTICE: This source code is copyrighted material. You are granted a */
- /* limited license to use and distribute the code. The complete text of */
- /* the license can be found in the document LICENSE.DOC which accompanies */
- /* this source code, or can be obtained directly from the author. */
- /* */
- /* Inquiries regarding this package should be directed to: */
- /* */
- /* AMAX */
- /* Alan D. Bryant */
- /* P. O. Box 101612 */
- /* Denver, CO 80250 */
- /* USA */
- /* */
- /*---------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <dos.h>
- #include "cbtree.h"
- #include "amax.h"
-
- extern char fullinfo;
-
- char *parseaddress(char *);
- int extractnet(char *);
- int extractnode(char *);
- void pressanykey();
- void clearline();
- void cleareol();
- char *findaddress(char *);
- void display_nl_info();
- char delete_file_ref(int, char*);
- char strfir(char *, char *);
-
- char *parseaddress(char *address)
- {
-
- int x;
- int counter;
- int to_node;
- int to_net;
- int zone;
-
- unsigned char prenet[10];
- unsigned char prenode[10];
- unsigned char prezone[10];
- unsigned char finnet[10];
- unsigned char finnode[10];
- unsigned char returnval[15];
- unsigned char system[30];
-
-
- int colon_offset = 0;
- int point_offset;
-
- strcpy(system, address);
-
- zone = our_zone;
-
- if (! strchr(system, '/')) {
- strcpy(system, findaddress(address));
- if (! strchr(system, '/')) return "00000000";
- }
-
- for (x = 0; x < strlen(system); x++) {
- if(! strchr("0123456789/.:\x00", system[x])) return "00000000";
- }
-
- if (strchr(system, ':')) {
- colon_offset = strlen(system) - strlen(strchr(system, ':'));
- for (x = 0; x < colon_offset; x++) {
- prezone[x] = system[x];
- }
- prezone[x] = NULL;
- zone = atoi(prezone);
- ++colon_offset;
- if (zone != zone_num) newzone(zone);
- }
-
- for (x = colon_offset; x <= strlen(system); x++) {
- if (system[x] == '/') break;
- prenet[x - colon_offset] = system[x];
- }
-
- prenet[x - colon_offset] = NULL;
-
- counter = ++x;
-
- for (x = 0; x <= (strlen(system) - counter); x++) {
- prenode[x] = system[x + counter];
- }
-
- to_net = atoi(prenet);
- to_node = atoi(prenode);
-
- if (to_net < 0 || to_node < 0 || to_net > 32766 || to_node > 32766) return "00000000";
-
- itoa(to_net, prenet, 16);
- itoa(to_node, prenode, 16);
-
- for (x = 0; x < (4 - strlen(prenet)); x++) {
- finnet[x] = '0';
- }
- finnet[x] = 0x00;
- strcat(finnet, prenet);
-
- for (x = 0; x < (4 - strlen(prenode)); x++) {
- finnode[x] = '0';
- }
- finnode[x] = 0x00;
- strcat(finnode, prenode);
-
- strcpy(returnval, finnet);
- strcat(returnval, finnode);
-
- return returnval;
-
- }
-
- int extractnet(char *filename)
- {
- int x;
- unsigned int final;
-
- unsigned char hex[15];
- unsigned char to_net[10];
-
- strcpy(hex, filename);
-
- for (x = 0; x < 4; x++) {
- to_net[x] = hex[x];
- }
-
- to_net[x] = 0x00;
-
- sscanf(to_net, "%x", &final);
-
- return final;
- }
-
-
- int extractnode(char *filename)
- {
- int x;
- unsigned int final;
-
- unsigned char hex[15];
- unsigned char to_node[10];
-
- strcpy(hex, filename);
-
- for (x = 0; x < 4; x++) {
- to_node[x] = hex[x + 4];
- }
-
- to_node[x] = 0x00;
-
- sscanf(to_node, "%x", &final);
-
- return final;
- }
-
-
- void pressanykey()
- {
- output("press any key...");
- agetch();
- }
-
- void clearline()
- {
- if (! direct) output("\r\x1B[K");
- else {
- output("\r");
- clreol();
- }
- }
-
- void cleareol()
- {
- if (! direct) output("\x1B[K");
- else {
- clreol();
- }
- }
-
-
- void display_nl_info()
- {
- unsigned int x;
- unsigned int y;
- unsigned int a;
- unsigned int b;
- unsigned int c;
- unsigned long seekval;
- int counter;
-
- int address[3];
- char table[50] = " EANROSTILCHBDMUGPKYWFVJXZQ-'0123456789";
-
- char temp[100] = "";
- char input[100] = "";
- char disp[100];
- char retstring[100];
- char ch;
-
- FILE *stream;
-
- struct v7fixed {
- unsigned int zone;
- unsigned int net;
- unsigned int node;
- unsigned int hubnode;
- unsigned int callcost;
- unsigned int msgfee;
- unsigned int nodeflags;
- unsigned char modemtype;
- unsigned char phonelen;
- unsigned char passwordlen;
- unsigned char bnamelen;
- unsigned char snamelen;
- unsigned char cnamelen;
- unsigned char packlen;
- unsigned char baudrate;
- } n;
-
-
- unsigned char system[60] = "";
- unsigned char hexname[15] = "";
- unsigned int to_net;
- unsigned int to_node;
-
-
-
-
- cls();
- output("$1AMAX $4Display Nodelist Record$0");
- cursor(2, 0);
-
- output("Destination System <net/node> ");
- vpanel(45);
- getln(input, 45);
-
- strcpy(system, input);
-
- if (strlen(system) == 0) return;
-
- if (strchr(system, '/') == NULL) {
- strcpy(system, findaddress(input));
- if (strlen(system) == 0) {
- output("\r\nExpected a Sysop name or node address in the form NET/NODE...press a key...");
- agetch();
- return;
- }
- }
-
- strcpy(hexname, parseaddress(system));
-
- to_net = extractnet(hexname);
- to_node = extractnode(hexname);
-
- output("\r\nInformation as found in compiled nodelist...\r\n\r\n");
-
- address[0] = zone_num;
- address[1] = to_net;
- address[2] = to_node;
-
-
- status = cbfind(nodexindex, address, sizeof(address), &item);
- if (status != FOUND && status != NOTFOUND) {
- output("End of nodelist reached. To continue, ");
- pressanykey();
- }
- else {
- while(0x01) {
- fseek(nodexdata, item, SEEK_SET);
- fread(&n, sizeof(n), 1, nodexdata);
-
- sprintf(disp, "System: %d:%d/%d", n.zone, n.net, n.node);
- strcat(disp, "\r\n");
- output(disp);
-
- for (x = 0; x < n.phonelen; x++) {
- ch = fgetc(nodexdata);
- temp[x] = ch;
- }
- temp[x] = 0x00;
-
- strcpy(disp, "Phone: ");
- strcat(disp, temp);
- strcat(disp, "\r\n");
- output(disp);
-
- sprintf(disp, "Baud: %lu\r\n", (unsigned long) n.baudrate * 300);
- output(disp);
-
-
- for (x = 0; x < n.passwordlen; x++) {
- ch = fgetc(nodexdata);
- temp[x] = ch;
- }
- temp[x] = 0x00;
-
- strcpy(disp, "Password: ");
- strcat(disp, temp);
- strcat(disp, "\r\n");
- output(disp);
-
-
- for (x = 0; x < n.packlen && x < 30; x++) {
- a = getw(nodexdata);
- b = a / 40;
- c = a - (b * 40);
- temp[(x * 3) + 2] = (char) table[c];
-
- a = b;
- b = a / 40;
- c = a - (b * 40);
- temp[(x * 3) + 1] = (char) table[c];
-
- a = b;
- b = a / 40;
- c = a - (b * 40);
- temp[(x * 3) + 0] = (char) table[c];
- }
- temp[n.snamelen + n.cnamelen + n.bnamelen] = 0x00;
-
- for (x = 0; x < n.bnamelen; x++) {
- input[x] = temp[x];
- }
- input[x] = 0x00;
-
- strcpy(disp, "Board: ");
- strcat(disp, input);
- strcat(disp, "\r\n");
- output(disp);
-
- strcpy(retstring, input);
-
- for (x = 0; x < n.snamelen; x++) {
- input[x] = temp[x + n.bnamelen];
- }
- input[x] = 0x00;
-
- strcpy(disp, "Sysop: ");
- strcat(disp, input);
- strcat(disp, "\r\n");
- output(disp);
-
-
- for (x = 0; x < n.cnamelen; x++) {
- input[x] = temp[x + n.bnamelen + n.snamelen];
- }
- input[x] = 0x00;
-
-
- strcpy(disp, "Location: ");
- strcat(disp, input);
- strcat(disp, "\r\n");
- output(disp);
-
- cursor(14, 0);
- output("$1Q$0)uit $1P$0)revious Entry $1N$0)ext Entry");
- ch = menu_select("QPN\x1B\r");
- if (ch == 'Q' || ch == 0x1B) return;
- if (ch == 'P') {
- status = cbprev(nodexindex, &item);
- if (status != OK) {
- return;
- }
- }
- if (ch == 'N' || ch == '\r') {
- status = cbnext(nodexindex, &item);
- if (status != OK) {
- return;
- }
- }
- bottomcls(6);
- cursor(6, 0);
- }
- }
- }
-
-
- char delete_file_ref(int line, char *filename)
- {
- char path[100];
- char temppath[100];
- char string[100];
- char eolarea[3];
- int x = 1;
- FILE *stream;
- FILE *stream2;
-
- strcpy(path, outbound);
- strcat(path, filename);
- strcpy(temppath, outbound);
- strcat(temppath, tmpnam(NULL));
-
- stream = fopen(path, "r+b");
- if (stream == NULL) return 0x00;
- stream2 = fopen(temppath, "w+b");
- if (stream2 == NULL) {
- fclose(stream);
- return 0x00;
- }
-
- while(! feof(stream)) {
- fgetln(string, sizeof(string), eolarea, stream);
- if (x != line && strlen(string) != 0) fprintf(stream2, "%s\n", string);
- ++x;
- }
- fclose(stream);
- fclose(stream2);
- unlink(path);
- rename(temppath, path);
- return 0x01;
- }
-
-
- /*------------------------------------------------------------------------*/
- /* strfir */
- /* */
- /* This function makes certain first[0] to strlen(second) characters */
- /* of first match, with case sensitivity. A space MUST be encountered */
- /* somewhere during the match in first, or a false is returned. True */
- /* is returned on a match, false on no match. */
- /*------------------------------------------------------------------------*/
-
-
- char strfir(char *first, char *second)
- {
- int x;
- char flag = 0;
-
- for (x = 0; x < strlen(second); x++) {
- if (first[x] != second[x]) return 0;
- if (first[x + 1] == ' ') flag = 1;
- }
- if (flag) return 1;
- else return 0;
- }
-
- // This routine returns a node address in string form (1:104/36)
- // after performing a lookup for the name. If not found, or if
- // other errors occur, it returns a null string.
- // This routine has been corrected for V7 support.
-
-
- char *findaddress(char *input)
- {
- int status;
- unsigned int x;
- unsigned int y;
- unsigned int a;
- unsigned int b;
- unsigned int c;
- unsigned long seekval;
- int counter;
- char temp[100] = "";
- char name[100] = "";
- char firstname[50];
- char lastname[50];
- unsigned char ch;
- // char table[50] = " EANROSTILCHBDMUGPKYWFVJXZQ-'0123456789";
-
- struct v7fixed {
- unsigned int zone;
- unsigned int net;
- unsigned int node;
- unsigned int hubnode;
- unsigned int callcost;
- unsigned int msgfee;
- unsigned int nodeflags;
- unsigned char modemtype;
- unsigned char phonelen;
- unsigned char passwordlen;
- unsigned char bnamelen;
- unsigned char snamelen;
- unsigned char cnamelen;
- unsigned char packlen;
- unsigned char baudrate;
- } n;
-
- if (sysopindex == NULL) return "";
-
-
- strcpy(name, input);
- strupr(name);
-
-
- if (strchr(name, '_')) {
- for (x = 0; x < strlen(name); x++) {
- if (name[x] == '_') name[x] = ' ';
- }
- }
-
- strcpy(lastname, strrchr(name, ' ') + 1);
-
- strncpy(firstname, name, strlen(name) - strlen(lastname - 1));
- firstname[strlen(name) - strlen(lastname - 1)] = 0x00;
-
- if (strlen(lastname) == 0) strcpy(name, firstname);
- else {
- strcpy(name, lastname);
- strcat(name, ", ");
- strcat(name, firstname);
- }
-
- status = cbfind(sysopindex, name, strlen(name), &item);
- if (status == FOUND) {
- rewind(nodexdata);
- fseek(nodexdata, item, SEEK_SET);
- fread(&n, sizeof(n), 1, nodexdata);
- }
- else {
- return "";
- }
-
- sprintf(temp, "%d:%d/%d", n.zone, n.net, n.node);
- return temp;
-
- }
-
-
-