Exemple #1
0
static void write_dict(Agdict_t * dict, FILE * fp)
{
    int i, cnt = 0;
    Agsym_t *a;

    for (i = 0; i < dtsize(dict->dict); i++) {
	a = dict->list[i];
	if (ISEMPTYSTR(a->value) == FALSE) {
	    if (cnt++ == 0)
		fprintf(fp, "\t%s [", dict->name);
	    else
		fprintf(fp, ", ");
	    fprintf(fp, "%s=%s", a->name, agcanonical(a->value));
	}
    }
    if (cnt > 0)
	fprintf(fp, "];\n");
}
Exemple #2
0
/* _agstrcanon:
 * Canonicalize an ordinary string if necessary.
 */
static char* 
_agstrcanon (char* arg, char* buf)
{
    char *s = arg;
    unsigned char uc;
    char *p = buf;
    int cnt = 0;
    int has_special = FALSE;
    int maybe_num;

    if (ISEMPTYSTR(arg))
	return "\"\"";
    *p++ = '\"';
    uc = *(unsigned char *) s++;
    maybe_num = (isdigit(uc) || (uc == '.'));
    while (uc) {
	if (uc == '\"') {
	    *p++ = '\\';
	    has_special = TRUE;
	} else {
	    if (!ISALNUM(uc))
		has_special = TRUE;
	    else if (maybe_num && (!isdigit(uc) && (uc != '.')))
		has_special = TRUE;
	}
	*p++ = (char) uc;
	uc = *(unsigned char *) s++;
	cnt++;
	if (cnt % SMALLBUF == 0) {
	    *p++ = '\\';
	    *p++ = '\n';
	    has_special = TRUE;
	}
    }
    *p++ = '\"';
    *p = '\0';
    if (has_special)
	return buf;

    /* use quotes to protect tokens (example, a node named "node") */
    if (agtoken(arg) >= 0)
	return buf;
    return arg;
}
Exemple #3
0
static void write_dict(Agdict_t * dict, FILE * fp)
{
    int i, cnt = 0;
    Agsym_t *a;

    for (i = 0; i < dtsize(dict->dict); i++) {
	a = dict->list[i];
	if (ISEMPTYSTR(a->value) == FALSE) {
	    if (cnt++ == 0) {
		agputc('\t', fp);
		agputs(dict->name, fp);
		agputs(" [", fp);
	    }
	    else {
		agputs(", ", fp);
            }
	    agputs(a->name, fp);
	    agputc('=', fp);
	    agputs(agcanonical(a->value), fp);
	}
    }
    if (cnt > 0)
	agputs("];\n", fp);
}
Exemple #4
0
/* _agstrcanon:
 * Canonicalize an ordinary string if necessary.
 */
static char* 
_agstrcanon (char* arg, char* buf)
{
    char *s = arg;
    unsigned char uc;
    char *p = buf;
    int cnt = 0, dotcnt = 0;
    int has_special = FALSE;
    int maybe_num;
    int backslash_pending = FALSE;

    if (ISEMPTYSTR(arg))
	return "\"\"";
    *p++ = '\"';
    uc = *(unsigned char *) s++;
    maybe_num = _is_number_char(uc) || (uc == '-');
    while (uc) {
	if (uc == '\"') {
	    *p++ = '\\';
	    has_special = TRUE;
	} 
	else if (maybe_num) {
	    if (uc == '-') {
		if (cnt) {
		    maybe_num = FALSE;
		    has_special = TRUE;
		}
	    }
	    else if (uc == '.') {
		if (dotcnt++) {
		    maybe_num = FALSE;
		    has_special = TRUE;
		}
	    }
	    else if (!isdigit(uc)) {
		maybe_num = FALSE;
		has_special = TRUE;
	    }
	}
	else if (!ISALNUM(uc))
	    has_special = TRUE;
	*p++ = (char) uc;
	uc = *(unsigned char *) s++;
	cnt++;
        if (uc && backslash_pending && !((_is_number_char(p[-1]) || isalpha(p[-1]) || (p[-1] == '\\')) && (_is_number_char(uc) || isalpha(uc)))) {
            *p++ = '\\';
            *p++ = '\n';
            has_special = TRUE;
            backslash_pending = FALSE;
        } else if (uc && cnt % SMALLBUF == 0) {
            if (!((_is_number_char(p[-1]) || isalpha(p[-1]) || (p[-1] == '\\')) && (_is_number_char(uc) || isalpha(uc)))) {
	        *p++ = '\\';
    	        *p++ = '\n';
	        has_special = TRUE;
            } else {
                backslash_pending = TRUE;
            }
	}
    }
    *p++ = '\"';
    *p = '\0';
    if (has_special || ((cnt == 1) && ((*arg == '.') || (*arg == '-'))))
	return buf;

    /* use quotes to protect tokens (example, a node named "node") */
    if (agtoken(arg) >= 0)
	return buf;
    return arg;
}