Hi, Fixed a bug in ntty.c when processing backspaces. Rewrited xt-key.c to reduce code size. Clean code in some functions in fs directory. Code size was reduced by 288 bytes and data size increased 84 bytes. Greetings, Juan
diff -Nur elks.orig/arch/i86/drivers/char/dircon.c elks/arch/i86/drivers/char/dircon.c --- elks.orig/arch/i86/drivers/char/dircon.c 2014-11-27 10:53:27.000000000 -0600 +++ elks/arch/i86/drivers/char/dircon.c 2014-12-02 20:19:30.000000000 -0600 @@ -105,7 +105,6 @@ }; #endif -static void ScrollUp(register Console * C, int st, int en); static void ClearRange(register Console * C, int x, int y, int xx, int yy); #ifdef CONFIG_DCON_VT52 @@ -139,6 +138,19 @@ } } +static void ScrollUp(register Console * C, int st, int en) +{ + unsigned rdofs, wrofs; + + if (st >= 1 && st < en) { + wrofs = (rdofs = (unsigned int) ((Width << 1) * st)) - (Width << 1); + far_memmove(C->vseg, rdofs, C->vseg, wrofs, + ((unsigned) (Width * (en - st))) << 1); + en--; + ClearRange(C, 0, en, Width, en); + } +} + void WriteChar(register Console * C, char c) { unsigned int offset; @@ -225,19 +237,6 @@ PositionCursor(Visible); } -static void ScrollUp(register Console * C, int st, int en) -{ - unsigned rdofs, wrofs; - - if (st >= 1 && st < en) { - wrofs = (rdofs = (unsigned int) ((Width << 1) * st)) - (Width << 1); - far_memmove(C->vseg, rdofs, C->vseg, wrofs, - ((unsigned) (Width * (en - st))) << 1); - en--; - ClearRange(C, 0, en, Width, en); - } -} - #ifdef CONFIG_DCON_VT52 static void ScrollDown(register Console * C, int st, int en) diff -Nur elks.orig/arch/i86/drivers/char/ntty.c elks/arch/i86/drivers/char/ntty.c --- elks.orig/arch/i86/drivers/char/ntty.c 2014-11-27 10:53:27.000000000 -0600 +++ elks/arch/i86/drivers/char/ntty.c 2014-12-02 16:57:53.000000000 -0600 @@ -212,7 +212,7 @@ tty_echo(tty, ch); } else if (((int)pi) > 0) { --pi; - k = ((get_user_char((void *)(data++)) + k = ((get_user_char((void *)(--data)) == '\t') ? TAB_SPACES : 1); do { tty_echo(tty, ch); diff -Nur elks.orig/arch/i86/drivers/char/xt_key.c elks/arch/i86/drivers/char/xt_key.c --- elks.orig/arch/i86/drivers/char/xt_key.c 2014-11-27 10:53:27.000000000 -0600 +++ elks/arch/i86/drivers/char/xt_key.c 2014-12-02 20:07:55.000000000 -0600 @@ -58,6 +58,46 @@ #define ANYSHIFT (LSHIFT | RSHIFT) +#define SSC 0xC0 + +static unsigned char tb_state[] = { + 0x80, CTRL, SSC, SSC, /*1C->1F*/ + SSC, SSC, SSC, SSC, SSC, SSC, SSC, SSC, /*20->27*/ + SSC, SSC, LSHIFT, SSC, SSC, SSC, SSC, SSC, /*28->2F*/ + SSC, SSC, SSC, SSC, SSC, SSC, RSHIFT, SSC, /*30->37*/ + SSC, SSC, CAPS, /*38->3A*/ + 'a', 'b', 'c', 'd', 'e', /*3B->3F, Function Keys*/ + 'f', 'g', 'h', 'i', 'j', /*40->44, Function Keys*/ + NUM, SSC, SSC, /*45->47*/ + 0xB7, SSC, SSC, 0xBA, SSC, 0xB9, SSC, SSC, /*48->4F*/ + 0xB8, SSC, SSC, SSC, SSC, SSC, ALT, SSC, /*50->57*/ +}; + +static unsigned char state_code[] = { + 0, /* All status are 0 */ + 1, /* SHIFT */ + 0, /* CTRL */ + 1, /* SHIFT CTRL */ + 0, /* ALT */ + 1, /* SHIFT ALT */ + 3, /* CTRL ALT */ + 1, /* SHIFT CTRL ALT */ + 2, /* CAPS */ + 0, /* CAPS SHIFT */ + 2, /* CAPS CTRL */ + 0, /* CAPS SHIFT CTRL */ + 2, /* CAPS ALT */ + 0, /* CAPS SHIFT ALT */ + 2, /* CAPS CTRL ALT */ + 3, /* CAPS SHIFT CTRL ALT */ +}; +static unsigned char *scan_tabs[] = { + xtkb_scan, + xtkb_scan_shifted, + xtkb_scan_caps, + xtkb_scan_ctrl_alt, +}; + /* Ack. We can't add a character until the queue's ready */ @@ -117,87 +157,25 @@ E0Prefix = 0; } IsReleasep = (char *)(code & 0x80); - switch (code & 0x7F) { - case 29: - IsReleasep ? (ModeState &= ~CTRL) : (ModeState |= CTRL); - return; - case 42: - IsReleasep ? (ModeState &= ~LSHIFT) : (ModeState |= LSHIFT); - return; - case 54: - IsReleasep ? (ModeState &= ~RSHIFT) : (ModeState |= RSHIFT); - return; - case 56: + code &= 0x7F; + mode = (code >= 0x1C) ? tb_state[code - 0x1C] : SSC; -#if defined(CONFIG_KEYMAP_DE) || defined(CONFIG_KEYMAP_SE) - - if (E0 == 0) { - IsReleasep ? (ModeState &= ~ALT) : (ModeState |= ALT); - } else { - IsReleasep ? (ModeState &= ~ALT_GR) : (ModeState |= ALT_GR); - } - -#else - - IsReleasep ? (ModeState &= ~ALT) : (ModeState |= ALT); + /* --------------Process status keys-------------- */ + if(!(mode & 0xC0)) { +#if defined(CONFIG_KEYMAP_DE) || defined(CONFIG_KEYMAP_SE) + if((mode == ALT) && (E0 != 0)) + mode = ALT_GR; #endif - - return; - case 58: - ModeState ^= IsReleasep ? 0 : CAPS; - return; - case 69: - ModeState ^= IsReleasep ? 0 : NUM; + IsReleasep ? (ModeState &= ~mode) : (ModeState |= mode); return; - default: - if (IsReleasep) - return; - break; } + if(IsReleasep) + return; - /* Handle CTRL-ALT-DEL */ - - if ((code == 0x53) && (ModeState & CTRL) && (ModeState & ALT)) - ctrl_alt_del(); - - /* - * Pick the right keymap - */ - if (ModeState & CAPS && !(ModeState & ANYSHIFT)) - keyp = (char *) xtkb_scan_caps[code]; - else if (ModeState & ANYSHIFT && !(ModeState & CAPS)) - keyp = (char *) xtkb_scan_shifted[code]; - - /* added for belgian keyboard (Stefke) */ - - else if ((ModeState & CTRL) && (ModeState & ALT)) - keyp = (char *) xtkb_scan_ctrl_alt[code]; - - /* end belgian */ - - /* added for German keyboard (Klaus Syttkus) */ - - else if (ModeState & ALT_GR) - keyp = (char *) xtkb_scan_ctrl_alt[code]; - /* end German */ - else - keyp = (char *) xtkb_scan[code]; - - if (ModeState & CTRL && code < 14 && !(ModeState & ALT)) - keyp = (char *) xtkb_scan_shifted[code]; - if (code < 70 && ModeState & NUM) - keyp = (char *) xtkb_scan_shifted[code]; - /* - * Apply special modifiers - */ - if (ModeState & ALT && !(ModeState & CTRL)) /* Changed to support CTRL-ALT */ - keyp = (char *)(((int) keyp) | 0x80); /* META-.. */ - if (!keyp) /* non meta-@ is 64 */ - keyp = (char *) '@'; - if (ModeState & CTRL && !(ModeState & ALT)) /* Changed to support CTRL-ALT */ - keyp = (char *)(((int) keyp) & 0x1F); /* CTRL-.. */ - if (code < 0x45 && code > 0x3A) { /* F1 .. F10 */ + switch(mode & 0xC0) { + case 0x40: /* F1 .. F10 */ + /* --------------Handle Function keys-------------- */ #ifdef CONFIG_CONSOLE_DIRECT @@ -208,34 +186,51 @@ #endif AddQueue(ESC); - AddQueue((unsigned char) (code - 0x3B + 'a')); + AddQueue((unsigned char)mode); return; - } - if (E0) /* Is extended scancode */ - switch (code) { - case 0x48: /* Arrow up */ - AddQueue(ESC); - AddQueue('A'); - return; - case 0x50: /* Arrow down */ - AddQueue(ESC); - AddQueue('B'); - return; - case 0x4D: /* Arrow right */ - AddQueue(ESC); - AddQueue('C'); - return; - case 0x4B: /* Arrow left */ - AddQueue(ESC); - AddQueue('D'); - return; - case 0x1c: /* keypad enter */ - AddQueue('\n'); + + /* --------------Handle extended scancodes-------------- */ + case 0x80: + if(E0) { /* Is extended scancode? */ + mode &= 0x3F; + if(mode) + AddQueue(ESC); + AddQueue(mode + 0x0A); return; } - if (((int)keyp) == '\r') - keyp = (char *) '\n'; - AddQueue((unsigned char) keyp); + + default: + /* --------------Handle CTRL-ALT-DEL-------------- */ + + if ((code == 0x53) && (ModeState & CTRL) && (ModeState & ALT)) + ctrl_alt_del(); + + /* + * Pick the right keymap + */ + mode = ((ModeState & ~(NUM | ALT_GR)) >> 1) | (ModeState & 0x01); + mode = state_code[mode]; + if(!mode && (ModeState & ALT_GR)) + mode = 3; + keyp = (char *)(*(scan_tabs[mode] + code)); + + if (ModeState & CTRL && code < 14 && !(ModeState & ALT)) + keyp = (char *) xtkb_scan_shifted[code]; + if (code < 70 && ModeState & NUM) + keyp = (char *) xtkb_scan_shifted[code]; + /* + * Apply special modifiers + */ + if (ModeState & ALT && !(ModeState & CTRL)) /* Changed to support CTRL-ALT */ + keyp = (char *)(((int) keyp) | 0x80); /* META-.. */ + if (!keyp) /* non meta-@ is 64 */ + keyp = (char *) '@'; + if (ModeState & CTRL && !(ModeState & ALT)) /* Changed to support CTRL-ALT */ + keyp = (char *)(((int) keyp) & 0x1F); /* CTRL-.. */ + if (((int)keyp) == '\r') + keyp = (char *) '\n'; + AddQueue((unsigned char) keyp); + } } /* diff -Nur elks.orig/fs/fcntl.c elks/fs/fcntl.c --- elks.orig/fs/fcntl.c 2014-11-27 10:53:27.000000000 -0600 +++ elks/fs/fcntl.c 2014-12-05 18:00:10.000000000 -0600 @@ -30,7 +30,7 @@ if (arg >= NR_OPEN) return -EMFILE; - (void) clear_bit(arg, &fils->close_on_exec); + clear_bit(arg, &fils->close_on_exec); (fils->fd[arg] = fils->fd[fd])->f_count++; return (int) arg; @@ -73,9 +73,9 @@ break; case F_SETFD: if (arg & 1) - (void) set_bit(fd, &fils->close_on_exec); + set_bit(fd, &fils->close_on_exec); else - (void) clear_bit(fd, &fils->close_on_exec); + clear_bit(fd, &fils->close_on_exec); result = 0; break; case F_GETFL: diff -Nur elks.orig/fs/open.c elks/fs/open.c --- elks.orig/fs/open.c 2014-12-05 18:33:19.000000000 -0600 +++ elks/fs/open.c 2014-12-05 18:02:23.000000000 -0600 @@ -489,7 +489,7 @@ register struct file_struct *cfiles = ¤t->files; if (fd < NR_OPEN) { - (void) clear_bit(fd, &cfiles->close_on_exec); + clear_bit(fd, &cfiles->close_on_exec); if ((filp = cfiles->fd[fd])) { cfiles->fd[fd] = NULL; return close_fp(filp); diff -Nur elks.orig/fs/super.c elks/fs/super.c --- elks.orig/fs/super.c 2014-11-27 10:53:27.000000000 -0600 +++ elks/fs/super.c 2014-12-05 18:19:30.000000000 -0600 @@ -75,12 +75,12 @@ return; wait_set(&sb->s_wait); - repeat: - current->state = TASK_UNINTERRUPTIBLE; - if (sb->s_lock) { + goto ini_loop; + do { schedule(); - goto repeat; - } + ini_loop: + current->state = TASK_UNINTERRUPTIBLE; + } while(sb->s_lock); wait_clear(&sb->s_wait); current->state = TASK_RUNNING; } @@ -102,7 +102,7 @@ register struct super_block *sb; register struct super_operations *sop; - for (sb = super_blocks + 0; sb < super_blocks + NR_SUPER; sb++) { + for (sb = super_blocks; sb < super_blocks + NR_SUPER; sb++) { if ((!sb->s_dev) || (dev && sb->s_dev != dev)) @@ -126,7 +126,7 @@ register struct super_block *s; if (dev) { - s = 0 + super_blocks; + s = super_blocks; while (s < super_blocks + NR_SUPER) if (s->s_dev == dev) { wait_on_super(s); @@ -212,11 +212,9 @@ type = file_systems[0]; #endif - for (s = super_blocks;; s++) { + for (s = super_blocks; s->s_dev; s++) { if (s >= super_blocks + NR_SUPER) return NULL; - if (!(s->s_dev)) - break; } s->s_dev = dev; s->s_flags = (unsigned short int) flags; @@ -362,10 +360,9 @@ register struct super_block *sb; int error; - error = namei(dir, &dir_i, IS_DIR, 0); - dirp = dir_i; - if (error) + if((error = namei(dir, &dir_i, IS_DIR, 0))) return error; + dirp = dir_i; if ((dirp->i_count != 1 || dirp->i_mount) || (!fs_may_mount(dev)) ) { Binary files elks.orig/Image-2j and elks/Image-2j differ diff -Nur elks.orig/kernel/signal.c elks/kernel/signal.c --- elks.orig/kernel/signal.c 2014-11-27 10:53:27.000000000 -0600 +++ elks/kernel/signal.c 2014-12-05 18:22:46.000000000 -0600 @@ -19,7 +19,6 @@ static void generate(int sig, register struct task_struct *p) { register struct sigaction *sa = &(p->sig.action[sig - 1]); - sigset_t mask = ((sigset_t) 1) << (sig - 1); if (sa->sa_handler == SIG_IGN) return; @@ -31,7 +30,7 @@ )) return; debug1("SIGNAL: Generating sig %d.\n", sig); - p->signal |= mask; + p->signal |= (((sigset_t) 1) << (sig - 1)); if ((p->state == TASK_INTERRUPTIBLE) /* && (p->signal & ~p->blocked) */ ) { debug("SIGNAL: Waking up.\n"); wake_up_process(p);