示例#1
0
/**
 * osl_body_read function:
 * this function reads a body structure from a string complying to the
 * OpenScop textual format and returns a pointer to this body structure.
 * The input string should only contain the body this function
 * has to read (comments at the end of the line are accepted). The input
 * parameter is updated to the position in the input string this function
 * reach right after reading the strings structure.
 * \param[in,out] input The input string where to find a body structure.
 *                      Updated to the position after what has been read.
 * \return A pointer to the body structure that has been read.
 */
osl_body_p osl_body_sread(char ** input) {
  osl_body_p body = NULL;
  char * expression;
  int nb_iterators;

  if (input) {
    body = osl_body_malloc();
    
    // Read the number of iterators.
    nb_iterators = osl_util_read_int(NULL, input);
    
    // Read the iterator strings if any.
    if (nb_iterators > 0) {
      body->iterators = osl_strings_sread(input);
    }
    else {
      body->iterators = osl_strings_malloc();
      OSL_malloc(body->iterators->string, char **, sizeof(char *));
      body->iterators->string[0] = NULL;
    }

    // Read the body:
    expression = osl_util_read_line(NULL, input);

    // Insert the body.
    body->expression = osl_strings_encapsulate(expression);
  }

  return body;
}
示例#2
0
/**
 * osl_scatnames_sread function:
 * this function reads a scatnames structure from a string complying to the
 * OpenScop textual format and returns a pointer to this scatnames structure.
 * The input parameter is updated to the position in the input string this
 * function reach right after reading the scatnames structure. If there
 * is nothing to read, the function returns NULL.
 * \param[in,out] input The input string where to find a scatnames.
 *                      Updated to the position after what has been read.
 * \return A pointer to the scatnames structure that has been read.
 */
osl_scatnames_p osl_scatnames_sread(char ** input) {
  osl_scatnames_p scatnames = NULL;
  osl_strings_p names = NULL;

  if (*input == NULL) {
    OSL_debug("no scatnames optional tag");
    return NULL;
  }

  // Build the scatnames structure
  names = osl_strings_sread(input);
  if (names != NULL) {
    scatnames = osl_scatnames_malloc();
    scatnames->names = names;
  }

  return scatnames;
}
示例#3
0
/**
 * osl_body_read function:
 * this function reads a body structure from a string complying to the
 * OpenScop textual format and returns a pointer to this body structure.
 * The input string should only contain the body this function
 * has to read (comments at the end of the line are accepted). The input
 * parameter is updated to the position in the input string this function
 * reach right after reading the strings structure.
 * \param[in,out] input The input string where to find a body structure.
 *                      Updated to the position after what has been read.
 * \return A pointer to the body structure that has been read.
 */
osl_body_p osl_body_sread(char ** input) {
  osl_body_p body = NULL;
  char * expression;
  int nb_iterators;

  if (input) {
    body = osl_body_malloc();
    
    // Read the number of iterators.
    nb_iterators = osl_util_read_int(NULL, input);
    
    // Read the iterator strings if any.
    if (nb_iterators > 0)
      body->iterators = osl_strings_sread(input);

    // Read the body:
    // - Skip blank/commented lines and spaces before the body.
    osl_util_sskip_blank_and_comments(input);
      
    // - Remove the comments after the body.
    expression = *input;
    while (*input && **input != '#' && **input != '\n')
      (*input)++;
    
    if (*input && **input == '#') {
      **input = '\0';
      while (**input != '\n')
        (*input)++;
    }
    else {
      if (*input && **input == '\n') {
        **input = '\0';
        (*input)++;
      }
    }

    // - Copy the body.
    body->expression = osl_strings_encapsulate(strdup(expression));
  }

  return body;
}