Kleine Anekdote: Genau das von Dir gewünschte Feature des ' Kommentars nur für den Editor hatte ich ursprünglich, bis mich ein Anwender von Exbasic darauf hinwies, dass ich ihm seinen Source verstümmel...
Machs doch einstellbar.
Hier übrigens mal mein Preprozessor, geschrieben in FreeBASIC. Entfernt alle unnötigen Leerzeichen und macht möglichst kurze Zeilennummern.
(Bitte nicht zu schief ansehen, das ganze ist eigentlich nur ein Hack für mich...)
Code
- dim t as string
- dim ta as string
- dim tm as string
- dim te as string
- dim tn as integer
- dim linenums(65535) as integer
- dim lines(65535) as string
- dim lastline as integer
- dim posi as integer
- dim i as integer
- dim j as integer
- dim quotescheck as integer
- dim quotesbegin as integer
- dim quotesend as integer
- dim onwith as integer
- #define ON_ERROR 0
- #define ON_GOTO 1
- #define ON_GOSUB 2
- open command(1) for input as #1
- open command(2) for output as #2
- do
- posi += 1
- do
- line input #1,t
- t = trim(t)
- if left(t,3) = "rem" then t = ""
- if left(t,1) = "'" then t = ""
- if eof(1) then exit do
- loop until len(t) > 0
- print posi,t
- print "len:";len(t)
- 'Zeilennummer holen, wenn vorhanden
- if instr(left(t,1),any "0123456789") then
- for i = 1 to len(t)
- if t[i] = asc(" ") then exit for
- next i
- 'Zeilennummer holen
- linenums(posi) = val(left(t,i))
- '''print linenums(posi),
- 'Zeile selber holen
- lines(posi) = trim(mid(t,i+1))
- '''print lines(posi)
- else 'Keine Zeilennummer
- lines(posi) = t
- '''print 0,lines(posi)
- end if
- loop until eof(1)
- lastline = posi
- close 1
- print "beginne renum"
- for posi = 1 to lastline
- 'Pruefe auf Anfuehrungszeichen...
- quotescheck = 0
- t = lines(posi)
- 'print posi,t
- i = 0
- do
- i += 1
- if mid(t,i,1) = """" then
- do
- i += 1
- if mid(t,i,1) = """" then exit do
- if i>len(t) then
- print "ERROR: Something wrong with the quotes in:";posi
- print "Line:";t
- end
- end if
- loop
- end if
- if mid(t,i,2) = "on" then
- i += 2
- onwith = ON_ERROR
- for j = i to len(t)
- if mid(t,j,4) = "goto" then onwith = ON_GOTO:i = j + 4:exit for
- if mid(t,j,5) = "gosub" then onwith = ON_GOSUB:i = j+ 5:exit for
- next j
- 'Break if we dont have a goto or a gosub
- if onwith = ON_ERROR then
- print "ERROR: Something wrong with an ON ... GO* in:";posi
- print "Line:";t
- end
- end if
- do
- ta = trim(left(t,i-1))
- for j = i to len(t)
- if instr(mid(t,j,1),any "0123456789 ") = 0 then exit for
- next j
- tm = mid(t,i,j-i)
- te = trim(mid(t,j))
- ' print "ON:"
- ' print ta;"|";tm;"|";te
- ' print "i=";i
- tn = val(tm)
- for j = 1 to lastline
- if tn = linenums(j) then exit for
- next j
- tn = j
- t = ta+str(tn)
- i = len(t)
- t = t + te
- j=0
- do
- if mid(t,i,1) = "," then i +=1:exit do
- if mid(t,i,1) = ":" then j = 1:i +=1:exit do
- if i > len(t) then j = 1:exit do
- i +=1
- loop
- if j = 1 then exit do
- loop
- end if
- if mid(t,i,4) = "goto" then
- i += 4
- ta = trim(left(t,i))
- for j = i to len(t)
- if instr(mid(t,j,1),any "0123456789 ") = 0 then exit for
- next j
- tm = mid(t,i,j-i)
- te = mid(t,j)
- tn = val(tm)
- ' print "GOTO:"
- ' print ta;"|";tm;"|";te
- ' print "i=";i
- for j = 1 to lastline
- if tn = linenums(j) then exit for
- next j
- tn = j
- t = ta+str(tn)
- i = len(t)+1
- t = t + te
- end if
- if mid(t,i,4) = "then" then
- i += 4
- te = trim(mid(t,i))
- if instr(left(te,1),any "0123456789") = 1 then
- ta = trim(left(t,i))
- for j = i to len(t)
- if instr(mid(t,j,1),any "0123456789 ") = 0 then exit for
- next j
- tm = mid(t,i,j-i)
- te = mid(t,j)
- tn = val(tm)
- for j = 1 to lastline
- if tn = linenums(j) then exit for
- next j
- tn = j
- t = ta+str(tn)
- i = len(t)+1
- t = t + te
- end if
- end if
- if mid(t,i,5) = "gosub" then
- i += 5
- ta = trim(left(t,i))
- for j = i to len(t)
- if instr(mid(t,j,1),any "0123456789 ") = 0 then exit for
- next j
- tm = mid(t,i,j-i)
- te = mid(t,j)
- tn = val(tm)
- for j = 1 to lastline
- if tn = linenums(j) then exit for
- next j
- tn = j
- t = ta+str(tn)
- i = len(t)+1
- t = t + te
- end if
- loop until i >= len(t)
- lines(posi) = t
- next posi
- 'Unnötige Leerzeichen killen
- for posi = 1 to lastline
- t=lines(posi)
- ta = ""
- quotescheck = 0
- for i = 1 to len(t)
- select case mid(t,i,1)
- case """"
- select case quotescheck
- case 0
- quotescheck = 1
- case 1
- quotescheck = 0
- end select
- case " "
- if quotescheck = 0 then continue for
- end select
- ta = ta + mid(t,i,1)
- next i
- lines(posi)=ta
- next posi
- for posi = 1 to lastline-1
- print #2,posi;" ";lines(posi)
- next posi
- if lines(lastline) <> "" then
- posi = lastline
- print #2,posi;" ";lines(posi)
- end if
- close 2