'MANUALCREATE.O2BAS
===================

'MANUAL GENERATOR
'MANUAL CREATE
'11/02/2025
'24/03/2025
'23/01/2026
'CP

'---------------------------------
'DATA PROCESSING FOR OXYGEN MANUAL
'=================================

  '$ FileName "t.exe"
  'uses RTL64

   indexbase 1

  #if sizeof sys = 8
    def StrideShift 5 ' stride of 32 (sizeof recordlist)
  #else
    def StrideShift 4 ' stride of 16 (sizeof recordlist)
  #endif
  uses Generics
  uses ManualUtil
  '
  '-------
  'INITIAL
  '=======
  string source,examples
  source=getfile("..\..\inf\oxyDatabase.txt")
  examples="..\..\"
  '
  recordlist list[1000]
  int index[2000]
  recordlist grlist[1000]
  'o
  string head1,head2,tail,wordentry
  string contentshead
  string contentsentry
  string contentsfoot
  string indexhead,indexentry,indexfoot
  string listhead,listentry,listfoot
  int i,j,k,m
  int amount
  string s,t
  '
  '
  i=1 : j=1 : amount=0
  '
  '
  '---------------------------
  'CREATE LIST OF ALL KEYWORDS
  '===========================
  '
  makelist source, list, amount
  int totamount=amount
  
  '--------------------------------------
  'SAVE GROUPED LISTS OF KEYWORDS TO FILE
  '======================================
  '
  prbuf="Grouped Keyword List:" cr cr
  prof=len prbuf
  '
  (
  '
  sys u,v
  string w
  string ww[30]
  int gw[30,100]
  int ew[30]
  ----------------------
  ww[1]="various"
  ww[2]="def macro"
  ww[3]="defs enumeration"
  ww[4]="type / class"
  ww[5]="low level functions"
  ww[6]="proc / sub / function / method"
  ww[7]="struct from typedef"
  ww[8]="common reserved words"
  ww[9]="x86 CPU registerS"
  ww[10]="attributes"
  ww[11]="namespace"
  ww[12]="major keywords group 1"
  ww[13]="major keywords group 2"
  ww[14]="primitive types"
  ww[15]="functions"
  ww[16]="float macros"
  ww[18]="labels"
  ww[18]="low level macros"
  ww[19]="internal macros"
  ww[20]="high level macro"
  ----------------------
  'SECONDARY KEYWORDS
  ----------------------
  ww[21]="operators"
  ww[22]="control / loops"
  ww[23]="declaratives"
  ww[24]="secondary keywords"
  ww[25]="calling conventions"
  ww[26]="comment symbols"
  ww[27]="meta language keywords"
  ww[28]="macro operator keywords"
  ww[29]="macro functions & dim"
  ----------------------

  u=-99999
  for i=1 to amount
    v=list[i].m
    select v
    'PRIMARY KEYWORDS
    'BUILT IN
    'GROUPED BY METATYPE
    ----------------------
      case 0  : k=1
      case 1  : k=2
      case 2  : k=3
      case 3  : k=4
      case 4  : k=5
      case 5  : k=6
      case 8  : k=7
      case 9  : k=8
      case 10 : k=9
      case 11 : k=10
      case 12 : k=11
      case 13 : k=12
      case 14 : k=13
      case 15 : k=14
      case 16 : k=15
      case 17 : k=16
      case 30 : k=17
      case 18 : k=18
      case 19 : k=19
      case 20 : k=20
      ----------------------
      'SECONDARY KEYWORDS
      ----------------------
      case 51 : k=21
      case 52 : k=22
      case 53 : k=23
      case 54 : k=24
      case 55 : k=25
      case 56 : k=26
      case 57 : k=27
      case 59 : k=28
     'case 99 : k=29
      '----------------------
      case 99 : k=29 : jmp fwd nlist 'omit : continue with prior group
    end select
    ew[k]++
    j=ew[k]
    gw[k,j]=i
    nlist: 'bypass
  next 'i
  '
  'sort gw lists
  'for i=1 to totamount : index[i]=i : next
  'macro choose(sw,i,j) if list[i].s > list[j].s then sw=1
  'MergeSort index,totamount,choose

  macro gchoose(sw,ii,jj, i1,j1)
    int i1=gw[i,ii]
    int j1=gw[i,jj]
    if list[i1].s > list[j1].s then sw=1
  end macro
  

  for i=1 to 30
    if ew[i]
      k=ew[i]
      pr cr cr "Group: " ww[i] + cr cr
      '
      for j=1 to k
        index[j]=j
      next
      '
      MergeSort(index,k,gchoose)
      '
      t=""
      for j=1 to k
        m=index[j]
        m=gw[i,m]
        s=list[m].s
        if s<>t 'exclude duplicates
          pr s+cr
        endif
        t=s
      next
    endif
  next
  '
  putfile "KeywordsGrouped.txt", left(prbuf,prof)
  '
  )
  '
  '
  '
  '----------------------------------
  'CREATE LIST WITHOUT GROUP HEADINGS
  '==================================
  '
  int gramount=0
  makegrlist source, grlist, gramount
 
  '
  '-------------------
  'CREATE SORTED INDEX
  '===================
  '
  for i=1 to amount : index[i]=i : next
  macro choose(sw,i,j) if list[i].s > list[j].s then sw=1
  MergeSort index,amount,choose
  '
  '
  '
  '------------------------------------
  'SAVE SORTED LIST OF KEYWORDS TO FILE
  '====================================
  '
  string prv=""
  prbuf="" '"Sorted Keyword List:" cr cr
  prof=len prbuf
  '
  for i=1 to amount
    j=index[i]
    'exclude duplicates
    if list[j].s<>prv
      pr list[j].s cr ' tab list[j].i cr ' tab index[j] cr
      prv=list[j].s
    endif
  next
  prv=""
  '
  putfile "KeywordsSorted.txt", left(prbuf,prof)
  putfile "..\..\inf\KeywordsSorted.txt", left(prbuf,prof)
  '
  '





  '============
  'MAIN OUTPUTS
  '============
  '============



  string outdir="o2manual\" 'inputs directory




  '===================================
  'GENERAL HTML PAGE HEADER AND FOOTER
  '===================================


  string head1=quote
  !!!
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

  <html>

  <head>
  !!!



  string head2=quote
  !!!
   <meta name="generator" content="Help &amp; Manual" />
   <meta name="keywords" content="" />
   <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
   <meta http-equiv="Content-Style-Type" content="text/css" />
   <link type="text/css" href="default.css" rel="stylesheet" />
  </head>


  <body style="margin: 20px 20px 20px 20px; background: #fefeee;">

  !!!

