static void write_fn_type(CTX *ctx, struct ir_fn_type *fnt, bool as_ptr, char *name) { fprintf(ctx->f, "%s ", ret_type(ctx, fnt->ret_type)); if (as_ptr) { fprintf(ctx->f, "(*%s)", name); } else { fprintf(ctx->f, "%s", name); } fprintf(ctx->f, "("); for (int n = 0; n < fnt->args->members_count; n++) { struct ir_struct_member *m = fnt->args->members[n]; if (n > 0) fprintf(ctx->f, ", "); P(ctx, "%s A%d", def_type(ctx, m->type), n); } if (fnt->vararg == IR_VARARG_C) { if (fnt->args->members_count) fprintf(ctx->f, ", "); fprintf(ctx->f, "..."); } else if (fnt->args->members_count == 0) { fprintf(ctx->f, "void"); } fprintf(ctx->f, ")"); }
static int save_csv(char *fn, buffer * buf) { int i, j, lastcell, lr; FILE *fp; int s = 0; /* only use first sheet */ strcpy(ifs, ","); if (!ask_for_str("Field separator(s):", ifs)) strcpy(ifs, ","); if ((fp = fopen(fn, "w")) == (FILE *) 0) return 1; lr = line_last_used(buf, s); for (i = 1; i <= lr; i++) { lastcell = col_last_changed(buf, s, i); for (j = 1; j <= lastcell; j++) { if (j > 1) fprintf(fp, "%c", ifs[0]); if (ret_type(buf, s, i, j) != ERROR) { fprintf(fp, "%s", ret_pvalue(NULL, buf, s, i, j, -1)); } } fprintf(fp, "\n"); } fclose(fp); return 0; } /* save */
static LISP x_get_string(LISP row, LISP col, LISP bname) { int r, c; int s; char *p; buffer *buf; r = get_c_long(row); c = get_c_long(col); if (r < 1 || r > BUFFER_ROWS || c < 1 || c > BUFFER_COLS) return NIL; if (NULLP(bname)) { buf = siag_buffer; s = siag_sht; } else if (TYPEP(bname, tc_string)) { buf = find_sheet_by_name(bname->storage_as.string.data, siag_buffer, &s); if (buf == NULL) return NIL; } else return NIL; if (ret_type(buf, s, r, c) == ERROR) p = ""; else p = ret_pvalue(NULL, buf, s, r, c, -1); return strcons(strlen(p), p); }
static LISP x_get_cell(LISP row, LISP col, LISP bname) { int r, c; char *p; buffer *buf; int s; r = get_c_long(row); c = get_c_long(col); if (r < 1 || r > BUFFER_ROWS || c < 1 || c > BUFFER_COLS) return NIL; if (NULLP(bname)) { buf = siag_buffer; s = siag_sht; } else if (TYPEP(bname, tc_string)) { buf = find_sheet_by_name(bname->storage_as.string.data, siag_buffer, &s); if (buf == NULL) return NIL; } else return NIL; switch (ret_type(buf, s, r, c)) { case STRING: p = ret_string(buf, s, r, c); return strcons(strlen(p), p); case LABEL: p = ret_text(buf, s, r, c); return strcons(strlen(p), p); case EMPTY: case ERROR: return NIL; default: return flocons(ret_val(buf, s, r, c).number); } }
static int save_txt(char *fn, buffer *buf) { int i, j, lastcell, lr; int s = 0; /* only first sheet */ FILE *fp; if ((fp = fopen(fn, "w")) == (FILE *) 0) return 1; lr = line_last_used(buf, s); for (i = 1; i <= lr; i++) { lastcell = col_last_changed(buf, s, i); for (j = 1; j <= lastcell; j++) { if (j > 1) fprintf(fp, " "); if (ret_type(buf, s, i, j) != ERROR) { fprintf(fp, "%s", ret_pvalue(NULL, buf, s, i, j, -1)); } } fprintf(fp, "\n"); } fclose(fp); return 0; }
static int col_last_changed(buffer *b, int s, int row) { int i; if (row > b->sht[s].alloc_lines) return 0; for (i = b->sht[s].alloc_cols[row]; i > 1; i--) if (ret_type(b, s, row, i) != EMPTY) break; return i; }
static double ret_number(buffer *buf, int s, int r, int c) { if (r < 1 || r > BUFFER_ROWS || c < 1 || c > BUFFER_COLS) return 0.0; switch (ret_type(buf, s, r, c)) { case STRING: case LABEL: case EMPTY: case ERROR: return 0; default: return ret_val(buf, s, r, c).number; } }
static int get_cell(ClientData clientdata, Tcl_Interp *interp, Tcl_Value *args, Tcl_Value *resultPtr) { int r = args[0].intValue; int c = args[1].intValue; int type = ret_type(siag_buffer, siag_sht, r, c); if (IS_NUMBER(type)) resultPtr->doubleValue = ret_val(siag_buffer, siag_sht, r, c).number; else resultPtr->doubleValue = 0; resultPtr->type = TCL_DOUBLE; return TCL_OK; }
/* the problem here is that we don't know the current buffer and current sheet. That information is static in siodi.c */ static double get_value(buffer *buf, int sheet, int row, int col) { if (row < 1 || row > BUFFER_ROWS || col < 1 || col > BUFFER_COLS) return 0.0; switch (ret_type(buf, sheet, row, col)) { case STRING: case LABEL: return strtod(ret_string(buf, sheet, row, col), NULL); case EMPTY: case ERROR: return 0.0; default: return ret_val(buf, sheet, row, col).number; } }
static LISP get_type(LISP bname, LISP row, LISP col) { buffer *buf; int s, t, r, c; if (NULLP (bname)) { buf = buffer_of_window(w_list); s = w_list->sht; } else { buf = find_sheet_by_name(get_c_string(bname), w_list->buf, &s); } r = get_c_long(row); c = get_c_long(col); t = ret_type(buf, s, r, c); return flocons(t); }
static int save_flat(char *fn, buffer * buf) { int i, j, lastcell, lr; int s; FILE *fp; int sw = buf->sw, sh = buf->sh, sf = std_fmt_get(buf); int intp, f; MwFmt fmt; char *taddr; property_list *p; char *used_fmt = MwCalloc(MwFormatCount+1, 1); char *used_style = MwCalloc(nstyle+1, 1); if ((fp = fopen(fn, "w")) == (FILE *) 0) return 1; /* start by saving standard values */ fprintf(fp, "# Creator: %s\n", version); fprintf(fp, ".sw %d\n", sw); fprintf(fp, ".sh %d\n", sh); fprintf(fp, ".margins %d %d %d %d %d %d\n", buf->top_margin, buf->bottom_margin, buf->left_margin, buf->right_margin, buf->header_margin, buf->footer_margin); fprintf(fp, ".paper %s %d %d %d\n", buf->paper_name, buf->paper_width, buf->paper_height, buf->orientation); fprintf(fp, ".header %s\n", buf->header); fprintf(fp, ".footer %s\n", buf->footer); fprintf(fp, ".header_on_first %d\n", buf->header_on_first); fprintf(fp, ".first_page %d\n", buf->first_page_number); fprintf(fp, ".a1_refs %d\n", buf->a1_refs); MwDecodeFormat(sf, ~0, &fmt); if (!used_style[fmt.style]) { /* haven't saved style before */ save_styles(fp, fmt.style); used_style[fmt.style] = 1; } if (!used_fmt[sf]) { /* we haven't saved this format before */ MwSaveFormats(fp, sf); used_fmt[sf] = 1; } fprintf(fp, ".nsf %d\n", sf); /* properties */ for (p = buf->p_list; p; p = p->next) { fprintf(fp, ".p%d %s\n", strlen(p->value), p->key); fwrite(p->value, strlen(p->value), 1, fp); fprintf(fp, "\n"); /* terminate last line */ } for (s = 0; s < buf->nsht; s++) { fprintf(fp, ".sheet %d %s\n", s, buf->sht[s].name); lr = line_last_used(buf, s); fprintf(fp, "# %s\n# %d lines\n#\n", fn, lr); for (i = 1; i <= buf->sht[s].used_lines; i++) { int height = cell_height(buf, s, i); if (height != sh) fprintf(fp, ".rh %d %d\n", i, height); } for (i = 1; i <= buf->sht[s].used_cols; i++) { int width = cell_width(buf, s, i); if (width != sw) fprintf(fp, ".cw %d %d\n", i, width); } for (i = 0; i < buf->sht[s].nplugin; i++) { int width, height; int n = plugin_size_get(buf->sht[s].plugin[i].ph, &width, &height); if (n != 0) continue; fprintf(fp, ".plugin %d %d %s\n", buf->sht[s].plugin[i].row, buf->sht[s].plugin[i].col, buf->sht[s].plugin[i].name); fprintf(fp, ".plugin-geometry %d %d\n", width, height); } for (i = 1; i <= lr; i++) { fprintf(fp, "# Line %d\n", i); lastcell = col_last_changed(buf, s, i, sf); for (j = 1; j <= lastcell; j++) { f = ret_format(buf, s, i, j); MwDecodeFormat(f, ~0, &fmt); if (!used_style[fmt.style]) { /* haven't saved style before */ save_styles(fp, fmt.style); used_style[fmt.style] = 1; } if (!used_fmt[f]) { /* we haven't saved this format before */ MwSaveFormats(fp, f); used_fmt[f] = 1; } switch (ret_type(buf, s, i, j)) { case EMPTY: if (f != sf) fprintf(fp, "%d %d %d\t#\n", i, j, f); break; case LABEL: fprintf(fp, "%d %d %d\t\"%s\n", i, j, f, ret_text(buf, s, i, j)); break; case EMBED: fprintf(fp, "%d %d %d\tm%s\n", i, j, f, ret_text(buf, s, i, j)); break; case MNUMBER: case MTEXT: break; /* not stored at all */ /* ERRORs and CONSTANTs are stored as EXPRESSION */ default: /* EXPRESSION */ /* Special case SIOD and C for backward compatibility. */ intp = ret_interpreter(buf, s, i, j); taddr = ret_text(buf, s, i, j); if (intp == siod_interpreter && taddr[0] == '=') { intp = C_interpreter; taddr++; } if (intp == siod_interpreter) { fprintf(fp, "%d %d %d\t=%s\n", i, j, f, taddr); } else if (intp == C_interpreter) { fprintf(fp, "%d %d %d\t==%s\n", i, j, f, taddr); } else { fprintf(fp, "%d %d %d\t+%s,%s\n", i, j, f, interpreter2name(intp), taddr); } } } } } fprintf(fp, "# End of file %s\n", fn); fclose(fp); MwFree(used_fmt); MwFree(used_style); return 0; } /* save_flat */
ret_type invert( T&& tuple, std::index_sequence<indices...> ) { return ret_type ( std::get<tuple_size - indices - 1>(std::forward<T>(tuple))... ); }