parses a line of 'code'. return value from the lexfn a 0 for EOL (end of line). -1 for error. -2 for comment
| 138 | // -1 for error. |
| 139 | // -2 for comment |
| 140 | int InfFile::ParseLine(char *operand, int oprlen) { |
| 141 | if (!m_lineptr) |
| 142 | return INFFILE_EOL; |
| 143 | |
| 144 | // tokenize line. |
| 145 | char command[32]; // Command read from line. |
| 146 | char *opr = NULL, *cmd; |
| 147 | int retval = INFFILE_NULL; |
| 148 | |
| 149 | if (strlen(m_lineptr) == 0) |
| 150 | return INFFILE_EOL; |
| 151 | |
| 152 | // parse out command and operand (command=str) |
| 153 | // m_lineptr = command, opr = operand, nextcmd = next lineptr. |
| 154 | cmd = strtok(m_lineptr, " \t=:"); |
| 155 | if (cmd) |
| 156 | opr = strtok(NULL, ",;"); |
| 157 | else |
| 158 | Int3(); |
| 159 | |
| 160 | // clean out trailing and preceeding trash (tabs, spaces, etc) |
| 161 | CleanupStr(command, cmd, sizeof(command)); |
| 162 | if (opr) |
| 163 | CleanupStr(operand, opr, oprlen); |
| 164 | else |
| 165 | operand[0] = 0; |
| 166 | |
| 167 | if (strlen(command) == 0) { |
| 168 | if (strlen(operand) == 0) |
| 169 | return INFFILE_EOL; |
| 170 | } |
| 171 | |
| 172 | // do predefined commands |
| 173 | if (command[0] == '@') |
| 174 | retval = INFFILE_COMMENT; |
| 175 | |
| 176 | // do symbolic commands. |
| 177 | if (operand[0] == '#') { |
| 178 | const char *sym = GetSymbolText(&operand[1]); |
| 179 | if (sym) |
| 180 | strcpy(operand, sym); |
| 181 | else |
| 182 | retval = INFFILE_ERROR; |
| 183 | } |
| 184 | |
| 185 | if (retval == INFFILE_NULL) { |
| 186 | if (command[0] == '#') { |
| 187 | AddSymbol(&command[1], operand); |
| 188 | retval = INFFILE_SYMBOL; |
| 189 | } else { |
| 190 | // do command through lex analyzer. if not preprocessed. |
| 191 | if (m_lexfn) |
| 192 | retval = (*m_lexfn)(command); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // adjust text pointers to prepare for next read |
| 197 | char *lastptr = (opr) ? opr : cmd; |
no test coverage detected