GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
sf_sed(3) FreeBSD Library Functions Manual sf_sed(3)

sed_compile, sed_exec, sed_free
string editor

#include <strfunc.h>


sed_t *
sed_compile(char *expr);

char *
sed_exec(sed_t *se, char *string);

svect *
sed_results(sed_t *se);

void
sed_free(sed_t *se);

These routines implement a subset of sed(1) or Perl's s///, y/// and // functionality.

You must compule your expression with sed_compile() in order to evaluate it later. Once compiled, it can be evaluated multiple times. See the EXPRESSIONS block to know about expressions semantics.

sed_free() used to destroy the compiled structure and free the allocated memory.

sed_exec() takes the source string and transforms it according to the compiled rules. Resulting string stored in the internal buffer within the specified sed_t structure.

sed_results() May be invoked multiple times after sed_exec() to obtain last match results. An 'r' flag should be specified within the expression string.

Currently, this library supports two types of string transformations and one type of string match.

Substitutions

Expressions of this type are defined in the following BNF:

<delim>	:=	'/' | <other_character>

<regex>	:=	<regular_expression, re_format(7)>

<to>	:=	<string>

<flags>	:=	*( 'g' | 'i' | 'e' | 'r' | 'm' | 'n' )

<expr>	:= 	s <delim> <regex> <delim> <to> <delim> <flags>

Refer to sed(1) manual page to know other details.

Table lookup

<delim>	:=	'/' | <other_character>

<flags>	:=	*( 'i' )

<expr>	:= 	y <delim> <string> <delim> <string> <delim> <flags>

String match

<delim>	:=	'/' | <other_character>

<flags>	:=	*( 'i' | 'r' | 'm' | 'n' )

<reply>	:=	<string>

<expr>	:= 	<delim> <string> <delim> [ <reply> <delim>] <flags>

In the last case, if string does not match, sed_exec() will return a NULL pointer, <reply> otherwise. s/// and y/// functions will never return a NULL pointer.

Flags are common to those transformations.

'i'
case-insensitive matches.
'e'
compile in extended mode (REG_EXTENDED).
'g'
Make the substitution for all non-overlapping matches of the regular expression, not just the first one.
'r'
Remember last match results to allow use of sed_results().
'm'
Compile for newline-sensitive matching (REG_NEWLINE).
'n'
Don't include zero regexec(3) match (a whole substring) into results list.

void main() {
	sed_t *se1;
	sed_t *se2;
	sed_t *se3;
	char *r1, *r2, r3;

	/* Compile expressions */
	se1 = sed_compile("s/(tree) (apple)/\\2 \\1/igr");
	se2 = sed_compile("y/abc/AbC/i");
	se3 = sed_compile("/apple/i");

	r1 = sed_exec(se1, "Tree Apple");
	r2 = sed_exec(se2, "abcabc");
	r3 = sed_exec(se3, "another apple tree");

	/*
	** This will produce:
	** "Apple Tree\nAbCAbC\n1\n"
	*/
	printf("%s\n%s\n%d\n", r1, r2, r3?1:0);

	/*
	** This will produce:
	** "[Tree Apple], [Tree], [Apple]\n"
	*/
	printf("[%s]\n", sjoin(sed_results(se1), "], ["));

	/* Free the resources */
	sed_free(se1);
	sed_free(se2);
	sed_free(se3);
};

strfunc(3).

Lev Walkin <vlm@lionet.info>
December 4, 2000 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.