home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / freedos3 / source / jh_utils / fcat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-07  |  2.1 KB  |  104 lines

  1. /*
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.  
  7.    This program is distributed in the hope that it will be useful,
  8.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.    GNU General Public License for more details.
  11.  
  12.    You should have received a copy of the GNU General Public License
  13.    along with this program; if not, write to the Free Software
  14.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15.    */
  16.  
  17. #include <stdio.h>
  18. #include <ctype.h>
  19. #include "freedos.h"
  20.  
  21.  
  22. /**************************************************************************
  23.  * This function displays a file from FILE *p to the standard output stream,
  24.  * much like UNIX 'cat'.  There are a few enhancements to allow control over
  25.  * the display of the file.
  26.  *
  27.  * Author: James Hall
  28.  */
  29.  
  30. void 
  31. fcat (FILE * p, int iNum, int iBlank, int iCtrl, int iEnds,
  32.       int iTabs, int iUpc, int iDownc)
  33. {
  34.   int i, iLen, iLast = 0;
  35.   long lLines;
  36.   char c, sz[MAX_STR];
  37.  
  38.   /* Read the file until EOF */
  39.  
  40.   for (lLines = 1; fgets (sz, MAX_STR, p) != NULL; lLines++)
  41.     {
  42.       iLen = strlen (sz);
  43.  
  44.       /* Squeeze blank lines if needed */
  45.  
  46.       if ((iLast) && (iLast = blank (sz)) && (iBlank));
  47.  
  48.       /* Number the output if needed */
  49.  
  50.       else
  51.     {
  52.  
  53.       if (iNum)
  54.         {
  55.           printf ("%ld:", lLines);
  56.         }
  57.  
  58.       /* Print specials if needed */
  59.  
  60.       for (i = 0; i < (iLen - 1); i++)
  61.         {
  62.  
  63.           /* Convert to upper or lower */
  64.  
  65.           if (iUpc)
  66.         {
  67.           sz[i] = toupper (sz[i]);
  68.         }
  69.  
  70.           else if (iDownc)
  71.         {
  72.           sz[i] = tolower (sz[i]);
  73.         }
  74.  
  75.           if ((iscntrl (sz[i])) && (iCtrl))
  76.         {
  77.           printf ("^%c", sz[i] + 64);
  78.         }
  79.  
  80.           else if ((sz[i] == '\t') && (iTabs))
  81.         {
  82.           printf ("^%c", sz[i] + 64);
  83.         }
  84.  
  85.           else
  86.         {
  87.           printf ("%c", sz[i]);
  88.         }
  89.         }
  90.  
  91.       /* Print the EOL if needed */
  92.  
  93.       if (iEnds)
  94.         {
  95.           printf ("$");
  96.         }
  97.  
  98.       printf ("\n");
  99.     }
  100.     }
  101.  
  102.   return;
  103. }
  104.