static void print_line(FILE *dest, void *buf, size_t len, size_t addr, char *addr_fmt) { size_t words = len / BYTES_PER_WORD; size_t last_word = len % BYTES_PER_WORD; char *pos = buf; size_t i; uint32_t line_pos = 0; fprintf(dest, addr_fmt, addr); for (i = 0; i < words; i++) { line_pos += print_word(dest, pos, BYTES_PER_WORD); pos += BYTES_PER_WORD; } if (last_word) { line_pos += print_word(dest, pos, last_word); } fprintf(dest, "%s| ", &spc_line[line_pos]); for (i = 0; i < len; i++) { char c = ((char*)buf)[i]; if (isprint(c)) { fprintf(dest, "%c", c); } else { fprintf(dest, "."); } } fprintf(dest, "\n"); }
void print_production (Production* p){ print_word(&p->left); printf (" --> "); print_word(&p->right); print_error(p->error); }
static int pre_bl(DECL_ARGS) { size_t icol; /* * print_offs() will increase the -offset to account for * a possible enclosing .It, but any enclosed .It blocks * just nest and do not add up their indentation. */ if (n->norm->Bl.offs) { print_offs(n->norm->Bl.offs, 0); Bl_stack[Bl_stack_len++] = 0; } switch (n->norm->Bl.type) { case LIST_enum: n->norm->Bl.count = 0; return 1; case LIST_column: break; default: return 1; } if (n->child != NULL) { print_line(".TS", MMAN_nl); for (icol = 0; icol < n->norm->Bl.ncols; icol++) print_word("l"); print_word("."); } outflags |= MMAN_nl; return 1; }
static void post_bd(DECL_ARGS) { enum roff_tok bef, now; /* Close out this display. */ print_line(".RE", MMAN_nl); bef = n->flags & NODE_NOFILL ? ROFF_nf : ROFF_fi; if (n->last == NULL) now = n->norm->Bd.type == DISP_unfilled || n->norm->Bd.type == DISP_literal ? ROFF_nf : ROFF_fi; else if (n->last->tok == ROFF_nf) now = ROFF_nf; else if (n->last->tok == ROFF_fi) now = ROFF_fi; else now = n->last->flags & NODE_NOFILL ? ROFF_nf : ROFF_fi; if (bef != now) { outflags |= MMAN_nl; print_word("."); outflags &= ~MMAN_spc; print_word(roff_name[bef]); outflags |= MMAN_nl; } /* Maybe we are inside an enclosing list? */ if (NULL != n->parent->next) mid_it(); }
void print_map(struct pcp_vars *pcp) { register int *y = y_address; int ndgen = pcp->ndgen; int dgen = pcp->dgen; int p2; int i; #if defined(GROUP) printf("\nRelationship between group defining generators and "); printf("consistent\npower-commutator presentation generators:\n"); #endif for (i = 1; i <= ndgen; i++) { p2 = y[dgen + i]; printf("%d", i); printf(" "); printf(" ="); print_word(p2, pcp); p2 = y[dgen - i]; if (p2 <= 0) { printf("%d", i); printf("^-1 ="); print_word(p2, pcp); } } }
void rev_text_1(char *text) { char *pos = NULL; char *next = NULL; struct list *tmp = NULL; struct list *rev = NULL; pos = text; do { tmp = calloc(1, sizeof(struct list)); next = my_strtok(pos, ' '); tmp->word = pos; tmp->word_len = (unsigned) (next - pos) -1; tmp->next = rev; rev = tmp; pos = next; } while( pos != NULL ); while( rev != '\0' ) { print_word( rev->word, 0, rev->word_len); tmp = rev; rev = rev->next; free(tmp); } print_word("\n", 0, 1); }
/* * Set up the indentation for a list item; used from pre_it(). */ static void print_width(const struct mdoc_bl *bl, const struct roff_node *child) { char buf[24]; struct roffsu su; const char *end; int numeric, remain, sz, chsz; numeric = 1; remain = 0; /* Convert the width into a number (of characters). */ if (bl->width == NULL) sz = (bl->type == LIST_hang) ? 6 : 0; else { end = a2roffsu(bl->width, &su, SCALE_MAX); if (end == NULL || *end != '\0') sz = man_strlen(bl->width); else if (SCALE_EN == su.unit) sz = su.scale; else { sz = 0; numeric = 0; } } /* XXX Rough estimation, might have multiple parts. */ if (bl->type == LIST_enum) chsz = (bl->count > 8) + 1; else if (child != NULL && child->type == ROFFT_TEXT) chsz = man_strlen(child->string); else chsz = 0; /* Maybe we are inside an enclosing list? */ mid_it(); /* * Save our own indentation, * such that child lists can use it. */ Bl_stack[Bl_stack_len++] = sz + 2; /* Set up the current list. */ if (chsz > sz && bl->type != LIST_tag) print_block(".HP", 0); else { print_block(".TP", 0); remain = sz + 2; } if (numeric) { (void)snprintf(buf, sizeof(buf), "%dn", sz + 2); print_word(buf); } else print_word(bl->width); TPremain = remain; }
static void pre_noarg(DECL_ARGS) { outflags |= MMAN_nl; print_word("."); outflags &= ~MMAN_spc; print_word(roff_name[n->tok]); outflags |= MMAN_nl; }
int do_fontwords(int this_font, int other_font, int early_exit) { static char ftab[] = " RBIS"; char *p=word; int i, ch; int in_quote = 0; no_nl=0; /* Line is effectivly been reprocessed so NL is visable */ for(;;) { if (p == word) { strcpy(p, "\\f"); p[2]=ftab[this_font]; p+=3; } if ((ch=fgetc(ifd)) == EOF || ch == '\n') break; if (ch == '"') { in_quote = !in_quote; continue; } if (in_quote || !isspace(ch)) { if (isspace(ch) && p > word+3) { strcpy(p, "\\fR"); p+=3; *p=0; print_word(word); p=word; if (no_fill) print_word(" "); continue; } if (p<word+sizeof(word)-4) *p++ = ch; if (ch == '\\') { if ((ch=fgetc(ifd)) == EOF || ch == '\n') break; if (p<word+sizeof(word)-4) *p++ = ch; } continue; } if (p != word+3) { if (early_exit) break; if (this_font == other_font) { strcpy(p, "\\fR"); p+=3; *p=0; print_word(word); p=word; } i=this_font; this_font=other_font; other_font=i; if (p<word+sizeof(word)-4) { strcpy(p, "\\f"); p[2]=ftab[this_font]; p+=3; } } } ungetc(ch, ifd); if (p > word+3) { strcpy(p, "\\fR"); p+=3; *p=0; print_word(word); } return 0; }
static void post_fn(DECL_ARGS) { print_word(")"); if (NODE_SYNPRETTY & n->flags) { print_word(";"); outflags |= MMAN_PP; } }
static int pre_ux(DECL_ARGS) { print_word(manacts[n->tok].prefix); if (NULL == n->child) return(0); outflags &= ~MMAN_spc; print_word("\\ "); outflags &= ~MMAN_spc; return(1); }
void print_pcp_relations(struct pcp_vars *pcp) { register int *y = y_address; register int i; register int j; register int k; register int l; register int p1; register int p2; register int weight; #include "access.h" k = y[pcp->clend + pcp->cc - 1]; /* int start, finish; printf ("input start, finish: "); scanf ("%d %d", &start, &finish); */ #if defined(GROUP) printf("\nNon-trivial powers:\n"); /* for (i = start; i <= finish; i++) { */ for (i = 1; i <= k; i++) { p2 = y[pcp->ppower + i]; if (p2 != 0) { printf(" .%d^%d =", i, pcp->p); print_word(p2, pcp); } } printf("\nNon-trivial commutators:\n"); #endif /* for (i = start; i <= finish; i++) { */ for (i = 2; i <= k; i++) { weight = WT(y[pcp->structure + i]); p1 = y[pcp->ppcomm + i]; l = MIN(i - 1, y[pcp->clend + pcp->cc - weight]); for (j = 1; j <= l; j++) { p2 = y[p1 + j]; if (p2 != 0) { printf("[ .%d, .%d ] =", i, j); print_word(p2, pcp); } } } }
/* * Set up the indentation for a list item; used from pre_it(). */ static void print_width(const char *v, const struct mdoc_node *child, size_t defsz) { char buf[24]; struct roffsu su; size_t sz, chsz; int numeric, remain; numeric = 1; remain = 0; /* Convert v into a number (of characters). */ if (NULL == v) sz = defsz; else if (a2roffsu(v, &su, SCALE_MAX)) { if (SCALE_EN == su.unit) sz = su.scale; else { sz = 0; numeric = 0; } } else sz = strlen(v); /* XXX Rough estimation, might have multiple parts. */ chsz = (NULL != child && MDOC_TEXT == child->type) ? strlen(child->string) : 0; /* Maybe we are inside an enclosing list? */ mid_it(); /* * Save our own indentation, * such that child lists can use it. */ Bl_stack[Bl_stack_len++] = sz + 2; /* Set up the current list. */ if (defsz && chsz > sz) print_block(".HP", 0); else { print_block(".TP", 0); remain = sz + 2; } if (numeric) { (void)snprintf(buf, sizeof(buf), "%zun", sz + 2); print_word(buf); } else print_word(v); TPremain = remain; }
static void pre_onearg(DECL_ARGS) { outflags |= MMAN_nl; print_word("."); outflags &= ~MMAN_spc; print_word(roff_name[n->tok]); if (n->child != NULL) print_word(n->child->string); outflags |= MMAN_nl; if (n->tok == ROFF_ce) for (n = n->child->next; n != NULL; n = n->next) print_node(meta, n); }
static void post_in(DECL_ARGS) { if (NODE_SYNPRETTY & n->flags) { outflags &= ~MMAN_spc; print_word(">"); font_pop(); outflags |= MMAN_br; } else { font_pop(); outflags &= ~MMAN_spc; print_word(">"); } }
static void print_offs(const char *v, int keywords) { char buf[24]; struct roffsu su; const char *end; int sz; print_line(".RS", MMAN_Bk_susp); /* Convert v into a number (of characters). */ if (NULL == v || '\0' == *v || (keywords && !strcmp(v, "left"))) sz = 0; else if (keywords && !strcmp(v, "indent")) sz = 6; else if (keywords && !strcmp(v, "indent-two")) sz = 12; else { end = a2roffsu(v, &su, SCALE_EN); if (end == NULL || *end != '\0') sz = man_strlen(v); else if (SCALE_EN == su.unit) sz = su.scale; else { /* * XXX * If we are inside an enclosing list, * there is no easy way to add the two * indentations because they are provided * in terms of different units. */ print_word(v); outflags |= MMAN_nl; return; } } /* * We are inside an enclosing list. * Add the two indentations. */ if (Bl_stack_len) sz += Bl_stack[Bl_stack_len - 1]; (void)snprintf(buf, sizeof(buf), "%dn", sz); print_word(buf); outflags |= MMAN_nl; }
static void post_percent(DECL_ARGS) { if (mdoc_man_act(n->tok)->pre == pre_em) font_pop(); if (n->next) { print_word(","); if (n->prev && n->prev->tok == n->tok && n->next->tok == n->tok) print_word("and"); } else { print_word("."); outflags |= MMAN_nl; } }
static int pre_in(DECL_ARGS) { if (NODE_SYNPRETTY & n->flags) { pre_syn(n); font_push('B'); print_word("#include <"); outflags &= ~MMAN_spc; } else { print_word("<"); outflags &= ~MMAN_spc; font_push('I'); } return 1; }
static void pre_ft(DECL_ARGS) { print_line(".ft", 0); print_word(n->child->string); outflags |= MMAN_nl; }
void sort_str(const char *str) { char ar[100][100]; int index = 0; int word = 0; int start = 0; int end = 0; while (str[end] != '\0') { if (my_isspace(str[end])) { if (word == 1) { word = 0; str_ncpy(ar[index], str, start, end - 1); index++; } } else if (word == 0){ word = 1; start = end; } end++; } if (!my_isspace(--end)) { str_ncpy(ar[index++], str, start, end); } sort_word(ar, index); print_word(ar, index); }
static int pre_fn(DECL_ARGS) { pre_syn(n); n = n->child; if (NULL == n) return 0; if (NODE_SYNPRETTY & n->flags) print_block(".HP 4n", MMAN_nl); font_push('B'); print_node(meta, n); font_pop(); outflags &= ~MMAN_spc; print_word("("); outflags &= ~MMAN_spc; n = n->next; if (NULL != n) pre_fa(meta, n); return 0; }
static void post_fa(DECL_ARGS) { if (NULL != n->next && MDOC_Fa == n->next->tok) print_word(","); }
int main() { char key[256]; Word *p; Word *head = NULL; while (1) { printf("調べたい単語を入力してください.\n"); scanf("%s", key); if (strcmp(key, "-add") == 0) { printf("辞書に単語を追加します.\n"); printf("読み方は? "); scanf("%s", key); head = add(key, head); } else if (strcmp(key, "-delete") == 0) { printf("辞書から単語を削除します.\n"); printf("読み方は? "); scanf("%s", key); head = delete(key, head); } else if (strcmp(key, "-quit") == 0) { break; } else { p = search(key, head); if (p == NULL) { printf("指定した単語は見つかりませんでした.\n"); } else { print_word(p); } } } return 0; }
static int pre_nm(DECL_ARGS) { char *name; if (MDOC_BLOCK == n->type) { outflags |= MMAN_Bk; pre_syn(n); } if (MDOC_ELEM != n->type && MDOC_HEAD != n->type) return(1); name = n->child ? n->child->string : meta->name; if (NULL == name) return(0); if (MDOC_HEAD == n->type) { if (NULL == n->parent->prev) outflags |= MMAN_sp; print_block(".HP", 0); printf(" %zun", strlen(name) + 1); outflags |= MMAN_nl; } font_push('B'); if (NULL == n->child) print_word(meta->name); return(1); }
static int pre_nm(DECL_ARGS) { char *name; if (n->type == ROFFT_BLOCK) { outflags |= MMAN_Bk; pre_syn(n); } if (n->type != ROFFT_ELEM && n->type != ROFFT_HEAD) return 1; name = n->child ? n->child->string : meta->name; if (NULL == name) return 0; if (n->type == ROFFT_HEAD) { if (NULL == n->parent->prev) outflags |= MMAN_sp; print_block(".HP", 0); printf(" %zun", strlen(name) + 1); outflags |= MMAN_nl; } font_push('B'); if (NULL == n->child) print_word(meta->name); return 1; }
static void post_percent(DECL_ARGS) { if (pre_em == manacts[n->tok].pre) font_pop(); if (n->next) { print_word(","); if (n->prev && n->prev->tok == n->tok && n->next->tok == n->tok) print_word("and"); } else { print_word("."); outflags |= MMAN_nl; } }
static int pre_fo(DECL_ARGS) { switch (n->type) { case ROFFT_BLOCK: pre_syn(n); break; case ROFFT_HEAD: if (n->child == NULL) return 0; if (NODE_SYNPRETTY & n->flags) print_block(".HP 4n", MMAN_nl); font_push('B'); break; case ROFFT_BODY: outflags &= ~(MMAN_spc | MMAN_nl); print_word("("); outflags &= ~MMAN_spc; break; default: break; } return 1; }
static int print_close(dtd_parser * p, dtd_element * e) { print_word(p, ')', e->name->name, 0); putchar('\n'); return TRUE; }
int do_command(void) { const char *cmd; int i; char lbuf[10]; cmd = word + 1; /* Comments don't need the space */ if (strncmp(cmd, "\\\"", 2) == 0) cmd = "\\\""; for (i = 0; cmd_list[i].cmd[0]; i++) { if (strcmp(cmd_list[i].cmd, cmd) == 0) break; } if (cmd_list[i].cmd[0] == 0) { if (verbose) { strncpy(lbuf, cmd, 3); lbuf[3] = 0; line_break(); i = left_indent; left_indent = 0; strcpy(word, "**** Unknown formatter command: ."); strcat(word, lbuf); print_word(word); line_break(); left_indent = i; } i = 0; /* Treat as comment */ } switch (cmd_list[i].class) { case 1: /* Parametered commands */ return do_argvcmd(cmd_list[i].id); case 2: /* Font changers */ return do_fontwords(cmd_list[i].id / 10, cmd_list[i].id % 10, 0); case 3: /* .so */ fetch_word(); strcat(man_file, word); close_page(); if (find_page(man_file, (char *) 0) < 0) { fprintf(stderr, "Cannot open .so file %s\n", word); return -1; } ungetc('\r', ifd); break; default: do_skipeol(); if (cmd_list[i].id) return do_noargs(cmd_list[i].id); } return 0; }
static void post_aq(DECL_ARGS) { outflags &= ~(MMAN_spc | MMAN_nl); print_word(n->child != NULL && n->child->next == NULL && n->child->tok == MDOC_Mt ? ">" : "\\(ra"); }