예제 #1
0
파일: node.hpp 프로젝트: aghandoura/patl
 /// for debug only
 const char *visualize(const node_type *id0) const
 {
     static char buf[256];
     sprintf(buf, "%d skip: %d pt: %d ptId: %d lnk0: %d tag0: %d lnk1: %d tag1: %d\n",
         this - id0,
         get_skip(),
         get_parent() - id0,
         get_parent_id(),
         get_xlink(0) - id0,
         get_xtag(0),
         get_xlink(1) - id0,
         get_xtag(1));
     return buf;
 }
예제 #2
0
파일: node.hpp 프로젝트: aghandoura/patl
 /// for debug only
 bool integrity() const
 {
     const word_t
         skip = get_skip(),
         tag0 = get_xtag(0),
         tag1 = get_xtag(1);
     const node_type
         *p0 = get_xlink(0),
         *p1 = get_xlink(1);
     return
         skip == ~word_t(0) && p1 == 0 && get_parent() == 0 && get_parent_id() == 0 ||
         !tag0 && p0->get_parent() == this && !p0->get_parent_id() && skip < p0->get_skip() ||
         !tag1 && p1->get_parent() == this && p1->get_parent_id() && skip < p1->get_skip() ||
         tag0 && tag1;
 }
예제 #3
0
파일: odftread.c 프로젝트: andreiw/polaris
int
odftread()
{
    if (Already_read)
	return(0);
    Already_read = TRUE;
    if (!Vflag) {
	/*
	 * table is hard-coded for "FACE" FMLI 
	 */
	register int i;

	for (i = 0; i < MAXODFT && FMLI_detab[i].objtype[0] != '\0';i++)
	    Detab[i] = FMLI_detab[i];
	Detab[i].objtype[0] = '\0';
    }
    else {
	register int i, moffset;
	char *p, *q, buf[PATHSIZ];
	char *b;
	char	*tmpstr;
	FILE *fp;
	int offset = 0, magic;
	long magic_offset[MAXMAGIC+1];
	char magic_bytes[MAXMAGIC];
	char	*get_skip();
	char	*tab_parse();
	long	tab_long();

	p = expand("$OASYS/info/OH/externals/detect.tab");
	fp = fopen(p, "r");
	free(p);
	if (fp == NULL)
	    fatal(MISSING, "detect.tab");
	tmpstr = NULL;
	while (get_skip(buf, PATHSIZ, fp) != NULL) {
	    /* flush optional line number */
	    for (b = buf; *b == '\t' || isdigit(*b); b++)
		;
	    b = tab_parse(&tmpstr, b);
	    strncpy(Detab[offset].objtype, tmpstr, OTYPESIZ);
	    if (b) {
		char	*unbackslash();

		b = tab_parse(&Detab[offset].defodi, b);
		p = unbackslash(Detab[offset].defodi);
		if (p[0] == '"')
		    memshift(p, p + 1, strlen(p));
		p += strlen(p) - 1;
		if (p[0] == '"')
		    p[0] = '\0';
	    }
	    Detab[offset].defmask = tab_long(&b, 16);
	    if (b && *b)
		Detab[offset].func_type = tab_long(&b, 16);
	    else {
#ifdef _DEBUG
		_debug(stderr, "BAD ODFT '%s'\n", Detab[offset].objtype);
#endif
		error(MUNGED, "heuristics table");
		continue;
	    }
	    switch (Detab[offset].func_type) {
	    case F_INT:
		Detab[offset].intern_func = tab_long(&b, 0);
		break;
	    case F_SHELL:
	    case F_EXEC:
		b = tab_parse(&tmpstr, b);
		Detab[offset].extern_func = tmpstr;
		tmpstr = NULL;
		break;
	    case F_PARTS:
	    case F_DPARTS:
		break;
	    case F_MAGIC:
		p = b;
		magic = 0;
		while (*p && magic < MAXMAGIC) {
		    moffset = strtol(p, &q, 0);
		    if (p == q)	/* strtol failed */
			break;
		    p = q;
		    while (*q && isspace(*q))
			q++;
		    if (*q == '"') {
			q++;
			while (*q && *q != '"' && magic < MAXMAGIC-1) {
			    magic_bytes[magic] = *q;
			    magic_offset[magic] = moffset++;
			    magic++;
			    q++;
			}
			if (*q)
			    q++;
		    } else {
			magic_offset[magic] = moffset;
			magic_bytes[magic] = (char) strtol(p,&q,0);
			if (p == q) {
			    p = '\0';
			    break;
			} else
			    p = q;
			magic++;
		    }
		}
		if (magic == 0) {
#ifdef _DEBUG
		    _debug(stderr, "BAD ODFT '%s' MAGIC: %s\n", Detab[offset].objtype, q);
#endif
		    error(MUNGED, "heuristics magic number");
		    continue;
		}
		magic_offset[magic] = -1L;

		/* for efficiency, the most common magic number
		 * case, 0, 1, -1, is coded up.
		 */

		if (magic == 2 && magic_offset[0] == 0L &&
		    magic_offset[1] == 1L) {
		    Detab[offset].magic_offset = &(Normal_mag_offset[0]);
		}
		else {
		    Detab[offset].magic_offset = (long *)calloc(magic+1, sizeof(long));
		    for (i = 0; i < magic+1; i++)
			Detab[offset].magic_offset[i] = magic_offset[i];
		}
		Detab[offset].magic_bytes = calloc(magic, sizeof(char));
		for (i = 0; i < magic; i++)
		    Detab[offset].magic_bytes[i] = magic_bytes[i];
		break;
	    default:
#ifdef _DEBUG
		_debug(stderr, "ODFT '%s' BAD FUNCTION: %d\n", Detab[offset].objtype, Detab[offset].func_type);
#endif
		error(MUNGED, "heuristics table function");
		continue;
	    }
	    offset++;
	}
	fclose(fp);
	Detab[offset].objtype[0] = '\0';
	if (tmpstr)
	    free(tmpstr);
    }
    return(0);
}