cleaned up code
This commit is contained in:
parent
1e45c03f82
commit
5ccbefe349
@ -103,21 +103,26 @@ void qse_sed_fini (qse_sed_t* sed)
|
|||||||
qse_sed_cmd_t* c;
|
qse_sed_cmd_t* c;
|
||||||
for (c = sed->cmd.buf; c != sed->cmd.cur; c++)
|
for (c = sed->cmd.buf; c != sed->cmd.cur; c++)
|
||||||
{
|
{
|
||||||
if (c->type == QSE_SED_CMD_B || c->type == QSE_SED_CMD_T)
|
switch (c->type)
|
||||||
{
|
{
|
||||||
if (c->u.branch.text != QSE_NULL)
|
case QSE_SED_CMD_B:
|
||||||
qse_str_close (c->u.branch.text);
|
case QSE_SED_CMD_T:
|
||||||
}
|
if (c->u.branch.text != QSE_NULL)
|
||||||
else if (c->type == QSE_SED_CMD_Y)
|
qse_str_close (c->u.branch.text);
|
||||||
{
|
break;
|
||||||
if (c->u.transet.ptr != QSE_NULL)
|
|
||||||
QSE_MMGR_FREE (sed->mmgr, c->u.transet.ptr);
|
case QSE_SED_CMD_Y:
|
||||||
}
|
if (c->u.transet.ptr != QSE_NULL)
|
||||||
else if (c->type == QSE_SED_CMD_R || c->type == QSE_SED_CMD_RR ||
|
QSE_MMGR_FREE (sed->mmgr, c->u.transet.ptr);
|
||||||
c->type == QSE_SED_CMD_W || c->type == QSE_SED_CMD_WW)
|
break;
|
||||||
{
|
|
||||||
if (c->u.filename.ptr != QSE_NULL)
|
case QSE_SED_CMD_R:
|
||||||
QSE_MMGR_FREE (sed->mmgr, c->u.filename.ptr);
|
case QSE_SED_CMD_RR:
|
||||||
|
case QSE_SED_CMD_W:
|
||||||
|
case QSE_SED_CMD_WW:
|
||||||
|
if (c->u.filename.ptr != QSE_NULL)
|
||||||
|
QSE_MMGR_FREE (sed->mmgr, c->u.filename.ptr);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QSE_MMGR_FREE (sed->mmgr, sed->cmd.buf);
|
QSE_MMGR_FREE (sed->mmgr, sed->cmd.buf);
|
||||||
@ -592,6 +597,13 @@ oops:
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int get_subst (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||||
|
{
|
||||||
|
|
||||||
|
oops:
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
static int get_transet (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||||
{
|
{
|
||||||
qse_cint_t c, delim;
|
qse_cint_t c, delim;
|
||||||
@ -716,7 +728,7 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c);
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
case QSE_T(':'):
|
case QSE_T(':'):
|
||||||
/* label */
|
/* label - this is not a command */
|
||||||
cmd->type = c;
|
cmd->type = c;
|
||||||
if (cmd->a1.type != QSE_SED_A_NONE)
|
if (cmd->a1.type != QSE_SED_A_NONE)
|
||||||
{
|
{
|
||||||
@ -760,6 +772,22 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c);
|
|||||||
ADVSCP (sed);
|
ADVSCP (sed);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
case QSE_T('='):
|
||||||
|
case QSE_T('q'):
|
||||||
|
case QSE_T('Q'):
|
||||||
|
cmd->type = c;
|
||||||
|
if (cmd->a2.type != QSE_SED_A_NONE)
|
||||||
|
{
|
||||||
|
sed->errnum = QSE_SED_EA2PHB;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ADVSCP (sed);
|
||||||
|
if (terminate_command (sed) == -1) return -1;
|
||||||
|
printf ("command %c\n", cmd->type);
|
||||||
|
break;
|
||||||
|
|
||||||
|
|
||||||
case QSE_T('a'):
|
case QSE_T('a'):
|
||||||
case QSE_T('i'):
|
case QSE_T('i'):
|
||||||
case QSE_T('c'):
|
case QSE_T('c'):
|
||||||
@ -806,27 +834,9 @@ qse_printf (QSE_T("%s%s"), ttt, QSE_STR_PTR(cmd->u.text));
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case QSE_T('D'):
|
|
||||||
case QSE_T('d'):
|
case QSE_T('d'):
|
||||||
cmd->type = c;
|
case QSE_T('D'):
|
||||||
ADVSCP (sed);
|
|
||||||
if (terminate_command (sed) == -1) return -1;
|
|
||||||
printf ("command %c\n", cmd->type);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QSE_T('='):
|
|
||||||
cmd->type = c;
|
|
||||||
if (cmd->a2.type != QSE_SED_A_NONE)
|
|
||||||
{
|
|
||||||
sed->errnum = QSE_SED_EA2PHB;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ADVSCP (sed);
|
|
||||||
if (terminate_command (sed) == -1) return -1;
|
|
||||||
printf ("command %c\n", cmd->type);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QSE_T('h'):
|
case QSE_T('h'):
|
||||||
case QSE_T('H'):
|
case QSE_T('H'):
|
||||||
case QSE_T('g'):
|
case QSE_T('g'):
|
||||||
@ -869,19 +879,13 @@ qse_printf (QSE_T("cmd->u.branch.target = [%p]\n"), cmd->u.branch.target);
|
|||||||
qse_printf (QSE_T("cmd->u.filename= [%.*s]\n"), (int)cmd->u.filename.len, cmd->u.filename.ptr);
|
qse_printf (QSE_T("cmd->u.filename= [%.*s]\n"), (int)cmd->u.filename.len, cmd->u.filename.ptr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QSE_T('q'):
|
|
||||||
case QSE_T('Q'):
|
|
||||||
cmd->type = c;
|
|
||||||
if (cmd->a2.type != QSE_SED_A_NONE)
|
|
||||||
{
|
|
||||||
sed->errnum = QSE_SED_EA2PHB;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case QSE_T('s'):
|
case QSE_T('s'):
|
||||||
/* TODO */
|
cmd->type = c;
|
||||||
|
ADVSCP (sed);
|
||||||
|
if (get_subst (sed, cmd) == -1) return -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QSE_T('y'):
|
case QSE_T('y'):
|
||||||
cmd->type = c;
|
cmd->type = c;
|
||||||
ADVSCP (sed);
|
ADVSCP (sed);
|
||||||
|
@ -74,11 +74,15 @@ struct qse_sed_cmd_t
|
|||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
QSE_SED_CMD_B = QSE_T('b'), /* branch */
|
|
||||||
QSE_SED_CMD_T = QSE_T('t'), /* branch */
|
|
||||||
|
|
||||||
/* print current line number */
|
/* print current line number */
|
||||||
QSE_SED_CMD_EQ = QSE_T('='), /* print current line number */
|
QSE_SED_CMD_EQ = QSE_T('='),
|
||||||
|
QSE_SED_CMD_Q = QSE_T('q'),
|
||||||
|
QSE_SED_CMD_QQ = QSE_T('Q'),
|
||||||
|
|
||||||
|
/* delete pattern space */
|
||||||
|
QSE_SED_CMD_D = QSE_T('d'),
|
||||||
|
QSE_SED_CMD_DD = QSE_T('D'),
|
||||||
|
|
||||||
/* a \<\n> text - append text */
|
/* a \<\n> text - append text */
|
||||||
QSE_SED_CMD_A = QSE_T('a'),
|
QSE_SED_CMD_A = QSE_T('a'),
|
||||||
@ -87,9 +91,6 @@ struct qse_sed_cmd_t
|
|||||||
/* c \<\n> text - change text */
|
/* c \<\n> text - change text */
|
||||||
QSE_SED_CMD_C = QSE_T('c'),
|
QSE_SED_CMD_C = QSE_T('c'),
|
||||||
|
|
||||||
QSE_SED_CMD_D = QSE_T('d'), /* delete pattern space */
|
|
||||||
QSE_SED_CMD_DD = QSE_T('D'),
|
|
||||||
|
|
||||||
QSE_SED_CMD_H = QSE_T('h'),
|
QSE_SED_CMD_H = QSE_T('h'),
|
||||||
QSE_SED_CMD_HH = QSE_T('H'),
|
QSE_SED_CMD_HH = QSE_T('H'),
|
||||||
QSE_SED_CMD_G = QSE_T('g'),
|
QSE_SED_CMD_G = QSE_T('g'),
|
||||||
@ -103,6 +104,10 @@ struct qse_sed_cmd_t
|
|||||||
/* exchange hold space and pattern space */
|
/* exchange hold space and pattern space */
|
||||||
QSE_SED_CMD_X = QSE_T('x'),
|
QSE_SED_CMD_X = QSE_T('x'),
|
||||||
|
|
||||||
|
/* branch */
|
||||||
|
QSE_SED_CMD_B = QSE_T('b'),
|
||||||
|
QSE_SED_CMD_T = QSE_T('t'),
|
||||||
|
|
||||||
/* r filename - append a text from a file */
|
/* r filename - append a text from a file */
|
||||||
QSE_SED_CMD_R = QSE_T('r'),
|
QSE_SED_CMD_R = QSE_T('r'),
|
||||||
/* R filename - append a line from a file */
|
/* R filename - append a line from a file */
|
||||||
@ -113,9 +118,7 @@ struct qse_sed_cmd_t
|
|||||||
/* W filename - write first line of pattern space to a file */
|
/* W filename - write first line of pattern space to a file */
|
||||||
QSE_SED_CMD_WW = QSE_T('W'),
|
QSE_SED_CMD_WW = QSE_T('W'),
|
||||||
|
|
||||||
QSE_SED_CMD_Q = QSE_T('q'),
|
/* s/regex/str/ - replace matching pattern with a new string */
|
||||||
QSE_SED_CMD_QQ = QSE_T('Q'),
|
|
||||||
|
|
||||||
QSE_SED_CMD_S = QSE_T('s'),
|
QSE_SED_CMD_S = QSE_T('s'),
|
||||||
/* y/s/d/ - translate characters in s to characters in d */
|
/* y/s/d/ - translate characters in s to characters in d */
|
||||||
QSE_SED_CMD_Y = QSE_T('y')
|
QSE_SED_CMD_Y = QSE_T('y')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user