CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pre Processor Directive: __FILE__

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Freddie



Joined: 06 Sep 2003
Posts: 49

View user's profile Send private message

Pre Processor Directive: __FILE__
PostPosted: Fri Sep 16, 2005 1:47 pm     Reply with 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). 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

View user's profile Send private message

PostPosted: Fri Sep 16, 2005 2:28 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 16, 2005 2:37 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 16, 2005 2:52 pm     Reply with quote

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. Confused


Humberto
Ttelmah
Guest







PostPosted: Fri Sep 16, 2005 3:09 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Sep 16, 2005 3:21 pm     Reply with quote

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







PostPosted: Fri Sep 16, 2005 4:08 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 19, 2005 8:28 am     Reply with quote

Thanks guys this is really helpful.

I wish there that __FILE__ was more like this:
__FILE_NAME_WITH_OUT_PATH__

Laughing Cool Shocked Shocked
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 19, 2005 8:40 am     Reply with quote

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








PostPosted: Mon Sep 19, 2005 9:03 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 19, 2005 9:06 am     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Sep 19, 2005 1:25 pm     Reply with quote

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. Wink Very Happy
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Mon Sep 19, 2005 2:05 pm     Reply with quote

Nope, I just don't like for the field guys to come back and tell me that they found a bug Laughing Code reviews and software verification tests help reduce those "added features".
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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