C소수 중에서 주석 // 을 /* ~ */ 로 변경하는 쉬운 방법

neohwang의 이미지

안녕하세요..

급히 도움 좀 부탁드립니다.

C로 작성된 소스코드 인데요.. 주석이 // 과 /*~*/로 섞여서 작성되어 있습니다.

IBM-AIX에서 cc로 컴파일 할려고 하니.. // 형식의 주석이 안 먹히더라구요..

그래서.. // 형식의 주석을 /* ~ */로 변경할려고 하는데요..

소스파일도 많고, 크기도 커서 너무 어렵네요..

이것을 어떻게 손쉽게 변경하는 방법 없나요?

현재 edit plus로 나름대로 정규식을 주어서 하는데.. 제대로 안되네요...

좋은 방법좀 부탁드립니다.

감사합니다.

cppig1995의 이미지

C99 호환 컴파일러를 사용하시거나, C++ 컴파일러를 사용하셔도 됩니다.
하지만 꼭 IBM-AIX cc로 컴파일해야 하는 경우...
저도 잘 모르겠습니...(*shot*)

Real programmers /* don't */ comment their code.
If it was hard to write, it should be /* hard to */ read.

lnyarl의 이미지

그냥 때려 박으니 되는군요-_-

s/\/\/\(.*\)$/\/\* \1 \*\//g

vi에서의 정규표현식입니다.
'//'부터 줄의 끝까지를 지정한다음에 그 부분을 /* ~ */로 감쌌습니다.

neohwang의 이미지

완벽하진 않습니다만.. 이렇게 우선 프로그램 만들어서 해결했습니다.

테스트 해본 결과 따옴표 속에 들어가는 주석에서는 문제가 발생합니다.

여러 소스코드중 한라인에서만 다행이 발생하여.. 이 프로그램을 돌린후 그 부분만 손으로 했습니다..

참고삼아 올려드립니다.

#include <stdio.h>
 
int main(int argc, char *argv[])
{
	FILE *in;
	FILE *out;
	char backup[300];
	char buff[5000];
	char *s;
	char *p;
	char *t;
	char *q;
	int i,len;
	int star = 0;
 
	if(argc != 2)
	{
		printf("error argument\n");
		return 0;
	}
 
 
	// file backup
	if((in=fopen(argv[1],"rb"))==NULL)
	{
		printf("error read file open\n");
		return 0;
	}
 
	sprintf(backup,"%s.bak",argv[1]);
	if((out=fopen(backup,"wb"))==NULL)
	{
		printf("error write file open\n");
		fclose(in);
		return 0;
	}
 
	while(fgets(buff,sizeof(buff), in) != NULL)	fputs(buff,out);
	fclose(out);
	fclose(in);
 
 
	// 작업시작
	if((in=fopen(backup,"rb"))==NULL)
	{
		printf("error read file open\n");
		return 0;
	}
 
	if((out=fopen(argv[1],"wb"))==NULL)
	{
		printf("error write file open\n");
		fclose(in);
		return 0;
	}
 
 
 
 
 
	while(fgets(buff,sizeof(buff),in) != NULL)
	{
		s = buff;
 
cmt :
 
		// "*/" 처리
		if(star == 1)
		{
			len = strlen(s);
			p = strstr(s,"*/");
			if(!p)
			{
				fputs(s,out);
				continue;				
			}
			for(i=0 ; i<len ; i++)
			{
				fputc((int)(*(s+i)), out);
				if(p == s+i)
				{
					fputc((int)(*(s+i+1)), out);
					s = s+i+2;
					star = 0;
					break;
				}
			}
		}
 
		// "/*" 처리
		p = strstr(s,"//");
		t = strstr(s,"/*");
 
		if((p && t&& p>t) || t && !p )
		{
			star = 1;
			len = strlen(s);
			q = strstr(t,"*/");
			if(q)
			{
				for(i=0 ; i<len ; i++)
				{
					fputc((int)(*(s+i)), out);
					if(q == s+i)
					{
						fputc((int)(*(s+i+1)), out);
						s = s+i+2;
						goto cmt;
					}
 
				}	
			}
 
			fputs(s,out);
			continue;
		}
 
		// "//"처리
		if(!p)
		{
			fputs(s,out);
			continue;
		}
		len = strlen(s);
		for(i=0 ; i<len ; i++)
		{
			if(p == s+i)	fputs("/*", out);
			if(*(s+i)== 0x0a || *(s+i) == 0x0d)
			{
				fputs("*/\n", out);
				continue;
			}
			fputc((int)(*(s+i)), out);
		}
	}
 
	fclose(out);
	fclose(in);
 
	printf("ok :: %s\n", argv[1]);
 
	return 0;
}
neohwang의 이미지

소스코드 어떻게 올리죠?

gamdora의 이미지

<code></code>로 감싸시면 됩니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.