diff --git a/qse/lib/utl/sed.c b/qse/lib/utl/sed.c index afc19573..0e9b85e0 100644 --- a/qse/lib/utl/sed.c +++ b/qse/lib/utl/sed.c @@ -319,6 +319,7 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c); break; case QSE_T(':'): + cmd->type = c; if (cmd->a1.type != QSE_SED_A_NONE) { /* label cannot have an address */ @@ -331,7 +332,7 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c); /* TODO: ... */ break; - case QSE_SED_CMD_EQ: + case QSE_T('='): cmd->type = c; if (cmd->a2.type != QSE_SED_A_NONE) { @@ -340,11 +341,12 @@ qse_printf (QSE_T("command not recognized [%c]\n"), c); } break; - case QSE_SED_CMD_A: - case QSE_SED_CMD_I: - case QSE_SED_CMD_C: + case QSE_T('a'): + case QSE_T('i'): + case QSE_T('c'): { cmd->type = c; + /* TODO: this check for A and I 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; } - case QSE_T('g'): - break; - - case QSE_T('G'): + case QSE_T('D'): + //cmd->u.label = pspace; + case QSE_T('d'): + cmd->type = c; break; case QSE_T('h'): - break; - 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; - case QSE_T('t'): - break; case QSE_T('b'): break; - - case QSE_T('n'): + case QSE_T('t'): break; - case QSE_T('N'): - break; - - case QSE_T('p'): - break; - - case QSE_T('P'): - break; case QSE_T('r'): break; - - case QSE_T('d'): - break; - - case QSE_T('D'): - break; - - case QSE_T('q'): - break; - - case QSE_T('l'): - break; - - case QSE_T('s'): + case QSE_T('R'): break; case QSE_T('w'): break; - - case QSE_T('x'): + case QSE_T('W'): 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'): break; } diff --git a/qse/lib/utl/sed.h b/qse/lib/utl/sed.h index 85ee2dee..d53d0d42 100644 --- a/qse/lib/utl/sed.h +++ b/qse/lib/utl/sed.h @@ -53,7 +53,7 @@ struct qse_sed_c_t { qse_str_t* text; void* rex; - qse_sed_c_t* lbl; /* branch destination */ + qse_sed_c_t* label; /* branch destination */ } u; qse_char_t* rhs; /* right-hand side of sustitution */ @@ -61,11 +61,48 @@ struct qse_sed_c_t enum { 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_A = QSE_T('a'), /* append text */ - QSE_SED_CMD_I = QSE_T('i'), /* insert text */ - QSE_SED_CMD_C = QSE_T('c') /* change text */ + /* a \<\n> text - append text */ + QSE_SED_CMD_A = QSE_T('a'), + /* 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; /* TODO: change the data type to a shorter one to save space */