1 ' INFO_1: Converter for STANDARD.MAC to MACRO.C
3 ' INFO_2: Written by Mark Junker in 1997
4 ' InterNet: mjs@prg.hannover.sgh-net.de
5 ' FIDO: Mark Junker@2:2437/47.21
7 ' COMMENT: To start the program press SHIFT+F5 within the QBasic IDE
8 ' or start it from the command-line with QBASIC /RUN MACROS
13 DECLARE FUNCTION StrTrimLeft$
(a
$, b
$)
14 DECLARE FUNCTION StrTrimRight$
(a
$, b
$)
15 DECLARE FUNCTION StrTrim$
(a
$, b
$)
16 DECLARE SUB StrSplitString (SplitString
$, SplitChars
$, SplitField
$(), SplitCount
%)
17 DECLARE FUNCTION Min
% (a
%, b
%)
18 DECLARE FUNCTION StrInstrLeft
% (SearchStart
%, SearchIn
$, SearchFor
$)
19 DECLARE FUNCTION StrAscii
% (a
$)
25 OPEN
"I", 1, "STANDARD.MAC"
26 OPEN
"O", 2, "macros.c"
28 PRINT #
2, "/* This file auto-generated from standard.mac by macros.bas - don't edit it */"
30 PRINT #
2, "static char *stdmac[] = {"
34 CALL StrSplitString(l
$, ";", LineData
$(), SplitCount
)
36 LineData
$(1) = StrTrim
$(LineData$(1), CHR
$(9) + " ")
37 IF LEN(LineData
$(1)) THEN
38 PRINT #
2, " " + CHR
$(34) + LineData
$(1) + CHR
$(34) + ","
49 FUNCTION Min
% (a
%, b
%)
50 IF a
% < b
% THEN Min
% = a
% ELSE Min
% = b
%
53 FUNCTION StrAscii (a
$)
61 ' same as =INSTR(SearchStart, SearchIn, ANY SearchFor$) in PowerBASIC(tm)
63 FUNCTION StrInstrLeft (SearchStart
, SearchIn
$, SearchFor
$)
64 ValuesCount
= LEN(SearchFor
$)
65 MaxValue
= LEN(SearchIn
$) + 1
67 FOR Counter1
= 1 TO ValuesCount
68 SearchChar$
= MID$(SearchFor$, Counter1
, 1)
69 hVal2
= INSTR(SearchStart
, SearchIn
$, SearchChar
$)
70 IF hVal2
> 0 THEN MinValue
= Min
%(hVal2
, MinValue
)
72 IF MinValue
= MaxValue
THEN MinValue
= 0
73 StrInstrLeft
= MinValue
77 ' This is a very damn fuckin' shit version of this splitting routine.
78 ' At this time, it's not very useful :]
80 SUB StrSplitString (SplitString
$, SplitChars
$, SplitField
$(), SplitCount
)
81 StartIndex
= LBOUND(SplitField
$)
82 LastIndex
= UBOUND(SplitField
$)
83 ActualIndex
& = StartIndex
87 FoundPos
= StrInstrLeft(LastPos
, SplitString
$, SplitChars$
+ CHR
$(34))
92 FoundCharVal
= StrAscii(MID$(SplitString$, FoundPos
, 1))
93 PosDiff
= (FoundPos
- LastPos
) + 1
94 SELECT CASE FoundCharVal
96 TempString$
= TempString$
+ MID$(SplitString$, LastPos
, PosDiff
- 1)
104 TempString$
= TempString$
+ MID$(SplitString$, LastPos
, PosDiff
- 1)
105 SplitField
$(ActualIndex&) = TempString$
107 ActualIndex
& = ActualIndex
& + 1
108 IF ActualIndex
& > LastIndex
THEN
109 ActualIndex
& = LastIndex
116 LastPos
= FoundPos
+ 1
117 FoundPos
= StrInstrLeft(LastPos
, SplitString
$, SplitChars
$)
118 LOOP WHILE LastPos
= FoundPos
119 FoundPos
= StrInstrLeft(LastPos
, SplitString
$, SplitChars$
+ CHR
$(34))
122 LastPos
= LEN(SplitString
$) + 1
125 LastPos
= FoundPos
+ 1
126 FoundPos
= StrInstrLeft(LastPos
, SplitString
$, CHR
$(34))
128 SplitString$
= SplitString$
+ CHR
$(34)
129 FoundPos
= LEN(SplitString
$)
134 IF LEN(TempString
$) > 0 THEN
135 SplitField
$(ActualIndex&) = TempString$
136 ELSEIF LastPos
<= LEN(SplitString
$) THEN
137 SplitField
$(ActualIndex&) = MID$(SplitString$, LastPos
)
139 ActualIndex
& = ActualIndex
& - 1
142 FOR a
= ActualIndex
& + 1 TO LastIndex
145 SplitCount
= (ActualIndex
& - StartIndex
) + 1
148 FUNCTION StrTrim$
(a
$, b
$)
149 StrTrim$
= StrTrimRight
$(StrTrimLeft$(a$, b
$), b
$)
152 FUNCTION StrTrimLeft$
(a
$, b
$) 'public
158 LOOP WHILE (p
< l
) AND (INSTR(b
$, t
$) > 0)
159 StrTrimLeft$
= MID$(a$, p
)
162 FUNCTION StrTrimRight$
(a
$, b
$) 'public
172 LOOP WHILE (p
> 0) AND (INSTR(b
$, t
$) > 0)
173 StrTrimRight$
= LEFT
$(a$, p
)