efine MAXSTR 100
void substr(char *s, char *t, int maxstr);
int numcmp(char *s1, char *s2)
{
double v1, v2;
char str[MAXSTR];
substr(s1, str, MAXSTR);
v1 = atof(str);
substr(s2, str, MAXSTR);
v2 = atof(str);
if (v1 < v2)
return -1;
else if (v1 > v2)
return 1;
else
return 0;
}
#define FOLD 4
#define DIR 8
int charcmp(char *s, char *t)
{
char a, b;
int i, j, endpos;
extern char option;
extern int pos1, pos2;
int fold = (option & FOLD) ? 1: 0;
int dir = (option & DIR) ? 1: 0;
i = j = pos1;
if (pos2 > 0)
endpos = pos2;
else if ((endpos = strlen(s)) > strlen(t))
endpos = strlen(t);
do {
if (dir) {
while (i < endpos && !isalpha(s[i]) && s[i] != && s[i] != \0)
i++;
while (j < endpos && !isalpha(t[j]) && t[j] != && t[j] != \0)
j++;
}
if (i < endpos && j < endpos) {
a = fold ? tolower(s[i]): s[i];
i++;
b = fold ? tolower(t[j]): t[j];
j++;
if (a == b && a == \0)
return 0;
}
} while (a == b && i < endpos && j < endpos);
return a - b;
}
//substr.c
#include
void error(char *);
void substr(char *s, char *str)
{
int i, j, len;
extern int pos1, pos2;
len = strlen(s);
if (pos2 > 0 && len > pos2)
len = pos2;
else if (pos2 > 0 && len < pos2)
error("substr: string too short");
for (j = 0, i = pos1; i < len; i++, j++)
str[j] = s[i];
str[j] = \0;
}