OSDN Git Service

* Previous contents of gcc/f/runtime moved into toplevel
[pf3gnuchains/gcc-fork.git] / libf2c / libF77 / s_cmp.c
1 #include "f2c.h"
2
3 /* compare two strings */
4
5 #ifdef KR_headers
6 integer s_cmp(a0, b0, la, lb) char *a0, *b0; ftnlen la, lb;
7 #else
8 integer s_cmp(char *a0, char *b0, ftnlen la, ftnlen lb)
9 #endif
10 {
11 register unsigned char *a, *aend, *b, *bend;
12 a = (unsigned char *)a0;
13 b = (unsigned char *)b0;
14 aend = a + la;
15 bend = b + lb;
16
17 if(la <= lb)
18         {
19         while(a < aend)
20                 if(*a != *b)
21                         return( *a - *b );
22                 else
23                         { ++a; ++b; }
24
25         while(b < bend)
26                 if(*b != ' ')
27                         return( ' ' - *b );
28                 else    ++b;
29         }
30
31 else
32         {
33         while(b < bend)
34                 if(*a == *b)
35                         { ++a; ++b; }
36                 else
37                         return( *a - *b );
38         while(a < aend)
39                 if(*a != ' ')
40                         return(*a - ' ');
41                 else    ++a;
42         }
43 return(0);
44 }