|
Post by Carl Gundel on Apr 22, 2019 12:22:02 GMT -5
Challenge: Using httpget$(), write a utility that reads the rosettacode.org website and aggregates all the Liberty BASIC examples and open then in a window with a list of the entry names on the left. Clicking on an entry produces the code for the entry on the right.
|
|
|
Post by tenochtitlanuk on Apr 22, 2019 16:11:28 GMT -5
Would be easier and more direct now- so perhaps someone with time can update it!
|
|
|
Post by Carl Gundel on Apr 23, 2019 9:45:07 GMT -5
Would be easier and more direct now- so perhaps someone with time can update it!
Thanks John. I had forgotten about this.
|
|
|
Post by Brandon Parker on Feb 11, 2020 19:07:39 GMT -5
Would be easier and more direct now- so perhaps someone with time can update it!
Hey John, It seems like something has changed as your code is no longer working for me. I figured I would give you the opportunity to resolve the issue first. {:0) Brandon Parker
|
|
|
Post by tenochtitlanuk on Feb 12, 2020 9:09:57 GMT -5
Hi Brandon Thanks for 'giving me the opportunity'! Always glad to hear someone has tried my code, even if there is a problem.
The page layout code on the Rosetta code site has changed. I'm currently running with new start strings and it seems to run OK. I haven't used the newer LB functions in the parsing code.
Can't vouch for the running of each LB code it downloads! ( especially as I run under linux with different path names and structure)
I'll put the corrected updated code on here first. If no-one finds errors will chaŋge on Rosetta if I remember my password.
JohnF
he following 335 pages are in this category, out of 335 total. 1
100 doors 15 Puzzle Game
2
24 game 24 game/Solve
9
99 Bottles of Beer 99 Bottles of Beer/Basic
A
A+B ABC Problem Abundant, deficient and perfect number classifications Ackermann function AKS test for primes Align columns Aliquot sequence classifications Almost prime Anagrams Anagrams/Deranged anagrams Animate a pendulum Animation Arbitrary-precision integers (included) Arithmetic evaluation Arithmetic-geometric mean Arithmetic/Complex Arithmetic/Integer Arithmetic/Rational Array concatenation Array length Arrays Assertions Associative array/Creation Associative array/Iteration AudioAlarm Average loop length Averages/Arithmetic mean Averages/Mean angle Averages/Mean time of day Averages/Median Averages/Mode Averages/Pythagorean means Averages/Root mean square Averages/Simple moving average
B
Babbage problem Balanced brackets Balanced ternary Benford's law Best shuffle Binary digits Binary search Binary strings Bitmap/Flood fill Bitwise operations Boolean values Box the compass Brownian tree Bulls and cows Bulls and cows/Player
C
Caesar cipher Call a function Case-sensitivity of identifiers Catalan numbers Character codes Check that file exists Circles of given radius through two points Closest-pair problem Color of a screen pixel Colour bars/Display Comma quibbling Command-line arguments Comments Constrained random points on a circle Convert decimal number to rational Convert seconds to compound duration Conway's Game of Life Copy a string Count in factors Count in octal Count occurrences of a substring Create a file Create a two-dimensional array at runtime Create an HTML table CSV to HTML translation Cumulative standard deviation
D
Date format Day of the week Delete a file Detect division by zero Determine if a string is numeric Determine if only one instance is running Dot product Doubly-linked list/Traversal Dragon curve Draw a clock Draw a cuboid Draw a sphere
E
Empty directory Empty program Empty string Entropy Environment variables Equilibrium index Ethiopian multiplication Evaluate binomial coefficients Even or odd Evolutionary algorithm Execute a system command Execute HQ9+ Exponentiation operator
F
Factorial Factors of an integer Fast Fourier transform Fibonacci sequence File input/output File size Filter Find common directory path Find limit of recursion Find the last Sunday of each month FizzBuzz FizzBuzz/Basic Floyd's triangle Formatted numeric output Fractal tree Function definition
G
Globally replace text in several files Gray code Greatest common divisor Greatest element of a list Greatest subsequential sum Greyscale bars/Display Guess the number Guess the number/With feedback Guess the number/With feedback (player) GUI component interaction GUI enabling/disabling of controls
H
Hailstone sequence Hamming numbers Handle a signal Happy numbers Haversine formula Hello world/Graphical Hello world/Newline omission Hello world/Text Hello world/Web server Honeycombs Horizontal sundial calculations Horner's rule for polynomial evaluation Hostname HTTP
I
Image convolution Image noise Increment a numerical string Input loop Integer comparison Integer sequence
J
Joystick position
K
Kaprekar numbers Keyboard input/Obtain a Y or N response Knuth shuffle
L
Langton's ant Leap year Least common multiple Letter frequency Levenshtein distance Linear congruential generator Literals/String Logical operations Long multiplication Longest common subsequence Loop over multiple arrays simultaneously Loops/Break Loops/Continue Loops/Do-while Loops/Downward for Loops/For Loops/For with a specified step Loops/Foreach Loops/Infinite Loops/N plus one half Loops/Nested Loops/While Luhn test of credit card numbers LZW compression
M
Mad Libs Magic squares of odd order Mandelbrot set Matrix multiplication Matrix transposition Matrix-exponentiation operator MD5 MD5/Implementation Metronome Miller–Rabin primality test Monte Carlo methods Monty Hall problem Morse code Mouse position Multiplication tables Munching squares Mutual recursion
N
N'th N-queens problem Narcissist Non-decimal radices/Convert Nth root Numerical integration
O
Old lady swallowed a fly One of n lines in a file One-dimensional cellular automata OpenGL Ordered words
P
Palindrome detection Pangram checker Parsing/RPN calculator algorithm Parsing/Shunting-yard algorithm Pascal's triangle Percentage difference between images Perfect numbers Permutations Pi Pick random element Pinstripe/Display Pinstripe/Printer Play recorded sounds Playing cards Plot coordinate pairs Price fraction Primality by trial division Probabilistic choice Problem of Apollonius Program name Program termination Pythagorean triples
Q
Quaternion type Quine
R
Random numbers Range expansion Range extraction Rate counter Ray-casting algorithm Read a configuration file Read a file line by line Read a specific line from a file Read entire file Real constants and functions Record sound Remove duplicate elements Remove lines from a file Rename a file Repeat a string Return multiple values Reverse a string Reverse words in a string Rock-paper-scissors Roman numerals/Decode Roman numerals/Encode Roots of a function Roots of a quadratic function Roots of unity Rosetta Code/Run examples Rot-13 Run-length encoding Runge-Kutta method Runtime evaluation Runtime evaluation/In an environment
S
Scope modifiers Search a list SEDOLs Self-describing numbers Semordnilap Send email Sequence of non-squares Sequence of primes by trial division Set Seven-sided dice from five-sided dice SHA-1 Shell one-liner Short-circuit evaluation Sierpinski carpet Sierpinski triangle Sierpinski triangle/Graphical Sieve of Eratosthenes Simple windowed application Sleep Sort an array of composite structures Sort an integer array Sort stability Sorting algorithms/Bubble sort Sorting algorithms/Comb sort Sorting algorithms/Heapsort Sorting algorithms/Insertion sort Sorting algorithms/Merge sort Sorting algorithms/Selection sort Sorting algorithms/Shell sort Speech synthesis Spiral matrix Stack Stair-climbing puzzle Statistics/Basic Statistics/Normal distribution String case String concatenation String length String matching Strip a set of characters from a string Strip block comments Strip comments from a string Strip control codes and extended characters from a string Strip whitespace from a string/Top and tail Substring Substring/Top and tail Sum and product of an array Sum of a series Sum of squares System time
T
Terminal control/Cursor positioning Ternary logic Tokenize a string Towers of Hanoi Trigonometric functions Truncate a file Truth table
U
URL decoding URL encoding User input/Graphical User input/Text
V
Variables Vector products Verify distribution uniformity/Naive Vigenère cipher Voronoi diagram
W
Web scraping Window creation Wireworld Write language name in 3D ASCII
X
Xiaolin Wu's line algorithm
Y
Yin and yang
|
|
|
Post by tenochtitlanuk on Feb 12, 2020 18:20:08 GMT -5
I've had to play quite lot over two or three hours on this. It presently runs and claims to have downloaded the code for all current entries.
BUT
Several points I need to deal with- some caused by Rosetta Code structure and changes.
Some of LB entries are in Rosetta Code/Liberty BASIC, but a significant number are grouped under a general BASIC section, sub-section Liberty BASIC, ie Rosetta Code/BASIC/Liberty BASIC. My existing code scrambles data in these cases since it id not expect this html variation of structure.
Some entries have NO LB code, but a reference to another page or language. Again scrambled because not expected by my code.
At present I didn't check for <& a m p ;> and replace with '&' in the text, so it embeds a chr$( 0) by mistake. Correctable.
At present some pages are downloaded and saved but with a chr$( 10) at the beginning. This makes code editor interpret the whole code as UTF and looks very odd in weird scripts!!
I noticed one INCORRECT entry for 'User input/Text' which asks for two inputs but does not print them. Task spec'n may have changed?? Another one required a library code on the extinct wiki in order to run....
I haven't checked the section of my code which tries to run each example ( which used to work fine), but the saved code of all the examples generally runs with the exception of those in the above list. Until I modify the identified problem bits, you can change the saved code by hand -'UTF' cases are easily edited by hand to get rid of the chr$( 10); The ampersand can be substituted for the chr$( 0)s.
I'll see what I can do- a bit occupied by other things this year.
|
|
|
Post by tenochtitlanuk on Feb 13, 2020 18:23:25 GMT -5
Currently successfully downloading 500+ LB programs with the updated version. Now to find a Windows machine to see if the 'run with LB' still works!
Meanwhile two new RC entries suddenly added to the list, confusingly, including the 'Calendar' one with an ASCII art Snoopy added! And the 'Magic Ball"..
The ones where LB is a sub-section of a general BASIC section do NOT download correctly. MAY try to change this.
I've located the subList+ library that was needed for one entry, but not edited RCode at all yet- if I do I'll have to point to a new host for the files ( could be on my site??).
'Colour of a screen pixel' and 'Mouse Position' seem odd or dated- to find pointer position and colour on a graphic screen? Task is not entirely clear.
'Hello World web server' seems to be a RunBASIC solution??
|
|
|
Post by tenochtitlanuk on Feb 14, 2020 14:46:44 GMT -5
Ploughing my way through Rosetta Code, checking them as I go. In first 62 I found-
Two where Jack Kelly ( if still around will be in his late 70s now) has supplied code that works only in LBB ( Arithmetic_Rational and 'Babbage_problem'. Naughty.
The 'Associative array...' examples need the sublist - where should we put this and re-link?
"bitmap floodfill' has the version we know doesn't work. Rod/Brandon perhaps choose corrected version??? ( following the discussion on hgere recently
'Box the compass' is missing final '"'.
'Abundant, def...' is VERY slow and has no mechanism to interrupt and stop.
'Arbitrary precision...' is VERY slow in LB yet fast in RunBASIC. Why???
At this rate it'll take some time to even locate the rest of any previously not noticed LB errors on RC. That's my priority.
Very happy for others to edit them.... it's a shame that a new user looking at code on RC may get landed with these small number of errors.
It would help if anyone altering or adding to Rosetta Code put a note on this board. Those who don't observe this nicety- they know who they are, and are visible on the 'history of edits' page- are muddying the water.
|
|
|
Post by Carl Gundel on Feb 17, 2020 10:01:46 GMT -5
Here's a thought that could bring more people to Liberty BASIC. A version of the aggregator that let's you aggregate for any language on Rosetta Code.
|
|
|
Post by tenochtitlanuk on Feb 17, 2020 11:23:31 GMT -5
I'm unlikely to do much further on my version in the next few weeks.
Version below, given an hour or so, will download most of the LB entries. It is messy but well annotated code.
I can't get the address right on my Linux/Wine/LB set-up to get the auto run of liberty.exe to find the code of the saved tasks.
Various rem-med lines change it from downloading ALL current tasks, or to asking you which you want.
Pages with just a note on RC and no code will download nonsense. And the LBB code mentioned elsewhere won't run, or will run wrongly. Haven't time yet to check if all code runs- and some need auxiliary files downloaded too- I downloaded them to my folder of LB solution code.
It IS nice to have a single folder on my machines holding all current entries, but I'd always download direct from Rosetta Code in case of editing- not every solver or editor notifies the community here of entries or improvements! On my brief checks under W10 I keep re-inventing the 'LB bomb', with it loading and running further copies of itself ( reference set to 'load last program on start')
' ******************************************************************** ' ** ** ' ** parseAndRun.bas v26b tenochtitlanuk November 2012 ** ' ** RC-findInRCpatched3e6.bas tenochtitlanuk February 2020 ** ' ** ** ' ** ** ' ** Select a LB solution from RC site & run it locally ** ' ** ** ' ********************************************************************
' filename to save downloaded HTML: Source$ = "source.htm"
' nomainwin
' Download main RC LB page which has current tasks on it. Save as 'source.htm' ' run "C:\Program Files\Mozilla Firefox\firefox.exe http://rosettacode.org/wiki/Category:Liberty_BASIC" 'testing routine print " Fetching current RC page of completed Liberty BASIC RC solutions."
result = DownloadToFile( "http://rosettacode.org/wiki/Category:Liberty_BASIC", Source$)
if result <>0 then print "Error downloading LB solved tasks.": end else print: print " Displaying solved tasks.": print
' Load source into a string. Go through and save in a 2D array all topic titles ' and the appropriate web addresses to find them.
open Source$ for input as #f html$ = input$( #f, lof( #f)) close #f
' kill Source$ 'remove temp file
dim solutions$( 500, 2) ' we don't have more than 500 done yet on RC! First column =title, second =web address
global count count =1 first =0 last =0 reading =0
' The first topic is the '100 doors' so skip all html jump ref's earlier than this. do r$ =getHtmlSection$( html$, first, last) ' keep looking for fragments that are html jumps to addresses ie '<a href=" ....... "'.
if instr( r$, "/rosettacode.org/mw/index.php") then exit do ' We've read all LB solved tasks. <<<<< not working??? if count =340 then exit do ' We've read all LB solved tasks.
if r$ ="wiki/100_doors" then reading =1
' / if reading =1 then ' we can start recording name and URL ( and section) of LB part, eg 'http://rosettacode.org/wiki/100_doors#Liberty_BASIC'
' ' but some are eg 'http://rosettacode.org/wiki/99_Bottles_of_Beer/Basic#Liberty BASIC'
solutions$( count, 1) ="http://rosettacode.org/" +r$ +"#Liberty_BASIC"
special =instr( r$, "%2B"): if special <>0 then r$ =left$( r$, special -1) +"+" +mid$( r$, special +3) special =instr( r$, "%27"): if special <>0 then r$ =left$( r$, special -1) +"'" +mid$( r$, special +3) special =instr( r$, "%C3%A8"): if special <>0 then r$ =left$( r$, special -1) +chr$( 232) +mid$( r$, special +6)
m$ =mid$( r$,6) solutions$( count, 0) =mid$( r$, 6) ' we want the bit beyond '/wiki/'
if instr( solutions$( count, 0), "/") then ' not allowable in filenames for storing on disk. newName$ =""
for ii =1 to len( solutions$( count, 0) ) n$ =mid$( solutions$( count, 0), ii, 1) if n$ ="/" then n$ ="_" newName$ =newName$ +n$ next ii
solutions$( count, 0) =newName$ end if
print count, solutions$( count, 0); solutions$( count, 1) print tab( 10); newName$
count =count +1 end if
loop until 0
print: print count -1; " tasks solved in LB."
timer 2000, [o] wait [o] timer 0
cls ' omit$ =" 5 6 26 41 65 73 79 86 94 101 135 171 176 301 318 335 337 " for various reasons
input " Choose task # "; R ' Choose a page to try. ' R =4 ' ' for R =1 to count -1 ' use a loop if you want all.... otherwise select with R
print print " Choosing task viz #"; R; " out of "; count -1; " completed in LB." print " Task is "; chr$( 34); solutions$( R, 0); chr$( 34) print
'********************run "C:\Program Files\Mozilla" +chr$( 34) +" " +chr$( 34) +"Firefox\firefox.exe " +solutions$( R, 1)
' Fetch the RC task page with all the sol'ns including LB one. print " Downloading the page for this task."
print , solutions$( R, 1) result = DownloadToFile( solutions$( R, 1), "rx_" +right$( "000" +str$( R), 4) +".htm")
if result <>0 then print " Error downloading.": end
print " Now finding the LB section of the html code." ' Now finding the appropriate LB section on this topic.
open "rx_" +right$( "000" +str$( R), 4) +".htm" for input as #r L =lof( #r) print " Length of source html of this topic's page is "; L t$ =input$( #r, L) close #r
preamble$ ="Liberty BASIC" +chr$( 34) +">edit</a><span class=" +chr$( 34) +"mw-editsection-bracket" +chr$( 34) +">]</span></span></h2>" +chr$( 10)
lP =len( preamble$) print " Finding the preamble string at "; beg =instr( t$, preamble$)' +len( preamble$) print beg
lookFor$ ="source" +chr$( 34) +">" beg =instr( t$, lookFor$, beg) ' get to start of BASIC code. beg =beg +len( lookFor$)
print " Found LB section at "; beg;
fin =instr( t$, "</pre>", beg) print " and ending at "; fin
print " Chopping off unwanted earlier & later sections of html source." t$ =mid$( t$, beg, fin -beg) ' discard earlier & later parts of html code. ' print t$ ' <<<<<<<<<<< print
' open solutions$( R, 0) +".txt" for output as #LbText ' #LbText t$; ' close #LbText
L =len( t$)
print " Relevant html code LB section being parsed for LB BASIC code."
' Read the rest of the LB code section to </pre> section .. LB$ ="" j =1
print " Dropping html tags & translating html entities." print print " LB code follows." print "______________________________________________________________________" print
do nxtChr$ =mid$( t$, j, 1)
select case ' _______________________________________________________________________________________________________ case ( nxtChr$ =chr$( 10)) or ( nxtChr$ =chr$( 13)) j =L ' print "End reached- CRLF"
case nxtChr$ ="<" ' we've found a html tag. Omit. ' print " Starting a tag with a <"; item$ ="<" do ' keep looking until find a '>' or finish... j =j +1 nxtChr$ =mid$( t$, j, 1) item$ =item$ +nxtChr$ loop until nxtChr$ =">" ' print " Closing a tag with a >." if item$ ="</pre>" then j =L ' end reached if item$ ="<br />" then LB$ =LB$ +chr$( 10) ' code for CRLF if item$ ="<br/>" then LB$ =LB$ +chr$( 10) ' code for CRLF, now if j <>L then j =j +1
case nxtChr$ ="&" ' we've found an html entity. ' replace with plain-text equivalents. ' print " html entity starting with & "; ' Need pure ASCII for BASIC text
select case ' .............................................................................. case mid$( t$, j+1, 5) ="quot;" LB$ =LB$ +chr$( 34) j =j +6 ' "
case mid$( t$, j+1, 3) ="gt;" LB$ =LB$ +">" j =j +4 ' >
case mid$( t$, j+1, 3) ="lt;" LB$ =LB$ +"<" j =j +4 ' <
case mid$( t$, j +1, 4) ="amp;" ' ampersand LB$ =LB$ +"&" j =j +5
case right$( mid$( t$, j, 5), 1) =";" v =val( mid$( t$, j +2, 2)) j =j +5 ' 2-digit character-code if v =39 then LB$ =LB$ +chr$( 39) else LB$ =LB$ +chr$( v) ' eg ' ( 40,41) '()
case right$( mid$( t$, j, 6), 1) =";" ' 3-digit character-code v =val( mid$( t$, j +2, 3)) if v =160 then v =32 'print "Hard space!" ' convert hard- to soft-space. j =j +6 LB$ =LB$ +chr$( v)
end select ' .............................................................................. ' print " and finishing with ;"
case else ' not an html entity nor a tag. Use as-is unless it's the final hard-space plus semi-colon..' <<<<??? if mid$( t$, j +1, 5) ="#160;" and mid$( t$, j +5, 6) ="</pre>" then j =L else LB$ =LB$ +nxtChr$: j =j +1
end select ' _________________________________________________________________________________________________________ scan
loop until j >= ( fin -beg -4)
print "" print LB$ print ""
po =instr( solutions$( R, 0), "/") ' can't use '/' in file path name
if po <>0 then solutions$( R, 0) =left$( solutions$( R, 0), po -1) +"_" +mid$( solutions$( R, 0), po +1)
open solutions$( R, 0) +".bas" for output as #LB #LB LB$; close #LB 'wait print print " ________________________________________________________________________________________"
print "" print "solutions$( R, 0) = "; solutions$( R, 0) print " Saving as "; solutions$( R, 0) +".bas" print "Done."
'notice "Task "; str$( R); " done."
timer 4000, [on2] wait [on2] timer 0
cls ' Run with LB. ' problem for Linux <<<<<<
print " Loading and running in LB, '"; solutions$( R, 0) +".bas'." run chr$( 34) +"/home/johnf/.wine/drive_c/Program Files (x86)/Liberty BASIC v4.5.1/liberty.exe" +chr$( 34) +" -R " +chr$( 34) +"/media/johnf/32Gorange/testRC11/" +solutions$( R, 0) +".bas" +chr$( 34)
[skip]
' next R ' rem out if using a single value of R
notice "Finished."
end
' ************************************************************** Function DownloadToFile( urlfile$, localfile$) open "URLmon" for dll as #url calldll #url, "URLDownloadToFileA",_ 0 as long,_ 'null urlfile$ as ptr,_ 'url to download localfile$ as ptr,_ 'save file name 0 as long,_ 'reserved, must be 0 0 as long,_ 'callback address, can be 0 DownloadToFile as ulong '0=success close #url end function end
function getHtmlSection$( string$, byref first, last) ' fetch am html address between '<a href=' and '"'. a =instr( string$, "<a href=" +chr$( 34), first) if a =0 then getHtmlSection$ =" Sorry! html link not found": exit function
b =instr( string$, chr$( 34), a +9)
getHtmlSection$ =mid$( string$, a +10, b -a -10)
first =b +1 ' Reset value of "first" so that in the next call to ' getHtmlSection$( the next html link can be found. end function
|
|
|
Post by Carl Gundel on Feb 17, 2020 12:17:32 GMT -5
I'm unlikely to do much further on my version in the next few weeks. Version below, given an hour or so, will download most of the LB entries. It is messy but well annotated code. Thanks John.
|
|
|
Post by sarossell on Feb 17, 2020 12:43:54 GMT -5
Here's a thought that could bring more people to Liberty BASIC. A version of the aggregator that let's you aggregate for any language on Rosetta Code. ...and then loads it, converts it to LB, and runs it!
Sorry, I went a little coo-coo there for a sec.
;@)
|
|
|
Post by Carl Gundel on Feb 17, 2020 13:36:39 GMT -5
Here's a thought that could bring more people to Liberty BASIC. A version of the aggregator that let's you aggregate for any language on Rosetta Code. ...and then loads it, converts it to LB, and runs it!
Sorry, I went a little coo-coo there for a sec.
;@)
LOL. What I mean is that people can download Liberty BASIC to use a Rosetta Code aggregator to examine code for their favorite language(s) and in the process they are introduced to Liberty BASIC.
|
|
|
Post by sarossell on Feb 17, 2020 13:45:39 GMT -5
Absolutely. I whole-heartedly support any legitimate ways to show the world that BASIC, specifically Liberty BASIC, is not your grandfather's BASIC.
|
|
|
Post by tenochtitlanuk on Feb 18, 2020 4:42:25 GMT -5
It's trivial to change the delimiter strings to download all examples of another language. I tend to look at other BASICs, Python and Fortran for inspiration and help. Depends on which you are most familiar with. But automatic translation of source code- 'Nah! Dream on!'. JohnF
PS the lines that automatically terminate on the last code example need editing- will do today. It took 40 minutes to download 342 examples last night. If you sit and watch you will notice the few ones tat I mentioned as special cases.
|
|