UFO:Alien Invasion
Development => Newbie Coding => Topic started by: Muton on April 05, 2010, 01:24:33 pm
-
I tried to add a new macro
to also show the svn revision on the ufoai mainscreen (prevent posts "I dont know the revision of my build")
First i used int and all worked fine
The number was shown
but than i tried to add a string to add rev29954
C::B now returns always a warning (the exe crash)
common.c:887:60: warning: character constant too long for its type
common.c: In function 'Qcommon_Init':
common.c:887: warning: format '%s' expects type 'char *', but argument 3 has type 'int'
After h's of trial and error i tried a small piece of code
#include <stdio.h>
# ifdef REVISION
# define UFO_REVISION REVISION
# else
# define UFO_REVISION ""
# endif
void main(void) {
printf("%s\n", UFO_REVISION);
}
To compile i've used first MinGW environment
mingw32-gcc.exe -DREVISION='"rev1234"' test.c -otest.exe
the output was than as expected
but if i run the same on cmd.exe
test.c:10:17: warning: character constant too long for its type
C::B does use the correct command-line
The question now is whats the problem ???
The code can't be?!
I've used this manual (bottom) http://www.network-theory.co.uk/docs/gccintro/gccintro_35.html
-DMACRONAME='"stringvalue"'
I`'ve added
#define UFO_VERSION "2.3-dev"
# ifdef REVISION
# define UFO_REVISION REVISION
# else
# define UFO_REVISION ""
# endif
s = va("UFO: Alien Invasion %s %s %s %s %s", UFO_VERSION, UFO_REVISION, CPUSTRING, __DATE__, BUILDSTRING);
<Add option="-DREVISION='"rev22568"'" />
-
the revision should only be the number - if you want to convert the number into a string, use the STRINGIFY macro
-
but - this is really nothing i would like to see solved like this. it must work crossplattform if this gets ever into svn. and that is not an easy task to do it for all the *nixes out there.
-
If we boil it down to the minimum required, it should work cross-platform imho. Like:
char verString[222];
int rev = 12345;
sprintf(verString, "UFO:AI V2.3 dev revision: %i\n", rev);
printf(verString);
My biggest question is: how do you get the svn rev number into the call of mingW ??
-
maybe mingw also has the command svnversion - otherwise
SVN_REV=$(shell LANG=C svn info | awk '$$1 == "Revision:" {print $$2; exit 0}')
-
see https://sourceforge.net/apps/trac/ufoai/changeset/29236
-
the "real" fix for this would be to use the version specified in configure.ac and attach the svn revision number extracted with svnversion or svn info
-
> maybe mingw also has the command svnversion
The package we support own it
but you cant count on it
> - otherwise
.... or file ufoaiSOURCEfolder/.svn/entries line 4
> sprintf(verString, "UFO:AI V2.3 dev revision: %i\n", rev);
Thats a better way
but if the macro is not provided than ....
UFO:AI V2.3 dev revision: x86 Apr 1 2010 whathever
A user would think revision x86
> My biggest question is: how do you get the svn rev number into the call of mingW ??
Does configure && make work under MinGW ?
There is a way to join macros url1 (http://gcc.gnu.org/onlinedocs/gcc-3.0.1/cpp_3.html#SEC16) url2 (https://www.securecoding.cert.org/confluence/display/seccode/PRE05-C.+Understand+macro+replacement+when+concatenating+tokens+or+performing+stringification)
The code is not working
its 10pm and i'm not getting it :P
error: pasting ""2.3-dev "" and ""1234"" does not give a valid preprocessing token
#include <stdio.h>
# ifdef REVISION
# define UFO_REVISION REVISION
# define xstr(s) str(s)
# define str(s) #s
# define JOIN(x, y) JOIN_AGAIN(x, y)
# define JOIN_AGAIN(x, y) x ## y
# define UFO_VERSION JOIN("2.3-dev ",xstr(UFO_REVISION))
# else
# define UFO_VERSION "2.3-dev"
# endif
void main(void) {
printf("%s\n",UFO_VERSION );
}
-
> My biggest question is: how do you get the svn rev number into the call of mingW ??
Does configure && make work under MinGW ?
that is the long term goal as i would like to get rid of the c::b project files completely. It works for some users already - but only with manual setup - afair BTAxis, Destructavator and bayo are using (or were using) configure and make under windows.
if you have:
gcc -DSOMEVAR=1 ....
you can do:
#if SOMEVAR > 0
Com_sprintf(buf, sizeof(buf), "Some nice info %s", DOUBLEQUOTE(SOMEVAR));
#endif
or
#if SOMEVAR > 0
Com_sprintf(buf, sizeof(buf), "Some nice info %i", SOMEVAR);
#endif
-
see r29245
but keep in mind that this must not be up-to-date if you don't do a clean build.
-
http://sourceforge.net/apps/trac/ufoai/changeset/29287
or
Compiling: ..\..\src\common\common.c
V:\strün (x68)\MinGW\ufoai\src\common\common.c: In function 'Qcommon_Init':
V:\strün (x68)\MinGW\ufoai\src\common\common.c:887: error: expected ')' before numeric constant
Process terminated with status 1 (2 minutes, 24 seconds)
1 errors, 0 warnings
-
Should be fixed now in the SVN.
-
reverted that commit - see https://sourceforge.net/apps/trac/ufoai/changeset/29291 for more details.
-
I thought we submit an int as macro not a string
because gcc on Win32 is not able to use the string
if called from C::B (first post)
<Add option="-DUFO_REVISION='"28869M"'" />
result in
Compiling: ..\..\src\common\common.c
V:\strün (x68)\MinGW\ufoai\src\common\common.c:887:78: warning: character constant too long for its type
V:\strün (x68)\MinGW\ufoai\src\common\common.c: In function 'Qcommon_Init':
V:\strün (x68)\MinGW\ufoai\src\common\common.c:887: error: expected ')' before '\x3836394d'
GNU C (TDM-2 mingw32) version 4.4.1 (mingw32)
the explanation for this
cmd
COLLECT_GCC_OPTIONS='-v' '-DUFO_REVISION='\''1234c'\''' '-otest.exe' '-mtune=i386'
there are ' \ ' ' 1234c ' \ ' '
not ' " 1234c " '
mingw
COLLECT_GCC_OPTIONS='-v' '-DUFO_REVISION="1234c"' '-otest.exe' '-mtune=i386'
correct ' " 1234c " '
-
well for me -DSOMEVAR=\"VALUE\" works and - as i've written in the commit log - int is not possible, because svnversion might also return none int values.
-
that does it
I'm a real newbie ;)