]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/INC/STRING.C

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / INC / STRING.C
1 #include "types.h"
2 #include "internat.h"
3 #include <dos.h>
4
5 /* #define KANJI TRUE */
6
7 char haveinttab = FALSE;
8
9 struct InterTbl Currtab;
10
11 int toupper(c)
12 int c;
13 {
14 union REGS regs ;
15
16 if(!haveinttab) {
17 regs.x.ax = 0x3800 ;
18 regs.x.dx = (unsigned) &Currtab ;
19 intdos (&regs, &regs) ; /* INIT the table */
20
21 haveinttab = TRUE;
22 }
23
24 return(IToupper(c,Currtab.casecall));
25
26 }
27
28 char *strupr(string)
29 char *string;
30 {
31 register char *p1;
32
33 p1 = string;
34 while (*p1 != NULL) {
35 /*
36 * A note about the following " & 0xFF" stuff. This is
37 * to prevent the damn C compiler from converting bytes
38 * to words with the CBW instruction which is NOT correct
39 * for routines like toupper
40 */
41 #ifdef KANJI
42 if(testkanj(*p1 & 0xFF))
43 p1 += 2 ;
44 else
45 *p1++ = toupper(*p1 & 0xFF);
46 #else
47 *p1++ = toupper(*p1 & 0xFF);
48 #endif
49 }
50 return(string);
51 }
52
53 char *strpbrk(string1,string2)
54 char *string1;
55 char *string2;
56 {
57 register char *p1;
58
59 while (*string1 != NULL) {
60 /*
61 * A note about the following " & 0xFF" stuff. This is
62 * to prevent the damn C compiler from converting bytes
63 * to words with the CBW instruction which is NOT correct
64 * for routines like toupper
65 */
66 #ifdef KANJI
67 if(testkanj(*string1 & 0xFF))
68 string1 += 2 ;
69 else {
70 #endif
71 p1 = string2;
72 while (*p1 != NULL) {
73 if(*p1++ == *string1)
74 return(string1);
75 }
76 string1++;
77 #ifdef KANJI
78 }
79 #endif
80
81 }
82 return(NULL); /* no matches found */
83 }
84
85 #ifdef KANJI
86 testkanj(c)
87 unsigned char c;
88 {
89 if((c >= 0x81 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFC))
90 return(TRUE);
91 else
92 return(FALSE);
93 }
94 #endif