misc/138797: [patch] \newif command support to latex2rtf
Yoshihiro Ota
ota at j.email.ne.jp
Mon Sep 14 03:00:16 UTC 2009
>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:
More information about the freebsd-bugs
mailing list