home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume36 / unpost / part01 / utils / mofs.c
Encoding:
C/C++ Source or Header  |  1993-04-18  |  2.7 KB  |  106 lines

  1. /******************************************************************************
  2. * Module    :   Used for debugging UNPOST, this routine will start doing
  3. *               a MORE at the specified offset in the file.
  4. *
  5. * Author    :   John W. M. Stevens
  6. ******************************************************************************/
  7.  
  8. #include    <stdio.h>
  9. #include    <stdlib.h>
  10. #include    <string.h>
  11.  
  12. void    main(int    argc,
  13.              char   **argv)
  14. {
  15.     register    int     i;
  16.     register    int     j;
  17.     auto        FILE    *FlPtr;
  18.     auto        long    Ofs;
  19.     static      char    Bfr[513];
  20.  
  21.     /*  Check the command line arguments.   */
  22.     if (argc != 3)
  23.     {
  24.         fprintf(stderr,
  25.                 "%s %d : Error - Syntax is: mofs <+ofs> <file name>\n",
  26.                 __FILE__,
  27.                 __LINE__);
  28.         exit( 1 );
  29.     }
  30.  
  31.     /*  Get the offset. */
  32.     if (argv[1][0] != '+')
  33.     {
  34.         fprintf(stderr,
  35.                 "%s %d : Error - Syntax is: mofs <+ofs> <file name>\n",
  36.                 __FILE__,
  37.                 __LINE__);
  38.         exit( 1 );
  39.     }
  40.     Ofs = atol(argv[1] + 1);
  41.  
  42.     /*  Open the file to more.  */
  43.     if ((FlPtr = fopen(argv[2], "r")) == NULL)
  44.     {
  45.         fprintf(stderr,
  46.                 "%s %d : Error - %s\n",
  47.                 __FILE__,
  48.                 __LINE__,
  49.                 sys_errlist[errno]);
  50.         exit( 1 );
  51.     }
  52.  
  53.     /*  Position the file pointer.  */
  54.     if ( fseek(FlPtr, Ofs, SEEK_SET) )
  55.     {
  56.         fprintf(stderr,
  57.                 "%s %d : Error - %s\n",
  58.                 __FILE__,
  59.                 __LINE__,
  60.                 sys_errlist[errno]);
  61.         exit( 1 );
  62.     }
  63.  
  64.     /*  More the file.  */
  65.     for ( ; ; )
  66.     {
  67.         /*  Dump out lines. */
  68.         for (i = 0; i < 24; i++)
  69.         {
  70.             /*  Get a line. */
  71.             if (fgets(Bfr, 512, FlPtr) == NULL)
  72.                 exit( 0 );
  73.  
  74.             /*  Check for auto scroll.  */
  75.             j = strlen( Bfr );
  76.             if (j > 80)
  77.                 i += j / 80;
  78.             fputs(Bfr, stdout);
  79.         }
  80.  
  81.         /*  Get the input from the user.    */
  82.         fgets(Bfr, 512, stdin);
  83.         if (*Bfr >= '0' && *Bfr <= '9')
  84.         {
  85.             /*  Get the offset. */
  86.             Ofs = atol( Bfr );
  87.  
  88.             /*  Position the file pointer.  */
  89.             if ( fseek(FlPtr, Ofs, SEEK_SET) )
  90.             {
  91.                 fprintf(stderr,
  92.                         "%s %d : Error - %s\n",
  93.                         __FILE__,
  94.                         __LINE__,
  95.                         sys_errlist[errno]);
  96.                 exit( 1 );
  97.             }
  98.         }
  99.         else if (*Bfr == 'q' || *Bfr == 'Q')
  100.             break;
  101.     }
  102.  
  103.     /*  Close the file. */
  104.     fclose( FlPtr );
  105. }
  106.