NASM 0.97
[nasm/avx512.git] / macros.bas
blob89ba846bdbde26c70cff7875b5dbb263dfce0f25
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
11 DEFINT A-Z
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$)
22 CLS
23 DIM LineData$(1 TO 2)
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 */"
29 PRINT #2, ""
30 PRINT #2, "static char *stdmac[] = {"
32 WHILE NOT EOF(1)
33 LINE INPUT #1, l$
34 CALL StrSplitString(l$, ";", LineData$(), SplitCount)
35 IF SplitCount THEN
36 LineData$(1) = StrTrim$(LineData$(1), CHR$(9) + " ")
37 IF LEN(LineData$(1)) THEN
38 PRINT #2, " " + CHR$(34) + LineData$(1) + CHR$(34) + ","
39 END IF
40 END IF
41 WEND
42 PRINT #2, " NULL"
43 PRINT #2, "};"
45 CLOSE 2
46 CLOSE 1
47 SYSTEM
49 FUNCTION Min% (a%, b%)
50 IF a% < b% THEN Min% = a% ELSE Min% = b%
51 END FUNCTION
53 FUNCTION StrAscii (a$)
54 IF LEN(a$) = 0 THEN
55 StrAscii = -1
56 ELSE
57 StrAscii = ASC(a$)
58 END IF
59 END FUNCTION
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
66 MinValue = MaxValue
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)
71 NEXT
72 IF MinValue = MaxValue THEN MinValue = 0
73 StrInstrLeft = MinValue
74 END FUNCTION
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
84 SplitCount = 0
86 LastPos = 1
87 FoundPos = StrInstrLeft(LastPos, SplitString$, SplitChars$ + CHR$(34))
88 GetDirect = 0
89 EndLoop = 0
90 TempString$ = ""
91 DO WHILE FoundPos > 0
92 FoundCharVal = StrAscii(MID$(SplitString$, FoundPos, 1))
93 PosDiff = (FoundPos - LastPos) + 1
94 SELECT CASE FoundCharVal
95 CASE 34
96 TempString$ = TempString$ + MID$(SplitString$, LastPos, PosDiff - 1)
97 SELECT CASE EndLoop
98 CASE 0
99 EndLoop = 2
100 CASE 3
101 EndLoop = 0
102 END SELECT
103 CASE ELSE
104 TempString$ = TempString$ + MID$(SplitString$, LastPos, PosDiff - 1)
105 SplitField$(ActualIndex&) = TempString$
106 TempString$ = ""
107 ActualIndex& = ActualIndex& + 1
108 IF ActualIndex& > LastIndex THEN
109 ActualIndex& = LastIndex
110 EndLoop = 1
111 END IF
112 END SELECT
113 SELECT CASE EndLoop
114 CASE 0
116 LastPos = FoundPos + 1
117 FoundPos = StrInstrLeft(LastPos, SplitString$, SplitChars$)
118 LOOP WHILE LastPos = FoundPos
119 FoundPos = StrInstrLeft(LastPos, SplitString$, SplitChars$ + CHR$(34))
120 CASE 1
121 FoundPos = 0
122 LastPos = LEN(SplitString$) + 1
123 CASE 2
124 EndLoop = 3
125 LastPos = FoundPos + 1
126 FoundPos = StrInstrLeft(LastPos, SplitString$, CHR$(34))
127 IF FoundPos = 0 THEN
128 SplitString$ = SplitString$ + CHR$(34)
129 FoundPos = LEN(SplitString$)
130 END IF
131 END SELECT
132 LOOP
133 IF EndLoop = 0 THEN
134 IF LEN(TempString$) > 0 THEN
135 SplitField$(ActualIndex&) = TempString$
136 ELSEIF LastPos <= LEN(SplitString$) THEN
137 SplitField$(ActualIndex&) = MID$(SplitString$, LastPos)
138 ELSE
139 ActualIndex& = ActualIndex& - 1
140 END IF
141 END IF
142 FOR a = ActualIndex& + 1 TO LastIndex
143 SplitField$(a) = ""
144 NEXT
145 SplitCount = (ActualIndex& - StartIndex) + 1
146 END SUB
148 FUNCTION StrTrim$ (a$, b$)
149 StrTrim$ = StrTrimRight$(StrTrimLeft$(a$, b$), b$)
150 END FUNCTION
152 FUNCTION StrTrimLeft$ (a$, b$) 'public
153 p = 0
154 l = LEN(a$)
156 p = p + 1
157 t$ = MID$(a$, p, 1)
158 LOOP WHILE (p < l) AND (INSTR(b$, t$) > 0)
159 StrTrimLeft$ = MID$(a$, p)
160 END FUNCTION
162 FUNCTION StrTrimRight$ (a$, b$) 'public
163 l = LEN(a$)
164 p = l + 1
166 p = p - 1
167 IF p > 0 THEN
168 t$ = MID$(a$, p, 1)
169 ELSE
170 t$ = ""
171 END IF
172 LOOP WHILE (p > 0) AND (INSTR(b$, t$) > 0)
173 StrTrimRight$ = LEFT$(a$, p)
174 END FUNCTION
176 \x1a