diff --git a/Makefile b/Makefile index d7acd433..1728f7bc 100644 --- a/Makefile +++ b/Makefile @@ -139,6 +139,7 @@ else MKDIR = mkdir -p RMDIR = rmdir CP = cp + ifdef WIN32CROSS #cross compile a Win32 executable CC = i586-mingw32msvc-gcc @@ -148,13 +149,27 @@ else LOPT = -mwindows -lmingw32 -lSDLmain -lSDL -lshlwapi `/usr/local/cross-tools/i386-mingw32/bin/sdl-config --libs` -lSDL_image $(TTFLOPT) OBJDIR = obj/win32 else - BIN = grafx2 - CFGBIN = gfxcfg - COPT = -W -Wall -Wdeclaration-after-statement -pedantic -std=c99 -c -g `sdl-config --cflags` $(TTFCOPT) - LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT) - CC = gcc - OBJDIR = obj/unix - X11LOPT = -lX11 + + ifdef GP2XCROSS + #cross compile an exec for the gp2x + CC = /opt/open2x/gcc-4.1.1-glibc-2.3.6/arm-open2x-linux/bin/arm-open2x-linux-gcc + BIN = grafx2.gpe + CFGBIN = gfxcfg.gpe + COPT = -W -Wall -Wdeclaration-after-statement -pedantic -std=c99 -static -c -g -O3 `/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/sdl-config --cflags` $(TTFCOPT) -D__GP2X__ + LOPT = -static -lSDL_image `/opt/open2x/gcc-4.1.1-glibc-2.3.6/bin/sdl-config --static-libs` -ljpeg -lpng -lz -lm $(TTFLOPT) + OBJDIR = obj/gp2x + NOTTF = 1 + else + + # Compiles a regular linux exectutable for the native platform + BIN = grafx2 + CFGBIN = gfxcfg + COPT = -W -Wall -Wdeclaration-after-statement -pedantic -std=c99 -c -g `sdl-config --cflags` $(TTFCOPT) + LOPT = `sdl-config --libs` -lSDL_image $(TTFLOPT) + CC = gcc + OBJDIR = obj/unix + X11LOPT = -lX11 + endif endif endif endif diff --git a/SFont.c b/SFont.c index e2e2ada8..049dd39d 100644 --- a/SFont.c +++ b/SFont.c @@ -24,8 +24,8 @@ GERMANY karlb@gmx.net */ -#include -#include +#include +#include #include #include diff --git a/SFont.h b/SFont.h index bab55e9e..96e2cb0a 100644 --- a/SFont.h +++ b/SFont.h @@ -36,7 +36,7 @@ #ifndef _SFONT_H_ #define _SFONT_H_ -#include +#include #ifdef __cplusplus extern "C" { diff --git a/boutons.c b/boutons.c index 985c6e03..c1f64b5e 100644 --- a/boutons.c +++ b/boutons.c @@ -25,7 +25,7 @@ #include #include #include -#include +#include #include "const.h" #include "struct.h" diff --git a/divers.c b/divers.c index 3661850c..666febd2 100644 --- a/divers.c +++ b/divers.c @@ -20,8 +20,9 @@ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include #include +#include #include #include "struct.h" #include "sdlscreen.h" diff --git a/files.c b/files.c index af366fdb..3ba42ad5 100644 --- a/files.c +++ b/files.c @@ -285,7 +285,6 @@ void bstrtostr( BSTR in, STRPTR out, TEXT max ) // -- Lecture d'une liste de lecteurs / volumes ----------------------------- void Lire_liste_des_lecteurs(void) { -// Fixes a warning on os4 #ifndef __amigaos4__ int Indice; #endif diff --git a/gfxcfg.c b/gfxcfg.c index ca62ecd0..b10951a0 100644 --- a/gfxcfg.c +++ b/gfxcfg.c @@ -29,9 +29,9 @@ #include //SDL -#include -#include -#include +#include +#include +#include //#include //mine diff --git a/global.h b/global.h index 48b909f8..a0a16d41 100644 --- a/global.h +++ b/global.h @@ -39,7 +39,7 @@ #ifndef _GLOBAL_H_ #define _GLOBAL_H_ -#include +#include #include "struct.h" GFX2_GLOBAL struct S_Config diff --git a/hotkeys.h b/hotkeys.h index cf49bef1..13c465b2 100644 --- a/hotkeys.h +++ b/hotkeys.h @@ -20,7 +20,7 @@ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include -#include +#include /*** Types definitions and structs ***/ diff --git a/init.c b/init.c index ff17225e..aea66c8f 100644 --- a/init.c +++ b/init.c @@ -31,7 +31,7 @@ #include #include #include -#include +#include #if defined(__WIN32__) #include // GetLogicalDrives(), GetDriveType(), DRIVE_* #endif diff --git a/io.c b/io.c index 00840fbe..8f5ba874 100644 --- a/io.c +++ b/io.c @@ -1,245 +1,245 @@ -/* Grafx2 - The Ultimate 256-color bitmap paint program - - Copyright 2008 Yves Rizoud - Copyright 2007 Adrien Destugues - Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) - - Grafx2 is free software; you can redistribute it and/or - modify it under the terms of the GNU General Public License - as published by the Free Software Foundation; version 2 - of the License. - - Grafx2 is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Grafx2; if not, see or - write to the Free Software Foundation, Inc., - 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -// Fonctions de lecture/ecriture fichier, gèrent les systèmes big-endian et -// little-endian. - -#include -#include -#include -#include -#if defined(__amigaos4__) - #include - #include -#elif defined(__WATCOMC__) - #include -#elif defined(__WIN32__) - #include - #include -#else - #include -#endif - -#include "struct.h" -#include "io.h" - -word endian_magic16(word x) -{ - #if SDL_BYTEORDER == SDL_LIL_ENDIAN - return x; - #else - return SDL_Swap16(x); - #endif -} -dword endian_magic32(dword x) -{ - #if SDL_BYTEORDER == SDL_LIL_ENDIAN - return x; - #else - return SDL_Swap32(x); - #endif -} - -// Lit un octet -// Renvoie -1 si OK, 0 en cas d'erreur -int read_byte(FILE *Fichier, byte *Dest) -{ - return fread(Dest, 1, 1, Fichier) == 1; -} -// Ecrit un octet -// Renvoie -1 si OK, 0 en cas d'erreur -int write_byte(FILE *Fichier, byte Byte) -{ - return fwrite(&Byte, 1, 1, Fichier) == 1; -} -// Lit des octets -// Renvoie -1 si OK, 0 en cas d'erreur -int read_bytes(FILE *Fichier, void *Dest, size_t Taille) -{ - return fread(Dest, 1, Taille, Fichier) == Taille; -} -// Ecrit des octets -// Renvoie -1 si OK, 0 en cas d'erreur -int write_bytes(FILE *Fichier, void *Src, size_t Taille) -{ - return fwrite(Src, 1, Taille, Fichier) == Taille; -} - -// Lit un word (little-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int read_word_le(FILE *Fichier, word *Dest) -{ - if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word)) - return 0; - #if SDL_BYTEORDER != SDL_LIL_ENDIAN - *Dest = SDL_Swap16(*Dest); - #endif - return -1; -} -// Ecrit un word (little-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int write_word_le(FILE *Fichier, word Mot) -{ - #if SDL_BYTEORDER != SDL_LIL_ENDIAN - Mot = SDL_Swap16(Mot); - #endif - return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word); -} -// Lit un word (big-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int read_word_be(FILE *Fichier, word *Dest) -{ - if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word)) - return 0; - #if SDL_BYTEORDER != SDL_BIG_ENDIAN - *Dest = SDL_Swap16(*Dest); - #endif - return -1; -} -// Ecrit un word (big-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int write_word_be(FILE *Fichier, word Mot) -{ - #if SDL_BYTEORDER != SDL_BIG_ENDIAN - Mot = SDL_Swap16(Mot); - #endif - return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word); -} -// Lit un dword (little-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int read_dword_le(FILE *Fichier, dword *Dest) -{ - if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword)) - return 0; - #if SDL_BYTEORDER != SDL_LIL_ENDIAN - *Dest = SDL_Swap32(*Dest); - #endif - return -1; -} -// Ecrit un dword (little-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int write_dword_le(FILE *Fichier, dword Mot) -{ - #if SDL_BYTEORDER != SDL_LIL_ENDIAN - Mot = SDL_Swap32(Mot); - #endif - return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword); -} - -// Lit un dword (big-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int read_dword_be(FILE *Fichier, dword *Dest) -{ - if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword)) - return 0; - #if SDL_BYTEORDER != SDL_BIG_ENDIAN - *Dest = SDL_Swap32(*Dest); - #endif - return -1; -} -// Ecrit un dword (big-endian) -// Renvoie -1 si OK, 0 en cas d'erreur -int write_dword_be(FILE *Fichier, dword Mot) -{ - #if SDL_BYTEORDER != SDL_BIG_ENDIAN - Mot = SDL_Swap32(Mot); - #endif - return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword); -} - -// Détermine la position du dernier '/' ou '\\' dans une chaine, -// typiquement pour séparer le nom de fichier d'un chemin. -// Attention, sous Windows, il faut s'attendre aux deux car -// par exemple un programme lancé sous GDB aura comme argv[0]: -// d:\Data\C\GFX2\grafx2/grafx2.exe -char * Position_dernier_slash(const char * Chaine) -{ - const char * Position = NULL; - for (; *Chaine != '\0'; Chaine++) - if (*Chaine == SEPARATEUR_CHEMIN[0] -#ifdef __WIN32__ - || *Chaine == '/' -#endif - ) - Position = Chaine; - return (char *)Position; -} -// Récupère la partie "nom de fichier seul" d'un chemin -void Extraire_nom_fichier(char *Destination, const char *Source) -{ - const char * Position = Position_dernier_slash(Source); - - if (Position) - strcpy(Destination,Position+1); - else - strcpy(Destination,Source); -} -// Récupère la partie "répertoire+/" d'un chemin. -void Extraire_chemin(char *Destination, const char *Source) -{ - char * Position; - - strcpy(Destination,Source); - Position = Position_dernier_slash(Destination); - if (Position) - *(Position+1) = '\0'; - else - strcat(Destination, SEPARATEUR_CHEMIN); -} - -int Fichier_existe(char * Fichier) -// Détermine si un fichier passé en paramètre existe ou non dans le -// répertoire courant. -{ - struct stat buf; - int Resultat; - - Resultat=stat(Fichier,&buf); - if (Resultat!=0) - return(errno!=ENOENT); - else - return 1; - -} -int Repertoire_existe(char * Repertoire) -// Détermine si un répertoire passé en paramètre existe ou non dans le -// répertoire courant. -{ - DIR* Enreg; // Structure de lecture des éléments - - if (strcmp(Repertoire,"..")==0) - return 1; - else - { - // On va chercher si le répertoire existe à l'aide d'un Opendir. S'il - // renvoie NULL c'est que le répertoire n'est pas accessible... - - Enreg=opendir(Repertoire); - if (Enreg==NULL) - return 0; - else - { - closedir(Enreg); - return 1; - } - } +/* Grafx2 - The Ultimate 256-color bitmap paint program + + Copyright 2008 Yves Rizoud + Copyright 2007 Adrien Destugues + Copyright 1996-2001 Sunset Design (Guillaume Dorme & Karl Maritaud) + + Grafx2 is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 + of the License. + + Grafx2 is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Grafx2; if not, see or + write to the Free Software Foundation, Inc., + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +// Fonctions de lecture/ecriture fichier, gèrent les systèmes big-endian et +// little-endian. + +#include +#include +#include +#include +#if defined(__amigaos4__) + #include + #include +#elif defined(__WATCOMC__) + #include +#elif defined(__WIN32__) + #include + #include +#else + #include +#endif + +#include "struct.h" +#include "io.h" + +word endian_magic16(word x) +{ + #if SDL_BYTEORDER == SDL_LIL_ENDIAN + return x; + #else + return SDL_Swap16(x); + #endif +} +dword endian_magic32(dword x) +{ + #if SDL_BYTEORDER == SDL_LIL_ENDIAN + return x; + #else + return SDL_Swap32(x); + #endif +} + +// Lit un octet +// Renvoie -1 si OK, 0 en cas d'erreur +int read_byte(FILE *Fichier, byte *Dest) +{ + return fread(Dest, 1, 1, Fichier) == 1; +} +// Ecrit un octet +// Renvoie -1 si OK, 0 en cas d'erreur +int write_byte(FILE *Fichier, byte Byte) +{ + return fwrite(&Byte, 1, 1, Fichier) == 1; +} +// Lit des octets +// Renvoie -1 si OK, 0 en cas d'erreur +int read_bytes(FILE *Fichier, void *Dest, size_t Taille) +{ + return fread(Dest, 1, Taille, Fichier) == Taille; +} +// Ecrit des octets +// Renvoie -1 si OK, 0 en cas d'erreur +int write_bytes(FILE *Fichier, void *Src, size_t Taille) +{ + return fwrite(Src, 1, Taille, Fichier) == Taille; +} + +// Lit un word (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_word_le(FILE *Fichier, word *Dest) +{ + if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word)) + return 0; + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + *Dest = SDL_Swap16(*Dest); + #endif + return -1; +} +// Ecrit un word (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_word_le(FILE *Fichier, word Mot) +{ + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + Mot = SDL_Swap16(Mot); + #endif + return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word); +} +// Lit un word (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_word_be(FILE *Fichier, word *Dest) +{ + if (fread(Dest, 1, sizeof(word), Fichier) != sizeof(word)) + return 0; + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + *Dest = SDL_Swap16(*Dest); + #endif + return -1; +} +// Ecrit un word (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_word_be(FILE *Fichier, word Mot) +{ + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + Mot = SDL_Swap16(Mot); + #endif + return fwrite(&Mot, 1, sizeof(word), Fichier) == sizeof(word); +} +// Lit un dword (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_dword_le(FILE *Fichier, dword *Dest) +{ + if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword)) + return 0; + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + *Dest = SDL_Swap32(*Dest); + #endif + return -1; +} +// Ecrit un dword (little-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_dword_le(FILE *Fichier, dword Mot) +{ + #if SDL_BYTEORDER != SDL_LIL_ENDIAN + Mot = SDL_Swap32(Mot); + #endif + return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword); +} + +// Lit un dword (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int read_dword_be(FILE *Fichier, dword *Dest) +{ + if (fread(Dest, 1, sizeof(dword), Fichier) != sizeof(dword)) + return 0; + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + *Dest = SDL_Swap32(*Dest); + #endif + return -1; +} +// Ecrit un dword (big-endian) +// Renvoie -1 si OK, 0 en cas d'erreur +int write_dword_be(FILE *Fichier, dword Mot) +{ + #if SDL_BYTEORDER != SDL_BIG_ENDIAN + Mot = SDL_Swap32(Mot); + #endif + return fwrite(&Mot, 1, sizeof(dword), Fichier) == sizeof(dword); +} + +// Détermine la position du dernier '/' ou '\\' dans une chaine, +// typiquement pour séparer le nom de fichier d'un chemin. +// Attention, sous Windows, il faut s'attendre aux deux car +// par exemple un programme lancé sous GDB aura comme argv[0]: +// d:\Data\C\GFX2\grafx2/grafx2.exe +char * Position_dernier_slash(const char * Chaine) +{ + const char * Position = NULL; + for (; *Chaine != '\0'; Chaine++) + if (*Chaine == SEPARATEUR_CHEMIN[0] +#ifdef __WIN32__ + || *Chaine == '/' +#endif + ) + Position = Chaine; + return (char *)Position; +} +// Récupère la partie "nom de fichier seul" d'un chemin +void Extraire_nom_fichier(char *Destination, const char *Source) +{ + const char * Position = Position_dernier_slash(Source); + + if (Position) + strcpy(Destination,Position+1); + else + strcpy(Destination,Source); +} +// Récupère la partie "répertoire+/" d'un chemin. +void Extraire_chemin(char *Destination, const char *Source) +{ + char * Position; + + strcpy(Destination,Source); + Position = Position_dernier_slash(Destination); + if (Position) + *(Position+1) = '\0'; + else + strcat(Destination, SEPARATEUR_CHEMIN); +} + +int Fichier_existe(char * Fichier) +// Détermine si un fichier passé en paramètre existe ou non dans le +// répertoire courant. +{ + struct stat buf; + int Resultat; + + Resultat=stat(Fichier,&buf); + if (Resultat!=0) + return(errno!=ENOENT); + else + return 1; + +} +int Repertoire_existe(char * Repertoire) +// Détermine si un répertoire passé en paramètre existe ou non dans le +// répertoire courant. +{ + DIR* Enreg; // Structure de lecture des éléments + + if (strcmp(Repertoire,"..")==0) + return 1; + else + { + // On va chercher si le répertoire existe à l'aide d'un Opendir. S'il + // renvoie NULL c'est que le répertoire n'est pas accessible... + + Enreg=opendir(Repertoire); + if (Enreg==NULL) + return 0; + else + { + closedir(Enreg); + return 1; + } + } } diff --git a/main.c b/main.c index 911af9aa..fd74c81b 100644 --- a/main.c +++ b/main.c @@ -35,8 +35,8 @@ #include #include #include -#include -#include +#include +#include #include #include "pages.h" #include "files.h" @@ -58,7 +58,7 @@ #elif defined(__macosx__) #import #import -#elif defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) +#elif defined(__AROS__) || defined(__BEOS__) || defined(__MORPHOS__) || defined(__GP2X__) #include "realpath.h" #endif diff --git a/operatio.c b/operatio.c index 299c4f85..99223d85 100644 --- a/operatio.c +++ b/operatio.c @@ -36,7 +36,7 @@ #include "brush.h" #include "windows.h" -#ifdef __WATCOMC__ +#if defined(__WATCOMC__) || defined(__GP2X__) #define M_PI 3.14159265358979323846 #endif diff --git a/pxsimple.c b/pxsimple.c index 00ee5662..ec4ad5f3 100644 --- a/pxsimple.c +++ b/pxsimple.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include "global.h" #include "sdlscreen.h" #include "divers.h" diff --git a/pxtall.c b/pxtall.c index f45df845..ff0760c5 100644 --- a/pxtall.c +++ b/pxtall.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include "global.h" #include "sdlscreen.h" #include "divers.h" diff --git a/pxwide.c b/pxwide.c index 1b3435d3..fd71911d 100644 --- a/pxwide.c +++ b/pxwide.c @@ -23,7 +23,7 @@ #include #include -#include +#include #include "global.h" #include "sdlscreen.h" #include "divers.h" diff --git a/realpath.c b/realpath.c index 00d2cade..06bb1f56 100644 --- a/realpath.c +++ b/realpath.c @@ -9,6 +9,11 @@ #include #include +#if defined(__GP2X__) + // This is a random default value ... + #define PATH_MAX 32768 +#endif + static char *sep(char *path) { char *tmp, c; diff --git a/sdlscreen.c b/sdlscreen.c index 170f26a0..03678055 100644 --- a/sdlscreen.c +++ b/sdlscreen.c @@ -22,7 +22,7 @@ */ #include #include -#include +#include #include "global.h" #include "sdlscreen.h" #include "erreurs.h" diff --git a/sdlscreen.h b/sdlscreen.h index caf3278b..3e7a1429 100644 --- a/sdlscreen.h +++ b/sdlscreen.h @@ -22,7 +22,7 @@ #ifndef SDLSCREEN_H_INCLUDED #define SDLSCREEN_H_INCLUDED -#include +#include #include "struct.h" void Set_Mode_SDL(int *,int *,int); diff --git a/texte.c b/texte.c index 72341b22..c707cc2c 100644 --- a/texte.c +++ b/texte.c @@ -33,7 +33,7 @@ #ifdef __macosx__ #include #else - #include + #include #endif #ifdef __linux__ @@ -46,7 +46,8 @@ #endif #endif #endif -#include + +#include // SFont #include "SFont.h" @@ -319,6 +320,7 @@ void Initialisation_Texte(void) #endif #elif defined(__linux__) + #ifndef NOTTF #define USE_XLIB #ifdef USE_XLIB @@ -333,6 +335,7 @@ void Initialisation_Texte(void) XFreeFontPath(font_path_list); } #endif + #endif #elif defined(__amigaos4__) #ifndef NOTTF for_each_file( "FONTS:_TrueType", Ajout_fonte );