View previous topic :: View next topic |
Author |
Message |
Freddie
Joined: 06 Sep 2003 Posts: 49
|
Pre Processor Directive: __FILE__ |
Posted: Fri Sep 16, 2005 1:47 pm |
|
|
I'm using the __FILE__ pre processor directive in my code to display to the user the file name of the code they are running, soy they know which version of the software is running (code below). The issue is that my file name path is apparently too long and the complier (v3.233) complains that the name is too long. If I move the file to my c:\ directory it works fine (because that path is much shorter).
Does anyone have a work around or slick way to extract just the file name from the full path? I need to leave the souce files in the dirctories they are in, for sanity's sake. Thanks.
Code: |
fprintf(serialPC, "%S\r\n", __FILE__);
|
|
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Sep 16, 2005 2:28 pm |
|
|
Quote: |
fprintf(serialPC, "%S\r\n", __FILE__);
|
After the string comma fprintf is expecting a value, __FILE__ is an identifier.
Try this way:
fprintf(serialPC, __FILE__);
Humberto |
|
|
Freddie
Joined: 06 Sep 2003 Posts: 49
|
|
Posted: Fri Sep 16, 2005 2:37 pm |
|
|
Humberto,
Thanks. It's not that I can't get __FILE__ to work. It's that the file path/name is too long and causes an error, if I do it the way I showed, or the way you suggested.
Code: | *** Error 6 "C:\Documents and Settings\blah\My Documents\PIC Code\CODE\blahblahblah\blahblahblah\blahblahblahblahblah.c" Line 108(19,20): String too long fprintf |
I guess the questions is: Is there a way to extract just the file name from __FILE__ and not the entire path I need to do this as a directive, not programitically, which would use up too much RAM.
. |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Fri Sep 16, 2005 2:52 pm |
|
|
I know what you mean, __FILE__ take the full path.
Work around this? move your source file to/close to the main root unless another better idea.
Humberto |
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 16, 2005 3:09 pm |
|
|
It'll cost you quite a lot of ROM (since the whole filename will be held in ROM once you use it), but you could probably do it with something like:
Code: |
int8 len;
int8 ctr;
clrcount() {
len=0;
ctr=0;
}
count(int8 chr) {
++len;
if (chr=='\\') ctr=len;
}
output(int8 chr) {
if (ctr) --ctr;
else putc(chr);
}
//Then when you want the final filename, use:
clrcount();
count(__FILE__);
len=ctr;
output(__FILE__);
|
This takes advantage of the CCS shortcut, where a function that handles an int8, if called with a constant string will be repeatedly called with the successive characters in the string. Clrcount, sets two global counters to zero. Then 'count', counts along the string, and whenever a file name seperator is found, moves the second counter to point to this. Hence it should return with the position of the last filename seperator. I then call the output routine. This does exactly the same 'walk', but only starts outputing characters to the putc, once the address of the last seperator is passed.
It should give just the filename!.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Sep 16, 2005 3:21 pm |
|
|
While you were doing yours, I was doing one too.
Might as well post it. Pretty much the same idea.
This program just proves that I can find the backslash
character right before the filename. If I can find that,
then I have the filename.
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
const int8 pathname[] = __FILE__;
//======================================
main(void)
{
int8 index;
index = 0;
while(pathname[index++]);
index -=2;
while(pathname[index--] != '\\');
index++;
printf("index = %d\n\r", index);
printf("index char = %c\n\r", pathname[index]);
while(1);
} |
|
|
|
Ttelmah Guest
|
|
Posted: Fri Sep 16, 2005 4:08 pm |
|
|
I think your idea of declaring the pathname, is probably far better (I suspect mine will store it twice). However I think finding the seperator 'on the way' as I do it, is neater.
I suspect a combination of the two routines would probably be the 'best' way of doing it.
Some sentence involving 'minds' and 'alike' applies here. :-)
Best Wishes |
|
|
Freddie
Joined: 06 Sep 2003 Posts: 49
|
|
Posted: Mon Sep 19, 2005 8:28 am |
|
|
Thanks guys this is really helpful.
I wish there that __FILE__ was more like this:
__FILE_NAME_WITH_OUT_PATH__
|
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 19, 2005 8:40 am |
|
|
Quote: | I'm using the __FILE__ pre processor directive in my code to display to the user the file name of the code they are running, soy they know which version of the software is running (code below). |
Just declare a const string with you firmware version and use that |
|
|
Guest
|
|
Posted: Mon Sep 19, 2005 9:03 am |
|
|
Quote: | Just declare a const string with you firmware version and use that |
I've done this in the past, but I forget to update the const string with the new firmware version, then I have several different versions floating around with the same firmware version number. Gets confusing. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 19, 2005 9:06 am |
|
|
Anonymous wrote: | Quote: | Just declare a const string with you firmware version and use that |
I've done this in the past, but I forget to update the const string with the new firmware version, then I have several different versions floating around with the same firmware version number. Gets confusing. |
Then create yourself a checklist of things that you need to do in order to release your firmware. Do you even do a test on it? Part of the test could include the firmware revision. |
|
|
Freddie
Joined: 06 Sep 2003 Posts: 49
|
|
Posted: Mon Sep 19, 2005 1:25 pm |
|
|
Quote: | Then create yourself a checklist of things that you need to do in order to release your firmware. Do you even do a test on it? Part of the test could include the firmware revision. |
Mark, You must be in "management" or from the "Quality Assurance" department. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Sep 19, 2005 2:05 pm |
|
|
Nope, I just don't like for the field guys to come back and tell me that they found a bug Code reviews and software verification tests help reduce those "added features". |
|
|
|