catv: code shrink

catv_main                                            250     227     -23

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2013-07-30 11:41:58 +02:00
parent 79c618c411
commit bfa6ed1bf4
2 changed files with 13 additions and 7 deletions

View File

@ -26,19 +26,22 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
int retval = EXIT_SUCCESS; int retval = EXIT_SUCCESS;
int fd; int fd;
unsigned opts; unsigned opts;
int flags = 0;
opts = getopt32(argv, "etv");
#define CATV_OPT_e (1<<0) #define CATV_OPT_e (1<<0)
#define CATV_OPT_t (1<<1) #define CATV_OPT_t (1<<1)
#define CATV_OPT_v (1<<2) #define CATV_OPT_v (1<<2)
typedef char BUG_const_mismatch[
CATV_OPT_e == VISIBLE_ENDLINE && CATV_OPT_t == VISIBLE_SHOW_TABS
? 1 : -1
];
opts = getopt32(argv, "etv");
argv += optind; argv += optind;
if (opts & (CATV_OPT_e | CATV_OPT_t)) #if 0 /* These consts match, we can just pass "opts" to visible() */
opts &= ~CATV_OPT_v;
if (opts & CATV_OPT_e) if (opts & CATV_OPT_e)
flags |= VISIBLE_ENDLINE; flags |= VISIBLE_ENDLINE;
if (opts & CATV_OPT_t) if (opts & CATV_OPT_t)
flags |= VISIBLE_SHOW_TABS; flags |= VISIBLE_SHOW_TABS;
#endif
/* Read from stdin if there's nothing else to do. */ /* Read from stdin if there's nothing else to do. */
if (!argv[0]) if (!argv[0])
@ -64,7 +67,7 @@ int catv_main(int argc UNUSED_PARAM, char **argv)
putchar(c); putchar(c);
} else { } else {
char buf[sizeof("M-^c")]; char buf[sizeof("M-^c")];
visible(c, buf, flags); visible(c, buf, opts);
fputs(buf, stdout); fputs(buf, stdout);
} }
} }

View File

@ -680,7 +680,10 @@ enum { PRINTABLE_META = 0x100 };
void fputc_printable(int ch, FILE *file) FAST_FUNC; void fputc_printable(int ch, FILE *file) FAST_FUNC;
/* Return a string that is the printable representation of character ch. /* Return a string that is the printable representation of character ch.
* Buffer must hold at least four characters. */ * Buffer must hold at least four characters. */
enum { VISIBLE_SHOW_TABS = 1, VISIBLE_ENDLINE = 2 }; enum {
VISIBLE_ENDLINE = 1 << 0,
VISIBLE_SHOW_TABS = 1 << 1,
};
void visible(unsigned ch, char *buf, int flags) FAST_FUNC; void visible(unsigned ch, char *buf, int flags) FAST_FUNC;
/* dmalloc will redefine these to it's own implementation. It is safe /* dmalloc will redefine these to it's own implementation. It is safe