Exemple #1
0
const char *disambiguate_pp(SourceFile *sourcefile) {
	char *p = ohcount_sourcefile_get_contents(sourcefile);

	/* prepare regular expressions */
	const char *error;
	int erroffset;

	/* try harder with optional spaces */
	pcre *keyword;
	keyword = pcre_compile("^\\s*(ensure|content|notify|require|source)\\s+=>",
			PCRE_MULTILINE, &error, &erroffset, NULL);

	if (pcre_exec(keyword, NULL, p, mystrnlen(p, 10000), 0, 0, NULL, 0) > -1)
		return LANG_PUPPET;

	/* check for standard puppet constructs */
	pcre *construct;
	construct = pcre_compile("^\\s*(define\\s+[\\w:-]+\\s*\\(|class\\s+[\\w:-]+(\\s+inherits\\s+[\\w:-]+)?\\s*{|node\\s+\\'?[\\w:\\.-]+\\'?\\s*{)",
			PCRE_MULTILINE, &error, &erroffset, NULL);

	if (pcre_exec(construct, NULL, p, mystrnlen(p, 10000), 0, 0, NULL, 0) > -1)
		return LANG_PUPPET;

	return LANG_PASCAL;
}
Exemple #2
0
void picolListAppend(picolList *l, char *str, char *buf, char sep) {
    if(l->size == 0)
        l->table[0] = buf;
    else
    {
        l->table[l->size] = l->table[l->size-1] + mystrnlen(l->table[l->size-1], MAXSTR);
        if(sep)
            l->table[l->size][0] = sep;
        l->table[l->size] += 1;
    }
    mysnprintf(l->table[l->size], mystrnlen(str, MAXSTR), "%s", str);
    l->size += 1;
}
Exemple #3
0
/**
 * returns 0 on success.
 */
