| M E M _ F I N D I N F I L E Q ( )
| | | | | SOURCE: qdev_autodocs.txt 1.163 (12/09/2014) English
PORTA - MEM_#?
----------------------------------------------------------------------------
NAME
mem_findinfileq() - Allows to search in a file (by name).
SYNOPSIS
res = mem_findinfileq(buflen, file, data, datalen, hits);
LONG mem_findinfileq(ULONG, UBYTE *, UBYTE *, LONG, LONG);
FUNCTION
With this one you are able to find either, a NULL terminated
string or bin. data in a file. The search is case sensitive!
INPUTS
buflen - Buffer size used for sequential reading. It can be
0 so the default value defined in 'mem_scanfile()'
will be used. Generally 8192 to 65536 bytes is OK
in most cases, but if you need to seek for 512 k
pattern for instance then double that value here!
Passing negative val. switches to case insensitive
mode.
file - File(filename) to search in.
data - NULL terminated string or binary data.
datalen - Length of 'data', passing -1 will determine size of
NULL terminated string.
hits - How many times data should occurr, passing -1 here
will produce total number of hits per file, passing
0 will report last occurrence at its location in
bytes, passing 1 will try to find the very first
occurrence; numbers equal/higher than 1 may be used
to test if this much times 'data' appears to be in
a given file.
RETURNS
May return byte at which 'data' was found or total 'data'
occurrences, depending what was passed in 'hits' argument.
It may also return these error codes: -2 if file could not
be opened or there was not enough memory, -1 will be set
if 'data' was not found anywhere in the file.
BASES
SysBase, DOSBase
NOTES
Function can safely be terminated with SIGBREAKF_CTRL_C
(Control-C).
If termination signal was used then it must be cleared
('Signal(0L, signal)') after the function returns or else
it will trigger some exception handler or something similar
further.
SEE ALSO
mem_scanfile(), mem_findinfile()
EXAMPLE
...
LONG res;
if ((res = mem_findinfileq(0, "famous_ppl.db",
"Jay Miner", -1, 1)) >= 0)
{
UBYTE buf[256];
BPTR fd;
if ((fd = Open("famous_ppl.db", MODE_OLDFILE)))
{
Seek(fd, res, OFFSET_BEGINNING);
FGets(fd, buf, 256);
FPuts(Output(), buf);
Close(fd);
}
}
BUGS
None known.
----------------------------------------------------------------------------
| |
| |