home *** CD-ROM | disk | FTP | other *** search
- /* This is a sample user application, to show you examples of using the new
- way of configuring E.
-
- First, if you need any of the standard constants or colors, you can simply
- include the appropriate files. The constants take up no additional space
- in the .EX file if they're unused:
- include 'STDCONST.E'
- include 'COLORS.E'
-
- If your application can be compiled standalone (for linking at runtime) or
- included with the base E files, then you can check which case you're in by
- testing to see if a constant included in the base macros is defined. We've
- been using SMALL: */
- const
- compile if defined(SMALL)
- STAND_ALONE = 0 -- We're being included in the base macros
- compile else
- STAND_ALONE = 1 -- We're being compiled stand-alone
- compile endif
-
- /* Now, if we need to use E's configuration constants, we can easily do so.
- Previously, we couldn't since the user made changes to STDCNF.E, and we
- couldn't include that file since it had a DEFINIT in it. Now, the user
- should only modify MYCNF.E, which we can safely include. (This could
- actually be included in the COMPILE IF statements above, but it's broken
- out here for clarity.)
-
- Note that after trying to include MYCNF, we have initialization code
- that's copied from STDCNF.E, so after this section, the constants should
- be defined the same way they would be if we were included in E.E. */
-
- compile if STAND_ALONE -- or, COMPILE IF NOT DEFINED(SMALL)
- define INCLUDING_FILE = 'USERAPP.SMP' -- Specify the file that's including MYCNF
- tryinclude 'mycnf.e' -- Include user's configuration
-
- compile if not defined(SITE_CONFIG) -- Did user's MYCNF.E set a SITE_CONFIG file?
- const SITE_CONFIG = 'SITECNF.E' -- If not, use the default
- compile endif
- compile if SITE_CONFIG -- If SITE_CONFIG file was not set to null,
- tryinclude SITE_CONFIG -- include the site configuration file.
- compile endif
-
- compile if not defined(USE_APPEND) -- because we need these variables
- USE_APPEND = 0 -- and this sets them properly.
- compile endif
-
- compile if not defined(WANT_SEARCH_PATH)
- WANT_SEARCH_PATH = 0
- compile endif
-
- compile if not defined(WANT_GET_ENV)
- compile if EVERSION < 4
- WANT_GET_ENV = 0
- compile else
- WANT_GET_ENV = 1
- compile endif
- compile endif
-
- compile if not defined(EPATH)
- compile if EVERSION>=5 -- EPM uses a different name, for easier coexistance
- EPATH= 'epmpath'
- compile else
- EPATH= 'epath'
- compile endif
- compile endif
- compile endif
-
- /* If your routine has private constants, you can do the same sort of thing
- (except outside of the COMPILE IF STAND_ALONE), in order to let your users
- define your constants in their MYCNF.E. That makes it easier to upgrade
- to a new version of your code, since they don't have to patch in their own
- settings.
-
- Now, finally, the sample code. This is a simple routine to edit a file. If
- the file is not in the current subdirectory, it is searched for along the
- EPATH.
-
- This routine requires the SEARCH_PATH and GET_ENV procedures. These
- routines are optional, and are only included if the corresponding WANT_
- constant is set to 1, or are both included if the USE_APPEND constant is
- set to 1. First I define the new command, then I include the necessary
- routines if and only if the user doesn't have them included in the base
- set of macros. (Note that if this is being compiled stand-alone, then
- I could simply include the two procedures, but this would waste space
- in the .EX file if the user was including them in the base E.EX. */
- defc ep, epath=
- parse arg filename .
- if not exist(filename) then
- filename = search_path(Get_Env(EPATH),filename)filename
- endif
- 'e' filename
-
- /* The following two routines are copied directly from DOSUTIL.E. */
- compile if not (USE_APPEND | WANT_SEARCH_PATH) -- This might already be included in user's E.
- defproc search_path(AppendPath, FileName)
- do while AppendPath<>''
- parse value AppendPath with TryDir ';' AppendPath
- if trydir='' then iterate; endif
- lastch=substr(TryDir,length(TryDir),1)
- if lastch<>'\' & lastch<>':' then
- TryDir = TryDir||'\'
- endif
- if exist(TryDir||FileName) then
- return TryDir
- endif
- enddo
- return ''
- compile endif
-
- compile if not (USE_APPEND | WANT_GET_ENV) -- This might already be included in user's E.
- defproc get_env(varname)=
- varname = upcase(varname)
- env_ofs = 0
- compile if EVERSION>=4
- compile if EVERSION<'4.10' -- If no more family mode, don't check machine()
- if machine()='OS2PROTECT' then
- compile endif
- seg_ptr = 1234
- cmd_ptr = 1234
- call dynalink('DOSCALLS',
- '#91',
- selector(seg_ptr) ||
- offset(seg_ptr) ||
- selector(cmd_ptr) ||
- offset(cmd_ptr) )
- env_seg=itoa(seg_ptr,10)
- compile if EVERSION<'4.10' -- If no more family mode, don't check machine()
- else
- compile endif
- compile endif
- compile if EVERSION<'4.10'
- if dos_version() < 300 then
- sayerror 'DOS version 3.0 or above required for Get_Env Address.'
- return ''
- endif
- parse value int86x(33,25088,'') with . PSP_seg . -- Int 21H, AH=62H
- env_seg = asc(peek(PSP_seg,45,1)) * 256 + asc(peek(PSP_seg,44,1))
- compile if EVERSION>='4.02'
- endif
- compile endif
- compile endif
- do while peek(env_seg,env_ofs,1) /== \0 -- (backslash) 0 == ASCII null
- start = env_ofs
- do while peek(env_seg,env_ofs,1) /== \0
- env_ofs = env_ofs + 1
- end
- setting = peek(env_seg,start,env_ofs-start)
- parse value setting with name '=' parameter
- if name=varname then return parameter; endif
- env_ofs=env_ofs+1
- end
- return ''
- compile endif
-