diff --git a/commands/CmdFI.c b/commands/CmdFI.c
index 127ff706..fb624e71 100644
--- a/commands/CmdFI.c
+++ b/commands/CmdFI.c
@@ -1958,7 +1958,7 @@ CmdFlatten(w, cmd)
MagWindow *w;
TxCommand *cmd;
{
- int rval, xMask;
+ int i, xMask, optargs;
bool dolabels, dobox, toplabels, invert, doports, doinplace;
char *destname;
CellDef *newdef;
@@ -1966,36 +1966,32 @@ CmdFlatten(w, cmd)
SearchContext scx;
CellUse *flatDestUse;
- destname = cmd->tx_argv[cmd->tx_argc - 1];
+ destname = NULL;
xMask = CU_DESCEND_ALL;
dolabels = TRUE;
toplabels = FALSE;
dobox = FALSE;
doports = TRUE;
doinplace = FALSE;
+ optargs = cmd->tx_argc - 1;
- rval = 0;
- if (cmd->tx_argc > 2)
+ if (optargs > 0)
{
- int i;
- for (i = 1; i < (cmd->tx_argc - 1); i++)
+ for (i = 1; i < (optargs + 1); i++)
{
- if (!strncmp(cmd->tx_argv[i], "-no", 3))
+ if ((cmd->tx_argv[i][0] == '-') && (strlen(cmd->tx_argv[i]) > 3))
{
- invert = TRUE;
- }
- else if (!strncmp(cmd->tx_argv[i], "-do", 3))
- {
- invert = FALSE;
- }
- else
- {
- rval = -1;
- break;
- }
+ if (!strncmp(cmd->tx_argv[i] + 1, "no", 2))
+ invert = TRUE;
+ else if (!strncmp(cmd->tx_argv[i] + 1, "do", 2))
+ invert = FALSE;
+ else
+ {
+ TxError("Bad flatten option \"%s\"; must start with \"-no\" or \"-do\"\n",
+ cmd->tx_argv[i]);
+ return;
+ }
- if (strlen(cmd->tx_argv[i]) > 3)
- {
switch(cmd->tx_argv[i][3])
{
case 'b':
@@ -2029,98 +2025,53 @@ CmdFlatten(w, cmd)
break;
}
}
+ else
+ destname = cmd->tx_argv[i];
}
}
- else if (cmd->tx_argc != 2)
- rval = -1;
- if (rval != 0)
+ /* Flatten-in-place */
+ if (doinplace)
{
- TxError("usage: flatten [-