This version have been changed to use an array variable (stem variable) for the 
menus.

It seems to not work well with new users, because it ask directly to choose the 
unit to convert to... not asking units to convert from.

Was saved on a Windows computer... frankly unsure if it means that line 
conversions were done.

It now does cls as requested by a new user... the new user also ask to center 
stuff... not done yet.

Including program here... for the archive to get it:

/*
Copyright 2024 Paul Dufresne (dufres...@zoho.com)

Permission is hereby granted, free of charge, to any person obtaining a copy of 
this software and
associated documentation files (the “Software”), to deal in the Software 
without restriction,
including without limitation the rights to use, copy, modify, merge, publish, 
distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software 
is furnished to do so.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 
AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 
CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

/* This program is written in REXX...
see https://rexxinfo.org/reference/index_reference.html for more
information about this programming language. */

/* This program allows you to convert from one unit of measure to an other one. 
*/

/* This program when named ConvREXXter_v1.0.rex can be executed with: regina 
ConvREXXter_v1.0.rex or rexx ConvREXXter_v1.0.rex */

options ANSI

noreturn = 1  /* If 1, menus will not need you to type Return after choice, but 
not REXX ANSI */
/* noreturn get your menu answer with GeySysKey rather than pull */

docls = 1  /* If 1, screen will be cleared before showing a menu */

menus.='NOTTHERE'
menus.0.title='Types of conversions'
menus.1.text='Temperature'
menus.1.id='TEMP'
menus.2.text='Weight'
menus.2.id='WEIGHT'
menus.3.text='Speed'
menus.3.id='SPD'
menus.4.text='Distance'
menus.4.id='DIST'
menus.5.text='Volume'
menus.5.id='VOL'
menus.6.text='Area'
menus.6.id='AREA'
menus.7.text='Pression'
menus.7.id='PRS'
menus.8.text='Power'
menus.8.id='PWR'

menus.1.0.title='Temperature conversions'
menus.1.1.text='Celsius'
menus.1.1.id='C'
menus.1.2.text='Farenheits'
menus.1.2.id='F'
menus.1.3.text='Kelvins'
menus.1.3.id='K'

menus.2.0.title='Weight conversions'
menus.2.1.text='Pounds'
menus.2.1.id='LB'
menus.2.1.conv=2.20462
menus.2.2.text='Kilograms'
menus.2.2.id='KG'
menus.2.2.conv=1
menus.2.3.text='Ounces'
menus.2.3.id='OZ'
menus.2.3.conv=35.274
menus.2.4.text='Grams'
menus.2.4.id='G'
menus.2.4.conv=1000

menus.3.0.title='Speed conversions'
menus.3.1.text='Miles per hour'
menus.3.1.id='MPH'
menus.3.1.conv=0.621371
menus.3.2.text='Kilometers per hour'
menus.3.2.id='KMH'
menus.3.2.conv=1
menus.3.3.text='Meters per second'
menus.3.3.id='MPS'
menus.3.3.conv=0.277778
menus.3.4.text='Knots'
menus.3.4.id='K'
menus.3.4.conv=0.539957

menus.4.0.title='Distance conversions'
menus.4.1.text='Miles'
menus.4.1.id='MI'
menus.4.1.conv=0.000621371
menus.4.2.text='Kilometers'
menus.4.2.id='KM'
menus.4.2.conv=0.001
menus.4.3.text='Meters'
menus.4.3.id='M'
menus.4.3.conv=1
menus.4.4.text='Feets'
menus.4.4.id='FT'
menus.4.4.conv=3.28084
menus.4.5.text='Yards'
menus.4.5.id='YD'
menus.4.5.conv=1.09361
menus.4.6.text='Inches'
menus.4.6.id='IN'
menus.4.6.conv=39.3701
menus.4.7.text='Centimeters'
menus.4.7.id='CM'
menus.4.7.conv=100
menus.4.8.text='Milimeters'
menus.4.8.id='MM'
menus.4.8.conv=1000

menus.5.0.title='Volume conversions'
menus.5.1.text='Gallons'
menus.5.1.id='GAL'
menus.5.1.conv=0.264172
menus.5.2.text='Pints'
menus.5.2.id='PT'
menus.5.2.conv=2.11338
menus.5.3.text='Fluid ounces'
menus.5.3.id='FLOZ'
menus.5.3.conv=33.814
menus.5.4.text='Cube meters'
menus.5.4.id='M3'
menus.5.4.conv=1000
menus.5.5.text='Liters'
menus.5.5.id='L'
menus.5.5.conv=1
menus.5.6.text='Mililiters'
menus.5.6.id='ML'
menus.5.6.conv=1000

