summaryrefslogtreecommitdiff
path: root/macros.bas
blob: 89ba846bdbde26c70cff7875b5dbb263dfce0f25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
' INFO_1: Converter for STANDARD.MAC to MACRO.C
'
' INFO_2: Written by Mark Junker in 1997
'         InterNet: mjs@prg.hannover.sgh-net.de
'         FIDO:     Mark Junker@2:2437/47.21
'
' COMMENT: To start the program press SHIFT+F5 within the QBasic IDE
'          or start it from the command-line with QBASIC /RUN MACROS
'

DEFINT A-Z

DECLARE FUNCTION StrTrimLeft$ (a$, b$)
DECLARE FUNCTION StrTrimRight$ (a$, b$)
DECLARE FUNCTION StrTrim$ (a$, b$)
DECLARE SUB StrSplitString (SplitString$, SplitChars$, SplitField$(), SplitCount%)
DECLARE FUNCTION Min% (a%, b%)
DECLARE FUNCTION StrInstrLeft% (SearchStart%, SearchIn$, SearchFor$)
DECLARE FUNCTION StrAscii% (a$)


CLS
DIM LineData$(1 TO 2)

OPEN "I", 1, "STANDARD.MAC"
OPEN "O", 2, "macros.c"

PRINT #2, "/* This file auto-generated from standard.mac by macros.bas - don't edit it */"
PRINT #2, ""
PRINT #2, "static char *stdmac[] = {"

WHILE NOT EOF(1)
  LINE INPUT #1, l$
  CALL StrSplitString(l$, ";", LineData$(), SplitCount)
  IF SplitCount THEN
    LineData$(1) = StrTrim$(LineData$(1), CHR$(9) + " ")
    IF LEN(LineData$(1)) THEN
      PRINT #2, "    " + CHR$(34) + LineData$(1) + CHR$(34) + ","
    END IF
  END IF
WEND
PRINT #2, "    NULL"
PRINT #2, "};"

CLOSE 2
CLOSE 1
SYSTEM

FUNCTION Min% (a%, b%)
  IF a% < b% THEN Min% = a% ELSE Min% = b%
END FUNCTION

FUNCTION StrAscii (a$)
  IF LEN(a$) = 0 THEN
    StrAscii = -1
  ELSE
    StrAscii = ASC(a$)
  END IF
END FUNCTION

' same as =INSTR(SearchStart, SearchIn, ANY SearchFor$) in PowerBASIC(tm)
'
FUNCTION StrInstrLeft (SearchStart, SearchIn$, SearchFor$)
 ValuesCount = LEN(SearchFor$)
 MaxValue = LEN(SearchIn$) + 1
 MinValue = MaxValue
 FOR Counter1 = 1 TO ValuesCount
  SearchChar$ = MID$(SearchFor$, Counter1, 1)
  hVal2 = INSTR(SearchStart, SearchIn$, SearchChar$)
  IF hVal2 > 0 THEN MinValue = Min%(hVal2, MinValue)
 NEXT
 IF MinValue = MaxValue THEN MinValue = 0
 StrInstrLeft = MinValue
END FUNCTION

'
' This is a very damn fuckin' shit version of this splitting routine.
' At this time, it's not very useful :]
'
SUB StrSplitString (SplitString$, SplitChars$, SplitField$(), SplitCount)
  StartIndex = LBOUND(SplitField$)
  LastIndex = UBOUND(SplitField$)
  ActualIndex& = StartIndex
  SplitCount = 0

  LastPos = 1
  FoundPos = StrInstrLeft(LastPos, SplitString$, SplitChars$ + CHR$(34))
  GetDirect = 0
  EndLoop = 0
  TempString$ = ""
  DO WHILE FoundPos > 0
    FoundCharVal = StrAscii(MID$(SplitString$, FoundPos, 1))
    PosDiff = (FoundPos - LastPos) + 1
    SELECT CASE FoundCharVal
    CASE 34
      TempString$ = TempString$ + MID$(SplitString$, LastPos, PosDiff - 1)
      SELECT CASE EndLoop
      CASE 0
        EndLoop = 2
      CASE 3
        EndLoop = 0
      END SELECT
    CASE ELSE
      TempString$ = TempString$ + MID$(SplitString$, LastPos, PosDiff - 1)
      SplitField$(ActualIndex&) = TempString$
      TempString$ = ""
      ActualIndex& = ActualIndex& + 1
      IF ActualIndex& > LastIndex THEN
        ActualIndex& = LastIndex
        EndLoop = 1
      END IF
    END SELECT
    SELECT CASE EndLoop
    CASE 0
      DO
        LastPos = FoundPos + 1
        FoundPos = StrInstrLeft(LastPos, SplitString$, SplitChars$)
      LOOP WHILE LastPos = FoundPos
      FoundPos = StrInstrLeft(LastPos, SplitString$, SplitChars$ + CHR$(34))
    CASE 1
      FoundPos = 0
      LastPos = LEN(SplitString$) + 1
    CASE 2
      EndLoop = 3
      LastPos = FoundPos + 1
      FoundPos = StrInstrLeft(LastPos, SplitString$, CHR$(34))
      IF FoundPos = 0 THEN
       SplitString$ = SplitString$ + CHR$(34)
       FoundPos = LEN(SplitString$)
      END IF
    END SELECT
  LOOP
  IF EndLoop = 0 THEN
    IF LEN(TempString$) > 0 THEN
      SplitField$(ActualIndex&) = TempString$
    ELSEIF LastPos <= LEN(SplitString$) THEN
      SplitField$(ActualIndex&) = MID$(SplitString$, LastPos)
    ELSE
      ActualIndex& = ActualIndex& - 1
    END IF
  END IF
  FOR a = ActualIndex& + 1 TO LastIndex
    SplitField$(a) = ""
  NEXT
  SplitCount = (ActualIndex& - StartIndex) + 1
END SUB

FUNCTION StrTrim$ (a$, b$)
        StrTrim$ = StrTrimRight$(StrTrimLeft$(a$, b$), b$)
END FUNCTION

FUNCTION StrTrimLeft$ (a$, b$) 'public
        p = 0
        l = LEN(a$)
        DO
          p = p + 1
          t$ = MID$(a$, p, 1)
        LOOP WHILE (p < l) AND (INSTR(b$, t$) > 0)
        StrTrimLeft$ = MID$(a$, p)
END FUNCTION

FUNCTION StrTrimRight$ (a$, b$) 'public
        l = LEN(a$)
        p = l + 1
        DO
          p = p - 1
          IF p > 0 THEN
            t$ = MID$(a$, p, 1)
          ELSE
            t$ = ""
          END IF
        LOOP WHILE (p > 0) AND (INSTR(b$, t$) > 0)
        StrTrimRight$ = LEFT$(a$, p)
END FUNCTION