public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* New modes for cygpath that terminate path with null byte, nothing
@ 2012-07-27  8:08 Daniel Colascione
  2012-07-27  9:33 ` Corinna Vinschen
  2012-07-27 15:00 ` Christopher Faylor
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Colascione @ 2012-07-27  8:08 UTC (permalink / raw)
  To: cygwin-patches


[-- Attachment #1.1: Type: text/plain, Size: 530 bytes --]

I wrote this patch because I often write this:

$ cygpath -aw foo > /dev/clipboard

Today, cygpath always appends a newline to the information in the
clipboard, which is annoying when trying to paste into a program that
interprets newlines specially. This patch implements two new options:
-0/--null and -n/--no-newline. The former separates all paths output by
cygpath with a null byte; the latter separates them with nothing at all.
With -n, my example above works more smoothly and pastes don't include a
newline.


[-- Attachment #1.2: cygpath-n0.patch --]
[-- Type: text/plain, Size: 3232 bytes --]

Index: cygpath.cc
===================================================================
RCS file: /cvs/src/src/winsup/utils/cygpath.cc,v
retrieving revision 1.69
diff -u -r1.69 cygpath.cc
--- cygpath.cc	6 Jul 2012 14:52:33 -0000	1.69
+++ cygpath.cc	27 Jul 2012 08:01:19 -0000
@@ -37,6 +37,7 @@
 static char *prog_name;
 static char *file_arg, *output_arg;
 static int path_flag, unix_flag, windows_flag, absolute_flag;
+static int separator_mode; // 0 = newline, 1 = null, 2 = nothing
 static int shortname_flag, longname_flag;
 static int ignore_flag, allusers_flag, output_flag;
 static int mixed_flag, options_from_file_flag, mode_flag;
@@ -47,6 +48,8 @@
 static struct option long_options[] = {
   {(char *) "absolute", no_argument, NULL, 'a'},
   {(char *) "close", required_argument, NULL, 'c'},
+  {(char *) "no-newline", no_argument, NULL, 'n'},
+  {(char *) "null", no_argument, NULL, '0'},
   {(char *) "dos", no_argument, NULL, 'd'},
   {(char *) "file", required_argument, NULL, 'f'},
   {(char *) "help", no_argument, NULL, 'h'},
@@ -73,14 +76,14 @@
   {0, no_argument, 0, 0}
 };
 
-static char options[] = "ac:df:hilmMopst:uVwAC:DHOPSWF:";
+static char options[] = "ac:df:hilmMopst:uVwAC:DHOPSWF:n0";
 
 static void
 usage (FILE * stream, int status)
 {
   if (!ignore_flag || !status)
     fprintf (stream, "\
-Usage: %1$s (-d|-m|-u|-w|-t TYPE) [-f FILE] [OPTION]... NAME...\n\
+Usage: %1$s (-d|-m|-u|-w|-t TYPE) [-n0] [-f FILE] [OPTION]... NAME...\n\
        %1$s [-c HANDLE] \n\
        %1$s [-ADHOPSW] \n\
        %1$s [-F ID] \n\
@@ -132,6 +135,8 @@
   -f, --file FILE       read FILE for input; use - to read from STDIN\n\
   -o, --option          read options from FILE as well (for use with --file)\n\
   -c, --close HANDLE    close HANDLE (for use in captured process)\n\
+  -n, --no-newline      do not print a newline after the path\n\
+  -0, --null            print a null byte instead of a newline after each path\n\
   -i, --ignore          ignore missing argument\n\
   -h, --help            output usage information and exit\n\
   -V, --version         output version information and exit\n\
@@ -303,6 +308,29 @@
   return ret;
 }
 
+static void
+output_with_separator (const char* buf)
+{
+  fputs (buf, stdout);
+
+  switch (separator_mode)
+    {
+    case 0:
+      fputc ('\n', stdout);
+      break;
+
+    case 1:
+      fputc ('\0', stdout);
+      break;
+
+    case 2:
+      break;
+
+    default:
+      abort ();
+    }
+}
+
 static char *
 get_device_paths (char *path)
 {
@@ -621,7 +649,8 @@
       if (mixed_flag)
 	convert_slashes (buf);
     }
-  printf ("%s\n", buf);
+
+  output_with_separator (buf);
 }
 
 static void
@@ -756,7 +785,8 @@
 	}
     }
 
-  puts (print_tmp ? tmp : buf);
+  output_with_separator (print_tmp ? tmp : buf);
+  
   if (buf2)
     free (buf2);
   if (buf)
@@ -810,6 +840,14 @@
 	  CloseHandle ((HANDLE) strtoul (optarg, NULL, 16));
 	  break;
 
