Author Topic: QB64 Wiki Keyword Generator  (Read 4281 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
QB64 Wiki Keyword Generator
« on: November 03, 2018, 06:36:54 am »
This is a little tool of mine which Dav might like for his IDE (or, for other folks who want to keep a list of keywords in our wiki, for whatever reason.)

Code: QB64: [Select]
  1. CONST SleepSet = 0 'to sleep between each keyword so we can see them and read them
  2. CONST SaveTo = "wiki.txt" '"SCRN:" to display to the screen, or insert a filename to save the list to disk
  3.  
  4. SCREEN _NEWIMAGE(1024, 720, 256)
  5. PRINT "DOWNLOAD STARTING"
  6. file$ = "QB64WikiList.txt"
  7. 'Increase the 2-second time limit here if you need to.
  8. DownloadRSS "http://qb64.org/wiki/Keyword_Reference_-_Alphabetical", file$, 2
  9. PRINT "DOWNLOAD FINISHED"
  10.  
  11.  
  12. OPEN file$ FOR BINARY AS #1
  13. temp$ = SPACE$(LOF(1))
  14. GET #1, , temp$
  15. l = 0
  16. finish$ = "<div id=" + CHR$(34) + "symbols" + CHR$(34) + "></div>"
  17. finish = INSTR(temp$, finish$) 'No need to parse anything after we get down to the symbol section of the wiki page
  18.  
  19. OPEN SaveTo FOR OUTPUT AS #1
  20.  
  21.  
  22.     l = INSTR(l, temp$, "<li>")
  23.     IF l >= finish THEN EXIT DO
  24.     IF l THEN
  25.         l2 = INSTR(l + 5, temp$, "</li>"): IF l2 = 0 THEN l2 = LEN(temp$)
  26.         work$ = MID$(temp$, l + 4, l2 - l - 5)
  27.         li1 = INSTR(work$, CHR$(34)): li2 = INSTR(li1 + 1, work$, CHR$(34))
  28.         link$ = MID$(work$, li1 + 1, li2 - li1 - 1)
  29.         IF INSTR(link$, "&amp") THEN link$ = "Page does not exist yet."
  30.         link$ = StripCRLF(link$)
  31.         k1 = INSTR(li2 + 1, work$, ">"): k2 = INSTR(k1 + 1, work$, "<")
  32.         keyword$ = MID$(work$, k1 + 1, k2 - k1 - 1)
  33.         keyword$ = StripCRLF(keyword$)
  34.         d = INSTR(k2 + 1, work$, "<span"): d1 = INSTR(d + 1, work$, ">"): d2 = INSTR(d1 + 1, work$, "</span")
  35.         desc$ = MID$(work$, d1 + 1, d2 - d1 - 1)
  36.         desc$ = StripCRLF(desc$)
  37.         PRINT #1, keyword$
  38.         PRINT #1, "         http://qb64.org"; link$
  39.         PRINT #1, "         "; desc$
  40.         IF SleepSet THEN SLEEP
  41.         l = l2 + 1
  42.     END IF
  43. LOOP UNTIL l = 0
  44.  
  45.  
  46.  
  47. SUB DownloadRSS (url$, file$, timelimit)
  48.     link$ = url$
  49.  
  50.     url2$ = RTRIM$(LTRIM$(link$))
  51.     url4$ = RTRIM$(LTRIM$(link$))
  52.     IF LEFT$(UCASE$(url2$), 7) = "HTTP://" THEN url4$ = MID$(url2$, 8)
  53.     x = INSTR(url4$, "/")
  54.     IF x THEN url2$ = LEFT$(url4$, x - 1)
  55.     NewsClient = _OPENCLIENT("TCP/IP:80:" + url2$)
  56.     IF NewsClient = 0 THEN EXIT FUNCTION
  57.     e$ = CHR$(13) + CHR$(10) ' end of line characters
  58.     url3$ = RIGHT$(url4$, LEN(url4$) - x + 1)
  59.     x$ = "GET " + url3$ + " HTTP/1.1" + e$
  60.     x$ = x$ + "Host: " + url2$ + e$ + e$
  61.     PUT #NewsClient, , x$
  62.  
  63.     OPEN file$ FOR OUTPUT AS #1: CLOSE #1
  64.     OPEN file$ FOR BINARY AS #1
  65.  
  66.     t! = TIMER ' start time
  67.     head$ = ""
  68.     cont_type$ = ""
  69.     DO
  70.         _LIMIT 20
  71.         GET #NewsClient, , a$
  72.         IF LTRIM$(a$) > "" THEN PUT #1, , a$
  73.     LOOP UNTIL TIMER > t! + timelimit AND timelimit > 0 ' (in seconds)
  74.     CLOSE #NewsClient
  75.     CLOSE #1
  76.  
  77. FUNCTION StripCRLF$ (text$)
  78.     'The wiki seems to contain stray CRLF characters at the dangest spots.
  79.     'Why it has them, I don't know, but we need to filter them out so our information will load and display properly.
  80.     li1 = 0
  81.     DO
  82.         li1 = INSTR(li1 + 1, text$, CHR$(13) + CHR$(10))
  83.         IF li1 THEN
  84.             l$ = LEFT$(text$, li1 - 1)
  85.             r$ = MID$(text$, li1 + 2)
  86.             text$ = l$ + r$
  87.         END IF
  88.     LOOP UNTIL li1 = 0
  89.  
  90.     'Also some of the descriptions and such contain links to different keywords.
  91.     'We want to just strip those links and use a normal word replacement for ease of display, since we're not going to be displaying in
  92.     'an html editor/viewer.
  93.  
  94.     li1 = 0
  95.     DO
  96.         li1 = INSTR(li1 + 1, text$, "<a href")
  97.         IF li1 THEN
  98.             li2 = INSTR(li1 + 1, text$, "</a>")
  99.             li3 = INSTR(li1 + 1, text$, ">")
  100.             l$ = LEFT$(text$, li1 - 1)
  101.             m$ = MID$(text$, li3 + 1, li2 - li3 - 1)
  102.             r$ = MID$(text$, li2 + 4)
  103.             text$ = l$ + m$ + r$
  104.         END IF
  105.     LOOP UNTIL li1 = 0
  106.  
  107.     StripCRLF$ = text$
  108.  

Change SleepSet to 0 if you don't want to be bothered with the need to press a key between keywords.
Change SaveTo to a filename (like "wiki.txt") if you want to save the list to an external file on your hard drive.

This gives us 3 pieces of information for each entry in the wiki:

Keyword name.
Link to the wiki page where we can go to get detailed information about that keyword.
And a brief summery of what the keyword does.
« Last Edit: November 03, 2018, 07:02:52 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

FellippeHeitor

  • Guest
Re: QB64 Wiki Keyword Generator
« Reply #1 on: November 03, 2018, 06:45:24 am »
Does it work with no changes with the new wiki? I've had to do some reworking with the IDE's parsing routines for the wiki because we use a newer version of MediaWiki than Galleon had installed and some new formatting/tagging got in the way.
« Last Edit: November 03, 2018, 08:25:44 am by FellippeHeitor »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: QB64 Wiki Keyword Generator
« Reply #2 on: November 03, 2018, 06:56:21 am »
Here's a small sample of how it outputs information for us -- as far as I can tell, it processes everything fine, without glitching out anywhere.

Quote
_ACOS
         http://qb64.org/wiki/ACOS
         arccosine function returns the angle in radians based on an input COSine value range from -1 to 1.
_ACOSH
         http://qb64.org/wiki/ACOSH
         Returns the nonnegative arc hyperbolic cosine of x, expressed in radians.
_ALPHA
         http://qb64.org/wiki/ALPHA
         returns the alpha channel transparency level of a color value used on a screen page or image.
_ALPHA32
         http://qb64.org/wiki/ALPHA32
         returns the alpha channel transparency level of a color value used on a 32 bit screen page or image.
_ARCCOT
         http://qb64.org/wiki/Mathematical_Operations
         is the inverse function of the cotangent. .  <a rel="nofollow" class="external free" href="http://mathworld.wolfram.com/InverseCosecant.html">http://mathworld.wolfram.com/InverseCosecant.html[/url]
_ARCCSC
         http://qb64.org/wiki/Mathematical_Operations
         is the inverse function of the cosecant.  <a rel="nofollow" class="external free" href="http://mathworld.wolfram.com/InverseCosecant.html">http://mathworld.wolfram.com/InverseCosecant.html[/url]
_ARCSEC
         http://qb64.org/wiki/Mathematical_Operations
         is the inverse function of the secant.  <a rel="nofollow" class="external free" href="http://mathworld.wolfram.com/InverseSecant.html">http://mathworld.wolfram.com/InverseSecant.html[/url]
_ASIN
         http://qb64.org/wiki/ASIN
         Returns the principal value of the arc sine of x, expressed in radians.
_ASINH
         http://qb64.org/wiki/ASINH
         Returns the arc hyperbolic sine of x, expressed in radians.
_ATAN2
         http://qb64.org/wiki/ATAN2
         Returns the principal value of the arc tangent of y/x, expressed in radians.
_ATANH
         http://qb64.org/wiki/ATANH
         Returns the arc hyperbolic tangent of x, expressed in radians.
_AUTODISPLAY
         http://qb64.org/wiki/AUTODISPLAY
         enables the automatic display of the screen image changes previously disabled by _DISPLAY.
_AUTODISPLAY (function)
         http://qb64.org/wiki/AUTODISPLAY_(function)
         returns the current display mode as true (-1) if automatic or false (0) if per request using _DISPLAY.
_AXIS
         http://qb64.org/wiki/AXIS
         returns a SINGLE value between -1 and 1 indicating the maximum distance from the device axis center, 0.


Edit: You were right; it required some changing to the links to each keyword.  They're no longer in the "Keyword_Reference_-_Alphabetical" subfolder, as each now falls directly into "http://qb64.org/wiki/". 

Changed and links should now be valid again.
« Last Edit: November 03, 2018, 07:05:23 am by SMcNeill »
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!