/*
  tail=quote
  !!!
  <!-- FOOTER_START -->
  <P>&nbsp;</P>

  <table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#F0F0F0">
  <tr>
    <td align="left"><Font face="Verdana,Arial" size="1" color="#003366">Copyright &#169; Charles Pegge, 2010-2025</FONT>
    </td>
    <td align="right"><Font face="Verdana,Arial" size="1" color="#003366"></a></FONT>
    </td>
  </tr>
  </table>
  <!-- FOOTER_END -->

  </body>
  </html>
  !!!
*/


  string tail=quote
  !!!
  </body>
  </html>
  !!!



  'INITIAL
  '-------
  '
  int a,b
  string f,s,m,n
  string same,members,action,use,example,result,incstring1,incstring2,keywords,remarks,related
  string group,see,keylinks,title,incfile1,incfile2
  string record,name,ent
  '
  prbuf="" : prof=0
  '


  '==========================
  'GENERATE wordlink.htm FILE
  '==========================

  WordEntry=quote
  !!!
  <tr><td><a name="#%1"> </><a href="%2">%1</a> </td><td>%3</td></tr>
  !!!


  '
  '------------------------------------------
  'CREATE WORLINK LIST FOR LINKAGE TO THE IDE
  '------------------------------------------
  '
  string sa,sl,sr ',s
  '
  for i=1 to amount
    '
    j=index[i]
    a=list[j].i
    getrec source, a, b
    record=mid source, a, b-a
    name=getname record,1
    s={name}
    HTMLencodew s
    SplitWord s,sl,sr
    '
    n=fileNameHTM name
    varget same
    varget members
    if members then
      varget group
      sa=group
    else
      varget action
      sa=action
    end if
    ent=WordEntry
    ent=replace(ent,"%1",sl) 'keyword
    ent=replace(ent,"%2",n) 'filename
    ent=replace(ent,"%3",sr+sa)
    pr ent cr
    if same then
      ent=WordEntry
      ent=replace(ent,"%1",same)
      ent=replace(ent,"%2",n)
      ent=replace(ent,"%3",sa)
      pr ent cr
    end if
    '
  next

  '
  'CREATE WORDLINK FILE
  '
  putfile outdir + "wordlink.htm",
  head1 +  "  <title>WordLink</title>" +
  head2 +
  "  <h2>Keyword List</h2>" cr +
  "  <table>" cr +
  left(prbuf,prof) +
  "  </table>" cr +
  tail
  '




  '========================
  'GENERATE REFERENCE PAGES
  '========================





  '=====================
  'GROUP REFERENCE PAGES
  '=====================

  for i=1 to gramount
    a=grlist[i].i
    getrec source, a, b
    record=mid source, a, b-a
    '
    seelinks record
    '
    varget members
    if members then
      '
      prbuf="" : prof=0 'clear ready for next page
      '
      n=getname record, 1
      '
      varget same
      varget action
      varget use
      varget example
      varget result
      varget remarks
      varget keylinks
      varget keywords
      varget related
      varget group
      varget title
      varget incfile1
      varget incfile2
      '
      int lfl
      lfl=0 'NO LINKS
      if instr(keylinks,"yes") then lfl=1
      'JSON RECORD
      '
      prjn "{"+cr
      prijn "id",n

      def pj prijn "%1",%1
      pj same
      pj members
      pj action
      pj use
      pj example
      pj result
      if incfile1
        incstring1=embed examples+incfile1
        pj incstring1
      end if
      if incfile2
        incstring2=embed examples+incfile2
        pj incstring2
      end if
      pj remarks
      pj related
      pj group
      pj title
      profj-=3 'omit last comma cr
      prjn cr+"},"+cr
      '
      if lfl
        reftag members
      endif
      reftag related
      '
      if title
        m=title
      else
        m=n
      endif
      'override getname (Data expression)
      '
      pr     "<table cellspacing=10% cellpadding=10% >" cr //border=4% rules=rows
      SplitWord m
      prih   `<font size="5" color=#0000ff ><b>` m `</b></font>`, ` `
      '
      pr "<tr><td></td><td><font color=#2222ff ><b>" cr
      'grprintnames source,a,lfl
      pr "</b></font></td></tr>" cr
      '
      prif   "MEMBERS:", members
      prif   "ACTION:",  action
      prif   "USE:",     use
      prifc  "EXAMPLE:", HTMLencode example
      prifc  "RESULT:",  result
      if incfile1 then
        pr EmbedHTM examples+incfile1
      end if
      if incfile2 then
        pr EmbedHTM examples+incfile2
      end if
      prifbr "KEYWORDS:",keywords
      prifbr "REMARKS:", remarks
      prif   "RELATED:", related
     'prif   "GROUP:",   group
      pr     cr cr cr
      pr     "</table>" cr "<br><br><br>" cr cr
      '
      n=filenameHTM n
      '
      putfile outdir + n,
      head1 +  "<title>" + title + "</title>" +
      head2 +
      left(prbuf,prof) +
      tail
      '
      'ADD FOR INDEX FILE
      '
      totamount+=1
      list[totamount].s=rtrim(group)
      list[totamount].i=grlist[i].i
    end if
  next


  '==========================
  'INDIVIDUAL REFERENCE PAGES
  '==========================

  for i=1 to amount  'each page to file
    '
    j=index[i]
    a=list[j].i
    getrec source, a, b
    record=mid source, a, b-a
    '
    seelinks record
    '
    varget members
    if not members then
      '
      prbuf="" : prof=0 'clear ready for next page
      '
      n=getname record, 1
      '
      varget same
      varget action
      varget use
      varget example
      varget result
      varget remarks
      varget related
      varget group
      varget title
      varget incfile1
      varget incfile2
      '
      'JSON RECORD
      '
      prjn "{"+cr
      prijn "id",n
      def pj prijn "%1",%1
      pj same
      pj action
      pj use
      pj example
      pj result
      if incfile1
       incstring1=embed examples+incfile1
        pj incstring1
      end if
      if incfile2
        incstring2=embed examples+incfile2
        pj incstring2
      end if
      pj remarks
      pj related
      pj group
      pj title
      profj-=3 'omit last comma cr
      prjn cr+"},"+cr
      '
      reftag related
      '
      if title
        m=title
      else
        m=n
      endif
      'override getname (Data expression)
      if same then m=m+"<br>"+same
      '
      pr     "<table cellspacing=10% cellpadding=10% >" cr //border=4% rules=rows
      splitword m
      prih   `<font size="5" color=#0000ff ><b>` m `</b></font>`, ` `
      prif   "ACTION:",  action
      prif   "USE:",     use
      prifc  "EXAMPLE:", HTMLencode example
      prifc  "RESULT:",  result
      if incfile1 then
        pr EmbedHTM examples+incfile1
      end if
      if incfile2 then
        pr EmbedHTM examples+incfile2
      end if
      prifbr "REMARKS:", remarks
      prif   "RELATED:", related
     'prif   "GROUP:",   group
      pr     cr cr cr
      pr     "</table>" cr "<br><br><br>" cr cr
      '
      '
      putfile outdir + filenameHTM(n),
      head1 +  "<title>" + title + "</title>" +
      head2 + left(prbuf,prof) + tail
    end if
    '
  next 'page to file
  '
  '
  'putfile outdir + "Oxygen.htm", head + left(prbuf,prof) + tail

  'STORE JSON FILE
  profj-=3 'omit last ","cr
  putfile "..\..\inf\OxyDatabase.js", "const database = ["+cr+left(prbufj,profj)+cr+"];"+cr



  a=0 : b=0
  '


  '===================================
  'GENERATE Table of Contents.hhc FILE
  '===================================



  ContentsHead=quote
  !!!
  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  <HTML>
  <HEAD>
  <meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
  <!-- Sitemap 1.0 -->
  </HEAD>
  <BODY>
  <UL>
  !!!

  ContentsEntry=quote
  !!!
  <LI><OBJECT type="text/sitemap">
  <param name="Name" value="%1">
  <param name="Local" value="%2">
  </OBJECT>
  !!!


  ContentsFoot=quote
  !!!
  </UL>
  </BODY>
  </HTML>
  !!!


  prbuf=ContentsHead : prof=len(prbuf)
  '
  pr InclFile "About", ContentsEntry
  pr InclFile "Introduction", ContentsEntry
  '
  for i=1 to gramount
    a=grlist[i].i
    getrec source, a, b
    record=mid source, a, b-a
    name=getname record,1
    '
    varget members
    if members then
      '
      n=filenameHTM name
      group=getFieldWord record,"group"
      ent=ContentsEntry
      ent=replace(ent,"%1",group)
      ent=replace(ent,"%2",n)
      pr ent cr
      '
      n+=cr
      a=instr(filelist,n)
      if a=0 then
        filelist+=n
      end if
      '
    end if
    '
  next
  string sindex
  ' pr "<UL>" cr sindex "</UL>" cr 'add index list to contentents
  pr ContentsFoot
  putfile outdir "Contents.hhc",left(prbuf,prof)




  '=======================
  'GENERATE Index.hhk FILE
  '=======================


  string IndexHead=quote
  !!!
  <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
  <HTML>
  <HEAD>
  <meta name="GENERATOR" content="Microsoft&reg; HTML Help Workshop 4.1">
  <!-- Sitemap 1.0 -->
  </HEAD>
  <BODY>
  <UL>
  !!!

  string IndexEntry=quote
  !!!
  <LI><OBJECT type="text/sitemap">
  <param name="Name" value="%1">
  <param name="Local" value="%2">
  </OBJECT>
  !!!


  string IndexFoot=quote
  !!!
  </UL>
  </BODY>
  </HTML>
  !!!


  '
  record=""
  name=""
  group=""
  members=""
  s=""
  prbuf="" : prof=0
  '
  '
  '------------------------------------------
  'CREATE SORTED INDEX, INCLUDING GROUP FILES
  '------------------------------------------
  '
  for i=1 to totamount : index[i]=i : next
  macro choose(sw,i,j) if list[i].s > list[j].s then sw=1
  MergeSort index,totamount,choose
  '
  for i=1 to totamount
    '
    j=index[i]
    a=list[j].i
    getrec source, a, b
    record=mid source, a, b-a
    name=getname record,1
    '
    same=getFieldWord record,"same"
    group=getFieldWord record,"group"
    varget members
    '
    '
    if list[j].s=group then
      s=group 'added in if members
    elseif members then
      s=name + ", "+group
    else
      s=name
    end if
    '
    n=filenameHTM name
    '
    SplitWord s
    ent=IndexEntry
    ent=replace(ent,"%1",s)
    ent=replace(ent,"%2",n)
    pr ent cr
    if same then
      ent=IndexEntry
      ent=replace(ent,"%1",same)
      ent=replace(ent,"%2",n)
      pr ent cr
    end if
    '
    n+=cr
    if not members then
      a=instr(filelist,n)
      if a=0 then
        filelist+=n
      end if
    end if
    '
  next
  '
  sindex=left prbuf,prof
  putfile outdir "Index.hhk", IndexHead sindex IndexFoot
  '


  '=============================
  'GENERATE OxygenBasic_Manual.HHP FILE 
  '=============================

  string listname="OxygenBasic_Manual.hhp"

  string ListHead=quote
!!!
Auto Index=Yes
Compatibility=1.1 or later
Compiled file=..\..\..\inf\OxygenBasic_Manual.chm
Contents file=Contents.hhc
Default topic=About.hha
Display compile progress=No
Full-text search=Yes
Index file=Index.hhk
Language=0x809 English (United Kingdom)
Title=OxygenBasic Manual

[FILES]
!!!

  
  ListFoot=quote
!!!
[INFOTYPES]
!!!

  putfile outdir listname, listhead + filelist + "WordLink.htm" cr + listfoot






  '====
  .done
  '====


  '
  print "Okay!" cr "Outputs in: " outdir

