#! ./srexx

/*
 *   SEDIT and S/REXX installation script. Do not modify it.
 *
 *
 *   Copyright (C) 1991-1999 by Benaroya et Compagnie
 *   All rights reserved.
 *
 *   Calls:           install
 *                    install SEDIT
 *                    install REXX
 *                    install SERVER
 *                    install SERVER  RESTART
 *                    install MWMRC
 */

signal on novalue
signal on halt
option mixed setenv noload


arch = arch()

if arch = 'sun4' & state('/devices', 'd') then
 { say 'This is the SunOS S/REXX version, and you are running a Solaris system.'
   exit 1
 }

if ~state('srexx') then
 { say 'install: 'cwd()' is not an SEDIT-S/REXX directory.'
   exit 1
 }

if arch = 'sparc' then
 { $PATH = $PATH':/usr/ucb'
   hostname = 'uname -n'
   found = 0
   do dir IN 'xbin cbin mbin'
      call unix '/bin/ls -l 'dir'/sparc', tab
      do i = 1 to tab.0
         parse var tab.i . ' -> ' link
         if link = 'xed.d' then
          { found = found + 1
            leave i
          }
      end i
   end

   if found ~= 3 then
    { say
      say 'install: redoing links .....'
      say
      './mkln d'
    }
 }
else hostname = 'hostname'

parse upper arg a .

if a ~= '-NS' & ~state('.install.ath') then
 { say
   say 'install: Setting permissions.'
   say
   'touch .install.ath'
   trace off

   call subdirs '.', tab, 'r'
   dirs = ''
   do i = 1 to tab.0
     dirs = dirs tab.i
   end i
   sayx 'chmod a+r+x ' dirs

   files = ''

   if state('filters', 'd') then files = 'filters/'arch'/toggle_comment' files
   if state('demo/demo_ex', 'd') then files = 'demo/demo_ex/*.ex 'files
   if state('xmac', 'd')         then files = 'xmac/*.ex 'files

   execs = 'aplsedit cco ccod co cod fo fod install mkesc mkln mkln1 mktrans msedit msrexx mxed pdf psedit pxed rxd sedit sedit_spell setkey srexx test_rexx test_rxd unex xed xeda xedit xinfo xsedit xserv xsrexx'
   do ee in execs
      if state(ee) then files = files ee
   end ee
   sayx 'chmod a+x 'files

   dirs = 'bin xbin cbin sbin mbin'
   do dd in dirs
      ss = dd'/'arch
      if state(ss, 'd') then sayx 'chmod a+x 'ss'/*'
   end dd

   say 'chmod -R a+r . .rxdinit .Xdefaults'
   call unix 'chmod -R a+r . .rxdinit .Xdefaults', tab
   sayx 'chmod 0700 private/xsdown private'
   if userid('r') = 'root' then sayx 'chown -R root private'
   say
   say 'install: Done setting permissions.'
   say
   trace e

   say 'install: updating .srexxrc'
   if state('.srexxrc') then
    { 'execio 1 diskr .srexxrc . .(finis var fl'
      if fl[1:2] = '#!' then
        'execio 1 diskw .srexxrc . . 1(finis string #!'cwd()'/srexx'
    }

   './setup auto'
 }

if arch = 'sun4' | arch = 'sun3' | arch = 'sparc' then arch = 'sun'

parse upper arg a goto new_name new_id new_pass .

if a = '-CLEAN' then
 { lg_clean = 1
   parse upper arg . a goto new_name new_id new_pass .
   lg_removed_passwds = 0
   lg_removed_seditusers = 0
   lg_removed_srexxusers = 0
 }
else lg_clean = 0

if 0 ~= index(a, 'RC') then
 { call inst_mwmrc
   exit 0
 }

if 0 <> index(a, "REXX-RUN")  then call inst "S/REXX-RT"
if 0 <> index(a, "REXX")      then call inst "S/REXX"
if 0 <> index(a, "EDIT")      then call inst "SEDIT"
if 0 <> index(a, "SETUP")     then
 { './setup'
   exit 0
 }
