/*
   <p>Test module for the tabs string expansion functions.</p>

   <kbd>
   <b>environ - C programming support functions</b><br>
   Copyright (C) 2005  Martin C Gregorie
   
   This program is free software; you can redistribute it and/or
   modify it under the terms of the Lesser GNU General Public License.
   
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
  
   You should have received a copy of the Lesser GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   </kbd>
  
   <p>Contact Martin Gregorie at <i>martin@gregorie.org</i></p>
*/

#include <stdio.h>
#include "environ.h"

main(int argc, char **argv)
{
    char    tabs[MAXLINE],
            data[MAXLINE],
            printline[MAXLINE];
    int     i,col;
    FILE    *inp;

    setprog(argv[0]);

    if (argc<2)
        error(progname(), "usage: testtab2 filename", "");
    
    tabnormal(tabs);

    for ( i=0; i<=MAXLINE; i++)
        if (tabpos(i,tabs))
            putchar('T');
        else
            putchar('.');

    printf("\n\n");

    inp = fopen(argv[1],"r");
    if (!inp) 
        error(progname(), "Failed to open", argv[1]);

    while (fgets(data,MAXLINE-1,inp))
    {
        col=0;
        for ( i=0; data[i]; i++)
        {
            if (data[i] == 9)
            {
                col = tabexpand(printline,col,tabs,BLANK);
            }
            else
                printline[col++] = data[i];
        }
        printline[col] = '\0';
        printf("%s",printline);
    }
    fclose(inp);

    return(0);
}
