/*
** Module   : jctrlpnl.cmd
** Abstract : Wrapper program to launch the OJI Plugin Control Panel.
**
** Copyright (c) 2003, Golden Code Development Corporation.
** ALL RIGHTS RESERVED. Use is subject to license terms.
**
**           Golden Code Development Corporation
**                      CONFIDENTIAL
**
*/

/* Notes:
 *
 * 1. This program must reside in the jre\bin directory to
 *    properly find the java.exe launcher and the plugin
 *    jar file.
 * 2. The program has been named the same name as in the
 *    IBM JVM so that users will be able to easily find
 *    it.  The IBM source was not used to create this, it
 *    was written from scratch by GCD.
 */

parse source . . path

   drive     = filespec( "DRIVE", path )
   bin_dir   = drive || filespec( "PATH", path )
   home_pos  = lastpos( "\", bin_dir, (length( bin_dir )-1) )
   java_home = substr( bin_dir, 1, home_pos )
   lib_dir   = java_home"lib\"
   class     = "sun.plugin.panel.ControlPanel"

   res = get_version()

   if res = '' then
   do
      say 'Unable to locate JAVA.EXE launcher.'
      exit
   end

   address cmd '@'bin_dir"java.exe -Djavaplugin.version="version,
                                 " -Djavaplugin.nodotversion="nodotversion,
                                 " -classpath "lib_dir"javaplugin.jar; "class
exit

get_version: procedure expose bin_dir version  nodotversion
   work_queue='jqueue'

   /* Retrieve version string from JVM launcher */

   /* Use safe approach */

   new_queue = RXQUEUE('Create', work_queue)
   old_queue = RXQUEUE('Set'   , new_queue)

   address cmd '@'bin_dir"java.exe -version 2>&1 | rxqueue "work_queue

   res = rc

   /* first string is whet we're looking for */

   parse pull version_string

   /* Clean up remaining data in queue */

   do while queued() > 0
      parse pull str
   end

   call RXQUEUE 'Set'   , old_queue
   call RXQUEUE 'Delete', new_queue

   if res \= 0
      then return ''

   parse value version_string with .'"'version'"'.

   parse value version with version'_'.

   nodotversion=version

   dot_pos = pos('.', nodotversion)

   do while dot_pos > 0
      nodotversion=delstr(nodotversion, dot_pos, 1)
      dot_pos = pos('.', nodotversion)
   end
return version' 'nodotversion
