YACP

Joshua Daniel Franklin joshuadfranklin@yahoo.com
Sun Jun 23 00:16:00 GMT 2002


> >It would be fine with me to leave the '--type TYPE' syntax as an
> >alternative to --unix, --windows, --mixed, but having the --type mixed
> >as the only way to get a forward-slash Windows path seemed counter-
> >intuitive to me. Also --type dos to me should mean short-name as well.
> >So should I put together another patch to do this as well?
>
> Actually, I think that specifying the output via --type makes things a
> little more structured.  We can't go back now, though, because users
> would complain.  It looks like I should have added a '--type unix' if
> I was going to be consistent, though.
>
> I dunno.  I don't feel really strongly about this, though.  If no one
> agrees then I don't mind changing it.

That does sound like a better idea. This patch is therefore better.
It fleshes out the --type option so that one can specify: 'dos', 'mixed',
'unix', or 'windows'. The 'dos' type includes short-name. While I was
at it, I added a --dos option which is the same as --windows --short-name.
It's too bad about the feature bloat, but having both should satisfy both
structure and users.

I feel good about changing the default action to --unix since before
-u or -w was required in every case, so the only thing it would change
(to users) is if before they were always typing something like
'cygpath c:' and getting errors now they will get UNIXy path output.

I also corrected an apparent bug in the long_options that prevented
"close", "file" and "type" from working, even though -c, -f, and -t
did. I'm not intimate with getopt but it looks like the flag part of
long_options struct should be set to NULL if you're using the optarg.

ChangeLog:

2002-06-22  Joshua Daniel Franklin <joshuadfranklin@yahoo.com>

	* cygpath.cc (long_options): Add "dos" and "mixed", correct
	"close", "file" and "type" to use NULL flag.
	(usage): Clean up usage output (more), accomodate new options.
	(main): Add --dos and --mixed options; accomodate all output
	forms in --type. Make UNIXy output default.

-------------- next part --------------
--- cygpath.cc-orig	Thu Jun 20 17:28:00 2002
+++ cygpath.cc	Sat Jun 22 11:35:50 2002
@@ -30,28 +30,30 @@ static int path_flag, unix_flag, windows
 static int shortname_flag, longname_flag;
 static int ignore_flag, allusers_flag, output_flag;
 static int mixed_flag;
-static const char *windows_format_arg;
+static const char *format_type_arg;
 
 static struct option long_options[] = {
-  {(char *) "help", no_argument, NULL, 'h'},
   {(char *) "absolute", no_argument, NULL, 'a'},
+  {(char *) "close", required_argument, NULL, 'c'},
+  {(char *) "dos", no_argument, NULL, 'd'},
+  {(char *) "file", required_argument, NULL, 'f'},
+  {(char *) "help", no_argument, NULL, 'h'},
+  {(char *) "ignore", no_argument, NULL, 'i'},
+  {(char *) "long-name", no_argument, NULL, 'l'},
+  {(char *) "mixed", no_argument, NULL, 'm'},
   {(char *) "option", no_argument, NULL, 'o'},
   {(char *) "path", no_argument, NULL, 'p'},
-  {(char *) "close", required_argument, (int *) &close_arg, 'c'},
+  {(char *) "short-name", no_argument, NULL, 's'},
+  {(char *) "type", required_argument, NULL, 't'},
   {(char *) "unix", no_argument, NULL, 'u'},
-  {(char *) "file", required_argument, (int *) &file_arg, 'f'},
   {(char *) "version", no_argument, NULL, 'v'},
   {(char *) "windows", no_argument, NULL, 'w'},
-  {(char *) "short-name", no_argument, NULL, 's'},
-  {(char *) "long-name", no_argument, NULL, 'l'},
-  {(char *) "windir", no_argument, NULL, 'W'},
-  {(char *) "sysdir", no_argument, NULL, 'S'},
-  {(char *) "ignore", no_argument, NULL, 'i'},
   {(char *) "allusers", no_argument, NULL, 'A'},
   {(char *) "desktop", no_argument, NULL, 'D'},
-  {(char *) "smprograms", no_argument, NULL, 'P'},
-  {(char *) "type", required_argument, (int *) &windows_format_arg, 't'},
   {(char *) "homeroot", no_argument, NULL, 'H'},
+  {(char *) "smprograms", no_argument, NULL, 'P'},
+  {(char *) "sysdir", no_argument, NULL, 'S'},
+  {(char *) "windir", no_argument, NULL, 'W'},
   {0, no_argument, 0, 0}
 };
 
