From 4977648064f7bdf5b8a8c928fe904ad296429342 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 12 Dec 2015 09:08:45 +0100 Subject: fix bug + allow piping MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- README | 2 +- TODO | 2 -- doc/info/chap/invoking.texinfo | 4 ++++ doc/man/scrotty.1 | 4 +++- doc/man/scrotty.sv.1 | 4 +++- po/sv.po | 49 +++++++++++++++++++------------------- src/info.c | 2 +- src/pattern.c | 2 +- src/scrotty.c | 54 +++++++++++++++++++++++------------------- 9 files changed, 67 insertions(+), 56 deletions(-) diff --git a/README b/README index 75d5d38..6863373 100644 --- a/README +++ b/README @@ -2,7 +2,7 @@ NAME scrotty 2.0-dev - Framebuffer screenshot program SYNOPSIS - scrotty [OPTION]... [--] [FILENAME_PATTERN] + scrotty [OPTION]... [--] [FILENAME_PATTERN | > FILE] DESCRIPTION scrotty is a minimalist screenshoter for your framebuffers. diff --git a/TODO b/TODO index 3ea40ad..42d3998 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -(maybe) include date and time by default in filenames. - Take the screenshot of the framebuffers more simultaneously. (async) Support framebuffers with other depths. diff --git a/doc/info/chap/invoking.texinfo b/doc/info/chap/invoking.texinfo index 31e0530..14588a5 100644 --- a/doc/info/chap/invoking.texinfo +++ b/doc/info/chap/invoking.texinfo @@ -31,6 +31,10 @@ In addition to these options, a filename pattern, that does not start with a dash, can be added. This filename pattern selects with what filename the image should be saved. +Alternatively, you can pipe stdout to another +program, or file, and the framebuffer will +be sent there. This requires that @option{--exec} +is unused. Both the @option{--exec} and filename pattern parameters can take format specifiers that are diff --git a/doc/man/scrotty.1 b/doc/man/scrotty.1 index 227c98d..3cc50e8 100644 --- a/doc/man/scrotty.1 +++ b/doc/man/scrotty.1 @@ -4,7 +4,9 @@ scrotty \- Framebuffer screenshot program .SH SYNOPSIS .B scrotty .RI [ OPTION ]...\ [\-\-] -.RI [ FILENAME_PATTERN ] +.RI [ FILENAME_PATTERN +| > +.IR FILE ] .SH DESCRIPTION .B scrotty is a minimalist screenshoter for your framebuffers. diff --git a/doc/man/scrotty.sv.1 b/doc/man/scrotty.sv.1 index e87fe1c..4ae5c71 100644 --- a/doc/man/scrotty.sv.1 +++ b/doc/man/scrotty.sv.1 @@ -5,7 +5,9 @@ scrotty \- Bildrutebuffertskärmsdumpsprogram .SH ÖVERSIKT .B scrotty .RI [ ALTERNATIV ]...\ [\-\-] -.RI [ FILNAMNSMÖNSTER ] +.RI [ FILNAMNSMÖNSTER +| > +.IR FIL ] .SH BESKRIVNING .B scrotty är ett minimalistiskt skärmsdumpsprogram för dina diff --git a/po/sv.po b/po/sv.po index 99d47a5..7f1e7bb 100644 --- a/po/sv.po +++ b/po/sv.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: scrotty 1.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2015-12-12 08:34+0100\n" +"POT-Creation-Date: 2015-12-12 09:08+0100\n" "PO-Revision-Date: 2015-12-07 18:50+0100\n" "Last-Translator: Mattias Andrée \n" "Language-Team: none\n" @@ -17,55 +17,55 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: src/scrotty.c:226 +#: src/scrotty.c:224 #, c-format msgid "Saved framebuffer %i to %s.\n" msgstr "Bildrutebuffert %i sparad till %s.\n" -#: src/scrotty.c:361 src/scrotty.c:364 src/scrotty.c:370 src/scrotty.c:376 -#: src/scrotty.c:380 src/scrotty.c:386 +#: src/scrotty.c:358 src/scrotty.c:361 src/scrotty.c:367 src/scrotty.c:373 +#: src/scrotty.c:377 src/scrotty.c:383 src/scrotty.c:391 #, c-format msgid "%s: %s. Type '%s --help' for help.\n" msgstr "%s: %s. Kör '%s --help' för hjälp.\n" -#: src/scrotty.c:361 -#, fuzzy +#: src/scrotty.c:358 msgid "--device is used twice" -msgstr "--exec förkommer mer än en gång." +msgstr "--device förkommer mer än en gång" -#: src/scrotty.c:364 src/scrotty.c:370 -msgid "Invalid device number, not an integer" -msgstr "" +#: src/scrotty.c:361 src/scrotty.c:367 +msgid "Invalid device number, not a non-negative integer" +msgstr "Ogiltigt enhetsnummer, måste vara ett ickenegativt heltal" -#: src/scrotty.c:376 -#, fuzzy +#: src/scrotty.c:373 msgid "--exec is used twice" -msgstr "--exec förkommer mer än en gång." +msgstr "--exec förkommer mer än en gång" -#: src/scrotty.c:380 -#, fuzzy +#: src/scrotty.c:377 msgid "Invalid input" -msgstr "Ogiltig indata." +msgstr "Ogiltig indata" -#: src/scrotty.c:386 -#, fuzzy +#: src/scrotty.c:383 msgid "FILENAME-PATTERN is used twice" msgstr "FILNAMNSMÖNSTER förekommer mer än en gång" -#: src/scrotty.c:399 +#: src/scrotty.c:391 +msgid "--exec cannot be combined with piping" +msgstr "--exec kan inte kombineras med rördragning" + +#: src/scrotty.c:403 #, c-format msgid "%s: It looks like you are inside a display server. If this is correct, what you see is probably not what you get.\n" msgstr "%s: Det ser ut som att du är innan för en grafikserver. Om detta är korrect, vad de ser är troligtvis inte vad du får.\n" -#: src/scrotty.c:409 +#: src/scrotty.c:413 #, c-format msgid "%s: %s: %s\n" msgstr "%s: %s: %s\n" -#: src/scrotty.c:417 +#: src/scrotty.c:421 #, c-format msgid "%s: The selected device does not exist.\n" -msgstr "" +msgstr "%s: Vald enhet existerar inte.\n" #: src/kern-linux.c:41 #, c-format @@ -73,10 +73,10 @@ msgid "%s: Unable to find a framebuffer. If you have a file named %s/MAKEDEV, ru msgstr "%s: Kunde inte hitta någon bildrutebuffert. Om filen %s/MAKEDEV finns ditt system, kör den med '-d /dev/fb' som root, eller testa att köra '%s'.\n" #: src/info.c:32 -#, c-format +#, fuzzy, c-format msgid "" "SYNOPSIS\n" -"\t%s [OPTIONS...] [--] [FILENAME-PATTERN]\n" +"\t%s [OPTIONS...] [--] [FILENAME-PATTERN | > FILE]\n" "\n" "OPTIONS\n" "\t-h, --help Print usage information.\n" @@ -121,6 +121,7 @@ msgstr "" "\t-e, --exec KMD Kommando att köra för varje sparad bild.\n" "\n" "\tVarje alternative kan endast användst en gång.\n" +"\n" "SÄRSKILDA STRÄNGAR\n" "\tBåde --exec och filnamnsmönstrets tar formatspecifikationsargument som\n" "\tersätts av scrotty. Det finns två typer av formatspecifikationsargument.\n" diff --git a/src/info.c b/src/info.c index a9a0d09..c95052f 100644 --- a/src/info.c +++ b/src/info.c @@ -30,7 +30,7 @@ int print_help (void) { return printf (_("SYNOPSIS\n" - "\t%s [OPTIONS...] [--] [FILENAME-PATTERN]\n" + "\t%s [OPTIONS...] [--] [FILENAME-PATTERN | > FILE]\n" "\n" "OPTIONS\n" "\t-h, --help Print usage information.\n" diff --git a/src/pattern.c b/src/pattern.c index 4075a6f..0a14dd5 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -184,9 +184,9 @@ evaluate (const char *restrict pattern, int fbno, long width, if (try_evaluate (buffer, size, pattern, fbno, width, height, path) < 0) { + size <<= 1; if (errno == ENAMETOOLONG) goto retry; - size <<= 1; goto fail; } diff --git a/src/scrotty.c b/src/scrotty.c index 0faa685..bce7036 100644 --- a/src/scrotty.c +++ b/src/scrotty.c @@ -67,7 +67,7 @@ static int try_alt_fbpath = 0; * Create an image of a framebuffer. * * @param fbname The framebuffer device. - * @param imgname The pathname of the output image. + * @param imgname The pathname of the output image, `NULL` for piping. * @param width The width of the image. * @param height The height of the image. * @param data Additional data for `convert_fb_to_png`. @@ -77,14 +77,17 @@ static int save (const char *fbpath, const char *imgpath, long width, long height, void *restrict data) { - int imgfd = -1, fbfd = -1; + int imgfd = STDOUT_FILENO, fbfd = -1, piping = (imgpath == NULL); int saved_errno; /* Open output file. */ - imgfd = open (imgpath, O_WRONLY | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); - if (imgfd == -1) - FILE_FAILURE (imgpath); + if (!piping) + { + imgfd = open (imgpath, O_WRONLY | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + if (imgfd == -1) + FILE_FAILURE (imgpath); + } /* Open the framebuffer device for reading. */ fbfd = open (fbpath, O_RDONLY); @@ -96,14 +99,15 @@ save (const char *fbpath, const char *imgpath, long width, goto fail; close (fbfd); - close (imgfd); + if (!piping) + close (imgfd); return 0; fail: saved_errno = errno; if (fbfd >= 0) close (fbfd); - if (imgfd >= 0) + if ((imgfd >= 0) && !piping) close (imgfd); errno = saved_errno; return -1; @@ -181,7 +185,7 @@ exec_image (char *flatten_args) * Take a screenshot of a framebuffer. * * @param fbno The number of the framebuffer. - * @param filepattern The pattern for the filename, `NULL` for default. + * @param filepattern The pattern for the filename, `NULL` for piping. * @param execpattern The pattern for the command to run to * process the image, `NULL` for none. * @return Zero on success, -1 on error, 1 if the framebuffer does not exist. @@ -189,13 +193,12 @@ exec_image (char *flatten_args) static int save_fb (int fbno, const char *filepattern, const char *execpattern) { - char imgpath_[sizeof ("fb.png.") + 2 * 3 * sizeof (int)]; - char *imgpath = imgpath_; + char *imgpath = NULL; char *fbpath; /* Statically allocate string is returned. */ char *execargs = NULL; long width, height; void *data = NULL; - int i, rc = 0, saved_errno = 0; + int rc = 0, saved_errno = 0; /* Get pathname for framebuffer, and stop if we have read all existing ones. */ fbpath = get_fbpath (try_alt_fbpath, fbno); @@ -207,13 +210,7 @@ save_fb (int fbno, const char *filepattern, const char *execpattern) goto fail; /* Get output pathname. */ - if (filepattern == NULL) - { - sprintf (imgpath, "fb%i.png", fbno); - for (i = 2; access (imgpath, F_OK) == 0; i++) - sprintf (imgpath, "fb%i.png.%i", fbno, i); - } - else + if (filepattern != NULL) { imgpath = evaluate (filepattern, fbno, width, height, NULL); if (imgpath == NULL) @@ -223,7 +220,8 @@ save_fb (int fbno, const char *filepattern, const char *execpattern) /* Take a screenshot of the current framebuffer. */ if (save (fbpath, imgpath, width, height, data) < 0) goto fail; - fprintf (stderr, _("Saved framebuffer %i to %s.\n"), fbno, imgpath); + if (imgpath) + fprintf (stderr, _("Saved framebuffer %i to %s.\n"), fbno, imgpath); /* Should we run a command over the image? */ if (execpattern == NULL) @@ -245,8 +243,7 @@ save_fb (int fbno, const char *filepattern, const char *execpattern) rc = -1; done: free (execargs); - if (imgpath != imgpath_) - free (imgpath); + free (imgpath); return errno = saved_errno, rc; } @@ -254,7 +251,7 @@ save_fb (int fbno, const char *filepattern, const char *execpattern) /** * Take a screenshot of all, or one, framebuffers. * - * @param filepattern The pattern for the filename, `NULL` for default. + * @param filepattern The pattern for the filename, `NULL` for piping. * @param execpattern The pattern for the command to run to * process thes image, `NULL` for none. * @param all All framebuffers? @@ -361,13 +358,13 @@ main (int argc, char *argv[]) USAGE_ASSERT (all, _("--device is used twice")); all = 0; if (!isdigit (*optarg)) - EXIT_USAGE (_("Invalid device number, not an integer")); + EXIT_USAGE (_("Invalid device number, not a non-negative integer")); errno = 0; devno_ = strtol (optarg, &p, 10); if ((devno_ == 0) && (errno == ERANGE)) devno = -1; else if (*p) - EXIT_USAGE (_("Invalid device number, not an integer")); + EXIT_USAGE (_("Invalid device number, not a non-negative integer")); else devno = (devno_ >= INT_MAX ? (INT_MAX - 1) : (int)devno_); } @@ -386,6 +383,13 @@ main (int argc, char *argv[]) USAGE_ASSERT (filepattern == NULL, _("FILENAME-PATTERN is used twice")); filepattern = argv[optind++]; } + if (filepattern == NULL) + { + if (isatty(STDOUT_FILENO)) + filepattern = "%Y-%m-%d_%H:%M:%S_$wx$h.$i.png"; + else + USAGE_ASSERT (exec == NULL, _("--exec cannot be combined with piping")); + } /* Take a screenshot of each framebuffer. */ r = save_fbs (filepattern, exec, all, devno); -- cgit v1.2.3-70-g09d2