From owner-freebsd-bugs@FreeBSD.ORG Mon Mar 3 19:00:05 2014 Return-Path: Delivered-To: freebsd-bugs@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 71BE37D4 for ; Mon, 3 Mar 2014 19:00:05 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4609FE23 for ; Mon, 3 Mar 2014 19:00:05 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s23J047S059320 for ; Mon, 3 Mar 2014 19:00:04 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s23J04m3059319; Mon, 3 Mar 2014 19:00:04 GMT (envelope-from gnats) Date: Mon, 3 Mar 2014 19:00:04 GMT Message-Id: <201403031900.s23J04m3059319@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: oliver Subject: Re: bin/186294: calendar(1): calendar' preprocessor process comments X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list Reply-To: oliver List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Mar 2014 19:00:05 -0000 The following reply was made to PR bin/186294; it has been noted by GNATS. From: oliver To: bug-followup@FreeBSD.org, romain@FreeBSD.org Cc: Subject: Re: bin/186294: calendar(1): calendar' preprocessor process comments Date: Mon, 3 Mar 2014 19:54:02 +0100 --MP_/PvNvoarowC1Efp0H7PxZt== Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Content-Disposition: inline okay, here is my final patch for this issue and issue bin/184648 I modified my original patch for removing multiple inline comments. I tested it against an original version of calendar and did not find any additional issues. Greetings, Oliver --MP_/PvNvoarowC1Efp0H7PxZt== Content-Type: text/plain Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=patch3.txt --- /usr/src/usr.bin/calendar/calcpp.c 2014-03-03 19:22:25.000000000 +0100 +++ calcpp.c 2014-03-03 19:19:37.000000000 +0100 @@ -52,6 +52,8 @@ static void pushfp(FILE *fp); static FILE *popfp(void); static int tokenscpp(char *buf, char *string); +static void striptags(char *buf, int size, const char *ts, const char *te); +static void rmcomments(char *buf, int size); #define T_INVALID -1 #define T_INCLUDE 0 @@ -93,6 +95,7 @@ return(fp); } } + rmcomments(buf,size); switch (tokenscpp(buf, name)) { case T_INCLUDE: *buf = '\0'; @@ -230,3 +233,48 @@ return (1); return (0); } + + + + + +static void +rmcomments(char *buf, int size) +{ + striptags(buf,size,"/*", "*/"); +} + + +static void +striptags(char *buf, int size, const char *ts, const char *te) +{ + static int cf = 0; /* carry flag */ + int te_len = strlen(te); /* end tag length */ + char *idx_ts = strstr(buf, ts); + char *idx_te = strstr(buf, te); + if (idx_ts == NULL && idx_te == NULL) { + if (cf == 0) + return; + else + *buf='\0'; + } else if (idx_ts != NULL && idx_te == NULL) { + if (cf == 0) { + cf = 1; + buf = idx_ts; + } + *buf = '\0'; + } else if (idx_ts != NULL && idx_te != NULL && cf == 0) { + if (idx_ts < idx_te) { + memmove(idx_ts, idx_te+te_len, + (buf+size)-(idx_ts+te_len)); + } else { + buf = idx_ts; + } + striptags(buf,size,ts,te); + } else if (idx_ts == NULL && idx_te != NULL && cf == 1) { + memmove(buf, idx_te+te_len, + (buf+size)-(idx_te+te_len)); + cf = 0; + } + return; +} --MP_/PvNvoarowC1Efp0H7PxZt==--