home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / bbs / listcall.arc / LISTCALL.C next >
Text File  |  1985-03-15  |  6KB  |  175 lines

  1. /************************************************************************
  2.  
  3. Program to List Callers file for RBBS-PC
  4.  
  5. This program is distributed freely to all SYSOPs of RBBS-PC systems.  No
  6. payment or other award, except maybe a quick word of thanks, is expected.
  7. The program is given in return for the many hours and dollars the SYSOPs
  8. spend in running and maintaining their boards everyone's enjoyment.
  9.  
  10. I only ask that you observe two rules in the use of this program:
  11.     1)    That you do not remove my credits from the either the source
  12.     or executable file.
  13.     2)    That you do not distribute the program in modified form.  If you
  14.     have bug fixes or suggestions, please send them to me.
  15.  
  16.  
  17. Jeff Porter
  18. 1505 West Creek Loop
  19. Round Rock, TX 78681
  20. (512) 255-1030
  21.  
  22. I can also be reached on most of the Austin BBSs.
  23.  
  24. ***************************************************************************
  25.  
  26.  
  27.  
  28. ---------------------------------------------------------------------------
  29. Revision History
  30. V1.0   2-3-85    The original version of the program.
  31. V1.1   3-15-85    Revised to handle files of up to 4.1 M in size.  This
  32.         resulted in an overall loss in efficency, however, since
  33.         it is not possible to hold a 4.1 M file in RAM.
  34. --------------------------------------------------------------------------*/
  35.  
  36. /* Get the standard declarations. */
  37. #include <stdio.h>
  38.  
  39.  
  40. #define error(s)    { fprintf(stderr, "%s\r\n", s); exit(1); }
  41.  
  42. /* buf holds the information that is read from the file. */
  43. char buf[65];
  44.  
  45. /* These track the input (fi) and output (fo) files. */
  46. FILE *fi, *fo;
  47.  
  48.  
  49. main(argc, argv)
  50. int argc;
  51. char *argv[];
  52. {
  53.     unsigned int size, i;
  54.     long fseek();
  55.     FILE *fopen();
  56.     char *readprevious(), *lookblock(), *zaprtspc();
  57.     /* If they entered no arguments, show credits and a usage summary. */
  58.     if ( argc<2 )
  59.     {
  60.     printf("List CALLERS file\n");
  61.     printf("Jeff Porter\n");
  62.     printf("2-14-85, 3-15-85\n");
  63.     printf("Usage:  LISTCALL infile [outfile]\n");
  64.     exit(1);
  65.     }
  66.     /* Attempt to open the input file. */
  67.     if ( (fi=fopen(argv[1], "r")) == 0 )
  68.     {
  69.     printf("can't open %s\n", argv[1]);
  70.     exit(1);
  71.     }
  72.     /* If there is an output file specified, use it. */
  73.     if ( argc >= 3 )
  74.     {
  75.     if ( (fo=fopen(argv[2], "w")) == 0 )
  76.         error("can't create output file");
  77.     /* If there is no output file given, use standard output. */
  78.     }else
  79.     fo = stdout;     /* can be redirected under dos 2 */
  80.     /* Determine the number of 64 byte records in the file. */
  81.     size = (unsigned)(fseek(fi, 0L, 2)/64)-1;
  82.     /* The file must contain two records -- one person. */
  83.     if ( size < 2 )
  84.     error("The file is too short");
  85.     /* Back up 128 bytes in order to be looking at the last record in */
  86.     /* the file.  It should be 64 bytes except that 64 doesn't work and */
  87.     /* 128 does.  If you can explain why, please let me know. */
  88.     if ( fseek(fi, -128L, 2) == ERROR )
  89.     error("starting file positioning");
  90.     /* Go through the file, counting two records min. each time through. */
  91.     for (i=0; i<size; i+=2)
  92.     {
  93.     /* Read the record, back up, and print it out. */
  94.     /* This will be the first 64 characters of the line containing */
  95.     /* the caller, location, time, baud, etc. */
  96.     if ( fprintf(fo, "%s", zaprtspc(readprevious()) ) == ERROR )
  97.         error("disk full");
  98.     /* Do the same for the next (previous) record. */
  99.     /* This is the remainder of the line.  The last part of this */
  100.     /* information is not used because it will not fit on the screen. */
  101.     if ( fprintf(fo, "%-15.15s\r\n", readprevious() ) == ERROR )
  102.         error("disk full");
  103.     /* Now print out all activities done by the person, if there are */
  104.     /* any.  All activity entries start will a space. */
  105.     while ( i <size-2 && *lookblock()==32 )
  106.     {
  107.         if ( fprintf(fo, "%s\r\n", zaprtspc(readprevious()) ) == ERROR )
  108.         error("disk full");
  109.         i++;
  110.     }
  111.     /* Continue for every person in the file, counting two records each */
  112.     /* plus one count for every activity record printed. */
  113.     }
  114.     /* Close down the files. */
  115.     fclose(fi);
  116.     fclose(fo);
  117.     /* Exit the program with an OK error return code. */
  118.     return(0);
  119. }
  120.  
  121. /* readprevious()   reads the 64 byte block into the data buffer and backs
  122.             up.
  123. */
  124.  
  125. char *
  126. readprevious()
  127. {
  128.     long fseek();
  129.     /* Get the info. */
  130.     fread(buf, 1, 64, fi);
  131.     /* Move back over that and position to read the previous block. */
  132.     if ( fseek(fi, -128L, 1) == ERROR )
  133.     error("readprevious seek error");
  134.     return(buf);
  135. }
  136.  
  137. /* lookblock()     looks at the previous 64 byte block without backing up. */
  138.  
  139. char *
  140. lookblock()
  141. {
  142.     long fseek();
  143.     /* Get the info. */
  144.     fread(buf, 1, 64, fi);
  145.     /* Move back over this information. */
  146.     fseek(fi, -64L, 1);
  147.     return(buf);
  148. }
  149.  
  150. /** zaprtspc(p)    removes trailing spaces from the string p.  NOTE that
  151.             p must point to a buffer!  The contents may be changed!
  152. *****/
  153.  
  154. char *
  155. zaprtspc(p)
  156. char *p;
  157. {
  158.     char *o;
  159.     /* Save the start address. */
  160.     o=p;
  161.     /* Move to the end of the string. */
  162.     while (*p)
  163.     p++;
  164.     /* As long as we are either at the end of the string or on a space */
  165.     /* but aren't at the end, back up one character and try again. */
  166.     while ( (*p==32 || *p==0) && p>o )
  167.     p--;
  168.     /* Add terminator at the character after the one we stopped on. */
  169.     /* If we backed up over spaces, the null will be placed on the */
  170.     /* first space to the right. */
  171.     p[1]=0;
  172.     /* Return a pointer to the new string. */
  173.     return(o);
  174. }
  175.