4 * Revision 1.1 2001/04/04 05:43:37 wang
5 * First commit: compiles on Linux, Amiga, Windows, Windows CE, generic gcc
7 * Revision 1.5 1999/11/29 14:58:00 bnv
8 * Changed: Some defines
10 * Revision 1.4 1999/05/14 13:06:01 bnv
13 * Revision 1.3 1999/03/10 16:57:31 bnv
14 * Changed: from __GREEK__ to GREEK
16 * Revision 1.2 1998/09/09 08:44:59 bnv
17 * Removed somed "const" in function calls
19 * Revision 1.1 1998/07/02 17:35:50 bnv
46 /* --- Lstring types --- */
47 enum TYPES
{ LSTRING_TY
,
51 typedef void (*LerrorFunc
)(const int,const int,...);
53 /* ------------------------- */
54 /* --- Lstring structure --- */
55 /* ------------------------- */
56 typedef struct Lstr_st
{
57 char *pstr
; /* String (Data) pointer */
58 size_t len
; /* Actual length of string(data) */
59 size_t maxlen
; /* Maximum length allocated for string */
60 short type
; /* Type of data STRING, INT, REAL */
62 short options
; /* Bit-options */
68 /* ---------------- Macros ------------------- */
69 /* --- lstring data --- */
70 #define LSTR(L) ((L).pstr)
71 #define LINT(L) (*(long*)((L).pstr))
72 #define LREAL(L) (*(double*)((L).pstr))
73 #define LLEN(L) ((L).len)
74 #define LTYPE(L) ((L).type)
75 #define LMAXLEN(L) ((L).maxlen)
76 #define LOPT(L) ((L).options)
79 #define LOPTION(L,O) ((L).options & (O))
80 #define LSETOPT(L,O) ((L).options |= (O))
81 #define LUNSETOPT(L,O) ((L).options &= ~(O))
84 #define LASCIIZ(s) {LSTR(s)[LLEN(s)] = '\0';}
85 #define LZEROSTR(s) {(s).len=0; (s).type=LSTRING_TY;}
86 #define LISNULL(s) (!(s).pstr)
89 #define IS_NUMBER(A) (_Lisnum(A) != LSTRING_TY)
90 #define IS_INT(A) (LREAL(A) == (double)(long)LREAL(A))
91 #define TOREAL(A) ((LTYPE(A)==LINTEGER_TY)? (double) LINT(A): LREAL(A))
92 #define TOINT(A) ((LTYPE(A)==LINTEGER_TY)? LINT(A): (long)LREAL(A))
93 #define ODD(n) ((n)&0x1)
95 /* --- allocate strings --- */
98 #define LINITSTR(s) {(s).pstr=NULL;(s).len=0;(s).maxlen=0; \
99 (s).type=LSTRING_TY;(s).options=0;}
100 #define LFREESTR(s) {if ((s).pstr && !LOPTION((s),LOPTFIX)) \
102 #define LMOVESTR(d,s) {(d).pstr=(s).pstr; (s).pstr=NULL; \
103 (d).len=(s).len; (s).len=0; \
104 (d).maxlen=(s).maxlen; (s).maxlen=0; \
105 (d).type=(s).type; (s).type=0; \
106 (d).options=(s).options;(s).options=0;}
108 #define LPMALLOC(s) {(s)=(PLstr)MALLOC(sizeof(Lstr),"PLstr");LINITSTR(*(s));}
109 #define LPFREE(s) {if ((s)->pstr && !LOPTION((*s),LOPTFIX)) \
110 FREE((s)->pstr); FREE((s));}
112 #else /* DO NOT USE OPTION */
114 #define LINITSTR(s) {(s).pstr=NULL;(s).len=0;(s).maxlen=0; \
115 (s).type=LSTRING_TY;}
116 #define LFREESTR(s) {if ((s).pstr) FREE((s).pstr); }
117 #define LMOVESTR(d,s) {(d).pstr=(s).pstr; (s).pstr=NULL; \
118 (d).len=(s).len; (s).len=0; \
119 (d).maxlen=(s).maxlen; (s).maxlen=0; \
120 (d).type=(s).type; (s).type=0;}
122 #define LPMALLOC(s) {(s)=(PLstr)MALLOC(sizeof(Lstr),"PLstr");LINITSTR(*(s));}
123 #define LPFREE(s) {if ((s)->pstr) FREE((s)->pstr); FREE((s));}
126 #define LICPY(s,i) { LINT(s) = (i); \
127 LLEN(s) = sizeof(long); \
128 LTYPE(s) = LINTEGER_TY; }
131 #define LSKIPBLANKS(S,P) {while (((P)<LLEN(S)) && ISSPACE(LSTR(S)[P])) (P)++;}
132 #define LSKIPWORD(S,P) {while (((P)<LLEN(S)) && !ISSPACE(LSTR(S)[P])) (P)++;}
134 /* --- transform --- */
135 #define L2INT(s) if (LTYPE(*(s))!=LINTEGER_TY) L2int((s))
136 #define L2REAL(s) if (LTYPE(*(s))!=LREAL_TY) L2real((s))
137 #define _L2NUM(s,t) if (LTYPE(*(s))==LSTRING_TY) _L2num((s),(t))
138 #define L2NUM(s) if (LTYPE(*(s))==LSTRING_TY) L2num((s))
139 #define L2STR(s) if (LTYPE(*(s))!=LSTRING_TY) L2str((s))
141 /* -------------------- definitions ---------------------- */
142 /* --- lstring options --- */
143 #define LOPTFIX 0x0001
144 #define LOPTINT 0x0002
145 #define LOPTREAL 0x0004
147 /* --- strip options --- */
150 #define LTRAILING 'T'
152 /* --- position options --- */
153 #define LREST -1 /* for rest of string ie in substr */
154 #define LNOTFOUND 0 /* for not found ie Lindex */
156 /* --- file options --- */
158 #define LREADINCSIZE 32
161 #define LMAXNUMERICDIGITS 7
163 /* --- for interal use of lstring --- */
164 /* With some extra chars */
165 /* it must have enough space to allow transformation from */
166 /* int or real to string without resizing */
167 #define LNORMALISE(size) ((size) | 0x000F)
170 /* --------------- Lstr function prototypes --------------- */
171 void Linit(LerrorFunc
); /* must be called at initialisation */
173 void _Lfree(void *str
); /* free a Lstring */
175 void Lfx (const PLstr s
, const size_t len
);
176 void Licpy (const PLstr to
, const long from
);
177 void Lrcpy (const PLstr to
, const double from
);
178 void Lscpy (const PLstr to
, const char *from
);
179 void Lwscpy(const PLstr to
, const wchar_t *from
);
180 void Lcat (const PLstr to
, const char *from
);
181 int Lcmp (const PLstr a
, const char *b
);
183 void Lstrcpy ( const PLstr to
, const PLstr from
);
184 void Lstrcat ( const PLstr to
, const PLstr from
);
185 void Lstrset ( const PLstr to
, const size_t length
, const char value
);
186 int _Lstrcmp( const PLstr a
, const PLstr b
);
187 int Lstrcmp ( const PLstr a
, const PLstr b
);
189 void _Lsubstr( const PLstr to
, const PLstr from
, size_t start
, size_t length
);
190 int _Lisnum ( const PLstr s
);
192 void L2str ( const PLstr s
);
193 void L2int ( const PLstr s
);
194 void L2real ( const PLstr s
);
195 void _L2num ( const PLstr s
, const int type
);
196 void L2num ( const PLstr s
);
198 long Lrdint ( const PLstr s
);
199 double Lrdreal( const PLstr s
);
201 void _Ltimeinit(void);
203 bool Labbrev ( const PLstr information
, const PLstr info
,
205 void Lb2x ( const PLstr to
, const PLstr from
);
206 void Lbitand ( const PLstr to
, const PLstr s1
, const PLstr s2
,
207 const bool usepad
, const char pad
);
208 void Lbitor ( const PLstr to
, const PLstr s1
, const PLstr s2
,
209 const bool usepad
, const char pad
);
210 void Lbitxor ( const PLstr to
, const PLstr s1
, const PLstr s2
,
211 const bool usepad
, const char pad
);
212 void Lc2d ( const PLstr to
, const PLstr from
, long n
);
213 void Lc2x ( const PLstr to
, const PLstr from
);
214 void Lcenter ( const PLstr to
, const PLstr str
, const long length
,
216 void Lchangestr(const PLstr to
, const PLstr oldstr
, const PLstr str
,
218 long Lcountstr(const PLstr target
, const PLstr source
);
219 void Lcharin ( FILEP f
, const PLstr line
, const long start
,
221 void Lcharout( FILEP f
, const PLstr line
, const long start
);
222 long Lchars ( FILEP f
);
223 long Lcompare( const PLstr A
, const PLstr B
, const char pad
);
224 void Lcopies ( const PLstr to
, const PLstr str
, long n
);
225 void Ld2c ( const PLstr to
, const PLstr from
, long n
);
226 void Ld2x ( const PLstr to
, const PLstr from
, long length
);
227 int Ldatatype(const PLstr str
, char type
);
228 void Ldate ( const PLstr datestr
, char option
);
229 void Ldelstr ( const PLstr to
, const PLstr str
, long start
, long length
);
230 void Ldelword( const PLstr to
, const PLstr str
, long start
, long length
);
231 void Lerrortext( const PLstr to
, const int errno
, const int subno
, va_list *ap
);
232 void Lformat ( const PLstr to
, const PLstr num
, long before
,
233 long after
, long expp
, long expt
);
234 word
Lhashvalue( const PLstr s
);
235 long Lindex ( const PLstr haystack
, const PLstr needle
, long p
);
236 void Linsert ( const PLstr to
, const PLstr target
, const PLstr newstr
,
237 long n
, long length
, const char pad
);
238 void Ljustify( const PLstr to
, const PLstr str
, long length
, char pad
);
239 long Llastpos( const PLstr needle
, const PLstr haystack
, long p
);
240 void Llinein ( FILEP f
, const PLstr line
, long *curline
,
241 long start
, long length
);
242 int Llineout( FILEP f
, const PLstr line
, long *curline
, long start
);
243 long Llines ( FILEP f
);
244 void Llower ( const PLstr s
);
245 void Loverlay( const PLstr to
, const PLstr str
, const PLstr target
,
246 long n
, long length
, const char pad
);
247 void Lprint ( FILEP f
, const PLstr str
);
248 void Lread ( FILEP f
, const PLstr line
, long size
);
249 void Lreverse( const PLstr s
);
250 void Lright ( const PLstr to
, const PLstr str
, const long length
,
252 void Lsoundex( const PLstr to
, const PLstr str
);
253 void Lstderr ( const int errno
, const int subno
, ... );
254 void Lstrip ( const PLstr to
, const PLstr str
, const char action
,
256 void Lspace ( const PLstr to
, const PLstr str
, long n
, const char pad
);
257 void Lsubstr ( const PLstr to
, const PLstr str
, long start
,
258 long length
, const char pad
);
259 void Lsubword( const PLstr to
, const PLstr from
, long n
, long length
);
260 void Ltime ( const PLstr timestr
, char option
);
261 void Ltranslate(const PLstr to
, const PLstr from
, const PLstr tableout
,
262 const PLstr tablein
, const char pad
);
263 void Ltrunc ( const PLstr to
, const PLstr from
, long n
);
264 long Lverify ( const PLstr str
, const PLstr ref
, const bool match
,
266 void Lupper ( const PLstr s
);
267 void Lword ( const PLstr to
, const PLstr from
, long n
);
268 long Lwordindex( const PLstr str
, long n
);
269 long Lwordlength( const PLstr str
, long n
);
270 long Lwordpos( const PLstr phrase
, const PLstr s
, long n
);
271 long Lwords ( const PLstr from
);
272 void Lwrite ( FILEP f
, const PLstr line
, const bool newline
);
273 void Lx2b ( const PLstr to
, const PLstr from
);
274 void Lx2c ( const PLstr to
, const PLstr from
);
275 void Lx2d ( const PLstr to
, const PLstr from
, long n
);
276 void Lxrange ( const PLstr to
, byte start
, byte stop
);
278 #define Leq(A,B) (Lequal(A,B)==0)
279 #define Lne(A,B) (Lequal(A,B)!=0)
280 #define Llt(A,B) (Lequal(A,B)<0)
281 #define Lle(A,B) (Lequal(A,B)<1)
282 #define Lge(A,B) (Lequal(A,B)>-1)
283 #define Lgt(A,B) (Lequal(A,B)>0)
285 #define Ldeq(A,B) (Lstrcmp(A,B)==0)
286 #define Ldne(A,B) (Lstrcmp(A,B)!=0)
287 #define Ldlt(A,B) (Lstrcmp(A,B)<0)
288 #define Ldle(A,B) (Lstrcmp(A,B)<1)
289 #define Ldge(A,B) (Lstrcmp(A,B)>-1)
290 #define Ldgt(A,B) (Lstrcmp(A,B)>0)
292 #define Lfind(str,phrase,n) Lwordpos(phrase,str,n)
293 #define Lleft(to,from,length,pad) Lsubstr(to,from,1,length,pad)
294 #define Lpos(needle,haystack,p) Lindex(haystack,needle,p)
296 /* ------------- Math functions --------------------- */
297 void Ladd ( const PLstr to
, const PLstr A
, const PLstr B
);
298 int Lbool ( const PLstr num
);
299 void Ldec ( const PLstr num
);
300 void Ldiv ( const PLstr to
, const PLstr A
, const PLstr B
);
301 int Lequal( const PLstr A
, const PLstr B
);
302 void Lexpose(const PLstr to
, const PLstr A
, const PLstr B
);
303 void Linc ( const PLstr num
);
304 void Lintdiv(const PLstr to
, const PLstr A
, const PLstr B
);
305 void Lmod ( const PLstr to
, const PLstr A
, const PLstr B
);
306 void Lmult ( const PLstr to
, const PLstr A
, const PLstr B
);
307 void Lneg ( const PLstr to
, const PLstr num
);
308 void Lsub ( const PLstr to
, const PLstr A
, const PLstr B
);
310 void Labs ( const PLstr result
, const PLstr num
);
311 int Lsign ( const PLstr num
);
312 void Lpow ( const PLstr result
, const PLstr num
, const PLstr p
);
313 #define DECLMATH( func ) void L##func(const PLstr result, const PLstr num)
330 /* ====================== Some variables ================ */
335 *clower
="abcdefghijklmnopqrstuvwxyz˜™š›œ�žŸ ¡¢£¤¥¦§¨©«¬®¯àªáâãåæçéäè",
336 *cUPPER
="ABCDEFGHIJKLMNOPQRSTUVWXYZ€�‚ƒ„…†‡ˆ‰Š‹Œ�Ž��‘’“”•–—‘êëìíîïðˆ“",
338 *clower
="abcdefghijklmnopqrstuvwxyzáâãäåæçèéêëìíîïðñóôõö÷øùÜÝÞßúÀüýûàþò",
339 *cUPPER
="ABCDEFGHIJKLMNOPQRSTUVWXYZÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÓÔÕÖ×ØÙ¶¸¹ºÚÚ¼¾ÛÛ¿Ó",
342 *clower
="abcdefghijklmnopqrstuvwxyz",
343 *cUPPER
="ABCDEFGHIJKLMNOPQRSTUVWXYZ",
345 *cdigits
= "0123456789",
346 *chex
= "0123456789ABCDEFabcdef",
347 *crxsymb
= "@#$_.?!";
349 double lLastScannedNumber
=0.0;
351 char lFormatStringToReal
[10] = "%.8lG";
353 int lNumericDigits
= LMAXNUMERICDIGITS
;
355 byte l2u
[256], u2l
[256];
364 extern double lLastScannedNumber
;
366 extern char lFormatStringToReal
[];
368 extern int lNumericDigits
;
369 extern byte l2u
[], u2l
[];
370 extern LerrorFunc Lerror
;