forked from ge-ne/bibtool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtype.c
160 lines (149 loc) · 6.6 KB
/
type.c
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*** type.c *******************************************************************
**
** This file is part of BibTool.
** It is distributed under the GNU General Public License.
** See the file COPYING for details.
**
** (c) 1996-2017 Gerd Neugebauer
**
** Net: gene@gerd-neugebauer.de
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2, or (at your option)
** any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
**-----------------------------------------------------------------------------
**
** Description:
** This file contains functions to support a separate treatment of
** character types. The normal functions and macros in |ctype.h| are
** replaced by those in |type.h|. This file contains an initialization
** function which is required for the macros in |type.h| to work
** properly.
**
** See also the documentation of the header file |type.h| for
** further information.
**
******************************************************************************/
/*****************************************************************************/
/* Internal Programs */
/*===========================================================================*/
#define INIT_TYPE
#include <bibtool/general.h>
#include <bibtool/type.h>
/*****************************************************************************/
/* External Programs */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
#define to_lower(C) ((C) + 'a'-'A')
#define to_upper(C) ((C) + 'A'-'a')
/*-----------------------------------------------------------------------------
** Function: init_type()
** Purpose: This is the initialization routine for this file. This
** has to be called before some of the macros in |type.h|
** will work as described. It does no harm to call this
** initialization more than once. It just takes some time.
**
** Note that this function is for internal purposes
** only. The normal user should call |init_bibtool()|
** instead.
** Arguments: none
** Returns: nothing
**___________________________________________________ */
void init_type() /* */
{ register unsigned short int i; /* */
/* */
for ( i = 0; i < 256; ++i ) /* */
{ trans_lower[i] = is_upper(i) ? to_lower(i) : i;/* */
trans_upper[i] = is_lower(i) ? to_upper(i) : i;/* */
trans_id[i] = i; /* */
} /* */
} /*------------------------*/
/*-----------------------------------------------------------------------------
** Function: add_word_sep()
** Type: void
** Purpose:
** Mark some characters as word separator.
** Arguments:
** s the allowed word separator characters
** Returns: nothing
**___________________________________________________ */
void add_word_sep(s) /* */
register String s; /* */
{ /* */
if ( s == StringNULL ) return; /* */
for ( ; *s ; s++ ) /* */
{ type__allowed[*s] |= T__WordSep; } /* */
} /*------------------------*/
#ifdef DEBUG
#include <assert.h>
#endif
/*-----------------------------------------------------------------------------
** Function: case_eq()
** Purpose: Compare two strings ignoring cases. If the strings are
** identical up to differences in case then this function
** returns |true|.
** Arguments:
** s First string to consider.
** t Second string to consider.
** Returns: |true| iff the strings are equal.
**___________________________________________________ */
bool case_eq(s, t) /* */
register String s; /* */
register String t; /* */
{ /* */
#ifdef DEBUG
assert(s != NULL); /* */
assert(t != NULL); /* */
#endif
while ( *s ) /* */
{ if (ToLower(*(s++)) != ToLower(*(t++))) /* */
return false; /* */
} /* */
#ifdef DEBUG
assert(t != NULL); /* */
#endif
return (*t == '\0' ? true : false); /* */
} /*------------------------*/
/*-----------------------------------------------------------------------------
** Function: cmp()
** Type: int
** Purpose: Compare two strings.
** Arguments:
** s the first string
** t the second string
** Returns:
**___________________________________________________ */
int cmp(s, t) /* */
register String s; /* */
register String t; /* */
{ register int d; /* */
while ( *s ) /* */
{ d = *(s++) - *(t++); /* */
if ( d ) return d; /* */
} /* */
return *s - *t; /* */
} /*------------------------*/
/*-----------------------------------------------------------------------------
** Function: lower()
** Purpose: Function to translate all letters in a string to lower case.
** Arguments:
** s string to convert
** Returns: The converted string.
**___________________________________________________ */
String lower(s) /* */
register String s; /* */
{ String t = s; /* */
while ( *s ) { *s = ToLower(*s); ++s; } /* */
return t; /* */
} /*------------------------*/