Seite 7 von 8

Verfasst: 19.02.2009 16:17
von cxAlex
Seh ich heute zum 1. mal, mal schauen ob man das brauchen kann...

Verfasst: 19.02.2009 16:20
von Andesdaf
ja, habe ich auch das erste Mal gesehen. Finde ich aber gut.

Verfasst: 20.02.2009 00:22
von Little John
Na dann wurde es aber Zeit, dass Ihr das seht. :mrgreen:

2Andesdaf:
Danke für die positive Rückmeldung.

Ich denke die neue Version 0.50 kann man wirklich ernsthaft einsetzen, da jetzt Include-Dateien verarbeitet werden, und Syntaxfehler an der richtigen Stelle angezeigt werden.

Gruß, Little John

Verfasst: 24.02.2009 02:55
von ts-soft
Hab endlich Zeit gefunden zu einem kurzem Test, dabei sind mir folgende
Mankos aufgefallen: Funktioniert nicht, wenn x64 und x86 von PB installiert
sind, weil GetPBFolder hierbei versagen muß.
Desweiteren werden nur gespeicherte Sourcen berücksichtigt.

Das hab ich mal geändert:

Code: Alles auswählen

; -- Little Purebasic Preprocessor (LPP)
; -- Version 0.51, 2009-02-24
; Public Domain, written by Juergen Luethje <http://luethje.eu/>.
; Developed with Purebasic 4.30.
; Cross-platform, Unicode compliant.
; Tested on Windows XP, and Ubuntu 8.10.
; Standard disclaimer: USE AT YOUR OWN RISK!
;
; Features
; --------
; Currently the only feature is the option of line continuation in the
; source code, by adding a particular mark at the end of the regarding
; lines. This is possible in the main file and in include files as well.
;
; Command line
; ------------
; Lpp <PB source code file> <output file>
;
; Installation
; ------------
; Compile the program to an EXE file, and put it into a subdirectory
; of the directory where your 'PureBasic.exe' file is located.
;
; 1) You can use it as standalone program.
;
; 2) This program was developed as tool for the Purebasic IDE.
;    In the IDE, choose from the menu "Configure Tools ...".
;    In the window that appears, add the program 2 times with
;    different names by clicking the [ New ] button.
;
;    Use as trigger
;    - for one name      : Before Compile/Run
;    - for the other name: Before Create Executable
;
;    and for both names choose the following settings
;
;    Arguments: "%FILE" "%TEMPFILE" "%COMPILEFILE"      (with the quotes!)
;    [v] Wait until tool quits
;    [v] Hide Tool from the Main menu
;
; Usage
; -----
; For using line continuation in your code, type
;     $LPP      (lower/upper case doesn't matter)
; as first executable statement in your main source code file. <New>
; code in the IDE must be saved to a file, before LPP can process it.
;
; This tool allows to continue any line by adding a trailing _ like in
; the first example (a comment may follow). Open strings cannot be
; continued. In case that mark is part of an identifier (e.g. procedure
; or variable name), it is *not* interpreted as line continuation mark.
;
; If you want, you can define a custom string (e.g. &) as continuation
; mark for each file separately. In order to do so, write:
;     $LPP_MULTILINE = &
; on the line after $LPP in your main source code file, or as first
; executable statement in an include file. Note that the custom string
; is not enclosed in quotes.
;
; In case of an error in an include file, the IDE will display a
; temporary file with the flawed line, generated by LPP. If e.g. the
; error is on line 12 in the file "test.pbi", in combination with LPP
; the IDE will highlight line 12 in the file "~Lpp_test.pbi". Bear in
; mind to correct the code in the original source file (which is in the
; same directory), not in the temporary file!
;
; For working with your normal code, it's not required to switch this
; tool off in the IDE. Just leave out $LPP at the beginning of the
; source code, and then the pre-processor will see that there's nothing
; to do for it and will immediately terminate.
;
; Notes
; -----
; All XincludeFile, IncludeFile and IncludePath statements in the
; source code which is to be processed by this program
; - must not be part of multi-statemented (colon separated) lines
; - must only involve constant literal strings and #PB_Compiler_Home
; - must not depend on any preprocessor actions such as macros
;   (The only exception is the permissable use of #PB_Compiler_Home.)
;
; Include files may have different encodings.
;
; Return code of the program
; --------------------------
; 0 = source code doesn't require preprocessing
; 1 = source code successfully processed
; 2 = error (also a message is shown in this case)
;
; Credits
; -------
; This program is based on code by Stephen Rodriguez for merging a
; Purebasic source file and all included files into a single file.
; Thank you very much!
; Thanks to all members of the German and the English Purebasic
; forums, from whom I learned tips, and who made suggestions for
; improvement of this program and its predecessor 'JoinLines'.


EnableExplicit

;-- CONSTANTS AND STRUCTURES

#PROGRAM_TITLE$ = "LPP 0.51"
#TMPFILE_PREFIX$ = "~Lpp_"
#ABORT_MESSAGE$ = #CRLF$ + "Program aborted."
#SIZEOFSTACK = 1024                        ; Max number of include files

#WHITESPACE$ = " " + #TAB$
#KEYWORD_SEPARATOR$ = "=" + #WHITESPACE$
#INCLUDE_SEPARATOR$ = "+" + #WHITESPACE$ + #DQUOTE$
#SYMBOLS$ = ",=-*/\&|!~()<>%:'" + #INCLUDE_SEPARATOR$
#LPP_KEYWORD$ = "$LPP"                     ; Upper case here!
#MULTILINE_KEYWORD$ = "$LPP_MULTILINE"     ;    -- " --


; Return values of PreProcessSources()
Enumeration 0 Step -1
   #LPP_NOTHINGTODO
   #LPP_OKAY
   #LPP_MAINOPENERROR
   #LPP_FILECREATEERROR
   #LPP_INVALIDCOMPILERHOME
   #LPP_INVALIDPATH
   #LPP_INVALIDINCLUDEFILE
   #LPP_NESTEDINCLUDESOVERFLOW
   #LPP_INCLUDEOPENERROR
   #LPP_INVALIDSTRINGFORMAT
   #LPP_INVALIDMULTILINESYNTAX
EndEnumeration

Structure File
   inFile.i
   outFile.i
   format.i
   mark$
EndStructure


;-- PLATFORM SPECIFIC CODE

CompilerSelect #PB_Compiler_OS
   CompilerCase #PB_OS_Windows
      #SLASH = "\"
      #PB_IDE = "purebasic.exe"        ; file name relative to #PB_COMPILER_HOME
      Macro PathIsRelative (_file_)
         (Mid(_file_, 2, 1) <> ":")
      EndMacro

   CompilerDefault
      #SLASH = "/"
      #PB_IDE = "compilers/purebasic"  ; Linux (** What about Mac OS?)
      Macro PathIsRelative (_file_)
         (Left(_file_, 1) <> "/")
      EndMacro
CompilerEndSelect


;-- GLOBAL VARIABLES

; The following global is used in the case of an #LPP_INCLUDEOPENERROR
; error and contains the full name of the file which could not be
; located. (It is also used internally!)
Global g_Include$

; The following global is used in the case of an #LPP_FILECREATEERROR
; error and contains the full name of the file which could not be
; created.
Global g_Create$


;-- PROCEDURES

Procedure.s LTrimChars (source$, charList$=#WHITESPACE$)
   ; in : string
   ; out: string without any leading characters, that are contained in 'charList$'
   Protected left, length=Len(source$)

   left = 1
   While (left <= length) And FindString(charList$, Mid(source$,left,1), 1)
      left + 1
   Wend
   ProcedureReturn Mid(source$, left)
EndProcedure


Procedure.s RTrimChars (source$, charList$=#WHITESPACE$)
   ; in : string
   ; out: string without any trailing characters, that are contained in 'charList$'
   Protected right

   right = Len(source$)
   While (right >= 1) And FindString(charList$, Mid(source$,right,1), 1)
      right - 1
   Wend
   ProcedureReturn Left(source$, right)
EndProcedure

Procedure.s GetPBFolder()
  ; returns the absolute path of the PB installation directory
  CompilerIf #PB_Compiler_Debugger                           ; IDE with debugger on
  ProcedureReturn #PB_Compiler_Home

  CompilerElse                                               ; EXE file
  ; The EXE file of this program must be in a SUBDIRECTORY of the PB installation directory.
  Protected folder$
  folder$ = GetEnvironmentVariable("PB_TOOL_IDE")
  If folder$ <> ""
    ProcedureReturn GetPathPart(folder$)
  Else
    folder$ = GetPathPart(ProgramFilename())
    While folder$
      If FileSize(folder$ + #PB_IDE) > 0
        ProcedureReturn folder$
      EndIf
      folder$ = GetPathPart(Left(folder$, Len(folder$)-1))  ; parent folder
    Wend
  EndIf
  ProcedureReturn ""
  CompilerEndIf
EndProcedure

Procedure.s ExtractCode (line$)
   ; in : source code line
   ; out: source code line without comment, and
   ;      without leading or trailing whitespace
   ;      (with a trailing " " in case of an error, though)
   Protected char, i, length=Len(line$)

   i = 1
   While i <= length
      char = Asc(Mid(line$, i, 1))
      If char = '"'      ; skip quoted string
         i = FindString(line$, #DQUOTE$, i+1)
         If i = 0
            Break
         EndIf
      ElseIf char = 39   ; skip 'quoted number'
         i = FindString(line$, "'", i+1)
         If i = 0
            Break
         EndIf
      ElseIf char = ';'  ; end of code in given line
         line$ = Left(line$, i-1)
         Break
      EndIf
      i + 1
   Wend

   line$ = RTrimChars(line$)
   If i = 0              ; error: " or ' are unbalanced on the line
      line$ + " "
   EndIf
   ProcedureReturn line$
EndProcedure


Procedure.s GetLine (inFileID, format, cMark$, lenMark, *lineCount.Integer)
   ; in : inFileID    : input file number
   ;      format      : #PB_Ascii, #PB_UTF8, or #PB_Unicode
   ;      cMark$      : line continuation mark
   ;      lenMark     : length of line continuation mark
   ; out: *lineCount\i: number of blank lines to pad
   ;      return value: current whole (code) line
   Protected lenCode
   Protected line$, code$, ret$

   *lineCount\i = 0
   While Eof(inFileID) = #False
      line$ = ReadString(inFileID, format)
      code$ = ExtractCode(line$)
      lenCode = Len(code$)
      If (UCase(Right(code$,lenMark)) = cMark$) And FindString(#SYMBOLS$, Mid(code$,lenCode-lenMark,1), 1)
         If *lineCount\i = 0
            ret$ = Left(code$, lenCode-lenMark)
         Else
            ret$ + LTrimChars(Left(code$, lenCode-lenMark))
         EndIf
         *lineCount\i + 1
      ElseIf *lineCount\i > 0
         ProcedureReturn ret$ + LTrimChars(code$)
      Else
         ProcedureReturn line$
      EndIf
   Wend

   ProcedureReturn ""                      ; end of file
EndProcedure


Procedure.s NextStatement (inFileID, format, List buffer$(), *filePntr.Quad)
   ; in : inFileID    : input file number
   ;      format      : #PB_Ascii, #PB_UTF8, or #PB_Unicode
   ; out: buffer$()   : skipped lines
   ;      *filePntr\q : pointer of file 'inFileID' before doing ReadString()
   ;      return value: next statement in input file
   Protected line$, code$=""

   ClearList(buffer$())
   While Eof(inFileID) = #False
      *filePntr\q = Loc(inFileID)
      line$ = ReadString(inFileID, format)
      code$ = LTrimChars(ExtractCode(line$))
      If code$
         Break
      EndIf
      AddElement(buffer$())
      buffer$() = line$
   Wend

   ProcedureReturn code$
EndProcedure


Procedure.s ContinuationMark (inFileID, outFileID, format)
   ; in : file numbers and encodings
   ; out: custom line continuation mark,
   ;      ""  on error,
   ;      " " if #MULTILINE_KEYWORD$ statement was not found
   Protected filePntr.q, multilineKeyLength=Len(#MULTILINE_KEYWORD$)
   Protected line$, param$, ret$

   NewList buffer$()
   line$ = NextStatement(inFileID, format, buffer$(), @filePntr)
   If (UCase(Left(line$, multilineKeyLength)) = #MULTILINE_KEYWORD$) And FindString(#KEYWORD_SEPARATOR$, Mid(line$+" ", multilineKeyLength+1, 1), 1)
      param$ = LTrim(Mid(line$, multilineKeyLength+1))
      If Left(param$,1) = "="
         ret$ = UCase(LTrim(Mid(param$, 2)))         ; custom string to denote line continuation
      Else
         ret$ = ""                                   ; Syntax error
      EndIf
      AddElement(buffer$())
   Else                                              ; #MULTILINE_KEYWORD$ not found
      ret$ = " "
      FileSeek(inFileID, filePntr)                   ; rewind file pointer
   EndIf

   ForEach buffer$()
      WriteStringN(outFileID, buffer$(), format)     ; write skipped lines
   Next

   ProcedureReturn ret$
EndProcedure


Procedure.i ProcessIncludeString (line$)
   ; in : path / filename
   ;      (can contain concatenations or the #PB_Compiler_Home constant)
   ; out: g_Include$  : corresponding string literal; this is not
   ;                    necessarily a perfectly validated path /
   ;                    filename, but that will be picked up later.
   ;      return value: error code, 0 on success
   Protected char$, pbFolder$, token$=""
   Protected numberoftokens, length, left, right, i, errCode

   g_Include$ = ""
   line$ = ExtractCode(line$)
   length = Len(line$)
   If length = 0
      ProcedureReturn -2
   EndIf

   ; First we 'tokenise' the line.
   left=1 : right=1
   Repeat
      char$ = Mid(line$, right, 1)
      If FindString(#INCLUDE_SEPARATOR$, char$, 1)
         If left < right
            token$ + Mid(line$, left, right-left) + #LF$
            numberoftokens+1
            left = right
         ElseIf char$ = #DQUOTE$     ; Open quote. left=right
            right = FindString(line$, char$, left+1)
            If right = 0             ; No end quote.
               numberoftokens = 0
               token$ = ""
               Break
            ElseIf right-left > 1
               token$ + Mid(line$, left, right-left+1) + #LF$
               numberoftokens+1
            EndIf
            right+1
            left = right
         ElseIf char$ <> " "         ; left=right
            token$ + Mid(line$,left,1) + #LF$
            numberoftokens+1
            left+1 : right+1
         Else
            left+1 : right+1
         EndIf
      ElseIf right = length
         right+1
         token$ + Mid(line$, left, right-left) + #LF$
         numberoftokens+1
      Else
         right+1
      EndIf
   Until right > length

   ; Now process the tokens.
   errCode = 0
   For i = 1 To numberoftokens
      char$ = StringField(token$, i, #LF$)
      If i % 2 = 0
         If char$ <> "+"
            errCode = -2
            g_Include$ = ""
            Break
         EndIf
      ElseIf UCase(char$) = "#PB_COMPILER_HOME"
         pbFolder$ = GetPBFOlder()
         If pbFolder$ = ""
            errCode = -1
            g_Include$ = ""
            Break
         EndIf
         g_Include$ + pbFolder$
      ElseIf Left(char$,1) = #DQUOTE$
         g_Include$ + Mid(char$, 2, Len(char$)-2)
      Else
         errCode = -2
         g_Include$ = ""
         Break
      EndIf
   Next

   ProcedureReturn errCode
EndProcedure


Procedure.i PreProcessSources (inFile$, outFile$)
   ; -- Main procedure
   ; in : inFile$ : name of main source code file to process
   ;      outFile$: name of target file
   ; out: one of the #LPP_* constants listed at the top
   Protected inFileID, outFileID, format, stackPtr, logFileID, filePntr.q
   Protected k, inc, padLines, lenMark, processInclude, result
   Protected path$, line$, cMark$, customMark$, xInclude$, incStatement$
   Protected LogFile$ = GetTemporaryDirectory() + "~Lpp.tmp"

   If inFile$ = ""
      ProcedureReturn #LPP_NOTHINGTODO        ; no preprocessing possible
   EndIf

   ; Create file stack and line buffer
   Dim stack.File(#SIZEOFSTACK)
   stackPtr = 0                               ; number of elements on the stack
   NewList buffer$()

   ; Attempt to open the main input file
   path$ = GetPathPart(inFile$)
   inFileID = ReadFile(#PB_Any, inFile$)
   If inFileID = 0
      ProcedureReturn #LPP_MAINOPENERROR
   EndIf

   ; Identify the string encoding used in the file
   format = ReadStringFormat(inFileID)
   Select format
      Case #PB_Ascii, #PB_UTF8, #PB_Unicode
      Default
         CloseFile(inFileID)
         ProcedureReturn #LPP_INVALIDSTRINGFORMAT
   EndSelect

   ; Check the first statement of the main input file.
   If UCase(NextStatement(inFileID, format, buffer$(), @filePntr)) <> #LPP_KEYWORD$
      CloseFile(inFileID)
      ProcedureReturn #LPP_NOTHINGTODO   ; no preprocessing necessary
   EndIf

   ; Attempt to create the main output file
   outFileID = CreateFile(#PB_Any, outFile$)
   If outFileID = 0
      CloseFile(inFileID)
      g_Create$ = outFile$
      ProcedureReturn #LPP_FILECREATEERROR
   EndIf

   ; Write BOM and skipped lines to main output file.
   WriteStringFormat(outFileID, format)
   ForEach buffer$()
      WriteStringN(outFileID, buffer$(), format)
   Next
   WriteStringN(outFileID, "")

   cMark$ = "_"                              ; default line continuation mark

   ; Look for custom line continuation mark
   customMark$ = ContinuationMark(inFileID, outFileID, format)
   If customMark$ = ""
      CloseFile(inFileID)
      CloseFile(outFileID)
      ProcedureReturn #LPP_INVALIDMULTILINESYNTAX  ; Error
   ElseIf customMark$ <> " "
      cMark$ = customMark$
   EndIf

   logFileID = CreateFile(#PB_Any, logFile$)
   If logFileID = 0
      CloseFile(inFileID)
      CloseFile(outFileID)
      g_Create$ = logFile$
      ProcedureReturn #LPP_FILECREATEERROR
   EndIf

   ; Main loop
   result = #LPP_OKAY
   Repeat
      lenMark = Len(cMark$)

      While Eof(inFileID) = #False
         line$ = GetLine(inFileID, format, cMark$, lenMark, @padLines)

         ; Check the three possible 'include' options.
         If (FindString(UCase(line$), "INCLUDEPATH",1) = 1) And FindString(#SYMBOLS$, Mid(line$,12,1),1)
            line$ = LTrimChars(RTrimChars(Mid(line$, 12)))
            If line$ = #DQUOTE$ + #DQUOTE$
               path$ = ""
            Else
               processInclude = ProcessIncludeString(line$)
               If processInclude < 0
                  CloseFile(inFileID)
                  CloseFile(outFileID)
                  If processInclude = -1
                     result = #LPP_INVALIDCOMPILERHOME     ; Error
                  Else
                     result = #LPP_INVALIDPATH             ; Error
                  EndIf
                  Break 2
               EndIf
               path$ = g_Include$
               If path$ And (Right(path$,1) <> #SLASH)
                  path$ + #SLASH
               EndIf
            EndIf
            For k = 1 To padLines+1                        ; Write appropriate number of blank
               WriteStringN(outFileID, "")                 ; lines, in order to preserve line
            Next                                           ; numbers of subsequent statements

         Else
            inc = FindString(UCase(line$), "INCLUDEFILE",1) + 11
            If (inc = 12 Or (inc=13 And UCase(Left(line$,1))="X")) And FindString(#SYMBOLS$, Mid(line$,inc,1),1)
               incStatement$ = Left(line$, inc-1) + " "
               line$ = LTrimChars(RTrimChars(Mid(line$, inc)))
               processInclude = ProcessIncludeString(line$)
               If processInclude < 0
                  CloseFile(inFileID)
                  CloseFile(outFileID)
                  If processInclude = -1
                     result = #LPP_INVALIDCOMPILERHOME     ; Error
                  Else
                     result = #LPP_INVALIDINCLUDEFILE      ; Error
                  EndIf
                  Break 2
               EndIf
               line$ = g_Include$
               If PathIsRelative(line$)
                  line$ = path$ + line$
               EndIf
               ; Write Include statement with new file name into including file.
               outFile$ = GetPathPart(line$) + #TMPFILE_PREFIX$ + GetFilePart(line$)
               WriteStringN(outFileID, incStatement$ + #DQUOTE$ + outFile$ + #DQUOTE$, format)
               For k = 1 To padLines                       ; Write appropriate number of blank
                  WriteStringN(outFileID, "")              ; lines, in order to preserve line
               Next                                        ; numbers of subsequent statements

               ; Check if it's OK to include the file.
               If inc = 12 Or FindString(XInclude$, "<"+line$+">",1) = 0
                  ; Save information about the current file on the stack.
                  If stackPtr = #SIZEOFSTACK
                     CloseFile(inFileID)
                     CloseFile(outFileID)
                     result = #LPP_NESTEDINCLUDESOVERFLOW  ; Error
                     Break 2
                  EndIf
                  stackPtr + 1
                  stack(stackPtr)\inFile  = inFileID
                  stack(stackPtr)\outFile = outFileID
                  stack(stackPtr)\format  = format
                  stack(stackPtr)\mark$   = cMark$
                  ; Attempt to open the include file.
                  inFileID = ReadFile(#PB_Any, line$)
                  If inFileID = 0
                     g_Include$ = line$
                     result = #LPP_INCLUDEOPENERROR        ; Error
                     Break 2
                  EndIf
                  ; Identify the string encoding used in the file.
                  format = ReadStringFormat(inFileID)
                  Select format
                     Case #PB_Ascii, #PB_UTF8, #PB_Unicode
                     Default
                        CloseFile(inFileID)
                        result = #LPP_INVALIDSTRINGFORMAT  ; Error
                        Break 2
                  EndSelect
                  ; Attempt to create temporary output file.
                  outFileID = CreateFile(#PB_Any, outFile$)
                  If outFileID = 0
                     CloseFile(inFileID)
                     g_Create$ = outFile$
                     result = #LPP_FILECREATEERROR         ; Error
                     Break 2
                  EndIf
                  ; Write BOM to output file.
                  WriteStringFormat(outFileID, format)
                  ; Look for custom line continuation mark
                  customMark$ = ContinuationMark(inFileID, outFileID, format)
                  If customMark$ = ""
                     CloseFile(inFileID)
                     CloseFile(outFileID)
                     result = #LPP_INVALIDMULTILINESYNTAX  ; Error
                     Break 2
                  ElseIf customMark$ <> " "
                     cMark$ = customMark$
                     lenMark = Len(cMark$)
                  EndIf

                  ; Add this file to the list of already included files.
                  xinclude$ + "<"+line$+">"
                  ; Save absolute name of the temporary output file.
                  If PathIsRelative(outFile$)
                     outFile$ = GetCurrentDirectory() + outFile$
                  EndIf
                  WriteStringN(logFileID, outFile$, #PB_UTF8)
               EndIf

            Else
               WriteStringN(outFileID, line$, format)   ; Write line;
               For k = 1 To padLines                    ; write appropriate number of blank
                  WriteStringN(outFileID, "")           ; lines, in order to preserve line
               Next                                     ; numbers of subsequent statements
            EndIf
         EndIf
      Wend
      CloseFile(inFileID)
      CloseFile(outFileID)

      If stackPtr = 0
         Break
      EndIf

      inFileID  = stack(stackPtr)\inFile    ; restore inFile ID
      outFileID = stack(stackPtr)\outFile   ; restore outFile ID
      format    = stack(stackPtr)\format    ; restore encoding
      cMark$    = stack(stackPtr)\mark$     ; restore line continuation mark
      stackPtr - 1
   ForEver

   CloseFile(logFileID)

   ; Clear the stack if there was an error.
   For k = 1 To stackPtr
      CloseFile(stack(k)\inFile)
      CloseFile(stack(k)\outFile)
   Next

   ProcedureReturn result
EndProcedure


;===========================
;-- EXECUTION ENTRY POINT
;===========================

Define ExitCode
Define Infile$, Outfile$, Msg$

If CountProgramParameters() <> 3
   Msg$ = "Little Purebasic Preprocessor" + #LF$
   Msg$ + "Juergen Luethje 2009" + #LF$
   Msg$ + #LF$
   Msg$ + "Usage : Lpp <PB source code file> <output file>"
   MessageRequester(#PROGRAM_TITLE$, Msg$)
   End 2
EndIf

Infile$  = ProgramParameter(0)
If Infile$ = ""
  Infile$  = ProgramParameter(1)
EndIf
Outfile$ = ProgramParameter(2)
ExitCode = PreProcessSources(Infile$, Outfile$)

Select ExitCode
   Case #LPP_NOTHINGTODO
      Debug "Nothing got to do."
      End 0
   Case #LPP_OKAY
      Debug "File '" + Infile$ + "' successfully processed."
      End 1

   Case #LPP_MAINOPENERROR
      Msg$ = "Couldn't open main source file '" + Infile$ + "'." + #ABORT_MESSAGE$
   Case #LPP_FILECREATEERROR
      Msg$ = "Couldn't create file '" + g_Create$ + "'." + #ABORT_MESSAGE$
   Case #LPP_INVALIDCOMPILERHOME
      Msg$ = "File 'PureBasic.exe' not found."
      Msg$ + #ABORT_MESSAGE$
      Msg$ + #CRLF$ + #CRLF$
      Msg$ + "Put the EXE file of this program in a directory, which" + #CRLF$
      Msg$ + "is below the directory that contains 'PureBasic.exe'."
   Case #LPP_INVALIDPATH
      Msg$ = "Invalid parameter for IncludePath" + #ABORT_MESSAGE$
   Case #LPP_INVALIDINCLUDEFILE
      Msg$ = "Invalid parameter for XIncludeFile or IncludeFile" + #ABORT_MESSAGE$
   Case #LPP_NESTEDINCLUDESOVERFLOW
      Msg$ = "Too many nested includes" + #CRLF$
      Msg$ + "(probably a recursive use of a certain include file)." + #ABORT_MESSAGE$
   Case #LPP_INCLUDEOPENERROR
      Msg$ = "Couldn't open include file '" + g_Include$ + "'." + #ABORT_MESSAGE$
   Case #LPP_INVALIDSTRINGFORMAT
      Msg$ = "Unsupported encoding in source file '" + Infile$ + "'." + #ABORT_MESSAGE$
   Case #LPP_INVALIDMULTILINESYNTAX
      Msg$ = "Invalid syntax for " + #MULTILINE_KEYWORD$ + "." + #ABORT_MESSAGE$
EndSelect

MessageRequester(#PROGRAM_TITLE$, Msg$)
End 2
Die Änderungen sind in GetPBFolder(). Wenn Dein PreProcessor als
Plugin installiert ist, wird jetzt auch bei vorhandener x86 und x64
Installation der korrekte Pfad gefunden! (beide teilen sich eine prefs!)

Die andere Änderung ist bei der Abfrage der Programparameter, es
werden jetzt 3 Parameter erwartet:
Arguments: "%FILE" "%TEMPFILE" "%COMPILEFILE" (with the quotes!)
Dadurch kann man auch mit ungespeicherten Dateien arbeiten.

Gruß
Thomas

Verfasst: 26.02.2009 21:24
von Little John
Hallo Thomas,

bitte entschuldige die etwas verspätete Antwort. Ich bin z.Z. krank und verbringe die meiste Zeit des Tages schlafend.

Über die Umgebungsvariablen für IDE-Tools habe ich kürzlich zum ersten Mal etwas gelesen. Als ich LPP Version 0.50 schrieb kannte ich sie noch nicht. PB_TOOL_IDE ist hier natürlich sehr hilfreich.

Deine Änderng
ts-soft hat geschrieben:

Code: Alles auswählen

Procedure.s GetPBFolder()
  ; [...]
  folder$ = GetEnvironmentVariable("PB_TOOL_IDE")
  If folder$ <> ""
    ProcedureReturn GetPathPart(folder$)
  ; [...]
EndProcedure
ist nicht cross-plattform kompatibel, weil die PureBasic-IDE sich unter Linux (i. Ggs. zu Windows und Mac OS) standardmäßig leider im Unterverzeichnis "compilers" befindet.

Ich denke ich werde Deine Änderung etwa so übernehmen:

Code: Alles auswählen

CompilerSelect #PB_Compiler_OS
   CompilerCase #PB_OS_Windows
      #PB_IDE$ = "purebasic.exe"        ; file name relative to #PB_COMPILER_HOME
   CompilerCase #PB_OS_Linux
      #PB_IDE$ = "compilers/purebasic"
   CompilerCase #PB_OS_MacOS
      #PB_IDE$ = "PureBasic.app"
CompilerEndSelect

folder$ = GetEnvironmentVariable("PB_TOOLS_IDE")
If folder$ <> ""
   ProcedureReturn Left(folder$, Len(folder$)-Len(#PB_IDE$))
   ; [...]
EndIf
ts-soft hat geschrieben:Die andere Änderung ist bei der Abfrage der Programparameter, es werden jetzt 3 Parameter erwartet:
Arguments: "%FILE" "%TEMPFILE" "%COMPILEFILE" (with the quotes!)
Dadurch kann man auch mit ungespeicherten Dateien arbeiten.
Das Problem war mir bekannt, ich hatte nur keine Lösung ...
Ich denke auch dies werde ich in leicht abgewandelter Form übernehmen, denn LPP soll nicht "nur" als IDE-Tool verwenbar sein, sondern auch als Standalone-Programm (z.B. um Quellcode vorzuverarbeiten, der dann mit PureUnit getestet werden soll). Ich denke ich werde den Aufruf bei Verwendung als Standalone-Programm so lassen wie bisher, und für Verwendung als IDE-Tool "%TEMPFILE" zusätzlich als 3. Parameter verwenden.

Vielen Dank!

Gruß, Little John

Verfasst: 27.02.2009 05:23
von ts-soft
> ist nicht cross-plattform kompatibel
Dann verstehe ich nicht, das es bei mir funktioniert unter Ubuntu 8.10 :wink:

Verfasst: 27.02.2009 10:54
von Little John
ts-soft hat geschrieben:> ist nicht cross-plattform kompatibel
Dann verstehe ich nicht, das es bei mir funktioniert unter Ubuntu 8.10 :wink:
Verstehe ich auch nicht. Das hat mich daran erinnert, dass in der "Install"-Datei von PB 4.30 verschiedene Installationsmethoden angegeben werden. Hab's grad nochmal nachgelesen. Wenn ich nichts übersehen habe, dann befindet sich nach allen angegebenen Methoden die IDE im Unterverzeichnis "compilers". Ich habe das auf meinem System mit Hilfe des folgenden kleinen Testprogramms verifiziert:

Code: Alles auswählen

folder$ = GetEnvironmentVariable("PB_TOOL_IDE")
MessageRequester("GetPathPart(PB_TOOL_IDE)", GetPathPart(folder$))
Das ist ja die von Dir vorgeschlagene Methode. Wenn ich das unter Ubuntu 8.10 compiliere und als Tool in die IDE einbinde, erhalte ich das Ergebnis
/opt/purebasic/compilers/
Aber was ich haben möchte ist ja
/opt/purebasic/
Was zeigt denn dieser Programmschnipsel bei Dir an?

Unabhängig davon wurde ich durch das erneute Lesen der "Install"-Datei daran erinnert, dass dort optional eine systemweite Umgebungsvariable namens "PUREBASIC_HOME" vorgeschlagen wird. Die werde ich auch noch berücksichtigen.

Gruß, Little John

Verfasst: 27.02.2009 12:23
von ts-soft
>> Was zeigt denn dieser Programmschnipsel bei Dir an?
/home/thomas/purebasic/compilers/
>> Aber was ich haben möchte ist ja
Bei mir funktioniert es so, aber wenns den wichtig ist, RemoveString sollte
helfen :wink:

Verfasst: 27.02.2009 12:56
von Little John
ts-soft hat geschrieben:>> Was zeigt denn dieser Programmschnipsel bei Dir an?
/home/thomas/purebasic/compilers/
>> Aber was ich haben möchte ist ja
Bei mir funktioniert es so, aber wenns den wichtig ist,
Das ist ja klar definiert: Meine Prozedur GetPBFolder() soll den selben Wert liefern wie #PB_Compiler_Home. Und das ist z.B. bei Dir
/home/thomas/purebasic/
und nicht
/home/thomas/purebasic/compilers/
ts-soft hat geschrieben:RemoveString sollte helfen :wink:
Der Code, den ich bereits mehrere Nachrichten weiter oben gepostet habe ist auch nicht ganz schlecht. :wink:

Gruß, Little John

Verfasst: 27.02.2009 13:05
von ts-soft
Little John hat geschrieben: Der Code, den ich bereits mehrere Nachrichten weiter oben gepostet habe ist auch nicht ganz schlecht. :wink:

Gruß, Little John
Egal, wichtig ist das es so drinnen ist, weil ansonsten kann ich es nicht
nutzen, da ich die LPP exe ja nicht gleichzeitig ins Unterverzeichnis der x86
und der x64 IDE packen kann, technisch einfach nicht machbar :mrgreen:
Da beide dieselbe Tools.pref verwenden würde nur eine Version funzen können.

Gruß
Thomas