Skip to content

Commit e3c0fd3

Browse files
author
Peter Hosey
committed
Changed the paste subcommand to use the argblock to store the output filename.
1 parent ce7cc94 commit e3c0fd3

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

main.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,6 @@ int paste(struct argblock *pbptr) {
550550
struct argblock these_args = *pbptr;
551551
struct argblock *these_args_ptr = &these_args;
552552

553-
const char *filename = NULL;
554553
const char *type_cstr = NULL;
555554
CFStringRef type = NULL;
556555
const char *index_cstr = NULL;
@@ -562,12 +561,12 @@ int paste(struct argblock *pbptr) {
562561
Boolean has_encountered_translate_newlines = false;
563562
UInt32 numericValue;
564563

565-
while(*(pbptr->argv) && !(filename && type_cstr && index_cstr)) {
564+
while(*(pbptr->argv) && !(pbptr->filename && type_cstr && index_cstr)) {
566565
const char *option_arg = NULL;
567566

568567
if(compare_argument('f', "file", pbptr->argv, &pbptr->argv, /*out_args_consumed*/ NULL, /*option_arg_optional*/ false, &option_arg) & option_comparison_eitheropt) {
569-
if(!filename)
570-
filename = option_arg;
568+
if(!(pbptr->filename))
569+
pbptr->filename = option_arg;
571570
else
572571
break;
573572
} else if(compare_argument('t', "type", pbptr->argv, &pbptr->argv, /*out_args_consumed*/ NULL, /*option_arg_optional*/ false, &option_arg) & option_comparison_eitheropt) {
@@ -628,17 +627,17 @@ int paste(struct argblock *pbptr) {
628627
pbptr->flags.infer_translate_newlines = true;
629628
}
630629
} else {
631-
if(filename)
630+
if(pbptr->filename)
632631
break;
633632
else
634-
filename = *((pbptr->argv)++);
633+
pbptr->filename = *((pbptr->argv)++);
635634
}
636635
}
637636
}
638637

639638
these_args = *pbptr;
640639
if(these_args_ptr->out_fd < 0)
641-
these_args_ptr->out_fd = filename ? open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644) : STDOUT_FILENO;
640+
these_args_ptr->out_fd = pbptr->filename ? open(pbptr->filename, O_WRONLY | O_CREAT | O_TRUNC, 0644) : STDOUT_FILENO;
642641
if(!these_args_ptr->type)
643642
these_args_ptr->type = kUTTypeUTF8PlainText; //Don't retain; borrow the retention by pbptr.
644643
if(!these_args_ptr->itemIndex)
@@ -652,7 +651,7 @@ int paste(struct argblock *pbptr) {
652651
close(pbptr->out_fd);
653652
pbptr->out_fd = -1;
654653
}
655-
filename = NULL;
654+
pbptr->filename = NULL;
656655
pbptr->type = NULL;
657656
++pbptr->itemIndex;
658657
}

0 commit comments

Comments
 (0)