HIDDEN int wdb_do_paren(struct bu_list *hp) { struct tokens *tok; for (BU_LIST_FOR(tok, tokens, hp)) { struct tokens *prev, *next; if (tok->type != WDB_TOK_TREE) continue; prev = BU_LIST_PREV(tokens, &tok->l); next = BU_LIST_NEXT(tokens, &tok->l); if (prev->type !=WDB_TOK_LPAREN || next->type != WDB_TOK_RPAREN) continue; /* this is an eligible operand surrounded by parens */ BU_LIST_DEQUEUE(&next->l); bu_free((char *)next, "next"); BU_LIST_DEQUEUE(&prev->l); bu_free((char *)prev, "prev"); } if (hp->forw == hp->back && hp->forw != hp) return 1; /* done */ else if (BU_LIST_IS_EMPTY(hp)) return -1; /* empty tree!!!! */ else return 0; /* more to do */ }
HIDDEN void wdb_do_inter(struct bu_list *hp) { struct tokens *tok; for (BU_LIST_FOR(tok, tokens, hp)) { struct tokens *prev, *next; union tree *tp; if (tok->type != WDB_TOK_INTER) continue; prev = BU_LIST_PREV(tokens, &tok->l); next = BU_LIST_NEXT(tokens, &tok->l); if (prev->type !=WDB_TOK_TREE || next->type != WDB_TOK_TREE) continue; /* this is an eligible intersection operation */ BU_ALLOC(tp, union tree); RT_TREE_INIT(tp); tp->tr_b.tb_op = OP_INTERSECT; tp->tr_b.tb_regionp = (struct region *)NULL; tp->tr_b.tb_left = prev->tp; tp->tr_b.tb_right = next->tp; BU_LIST_DEQUEUE(&tok->l); bu_free((char *)tok, "tok"); BU_LIST_DEQUEUE(&prev->l); bu_free((char *)prev, "prev"); next->tp = tp; tok = next; } }
void merge(void) { struct frame *cur, *next; for (BU_LIST_FOR(cur, frame, &head)) { next = BU_LIST_NEXT(frame, &cur->l); if (BU_LIST_IS_HEAD(next, &head)) break; if (cur->number == next->number) { if (next->text) addtext(cur, next->text); cur->flags |= next->flags; BU_LIST_DEQUEUE(&next->l); if (next->text) bu_free(next->text, "text area"); next->text = NULL; next->l.magic = -1; bu_free(next, "struct frame"); cur = BU_LIST_PREV(frame, &cur->l); } } }
HIDDEN void wdb_do_union_subtr(struct bu_list *hp) { struct tokens *tok; for (BU_LIST_FOR(tok, tokens, hp)) { struct tokens *prev, *next; union tree *tp; if (tok->type != WDB_TOK_UNION && tok->type != WDB_TOK_SUBTR) continue; prev = BU_LIST_PREV( tokens, &tok->l ); next = BU_LIST_NEXT( tokens, &tok->l ); if (prev->type !=WDB_TOK_TREE || next->type != WDB_TOK_TREE) continue; /* this is an eligible operation */ tp = (union tree *)bu_malloc( sizeof( union tree ), "tp" ); tp->magic = RT_TREE_MAGIC; if (tok->type == WDB_TOK_UNION) tp->tr_b.tb_op = OP_UNION; else tp->tr_b.tb_op = OP_SUBTRACT; tp->tr_b.tb_regionp = (struct region *)NULL; tp->tr_b.tb_left = prev->tp; tp->tr_b.tb_right = next->tp; BU_LIST_DEQUEUE(&tok->l); bu_free((char *)tok, "tok"); BU_LIST_DEQUEUE(&prev->l); bu_free((char *)prev, "prev"); next->tp = tp; tok = next; } }
HIDDEN void do_union_subtr(struct bu_list *hp) { struct tokens *tok; for (BU_LIST_FOR(tok, tokens, hp)) { struct tokens *prev, *next; union tree *tp; if (tok->type != TOK_UNION && tok->type != TOK_SUBTR) continue; prev = BU_LIST_PREV(tokens, &tok->l); next = BU_LIST_NEXT(tokens, &tok->l); if (prev->type !=TOK_TREE || next->type != TOK_TREE) continue; /* this is an eligible operation */ BU_ALLOC(tp, union tree); RT_TREE_INIT(tp); if (tok->type == TOK_UNION) tp->tr_b.tb_op = OP_UNION; else tp->tr_b.tb_op = OP_SUBTRACT; tp->tr_b.tb_regionp = (struct region *)NULL; tp->tr_b.tb_left = prev->tp; tp->tr_b.tb_right = next->tp; BU_LIST_DEQUEUE(&tok->l); bu_free((char *)tok, "tok"); BU_LIST_DEQUEUE(&prev->l); bu_free((char *)prev, "prev"); next->tp = tp; tok = next; } }
int bu_cmdhist_history(void *data, int argc, const char *argv[]) { FILE *fp; int with_delays = 0; struct bu_cmdhist *hp, *hp_prev; struct bu_vls str = BU_VLS_INIT_ZERO; struct timeval tvdiff; struct bu_cmdhist_obj *chop = (struct bu_cmdhist_obj *)data; if (argc < 2 || 5 < argc) { bu_log("Usage: %s -delays\nList command history.\n", argv[0]); return BRLCAD_ERROR; } fp = NULL; while (argc >= 3) { const char *delays = "-delays"; const char *outfile = "-outfile"; if (BU_STR_EQUAL(argv[2], delays)) with_delays = 1; else if (BU_STR_EQUAL(argv[2], outfile)) { if (fp != NULL) { fclose(fp); bu_log("%s: -outfile option given more than once\n", argv[0]); return BRLCAD_ERROR; } else if (argc < 4 || BU_STR_EQUAL(argv[3], delays)) { bu_log("%s: I need a file name\n", argv[0]); return BRLCAD_ERROR; } else { fp = fopen(argv[3], "ab+"); if (UNLIKELY(fp == NULL)) { bu_log("%s: error opening file", argv[0]); return BRLCAD_ERROR; } --argc; ++argv; } } else { bu_log("Invalid option %s\n", argv[2]); } --argc; ++argv; } for (BU_LIST_FOR(hp, bu_cmdhist, &chop->cho_head.l)) { bu_vls_trunc(&str, 0); hp_prev = BU_LIST_PREV(bu_cmdhist, &hp->l); if (with_delays && BU_LIST_NOT_HEAD(hp_prev, &chop->cho_head.l)) { if (cmdhist_timediff(&tvdiff, &(hp_prev->h_finish), &(hp->h_start)) >= 0) bu_vls_printf(&str, "delay %ld %ld\n", (long)tvdiff.tv_sec, (long)tvdiff.tv_usec); } if (hp->h_status == BRLCAD_ERROR) bu_vls_printf(&str, "# "); bu_vls_vlscat(&str, &(hp->h_command)); if (fp != NULL) bu_vls_fwrite(fp, &str); else bu_log("%s\n", bu_vls_addr(&str)); } if (fp != NULL) fclose(fp); return BRLCAD_OK; }