OpenCores
URL https://opencores.org/ocsvn/jtag_stapl_player/jtag_stapl_player/trunk

Subversion Repositories jtag_stapl_player

[/] [jtag_stapl_player/] [trunk/] [jamutil.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sukhanov
/****************************************************************************/
2
/*                                                                                                                                                      */
3
/*      Module:                 jamutil.c                                                                                               */
4
/*                                                                                                                                                      */
5
/*                                      Copyright (C) Altera Corporation 1997                                   */
6
/*                                                                                                                                                      */
7
/*      Description:    Utility functions.  Most of these are private copies    */
8
/*                                      of standard 'C' library functions.  Having them here    */
9
/*                                      is intended to reduce porting hassles by eliminating    */
10
/*                                      the need for local run-time library functions                   */
11
/*                                                                                                                                                      */
12
/****************************************************************************/
13
 
14
/****************************************************************************/
15
/*                                                                                                                                                      */
16
/*      Actel version 1.1             May 2003                                                                  */
17
/*                                                                                                                                                      */
18
/****************************************************************************/
19
 
20
#include "jamutil.h"
21
 
22
char jam_toupper(char ch)
23
{
24
        return ((char) (((ch >= 'a') && (ch <= 'z')) ? (ch + 'A' - 'a') : ch));
25
}
26
 
27
int jam_iscntrl(char ch)
28
{
29
        return (((ch >= 0) && (ch <= 0x1f)) || (ch == 0x7f));
30
}
31
 
32
int jam_isalpha(char ch)
33
{
34
        return (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')));
35
}
36
 
37
int jam_isdigit(char ch)
38
{
39
        return ((ch >= '0') && (ch <= '9'));
40
}
41
 
42
int jam_isalnum(char ch)
43
{
44
        return (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')) ||
45
                ((ch >= '0') && (ch <= '9')));
46
}
47
 
48
int jam_isspace(char ch)
49
{
50
        return (((ch >= 0x09) && (ch <= 0x0d)) || (ch == 0x20));
51
}
52
 
53
int jam_is_name_char(char ch)
54
{
55
        return (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')) ||
56
                ((ch >= '0') && (ch <= '9')) || (ch == '_'));
57
}
58
 
59
int jam_is_hex_char(char ch)
60
{
61
        return (((ch >= 'A') && (ch <= 'F')) || ((ch >= 'a') && (ch <= 'f')) ||
62
                ((ch >= '0') && (ch <= '9')));
63
}
64
 
65
int jam_strlen(char *string)
66
{
67
        int len = 0;
68
 
69
        while (string[len] != '\0') ++len;
70
 
71
        return (len);
72
}
73
 
74
long jam_atol(char *string)
75
{
76
        long result = 0L;
77
        int index = 0;
78
 
79
        while ((string[index] >= '0') && (string[index] <= '9'))
80
        {
81
                result = (result * 10) + (string[index] - '0');
82
                ++index;
83
        }
84
 
85
        return (result);
86
}
87
 
88
void jam_ltoa(char *buffer, long number)
89
{
90
        int index = 0;
91
        int rev_index = 0;
92
        char reverse[32];
93
 
94
        if (number < 0L)
95
        {
96
                buffer[index++] = '-';
97
                number = 0 - number;
98
        }
99
        else if (number == 0)
100
        {
101
                buffer[index++] = '0';
102
        }
103
 
104
        while (number != 0)
105
        {
106
                reverse[rev_index++] = (char) ((number % 10) + '0');
107
                number /= 10;
108
        }
109
 
110
        while (rev_index > 0)
111
        {
112
                buffer[index++] = reverse[--rev_index];
113
        }
114
 
115
        buffer[index] = '\0';
116
}
117
 
118
int jam_strcmp(char *left, char *right)
119
{
120
        int result = 0;
121
        char l, r;
122
 
123
        do
124
        {
125
                l = *left;
126
                r = *right;
127
                result = l - r;
128
                ++left;
129
                ++right;
130
        }
131
        while ((result == 0) && (l != '\0') && (r != '\0'));
132
 
133
        return (result);
134
}
135
 
136
int jam_stricmp(char *left, char *right)
137
{
138
        int result = 0;
139
        char l, r;
140
 
141
        do
142
        {
143
                l = jam_toupper(*left);
144
                r = jam_toupper(*right);
145
                result = l - r;
146
                ++left;
147
                ++right;
148
        }
149
        while ((result == 0) && (l != '\0') && (r != '\0'));
150
 
151
        return (result);
152
}
153
 
154
int jam_strncmp(char *left, char *right, int count)
155
{
156
        int result = 0;
157
        char l, r;
158
 
159
        do
160
        {
161
                l = *left;
162
                r = *right;
163
                result = l - r;
164
                ++left;
165
                ++right;
166
                --count;
167
        }
168
        while ((result == 0) && (count > 0) && (l != '\0') && (r != '\0'));
169
 
170
        return (result);
171
}
172
 
173
int jam_strnicmp(char *left, char *right, int count)
174
{
175
        int result = 0;
176
        char l, r;
177
 
178
        do
179
        {
180
                l = jam_toupper(*left);
181
                r = jam_toupper(*right);
182
                result = l - r;
183
                ++left;
184
                ++right;
185
                --count;
186
        }
187
        while ((result == 0) && (count > 0) && (l != '\0') && (r != '\0'));
188
 
189
        return (result);
190
}
191
 
192
void jam_strcpy(char *left, char *right)
193
{
194
        char ch;
195
 
196
        do
197
        {
198
                *left = *right;
199
                ch = *right;
200
                ++left;
201
                ++right;
202
        }
203
        while (ch != '\0');
204
}
205
 
206
void jam_strncpy(char *left, char *right, int count)
207
{
208
        char ch;
209
 
210
        do
211
        {
212
                *left = *right;
213
                ch = *right;
214
                ++left;
215
                ++right;
216
                --count;
217
        }
218
        while ((ch != '\0') && (count != 0));
219
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.