[AD] [PATCH] Split USE_CONSOLE

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


USE_CONSOLE was introduced because Windows isn't able to provide a console
ouput for its GUI applications. Under Windows, it disables the magic main
that turns by default a main() into a WinMain().

Now, presumably in order to mimic this behaviour, USE_CONSOLE disables the
magic main on Unix systems too, although Unix systems always provide a
console output, thus making USE_CONSOLE useless.

Disabling the magic main on Unix systems has a few nasty effects: some
configuration and file routines don't work anymore. For example, the
following program:

#define USE_CONSOLE

#include <stdio.h>
#include <allegro.h>

int main(int argc, char *argv[])
{
   char exec_name[1024];

   set_uformat(U_ASCII);
   allegro_init();

   get_executable_name(exec_name, 1024);

   puts(exec_name);
   return 0;
}
END_OF_MAIN()

returns "./unknown" on Unix systems, whereas it perfectly works under
Windows!

The attached patch splits USE_CONSOLE into two parts: ALLEGRO_USE_CONSOLE
that only instructs Allegro to provide a console output (no-op on Unix
systems) and ALLEGRO_NO_MAGIC_MAIN that disables the magic main.
USE_CONSOLE is still provided for backward compatibility. After this patch
is applied, the program above behaves correctly if USE_CONSOLE is replaced
by ALLEGRO_USE_CONSOLE.

Defining ALLEGRO_NO_MAGIC_MAIN allows a program to #include <allegro.h>
without linking against the library (see src/i386/asmdef.c). And it's that
symbol which inherits the few nasty effects of the former USE_CONSOLE.

This patch will also simply the problem we are faced with Darwin:
- it will let the Allegro distribution build on Darwin without any
additional modification because USE_CONSOLE is replaced by
ALLEGRO_USE_CONSOLE in the utilities,
- it will narrow down the problem to the sole behaviour of
ALLEGRO_NO_MAGIC_MAIN under Darwin (which is already impaired by the
aforementioned limitations because Darwin belongs to the Unix family).

Tested under Linux and Windows.

Off-topic: is it normal that get_executable_name() returns './exec_name' on
Unix systems ? The docs read "This generally comes from argv[0], but on Unix
systems if argv[0] does not specify the path, we search for our file in
$PATH."

--
Eric Botcazou
ebotcazou@xxxxxxxxxx

Attachment: magic_main5.zip
Description: Zip compressed data



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/