if 0 <> index(a, "SER")       then
 { if goto = 'RESTART'        then call start_serv
   else                            call install_serv
   exit 0
 }

say
say  'This script may:'
say
say  '   1)  Install SEDIT in fixed license mode.'
say
say
say  '   2)  Install S/REXX in fixed license mode.'
say
say
say  '   3)  Install the license server "xserv" for both SEDIT and S/REXX.'
say
say  '       In this case, your password sheet must display the 2'
say  '       additional fields:'
say
say  '             licenses     : xxxx'
say  '             serial number: xxxx'
say
say
say  '   4)  Kill and restart an installed server.'
say
say  '   5)  Customize your ~/.mwmrc file (IBM only).'
say
say  '   6)  Run the SEDIT-S/REXX setup utility'
say
say  '   7)  Exit.'
say

do forever
   sayn  'Enter your choice (1|2|3|4|5|6|7): '
   pull choice
   select
     when choice = 1 then
      { call inst "SEDIT"
        exit
      }

     when choice = 2 then
      { call inst "S/REXX"
        exit
      }

     when choice = 3 then
      { call install_serv
        exit
      }

     when choice = 4 then
      { call start_serv
        exit
      }

     when choice = 5 then
      { call inst_mwmrc
        exit
      }

     when choice = 6 then
      { './setup'
        exit
      }

     when choice = 7 then exit

     otherwise
      say '..... Invalid choice.'
      say
   end
end


/*
 * inst: installation arg(1)
 */

inst:

  arg prod .

  say
  say " ******** Beginning to install "prod
  say

  file = "passwds"

  if lg_clean & ~lg_removed_passwds then
   { if state(file) then call rmv_file file
     lg_removed_passwds = 1
   }


  first_inst = 1

  select
    when arch = 'sun' | arch = 'i86pc' | arch = 'sinix' then hostid = 'HOSTID'
    when arch = 'alpha' then hostid = 'ETHERNET ADDRESS'
    when arch = 'ibm' then hostid = 'UNAME'
    when arch = 'hp'  then hostid = 'UNAME'
    when arch = 'sgi' then hostid = 'SYSID'
    when arch = 'esa' then hostid = 'UNAME'
    when arch = 'cray' then hostid = 'UNAME'
    when arch = 'linux' | arch = 'sco' | arch = 'uxw' then hostid = 'SEDITID'
    otherwise
       hostid = 'hostid'
       say ' ********** Warning: unknown architecture'
  end
 /*
  *  Check file "passwds"
  */
  if state(file) then
   {    /* DO_1 */

     nbl = lines(file)
     nbp = 0             /* Number of passwords for the current product */
     do i = 1 to nbl
       ll = linein(file)
       if word(ll, 1) = prod then
        do
          nbp = nbp + 1
          tab.nbp = ll
          tab_line.nbp = i
        end
     end i

     if nbp <> 0 then
      {    /* DO_2 */
        say
        say 'The following passwords have been installed:'
        say

        /*
         * Computing maximum length for HOSTNAME and HOSTID
         */
        do i5 = 1
           max_id = 0;
           max_name = 0;
           do i = 1 to nbp
             max_id   = max(max_id,   length(word(tab.i, 3)))
             max_name = max(max_name, length(word(tab.i, 2)))
           end i
           max_id   = max_id + 2
           max_name = max_name + 2
           max_i    = length(nbp)

           call display_pass

           if goto = 'MOD' then call mod_pass
           else
            do  /* MODIFY */
              if goto = 'ADD' then leave i5
              say
              if first_inst then
               { sayn "Do you want to modify one of these passwords ? "
                 first_inst = 0
               }
              else
               { say
                 sayn "Do you want to modify another one of these passwords ? "
               }

              pull rep .
              if left(rep, 1) = 'Y' then call mod_pass
              else
               do
                if left(rep, 1) = 'Q' then exit
                if datatype(rep, 'n') then call mod_pass rep
                else                       leave i5
               end
            end /* MODIFY */
        end i5
      }     /* DO_2 */
   }     /* DO_1 */
  else  nbp = 0

  call add_pass

  exit     /* eject */


