Server for Information Technologies ������ ��������������
������� �������������� ����������
(095) 932-9212, 932-9213, 939-0783
E-mail: [email protected]
������ �������� ����(!) ������������� ���������� CIT Forum CD-ROM

REGEXP(5)

��������
regexp - ������� ��� ���������� � ������������� ���� ������ ���������

���������

        #define INIT      ��������
        #define GETC( )   ����������_GETC
        #define PEEKC( )  ����������_PEEKC
        #define UNGETC(c) ����������_UNGETC
        #define RETURN(p) ����������_RETURN
        #define ERROR(v)  ����������_ERROR

        #include <regexp.h>

        char *compile (instring, expbuf, endbuf, eof)
        char *instring, *expbuf, *endbuf;
        int eof;

        int step (string, expbuf)
        char *string, *expbuf;

        extern char *loc1, *loc2, *locs;

        extern int circf, sed, nbra;

��������
� ������ ������ ����������� ������������� ������� ������������� ���������� ��������� � ����� ed(1), ������������ �� ���������� ����� <regexp.h>. ���� �������� ���� ������������ ������ �����������, ��� ed(1), sed(1), grep(1), bs(1)expr(1), ������� ��������� ������������� ���������� ���������. ��� ����� �������������� ������������� ��������� ���������� ���������.

� ����� ����� ���������� ���������. ���������, ������� �������� ������ ����, ����� ���������� #include <regexp.h> ������ ��������� ����������� ���� ��������, ������������� ����. ������� ������������ �������� compile.

GETC( )
���������� �������� ���������� ������� � ���������� ���������. ���������������� ������ GETC ����� ���������� ���������������� ������� ����������� ���������.
PEEKC( )
���������� ��������� ������ � ���������� ���������. ���������������� ������ PEEKC ���������� ���� � ��� �� ������ (������ ������ ����� ��������� � ��� ��������� ������ GETC).
UNGETC(c)
������������, ����� ������ c ��� ����� ��� ��������� ������ GETC (� PEEKC). �������������, ��� �� �������� ������� ������� ������ ����� ������ �������, � ���� ������ �������� ���������, ����������� GETC. �������� ������� UNGETC ������������.
RETURN(p)
������ ������ ������������ ��� ���������� ���������� ������� compile. �������� ��������� p - ��������� �� ������, ��������� �� ��������� �������� ����������������� ����������� ���������. ��� ������� ��� ��������, ������� ������ ���������� �������������� ������.
ERROR(v)
��������� ���������� ������� compile. �������� v - ��� ��� ������. �������� �� ������� ������� ���� �� ������. ���� ������:
�������������
11������� ������� ��������� ������� ������.
16������������ �����.
25"\�����" ��� ���������.
36������������ ��� ������������� �����������.
41��� ����������� ������� �������� ��� ������.
42�� �������������� ������ \( � \).
43������� ����� ����������� ������ \(.
44� ������� \{ \} ������� ������ ���� �����.
45�������� ������ } ��������� ����� \.
46� ������� \{ \} ������ ����� ������ �������.
49�� �������������� ������ [ � ].
50������������ ����������� ���������.
��������� � ������� compile �������� ���:
 compile (instring, expbuf, endbuf, eof)

������ �������� instring ������� �� ������������ �������� compile ����, �� ������ ������ ��� ��������, ������� �������� ��������� ��������� �� ������� �������. ������ �� ������������ � ��������� INIT (��. ����). ���������, ������� �������� ������� ����������� ������� ������� ��� ������ �� �� ������� �������, ����� ���������� � �������� ����� ��������� �������� ((char *) 0).

�������� expbuf - ��������� �� ������. �� ���������� �������, ������� � ������� ������ ���� ��������� ���������������� ���������� ���������.

�������� endbuf �� ������� ����������� ������������ �������, � ������� ����� ���� ��������� ���������� ���������. ���� ���������������� ��������� �� ��������� � (endbuf-expbuf) ����, ����������� ����� ERROR (50).

�������� eof - ��� ������, ������� �������� ����� ����������� ���������. ��������, � ed(1) ���� �������� ������ �������� /.

� ������ ���������, ������� �������� ���� <regexp.h>, ������ ���� �������� #define ��� ����� INIT. �������� � ��� �������� ����� ��������� � ����� ������ ������� compile. ���� ����� ������ INIT ������ ��� ����, ����� ���������� ����������� ���������� �� ������ ����������� ��������� � ����� ������������ ������������� � GETC, PEEKC � UNGETC. ����� ����, � INIT ����� ������� ������� ����������, ������������ ��������� GETC, PEEKC � UNGETC. ��. ���� ������ ��������, ������ �� grep(1).

