Index | PAL Intro | Commands | Registers | Indices | Stack | Macros | Classes | Attributes | Errors


Manual Reference Pages  - reg_xscan (5)

NAME

reg/xscan - Search text or byte strings

CONTENTS

Synopsis
Description
Error Handling
Examples
See Also
Author

SYNOPSIS

reg/xscan write, [text], [find]
reg/xscan write, [text], [find], #offset

DESCRIPTION

Searches given text argument, which may be a text or byte string, for the sub-string find, returning in the write argument the offset within text where the find string was located. The returned offset will be represented as a psInteger encoded as a PSUNIT_TYPE_XVALUE where the first character position is index 0.

If the find sub-string could not be located within the given text, then a NULL pointer will be returned instead of a raw index.

If the optional offset argument is provided, this may be a raw index or a psInteger encoded as a PSUNIT_TYPE_XVALUE and indicates the starting position for the search. If omitted, the start position is the first character (index 0).

ERROR HANDLING

A runtime error is generated if an argument provided is of the wrong type.

EXAMPLES

The following searches the standard input for any lines containing the text "Function:", and sends matching lines to standard output:

.main  
% Prepare registers
reg/load P9, ![.prose.sys.io]
attr/load P10, [psStreamIn], P11, [psStreamOut]
reg/load P12, [Function:]       % string to search

.loop   % Load next line from stdin attr/copy P0, P9, P10 reg/jmpeq &[.exit], P0, NULL
% Search for text reg/xscan P1, P0, P12
% If text was found, send line to stdout reg/jmpeq &[.clr], P1, NULL attr/mod P9, P11, P0 local/jmp &[.loop]
.clr   % Free string and continue loop reg/clr P0 local/jmp &[.loop]
.exit   func/rtn

SEE ALSO

pal_commands(5), pal_registers(5), pal_indices(5), pal_macros(5), reg_load_text(5), reg_copy(5),
PROSE Assembly Language at prose.sourceforge.net.

AUTHOR

Copyright (c) 2002-2017 Mark R. Bannister <cambridge@users.sourceforge.net>.

This is free software and can be downloaded from prose.sourceforge.net; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


PAL 1.0 reg_xscan (5) 12 September 2017
Generated by manServer 1.07 from man5/reg_xscan.5 using man macros.