aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--DEPENDENCIES9
-rw-r--r--Makefile.in2
-rw-r--r--NEWS25
-rw-r--r--README22
-rw-r--r--TODO5
-rw-r--r--doc/info/chap/invoking.texinfo28
-rw-r--r--doc/info/chap/overview.texinfo11
-rw-r--r--doc/man/scrotty.126
-rw-r--r--doc/man/scrotty.sv.128
-rw-r--r--po/sv.po50
-rw-r--r--src/info.c12
-rw-r--r--src/info.h2
-rw-r--r--src/kern-linux.c11
-rw-r--r--src/kern.h7
-rw-r--r--src/pattern.c2
-rw-r--r--src/scrotty.c132
16 files changed, 196 insertions, 176 deletions
diff --git a/DEPENDENCIES b/DEPENDENCIES
index cd8cf36..d97fafc 100644
--- a/DEPENDENCIES
+++ b/DEPENDENCIES
@@ -1,16 +1,17 @@
RUNTIME DEPENDENCIES:
linux
- libc
- imagemagick (opt-out)
+ glibc (any libc with getopt_long)
+ libpng
BUILD DEPENDENCIES:
make
coreutils
- libc
- gcc (any c99 can be used if WARN in Makefile is edited)
+ glibc (any libc with getopt_long)
+ libpng
+ c99
gettext (opt-out, for internationalisation)
texinfo (opt-out, for info, pdf, dvi, ps, and html manuals)
texlive-plainextra (opt-in, for pdf, dvi, and ps manuals)
diff --git a/Makefile.in b/Makefile.in
index fd8a4ff..939647d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -50,7 +50,7 @@ PKGNAME = scrotty
# Package information.
_PROJECT = scrotty
-_VERSION = 1.1
+_VERSION = 2.0
# Used by mk/lang-c.mk
_C_STD = c99
diff --git a/NEWS b/NEWS
index 751422e..8016618 100644
--- a/NEWS
+++ b/NEWS
@@ -1,18 +1,30 @@
scrotty NEWS -*- outline -*-
-* Noteworthy changes in release 1.1 (TO BE DETERMINED) [stable]
+* Noteworthy changes in release 2.0 (TO BE DETERMINED) [stable]
** Installation changes
The installation process has changed. Please read INSTALL.
+** Dependency changes
+
+ ImageMagick is not longer used.
+
+ libpng is now required.
+
+ GCC is not required, any compiler for ISO C 99 will do.
+
+ The GNU C library, or any POSIX-compliant C standard
+ library with the getopt_long function, is now required.
+
** Improvements
The option --raw has been added. This option makes scrotty
- store the images as a portble anymap format image rather
- than as Portable Network Graphics image. With this change
- ImageMagick becomes optional, but you have to opt-out if
- you do not have it.
+ store the images as a portable anymap format image rather
+ than as Portable Network Graphics image.
+
+ The ability to pass arguments to convert(1) has been
+ removed. Utilise the --exec option instead!
Internationalisation support has been added. For the purpose
of testing, a complete Swedish translation has been included.
@@ -21,6 +33,9 @@ scrotty NEWS -*- outline -*-
The Texinfo manual lists the basics of strftime(3P).
+ The invocation syntax is less strict, and short options
+ have been added.
+
** Translations
The program and the man page has been translated to Swedish.
diff --git a/README b/README
index 2ed2e42..474d598 100644
--- a/README
+++ b/README
@@ -1,8 +1,8 @@
NAME
- scrotty 1.1-dev - Framebuffer screenshot program
+ scrotty 2.0-dev - Framebuffer screenshot program
SYNOPSIS
- scrotty [OPTION]... [FILENAME_PATTERN] [-- CONVERT_OPTION...]
+ scrotty [OPTION]... [--] [FILENAME_PATTERN]
DESCRIPTION
scrotty is a minimalist screenshoter for your framebuffers.
@@ -10,24 +10,24 @@ DESCRIPTION
scrotty is designed after scrot(1), but includes a some
improvements. Namely it does not support delaying the screenshot,
- selecting image quality or creating thumbnails, but it has
- support for adding arbitrary arguments to convert(1), which is
- used to save the image.
+ selecting image quality or creating thumbnails. That is left
+ to be done by the user with the option --exec and a a utility
+ such as convert(1).
OPTIONS
- --help
+ -h, --help
Print usage information.
- --version
+ -v, --version
Print program name and version.
- --copyright
+ -c, --copyright
Print copyright information.
- --raw
+ -r, --raw
Save in PNM rather than in PNG.
- --exec CMD
+ -e, --exec CMD
Command to run for each saved image.
SPECIAL STRINGS
@@ -65,7 +65,7 @@ RATIONALE
image of how something looks.
SEE ALSO
- scrot(1), convert(1), strftime(3), fbcat(1), setterm(1)
+ scrot(1), strftime(3), convert(1), fbcat(1), setterm(1)
Full documentation available locally via: info '(scrotty)'
diff --git a/TODO b/TODO
index fea7b41..5f2f61a 100644
--- a/TODO
+++ b/TODO
@@ -8,3 +8,8 @@ Support framebuffers with other depths.
Investigate Hurd support.
+Make a release-test script that validates that the
+build system works as expected, that the tarball
+does not contain .gitignore, and that all references
+to the version number is correct.
+
diff --git a/doc/info/chap/invoking.texinfo b/doc/info/chap/invoking.texinfo
index 25c0b25..d418fc2 100644
--- a/doc/info/chap/invoking.texinfo
+++ b/doc/info/chap/invoking.texinfo
@@ -4,26 +4,30 @@
@command{scrotty} recognises four options:
@table @option
-@item --help
+@item -h
+@itemx --help
Print usage information and exit.
-@item --version
+@item -v
+@itemx --version
Print program name and version and exit.
-@item --copyright
+@item -c
+@itemx --copyright
Print copyright information and exit.
-@item --raw
+@item -r
+@itemx --raw
Save the images in portable anymap format
-(PNM), rather than in Portable Network
-Graphics (PNG). If this option is used,
-and no arguments for @command{convert}
-is specified, @command{convert} will not
-be used, and there will be not requirement
-to have ImageMagick installed.
+(@sc{PNM}), rather than in Portable Network
+Graphics (@sc{PNG}).
-PNM images are highly compressable with
+@sc{PNM} images are highly compressable with
@command{bzip2}. Compressed images are comparable
in size with @sc{PNG},@footnote{Usually a few
bytes in difference.} and can in fact be smaller.
-@item --exec CMD
+
+@sc{PNM} is a good alternative for anything
+but storage. (Unless you compress them.)
+@item -e
+@itemx --exec CMD
Run a command for each saved image.
@end table
diff --git a/doc/info/chap/overview.texinfo b/doc/info/chap/overview.texinfo
index f5d1ff3..26765f4 100644
--- a/doc/info/chap/overview.texinfo
+++ b/doc/info/chap/overview.texinfo
@@ -10,11 +10,16 @@ rendered on the framebuffer.}
@command{scrotty} is designed after @command{scrot}, but
includes a some improvements. Namely it does not support
delaying the screenshot, selecting image quality or creating
-thumbnails, but it has support for adding arbitrary arguments
-to @command{convert} (from the ImageMagick project), which
-is used to save the image.
+thumbnails. Such operations is left to be done by the user
+with the option @option{--exec} and a utility such as
+@command{convert} (from the ImageMagick project.)
@command{scrotty} reads the data stored in the framebuffers,
convert it the @sc{PNM} images and pipes it to @command{convert}
to create @sc{PNG} images.
+@command{scrotty} can appear to be a bit slow. This is not
+@command{scrotty}'s fault. Reading a framebuffer, even if
+not processing the data, takes time. In fact, screenshots
+for @sc{X} are slow too.
+
diff --git a/doc/man/scrotty.1 b/doc/man/scrotty.1
index 430c7e2..aacb092 100644
--- a/doc/man/scrotty.1
+++ b/doc/man/scrotty.1
@@ -3,9 +3,8 @@
scrotty \- Framebuffer screenshot program
.SH SYNOPSIS
.B scrotty
-.RI [ OPTION ]...\ [ FILENAME_PATTERN ]
-[\-\-
-.IR CONVERT_OPTION ...]
+.RI [ OPTION ]...\ [\-\-]
+.RI [ FILENAME_PATTERN ]
.SH DESCRIPTION
.B scrotty
is a minimalist screenshoter for your framebuffers.
@@ -18,25 +17,26 @@ is designed after
.BR scrot (1),
but includes a some improvements. Namely it does not support
delaying the screenshot, selecting image quality or creating
-thumbnails, but it has support for adding arbitrary arguments
-to
-.BR convert (1),
-which is used to save the image.
+thumbnails. Such operations is left to be done by the user
+with the option
+.B \-\-exec
+and a utility such as
+.BR convert (1).
.SH OPTIONS
.TP
-.B \-\-help
+.B \-h ,\ \-\-help
Print usage information.
.TP
-.B \-\-version
+.B \-v ,\ \-\-version
Print program name and version.
.TP
-.B \-\-copyright
+.B \-c ,\ \-\-copyright
Print copyright information.
.TP
-.B \-\-raw
+.B \-r ,\ \-\-raw
Save in PNM rather than in PNG.
.TP
-.BR \-\-exec \ \fICMD\fP
+.BR \-e ,\ \-\-exec \ \fICMD\fP
Command to run for each saved image.
.SH "SPECIAL STRINGS"
Both the
@@ -89,8 +89,8 @@ Screenshots are useful if you want to remember something or
send an image of how something looks.
.SH "SEE ALSO"
.BR scrot (1),
-.BR convert (1),
.BR strftime (3),
+.BR convert (1),
.BR fbcat (1),
.BR setterm (1)
.PP
diff --git a/doc/man/scrotty.sv.1 b/doc/man/scrotty.sv.1
index 56fb2ce..2cc157e 100644
--- a/doc/man/scrotty.sv.1
+++ b/doc/man/scrotty.sv.1
@@ -4,9 +4,8 @@
scrotty \- Bildrutebuffertskärmsdumpsprogram
.SH ÖVERSIKT
.B scrotty
-.RI [ ALTERNATIV ]...\ [ FILNAMNSMÖNSTER ]
-[\-\-
-.IR ALTERNATIV_FÖR_CONVERT ...]
+.RI [ ALTERNATIV ]...\ [\-\-]
+.RI [ FILNAMNSMÖNSTER ]
.SH BESKRIVNING
.B scrotty
är ett minimalistiskt skärmsdumpsprogram för dina
@@ -19,25 +18,26 @@ Det finns inget stöd för
.BR scrot (1),
men har en del förbättringar: inget stöd för fördröjda
skrämdumpar, val av bildkvalitet eller stöd för att skapa
-miniatyrer, men det finns stöd för att specifiera valfria
-alternativ för
-.BR convert (1),
-som används för att spara bilden.
+miniatyrer. Sådana operations är lämnat till användaren
+att utföra med hjälp av alternativet
+.B \-\-exec
+och verktyg såsom
+.BR convert (1).
.SH ALTERNATIV
.TP
-.B \-\-help
+.B \-h ,\ \-\-help
Skriv ut burksanvisningar.
.TP
-.B \-\-version
+.B \-v ,\ \-\-version
Skriv ut programmets namn och version.
.TP
-.B \-\-copyright
+.B \-c ,\ \-\-copyright
Skriv ut upphovsrätts information.
.TP
-.B \-\-raw
+.B \-r ,\ \-\-raw
Spara som PNM-bild snarare än som PNG-bild.
.TP
-.BR \-\-exec \ \fIKMD\fP
+.BR \-e ,\ \-\-exec \ \fIKMD\fP
Kommando att köra för varje sparad bild.
.SH "SÄRSKILDA STRÄNGAR"
Både
@@ -91,8 +91,10 @@ redan fanns utan författarens kännedom.) Skärmdumpar
du vill skicka en bild på hur någonting ser hur.
.SH "SE ÄVEN"
.BR scrot (1),
+.BR strftime (3),
.BR convert (1),
-.BR strftime (3)
+.BR fbcat (1),
+.BR setterm (1)
.PP
Full dokumentation finns tillgängligt lokalt via: info \(aq(scrotty)\(aq
.SH FÖRFATTARE
diff --git a/po/sv.po b/po/sv.po
index f262086..a048ef0 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-10 16:17+0100\n"
+"POT-Creation-Date: 2015-12-10 22:45+0100\n"
"PO-Revision-Date: 2015-12-07 18:50+0100\n"
"Last-Translator: Mattias Andrée <maandree@member.fsf.org>\n"
"Language-Team: none\n"
@@ -17,30 +17,34 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
-#: src/scrotty.c:377
+#: src/scrotty.c:373
#, c-format
msgid "Saved framebuffer %i to %s.\n"
msgstr "Bildrutebuffert %i sparad till %s.\n"
-#: src/scrotty.c:467 src/scrotty.c:474
+#: src/scrotty.c:468 src/scrotty.c:472 src/scrotty.c:478
#, 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:467
-msgid "Unrecognised option."
-msgstr "Val känns inte igen."
+#: src/scrotty.c:468
+msgid "--exec is used twice."
+msgstr "--exec förkommer mer än en gång."
-#: src/scrotty.c:474
-msgid "--exec has no argument."
-msgstr "--exec saknar argument."
+#: src/scrotty.c:472
+msgid "Invalid input."
+msgstr "Ogiltig indata."
-#: src/scrotty.c:524
+#: src/scrotty.c:478
+msgid "FILENAME-PATTERN is used twice."
+msgstr "FILNAMNSMÖNSTER förekommer mer än en gång"
+
+#: src/scrotty.c:509
#, 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:534
+#: src/scrotty.c:519
#, c-format
msgid "%s: %s: %s\n"
msgstr "%s: %s: %s\n"
@@ -54,14 +58,14 @@ msgstr "%s: Kunde inte hitta någon bildrutebuffert. Om filen %s/MAKEDEV finns d
#, c-format
msgid ""
"SYNOPSIS\n"
-"\t%s [options...] [filename-pattern] [-- options-for-convert...]\n"
+"\t%s [OPTIONS...] [--] [FILENAME-PATTERN]\n"
"\n"
"OPTIONS\n"
-"\t--help Print usage information.\n"
-"\t--version Print program name and version.\n"
-"\t--copyright Print copyright information.\n"
-"\t--raw Save in PNM rather than in PNG.\n"
-"\t--exec CMD Command to run for each saved image.\n"
+"\t-h, --help Print usage information.\n"
+"\t-v, --version Print program name and version.\n"
+"\t-c, --copyright Print copyright information.\n"
+"\t-r, --raw Save in PNM rather than in PNG.\n"
+"\t-e, --exec CMD Command to run for each saved image.\n"
"\n"
"SPECIAL STRINGS\n"
"\tBoth the --exec and filename-pattern parameters can take format specifiers\n"
@@ -88,14 +92,14 @@ msgid ""
"\n"
msgstr ""
"ANVÄNDING\n"
-"\t%s [ALTERNATIV...] [FILNAMNSMÖNSTER] [-- ALTERNATIV_FÖR_CONVERT...]\n"
+"\t%s [ALTERNATIV...] [--] [FILNAMNSMÖNSTER]\n"
"\n"
"ALTERNATIV\n"
-"\t--help Skriv ut burksanvisningar.\n"
-"\t--version Skriv ut programmets namn och version.\n"
-"\t--copyright Skriv ut upphovsrätts information.\n"
-"\t--raw Spara som PNM-bild snarare än som PNG-bild.\n"
-"\t--exec KMD Kommando att köra för varje sparad bild.\n"
+"\t-h, --help Skriv ut burksanvisningar.\n"
+"\t-v, --version Skriv ut programmets namn och version.\n"
+"\t-c, --copyright Skriv ut upphovsrätts information.\n"
+"\t-r, --raw Spara som PNM-bild snarare än som PNG-bild.\n"
+"\t-e, --exec KMD Kommando att köra för varje sparad bild.\n"
"\n"
"SÄRSKILDA STRÄNGAR\n"
"\tBåde --exec och filnamnsmönstrets tar formatspecifikationsargument som\n"
diff --git a/src/info.c b/src/info.c
index 9eff7cb..36ab8f5 100644
--- a/src/info.c
+++ b/src/info.c
@@ -30,14 +30,14 @@ int
print_help (void)
{
return printf (_("SYNOPSIS\n"
- "\t%s [options...] [filename-pattern] [-- options-for-convert...]\n"
+ "\t%s [OPTIONS...] [--] [FILENAME-PATTERN]\n"
"\n"
"OPTIONS\n"
- "\t--help Print usage information.\n"
- "\t--version Print program name and version.\n"
- "\t--copyright Print copyright information.\n"
- "\t--raw Save in PNM rather than in PNG.\n"
- "\t--exec CMD Command to run for each saved image.\n"
+ "\t-h, --help Print usage information.\n"
+ "\t-v, --version Print program name and version.\n"
+ "\t-c, --copyright Print copyright information.\n"
+ "\t-r, --raw Save in PNM rather than in PNG.\n"
+ "\t-e, --exec CMD Command to run for each saved image.\n"
"\n"
"SPECIAL STRINGS\n"
"\tBoth the --exec and filename-pattern parameters can take format specifiers\n"
diff --git a/src/info.h b/src/info.h
index 1d2c652..cba9e05 100644
--- a/src/info.h
+++ b/src/info.h
@@ -20,7 +20,7 @@
# define PROGRAM_NAME "scrotty"
#endif
#ifndef PROGRAM_VERSION
-# define PROGRAM_VERSION "1.1"
+# define PROGRAM_VERSION "development-version"
#endif
diff --git a/src/kern-linux.c b/src/kern-linux.c
index af17822..28b4d4e 100644
--- a/src/kern-linux.c
+++ b/src/kern-linux.c
@@ -54,7 +54,7 @@ print_not_found_help (void)
* @param fbno The index of the framebuffer.
*/
void
-get_fbpath (char *pathbuf, int altpath, int fbno)
+get_fbpath (char *restrict pathbuf, int altpath, int fbno)
{
sprintf (pathbuf, "%s/fb%s%i", DEVDIR, (altpath ? "/" : ""), fbno);
}
@@ -70,7 +70,7 @@ get_fbpath (char *pathbuf, int altpath, int fbno)
* @return Zero on success, -1 on error.
*/
int
-measure (int fbno, char *fbpath, long *width, long *height)
+measure (int fbno, char *restrict fbpath, long *restrict width, long *restrict height)
{
static char buf[PATH_MAX];
char *delim;
@@ -124,9 +124,10 @@ measure (int fbno, char *fbpath, long *width, long *height)
* @return Zero on success, -1 on error.
*/
int
-convert_fb (FILE *file, char *buf, size_t n, size_t *adjustment)
+convert_fb (FILE *restrict file, const char *restrict buf,
+ size_t n, size_t *restrict adjustment)
{
- uint32_t *pixel;
+ const uint32_t *restrict pixel;
int r, g, b;
size_t off;
@@ -134,7 +135,7 @@ convert_fb (FILE *file, char *buf, size_t n, size_t *adjustment)
{
/* A pixel in the framebuffer is formatted as `%{blue}%{green}%{red}%{x}`
in big-endian binary, or `%{x}%{red}%{green}%{blue}` in little-endian binary. */
- pixel = (uint32_t *)(buf + off);
+ pixel = (const uint32_t *)(buf + off);
r = (*pixel >> 16) & 255;
g = (*pixel >> 8) & 255;
b = (*pixel >> 0) & 255;
diff --git a/src/kern.h b/src/kern.h
index 69eaf0b..624564c 100644
--- a/src/kern.h
+++ b/src/kern.h
@@ -39,7 +39,7 @@ void print_not_found_help (void);
* @param altpath The index of the alternative path-pattern to use.
* @param fbno The index of the framebuffer.
*/
-void get_fbpath (char *pathbuf, int altpath, int fbno);
+void get_fbpath (char *restrict pathbuf, int altpath, int fbno);
/**
* Get the dimensions of a framebuffer.
@@ -50,7 +50,7 @@ void get_fbpath (char *pathbuf, int altpath, int fbno);
* @param height Output parameter for the height of the image.
* @return Zero on success, -1 on error.
*/
-int measure (int fbno, char *fbpath, long *width, long *height);
+int measure (int fbno, char *restrict fbpath, long *restrict width, long *restrict height);
/**
* Convert read data from a framebuffer to PNM pixel data.
@@ -64,5 +64,6 @@ int measure (int fbno, char *fbpath, long *width, long *height);
* pixel is encoded.
* @return Zero on success, -1 on error.
*/
-int convert_fb (FILE *file, char *buf, size_t n, size_t *adjustment);
+int convert_fb (FILE *restrict file, const char *restrict buf,
+ size_t n, size_t *restrict adjustment);
diff --git a/src/pattern.c b/src/pattern.c
index 6912731..c766d83 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -145,7 +145,5 @@ evaluate (char *restrict buf, size_t n, const char *restrict pattern,
fail:
return -1;
-
-#undef P
}
diff --git a/src/scrotty.c b/src/scrotty.c
index c6cb3fc..da69cc9 100644
--- a/src/scrotty.c
+++ b/src/scrotty.c
@@ -16,12 +16,14 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define _GNU_SOURCE /* For getopt_long. */
#include "common.h"
#include "kern.h"
#include "info.h"
#include "pnm.h"
#include "pattern.h"
+#include <getopt.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -64,6 +66,7 @@ const char* inttable[] =
};
+
/**
* `argv[0]` from `main`.
*/
@@ -77,13 +80,6 @@ const char *execname;
const char *failure_file = NULL;
/**
- * Arguments for `convert`,
- * the output file should be printed into `convert_args[2]`.
- * `NULL` is `convert` shall not be used.
- */
-static char **convert_args = NULL;
-
-/**
* The index of the alternative path-pattern,
* for the framebuffers, to try.
*/
@@ -92,13 +88,13 @@ static int try_alt_fbpath = 0;
/**
- * Create an PNM-file that is sent to `convert` for convertion
- * to a compressed format, or directly to a file.
+ * Create an PNM-file that is sent to a conversion process,
+ * or directly to a file.
*
* @param fbname The framebuffer device.
* @param width The width of the image.
* @param height The height of the image.
- * @param fd The file descriptor connected to `convert`'s stdin.
+ * @param fd The file descriptor connected to conversion process's stdin.
* @return Zero on success, -1 on error.
*/
static int
@@ -116,7 +112,7 @@ save_pnm (const char *fbpath, long width, long height, int fd)
if (fbfd == -1)
goto fail;
- /* Create a FILE*, for writing, for the image file. */
+ /* Create a FILE *, for writing, for the image file. */
file = fdopen (fd, "w");
if (file == NULL)
goto fail;
@@ -177,10 +173,11 @@ save_pnm (const char *fbpath, long width, long height, int fd)
* @param imgname The pathname of the output image.
* @param width The width of the image.
* @param height The height of the image.
+ * @param raw Save in PNM?
* @return Zero on success, -1 on error.
*/
static int
-save (const char *fbpath, const char *imgpath, long width, long height)
+save (const char *fbpath, const char *imgpath, long width, long height, int raw)
{
int pipe_rw[2] = { -1, -1 };
pid_t pid;
@@ -188,14 +185,14 @@ save (const char *fbpath, const char *imgpath, long width, long height)
int fd = -1;
int saved_errno;
- if (convert_args == NULL)
+ if (raw)
goto no_convert;
- /* Create a pipe that for sending data into the `convert` program. */
+ /* Create a pipe that for sending data into the conversion process program. */
if (pipe (pipe_rw) < 0)
goto fail;
- /* Fork the process, the child will exec. `convert`. */
+ /* Fork the process, the child will become the conversion process. */
pid = fork ();
if (pid == -1)
goto fail;
@@ -206,7 +203,7 @@ save (const char *fbpath, const char *imgpath, long width, long height)
{
/* Close the write-end of the pipe. */
close (pipe_rw[1]);
- /* Turn the read-end of the into stdin. */
+ /* Turn the read-end of the pipe into stdin. */
if (pipe_rw[0] != STDIN_FILENO)
{
close (STDIN_FILENO);
@@ -215,8 +212,7 @@ save (const char *fbpath, const char *imgpath, long width, long height)
close (pipe_rw[0]);
}
/* Exec. `convert` to convert the PNM-image we create to a compressed image. */
- sprintf (convert_args[2], "%s", imgpath);
- execvp ("convert", convert_args);
+ execlp ("convert", "convert", DEVDIR "/stdin", imgpath, NULL);
child_fail:
perror(execname);
@@ -236,15 +232,15 @@ save (const char *fbpath, const char *imgpath, long width, long height)
/* Close the write-end of the pipe. */
close (pipe_rw[1]), pipe_rw[1] = -1;
- /* Wait for `convert` to exit. */
+ /* Wait for conversion process to exit. */
if (waitpid (pid, &status, 0) < 0)
goto fail;
- /* Return successfully if and only if `convert` did. */
+ /* Return successfully if and only if conversion did. */
return status == 0 ? 0 : -1;
- /* `convert` shall not be used: */
+ /* Conversion shall not take place: */
no_convert:
/* Open output file. */
@@ -372,7 +368,7 @@ save_fb (int fbno, int raw, const char *filepattern, const char *execpattern)
return -1;
/* Take a screenshot of the current framebuffer. */
- if (save (fbpath, imgpath, width, height) < 0)
+ if (save (fbpath, imgpath, width, height, raw) < 0)
goto fail;
fprintf (stderr, _("Saved framebuffer %i to %s.\n"), fbno, imgpath);
@@ -433,15 +429,22 @@ int
main (int argc, char *argv[])
{
#define EXIT_USAGE(MSG) \
- return fprintf (stderr, _("%s: %s. Type '%s --help' for help.\n"), execname, MSG, execname), 1
-
- int fbno, r, i, dash = argc, exec = -1, help = 0, found = 0;
- int raw = 0, version = 0, copyright = 0, filepattern = -1;
- static char convert_args_0[] = "convert";
- static char convert_args_1[] = DEVDIR "/stdin";
- static char convert_args_2[PATH_MAX];
-
- execname = argc ? *argv : "scrotty";
+ return fprintf (stderr, _("%s: %s. Type '%s --help' for help.\n"), execname, MSG, execname), 2
+#define USAGE_ASSERT(ASSERTION, MSG) \
+ do { if (!(ASSERTION)) EXIT_USAGE (MSG); } while (0)
+
+ int fbno, r, found = 0, raw = 0;
+ char *exec = NULL;
+ char *filepattern = NULL;
+ struct option long_options[] =
+ {
+ {"help", no_argument, NULL, 'h'},
+ {"version", no_argument, NULL, 'v'},
+ {"copyright", no_argument, NULL, 'c'},
+ {"raw", no_argument, NULL, 'r'},
+ {"exec", required_argument, NULL, 'e'},
+ {NULL, 0, NULL, 0 }
+ };
/* Set up for internationalisation. */
#if defined(USE_GETTEXT) && defined(PACKAGE) && defined(LOCALEDIR)
@@ -451,62 +454,44 @@ main (int argc, char *argv[])
#endif
/* Parse command line. */
- for (i = 1; i < argc; i++)
+ execname = argc ? *argv : "scrotty";
+ for (;;)
{
- if (!strcmp (argv[i], "--help")) help = 1;
- else if (!strcmp (argv[i], "--version")) version = 1;
- else if (!strcmp (argv[i], "--copyright")) copyright = 1;
- else if (!strcmp (argv[i], "--raw")) raw = 1;
- else if (!strcmp (argv[i], "--exec")) exec = ++i;
- else if (!strcmp (argv[i], "--"))
+ r = getopt_long (argc, argv, "hvcre:", long_options, NULL);
+ if (r == -1) break;
+ else if (r == 'h') return -(print_help ());
+ else if (r == 'v') return -(print_version ());
+ else if (r == 'c') return -(print_copyright ());
+ else if (r == 'r') raw = 1;
+ else if (r == 'e')
{
- dash = i + 1;
- break;
+ USAGE_ASSERT (exec == NULL, _("--exec is used twice."));
+ exec = optarg;
}
- else if ((argv[i][0] == '-') || (filepattern != -1))
- EXIT_USAGE (_("Unrecognised option."));
+ else if (r == '?')
+ EXIT_USAGE (_("Invalid input."));
else
- filepattern = i;
+ abort ();
}
-
- /* Check that --exec is valid. */
- if (exec == argc)
- EXIT_USAGE (_("--exec has no argument."));
-
- /* Was --help, --version, or --copyright used? */
- if (help) return -(print_help ());
- if (version) return -(print_version ());
- if (copyright) return -(print_copyright ());
-
- /* Create arguments for `convert`. */
- if ((!raw) || (dash < argc))
+ while (optind < argc)
{
- convert_args = alloca ((size_t)(4 + (argc - dash)) * sizeof (char*));
- convert_args[0] = convert_args_0;
- convert_args[1] = convert_args_1;
- convert_args[2] = convert_args_2;
- for (i = dash; i < argc; i++)
- convert_args[i - dash + 2] = argv[i];
- convert_args[3 + (argc - dash)] = NULL;
+ USAGE_ASSERT (filepattern == NULL, _("FILENAME-PATTERN is used twice."));
+ filepattern = argv[optind++];
}
retry:
/* Take a screenshot of each framebuffer. */
for (fbno = 0;; fbno++)
{
- r = save_fb (fbno, raw,
- (filepattern < 0 ? NULL : argv[filepattern]),
- (exec < 0 ? NULL : argv[exec]));
+ r = save_fb (fbno, raw, filepattern, exec);
if (r < 0)
goto fail;
- if (r > 0)
- {
- if (fbno) /* Perhaps framebuffer 1 is the first. */
- break;
- else
- continue;
- }
- found = 1;
+ else if (r == 0)
+ found = 1;
+ else if (fbno > 0)
+ break;
+ else
+ continue; /* Perhaps framebuffer 1 is the first. */
}
/* Did not find any framebuffer? */
@@ -535,6 +520,5 @@ main (int argc, char *argv[])
execname, strerror (errno), failure_file);
return 1;
-#undef EXIT_USAGE
}