Esempio n. 1
0
array *
string_wildcard_expand(char *str) {
  glob_t g;
  int i, j;
  int flags, flags_init;
  int retval;
  string *s, *p;
  array *t;

  s = string_new(str);
  t = string_tokenize_with_quotes(s, NULL, NULL);
  if(array_length(t) == 0) {
    fprintf(stderr, "odd number of quotes found\n");
    return NULL;
  }
  flags_init = GLOB_NOSORT | GLOB_BRACE | GLOB_TILDE;

  for(j = 0; j < array_length(t); j++) {
    flags = (j == 0) ? flags_init : (flags_init | GLOB_APPEND);

    p = array_element(t,j);

#ifdef __UNIT_TESTING_DEBUG__
    fprintf(stderr, "path:    %s\n", string_string(p));
#endif
    
    if(string_length(p) > 0) {
      retval = glob(string_string(array_element(t,j)), flags, 
                    string_wildcard_expand_error, &g);
      switch(retval) {
      case GLOB_NOSPACE: 
        fprintf(stderr, "Error allocating memory for file search\n");
        break;
      case GLOB_ABORTED: 
        fprintf(stderr, "Error was encountered for \"%s\"\n",
                string_string(p));
        break;
      case GLOB_NOMATCH: 
        fprintf(stderr, "No matches were found for \"%s\"\n", 
                string_string(p));
        break;
      }
      
#ifdef __UNIT_TESTING_DEBUG__
      fprintf(stderr, "retval:  %d\n", retval);
      fprintf(stderr, "path:    %d\n", g.gl_pathc);
      fprintf(stderr, "matches: %d\n", g.gl_matchc);
#endif /* __UNIT_TESTING_DEBUG_ _ */

   }
  }
  for(i = 0; i < g.gl_pathc; i++) {
    fprintf(stderr, "string[%.3d/%.3d]: <%s>\n", 
            i, strlen(g.gl_pathv[i]), g.gl_pathv[i]);
  }
  globfree(&g);
  
  return NULL;
}
Esempio n. 2
0
void 
array_dump_elements(array *a, void (func)(void *d)) {
  int i;
  for(i = 0; i < a->n; i++) {
    fprintf(stderr, "\telement: %d %p %p %p alloc: %d n: %d\n\t", 
    	    i, a, array_element(a,i), &a->data[i], a->alloc, a->n);
    (func)(array_element(a,i));
  }
}
Esempio n. 3
0
void
array_dump_element(array *a, int i, void (func)(void *d)) {
  if(i < 0) {
    i = a->n - 1;
  }
  if(i >= a->n || i < 0) {
    fprintf(stderr, "\telement: %d %p %p alloc: %d n: %d\n", 
            i, NULL, NULL, a->alloc, a->n);
  }
  fprintf(stderr, "\telement: %d %p %p alloc: %d n: %d\n\t", 
          i, a, array_element(a,i), a->alloc, a->n);
  (func)(array_element(a,i));
}
Esempio n. 4
0
static void
combine(int num, int ai)
{
    int i = 0;

    if (num == array_element(brr))
    {
        show();
        return;
    }

    for (; ai < array_element(arr); ai++)
    {
        brr[num] = ai;
        combine(num+1, ai+1);
    }
}
Esempio n. 5
0
void *
array_shift(array *a) {
  void *d = NULL;
  d = array_element(a, 0);
  a = array_slide_up(a, -1);
  a->n = a->n - 1;
  return d;
}
Esempio n. 6
0
void array_add(array_t *a, void *val){
	// Expand
	if(a->size == a->capacity){
		a->capacity = a->capacity * 2;
		a->data = (void **)realloc(a->data, sizeof(void *) * a->capacity);
	}

	*array_element(a, a->size++) = val;
}
Esempio n. 7
0
static void
show(void)
{
    int i = 0;

    for (i = 0; i < array_element(brr); i++)
    {
        printf("%d  ", arr[brr[i]]);
    }
    printf("\n");
}