Example #1
0
/**
 * Try to get "desired_ntokens" number of tokens from the given
 * filestream f.  Store them (destructively) in the given list
 * "tokens" of dynamically created extstring_t objects.  Store in
 * "gotten_ntokens" the actual number of tokens that we got. 
 */
int
bebop_get_tokens (list_t* tokens, 
		 int* gotten_ntokens, 
		 FILE* f,
		 const int desired_ntokens,
		 const char delimiters[],
		 const int ndelimiters)
{
  list_t current = *tokens;
  list_t outlist = *tokens;

  if (desired_ntokens < 0)
    {
      bebop_error ("bebop_get_tokens", 
		  "desired_ntokens = %d < 0", 
		  desired_ntokens);
      return -1;
    }
  for (*gotten_ntokens = 0; 
       *gotten_ntokens < desired_ntokens;
       (*gotten_ntokens)++)
    {
      extstring_t* token = NULL;
      int result = 0;

      if (list_empty_p (current))
	  /* We're out of nodes to reuse, so we have to create a new
	     extstring_t */
	token = extstring_create (0);
      else
	token = list_car (current);

      /* Try to get the next token */
      result = bebop_next_token (token, f, delimiters, ndelimiters);
      if (result != 0)
	{
	  extstring_destroy (token);
	  break;
	}
      else
	{
	  if (list_empty_p (current))
	    outlist = list_append_node (outlist, token);
	  else
	    {
	      list_set_car (current, token);
	      current = list_cdr (current);
	    }
	}
    }
  return 0;
}
Example #2
0
PRIVATE int
enumMax(Type t)
{
    list enum_field = type_description(t)->structuredDes.enumeration;
    int xval = ((EnumField)list_ref(enum_field, 0))->id;
    list l = list_cdr(enum_field);
    cardinal i;
    for (i = 0; i < list_size(l); i++) 
        if (xval < ((EnumField)list_ref(l, i))->id)
            xval = ((EnumField)list_ref(l, i))->id;

    return xval;
}