Exemple #1
0
main(void)
{	
	puts("/* WARNING: This is an autogenerated file */\n"
		"#include <algnbyte.h>\n"
		"typedef struct {");
	while(fgets(buf, sizeof(buf), stdin))
		switch(state) {
		case NEED_START:
			if(isline("/* START OF FLAGS */")) {
				state = PARSE_SHARED;
			}
			break;
		case PARSE_SHARED:
			if(isline("/* END OF SHARED FLAGS */")) {
				fputs(buf, stdout);
				state = PARSE_ANY;
				break;
			}
			if(*buf != '/')
				fputs(buf, stdout);
			/**FALL THROUGH**/
		case PARSE_ANY:
			if(isline("/* END OF FLAGS */"))
				goto okRet;
			if(*buf != '/') {
				unsigned char *p, *q;

				if((p = (unsigned char*)strchr(buf, ';')) == 0) {
					fprintf(stderr, "Syntax error: %s", buf);
					return 40;
				}
				*p = 0;
				while(--p >= (unsigned char*)buf && (isalnum(*p) || *p == '_'));
				if(memcmp(q = p + 1, "f_", 2) == 0)
					q += 2;
				printf("#define gflag_%s (ctxtFlagsP->%s)\n", q, p + 1);
				if(state == PARSE_SHARED)
					printf("#define lflag_%s (ctxtSharedFlags.%s)\n", q, p + 1);
			}
			break;
	}

okRet:
	puts("} ctxt_shared_flags_t;\n"
		"#include <algndflt.h>");

	return 0;
}
Exemple #2
0
static int check_standard(const char *judge, size_t jlen, const char *process, size_t plen) {
	size_t j = 0, p = 0;
	int nj, np;

	while (j < jlen && iswhite(judge[j])) ++j;
	while (p < plen && iswhite(process[p])) ++p;
	for (;;) {
		nj = np = 0;
		while (j < jlen && ((nj |= isline(judge[j])), iswhite(judge[j]))) ++j;
		while (p < plen && ((np |= isline(process[p])), iswhite(process[p]))) ++p;
		if (j == jlen || p == plen) return j == jlen && p == plen;
		if (nj != np) return 0;

		while (j < jlen && !iswhite(judge[j])) {
			if (p >= plen) return 0;
			if (judge[j++] != process[p++]) return 0;
		}
	}
}
Exemple #3
0
/* Increment *pos to the next non-whitespace character, and returns
 * 2 if a new line was seen, 1 if only spaces were seen, and 0 if no whitespace was seen */
