home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*/
- /* */
- /* Module Name: AMAXFREQ.C */
- /* Program Name: AMAX */
- /* Revision: 2.xx */
- /* Purpose: File Request Generator 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 <dir.h>
- #include <dos.h>
- #include <io.h>
- #include <time.h>
- #include <sys\stat.h>
- #include "amax.h"
-
- extern int daylight;
- extern long timezone;
- extern char series[80];
-
-
- void freq(char, int, int, char *);
-
- void freq(char courtesy, int from_net, int from_node, char *sysop)
- {
- FILE *stream;
-
- unsigned char sysopname[50] = "Sysop";
- unsigned char info[70] = "";
- unsigned char system[50] = "";
- unsigned char name[90] = "";
- unsigned char password[20] = "";
- unsigned char first[20] = "";
- unsigned char hexname[20] = "";
- unsigned char out[100] = "";
- unsigned char text[20][85];
- unsigned char pass[60] = "";
- unsigned char msgpath[100] = "";
- unsigned char alt[100] = "";
- unsigned char line[100] = "";
- unsigned char eolarea[3] = "";
- unsigned char input[50] = "";
- unsigned char tempfile[13] = "";
- unsigned char update[25] = "";
- unsigned char update_file[90] = "";
- unsigned char drive[MAXDRIVE];
- unsigned char dir[MAXDIR];
- unsigned char file[MAXFILE];
- unsigned char ext[MAXEXT];
- char ch = 0x00;
- char append_msg = 0;
- char typeupd = 0;
- char ret = 0;
-
- int to_net;
- int to_node;
- int counter = 0;
- int thiscount = 0;
- int x;
- int y;
- int flag;
- int done;
-
- struct ffblk ffblk;
- struct stat finfo;
-
- long outtime;
- long timenow;
- long filesize;
-
- for (x = 0; x < 20; x++) {
- text[x][0] = 0x00;
- }
-
- do {
-
- cls();
- output("$1AMAX $4Request a File$0");
- cursor(2, 0);
-
- input[0] = 0x00;
-
- output("Destination System <net/node> ");
- vpanel(45);
- getln(input, 45);
-
- strcpy(system, input);
-
- counter = 0;
-
- 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(sysopname, input);
- }
-
- strcpy(hexname, parseaddress(system));
-
- to_net = extractnet(hexname);
- to_node = extractnode(hexname);
-
- strcpy(info, lookinfo(to_net, to_node, 0));
- sprintf(out, " Looks Like: %s\r\n\r\n", info);
- if (usenl) output(out);
-
- strcpy(pass, outbound);
- strcat(pass, hexname);
- strcat(pass, ".REQ");
-
-
- if (! findfirst(pass, &ffblk, 0)) {
- if (! strlen(series)) {
- cursor(5, 0);
- output("File requests are pending for this system. Display? $1Y$0)es $1N$0)o ");
- ch = menu_select("YN\x1B\x0D");
- if (ch == 0x1B) return;
- if (ch == 'Y') {
- aputch(ch);
- stream = fopen(pass, "rb");
- if (stream != NULL) {
- counter = list_contents(stream, 7, 3);
- fclose(stream);
- output("\r\nPress any key to continue...");
- agetch();
- }
- }
- }
- stream = fopen(pass, "rb");
- if (stream != NULL) {
- while (! feof(stream)) {
- fgetln(line, sizeof(line), eolarea, stream);
- ++counter;
- }
- --counter;
- fclose(stream);
- }
- }
-
- bottomcls(5);
- cursor(5, 0);
- output("Files Requested = ");
-
-
-
- do {
-
- cursor(5, 18);
- sprintf(line, "%d", counter);
- output(line);
- bottomcls(7);
-
- cursor(5, 25);
- output("For update request, specify drive and path.");
-
- cursor(7, 0);
-
- output("File Desired <filename> \r\n ");
- name[0] = 0x00;
- vpanel(75);
- getln(name, 75);
- if (strlen(name) < 1) break;
- flag = fnsplit(name, drive, dir, file, ext);
- update[0] = 0x00;
- if ((flag & DRIVE) && (flag & DIRECTORY)) {
- typeupd = 1;
- done = findfirst(name, &ffblk, 0);
- if (done) {
- output("Cannot update non-existent file, ");
- pressanykey();
- continue;
- }
- stat(name, &finfo);
- outtime = finfo.st_atime;
- filesize = finfo.st_size;
- output("Update Request Mode. Do you want files that are: N)ewer O)lder ");
- output("\r\n");
- ch = menu_select("NO\r\x1B");
- if (ch == 0x1B) return;
- if (ch == 'N' || ch == '\r') sprintf(update, " +%ld", outtime);
- else sprintf(update, " -%ld", outtime);
- strcpy(name, file);
- strcat(name, ext);
- strcpy(update_file, outbound);
- strcat(update_file, "updates.req");
- stream = fopen(update_file, "a+");
- if (stream != NULL) {
- time(&timenow);
- fprintf(stream, "%s %s%s%s %d:%d/%d %ld %ld %ld\n", name, drive, dir, update, our_zone, net, node, outtime, filesize, timenow);
- fclose(stream);
- }
- }
- output("Password (if any) <password> ");
- first[0] = 0x00;
- vpanel(15);
- getln(first, 15);
- strcpy(password, "!");
- strcat(password, first);
-
- output("\r\n");
-
-
- if (findfirst(pass, &ffblk, 0) != 0) output("Creating new file request...\r\n");
- else output("Appending existing file request...\r\n");
-
- stream = fopen(pass, "a+b");
- if (stream == NULL) {
- cursor(12, 0);
- output("Cannot open .REQ file. Press any key...");
- agetch();
- return;
- }
-
-
- strcpy(out, name);
-
- for (x = 0; x < strlen(name); x++) {
- if (name[x] == ' ') break;
- }
- name[x] = 0x00;
-
- flag = 0;
- for (y = x + 1; y < strlen(out); y++) {
- out[flag] = out[y];
- ++flag;
- }
- out[flag] = 0x00;
-
- fprintf(stream, "%s", name);
- if (strlen(first) > 0) fprintf(stream, " %s", password);
- if (strlen(out) > 0) fprintf(stream, " %s", out);
- if (strlen(update) > 0) fprintf(stream, "%s", update);
- fprintf(stream, "%c%c", 0x0D, 0x0A);
-
- ++counter;
- ++thiscount;
- if (thiscount < 18) sprintf(text[thiscount + 1], "File %d - %s\r\n", thiscount, name);
-
- fclose(stream);
-
- } while (strlen(name) > 0);
-
- if (courtesy) {
-
- output("Generating courtesy message packet...\r\n");
-
- strcpy(msgpath, outbound);
- strcat(msgpath, hexname);
- strcat(msgpath, ".OUT");
-
- tmpnam(tempfile);
-
- strcpy(alt, outbound);
- strcat(alt, tempfile);
-
- if (! typeupd) sprintf(text[0], "File request generated by AMAX Version %s\r\n", VERSION);
- else sprintf(text[0], "File update request generated by AMAX Version %s\r\n", VERSION);
-
- sprintf(text[1], "\r\n");
-
- if (findfirst(msgpath, &ffblk, 0) != 0) append_msg = 0;
- else append_msg = 1;
-
- strcpy(name, "Files Listed Below");
-
- if (thiscount < 17) {
- strcat(text[thiscount + 1], "\r\n");
- }
- else {
- strcat(text[18], "\r\n");
- thiscount = 18;
- }
-
- if (append_msg) {
- save_msg(alt, from_node, extractnode(hexname), from_net,
- extractnet(hexname), text, sysopname, sysop, name,
- thiscount + 2, 2049, "amaxfreq.txt");
- append_packet(alt, msgpath);
- }
-
- else {
- save_msg(msgpath, from_node, extractnode(hexname), from_net,
- extractnet(hexname), text, sysopname, sysop, name,
- thiscount + 2, 2049, "amaxfreq.txt");
- }
- }
-
-
- output("\r\n\r\nPress ENTER to return to Main Menu, any other key to enter more requests... ");
- ret = agetch();
- } while (ret != 0x0D);
-
- return;
-
- }
-