Belle II Software development
FTDConverter.cc
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * See git log for contributors and copyright holders. *
6 * This file is licensed under LGPL-3.0, see LICENSE.md. *
7 **************************************************************************/
8
9#include <fstream>
10#include <iostream>
11#include <string>
12#include <vector>
13#include <map>
14#include <string.h>
15#include "trg/trg/Utilities.h"
16
17unsigned DebugLevel = 1;
18
19using namespace std;
20
21vector<string> inputs;
22vector<unsigned> inputSizes;
23vector<string> inputBits;
24vector<string> inputNames;
25vector<string> outputs;
26map<string, string> logics;
27vector<string> expanded;
28vector<string> expanded2;
29vector<string> expandedcc;
30
31void shrink(char b[800]);
32void shrink(string&);
33void cosmetic(string&);
34void tocc(string&);
35void chopWord(char b[800], char c[800]);
36void chopWord(string&, string&);
37void removeComments(char b[800]);
38void getInput(char b[800]);
39void getOutput(char b[800]);
40void getLogic(char b[800]);
41void getLogicGND(string&);
42void tofunc(string&);
43string breakup(const string& logic);
44string decodeLogic(const string& logic);
45void kumacOutput(ofstream&, string logic, const string& ftd);
46
47class Term {
48public:
49 explicit Term(const string&);
50 virtual ~Term();
51
52public:
53// unsigned size(void) const;
54 string sentence(void) const;
55 void expand(void);
56 string expanded(void);
57
58private:
59 string _sentence;
60 vector<string> _words;
61 vector<Term> _terms;
62 string _expanded;
63};
64
65int
66main(int argc, char* argv[])
67{
68 cout << "ftd: version 1.01 : 2007/09/21 Y.Iwasaki" << endl;
69
70 //...Check arguments...
71 if (argc != 2) {
72 cout << "usage : ftd.v" << endl;
73 cout << " ftd.v : ftd logic file" << endl;
74
75 return -1;
76 }
77
78 //...Open file...
79 cout << "ftd ... reading verilog file : "
80 << argv[1] << endl;
81 ifstream file(argv[1], ios::in);
82 if (! file.is_open()) {
83 cout << " !!! can not open file : " << argv[1] << endl;
84 exit(-1);
85 }
86
87 //...Read source...
88 char b[800];
89 unsigned state = 0;
90 while (! file.eof()) {
91 file.getline(b, 800);
92
93 //...Remove unnecessary spaces...
94 shrink(b);
95
96 if (DebugLevel) {
97 string tmp = b;
98 shrink(tmp);
99 bool tmpWrong = false;
100 for (unsigned i = 0; i < tmp.size(); i++) {
101 if (b[i] != tmp[i])
102 tmpWrong = true;
103 }
104 cout << "state=" << state << ",b0:[" << b << "], tmpWrong="
105 << tmpWrong << endl;
106 }
107
108 //...Skip blank line...
109 if (b[0] == 0) continue;
110
111 //...Input definitions...
112 if (state == 0) {
113 if (strstr(b, "Inputs"))
114 state = 1;
115 } else if (state == 1) {
116 getInput(b);
117 if (strstr(b, "Outputs"))
118 state = 2;
119 } else if (state == 2) {
120 getOutput(b);
121 if (strstr(b, "FTD logics"))
122 state = 3;
123 } else if (state == 3) {
124 string tmp = b;
125 if (tmp.find("end") != string::npos)
126 break;
127 getLogic(b);
128 }
129 }
130 file.close();
131
132 //...Logic decoding...
133 for (unsigned i = 0; i < outputs.size(); i++) {
134 string logic = decodeLogic(logics[outputs[i]]);
135 shrink(logic);
136 expanded.push_back(logic);
137 string logic_cc = logic;
138
139 //...For algorithm file...
140 for (unsigned j = 0; j < inputBits.size(); j++) {
141 while (1) {
142 char crep[10];
143 sprintf(crep, "%d", (int)j);
144 string inp = inputBits[j];
145 string rep = crep;
146 string::size_type p = logic.find(inp);
147 if (p != string::npos)
148 logic.replace(p, inp.size(), rep, 0, rep.size());
149 else
150 break;
151 }
152 }
153 shrink(logic);
154 cosmetic(logic);
155 expanded2.push_back(logic);
156
157 //...For cc file...
158 for (unsigned j = 0; j < inputBits.size(); j++) {
159 while (1) {
160 char crep[10];
161 sprintf(crep, "i[%d]", (int)j);
162 string inp = inputBits[j];
163 string rep = crep;
164 string::size_type p = logic_cc.find(inp);
165 if (p != string::npos)
166 logic_cc.replace(p, inp.size(), rep, 0, rep.size());
167 else
168 break;
169 }
170 }
171
172 shrink(logic_cc);
173 cosmetic(logic_cc);
174 tocc(logic_cc);
175 string right_cc = "b[" + Belle2::TRGUtilities::itostring(i) + "] = (";
176 logic_cc = right_cc + logic_cc + ");";
177
178 expandedcc.push_back(logic_cc);
179
180 if (DebugLevel) {
181 cout << "->" << logic << "<-" << endl;
182 cout << "->" << logic_cc << "<-" << endl;
183
184 }
185 }
186
187 //...Otain file name...
188 string filename = argv[1];
189 string::size_type s = filename.find_last_of("/");
190 if (s != string::npos)
191 filename = filename.substr(s + 1);
192 s = filename.find_last_of(".");
193 if (s != string::npos)
194 filename = filename.substr(0, s);
195
196 //...Summary for text file...
197 string tFilename = filename + ".txt";
198 string iFilename = filename + ".inp";
199 string oFilename = filename + ".oup";
200 cout << " Text file :" << tFilename << endl;
201 ofstream tFile(tFilename.c_str(), ios::out);
202 if (! tFile.is_open()) {
203 cout << " !!! can not open file : " << tFilename << endl;
204 exit(-2);
205 }
206 cout << " Input file :" << iFilename << endl;
207 ofstream iFile(iFilename.c_str(), ios::out);
208 if (! iFile.is_open()) {
209 cout << " !!! can not open file : " << iFilename << endl;
210 exit(-2);
211 }
212 cout << " Output file:" << oFilename << endl;
213 ofstream oFile(oFilename.c_str(), ios::out);
214 if (! oFile.is_open()) {
215 cout << " !!! can not open file : " << oFilename << endl;
216 exit(-2);
217 }
218 tFile << "----- relations -----------------------" << endl;
219 for (unsigned i = 0; i < outputs.size(); i++) {
220 tFile << i << " : " << outputs[i] << " = " << logics[outputs[i]]
221 << endl;
222 }
223 tFile << "----- inputs -------------------------" << endl;
224 for (unsigned i = 0; i < inputBits.size(); i++) {
225 tFile << i << " : " << inputBits[i] << endl;
226 iFile << i << " " << inputNames[i] << endl;
227 }
228 tFile << "----- outputs ------------------------" << endl;
229 for (unsigned i = 0; i < outputs.size(); i++) {
230 tFile << i << " : " << outputs[i] << endl;
231 tFile << " " << expanded[i] << endl;
232 tFile << " " << expanded2[i] << endl;
233 oFile << i << " " << outputs[i] << endl;
234 }
235 tFile << "----- logics ------------------------" << endl;
236 for (unsigned i = 0; i < outputs.size(); i++) {
237 tFile << i << " : " << outputs[i] << endl;
238 tFile << " " << logics[outputs[i]] << endl;
239 tFile << " " << expanded[i] << endl;
240 tFile << " " << expanded2[i] << endl;
241 }
242 tFile.close();
243 iFile.close();
244 oFile.close();
245
246 //...Summary for alg file...
247 string aFilename = filename + ".alg";
248 cout << " alg file :" << aFilename << endl;
249 ofstream aFile(aFilename.c_str(), ios::out);
250 if (! aFile.is_open()) {
251 cout << " !!! can not open file : " << aFilename << endl;
252 exit(-3);
253 }
254 for (unsigned i = 0; i < expanded2.size(); i++) {
255 aFile << i << " : ( " << expanded2[i] << " )" << endl;
256 }
257 aFile.close();
258
259 //...C++ alg file...
260 string cFilename = filename + ".cc";
261 string funcname = filename;
262 tofunc(funcname);
263 cout << " c++ file :" << cFilename << endl;
264 ofstream cFile(cFilename.c_str(), ios::out);
265 if (! cFile.is_open()) {
266 cout << " !!! can not open file : " << cFilename << endl;
267 exit(-3);
268 }
269 cFile << "namespace Belle2 {" << endl;
270 cFile << "void " << funcname << "(bool * b, bool * i) {" << endl;
271 for (unsigned i = 0; i < expandedcc.size(); i++) {
272 cFile << expandedcc[i] << endl;
273 }
274 cFile << "}" << endl;
275 cFile << "}" << endl;
276 cFile.close();
277
278 //...Summary for paw...
279 string kFilename = filename + ".kumac";
280 cout << " kumac file :" << kFilename << endl;
281 ofstream kFile(kFilename.c_str(), ios::out);
282 if (! kFile.is_open()) {
283 cout << " !!! can not open file : " << kFilename << endl;
284 exit(-3);
285 }
286 kFile << "macro main wait=wait baseRise=197 baseFall=293" << endl;
287 for (unsigned i = 0; i < expanded.size(); i++) {
288 string logic = expanded[i];
289 kFile << "*...FTD " << i << "..." << endl;
290 kFile << "* " << logic << endl;
291 kumacOutput(kFile, logic, outputs[i]);
292 kFile << endl;
293 }
294 kFile << "return" << endl;
295 kFile.close();
296
297 return 0;
298}
299
300void
301shrink(char b[800])
302{
303 char c[800];
304 unsigned i = 0;
305 unsigned j = 0;
306 bool deleteSpace = true;
307 while (b[i]) {
308 char d = b[i++];
309 char e = b[i];
310 if (d == '\t') d = ' ';
311 if (d == ';') d = ' ';
312 if ((d == '|') && (e == '|')) d = ' ';
313
314 const bool space = (d == ' ');
315 if (deleteSpace && space)
316 continue;
317 if (space)
318 deleteSpace = true;
319 else
320 deleteSpace = false;
321 c[j] = d;
322 ++j;
323 }
324 c[j] = 0;
325 strcpy(b, c);
326}
327
328void
329removeComments(char b[800])
330{
331 if ((b[0] == 0) || (b[1] == 0)) return;
332 unsigned i = 1;
333 while (b[i]) {
334 char c = b[i - 1];
335 char d = b[i];
336
337 if ((c == '/') && (d == '/')) {
338 b[i - 1] = 0;
339 return;
340 }
341 i++;
342 }
343}
344
345void
346chopWord(char b[800], char c[800])
347{
348 c[0] = 0;
349 unsigned i = 0;
350 while (1) {
351 c[i] = b[i];
352 if ((b[i] == ' ') || (b[i] == 0)) {
353 c[i] = 0;
354 break;
355 }
356 ++i;
357 }
358
359 if (b[i] == 0) {
360 b[0] = 0;
361 return;
362 }
363
364// for (unsigned j = i, k = 0; j++, k++; j < 800) {
365 for (unsigned j = i, k = 0; j < 800; j++, k++) {
366 b[k] = b[j];
367 ++k;
368 if (b[j] == 0)
369 return;
370 }
371}
372
373void
374getInput(char b[800])
375{
376 char w[800];
377
378 //...First word should be "reg"...
379 chopWord(b, w);
380 if (strcmp(w, "reg")) return;
381
382 //...Next word should be the name of input, or bit width...
383 unsigned b0 = 0;
384 unsigned b1 = 0;
385 chopWord(b, w);
386 if (w[0] == '[') {
387
388 //...One character...
389 if (w[2] == ':') {
390 b0 = w[3] - '0';
391 b1 = w[1] - '0';
392 } else {
393 b0 = w[4] - '0';
394 b1 = (w[1] - '0') * 10 + (w[2] - '0');
395 }
396
397 chopWord(b, w);
398 }
399
400 inputs.push_back(string(w));
401 inputSizes.push_back(b1 - b0);
402
403 if (b0 != b1) {
404 if ((b1 - b0) < 10) {
405 for (unsigned i = b0; i <= b1; i++) {
406 char n[2];
407 n[0] = '0' + i;
408 n[1] = 0;
409 inputBits.push_back(string(w) + "[" + string(n) + "]");
410 inputNames.push_back(string(w) + string(n));
411 }
412 } else {
413 for (unsigned i = b0; i <= b1; i++) {
414 if (i < 10) {
415 char n[2];
416 n[0] = '0' + i;
417 n[1] = 0;
418 inputBits.push_back(string(w) + "[" + string(n) + "]");
419 inputNames.push_back(string(w) + string(n));
420 }
421 //...Assuming less than 20...
422 else {
423 char n[3];
424 n[0] = '1';
425 n[1] = '0' + i - 10;
426 n[2] = 0;
427 inputBits.push_back(string(w) + "[" + string(n) + "]");
428 inputNames.push_back(string(w) + string(n));
429 }
430 }
431 if (DebugLevel) {
432// cout << inputNames.last() << endl;
433 }
434 }
435 } else {
436 inputBits.push_back(string(w));
437 inputNames.push_back(string(w));
438 }
439}
440
441void
442getOutput(char b[800])
443{
444 char w[800];
445
446 //...First word should be "reg"...
447 chopWord(b, w);
448 if (strcmp(w, "reg")) return;
449
450 //...Next word should be the name...
451 chopWord(b, w);
452
453 outputs.push_back(string(w));
454}
455
456void
457getLogic(char b[800])
458{
459 char w[800];
460
461 //...First word should be the output name...
462 string tmp = b;
463 getLogicGND(tmp);
464 strcpy(b, tmp.c_str());
465 removeComments(b);
466 chopWord(b, w);
467 string name = w;
468 chopWord(b, w); // This must be '='.
469
470 for (unsigned i = 0; i < outputs.size(); i++) {
471 if (name == outputs[i]) {
472 string logic = b;
473 logics[name] = logic;
474 }
475 }
476}
477
478string
479breakup(const string& logic)
480{
481 string s = logic;
482 string sp = " ";
483
484 //...Instert spaces...
485// for (string::size_type i = s.size(); i >= 0; i--) {
486 int len = int(s.size());
487 for (int i = len; i >= 0; i--) {
488 char c = s[i];
489 if ((c == '(') ||
490 (c == ')') ||
491 (c == '&') ||
492 (c == '|') ||
493 (c == '>') ||
494 (c == '<') ||
495 (c == '!') ||
496 (c == '=')) {
497 string d = s.substr(i, 1);
498
499 if (i == 0) {
500 s.insert(i + 1, sp);
501 } else if (i == int(s.size())) {
502 s.insert(i, sp);
503 } else if (c == '=') {
504 // assuming only "=="
505 s.insert(i - 1, sp);
506 s.insert(i + 2, sp);
507 } else {
508 s.insert(i, sp);
509 s.insert(i + 2, sp);
510 }
511
512 if (DebugLevel) {
513 cout << "i=" << i << ",d=[" << d << "]" << endl;
514 cout << s << endl;
515 }
516 }
517 }
518
519 char w[800];
520 strcpy(w, s.c_str());
521 shrink(w);
522
523 if (DebugLevel) {
524 cout << " breakup : in=[" << logic << "]" << endl;
525 cout << " out=[" << string(w) << "]" << endl;
526 }
527
528 return string(w);
529}
530
531string
532decodeLogic(const string& logic)
533{
534 string s = logic;
535 s = breakup(s);
536 char c[800];
537 strcpy(c, s.c_str());
538
539 string f;
540 char p0[800] = "";
541 char p1[800] = "";
542 while (1) {
543 char cw[800];
544 chopWord(c, cw);
545 if (! cw[0]) {
546 if (f.size() && (p1[0] != 0)) f += " ";
547 f += p1;
548 if (f.size() && (p0[0] != 0)) f += " ";
549 f += p0;
550 break;
551 }
552
553 if (DebugLevel) {
554 cout << "p0=" << p0 << ",p1=" << p1 << endl;
555 }
556
557 //...'>'...
558 if (p0[0] == '>') {
559
560 //...Search for width...
561 string name = p1;
562 unsigned n = 999;
563 for (unsigned i = 0; i < inputs.size(); i++) {
564 if (inputs[i] == p1) {
565 n = i;
566 break;
567 }
568 }
569 unsigned width = inputSizes[n] + 1;
570 string x = "( ";
571 if (cw[0] == '0') {
572 char b = '0';
573 for (unsigned i = 0; i < width; i++) {
574 if (i) x += " | ";
575 x += name + "[" + char(b + i) + "]";
576 }
577 } else if (cw[0] == '1') {
578 char b = '0';
579 for (unsigned i = 1; i < width; i++) {
580 if (i > 1) x += " | ";
581 x += name + "[" + char(b + i) + "]";
582 }
583 } else if (cw[0] == '2') {
584 char b = '0';
585 x = "(" + name + "[0] & " + name + "[1] )";
586 for (unsigned i = 2; i < width; i++) {
587 x += " | ";
588 x += name + "[" + char(b + i) + "]";
589 }
590 } else if (cw[0] == '3') {
591 char b = '0';
592 for (unsigned i = 2; i < width; i++) {
593 if (i > 2) x += " | ";
594 x += name + "[" + char(b + i) + "]";
595 }
596 } else if (cw[0] == '4') {
597 char b = '0';
598 x = "(" + name + "[1] & " + name + "[2] )";
599 x += "| (" + name + "[0] & " + name + "[2] )";
600 for (unsigned i = 3; i < width; i++) {
601 x += " | ";
602 x += name + "[" + char(b + i) + "]";
603 }
604 } else {
605 cout << "decodeLogic !!! [> with 4] is not supported"
606 << endl;
607 cout << " " << logic << endl;
608 }
609
610 x += " )";
611
612 if (DebugLevel) {
613 cout << " s=" << p1 << " " << p0 << " " << cw
614 << endl;
615 cout << " name=" << name << ",width=" << width
616 << endl;
617 cout << " x={" << x << "}" << endl;
618 }
619
620 strcpy(p1, x.c_str());
621 strcpy(p0, "");
622 strcpy(cw, "");
623 }
624
625 //...'<'...
626 else if (p0[0] == '<') {
627 cout << "decodeLogic !!! [> with 4] is not supported"
628 << endl;
629 }
630
631 //...'='...
632 else if (p0[0] == '=') {
633
634 //...Search for width...
635 string name = p1;
636 unsigned n = 999;
637 for (unsigned i = 0; i < inputs.size(); i++) {
638 if (inputs[i] == p1) {
639 n = i;
640 break;
641 }
642 }
643 unsigned width = inputSizes[n] + 1;
644 string x = "( ";
645 if (cw[0] == '0') {
646 char b = '0';
647 for (unsigned i = 0; i < width; i++) {
648 if (i) x += " & ";
649 x += "!" + name + "[" + char(b + i) + "]";
650 }
651 } else {
652 cout << "decodeLogic !!! '== n' is not supported"
653 << endl;
654 cout << " " << logic << endl;
655 }
656
657 if (DebugLevel) {
658 cout << " s=" << p1 << " " << p0 << " " << cw
659 << endl;
660 cout << " name=" << name << ",width=" << width
661 << endl;
662 cout << " x={" << x << "}" << endl;
663 }
664
665 x += " )";
666
667 strcpy(p1, x.c_str());
668 strcpy(p0, "");
669 strcpy(cw, "");
670 }
671
672 if (f.size() && (p1[0] != 0)) f += " ";
673 f += p1;
674 strcpy(p1, p0);
675 strcpy(p0, cw);
676
677 }
678
679 Term t(f);
680 t.expand();
681
682 return t.expanded();
683}
684
685Term::Term(const string& a)
686 : _sentence(a)
687{
688 char b[800];
689 strcpy(b, _sentence.c_str());
690
691 char w[800];
692 while (1) {
693 chopWord(b, w);
694 if (w[0] == 0) break;
695 _words.push_back(string(w));
696 }
697
698 //...Create term candidates...
699 unsigned inP = 0;
700 vector<string> termCandidates;
701 string t;
702 for (unsigned i = 0; i < _sentence.size(); i++) {
703 char c = _sentence[i];
704
705 if (c == '(') {
706 t += c;
707 ++inP;
708 continue;
709 } else if (c == ')') {
710 t += c;
711 --inP;
712 continue;
713 }
714
715 if (inP) {
716 t += c;
717 continue;
718 }
719
720 if (c == '|') {
721 termCandidates.push_back(t);
722 t = "";
723 continue;
724 }
725
726 t += c;
727 }
728 termCandidates.push_back(t);
729
730 //...Check term candidates...
731 if (termCandidates.size() > 1) {
732 for (unsigned i = 0; i < termCandidates.size(); i++) {
733 Term x(termCandidates[i]);
734 _terms.push_back(x);
735 }
736
737// cout << "Term list:#=" << _terms.size() << endl;
738// for (unsigned i = 0; i < _terms.size(); i++) {
739// cout << i << ":" << _terms[i].sentence() << endl;
740// }
741 }
742}
743
744Term::~Term()
745{
746}
747
748string
749Term::sentence(void) const
750{
751 return _sentence;
752}
753
754void
755Term::expand(void)
756{
757 _expanded = "";
758
759 //...Have sub-terms...
760 if (_terms.size() > 1) {
761 for (unsigned i = 0; i < _terms.size(); i++) {
762 _terms[i].expand();
763 if (i)
764 _expanded += " | ";
765 _expanded += _terms[i].expanded();
766 }
767 return;
768 }
769
770 //...Expand...
771 _expanded = _sentence;
772 while (1) {
773 unsigned a = 0;
774 unsigned b = 0;
775 for (unsigned i = 0; i < _expanded.size(); i++) {
776 char c = _expanded[i];
777 if (c == '(') {
778 a = i;
779 } else if (c == ')') {
780 b = i;
781 break;
782 }
783 }
784
785 //...No ()...
786 if (a == b) return;
787
788 //...necessary to expand...
789 string s0 = _expanded.substr(0, a - 1);
790 if (a == 0) s0 = "";
791 string p = _expanded.substr(a + 1, b - a - 1);
792 string s1 = _expanded.substr(b + 1);
793
794// cout << "a,b=" << a << "," << b << endl;
795// cout << " s0=" << s0 << endl;
796// cout << " p =" << p << endl;
797// cout << " s1=" << s1 << endl;
798
799 //...divide p into two...
800 unsigned a1 = 0;
801 for (unsigned i = 0; i < p.size(); i++) {
802 char c = p[i];
803 if (c == '|') {
804 a1 = i;
805 break;
806 }
807 }
808 if (a1) {
809 string p0 = p.substr(0, a1 - 1);
810 string p1 = p.substr(a1 + 1);
811 _expanded = s0 + p0 + s1 + " | " + s0 + " (" + p1 + ") " + s1;
812
813 Term tmp(_expanded);
814 tmp.expand();
815 _expanded = tmp.expanded();
816 } else {
817 _expanded = s0 + p + s1;
818 }
819
820 // cout << "--->" << endl;
821 // cout << _expanded << endl;
822 // cout << "<---" << endl;
823 }
824}
825
826string
827Term::expanded(void)
828{
829 return _expanded;
830}
831
832void
833shrink(string& s)
834{
835 string t;
836 bool deleteSpace = true;
837 for (unsigned i = 0; i < s.size(); i++) {
838 char d = s[i];
839 char e = 0;
840 if ((i + 1) < s.size())
841 e = s[i + 1];
842
843 if (d == '\t') d = ' ';
844 if (d == ';') d = ' ';
845 if ((d == '|') && (e == '|')) d = ' ';
846
847 const bool space = (d == ' ');
848 if (deleteSpace && space)
849 continue;
850 if (space)
851 deleteSpace = true;
852 else
853 deleteSpace = false;
854
855 t += d;
856 }
857
858 s = t;
859}
860
861void
862cosmetic(string& s)
863{
864 for (unsigned i = 0; i < s.size(); i++) {
865 char d = s[i];
866 char e = 0;
867 if ((i + 1) < s.size())
868 e = s[i + 1];
869
870 if (d == '&')
871 s[i] = '*';
872 else if (d == '|')
873 s[i] = '+';
874 else if ((d == '!') && (e == ' '))
875 s.erase(i + 1, 1);
876 }
877}
878
879void
880getLogicGND(string& s)
881{
882// cout << "s0=" << s << endl;
883 string g = "= 0";
884 string::size_type p = s.find(g);
885 if (p != string::npos)
886 s.replace(p, 3, "= GND", 0, 5);
887// cout << "s1=" << s << endl;
888}
889
890void
891kumacOutput(ofstream& f, string logic, const string& ftd)
892{
893 const string tab = " ";
894 bool first = true;
895
896 //...Check how many ORs...
897 unsigned nO = 0;
898 for (unsigned i = 0; i < logic.size(); i++)
899 if (logic[i] == '|')
900 ++nO;
901
902 unsigned n = 0;
903 while (1) {
904 string t;
905 chopWord(logic, t);
906 if (t.empty()) break;
907
908 if (t == "|")
909 first = true;
910
911 if (first) {
912 f << "[wait]" << endl;
913 f << tab << "zone 1 6 1" << endl;
914 f << tab << "title '" << ftd << " " << n + 1 << "/" << nO + 1 <<
915 "'" << endl;
916 first = false;
917 ++n;
918 }
919
920 for (unsigned i = 0; i < inputBits.size(); i++) {
921 if (t == inputBits[i]) {
922 f << tab << "set hcol 2" << endl;
923 f << tab << "id=[baseRise]+" << i << ";"
924 << "hi/pl [id]" << endl;
925 f << tab << "set hcol 4" << endl;
926 f << tab << "id=[baseFall]+" << i << ";"
927 << "hi/pl [id] s" << endl;
928 f << tab << "atit '" << t << "' ' '" << endl;
929 first = false;
930 break;
931 }
932 }
933 }
934}
935
936void
937chopWord(string& b, string& c)
938{
939 c = "";
940 unsigned i = 0;
941 while (1) {
942 if ((b[i] == ' ') || (b[i] == 0))
943 break;
944
945 c += b[i];
946 ++i;
947 }
948
949 int l = b.size() - i - 1;
950 if (l > 0)
951 b = b.substr(i + 1, l);
952 else
953 b = "";
954}
955
956void
957tocc(string& s)
958{
959 while (s.find("*") != string::npos) {
960 const unsigned n = s.size();
961 for (unsigned i = 0; i < n; i++)
962 if (s[i] == '*')
963 s.replace(i, 2, "&& ", 0, 3);
964 }
965 while (s.find("+") != string::npos) {
966 const unsigned n = s.size();
967 for (unsigned i = 0; i < n; i++)
968 if (s[i] == '+')
969 s.replace(i, 2, ") || ( ", 0, 6);
970 }
971}
972
973void
974tofunc(string& s)
975{
976 const unsigned n = s.size();
977 for (unsigned i = 0; i < n; i++)
978 if (s[i] == '.')
979 s.replace(i, 1, "_", 0, 1);
980}
static std::string itostring(int i)
converts int to string. (Use boost::lexical_cast)
Definition: Utilities.cc:50
STL namespace.