menus.6.0.title='Area conversions'
menus.6.1.text='Square meters'
menus.6.1.id='M2'
menus.6.1.conv=1
menus.6.2.text='Square miles'
menus.6.2.id='MI2'
menus.6.2.conv=3.86102e-7
menus.6.3.text='Square kilometers'
menus.6.3.id='KM2'
menus.6.3.conv=1e-6
menus.6.4.text='Square yards'
menus.6.4.id='YD2'
menus.6.4.conv=1.19599
menus.6.5.text='Square inches'
menus.6.5.id='IN2'
menus.6.5.conv=1550
menus.6.6.text='Square feets'
menus.6.6.id='FT2'
menus.6.6.conv=10.7639
menus.6.7.text='hectares'
menus.6.7.id='HA'
menus.6.7.conv=0.0001

menus.7.0.title='Pressure conversions'
menus.7.1.text='Pascals'
menus.7.1.id='PA'
menus.7.1.conv=1000
menus.7.2.text='Atmospheres'
menus.7.2.id='ATM'
menus.7.2.conv=0.00986923
menus.7.3.text='Bars'
menus.7.3.id='BAR'
menus.7.3.conv=100
menus.7.4.text='Milimeters of mercury'
menus.7.4.id='MMHG'
menus.7.4.conv=7.50062
menus.7.5.text='Pounds per square inch'
menus.7.5.id='LBPIN2'
menus.7.5.conv=6894.76
menus.7.6.text='Kilopascals'
menus.7.6.id='KPA'
menus.7.6.conv=1
menus.7.7.text='Kilograms per square centimeters'
menus.7.7.id='KGCM2'
menus.7.7.conv=98.0665

menus.8.0.title='Power conversions'
menus.8.1.text='Watts'
menus.8.1.id='W'
menus.8.1.conv=1
menus.8.2.text='Horse powers'
menus.8.2.id='HP'
menus.8.2.conv=0.00134102

/* Load RegUtils if needed */
if noreturn | docls then ,
if rxfuncquery('SYSLoadFuncs')=1 then , /* SYSLoadFuncs not loaded yet */
if rxfuncadd('SYSLoadFuncs','regutil','SYSLoadFuncs')<>0 then do
  Say 'Error on loading regutil:'RXFUNCERRMSG()
  Say 'Falling back on forcing you to use Return after your choice in menus'
  noreturn=0
  end
else call sysloadfuncs /* for SysGetKey that avoid forcing to type Enter after 
a choice */

/* And now, your main  program! */
if docls then call syscls
Say 'Welcome to ConvREXXter v.1.3'
Say
mymenu = ''
finished=0
do until finished
  call getLeafMenu
  mymenu=RESULT
  if mymenu \='' then
    call askConversions
    choice=RESULT
    if choice='Z' | choice='z' then do
      call goback mymenu
      mymenu=RESULT
      end
  else finished=1
  end
if docls then call syscls
Say
Say 'Thank you for using my program!'
Say
Say 'If your plane crashed because your pilot used my program,'
Say 'please send me the details...'
Say 'so that I can eventually fix it in a future version.'
Say
Say 'Seriously, send your comments/bugs messages to dufres...@zoho.com'
exit 0

getLeafMenu: procedure expose menus. noreturn mymenu docls
finished=0
do until finished
  call showMenu mymenu
  /* ask choice */
  if noreturn then do
    choice=SysGetKey('')
    if choice=0 then choice=SysGetKey('')
    Say
    end
  else
    parse pull choice
    /* handle choice */  
  if choice='Z' | choice='z' then
    /* back requested */
    if mymenu='' then finished=1
    else do
      call goBack mymenu
      mymenu=RESULT
      end
  else mymenu=mymenu''choice'.'
  if \finished then do
    call noSubMenus mymenu
    finished=RESULT
    /*say 'noSubMenus='finished*/
    end
  end
return mymenu

goback: procedure
/* '' return ''
   '1.' return ''
   '1.2. return '1.'
   '1.2.3. return '1.2'
   etc.
*/
parse arg mymenu
if mymenu='' then return mymenu
lastdot=lastpos('.',mymenu)
if lastdot=2 then return ''
return substr(mymenu,1,lastdot-2)

noSubMenus: procedure expose menus.
parse arg mymenu
if mymenu='' then say 'noSubMenus called with empty string'
/*say 'isLeaf:' value('menus.'mymenu'1.text')*/
return value('menus.'mymenu'1.text') = 'NOTTHERE'

