Exemplo n.º 1
0
Arquivo: rex01.c Projeto: apense/qse
static int rex_main (int argc, qse_char_t* argv[])
{
	qse_rex_t* rex;
	qse_rex_node_t* start;
	qse_cstr_t str;
	qse_cstr_t matstr;
	int n;

	if (argc != 3)
	{
		qse_printf (QSE_T("USAGE: %s pattern string\n"), 
			qse_basename(argv[0]));
		return -1;
	}

	rex = qse_rex_open (QSE_MMGR_GETDFL(), 0, QSE_NULL);
	if (rex == QSE_NULL)
	{
		qse_printf (QSE_T("ERROR: cannot open rex\n"));
		return -1;
	}

	qse_rex_setopt (rex, QSE_REX_STRICT);

	start = qse_rex_comp (rex, argv[1], qse_strlen(argv[1]));
	if (start == QSE_NULL)
	{
		qse_printf (QSE_T("ERROR: cannot compile - %s\n"),
			qse_rex_geterrmsg(rex));
		qse_rex_close (rex);
		return -1;
	}

	str.ptr = argv[2];
	str.len = qse_strlen(argv[2]);

	qse_printf (QSE_T("compile ok\n"));

	n = qse_rex_exec (rex, &str, &str, &matstr);
	if (n <= -1)
	{
		qse_printf (QSE_T("ERROR: cannot execute - %s\n"),
			qse_rex_geterrmsg(rex));
		qse_rex_close (rex);
		return -1;
	}
	if (n >= 1)
	{
		qse_printf (QSE_T("MATCH: [%.*s] beginning from char #%d\n"), 
			(int)matstr.len, matstr.ptr,
			(int)(matstr.ptr - str.ptr + 1));
	}

	qse_rex_close (rex);
	return 0;
}
Exemplo n.º 2
0
Arquivo: sed.c Projeto: DeadZen/qse
static void print_usage (qse_sio_t* out, int argc, qse_char_t* argv[])
{
	const qse_char_t* b = qse_basename (argv[0]);

	qse_fprintf (out, QSE_T("USAGE: %s [options] script [file]\n"), b);
	qse_fprintf (out, QSE_T("       %s [options] -f script-file [file]\n"), b);
	qse_fprintf (out, QSE_T("       %s [options] -e script [file]\n"), b);

	qse_fprintf (out, QSE_T("options as follows:\n"));
	qse_fprintf (out, QSE_T(" -h/--help                 show this message\n"));
	qse_fprintf (out, QSE_T(" --version                 show version\n"));
	qse_fprintf (out, QSE_T(" -n                        disable auto-print\n"));
	qse_fprintf (out, QSE_T(" -e                 script specify a script\n"));
	qse_fprintf (out, QSE_T(" -f                 file   specify a script file\n"));
	qse_fprintf (out, QSE_T(" -o                 file   specify an output file\n"));
	qse_fprintf (out, QSE_T(" -r                        use the extended regular expression\n"));
	qse_fprintf (out, QSE_T(" -R                        enable non-standard extensions to the regular\n"));
	qse_fprintf (out, QSE_T("                           expression\n"));
	qse_fprintf (out, QSE_T(" -i                        perform in-place editing. imply -s\n"));
	qse_fprintf (out, QSE_T(" -s                        process input files separately\n"));
	qse_fprintf (out, QSE_T(" -a                        perform strict address and label check\n"));
	qse_fprintf (out, QSE_T(" -b                        allow extended address formats\n"));
	qse_fprintf (out, QSE_T("                           <start~step>,<start,+line>,<start,~line>,<0,/regex/>\n"));
	qse_fprintf (out, QSE_T(" -x                        allow text on the same line as c, a, i\n"));
	qse_fprintf (out, QSE_T(" -y                        ensure a newline at text end\n"));
	qse_fprintf (out, QSE_T(" -m                 number specify the maximum amount of memory to use in bytes\n"));
	qse_fprintf (out, QSE_T(" -w                        expand file wildcards\n"));
#if defined(QSE_ENABLE_SEDTRACER)
	qse_fprintf (out, QSE_T(" -t                        print command traces\n"));
#endif
#if defined(QSE_BUILD_DEBUG)
	qse_fprintf (out, QSE_T(" -X                 number fail the number'th memory allocation\n"));
#endif
#if defined(QSE_CHAR_IS_WCHAR)
     qse_fprintf (out, QSE_T(" --script-encoding  string specify script file encoding name\n"));
     qse_fprintf (out, QSE_T(" --infile-encoding  string specify input file encoding name\n"));
     qse_fprintf (out, QSE_T(" --outfile-encoding string specify output file encoding name\n"));
#endif
}