commit 6531d7922b3b88ff756dc02346ede6e8edeb11b0 Author: Daniel Swanson Date: Tue Jun 15 13:27:15 2021 -0500 escape characters properly, check text mode before writing blanks diff --git a/src/chunk.cc b/src/chunk.cc index 4a0b4c7..8c7a8c2 100644 --- a/src/chunk.cc +++ b/src/chunk.cc @@ -324,13 +324,14 @@ Chunk::writeTree(TreeMode mode, UFILE* out) if(rt > 16) writeString(UString(rt - 16, ' '), out); } writeString("\n"_u, out); - writeString(UString(tr, (UChar)L'─') + " "_u, out); - writeString(UString(sl, (UChar)L'─') + " "_u, out); - writeString(UString(st, (UChar)L'─') + " "_u, out); - writeString(UString(tl, (UChar)L'─') + " "_u, out); - writeString(UString(tt, (UChar)L'─'), out); - if(doCoref) writeString(" "_u + UString(rl, (UChar)L'─'), out); - if(doCoref) writeString(" "_u + UString(rt, (UChar)L'─'), out); + UChar dash = u'\u2500'; // '─' + writeString(UString(tr, dash) + " "_u, out); + writeString(UString(sl, dash) + " "_u, out); + writeString(UString(st, dash) + " "_u, out); + writeString(UString(tl, dash) + " "_u, out); + writeString(UString(tt, dash), out); + if(doCoref) writeString(" "_u + UString(rl, dash), out); + if(doCoref) writeString(" "_u + UString(rt, dash), out); writeString("\n"_u, out); for(unsigned int i = 0; i < tree.size(); i++) { @@ -546,7 +547,7 @@ Chunk::writeTreeBox() } if(tree.size() == 1) { - tree[0][0] = (UChar)L'─' + tree[0][0]; + tree[0][0] = u'\u2500' + tree[0][0]; // '─' return tree; } unsigned int center = tree.size() / 2; @@ -577,25 +578,36 @@ Chunk::writeTreeBox() { switch(tree[i][0][0]) { - case (UChar)L'│': tree[i][0][0] = (UChar)L'┤'; break; - case (UChar)L'├': tree[i][0][0] = (UChar)L'┼'; break; - case (UChar)L'┌': tree[i][0][0] = (UChar)L'┬'; break; - case (UChar)L'└': tree[i][0][0] = (UChar)L'┴'; break; - default: break; + case u'\u2502': // '│' + tree[i][0][0] = u'\u2524'; break; // '┤' + case u'\u251c': // '├' + tree[i][0][0] = u'\u253c'; break; // '┼' + case u'\u250c': // '┌' + tree[i][0][0] = u'\u252c'; break; // '┬' + case u'\u2514': // '└' + tree[i][0][0] = u'\u2534'; break; // '┴' + default: break; } } - tree[i][0] = UString(len - sz, (UChar)L'─') + tree[i][0]; + tree[i][0] = UString(len - sz, u'\u2500') + tree[i][0]; // '─' } - if(i < firstLine || i > lastLine) tree[i][0] = (UChar)L' ' + tree[i][0]; - else if(i == firstLine && i == lastLine) { - tree[i][0] = (UChar)L'─' + tree[i][0]; - } else if(i == firstLine) tree[i][0] = (UChar)L'┌' + tree[i][0]; - else if(i > firstLine && i < lastLine) - { - if(lines.count(i) == 0) tree[i][0] = (UChar)L'│' + tree[i][0]; - else tree[i][0] = (UChar)L'├' + tree[i][0]; + UChar prefix = ' '; + if (i > firstLine && i < lastLine) { + if (lines.count(i) == 0) { + prefix = u'\u2502'; // '│' + } else { + prefix = u'\u251c'; // '├' + } + } else if (i == firstLine) { + if (i == lastLine) { + prefix = u'\u2500'; // '─' + } else { + prefix = u'\u250c'; // '┌' + } + } else if (i == lastLine) { + prefix = u'\u2514'; // '└' } - else if(i == lastLine) tree[i][0] = (UChar)L'└' + tree[i][0]; + tree[i][0] = prefix + tree[i][0]; } return tree; } diff --git a/src/randpath.cc b/src/randpath.cc index d857a86..b8ae2da 100644 --- a/src/randpath.cc +++ b/src/randpath.cc @@ -91,14 +91,14 @@ void followPath(int idx) { paths.push_back(make_pair(ops[i].second, paths[idx].second)); A.getSymbol(paths.back().second, ops[i].first); - if(paths.back().second.size() > 0 && paths.back().second.back() == L'+') + if(paths.back().second.size() > 0 && paths.back().second.back() == '+') { paths.pop_back(); } } state = ops[0].second; A.getSymbol(paths[idx].second, ops[0].first); - if(paths[idx].second.size() > 0 && paths[idx].second.back() == L'+') + if(paths[idx].second.size() > 0 && paths[idx].second.back() == '+') { paths.erase(paths.begin() + idx); return; @@ -114,12 +114,12 @@ void generatePaths() for(unsigned int i = 0; i < prefix.size(); i++) { int sym = prefix[i]; - int sym2 = towlower(prefix[i]); - if(prefix[i] == L'<') + int sym2 = u_tolower(prefix[i]); + if(prefix[i] == '<') { for(unsigned int j = i+1; j < prefix.size(); j++) { - if(prefix[j] == L'>') + if(prefix[j] == '>') { sym = A(prefix.substr(i, j-i+1)); i = j; @@ -166,25 +166,25 @@ int main(int argc, char *argv[]) LtLocale::tryToSetLocale(); if(argc != 3) { - wcerr << "Usage: " << argv[0] << " transducer prefix" << endl; + cerr << "Usage: " << argv[0] << " transducer prefix" << endl; return EXIT_FAILURE; } FILE* tf = fopen(argv[1], "rb"); if(tf == NULL) { - wcerr << "Unable to open " << argv[1] << " for reading." << endl; + cerr << "Unable to open " << argv[1] << " for reading." << endl; return EXIT_FAILURE; } if(!load(tf)) { - wcerr << "Unable to read transducer." << endl; + cerr << "Unable to read transducer." << endl; return EXIT_FAILURE; } prefix = to_ustring(argv[2]); generatePaths(); if(paths.size() == 0) { - wcerr << "No paths begin with that prefix." << endl; + cerr << "No paths begin with that prefix." << endl; return EXIT_FAILURE; } //seed_seq s (prefix.begin(), prefix.end()); diff --git a/src/rtx_compiler.cc b/src/rtx_compiler.cc index 962fe29..8993d1a 100644 --- a/src/rtx_compiler.cc +++ b/src/rtx_compiler.cc @@ -136,8 +136,7 @@ RTXCompiler::nextTokenNoSpace() UChar c = getchar(); UChar next = peekchar(); UString ret; - if(c == (UChar)L'→') - { + if (c == u'\u2192') { // '→' ret = "->"_u; } else if(SPECIAL_CHARS.find(c) != string::npos) diff --git a/src/rtx_compiler.h b/src/rtx_compiler.h index 2721026..6d333c6 100644 --- a/src/rtx_compiler.h +++ b/src/rtx_compiler.h @@ -392,7 +392,7 @@ private: /** * Convert a string to an operator * @param op - the string from the rule - * @return bytecode for corresponding operation or L'\0' if not found + * @return bytecode for corresponding operation or '\0' if not found */ UChar lookupOperator(UString op); diff --git a/src/rtx_processor.cc b/src/rtx_processor.cc index d1bfeae..65532b4 100644 --- a/src/rtx_processor.cc +++ b/src/rtx_processor.cc @@ -1472,7 +1472,12 @@ RTXProcessor::writeBlank(UFILE* out) blank->target = blankQueue.front(); blankQueue.pop_front(); blank->isBlank = true; - blank->output(out); + if (printingText) { + blank->output(out); + } + if (printingTrees) { + blank->writeTree(treePrintMode, out); + } } bool @@ -1702,7 +1707,12 @@ RTXProcessor::processGLR(UFILE *out) // skip parseGraph stuff if a blank is the only thing being processed if(next->isBlank) { - next->output(out); + if (printingText) { + next->output(out); + } + if (printingTrees) { + next->writeTree(treePrintMode, out); + } if(furtherInput) { inputBuffer.push_back(readToken()); diff --git a/src/trx_compiler.cc b/src/trx_compiler.cc index 234655d..8b01907 100644 --- a/src/trx_compiler.cc +++ b/src/trx_compiler.cc @@ -657,9 +657,9 @@ TRXCompiler::processValue(xmlNode* node) ret += DROP; ret += STRING; ret += (UChar)(link.size() + 2); - ret += L'<'; + ret += '<'; ret += link; - ret += L'>'; + ret += '>'; } // TODO: what does attribute "queue" do? }