Преглед на файлове

[libc] Fix isdigit(), islower() and isupper().

From: Stefan Hajnoczi <stefanha@gmail.com>
tags/v0.9.4
Michael Brown преди 16 години
родител
ревизия
7d01bf663e
променени са 3 файла, в които са добавени 9 реда и са изтрити 16 реда
  1. 3
    6
      src/drivers/net/mlx_ipoib/mt23108.c
  2. 3
    6
      src/drivers/net/mlx_ipoib/mt25218.c
  3. 3
    4
      src/include/ctype.h

+ 3
- 6
src/drivers/net/mlx_ipoib/mt23108.c Целия файл

@@ -10,6 +10,8 @@ Skeleton NIC driver for Etherboot
10 10
  * your option) any later version.
11 11
  */
12 12
 
13
+/* to get toupper() */
14
+#include <ctype.h>
13 15
 /* to get some global routines like printf */
14 16
 #include "etherboot.h"
15 17
 /* to get the interface to the body of the program */
@@ -31,12 +33,7 @@ int prompt_key(int secs, unsigned char *ch_p)
31 33
 
32 34
 	for (tmo = currticks() + secs * TICKS_PER_SEC; currticks() < tmo;) {
33 35
 		if (iskey()) {
34
-			ch = getchar();
35
-			/* toupper does not work ... */
36
-			if (ch == 'v')
37
-				ch = 'V';
38
-			if (ch == 'i')
39
-				ch = 'I';
36
+			ch = toupper(getchar());
40 37
 			if ((ch=='V') || (ch=='I')) {
41 38
 				*ch_p = ch;
42 39
 				return 1;

+ 3
- 6
src/drivers/net/mlx_ipoib/mt25218.c Целия файл

@@ -10,6 +10,8 @@ Skeleton NIC driver for Etherboot
10 10
  * your option) any later version.
11 11
  */
12 12
 
13
+/* to get toupper() */
14
+#include <ctype.h>
13 15
 /* to get some global routines like printf */
14 16
 #include "etherboot.h"
15 17
 /* to get the interface to the body of the program */
@@ -31,12 +33,7 @@ int prompt_key(int secs, unsigned char *ch_p)
31 33
 
32 34
 	for (tmo = currticks() + secs * TICKS_PER_SEC; currticks() < tmo;) {
33 35
 		if (iskey()) {
34
-			ch = getchar();
35
-			/* toupper does not work ... */
36
-			if (ch == 'v')
37
-				ch = 'V';
38
-			if (ch == 'i')
39
-				ch = 'I';
36
+			ch = toupper(getchar());
40 37
 			if ((ch=='V') || (ch=='I')) {
41 38
 				*ch_p = ch;
42 39
 				return 1;

+ 3
- 4
src/include/ctype.h Целия файл

@@ -6,10 +6,9 @@
6 6
  * Character types
7 7
  */
8 8
 
9
-#define isdigit(c)	((c & 0x04) != 0)
10
-#define islower(c)	((c & 0x02) != 0)
11
-//#define isspace(c)	((c & 0x20) != 0)
12
-#define isupper(c)	((c & 0x01) != 0)
9
+#define isdigit(c)	((c) >= '0' && (c) <= '9')
10
+#define islower(c)	((c) >= 'a' && (c) <= 'z')
11
+#define isupper(c)	((c) >= 'A' && (c) <= 'Z')
13 12
 
14 13
 static inline unsigned char tolower(unsigned char c)
15 14
 {

Loading…
Отказ
Запис