[796] | 1 | TMGKERNL ;TMG/kst/OS Specific functions ;11/01/04
|
---|
| 2 | ;;1.0;TMG-LIB;**1**;04/24/09
|
---|
| 3 |
|
---|
| 4 | ;"TMG KERNEL FUNCTIONS
|
---|
| 5 | ;"I.e. functions that are OS specific.
|
---|
| 6 | ;"Kevin Toppenberg MD
|
---|
| 7 | ;"GNU General Public License (GPL) applies
|
---|
| 8 | ;"7-12-2005
|
---|
| 9 |
|
---|
| 10 | ;"=======================================================================
|
---|
| 11 | ;" API -- Public Functions.
|
---|
| 12 | ;"=======================================================================
|
---|
| 13 | ;"$$Dos2Unix^TMGKERNL(FullNamePath)
|
---|
| 14 | ;"$$IsDir^TMGKERNL(Path)
|
---|
| 15 | ;"$$Move^TMGKERNL(Source,Dest)
|
---|
| 16 | ;"$$Copy^TMGKERNL(Source,Dest)
|
---|
| 17 | ;"$$Convert^TMGKERNL(FPathName,NewType) -- convert a graphic image to new type
|
---|
| 18 | ;"$$GetPckList(PckInit,Array,NeedsRefresh,PckDirFName) -- launch special linux script to get patch file list from ftp.va.gov
|
---|
| 19 | ;"$$DownloadFile^TMGKERNL(URL,DestDir) -- Interact with Linux to download a file with wget
|
---|
| 20 | ;"$$EditHFSFile^TMGKERNL(FilePathName) -- interact with Linux to edit a file on the host file system
|
---|
| 21 | ;"ZSAVE -- to save routine out to HFS
|
---|
| 22 | ;"MAKEBAKF^TMGKERNL(FilePathName,NodeDiv) ;Make Backup File if original exists
|
---|
| 23 | ;"$$GetScrnSize(ROWS,COLS) --query the OS and get the dimensions of the terminal window.
|
---|
| 24 |
|
---|
| 25 | ;"=======================================================================
|
---|
| 26 | ;"Dependancies
|
---|
| 27 | ;"=======================================================================
|
---|
| 28 |
|
---|
| 29 | ;"=======================================================================
|
---|
| 30 |
|
---|
| 31 | Dos2Unix(FullNamePath)
|
---|
| 32 | ;"Purpose: To execute the unix command Dos2Unix on filename path
|
---|
| 33 | ;"FullNamePath: The filename to act on.
|
---|
| 34 | ;"Result: 0 if no error; >0 if error
|
---|
| 35 | ;"Notice!!!! The return code here is DIFFERENT from usual
|
---|
| 36 |
|
---|
| 37 | new result set result=0
|
---|
| 38 | if $get(FullNamePath)="" goto DUDone
|
---|
| 39 | new spec set spec(" ")="\ "
|
---|
| 40 | set FullNamePath=$$REPLACE^XLFSTR(FullNamePath,.spec)
|
---|
| 41 |
|
---|
| 42 | new HookCmd set HookCmd="dos2unix -q "_FullNamePath
|
---|
| 43 | zsystem HookCmd
|
---|
| 44 | set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
|
---|
| 45 |
|
---|
| 46 | DUDone
|
---|
| 47 | quit result
|
---|
| 48 |
|
---|
| 49 |
|
---|
| 50 |
|
---|
| 51 | IsDir(Path,NodeDiv)
|
---|
| 52 | ;"Purpose: To determine if Path is a path to a directory (i.e. are there sub files)
|
---|
| 53 | ;"Input: Path to test, e.g. "/home/user" or "/home/user/"
|
---|
| 54 | ;" NodeDiv: [OPTIONAL] -- the character that separates folders (e.g. "/")
|
---|
| 55 | ;" if not supplied, then default value is "/"
|
---|
| 56 | ;"Result: 1 filepath is actually a directory
|
---|
| 57 | ;"Note: NEW! Will now return 1 if Path is a valid path to a directory, but there are no files in directory
|
---|
| 58 |
|
---|
| 59 | set Path=$get(Path)
|
---|
| 60 | set NodeDiv=$get(NodeDiv,"/")
|
---|
| 61 | if $extract(Path,$length(Path))'=NodeDiv set Path=Path_NodeDiv
|
---|
| 62 |
|
---|
| 63 | new p set p="myTerm"
|
---|
| 64 | open p:(COMMAND="stat --format=%F "_Path:readonly)::"pipe"
|
---|
| 65 | use p
|
---|
| 66 | new x read x
|
---|
| 67 | close p use $p
|
---|
| 68 | quit (x="directory")
|
---|
| 69 |
|
---|
| 70 | ;" ==== old code/method below (slower) ===
|
---|
| 71 | ;"Old results
|
---|
| 72 | ;"Result: 1 if there are files in path, 0 otherwise
|
---|
| 73 | ;"Note: if Path is a valid path to a directory, but there are no files in directory, 0 returned.
|
---|
| 74 |
|
---|
| 75 | new TMGMask set TMGMask("*")=""
|
---|
| 76 | new TMGFiles
|
---|
| 77 | new result set result=0
|
---|
| 78 |
|
---|
| 79 | new spec set spec(" ")="\ "
|
---|
| 80 | set Path=$$REPLACE^XLFSTR(Path,.spec)
|
---|
| 81 |
|
---|
| 82 | ;"Note: I can't seem to get this to work with names containing spaces.
|
---|
| 83 | if $$LIST^%ZISH(Path,"TMGMask","TMGFiles")=1 do
|
---|
| 84 | . new index set index=$order(TMGFiles(""))
|
---|
| 85 | . if index'="" set result=1
|
---|
| 86 |
|
---|
| 87 | quit result
|
---|
| 88 |
|
---|
| 89 |
|
---|
| 90 | Move(Source,Dest)
|
---|
| 91 | ;"Purpose to provide a shell for the Linux command 'mv'
|
---|
| 92 | ;" This can serve to move or rename a file
|
---|
| 93 | ;"Note: a platform independant version of the this could be constructed later...
|
---|
| 94 | ;"Result: 0 if no error; >0 if error
|
---|
| 95 | ;"Notice!!!! The return code here is DIFFERENT from usual
|
---|
| 96 |
|
---|
| 97 | new HookCmd,result
|
---|
| 98 | new Srch
|
---|
| 99 | set Srch(" ")="\ "
|
---|
| 100 | set Source=$$REPLACE^XLFSTR(Source,.Srch)
|
---|
| 101 | set Dest=$$REPLACE^XLFSTR(Dest,.Srch)
|
---|
| 102 | set HookCmd="mv "_Source_" "_Dest
|
---|
| 103 | zsystem HookCmd
|
---|
| 104 | set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
|
---|
| 105 | quit result
|
---|
| 106 |
|
---|
| 107 |
|
---|
| 108 | Copy(Source,Dest)
|
---|
| 109 | ;"Purpose to provide a shell for the Linux command 'cp'
|
---|
| 110 | ;" This can serve to move or rename a file
|
---|
| 111 | ;"Note: a platform independant version of the this could be constructed later...
|
---|
| 112 | ;"Result: 0 if no error; >0 if error
|
---|
| 113 | ;"Notice!!!! The return code here is DIFFERENT from usual
|
---|
| 114 |
|
---|
| 115 | new HookCmd,result
|
---|
| 116 | new Srch
|
---|
| 117 | set Srch(" ")="\ "
|
---|
| 118 | set Source=$$REPLACE^XLFSTR(Source,.Srch)
|
---|
| 119 | set Dest=$$REPLACE^XLFSTR(Dest,.Srch)
|
---|
| 120 | set HookCmd="cp "_Source_" "_Dest
|
---|
| 121 | zsystem HookCmd
|
---|
| 122 | set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
|
---|
| 123 | quit result
|
---|
| 124 |
|
---|
| 125 | mkdir(Dir)
|
---|
| 126 | ;"Purpose to provide a shell for the Linux command 'mkdir'
|
---|
| 127 | ;"Note: a platform independant version of the this could be constructed later...
|
---|
| 128 | ;"Result: 0 if no error; >0 if error
|
---|
| 129 | ;"Notice!!!! The return code here is DIFFERENT from usual
|
---|
| 130 |
|
---|
| 131 | new HookCmd,result
|
---|
| 132 | new Srch set Srch(" ")="\ "
|
---|
| 133 | set Dir=$$REPLACE^XLFSTR(Dir,.Srch)
|
---|
| 134 | set HookCmd="mkdir "_Dir
|
---|
| 135 | zsystem HookCmd
|
---|
| 136 | set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
|
---|
| 137 | quit result
|
---|
| 138 |
|
---|
| 139 | rmdir(Dir)
|
---|
| 140 | ;"Purpose to provide a shell for the Linux command 'rmdir'
|
---|
| 141 | ;"Note: a platform independant version of the this could be constructed later...
|
---|
| 142 | ;"Result: 0 if no error; >0 if error
|
---|
| 143 | ;"Notice!!!! The return code here is DIFFERENT from usual
|
---|
| 144 |
|
---|
| 145 | new HookCmd,result
|
---|
| 146 | new Srch set Srch(" ")="\ "
|
---|
| 147 | set Dir=$$REPLACE^XLFSTR(Dir,.Srch)
|
---|
| 148 | set HookCmd="rmdir "_Dir
|
---|
| 149 | zsystem HookCmd
|
---|
| 150 | set result=$ZSYSTEM&255 ;"get result of execution. (low byte only)
|
---|
| 151 | quit result
|
---|
| 152 |
|
---|
| 153 |
|
---|
| 154 | Convert(FPathName,NewType)
|
---|
| 155 | ;"Purpose: to convert a graphic image on the linux host to new type
|
---|
| 156 | ;" i.e. image.jpg --> image.png. This is more than a simple renaming.
|
---|
| 157 | ;"Input: FPathName -- full path, filename and extention. E.g. "\tmp\image.jpg"
|
---|
| 158 | ;" NewType -- the new image type (without '.'),
|
---|
| 159 | ;" E.g. "jpg", or "JPG", or "TIFF", or "pcd" (NOT ".jpg" etc)
|
---|
| 160 | ;"Output: New FPathName (with new extension) to new image file, or "" if problem
|
---|
| 161 | ;"
|
---|
| 162 | ;"Note: If the conversion is successful, then the original image will be deleted
|
---|
| 163 | ;"Note: This function depends on the ImageMagick graphic utility "convert" to be
|
---|
| 164 | ;" installed on the host linux system, and in the path so that it can be
|
---|
| 165 | ;" launched from any directory.
|
---|
| 166 |
|
---|
| 167 | new newFPathName set newFPathName=""
|
---|
| 168 | set NewType=$get(NewType)
|
---|
| 169 | if NewType="" goto ConvDone
|
---|
| 170 |
|
---|
| 171 | new FName,FPath,FileSpec
|
---|
| 172 | do SplitFNamePath^TMGIOUTL(FPathName,.FPath,.FName,"/")
|
---|
| 173 | set FileSpec(FName)=""
|
---|
| 174 |
|
---|
| 175 | set newFPathName=$piece(FPathName,".",1)_"."_NewType
|
---|
| 176 |
|
---|
| 177 | ;"Setup and launch linux command to execute convert
|
---|
| 178 | new CmdStr
|
---|
| 179 | set CmdStr="convert "_FPathName_" "_newFPathName
|
---|
| 180 | do
|
---|
| 181 | . ;"new $ETRAP,$ZTRAP
|
---|
| 182 | . ;"set $ETRAP="S $ECODE="""""
|
---|
| 183 | . zsystem CmdStr ;"Launch command
|
---|
| 184 |
|
---|
| 185 | ;"get result of execution. (low byte only) -- if wanted
|
---|
| 186 | new CmdResult set CmdResult=$ZSYSTEM&255
|
---|
| 187 | if CmdResult'=0 do goto ConvDone
|
---|
| 188 | . set newFPathName=""
|
---|
| 189 |
|
---|
| 190 | ;"Delete old image file
|
---|
| 191 | ;"**** temp!!!!! REMOVE COMMENTS LATER
|
---|
| 192 | ;"new temp set temp=$$DEL^%ZISH(FPath,"FileSpec")
|
---|
| 193 |
|
---|
| 194 | ConvDone
|
---|
| 195 | quit newFPathName
|
---|
| 196 |
|
---|
| 197 |
|
---|
| 198 | XLTLANG(Phrase,langPair)
|
---|
| 199 | ;"Purpose: To execute a linux OS call to convert a phrase into another
|
---|
| 200 | ;" spoken language
|
---|
| 201 | ;"Input: Phrase -- The text to be translated.
|
---|
| 202 | ;" LangPair -- a language pair (as allowed by Google translater)
|
---|
| 203 | ;" for now, tested pairs are:
|
---|
| 204 | ;" "en-es" -- english -> spanish
|
---|
| 205 | ;" "en-fr" -- english --> french
|
---|
| 206 | ;" "en-da" -- english --> ?
|
---|
| 207 | ;"Result: The translated text, or "" if error.
|
---|
| 208 | ;"Note: This depends on the "tw" package be installed in the host OS
|
---|
| 209 | ;" I got this on 7/11/08 from: http://savannah.nongnu.org/projects/twandgtw/
|
---|
| 210 | ;"Note: This is not working for some reason.....
|
---|
| 211 |
|
---|
| 212 | new result set result=""
|
---|
| 213 | set langPair=$get(langPair,"en-es")
|
---|
| 214 | set Phrase=$get(Phrase,"?? Nothing Provided ??")
|
---|
| 215 |
|
---|
| 216 | new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/TransLang.txt")
|
---|
| 217 |
|
---|
| 218 | ;"Setup and launch linux command to execute tw command
|
---|
| 219 | new CmdStr
|
---|
| 220 | set CmdStr="tw translate.google.com."_langPair_" """_Phrase_""" > """_msgFName_""""
|
---|
| 221 |
|
---|
| 222 | ;"write "About to execute zsystem command:",!,CmdStr,!
|
---|
| 223 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 224 | ;"write "Back from zsystem",!
|
---|
| 225 |
|
---|
| 226 | ;"get result of execution. (low byte only) -- if wanted
|
---|
| 227 | new CmdResult set CmdResult=$ZSYSTEM&255
|
---|
| 228 | if CmdResult'=0 goto TLDone
|
---|
| 229 |
|
---|
| 230 | new FName,FPath
|
---|
| 231 | do SplitFNamePath^TMGIOUTL(msgFName,.FPath,.FName,"/")
|
---|
| 232 | new resultArray
|
---|
| 233 | if $$FTG^%ZISH(FPath,FName,"resultArray(0)",1)=0 goto TLDone
|
---|
| 234 | set result=$get(resultArray(0))
|
---|
| 235 |
|
---|
| 236 | TLDone
|
---|
| 237 | quit result
|
---|
| 238 |
|
---|
| 239 |
|
---|
| 240 | TestTrans
|
---|
| 241 | set langPair=$get(langPair,"en-es")
|
---|
| 242 | set Phrase=$get(Phrase,"Hello friend")
|
---|
| 243 | new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/TransLang.txt")
|
---|
| 244 |
|
---|
| 245 | new CmdStr
|
---|
| 246 | new qtChar set qtChar="'"
|
---|
| 247 |
|
---|
| 248 | set CmdStr="sh /var/local/OpenVistA_UserData/twlang.sh "_qtChar_langPair_qtChar_" "_qtChar_Phrase_qtChar_" "_msgFName
|
---|
| 249 | write "About to execute zsystem command:",!,CmdStr,!
|
---|
| 250 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 251 | write "Back from zsystem",!
|
---|
| 252 |
|
---|
| 253 | set qtChar=""""
|
---|
| 254 | set CmdStr="sh /var/local/OpenVistA_UserData/twlang.sh "_qtChar_langPair_qtChar_" "_qtChar_Phrase_qtChar_" "_msgFName
|
---|
| 255 | write "About to execute zsystem command:",!,CmdStr,!
|
---|
| 256 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 257 | write "Back from zsystem",!
|
---|
| 258 |
|
---|
| 259 | quit
|
---|
| 260 |
|
---|
| 261 |
|
---|
| 262 | GetPckList(PckInit,Array,NeedsRefresh,PckDirFName)
|
---|
| 263 | ;"Purpose: Call Linux, launching special script to get patch file list from ftp.va.gov
|
---|
| 264 | ;" This is a support function for automating the KIDS installation of patches.
|
---|
| 265 | ;"Input: PckInit -- this is the namespace of the package to get patches for, e.g. 'DI' for fileman
|
---|
| 266 | ;" Array -- PASS BY REFERENCE. An OUT parameter. Format:
|
---|
| 267 | ;" Array(0)=1st line
|
---|
| 268 | ;" Array(1)=2nd line etc.
|
---|
| 269 | ;" NeedsRefresh -- if 0 then no refresh needed, just set PckDirFName (but ensure file exists)
|
---|
| 270 | ;" PckDirFName -- Optional. PASS BY REFERNCE, an OUT PARAMETER. Filled with HFS filename of file
|
---|
| 271 | ;"Result : 1=success, 0=failure
|
---|
| 272 |
|
---|
| 273 | new result set result=1 ;"success
|
---|
| 274 | kill Array
|
---|
| 275 | if $get(PckInit)="" set result=0 goto GPLDone
|
---|
| 276 |
|
---|
| 277 | ;"Results will be stored in /<dir>/ftp.va.gov-dirFor-'PckInit'
|
---|
| 278 | new FName,FPath
|
---|
| 279 | ;"Fix this.... check if path exists.....
|
---|
| 280 | set FPath=$get(^TMG("KIDS","PATCH DIR"))
|
---|
| 281 | if (FPath="")!($$IsDir^TMGKERNL(FPath)=0) do
|
---|
| 282 | . new Msg set Msg="Please choose a file path for storing VA patches in."
|
---|
| 283 | . set FPath=$$GetDirName^TMGIOUTL2(Msg,DefPath,"/","Pick directory")
|
---|
| 284 | if FPath="" set result=0 goto GPLDone
|
---|
| 285 | set FName="ftp.va.gov-dirFor-"_PckInit
|
---|
| 286 | set PckDirFName=FPath_FName
|
---|
| 287 | if ($get(NeedsRefresh)'>0)&($$FileExists^TMGIOUTL(PckDirFName)) goto GPLDone
|
---|
| 288 |
|
---|
| 289 | new FPScript set FPScript=$get(^TMG("KIDS","VA FTP Script"))
|
---|
| 290 | if (FPScript'=""),($$FileExists^TMGIOUTL(FPScript)=0) do
|
---|
| 291 | . kill ^TMG("KIDS","VA FTP Script")
|
---|
| 292 | . set FPScript=""
|
---|
| 293 | if FPScript="" do
|
---|
| 294 | . new msg set msg="Linux script needed: vaftp_launcher.sh\n"
|
---|
| 295 | . set msg=msg_"Please browse to this script and select it after the pause."
|
---|
| 296 | . set FPScript=$$GetFName^TMGIOUTL(msg,"/","vaftp_launcher.sh")
|
---|
| 297 | . if $$FileExists^TMGIOUTL(FPScript) do
|
---|
| 298 | . . set ^TMG("KIDS","VA FTP Script")=FPScript
|
---|
| 299 | . else do
|
---|
| 300 | . . write "ERROR: Choice of "_FPScript_" is invalid. Aborting."
|
---|
| 301 | . . set FPScript=""
|
---|
| 302 | if FPScript="" set result=0 goto GPLDone
|
---|
| 303 |
|
---|
| 304 | new CmdStr set CmdStr=FPScript_" "_PckInit_" "_FPath
|
---|
| 305 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 306 |
|
---|
| 307 | ;"get result of execution. (low byte only) -- if wanted
|
---|
| 308 | new CmdResult set CmdResult=$ZSYSTEM&255
|
---|
| 309 | if CmdResult'=0 do
|
---|
| 310 | . ;"Failed, so get log file instead of results
|
---|
| 311 | . set FName="ftp.va.gov_log"
|
---|
| 312 | . set result=1 ;"success
|
---|
| 313 |
|
---|
| 314 | GPL2 ;"Get results file (or log file if problem)
|
---|
| 315 | if $$FTG^%ZISH(FPath,FName,"Array(0)",1)=0 set result=0 goto GPLDone
|
---|
| 316 |
|
---|
| 317 | GPLDone
|
---|
| 318 | quit result
|
---|
| 319 |
|
---|
| 320 |
|
---|
| 321 | DownloadFile(URL,DestDir,Verbose)
|
---|
| 322 | ;"Purpose: Interact with Linux to download a file with wget
|
---|
| 323 | ;"Input: URL -- this is the URL of the file to be downloaded, as to be passed to wget
|
---|
| 324 | ;" if the server is an FTP server, then URL should start with 'ftp://'
|
---|
| 325 | ;" NOTE: the URL will be enclosed in " ", so it may contain spaces etc,
|
---|
| 326 | ;" but should NOT have escaped characters, i.e. "Not\ this"
|
---|
| 327 | ;" Exception "April Fool'\''s Day" is proper
|
---|
| 328 | ;" DestDir -- this is the destination directory, on the HFS, where file should be stored
|
---|
| 329 | ;" Verbose -- OPTIONAL. If 1, then output from wget is shown. Default is 0
|
---|
| 330 | ;"result: 1 if success, 0 if failure
|
---|
| 331 |
|
---|
| 332 | ;"NOTE: This needs to be rewritten to use the vawget_launcher because wget it
|
---|
| 333 | ;" hanging when the file doesn't exist, and the process has to be aborted...
|
---|
| 334 |
|
---|
| 335 | new CmdStr,qFlag
|
---|
| 336 | ;"Setup and launch linux command to execute command
|
---|
| 337 | if +$get(Verbose) set qFlag=""
|
---|
| 338 | else set qFlag="-q "
|
---|
| 339 | set CmdStr="wget "_qFlag_"-P """_DestDir_""" """_URL_""""
|
---|
| 340 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 341 |
|
---|
| 342 | ;"get result of execution. (low byte only)
|
---|
| 343 | new CmdResult set CmdResult=$ZSYSTEM&255
|
---|
| 344 | new result set result=(CmdResult=0)
|
---|
| 345 |
|
---|
| 346 | quit result
|
---|
| 347 |
|
---|
| 348 |
|
---|
| 349 | EditHFSFile(FilePathName)
|
---|
| 350 | ;"Purpose: interact with Linux to edit a file on the host file system
|
---|
| 351 | ;"Input: FilePathName -- the full path of the file to edit.
|
---|
| 352 | ;"result: 1 if success, 0 if failure
|
---|
| 353 |
|
---|
| 354 | ;"Setup and launch linux command to execute command
|
---|
| 355 | new CmdStr set CmdStr="nano "_FilePathName
|
---|
| 356 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 357 |
|
---|
| 358 | ;"get result of execution. (low byte only)
|
---|
| 359 | new CmdResult set CmdResult=$ZSYSTEM&255
|
---|
| 360 | new result set result=(CmdResult=0)
|
---|
| 361 | quit result
|
---|
| 362 |
|
---|
| 363 |
|
---|
| 364 | ZSAVE
|
---|
| 365 | ;"Purpose: to save routine out to HFS
|
---|
| 366 | ;"Input: globally scoped variable X should hold routine name
|
---|
| 367 |
|
---|
| 368 | ;"NOTE: this was moved out of ^DD("OS",19,"ZS")
|
---|
| 369 | ;"Original line there was (all three lines were one long line)
|
---|
| 370 | ;"N %I,%F,%S S %I=$I,%F=$P($P($ZRO,")"),"(",2)_"/"_X_".m" O %F:(NEWVERSION)
|
---|
| 371 | ;"U %F X "S %S=0 F S %S=$O(^UTILITY($J,0,%S)) Q:%S="""" Q:'$D(^(%S)) S %=
|
---|
| 372 | ;"^UTILITY($J,0,%S) I $E(%)'="";"" W %,!" C %F U %I
|
---|
| 373 |
|
---|
| 374 | ;"NOTE: The KIDS system seems to be using X ^%ZOSF("SAVE") instead of this.
|
---|
| 375 |
|
---|
| 376 | new %I,%F,%S
|
---|
| 377 | new % ;"//kt added -- not newing this caused problems in SAVE^DIKZ
|
---|
| 378 | set %I=$I
|
---|
| 379 | new %DIR set %DIR=$P($P($ZRO,")"),"(",2)
|
---|
| 380 | set %DIR=$piece(%DIR," ",$length(%DIR," "))
|
---|
| 381 | set %F=%DIR_"/"_X_".m"
|
---|
| 382 | open %F:(NEWVERSION)
|
---|
| 383 | use %F
|
---|
| 384 | set %S=0
|
---|
| 385 | for set %S=$O(^UTILITY($J,0,%S)) Q:%S="" Q:'$D(^(%S)) do
|
---|
| 386 | . set %=^UTILITY($J,0,%S)
|
---|
| 387 | . if $E(%)'=";" W %,!
|
---|
| 388 | close %F
|
---|
| 389 | use %I
|
---|
| 390 |
|
---|
| 391 | quit
|
---|
| 392 |
|
---|
| 393 |
|
---|
| 394 | MAKEBAKF(FilePathName,NodeDiv) ;"Make Backup File if original exists
|
---|
| 395 | ;"Purpose: to COPY existing File to File-ext_#.bak, creating a backup
|
---|
| 396 | ;" e.g. /tmp/dir1/FName.txt --> /tmp/dir1/FName-txt_1.bak
|
---|
| 397 | ;"Input: FilePathName -- the name, e.g. /tmp/dir1/filename.txt
|
---|
| 398 | ;" NodeDiv -- OPTIONAL. Default is "/"
|
---|
| 399 | ;" The node divider. "/" for unix, "\" for Microsoft
|
---|
| 400 | ;"results: none
|
---|
| 401 | ;"Note: This assumes that the HFS supports filenames like FName-txt_1.bak,
|
---|
| 402 | ;" and length file name is not limited (e.g. not old 8.3 DOS style)
|
---|
| 403 | ;" Also, if backup file, then number is incremented until a filename is found that doesn't exists
|
---|
| 404 | ;" e.g. /tmp/dir1/FName-txt_1.bak
|
---|
| 405 | ;" /tmp/dir1/FName-txt_2.bak
|
---|
| 406 | ;" /tmp/dir1/FName-txt_3.bak
|
---|
| 407 |
|
---|
| 408 | set NodeDiv=$get(NodeDiv,"/")
|
---|
| 409 | if $$FileExists^TMGIOUTL(FilePathName) do ;"backup file if it exists
|
---|
| 410 | . new count set count=0
|
---|
| 411 | . new FName,FPath,done
|
---|
| 412 | . do SplitFNamePath^TMGIOUTL(FilePathName,.FPath,.FName,NodeDiv)
|
---|
| 413 | . for do quit:done
|
---|
| 414 | . . set count=count+1
|
---|
| 415 | . . new bakName set bakName=FName_"_"_count
|
---|
| 416 | . . set bakName=FPath_$translate(bakName,".","-")_".bak"
|
---|
| 417 | . . if $$FileExists^TMGIOUTL(bakName) set done=0 quit
|
---|
| 418 | . . else do
|
---|
| 419 | . . . set done=1
|
---|
| 420 | . . . if $$Copy(FilePathName,bakName)
|
---|
| 421 |
|
---|
| 422 | quit
|
---|
| 423 |
|
---|
| 424 | IOCapON
|
---|
| 425 | ;"Purpose: to redirect IO to a HFS file, so that it can be captured.
|
---|
| 426 | ;"NOTE: CAUTION: If this is called, and then a routine asks for user input,
|
---|
| 427 | ;" then the program will appear to hang, because the message asking
|
---|
| 428 | ;" for input has gone to the output channel.
|
---|
| 429 |
|
---|
| 430 | set TMGIOCAP=IO
|
---|
| 431 | set TMGIOCPT="/tmp/"
|
---|
| 432 | set TMGIOCFN="io-capture-"_$J_".txt"
|
---|
| 433 | set IO=TMGIOCPT_TMGIOCFN
|
---|
| 434 | open IO:(REWIND)
|
---|
| 435 | use IO
|
---|
| 436 |
|
---|
| 437 | quit
|
---|
| 438 |
|
---|
| 439 |
|
---|
| 440 | IOCapOFF(pOutArray)
|
---|
| 441 | ;"Purpose: To restore IO channel to that prior IOCapON was called, and return
|
---|
| 442 | ;" captured output in OutArray
|
---|
| 443 | ;"NOTE: MUST call IOCapON prior to calling this function
|
---|
| 444 | ;"Input: Globally-scoped TMGIOCAP is used.
|
---|
| 445 | ;" pOutArray -- PASS BY NAME, an OUT PARAMETER. Prior contents are killed.
|
---|
| 446 | ;"results: none
|
---|
| 447 |
|
---|
| 448 | close IO
|
---|
| 449 | if $get(TMGIOCAP)="" use $P goto IOCDone
|
---|
| 450 | set IO=TMGIOCAP
|
---|
| 451 | use IO
|
---|
| 452 | if $get(pOutArray)="" goto IOCDone
|
---|
| 453 | kill @pOutArray
|
---|
| 454 |
|
---|
| 455 | if ($get(TMGIOCPT)="")!($get(TMGIOCFN)="") goto IOCDone
|
---|
| 456 | if $$FTG^%ZISH(TMGIOCPT,TMGIOCFN,$name(@pOutArray@(0)),1)
|
---|
| 457 | new TMGA set TMGA(TMGIOCFN)=""
|
---|
| 458 | if $$DEL^%ZISH(TMGIOCPT,"TMGA")
|
---|
| 459 |
|
---|
| 460 | IOCDone quit
|
---|
| 461 |
|
---|
| 462 | KillPID(JobNum)
|
---|
| 463 | ;"Purpose: send message to MUPIP to kill Job
|
---|
| 464 | new CmdStr set CmdStr="mupip stop "_JobNum
|
---|
| 465 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 466 | ;"do PressToCont^TMGUSRIF
|
---|
| 467 | quit
|
---|
| 468 |
|
---|
| 469 | TEST
|
---|
| 470 | new array
|
---|
| 471 | new p set p="temp"
|
---|
| 472 | open p:(COMMAND="ps -C mumps":readonly)::"pipe"
|
---|
| 473 | use p
|
---|
| 474 | new lineIn
|
---|
| 475 | for do quit:($zeof)
|
---|
| 476 | . read lineIn
|
---|
| 477 | . new ch for do quit:(ch'=" ")
|
---|
| 478 | . . set ch=$extract(lineIn,1,1)
|
---|
| 479 | . . if ch=" " set lineIn=$extract(lineIn,2,40)
|
---|
| 480 | . if +lineIn=0 quit
|
---|
| 481 | . set array(+lineIn)=lineIn
|
---|
| 482 | close p
|
---|
| 483 | use $p
|
---|
| 484 | zwr array
|
---|
| 485 | quit
|
---|
| 486 |
|
---|
| 487 | MJOBS(array)
|
---|
| 488 | ;"Purpose: To execute a linux OS call to get list of all 'mumps' jobs
|
---|
| 489 | ;" using: 'ps -C mumps'
|
---|
| 490 | ;"Input: array -- PASS BY REFERNCE, an OUT PARAMETER.
|
---|
| 491 | ;"Output: array is filled as follows: (Prior data is killed)
|
---|
| 492 | ;" array(job#)=InfoLineFromOS
|
---|
| 493 | ;" array(job#)=InfoLineFromOS
|
---|
| 494 | ;" e.g. array(4483)=' 4883 pts/8 00:00:00 mumps'
|
---|
| 495 | ;" e.g. array(19308)='19308 ? 00:00:00 mumps'
|
---|
| 496 | ;" e.g. array(27454)='27454 pts/5 00:00:53 mumps'
|
---|
| 497 | ;"Result: none
|
---|
| 498 |
|
---|
| 499 | new p set p="temp"
|
---|
| 500 | open p:(COMMAND="ps -C mumps":readonly)::"pipe"
|
---|
| 501 | use p
|
---|
| 502 | new lineIn,ch
|
---|
| 503 | for do quit:($zeof)
|
---|
| 504 | . read lineIn
|
---|
| 505 | . for do quit:(ch'=" ")
|
---|
| 506 | . . set ch=$extract(lineIn,1,1) quit:(ch'=" ")
|
---|
| 507 | . . set lineIn=$extract(lineIn,2,40)
|
---|
| 508 | . if +lineIn=0 quit
|
---|
| 509 | . set array(+lineIn)=lineIn
|
---|
| 510 | close p
|
---|
| 511 | use $p
|
---|
| 512 | quit
|
---|
| 513 |
|
---|
| 514 | ;"====== old method below ==============
|
---|
| 515 | kill array
|
---|
| 516 | new msgFName set msgFName=$$UNIQUE^%ZISUTL("/tmp/mjobslist.txt")
|
---|
| 517 | new CmdStr set CmdStr="ps -C mumps > """_msgFName_""""
|
---|
| 518 | zsystem CmdStr ;"Launch command in linux OS
|
---|
| 519 | ;
|
---|
| 520 | ;"get result of execution. (low byte only) -- if wanted
|
---|
| 521 | new CmdResult set CmdResult=$ZSYSTEM&255
|
---|
| 522 | if CmdResult'=0 goto MJDone
|
---|
| 523 | ;
|
---|
| 524 | new FName,FPath
|
---|
| 525 | do SplitFNamePath^TMGIOUTL(msgFName,.FPath,.FName,"/")
|
---|
| 526 | new resultArray
|
---|
| 527 | if $$FTG^%ZISH(FPath,FName,"resultArray(0)",1)=0 goto TLDone
|
---|
| 528 | ;
|
---|
| 529 | ;"Delete temp info file
|
---|
| 530 | new FileSpec set FileSpec(FName)=""
|
---|
| 531 | new temp set temp=$$DEL^%ZISH(FPath,"FileSpec")
|
---|
| 532 | ;
|
---|
| 533 | ;"Format resulting array
|
---|
| 534 | new i set i=0
|
---|
| 535 | for set i=$order(resultArray(i)) quit:(i'>0) do
|
---|
| 536 | . new j set j=$extract(resultArray(i),1,5)
|
---|
| 537 | . new ch for do quit:(ch'=" ")
|
---|
| 538 | . . set ch=$extract(j,1,1)
|
---|
| 539 | . . if ch=" " set j=$extract(j,2,40)
|
---|
| 540 | . set array(+j)=resultArray(i)
|
---|
| 541 | ;
|
---|
| 542 | MJDone quit
|
---|
| 543 |
|
---|
| 544 |
|
---|
| 545 | GetScrnSize(ROWS,COLS)
|
---|
| 546 | ;"Purpose: To query the OS and get the dimensions of the terminal window
|
---|
| 547 | ;"Input: ROWS,COLS -- Optional. PASS BY REFERENCE. Filled with results
|
---|
| 548 | ;"Results: Row^Col e.g. '24^80', or '0^0' if problem.
|
---|
| 549 | ;"Note: thanks Bhaskar for figuring this out!
|
---|
| 550 | new p set p="myTerm"
|
---|
| 551 | open p:(COMMAND="stty -a -F "_$p_"|grep columns":readonly)::"pipe"
|
---|
| 552 | new x
|
---|
| 553 | for use p read x quit:($zeof)!(x["columns")
|
---|
| 554 | close p use $p
|
---|
| 555 | set COLS=+$piece(x,"columns ",2)
|
---|
| 556 | set ROWS=+$piece(x,"rows ",2)
|
---|
| 557 | quit ROWS_"^"_COLS
|
---|