|
|
View previous topic :: View next topic |
Author |
Message |
mbge5amw
Joined: 13 Dec 2004 Posts: 15 Location: Yorkshire, UK
|
changing format of __DATE__ |
Posted: Wed Jul 19, 2006 3:26 am |
|
|
Is there a better way of doing this:
I wish to have a string containing the compile date in dd/mm/yy format.
I have written a very Heath Robinson routine that takes __DATE__ in its format 17-Jul-06 and changes it to 17/07/06 but this routine uses up valuable ROM and RAM.
Is there any way of getting this conversion to be performed automatically at compile time?
TIA
Andy
Code: |
void generate_version( void )
{
int8 local_date_t;
int8 local_date_u;
int8 local_month_t;
int8 local_month_u;
int8 local_year_t;
int8 local_year_u;
strcpy (motor_compile_date,__DATE__);
local_date_t = motor_compile_date[0];
local_date_u = motor_compile_date[1];
local_year_t = motor_compile_date[7];
local_year_u = motor_compile_date[8];
switch(motor_compile_date[3])
{
case 'J':
switch(motor_compile_date[4])
{
case 'a': //jan
local_month_t = '0';
local_month_u = '1';
break;
case 'u':
switch(motor_compile_date[5])
{
case 'n': //jun
local_month_t = '0';
local_month_u = '6';
break;
case 'l': //jul
local_month_t = '0';
local_month_u = '7';
break;
}
break;
}
break;
case 'F': // feb
local_month_t = '0';
local_month_u = '2';
break;
case 'M':
switch(motor_compile_date[4])
{
case 'a':
switch(motor_compile_date[5])
{
case 'r': //mar
local_month_t = '0';
local_month_u = '3';
break;
case 'y': //may
local_month_t = '0';
local_month_u = '5';
break;
}
break;
}
break;
case 'A':
switch(motor_compile_date[4])
{
case 'p': //apr
local_month_t = '0';
local_month_u = '4';
break;
case 'u': //aug
local_month_t = '0';
local_month_u = '8';
break;
}
break;
case 'S': // sep
local_month_t = '0';
local_month_u = '9';
break;
case 'O': // oct
local_month_t = '1';
local_month_u = '0';
break;
case 'N': // nov
local_month_t = '1';
local_month_u = '1';
break;
case 'D': // dec
local_month_t = '1';
local_month_u = '2';
break;
}
motor_version[0]='v';
motor_version[1]='e';
motor_version[2]='r';
motor_version[3]=':';
motor_version[4]=' ';
motor_version[5] = ((local_date_t & 0x0f) << 4) + (local_date_u & 0x0f);
motor_version[6] = ((local_month_t & 0x0f) << 4) + (local_month_u & 0x0f);
motor_version[7] = ((local_year_t & 0x0f) << 4) + (local_year_u & 0x0f);
}
|
|
|
|
Ttelmah Guest
|
|
Posted: Wed Jul 19, 2006 6:26 am |
|
|
Unfortunately, I can't think of any truly 'better' way of doing this. The problem is that '__date__' is a pre-processor defintion, replaced as a constant string with the 'date'. All string comparisons/manipulations, are C operators, not preprocessor operators.
Personally, given that the 'date', is the compile date, and not something that should change in normal use, I'd do the following:
Firstly, just define your own constant at the start of the source, something like:
#define mdate 17/07/06
and make a point for now of changing this whenever you re-compile.
Then secondly, ask CCS, to consider generating a new '__numdate__' definition to the compiler, or a flag to switch the format of the 'date data'. This should be pretty easy for them to do, and could be of use to other people.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|