tagged release 0.6.4
[parrot.git] / runtime / parrot / library / libpcre.pir
blob06cb0af49f9d0816e075915aec8edfb1109918ae
1 # Copyright (C) 2004-2008, The Perl Foundation.
2 # $Id$
4 =head1 TITLE
6 libpcre.pir - NCI interface to Perl-Compatible Regular Expression library
8 =head1 DESCRIPTION
10 See 'library/pcre.pir' for details on the user interface.
12 =cut
15 .namespace ['PCRE::NCI']
18 .sub compile
19     .param string pat
20     .param int options
22     .local string error
23     .local pmc PCRE_NCI_compile
24     .local int error_size
26     .local pmc NULL
27     null NULL
29     .local pmc errptr
30     errptr= new 'Integer'
32     ## error message string size
33     error_size= 500
35     ## allocate space in string for error message
36     repeat error, " ", error_size
38     PCRE_NCI_compile= find_global 'PCRE::NCI', 'PCRE_compile'
40     .local pmc code
42     code= PCRE_NCI_compile( pat, options, error, errptr, NULL )
44     .local int is_code_defined
45     is_code_defined = defined code
46     unless is_code_defined goto RETURN
48     error = ""
50 RETURN:
51     .return( code, error, errptr )
52 .end
55 .sub exec
56     .param pmc regex
57     .param string s
58     .param int start
59     .param int options
61     .local int len
62     length len, s
64     .local pmc NULL
65     null NULL
67     ## osize -- 1/(2/3) * 4 * 2
68     .local int osize
69     osize= 12
71     ## number of result pairs
72     .local int num_result_pairs
73     num_result_pairs= 10
75     .local int ovector_length
76     ovector_length= osize * num_result_pairs
78     .local pmc ovector
79     ovector= new 'ManagedStruct'
80     ovector= ovector_length
82     ## on 32 bit systems
83     .local pmc PCRE_NCI_exec
84     PCRE_NCI_exec = find_global 'PCRE::NCI', 'PCRE_exec'
86     .local int ok
88     ok= PCRE_NCI_exec( regex, NULL, s, len, start, options, ovector, 10 )
90     .return( ok, ovector )
91 .end
94 .sub result
95     .param string s
96     .param int ok
97     .param pmc ovector
98     .param int n
100     .local string match
101     match= ""
102     if ok <= 0 goto NOMATCH
104     .local int ovecs
105     .local int ovece
107     .local pmc struct
108     struct= new 'SArray'
109     struct= 3
111     .include "datatypes.pasm"
113     struct[0] = .DATATYPE_INT
114     $I0 = ok * 2
115     struct[1] = $I0
116     struct[2] = 0
117     assign ovector, struct
118     $I0 = n * 2
119     ovecs = ovector[0;$I0]
120     inc $I0
121     ovece = ovector[0;$I0]
122     $I0 = ovece - ovecs
123     if ovecs >= 0 goto M1
124     match = ""
125     goto M0
127     substr match, s, ovecs, $I0
129 NOMATCH:
130     .return( match )
131 .end
133 =for todo
134     # or use convinience function
135     print "copy_substring\n"
136     i = 0
137     repeat match, " ", 500
138 loop:
139     .begin_call
140     .arg s
141     .arg ovector
142     .arg ok
143     .arg i
144     .arg match
145     .arg 500
146     .nci_call COPY_SUBSTRING
147     .end_call
148     if i goto subp
149     print "all "
150     goto all
151 subp:
152     print "("
153     print i
154     print ") "
155 all:
156     print "matched: '"
157     print match
158     print "'\n"
159     inc i
160     if i < ok goto loop
161     end
162 .end
164 =head1 FILES
166 pcre.pir, libpcre.pir
168 =head1 SEE ALSO
170 pcre(3)
172 =head1 AUTHORS
174 Original code by Leo Toetsch, updated by Jerry Gay
175 E<lt>jerry dot gay at gmail dot com<gt>
177 =cut
180 # Local Variables:
181 #   mode: pir
182 #   fill-column: 100
183 # End:
184 # vim: expandtab shiftwidth=4 ft=pir: