3 mark translatable strings
5 call parse_long_options
7 do fclose/error checking
10 /* asa.c - interpret ASA carriage control characters
11 Copyright (C) 94, 1996 Thomas Koenig
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software Foundation,
25 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
38 #define MAX(a,b) ((a) > (b) ? (a) : (b))
40 /* Structures and unions */
47 typedef struct Str str
;
49 /* File scope variables */
51 static str
*line_buffer
= (str
*) 0;
52 static size_t line_num
= 0;
53 static size_t linebuf_size
;
55 /* Function declarations */
60 static size_t readline (FILE *fp
, char **a
);
61 static void add_line (str
*);
62 static void flush (void);
63 static void copy_file (FILE *fp
);
82 if (line_num
>= linebuf_size
)
84 linebuf_size
+= NUMLINES
;
85 line_buffer
= (str
*) xrealloc (line_buffer
, linebuf_size
* sizeof (str
*));
87 line_buffer
[line_num
] = *line
;
101 printf ("%s\n", line_buffer
[0].chr
+ 1);
106 for (j
= 0; j
< line_num
; j
++)
107 max_len
= MAX (max_len
, line_buffer
[j
].len
);
109 for (i
= 1; i
<= max_len
; i
++)
113 for (j
= 0; j
< line_num
; j
++)
115 if (line_buffer
[j
].len
> i
)
117 int ch
= line_buffer
[j
].chr
[i
];
131 for (j
= 0; j
< line_num
; j
++)
132 free (line_buffer
[j
].chr
);
139 readline (FILE *fp
, char **ret
)
141 static char *buffer
= (char *) 0;
143 static int bufsize
= LINESIZE
;
149 if (buffer
== (char *) 0)
150 buffer
= (char *) xmalloc (LINESIZE
);
165 if (len
+ inc
> bufsize
- 2)
168 buffer
= xrealloc (buffer
, bufsize
);
170 for (i
= 0; i
< inc
; i
++)
171 buffer
[len
+ i
] = ch
;
177 ret_buff
= xmalloc (len
+ 1);
178 strcpy (ret_buff
, buffer
);
187 static first_line
= 1;
189 while ((line
.len
= readline (fp
, &(line
.chr
))))
191 if (line
.chr
[line
.len
- 1] == '\n')
193 line
.chr
[line
.len
- 1] = '\0';
230 /* Global functions */
233 main (int argc
, char **argv
)
236 line_buffer
= (str
*) xmalloc (NUMLINES
* sizeof (str
*));
237 linebuf_size
= NUMLINES
;
250 if ((fp
= fopen (fname
, "r")) == NULL
)
253 error (0, errno
, "%s", fname
);
263 exit (err
? EXIT_FAILURE
: EXIT_SUCCESS
);