Rev 575 | Rev 601 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 575 | Rev 588 | ||
|---|---|---|---|
| Line 37... | Line 37... | ||
| 37 | 37 | ||
| 38 | /** Standard input character device. */ |
38 | /** Standard input character device. */ |
| 39 | chardev_t *stdin = NULL; |
39 | chardev_t *stdin = NULL; |
| 40 | chardev_t *stdout = NULL; |
40 | chardev_t *stdout = NULL; |
| 41 | 41 | ||
| - | 42 | /** Get character from character device. |
|
| - | 43 | * |
|
| - | 44 | * @param chardev Character device. |
|
| - | 45 | * |
|
| - | 46 | * @return Character read. |
|
| - | 47 | */ |
|
| - | 48 | static __u8 _getc(chardev_t *chardev) |
|
| - | 49 | { |
|
| - | 50 | __u8 ch; |
|
| - | 51 | ipl_t ipl; |
|
| - | 52 | ||
| - | 53 | waitq_sleep(&chardev->wq); |
|
| - | 54 | ipl = interrupts_disable(); |
|
| - | 55 | spinlock_lock(&chardev->lock); |
|
| - | 56 | ch = chardev->buffer[(chardev->index - chardev->counter) % CHARDEV_BUFLEN]; |
|
| - | 57 | chardev->counter--; |
|
| - | 58 | spinlock_unlock(&chardev->lock); |
|
| - | 59 | interrupts_restore(ipl); |
|
| - | 60 | ||
| - | 61 | chardev->op->resume(chardev); |
|
| - | 62 | ||
| - | 63 | return ch; |
|
| - | 64 | } |
|
| - | 65 | ||
| 42 | /** Get string from character device. |
66 | /** Get string from character device. |
| 43 | * |
67 | * |
| 44 | * Read characters from character device until first occurrence |
68 | * Read characters from character device until first occurrence |
| 45 | * of newline character. |
69 | * of newline character. |
| 46 | * |
70 | * |
| Line 54... | Line 78... | ||
| 54 | { |
78 | { |
| 55 | index_t index = 0; |
79 | index_t index = 0; |
| 56 | char ch; |
80 | char ch; |
| 57 | 81 | ||
| 58 | while (index < buflen) { |
82 | while (index < buflen) { |
| 59 | ch = getc(chardev); |
83 | ch = _getc(chardev); |
| - | 84 | if (ch == '\b') { |
|
| - | 85 | if (index > 0) { |
|
| - | 86 | index--; |
|
| - | 87 | /* Space backspace, space */ |
|
| - | 88 | putchar('\b'); |
|
| - | 89 | putchar(' '); |
|
| - | 90 | putchar('\b'); |
|
| - | 91 | } |
|
| - | 92 | continue; |
|
| - | 93 | } |
|
| - | 94 | putchar(ch); |
|
| - | 95 | ||
| 60 | if (ch == '\n') { /* end of string => write 0, return */ |
96 | if (ch == '\n') { /* end of string => write 0, return */ |
| 61 | buf[index] = '\0'; |
97 | buf[index] = '\0'; |
| 62 | return (count_t) index; |
98 | return (count_t) index; |
| 63 | } |
99 | } |
| 64 | buf[index++] = ch; |
100 | buf[index++] = ch; |
| 65 | } |
101 | } |
| 66 | return (count_t) index; |
102 | return (count_t) index; |
| 67 | } |
103 | } |
| 68 | 104 | ||
| 69 | /** Get character from character device. |
105 | /** Get character from device & echo it to screen */ |
| 70 | * |
- | |
| 71 | * @param chardev Character device. |
- | |
| 72 | * |
- | |
| 73 | * @return Character read. |
- | |
| 74 | */ |
- | |
| 75 | __u8 getc(chardev_t *chardev) |
106 | __u8 getc(chardev_t *chardev) |
| 76 | { |
107 | { |
| 77 | __u8 ch; |
108 | __u8 ch; |
| 78 | ipl_t ipl; |
- | |
| 79 | - | ||
| 80 | waitq_sleep(&chardev->wq); |
- | |
| 81 | ipl = interrupts_disable(); |
- | |
| 82 | spinlock_lock(&chardev->lock); |
- | |
| 83 | ch = chardev->buffer[(chardev->index - chardev->counter) % CHARDEV_BUFLEN]; |
- | |
| 84 | chardev->counter--; |
- | |
| 85 | spinlock_unlock(&chardev->lock); |
- | |
| 86 | interrupts_restore(ipl); |
- | |
| 87 | - | ||
| 88 | chardev->op->resume(chardev); |
- | |
| 89 | 109 | ||
| - | 110 | ch = _getc(chardev); |
|
| - | 111 | putchar(ch); |
|
| 90 | return ch; |
112 | return ch; |
| 91 | } |
113 | } |
| 92 | 114 | ||
| 93 | void putchar(char c) |
115 | void putchar(char c) |
| 94 | { |
116 | { |