/*
 * display_pass: displays nbp passwords tab.i
 */

display_pass:
  say
  do i = 1 to nbp
    sayn right(i, max_i)': '
    sayn  'HOSTNAME:'           left(word(tab.i, 2), max_name)
    sayn  hostid':'             left(word(tab.i, 3), max_id)
    say   'PASSWORD:'           word(tab.i, 4)
  end i
  return

/*
 * mod_pass: password modification
 */

mod_pass:

    arg vv .

    do i1 = 1
      if vv = '' then
        { if nbp = 1 then rep = 1
          else
           { say
             sayn 'Enter a number (? to redisplay the list, Q to QUIT) : '
             pull rep .
           }
        }
      else
        { rep = vv
          vv  = ''
        }

      if  left(rep, 1) = '?' then
       do
         call display_pass
         iterate i1
       end

      if  left(rep, 1) = 'Q' then return

      if ~datatype(rep, 'N') | rep <= 0 | rep > nbp | rep <> trunc(rep, 0) then
        do
          call inv_ent
          call display_pass
          iterate i1
        end

      hn = word(tab.rep, 2)
      id = word(tab.rep, 3)
      pp = word(tab.rep, 4)

      ok = ent_pass()

      if left(ok, 1) = 'Y' | left(ok, 1) = 'O' then
       do
         en = space(prod hn id pp, 4)
         tab.rep = en
         call lineout file, en, tab_line.rep
         call just_file
       end
       return
    end i1

    /* NOTREACHED */

inv_ent:procedure
  parse arg mes

  say
  say '                         *********'

if mes ~= '' then
  say '                         *********' mes
else
  say '                         ********* Invalid entry'

  say '                         *********'
  say
  call charout, '07'x      /* Bell */
  return                                          /* eject */

/*
 * ent_pass: receives default HOSTNAME, ID and PASSWORD values.
 *           asks for new values.
 *
 *           Global variables: hn id pp hostid
 *           Returns ok
 */

ent_pass:
  procedure expose hn id pp hostid new_name new_id new_pass arch hostname lg_clean prod

  say

  if new_name = '' then
   do
     sayn 'Enter the HOSTNAME ('hn') : '
     parse pull r_hn .
     if r_hn <> '' then  hn = r_hn
   end
  else
   do
    hn = new_name
    new_name = ''
   end

  if new_id = '' then
   do
     sayn 'Enter the 'hostid' ('id') : '
     parse pull r_id .
     if r_id <> '' then id = r_id
   end
  else
   do
    id = new_id
    new_id = ''
   end

  if new_pass = '' then
   do
     do i3 = 1
       sayn 'Enter the PASSWORD ('pp') : '
       parse pull r_pp .
       if r_pp == "" then r_pp = pp
       if prod = 'SEDIT'          then ret = ckpa('sedit', id, r_pp, dummy)
       else if prod = 'S/REXX-RT' then ret = ckpa('srexx-rt', id, r_pp, dummy)
       else                            ret = ckpa('srexx', id, r_pp, dummy)
       if ret ~= 0 then
         { call inv_ent ret
           iterate i3
         }
       pp = r_pp
       leave i3
     end i3
   end
  else
   do
    pp = new_pass
    new_pass = ''
   end

  say
  say 'You have typed the following information:'
  say
  say 'HOSTNAME:' hn
  say left(hostid, 8)': 'id
  say 'PASSWORD:' pp
  say
  sayn 'OK ? '
  pull ok

  if left(ok, 1) = 'Q' then exit

  return ok               /* eject */

/*
 * just_file: justifies every file entry
 */
