Qbasicnews.com
August 26, 2019, 12:35:10 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Challenge....  (Read 2934 times)
BinarySHOCK
Forum Regular
**
Posts: 117



WWW
« on: November 04, 2004, 05:59:27 AM »

Write a qbasic Quine, for those of you who don't know a quine is a program that when run outputs it's source, you may not use the open command that is just a weak hack and not really a true quine, but to give u a better idea of what needs to be done i'll show you a example using the hack...

Code:


Open "ThisFile.Bas" For input as #1
     While Not Eof(1)
            Line Input #1, ProgLine$
            Print ProgLine$
     Wend
Close #1



Save it as thisfile.bas and run it to see the results correctly.

Just remember you may not use anything similar to the above, it's just there to show you what your program should do.

Good luck it's not a easy challenge.
Logged

very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Antoni Gual
Na_th_an
*****
Posts: 1434



WWW
« Reply #1 on: November 04, 2004, 12:02:59 PM »

This challenge has already been proposed here...

My entry: Two lines and a comment
Code:

A$="PRINT MID$(A$,43);CHR$(34);A$;CHR$(34);A$'A$="
PRINT MID$(A$,43);CHR$(34);A$;CHR$(34);A$'A$=


edited:
In GW-BASIC it was easier:
Code:

1 LIST
Logged

Antoni
Meg
Ancient QBer
****
Posts: 483


« Reply #2 on: November 04, 2004, 01:17:14 PM »

I am guessing this will also be considered a cheap solution:

Code:
SHELL "type ThisProgram.bas"


*peace*

MB.
Logged
Neo
Na_th_an
*****
Posts: 2150



« Reply #3 on: November 04, 2004, 03:24:42 PM »

Since everyone posted easy solutions, I now post a hard solution Wink

[syntax="QBasic"]'// ThisFile.bas
'// Prints out this file's contents Smiley

'$INCLUDE: 'QB.BI'
DIM RegsX AS RegTypeX

'clear screen
CLS

'open the file
RegsX.ax = &H3D00
FILE$ = "THISFILE.BAS" + CHR$(0)
RegsX.ds = VARSEG(FILE$)
RegsX.dx = SADD(FILE$)
CALL INTERRUPTX(&H21, RegsX, RegsX)
Hand% = RegsX.ax

'read file data
RegsX.ax = &H3F00
RegsX.bx = Hand%
RegsX.cx = 1024
DIM Buffer AS STRING * 1024
RegsX.ds = VARSEG(Buffer)
RegsX.dx = VARPTR(Buffer)
CALL INTERRUPTX(&H21, RegsX, RegsX)

'close file
RegsX.ax = &H3E00
RegsX.bx = Hand%
CALL INTERRUPTX(&H21, RegsX, RegsX)

'convert \lf to nothing (leaving \cr only)
A$ = ""
FOR i = 1 TO LEN(Buffer)
   IF MID$(Buffer, i, 1) <> CHR$(10) AND MID$(Buffer, i, 1) <> CHR$(0) THEN
      A$ = A$ + MID$(Buffer, i, 1)
   END IF
NEXT i
PRINT A$

END 'end the prog reading itself Smiley[/syntax]

Have fun Smiley

NOTE: It doesn't use QB's OPEN command Wink It uses DOS's commands for file handling Smiley
Btw, did I use "anything similar"?


There are several options to work out this challenge:
#1: Using QB commands like OPEN like BinarySHOCK's example
#2: Hardcode like Antoni Gual's code
#3: Via shell like Meg's code
#4: Using DOS interrupts
And the last I can think of:
#5: Compile the program as EXE file, find the EXE location in memory, read EXE data and decode this to QB code.
Logged
BinarySHOCK
Forum Regular
**
Posts: 117



WWW
« Reply #4 on: November 04, 2004, 07:18:35 PM »

sorry guess i didn't notice the other quine challege, and as far as i could tell neo you just open the file up with interupts, which is esstentially the same thing IMO but as i didn't specify that...
Logged

very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!