Fix for initialization of scalos preferences library. Library is now loaded only...
[AROS-Contrib.git] / rexx / lstring / equal.c
blobf74ad06217a38ace0302281cbeb8193896518a4b
1 /*
2 * $Header$
3 * $Log$
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.3 1999/11/26 09:56:55 bnv
8 * Changed: To use the new macros.
9 * Changed: From char* to byte* comparison, to avoid signed char problems.
10 * Changed: To use the lLastScannedNumber
12 * Revision 1.2 1998/11/10 13:36:14 bnv
13 * Comparison for reals is done with fabs(a-b)<smallnumber
15 * Revision 1.1 1998/07/02 17:18:00 bnv
16 * Initial Version
20 #include <math.h>
21 #include <ctype.h>
22 #include <string.h>
23 #include <lstring.h>
25 /* -------------------- Lequal ----------------- */
26 int
27 Lequal(const PLstr A, const PLstr B)
29 int ta, tb;
30 byte *a, *b; /* start position in string */
31 byte *ae, *be; /* ending position in string */
32 double ra, rb;
34 if (LTYPE(*A)==LSTRING_TY) {
35 ta = _Lisnum(A);
37 /* check to see if the first argument is string? */
38 if (ta == LSTRING_TY) {
39 L2STR(B); /* make string and the second */
40 goto eq_str; /* go and check strings */
43 ra = lLastScannedNumber;
44 } else {
45 ta = LTYPE(*A);
46 ra = TOREAL(*A);
49 if (LTYPE(*B)==LSTRING_TY) {
50 tb = _Lisnum(B);
51 rb = lLastScannedNumber;
52 } else {
53 tb = LTYPE(*B);
54 rb = TOREAL(*B);
57 /* is B also a number */
58 if (tb != LSTRING_TY) {
59 if (fabs(ra-rb)<=1E-14)
60 return 0;
61 else
62 if (ra>rb)
63 return 1;
64 else
65 return -1;
68 /* nope it was a string */
69 L2STR(A); /* convert A string */
70 eq_str:
71 a = (byte*)LSTR(*A);
72 ae = a + LLEN(*A);
73 for(; (a<ae) && ISSPACE(*a); a++) ;
75 b = (byte*)LSTR(*B);
76 be = b + LLEN(*B);
77 for(; (b<be) && ISSPACE(*b); b++) ;
79 for(;(a<ae) && (b<be) && (*a==*b); a++,b++) ;
81 for(; (a<ae) && ISSPACE(*a);a++) ;
82 for(; (b<be) && ISSPACE(*b);b++) ;
84 if (a==ae && b==be)
85 return 0;
86 else
87 if (a<ae && b<be)
88 return (*a<*b) ? -1 : 1 ;
89 else
90 return (a<ae) ? 1 : -1 ;
91 } /* Lequal */