tools:
[dwarf-doc.git] / dwarf5 / tools / refer.py
index a954d45..4277750 100644 (file)
@@ -9,6 +9,9 @@
 # Run as (for example)
 #   python refer.py 
 
+# This version assumes relevant commands are used
+# all-on-one-line, not with operands on successive lines.
+
 # This is the simplest 'parse' of the .tex that we can manage
 # while still finding what we want to find.
 # One would hardly call it a parser, really.
@@ -185,7 +188,7 @@ def pickup(linetoks,tnumin,pattern,myfile,linenum,suppresserr):
       if curtok._class != "id":
         if isbrace(curtok,"}") == "y":
           tk = fileio.dwtoken()
-          tk.insertid("")
+          tk.insertid("",linenum)
           outtoks += [tk]
           # Do not update location.
           continue
@@ -346,18 +349,22 @@ def livetargiprocess(linetoks,tnumin,myfile,linenum):
   global targhyperdict
   global indexdict
   t = linetoks[tnumin]
-  ourtoks,inlen = pickup(linetoks,tnumin,"i { i } { e } { * }",myfile,linenum,"n")
+  # The first * here used to be e but that was insufficiently general.
+  # The index is generated from the entire  * (token list 8) , not from the
+  # initial  *, token list 5
+  ourtoks,inlen = pickup(linetoks,tnumin,"i { i } { * } { * }",myfile,linenum,"n")
   if len(ourtoks) > 5:
     t2 = ourtoks[2];
     index = tokmention(t2,myfile,linenum)
     name = toknamestring(t2)
     applytodict(targhyperdict,name,index)
 
-    t2 = ourtoks[5];
-    name = toknamestring(t2)
-    if len(name) > 0:
-      index = tokmention(t2,myfile,linenum)
-      applytodict(indexdict,name,index)
+    # WARNING: looking at 5 this way was wrong.
+    #t2 = ourtoks[5];
+    #name = toknamestring(t2)
+    #if len(name) > 0:
+    #  index = tokmention(t2,myfile,linenum)
+    #  applytodict(indexdict,name,index)
   else:
     tn = toknamestring(linetoks[tnumin])
     printbadcommand(tn,myfile,linenum)
@@ -368,21 +375,26 @@ def livelinkprocess(linetoks,tnumin,myfile,linenum,justlink):
   global linkhyperdict
   global indexdict
   t = linetoks[tnumin]
-  ourtoks,inlen = pickup(linetoks,tnumin,"i { i } { * }",myfile,linenum,"n")
-  if len(ourtoks) > 5:
-    t2 = ourtoks[2];
-    index = tokmention(t2,myfile,linenum)
-    name = toknamestring(t2)
-    applytodict(linkhyperdict,name,index)
-
-    # can be multiword. For now do not bother with every index.
-    #t2 = ourtoks[5];
-    #index = tokmention(t2,myfile,linenum)
-    #name = toknamestring(t2)
-    #applytodict(indexdict,name,index)
+  if justlink == "y":
+    ourtoks,inlen = pickup(linetoks,tnumin,"i { i } { * }",myfile,linenum,"n")
+    if len(ourtoks) > 5:
+      t2 = ourtoks[2];
+      index = tokmention(t2,myfile,linenum)
+      name = toknamestring(t2)
+      applytodict(linkhyperdict,name,index)
+    else:
+      tn = toknamestring(linetoks[tnumin])
+      printbadcommand(tn,myfile,linenum)
   else:
-    tn = toknamestring(linetoks[tnumin])
-    printbadcommand(tn,myfile,linenum)
+    ourtoks,inlen = pickup(linetoks,tnumin,"i { i }",myfile,linenum,"n")
+    if len(ourtoks) == 4:
+      t2 = ourtoks[2];
+      index = tokmention(t2,myfile,linenum)
+      name = toknamestring(t2)
+      applytodict(linkhyperdict,name,index)
+    else:
+      tn = toknamestring(linetoks[tnumin])
+      printbadcommand(tn,myfile,linenum)
   return inlen
 def labelprocess(linetoks,tnumin,myfile,linenum):
   """ \label{alabel} """
@@ -417,7 +429,7 @@ def addtoindexprocess(linetoks,tnumin,myfile,linenum):
 def hyperlinkname(name,tnumin,myfile,linenum):
   global linkhyperdict
   tkmod = fileio.dwtoken()
-  tkmod.insertid(name)
+  tkmod.insertid(name,linenum)
   tm = tokmention(tkmod,myfile,linenum)
   applytodict(linkhyperdict,name,tm)
   return 1
@@ -525,7 +537,7 @@ def transfunc1(linetoks,myfile,linenum):
     # are coded.
     t2 = linetoks[tnum+2]
     tkmod = fileio.dwtoken()
-    tkmod.insertid("\\" + toknamestring(t2))
+    tkmod.insertid("\\" + toknamestring(t2),linenum)
     tm = tokmention(tkmod,myfile,linenum)
     applytodict(dwfnamecommsdict,toknamestring(tkmod),tm)
     return linetoks