home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / fixline.c < prev    next >
Text File  |  1994-09-25  |  2KB  |  79 lines

  1. /*  fixline.c   This routine expands tabs and removes escape characters.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  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.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. /* Expand tabs to 8 spaces.  Removes ESC chars.  Returns a copy of the new
  26.    line in the buffer originally passed.  Buffer must be large enough for
  27.    expanded line.  Does not check for overflow.  Rewritten by REB. */
  28.  
  29. #include "uucp.h"
  30. #include <ctype.h>
  31.  
  32. #define TABSIZE   8
  33.  
  34.  
  35. int fixline (line)
  36. char *line;
  37. {
  38.      register char *p;
  39.      char *nptr, *strdetab();
  40.      char newline[256];
  41.      flag escflag = FALSE;
  42.  
  43.      nptr = newline;
  44.      *nptr = '\0';
  45.  
  46.      if ((p = strchr (line, '\x0A')) != NULL)        /* LF -> CR */
  47.           *p = '\n';
  48.  
  49.      p = line;
  50.  
  51.      if (strchr (p, '\t') == NULL  &&  strchr (p, '\x1b') == NULL)
  52.           return (0);
  53.  
  54.      if (strchr (p, '\t') != NULL)                   /* zap tabs */
  55.           p = strdetab (p, TABSIZE);
  56.  
  57.      while (*p)
  58.           switch (*p)
  59.             {
  60.                case '\x1b':                          /* strip escape */
  61.                     escflag = TRUE;
  62.                     ++p;
  63.  
  64.                     while (*p && (isdigit (*p) || *p == '[' || *p == ';'))
  65.                          ++p;
  66.                     break;
  67.  
  68.                default:
  69.                     *nptr++ = *p++;
  70.                     *nptr = '\0';
  71.                     break;
  72.             }
  73.  
  74.      if (escflag)
  75.           strcpy (line, newline);
  76.  
  77.      return (0);
  78. }
  79.