]> cygwin.com Git - cygwin-apps/cygutils.git/commitdiff
Ensure uniformity of --version options.
authorCharles Wilson <cygwin@cwilson.fastmail.fm>
Wed, 6 May 2009 22:09:39 +0000 (22:09 +0000)
committerCharles Wilson <cygwin@cwilson.fastmail.fm>
Wed, 6 May 2009 22:09:39 +0000 (22:09 +0000)
12 files changed:
ChangeLog
src/ascii/ascii.c
src/banner/banner.c
src/clip/getclip.c
src/clip/putclip.c
src/conv/conv.c
src/cygstart/cygstart.c
src/dump/dump.c
src/mkshortcut/mkshortcut.c
src/readshortcut/readshortcut.1
src/readshortcut/readshortcut.c
src/realpath/realpath.c

index c8850901cb406f9040bd87100d22aa019f71a9df..f411c88477d86b91ddb85cf9a727fe3e55e91324 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-05-06  Charles Wilson  <cwilson@...>
+
+       Ensure uniformity for --version option.
+       * src/ascii/ascii.c: Ensure --version output
+       reports package version; harmonize formats.
+       * src/banner/banner.c: Ditto.
+       * src/clip/getclip.c: Ditto.
+       * src/clip/putclip.c: Ditto.
+       * src/conv/conv.c: Ditto.
+       * src/cygstart/cygstart.c: Ditto.
+       * src/dump/dump.c: Ditto.
+       * src/mkshortcut/mkshortcut.c: Ditto.
+       * src/realpath/realpath.c: Ditto.
+       * src/readshortcut/readshortcut.c: Ditto, and
+       fix line endings.
+       * src/readshortcut/readshortcut.c: Fix line
+       endings.
+
 2009-05-06  Charles Wilson  <cwilson@...>
 
        * PROGLIST: Fix typo.
index c69361ad10c0fca9064208fd1a095192b92981f3..47eb32a2fb51522f6f9bbd8f58c21689e9a7aad0 100755 (executable)
@@ -1,5 +1,5 @@
 /**
- * ascii.exe   ASCII table display
+ * ascii.c ASCII table display
  *
  * Copyright 2001,... by Charles Wilson <cwilson@ece.gatech.edu>.
  * All rights reserved.
@@ -27,9 +27,7 @@
 
 #include "common.h"
 
-static const char versionID[] = 
-    "0.1.1";
-/* for future CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
     "$Id$";
 static const char copyrightID[] =
@@ -120,7 +118,7 @@ static const char * getVersion()
 
 static void printTopDescription(FILE * f, char * name)
 {
-  fprintf(f, "%s version %s\n", name, getVersion());
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
   fprintf(f, "  Prints nicely formatted table of the ascii character set\n\n");
 }
 
@@ -163,7 +161,7 @@ static void license(poptContext optCon, FILE * f, char * name)
 {
   printTopDescription(f, name);
   printLicense(f, name);
-}  
+}
 
 static void ascii(FILE *f)
 {
index bac82e66f7817917ea3688c2c6d564f113629a7f..23802dfe4d373c300a8e6fdc0f10b4f8786a46df 100644 (file)
@@ -22,9 +22,7 @@
 
 #include "common.h"
 
-static const char versionID[] = 
-    "1.0";
-/* for future CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
     "$Id$";
 static const char copyrightID[] =
@@ -225,7 +223,7 @@ static const char * getVersion()
 
 static void printTopDescription(FILE * f, char * name)
 {
-  fprintf(f, "%s version %s\n", name, getVersion());
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
   fprintf(f, "  Prints a string enlarged as a banner on the screen.\n\n");
 }
 
@@ -275,5 +273,5 @@ static void license(poptContext optCon, FILE * f, char * name)
 {
   printTopDescription(f, name);
   printLicense(f, name);
-}  
+}
 
index 1e1d00ee31c24460e33ae81fb5afa63d22a4ca2e..b512dffb7b1c235ec6aa2a246b741a94d7d74bed 100644 (file)
@@ -35,9 +35,7 @@
 #define ENDLMODE_DOS 1
 #define ENDLMODE_NOCONV 2
 
-static const char versionID[] = 
-    "0.2.0";
-/* for future CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
     "$Id$";
 static const char copyrightID[] =
@@ -178,7 +176,7 @@ static const char * getVersion()
 
 static void printTopDescription(FILE * f, char * name)
 {
-  fprintf(f, "%s version %s\n", name, getVersion());
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
   fprintf(f, "  Copy the Windows Clipboard to stdout\n\n");
 }
 
@@ -227,7 +225,7 @@ static void license(poptContext optCon, FILE * f, char * name)
 {
   printTopDescription(f, name);
   printLicense(f, name);
-}  
+}
 
 int getclip(FILE * out, flags_struct flags, FILE * f, char * name)
 {
@@ -269,10 +267,10 @@ int getclip(FILE * out, flags_struct flags, FILE * f, char * name)
         size_t buflen = (*(size_t *) nativebuf);
         buf = nativebuf + sizeof(size_t);
         len = buflen;
-       
+
         fwrite(buf, sizeof(unsigned char), len, out);
         GlobalUnlock(hglb);
-      }      
+      }
     }
     else
     {
@@ -289,7 +287,7 @@ int getclip(FILE * out, flags_struct flags, FILE * f, char * name)
     }
     CloseClipboard();
   }
-  
+
   if (flags.endl_mode == ENDLMODE_UNIX )
   {
     /* remove the '\r' of any '\r\n' pair */
@@ -307,7 +305,7 @@ int getclip(FILE * out, flags_struct flags, FILE * f, char * name)
 
     buf = lpstr;
     len = lplen;
-  
+
     /* get some memory for the new string */
     if ((newStr = (char*)malloc((len+1)* sizeof(char))) == NULL) {
       fprintf(f,"%s: memory allocation error\n", name);
@@ -339,7 +337,7 @@ int getclip(FILE * out, flags_struct flags, FILE * f, char * name)
     GlobalUnlock(hglb);
     CloseClipboard();
   }
-  
+
   if (flags.endl_mode == ENDLMODE_DOS )
   {
     /* change all instances of [!\r]\n to \r\n */
@@ -371,7 +369,7 @@ int getclip(FILE * out, flags_struct flags, FILE * f, char * name)
       }
       prev = curr;
     }
+
     /* allocate memory for a new string */
     if ((newStr = (char*)malloc((len+cnt+1)* sizeof(char))) == NULL) {
       fprintf(stderr,"%s: memory allocation error\n", name);
index 869074cedabe49ea9bcc3958a031e48149843004..5734f7f9c4baaf40b5e3041e627b0dbbeea60ecc 100644 (file)
@@ -39,8 +39,7 @@
 #define PUTCLIP_ERR    1
 #define PUTCLIP_ARGERR 2
 
-static const char versionID[] = 
-    "0.2.0";
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
     "$Id$";
 static const char copyrightID[] =
@@ -179,7 +178,7 @@ static const char * getVersion()
 
 static void printTopDescription(FILE * f, char * name)
 {
-  fprintf(f, "%s version %s\n", name, getVersion());
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
   fprintf(f, "  Copy stdin to the Windows Clipboard\n\n");
 }
 
@@ -228,7 +227,7 @@ static void license(poptContext optCon, FILE * f, char * name)
 {
   printTopDescription(f, name);
   printLicense(f, name);
-}  
+}
 
 int putclip(FILE * in, flags_struct flags, FILE * f, char * name)
 {
@@ -285,11 +284,11 @@ int putclip(FILE * in, flags_struct flags, FILE * f, char * name)
   {
     const char* CYGWIN_NATIVE = "CYGWIN_NATIVE_CLIPBOARD";
     UINT cygnativeformat;
-    
+
     OpenClipboard(0);
     cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE);
     CloseClipboard();
-   
+
     // if flags.endl_mode == ENDLMODE_NOCONV 
     convbuf = buf;
     convlen = len;
@@ -410,16 +409,16 @@ int putclip(FILE * in, flags_struct flags, FILE * f, char * name)
       free(convbuf);
       return (PUTCLIP_ERR);
     }
