revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / iffparse / goodid.c
blob6cb1672d126dcbaabe219d5cb26f8bf81b7b8369
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
7 #include <aros/debug.h>
8 #include "iffparse_intern.h"
10 #define DEBUG_GOODID(x) ;
12 /*****************************************************************************
14 NAME */
15 #include <proto/iffparse.h>
17 AROS_LH1(LONG, GoodID,
19 /* SYNOPSIS */
20 AROS_LHA(LONG, id, D0),
22 /* LOCATION */
23 struct Library *, IFFParseBase, 43, IFFParse)
25 /* FUNCTION
26 Determines whether an ID is valid according to the IFF specification.
28 INPUTS
29 id - An IFF chunk ID to be tested.
31 RESULT
32 TRUE if valid.
33 FALSE otherwise.
35 NOTES
36 Assumes input to be in local byte order.
38 EXAMPLE
40 BUGS
42 SEE ALSO
44 INTERNALS
46 *****************************************************************************/
48 AROS_LIBFUNC_INIT
50 UBYTE theId[4];
52 (void) IFFParseBase;
54 theId[0] = id >> 24;
55 theId[1] = id >> 16;
56 theId[2] = id >> 8;
57 theId[3] = id;
59 DEBUG_GOODID(bug("theid: 0x%08lx [%c%c%c%c]\n",
60 id, theId[0], theId[1], theId[2], theId[3]));
62 /* If the ID starts with a space, but is not all spaces, then invalid */
63 if((theId[0] == 0x20) && (id != 0x20202020))
65 DEBUG_GOODID(bug("badid 1\n"));
66 return (FALSE);
70 Check whether the ID is within the allowed character ranges.
71 This loop is unrolled
74 if( (theId[0] < 0x20) || (theId[0] > 0x7e))
76 DEBUG_GOODID(bug("badid 2\n"));
77 return (FALSE);
79 if( (theId[1] < 0x20) || (theId[1] > 0x7e))
81 DEBUG_GOODID(bug("badid 3\n"));
82 return (FALSE);
84 if( (theId[2] < 0x20) || (theId[2] > 0x7e))
86 DEBUG_GOODID(bug("badid 4\n"));
87 return (FALSE);
89 if( (theId[3] < 0x20) || (theId[3] > 0x7e))
91 DEBUG_GOODID(bug("badid 5\n"));
92 return (FALSE);
95 DEBUG_GOODID(bug("goodid\n"));
96 return (TRUE);
98 AROS_LIBFUNC_EXIT
99 } /* GoodID */