Page 1 of 1

IDE tool: preprocess to clipboard

Posted: Sun Nov 09, 2025 9:26 am
by Piero

Code: Select all

; IDE tool with parameter: %TEMPFILE
; Copy preprocessed source (expanded macros etc.) to clipboard

Structure daResults : Out.s : Err.s : ExC.w : EndStructure
Global Sh.daResults

Procedure Shell(ShellCommand$, AddReturns = 1)
   Protected Err$, tmper$, Output$, shell, Exc.w = -1 ; -1 on failed launch
   shell = RunProgram("zsh","-l","",
      #PB_Program_Open|#PB_Program_Write|#PB_Program_Read|#PB_Program_Error )
   If shell
      WriteProgramStringN(shell,ShellCommand$)
      WriteProgramData(shell,#PB_Program_Eof,0)
      While ProgramRunning(shell)
         If AvailableProgramOutput(shell)
            Output$ + ReadProgramString(shell)
            If AddReturns : Output$ + Chr(10) : EndIf
         EndIf
         tmper$ = ReadProgramError(shell)
         If tmper$ : Err$ + tmper$ + Chr(10) : EndIf
      Wend
      Exc = ProgramExitCode(shell) : CloseProgram(shell)
   EndIf
   Sh\Out = Output$ : Sh\Err = Err$ : Sh\ExC = Exc
EndProcedure

Procedure.s QP(str$) ; to quote paths
   ProcedureReturn "'" + ReplaceString(str$, "'", "'\''") + "'"
EndProcedure

Shell("pbcompiler "+QP(ProgramParameter())+" -q -pp /dev/stdout")
Result = MessageRequester("Preprocessed:", Left(Sh\Out, 80)+~"…\n\n\nCopy to clipboard?", #PB_MessageRequester_YesNo)
If Result = #PB_MessageRequester_Yes    ; pressed Yes button
   SetClipboardText(RTrim(Sh\Out,Chr(10)))
EndIf