static inline int skip_spaces(const char *str, int *pos, int length) {
	int saw_line = 0, saw_space = 0;
	while (*pos < length) {
		saw_line |= isline(str[*pos]);
		if (!iswhite(str[*pos])) {
			break;
		}
		++*pos;
		saw_space = 1;
	}
	return saw_line ? 2 : saw_space;
}
Exemple #4
0
char skipLineSpaceComment(FILE *f, char c) {
	while(c != EOF && (isspace(c) || c == '#')) {
		while(c != EOF && isspace(c)) {
			c = getc(f);
		} 
		if(c == '#') {
			do {
				c = getc(f);
			} while(c != EOF && !isline(c));
		}
	}
	return c;
}
Exemple #5
0
/*read partition in Clustnsee format*/
TypePartition readPartition(FILE *f, char***name) {
    char c;
    TypePartition part;
    int sizeBufItem = INC_SIZE_ITEM_BUF, index;
    TypeLexiTree *dict;
    dict = newLexiTree();

    part.sizeAtom = -1;
    part.sizeItem = 0;
    part.atom = (int*) malloc(sizeBufItem*sizeof(int));
    for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f));
    while(c != EOF) {
        char tmp[MAX_NAME_SIZE+1];
        int i;
        if(c == '\'' || c == '"') {
            c = fgetc(f);
            for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
            if(c == '\'' || c == '"')
                c = fgetc(f);
            else
                exitProg(ErrorReading, "Missing closing \" or '...");
        } else {
            for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
        }
/*		if(i == 0)
            exitProg(ErrorExec, "Empty name...");
*/		if(i == MAX_NAME_SIZE)
            exitProg(ErrorExec, "Name too much long...");
        if(i>0) {
            tmp[i++] = '\0';
//printf("%s\n", tmp);
            if(tmp[0] == '#') {
                for(; c != EOF && !isline(c); c = fgetc(f));
            } else {
                if(strncmp(tmp, CLUSTERID, strlen(CLUSTERID)) == 0) {
//	printf("Class\n");
                    part.sizeAtom++;
                    for(; c != EOF && !isline(c); c = fgetc(f));
                } else {
//	printf("Ident\n");
                    if(findWordLexi(tmp, dict) >= 0) {
                        printf("Duplicate identifier %s(%d)\n", tmp, findWordLexi(tmp, dict));
                        fprintLexiTree(stdout, dict);
                        exit(1);
                    }
                    index = addWordLexiTree(tmp, dict);
                    if(index>part.sizeItem)
                        part.sizeItem = index;
                    if(index>=sizeBufItem) {
                        sizeBufItem += INC_SIZE_ITEM_BUF;
                        part.atom = (int*) realloc((void*)part.atom, sizeBufItem*sizeof(int));
                    }
                    part.atom[index] = part.sizeAtom;
                }
            }
        }
        for(; c != EOF && issepline(c); c = fgetc(f));
    }
    part.sizeItem++;
    part.sizeAtom++;
    part.atom = (int*) realloc((void*)part.atom, part.sizeItem*sizeof(int));
    *name = (char**) malloc(part.sizeItem*sizeof(char*));
    fillLexiTree(*name, dict);
    freeLexiTree(dict);
    return part;
}
Exemple #6
0
/*read partition in Line Number format*/
TypePartition readPartitionNumber(FILE *f) {
    char c;
    TypePartition part;
    int sizeBufItem = INC_SIZE_ITEM_BUF, index;
    TypeLexiTree *dict;
    dict = newLexiTree();

    part.sizeAtom = 0;
    part.sizeItem = 0;
    part.atom = (int*) malloc(sizeBufItem*sizeof(int));
    for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f));
    while(c != EOF) {
        char tmp[MAX_NAME_SIZE+1];
        int i;
        while(c != EOF && !isline(c)) {
            if(c == '\'' || c == '"') {
                c = fgetc(f);
                for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
                    tmp[i] = c;
                    c = fgetc(f);
                }
                if(c == '\'' || c == '"')
                    c = fgetc(f);
                else
                    exitProg(ErrorReading, "Missing closing \" or '...");
            } else {
                for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issep(c); i++) {
                    tmp[i] = c;
                    c = fgetc(f);
                }
            }
            if(i == MAX_NAME_SIZE)
                exitProg(ErrorExec, "Name too much long...");
            if(i>0) {
                tmp[i++] = '\0';
                index = atoi(tmp);
				if(index>part.sizeItem)
                    part.sizeItem = index;
                if(index>=sizeBufItem) {
                    sizeBufItem += INC_SIZE_ITEM_BUF;
                    part.atom = (int*) realloc((void*)part.atom, sizeBufItem*sizeof(int));
                }
				for(; c != EOF && issep(c); c = fgetc(f));
				if(c == '\'' || c == '"') {
					c = fgetc(f);
					for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
						tmp[i] = c;
						c = fgetc(f);
					}
					if(c == '\'' || c == '"')
						c = fgetc(f);
					else
						exitProg(ErrorReading, "Missing closing \" or '...");
				} else {
					for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
						tmp[i] = c;
						c = fgetc(f);
					}
				}
				if(i == MAX_NAME_SIZE)
					exitProg(ErrorExec, "Name too much long...");
				if(i>0) {
					tmp[i++] = '\0';
					part.atom[index] = atoi(tmp);
					if(part.atom[index]>=part.sizeAtom)
						part.sizeAtom = part.atom[index]+1;
				}
            }
            for(; c != EOF && issep(c); c = fgetc(f));
        }
        for(; c != EOF && issepline(c); c = fgetc(f));
    }
    part.sizeItem++;
    part.atom = (int*) realloc((void*)part.atom, part.sizeItem*sizeof(int));
    return part;
}
Exemple #7
0
int v2body(BUFFER *body)
{
  int i, n;
  BUFFER *to, *newsgroups;
  BUFFER *temp, *out;
  BUFFER *line;
  int type = MSG_MAIL;
  int subject = 0;

  line = buf_new();
  to = buf_new();
  newsgroups = buf_new();
  temp = buf_new();
  out = buf_new();

  n = buf_getc(body);
  for (i = 0; i < n; i++) {
    buf_get(body, line, 80);
    buf_chop(line);
    if (bufileft(line, "null:"))
      goto end;
    if (bufileft(line, "post:")) {
      type = MSG_POST;
      if (line->length > 5) {
	int j = 5;

	while (j < line->length && isspace(line->data[j]))
	  j++;
	if (newsgroups->length > 0)
	  buf_appends(newsgroups, ",");
	buf_append(newsgroups, line->data + j, line->length - j);
      }
    } else {
      if (to->length > 0)
	buf_appends(to, ",");
      buf_cat(to, line);
    }
  }
  if (to->length > 0) {
    buf_appends(out, "To: ");
    buf_cat(out, to);
    buf_nl(out);
  }
  if (newsgroups->length > 0) {
    buf_appends(out, "Newsgroups: ");
    buf_cat(out, newsgroups);
    buf_nl(out);
  }
  n = buf_getc(body);
  for (i = 0; i < n; i++) {
    buf_get(body, line, 80);
    buf_chop(line);
    if (bufileft(line, "Subject:"))
      subject = 1;
    buf_cat(out, line);
    buf_nl(out);
  }

  buf_rest(temp, body);
  buf_uncompress(temp);
  buf_set(body, temp);
  buf_reset(temp);

  if (buf_lookahead(body, line) == 0 && isline(line, HASHMARK)) {
    buf_getline(body, line);
    while (buf_getline(body, line) == 0) {
      if (bufileft(line, "subject:"))
	subject = 1;
      buf_cat(out, line);
      buf_nl(out);
    }
  }
  if (type == MSG_POST && !subject)
    buf_appends(out, "Subject: (no subject)\n");

  buf_nl(out);
  buf_rest(out, body);
  buf_reset(body);
  mix_pool(out, type, -1);

end:
  buf_free(line);
  buf_free(to);
  buf_free(newsgroups);
  buf_free(temp);
  buf_free(out);
  return (0);
}
Exemple #8
0
TypeOntologyInfo *readOntologyInfo(FILE *f) {
	char c, first[MAX_NAME_SIZE+1], last[MAX_NAME_SIZE+1], id[MAX_NAME_SIZE+1], name[MAX_NAME_SIZE+1];
	int sizeBuffer, indexG, indexA, indexL, n, m, i, j;
	TypeOntologyInfo *info;

	info = (TypeOntologyInfo*) malloc(sizeof(TypeOntologyInfo));

	sizeBuffer = BASIC_INC_BUFFER_L;
	info->id = (char**) malloc(sizeBuffer*sizeof(char*));
	info->name = (char**) malloc(sizeBuffer*sizeof(char*));
	info->size = 0;
	for(c=getc(f); c!=EOF && issepline(c); c = fgetc(f));
	do {
		for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
			first[i] = c;
			c = fgetc(f);
		}
		first[i] = '\0';
		for(; c!=EOF && isline(c); c = fgetc(f));
		for(; c!=EOF && issepline(c); c = fgetc(f));
//printf("first %s\n", first);
	} while(strcmp(first, "[Term]") != 0);
	while(c != EOF) {
		id[0] = '\0';
		name[0] = '\0';
		do {
			for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issepline(c); i++) {
				first[i] = c;
				c = fgetc(f);
			}
			first[i] = '\0';
			if(strcmp(first, "id:") == 0) {
				for(; c!=EOF && issep(c); c = fgetc(f));
				for(i=0; i<MAX_NAME_SIZE && c !=EOF && !isline(c); i++) {
					id[i] = c;
					c = fgetc(f);
				}
				id[i] = '\0';
			}
			if(strcmp(first, "name:") == 0) {
				for(; c!=EOF && issep(c); c = fgetc(f));
				for(i=0; i<MAX_NAME_SIZE && c !=EOF && !isline(c); i++) {
					name[i] = c;
					c = fgetc(f);
				}
				name[i] = '\0';
			}
			for(; c!=EOF && !isline(c); c = fgetc(f));
			for(; c!=EOF && issepline(c); c = fgetc(f));
		} while(c != EOF && strcmp(first, "[Term]") != 0);
		if(id[0] != '\0' && name[0] != '\0') {
			if(info->size >= sizeBuffer) {
				sizeBuffer += BASIC_INC_BUFFER_L;
				info->id = (char**) realloc(info->id, sizeBuffer*sizeof(char*));
				info->name = (char**) realloc(info->name, sizeBuffer*sizeof(char*));
			}
			info->id[info->size] = strdup(id);
			info->name[info->size] = strdup(name);
			info->size++;
		}
	}
	info->id = (char**) realloc(info->id, info->size*sizeof(char*));
	info->name = (char**) realloc(info->name, info->size*sizeof(char*));
	return info;
}	
TypeNameFossilIntTab *readFossilIntTab(FILE *f) {
    int sizeBuf;
    char c;
    TypeNameFossilIntTab *res;

    res = (TypeNameFossilIntTab *) malloc(sizeof(TypeNameFossilIntTab));
    sizeBuf = INC_FOSSIL_ITEM;
    res->name = (char**) malloc(sizeBuf*sizeof(char*));
    res->fossilIntTab = (TypeFossilIntTab*) malloc(sizeBuf*sizeof(TypeFossilIntTab));
    res->size = 0;
    do {
        char *tmp;
        int i;
        tmp = (char*) malloc((MAX_NAME_SIZE+1)*sizeof(char));
        for(c = fgetc(f); c != EOF && issepline(c); c = fgetc(f));
        if(c == '\'' || c == '"') {
            c = fgetc(f);
            for(i=0; i<MAX_NAME_SIZE && c != EOF && c != '\'' && c != '"'; i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
            if(c == '\'' || c == '"')
                c = fgetc(f);
        } else {
            for(i=0; i<MAX_NAME_SIZE && c !=EOF && !issep(c); i++) {
                tmp[i] = c;
                c = fgetc(f);
            }
        }
        if(i == MAX_NAME_SIZE)
            exitProg(ErrorExec, "Name too much long...");
        tmp[i++] = '\0';
        if(i>1) {
            char bof[MAX_NAME_SIZE+1];
            int sizeFossilIntBuf = INC_FOSSIL_ITEM;
            if(res->size >= sizeBuf) {
                sizeBuf += INC_FOSSIL_ITEM;
                res->name = (char**) realloc((void*) res->name, sizeBuf*sizeof(char*));
                res->fossilIntTab = (TypeFossilIntTab*) realloc((void*) res->fossilIntTab, sizeBuf*sizeof(TypeFossilIntTab));
            }
            res->name[res->size] = (char *) realloc((void*) tmp, i*sizeof(char));
            fixSpace(res->name[res->size]);
            res->fossilIntTab[res->size].size = 0;
            res->fossilIntTab[res->size].fossilInt = (TypeTimeInterval*) malloc(sizeFossilIntBuf*sizeof(TypeTimeInterval));
            for(; c != EOF && issep(c); c = fgetc(f));
            while(c != EOF && !isline(c)) {
                for(i=0; c != EOF && !issepline(c) && i<MAX_NAME_SIZE; i++) {
                    bof[i] = c;
                    c = fgetc(f);
                }
                bof[i++] = '\0';
                if(res->fossilIntTab[res->size].size>=sizeFossilIntBuf) {
                    sizeFossilIntBuf += INC_FOSSIL_ITEM;
                    res->fossilIntTab[res->size].fossilInt = (TypeTimeInterval*) realloc((void*) res->fossilIntTab[res->size].fossilInt, sizeFossilIntBuf*sizeof(TypeTimeInterval));
                }
                res->fossilIntTab[res->size].fossilInt[res->fossilIntTab[res->size].size++] = toFossilInt(bof);
DEBUG(
    printf("\"%s\"\t%s\t", tmp, bof);
    fprintFossilInt(stdout, res->fossilIntTab[res->size].fossilInt[res->fossilIntTab[res->size].size-1]);
    printf("\n");
)
                for(; c != EOF && issep(c); c = fgetc(f));
            }
            res->size++;
        } else