showMenu: procedure expose menus. noreturn docls
parse arg mymenu
if docls then call syscls
/* show title */
if value('menus.' || mymenu || '0.title') \= 'NOTTHERE' then do
  say value('menus.' || mymenu || '0.title')
  say 'Convert to:'
  end
/* show menu itself */
index=1
/*say 'menus.'mymenu''index'.text'*/
do while value('menus.'mymenu''index'.text') \= 'NOTTHERE'
  say index'.'value('menus.'mymenu''index'.text')
  index=index+1
  if index>13 then exit 1
  end
say 'Z. Go back'
return

askConversions: procedure expose menus. mymenu noreturn
  /*say 'entering askConversions'*/
  /*say 'mymenu='mymenu*/
  /*say 'menus.'mymenu'1.text'*/
  units=value('menus.'mymenu'text')
  fromUnits=1
  choice='S' /* Like Something other than Z */
  do until choice='z' | choice='Z'
    call showConversions
    say 'C. Change fromUnits'
    say 'Z. Go back'
    if noreturn then do
      choice=SysGetKey('')
      if choice=0 then choice=SysGetKey('')
      Say
      end
    else do
      parse pull choice
      end
    /* handle choice */  
    if choice='Z' | choice='z' then
      /* back requested */
      nop
      else do/* Change fromUnits */
        say 'How many 'units':'
        parse pull fromUnits
        end
    if choice='z' | choice='Z' then nop  /*say 'choiceIsZ'*/
    else nop /*say 'choiceNotZ'*/
  end
  /*say 'exiting askConversion'*/
return choice

showConversions: procedure expose menus. mymenu fromUnits
/*say 'entering showConversions'*/
toUnitConv=value('menus.'mymenu'conv')
/*say 'toUnitsConv='toUnitsConv*/
toUnit=value('menus.'mymenu'text')
/*say 'toUnit='toUnit*/
toUnitID=value('menus.'mymenu'id')
/*say 'toUnitID='toUnitID*/
call goback mymenu
localmymenu=RESULT
/*say 'localmymenu='localmymenu*/
finished = 0
do index=1 until finished  
  if value('menus.'localmymenu'index.text')='NOTTHERE' then finished=1
  else do
    fromUnitID=value('menus.'localmymenu'index.id')
    fromUnit=value('menus.'localmymenu'index.text')
    /*
    say 'fromUnit='fromUnit
    say 'fromUnitID='fromUnitID
    say 'toUnitID='toUnitID
    */
    select
      when toUnitID='F' then
        if fromUnitID='C' then do
          rez=(9/5)*fromUnits+32
          Say fromUnits' 'fromUnit' is equivalent to 'rez' 'toUnit
          end
        else if fromUnitID='K' then do
          rez=fromUnits+273.15
          Say fromUnits' 'fromUnit' is equivalent to 'rez' 'toUnit
          end
          else nop
      when toUnitID='C' then
        if fromUnitID='K' then do
          rez=fromUnits-273.15
          Say fromUnits' 'fromUnit' is equivalent to 'rez' 'toUnit
          end
        else if fromUnitID='F' then do
          rez=(fromUnits-32)*5/9
          Say fromUnits' 'fromUnit' is equivalent to 'rez' 'toUnit
          end
          else nop
      when toUnitID='K' then
        if fromUnitID='C' then do
          rez=fromUnits-273.15
          Say fromUnits' 'fromUnit' is equivlent to 'rez' 'toUnit
          end
        else if fromUnitID='F' then do
          rez=(fromUnits-32)*5/9+273.15
          Say fromUnits' 'fromUnit' is equivalent to 'rez' 'toUnit
          end
          else nop
      otherwise
        /*say fromUnits fromUnit' 'value('menus.'localmymenu'incex.text')' is 
equivalent to 'RESULT' 'toUnits*/
        fromUnitConv=value('menus.'localmymenu''index.conv)
        /*say 'fromUnitsConv='fromUnitConv*/
        say fromUnits' 'value('menus.'localmymenu'index.text')' is equivalent 
to 'toUnitConv/fromUnitConv*fromUnits' 'toUnit
    end  /* end select */
  end /* else do */
end /* of do until finished */
/*say 'exiting showConversions'*/
return

Attachment: ConvREXXter_v1.3.rex
Description: Binary data

_______________________________________________
Freedos-devel mailing list
Freedos-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freedos-devel

Reply via email to