MiniM. Saving time.

| About | Download | Tools | Knowledge Base | How to Buy |

MiniM Overview

Getting Started




Cache Tools

GT.M Tools

Knowledge Base




MiniM Additional Tools | RUS | Dec 28, 2011

$ZSEARCH function emulation for MiniM

On porting applications was developed developer may need to get file list by file mask. Cache DBMS uses for this purpose special $Z function $ZSEARCH. This function may be ported to MiniM without change any available code.

To emulate system $Z function in MiniM it is need to make special routine, with name prefix %ZFUNC. This routine must contain labels corresponded to emulated $Z functions. In the case of $ZSEARCH function need to be created two labels, ZSEARCH and ZSE. Second case is short abbreviation.

This labels must accept only one argument, target, and this argument mean the following:

  1. For empty string function must return the following file name matched by file mask used on previous function call.
  2. For nonempty string function must create ne wfile search and argument specify file mask, with possible name pattern symbols "*" and "?".

Function returns empty string if the following file name does not exists or return next file name as full file name with directories and disk letter.

To emulate functionality of $ZSEARCH function we create routine %ZFUNCSEARCH and local variable %zsearch. Inside function emulation we check need or not to be created new file search and check have we next file to return or not. If next file exists we return one and forgot this file for next call:

 ; if target is not empty string, create new file list
 i target'="" d makenew
 ; get next file number
 n n=$o(%zsearch("f","")),ret
 ; if files are out, return empty string
 i n="" s ret="" k %zsearch
 ; get next file name and remove from queue
 e  s ret=%zsearch("f",n) k %zsearch("f",n)
 q ret

Function makenew entirely recreates local variable %zsearch by specified file mask:

 ; remove entire queue
 k %zsearch
 ; save current file pattern
 s %zsearch("p")=target
 n mask,file,dir,dev,saveio,saveeof
 ; normalize slashs and separate dir from file
 s mask=$tr(target,"/","\")
 s dir=mask,$p(dir,"\",$l(dir,"\"))=""
 ; if dir was not present, use current dir
 i dir="" s dir=$v("proc",7)_"\"
 s file=$p(mask,"\",$l(mask,"\"))
 ; call dir OS command and
 ;   redirect possible error message about file not found
 s dev="|PIPE|dir /b "_$zquote(dir_file)_" 2> NUL"
 ; after execution current device need to be restored
 s saveio=$io
 o dev:"rt" u dev
 ; use $zeof end of device input indicator
 s saveeof=$v("proc",5,0)
 ; read all line by line
 f  r file q:$zeof  s %zsearch("f",$i(%zsearch("f")))=dir_file
 ; restore $zeof indicator behaviour
 i $v("proc",5,saveeof)
 ; restore current device
 u saveio
 ; close dir device
 c dev

Here in one function have been used simultaneously several elements:

  • normalizing directories slashes
  • use apologies that we need to return full file name but source directory can be omitted
  • call external console process dir to get file list by file mask
  • read output line by line and use $zeof indicator as end of file
  • resetting $zeof behaviour and current device

After import and compilation of function %ZFUNCSEARCH any MiniM process on call to system function $ZSEARCH calls emulation of this function with behaviour as like as in Cache:

 n mask,file
 s mask="c:\downloads\*.exe"
 s file=$zsearch(mask) i file'="" d  f  s file=$zse("") q:file=""  d
 . w file,!

Download routine %ZFUNCSEARCH (zip, 1Kb)

Eugene Karataev

Copyright (C) 2017 Eugene Karataev
Emails: Info Tech Support