#] #] ********************* #] "$d_Qroot""5_IF examples [file_exists, pthL, is[chr, str], etc].txt" # www.BillHowell.ca 11Jun2021 initial, from "0_QNial notes.txt" # 09Oct2021 split from '0_QNial summary.txt' # collection of often used, but easily forgotten and important, coding ideas # note the use of noerror, which : # greatly facilitates multiple-parallel conditions (eg tests of [str,ary,etc]) # strongly reduces length of code lines # options for types : ["d_old, "d_new, "p_old, "p_new] # 21Oct2021 Many of these are being transformed into checkOptrs in 'QNial setup.ndf' ... # this is much more [reliable, easy, powerful, easy to read, portable] #**************************** # List of operators, generated with : # $ grep "^#] " "$d_Qroot""5_IF examples [file_exists, pathL, is[chr, str], etc].txt" | sed 's/^#\]/ /' # ********************* "$d_Qroot""5_IF examples [file_exists, pthL, is[chr, str], etc].txt" +-----+ [start, end] setups for IF conditionals +-----+ file_exist templates single path : eg (NOT pth_typ_exists pth "p_old) specified paths : eg (NAND (EACH pth_typ_exists ("p_old pinn) ("p_new pout))) Path lists : eg (NAND (EACH pth_typ_exists ("p_old EACHRIGHT pair pthL))) +-----+ other templates search for paths IF : host_result link 'ls -1 "' d_zArchive '" | grep "' fname '" ' +-----+ [chr, str] IF templates [find, grep, sed] test for problematic characters - it can be possible to make this work with customize code test that each strOldNewL is a pair of strings test that strOldNewL are unique (dissimilar) strings (NOT AND (EACH isString strL)) (NOT isString chrL) subStr pairs +-----+ transformerStr IF templates IF (str_toUpperCase transStr) in ('EACH' 'TWIG' 'LEAF') 08********08 #] +-----+ #] [start, end] setups for IF conditionals % ; result := null ; result := link result ???check1??? ; result := link result ???check2??? ; % ; IF (= null result) THEN ... code ... ENDIF ; % ; result } 08********08 #] +-----+ #] pth_check [description, example]s : #] pinnL_strL_options_grepTo_pout IS OP pthL strL options pout { LOCAL cmd grep_expr outputStr ptmp_grepOut ptmp_pthL result wordOption ; % ; result := null ; result := link result (pinnL EACHLEFT pth_typ_check "p_old) ; result := link result EACH str_check strL ; result := link result EACH str_checkGrepProblemChrs strL ; result := link result grepOptions_check options ; % 23Oct2021 dummy optr - returns null ; result := link result pth_typ_check pout "p_new ; % ; IF (= null result) THEN ... ENDIF ; result } 08********08 #] +-----+ #] other templates #] search for paths IF : host_result link 'ls -1 "' d_zArchive '" | grep "' fname '" ' p_zArchive := fault '?pZarchive_restore error: p_zArchive cannot be found due to other failures' ; % ; % look for the most recent version of fname in d_zArchive ; fname_list := host_result link 'ls -1 "' d_zArchive '" | grep "' fname '" ' ; IF (= null fname_list) THEN noerror := o ; result := link result (fault '? error: unknown path(s)') ; ENDIF ; 08********08 #] +-----+ #] [chr, str] IF templates 08********08 #] +-----+ #] transformerStr IF templates #] IF (str_toUpperCase transStr) in ('EACH' 'TWIG' 'LEAF') % ; IF (str_toUpperCase transStr) in ('EACH' 'TWIG' 'LEAF') # enddoc