@@ -60,33 +62,41 @@ usage (FILE * stream, int status)
 {
   if (!ignore_flag || !status)
     fprintf (stream, "\
-Usage: %s (-u|-w|-t TYPE) [-c HANDLE] [-f FILE] [options] NAME\n\n\
-       %s [-ADHPSW] \n\n\
-Output type options (required):\n\
-  -u|--unix		print Unix form of NAME (default)\n\
-  -w|--windows		print Windows form of NAME \n\n\
-  -t|--type             print Windows form of NAME with TYPE one of\n\
-     dos                drive letter with backslashes (C:\\WINNT)\n\
-     mixed              drive letter with regular slashes (C:/WINNT)\n\
+Usage: %s (-d|-m|-u|-w|-t TYPE) [-c HANDLE] [-f FILE] [options] NAME\n\
+       %s [-ADHPSW] \n\
+Output type options:\n\
+  -d, --dos	        print DOS (short) form of NAME (C:\\PROGRA~1\\)\n\
+  -m, --mixed           like --windows, but with regular slashes (C:/WINNT)\n\
+  -u, --unix	        (default) print Unix form of NAME (/cygdrive/c/winnt)\n\
+  -w, --windows         print Windows form of NAME (C:\\WINNT)\n\
+  -t, --type TYPE       print TYPE form: 'dos', 'mixed', 'unix', or 'windows'\n\
 Path conversion options:\n\
-  -a|--absolute		output absolute path\n\
-  -c|--close HANDLE     close HANDLE (for use in captured process)\n\
-  -f|--file FILE        read FILE for input; use - to read from STDIN\n\
-  -i|--ignore		ignore missing argument\n\
-  -l|--long-name	print Windows long form of NAME (with -w only)\n\
-  -p|--path		NAME is a PATH list (i.e., '/bin:/usr/bin')\n\
-  -s|--short-name	print Windows short form of NAME (with -w only)\n\
-System information output:\n\
-  -A|--allusers		use `All Users' instead of current user for -D, -P\n\
-  -D|--desktop		output `Desktop' directory and exit\n\
-  -H|--homeroot		output `Profiles' directory (home root) and exit\n\
-  -P|--smprograms	output Start Menu `Programs' directory and exit\n\
-  -S|--sysdir		output system directory and exit\n\
-  -W|--windir		output `Windows' directory and exit\n\n\
+  -a, --absolute        output absolute path\n\
+  -l, --long-name	print Windows long form of NAME (with -w, -m only)\n\
+  -p, --path	        NAME is a PATH list (i.e., '/bin:/usr/bin')\n\
+  -s, --short-name	print DOS (short) form of NAME (with -w, -m only)\n\
+System information:\n\
+  -A, --allusers        use `All Users' instead of current user for -D, -P\n\
+  -D, --desktop		output `Desktop' directory and exit\n\
+  -H, --homeroot        output `Profiles' directory (home root) and exit\n\
+  -P, --smprograms	output Start Menu `Programs' directory and exit\n\
+  -S, --sysdir		output system directory and exit\n\
+  -W, --windir		output `Windows' directory and exit\n\
+", prog_name, prog_name);
+  if (stream == stdout)
+    {
+    fprintf (stream, "\
 Other options:\n\
-  -h|--help             output usage information and exit\n\
-  -v|--version		output version information and exit\n\
-  ", prog_name, prog_name);
+  -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\
+  -i, --ignore		ignore missing argument\n\
+  -h, --help            output usage information and exit\n\
+  -v, --version		output version information and exit\
+");
+    }
+  else
+    fprintf(stream, "Try `%s --help' for more information.", prog_name);
   exit (ignore_flag ? 0 : status);
 }
 
@@ -543,7 +553,7 @@ main (int argc, char **argv)
     prog_name++;
 
   path_flag = 0;
-  unix_flag = 0;
+  unix_flag = 1;
   windows_flag = 0;
   shortname_flag = 0;
   longname_flag = 0;