static int load_parameter(mcmc * m, FILE * input, int i) {
	int col = 0;
	double start;
	double min;
	double max;
	double step;
	char * descr = (char*) mem_calloc(MAX_LINE_LENGTH, sizeof(char));
	IFDEBUGPARSER
	dump_i("parsing line", i);

	col = fscanf(input, "%lf\t%lf\t%lf\t%s\t%lf\n", &start, &min, &max, descr,
			&step);
	if (col != 5) {
		fprintf(stderr, "only %d fields matched.\n", col);
		return 1;
	}
	if (!(descr != NULL && mystrnlen(descr, MAX_LINE_LENGTH) > 0 && mystrnlen(
			descr, MAX_LINE_LENGTH) < MAX_LINE_LENGTH)) {
		fprintf(stderr, "description invalid: %s\n", descr);
		return 1;
	}
	IFDEBUGPARSER
	debug("setting values");
	gsl_vector_set(m->params, i, start);
	gsl_vector_set(m->params_best, i, start);
	if (min > max) {
		fprintf(stderr, "min(%f) < max(%f)\n", min, max);
		return 1;
	}
	if (start > max) {
		fprintf(stderr, "start(%f) > max(%f)\n", start, max);
		return 1;
	}
	if (start < min) {
		fprintf(stderr, "start(%f) < min(%f)\n", start, min);
		return 1;
	}
	if (step < 0) {
		step = (max - min) * 0.1;
		dump_d("using auto step size, 10% of parameter space", step);
	}
	gsl_vector_set(m->params_min, i, min);
	gsl_vector_set(m->params_max, i, max);
	m->params_descr[i] = descr;
	gsl_vector_set(m->params_step, i, step /* * (max - min) */);
	IFDEBUGPARSER
	debug("setting values done.");
	return 0;
}
Exemple #4
0
/* ----------------------------------------------------- parser functions */
void picolInitParser(picolParser *p, const char *text) {
    p->text  = p->p = (char*)text;
    p->len   = mystrnlen(text, MAXSTR);
    p->start = 0; p->end = 0; p->insidequote = 0;
    p->type  = PT_EOL;
    p->expand = 0;
}
Exemple #5
0
int     picolSetVar2(picolInterp *i, char *name, char *val,int glob) {
    picolVar       *v = picolGetVar(i,name);
    picolCallFrame *c = i->callframe, *localc = c;
    int             global = COLONED(name);
    if(glob||global) v = picolGetGlobalVar(i,name);
    if(!v) {           /* non-existing variable */
        if(glob || global) {
            if(global) name += 2;
            while(c->parent) c = c->parent;
        } else {
            v       = mymalloc(sizeof(*v));
            v->name = mystrdup(name);
            v->next = c->vars;
            c->vars = v;
            i->callframe = localc;
        }
    }
    if(v)
    {
        if(glob || global)
            mystrncpy(v->val, val, mystrnlen(v->val, MAXSTR));
        else
            v->val = mystrdup(val);
    }
    return PICOL_OK;
}
Exemple #6
0
picolVar *picolGetVar2(picolInterp *i, char *name, int glob) {
    picolVar *v = i->callframe->vars;
    int  global = COLONED(name);
    //char buf[MAXSTR], buf2[MAXSTR], *cp, *cp2;
    if(global || glob) {
        picolCallFrame *c = i->callframe;
        while(c->parent) c = c->parent;
        v = c->vars;
        if(global) name += 2;  /* skip the "::" */
    }
#if 0
    if((cp = mymemchr((uint8_t*)name,'(',mystrnlen(name,MAXSTR)))) { /* array element syntax? */
        picolArray* ap;
        int found = 0;
        strncpy(buf,name,cp-name);
        buf[cp-name] = '\0';
        for( ;v; v = v->next) if (EQ(v->name,buf)) {found = 1; break;}
        if(!found) return NULL;
        if(!((ap = picolIsPtr(v->val)))) return NULL;
        strcpy(buf2,cp+1); /* copy the key from after the opening paren*/
        if(!((cp = strchr(buf2,')')))) return NULL;
        *cp = '\0';       /* overwrite closing paren */
        v = picolArrGet1(ap,buf2);
        if(!v) {
            if(!((cp2 = getenv(buf2)))) return NULL;
            strcpy(buf,"::env("); strcat(buf,buf2); strcat(buf,")");
            return picolArrSet1(i, buf, cp2);
        }
        return v;
    }
#endif
    for( ;v; v = v->next) {if (EQ(v->name,name)) return v;}
    return NULL;
}
Exemple #7
0
const char *disambiguate_pp(SourceFile *sourcefile) {
	char *p = ohcount_sourcefile_get_contents(sourcefile);
  char *eof = p + ohcount_sourcefile_get_contents_size(sourcefile);

	/* prepare regular expressions */
	pcre *re;
	const char *error;
	int erroffset;
	re = pcre_compile("(define\\s+\\w+\\s*\\(|class \\s+\\w+\\s*{)", 0, &error, &erroffset, NULL);

	for (; p < eof; p++) {
		if (strncmp(p, "$include", 8) == 0 ||
				strncmp(p, "$INCLUDE", 8) == 0 ||
				strncmp(p, "end.", 4) == 0)
			return LANG_PASCAL;
		if (strncmp(p, "enable =>", 9) == 0 ||
				strncmp(p, "ensure =>", 9) == 0 ||
				strncmp(p, "content =>", 10) == 0 ||
				strncmp(p, "source =>", 9) == 0 ||
				strncmp(p, "include ", 8) == 0)
			return LANG_PUPPET;

		/* regexp for checking for define and class declarations */

		int rc;
		int ovector[30];
		rc = pcre_exec(re, NULL, p, mystrnlen(p, 100), 0, 0, ovector, 30);
		if(rc > 0) {
			return LANG_PUPPET;
		}

	}
	return LANG_PASCAL;
}
Exemple #8
0
char* mystrdup(char *str)
{
    size_t len = mystrnlen(str, MAXSTR);
    char *ptr = mymalloc(len + 1);
    if(ptr)
    {
        mystrncpy(ptr, str, MAXSTR);
        return ptr;
    }
    return 0;
}
Exemple #9
0
static int		get_request(void *req, char *output, t_conf *conf,
				    struct sockaddr_in *sa)
{
  char			buffer[MAX_HOST_NAME_ENCODED + 1];
  int			len;
  char			*data;


  data = JUMP_DNS_HDR(req);
  if (mystrnlen(data, MAX_HOST_NAME_ENCODED + 1) > MAX_HOST_NAME_ENCODED)
    return (-1);
  if (dns_decode((char *)req, data, buffer, conf, sa) == -1)
    return (-1);
  len = base64_decode((unsigned char *)output, buffer);
  output[len] = 0;
  return (len);
}
Exemple #10
0
static uint16_t parse_eth_addr(char *in, uint8_t *out, char delim, uint8_t len, uint16_t base)
{
    uint8_t j, k, ii;
    char *a = in;
    for(j = 0, k = 0, ii = 0; j <= mystrnlen(in, 20); j++)
    {
        if((a[j] == 0) || a[j] == delim)
            out[ii++] = (base == 10) ? atoi(&a[k]) : htoi(&a[k]);
        if(a[j] == 0)
            break;
        if(a[j] == delim)
            k = j + 1;
    }
    if(len != ii)
        return 0;
    return len;
}
Exemple #11
0
const char *disambiguate_pl(SourceFile *sourcefile) {
	char *contents = ohcount_sourcefile_get_contents(sourcefile);
  if (!contents)
    return NULL;

  // Check for a perl shebang on first line of file
	const char *error;
	int erroffset;
	pcre *re = pcre_compile("#![^\\n]*perl", PCRE_CASELESS, &error, &erroffset, NULL);
  if (pcre_exec(re, NULL, contents, mystrnlen(contents, 100), 0, PCRE_ANCHORED, NULL, 0) > -1)
    return LANG_PERL;

  // Check for prolog :- rules
  if (strstr(contents, ":- ") || strstr(contents, ":-\n"))
    return LANG_PROLOG;

  // Perl by default.
  return LANG_PERL;
}