home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / fax-3.2.1 / lib / libutil / show.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-31  |  1.6 KB  |  76 lines

  1. /*
  2.   This file is part of the NetFax system.
  3.  
  4.   (c) Copyright 1989 by David M. Siegel and Sundar Narasimhan.
  5.       All rights reserved.
  6.  
  7.     This program is free software; you can redistribute it and/or modify
  8.     it under the terms of the GNU General Public License as published by
  9.     the Free Software Foundation.
  10.  
  11.     This program is distributed in the hope that it will be useful, 
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. */
  20.  
  21. #include <stdio.h>
  22.  
  23. #include "show.h"
  24.  
  25. #define MORE "/usr/ucb/more"
  26.  
  27. int
  28. show_file(filename, fp)
  29. char *filename;
  30. FILE *fp;
  31. {
  32.     FILE *f;
  33.     char buf[BUFSIZ];
  34.  
  35.     if ((f = fopen(filename, "r")) == NULL)
  36.       return (-1);
  37.  
  38.     while (!feof(f)) {
  39.     int count = fread(buf, sizeof(char), sizeof(buf), f);
  40.     if (count > 0)
  41.       fwrite(buf, sizeof(char), count, fp);
  42.     }
  43.     
  44.     fclose(f);
  45.  
  46.     return (0);
  47. }
  48.  
  49. int
  50. show_file_with_more(filename)
  51. char *filename;
  52. {
  53.     FILE *p;
  54.     FILE *f;
  55.     char buf[BUFSIZ];
  56.  
  57.     if ((p = popen(MORE, "w")) == NULL)
  58.       return (-1);
  59.  
  60.     if ((f = fopen(filename, "r")) == NULL) {
  61.     pclose(p);
  62.     return (-1);
  63.     }
  64.  
  65.     while (!feof(f)) {
  66.     int count = fread(buf, sizeof(char), sizeof(buf), f);
  67.     if (count > 0)
  68.       fwrite(buf, sizeof(char), count, p);
  69.     }
  70.     
  71.     pclose(p);
  72.     fclose(f);
  73.  
  74.     return (0);
  75. }
  76.