OSDN Git Service

Merging MinGW changes
authorearnie <earnie>
Tue, 28 May 2002 13:13:26 +0000 (13:13 +0000)
committerearnie <earnie>
Tue, 28 May 2002 13:13:26 +0000 (13:13 +0000)
28 files changed:
winsup/mingw/samples/filehand/jamfile
winsup/mingw/samples/filehand/junk.txt
winsup/mingw/samples/fixargv/fixargv.c
winsup/mingw/samples/fixargv/fixargv.h
winsup/mingw/samples/fixargv/readme.txt
winsup/mingw/samples/fmode/all.c
winsup/mingw/samples/fmode/jamfile
winsup/mingw/samples/fmode/readme.txt
winsup/mingw/samples/fmode/test.c
winsup/mingw/samples/print/jamfile
winsup/mingw/samples/print/prntest.c
winsup/mingw/samples/seh/eh3.c
winsup/mingw/samples/seh/exutil.c
winsup/mingw/samples/seh/exutil.def
winsup/mingw/samples/seh/exutil.h
winsup/mingw/samples/seh/jamfile
winsup/mingw/samples/seh/sehfix.c
winsup/mingw/samples/seh/sehsub.c
winsup/mingw/samples/seh/sehtest.c
winsup/mingw/samples/simpledll/dll.c
winsup/mingw/samples/simpledll/dll.cpp
winsup/mingw/samples/simpledll/dll.def
winsup/mingw/samples/simpledll/exe.c
winsup/mingw/samples/simpledll/jamfile
winsup/mingw/samples/test/jamfile
winsup/mingw/samples/test/test.c
winsup/mingw/samples/wintest/jamfile
winsup/mingw/samples/wintest/test.c

