Release 941017
[wine/gsoc-2012-control.git] / misc / lstr.c
blob41174f3e24ca5805aae26cf6655a88142ec7b7d4
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"
15 #define ToUpper(c) toupper(c)
16 #define ToLower(c) tolower(c)
18 /* Funny to divide them between user and kernel. */
20 /* KERNEL.89 */
21 LPSTR lstrcat(LPSTR target,LPCSTR source)
23 #ifdef DEBUG_STRING
24 fprintf(stderr,"lstrcat(%s,%s)\n",target,source);
25 #endif
26 return strcat(target,source);
29 /* USER.430 */
30 INT lstrcmp(LPCSTR str1,LPCSTR str2)
32 return strcmp(str1,str2);
35 /* USER.471 */
36 INT lstrcmpi(LPCSTR str1,LPCSTR str2)
38 int i;
39 i=0;
40 while((toupper(str1[i])==toupper(str2[i]))&&(str1[i]!=0))
41 i++;
42 return toupper(str1[i])-toupper(str2[i]);
45 /* KERNEL.88 */
46 LPSTR lstrcpy(LPSTR target,LPCSTR source)
48 return strcpy(target,source);
51 /* KERNEL.353 */
52 LPSTR lstrcpyn(LPSTR target,LPCSTR source,int n)
54 return strncpy(target,source,n);
57 /* KERNEL.90 */
58 INT lstrlen(LPCSTR str)
60 return strlen(str);
63 /* IsCharAlpha USER 433 */
64 BOOL IsCharAlpha(char ch)
66 return isalpha(ch); /* This is probably not right for NLS */
69 /* IsCharAlphanumeric USER 434 */
70 BOOL IsCharAlphanumeric(char ch)
72 return (ch<'0')?0:(ch<'9');
75 /* IsCharUpper USER 435 */
76 BOOL IsCharUpper(char ch)
78 return isupper(ch);
81 /* IsCharLower USER 436 */
82 BOOL IsCharLower(char ch)
84 return islower(ch);
87 /* AnsiUpper USER.431 */
88 LPSTR AnsiUpper(LPSTR strOrChar)
90 char *s = strOrChar;
91 /* I am not sure if the locale stuff works with toupper, but then again
92 I am not sure if the Linux libc locale stuffs works at all */
94 /* uppercase only one char if strOrChar < 0x10000 */
95 if(HIWORD((DWORD)strOrChar)) {
96 while (*s) {
97 if (IsCharLower(*s))
98 *s = ToUpper(*s);
99 s++;
101 return strOrChar;
102 } else
103 if (IsCharLower((int)strOrChar))
104 return (LPSTR) ToUpper((int)strOrChar);
105 else
106 return (LPSTR) strOrChar;
109 /* AnsiUpperBuff USER.437 */
110 UINT AnsiUpperBuff(LPSTR str,UINT len)
112 int i;
113 len=(len==0)?65536:len;
115 for(i=0;i<len;i++)
116 str[i]=toupper(str[i]);
117 return i;
120 /* AnsiLower USER.432 */
121 LPSTR AnsiLower(LPSTR strOrChar)
123 char *s = strOrChar;
124 /* I am not sure if the locale stuff works with toupper, but then again
125 I am not sure if the Linux libc locale stuffs works at all */
127 /* lowercase only one char if strOrChar < 0x10000 */
128 if(HIWORD((DWORD)strOrChar)) {
129 while (*s) {
130 if (IsCharUpper(*s))
131 *s = ToLower(*s);
132 s++;
134 return strOrChar;
135 } else
136 if (IsCharUpper((int)strOrChar))
137 return (LPSTR) ToLower((int)strOrChar);
138 else
139 return (LPSTR) strOrChar;
142 /* AnsiLowerBuff USER.438 */
143 UINT AnsiLowerBuff(LPSTR str,UINT len)
145 int i;
146 len=(len==0)?65536:len;
147 i=0;
149 for(i=0;i<len;i++)
150 str[i]=tolower(str[i]);
152 return i;
155 /* AnsiNext USER.472 */
156 LPSTR AnsiNext(LPSTR current)
158 return (*current)?current+1:current;
161 /* AnsiPrev USER.473 */
162 char FAR* AnsiPrev(/*const*/ char FAR* start,char FAR* current)
164 return (current==start)?start:current-1;
167 static char Oem2Ansi[256];
168 static char Ansi2Oem[256];
170 void InitOemAnsiTranslations(void)
172 static int inited=0; /* should called called in some init function*/
173 int transfile,i;
174 if(inited) return;
175 if(transfile=open("oem2ansi.trl",O_RDONLY)){
176 read(transfile,Oem2Ansi,256);
177 close(transfile);
179 else { /* sets up passive translations if it does not find the file */
180 for(i=0;i<256;i++) /* Needs some fixing */
181 Oem2Ansi[i]=i;
183 if(transfile=open("ansi2oem.trl",O_RDONLY)){
184 read(transfile,Ansi2Oem,256);
185 close(transfile);
187 else { /* sets up passive translations if it does not find the file */
188 for(i=0;i<256;i++) /* Needs some fixing */
189 Ansi2Oem[i]=i;
191 inited=1;
194 /* AnsiToOem Keyboard.5 */
195 INT AnsiToOem(LPSTR lpAnsiStr, LPSTR lpOemStr) /* why is this int ??? */
197 InitOemAnsiTranslations(); /* should called called in some init function*/
198 while(*lpAnsiStr){
199 *lpOemStr++=Ansi2Oem[*lpAnsiStr++];
201 return -1;
204 /* OemToAnsi Keyboard.6 */
205 BOOL OemToAnsi(LPSTR lpOemStr, LPSTR lpAnsiStr) /* why is this BOOL ???? */
207 InitOemAnsiTranslations(); /* should called called in some init function*/
208 while(*lpOemStr){
209 *lpAnsiStr++=Oem2Ansi[*lpOemStr++];
211 return -1;
214 /* AnsiToOemBuff Keyboard.134 */
215 void AnsiToOemBuff(LPSTR lpAnsiStr, LPSTR lpOemStr, INT nLength)
217 int i;
218 InitOemAnsiTranslations(); /* should called called in some init function*/
219 for(i=0;i<nLength;i++)
220 lpOemStr[i]=Ansi2Oem[lpAnsiStr[i]];
223 /* OemToAnsi Keyboard.135 */
224 void OemToAnsiBuff(LPSTR lpOemStr, LPSTR lpAnsiStr, INT nLength)
226 int i;
227 InitOemAnsiTranslations(); /* should called called in some init function*/
228 for(i=0;i<nLength;i++)
229 lpAnsiStr[i]=Oem2Ansi[lpOemStr[i]];