summaryrefslogtreecommitdiffabout
path: root/etc/flncat.c
authorSergey Poznyakoff <gray@gnu.org>2013-12-03 13:32:12 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2013-12-03 13:32:12 (GMT)
commit5e501cf05fd1997018613304761d1104879353aa (patch) (side-by-side diff)
treefd14fa84bf80b72e8472f8451639e33501afe886 /etc/flncat.c
parent495c4a5cadf67b7c9b5e0c8b224f7b68c42c8da4 (diff)
downloadeclat-5e501cf05fd1997018613304761d1104879353aa.tar.gz
eclat-5e501cf05fd1997018613304761d1104879353aa.tar.bz2
Implement sg --list
* etc/Makefile.am (FLNFILES): Add lsattr.fln (.fln.forlan): Use all prerequisites, not only the first one. (FORMATFILES): Remove lsattr.forlan (lsattr.forlan): Use implicit rule. (sg.forlan): New rule * etc/flncat.c (comment): Optionally output the comment. (main): Output " else " only if some non-whitespace and non-comment characters were output before. * etc/lsattr.fln: New file * src/sg-cl.opt: New option --list. * src/sg.c (list_option): New variable.
Diffstat (limited to 'etc/flncat.c') (more/less context) (ignore whitespace changes)
-rw-r--r--etc/flncat.c48
1 files changed, 33 insertions, 15 deletions
diff --git a/etc/flncat.c b/etc/flncat.c
index 0c29453..82c4086 100644
--- a/etc/flncat.c
+++ b/etc/flncat.c
@@ -19,30 +19,44 @@
#include <assert.h>
int
-comment(FILE *fp, int c)
+comment(FILE *fp, int c, int echo)
{
if (c != '/') {
ungetc(c, fp);
return 0;
- }
+ } else if (echo)
+ fputc(c, stdout);
if ((c = getc(fp)) == '/') {
- while ((c = getc(fp)) != EOF && c != '\n')
- ;
+ do
+ if (echo) fputc(c, stdout);
+ while ((c = getc(fp)) != EOF && c != '\n');
return 1;
}
+
+ if (echo)
+ fputc(c, stdout);
if (c == '*') {
do {
- while ((c = getc(fp)) != '*') {
+ do {
+ c = getc(fp);
if (c == EOF)
return 0;
- }
- } while ((c = getc(fp)) != '/');
+ else if (echo)
+ fputc(c, stdout);
+ } while (c != '*');
+ c = getc(fp);
+ if (echo)
+ fputc(c, stdout);
+ } while (c != '/');
return 1;
+ } else
+
+ if (!echo) {
+ ungetc(c, fp);
+ ungetc('/', fp);
}
- ungetc(c, fp);
- ungetc('/', fp);
return 0;
}
@@ -54,6 +68,7 @@ main(int argc, char **argv)
int c;
char buf[128];
size_t lev = 0;
+ int outchars = 0;
for (i = 1; i < argc; i++) {
fp = fopen(*++argv, "r");
@@ -62,16 +77,19 @@ main(int argc, char **argv)
return 1;
}
- if (i > 1) {
- /* Skip whitespace and comment lines */
- do {
- while ((c = fgetc(fp)) != EOF && isspace(c))
- ;
- } while (c != EOF && comment(fp, c));
+ /* Skip initial whitespace and comment lines, unless it is the
+ first file we process. */
+ do {
+ while ((c = fgetc(fp)) != EOF && isspace(c))
+ if (i == 1) fputc(c, stdout);
+ } while (c != EOF && comment(fp, c, i == 1));
+
+ if (outchars) {
printf(" else ");
}
while ((c = fgetc(fp)) != EOF) {
+ outchars = 1;
putchar(c);
if (c == '}') {
lev = 0;

Return to:

Send suggestions and report system problems to the System administrator.