@@ -552,7 +562,7 @@ main (int argc, char **argv)
   options_from_file_flag = 0;
   allusers_flag = 0;
   output_flag = 0;
-  while ((c = getopt_long (argc, argv, (char *) "hac:f:opslSuvwt:WiDPAH",
+  while ((c = getopt_long (argc, argv, (char *) "ac:df:hilmopst:uvwADHPSW",
 			   long_options, (int *) NULL)) != EOF)
     {
       switch (c)
@@ -565,6 +575,14 @@ main (int argc, char **argv)
 	  CloseHandle ((HANDLE) strtoul (optarg, NULL, 16));
 	  break;
 
+	case 'd':
+	  if (windows_flag) 
+	    usage (stderr, 1);
+	  unix_flag = 0;
+	  windows_flag = 1;
+	  shortname_flag = 1;
+	  break;
+
 	case 'f':
 	  file_arg = optarg;
 	  break;
@@ -578,40 +596,63 @@ main (int argc, char **argv)
 	  break;
 
 	case 'u':
-	  if (unix_flag || windows_flag)
+	  if (windows_flag || mixed_flag)
 	    usage (stderr, 1);
 	  unix_flag = 1;
 	  break;
 
 	case 'w':
-	  if (unix_flag || windows_flag)
+	  if (windows_flag || mixed_flag)
 	    usage (stderr, 1);
+	  unix_flag = 0;
+	  windows_flag = 1;
+	  break;
+
+	 case 'm':
+	  unix_flag = 0;
 	  windows_flag = 1;
+	  mixed_flag = 1;
 	  break;
 
 	case 'l':
-	  if (unix_flag || shortname_flag)
-	    usage (stderr, 1);
 	  longname_flag = 1;
 	  break;
 
 	case 's':
-	  if (unix_flag || longname_flag)
-	    usage (stderr, 1);
 	  shortname_flag = 1;
 	  break;
 
 	 case 't':
-	  if (unix_flag || (optarg == NULL))
+	  if (optarg == NULL)
 	    usage (stderr, 1);
 
-	  windows_flag = 1;
-	  windows_format_arg = (*optarg == '=') ? (optarg + 1) : (optarg);
-
-	  if (strcasecmp (windows_format_arg, "mixed") == 0)
+	  format_type_arg = (*optarg == '=') ? (optarg + 1) : (optarg);
+	  if (strcasecmp (format_type_arg, "dos") == 0)
+            {
+            if (windows_flag || longname_flag)
+              usage (stderr, 1);
+            unix_flag = 0;
+            windows_flag = 1;
+            shortname_flag = 1;
+            }
+	  else if (strcasecmp (format_type_arg, "mixed") == 0)
+            {
+            unix_flag = 0;
 	    mixed_flag = 1;
-	  else if (strcasecmp (windows_format_arg, "dos") == 0)
-	    /* nothing */;
+            }
+	  else if (strcasecmp (format_type_arg, "unix") == 0)
+            {
+            if (windows_flag)
+              usage (stderr, 1);
+	    unix_flag = 1;
+            }
+	  else if (strcasecmp (format_type_arg, "windows") == 0)
+            {
+            if (mixed_flag)
+              usage (stderr, 1);
+            unix_flag = 0;
+            windows_flag = 1;
+            }
 	  else
 	    usage (stderr, 1);
 	  break;
@@ -652,7 +693,13 @@ main (int argc, char **argv)
   if (options_from_file_flag && !file_arg)
     usage (stderr, 1);
 
-  if (!output_flag && !unix_flag && !windows_flag && !options_from_file_flag)
+  if (longname_flag && !windows_flag)
+    usage (stderr, 1);
+
+  if (shortname_flag && !windows_flag)
+    usage (stderr, 1);
+
+  if (!unix_flag && !windows_flag && !mixed_flag && !options_from_file_flag)
     usage (stderr, 1);
 
   if (!file_arg)
@@ -714,6 +761,10 @@ main (int argc, char **argv)
 		    shortname_flag = 0;
 		    longname_flag = 1;
 		    break;
+		  case 'm':
+		    unix_flag = 0;
+		    windows_flag = 1;
+		    mixed_flag = 1;
 		  case 'w':
 		    unix_flag = 0;
 		    windows_flag = 1;


More information about the Cygwin-patches mailing list