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');
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)
160 while (**str && !isspace(**str) && **str !=
'\n' && **str !=
'#')
161 s[i++] = *((*str)++);
163 if (sscanf(s,
"%d", &res) != 1)
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");
193 if (sscanf(start,
" %s", res) != 1)
202 while (**str && !isspace(**str) && **str !=
'\n' && **str !=
'#')
203 s[i++] = *((*str)++);
205 if (sscanf(s,
"%s", res) != 1)
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");
238 while (*start && *start !=
'\n' && *start !=
'#' && i <
OSL_MAX_STRING)
244 while (**str && **str !=
'\n' && **str !=
'#' && i <
OSL_MAX_STRING)
245 res[i++] = *((*str)++);
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");
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");
337 size_t 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));
347 lenstr = str != NULL ? strlen(*str) : 0;
348 while (((str != NULL) && (nb_chars != lenstr)) ||
349 ((file != NULL) && (!feof(file)))) {
350 res[nb_chars++] = (str != NULL) ? *((*str)++) : (
char)fgetc(file);
352 if ((nb_chars >= lenflag) &&
353 (!strncmp(&res[nb_chars - lenflag], flag, lenflag))) {
358 if (nb_chars >= high_water_mark) {
359 high_water_mark += high_water_mark;
360 OSL_realloc(res,
char *, high_water_mark *
sizeof(
char));
365 OSL_debug(
"flag was not found, end of input reached");
371 OSL_realloc(res,
char *, (nb_chars - strlen(flag) + 1) *
sizeof(
char));
372 res[nb_chars - strlen(flag)] =
'\0';
392 char tag[strlen(name) + 3];
394 sprintf(tag,
"<%s>", name);
413 char endtag[strlen(name) + 4];
415 sprintf(endtag,
"</%s>", name);
433 char tag[strlen(name) + 3];
434 char endtag[strlen(name) + 4];
439 sprintf(tag,
"<%s>", name);
440 sprintf(endtag,
"</%s>", name);
444 lentag = strlen(tag);
445 for (; start && *start && strncmp(start, tag, lentag); ++start)
453 lentag = strlen(endtag);
454 for (size = 0; *stop && strncmp(stop, endtag, lentag); ++stop, ++size)
460 OSL_malloc(res,
char *, (size + 1) *
sizeof(
char));
463 for (++start, i = 0; start != stop; ++start, ++i)
484 while ((strlen(*dst) + strlen(src)) >= *hwm) {
505 OSL_malloc(dup,
char *, (strlen(str) + 1) *
sizeof(
char));
506 if (dup) { strcpy(dup, str); }
519 char * precision_env;
521 #ifdef OSL_GMP_IS_HERE 526 if (precision_env != NULL) {
532 #ifndef OSL_GMP_IS_HERE 533 OSL_warning(
"$OSL_PRECISION says GMP but osl not compiled with " 534 "GMP support, switching to double precision");
541 OSL_warning(
"bad OSL_PRECISION environment value, see osl's manual");
558 fprintf(file,
"# %s provided\n", title);
559 fprintf(file,
"1\n");
562 fprintf(file,
"# %s not provided\n", title);
563 fprintf(file,
"0\n\n");
580 size_t identifier_len = strlen(identifier);
581 size_t expression_len = strlen(expression);
584 if (identifier_len + index > expression_len)
589 (((expression[index - 1] >=
'A') && (expression[index - 1] <=
'Z')) ||
590 ((expression[index - 1] >=
'a') && (expression[index - 1] <=
'z')) ||
591 ((expression[index - 1] >=
'0') && (expression[index - 1] <=
'9')) ||
592 (expression[index - 1] ==
'_')))
596 if ((identifier_len + index < expression_len) &&
597 (((expression[identifier_len + index] >=
'A') &&
598 (expression[identifier_len + index] <=
'Z')) ||
599 ((expression[identifier_len + index] >=
'a') &&
600 (expression[identifier_len + index] <=
'z')) ||
601 ((expression[identifier_len + index] >=
'0') &&
602 (expression[identifier_len + index] <=
'9')) ||
603 ( expression[identifier_len + index] ==
'_')))
607 if (strncmp(expression + index, identifier, identifier_len))
632 size_t expression_len = strlen(expression);
633 size_t identifier_len = strlen(identifier);
637 while (look < index) {
638 if (isspace(expression[look]))
644 if ((look < index) &&
645 (expression[look] !=
'[') &&
646 (expression[look] !=
'(') &&
647 (expression[look] !=
'+') &&
648 (expression[look] !=
'=') &&
649 (expression[look] !=
','))
653 look = index + identifier_len;
654 while (look < expression_len) {
655 if (isspace(expression[look]))
661 if ((look < expression_len) &&
662 (expression[look] !=
']') &&
663 (expression[look] !=
')') &&
664 (expression[look] !=
'+') &&
665 (expression[look] !=
',') &&
666 (expression[look] !=
';'))
689 char ** identifiers) {
696 OSL_malloc(
string,
char *, high_water_mark *
sizeof(
char));
700 while (index < strlen(expression)) {
703 while (identifiers[j] != NULL) {
706 sprintf(buffer,
"@%d@", j);
708 sprintf(buffer,
"(@%d@)", j);
710 index += strlen(identifiers[j]);
717 sprintf(buffer,
"%c", expression[index]);
#define OSL_PRECISION_ENV_DP
static int osl_util_identifier_is_here(char *expression, char *identifier, size_t index)
int osl_util_read_int(FILE *file, char **str)
static int osl_util_lazy_isolated_identifier(char *expression, char *identifier, size_t index)
char * osl_util_tag_content(char *str, char *name)
void osl_util_safe_strcat(char **dst, char *src, size_t *hwm)
#define OSL_PRECISION_ENV_MP
#define OSL_PRECISION_ENV_SP
char * osl_util_read_string(FILE *file, char **str)
#define OSL_realloc(ptr, type, size)
char * osl_util_strdup(char const *str)
String duplicate.
char * osl_util_read_tag(FILE *file, char **str)
char * osl_util_read_uptotag(FILE *file, char **str, char *name)
void osl_util_sskip_blank_and_comments(char **str)
#define OSL_PRECISION_ENV
char * osl_util_read_uptoendtag(FILE *file, char **str, char *name)
int osl_util_get_precision(void)
void osl_util_print_provided(FILE *file, int provided, char *title)
char * osl_util_read_uptoflag(FILE *file, char **str, char *flag)
char * osl_util_skip_blank_and_comments(FILE *file, char *str)
char * osl_util_identifier_substitution(char *expression, char **identifiers)
char * osl_util_read_line(FILE *file, char **str)
#define OSL_malloc(ptr, type, size)