--- /dev/null
+# Copyright 2013 DWARF Debugging Information Format Committee
+# This reads the input tokens and then
+# writes them out in new files.
+
+# October 5, 2013.
+# This replaces \livelink and \livetarg with
+# a simpler \DWXXXyyy, per Rob Brender email of Oct 4, 2013
+# It strives to be idempotent, so rerunning makes no
+# further changes.
+
+import sys
+import fileio
+
+def ischar(tok,c):
+ if tok._class != "ind":
+ return "n"
+ if len(tok._tex) != 1:
+ return "n"
+ if tok._tex[0] != c:
+ return "n"
+ return "y"
+
+
+def append_to_out(out,addthese):
+ for a in addthese:
+ out += [a]
+
+
+def doreplace(toks,curtoknum,lasttoknum):
+ if int(curtoknum) + 6 > int(lasttoknum):
+ print "n1"
+ return "n"
+ if toks[curtoknum+1]._class != "ind" or ''.join(toks[curtoknum+1]._label) != "{":
+ print "n2"
+ return "n"
+ if toks[curtoknum+2]._class != "id":
+ print "n3"
+ return "n"
+ if toks[curtoknum+3]._class != "ind" or ''.join(toks[curtoknum+3]._label) != "}":
+ print "n4"
+ return "n"
+ if toks[curtoknum+4]._class != "ind" or ''.join(toks[curtoknum+4]._label) != "{":
+ print "n5"
+ return "n"
+ if toks[curtoknum+5]._class != "id":
+ print "n6"
+ return "n"
+ if toks[curtoknum+6]._class != "ind" or ''.join(toks[curtoknum+6]._label) != "}":
+ print "n7"
+ return "n"
+ print "Found something needing replacing"
+ return "y"
+
+def newt(toks,curtoknum,finalchars,):
+ s = ''.join(toks[curtoknum + 5]._label)
+ s2 = "\\" + s + finalchars
+ t = fileio.dwtoken()
+ t.insertid(s2)
+ print " Final new token string '", s2, "'"
+ return t
+
+def transfunc(linetoks,myfile,linenum):
+ if len(linetoks) < 1:
+ return linetoks
+ print " "
+ tnumin = 0
+ changes = 0
+ lasttoknum = len(linetoks) -1
+ outtoks = []
+ for x in linetoks:
+ print tnumin
+ if tnumin > lasttoknum:
+ break
+ t = linetoks[tnumin]
+ rawtok = ''.join(t._tex)
+ t.dwprint()
+ if rawtok == "\\newcommand" and tnumin == 0:
+ # Do not touch newcommand stuff
+ return linetoks
+ if rawtok == "\\livelink" and "y" == doreplace(linetoks,tnumin,lasttoknum):
+ newtok = newt(linetoks,tnumin,"")
+ outtoks += [newtok]
+ tnumin += 7
+ if int(tnumin) <= int(lasttoknum):
+ # not at end of line, Check to see if we want a {} or not.
+ if linetoks[tnumin]._class == "ind" and ''.join(linetoks[tnumin]._label) == " ":
+ newtlb = fileio.dwtoken();
+ newtlb.setIndivid("{")
+ outtoks += [newtlb]
+ newtrb = fileio.dwtoken();
+ newtrb.setIndivid("}")
+ outtoks += [newtrb]
+ elif rawtok == "\\livetarg" and "y" == doreplace(linetoks,tnumin,lasttoknum):
+ newtok = newt(linetoks,tnumin,"TARG")
+ outtoks += [newtok]
+ tnumin += 7
+ if int(tnumin) <= int(lasttoknum):
+ # not at end of line. Check to see if we want a {} or not.
+ if linetoks[tnumin]._class == "ind" and ''.join(linetoks[tnumin]._label) == " ":
+ newtlb = fileio.dwtoken();
+ newtlb.setIndivid("{")
+ outtoks += [newtlb]
+ newtrb = fileio.dwtoken();
+ newtrb.setIndivid("}")
+ outtoks += [newtrb]
+ else:
+ tnumin = tnumin+ 1
+ outtoks += [t]
+ # End of for loop.
+ print "output toks"
+ for y in outtoks:
+ y.dwprint()
+ print "end output toks"
+ return outtoks
+
+def read_args():
+ cur = 1
+ filelist = []
+ while len(sys.argv) > cur:
+ v = sys.argv[cur]
+ filelist += [v]
+ cur = int(cur) + 1
+
+ dwf = fileio.readFilelist(filelist)
+ dwf.dwtransformline(transfunc)
+ dwf.dwwrite()
+
+if __name__ == '__main__':
+ read_args()
+
+
+
--- /dev/null
+
+% Sample input for dellivelink.py
+% use like \livelink{chap:DWOPdup}{DW\_OP\_dup}
+\newcommand{\livelink}[2]{\hyperlink{#1}{#2}\index{#2}}
+% use when the index is different from the text and target.
+\newcommand{\livelinki}[3]{\hyperlink{#1}{#2}\index{#3}}
+% livetarg is the declaration this is the target of livelinks.
+% FIXME: we might want livetarg and livetargi #2 to be \textbf{#2}
+\newcommand{\livetarg}[2]{\hypertarget{#1}{#2}\index{#2}}
+% When we want the index entry to look different from the name.
+\newcommand{\livetargi}[3]{\hypertarget{#1}{#2}\index{#3}}
+
+\livelink{chap:DWTAGaccessdeclaration}{DW\_TAG\_access\_declaration},
+\livelink{chap:DWTAGarraytype}{DW\_TAG\_array\_type},
+\livelink{chap:DWTAGbasetype}{DW\_TAG\_base\_type},
+
+\livetarg{chap:DWATabstractorigin}{DW\_AT\_abstract\_origin}
+&\livelinki{chap:DWATabstractorigininlineinstance}{Inline instances of inline subprograms} {inline instances of inline subprograms} \\
+
+
+one \livelink{chap:DWOPplus}{DW\_OP\_plus} one
+one \livelink{chap:DWOPplus}{DW\_OP\_plus}two
+one \livelink{chap:DWOPplus}{DW\_OP\_plus}+ 3
+one \livelink{chap:DWOPplus}{DW\_OP\_plus}
+
+