+2009-05-06 Charles Wilson <cwilson@...>
+
+ Make coding style consistent throughout.
+ * ascii/ascii.c: Format using 'indent -gnu
+ -nut -ppi 1'.
+ * banner/banner.c: Ditto.
+ * clip/getclip.c: Ditto.
+ * clip/putclip.c: Ditto.
+ * cygstart/cygstart.c: Ditto.
+ * dump/dump.c: Ditto.
+ * ipc/msgtool.c: Ditto.
+ * ipc/semstat.c: Ditto.
+ * ipc/semtool.c: Ditto.
+ * ipc/shmtool.c: Ditto.
+ * mkshortcut/mkshortcut.c: Ditto.
+ * readshortcut/readshortcut.c: Ditto.
+ * realpath/realpath.c: Ditto.
+ * Printer.hh: Format using 'astyle --style=gnu -c'.
+ Move 'using namespace' from hh to cc.
+ * Printer.cc: Ditto.
+ * Win32Utils.cc: Ditto.
+ * Win32Utils.hh: Ditto.
+ * PrinterException.hh: Format using 'astyle --style=gnu
+ -c'. Removed 'using namespace' statement.
+ * lpr.cc: Format using 'astyle --style=gnu -c'
+
2009-05-06 Charles Wilson <cwilson@...>
Ensure uniformity for --version option.
*/
#if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char versionID[] = PACKAGE_VERSION;
static const char revID[] =
- "$Id$";
+ "$Id$";
static const char copyrightID[] =
- "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
+ "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
-static void printTopDescription(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);
-static void ascii(FILE * f);
+static void printTopDescription (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);
+static void ascii (FILE * f);
-static char * program_name;
+static char *program_name;
-int main(int argc, const char ** argv)
+int
+main (int argc, const char **argv)
{
poptContext optCon;
- const char ** rest;
+ const char **rest;
int rc;
int ec = 0;
struct poptOption helpOptionsTable[] = {
- { "help", '?', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", '\0', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"help", '?', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", '\0', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
- if( (program_name = strdup(argv[0])) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- optCon = poptGetContext(NULL, argc, argv, opt, 0);
-
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- case '?': help(optCon, stderr, program_name);
- goto exit;
- case 'u': usage(optCon, stderr, program_name);
- goto exit;
- case 'v': version(optCon, stderr, program_name);
- goto exit;
- case 'l': license(optCon, stderr, program_name);
- goto exit;
+ if ((program_name = strdup (argv[0])) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- }
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- ec = 2;
- goto exit;
- }
- rest = poptGetArgs(optCon);
+ optCon = poptGetContext (NULL, argc, argv, opt, 0);
+
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ case '?':
+ help (optCon, stderr, program_name);
+ goto exit;
+ case 'u':
+ usage (optCon, stderr, program_name);
+ goto exit;
+ case 'v':
+ version (optCon, stderr, program_name);
+ goto exit;
+ case 'l':
+ license (optCon, stderr, program_name);
+ goto exit;
+ }
+ }
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ ec = 2;
+ goto exit;
+ }
+ rest = poptGetArgs (optCon);
if (rest == NULL)
- ascii(stdout);
- else {
- fprintf(stderr, "Extra args ignored: ");
- while (*rest)
- fprintf(stderr, "%s ", *rest++);
- fprintf(stderr, "\n");
- ascii(stdout);
- }
+ ascii (stdout);
+ else
+ {
+ fprintf (stderr, "Extra args ignored: ");
+ while (*rest)
+ fprintf (stderr, "%s ", *rest++);
+ fprintf (stderr, "\n");
+ ascii (stdout);
+ }
exit:
- poptFreeContext(optCon);
- free(program_name);
- return(ec);
+ poptFreeContext (optCon);
+ free (program_name);
+ return (ec);
}
-static const char * getVersion()
+static const char *
+getVersion ()
{
return versionID;
}
-static void printTopDescription(FILE * f, char * name)
+static void
+printTopDescription (FILE * f, char *name)
{
- 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");
+ 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");
}
-static printLicense(FILE * f, char * name)
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE * f, char * name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
}
-static void version(poptContext optCon, FILE * f, char * name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
+ printTopDescription (f, name);
}
-static void license(poptContext optCon, FILE * f, char * name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
+ printTopDescription (f, name);
+ printLicense (f, name);
}
-static void ascii(FILE *f)
+static void
+ascii (FILE * f)
{
char str1[64][80];
int i, j;
int c;
- for( i = 0; i < 64; i++)
+ for (i = 0; i < 64; i++)
str1[i][0] = '\0';
- for( i = 0; i < 128; i++)
- {
- j = i % 32;
- sprintf(str1[j], "%s%03d %0#4x ", str1[j], i, i);
- if( i < 32 )
- sprintf(str1[j], "%s^%c\t", str1[j], i + 64 );
- else
- sprintf(str1[j], "%s%c\t", str1[j], i );
- }
- for( i = 128; i < 256; i++)
- {
- j = ((i - 128) % 32) + 32;
- sprintf(str1[j], "%s%03d %0#4x ", str1[j], i, i);
- sprintf(str1[j], "%s%c\t", str1[j], i );
- }
- for( i = 0; i < 32; i++)
- fprintf(f, "%s\n", str1[i]);
- fprintf(f, "\n");
- for( i = 32; i < 64; i++)
- fprintf(f, "%s\n", str1[i]);
+ for (i = 0; i < 128; i++)
+ {
+ j = i % 32;
+ sprintf (str1[j], "%s%03d %0#4x ", str1[j], i, i);
+ if (i < 32)
+ sprintf (str1[j], "%s^%c\t", str1[j], i + 64);
+ else
+ sprintf (str1[j], "%s%c\t", str1[j], i);
+ }
+ for (i = 128; i < 256; i++)
+ {
+ j = ((i - 128) % 32) + 32;
+ sprintf (str1[j], "%s%03d %0#4x ", str1[j], i, i);
+ sprintf (str1[j], "%s%c\t", str1[j], i);
+ }
+ for (i = 0; i < 32; i++)
+ fprintf (f, "%s\n", str1[i]);
+ fprintf (f, "\n");
+ for (i = 32; i < 64; i++)
+ fprintf (f, "%s\n", str1[i]);
}
-
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char versionID[] = PACKAGE_VERSION;
static const char revID[] =
- "$Id$";
+ "$Id$";
static const char copyrightID[] =
- "Copyright (c) 1999-2001\nJoerg Schaible. All rights reserved.\nLicensed under GPL v2.0\n";
+ "Copyright (c) 1999-2001\nJoerg Schaible. All rights reserved.\nLicensed under GPL v2.0\n";
-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);
+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);
-static char * program_name;
+static char *program_name;
static char *c = "X";
static int w = 80;
static BITMAPINFO bmi;
static unsigned char *buffer;
-void initialize()
+void
+initialize ()
{
- HDC hScreen;
- hFont = GetStockObject( ANSI_FIXED_FONT );
- hScreen = GetDC( 0 );
- hMem = CreateCompatibleDC( hScreen );
- ReleaseDC( 0, hScreen );
-
- SelectObject( hMem, hFont );
- GetTextMetrics( hMem, &tm );
-
- hBmp = CreateBitmap( w, tm.tmHeight, 1, 1, 0 );
- GetObject( hBmp, sizeof( bm ), &bm );
- memset( &bmi.bmiHeader, 0, sizeof( BITMAPINFOHEADER ));
- bmi.bmiHeader.biSize = sizeof( BITMAPINFOHEADER );
- bmi.bmiHeader.biWidth = bm.bmWidth;
- bmi.bmiHeader.biHeight = bm.bmHeight;
- bmi.bmiHeader.biPlanes = 1;
- bmi.bmiHeader.biCompression = BI_RGB;
- bmi.bmiHeader.biBitCount = 1;
- bmi.bmiHeader.biSizeImage =
- (((( unsigned int )bm.bmWidth + 31 ) & ~31 ) >> 3 )
- * bm.bmHeight;
- bmi.bmiHeader.biClrUsed = 2;
- buffer = ( unsigned char * )malloc( bmi.bmiHeader.biSizeImage );
-
- hBmpOrg = SelectObject( hMem, hBmp );
- SelectObject( hMem, GetStockObject( WHITE_BRUSH ));
- SelectObject( hMem, GetStockObject( WHITE_PEN ));
-
- SetBkColor( hMem, RGB( 0, 0, 0 ));
- SetTextColor( hMem, RGB( 255, 255, 255 ));
- SetBkMode( hMem, OPAQUE );
-
- rt.top = 0;
- rt.left = 0;
- rt.right = w;
- rt.bottom = tm.tmHeight;
+ HDC hScreen;
+ hFont = GetStockObject (ANSI_FIXED_FONT);
+ hScreen = GetDC (0);
+ hMem = CreateCompatibleDC (hScreen);
+ ReleaseDC (0, hScreen);
+
+ SelectObject (hMem, hFont);
+ GetTextMetrics (hMem, &tm);
+
+ hBmp = CreateBitmap (w, tm.tmHeight, 1, 1, 0);
+ GetObject (hBmp, sizeof (bm), &bm);
+ memset (&bmi.bmiHeader, 0, sizeof (BITMAPINFOHEADER));
+ bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
+ bmi.bmiHeader.biWidth = bm.bmWidth;
+ bmi.bmiHeader.biHeight = bm.bmHeight;
+ bmi.bmiHeader.biPlanes = 1;
+ bmi.bmiHeader.biCompression = BI_RGB;
+ bmi.bmiHeader.biBitCount = 1;
+ bmi.bmiHeader.biSizeImage =
+ ((((unsigned int) bm.bmWidth + 31) & ~31) >> 3) * bm.bmHeight;
+ bmi.bmiHeader.biClrUsed = 2;
+ buffer = (unsigned char *) malloc (bmi.bmiHeader.biSizeImage);
+
+ hBmpOrg = SelectObject (hMem, hBmp);
+ SelectObject (hMem, GetStockObject (WHITE_BRUSH));
+ SelectObject (hMem, GetStockObject (WHITE_PEN));
+
+ SetBkColor (hMem, RGB (0, 0, 0));
+ SetTextColor (hMem, RGB (255, 255, 255));
+ SetBkMode (hMem, OPAQUE);
+
+ rt.top = 0;
+ rt.left = 0;
+ rt.right = w;
+ rt.bottom = tm.tmHeight;
}
-void deinitialize()
+void
+deinitialize ()
{
- SelectObject( hMem, hBmpOrg );
- DeleteObject( hBmp );
- DeleteDC( hMem );
- free( buffer );
+ SelectObject (hMem, hBmpOrg);
+ DeleteObject (hBmp);
+ DeleteDC (hMem);
+ free (buffer);
}
-int print_line( const char *line )
+int
+print_line (const char *line)
{
- int x, y;
- int len = strlen( line );
- if( len > ( w / tm.tmMaxCharWidth ))
- len = ( w / tm.tmMaxCharWidth );
-
- Rectangle( hMem, 0, 0, rt.right, rt.bottom );
- DrawText( hMem, line, len, &rt,
- DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE );
-
- SelectObject( hMem, hBmpOrg );
- GetDIBits( hMem, hBmp, 0, bmi.bmiHeader.biHeight, buffer,
- ( LPBITMAPINFO )&bmi.bmiHeader, DIB_RGB_COLORS );
- SelectObject( hMem, hBmp );
-
- for( y = tm.tmHeight; y--; )
- {
- unsigned char *line = buffer + y * ( bmi.bmiHeader.biSizeImage / bmi.bmiHeader.biHeight );
-
- for( x = 0; x < len * tm.tmMaxCharWidth; ++x )
- {
- unsigned char byte = *( line + ( x / 8 ));
- putchar(( byte & ( 1 << (7 - (( int )x % 8 )))) ? *c : ' ' );
- }
-
- putchar( '\n' );
- }
- return 0;
+ int x, y;
+ int len = strlen (line);
+ if (len > (w / tm.tmMaxCharWidth))
+ len = (w / tm.tmMaxCharWidth);
+
+ Rectangle (hMem, 0, 0, rt.right, rt.bottom);
+ DrawText (hMem, line, len, &rt, DT_NOCLIP | DT_NOPREFIX | DT_SINGLELINE);
+
+ SelectObject (hMem, hBmpOrg);
+ GetDIBits (hMem, hBmp, 0, bmi.bmiHeader.biHeight, buffer,
+ (LPBITMAPINFO) & bmi.bmiHeader, DIB_RGB_COLORS);
+ SelectObject (hMem, hBmp);
+
+ for (y = tm.tmHeight; y--;)
+ {
+ unsigned char *line =
+ buffer + y * (bmi.bmiHeader.biSizeImage / bmi.bmiHeader.biHeight);
+
+ for (x = 0; x < len * tm.tmMaxCharWidth; ++x)
+ {
+ unsigned char byte = *(line + (x / 8));
+ putchar ((byte & (1 << (7 - ((int) x % 8)))) ? *c : ' ');
+ }
+
+ putchar ('\n');
+ }
+ return 0;
}
-int main(int argc, const char ** argv)
+int
+main (int argc, const char **argv)
{
poptContext optCon;
- const char ** rest;
+ const char **rest;
int rc;
int ec = 0;
int i;
struct poptOption generalOptionsTable[] = {
- { "char", 'c', POPT_ARG_STRING, &c, 'c', \
- "use character <X>", "X"},
- { "width", 'w', POPT_ARG_INT, &w, 'w', \
- "set display width to <80> ", "80"},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"char", 'c', POPT_ARG_STRING, &c, 'c',
+ "use character <X>", "X"},
+ {"width", 'w', POPT_ARG_INT, &w, 'w',
+ "set display width to <80> ", "80"},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption helpOptionsTable[] = {
- { "help", '?', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", '\0', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"help", '?', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", '\0', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0, \
- "General options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0,
+ "General options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
- if( (program_name = strdup(argv[0])) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- optCon = poptGetContext(NULL, argc, argv, opt, 0);
- poptSetOtherOptionHelp(optCon, "A string to print...");
-
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- case '?': help(optCon, stderr, program_name);
- goto exit;
- case 'u': usage(optCon, stderr, program_name);
- goto exit;
- case 'v': version(optCon, stderr, program_name);
- goto exit;
- case 'l': license(optCon, stderr, program_name);
- goto exit;
- case 'c': /* no additional action needed */
- break;
- case 'w': /* no additional action needed */
- break;
+ if ((program_name = strdup (argv[0])) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
+ }
+ optCon = poptGetContext (NULL, argc, argv, opt, 0);
+ poptSetOtherOptionHelp (optCon, "A string to print...");
+
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ case '?':
+ help (optCon, stderr, program_name);
+ goto exit;
+ case 'u':
+ usage (optCon, stderr, program_name);
+ goto exit;
+ case 'v':
+ version (optCon, stderr, program_name);
+ goto exit;
+ case 'l':
+ license (optCon, stderr, program_name);
+ goto exit;
+ case 'c': /* no additional action needed */
+ break;
+ case 'w': /* no additional action needed */
+ break;
+ }
+ }
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ ec = 2;
+ goto exit;
+ }
+ rest = poptGetArgs (optCon);
+
+ if (rest == NULL)
+ {
+ fprintf (stderr, "%s: not enough arguments\n", program_name);
+ usage (optCon, stderr, program_name);
+ }
+ else
+ {
+ initialize ();
+ while (*rest && !ec)
+ {
+ ec |= print_line (*rest);
+ rest++;
+ }
+ deinitialize ();
}
- }
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- ec = 2;
- goto exit;
- }
- rest = poptGetArgs(optCon);
-
- if (rest == NULL) {
- fprintf(stderr, "%s: not enough arguments\n",program_name);
- usage(optCon, stderr, program_name);
- }
- else {
- initialize();
- while (*rest && !ec) {
- ec |= print_line( *rest );
- rest++;
- }
- deinitialize();
- }
exit:
- poptFreeContext(optCon);
- free(program_name);
- return(ec);
+ poptFreeContext (optCon);
+ free (program_name);
+ return (ec);
}
-
-static const char * getVersion()
+
+static const char *
+getVersion ()
{
return versionID;
}
-static void printTopDescription(FILE * f, char * name)
+static void
+printTopDescription (FILE * f, char *name)
{
- 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");
+ 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");
}
-static void printBottomDescription(FILE * f, char * name)
+static void
+printBottomDescription (FILE * f, char *name)
{
- fprintf(f, "\nThis version works the same way as System V'S banner does:\n");
- fprintf(f, "The banner text is displayed horizontally.\n");
+ fprintf (f,
+ "\nThis version works the same way as System V'S banner does:\n");
+ fprintf (f, "The banner text is displayed horizontally.\n");
}
-static printLicense(FILE * f, char * name)
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE * f, char * name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
- printBottomDescription(f, name);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
+ printBottomDescription (f, name);
}
-static void version(poptContext optCon, FILE * f, char * name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
+ printTopDescription (f, name);
}
-static void license(poptContext optCon, FILE * f, char * name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
+ printTopDescription (f, name);
+ printLicense (f, name);
}
-
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char versionID[] = PACKAGE_VERSION;
static const char revID[] =
- "$Id$";
+ "$Id$";
static const char copyrightID[] =
- "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
+ "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
typedef struct
{
- int endl_mode; /* ENDLMODE_DOS ENDLMODE_UNIX ENDLMODE_NOCONV */
- int unixflag; /* indicates that the user specified -u or --unix */
- int dosflag; /* indicates that the user specified -d or --dos */
- int noconvflag;/* indicates that the user specified -n or --no-conv */
+ int endl_mode; /* ENDLMODE_DOS ENDLMODE_UNIX ENDLMODE_NOCONV */
+ int unixflag; /* indicates that the user specified -u or --unix */
+ int dosflag; /* indicates that the user specified -d or --dos */
+ int noconvflag; /* indicates that the user specified -n or --no-conv */
} flags_struct;
-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);
-static int getclip(FILE * out, flags_struct flags, FILE * f, char * name);
-
-static char * program_name;
-
-int main(int argc, const char ** argv)
+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);
+static int getclip (FILE * out, flags_struct flags, FILE * f, char *name);
+
+static char *program_name;
+
+int
+main (int argc, const char **argv)
{
poptContext optCon;
- const char ** rest;
+ const char **rest;
int rc;
int ec = 0;
flags_struct flags = { ENDLMODE_NOCONV, FALSE, FALSE, FALSE };
struct poptOption generalOptionsTable[] = {
- { "dos", 'd', POPT_ARG_NONE, NULL, 'd', \
- "Output text will have DOS line endings.", NULL},
- { "unix", 'u', POPT_ARG_NONE, NULL, 'U', \
- "Output text will have UNIX line endings.", NULL},
- { "no-conv", 'n', POPT_ARG_NONE, NULL, 'n', \
- "Do not translate line endings.", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"dos", 'd', POPT_ARG_NONE, NULL, 'd',
+ "Output text will have DOS line endings.", NULL},
+ {"unix", 'u', POPT_ARG_NONE, NULL, 'U',
+ "Output text will have UNIX line endings.", NULL},
+ {"no-conv", 'n', POPT_ARG_NONE, NULL, 'n',
+ "Do not translate line endings.", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption helpOptionsTable[] = {
- { "help", '?', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", '\0', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"help", '?', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", '\0', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0, \
- "General options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0,
+ "General options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
- if( (program_name = strdup(argv[0])) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- optCon = poptGetContext(NULL, argc, argv, opt, 0);
-
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- case '?': help(optCon, stderr, program_name);
- goto exit;
- case 'u': usage(optCon, stderr, program_name);
- goto exit;
- case 'v': version(optCon, stderr, program_name);
- goto exit;
- case 'l': license(optCon, stderr, program_name);
- goto exit;
- case 'd': flags.dosflag = TRUE;
- flags.endl_mode = ENDLMODE_DOS;
- break;
- case 'U': flags.unixflag = TRUE;
- flags.endl_mode = ENDLMODE_UNIX;
- break;
- case 'n': flags.noconvflag = TRUE;
- flags.endl_mode = ENDLMODE_NOCONV;
- break;
+ if ((program_name = strdup (argv[0])) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- }
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- ec = 2;
- goto exit;
- }
- if (flags.dosflag && flags.unixflag) {
- fprintf(stderr, "%s: can't specify both --unix and --dos (-u and -d)\n", program_name);
- ec = 2;
- goto exit;
- }
- if (flags.dosflag && flags.noconvflag) {
- fprintf(stderr, "%s: can't specify both --dos and --no-conv (-d and -n)\n", program_name);
- ec = 2;
- goto exit;
- }
- if (flags.unixflag && flags.noconvflag) {
- fprintf(stderr, "%s: can't specify both --unix and --no-conv (-u and -n)\n", program_name);
- ec = 2;
- goto exit;
- }
- if (flags.unixflag && (sizeof(char) != 1)) {
- fprintf(stderr, "%s: the --unix flag will not work on wide-character systems\n", program_name);
- ec = 2;
- goto exit;
- }
- rest = poptGetArgs(optCon);
+ optCon = poptGetContext (NULL, argc, argv, opt, 0);
+
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ case '?':
+ help (optCon, stderr, program_name);
+ goto exit;
+ case 'u':
+ usage (optCon, stderr, program_name);
+ goto exit;
+ case 'v':
+ version (optCon, stderr, program_name);
+ goto exit;
+ case 'l':
+ license (optCon, stderr, program_name);
+ goto exit;
+ case 'd':
+ flags.dosflag = TRUE;
+ flags.endl_mode = ENDLMODE_DOS;
+ break;
+ case 'U':
+ flags.unixflag = TRUE;
+ flags.endl_mode = ENDLMODE_UNIX;
+ break;
+ case 'n':
+ flags.noconvflag = TRUE;
+ flags.endl_mode = ENDLMODE_NOCONV;
+ break;
+ }
+ }
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ ec = 2;
+ goto exit;
+ }
+ if (flags.dosflag && flags.unixflag)
+ {
+ fprintf (stderr,
+ "%s: can't specify both --unix and --dos (-u and -d)\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ if (flags.dosflag && flags.noconvflag)
+ {
+ fprintf (stderr,
+ "%s: can't specify both --dos and --no-conv (-d and -n)\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ if (flags.unixflag && flags.noconvflag)
+ {
+ fprintf (stderr,
+ "%s: can't specify both --unix and --no-conv (-u and -n)\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ if (flags.unixflag && (sizeof (char) != 1))
+ {
+ fprintf (stderr,
+ "%s: the --unix flag will not work on wide-character systems\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ rest = poptGetArgs (optCon);
if (rest == NULL)
- ec |= getclip(stdout, flags, stderr, program_name);
- else {
- fprintf(stderr, "Extra args ignored: ");
- while (*rest)
- fprintf(stderr, "%s ", *rest++);
- fprintf(stderr, "\n");
- ec |= getclip(stdout, flags, stderr, program_name);
- }
+ ec |= getclip (stdout, flags, stderr, program_name);
+ else
+ {
+ fprintf (stderr, "Extra args ignored: ");
+ while (*rest)
+ fprintf (stderr, "%s ", *rest++);
+ fprintf (stderr, "\n");
+ ec |= getclip (stdout, flags, stderr, program_name);
+ }
exit:
- poptFreeContext(optCon);
- free(program_name);
- return(ec);
+ poptFreeContext (optCon);
+ free (program_name);
+ return (ec);
}
-static const char * getVersion()
+static const char *
+getVersion ()
{
return versionID;
}
-static void printTopDescription(FILE * f, char * name)
+static void
+printTopDescription (FILE * f, char *name)
{
- fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
- fprintf(f, " Copy the Windows Clipboard to stdout\n\n");
+ fprintf (f, "%s is part of cygutils version %s\n", name, getVersion ());
+ fprintf (f, " Copy the Windows Clipboard to stdout\n\n");
}
-static void printBottomDescription(FILE * f, char * name)
+static void
+printBottomDescription (FILE * f, char *name)
{
- fprintf(f, "\nNOTE: by default, no line ending conversion is performed.\n");
+ fprintf (f,
+ "\nNOTE: by default, no line ending conversion is performed.\n");
}
-static printLicense(FILE * f, char * name)
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE * f, char * name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
- printBottomDescription(f, name);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
+ printBottomDescription (f, name);
}
-static void version(poptContext optCon, FILE * f, char * name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
+ printTopDescription (f, name);
}
-static void license(poptContext optCon, FILE * f, char * name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
+ printTopDescription (f, name);
+ printLicense (f, name);
}
-int getclip(FILE * out, flags_struct flags, FILE * f, char * name)
+int
+getclip (FILE * out, flags_struct flags, FILE * f, char *name)
{
HGLOBAL hglb;
- char *buf = NULL;
- size_t len = 0;
+ char *buf = NULL;
+ size_t len = 0;
char *newStr = NULL;
int origMode;
- origMode = setmode(fileno(out), O_BINARY);
+ origMode = setmode (fileno (out), O_BINARY);
if (flags.endl_mode == ENDLMODE_NOCONV)
- {
- const char* CYGWIN_NATIVE = "CYGWIN_NATIVE_CLIPBOARD";
- UINT cygnativeformat;
- UINT formatlist[2];
- UINT format;
-
- OpenClipboard(NULL);
- cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE);
-
- formatlist[0] = cygnativeformat;
- formatlist[1] = CF_TEXT;
-
- if ((format = GetPriorityClipboardFormat(formatlist, 2)) <= 0)
{
- CloseClipboard();
- return(0);
+ const char *CYGWIN_NATIVE = "CYGWIN_NATIVE_CLIPBOARD";
+ UINT cygnativeformat;
+ UINT formatlist[2];
+ UINT format;
+
+ OpenClipboard (NULL);
+ cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE);
+
+ formatlist[0] = cygnativeformat;
+ formatlist[1] = CF_TEXT;
+
+ if ((format = GetPriorityClipboardFormat (formatlist, 2)) <= 0)
+ {
+ CloseClipboard ();
+ return (0);
+ }
+
+ hglb = GetClipboardData (format);
+
+ if (format == cygnativeformat)
+ {
+ unsigned char *nativebuf = (unsigned char *) GlobalLock (hglb);
+ if (nativebuf)
+ {
+ size_t buflen = (*(size_t *) nativebuf);
+ buf = nativebuf + sizeof (size_t);
+ len = buflen;
+
+ fwrite (buf, sizeof (unsigned char), len, out);
+ GlobalUnlock (hglb);
+ }
+ }
+ else
+ {
+ LPSTR lpstr = (LPSTR) GlobalLock (hglb);
+ if (lpstr)
+ {
+ size_t lplen = strlen (lpstr);
+ buf = lpstr;
+ len = lplen;
+
+ fwrite (buf, sizeof (unsigned char), len, out);
+ GlobalUnlock (hglb);
+ }
+ }
+ CloseClipboard ();
}
- hglb = GetClipboardData(format);
-
- if (format == cygnativeformat)
+ if (flags.endl_mode == ENDLMODE_UNIX)
{
- unsigned char *nativebuf = (unsigned char *) GlobalLock (hglb);
- if (nativebuf)
- {
- size_t buflen = (*(size_t *) nativebuf);
- buf = nativebuf + sizeof(size_t);
- len = buflen;
-
- fwrite(buf, sizeof(unsigned char), len, out);
- GlobalUnlock(hglb);
- }
- }
- else
- {
- LPSTR lpstr = (LPSTR) GlobalLock (hglb);
- if (lpstr)
- {
- size_t lplen = strlen(lpstr);
- buf = lpstr;
- len = lplen;
-
- fwrite(buf, sizeof(unsigned char), len, out);
- GlobalUnlock(hglb);
- }
- }
- CloseClipboard();
- }
-
- if (flags.endl_mode == ENDLMODE_UNIX )
- {
- /* remove the '\r' of any '\r\n' pair */
- int i, cnt;
- LPSTR lpstr;
- int lplen;
- char* prev;
- char* curr;
- char* pos;
-
- OpenClipboard(0);
- hglb = GetClipboardData(CF_TEXT);
- lpstr = GlobalLock(hglb);
- lplen = strlen(lpstr);
-
- 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);
- return 1;
+ /* remove the '\r' of any '\r\n' pair */
+ int i, cnt;
+ LPSTR lpstr;
+ int lplen;
+ char *prev;
+ char *curr;
+ char *pos;
+
+ OpenClipboard (0);
+ hglb = GetClipboardData (CF_TEXT);
+ lpstr = GlobalLock (hglb);
+ lplen = strlen (lpstr);
+
+ 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);
+ return 1;
+ }
+
+ cnt = 0; /* how many '\r' have been dropped */
+ pos = newStr; /* the current position in the new string */
+ prev = buf;
+ curr = buf;
+ for (i = 1; i < len; i++)
+ {
+ ++curr;
+ if ((*prev == '\r') && (*curr == '\n'))
+ {
+ ++cnt;
+ }
+ else
+ {
+ *pos++ = *prev;
+ }
+ prev = curr;
+ }
+ /* always copy the last char -- it can't be the '\r' of a '\r\n' pair */
+ *pos++ = *prev;
+ *pos = '\0';
+ len -= cnt;
+
+ /* not len+1 because we don't want to write the final '\0' */
+ fwrite (newStr, sizeof (char), len, out);
+ free (newStr);
+
+ GlobalUnlock (hglb);
+ CloseClipboard ();
}
- cnt = 0; /* how many '\r' have been dropped */
- pos = newStr; /* the current position in the new string */
- prev = buf;
- curr = buf;
- for (i = 1; i < len; i++) {
- ++curr;
- if ((*prev == '\r') && (*curr == '\n')) {
- ++cnt;
- } else {
- *pos++ = *prev;
- }
- prev = curr;
- }
- /* always copy the last char -- it can't be the '\r' of a '\r\n' pair */
- *pos++ = *prev;
- *pos = '\0';
- len -= cnt;
-
- /* not len+1 because we don't want to write the final '\0' */
- fwrite(newStr, sizeof(char), len, out);
- free(newStr);
-
- GlobalUnlock(hglb);
- CloseClipboard();
- }
-
- if (flags.endl_mode == ENDLMODE_DOS )
- {
- /* change all instances of [!\r]\n to \r\n */
- int i, cnt;
- LPSTR lpstr;
- int lplen;
- char *newStr = NULL;
- char* prev;
- char* curr;
- char* pos;
-
- OpenClipboard(0);
- hglb = GetClipboardData(CF_TEXT);
- lpstr = GlobalLock(hglb);
- lplen = strlen(lpstr);
-
- buf = lpstr;
- len = lplen;
-
- /* count the instances [!\r]\n */
- cnt = 0;
- prev = buf;
- curr = buf;
- if (buf[0] == '\n') { cnt++; }
- for (i = 1; i < len; i++) {
- ++curr;
- if ((*curr == '\n') && (*prev != '\r')) {
- cnt++;
- }
- 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);
- return 1;
- }
-
- /* do the search and replace */
- pos = newStr;
- prev = buf;
- curr = buf;
- if (buf[0] == '\n') {
- *pos++ = '\r';
- *pos++ = '\n';
- } else {
- *pos++ = buf[0];
- }
- for (i = 1; i < len; i++) {
- ++curr;
- if ((*curr == '\n') && (*prev != '\r')) {
- *pos++ = '\r';
- *pos++ = '\n';
- } else {
- *pos++ = *curr;
- }
- prev = curr;
+ if (flags.endl_mode == ENDLMODE_DOS)
+ {
+ /* change all instances of [!\r]\n to \r\n */
+ int i, cnt;
+ LPSTR lpstr;
+ int lplen;
+ char *newStr = NULL;
+ char *prev;
+ char *curr;
+ char *pos;
+
+ OpenClipboard (0);
+ hglb = GetClipboardData (CF_TEXT);
+ lpstr = GlobalLock (hglb);
+ lplen = strlen (lpstr);
+
+ buf = lpstr;
+ len = lplen;
+
+ /* count the instances [!\r]\n */
+ cnt = 0;
+ prev = buf;
+ curr = buf;
+ if (buf[0] == '\n')
+ {
+ cnt++;
+ }
+ for (i = 1; i < len; i++)
+ {
+ ++curr;
+ if ((*curr == '\n') && (*prev != '\r'))
+ {
+ cnt++;
+ }
+ 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);
+ return 1;
+ }
+
+ /* do the search and replace */
+ pos = newStr;
+ prev = buf;
+ curr = buf;
+ if (buf[0] == '\n')
+ {
+ *pos++ = '\r';
+ *pos++ = '\n';
+ }
+ else
+ {
+ *pos++ = buf[0];
+ }
+ for (i = 1; i < len; i++)
+ {
+ ++curr;
+ if ((*curr == '\n') && (*prev != '\r'))
+ {
+ *pos++ = '\r';
+ *pos++ = '\n';
+ }
+ else
+ {
+ *pos++ = *curr;
+ }
+ prev = curr;
+ }
+ len += cnt;
+ *pos = '\0';
+
+ /* not len+1 because we don't want to write the final '\0' */
+ fwrite (newStr, sizeof (char), len, out);
+ free (newStr);
+
+ GlobalUnlock (hglb);
+ CloseClipboard ();
}
- len += cnt;
- *pos = '\0';
-
- /* not len+1 because we don't want to write the final '\0' */
- fwrite(newStr, sizeof(char), len, out);
- free(newStr);
-
- GlobalUnlock(hglb);
- CloseClipboard();
- }
/* reset the mode of the output channel (in case it's stdout or stderr) */
- setmode(fileno(out), origMode);
- return(0);
+ setmode (fileno (out), origMode);
+ return (0);
}
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include <io.h>
static const char versionID[] = PACKAGE_VERSION;
static const char revID[] =
- "$Id$";
+ "$Id$";
static const char copyrightID[] =
- "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
+ "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
typedef struct
{
- int endl_mode; /* ENDLMODE_DOS ENDLMODE_UNIX ENDLMODE_NOCONV */
- int unixflag; /* indicates that the user specified -u or --unix */
- int dosflag; /* indicates that the user specified -d or --dos */
- int noconvflag;/* indicates that the user specified -n or --no-conv */
+ int endl_mode; /* ENDLMODE_DOS ENDLMODE_UNIX ENDLMODE_NOCONV */
+ int unixflag; /* indicates that the user specified -u or --unix */
+ int dosflag; /* indicates that the user specified -d or --dos */
+ int noconvflag; /* indicates that the user specified -n or --no-conv */
} flags_struct;
-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);
-static int putclip(FILE * in, flags_struct flags, FILE * f, char * name);
-
-static char * program_name;
-
-int main(int argc, const char ** argv)
+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);
+static int putclip (FILE * in, flags_struct flags, FILE * f, char *name);
+
+static char *program_name;
+
+int
+main (int argc, const char **argv)
{
poptContext optCon;
- const char ** rest;
+ const char **rest;
int rc;
int ec = PUTCLIP_OK;
flags_struct flags = { ENDLMODE_NOCONV, FALSE, FALSE, FALSE };
struct poptOption generalOptionsTable[] = {
- { "dos", 'd', POPT_ARG_NONE, NULL, 'd', \
- "Clipboard text will have DOS line endings.", NULL},
- { "unix", 'u', POPT_ARG_NONE, NULL, 'U', \
- "Clipboard text will have UNIX line endings.", NULL},
- { "no-conv", 'n', POPT_ARG_NONE, NULL, 'n', \
- "Do not translate line endings.", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"dos", 'd', POPT_ARG_NONE, NULL, 'd',
+ "Clipboard text will have DOS line endings.", NULL},
+ {"unix", 'u', POPT_ARG_NONE, NULL, 'U',
+ "Clipboard text will have UNIX line endings.", NULL},
+ {"no-conv", 'n', POPT_ARG_NONE, NULL, 'n',
+ "Do not translate line endings.", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption helpOptionsTable[] = {
- { "help", '?', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", '\0', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"help", '?', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", '\0', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0, \
- "General options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0,
+ "General options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
- if( (program_name = strdup(argv[0])) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- optCon = poptGetContext(NULL, argc, argv, opt, 0);
-
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- case '?': help(optCon, stderr, program_name);
- goto exit;
- case 'u': usage(optCon, stderr, program_name);
- goto exit;
- case 'v': version(optCon, stderr, program_name);
- goto exit;
- case 'l': license(optCon, stderr, program_name);
- goto exit;
- case 'd': flags.dosflag = TRUE;
- flags.endl_mode = ENDLMODE_DOS;
- break;
- case 'U': flags.unixflag = TRUE;
- flags.endl_mode = ENDLMODE_UNIX;
- break;
- case 'n': flags.noconvflag = TRUE;
- flags.endl_mode = ENDLMODE_NOCONV;
- break;
+ if ((program_name = strdup (argv[0])) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- }
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- ec = PUTCLIP_ARGERR;
- goto exit;
- }
- if (flags.dosflag && flags.unixflag) {
- fprintf(stderr, "%s: can't specify both --unix and --dos (-u and -d)\n", program_name);
- ec = PUTCLIP_ARGERR;
- goto exit;
- }
- if (flags.dosflag && flags.noconvflag) {
- fprintf(stderr, "%s: can't specify both --dos and --no-conv (-d and -n)\n", program_name);
- ec = PUTCLIP_ARGERR;
- goto exit;
- }
- if (flags.unixflag && flags.noconvflag) {
- fprintf(stderr, "%s: can't specify both --unix and --no-conv (-u and -n)\n", program_name);
- ec = PUTCLIP_ARGERR;
- goto exit;
- }
-
- rest = poptGetArgs(optCon);
+ optCon = poptGetContext (NULL, argc, argv, opt, 0);
+
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ case '?':
+ help (optCon, stderr, program_name);
+ goto exit;
+ case 'u':
+ usage (optCon, stderr, program_name);
+ goto exit;
+ case 'v':
+ version (optCon, stderr, program_name);
+ goto exit;
+ case 'l':
+ license (optCon, stderr, program_name);
+ goto exit;
+ case 'd':
+ flags.dosflag = TRUE;
+ flags.endl_mode = ENDLMODE_DOS;
+ break;
+ case 'U':
+ flags.unixflag = TRUE;
+ flags.endl_mode = ENDLMODE_UNIX;
+ break;
+ case 'n':
+ flags.noconvflag = TRUE;
+ flags.endl_mode = ENDLMODE_NOCONV;
+ break;
+ }
+ }
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ ec = PUTCLIP_ARGERR;
+ goto exit;
+ }
+ if (flags.dosflag && flags.unixflag)
+ {
+ fprintf (stderr,
+ "%s: can't specify both --unix and --dos (-u and -d)\n",
+ program_name);
+ ec = PUTCLIP_ARGERR;
+ goto exit;
+ }
+ if (flags.dosflag && flags.noconvflag)
+ {
+ fprintf (stderr,
+ "%s: can't specify both --dos and --no-conv (-d and -n)\n",
+ program_name);
+ ec = PUTCLIP_ARGERR;
+ goto exit;
+ }
+ if (flags.unixflag && flags.noconvflag)
+ {
+ fprintf (stderr,
+ "%s: can't specify both --unix and --no-conv (-u and -n)\n",
+ program_name);
+ ec = PUTCLIP_ARGERR;
+ goto exit;
+ }
+
+ rest = poptGetArgs (optCon);
if (rest == NULL)
- ec |= putclip(stdin, flags, stderr, program_name);
+ ec |= putclip (stdin, flags, stderr, program_name);
else
- {
- fprintf(stderr, "Extra args ignored: ");
- while (*rest)
- fprintf(stderr, "%s ", *rest++);
- fprintf(stderr, "\n");
- ec |= putclip(stdin, flags, stderr, program_name);
- }
+ {
+ fprintf (stderr, "Extra args ignored: ");
+ while (*rest)
+ fprintf (stderr, "%s ", *rest++);
+ fprintf (stderr, "\n");
+ ec |= putclip (stdin, flags, stderr, program_name);
+ }
exit:
- poptFreeContext(optCon);
- free(program_name);
- return(ec);
+ poptFreeContext (optCon);
+ free (program_name);
+ return (ec);
}
-static const char * getVersion()
+static const char *
+getVersion ()
{
return versionID;
}
-static void printTopDescription(FILE * f, char * name)
+static void
+printTopDescription (FILE * f, char *name)
{
- fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
- fprintf(f, " Copy stdin to the Windows Clipboard\n\n");
+ fprintf (f, "%s is part of cygutils version %s\n", name, getVersion ());
+ fprintf (f, " Copy stdin to the Windows Clipboard\n\n");
}
-static void printBottomDescription(FILE * f, char * name)
+static void
+printBottomDescription (FILE * f, char *name)
{
- fprintf(f, "NOTE: by default, no line ending conversion is performed.\n");
+ fprintf (f, "NOTE: by default, no line ending conversion is performed.\n");
}
-static printLicense(FILE * f, char * name)
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE * f, char * name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
- printBottomDescription(f, name);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
+ printBottomDescription (f, name);
}
-static void version(poptContext optCon, FILE * f, char * name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
+ printTopDescription (f, name);
}
-static void license(poptContext optCon, FILE * f, char * name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
+ printTopDescription (f, name);
+ printLicense (f, name);
}
-int putclip(FILE * in, flags_struct flags, FILE * f, char * name)
+int
+putclip (FILE * in, flags_struct flags, FILE * f, char *name)
{
- HANDLE hData; /* handle to clip data */
- char* clipbuf = NULL; /* pointer to clip data */
- char chunk[CLIPCHUNK+1];
+ HANDLE hData; /* handle to clip data */
+ char *clipbuf = NULL; /* pointer to clip data */
+ char chunk[CLIPCHUNK + 1];
char *buf = NULL;
char *convbuf = NULL;
char *buf_old = NULL;
read entire stream into memory. However, let's try to
do this using the minimum amount of memory, but keep
allocating more if needed.
- */
+ */
do
- {
- numread = fread(chunk,sizeof(char),CLIPCHUNK,in);
- if(numread > 0)
{
- if (buf)
- {
- if ((buf_old = malloc (len * sizeof(char))) == NULL)
+ numread = fread (chunk, sizeof (char), CLIPCHUNK, in);
+ if (numread > 0)
{
- fprintf(stderr, "%s: memory allocation error\n", name);
- return(PUTCLIP_ERR);
+ if (buf)
+ {
+ if ((buf_old = malloc (len * sizeof (char))) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", name);
+ return (PUTCLIP_ERR);
+ }
+ memcpy (buf_old, buf, len);
+ free (buf);
+ }
+ if ((buf = malloc ((len + numread) * sizeof (char))) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", name);
+ return (PUTCLIP_ERR);
+ }
+ if (buf_old)
+ {
+ memcpy (buf, buf_old, len);
+ free (buf_old);
+ }
+ ptr = &(buf[len]);
+ memcpy (ptr, chunk, numread);
+ len += numread;
}
- memcpy(buf_old, buf, len);
- free(buf);
- }
- if ((buf = malloc ((len+numread) * sizeof(char))) == NULL)
- {
- fprintf(stderr, "%s: memory allocation error\n", name);
- return(PUTCLIP_ERR);
- }
- if (buf_old)
- {
- memcpy(buf,buf_old,len);
- free(buf_old);
- }
- ptr = &(buf[len]);
- memcpy(ptr,chunk,numread);
- len += numread;
}
- }
- while(!feof(in) && !ferror(in));
+ while (!feof (in) && !ferror (in));
/* format the string according to flags */
if (buf)
- {
- const char* CYGWIN_NATIVE = "CYGWIN_NATIVE_CLIPBOARD";
- UINT cygnativeformat;
+ {
+ const char *CYGWIN_NATIVE = "CYGWIN_NATIVE_CLIPBOARD";
+ UINT cygnativeformat;
- OpenClipboard(0);
- cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE);
- CloseClipboard();
+ OpenClipboard (0);
+ cygnativeformat = RegisterClipboardFormat (CYGWIN_NATIVE);
+ CloseClipboard ();
- // if flags.endl_mode == ENDLMODE_NOCONV
- convbuf = buf;
- convlen = len;
+ // if flags.endl_mode == ENDLMODE_NOCONV
+ convbuf = buf;
+ convlen = len;
- if (flags.endl_mode == ENDLMODE_UNIX)
- {
- /* remove all instances of '\r' */
- int i, cnt;
- char *newStr = NULL;
- char* prev;
- char* curr;
- char* pos;
-
- /* allocate memory for a new string */
- if ((newStr = (char*)malloc(convlen * sizeof(char))) == NULL) {
- fprintf(stderr, "%s: memory allocation error\n", name);
- return (PUTCLIP_ERR);
- }
-
- cnt = 0; /* # of occurrences of \r\n */
- pos = newStr; /* the current position in the new string */
- prev = buf;
- curr = buf;
- for (i = 1; i < convlen; i++) {
- ++curr;
- if ((*prev == '\r') && *curr == '\n') {
- cnt++;
- } else {
+ if (flags.endl_mode == ENDLMODE_UNIX)
+ {
+ /* remove all instances of '\r' */
+ int i, cnt;
+ char *newStr = NULL;
+ char *prev;
+ char *curr;
+ char *pos;
+
+ /* allocate memory for a new string */
+ if ((newStr = (char *) malloc (convlen * sizeof (char))) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", name);
+ return (PUTCLIP_ERR);
+ }
+
+ cnt = 0; /* # of occurrences of \r\n */
+ pos = newStr; /* the current position in the new string */
+ prev = buf;
+ curr = buf;
+ for (i = 1; i < convlen; i++)
+ {
+ ++curr;
+ if ((*prev == '\r') && *curr == '\n')
+ {
+ cnt++;
+ }
+ else
+ {
+ *pos++ = *prev;
+ }
+ prev = curr;
+ }
+ /* always copy the last char -- it can't be the '\r' of a '\r\n' pair */
*pos++ = *prev;
+ convbuf = newStr;
+ convlen -= cnt;
}
- prev = curr;
- }
- /* always copy the last char -- it can't be the '\r' of a '\r\n' pair */
- *pos++ = *prev;
- convbuf = newStr;
- convlen -= cnt;
- }
- if (flags.endl_mode == ENDLMODE_DOS)
- {
- /* change all instances of [!\r]\n to \r\n */
- int i, cnt;
- char *newStr = NULL;
- char* prev;
- char* curr;
- char* pos;
-
- /* count the instances [!\r]\n */
- cnt = 0;
- prev = buf;
- curr = buf;
- if (buf[0] == '\n') { cnt++; }
- for (i = 1; i < convlen; i++) {
- ++curr;
- if ((*curr == '\n') && (*prev != '\r')) {
- cnt++;
- }
- prev = curr;
- }
-
- /* allocate memory for a new string */
- if ((newStr = (char*)malloc((convlen+cnt+1)* sizeof(char))) == NULL) {
- fprintf(stderr,"%s: memory allocation error\n", name);
- return (PUTCLIP_ERR);
- }
-
- /* do the search and replace */
- pos = newStr;
- prev = buf;
- curr = buf;
- if (buf[0] == '\n') {
- *pos++ = '\r';
- *pos++ = '\n';
- } else {
- *pos++ = buf[0];
- }
- for (i = 1; i < convlen; i++) {
- ++curr;
- if ((*curr == '\n') && (*prev != '\r')) {
- *pos++ = '\r';
- *pos++ = '\n';
- } else {
- *pos++ = *curr;
+ if (flags.endl_mode == ENDLMODE_DOS)
+ {
+ /* change all instances of [!\r]\n to \r\n */
+ int i, cnt;
+ char *newStr = NULL;
+ char *prev;
+ char *curr;
+ char *pos;
+
+ /* count the instances [!\r]\n */
+ cnt = 0;
+ prev = buf;
+ curr = buf;
+ if (buf[0] == '\n')
+ {
+ cnt++;
+ }
+ for (i = 1; i < convlen; i++)
+ {
+ ++curr;
+ if ((*curr == '\n') && (*prev != '\r'))
+ {
+ cnt++;
+ }
+ prev = curr;
+ }
+
+ /* allocate memory for a new string */
+ if ((newStr =
+ (char *) malloc ((convlen + cnt + 1) * sizeof (char))) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", name);
+ return (PUTCLIP_ERR);
+ }
+
+ /* do the search and replace */
+ pos = newStr;
+ prev = buf;
+ curr = buf;
+ if (buf[0] == '\n')
+ {
+ *pos++ = '\r';
+ *pos++ = '\n';
+ }
+ else
+ {
+ *pos++ = buf[0];
+ }
+ for (i = 1; i < convlen; i++)
+ {
+ ++curr;
+ if ((*curr == '\n') && (*prev != '\r'))
+ {
+ *pos++ = '\r';
+ *pos++ = '\n';
+ }
+ else
+ {
+ *pos++ = *curr;
+ }
+ prev = curr;
+ }
+ convbuf = newStr;
+ convlen += cnt;
}
- prev = curr;
- }
- convbuf = newStr;
- convlen += cnt;
- }
- if (buf != convbuf) free(buf);
- /* Now, the only buffer left to be freed is convbuf */
+ if (buf != convbuf)
+ free (buf);
+ /* Now, the only buffer left to be freed is convbuf */
- /* Allocate memory and copy the string to it */
- /* cygwin native format */
- OpenClipboard(0);
- if (!(hData = GlobalAlloc(GMEM_MOVEABLE, convlen + sizeof (size_t))))
- {
- fprintf(f, "Couldn't allocate global buffer for write.\n");
- if (convbuf) free(convbuf);
- return (PUTCLIP_ERR);
- }
- if (!(clipbuf = (char*) GlobalLock(hData)))
- {
- fprintf(f, "Couldn't lock global buffer.\n");
- free(convbuf);
- return (PUTCLIP_ERR);
- }
+ /* Allocate memory and copy the string to it */
+ /* cygwin native format */
+ OpenClipboard (0);
+ if (!(hData = GlobalAlloc (GMEM_MOVEABLE, convlen + sizeof (size_t))))
+ {
+ fprintf (f, "Couldn't allocate global buffer for write.\n");
+ if (convbuf)
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
+ if (!(clipbuf = (char *) GlobalLock (hData)))
+ {
+ fprintf (f, "Couldn't lock global buffer.\n");
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
- *(size_t *) (clipbuf) = convlen;
- memcpy(clipbuf + sizeof (size_t), convbuf, convlen);
- GlobalUnlock (hData);
- EmptyClipboard();
- if (! SetClipboardData (cygnativeformat, hData))
- {
- fprintf(f, "Couldn't write native format to the clipboard %04x %x\n",
- cygnativeformat, hData);
- free(convbuf);
- return (PUTCLIP_ERR);
- }
- 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;
+ *(size_t *) (clipbuf) = convlen;
+ memcpy (clipbuf + sizeof (size_t), convbuf, convlen);
+ GlobalUnlock (hData);
+ EmptyClipboard ();
+ if (!SetClipboardData (cygnativeformat, hData))
+ {
+ fprintf (f,
+ "Couldn't write native format to the clipboard %04x %x\n",
+ cygnativeformat, hData);
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
+ 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)))
- {
- fprintf(f, "Couldn't allocate global buffer for write.\n");
- free(convbuf);
- return (PUTCLIP_ERR);
- }
- if (!(clipbuf = (char*) GlobalLock(hData)))
- {
- fprintf(f, "Couldn't lock global buffer.\n");
- free(convbuf);
- return (PUTCLIP_ERR);
- }
+ /* CF_TEXT format */
+ OpenClipboard (0);
+ if (!(hData = GlobalAlloc (GMEM_MOVEABLE, convlen + 2)))
+ {
+ fprintf (f, "Couldn't allocate global buffer for write.\n");
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
+ if (!(clipbuf = (char *) GlobalLock (hData)))
+ {
+ fprintf (f, "Couldn't lock global buffer.\n");
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
- memcpy(clipbuf, convbuf, convlen);
- *(clipbuf + convlen) = '\0';
- *(clipbuf + convlen + 1) = '\0';
+ memcpy (clipbuf, convbuf, convlen);
+ *(clipbuf + convlen) = '\0';
+ *(clipbuf + convlen + 1) = '\0';
- GlobalUnlock (hData);
- if (! SetClipboardData (CF_TEXT, hData))
- {
- fprintf(f, "Couldn't write CF_TEXT format to the clipboard.\n");
- free(convbuf);
- return (PUTCLIP_ERR);
+ GlobalUnlock (hData);
+ if (!SetClipboardData (CF_TEXT, hData))
+ {
+ fprintf (f, "Couldn't write CF_TEXT format to the clipboard.\n");
+ free (convbuf);
+ return (PUTCLIP_ERR);
+ }
+ 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;
+
+ free (convbuf);
}
- CloseClipboard();
- if (GlobalFree(hData))
+ else /* if (buf) */
{
- fprintf(f, "Couldn't free global buffer after write to clipboard.\n");
- free(convbuf);
- return (PUTCLIP_ERR);
+ OpenClipboard (0);
+ EmptyClipboard ();
+ CloseClipboard ();
}
- hData = NULL;
- clipbuf = NULL;
-
- free(convbuf);
- }
- else /* if (buf) */
- {
- OpenClipboard(0);
- EmptyClipboard();
- CloseClipboard();
- }
return (PUTCLIP_OK);
}
*/
#if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char versionID[] = PACKAGE_VERSION;
static const char revID[] =
- "$Id$";
+ "$Id$";
static const char copyrightID[] =
- "Copyright (c) 2002,...\n"
- "Michael Schaap. All rights reserved.\n"
- "Licensed under GPL v2.0\n";
+ "Copyright (c) 2002,...\n"
+ "Michael Schaap. All rights reserved.\n" "Licensed under GPL v2.0\n";
/* The name this program was run with. */
static char *program_name;
-typedef enum StartFlags {
- SF_NONE = 0,
- SF_VERBOSE = 1 << 0,
- SF_WAIT = 1 << 1,
+typedef enum StartFlags
+{
+ SF_NONE = 0,
+ SF_VERBOSE = 1 << 0,
+ SF_WAIT = 1 << 1,
} StartFlags;
-static int cygStart(const char *aPath, const wchar_t *action,
- const wchar_t *args, const char *workDir,
- int show, StartFlags startFlags);
-static int winStart(const wchar_t *aPath, const wchar_t *action,
- const wchar_t *args, const wchar_t *workDir,
- int show, StartFlags startFlags);
-static char *startError(int err);
-static const char *getVersion(void);
-static void printTopDescription(FILE *f, char *name);
-static void printBottomDescription(FILE *f, char *name);
-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);
-
-static size_t mbstowcs_noerr(wchar_t *wcs, const char *mbs, size_t n)
+static int cygStart (const char *aPath, const wchar_t * action,
+ const wchar_t * args, const char *workDir,
+ int show, StartFlags startFlags);
+static int winStart (const wchar_t * aPath, const wchar_t * action,
+ const wchar_t * args, const wchar_t * workDir,
+ int show, StartFlags startFlags);
+static char *startError (int err);
+static const char *getVersion (void);
+static void printTopDescription (FILE * f, char *name);
+static void printBottomDescription (FILE * f, char *name);
+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);
+
+static size_t
+mbstowcs_noerr (wchar_t * wcs, const char *mbs, size_t n)
{
- size_t wcsLen = mbstowcs(wcs, mbs, n);
- if (wcsLen == (size_t) -1) {
- fprintf(stderr, "%s: multibyte to wide string conversion error\n",
- program_name);
- exit(1);
+ size_t wcsLen = mbstowcs (wcs, mbs, n);
+ if (wcsLen == (size_t) - 1)
+ {
+ fprintf (stderr, "%s: multibyte to wide string conversion error\n",
+ program_name);
+ exit (1);
}
- return wcsLen;
+ return wcsLen;
}
-static wchar_t *mbstowcs_dup(const char *mbs)
+static wchar_t *
+mbstowcs_dup (const char *mbs)
{
- size_t len = mbstowcs (NULL, mbs, 0);
- if (len == (size_t) -1) {
- fprintf(stderr, "%s: multibyte to wide string conversion error\n",
- program_name);
- exit(1);
+ size_t len = mbstowcs (NULL, mbs, 0);
+ if (len == (size_t) - 1)
+ {
+ fprintf (stderr, "%s: multibyte to wide string conversion error\n",
+ program_name);
+ exit (1);
}
- wchar_t *wcs = (wchar_t *) malloc(sizeof(wchar_t) * (len + 1));
- size_t wcsLen = mbstowcs_noerr(wcs, mbs, len);
- wcs[wcsLen] = L'\0';
- return wcs;
+ wchar_t *wcs = (wchar_t *) malloc (sizeof (wchar_t) * (len + 1));
+ size_t wcsLen = mbstowcs_noerr (wcs, mbs, len);
+ wcs[wcsLen] = L'\0';
+ return wcs;
}
-int main(int argc, const char **argv)
+int
+main (int argc, const char **argv)
{
- poptContext optCon;
- const char *arg;
- const char **rest;
- int rc;
- int ret;
- wchar_t *action = NULL;
- char *file = NULL;
- size_t argLength;
- const char **tmp;
- wchar_t *args = NULL;
- char *workDir = NULL;
- int show = SW_SHOWNORMAL;
- StartFlags startFlags = SF_NONE;
-
- setlocale(LC_ALL, "");
-
- /* Action options */
- struct poptOption actionOptionsTable[] = {
- { "action", 'a', POPT_ARG_STRING, NULL, 'a', \
- "Use specified action instead of default", NULL},
- { "open", 'o', POPT_ARG_NONE, NULL, 'o', \
- "Short for: --action open", NULL},
- { "explore", 'x', POPT_ARG_NONE, NULL, 'x', \
- "Short for: --action explore", NULL},
- { "edit", 'e', POPT_ARG_NONE, NULL, 'e', \
- "Short for: --action edit", NULL},
- { "find", 'f', POPT_ARG_NONE, NULL, 'f', \
- "Short for: --action find", NULL},
- { "print", 'p', POPT_ARG_NONE, NULL, 'p', \
- "Short for: --action print", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- /* Directory options */
- struct poptOption directoryOptionsTable[] = {
- { "directory", 'd', POPT_ARG_STRING, NULL, 'd', \
- "Set working directory", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- /* Show options */
- struct poptOption showOptionsTable[] = {
- { "hide", '\0', POPT_ARG_NONE, NULL, 'H', \
- "Hides the window and activates another window", NULL},
- { "maximize", '\0', POPT_ARG_NONE, NULL, 'M', \
- "Maximizes the specified window", NULL},
- { "minimize", '\0', POPT_ARG_NONE, NULL, 'N', \
- "Minimizes the specified window and activates the next top-level "
- "window in the z-order", NULL},
- { "restore", '\0', POPT_ARG_NONE, NULL, 'R', \
- "Activates and displays the window. If the window is minimized or "
- "maximized, Windows restores it to its original size and position. "
- "An application should specify this flag when restoring a minimized "
- "window", NULL},
- { "show", '\0', POPT_ARG_NONE, NULL, 'S', \
- "Activates the window and displays it in its current size and "
- "position", NULL},
- { "showmaximized", '\0', POPT_ARG_NONE, NULL, 'X', \
- "Activates the window and displays it as a maximized window", NULL},
- { "showminimized", '\0', POPT_ARG_NONE, NULL, 'Y', \
- "Activates the window and displays it as a minimized window", NULL},
- { "showminnoactive", '\0', POPT_ARG_NONE, NULL, 'Z', \
- "Displays the window as a minimized window. The active window "
- "remains active", NULL},
- { "showna", '\0', POPT_ARG_NONE, NULL, 'A', \
- "Displays the window in its current state. The active window "
- "remains active", NULL},
- { "shownoactivate", '\0', POPT_ARG_NONE, NULL, 'V', \
- "Displays a window in its most recent size and position. The "
- "active window remains active", NULL},
- { "shownormal", '\0', POPT_ARG_NONE, NULL, 'O', \
- "Activates and displays a window. If the window is minimized or "
- "maximized, Windows restores it to its original size and position. "
- "An application should specify this flag when displaying the window "
- "for the first time", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- /* Startup options */
- struct poptOption startupOptionsTable[] = {
- { "wait", 'w', POPT_ARG_NONE, NULL, 'w',
- "Waits until the started application terminates before exiting.",
- NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- /* Troubleshooting options */
- struct poptOption troubleOptionsTable[] = {
- { "verbose", 'v', POPT_ARG_NONE, NULL, 'E', \
- "Show the actual ShellExecute call made", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- /* Help options */
- struct poptOption helpOptionsTable[] = {
- { "help", '?', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", '\0', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { "reference", '\0', POPT_ARG_NONE, NULL, 'r', \
- "Open MSDN reference for ShellExecute", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, actionOptionsTable, 0, \
- "Action options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, directoryOptionsTable, 0, \
- "Directory options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, showOptionsTable, 0, \
- "Show options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, startupOptionsTable, 0,
- "Startup options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, troubleOptionsTable, 0, \
- "Troubleshooting options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
- };
-
- if ((program_name = strdup(argv[0])) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
+ poptContext optCon;
+ const char *arg;
+ const char **rest;
+ int rc;
+ int ret;
+ wchar_t *action = NULL;
+ char *file = NULL;
+ size_t argLength;
+ const char **tmp;
+ wchar_t *args = NULL;
+ char *workDir = NULL;
+ int show = SW_SHOWNORMAL;
+ StartFlags startFlags = SF_NONE;
+
+ setlocale (LC_ALL, "");
+
+ /* Action options */
+ struct poptOption actionOptionsTable[] = {
+ {"action", 'a', POPT_ARG_STRING, NULL, 'a',
+ "Use specified action instead of default", NULL},
+ {"open", 'o', POPT_ARG_NONE, NULL, 'o',
+ "Short for: --action open", NULL},
+ {"explore", 'x', POPT_ARG_NONE, NULL, 'x',
+ "Short for: --action explore", NULL},
+ {"edit", 'e', POPT_ARG_NONE, NULL, 'e',
+ "Short for: --action edit", NULL},
+ {"find", 'f', POPT_ARG_NONE, NULL, 'f',
+ "Short for: --action find", NULL},
+ {"print", 'p', POPT_ARG_NONE, NULL, 'p',
+ "Short for: --action print", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
+ };
+
+ /* Directory options */
+ struct poptOption directoryOptionsTable[] = {
+ {"directory", 'd', POPT_ARG_STRING, NULL, 'd',
+ "Set working directory", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
+ };
+
+ /* Show options */
+ struct poptOption showOptionsTable[] = {
+ {"hide", '\0', POPT_ARG_NONE, NULL, 'H',
+ "Hides the window and activates another window", NULL},
+ {"maximize", '\0', POPT_ARG_NONE, NULL, 'M',
+ "Maximizes the specified window", NULL},
+ {"minimize", '\0', POPT_ARG_NONE, NULL, 'N',
+ "Minimizes the specified window and activates the next top-level "
+ "window in the z-order", NULL},
+ {"restore", '\0', POPT_ARG_NONE, NULL, 'R',
+ "Activates and displays the window. If the window is minimized or "
+ "maximized, Windows restores it to its original size and position. "
+ "An application should specify this flag when restoring a minimized "
+ "window", NULL},
+ {"show", '\0', POPT_ARG_NONE, NULL, 'S',
+ "Activates the window and displays it in its current size and "
+ "position", NULL},
+ {"showmaximized", '\0', POPT_ARG_NONE, NULL, 'X',
+ "Activates the window and displays it as a maximized window", NULL},
+ {"showminimized", '\0', POPT_ARG_NONE, NULL, 'Y',
+ "Activates the window and displays it as a minimized window", NULL},
+ {"showminnoactive", '\0', POPT_ARG_NONE, NULL, 'Z',
+ "Displays the window as a minimized window. The active window "
+ "remains active", NULL},
+ {"showna", '\0', POPT_ARG_NONE, NULL, 'A',
+ "Displays the window in its current state. The active window "
+ "remains active", NULL},
+ {"shownoactivate", '\0', POPT_ARG_NONE, NULL, 'V',
+ "Displays a window in its most recent size and position. The "
+ "active window remains active", NULL},
+ {"shownormal", '\0', POPT_ARG_NONE, NULL, 'O',
+ "Activates and displays a window. If the window is minimized or "
+ "maximized, Windows restores it to its original size and position. "
+ "An application should specify this flag when displaying the window "
+ "for the first time", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
+ };
+
+ /* Startup options */
+ struct poptOption startupOptionsTable[] = {
+ {"wait", 'w', POPT_ARG_NONE, NULL, 'w',
+ "Waits until the started application terminates before exiting.",
+ NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
+ };
+
+ /* Troubleshooting options */
+ struct poptOption troubleOptionsTable[] = {
+ {"verbose", 'v', POPT_ARG_NONE, NULL, 'E',
+ "Show the actual ShellExecute call made", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
+ };
+
+ /* Help options */
+ struct poptOption helpOptionsTable[] = {
+ {"help", '?', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", '\0', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {"reference", '\0', POPT_ARG_NONE, NULL, 'r',
+ "Open MSDN reference for ShellExecute", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
+ };
+
+ struct poptOption opt[] = {
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, actionOptionsTable, 0,
+ "Action options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, directoryOptionsTable, 0,
+ "Directory options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, showOptionsTable, 0,
+ "Show options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, startupOptionsTable, 0,
+ "Startup options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, troubleOptionsTable, 0,
+ "Troubleshooting options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
+ };
+
+ if ((program_name = strdup (argv[0])) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- /* Parse options */
- optCon = poptGetContext(NULL, argc, argv, opt, POPT_CONTEXT_POSIXMEHARDER);
- poptSetOtherOptionHelp(optCon, "[OPTION]... FILE [ARGUMENTS]");
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- /* Help options */
- case '?':
- help(optCon, stdout, program_name);
- poptFreeContext(optCon);
- free(program_name);
- if (action)
- free(action);
- if (workDir)
- free(workDir);
- return(0);
- case 'u':
- usage(optCon, stdout, program_name);
- poptFreeContext(optCon);
- free(program_name);
- if (action)
- free(action);
- if (workDir)
- free(workDir);
- return(0);
- case 'v':
- version(optCon, stdout, program_name);
- poptFreeContext(optCon);
- free(program_name);
- if (action)
- free(action);
- if (workDir)
- free(workDir);
- return(0);
- case 'l':
- license(optCon, stdout, program_name);
- poptFreeContext(optCon);
- free(program_name);
- if (action)
- free(action);
- if (workDir)
- free(workDir);
- return(0);
- case 'r':
- cygStart(MSDN_URL, NULL, NULL, NULL, SW_NORMAL, startFlags);
- poptFreeContext(optCon);
- free(program_name);
- if (action)
- free(action);
- if (workDir)
- free(workDir);
- return(0);
-
- /* Action options */
- case 'a':
- if (arg = poptGetOptArg(optCon)) {
- if ((action = mbstowcs_dup(arg)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n",
- argv[0]);
- exit(1);
- }
- }
- break;
- case 'o':
- if ((action = mbstowcs_dup(ACTION_OPEN)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- break;
- case 'x':
- if ((action = mbstowcs_dup(ACTION_EXPLORE)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- break;
- case 'e':
- if ((action = mbstowcs_dup(ACTION_EDIT)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- break;
- case 'f':
- if ((action = mbstowcs_dup(ACTION_FIND)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- break;
- case 'p':
- if ((action = mbstowcs_dup(ACTION_PRINT)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
+ /* Parse options */
+ optCon = poptGetContext (NULL, argc, argv, opt, POPT_CONTEXT_POSIXMEHARDER);
+ poptSetOtherOptionHelp (optCon, "[OPTION]... FILE [ARGUMENTS]");
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ /* Help options */
+ case '?':
+ help (optCon, stdout, program_name);
+ poptFreeContext (optCon);
+ free (program_name);
+ if (action)
+ free (action);
+ if (workDir)
+ free (workDir);
+ return (0);
+ case 'u':
+ usage (optCon, stdout, program_name);
+ poptFreeContext (optCon);
+ free (program_name);
+ if (action)
+ free (action);
+ if (workDir)
+ free (workDir);
+ return (0);
+ case 'v':
+ version (optCon, stdout, program_name);
+ poptFreeContext (optCon);
+ free (program_name);
+ if (action)
+ free (action);
+ if (workDir)
+ free (workDir);
+ return (0);
+ case 'l':
+ license (optCon, stdout, program_name);
+ poptFreeContext (optCon);
+ free (program_name);
+ if (action)
+ free (action);
+ if (workDir)
+ free (workDir);
+ return (0);
+ case 'r':
+ cygStart (MSDN_URL, NULL, NULL, NULL, SW_NORMAL, startFlags);
+ poptFreeContext (optCon);
+ free (program_name);
+ if (action)
+ free (action);
+ if (workDir)
+ free (workDir);
+ return (0);
+
+ /* Action options */
+ case 'a':
+ if (arg = poptGetOptArg (optCon))
+ {
+ if ((action = mbstowcs_dup (arg)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- break;
-
- /* Directory options */
- case 'd':
- if (arg = poptGetOptArg(optCon)) {
- if ((workDir = strdup(arg)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n",
- argv[0]);
- exit(1);
- }
+ }
+ break;
+ case 'o':
+ if ((action = mbstowcs_dup (ACTION_OPEN)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
+ }
+ break;
+ case 'x':
+ if ((action = mbstowcs_dup (ACTION_EXPLORE)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
+ }
+ break;
+ case 'e':
+ if ((action = mbstowcs_dup (ACTION_EDIT)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
+ }
+ break;
+ case 'f':
+ if ((action = mbstowcs_dup (ACTION_FIND)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
+ }
+ break;
+ case 'p':
+ if ((action = mbstowcs_dup (ACTION_PRINT)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
+ }
+ break;
+
+ /* Directory options */
+ case 'd':
+ if (arg = poptGetOptArg (optCon))
+ {
+ if ((workDir = strdup (arg)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- break;
-
- /* Show options */
- case 'H':
- show = SW_HIDE;
- break;
- case 'M':
- show = SW_MAXIMIZE;
- break;
- case 'N':
- show = SW_MINIMIZE;
- break;
- case 'R':
- show = SW_RESTORE;
- break;
- case 'S':
- show = SW_SHOW;
- break;
- case 'X':
- show = SW_SHOWMAXIMIZED;
- break;
- case 'Y':
- show = SW_SHOWMINIMIZED;
- break;
- case 'Z':
- show = SW_SHOWMINNOACTIVE;
- break;
- case 'A':
- show = SW_SHOWNA;
- break;
- case 'V':
- show = SW_SHOWNOACTIVATE;
- break;
- case 'O':
- show = SW_SHOWNORMAL;
- break;
-
- /* Startup options */
- case 'w':
- startFlags |= SF_WAIT;
- break;
-
- /* Troubleshooting options */
- case 'E':
- startFlags |= SF_VERBOSE;
- break;
+ }
+ break;
+
+ /* Show options */
+ case 'H':
+ show = SW_HIDE;
+ break;
+ case 'M':
+ show = SW_MAXIMIZE;
+ break;
+ case 'N':
+ show = SW_MINIMIZE;
+ break;
+ case 'R':
+ show = SW_RESTORE;
+ break;
+ case 'S':
+ show = SW_SHOW;
+ break;
+ case 'X':
+ show = SW_SHOWMAXIMIZED;
+ break;
+ case 'Y':
+ show = SW_SHOWMINIMIZED;
+ break;
+ case 'Z':
+ show = SW_SHOWMINNOACTIVE;
+ break;
+ case 'A':
+ show = SW_SHOWNA;
+ break;
+ case 'V':
+ show = SW_SHOWNOACTIVATE;
+ break;
+ case 'O':
+ show = SW_SHOWNORMAL;
+ break;
+
+ /* Startup options */
+ case 'w':
+ startFlags |= SF_WAIT;
+ break;
+
+ /* Troubleshooting options */
+ case 'E':
+ startFlags |= SF_VERBOSE;
+ break;
}
}
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- poptFreeContext(optCon);
- free(program_name);
- if (action)
- free(action);
- if (workDir)
- free(workDir);
- return(2);
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ poptFreeContext (optCon);
+ free (program_name);
+ if (action)
+ free (action);
+ if (workDir)
+ free (workDir);
+ return (2);
}
- rest = poptGetArgs(optCon);
+ rest = poptGetArgs (optCon);
- /* Determine file (or program, or URL) to start */
- if (rest && *rest) {
- if ((file = strdup(*rest)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
+ /* Determine file (or program, or URL) to start */
+ if (rest && *rest)
+ {
+ if ((file = strdup (*rest)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- rest++;
- } else {
- usage(optCon, stdout, program_name);
- return(2);
+ rest++;
+ }
+ else
+ {
+ usage (optCon, stdout, program_name);
+ return (2);
}
- /* Retrieve any arguments */
- if (rest && *rest) {
- tmp = rest;
- argLength = strlen(*tmp);
- while (tmp++ && *tmp) {
- argLength += 1 + strlen(*tmp);
+ /* Retrieve any arguments */
+ if (rest && *rest)
+ {
+ tmp = rest;
+ argLength = strlen (*tmp);
+ while (tmp++ && *tmp)
+ {
+ argLength += 1 + strlen (*tmp);
}
- if ((args = (wchar_t *) malloc(sizeof(wchar_t) * (argLength + 1)))
- == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
+ if ((args = (wchar_t *) malloc (sizeof (wchar_t) * (argLength + 1)))
+ == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- size_t argOffset = mbstowcs_noerr(args, *rest, argLength);
- while (rest++ && *rest) {
- args[argOffset++] = L' ';
- size_t len = mbstowcs_noerr(args + argOffset, *rest,
- argLength - argOffset);
- argOffset += len;
+ size_t argOffset = mbstowcs_noerr (args, *rest, argLength);
+ while (rest++ && *rest)
+ {
+ args[argOffset++] = L' ';
+ size_t len = mbstowcs_noerr (args + argOffset, *rest,
+ argLength - argOffset);
+ argOffset += len;
}
- args[argOffset] = L'\0';
+ args[argOffset] = L'\0';
}
- /* Start it! */
- ret = cygStart(file, action, args, workDir, show, startFlags);
-
- poptFreeContext(optCon);
- free(program_name);
- if (action)
- free(action);
- if (args)
- free(args);
- if (workDir)
- free(workDir);
- if (file)
- free(file);
-
- return ret;
+ /* Start it! */
+ ret = cygStart (file, action, args, workDir, show, startFlags);
+
+ poptFreeContext (optCon);
+ free (program_name);
+ if (action)
+ free (action);
+ if (args)
+ free (args);
+ if (workDir)
+ free (workDir);
+ if (file)
+ free (file);
+
+ return ret;
}
/* ShellExecute*W is TOO SLOW when there is '\\?\' */
-static const wchar_t *skipLocalUNCPart(const wchar_t *path)
+static const wchar_t *
+skipLocalUNCPart (const wchar_t * path)
{
- size_t offset = 0;
- if ( (wcslen (path) < MAX_PATH + 4)
- && (!wcsncmp (path, L"\\\\?\\", 4))
- && (path[5] == L':'))
- return path + 4;
- else
- return path;
+ size_t offset = 0;
+ if ((wcslen (path) < MAX_PATH + 4)
+ && (!wcsncmp (path, L"\\\\?\\", 4)) && (path[5] == L':'))
+ return path + 4;
+ else
+ return path;
}
/* Start a program, or open a file or URL, using Cygwin POSIX paths */
-static int cygStart(const char *aPath, const wchar_t *action,
- const wchar_t *args, const char *workDir,
- int show, StartFlags startFlags)
+static int
+cygStart (const char *aPath, const wchar_t * action,
+ const wchar_t * args, const char *workDir,
+ int show, StartFlags startFlags)
{
- wchar_t *winPath = NULL;
- wchar_t *winDir = NULL;
- const wchar_t *pWinPath = NULL;
- const wchar_t *pWinDir = NULL;
- int rc = 0;
-
- /* Convert file path from POSIX to Windows, unless it looks like a URL */
- if (!strstr(aPath, "://")) {
- ssize_t len = cygwin_conv_path (CCP_POSIX_TO_WIN_W, aPath, NULL, 0);
- if (len < 0) {
- fprintf(stderr,
- "%s: error converting path `%s' from cygwin to native format: %s\n",
- program_name, aPath, strerror (errno));
- rc = 1;
- goto cleanup;
+ wchar_t *winPath = NULL;
+ wchar_t *winDir = NULL;
+ const wchar_t *pWinPath = NULL;
+ const wchar_t *pWinDir = NULL;
+ int rc = 0;
+
+ /* Convert file path from POSIX to Windows, unless it looks like a URL */
+ if (!strstr (aPath, "://"))
+ {
+ ssize_t len = cygwin_conv_path (CCP_POSIX_TO_WIN_W, aPath, NULL, 0);
+ if (len < 0)
+ {
+ fprintf (stderr,
+ "%s: error converting path `%s' from cygwin to native format: %s\n",
+ program_name, aPath, strerror (errno));
+ rc = 1;
+ goto cleanup;
}
- winPath = (wchar_t *) malloc ((len + 1) * sizeof (wchar_t));
- if (!winPath) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- rc = 1;
- goto cleanup;
+ winPath = (wchar_t *) malloc ((len + 1) * sizeof (wchar_t));
+ if (!winPath)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", program_name);
+ rc = 1;
+ goto cleanup;
}
- if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, aPath, winPath,
- (len + 1) * sizeof (wchar_t)) < 0) {
- fprintf(stderr,
- "%s: error converting path `%s' from cygwin to format: %s\n",
- program_name, aPath, strerror (errno));
- rc = 1;
- goto cleanup;
+ if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, aPath, winPath,
+ (len + 1) * sizeof (wchar_t)) < 0)
+ {
+ fprintf (stderr,
+ "%s: error converting path `%s' from cygwin to format: %s\n",
+ program_name, aPath, strerror (errno));
+ rc = 1;
+ goto cleanup;
}
- pWinPath = skipLocalUNCPart (winPath);
- } else {
- size_t len = mbstowcs (NULL, aPath, 0);
- if (len == (size_t) -1) {
- fprintf(stderr, "%s: error converting path `%s' to unicode: %s\n",
- program_name, aPath, strerror (errno));
- rc = 1;
- goto cleanup;
+ pWinPath = skipLocalUNCPart (winPath);
+ }
+ else
+ {
+ size_t len = mbstowcs (NULL, aPath, 0);
+ if (len == (size_t) - 1)
+ {
+ fprintf (stderr, "%s: error converting path `%s' to unicode: %s\n",
+ program_name, aPath, strerror (errno));
+ rc = 1;
+ goto cleanup;
}
- winPath = (wchar_t *) malloc ((len + 1) * sizeof (wchar_t));
- if (!winPath) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- rc = 1;
- goto cleanup;
+ winPath = (wchar_t *) malloc ((len + 1) * sizeof (wchar_t));
+ if (!winPath)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", program_name);
+ rc = 1;
+ goto cleanup;
}
- if (mbstowcs (winPath, aPath, (len + 1) * sizeof (wchar_t)) == (size_t) -1) {
- fprintf(stderr, "%s: error converting path `%s' to unicode: %s\n",
- program_name, aPath, strerror (errno));
- rc = 1;
- goto cleanup;
+ if (mbstowcs (winPath, aPath, (len + 1) * sizeof (wchar_t)) ==
+ (size_t) - 1)
+ {
+ fprintf (stderr, "%s: error converting path `%s' to unicode: %s\n",
+ program_name, aPath, strerror (errno));
+ rc = 1;
+ goto cleanup;
}
- winPath[len] = L'\0';
- pWinPath = winPath;
+ winPath[len] = L'\0';
+ pWinPath = winPath;
}
- /* Convert working directory, if any, from POSIX to Windows */
- if (workDir) {
- ssize_t len = cygwin_conv_path (CCP_POSIX_TO_WIN_W, workDir, NULL, 0);
- if (len < 0) {
- fprintf(stderr,
- "%s: error converting path `%s' from cygwin to native format: %s\n",
- program_name, workDir, strerror (errno));
- rc = 1;
- goto cleanup;
+ /* Convert working directory, if any, from POSIX to Windows */
+ if (workDir)
+ {
+ ssize_t len = cygwin_conv_path (CCP_POSIX_TO_WIN_W, workDir, NULL, 0);
+ if (len < 0)
+ {
+ fprintf (stderr,
+ "%s: error converting path `%s' from cygwin to native format: %s\n",
+ program_name, workDir, strerror (errno));
+ rc = 1;
+ goto cleanup;
}
- winDir = (wchar_t *) malloc ((len + 1) * sizeof (wchar_t));
- if (!winDir) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- rc = 1;
- goto cleanup;
+ winDir = (wchar_t *) malloc ((len + 1) * sizeof (wchar_t));
+ if (!winDir)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", program_name);
+ rc = 1;
+ goto cleanup;
}
- if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, workDir, winDir,
- (len + 1) * sizeof (wchar_t)) < 0) {
- fprintf(stderr,
- "%s: error converting path `%s' from cygwin to native format: %s\n",
- program_name, workDir, strerror (errno));
- rc = 1;
- goto cleanup;
+ if (cygwin_conv_path (CCP_POSIX_TO_WIN_W, workDir, winDir,
+ (len + 1) * sizeof (wchar_t)) < 0)
+ {
+ fprintf (stderr,
+ "%s: error converting path `%s' from cygwin to native format: %s\n",
+ program_name, workDir, strerror (errno));
+ rc = 1;
+ goto cleanup;
}
- pWinDir = skipLocalUNCPart (winDir);
- rc = winStart (pWinPath, action, args, pWinDir, show, startFlags);
- } else {
- rc = winStart (pWinPath, action, args, NULL, show, startFlags);
+ pWinDir = skipLocalUNCPart (winDir);
+ rc = winStart (pWinPath, action, args, pWinDir, show, startFlags);
+ }
+ else
+ {
+ rc = winStart (pWinPath, action, args, NULL, show, startFlags);
}
cleanup:
- if (winDir)
- free (winDir);
- if (winPath)
- free (winPath);
+ if (winDir)
+ free (winDir);
+ if (winPath)
+ free (winPath);
- return rc;
+ return rc;
}
-static void printLastError(FILE* file);
+static void printLastError (FILE * file);
/* Start a program, or open a file or URL, using Windows paths */
-static int winStart(const wchar_t *aPath, const wchar_t *action,
- const wchar_t *args, const wchar_t *workDir,
- int show, StartFlags startFlags)
+static int
+winStart (const wchar_t * aPath, const wchar_t * action,
+ const wchar_t * args, const wchar_t * workDir,
+ int show, StartFlags startFlags)
{
- /* Need to sync the Windows environment */
- cygwin_internal(CW_SYNC_WINENV);
+ /* Need to sync the Windows environment */
+ cygwin_internal (CW_SYNC_WINENV);
- if (startFlags & SF_VERBOSE) {
- wprintf(L"ShellExecute(NULL, \"%ls\", \"%ls\", \"%ls\", \"%ls\", %d)\n",
- action, aPath, args, workDir, show);
+ if (startFlags & SF_VERBOSE)
+ {
+ wprintf
+ (L"ShellExecute(NULL, \"%ls\", \"%ls\", \"%ls\", \"%ls\", %d)\n",
+ action, aPath, args, workDir, show);
}
- if (!(startFlags & SF_WAIT)) {
- int ret = (int) ShellExecuteW(NULL, action, aPath, args, workDir, show);
+ if (!(startFlags & SF_WAIT))
+ {
+ int ret =
+ (int) ShellExecuteW (NULL, action, aPath, args, workDir, show);
- if (ret >= 32) {
- return 0;
- } else {
- fwprintf(stderr, L"Unable to start '%ls': %s\n", aPath, startError(ret));
- return 1;
+ if (ret >= 32)
+ {
+ return 0;
}
- } else {
- SHELLEXECUTEINFOW sei;
-
- memset(&sei, 0, sizeof(sei));
- sei.cbSize = sizeof(sei);
- sei.lpVerb = action;
- sei.lpFile = aPath;
- sei.lpParameters = args;
- sei.lpDirectory = workDir;
- sei.nShow = show;
- sei.fMask |= SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
-
- if (!ShellExecuteExW(&sei)) {
- if (((int) sei.hInstApp) < 32) {
- fwprintf(stderr, L"Unable to start '%ls': %s\n", aPath, startError((int) sei.hInstApp));
- return 1;
- } else {
- fwprintf(stderr, L"Unable to start '%ls': ", aPath);
- printLastError(stderr);
- fprintf(stderr, "\n");
- return 1;
+ else
+ {
+ fwprintf (stderr, L"Unable to start '%ls': %s\n", aPath,
+ startError (ret));
+ return 1;
+ }
+ }
+ else
+ {
+ SHELLEXECUTEINFOW sei;
+
+ memset (&sei, 0, sizeof (sei));
+ sei.cbSize = sizeof (sei);
+ sei.lpVerb = action;
+ sei.lpFile = aPath;
+ sei.lpParameters = args;
+ sei.lpDirectory = workDir;
+ sei.nShow = show;
+ sei.fMask |= SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
+
+ if (!ShellExecuteExW (&sei))
+ {
+ if (((int) sei.hInstApp) < 32)
+ {
+ fwprintf (stderr, L"Unable to start '%ls': %s\n", aPath,
+ startError ((int) sei.hInstApp));
+ return 1;
+ }
+ else
+ {
+ fwprintf (stderr, L"Unable to start '%ls': ", aPath);
+ printLastError (stderr);
+ fprintf (stderr, "\n");
+ return 1;
}
}
- if (sei.hProcess) {
- DWORD code;
- WaitForSingleObject(sei.hProcess, INFINITE);
- if (!GetExitCodeProcess(sei.hProcess, &code)) {
- code = 1;
+ if (sei.hProcess)
+ {
+ DWORD code;
+ WaitForSingleObject (sei.hProcess, INFINITE);
+ if (!GetExitCodeProcess (sei.hProcess, &code))
+ {
+ code = 1;
}
- CloseHandle(sei.hProcess);
- return (int) code;
+ CloseHandle (sei.hProcess);
+ return (int) code;
}
- return 0;
+ return 0;
}
}
/* Print a correctly-localized error message for GetLastError() to the given
file descriptor. */
-static void printLastError(FILE* file)
+static void
+printLastError (FILE * file)
{
- LPSTR buf = 0;
-
- if (!FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- 0,
- GetLastError(),
- 0,
- (LPSTR) &buf,
- 0, // min size
- 0))
+ LPSTR buf = 0;
+
+ if (!FormatMessage (FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, 0, GetLastError (), 0, (LPSTR) & buf, 0, // min size
+ 0))
{
- // avoid recursion getting message - possible but infinite-prone
- fprintf(file, "Couldn't retrieve error message");
- return;
+ // avoid recursion getting message - possible but infinite-prone
+ fprintf (file, "Couldn't retrieve error message");
+ return;
}
- fputs(buf, file);
+ fputs (buf, file);
- LocalFree(buf);
+ LocalFree (buf);
}
/* Return an error message, given a ShellExecute return code */
-static char *startError(int err)
+static char *
+startError (int err)
{
- switch (err) {
- case 0:
- return "The operating system is out of memory or resources.";
- case ERROR_FILE_NOT_FOUND:
- return "The specified file was not found.";
- case ERROR_PATH_NOT_FOUND:
- return "The specified path was not found.";
- case ERROR_BAD_FORMAT:
- return "The .exe file is invalid (non-Win32 .exe or error in "
- ".exe image).";
- case SE_ERR_ACCESSDENIED:
- return "The operating system denied access to the specified file.";
- case SE_ERR_ASSOCINCOMPLETE:
- return "The file name association is incomplete or invalid.";
- case SE_ERR_DDEBUSY:
- return "The DDE transaction could not be completed because "
- "other DDE transactions were being processed.";
- case SE_ERR_DDEFAIL:
- return "The DDE transaction failed.";
- case SE_ERR_DDETIMEOUT:
- return "The DDE transaction could not be completed because the "
- "request timed out.";
- case SE_ERR_DLLNOTFOUND:
- return "The specified dynamic-link library was not found.";
- case SE_ERR_NOASSOC:
- return "There is no application associated with the given file "
- "name extension.";
- case SE_ERR_OOM:
- return "There was not enough memory to complete the operation.";
- case SE_ERR_SHARE:
- return "A sharing violation occurred.";
- default:
- return "An unknown error occurred.";
+ switch (err)
+ {
+ case 0:
+ return "The operating system is out of memory or resources.";
+ case ERROR_FILE_NOT_FOUND:
+ return "The specified file was not found.";
+ case ERROR_PATH_NOT_FOUND:
+ return "The specified path was not found.";
+ case ERROR_BAD_FORMAT:
+ return "The .exe file is invalid (non-Win32 .exe or error in "
+ ".exe image).";
+ case SE_ERR_ACCESSDENIED:
+ return "The operating system denied access to the specified file.";
+ case SE_ERR_ASSOCINCOMPLETE:
+ return "The file name association is incomplete or invalid.";
+ case SE_ERR_DDEBUSY:
+ return "The DDE transaction could not be completed because "
+ "other DDE transactions were being processed.";
+ case SE_ERR_DDEFAIL:
+ return "The DDE transaction failed.";
+ case SE_ERR_DDETIMEOUT:
+ return "The DDE transaction could not be completed because the "
+ "request timed out.";
+ case SE_ERR_DLLNOTFOUND:
+ return "The specified dynamic-link library was not found.";
+ case SE_ERR_NOASSOC:
+ return "There is no application associated with the given file "
+ "name extension.";
+ case SE_ERR_OOM:
+ return "There was not enough memory to complete the operation.";
+ case SE_ERR_SHARE:
+ return "A sharing violation occurred.";
+ default:
+ return "An unknown error occurred.";
}
}
-static const char *getVersion()
+static const char *
+getVersion ()
{
- return versionID;
+ return versionID;
}
-static void printTopDescription(FILE *f, char *name)
+static void
+printTopDescription (FILE * f, char *name)
{
- 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");
+ 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");
}
-static void printBottomDescription(FILE *f, char *name)
+static void
+printBottomDescription (FILE * f, char *name)
{
- fprintf(f, "\n");
- fprintf(f, "With thanks to MSDN: <%s>\n\n", MSDN_URL);
- fprintf(f, "Please report any bugs to <cygwin(at)cygwin.com>.\n");
+ fprintf (f, "\n");
+ fprintf (f, "With thanks to MSDN: <%s>\n\n", MSDN_URL);
+ fprintf (f, "Please report any bugs to <cygwin(at)cygwin.com>.\n");
}
-static printLicense(FILE *f, char *name)
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE *f, char *name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
- printBottomDescription(f, name);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
+ printBottomDescription (f, name);
}
-static void version(poptContext optCon, FILE *f, char *name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
+ printTopDescription (f, name);
}
-static void license(poptContext optCon, FILE *f, char *name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
+ printTopDescription (f, name);
+ printLicense (f, name);
}
/**
- * dump.exe HEXDUMP utility
+ * dump.c HEXDUMP utility
*
* Copyright 2001,... by Charles Wilson <cwilson@ece.gatech.edu>.
* All rights reserved.
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char versionID[] = PACKAGE_VERSION;
static const char revID[] =
- "$Id$";
+ "$Id$";
static const char copyrightID[] =
- "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
-
-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);
-static void puthex(long n, int digits, int pos);
-static void dumpfile(FILE *f);
-
-static char * program_name;
+ "Copyright (c) 2001,...\nCharles S. Wilson. All rights reserved.\nLicensed under GPL v2.0\n";
+
+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);
+static void puthex (long n, int digits, int pos);
+static void dumpfile (FILE * f);
+
+static char *program_name;
static char line[80];
static long address;
-int main(int argc, const char ** argv)
+int
+main (int argc, const char **argv)
{
poptContext optCon;
- const char ** rest;
+ const char **rest;
int rc;
int ec = 0;
struct poptOption helpOptionsTable[] = {
- { "help", '?', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", '\0', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"help", '?', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", '\0', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
- if( (program_name = strdup(argv[0])) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- optCon = poptGetContext(NULL, argc, argv, opt, 0);
- poptSetOtherOptionHelp(optCon, "[OPTION...] [files...]");
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- case '?': help(optCon, stderr, program_name);
- goto exit;
- case 'u': usage(optCon, stderr, program_name);
- goto exit;
- case 'v': version(optCon, stderr, program_name);
- goto exit;
- case 'l': license(optCon, stderr, program_name);
- goto exit;
+ if ((program_name = strdup (argv[0])) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- }
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- ec = 2;
- goto exit;
- }
- rest = poptGetArgs(optCon);
+ optCon = poptGetContext (NULL, argc, argv, opt, 0);
+ poptSetOtherOptionHelp (optCon, "[OPTION...] [files...]");
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ case '?':
+ help (optCon, stderr, program_name);
+ goto exit;
+ case 'u':
+ usage (optCon, stderr, program_name);
+ goto exit;
+ case 'v':
+ version (optCon, stderr, program_name);
+ goto exit;
+ case 'l':
+ license (optCon, stderr, program_name);
+ goto exit;
+ }
+ }
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ ec = 2;
+ goto exit;
+ }
+ rest = poptGetArgs (optCon);
if (rest == NULL)
- dumpfile(stdin);
- else {
- while (*rest) {
- FILE *f = fopen(*rest, "rb");
- printf("%s:\n",*rest);
- if (f) {
- dumpfile(f);
- fclose(f);
- }
- else
- printf("*** Can't open %s!!\n", *rest);
- rest++;
+ dumpfile (stdin);
+ else
+ {
+ while (*rest)
+ {
+ FILE *f = fopen (*rest, "rb");
+ printf ("%s:\n", *rest);
+ if (f)
+ {
+ dumpfile (f);
+ fclose (f);
+ }
+ else
+ printf ("*** Can't open %s!!\n", *rest);
+ rest++;
+ }
}
- }
/*
if (argc < 2) dumpfile(stdin);
else {
}
*/
exit:
- poptFreeContext(optCon);
- free(program_name);
- return(ec);
+ poptFreeContext (optCon);
+ free (program_name);
+ return (ec);
}
-static const char * getVersion()
+static const char *
+getVersion ()
{
return versionID;
}
-static void printTopDescription(FILE * f, char * name)
+static void
+printTopDescription (FILE * f, char *name)
{
- 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");
+ 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");
}
-static void printBottomDescription(FILE * f, char * name)
+static void
+printBottomDescription (FILE * f, char *name)
{
- fprintf(f, "\n");
- fprintf(f, "Other arguments\n");
- fprintf(f, " [files...] dump each file specified; if none, use stdin\n");
+ fprintf (f, "\n");
+ fprintf (f, "Other arguments\n");
+ fprintf (f,
+ " [files...] dump each file specified; if none, use stdin\n");
}
-static printLicense(FILE * f, char * name)
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE * f, char * name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
- printBottomDescription(f, name);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
+ printBottomDescription (f, name);
}
-static void version(poptContext optCon, FILE * f, char * name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
+ printTopDescription (f, name);
}
-static void license(poptContext optCon, FILE * f, char * name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
-}
+ printTopDescription (f, name);
+ printLicense (f, name);
+}
-static void puthex(long n, int digits, int pos) {
- if (digits > 1) puthex(n/16,digits-1,pos);
- line[pos+digits-1] = "0123456789abcdef"[n%16];
+static void
+puthex (long n, int digits, int pos)
+{
+ if (digits > 1)
+ puthex (n / 16, digits - 1, pos);
+ line[pos + digits - 1] = "0123456789abcdef"[n % 16];
}
-static void dumpfile(FILE *f) {
- int c,i;
+static void
+dumpfile (FILE * f)
+{
+ int c, i;
address = 0;
- c=getc(f);
- while (1) {
- for (i=0;i<50;i++) line[i]=' ';
- for (;i<80;i++) line[i]=0;
- puthex(address,8,0);
- if (c == EOF) return;
- for (i=0;i<16;i++) {
- puthex(c & 0xff,2, 10 + i*2 + i/2);
- line[50+i] = '.';
- if (isprint(c & 0x7f)) line[50+i] = c & 0x7f;
- if ((c=getc(f)) == EOF) break;
- }
- if (address && ((address % 256) == 0)) {
+ c = getc (f);
+ while (1)
+ {
+ for (i = 0; i < 50; i++)
+ line[i] = ' ';
+ for (; i < 80; i++)
+ line[i] = 0;
+ puthex (address, 8, 0);
+ if (c == EOF)
+ return;
+ for (i = 0; i < 16; i++)
+ {
+ puthex (c & 0xff, 2, 10 + i * 2 + i / 2);
+ line[50 + i] = '.';
+ if (isprint (c & 0x7f))
+ line[50 + i] = c & 0x7f;
+ if ((c = getc (f)) == EOF)
+ break;
+ }
+ if (address && ((address % 256) == 0))
+ {
#if defined(__WIN32__) && !defined(__CYGWIN__)
- if (isatty (STDOUT_FILENO)) {
- while (kbhit())
- getch();
- getch();
- }
+ if (isatty (STDOUT_FILENO))
+ {
+ while (kbhit ())
+ getch ();
+ getch ();
+ }
#endif
- puts("");
- puts(" Addr 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 2 4 6 8 A C E ");
- puts("-------- ---- ---- ---- ---- ---- ---- ---- ---- ----------------");
+ puts ("");
+ puts
+ (" Addr 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 2 4 6 8 A C E ");
+ puts
+ ("-------- ---- ---- ---- ---- ---- ---- ---- ---- ----------------");
+ }
+ puts (line);
+ address += 16;
}
- puts(line);
- address += 16;
- }
}
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
#if HAVE_SYS_IPC_H
-# include <sys/ipc.h>
+# include <sys/ipc.h>
#endif
#if HAVE_SYS_MSG_H
-# include <sys/msg.h>
+# include <sys/msg.h>
#endif
#define MAX_SEND_SIZE 80
-struct mymsgbuf {
- long mtype;
- char mtext[MAX_SEND_SIZE];
+struct mymsgbuf
+{
+ long mtype;
+ char mtext[MAX_SEND_SIZE];
};
-void send_message(int qid, struct mymsgbuf *qbuf, long type, char *text);
-void read_message(int qid, struct mymsgbuf *qbuf, long type);
-void remove_queue(int qid);
-void change_queue_mode(int qid, char *mode);
-void usage(void);
+void send_message (int qid, struct mymsgbuf *qbuf, long type, char *text);
+void read_message (int qid, struct mymsgbuf *qbuf, long type);
+void remove_queue (int qid);
+void change_queue_mode (int qid, char *mode);
+void usage (void);
-int main(int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
- key_t key;
- int msgqueue_id;
- struct mymsgbuf qbuf;
-
- if(argc == 1)
- usage();
-
- /* Create unique key via call to ftok() */
- key = ftok(".", 'm');
-
- /* Open the queue - create if necessary */
- if((msgqueue_id = msgget(key, IPC_CREAT|0660)) == -1) {
- perror("msgget");
- exit(1);
- }
-
- switch(tolower(argv[1][0]))
- {
- case 's': send_message(msgqueue_id, (struct mymsgbuf *)&qbuf,
- atol(argv[2]), argv[3]);
- break;
- case 'r': read_message(msgqueue_id, &qbuf, atol(argv[2]));
- break;
- case 'd': remove_queue(msgqueue_id);
- break;
- case 'm': change_queue_mode(msgqueue_id, argv[2]);
- break;
-
- default: usage();
-
- }
-
- return(0);
+ key_t key;
+ int msgqueue_id;
+ struct mymsgbuf qbuf;
+
+ if (argc == 1)
+ usage ();
+
+ /* Create unique key via call to ftok() */
+ key = ftok (".", 'm');
+
+ /* Open the queue - create if necessary */
+ if ((msgqueue_id = msgget (key, IPC_CREAT | 0660)) == -1)
+ {
+ perror ("msgget");
+ exit (1);
+ }
+
+ switch (tolower (argv[1][0]))
+ {
+ case 's':
+ send_message (msgqueue_id, (struct mymsgbuf *) &qbuf,
+ atol (argv[2]), argv[3]);
+ break;
+ case 'r':
+ read_message (msgqueue_id, &qbuf, atol (argv[2]));
+ break;
+ case 'd':
+ remove_queue (msgqueue_id);
+ break;
+ case 'm':
+ change_queue_mode (msgqueue_id, argv[2]);
+ break;
+
+ default:
+ usage ();
+
+ }
+
+ return (0);
}
-void send_message(int qid, struct mymsgbuf *qbuf, long type, char *text)
+void
+send_message (int qid, struct mymsgbuf *qbuf, long type, char *text)
{
- /* Send a message to the queue */
- printf("Sending a message ...\n");
- qbuf->mtype = type;
- strcpy(qbuf->mtext, text);
-
- if((msgsnd(qid, (struct msgbuf *)qbuf,
- strlen(qbuf->mtext)+1, 0)) ==-1)
- {
- perror("msgsnd");
- exit(1);
- }
+ /* Send a message to the queue */
+ printf ("Sending a message ...\n");
+ qbuf->mtype = type;
+ strcpy (qbuf->mtext, text);
+
+ if ((msgsnd (qid, (struct msgbuf *) qbuf,
+ strlen (qbuf->mtext) + 1, 0)) == -1)
+ {
+ perror ("msgsnd");
+ exit (1);
+ }
}
-void read_message(int qid, struct mymsgbuf *qbuf, long type)
+void
+read_message (int qid, struct mymsgbuf *qbuf, long type)
{
- /* Read a message from the queue */
- printf("Reading a message ...\n");
- qbuf->mtype = type;
- msgrcv(qid, (struct msgbuf *)qbuf, MAX_SEND_SIZE, type, 0);
-
- printf("Type: %ld Text: %s\n", qbuf->mtype, qbuf->mtext);
+ /* Read a message from the queue */
+ printf ("Reading a message ...\n");
+ qbuf->mtype = type;
+ msgrcv (qid, (struct msgbuf *) qbuf, MAX_SEND_SIZE, type, 0);
+
+ printf ("Type: %ld Text: %s\n", qbuf->mtype, qbuf->mtext);
}
-void remove_queue(int qid)
+void
+remove_queue (int qid)
{
- /* Remove the queue */
- msgctl(qid, IPC_RMID, 0);
+ /* Remove the queue */
+ msgctl (qid, IPC_RMID, 0);
}
-void change_queue_mode(int qid, char *mode)
+void
+change_queue_mode (int qid, char *mode)
{
- struct msqid_ds myqueue_ds;
+ struct msqid_ds myqueue_ds;
- /* Get current info */
- msgctl(qid, IPC_STAT, &myqueue_ds);
+ /* Get current info */
+ msgctl (qid, IPC_STAT, &myqueue_ds);
- /* Convert and load the mode */
- sscanf(mode, "%ho", &myqueue_ds.msg_perm.mode);
+ /* Convert and load the mode */
+ sscanf (mode, "%ho", &myqueue_ds.msg_perm.mode);
- /* Update the mode */
- msgctl(qid, IPC_SET, &myqueue_ds);
+ /* Update the mode */
+ msgctl (qid, IPC_SET, &myqueue_ds);
}
-void usage(void)
+void
+usage (void)
{
- fprintf(stderr, "msgtool - A utility for tinkering with msg queues\n");
- fprintf(stderr, "\nUSAGE: msgtool (s)end <type> <messagetext>\n");
- fprintf(stderr, " (r)ecv <type>\n");
- fprintf(stderr, " (d)elete\n");
- fprintf(stderr, " (m)ode <octal mode>\n");
- exit(1);
+ fprintf (stderr, "msgtool - A utility for tinkering with msg queues\n");
+ fprintf (stderr, "\nUSAGE: msgtool (s)end <type> <messagetext>\n");
+ fprintf (stderr, " (r)ecv <type>\n");
+ fprintf (stderr, " (d)elete\n");
+ fprintf (stderr, " (m)ode <octal mode>\n");
+ exit (1);
}
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
#if HAVE_SYS_IPC_H
-# include <sys/ipc.h>
+# include <sys/ipc.h>
#endif
#if HAVE_SYS_SEM_H
-# include <sys/sem.h>
+# include <sys/sem.h>
#endif
/* arg for semctl system calls. */
-union semun {
- int val; /* value for SETVAL */
- struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
- ushort *array; /* array for GETALL & SETALL */
- struct seminfo *__buf; /* buffer for IPC_INFO */
+union semun
+{
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ ushort *array; /* array for GETALL & SETALL */
+ struct seminfo *__buf; /* buffer for IPC_INFO */
void *__pad;
};
-int get_sem_count(int sid);
-void show_sem_usage(int sid);
-int get_sem_count(int sid);
-void dispval(int sid);
+int get_sem_count (int sid);
+void show_sem_usage (int sid);
+int get_sem_count (int sid);
+void dispval (int sid);
-int main(int argc, char *argv[])
+int
+main (int argc, char *argv[])
{
- key_t key;
- int semset_id;
+ key_t key;
+ int semset_id;
- /* Create unique key via call to ftok() */
- key = ftok(".", 's');
+ /* Create unique key via call to ftok() */
+ key = ftok (".", 's');
- /* Open the semaphore set - do not create! */
- if((semset_id = semget(key, 1, 0666)) == -1)
- {
- printf("Semaphore set does not exist\n");
- exit(1);
- }
+ /* Open the semaphore set - do not create! */
+ if ((semset_id = semget (key, 1, 0666)) == -1)
+ {
+ printf ("Semaphore set does not exist\n");
+ exit (1);
+ }
- show_sem_usage(semset_id);
- return(0);
+ show_sem_usage (semset_id);
+ return (0);
}
-void show_sem_usage(int sid)
+void
+show_sem_usage (int sid)
{
- int cntr=0, maxsems, semval;
+ int cntr = 0, maxsems, semval;
- maxsems = get_sem_count(sid);
+ maxsems = get_sem_count (sid);
- while(cntr < maxsems) {
- semval = semctl(sid, cntr, GETVAL, 0);
- printf("Semaphore #%d: --> %d\n", cntr, semval);
- cntr++;
- }
+ while (cntr < maxsems)
+ {
+ semval = semctl (sid, cntr, GETVAL, 0);
+ printf ("Semaphore #%d: --> %d\n", cntr, semval);
+ cntr++;
+ }
}
-int get_sem_count(int sid)
+int
+get_sem_count (int sid)
{
- int rc;
- struct semid_ds mysemds;
- union semun semopts;
+ int rc;
+ struct semid_ds mysemds;
+ union semun semopts;
- /* Get current values for internal data structure */
- semopts.buf = &mysemds;
+ /* Get current values for internal data structure */
+ semopts.buf = &mysemds;
- if((rc = semctl(sid, 0, IPC_STAT, semopts)) == -1) {
- perror("semctl");
- exit(1);
- }
+ if ((rc = semctl (sid, 0, IPC_STAT, semopts)) == -1)
+ {
+ perror ("semctl");
+ exit (1);
+ }
- /* return number of semaphores in set */
- return(semopts.buf->sem_nsems);
+ /* return number of semaphores in set */
+ return (semopts.buf->sem_nsems);
}
-void dispval(int sid)
+void
+dispval (int sid)
{
- int semval;
+ int semval;
- semval = semctl(sid, 0, GETVAL, 0);
- printf("semval is %d\n", semval);
+ semval = semctl (sid, 0, GETVAL, 0);
+ printf ("semval is %d\n", semval);
}
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
#if HAVE_SYS_IPC_H
-# include <sys/ipc.h>
+# include <sys/ipc.h>
#endif
#if HAVE_SYS_SEM_H
-# include <sys/sem.h>
+# include <sys/sem.h>
#endif
/* cygserver doesn't define this constant where we
#endif
/* arg for semctl system calls. */
-union semun {
- int val; /* value for SETVAL */
- struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
- ushort *array; /* array for GETALL & SETALL */
- struct seminfo *__buf; /* buffer for IPC_INFO */
+union semun
+{
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ ushort *array; /* array for GETALL & SETALL */
+ struct seminfo *__buf; /* buffer for IPC_INFO */
void *__pad;
};
#define SEM_RESOURCE_MAX 1 /* Initial value of all semaphores */
-void opensem(int *sid, key_t key);
-void createsem(int *sid, key_t key, int members);
-void locksem(int sid, int member);
-void unlocksem(int sid, int member);
-void removesem(int sid);
-unsigned short get_member_count(int sid);
-int getval(int sid, int member);
-void dispval(int sid, int member);
-void changemode(int sid, char *mode);
-void usage(void);
-
-int main(int argc, char *argv[])
+void opensem (int *sid, key_t key);
+void createsem (int *sid, key_t key, int members);
+void locksem (int sid, int member);
+void unlocksem (int sid, int member);
+void removesem (int sid);
+unsigned short get_member_count (int sid);
+int getval (int sid, int member);
+void dispval (int sid, int member);
+void changemode (int sid, char *mode);
+void usage (void);
+
+int
+main (int argc, char *argv[])
{
- key_t key;
- int semset_id;
-
- if(argc == 1)
- usage();
-
- /* Create unique key via call to ftok() */
- key = ftok(".", 's');
-
- switch(tolower(argv[1][0]))
- {
- case 'c': if(argc != 3)
- usage();
- createsem(&semset_id, key, atoi(argv[2]));
- break;
- case 'l': if(argc != 3)
- usage();
- opensem(&semset_id, key);
- locksem(semset_id, atoi(argv[2]));
- break;
- case 'u': if(argc != 3)
- usage();
- opensem(&semset_id, key);
- unlocksem(semset_id, atoi(argv[2]));
- break;
- case 'd': opensem(&semset_id, key);
- removesem(semset_id);
- break;
- case 'm': opensem(&semset_id, key);
- changemode(semset_id, argv[2]);
- break;
- default: usage();
-
- }
-
- return(0);
+ key_t key;
+ int semset_id;
+
+ if (argc == 1)
+ usage ();
+
+ /* Create unique key via call to ftok() */
+ key = ftok (".", 's');
+
+ switch (tolower (argv[1][0]))
+ {
+ case 'c':
+ if (argc != 3)
+ usage ();
+ createsem (&semset_id, key, atoi (argv[2]));
+ break;
+ case 'l':
+ if (argc != 3)
+ usage ();
+ opensem (&semset_id, key);
+ locksem (semset_id, atoi (argv[2]));
+ break;
+ case 'u':
+ if (argc != 3)
+ usage ();
+ opensem (&semset_id, key);
+ unlocksem (semset_id, atoi (argv[2]));
+ break;
+ case 'd':
+ opensem (&semset_id, key);
+ removesem (semset_id);
+ break;
+ case 'm':
+ opensem (&semset_id, key);
+ changemode (semset_id, argv[2]);
+ break;
+ default:
+ usage ();
+
+ }
+
+ return (0);
}
-void opensem(int *sid, key_t key)
+void
+opensem (int *sid, key_t key)
{
- /* Open the semaphore set - do not create! */
+ /* Open the semaphore set - do not create! */
- if((*sid = semget(key, 0, 0666)) == -1)
- {
- printf("Semaphore set does not exist!\n");
- exit(1);
- }
+ if ((*sid = semget (key, 0, 0666)) == -1)
+ {
+ printf ("Semaphore set does not exist!\n");
+ exit (1);
+ }
}
-void createsem(int *sid, key_t key, int members)
+void
+createsem (int *sid, key_t key, int members)
{
- int cntr;
- union semun semopts;
-
- if(members > SEMMSL) {
- printf("Sorry, max number of semaphores in a set is %d\n",
- SEMMSL);
- exit(1);
- }
-
- printf("Attempting to create new semaphore set with %d members\n",
- members);
-
- if((*sid = semget(key, members, IPC_CREAT|IPC_EXCL|0666))
- == -1)
- {
- fprintf(stderr, "Semaphore set already exists!\n");
- exit(1);
- }
-
- semopts.val = SEM_RESOURCE_MAX;
-
- /* Initialize all members (could be done with SETALL) */
- for(cntr=0; cntr<members; cntr++)
- semctl(*sid, cntr, SETVAL, semopts);
+ int cntr;
+ union semun semopts;
+
+ if (members > SEMMSL)
+ {
+ printf ("Sorry, max number of semaphores in a set is %d\n", SEMMSL);
+ exit (1);
+ }
+
+ printf ("Attempting to create new semaphore set with %d members\n",
+ members);
+
+ if ((*sid = semget (key, members, IPC_CREAT | IPC_EXCL | 0666)) == -1)
+ {
+ fprintf (stderr, "Semaphore set already exists!\n");
+ exit (1);
+ }
+
+ semopts.val = SEM_RESOURCE_MAX;
+
+ /* Initialize all members (could be done with SETALL) */
+ for (cntr = 0; cntr < members; cntr++)
+ semctl (*sid, cntr, SETVAL, semopts);
}
-void locksem(int sid, int member)
+void
+locksem (int sid, int member)
{
- struct sembuf sem_lock={ 0, -1, IPC_NOWAIT};
-
- if( member<0 || member>(get_member_count(sid)-1))
- {
- fprintf(stderr, "semaphore member %d out of range\n", member);
- return;
- }
-
- /* Attempt to lock the semaphore set */
- if(!getval(sid, member))
- {
- fprintf(stderr, "Semaphore resources exhausted (no lock)!\n");
- exit(1);
- }
-
- sem_lock.sem_num = member;
-
- if((semop(sid, &sem_lock, 1)) == -1)
- {
- fprintf(stderr, "Lock failed\n");
- exit(1);
- }
- else
- printf("Semaphore resources decremented by one (locked)\n");
-
- dispval(sid, member);
+ struct sembuf sem_lock = { 0, -1, IPC_NOWAIT };
+
+ if (member < 0 || member > (get_member_count (sid) - 1))
+ {
+ fprintf (stderr, "semaphore member %d out of range\n", member);
+ return;
+ }
+
+ /* Attempt to lock the semaphore set */
+ if (!getval (sid, member))
+ {
+ fprintf (stderr, "Semaphore resources exhausted (no lock)!\n");
+ exit (1);
+ }
+
+ sem_lock.sem_num = member;
+
+ if ((semop (sid, &sem_lock, 1)) == -1)
+ {
+ fprintf (stderr, "Lock failed\n");
+ exit (1);
+ }
+ else
+ printf ("Semaphore resources decremented by one (locked)\n");
+
+ dispval (sid, member);
}
-void unlocksem(int sid, int member)
+void
+unlocksem (int sid, int member)
{
- struct sembuf sem_unlock={ member, 1, IPC_NOWAIT};
- int semval;
-
- if( member<0 || member>(get_member_count(sid)-1))
- {
- fprintf(stderr, "semaphore member %d out of range\n", member);
- return;
- }
-
- /* Is the semaphore set locked? */
- semval = getval(sid, member);
- if(semval == SEM_RESOURCE_MAX) {
- fprintf(stderr, "Semaphore not locked!\n");
- exit(1);
- }
-
- sem_unlock.sem_num = member;
-
- /* Attempt to lock the semaphore set */
- if((semop(sid, &sem_unlock, 1)) == -1)
- {
- fprintf(stderr, "Unlock failed\n");
- exit(1);
- }
- else
- printf("Semaphore resources incremented by one (unlocked)\n");
-
- dispval(sid, member);
+ struct sembuf sem_unlock = { member, 1, IPC_NOWAIT };
+ int semval;
+
+ if (member < 0 || member > (get_member_count (sid) - 1))
+ {
+ fprintf (stderr, "semaphore member %d out of range\n", member);
+ return;
+ }
+
+ /* Is the semaphore set locked? */
+ semval = getval (sid, member);
+ if (semval == SEM_RESOURCE_MAX)
+ {
+ fprintf (stderr, "Semaphore not locked!\n");
+ exit (1);
+ }
+
+ sem_unlock.sem_num = member;
+
+ /* Attempt to lock the semaphore set */
+ if ((semop (sid, &sem_unlock, 1)) == -1)
+ {
+ fprintf (stderr, "Unlock failed\n");
+ exit (1);
+ }
+ else
+ printf ("Semaphore resources incremented by one (unlocked)\n");
+
+ dispval (sid, member);
}
-void removesem(int sid)
+void
+removesem (int sid)
{
- union semun semopts;
- semopts.val = 0;
+ union semun semopts;
+ semopts.val = 0;
- semctl(sid, 0, IPC_RMID, semopts);
- printf("Semaphore removed\n");
+ semctl (sid, 0, IPC_RMID, semopts);
+ printf ("Semaphore removed\n");
}
-unsigned short get_member_count(int sid)
+unsigned short
+get_member_count (int sid)
{
- union semun semopts;
- struct semid_ds mysemds;
+ union semun semopts;
+ struct semid_ds mysemds;
- semopts.buf = &mysemds;
+ semopts.buf = &mysemds;
- /* Return number of members in the semaphore set */
- return(semopts.buf->sem_nsems);
+ /* Return number of members in the semaphore set */
+ return (semopts.buf->sem_nsems);
}
-int getval(int sid, int member)
+int
+getval (int sid, int member)
{
- int semval;
- union semun semopts;
- semopts.val = 0;
+ int semval;
+ union semun semopts;
+ semopts.val = 0;
- semval = semctl(sid, member, GETVAL, semopts);
- return(semval);
+ semval = semctl (sid, member, GETVAL, semopts);
+ return (semval);
}
-void changemode(int sid, char *mode)
+void
+changemode (int sid, char *mode)
{
- int rc;
- union semun semopts;
- struct semid_ds mysemds;
+ int rc;
+ union semun semopts;
+ struct semid_ds mysemds;
+
+ /* Get current values for internal data structure */
+ semopts.buf = &mysemds;
+
+ rc = semctl (sid, 0, IPC_STAT, semopts);
- /* Get current values for internal data structure */
- semopts.buf = &mysemds;
+ if (rc == -1)
+ {
+ perror ("semctl");
+ exit (1);
+ }
- rc = semctl(sid, 0, IPC_STAT, semopts);
+ printf ("Old permissions were %o\n", semopts.buf->sem_perm.mode);
- if (rc == -1) {
- perror("semctl");
- exit(1);
- }
-
- printf("Old permissions were %o\n", semopts.buf->sem_perm.mode);
-
- /* Change the permissions on the semaphore */
- sscanf(mode, "%ho", &semopts.buf->sem_perm.mode);
+ /* Change the permissions on the semaphore */
+ sscanf (mode, "%ho", &semopts.buf->sem_perm.mode);
- /* Update the internal data structure */
- semctl(sid, 0, IPC_SET, semopts);
+ /* Update the internal data structure */
+ semctl (sid, 0, IPC_SET, semopts);
- printf("Updated...\n");
+ printf ("Updated...\n");
}
-void dispval(int sid, int member)
+void
+dispval (int sid, int member)
{
- int semval;
- union semun semopts;
- semopts.val = 0;
+ int semval;
+ union semun semopts;
+ semopts.val = 0;
- semval = semctl(sid, member, GETVAL, semopts);
- printf("semval for member %d is %d\n", member, semval);
+ semval = semctl (sid, member, GETVAL, semopts);
+ printf ("semval for member %d is %d\n", member, semval);
}
-void usage(void)
+void
+usage (void)
{
- fprintf(stderr, "semtool - A utility for tinkering with semaphores\n");
- fprintf(stderr, "\nUSAGE: semtool (c)reate <semcount>\n");
- fprintf(stderr, " (l)ock <sem #>\n");
- fprintf(stderr, " (u)nlock <sem #>\n");
- fprintf(stderr, " (d)elete\n");
- fprintf(stderr, " (m)ode <mode>\n");
- exit(1);
+ fprintf (stderr, "semtool - A utility for tinkering with semaphores\n");
+ fprintf (stderr, "\nUSAGE: semtool (c)reate <semcount>\n");
+ fprintf (stderr, " (l)ock <sem #>\n");
+ fprintf (stderr, " (u)nlock <sem #>\n");
+ fprintf (stderr, " (d)elete\n");
+ fprintf (stderr, " (m)ode <mode>\n");
+ exit (1);
}
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
#if HAVE_SYS_IPC_H
-# include <sys/ipc.h>
+# include <sys/ipc.h>
#endif
#if HAVE_SYS_SHM_H
-# include <sys/shm.h>
+# include <sys/shm.h>
#endif
#define SEGSIZE 100
-main(int argc, char *argv[])
+main (int argc, char *argv[])
{
- key_t key;
- int shmid, cntr;
- char *segptr;
+ key_t key;
+ int shmid, cntr;
+ char *segptr;
- if(argc == 1)
- usage();
+ if (argc == 1)
+ usage ();
- /* Create unique key via call to ftok() */
- key = ftok(".", 'S');
+ /* Create unique key via call to ftok() */
+ key = ftok (".", 'S');
- /* Open the shared memory segment - create if necessary */
- if((shmid = shmget(key, SEGSIZE, IPC_CREAT|IPC_EXCL|0666)) == -1)
- {
- printf("Shared memory segment exists - opening as client\n");
-
- /* Segment probably already exists - try as a client */
- if((shmid = shmget(key, SEGSIZE, 0)) == -1)
- {
- perror("shmget");
- exit(1);
- }
- }
- else
- {
- printf("Creating new shared memory segment\n");
- }
+ /* Open the shared memory segment - create if necessary */
+ if ((shmid = shmget (key, SEGSIZE, IPC_CREAT | IPC_EXCL | 0666)) == -1)
+ {
+ printf ("Shared memory segment exists - opening as client\n");
- /* Attach (map) the shared memory segment into the current process */
- if((segptr = shmat(shmid, 0, 0)) == ((char *)-1))
+ /* Segment probably already exists - try as a client */
+ if ((shmid = shmget (key, SEGSIZE, 0)) == -1)
{
- perror("shmat");
- exit(1);
- }
-
- switch(tolower(argv[1][0]))
- {
- case 'w': writeshm(shmid, segptr, argv[2]);
- break;
- case 'r': readshm(shmid, segptr);
- break;
- case 'd': removeshm(shmid);
- break;
- case 'm': changemode(shmid, argv[2]);
- break;
- default: usage();
-
+ perror ("shmget");
+ exit (1);
}
+ }
+ else
+ {
+ printf ("Creating new shared memory segment\n");
+ }
+
+ /* Attach (map) the shared memory segment into the current process */
+ if ((segptr = shmat (shmid, 0, 0)) == ((char *) -1))
+ {
+ perror ("shmat");
+ exit (1);
+ }
+
+ switch (tolower (argv[1][0]))
+ {
+ case 'w':
+ writeshm (shmid, segptr, argv[2]);
+ break;
+ case 'r':
+ readshm (shmid, segptr);
+ break;
+ case 'd':
+ removeshm (shmid);
+ break;
+ case 'm':
+ changemode (shmid, argv[2]);
+ break;
+ default:
+ usage ();
+
+ }
}
-writeshm(int shmid, char *segptr, char *text)
+writeshm (int shmid, char *segptr, char *text)
{
- strcpy(segptr, text);
- printf("Done...\n");
+ strcpy (segptr, text);
+ printf ("Done...\n");
}
-readshm(int shmid, char *segptr)
+readshm (int shmid, char *segptr)
{
- printf("segptr: %s\n", segptr);
+ printf ("segptr: %s\n", segptr);
}
-removeshm(int shmid)
+removeshm (int shmid)
{
- shmctl(shmid, IPC_RMID, 0);
- printf("Shared memory segment marked for deletion\n");
+ shmctl (shmid, IPC_RMID, 0);
+ printf ("Shared memory segment marked for deletion\n");
}
-changemode(int shmid, char *mode)
+changemode (int shmid, char *mode)
{
- struct shmid_ds myshmds;
+ struct shmid_ds myshmds;
- /* Get current values for internal data structure */
- shmctl(shmid, IPC_STAT, &myshmds);
+ /* Get current values for internal data structure */
+ shmctl (shmid, IPC_STAT, &myshmds);
- /* Display old permissions */
- printf("Old permissions were: %o\n", myshmds.shm_perm.mode);
+ /* Display old permissions */
+ printf ("Old permissions were: %o\n", myshmds.shm_perm.mode);
- /* Convert and load the mode */
- sscanf(mode, "%o", &myshmds.shm_perm.mode);
+ /* Convert and load the mode */
+ sscanf (mode, "%o", &myshmds.shm_perm.mode);
- /* Update the mode */
- shmctl(shmid, IPC_SET, &myshmds);
+ /* Update the mode */
+ shmctl (shmid, IPC_SET, &myshmds);
- printf("New permissions are : %o\n", myshmds.shm_perm.mode);
+ printf ("New permissions are : %o\n", myshmds.shm_perm.mode);
}
-usage()
+usage ()
{
- fprintf(stderr, "shmtool - A utility for tinkering with shared memory\n");
- fprintf(stderr, "\nUSAGE: shmtool (w)rite <text>\n");
- fprintf(stderr, " (r)ead\n");
- fprintf(stderr, " (d)elete\n");
- fprintf(stderr, " (m)ode change <octal mode>\n");
- exit(1);
+ fprintf (stderr, "shmtool - A utility for tinkering with shared memory\n");
+ fprintf (stderr, "\nUSAGE: shmtool (w)rite <text>\n");
+ fprintf (stderr, " (r)ead\n");
+ fprintf (stderr, " (d)elete\n");
+ fprintf (stderr, " (m)ode change <octal mode>\n");
+ exit (1);
}
-
-/*
+/*
* lpr for cygwin/windows
*
* Copyright (C) 2000-2003 Rick Rankin
#include "src/lpr/Printer.hh"
#include "src/lpr/Win32Utils.hh"
+using namespace std;
inline LPTSTR tstr(const string & str)
{
return const_cast<char*>(str.c_str());
}
-Printer::Printer(const string &name, bool debugFlag)
- throw(PrinterException)
- : m_devName(name),
+Printer::Printer(const string &name, bool debugFlag) throw(PrinterException)
+ : m_devName(name),
m_debugFlag(debugFlag),
m_devHandle(INVALID_HANDLE_VALUE),
m_devMode(0),
mapPortName();
open();
-
+
// Initialize the DEVMODE structure
// Get the amount of space needed for the buffer.
DWORD needed = DocumentProperties(NULL, m_devHandle, tstr(m_devName),
NULL, NULL, 0);
m_devMode = reinterpret_cast<DEVMODE *>(new unsigned char[needed]);
-
+
// Get the default DEVMODE for the printer.
DWORD ret = DocumentProperties(NULL, m_devHandle, tstr(m_devName),
m_devMode, NULL, DM_OUT_BUFFER);
void Printer::close()
{
if (m_devHandle != INVALID_HANDLE_VALUE)
- {
- ClosePrinter(m_devHandle);
- m_devHandle = INVALID_HANDLE_VALUE;
- }
+ {
+ ClosePrinter(m_devHandle);
+ m_devHandle = INVALID_HANDLE_VALUE;
+ }
}
-void Printer::endDoc()
- throw(PrinterException)
+void Printer::endDoc() throw(PrinterException)
{
if (!EndDocPrinter(m_devHandle))
throw PrinterException("EndDocPrinter error: " +
Win32Utils::getErrorMessage());
}
-void Printer::endPage()
- throw(PrinterException)
+void Printer::endPage() throw(PrinterException)
{
cout << "Printer::endPage()" << endl;
if (!EndPagePrinter(m_devHandle))
Win32Utils::getErrorMessage());
}
-void Printer::flush(void)
- throw(PrinterException)
+void Printer::flush(void) throw(PrinterException)
{
if (m_bufferIndex > 0)
- {
- write(m_buffer, m_bufferIndex);
- m_bufferIndex = 0;
- }
+ {
+ write(m_buffer, m_bufferIndex);
+ m_bufferIndex = 0;
+ }
}
bool Printer::getRawFlag() const
return m_rawFlag;
}
-void Printer::print(istream & in, const string & docName)
- throw(PrinterException)
+void Printer::print(istream & in, const string & docName) throw(PrinterException)
{
startDoc(docName);
char ch;
char lastCh = '\0';
while (in.get(ch))
- {
- if (!m_rawFlag && ch == '\n' && lastCh != '\r')
- put('\r');
- put(ch);
- lastCh = ch;
- }
+ {
+ if (!m_rawFlag && ch == '\n' && lastCh != '\r')
+ put('\r');
+ put(ch);
+ lastCh = ch;
+ }
flush();
endDoc();
}
-void Printer::put(unsigned char ch)
- throw(PrinterException)
+void Printer::put(unsigned char ch) throw(PrinterException)
{
if (m_bufferIndex == m_bufferSize)
flush();
m_rawFlag = flag;
}
-void Printer::startDoc(const string & docName)
- throw(PrinterException)
+void Printer::startDoc(const string & docName) throw(PrinterException)
{
DOC_INFO_1 di1;
-
+
open();
-
+
di1.pDocName = tstr(docName);
di1.pOutputFile = 0;
di1.pDatatype = "RAW";
-
+
if (StartDocPrinter(m_devHandle, 1, (LPBYTE) &di1) == 0)
throw PrinterException("StartDocPrinter error: " +
Win32Utils::getErrorMessage());
}
-void Printer::startPage()
- throw(PrinterException)
+void Printer::startPage() throw(PrinterException)
{
cout << "Printer::startPage()" << endl;
if (!StartPagePrinter(m_devHandle))
Win32Utils::getErrorMessage());
}
-void Printer::write(unsigned char *buf, unsigned int size)
- throw(PrinterException)
+void Printer::write(unsigned char *buf, unsigned int size) throw(PrinterException)
{
DWORD written;
if (!WritePrinter(m_devHandle, buf, size, &written))
//
//***************************************************************************
-Printer::PrinterList Printer::enumPrinters(DWORD flags, LPTSTR name)
- throw(PrinterException)
+Printer::PrinterList Printer::enumPrinters(DWORD flags, LPTSTR name) throw(PrinterException)
{
DWORD numPrinters;
DWORD bytesNeeded;
PrinterList list;
for (unsigned int ii = 0; ii < numPrinters; ++ii)
- {
- if (m_debugFlag)
- cerr << "Printer name: '" << pi->pPrinterName << "', "
- << "Port name: '" << pi->pPortName << "'" << endl;
- list.push_back(*pi++);
- }
+ {
+ if (m_debugFlag)
+ cerr << "Printer name: '" << pi->pPrinterName << "', "
+ << "Port name: '" << pi->pPortName << "'" << endl;
+ list.push_back(*pi++);
+ }
return list;
}
-void Printer::mapPortName()
- throw(PrinterException)
+void Printer::mapPortName() throw(PrinterException)
{
OSVERSIONINFO osvi;
if (isWindows9x)
- {
- PrinterList list = enumPrinters(PRINTER_ENUM_NAME, "");
- for (PrinterList::iterator it = list.begin(); it != list.end(); ++it)
{
- if (stricmp(m_devName.c_str(), it->pPortName) == 0)
- {
- if (m_debugFlag)
- cout << "Mapped '" << m_devName << "' to '" << it->pPrinterName
- << "'" << endl;
- m_devName = it->pPrinterName;
- return;
- }
+ PrinterList list = enumPrinters(PRINTER_ENUM_NAME, "");
+ for (PrinterList::iterator it = list.begin(); it != list.end(); ++it)
+ {
+ if (stricmp(m_devName.c_str(), it->pPortName) == 0)
+ {
+ if (m_debugFlag)
+ cout << "Mapped '" << m_devName << "' to '" << it->pPrinterName
+ << "'" << endl;
+ m_devName = it->pPrinterName;
+ return;
+ }
+ }
}
- }
else if (isWindows2K_NT4)
- {
- PrinterList list = enumPrinters(PRINTER_ENUM_LOCAL, 0);
- for (PrinterList::iterator it = list.begin(); it != list.end(); ++it)
{
- if (stricmp(m_devName.c_str(), it->pPortName) == 0)
- {
- if (m_debugFlag)
- cout << "Mapped '" << m_devName << "' to '" << it->pPrinterName
- << "'" << endl;
- m_devName = it->pPrinterName;
- return;
- }
+ PrinterList list = enumPrinters(PRINTER_ENUM_LOCAL, 0);
+ for (PrinterList::iterator it = list.begin(); it != list.end(); ++it)
+ {
+ if (stricmp(m_devName.c_str(), it->pPortName) == 0)
+ {
+ if (m_debugFlag)
+ cout << "Mapped '" << m_devName << "' to '" << it->pPrinterName
+ << "'" << endl;
+ m_devName = it->pPrinterName;
+ return;
+ }
+ }
+
+ list = enumPrinters(PRINTER_ENUM_CONNECTIONS, 0);
+ for (PrinterList::iterator it = list.begin(); it != list.end(); ++it)
+ {
+ if (stricmp(m_devName.c_str(), it->pPortName) == 0)
+ {
+ if (m_debugFlag)
+ cout << "Mapped '" << m_devName << "' to '" << it->pPrinterName
+ << "'" << endl;
+ m_devName = it->pPrinterName;
+ return;
+ }
+ }
}
-
- list = enumPrinters(PRINTER_ENUM_CONNECTIONS, 0);
- for (PrinterList::iterator it = list.begin(); it != list.end(); ++it)
- {
- if (stricmp(m_devName.c_str(), it->pPortName) == 0)
- {
- if (m_debugFlag)
- cout << "Mapped '" << m_devName << "' to '" << it->pPrinterName
- << "'" << endl;
- m_devName = it->pPrinterName;
- return;
- }
- }
- }
}
-void Printer::open()
- throw(PrinterException)
+void Printer::open() throw(PrinterException)
{
PRINTER_DEFAULTS prDef;
-
+
prDef.pDatatype = "RAW";
prDef.pDevMode = m_devMode;
prDef.DesiredAccess = PRINTER_ACCESS_USE;
-
+
if (m_devHandle == INVALID_HANDLE_VALUE &&
!OpenPrinter(tstr(m_devName), &m_devHandle, &prDef))
throw PrinterException("can't open '" + m_devName + "' for writing: " +
-/*
+/*
* lpr for cygwin/windows
*
* Copyright (C) 2000-2003 Rick Rankin
#include "src/lpr/PrinterException.hh"
-using namespace std;
-
class Printer
{
public:
- Printer(const string &name, bool debugFlag)
- throw(PrinterException);
+ Printer(const std::string &name, bool debugFlag) throw(PrinterException);
~Printer();
void close();
- void endDoc()
- throw(PrinterException);
- void endPage()
- throw(PrinterException);
- void flush()
- throw(PrinterException);
+ void endDoc() throw(PrinterException);
+ void endPage() throw(PrinterException);
+ void flush() throw(PrinterException);
bool getRawFlag() const;
- void print(istream & in, const string & docName)
- throw(PrinterException);
- void put(unsigned char ch)
- throw(PrinterException);
+ void print(istream & in, const std::string & docName) throw(PrinterException);
+ void put(unsigned char ch) throw(PrinterException);
void setRawFlag(bool flag);
- void startDoc(const string & docName)
- throw(PrinterException);
- void startPage()
- throw(PrinterException);
- void write(unsigned char *buf, unsigned int size)
- throw(PrinterException);
-
+ void startDoc(const std::string & docName) throw(PrinterException);
+ void startPage() throw(PrinterException);
+ void write(unsigned char *buf, unsigned int size) throw(PrinterException);
+
private:
- typedef vector<PRINTER_INFO_5> PrinterList;
-
+ typedef std::vector<PRINTER_INFO_5> PrinterList;
+
// Don't want copy construction or assignment.
Printer(const Printer & rhs);
Printer & operator = (const Printer & rhs);
-
+
// Enumerate the existing printers.
- PrinterList enumPrinters(DWORD flags, LPTSTR name)
- throw(PrinterException);
-
+ PrinterList enumPrinters(DWORD flags, LPTSTR name) throw(PrinterException);
+
// Map a port name (lpt1, etc) to a device name.
- void mapPortName()
- throw(PrinterException);
+ void mapPortName() throw(PrinterException);
// Open the printer if it's not already open.
- void open()
- throw(PrinterException);
-
- string m_devName;
+ void open() throw(PrinterException);
+
+ std::string m_devName;
bool m_debugFlag;
HANDLE m_devHandle;
DEVMODE * m_devMode;
-/*
+/*
* lpr for cygwin/windows
*
* Copyright (C) 2000-2003 Rick Rankin
*/
#include "src/lpr/Win32Utils.hh"
+using namespace std;
string Win32Utils::getErrorMessage()
{
-/*
+/*
* lpr for cygwin/windows
*
* Copyright (C) 2000-2003 Rick Rankin
#include <string>
-using namespace std;
-
class Win32Utils
{
public:
- static string getErrorMessage();
- static string getErrorMessage(DWORD code);
+ static std::string getErrorMessage();
+ static std::string getErrorMessage(DWORD code);
};
#endif
-/*
+/*
* lpr for cygwin/windows
*
* Copyright (C) 2000-2003 Rick Rankin
}
const char * usageMessage =
-" [-h] [-D] [-d device] [-l] [-P device]\n"
-"\n"
-"where:\n"
-"\n"
-" -h does nothing. Accepted for compatibility.\n"
-" -d device spools to the specified device.\n"
-" -D enable debugging output.\n"
-" -l prevent <LF> -> <CR><LF> processing. By default, standalone"
-" <LF> characters are converted to <CR><LF>."
-" -P device spools to the specified device.\n"
-"\n"
-"Notes:\n"
-"\n"
-"-d and -P are aliases of each other and perform the same function.\n"
-"Device names may take the form of DOS devices (e.g., lpt1:) if the printer\n"
-"is connected locally. Network printers can be accessed using the form\n"
-"'\\\\server\\printer_name'. Forward slashes can be used as well, e.g.,\n"
-"'//server/printer_name'.\n"
-"\n"
-"The environment variable PRINTER can be used to set the default printer\n"
-"device.\n";
+ " [-h] [-D] [-d device] [-l] [-P device]\n"
+ "\n"
+ "where:\n"
+ "\n"
+ " -h does nothing. Accepted for compatibility.\n"
+ " -d device spools to the specified device.\n"
+ " -D enable debugging output.\n"
+ " -l prevent <LF> -> <CR><LF> processing. By default, standalone"
+ " <LF> characters are converted to <CR><LF>."
+ " -P device spools to the specified device.\n"
+ "\n"
+ "Notes:\n"
+ "\n"
+ "-d and -P are aliases of each other and perform the same function.\n"
+ "Device names may take the form of DOS devices (e.g., lpt1:) if the printer\n"
+ "is connected locally. Network printers can be accessed using the form\n"
+ "'\\\\server\\printer_name'. Forward slashes can be used as well, e.g.,\n"
+ "'//server/printer_name'.\n"
+ "\n"
+ "The environment variable PRINTER can be used to set the default printer\n"
+ "device.\n";
void usage(const string & msg = "")
{
int optionChar;
while ((optionChar = getopt(argc, argv, ":Dd:hlP:")) != EOF)
- {
- switch (optionChar)
{
- case 'h':
- // accept for compatibility
- break;
- case 'D':
- debugFlag = true;
- break;
- case 'd':
- case 'P':
- printerName = optarg;
- break;
- case 'l':
- rawFlag = true;
- break;
- default:
- usage(string("unknown option: -") + char(optionChar));
+ switch (optionChar)
+ {
+ case 'h':
+ // accept for compatibility
+ break;
+ case 'D':
+ debugFlag = true;
+ break;
+ case 'd':
+ case 'P':
+ printerName = optarg;
+ break;
+ case 'l':
+ rawFlag = true;
+ break;
+ default:
+ usage(string("unknown option: -") + char(optionChar));
+ }
}
- }
// Can't proceed without a printer name.
if (printerName == "")
- {
- cerr << progName << ": no printer specified" << endl;
- return 1;
- }
-
+ {
+ cerr << progName << ": no printer specified" << endl;
+ return 1;
+ }
+
char winPrinter[MAX_PATH];
cygwin_conv_to_win32_path(printerName.c_str(), winPrinter);
if (debugFlag)
cout << "Windows printer name = '" << winPrinter << "'" << endl;
-
+
try
- {
- Printer pr(winPrinter, debugFlag);
- pr.setRawFlag(rawFlag);
-
- if (optind >= argc)
- pr.print(cin, "stdin");
- else
{
- for (int ii = optind; ii < argc; ++ii)
- {
- ifstream in (argv[ii]);
- if (!in)
- cerr << progName << ": can't open '" << argv[ii] << "' for input."
- << endl;
- else
- pr.print(in, argv[ii]);
- }
+ Printer pr(winPrinter, debugFlag);
+ pr.setRawFlag(rawFlag);
+
+ if (optind >= argc)
+ pr.print(cin, "stdin");
+ else
+ {
+ for (int ii = optind; ii < argc; ++ii)
+ {
+ ifstream in (argv[ii]);
+ if (!in)
+ cerr << progName << ": can't open '" << argv[ii] << "' for input."
+ << endl;
+ else
+ pr.print(in, argv[ii]);
+ }
+ }
+ pr.close();
}
- pr.close();
- }
catch (const PrinterException & ex)
- {
- cerr << progName << ": printer error: " << ex << endl;
- return 1;
- }
+ {
+ cerr << progName << ": printer error: " << ex << endl;
+ return 1;
+ }
return 0;
}
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char copyrightID[] =
"Copyright (c) 2002\nJoshua Daniel Franklin. All rights reserved.\nLicensed under GPL v2.0\n";
-typedef struct optvals_s {
+typedef struct optvals_s
+{
int icon_flag;
int unix_flag;
int windows_flag;
int smprograms_flag;
int show_flag;
int offset;
- char * name_arg;
- char * desc_arg;
- char * dir_name_arg;
- char * argument_arg;
- char * target_arg;
- char * icon_name_arg;
+ char *name_arg;
+ char *desc_arg;
+ char *dir_name_arg;
+ char *argument_arg;
+ char *target_arg;
+ char *icon_name_arg;
} optvals;
-static int mkshortcut(optvals opts, poptContext optCon);
-static void printTopDescription(FILE * f, char * name);
-static void printBottomDescription(FILE * f, char * name);
-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);
-static void license(poptContext optCon, FILE * f, char * name);
+static int mkshortcut (optvals opts, poptContext optCon);
+static void printTopDescription (FILE * f, char *name);
+static void printBottomDescription (FILE * f, char *name);
+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);
+static void license (poptContext optCon, FILE * f, char *name);
static char *program_name;
main (int argc, const char **argv)
{
poptContext optCon;
- const char ** rest;
+ const char **rest;
int rc;
int ec = 0;
optvals opts;
const char *tmp_str;
int icon_offset_flag;
char icon_name[MAX_PATH];
- const char * arg;
+ const char *arg;
struct poptOption helpOptionsTable[] = {
- { "help", 'h', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", 'v', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"help", 'h', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", 'v', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption generalOptionsTable[] = {
- { "arguments", 'a', POPT_ARG_STRING, NULL, 'a', \
- "Use arguments ARGS", "ARGS"},
- { "desc", 'd', POPT_ARG_STRING, NULL, 'd', \
- "Text for description/tooltip (defaults to POSIX path of TARGET)", "DESC"},
- { "icon", 'i', POPT_ARG_STRING, NULL, 'i', \
- "Icon file for link to use", "ICONFILE"},
- { "iconoffset", 'j', POPT_ARG_INT, &(opts.offset), 'j', \
- "Offset of icon in icon file (default is 0)", NULL},
- { "name", 'n', POPT_ARG_STRING, NULL, 'n', \
- "Name for link (defaults to TARGET)", "NAME"},
- { "show", 's', POPT_ARG_STRING, NULL, 's', \
- "Window to show: normal, minimized, maximized", "norm|min|max"},
- { "workingdir", 'w', POPT_ARG_STRING, NULL, 'w', \
- "Set working directory (defaults to directory path of TARGET)", "PATH"},
- { "allusers", 'A', POPT_ARG_VAL, &(opts.allusers_flag), 1, \
- "Use 'All Users' instead of current user for -D,-P", NULL},
- { "desktop", 'D', POPT_ARG_VAL, &(opts.desktop_flag), 1, \
- "Create link relative to 'Desktop' directory", NULL},
- { "smprograms", 'P', POPT_ARG_VAL, &(opts.smprograms_flag), 1, \
- "Create link relative to Start Menu 'Programs' directory", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"arguments", 'a', POPT_ARG_STRING, NULL, 'a',
+ "Use arguments ARGS", "ARGS"},
+ {"desc", 'd', POPT_ARG_STRING, NULL, 'd',
+ "Text for description/tooltip (defaults to POSIX path of TARGET)",
+ "DESC"},
+ {"icon", 'i', POPT_ARG_STRING, NULL, 'i',
+ "Icon file for link to use", "ICONFILE"},
+ {"iconoffset", 'j', POPT_ARG_INT, &(opts.offset), 'j',
+ "Offset of icon in icon file (default is 0)", NULL},
+ {"name", 'n', POPT_ARG_STRING, NULL, 'n',
+ "Name for link (defaults to TARGET)", "NAME"},
+ {"show", 's', POPT_ARG_STRING, NULL, 's',
+ "Window to show: normal, minimized, maximized", "norm|min|max"},
+ {"workingdir", 'w', POPT_ARG_STRING, NULL, 'w',
+ "Set working directory (defaults to directory path of TARGET)", "PATH"},
+ {"allusers", 'A', POPT_ARG_VAL, &(opts.allusers_flag), 1,
+ "Use 'All Users' instead of current user for -D,-P", NULL},
+ {"desktop", 'D', POPT_ARG_VAL, &(opts.desktop_flag), 1,
+ "Create link relative to 'Desktop' directory", NULL},
+ {"smprograms", 'P', POPT_ARG_VAL, &(opts.smprograms_flag), 1,
+ "Create link relative to Start Menu 'Programs' directory", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
-
+
struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0, \
- "General options", NULL },
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, generalOptionsTable, 0,
+ "General options", NULL},
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
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(2);
- }
+ 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 (2);
+ }
icon_offset_flag = 0;
opts.icon_name_arg = NULL;
/* Parse options */
- optCon = poptGetContext(NULL, argc, argv, opt, 0);
- poptSetOtherOptionHelp(optCon, "[OPTION]* TARGET");
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- case '?': help(optCon, stderr, program_name);
- goto exit;
- case 'u': usage(optCon, stderr, program_name);
- goto exit;
- case 'v': version(optCon, stderr, program_name);
- goto exit;
- case 'l': license(optCon, stderr, program_name);
- goto exit;
- case 'd': if (arg = poptGetOptArg(optCon)) {
- if ((opts.desc_arg = strdup(arg)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- ec=2;
- goto exit;
- }
- }
- break;
- case 'i': opts.icon_flag = 1;
- if (arg = poptGetOptArg(optCon)) {
- cygwin_conv_to_full_win32_path (arg, icon_name);
- if ((opts.icon_name_arg = strdup(icon_name)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- ec=2;
- goto exit;
- }
- }
- break;
- case 'j': icon_offset_flag = 1;
- break;
- case 'n': if (arg = poptGetOptArg(optCon)) {
- if ((opts.name_arg = strdup(arg)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- ec=2;
- goto exit;
- }
- }
- break;
- case 's': if (arg = poptGetOptArg(optCon)) {
- if (strcmp(arg, "min") == 0) {
- opts.show_flag = SW_SHOWMINNOACTIVE;
- } else if (strcmp(arg, "max") == 0) {
- opts.show_flag = SW_SHOWMAXIMIZED;
- } else if (strcmp(arg, "norm") == 0) {
- opts.show_flag = SW_SHOWNORMAL;
- } else {
- fprintf(stderr, "%s: %s not valid for show window\n",
- program_name, arg);
- ec=2;
- goto exit;
- }
- }
- break;
- case 'w': if (arg = poptGetOptArg(optCon)) {
- if ((opts.dir_name_arg = strdup(arg)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- ec=2;
- goto exit;
- }
- }
- break;
- case 'a': if (arg = poptGetOptArg(optCon)) {
- if ((opts.argument_arg = strdup(arg)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- ec=2;
- goto exit;
- }
- }
- break;
- // case 'A'
- // case 'D'
- // case 'P' all handled by popt itself
- }
- }
-
- if (icon_offset_flag & !opts.icon_flag) {
- fprintf(stderr,
- "%s: --iconoffset|-j only valid in conjuction with --icon|-i\n",
- program_name);
- usage(optCon, stderr, program_name);
- ec=1;
- goto exit;
- }
-
- if (opts.smprograms_flag && opts.desktop_flag) {
- fprintf(stderr,
- "%s: --smprograms|-P not valid in conjuction with --desktop|-D\n",
- program_name);
- usage(optCon, stderr, program_name);
- ec=1;
- goto exit;
- }
-
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- ec = 1;
- goto exit;
- }
-
- rest = poptGetArgs(optCon);
-
- if (rest && *rest) {
- if ((opts.target_arg = strdup(*rest)) == NULL) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- ec=2;
+ optCon = poptGetContext (NULL, argc, argv, opt, 0);
+ poptSetOtherOptionHelp (optCon, "[OPTION]* TARGET");
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ case '?':
+ help (optCon, stderr, program_name);
+ goto exit;
+ case 'u':
+ usage (optCon, stderr, program_name);
+ goto exit;
+ case 'v':
+ version (optCon, stderr, program_name);
+ goto exit;
+ case 'l':
+ license (optCon, stderr, program_name);
+ goto exit;
+ case 'd':
+ if (arg = poptGetOptArg (optCon))
+ {
+ if ((opts.desc_arg = strdup (arg)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ }
+ break;
+ case 'i':
+ opts.icon_flag = 1;
+ if (arg = poptGetOptArg (optCon))
+ {
+ cygwin_conv_to_full_win32_path (arg, icon_name);
+ if ((opts.icon_name_arg = strdup (icon_name)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ }
+ break;
+ case 'j':
+ icon_offset_flag = 1;
+ break;
+ case 'n':
+ if (arg = poptGetOptArg (optCon))
+ {
+ if ((opts.name_arg = strdup (arg)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ }
+ break;
+ case 's':
+ if (arg = poptGetOptArg (optCon))
+ {
+ if (strcmp (arg, "min") == 0)
+ {
+ opts.show_flag = SW_SHOWMINNOACTIVE;
+ }
+ else if (strcmp (arg, "max") == 0)
+ {
+ opts.show_flag = SW_SHOWMAXIMIZED;
+ }
+ else if (strcmp (arg, "norm") == 0)
+ {
+ opts.show_flag = SW_SHOWNORMAL;
+ }
+ else
+ {
+ fprintf (stderr, "%s: %s not valid for show window\n",
+ program_name, arg);
+ ec = 2;
+ goto exit;
+ }
+ }
+ break;
+ case 'w':
+ if (arg = poptGetOptArg (optCon))
+ {
+ if ((opts.dir_name_arg = strdup (arg)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ }
+ break;
+ case 'a':
+ if (arg = poptGetOptArg (optCon))
+ {
+ if ((opts.argument_arg = strdup (arg)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n",
+ program_name);
+ ec = 2;
+ goto exit;
+ }
+ }
+ break;
+ // case 'A'
+ // case 'D'
+ // case 'P' all handled by popt itself
+ }
+ }
+
+ if (icon_offset_flag & !opts.icon_flag)
+ {
+ fprintf (stderr,
+ "%s: --iconoffset|-j only valid in conjuction with --icon|-i\n",
+ program_name);
+ usage (optCon, stderr, program_name);
+ ec = 1;
goto exit;
}
- rest++;
- if (rest && *rest) {
- fprintf(stderr, "%s: Too many arguments: ", program_name);
- while (*rest)
- fprintf(stderr, "%s ", *rest++);
- fprintf(stderr, "\n");
- usage(optCon, stderr, program_name);
- ec=1;
- } else {
- // THE MEAT GOES HERE
- ec = mkshortcut(opts, optCon);
+
+ if (opts.smprograms_flag && opts.desktop_flag)
+ {
+ fprintf (stderr,
+ "%s: --smprograms|-P not valid in conjuction with --desktop|-D\n",
+ program_name);
+ usage (optCon, stderr, program_name);
+ ec = 1;
+ goto exit;
+ }
+
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ ec = 1;
+ goto exit;
+ }
+
+ rest = poptGetArgs (optCon);
+
+ if (rest && *rest)
+ {
+ if ((opts.target_arg = strdup (*rest)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", program_name);
+ ec = 2;
+ goto exit;
+ }
+ rest++;
+ if (rest && *rest)
+ {
+ fprintf (stderr, "%s: Too many arguments: ", program_name);
+ while (*rest)
+ fprintf (stderr, "%s ", *rest++);
+ fprintf (stderr, "\n");
+ usage (optCon, stderr, program_name);
+ ec = 1;
+ }
+ else
+ {
+ // THE MEAT GOES HERE
+ ec = mkshortcut (opts, optCon);
+ }
+ }
+ else
+ {
+ fprintf (stderr, "%s: TARGET not specified\n", program_name);
+ usage (optCon, stderr, program_name);
+ ec = 1;
}
- } else {
- fprintf(stderr, "%s: TARGET not specified\n", program_name);
- usage(optCon, stderr, program_name);
- ec=1;
- }
exit:
- poptFreeContext(optCon);
- if (opts.target_arg) { free(opts.target_arg); }
- if (opts.name_arg) { free(opts.name_arg); }
- if (opts.desc_arg) { free(opts.desc_arg); }
- if (opts.dir_name_arg) { free(opts.dir_name_arg); }
- if (opts.argument_arg) { free(opts.argument_arg); }
- if (opts.icon_name_arg) { free(opts.icon_name_arg); }
- free(program_name);
- return(ec);
+ poptFreeContext (optCon);
+ if (opts.target_arg)
+ {
+ free (opts.target_arg);
+ }
+ if (opts.name_arg)
+ {
+ free (opts.name_arg);
+ }
+ if (opts.desc_arg)
+ {
+ free (opts.desc_arg);
+ }
+ if (opts.dir_name_arg)
+ {
+ free (opts.dir_name_arg);
+ }
+ if (opts.argument_arg)
+ {
+ free (opts.argument_arg);
+ }
+ if (opts.icon_name_arg)
+ {
+ free (opts.icon_name_arg);
+ }
+ free (program_name);
+ return (ec);
}
-int mkshortcut(optvals opts, poptContext optCon)
+int
+mkshortcut (optvals opts, poptContext optCon)
{
char link_name[MAX_PATH];
char exe_name[MAX_PATH];
WCHAR widepath[MAX_PATH];
buf_str = (char *) malloc (PATH_MAX);
- if (buf_str == NULL) {
- fprintf (stderr, "%s: out of memory\n", program_name);
- return(2);
- }
+ if (buf_str == NULL)
+ {
+ fprintf (stderr, "%s: out of memory\n", program_name);
+ return (2);
+ }
/* If there's a colon in the TARGET, it should be a URL */
if (strchr (opts.target_arg, ':') != NULL)
{
/* Nope, somebody's trying a W32 path */
- if (opts.target_arg[1] == ':') {
- free (buf_str);
- fprintf(stderr, "%s: all paths must be in POSIX format\n",
- program_name);
- usage (optCon, stderr, program_name);
- return(1);
- }
+ if (opts.target_arg[1] == ':')
+ {
+ free (buf_str);
+ fprintf (stderr, "%s: all paths must be in POSIX format\n",
+ program_name);
+ usage (optCon, stderr, program_name);
+ return (1);
+ }
strcpy (exe_name, opts.target_arg);
- dir_name[0] = '\0'; /* No working dir for URL */
+ dir_name[0] = '\0'; /* No working dir for URL */
}
/* Convert TARGET to win32 path */
else
if (strchr (opts.dir_name_arg, ':') != NULL)
{
free (buf_str);
- fprintf(stderr, "%s: all paths must be in POSIX format\n",
- program_name);
+ fprintf (stderr, "%s: all paths must be in POSIX format\n",
+ program_name);
usage (optCon, stderr, program_name);
- return(1);
+ return (1);
}
cygwin_conv_to_win32_path (opts.dir_name_arg, dir_name);
}
tmp_str = buf_str;
tmp = strlen (buf_str) - 1;
while (strrchr (buf_str, '/') == (buf_str + tmp))
- {
- buf_str[tmp] = '\0';
- tmp--;
- }
+ {
+ buf_str[tmp] = '\0';
+ tmp--;
+ }
/* Get basename */
while (*buf_str)
- {
- if (*buf_str == '/')
- tmp_str = buf_str + 1;
- buf_str++;
- }
+ {
+ if (*buf_str == '/')
+ tmp_str = buf_str + 1;
+ buf_str++;
+ }
strcpy (link_name, tmp_str);
- }
+ }
/* User specified a name, so check it and convert */
else
{
if (opts.desktop_flag || opts.smprograms_flag)
- {
- /* Cannot have absolute path relative to Desktop/SM Programs */
- if (opts.name_arg[0] == '/') {
- free (buf_str);
- fprintf(stderr, "%s: absolute pathnames not allowed with -D/-P\n",
- program_name);
- usage (optCon, stderr, program_name);
- return(1);
- }
- }
+ {
+ /* Cannot have absolute path relative to Desktop/SM Programs */
+ if (opts.name_arg[0] == '/')
+ {
+ free (buf_str);
+ fprintf (stderr,
+ "%s: absolute pathnames not allowed with -D/-P\n",
+ program_name);
+ usage (optCon, stderr, program_name);
+ return (1);
+ }
+ }
/* Sigh. Another W32 path */
- if (strchr (opts.name_arg, ':') != NULL) {
- free (buf_str);
- fprintf(stderr, "%s: all paths must be in POSIX format\n",
- program_name);
- usage (optCon, stderr, program_name);
- return(1);
- }
+ if (strchr (opts.name_arg, ':') != NULL)
+ {
+ free (buf_str);
+ fprintf (stderr, "%s: all paths must be in POSIX format\n",
+ program_name);
+ usage (optCon, stderr, program_name);
+ return (1);
+ }
cygwin_conv_to_win32_path (opts.name_arg, link_name);
- }
+ }
/* Add suffix to link name if necessary */
if (strlen (link_name) > 4)
{
tmp = strlen (link_name) - 4;
if (strncmp (link_name + tmp, ".lnk", 4) != 0)
- strcat (link_name, ".lnk");
+ strcat (link_name, ".lnk");
}
else
strcat (link_name, ".lnk");
{
strcpy (buf_str, link_name);
if (!opts.allusers_flag)
- SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
+ SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
else
- SHGetSpecialFolderLocation (NULL, CSIDL_COMMON_DESKTOPDIRECTORY, &id);
+ SHGetSpecialFolderLocation (NULL, CSIDL_COMMON_DESKTOPDIRECTORY, &id);
SHGetPathFromIDList (id, link_name);
/* Make sure Win95 without "All Users" has output */
if (strlen (link_name) == 0)
- {
- SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
- SHGetPathFromIDList (id, link_name);
- }
+ {
+ SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id);
+ SHGetPathFromIDList (id, link_name);
+ }
strcat (link_name, "\\");
strcat (link_name, buf_str);
}
{
strcpy (buf_str, link_name);
if (!opts.allusers_flag)
- SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
+ SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
else
- SHGetSpecialFolderLocation (NULL, CSIDL_COMMON_PROGRAMS, &id);
+ SHGetSpecialFolderLocation (NULL, CSIDL_COMMON_PROGRAMS, &id);
SHGetPathFromIDList (id, link_name);
/* Make sure Win95 without "All Users" has output */
if (strlen (link_name) == 0)
- {
- SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
- SHGetPathFromIDList (id, link_name);
- }
+ {
+ SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id);
+ SHGetPathFromIDList (id, link_name);
+ }
strcat (link_name, "\\");
strcat (link_name, buf_str);
}
/* Beginning of Windows interface */
hres = OleInitialize (NULL);
if (hres != S_FALSE && hres != S_OK)
- {
+ {
free (buf_str);
- fprintf (stderr, "%s: Could not initialize OLE interface\n",
- program_name);
+ fprintf (stderr, "%s: Could not initialize OLE interface\n",
+ program_name);
return (3);
}
hres =
CoCreateInstance (&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER,
- &IID_IShellLink, (void **) &shell_link);
+ &IID_IShellLink, (void **) &shell_link);
if (SUCCEEDED (hres))
{
hres =
- shell_link->lpVtbl->QueryInterface (shell_link, &IID_IPersistFile,
- (void **) &persist_file);
+ shell_link->lpVtbl->QueryInterface (shell_link, &IID_IPersistFile,
+ (void **) &persist_file);
if (SUCCEEDED (hres))
- {
- shell_link->lpVtbl->SetPath (shell_link, exe_name);
- shell_link->lpVtbl->SetDescription (shell_link, desc);
- shell_link->lpVtbl->SetWorkingDirectory (shell_link, dir_name);
- if (opts.argument_arg)
- shell_link->lpVtbl->SetArguments (shell_link, opts.argument_arg);
- if (opts.icon_flag)
- shell_link->lpVtbl->SetIconLocation (shell_link, opts.icon_name_arg,
- opts.offset);
+ {
+ shell_link->lpVtbl->SetPath (shell_link, exe_name);
+ shell_link->lpVtbl->SetDescription (shell_link, desc);
+ shell_link->lpVtbl->SetWorkingDirectory (shell_link, dir_name);
+ if (opts.argument_arg)
+ shell_link->lpVtbl->SetArguments (shell_link, opts.argument_arg);
+ if (opts.icon_flag)
+ shell_link->lpVtbl->SetIconLocation (shell_link,
+ opts.icon_name_arg,
+ opts.offset);
if (opts.show_flag != SW_SHOWNORMAL)
- shell_link->lpVtbl->SetShowCmd(shell_link, opts.show_flag);
-
-
- /* Make link name Unicode-compliant */
- hres =
- MultiByteToWideChar (CP_ACP, 0, link_name, -1, widepath,
- MAX_PATH);
- if (!SUCCEEDED (hres))
- {
- free (buf_str);
- fprintf (stderr, "%s: Unicode translation failed%d\n",
- program_name, hres);
- return (3);
- }
- hres = persist_file->lpVtbl->Save (persist_file, widepath, TRUE);
- if (!SUCCEEDED (hres))
- {
- free (buf_str);
- fprintf (stderr,
- "%s: Saving \"%s\" failed; does the target directory exist?\n",
- program_name, link_name);
- return (3);
- }
- persist_file->lpVtbl->Release (persist_file);
- shell_link->lpVtbl->Release (shell_link);
- }
+ shell_link->lpVtbl->SetShowCmd (shell_link, opts.show_flag);
+
+
+ /* Make link name Unicode-compliant */
+ hres =
+ MultiByteToWideChar (CP_ACP, 0, link_name, -1, widepath,
+ MAX_PATH);
+ if (!SUCCEEDED (hres))
+ {
+ free (buf_str);
+ fprintf (stderr, "%s: Unicode translation failed%d\n",
+ program_name, hres);
+ return (3);
+ }
+ hres = persist_file->lpVtbl->Save (persist_file, widepath, TRUE);
+ if (!SUCCEEDED (hres))
+ {
+ free (buf_str);
+ fprintf (stderr,
+ "%s: Saving \"%s\" failed; does the target directory exist?\n",
+ program_name, link_name);
+ return (3);
+ }
+ persist_file->lpVtbl->Release (persist_file);
+ shell_link->lpVtbl->Release (shell_link);
+ }
else
- {
- free (buf_str);
- fprintf (stderr, "%s: QueryInterface failed\n", program_name);
- return (3);
- }
+ {
+ free (buf_str);
+ fprintf (stderr, "%s: QueryInterface failed\n", program_name);
+ return (3);
+ }
}
else
{
}
}
-static const char * getVersion()
+static const char *
+getVersion ()
{
return versionID;
}
-static void printTopDescription(FILE * f, char * name)
+static void
+printTopDescription (FILE * f, char *name)
{
char s[20];
- fprintf(f, "%s is part of cygutils version %s\n", name, getVersion());
- fprintf(f, " create a Windows shortcut\n\n");
+ 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)
+static void
+printBottomDescription (FILE * f, char *name)
{
- fprintf(f, "\nNOTE: All filename arguments must be in unix (POSIX) format\n");
+ fprintf (f,
+ "\nNOTE: All filename arguments must be in unix (POSIX) format\n");
}
-static printLicense(FILE * f, char * name)
+
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE * f, char * name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
- printBottomDescription(f, name);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
+ printBottomDescription (f, name);
}
-static void version(poptContext optCon, FILE * f, char * name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- fprintf(f, copyrightID);
+ printTopDescription (f, name);
+ fprintf (f, copyrightID);
}
-static void license(poptContext optCon, FILE * f, char * name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
-}
-
+ printTopDescription (f, name);
+ printLicense (f, name);
+}
/* 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
- */
+ * 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:
*
#if HAVE_CONFIG_H
-#include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char versionID[] = PACKAGE_VERSION;
-typedef struct optvals_s {
- char * target_fname;
+typedef struct optvals_s
+{
+ char *target_fname;
int show_field_names;
int pathType;
} 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);
+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);
+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);
+void formatPath (char *strPath, int format);
+int readshortcut (optvals * opts, poptContext optContext);
static char *program_name;
-int main (int argc, const char **argv) {
+int
+main (int argc, const char **argv)
+{
poptContext optContext;
- const char ** loose_args;
+ 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 }
+ {"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 }
+ {"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 }
+ {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);
- }
+ 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_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;
+ 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; }
+ 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 = 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);
+ }
}
- 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);
+ else
+ {
+ fprintf (stderr, "%s: SHORTCUT not specified\n", program_name);
+ 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);
+ poptFreeContext (optContext);
+ free (program_name);
+ free (opts.target_fname);
return result;
}
-int readshortcut(optvals *opts, poptContext optContext) {
+int
+readshortcut (optvals * opts, poptContext optContext)
+{
HRESULT hres;
IShellLink *shell_link;
IPersistFile *persist_file;
- char strPath[MAX_PATH];
+ char strPath[MAX_PATH];
char strBuff[BUFF_SIZE];
int iBuff;
- int result = ERR_NONE; /* the value to return on exit */
-
+ 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");
+ 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);
+ 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");
}
- 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);
+ 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;
}
- 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);
- }
+ 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);
- }
+ 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;
+ 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);
+ }
}
- }
- 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);
+ else
+ {
+ fprintf (stderr, "%s: Load failed on %s\n", program_name,
+ opts->target_fname);
+ result = ERR_WIN;
}
- }
- 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);
- }
+
+ /* Release the pointer to the IPersistFile interface. */
+ persist_file->lpVtbl->Release (persist_file);
}
- else {
- fprintf (stderr, "%s: Load failed on %s\n", program_name, opts->target_fname);
+ else
+ {
+ fprintf (stderr, "%s: QueryInterface failed\n", program_name);
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);
+ shell_link->lpVtbl->Release (shell_link);
- return(result);
+ 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);
- }
+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() {
+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
+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
+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
+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
+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
+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
+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);
-}
+static void
+license (poptContext optCon, FILE * f, char *name)
+{
+ printTopDescription (f, name);
+ printLicense (f, name);
+}
*/
#if HAVE_CONFIG_H
-# include "config.h"
+# include "config.h"
#endif
#include "common.h"
static const char versionID[] = PACKAGE_VERSION;
static const char revID[] =
- "$Id$";
+ "$Id$";
static const char copyrightID[] =
- "Copyright (c) 2001,...\nSteven Barker. All rights reserved.\nLicensed under GPL v2.0\n";
+ "Copyright (c) 2001,...\nSteven Barker. All rights reserved.\nLicensed under GPL v2.0\n";
/* The name this program was run with. */
-static char * program_name;
-
-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);
-
-int main(int argc, const char ** argv)
+static char *program_name;
+
+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);
+
+int
+main (int argc, const char **argv)
{
poptContext optCon;
- const char ** rest;
+ const char **rest;
int rc;
int ec = 0;
char *input;
char *result;
struct poptOption helpOptionsTable[] = {
- { "help", '?', POPT_ARG_NONE, NULL, '?', \
- "Show this help message", NULL},
- { "usage", '\0', POPT_ARG_NONE, NULL, 'u', \
- "Display brief usage message", NULL},
- { "version", '\0', POPT_ARG_NONE, NULL, 'v', \
- "Display version information", NULL},
- { "license", '\0', POPT_ARG_NONE, NULL, 'l', \
- "Display licensing information", NULL},
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {"help", '?', POPT_ARG_NONE, NULL, '?',
+ "Show this help message", NULL},
+ {"usage", '\0', POPT_ARG_NONE, NULL, 'u',
+ "Display brief usage message", NULL},
+ {"version", '\0', POPT_ARG_NONE, NULL, 'v',
+ "Display version information", NULL},
+ {"license", '\0', POPT_ARG_NONE, NULL, 'l',
+ "Display licensing information", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
struct poptOption opt[] = {
- { NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0, \
- "Help options", NULL },
- { NULL, '\0', 0, NULL, 0, NULL, NULL }
+ {NULL, '\0', POPT_ARG_INCLUDE_TABLE, helpOptionsTable, 0,
+ "Help options", NULL},
+ {NULL, '\0', 0, NULL, 0, NULL, NULL}
};
- if( (program_name = strdup(argv[0])) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", argv[0]);
- exit(1);
- }
- if( (result = malloc(PATH_MAX)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- free(program_name);
- exit(1);
- }
-
- optCon = poptGetContext(NULL, argc, argv, opt, 0);
- poptSetOtherOptionHelp(optCon, "[OPTIONS...] PATH");
-
- while ((rc = poptGetNextOpt(optCon)) > 0) {
- switch (rc) {
- case '?': help(optCon, stderr, program_name);
- goto exit;
- case 'u': usage(optCon, stderr, program_name);
- goto exit;
- case 'v': version(optCon, stderr, program_name);
- goto exit;
- case 'l': license(optCon, stderr, program_name);
- goto exit;
+ if ((program_name = strdup (argv[0])) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", argv[0]);
+ exit (1);
}
- }
- if (rc < -1 ) {
- fprintf(stderr, "%s: bad argument %s: %s\n",
- program_name, poptBadOption(optCon, POPT_BADOPTION_NOALIAS),
- poptStrerror(rc));
- ec = 2;
- goto exit;
- }
- rest = poptGetArgs(optCon);
-
- if (rest == NULL) {
- fprintf(stderr, "%s: not enough arguments\n",program_name);
- usage(optCon, stderr, program_name);
- }
- else {
- if( (input = strdup(*rest++)) == NULL ) {
- fprintf(stderr, "%s: memory allocation error\n", program_name);
- ec = 1;
+ if ((result = malloc (PATH_MAX)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", program_name);
+ free (program_name);
+ exit (1);
+ }
+
+ optCon = poptGetContext (NULL, argc, argv, opt, 0);
+ poptSetOtherOptionHelp (optCon, "[OPTIONS...] PATH");
+
+ while ((rc = poptGetNextOpt (optCon)) > 0)
+ {
+ switch (rc)
+ {
+ case '?':
+ help (optCon, stderr, program_name);
+ goto exit;
+ case 'u':
+ usage (optCon, stderr, program_name);
+ goto exit;
+ case 'v':
+ version (optCon, stderr, program_name);
+ goto exit;
+ case 'l':
+ license (optCon, stderr, program_name);
+ goto exit;
+ }
+ }
+ if (rc < -1)
+ {
+ fprintf (stderr, "%s: bad argument %s: %s\n",
+ program_name, poptBadOption (optCon, POPT_BADOPTION_NOALIAS),
+ poptStrerror (rc));
+ ec = 2;
goto exit;
}
- if (*rest != NULL) { /* should only have ONE member of **rest */
- fprintf(stderr, "%s: too many arguments\n", program_name);
- usage(optCon, stderr, program_name);
- free(input);
+ rest = poptGetArgs (optCon);
+
+ if (rest == NULL)
+ {
+ fprintf (stderr, "%s: not enough arguments\n", program_name);
+ usage (optCon, stderr, program_name);
}
- else {
- if(! realpath (input, result)) {
- ec = errno;
- perror(program_name);
- free(input);
- goto exit;
- }
- printf ("%s\n", result);
- free(input);
+ else
+ {
+ if ((input = strdup (*rest++)) == NULL)
+ {
+ fprintf (stderr, "%s: memory allocation error\n", program_name);
+ ec = 1;
+ goto exit;
+ }
+ if (*rest != NULL)
+ { /* should only have ONE member of **rest */
+ fprintf (stderr, "%s: too many arguments\n", program_name);
+ usage (optCon, stderr, program_name);
+ free (input);
+ }
+ else
+ {
+ if (!realpath (input, result))
+ {
+ ec = errno;
+ perror (program_name);
+ free (input);
+ goto exit;
+ }
+ printf ("%s\n", result);
+ free (input);
+ }
}
- }
exit:
- poptFreeContext(optCon);
- free(program_name);
- free(result);
- return(ec);
+ poptFreeContext (optCon);
+ free (program_name);
+ free (result);
+ return (ec);
}
-static const char * getVersion()
+static const char *
+getVersion ()
{
return versionID;
}
-static void printTopDescription(FILE * f, char * name)
+static void
+printTopDescription (FILE * f, char *name)
{
- 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");
+ 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)
+static void
+printBottomDescription (FILE * f, char *name)
{
/* fprintf(f, "\n");
* fprintf(f, "Report bugs to <bug-sh-utils@gnu.org>.\n");
*/
}
-static printLicense(FILE * f, char * name)
+static
+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");
+ 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)
+static void
+usage (poptContext optCon, FILE * f, char *name)
{
- poptPrintUsage(optCon, f, 0);
+ poptPrintUsage (optCon, f, 0);
}
-static void help(poptContext optCon, FILE * f, char * name)
+static void
+help (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- poptPrintHelp(optCon, f, 0);
- printBottomDescription(f, name);
+ printTopDescription (f, name);
+ poptPrintHelp (optCon, f, 0);
+ printBottomDescription (f, name);
}
-static void version(poptContext optCon, FILE * f, char * name)
+static void
+version (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
+ printTopDescription (f, name);
}
-static void license(poptContext optCon, FILE * f, char * name)
+static void
+license (poptContext optCon, FILE * f, char *name)
{
- printTopDescription(f, name);
- printLicense(f, name);
+ printTopDescription (f, name);
+ printLicense (f, name);
}
-