just_file:

  procedure expose file new_name new_id new_pass arch hostname lg_clean

  nbp = len_file(file)

  max_pp   = 0;
  max_id   = 0;
  max_name = 0;
  max_prod = 0;
  do i = 1 to nbp
    tab.i    = linein(file, i)
    max_pp   = max(max_pp,   wordlength(tab.i, 4))
    max_id   = max(max_id,   wordlength(tab.i, 3))
    max_name = max(max_name, wordlength(tab.i, 2))
    max_prod = max(max_prod, wordlength(tab.i, 1))
  end i

  max_prod = max_prod + 2
  max_name = max_name + 2
  max_id   = max_id + 2
  max_pp   = max_pp + 2

  do i = 1 to nbp
     if left(tab.i, 1) ~= '*' then
      do
        t1 = left(word(tab.i, 1), max_prod)
        t2 = left(word(tab.i, 2), max_name)
        t3 = left(word(tab.i, 3), max_id)
        t4 = left(word(tab.i, 4), max_pp)
        ii = wordindex(tab.i, 5)
        if 0 <> ii then  ss = '  ' substr(tab.i, ii)
        else             ss = ''
        tab.i = t1 t2 t3 t4 ss
      end

     call lineout file, tab.i, i
  end

  return                    /* eject */


/*
 * add_pass: adds a password
 */

add_pass:

  do forever      /* DO_5 */
      say

      if goto = 'ADD' then
       do
         say ' ********** Adding a new password'
         goto = ''
       end
      else
       do
         sayn  'Do you want to add a new password ? '
         pull a .

         if left(a, 1) ~= 'Y' & left(a, 1) ~= 'O' then return
         if left(a, 1) = 'Q' then exit
       end

      hn = `hostname`
      id = cpuid('n')
      pp = ''

      do i5 = 1
        ok =  ent_pass()
        if left(ok, 1) = 'Y' | left(ok, 1) = 'O' then leave i5
      end i5

      en = prod hn id pp

      call lineout file, en, 1+len_file(file)

      nbp          = nbp + 1
      tab.nbp      = en
      tab_line.nbp = len_file(file)

      call just_file
      call unix 'chmod a+r' file, foo

  end             /* DO_5 */


/*
 * len_file: returns the number of lines of arg(1)
 */
len_file: procedure expose arch hostname lg_clean

  call linein arg(1), 1, 0
  return lines(arg(1))

/*
 * install_serv: maj seditusers
 *
 *           hostname ??????
 *           hostid   ????????
 *           password ????????????????????????????
 *           serial   ????
 *           port     1112
 *           expire   Never
 *           version  UNIX
 *           licenses ?
 *           home     ?????????
 *
 */

install_serv:procedure expose arch goto new_name new_id new_pass hostname lg_clean lg_removed_seditusers lg_removed_srexxusers

 parse arg arg_serv

 sayn "Do you want to install the license server for SEDIT? "
 pull rep .
 if left(rep, 1) = 'Y' then
  { file = "seditusers"
    if lg_clean & ~lg_removed_seditusers then
    { if state(file) then call rmv_file file
      lg_removed_seditusers = 1
    }

    call install_serv1 arg_serv
  }

 call charout, '07'x      /* Bell */
 call charout, '07'x      /* Bell */
 say
 say '***'
 say '***    Warning: DO NOT install the license server for S/REXX'
 say '***             if you do not have an S/REXX license.'
 say '***'
 say
 call sleep 3

 sayn "Do you want to install the license server for S/REXX? "
 pull rep .
 if left(rep, 1) = 'Y' then
  { file = "srexxusers"

    if lg_clean & ~lg_removed_srexxusers then
    { if state(file) then call rmv_file file
      lg_removed_srexxusers = 1
    }

    call install_serv1 arg_serv
  }

 sayn 'Do you want to start the license server ? '
 pull rep .
 if left(rep, 1) = 'Y' | left(rep, 1) = 'O' then call start_serv

