1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
/* $Id: strlwr.c,v 1.1 2007/03/01 13:10:55 dmix Exp $ */
#ifndef __AVR__
# include <ctype.h>
# include <stdio.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "progmem.h"
#ifndef __AVR__ /* strlwr() is't a standart function */
char * strlwr (char *s)
{
char *p = s;
while (*p) {
*p = tolower(*p);
p++;
}
return s;
}
#endif
void Check (int line, const char *s, const char *expect)
{
char t[200];
char *p;
int code;
if (strlen_P(s) > sizeof(t) - 1)
exit (1);
strcpy_P (t, s);
p = strlwr (t);
if (p != t)
code = line + 1000;
else if (strcmp_P (t, expect))
code = line;
else
return;
#if !defined(__AVR__)
printf ("\nLine %d: expect: \"%s\""
"\n result: \"%s\"\n",
line, expect, t);
if (code > 255) code = 255;
#elif defined(DEBUG)
exit ((int)t);
#endif
exit (code);
}
#define CHECK(s, expect) do { \
Check (__LINE__, PSTR(s), PSTR(expect)); \
} while (0)
int main ()
{
/* Empty string. */
CHECK ("", "");
CHECK ("A", "a");
CHECK ("Z", "z");
CHECK ("@[", "@["); /* '@'=='A'-1, '['=='Z'+1 */
CHECK ("`az{", "`az{"); /* '`'=='a'-1, '{'=='z'+1 */
CHECK ("QWERTYUIOPASDFGHJKLZXCVBNM", "qwertyuiopasdfghjklzxcvbnm");
CHECK ("FoO", "foo");
/* non-ASCII */
CHECK ("\001A\177\200\201B\377", "\001a\177\200\201b\377");
return 0;
}
|