added more commands to sed

This commit is contained in:
hyung-hwan 2009-03-12 07:32:31 +00:00
parent 2e818033c9
commit 1167325005
2 changed files with 75 additions and 42 deletions

View File

@ -319,6 +319,7 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c);
break; break;
case QSE_T(':'): case QSE_T(':'):
cmd->type = c;
if (cmd->a1.type != QSE_SED_A_NONE) if (cmd->a1.type != QSE_SED_A_NONE)
{ {
/* label cannot have an address */ /* label cannot have an address */
@ -331,7 +332,7 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c);
/* TODO: ... */ /* TODO: ... */
break; break;
case QSE_SED_CMD_EQ: case QSE_T('='):
cmd->type = c; cmd->type = c;
if (cmd->a2.type != QSE_SED_A_NONE) if (cmd->a2.type != QSE_SED_A_NONE)
{ {
@ -340,11 +341,12 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c);
} }
break; break;
case QSE_SED_CMD_A: case QSE_T('a'):
case QSE_SED_CMD_I: case QSE_T('i'):
case QSE_SED_CMD_C: case QSE_T('c'):
{ {
cmd->type = c; cmd->type = c;
/* TODO: this check for A and I /* TODO: this check for A and I
if (cmd->a2.type != QSE_SED_A_NONE) if (cmd->a2.type != QSE_SED_A_NONE)
{ {
@ -387,60 +389,54 @@ qse_printf (QSE_T("%s%s"), ttt, QSE_STR_PTR(cmd->u.text));
break; break;
} }
case QSE_T('g'): case QSE_T('D'):
break; //cmd->u.label = pspace;
case QSE_T('d'):
case QSE_T('G'): cmd->type = c;
break; break;
case QSE_T('h'): case QSE_T('h'):
break;
case QSE_T('H'): case QSE_T('H'):
case QSE_T('g'):
case QSE_T('G'):
case QSE_T('l'):
case QSE_T('n'):
case QSE_T('N'):
case QSE_T('p'):
case QSE_T('P'):
case QSE_T('x'):
cmd->type = c;
break; break;
case QSE_T('t'):
break;
case QSE_T('b'): case QSE_T('b'):
break; break;
case QSE_T('t'):
case QSE_T('n'):
break; break;
case QSE_T('N'):
break;
case QSE_T('p'):
break;
case QSE_T('P'):
break;
case QSE_T('r'): case QSE_T('r'):
break; break;
case QSE_T('R'):
case QSE_T('d'):
break;
case QSE_T('D'):
break;
case QSE_T('q'):
break;
case QSE_T('l'):
break;
case QSE_T('s'):
break; break;
case QSE_T('w'): case QSE_T('w'):
break; break;
case QSE_T('W'):
case QSE_T('x'):
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'):
break;
case QSE_T('y'): case QSE_T('y'):
break; break;
} }

View File

@ -53,7 +53,7 @@ struct qse_sed_c_t
{ {
qse_str_t* text; qse_str_t* text;
void* rex; void* rex;
qse_sed_c_t* lbl; /* branch destination */ qse_sed_c_t* label; /* branch destination */
} u; } u;
qse_char_t* rhs; /* right-hand side of sustitution */ qse_char_t* rhs; /* right-hand side of sustitution */
@ -61,11 +61,48 @@ struct qse_sed_c_t
enum enum
{ {
QSE_SED_CMD_B = QSE_T('b'), /* branch */ QSE_SED_CMD_B = QSE_T('b'), /* branch */
/* print current line number */
QSE_SED_CMD_EQ = QSE_T('='), /* print current line number */ QSE_SED_CMD_EQ = QSE_T('='), /* print current line number */
QSE_SED_CMD_A = QSE_T('a'), /* append text */ /* a \<\n> text - append text */
QSE_SED_CMD_I = QSE_T('i'), /* insert text */ QSE_SED_CMD_A = QSE_T('a'),
QSE_SED_CMD_C = QSE_T('c') /* change text */ /* i \<\n> text - insert text */
QSE_SED_CMD_I = QSE_T('i'),
/* c \<\n> text - change text */
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_HH = QSE_T('H'),
QSE_SED_CMD_G = QSE_T('g'),
QSE_SED_CMD_GG = QSE_T('G'),
/* list out current line */
QSE_SED_CMD_L = QSE_T('l'),
QSE_SED_CMD_N = QSE_T('n'),
QSE_SED_CMD_NN = QSE_T('N'),
QSE_SED_CMD_P = QSE_T('p'),
QSE_SED_CMD_PP = QSE_T('P'),
/* exchange hold space and pattern space */
QSE_SED_CMD_X = QSE_T('x'),
/* r filename - append a text from a file */
QSE_SED_CMD_R = QSE_T('r'),
/* R filename - append a line from a file */
QSE_SED_CMD_RR = QSE_T('R'),
/* w filename - write pattern space to a file */
QSE_SED_CMD_W = QSE_T('r'),
/* W filename - write first line of pattern space to a file */
QSE_SED_CMD_WW = QSE_T('R'),
QSE_SED_CMD_Q = QSE_T('q'),
QSE_SED_CMD_QQ = QSE_T('Q'),
QSE_SED_CMD_S = QSE_T('s'),
QSE_SED_CMD_Y = QSE_T('y')
} type; } type;
/* TODO: change the data type to a shorter one to save space */ /* TODO: change the data type to a shorter one to save space */