AT&T UNIX™PC Unix System V Users Manual - tenox

AT&T UNIX™PC Unix System V Users Manual - tenox AT&T UNIX™PC Unix System V Users Manual - tenox

01.01.2013 Views

REGCMP {3X) REGCMP {3X) ( . . . ) Parentheses are used for grouping. An operator, e.g. *, +, { }, can work on a single character or a regular expression enclosed in parenthesis. For example, (a*( cb+ )* )$0. By necessity, all the above defined symbols are special. They must, therefore, be escaped to be used as themselves. EXAMPLES Example 1: char •cursor, •newcursor, *ptr; newcursor = regex((ptr = regcmp("�\n", 0)), cursor); free(ptr); This example will match a leading new-line in the subject string pointed at by cursor. Example 2: char ret0[9]; char •newcursor, •name; name = regcmp("([A-Za-z] [A-za- z0-9_] {0,7})$0", 0); newcursor = regex(name, "123Testing321", reto); This example will match through the string "Testing3" and will return the address of the character after the last matched character (cursor+ll). The string "Testing3" will be copied to the character array retO. /� Example 3: #include "file.i" char •string, •newcursor; newcursor = regex(name, string); This example applies a precompiled regular expression in file.i (see regcmp ( l)) against string . This routine is kept in /lib/libPW.a. SEE ALSO ed(l), regcmp(l), malloc(3C). BUGS The user program may run out of memory if regcmp is called iteratively without freeing the vectors no longer required. The following user-supplied replacement for malloc(3C) reuses the same vector saving time and space: /* user's program */ malloc(n) { static int rebuf[256] ; return rebuf; } - 2-

SCANF ( 3S ) SCANF(3S) NAME scanf, fscanf, sscanf - convert formatted input SYNOPSIS #include int scanf (format [ , pointer ] . . . ) char *format; int fscanf (stream, format [ , pointer ] . .. FILE *stream; char *format; int sscanf (s, format [ , pointer ] . . . ) char *s, *format; DESCRIPTION Scanf reads from the standard input stream stdin . Fscanf reads from the named input stream. Sscanf reads from the character string s . Each function reads characters, interprets them according to a format, and stores the results in its arguments. Each expects, as arguments, a control string format described below, and a set of pointer arguments indicating where the converted input should be stored. The control string usually contains conversion specifications, which are used to direct interpretation of input sequences. The control string may contain: 1. White-space characters (blanks, tabs, new-lines, or form-feeds) which, except in two cases described below, cause input to be read up to the next non-white-space character. 2. An ordinary character (not %), which must match the next character of the input stream. 3. Conversion specifications, consisting of the character %, an optional assignment suppressing character *, an optional numerical maximum field width, an optional I or h indicating the size of the receiving variable, and a conversion code. A conversion specification directs the conversion of the next input field; the result is placed in the variable pointed to by the corresponding argument, unless assignment suppression was indicated by *· The suppression of assignment provides a way of describing an input field which is to be skipped. An input field is defined as a string of non-space characters; it extends to the next inappropriate character or until the field width, if specified, is exhausted. The conversion code indicates the interpretation of the input field; the corresponding pointer argument must usually be of a restricted type. For a suppressed field, no pointer argument should be given. The following conversion codes are legal: % a single % is expected in the input at this point; no assignment is done. d a decimal integer is expected; the corresponding argument should be an integer pointer. - 1 -

REGCMP {3X) REGCMP {3X)<br />

( . . . ) Parentheses are used for grouping. An operator, e.g. *,<br />

+, { }, can work on a single character or a regular<br />

expression enclosed in parenthesis. For example,<br />

(a*( cb+ )* )$0.<br />

By necessity, all the above defined symbols are special. They<br />

must, therefore, be escaped to be used as themselves.<br />

EXAMPLES<br />

Example 1:<br />

char •cursor, •newcursor, *ptr;<br />

newcursor = regex((ptr = regcmp("�\n", 0)), cursor);<br />

free(ptr);<br />

This example will match a leading new-line in the subject string<br />

pointed at by cursor.<br />

Example 2:<br />

char ret0[9];<br />

char •newcursor, •name;<br />

name = regcmp("([A-Za-z] [A-za- z0-9_] {0,7})$0", 0);<br />

newcursor = regex(name, "123Testing321", reto);<br />

This example will match through the string "Testing3" and will<br />

return the address of the character after the last matched character<br />

(cursor+ll). The string "Testing3" will be copied to the character<br />

array retO. /�<br />

Example 3:<br />

#include "file.i"<br />

char •string, •newcursor;<br />

newcursor = regex(name, string);<br />

This example applies a precompiled regular expression in file.i (see<br />

regcmp ( l)) against string .<br />

This routine is kept in /lib/libPW.a.<br />

SEE ALSO<br />

ed(l), regcmp(l), malloc(3C).<br />

BUGS<br />

The user program may run out of memory if regcmp is called<br />

iteratively without freeing the vectors no longer required. The following<br />

user-supplied replacement for malloc(3C) reuses the same<br />

vector saving time and space:<br />

/* user's program */<br />

malloc(n) {<br />

static int rebuf[256] ;<br />

return rebuf;<br />

}<br />

- 2-

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!