1 /* @source notab application
2 **
3 ** Replace tabs with spaces in an ASCII text file
4 ** @author Copyright (C) Jon Ison (jison@ebi.ac.uk)
5 ** @@
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software
19 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 ******************************************************************************/
21 
22 #include "emboss.h"
23 
24 
25 
26 
27 /* @prog notab ****************************************************************
28 **
29 ** Replace tabs with spaces in an ASCII text file
30 **
31 ******************************************************************************/
32 
main(int argc,char ** argv)33 int main(int argc, char **argv)
34 {
35     /* Variable Declarations */
36     AjPFile inf     = NULL;
37     AjPFile outf    = NULL;
38 
39     AjPStr  line    = NULL;  /* Line from inf    */
40     AjPStr  outline    = NULL;  /* Line to write    */
41     AjPStr tmpstr = NULL;
42 
43     AjPRegexp tabexp = NULL;
44     ajuint ilen;
45     ajuint irest;
46 
47     /* ACD File Processing */
48     embInit("notab", argc, argv);
49     inf  = ajAcdGetInfile("infile");
50     outf = ajAcdGetOutfile("outfile");
51     tabexp = ajRegCompC("\t");
52 
53     /* Application logic */
54     line = ajStrNew();
55     while(ajReadline(inf,&line))
56     {
57         ilen = 0;
58         ajStrAssignClear(&outline);
59         while(ajRegExec(tabexp, line))
60         {
61             ajRegPre(tabexp, &tmpstr);
62             ajStrAppendS(&outline, tmpstr);
63             ilen += ajStrGetLen(tmpstr);
64             irest = 8 - (ilen - 8*(ilen/8));
65             ajStrAppendCountK(&outline, ' ', irest);
66             ilen += irest;
67             ajRegPost(tabexp, &tmpstr);
68             ajStrAssignS(&line, tmpstr);
69             ajDebug("ilen: %u irest: %u\n'%S'\n",
70                    ilen, irest, outline);
71         }
72         ajStrAppendS(&outline, line);
73 
74 	ajFmtPrintF(outf, "%S", outline);
75     }
76 
77     /* Memory management and exit */
78     ajFileClose(&inf);
79     ajFileClose(&outf);
80     ajRegFree(&tabexp);
81     ajStrDel(&line);
82     ajStrDel(&outline);
83     ajStrDel(&tmpstr);
84 
85     embExit();
86 
87     return 0;
88 }
89 
90