return

install_serv1:procedure expose arch goto new_name new_id new_pass file hostname lg_clean

  arg restart

  if restart = '' then do
    say
    say " ******** Beginning to install the license server ""xserv"""
    say

    id = cpuid('n')
    select
      when arch() = 'sparc'  | arch = 'i86pc' then do
        hostid = 'HOSTID'
      end

      when arch = 'sun' then do
        hostid = 'HOSTID'
      end

      when arch = 'alpha' then do
        hostid = 'ETHERNET ADDRESS'
      end

      when arch = 'ibm' then do
        hostid = 'UNAME'
      end

      when arch = 'hp'  then do
        hostid = 'UNAME'
      end

      when arch = 'sgi' then do
        hostid = 'SYSID'
      end

      when arch = 'linux' | arch = 'sco' | arch = 'uxw' then do
        hostid = 'SEDITID'
      end

      when arch = 'sinix' then do
        hostid = 'HOSTID'
      end

      otherwise
         hostid = 'HOSTID'
         id     = '??????'
         say ' ********** Warning: unknown architecture'
    end


    hn = `hostname`
    pa = ''
    se = ''
    po = '1112'
    ex = ''
    ve = 'None'
    li = ''
    ho = cwd()

    comment.0 = 0        /* Number of unrecognized lines */

    if state(file) then do
      do i = 1 to lines(file)
         newl = linein(file, i)
         item = word(newl, 1)
         lower item
         select
           when item = 'hostname' then hn = word(newl, 2)

           when item = 'hostid'  |,
                item = 'etherid' |,
                item = 'sysid'   |,
                item = 'sysinfo' |,
                item = 'seditid' |,
                item = 'uname'       then id = word(newl, 2)

           when item = 'password' then pa = word(newl, 2)
           when item = 'serial'   then se = word(newl, 2)
           when item = 'port'     then po = word(newl, 2)
           when item = 'expire'   then ex = word(newl, 2)
           when item = 'version' | item = 'options' then ve = subword(newl, 2)
           when item = 'licenses' | item = 'users' then li = word(newl, 2)
           when item = 'home'     then ho = word(newl, 2)
           otherwise
            comment.0 = comment.0 + 1
            a = comment.0
            comment.a = newl
        end
      end
      call disp_serv
      say
      sayn 'DO you want to modify one of these parameters ? '
      pull rep .
      if left(rep, 1) = 'Q' then exit
      if left(rep, 1) \= 'Y' & left(rep, 1) \= 'O' then lg_mod = 0
      else                                              lg_mod = 1
    end
   else lg_mod = 1

   if lg_mod then do i2 = 1
      do i_pass = 1
         call def_enter 'hn',   , 'HOSTNAME'
         call def_enter 'id',   , hostid
         call def_enter 'pa', 23, 'PASSWORD'
         call def_enter 'se',   , 'SERIAL number'
         call def_enter 'po',   , 'PORT number'
         call def_enter 'ex',   , 'Expiration date'
         call def_enter 've',   , 'OPTIONS'
         call def_enter 'li',   , 'number of licenses'
         call def_enter 'ho',   , 'installation directory'

         if file = 'seditusers' then ret = ckpa('sedit', id, pa, dummy, se)
         else                        ret = ckpa('srexx', id, pa, dummy, se)
         if ret = 0 then leave i_pass
         else
          { say
            say '                         *********'
            say '                         *********' ret
            say '                         *********'
            say
          }

      end i_pass

      call disp_serv
      say
      sayn 'Do you want to modify these settings ? '
      pull rep .
      if left(rep, 1) = 'Y' | left(rep, 1) = 'O' then iterate i2
      if left(rep, 1) = 'Q' then exit
      sayn 'Do you want to save these settings ? '
      pull rep .
      if left(rep, 1) = 'Q' then exit
      if left(rep, 1) = 'Y' | left(rep, 1) = 'O' then call sav_serv
      leave i2
   end i2
 end           /* restart */

 return

  /* NOTREACHED */

