⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctocpp.html

📁 convert C programs for use in C++ compiler environment
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html lang="en"><head><title>C To C++ Converter</title><meta http-equiv="Content-Type" content="text/html"><meta name=description content="C To C++ Converter"><meta name=generator content="makeinfo 4.0"><link href="http://texinfo.org/" rel=generator-home></head><body><h1>Table of Contents</h1><ul><li><a href="#Overview">Overview</a><li><a href="#Requirements%20&amp;%20conventions">Requirements &amp; conventions</a><li><a href="#How%20it%20works">How it works</a><li><a href="#Tools">Tools</a><ul><li><a href="#Mover">Mover</a><li><a href="#Search">Search</a></ul><li><a href="#Limitations">Limitations</a><ul><li><a href="#General%20restrictions">General restrictions</a><li><a href="#Make%20list">Make list</a><li><a href="#Make%20header">Make header</a><li><a href="#Make%20class">Make class</a></ul><li><a href="#Step%20by%20step">Step by step</a><ul><li><a href="#Moving%20the%20files">Moving the files</a><li><a href="#Making%20a%20list">Making a list</a><li><a href="#Verify%20headers">Verify headers</a><li><a href="#List%20of%20headers">List of headers</a><li><a href="#Generating%20classes">Generating classes</a><li><a href="#Propagating%20changes">Propagating changes</a></ul><li><a href="#Example">Example</a><li><a href="#Index">Index</a></ul><p><hr>Node:<a name="Top">Top</a>,Next:<a rel=next href="#Overview">Overview</a>,Previous:<a rel=previous href="#(dir)">(dir)</a>,Up:<a rel=up href="#(dir)">(dir)</a><br><p>This documentation is for: <code>ctocpp</code>, version 1.4.0<br>Mail: <a href="mailto:webmaster@scriptol.org">webmaster@scriptol.org</a>.<br>Home page: <a href="http://www.scriptol.org/">http://www.scriptol.org/</a><br>Alternate page: {No value for `ALTERNATE'}<ul><li><a href="#Overview">Overview</a>:                      What is the program. <li><a href="#Requirements%20&amp;%20conventions">Requirements &amp; conventions</a>:    Computer, OS, files, extensions. <li><a href="#How%20it%20works">How it works</a>:                  Principles of processing. <li><a href="#Tools">Tools</a>:                         Complementary scripts. <li><a href="#Limitations">Limitations</a>:                   Current state of the program. <li><a href="#Step%20by%20step">Step by step</a>:                  How to use the program, step by step. <li><a href="#Example">Example</a>:                       Test the program with an example. <li><a href="#Index">Index</a>:<br><br>Tools::<li><a href="#Mover">Mover</a>: <li><a href="#Search">Search</a>:<br><br>Limitations:<li><a href="#General%20restrictions">General restrictions</a>: <li><a href="#Make%20list">Make list</a>: <li><a href="#Make%20header">Make header</a>: <li><a href="#Make%20class">Make class</a>:<br><br>Step by step:<li><a href="#Moving%20the%20files">Moving the files</a>:             This is optional. <li><a href="#Making%20a%20list">Making a list</a>:                Build the project with -l or mklist. <li><a href="#Verify%20headers">Verify headers</a>:               This is performed by -i or mkheader. <li><a href="#List%20of%20headers">List of headers</a>:              allhead or -a do the job. <li><a href="#Generating%20classes">Generating classes</a>:           Generated by -c or mkclass. <li><a href="#Propagating%20changes">Propagating changes</a>:          mkcpp or -p achieve the work.</ul><p><hr>Node:<a name="Overview">Overview</a>,Next:<a rel=next href="#Requirements%20&amp;%20conventions">Requirements & conventions</a>,Previous:<a rel=previous href="#Top">Top</a>,Up:<a rel=up href="#Top">Top</a><br><h1>Overview</h1><p>These scripts allow to convert a C file or a whole C project to C++. They should be used mainly by someone that want to convert big files,or several projects, as some time is required to master the tool.<br><p>I have written it because I did not have found a such tool over the Net. Since I have written the project before Scriptol was available, itis written in Python and you need to install the Python interpreterto run the scripts.<br>These are simple scripts, anyway. They require C sources writtenwith a clear programming style: one statement per line isrequired in most case. Programs are available over the web to formatproperly C sources.<br>Before to start, you need to mark as "static", any variable or functionyou want not being converted to class members.<br><br><p>The scripts build classes, and global variables will become members ofthe classes, functions will become methods.<br><br><p>The command to run the program and convert a project is:<br>  ctocpp  ... some arguments ...<br><p>If you want to convert single files only, use directly each script instead.<br>They are in the c2cpp sub-directory, and under Unix, in /usr/local/c2cppunless you have installed them elsewhere. <br><br><p><hr>Node:<a name="Requirements%20&amp;%20conventions">Requirements & conventions</a>,Next:<a rel=next href="#How%20it%20works">How it works</a>,Previous:<a rel=previous href="#Overview">Overview</a>,Up:<a rel=up href="#Top">Top</a><br><h1>Requirements &amp; conventions</h1><p>For Windows, Linux and others, as Python is universal.<br>Requires the python interpreter (www.python.org) installed.<br><p>To convert your C project into a C++ one, you need for:<br>- Some files with ".c" extensions.<br>- The python interpreter installed. (Get it at www.python.org)<br>- The files below, from the current archive:<br><br><p>wstring.py pattern.py mklist.py lexer.py mover.py<br>mkclass.py allhead.py iscomp.py mkcpp.py mkheader.py<br><p>Conventions:<br>- C sources must have the .c extension.<br>- C headers must have the .h extension.<br>- a variable with the "static" modifier remain global and doesn't  become a class member (nothing to do with a C++ static member!   class attributes are declared as static from variable not  declared as static, because static for C++ class is a different  thing).<br>- If a declaration is splitted, parts must be ended by a comma.<br>  Example:<br>  mydecl(int x, <br>         int y); <br><p><hr>Node:<a name="How%20it%20works">How it works</a>,Next:<a rel=next href="#Tools">Tools</a>,Previous:<a rel=previous href="#Requirements%20&amp;%20conventions">Requirements & conventions</a>,Up:<a rel=up href="#Top">Top</a><br><h1>How it works</h1><p>The conversion process is accomplished in several stepsaccording to the options:<br>1) Use -l to build the list of all sources automatically.<br>2) Use -i to complete the header files.<br>3) Use -a to build the new list of header files.<br>4) Use -c to create the C++ classes.<br>   The name of a class is the name of the C file,   all variables and functions will be declared static.<br>   You can change manually the class produced into ".hpp" files.<br>5) Use -p to produce ".cpp" files inside which   all c functions are transformed into methods according to   the class declaration.<br>   Global variables are removed from the .cpp files.<br>   References to variables and functions are replaced by to C++   equivalents references to attributes and methods.<br><br><p>You need then a makefile to build your new C++ program. Thisdepends the compiler you use and is not covered here.<br><p><hr>Node:<a name="Tools">Tools</a>,Next:<a rel=next href="#Mover">Mover</a>,Previous:<a rel=previous href="#How%20it%20works">How it works</a>,Up:<a rel=up href="#Top">Top</a><br><h1>Tools</h1><p>Some tools here included may be used for a general purpose, type the nameof the tool without parameter to get the usage. The main ones are:<br>- mkhead.py: may be used as a standalone tool to make and update c header  files.<br>- mover.py: translates a project from a directory to another one.<br>- search.py: is a general purpose search-replace tool for strings or  identifiers.<br>Some other .py files are modules called by the named scripts.<p><hr>Node:<a name="Mover">Mover</a>,Next:<a rel=next href="#Search">Search</a>,Previous:<a rel=previous href="#Tools">Tools</a>,Up:<a rel=up href="#Top">Top</a><br><h2>Mover</h2><p>Mover - Project Translator<br><br><p>This program changes directories of files used by a C project and updatesthe include statements. Files are moved from one directory to another one,from several directories to several other ones, or from several directoriesto a single one. A text as "../" may be replaced by an absolute path andconversely.<br><p>The syntax is:<br><br><p>mover mainfile.c origpath@destpath [ origpath@destpath ]*  <br><br><p>The source file it the one that holds the main function.<br> It is followed by a list of couples:<br> original path  @  destination path<br> Example:<br> c:\gui @ t:\ide<p>All files of the project, (from which the main source is dependent),will be moved according to the couple given at command line.<br> The #include statements will be updated according to the changes indirectories.<br> The files may be grouped into an unique directory:<br> mover mainfile.c \lister@\newlister \gui@\newlister <br><p>Warnings:<br>- Under Windows the project and mover must stand on the same disk.<br>- Take care to the \ and / symbols in paths, according to the  operating system.<br><p><hr>Node:<a name="Search">Search</a>,Next:<a rel=next href="#Limitations">Limitations</a>,Previous:<a rel=previous href="#Mover">Mover</a>,Up:<a rel=up href="#Top">Top</a><br><h2>Search</h2><p>Search and Replace<br><br><p>This program searches and (optionaly) replaces either anidentifier or a string, in a file, or in a set of files.<br> Regular expressions are not supported.<br><br><p>This searches texts in a file, or in a set of files matching a pattern.  The pattern may contain wilcards which are those of MS-DOSand Unix: * and ?<br><p>The search can be performed case-sensitive or not.  One can search for identifiers in source,or any string in any ASCII text.<br><br><p>By changing the "delimiters" string in the source, one canchange definition of what is identifier.<br> The current setting doesn't include "#" among delimiters.<br><br><p>The syntax is:<br><br><p>search [options] searching [replacing] filename<br><br><p>1) Filename may contain wildcards, example:<br>  *.c<br>  name.*<br>  name?.py<br><br><p>2) If the replacing text is omitted, a simple search is performed.<br><br><p>3) Options are those:<br><br><p>-i     case-insensitive for searched identifier.<br>-w     Windows mode, case-insensitive for filename. Defaults are case-sensitive.<br>-c     search for identifiers in code. The default is search for strings.<br>       The string may contain space and must be inclosed inside "".        Space is a delimiter, therefore identifiers always are single words.<br>-q     quiet mode, don't display when replacing. Default is display.<br>-h     displaying help.<br>-v     displaying version.<br><br><p>4) Multiple options are packed into a single string as:<br>        -ifcq<br><br><p>Removing strings from a text file may be performed by replacingthem by a blank space. Example:<br>    search -w "searched" " " filename<p><hr>Node:<a name="Limitations">Limitations</a>,Next:<a rel=next href="#General%20restrictions">General restrictions</a>,Previous:<a rel=previous href="#Search">Search</a>,Up:<a rel=up href="#Top">Top</a><br><h1>Limitations</h1><ul><li><a href="#General%20restrictions">General restrictions</a>: <li><a href="#Make%20list">Make list</a>: <li><a href="#Make%20header">Make header</a>: <li><a href="#Make%20class">Make class</a>: </ul><p><hr>Node:<a name="General%20restrictions">General restrictions</a>,Next:<a rel=next href="#Make%20list">Make list</a>,Previous:<a rel=previous href="#Limitations">Limitations</a>,Up:<a rel=up href="#Limitations">Limitations</a><br><h2>General restrictions</h2><p>- The program assumes the C code is written with a good  programming style. What is hard to read for an human will  be hard to parse for the program too.<br><br><p>- Define statements used in code must be moved to header  file, they are processed only in some cases by the scripts.<br><br>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -