7 On @defManual manual refManual eg @defManual LM rlearning
8 Associate manual name 'manual' with reference @'refManual'{ ... }
9 Add 'refManual' to list of keywords
10 On @setManual manual set current manual name to 'manual'
11 On @include open and process new file
12 On @node add node to Nodes list with current manual name and current file name
13 On @ref add contents to References list with refManual, current manual name and current file name
14 On one of refManual keywords add contents to References list with ditto
16 Process References list:
17 Check reference is contained in Nodes list with refManual in Nodes = refManual in References
21 Node names containing commas are only checked up to the comma
22 Spurious warnings "Xref should be internal" for files in /included
27 ##################################################
29 """ Holds References and Nodes """
33 self.nodeNames = {} # used to check for duplicates only
37 def addManual(self, manualName, refManual):
38 self.Manuals[refManual] = manualName
40 def getRefManuals(self):
41 return self.Manuals.keys()
43 def getManualName(self, refManual):
44 return self.Manuals[refManual]
46 def addNode(self, nodeName, manualName, fileName):
48 # print "Node: ", nodeName, " in ", manualName, " found in ", fileName
49 if manualName+"/"+nodeName in self.Nodes.keys():
50 print "Error: Duplicate nodename ",nodeName, " in ", fileName, " and ", self.Nodes[manualName+nodeName]
52 self.Nodes[manualName + "/" + nodeName] = [manualName, fileName]
53 self.nodeNames[nodeName] = fileName
55 def addRef(self, toManualName, toHeading, inFileName):
56 # if inFileName == "notation/vocal.itely":
57 # print "Ref to ", toManualName, "/",toHeading, " found in ", inFileName
58 self.Refs.append([toManualName + "/" + toHeading, inFileName])
62 for [refHeading, refFileName] in self.Refs:
64 targetFileName = self.Nodes[refHeading]
65 # if refFileName == "notation/vocal.itely":
66 # print "ref to: ", refHeading, " in ", refFileName, " found in ", targetFileName
69 print "ref to: ", refHeading, " in ", refFileName, " not found"
71 print " All references satisfied"
75 ##################################################
77 """ Process an included file """
80 CurrentManualName = ""
86 def __init__(self, fileName):
87 self.fileName = fileName
89 self.fullFileName = File.Paths[fileName] + fileName
91 self.fullFileName = File.DefaultPath + fileName
93 def read(self, crossRefs):
97 myfile = open(self.fullFileName, 'r')
104 if words[0] == "@ignore" or words[0] == "@macro":
106 if skip and len(words) > 1:
107 if words[0] == "@end" and (words[1].find("ignore") >= 0 or words[1].find("macro") >= 0):
110 if not skip and words[0].find("@c") < 0:
111 if words[0].find("@defManual") >= 0:
112 # Manual definition found - extract manual name and refManual string
113 manualName = words[1]
115 crossRefs.addManual(manualName, refManual)
116 # print manualName, refManual
118 elif words[0].find("@defaultPath") >=0:
119 File.DefaultPath = words[1]
121 elif words[0].find("@path") >=0:
122 File.Paths[words[1]] = words[2]
124 elif words[0].find("@setManual") >= 0:
125 File.CurrentManualName = words[1]
126 # print " Checking ", File.CurrentManualName
128 elif words[0].find("@exclude") >=0:
129 File.Excludes.append(words[1])
131 elif words[0].find("@include") >= 0:
132 if words[1] not in File.Excludes:
133 currentFileName = words[1]
134 # print " File: ", currentFileName
135 currentFile = File(currentFileName)
136 currentFile.read(crossRefs)
138 elif words[0] == "@node":
139 nodeName = line[6:-1]
140 crossRefs.addNode(nodeName, File.CurrentManualName, self.fileName)
144 twoLines = remainderLine + ' ' + line.strip()
145 manualRefStrings = crossRefs.getRefManuals()
147 for manualRefString in manualRefStrings:
148 toManualName = crossRefs.getManualName(manualRefString)
149 actualToManualName = toManualName
150 if toManualName == "this":
151 toManualName = File.CurrentManualName
152 refString = "@" + manualRefString + "{"
153 refStart = twoLines.find(refString)
156 if actualToManualName == File.CurrentManualName:
157 print "Warning: xref should be internal around line ", lineNo, " in ", self.fileName
158 twoLines = twoLines[refStart:]
159 refNodeStart = twoLines.find("{") + 1
160 # TODO Need to check here for nested {}
161 refNodeEnd = twoLines.find("}")
162 refNodeEndComma = twoLines.find(",")
163 if refNodeEndComma > 0:
164 refNodeEnd = min(refNodeEnd, refNodeEndComma)
166 crossRefs.addRef(toManualName, twoLines[refNodeStart:refNodeEnd], self.fileName)
167 remainderLine=twoLines[refNodeEnd+1:]
177 topFile = File("scripts/auxiliar/ref_check.tely") # TODO get from input params
178 print "RefCheck ver 0.1"
180 crossRefs = CrossRefs()
181 topFile.read(crossRefs)
184 print "Errors found: status code: ",returnCode