/*
 * def_enter:  reads arg(1), reassigns it and checks its length to
 *             arg(2). arg(3) is the label
 */
def_enter:procedure expose arch goto new_name new_id new_pass hostname lg_clean

  parse arg name, len, label
  interpret 'procedure expose 'name
  def = value(name)
  do i1 = 1
    sayn "Enter the "label" ("def"): "
    parse pull rep .
    if rep = '' then  interpret 'rep ='name
    rep = strip(rep)

    if len <> "" & length(rep) <> len then
     { call inv_ent
       iterate i1
     }

    if rep = '' then do
      call inv_ent
      iterate i1
    end

    interpret  name '= rep'

    return
  end i1

  /* NOTREACHED */

/*
 * disp_serv
 */
disp_serv:

 say
 say 'The server is configured with the following parameters:'
 say
 if arch() = 'alpha' then ll_di = 17  /* ETHERNET ADDRESS */
 else                     ll_di = 12
 say left('HOSTNAME:', ll_di) hn
 say left(hostid':', ll_di)   id
 say left('PASSWORD:', ll_di) pa
 say left('SERIAL:', ll_di)   se
 say left('PORT:', ll_di)     po
 say left('EXPIRE:', ll_di)   ex
 say left('OPTIONS:', ll_di)  ve
 say left('LICENSES:', ll_di) li
 say left('HOME:', ll_di)     ho
 say

return


/*
 * sav_serv
 */
sav_serv: procedure expose file hn id pa se po ex ve li ho comment. hostid arch hostname lg_clean

/*
 * We close file before renaming it
 */
call lineout file

if state(file) then 'mv 'file file'%'

if hostid[1:8] = 'ETHERNET' then hid = 'etherid'
else                             hid = hostid

call lineout file, left('hostname', 9)     hn
call lineout file, lower(left(hid, 9))     id
call lineout file, left('password', 9)     pa
call lineout file, left('serial', 9)       se
call lineout file, left('port', 9)         po
call lineout file, left('expire', 9)       ex
call lineout file, left('options', 9)      ve
call lineout file, left('licenses', 9)     li
call lineout file, left('home', 9)         ho

do i = 1 to comment.0
  call lineout file, comment.i
end

call lineout file

call unix 'chmod a+r' file, foo

say
say 'The "'cwd()'/'file'" file has been saved.'
say

return

/*
 * start_serv: starts the license server
 */

start_serv:procedure expose arch hostname lg_clean

  select
    when arch() = 'sparc' | arch = 'i86pc' then pscmd = '/usr/bin/ps -e'
    when arch = 'sun' | arch = 'alpha' | arch = 'ibm' | arch = 'esa' | arch = 'linux' then pscmd = 'ps ax'
    when arch = 'hp'  | arch = 'sgi' | arch = 'sco' | arch = 'uxw' | arch = 'sinix' then pscmd = 'ps -e'
    otherwise
       pscmd = 'ps ax'
       say ' ********** start_serv: Warning: unknown architecture.'
  end

  say  '... Checking for "xserv" processes; wait.'
  call unix  pscmd "| egrep xserv | egrep -v '(egrep|ps|install|xserverrc)'", ps

  if ps.0 ~= 0 then do
     say
     say 'The following "xserv" processes are running:'
     say
     do i=1 to ps.0
       say '   'ps.i
     end
     say
     say 'They must be killed before restarting the new license server.'
     sayn 'Do you want to kill these processes? '
     pull rep .
     if left(rep,1) ~= 'Y' then return

     do i=1 to ps.0
       parse var ps.i id .
       say '... killing 'id
       rep.1 = 'no such'
       call unix 'kill -9 'id, rep
       if result ~= 0 then do
          if 0 = index(lower(rep.1), 'no such') then do
            say 'Unable to kill process 'id';please retry while being root.'
            return
          end
       end
     end

     say
     say '.... All "xserv" processes killed.'
  end
  say
  say '.... Starting "xserv"'
  say

  './xserv -fg .'

  if rc ~= 0 then do
    say '.... Unable to start the license server "xserv".'
    return 1
  end
  else  say '.... "xserv" started.'


