TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Edwards
from: andrew clarke
date: 1996-04-02 01:04:16
subject: C beautifier programs

31 Mar 96 15:00, Paul Edwards wrote to david nugent:

 > The problem with GNU indent, at least the version I have, is that
 > you (or at least I) can't get it to generate code without tabs.

Straw men, Paul?

/* remtab.c 12-4-91 Robert Mashlan, Public Domain
   modified 28 mar 93 by Bob Stout

   Filter for removing tabs.  All tabs in the input will be replaced
   with spaces.  This filter takes one optional command line
   parameter, which specifies the number spaces to replace for a tab.
   If no size is specifies, it defaults to 8.

   example usage:

   remtab 6  untabbed.c

*/

#include 
#include 

#define BUFSIZE 4096


int main(int argc, char **argv )
{
      int tabsize = 8;

      if (argc > 1)                 /* look for command line parameter */
      {
            if (0 == (tabsize = atoi(argv[1])))
                  tabsize = 8;
      }

      while (1)
      {
            char buf[BUFSIZE];
            int nr, i, j, pos = 0;

            nr = fread(buf, 1, sizeof(buf), stdin);
            for (i = 0; i < nr; i++)
            {
                  switch (buf[i])
                  {
                  case '\t':              /* replace tabs with spaces   */
                        for(j = pos % tabsize; j < tabsize; ++j)
                        {
                              putchar(' ');
                              ++pos;
                        }
                        break;

                  case '\n':              /* start a new line           */
                        pos = -1;         /* this will become 0 when... */

                        /* ...we fall through to...   */

                  default:
                        putchar(buf[i]);/* send character through unchanged */
                        ++pos;
                  }
            }
            if (nr < sizeof(buf))
                  break;
      }
      return 0;
}


:-)

--- Msgedsq/2 3.30
* Origin: Blizzard of Ozz, Melbourne, Australia (3:635/727.4{at}fidonet)
SEEN-BY: 50/99 78/0 620/243 623/630 632/349 635/503 544 727 637/106 711/401
SEEN-BY: 711/409 410 413 430 808 809 932 934 712/515 713/888 714/906 800/1
SEEN-BY: 7877/2809
@PATH: 635/727 544 50/99 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.