added QSE_SED_SAMELINE to sed
This commit is contained in:
parent
8118c7477d
commit
15227808a7
@ -120,13 +120,15 @@ static void print_usage (QSE_FILE* out, int argc, qse_char_t* argv[])
|
||||
qse_fprintf (out, QSE_T(" -n disable auto-print\n"));
|
||||
qse_fprintf (out, QSE_T(" -a perform strict address check\n"));
|
||||
qse_fprintf (out, QSE_T(" -r allows {n,m} in a regular expression\n"));
|
||||
qse_fprintf (out, QSE_T(" -s allows text on the same line as c, a, i\n"));
|
||||
qse_fprintf (out, QSE_T(" -l ensures a newline at the text end"));
|
||||
}
|
||||
|
||||
static int handle_args (int argc, qse_char_t* argv[])
|
||||
{
|
||||
static qse_opt_t opt =
|
||||
{
|
||||
QSE_T("hnar"),
|
||||
QSE_T("hnarsl"),
|
||||
QSE_NULL
|
||||
};
|
||||
qse_cint_t c;
|
||||
@ -170,6 +172,14 @@ static int handle_args (int argc, qse_char_t* argv[])
|
||||
case QSE_T('r'):
|
||||
g_option |= QSE_SED_REXBOUND;
|
||||
break;
|
||||
|
||||
case QSE_T('s'):
|
||||
g_option |= QSE_SED_SAMELINE;
|
||||
break;
|
||||
|
||||
case QSE_T('l'):
|
||||
g_option |= QSE_SED_ENSURENL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,13 +93,15 @@ Terminates the exection of commands quietly.
|
||||
|
||||
- <b>a \\ \n text</b>
|
||||
Stores @b text into the append buffer which is printed after the pattern
|
||||
space for each input line. If #QSE_SED_STRICT is specified, a line selector
|
||||
of an address range is not allowed.
|
||||
space for each input line. If #QSE_SED_STRICT is on, an address range is not
|
||||
allowed for a line selector. If #QSE_SED_NEWLINE is specified, the backslash
|
||||
and the text can be located on the same line without a line break.
|
||||
|
||||
- <b>i \\ \n text</b>
|
||||
Inserts @b text into an insert buffer which is printed before the pattern
|
||||
space for each input line. If #QSE_SED_STRICT is specified, a line selector
|
||||
of an address range is not allowed.
|
||||
space for each input line. If #QSE_SED_STRICT is on, an address range is not
|
||||
allowed for a line selector. If #QSE_SED_NEWLINE is specified, the backslash
|
||||
and the text can be located on the same line without a line break.
|
||||
|
||||
- <b>c \\ \n text</b>
|
||||
If a single line is selected for the command (i.e. no line selector, a single
|
||||
@ -107,7 +109,9 @@ address line selector, or a start~step line selector is specified), it changes
|
||||
the pattern space to @b text and branches to the end of commands for the line.
|
||||
If an address range is specified, it deletes the pattern space and branches
|
||||
to the end of commands for all input lines but the last, and changes pattern
|
||||
space to @b text and branches to the end of commands.
|
||||
space to @b text and branches to the end of commands. If #QSE_SED_NEWLINE is
|
||||
on, the backlash and the text can be located on the same line without a line
|
||||
break.
|
||||
|
||||
- <b>d</b>
|
||||
Deletes the pattern space and branches to the end of commands.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: sed.h 275 2009-08-30 13:19:02Z hyunghwan.chung $
|
||||
* $Id: sed.h 276 2009-08-31 13:24:06Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -127,13 +127,14 @@ typedef const qse_char_t* (*qse_sed_errstr_t) (
|
||||
*/
|
||||
enum qse_sed_option_t
|
||||
{
|
||||
QSE_SED_STRIPLS = (1 << 0), /**< strip leading spaces from text */
|
||||
QSE_SED_KEEPTBS = (1 << 1), /**< keep an trailing backslash */
|
||||
QSE_SED_ENSURENL = (1 << 2), /**< ensure NL at the text end */
|
||||
QSE_SED_QUIET = (1 << 3), /**< do not print pattern space */
|
||||
QSE_SED_STRICT = (1 << 4), /**< do strict address check */
|
||||
QSE_SED_STARTSTEP = (1 << 5), /**< allow start~step */
|
||||
QSE_SED_REXBOUND = (1 << 6) /**< allow {n,m} in regular expression */
|
||||
QSE_SED_STRIPLS = (1 << 0), /**< strip leading spaces from text */
|
||||
QSE_SED_KEEPTBS = (1 << 1), /**< keep an trailing backslash */
|
||||
QSE_SED_ENSURENL = (1 << 2), /**< ensure NL at the text end */
|
||||
QSE_SED_QUIET = (1 << 3), /**< do not print pattern space */
|
||||
QSE_SED_STRICT = (1 << 4), /**< do strict address check */
|
||||
QSE_SED_STARTSTEP = (1 << 5), /**< allow start~step */
|
||||
QSE_SED_REXBOUND = (1 << 6), /**< allow {n,m} in regular expression */
|
||||
QSE_SED_SAMELINE = (1 << 7), /**< allow text on the same line as c, a, i */
|
||||
};
|
||||
typedef enum qse_sed_option_t qse_sed_option_t;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: pio.c 244 2009-07-24 12:22:00Z hyunghwan.chung $
|
||||
* $Id: pio.c 276 2009-08-31 13:24:06Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -479,7 +479,9 @@ qse_pio_t* qse_pio_init (
|
||||
argv[2] = mcmd;
|
||||
argv[3] = QSE_NULL;
|
||||
|
||||
QSE_EXECVE (QSE_MT("/bin/sh"), argv, environ);
|
||||
QSE_EXECVE (
|
||||
QSE_MT("/bin/sh"),
|
||||
(qse_mchar_t*const*)argv, environ);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $Id: sed.c 269 2009-08-26 03:03:51Z hyunghwan.chung $
|
||||
* $Id: sed.c 276 2009-08-31 13:24:06Z hyunghwan.chung $
|
||||
*
|
||||
Copyright 2006-2009 Chung, Hyung-Hwan.
|
||||
|
||||
@ -1142,12 +1142,16 @@ static int get_command (qse_sed_t* sed, qse_sed_cmd_t* cmd)
|
||||
|
||||
if (c != QSE_CHAR_EOF && c != QSE_T('\n'))
|
||||
{
|
||||
if (sed->option & QSE_SED_SAMELINE)
|
||||
goto sameline_ok;
|
||||
|
||||
SETERR0 (sed, QSE_SED_EGBABS, &sed->src.loc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
NXTSC (sed); /* skip the new line */
|
||||
|
||||
sameline_ok:
|
||||
/* get_text() starts from the next line */
|
||||
if (get_text (sed, cmd) <= -1) return -1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user