int plot_arc(void *v, int x, int y, int x0, int y0, int x1, int y1) { struct plotctx *pl = v; char *p; if (!(pl->caps & _PLOT_RC)) { pl->caps |= _PLOT_RC; if (cgetstr(pl->buf, "rc", &p) > 0) pl->rc = p; } if (pl->rc) { plot_move(pl, x, y); return (_plot_out(pl, pl->rc, x0 * pl->xnum / pl->xdenom, y0 * pl->ynum / pl->ydenom, x1 * pl->xnum / pl->xdenom, y1 * pl->ynum / pl->ydenom)); #if 0 } else if (pl->flags & ARCVSLN || ((pl->caps & _PLOT_CO || cgetstr(pl->buf, "co", &p) > 0) || (pl->caps & _PLOT_LN || cgetstr(pl->buf, "ln", &p) > 0))) { /* TODO emulate through the line */ flags |= ARCVSLN; #endif } else { /* TODO emulate through the point */ errno = EOPNOTSUPP; return (-1); } return (0); }
int PlotArea::do_plot(const char *commands, bool clear) { // Discard all commands up to `G' command, if any int discard = -1; { const char *cmds = commands; while (*cmds != '\0') { if (cmds[0] == 'G' && cmds[1] == '\n') { if (pending_plots > 0) pending_plots--; discard = (cmds - commands); } while (*cmds != '\n' && *cmds != '\0') cmds++; if (*cmds != '\0') cmds++; } } // Process commands const char *cmds = commands; if (discard >= 0) { cmds += discard; assert(cmds[0] == 'G'); assert(cmds[1] == '\n'); } #if 0 // FIXME: Not thoroughly tested yet -AZ if (discard < 0 && pending_plots > 0) return discard; #endif while (cmds[0] != '\0') { const char *command_begin = cmds; // Move CMDS to the next line while (*cmds != '\0' && *cmds != '\n') cmds++; if (*cmds == '\0') break; // Command is incomplete - don't do it assert(*cmds == '\n'); cmds++; // Copy current command to a NULL-terminated string. Otherwise, // sscanf() takes far too much time. const int len_ = cmds-command_begin-1; assert(len_ >= 0); const string command_s(command_begin,len_); const char *command = command_s.chars(); switch (command[0]) { case 'V': if (win) plot_vector(command); break; case 'M': if (win) plot_move(command); break; case 'T': if (win) plot_text(command); break; case 'J': if (win) plot_justify(command); break; case 'L': if (win) plot_linetype(command); break; case 'P': if (win) plot_point(command); break; case 'G': plot_reset(command); if (win && clear) plot_clear(command); break; case 'E': case 'R': if (win) plot_nop(command); break; default: plot_unknown(command); break; } } return discard; }
static void fplt(FILE *fin) { int c; char s[256]; int xi,yi,x0,y0,x1,y1,r/*,dx,n,i*/; /*int pat[256];*/ openpl(); while((c=getc(fin)) != EOF){ switch(c){ case 'm': xi = getsi(fin); yi = getsi(fin); plot_move(xi,yi); break; case 'l': x0 = getsi(fin); y0 = getsi(fin); x1 = getsi(fin); y1 = getsi(fin); line(x0,y0,x1,y1); break; case 't': getstr(s,fin); label(s); break; case 'e': plot_erase(); break; case 'p': xi = getsi(fin); yi = getsi(fin); point(xi,yi); break; case 'n': xi = getsi(fin); yi = getsi(fin); cont(xi,yi); break; case 's': x0 = getsi(fin); y0 = getsi(fin); x1 = getsi(fin); y1 = getsi(fin); space(x0,y0,x1,y1); break; case 'a': xi = getsi(fin); yi = getsi(fin); x0 = getsi(fin); y0 = getsi(fin); x1 = getsi(fin); y1 = getsi(fin); arc(xi,yi,x0,y0,x1,y1); break; case 'c': xi = getsi(fin); yi = getsi(fin); r = getsi(fin); circle(xi,yi,r); break; case 'f': getstr(s,fin); linemod(s); break; default: fprintf(stderr, "Unknown command %c (%o)\n", c, c); break; } } closepl(); }