D&Dbrowser

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: D&Dbrowser

Post by rbytes »

Ton, I looked a bit closer at the errors generated in my SB Notes code I downloaded with the D&D browser. I can see now that many special characters were simply swapped with their HTML identifiers - eg &amp; for the & character, &lt; for the < character, &gt; for the > character, and so on. In a large program, the time it would take to deal with these changes would be prohibitive. I think it would be better to encode the programs via Makeinstall, or transfer them via the photo-with-attached-code or photo-with-visual-bits methods. What are your thoughts?
The only thing that gets me down is gravity...

User avatar
Dutchman
Posts: 851
Joined: Mon May 06, 2013 9:21 am
My devices: iMac, iPad Air, iPhone
Location: Netherlands
Flag: Netherlands

Re: D&Dbrowser

Post by Dutchman »

In my folder "File transfer" on Dropbox (https://www.dropbox.com/sh/baavn06jne57 ... S4FDa?dl=0) there is the program "Clarify code.sb" in which HTML-entities are converted to their original characters.
Here is the code:

Code: Select all

'Clarify code, by Dutchman September 2017
'Certain characters have special significance in HTML,
'	and are represented by HTML entities if they are to
' 	preserve their meanings. See DATA
'The function Convert$() returns strings in which these
'	entities are converted to the original characters.
'

{preferences.default}
InFile$="code.dump-001"
OutFile$="Clarified.sb"
InDir$=DumpDir$
OutDir$="Downloads"
'
'--- In and out-file
In$=InDir$&"/"&InFile$
Out$=OutDir$&"/"&OutFile$
IF NOT FILE_EXISTS(OutDir$&"/") THEN DIR OutDir$ CREATE
'
OPTION BASE 1
CALL Convert$("") ' init conversion
IF NOT FILE_EXISTS(In$) THEN
  PRINT "File """&In$&""" not found."
  stop
ENDIF
'
IF FILE_EXISTS(Out$) THEN FILE Out$ DELETE
WHILE NOT FILE_END(In$)
  FILE In$ READLINE Line$
  FILE Out$ WRITELINE Convert$(Line$)
END WHILE
PRINT "Clarified code written to """&out$&"""."
END
'
DEF Convert$(text$) ' by Dutchman
'Certain characters have special significance in HTML,
'	and are represented by HTML entities if they are to
' 	preserve their meanings. See DATA
'The function Convert$() returns strings in which these
'	entities are converted to the original characters.
IF NOT preset THEN GOSUB Init 'local
FOR i=1 TO n ' for all codes
  c=INSTR(Text$,Code$(i))
  WHILE C>0
    lt=LEN(Text$)
    t1$=LEFT$(Text$,c-1)
    t2$=RIGHT$(Text$,lt-c-Size(i)+1)
    Text$=T1$&Set$(i)&T2$
    c=INSTR(Text$,Code$(i))
  END WHILE
NEXT i
RETURN Text$
'--- local subroutines
Init:
  n=5
  DIM Code$(n), Set$(n)
  RESTORE
  FOR i=1 TO n
    READ Code$(i), Set$(i)
    Size(i)=LEN(Code$(i)) ' length of code
  NEXT i
  preset=1
RETURN ' from subroutine
'code, replace
DATA "&amp;","&","&quot;","""","&#039;","'","&lt;","<","&gt;",">"
END DEF
You should adapt the following section (at the beginning of the program) to your own targets:

Code: Select all

{preferences.default}
InFile$="code.dump-001"
OutFile$="Clarified.sb"
InDir$=DumpDir$
OutDir$="Downloads"

User avatar
rbytes
Posts: 1338
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone 11 Pro Max
iPad Pro 11
MacBook
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

Re: D&Dbrowser

Post by rbytes »

Thanks for pointing this out. I have read the instructions a few times, but should review them again. :oops:
The only thing that gets me down is gravity...

Post Reply