-    CloseClipboard();    
+    CloseClipboard();
     if (GlobalFree(hData))
-    { 
+    {
       fprintf(f, "Couldn't free global buffer after write to clipboard.\n");
       free(convbuf);
       return (PUTCLIP_ERR);
     }
     hData = NULL;
     clipbuf = NULL;
+
     /* CF_TEXT format */
     OpenClipboard(0);
     if (!(hData = GlobalAlloc(GMEM_MOVEABLE, convlen + 2)))
@@ -434,7 +433,7 @@ int putclip(FILE * in, flags_struct flags, FILE * f, char * name)
       free(convbuf);
       return (PUTCLIP_ERR);
     }
-    
+
     memcpy(clipbuf, convbuf, convlen);
     *(clipbuf + convlen) = '\0';
     *(clipbuf + convlen + 1) = '\0';
@@ -446,9 +445,9 @@ int putclip(FILE * in, flags_struct flags, FILE * f, char * name)
       free(convbuf);
       return (PUTCLIP_ERR);
     }
-    CloseClipboard();    
+    CloseClipboard();
     if (GlobalFree(hData))
-    { 
+    {
       fprintf(f, "Couldn't free global buffer after write to clipboard.\n");
       free(convbuf);
       return (PUTCLIP_ERR);
@@ -462,7 +461,7 @@ int putclip(FILE * in, flags_struct flags, FILE * f, char * name)
   {
     OpenClipboard(0);
     EmptyClipboard();
-    CloseClipboard();    
+    CloseClipboard();
   }
   return (PUTCLIP_OK);
 }
index 91cf2a23408e0fb0bf66176b363680fa71c9c415..8ad2bb8730f694e300b7c928666b96cc6f7068a9 100755 (executable)
@@ -1,5 +1,5 @@
 /**
- * conv.exe '\n' convertor 0.1.3
+ * conv.c '\n' convertor
  *   based on hd2c 0.5.12 by Peter Hanecak (made 17.1.2001)
  *     Copyright 1997,.. by Peter Hanecak <hanecak@megaloman.com>.
  *     All rights reserved.
@@ -32,9 +32,7 @@
 
 #include "common.h"
 
-static const char versionID[] = 
-    "0.1.3";
-/* for future CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
     "$Id$";
 static const char copyrightID[] =
@@ -270,13 +268,13 @@ static int basename(char* p, const char* s)
    char* s1;
    s1 = strdup(s);
    // first, replace all \  with /
-   while (start = strchr(s1, '\\')) 
+   while (start = strchr(s1, '\\'))
      *start = '/';
    // then, locate the final /
    start = strrchr(s1, '/');
    if (!start)
      start = s1;
-   else 
+   else
      start++;   // if s ends with /, then this points to '\0'
    end = &s1[strlen(s1)];  // this points to '\0'
 
@@ -302,18 +300,18 @@ static void printTopDescription(FILE * f, char * name)
 {
   if( ( strcasecmp(name, UNIX2DOS_NAME_S) == 0 ) ||
       ( strcasecmp(name, UNIX2DOS_NAME_L) == 0 ) ) {
-    fprintf(f, "%s version %s\n", name, getVersion());
+    fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
     fprintf(f, "  converts the line endings of text files from\n");
     fprintf(f, "  UNIX style (0x0a) to DOS style (0x0d 0x0a)\n\n");
   }
   else if ( ( strcasecmp(name, DOS2UNIX_NAME_S) == 0 ) ||
             ( strcasecmp(name, DOS2UNIX_NAME_L) == 0 ) ) {
-    fprintf(f, "%s version %s\n", name, getVersion());
+    fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
     fprintf(f, "  converts the line endings of text files from\n");
     fprintf(f, "  DOS style (0x0d 0x0a) to UNIX style (0x0a)\n\n");
   }
   else {
-    fprintf(f, "%s version %s\n", name, getVersion());
+    fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
     fprintf(f, "  converts the line endings of text files to/from\n");
     fprintf(f, "  DOS style (0x0d 0x0a) and UNIX style (0x0a)\n");
     fprintf(f, "  When no conversion options are specified, the input format\n");
@@ -370,7 +368,7 @@ static void license(poptContext optCon, FILE * f, char * name)
   printTopDescription(f, name);
   printLicense(f, name);
 }
-  
+
 //  0 : continue
 //  1 : error, skip to next file
 // <0 : error, exit immediately
@@ -382,7 +380,7 @@ static int exitOnZero(const char *fn, Opt opts,
   // We may be dealing with a binary file 
   // if not using stdin, and not --safe mode, warn and bail
   if ((fn != NULL) && (opts.SafeMode == SM_SAFE)) {
-    snprintf(buf, PATH_MAX*2 - 1, 
+    snprintf(buf, PATH_MAX*2 - 1,
              "\n%s: skipping binary file %s...", opts.progname, fn);
     buf[PATH_MAX*2 - 1] = '\0';
     fputs(buf, stderr);
index 7533aa67ceaf8635bf74794cf8fe8a1b19b75858..c6049e4ea7f0bd7394adfb4c5f8302b87ea202ec 100644 (file)
@@ -45,8 +45,7 @@
 #define MSDN_URL "http://msdn.microsoft.com/library/en-us/shellcc/platform/" \
                  "Shell/reference/functions/shellexecute.asp"
 
-static const char versionID[] = "1.4";
-/* for future CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
        "$Id$";
 static const char copyrightID[] =
@@ -701,7 +700,8 @@ static const char *getVersion()
 
 static void printTopDescription(FILE *f, char *name)
 {
-    fprintf(f, "%s version %s, by %s\n", name, getVersion(), AUTHORS);
+    fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
+    fprintf(f, "%s was originally authored by %s\n", name, AUTHORS);
     fprintf(f, "\nLet Windows start a program or open a file or URL.\n\n");
 }
 
index 0bd93c0b29b163b1352349c4b9eb11d0f69c02bc..d6349113fb24fcc2a5157ebf77616cdedc396625 100644 (file)
@@ -32,9 +32,7 @@
 # include <conio.h>
 #endif
 
-static const char versionID[] = 
-    "0.1.1";
-/* for future CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
     "$Id$";
 static const char copyrightID[] =
@@ -148,7 +146,7 @@ static const char * getVersion()
 
 static void printTopDescription(FILE * f, char * name)
 {
-  fprintf(f, "%s version %s\n", name, getVersion());
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
   fprintf(f, "  Prints a hexdump of stdin or specified files to stdout\n\n");
 }
 
index d127ab8a1e18a8c69dfebd4892e05278f0af9f69..c760734b96c9d317b6d94d6b6e3b6651491c6d7d 100644 (file)
@@ -30,7 +30,7 @@
 
 #if HAVE_CONFIG_H
 #  include "config.h"
-#endif 
+#endif
 #include "common.h"
 
 #define NOCOMATTRIBUTE
@@ -43,9 +43,7 @@
 #include <popt.h>
 */
 
-static const char versionStr[] = "$Revision$";
-static const char versionID[] = "1.02.0";
-/* for CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
   "$Id$";
 static const char copyrightID[] =
@@ -71,7 +69,7 @@ typedef struct optvals_s {
 static int mkshortcut(optvals opts, poptContext optCon);
 static void printTopDescription(FILE * f, char * name);
 static void printBottomDescription(FILE * f, char * name);
-static char * getVersion(char * s, int slen);
+static const char * getVersion();
 static void usage(poptContext optCon, FILE * f, char * name);
 static void help(poptContext optCon, FILE * f, char * name);
 static void version(poptContext optCon, FILE * f, char * name);
@@ -184,7 +182,7 @@ main (int argc, const char **argv)
       case 'd':  if (arg = poptGetOptArg(optCon)) {
                    if ((opts.desc_arg = strdup(arg)) == NULL ) {
                      fprintf(stderr, "%s: memory allocation error\n", program_name);
-                     ec=2;                                            
+                     ec=2;
                      goto exit;
                    }
                  }
@@ -545,33 +543,22 @@ int mkshortcut(optvals opts, poptContext optCon)
        }
     }
   else
-    { 
+    {
       free (buf_str);
       fprintf (stderr, "%s: CoCreateInstance failed\n", program_name);
       return (3);
     }
 }
 
-static char * getVersion(char * s, int slen)
+static const char * getVersion()
 {
-  const char *v = strchr (versionStr, ':');
-
-  int len;
-  if (!v) {
-    v = "?";
-    len = 1;
-  } else {
-    v += 2;
-    len = strchr (v, ' ') - v;
-  }
-  snprintf (s,slen,"%.*s", len, v);
-  return s;
+  return versionID;
 }
 
 static void printTopDescription(FILE * f, char * name)
 {
   char s[20];
-  fprintf(f, "%s (cygutils) version %s\n", name, getVersion(s, 20));
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
   fprintf(f, "  create a Windows shortcut\n\n");
 }
 static void printBottomDescription(FILE * f, char * name)
index 213e88594dd575f241c741511aae6f9bf22c29b9..02fd0f730f8bf3818cbfbb7a9cc8f4476419f29e 100644 (file)
-.TH "READSHORTCUT" 1 "4 September 2003" "readshortcut 1.00 (cygutils)" "Cygutils"\r
-.SH NAME\r
-readshortcut \- read data from a windows shortcut (.lnk) file\r
-.\"{{{  Synopsis\r
-.SH SYNOPSIS\r
-.B readshortcut\r
-.RB [OPTION]*\r
-.RB "SHORTCUT"\r
-.BR\r
-.\"}}}\r
-.SH DESCRIPTION\r
-.B readshortcut\r
-is a command-line tool for reading Windows shortcut files (also known as\r
-OLE links). The most practical use is to resolve the target that a shortcut\r
-points to.  It can be easily run from a script or batch file for non-interactive \r
-use.\r
-\r
-.SH OPTIONS\r
-\r
-.TP \r
-\fB\-h\fR, \fB\-\-help\fR\r
-Output detailed usage information and exit.\r
-\r
-.TP \r
-\fB\-\-usage\fR\r
-Output basic usage information and exit.\r
-\r
-.TP \r
-\fB\-v\fR, \fB\-\-version\fR\r
-Display the program version and exit.\r
-\r
-.TP \r
-\fB\-\-license\fR\r
-Display the license agreement and exit.\r
-\r
-.TP \r
-\fB\-f\fR, \fB\-\-fields\fR\r
-Show field names (Target, Working Directory, Arguments, Show Command, Icon Library, Icon Library Offset, Description).\r
-\r
-.TP \r
-\fB\-u\fR, \fB\-\-unix\fR\r
-Use Unix path format for display (default).\r
-\r
-.TP \r
-\fB\-w\fR, \fB\-\-windows\fR\r
-Use Windows path format for display.\r
-\r
-.TP \r
-\fB\-t\fR, \fB\-\-target\fR\r
-Display shortcut target (default). \r
-\r
-.TP \r
-\fB\-g\fR, \fB\-\-working\fR\r
-Display shortcut working directory.\r
-\r
-.TP \r
-\fB\-r\fR, \fB\-\-args\fR\r
-Display shortcut arguments\r
-\r
-.TP \r
-\fB\-s\fR, \fB\-\-showcmd\fR\r
-Display shortcut "show" command value (Normal, Minimized, or Maximized).\r
-\r
-.TP \r
-\fB\-i\fR, \fB\-\-icon\fR\r
-Display icon library location.\r
-\r
-.TP \r
-\fB\-j\fR, \fB\-\-offset\fR\r
-Display icon library offset.\r
-\r
-.TP \r
-\fB\-d\fR, \fB\-\-desc\fR\r
-Display shortcut description.\r
-\r
-.TP \r
-\fB\-a\fR, \fB\-\-all\fR\r
-Display all information.\r
-\r
-.SH NOTES\r
-The filename (shortcut) argument may be unix (POSIX) format or Windows (C:\\) format.\r
-.PP\r
-Information extracted from the shortcut is always displayed in the following order: Target, Working Directory, Arguments, Show Command, Icon Library, Icon Library Offset, Description.  Each element appears on a separate line.\r
-\r
-.SH BUGS\r
-There may be problems if the SHORTCUT argument is longer than 256 characters\r
-\r
-.SH COPYRIGHT\r
-Copyright (C) 2003 Rob Siklos\r
-.PP\r
-\fBreadshortcut\fP is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2, or (at your option) any \r
-later version.\r
-.PP\r
-\fBreadshortcut\fP is distributed in the hope that it will be useful, but\r
-WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
-or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for \r
-more details.\r
-.PP\r
-You should have received a copy of the GNU General Public License; \r
-see the file COPYING. If not, write to the \r
-Free Software Foundation, \r
-59 Temple Place,\r
-Suite 330, Boston, MA  02111-1307, USA.\r
-\r
-.SH AUTHOR\r
-Rob Siklos, (r o b 3 @ s i k l o s . c a), Toronto, Canada\r
-\r
-.SH "SEE ALSO"\r
-.BR mkshortcut (1)\r
-.BR readlink (1) \r
+.TH "READSHORTCUT" 1 "4 September 2003" "readshortcut 1.00 (cygutils)" "Cygutils"
+.SH NAME
+readshortcut \- read data from a windows shortcut (.lnk) file
+.\"{{{  Synopsis
+.SH SYNOPSIS
+.B readshortcut
+.RB [OPTION]*
+.RB "SHORTCUT"
+.BR
+.\"}}}
+.SH DESCRIPTION
+.B readshortcut
+is a command-line tool for reading Windows shortcut files (also known as
+OLE links). The most practical use is to resolve the target that a shortcut
+points to.  It can be easily run from a script or batch file for non-interactive 
+use.
+
+.SH OPTIONS
+
+.TP 
+\fB\-h\fR, \fB\-\-help\fR
+Output detailed usage information and exit.
+
+.TP 
+\fB\-\-usage\fR
+Output basic usage information and exit.
+
+.TP 
+\fB\-v\fR, \fB\-\-version\fR
+Display the program version and exit.
+
+.TP 
+\fB\-\-license\fR
+Display the license agreement and exit.
+
+.TP 
+\fB\-f\fR, \fB\-\-fields\fR
+Show field names (Target, Working Directory, Arguments, Show Command, Icon Library, Icon Library Offset, Description).
+
+.TP 
+\fB\-u\fR, \fB\-\-unix\fR
+Use Unix path format for display (default).
+
+.TP 
+\fB\-w\fR, \fB\-\-windows\fR
+Use Windows path format for display.
+
+.TP 
+\fB\-t\fR, \fB\-\-target\fR
+Display shortcut target (default). 
+
+.TP 
+\fB\-g\fR, \fB\-\-working\fR
+Display shortcut working directory.
+
+.TP 
+\fB\-r\fR, \fB\-\-args\fR
+Display shortcut arguments
+
+.TP 
+\fB\-s\fR, \fB\-\-showcmd\fR
+Display shortcut "show" command value (Normal, Minimized, or Maximized).
+
+.TP 
+\fB\-i\fR, \fB\-\-icon\fR
+Display icon library location.
+
+.TP 
+\fB\-j\fR, \fB\-\-offset\fR
+Display icon library offset.
+
+.TP 
+\fB\-d\fR, \fB\-\-desc\fR
+Display shortcut description.
+
+.TP 
+\fB\-a\fR, \fB\-\-all\fR
+Display all information.
+
+.SH NOTES
+The filename (shortcut) argument may be unix (POSIX) format or Windows (C:\\) format.
+.PP
+Information extracted from the shortcut is always displayed in the following order: Target, Working Directory, Arguments, Show Command, Icon Library, Icon Library Offset, Description.  Each element appears on a separate line.
+
+.SH BUGS
+There may be problems if the SHORTCUT argument is longer than 256 characters
+
+.SH COPYRIGHT
+Copyright (C) 2003 Rob Siklos
+.PP
+\fBreadshortcut\fP is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option) any 
+later version.
+.PP
+\fBreadshortcut\fP 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 General Public License for 
+more details.
+.PP
+You should have received a copy of the GNU General Public License; 
+see the file COPYING. If not, write to the 
+Free Software Foundation, 
+59 Temple Place,
+Suite 330, Boston, MA  02111-1307, USA.
+
+.SH AUTHOR
+Rob Siklos, (r o b 3 @ s i k l o s . c a), Toronto, Canada
+
+.SH "SEE ALSO"
+.BR mkshortcut (1)
+.BR readlink (1) 
index 8cdd0441f20dfc7bbcb95e320f95ec730df13118..2537bd54f4cce73db91844ac5c5b70b67572c3cd 100644 (file)
-/* \r
- * readshortcut for cygwin/windows\r
- *\r
- * Copyright (C) 2003 Rob Siklos\r
- * http://www.cygwin.com/ml/cygwin/2003-08/msg00640.html\r
- *\r
- * This program is free software; you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation in version 2 of the License.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
- */\r
\r
-\r
\r
- /* http://www.rpm.org/dark_corners/popt/\r
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_int/shell_int_programming/shortcuts/shortcut.asp\r
- */\r
-\r
-/* how to compile a standalone version:\r
- *\r
- * - comment the config.h and common.h includes\r
- * - uncomment the stdio and popt.h includes\r
- * - run "gcc readshortcut.c -o readshortcut.exe -lpopt -luuid -lole32" \r
- *\r
- */\r
-\r
-\r
-#if HAVE_CONFIG_H\r
-#include "config.h"\r
-#endif\r
-#include "common.h"\r
-\r
-/* moved to common.h */\r
-/*\r
-#include <stdio.h>\r
-#include <popt.h>\r
-*/\r
-\r
-#include <shlobj.h>\r
-#include <olectlid.h>\r
-\r
-#define PATH_UNIX 0\r
-#define PATH_WIN  1\r
-\r
-#define ERR_NONE 0\r
-#define ERR_USER 1\r
-#define ERR_SYS  2\r
-#define ERR_WIN  3\r
-\r
-#define SLGP_RAWPATH 0\r
-#define SW_SHOWMINIMIZED_SEVEN 7\r
-\r
-#define BUFF_SIZE 1024\r
-\r
-static const char versionID[] = "1.0";\r
-\r
-typedef struct optvals_s {\r
-  char * target_fname;  \r
-\r
-  int show_field_names;\r
-  int pathType;\r
-  \r
-  int show_target;\r
-  int show_working_dir;\r
-  int show_args;\r
-  int show_showCmd;\r
-  int show_icon;\r
-  int show_icon_offset;\r
-  int show_desc;\r
-  int show_all;\r
-\r
-} optvals;\r
-\r
-void cygwin_conv_to_full_win32_path(const char *path, char *win32_path);\r
-void cygwin_conv_to_full_posix_path(const char *path, char *posix_path);\r
-\r
-static void printTopDescription(FILE * f, char * name);\r
-static void printBottomDescription(FILE * f, char * name);\r
-static const char * getVersion(void);\r
-static void usage(poptContext optCon, FILE * f, char * name);\r
-static void help(poptContext optCon, FILE * f, char * name);\r
-static void version(poptContext optCon, FILE * f, char * name);\r
-static void license(poptContext optCon, FILE * f, char * name);\r
-\r
-void formatPath (char * strPath, int format);\r
-int readshortcut(optvals *opts, poptContext optContext);\r
-\r
-static char *program_name;\r
-\r
-int main (int argc, const char **argv) {\r
-  poptContext optContext;\r
-  const char ** loose_args;\r
-  int rc;\r
-  int result = ERR_NONE;\r
-  optvals opts;\r
-  const char *tmp_str;\r
-\r
-  struct poptOption infoOptionsTable[] = {\r
-    { "help",  'h',  POPT_ARG_NONE, NULL, '?', "This message", NULL},\r
-    { "usage", '\0', POPT_ARG_NONE, NULL, 'u', "Program usage", NULL},\r
-    { "version", 'v', POPT_ARG_NONE, NULL, 'v', "Version information", NULL},\r
-    { "license", '\0', POPT_ARG_NONE, NULL, 'l', "License information", NULL},\r
-    { NULL, '\0', 0, NULL, 0, NULL, NULL }\r
-  };\r
-\r
-  struct poptOption outputOptionsTable[] = {\r
-    { "fields",  'f', POPT_ARG_VAL, &(opts.show_field_names), 1, "Show field names", NULL},\r
-    { "unix",    'u', POPT_ARG_VAL, &(opts.pathType), PATH_UNIX, "Use Unix path format for display (default)", NULL},\r
-    { "windows", 'w', POPT_ARG_VAL, &(opts.pathType), PATH_WIN, "Use Windows path format for display ", NULL},\r
-    { "target",  't', POPT_ARG_VAL, &(opts.show_target),      1, "Display shortcut target", NULL},\r
-    { "working", 'g', POPT_ARG_VAL, &(opts.show_working_dir), 1, "Display shortcut working directory", NULL},\r
-    { "args",    'r', POPT_ARG_VAL, &(opts.show_args),        1, "Display shortcut arguments", NULL},\r
-    { "showcmd", 's', POPT_ARG_VAL, &(opts.show_showCmd),     1, "Display shortcut \"show\" command value", NULL},\r
-    { "icon",    'i', POPT_ARG_VAL, &(opts.show_icon),        1, "Display icon library location", NULL},\r
-    { "offset",  'j', POPT_ARG_VAL, &(opts.show_icon_offset), 1, "Display icon library offset", NULL},\r
-    { "desc",    'd', POPT_ARG_VAL, &(opts.show_desc),        1, "Display shortcut description", NULL},\r
-    { "all",     'a', POPT_ARG_VAL, &(opts.show_all),         1, "Display all information", NULL},\r
-    { NULL, '\0', 0, NULL, 0, NULL, NULL }\r
-  };\r
-  \r
-  struct poptOption opt[] = {\r
-    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, outputOptionsTable, 0, "Output options", NULL },\r
-    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, infoOptionsTable, 0, "Information options (display a message and exit)", NULL },\r
-    { NULL, '\0', 0, NULL, 0, NULL, NULL }\r
-  };\r
-\r
-  /* get the program name */\r
-  tmp_str = strrchr (argv[0], '/');\r
-  if (tmp_str == NULL) { tmp_str = strrchr (argv[0], '\\'); }\r
-  if (tmp_str == NULL) { tmp_str = argv[0]; }\r
-  else { tmp_str++; }\r
-  if ((program_name = strdup(tmp_str)) == NULL ) {\r
-    fprintf(stderr, "%s: memory allocation error\n", argv[0]);\r
-    exit(ERR_SYS);\r
-  }\r
-\r
-  /* set default values for options */\r
-  opts.target_fname = NULL;\r
-\r
-  opts.show_field_names = 0;\r
-  opts.pathType = PATH_UNIX;\r
-  \r
-  opts.show_target = 0;\r
-  opts.show_working_dir = 0;\r
-  opts.show_args = 0;\r
-  opts.show_showCmd = 0;\r
-  opts.show_icon = 0;\r
-  opts.show_icon_offset = 0;\r
-  opts.show_desc = 0;\r
-  opts.show_all = 0;\r
-\r
-  /* set the pOpt context and help line */\r
-  optContext = poptGetContext(NULL, argc, argv, opt, 0);\r
-  poptSetOtherOptionHelp(optContext, "[OPTION]* SHORTCUT");\r
-  \r
-  while ((rc = poptGetNextOpt(optContext)) > 0) {\r
-    switch (rc) {\r
-      case '?':\r
-        help(optContext, stdout, program_name);\r
-        goto exit;\r
-      case 'u':\r
-        usage(optContext, stdout, program_name);\r
-        goto exit;\r
-      case 'v':\r
-        version(optContext, stdout, program_name);\r
-        goto exit;\r
-      case 'l':\r
-        license(optContext, stdout, program_name);\r
-        goto exit;\r
-    }\r
-  }\r
-  \r
-  // set show_target by default\r
-  if (!(opts.show_all + opts.show_target + opts.show_working_dir + opts.show_args + \r
-        opts.show_showCmd + opts.show_icon + opts.show_icon_offset + \r
-        opts.show_desc)) { opts.show_target = 1; }\r
-\r
-  /* get the remaining arguments */\r
-  loose_args = poptGetArgs(optContext);\r
-\r
-  if (loose_args && *loose_args) {\r
-    if ((opts.target_fname = strdup(*loose_args)) == NULL) {\r
-      fprintf(stderr, "%s: memory allocation error\n", program_name);\r
-      result = ERR_SYS;\r
-      goto exit;\r
-    }\r
-    loose_args++;\r
-    if (loose_args && *loose_args) {\r
-      fprintf(stderr, "%s: Too many arguments: ", program_name);\r
-      while (*loose_args) { fprintf(stderr, "%s ", *loose_args++); }\r
-      fprintf(stderr, "\n"); \r
-      usage(optContext, stderr, program_name);\r
-      result = ERR_USER;\r
-    } else {\r
-      /************** Main Program ***********/\r
-      result = readshortcut(&opts, optContext);\r
-    }    \r
-  } else {\r
-    fprintf(stderr, "%s: SHORTCUT not specified\n", program_name);\r
-    usage(optContext, stderr, program_name);\r
-    result = ERR_USER;\r
-  }\r
-\r
-exit:\r
-  poptFreeContext(optContext);\r
-  free(program_name);\r
-  free(opts.target_fname);\r
-  return result;\r
-}\r
-\r
-int readshortcut(optvals *opts, poptContext optContext) {\r
-  HRESULT hres;\r
-  IShellLink *shell_link;\r
-  IPersistFile *persist_file;\r
-  char strPath[MAX_PATH]; \r
-  char strBuff[BUFF_SIZE];\r
-  int iBuff;\r
-\r
-  int result = ERR_NONE;  /* the value to return on exit */\r
-  \r
-  /*  Add suffix to link name if necessary */\r
-  if (strlen (opts->target_fname) > 4) {\r
-    int tmp = strlen (opts->target_fname) - 4;\r
-    if (strncmp (opts->target_fname + tmp, ".lnk", 4) != 0) {\r
-      opts->target_fname = (char *)realloc(opts->target_fname, strlen(opts->target_fname) + 1 + 4);\r
-      if (opts->target_fname == NULL) {\r
-        fprintf(stderr, "%s: memory allocation error\n", program_name);\r
-        return (ERR_SYS);\r
-      }\r
-      strcat (opts->target_fname, ".lnk");\r
-    }\r
-  }\r
-  else {\r
-    opts->target_fname = (char *)realloc(opts->target_fname, strlen(opts->target_fname) + 1 + 4);\r
-    if (opts->target_fname == NULL) {\r
-      fprintf(stderr, "%s: memory allocation error\n", program_name);\r
-      return (ERR_SYS);\r
-    }\r
-    strcat (opts->target_fname, ".lnk");\r
-  }\r
-\r
-  /* if there's no colon in the path, it's POSIX and we should convert to win32 */\r
-  if (strchr (opts->target_fname, ':') == NULL) {\r
-    char *strTmpPath = (char*)malloc(MAX_PATH);\r
-    if (strTmpPath == NULL) {\r
-      fprintf(stderr, "%s: memory allocation error\n", program_name);\r
-      return (ERR_SYS);\r
-    }\r
-    cygwin_conv_to_full_win32_path (opts->target_fname, strTmpPath);\r
-    free (opts->target_fname);\r
-    opts->target_fname = strTmpPath;\r
-  }\r
-\r
-  hres = OleInitialize (NULL);\r
-  if (hres != S_FALSE && hres != S_OK) {\r
-    fprintf (stderr, "%s: Could not initialize OLE interface\n", program_name);\r
-    return (ERR_WIN);\r
-  }\r
-\r
-  /* Get a pointer to the IShellLink interface. */\r
-  hres = CoCreateInstance (&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **) &shell_link); \r
-\r
-  if (!SUCCEEDED(hres)) {\r
-    fprintf (stderr, "%s: CoCreateInstance failed\n", program_name);\r
-    return (ERR_WIN);\r
-  }\r
-\r
-  /* Get a pointer to the IPersistFile interface. */\r
-  hres = shell_link->lpVtbl->QueryInterface(shell_link, &IID_IPersistFile, (void **) &persist_file);\r
-\r
-  if (SUCCEEDED(hres)) {\r
-    WCHAR wsz[MAX_PATH]; \r
\r
-    /* Ensure that the string is Unicode. */\r
-    MultiByteToWideChar(CP_ACP, 0, (LPCSTR)opts->target_fname, -1, wsz, MAX_PATH); \r
-\r
-    /* Load the shortcut.  */\r
-    hres = persist_file->lpVtbl->Load(persist_file, wsz, STGM_READ); \r
-\r
-    if (SUCCEEDED(hres)) {\r
-      /* read stuff from the link object and print it to the screen */\r
-      if (opts->show_all || opts->show_target) {\r
-        shell_link->lpVtbl->GetPath(shell_link, strPath, MAX_PATH, NULL, SLGP_RAWPATH);\r
-        if (opts->show_field_names) { printf("Target: "); }\r
-        formatPath(strPath, opts->pathType);\r
-        printf("%s\n", strPath);\r
-      }\r
-      if (opts->show_all || opts->show_working_dir) {\r
-        shell_link->lpVtbl->GetWorkingDirectory(shell_link, strPath, MAX_PATH);\r
-        if (opts->show_field_names) { printf("Working Directory: "); }\r
-        formatPath(strPath, opts->pathType);\r
-        printf("%s\n", strPath);\r
-      }\r
-      if (opts->show_all || opts->show_args) {\r
-        shell_link->lpVtbl->GetArguments(shell_link, strBuff, BUFF_SIZE);\r
-        if (opts->show_field_names) { printf("Arguments: "); }\r
-        printf("%s\n", strBuff);\r
-      }\r
-      if (opts->show_all || opts->show_showCmd) {\r
-        shell_link->lpVtbl->GetShowCmd(shell_link, &iBuff);\r
-        if (opts->show_field_names) { printf("Show Command: "); }\r
-\r
-        switch (iBuff) {\r
-          case SW_SHOWNORMAL:\r
-            printf("Normal\n");\r
-            break;\r
-          case SW_SHOWMINIMIZED:\r
-          case SW_SHOWMINIMIZED_SEVEN:\r
-            printf("Minimized\n");\r
-            break;\r
-          case SW_SHOWMAXIMIZED:\r
-            printf("Maximized\n");\r
-            break;\r
-        }\r
-      }\r
-      if (opts->show_all || opts->show_icon || opts->show_icon_offset) {\r
-        shell_link->lpVtbl->GetIconLocation(shell_link, strPath, MAX_PATH, &iBuff);\r
-        if (opts->show_all || opts->show_icon) {\r
-          if (opts->show_field_names) { printf("Icon Library: "); }\r
-          formatPath(strPath, opts->pathType);\r
-          printf("%s\n", strPath);\r
-      }\r
-        if (opts->show_all || opts->show_icon_offset) {\r
-          if (opts->show_field_names) { printf("Icon Library Offset: "); }\r
-          printf("%d\n", iBuff);\r
-        }\r
-      }\r
-      if (opts->show_all || opts->show_desc) {\r
-        shell_link->lpVtbl->GetDescription(shell_link, strBuff, BUFF_SIZE);\r
-        if (opts->show_field_names) { printf("Description: "); }\r
-        printf("%s\n", strBuff);\r
-      }\r
-    }\r
-    else {\r
-      fprintf (stderr, "%s: Load failed on %s\n", program_name, opts->target_fname);\r
-      result = ERR_WIN;\r
-    }\r
-\r
-    /* Release the pointer to the IPersistFile interface. */\r
-    persist_file->lpVtbl->Release(persist_file);\r
-  }\r
-  else { \r
-    fprintf (stderr, "%s: QueryInterface failed\n", program_name);\r
-    result = ERR_WIN;\r
-  }\r
-  \r
-  /* Release the pointer to the IShellLink interface. */\r
-  shell_link->lpVtbl->Release(shell_link);\r
-\r
-  return(result);\r
-}\r
-\r
-/* change the path to the proper format */\r
-void formatPath (char * strPath, int format) {\r
-  if (format == PATH_WIN) { return; } /* windows is the default */\r
-  else {\r
-    // convert to posix path\r
-    char strTmp[MAX_PATH];\r
-    strcpy(strTmp, strPath);\r
-    cygwin_conv_to_full_posix_path(strTmp, strPath);\r
-  }\r
-}\r
-\r
-static const char * getVersion() {\r
-  return versionID;\r
-}\r
-\r
-static void printTopDescription(FILE * f, char * name) {\r
-  fprintf(f, "%s version %s\n", name, getVersion());\r
-  fprintf(f, "  Reads and outputs data from a Windows shortcut (.lnk) file.\n\n");\r
-}\r
-\r
-static void printBottomDescription(FILE * f, char * name) {\r
-  fprintf(f, "\nNOTE: The SHORTCUT argument may be in Windows or Unix format.\n");\r
-}\r
-\r
-static void printLicense(FILE * f, char * name) {\r
-  fprintf(f, "This program is free software; you can redistribute it and/or\n");\r
-  fprintf(f, "modify it under the terms of the GNU General Public License\n");\r
-  fprintf(f, "as published by the Free Software Foundation; either version 2\n");\r
-  fprintf(f, "of the License, or (at your option) any later version.\n");\r
-  fprintf(f, "\n");\r
-  fprintf(f, "This program is distributed in the hope that it will be useful,\n");\r
-  fprintf(f, "but WITHOUT ANY WARRANTY; without even the implied warranty of\n");\r
-  fprintf(f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");\r
-  fprintf(f, "GNU General Public License for more details.\n");\r
-  fprintf(f, "\n");\r
-  fprintf(f, "You should have received a copy of the GNU General Public License\n");\r
-  fprintf(f, "along with this program; if not, write to the Free Software\n");\r
-  fprintf(f, "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n");\r
-  fprintf(f, "\n");\r
-  fprintf(f, "See the COPYING file for license information.\n");\r
-}\r
-\r
-static void usage(poptContext optCon, FILE * f, char * name) {\r
-  poptPrintUsage(optCon, f, 0);\r
-}\r
-\r
-static void help(poptContext optCon, FILE * f, char * name) {\r
-  printTopDescription(f, name);\r
-  poptPrintHelp(optCon, f, 0);\r
-  printBottomDescription(f, name);\r
-}\r
-\r
-static void version(poptContext optCon, FILE * f, char * name) {\r
-  printTopDescription(f, name);\r
-}\r
-\r
-static void license(poptContext optCon, FILE * f, char * name) {\r
-  printTopDescription(f, name);\r
-  printLicense(f, name);\r
-}  \r
+/* 
+ * readshortcut for cygwin/windows
+ *
+ * Copyright (C) 2003 Rob Siklos
+ * http://www.cygwin.com/ml/cygwin/2003-08/msg00640.html
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation in version 2 of the License.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+
+
+ /* http://www.rpm.org/dark_corners/popt/
+ * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/programmersguide/shell_int/shell_int_programming/shortcuts/shortcut.asp
+ */
+
+/* how to compile a standalone version:
+ *
+ * - comment the config.h and common.h includes
+ * - uncomment the stdio and popt.h includes
+ * - run "gcc readshortcut.c -o readshortcut.exe -lpopt -luuid -lole32" 
+ *
+ */
+
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+#include "common.h"
+
+/* moved to common.h */
+/*
+#include <stdio.h>
+#include <popt.h>
+*/
+
+#include <shlobj.h>
+#include <olectlid.h>
+
+#define PATH_UNIX 0
+#define PATH_WIN  1
+
+#define ERR_NONE 0
+#define ERR_USER 1
+#define ERR_SYS  2
+#define ERR_WIN  3
+
+#define SLGP_RAWPATH 0
+#define SW_SHOWMINIMIZED_SEVEN 7
+
+#define BUFF_SIZE 1024
+
+static const char versionID[] = PACKAGE_VERSION;
+
+typedef struct optvals_s {
+  char * target_fname;
+
+  int show_field_names;
+  int pathType;
+
+  int show_target;
+  int show_working_dir;
+  int show_args;
+  int show_showCmd;
+  int show_icon;
+  int show_icon_offset;
+  int show_desc;
+  int show_all;
+
+} optvals;
+
+void cygwin_conv_to_full_win32_path(const char *path, char *win32_path);
+void cygwin_conv_to_full_posix_path(const char *path, char *posix_path);
+
+static void printTopDescription(FILE * f, char * name);
+static void printBottomDescription(FILE * f, char * name);
+static const char * getVersion(void);
+static void usage(poptContext optCon, FILE * f, char * name);
+static void help(poptContext optCon, FILE * f, char * name);
+static void version(poptContext optCon, FILE * f, char * name);
+static void license(poptContext optCon, FILE * f, char * name);
+
+void formatPath (char * strPath, int format);
+int readshortcut(optvals *opts, poptContext optContext);
+
+static char *program_name;
+
+int main (int argc, const char **argv) {
+  poptContext optContext;
+  const char ** loose_args;
+  int rc;
+  int result = ERR_NONE;
+  optvals opts;
+  const char *tmp_str;
+
+  struct poptOption infoOptionsTable[] = {
+    { "help",  'h',  POPT_ARG_NONE, NULL, '?', "This message", NULL},
+    { "usage", '\0', POPT_ARG_NONE, NULL, 'u', "Program usage", NULL},
+    { "version", 'v', POPT_ARG_NONE, NULL, 'v', "Version information", NULL},
+    { "license", '\0', POPT_ARG_NONE, NULL, 'l', "License information", NULL},
+    { NULL, '\0', 0, NULL, 0, NULL, NULL }
+  };
+
+  struct poptOption outputOptionsTable[] = {
+    { "fields",  'f', POPT_ARG_VAL, &(opts.show_field_names), 1, "Show field names", NULL},
+    { "unix",    'u', POPT_ARG_VAL, &(opts.pathType), PATH_UNIX, "Use Unix path format for display (default)", NULL},
+    { "windows", 'w', POPT_ARG_VAL, &(opts.pathType), PATH_WIN, "Use Windows path format for display ", NULL},
+    { "target",  't', POPT_ARG_VAL, &(opts.show_target),      1, "Display shortcut target", NULL},
+    { "working", 'g', POPT_ARG_VAL, &(opts.show_working_dir), 1, "Display shortcut working directory", NULL},
+    { "args",    'r', POPT_ARG_VAL, &(opts.show_args),        1, "Display shortcut arguments", NULL},
+    { "showcmd", 's', POPT_ARG_VAL, &(opts.show_showCmd),     1, "Display shortcut \"show\" command value", NULL},
+    { "icon",    'i', POPT_ARG_VAL, &(opts.show_icon),        1, "Display icon library location", NULL},
+    { "offset",  'j', POPT_ARG_VAL, &(opts.show_icon_offset), 1, "Display icon library offset", NULL},
+    { "desc",    'd', POPT_ARG_VAL, &(opts.show_desc),        1, "Display shortcut description", NULL},
+    { "all",     'a', POPT_ARG_VAL, &(opts.show_all),         1, "Display all information", NULL},
+    { NULL, '\0', 0, NULL, 0, NULL, NULL }
+  };
+  
+  struct poptOption opt[] = {
+    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, outputOptionsTable, 0, "Output options", NULL },
+    { NULL, '\0', POPT_ARG_INCLUDE_TABLE, infoOptionsTable, 0, "Information options (display a message and exit)", NULL },
+    { NULL, '\0', 0, NULL, 0, NULL, NULL }
+  };
+
+  /* get the program name */
+  tmp_str = strrchr (argv[0], '/');
+  if (tmp_str == NULL) { tmp_str = strrchr (argv[0], '\\'); }
+  if (tmp_str == NULL) { tmp_str = argv[0]; }
+  else { tmp_str++; }
+  if ((program_name = strdup(tmp_str)) == NULL ) {
+    fprintf(stderr, "%s: memory allocation error\n", argv[0]);
+    exit(ERR_SYS);
+  }
+
+  /* set default values for options */
+  opts.target_fname = NULL;
+
+  opts.show_field_names = 0;
+  opts.pathType = PATH_UNIX;
+  
+  opts.show_target = 0;
+  opts.show_working_dir = 0;
+  opts.show_args = 0;
+  opts.show_showCmd = 0;
+  opts.show_icon = 0;
+  opts.show_icon_offset = 0;
+  opts.show_desc = 0;
+  opts.show_all = 0;
+
+  /* set the pOpt context and help line */
+  optContext = poptGetContext(NULL, argc, argv, opt, 0);
+  poptSetOtherOptionHelp(optContext, "[OPTION]* SHORTCUT");
+  
+  while ((rc = poptGetNextOpt(optContext)) > 0) {
+    switch (rc) {
+      case '?':
+        help(optContext, stdout, program_name);
+        goto exit;
+      case 'u':
+        usage(optContext, stdout, program_name);
+        goto exit;
+      case 'v':
+        version(optContext, stdout, program_name);
+        goto exit;
+      case 'l':
+        license(optContext, stdout, program_name);
+        goto exit;
+    }
+  }
+  
+  // set show_target by default
+  if (!(opts.show_all + opts.show_target + opts.show_working_dir + opts.show_args + 
+        opts.show_showCmd + opts.show_icon + opts.show_icon_offset + 
+        opts.show_desc)) { opts.show_target = 1; }
+
+  /* get the remaining arguments */
+  loose_args = poptGetArgs(optContext);
+
+  if (loose_args && *loose_args) {
+    if ((opts.target_fname = strdup(*loose_args)) == NULL) {
+      fprintf(stderr, "%s: memory allocation error\n", program_name);
+      result = ERR_SYS;
+      goto exit;
+    }
+    loose_args++;
+    if (loose_args && *loose_args) {
+      fprintf(stderr, "%s: Too many arguments: ", program_name);
+      while (*loose_args) { fprintf(stderr, "%s ", *loose_args++); }
+      fprintf(stderr, "\n"); 
+      usage(optContext, stderr, program_name);
+      result = ERR_USER;
+    } else {
+      /************** Main Program ***********/
+      result = readshortcut(&opts, optContext);
+    }    
+  } else {
+    fprintf(stderr, "%s: SHORTCUT not specified\n", program_name);
+    usage(optContext, stderr, program_name);
+    result = ERR_USER;
+  }
+
+exit:
+  poptFreeContext(optContext);
+  free(program_name);
+  free(opts.target_fname);
+  return result;
+}
+
+int readshortcut(optvals *opts, poptContext optContext) {
+  HRESULT hres;
+  IShellLink *shell_link;
+  IPersistFile *persist_file;
+  char strPath[MAX_PATH]; 
+  char strBuff[BUFF_SIZE];
+  int iBuff;
+
+  int result = ERR_NONE;  /* the value to return on exit */
+  
+  /*  Add suffix to link name if necessary */
+  if (strlen (opts->target_fname) > 4) {
+    int tmp = strlen (opts->target_fname) - 4;
+    if (strncmp (opts->target_fname + tmp, ".lnk", 4) != 0) {
+      opts->target_fname = (char *)realloc(opts->target_fname, strlen(opts->target_fname) + 1 + 4);
+      if (opts->target_fname == NULL) {
+        fprintf(stderr, "%s: memory allocation error\n", program_name);
+        return (ERR_SYS);
+      }
+      strcat (opts->target_fname, ".lnk");
+    }
+  }
+  else {
+    opts->target_fname = (char *)realloc(opts->target_fname, strlen(opts->target_fname) + 1 + 4);
+    if (opts->target_fname == NULL) {
+      fprintf(stderr, "%s: memory allocation error\n", program_name);
+      return (ERR_SYS);
+    }
+    strcat (opts->target_fname, ".lnk");
+  }
+
+  /* if there's no colon in the path, it's POSIX and we should convert to win32 */
+  if (strchr (opts->target_fname, ':') == NULL) {
+    char *strTmpPath = (char*)malloc(MAX_PATH);
+    if (strTmpPath == NULL) {
+      fprintf(stderr, "%s: memory allocation error\n", program_name);
+      return (ERR_SYS);
+    }
+    cygwin_conv_to_full_win32_path (opts->target_fname, strTmpPath);
+    free (opts->target_fname);
+    opts->target_fname = strTmpPath;
+  }
+
+  hres = OleInitialize (NULL);
+  if (hres != S_FALSE && hres != S_OK) {
+    fprintf (stderr, "%s: Could not initialize OLE interface\n", program_name);
+    return (ERR_WIN);
+  }
+
+  /* Get a pointer to the IShellLink interface. */
+  hres = CoCreateInstance (&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, &IID_IShellLink, (void **) &shell_link); 
+
+  if (!SUCCEEDED(hres)) {
+    fprintf (stderr, "%s: CoCreateInstance failed\n", program_name);
+    return (ERR_WIN);
+  }
+
+  /* Get a pointer to the IPersistFile interface. */
+  hres = shell_link->lpVtbl->QueryInterface(shell_link, &IID_IPersistFile, (void **) &persist_file);
+
+  if (SUCCEEDED(hres)) {
+    WCHAR wsz[MAX_PATH]; 
+    /* Ensure that the string is Unicode. */
+    MultiByteToWideChar(CP_ACP, 0, (LPCSTR)opts->target_fname, -1, wsz, MAX_PATH); 
+
+    /* Load the shortcut.  */
+    hres = persist_file->lpVtbl->Load(persist_file, wsz, STGM_READ); 
+
+    if (SUCCEEDED(hres)) {
+      /* read stuff from the link object and print it to the screen */
+      if (opts->show_all || opts->show_target) {
+        shell_link->lpVtbl->GetPath(shell_link, strPath, MAX_PATH, NULL, SLGP_RAWPATH);
+        if (opts->show_field_names) { printf("Target: "); }
+        formatPath(strPath, opts->pathType);
+        printf("%s\n", strPath);
+      }
+      if (opts->show_all || opts->show_working_dir) {
+        shell_link->lpVtbl->GetWorkingDirectory(shell_link, strPath, MAX_PATH);
+        if (opts->show_field_names) { printf("Working Directory: "); }
+        formatPath(strPath, opts->pathType);
+        printf("%s\n", strPath);
+      }
+      if (opts->show_all || opts->show_args) {
+        shell_link->lpVtbl->GetArguments(shell_link, strBuff, BUFF_SIZE);
+        if (opts->show_field_names) { printf("Arguments: "); }
+        printf("%s\n", strBuff);
+      }
+      if (opts->show_all || opts->show_showCmd) {
+        shell_link->lpVtbl->GetShowCmd(shell_link, &iBuff);
+        if (opts->show_field_names) { printf("Show Command: "); }
+
+        switch (iBuff) {
+          case SW_SHOWNORMAL:
+            printf("Normal\n");
+            break;
+          case SW_SHOWMINIMIZED:
+          case SW_SHOWMINIMIZED_SEVEN:
+            printf("Minimized\n");
+            break;
+          case SW_SHOWMAXIMIZED:
+            printf("Maximized\n");
+            break;
+        }
+      }
+      if (opts->show_all || opts->show_icon || opts->show_icon_offset) {
+        shell_link->lpVtbl->GetIconLocation(shell_link, strPath, MAX_PATH, &iBuff);
+        if (opts->show_all || opts->show_icon) {
+          if (opts->show_field_names) { printf("Icon Library: "); }
+          formatPath(strPath, opts->pathType);
+          printf("%s\n", strPath);
+      }
+        if (opts->show_all || opts->show_icon_offset) {
+          if (opts->show_field_names) { printf("Icon Library Offset: "); }
+          printf("%d\n", iBuff);
+        }
+      }
+      if (opts->show_all || opts->show_desc) {
+        shell_link->lpVtbl->GetDescription(shell_link, strBuff, BUFF_SIZE);
+        if (opts->show_field_names) { printf("Description: "); }
+        printf("%s\n", strBuff);
+      }
+    }
+    else {
+      fprintf (stderr, "%s: Load failed on %s\n", program_name, opts->target_fname);
+      result = ERR_WIN;
+    }
+
+    /* Release the pointer to the IPersistFile interface. */
+    persist_file->lpVtbl->Release(persist_file);
+  }
+  else { 
+    fprintf (stderr, "%s: QueryInterface failed\n", program_name);
+    result = ERR_WIN;
+  }
+  
+  /* Release the pointer to the IShellLink interface. */
+  shell_link->lpVtbl->Release(shell_link);
+
+  return(result);
+}
+
+/* change the path to the proper format */
+void formatPath (char * strPath, int format) {
+  if (format == PATH_WIN) { return; } /* windows is the default */
+  else {
+    // convert to posix path
+    char strTmp[MAX_PATH];
+    strcpy(strTmp, strPath);
+    cygwin_conv_to_full_posix_path(strTmp, strPath);
+  }
+}
+
+static const char * getVersion() {
+  return versionID;
+}
+
+static void printTopDescription(FILE * f, char * name) {
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
+  fprintf(f, "  Reads and outputs data from a Windows shortcut (.lnk) file.\n\n");
+}
+
+static void printBottomDescription(FILE * f, char * name) {
+  fprintf(f, "\nNOTE: The SHORTCUT argument may be in Windows or Unix format.\n");
+}
+
+static void printLicense(FILE * f, char * name) {
+  fprintf(f, "This program is free software; you can redistribute it and/or\n");
+  fprintf(f, "modify it under the terms of the GNU General Public License\n");
+  fprintf(f, "as published by the Free Software Foundation; either version 2\n");
+  fprintf(f, "of the License, or (at your option) any later version.\n");
+  fprintf(f, "\n");
+  fprintf(f, "This program is distributed in the hope that it will be useful,\n");
+  fprintf(f, "but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
+  fprintf(f, "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n");
+  fprintf(f, "GNU General Public License for more details.\n");
+  fprintf(f, "\n");
+  fprintf(f, "You should have received a copy of the GNU General Public License\n");
+  fprintf(f, "along with this program; if not, write to the Free Software\n");
+  fprintf(f, "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\n");
+  fprintf(f, "\n");
+  fprintf(f, "See the COPYING file for license information.\n");
+}
+
+static void usage(poptContext optCon, FILE * f, char * name) {
+  poptPrintUsage(optCon, f, 0);
+}
+
+static void help(poptContext optCon, FILE * f, char * name) {
+  printTopDescription(f, name);
+  poptPrintHelp(optCon, f, 0);
+  printBottomDescription(f, name);
+}
+
+static void version(poptContext optCon, FILE * f, char * name) {
+  printTopDescription(f, name);
+}
+
+static void license(poptContext optCon, FILE * f, char * name) {
+  printTopDescription(f, name);
+  printLicense(f, name);
+}  
index 997fe43b0fc57908291938e539a137ed809131df..c9255a0858acc233b5dd9f4e1463639f8e07aac4 100644 (file)
@@ -30,8 +30,7 @@
 #define PROGRAM_NAME "realpath"
 #define AUTHORS "Steven Barker"
 
-static const char versionID[] = "0.9";
-/* for future CVS */
+static const char versionID[] = PACKAGE_VERSION;
 static const char revID[] =
        "$Id$";
 static const char copyrightID[] =
@@ -150,7 +149,8 @@ static const char * getVersion()
 
 static void printTopDescription(FILE * f, char * name)
 {
-  fprintf(f, "%s version %s, by %s\n", name, getVersion(), AUTHORS);
+  fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
+  fprintf(f, "%s was originally authored by %s\n", name, AUTHORS);
   fprintf(f, "  Print PATH with all references to `.', `..', and symlinks resolved.\n\n");
 }
 static void printBottomDescription(FILE * f, char * name)
@@ -200,5 +200,5 @@ static void license(poptContext optCon, FILE * f, char * name)
 {
   printTopDescription(f, name);
   printLicense(f, name);
-}  
+}
 
This page took 0.088535 seconds and 5 git commands to generate.