Because the Uclinux kernel is a behemoth, to avoid being hit in the first place, you decide to comment out all the code first. At the same time, however, to preserve the dependencies between the individual files, you must preserve statements such as #include. Consider that uclinux is a macro definition to control the implementation of a variety of functions, and the macro definition will almost not cause any trouble to the porting, so also retains the #if #define这样的语句.
The following is a small piece of code written by yourself, used to achieve the above function, under the VS2005 can be used.
Hprocess.cpp: Defines the entry point for a console application.
//
#include "stdafx.h"
#include <windows.h>
#include <fstream>
#pragma warning (disable:4996)
using namespace Std;
void Changefile (char* pFile)
{
Char line[10000];
Char* p, C;
printf ("%s processing ..."). ", PFile);
Ifstream f (pFile);
Ofstream O ("tmp.h");
c = Pfile[strlen (PFile)-1];
if (c = = ' C ' | | c = = ' C ')
o << "#include <config.h>" << Endl;
BOOL Bisdefine = false;
Todo
{
F.getline (line, 10000);
if (bisdefine)
{
if (Line[strlen (line)-1]!= '//')
Bisdefine = false;
}
Else
{
if (line, "#define") && Line[strlen (line)-1] = = '//') strstr
Bisdefine = true;
Else
{
p = line;
while (*p = = ") p++;
if (*p!= ' # ')
o << "//";
}
}
o << line << Endl;
}while (!f.eof ());
F.close ();
O.close ();
CopyFile ("Tmp.h", PFile, FALSE);
printf ("done!/n");
}
int Processfile (char* pdir)
{
Win32_find_data Findfiledata;
HANDLE hfind = Invalid_handle_value;
Char Dirspec[max_path]; Directory specification
Char Nextpath[max_path]; Directory specification
DWORD dwerror;
printf ("Target directory is%s./n", pdir);
strcpy (Dirspec, Pdir);
strcat (Dirspec, "*");
Hfind = FindFirstFile (Dirspec, &findfiledata);
if (hfind = = INVALID_HANDLE_VALUE)
{
printf ("Invalid file handle. Error is%u/n ", GetLastError ());
Return (-1);
}
Else
{
Todo
{
if (strcmp (Findfiledata.cfilename, ".") = = 0 | | strcmp (findfiledata.cfilename, "...") = = 0) continue;
if (Findfiledata.dwfileattributes & File_attribute_directory)
{
if (strcmp (Findfiledata.cfilename, "vs2005") = = 0) continue;
strcpy (Nextpath, Pdir);
strcat (Nextpath, findfiledata.cfilename);
strcat (Nextpath, "//");
Processfile (Nextpath);
}
Else
{
int len = strlen (findfiledata.cfilename);
if (findfiledata.cfilename[len-2] = = '. ' && (findfiledata.cfilename[len-1] = = ' H ' | | Findfiledata.cfilename[len-1] = = ' H ' | | Findfiledata.cfilename[len-1] = = ' C ' | | Findfiledata.cfilename[len-1] = = ' C ')
{
strcpy (Nextpath, Pdir);
strcat (Nextpath, findfiledata.cfilename);
Changefile (Nextpath);
}
}
}while (FindNextFile (Hfind, &findfiledata)!= 0);
dwerror = GetLastError ();
FindClose (hfind);
if (dwerror!= error_no_more_files)
{
printf ("FindNextFile error.") Error is%u/n ", dwerror);
Return (-1);
}
}
return (0);
}
int _tmain (int argc, _tchar* argv[])
{
Processfile ("d://uc2008//linux-2.6.x//");
printf ("all OK");
GetChar ();
return 0;
}
Of course, you should set the correct path before using it.
However, there is a bug in this code, which is the handling of line breaks. Because the files under Linux are different from the file line breaks under Windows, if the #define statement has a newline, it is likely that the correct results will not be obtained and need to be noted when porting.