Load the program :param file: The name and path of the file to be loaded tmpfile: File handle for temporary basic workfile
(self, file, tmpfile)
| 137 | return retCode |
| 138 | |
| 139 | def load(self, file, tmpfile): |
| 140 | """Load the program |
| 141 | |
| 142 | :param file: The name and path of the file to be loaded |
| 143 | tmpfile: File handle for temporary basic workfile""" |
| 144 | |
| 145 | infile = None |
| 146 | |
| 147 | try: |
| 148 | infile = open(file, 'r') |
| 149 | if hasattr(infile,'newlines'): |
| 150 | try: |
| 151 | infile.readline() |
| 152 | except: |
| 153 | pass |
| 154 | newlines = infile.newlines |
| 155 | infile.seek(0) |
| 156 | else: |
| 157 | newlines = None |
| 158 | fIndex = 0 |
| 159 | fOffset = 0 |
| 160 | pgmLoad = False |
| 161 | if file.split(".")[-1].upper() == "PGM": |
| 162 | pgmLoad = True |
| 163 | for fileLine in infile: |
| 164 | fOffset += len(fileLine) |
| 165 | if newlines != None: |
| 166 | fOffset += len(newlines)-1 |
| 167 | elif self.__imp != 'X': |
| 168 | fOffset += 1 |
| 169 | if len(fileLine) >= 9 and fileLine[0:9] == "-999,-999": |
| 170 | break |
| 171 | |
| 172 | infile.seek(0) |
| 173 | for fileLine in infile: |
| 174 | if pgmLoad: |
| 175 | line_number = int(fileLine.split(",")[0]) |
| 176 | fIndex = int(fileLine.split(",")[1]) |
| 177 | if len(fileLine) >= 9 and fileLine[0:9] == "-999,-999": |
| 178 | break |
| 179 | self.__program[line_number] = abs(fIndex)+fOffset |
| 180 | if fIndex < 0: |
| 181 | self.__data.addData(line_number,abs(fIndex)+fOffset) |
| 182 | else: |
| 183 | if ((fileLine.strip()).replace("\n","")).replace("\r","") != "": |
| 184 | line_number = int(fileLine.strip().split(" ")[0]) |
| 185 | self.__program[line_number] = fIndex+fOffset |
| 186 | if fileLine.strip().upper()[fileLine.strip().find(' '):].strip()[:4] == "DATA": |
| 187 | self.__data.addData(line_number,fIndex) |
| 188 | #self.add_stmt(Lexer().tokenize((fileLine.replace("\n","")).replace("\r","")),fIndex+fOffset,tmpfile) |
| 189 | fIndex += len(fileLine) |
| 190 | if newlines != None: |
| 191 | fIndex += len(newlines)-1 |
| 192 | elif self.__imp != 'X': |
| 193 | fIndex += 1 |
| 194 | |
| 195 | except OSError: |
| 196 | print("Could not read file") |