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 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.
he following 335 pages are in this category, out of 335 total. 1
100 doors 15 Puzzle Game
24 game 24 game/Solve
99 Bottles of Beer 99 Bottles of Beer/Basic
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
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
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
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
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
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
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
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
Kaprekar numbers Keyboard input/Obtain a Y or N response Knuth shuffle
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
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'th N-queens problem Narcissist Non-decimal radices/Convert Nth root Numerical integration
Old lady swallowed a fly One of n lines in a file One-dimensional cellular automata OpenGL Ordered words
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
Quaternion type Quine
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
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
Terminal control/Cursor positioning Ternary logic Tokenize a string Towers of Hanoi Trigonometric functions Truncate a file Truth table
URL decoding URL encoding User input/Graphical User input/Text
Variables Vector products Verify distribution uniformity/Naive Vigenère cipher Voronoi diagram
Web scraping Window creation Wireworld Write language name in 3D ASCII
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.
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 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 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"
' 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'
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
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 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 " ________________________________________________________________________________________"
' ************************************************************** 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 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.