home *** CD-ROM | disk | FTP | other *** search
- /************************************************************************
-
- Program to List Callers file for RBBS-PC
-
- This program is distributed freely to all SYSOPs of RBBS-PC systems. No
- payment or other award, except maybe a quick word of thanks, is expected.
- The program is given in return for the many hours and dollars the SYSOPs
- spend in running and maintaining their boards everyone's enjoyment.
-
- I only ask that you observe two rules in the use of this program:
- 1) That you do not remove my credits from the either the source
- or executable file.
- 2) That you do not distribute the program in modified form. If you
- have bug fixes or suggestions, please send them to me.
-
-
- Jeff Porter
- 1505 West Creek Loop
- Round Rock, TX 78681
- (512) 255-1030
-
- I can also be reached on most of the Austin BBSs.
-
- ***************************************************************************
-
-
-
- ---------------------------------------------------------------------------
- Revision History
- V1.0 2-3-85 The original version of the program.
- V1.1 3-15-85 Revised to handle files of up to 4.1 M in size. This
- resulted in an overall loss in efficency, however, since
- it is not possible to hold a 4.1 M file in RAM.
- --------------------------------------------------------------------------*/
-
- /* Get the standard declarations. */
- #include <stdio.h>
-
-
- #define error(s) { fprintf(stderr, "%s\r\n", s); exit(1); }
-
- /* buf holds the information that is read from the file. */
- char buf[65];
-
- /* These track the input (fi) and output (fo) files. */
- FILE *fi, *fo;
-
-
- main(argc, argv)
- int argc;
- char *argv[];
- {
- unsigned int size, i;
- long fseek();
- FILE *fopen();
- char *readprevious(), *lookblock(), *zaprtspc();
- /* If they entered no arguments, show credits and a usage summary. */
- if ( argc<2 )
- {
- printf("List CALLERS file\n");
- printf("Jeff Porter\n");
- printf("2-14-85, 3-15-85\n");
- printf("Usage: LISTCALL infile [outfile]\n");
- exit(1);
- }
- /* Attempt to open the input file. */
- if ( (fi=fopen(argv[1], "r")) == 0 )
- {
- printf("can't open %s\n", argv[1]);
- exit(1);
- }
- /* If there is an output file specified, use it. */
- if ( argc >= 3 )
- {
- if ( (fo=fopen(argv[2], "w")) == 0 )
- error("can't create output file");
- /* If there is no output file given, use standard output. */
- }else
- fo = stdout; /* can be redirected under dos 2 */
- /* Determine the number of 64 byte records in the file. */
- size = (unsigned)(fseek(fi, 0L, 2)/64)-1;
- /* The file must contain two records -- one person. */
- if ( size < 2 )
- error("The file is too short");
- /* Back up 128 bytes in order to be looking at the last record in */
- /* the file. It should be 64 bytes except that 64 doesn't work and */
- /* 128 does. If you can explain why, please let me know. */
- if ( fseek(fi, -128L, 2) == ERROR )
- error("starting file positioning");
- /* Go through the file, counting two records min. each time through. */
- for (i=0; i<size; i+=2)
- {
- /* Read the record, back up, and print it out. */
- /* This will be the first 64 characters of the line containing */
- /* the caller, location, time, baud, etc. */
- if ( fprintf(fo, "%s", zaprtspc(readprevious()) ) == ERROR )
- error("disk full");
- /* Do the same for the next (previous) record. */
- /* This is the remainder of the line. The last part of this */
- /* information is not used because it will not fit on the screen. */
- if ( fprintf(fo, "%-15.15s\r\n", readprevious() ) == ERROR )
- error("disk full");
- /* Now print out all activities done by the person, if there are */
- /* any. All activity entries start will a space. */
- while ( i <size-2 && *lookblock()==32 )
- {
- if ( fprintf(fo, "%s\r\n", zaprtspc(readprevious()) ) == ERROR )
- error("disk full");
- i++;
- }
- /* Continue for every person in the file, counting two records each */
- /* plus one count for every activity record printed. */
- }
- /* Close down the files. */
- fclose(fi);
- fclose(fo);
- /* Exit the program with an OK error return code. */
- return(0);
- }
-
- /* readprevious() reads the 64 byte block into the data buffer and backs
- up.
- */
-
- char *
- readprevious()
- {
- long fseek();
- /* Get the info. */
- fread(buf, 1, 64, fi);
- /* Move back over that and position to read the previous block. */
- if ( fseek(fi, -128L, 1) == ERROR )
- error("readprevious seek error");
- return(buf);
- }
-
- /* lookblock() looks at the previous 64 byte block without backing up. */
-
- char *
- lookblock()
- {
- long fseek();
- /* Get the info. */
- fread(buf, 1, 64, fi);
- /* Move back over this information. */
- fseek(fi, -64L, 1);
- return(buf);
- }
-
- /** zaprtspc(p) removes trailing spaces from the string p. NOTE that
- p must point to a buffer! The contents may be changed!
- *****/
-
- char *
- zaprtspc(p)
- char *p;
- {
- char *o;
- /* Save the start address. */
- o=p;
- /* Move to the end of the string. */
- while (*p)
- p++;
- /* As long as we are either at the end of the string or on a space */
- /* but aren't at the end, back up one character and try again. */
- while ( (*p==32 || *p==0) && p>o )
- p--;
- /* Add terminator at the character after the one we stopped on. */
- /* If we backed up over spaces, the null will be placed on the */
- /* first space to the right. */
- p[1]=0;
- /* Return a pointer to the new string. */
- return(o);
- }