static int do_output_char(unsigned char c, struct tty_struct *tty, int space) { int spaces; if (!space) return -1; switch (c) { case '\n': if (O_ONLRET(tty)) tty->column = 0; if (O_ONLCR(tty)) { if (space < 2) return -1; tty->canon_column = tty->column = 0; tty->ops->write(tty, "\r\n", 2); return 2; } tty->canon_column = tty->column; break; case '\r': if (O_ONOCR(tty) && tty->column == 0) return 0; if (O_OCRNL(tty)) { c = '\n'; if (O_ONLRET(tty)) tty->canon_column = tty->column = 0; break; } tty->canon_column = tty->column = 0; break; case '\t': spaces = 8 - (tty->column & 7); if (O_TABDLY(tty) == XTABS) { if (space < spaces) return -1; tty->column += spaces; tty->ops->write(tty, " ", spaces); return spaces; } tty->column += spaces; break; case '\b': if (tty->column > 0) tty->column--; break; default: if (!iscntrl(c)) { if (O_OLCUC(tty)) c = toupper(c); if (!is_continuation(c, tty)) tty->column++; } break; } tty_put_char(tty, c); return 1; }
static int opost(unsigned char c, struct tty_struct *tty) { int space, spaces; space = tty->driver->write_room(tty); if (!space) return -1; if (O_OPOST(tty)) { switch (c) { case '\n': if (O_ONLRET(tty)) tty->column = 0; if (O_ONLCR(tty)) { if (space < 2) return -1; tty->driver->put_char(tty, '\r'); tty->column = 0; } tty->canon_column = tty->column; break; case '\r': if (O_ONOCR(tty) && tty->column == 0) return 0; if (O_OCRNL(tty)) { c = '\n'; if (O_ONLRET(tty)) tty->canon_column = tty->column = 0; break; } tty->canon_column = tty->column = 0; break; case '\t': spaces = 8 - (tty->column & 7); if (O_TABDLY(tty) == XTABS) { if (space < spaces) return -1; tty->column += spaces; tty->driver->write(tty, " ", spaces); return 0; } tty->column += spaces; break; case '\b': if (tty->column > 0) tty->column--; break; default: if (O_OLCUC(tty)) c = toupper(c); if (!iscntrl(c) && !is_continuation(c, tty)) tty->column++; break; } } tty->driver->put_char(tty, c); return 0; }
static ssize_t process_output_block(struct tty_struct *tty, const unsigned char *buf, unsigned int nr) { int space; int i; const unsigned char *cp; mutex_lock(&tty->output_lock); space = tty_write_room(tty); if (!space) { mutex_unlock(&tty->output_lock); return 0; } if (nr > space) nr = space; for (i = 0, cp = buf; i < nr; i++, cp++) { unsigned char c = *cp; switch (c) { case '\n': if (O_ONLRET(tty)) tty->column = 0; if (O_ONLCR(tty)) goto break_out; tty->canon_column = tty->column; break; case '\r': if (O_ONOCR(tty) && tty->column == 0) goto break_out; if (O_OCRNL(tty)) goto break_out; tty->canon_column = tty->column = 0; break; case '\t': goto break_out; case '\b': if (tty->column > 0) tty->column--; break; default: if (!iscntrl(c)) { if (O_OLCUC(tty)) goto break_out; if (!is_continuation(c, tty)) tty->column++; } break; } } break_out: i = tty->ops->write(tty, buf, i); mutex_unlock(&tty->output_lock); return i; }
static void eraser(unsigned char c, struct tty_struct *tty) { enum { ERASE, WERASE, KILL } kill_type; int head, seen_alnums, cnt; unsigned long flags; if (tty->read_head == tty->canon_head) { return; } if (c == ERASE_CHAR(tty)) kill_type = ERASE; else if (c == WERASE_CHAR(tty)) kill_type = WERASE; else { if (!L_ECHO(tty)) { spin_lock_irqsave(&tty->read_lock, flags); tty->read_cnt -= ((tty->read_head - tty->canon_head) & (N_TTY_BUF_SIZE - 1)); tty->read_head = tty->canon_head; spin_unlock_irqrestore(&tty->read_lock, flags); return; } if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { spin_lock_irqsave(&tty->read_lock, flags); tty->read_cnt -= ((tty->read_head - tty->canon_head) & (N_TTY_BUF_SIZE - 1)); tty->read_head = tty->canon_head; spin_unlock_irqrestore(&tty->read_lock, flags); finish_erasing(tty); echo_char(KILL_CHAR(tty), tty); if (L_ECHOK(tty)) echo_char_raw('\n', tty); return; } kill_type = KILL; } seen_alnums = 0; while (tty->read_head != tty->canon_head) { head = tty->read_head; do { head = (head - 1) & (N_TTY_BUF_SIZE-1); c = tty->read_buf[head]; } while (is_continuation(c, tty) && head != tty->canon_head); if (is_continuation(c, tty)) break; if (kill_type == WERASE) { if (isalnum(c) || c == '_') seen_alnums++; else if (seen_alnums) break; } cnt = (tty->read_head - head) & (N_TTY_BUF_SIZE-1); spin_lock_irqsave(&tty->read_lock, flags); tty->read_head = head; tty->read_cnt -= cnt; spin_unlock_irqrestore(&tty->read_lock, flags); if (L_ECHO(tty)) { if (L_ECHOPRT(tty)) { if (!tty->erasing) { echo_char_raw('\\', tty); tty->erasing = 1; } echo_char(c, tty); while (--cnt > 0) { head = (head+1) & (N_TTY_BUF_SIZE-1); echo_char_raw(tty->read_buf[head], tty); echo_move_back_col(tty); } } else if (kill_type == ERASE && !L_ECHOE(tty)) { echo_char(ERASE_CHAR(tty), tty); } else if (c == '\t') { unsigned int num_chars = 0; int after_tab = 0; unsigned long tail = tty->read_head; while (tail != tty->canon_head) { tail = (tail-1) & (N_TTY_BUF_SIZE-1); c = tty->read_buf[tail]; if (c == '\t') { after_tab = 1; break; } else if (iscntrl(c)) { if (L_ECHOCTL(tty)) num_chars += 2; } else if (!is_continuation(c, tty)) { num_chars++; } } echo_erase_tab(num_chars, after_tab, tty); } else { if (iscntrl(c) && L_ECHOCTL(tty)) { echo_char_raw('\b', tty); echo_char_raw(' ', tty); echo_char_raw('\b', tty); } if (!iscntrl(c) || L_ECHOCTL(tty)) { echo_char_raw('\b', tty); echo_char_raw(' ', tty); echo_char_raw('\b', tty); } } } if (kill_type == ERASE) break; } if (tty->read_head == tty->canon_head && L_ECHO(tty)) finish_erasing(tty); }
static void eraser(unsigned char c, struct tty_struct *tty) { enum { ERASE, WERASE, KILL } kill_type; int head, seen_alnums, cnt; unsigned long flags; if (tty->read_head == tty->canon_head) { /* opost('\a', tty); */ /* what do you think? */ return; } if (c == ERASE_CHAR(tty)) kill_type = ERASE; else if (c == WERASE_CHAR(tty)) kill_type = WERASE; else { if (!L_ECHO(tty)) { spin_lock_irqsave(&tty->read_lock, flags); tty->read_cnt -= ((tty->read_head - tty->canon_head) & (N_TTY_BUF_SIZE - 1)); tty->read_head = tty->canon_head; spin_unlock_irqrestore(&tty->read_lock, flags); return; } if (!L_ECHOK(tty) || !L_ECHOKE(tty) || !L_ECHOE(tty)) { spin_lock_irqsave(&tty->read_lock, flags); tty->read_cnt -= ((tty->read_head - tty->canon_head) & (N_TTY_BUF_SIZE - 1)); tty->read_head = tty->canon_head; spin_unlock_irqrestore(&tty->read_lock, flags); finish_erasing(tty); echo_char(KILL_CHAR(tty), tty); /* Add a newline if ECHOK is on and ECHOKE is off. */ if (L_ECHOK(tty)) opost('\n', tty); return; } kill_type = KILL; } seen_alnums = 0; while (tty->read_head != tty->canon_head) { head = tty->read_head; /* erase a single possibly multibyte character */ do { head = (head - 1) & (N_TTY_BUF_SIZE-1); c = tty->read_buf[head]; } while (is_continuation(c, tty) && head != tty->canon_head); /* do not partially erase */ if (is_continuation(c, tty)) break; if (kill_type == WERASE) { /* Equivalent to BSD's ALTWERASE. */ if (isalnum(c) || c == '_') seen_alnums++; else if (seen_alnums) break; } cnt = (tty->read_head - head) & (N_TTY_BUF_SIZE-1); spin_lock_irqsave(&tty->read_lock, flags); tty->read_head = head; tty->read_cnt -= cnt; spin_unlock_irqrestore(&tty->read_lock, flags); if (L_ECHO(tty)) { if (L_ECHOPRT(tty)) { if (!tty->erasing) { put_char('\\', tty); tty->column++; tty->erasing = 1; } /* if cnt > 1, output a multi-byte character */ echo_char(c, tty); while (--cnt > 0) { head = (head+1) & (N_TTY_BUF_SIZE-1); put_char(tty->read_buf[head], tty); } } else if (kill_type == ERASE && !L_ECHOE(tty)) { echo_char(ERASE_CHAR(tty), tty); } else if (c == '\t') { unsigned int col = tty->canon_column; unsigned long tail = tty->canon_head; /* Find the column of the last char. */ while (tail != tty->read_head) { c = tty->read_buf[tail]; if (c == '\t') col = (col | 7) + 1; else if (iscntrl(c)) { if (L_ECHOCTL(tty)) col += 2; } else if (!is_continuation(c, tty)) col++; tail = (tail+1) & (N_TTY_BUF_SIZE-1); } /* should never happen */ if (tty->column > 0x80000000) tty->column = 0; /* Now backup to that column. */ while (tty->column > col) { /* Can't use opost here. */ put_char('\b', tty); if (tty->column > 0) tty->column--; } } else { if (iscntrl(c) && L_ECHOCTL(tty)) { put_char('\b', tty); put_char(' ', tty); put_char('\b', tty); if (tty->column > 0) tty->column--; } if (!iscntrl(c) || L_ECHOCTL(tty)) { put_char('\b', tty); put_char(' ', tty); put_char('\b', tty); if (tty->column > 0) tty->column--; } } } if (kill_type == ERASE) break; } if (tty->read_head == tty->canon_head) finish_erasing(tty); }
static void do_file(FILE *fp) { char *cp; char *begin; char ch; int continuation = 0; int quotes_found = 0; int i; int j; while (fgets(buf, MAX_LEN, fp)) { chk_len(buf); cp = buf; if (*cp == '#') continue; if (!continuation) { /* * Look for gettext. */ while (strncmp(cp, "gettext", 7) != 0) { cp++; if (!*cp) break; } if (!*cp) continue; } if (is_private_function(cp)) continue; continuation = 0; if (quotes_found == 0) { /* * Find first quote after gettext. */ while (*cp && *cp != '"' && *cp != '\'') { if (is_continuation(cp)) { continuation = 1; break; } cp++; } if (!*cp) { (void) fprintf(stderr, "Cannot find quote after gettext():\n"); (void) fprintf(stderr, "%s\n", buf); continue; } if (continuation) continue; /* * We have our first quote. */ ch = *cp; quotes_found = 1; cp++; if (!*cp) { (void) fprintf(stderr, "String ended unexpectedly: %s\n", buf); continue; } /* * Remember the start of our string. */ begin = cp; } /* * Look for second quote. */ while (*cp) { /* * Allow backslash quotes in the string. */ if (*cp == '\\') { cp++; if (cp && *cp && *cp == ch) { cp++; } else cp--; } if (is_continuation(cp)) { /* * Remove backslash and newline */ buf[cp - buf] = '\0'; continuation = 1; break; } /* * Is this our second quote. */ if (*cp == ch) { *cp = '\0'; (void) strcat(string, begin); quotes_found = 2; continuation = 0; break; } cp++; } if (continuation) { (void) strcat(string, begin); begin = buf; continue; } if (quotes_found != 2) { (void) fprintf(stderr, "Missing matching quote:\n"); (void) fprintf(stderr, "%s\n", buf); continuation = 0; quotes_found = 0; continue; } for (i = 0; i < (int) strlen(string); i++) { if (string[i] == '"' && i > 0 && string[i-1] != '\\') { string[strlen(string) + 1] = '\0'; for (j = strlen(string); j > i; j--) string[j] = string[j - 1]; string[i] = '\\'; } } if (!cmsg(string)) { (void) fprintf(ofp, "msgid \"%s\"\n", string); if (msgstrtag) { (void) fprintf(ofp, "msgstr \"%s%s\"\n", msgstrtag, string); } else (void) fprintf(ofp, "msgstr\n"); } else { (void) fprintf(ofp, "# msgid \"%s\"\n", string); if (msgstrtag) { (void) fprintf(ofp, "# msgstr \"%s%s\"\n", msgstrtag, string); } else (void) fprintf(ofp, "# msgstr\n"); } (void) memset(string, '\0', MAX_LEN); (void) memset(buf, '\0', MAX_LEN); quotes_found = 0; } }