+        case '0':
+          separator_mode = 1;
+          break;
+
+        case 'n':
+          separator_mode = 2;
+          break;
+
 	case 'd':
 	  windows_flag = 1;
 	  shortname_flag = 1;

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New modes for cygpath that terminate path with null byte, nothing
  2012-07-27  8:08 New modes for cygpath that terminate path with null byte, nothing Daniel Colascione
@ 2012-07-27  9:33 ` Corinna Vinschen
  2012-08-14 21:49   ` Daniel Colascione
  2012-07-27 15:00 ` Christopher Faylor
  1 sibling, 1 reply; 7+ messages in thread
From: Corinna Vinschen @ 2012-07-27  9:33 UTC (permalink / raw)
  To: cygwin-patches

Hi Daniel,

On Jul 27 01:08, Daniel Colascione wrote:
> I wrote this patch because I often write this:
> 
> $ cygpath -aw foo > /dev/clipboard
> 
> Today, cygpath always appends a newline to the information in the
> clipboard, which is annoying when trying to paste into a program that
> interprets newlines specially. This patch implements two new options:
> -0/--null and -n/--no-newline. The former separates all paths output by
> cygpath with a null byte; the latter separates them with nothing at all.
> With -n, my example above works more smoothly and pastes don't include a
> newline.

Thanks for the patch.  It looks good and is a nice idea.  What's missing
is a ChangeLog entry (just the plain entry, not as part of the patch
itself) and briefly adding the new options to utils.sgml.

There's just the problem of the copyright assignment.  If you want to
provide a non-obvious patch, or if the patch adds new functionality, we
need a copyright assignment from you.  Please see the section "Before
you get started" on http://cygwin.com/contrib.html and the assignment
form http://cygwin.com/assign.txt

As soon as my manager has the assignment, I'll apply your patch.


Thanks,
Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New modes for cygpath that terminate path with null byte, nothing
  2012-07-27  8:08 New modes for cygpath that terminate path with null byte, nothing Daniel Colascione
  2012-07-27  9:33 ` Corinna Vinschen
@ 2012-07-27 15:00 ` Christopher Faylor
  1 sibling, 0 replies; 7+ messages in thread
From: Christopher Faylor @ 2012-07-27 15:00 UTC (permalink / raw)
  To: cygwin-patches

On Fri, Jul 27, 2012 at 01:08:02AM -0700, Daniel Colascione wrote:
>I wrote this patch because I often write this:
>
>$ cygpath -aw foo > /dev/clipboard
>
>Today, cygpath always appends a newline to the information in the
>clipboard, which is annoying when trying to paste into a program that
>interprets newlines specially. This patch implements two new options:
>-0/--null and -n/--no-newline. The former separates all paths output by
>cygpath with a null byte; the latter separates them with nothing at all.
>With -n, my example above works more smoothly and pastes don't include a
>newline.

You could trivially accomplish these tasks with the use of 'tr':

cygpath -aw foo | tr -d '\n' > /dev/clipboard
cygpath -aw foo | tr '\n' '\0' >/dev/clipboard

cgf

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New modes for cygpath that terminate path with null byte, nothing
  2012-07-27  9:33 ` Corinna Vinschen
@ 2012-08-14 21:49   ` Daniel Colascione
  2012-08-15  5:02     ` Christopher Faylor
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Colascione @ 2012-08-14 21:49 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 641 bytes --]

Hi Corinna,

On 7/27/2012 2:32 AM, Corinna Vinschen wrote:
> There's just the problem of the copyright assignment.  If you want to
> provide a non-obvious patch, or if the patch adds new functionality, we
> need a copyright assignment from you.  Please see the section "Before
> you get started" on http://cygwin.com/contrib.html and the assignment
> form http://cygwin.com/assign.txt
> 
> As soon as my manager has the assignment, I'll apply your patch.

Do you guys still want the patch (and papers that go with it)? If so, could I
discuss the particulars of the assignment off-list somewhere?

