Changeset ed05467


Ignore:
Timestamp:
Mar 13, 2016, 12:43:12 PM (8 years ago)
Author:
Karl Ramm <kcr@1ts.org>
Children:
a2a3cc0
Parents:
9e219d3
git-author:
Karl Ramm <kcr@1ts.org> (03/12/16 21:41:34)
git-committer:
Karl Ramm <kcr@1ts.org> (03/13/16 12:43:12)
Message:
clean out some debug tooling
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ztext.c

    r9e219d3 red05467  
    2222    JNMATCH, // next slot is where to go if the stack is not a match
    2323    JNSAVED, // ""
    24     MAX_OPS,
    25 };
    26 
    27 static const char *opname[MAX_OPS]= {
    28     [NEXT] = "NEXT",
    29     [TEXTC] = "TEXTC",
    30     [LABELC] = "LABELC",
    31     [UNSAVE] = "UNSAVE",
    32     [EMIT] = "EMIT",
    33     [CLEAR] = "CLEAR",
    34     [PUSH] = "PUSH",
    35     [POP] = "POP",
    36     [JNMATCH] = "JNMATCH",
    37     [JNSAVED] = "JNSAVED",
    3824};
    3925
     
    142128    ztext_env *tree = ztext_env_new(g_strdup(""), 0);
    143129    ztext_env *cur = tree;
    144     int debug = 0;
    145130
    146131    text[texti] = 0;
     
    148133
    149134    for(int i = 0; i <= len; i++) { /* <=: deliberately processing the '\0' */
    150         if (debug) printf("'%s' %d %c\n", unctrl(s[i]), state, stack ? stack->close : '-');
    151135        const unsigned char *line = machine[state][(unsigned)s[i]];
    152136        next = -1;
    153137        for (int ip = 0; next == -1; ip++) {
    154             if (debug) printf(" %s \"%s\" \"%s\"\n", opname[line[ip]], text, save);
    155138            switch (line[ip]) {
    156139            case NEXT:
     
    242225    return s;
    243226}
    244 
    245 #ifdef notmain
    246 char *ztext_ztext(ztext_env *tree) {
    247     char *s, *t;
    248 
    249     if (tree->closer == '@' && tree->content == NULL)
    250         return g_strdup("@@");
    251 
    252     if (tree->opener) {
    253         s = g_strdup_printf("%s%c", tree->label, tree->opener);
    254     } else {
    255         s = g_strdup("");
    256     }
    257 
    258     for (ztext_node *p = tree->content; p != NULL; p = p->next) {
    259         t = s;
    260         if (p->type== ZTEXT_NODE_STRING) {
    261             s = g_strconcat(s, p->string, NULL);
    262         } else if (p->type == ZTEXT_NODE_ENV) {
    263             s = g_strconcat(s, ztext_ztext(p->env), NULL);
    264         }
    265         g_free(t);
    266     }
    267 
    268     if (tree->closer) {
    269         t = s;
    270         s = g_strdup_printf("%s%c", s, tree->closer);
    271         g_free(t);
    272     }
    273 
    274     return s;
    275 }
    276 
    277 static char *ztext_str(ztext_env *tree) {
    278     /* Unambiguous representation of the parse tree */
    279     char *s, *t;
    280 
    281     if (tree->opener) {
    282         s = g_strdup_printf("{'%s%c'", tree->label, tree->opener);
    283     } else {
    284         s = g_strdup("{-");
    285     }
    286 
    287     for (ztext_node *p = tree->content; p != NULL; p = p->next) {
    288         t = s;
    289         if (p->type== ZTEXT_NODE_STRING) {
    290             s = g_strdup_printf("%s |%s|", s, p->string);
    291         } else if (p->type == ZTEXT_NODE_ENV) {
    292             s = g_strconcat(s, " ", ztext_str(p->env), NULL);
    293         }
    294         g_free(t);
    295     }
    296 
    297     t = s;
    298     if (tree->closer) {
    299         s = g_strdup_printf("%s '%c'}", s, tree->closer);
    300     } else {
    301         s = g_strconcat(s, "}", NULL);
    302     }
    303     g_free(t);
    304 
    305     return s;
    306 }
    307 
    308 int notmain(int argc, char *argv[]) {
    309     if (argc != 2) {
    310         printf("?%d\n", argc);
    311         exit(1);
    312     }
    313     ztext_env *tree = ztext_tree(argv[1]);
    314     char *s = ztext_ztext(tree);
    315     printf("%s\n", s);
    316     g_free(s);
    317     s = ztext_str(tree);
    318     printf("%s\n", s);
    319     g_free(s);
    320     ztext_env_free(tree);
    321     return 0;
    322 }
    323 #endif
Note: See TracChangeset for help on using the changeset viewer.