summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-03 18:11:50 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-03 22:52:24 (GMT)
commitcd197d8d8b34e3770ec49dfdc808427b2e1f0963 (patch)
tree6d113a0a97979d52309e463554c2209fc8151ae0 /gfx
parent487c2ed78ba10bdd089009fe88f21fbc276ee3b2 (diff)
downloadeeshow-cd197d8d8b34e3770ec49dfdc808427b2e1f0963.zip
eeshow-cd197d8d8b34e3770ec49dfdc808427b2e1f0963.tar.gz
eeshow-cd197d8d8b34e3770ec49dfdc808427b2e1f0963.tar.bz2
gfx/gfx.c: we now pass a combined option string to drivers
Further changes implied by this: - drivers can no longer receive arguments, only options - drivers have to ignore options they don't recognize
Diffstat (limited to 'gfx')
-rw-r--r--gfx/cro.c22
-rw-r--r--gfx/diff.c14
-rw-r--r--gfx/fig.c13
-rw-r--r--gfx/gfx.c12
-rw-r--r--gfx/gfx.h7
5 files changed, 43 insertions, 25 deletions
diff --git a/gfx/cro.c b/gfx/cro.c
index 13b1daa..52c9f0b 100644
--- a/gfx/cro.c
+++ b/gfx/cro.c
@@ -504,13 +504,13 @@ static void setup_font(struct cro_ctx *cc)
}
-static bool cr_args(void *ctx, int argc, char *const *argv)
+static bool cr_args(void *ctx, int argc, char *const *argv, const char *opts)
{
struct cro_ctx *cc = ctx;
const char *colon;
char c;
- while ((c = getopt(argc, argv, "o:s:T")) != EOF)
+ while ((c = getopt(argc, argv, opts)) != EOF)
switch (c) {
case 'o':
colon = strchr(optarg, ':');
@@ -522,15 +522,12 @@ static bool cr_args(void *ctx, int argc, char *const *argv)
case 'T':
cc->add_toc = 0;
break;
- default:
+ case '?':
usage(*argv);
+ default:
+ break;
}
-#if 0
- if (argc != optind)
- usage(*argv);
-#endif
-
return 1;
}
@@ -617,11 +614,12 @@ static void *cr_pdf_init(void)
}
-static bool cr_pdf_args(void *ctx, int argc, char *const *argv)
+static bool cr_pdf_args(void *ctx, int argc, char *const *argv,
+ const char *opts)
{
struct cro_ctx *cc = ctx;
- if (!cr_args(cc, argc, argv))
+ if (!cr_args(cc, argc, argv, opts))
return 0;
if (cc->add_toc && cc->output_name && strcmp(cc->output_name, "-"))
return pdftoc_set_file(cc->toc, cc->output_name);
@@ -925,6 +923,8 @@ static const char *const cro_png_ext[] = { "png" };
const struct gfx_ops cro_png_ops = {
.ext = cro_png_ext,
.n_ext = ARRAY_ELEMENTS(cro_png_ext),
+ .opts = "o:s:",
+
.line = record_line,
.poly = record_poly,
.circ = record_circ,
@@ -941,6 +941,8 @@ static const char *const cro_pdf_ext[] = { "pdf" };
const struct gfx_ops cro_pdf_ops = {
.ext = cro_pdf_ext,
.n_ext = ARRAY_ELEMENTS(cro_pdf_ext),
+ .opts = "o:s:T",
+
.line = record_line,
.poly = record_poly,
.circ = record_circ,
diff --git a/gfx/diff.c b/gfx/diff.c
index d43b292..d27525b 100644
--- a/gfx/diff.c
+++ b/gfx/diff.c
@@ -150,7 +150,7 @@ static void *diff_init(void)
}
-static bool diff_args(void *ctx, int argc, char *const *argv)
+static bool diff_args(void *ctx, int argc, char *const *argv, const char *opts)
{
struct diff *diff = ctx;
const char *colon;
@@ -166,7 +166,7 @@ static bool diff_args(void *ctx, int argc, char *const *argv)
sch_init(&new_sch, 0);
lib_init(&new_lib);
- while ((c = getopt(argc, argv, "o:s:")) != EOF)
+ while ((c = getopt(argc, argv, opts)) != EOF)
switch (c) {
case 'o':
colon = strchr(optarg, ':');
@@ -175,8 +175,10 @@ static bool diff_args(void *ctx, int argc, char *const *argv)
case 's':
diff->scale = atof(optarg) * DEFAULT_SCALE;
break;
- default:
+ case '?':
usage(*argv);
+ default:
+ break;
}
if (argc - optind < 1)
@@ -215,7 +217,7 @@ static bool diff_args(void *ctx, int argc, char *const *argv)
suppress_page_layout = 1;
diff->gfx = gfx_init(&cro_img_ops);
- if (!gfx_args(diff->gfx, argc, argv))
+ if (!gfx_args(diff->gfx, argc, argv, opts))
goto fail_open;
sch_render(new_sch.sheets, diff->gfx);
diff->new_gfx = diff->gfx;
@@ -224,7 +226,7 @@ static bool diff_args(void *ctx, int argc, char *const *argv)
lib_free(&new_lib);
diff->gfx = gfx_init(&cro_img_ops);
- if (!gfx_args(diff->gfx, argc, argv))
+ if (!gfx_args(diff->gfx, argc, argv, opts))
goto fail_open;
return 1;
@@ -508,6 +510,8 @@ void diff_to_canvas(cairo_t *cr, int cx, int cy, float scale,
const struct gfx_ops diff_ops = {
+ .opts = "o:s:",
+
.line = diff_line,
.poly = diff_poly,
.circ = diff_circ,
diff --git a/gfx/fig.c b/gfx/fig.c
index c0fa470..021321e 100644
--- a/gfx/fig.c
+++ b/gfx/fig.c
@@ -288,7 +288,7 @@ static void *fig_init(void)
}
-static bool fig_args(void *ctx, int argc, char *const *argv)
+static bool fig_args(void *ctx, int argc, char *const *argv, const char *opts)
{
struct fig_ctx *fig = ctx;
static char *buf = NULL;
@@ -302,7 +302,7 @@ static bool fig_args(void *ctx, int argc, char *const *argv)
FILE *file;
int lines_to_colors = 8;
- while ((c = getopt(argc, argv, "o:t:D:")) != EOF)
+ while ((c = getopt(argc, argv, opts)) != EOF)
switch (c) {
case 'o':
colon = strchr(optarg, ':');
@@ -318,13 +318,12 @@ static bool fig_args(void *ctx, int argc, char *const *argv)
vars = realloc_type_n(vars, const char *, n_vars);
vars[n_vars - 1] = optarg;
break;
- default:
+ case '?':
usage(*argv);
+ default:
+ break;
}
- if (argc != optind)
- usage(*argv);
-
if (output && strcmp(output, "-")) {
fig->file = fopen(output, "w");
if (!fig->file)
@@ -377,6 +376,8 @@ static const char *const fig_ext[] = { "fig" };
const struct gfx_ops fig_ops = {
.ext = fig_ext,
.n_ext = ARRAY_ELEMENTS(fig_ext),
+ .opts = "o:t:D:",
+
.line = fig_line,
.rect = fig_rect,
.poly = fig_poly,
diff --git a/gfx/gfx.c b/gfx/gfx.c
index 2599131..e49160c 100644
--- a/gfx/gfx.c
+++ b/gfx/gfx.c
@@ -121,10 +121,18 @@ struct gfx *gfx_init(const struct gfx_ops *ops)
}
-bool gfx_args(struct gfx *gfx, int argc, char *const *argv)
+bool gfx_args(struct gfx *gfx, int argc, char *const *argv, const char *opts)
{
+ char *combined = (char *) opts;
+ bool res;
+
+ if (gfx->ops->opts)
+ alloc_printf(&combined, "%s%s", opts, gfx->ops->opts);
optind = 0;
- return gfx->ops->args && gfx->ops->args(gfx->user, argc, argv);
+ res = gfx->ops->args && gfx->ops->args(gfx->user, argc, argv, combined);
+ if (gfx->ops->opts)
+ free(combined);
+ return res;
}
diff --git a/gfx/gfx.h b/gfx/gfx.h
index da28b6b..2930f5f 100644
--- a/gfx/gfx.h
+++ b/gfx/gfx.h
@@ -24,6 +24,8 @@ struct gfx;
struct gfx_ops {
const char *const *ext;
int n_ext;
+ const char *opts;
+
void (*line)(void *ctx, int sx, int sy, int ex, int ey,
int color, unsigned layer);
void (*rect)(void *ctx, int sx, int sy, int ex, int ey,
@@ -42,8 +44,9 @@ struct gfx_ops {
int points, const int x[points], const int y[points]);
unsigned (*text_width)(void *ctx, const char *s, unsigned size,
enum text_style style);
+
void *(*init)(void);
- bool (*args)(void *ctx, int argc, char *const *argv);
+ bool (*args)(void *ctx, int argc, char *const *argv, const char *opts);
void (*sheet_name)(void *ctx, const char *name);
void (*new_sheet)(void *ctx);
int (*end)(void *ctx);
@@ -74,7 +77,7 @@ unsigned gfx_text_width(struct gfx *gfx, const char *s, unsigned size,
/* inititalization and termination */
struct gfx *gfx_init(const struct gfx_ops *ops);
-bool gfx_args(struct gfx *gfx, int argc, char *const *argv);
+bool gfx_args(struct gfx *gfx, int argc, char *const *argv, const char *opts);
void gfx_sheet_name(struct gfx *gfx, const char *name);
void gfx_new_sheet(struct gfx *gfx);