Comment Conversion--c comments to standard C + + annotations

Source: Internet
Author: User
Tags assert

http://blog.csdn.net/fujinlong520/article/details/46573445 Annotation Conversion--c++ comments to standard C language annotations

Directly on the code:

<span style= "color: #ff0000;" > #include <stdio.h> #include <errno.h> #include <assert.h> typedef enum STATE{SUCCESS,//Conversion Success File_ erroe,//file Error no_match,//mismatch other,//other error}state;typedef enum tag{tag_begin,//in C comment paragraph tag_end,//c comment end}tag; #pragma Warning (disable:4996) state Annotationconvert (file* inFile, file* outFile) {tag tag = Tag_end;char Firstch, secondch; ASSERT (InFile), assert (outFile);d O{firstch = fgetc (inFile), switch (firstch) {case '/': SECONDCH = fgetc (inFile); if ( SECONDCH = = ' * ' && tag = = tag_end) {FPUTC ('/', outFile); FPUTC ('/', outFile); tag = Tag_begin;} else if (SECONDCH = = ' *  ' && tag! = tag_end) {FPUTC (', outFile); FPUTC (', outFile); tag = Tag_begin;}   else if (secondch = = '/') {char nextch;                                           FPUTC ('/', outFile); FPUTC ('/', outFile);       do {nextch = fgetc (inFile);                        FPUTC (Nextch, outFile);   }while (nextch! = ' \ n ' && nextch! = '/'); if (Nextch = ='/') {char next;next = fgetc (inFile); if (next = = '/' | |            Next = = ' * ') {FPUTC (', outFile); FPUTC (', outFile); }}//tag = Tag_end; } ELSE{FPUTC (Firstch, outFile); FPUTC (SECONDCH, outFile);} Break  Case ' \ n '://fputc (' \ n ', outFile);                FPUTC (Firstch, outFile);                    if (tag = = Tag_begin)//Multiline comment problem {FPUTC ('/', outFile);                FPUTC ('/', outFile); }break;case ' * ': SECONDCH = fgetc (InFile), if (secondch = = '/') {char next = fgetc (InFile); if (next! = ' \ n ' && next!) = EOF) {FPUTC (' \ n ', outFile), if (next! = '/') {FPUTC (next,outfile);} tag = Tag_begin;} if (next = = EOF) {firstch = EOF;}                       if (next = = '/')//continuous annotation problem {//FPUTC (', outFile);                         FPUTC (', outFile);     FPUTC (' \ n ', outFile);//firstch = next;        Fseek (InFile,-1, seek_cur);//Return to previous character//tag = Tag_begin;} tag = tag_end;} else if (secondch! = '/') {FPUTC (firstch,outfile); }ELSE{FPUTC (Firstch, outFile); FPUTC (SECONDCH, outFile);} BREAK;DEFAULT:FPUTC (Firstch, outFile); break;}} while (firstch! = EOF); if (tag = = tag_end) {return SUCCESS;} Else{return No_match;}} int Startconvert () {state s;const char* infilename = "input.c"; const char* outfilename = "output.c"; file* inFile = fopen (Infilename, "R"); file* outFile = fopen (Outfilename, "w"); if (inFile = = NULL) {return file_erroe;} if (OutFile = = NULL) {fclose (inFile); return File_erroe;} s = Annotationconvert (InFile, outFile); fclose (inFile); fclose (outFile); return s;} int main () {state ret = Startconvert (); if (ret = = SUCCESS) {printf ("Conversion succeeded \ n");} else if (ret = = No_match) {printf ("does not match \ n");} else if (ret = = File_erroe) {printf ("File Error:%d\n", errno);} else{printf ("Other error:%d\n", errno);} return 0;} </span>


infile file


1. General Information
/* int i = 0; */


2. Line break issues
/* int i = 0; */Int j = 0;


3. Matching issues
/*int i = 0;/*xxxxx*/


4. Multi-line annotation issues
/*
int i=0;
int j = 0;
int k = 0;
*/int k = 0;


5. Continuous annotation Issues
/**//**/


6. Continuous **/problem
/***/


7.c++ Comment Questions
/*xxxxxxxxxxxx*/

8.aaa
Aa



Converted files:


1. General Information
int i = 0;
2. Line break issues
int i = 0;
int j = 0;


3. Matching issues
int i = 0; Xxxxx
4. Multi-line annotation issues
//
int i=0;
int j = 0;
int k = 0;
//
int k = 0;


5. Continuous annotation Issues
//
//
6. Continuous **/?? Problem
//*/


7.c++ Comment Questions
/xxxxxxxxxxxx
8.aaa
Aa?

Comment Conversion--c comments to standard C + + annotations

Related Article

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.