home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*/
- /* */
- /* Module Name: AMAXQMSG.C */
- /* Program Name: AMAX */
- /* Revision: 2.xx */
- /* Purpose: Quick Message Entry Module */
- /* Programmer: Alan Bryant */
- /* Programmer: Charles Frnka */
- /* */
- /* Copyright (C) 1988, 89, 90, 92 Alan D. Bryant, All Rights Reserved. */
- /* Portions Copyright (C) 1988, 89 Charles Frnka, 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 <time.h>
- #include <dir.h>
- #include "amax.h"
-
- extern char tearline;
- extern unsigned char sysname[100];
-
- void qmsg(int, int, char *, char, char *, char *);
- char save_msg(char *, int, int, int, int, char [20][85], char *, char *, char *, int, int, char *, char);
- // char *find_sysop(char *);
- void get_date(char *);
-
- /* char type is 0 if called from the menu, 1 if called from the bomber */
- /* char *list is a pointer to the name of the list file for bomber calls */
- /* char *key is the keyname in the list for bomber calls */
-
-
-
- void qmsg(int from_net, int from_node, char *name, char type, char *list, char *key)
- {
- struct tm *tm_now;
- long secs_now;
- char *str_now;
- struct ffblk ffblk;
-
- FILE *stream;
-
- char ch = 0;
- char exists = 0;
- char route_type = 0;
- char to[36] = "";
- char from[36] = "";
- char subject[72] = "";
- char nodestring[50] = "";
- char text[20][85];
- char string[100] = "";
- char hexname[20] = "";
- char info[70] = "";
- char oldpart[80] = "";
- char newpart[80] = "";
- char pick = 0x00;
- char inter[80] = "";
- char fileopen[100] = "";
- char destination[100] = "";
- char line[100] = "";
- char part[40] = "";
- char eolarea[3] = "";
- char out[100] = "";
- char suffix[5] = "";
- char entry[5] = "";
- char textfile[100] = "";
- char drive[MAXDRIVE];
- char dir[MAXDIR];
- char filefoo[MAXFILE];
- char ext[MAXEXT];
- char beep = 0;
-
- int x = 0;
- int y = 0;
- int start = 0;
- int offset = 0;
- int done;
- int to_net = 0;
- int to_node = 0;
- int attrib = 0;
- int flag;
- int maxlen;
-
-
- strcpy(from, name);
- for (x = 0; x < 20; x++) {
- text[x][0] = 0x00;
- }
- if (type == 0) {
- cls();
- output("$1AMAX $4Enter a Message Directly to Outbound Area$0");
- cursor(2, 0);
- }
- else {
- minicls();
- cursor(2, 0);
- }
- output("Message TO: ");
- vpanel(35);
- getln(to, 35);
- if (strlen(to) == 0) return;
- strcpy(nodestring, findaddress(to));
- output("Message FROM: ");
- vpanel(35);
- getln(from, 35);
- if (strlen(from) == 0) return;
- if (type == 0) {
- output("Node Address TO: ");
- vpanel(20);
- getln(nodestring, 20);
- if (strchr(nodestring, '/') == NULL) {
- output("\r\nSystem node address must be in the format NET/NODE...");
- pressanykey();
- return;
- }
- strcpy(hexname, parseaddress(nodestring));
- to_net = extractnet(hexname);
- to_node = extractnode(hexname);
- strcpy(info, lookinfo(to_net, to_node, 0));
- sprintf(string, " %s\r\n", info);
- output(string);
-
- strcpy(string, to);
- strupr(string);
-
- strcpy(fileopen, nodelist);
- strcat(fileopen, "fidouser.lst");
-
- done = findfirst(fileopen, &ffblk, 0);
-
-
- /*
- if (((strstr(string, "SYSOP") || strlen(to) < 2)) && ! done) {
- output("Want to locate SYSOP name? ");
- ch = agetch();
- if (ch == 'Y' || ch == 'y') {
- output("Y Searching...");
- strcpy(line, (char *) find_sysop(nodestring));
- if (line) {
- output("\r\nWill send message to ");
- output(line);
- output(" - send? ");
- ch = agetch();
- if (ch == 'Y' || ch == 'y') ch = 0x01;
- else ch = 0x00;
- if (ch) {
- strcpy(to, line);
- cursor(2, 18);
- vpanel(35);
- output("$6");
- output(to);
- output("$0");
- } /* end if ch */
- } /* end if line */
- } /* end want to locate */
- } /* end if we should locate */
- */
-
- }
-
- ch = 0x00;
- bottomcls(6);
- cursor(6, 0);
- output("$1P$0)rivate $1F$0)ile Attached ");
- while (ch != 0x0D) {
- ch = agetch();
- if (ch > 90) ch = ch - 32;
- if (ch == 'P') {
- attrib = attrib ^ 1;
- cursor(6, 0);
- if (attrib & 1) output ("$1P$0)RIVATE ");
- else output("$1P$0)rivate ");
- cursor(6, 26);
- }
- if (ch == 'F') {
- attrib = attrib ^ 16;
- cursor(6, 10);
- if (attrib & 16) {
- output("$1F$0)ILE ATTACHED ");
- }
- else {
- output("$1F$0)ile Attached ");
- }
- cursor(6, 26);
- }
- }
- cursor(7, 0);
- if (attrib & 16) output("Filename: ");
- else output("Subject: ");
- vpanel(50);
- getln(subject, 50);
- if (strlen(subject) == 0) return;
- if (attrib & 16) {
- done = findfirst(subject, &ffblk, 0);
- if (done) {
- output("File cannot be located...");
- pressanykey();
- return;
- }
- flag = fnsplit(subject, drive, dir, filefoo, ext);
- if (! (flag & DRIVE) || ! (flag & DIRECTORY)) {
- output("You MUST enter a complete filespec including drive and directory.\r\n");
- output("To return, ");
- pressanykey();
- return;
- }
- }
- ch = 0x00;
- output("\r\n\r\nUse text file for bottom portion of message text? $1Y$0)es $1N$0)o ");
- ch = menu_select("YN\x1B\x0D");
- if (ch == 0x1B) return;
- stream = NULL;
- if (ch == 'Y') {
- aputch(ch);
- output("\r\n");
- while (stream == NULL) {
- textfile[0] = 0x00;
- cursor(10, 0);
- clearline();
- output("Name of text file to use? ");
- vpanel(40);
- getln(textfile, 40);
- if (strlen(textfile) == 0) return;
- stream = fopen(textfile, "rb");
- }
- fclose(stream);
- }
-
- bottomcls(2);
-
- while(pick == 0x00) {
- for (x = start; x < 20; x++) {
- if (x > 14 && x < 19) {
- cursor(22, 0);
- /*!!!! if (x > 18) printf("\a"); */
- sprintf(out, "Including this one, only %d lines left!", 20 - x);
- output(out);
- }
- if (x == 19) {
- cursor(22, 0);
- /*!!! printf("\a"); */
- sprintf(out, "This is your last line. For longer messages, use text file option.");
- output(out);
- }
- cursor(x + 2, 0);
- sprintf(string, "%02d > ", x);
- output(string);
- vpanel(70);
- getln(text[x], 570);
- scolor(7);
- cursor(x + 2, 0);
- if (direct) clreol();
- else output("\x1B[0K");
- cursor(x + 2, 0);
- sprintf(out, "%02d > %s", x, text[x]);
- output(out);
- if (strlen(text[x]) == 0) break;
- }
- if (x == 20) {
- cursor(22, 0);
- clearline();
- if (! beep) {
- beep = 1;
- }
- sprintf(out, "END OF ALLOWABLE TEXT! For longer messages, use text file option.");
- output(out);
- sleep(2);
- while (kbhit()) {
- agetch();
- }
- }
- start = x;
- cursor(22, 0);
- clearline();
- output("$1E$0)dit $1S$0)ave $1A$0)bort $1I$0)nsert $1D$0)elete $1C$0)ontinue ");
- pick = menu_select("ESIDAC\x1B");
-
- switch (pick) {
- case 'I':
- case 'i':
- cursor(22, 0);
- clearline();
- output("Insert AFTER which line? ");
- vpanel(2);
- entry[0] = 0x00;
- getln(entry, 2);
- for (x = 0; x < strlen(entry); x++) {
- if (entry[x] < 48 || entry[x] > 57) {
- cursor(22, 0);
- clearline();
- output("Invalid entry...");
- break;
- }
- }
- ch = atoi(entry);
- if (ch > 19 || ch > (start - 1)) {
- cursor(22, 0);
- clearline();
- output("Invalid entry...");
- break;
- }
- for (x = 19; x >= ch; --x) {
- strcpy(text[x+1], text[x]);
- }
- text[ch+1][0] = 0x00;
- ++start;
- for (x = 0; x <= start; x++) {
- cursor(x + 2, 0);
- if (direct) clreol();
- else output("\x1B[0K");
- sprintf(string, "%02d > %s", x, text[x]);
- output(string);
- }
- clearline();
- cursor(ch + 3, 0);
- sprintf(string, "%02d > ", ch+1);
- output(string);
- vpanel(70);
- getln(text[ch+1], 570);
- scolor(7);
- cursor(ch + 3, 0);
- if (direct) clreol();
- else output("\x1B[0K");
- cursor(ch + 3, 0);
- sprintf(out, "%02d > %s", ch+1, text[ch+1]);
- output(out);
- break;
- case 'D':
- case 'd':
- cursor(22, 0);
- clearline();
- output("Delete which line? ");
- vpanel(2);
- entry[0] = 0x00;
- getln(entry, 2);
- for (x = 0; x < strlen(entry); x++) {
- if (entry[x] < 48 || entry[x] > 57) {
- cursor(22, 0);
- clearline();
- output("Invalid entry...");
- break;
- }
- }
- ch = atoi(entry);
- if (ch >= start) break;
- for (x = ch; x < 20; x++) {
- strcpy(text[x], text[x+1]);
- }
- text[20][0] = 0x00;
- --start;
- if (start < 0) start = 0;
- for (x = 0; x <= start; x++) {
- cursor(x + 2, 0);
- if (direct) clreol();
- else output("\x1B[0K");
- sprintf(string, "%02d > %s", x, text[x]);
- output(string);
- }
- break;
- case 'C':
- case 'c':
- clearline();
- break;
- case 'A':
- case 'a':
- case 0x1B:
- return;
- case 'E':
- case 'e':
- clearline();
- cursor(22, 0);
- entry[0] = 0x00;
- output("Which line? ");
- vpanel(2);
- getln(entry, 3);
- for (x = 0; x < strlen(entry); x++) {
- if (entry[x] < 48 || entry[x] > 57) {
- cursor(22, 0);
- clearline();
- output("Invalid entry...");
- break;
- }
- }
- ch = atoi(entry);
- clearline();
- if (ch >= start) {
- cursor(22, 0);
- output("You haven't written that line yet...");
- pressanykey();
- break;
- }
- oldpart[0] = NULL;
- newpart[0] = NULL;
- cursor(22, 0);
- clearline();
- output("Old string? ");
- vpanel(60);
- getln(oldpart, 60);
- cursor(22, 0);
- clearline();
- output("New string? ");
- maxlen = 75 - (strlen(text[ch]) - strlen(oldpart));
- if (maxlen > 66) maxlen = 66;
- vpanel(maxlen);
- getln(newpart, maxlen);
- offset = strlen(text[ch]) - strlen(strstr(text[ch], oldpart));
- if (offset == strlen(text[ch])) {
- cursor(22, 0);
- clearline();
- output("Not found! Press any key... ");
- agetch();
- break;
- }
- for (x = 0; x < offset; x++) {
- inter[x] = text[ch][x];
- }
- inter[x] = 0x00;
- strcat(inter, newpart);
-
- y = strlen(inter);
- for (x = offset + strlen(oldpart); x < strlen(text[ch]); x++) {
- inter[y] = text[ch][x];
- ++y;
- }
- inter[y] = 0x00;
- strcpy(text[ch], inter);
- cursor(ch + 2, 0); /* !!!! */
- sprintf(string, "%02d > %s", ch, text[ch]);
- clearline();
- output(string);
- break;
- case 'S':
- case 's':
- cursor(22, 0);
- clearline();
- output("Flavor? $1C$0)ontinuous $1N$0)ormal $1D$0)irect $1H$0)old $1A$0)bort ");
- route_type = menu_select("CNDHA\x1B");
- cursor(22, 0);
- clearline();
- if (route_type == 'C') {
- strcpy(suffix, ".CUT");
- output("Saving as Continuous. ");
- }
- if (route_type == 'N') {
- strcpy(suffix, ".OUT");
- output("Saving as Normal. ");
- }
- if (route_type == 'D') {
- strcpy(suffix, ".DUT");
- output("Saving as Direct. ");
- }
- if (route_type == 'H') {
- strcpy(suffix, ".HUT");
- output("Saving as Hold. ");
- }
- if (route_type == 'A' || route_type == 0x1B) {
- return;
- }
-
- if (type == 0) {
- strcpy(fileopen, outbound);
- strcat(fileopen, hexname);
- strcat(fileopen, suffix);
-
- done = findfirst(fileopen, &ffblk, 0);
- if (! done) {
- exists = 1;
- strcpy(destination, fileopen);
- fileopen[strlen(fileopen) - 3] = 'T';
- output("Append existing packet. ");
- }
-
- else {
- exists = 0;
- output("Creating new packet. ");
- }
-
- if (! save_msg(fileopen, from_node, to_node, from_net, to_net, text, to, from, subject, start, attrib, textfile, route_type)) return;
-
- if (exists == 1) {
- append_packet(fileopen, destination);
- }
- }
- else {
- stream = fopen(list, "rb");
- if (stream == NULL) {
- output(" Invalid list file...");
- pressanykey();
- return;
- }
- ch = 0;
- minicls();
- cursor(2, 0);
- output("Sending message to list members...\r\n\r\n");
- while (! feof(stream)) {
- fscanf(stream, "%s", part);
- if (! strcmp(part, ";")) fgetln(line, sizeof(line), eolarea, stream);
- if (! stricmp(part, key)) {
- while (strcmp(part, ".")) {
- fscanf(stream, "%s ", part);
- if (! strcmp(part, ".")) continue;
- /* if (! strchr(part, '/')) continue; */
- strcpy(hexname, parseaddress(part));
- to_node = extractnode(hexname);
- to_net = extractnet(hexname);
- if (to_net == 0 && to_node == 0) continue;
- ++ch;
- if (ch > 12) {
- bottomcls(4);
- cursor(4, 0);
- ch = 0;
- }
- strcpy(fileopen, outbound);
- strcat(fileopen, hexname);
- strcat(fileopen, suffix);
- done = findfirst(fileopen, &ffblk, 0);
- if (! done) {
- exists = 1;
- strcpy(destination, fileopen);
- fileopen[strlen(fileopen) - 3] = 'T';
- sprintf(out, "Append existing packet for %d:%d/%d. ", zone_num, to_net, to_node);
- output(out);
- }
- else {
- exists = 0;
- sprintf(out, "Creating new packet for %d:%d/%d. ", zone_num, to_net, to_node);
- output(out);
- }
-
-
- if (! save_msg(fileopen, from_node, to_node, from_net, to_net, text, to, from, subject, start, attrib, textfile, route_type)) return;
-
- output("\r\n");
-
- if (exists == 1) append_packet(fileopen, destination);
-
- } /* while ! . */
- } /* end if ! */
- } /* end while ! feof */
- fclose(stream);
- } /* end else */
- if (type == 0) {
- cursor(22, 0);
- clearline();
- output("Operation complete...");
- pressanykey();
- }
- else output("\r\n");
- continue;
- } /* end switch */
-
- pick = 0x00;
- bottomcls(start + 2);
- cursor(start + 2, 0);
- continue;
- } /* end while */
-
- } /* end function */
-
-
- char save_msg(char *fileopen, int from_node, int to_node, int from_net,
- int to_net, char text[20][85], char *to, char *from, char *subject,
- int start, int attrib, char *textfile, char route_type) {
-
- struct tm *tm_now;
- long secs_now;
- char *str_now;
- struct ffblk ffblk;
-
- FILE *stream;
- FILE *stream2;
-
- char date_time[20];
- char address[15];
- char existtext = 0;
- char ch;
-
- char drive[MAXDRIVE];
- char dir[MAXDIR];
- char filefoo[MAXFILE];
- char ext[MAXEXT];
-
-
- int year = 0;
- int month = 0;
- int day = 0;
- int hour = 0;
- int minute = 0;
- int second = 0;
- int baud = 0;
- int y = 0;
- int x = 0;
-
- sprintf(address, "%d/%d", to_net, to_node);
-
- stream = fopen(fileopen, "wb");
- if (stream == NULL) {
- output("\r\nFile error...");
- pressanykey();
- return 0;
- }
- if (strlen(textfile) != 0) {
- stream2 = fopen(textfile, "rb");
- if (stream2 == NULL) existtext = 0;
- else existtext = 1;
- }
-
- putw(from_node, stream);
- putw(to_node, stream);
- time(&secs_now);
- str_now = ctime(&secs_now);
- sscanf(str_now, "%*3s %*3s %*2s %*8s %d", &year);
- tm_now = localtime(&secs_now);
- month = tm_now->tm_mon;
- day = tm_now->tm_mday;
- hour = tm_now->tm_hour;
- minute = tm_now->tm_min;
- second = tm_now->tm_sec;
- putw(year, stream);
- putw(month, stream);
- putw(day, stream);
- putw(hour, stream);
- putw(minute, stream);
- putw(second, stream);
- putw(baud, stream);
- putw(2, stream);
- putw(from_net, stream);
- putw(to_net, stream);
- putc(0x2E, stream);
- for (x = 0; x < 33; x++) {
- putc('\0', stream);
- }
- putw((int) 0x0002, stream);
- putw(from_node, stream);
- putw(to_node, stream);
- putw(from_net, stream);
- putw(to_net, stream);
- putw(attrib, stream); /* Attrib */
- putw((int) 0x0000, stream); /* Cost */
- get_date(date_time);
- fputs(date_time, stream);
- putc('\0', stream);
- fputs(to, stream);
- putc('\0', stream);
- fputs(from, stream);
- putc('\0', stream);
- if (attrib & 16) { /* if file attach store only name/ext */
- fnsplit(subject, drive, dir, filefoo, ext);
- fputs(filefoo, stream);
- fputs(ext, stream);
- }
- else fputs(subject, stream);
- putc('\0', stream);
-
- for (x = 0; x < start; x++) {
- for (y = 0; y < strlen(text[x]); y++) {
- putc(text[x][y], stream);
- }
- if (text[x][strlen(text[x]) - 1] != 0x0A) {
- putc(0x20, stream);
- putc(0x8D, stream);
- }
- }
-
- if (existtext) {
- while (! feof(stream2)) {
- ch = fgetc(stream2);
- if (ch > 0x1F || ch == 0x0A || ch == 0x0D) putc(ch, stream);
- }
- fclose(stream2);
- }
-
- if (tearline) fprintf(stream, "\r\n\r\n--- AMAX %s\r\n * Origin: %s", VERSION, sysname);
-
- fprintf(stream, "\r\n");
- putc('\0', stream);
- putw(0x00, stream);
- fclose(stream);
-
-
- if (attrib & 16) file(subject, address, route_type);
-
- return 1;
-
-
- }
-
-
-
- void get_date(char *date_time)
- {
- long secs, time();
- char *now;
- char day[3], mon[4], tme[9], year[3];
-
- time(&secs);
- now = (char *) ctime(&secs);
- sscanf(now, "%*3s %3s %2s %8s %*2s%2s", mon, day, tme, year);
- sprintf(date_time, "%2s %3s %2s %8s\0", day, mon, year, tme);
- }
-
-
- /*
-
- char *find_sysop(char *instring)
- {
- char fileopen[100];
- char filename[20] = "fidouser.lst";
- char eolarea[3];
- char line[100];
- char last[100];
- char first[100];
- char nodestring[50];
- char ch;
- char *portion;
- char part[50];
-
- FILE *stream;
-
- /* strcpy(nodestring, " ");
- strcat(nodestring, instring);
- strcat(nodestring, " ");
- */
-
- strcpy(nodestring, instring);
-
-
-
- strcpy(fileopen, nodelist);
- strcat(fileopen, filename);
-
- stream = fopen(fileopen, "rb");
- if (stream == NULL) {
- stream = fopen(filename, "rb");
- }
- if (stream) {
- while (! feof(stream)) {
- if (kbhit()) break;
- fgetln(line, sizeof(line), eolarea, stream);
-
- portion = (char *) strstr(line, nodestring);
- if (portion) {
-
- strcpy(part, portion - 1);
- if ((part[0] >= 48 && part[0] <= 57) || (part[strlen(nodestring)+1] >= 48 && part[strlen(nodestring)+1] <= 57)) continue;
-
- sscanf(line, "%s %s", last, first);
- last[strlen(last) - 1] = 0x00;
- strcpy(line, first);
- strcat(line, " ");
- strcat(line, last);
- fclose(stream);
- return line;
- }
- }
- fclose(stream);
- if (kbhit()) getch();
- return NULL;
- }
- return NULL;
- }
-
- */
-