95 start = fgets(str, OSL_MAX_STRING, file);
96 while ((start != NULL) && isspace(*start) && (*start !=
'\n'))
99 while (start != NULL && (*start ==
'#' || *start ==
'\n'));
116 while (*str && **str && isspace(**str))
120 if (*str && **str && **str ==
'#') {
121 while (**str && **str !=
'\n') {
126 while (*str && **str && **str ==
'\n');
141 char s[OSL_MAX_STRING], * start;
145 if ((file != NULL && str != NULL) || (file == NULL && str == NULL))
146 OSL_error(
"one and only one of the two parameters can be non-NULL");
151 if (sscanf(start,
" %d", &res) != 1)
152 OSL_error(
"an int was expected");
160 while (**str && !isspace(**str) && **str !=
'\n' && **str !=
'#')
161 s[i++] = *((*str)++);
163 if (sscanf(s,
"%d", &res) != 1)
164 OSL_error(
"an int was expected");
182 char s[OSL_MAX_STRING], * start;
186 if ((file != NULL && str != NULL) || (file == NULL && str == NULL))
187 OSL_error(
"one and only one of the two parameters can be non-NULL");
189 OSL_malloc(res,
char *, OSL_MAX_STRING *
sizeof(
char));
193 if (sscanf(start,
" %s", res) != 1)
194 OSL_error(
"a string was expected");
202 while (**str && !isspace(**str) && **str !=
'\n' && **str !=
'#')
203 s[i++] = *((*str)++);
205 if (sscanf(s,
"%s", res) != 1)
206 OSL_error(
"a string was expected");
209 OSL_realloc(res,
char *, strlen(res) + 1);
227 char s[OSL_MAX_STRING], * start;
231 if ((file != NULL && str != NULL) || (file == NULL && str == NULL))
232 OSL_error(
"one and only one of the two parameters can be non-NULL");
234 OSL_malloc(res,
char *, OSL_MAX_STRING *
sizeof(
char));
238 while (*start && *start !=
'\n' && *start !=
'#' && i < OSL_MAX_STRING)
244 while (**str && **str !=
'\n' && **str !=
'#' && i < OSL_MAX_STRING)
245 res[i++] = *((*str)++);
249 OSL_realloc(res,
char *, strlen(res) + 1);
269 char s[OSL_MAX_STRING], * start;
273 if ((file != NULL && str != NULL) || (file == NULL && str == NULL))
274 OSL_error(
"one and only one of the two parameters can be non-NULL");
286 if (((file != NULL) && (feof(file))) ||
287 ((str != NULL) && (**str ==
'\0')))
292 OSL_error(
"a \"<\" to start a tag was expected");
296 OSL_malloc(res,
char *, (OSL_MAX_STRING + 1) *
sizeof(
char));
297 res[OSL_MAX_STRING] =
'\0';
299 while (**str && **str !=
'>') {
300 if (((**str >=
'A') && (**str <=
'Z')) ||
301 ((**str >=
'a') && (**str <=
'z')) ||
302 ((**str ==
'/') && (i == 0)) ||
304 res[i++] = *((*str)++);
308 OSL_error(
"illegal character in the tag name");
314 OSL_error(
"a \">\" to end a tag was expected");
335 int high_water_mark = OSL_MAX_STRING;
337 int lenflag = strlen(flag), lenstr;
341 if ((file != NULL && str != NULL) || (file == NULL && str == NULL))
342 OSL_error(
"one and only one of the two parameters can be non-NULL");
344 OSL_malloc(res,
char *, high_water_mark *
sizeof(
char));
348 lenstr = strlen(*str);
349 while (((str != NULL) && (nb_chars != lenstr)) ||
350 ((file != NULL) && (!feof(file)))) {
351 res[nb_chars++] = (str != NULL) ? *((*str)++) : fgetc(file);
353 if ((nb_chars >= lenflag) &&
354 (!strncmp(&res[nb_chars - lenflag], flag, lenflag))) {
359 if (nb_chars >= high_water_mark) {
360 high_water_mark += high_water_mark;
361 OSL_realloc(res,
char *, high_water_mark *
sizeof(
char));
366 OSL_debug(
"flag was not found, end of input reached");
372 OSL_realloc(res,
char *, (nb_chars - strlen(flag) + 1) *
sizeof(
char));
373 res[nb_chars - strlen(flag)] =
'\0';
393 char tag[strlen(name) + 3];
395 sprintf(tag,
"<%s>", name);
414 char endtag[strlen(name) + 4];
416 sprintf(endtag,
"</%s>", name);
434 char tag[strlen(name) + 3];
435 char endtag[strlen(name) + 4];
440 sprintf(tag,
"<%s>", name);
441 sprintf(endtag,
"</%s>", name);
445 lentag = strlen(tag);
446 for (; start && *start && strncmp(start, tag, lentag); ++start)
454 lentag = strlen(endtag);
455 for (size = 0; *stop && strncmp(stop, endtag, lentag); ++stop, ++size)
461 OSL_malloc(res,
char *, (size + 1) *
sizeof(
char));
464 for (++start, i = 0; start != stop; ++start, ++i)
485 while ((
int)(strlen(*dst) + strlen(src)) >= *hwm) {
486 *hwm += OSL_MAX_STRING;
487 OSL_realloc(*dst,
char *, *hwm *
sizeof(
char));
506 OSL_malloc(dup,
char *, (strlen(str) + 1) *
sizeof(
char));
507 if (dup) { strcpy(dup, str); }
519 int precision = OSL_PRECISION_DP;
520 char * precision_env;
522 #ifdef OSL_GMP_IS_HERE
523 precision = OSL_PRECISION_MP;
526 precision_env = getenv(OSL_PRECISION_ENV);
527 if (precision_env != NULL) {
528 if (!strcmp(precision_env, OSL_PRECISION_ENV_SP))
529 precision = OSL_PRECISION_SP;
530 else if (!strcmp(precision_env, OSL_PRECISION_ENV_DP))
531 precision = OSL_PRECISION_DP;
532 else if (!strcmp(precision_env, OSL_PRECISION_ENV_MP)) {
533 #ifndef OSL_GMP_IS_HERE
534 OSL_warning(
"$OSL_PRECISION says GMP but osl not compiled with "
535 "GMP support, switching to double precision");
536 precision = OSL_PRECISION_DP;
538 precision = OSL_PRECISION_MP;
542 OSL_warning(
"bad OSL_PRECISION environment value, see osl's manual");
559 fprintf(file,
"# %s provided\n", title);
560 fprintf(file,
"1\n");
563 fprintf(file,
"# %s not provided\n", title);
564 fprintf(file,
"0\n\n");
582 if (strlen(identifier) + index > strlen(expression))
587 (((expression[index - 1] >=
'A') && (expression[index - 1] <=
'Z')) ||
588 ((expression[index - 1] >=
'a') && (expression[index - 1] <=
'z')) ||
589 ((expression[index - 1] >=
'0') && (expression[index - 1] <=
'9'))))
593 if ((strlen(identifier) + index < strlen(expression)) &&
594 (((expression[strlen(identifier) + index] >=
'A') &&
595 (expression[strlen(identifier) + index] <=
'Z')) ||
596 ((expression[strlen(identifier) + index] >=
'a') &&
597 (expression[strlen(identifier) + index] <=
'z')) ||
598 ((expression[strlen(identifier) + index] >=
'0') &&
599 (expression[strlen(identifier) + index] <=
'9'))))
603 if (strncmp(expression + index, identifier, strlen(identifier)))
632 if (isspace(expression[look]))
639 (expression[look] !=
'[') &&
640 (expression[look] !=
'(') &&
641 (expression[look] !=
'+') &&
642 (expression[look] !=
'=') &&
643 (expression[look] !=
','))
647 look = index + strlen(identifier);
648 while (look < (
int)strlen(expression)) {
649 if (isspace(expression[look]))
655 if ((look < (
int)strlen(expression)) &&
656 (expression[look] !=
']') &&
657 (expression[look] !=
')') &&
658 (expression[look] !=
'+') &&
659 (expression[look] !=
',') &&
660 (expression[look] !=
';'))
683 char ** identifiers) {
686 int high_water_mark = OSL_MAX_STRING;
687 char buffer[OSL_MAX_STRING];
690 OSL_malloc(
string,
char *, high_water_mark *
sizeof(
char));
694 while (index < strlen(expression)) {
697 while (identifiers[j] != NULL) {
700 sprintf(buffer,
"@%d@", j);
702 sprintf(buffer,
"(@%d@)", j);
704 index += strlen(identifiers[j]);
711 sprintf(buffer,
"%c", expression[index]);
char * osl_util_read_uptoendtag(FILE *file, char **str, char *name)
char * osl_util_identifier_substitution(char *expression, char **identifiers)
static int osl_util_lazy_isolated_identifier(char *expression, char *identifier, int index)
char * osl_util_strdup(char const *str)
String duplicate.
void osl_util_safe_strcat(char **dst, char *src, int *hwm)
char * osl_util_read_uptoflag(FILE *file, char **str, char *flag)
int osl_util_get_precision()
void osl_util_sskip_blank_and_comments(char **str)
static int osl_util_identifier_is_here(char *expression, char *identifier, int index)
int osl_util_read_int(FILE *file, char **str)
char * osl_util_skip_blank_and_comments(FILE *file, char *str)
char * osl_util_read_string(FILE *file, char **str)
void osl_util_print_provided(FILE *file, int provided, char *title)
char * osl_util_read_tag(FILE *file, char **str)
char * osl_util_read_line(FILE *file, char **str)
char * osl_util_read_uptotag(FILE *file, char **str, char *name)
char * osl_util_tag_content(char *str, char *name)