/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include <stdarg.h>
#include <libgen.h>

char *regcmp(const char *string1, ...) {

  va_list ap;
  int vacount;
  void *fptr;
  char *retval;

  char *string2, *string3, *string4;

  fptr = dlsym(_ChLibgen_handle, "regcmp_chdl");
  if(fptr == NULL) {
    fprintf(_stderr, "Error: %s(): dlsym(): %s\n", __func__,  dlerror());
    return NULL;
  }

  va_start(ap, string1);
  vacount = va_count(ap);

  if(vacount == 1) {
    string2 = va_arg(ap, char *);
    dlrunfun(fptr, &retval, regcmp, string1, 1, string2);
  }

  else if(vacount == 2) {
    string2 = va_arg(ap, char *);
    string3 = va_arg(ap, char *);
    dlrunfun(fptr, &retval, regcmp, string1, 2, string2, string3);
  }

  else if(vacount == 3) {
    string2 = va_arg(ap, char *);
    string3 = va_arg(ap, char *);
    string4 = va_arg(ap, char *);
    dlrunfun(fptr, &retval, regcmp, string1, 3, string2, string3, string4);
  }

  else {
    fprintf(_stderr, "Error: wrong arguments in regcmp()\n");
    return NULL;
  }

  va_end(ap);
  return retval;
}
