home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #3 / amigamamagazinepolishissue1998.iso / bazy / config_server / bin / config-editor.rexx next >
OS/2 REXX Batch file  |  1995-03-13  |  14KB  |  594 lines

  1. /*
  2. **  $Id: config-editor.rexx,v 1.1 1995/02/12 22:13:08 rkr Exp $
  3. **
  4. **  config-editor provides you with a means to edit the config-server
  5. **  database.
  6. **
  7. */
  8.     call init( )
  9.     address value host
  10.     options results
  11.     do while ~done
  12.         call do_app_list( )
  13.     end
  14. exuent:
  15.     call cls( )
  16.     address command 'set_con'
  17. exit prog_ret
  18.  
  19.  
  20. init:
  21.     host = 'config-server'
  22.     if ~show( 'p', host ) then
  23.     do
  24.         say 'Could not find configuration host, {'config-server'}.'
  25.         say 'Exiting.'
  26.         prog_ret = 10
  27.         signal exuent
  28.     end
  29.     address command 'set_raw'
  30.     prog_ret = 0
  31.     done = 0
  32.     call init_display( )
  33. return
  34.  
  35.  
  36.  
  37. do_app_list:
  38.     call list_apps( )
  39.     current_app = 1
  40.     call sync_disp_apps( )
  41.  
  42.     dal_done = 0
  43.     do until dal_done
  44.         dal_event = get_key( )
  45.  
  46.         select
  47.             when 'UP' == dal_event then
  48.                 call adjust_current_app( -1 )
  49.  
  50.             when 'DOWN' == dal_event then
  51.                 call adjust_current_app( +1 )
  52.  
  53.             when 'RIGHT' == dal_event | '0d'x == dal_event then
  54.                 dal_done = do_app( )
  55.  
  56.             when 'LEFT' == dal_event then
  57.                 call beep( )
  58.  
  59.             when 'Q' = upper( dal_event ) then
  60.                 dal_done = 1
  61.  
  62.             when 'R' == upper( dal_event ) then
  63.             do
  64.                 'reload'
  65.                 call list_apps( )
  66.                 current_app = 1
  67.                 call sync_disp_apps( )
  68.             end
  69.  
  70.             when 'S' == upper( dal_event ) then
  71.                 'save'
  72.  
  73.             when '7f'x == dal_event | 'D' = upper( dal_event ) then
  74.                 call delete_current_app( )
  75.  
  76.             otherwise
  77.                 nop
  78.  
  79.         end
  80.  
  81.     end
  82.     done = 1
  83. return
  84.  
  85. list_apps:
  86.     apps. = ''
  87.     'getattr apps'
  88.     parse var result 'TEXT:' apps
  89.     apps_clone = apps
  90.     apps.count = length( apps ) - length( compress( apps, ':' ) )
  91.     apps.max_len = 0
  92.     do i = 1 for apps.count
  93.         parse var apps app ':' apps
  94.         apps.i = app
  95.         apps.max_len = max( length( app ), apps.max_len )
  96.     end
  97.     apps.i = '::Quit::'
  98.     apps.count = i
  99.     apps.max_len = max( length( apps.i ), apps.max_len )
  100. return
  101.  
  102. sync_disp_apps:
  103.     call show_apps( )
  104.     call highlight_current_app( )
  105. return
  106.  
  107. show_apps:
  108.     call cls( )
  109.     say '::Applications::'
  110.     say
  111.     call push_mode( 'inverse' )
  112.     sa_max_len = apps.max_len + 2
  113.     do i = 1 for apps.count
  114.         say '' left( apps.i, sa_max_len )
  115.     end
  116.     call pop_mode( )
  117. return
  118.  
  119. show_current_app:
  120.     call pos_cursor( current_app + 2, 2 )
  121.     call writech( 'STDOUT', apps.current_app )
  122.     call pos_cursor( current_app + 2, 2 )
  123. return
  124.  
  125. highlight_current_app:
  126.     call push_mode( 'inverse underline' )
  127.     call show_current_app( )
  128.     call pop_mode( )
  129. return
  130.  
  131. adjust_current_app:
  132. parse arg aca_adj
  133.     aca_new = current_app + aca_adj
  134.     aca_new = max( min( apps.count, aca_new ), 1 )
  135.     if aca_new = current_app then
  136.         call beep( )
  137.     else
  138.     do
  139.         call push_mode( 'inverse' )
  140.         call show_current_app( )
  141.         current_app = aca_new
  142.         call highlight_current_app( )
  143.         call pop_mode( )
  144.     end
  145. return
  146.  
  147. delete_current_app:
  148.     'remattr app' apps.current_app
  149.     call list_apps( )
  150.     call sync_disp_apps( )
  151. return
  152.  
  153.  
  154.  
  155. do_app:
  156.     da_ret = 0
  157.     if '::Quit::' = apps.current_app then
  158.         da_ret = 1
  159.     else
  160.     do
  161.         current_app_name = apps.current_app
  162.         call list_tags( )
  163.         current_tag = 1
  164.         call sync_disp_tags( )
  165.         da_done = 0
  166.         do until da_done
  167.             da_event = get_key( )
  168.             select
  169.                 when 'UP' == da_event then
  170.                     call adjust_current_tag( -1 )
  171.  
  172.                 when 'DOWN' == da_event then
  173.                     call adjust_current_tag( +1 )
  174.  
  175.                 when 'RIGHT' == da_event | '0d'x == da_event then
  176.                     da_done = do_tag_subs( )
  177.  
  178.                 when 'LEFT' == da_event | 'Q' == upper( da_event ) then
  179.                     da_done = 1
  180.  
  181.                 when '7f'x == da_event | 'D' == upper( da_event ) then
  182.                     call delete_current_tag( )
  183.  
  184.                 otherwise
  185.                     nop
  186.             end
  187.         end
  188.         call list_apps( )
  189.         call sync_disp_apps( )
  190.     end
  191. return da_ret
  192.  
  193. list_tags:
  194.     tags. = ''
  195.     'getattr tags' current_app_name
  196.     parse var result 'TEXT:' tags
  197.     tags_clone = tags
  198.     tags.count = length( tags ) - length( compress( tags, ':' ) )
  199.     tags.max_len = 0
  200.     do i = 1 for tags.count
  201.         parse var tags tag ':' tags
  202.         tags.i = tag
  203.         tags.max_len = max( length( tag ), tags.max_len )
  204.     end
  205.     tags.i = '::Quit::'
  206.     tags.count = i
  207.     tags.max_len = max( length( '::Quit::' ), tags.max_len )
  208. return
  209.  
  210. sync_disp_tags:
  211.     call show_tags( )
  212.     call highlight_current_tag( )
  213. return
  214.  
  215. show_tags:
  216.     call cls( )
  217.     say '::Tags for' current_app_name'::'
  218.     say
  219.     call push_mode( 'inverse' )
  220.     st_max_len = tags.max_len + 2
  221.     do i = 1 for tags.count
  222.         say '' left( tags.i, st_max_len )
  223.     end
  224.     call pop_mode( )
  225. return
  226.  
  227. show_current_tag:
  228.     call pos_cursor( current_tag + 2, 2 )
  229.     call writech( 'STDOUT', tags.current_tag )
  230.     call pos_cursor( current_tag + 2, 2 )
  231. return
  232.  
  233. highlight_current_tag:
  234.     call push_mode( 'inverse underline' )
  235.     call show_current_tag( )
  236.     call pop_mode( )
  237. return
  238.  
  239. adjust_current_tag:
  240. parse arg act_adj
  241.     act_new = current_tag + act_adj
  242.     act_new = max( min( tags.count, act_new ), 1 )
  243.     if act_new = current_tag then
  244.         call beep( )
  245.     else
  246.     do
  247.         call push_mode( 'inverse' )
  248.         call show_current_tag( )
  249.         current_tag = act_new
  250.         call highlight_current_tag( )
  251.         call pop_mode( )
  252.     end
  253. return
  254.  
  255. delete_current_tag:
  256.     dct_tag = tags.current_tag
  257.     dct_app_tag = current_app_name':'dct_tag"'S"
  258.     'remattr tag' dct_app_tag
  259.     call list_tags( )
  260.     call sync_disp_tags( )
  261. return
  262.  
  263.  
  264.  
  265. do_tag_subs:
  266.     dts_ret = 0
  267.     if '::Quit::' = tags.current_tag then
  268.         dts_ret = 1
  269.     else
  270.     do
  271.         current_tag_name = tags.current_tag
  272.         call list_tag_subs( )
  273.         current_tag_sub = 1
  274.         call sync_disp_tag_subs( )
  275.         dts_done = 0
  276.         do until dts_done
  277.             dts_event = get_key( )
  278.             select
  279.                 when 'UP' == dts_event then
  280.                     call adjust_current_tag_sub( -1 )
  281.  
  282.                 when 'DOWN' == dts_event then
  283.                     call adjust_current_tag_sub( +1 )
  284.  
  285.                 when 'RIGHT' == dts_event | '0d'x == dts_event then
  286.                     dts_done = do_specific_tag( )
  287.  
  288.                 when 'LEFT' == dts_event | 'Q' == upper( dts_event ) then
  289.                     dts_done = 1
  290.  
  291.                 when 'I' == upper( dts_event ) then
  292.                     call insert_new_tag_sub( )
  293.  
  294.                 when '7f'x == dts_event | 'D' == upper( dts_event ) then
  295.                     call delete_current_tag_sub( )
  296.  
  297.                 otherwise
  298.                     nop
  299.             end
  300.         end
  301.         call list_tags( )
  302.         call sync_disp_tags( )
  303.     end
  304. return dts_ret
  305.  
  306. list_tag_subs:
  307.     tag_subs. = ''
  308.     'getattr tag' current_app_name':'current_tag_name"'S"
  309.     parse var result 'TEXT:' tag_subs.count
  310.     tag_subs.max_len = 0
  311.     do i = 1 for tag_subs.count
  312.         'getattr tag' current_app_name':'current_tag_name'.'i
  313.         tag_subs.i = result
  314.         tag_subs.max_len = max( length( tag_subs.i ), tag_subs.max_len )
  315.     end
  316.     tag_subs.i = '::Quit::'
  317.     tag_subs.count = i
  318.     tag_subs.max_len = max( length( '::Quit::' ), tag_subs.max_len )
  319. return
  320.  
  321. sync_disp_tag_subs:
  322.     call show_tag_subs( )
  323.     call highlight_current_tag_sub( )
  324. return
  325.  
  326. show_tag_subs:
  327.     call cls( )
  328.     say '::Tag subs for' current_app_name':'current_tag_name'::'
  329.     say
  330.     call push_mode( 'inverse' )
  331.     sts_max_len = tag_subs.max_len + 2
  332.     do i = 1 for tag_subs.count
  333.         say '' left( tag_subs.i, sts_max_len )
  334.     end
  335.     call pop_mode( )
  336. return
  337.  
  338. show_current_tag_sub:
  339.     call pos_cursor( current_tag_sub + 2, 2 )
  340.     call writech( 'STDOUT', tag_subs.current_tag_sub )
  341.     call pos_cursor( current_tag_sub + 2, 2 )
  342. return
  343.  
  344. highlight_current_tag_sub:
  345.     call push_mode( 'inverse underline' )
  346.     call show_current_tag_sub( )
  347.     call pop_mode( )
  348. return
  349.  
  350. adjust_current_tag_sub:
  351. parse arg acts_adj
  352.     acts_new = current_tag_sub + acts_adj
  353.     acts_new = max( min( tag_subs.count, acts_new ), 1 )
  354.     if acts_new = current_tag_sub then
  355.         call beep( )
  356.     else
  357.     do
  358.         call push_mode( 'inverse' )
  359.         call show_current_tag_sub( )
  360.         current_tag_sub = acts_new
  361.         call highlight_current_tag_sub( )
  362.         call pop_mode( )
  363.     end
  364. return
  365.  
  366. delete_current_tag_sub:
  367.     dcts_tag = current_tag_name'.'current_tag_sub
  368.     dcts_app_tag = current_app_name':'dcts_tag
  369.     'remattr tag' dcts_app_tag
  370.     call list_tag_subs( )
  371.     call sync_disp_tag_subs( )
  372. return
  373.  
  374. insert_new_tag_sub:
  375.     ints_quit = ('::Quit::' == tag_subs.current_tag_sub)
  376.     if ints_quit & (current_tag_sub > 1) then
  377.         call beep( )
  378.     else
  379.     do
  380.         ints_def_app = current_app_name
  381.         ints_def_tag = current_tag_name
  382.         if current_tag_sub == tag_subs.count then
  383.         do
  384.             /* ints_def_num = '' */
  385.             ints_def_enc = 'TEXT'
  386.             ints_def_val = ''
  387.         end
  388.         else
  389.         do
  390.             /* ints_def_num = current_tag_sub */
  391.             'getattr tag' ints_def_app':'ints_def_tag'.'current_tag_sub
  392.             parse var result ints_def_enc':'ints_def_val
  393.         end
  394.         call cls( )
  395.         /* say '::New application:encoding:tag.num:value::' */
  396.         say '::New application:encoding:tag:value::'
  397.         say
  398.         say 'Data:'
  399.         say '  app:' ints_def_app
  400.         say '  enc:' ints_def_enc
  401.         say '  tag:' ints_def_tag
  402.         say '  num:  ---' /*** ints_def_num ***/
  403.         say '  val:' ints_def_val
  404.  
  405.         call set_con( )
  406.  
  407.         call pos_cursor( 10, 1 )
  408.         call writech( 'STDOUT', 'App: ' )
  409.         call push_mode( 'inverse' )
  410.         ints_app = readln( 'STDIN' )
  411.         if '' == ints_app then
  412.             ints_app = ints_def_app
  413.         ints_app = compress( ints_app, ':' )
  414.         call pos_cursor( 4, 8 )
  415.         call writech( 'STDOUT', left( ints_app, 64 ) )
  416.         call pop_mode( )
  417.  
  418.         call pos_cursor( 10, 1 )
  419.         call writech( 'STDOUT', 'Enc: ' )
  420.         call push_mode( 'inverse' )
  421.         ints_enc = readln( 'STDIN' )
  422.         if '' == ints_enc then
  423.             ints_enc = ints_def_enc
  424.         ints_enc = compress( ints_enc, ':' )
  425.         call pos_cursor( 5, 8 )
  426.         call writech( 'STDOUT', left( ints_enc, 64 ) )
  427.         call pop_mode( )
  428.  
  429.         call pos_cursor( 10, 1 )
  430.         call writech( 'STDOUT', 'Tag: ' )
  431.         call push_mode( 'inverse' )
  432.         ints_tag = readln( 'STDIN' )
  433.         if '' == ints_tag then
  434.             ints_tag = ints_def_tag
  435.         ints_tag = compress( ints_tag, "'.:" )
  436.         call pos_cursor( 6, 8 )
  437.         call writech( 'STDOUT', left( ints_tag, 64 ) )
  438.         call pop_mode( )
  439.  
  440.         /*
  441.         **  call pos_cursor( 10, 1 )
  442.         **  call writech( 'STDOUT', 'Num: ' )
  443.         **  call push_mode( 'inverse' )
  444.         **  ints_num = readln( 'STDIN' )
  445.         **  if ~datatype( ints_num, 'n' ) then
  446.         **      ints_num = ints_def_val
  447.         **  call pos_cursor( 7, 8 )
  448.         **  call writech( 'STDOUT', left( ints_num, 64 ) )
  449.         **  call pop_mode( )
  450.         **
  451.         */
  452.  
  453.         call pos_cursor( 10, 1 )
  454.         call writech( 'STDOUT', 'Val: ' )
  455.         call push_mode( 'inverse' )
  456.         ints_val = readln( 'STDIN' )
  457.         if '' == ints_val then
  458.             ints_val = ints_def_val
  459.         call pos_cursor( 8, 8 )
  460.         call writech( 'STDOUT', left( ints_val, 64 ) )
  461.         call pop_mode( )
  462.  
  463.         call set_raw( )
  464.  
  465.         'addattr tag' ints_app':'ints_enc':'ints_tag':'ints_val
  466.  
  467.         call list_tag_subs( )
  468.         call sync_disp_tag_subs( )
  469.     end
  470. return ''
  471.  
  472.  
  473. do_specific_tag:
  474.     dst_ret = 0
  475.     if '::Quit::' = tag_subs.current_tag_sub then
  476.         dst_ret = 1
  477.     else
  478.         call beep( )
  479. return dst_ret
  480.  
  481.  
  482.  
  483.  
  484. /*
  485. **  Screen editing functions
  486. **
  487. */
  488. init_display:
  489.     call cls( )
  490.     mode. = ''
  491.     mode.count = 0
  492. return
  493.  
  494. cls:
  495.     call writech( 'STDOUT', '0c'x )
  496. return
  497.  
  498. push_mode:
  499. parse arg pm_add
  500.     pm_c = mode.count
  501.     pm_old = mode.pm_c
  502.     pm_new = '' pm_old ''
  503.     do i = 1 for words( pm_add )
  504.         if 0 = pos( '' word( pm_add, i ) '', pm_new ) then
  505.             pm_new = pm_new || word( pm_add, i ) ''
  506.     end
  507.     pm_c = pm_c + 1
  508.     mode.pm_c = strip( pm_new )
  509.     mode.count = pm_c
  510.     call display_mode( )
  511. return
  512.  
  513. pop_mode:
  514.     mode.count = mode.count - 1
  515.     if 0 > mode.count then
  516.         mode.count = 0
  517.     call display_mode( )
  518. return
  519.  
  520. display_mode:
  521.     dm_out = '9b'x || '0'
  522.     dm_c = mode.count
  523.     dm_modes = mode.dm_c
  524.     do i = 1 for words( dm_modes )
  525.         dm_umode = upper( word( dm_modes, i ) )
  526.         select
  527.             when 'BOLD' == dm_umode then
  528.                 dm_out = dm_out';1'
  529.  
  530.             when 'STANDOUT' = dm_umode then
  531.                 dm_out = dm_out';2'
  532.  
  533.             when 'ITALICS' = dm_umode then
  534.                 dm_out = dm_out';3'
  535.  
  536.             when 'UNDERLINE' = dm_umode then
  537.                 dm_out = dm_out';4'
  538.  
  539.             when 'INVERSE' == dm_umode then
  540.                 dm_out = dm_out';7'
  541.  
  542.             otherwise
  543.                 nop
  544.         end
  545.     end
  546.     call writech( 'STDOUT', dm_out'm' )
  547. return
  548.  
  549. pos_cursor:
  550. parse arg pc_row, pc_col
  551.     call writech( 'STDOUT', '9b'x || pc_row';'pc_col'H' )
  552. return
  553.  
  554. get_key:
  555.     gk_ret = readch( 'STDIN', 1 )
  556.     if '1b'x == gk_ret then
  557.     do
  558.         gk_ret = gk_ret || readch( 'STDIN', 1 )
  559.         if '1b5b'x == gk_ret then
  560.             gk_ret = '9b'x
  561.     end
  562.     if '9b'x = gk_ret then
  563.     do
  564.         gk_ret = gk_ret || readch( 'STDIN', 1 )
  565.         select
  566.             when '9b41'x == gk_ret then
  567.                 gk_ret = 'UP'
  568.  
  569.             when '9b42'x == gk_ret then
  570.                 gk_ret = 'DOWN'
  571.  
  572.             when '9b43'x == gk_ret then
  573.                 gk_ret = 'RIGHT'
  574.  
  575.             when '9b44'x == gk_ret then
  576.                 gk_ret = 'LEFT'
  577.  
  578.             otherwise
  579.                 gk_ret = ''
  580.         end
  581.     end
  582. return gk_ret
  583.  
  584.  
  585. beep:
  586. return writech( 'STDOUT', '07'x )
  587.  
  588. set_con:
  589.     address command 'set_con'
  590. return 1
  591. set_raw:
  592.     address command 'set_raw'
  593. return 1
  594.