예제 #1
0
파일: alic.c 프로젝트: maksverver/ali
/* Resolve fragment token given by string [i:j) of type `type'.
   Returns -1 if not match found, -2 for multiple matches, >= 0 otherwise. */
int resolve_fragment(int type, const char *i, const char *j)
{
/*
    const void *f_idx;
    const Fragment *f;
    char *str = strdup(token);
    normalize(str);
    if (!ST_find(&st_fragments, str, &f_idx))
    {
        fatal("Reference to undeclared fragment \"%s\" on line %d.",
            str, lineno + 1);
    }
    free(str);
    f = AR_at(&ar_fragments, (long)f_idx);
    if (type != -1 && type != (int)f->type)
    {
        fatal("Fragment referenced by \"%s\" has wrong type on line %d.",
            str, lineno + 1);
    }
    return f->id;
*/
    switch (type)
    {
    case F_VERB:
        return find_fragment(&ar_verbs, i, j);

    case F_PREPOSITION:
        return find_fragment(&ar_preps, i, j);

    case F_ENTITY:
        return find_fragment(&ar_ents, i, j);

    default:
        fatal("invalid fragment type");
        return -1;
    }
}
예제 #2
0
static const char *
replace_attr (const char *p, int size, FILE *fp, const char *new_text)
{
    bool quote_flag = false;
    char quote_char = '\"';       /* use "..." for quoting, unless the
                                   original value is quoted, in which
                                   case reuse its quoting char. */
    const char *frag_beg, *frag_end;

    /* Structure of our string is:
         "...old-contents..."
         <---    size    --->  (with quotes)
       OR:
         ...old-contents...
         <---    size   -->    (no quotes)   */

    if (*p == '\"' || *p == '\'')
    {
        quote_char = *p;
        quote_flag = true;
        ++p;
        size -= 2;                /* disregard opening and closing quote */
    }
    putc (quote_char, fp);
    fputs (new_text, fp);

    /* Look for fragment identifier, if any. */
    if (find_fragment (p, size, &frag_beg, &frag_end))
        fwrite (frag_beg, 1, frag_end - frag_beg, fp);
    p += size;
    if (quote_flag)
        ++p;
    putc (quote_char, fp);

    return p;
}