1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: ftest_io.cc,v 1.7 1997-10-15 13:53:21 schmidt Exp $ */ |
---|
3 | |
---|
4 | //{{{ docu |
---|
5 | // |
---|
6 | // ftest_io.cc - io utilities for the factory test environment. |
---|
7 | // |
---|
8 | //}}} |
---|
9 | |
---|
10 | #include <ctype.h> |
---|
11 | #include <string.h> |
---|
12 | #include <stdlib.h> |
---|
13 | #include <iostream.h> |
---|
14 | #include <strstream.h> |
---|
15 | |
---|
16 | #include <factory.h> |
---|
17 | |
---|
18 | #include "ftest_util.h" |
---|
19 | |
---|
20 | // |
---|
21 | // - external functions. |
---|
22 | // |
---|
23 | |
---|
24 | //{{{ CanonicalForm ftestGetCanonicalForm ( const char * canFormSpec ) |
---|
25 | //{{{ docu |
---|
26 | // |
---|
27 | // ftestGetCanonicalForm() - read a canonical form from canFormSpec, |
---|
28 | // return it. |
---|
29 | // |
---|
30 | //}}} |
---|
31 | CanonicalForm |
---|
32 | ftestGetCanonicalForm ( const char * canFormSpec ) |
---|
33 | { |
---|
34 | // get string to read canonical form from |
---|
35 | const char * stringF = canFormSpec; |
---|
36 | stringF = ftestSkipBlancs( stringF ); |
---|
37 | if ( *stringF == '$' ) { |
---|
38 | const char * tokenCursor = ftestSkipBlancs( stringF+1 ); |
---|
39 | // read canonical form from environment |
---|
40 | stringF = getenv( tokenCursor ); |
---|
41 | if ( ! stringF ) |
---|
42 | ftestError( CanFormSpecError, |
---|
43 | "no environment variable `$%s' set\n", |
---|
44 | tokenCursor ); |
---|
45 | } |
---|
46 | |
---|
47 | // create terminated CanonicalForm |
---|
48 | int i = strlen( stringF ); |
---|
49 | char * terminatedStringF = new char[i+2]; |
---|
50 | char * stringCursor = terminatedStringF; |
---|
51 | while ( *stringF ) { |
---|
52 | switch ( *stringF ) { |
---|
53 | case '.': *stringCursor = '*'; break; |
---|
54 | case '{': *stringCursor = '('; break; |
---|
55 | case '}': *stringCursor = ')'; break; |
---|
56 | default: *stringCursor = *stringF; break; |
---|
57 | } |
---|
58 | stringF++; stringCursor++; |
---|
59 | } |
---|
60 | *stringCursor++ = ';'; |
---|
61 | *stringCursor = '\0'; |
---|
62 | |
---|
63 | // read f |
---|
64 | CanonicalForm f; |
---|
65 | istrstream( terminatedStringF ) >> f; |
---|
66 | |
---|
67 | delete [] terminatedStringF; |
---|
68 | return f; |
---|
69 | } |
---|
70 | //}}} |
---|
71 | |
---|
72 | //{{{ Variable ftestGetVariable ( const char * stringVariable ) |
---|
73 | //{{{ docu |
---|
74 | // |
---|
75 | // ftestGetVariable() - read a variable from stringVariable, |
---|
76 | // return it. |
---|
77 | // |
---|
78 | //}}} |
---|
79 | Variable |
---|
80 | ftestGetVariable ( const char * stringVariable ) |
---|
81 | { |
---|
82 | Variable v; |
---|
83 | stringVariable = ftestSkipBlancs( stringVariable ); |
---|
84 | |
---|
85 | if ( isalpha( *stringVariable ) ) |
---|
86 | v = Variable( *stringVariable ); |
---|
87 | else if ( isdigit( *stringVariable ) ) |
---|
88 | v = Variable(); |
---|
89 | else |
---|
90 | ftestError( CommandlineError, |
---|
91 | "variable expected at `%s'\n", stringVariable ); |
---|
92 | |
---|
93 | stringVariable = ftestSkipBlancs( stringVariable+1 ); |
---|
94 | if ( *stringVariable ) |
---|
95 | ftestError( CommandlineError, |
---|
96 | "extra characters after var spec `%s'\n", stringVariable ); |
---|
97 | |
---|
98 | return v; |
---|
99 | } |
---|
100 | //}}} |
---|
101 | |
---|
102 | //{{{ int ftestGetint ( const char * stringInt ) |
---|
103 | //{{{ docu |
---|
104 | // |
---|
105 | // ftestGetint() - read an integer from stringInt, |
---|
106 | // return it. |
---|
107 | // |
---|
108 | //}}} |
---|
109 | int |
---|
110 | ftestGetint ( const char * stringInt ) |
---|
111 | { |
---|
112 | const char * tokenCursor; |
---|
113 | |
---|
114 | int i = (int)strtol( stringInt, (char**)&tokenCursor, 0 ); |
---|
115 | |
---|
116 | // do error checks |
---|
117 | if ( stringInt == tokenCursor ) |
---|
118 | ftestError( CommandlineError, |
---|
119 | "integer expected at `%s'\n", stringInt ); |
---|
120 | |
---|
121 | stringInt = ftestSkipBlancs( tokenCursor ); |
---|
122 | if ( *stringInt ) |
---|
123 | ftestError( CommandlineError, |
---|
124 | "extra characters after int spec `%s'\n", stringInt ); |
---|
125 | |
---|
126 | return i; |
---|
127 | } |
---|
128 | //}}} |
---|
129 | |
---|
130 | //{{{ void ftestPrintResult ( const char * resultName, const CanonicalForm & result ) |
---|
131 | //{{{ docu |
---|
132 | // |
---|
133 | // ftestPrintResult() - print a canonical form. |
---|
134 | // |
---|
135 | //}}} |
---|
136 | void |
---|
137 | ftestPrintResult ( const char * resultName, const CanonicalForm & result ) |
---|
138 | { |
---|
139 | if ( ftestPrintResultFlag ) { |
---|
140 | ftestPrint( "result: %s\n", "@@%s\n", resultName ); |
---|
141 | cout << result << endl; |
---|
142 | ftestPrint( (char *)0, "@@\n" ); |
---|
143 | } else if ( ! ftestPrintFlag ) |
---|
144 | cout << result << endl; |
---|
145 | } |
---|
146 | //}}} |
---|
147 | |
---|
148 | //{{{ void ftestPrintResult ( const char * resultName, const CFFList & result ) |
---|
149 | //{{{ docu |
---|
150 | // |
---|
151 | // ftestPrintResult() - print a list of canonical form factors |
---|
152 | // |
---|
153 | //}}} |
---|
154 | void |
---|
155 | ftestPrintResult ( const char * resultName, const CFFList & result ) |
---|
156 | { |
---|
157 | CFFListIterator I; |
---|
158 | |
---|
159 | if ( ftestPrintResultFlag ) { |
---|
160 | ftestPrint( "result: %s\n", "@@%s\n", resultName ); |
---|
161 | for ( I = result; I.hasItem(); I++ ) |
---|
162 | cout << I.getItem() << endl; |
---|
163 | ftestPrint( (char *)0, "@@\n" ); |
---|
164 | } else if ( ! ftestPrintFlag ) |
---|
165 | for ( I = result; I.hasItem(); I++ ) |
---|
166 | cout << I.getItem() << endl; |
---|
167 | } |
---|
168 | //}}} |
---|
169 | |
---|
170 | //{{{ void ftestPrintResult ( const char * resultName, const int result ) |
---|
171 | //{{{ docu |
---|
172 | // |
---|
173 | // ftestPrintResult() - print an integer. |
---|
174 | // |
---|
175 | //}}} |
---|
176 | void |
---|
177 | ftestPrintResult ( const char * resultName, const int result ) |
---|
178 | { |
---|
179 | if ( ftestPrintResultFlag ) { |
---|
180 | ftestPrint( "result: %s\n", "@@%s\n", resultName ); |
---|
181 | cout << result << endl; |
---|
182 | ftestPrint( (char *)0, "@@\n" ); |
---|
183 | } else if ( ! ftestPrintFlag ) |
---|
184 | cout << result << endl; |
---|
185 | } |
---|
186 | //}}} |
---|