diff -Naur a/xwd.c b/xwd.c --- xwd.c 2013-08-09 05:12:24.000000000 +0100 +++ xwd.c 2021-06-12 22:52:50.927439065 +0100 @@ -56,6 +56,11 @@ * abilities. (Xwd V7 has yet to be tested on a color machine, so * all color-related code is commented out until color support * becomes practical.) + * + * 20210612 jr. + * - modified for 'povr' RTR use. + * new option '-nfrm N' number of frames. + * modified option '-out' now basename. */ /*% @@ -138,13 +143,27 @@ return (thesign * retval); } -int -main(int argc, char **argv) -{ +static void mkFname(char *buf, + char const *base, + size_t const last, + size_t const curr) { + if (100 > last) + sprintf(buf, "%s_%02zu.xwd", base, curr); + else if (1000 > last) + sprintf(buf, "%s_%03zu.xwd", base, curr); + else + sprintf(buf, "%s_%04zu.xwd", base, curr); + return; +} + +int main(int argc, char **argv) { register int i; Window target_win; FILE *out_file = stdout; Bool frame_only = False; + size_t nframes = 0; + char *bname = NULL; + Bool eexit = False; INIT_NAME; @@ -154,6 +173,14 @@ target_win = Select_Window_Args(&argc, argv); for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-nfrm")) { + if (++i >= argc) usage(); + if (!(nframes = atoi(argv[i]))) + Fatal_Error("oops, bad number frames."); + else if (1 > nframes || 5000 < nframes) + Fatal_Error("oops, bad number frames."); + continue; + } if (!strcmp(argv[i], "-nobdrs")) { nobdrs = True; continue; @@ -166,8 +193,7 @@ usage(); if (!strcmp(argv[i], "-out")) { if (++i >= argc) usage(); - if (!(out_file = fopen(argv[i], "wb"))) - Fatal_Error("Can't open output file as specified."); + bname = argv[i]; standard_out = False; continue; } @@ -198,28 +224,38 @@ } usage(); } + + if (!nframes) Fatal_Error("oops, need number frames."); + if (!bname) Fatal_Error("oops, need base name for files."); + #ifdef WIN32 if (standard_out) _setmode(fileno(out_file), _O_BINARY); #endif - /* - * Let the user select the target window. - */ + /* Let the user select the target window. */ if (target_win == None) target_win = Select_Window(dpy, !frame_only); - /* - * Dump it! - */ - Window_Dump(target_win, out_file); + for (size_t j = 0; nframes != j; ++j) { + char fnbuf[2048] = {'\0'}; + mkFname(fnbuf, bname, nframes, j); + if (!(out_file = fopen(fnbuf,"wb"))) { + eexit = True; + perror("fopen"); + goto label_exit; + } + Window_Dump(target_win, out_file); + if (fclose(out_file)) { + eexit = True; + perror("fclose"); + goto label_exit; + } + } +label_exit: XCloseDisplay(dpy); - if (fclose(out_file)) { - perror("xwd"); - exit(1); - } - exit(0); + exit(eexit); } static int @@ -521,9 +557,9 @@ usage(void) { fprintf (stderr, -"usage: %s [-display host:dpy] [-debug] [-help] %s [-nobdrs] [-out ]", +"usage: %s [-display host:dpy] [-debug] [-help] %s [-nobdrs] -out base", program_name, "[{-root|-id |-name }]"); - fprintf (stderr, " [-xy] [-add value] [-frame]\n"); + fprintf (stderr, " [-xy] [-add value] [-frame] -nfrm N\n"); exit(1); }