Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I extract all strings from a C file?

Status
Not open for further replies.

ddeham

Programmer
Sep 30, 2005
11
Hi,

I need to get my C program translated from English into Spanish. In order to do so, I need to extract all of the strings out of my 35,000 lines of C code into a separate file so I can send it off to be translated. How can I quickly and easily extract the strings out of a C code file? I tried using xstr, but it didn't extract all of the strings. It left a lot of them in the source file. Please help!

Thanks,

Dan
 
> How can I quickly and easily extract the strings out of a C code file?
Use xstr of course, after you've fixed your code to be xstr friendly.

I can only guess from your vague information "It left a lot of them in the source file" what you're seeing.

Why don't you post a 5-line example source file which shows two examples of strings, one which xstr finds, and one which xstr doesn't.

My guess is that the strings it misses are buried inside macros, or other horrors, and xstr wisely leaves them alone as being "too difficult".



--
 
Here's a code fragment where the strings weren't extracted:

Code:
// Write new flash variables
if (SaveUserParameters(&mds, sizeof(mds)) != 0)
    sprintf(silentstring, "Programmed correctly");
else
    sprintf(silentstring, "Programming failed");
SilentHistoryQueue();
WriteConfigRecord();
strcpy(statusstring, "ReBooting - Wait 5 seconds - Then Refresh");

Here's a code fragment where the strings were extracted:
Code:
sprintf(silentstring, (&xstr[1644]), MotorCurrent, Old_Motor_Current);
SilentHistoryQueue();
sprintf(FiveSecString, (&xstr[1714]));
FiveSecTime = TimeTick;
FiveSecHistoryQueue();
 
Easiest way is to write a program to do it.

for each file
1) Ignore all // and /* */ comments
2) Look for ". When you find another " which is not preceded by \, save it in a file

It is actually easier than you think. Probably take half a day to write (the most difficult part is navigating the directory structure and getting all the source files) and a few minutes to run.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top