� ����� <regexp.h> ���� � ������ �������, ������� ���������� ��������� ������������� ���������� ���������; ���� �� ��� - ������� step. ��������� � ��� �������� ���:

 step (string, expbuf)

������ �������� ������� step - ��������� �� ������� ��������, ��� ������� ���� ��������� ����������� �������������. ��� ������� ������ ���� ���������� ������� ������.

������ ��������, expbuf, - ���������������� ���������� ���������, ���������� ��� ������ ������� compile.

������� step ���������� ��������� ��������, ���� ������ ������� �������������� � ���������� ����������, � 0 � ��������� ������. ���� ������������� ����� �����, �������� ������ ������� step ����������� � ��������� ���� ������� ����������. ���������� loc1, ��������������� �������� step, �������� ���������� �� ������ �������������� ������. ���������� loc2, ������� ��������������� �������� advance, ��������� �� ������, ��������� �� ��������� �������������� ��������. ����� �������, ���� � ���������� ���������� ������������� ��� �������, �� loc1 ����� ��������� �� ������ ������ string, � loc2 - �� ������� ���� � ����� string.

������� step ���������� ������� ���������� circf. Compile ����������� ���� ���������� ��������� ��������, ���� ���������� ��������� ���������� � ^; � ����� ������ step ����� �������� ��������� ������������� ������ � ������ ������� ��������. ���� �� ������ ������� ������������� ��������������� ����� ������ ����������� ���������, ������� ��������� ��� ������� ����������������� ��������� �������� circf � ��������������� �������� ���� ���������� ����� ������ ������� step.

������� advance ���������� �� step � ���� �� �����������, ��� � step. ������ ������� step - ����������� ��������� string �� ������ ������ � �������� advance; step ����������� �� ��� ���, ���� ���� advance �� ��������� ��������� ��������, ��� ���������� �������������, ���� �� ����� ��������� ����� string. ���� ����� � ����� ������ ������������ �������������� � ������ ������� string, step �� ��������, � ������ ���������� advance.

���� ������� advance ��������� � ���������� ��������� * ��� ������������������ \{ \}, ���, �������� �������������, ���������� ��������� �� ������� ��������, ��������� ��� ��������, � ���������� �������� ���� ����, ������� ����������� ������� ������� � �������� ����������� ���������. ���� ��� ���� ������������� �� ����������, advance ����� ������������ ����� �������, ���� �� ��������� ������������� ���� �� �������� � ������� � ������� ��������, � ������� ������������� ���� ������������ * ��� \{ \}. ������ ���������� ���������� ���� ������� ����� �� ����, ��� ����� ���������� ������ �������. ���� locs - ������� ��������� �� ������ - � ��������� ������ �������� �������� ������ ����� ������� � ������� ��������, advance ������� ���� �������� � ���������� � ����������� 0. ��� ����������� ������������ ����������� ed(1)sed(1) ��� ���������� ���������� ����������� (�� ���� �� ��� ������� ���������, � ��� ���� �������); ��������, ��� ��������� ��������� ���� /y*//g �� ��������� ������������ �����.

������
��������� ������ ����������, ��� �������� ��������������� ��� ������ � ����������� ����������� ������� � �������, ������� ������������ � grep(1):

#define INIT      register char *sp = instring;
#define GETC()    (*sp++)
#define PEEKC()   (*sp)
#define UNGETC(c) (--sp)
#define RETURN(c) return;
#define ERROR(c)  regerr()

#include <regexp.h>
 ...
(void) compile (*argv, expbuf, &expbuf[ESIZE], '\0');
 ...
if (step(linebuf, expbuf))
 succeed();

��. �����
ed(1), expr(1), grep(1), sed(1) � ����������� ������������.

R_PCRWORD
����������� �������� ������������ �������� ������.
R_PCRLONG
�������������� �������� ������������ �������� ������.

���������� ������ ���� ������ ��� ���� �����������. ���������� ���� ������ �� ������ ����������� ����� ���������� ������ � �����. ���� ��������� ������������� � ����� ����� ������, �� ����� ����� �� �������� � ������ ��������.

��������, ���������� ���������� � ���������, ��������� ����������� � ������������ ���������� ������ �������������. ����� ��������� ������ ��������� ��� ���������, ��� � ������� ��� ���������� �� �������� ������.

��. �����
a.out(4), syms(4).
as(1), ld(1) � ����������� ������������.
Comments: [email protected]
Designed by Andrey Novikov
Copyright © CIT