April 20, 2024, 05:59:33 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


A change of pace...

Started by LarryMc, May 30, 2012, 10:16:40 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LarryMc

When I'm working on some code, whether it's a project of mine or something I'm doing to try and help a forum member, I'm constantly looking for bits and pieces of code.

I always cut and paste when i can as opposed to coding from scratch.  As a result I look in numerous places for pieces of code.
One of the resources i often use is the Forum CD from the old Pyxia website.

When I try to copy code from that program, which appears like you are looking at an actual forum website, sometimes it works and sometimes it doesn't.

It seems that a lot of the code, stored in html format, has no CRLFs.  If you select the code and copy and paste it into an iwb file it is just one long string.

I decided tonight to take a break from the new IDE and write me a little utility to solve that issue for myself.
I took the RichEdit example program and modified it.
To use it, copy the web page  in question that contains the code you want, to a file as html.
Run the utility and load the html file.  Click the button to Strip.  It will discard all code except that code that is in a < pre > < / pre > block.
That's how CODE: blocks are saved in the forum.
It will then change all the BR html code to CRLF, plus convert some other escape sequences.
You can then copy and paste the code you want into your program.
Note that some html code already has CRLFs in addition to the BRs which will result in double spacing.

Anyway, maybe it will help someone:
istring trans[64000]
$include "windowssdk.inc"
$include "commctrl.inc"
InitCommonControls()
DEF d1:Dialog
DEF textclr,size,weight,bold,flags:INT
DEF fontname,oldfont,filename,filter:STRING
DEF file1:FILE
'the default font properties
fontname = "Tahoma"
oldfont = fontname
size = 10
weight = 400
filter = "HTML file (*.htm;*html)|*.htm;*html||"
filename=getstartpath+"test.htm"
CREATEDIALOG d1,0,0,577,360,0x80C80080|@SIZE,0,"Strip HTML",&Handler
CONTROL d1,@RICHEDIT,"",7,35,570,294,0x50B010C4,1
CONTROL d1,@BUTTON,"Strip",11,9,46,23,0x50000000,3
CONTROL d1,@RICHEDIT,"",578,35,570,294,0x50B010C4|@SYSMENU,4

DOMODAL d1
END

SUB Handler
SELECT @MESSAGE
CASE @IDINITDIALOG
CENTERWINDOW d1
BEGINMENU d1
MENUTITLE "File"
MENUITEM "Save",0,6
MENUITEM "Load",0,7
MENUITEM "Print",0,11
SEPARATOR
MENUITEM "Quit",0,1
'
MENUTITLE "Edit"
MENUITEM "Undo",0,2
MENUITEM "Cut",0,3
MENUITEM "Copy",0,4
MENUITEM "Paste",0,5
'
ENDMENU
'default font and color
CONTROLCMD d1,1,@RTSETDEFAULTFONT,fontname,size,0,0
CONTROLCMD d1,1,@RTSETDEFAULTCOLOR,RGB(0,0,0)
'margins
CONTROLCMD d1,1,@RTSETMARGINS,10,10
'7.5 inch line size
CONTROLCMD d1,1,@RTSETLINEWIDTH,770 * 15
'128K text limit
CONTROLCMD d1,1,@RTSETLIMITTEXT,128000
CONTROLCMD d1,2,@RTSETDEFAULTFONT,fontname,size,0,0
CONTROLCMD d1,2,@RTSETDEFAULTCOLOR,RGB(0,0,0)
'margins
CONTROLCMD d1,2,@RTSETMARGINS,10,10
'7.5 inch line size
CONTROLCMD d1,2,@RTSETLINEWIDTH,770 * 15
'128K text limit
CONTROLCMD d1,2,@RTSETLIMITTEXT,128000
SETCONTROLCOLOR d1,3,0,RGB(255,255,0)

CASE @IDCONTROL
SELECT @CONTROLID
CASE 3:'strip
if @notifycode=0
SETCONTROLCOLOR d1,3,0,RGB(255,0,0)
wait 1
start=0
cend=0
label redo
inpre=0
text$="<pre>"
start = CONTROLCMD (d1,1, @RTFINDTEXT, text$, start, 1)
if start <>-1
text$="</pre>"
cend = CONTROLCMD (d1,1, @RTFINDTEXT, text$, start, 1)
if cend<>-1
CONTROLCMD d1,1, @RTSETSELECTION, start+5, cend
CONTROLCMD d1,1, @RTCOPY
CONTROLCMD d1,4, @RTPASTE
start=cend
goto redo
endif
endif
convert ("\n<br>",chr$(13))
convert ("<br>",chr$(13))
convert ("&nbsp;"," ")
convert ("&quot;","\"")
convert ("&amp;","&")
convert ("&#124;","|")
convert ("&lt;","<")
convert ("&gt;",">")
convert ("&#58;",":")
convert ("&#40;","(")
convert ("&#41;",")")