index 6f29c37..3b2c726 100644 (file)
@@ -1,3 +1,3 @@
-\r
-Main filehand.exe : filehand.c ;\r
-\r
+
+Main filehand.exe : filehand.c ;
+
index 50c24cd..c2e2a41 100644 (file)
-/*\r
- * fixargv.c\r
- *\r
- * A special function which "fixes" an argv array by replacing arguments\r
- * that need quoting with quoted versions.\r
- *\r
- * NOTE: In order to be reasonably consistent there is some misuse of the\r
- *       const keyword here-- which leads to compilation warnings. These\r
- *       should be ok to ignore.\r
- *\r
- * This is a sample distributed as part of the Mingw32 package.\r
- *\r
- * Contributors:\r
- *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>\r
- *\r
- *  THIS SOFTWARE IS NOT COPYRIGHTED\r
- *\r
- *  This source code is offered for use in the public domain. You may\r
- *  use, modify or distribute it freely.\r
- *\r
- *  This code is distributed in the hope that it will be useful but\r
- *  WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY\r
- *  DISCLAMED. This includes but is not limited to warrenties of\r
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
- *\r
- * $Revision$\r
- * $Author$\r
- * $Date$\r
- *\r
- */\r
-\r
-#include <string.h>\r
-#include "fixargv.h"\r
-\r
-/*\r
- * This takes a single string and fixes it, enclosing it in quotes if it\r
- * contains any spaces and/or escaping the quotes it contains.\r
- */\r
-char*\r
-fix_arg (const char* szArg)\r
-{\r
-       int     nQuoteAll;      /* Does the whole arg need quoting? */\r
-       int     nBkSlRun;       /* How may backslashes in a row? */\r
-       char*   sz;\r
-       char*   szNew;\r
-       size_t  sizeLen;\r
-\r
-       nQuoteAll = 0;\r
-       nBkSlRun = 0;\r
-       sz = szArg;\r
-       sizeLen = 1;\r
-\r
-       /* First we figure out how much bigger the new string has to be\r
-        * than the old one. */\r
-       while (*sz != '\0')\r
-       {\r
-               /*\r
-                * Arguments containing whitespace of wildcards will be\r
-                * quoted to preserve tokenization and/or those special\r
-                * characters (i.e. wildcarding will NOT be done at the\r
-                * other end-- they will get the * and ? characters as is).\r
-                * TODO: Is this the best way? Do we want to enable wildcards?\r
-                *       If so, when?\r
-                */\r
-               if (!nQuoteAll &&\r
-                   (*sz == ' ' || *sz == '\t' || *sz == '*' || *sz == '?'))\r
-               {\r
-                       nQuoteAll = 1;\r
-               }\r
-               else if (*sz == '\\')\r
-               {\r
-                       nBkSlRun++;\r
-               }\r
-               else\r
-               {\r
-                       if (*sz == '\"')\r
-                       {\r
-                               sizeLen += nBkSlRun + 1;\r
-                       }\r
-                       nBkSlRun = 0;\r
-               }\r
-\r
-               sizeLen++;\r
-               sz++;\r
-       }\r
-\r
-       if (nQuoteAll)\r
-       {\r
-               sizeLen += 2;\r
-       }\r
-\r
-       /*\r
-        * Make a new string big enough.\r
-        */\r
-       szNew = (char*) malloc (sizeLen);\r
-       if (!szNew)\r
-       {\r
-               return NULL;\r
-       }\r
-       sz = szNew;\r
-\r
-       /* First enclosing quote for fully quoted args. */\r
-       if (nQuoteAll)\r
-       {\r
-               *sz = '\"';\r
-               sz++;\r
-       }\r
-\r
-       /*\r
-        * Go through the string putting backslashes in front of quotes,\r
-        * and doubling all backslashes immediately in front of quotes.\r
-        */\r
-       nBkSlRun = 0;\r
-       while (*szArg != '\0')\r
-       {\r
-               if (*szArg == '\\')\r
-               {\r
-                       nBkSlRun++;\r
-               }\r
-               else\r
-               {\r
-                       if (*szArg == '\"')\r
-                       {\r
-                               while (nBkSlRun > 0)\r
-                               {\r
-                                       *sz = '\\';\r
-                                       sz++;\r
-                                       nBkSlRun--;\r
-                               }\r
-                               *sz = '\\';\r
-                               sz++;\r
-                       }\r
-                       nBkSlRun = 0;\r
-               }\r
-\r
-               *sz = *szArg;\r
-               sz++;\r
-               szArg++;\r
-       }\r
-\r
-       /* Closing quote for fully quoted args. */\r
-       if (nQuoteAll)\r
-       {\r
-               *sz = '\"';\r
-               sz++;\r
-       }\r
-\r
-       *sz = '\0';\r
-       return szNew;\r
-}\r
-\r
-/*\r
- * Takes argc and argv and returns a new argv with escaped members. Pass\r
- * this fixed argv (along with the old one) to free_fixed_argv after\r
- * you finish with it. Pass in an argc of -1 and make sure the argv vector\r
- * ends with a null pointer to have fix_argv count the arguments for you.\r
- */\r
-char* const*\r
-fix_argv (int argc, char* const* szaArgv)\r
-{\r
-       char**  szaNew;\r
-       char*   sz;\r
-       int     i;\r
-\r
-       if (!szaArgv)\r
-       {\r
-               return NULL;\r
-       }\r
-\r
-       /*\r
-        * Count the arguments if asked.\r
-        */\r
-       if (argc == -1)\r
-       {\r
-               for (i = 0; szaArgv[i]; i++)\r
-                       ;\r
-\r
-               argc = i;\r
-       }\r
-\r
-       /*\r
-        * If there are no args or only one arg then do no escaping.\r
-        */\r
-       if (argc < 2)\r
-       {\r
-               return szaArgv;\r
-       }\r
-\r
-       for (i = 1, szaNew = NULL; i < argc; i++)\r
-       {\r
-               sz = szaArgv[i];\r
-\r
-               /*\r
-                * If an argument needs fixing, then fix it.\r
-                */\r
-               if (strpbrk (sz, "\" \t*?"))\r
-               {\r
-                       /*\r
-                        * If we haven't created a new argv list already\r
-                        * then make one.\r
-                        */\r
-                       if (!szaNew)\r
-                       {\r
-                               szaNew = (char**) malloc ((argc + 1) *\r
-                                       sizeof (char*));\r
-                               if (!szaNew)\r
-                               {\r
-                                       return NULL;\r
-                               }\r
-\r
-                               /*\r
-                                * Copy previous args from old to new.\r
-                                */\r
-                               memcpy (szaNew, szaArgv, sizeof(char*) * i);\r
-                       }\r
-\r
-                       /*\r
-                        * Now do the fixing.\r
-                        */\r
-                       szaNew[i] = fix_arg (sz);\r
-                       if (!szaNew[i])\r
-                       {\r
-                               /* Fixing failed, free up and return error. */\r
-                               free_fixed_argv (szaNew, szaArgv);\r
-                               return NULL;\r
-                       }\r
-               }\r
-               else if (szaNew)\r
-               {\r
-                       szaNew[i] = sz;\r
-               }\r
-       }\r
-\r
-       if (szaNew)\r
-       {\r
-               /* If we have created a new argv list then we might as well\r
-                * terminate it nicely. (And we depend on it in\r
-                * free_fixed_argv.) */\r
-               szaNew[argc] = NULL;\r
-       }\r
-       else\r
-       {\r
-               /* If we didn't create a new argv list then return the\r
-                * original. */\r
-               return szaArgv;\r
-       }\r
-\r
-       return szaNew;\r
-}\r
-\r
-void\r
-free_fixed_argv (char* const* szaFixed, char* const* szaOld)\r
-{\r
-       char* const*    sza;\r
-\r
-       /*\r
-        * Check for error conditions. Also note that if no corrections\r
-        * were required the fixed argv will actually be the same as\r
-        * the old one, and we don't need to do anything.\r
-        */\r
-       if (!szaFixed || !szaOld || szaFixed == szaOld)\r
-       {\r
-               return;\r
-       }\r
-\r
-       /*\r
-        * Go through all members of the argv list. If any of the\r
-        * members in the fixed list are different from the old\r
-        * list we free those members.\r
-        * NOTE: The first member is never modified, so we don't need to\r
-        * check.\r
-        */\r
-       sza = szaFixed + 1;\r
-       szaOld++;\r
-       while (*sza)\r
-       {\r
-               if (*sza != *szaOld)\r
-               {\r
-                       free (*sza);\r
-               }\r
-               sza++;\r
-               szaOld++;\r
-       }\r
-\r
-       /*\r
-        * Now we can free the array of char pointers itself.\r
-        */\r
-       free (szaFixed);\r
-}\r
-\r
+/*
+ * fixargv.c
+ *
+ * A special function which "fixes" an argv array by replacing arguments
+ * that need quoting with quoted versions.
+ *
+ * NOTE: In order to be reasonably consistent there is some misuse of the
+ *       const keyword here-- which leads to compilation warnings. These
+ *       should be ok to ignore.
+ *
+ * This is a sample distributed as part of the Mingw32 package.
+ *
+ * Contributors:
+ *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
+ *
+ *  THIS SOFTWARE IS NOT COPYRIGHTED
+ *
+ *  This source code is offered for use in the public domain. You may
+ *  use, modify or distribute it freely.
+ *
+ *  This code is distributed in the hope that it will be useful but
+ *  WITHOUT ANY WARRANTY. ALL WARRENTIES, EXPRESS OR IMPLIED ARE HEREBY
+ *  DISCLAMED. This includes but is not limited to warrenties of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ * $Revision$
+ * $Author$
+ * $Date$
+ *
+ */
+
+#include <string.h>
+#include "fixargv.h"
+
+/*
+ * This takes a single string and fixes it, enclosing it in quotes if it
+ * contains any spaces and/or escaping the quotes it contains.
+ */
+char*
+fix_arg (const char* szArg)
+{
+       int     nQuoteAll;      /* Does the whole arg need quoting? */
+       int     nBkSlRun;       /* How may backslashes in a row? */
+       char*   sz;
+       char*   szNew;
+       size_t  sizeLen;
+
+       nQuoteAll = 0;
+       nBkSlRun = 0;
+       sz = szArg;
+       sizeLen = 1;
+
+       /* First we figure out how much bigger the new string has to be
+        * than the old one. */
+       while (*sz != '\0')
+       {
+               /*
+                * Arguments containing whitespace of wildcards will be
+                * quoted to preserve tokenization and/or those special
+                * characters (i.e. wildcarding will NOT be done at the
+                * other end-- they will get the * and ? characters as is).
+                * TODO: Is this the best way? Do we want to enable wildcards?
+                *       If so, when?
+                */
+               if (!nQuoteAll &&
+                   (*sz == ' ' || *sz == '\t' || *sz == '*' || *sz == '?'))
+               {
+                       nQuoteAll = 1;
+               }
+               else if (*sz == '\\')
+               {
+                       nBkSlRun++;
+               }
+               else
+               {
+                       if (*sz == '\"')
+                       {
+                               sizeLen += nBkSlRun + 1;
+                       }
+                       nBkSlRun = 0;
+               }
+
+               sizeLen++;
+               sz++;
+       }
+
+       if (nQuoteAll)
+       {
+               sizeLen += 2;
+       }
+
+       /*
+        * Make a new string big enough.
+        */
+       szNew = (char*) malloc (sizeLen);
+       if (!szNew)
+       {
+               return NULL;
+       }
+       sz = szNew;
+
+       /* First enclosing quote for fully quoted args. */
+       if (nQuoteAll)
+       {
+               *sz = '\"';
+               sz++;
+       }
+
+       /*
+        * Go through the string putting backslashes in front of quotes,
+        * and doubling all backslashes immediately in front of quotes.
+        */
+       nBkSlRun = 0;
+       while (*szArg != '\0')
+       {
+               if (*szArg == '\\')
+               {
+                       nBkSlRun++;
+               }
+               else
+               {
+                       if (*szArg == '\"')
+                       {
+                               while (nBkSlRun > 0)
+                               {
+                                       *sz = '\\';
+                                       sz++;
+                                       nBkSlRun--;
+                               }
+                               *sz = '\\';
+                               sz++;
+                       }
+                       nBkSlRun = 0;
+               }
+
+               *sz = *szArg;
+               sz++;
+               szArg++;
+       }
+
+       /* Closing quote for fully quoted args. */
+       if (nQuoteAll)
+       {
+               *sz = '\"';
+               sz++;
+       }
+
+       *sz = '\0';
+       return szNew;
+}
+
+/*
+ * Takes argc and argv and returns a new argv with escaped members. Pass
+ * this fixed argv (along with the old one) to free_fixed_argv after
+ * you finish with it. Pass in an argc of -1 and make sure the argv vector
+ * ends with a null pointer to have fix_argv count the arguments for you.
+ */
+char* const*
+fix_argv (int argc, char* const* szaArgv)
+{
+       char**  szaNew;
+       char*   sz;
+       int     i;
+
+       if (!szaArgv)
+       {
+               return NULL;
+       }
+
+       /*
+        * Count the arguments if asked.
+        */
+       if (argc == -1)
+       {
+               for (i = 0; szaArgv[i]; i++)
+                       ;
+
+               argc = i;
+       }
+
+       /*
+        * If there are no args or only one arg then do no escaping.
+        */
+       if (argc < 2)
+       {
+               return szaArgv;
+       }
+
+       for (i = 1, szaNew = NULL; i < argc; i++)
+       {
+               sz = szaArgv[i];
+
+               /*
+                * If an argument needs fixing, then fix it.
+                */
+               if (strpbrk (sz, "\" \t*?"))
+               {
+                       /*
+                        * If we haven't created a new argv list already
+                        * then make one.
+                        */
+                       if (!szaNew)
+                       {
+                               szaNew = (char**) malloc ((argc + 1) *
+                                       sizeof (char*));
+                               if (!szaNew)
+                               {
+                                       return NULL;
+                               }
+
+                               /*
+                                * Copy previous args from old to new.
+                                */
+                               memcpy (szaNew, szaArgv, sizeof(char*) * i);
+                       }
+
+                       /*
+                        * Now do the fixing.
+                        */
+                       szaNew[i] = fix_arg (sz);
+                       if (!szaNew[i])
+                       {
+                               /* Fixing failed, free up and return error. */
+                               free_fixed_argv (szaNew, szaArgv);
+                               return NULL;
+                       }
+               }
+               else if (szaNew)
+               {
+                       szaNew[i] = sz;
+               }
+       }
+
+       if (szaNew)
+       {
+               /* If we have created a new argv list then we might as well
+                * terminate it nicely. (And we depend on it in
+                * free_fixed_argv.) */
+               szaNew[argc] = NULL;
+       }
+       else
+       {
+               /* If we didn't create a new argv list then return the
+                * original. */
+               return szaArgv;
+       }
+
+       return szaNew;
+}
+
+void
+free_fixed_argv (char* const* szaFixed, char* const* szaOld)
+{
+       char* const*    sza;
+
+       /*
+        * Check for error conditions. Also note that if no corrections
+        * were required the fixed argv will actually be the same as
+        * the old one, and we don't need to do anything.
+        */
+       if (!szaFixed || !szaOld || szaFixed == szaOld)
+       {
+               return;
+       }
+
+       /*
+        * Go through all members of the argv list. If any of the
+        * members in the fixed list are different from the old
+        * list we free those members.
+        * NOTE: The first member is never modified, so we don't need to
+        * check.
+        */
+       sza = szaFixed + 1;
+       szaOld++;
+       while (*sza)
+       {
+               if (*sza != *szaOld)
+               {
+                       free (*sza);
+               }
+               sza++;
+               szaOld++;
+       }
+
+       /*
+        * Now we can free the array of char pointers itself.
+        */
+       free (szaFixed);
+}
+
index 0e62226..e4a83fa 100644 (file)
@@ -1,24 +1,24 @@
-/*\r
- * fixargv.h\r
- *\r
- * Prototypes of utility functions for 'properly' escaping argv vectors.\r
- *\r
- *  THIS SOFTWARE IS NOT COPYRIGHTED\r
- *\r
- *  This source code is offered for use in the public domain. You may\r
- *  use, modify or distribute it freely.\r
- *\r
- * $Revision$\r
- * $Author$\r
- * $Date$\r
- *\r
- */\r
-\r
-#ifndef _FIXARGV_H_\r
-#define _FIXARGV_H_\r
-\r
-char* fix_arg (const char* szArg);\r
-char* const* fix_argv (int argc, char* const* szaArgv);\r
-void free_fixed_argv (char* const* szaFixed, char* const* szaOld);\r
-\r
-#endif\r
+/*
+ * fixargv.h
+ *
+ * Prototypes of utility functions for 'properly' escaping argv vectors.
+ *
+ *  THIS SOFTWARE IS NOT COPYRIGHTED
+ *
+ *  This source code is offered for use in the public domain. You may
+ *  use, modify or distribute it freely.
+ *
+ * $Revision$
+ * $Author$
+ * $Date$
+ *
+ */
+
+#ifndef _FIXARGV_H_
+#define _FIXARGV_H_
+
+char* fix_arg (const char* szArg);
+char* const* fix_argv (int argc, char* const* szaArgv);
+void free_fixed_argv (char* const* szaFixed, char* const* szaOld);
+
+#endif
index 14048f5..555ef9b 100644 (file)
@@ -1,85 +1,85 @@
-\r
-This code is a utility function I was considering adding to Mingw32. The\r
-Microsoft versions of argc, argv construction use quotes and backslashes\r
-to allow the user to pass arguments containing spaces (or quotes) to \r
-programs they invoke. The rules are\r
-\r
- - Arguments containing spaces must be enclosed in quotes.\r
- - A quote can be passed by preceeding it with a backslash.\r
- - Backslashes immediately preceeding a quote must be doubled to avoid\r
-   escaping the quote.\r
-\r
-Thus an argument like:\r
-\r
- -D="Foo Bar\\"\r
-\r
-needs to be mangled as:\r
-\r
- "-D\"Foo Bar\\\\\""\r
-\r
-in order to get to the program as what was intended above.\r
-\r
-The fix_argv set of functions is meant to be used with spawnv and the\r
-like to allow a program to set up an argv array for the spawned program\r
-and have that array duplicated *exactly* in the spawned program, no\r
-matter what it contains (it also quotes 'globbing' characters like *\r
-and ?, so it does not matter if the destination has globbing turned on\r
-or not; it might be a reasonable extension to allow a flag to allow\r
-globbing characters to pass through unmolested, but they would still\r
-be quoted if the string contained whitespace).\r
-\r
-The reason for writing this came up because of problems with arguments\r
-like -DBLAH="Foo Bar" to GCC (define BLAH as a preprocessor constant\r
-being the string "Foo Bar", including the quotes). Because GCC simply\r
-passes the argument directly to CPP (the preprocessor) it had to be\r
-escaped *twice*:\r
-\r
- "-DBLAH=\"\\\"Foo Bar\\\"\""\r
-\r
-This would reach GCC as\r
-\r
- -DBLAH="\"Foo Bar\""\r
-\r
-And that would reach CPP as the desired\r
-\r
- -DBLAH="Foo Bar"\r
-\r
-One level of quoting and escaping is to be expected (although MS's\r
-standard is, arguably, not very good), but forcing the user to know\r
-how many different programs the argument is going to pass through,\r
-and perform double quoting and escaping, seems unreasonable. If\r
-GCC and friends all used fix_argv (they use their own version of\r
-it now) then the original argument could be\r
-\r
- "-DBLAH=\"Foo Bar\""\r
-\r
-And that would work fine, no matter how many different tools it\r
-passed through.\r
-\r
-The only basic limitation with this code is that it assumes that all\r
-the spawned programs use Microsoft-type escaping when interpreting\r
-their command line. Most programs on Win32 machines do (anything\r
-compiled with Mingw32 will).\r
-\r
-For now, this code has been relegated to 'sample' status. If you want\r
-to use it, feel free (it is public domain after all).\r
-\r
-Colin.\r
-\r
-P.S. Just out of interest you might try writing your own little program\r
-     to look at the interaction of wildcards and quotes. Use the glob.exe\r
-     program in ../globbing and see what it does with\r
-\r
-      glob "foo*.txt"\r
-\r
-     even if there are files foo.txt and foobar.txt in the same directory.\r
-\r
-     Note that\r
-\r
-      del "My *.txt"\r
-\r
-     works (i.e. it deletes all files starting with My<space>). This could\r
-     not be done unless del does globbing *after* processing escapes and\r
-     quotes, which is not the way it seems to work normally (again see\r
-     the glob example).\r
-\r
+
+This code is a utility function I was considering adding to Mingw32. The
+Microsoft versions of argc, argv construction use quotes and backslashes
+to allow the user to pass arguments containing spaces (or quotes) to 
+programs they invoke. The rules are
+
+ - Arguments containing spaces must be enclosed in quotes.
+ - A quote can be passed by preceeding it with a backslash.
+ - Backslashes immediately preceeding a quote must be doubled to avoid
+   escaping the quote.
+
+Thus an argument like:
+
+ -D="Foo Bar\\"
+
+needs to be mangled as:
+
+ "-D\"Foo Bar\\\\\""
+
+in order to get to the program as what was intended above.
+
+The fix_argv set of functions is meant to be used with spawnv and the
+like to allow a program to set up an argv array for the spawned program
+and have that array duplicated *exactly* in the spawned program, no
+matter what it contains (it also quotes 'globbing' characters like *
+and ?, so it does not matter if the destination has globbing turned on
+or not; it might be a reasonable extension to allow a flag to allow
+globbing characters to pass through unmolested, but they would still
+be quoted if the string contained whitespace).
+
+The reason for writing this came up because of problems with arguments
+like -DBLAH="Foo Bar" to GCC (define BLAH as a preprocessor constant
+being the string "Foo Bar", including the quotes). Because GCC simply
+passes the argument directly to CPP (the preprocessor) it had to be
+escaped *twice*:
+
+ "-DBLAH=\"\\\"Foo Bar\\\"\""
+
+This would reach GCC as
+
+ -DBLAH="\"Foo Bar\""
+
+And that would reach CPP as the desired
+
+ -DBLAH="Foo Bar"
+
+One level of quoting and escaping is to be expected (although MS's
+standard is, arguably, not very good), but forcing the user to know
+how many different programs the argument is going to pass through,
+and perform double quoting and escaping, seems unreasonable. If
+GCC and friends all used fix_argv (they use their own version of
+it now) then the original argument could be
+
+ "-DBLAH=\"Foo Bar\""
+
+And that would work fine, no matter how many different tools it
+passed through.
+
+The only basic limitation with this code is that it assumes that all
+the spawned programs use Microsoft-type escaping when interpreting
+their command line. Most programs on Win32 machines do (anything
+compiled with Mingw32 will).
+
+For now, this code has been relegated to 'sample' status. If you want
+to use it, feel free (it is public domain after all).
+
+Colin.
+
+P.S. Just out of interest you might try writing your own little program
+     to look at the interaction of wildcards and quotes. Use the glob.exe
+     program in ../globbing and see what it does with
+
+      glob "foo*.txt"
+
+     even if there are files foo.txt and foobar.txt in the same directory.
+
+     Note that
+
+      del "My *.txt"
+
+     works (i.e. it deletes all files starting with My<space>). This could
+     not be done unless del does globbing *after* processing escapes and
+     quotes, which is not the way it seems to work normally (again see
+     the glob example).
+
index 52f93d1..a6f7d51 100644 (file)
@@ -1,46 +1,46 @@
-/*\r
- * A sample program demonstrating how to use _CRT_fmode to change the default\r
- * file opening mode to binary AND change stdin, stdout and stderr. Redirect\r
- * stdout to a file from the command line to see the difference.\r
- *\r
- * Also try directing a file into stdin. If you type into stdin you will get\r
- * \r\n at the end of every line... unlike UNIX. But at least if you\r
- * redirect a file in you will get exactly the characters in the file as input.\r
- *\r
- * THIS CODE IS IN THE PUBLIC DOMAIN.\r
- *\r
- * Colin Peters <colin@fu.is.saga-u.ac.jp>\r
- */\r
-\r
-#include <stdio.h>\r
-#include <fcntl.h>\r
-\r
-unsigned int _CRT_fmode = _O_BINARY;\r
-\r
-main ()\r
-{\r
-       char* sz = "This is line one.\nThis is line two.\n";\r
-       FILE*   fp;\r
-       int     c;\r
-\r
-       printf (sz);\r
-\r
-       /* Note how this fopen does NOT indicate "wb" to open the file in\r
-        * binary mode. */\r
-       fp = fopen ("all.out", "w");\r
-\r
-       fprintf (fp, sz);\r
-\r
-       fclose (fp);\r
-\r
-       if (_isatty (_fileno(stdin)))\r
-       {\r
-               fprintf (stderr, "Waiting for input, press Ctrl-Z to finish.\n");\r
-       }\r
-\r
-       while ((c = fgetc(stdin)) != EOF)\r
-       {\r
-               printf ("\'%c\' %02X\n", (char) c, c);\r
-       }\r
-}\r
-\r
+/*
+ * A sample program demonstrating how to use _CRT_fmode to change the default
+ * file opening mode to binary AND change stdin, stdout and stderr. Redirect
+ * stdout to a file from the command line to see the difference.
+ *
+ * Also try directing a file into stdin. If you type into stdin you will get
+ * \r\n at the end of every line... unlike UNIX. But at least if you
+ * redirect a file in you will get exactly the characters in the file as input.
+ *
+ * THIS CODE IS IN THE PUBLIC DOMAIN.
+ *
+ * Colin Peters <colin@fu.is.saga-u.ac.jp>
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+
+unsigned int _CRT_fmode = _O_BINARY;
+
+main ()
+{
+       char* sz = "This is line one.\nThis is line two.\n";
+       FILE*   fp;
+       int     c;
+
+       printf (sz);
+
+       /* Note how this fopen does NOT indicate "wb" to open the file in
+        * binary mode. */
+       fp = fopen ("all.out", "w");
+
+       fprintf (fp, sz);
+
+       fclose (fp);
+
+       if (_isatty (_fileno(stdin)))
+       {
+               fprintf (stderr, "Waiting for input, press Ctrl-Z to finish.\n");
+       }
+
+       while ((c = fgetc(stdin)) != EOF)
+       {
+               printf ("\'%c\' %02X\n", (char) c, c);
+       }
+}
+
index 2c7f7d3..33455ec 100644 (file)
@@ -1,5 +1,5 @@
-\r
-Main test.exe : test.c ;\r
-\r
-Main all.exe : all.c ;\r
-\r
+
+Main test.exe : test.c ;
+
+Main all.exe : all.c ;
+
index 873b853..b865bfd 100644 (file)
@@ -1,5 +1,5 @@
-\r
-These two demos show how _fmode and _CRT_fmode can be used to modify the\r
-default file opening mode (text vs. binary) and/or the mode of the standard\r
-file handles.\r
-\r
+
+These two demos show how _fmode and _CRT_fmode can be used to modify the
+default file opening mode (text vs. binary) and/or the mode of the standard
+file handles.
+
index f19e7e0..b0488b2 100644 (file)
@@ -1,31 +1,31 @@
-/*\r
- * A sample program demonstrating how to use fmode to change the default\r
- * file opening mode to binary. NOTE: Does not change stdin, stdout or\r
- * stderr.\r
- *\r
- * THIS CODE IS IN THE PUBLIC DOMAIN.\r
- *\r
- * Colin Peters <colin@fu.is.saga-u.ac.jp>\r
- */\r
-\r
-#include <stdio.h>\r
-#include <fcntl.h>     /* Required to get _fmode and _O_BINARY */\r
-\r
-main ()\r
-{\r
-       char* sz = "This is line one.\nThis is line two.\n";\r
-       FILE*   fp;\r
-\r
-       _fmode = _O_BINARY;\r
-\r
-       printf (sz);\r
-\r
-       /* Note how this fopen does NOT indicate "wb" to open the file in\r
-        * binary mode. */\r
-       fp = fopen ("test.out", "w");\r
-\r
-       fprintf (fp, sz);\r
-\r
-       fclose (fp);\r
-}\r
-\r
+/*
+ * A sample program demonstrating how to use fmode to change the default
+ * file opening mode to binary. NOTE: Does not change stdin, stdout or
+ * stderr.
+ *
+ * THIS CODE IS IN THE PUBLIC DOMAIN.
+ *
+ * Colin Peters <colin@fu.is.saga-u.ac.jp>
+ */
+
+#include <stdio.h>
+#include <fcntl.h>     /* Required to get _fmode and _O_BINARY */
+
+main ()
+{
+       char* sz = "This is line one.\nThis is line two.\n";
+       FILE*   fp;
+
+       _fmode = _O_BINARY;
+
+       printf (sz);
+
+       /* Note how this fopen does NOT indicate "wb" to open the file in
+        * binary mode. */
+       fp = fopen ("test.out", "w");
+
+       fprintf (fp, sz);
+
+       fclose (fp);
+}
+
index f539533..b77e6d6 100644 (file)
@@ -1,9 +1,9 @@
-#\r
-# A simple example which prints a message on a selected printer. This won't\r
-# work right unless you make PRINTDLG a packed structure!\r
-#\r
-\r
-Main prntest.exe : prntest.c ;\r
-\r
-Gui prntest.exe ;\r
-\r
+#
+# A simple example which prints a message on a selected printer. This won't
+# work right unless you make PRINTDLG a packed structure!
+#
+
+Main prntest.exe : prntest.c ;
+
+Gui prntest.exe ;
+
index 801d1d8..a70e7ed 100644 (file)
@@ -1,65 +1,65 @@
-\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <string.h>\r
-#include <windows.h>\r
-\r
-main ()\r
-{\r
-       PRINTDLG        pd;\r
-       DOCINFO         di;\r
-       char*           szMessage;\r
-\r
-       memset (&pd, 0, sizeof(PRINTDLG));\r
-       memset (&di, 0, sizeof(DOCINFO));\r
-\r
-       di.cbSize = sizeof(DOCINFO);\r
-       di.lpszDocName = "Test";\r
-\r
-       pd.lStructSize = sizeof(PRINTDLG);\r
-       pd.Flags = PD_PAGENUMS | PD_RETURNDC;\r
-       pd.nFromPage = 1;\r
-       pd.nToPage = 1;\r
-       pd.nMinPage = 1;\r
-       pd.nMaxPage = 1;\r
-\r
-       szMessage = 0;\r
-\r
-       if (PrintDlg (&pd))\r
-       {\r
-               if (pd.hDC)\r
-               {\r
-                       if (StartDoc (pd.hDC, &di) != SP_ERROR)\r
-                       {\r
-                               StartPage (pd.hDC);\r
-\r
-                               TextOut (pd.hDC, 0, 0, "Hello, printer!", 15);\r
-\r
-                               EndPage (pd.hDC);\r
-\r
-                               EndDoc (pd.hDC);\r
-\r
-                               szMessage = "Printed.";\r
-                       }\r
-                       else\r
-                       {\r
-                               szMessage = "Could not start document.";\r
-                       }\r
-               }\r
-               else\r
-               {\r
-                       szMessage = "Could not create device context.";\r
-               }\r
-       }\r
-       else\r
-       {\r
-               szMessage = "Canceled or printer could not be setup.";\r
-       }\r
-\r
-       if (szMessage)\r
-       {\r
-               MessageBox (NULL, szMessage, "Print Test", MB_OK);\r
-       }\r
-\r
-       return 0;\r
-}\r
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <windows.h>
+
+main ()
+{
+       PRINTDLG        pd;
+       DOCINFO         di;
+       char*           szMessage;
+
+       memset (&pd, 0, sizeof(PRINTDLG));
+       memset (&di, 0, sizeof(DOCINFO));
+
+       di.cbSize = sizeof(DOCINFO);
+       di.lpszDocName = "Test";
+
+       pd.lStructSize = sizeof(PRINTDLG);
+       pd.Flags = PD_PAGENUMS | PD_RETURNDC;
+       pd.nFromPage = 1;
+       pd.nToPage = 1;
+       pd.nMinPage = 1;
+       pd.nMaxPage = 1;
+
+       szMessage = 0;
+
+       if (PrintDlg (&pd))
+       {
+               if (pd.hDC)
+               {
+                       if (StartDoc (pd.hDC, &di) != SP_ERROR)
+                       {
+                               StartPage (pd.hDC);
+
+                               TextOut (pd.hDC, 0, 0, "Hello, printer!", 15);
+
+                               EndPage (pd.hDC);
+
+                               EndDoc (pd.hDC);
+
+                               szMessage = "Printed.";
+                       }
+                       else
+                       {
+                               szMessage = "Could not start document.";
+                       }
+               }
+               else
+               {
+                       szMessage = "Could not create device context.";
+               }
+       }
+       else
+       {
+               szMessage = "Canceled or printer could not be setup.";
+       }
+
+       if (szMessage)
+       {
+               MessageBox (NULL, szMessage, "Print Test", MB_OK);
+       }
+
+       return 0;
+}
index e002019..49a06ce 100644 (file)
-int\r
-__except_handler3(\r
-       struct _EXCEPTION_RECORD*       pExceptionRecord,\r
-       struct EXCEPTION_REGISTRATION*  pRegistrationFrame,\r
-       struct _CONTEXT*                pContextRecord,\r
-       void*                           pDispatcherContext\r
-       )\r
-{\r
-       LONG    filterFuncRet;\r
-       LONG trylevel;\r
-       EXCEPTION_POINTERS exceptPtrs;\r
-       PSCOPETABLE pScopeTable;\r
-\r
-\r
-       CLD // Clear the direction flag (make no assumptions!)\r
-\r
-       // if neither the EXCEPTION_UNWINDING nor EXCEPTION_EXIT_UNWIND bit\r
-       // is set... This is true the first time through the handler (the\r
-       // non-unwinding case)\r
-\r
-       if ( ! (pExceptionRecord->ExceptionFlags\r
-                & (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND)\r
-               ) )\r
-       {\r
-               // Build the EXCEPTION_POINTERS structure on the stack\r
-               exceptPtrs.ExceptionRecord = pExceptionRecord;\r
-               exceptPtrs.ContextRecord = pContextRecord;\r
-\r
-               // Put the pointer to the EXCEPTION_POINTERS 4 bytes below the\r
-               // establisher frame. See ASM code for GetExceptionInformation\r
-               *(PDWORD)((PBYTE)pRegistrationFrame - 4) = &exceptPtrs;\r
-\r
-               // Get initial "trylevel" value\r
-               trylevel = pRegistrationFrame->trylevel \r
-\r
-               // Get a pointer to the scopetable array\r
-               scopeTable = pRegistrationFrame->scopetable;\r
-\r
-search_for_handler: \r
-               if ( pRegistrationFrame->trylevel != TRYLEVEL_NONE )\r
-               {\r
-                       if ( pRegistrationFrame->scopetable[trylevel].lpfnFilter )\r
-                       {\r
-\r
-                               PUSH EBP // Save this frame EBP\r
-\r
-                       // !!!Very Important!!! Switch to original EBP. This is\r
-                       // what allows all locals in the frame to have the same\r
-                       // value as before the exception occurred.\r
-\r
-                               EBP = &pRegistrationFrame->_ebp\r
-\r
-                               // Call the filter function\r
-                               filterFuncRet = scopetable[trylevel].lpfnFilter();\r
-\r
-                               POP EBP // Restore handler frame EBP\r
-\r
-                               if ( filterFuncRet != EXCEPTION_CONTINUE_SEARCH )\r
-                               {\r
-                                       if ( filterFuncRet < 0 ) // EXCEPTION_CONTINUE_EXECUTION\r
-                                               return ExceptionContinueExecution;\r
-\r
-                                       // If we get here, EXCEPTION_EXECUTE_HANDLER was specified\r
-                                       scopetable == pRegistrationFrame->scopetable\r
-\r
-                       // Does the actual OS cleanup of registration frames\r
-                                       // Causes this function to recurse\r
-                                       __global_unwind2( pRegistrationFrame );\r
-\r
-\r
-               // Once we get here, everything is all cleaned up, except\r
-               // for the last frame, where we'll continue execution\r
-                                       EBP = &pRegistrationFrame->_ebp\r
-\r
-                                       __local_unwind2( pRegistrationFrame, trylevel );\r
-\r
-               // NLG == "non-local-goto" (setjmp/longjmp stuff)\r
-                                       __NLG_Notify( 1 ); // EAX == scopetable->lpfnHandler\r
-\r
-               // Set the current trylevel to whatever SCOPETABLE entry\r
-               // was being used when a handler was found\r
-                                       pRegistrationFrame->trylevel = scopetable->previousTryLevel;\r
-\r
-               // Call the _except {} block. Never returns.\r
-                                       pRegistrationFrame->scopetable[trylevel].lpfnHandler();\r
-                               }\r
-                       }\r
-\r
-                       scopeTable = pRegistrationFrame->scopetable;\r
-                       trylevel = scopeTable->previousTryLevel\r
-\r
-                       goto search_for_handler;\r
-               }\r
-               else // trylevel == TRYLEVEL_NONE\r
-               {\r
-                       retvalue == DISPOSITION_CONTINUE_SEARCH;\r
-               }\r
-       }\r
-       else // EXCEPTION_UNWINDING or EXCEPTION_EXIT_UNWIND flags are set\r
-       {\r
-               PUSH EBP // Save EBP\r
-\r
-               EBP = pRegistrationFrame->_ebp // Set EBP for __local_unwind2\r
-\r
-               __local_unwind2( pRegistrationFrame, TRYLEVEL_NONE )\r
-\r
-               POP EBP // Restore EBP\r
-\r
-               retvalue == DISPOSITION_CONTINUE_SEARCH;\r
-       }\r
-}\r
-\r
+int
+__except_handler3(
+       struct _EXCEPTION_RECORD*       pExceptionRecord,
+       struct EXCEPTION_REGISTRATION*  pRegistrationFrame,
+       struct _CONTEXT*                pContextRecord,
+       void*                           pDispatcherContext
+       )
+{
+       LONG    filterFuncRet;
+       LONG trylevel;
+       EXCEPTION_POINTERS exceptPtrs;
+       PSCOPETABLE pScopeTable;
+
+
+       CLD // Clear the direction flag (make no assumptions!)
+
+       // if neither the EXCEPTION_UNWINDING nor EXCEPTION_EXIT_UNWIND bit
+       // is set... This is true the first time through the handler (the
+       // non-unwinding case)
+
+       if ( ! (pExceptionRecord->ExceptionFlags
+                & (EXCEPTION_UNWINDING | EXCEPTION_EXIT_UNWIND)
+               ) )
+       {
+               // Build the EXCEPTION_POINTERS structure on the stack
+               exceptPtrs.ExceptionRecord = pExceptionRecord;
+               exceptPtrs.ContextRecord = pContextRecord;
+
+               // Put the pointer to the EXCEPTION_POINTERS 4 bytes below the
+               // establisher frame. See ASM code for GetExceptionInformation
+               *(PDWORD)((PBYTE)pRegistrationFrame - 4) = &exceptPtrs;
+
+               // Get initial "trylevel" value
+               trylevel = pRegistrationFrame->trylevel 
+
+               // Get a pointer to the scopetable array
+               scopeTable = pRegistrationFrame->scopetable;
+
+search_for_handler: 
+               if ( pRegistrationFrame->trylevel != TRYLEVEL_NONE )
+               {
+                       if ( pRegistrationFrame->scopetable[trylevel].lpfnFilter )
+                       {
+
+                               PUSH EBP // Save this frame EBP
+
+                       // !!!Very Important!!! Switch to original EBP. This is
+                       // what allows all locals in the frame to have the same
+                       // value as before the exception occurred.
+
+                               EBP = &pRegistrationFrame->_ebp
+
+                               // Call the filter function
+                               filterFuncRet = scopetable[trylevel].lpfnFilter();
+
+                               POP EBP // Restore handler frame EBP
+
+                               if ( filterFuncRet != EXCEPTION_CONTINUE_SEARCH )
+                               {
+                                       if ( filterFuncRet < 0 ) // EXCEPTION_CONTINUE_EXECUTION
+                                               return ExceptionContinueExecution;
+
+                                       // If we get here, EXCEPTION_EXECUTE_HANDLER was specified
+                                       scopetable == pRegistrationFrame->scopetable
+
+                       // Does the actual OS cleanup of registration frames
+                                       // Causes this function to recurse
+                                       __global_unwind2( pRegistrationFrame );
+
+
+               // Once we get here, everything is all cleaned up, except
+               // for the last frame, where we'll continue execution
+                                       EBP = &pRegistrationFrame->_ebp
+
+                                       __local_unwind2( pRegistrationFrame, trylevel );
+
+               // NLG == "non-local-goto" (setjmp/longjmp stuff)
+                                       __NLG_Notify( 1 ); // EAX == scopetable->lpfnHandler
+
+               // Set the current trylevel to whatever SCOPETABLE entry
+               // was being used when a handler was found
+                                       pRegistrationFrame->trylevel = scopetable->previousTryLevel;
+
+               // Call the _except {} block. Never returns.
+                                       pRegistrationFrame->scopetable[trylevel].lpfnHandler();
+                               }
+                       }
+
+                       scopeTable = pRegistrationFrame->scopetable;
+                       trylevel = scopeTable->previousTryLevel
+
+                       goto search_for_handler;
+               }
+               else // trylevel == TRYLEVEL_NONE
+               {
+                       retvalue == DISPOSITION_CONTINUE_SEARCH;
+               }
+       }
+       else // EXCEPTION_UNWINDING or EXCEPTION_EXIT_UNWIND flags are set
+       {
+               PUSH EBP // Save EBP
+
+               EBP = pRegistrationFrame->_ebp // Set EBP for __local_unwind2
+
+               __local_unwind2( pRegistrationFrame, TRYLEVEL_NONE )
+
+               POP EBP // Restore EBP
+
+               retvalue == DISPOSITION_CONTINUE_SEARCH;
+       }
+}
+
index 9d98d83..187242c 100644 (file)
@@ -1,68 +1,68 @@
-\r
-#include <stdlib.h>\r
-#include <stdio.h>\r
-#include <excpt.h>\r
-#include <windows.h>\r
-\r
-#include "exutil.h"\r
-\r
-void\r
-WalkExceptionHandlers ()\r
-{\r
-       PEXCEPTION_REGISTRATION_RECORD  p;\r
-       int                             i;\r
-\r
-       __asm__("movl %%fs:0,%%eax;movl %%eax,%0" : "=g" (p) : : "%eax");\r
-\r
-       i = 0;\r
-       while (p != (PEXCEPTION_REGISTRATION_RECORD) -1 && p)\r
-       {\r
-               printf ("Registration %d at %08x : ", i, p);\r
-               printf ("Handler = %08x ", p->handler);\r
-               printf ("Next Registration = %08x\n", p->prev);\r
-               p = p->prev;\r
-               i++;\r
-       }\r
-       printf ("End of exception handler list.\n");\r
-       fflush (stdout);\r
-}\r
-\r
-void\r
-DumpExceptionRecord (struct _EXCEPTION_RECORD* pExRec)\r
-{\r
-       printf ("Exception: Code = %08x Flags %08x", pExRec->ExceptionCode,\r
-               pExRec->ExceptionFlags);\r
-\r
-       if (pExRec->ExceptionFlags)\r
-       {\r
-               printf (" ( ");\r
-               if (pExRec->ExceptionFlags & EH_NONCONTINUABLE)\r
-               {\r
-                       printf ("EH_NONCONTINUABLE ");\r
-               }\r
-               if (pExRec->ExceptionFlags & EH_UNWINDING)\r
-               {\r
-                       printf ("EH_UNWINDING ");\r
-               }\r
-               if (pExRec->ExceptionFlags & EH_EXIT_UNWIND)\r
-               {\r
-                       printf ("EH_EXIT_UNWIND ");\r
-               }\r
-               if (pExRec->ExceptionFlags & EH_STACK_INVALID)\r
-               {\r
-                       printf ("EH_STACK_INVALID ");\r
-               }\r
-               if (pExRec->ExceptionFlags & EH_NESTED_CALL)\r
-               {\r
-                       printf ("EH_NESTED_CALL ");\r
-               }\r
-               printf (")\n");\r
-       }\r
-       else\r
-       {\r
-               printf ("\n");\r
-       }\r
-\r
-       fflush(stdout);\r
-}\r
-\r
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <excpt.h>
+#include <windows.h>
+
+#include "exutil.h"
+
+void
+WalkExceptionHandlers ()
+{
+       PEXCEPTION_REGISTRATION_RECORD  p;
+       int                             i;
+
+       __asm__("movl %%fs:0,%%eax;movl %%eax,%0" : "=g" (p) : : "%eax");
+
+       i = 0;
+       while (p != (PEXCEPTION_REGISTRATION_RECORD) -1 && p)
+       {
+               printf ("Registration %d at %08x : ", i, p);
+               printf ("Handler = %08x ", p->handler);
+               printf ("Next Registration = %08x\n", p->prev);
+               p = p->prev;
+               i++;
+       }
+       printf ("End of exception handler list.\n");
+       fflush (stdout);
+}
+
+void
+DumpExceptionRecord (struct _EXCEPTION_RECORD* pExRec)
+{
+       printf ("Exception: Code = %08x Flags %08x", pExRec->ExceptionCode,
+               pExRec->ExceptionFlags);
+
+       if (pExRec->ExceptionFlags)
+       {
+               printf (" ( ");
+               if (pExRec->ExceptionFlags & EH_NONCONTINUABLE)
+               {
+                       printf ("EH_NONCONTINUABLE ");
+               }
+               if (pExRec->ExceptionFlags & EH_UNWINDING)
+               {
+                       printf ("EH_UNWINDING ");
+               }
+               if (pExRec->ExceptionFlags & EH_EXIT_UNWIND)
+               {
+                       printf ("EH_EXIT_UNWIND ");
+               }
+               if (pExRec->ExceptionFlags & EH_STACK_INVALID)
+               {
+                       printf ("EH_STACK_INVALID ");
+               }
+               if (pExRec->ExceptionFlags & EH_NESTED_CALL)
+               {
+                       printf ("EH_NESTED_CALL ");
+               }
+               printf (")\n");
+       }
+       else
+       {
+               printf ("\n");
+       }
+
+       fflush(stdout);
+}
+
index bf20cc1..a474be7 100644 (file)
@@ -1,3 +1,3 @@
-EXPORTS\r
- WalkExceptionHandlers\r
- DumpExceptionRecord\r
+EXPORTS
+ WalkExceptionHandlers
+ DumpExceptionRecord
index 79937f7..a56155b 100644 (file)
@@ -1,23 +1,23 @@
-/*\r
- * Definitions of some internal stuff for exception handling, including\r
- * a version of the all-important EXCEPTION_REGISTRATION_RECORD.\r
- */\r
-\r
-#ifndef _EXUTIL_H_\r
-#define _EXUTIL_H_\r
-\r
-#include <windows.h>\r
-#include <excpt.h>\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-void WalkExceptionHandlers ();\r
-void DumpExceptionRecord (struct _EXCEPTION_RECORD* pExRec);\r
-\r
-#ifdef __cplusplus\r
-}\r
-#endif\r
-\r
-#endif\r
+/*
+ * Definitions of some internal stuff for exception handling, including
+ * a version of the all-important EXCEPTION_REGISTRATION_RECORD.
+ */
+
+#ifndef _EXUTIL_H_
+#define _EXUTIL_H_
+
+#include <windows.h>
+#include <excpt.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void WalkExceptionHandlers ();
+void DumpExceptionRecord (struct _EXCEPTION_RECORD* pExRec);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
index 72b51b7..04d83c7 100644 (file)
@@ -1,13 +1,13 @@
-\r
-Dll exutil.dll : exutil.c ;\r
-\r
-ImportLib libexutil.a : exutil.def ;\r
-\r
-Main sehtest.exe : sehtest.c ;\r
-\r
-Main sehfix.exe : sehfix.c ;\r
-\r
-Main sehsub.exe : sehsub.c ;\r
-\r
-LinkLibraries sehtest.exe sehfix.exe sehsub.exe : libexutil.a ;\r
-\r
+
+Dll exutil.dll : exutil.c ;
+
+ImportLib libexutil.a : exutil.def ;
+
+Main sehtest.exe : sehtest.c ;
+
+Main sehfix.exe : sehfix.c ;
+
+Main sehsub.exe : sehsub.c ;
+
+LinkLibraries sehtest.exe sehfix.exe sehsub.exe : libexutil.a ;
+
index 1a414e6..be527ab 100644 (file)
@@ -1,60 +1,60 @@
-/*\r
- * sehfix.c\r
- *\r
- * A test program involving an exception handler that fixes the exception\r
- * causing condition.\r
- *\r
- * In this code we install an exception handler my_handler and then a piece\r
- * of inline assembly attempts to write at the address marked in eax, after\r
- * setting eax to 10. This should produce an exception. The handler then\r
- * changes the eax register of the exception context to be the address of\r
- * a static variable and restarts the code. This should allow everything\r
- * to continue.\r
- */\r
-\r
-#include <windows.h>\r
-#include <excpt.h>\r
-\r
-#include "exutil.h"\r
-\r
-int    x;\r
-\r
-EXCEPTION_DISPOSITION\r
-my_handler (\r
-       struct _EXCEPTION_RECORD* pExceptionRec,\r
-       void* pEstablisherFrame,\r
-       struct _CONTEXT* pContextRecord,\r
-       void* pDispatcherContext\r
-       )\r
-{\r
-       printf ("In my exception handler!\n");\r
-       DumpExceptionRecord (pExceptionRec);\r
-       pContextRecord->Eax = (DWORD) &x;\r
-       return ExceptionContinueExecution;\r
-}\r
-\r
-main ()\r
-{\r
-       x = 2;\r
-\r
-       printf ("x = %d\n", x);\r
-\r
-       WalkExceptionHandlers();\r
-\r
-       __try1(my_handler)\r
-\r
-       WalkExceptionHandlers();\r
-\r
-       /* This assembly code should produce an exception. */\r
-       __asm__("movl $10,%%eax;movl $1,(%%eax);" : : : "%eax");\r
-\r
-       __except1\r
-\r
-       WalkExceptionHandlers();\r
-\r
-       printf ("x = %d\n", x);\r
-\r
-       printf ("Finished!\n");\r
-}\r
-\r
-\r
+/*
+ * sehfix.c
+ *
+ * A test program involving an exception handler that fixes the exception
+ * causing condition.
+ *
+ * In this code we install an exception handler my_handler and then a piece
+ * of inline assembly attempts to write at the address marked in eax, after
+ * setting eax to 10. This should produce an exception. The handler then
+ * changes the eax register of the exception context to be the address of
+ * a static variable and restarts the code. This should allow everything
+ * to continue.
+ */
+
+#include <windows.h>
+#include <excpt.h>
+
+#include "exutil.h"
+
+int    x;
+
+EXCEPTION_DISPOSITION
+my_handler (
+       struct _EXCEPTION_RECORD* pExceptionRec,
+       void* pEstablisherFrame,
+       struct _CONTEXT* pContextRecord,
+       void* pDispatcherContext
+       )
+{
+       printf ("In my exception handler!\n");
+       DumpExceptionRecord (pExceptionRec);
+       pContextRecord->Eax = (DWORD) &x;
+       return ExceptionContinueExecution;
+}
+
+main ()
+{
+       x = 2;
+
+       printf ("x = %d\n", x);
+
+       WalkExceptionHandlers();
+
+       __try1(my_handler)
+
+       WalkExceptionHandlers();
+
+       /* This assembly code should produce an exception. */
+       __asm__("movl $10,%%eax;movl $1,(%%eax);" : : : "%eax");
+
+       __except1
+
+       WalkExceptionHandlers();
+
+       printf ("x = %d\n", x);
+
+       printf ("Finished!\n");
+}
+
+
index d244285..466b2e8 100644 (file)
@@ -1,43 +1,43 @@
-/*\r
- * sehsub.c\r
- *\r
- * In an attempt to see what might be going on inside CRTDLL, this program\r
- * walks the exception list after creating a new thread with _beginthread.\r
- *\r
- * It turns out that _beginthread DOES install an exception handler, as\r
- * expected, but this handler is NOT exported by CRTDLL (it is certainly\r
- * not _except_handler2 or _XcptFilter)... an odd and unpleasant turn of\r
- * events.\r
- */\r
-\r
-#include <windows.h>\r
-#include <excpt.h>\r
-#include <process.h>\r
-\r
-#include "exutil.h"\r
-\r
-extern void* __imp__except_handler3;\r
-\r
-unsigned\r
-my_thread (void * p)\r
-{\r
-       printf ("In my thread.\n");\r
-       WalkExceptionHandlers();\r
-       return 0;\r
-}\r
-\r
-main ()\r
-{\r
-       unsigned long   h;\r
-       unsigned        id;\r
-       printf ("In main.\n");\r
-       WalkExceptionHandlers();\r
-\r
-       printf ("Except_handler3 %08x\n", __imp__except_handler3);\r
-       h = _beginthreadex (NULL, 0, my_thread, NULL, 0, &id);\r
-\r
-       WaitForSingleObject ((HANDLE) h, INFINITE);\r
-       CloseHandle ((HANDLE) h);\r
-       return;\r
-}\r
-\r
+/*
+ * sehsub.c
+ *
+ * In an attempt to see what might be going on inside CRTDLL, this program
+ * walks the exception list after creating a new thread with _beginthread.
+ *
+ * It turns out that _beginthread DOES install an exception handler, as
+ * expected, but this handler is NOT exported by CRTDLL (it is certainly
+ * not _except_handler2 or _XcptFilter)... an odd and unpleasant turn of
+ * events.
+ */
+
+#include <windows.h>
+#include <excpt.h>
+#include <process.h>
+
+#include "exutil.h"
+
+extern void* __imp__except_handler3;
+
+unsigned
+my_thread (void * p)
+{
+       printf ("In my thread.\n");
+       WalkExceptionHandlers();
+       return 0;
+}
+
+main ()
+{
+       unsigned long   h;
+       unsigned        id;
+       printf ("In main.\n");
+       WalkExceptionHandlers();
+
+       printf ("Except_handler3 %08x\n", __imp__except_handler3);
+       h = _beginthreadex (NULL, 0, my_thread, NULL, 0, &id);
+
+       WaitForSingleObject ((HANDLE) h, INFINITE);
+       CloseHandle ((HANDLE) h);
+       return;
+}
+
index b7ac335..f1c18d0 100644 (file)
@@ -1,72 +1,72 @@
-/*\r
- * This file tests some of the basics of structured exception handling as\r
- * implemented in excpt.h and the Windows API header files.\r
- *\r
- * The program installs two exception handlers, then attempts to write to\r
- * a pointer to an invalid address. This causes an exception which passes\r
- * through the exception handlers and on to the default system exception\r
- * handler. That handler brings up the dialog box all Windows users know\r
- * and love, and then the program is terminated.\r
- *\r
- * You might note that after the initial run up through our exception frames\r
- * we get a second run up through them with the exception code\r
- * STATUS_INVALID_DISPOSITION and the code EH_UNWINDING. This seems normal\r
- * except that the code got changed from the previous STATUS_ACCESS_VIOLATION.\r
- * I don't understand that bit particularly.\r
- */\r
-\r
-#include <stdio.h>\r
-#include <excpt.h>\r
-\r
-#include "exutil.h"\r
-\r
-EXCEPTION_DISPOSITION\r
-my_handler (\r
-       struct _EXCEPTION_RECORD* pExceptionRec,\r
-       void* pEstablisherFrame,\r
-       struct _CONTEXT* pContextRecord,\r
-       void* pDispatcherContext\r
-       )\r
-{\r
-       printf ("In my exception handler!\n");\r
-       DumpExceptionRecord (pExceptionRec);\r
-       return ExceptionContinueSearch;\r
-}\r
-\r
-EXCEPTION_DISPOSITION\r
-my_handler2 (\r
-       struct _EXCEPTION_RECORD* pExceptionRec,\r
-       void* pEstablisherFrame,\r
-       struct _CONTEXT* pContextRecord,\r
-       void* pDispatcherContext\r
-       )\r
-{\r
-       printf ("In top exception handler!\n");\r
-       DumpExceptionRecord (pExceptionRec);\r
-       return ExceptionContinueSearch;\r
-}\r
-\r
-main ()\r
-{\r
-       char*   x;\r
-\r
-       printf ("my_handler2 = %08x\n", my_handler2);\r
-       printf ("my_handler = %08x\n", my_handler);\r
-\r
-       WalkExceptionHandlers();\r
-\r
-       __try1(my_handler2)\r
-       x = (char*) 10;\r
-\r
-       WalkExceptionHandlers();\r
-\r
-       __try1(my_handler)\r
-\r
-       WalkExceptionHandlers();\r
-\r
-       *x = 1;\r
-       __except1\r
-       __except1\r
-       printf ("Finished!\n");\r
-}\r
-\r
+/*
+ * This file tests some of the basics of structured exception handling as
+ * implemented in excpt.h and the Windows API header files.
+ *
+ * The program installs two exception handlers, then attempts to write to
+ * a pointer to an invalid address. This causes an exception which passes
+ * through the exception handlers and on to the default system exception
+ * handler. That handler brings up the dialog box all Windows users know
+ * and love, and then the program is terminated.
+ *
+ * You might note that after the initial run up through our exception frames
+ * we get a second run up through them with the exception code
+ * STATUS_INVALID_DISPOSITION and the code EH_UNWINDING. This seems normal
+ * except that the code got changed from the previous STATUS_ACCESS_VIOLATION.
+ * I don't understand that bit particularly.
+ */
+
+#include <stdio.h>
+#include <excpt.h>
+
+#include "exutil.h"
+
+EXCEPTION_DISPOSITION
+my_handler (
+       struct _EXCEPTION_RECORD* pExceptionRec,
+       void* pEstablisherFrame,
+       struct _CONTEXT* pContextRecord,
+       void* pDispatcherContext
+       )
+{
+       printf ("In my exception handler!\n");
+       DumpExceptionRecord (pExceptionRec);
+       return ExceptionContinueSearch;
+}
+
+EXCEPTION_DISPOSITION
+my_handler2 (
+       struct _EXCEPTION_RECORD* pExceptionRec,
+       void* pEstablisherFrame,
+       struct _CONTEXT* pContextRecord,
+       void* pDispatcherContext
+       )
+{
+       printf ("In top exception handler!\n");
+       DumpExceptionRecord (pExceptionRec);
+       return ExceptionContinueSearch;
+}
+
+main ()
+{
+       char*   x;
+
+       printf ("my_handler2 = %08x\n", my_handler2);
+       printf ("my_handler = %08x\n", my_handler);
+
+       WalkExceptionHandlers();
+
+       __try1(my_handler2)
+       x = (char*) 10;
+
+       WalkExceptionHandlers();
+
+       __try1(my_handler)
+
+       WalkExceptionHandlers();
+
+       *x = 1;
+       __except1
+       __except1
+       printf ("Finished!\n");
+}
+
index 7f743bf..c642af4 100644 (file)
@@ -1,33 +1,33 @@
-\r
-#include <windows.h>\r
-\r
-BOOL WINAPI\r
-DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)\r
-{\r
-       switch (dwReason)\r
-       {\r
-               case DLL_PROCESS_ATTACH:\r
-                       printf ("DLL Attached.\n");\r
-                       break;\r
-\r
-               case DLL_PROCESS_DETACH:\r
-                       printf ("DLL Detached.\n");\r
-                       break;\r
-\r
-               case DLL_THREAD_ATTACH:\r
-                       printf ("DLL Thread Attached.\n");\r
-                       break;\r
-\r
-               case DLL_THREAD_DETACH:\r
-                       printf ("DLL Thread Detached.\n");\r
-                       break;\r
-       }\r
-       return TRUE;\r
-}\r
-\r
-void\r
-Test ()\r
-{\r
-       printf ("Test Function called!\n");\r
-}\r
-\r
+
+#include <windows.h>
+
+BOOL WINAPI
+DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
+{
+       switch (dwReason)
+       {
+               case DLL_PROCESS_ATTACH:
+                       printf ("DLL Attached.\n");
+                       break;
+
+               case DLL_PROCESS_DETACH:
+                       printf ("DLL Detached.\n");
+                       break;
+
+               case DLL_THREAD_ATTACH:
+                       printf ("DLL Thread Attached.\n");
+                       break;
+
+               case DLL_THREAD_DETACH:
+                       printf ("DLL Thread Detached.\n");
+                       break;
+       }
+       return TRUE;
+}
+
+void
+Test ()
+{
+       printf ("Test Function called!\n");
+}
+
index 0c02406..cdf0dfb 100644 (file)
@@ -1,44 +1,44 @@
-//\r
-// This is a C++ version of the code in dll.c. NOTE that you need to put\r
-// extern "C" { ... } around DllMain or it will not be called when your\r
-// Dll starts up! (It will get name mangled as a C++ function and the C\r
-// default version in libmingw32.a will get called instead.)\r
-//\r
-\r
-#include <windows.h>\r
-\r
-#include <iostream>\r
-\r
-extern "C" {\r
-\r
-BOOL WINAPI\r
-DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)\r
-{\r
-       switch (dwReason)\r
-       {\r
-               case DLL_PROCESS_ATTACH:\r
-                       cout << "Dll Attached" << endl ;\r
-                       break;\r
-\r
-               case DLL_PROCESS_DETACH:\r
-                       cout << "Dll Detached" << endl ;\r
-                       break;\r
-\r
-               case DLL_THREAD_ATTACH:\r
-                       printf ("DLL Thread Attached.\n");\r
-                       break;\r
-\r
-               case DLL_THREAD_DETACH:\r
-                       printf ("DLL Thread Detached.\n");\r
-                       break;\r
-       }\r
-       return TRUE;\r
-}\r
-\r
-void\r
-Test ()\r
-{\r
-       printf ("Test Function called!\n");\r
-}\r
-\r
-};\r
+//
+// This is a C++ version of the code in dll.c. NOTE that you need to put
+// extern "C" { ... } around DllMain or it will not be called when your
+// Dll starts up! (It will get name mangled as a C++ function and the C
+// default version in libmingw32.a will get called instead.)
+//
+
+#include <windows.h>
+
+#include <iostream>
+
+extern "C" {
+
+BOOL WINAPI
+DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved)
+{
+       switch (dwReason)
+       {
+               case DLL_PROCESS_ATTACH:
+                       cout << "Dll Attached" << endl ;
+                       break;
+
+               case DLL_PROCESS_DETACH:
+                       cout << "Dll Detached" << endl ;
+                       break;
+
+               case DLL_THREAD_ATTACH:
+                       printf ("DLL Thread Attached.\n");
+                       break;
+
+               case DLL_THREAD_DETACH:
+                       printf ("DLL Thread Detached.\n");
+                       break;
+       }
+       return TRUE;
+}
+
+void
+Test ()
+{
+       printf ("Test Function called!\n");
+}
+
+};
index cc44202..af5bb41 100644 (file)
@@ -1,13 +1,13 @@
-#include <stdio.h>\r
-\r
-extern void Test();\r
-\r
-int main()\r
-{\r
-       printf ("Program started.\n");\r
-       Test ();\r
-       printf ("Program ends.\n");\r
-\r
-       return 0;\r
-}\r
-\r
+#include <stdio.h>
+
+extern void Test();
+
+int main()
+{
+       printf ("Program started.\n");
+       Test ();
+       printf ("Program ends.\n");
+
+       return 0;
+}
+
index 30704e6..d1e2591 100644 (file)
@@ -1,14 +1,14 @@
-\r
-Dll dll.dll : dll.c ;\r
-\r
-ImportLib libdll.a : dll.def ;\r
-\r
-\r
-Main exe.exe : exe.c ;\r
-\r
-LinkLibraries exe.exe : libdll.a ;\r
-\r
-DEPENDS exe.exe : dll.dll ;\r
-\r
-LINKFLAGS on exe.exe = $(LINKFLAGS) -L. ;\r
-\r
+
+Dll dll.dll : dll.c ;
+
+ImportLib libdll.a : dll.def ;
+
+
+Main exe.exe : exe.c ;
+
+LinkLibraries exe.exe : libdll.a ;
+
+DEPENDS exe.exe : dll.dll ;
+
+LINKFLAGS on exe.exe = $(LINKFLAGS) -L. ;
+
index 332ac04..2fc7b84 100644 (file)
@@ -1,9 +1,9 @@
-#\r
-# A very simple example with which you can test your compiler/jam setup.\r
-# Also an interesting example of a hybrid console/GUI application.\r
-#\r
-\r
-Main test.exe : test.c ;\r
-\r
-GuiLibs test.exe ;\r
-\r
+#
+# A very simple example with which you can test your compiler/jam setup.
+# Also an interesting example of a hybrid console/GUI application.
+#
+
+Main test.exe : test.c ;
+
+GuiLibs test.exe ;
+
index af8884c..82ca6b0 100644 (file)
@@ -1,20 +1,20 @@
-/*\r
- * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.\r
- *\r
- * Colin Peters <colin@bird.fu.is.saga-u.ac.jp>, April 15, 1997.\r
- */\r
-\r
-#include <windows.h>\r
-#include <stdio.h>\r
-\r
-int STDCALL\r
-WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)\r
-{\r
-       char text[80];\r
-\r
-       printf ("Enter message box text:");\r
-       fgets(text, 80, stdin);\r
-       MessageBox (NULL, text, "Test", MB_OK);\r
-       printf ("\nHello after message box.\n");\r
-       return 0;\r
-}\r
+/*
+ * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
+ *
+ * Colin Peters <colin@bird.fu.is.saga-u.ac.jp>, April 15, 1997.
+ */
+
+#include <windows.h>
+#include <stdio.h>
+
+int STDCALL
+WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
+{
+       char text[80];
+
+       printf ("Enter message box text:");
+       fgets(text, 80, stdin);
+       MessageBox (NULL, text, "Test", MB_OK);
+       printf ("\nHello after message box.\n");
+       return 0;
+}
index 8102fa0..b2f7831 100644 (file)
@@ -1,8 +1,8 @@
-#\r
-# A example of Win32 GUI programming in C.\r
-#\r
-\r
-Main test.exe : test.c ;\r
-\r
-Gui test.exe ;\r
-\r
+#
+# A example of Win32 GUI programming in C.
+#
+
+Main test.exe : test.c ;
+
+Gui test.exe ;
+
index 961496f..056888f 100644 (file)
-/*\r
- * A basic example of Win32 programming in C.\r
- *\r
- * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.\r
- *\r
- * Colin Peters <colin@bird.fu.is.saga-u.ac.jp>\r
- */\r
-\r
-#include <windows.h>\r
-#include <string.h>\r
-\r
-/*\r
- * This is the window function for the main window. Whenever a message is\r
- * dispatched using DispatchMessage (or sent with SendMessage) this function\r
- * gets called with the contents of the message.\r
- */\r
-LRESULT CALLBACK\r
-MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)\r
-{\r
-       /* The window handle for the "Click Me" button. */\r
-       static  HWND    hwndButton = 0;\r
-       static int      cx, cy; /* Height and width of our button. */\r
-\r
-       HDC             hdc;    /* A device context used for drawing */\r
-       PAINTSTRUCT     ps;     /* Also used during window drawing */\r
-       RECT            rc;     /* A rectangle used during drawing */\r
-\r
-       /*\r
-        * Perform processing based on what kind of message we got.\r
-        */\r
-       switch (nMsg)\r
-       {\r
-               case WM_CREATE:\r
-               {\r
-                       /* The window is being created. Create our button\r
-                        * window now. */\r
-                       TEXTMETRIC      tm;\r
-\r
-                       /* First we use the system fixed font size to choose\r
-                        * a nice button size. */\r
-                       hdc = GetDC (hwnd);\r
-                       SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));\r
-                       GetTextMetrics (hdc, &tm);\r
-                       cx = tm.tmAveCharWidth * 30;\r
-                       cy = (tm.tmHeight + tm.tmExternalLeading) * 2;\r
-                       ReleaseDC (hwnd, hdc);\r
-\r
-                       /* Now create the button */\r
-                       hwndButton = CreateWindow (\r
-                               "button",       /* Builtin button class */\r
-                               "Click Here",\r
-                               WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,\r
-                               0, 0, cx, cy,\r
-                               hwnd,           /* Parent is this window. */\r
-                               (HMENU) 1,      /* Control ID: 1 */\r
-                               ((LPCREATESTRUCT) lParam)->hInstance,\r
-                               NULL\r
-                               );\r
-\r
-                       return 0;\r
-                       break;\r
-               }\r
-\r
-               case WM_DESTROY:\r
-                       /* The window is being destroyed, close the application\r
-                        * (the child button gets destroyed automatically). */\r
-                       PostQuitMessage (0);\r
-                       return 0;\r
-                       break;\r
-\r
-               case WM_PAINT:\r
-                       /* The window needs to be painted (redrawn). */\r
-                       hdc = BeginPaint (hwnd, &ps);\r
-                       GetClientRect (hwnd, &rc);\r
-\r
-                       /* Draw "Hello, World" in the middle of the upper\r
-                        * half of the window. */\r
-                       rc.bottom = rc.bottom / 2;\r
-                       DrawText (hdc, "Hello, World", -1, &rc,\r
-                               DT_SINGLELINE | DT_CENTER | DT_VCENTER);\r
-\r
-                       EndPaint (hwnd, &ps);\r
-                       return 0;\r
-                       break;\r
-\r
-               case WM_SIZE:\r
-                       /* The window size is changing. If the button exists\r
-                        * then place it in the center of the bottom half of\r
-                        * the window. */\r
-                       if (hwndButton &&\r
-                               (wParam == SIZEFULLSCREEN ||\r
-                                wParam == SIZENORMAL)\r
-                          )\r
-                       {\r
-                               rc.left = (LOWORD(lParam) - cx) / 2;\r
-                               rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;\r
-                               MoveWindow (\r
-                                       hwndButton,\r
-                                       rc.left, rc.top, cx, cy, TRUE);\r
-                       }\r
-                       break;\r
-\r
-               case WM_COMMAND:\r
-                       /* Check the control ID, notification code and\r
-                        * control handle to see if this is a button click\r
-                        * message from our child button. */\r
-                       if (LOWORD(wParam) == 1 &&\r
-                           HIWORD(wParam) == BN_CLICKED &&\r
-                           (HWND) lParam == hwndButton)\r
-                       {\r
-                               /* Our button was clicked. Close the window. */\r
-                               DestroyWindow (hwnd);\r
-                       }\r
-                       return 0;\r
-                       break;\r
-       }\r
-\r
-       /* If we don't handle a message completely we hand it to the system\r
-        * provided default window function. */\r
-       return DefWindowProc (hwnd, nMsg, wParam, lParam);\r
-}\r
-\r
-\r
-int STDCALL\r
-WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)\r
-{\r
-       HWND            hwndMain;       /* Handle for the main window. */\r
-       MSG             msg;            /* A Win32 message structure. */\r
-       WNDCLASSEX      wndclass;       /* A window class structure. */\r
-       char*           szMainWndClass = "WinTestWin";\r
-                                       /* The name of the main window class */\r
-\r
-       /*\r
-        * First we create a window class for our main window.\r
-        */\r
-\r
-       /* Initialize the entire structure to zero. */\r
-       memset (&wndclass, 0, sizeof(WNDCLASSEX));\r
-\r
-       /* This class is called WinTestWin */\r
-       wndclass.lpszClassName = szMainWndClass;\r
-\r
-       /* cbSize gives the size of the structure for extensibility. */\r
-       wndclass.cbSize = sizeof(WNDCLASSEX);\r
-\r
-       /* All windows of this class redraw when resized. */\r
-       wndclass.style = CS_HREDRAW | CS_VREDRAW;\r
-\r
-       /* All windows of this class use the MainWndProc window function. */\r
-       wndclass.lpfnWndProc = MainWndProc;\r
-\r
-       /* This class is used with the current program instance. */\r
-       wndclass.hInstance = hInst;\r
-\r
-       /* Use standard application icon and arrow cursor provided by the OS */\r
-       wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);\r
-       wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);\r
-       wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);\r
-\r
-       /* Color the background white */\r
-       wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);\r
-\r
-       /*\r
-        * Now register the window class for use.\r
-        */\r
-       RegisterClassEx (&wndclass);\r
-\r
-       /*\r
-        * Create our main window using that window class.\r
-        */\r
-       hwndMain = CreateWindow (\r
-               szMainWndClass,         /* Class name */\r
-               "Hello",                /* Caption */\r
-               WS_OVERLAPPEDWINDOW,    /* Style */\r
-               CW_USEDEFAULT,          /* Initial x (use default) */\r
-               CW_USEDEFAULT,          /* Initial y (use default) */\r
-               CW_USEDEFAULT,          /* Initial x size (use default) */\r
-               CW_USEDEFAULT,          /* Initial y size (use default) */\r
-               NULL,                   /* No parent window */\r
-               NULL,                   /* No menu */\r
-               hInst,                  /* This program instance */\r
-               NULL                    /* Creation parameters */\r
-               );\r
-       \r
-       /*\r
-        * Display the window which we just created (using the nShow\r
-        * passed by the OS, which allows for start minimized and that\r
-        * sort of thing).\r
-        */\r
-       ShowWindow (hwndMain, nShow);\r
-       UpdateWindow (hwndMain);\r
-\r
-       /*\r
-        * The main message loop. All messages being sent to the windows\r
-        * of the application (or at least the primary thread) are retrieved\r
-        * by the GetMessage call, then translated (mainly for keyboard\r
-        * messages) and dispatched to the appropriate window procedure.\r
-        * This is the simplest kind of message loop. More complex loops\r
-        * are required for idle processing or handling modeless dialog\r
-        * boxes. When one of the windows calls PostQuitMessage GetMessage\r
-        * will return zero and the wParam of the message will be filled\r
-        * with the argument to PostQuitMessage. The loop will end and\r
-        * the application will close.\r
-         */\r
-       while (GetMessage (&msg, NULL, 0, 0))\r
-       {\r
-               TranslateMessage (&msg);\r
-               DispatchMessage (&msg);\r
-       }\r
-       return msg.wParam;\r
-}\r
-\r
+/*
+ * A basic example of Win32 programming in C.
+ *
+ * This source code is in the PUBLIC DOMAIN and has NO WARRANTY.
+ *
+ * Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
+ */
+
+#include <windows.h>
+#include <string.h>
+
+/*
+ * This is the window function for the main window. Whenever a message is
+ * dispatched using DispatchMessage (or sent with SendMessage) this function
+ * gets called with the contents of the message.
+ */
+LRESULT CALLBACK
+MainWndProc (HWND hwnd, UINT nMsg, WPARAM wParam, LPARAM lParam)
+{
+       /* The window handle for the "Click Me" button. */
+       static  HWND    hwndButton = 0;
+       static int      cx, cy; /* Height and width of our button. */
+
+       HDC             hdc;    /* A device context used for drawing */
+       PAINTSTRUCT     ps;     /* Also used during window drawing */
+       RECT            rc;     /* A rectangle used during drawing */
+
+       /*
+        * Perform processing based on what kind of message we got.
+        */
+       switch (nMsg)
+       {
+               case WM_CREATE:
+               {
+                       /* The window is being created. Create our button
+                        * window now. */
+                       TEXTMETRIC      tm;
+
+                       /* First we use the system fixed font size to choose
+                        * a nice button size. */
+                       hdc = GetDC (hwnd);
+                       SelectObject (hdc, GetStockObject (SYSTEM_FIXED_FONT));
+                       GetTextMetrics (hdc, &tm);
+                       cx = tm.tmAveCharWidth * 30;
+                       cy = (tm.tmHeight + tm.tmExternalLeading) * 2;
+                       ReleaseDC (hwnd, hdc);
+
+                       /* Now create the button */
+                       hwndButton = CreateWindow (
+                               "button",       /* Builtin button class */
+                               "Click Here",
+                               WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON,
+                               0, 0, cx, cy,
+                               hwnd,           /* Parent is this window. */
+                               (HMENU) 1,      /* Control ID: 1 */
+                               ((LPCREATESTRUCT) lParam)->hInstance,
+                               NULL
+                               );
+
+                       return 0;
+                       break;
+               }
+
+               case WM_DESTROY:
+                       /* The window is being destroyed, close the application
+                        * (the child button gets destroyed automatically). */
+                       PostQuitMessage (0);
+                       return 0;
+                       break;
+
+               case WM_PAINT:
+                       /* The window needs to be painted (redrawn). */
+                       hdc = BeginPaint (hwnd, &ps);
+                       GetClientRect (hwnd, &rc);
+
+                       /* Draw "Hello, World" in the middle of the upper
+                        * half of the window. */
+                       rc.bottom = rc.bottom / 2;
+                       DrawText (hdc, "Hello, World", -1, &rc,
+                               DT_SINGLELINE | DT_CENTER | DT_VCENTER);
+
+                       EndPaint (hwnd, &ps);
+                       return 0;
+                       break;
+
+               case WM_SIZE:
+                       /* The window size is changing. If the button exists
+                        * then place it in the center of the bottom half of
+                        * the window. */
+                       if (hwndButton &&
+                               (wParam == SIZEFULLSCREEN ||
+                                wParam == SIZENORMAL)
+                          )
+                       {
+                               rc.left = (LOWORD(lParam) - cx) / 2;
+                               rc.top = HIWORD(lParam) * 3 / 4 - cy / 2;
+                               MoveWindow (
+                                       hwndButton,
+                                       rc.left, rc.top, cx, cy, TRUE);
+                       }
+                       break;
+
+               case WM_COMMAND:
+                       /* Check the control ID, notification code and
+                        * control handle to see if this is a button click
+                        * message from our child button. */
+                       if (LOWORD(wParam) == 1 &&
+                           HIWORD(wParam) == BN_CLICKED &&
+                           (HWND) lParam == hwndButton)
+                       {
+                               /* Our button was clicked. Close the window. */
+                               DestroyWindow (hwnd);
+                       }
+                       return 0;
+                       break;
+       }
+
+       /* If we don't handle a message completely we hand it to the system
+        * provided default window function. */
+       return DefWindowProc (hwnd, nMsg, wParam, lParam);
+}
+
+
+int STDCALL
+WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
+{
+       HWND            hwndMain;       /* Handle for the main window. */
+       MSG             msg;            /* A Win32 message structure. */
+       WNDCLASSEX      wndclass;       /* A window class structure. */
+       char*           szMainWndClass = "WinTestWin";
+                                       /* The name of the main window class */
+
+       /*
+        * First we create a window class for our main window.
+        */
+
+       /* Initialize the entire structure to zero. */
+       memset (&wndclass, 0, sizeof(WNDCLASSEX));
+
+       /* This class is called WinTestWin */
+       wndclass.lpszClassName = szMainWndClass;
+
+       /* cbSize gives the size of the structure for extensibility. */
+       wndclass.cbSize = sizeof(WNDCLASSEX);
+
+       /* All windows of this class redraw when resized. */
+       wndclass.style = CS_HREDRAW | CS_VREDRAW;
+
+       /* All windows of this class use the MainWndProc window function. */
+       wndclass.lpfnWndProc = MainWndProc;
+
+       /* This class is used with the current program instance. */
+       wndclass.hInstance = hInst;
+
+       /* Use standard application icon and arrow cursor provided by the OS */
+       wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
+       wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
+       wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
+
+       /* Color the background white */
+       wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
+
+       /*
+        * Now register the window class for use.
+        */
+       RegisterClassEx (&wndclass);
+
+       /*
+        * Create our main window using that window class.
+        */
+       hwndMain = CreateWindow (
+               szMainWndClass,         /* Class name */
+               "Hello",                /* Caption */
+               WS_OVERLAPPEDWINDOW,    /* Style */
+               CW_USEDEFAULT,          /* Initial x (use default) */
+               CW_USEDEFAULT,          /* Initial y (use default) */
+               CW_USEDEFAULT,          /* Initial x size (use default) */
+               CW_USEDEFAULT,          /* Initial y size (use default) */
+               NULL,                   /* No parent window */
+               NULL,                   /* No menu */
+               hInst,                  /* This program instance */
+               NULL                    /* Creation parameters */
+               );
+       
+       /*
+        * Display the window which we just created (using the nShow
+        * passed by the OS, which allows for start minimized and that
+        * sort of thing).
+        */
+       ShowWindow (hwndMain, nShow);
+       UpdateWindow (hwndMain);
+
+       /*
+        * The main message loop. All messages being sent to the windows
+        * of the application (or at least the primary thread) are retrieved
+        * by the GetMessage call, then translated (mainly for keyboard
+        * messages) and dispatched to the appropriate window procedure.
+        * This is the simplest kind of message loop. More complex loops
+        * are required for idle processing or handling modeless dialog
+        * boxes. When one of the windows calls PostQuitMessage GetMessage
+        * will return zero and the wParam of the message will be filled
+        * with the argument to PostQuitMessage. The loop will end and
+        * the application will close.
+         */
+       while (GetMessage (&msg, NULL, 0, 0))
+       {
+               TranslateMessage (&msg);
+               DispatchMessage (&msg);
+       }
+       return msg.wParam;
+}
+