summaryrefslogtreecommitdiff
path: root/gfx
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-03 22:50:21 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-03 22:52:24 (GMT)
commit1eebec29e302f07a77cfcfa6db5a08dedc727eda (patch)
treef1fa58fa6bc4b3b25074ca411de9a355d22bfa3d /gfx
parentf84e0bd6b07b7e75e47570b8e16ae6dcd9f40d93 (diff)
downloadeeshow-1eebec29e302f07a77cfcfa6db5a08dedc727eda.zip
eeshow-1eebec29e302f07a77cfcfa6db5a08dedc727eda.tar.gz
eeshow-1eebec29e302f07a77cfcfa6db5a08dedc727eda.tar.bz2
gfx/diff.c (diff_args): move "new" file processing to diff_process_file
Diffstat (limited to 'gfx')
-rw-r--r--gfx/diff.c102
1 files changed, 56 insertions, 46 deletions
diff --git a/gfx/diff.c b/gfx/diff.c
index d27525b..824b37f 100644
--- a/gfx/diff.c
+++ b/gfx/diff.c
@@ -150,55 +150,31 @@ static void *diff_init(void)
}
-static bool diff_args(void *ctx, int argc, char *const *argv, const char *opts)
+static void *diff_process_file(struct diff *diff, struct file_names *file_names,
+ int argc, char *const *argv, const char *opts)
{
- struct diff *diff = ctx;
- const char *colon;
- char c;
- unsigned i;
- struct file_names file_names;
- struct file_names *fn = &file_names;
+ struct file_names *fn = file_names;
struct sch_ctx new_sch;
struct file pro_file;
struct file sch_file;
struct lib new_lib;
+ unsigned i;
sch_init(&new_sch, 0);
lib_init(&new_lib);
- while ((c = getopt(argc, argv, opts)) != EOF)
- switch (c) {
- case 'o':
- colon = strchr(optarg, ':');
- diff->output_name = colon ? colon + 1 : optarg;
- break;
- case 's':
- diff->scale = atof(optarg) * DEFAULT_SCALE;
- break;
- case '?':
- usage(*argv);
- default:
- break;
- }
-
- if (argc - optind < 1)
- usage(*argv);
-
- classify_files(&file_names, argv + optind, argc - optind);
- if (!file_names.pro && !file_names.sch)
- fatal("project or top sheet name required");
- if (file_names.pro) {
- if (!file_open(&pro_file, file_names.pro, NULL))
+ if (file_names->pro) {
+ if (!file_open(&pro_file, file_names->pro, NULL))
return 0;
- fn = pro_parse_file(&pro_file, &file_names);
+ fn = pro_parse_file(&pro_file, file_names);
if (!fn) {
file_close(&pro_file);
- free_file_names(&file_names);
- return 0;
+ free_file_names(file_names);
+ return NULL;
}
}
- if (!file_open(&sch_file, fn->sch, file_names.pro ? &pro_file : NULL))
+ if (!file_open(&sch_file, fn->sch, file_names->pro ? &pro_file : NULL))
goto fail_open;
for (i = 0 ; i != fn->n_libs; i++)
if (!lib_parse(&new_lib, fn->libs[i], &sch_file))
@@ -206,37 +182,71 @@ static bool diff_args(void *ctx, int argc, char *const *argv, const char *opts)
if (!sch_parse(&new_sch, &sch_file, &new_lib, NULL))
goto fail_parse;
file_close(&sch_file);
- if (file_names.pro)
+ if (file_names->pro)
file_close(&pro_file);
- if (fn != &file_names) {
+ if (fn != file_names) {
free_file_names(fn);
free(fn);
}
- free_file_names(&file_names);
-
- suppress_page_layout = 1;
diff->gfx = gfx_init(&cro_img_ops);
if (!gfx_args(diff->gfx, argc, argv, opts))
goto fail_open;
sch_render(new_sch.sheets, diff->gfx);
- diff->new_gfx = diff->gfx;
sch_free(&new_sch);
lib_free(&new_lib);
- diff->gfx = gfx_init(&cro_img_ops);
- if (!gfx_args(diff->gfx, argc, argv, opts))
- goto fail_open;
-
- return 1;
+ return diff->gfx;
fail_parse:
file_close(&sch_file);
fail_open:
sch_free(&new_sch);
lib_free(&new_lib);
- return 0;
+ return NULL;
+}
+
+
+static bool diff_args(void *ctx, int argc, char *const *argv, const char *opts)
+{
+ struct diff *diff = ctx;
+ const char *colon;
+ char c;
+ struct file_names file_names;
+
+ while ((c = getopt(argc, argv, opts)) != EOF)
+ switch (c) {
+ case 'o':
+ colon = strchr(optarg, ':');
+ diff->output_name = colon ? colon + 1 : optarg;
+ break;
+ case 's':
+ diff->scale = atof(optarg) * DEFAULT_SCALE;
+ break;
+ case '?':
+ usage(*argv);
+ default:
+ break;
+ }
+
+ if (argc - optind < 1)
+ usage(*argv);
+
+ suppress_page_layout = 1;
+
+ classify_files(&file_names, argv + optind, argc - optind);
+ if (!file_names.pro && !file_names.sch)
+ fatal("project or top sheet name required");
+
+ diff->new_gfx = diff_process_file(diff, &file_names, argc, argv, opts);
+ free_file_names(&file_names);
+
+ diff->gfx = gfx_init(&cro_img_ops);
+ if (!diff->gfx)
+ return 0;
+
+ return gfx_args(diff->gfx, argc, argv, opts);
}