Uclinux-2008r1-rc8 (bf561) to VDSP5 Transplantation (2): Code comment

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.