Thanks,
Daniel Colascione


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 259 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New modes for cygpath that terminate path with null byte, nothing
  2012-08-14 21:49   ` Daniel Colascione
@ 2012-08-15  5:02     ` Christopher Faylor
  2012-08-15  5:11       ` Daniel Colascione
  0 siblings, 1 reply; 7+ messages in thread
From: Christopher Faylor @ 2012-08-15  5:02 UTC (permalink / raw)
  To: cygwin-patches

On Tue, Aug 14, 2012 at 02:49:17PM -0700, Daniel Colascione wrote:
>On 7/27/2012 2:32 AM, Corinna Vinschen wrote:
>> There's just the problem of the copyright assignment.  If you want to
>> provide a non-obvious patch, or if the patch adds new functionality, we
>> need a copyright assignment from you.  Please see the section "Before
>> you get started" on http://cygwin.com/contrib.html and the assignment
>> form http://cygwin.com/assign.txt
>> 
>> As soon as my manager has the assignment, I'll apply your patch.
>
>Do you guys still want the patch (and papers that go with it)? If so, could I
>discuss the particulars of the assignment off-list somewhere?

As I mentioned, it seems like you can easily get the functionality
you're looking for by using standard Cygwin tools so, IMO, we don't need
your patch.

cgf

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New modes for cygpath that terminate path with null byte, nothing
  2012-08-15  5:02     ` Christopher Faylor
@ 2012-08-15  5:11       ` Daniel Colascione
  2012-08-16  8:41         ` Corinna Vinschen
  0 siblings, 1 reply; 7+ messages in thread
From: Daniel Colascione @ 2012-08-15  5:11 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 1269 bytes --]

On 8/14/12 10:02 PM, Christopher Faylor wrote:
> On Tue, Aug 14, 2012 at 02:49:17PM -0700, Daniel Colascione wrote:
>> On 7/27/2012 2:32 AM, Corinna Vinschen wrote:
>>> There's just the problem of the copyright assignment.  If you want to
>>> provide a non-obvious patch, or if the patch adds new functionality, we
>>> need a copyright assignment from you.  Please see the section "Before
>>> you get started" on http://cygwin.com/contrib.html and the assignment
>>> form http://cygwin.com/assign.txt
>>>
>>> As soon as my manager has the assignment, I'll apply your patch.
>>
>> Do you guys still want the patch (and papers that go with it)? If so, could I
>> discuss the particulars of the assignment off-list somewhere?
> 
> As I mentioned, it seems like you can easily get the functionality
> you're looking for by using standard Cygwin tools so, IMO, we don't need
> your patch.

I didn't know what the final decision was; that's why I asked. Corinna
said she wanted the patch. As for the feature itself: piping through
tr is fine, but having cygpath output paths in the desired way in the
first place keeps error information around (without pipefail, $? is
tr's exit status) and involves fewer forks. There's precedent in "echo
-n" too.


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 235 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: New modes for cygpath that terminate path with null byte, nothing
  2012-08-15  5:11       ` Daniel Colascione
@ 2012-08-16  8:41         ` Corinna Vinschen
  0 siblings, 0 replies; 7+ messages in thread
From: Corinna Vinschen @ 2012-08-16  8:41 UTC (permalink / raw)
  To: cygwin-patches

On Aug 14 22:11, Daniel Colascione wrote:
> On 8/14/12 10:02 PM, Christopher Faylor wrote:
> > On Tue, Aug 14, 2012 at 02:49:17PM -0700, Daniel Colascione wrote:
> >> On 7/27/2012 2:32 AM, Corinna Vinschen wrote:
> >>> There's just the problem of the copyright assignment.  If you want to
> >>> provide a non-obvious patch, or if the patch adds new functionality, we
> >>> need a copyright assignment from you.  Please see the section "Before
> >>> you get started" on http://cygwin.com/contrib.html and the assignment
> >>> form http://cygwin.com/assign.txt
> >>>
> >>> As soon as my manager has the assignment, I'll apply your patch.
> >>
> >> Do you guys still want the patch (and papers that go with it)? If so, could I
> >> discuss the particulars of the assignment off-list somewhere?
> > 
> > As I mentioned, it seems like you can easily get the functionality
> > you're looking for by using standard Cygwin tools so, IMO, we don't need
> > your patch.
> 
> I didn't know what the final decision was; that's why I asked. Corinna
> said she wanted the patch. As for the feature itself: piping through
> tr is fine, but having cygpath output paths in the desired way in the
> first place keeps error information around (without pipefail, $? is
> tr's exit status) and involves fewer forks. There's precedent in "echo
> -n" too.

What's your problem with the assignment form?  You can send me PM
to my address as mentioned in the ChangeLog files.


Corinna

-- 
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Project Co-Leader          cygwin AT cygwin DOT com
Red Hat

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-08-16  8:41 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-27  8:08 New modes for cygpath that terminate path with null byte, nothing Daniel Colascione
2012-07-27  9:33 ` Corinna Vinschen
2012-08-14 21:49   ` Daniel Colascione
2012-08-15  5:02     ` Christopher Faylor
2012-08-15  5:11       ` Daniel Colascione
2012-08-16  8:41         ` Corinna Vinschen
2012-07-27 15:00 ` Christopher Faylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).