Release 940804
[wine/gsoc-2012-control.git] / misc / lstr.c
blob361ea10b69962397419cdafdfde8bad095174d8c
1 static char Copyright[] = "Copyright Yngvi Sigurjonsson (yngvi@hafro.is), 1993";
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <ctype.h>
7 #include <sys/types.h>
8 #include <fcntl.h>
9 #include <unistd.h>
11 #include "prototypes.h"
12 #include "regfunc.h"
13 #include "windows.h"
16 /* Funny to divide them between user and kernel. */
18 /* KERNEL.89 */
19 LPSTR lstrcat(LPSTR target,LPCSTR source)
21 #ifdef DEBUG_STRING
22 fprintf(stderr,"lstrcat(%s,%s)\n",target,source);
23 #endif
24 return strcat(target,source);
27 /* USER.430 */
28 INT lstrcmp(LPCSTR str1,LPCSTR str2)
30 return strcmp(str1,str2);
33 /* USER.471 */
34 INT lstrcmpi(LPCSTR str1,LPCSTR str2)
36 int i;
37 i=0;
38 while((toupper(str1[i])==toupper(str2[i]))&&(str1[i]!=0))
39 i++;
40 return toupper(str1[i])-toupper(str2[i]);
43 /* KERNEL.88 */
44 LPSTR lstrcpy(LPSTR target,LPCSTR source)
46 return strcpy(target,source);
49 /* KERNEL.353 */
50 LPSTR lstrcpyn(LPSTR target,LPCSTR source,int n)
52 return strncpy(target,source,n);
55 /* KERNEL.90 */
56 INT lstrlen(LPCSTR str)
58 return strlen(str);
62 /* AnsiUpper USER.431 */
63 char FAR* AnsiUpper(char FAR* strOrChar)
65 /* I am not sure if the locale stuff works with toupper, but then again
66 I am not sure if the Linux libc locale stuffs works at all */
67 /* if((int)strOrChar<256)
68 return (char FAR*) toupper((int)strOrChar);
69 else {
70 int i;
71 for(i=0;(i<65536) && strOrChar[i];i++)
72 strOrChar[i]=toupper(strOrChar[i]);
73 return strOrChar;
74 } */
75 int i;
76 for (i = 0; (i < 65536 && strOrChar[i]);i++)
77 strOrChar[i] = (strOrChar[i] >= 'a' && strOrChar[i] <= 'z') ?
78 strOrChar[i] - ('a' - 'A') : strOrChar[i];
79 return strOrChar;
82 /* AnsiLower USER.432 */
83 char FAR* AnsiLower(char FAR* strOrChar)
85 /* I am not sure if the locale stuff works with tolower, but then again
86 I am not sure if the Linux libc locale stuffs works at all */
87 /* if((int)strOrChar<256)
88 return (char FAR*)tolower((int)strOrChar);
89 else {
90 int i;
91 for(i=0;(i<65536)&&strOrChar[i];i++)
92 strOrChar[i]=tolower(strOrChar[i]);
93 return strOrChar;
94 }*/
95 int i;
96 for (i = 0; (i < 65536 && strOrChar[i]);i++)
97 strOrChar[i] = (strOrChar[i] >= 'A' && strOrChar[i] <= 'Z') ?
98 strOrChar[i] + ('a' - 'A') : strOrChar[i];
101 /* AnsiUpperBuff USER.437 */
102 UINT AnsiUpperBuff(LPSTR str,UINT len)
104 int i;
105 len=(len==0)?65536:len;
107 for(i=0;i<len;i++)
108 str[i]=toupper(str[i]);
109 return i;
112 /* AnsiLowerBuff USER.438 */
113 UINT AnsiLowerBuff(LPSTR str,UINT len)
115 int i;
116 len=(len==0)?65536:len;
117 i=0;
119 for(i=0;i<len;i++)
120 str[i]=tolower(str[i]);
122 return i;
125 /* AnsiNext USER.472 */
126 LPSTR AnsiNext(LPSTR current)
128 return (*current)?current+1:current;
131 /* AnsiPrev USER.473 */
132 char FAR* AnsiPrev(/*const*/ char FAR* start,char FAR* current)
134 return (current==start)?start:current-1;
137 /* IsCharAlpha USER 433 */
138 BOOL IsCharAlpha(char ch)
140 return isalpha(ch); /* This is probably not right for NLS */
142 /* IsCharAlphanumeric USER 434 */
143 BOOL IsCharAlphanumeric(char ch)
145 return (ch<'0')?0:(ch<'9');
148 /* IsCharUpper USER 435 */
149 BOOL IsCharUpper(char ch)
151 return isupper(ch);
154 /* IsCharUpper USER 436 */
155 BOOL IsCharLower(char ch)
157 return islower(ch);
160 static char Oem2Ansi[256];
161 static char Ansi2Oem[256];
163 void InitOemAnsiTranslations(void)
165 static int inited=0; /* should called called in some init function*/
166 int transfile,i;
167 if(inited) return;
168 if(transfile=open("oem2ansi.trl",O_RDONLY)){
169 read(transfile,Oem2Ansi,256);
170 close(transfile);
172 else { /* sets up passive translations if it does not find the file */
173 for(i=0;i<256;i++) /* Needs some fixing */
174 Oem2Ansi[i]=i;
176 if(transfile=open("ansi2oem.trl",O_RDONLY)){
177 read(transfile,Ansi2Oem,256);
178 close(transfile);
180 else { /* sets up passive translations if it does not find the file */
181 for(i=0;i<256;i++) /* Needs some fixing */
182 Ansi2Oem[i]=i;
184 inited=1;
187 /* AnsiToOem Keyboard.5 */
188 INT AnsiToOem(LPSTR lpAnsiStr, LPSTR lpOemStr) /* why is this int ??? */
190 InitOemAnsiTranslations(); /* should called called in some init function*/
191 while(*lpAnsiStr){
192 *lpOemStr++=Ansi2Oem[*lpAnsiStr++];
194 return -1;
197 /* OemToAnsi Keyboard.6 */
198 BOOL OemToAnsi(LPSTR lpOemStr, LPSTR lpAnsiStr) /* why is this BOOL ???? */
200 InitOemAnsiTranslations(); /* should called called in some init function*/
201 while(*lpOemStr){
202 *lpAnsiStr++=Oem2Ansi[*lpOemStr++];
204 return -1;
207 /* AnsiToOemBuff Keyboard.134 */
208 void AnsiToOemBuff(LPSTR lpAnsiStr, LPSTR lpOemStr, INT nLength)
210 int i;
211 InitOemAnsiTranslations(); /* should called called in some init function*/
212 for(i=0;i<nLength;i++)
213 lpOemStr[i]=Ansi2Oem[lpAnsiStr[i]];
216 /* OemToAnsi Keyboard.135 */
217 void OemToAnsiBuff(LPSTR lpOemStr, LPSTR lpAnsiStr, INT nLength)
219 int i;
220 InitOemAnsiTranslations(); /* should called called in some init function*/
221 for(i=0;i<nLength;i++)
222 lpAnsiStr[i]=Oem2Ansi[lpOemStr[i]];