CONTROLCMD d1,1, @RTSETSELECTION, 0, -1
CONTROLCMD d1,1, @RTDELETESEL
CONTROLCMD d1,4, @RTSETSELECTION, 0, -1
CONTROLCMD d1,4, @RTCOPY
CONTROLCMD d1,1, @RTPASTE
CONTROLCMD d1,4, @RTDELETESEL
SETCONTROLCOLOR d1,3,0,RGB(255,255,0)
endif
ENDSELECT
CASE @IDMENUPICK
SELECT @MENUNUM
CASE 1:'Quit
CLOSEDIALOG d1,@IDOK
CASE 2:'Undo
CONTROLCMD d1,1,@RTUNDO
CASE 3:'Cut
CONTROLCMD d1,1,@RTCUT
CASE 4:'Copy
CONTROLCMD d1,1,@RTCOPY
CASE 5:'Paste
CONTROLCMD d1,1,@RTPASTE
CASE 6:'SAVE
filename = FILEREQUEST("Save file",d1,0,filter,"htm")
if(len(filename))
if(OPENFILE(file1,filename,"W")=0)
CONTROLCMD d1,1,@RTSAVE,file1,0
CLOSEFILE file1
endif
endif
CASE 7:'LOAD
filename = FILEREQUEST("Load file",d1,1,filter,"htm")
if(len(filename))
if(OPENFILE(file1,filename,"R")=0)
CONTROLCMD d1,1,@RTLOAD,file1,0
CLOSEFILE file1
endif
endif
CASE 8:'Subscript
CONTROLCMD d1,1,@RTSETCHAROFFSET,-((size / 2) * 20)
CASE 9:'Superscript
CONTROLCMD d1,1,@RTSETCHAROFFSET,((size / 2) * 20)
CASE 10:'normal
CONTROLCMD d1,1,@RTSETCHAROFFSET,0
CASE 11:'Print
CONTROLCMD d1,1,@RTPRINT,0


ENDSELECT
CASE @IDMENUINIT
'only enable the Undo menu if there is something to..undo
ENABLEMENUITEM d1,2,CONTROLCMD(d1,1, @RTCANUNDO)
ENDSELECT
RETURN
ENDSUB

sub convert(string text$,string text2$)
pos = CONTROLCMD (d1,4, @RTFINDTEXT, text$, 0, 1)
while pos <>-1
CONTROLCMD d1,4, @RTSETSELECTION, pos, pos+len(text$)
CONTROLCMD d1,4, @RTREPLACESEL, text2$
pos = CONTROLCMD (d1,4, @RTFINDTEXT, text$, pos+1, 1)
endwhile
return
endsub
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Brian

Larry,

I seem to remember that I copied the code from the CD, and pasted it into Notepad, and
then saved it. Haven't done any for a while, though

Brian

LarryMc

Quote from: Brian Pugh on May 31, 2012, 01:57:17 AM
Larry,

I seem to remember that I copied the code from the CD, and pasted it into Notepad, and
then saved it. Haven't done any for a while, though

Brian

Some will work in notepad and some won't.I guess the difference is in how the poster pasted originally.

Attached is the test file I was using with my little utility.
The very first code: block doesn't work correctly in notepad.
Go down to the last code block and it does format correctly in notepad.

The first has no embedded CRLFs and the last does.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bill-Bo

Larry and Brian,

What I do is save the webpage as complete. Then I delete
the ...files subdirectory leaving the *.htm file. The program(s)
code is no longer in a code window and I can copy and paste
with no problem.

Bill

LarryMc

Quote from: Bill-Bo on May 31, 2012, 08:10:00 AM
Larry and Brian,

What I do is save the webpage as complete. Then I delete
the ...files subdirectory leaving the *.htm file. The program(s)
code is no longer in a code window and I can copy and paste
with no problem.

Bill
The area I'm having the problem with is in the browser window that is part of the program that reads the pyxia forums database.
There is no option to save the displayed html page, in any form.  The right-click menu lets me view source and then I can save that.
And when there are no end of line markers there isn't much you can do.
(I can remember years ago using a program to take all the 'air' out of a html page and that is what this looks like.)

So, in this case, your solution is not an option. But I have used your option successfully before.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

Bill-Bo

May 31, 2012, 08:51:15 AM #5 Last Edit: May 31, 2012, 09:03:57 AM by Bill-Bo
Larry and Brian,

Dah. I looked at the test.htm. I think you do the
same thing.

The reason I save as a complete page and then
delete the ...files page, is that saving as 'page
only' can display as the webpage, but without the
graphics (pictures, icons, etc.). Plus, you still
have the code window.

Bill

P.S. Is there a download for the latest inc's??
I found and clicked the link. The file is "not
available."

Bill-Bo

Larry,

Sorry. I must have been typing my last reply as you was sending yours.
I must not have read the fine print. Good luck.

Bill

billhsln

This is not an answer, it is a question.

If you would save the file and bring it up in a browser, could it be saved in a more useable format?

Just wondering,
Bill
When all else fails, get a bigger hammer.

LarryMc

Quote from: billhsln on May 31, 2012, 10:55:17 AM
This is not an answer, it is a question.

If you would save the file and bring it up in a browser, could it be saved in a more useable format?

Just wondering,
Bill
No, if the CRLFs aren't there to begin with nothing magically inserts them.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library