Add a new chartype module for character classification. Use the new
function IsDigit in target.c. git-svn-id: svn://svn.cc65.org/cc65/trunk@592 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
608f27b274
commit
37da7dff98
5 changed files with 229 additions and 4 deletions
128
src/common/chartype.c
Normal file
128
src/common/chartype.c
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* chartype.c */
|
||||||
|
/* */
|
||||||
|
/* Character classification functions */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include "chartype.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* This module contains replacements for functions in ctype.h besides other
|
||||||
|
* functions. There is a problem with using ctype.h directly:
|
||||||
|
* The parameter must have a value of "unsigned char" or EOF.
|
||||||
|
* So on platforms where a char is signed, this may give problems or at
|
||||||
|
* least warnings. The wrapper functions below will have an "char" parameter
|
||||||
|
* but handle it correctly. They will NOT work for EOF, but this is not a
|
||||||
|
* problem, since EOF is always handled separately.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsAlpha (char C)
|
||||||
|
/* Check for a letter */
|
||||||
|
{
|
||||||
|
return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsAlNum (char C)
|
||||||
|
/* Check for letter or digit */
|
||||||
|
{
|
||||||
|
return (C >= 'a' && C <= 'z') || (C >= 'A' && C <= 'Z') || (C >= '0' && C <= '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsAscii (char C)
|
||||||
|
/* Check for an ASCII character */
|
||||||
|
{
|
||||||
|
return (C & ~0x7F) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsBlank (char C)
|
||||||
|
/* Check for a space, tab or newline */
|
||||||
|
{
|
||||||
|
return (C == ' ' || C == '\t' || C == '\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsDigit (char C)
|
||||||
|
/* Check for a digit */
|
||||||
|
{
|
||||||
|
return (C >= '0' && C <= '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsLower (char C)
|
||||||
|
/* Check for a lower case char */
|
||||||
|
{
|
||||||
|
return (C >= 'a' && C <= 'z');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsUpper (char C)
|
||||||
|
/* Check for upper case characters */
|
||||||
|
{
|
||||||
|
return (C >= 'A' && C <= 'Z');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsXDigit (char C)
|
||||||
|
/* Check for hexadecimal digits */
|
||||||
|
{
|
||||||
|
return (C >= 'a' && C <= 'f') || (C >= 'A' && C <= 'F') || (C >= '0' && C <= '9');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsQuote (char C)
|
||||||
|
/* Check for a single or double quote */
|
||||||
|
{
|
||||||
|
return (C == '"' || C == '\'');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
95
src/common/chartype.h
Normal file
95
src/common/chartype.h
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* chartype.h */
|
||||||
|
/* */
|
||||||
|
/* Character classification functions */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* (C) 2000 Ullrich von Bassewitz */
|
||||||
|
/* Wacholderweg 14 */
|
||||||
|
/* D-70597 Stuttgart */
|
||||||
|
/* EMail: uz@musoftware.de */
|
||||||
|
/* */
|
||||||
|
/* */
|
||||||
|
/* This software is provided 'as-is', without any expressed or implied */
|
||||||
|
/* warranty. In no event will the authors be held liable for any damages */
|
||||||
|
/* arising from the use of this software. */
|
||||||
|
/* */
|
||||||
|
/* Permission is granted to anyone to use this software for any purpose, */
|
||||||
|
/* including commercial applications, and to alter it and redistribute it */
|
||||||
|
/* freely, subject to the following restrictions: */
|
||||||
|
/* */
|
||||||
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
||||||
|
/* claim that you wrote the original software. If you use this software */
|
||||||
|
/* in a product, an acknowledgment in the product documentation would be */
|
||||||
|
/* appreciated but is not required. */
|
||||||
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
||||||
|
/* be misrepresented as being the original software. */
|
||||||
|
/* 3. This notice may not be removed or altered from any source */
|
||||||
|
/* distribution. */
|
||||||
|
/* */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef CHARTYPE_H
|
||||||
|
#define CHARTYPE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* This module contains replacements for functions in ctype.h besides other
|
||||||
|
* functions. There is a problem with using ctype.h directly:
|
||||||
|
* The parameter must have a value of "unsigned char" or EOF.
|
||||||
|
* So on platforms where a char is signed, this may give problems or at
|
||||||
|
* least warnings. The wrapper functions below will have an "char" parameter
|
||||||
|
* but handle it correctly. They will NOT work for EOF, but this is not a
|
||||||
|
* problem, since EOF is always handled separately.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*****************************************************************************/
|
||||||
|
/* Code */
|
||||||
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int IsAlpha (char C);
|
||||||
|
/* Check for a letter */
|
||||||
|
|
||||||
|
int IsAlNum (char C);
|
||||||
|
/* Check for letter or digit */
|
||||||
|
|
||||||
|
int IsAscii (char C);
|
||||||
|
/* Check for an ASCII character */
|
||||||
|
|
||||||
|
int IsBlank (char C);
|
||||||
|
/* Check for a space, tab or newline */
|
||||||
|
|
||||||
|
int IsDigit (char C);
|
||||||
|
/* Check for a digit */
|
||||||
|
|
||||||
|
int IsLower (char C);
|
||||||
|
/* Check for a lower case char */
|
||||||
|
|
||||||
|
int IsSpace (char C);
|
||||||
|
/* Check for white space characters */
|
||||||
|
|
||||||
|
int IsUpper (char C);
|
||||||
|
/* Check for upper case characters */
|
||||||
|
|
||||||
|
int IsXDigit (char C);
|
||||||
|
/* Check for hexadecimal digits */
|
||||||
|
|
||||||
|
int IsQuote (char C);
|
||||||
|
/* Check for a single or double quote */
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* End of chartype.h */
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ LIB = common.a
|
||||||
|
|
||||||
OBJS = abend.o \
|
OBJS = abend.o \
|
||||||
bitops.o \
|
bitops.o \
|
||||||
|
chartype.o \
|
||||||
check.o \
|
check.o \
|
||||||
cmdline.o \
|
cmdline.o \
|
||||||
coll.o \
|
coll.o \
|
||||||
|
|
|
@ -67,6 +67,7 @@ CCCFG = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
|
||||||
|
|
||||||
OBJS = abend.obj \
|
OBJS = abend.obj \
|
||||||
bitops.obj \
|
bitops.obj \
|
||||||
|
chartype.obj \
|
||||||
check.obj \
|
check.obj \
|
||||||
cmdline.obj \
|
cmdline.obj \
|
||||||
coll.obj \
|
coll.obj \
|
||||||
|
|
|
@ -35,8 +35,8 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
|
#include "chartype.h"
|
||||||
#include "target.h"
|
#include "target.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ target_t FindTarget (const char* Name)
|
||||||
unsigned I;
|
unsigned I;
|
||||||
|
|
||||||
/* Check for a numeric target */
|
/* Check for a numeric target */
|
||||||
if (isdigit (*Name)) {
|
if (IsDigit (*Name)) {
|
||||||
int Target = atoi (Name);
|
int Target = atoi (Name);
|
||||||
if (Target >= 0 && Target < TGT_COUNT) {
|
if (Target >= 0 && Target < TGT_COUNT) {
|
||||||
return (target_t)Target;
|
return (target_t)Target;
|
||||||
|
|
Loading…
Add table
Reference in a new issue