240 |
kaklik |
1 |
CCS PCM C Compiler, Version 3.245, 27853 11-V-08 00:17 |
223 |
kapl |
2 |
|
239 |
kaklik |
3 |
Filename: D:\MLAB_E\projekty\Ovladani_mobilnim_telefonem\SW\final\main.lst |
223 |
kapl |
4 |
|
240 |
kaklik |
5 |
ROM used: 275 words (3%) |
238 |
kaklik |
6 |
Largest free fragment is 2048 |
240 |
kaklik |
7 |
RAM used: 52 (30%) at main() level |
|
|
8 |
56 (32%) worst case |
|
|
9 |
Stack: 1 locations |
223 |
kapl |
10 |
|
|
|
11 |
* |
|
|
12 |
0000: MOVLW 00 |
|
|
13 |
0001: MOVWF 0A |
240 |
kaklik |
14 |
0002: GOTO 057 |
223 |
kapl |
15 |
0003: NOP |
|
|
16 |
.................... #include ".\main.h" |
238 |
kaklik |
17 |
.................... #include <16F876A.h> |
|
|
18 |
.................... //////// Standard Header file for the PIC16F876A device //////////////// |
|
|
19 |
.................... #device PIC16F876A |
223 |
kapl |
20 |
.................... #list |
|
|
21 |
.................... |
|
|
22 |
.................... #device adc=8 |
|
|
23 |
.................... |
238 |
kaklik |
24 |
.................... #FUSES NOWDT //Watch Dog Timer |
|
|
25 |
.................... #FUSES HS//XT //Crystal osc <= 4mhz |
223 |
kapl |
26 |
.................... #FUSES NOPUT //No Power Up Timer |
|
|
27 |
.................... #FUSES NOPROTECT //Code not protected from reading |
|
|
28 |
.................... #FUSES NODEBUG //No Debug mode for ICD |
|
|
29 |
.................... #FUSES NOBROWNOUT //No brownout reset |
|
|
30 |
.................... #FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O |
|
|
31 |
.................... #FUSES NOCPD //No EE protection |
|
|
32 |
.................... #FUSES NOWRT //Program memory not write protected |
|
|
33 |
.................... |
238 |
kaklik |
34 |
.................... #use delay(clock=18432000,RESTART_WDT) |
240 |
kaklik |
35 |
0013: MOVLW 52 |
|
|
36 |
0014: MOVWF 04 |
|
|
37 |
0015: MOVF 00,W |
|
|
38 |
0016: BTFSC 03.2 |
|
|
39 |
0017: GOTO 028 |
|
|
40 |
0018: MOVLW 05 |
|
|
41 |
0019: MOVWF 78 |
|
|
42 |
001A: MOVLW BF |
|
|
43 |
001B: MOVWF 77 |
|
|
44 |
001C: CLRWDT |
|
|
45 |
001D: DECFSZ 77,F |
|
|
46 |
001E: GOTO 01C |
|
|
47 |
001F: DECFSZ 78,F |
|
|
48 |
0020: GOTO 01A |
|
|
49 |
0021: MOVLW F9 |
|
|
50 |
0022: MOVWF 77 |
|
|
51 |
0023: DECFSZ 77,F |
|
|
52 |
0024: GOTO 023 |
|
|
53 |
0025: CLRWDT |
|
|
54 |
0026: DECFSZ 00,F |
|
|
55 |
0027: GOTO 018 |
|
|
56 |
0028: RETLW 00 |
238 |
kaklik |
57 |
.................... #use rs232(STREAM=MOBIL,baud=19200,force_sw,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) |
|
|
58 |
* |
240 |
kaklik |
59 |
006B: MOVLW FF |
|
|
60 |
006C: BCF 03.5 |
|
|
61 |
006D: MOVWF 20 |
238 |
kaklik |
62 |
.................... #use rs232(STREAM=VRTULE,baud=600,parity=N,xmit=PIN_B2,rcv=PIN_B4,bits=8) |
|
|
63 |
* |
240 |
kaklik |
64 |
0029: BSF 03.5 |
|
|
65 |
002A: BCF 06.2 |
|
|
66 |
002B: BCF 03.5 |
|
|
67 |
002C: BCF 06.2 |
|
|
68 |
002D: MOVLW 08 |
|
|
69 |
002E: MOVWF 78 |
|
|
70 |
002F: NOP |
|
|
71 |
0030: NOP |
|
|
72 |
0031: NOP |
|
|
73 |
0032: BSF 78.7 |
|
|
74 |
0033: GOTO 043 |
|
|
75 |
0034: BCF 78.7 |
|
|
76 |
0035: RRF 52,F |
|
|
77 |
0036: BTFSC 03.0 |
|
|
78 |
0037: BSF 06.2 |
|
|
79 |
0038: BTFSS 03.0 |
|
|
80 |
0039: BCF 06.2 |
|
|
81 |
003A: BSF 78.6 |
|
|
82 |
003B: GOTO 043 |
|
|
83 |
003C: BCF 78.6 |
|
|
84 |
003D: DECFSZ 78,F |
|
|
85 |
003E: GOTO 035 |
|
|
86 |
003F: NOP |
|
|
87 |
0040: NOP |
|
|
88 |
0041: NOP |
|
|
89 |
0042: BSF 06.2 |
|
|
90 |
0043: MOVLW 09 |
|
|
91 |
0044: MOVWF 77 |
|
|
92 |
0045: CLRF 04 |
|
|
93 |
0046: DECFSZ 04,F |
|
|
94 |
0047: GOTO 046 |
|
|
95 |
0048: DECFSZ 77,F |
|
|
96 |
0049: GOTO 045 |
|
|
97 |
004A: MOVLW F0 |
|
|
98 |
004B: MOVWF 04 |
|
|
99 |
004C: DECFSZ 04,F |
|
|
100 |
004D: GOTO 04C |
|
|
101 |
004E: NOP |
|
|
102 |
004F: NOP |
|
|
103 |
0050: BTFSC 78.7 |
|
|
104 |
0051: GOTO 034 |
|
|
105 |
0052: BTFSC 78.6 |
|
|
106 |
0053: GOTO 03C |
|
|
107 |
0054: BCF 0A.3 |
|
|
108 |
0055: BCF 0A.4 |
|
|
109 |
0056: GOTO 102 (RETURN) |
223 |
kapl |
110 |
.................... |
|
|
111 |
.................... |
|
|
112 |
.................... |
|
|
113 |
.................... #define LCD_RS PIN_B1 // rizeni registru LCD displeje |
|
|
114 |
.................... #define LCD_E PIN_B0 // enable LCD displeje |
|
|
115 |
.................... #define LCD_DATA_LSB PIN_C0 // pripojeni LSB bitu datoveho portu LCD displeje (celkem 4 bity vzestupne za sebou) |
|
|
116 |
.................... |
240 |
kaklik |
117 |
.................... |
238 |
kaklik |
118 |
.................... #bit SPEN=0x18.7 |
|
|
119 |
.................... #bit RCIF=0x0C.5 |
|
|
120 |
.................... |
240 |
kaklik |
121 |
.................... #include <stdio.h> |
|
|
122 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
123 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
124 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
125 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
126 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
127 |
.................... //// or distribution is permitted without written permission. //// |
|
|
128 |
.................... //// Derivative programs created using this software in object code //// |
|
|
129 |
.................... //// form are not restricted in any way. //// |
|
|
130 |
.................... /////////////////////////////////////////////////////////////////////////// |
223 |
kapl |
131 |
.................... |
240 |
kaklik |
132 |
.................... #ifndef _STDIO |
|
|
133 |
.................... #define _STDIO |
|
|
134 |
.................... #include <string.h> |
|
|
135 |
.................... //////////////////////////////////////////////////////////////////////////// |
|
|
136 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
137 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
138 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
139 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
140 |
.................... //// or distribution is permitted without written permission. //// |
|
|
141 |
.................... //// Derivative programs created using this software in object code //// |
|
|
142 |
.................... //// form are not restricted in any way. //// |
|
|
143 |
.................... //////////////////////////////////////////////////////////////////////////// |
223 |
kapl |
144 |
.................... |
240 |
kaklik |
145 |
.................... #ifndef _STRING |
|
|
146 |
.................... #define _STRING |
|
|
147 |
.................... #include <stddef.h> |
|
|
148 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
149 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
150 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
151 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
152 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
153 |
.................... //// or distribution is permitted without written permission. //// |
|
|
154 |
.................... //// Derivative programs created using this software in object code //// |
|
|
155 |
.................... //// form are not restricted in any way. //// |
|
|
156 |
.................... /////////////////////////////////////////////////////////////////////////// |
223 |
kapl |
157 |
.................... |
240 |
kaklik |
158 |
.................... #ifndef _STDDEF |
223 |
kapl |
159 |
.................... |
240 |
kaklik |
160 |
.................... #define _STDDEF |
223 |
kapl |
161 |
.................... |
240 |
kaklik |
162 |
.................... #if sizeof(int *)==1 |
|
|
163 |
.................... #define ptrdiff_t int |
|
|
164 |
.................... #else |
|
|
165 |
.................... #define ptrdiff_t long |
|
|
166 |
.................... #endif |
223 |
kapl |
167 |
.................... |
240 |
kaklik |
168 |
.................... #define size_t int |
|
|
169 |
.................... #define wchar_t char |
|
|
170 |
.................... #define NULL 0 |
223 |
kapl |
171 |
.................... |
240 |
kaklik |
172 |
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) |
223 |
kapl |
173 |
.................... |
240 |
kaklik |
174 |
.................... #endif |
223 |
kapl |
175 |
.................... |
240 |
kaklik |
176 |
.................... #include <ctype.h> |
|
|
177 |
.................... //////////////////////////////////////////////////////////////////////////// |
|
|
178 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
179 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
180 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
181 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
182 |
.................... //// or distribution is permitted without written permission. //// |
|
|
183 |
.................... //// Derivative programs created using this software in object code //// |
|
|
184 |
.................... //// form are not restricted in any way. //// |
|
|
185 |
.................... //////////////////////////////////////////////////////////////////////////// |
223 |
kapl |
186 |
.................... |
240 |
kaklik |
187 |
.................... #ifndef _CTYPE |
|
|
188 |
.................... #define _CTYPE |
223 |
kapl |
189 |
.................... |
240 |
kaklik |
190 |
.................... #define islower(x) isamong(x,"abcdefghijklmnopqrstuvwxyz") |
|
|
191 |
.................... #define isupper(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZ") |
|
|
192 |
.................... #define isalnum(x) isamong(x,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") |
|
|
193 |
.................... #define isalpha(x) isamong(x,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz") |
|
|
194 |
.................... #define isdigit(x) isamong(x,"0123456789") |
|
|
195 |
.................... #define isspace(x) (x==' ') |
|
|
196 |
.................... #define isxdigit(x) isamong(x,"0123456789ABCDEFabcdef") |
|
|
197 |
.................... #define iscntrl(x) (x<' ') |
|
|
198 |
.................... #define isprint(x) (x>=' ') |
|
|
199 |
.................... #define isgraph(x) (x>' ') |
|
|
200 |
.................... #define ispunct(x) ((x>' ')&&!isalnum(x)) |
223 |
kapl |
201 |
.................... |
240 |
kaklik |
202 |
.................... #endif |
|
|
203 |
.................... |
|
|
204 |
.................... |
|
|
205 |
.................... |
|
|
206 |
.................... |
|
|
207 |
.................... |
|
|
208 |
.................... ////////////////////////////////////////////// |
|
|
209 |
.................... //// Uncomment the following define to //// |
|
|
210 |
.................... //// allow some functions to use a //// |
|
|
211 |
.................... //// quicker algorithm, but use more ROM //// |
|
|
212 |
.................... //// //// |
|
|
213 |
.................... //// #define FASTER_BUT_MORE_ROM //// |
|
|
214 |
.................... ////////////////////////////////////////////// |
|
|
215 |
.................... |
|
|
216 |
.................... |
|
|
217 |
.................... |
|
|
218 |
.................... /*Copying functions*/ |
|
|
219 |
.................... /* standard template: |
|
|
220 |
.................... void *memmove(void *s1, void *s2, size_t n). |
|
|
221 |
.................... Copies max of n characters safely (not following ending '\0') |
|
|
222 |
.................... from s2 in s1; if s2 has less than n characters, appends 0 */ |
|
|
223 |
.................... |
|
|
224 |
.................... char *memmove(void *s1,char *s2,size_t n) |
223 |
kapl |
225 |
.................... { |
240 |
kaklik |
226 |
.................... char *sc1; |
|
|
227 |
.................... char *sc2; |
|
|
228 |
.................... sc1=s1; |
|
|
229 |
.................... sc2=s2; |
|
|
230 |
.................... if(sc2<sc1 && sc1 <sc2 +n) |
|
|
231 |
.................... for(sc1+=n,sc2+=n;0<n;--n) |
|
|
232 |
.................... *--sc1=*--sc2; |
|
|
233 |
.................... else |
|
|
234 |
.................... for(;0<n;--n) |
|
|
235 |
.................... *sc1++=*sc2++; |
|
|
236 |
.................... return s1; |
|
|
237 |
.................... } |
223 |
kapl |
238 |
.................... |
240 |
kaklik |
239 |
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? |
|
|
240 |
.................... Standard template: char *strcpy(char *s1, const char *s2) |
|
|
241 |
.................... copies the string s2 including the null character to s1*/ |
223 |
kapl |
242 |
.................... |
240 |
kaklik |
243 |
.................... char *strcopy(char *s1, char *s2) |
223 |
kapl |
244 |
.................... { |
240 |
kaklik |
245 |
.................... char *s; |
|
|
246 |
.................... |
|
|
247 |
.................... for (s = s1; *s2 != 0; s++, s2++) { |
|
|
248 |
.................... *s = *s2; |
|
|
249 |
.................... } |
|
|
250 |
.................... *s = *s2; |
|
|
251 |
.................... return(s1); |
223 |
kapl |
252 |
.................... } |
|
|
253 |
.................... |
240 |
kaklik |
254 |
.................... /* standard template: |
|
|
255 |
.................... char *strncpy(char *s1, const char *s2, size_t n). |
|
|
256 |
.................... Copies max of n characters (not following ending '\0') |
|
|
257 |
.................... from s2 in s1; if s2 has less than n characters, appends 0 */ |
223 |
kapl |
258 |
.................... |
240 |
kaklik |
259 |
.................... char *strncpy(char *s1, char *s2, size_t n) |
223 |
kapl |
260 |
.................... { |
240 |
kaklik |
261 |
.................... char *s; |
|
|
262 |
.................... |
|
|
263 |
.................... for (s = s1; n > 0 && *s2 != '\0'; n--) |
|
|
264 |
.................... *s++ = *s2++; |
|
|
265 |
.................... for (; n > 0; n--) |
|
|
266 |
.................... *s++ = '\0'; |
|
|
267 |
.................... |
|
|
268 |
.................... return(s1); |
|
|
269 |
.................... } |
|
|
270 |
.................... /***********************************************************/ |
|
|
271 |
.................... |
|
|
272 |
.................... /*concatenation functions*/ |
|
|
273 |
.................... /* standard template: char *strcat(char *s1, const char *s2) |
|
|
274 |
.................... appends s2 to s1*/ |
|
|
275 |
.................... |
|
|
276 |
.................... char *strcat(char *s1, char *s2) |
|
|
277 |
.................... { |
|
|
278 |
.................... char *s; |
|
|
279 |
.................... |
|
|
280 |
.................... for (s = s1; *s != '\0'; ++s); |
|
|
281 |
.................... while(*s2 != '\0') |
|
|
282 |
.................... { |
|
|
283 |
.................... *s = *s2; |
|
|
284 |
.................... ++s; |
|
|
285 |
.................... ++s2; |
|
|
286 |
.................... } |
|
|
287 |
.................... |
|
|
288 |
.................... *s = '\0'; |
|
|
289 |
.................... return(s1); |
|
|
290 |
.................... } |
|
|
291 |
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) |
|
|
292 |
.................... appends not more than n characters from s2 to s1*/ |
|
|
293 |
.................... |
|
|
294 |
.................... char *strncat(char *s1, char *s2, size_t n) |
|
|
295 |
.................... { |
|
|
296 |
.................... char *s; |
|
|
297 |
.................... |
|
|
298 |
.................... for (s = s1; *s != '\0'; ++s); |
|
|
299 |
.................... while(*s2 != '\0' && 0<n) |
|
|
300 |
.................... { |
|
|
301 |
.................... *s = *s2; |
|
|
302 |
.................... ++s; |
|
|
303 |
.................... ++s2; |
|
|
304 |
.................... --n; |
|
|
305 |
.................... } |
|
|
306 |
.................... |
|
|
307 |
.................... *s = '\0'; |
|
|
308 |
.................... return(s1); |
|
|
309 |
.................... } |
|
|
310 |
.................... |
|
|
311 |
.................... /***********************************************************/ |
|
|
312 |
.................... |
|
|
313 |
.................... |
|
|
314 |
.................... /*comparison functions*/ |
|
|
315 |
.................... /* standard template: signed int memcmp(void *s1, void *s2). |
|
|
316 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
|
|
317 |
.................... |
|
|
318 |
.................... signed int memcmp(void * s1,char *s2,size_t n) |
|
|
319 |
.................... { |
|
|
320 |
.................... char *su1, *su2; |
|
|
321 |
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) |
|
|
322 |
.................... { |
|
|
323 |
.................... if(*su1!=*su2) |
|
|
324 |
.................... return ((*su1<*su2)?-1:+1); |
|
|
325 |
.................... } |
|
|
326 |
.................... return 0; |
|
|
327 |
.................... } |
|
|
328 |
.................... |
|
|
329 |
.................... /* standard template: int strcmp(const char *s1, const char *s2). |
|
|
330 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
|
|
331 |
.................... |
|
|
332 |
.................... signed int strcmp(char *s1, char *s2) |
|
|
333 |
.................... { |
|
|
334 |
.................... for (; *s1 == *s2; s1++, s2++) |
|
|
335 |
.................... if (*s1 == '\0') |
|
|
336 |
.................... return(0); |
|
|
337 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
338 |
.................... } |
|
|
339 |
.................... /* standard template: int strcoll(const char *s1, const char *s2). |
|
|
340 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
|
|
341 |
.................... |
|
|
342 |
.................... signed int strcoll(char *s1, char *s2) |
|
|
343 |
.................... { |
|
|
344 |
.................... for (; *s1 == *s2; s1++, s2++) |
|
|
345 |
.................... if (*s1 == '\0') |
|
|
346 |
.................... return(0); |
|
|
347 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
348 |
.................... } |
|
|
349 |
.................... |
|
|
350 |
.................... /* standard template: |
|
|
351 |
.................... int strncmp(const char *s1, const char *s2, size_t n). |
|
|
352 |
.................... Compares max of n characters (not following 0) from s1 to s2; |
|
|
353 |
.................... returns same as strcmp */ |
|
|
354 |
.................... |
|
|
355 |
.................... signed int strncmp(char *s1, char *s2, size_t n) |
|
|
356 |
.................... { |
|
|
357 |
.................... for (; n > 0; s1++, s2++, n--) |
|
|
358 |
.................... if (*s1 != *s2) |
|
|
359 |
.................... return((*s1 <*s2) ? -1: 1); |
|
|
360 |
.................... else if (*s1 == '\0') |
|
|
361 |
.................... return(0); |
|
|
362 |
.................... return(0); |
|
|
363 |
.................... } |
|
|
364 |
.................... /* standard template: |
|
|
365 |
.................... int strxfrm(const char *s1, const char *s2, size_t n). |
|
|
366 |
.................... transforms maximum of n characters from s2 and places them into s1*/ |
|
|
367 |
.................... size_t strxfrm(char *s1, char *s2, size_t n) |
|
|
368 |
.................... { |
|
|
369 |
.................... char *s; |
|
|
370 |
.................... int n1; |
|
|
371 |
.................... n1=n; |
|
|
372 |
.................... for (s = s1; n > 0 && *s2 != '\0'; n--) |
|
|
373 |
.................... *s++ = *s2++; |
|
|
374 |
.................... for (; n > 0; n--) |
|
|
375 |
.................... *s++ = '\0'; |
|
|
376 |
.................... |
|
|
377 |
.................... return(n1); |
|
|
378 |
.................... } |
|
|
379 |
.................... |
|
|
380 |
.................... |
|
|
381 |
.................... |
|
|
382 |
.................... |
|
|
383 |
.................... |
|
|
384 |
.................... /***********************************************************/ |
|
|
385 |
.................... /*Search functions*/ |
|
|
386 |
.................... /* standard template: void *memchr(const char *s, int c). |
|
|
387 |
.................... Finds first occurrence of c in n characters of s */ |
|
|
388 |
.................... |
|
|
389 |
.................... char *memchr(void *s,int c,size_t n) |
|
|
390 |
.................... { |
|
|
391 |
.................... char uc; |
|
|
392 |
.................... char *su; |
|
|
393 |
.................... uc=c; |
|
|
394 |
.................... for(su=s;0<n;++su,--n) |
|
|
395 |
.................... if(*su==uc) |
|
|
396 |
.................... return su; |
|
|
397 |
.................... return NULL; |
|
|
398 |
.................... } |
|
|
399 |
.................... |
|
|
400 |
.................... /* standard template: char *strchr(const char *s, int c). |
|
|
401 |
.................... Finds first occurrence of c in s */ |
|
|
402 |
.................... |
|
|
403 |
.................... char *strchr(char *s, int c) |
|
|
404 |
.................... { |
|
|
405 |
.................... for (; *s != c; s++) |
|
|
406 |
.................... if (*s == '\0') |
|
|
407 |
.................... return(0); |
|
|
408 |
.................... return(s); |
|
|
409 |
.................... } |
|
|
410 |
.................... /* standard template: |
|
|
411 |
.................... size_t strcspn(const char *s1, const char *s2). |
|
|
412 |
.................... Computes length of max initial segment of s1 that |
|
|
413 |
.................... consists entirely of characters NOT from s2*/ |
|
|
414 |
.................... |
|
|
415 |
.................... int *strcspn(char *s1, char *s2) |
|
|
416 |
.................... { |
|
|
417 |
.................... char *sc1, *sc2; |
|
|
418 |
.................... |
|
|
419 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
420 |
.................... for (sc2 = s2; *sc2 != 0; sc2++) |
|
|
421 |
.................... if (*sc1 == *sc2) |
|
|
422 |
.................... return(sc1 - s1); |
|
|
423 |
.................... return(sc1 - s1); |
|
|
424 |
.................... } |
|
|
425 |
.................... /* standard template: |
|
|
426 |
.................... char *strpbrk(const char *s1, const char *s2). |
|
|
427 |
.................... Locates first occurence of any character from s2 in s1; |
|
|
428 |
.................... returns s1 if s2 is empty string */ |
|
|
429 |
.................... |
|
|
430 |
.................... char *strpbrk(char *s1, char *s2) |
|
|
431 |
.................... { |
|
|
432 |
.................... char *sc1, *sc2; |
|
|
433 |
.................... |
|
|
434 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
435 |
.................... for (sc2 = s2; *sc2 != 0; sc2++) |
|
|
436 |
.................... if (*sc1 == *sc2) |
|
|
437 |
.................... return(sc1); |
|
|
438 |
.................... return(0); |
|
|
439 |
.................... } |
|
|
440 |
.................... |
|
|
441 |
.................... |
|
|
442 |
.................... /* standard template: char *strrchr(const char *s, int c). |
|
|
443 |
.................... Finds last occurrence of c in s */ |
|
|
444 |
.................... |
|
|
445 |
.................... char *strrchr(char *s, int c) |
|
|
446 |
.................... { |
|
|
447 |
.................... char *p; |
|
|
448 |
.................... |
|
|
449 |
.................... for (p = 0; ; s++) |
|
|
450 |
.................... { |
|
|
451 |
.................... if (*s == c) |
|
|
452 |
.................... p = s; |
|
|
453 |
.................... if (*s == '\0') |
|
|
454 |
.................... return(p); |
|
|
455 |
.................... } |
|
|
456 |
.................... } |
|
|
457 |
.................... /* computes length of max initial segment of s1 consisting |
|
|
458 |
.................... entirely of characters from s2 */ |
|
|
459 |
.................... |
|
|
460 |
.................... int *strspn(char *s1, char *s2) |
|
|
461 |
.................... { |
|
|
462 |
.................... char *sc1, *sc2; |
|
|
463 |
.................... |
|
|
464 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
465 |
.................... for (sc2 = s2; ; sc2++) |
|
|
466 |
.................... if (*sc2 == '\0') |
|
|
467 |
.................... return(sc1 - s1); |
|
|
468 |
.................... else if (*sc1 == *sc2) |
|
|
469 |
.................... break; |
|
|
470 |
.................... return(sc1 - s1); |
|
|
471 |
.................... } |
|
|
472 |
.................... /* standard template: |
|
|
473 |
.................... char *strstr(const char *s1, const char *s2); |
|
|
474 |
.................... Locates first occurence of character sequence s2 in s1; |
|
|
475 |
.................... returns 0 if s2 is empty string |
|
|
476 |
.................... |
|
|
477 |
.................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the |
|
|
478 |
.................... file to use the faster algorithm */ |
|
|
479 |
.................... char *strstr(char *s1, char *s2) |
|
|
480 |
.................... { |
|
|
481 |
.................... char *s, *t; |
|
|
482 |
.................... |
|
|
483 |
.................... #ifdef FASTER_BUT_MORE_ROM |
|
|
484 |
.................... if (*s2 == '\0') |
|
|
485 |
.................... return(s1); |
|
|
486 |
.................... #endif |
|
|
487 |
.................... |
|
|
488 |
.................... while (*s1) |
|
|
489 |
.................... { |
|
|
490 |
.................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t); |
|
|
491 |
.................... |
|
|
492 |
.................... if (*t == '\0') |
|
|
493 |
.................... return s1; |
|
|
494 |
.................... ++s1; |
|
|
495 |
.................... #ifdef FASTER_BUT_MORE_ROM |
|
|
496 |
.................... while(*s1 != '\0' && *s1 != *s2) |
|
|
497 |
.................... ++s1; |
|
|
498 |
.................... #endif |
|
|
499 |
.................... } |
|
|
500 |
.................... return 0; |
|
|
501 |
.................... } |
|
|
502 |
.................... |
|
|
503 |
.................... /* standard template: char *strtok(char *s1, const char *s2). |
|
|
504 |
.................... |
|
|
505 |
.................... Finds next token in s1 delimited by a character from separator |
|
|
506 |
.................... string s2 (which can be different from call to call). First call |
|
|
507 |
.................... starts at beginning of s1 searching for first character NOT |
|
|
508 |
.................... contained in s2; returns 0 if none is found. |
|
|
509 |
.................... If one is found, it is the start of first token (return value). |
|
|
510 |
.................... Function then searches from there for a character contained in s2. |
|
|
511 |
.................... If none is found, current token extends to end of s1, and subsequent |
|
|
512 |
.................... searches for a token will return 0. If one is found, it is |
|
|
513 |
.................... overwritten by '\0', which terminates current token. Function saves |
|
|
514 |
.................... pointer to following character from which next search will start. |
|
|
515 |
.................... Each subsequent call, with 0 as first argument, starts searching |
|
|
516 |
.................... from saved pointer */ |
|
|
517 |
.................... |
|
|
518 |
.................... char *strtok(char *s1, char *s2) |
|
|
519 |
.................... { |
|
|
520 |
.................... char *beg, *end; |
|
|
521 |
.................... static char *save; |
239 |
kaklik |
522 |
* |
240 |
kaklik |
523 |
006E: CLRF 21 |
|
|
524 |
.................... |
|
|
525 |
.................... beg = (s1)? s1: save; |
|
|
526 |
.................... beg += strspn(beg, s2); |
|
|
527 |
.................... if (*beg == '\0') |
|
|
528 |
.................... { |
|
|
529 |
.................... *save = ' '; |
|
|
530 |
.................... return(0); |
|
|
531 |
.................... } |
|
|
532 |
.................... end = strpbrk(beg, s2); |
|
|
533 |
.................... if (*end != '\0') |
|
|
534 |
.................... { |
|
|
535 |
.................... *end = '\0'; |
|
|
536 |
.................... end++; |
|
|
537 |
.................... } |
|
|
538 |
.................... save = end; |
|
|
539 |
.................... return(beg); |
223 |
kapl |
540 |
.................... } |
|
|
541 |
.................... |
240 |
kaklik |
542 |
.................... /*****************************************************************/ |
|
|
543 |
.................... /*Miscellaneous functions*/ |
|
|
544 |
.................... /* standard template |
|
|
545 |
.................... maps error number in errnum to an error message string |
|
|
546 |
.................... Returns: Pointer to string |
|
|
547 |
.................... */ |
|
|
548 |
.................... #ifdef _ERRNO |
|
|
549 |
.................... char * strerror(int errnum) |
|
|
550 |
.................... { |
|
|
551 |
.................... char s[15]; |
|
|
552 |
.................... switch( errnum) |
|
|
553 |
.................... { |
|
|
554 |
.................... case 0: |
|
|
555 |
.................... strcpy(s,"no errors"); |
|
|
556 |
.................... return s; |
|
|
557 |
.................... case EDOM : |
|
|
558 |
.................... strcpy(s,"domain error"); |
|
|
559 |
.................... return s; |
|
|
560 |
.................... case ERANGE: |
|
|
561 |
.................... strcpy(s,"range error"); |
|
|
562 |
.................... return s; |
|
|
563 |
.................... } |
|
|
564 |
.................... } |
|
|
565 |
.................... #ENDIF |
|
|
566 |
.................... /* standard template: size_t strlen(const char *s). |
|
|
567 |
.................... Computes length of s1 (preceding terminating 0) */ |
223 |
kapl |
568 |
.................... |
240 |
kaklik |
569 |
.................... int *strlen(char *s) |
223 |
kapl |
570 |
.................... { |
240 |
kaklik |
571 |
.................... char *sc; |
223 |
kapl |
572 |
.................... |
240 |
kaklik |
573 |
.................... for (sc = s; *sc != 0; sc++); |
|
|
574 |
.................... return(sc - s); |
|
|
575 |
.................... } |
223 |
kapl |
576 |
.................... |
240 |
kaklik |
577 |
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). |
|
|
578 |
.................... Compares s1 to s2 ignoring case (upper vs. lower) */ |
223 |
kapl |
579 |
.................... |
240 |
kaklik |
580 |
.................... signed int stricmp(char *s1, char *s2) |
|
|
581 |
.................... { |
|
|
582 |
.................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); |
|
|
583 |
.................... s1++, s2++) |
|
|
584 |
.................... if (*s1 == '\0') |
|
|
585 |
.................... return(0); |
|
|
586 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
587 |
.................... } |
223 |
kapl |
588 |
.................... |
|
|
589 |
.................... |
240 |
kaklik |
590 |
.................... /* standard template: char *strlwr(char *s). |
|
|
591 |
.................... Replaces uppercase letters by lowercase; |
|
|
592 |
.................... returns pointer to new string s */ |
|
|
593 |
.................... |
|
|
594 |
.................... char *strlwr(char *s) |
|
|
595 |
.................... { |
|
|
596 |
.................... char *p; |
|
|
597 |
.................... |
|
|
598 |
.................... for (p = s; *p != '\0'; p++) |
|
|
599 |
.................... if (*p >= 'A' && *p <='Z') |
|
|
600 |
.................... *p += 'a' - 'A'; |
|
|
601 |
.................... return(s); |
|
|
602 |
.................... } |
|
|
603 |
.................... |
|
|
604 |
.................... |
|
|
605 |
.................... /************************************************************/ |
|
|
606 |
.................... |
|
|
607 |
.................... |
|
|
608 |
.................... #endif |
|
|
609 |
.................... |
|
|
610 |
.................... #ifndef getc |
|
|
611 |
.................... #define getc getch |
|
|
612 |
.................... #define getchar getch |
|
|
613 |
.................... #define puts(s) {printf(s); putchar(13); putchar(10);} |
|
|
614 |
.................... #define putc putchar |
|
|
615 |
.................... #endif |
|
|
616 |
.................... /* maps error number to an error message. Writes a sequence of characters to |
|
|
617 |
.................... stderr stream thus: if s is not null then string pointed to by s follwed by |
|
|
618 |
.................... a colon (:) and a space and the appropriate error message returned by strerror |
|
|
619 |
.................... function with argument errno |
|
|
620 |
.................... |
|
|
621 |
.................... Returns: no value |
|
|
622 |
.................... */ |
|
|
623 |
.................... |
|
|
624 |
.................... #ifdef _ERRNO |
|
|
625 |
.................... void perror(char *s) |
|
|
626 |
.................... { |
|
|
627 |
.................... if(s) |
|
|
628 |
.................... fprintf(STDERR,"%s: ",s); |
|
|
629 |
.................... fprintf(STDERR,"%s\r\n",strerror(errno)); |
|
|
630 |
.................... } |
|
|
631 |
.................... #endif |
|
|
632 |
.................... #endif |
|
|
633 |
.................... |
|
|
634 |
.................... #include <string.h> |
|
|
635 |
.................... //////////////////////////////////////////////////////////////////////////// |
|
|
636 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
637 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
638 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
639 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
640 |
.................... //// or distribution is permitted without written permission. //// |
|
|
641 |
.................... //// Derivative programs created using this software in object code //// |
|
|
642 |
.................... //// form are not restricted in any way. //// |
|
|
643 |
.................... //////////////////////////////////////////////////////////////////////////// |
|
|
644 |
.................... |
|
|
645 |
.................... #ifndef _STRING |
|
|
646 |
.................... #define _STRING |
|
|
647 |
.................... #include <stddef.h> |
|
|
648 |
.................... #include <ctype.h> |
|
|
649 |
.................... |
|
|
650 |
.................... |
|
|
651 |
.................... |
|
|
652 |
.................... ////////////////////////////////////////////// |
|
|
653 |
.................... //// Uncomment the following define to //// |
|
|
654 |
.................... //// allow some functions to use a //// |
|
|
655 |
.................... //// quicker algorithm, but use more ROM //// |
|
|
656 |
.................... //// //// |
|
|
657 |
.................... //// #define FASTER_BUT_MORE_ROM //// |
|
|
658 |
.................... ////////////////////////////////////////////// |
|
|
659 |
.................... |
|
|
660 |
.................... |
|
|
661 |
.................... |
|
|
662 |
.................... /*Copying functions*/ |
|
|
663 |
.................... /* standard template: |
|
|
664 |
.................... void *memmove(void *s1, void *s2, size_t n). |
|
|
665 |
.................... Copies max of n characters safely (not following ending '\0') |
|
|
666 |
.................... from s2 in s1; if s2 has less than n characters, appends 0 */ |
|
|
667 |
.................... |
|
|
668 |
.................... char *memmove(void *s1,char *s2,size_t n) |
|
|
669 |
.................... { |
|
|
670 |
.................... char *sc1; |
|
|
671 |
.................... char *sc2; |
|
|
672 |
.................... sc1=s1; |
|
|
673 |
.................... sc2=s2; |
|
|
674 |
.................... if(sc2<sc1 && sc1 <sc2 +n) |
|
|
675 |
.................... for(sc1+=n,sc2+=n;0<n;--n) |
|
|
676 |
.................... *--sc1=*--sc2; |
|
|
677 |
.................... else |
|
|
678 |
.................... for(;0<n;--n) |
|
|
679 |
.................... *sc1++=*sc2++; |
|
|
680 |
.................... return s1; |
|
|
681 |
.................... } |
|
|
682 |
.................... |
|
|
683 |
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? |
|
|
684 |
.................... Standard template: char *strcpy(char *s1, const char *s2) |
|
|
685 |
.................... copies the string s2 including the null character to s1*/ |
|
|
686 |
.................... |
|
|
687 |
.................... char *strcopy(char *s1, char *s2) |
|
|
688 |
.................... { |
|
|
689 |
.................... char *s; |
|
|
690 |
.................... |
|
|
691 |
.................... for (s = s1; *s2 != 0; s++, s2++) { |
|
|
692 |
.................... *s = *s2; |
|
|
693 |
.................... } |
|
|
694 |
.................... *s = *s2; |
|
|
695 |
.................... return(s1); |
|
|
696 |
.................... } |
|
|
697 |
.................... |
|
|
698 |
.................... /* standard template: |
|
|
699 |
.................... char *strncpy(char *s1, const char *s2, size_t n). |
|
|
700 |
.................... Copies max of n characters (not following ending '\0') |
|
|
701 |
.................... from s2 in s1; if s2 has less than n characters, appends 0 */ |
|
|
702 |
.................... |
|
|
703 |
.................... char *strncpy(char *s1, char *s2, size_t n) |
|
|
704 |
.................... { |
|
|
705 |
.................... char *s; |
|
|
706 |
.................... |
|
|
707 |
.................... for (s = s1; n > 0 && *s2 != '\0'; n--) |
|
|
708 |
.................... *s++ = *s2++; |
|
|
709 |
.................... for (; n > 0; n--) |
|
|
710 |
.................... *s++ = '\0'; |
|
|
711 |
.................... |
|
|
712 |
.................... return(s1); |
|
|
713 |
.................... } |
|
|
714 |
.................... /***********************************************************/ |
|
|
715 |
.................... |
|
|
716 |
.................... /*concatenation functions*/ |
|
|
717 |
.................... /* standard template: char *strcat(char *s1, const char *s2) |
|
|
718 |
.................... appends s2 to s1*/ |
|
|
719 |
.................... |
|
|
720 |
.................... char *strcat(char *s1, char *s2) |
|
|
721 |
.................... { |
|
|
722 |
.................... char *s; |
|
|
723 |
.................... |
|
|
724 |
.................... for (s = s1; *s != '\0'; ++s); |
|
|
725 |
.................... while(*s2 != '\0') |
223 |
kapl |
726 |
.................... { |
240 |
kaklik |
727 |
.................... *s = *s2; |
|
|
728 |
.................... ++s; |
|
|
729 |
.................... ++s2; |
223 |
kapl |
730 |
.................... } |
|
|
731 |
.................... |
240 |
kaklik |
732 |
.................... *s = '\0'; |
|
|
733 |
.................... return(s1); |
|
|
734 |
.................... } |
|
|
735 |
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) |
|
|
736 |
.................... appends not more than n characters from s2 to s1*/ |
223 |
kapl |
737 |
.................... |
240 |
kaklik |
738 |
.................... char *strncat(char *s1, char *s2, size_t n) |
|
|
739 |
.................... { |
|
|
740 |
.................... char *s; |
|
|
741 |
.................... |
|
|
742 |
.................... for (s = s1; *s != '\0'; ++s); |
|
|
743 |
.................... while(*s2 != '\0' && 0<n) |
223 |
kapl |
744 |
.................... { |
240 |
kaklik |
745 |
.................... *s = *s2; |
|
|
746 |
.................... ++s; |
|
|
747 |
.................... ++s2; |
|
|
748 |
.................... --n; |
223 |
kapl |
749 |
.................... } |
240 |
kaklik |
750 |
.................... |
|
|
751 |
.................... *s = '\0'; |
|
|
752 |
.................... return(s1); |
223 |
kapl |
753 |
.................... } |
|
|
754 |
.................... |
240 |
kaklik |
755 |
.................... /***********************************************************/ |
223 |
kapl |
756 |
.................... |
240 |
kaklik |
757 |
.................... |
|
|
758 |
.................... /*comparison functions*/ |
|
|
759 |
.................... /* standard template: signed int memcmp(void *s1, void *s2). |
|
|
760 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
|
|
761 |
.................... |
|
|
762 |
.................... signed int memcmp(void * s1,char *s2,size_t n) |
223 |
kapl |
763 |
.................... { |
240 |
kaklik |
764 |
.................... char *su1, *su2; |
|
|
765 |
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) |
|
|
766 |
.................... { |
|
|
767 |
.................... if(*su1!=*su2) |
|
|
768 |
.................... return ((*su1<*su2)?-1:+1); |
|
|
769 |
.................... } |
|
|
770 |
.................... return 0; |
|
|
771 |
.................... } |
223 |
kapl |
772 |
.................... |
240 |
kaklik |
773 |
.................... /* standard template: int strcmp(const char *s1, const char *s2). |
|
|
774 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
223 |
kapl |
775 |
.................... |
240 |
kaklik |
776 |
.................... signed int strcmp(char *s1, char *s2) |
|
|
777 |
.................... { |
|
|
778 |
.................... for (; *s1 == *s2; s1++, s2++) |
|
|
779 |
.................... if (*s1 == '\0') |
|
|
780 |
.................... return(0); |
|
|
781 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
782 |
.................... } |
|
|
783 |
.................... /* standard template: int strcoll(const char *s1, const char *s2). |
|
|
784 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
|
|
785 |
.................... |
|
|
786 |
.................... signed int strcoll(char *s1, char *s2) |
|
|
787 |
.................... { |
|
|
788 |
.................... for (; *s1 == *s2; s1++, s2++) |
|
|
789 |
.................... if (*s1 == '\0') |
|
|
790 |
.................... return(0); |
|
|
791 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
792 |
.................... } |
|
|
793 |
.................... |
|
|
794 |
.................... /* standard template: |
|
|
795 |
.................... int strncmp(const char *s1, const char *s2, size_t n). |
|
|
796 |
.................... Compares max of n characters (not following 0) from s1 to s2; |
|
|
797 |
.................... returns same as strcmp */ |
|
|
798 |
.................... |
|
|
799 |
.................... signed int strncmp(char *s1, char *s2, size_t n) |
|
|
800 |
.................... { |
|
|
801 |
.................... for (; n > 0; s1++, s2++, n--) |
|
|
802 |
.................... if (*s1 != *s2) |
|
|
803 |
.................... return((*s1 <*s2) ? -1: 1); |
|
|
804 |
.................... else if (*s1 == '\0') |
|
|
805 |
.................... return(0); |
|
|
806 |
.................... return(0); |
|
|
807 |
.................... } |
|
|
808 |
.................... /* standard template: |
|
|
809 |
.................... int strxfrm(const char *s1, const char *s2, size_t n). |
|
|
810 |
.................... transforms maximum of n characters from s2 and places them into s1*/ |
|
|
811 |
.................... size_t strxfrm(char *s1, char *s2, size_t n) |
|
|
812 |
.................... { |
|
|
813 |
.................... char *s; |
|
|
814 |
.................... int n1; |
|
|
815 |
.................... n1=n; |
|
|
816 |
.................... for (s = s1; n > 0 && *s2 != '\0'; n--) |
|
|
817 |
.................... *s++ = *s2++; |
|
|
818 |
.................... for (; n > 0; n--) |
|
|
819 |
.................... *s++ = '\0'; |
|
|
820 |
.................... |
|
|
821 |
.................... return(n1); |
|
|
822 |
.................... } |
|
|
823 |
.................... |
|
|
824 |
.................... |
|
|
825 |
.................... |
|
|
826 |
.................... |
|
|
827 |
.................... |
|
|
828 |
.................... /***********************************************************/ |
|
|
829 |
.................... /*Search functions*/ |
|
|
830 |
.................... /* standard template: void *memchr(const char *s, int c). |
|
|
831 |
.................... Finds first occurrence of c in n characters of s */ |
|
|
832 |
.................... |
|
|
833 |
.................... char *memchr(void *s,int c,size_t n) |
|
|
834 |
.................... { |
|
|
835 |
.................... char uc; |
|
|
836 |
.................... char *su; |
|
|
837 |
.................... uc=c; |
|
|
838 |
.................... for(su=s;0<n;++su,--n) |
|
|
839 |
.................... if(*su==uc) |
|
|
840 |
.................... return su; |
|
|
841 |
.................... return NULL; |
|
|
842 |
.................... } |
|
|
843 |
.................... |
|
|
844 |
.................... /* standard template: char *strchr(const char *s, int c). |
|
|
845 |
.................... Finds first occurrence of c in s */ |
|
|
846 |
.................... |
|
|
847 |
.................... char *strchr(char *s, int c) |
|
|
848 |
.................... { |
|
|
849 |
.................... for (; *s != c; s++) |
|
|
850 |
.................... if (*s == '\0') |
|
|
851 |
.................... return(0); |
|
|
852 |
.................... return(s); |
|
|
853 |
.................... } |
|
|
854 |
.................... /* standard template: |
|
|
855 |
.................... size_t strcspn(const char *s1, const char *s2). |
|
|
856 |
.................... Computes length of max initial segment of s1 that |
|
|
857 |
.................... consists entirely of characters NOT from s2*/ |
|
|
858 |
.................... |
|
|
859 |
.................... int *strcspn(char *s1, char *s2) |
|
|
860 |
.................... { |
|
|
861 |
.................... char *sc1, *sc2; |
|
|
862 |
.................... |
|
|
863 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
864 |
.................... for (sc2 = s2; *sc2 != 0; sc2++) |
|
|
865 |
.................... if (*sc1 == *sc2) |
|
|
866 |
.................... return(sc1 - s1); |
|
|
867 |
.................... return(sc1 - s1); |
|
|
868 |
.................... } |
|
|
869 |
.................... /* standard template: |
|
|
870 |
.................... char *strpbrk(const char *s1, const char *s2). |
|
|
871 |
.................... Locates first occurence of any character from s2 in s1; |
|
|
872 |
.................... returns s1 if s2 is empty string */ |
|
|
873 |
.................... |
|
|
874 |
.................... char *strpbrk(char *s1, char *s2) |
|
|
875 |
.................... { |
|
|
876 |
.................... char *sc1, *sc2; |
|
|
877 |
.................... |
|
|
878 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
879 |
.................... for (sc2 = s2; *sc2 != 0; sc2++) |
|
|
880 |
.................... if (*sc1 == *sc2) |
|
|
881 |
.................... return(sc1); |
|
|
882 |
.................... return(0); |
|
|
883 |
.................... } |
|
|
884 |
.................... |
|
|
885 |
.................... |
|
|
886 |
.................... /* standard template: char *strrchr(const char *s, int c). |
|
|
887 |
.................... Finds last occurrence of c in s */ |
|
|
888 |
.................... |
|
|
889 |
.................... char *strrchr(char *s, int c) |
|
|
890 |
.................... { |
|
|
891 |
.................... char *p; |
|
|
892 |
.................... |
|
|
893 |
.................... for (p = 0; ; s++) |
223 |
kapl |
894 |
.................... { |
240 |
kaklik |
895 |
.................... if (*s == c) |
|
|
896 |
.................... p = s; |
|
|
897 |
.................... if (*s == '\0') |
|
|
898 |
.................... return(p); |
223 |
kapl |
899 |
.................... } |
240 |
kaklik |
900 |
.................... } |
|
|
901 |
.................... /* computes length of max initial segment of s1 consisting |
|
|
902 |
.................... entirely of characters from s2 */ |
223 |
kapl |
903 |
.................... |
240 |
kaklik |
904 |
.................... int *strspn(char *s1, char *s2) |
|
|
905 |
.................... { |
|
|
906 |
.................... char *sc1, *sc2; |
|
|
907 |
.................... |
|
|
908 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
909 |
.................... for (sc2 = s2; ; sc2++) |
|
|
910 |
.................... if (*sc2 == '\0') |
|
|
911 |
.................... return(sc1 - s1); |
|
|
912 |
.................... else if (*sc1 == *sc2) |
|
|
913 |
.................... break; |
|
|
914 |
.................... return(sc1 - s1); |
223 |
kapl |
915 |
.................... } |
240 |
kaklik |
916 |
.................... /* standard template: |
|
|
917 |
.................... char *strstr(const char *s1, const char *s2); |
|
|
918 |
.................... Locates first occurence of character sequence s2 in s1; |
|
|
919 |
.................... returns 0 if s2 is empty string |
223 |
kapl |
920 |
.................... |
240 |
kaklik |
921 |
.................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the |
|
|
922 |
.................... file to use the faster algorithm */ |
|
|
923 |
.................... char *strstr(char *s1, char *s2) |
|
|
924 |
.................... { |
|
|
925 |
.................... char *s, *t; |
223 |
kapl |
926 |
.................... |
240 |
kaklik |
927 |
.................... #ifdef FASTER_BUT_MORE_ROM |
|
|
928 |
.................... if (*s2 == '\0') |
|
|
929 |
.................... return(s1); |
|
|
930 |
.................... #endif |
|
|
931 |
.................... |
|
|
932 |
.................... while (*s1) |
|
|
933 |
.................... { |
|
|
934 |
.................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t); |
|
|
935 |
.................... |
|
|
936 |
.................... if (*t == '\0') |
|
|
937 |
.................... return s1; |
|
|
938 |
.................... ++s1; |
|
|
939 |
.................... #ifdef FASTER_BUT_MORE_ROM |
|
|
940 |
.................... while(*s1 != '\0' && *s1 != *s2) |
|
|
941 |
.................... ++s1; |
|
|
942 |
.................... #endif |
|
|
943 |
.................... } |
|
|
944 |
.................... return 0; |
|
|
945 |
.................... } |
|
|
946 |
.................... |
|
|
947 |
.................... /* standard template: char *strtok(char *s1, const char *s2). |
|
|
948 |
.................... |
|
|
949 |
.................... Finds next token in s1 delimited by a character from separator |
|
|
950 |
.................... string s2 (which can be different from call to call). First call |
|
|
951 |
.................... starts at beginning of s1 searching for first character NOT |
|
|
952 |
.................... contained in s2; returns 0 if none is found. |
|
|
953 |
.................... If one is found, it is the start of first token (return value). |
|
|
954 |
.................... Function then searches from there for a character contained in s2. |
|
|
955 |
.................... If none is found, current token extends to end of s1, and subsequent |
|
|
956 |
.................... searches for a token will return 0. If one is found, it is |
|
|
957 |
.................... overwritten by '\0', which terminates current token. Function saves |
|
|
958 |
.................... pointer to following character from which next search will start. |
|
|
959 |
.................... Each subsequent call, with 0 as first argument, starts searching |
|
|
960 |
.................... from saved pointer */ |
|
|
961 |
.................... |
|
|
962 |
.................... char *strtok(char *s1, char *s2) |
223 |
kapl |
963 |
.................... { |
240 |
kaklik |
964 |
.................... char *beg, *end; |
|
|
965 |
.................... static char *save; |
223 |
kapl |
966 |
.................... |
240 |
kaklik |
967 |
.................... beg = (s1)? s1: save; |
|
|
968 |
.................... beg += strspn(beg, s2); |
|
|
969 |
.................... if (*beg == '\0') |
223 |
kapl |
970 |
.................... { |
240 |
kaklik |
971 |
.................... *save = ' '; |
|
|
972 |
.................... return(0); |
223 |
kapl |
973 |
.................... } |
240 |
kaklik |
974 |
.................... end = strpbrk(beg, s2); |
|
|
975 |
.................... if (*end != '\0') |
|
|
976 |
.................... { |
|
|
977 |
.................... *end = '\0'; |
|
|
978 |
.................... end++; |
|
|
979 |
.................... } |
|
|
980 |
.................... save = end; |
|
|
981 |
.................... return(beg); |
223 |
kapl |
982 |
.................... } |
|
|
983 |
.................... |
240 |
kaklik |
984 |
.................... /*****************************************************************/ |
|
|
985 |
.................... /*Miscellaneous functions*/ |
|
|
986 |
.................... /* standard template |
|
|
987 |
.................... maps error number in errnum to an error message string |
|
|
988 |
.................... Returns: Pointer to string |
|
|
989 |
.................... */ |
|
|
990 |
.................... #ifdef _ERRNO |
|
|
991 |
.................... char * strerror(int errnum) |
|
|
992 |
.................... { |
|
|
993 |
.................... char s[15]; |
|
|
994 |
.................... switch( errnum) |
|
|
995 |
.................... { |
|
|
996 |
.................... case 0: |
|
|
997 |
.................... strcpy(s,"no errors"); |
|
|
998 |
.................... return s; |
|
|
999 |
.................... case EDOM : |
|
|
1000 |
.................... strcpy(s,"domain error"); |
|
|
1001 |
.................... return s; |
|
|
1002 |
.................... case ERANGE: |
|
|
1003 |
.................... strcpy(s,"range error"); |
|
|
1004 |
.................... return s; |
|
|
1005 |
.................... } |
|
|
1006 |
.................... } |
|
|
1007 |
.................... #ENDIF |
|
|
1008 |
.................... /* standard template: size_t strlen(const char *s). |
|
|
1009 |
.................... Computes length of s1 (preceding terminating 0) */ |
223 |
kapl |
1010 |
.................... |
240 |
kaklik |
1011 |
.................... int *strlen(char *s) |
223 |
kapl |
1012 |
.................... { |
240 |
kaklik |
1013 |
.................... char *sc; |
|
|
1014 |
.................... |
|
|
1015 |
.................... for (sc = s; *sc != 0; sc++); |
|
|
1016 |
.................... return(sc - s); |
223 |
kapl |
1017 |
.................... } |
|
|
1018 |
.................... |
240 |
kaklik |
1019 |
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). |
|
|
1020 |
.................... Compares s1 to s2 ignoring case (upper vs. lower) */ |
223 |
kapl |
1021 |
.................... |
240 |
kaklik |
1022 |
.................... signed int stricmp(char *s1, char *s2) |
223 |
kapl |
1023 |
.................... { |
240 |
kaklik |
1024 |
.................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); |
|
|
1025 |
.................... s1++, s2++) |
|
|
1026 |
.................... if (*s1 == '\0') |
|
|
1027 |
.................... return(0); |
|
|
1028 |
.................... return((*s1 < *s2) ? -1: 1); |
223 |
kapl |
1029 |
.................... } |
|
|
1030 |
.................... |
|
|
1031 |
.................... |
240 |
kaklik |
1032 |
.................... /* standard template: char *strlwr(char *s). |
|
|
1033 |
.................... Replaces uppercase letters by lowercase; |
|
|
1034 |
.................... returns pointer to new string s */ |
223 |
kapl |
1035 |
.................... |
240 |
kaklik |
1036 |
.................... char *strlwr(char *s) |
|
|
1037 |
.................... { |
|
|
1038 |
.................... char *p; |
223 |
kapl |
1039 |
.................... |
240 |
kaklik |
1040 |
.................... for (p = s; *p != '\0'; p++) |
|
|
1041 |
.................... if (*p >= 'A' && *p <='Z') |
|
|
1042 |
.................... *p += 'a' - 'A'; |
|
|
1043 |
.................... return(s); |
|
|
1044 |
.................... } |
|
|
1045 |
.................... |
|
|
1046 |
.................... |
|
|
1047 |
.................... /************************************************************/ |
|
|
1048 |
.................... |
|
|
1049 |
.................... |
|
|
1050 |
.................... #endif |
|
|
1051 |
.................... |
|
|
1052 |
.................... #include <stdlib.h> |
|
|
1053 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
1054 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
1055 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
1056 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
1057 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
1058 |
.................... //// or distribution is permitted without written permission. //// |
|
|
1059 |
.................... //// Derivative programs created using this software in object code //// |
|
|
1060 |
.................... //// form are not restricted in any way. //// |
|
|
1061 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
1062 |
.................... |
|
|
1063 |
.................... #ifndef _STDLIB |
|
|
1064 |
.................... #define _STDLIB |
|
|
1065 |
.................... |
|
|
1066 |
.................... //--------------------------------------------------------------------------- |
|
|
1067 |
.................... // Definitions and types |
|
|
1068 |
.................... //--------------------------------------------------------------------------- |
|
|
1069 |
.................... |
|
|
1070 |
.................... #ifndef RAND_MAX |
|
|
1071 |
.................... #define RAND_MAX 32767 // The value of which is the maximum value |
|
|
1072 |
.................... // ... returned by the rand function |
|
|
1073 |
.................... #endif |
|
|
1074 |
.................... |
|
|
1075 |
.................... typedef struct { |
|
|
1076 |
.................... signed int quot; |
|
|
1077 |
.................... signed int rem; |
|
|
1078 |
.................... } div_t; |
|
|
1079 |
.................... |
|
|
1080 |
.................... typedef struct { |
|
|
1081 |
.................... signed long quot; |
|
|
1082 |
.................... signed long rem; |
|
|
1083 |
.................... } ldiv_t; |
|
|
1084 |
.................... |
|
|
1085 |
.................... #include <stddef.h> |
|
|
1086 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
1087 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
1088 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
1089 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
1090 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
1091 |
.................... //// or distribution is permitted without written permission. //// |
|
|
1092 |
.................... //// Derivative programs created using this software in object code //// |
|
|
1093 |
.................... //// form are not restricted in any way. //// |
|
|
1094 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
1095 |
.................... |
|
|
1096 |
.................... #ifndef _STDDEF |
|
|
1097 |
.................... |
|
|
1098 |
.................... #define _STDDEF |
|
|
1099 |
.................... |
|
|
1100 |
.................... #if sizeof(int *)==1 |
|
|
1101 |
.................... #define ptrdiff_t int |
|
|
1102 |
.................... #else |
|
|
1103 |
.................... #define ptrdiff_t long |
|
|
1104 |
.................... #endif |
|
|
1105 |
.................... |
|
|
1106 |
.................... #define size_t int |
|
|
1107 |
.................... #define wchar_t char |
|
|
1108 |
.................... #define NULL 0 |
|
|
1109 |
.................... |
|
|
1110 |
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) |
|
|
1111 |
.................... |
|
|
1112 |
.................... #endif |
|
|
1113 |
.................... |
|
|
1114 |
.................... |
|
|
1115 |
.................... //--------------------------------------------------------------------------- |
|
|
1116 |
.................... // String conversion functions |
|
|
1117 |
.................... //--------------------------------------------------------------------------- |
|
|
1118 |
.................... |
|
|
1119 |
.................... /* Standard template: float atof(char * s) |
|
|
1120 |
.................... * converts the initial portion of the string s to a float. |
|
|
1121 |
.................... * returns the converted value if any, 0 otherwise |
|
|
1122 |
.................... */ |
|
|
1123 |
.................... float atof(char * s); |
|
|
1124 |
.................... |
|
|
1125 |
.................... /* Standard template: float atoe(char * s) |
|
|
1126 |
.................... * converts the initial portion of the string s to a float. |
|
|
1127 |
.................... * returns the converted value if any, 0 otherwise |
|
|
1128 |
.................... * also handles E format numbers |
|
|
1129 |
.................... */ |
|
|
1130 |
.................... float atoe(char * s); |
|
|
1131 |
.................... |
|
|
1132 |
.................... /* Standard template: signed int atoi(char * s) |
|
|
1133 |
.................... * converts the initial portion of the string s to a signed int |
|
|
1134 |
.................... * returns the converted value if any, 0 otherwise |
|
|
1135 |
.................... */ |
|
|
1136 |
.................... signed int atoi(char *s); |
|
|
1137 |
.................... |
|
|
1138 |
.................... /* Syntax: signed int32 atoi32(char * s) |
|
|
1139 |
.................... converts the initial portion of the string s to a signed int32 |
|
|
1140 |
.................... returns the converted value if any, 0 otherwise*/ |
|
|
1141 |
.................... signed int32 atoi32(char *s); |
|
|
1142 |
.................... |
|
|
1143 |
.................... /* Syntax: char * itoa(signed int32 num, int8 base, char * s) |
|
|
1144 |
.................... converts the signed int32 to a string and |
|
|
1145 |
.................... returns the converted value if any, 0 otherwise*/ |
|
|
1146 |
.................... char * itoa(signed int32 num, int8 base, char * s); |
|
|
1147 |
.................... |
|
|
1148 |
.................... /* Standard template: signed long atol(char * s) |
|
|
1149 |
.................... * converts the initial portion of the string s to a signed long |
|
|
1150 |
.................... * returns the converted value if any, 0 otherwise |
|
|
1151 |
.................... */ |
|
|
1152 |
.................... signed long atol(char *s); |
|
|
1153 |
.................... |
|
|
1154 |
.................... /* Standard template: float strtol(char * s,char *endptr) |
|
|
1155 |
.................... * converts the initial portion of the string s to a float |
|
|
1156 |
.................... * returns the converted value if any, 0 otherwise |
|
|
1157 |
.................... * the final string is returned in the endptr, if endptr is not null |
|
|
1158 |
.................... */ |
|
|
1159 |
.................... float strtod(char *s,char *endptr); |
|
|
1160 |
.................... |
|
|
1161 |
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) |
|
|
1162 |
.................... * converts the initial portion of the string s, represented as an |
|
|
1163 |
.................... * integral value of radix base to a signed long. |
|
|
1164 |
.................... * Returns the converted value if any, 0 otherwise |
|
|
1165 |
.................... * the final string is returned in the endptr, if endptr is not null |
|
|
1166 |
.................... */ |
|
|
1167 |
.................... signed long strtol(char *s,char *endptr,signed int base); |
|
|
1168 |
.................... |
|
|
1169 |
.................... /* Standard template: long strtoul(char * s,char *endptr,signed int base) |
|
|
1170 |
.................... * converts the initial portion of the string s, represented as an |
|
|
1171 |
.................... * integral value of radix base to a unsigned long. |
|
|
1172 |
.................... * returns the converted value if any, 0 otherwise |
|
|
1173 |
.................... * the final string is returned in the endptr, if endptr is not null |
|
|
1174 |
.................... */ |
|
|
1175 |
.................... long strtoul(char *s,char *endptr,signed int base); |
|
|
1176 |
.................... |
|
|
1177 |
.................... //--------------------------------------------------------------------------- |
|
|
1178 |
.................... // Pseudo-random sequence generation functions |
|
|
1179 |
.................... //--------------------------------------------------------------------------- |
|
|
1180 |
.................... |
|
|
1181 |
.................... /* The rand function computes a sequence of pseudo-random integers in |
|
|
1182 |
.................... * the range 0 to RAND_MAX |
|
|
1183 |
.................... * |
|
|
1184 |
.................... * Parameters: |
|
|
1185 |
.................... * (none) |
|
|
1186 |
.................... * |
|
|
1187 |
.................... * Returns: |
|
|
1188 |
.................... * The pseudo-random integer |
|
|
1189 |
.................... */ |
|
|
1190 |
.................... long rand(void); |
|
|
1191 |
.................... |
|
|
1192 |
.................... /* The srand function uses the argument as a seed for a new sequence of |
|
|
1193 |
.................... * pseudo-random numbers to be returned by subsequent calls to rand. |
|
|
1194 |
.................... * |
|
|
1195 |
.................... * Parameters: |
|
|
1196 |
.................... * [in] seed: The seed value to start from. You might need to pass |
|
|
1197 |
.................... * |
|
|
1198 |
.................... * Returns: |
|
|
1199 |
.................... * (none) |
|
|
1200 |
.................... * |
|
|
1201 |
.................... * Remarks |
|
|
1202 |
.................... * The srand function sets the starting point for generating |
|
|
1203 |
.................... * a series of pseudorandom integers. To reinitialize the |
|
|
1204 |
.................... * generator, use 1 as the seed argument. Any other value for |
|
|
1205 |
.................... * seed sets the generator to a random starting point. rand |
|
|
1206 |
.................... * retrieves the pseudorandom numbers that are generated. |
|
|
1207 |
.................... * Calling rand before any call to srand generates the same |
|
|
1208 |
.................... * sequence as calling srand with seed passed as 1. |
|
|
1209 |
.................... * Usually, you need to pass a time here from outer source |
|
|
1210 |
.................... * so that the numbers will be different every time you run. |
|
|
1211 |
.................... */ |
|
|
1212 |
.................... void srand(unsigned int32 seed); |
|
|
1213 |
.................... |
|
|
1214 |
.................... //--------------------------------------------------------------------------- |
|
|
1215 |
.................... // Memory management functions |
|
|
1216 |
.................... //--------------------------------------------------------------------------- |
|
|
1217 |
.................... |
|
|
1218 |
.................... // Comming soon |
|
|
1219 |
.................... |
|
|
1220 |
.................... //--------------------------------------------------------------------------- |
|
|
1221 |
.................... // Communication with the environment |
|
|
1222 |
.................... //--------------------------------------------------------------------------- |
|
|
1223 |
.................... |
|
|
1224 |
.................... /* The function returns 0 always |
|
|
1225 |
.................... */ |
|
|
1226 |
.................... signed int system(char *string); |
|
|
1227 |
.................... |
|
|
1228 |
.................... //--------------------------------------------------------------------------- |
|
|
1229 |
.................... // Searching and sorting utilities |
|
|
1230 |
.................... //--------------------------------------------------------------------------- |
|
|
1231 |
.................... |
|
|
1232 |
.................... /* Performs a binary search of a sorted array.. |
|
|
1233 |
.................... * |
|
|
1234 |
.................... * Parameters: |
|
|
1235 |
.................... * [in] key: Object to search for |
|
|
1236 |
.................... * [in] base: Pointer to base of search data |
|
|
1237 |
.................... * [in] num: Number of elements |
|
|
1238 |
.................... * [in] width: Width of elements |
|
|
1239 |
.................... * [in] compare: Function that compares two elements |
|
|
1240 |
.................... * |
|
|
1241 |
.................... * Returns: |
|
|
1242 |
.................... * bsearch returns a pointer to an occurrence of key in the array pointed |
|
|
1243 |
.................... * to by base. If key is not found, the function returns NULL. If the |
|
|
1244 |
.................... * array is not in order or contains duplicate records with identical keys, |
|
|
1245 |
.................... * the result is unpredictable. |
|
|
1246 |
.................... */ |
|
|
1247 |
.................... //void *bsearch(const void *key, const void *base, size_t num, size_t width, |
|
|
1248 |
.................... // int (*compare)(const void *, const void *)); |
|
|
1249 |
.................... |
|
|
1250 |
.................... /* Performs the shell-metzner sort (not the quick sort algorithm). The contents |
|
|
1251 |
.................... * of the array are sorted into ascending order according to a comparison |
|
|
1252 |
.................... * function pointed to by compar. |
|
|
1253 |
.................... * |
|
|
1254 |
.................... * Parameters: |
|
|
1255 |
.................... * [in] base: Pointer to base of search data |
|
|
1256 |
.................... * [in] num: Number of elements |
|
|
1257 |
.................... * [in] width: Width of elements |
|
|
1258 |
.................... * [in] compare: Function that compares two elements |
|
|
1259 |
.................... * |
|
|
1260 |
.................... * Returns: |
|
|
1261 |
.................... * (none) |
|
|
1262 |
.................... */ |
|
|
1263 |
.................... //void *qsort(const void *base, size_t num, size_t width, |
|
|
1264 |
.................... // int (*compare)(const void *, const void *)); |
|
|
1265 |
.................... |
|
|
1266 |
.................... //--------------------------------------------------------------------------- |
|
|
1267 |
.................... // Integer arithmetic functions |
|
|
1268 |
.................... //--------------------------------------------------------------------------- |
|
|
1269 |
.................... |
|
|
1270 |
.................... #define labs abs |
|
|
1271 |
.................... |
|
|
1272 |
.................... div_t div(signed int numer,signed int denom); |
|
|
1273 |
.................... ldiv_t ldiv(signed long numer,signed long denom); |
|
|
1274 |
.................... |
|
|
1275 |
.................... //--------------------------------------------------------------------------- |
|
|
1276 |
.................... // Multibyte character functions |
|
|
1277 |
.................... //--------------------------------------------------------------------------- |
|
|
1278 |
.................... |
|
|
1279 |
.................... // Not supported |
|
|
1280 |
.................... |
|
|
1281 |
.................... //--------------------------------------------------------------------------- |
|
|
1282 |
.................... // Multibyte string functions |
|
|
1283 |
.................... //--------------------------------------------------------------------------- |
|
|
1284 |
.................... |
|
|
1285 |
.................... // Not supported |
|
|
1286 |
.................... |
|
|
1287 |
.................... |
|
|
1288 |
.................... //--------------------------------------------------------------------------- |
|
|
1289 |
.................... // Internal implementation |
|
|
1290 |
.................... //--------------------------------------------------------------------------- |
|
|
1291 |
.................... |
|
|
1292 |
.................... #include <stddef.h> |
|
|
1293 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
1294 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
1295 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
1296 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
1297 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
1298 |
.................... //// or distribution is permitted without written permission. //// |
|
|
1299 |
.................... //// Derivative programs created using this software in object code //// |
|
|
1300 |
.................... //// form are not restricted in any way. //// |
|
|
1301 |
.................... /////////////////////////////////////////////////////////////////////////// |
|
|
1302 |
.................... |
|
|
1303 |
.................... #ifndef _STDDEF |
|
|
1304 |
.................... |
|
|
1305 |
.................... #define _STDDEF |
|
|
1306 |
.................... |
|
|
1307 |
.................... #if sizeof(int *)==1 |
|
|
1308 |
.................... #define ptrdiff_t int |
|
|
1309 |
.................... #else |
|
|
1310 |
.................... #define ptrdiff_t long |
|
|
1311 |
.................... #endif |
|
|
1312 |
.................... |
|
|
1313 |
.................... #define size_t int |
|
|
1314 |
.................... #define wchar_t char |
|
|
1315 |
.................... #define NULL 0 |
|
|
1316 |
.................... |
|
|
1317 |
.................... #define offsetof(s,f) (offsetofbit(s,f)/8) |
|
|
1318 |
.................... |
|
|
1319 |
.................... #endif |
|
|
1320 |
.................... |
|
|
1321 |
.................... #include <string.h> |
|
|
1322 |
.................... //////////////////////////////////////////////////////////////////////////// |
|
|
1323 |
.................... //// (C) Copyright 1996,2003 Custom Computer Services //// |
|
|
1324 |
.................... //// This source code may only be used by licensed users of the CCS C //// |
|
|
1325 |
.................... //// compiler. This source code may only be distributed to other //// |
|
|
1326 |
.................... //// licensed users of the CCS C compiler. No other use, reproduction //// |
|
|
1327 |
.................... //// or distribution is permitted without written permission. //// |
|
|
1328 |
.................... //// Derivative programs created using this software in object code //// |
|
|
1329 |
.................... //// form are not restricted in any way. //// |
|
|
1330 |
.................... //////////////////////////////////////////////////////////////////////////// |
|
|
1331 |
.................... |
|
|
1332 |
.................... #ifndef _STRING |
|
|
1333 |
.................... #define _STRING |
|
|
1334 |
.................... #include <stddef.h> |
|
|
1335 |
.................... #include <ctype.h> |
|
|
1336 |
.................... |
|
|
1337 |
.................... |
|
|
1338 |
.................... |
|
|
1339 |
.................... ////////////////////////////////////////////// |
|
|
1340 |
.................... //// Uncomment the following define to //// |
|
|
1341 |
.................... //// allow some functions to use a //// |
|
|
1342 |
.................... //// quicker algorithm, but use more ROM //// |
|
|
1343 |
.................... //// //// |
|
|
1344 |
.................... //// #define FASTER_BUT_MORE_ROM //// |
|
|
1345 |
.................... ////////////////////////////////////////////// |
|
|
1346 |
.................... |
|
|
1347 |
.................... |
|
|
1348 |
.................... |
|
|
1349 |
.................... /*Copying functions*/ |
|
|
1350 |
.................... /* standard template: |
|
|
1351 |
.................... void *memmove(void *s1, void *s2, size_t n). |
|
|
1352 |
.................... Copies max of n characters safely (not following ending '\0') |
|
|
1353 |
.................... from s2 in s1; if s2 has less than n characters, appends 0 */ |
|
|
1354 |
.................... |
|
|
1355 |
.................... char *memmove(void *s1,char *s2,size_t n) |
223 |
kapl |
1356 |
.................... { |
240 |
kaklik |
1357 |
.................... char *sc1; |
|
|
1358 |
.................... char *sc2; |
|
|
1359 |
.................... sc1=s1; |
|
|
1360 |
.................... sc2=s2; |
|
|
1361 |
.................... if(sc2<sc1 && sc1 <sc2 +n) |
|
|
1362 |
.................... for(sc1+=n,sc2+=n;0<n;--n) |
|
|
1363 |
.................... *--sc1=*--sc2; |
|
|
1364 |
.................... else |
|
|
1365 |
.................... for(;0<n;--n) |
|
|
1366 |
.................... *sc1++=*sc2++; |
|
|
1367 |
.................... return s1; |
|
|
1368 |
.................... } |
|
|
1369 |
.................... |
|
|
1370 |
.................... /* compiler ignored the name 'strcpy()'; perhaps, it's reserved? |
|
|
1371 |
.................... Standard template: char *strcpy(char *s1, const char *s2) |
|
|
1372 |
.................... copies the string s2 including the null character to s1*/ |
|
|
1373 |
.................... |
|
|
1374 |
.................... char *strcopy(char *s1, char *s2) |
|
|
1375 |
.................... { |
|
|
1376 |
.................... char *s; |
|
|
1377 |
.................... |
|
|
1378 |
.................... for (s = s1; *s2 != 0; s++, s2++) { |
|
|
1379 |
.................... *s = *s2; |
|
|
1380 |
.................... } |
|
|
1381 |
.................... *s = *s2; |
|
|
1382 |
.................... return(s1); |
223 |
kapl |
1383 |
.................... } |
|
|
1384 |
.................... |
240 |
kaklik |
1385 |
.................... /* standard template: |
|
|
1386 |
.................... char *strncpy(char *s1, const char *s2, size_t n). |
|
|
1387 |
.................... Copies max of n characters (not following ending '\0') |
|
|
1388 |
.................... from s2 in s1; if s2 has less than n characters, appends 0 */ |
223 |
kapl |
1389 |
.................... |
240 |
kaklik |
1390 |
.................... char *strncpy(char *s1, char *s2, size_t n) |
|
|
1391 |
.................... { |
|
|
1392 |
.................... char *s; |
223 |
kapl |
1393 |
.................... |
240 |
kaklik |
1394 |
.................... for (s = s1; n > 0 && *s2 != '\0'; n--) |
|
|
1395 |
.................... *s++ = *s2++; |
|
|
1396 |
.................... for (; n > 0; n--) |
|
|
1397 |
.................... *s++ = '\0'; |
223 |
kapl |
1398 |
.................... |
240 |
kaklik |
1399 |
.................... return(s1); |
|
|
1400 |
.................... } |
|
|
1401 |
.................... /***********************************************************/ |
223 |
kapl |
1402 |
.................... |
240 |
kaklik |
1403 |
.................... /*concatenation functions*/ |
|
|
1404 |
.................... /* standard template: char *strcat(char *s1, const char *s2) |
|
|
1405 |
.................... appends s2 to s1*/ |
223 |
kapl |
1406 |
.................... |
240 |
kaklik |
1407 |
.................... char *strcat(char *s1, char *s2) |
|
|
1408 |
.................... { |
|
|
1409 |
.................... char *s; |
223 |
kapl |
1410 |
.................... |
240 |
kaklik |
1411 |
.................... for (s = s1; *s != '\0'; ++s); |
|
|
1412 |
.................... while(*s2 != '\0') |
|
|
1413 |
.................... { |
|
|
1414 |
.................... *s = *s2; |
|
|
1415 |
.................... ++s; |
|
|
1416 |
.................... ++s2; |
|
|
1417 |
.................... } |
223 |
kapl |
1418 |
.................... |
240 |
kaklik |
1419 |
.................... *s = '\0'; |
|
|
1420 |
.................... return(s1); |
|
|
1421 |
.................... } |
|
|
1422 |
.................... /* standard template: char *strncat(char *s1, char *s2,size_t n) |
|
|
1423 |
.................... appends not more than n characters from s2 to s1*/ |
223 |
kapl |
1424 |
.................... |
240 |
kaklik |
1425 |
.................... char *strncat(char *s1, char *s2, size_t n) |
|
|
1426 |
.................... { |
|
|
1427 |
.................... char *s; |
223 |
kapl |
1428 |
.................... |
240 |
kaklik |
1429 |
.................... for (s = s1; *s != '\0'; ++s); |
|
|
1430 |
.................... while(*s2 != '\0' && 0<n) |
|
|
1431 |
.................... { |
|
|
1432 |
.................... *s = *s2; |
|
|
1433 |
.................... ++s; |
|
|
1434 |
.................... ++s2; |
|
|
1435 |
.................... --n; |
|
|
1436 |
.................... } |
|
|
1437 |
.................... |
|
|
1438 |
.................... *s = '\0'; |
|
|
1439 |
.................... return(s1); |
|
|
1440 |
.................... } |
|
|
1441 |
.................... |
|
|
1442 |
.................... /***********************************************************/ |
|
|
1443 |
.................... |
|
|
1444 |
.................... |
|
|
1445 |
.................... /*comparison functions*/ |
|
|
1446 |
.................... /* standard template: signed int memcmp(void *s1, void *s2). |
|
|
1447 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
|
|
1448 |
.................... |
|
|
1449 |
.................... signed int memcmp(void * s1,char *s2,size_t n) |
223 |
kapl |
1450 |
.................... { |
240 |
kaklik |
1451 |
.................... char *su1, *su2; |
|
|
1452 |
.................... for(su1=s1, su2=s2; 0<n; ++su1, ++su2, --n) |
|
|
1453 |
.................... { |
|
|
1454 |
.................... if(*su1!=*su2) |
|
|
1455 |
.................... return ((*su1<*su2)?-1:+1); |
|
|
1456 |
.................... } |
|
|
1457 |
.................... return 0; |
|
|
1458 |
.................... } |
223 |
kapl |
1459 |
.................... |
240 |
kaklik |
1460 |
.................... /* standard template: int strcmp(const char *s1, const char *s2). |
|
|
1461 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
239 |
kaklik |
1462 |
.................... |
240 |
kaklik |
1463 |
.................... signed int strcmp(char *s1, char *s2) |
|
|
1464 |
.................... { |
|
|
1465 |
.................... for (; *s1 == *s2; s1++, s2++) |
|
|
1466 |
.................... if (*s1 == '\0') |
|
|
1467 |
.................... return(0); |
|
|
1468 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
1469 |
.................... } |
|
|
1470 |
.................... /* standard template: int strcoll(const char *s1, const char *s2). |
|
|
1471 |
.................... Compares s1 & s2; returns -1 if s1<s2, 0 if s1=s2, 1 if s1>s2 */ |
|
|
1472 |
.................... |
|
|
1473 |
.................... signed int strcoll(char *s1, char *s2) |
|
|
1474 |
.................... { |
|
|
1475 |
.................... for (; *s1 == *s2; s1++, s2++) |
|
|
1476 |
.................... if (*s1 == '\0') |
|
|
1477 |
.................... return(0); |
|
|
1478 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
1479 |
.................... } |
|
|
1480 |
.................... |
|
|
1481 |
.................... /* standard template: |
|
|
1482 |
.................... int strncmp(const char *s1, const char *s2, size_t n). |
|
|
1483 |
.................... Compares max of n characters (not following 0) from s1 to s2; |
|
|
1484 |
.................... returns same as strcmp */ |
|
|
1485 |
.................... |
|
|
1486 |
.................... signed int strncmp(char *s1, char *s2, size_t n) |
|
|
1487 |
.................... { |
|
|
1488 |
.................... for (; n > 0; s1++, s2++, n--) |
|
|
1489 |
.................... if (*s1 != *s2) |
|
|
1490 |
.................... return((*s1 <*s2) ? -1: 1); |
|
|
1491 |
.................... else if (*s1 == '\0') |
|
|
1492 |
.................... return(0); |
|
|
1493 |
.................... return(0); |
|
|
1494 |
.................... } |
|
|
1495 |
.................... /* standard template: |
|
|
1496 |
.................... int strxfrm(const char *s1, const char *s2, size_t n). |
|
|
1497 |
.................... transforms maximum of n characters from s2 and places them into s1*/ |
|
|
1498 |
.................... size_t strxfrm(char *s1, char *s2, size_t n) |
|
|
1499 |
.................... { |
|
|
1500 |
.................... char *s; |
|
|
1501 |
.................... int n1; |
|
|
1502 |
.................... n1=n; |
|
|
1503 |
.................... for (s = s1; n > 0 && *s2 != '\0'; n--) |
|
|
1504 |
.................... *s++ = *s2++; |
|
|
1505 |
.................... for (; n > 0; n--) |
|
|
1506 |
.................... *s++ = '\0'; |
|
|
1507 |
.................... |
|
|
1508 |
.................... return(n1); |
|
|
1509 |
.................... } |
|
|
1510 |
.................... |
|
|
1511 |
.................... |
|
|
1512 |
.................... |
|
|
1513 |
.................... |
|
|
1514 |
.................... |
|
|
1515 |
.................... /***********************************************************/ |
|
|
1516 |
.................... /*Search functions*/ |
|
|
1517 |
.................... /* standard template: void *memchr(const char *s, int c). |
|
|
1518 |
.................... Finds first occurrence of c in n characters of s */ |
|
|
1519 |
.................... |
|
|
1520 |
.................... char *memchr(void *s,int c,size_t n) |
|
|
1521 |
.................... { |
|
|
1522 |
.................... char uc; |
|
|
1523 |
.................... char *su; |
|
|
1524 |
.................... uc=c; |
|
|
1525 |
.................... for(su=s;0<n;++su,--n) |
|
|
1526 |
.................... if(*su==uc) |
|
|
1527 |
.................... return su; |
|
|
1528 |
.................... return NULL; |
|
|
1529 |
.................... } |
|
|
1530 |
.................... |
|
|
1531 |
.................... /* standard template: char *strchr(const char *s, int c). |
|
|
1532 |
.................... Finds first occurrence of c in s */ |
|
|
1533 |
.................... |
|
|
1534 |
.................... char *strchr(char *s, int c) |
|
|
1535 |
.................... { |
|
|
1536 |
.................... for (; *s != c; s++) |
|
|
1537 |
.................... if (*s == '\0') |
|
|
1538 |
.................... return(0); |
|
|
1539 |
.................... return(s); |
|
|
1540 |
.................... } |
|
|
1541 |
.................... /* standard template: |
|
|
1542 |
.................... size_t strcspn(const char *s1, const char *s2). |
|
|
1543 |
.................... Computes length of max initial segment of s1 that |
|
|
1544 |
.................... consists entirely of characters NOT from s2*/ |
|
|
1545 |
.................... |
|
|
1546 |
.................... int *strcspn(char *s1, char *s2) |
|
|
1547 |
.................... { |
|
|
1548 |
.................... char *sc1, *sc2; |
|
|
1549 |
.................... |
|
|
1550 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
1551 |
.................... for (sc2 = s2; *sc2 != 0; sc2++) |
|
|
1552 |
.................... if (*sc1 == *sc2) |
|
|
1553 |
.................... return(sc1 - s1); |
|
|
1554 |
.................... return(sc1 - s1); |
|
|
1555 |
.................... } |
|
|
1556 |
.................... /* standard template: |
|
|
1557 |
.................... char *strpbrk(const char *s1, const char *s2). |
|
|
1558 |
.................... Locates first occurence of any character from s2 in s1; |
|
|
1559 |
.................... returns s1 if s2 is empty string */ |
|
|
1560 |
.................... |
|
|
1561 |
.................... char *strpbrk(char *s1, char *s2) |
|
|
1562 |
.................... { |
|
|
1563 |
.................... char *sc1, *sc2; |
|
|
1564 |
.................... |
|
|
1565 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
1566 |
.................... for (sc2 = s2; *sc2 != 0; sc2++) |
|
|
1567 |
.................... if (*sc1 == *sc2) |
|
|
1568 |
.................... return(sc1); |
|
|
1569 |
.................... return(0); |
|
|
1570 |
.................... } |
|
|
1571 |
.................... |
|
|
1572 |
.................... |
|
|
1573 |
.................... /* standard template: char *strrchr(const char *s, int c). |
|
|
1574 |
.................... Finds last occurrence of c in s */ |
|
|
1575 |
.................... |
|
|
1576 |
.................... char *strrchr(char *s, int c) |
|
|
1577 |
.................... { |
|
|
1578 |
.................... char *p; |
|
|
1579 |
.................... |
|
|
1580 |
.................... for (p = 0; ; s++) |
223 |
kapl |
1581 |
.................... { |
240 |
kaklik |
1582 |
.................... if (*s == c) |
|
|
1583 |
.................... p = s; |
|
|
1584 |
.................... if (*s == '\0') |
|
|
1585 |
.................... return(p); |
|
|
1586 |
.................... } |
|
|
1587 |
.................... } |
|
|
1588 |
.................... /* computes length of max initial segment of s1 consisting |
|
|
1589 |
.................... entirely of characters from s2 */ |
239 |
kaklik |
1590 |
.................... |
240 |
kaklik |
1591 |
.................... int *strspn(char *s1, char *s2) |
|
|
1592 |
.................... { |
|
|
1593 |
.................... char *sc1, *sc2; |
239 |
kaklik |
1594 |
.................... |
240 |
kaklik |
1595 |
.................... for (sc1 = s1; *sc1 != 0; sc1++) |
|
|
1596 |
.................... for (sc2 = s2; ; sc2++) |
|
|
1597 |
.................... if (*sc2 == '\0') |
|
|
1598 |
.................... return(sc1 - s1); |
|
|
1599 |
.................... else if (*sc1 == *sc2) |
|
|
1600 |
.................... break; |
|
|
1601 |
.................... return(sc1 - s1); |
|
|
1602 |
.................... } |
|
|
1603 |
.................... /* standard template: |
|
|
1604 |
.................... char *strstr(const char *s1, const char *s2); |
|
|
1605 |
.................... Locates first occurence of character sequence s2 in s1; |
|
|
1606 |
.................... returns 0 if s2 is empty string |
238 |
kaklik |
1607 |
.................... |
240 |
kaklik |
1608 |
.................... Uncomment #define FASTER_BUT_MORE_ROM at the top of the |
|
|
1609 |
.................... file to use the faster algorithm */ |
|
|
1610 |
.................... char *strstr(char *s1, char *s2) |
|
|
1611 |
.................... { |
|
|
1612 |
.................... char *s, *t; |
238 |
kaklik |
1613 |
.................... |
240 |
kaklik |
1614 |
.................... #ifdef FASTER_BUT_MORE_ROM |
|
|
1615 |
.................... if (*s2 == '\0') |
|
|
1616 |
.................... return(s1); |
|
|
1617 |
.................... #endif |
238 |
kaklik |
1618 |
.................... |
240 |
kaklik |
1619 |
.................... while (*s1) |
|
|
1620 |
.................... { |
|
|
1621 |
.................... for(s = s1, t = s2; *t && *s == *t; ++s, ++t); |
|
|
1622 |
.................... |
|
|
1623 |
.................... if (*t == '\0') |
|
|
1624 |
.................... return s1; |
|
|
1625 |
.................... ++s1; |
|
|
1626 |
.................... #ifdef FASTER_BUT_MORE_ROM |
|
|
1627 |
.................... while(*s1 != '\0' && *s1 != *s2) |
|
|
1628 |
.................... ++s1; |
|
|
1629 |
.................... #endif |
|
|
1630 |
.................... } |
|
|
1631 |
.................... return 0; |
|
|
1632 |
.................... } |
|
|
1633 |
.................... |
|
|
1634 |
.................... /* standard template: char *strtok(char *s1, const char *s2). |
|
|
1635 |
.................... |
|
|
1636 |
.................... Finds next token in s1 delimited by a character from separator |
|
|
1637 |
.................... string s2 (which can be different from call to call). First call |
|
|
1638 |
.................... starts at beginning of s1 searching for first character NOT |
|
|
1639 |
.................... contained in s2; returns 0 if none is found. |
|
|
1640 |
.................... If one is found, it is the start of first token (return value). |
|
|
1641 |
.................... Function then searches from there for a character contained in s2. |
|
|
1642 |
.................... If none is found, current token extends to end of s1, and subsequent |
|
|
1643 |
.................... searches for a token will return 0. If one is found, it is |
|
|
1644 |
.................... overwritten by '\0', which terminates current token. Function saves |
|
|
1645 |
.................... pointer to following character from which next search will start. |
|
|
1646 |
.................... Each subsequent call, with 0 as first argument, starts searching |
|
|
1647 |
.................... from saved pointer */ |
|
|
1648 |
.................... |
|
|
1649 |
.................... char *strtok(char *s1, char *s2) |
|
|
1650 |
.................... { |
|
|
1651 |
.................... char *beg, *end; |
|
|
1652 |
.................... static char *save; |
|
|
1653 |
.................... |
|
|
1654 |
.................... beg = (s1)? s1: save; |
|
|
1655 |
.................... beg += strspn(beg, s2); |
|
|
1656 |
.................... if (*beg == '\0') |
|
|
1657 |
.................... { |
|
|
1658 |
.................... *save = ' '; |
|
|
1659 |
.................... return(0); |
|
|
1660 |
.................... } |
|
|
1661 |
.................... end = strpbrk(beg, s2); |
|
|
1662 |
.................... if (*end != '\0') |
|
|
1663 |
.................... { |
|
|
1664 |
.................... *end = '\0'; |
|
|
1665 |
.................... end++; |
|
|
1666 |
.................... } |
|
|
1667 |
.................... save = end; |
|
|
1668 |
.................... return(beg); |
|
|
1669 |
.................... } |
|
|
1670 |
.................... |
|
|
1671 |
.................... /*****************************************************************/ |
|
|
1672 |
.................... /*Miscellaneous functions*/ |
|
|
1673 |
.................... /* standard template |
|
|
1674 |
.................... maps error number in errnum to an error message string |
|
|
1675 |
.................... Returns: Pointer to string |
238 |
kaklik |
1676 |
.................... */ |
240 |
kaklik |
1677 |
.................... #ifdef _ERRNO |
|
|
1678 |
.................... char * strerror(int errnum) |
|
|
1679 |
.................... { |
|
|
1680 |
.................... char s[15]; |
|
|
1681 |
.................... switch( errnum) |
|
|
1682 |
.................... { |
|
|
1683 |
.................... case 0: |
|
|
1684 |
.................... strcpy(s,"no errors"); |
|
|
1685 |
.................... return s; |
|
|
1686 |
.................... case EDOM : |
|
|
1687 |
.................... strcpy(s,"domain error"); |
|
|
1688 |
.................... return s; |
|
|
1689 |
.................... case ERANGE: |
|
|
1690 |
.................... strcpy(s,"range error"); |
|
|
1691 |
.................... return s; |
|
|
1692 |
.................... } |
|
|
1693 |
.................... } |
|
|
1694 |
.................... #ENDIF |
|
|
1695 |
.................... /* standard template: size_t strlen(const char *s). |
|
|
1696 |
.................... Computes length of s1 (preceding terminating 0) */ |
239 |
kaklik |
1697 |
.................... |
240 |
kaklik |
1698 |
.................... int *strlen(char *s) |
|
|
1699 |
.................... { |
|
|
1700 |
.................... char *sc; |
239 |
kaklik |
1701 |
.................... |
240 |
kaklik |
1702 |
.................... for (sc = s; *sc != 0; sc++); |
|
|
1703 |
.................... return(sc - s); |
|
|
1704 |
.................... } |
238 |
kaklik |
1705 |
.................... |
240 |
kaklik |
1706 |
.................... /* standard template: size_t stricmp(const char *s1, const char *s2). |
|
|
1707 |
.................... Compares s1 to s2 ignoring case (upper vs. lower) */ |
238 |
kaklik |
1708 |
.................... |
240 |
kaklik |
1709 |
.................... signed int stricmp(char *s1, char *s2) |
|
|
1710 |
.................... { |
|
|
1711 |
.................... for(; *s1==*s2||(isalpha(*s1)&&isalpha(*s2)&&(*s1==*s2+32||*s2==*s1+32)); |
|
|
1712 |
.................... s1++, s2++) |
|
|
1713 |
.................... if (*s1 == '\0') |
|
|
1714 |
.................... return(0); |
|
|
1715 |
.................... return((*s1 < *s2) ? -1: 1); |
|
|
1716 |
.................... } |
238 |
kaklik |
1717 |
.................... |
|
|
1718 |
.................... |
240 |
kaklik |
1719 |
.................... /* standard template: char *strlwr(char *s). |
|
|
1720 |
.................... Replaces uppercase letters by lowercase; |
|
|
1721 |
.................... returns pointer to new string s */ |
|
|
1722 |
.................... |
|
|
1723 |
.................... char *strlwr(char *s) |
|
|
1724 |
.................... { |
|
|
1725 |
.................... char *p; |
|
|
1726 |
.................... |
|
|
1727 |
.................... for (p = s; *p != '\0'; p++) |
|
|
1728 |
.................... if (*p >= 'A' && *p <='Z') |
|
|
1729 |
.................... *p += 'a' - 'A'; |
|
|
1730 |
.................... return(s); |
|
|
1731 |
.................... } |
|
|
1732 |
.................... |
|
|
1733 |
.................... |
|
|
1734 |
.................... /************************************************************/ |
|
|
1735 |
.................... |
|
|
1736 |
.................... |
|
|
1737 |
.................... #endif |
|
|
1738 |
.................... |
|
|
1739 |
.................... |
|
|
1740 |
.................... div_t div(signed int numer,signed int denom) |
|
|
1741 |
.................... { |
|
|
1742 |
.................... div_t val; |
|
|
1743 |
.................... val.quot = numer / denom; |
|
|
1744 |
.................... val.rem = numer - (denom * val.quot); |
|
|
1745 |
.................... return (val); |
|
|
1746 |
.................... } |
|
|
1747 |
.................... |
|
|
1748 |
.................... ldiv_t ldiv(signed long numer,signed long denom) |
|
|
1749 |
.................... { |
|
|
1750 |
.................... ldiv_t val; |
|
|
1751 |
.................... val.quot = numer / denom; |
|
|
1752 |
.................... val.rem = numer - (denom * val.quot); |
|
|
1753 |
.................... return (val); |
|
|
1754 |
.................... } |
|
|
1755 |
.................... |
|
|
1756 |
.................... float atof(char * s) |
|
|
1757 |
.................... { |
|
|
1758 |
.................... float pow10 = 1.0; |
|
|
1759 |
.................... float result = 0.0; |
|
|
1760 |
.................... int sign = 0; |
|
|
1761 |
.................... char c; |
|
|
1762 |
.................... int ptr = 0; |
|
|
1763 |
.................... |
|
|
1764 |
.................... c = s[ptr++]; |
|
|
1765 |
.................... |
|
|
1766 |
.................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { |
|
|
1767 |
.................... if(c == '-') { |
|
|
1768 |
.................... sign = 1; |
|
|
1769 |
.................... c = s[ptr++]; |
|
|
1770 |
.................... } |
|
|
1771 |
.................... if(c == '+') |
|
|
1772 |
.................... c = s[ptr++]; |
|
|
1773 |
.................... |
|
|
1774 |
.................... while((c >= '0' && c <= '9')) { |
|
|
1775 |
.................... result = 10*result + c - '0'; |
|
|
1776 |
.................... c = s[ptr++]; |
|
|
1777 |
.................... } |
|
|
1778 |
.................... |
|
|
1779 |
.................... if (c == '.') { |
|
|
1780 |
.................... c = s[ptr++]; |
|
|
1781 |
.................... while((c >= '0' && c <= '9')) { |
|
|
1782 |
.................... pow10 = pow10*10; |
|
|
1783 |
.................... result += (c - '0')/pow10; |
|
|
1784 |
.................... c = s[ptr++]; |
|
|
1785 |
.................... } |
|
|
1786 |
.................... } |
|
|
1787 |
.................... |
|
|
1788 |
.................... } |
|
|
1789 |
.................... |
|
|
1790 |
.................... if (sign == 1) |
|
|
1791 |
.................... result = -1*result; |
|
|
1792 |
.................... return(result); |
|
|
1793 |
.................... } |
|
|
1794 |
.................... |
|
|
1795 |
.................... float atoe(char * s) |
|
|
1796 |
.................... { |
|
|
1797 |
.................... float pow10 = 1.0; |
|
|
1798 |
.................... float result = 0.0; |
|
|
1799 |
.................... int sign = 0; |
|
|
1800 |
.................... int expsign = 0; |
|
|
1801 |
.................... char c; |
|
|
1802 |
.................... int ptr = 0; |
|
|
1803 |
.................... int i; |
|
|
1804 |
.................... float exp = 1.0; |
|
|
1805 |
.................... int expcnt = 0; |
|
|
1806 |
.................... |
|
|
1807 |
.................... c = s[ptr++]; |
|
|
1808 |
.................... |
|
|
1809 |
.................... if ((c>='0' && c<='9') || c=='+' || c=='-' || c=='.' || c=='E' || c=='e') { |
|
|
1810 |
.................... if(c == '-') { |
|
|
1811 |
.................... sign = 1; |
|
|
1812 |
.................... c = s[ptr++]; |
|
|
1813 |
.................... } |
|
|
1814 |
.................... if(c == '+') |
|
|
1815 |
.................... c = s[ptr++]; |
|
|
1816 |
.................... |
|
|
1817 |
.................... while((c >= '0' && c <= '9')) { |
|
|
1818 |
.................... result = 10*result + c - '0'; |
|
|
1819 |
.................... c = s[ptr++]; |
|
|
1820 |
.................... } |
|
|
1821 |
.................... |
|
|
1822 |
.................... if (c == '.') { |
|
|
1823 |
.................... c = s[ptr++]; |
|
|
1824 |
.................... while((c >= '0' && c <= '9')) { |
|
|
1825 |
.................... pow10 = pow10*10; |
|
|
1826 |
.................... result += (c - '0')/pow10; |
|
|
1827 |
.................... c = s[ptr++]; |
|
|
1828 |
.................... } |
|
|
1829 |
.................... } |
|
|
1830 |
.................... |
|
|
1831 |
.................... // Handling the exponent |
|
|
1832 |
.................... if (c=='e' || c=='E') { |
|
|
1833 |
.................... c = s[ptr++]; |
|
|
1834 |
.................... |
|
|
1835 |
.................... if(c == '-') { |
|
|
1836 |
.................... expsign = 1; |
|
|
1837 |
.................... c = s[ptr++]; |
|
|
1838 |
.................... } |
|
|
1839 |
.................... if(c == '+') |
|
|
1840 |
.................... c = s[ptr++]; |
|
|
1841 |
.................... |
|
|
1842 |
.................... while((c >= '0' && c <= '9')) { |
|
|
1843 |
.................... expcnt = 10*expcnt + c - '0'; |
|
|
1844 |
.................... c = s[ptr++]; |
|
|
1845 |
.................... } |
|
|
1846 |
.................... |
|
|
1847 |
.................... for(i=0;i<expcnt;i++) |
|
|
1848 |
.................... exp*=10; |
|
|
1849 |
.................... |
|
|
1850 |
.................... if(expsign==1) |
|
|
1851 |
.................... result/=exp; |
|
|
1852 |
.................... else |
|
|
1853 |
.................... result*=exp; |
|
|
1854 |
.................... } |
|
|
1855 |
.................... } |
|
|
1856 |
.................... |
|
|
1857 |
.................... if (sign == 1) |
|
|
1858 |
.................... result = -1*result; |
|
|
1859 |
.................... return(result); |
|
|
1860 |
.................... } |
|
|
1861 |
.................... |
|
|
1862 |
.................... signed int atoi(char *s) |
|
|
1863 |
.................... { |
|
|
1864 |
.................... signed int result; |
|
|
1865 |
.................... int sign, base, index; |
|
|
1866 |
.................... char c; |
|
|
1867 |
.................... |
|
|
1868 |
.................... index = 0; |
|
|
1869 |
.................... sign = 0; |
|
|
1870 |
.................... base = 10; |
|
|
1871 |
.................... result = 0; |
|
|
1872 |
.................... |
|
|
1873 |
.................... if (!s) |
|
|
1874 |
.................... return 0; |
|
|
1875 |
.................... // Omit all preceeding alpha characters |
|
|
1876 |
.................... c = s[index++]; |
|
|
1877 |
.................... |
|
|
1878 |
.................... // increase index if either positive or negative sign is detected |
|
|
1879 |
.................... if (c == '-') |
223 |
kapl |
1880 |
.................... { |
240 |
kaklik |
1881 |
.................... sign = 1; // Set the sign to negative |
|
|
1882 |
.................... c = s[index++]; |
239 |
kaklik |
1883 |
.................... } |
240 |
kaklik |
1884 |
.................... else if (c == '+') |
|
|
1885 |
.................... { |
|
|
1886 |
.................... c = s[index++]; |
|
|
1887 |
.................... } |
|
|
1888 |
.................... |
|
|
1889 |
.................... if (c >= '0' && c <= '9') |
|
|
1890 |
.................... { |
|
|
1891 |
.................... |
|
|
1892 |
.................... // Check for hexa number |
|
|
1893 |
.................... if (c == '0' && (s[index] == 'x' || s[index] == 'X')) |
|
|
1894 |
.................... { |
|
|
1895 |
.................... base = 16; |
|
|
1896 |
.................... index++; |
|
|
1897 |
.................... c = s[index++]; |
|
|
1898 |
.................... } |
|
|
1899 |
.................... |
|
|
1900 |
.................... // The number is a decimal number |
|
|
1901 |
.................... if (base == 10) |
|
|
1902 |
.................... { |
|
|
1903 |
.................... while (c >= '0' && c <= '9') |
|
|
1904 |
.................... { |
|
|
1905 |
.................... result = 10*result + (c - '0'); |
|
|
1906 |
.................... c = s[index++]; |
|
|
1907 |
.................... } |
|
|
1908 |
.................... } |
|
|
1909 |
.................... else if (base == 16) // The number is a hexa number |
|
|
1910 |
.................... { |
|
|
1911 |
.................... c = toupper(c); |
|
|
1912 |
.................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c<='F')) |
|
|
1913 |
.................... { |
|
|
1914 |
.................... if (c >= '0' && c <= '9') |
|
|
1915 |
.................... result = (result << 4) + (c - '0'); |
|
|
1916 |
.................... else |
|
|
1917 |
.................... result = (result << 4) + (c - 'A' + 10); |
|
|
1918 |
.................... |
|
|
1919 |
.................... c = s[index++]; |
|
|
1920 |
.................... c = toupper(c); |
|
|
1921 |
.................... } |
|
|
1922 |
.................... } |
|
|
1923 |
.................... } |
|
|
1924 |
.................... |
|
|
1925 |
.................... if (sign == 1 && base == 10) |
|
|
1926 |
.................... result = -result; |
|
|
1927 |
.................... |
|
|
1928 |
.................... return(result); |
|
|
1929 |
.................... } |
|
|
1930 |
.................... |
|
|
1931 |
.................... signed long atol(char *s) |
|
|
1932 |
.................... { |
|
|
1933 |
.................... signed long result; |
|
|
1934 |
.................... int sign, base, index; |
|
|
1935 |
.................... char c; |
|
|
1936 |
.................... |
|
|
1937 |
.................... index = 0; |
|
|
1938 |
.................... sign = 0; |
|
|
1939 |
.................... base = 10; |
|
|
1940 |
.................... result = 0; |
|
|
1941 |
.................... |
|
|
1942 |
.................... if (!s) |
|
|
1943 |
.................... return 0; |
|
|
1944 |
.................... c = s[index++]; |
|
|
1945 |
.................... |
|
|
1946 |
.................... // increase index if either positive or negative sign is detected |
|
|
1947 |
.................... if (c == '-') |
|
|
1948 |
.................... { |
|
|
1949 |
.................... sign = 1; // Set the sign to negative |
|
|
1950 |
.................... c = s[index++]; |
|
|
1951 |
.................... } |
|
|
1952 |
.................... else if (c == '+') |
|
|
1953 |
.................... { |
|
|
1954 |
.................... c = s[index++]; |
|
|
1955 |
.................... } |
|
|
1956 |
.................... |
|
|
1957 |
.................... if (c >= '0' && c <= '9') |
|
|
1958 |
.................... { |
|
|
1959 |
.................... if (c == '0' && (s[index] == 'x' || s[index] == 'X')) |
|
|
1960 |
.................... { |
|
|
1961 |
.................... base = 16; |
|
|
1962 |
.................... index++; |
|
|
1963 |
.................... c = s[index++]; |
|
|
1964 |
.................... } |
|
|
1965 |
.................... |
|
|
1966 |
.................... // The number is a decimal number |
|
|
1967 |
.................... if (base == 10) |
|
|
1968 |
.................... { |
|
|
1969 |
.................... while (c >= '0' && c <= '9') |
|
|
1970 |
.................... { |
|
|
1971 |
.................... result = 10*result + (c - '0'); |
|
|
1972 |
.................... c = s[index++]; |
|
|
1973 |
.................... } |
|
|
1974 |
.................... } |
|
|
1975 |
.................... else if (base == 16) // The number is a hexa number |
|
|
1976 |
.................... { |
|
|
1977 |
.................... c = toupper(c); |
|
|
1978 |
.................... while ( (c >= '0' && c <= '9') || (c >= 'A' && c <='F')) |
|
|
1979 |
.................... { |
|
|
1980 |
.................... if (c >= '0' && c <= '9') |
|
|
1981 |
.................... result = (result << 4) + (c - '0'); |
|
|
1982 |
.................... else |
|
|
1983 |
.................... result = (result << 4) + (c - 'A' + 10); |
|
|
1984 |
.................... |
|
|
1985 |
.................... c = s[index++];c = toupper(c); |
|
|
1986 |
.................... } |
|
|
1987 |
.................... } |
|
|
1988 |
.................... } |
|
|
1989 |
.................... |
|
|
1990 |
.................... if (base == 10 && sign == 1) |
|
|
1991 |
.................... result = -result; |
|
|
1992 |
.................... |
|
|
1993 |
.................... return(result); |
|
|
1994 |
.................... } |
|
|
1995 |
.................... |
|
|
1996 |
.................... /* A fast routine to multiply by 10 |
|
|
1997 |
.................... */ |
|
|
1998 |
.................... signed int32 mult_with10(int32 num) |
|
|
1999 |
.................... { |
|
|
2000 |
.................... return ( (num << 1) + (num << 3) ); |
|
|
2001 |
.................... } |
|
|
2002 |
.................... |
|
|
2003 |
.................... signed int32 atoi32(char *s) |
|
|
2004 |
.................... { |
|
|
2005 |
.................... signed int32 result; |
|
|
2006 |
.................... int sign, base, index; |
|
|
2007 |
.................... char c; |
|
|
2008 |
.................... |
|
|
2009 |
.................... index = 0; |
|
|
2010 |
.................... sign = 0; |
|
|
2011 |
.................... base = 10; |
|
|
2012 |
.................... result = 0; |
|
|
2013 |
.................... |
|
|
2014 |
.................... if (!s) |
|
|
2015 |
.................... return 0; |
|
|
2016 |
.................... c = s[index++]; |
|
|
2017 |
.................... |
|
|
2018 |
.................... // increase index if either positive or negative sign is detected |
|
|
2019 |
.................... if (c == '-') |
|
|
2020 |
.................... { |
|
|
2021 |
.................... sign = 1; // Set the sign to negative |
|
|
2022 |
.................... c = s[index++]; |
|
|
2023 |
.................... } |
|
|
2024 |
.................... else if (c == '+') |
|
|
2025 |
.................... { |
|
|
2026 |
.................... c = s[index++]; |
|
|
2027 |
.................... } |
|
|
2028 |
.................... |
|
|
2029 |
.................... if (c >= '0' && c <= '9') |
|
|
2030 |
.................... { |
|
|
2031 |
.................... if (c == '0' && (s[index] == 'x' || s[index] == 'X')) |
|
|
2032 |
.................... { |
|
|
2033 |
.................... base = 16; |
|
|
2034 |
.................... index++; |
|
|
2035 |
.................... c = s[index++]; |
|
|
2036 |
.................... } |
|
|
2037 |
.................... |
|
|
2038 |
.................... // The number is a decimal number |
|
|
2039 |
.................... if (base == 10) |
|
|
2040 |
.................... { |
|
|
2041 |
.................... while (c >= '0' && c <= '9') { |
|
|
2042 |
.................... result = (result << 1) + (result << 3); // result *= 10; |
|
|
2043 |
.................... result += (c - '0'); |
|
|
2044 |
.................... c = s[index++]; |
|
|
2045 |
.................... } |
|
|
2046 |
.................... } |
|
|
2047 |
.................... else if (base == 16) // The number is a hexa number |
|
|
2048 |
.................... { |
|
|
2049 |
.................... c = toupper(c); |
|
|
2050 |
.................... while ((c >= '0' && c <= '9') || (c >= 'A' && c <='F')) |
|
|
2051 |
.................... { |
|
|
2052 |
.................... if (c >= '0' && c <= '9') |
|
|
2053 |
.................... result = (result << 4) + (c - '0'); |
|
|
2054 |
.................... else |
|
|
2055 |
.................... result = (result << 4) + (c - 'A' + 10); |
|
|
2056 |
.................... |
|
|
2057 |
.................... c = s[index++];c = toupper(c); |
|
|
2058 |
.................... } |
|
|
2059 |
.................... } |
|
|
2060 |
.................... } |
|
|
2061 |
.................... |
|
|
2062 |
.................... if (base == 10 && sign == 1) |
|
|
2063 |
.................... result = -result; |
|
|
2064 |
.................... |
|
|
2065 |
.................... return(result); |
|
|
2066 |
.................... } |
|
|
2067 |
.................... |
|
|
2068 |
.................... char * itoa(signed int32 num, int8 base, char *s) |
|
|
2069 |
.................... { |
|
|
2070 |
.................... int32 temp=1; |
|
|
2071 |
.................... int8 i,sign=0,cnt=0; |
|
|
2072 |
.................... char c; |
|
|
2073 |
.................... |
|
|
2074 |
.................... if(num<0) { |
|
|
2075 |
.................... sign=1; // Check for negative number |
|
|
2076 |
.................... num*=-1; |
|
|
2077 |
.................... } |
|
|
2078 |
.................... |
|
|
2079 |
.................... while(temp>0) { |
|
|
2080 |
.................... temp=(num/base); |
|
|
2081 |
.................... s[cnt]=(num%base)+'0'; // Conversion |
|
|
2082 |
.................... |
|
|
2083 |
.................... if(s[cnt]>0x39) |
|
|
2084 |
.................... s[cnt]+=0x7; |
|
|
2085 |
.................... |
|
|
2086 |
.................... cnt++; |
|
|
2087 |
.................... num=temp; |
|
|
2088 |
.................... } |
|
|
2089 |
.................... |
|
|
2090 |
.................... if(sign==1) { |
|
|
2091 |
.................... s[cnt]=0x2D; // Negative sign |
|
|
2092 |
.................... cnt++; |
|
|
2093 |
.................... } |
|
|
2094 |
.................... |
|
|
2095 |
.................... for(i = 0;i<(int8)(cnt/2);i++) { |
|
|
2096 |
.................... |
|
|
2097 |
.................... c=s[i]; |
|
|
2098 |
.................... s[i]=s[cnt-i-1]; // Reverse the number |
|
|
2099 |
.................... s[cnt-i-1]=c; |
|
|
2100 |
.................... } |
|
|
2101 |
.................... s[cnt]='\0'; // End the string |
|
|
2102 |
.................... return s; |
|
|
2103 |
.................... } |
|
|
2104 |
.................... |
|
|
2105 |
.................... float strtod(char *s,char *endptr) { |
|
|
2106 |
.................... float pow10 = 1.0; |
|
|
2107 |
.................... float result = 0.0; |
|
|
2108 |
.................... int sign = 0, point = 0; |
|
|
2109 |
.................... char c; |
|
|
2110 |
.................... int ptr = 0; |
|
|
2111 |
.................... |
|
|
2112 |
.................... if (!s) |
|
|
2113 |
.................... return 0; |
|
|
2114 |
.................... c=s[ptr++]; |
|
|
2115 |
.................... |
|
|
2116 |
.................... |
|
|
2117 |
.................... while((c>='0' && c<='9') || c=='+' || c=='-' || c=='.') { |
|
|
2118 |
.................... if(c == '-') { |
|
|
2119 |
.................... sign = 1; |
|
|
2120 |
.................... c = s[ptr++]; |
|
|
2121 |
.................... } |
|
|
2122 |
.................... |
|
|
2123 |
.................... while((c >= '0' && c <= '9') && point == 0) { |
|
|
2124 |
.................... result = 10*result + c - '0'; |
|
|
2125 |
.................... c = s[ptr++]; |
|
|
2126 |
.................... } |
|
|
2127 |
.................... |
|
|
2128 |
.................... if (c == '.') { |
|
|
2129 |
.................... point = 1; |
|
|
2130 |
.................... c = s[ptr++]; |
|
|
2131 |
.................... } |
|
|
2132 |
.................... |
|
|
2133 |
.................... while((c >= '0' && c <= '9') && point == 1) { |
|
|
2134 |
.................... pow10 = pow10*10; |
|
|
2135 |
.................... result += (c - '0')/pow10; |
|
|
2136 |
.................... c = s[ptr++]; |
|
|
2137 |
.................... } |
|
|
2138 |
.................... |
|
|
2139 |
.................... if (c == '+') { |
|
|
2140 |
.................... c = s[ptr++]; |
|
|
2141 |
.................... } |
|
|
2142 |
.................... } |
|
|
2143 |
.................... |
|
|
2144 |
.................... if (sign == 1) |
|
|
2145 |
.................... result = -1*result; |
|
|
2146 |
.................... if(endptr) |
|
|
2147 |
.................... { |
|
|
2148 |
.................... if (ptr) { |
|
|
2149 |
.................... ptr--; |
|
|
2150 |
.................... *((char *)endptr)=s+ptr; |
|
|
2151 |
.................... } |
|
|
2152 |
.................... else |
|
|
2153 |
.................... *((char *)endptr)=s; |
|
|
2154 |
.................... } |
|
|
2155 |
.................... |
|
|
2156 |
.................... return(result); |
|
|
2157 |
.................... } |
|
|
2158 |
.................... |
|
|
2159 |
.................... long strtoul(char *s,char *endptr,signed int base) |
|
|
2160 |
.................... { |
|
|
2161 |
.................... char *sc,*s1,*sd; |
|
|
2162 |
.................... unsigned long x=0; |
|
|
2163 |
.................... char sign; |
|
|
2164 |
.................... char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; |
|
|
2165 |
.................... for(sc=s;isspace(*sc);++sc); |
|
|
2166 |
.................... sign=*sc=='-'||*sc=='+'?*sc++:'+'; |
|
|
2167 |
.................... if(sign=='-') |
|
|
2168 |
.................... { |
|
|
2169 |
.................... if (endptr) |
|
|
2170 |
.................... { |
|
|
2171 |
.................... *((char *)endptr)=s; |
|
|
2172 |
.................... } |
|
|
2173 |
.................... return 0; |
|
|
2174 |
.................... } |
|
|
2175 |
.................... |
|
|
2176 |
.................... if (base <0 || base ==1|| base >36) // invalid base |
|
|
2177 |
.................... { |
|
|
2178 |
.................... if (endptr) |
|
|
2179 |
.................... { |
|
|
2180 |
.................... *((char *)endptr)=s; |
|
|
2181 |
.................... } |
|
|
2182 |
.................... return 0; |
|
|
2183 |
.................... } |
|
|
2184 |
.................... else if (base) |
|
|
2185 |
.................... { |
|
|
2186 |
.................... if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) |
|
|
2187 |
.................... sc+=2; |
|
|
2188 |
.................... if(base==8 && *sc =='0') |
|
|
2189 |
.................... sc+=1; |
|
|
2190 |
.................... if(base==2 && *sc =='0'&&sc[1]=='b') |
|
|
2191 |
.................... sc+=2; |
|
|
2192 |
.................... |
|
|
2193 |
.................... } |
|
|
2194 |
.................... else if(*sc!='0') // base is 0, find base |
|
|
2195 |
.................... base=10; |
|
|
2196 |
.................... else if (sc[1]=='x' || sc[1]=='X') |
|
|
2197 |
.................... base =16,sc+=2; |
|
|
2198 |
.................... else if(sc[1]=='b') |
|
|
2199 |
.................... base=2,sc+=2; |
239 |
kaklik |
2200 |
.................... else |
240 |
kaklik |
2201 |
.................... base=8; |
|
|
2202 |
.................... for (s1=sc;*sc=='0';++sc);// skip leading zeroes |
|
|
2203 |
.................... sd=memchr(digits,tolower(*sc),base); |
|
|
2204 |
.................... for(; sd!=0; ) |
223 |
kapl |
2205 |
.................... { |
240 |
kaklik |
2206 |
.................... x=x*base+(int16)(sd-digits); |
|
|
2207 |
.................... ++sc; |
|
|
2208 |
.................... sd=memchr(digits,tolower(*sc),base); |
|
|
2209 |
.................... } |
|
|
2210 |
.................... if(s1==sc) |
|
|
2211 |
.................... { |
|
|
2212 |
.................... if (endptr) |
|
|
2213 |
.................... { |
|
|
2214 |
.................... *((char *)endptr)=s; |
|
|
2215 |
.................... } |
|
|
2216 |
.................... return 0; |
|
|
2217 |
.................... } |
|
|
2218 |
.................... if (endptr) |
|
|
2219 |
.................... *((char *)endptr)=sc; |
|
|
2220 |
.................... return x; |
|
|
2221 |
.................... } |
|
|
2222 |
.................... |
|
|
2223 |
.................... |
|
|
2224 |
.................... signed long strtol(char *s,char *endptr,signed int base) |
|
|
2225 |
.................... { |
|
|
2226 |
.................... char *sc,*s1,*sd; |
|
|
2227 |
.................... signed long x=0; |
|
|
2228 |
.................... char sign; |
|
|
2229 |
.................... char digits[]="0123456789abcdefghijklmnopqstuvwxyz"; |
|
|
2230 |
.................... for(sc=s;isspace(*sc);++sc); |
|
|
2231 |
.................... sign=*sc=='-'||*sc=='+'?*sc++:'+'; |
|
|
2232 |
.................... if (base <0 || base ==1|| base >36) // invalid base |
|
|
2233 |
.................... { |
|
|
2234 |
.................... if (endptr) |
|
|
2235 |
.................... { |
|
|
2236 |
.................... *((char *)endptr)=s; |
|
|
2237 |
.................... } |
|
|
2238 |
.................... return 0; |
|
|
2239 |
.................... } |
|
|
2240 |
.................... else if (base) |
|
|
2241 |
.................... { |
|
|
2242 |
.................... if(base==16 && *sc =='0'&&(sc[1]=='x' || sc[1]=='X')) |
|
|
2243 |
.................... sc+=2; |
|
|
2244 |
.................... if(base==8 && *sc =='0') |
|
|
2245 |
.................... sc+=1; |
|
|
2246 |
.................... if(base==2 && *sc =='0'&&sc[1]=='b') |
|
|
2247 |
.................... sc+=2; |
|
|
2248 |
.................... |
|
|
2249 |
.................... } |
|
|
2250 |
.................... else if(*sc!='0') // base is 0, find base |
|
|
2251 |
.................... base=10; |
|
|
2252 |
.................... else if (sc[1]=='x' || sc[1]=='X') |
|
|
2253 |
.................... base =16,sc+=2; |
|
|
2254 |
.................... else if(sc[1]=='b') |
|
|
2255 |
.................... base=2,sc+=2; |
|
|
2256 |
.................... else |
|
|
2257 |
.................... base=8; |
|
|
2258 |
.................... for (s1=sc;*sc=='0';++sc);// skip leading zeroes |
|
|
2259 |
.................... |
|
|
2260 |
.................... sd=memchr(digits,tolower(*sc),base); |
|
|
2261 |
.................... for(;sd!=0;) |
|
|
2262 |
.................... { |
|
|
2263 |
.................... x=x*base+(int16)(sd-digits); |
|
|
2264 |
.................... ++sc; |
|
|
2265 |
.................... sd=memchr(digits,tolower(*sc),base); |
|
|
2266 |
.................... } |
|
|
2267 |
.................... if(s1==sc) |
|
|
2268 |
.................... { |
|
|
2269 |
.................... if (endptr) |
|
|
2270 |
.................... { |
|
|
2271 |
.................... *((char *)endptr)=s; |
|
|
2272 |
.................... } |
|
|
2273 |
.................... return 0; |
|
|
2274 |
.................... } |
|
|
2275 |
.................... if(sign=='-') |
|
|
2276 |
.................... x =-x; |
|
|
2277 |
.................... if (endptr) |
|
|
2278 |
.................... *((char *)endptr)=sc; |
|
|
2279 |
.................... return x; |
|
|
2280 |
.................... } |
|
|
2281 |
.................... |
|
|
2282 |
.................... signed int system(char *string) |
|
|
2283 |
.................... { |
|
|
2284 |
.................... return 0; |
|
|
2285 |
.................... } |
|
|
2286 |
.................... |
|
|
2287 |
.................... int mblen(char *s,size_t n) |
|
|
2288 |
.................... { |
|
|
2289 |
.................... return strlen(s); |
|
|
2290 |
.................... } |
|
|
2291 |
.................... |
|
|
2292 |
.................... int mbtowc(wchar_t *pwc,char *s,size_t n) |
|
|
2293 |
.................... { |
|
|
2294 |
.................... *pwc=*s; |
|
|
2295 |
.................... return 1; |
|
|
2296 |
.................... } |
|
|
2297 |
.................... |
|
|
2298 |
.................... int wctomb(char *s,wchar_t wchar) |
|
|
2299 |
.................... { |
|
|
2300 |
.................... *s=wchar; |
|
|
2301 |
.................... return 1; |
|
|
2302 |
.................... } |
|
|
2303 |
.................... |
|
|
2304 |
.................... size_t mbstowcs(wchar_t *pwcs,char *s,size_t n) |
|
|
2305 |
.................... { |
|
|
2306 |
.................... strncpy(pwcs,s,n); |
|
|
2307 |
.................... return strlen(pwcs); |
|
|
2308 |
.................... } |
|
|
2309 |
.................... |
|
|
2310 |
.................... size_t wcstombs(char *s,wchar_t *pwcs,size_t n) |
|
|
2311 |
.................... { |
|
|
2312 |
.................... strncpy(s,pwcs,n); |
|
|
2313 |
.................... return strlen(s); |
|
|
2314 |
.................... } |
|
|
2315 |
.................... |
|
|
2316 |
.................... //--------------------------------------------------------------------------- |
|
|
2317 |
.................... // The random number implementation |
|
|
2318 |
.................... //--------------------------------------------------------------------------- |
|
|
2319 |
.................... |
|
|
2320 |
.................... unsigned int32 _Randseed = 1; |
|
|
2321 |
006F: MOVLW 01 |
|
|
2322 |
0070: MOVWF 22 |
|
|
2323 |
0071: CLRF 23 |
|
|
2324 |
0072: CLRF 24 |
|
|
2325 |
0073: CLRF 25 |
|
|
2326 |
.................... |
|
|
2327 |
.................... long rand(void) |
|
|
2328 |
.................... { |
|
|
2329 |
.................... _Randseed = _Randseed * 1103515245 + 12345; |
|
|
2330 |
.................... return ((unsigned long)(_Randseed >> 16) % RAND_MAX); |
|
|
2331 |
.................... } |
|
|
2332 |
.................... |
|
|
2333 |
.................... void srand(unsigned int32 seed) |
|
|
2334 |
.................... { |
|
|
2335 |
.................... _Randseed = seed; |
|
|
2336 |
.................... } |
|
|
2337 |
.................... |
|
|
2338 |
.................... //--------------------------------------------------------------------------- |
|
|
2339 |
.................... // Searching and sorting utilities implementation |
|
|
2340 |
.................... //--------------------------------------------------------------------------- |
|
|
2341 |
.................... |
|
|
2342 |
.................... typedef signed int (*_Cmpfun)(char * p1,char * p2); |
|
|
2343 |
.................... |
|
|
2344 |
.................... void qsort(char * qdata, int qitems, int qsize, _Cmpfun cmp) { |
|
|
2345 |
.................... int m,j,i,l; |
|
|
2346 |
.................... short done; |
|
|
2347 |
.................... BYTE t[16]; |
|
|
2348 |
.................... |
|
|
2349 |
.................... m = qitems/2; |
|
|
2350 |
.................... while( m > 0 ) { |
|
|
2351 |
.................... for(j=0; j<(qitems-m); ++j) { |
|
|
2352 |
.................... i = j; |
|
|
2353 |
.................... do |
|
|
2354 |
.................... { |
|
|
2355 |
.................... done=TRUE; |
|
|
2356 |
.................... l = i+m; |
|
|
2357 |
.................... if( (*cmp)(qdata+i*qsize, qdata+l*qsize) > 0 ) { |
|
|
2358 |
.................... memcpy(t, qdata+i*qsize, qsize); |
|
|
2359 |
.................... memcpy(qdata+i*qsize, qdata+l*qsize, qsize); |
|
|
2360 |
.................... memcpy(qdata+l*qsize, t, qsize); |
|
|
2361 |
.................... if(m <= i) |
|
|
2362 |
.................... i -= m; |
|
|
2363 |
.................... done = FALSE; |
|
|
2364 |
.................... } |
|
|
2365 |
.................... } while(!done); |
|
|
2366 |
.................... } |
|
|
2367 |
.................... m = m/2; |
|
|
2368 |
.................... } |
|
|
2369 |
.................... } |
|
|
2370 |
.................... |
|
|
2371 |
.................... |
|
|
2372 |
.................... char *bsearch(char *key, char *base, size_t num, size_t width,_Cmpfun cmp) |
|
|
2373 |
.................... { |
|
|
2374 |
.................... char *p, *q; |
|
|
2375 |
.................... size_t n; |
|
|
2376 |
.................... size_t pivot; |
|
|
2377 |
.................... signed int val; |
|
|
2378 |
.................... |
|
|
2379 |
.................... p = base; |
|
|
2380 |
.................... n = num; |
|
|
2381 |
.................... |
|
|
2382 |
.................... while (n > 0) |
|
|
2383 |
.................... { |
|
|
2384 |
.................... pivot = n >> 1; |
|
|
2385 |
.................... q = p + width * pivot; |
|
|
2386 |
.................... |
|
|
2387 |
.................... val = (*cmp)(key, q); |
|
|
2388 |
.................... |
|
|
2389 |
.................... if (val < 0) |
|
|
2390 |
.................... n = pivot; |
|
|
2391 |
.................... else if (val == 0) |
|
|
2392 |
.................... return ((char *)q); |
|
|
2393 |
.................... else { |
|
|
2394 |
.................... p = q + width; |
|
|
2395 |
.................... n -= pivot + 1; |
|
|
2396 |
.................... } |
|
|
2397 |
.................... } |
|
|
2398 |
.................... |
|
|
2399 |
.................... return NULL; // There's no match |
|
|
2400 |
.................... } |
|
|
2401 |
.................... |
|
|
2402 |
.................... |
|
|
2403 |
.................... #endif |
|
|
2404 |
.................... |
|
|
2405 |
.................... |
|
|
2406 |
.................... #define DELKA 40 |
|
|
2407 |
.................... |
|
|
2408 |
.................... char odp[DELKA]; |
|
|
2409 |
.................... |
|
|
2410 |
.................... int1 check_new_sms() |
|
|
2411 |
.................... { |
|
|
2412 |
.................... fprintf(MOBIL,"AT+CMGL=1\r"); //vycti prijate SMS (0=nove;1=vsechny) |
|
|
2413 |
.................... while(fgetc(MOBIL)!=0x0A); // predkoc prvni radek odpovedi |
|
|
2414 |
.................... odp[0]=fgetc(MOBIL); // Nacti prvni dva znaky druheho radku odpovedi |
|
|
2415 |
.................... odp[1]=fgetc(MOBIL); |
|
|
2416 |
.................... while(fgetc(MOBIL)!=0x0A); // Preskoc zbytek radku |
|
|
2417 |
.................... |
|
|
2418 |
.................... if(odp[0] == 'O' && odp[1] == 'K') return 1; |
|
|
2419 |
.................... else return 0; |
|
|
2420 |
.................... } |
|
|
2421 |
.................... |
|
|
2422 |
.................... read_sms() |
|
|
2423 |
.................... { |
|
|
2424 |
.................... int pom,pom2,pom3,odkl,odkl2,maskovadlo; |
238 |
kaklik |
2425 |
.................... for(pom=0;pom<54;pom++) //preskoc nedulezite informace |
223 |
kapl |
2426 |
.................... { |
238 |
kaklik |
2427 |
.................... fgetc(MOBIL); |
239 |
kaklik |
2428 |
.................... } |
|
|
2429 |
.................... |
223 |
kapl |
2430 |
.................... //gets(odp); //uloz zakodovany text SMS |
239 |
kaklik |
2431 |
.................... |
238 |
kaklik |
2432 |
.................... odp[0]=fgetc(MOBIL); |
|
|
2433 |
.................... odp[1]=fgetc(MOBIL); |
|
|
2434 |
.................... odp[2]=fgetc(MOBIL); |
|
|
2435 |
.................... odp[3]=fgetc(MOBIL); |
|
|
2436 |
.................... odp[4]=fgetc(MOBIL); |
|
|
2437 |
.................... odp[5]=fgetc(MOBIL); |
|
|
2438 |
.................... odp[6]=fgetc(MOBIL); |
|
|
2439 |
.................... odp[7]=fgetc(MOBIL); |
|
|
2440 |
.................... |
223 |
kapl |
2441 |
.................... /*lcd_gotoxy(1,1); |
|
|
2442 |
.................... printf(lcd_putc,"\f%s\n",odp);*/ |
239 |
kaklik |
2443 |
.................... |
|
|
2444 |
.................... if(odp[0]==0) odp[1]='0'; // Prevod z ASCII do BIN |
223 |
kapl |
2445 |
.................... odp[0]=odp[0] - '0'; |
|
|
2446 |
.................... odp[1]=odp[1] - '0'; |
|
|
2447 |
.................... if(odp[0]>9) odp[0]=odp[0]-7; |
|
|
2448 |
.................... if(odp[1]>9) odp[1]=odp[1]-7; |
|
|
2449 |
.................... odp[0]=odp[0] << 4; |
|
|
2450 |
.................... odp[0] |= odp[1]; |
239 |
kaklik |
2451 |
.................... |
223 |
kapl |
2452 |
.................... if(odp[2]==0) odp[3]='0'; |
|
|
2453 |
.................... odp[2]=odp[2] - '0'; |
|
|
2454 |
.................... odp[3]=odp[3] - '0'; |
|
|
2455 |
.................... if(odp[2]>9) odp[2]=odp[2]-7; |
|
|
2456 |
.................... if(odp[3]>9) odp[3]=odp[3]-7; |
|
|
2457 |
.................... odp[2]=odp[2] << 4; |
|
|
2458 |
.................... odp[2] |= odp[3]; |
239 |
kaklik |
2459 |
.................... |
223 |
kapl |
2460 |
.................... if(odp[4]==0) odp[5]='0'; |
|
|
2461 |
.................... odp[4]=odp[4] - '0'; |
|
|
2462 |
.................... odp[5]=odp[5] - '0'; |
|
|
2463 |
.................... if(odp[4]>9) odp[4]=odp[4]-7; |
|
|
2464 |
.................... if(odp[5]>9) odp[5]=odp[5]-7; |
|
|
2465 |
.................... odp[4]=odp[4] << 4; |
|
|
2466 |
.................... odp[4] |= odp[5]; |
239 |
kaklik |
2467 |
.................... |
223 |
kapl |
2468 |
.................... if(odp[6]==0) odp[7]='0'; |
|
|
2469 |
.................... odp[6]=odp[6] - '0'; |
|
|
2470 |
.................... odp[7]=odp[7] - '0'; |
|
|
2471 |
.................... if(odp[6]>9) odp[6]=odp[6]-7; |
|
|
2472 |
.................... if(odp[7]>9) odp[7]=odp[7]-7; |
|
|
2473 |
.................... odp[6]=odp[6] << 4; |
|
|
2474 |
.................... odp[6] |= odp[7]; |
|
|
2475 |
.................... |
|
|
2476 |
.................... odp[1]=odp[2]; |
|
|
2477 |
.................... odp[2]=odp[4]; |
|
|
2478 |
.................... odp[3]=odp[6]; |
239 |
kaklik |
2479 |
.................... odp[4]=odp[5]=odp[6]=0; |
|
|
2480 |
.................... |
|
|
2481 |
.................... /*lcd_gotoxy(1,2); |
223 |
kapl |
2482 |
.................... printf(lcd_putc,"%u %u %u %u",odp[0],odp[1],odp[2]odp[3]); */ |
239 |
kaklik |
2483 |
.................... |
223 |
kapl |
2484 |
.................... pom3=0; |
239 |
kaklik |
2485 |
.................... for (pom = 0; pom < 4;pom++) |
223 |
kapl |
2486 |
.................... { |
|
|
2487 |
.................... maskovadlo = maskovadlo >> 1; //rotace promene urcene pro maskovani |
|
|
2488 |
.................... maskovadlo = maskovadlo | 0x80; |
|
|
2489 |
.................... odkl = odp[pom] & maskovadlo; //odlozeni "prenosu" do odkl pomoci maskovadla |
|
|
2490 |
.................... odp[pom] = odp[pom] << pom3; //rotace znaku |
|
|
2491 |
.................... for (pom2 = 0; pom2 < (8-pom3);pom2++) //rotace odkl2 |
|
|
2492 |
.................... { |
|
|
2493 |
.................... odkl2 = odkl2 >> 1; |
239 |
kaklik |
2494 |
.................... odkl2 = odkl2 & 127; |
223 |
kapl |
2495 |
.................... } |
|
|
2496 |
.................... odp[pom] = odp[pom] | odkl2; //pridani odkl2 ke znaku |
|
|
2497 |
.................... odp[pom] = odp[pom] & 127; //smazani nejvysiho bitu |
|
|
2498 |
.................... odkl2 = odkl; //ulozeni odlk na dalsi pruchod |
|
|
2499 |
.................... pom3++; //inkrementace citace rotace |
|
|
2500 |
.................... if (pom3 == 8) //kazdy 8my znak |
|
|
2501 |
.................... { |
|
|
2502 |
.................... pom3 = 0; //smaz citac |
|
|
2503 |
.................... odp[pom+1] = odkl2; //uloz 8my znak vznikly z "prenosu" |
|
|
2504 |
.................... maskovadlo = 0; //smaz maskovadlo |
|
|
2505 |
.................... } |
|
|
2506 |
.................... } |
239 |
kaklik |
2507 |
.................... odp[pom]='\0'; |
240 |
kaklik |
2508 |
.................... } |
239 |
kaklik |
2509 |
.................... |
240 |
kaklik |
2510 |
.................... void read_time() |
|
|
2511 |
.................... { |
|
|
2512 |
.................... unsigned int8 n; |
238 |
kaklik |
2513 |
.................... |
239 |
kaklik |
2514 |
.................... |
240 |
kaklik |
2515 |
.................... fprintf(MOBIL,"AT+CCLK?\r"); |
|
|
2516 |
.................... while(fgetc(MOBIL)!='"'); |
|
|
2517 |
.................... for(n=0;n<12;n++) //preskoc nedulezite informace |
|
|
2518 |
.................... { |
|
|
2519 |
.................... fgetc(MOBIL); |
|
|
2520 |
.................... } |
|
|
2521 |
.................... odp[0]=fgetc(MOBIL); |
|
|
2522 |
.................... odp[1]=fgetc(MOBIL); |
|
|
2523 |
.................... odp[2]=0; |
|
|
2524 |
.................... } |
239 |
kaklik |
2525 |
.................... |
240 |
kaklik |
2526 |
.................... void del_sms() |
|
|
2527 |
.................... { |
|
|
2528 |
.................... fprintf(MOBIL,"AT+CMGD=1\r"); //smaz prijatou SMSku |
|
|
2529 |
.................... } |
239 |
kaklik |
2530 |
.................... |
240 |
kaklik |
2531 |
.................... void main() |
|
|
2532 |
.................... { |
|
|
2533 |
* |
|
|
2534 |
0057: CLRF 04 |
|
|
2535 |
0058: MOVLW 1F |
|
|
2536 |
0059: ANDWF 03,F |
|
|
2537 |
005A: BCF 20.6 |
|
|
2538 |
005B: MOVF 20,W |
|
|
2539 |
005C: BSF 03.5 |
|
|
2540 |
005D: MOVWF 07 |
|
|
2541 |
005E: BCF 03.5 |
|
|
2542 |
005F: BSF 07.6 |
|
|
2543 |
0060: BSF 03.5 |
|
|
2544 |
0061: BCF 06.2 |
|
|
2545 |
0062: BCF 03.5 |
|
|
2546 |
0063: BSF 06.2 |
|
|
2547 |
0064: BSF 03.5 |
|
|
2548 |
0065: BSF 1F.0 |
|
|
2549 |
0066: BSF 1F.1 |
|
|
2550 |
0067: BSF 1F.2 |
|
|
2551 |
0068: BCF 1F.3 |
|
|
2552 |
0069: MOVLW 07 |
|
|
2553 |
006A: MOVWF 1C |
|
|
2554 |
.................... setup_adc_ports(NO_ANALOGS); |
|
|
2555 |
* |
|
|
2556 |
0074: BSF 03.5 |
|
|
2557 |
0075: BSF 1F.0 |
|
|
2558 |
0076: BSF 1F.1 |
|
|
2559 |
0077: BSF 1F.2 |
|
|
2560 |
0078: BCF 1F.3 |
|
|
2561 |
.................... setup_adc(ADC_OFF); |
|
|
2562 |
0079: BCF 03.5 |
|
|
2563 |
007A: BCF 1F.0 |
|
|
2564 |
.................... setup_spi(SPI_SS_DISABLED); |
|
|
2565 |
007B: BCF 14.5 |
|
|
2566 |
007C: BCF 20.5 |
|
|
2567 |
007D: MOVF 20,W |
|
|
2568 |
007E: BSF 03.5 |
|
|
2569 |
007F: MOVWF 07 |
|
|
2570 |
0080: BCF 03.5 |
|
|
2571 |
0081: BSF 20.4 |
|
|
2572 |
0082: MOVF 20,W |
|
|
2573 |
0083: BSF 03.5 |
|
|
2574 |
0084: MOVWF 07 |
|
|
2575 |
0085: BCF 03.5 |
|
|
2576 |
0086: BCF 20.3 |
|
|
2577 |
0087: MOVF 20,W |
|
|
2578 |
0088: BSF 03.5 |
|
|
2579 |
0089: MOVWF 07 |
|
|
2580 |
008A: MOVLW 01 |
|
|
2581 |
008B: BCF 03.5 |
|
|
2582 |
008C: MOVWF 14 |
|
|
2583 |
008D: MOVLW 00 |
|
|
2584 |
008E: BSF 03.5 |
|
|
2585 |
008F: MOVWF 14 |
|
|
2586 |
.................... setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
2587 |
0090: MOVF 01,W |
|
|
2588 |
0091: ANDLW C7 |
|
|
2589 |
0092: IORLW 08 |
|
|
2590 |
0093: MOVWF 01 |
|
|
2591 |
.................... setup_timer_1(T1_DISABLED); |
|
|
2592 |
0094: BCF 03.5 |
|
|
2593 |
0095: CLRF 10 |
|
|
2594 |
.................... setup_timer_2(T2_DIV_BY_4,255,1); |
|
|
2595 |
0096: MOVLW 00 |
|
|
2596 |
0097: MOVWF 78 |
|
|
2597 |
0098: IORLW 05 |
|
|
2598 |
0099: MOVWF 12 |
|
|
2599 |
009A: MOVLW FF |
|
|
2600 |
009B: BSF 03.5 |
|
|
2601 |
009C: MOVWF 12 |
|
|
2602 |
.................... setup_ccp1(CCP_PWM); |
|
|
2603 |
009D: BCF 03.5 |
|
|
2604 |
009E: BCF 20.2 |
|
|
2605 |
009F: MOVF 20,W |
|
|
2606 |
00A0: BSF 03.5 |
|
|
2607 |
00A1: MOVWF 07 |
|
|
2608 |
00A2: BCF 03.5 |
|
|
2609 |
00A3: BCF 07.2 |
|
|
2610 |
00A4: MOVLW 0C |
|
|
2611 |
00A5: MOVWF 17 |
|
|
2612 |
.................... setup_ccp2(CCP_PWM); |
|
|
2613 |
00A6: BCF 20.1 |
|
|
2614 |
00A7: MOVF 20,W |
|
|
2615 |
00A8: BSF 03.5 |
|
|
2616 |
00A9: MOVWF 07 |
|
|
2617 |
00AA: BCF 03.5 |
|
|
2618 |
00AB: BCF 07.1 |
|
|
2619 |
00AC: MOVLW 0C |
|
|
2620 |
00AD: MOVWF 1D |
|
|
2621 |
.................... setup_comparator(NC_NC_NC_NC); |
|
|
2622 |
00AE: MOVLW 07 |
|
|
2623 |
00AF: BSF 03.5 |
|
|
2624 |
00B0: MOVWF 1C |
|
|
2625 |
00B1: MOVF 05,W |
|
|
2626 |
00B2: CLRWDT |
|
|
2627 |
00B3: MOVLW 0E |
|
|
2628 |
00B4: MOVWF 77 |
|
|
2629 |
00B5: DECFSZ 77,F |
|
|
2630 |
00B6: GOTO 0B5 |
|
|
2631 |
00B7: NOP |
|
|
2632 |
00B8: NOP |
|
|
2633 |
00B9: MOVF 1C,W |
|
|
2634 |
00BA: BCF 03.5 |
|
|
2635 |
00BB: BCF 0D.6 |
|
|
2636 |
.................... setup_vref(FALSE); |
|
|
2637 |
00BC: BSF 03.5 |
|
|
2638 |
00BD: CLRF 1D |
|
|
2639 |
.................... setup_wdt(WDT_2304MS); |
|
|
2640 |
00BE: MOVLW 0F |
|
|
2641 |
00BF: MOVWF 77 |
|
|
2642 |
00C0: MOVLW 07 |
|
|
2643 |
00C1: BCF 03.5 |
|
|
2644 |
00C2: CLRF 01 |
|
|
2645 |
00C3: MOVLW 81 |
|
|
2646 |
00C4: MOVWF 04 |
|
|
2647 |
00C5: MOVF 00,W |
|
|
2648 |
00C6: ANDLW F0 |
|
|
2649 |
00C7: IORLW 07 |
|
|
2650 |
00C8: MOVWF 00 |
|
|
2651 |
00C9: CLRWDT |
|
|
2652 |
00CA: MOVF 00,W |
|
|
2653 |
00CB: ANDLW F7 |
|
|
2654 |
00CC: BTFSC 77.3 |
|
|
2655 |
00CD: ANDLW F0 |
|
|
2656 |
00CE: IORWF 77,W |
|
|
2657 |
00CF: MOVWF 00 |
239 |
kaklik |
2658 |
.................... |
240 |
kaklik |
2659 |
.................... set_pwm1_duty(0); |
|
|
2660 |
00D0: CLRF 15 |
|
|
2661 |
.................... set_pwm2_duty(0); |
|
|
2662 |
00D1: CLRF 1B |
239 |
kaklik |
2663 |
.................... |
240 |
kaklik |
2664 |
.................... while(TRUE) |
|
|
2665 |
.................... { |
|
|
2666 |
.................... int status; |
|
|
2667 |
.................... char *ptr; |
|
|
2668 |
.................... int time; |
238 |
kaklik |
2669 |
.................... |
240 |
kaklik |
2670 |
.................... restart_wdt(); |
|
|
2671 |
00D2: CLRWDT |
239 |
kaklik |
2672 |
.................... |
240 |
kaklik |
2673 |
.................... output_low(PIN_A4) ; |
|
|
2674 |
00D3: BSF 03.5 |
|
|
2675 |
00D4: BCF 05.4 |
|
|
2676 |
00D5: BCF 03.5 |
|
|
2677 |
00D6: BCF 05.4 |
|
|
2678 |
.................... delay_ms(150); |
|
|
2679 |
00D7: MOVLW 96 |
|
|
2680 |
00D8: MOVWF 52 |
|
|
2681 |
00D9: CALL 013 |
|
|
2682 |
.................... output_high(PIN_A4); |
|
|
2683 |
00DA: BSF 03.5 |
|
|
2684 |
00DB: BCF 05.4 |
|
|
2685 |
00DC: BCF 03.5 |
|
|
2686 |
00DD: BSF 05.4 |
|
|
2687 |
.................... delay_ms(150); |
|
|
2688 |
00DE: MOVLW 96 |
|
|
2689 |
00DF: MOVWF 52 |
|
|
2690 |
00E0: CALL 013 |
|
|
2691 |
.................... output_low(PIN_A4) ; |
|
|
2692 |
00E1: BSF 03.5 |
|
|
2693 |
00E2: BCF 05.4 |
|
|
2694 |
00E3: BCF 03.5 |
|
|
2695 |
00E4: BCF 05.4 |
|
|
2696 |
.................... delay_ms(150); |
|
|
2697 |
00E5: MOVLW 96 |
|
|
2698 |
00E6: MOVWF 52 |
|
|
2699 |
00E7: CALL 013 |
|
|
2700 |
.................... output_high(PIN_A4); |
|
|
2701 |
00E8: BSF 03.5 |
|
|
2702 |
00E9: BCF 05.4 |
|
|
2703 |
00EA: BCF 03.5 |
|
|
2704 |
00EB: BSF 05.4 |
|
|
2705 |
.................... delay_ms(150); |
|
|
2706 |
00EC: MOVLW 96 |
|
|
2707 |
00ED: MOVWF 52 |
|
|
2708 |
00EE: CALL 013 |
238 |
kaklik |
2709 |
.................... |
|
|
2710 |
.................... |
240 |
kaklik |
2711 |
.................... set_pwm1_duty(500); |
|
|
2712 |
00EF: MOVLW 7D |
|
|
2713 |
00F0: MOVWF 15 |
|
|
2714 |
00F1: MOVF 17,W |
|
|
2715 |
00F2: ANDLW CF |
|
|
2716 |
00F3: MOVWF 17 |
|
|
2717 |
.................... set_pwm2_duty(500); |
|
|
2718 |
00F4: MOVLW 7D |
|
|
2719 |
00F5: MOVWF 1B |
|
|
2720 |
00F6: MOVF 1D,W |
|
|
2721 |
00F7: ANDLW CF |
|
|
2722 |
00F8: MOVWF 1D |
239 |
kaklik |
2723 |
.................... |
240 |
kaklik |
2724 |
.................... fprintf(VRTULE,"ABABABABAB"); |
|
|
2725 |
00F9: CLRF 51 |
|
|
2726 |
00FA: MOVF 51,W |
|
|
2727 |
00FB: CALL 004 |
|
|
2728 |
00FC: IORLW 00 |
|
|
2729 |
00FD: BTFSC 03.2 |
|
|
2730 |
00FE: GOTO 103 |
|
|
2731 |
00FF: INCF 51,F |
|
|
2732 |
0100: MOVWF 52 |
|
|
2733 |
0101: GOTO 029 |
|
|
2734 |
0102: GOTO 0FA |
|
|
2735 |
.................... |
|
|
2736 |
.................... Delay_ms(5000); |
|
|
2737 |
0103: MOVLW 14 |
|
|
2738 |
0104: MOVWF 51 |
|
|
2739 |
0105: MOVLW FA |
|
|
2740 |
0106: MOVWF 52 |
|
|
2741 |
0107: CALL 013 |
|
|
2742 |
0108: DECFSZ 51,F |
|
|
2743 |
0109: GOTO 105 |
|
|
2744 |
.................... |
|
|
2745 |
.................... |
|
|
2746 |
.................... /* if(check_new_sms()) // Je odpoved "OK"? |
|
|
2747 |
.................... { |
|
|
2748 |
.................... // printf(lcd_putc,"736 655 250"); |
|
|
2749 |
.................... delay_ms(1000); |
|
|
2750 |
.................... } |
|
|
2751 |
.................... else |
|
|
2752 |
.................... { |
|
|
2753 |
.................... read_sms(); |
|
|
2754 |
.................... |
|
|
2755 |
.................... if (odp[0] == 'A' || odp[0] == 'a') |
|
|
2756 |
.................... { |
|
|
2757 |
.................... set_pwm1_duty(500); |
|
|
2758 |
.................... set_pwm2_duty(500); |
|
|
2759 |
.................... Delay_ms(5000); |
|
|
2760 |
.................... fprintf(VRTULE,"ABABABABAB"); |
|
|
2761 |
.................... Delay_ms(20000); |
|
|
2762 |
.................... set_pwm1_duty(0); |
|
|
2763 |
.................... set_pwm2_duty(0); |
|
|
2764 |
.................... } |
|
|
2765 |
.................... |
|
|
2766 |
.................... if (odp[0] == 118 && odp[1] == 121 && odp[2] == 112 && odp[3]== 49) |
223 |
kapl |
2767 |
.................... { |
240 |
kaklik |
2768 |
.................... fprintf(VRTULE,""); |
223 |
kapl |
2769 |
.................... } |
239 |
kaklik |
2770 |
.................... |
240 |
kaklik |
2771 |
.................... if (odp[0] == 97 && odp[1] == 104 && odp[2] == 111 && odp[3]== 106) |
223 |
kapl |
2772 |
.................... { |
240 |
kaklik |
2773 |
.................... fprintf(VRTULE,""); |
223 |
kapl |
2774 |
.................... } |
240 |
kaklik |
2775 |
.................... } |
|
|
2776 |
.................... /* read_time(); |
|
|
2777 |
.................... time=strtoul(odp,&ptr,10); |
|
|
2778 |
.................... if((time >= 30 && time <= 35) || (time >= 0 && time <= 5)) |
238 |
kaklik |
2779 |
.................... { |
240 |
kaklik |
2780 |
.................... set_pwm1_duty(500); |
|
|
2781 |
.................... set_pwm2_duty(500); |
|
|
2782 |
.................... } |
|
|
2783 |
.................... else |
|
|
2784 |
.................... { |
|
|
2785 |
.................... set_pwm1_duty(0); |
|
|
2786 |
.................... set_pwm2_duty(0); |
|
|
2787 |
.................... }*/ |
223 |
kapl |
2788 |
.................... |
238 |
kaklik |
2789 |
.................... delay_ms(1000); |
240 |
kaklik |
2790 |
010A: MOVLW 04 |
|
|
2791 |
010B: MOVWF 51 |
|
|
2792 |
010C: MOVLW FA |
|
|
2793 |
010D: MOVWF 52 |
|
|
2794 |
010E: CALL 013 |
|
|
2795 |
010F: DECFSZ 51,F |
|
|
2796 |
0110: GOTO 10C |
223 |
kapl |
2797 |
.................... } |
240 |
kaklik |
2798 |
0111: GOTO 0D2 |
223 |
kapl |
2799 |
.................... } |
240 |
kaklik |
2800 |
0112: SLEEP |
223 |
kapl |
2801 |
|
|
|
2802 |
Configuration Fuses: |
238 |
kaklik |
2803 |
Word 1: 3F3A HS NOWDT NOPUT NODEBUG NOPROTECT NOBROWNOUT NOLVP NOCPD NOWRT |