home *** CD-ROM | disk | FTP | other *** search
- /*---------------------------------------------------------------------------*/
- /* ALDEkit */
- /* Version 1.00 */
- /* December 16th, 1989 */
- /* (C) Copyright 1989 CMI */
- /*---------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <process.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <ctype.h>
- #include <string.h>
- #include <dos.h>
- #include <io.h>
-
- #define BELL 0x07 /* bell */
- #define BS 0x08 /* backspace */
- #define CR 0x0D /* carriage return */
- #define SPACE 0x20 /* space */
- #define LINELEN 83 /* char/line plus CR-LF-NULL */
- #define BUFSIZE 13 /* input buffer size */
- #define SLPTIME 3 /* sleep time in seconds */
-
- /* Function prototypes */
-
- void Print_Menu(void);
- void Get_Filename(void);
- void Erase_Line(void);
- char Prompt(int type);
- int Transfer(void);
-
- /* Global variables */
-
- const char *version = "1.00"; /* current version number */
- const char *menu = "MENU.TXT"; /* full name of menu file */
- const char *preset_src_path = "J:"; /* preset source path */
- const char *preset_cat_ext = ".CAT"; /* preset catalog file ext */
- const char *preset_dest_path = "I:\\CDROM"; /* preset destination path */
- const char *bbs_file = "FILES.BBS"; /* BBS download file list */
-
- char dir_mark[] = {'\\', '\0'}, line_buffer[LINELEN], input_buffer[BUFSIZE];
- char mst_path[80], cat_path[80], src_path[80], dest_path[80];
- FILE *cat_file, *src_file, *dest_file;
-
- main()
- {
- char ch;
- int done = 0, line, prompt;
-
- while (!done) {
- Print_Menu(); /* display main menu */
-
- do { /* make selection */
- printf(" Enter file area number to read (return to exit) -> ");
- Get_Filename();
-
- if (!input_buffer[0]) {
- Erase_Line();
- printf(" ALDEkit Version %s ", version);
- printf("(C) Copyright 1989 CMI\n");
- exit(0);
- }
- strset(mst_path, '\0'); /* clear master path */
- strcat(mst_path, preset_src_path); /* create master path */
- strcat(mst_path, dir_mark);
- strcat(mst_path, input_buffer);
- strcpy(src_path, mst_path); /* create source path */
- strcpy(cat_path, mst_path); /* create catalog path */
- strcat(cat_path, dir_mark);
- strcat(cat_path, input_buffer);
- strcat(cat_path, preset_cat_ext); /* complete catalog path */
-
- if ((cat_file = fopen(cat_path, "r")) == NULL) {
- Erase_Line();
- printf(" Cannot open catalog file ... try again. ");
- sleep(SLPTIME);
- Erase_Line();
- }
- } while (cat_file == NULL);
-
- clrscr();
- line = prompt = 0;
- ch = '\0';
-
- do {
- if (fgets(line_buffer, LINELEN, cat_file) == NULL) {
- fclose(cat_file);
- prompt = 1;
- }
- else printf("%s", line_buffer);
-
- if (line++ == 23) {
- line = 0;
-
- do {
- ch = Prompt(prompt);
- if (ch == 'T') Transfer();
- } while (ch == 'T');
- }
- } while (ch != 'E');
- }
- return 0; /* normal program termination */
- }
-
- void Print_Menu(void) /* display main menu */
- {
- FILE *menu_file;
-
- clrscr();
-
- /* make sure file exists otherwise terminate program */
- if ((menu_file = fopen(menu, "r")) == NULL) {
- Erase_Line();
- printf(" Cannot open menu file ... program terminated.\n");
- exit(1);
- }
- while (fgets(line_buffer, LINELEN, menu_file))
- printf("%s", line_buffer);
- fclose(menu_file);
- }
-
- void Get_Filename(void) /* get filename */
- {
- char ch;
- int i, done;
-
- strset(input_buffer, '\0'); /* clear buffer */
- done = i = 0;
-
- while (!done) {
- ch = getch();
-
- if (!ch) { /* skip extended keys */
- getch();
- putchar(BELL);
- continue;
- }
- switch (ch) {
- case CR:
- done = 1;
- break;
- case BS:
- if (i > 0) {
- putchar(BS);
- putchar(SPACE);
- putchar(BS);
- input_buffer[--i] = '\0';
- }
- break;
- default:
- if (ch > ' ' && ch <= '~')
- if (i < BUFSIZE - 1) {
- putchar(ch);
- input_buffer[i++] = toupper(ch);
- break;
- }
- putchar(BELL);
- break;
- }
- }
- }
-
- void Erase_Line(void)
- {
- printf("\r%79s\r", " ");
- }
-
- char Prompt(int type) /* prompt and get response during list */
- {
- char c, ch;
- int done = 0;
-
- if (!type) printf(" (M)ore,");
- printf(" (T)ransfer to download area, (E)xit to main menu -> ");
-
- while (!done) {
- ch = toupper(c = getch());
-
- if (!ch) { /* skip extended keys */
- getch();
- putchar(BELL);
- continue;
- }
- if (c >= ' ' && c <= '~') {
- putchar(c);
- putchar(BS);
- switch (ch) {
- case 'M':
- if (!type) {
- done = 1;
- break;
- }
- else putchar(BELL);
- break;
- case 'T':
- case 'E':
- done = 1;
- break;
- default:
- putchar(BELL);
- break;
- }
- }
- else putchar(BELL);
- }
- Erase_Line();
- return ch;
- }
-
- int Transfer(void)
- {
- int ch;
- struct ftime date;
-
- Erase_Line();
- printf(" Enter filename to transfer to download area -> ");
- Get_Filename();
- strset(src_path, '\0');
- strcat(src_path, mst_path);
- strcat(src_path, dir_mark);
- strcat(src_path, input_buffer);
-
- if ((src_file = fopen(src_path, "rb")) == NULL) {
- Erase_Line();
- printf(" Cannot open source file for transfer ... try again. ");
- sleep(SLPTIME);
- Erase_Line();
- return 1;
- }
- getftime(fileno(src_file), &date);
-
- strset(dest_path, '\0');
- strcat(dest_path, preset_dest_path);
- strcat(dest_path, dir_mark);
- strcat(dest_path, input_buffer);
-
- if (!access(dest_path, 0)) {
- fclose(src_file);
- Erase_Line();
- printf(" File already exists ... try again. ");
- sleep(SLPTIME);
- Erase_Line();
- return 2;
- }
- dest_file = fopen(dest_path, "w+b");
- Erase_Line();
- printf(" One moment please ... transferring file to download area. ");
-
- while ((ch = fgetc(src_file)) != EOF)
- fputc(ch, dest_file);
-
- fclose(src_file);
- fclose(dest_file);
- dest_file = fopen(dest_path, "rb");
- setftime(fileno(dest_file), &date);
- fclose(dest_file);
-
- strset(dest_path, '\0');
- strcat(dest_path, preset_dest_path);
- strcat(dest_path, dir_mark);
- strcat(dest_path, bbs_file);
-
- strcat(input_buffer, "\r\n");
- dest_file = fopen(dest_path, "ab");
- fwrite(input_buffer, strlen(input_buffer), 1, dest_file);
- fclose(dest_file);
-
- Erase_Line();
- return 0;
- }