diff options
Diffstat (limited to 'text-utils')
-rw-r--r-- | text-utils/Makefile | 4 | ||||
-rw-r--r-- | text-utils/col.c | 24 | ||||
-rw-r--r-- | text-utils/colcrt.c | 179 | ||||
-rw-r--r-- | text-utils/colrm.c | 37 | ||||
-rw-r--r-- | text-utils/column.c | 2 | ||||
-rw-r--r-- | text-utils/display.c | 12 | ||||
-rw-r--r-- | text-utils/more.c | 261 | ||||
-rw-r--r-- | text-utils/more.help.ja | 24 | ||||
-rw-r--r-- | text-utils/ul.c | 128 |
9 files changed, 430 insertions, 241 deletions
diff --git a/text-utils/Makefile b/text-utils/Makefile index 3c4343bfb..2cead324d 100644 --- a/text-utils/Makefile +++ b/text-utils/Makefile @@ -17,6 +17,8 @@ BIN= more USRBIN= col colcrt colrm column hexdump rev +MAYBE= ul + ifeq "$(HAVE_NCURSES)" "yes" USRBIN:=$(USRBIN) ul MAN1:=$(MAN1) ul.1 @@ -78,6 +80,6 @@ install install.shadow install.text-utils: all .PHONY: clean distclean clean: - -rm -f *.o *~ core $(BIN) $(USRBIN) + -rm -f *.o *~ core $(BIN) $(USRBIN) $(MAYBE) distclean: clean diff --git a/text-utils/col.c b/text-utils/col.c index 1f740f425..2e1552a7a 100644 --- a/text-utils/col.c +++ b/text-utils/col.c @@ -78,6 +78,7 @@ typedef struct char_str { short c_column; /* column character is in */ CSET c_set; /* character set (currently only 2) */ wchar_t c_char; /* character in question */ + int c_width; /* character width */ } CHAR; typedef struct line_str LINE; @@ -225,6 +226,11 @@ int main(int argc, char **argv) cur_line -= 2; continue; } + if (iswspace(ch)) { + if (wcwidth(ch) > 0) + cur_col += wcwidth(ch); + continue; + } if (!pass_unknown_seqs) continue; } @@ -297,6 +303,7 @@ int main(int argc, char **argv) c->c_char = ch; c->c_set = cur_set; c->c_column = cur_col; + c->c_width = wcwidth(ch); /* * If things are put in out of order, they will need sorting * when it is flushed. @@ -305,7 +312,8 @@ int main(int argc, char **argv) l->l_needs_sort = 1; else l->l_max_col = cur_col; - cur_col++; + if (c->c_width > 0) + cur_col += c->c_width; } /* goto the last line that had a character on it */ for (; l->l_next; l = l->l_next) @@ -435,8 +443,12 @@ void flush_line(LINE *l) } while (--nchars > 0 && this_col == endc->c_column); /* if -b only print last character */ - if (no_backspaces) + if (no_backspaces) { c = endc - 1; + if (nchars > 0 && + this_col + c->c_width > endc->c_column) + continue; + } if (this_col > last_col) { int nspace = this_col - last_col; @@ -455,7 +467,6 @@ void flush_line(LINE *l) PUTC(' '); last_col = this_col; } - last_col++; for (;;) { if (c->c_set != last_set) { @@ -469,10 +480,15 @@ void flush_line(LINE *l) last_set = c->c_set; } PUTC(c->c_char); + if ((c+1) < endc) { + int i; + for (i=0; i < c->c_width; i++) + PUTC('\b'); + } if (++c >= endc) break; - PUTC('\b'); } + last_col += (c-1)->c_width; } } diff --git a/text-utils/colcrt.c b/text-utils/colcrt.c index 55138f161..efb176f31 100644 --- a/text-utils/colcrt.c +++ b/text-utils/colcrt.c @@ -39,6 +39,7 @@ */ #include <stdio.h> +#include <stdlib.h> #include <unistd.h> /* for close() */ #include <string.h> #include "nls.h" @@ -72,13 +73,11 @@ char suppresul; char printall; char *progname; +void colcrt(FILE *f); int -main(int argc, char **argv) -{ +main(int argc, char **argv) { FILE *f; - wint_t c; - wchar_t *cp, *dp; setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); @@ -113,78 +112,7 @@ main(int argc, char **argv) argc--; argv++; } - for (;;) { - c = getwc(f); - if (c == -1) { - pflush(outline); - fflush(stdout); - break; - } - switch (c) { - case '\n': - if (outline >= 265) - pflush(62); - outline += 2; - outcol = 0; - continue; - case '\016': - case '\017': - continue; - case 033: - c = getwc(f); - switch (c) { - case '9': - if (outline >= 266) - pflush(62); - outline++; - continue; - case '8': - if (outline >= 1) - outline--; - continue; - case '7': - outline -= 2; - if (outline < 0) - outline = 0; - continue; - default: - continue; - } - case '\b': - if (outcol) - outcol--; - continue; - case '\t': - outcol += 8; - outcol &= ~7; - outcol--; - c = ' '; - default: - if (outcol >= 132) { - outcol++; - continue; - } - cp = &page[outline][outcol]; - outcol++; - if (c == '_') { - if (suppresul) - continue; - cp += 132; - c = '-'; - } - if (*cp == 0) { - *cp = c; - dp = cp - outcol; - for (cp--; cp >= dp && *cp == 0; cp--) - *cp = ' '; - } else - if (plus(c, *cp) || plus(*cp, c)) - *cp = '+'; - else if (*cp == ' ' || *cp == 0) - *cp = c; - continue; - } - } + colcrt(f); if (f != stdin) fclose(f); } while (argc > 0); @@ -194,6 +122,95 @@ main(int argc, char **argv) return 0; } +void +colcrt(FILE *f) { + wint_t c; + wchar_t *cp, *dp; + int i, w; + + for (;;) { + c = getwc(f); + if (c == WEOF) { + pflush(outline); + fflush(stdout); + break; + } + switch (c) { + case '\n': + if (outline >= 265) + pflush(62); + outline += 2; + outcol = 0; + continue; + case '\016': + case '\017': + continue; + case 033: + c = getwc(f); + switch (c) { + case '9': + if (outline >= 266) + pflush(62); + outline++; + continue; + case '8': + if (outline >= 1) + outline--; + continue; + case '7': + outline -= 2; + if (outline < 0) + outline = 0; + continue; + default: + continue; + } + case '\b': + if (outcol) + outcol--; + continue; + case '\t': + outcol += 8; + outcol &= ~7; + outcol--; + c = ' '; + default: + w = wcwidth(c); + if (outcol + w > 132) { + outcol++; + continue; + } + cp = &page[outline][outcol]; + outcol += w; + if (c == '_') { + if (suppresul) + continue; + cp += 132; + c = '-'; + } + if (*cp == 0) { + /* trick! */ + for (i=0; i<w; i++) + cp[i] = c; + dp = cp - (outcol-w); + for (cp--; cp >= dp && *cp == 0; cp--) + *cp = ' '; + } else { + if (plus(c, *cp) || plus(*cp, c)) + *cp = '+'; + else if (*cp == ' ' || *cp == 0) { + for (i=1; i<w; i++) + if (cp[i] != ' ' && cp[i] != 0) + continue; + for (i=0; i<w; i++) + cp[i] = c; + } + } + continue; + } + } +} + int plus(wchar_t c, wchar_t d) { @@ -207,7 +224,7 @@ void pflush(int ol) register int i; register wchar_t *cp; char lastomit; - int l; + int l, w; l = ol; lastomit = 0; @@ -226,7 +243,13 @@ void pflush(int ol) continue; } lastomit = 0; - fputws(cp, stdout); + while (*cp) { + if ((w = wcwidth(*cp)) > 0) { + putwchar(*cp); + cp += w; + } else + cp++; + } putwchar('\n'); } bcopy(page[ol], page, (267 - ol) * 132 * sizeof(wchar_t)); diff --git a/text-utils/colrm.c b/text-utils/colrm.c index 0297ccb53..1b90fe4ab 100644 --- a/text-utils/colrm.c +++ b/text-utils/colrm.c @@ -54,6 +54,8 @@ main(int argc, char **argv) { register int ct, first, last; register wint_t c; + int i, w; + int padding; setlocale(LC_ALL, ""); @@ -71,11 +73,15 @@ loop1: if (feof(stdin)) goto fin; if (c == '\t') - ct = (ct + 8) & ~7; + w = ((ct + 8) & ~7) - ct; else if (c == '\b') - ct = ct ? ct - 1 : 0; - else - ct++; + w = (ct ? ct - 1 : 0) - ct; + else { + w = wcwidth(c); + if (w < 0) + w = 0; + } + ct += w; if (c == '\n') { putwc(c, stdout); goto start; @@ -84,6 +90,8 @@ loop1: putwc(c, stdout); goto loop1; } + for (i = ct-w+1; i < first; i++) + putwc(' ', stdout); /* Loop getting rid of characters */ while (!last || ct < last) { @@ -98,18 +106,31 @@ loop1: ct = (ct + 8) & ~7; else if (c == '\b') ct = ct ? ct - 1 : 0; - else - ct++; + else { + w = wcwidth(c); + if (w < 0) + w = 0; + ct += w; + } } + padding = 0; + /* Output last of the line */ for (;;) { c = getwc(stdin); if (feof(stdin)) break; - putwc(c, stdout); - if (c == '\n') + if (c == '\n') { + putwc(c, stdout); goto start; + } + if (padding == 0 && last < ct) { + for (i = last; i <ct; i++) + putwc(' ', stdout); + padding = 1; + } + putwc(c, stdout); } fin: fflush(stdout); diff --git a/text-utils/column.c b/text-utils/column.c index cfea89fb7..79ebb115b 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -302,7 +302,7 @@ input(fp) continue; } *p = '\0'; - len = p - buf; + len = wcs_width(buf); /* len = p - buf; */ if (maxlength < len) maxlength = len; if (entries == maxentry) { diff --git a/text-utils/display.c b/text-utils/display.c index 481d2b1ae..145508813 100644 --- a/text-utils/display.c +++ b/text-utils/display.c @@ -209,7 +209,6 @@ static char **_argv; static u_char * get(void) { - extern enum _vflag vflag; extern int length; static int ateof = 1; static u_char *curp, *savp; @@ -341,19 +340,16 @@ doskip(char *fname, int statok) } char * -emalloc(int size) -{ +emalloc(int sz) { char *p; - if (!(p = malloc((u_int)size))) + if (!(p = malloc((u_int)sz))) nomem(); - bzero(p, size); + bzero(p, sz); return(p); } -void nomem() -{ - +void nomem() { (void)fprintf(stderr, "hexdump: %s.\n", strerror(errno)); exit(1); } diff --git a/text-utils/more.c b/text-utils/more.c index b7c9d76a2..79dc626dd 100644 --- a/text-utils/more.c +++ b/text-utils/more.c @@ -62,7 +62,7 @@ #undef _REGEX_RE_COMP /* #define MOREHELPFILE "/usr/lib/more.help" */ -#define VI "/usr/bin/vi" +#define VI "vi" /* found on the user's path */ #define Fopen(s,m) (Currline = 0,file_pos=0,fopen(s,m)) #define Ftell(f) file_pos @@ -83,7 +83,7 @@ void error (char *mess); void do_shell (char *filename); int colon (char *filename, int cmd, int nlines); int expand (char **outbuf, char *inbuf); -void argscan(char *s); +void argscan(char *s,char *argv0); void rdline (register FILE *f); void copy_file(register FILE *f); void search(char buf[], FILE *file, register int n); @@ -142,9 +142,8 @@ char **fnames; /* The list of file names */ int nfiles; /* Number of files left to process */ char *shell; /* The name of the shell to use */ int shellp; /* A previous shell command exists */ -char ch; sigjmp_buf restore; -char Line[LINSIZ]; /* Line buffer */ +char Line[LINSIZ+2]; /* Line buffer */ int Lpp = 24; /* lines per page */ char *Clear; /* clear screen */ char *eraseln; /* erase line */ @@ -256,6 +255,14 @@ idummy(int *kk) {} static void Fdummy(FILE **ff) {} +static void +usage(char *s) { + char *p = strrchr(s, '/'); + fprintf(stderr, + _("usage: %s [-dflpcsu] [+linenum | +/pattern] name1 name2 ...\n"), + p ? p + 1 : s); +} + int main(int argc, char **argv) { FILE *f; char *s; @@ -286,10 +293,10 @@ int main(int argc, char **argv) { nscroll = Lpp/2 - 1; if (nscroll <= 0) nscroll = 1; - if((s = getenv("MORE")) != NULL) argscan(s); + if((s = getenv("MORE")) != NULL) argscan(s,argv[0]); while (--nfiles > 0) { if ((ch = (*++fnames)[0]) == '-') { - argscan(*fnames+1); + argscan(*fnames+1,argv[0]); } else if (ch == '+') { s = *fnames; @@ -326,10 +333,7 @@ int main(int argc, char **argv) { if (nfiles > 1) prnames++; if (!no_intty && nfiles == 0) { - p = strrchr(argv[0], '/'); - fprintf(stderr, - _("usage: %s [-dfln] [+linenum | +/pattern] name1 name2 ...\n"), - p ? p + 1 : argv[0]); + usage(argv[0]); exit(1); } else @@ -439,7 +443,7 @@ int main(int argc, char **argv) { exit(0); } -void argscan(char *s) { +void argscan(char *s, char *argv0) { int seen_num = 0; while (*s != '\0') { @@ -475,6 +479,16 @@ void argscan(char *s) { case 'u': ul_opt = 0; break; + case '-': case ' ': case '\t': + break; + default: + fputs(argv0,stderr); + fputs(": unknown option \"-",stderr); + putc(*s,stderr); + fputs("\"\n",stderr); + usage(argv0); + exit(1); + break; } s++; } @@ -645,8 +659,9 @@ void onquit(int dummy) { Pause++; } else if (!dum_opt && notell) { - errwrite(_("[Use q or Q to quit]")); - promptlen += 20; + char *s = _("[Use q or Q to quit]"); + errwrite(s); + promptlen += strlen(s); notell = 0; } signal(SIGQUIT, onquit); @@ -705,11 +720,10 @@ void copy_file(register FILE *f) { /* Simplified printf function */ -int xprintf (char *fmt, ...) -{ +int xprintf (char *fmt, ...) { va_list ap; - register char ch; - register int ccount; + char ch; + int ccount; ccount = 0; va_start(ap, fmt); @@ -801,8 +815,8 @@ static int tailequ (char *path, register char *string) register char *tail; tail = path + strlen(path); - while (tail >= path) - if (*(--tail) == '/') + while (--tail >= path) + if (*tail == '/') break; ++tail; while (*tail++ == *string++) @@ -818,19 +832,19 @@ static void prompt (char *filename) else if (promptlen > 0) kill_line (); if (!hard) { - promptlen = 8; + promptlen = 0; if (Senter && Sexit) { my_putstring (Senter); promptlen += (2 * soglitch); } if (clreol) cleareol (); - pr(_("--More--")); + promptlen += pr(_("--More--")); if (filename != NULL) { promptlen += xprintf (_("(Next file: %s)"), filename); - } - else if (!no_intty) { - promptlen += xprintf ("(%d%%)", (int)((file_pos * 100) / file_size)); + } else if (!no_intty) { + promptlen += xprintf ("(%d%%)", + (int)((file_pos * 100) / file_size)); } if (dum_opt) { promptlen += pr(_("[Press space to continue, 'q' to quit.]")); @@ -879,6 +893,20 @@ int get_line(register FILE *f, int *length) break; } *p++ = c; +#if 0 + if (c == '\033') { /* ESC */ + c = Getc(f); + while (c > ' ' && c < '0' && p < &Line[LINSIZ - 1]) { + *p++ = c; + c = Getc(f); + } + if (c >= '0' && c < '\177' && p < &Line[LINSIZ - 1]) { + *p++ = c; + c = Getc(f); + continue; + } + } +#endif if (c == '\t') { if (!hardtabs || (column < promptlen && !hard)) { if (hardtabs && eraseln && !dumb) { @@ -917,9 +945,31 @@ int get_line(register FILE *f, int *length) *length = p - Line; return (column); } +#if 0 + else { + char ch[2]; /* for mblen() */ + + ch[0] = c; + ch[1] = '\0'; + if (mblen(ch, 1) <= 0) { /* multibyte, maybe 2 columns */ + if (column == Mcol-1 && fold_opt) { + p--; + Ungetc(c, f); + break; + } + *p++ = Getc(f); + column += 2; + } else if (c & 0x80) { /* maybe SJIS KANA, or utf-8 ? */ + column++; + } else if (isprint(c)) + column++; + } +#else else if (isprint(c)) - column++; - if (column >= Mcol && fold_opt) break; + column++; +#endif + if (column >= Mcol && fold_opt) + break; c = Getc (f); } if (column >= Mcol && Mcol > 0) { @@ -1255,7 +1305,26 @@ int command (char *filename, register FILE *f) break; case '?': case 'h': - if ((helpf = fopen (MOREHELPFILE, "r")) == NULL) + helpf = NULL; + { + char *lang; + char hlpfile[sizeof(MOREHELPFILE)+4]; + + lang = getenv("LANGUAGE"); + if (!lang || *lang == '\0') + lang = setlocale(LC_MESSAGES, ""); + if (!lang || *lang == '\0') + lang = getenv("LANG"); + if (lang && strlen(lang) > 1) { + strcpy(hlpfile, MOREHELPFILE); + strcat(hlpfile, "."); + strncat(hlpfile, lang, 2); + helpf = fopen (hlpfile, "r"); + } + } + if (helpf == NULL) + helpf = fopen (MOREHELPFILE, "r"); + if (helpf == NULL) error (_("Can't open help file")); if (noscroll) doclear (); copy_file (helpf); @@ -1264,13 +1333,22 @@ int command (char *filename, register FILE *f) break; case 'v': /* This case should go right before default */ if (!no_intty) { - kill_line (); - cmdbuf[0] = '+'; - scanstr (Currline - dlines < 0 ? 0 - : Currline - (dlines + 1) / 2, &cmdbuf[1]); - pr ("vi "); pr (cmdbuf); putchar (' '); pr (fnames[fnum]); - execute (filename, VI, "vi", cmdbuf, fnames[fnum], 0); - break; + char *editor; + + editor = getenv("VISUAL"); + if (editor == NULL || *editor == '\0') + editor = getenv("EDITOR"); + if (editor == NULL || *editor == '\0') + editor = VI; + + kill_line (); + cmdbuf[0] = '+'; + scanstr (Currline - dlines <= 0 ? 1 + : Currline - (dlines + 1) / 2, &cmdbuf[1]); + pr (editor); putchar (' '); + pr (cmdbuf); putchar (' '); pr (fnames[fnum]); + execute (filename, editor, editor, cmdbuf, fnames[fnum], 0); + break; } default: if (dum_opt) { @@ -1297,7 +1375,7 @@ endsw: return (retval); } -char ch; +static char ch; /* * Execute a colon-prefixed command. @@ -1305,8 +1383,7 @@ char ch; * more of the file to be printed. */ -int colon (char *filename, int cmd, int nlines) -{ +int colon (char *filename, int cmd, int nlines) { if (cmd == 0) ch = readch (); else @@ -1540,7 +1617,7 @@ void execute (char * filename, char * cmd, ...) } va_end(argp); - execv (cmd, args); + execvp (cmd, args); errwrite(_("exec failed\n")); exit (1); } @@ -1678,7 +1755,7 @@ retry: bad_so = my_tgetflag ("xs","xhp"); eraseln = my_tgetstr("ce","el"); Clear = my_tgetstr("cl","clear"); - Senter = my_tgetstr("co","smso"); + Senter = my_tgetstr("so","smso"); Sexit = my_tgetstr("se","rmso"); if ((soglitch = my_tgetnum("sg","xmc")) < 0) soglitch = 0; @@ -1738,18 +1815,17 @@ retry: } } -int readch () -{ - char ch; +int readch () { + char c; errno = 0; - if (read (2, &ch, 1) <= 0) { + if (read (2, &c, 1) <= 0) { if (errno != EINTR) end_it(0); else - ch = otty.c_cc[VKILL]; + c = otty.c_cc[VKILL]; } - return (ch); + return (c); } static char *BS = "\b"; @@ -1761,28 +1837,27 @@ static char *CARAT = "^"; else \ errwrite(BS); -void ttyin (char buf[], register int nmax, char pchar) -{ - register char *sptr; - register char ch; - register int slash = 0; +void ttyin (char buf[], register int nmax, char pchar) { + char *sp; + char c; + int slash = 0; int maxlen; char cbuf; - sptr = buf; + sp = buf; maxlen = 0; - while (sptr - buf < nmax) { + while (sp - buf < nmax) { if (promptlen > maxlen) maxlen = promptlen; - ch = readch (); - if (ch == '\\') { + c = readch (); + if (c == '\\') { slash++; } - else if (((cc_t) ch == otty.c_cc[VERASE]) && !slash) { - if (sptr > buf) { + else if (((cc_t) c == otty.c_cc[VERASE]) && !slash) { + if (sp > buf) { --promptlen; ERASEONECHAR - --sptr; - if ((*sptr < ' ' && *sptr != '\n') || *sptr == RUBOUT) { + --sp; + if ((*sp < ' ' && *sp != '\n') || *sp == RUBOUT) { --promptlen; ERASEONECHAR } @@ -1793,9 +1868,9 @@ void ttyin (char buf[], register int nmax, char pchar) siglongjmp (restore, 1); } } - else if (((cc_t) ch == otty.c_cc[VKILL]) && !slash) { + else if (((cc_t) c == otty.c_cc[VKILL]) && !slash) { if (hard) { - show (ch); + show (c); putchar ('\n'); putchar (pchar); } @@ -1809,43 +1884,42 @@ void ttyin (char buf[], register int nmax, char pchar) errwrite(BSB); promptlen = 1; } - sptr = buf; + sp = buf; fflush (stdout); continue; } - if (slash && ((cc_t) ch == otty.c_cc[VKILL] - || (cc_t) ch == otty.c_cc[VERASE])) { + if (slash && ((cc_t) c == otty.c_cc[VKILL] + || (cc_t) c == otty.c_cc[VERASE])) { ERASEONECHAR - --sptr; + --sp; } - if (ch != '\\') + if (c != '\\') slash = 0; - *sptr++ = ch; - if ((ch < ' ' && ch != '\n' && ch != ESC) || ch == RUBOUT) { - ch += ch == RUBOUT ? -0100 : 0100; + *sp++ = c; + if ((c < ' ' && c != '\n' && c != ESC) || c == RUBOUT) { + c += (c == RUBOUT) ? -0100 : 0100; errwrite(CARAT); promptlen++; } - cbuf = ch; - if (ch != '\n' && ch != ESC) { + cbuf = c; + if (c != '\n' && c != ESC) { errwrite1(&cbuf); promptlen++; } else break; } - *--sptr = '\0'; + *--sp = '\0'; if (!eraseln) promptlen = maxlen; - if (sptr - buf >= nmax - 1) + if (sp - buf >= nmax - 1) error (_("Line too long")); } /* return: 0 - unchanged, 1 - changed, -1 - overflow (unchanged) */ -int expand (char **outbuf, char *inbuf) -{ - char *instr; +int expand (char **outbuf, char *inbuf) { + char *inpstr; char *outstr; - char ch; + char c; char *temp; int changed = 0; int tempsz, xtra, offset; @@ -1857,9 +1931,9 @@ int expand (char **outbuf, char *inbuf) error (_("Out of memory")); return -1; } - instr = inbuf; + inpstr = inbuf; outstr = temp; - while ((ch = *instr++) != '\0'){ + while ((c = *inpstr++) != '\0'){ offset = outstr-temp; if (tempsz-offset-1 < xtra) { tempsz += 200 + xtra; @@ -1870,14 +1944,14 @@ int expand (char **outbuf, char *inbuf) } outstr = temp + offset; } - switch (ch) { + switch (c) { case '%': if (!no_intty) { strcpy (outstr, fnames[fnum]); outstr += strlen (fnames[fnum]); changed++; } else - *outstr++ = ch; + *outstr++ = c; break; case '!': if (!shellp) @@ -1887,12 +1961,12 @@ int expand (char **outbuf, char *inbuf) changed++; break; case '\\': - if (*instr == '%' || *instr == '!') { - *outstr++ = *instr++; + if (*inpstr == '%' || *inpstr == '!') { + *outstr++ = *inpstr++; break; } default: - *outstr++ = ch; + *outstr++ = c; } } *outstr++ = '\0'; @@ -1900,16 +1974,15 @@ int expand (char **outbuf, char *inbuf) return (changed); } -void show (register char ch) -{ +void show (char c) { char cbuf; - if ((ch < ' ' && ch != '\n' && ch != ESC) || ch == RUBOUT) { - ch += ch == RUBOUT ? -0100 : 0100; + if ((c < ' ' && c != '\n' && c != ESC) || c == RUBOUT) { + c += (c == RUBOUT) ? -0100 : 0100; errwrite(CARAT); promptlen++; } - cbuf = ch; + cbuf = c; errwrite1(&cbuf); promptlen++; } @@ -1944,20 +2017,20 @@ void error (char *mess) } -void set_tty () -{ +void set_tty () { otty.c_lflag &= ~(ICANON|ECHO); otty.c_cc[VMIN] = 1; /* read at least 1 char */ otty.c_cc[VTIME] = 0; /* no timeout */ stty(fileno(stderr), &otty); } -static int ourputch(int ch) { - return putc(ch, stdout); +static int +ourputch(int c) { + return putc(c, stdout); } -void reset_tty () -{ +void +reset_tty () { if (no_tty) return; if (pstate) { diff --git a/text-utils/more.help.ja b/text-utils/more.help.ja new file mode 100644 index 000000000..3654e89d3 --- /dev/null +++ b/text-utils/more.help.ja @@ -0,0 +1,24 @@ + +コマンドの多くは前に数値(k)を付けることができます。[] 内の値がデフォルトです。 +星印(*)はデフォルトが変更されることを示します。 +------------------------------------------------------------------------------- +<space> 次の k 行を表示する [現在の画面サイズ] +z 次の k 行を表示する [現在の画面サイズ]* +<return> 次の k 行を表示する [1]* +d or ctrl-D k 行スクロールする [現在のスクロール行数 初期値は 11]* +q or Q or <interrupt> more を終了する +s 次の k 行を読み飛ばす [1] +f 次の k 画面を読み飛ばす [1] +b or ctrl-B k 画面戻る [1] +' 前回の検索を開始した位置に戻る += 現在の行番号を表示する +/<正規表現> 正規表現を検索し、k 番目の位置に飛ぶ [1] +n 前回の検索を再実行し、k 番目の位置に飛ぶ [1] +!<cmd> or :!<cmd> サブシェルで <cmd> を実行する +v vi を起動する +ctrl-L 画面を再描画する +:n 次の k 番目のファイルを表示する [1] +:p 前の k 番目のファイルを表示する [1] +:f 現在のファイル名と行番号を表示する +. 直前のコマンドを繰り返す +------------------------------------------------------------------------------- diff --git a/text-utils/ul.c b/text-utils/ul.c index 419efc938..570c4f47d 100644 --- a/text-utils/ul.c +++ b/text-utils/ul.c @@ -71,9 +71,10 @@ void initbuf(void); void fwd(void); void reverse(void); void initinfo(void); -void outc(wint_t c); +void outc(wint_t c, int width); void setmode(int newmode); -void setcol(int newcol); +static void setcol(int newcol); +static void needcol(int col); #define IESC '\033' #define SO '\016' @@ -98,6 +99,7 @@ char *CURS_UP, *CURS_RIGHT, *CURS_LEFT, struct CHAR { char c_mode; wchar_t c_char; + int c_width; } ; struct CHAR *obuf; @@ -180,6 +182,7 @@ int main(int argc, char **argv) void filter(FILE *f) { wint_t c; + int i, w; while ((c = getwc(f)) != WEOF) switch(c) { @@ -245,10 +248,18 @@ void filter(FILE *f) continue; case '_': - if (obuf[col].c_char) - obuf[col].c_mode |= UNDERL | mode; - else - obuf[col].c_char = '_'; + if (obuf[col].c_char || obuf[col].c_width < 0) { + while(col > 0 && obuf[col].c_width < 0) + col--; + w = obuf[col].c_width; + for (i = 0; i < w; i++) + obuf[col++].c_mode |= UNDERL | mode; + setcol(col); + continue; + } + obuf[col].c_char = '_'; + obuf[col].c_width = 1; + /* fall through */ case ' ': setcol(col + 1); continue; @@ -265,17 +276,31 @@ void filter(FILE *f) default: if (!iswprint(c)) /* non printing */ continue; + w = wcwidth(c); + needcol(col + w); if (obuf[col].c_char == '\0') { obuf[col].c_char = c; - obuf[col].c_mode = mode; + for (i = 0; i < w; i++) + obuf[col+i].c_mode = mode; + obuf[col].c_width = w; + for (i = 1; i < w; i++) + obuf[col+i].c_width = -1; } else if (obuf[col].c_char == '_') { obuf[col].c_char = c; - obuf[col].c_mode |= UNDERL|mode; - } else if (obuf[col].c_char == c) - obuf[col].c_mode |= BOLD|mode; - else - obuf[col].c_mode = mode; - setcol(col + 1); + for (i = 0; i < w; i++) + obuf[col+i].c_mode |= UNDERL|mode; + obuf[col].c_width = w; + for (i = 1; i < w; i++) + obuf[col+i].c_width = -1; + } else if (obuf[col].c_char == c) { + for (i = 0; i < w; i++) + obuf[col+i].c_mode |= BOLD|mode; + } else { + w = obuf[col].c_width; + for (i = 0; i < w; i++) + obuf[col+i].c_mode = mode; + } + setcol(col + w); continue; } if (maxcol) @@ -299,9 +324,11 @@ void flushln(void) if (upln) { PRINT(CURS_RIGHT); } else - outc(' '); + outc(' ', 1); } else - outc(obuf[i].c_char); + outc(obuf[i].c_char, obuf[i].c_width); + if (obuf[i].c_width > 1) + i += obuf[i].c_width -1; } if (lastmode != NORMAL) { setmode(0); @@ -344,6 +371,8 @@ void overstrike(void) break; case BOLD: *cp++ = obuf[i].c_char; + if (obuf[i].c_width > 1) + i += obuf[i].c_width - 1; hadbold=1; break; } @@ -473,12 +502,16 @@ void initinfo(void) static int curmode = 0; -void outc(wint_t c) -{ +void +outc(wint_t c, int width) { + int i; + putwchar(c); if (must_use_uc && (curmode&UNDERL)) { - PRINT(CURS_LEFT); - PRINT(UNDER_CHAR); + for (i=0; i<width; i++) + PRINT(CURS_LEFT); + for (i=0; i<width; i++) + PRINT(UNDER_CHAR); } } @@ -533,39 +566,40 @@ void setmode(int newmode) curmode = newmode; } - - - -void setcol(int newcol) -{ +static void +setcol(int newcol) { col = newcol; if (col < 0) col = 0; - else if (col > maxcol) { - maxcol = col; - - /* If col >= obuflen, expand obuf until obuflen > col. */ - while (col >= obuflen) { - /* Paranoid check for obuflen == INT_MAX. */ - if (obuflen == INT_MAX) { - fprintf(stderr, - _("Input line too long.\n")); - exit(1); - } + else if (col > maxcol) + needcol(col); +} - /* Similar paranoia: double only up to INT_MAX. */ - obuflen = ((INT_MAX / 2) < obuflen) - ? INT_MAX - : obuflen * 2; - - /* Now we can try to expand obuf. */ - obuf = realloc(obuf, sizeof(struct CHAR) * obuflen); - if (obuf == NULL) { - fprintf(stderr, - _("Out of memory when growing buffer.\n")); - exit(1); - } +static void +needcol(int col) { + maxcol = col; + + /* If col >= obuflen, expand obuf until obuflen > col. */ + while (col >= obuflen) { + /* Paranoid check for obuflen == INT_MAX. */ + if (obuflen == INT_MAX) { + fprintf(stderr, + _("Input line too long.\n")); + exit(1); + } + + /* Similar paranoia: double only up to INT_MAX. */ + obuflen = ((INT_MAX / 2) < obuflen) + ? INT_MAX + : obuflen * 2; + + /* Now we can try to expand obuf. */ + obuf = realloc(obuf, sizeof(struct CHAR) * obuflen); + if (obuf == NULL) { + fprintf(stderr, + _("Out of memory when growing buffer.\n")); + exit(1); } } } |