From owner-freebsd-bugs@FreeBSD.ORG Mon Sep 14 03:00:15 2009 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id F3275106566C for ; Mon, 14 Sep 2009 03:00:15 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id C45718FC15 for ; Mon, 14 Sep 2009 03:00:15 +0000 (UTC) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.14.3/8.14.3) with ESMTP id n8E30FaS043406 for ; Mon, 14 Sep 2009 03:00:15 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.3/8.14.3/Submit) id n8E30F0m043405; Mon, 14 Sep 2009 03:00:15 GMT (envelope-from gnats) Resent-Date: Mon, 14 Sep 2009 03:00:15 GMT Resent-Message-Id: <200909140300.n8E30F0m043405@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Yoshihiro Ota Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CEB7B1065694 for ; Mon, 14 Sep 2009 02:55:06 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21]) by mx1.freebsd.org (Postfix) with ESMTP id B86D78FC1A for ; Mon, 14 Sep 2009 02:55:06 +0000 (UTC) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.14.3/8.14.3) with ESMTP id n8E2t6Jn068779 for ; Mon, 14 Sep 2009 02:55:06 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.14.3/8.14.3/Submit) id n8E2t65H068778; Mon, 14 Sep 2009 02:55:06 GMT (envelope-from nobody) Message-Id: <200909140255.n8E2t65H068778@www.freebsd.org> Date: Mon, 14 Sep 2009 02:55:06 GMT From: Yoshihiro Ota To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: misc/138797: [patch] \newif command support to latex2rtf X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Sep 2009 03:00:16 -0000 >Number: 138797 >Category: misc >Synopsis: [patch] \newif command support to latex2rtf >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Sep 14 03:00:15 UTC 2009 >Closed-Date: >Last-Modified: >Originator: Yoshihiro Ota >Release: 7.1-RELEASE >Organization: >Environment: FreeBSD xxx 7.1-RELEASE-p6 FreeBSD 7.1-RELEASE-p6 #465 r188634M: Wed Jun 17 12:19:08 EDT 2009 xxx:/usr/obj/usr/src/sys/GENERIC i386 >Description: \newif LaTeX command is supported with this patch. The patch is also sent to the authors but yet not been replied. By the way, I didn't test the patch using the port, print/latex2rtf. It needs to be renamed to put it under "files", at least. >How-To-Repeat: >Fix: Patch attached with submission follows: diff --git a/commands.c b/commands.c index 4e442a9..60b1bfe 100644 --- a/commands.c +++ b/commands.c @@ -646,6 +646,8 @@ static CommandArray PreambleCommands[] = { {"latextortftrue",CmdIgnore,1}, {"latextortffalse",CmdIgnore,0}, {"newif",CmdNewif,0}, + {"else",CmdElse,0}, + {"fi",CmdFi,0}, {"title", CmdTitle, TITLE_TITLE}, {"author", CmdTitle, TITLE_AUTHOR}, {"and", CmdAnd, 0}, diff --git a/convert.c b/convert.c index bf6721a..c46c4c4 100644 --- a/convert.c +++ b/convert.c @@ -828,5 +828,8 @@ returns: success or not if (TryVariableIgnore(cCommand)) return; + if (TryConditionSet(cCommand)) + return; + diagnostics(WARNING, "Unknown command '\\%s'", cCommand); } diff --git a/funct1.c b/funct1.c index 4c7af8a..69c17c2 100644 --- a/funct1.c +++ b/funct1.c @@ -1440,18 +1440,136 @@ void CmdIgnoreLet(int code) free(s); } +typedef struct iftag { + char *if_name; /* LaTeX newif name without \newif\if */ + int is_true; /* if this name is set to true */ + int did_push_env; /* keep track which of 'if' or 'else' is true */ +} IfName; + +/* ifCommands maintains all the \newif CONDitions */ +static int iIfNameCount = 0; /* number of if condition names */ +static IfName ifCommands[100] = { + {NULL, 0} +}; + +/* ifEnvs/iIfDepth is used to handle nested conditions. */ +static IfName ifEnvs[100]; +static int iIfDepth = 0; /* number of nested if conditions */ + void CmdNewif( /* @unused@ */ int code) /****************************************************************************** - purpose : ignore \newif\ifsomething + purpose : initiate handing of \newif\ifsomething + : \newif\ifSOMETHING + : => create a new ENTRY with SOMETHING with false + : \SOMETHINGfalse + : => set SOMETHING to false + : \SOMETHINGtrue + : => set SOMETHING to true + : \ifSOMETHING + : => if SOMETHING is true, process it. + : \else + : => if SOMETHING is NOT true, process it. + : \fi ******************************************************************************/ { char *s; s = getSimpleCommand(); diagnostics(4,"discarding %s",s); + if(strncmp(s, "\\if", 3) == 0) + { + int i; + for(i = 0; i < iIfNameCount; i++) + { + if(strcmp(ifCommands[i].if_name, &s[3]) == 0) + break; + } + if(i < iIfNameCount) + diagnostics(WARNING, "Duplicated \\newif command '%s'", s); + else + { + ifCommands[iIfNameCount].if_name = strdup(&s[3]); + ifCommands[iIfNameCount].is_true = FALSE; + ifCommands[iIfNameCount].did_push_env = FALSE; + iIfNameCount++; + } + } + else + diagnostics(WARNING, "Mystery \\newif command '%s'", s); if (s) free(s); } +void CmdElse( /* @unused@ */ int code) +{ + iIfDepth--; + if(ifEnvs[iIfDepth].did_push_env) /* if-closure is true, so else is false */ + { + fprintRTF("\" }"); + ifEnvs[iIfDepth].did_push_env = FALSE; + } + else /* if-closure is false, so else is true */ + { + ifEnvs[iIfDepth].did_push_env = TRUE; + fprintRTF("{\\v \""); + } + iIfDepth++; +} + +void CmdFi( /* @unused@ */ int code) +{ + iIfDepth--; + if(ifEnvs[iIfDepth].did_push_env) + { + fprintRTF("\" }"); + } +} + +bool TryConditionSet(char *command) +{ + int i; + if(strncmp(command, "if", 2) == 0) + { + for(i = 0; i < iIfNameCount; i++) + { + if(strcmp(&command[2], ifCommands[i].if_name) == 0) + { + ifEnvs[iIfDepth] = ifCommands[i]; + if(ifCommands[i].is_true) + { + /* no-op */; + } + else + { + ifEnvs[iIfDepth].did_push_env = TRUE; + fprintRTF("{\\v \""); + } + iIfDepth++; + return TRUE; + } + } + } + for(i = 0; i < iIfNameCount; i++) + { + char *s = ifCommands[i].if_name; + char *t = strdup_together(s, "true"); + char *f = strdup_together(s, "false"); + if(strcmp(command, t) == 0) + { + ifCommands[i].is_true = TRUE; + free(t); free(f); + return TRUE; + } + else if(strcmp(command, f) == 0) + { + ifCommands[iIfNameCount].is_true = FALSE; + free(t); free(f); + return TRUE; + } + free(t); free(f); + } + return FALSE; +} + void CmdQuad(int kk) /****************************************************************************** diff --git a/funct1.h b/funct1.h index 2e87415..f7ee63f 100644 --- a/funct1.h +++ b/funct1.h @@ -176,4 +176,8 @@ void CmdRule(int code); void CmdTolerateEnviron(int code); void CmdIflatextortf(int code); void CmdNewif(int code); +void CmdElse(int code); +void CmdFi(int code); void CmdAppendix(int code); + +bool TryConditionSet(char *command); >Release-Note: >Audit-Trail: >Unformatted: