home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / epmmac.zip / USERAPP.SMP < prev   
Text File  |  1992-12-18  |  6KB  |  154 lines

  1. /* This is a sample user application, to show you examples of using the new
  2.    way of configuring E.
  3.  
  4.    First, if you need any of the standard constants or colors, you can simply
  5.    include the appropriate files.  The constants take up no additional space
  6.    in the .EX file if they're unused:
  7. include 'STDCONST.E'
  8. include 'COLORS.E'
  9.  
  10.    If your application can be compiled standalone (for linking at runtime) or
  11.    included with the base E files, then you can check which case you're in by
  12.    testing to see if a constant included in the base macros is defined.  We've
  13.    been using SMALL:                                                          */
  14. const
  15. compile if defined(SMALL)
  16.    STAND_ALONE = 0         -- We're being included in the base macros
  17. compile else
  18.    STAND_ALONE = 1         -- We're being compiled stand-alone
  19. compile endif
  20.  
  21. /* Now, if we need to use E's configuration constants, we can easily do so.
  22.    Previously, we couldn't since the user made changes to STDCNF.E, and we
  23.    couldn't include that file since it had a DEFINIT in it.  Now, the user
  24.    should only modify MYCNF.E, which we can safely include.  (This could
  25.    actually be included in the COMPILE IF statements above, but it's broken
  26.    out here for clarity.)
  27.  
  28.    Note that after trying to include MYCNF, we have initialization code
  29.    that's copied from STDCNF.E, so after this section, the constants should
  30.    be defined the same way they would be if we were included in E.E.          */
  31.  
  32. compile if STAND_ALONE         -- or, COMPILE IF NOT DEFINED(SMALL)
  33.  define INCLUDING_FILE = 'USERAPP.SMP'  -- Specify the file that's including MYCNF
  34.   tryinclude 'mycnf.e'                 -- Include user's configuration
  35.  
  36.  compile if not defined(SITE_CONFIG)  -- Did user's MYCNF.E set a SITE_CONFIG file?
  37.     const SITE_CONFIG = 'SITECNF.E'   -- If not, use the default
  38.  compile endif
  39.  compile if SITE_CONFIG               -- If SITE_CONFIG file was not set to null,
  40.     tryinclude SITE_CONFIG            -- include the site configuration file.
  41.  compile endif
  42.  
  43.   compile if not defined(USE_APPEND)   -- because we need these variables
  44.   USE_APPEND = 0                       -- and this sets them properly.
  45.   compile endif
  46.  
  47.   compile if not defined(WANT_SEARCH_PATH)
  48.   WANT_SEARCH_PATH = 0
  49.   compile endif
  50.  
  51.   compile if not defined(WANT_GET_ENV)
  52.     compile if EVERSION < 4
  53.   WANT_GET_ENV = 0
  54.     compile else
  55.   WANT_GET_ENV = 1
  56.     compile endif
  57.   compile endif
  58.  
  59.   compile if not defined(EPATH)
  60.     compile if EVERSION>=5  -- EPM uses a different name, for easier coexistance
  61.   EPATH= 'epmpath'
  62.     compile else
  63.   EPATH= 'epath'
  64.     compile endif
  65.   compile endif
  66. compile endif
  67.  
  68. /* If your routine has private constants, you can do the same sort of thing
  69.    (except outside of the COMPILE IF STAND_ALONE), in order to let your users
  70.    define your constants in their MYCNF.E.  That makes it easier to upgrade
  71.    to a new version of your code, since they don't have to patch in their own
  72.    settings.
  73.  
  74.    Now, finally, the sample code.  This is a simple routine to edit a file.  If
  75.    the file is not in the current subdirectory, it is searched for along the
  76.    EPATH.
  77.  
  78.    This routine requires the SEARCH_PATH and GET_ENV procedures.  These
  79.    routines are optional, and are only included if the corresponding WANT_
  80.    constant is set to 1, or are both included if the USE_APPEND constant is
  81.    set to 1.  First I define the new command, then I include the necessary
  82.    routines if and only if the user doesn't have them included in the base
  83.    set of macros.  (Note that if this is being compiled stand-alone, then
  84.    I could simply include the two procedures, but this would waste space
  85.    in the .EX file if the user was including them in the base E.EX.           */
  86. defc ep, epath=
  87.    parse arg filename .
  88.    if not exist(filename) then
  89.       filename = search_path(Get_Env(EPATH),filename)filename
  90.    endif
  91.    'e' filename
  92.  
  93. /* The following two routines are copied directly from DOSUTIL.E.             */
  94. compile if not (USE_APPEND | WANT_SEARCH_PATH)  -- This might already be included in user's E.
  95. defproc search_path(AppendPath, FileName)
  96.    do while AppendPath<>''
  97.       parse value AppendPath with TryDir ';' AppendPath
  98.       if trydir='' then iterate; endif
  99.       lastch=substr(TryDir,length(TryDir),1)
  100.       if lastch<>'\' & lastch<>':' then
  101.          TryDir = TryDir||'\'
  102.       endif
  103.       if exist(TryDir||FileName) then
  104.          return TryDir
  105.       endif
  106.    enddo
  107.    return ''
  108. compile endif
  109.  
  110. compile if not (USE_APPEND | WANT_GET_ENV)  -- This might already be included in user's E.
  111. defproc get_env(varname)=
  112.    varname = upcase(varname)
  113.    env_ofs = 0
  114. compile if EVERSION>=4
  115.  compile if EVERSION<'4.10'     -- If no more family mode, don't check machine()
  116.    if machine()='OS2PROTECT' then
  117.  compile endif
  118.       seg_ptr = 1234
  119.       cmd_ptr = 1234
  120.       call dynalink('DOSCALLS',
  121.                     '#91',
  122.                     selector(seg_ptr) ||
  123.                     offset(seg_ptr)   ||
  124.                     selector(cmd_ptr) ||
  125.                     offset(cmd_ptr)     )
  126.       env_seg=itoa(seg_ptr,10)
  127.  compile if EVERSION<'4.10'     -- If no more family mode, don't check machine()
  128.    else
  129.  compile endif
  130. compile endif
  131. compile if EVERSION<'4.10'
  132.       if dos_version() < 300 then
  133.          sayerror 'DOS version 3.0 or above required for Get_Env Address.'
  134.          return ''
  135.       endif
  136.       parse value int86x(33,25088,'') with . PSP_seg .  -- Int 21H, AH=62H
  137.       env_seg = asc(peek(PSP_seg,45,1)) * 256 + asc(peek(PSP_seg,44,1))
  138.  compile if EVERSION>='4.02'
  139.    endif
  140.  compile endif
  141. compile endif
  142.    do while peek(env_seg,env_ofs,1) /== \0  -- (backslash) 0 == ASCII null
  143.       start = env_ofs
  144.       do while peek(env_seg,env_ofs,1) /== \0
  145.          env_ofs = env_ofs + 1
  146.       end
  147.       setting = peek(env_seg,start,env_ofs-start)
  148.       parse value setting with name '=' parameter
  149.       if name=varname then return parameter; endif
  150.       env_ofs=env_ofs+1
  151.    end
  152.    return ''
  153. compile endif
  154.