fltk 1.3.0rc3
About: FLTK (Fast Light Tool Kit) is a cross-platform C++ GUI toolkit for UNIX/Linux (X11), Microsoft Windows, and MacOS X. Release candidate.
  SfR Fresh Dox: fltk-1.3.0rc3-source.tar.gz ("inofficial" and yet experimental doxygen-generated source code documentation)  

fl_call_main.c

Go to the documentation of this file.
00001 /*
00002  * "$Id: fl_call_main.c 7903 2010-11-28 21:06:39Z matt $"
00003  *
00004  * Copyright 1998-2010 by Bill Spitzak and others.
00005  *
00006  * fl_call_main() calls main() for you Windows people.  Needs to be done in C
00007  * because Borland C++ won't let you call main() from C++.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Library General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2 of the License, or (at your option) any later version.
00013  *
00014  * This library is distributed in the hope that it will be useful,
00015  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  * Library General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Library General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00022  * USA.
00023  *
00024  * Please report all bugs and problems on the following page:
00025  *
00026  *     http://www.fltk.org/str.php
00027  */
00028 
00029 /*
00030  * This WinMain() function can be overridden by an application and
00031  * is provided for compatibility with programs written for other
00032  * operating systems that conform to the ANSI standard entry point
00033  * "main()".  This will allow you to build a WIN32 Application
00034  * without any special settings.
00035  *
00036  * Because of problems with the Microsoft Visual C++ header files
00037  * and/or compiler, you cannot have a WinMain function in a DLL.
00038  * I don't know why.  Thus, this nifty feature is only available
00039  * if you link to the static library.
00040  *
00041  * Currently the debug version of this library will create a
00042  * console window for your application so you can put printf()
00043  * statements for debugging or informational purposes.  Ultimately
00044  * we want to update this to always use the parent's console,
00045  * but at present we have not identified a function or API in
00046  * Microsoft(r) Windows(r) that allows for it.
00047  */
00048 
00049 #if defined(WIN32) && !defined(FL_DLL) && !defined (__GNUC__)
00050 
00051 #  include <windows.h>
00052 #  include <stdio.h>
00053 #  include <stdlib.h>
00054 #  include <FL/fl_utf8.h>
00055 
00056 extern int main(int, char *[]);
00057 
00058 #  ifdef BORLAND5
00059 #    define __argc _argc
00060 #    define __argv _argv
00061 #  endif /* BORLAND5 */
00062 
00063 /* static int mbcs2utf(const char *s, int l, char *dst, unsigned dstlen) */
00064 static int mbcs2utf(const char *s, int l, char *dst)
00065 {
00066   static xchar *mbwbuf;
00067   unsigned dstlen = 0;
00068   if (!s) return 0;
00069   dstlen = (l * 6) + 6;
00070   mbwbuf = (xchar*)malloc(dstlen * sizeof(xchar));
00071   l = mbstowcs(mbwbuf, s, l);
00072 /* l = fl_unicode2utf(mbwbuf, l, dst); */
00073   l = fl_utf8fromwc(dst, dstlen, mbwbuf, l);
00074   dst[l] = 0;
00075   free(mbwbuf);
00076   return l;
00077 }
00078 
00079 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
00080                              LPSTR lpCmdLine, int nCmdShow) {
00081   int rc, i;
00082   char **ar;
00083 
00084 #  ifdef _DEBUG
00085  /*
00086   * If we are using compiling in debug mode, open a console window so
00087   * we can see any printf's, etc...
00088   *
00089   * While we can detect if the program was run from the command-line -
00090   * look at the CMDLINE environment variable, it will be "WIN" for
00091   * programs started from the GUI - the shell seems to run all WIN32
00092   * applications in the background anyways...
00093   */
00094 
00095   AllocConsole();
00096   freopen("conin$", "r", stdin);
00097   freopen("conout$", "w", stdout);
00098   freopen("conout$", "w", stderr);
00099 #  endif /* _DEBUG */
00100 
00101   ar = (char**) malloc(sizeof(char*) * (__argc + 1));
00102   i = 0;
00103   while (i < __argc) {
00104     int l;
00105     unsigned dstlen;
00106     if (__wargv ) {
00107       for (l = 0; __wargv[i] && __wargv[i][l]; l++) {}; /* is this just wstrlen??? */
00108       dstlen = (l * 5) + 1;
00109       ar[i] = (char*) malloc(dstlen);
00110 /*    ar[i][fl_unicode2utf(__wargv[i], l, ar[i])] = 0; */
00111       dstlen = fl_utf8fromwc(ar[i], dstlen, __wargv[i], l);
00112       ar[i][dstlen] = 0;
00113     } else {
00114       for (l = 0; __argv[i] && __argv[i][l]; l++) {};
00115       dstlen = (l * 5) + 1;
00116       ar[i] = (char*) malloc(dstlen);
00117 /*      ar[i][mbcs2utf(__argv[i], l, ar[i], dstlen)] = 0; */
00118       ar[i][mbcs2utf(__argv[i], l, ar[i])] = 0;
00119     }
00120     i++;
00121   }
00122   ar[__argc] = 0;
00123   /* Run the standard main entry point function... */
00124   rc = main(__argc, ar);
00125 
00126 #  ifdef _DEBUG
00127   fclose(stdin);
00128   fclose(stdout);
00129   fclose(stderr);
00130 #  endif /* _DEBUG */
00131 
00132   return rc;
00133 }
00134 
00135 #elif defined(__hpux)
00136 /* This code to prevent "empty translation unit" or similar warnings... */
00137 static void dummy(void) {}
00138 #endif /* WIN32 && !FL_DLL && !__GNUC__ */
00139 
00140 /*
00141  * End of "$Id: fl_call_main.c 7903 2010-11-28 21:06:39Z matt $".
00142  */
00143