#define LF 10 #define CR 13 trim(s) char *s; { int i; char buf[1024]; /* trim right */ while ( 1 ) { i = strlen(s) - 1; if (s[i] == LF || s[i] == CR || s[i] == ' ') s[i] = '\0'; else break; } /* trim left */ while ( 1 ) { if (s[0] == LF || s[0] == CR || s[0] == ' ') { strcpy(buf, s+1); strcpy(s, buf); } else break; } } void strlower(char *org_s) /* small capitalize a string */ { char c, buf[256]; int i; for(i=0; i<=strlen(org_s); i++) { if ( isalpha(org_s[i]) && isupper(org_s[i]) ) org_s[i] = org_s[i] + 32; } buf[i] = '\0'; } // ########################### urlencode ##################################### static unsigned char hexchars[] = "0123456789ABCDEF"; char *URLencode(const char *s) { int x, y; int len; unsigned char *str; char *ptr; len = strlen(s); str = (unsigned char *) malloc(3 * len + 1); for (x = 0, y = 0; len--; x++, y++) { str[y] = (unsigned char) s[x]; if ((str[y] < '0' && str[y] != '-' && str[y] != '.' && str[y] != '/') || (str[y] < 'A' && str[y] > '9') || (str[y] > 'Z' && str[y] < 'a' && str[y] != '_') || (str[y] > 'z')) { str[y++] = '%'; str[y++] = hexchars[(unsigned char) s[x] >> 4]; str[y] = hexchars[(unsigned char) s[x] & 15]; } } str[y] = '\0'; return ((char *) str); }