File: strupr.c

package info (click to toggle)
avr-libc 1%3A1.6.2.cvs20080610-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 14,848 kB
  • ctags: 55,619
  • sloc: ansic: 92,267; asm: 6,692; sh: 4,131; makefile: 2,481; python: 976; pascal: 426; perl: 116
file content (71 lines) | stat: -rw-r--r-- 1,389 bytes parent folder | download
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: strupr.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__			/* strupr() is't a standart function	*/
char * strupr (char *s)
{
    char *p = s;
    while (*p) {
	*p = toupper(*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 = strupr (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;
}