···9191 { 'm', 1, "merge", "filename", "Merge an image" },
9292 { 'n', 1, "new-dos", "size", "Create a standard image of <size> KiB" },
9393 { 'N', 2, "new", "type size", "Create a standard image of <size> KiB" },
9494- { 'o', 1, "output", "filename", "Set the output file name [none]" },
9494+ { 'o', 1, "output", "filename", "Save to an output file [none]" },
9595 { 'O', 1, "output-format", "format", "Set the output format [auto]" },
9696 { 'p', 1, "operation", "name [...]", "Perform an operation" },
9797 { 'r', 3, "record", "c h s", "Select sectors [all all all]" },
···111111{
112112 pce_getopt_help (
113113 "psi: convert and modify PCE sector image files",
114114- "usage: psi [options] [input] [options] [output]",
114114+ "usage: psi [options] [input] [options] [output...]",
115115 opts
116116 );
117117···601601}
602602603603static
604604-int psi_save_image (psi_img_t *img, const char *fname)
604604+int psi_save_image (psi_img_t **img, const char *fname)
605605{
606606 int r;
607607 unsigned fmt;
···610610 fprintf (stderr, "%s: save image to %s\n", arg0, fname);
611611 }
612612613613+ if (*img == NULL) {
614614+ *img = psi_img_new();
615615+616616+ if (*img == NULL) {
617617+ return (1);
618618+ }
619619+ }
620620+613621 if (strcmp (fname, "-") == 0) {
614622 fmt = par_fmt_out;
615623···617625 fmt = PSI_FORMAT_PSI;
618626 }
619627620620- r = psi_save_fp (stdout, img, fmt);
628628+ r = psi_save_fp (stdout, *img, fmt);
621629 }
622630 else {
623623- r = psi_save (fname, img, par_fmt_out);
631631+ r = psi_save (fname, *img, par_fmt_out);
624632 }
625633626634 if (r) {
···711719 int r;
712720 char **optarg;
713721 psi_img_t *img;
714714- const char *out;
715722716723 arg0 = argv[0];
717724718725 img = NULL;
719719- out = NULL;
720726721727 while (1) {
722728 r = pce_getopt (argc, argv, &optarg, opts);
···857863 break;
858864859865 case 'o':
860860- out = optarg[0];
866866+ if (psi_save_image (&img, optarg[0])) {
867867+ return (1);
868868+ }
861869 break;
862870863871 case 'O':
···933941 return (1);
934942 }
935943 }
936936- else if (out == NULL) {
937937- out = optarg[0];
938938- }
939944 else {
940940- fprintf (stderr, "%s: unknown option (%s)\n",
941941- arg0, optarg[0]
942942- );
943943-944944- return (1);
945945+ if (psi_save_image (&img, optarg[0])) {
946946+ return (1);
947947+ }
945948 }
946949 break;
947950···950953 }
951954 }
952955953953- if ((img != NULL) && (out != NULL)) {
954954- if (psi_save_image (img, out)) {
955955- return (1);
956956- }
956956+ if (img != NULL) {
957957+ psi_img_del (img);
957958 }
958959959960 return (0);
+3-4
src/utils/psi/psi.1
···11-.TH PSI 1 "2023-11-30" "HH" "pce"
11+.TH PSI 1 "2024-01-20" "HH" "pce"
22\
33.SH NAME
44psi \- convert and modify PCE sector image files
5566.SH SYNOPSIS
77-.BI psi " [options] [input-file] [options] [output-file]"
77+.BI psi " [options] [input-file] [options] [output-file...]"
8899.SH DESCRIPTION
1010\fBpsi\fR(1) is used to modify and convert sector images
···186186\
187187.TP
188188.BI "-o, --output " filename
189189-Set the output file name. Before exiting, the current image will
190190-be written to this file.
189189+Write the current image to the output file \fIfilename\fR.
191190\
192191.TP
193192.BI "-O, --output-format " format