return 0

/*
 * inst_mwmrc modifies (or create) ~/.mwmrc in order to allow the use
 * of the ALT-Mouse keys (rectangular selections)
 */
inst_mwmrc:procedure

  trace off
  FILE = '~/.mwmrc'
  if ~state(FILE) then
   { if ~$?LANG | $LANG = 'C' then
        sys_mwmrc = '/usr/lpp/X11/Motif1.2/app-defaults/system.mwmrc'
     else
        sys_mwmrc = '/usr/lpp/X11/lib/X11/'$LANG'/system.mwmrc'

     if ~state(sys_mwmrc) then
      { say
        say 'install: unable to find "'sys_mwmrc'"'
        say 'install: MOTIF 1.2 may not be installed on your system.'
        say
        exit 1
      }

     say
     say 'install: copying "'sys_mwmrc'" in your home directory.'
     sayx 'cp 'sys_mwmrc $HOME'/.mwmrc'
     if rc ~= 0 then
      { say 'install: unable to copy "'sys_mwmrc'" in your home directory.'
        exit 1
      }
   }

  say
  say 'install: checking ~/.mwmrc'
  found = 0
  line  = 1

  do i = 1 to 100000

    'execio * diskr . mwmrc ~ 'line'(locate /Meta<Btn/ stem ff.'

    select
      when rc = 2 | rc = 3 then leave i   /* End of File or Not Found */

      when rc = 0 then
       { parse var ff.2 . line
         new = change(ff.1, "window", "frame")
         if new ~= ff.1 then
          { if found = 0 then
             { k = 1
               do forever
                  backup = $HOME'/'k'.mwmrc'
                  if ~state(backup) then leave
                  k = k+1
               end
               say 'install: saving ~/.mwmrc into 'backup
               sayx 'cp '$HOME'/.mwmrc 'backup
              }

            found = found + 1
            say 'install: modifying line 'line
            say '         "'ff.1'"'
            say '  --->   "'new'"'
            say
            'execio 1 diskw . mwmrc ~ 'line'( var new'
            if rc ~= 0 then
             { 'install: unable to write in ~/.mwmrc'
               exit 1
             }
          }
       }

      otherwise
        say 'install: unable to read ~/.mwmrc'
        exit 1
    end

    line = line+1

  end i

  select
      when found = 0 then say 'install: no modification done in ~/.mwmrc'
      when found = 1 then say 'install: done 1 modification in ~/.mwmrc'
      otherwise           say 'install: done 'found' modifications in ~/.mwmrc'
  end

  if found ~= 0 then
   { say
     say 'install: you may retreive your previous ~/.mwmrc file by typing:'
     say
     say '         cp 'backup $HOME'/.mwmrc'
     say
   }

return      /*  inst_mwmrc:procedure */

mkdir_rec:procedure

  parse arg dd
  nb = 0
  do forever
    dd = fd(dd)
    if dd = '/' then leave
    if ~state(dd, 'd') then do
      nb = nb + 1
      tab.nb = dd
    end
  end

  do i = nb to 1 by -1
      say 'mkdir 'tab.i
      call mkdir tab.i
  end
  return

rmv_file:procedure

 parse arg a

 i=1
 do forever
   new = a'.'i
   if ~state(new) then
    { sayx 'mv 'a new
      return
    }
   i = i+1
 end

 return  /* NOTREACHED */

novalue:
  say 'install: internal error 1 (no value) on line' sigl
  exit 1

halt:
  say
  say
  say 'install: user interrupt at line' sigl
  /* say sourceline(sigl) */
  say
  exit 2
