home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / plbin.zip / pl / src / pl-bite.c < prev    next >
C/C++ Source or Header  |  1992-05-26  |  1KB  |  63 lines

  1. /*  pl-bite.c,v 1.1.1.1 1992/05/26 11:52:15 jan Exp
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     See ../LICENCE to find out about your rights.
  5.     jan@swi.psy.uva.nl
  6.  
  7.     Purpose: Select part of a file
  8. */
  9.  
  10. #include <stdio.h>
  11. extern char *index();
  12.  
  13. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  14. This is a very simple stand alone program that picks  a  region  from  a
  15. file on character index basis and sends this to the standard output.  It
  16. is  part  of the help system to display long sections of the manual.  It
  17. should be installed as `pl-bite' in a directory that is in the  path  of
  18. the user (normally /usr/local/bin, next to Prolog itself).
  19. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  20.  
  21. char *program;
  22.  
  23. main(argc, argv)
  24. int argc;
  25. char **argv;
  26. { long from, to;
  27.   char *s;
  28.   FILE *fd;
  29.  
  30.   program = argv[0];
  31.  
  32.   if ( argc != 3 || (s = index(argv[1], ':')) == NULL )
  33.     usage();
  34.  
  35.   *s = '\0';
  36.   if ( (from = atol(argv[1])) == 0 || (to = atol(&s[1])) == 0 )
  37.     usage();
  38.  
  39.   if ( (fd = fopen(argv[2], "r")) == NULL || fseek(fd, from, 0) < 0 )
  40.   { perror(argv[2]);
  41.     exit(1);
  42.   }
  43.  
  44.   while(from++ < to)
  45.   { char c;
  46.  
  47.     if ( (c = getc(fd)) == EOF )
  48.     { fprintf(stderr, "%s: %s: premature EOF\n", program, argv[2]);
  49.       exit(1);
  50.     }
  51.     putchar(c);
  52.   }
  53.   fflush(stdout);
  54.   fclose(fd);
  55.  
  56.   exit(0);
  57. }
  58.  
  59. usage()
  60. { fprintf(stderr, "usage: %s from:to file\n");
  61.   exit(1);
  62. }
  63.