pax_global_header00006660000000000000000000000064135265047310014520gustar00rootroot0000000000000052 comment=b43ce94b072e7cd1f0c22546fc2bcd43fe1999ab scrot-1.2/000077500000000000000000000000001352650473100125145ustar00rootroot00000000000000scrot-1.2/.gitignore000066400000000000000000000002641352650473100145060ustar00rootroot00000000000000*.in aclocal.m4 autom4te.cache compile configure depcomp install-sh missing Makefile config.* src/.deps src/Makefile src/config.h src/scrot_config.h src/stamp-h1 src/*.o src/scrot scrot-1.2/AUTHORS000066400000000000000000000003731352650473100135670ustar00rootroot00000000000000Principle author. Tom Gilbert (giblet) Since 2019, this source code is being maintained by: Joao Eriberto Mota Filho Daniel T. Borelli and some people sending patches! scrot-1.2/CONTRIBUTING.md000066400000000000000000000021111352650473100147400ustar00rootroot00000000000000## HOW TO CONTRIBUTE TO SCROT DEVELOPMENT scrot is available at https://github.com/resurrecting-open-source-projects/scrot If you are interested in contribute to scrot development, please, follow the following steps: 1. Send a patch that fix an issue or that implement a new feature. Alternatively, you can do a 'pull request'[1] in GitHub. [1] https://help.github.com/articles/about-pull-requests 2. Ask for join to the scrot project in GitHub, if you want to work officially. Note that this second step is not compulsory. However, to accept you in project, is needed a minimum previous collaboration. To find issues and bugs to fix, you can check these addresses: - https://github.com/resurrecting-open-source-projects/scrot - https://bugs.debian.org/cgi-bin/pkgreport.cgi?dist=unstable;package=scrot - https://bugs.launchpad.net/ubuntu/+source/scrot/+bugs - https://apps.fedoraproject.org/packages/scrot/bugs - https://bugs.gentoo.org/buglist.cgi?quicksearch=scrot If you want to join, please make a contact. -- Eriberto, Tue, 12 Feb 2019 22:50:53 -0200. scrot-1.2/COPYING000066400000000000000000000021701352650473100135470ustar00rootroot00000000000000Copyright (C) 1999,2000 Tom Gilbert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. scrot-1.2/ChangeLog000066400000000000000000000172421352650473100142740ustar00rootroot00000000000000Sun Aug 19 08:35:00 -03:00 2019 Joao Eriberto Mota Filho Version 1.2 [ Daniel T. Borelli ] * Changed the cursor to indicate the selection mode. * Fixed GCC >=8.0 warning: -Wstringop-truncation. * Evaluate return of strftime. [ Jade Auer ] * Added a gitignore to prevent accidentally including any files generated by autotools. [ Santhosh Raju ] * Fixes ambiguous else warning by providing proper braces for if in src/getopt.c. * Fixed missing warnings. [ Joao Eriberto Mota Filho ] * Added rights for Santhosh Raju. * Prepare for new release. Tue Jul 11 23:45:00 -03:00 2019 Joao Eriberto Mota Filho Version 1.1.1 [ Daniel T. Borelli ] * Update manpage and help. [ Joao Eriberto Mota Filho ] * New release. Tue Jul 09 18:51:00 -03:00 2019 Joao Eriberto Mota Filho Version 1.1 [ Daniel T. Borelli ] * Added (-n, --note) to draw a text. * Added (-l, --line) to define the line to use to select an area to capture. [ Jade Auer ] * Added a specifier ($a) to embed hostname in output file. [ Joao Eriberto Mota Filho ] * Added a check for autoconf-archive presence in configure.ac. * Added rights for Jade. * Adjusted Makefile.am to remove src/scrot_config.h when distclean. * Updated manpage. * Final adjustments for a new release. * Several tests in Debian. Sun Jun 11 11:01:00 -03:00 2019 Joao Eriberto Mota Filho Version 1.0 [ Daniel Lublin ] * Added EXIT_FAILURE when are no arguments required by some options. Fix Debian bug #685173. * Improved the manpage to show undocumented options. [ Daniel T. Borelli ] * Added option: --overwrite or -o. Now, by default do not overwrite the file. Fix Debian bug #807139. * Added support to grab mouse pointer (-p option). Fix Ubuntu bug #1698375. * Added support to freeze the screen when selection is activated (-f option). * Do not use gib_eprintf in calls to X11 functions. Fix Ubuntu bug #1523212. * Fix: scrot can't save files without extension. Fix Ubuntu bug #148659. * Fix: scrot don't complain about invalid numeric argument. Fix Ubuntu bug #371784. * Fixed some compiling warnings. [ Joao Eriberto Mota Filho ] * Final adjustments for a new release. * Several tests in Debian. * Updated AUTHORS file. Tue Feb 12 19:06:11 -03:00 2019 Joao Eriberto Mota Filho Version 0.9 * Added --autoselect rectangle option. Thanks to Stoney Sauce . * Added --focused option. Thanks to James Cameron . * Added an autogen.sh file. * Added some explanation about how to help the project. * Character cleanup for UTF-8 compatibility. Thanks to William Vera . * Fixed a missing option for beep prevention. Thanks to Ibragimov Rinat . * Fixed spelling errors in final binary. Thanks to William Vera . * Improved the autotools (acinclude.m4, configure.ac, Makefile.am and src/Makefile.am). * Improved the GCC hardening. * Prevent arbitrary long file names. Thanks to George Danchev . * Several fixes in manpage. Wed Mar 12 13:20:11 GMT 2003 Tom Gilbert * Patch from Claes Nasten * Enhances thumbnail related options: "First, specifying -t would break the $f param to -exec. Second, the thumbnail and the screenshot got different timestamps. Third, one weren't able to specify geometry with -t. I fixed those and added, $m ( mini, instead of $t as it was taken ) so that one can do. $ scrot -t 91x0 -e 'echo $f,$m' 2003-03-08-104735_800x600_scrot.png,2003-03-08-104735_91x68_scrot-thumb.png` About the geometry, having either the width or height set to 0 makes it fill in the other pertaining the aspect ratio. " * Once I update the docs I'll release 0.8 Tue Feb 25 13:13:03 GMT 2003 Tom Gilbert * Update for latest giblib. Requires latest release now. * release 0.7 Sat Feb 23 12:37:29 GMT 2002 Tom Gilbert * Patch from Eric Z. Ayers * Changes the cursor to a bottom left corner when you start to drag to select a grab region. Thu Jan 11 17:43:19 2001 Tom Gilbert * Patch from Michael Roberts to add -t, --thumb option to generate thumbnails. I modified it a little, specify the percentage size of the thumbnail on the command line. Mon Dec 4 23:46:03 2000 Tom Gilbert * Added -m, --multidisp, which is for multiple heads (not xinerama) grabs shots from each and joins them together. * Fixed doing the string escapes when saving files. My bad. Sun Nov 12 15:16:40 2000 Tom Gilbert * Now uses giblib. You'll need the very latest giblib from CVS as of right now. Sun Nov 5 02:17:57 2000 Tom Gilbert * Beep when about to take the shot. * Added -b, --border to grab wm borders too. * Ungrab mouse, keyboard before sleeping for --delay. * -e 'feh &f' is not intuitive. Can't use '%' cos that's reserved for strftime, so now the internal format specifiers are prefixed '$'. Trouble is, you now _must_ use '', not "", or the shell will interpret the $ sign and perform variable substitution. Suggestions? * Purged boring debugging shit. Mon Oct 30 18:54:05 2000 Tom Gilbert * I can't be arsed to type all this again, so here's the new manpage entries: * If [file] is not specified, a date-stamped file will be dropped in the current directory. * SPECIAL STRINGS Both the --exec and filename parameters can take format specifiers that are expanded by scrot when encountered. There are two types of format specifier. Characters preceded by a '%' are interpreted by strftime(2). See man strftime for examples. These options may be used to refer to the current date and time. The second kind are internal to scrot and are prefixed by '&' The following specifiers are recognised: &f image path/filename (ignored when used in the filename) &n image name (ignored when used in the filename) &s image size (bytes) (ignored when used in the filename) &p image pixel size &w image width &h image height &t image format && prints a literal '&' \n prints a newline (ignored when used in the filename) EXAMPLE scrot '%Y-%m-%d_&wx&h.png' -e 'mv &f ~/shots/' This would create a file called something like 2000-10-30_2560x1024.png and move it to your shots directory. Sun Oct 29 01:02:16 2000 Tom Gilbert * Added -q, --quality for setting compression quality. Fri Oct 27 21:01:45 2000 Tom Gilbert * Added -s, --select. Let's you pick which window to grab by clicking on it, or you can draw a rectangle and grab that area :-) Also, while scrot has the mouse grabbed, hitting any key will cancel the shot and release it. * Plus, something import won't do, if you set a delay, you can choose the window or area first, then the delay occurs before the shot is taken. Thu Oct 26 20:37:08 2000 Tom Gilbert * Patch from richlowe to show countdown with delay (-c, --count). Cheers bud. Thu Oct 26 15:22:22 2000 Tom Gilbert * Added -d, --delay option to wait before shooting. Thu Oct 26 14:09:52 2000 Tom Gilbert * Created scrot. scrot-1.2/Makefile.am000066400000000000000000000042211352650473100145470ustar00rootroot00000000000000# Copyright 1999-2000 Tom Gilbert # Copyright 2015-2019 Joao Eriberto Mota Filho # Copyright 2019 Daniel T. Borelli # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies of the Software and its documentation and acknowledgment shall be # given in the documentation and software packages that this Software was # used. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ## Process this file with automake to produce Makefile.in AUTOMAKE_OPTIONS = 1.4 foreign # A list of all the files in the current directory which can be regenerated MAINTAINERCLEANFILES = Makefile.in AM_LDFLAGS = -L/usr/X11R6/lib -L/usr/lib -L/usr/local/lib AM_CPPFLAGS = -I/usr/X11R6/include \ $(X_CFLAGS) -I$(prefix)/include -I$(includedir) -I. man_MANS = man/scrot.1 #docs_DATA = README AUTHORS ChangeLog TODO #docsdir = $(prefix)/doc/scrot EXTRA_DIST = \ scrot.spec scrot.1 SUBDIRS = src distclean-local: -rm -rf autom4te.cache/ -rm -f *~ \ src/*~ \ aclocal.m4 \ compile \ configure \ depcomp \ install-sh \ Makefile.in \ missing \ src/config.h.in \ src/Makefile.in \ src/scrot_config.h scrot-1.2/README000066400000000000000000000032721352650473100134000ustar00rootroot00000000000000SCReenshOT - command line screen capture utility ================================================ scrot (SCReenshOT) is a simple command line screen capture utility that uses imlib2 to grab and save images. Multiple image formats are supported through imlib2's dynamic saver modules. Some features of the scrot: - support to multiple image formats (JPG, PNG, GIF, etc.). - optimization of the screen shots image quality. - capture a specific window or a rectangular area on the screen with the help of switch. scrot also can be used to monitor a desktop PC in admin absent and register unwanted activities. BUILD ===== scrot depends of the following libraries/artifacts to build: - autoconf-archive - giblib - imlib2 - libtool - libxcursor - libxfixes To build, run the following commands: $ ./autogen.sh $ ./configure $ make # make install To return to original source code you can use '$ make distclean' command. HELP THIS PROJECT ================= scrot needs your help. If you are a programmer and if you wants to help a nice project, this is your opportunity. scrot was imported from some tarballs (the original homepage and developers are inactive). After this, all patches found in Debian project and other places for this program were applied. All initial work was registered in ChangeLog file (version 0.9 and later releases). scrot is being packaged in Debian[1]. If you are interested to help scrot, read the CONTRIBUTING.md file. [1] https://tracker.debian.org/pkg/scrot AUTHOR ====== scrot was originally developed by Tom Gilbert under MIT-advertising license. Currently, source code and newer versions are available at https://github.com/resurrecting-open-source-projects/scrot scrot-1.2/TODO000066400000000000000000000000711352650473100132020ustar00rootroot00000000000000There has to be some way I can add pr0n to this thing... scrot-1.2/acinclude.m4000066400000000000000000000135261352650473100147140ustar00rootroot00000000000000dnl @synopsis AC_PATH_GENERIC(LIBRARY [, MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) dnl dnl Runs a LIBRARY-config script and defines LIBRARY_CFLAGS and LIBRARY_LIBS dnl dnl The script must support `--cflags' and `--libs' args. dnl If MINIMUM-VERSION is specified, the script must also support the dnl `--version' arg. dnl If the `--with-library-[exec-]prefix' arguments to ./configure are given, dnl it must also support `--prefix' and `--exec-prefix'. dnl (In other words, it must be like gtk-config.) dnl dnl For example: dnl dnl AC_PATH_GENERIC(Foo, 1.0.0) dnl dnl would run `foo-config --version' and check that it is at least 1.0.0 dnl dnl If so, the following would then be defined: dnl dnl FOO_CFLAGS to `foo-config --cflags` dnl FOO_LIBS to `foo-config --libs` dnl dnl At present there is no support for additional "MODULES" (see AM_PATH_GTK) dnl (shamelessly stolen from gtk.m4 and then hacked around a fair amount) dnl dnl @author Angus Lees dnl @version $Id: acinclude.m4,v 1.1 2001/08/08 20:23:52 gilbertt Exp $ AC_DEFUN([AC_PATH_GENERIC], [dnl dnl we're going to need uppercase, lowercase and user-friendly versions of the dnl string `LIBRARY' pushdef([UP], translit([$1], [a-z], [A-Z]))dnl pushdef([DOWN], translit([$1], [A-Z], [a-z]))dnl dnl dnl Get the cflags and libraries from the LIBRARY-config script dnl AC_ARG_WITH(DOWN-prefix,[ --with-]DOWN[-prefix=PFX Prefix where $1 is installed (optional)], DOWN[]_config_prefix="$withval", DOWN[]_config_prefix="") AC_ARG_WITH(DOWN-exec-prefix,[ --with-]DOWN[-exec-prefix=PFX Exec prefix where $1 is installed (optional)], DOWN[]_config_exec_prefix="$withval", DOWN[]_config_exec_prefix="") if test x$DOWN[]_config_exec_prefix != x ; then DOWN[]_config_args="$DOWN[]_config_args --exec-prefix=$DOWN[]_config_exec_prefix" if test x${UP[]_CONFIG+set} != xset ; then UP[]_CONFIG=$DOWN[]_config_exec_prefix/bin/DOWN-config fi fi if test x$DOWN[]_config_prefix != x ; then DOWN[]_config_args="$DOWN[]_config_args --prefix=$DOWN[]_config_prefix" if test x${UP[]_CONFIG+set} != xset ; then UP[]_CONFIG=$DOWN[]_config_prefix/bin/DOWN-config fi fi AC_PATH_PROG(UP[]_CONFIG, DOWN-config, no) ifelse([$2], , AC_MSG_CHECKING(for $1), AC_MSG_CHECKING(for $1 - version >= $2) ) no_[]DOWN="" if test "$UP[]_CONFIG" = "no" ; then no_[]DOWN=yes else UP[]_CFLAGS="`$UP[]_CONFIG $DOWN[]_config_args --cflags`" UP[]_LIBS="`$UP[]_CONFIG $DOWN[]_config_args --libs`" ifelse([$2], , ,[ DOWN[]_config_major_version=`$UP[]_CONFIG $DOWN[]_config_args \ --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'` DOWN[]_config_minor_version=`$UP[]_CONFIG $DOWN[]_config_args \ --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'` DOWN[]_config_micro_version=`$UP[]_CONFIG $DOWN[]_config_args \ --version | sed 's/[[^0-9]]*\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'` DOWN[]_wanted_major_version="regexp($2, [\<\([0-9]*\)], [\1])" DOWN[]_wanted_minor_version="regexp($2, [\<\([0-9]*\)\.\([0-9]*\)], [\2])" DOWN[]_wanted_micro_version="regexp($2, [\<\([0-9]*\).\([0-9]*\).\([0-9]*\)], [\3])" # Compare wanted version to what config script returned. # If I knew what library was being run, i'd probably also compile # a test program at this point (which also extracted and tested # the version in some library-specific way) if test "$DOWN[]_config_major_version" -lt \ "$DOWN[]_wanted_major_version" \ -o \( "$DOWN[]_config_major_version" -eq \ "$DOWN[]_wanted_major_version" \ -a "$DOWN[]_config_minor_version" -lt \ "$DOWN[]_wanted_minor_version" \) \ -o \( "$DOWN[]_config_major_version" -eq \ "$DOWN[]_wanted_major_version" \ -a "$DOWN[]_config_minor_version" -eq \ "$DOWN[]_wanted_minor_version" \ -a "$DOWN[]_config_micro_version" -lt \ "$DOWN[]_wanted_micro_version" \) ; then # older version found no_[]DOWN=yes echo -n "*** An old version of $1 " echo -n "($DOWN[]_config_major_version" echo -n ".$DOWN[]_config_minor_version" echo ".$DOWN[]_config_micro_version) was found." echo -n "*** You need a version of $1 newer than " echo -n "$DOWN[]_wanted_major_version" echo -n ".$DOWN[]_wanted_minor_version" echo ".$DOWN[]_wanted_micro_version." echo "***" echo "*** If you have already installed a sufficiently new version, this error" echo "*** probably means that the wrong copy of the DOWN-config shell script is" echo "*** being found. The easiest way to fix this is to remove the old version" echo "*** of $1, but you can also set the UP[]_CONFIG environment to point to the" echo "*** correct copy of DOWN-config. (In this case, you will have to" echo "*** modify your LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf" echo "*** so that the correct libraries are found at run-time)" fi ]) fi if test "x$no_[]DOWN" = x ; then AC_MSG_RESULT(yes) ifelse([$3], , :, [$3]) else AC_MSG_RESULT(no) if test "$UP[]_CONFIG" = "no" ; then echo "*** The DOWN-config script installed by $1 could not be found" echo "*** If $1 was installed in PREFIX, make sure PREFIX/bin is in" echo "*** your path, or set the UP[]_CONFIG environment variable to the" echo "*** full path to DOWN-config." fi UP[]_CFLAGS="" UP[]_LIBS="" ifelse([$4], , :, [$4]) fi AC_SUBST(UP[]_CFLAGS) AC_SUBST(UP[]_LIBS) popdef([UP]) popdef([DOWN]) ]) scrot-1.2/autogen.sh000077500000000000000000000044451352650473100145240ustar00rootroot00000000000000#!/bin/sh # autogen.sh with clean option, v0.1-scrot # Copyright 2019 Joao Eriberto Mota Filho # # This file is under BSD-3-Clause license. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # 3. Neither the name of the authors nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # Use clean option if [ "$1" = "clean" -a ! -e Makefile ] then echo "Vanishing the code" rm -rf aclocal.m4 autom4te.cache/ compile configure depcomp install-sh \ Makefile.in missing src/config.h.in src/Makefile.in exit 0 fi # Do not use clean option if [ "$1" = "clean" -a -e Makefile ] then echo "I can not clean. Use '$ make distclean'." exit 0 fi # Do autoreconf autoreconf -i \ && { echo " "; \ echo "Done. You can use the 'clean' option to vanish the source code."; \ echo "Example of use: $ ./autogen.sh clean"; \ echo " "; \ echo "Now run ./configure, make, and make install."; \ } \ || { echo "We have a problem..."; exit 1; } scrot-1.2/configure.ac000066400000000000000000000015431352650473100150050ustar00rootroot00000000000000dnl Process this file with autoconf to create configure. AC_INIT([scrot], [1.2], [https://github.com/resurrecting-open-source-projects/scrot/issues]) AC_CONFIG_SRCDIR([src/main.c]) AM_INIT_AUTOMAKE AC_CONFIG_HEADER([src/config.h]) AX_PREFIX_CONFIG_H([src/scrot_config.h]) AC_PROG_CC AM_PROG_CC_STDC AC_C_CONST AC_PROG_INSTALL AC_PROG_MAKE_SET AM_MAINTAINER_MODE AC_PATH_GENERIC(giblib, 1.2.3, [ AC_SUBST(GIBLIB_LIBS) AC_SUBST(GIBLIB_CFLAGS) ], AC_MSG_ERROR(Cannot find giblib: Is giblib-config in the path?) ) LIBS="$LIBS -lm" GIBLIB_LIBS=`giblib-config --libs` GIBLIB_CFLAGS=`giblib-config --cflags` AC_SUBST(GIBLIB_LIBS) AC_SUBST(GIBLIB_CFLAGS) AC_CHECK_FUNC(getopt_long,,[LIBOBJS="$LIBOBJS getopt.o getopt1.o"]) AC_SUBST(LIBOBJS) m4_pattern_forbid([^AX_],[=> GNU autoconf-archive not present. <=]) AC_CONFIG_FILES([Makefile src/Makefile]) AC_OUTPUT scrot-1.2/doc/000077500000000000000000000000001352650473100132615ustar00rootroot00000000000000scrot-1.2/doc/UPDATE-CHECK000066400000000000000000000004371352650473100150050ustar00rootroot00000000000000When updating, change the following files (if needed): - ChangeLog - Check for spelling errors in ChangeLog, manpage and README. - Check final manpage with man command. - configure.ac (VERSION) - man/create-man.sh (DATE, version) - Generate a new manpage. - README - Test in Debian Sid scrot-1.2/man/000077500000000000000000000000001352650473100132675ustar00rootroot00000000000000scrot-1.2/man/create-man.sh000077500000000000000000000011421352650473100156400ustar00rootroot00000000000000#!/bin/bash # Copyright 2015-2019 Joao Eriberto Mota Filho # Create a manpage using txt2man command. # # This script can be used under BSD-3-Clause license. TEST=$(txt2man -h 2> /dev/null) [ "$TEST" ] || { echo -e "\nYou need to install txt2man, from https://github.com/mvertes/txt2man.\n"; exit 1; } T2M_DATE="18 August 2019" T2M_NAME=scrot T2M_VERSION=1.2 T2M_LEVEL=1 T2M_DESC="command line screen capture utility" # Don't change the following line txt2man -d "$T2M_DATE" -t $T2M_NAME -r $T2M_NAME-$T2M_VERSION -s $T2M_LEVEL -v "$T2M_DESC" $T2M_NAME.txt > $T2M_NAME.$T2M_LEVEL scrot-1.2/man/scrot.1000066400000000000000000000111641352650473100145060ustar00rootroot00000000000000.\" Text automatically generated by txt2man .TH scrot 1 "18 August 2019" "scrot-1.2" "command line screen capture utility" .SH NAME \fBscrot \fP- command line screen capture utility \fB .SH SYNOPSIS .nf .fam C \fBscrot\fP [\fIoptions\fP] [\fIfile\fP] .fam T .fi .fam T .fi .SH DESCRIPTION \fBscrot\fP (SCReenshOT) is a simple command line screen capture utility that uses imlib2 to grab and save images. Multiple image formats are supported through imlib2's dynamic saver modules. .PP Some features of the \fBscrot\fP: .RS .IP \(bu 3 support to multiple image formats (JPG, PNG, GIF, etc.). .IP \(bu 3 optimization of the screen shots image quality. .IP \(bu 3 capture a specific window or a rectangular area on the screen with the help of switch. .RE .PP \fBscrot\fP also can be used to monitor a desktop PC in admin absent and register unwanted activities. .SH OPTIONS .TP .B \fB-h\fP, \fB--help\fP Display help output and exit. .TP .B \fB-v\fP, \fB--version\fP Output version information and exit. .TP .B \fB-a\fP, \fB--autoselect\fP Non-interactively choose a rectangle of x,y,w,h. .TP .B \fB-b\fP, \fB--border\fP When selecting a window, grab wm border too. .TP .B \fB-c\fP, \fB--count\fP Display a countdown when used with delay. .TP .B \fB-d\fP, \fB--delay\fP NUM Wait NUM seconds before taking a shot. .TP .B \fB-e\fP, \fB--exec\fP APP Exec APP on the saved image. .TP .B \fB-q\fP, \fB--quality\fP NUM Image quality (1-100) high value means high size, low compression. Default: 75. (Effect differs depending on \fIfile\fP format chosen). .TP .B \fB-m\fP, \fB--multidisp\fP For multiple heads, grab shot from each and join them together. .TP .B \fB-s\fP, \fB--select\fP Interactively select a window or rectangle with the mouse. See \fB-l\fP and \fB-f\fP \fIoptions\fP. .TP .B \fB-l\fP, \fB--line\fP Indicates the style of the line when the \fB-s\fP option is used. See SELECTION STYLE. .TP .B \fB-f\fP, \fB--freeze\fP Freeze the screen when the \fB-s\fP option is used. .TP .B \fB-u\fP, \fB--focused\fP Use the currently focused window. .TP .B \fB-t\fP, \fB--thumb\fP NUM|GEOM Generate thumbnail too. NUM is the percentage of the original size for the thumbnail to be. Alternatively, a GEOMetry can be specified, example: 300x200 .TP .B \fB-z\fP, \fB--silent\fP Prevent beeping. .TP .B \fB-p\fP, \fB--pointer\fP Capture the mouse pointer. .TP .B \fB-o\fP, \fB--overwrite\fP By default \fBscrot\fP does not overwrite the files, use this option to allow it. .TP .B \fB-n\fP, \fB--note\fP Draw a text note. See NOTE FORMAT. .SH SPECIAL STRINGS Both the \fB--exec\fP and filename parameters can take format specifiers that are expanded by \fBscrot\fP when encountered. There are two types of format specifier. Characters preceded by a '%' are interpreted by \fBstrftime\fP(2). See man strftime for examples. These \fIoptions\fP may be used to refer to the current date and time. The second kind are internal to \fBscrot\fP and are prefixed by '$' The following specifiers are recognised: .PP .nf .fam C $a hostname $f image path/filename (ignored when used in the filename) $m thumb image path/filename (ignored when used in the filename) $n image name (ignored when used in the filename) $s image size (bytes) (ignored when used in the filename) $p image pixel size $w image width $h image height $t image format (ignored when used in the filename) $$ print a literal '$' \\n print a newline (ignored when used in the filename) .fam T .fi Example: .PP .nf .fam C scrot '%Y-%m-%d_$wx$h.png' -e 'mv $f ~/shots/' .fam T .fi This would create a \fIfile\fP called something like 2000-10-30_2560x1024.png and move it to your shots directory. .SH SELECTION STYLE When using \fB--select\fP you can indicate the style of the line with \fB--line\fP. .PP The following specifiers are recognised: .PP .nf .fam C style=(solid,dash),width=(range 1 to 8) .fam T .fi The default style is: .PP .nf .fam C style=solid,width=1 .fam T .fi Example: .PP .nf .fam C scrot --line style=dash,width=3 --select .fam T .fi .SH NOTE FORMAT The following specifiers are recognised for the option \fB--note\fP: .PP .nf .fam C -f 'FontName/size' -t 'text' -x position (optional) -y position (optional) -c color(RGBA) (optional) -a angle (optional) .fam T .fi Example: .PP .nf .fam C scrot --note "-f '/usr/share/fonts/TTF/DroidSans-Bold/40' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'" .fam T .fi .SH AUTHOR \fBscrot\fP was originally developed by Tom Gilbert under MIT-advertising license and is maintained by some people. .PP Currently, source code and newer versions are available at https://github.com/resurrecting-open-source-projects/\fBscrot\fP scrot-1.2/man/scrot.txt000066400000000000000000000101151352650473100151600ustar00rootroot00000000000000NAME scrot - command line screen capture utility SYNOPSIS scrot [options] [file] DESCRIPTION scrot (SCReenshOT) is a simple command line screen capture utility that uses imlib2 to grab and save images. Multiple image formats are supported through imlib2's dynamic saver modules. Some features of the scrot: - support to multiple image formats (JPG, PNG, GIF, etc.). - optimization of the screen shots image quality. - capture a specific window or a rectangular area on the screen with the help of switch. scrot also can be used to monitor a desktop PC in admin absent and register unwanted activities. OPTIONS -h, --help Display help output and exit. -v, --version Output version information and exit. -a, --autoselect Non-interactively choose a rectangle of x,y,w,h. -b, --border When selecting a window, grab wm border too. -c, --count Display a countdown when used with delay. -d, --delay NUM Wait NUM seconds before taking a shot. -e, --exec APP Exec APP on the saved image. -q, --quality NUM Image quality (1-100) high value means high size, low compression. Default: 75. (Effect differs depending on file format chosen). -m, --multidisp For multiple heads, grab shot from each and join them together. -s, --select Interactively select a window or rectangle with the mouse. See -l and -f options. -l, --line Indicates the style of the line when the -s option is used. See SELECTION STYLE. -f, --freeze Freeze the screen when the -s option is used. -u, --focused Use the currently focused window. -t, --thumb NUM|GEOM Generate thumbnail too. NUM is the percentage of the original size for the thumbnail to be. Alternatively, a GEOMetry can be specified, example: 300x200 -z, --silent Prevent beeping. -p, --pointer Capture the mouse pointer. -o, --overwrite By default scrot does not overwrite the files, use this option to allow it. -n, --note Draw a text note. See NOTE FORMAT. SPECIAL STRINGS Both the --exec and filename parameters can take format specifiers that are expanded by scrot when encountered. There are two types of format specifier. Characters preceded by a '%' are interpreted by strftime(2). See man strftime for examples. These options may be used to refer to the current date and time. The second kind are internal to scrot and are prefixed by '$' The following specifiers are recognised: $a hostname $f image path/filename (ignored when used in the filename) $m thumb image path/filename (ignored when used in the filename) $n image name (ignored when used in the filename) $s image size (bytes) (ignored when used in the filename) $p image pixel size $w image width $h image height $t image format (ignored when used in the filename) $$ print a literal '$' \\n print a newline (ignored when used in the filename) Example: scrot '%Y-%m-%d_$wx$h.png' -e 'mv $f ~/shots/' This would create a file called something like 2000-10-30_2560x1024.png and move it to your shots directory. SELECTION STYLE When using --select you can indicate the style of the line with --line. The following specifiers are recognised: style=(solid,dash),width=(range 1 to 8) The default style is: style=solid,width=1 Example: scrot --line style=dash,width=3 --select NOTE FORMAT The following specifiers are recognised for the option --note: -f 'FontName/size' -t 'text' -x position (optional) -y position (optional) -c color(RGBA) (optional) -a angle (optional) Example: scrot --note "-f '/usr/share/fonts/TTF/DroidSans-Bold/40' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'" AUTHOR scrot was originally developed by Tom Gilbert under MIT-advertising license and is maintained by some people. Currently, source code and newer versions are available at https://github.com/resurrecting-open-source-projects/scrot scrot-1.2/src/000077500000000000000000000000001352650473100133035ustar00rootroot00000000000000scrot-1.2/src/Makefile.am000066400000000000000000000036161352650473100153450ustar00rootroot00000000000000# Copyright 1999-2000 Tom Gilbert # Copyright 2016 Joao Eriberto Mota Filho # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies of the Software and its documentation and acknowledgment shall be # given in the documentation and software packages that this Software was # used. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # A list of all the files in the current directory which can be regenerated MAINTAINERCLEANFILES = Makefile.in AM_LDFLAGS = -L/usr/X11R6/lib AM_CPPFLAGS = -g -O3 -Wall -I/usr/X11R6/include \ $(X_CFLAGS) -I$(prefix)/include -I$(includedir) -I. \ -DPREFIX=\""$(prefix)"\" @GIBLIB_CFLAGS@ LIBOBJS = @LIBOBJS@ bin_PROGRAMS = scrot scrot_SOURCES = main.c getopt.c getopt1.c getopt.h scrot.h \ options.c options.h debug.h imlib.c structs.h note.c note.h scrot_LDADD = -lX11 -lXfixes -lXcursor @GIBLIB_LIBS@ scrot-1.2/src/debug.h000066400000000000000000000023051352650473100145420ustar00rootroot00000000000000/* debug.h Copyright (C) 1999,2000 Tom Gilbert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef DEBUG_H #define DEBUG_H /* #define DEBUG */ #endif scrot-1.2/src/getopt.c000066400000000000000000001016061352650473100147550ustar00rootroot00000000000000/* Getopt for GNU. NOTE: getopt is now part of the C library, so if you don't know what "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu before changing it! Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97 Free Software Foundation, Inc. Copyright 2019 Santhosh Raju The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* This tells Alpha OSF/1 not to define a getopt prototype in . Ditto for AIX 3.2 and . */ #ifndef _NO_PROTO #define _NO_PROTO #endif #ifdef HAVE_CONFIG_H #include "config.h" #endif #if !defined (__STDC__) || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const #define const #endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 #include #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION #define ELIDE_CODE #endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them contain conflicting prototypes for getopt. */ #include #include #endif /* GNU C library. */ #ifdef VMS #include #if HAVE_STRING_H - 0 #include #endif #endif #include #ifndef _ /* This is for other GNU distributions with internationalized messages. When compiling libc, the _ macro is predefined. */ #ifdef HAVE_LIBINTL_H # include # define _(msgid) gettext (msgid) #else # define _(msgid) (msgid) #endif #endif /* This version of `getopt' appears to the caller like standard Unix `getopt' but it behaves differently for the user, since it allows the user to intersperse the options with the other arguments. As `getopt' works, it permutes the elements of ARGV so that, when it is done, all the options precede everything else. Thus all application programs are extended to handle flexible argument order. Setting the environment variable POSIXLY_CORRECT disables permutation. Then the behavior is completely standard. GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ #include "getopt.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ char *optarg = NULL; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ /* 1003.2 says this must be 1 before any call. */ int optind = 1; /* Formerly, initialization of getopt depended on optind==0, which causes problems with re-calling getopt as programs generally don't know that. */ int __getopt_initialized = 0; /* The next char to be scanned in the option-element in which the last option character we returned was found. This allows us to pick up the scan where we left off. If this is zero, or a null string, it means resume the scan by advancing to the next ARGV-element. */ static char *nextchar; /* Callers store zero here to inhibit the error message for unrecognized options. */ int opterr = 1; /* Set to an option character which was unrecognized. This must be initialized on some systems to avoid linking in the system's own getopt implementation. */ int optopt = '?'; /* Describe how to deal with options that follow non-option ARGV-elements. If the caller did not specify anything, the default is REQUIRE_ORDER if the environment variable POSIXLY_CORRECT is defined, PERMUTE otherwise. REQUIRE_ORDER means don't recognize them as options; stop option processing when the first non-option is seen. This is what Unix does. This mode of operation is selected by either setting the environment variable POSIXLY_CORRECT, or using `+' as the first character of the list of option characters. PERMUTE is the default. We permute the contents of ARGV as we scan, so that eventually all the non-options are at the end. This allows options to be given in any order, even with programs that were not written to expect this. RETURN_IN_ORDER is an option available to programs that were written to expect options and other ARGV-elements in any order and that care about the ordering of the two. We describe each non-option ARGV-element as if it were the argument of an option with character code 1. Using `-' as the first character of the list of option characters selects this mode of operation. The special argument `--' forces an end of option-scanning regardless of the value of `ordering'. In the case of RETURN_IN_ORDER, only `--' can cause `getopt' to return -1 with `optind' != ARGC. */ static enum { REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; #ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries because there are many ways it can cause trouble. On some systems, it contains special magic macros that don't work in GCC. */ #include #define my_index strchr #else /* Avoid depending on library functions or files whose names are inconsistent. */ char *getenv(); static char * my_index(str, chr) const char *str; int chr; { while (*str) { if (*str == chr) return (char *) str; str++; } return 0; } /* If using GCC, we can safely declare strlen this way. If not using GCC, it is ok not to declare it. */ #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. That was relevant to code that was here before. */ #if !defined (__STDC__) || !__STDC__ /* gcc with -traditional declares the built-in strlen to return int, and has done so at least since version 2.4.5. -- rms. */ extern int strlen(const char *); #endif /* not __STDC__ */ #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have been skipped. `first_nonopt' is the index in ARGV of the first of them; `last_nonopt' is the index after the last of them. */ static int first_nonopt; static int last_nonopt; #ifdef _LIBC /* Bash 2.0 gives us an environment variable containing flags indicating ARGV elements that should not be considered arguments. */ /* Defined in getopt_init.c */ extern char *__getopt_nonoption_flags; static int nonoption_flags_max_len; static int nonoption_flags_len; static int original_argc; static char *const *original_argv; /* Make sure the environment variable bash 2.0 puts in the environment is valid for the getopt call we must make sure that the ARGV passed to getopt is that one passed to the process. */ static void __attribute__ ((unused)) store_args_and_env(int argc, char *const *argv) { /* XXX This is no good solution. We should rather copy the args so that we can compare them later. But we must not use malloc(3). */ original_argc = argc; original_argv = argv; } # ifdef text_set_element text_set_element(__libc_subinit, store_args_and_env); # endif /* text_set_element */ # define SWAP_FLAGS(ch1, ch2) \ if (nonoption_flags_len > 0) \ { \ char __tmp = __getopt_nonoption_flags[ch1]; \ __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ __getopt_nonoption_flags[ch2] = __tmp; \ } #else /* !_LIBC */ # define SWAP_FLAGS(ch1, ch2) #endif /* _LIBC */ /* Exchange two adjacent subsequences of ARGV. One subsequence is elements [first_nonopt,last_nonopt) which contains all the non-options that have been skipped so far. The other is elements [last_nonopt,optind), which contains all the options processed since those non-options were skipped. `first_nonopt' and `last_nonopt' are relocated so that they describe the new indices of the non-options in ARGV after they are moved. */ #if defined (__STDC__) && __STDC__ static void exchange(char **); #endif static void exchange(argv) char **argv; { int bottom = first_nonopt; int middle = last_nonopt; int top = optind; char *tem; /* Exchange the shorter segment with the far end of the longer segment. That puts the shorter segment into the right place. It leaves the longer segment in the right place overall, but it consists of two parts that need to be swapped next. */ #ifdef _LIBC /* First make sure the handling of the `__getopt_nonoption_flags' string can work normally. Our top argument must be in the range of the string. */ if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) { /* We must extend the array. The user plays games with us and presents new arguments. */ char *new_str = malloc(top + 1); if (new_str == NULL) nonoption_flags_len = nonoption_flags_max_len = 0; else { memset(__mempcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len), '\0', top + 1 - nonoption_flags_max_len); nonoption_flags_max_len = top + 1; __getopt_nonoption_flags = new_str; } } #endif while (top > middle && middle > bottom) { if (top - middle > middle - bottom) { /* Bottom segment is the short one. */ int len = middle - bottom; register int i; /* Swap it with the top part of the top segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[top - (middle - bottom) + i]; argv[top - (middle - bottom) + i] = tem; SWAP_FLAGS(bottom + i, top - (middle - bottom) + i); } /* Exclude the moved bottom segment from further swapping. */ top -= len; } else { /* Top segment is the short one. */ int len = top - middle; register int i; /* Swap it with the bottom part of the bottom segment. */ for (i = 0; i < len; i++) { tem = argv[bottom + i]; argv[bottom + i] = argv[middle + i]; argv[middle + i] = tem; SWAP_FLAGS(bottom + i, middle + i); } /* Exclude the moved top segment from further swapping. */ bottom += len; } } /* Update records for the slots the non-options now occupy. */ first_nonopt += (optind - last_nonopt); last_nonopt = optind; } /* Initialize the internal data when the first call is made. */ #if defined (__STDC__) && __STDC__ static const char *_getopt_initialize(int, char *const *, const char *); #endif static const char * _getopt_initialize(argc, argv, optstring) int argc; char *const *argv; const char *optstring; { /* Start processing options with ARGV-element 1 (since ARGV-element 0 is the program name); the sequence of previously skipped non-option ARGV-elements is empty. */ first_nonopt = last_nonopt = optind; nextchar = NULL; posixly_correct = getenv("POSIXLY_CORRECT"); /* Determine how to handle the ordering of options and nonoptions. */ if (optstring[0] == '-') { ordering = RETURN_IN_ORDER; ++optstring; } else if (optstring[0] == '+') { ordering = REQUIRE_ORDER; ++optstring; } else if (posixly_correct != NULL) ordering = REQUIRE_ORDER; else ordering = PERMUTE; #ifdef _LIBC if (posixly_correct == NULL && argc == original_argc && argv == original_argv) { if (nonoption_flags_max_len == 0) { if (__getopt_nonoption_flags == NULL || __getopt_nonoption_flags[0] == '\0') nonoption_flags_max_len = -1; else { const char *orig_str = __getopt_nonoption_flags; int len = nonoption_flags_max_len = strlen(orig_str); if (nonoption_flags_max_len < argc) nonoption_flags_max_len = argc; __getopt_nonoption_flags = (char *) malloc(nonoption_flags_max_len); if (__getopt_nonoption_flags == NULL) nonoption_flags_max_len = -1; else memset(__mempcpy(__getopt_nonoption_flags, orig_str, len), '\0', nonoption_flags_max_len - len); } } nonoption_flags_len = nonoption_flags_max_len; } else nonoption_flags_len = 0; #endif return optstring; } /* Scan elements of ARGV (whose length is ARGC) for option characters given in OPTSTRING. If an element of ARGV starts with '-', and is not exactly "-" or "--", then it is an option element. The characters of this element (aside from the initial '-') are option characters. If `getopt' is called repeatedly, it returns successively each of the option characters from each of the option elements. If `getopt' finds another option character, it returns that character, updating `optind' and `nextchar' so that the next call to `getopt' can resume the scan with the following option character or ARGV-element. If there are no more option characters, `getopt' returns -1. Then `optind' is the index in ARGV of the first ARGV-element that is not an option. (The ARGV-elements have been permuted so that those that are not options now come last.) OPTSTRING is a string containing the legitimate option characters. If an option character is seen that is not listed in OPTSTRING, return '?' after printing an error message. If you set `opterr' to zero, the error message is suppressed but we still return '?'. If a char in OPTSTRING is followed by a colon, that means it wants an arg, so the following text in the same ARGV-element, or the text of the following ARGV-element, is returned in `optarg'. Two colons mean an option that wants an optional arg; if there is text in the current ARGV-element, it is returned in `optarg', otherwise `optarg' is set to zero. If OPTSTRING starts with `-' or `+', it requests different methods of handling the non-option ARGV-elements. See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. Long-named options begin with `--' instead of `-'. Their names may be abbreviated as long as the abbreviation is unique or is an exact match for some defined option. If they have an argument, it follows the option name in the same ARGV-element, separated from the option name by a `=', or else the in next ARGV-element. When `getopt' finds a long-named option, it returns 0 if that option's `flag' field is nonzero, the value of the option's `val' field if the `flag' field is zero. The elements of ARGV aren't really const, because we permute them. But we pretend they're const in the prototype to be compatible with other systems. LONGOPTS is a vector of `struct option' terminated by an element containing a name which is zero. LONGIND returns the index in LONGOPT of the long-named option found. It is only valid when a long-named option has been found by the most recent call. If LONG_ONLY is nonzero, '-' as well as '--' can introduce long-named options. */ int _getopt_internal(argc, argv, optstring, longopts, longind, long_only) int argc; char *const *argv; const char *optstring; const struct option *longopts; int *longind; int long_only; { optarg = NULL; if (optind == 0 || !__getopt_initialized) { if (optind == 0) optind = 1; /* Don't scan ARGV[0], the program name. */ optstring = _getopt_initialize(argc, argv, optstring); __getopt_initialized = 1; } /* Test whether ARGV[optind] points to a non-option argument. Either it does not have option syntax, or there is an environment flag from the shell indicating it is not an option. The later information is only used when the used in the GNU libc. */ #ifdef _LIBC #define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ || (optind < nonoption_flags_len \ && __getopt_nonoption_flags[optind] == '1')) #else #define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif if (nextchar == NULL || *nextchar == '\0') { /* Advance to the next ARGV-element. */ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been moved back by the user (who may also have changed the arguments). */ if (last_nonopt > optind) last_nonopt = optind; if (first_nonopt > optind) first_nonopt = optind; if (ordering == PERMUTE) { /* If we have just processed some options following some non-options, exchange them so that the options come first. */ if (first_nonopt != last_nonopt && last_nonopt != optind) exchange((char **) argv); else if (last_nonopt != optind) first_nonopt = optind; /* Skip any additional non-options and extend the range of non-options previously skipped. */ while (optind < argc && NONOPTION_P) optind++; last_nonopt = optind; } /* The special ARGV-element `--' means premature end of options. Skip it like a null option, then exchange with previous non-options as if it were an option, then skip everything else like a non-option. */ if (optind != argc && !strcmp(argv[optind], "--")) { optind++; if (first_nonopt != last_nonopt && last_nonopt != optind) exchange((char **) argv); else if (first_nonopt == last_nonopt) first_nonopt = optind; last_nonopt = argc; optind = argc; } /* If we have done all the ARGV-elements, stop the scan and back over any non-options that we skipped and permuted. */ if (optind == argc) { /* Set the next-arg-index to point at the non-options that we previously skipped, so the caller will digest them. */ if (first_nonopt != last_nonopt) optind = first_nonopt; return -1; } /* If we have come to a non-option and did not permute it, either stop the scan or describe it to the caller and pass it by. */ if (NONOPTION_P) { if (ordering == REQUIRE_ORDER) return -1; optarg = argv[optind++]; return 1; } /* We have found another option-ARGV-element. Skip the initial punctuation. */ nextchar = (argv[optind] + 1 + (longopts != NULL && argv[optind][1] == '-')); } /* Decode the current option-ARGV-element. */ /* Check whether the ARGV-element is a long option. If long_only and the ARGV-element has the form "-f", where f is a valid short option, don't consider it an abbreviated form of a long option that starts with f. Otherwise there would be no way to give the -f short option. On the other hand, if there's a long option "fubar" and the ARGV-element is "-fu", do consider that an abbreviation of the long option, just like "--fu", and not "-f" with arg "u". This distinction seems to be the most useful approach. */ if (longopts != NULL && (argv[optind][1] == '-' || (long_only && (argv[optind][2] || !my_index(optstring, argv[optind][1]))))) { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = -1; int option_index; for (nameend = nextchar; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp(p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == (unsigned int) strlen(p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (opterr) fprintf(stderr, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen(nextchar); optind++; optopt = 0; return '?'; } if (pfound != NULL) { option_index = indfound; optind++; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (opterr) { if (argv[optind - 1][1] == '-') /* --option */ fprintf(stderr, _ ("%s: option `--%s' doesn't allow an argument\n"), argv[0], pfound->name); else /* +option or -option */ fprintf(stderr, _ ("%s: option `%c%s' doesn't allow an argument\n"), argv[0], argv[optind - 1][0], pfound->name); } nextchar += strlen(nextchar); optopt = pfound->val; return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (opterr) fprintf(stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen(nextchar); optopt = pfound->val; return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen(nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } /* Can't find it as a long option. If this is not getopt_long_only, or the option starts with '--' or is not a valid short option, then it's an error. Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' || my_index(optstring, *nextchar) == NULL) { if (opterr) { if (argv[optind][1] == '-') /* --option */ fprintf(stderr, _("%s: unrecognized option `--%s'\n"), argv[0], nextchar); else /* +option or -option */ fprintf(stderr, _("%s: unrecognized option `%c%s'\n"), argv[0], argv[optind][0], nextchar); } nextchar = (char *) ""; optind++; optopt = 0; return '?'; } } /* Look at and handle the next short option-character. */ { char c = *nextchar++; char *temp = my_index(optstring, c); /* Increment `optind' when we start to process its last character. */ if (*nextchar == '\0') ++optind; if (temp == NULL || c == ':') { if (opterr) { if (posixly_correct) /* 1003.2 specifies the format of this message. */ fprintf(stderr, _("%s: illegal option -- %c\n"), argv[0], c); else fprintf(stderr, _("%s: invalid option -- %c\n"), argv[0], c); } optopt = c; return '?'; } /* Convenience. Treat POSIX -W foo same as long option --foo */ if (temp[0] == 'W' && temp[1] == ';') { char *nameend; const struct option *p; const struct option *pfound = NULL; int exact = 0; int ambig = 0; int indfound = 0; int option_index; /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (opterr) { /* 1003.2 specifies the format of this message. */ fprintf(stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; return c; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; /* optarg is now the argument, see if it's in the table of longopts. */ for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) /* Do nothing. */ ; /* Test all long options for either exact match or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) if (!strncmp(p->name, nextchar, nameend - nextchar)) { if ((unsigned int) (nameend - nextchar) == strlen(p->name)) { /* Exact match found. */ pfound = p; indfound = option_index; exact = 1; break; } else if (pfound == NULL) { /* First nonexact match found. */ pfound = p; indfound = option_index; } else /* Second or later nonexact match found. */ ambig = 1; } if (ambig && !exact) { if (opterr) fprintf(stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen(nextchar); optind++; return '?'; } if (pfound != NULL) { option_index = indfound; if (*nameend) { /* Don't test has_arg with >, because some C compilers don't allow it to be used on enums. */ if (pfound->has_arg) optarg = nameend + 1; else { if (opterr) fprintf(stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name); nextchar += strlen(nextchar); return '?'; } } else if (pfound->has_arg == 1) { if (optind < argc) optarg = argv[optind++]; else { if (opterr) fprintf(stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); nextchar += strlen(nextchar); return optstring[0] == ':' ? ':' : '?'; } } nextchar += strlen(nextchar); if (longind != NULL) *longind = option_index; if (pfound->flag) { *(pfound->flag) = pfound->val; return 0; } return pfound->val; } nextchar = NULL; return 'W'; /* Let the application handle it. */ } if (temp[1] == ':') { if (temp[2] == ':') { /* This is an option that accepts an argument optionally. */ if (*nextchar != '\0') { optarg = nextchar; optind++; } else optarg = NULL; nextchar = NULL; } else { /* This is an option that requires an argument. */ if (*nextchar != '\0') { optarg = nextchar; /* If we end this ARGV-element by taking the rest as an arg, we must advance to the next element now. */ optind++; } else if (optind == argc) { if (opterr) { /* 1003.2 specifies the format of this message. */ fprintf(stderr, _("%s: option requires an argument -- %c\n"), argv[0], c); } optopt = c; if (optstring[0] == ':') c = ':'; else c = '?'; } else /* We already incremented `optind' once; increment it again when taking next ARGV-elt as argument. */ optarg = argv[optind++]; nextchar = NULL; } } return c; } } int getopt(argc, argv, optstring) int argc; char *const *argv; const char *optstring; { return _getopt_internal(argc, argv, optstring, (const struct option *) 0, (int *) 0, 0); } #endif /* Not ELIDE_CODE. */ #ifdef TEST /* Compile with -DTEST to make an executable for use in testing the above definition of `getopt'. */ int main(argc, argv) int argc; char **argv; { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; c = getopt(argc, argv, "abc:d:0123456789"); if (c == -1) break; switch (c) { case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf("option %c\n", c); break; case 'a': printf("option a\n"); break; case 'b': printf("option b\n"); break; case 'c': printf("option c with value `%s'\n", optarg); break; case '?': break; default: printf("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\n"); } exit(0); } #endif /* TEST */ scrot-1.2/src/getopt.h000066400000000000000000000117411352650473100147620ustar00rootroot00000000000000/* Declarations for getopt. Copyright (C) 1989,90,91,92,93,94,96,97 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _GETOPT_H #define _GETOPT_H 1 #ifdef __cplusplus extern "C" { #endif /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, the argument value is returned here. Also, when `ordering' is RETURN_IN_ORDER, each non-option ARGV-element is returned here. */ extern char *optarg; /* Index in ARGV of the next element to be scanned. This is used for communication to and from the caller and for communication between successive calls to `getopt'. On entry to `getopt', zero means this is the first call; initialize. When `getopt' returns -1, this is the index of the first of the non-option elements that the caller should itself scan. Otherwise, `optind' communicates from one call to the next how much of ARGV has been scanned so far. */ extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints for unrecognized options. */ extern int opterr; /* Set to an option character which was unrecognized. */ extern int optopt; /* Describe the long-named options requested by the application. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector of `struct option' terminated by an element containing a name which is zero. The field `has_arg' is: no_argument (or 0) if the option does not take an argument, required_argument (or 1) if the option requires an argument, optional_argument (or 2) if the option takes an optional argument. If the field `flag' is not NULL, it points to a variable that is set to the value given in the field `val' when the option is found, but left unchanged if the option is not found. To have a long-named option do something other than set an `int' to a compiled-in constant, such as set a value from `optarg', set the option's `flag' field to zero and its `val' field to a nonzero value (the equivalent single-letter option character, if there is one). For long options that have a zero `flag' field, `getopt' returns the contents of the `val' field. */ struct option { #if defined (__STDC__) && __STDC__ const char *name; #else char *name; #endif /* has_arg can't be an enum because some compilers complain about type mismatches in all the code that assumes it is an int. */ int has_arg; int *flag; int val; }; /* Names for the values of the `has_arg' field of `struct option'. */ #define no_argument 0 #define required_argument 1 #define optional_argument 2 #if defined (__STDC__) && __STDC__ #ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in stdlib.h. To avoid compilation errors, only prototype getopt for the GNU C library. */ extern int getopt(int argc, char *const *argv, const char *shortopts); #else /* not __GNU_LIBRARY__ */ #ifndef __cplusplus /* C++ is more pedantic, and demands a full prototype, not this. Hope that stdlib.h has a prototype for `getopt'. */ extern int getopt(); #endif /* __cplusplus */ #endif /* __GNU_LIBRARY__ */ extern int getopt_long(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind); extern int getopt_long_only(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind); /* Internal only. Users should not call this directly. */ extern int _getopt_internal(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind, int long_only); #else /* not __STDC__ */ extern int getopt(); extern int getopt_long(); extern int getopt_long_only(); extern int _getopt_internal(); #endif /* __STDC__ */ #ifdef __cplusplus } #endif #endif /* getopt.h */ scrot-1.2/src/getopt1.c000066400000000000000000000114241352650473100150340ustar00rootroot00000000000000/* getopt_long and getopt_long_only entry points for GNU getopt. Copyright (C) 1987,88,89,90,91,92,93,94,96,97 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include "getopt.h" #if !defined (__STDC__) || !__STDC__ /* This is a separate conditional since some stdc systems reject `defined (const)'. */ #ifndef const #define const #endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C Library, but also included in many other GNU distributions. Compiling and linking in this code is a waste when using the GNU C library (especially if it is a shared library). Rather than having every GNU program understand `configure --with-gnu-libc' and omit the object files, it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined (_LIBC) && defined (__GLIBC__) && __GLIBC__ >= 2 #include #if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION #define ELIDE_CODE #endif #endif #ifndef ELIDE_CODE /* This needs to come after some library #include to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ #include #endif #ifndef NULL #define NULL 0 #endif int getopt_long(argc, argv, options, long_options, opt_index) int argc; char *const *argv; const char *options; const struct option *long_options; int *opt_index; { return _getopt_internal(argc, argv, options, long_options, opt_index, 0); } /* Like getopt_long, but '-' as well as '--' can indicate a long option. If an option that starts with '-' (not '--') doesn't match a long option, but does match a short option, it is parsed as a short option instead. */ int getopt_long_only(argc, argv, options, long_options, opt_index) int argc; char *const *argv; const char *options; const struct option *long_options; int *opt_index; { return _getopt_internal(argc, argv, options, long_options, opt_index, 1); } #endif /* Not ELIDE_CODE. */ #ifdef TEST #include int main(argc, argv) int argc; char **argv; { int c; int digit_optind = 0; while (1) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { {"add", 1, 0, 0}, {"append", 0, 0, 0}, {"delete", 1, 0, 0}, {"verbose", 0, 0, 0}, {"create", 0, 0, 0}, {"file", 1, 0, 0}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "abc:d:0123456789", long_options, &option_index); if (c == -1) break; switch (c) { case 0: printf("option %s", long_options[option_index].name); if (optarg) printf(" with arg %s", optarg); printf("\n"); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (digit_optind != 0 && digit_optind != this_option_optind) printf("digits occur in two different argv-elements.\n"); digit_optind = this_option_optind; printf("option %c\n", c); break; case 'a': printf("option a\n"); break; case 'b': printf("option b\n"); break; case 'c': printf("option c with value `%s'\n", optarg); break; case 'd': printf("option d with value `%s'\n", optarg); break; case '?': break; default: printf("?? getopt returned character code 0%o ??\n", c); } } if (optind < argc) { printf("non-option ARGV-elements: "); while (optind < argc) printf("%s ", argv[optind++]); printf("\n"); } exit(0); } #endif /* TEST */ scrot-1.2/src/imlib.c000066400000000000000000000040311352650473100145410ustar00rootroot00000000000000/* imlib.c Copyright (C) 1999,2000 Tom Gilbert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "scrot.h" #include "options.h" Display *disp = NULL; Visual *vis = NULL; Screen *scr = NULL; Colormap cm; int depth; Window root = 0; void init_x_and_imlib(char *dispstr, int screen_num) { disp = XOpenDisplay(dispstr); if (!disp) { fprintf(stderr, "Can't open X display. It *is* running, yeah?"); exit(EXIT_FAILURE); } if (screen_num) scr = ScreenOfDisplay(disp, screen_num); else scr = ScreenOfDisplay(disp, DefaultScreen(disp)); vis = DefaultVisual(disp, XScreenNumberOfScreen(scr)); depth = DefaultDepth(disp, XScreenNumberOfScreen(scr)); cm = DefaultColormap(disp, XScreenNumberOfScreen(scr)); root = RootWindow(disp, XScreenNumberOfScreen(scr)); imlib_context_set_display(disp); imlib_context_set_visual(vis); imlib_context_set_colormap(cm); imlib_context_set_color_modifier(NULL); imlib_context_set_operation(IMLIB_OP_COPY); } scrot-1.2/src/main.c000066400000000000000000000523561352650473100144060ustar00rootroot00000000000000/* main.c Copyright 1999-2000 Tom Gilbert Copyright 2009 James Cameron Copyright 2010 Ibragimov Rinat Copyright 2017 Stoney Sauce Copyright 2019 Daniel T. Borelli Copyright 2019 Jade Auer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "scrot.h" #include "options.h" int main(int argc, char **argv) { Imlib_Image image; Imlib_Image thumbnail; Imlib_Load_Error err; char *filename_im = NULL, *filename_thumb = NULL; char *have_extension = NULL; time_t t; struct tm *tm; init_parse_options(argc, argv); init_x_and_imlib(NULL, 0); if (!opt.output_file) { opt.output_file = gib_estrdup("%Y-%m-%d-%H%M%S_$wx$h_scrot.png"); opt.thumb_file = gib_estrdup("%Y-%m-%d-%H%M%S_$wx$h_scrot-thumb.png"); } else { have_extension = scrot_have_file_extension(opt.output_file); } if (opt.focused) image = scrot_grab_focused(); else if (opt.select) image = scrot_sel_and_grab_image(); else if (opt.autoselect) image = gib_imlib_create_image_from_drawable(root, 0, opt.autoselect_x, opt.autoselect_y, opt.autoselect_w, opt.autoselect_h, 1); else { scrot_do_delay(); if (opt.multidisp) { image = scrot_grab_shot_multi(); } else { image = scrot_grab_shot(); } } if (opt.note != NULL) scrot_note_draw(image); if (!image) gib_eprintf("no image grabbed"); time(&t); /* Get the time directly after the screenshot */ tm = localtime(&t); imlib_context_set_image(image); imlib_image_attach_data_value("quality", NULL, opt.quality, NULL); if (!have_extension) { imlib_image_set_format("png"); } filename_im = im_printf(opt.output_file, tm, NULL, NULL, image); scrot_check_if_overwrite_file(&filename_im); gib_imlib_save_image_with_error_return(image, filename_im, &err); if (err) gib_eprintf("Saving to file %s failed\n", filename_im); if (opt.thumb) { int cwidth, cheight; int twidth, theight; cwidth = gib_imlib_image_get_width(image); cheight = gib_imlib_image_get_height(image); /* Geometry based thumb size */ if (opt.thumb_width || opt.thumb_height) { if (!opt.thumb_width) { twidth = cwidth * opt.thumb_height / cheight; theight = opt.thumb_height; } else if (!opt.thumb_height) { twidth = opt.thumb_width; theight = cheight * opt.thumb_width / cwidth; } else { twidth = opt.thumb_width; theight = opt.thumb_height; } } else { twidth = cwidth * opt.thumb / 100; theight = cheight * opt.thumb / 100; } thumbnail = gib_imlib_create_cropped_scaled_image(image, 0, 0, cwidth, cheight, twidth, theight, 1); if (thumbnail == NULL) gib_eprintf("Unable to create scaled Image\n"); else { if (opt.note != NULL) scrot_note_draw(image); filename_thumb = im_printf(opt.thumb_file, tm, NULL, NULL, thumbnail); scrot_check_if_overwrite_file(&filename_thumb); gib_imlib_save_image_with_error_return(thumbnail, filename_thumb, &err); if (err) gib_eprintf("Saving thumbnail %s failed\n", filename_thumb); } } if (opt.exec) scrot_exec_app(image, tm, filename_im, filename_thumb); gib_imlib_free_image_and_decache(image); return 0; } void scrot_do_delay(void) { if (opt.delay) { if (opt.countdown) { int i; printf("Taking shot in %d.. ", opt.delay); fflush(stdout); sleep(1); for (i = opt.delay - 1; i > 0; i--) { printf("%d.. ", i); fflush(stdout); sleep(1); } printf("0.\n"); fflush(stdout); } else sleep(opt.delay); } } char* scrot_have_file_extension(char *filename) { char *ext = strrchr(filename, '.'); return (ext && (strlen(ext + 1) == 3)) ? ext : NULL; } void scrot_check_if_overwrite_file(char **filename) { char *curfile = *filename; if (opt.overwrite == 1) return; if (access(curfile, F_OK) == -1) return; const int max_count = 999; static int count = 0; const char *extension = scrot_have_file_extension(curfile); const size_t slen = strlen(curfile); int nalloc = slen + 4 + 1; // _000 + NUL byte char fmt[5]; char *newname = NULL; if (extension) nalloc += 4; // .ext newname = calloc(nalloc, sizeof(char)); if (extension) // exclude extension memcpy(newname, curfile, slen - 4); else memcpy(newname, curfile, slen); do { snprintf(fmt, 5, "_%03d", count++); if (!extension) { strncpy(newname + slen, fmt, 5); } else { strncpy((newname + slen)-4, fmt, 5); strncat(newname, extension, 4); } curfile = newname; } while ((count < max_count) && (access(curfile, F_OK) == 0)); free(*filename); *filename = newname; if (count == max_count) { fprintf(stderr, "scrot can no longer generate new file names.\n" "The last attempt is %s\n", newname); free(newname); exit(EXIT_FAILURE); } } void scrot_grab_mouse_pointer(const Imlib_Image image, const int ix_off, const int iy_off) { XFixesCursorImage *xcim = XFixesGetCursorImage(disp); const int width = xcim->width; const int height = xcim->height; const int x = (xcim->x - xcim->xhot) - ix_off; const int y = (xcim->y - xcim->yhot) - iy_off; DATA32 *pixels = NULL; #ifdef __i386__ pixels = (DATA32*)xcim->pixels; #else DATA32 data[width * height * 4]; for (size_t i = 0; i < (width * height); i++) ((DATA32*)data)[i] = (DATA32)xcim->pixels[i]; pixels = data; #endif Imlib_Image imcursor = imlib_create_image_using_data(width, height, pixels); XFree(xcim); if (!imcursor) { fprintf(stderr, "scrot_grab_mouse_pointer: Failed create image using data."); exit(EXIT_FAILURE); } imlib_context_set_image(imcursor); imlib_image_set_has_alpha(1); imlib_context_set_image(image); imlib_blend_image_onto_image(imcursor, 0, 0, 0, width, height, x, y, width, height); imlib_context_set_image(imcursor); imlib_free_image(); } Imlib_Image scrot_grab_shot(void) { Imlib_Image im; if (! opt.silent) XBell(disp, 0); im = gib_imlib_create_image_from_drawable(root, 0, 0, 0, scr->width, scr->height, 1); if (opt.pointer == 1) scrot_grab_mouse_pointer(im, 0, 0); return im; } void scrot_exec_app(Imlib_Image image, struct tm *tm, char *filename_im, char *filename_thumb) { char *execstr; int ret; execstr = im_printf(opt.exec, tm, filename_im, filename_thumb, image); errno = 0; ret = system(execstr); if (ret == -1) { fprintf(stderr, "The child process could not be created: %s\n", strerror(errno)); } else if (WEXITSTATUS(ret) == 127) { fprintf(stderr, "scrot could not be executed the command: %s.\n", execstr); } exit(0); } Imlib_Image scrot_grab_focused(void) { Imlib_Image im = NULL; int rx = 0, ry = 0, rw = 0, rh = 0; Window target = None; int ignored; scrot_do_delay(); XGetInputFocus(disp, &target, &ignored); if (!scrot_get_geometry(target, &rx, &ry, &rw, &rh)) return NULL; scrot_nice_clip(&rx, &ry, &rw, &rh); im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1); if (opt.pointer == 1) scrot_grab_mouse_pointer(im, rx, ry); return im; } Imlib_Image scrot_sel_and_grab_image(void) { Imlib_Image im = NULL; static int xfd = 0; static int fdsize = 0; XEvent ev; fd_set fdset; int count = 0, done = 0; int rx = 0, ry = 0, rw = 0, rh = 0, btn_pressed = 0; int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0; Cursor cur_cross, cur_angle; Window target = None; GC gc; XGCValues gcval; xfd = ConnectionNumber(disp); fdsize = xfd + 1; cur_cross = XCreateFontCursor(disp, XC_cross); cur_angle = XCreateFontCursor(disp, XC_lr_angle); gcval.foreground = XWhitePixel(disp, 0); gcval.function = GXxor; gcval.background = XBlackPixel(disp, 0); gcval.plane_mask = gcval.background ^ gcval.foreground; gcval.subwindow_mode = IncludeInferiors; gc = XCreateGC(disp, root, GCFunction | GCForeground | GCBackground | GCSubwindowMode, &gcval); XSetLineAttributes(disp, gc, opt.line_width, opt.line_style, CapRound, JoinRound); if ((XGrabPointer (disp, root, False, ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync, GrabModeAsync, root, cur_cross, CurrentTime) != GrabSuccess)) { fprintf(stderr, "couldn't grab pointer:"); XFreeCursor(disp, cur_cross); XFreeCursor(disp, cur_angle); XFreeGC(disp, gc); exit(EXIT_FAILURE); } if ((XGrabKeyboard (disp, root, False, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess)) { fprintf(stderr, "couldn't grab keyboard:"); XFreeCursor(disp, cur_cross); XFreeCursor(disp, cur_angle); XFreeGC(disp, gc); exit(EXIT_FAILURE); } if (opt.freeze == 1) XGrabServer(disp); while (1) { /* handle events here */ while (!done && XPending(disp)) { XNextEvent(disp, &ev); switch (ev.type) { case MotionNotify: if (btn_pressed) { if (rect_w) { /* re-draw the last rect to clear it */ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); } else { /* Change the cursor to show we're selecting a region */ XChangeActivePointerGrab(disp, ButtonMotionMask | ButtonReleaseMask, cur_angle, CurrentTime); } rect_x = rx; rect_y = ry; rect_w = ev.xmotion.x - rect_x; rect_h = ev.xmotion.y - rect_y; if (rect_w == 0) ++rect_w; if (rect_h == 0) ++rect_h; if (rect_w < 0) { rect_x += rect_w; rect_w = 0 - rect_w; } if (rect_h < 0) { rect_y += rect_h; rect_h = 0 - rect_h; } /* draw rectangle */ XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } break; case ButtonPress: btn_pressed = 1; rx = ev.xbutton.x; ry = ev.xbutton.y; target = scrot_get_window(disp, ev.xbutton.subwindow, ev.xbutton.x, ev.xbutton.y); if (target == None) target = root; break; case ButtonRelease: done = 1; break; case KeyPress: fprintf(stderr, "Key was pressed, aborting shot\n"); done = 2; break; case KeyRelease: /* ignore */ break; default: break; } } if (done) break; /* now block some */ FD_ZERO(&fdset); FD_SET(xfd, &fdset); errno = 0; count = select(fdsize, &fdset, NULL, NULL, NULL); if ((count < 0) && ((errno == ENOMEM) || (errno == EINVAL) || (errno == EBADF))) { fprintf(stderr, "Connection to X display lost"); exit(EXIT_FAILURE); } } if (rect_w) { XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h); XFlush(disp); } XUngrabPointer(disp, CurrentTime); XUngrabKeyboard(disp, CurrentTime); XFreeCursor(disp, cur_cross); XFreeCursor(disp, cur_angle); XFreeGC(disp, gc); XSync(disp, True); if (opt.freeze == 1) XUngrabServer(disp); if (done < 2) { scrot_do_delay(); if (rect_w > 5) { /* if a rect has been drawn, it's an area selection */ rw = ev.xbutton.x - rx; rh = ev.xbutton.y - ry; if (rw < 0) { rx += rw; rw = 0 - rw; } if (rh < 0) { ry += rh; rh = 0 - rh; } } else { /* else it's a window click */ if (!scrot_get_geometry(target, &rx, &ry, &rw, &rh)) return NULL; } scrot_nice_clip(&rx, &ry, &rw, &rh); if (! opt.silent) XBell(disp, 0); im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1); if (opt.pointer == 1) scrot_grab_mouse_pointer(im, rx, ry); } return im; } /* clip rectangle nicely */ void scrot_nice_clip(int *rx, int *ry, int *rw, int *rh) { if (*rx < 0) { *rw += *rx; *rx = 0; } if (*ry < 0) { *rh += *ry; *ry = 0; } if ((*rx + *rw) > scr->width) *rw = scr->width - *rx; if ((*ry + *rh) > scr->height) *rh = scr->height - *ry; } /* get geometry of window and use that */ int scrot_get_geometry(Window target, int *rx, int *ry, int *rw, int *rh) { Window child; XWindowAttributes attr; int stat; /* get windowmanager frame of window */ if (target != root) { unsigned int d; int x; int status; status = XGetGeometry(disp, target, &root, &x, &x, &d, &d, &d, &d); if (status != 0) { Window rt, *children, parent; for (;;) { /* Find window manager frame. */ status = XQueryTree(disp, target, &rt, &parent, &children, &d); if (status && (children != None)) XFree((char *) children); if (!status || (parent == None) || (parent == rt)) break; target = parent; } /* Get client window. */ if (!opt.border) target = scrot_get_client_window(disp, target); XRaiseWindow(disp, target); } } stat = XGetWindowAttributes(disp, target, &attr); if ((stat == False) || (attr.map_state != IsViewable)) return 0; *rw = attr.width; *rh = attr.height; XTranslateCoordinates(disp, target, root, 0, 0, rx, ry, &child); return 1; } Window scrot_get_window(Display * display, Window window, int x, int y) { Window source, target; int status, x_offset, y_offset; source = root; target = window; if (window == None) window = root; while (1) { status = XTranslateCoordinates(display, source, window, x, y, &x_offset, &y_offset, &target); if (status != True) break; if (target == None) break; source = window; window = target; x = x_offset; y = y_offset; } if (target == None) target = window; return (target); } char * im_printf(char *str, struct tm *tm, char *filename_im, char *filename_thumb, Imlib_Image im) { char *c; char buf[20]; char ret[4096]; char strf[4096]; char *tmp; struct stat st; ret[0] = '\0'; if (strftime(strf, 4095, str, tm) == 0) { fprintf(stderr, "strftime returned 0\n"); exit(EXIT_FAILURE); } for (c = strf; *c != '\0'; c++) { if (*c == '$') { c++; switch (*c) { case 'a': gethostname(buf, sizeof(buf)); strcat(ret, buf); break; case 'f': if (filename_im) strcat(ret, filename_im); break; case 'm': /* t was allready taken, so m as in mini */ if (filename_thumb) strcat(ret, filename_thumb); break; case 'n': if (filename_im) { tmp = strrchr(filename_im, '/'); if (tmp) strcat(ret, tmp + 1); else strcat(ret, filename_im); } break; case 'w': snprintf(buf, sizeof(buf), "%d", gib_imlib_image_get_width(im)); strcat(ret, buf); break; case 'h': snprintf(buf, sizeof(buf), "%d", gib_imlib_image_get_height(im)); strcat(ret, buf); break; case 's': if (filename_im) { if (!stat(filename_im, &st)) { int size; size = st.st_size; snprintf(buf, sizeof(buf), "%d", size); strcat(ret, buf); } else strcat(ret, "[err]"); } break; case 'p': snprintf(buf, sizeof(buf), "%d", gib_imlib_image_get_width(im) * gib_imlib_image_get_height(im)); strcat(ret, buf); break; case 't': tmp = gib_imlib_image_format(im); if (tmp) { strcat(ret, gib_imlib_image_format(im)); } break; case '$': strcat(ret, "$"); break; default: strncat(ret, c, 1); break; } } else if (*c == '\\') { c++; switch (*c) { case 'n': if (filename_im) strcat(ret, "\n"); break; default: strncat(ret, c, 1); break; } } else { const size_t len = strlen(ret); ret[len] = *c; ret[len + 1] = '\0'; } } return gib_estrdup(ret); } Window scrot_get_client_window(Display * display, Window target) { Atom state; Atom type = None; int format, status; unsigned char *data; unsigned long after, items; Window client; state = XInternAtom(display, "WM_STATE", True); if (state == None) return target; status = XGetWindowProperty(display, target, state, 0L, 0L, False, (Atom) AnyPropertyType, &type, &format, &items, &after, &data); if ((status == Success) && (type != None)) return target; client = scrot_find_window_by_property(display, target, state); if (!client) return target; return client; } Window scrot_find_window_by_property(Display * display, const Window window, const Atom property) { Atom type = None; int format, status; unsigned char *data; unsigned int i, number_children; unsigned long after, number_items; Window child = None, *children, parent, root; status = XQueryTree(display, window, &root, &parent, &children, &number_children); if (!status) return None; for (i = 0; (i < number_children) && (child == None); i++) { status = XGetWindowProperty(display, children[i], property, 0L, 0L, False, (Atom) AnyPropertyType, &type, &format, &number_items, &after, &data); if (data) XFree(data); if ((status == Success) && (type != (Atom) NULL)) child = children[i]; } for (i = 0; (i < number_children) && (child == None); i++) child = scrot_find_window_by_property(display, children[i], property); if (children != None) XFree(children); return (child); } Imlib_Image scrot_grab_shot_multi(void) { int screens; int i; char *dispstr, *subdisp; char newdisp[255]; gib_list *images = NULL; Imlib_Image ret = NULL; screens = ScreenCount(disp); if (screens < 2) return scrot_grab_shot(); dispstr = DisplayString(disp); subdisp = gib_estrdup(DisplayString(disp)); for (i = 0; i < screens; i++) { dispstr = strchr(subdisp, ':'); if (dispstr) { dispstr = strchr(dispstr, '.'); if (NULL != dispstr) *dispstr = '\0'; } snprintf(newdisp, sizeof(newdisp), "%s.%d", subdisp, i); init_x_and_imlib(newdisp, i); ret = gib_imlib_create_image_from_drawable(root, 0, 0, 0, scr->width, scr->height, 1); images = gib_list_add_end(images, ret); } free(subdisp); ret = stalk_image_concat(images); return ret; } Imlib_Image stalk_image_concat(gib_list * images) { int tot_w = 0, max_h = 0, w, h; int x = 0; gib_list *l, *item; Imlib_Image ret, im; if (gib_list_length(images) == 0) return NULL; l = images; while (l) { im = (Imlib_Image) l->data; h = gib_imlib_image_get_height(im); w = gib_imlib_image_get_width(im); if (h > max_h) max_h = h; tot_w += w; l = l->next; } ret = imlib_create_image(tot_w, max_h); gib_imlib_image_fill_rectangle(ret, 0, 0, tot_w, max_h, 255, 0, 0, 0); l = images; while (l) { im = (Imlib_Image) l->data; item = l; l = l->next; h = gib_imlib_image_get_height(im); w = gib_imlib_image_get_width(im); gib_imlib_blend_image_onto_image(ret, im, 0, 0, 0, w, h, x, 0, w, h, 1, 0, 0); x += w; gib_imlib_free_image_and_decache(im); free(item); } return ret; } scrot-1.2/src/note.c000066400000000000000000000144461352650473100144250ustar00rootroot00000000000000/* note.c Copyright 2019 Daniel T. Borelli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* This file is part of the scrot project. */ #include #include #include "scrot.h" scrotnote note; static Imlib_Font imfont = NULL; static void load_font(void); static char *parse_text(char **tok, char *const end); static char *new_text(const char *src, const size_t len); static inline void pfree(char **ptr) { free(*ptr); *ptr = NULL; } static inline void next_space(char **tok) { while (*++*tok == ' '); } static inline void next_not_space(char **tok) { while (*++*tok != ' '); } void scrot_note_new(char *format) { scrot_note_free(); note = (scrotnote){NULL,NULL,0,0,0.0,{COLOR_OPTIONAL,0,0,0,0}}; char *const end = format + strlen(format); char *tok = strpbrk(format, "-"); if ((NULL == tok) || (strlen(tok) == 1)) { malformed: pfree(&format); fprintf(stderr, "Error --note option : Malformed syntax.\n"); exit(EXIT_FAILURE); } while (tok != NULL) { const char type = *++tok; next_space(&tok); switch(type) { case 'f': { note.font = parse_text(&tok, end); if (NULL == note.font) { fprintf(stderr, "Error --note option : Malformed syntax for -f\n"); exit(EXIT_FAILURE); } char *number = strrchr(note.font, '/'); if (NULL == number) { fprintf(stderr, "Error --note option : Malformed syntax for -f, required number.\n"); exit(EXIT_FAILURE); } int fntsize = options_parse_required_number(++number); if (fntsize < 6) fprintf(stderr, "Warning: --note option: font size < 6\n"); } break; case 'x': { if ((1 != sscanf(tok, "%d", ¬e.x) || (note.x < 0))) { fprintf(stderr, "Error --note option : Malformed syntax for -x\n"); exit(EXIT_FAILURE); } next_not_space(&tok); } break; case 'y': { if ((1 != sscanf(tok, "%d", ¬e.y)) || (note.y < 0)) { fprintf(stderr, "Error --note option : Malformed syntax for -y\n"); exit(EXIT_FAILURE); } next_not_space(&tok); } break; case 'a': { if ((1 != sscanf(tok, "%lf", ¬e.angle))) { fprintf(stderr, "Error --note option : Malformed syntax for -a\n"); exit(EXIT_FAILURE); } next_not_space(&tok); } break; case 't': note.text = parse_text(&tok, end); if (NULL == note.text) { fprintf(stderr, "Error --note option : Malformed syntax for -t\n"); exit(EXIT_FAILURE); } break; case 'c': { char *saveptr = NULL; char *c = strtok_r(tok, ",", &saveptr); int nclrs = 0; note.color.status = COLOR_OK; while (c) { tok = c; int color = options_parse_required_number(c); if ((color < 0) || color > 255) { fprintf(stderr, "Error --note option : color '%d' out of range 0..255\n", color); note.color.status = COLOR_ERROR; break; } switch(++nclrs) { case 1 : note.color.r = color; case 2 : note.color.g = color; case 3 : note.color.b = color; case 4 : note.color.a = color; } c = strtok_r(NULL, ",", &saveptr); } if (nclrs != 4) { fprintf(stderr, "Error --note option : Malformed syntax for -c\n"); note.color.status = COLOR_ERROR; } } break; default: fprintf(stderr, "Error --note option : unknown option: '-%c'\n", type); exit(EXIT_FAILURE); } tok = strpbrk(tok, "-"); } if ((NULL == note.font) || (NULL == note.text)) goto malformed; load_font(); } void scrot_note_free(void) { if (note.text) pfree(¬e.text); if (note.font) pfree(¬e.font); if (imfont) { imlib_context_set_font(imfont); imlib_free_font(); } } void scrot_note_draw(Imlib_Image im) { if (NULL == im) return; imlib_context_set_image(im); imlib_context_set_font(imfont); imlib_context_set_direction(IMLIB_TEXT_TO_ANGLE); imlib_context_set_angle(note.angle); if (note.color.status == COLOR_OK) imlib_context_set_color(note.color.r, note.color.g, note.color.b, note.color.a); imlib_text_draw(note.x, note.y, note.text); } void load_font(void) { imfont = imlib_load_font(note.font); if (!imfont) { fprintf(stderr, "Error --note option : Failed to load fontname: %s\n", note.font); scrot_note_free(); exit(EXIT_FAILURE); } } char *parse_text(char **tok, char *const end) { assert(NULL != *tok); assert(NULL != end); if (**tok != '\'') return NULL; (*tok)++; char *begin = *tok; while ((*tok != end) && **tok != '\'') { (*tok)++; } ptrdiff_t len = (*tok - begin); if (len == 0) return NULL; return new_text(begin, len); } char *new_text(const char *src, const size_t len) { assert(NULL != src); char *text = malloc(len + 1); assert(NULL != text); strncpy(text, src, len); text[len] = '\0'; return text; } scrot-1.2/src/note.h000066400000000000000000000046301352650473100144240ustar00rootroot00000000000000/* note.h Copyright 2019 Daniel T. Borelli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /* This file is part of the scrot project. */ #ifndef NOTE_H #define NOTE_H #include "options.h" /* * Format: -f 'NAME/SIZE' -x NUM -y NUM -t 'TEXT' -c NUM,NUM,NUM,NUM * * -f fontname/size - absolute path * -x screen position x * -y screen position y * -t text note * -c color(red,green,blue,alpha) range 0..255 * * */ enum ecolor { COLOR_ERROR = -1, /* error parser */ COLOR_OPTIONAL = 0, /* the user did not indicate the color */ COLOR_OK = 1, /* the user indicate the color */ }; struct __scrotnote { char *font; /* font name */ char *text; /* text of the note */ int x; /* position screen (optional) */ int y; /* position screen (optional) */ double angle; /* angle text (optional) */ struct color /* (optional) */ { enum ecolor status; int r, /* red */ g, /* green */ b, /* blue */ a; /* alpha */ } color; }; extern scrotnote note; void scrot_note_new(char *format); void scrot_note_free(void); void scrot_note_draw(Imlib_Image im); #endif scrot-1.2/src/options.c000066400000000000000000000361111352650473100151440ustar00rootroot00000000000000/* options.c Copyright 1999-2000 Tom Gilbert Copyright 2008 William Vera Copyright 2009 George Danchev Copyright 2009 James Cameron Copyright 2010 Ibragimov Rinat Copyright 2017 Stoney Sauce Copyright 2019 Daniel Lublin Copyright 2019 Daniel T. Borelli Copyright 2019 Jade Auer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "scrot.h" #include "options.h" static void scrot_parse_option_array(int argc, char **argv); scrotoptions opt; void init_parse_options(int argc, char **argv) { /* Set default options */ memset(&opt, 0, sizeof(scrotoptions)); opt.quality = 75; opt.overwrite = 0; opt.line_style = LineSolid; opt.line_width = 1; /* Parse the cmdline args */ scrot_parse_option_array(argc, argv); } int options_parse_required_number(char *str) { char *end = NULL; int ret = 0; errno = 0; ret = strtol(str, &end, 10); if (str == end) { fprintf(stderr, "the option is not a number: %s\n", end); exit(EXIT_FAILURE); } if (errno) { perror("strtol"); exit(EXIT_FAILURE); } return ret; } static void options_parse_line(char *optarg) { enum {STYLE = 0, WIDTH }; char *const token[] = { [STYLE] = "style", [WIDTH] = "width", NULL }; char *subopts = optarg; char *value = NULL; while (*subopts != '\0') { switch(getsubopt(&subopts, token, &value)) { case STYLE: if (value == NULL) { fprintf(stderr, "Missing value for " "suboption '%s'\n", token[STYLE]); exit(EXIT_FAILURE); } if (!strncmp(value, "dash", 4)) opt.line_style = LineOnOffDash; else if (!strncmp(value, "solid", 5)) opt.line_style = LineSolid; else { fprintf(stderr, "Unknown value for " "suboption '%s': %s\n", token[STYLE], value); exit(EXIT_FAILURE); } break; case WIDTH: if (value == NULL) { fprintf(stderr, "Missing value for " "suboption '%s'\n", token[WIDTH]); exit(EXIT_FAILURE); } opt.line_width = options_parse_required_number(value); if (opt.line_width <= 0 || opt.line_width > 8){ fprintf(stderr, "Value of the range (1..8) for " "suboption '%s': %d\n", token[WIDTH], opt.line_width); exit(EXIT_FAILURE); } break; default: fprintf(stderr, "No match found for token: '%s'\n", value); exit(EXIT_FAILURE); break; } } /* while */ } static void scrot_parse_option_array(int argc, char **argv) { static char stropts[] = "a:ofpbcd:e:hmq:st:uv+:zn:l:"; static struct option lopts[] = { /* actions */ {"help", 0, 0, 'h'}, /* okay */ {"version", 0, 0, 'v'}, /* okay */ {"count", 0, 0, 'c'}, {"select", 0, 0, 's'}, {"focused", 0, 0, 'u'}, {"focussed", 0, 0, 'u'}, /* macquarie dictionary has both spellings */ {"border", 0, 0, 'b'}, {"multidisp", 0, 0, 'm'}, {"silent", 0, 0, 'z'}, {"pointer", 0, 0, 'p'}, {"freeze", 0, 0, 'f'}, {"overwrite", 0, 0, 'o'}, /* toggles */ {"thumb", 1, 0, 't'}, {"delay", 1, 0, 'd'}, {"quality", 1, 0, 'q'}, {"exec", 1, 0, 'e'}, {"debug-level", 1, 0, '+'}, {"autoselect", required_argument, 0, 'a'}, {"note", required_argument, 0, 'n'}, {"line", required_argument, 0, 'l'}, {0, 0, 0, 0} }; int optch = 0, cmdx = 0; /* Now to pass some optionarinos */ while ((optch = getopt_long(argc, argv, stropts, lopts, &cmdx)) != EOF) { switch (optch) { case 0: break; case 'h': show_usage(); break; case 'v': show_version(); break; case 'b': opt.border = 1; break; case 'd': opt.delay = options_parse_required_number(optarg); break; case 'e': opt.exec = gib_estrdup(optarg); break; case 'm': opt.multidisp = 1; break; case 'q': opt.quality = options_parse_required_number(optarg); break; case 's': opt.select = 1; break; case 'u': opt.focused = 1; break; case '+': opt.debug_level = options_parse_required_number(optarg); break; case 'c': opt.countdown = 1; break; case 't': options_parse_thumbnail(optarg); break; case 'z': opt.silent = 1; break; case 'p': opt.pointer = 1; break; case 'f': opt.freeze = 1; break; case 'o': opt.overwrite = 1; break; case 'a': options_parse_autoselect(optarg); break; case 'n': options_parse_note(optarg); break; case 'l': options_parse_line(optarg); break; case '?': exit(EXIT_FAILURE); default: break; } } /* Now the leftovers, which must be files */ if (optind < argc) { while (optind < argc) { /* If recursive is NOT set, but the only argument is a directory name, we grab all the files in there, but not subdirs */ if (!opt.output_file) { opt.output_file = argv[optind++]; if ( strlen(opt.output_file) > 256 ) { printf("output filename too long.\n"); exit(EXIT_FAILURE); } if (opt.thumb) opt.thumb_file = name_thumbnail(opt.output_file); } else gib_weprintf("unrecognised option %s\n", argv[optind++]); } } /* So that we can safely be called again */ optind = 1; } char * name_thumbnail(char *name) { size_t length = 0; char *new_title; char *dot_pos; size_t diff = 0; length = strlen(name) + 7; new_title = gib_emalloc(length); dot_pos = strrchr(name, '.'); if (dot_pos) { diff = (dot_pos - name) / sizeof(char); strncpy(new_title, name, diff); strcat(new_title, "-thumb"); strcat(new_title, dot_pos); } else sprintf(new_title, "%s-thumb", name); return new_title; } void options_parse_autoselect(char *optarg) { char *tok; const char tokdelim[2] = ","; int dimensions[4]; int i=0; if (strchr(optarg, ',')) /* geometry dimensions must be in format x,y,w,h */ { dimensions[i++] = options_parse_required_number(strtok(optarg, tokdelim)); while ((tok = strtok(NULL, tokdelim)) ) dimensions[i++] = options_parse_required_number(tok); opt.autoselect=1; opt.autoselect_x=dimensions[0]; opt.autoselect_y=dimensions[1]; opt.autoselect_w=dimensions[2]; opt.autoselect_h=dimensions[3]; } } void options_parse_thumbnail(char *optarg) { char *tok; if (strchr(optarg, 'x')) /* We want to specify the geometry */ { tok = strtok(optarg, "x"); opt.thumb_width = options_parse_required_number(tok); tok = strtok(NULL, "x"); if (tok) { opt.thumb_width = options_parse_required_number(optarg); opt.thumb_height = options_parse_required_number(tok); if (opt.thumb_width < 0) opt.thumb_width = 1; if (opt.thumb_height < 0) opt.thumb_height = 1; if (!opt.thumb_width && !opt.thumb_height) opt.thumb = 0; else opt.thumb = 1; } } else { opt.thumb = options_parse_required_number(optarg); if (opt.thumb < 1) opt.thumb = 1; else if (opt.thumb > 100) opt.thumb = 100; } } void options_parse_note(char *optarg) { opt.note = gib_estrdup(optarg); if (opt.note == NULL) return; if (opt.note[0] == '\0') { fprintf(stderr, "Required arguments for --note."); exit(EXIT_FAILURE); } scrot_note_new(opt.note); } void show_version(void) { printf(SCROT_PACKAGE " version " SCROT_VERSION "\n"); exit(0); } void show_mini_usage(void) { printf("Usage : " SCROT_PACKAGE " [OPTIONS]... FILE\nUse " SCROT_PACKAGE " --help for detailed usage information\n"); exit(0); } void show_usage(void) { fprintf(stdout, "Usage : " SCROT_PACKAGE " [OPTIONS]... [FILE]\n" " Where FILE is the target file for the screenshot.\n" " If FILE is not specified, a date-stamped file will be dropped in the\n" " current directory.\n" " See man " SCROT_PACKAGE " for more details\n" " -h, --help display this help and exit\n" " -v, --version output version information and exit\n" " -a, --autoselect non-interactively choose a rectangle of x,y,w,h\n" " -b, --border When selecting a window, grab wm border too\n" " -c, --count show a countdown before taking the shot\n" " -d, --delay NUM wait NUM seconds before taking a shot\n" " -e, --exec APP run APP on the resulting screenshot\n" " -q, --quality NUM Image quality (1-100) high value means\n" " high size, low compression. Default: 75.\n" " For lossless compression formats, like png,\n" " low quality means high compression.\n" " -m, --multidisp For multiple heads, grab shot from each\n" " and join them together.\n" " -s, --select interactively choose a window or rectangle\n" " with the mouse\n" " -u, --focused use the currently focused window\n" " -t, --thumb NUM generate thumbnail too. NUM is the percentage\n" " of the original size for the thumbnail to be,\n" " or the geometry in percent, e.g. 50x60 or 80x20.\n" " -z, --silent Prevent beeping\n" " -p, --pointer Capture the mouse pointer.\n" " -f, --freeze Freeze the screen when the selection is used: --select\n" " -o, --overwrite By default " SCROT_PACKAGE " does not overwrite the files, use this option to allow it.\n" " -l, --line Indicates the style of the line when the selection is used: --select\n" " See SELECTION STYLE\n" " -n, --note Draw a text note.\n" " See NOTE FORMAT\n" "\n" " SPECIAL STRINGS\n" " Both the --exec and filename parameters can take format specifiers\n" " that are expanded by " SCROT_PACKAGE " when encountered.\n" " There are two types of format specifier. Characters preceded by a '%%'\n" " are interpreted by strftime(2). See man strftime for examples.\n" " These options may be used to refer to the current date and time.\n" " The second kind are internal to " SCROT_PACKAGE " and are prefixed by '$'\n" " The following specifiers are recognised:\n" " $a hostname\n" " $f image path/filename (ignored when used in the filename)\n" " $m thumbnail path/filename\n" " $n image name (ignored when used in the filename)\n" " $s image size (bytes) (ignored when used in the filename)\n" " $p image pixel size\n" " $w image width\n" " $h image height\n" " $t image format (ignored when used in the filename)\n" " $$ prints a literal '$'\n" " \\n prints a newline (ignored when used in the filename)\n" " Example:\n" " " SCROT_PACKAGE " '%%Y-%%m-%%d_$wx$h_scrot.png' -e 'mv $f ~/images/shots/'\n" " Creates a file called something like 2000-10-30_2560x1024_scrot.png\n" " and moves it to your images directory.\n" "\n" "\n" " SELECTION STYLE\n" " When using --select you can indicate the style of the line with --line.\n" " The following specifiers are recognised:\n" " style=(solid,dash),width=(range 1 to 8)\n" " The default style are:\n" " style=solid,width=1\n" " Example:\n" " " SCROT_PACKAGE " --line style=dash,width=3 --select\n\n" "\n" " NOTE FORMAT\n" " The following specifiers are recognised for the option --note\n" " -f 'FontName/size'\n" " -t 'text'\n" " -x position (optional)\n" " -y position (optional)\n" " -c color(RGBA) (optional)\n" " -a angle (optional)\n" " Example:\n" " " SCROT_PACKAGE " --note \"-f '/usr/share/fonts/TTF/DroidSans-Bold/40' -x 10 -y 20 -c 255,0,0,255 -t 'Hi'\"\n\n" "This program is free software see the file COPYING for licensing info.\n" "Copyright Tom Gilbert 2000\n" "Email bugs to \n"); exit(0); } scrot-1.2/src/options.h000066400000000000000000000044751352650473100151610ustar00rootroot00000000000000/* options.h Copyright 1999-2000 Tom Gilbert Copyright 2009 James Cameron Copyright 2010 Ibragimov Rinat Copyright 2017 Stoney Sauce Copyright 2019 Daniel T. Borelli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef OPTIONS_H #define OPTIONS_H struct __scrotoptions { int debug_level; int delay; int countdown; int select; int focused; int quality; int border; int silent; int multidisp; int thumb; int thumb_width; int thumb_height; int pointer; int freeze; int overwrite; int line_style; int line_width; char *output_file; char *thumb_file; char *exec; char *note; int autoselect; int autoselect_x; int autoselect_y; int autoselect_h; int autoselect_w; }; void init_parse_options(int argc, char **argv); char *name_thumbnail(char *name); void options_parse_thumbnail(char *optarg); void options_parse_autoselect(char *optarg); void options_parse_note(char *optarg); int options_parse_required_number(char *str); extern scrotoptions opt; #endif scrot-1.2/src/scrot.h000066400000000000000000000071621352650473100146140ustar00rootroot00000000000000/* scrot.h Copyright 1999-2000 Tom Gilbert Copyright 2009 James Cameron Copyright 2019 Daniel T. Borelli Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef SCROT_H #define SCROT_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "scrot_config.h" #include "structs.h" #include "getopt.h" #include "debug.h" #include "note.h" #ifndef __GNUC__ # define __attribute__(x) #endif typedef void (*sighandler_t) (int); void show_usage(void); void show_version(void); void show_mini_usage(void); void init_x_and_imlib(char *dispstr, int screen_num); char *chop_file_from_full_path(char *str); Imlib_Image scrot_grab_shot(void); void scrot_exec_app(Imlib_Image image, struct tm *tm, char *filename_im, char *filename_thumb); void scrot_do_delay(void); Imlib_Image scrot_sel_and_grab_image(void); Imlib_Image scrot_grab_focused(void); void scrot_sel_area(int *x, int *y, int *w, int *h); void scrot_nice_clip(int *rx, int *ry, int *rw, int *rh); int scrot_get_geometry(Window target, int *rx, int *ry, int *rw, int *rh); Window scrot_get_window(Display *display,Window window,int x,int y); Window scrot_get_client_window(Display * display, Window target); Window scrot_find_window_by_property(Display * display, const Window window, const Atom property); char *im_printf(char *str, struct tm *tm, char *filename_im, char *filename_thumb, Imlib_Image im); Imlib_Image scrot_grab_shot_multi(void); Imlib_Image stalk_image_concat(gib_list *images); void scrot_grab_mouse_pointer(const Imlib_Image image, const int ix_off, const int iy_off); void scrot_check_if_overwrite_file(char **filename); char *scrot_have_file_extension(char *filename); /* Imlib stuff */ extern Display *disp; extern Visual *vis; extern Colormap cm; extern int depth; /* Thumbnail sizes */ extern Window root; extern Screen *scr; #endif scrot-1.2/src/stamp-h.in000066400000000000000000000000121352650473100151750ustar00rootroot00000000000000timestamp scrot-1.2/src/structs.h000066400000000000000000000024111352650473100151610ustar00rootroot00000000000000/* structs.h Copyright (C) 1999,2000 Tom Gilbert. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies of the Software and its documentation and acknowledgment shall be given in the documentation and software packages that this Software was used. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #ifndef STRUCTS_H #define STRUCTS_H typedef struct __scrotoptions scrotoptions; typedef struct __scrotnote scrotnote; #endif