home *** CD-ROM | disk | FTP | other *** search
- /*
- * REQDIR.C - Server for the W0RLI MailBox V10.xx
- *
- * Copyright (C) 1989
- * Peter Meiring
- * 13 Venn Crescent,
- * Hartley, Plymouth.
- * PL3 5PJ
- *
- * This code may be freely used and copied for non-commercial uses.
- *
- * s reqdir reqdir.exe reqdir.out H8 reqdir.in H8
- *
- * See SERVER.DOC for further details.
- *
- */
-
- #include <stdio.h>
- #include <ctype.h>
- #include <string.h>
- #include <dir.h>
- #include <dos.h>
- /*
- * Copyright storage:
- */
-
- char *copyright = "REQIR 1.05 Copyright (c) Peter Meiring, G0BSX, 1989.\n";
-
- /*
- * Some buffer space.
- */
-
- #define ln_buf 512
-
- char buf[ln_buf];
-
- /*
- * End-of-message mark.
- */
-
- char *mark = "/EX\n";
- char base[64]; /* storage for the root path of the files section */
-
- /*
- * File used by this program to read initialisation Data
- */
-
- char *datfile = "\\reqxxx.dat";
- /*
- * File the MailBox will create, and this server will read.
- */
-
- char *infile = "reqdir.out";
-
- /*
- * File this server will create, and the MailBox will read.
- */
-
- char *outfile = "reqdir.in";
-
- /* List directory to file */
-
-
- stripcr( line )
- char *line;
- {
- int i;
- for(i=1;i<strlen(line);i++)
- if(line[i]=='\n')
- line[i]='\0' ;
- }
-
- touc( w )
- char *w ;
- { int ch;
- while( (ch = *w ))
- *w++ = toupper(ch) ;
- }
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- FILE *in, *out;
- char *st, *tail, *fname, *ptr, path[128] ;
- int cntr = 0 ;
- struct ffblk *fblk ;
- /*
- int findfirst(const char *filename,
- struct ffblk *ffblk, int attrib);
- int findnext(struct ffblk *ffblk);
-
- struct ffblk {
- char ff_reserved[21];
- char ff_attrib;
- unsigned ff_ftime;
- unsigned ff_fdate;
- long ff_fsize;
- char ff_name[13];
- }
- */
- /*
- * Open and read the initialisation file: reqxxx.dat in the root directory
- */
-
- puts(copyright);
-
- if((in = fopen(datfile, "r")) == NULL) exit(1);
-
- st = fgets(buf, ln_buf, in) ;
-
- while (st != NULL) {
-
- /*
- * skip all comment and blank lines
- */
-
- while( ((*buf == ';') || (*buf == '\n')) && (st != NULL))
- st = fgets(buf, ln_buf, in) ;
-
- /*
- * Extract parameters
- */
- if (!strncmp(buf, "textsdir", 8)) {
- ptr = strchr(buf, ' ');
- while( *ptr == ' ' ) *ptr++ = '\0';
- strcpy( base, ptr);
- stripcr( base );
- }
- st = fgets(buf, ln_buf, in) ;
- }
-
- fclose(in);
-
- /*
- * Open the input file.
- * If not possible, exit with return code 1 to signal
- * the MailBox that the server failed.
- */
-
- if ((in = fopen(infile, "r")) == NULL) exit(1);
-
- /*
- * Open the output file.
- * If not possible, exit with return code 1 to signal
- * the MailBox that the server failed.
- */
-
- if ((out = fopen(outfile, "w")) == NULL) exit(1);
-
- st = fgets(buf, ln_buf, in);
- while (st != NULL)
- {
-
- /*
- * Read the rfc-822 header placed into the message by the MailBox.
- * The end of header is marked by a blank line.
- */
-
- while(*buf != '\n')
- {
-
- /*
- * Find end of keyword.
- * Terminate string at end of keyword.
- */
-
- tail = strchr(buf, ' ');
- *tail++ = '\0';
-
- /*
- * Make the new rfc-822 header.
- */
-
- if (!strcmp(buf, "To:")) fprintf(out, "From: %s", tail);
- else if (!strcmp(buf, "From:")) fprintf(out, "To: %s", tail);
- else if (!strcmp(buf, "Subject:")) {
- fname = tail ;
- if( (tail = strchr( fname, ' ')) != NULL) {
- *tail++ = '\n';
- *tail = '\0' ;
- }
- if( (*fname == '\n') || (*fname == '@') )
- strcpy( fname, "*.*\n" ) ;
- else if( strchr( fname, '\\') == NULL)
- if((strchr(fname, '*') == NULL) && (strchr(fname, '?')==NULL))
- stripcr( fname ) ;
- strcat( fname, "\\*.*\n" ) ;
-
- touc( fname ) ;
- fprintf(out, "Subject: Directory: %s", fname);
- }
- st = fgets(buf, ln_buf, in);
- }
-
- /*
- * Now that the rfc-822 header has been read, and a new one created,
- * copy the text of the message from the input to the output.
- */
- fputs(buf,out) ;
- stripcr(fname) ;
- cntr = 0 ;
- strcpy( path, base ) ;
- strcat( path, fname ) ;
- touc( path ) ;
- fprintf(out, "Directory: %s", path);
- if( findfirst( path, fblk, FA_DIREC ) == -1 )
- fprintf( out, " not found.");
- else if( fblk->ff_name[0] != '.' ) {
- if( (cntr++ % 3) == 0 )
- fprintf( out, "\n" ) ;
- else
- fprintf( out, " " ) ;
- fprintf( out, "%-15s", fblk->ff_name);
- if( fblk->ff_attrib == FA_DIREC)
- fprintf( out, "<DIR>") ;
- else
- fprintf( out, "%5d", fblk->ff_fsize );
- }
- while( findnext( fblk ) == 0 )
- if( fblk->ff_name[0] != '.' ) {
- if( (cntr++ % 3) == 0 )
- fprintf( out, "\n" ) ;
- else
- fprintf( out, " " ) ;
- fprintf( out, "%-15s", fblk->ff_name);
- if( fblk->ff_attrib == FA_DIREC)
- fprintf( out, "<DIR>") ;
- else
- fprintf( out, "%5ld", fblk->ff_fsize );
- }
- fprintf( out, "\n");
-
- while ((st != NULL) && stricmp(buf, mark))
- {
- st = fgets(buf, ln_buf, in);
- }
-
- /*
- * Mark the end of this message.
- * Go on to the next message.
- */
- fputs("\n", out);
- fputs(mark, out);
- if (st != NULL) st = fgets(buf, ln_buf, in);
- }
-
- /*
- * All the incoming messages have been processed,
- * and an outgoing message created for each one.
- */
-
- fclose(in);
- fclose(out);
-
- unlink( infile ) ;
-
- /*
- * Exit with return code 0 to signal the MailBox that
- * the server completed it's processing normally.
- * The MailBox will then read our output file,
- * and create messages from it.
- */
-
- exit(0);
- }