Révision 132 pobysoC-4.0/src/pobyso.c
pobyso.c (revision 132) | ||
---|---|---|
42 | 42 |
va_end(va); |
43 | 43 |
} /* End pobyso_autoprint. */ |
44 | 44 |
|
45 |
/* @see pobyso.h#pobyso_parse*/ |
|
46 |
pobyso_func_exp_t |
|
47 |
pobyso_parse(const char* expression) |
|
48 |
{ |
|
49 |
int expressionLength, i; |
|
50 |
char *expressionWithSemiCo; |
|
51 |
sollya_obj_t expressionStringSa; |
|
52 |
sollya_obj_t expressionSa; |
|
53 | 45 |
|
54 |
/* Arguments check. */ |
|
55 |
if (expression == NULL) |
|
56 |
{ |
|
57 |
pobyso_error_message("pobyso_parse", |
|
58 |
"NULL_POINTER_ARGUMENT", |
|
59 |
"The expression is a NULL pointer"); |
|
60 |
return(sollya_lib_error()); |
|
61 |
} |
|
62 |
expressionLength = strlen(expression); |
|
63 |
if (expressionLength == 0) |
|
64 |
{ |
|
65 |
pobyso_error_message("pobyso_parse", |
|
66 |
"EMPTY_STRING_ARGUMENT", |
|
67 |
"The expression is an empty string"); |
|
68 |
return(sollya_lib_error()); |
|
69 |
} |
|
70 |
/* Search from the last char of the expression until, whichever happens |
|
71 |
* first: |
|
72 |
* a ";" is found; |
|
73 |
* a char != ';' is found the the ";" is appended. |
|
74 |
* If the head of the string is reached before any of these two events happens |
|
75 |
* return an error. |
|
76 |
*/ |
|
77 |
for (i = expressionLength - 1 ; i >= 0 ; i--) |
|
78 |
{ |
|
79 |
if (expression[i] == ';') /* Nothing special to do: |
|
80 |
try to parse the string*/ |
|
81 |
{ |
|
82 |
/* This ugly cast comes from a deficient definition in Sollya: |
|
83 |
sollya_lib_string does not take a const char * argument. */ |
|
84 |
expressionStringSa = sollya_lib_string((char*)expression); |
|
85 |
expressionSa = sollya_lib_parse(expressionStringSa); |
|
86 |
sollya_lib_free(expressionStringSa); |
|
87 |
return(expressionSa); |
|
88 |
} |
|
89 |
else |
|
90 |
{ |
|
91 |
if (expression[i] == ' ' || expression[i] == '\t') /* A blank, |
|
92 |
just continue. */ |
|
93 |
{ |
|
94 |
continue; |
|
95 |
} |
|
96 |
else /* a character != ';' and from a blank: create the ';'ed string. */ |
|
97 |
{ |
|
98 |
/* Create a new string for the expression, add the ";" and |
|
99 |
* and call sollya_lib_parse_string. */ |
|
100 |
expressionWithSemiCo = calloc(i + 3, sizeof(char)); |
|
101 |
if (expressionWithSemiCo == NULL) |
|
102 |
{ |
|
103 |
pobyso_error_message("pobyso_parse", |
|
104 |
"MEMORY_ALLOCATION_ERROR", |
|
105 |
"Could not allocate the expression string"); |
|
106 |
return(sollya_lib_error()); |
|
107 |
} |
|
108 |
strncpy(expressionWithSemiCo, expression, i + 1); |
|
109 |
expressionWithSemiCo[i + 1] = ';'; |
|
110 |
expressionWithSemiCo[i + 2] = '\0'; |
|
111 |
expressionStringSa = sollya_lib_string(expressionWithSemiCo); |
|
112 |
expressionSa = sollya_lib_parse(expressionStringSa); |
|
113 |
free(expressionWithSemiCo); |
|
114 |
sollya_lib_free(expressionStringSa); |
|
115 |
return(expressionSa); |
|
116 |
} /* End character != ';' and from a blank. */ |
|
117 |
/* Create a new string for the expression, add the ";" and |
|
118 |
* and call sollya_lib_parse_string. */ |
|
119 |
} /* End else. */ |
|
120 |
} /* End for. */ |
|
121 |
/* We get here, it is because we did not find any char == anything different |
|
122 |
* from ' ' or '\t': the string is empty. |
|
123 |
*/ |
|
124 |
pobyso_error_message("pobyso_parse_string", |
|
125 |
"ONLY_BLANK_ARGUMENT", |
|
126 |
"The expression is only made of blanks"); |
|
127 |
return(sollya_lib_error()); |
|
128 |
|
|
129 |
} /* pobyso_parse_string */ |
|
130 |
|
|
131 | 46 |
/* @see pobyso.h#pobyso_parse_string*/ |
132 | 47 |
pobyso_func_exp_t |
133 | 48 |
pobyso_parse_string(const char* expression) |
... | ... | |
150 | 65 |
pobyso_error_message("pobyso_parse_string", |
151 | 66 |
"EMPTY_STRING_ARGUMENT", |
152 | 67 |
"The expression is an empty string"); |
153 |
return(sollya_lib_error());
|
|
68 |
return sollya_lib_error();
|
|
154 | 69 |
} |
155 | 70 |
/* Search from the last char of the expression until, whichever happens |
156 | 71 |
* first: |
... | ... | |
165 | 80 |
try to parse the string*/ |
166 | 81 |
{ |
167 | 82 |
expressionSa = sollya_lib_parse_string(expression); |
168 |
return(expressionSa);
|
|
83 |
return expressionSa;
|
|
169 | 84 |
} |
170 | 85 |
else |
171 | 86 |
{ |
... | ... | |
184 | 99 |
pobyso_error_message("pobyso_parse_string", |
185 | 100 |
"MEMORY_ALLOCATION_ERROR", |
186 | 101 |
"Could not allocate the expression string"); |
187 |
return(sollya_lib_error());
|
|
102 |
return sollya_lib_error();
|
|
188 | 103 |
} |
189 |
strncpy(expressionWithSemiCo, expression, i + 1);
|
|
104 |
strncpy(expressionWithSemiCo, expression, i+1);
|
|
190 | 105 |
expressionWithSemiCo[i + 1] = ';'; |
191 | 106 |
expressionWithSemiCo[i + 2] = '\0'; |
192 | 107 |
expressionSa = sollya_lib_parse_string(expressionWithSemiCo); |
193 | 108 |
free(expressionWithSemiCo); |
194 |
return(expressionSa);
|
|
109 |
return expressionSa;
|
|
195 | 110 |
} /* End character != ';' and from a blank. */ |
196 | 111 |
/* Create a new string for the expression, add the ";" and |
197 | 112 |
* and call sollya_lib_parse_string. */ |
... | ... | |
207 | 122 |
|
208 | 123 |
} /* pobyso_parse_string */ |
209 | 124 |
|
210 |
sollya_verbosity_t |
|
125 |
pobyso_func_exp_t |
|
126 |
pobyso_remez_canonical_monomials_base(pobyso_func_exp_t function, |
|
127 |
long int degree, |
|
128 |
pobyso_range_t interval, |
|
129 |
pobyso_func_exp_t weight, |
|
130 |
double quality, |
|
131 |
pobyso_range_t bounds) |
|
132 |
{ |
|
133 |
sollya_obj_t degreeSa = NULL; |
|
134 |
sollya_obj_t qualitySa = NULL; |
|
135 |
|
|
136 |
degreeSa = sollya_lib_constant_from_int(degree); |
|
137 |
qualitySa = sollya_lib_constant_from_double(quality); |
|
138 |
|
|
139 |
return NULL; |
|
140 |
} /* End pobyso_remez_canonical_monomials_base. */ |
|
141 |
|
|
142 |
int |
|
143 |
pobyso_set_canonical_on() |
|
144 |
{ |
|
145 |
pobyso_on_off_t currentCanonicalModeSo; |
|
146 |
int currentCanonicalMode; |
|
147 |
pobyso_on_off_t on; |
|
148 |
|
|
149 |
on = sollya_lib_on(); |
|
150 |
currentCanonicalModeSo = sollya_lib_get_canonical(); |
|
151 |
if (sollya_lib_is_on(currentCanonicalModeSo)) |
|
152 |
{ |
|
153 |
currentCanonicalMode = POBYSO_ON; |
|
154 |
} |
|
155 |
else |
|
156 |
{ |
|
157 |
currentCanonicalMode = POBYSO_OFF; |
|
158 |
} |
|
159 |
sollya_lib_set_canonical(on); |
|
160 |
sollya_lib_clear_obj(on); |
|
161 |
sollya_lib_clear_obj(currentCanonicalModeSo); |
|
162 |
return currentCanonicalMode; |
|
163 |
} /* End pobyso_set_canonical_on. */ |
|
164 |
|
|
165 |
pobyso_sollya_verbosity_t |
|
211 | 166 |
pobyso_set_verbosity_off() |
212 | 167 |
{ |
213 | 168 |
sollya_obj_t verbosityLevelZero; |
... | ... | |
220 | 175 |
return(currentVerbosityLevel); |
221 | 176 |
} /* End of pobyso_set_verbosity_off. */ |
222 | 177 |
|
223 |
sollya_verbosity_t |
|
224 |
pobyso_set_verbosity_to(sollya_obj_t newVerbosityLevel)
|
|
178 |
pobyso_sollya_verbosity_t
|
|
179 |
pobyso_set_verbosity_to(pobyso_sollya_verbosity_t newVerbosityLevel)
|
|
225 | 180 |
{ |
226 | 181 |
sollya_obj_t currentVerbosityLevel = NULL; |
227 | 182 |
if (newVerbosityLevel == NULL) |
228 | 183 |
{ |
229 | 184 |
pobyso_error_message("pobyso_set_verbosity_to", |
230 | 185 |
"NULL_POINTER_ARGUMENT", |
231 |
"The new verbosity level is a NULL pointer");
|
|
186 |
"The new verbosity level is a null pointer");
|
|
232 | 187 |
return(sollya_lib_error()); |
233 | 188 |
} |
234 | 189 |
currentVerbosityLevel = sollya_lib_get_verbosity(); |
... | ... | |
236 | 191 |
return(currentVerbosityLevel); |
237 | 192 |
} /* End of pobyso_set_verbosity_to. */ |
238 | 193 |
|
194 |
pobyso_sollya_verbosity_t |
|
195 |
pobyso_set_verbosity_to_int(int intVerbosityLevel) |
|
196 |
{ |
|
197 |
sollya_obj_t currentVerbosityLevel = NULL; |
|
198 |
sollya_obj_t newVerbosityLevel = NULL; |
|
199 |
if (intVerbosityLevel < 0) |
|
200 |
{ |
|
201 |
pobyso_error_message("pobyso_set_verbosity_to", |
|
202 |
"INVALID_VALUE", |
|
203 |
"The new verbosity level is a negative number"); |
|
204 |
return(sollya_lib_error()); |
|
205 |
} |
|
206 |
newVerbosityLevel = sollya_lib_constant_from_int(intVerbosityLevel); |
|
207 |
currentVerbosityLevel = sollya_lib_get_verbosity(); |
|
208 |
sollya_lib_set_verbosity(newVerbosityLevel); |
|
209 |
return(currentVerbosityLevel); |
|
210 |
} /* End of pobyso_set_verbosity_to_int. */ |
|
211 |
|
|
239 | 212 |
/* Attic from the sollya_lib < 4. */ |
240 | 213 |
#if 0 |
241 | 214 |
chain* |
Formats disponibles : Unified diff