annotate src/gpf/misc/tools.c @ 196:5f3544fc0308

AT@SPENH brought over from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 May 2020 19:46:18 +0000
parents 8b2a9a374324
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 | File: tools.c
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 | Copyright 2002 Texas Instruments Berlin, AG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 | All rights reserved.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 | This file is confidential and a trade secret of Texas
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 | Instruments Berlin, AG
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 | The receipt of or possession of this file does not convey
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 | any rights to reproduce or disclose its contents or to
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 | manufacture, use, or sell anything it may describe, in
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 | whole, or in part, without the specific written consent of
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 | Texas Instruments Berlin, AG.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 +-----------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 | Purpose : This module implements some format conversion functions.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 +-----------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 #ifndef __TOOLS_C__
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 #define __TOOLS_C__
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 /*==== INCLUDES ===================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 #include "typedefs.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 #include <string.h>
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 #include <ctype.h>
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 #include "vsi.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 #include "tools.h"
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 /*==== TYPES ======================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 /*==== CONSTANTS ==================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 /*==== EXTERNALS ==================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 /*==== VARIABLES ==================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /*==== FUNCTIONS ==================================================*/
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 #ifndef RUN_INT_RAM
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 | Function : GetNextToken
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 | Description : Exract text until next separator.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 | Parameters : source - where to search
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 | token - destination for text
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 | seperator - sperator
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 | Return : string length of token
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 unsigned int GetNextToken (char *source, char *token, char const *seperators)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 unsigned int i, j, k, sep_len, src_len;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 BOOL sepFound = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 sep_len = strlen (seperators);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 src_len = strlen (source);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 i = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 j = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 k = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 do
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 j = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 sepFound = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 while (j < sep_len)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 if (source[i] EQ seperators[j])
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 sepFound = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 j++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 if (sepFound)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 i++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 while (i < src_len AND sepFound);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 sepFound = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 while (!sepFound AND i < src_len)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 j = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 while (!sepFound AND j < sep_len)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (source[i] EQ seperators[j])
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 sepFound = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 j++;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 if (!sepFound)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 token[k++] = source[i++];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 token[k] = '\0';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 return strlen (token);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 #ifndef RUN_FLASH
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 | Function : HexToASCII
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 | Description : Convert hexadecimal value to ASCII string.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 | Parameters : value - value to be converted
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 | *ptr - destination for string
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 | num - number of characters
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 | Return : pointer behind the end of string
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 char *HexToASCII (ULONG value, char *ptr, int num)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 UBYTE i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 char v;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 ptr += (num-1);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 for (i=0; i<num ;i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 v = (char)(value & 0x000000f);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 value >>= 4;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 if (v > 9)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 v += ('A'-10);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 v += '0';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 *ptr-- = v;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 return(ptr+num+1);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 #ifndef RUN_INT_RAM
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 | Function : ASCIIToHex
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 | Description : Convert ASCII string to hexadecimal value.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 | Parameters : *ptr - string to be converted
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 | num - number of characters
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 | Return : value
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 unsigned int ASCIIToHex (char *ptr, int num)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 unsigned int i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 unsigned int result = 0;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 unsigned int len;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 char c;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 len = strlen(ptr);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 if ( len < (unsigned int)num )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 num = (int)len;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 ptr += (num-1);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 for (i=0; i < (unsigned int)num; i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 if (isxdigit (*ptr) )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 if (*ptr > '9')
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 c = *ptr-- - 'A' + 10;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 c = *ptr-- - '0';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 /*lint -e701 suppress Info -- shift left of signed quantity */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 result += (c << (i*4));
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 /*lint +e701 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 return result;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 #ifndef RUN_FLASH
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 | Function : InsertString
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 | Description : write a string into the buffer. If the string has less than
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 | 'num' characters, spaces are added.
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 | Parameters : *string - string to be written
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 | *ptr - pointer to destination
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 | num - number of characters to be filled
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 | Return : pointer to next character
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 char *InsertString (char *string, char *ptr, int num)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 UBYTE i;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 BYTE end_detected = FALSE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 for (i=0;i<num;i++)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 if (end_detected)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 *ptr++ = ' ';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 if (string [i] == 0)
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 end_detected = TRUE;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 *ptr++ = ' ';
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 else
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 *ptr++ = string [i];
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 return(ptr);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 #endif
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 #ifndef RUN_INT_RAM
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238 | Function : rm_path
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 | Description : remove path name from file name
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 | Parameters : *file - file name
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 | Return : file name without path information
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245 |
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 +------------------------------------------------------------------------------
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 char *rm_path ( const char *file )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 {
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 char *end;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 /*
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 * to avoid crashes in case the passed parameter file is a pointer to
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 * anywhere it is checked if file begins with a character that is allowed
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 * at the beginning of file/path names (any alpanumeric character, '.', '/',
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 * and '\')
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 */
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 if ( isalpha(*file) == 0 && *file != '.' && *file != '/' && *file != '\\' )
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 return ((char*)"NO VALID FILENAME");
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 end = (char*)file + strlen(file);
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 while ((*end != 0x2f) && (*end != 0x5c) && (end >= (char*)file))
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 end--;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 return end + 1;
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 }
8b2a9a374324 src/gpf: addition of Magnetite src/gpf2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268 #endif