Skip to content

Commit

Permalink
By default do not overwrite the file.
Browse files Browse the repository at this point in the history
Generate a new one: file_000.ext, file_0001.ext

Update manpage.
  • Loading branch information
daltomi authored and eribertomota committed Jun 11, 2019
1 parent 5fa034e commit 489e322
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 4 additions & 0 deletions man/scrot.1
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ Capture the mouse pointer.
.B
\fB-f\fP, \fB--freeze\fP
Freeze the screen when the selection is used: \fB--select\fP
.TP
.B
\fB-o\fP, \fB--overwrite\fP
By default \fBscrot\fP does not overwrite the files, use this option to allow it.
.RE
.PP

Expand Down
1 change: 1 addition & 0 deletions man/scrot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ OPTIONS
-z, --silent Prevent beeping.
-p, --pointer Capture the mouse pointer.
-f, --freeze Freeze the screen when the selection is used: --select
-o, --overwrite By default scrot does not overwrite the files, use this option to allow it.


SPECIAL STRINGS
Expand Down
7 changes: 3 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,16 @@ char* scrot_have_file_extension(char *filename)

void scrot_check_if_overwrite_file(char **filename)
{
const int max_count = 999;
static int count = 0;
char *curfile = *filename;

if (opt.overwrite) return;
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;
Expand Down
11 changes: 6 additions & 5 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ init_parse_options(int argc, char **argv)
memset(&opt, 0, sizeof(scrotoptions));

opt.quality = 75;
opt.overwrite = 1;
opt.overwrite = 0;

/* Parse the cmdline args */
scrot_parse_option_array(argc, argv);
Expand Down Expand Up @@ -78,7 +78,7 @@ parse_option_required_number(char *str)
static void
scrot_parse_option_array(int argc, char **argv)
{
static char stropts[] = "a:o:fpbcd:e:hmq:st:uv+:z";
static char stropts[] = "a:ofpbcd:e:hmq:st:uv+:z";
static struct option lopts[] = {
/* actions */
{"help", 0, 0, 'h'}, /* okay */
Expand All @@ -92,8 +92,8 @@ scrot_parse_option_array(int argc, char **argv)
{"silent", 0, 0, 'z'},
{"pointer", 0, 0, 'p'},
{"freeze", 0, 0, 'f'},
{"overwrite", 0, 0, 'o'},
/* toggles */
{"overwrite", 1, 0, 'o'},
{"thumb", 1, 0, 't'},
{"delay", 1, 0, 'd'},
{"quality", 1, 0, 'q'},
Expand Down Expand Up @@ -158,7 +158,7 @@ scrot_parse_option_array(int argc, char **argv)
opt.freeze = 1;
break;
case 'o':
opt.overwrite = !!parse_option_required_number(optarg);
opt.overwrite = 1;
break;
case 'a':
options_parse_autoselect(optarg);
Expand Down Expand Up @@ -324,9 +324,10 @@ show_usage(void)
" -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"
" -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 " PACKAGE " does not overwrite the files, use this option to allow it.\n"

"\n" " SPECIAL STRINGS\n"
" Both the --exec and filename parameters can take format specifiers\n"
Expand Down

1 comment on commit 489e322

@Enteee
Copy link

@Enteee Enteee commented on 489e322 Aug 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit caused: meskarune/i3lock-fancy#141

Please sign in to comment.