QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: krovit on October 07, 2021, 03:52:46 am

Title: '$INCLUCE as text
Post by: krovit on October 07, 2021, 03:52:46 am
Hello to all of you, these are difficult times... I hope you are (we are) all well.

I would like to read the command '$INCLUDE opening the BAS file with OPEN.
It seems to me that the string read (LINE INPUT#) completely ignores the content and cannot see '$INCLUDE.

Obviously all other strings are read regularly and can be manipulated.

Am I doing something wrong?


Title: Re: '$INCLUCE as text
Post by: SMcNeill on October 07, 2021, 04:14:22 am
Share some code please.
Title: Re: '$INCLUCE as text
Post by: krovit on October 07, 2021, 04:34:24 am
Thanks Neill you caught me in foul
rewriting from scratch a few lines of elementary code the problem does not arise
evidently there must be a problem that I can not see in the general code of the application I am developing
so it's a false alarm...
Sorry

if it will be necessary I will come back to disturb you (I usually try not to do it)
Title: Re: '$INCLUCE as text
Post by: George McGinn on October 07, 2021, 12:06:51 pm
@krovit,The following routine is from @luke's incmerge program.

This opens an '$INCLUDE: file, and reads it as input into the program. His utility opens a QB64 source and replaces the $INCLUDE with the code that is in that file. You should be able to change it to your needs.

Code: QB64: [Select]
  1. SUB process (filename$)
  2.     inclCount = inclCount + 1
  3.     IF NOT silentSW THEN
  4.         IF inclCount > 1 THEN PRINT "    Include File Found: "; filename$
  5.     END IF
  6.     fh = FREEFILE
  7.     IF _FILEEXISTS(filename$) THEN
  8.                 OPEN filename$ FOR BINARY AS #fh
  9.                 DO
  10.                         LINE INPUT #fh, l$
  11.                         IF INSTR(LTRIM$(l$), "'$include") = 1 OR INSTR(LTRIM$(l$), "'$INCLUDE") THEN
  12.                                 t$ = LTRIM$(l$)
  13.                                 q1 = INSTR(2, t$, "'")
  14.                                 q2 = INSTR(q1 + 1, t$, "'")
  15.                                 process MID$(t$, q1 + 1, q2 - q1 - 1)
  16.                         ELSE
  17.                                 PRINT #1, l$
  18.                         END IF
  19.                 LOOP UNTIL EOF(fh)
  20.         ELSE
  21.                 PRINT USING "Error - File: & Not Found."; filename$
  22.                 CLOSE #fh
  23.                 KILL COMMAND$(2)
  24.                 SYSTEM 1
  25.         END IF 
  26.     CLOSE #fh