/*:VRX Main */ /* Poor man's Samba print utility Copyright (C) 2007-2017 Herwig Bauernfeind for bww bitwise works GmbH. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* Main */ Main: /* Process the arguments. Get the parent window. */ parse source . calledAs . parent = "" argCount = arg() argOff = 0 if( calledAs \= "COMMAND" )then do if argCount >= 1 then do parent = arg(1) argCount = argCount - 1 argOff = 1 end end; else do call VROptions 'ImplicitNames' call VROptions 'NoEchoQuit' end InitArgs.0 = argCount if( argCount > 0 )then do i = 1 to argCount InitArgs.i = arg( i + argOff ) end drop calledAs argCount argOff /* Load the windows */ call VRInit parse source . . spec _VREPrimaryWindowPath = , VRParseFileName( spec, "dpn" ) || ".VRW" _VREPrimaryWindow = , VRLoad( parent, _VREPrimaryWindowPath ) drop parent spec if( _VREPrimaryWindow == "" )then do call VRMessage "", "Cannot load window:" VRError(), , "Error!" _VREReturnValue = 32000 signal _VRELeaveMain end /* Process events */ call Init signal on halt do while( \ VRGet( _VREPrimaryWindow, "Shutdown" ) ) _VREEvent = VREvent() interpret _VREEvent end _VREHalt: _VREReturnValue = Fini() call VRDestroy _VREPrimaryWindow _VRELeaveMain: call VRFini exit _VREReturnValue VRLoadSecondary: __vrlsWait = abbrev( 'WAIT', translate(arg(2)), 1 ) if __vrlsWait then do call VRFlush end __vrlsHWnd = VRLoad( VRWindow(), VRWindowPath(), arg(1) ) if __vrlsHWnd = '' then signal __vrlsDone if __vrlsWait \= 1 then signal __vrlsDone call VRSet __vrlsHWnd, 'WindowMode', 'Modal' __vrlsTmp = __vrlsWindows.0 if( DataType(__vrlsTmp) \= 'NUM' ) then do __vrlsTmp = 1 end else do __vrlsTmp = __vrlsTmp + 1 end __vrlsWindows.__vrlsTmp = VRWindow( __vrlsHWnd ) __vrlsWindows.0 = __vrlsTmp do while( VRIsValidObject( VRWindow() ) = 1 ) __vrlsEvent = VREvent() interpret __vrlsEvent end __vrlsTmp = __vrlsWindows.0 __vrlsWindows.0 = __vrlsTmp - 1 call VRWindow __vrlsWindows.__vrlsTmp __vrlsHWnd = '' __vrlsDone: return __vrlsHWnd /*:VRX _ShowMsg */ _ShowMsg: Buttons.1 = "OK" Buttons.0 = 1 id = VRMessage( VRWindow(), Msg.Text, Msg.Title, Msg.Type, "Buttons.", buttons.1, buttons.1 ) return/*:VRX Fini */ Fini: window = VRWindow() call VRSet window, "Visible", 0 drop window return 0 /*:VRX Halt */ Halt: signal _VREHalt return /*:VRX Init */ Init: window = VRWindow() /* call VRMethod window, "CenterWindow" */ call VRSet window, "Visible", 1 call VRMethod window, "Activate" drop window return /*:VRX Main_Close */ Main_Close: call Quit return /*:VRX Main_Create */ Main_Create: debug = 0 if debug = 1 then ok = VRRedirectStdIO("ON") else ok = VRRedirectStdIO("OFF") PrintParms = VRGet("Application","Commandline") spooldir = directory() if debug = 1 then say 'Printparms: "'Printparms'"' if debug = 1 then say 'Length : 'length(PrintParms) if PrintParms <> "" then do parse var PrintParms '"'spoolfile'" "'smbprintername'" "'Jobname'" "'pages'" "'JobSize'"' if debug = 1 then say 'Directory: "'spooldir'"' if debug = 1 then say 'Spoolfile: "'spoolfile'"' if debug = 1 then say 'Smbprinter: "'smbprintername'"' ok = VRMethod( "Application", "ListPrinters", "printer." ) FoundQueue = 0 if ok = 1 then do do i = 1 to printer.0 if debug = 1 then say printer.i parse value printer.i with PName';'PQueue';'Rest if debug = 1 then say 'Queue: 'PName'<-->'PQueue if translate(PQueue) = translate(smbprintername) then do FoundQueue = 1 leave end end end if FoundQueue then do ok = VRset("DT_Job","Caption", 'Print "'Jobname'" ('Pages', 'JobSize' bytes) to "'PName'"') ok = VRPrintFile( smbprintername, spooldir'\'spoolfile, , JobName ) if debug = 1 then say " ->"smbprintername", "spooldir"\"spoolfile", , "JobName ok = SysSleep(10) if debug = 1 then ok = VRRedirectStdIO("OFF") end else do Msg.Title = "Samba Print Command for OS/2" Msg.Type = "E" Msg.Text = 'Invalid (non existent) print queue specified in smb.conf: "'smbprintername'"' call _ShowMsg end ok = -255 do while ok <> 0 ok = SysSleep(2) ok = SysFileDelete(Spoolfile) end end else do Msg.Title = "Samba Print Command for OS/2" Msg.Type = "I" Msg.Text = 'smbprint.exe "spoolfile" "printerqueue" "jobname" "pages" "jobsize"' call _ShowMsg end call Quit return /*:VRX Quit */ Quit: window = VRWindow() call VRSet window, "Shutdown", 1 drop window return