home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 November / PCO_1198.ISO / filesbbs / os2 / epmtfe22.arj / EPMTFE22.ZIP / SOURCE / texfe.e < prev    next >
Encoding:
Text File  |  1998-09-07  |  73.4 KB  |  2,143 lines

  1. /**************************************************************************/
  2. /*                                                                        */
  3. /* What's it called: EPM TeX Front End (texfe.e)                          */   
  4. /*                                                                        */
  5. /*                                                                        */
  6. /* What does it do:  The E source code for the EPM TeX Front End          */
  7. /*                                                                        */
  8. /* Who and When:     Originally written as 'EPMTeX' by John Hacker,       */
  9. /*                   Rodney Korte, Thorsten Domsalla and Joachim Koenen,  */
  10. /*                   1/1993-10/1995;                                      */
  11. /*                   this version by Walter Schmidt,  9/1998,             */
  12. /*                   with contributions by Wonkoo Kim.                    */
  13. /*                                                                        */
  14. /**************************************************************************/
  15.  
  16. /*
  17.  
  18. Version 2.2
  19.  
  20.     * Default value of LATEX_SYNTAX_INDENT is now 2
  21.     
  22.     * Improved syntax assist:  Arguments of environments may appear on
  23.     the same line.  Arbitrary long environment names are recognized.
  24.     Reasonable handling of the "verbatim" and "macrocode" environments.
  25.     (See file texfek.e)
  26.     
  27.     * Optimized code for processing the EPMTeX accelerator keys; approx.
  28.     1kB smaller than the previous version.  (See file texfed.e)
  29.  
  30.  
  31. Version 2.1
  32.  
  33.     * tex_file_in_ring() rewritten; files differing in path only 
  34.     should now be handled properly.
  35.     
  36.     * Call 'TeXMenuEnable' once more, because the TeX menu would be
  37.     enabled erroneously under certain circumstances.  There is, however,
  38.     no complete solution to this problem.
  39.     
  40.     * Fixed the menu item "Menu always on', which would not display its
  41.     current setting.
  42.     
  43.     
  44. Version 2.0
  45.  
  46.     * The TeX menu is now provided with the module, too.
  47.     
  48.     * The default format can be changed via the settings menu; manual
  49.     format select is no longer provided.
  50.     
  51.     * Removed the menu item "Delete log file".
  52.  
  53.     * Bug fix: Customized <enter> key would not be honored
  54.     
  55.     * Bug fix: \end{...} would not be properly indented
  56.     
  57.     * New optional feature: Simple automatic indentation within LaTeX
  58.     environmemts, controlled by const LATEX_SYNTAX_INDENT.
  59.     
  60.     * Syntax assist (expansion): \fo -> \footnote{}
  61.     
  62.     * "Menu always on" can be toggled via the TeX menu only.
  63.     
  64.     * const EXTENDED_LATEX_ASSIST = 1 will include Juan J.G.Ripoll's
  65.     LaTeX auto-indentation package.
  66.     
  67.     * strip leading and trailing spaces from settings values which are 
  68.     entered interactively
  69.  
  70.  
  71. Version 1.1
  72.  
  73.     * Bug fix:  Menu item "Master file support" was broken.  (Only vith
  74.     v1.1 as of 1998-01-07.)
  75.     
  76.     * Added "Cancel" buttons to options entry box and to "process 
  77.     marked region" dialog box.
  78.     
  79.     * TeXing a marked region is now possible with plain TeX, too.  The
  80.     end of the header is indicated by "%**end of header"
  81.  
  82.     * "Locate Next Error" and "View Log File" will always refer to the 
  83.     log file of the *latest* TeX run.  The name of the log file is
  84.     memorized from one EPM invocation to the next and will be displayed 
  85.     while definit.
  86.  
  87.     * "Locate Next Error" will again draw a circle around the location
  88.     of the error.  I have found a reliable (!) method to do so.
  89.  
  90.     * "Locate next error" will at least display the name of the TeX
  91.     input file an error message refers to, if line number of error is
  92.     not indicated in the transcript file.
  93.  
  94.     * "View Log File" will reset the error browsing facility when called
  95.     from within the log file.
  96.     
  97.     * rewrote tex_more_errors(), the old one was too obscure ...
  98.     
  99.     * fixed a bug which caused the first line of the log file to be 
  100.     displayed instead of the recently found error, if the Log action was
  101.     triggered after the last error in the file had been processed.
  102.  
  103.     * The TeX command connected with a certain format can now be an exe
  104.     file, too.
  105.  
  106.     * Syntax highlighting is checked while defload; file types DTX and
  107.     FDD are never highlighted.
  108.     
  109.     * *Each* occurence of %**N or %**F in the external commands will now
  110.     be replaced with the filename.
  111.     
  112.     * Syntax assist: Fixed a bug which prevented the description
  113.     environment from being recognized (file texfek.e).
  114.     
  115.     * Syntax assist (expansion):
  116.     New :    \la -> \label{},   \re -> \ref{}
  117.     Removed: \hs -> \hspace{},  \vs -> \vspace{}
  118.  
  119.     * Preview, user commands etc.  will no longer change into master
  120.     file.  However, they cannot be executed, if master file does not
  121.     exist, regardless of the associated file type.
  122.  
  123.     * In case an external command is undefined, the corresponding menu
  124.     item or toolbar button will display an appropriate error message.
  125.     
  126.     * Replaced various error messages with pop-up windows for better 
  127.     information.
  128.     
  129.     * Pro version: "Shell" and "Folder" added to the "Command" and 
  130.     "File" submenus, instead of creating an "OS/2" submenu.  Applies 
  131.     only if STD_MENU_NAME is undefined, i.e. the standard menu is used.
  132.     
  133.     * Code optimization; no more unnecessary directory switching etc.
  134.  
  135.     * Many changes to the messages in texfeen.e
  136.  
  137.     * German version
  138.     
  139.     * rewrote the settings menu due to NLS support
  140.  
  141.  
  142. Version 1.0
  143.  
  144.     * TeX a marked region of the current file
  145.  
  146.     * Various changes to tex_extract_filename and tex_find_errors. 
  147.     Should now handle *all* TeX error messages!  If location of error 
  148.     cannot be determined, the log file will be displayed.
  149.  
  150.     * "View LOG File" now goes to the line of the last error which has 
  151.     been located before; the parsing routines will only be initialized, 
  152.     if there are no more errors or the log file is not found in the 
  153.     ring.
  154.  
  155.     * The log file being viewed is read-only.
  156.  
  157.     * Fixed one more error affecting handling of filenames without 
  158.     extension, in the procedure tex_file_in_ring.
  159.  
  160.     * Removed defc tex_warning
  161.     
  162.     * In case a specified master file does not exist, the current action
  163.     will be stopped without querying "Continue processing ... ?".
  164.  
  165.     * Fixed the TeX/PS action, which used to fail with file types other
  166.     than '.TEX'.
  167.     
  168.     * The name of the dvips executable will be determined from the INI 
  169.     file.  The default is 'dvips', as before.
  170.  
  171.     * The debug level is no longer saved in the INI file.  Each EPM 
  172.     session will start with TeX_debug = 0 .
  173.  
  174.     
  175. Version 0.96
  176.     
  177.     * File types, highlighting etc.  are configured via a menu.  The
  178.     EPM commands introduced with v0.92 have been removed.
  179.  
  180.     * The procedure tex_locate_error will no longer run into an endless
  181.     loop , if the TeX error does not refer to a line number, e.g.  with
  182.     "runaway argument".  Furthermore, it will move the cursor only; no 
  183.     mark will be set.
  184.  
  185.     * Changes to the syntax assist facility:  Completion of environments
  186.     and keywords will always be active with TeX documents/styles.  The
  187.     new command tex_keys will toggle the behaviour of the accelerator 
  188.     keys only.  The command tex_syntaxassist has been abandoned. 
  189.     New expansion: "\fr " -> "\frac{}{}"
  190.     Removed:       "\it " -> "\item "
  191.  
  192.     * Restored the "Quick Keys":
  193.     TeX               : Ctrl F9
  194.     TeX/PS            : Ctrl F10
  195.     locate next error : Ctlr F11
  196.     view log file     : Ctrl F12
  197.     This was the only way to get the same sequence as in the toolbar, so
  198.     it is necessarily different from EPMTeX's key assignments.
  199.  
  200.     * Restored the EPMTeX accelerator keys
  201.  
  202.  
  203. Changes from epmtex 3.1a to TeX Front End 0.92 (the first public
  204. version):
  205.  
  206.     Toolbar:
  207.  
  208.     * The standard version has no pull-down menus any more.  Instead it
  209.     is controlled via the toolbar.  This is because the menu identifiers
  210.     from different modules may collide.  With the Pro version one has
  211.     the source code available and can ensure unique menu identifiers.
  212.     
  213.     Files:
  214.  
  215.     * TeX documents are no longer required to have the extension .TEX
  216.  
  217.     * Since TeXing is no longer restricted to .TEX files, there are now
  218.     three different lists of 'file extensions to associate with TeX':
  219.     One for TeX documents, another one for style files, and a third one 
  220.     for auxiliary files.  The syntax assist is available with the 
  221.     documents and the style files, and the auxiliary files are those 
  222.     which provide syntax highlighting and the quick keys, too.  The TeX 
  223.     menu of the Pro version is enabled with file types from any list.
  224.     
  225.     Formats:
  226.  
  227.     * The default format is 'latex', unless there is a different 
  228.     specification in the configuration file.
  229.  
  230.     * Each format is called through its own batch file, so that the TeX
  231.     options and the environment settings can be specified individually.
  232.     
  233.     Configuration, external programs:
  234.  
  235.     * The master file support is now toggled via the menu resp.  the
  236.     toolbar.
  237.     
  238.     * The program epmtex.exe has disappeared.  Instead, some of the
  239.     settings are controlled via EPM commands; others are defined in a
  240.     text file TFE.CFG and transferred to EPM.INI by a configuration
  241.     script named TFCONFIG.CMD, which is *not* run from within the EPM.
  242.     The entries in the configuration file specify EPM commands, so that
  243.     one can run external programs (start /n program), EPM REXX programs
  244.     (rx program) or built-in EPM commands (sayerror ...).
  245.  
  246.     * Options may be passed interactively to external programs; see the 
  247.     documentation.  Thus e.g. the printer driver can now be told to 
  248.     process a certain range of pages only.
  249.  
  250.     * The passing of the filename to an external command has been 
  251.     changed:  Within the "executable file name" (i.e.  the command
  252.     line) the following substitutions will occur:
  253.  
  254.       %**N  ->  the filename without extension
  255.       %**F  ->  the filename incl. extension
  256.  
  257.     This syntax is similar to the WPS, and it should cover all possible
  258.     calling schemes of external programs.  In case none of the above
  259.     strings is present, the filename will *not* be passed to the
  260.     program.
  261.     
  262.     New features:
  263.  
  264.     * The commands for previewimg, printing, dvips and the user commands
  265.     will switch to the master file before running.
  266.     
  267.     * New menu items resp. toolbar buttons:  "Folder" opens the
  268.     directory of the current file as a WPS folder.  "Command Prompt"
  269.     creates an OS/2 shell window in the directory of the current file.
  270.  
  271.     * New menu items for dvips and Postscript viewing (Ghostview) have
  272.     been added.  (In case your *printer* supports Postscript, then you
  273.     just have to specify dvips to be used as the printer driver, too.)
  274.  
  275.     * There is a new menu item named TeX/PS.  It will run TeX and dvips
  276.     in sequence, so that you need not call dvips explicitly.  This is 
  277.     useful if you know that you will have to preview your document via
  278.     Postscript, because it contains Type 1 fonts or other Postscript
  279.     material.
  280.  
  281.     * The syntax assist facility will recognize more expansions: 
  282.       "equ " -> "equation" 
  283.       "eqn " -> "eqnarray"
  284.       "\hs " -> "\hspace"
  285.       "\vs " -> "\vspace"
  286.  
  287.     Removed features:
  288.  
  289.     * The 'TeX margins' have been removed due to their somewhat obscure
  290.     interaction with the `general' margins setting:  Switching the TeX
  291.     margins ON does not immediately affect the current file, but when
  292.     you open and close the settings notebook while the TeX margins are
  293.     active, then they will be saved, too, and become the 'general'
  294.     default for all file types.  (I do understand what happens here,
  295.     but what about users who are interested in writing texts and not in
  296.     the EPM internals?)
  297.     
  298.     * The 'user defined formats' have disappeared.  To my opinion it is 
  299.     difficult to understand why there are two different ways of defining
  300.     the format to be used: The 'automatic format selection' and the 
  301.     'user formats'.
  302.  
  303.     * The following features have also been removed:
  304.       Orientation
  305.       Resolving of references to environment variables (Will perhaps 
  306.         return in a later version)
  307.       Unix style directory separators
  308.       The menu item 'Remove DVI file'
  309.       The option 'Auto save' (i.e. it is now always on)
  310.       The option 'Auto log delete' (i.e. it is now always off)
  311.       The 'Quick keys' (they may return in a later version)
  312.       The 'Accelerator keys', except for '{', '$' and Ctrl-x,
  313.         which are now included in the 'Syntax Assist' option.
  314.       The TeX tabs
  315.       The TeX margins (see above)
  316.       The user formats (see above)
  317.       (My policy was: Keep it small and simple!)
  318.       
  319.     Bug fixes:
  320.  
  321.     * Dependent files will be recognized when given as "\input{file}",
  322.     too.  Formerly only "\input file" and "\include{file}" were allowed.
  323.  
  324.     * Dependent files will no lomger be checked for modification if the
  325.     \input or \include commands are commented out.
  326.     
  327.     * A user defined mouse pointer will no longer be overwritten by the 
  328.     TeX module.
  329.     
  330.     * 'Locate Next Error' has been made much more robust and handles
  331.     arbitrary filenames now.
  332.  
  333.     * The initialization code is no longer executed multiple times.
  334.     
  335.     Source code:
  336.     
  337.     * When compiling the Pro version, the TeX module is now included
  338.     into EPM.EX so that no separate .ex file must be loaded at startup 
  339.     time.
  340.  
  341.     * All messages are defined in a separate file so that support for
  342.     different languages will be possible in the future.
  343.     
  344.     * Cleaned up the source code, removed unused universal variables
  345.     etc.
  346.  
  347.  
  348. Known bugs and deficiencies:
  349.  
  350.     * You cannot TeX a file which has no `type'.
  351.  
  352.     * The LaTeX command \includeonly should be honored when master file
  353.     support is on.
  354.     
  355.     * Only one simgle \include or \input command per line is recognized.
  356.     
  357.     * A folder opened via tex_fm cannot be closed through the window
  358.     list.
  359.     
  360.     * The TeX menu is somteimes enabled erroineously, e.g., when a new 
  361.     module is losdad which adds its own submenu.
  362.  
  363.     * You cannot jump back to the _previous_ error.
  364.  
  365.     * You cannot request the window of a command to stay open after
  366.     completion, because the `start' command has no such option.  This
  367.     would sometimes be convenient, so as to see whether a command has
  368.     terminated normally or with an error message.
  369.     
  370.     * You cannot request a user command to check whether the document 
  371.     and the dependent files need to be saved before the command is 
  372.     executed.
  373. */
  374.  
  375. /*********************************/
  376. /*                               */
  377. /*  We need EPM 6.03b or later   */
  378. /*                               */
  379. /*********************************/
  380.  
  381. compile if EVERSION < '6.03b'
  382.   *** Error: EPM version 6.03b required
  383. compile endif
  384.  
  385.  
  386.  
  387.  
  388. /******************************/
  389. /*                            */
  390. /*  Standard or Pro version   */
  391. /*                            */
  392. /******************************/
  393.  
  394. compile if not defined(SMALL) -- being separately compiled
  395.   const TEXFEPRO = 0
  396. compile else                  -- integrated "Pro(fessional)" version
  397.   const TEXFEPRO = 1
  398. compile endif
  399.  
  400.  
  401.  
  402. /*
  403. ┌────────────────────────────────────────────────────────────────────────────┐
  404. │  Include the standard stuff we need  when we are compiling separately      │
  405. │  from epm.ex.                                                              │
  406. └────────────────────────────────────────────────────────────────────────────┘
  407. */
  408.  
  409. compile if not defined(SMALL)  -- Being compiled separately
  410.   include 'stdconst.e'
  411.   include 'colors.e'
  412.   define INCLUDING_FILE = 'TEXFE.E'
  413.   tryinclude 'MYCNF.E'
  414.   compile if not defined(SITE_CONFIG)
  415.     const SITE_CONFIG = 'SITECNF.E'
  416.   compile endif
  417.   compile if SITE_CONFIG
  418.     tryinclude SITE_CONFIG
  419.   compile endif
  420.   compile if not defined(NLS_LANGUAGE)
  421.     const NLS_LANGUAGE = 'ENGLISH'
  422.   compile endif
  423. compile endif -- SMALL
  424.  
  425.  
  426.  
  427. /*********************************************/
  428. /*                                           */
  429. /* TeX menu and extended LaTeX syntax assist */
  430. /*                                           */
  431. /*********************************************/
  432.  
  433. compile if not defined(WANT_TEX_MENU) -- may have been defined in MYCNF.E
  434.   define WANT_TEX_MENU = 1  -- default is to include the menu
  435. compile endif
  436.  
  437. compile if not defined(EXTENDED_LATEX_ASSIST)
  438.   define EXTENDED_LATEX_ASSIST = 0
  439. compile endif
  440.  
  441.  
  442. /*******************/
  443. /*                 */
  444. /*  Version info   */
  445. /*                 */
  446. /*******************/
  447.  
  448. define PrimVersion = '2.2'
  449.  
  450. const
  451. compile if TEXFEPRO
  452.   TEXFE_VERSION = PrimVersion || ' Pro'
  453. compile else
  454.   TEXFE_VERSION = PrimVersion
  455. compile endif /* TEXFEPRO */
  456.   TEXFE_COPYRIGHT_STRING = '(C) Walter Schmidt 1997-1998'
  457.  
  458. /* Within EPM.INI this application identifies itself as EPMTFE */
  459. TEX_APP = 'EPMTFE'
  460.  
  461.  
  462.  
  463. /************************/
  464. /*                      */
  465. /* Include NLS support  */
  466. /*                      */
  467. /************************/
  468.  
  469. /* only German and English currently available */
  470. compile if NLS_LANGUAGE = 'DEUTSCH'
  471.    include 'texfede.e'
  472. compile else
  473.    include 'texfeen.e'
  474. compile endif
  475.  
  476.  
  477.  
  478. /**************************************/
  479. /*                                    */
  480. /*   definit, defselect and defload   */
  481. /*                                    */
  482. /**************************************/
  483.  
  484. definit  -- called once at startup time
  485.    universal app_hini,
  486.              tex_debug,
  487.              tex_log_file_name,
  488.              tex_log_file_line,
  489.              tex_log_file_curr
  490. compile if EXTENDED_LATEX_ASSIST
  491.    universal TeX_Margin
  492. compile endif
  493.  
  494. -- we initialize the information in the INI file, if necessary
  495.     
  496.    answer = queryprofile(app_hini, TEX_APP, 'VERSION')
  497.    if answer <> TEXFE_VERSION then
  498.       -- the database might have been changed,
  499.       -- so we must check some of the settings:
  500.       answer = queryprofile(app_hini, TEX_APP, 'DVIPS_EXEC')
  501.       if answer = '' then
  502.          call setprofile(app_hini, TEX_APP, 'DVIPS_EXEC', 'dvips')
  503.       endif
  504.       answer = queryprofile(app_hini, TEX_APP, 'FILETYPES')
  505.       if answer = '' then
  506.          call setprofile(app_hini, TEX_APP, 'FILETYPES', 'AUX LOG')
  507.       endif
  508.       answer = queryprofile(app_hini, TEX_APP, 'STYLETYPES')
  509.       if answer = '' then
  510.          call setprofile(app_hini, TEX_APP, 'STYLETYPES', 'STY')
  511.       endif
  512.       answer = queryprofile(app_hini, TEX_APP, 'DOCTYPES')
  513.       if answer = '' then
  514.          call setprofile(app_hini, TEX_APP, 'DOCTYPES', 'TEX')
  515.       endif
  516.       answer = queryprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT')
  517.       if answer = '' then
  518.          call setprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT', 'LaTeX')
  519.       endif
  520.       -- leave an 'ok' mark:
  521.       call setprofile(app_hini, TEX_APP, 'VERSION', TEXFE_VERSION)
  522.    endif -- VERSION
  523.  
  524.    compile if WANT_TEX_MENU
  525.    'PostMe BuildTexMenu'    -- delay creating menu until after the definit
  526.    compile endif
  527.  
  528. -- we initialize the debug level
  529.    tex_debug = 0
  530.  
  531. -- we initialize log file processing
  532.    tex_log_file_name = queryprofile(app_hini, TEX_APP, 'LOGFILE')
  533.    if tex_log_file_name <> '' then
  534.       sayerror TEX_LOGINIT_STRING||tex_log_file_name
  535.    endif
  536.    tex_log_file_line = 1
  537.    tex_log_file_curr = 1
  538.  
  539. -- we initialize the TeX line width
  540. compile if EXTENDED_LATEX_ASSIST
  541.    TeX_Margin = queryprofile(app_hini, TEX_APP, 'MARGIN')
  542.    if TeX_Margin = '' then
  543.       TeX_Margin = 72
  544.       call setprofile(app_hini, TEX_APP, 'MARGIN', 72)
  545.    endif
  546. compile endif
  547.  
  548. defselect -- called at startup time and when switching files
  549.  
  550.     compile if TEXFEPRO and WANT_TEX_MENU
  551.     -- enable the TeX menu if TeX file loaded
  552.     'PostMe TexMenuEnable'
  553.     compile endif
  554.  
  555.     -- load any requested keysets and enable syntax expansion
  556.     call setTexKeySets()
  557.     
  558. compile if EXTENDED_LATEX_ASSIST
  559.     -- set margins to infinity, so as not to collide with TeX margins,
  560.     -- when a TeX document or style file is edited
  561.     call setTeXMargins()
  562. compile endif
  563.  
  564. defload -- called when loading a file
  565.    -- set hiliting if TeX file loaded
  566.    call setTexHilite()
  567.  
  568.  
  569. /**********************************************************/
  570. /*                                                        */
  571. /*  include the key set and the syntax assist functions   */
  572. /*                                                        */
  573. /**********************************************************/
  574.  
  575. compile if EXTENDED_LATEX_ASSIST
  576.   include 'emacs.e'
  577.   include 'xtexfek.e'
  578. compile else
  579.   include 'texfek.e'
  580. compile endif
  581.  
  582.  
  583.  
  584. /****************************/
  585. /*                          */
  586. /*  Define TeX menu system  */
  587. /*                          */
  588. /****************************/
  589.  
  590. compile if WANT_TEX_MENU
  591.  
  592. defc BuildTexMenu
  593.     universal  defaultmenu,
  594.                app_hini
  595.  
  596. -- load in required environment information to build menu system
  597.     TEX_USER1_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER1_MENU_TEXT')
  598.     TEX_USER1__MSG = queryprofile( app_hini, TEX_APP, 'USER1__MSG')
  599.     TEX_USER2_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER2_MENU_TEXT')
  600.     TEX_USER2__MSG = queryprofile( app_hini, TEX_APP, 'USER2__MSG')
  601.     TEX_USER3_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER3_MENU_TEXT')
  602.     TEX_USER3__MSG = queryprofile( app_hini, TEX_APP, 'USER3__MSG')
  603.     TEX_USER4_MENU_TEXT = queryprofile( app_hini, TEX_APP, 'USER4_MENU_TEXT')
  604.     TEX_USER4__MSG = queryprofile( app_hini, TEX_APP, 'USER4__MSG')
  605.  
  606. --  Temporarily delete Help menu so we can put it back later on the end
  607. --  of the menu bar where it belongs!
  608.     deletemenu defaultmenu, HELP_MENU_ID, 0, 0  -- delete the existing Help menu
  609.                                                 -- (we want it to stay at the right)
  610.  
  611. -- OS/2 menu
  612. compile if TEXFEPRO
  613. compile if defined(STD_MENU_NAME)
  614. -- the menu is not the standard one; we build our own OS/2 submenu
  615.    buildsubmenu  defaultmenu, 90, 'OS/~2', \1TEX_OS2__MSG, 0, 0
  616.      buildmenuitem defaultmenu,    90, 910, TEX_OSSHELL_MENU_TEXT, 'tex_osshell'\1TEX_OSSHELL__MSG, 0, 0
  617.      buildmenuitem defaultmenu,    90, 912, TEX_FOLDER_MENU_TEXT,  'tex_fm'\1TEX_FM__MSG,     0, 0
  618. compile else
  619. -- we add the OS/2 items to the "Command" and " File" submenus
  620.      buildmenuitem defaultmenu, 1, 105, \0,                      '',            4, 0
  621.      buildmenuitem defaultmenu, 1, 106, TEX_OSSHELL1_MENU_TEXT, 'tex_osshell'\1TEX_OSSHELL__MSG, 0, 0
  622.      buildmenuitem defaultmenu, 2, 212, \0,                      '',            4, 0
  623.      buildmenuitem defaultmenu, 2, 213, TEX_FOLDER1_MENU_TEXT,  'tex_fm'\1TEX_FM__MSG,     0, 0
  624. compile endif -- STD_MENU_NAME
  625. compile endif -- TEXFEPRO
  626.  
  627. -- TeX menu
  628.     buildsubmenu defaultmenu, 9, '~TeX', \1TEX_BAR__MSG, 0,0
  629.       buildmenuitem defaultmenu, 9, 901, TEX_TEX_MENU_TEXT\9'Ctrl+F9',      'tex'\1TEX_TEX__MSG, 0,0
  630.       buildmenuitem defaultmenu, 9, 908, TEX_TEXPS_MENU_TEXT\9'Ctrl+F10',   'texps'\1TEX_TEXPS__MSG, 0,0
  631.       buildmenuitem defaultmenu, 9, 924, TEX_LOCERR_MENU_TEXT\9'Ctrl+F11',  'tex_locate_error'\1TEX_LOCATE_ERROR__MSG, 0,0
  632.       buildmenuitem defaultmenu, 9, 905, TEX_VIEWLOG_MENU_TEXT\9'Ctrl+F12', 'tex_view_log'\1TEX_VIEW_LOG__MSG,  0,0
  633.  
  634.       buildmenuitem defaultmenu, 9, 902, \0, '', 4, 0
  635.       buildmenuitem defaultmenu, 9, 903, TEX_VIEW_MENU_TEXT,   'tex_view_dvi'\1TEX_VIEW_DVI__MSG,  0,0
  636.       buildmenuitem defaultmenu, 9, 943, TEX_VIEWPS_MENU_TEXT, 'tex_view_ps'\1TEX_VIEW_PS__MSG, 0,0
  637.       buildmenuitem defaultmenu, 9, 904, TEX_PRINT_MENU_TEXT,  'tex_print'\1TEX_PRINT__MSG,  0,0
  638.  
  639.       buildmenuitem defaultmenu, 9, 941, \0, '', 4, 0
  640.       buildmenuitem defaultmenu, 9, 944, TEX_DVIPS_MENU_TEXT,  'tex_dvips'\1TEX_DVIPS__MSG, 0,0
  641.       if TEX_USER1_MENU_TEXT <> '' then
  642.         buildmenuitem defaultmenu, 9, 911, TEX_USER1_MENU_TEXT,'texuser1exec' \1TEX_USER1__MSG, 0,0
  643.       endif
  644.       if TEX_USER2_MENU_TEXT <> '' then
  645.         buildmenuitem defaultmenu, 9, 921, TEX_USER2_MENU_TEXT,'texuser2exec' \1TEX_USER2__MSG, 0,0
  646.       endif
  647.       if TEX_USER3_MENU_TEXT <> '' then
  648.         buildmenuitem defaultmenu, 9, 930, TEX_USER3_MENU_TEXT,'texuser3exec' \1TEX_USER3__MSG, 0,0
  649.       endif
  650.       if TEX_USER4_MENU_TEXT <> '' then
  651.         buildmenuitem defaultmenu, 9, 933, TEX_USER4_MENU_TEXT,'texuser4exec' \1TEX_USER4__MSG, 0,0
  652.       endif
  653.  
  654.       buildmenuitem defaultmenu, 9, 927, \0, '', 4, 0
  655.       buildmenuitem defaultmenu, 9, 931, TEX_CONF_MENU_TEXT,'texfe_settings_window' \1TEX_CONF__MSG,0,0
  656. compile if TEXFEPRO
  657.       buildmenuitem defaultmenu, 9, 940, TEX_MFS_MENU_TEXT, 'tex_master_file_support' \1TEX_MASTER__MSG,0,0
  658.       buildmenuitem defaultmenu, 9, 916, TEX_MAO_MENU_TEXT, 'tex_menu_always_on' \1TEX_MENU__MSG,0,0
  659. compile endif
  660. compile if not TEXFEPRO
  661.       buildmenuitem defaultmenu, 9, 917, \0, '',4, 0
  662.       buildmenuitem defaultmenu, 9, 910, TEX_OSSHELL2_MENU_TEXT, 'tex_osshell'\1TEX_OSSHELL__MSG, 0, 0
  663.       buildmenuitem defaultmenu, 9, 912, TEX_FOLDER2_MENU_TEXT,  'tex_fm'\1TEX_FM__MSG,     0, 0
  664. compile endif
  665.       buildmenuitem defaultmenu, 9, 922, \0, '', 4, 0
  666.       buildmenuitem defaultmenu, 9, 929, TEX_ABOUT_MENU_TEXT, 'tex_ver' HELP_PROD_MENUP__MSG,0,0
  667.  
  668. -- unused & not critical: 923 925 926 928
  669.   
  670.       call readd_help_menu();   -- Put Help menu back in
  671.       showmenu defaultmenu
  672. compile if TEXFEPRO      
  673.       'PostMe TexMenuEnable'
  674. compile endif      
  675.  
  676. compile if TEXFEPRO
  677. defc TexMenuEnable
  678. --  enable the TeX menu only if TeX file loaded
  679. --  or enable if TEX_MENUON is set
  680.  
  681.     universal  app_hini
  682.     
  683.     if queryprofile( app_hini, TEX_APP, 'TEX_MENUON') then
  684.        SetMenuAttribute(9, 16384, 1)
  685.     else
  686.        if tex_is_file() then
  687.           SetMenuAttribute(9, 16384, 1)
  688.        else
  689.           SetMenuAttribute(9, 16384, 0)
  690.        endif
  691.     endif
  692. compile endif -- TEXFEPRO
  693.  
  694. compile endif -- WANT_TEX_MENU
  695.  
  696.  
  697. /*****************************/
  698. /*                           */
  699. /*  Set margins to infinity  */
  700. /*                           */
  701. /*****************************/
  702.  
  703. compile if EXTENDED_LATEX_ASSIST
  704. defproc setTexMargins
  705.    universal expand_on
  706.    if (tex_is_doc() or tex_is_style()) and expand_on then  
  707.      -- if TeX doc/style loaded and syntax expansion is on
  708.      .margins = '1 1599 1'
  709.    endif
  710. compile endif /* EXTENDED_LATEX_ASSIST */
  711.  
  712.  
  713. /**************************/
  714. /*                        */
  715. /*  Enable highlighting   */
  716. /*                        */
  717. /**************************/
  718.  
  719. defproc setTexHilite
  720.     universal  app_hini
  721.  
  722. if .visible and
  723.    tex_is_file() and not ( (filetype()='DTX' or filetype()='FDD') ) and
  724.    queryprofile(app_hini, TEX_APP, 'TEX_SYNTAXHILITE') then
  725.       'toggle_parse 1 EPMKWDS.TEX'
  726. endif
  727.  
  728.  
  729. /********************/
  730. /*                  */
  731. /*  Execute TeX     */
  732. /*                  */
  733. /********************/
  734.  
  735. defc tex
  736.    call tex_run_tex(0)  -- run TeX
  737.  
  738. defc texps
  739.    call tex_run_tex(1)  -- run TeX and dvips
  740.  
  741. defproc tex_run_tex(ps) -- here we do the real work
  742.  
  743.    universal  tex_log_file_line,
  744.               tex_log_file_curr,
  745.               tex_log_file_name,
  746.               app_hini,
  747.               tex_debug
  748.  
  749. -- lockout  if not a TeX document
  750. if not tex_is_doc() then
  751.     sayerror TEX_NODOC_STRING
  752.     RETURN
  753. endif
  754.  
  755. -- memorize id of file being edited
  756.    getfileid working_fid
  757.  
  758. -- If a line mark exists, then ask whether only the marked region
  759. -- is to be processed;  indicate this by process_mark = 1.
  760.    process_mark = 0
  761.    if (marktype() = 'LINE') then
  762.       getmark a,b,c,d,marked_fid
  763.       process_mark = (marked_fid = working_fid) -- mark is in the current file
  764.    endif
  765.    if process_mark then
  766.       rc = WinMessageBox(TEX_MARK1_STRING,
  767.                       TEX_MARK2_STRING,
  768.                       MB_YESNOCANCEL+MB_NOICON+MB_DEFBUTTON1+MB_MOVEABLE)
  769.       if rc = MBID_NO then 
  770.          process_mark = 0 -- proceed as usual
  771.       elseif rc = MBID_CANCEL then
  772.          RETURN  -- cancel
  773.       endif
  774.    endif
  775.  
  776. -- If master file system is enabled, then check for master file
  777.  
  778.     tex_master= queryprofile( app_hini, TEX_APP, 'TEX_MASTERFILE')
  779.     if tex_master then  /* master file system enabled */
  780.         master = tex_master_name(TEX_TEX_TITLE)
  781.  
  782. -- Need to change to master file to get Format from first line
  783. -- And TeX in that directory
  784.  
  785.         if master = '-1' then   -- master file specified but not found on disk
  786.            RETURN
  787.         endif
  788.  
  789.         if master = '' then  -- no master file specified
  790.             sayerror .filename||TEX_M_ASSUME_STRING
  791.             call tex_parse_filename(.filename,dr,dir,stem,ext)
  792.             call tex_check_for_save()
  793.         else   -- a master file is being used
  794.             sayerror TEX_M_NAME_STRING||master
  795.             call tex_parse_filename(master,dr,dir,stem,ext)
  796.             if tex_file_in_ring(master) then
  797.                 getfileid master_fid,master
  798.                 activatefile master_fid
  799.                 call tex_check_for_save()
  800.             else
  801.                 'edit /d' master
  802.                 getfileid master_fid
  803.             endif
  804.         endif
  805.  
  806. -- Here we look for file dependencies in the file to be TeX'd
  807. -- and if dependent files are loaded in the editor
  808. -- they are checked for modification as well.
  809. -- Notes:
  810. --    * we search each line of the file so this can be a real
  811. --      performance bottleneck with large files
  812. --    * nested dependencies more than one level deep are ignored
  813. --
  814. --  We recognize 3 methods to specify an included file:
  815. --  LaTeX: \include{file} or \input{file}
  816. --  TeX:   \input file
  817.  
  818.         getfileid source_fid
  819.         for counter = 1 to .last
  820.             getline line, counter
  821.             if pos('%', strip(line)) <> 1 then  -- line doesn't start with %
  822.                 parse value line with '\include{' dep_fname '}' .
  823.                 if dep_fname = '' then
  824.                    parse value line with '\input{' dep_fname '}' .
  825.                    if dep_fname = '' then
  826.                       parse value line with '\input ' dep_fname .
  827.                    endif
  828.                 endif
  829.             else
  830.                dep_fname = ''
  831.             endif
  832.  
  833.             if dep_fname <> '' then
  834. -- Translate from unix-style to OS/2-style and add '.tex' extension if missing
  835.                dep_fname = translate(strip(dep_fname),'\','/')
  836.                n = lastpos('\',dep_fname)
  837.                tmp = substr(dep_fname,n+1)
  838.                if lastpos('.', tmp) <> length(tmp) then
  839.                   parse value tmp with  tmpStem '.' tmpExt
  840.                   if tmpExt = ''  then
  841.                       dep_fname = dep_fname||'.tex'
  842.                   endif
  843.                else
  844.                   -- the given filename ends with '.', so
  845.                   -- we remove the '.' to get the real name
  846.                   dep_fname = substr(dep_fname, 1, length(dep_fname)-1)
  847.                endif
  848.                sayerror TEX_CHKDEP_STRING||dep_fname
  849.                if tex_file_in_ring(dep_fname) = 1 then
  850.                    getfileid dep_fid,dep_fname
  851.                    activatefile dep_fid
  852.                    call tex_check_for_save()
  853.                    activatefile source_fid   /* restore source file */
  854.                endif
  855.             endif
  856.         endfor
  857.     else /* master file system disabled */
  858.         call tex_parse_filename(.filename,dr,dir,stem,ext)
  859.         call tex_check_for_save()
  860.         master = ''
  861.     endif /* tex_master */
  862.  
  863. -- update and set format to use
  864.         format = tex_auto_format()
  865.  
  866. --  determine filename to be passed to TeX program
  867. ;    TeXfilename = translate(dr||dir||stem,'/','\')
  868.     if translate(ext) <> 'TEX' then -- add extension
  869.        TeXfilename = stem||'.'||ext
  870.     else
  871.        TeXfilename = stem
  872.     endif
  873.  
  874. -- get name of TeX program for the requested format
  875.    texprog = queryprofile(app_hini, TEX_APP, translate(format))
  876.    if texprog = '' then
  877.       texprog = format||'.CMD'
  878.    endif
  879.  
  880. -- Change working directory to directory of current file since that is
  881. -- where the .DVI and .LOG files (and any others) should go.
  882.    call tex_cd()
  883.  
  884. -- TeX marked region only?
  885.    if process_mark then
  886.       getfileid current_fid  -- memorize current file
  887.       'edit /n 'stem'.___'   -- create temporary file
  888.       -- first we locate the end of the preamble;
  889.       bye = ''
  890.       do counter = 1 to current_fid.last
  891.          getline line, counter, current_fid
  892.          insertline line
  893.          if pos('\begin{document}', line) then
  894.             bye = '\end{document}'
  895.             leave
  896.          endif
  897.          if pos('%**end of header', line) then
  898.             bye = '\bye'
  899.             leave
  900.          endif
  901.       enddo
  902.       if bye = '' then
  903.          .modify = 0; 
  904.          'quit'
  905.          activatefile current_fid
  906.          call WinMessageBox('TeX', TEX_MARK3_STRING,
  907.                             MB_OK+MB_WARNING+MB_MOVEABLE)
  908.          RETURN
  909.          -- we stay in the file the above warning refers to !
  910.       endif
  911.       -- now copy the marked lines from working_fid to temporary file
  912.       do counter = a to b
  913.          getline line, counter, marked_fid
  914.          insertline line
  915.       enddo
  916.       insertline bye
  917.       'file' -- save and quit temporary file
  918.       activatefile current_fid  -- return to main document
  919.       TeXfilename = stem'.___' 
  920.    endif /* process_mark */
  921.  
  922.    if ps=1 then
  923.       dvips = queryprofile(app_hini, TEX_APP, 'DVIPS_EXEC')
  924.       command = 'start /f /c "TeX/PS" TFETEXPS.CMD '||texprog||
  925.                 ' '||TeXfilename||' '||dvips||' '||stem||'.'||'dvi'
  926.       if translate(rightstr(texprog,4))<>'.EXE' then
  927.          command = command 'CALL'
  928.       endif
  929.    else
  930.       command = 'start /f /c "TeX" '||texprog||' '||TeXfilename
  931.    endif
  932.  
  933. -- launch the TeX command
  934.     if tex_debug=1 then sayerror 'TeX command: 'command; endif
  935.     command
  936.     if rc <> 0 then
  937.       sayerror command||TEX_CMDFAIL_STRING||rc
  938.       call tex_cmderror('TeX')
  939.     else
  940.       -- Memorize fully qualified name of current log file
  941.       tex_log_file_name = dr||dir||stem||'.log'
  942.       call setprofile(app_hini, TEX_APP, 'LOGFILE', tex_log_file_name)
  943.       -- Remove old LOG file from the ring after successful TeX compilation
  944.       if tex_file_in_ring(tex_log_file_name) = 1 then
  945.         getfileid log_fid,tex_log_file_name
  946.         activatefile log_fid
  947.         .modify = 0             -- set this in case user modified file
  948.         'quit'                  -- close the file
  949.       endif
  950.       -- Can't load new log file here unless we wait for TeX to finish
  951.       tex_log_file_line = 1
  952.       tex_log_file_curr = 1
  953.       -- need this in case the log file will be loaded manually
  954.     endif /* rc <> 0 */
  955.  
  956. -- Change back to file from which we called TeX if we changed it
  957.     getfileid current_fid
  958.     if current_fid <> working_fid then
  959.         activatefile working_fid
  960.     endif
  961. RETURN
  962.  
  963.  
  964. /********************/
  965. /*                  */
  966. /*   DVI preview    */
  967. /*                  */
  968. /********************/
  969.  
  970. defc tex_view_dvi
  971.     universal  app_hini
  972.  
  973.     command = queryprofile( app_hini, TEX_APP, 'VIEW_CMD')
  974.     call tex_run_cmd('.dvi', command, TEX_VIEW_TITLE, 'TEX_VIEW_DVI_OPT')
  975.  
  976.  
  977. /***************/
  978. /*             */
  979. /*   Print     */
  980. /*             */
  981. /***************/
  982.  
  983. defc tex_print
  984.     universal  app_hini
  985.     
  986.     command = queryprofile( app_hini, TEX_APP, 'PRINT_CMD')
  987.     call tex_run_cmd('.dvi', command, TEX_PRINT_TITLE, 'TEX_PRINT_OPT')
  988.  
  989.  
  990. /********************/
  991. /*                  */
  992. /*   PS preview     */
  993. /*                  */
  994. /********************/
  995.  
  996. defc tex_view_ps
  997.     universal  app_hini
  998.  
  999.     command = queryprofile( app_hini, TEX_APP, 'VIEWPS_CMD')
  1000.     call tex_run_cmd('.ps', command, TEX_VIEWPS_TITLE, 'TEX_VIEWPS_OPT')
  1001.  
  1002.  
  1003. /**************/
  1004. /*            */
  1005. /*   dvips    */
  1006. /*            */
  1007. /**************/
  1008.  
  1009. defc tex_dvips
  1010.     universal  app_hini
  1011.  
  1012.     dvips = queryprofile( app_hini, TEX_APP, 'DVIPS_EXEC')
  1013.     command  = 'start /n /f 'dvips' %**N -o ["'dvips' %**N -o "]'
  1014.     call tex_run_cmd('.dvi', command, TEX_DVIPS_TITLE, 'TEX_DVIPS_OPT')
  1015.  
  1016.  
  1017. /**********************/
  1018. /*                    */
  1019. /*   View log file    */
  1020. /*                    */
  1021. /**********************/
  1022.  
  1023. defc tex_view_log
  1024.     universal  tex_log_file_curr,
  1025.                tex_log_file_name,
  1026.                tex_error_fname,
  1027.                app_hini,
  1028.                tex_debug
  1029.  
  1030. -- lockout if there is no "current" log file yet
  1031. if not tex_current_log() then
  1032.    sayerror TEX_NOCURRLOG_STRING
  1033.    RETURN
  1034. endif
  1035.  
  1036. call tex_parse_filename(tex_log_file_name,dr,dir,stem,ext)
  1037.  
  1038. -- if there are still errors to be processed, 
  1039. -- AND the log file is still in the ring:
  1040. if tex_more_errors() and tex_file_in_ring(tex_log_file_name) then
  1041.     getfileid log_fid,tex_log_file_name
  1042.     getfileid current_fid
  1043.     activatefile log_fid
  1044.     -- if we are alreay in the log file, then start again at 1st error
  1045.     if current_fid = log_fid then
  1046.        call tex_parse_init()
  1047.     endif
  1048.     -- go to current error, if possible
  1049.     if tex_log_file_curr <= .last then
  1050.        .line = tex_log_file_curr
  1051.     endif
  1052. -- No (more) errors or log file not in the ring?
  1053. -- Then get rid of old copy in ring if it exists; edit new one.
  1054. -- (Is this really necessary?)
  1055. else
  1056.    if tex_file_in_ring(tex_log_file_name) then
  1057.        getfileid log_fid,tex_log_file_name
  1058.        activatefile log_fid
  1059.        .modify = 0             -- set this in case user modified file
  1060.        'quit'                  -- close the file
  1061.    else
  1062.        tex_log_file_curr = 3 -- forget location of last error
  1063.    endif
  1064.    if not exist(tex_log_file_name) then
  1065.      call WinMessageBox(TEX_VIEWLOG_TITLE, TEX_L_LOG_STRING||
  1066.                         tex_log_file_name||TEX_NOTFOUND_STRING,
  1067.                         MB_OK+MB_WARNING+MB_MOVEABLE)
  1068.      -- clear the current log file name
  1069.      tex_log_file_name = ''
  1070.      call setprofile(app_hini, TEX_APP, 'LOGFILE', '')
  1071.      RETURN
  1072.    endif
  1073.    'edit /d /r' tex_log_file_name
  1074.     -- show location of last error
  1075.     if tex_log_file_curr <= .last then
  1076.        .line = tex_log_file_curr
  1077.     endif
  1078. -- initialize the parsing routines
  1079.    tex_error_fname = dr||dir||stem||'.tex' -- ?
  1080.    call tex_parse_init()
  1081. endif
  1082.  
  1083.  
  1084.  
  1085. /*************************/
  1086. /*                       */
  1087. /*   The user commands   */
  1088. /*                       */
  1089. /*************************/
  1090.  
  1091. defc texuser1exec
  1092.    universal app_hini
  1093.  
  1094.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER1_MENU_TEXT')
  1095.    UserMenuTexT = translate(UserMenuText, '', '~')
  1096.    UserExt = queryprofile( app_hini, TEX_APP, 'USER1_EXT')
  1097.    command = queryprofile( app_hini, TEX_APP, 'USER1_CMD')
  1098.    key = 'USER1_OPT'
  1099.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1100.  
  1101. defc texuser2exec
  1102.    universal app_hini
  1103.  
  1104.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER2_MENU_TEXT')
  1105.    UserMenuTexT = translate(UserMenuText, '', '~')
  1106.    UserExt = queryprofile( app_hini, TEX_APP, 'USER2_EXT')
  1107.    command = queryprofile( app_hini, TEX_APP, 'USER2_CMD')
  1108.    key = 'USER2_OPT'
  1109.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1110.  
  1111. defc texuser3exec
  1112.    universal app_hini
  1113.  
  1114.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER3_MENU_TEXT')
  1115.    UserMenuTexT = translate(UserMenuText, '', '~')
  1116.    UserExt = queryprofile( app_hini, TEX_APP, 'USER3_EXT')
  1117.    command = queryprofile( app_hini, TEX_APP, 'USER3_CMD')
  1118.    key = 'USER3_OPT'
  1119.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1120.  
  1121. defc texuser4exec
  1122.    universal app_hini
  1123.  
  1124.    UserMenuText = queryprofile( app_hini, TEX_APP, 'USER4_MENU_TEXT')
  1125.    UserMenuTexT = translate(UserMenuText, '', '~')
  1126.    UserExt = queryprofile( app_hini, TEX_APP, 'USER4_EXT')
  1127.    command = queryprofile( app_hini, TEX_APP, 'USER4_CMD')
  1128.    key = 'USER4_OPT'
  1129.    call tex_run_cmd(UserExt, command, UserMenuText, key)
  1130.  
  1131.  
  1132. /***************************************/
  1133. /*                                     */
  1134. /*   Execute an external command       */
  1135. /*                                     */
  1136. /***************************************/
  1137.  
  1138. defproc tex_run_cmd(FileExt, cmd, title, optname) =
  1139.  
  1140. -- Arguments:
  1141. -- FileExt      check for the existence of this file type first
  1142. -- cmd          the command to be executed 
  1143. -- title        use this as the title for error messages
  1144. -- optname      save extra options under this key in the INI file
  1145.  
  1146. universal app_hini,
  1147.           tex_debug
  1148.  
  1149. if cmd = '' then
  1150.    sayerror TEX_NOCONFIG_STRING
  1151.    RETURN
  1152. endif
  1153.  
  1154. -- If master file system is enabled, then check for master file
  1155. tex_master= queryprofile( app_hini, TEX_APP, 'TEX_MASTERFILE')
  1156. if tex_master  then
  1157.     master = tex_master_name(title)
  1158.     if master = '-1' then
  1159.        RETURN
  1160.     endif
  1161.     if master = '' then
  1162.         sayerror .filename||TEX_M_ASSUME_STRING
  1163.         call tex_parse_filename(.filename,dr,dir,stem,ext)
  1164.     else
  1165.         sayerror TEX_M_NAME_STRING||master
  1166.         call tex_parse_filename(master,dr,dir,stem,ext)
  1167.     endif
  1168. else
  1169.    call tex_parse_filename(.filename,dr,dir,stem,ext)
  1170. endif /* masterfile support */
  1171.  
  1172. -- lockout if file does not exist
  1173. if FileExt <> '' then
  1174.    if not exist(dr||dir||stem||FileExt) then
  1175.       sayerror FileExt||TEX_NOEX2_STRING
  1176.       RETURN
  1177.    endif
  1178. endif
  1179.  
  1180. -- Substitute the filename in the command string
  1181. command = tex_makecmd(cmd, stem, ext)
  1182.  
  1183. -- Evaluate options to be entered interactively
  1184. if pos('[',command) and optname <> '' then
  1185.     parse value command with lcommand '[' prompttext ']' rcommand
  1186.     curopts = queryprofile( app_hini, TEX_APP, optname)
  1187.     sbuf = entrybox(title, 
  1188.                     TEX_XOPT_BUTTONS,
  1189.                     curopts,60,62,
  1190.                     atoi(1) ||            -- default button # 
  1191.                     atoi(0) ||            -- help panel ID (0 for no help)
  1192.                     gethwnd(APP_HANDLE) ||
  1193.                     TEX_ADDOPT_STRING||prompttext||\0) 
  1194.                                           -- prompt
  1195.     button = asc(leftstr(sbuf,1))
  1196.     if button=3 or button=0 then RETURN; endif -- Cancel or closed otherwise
  1197.     if button=2 then                           -- Use std. options
  1198.        options = ''
  1199.     else                                       -- Use extra options
  1200.        EOS = pos(\0,sbuf,2)    -- CHR(0) signifies End Of String
  1201.        options = substr(sbuf,2,EOS-2)
  1202.        call setprofile( app_hini, TEX_APP, optname, options)
  1203.     endif
  1204.     command = lcommand||options||rcommand
  1205. endif
  1206.  
  1207. -- tell the user that the command is going to be launched:
  1208. sayerror title
  1209.  
  1210. --  Change working directory to directory of current/master file since that is
  1211. --  where the .DVI and .LOG files (and any others) should go.
  1212.  
  1213. savedir = directory()    -- save directory **
  1214. tstr = dr || leftstr(dir,length(dir)-1)
  1215. if not (savedir = tstr) then
  1216.     if tex_debug then sayerror 'Changing to directory 'tstr; endif
  1217.     call directory(tstr)     -- change directory **
  1218. endif
  1219.  
  1220. -- launch the command
  1221. if tex_debug=1 then sayerror 'Run command: 'command; endif
  1222. command
  1223. if rc <> 0 then
  1224.   sayerror command||TEX_CMDFAIL_STRING||rc
  1225.   call tex_cmderror(title)
  1226. endif
  1227.  
  1228. -- change back to directory from where we called the command
  1229. ;if not (savedir = tstr) then
  1230. ;   if tex_debug then sayerror 'Back to directory 'savedir; endif
  1231. ;   call directory(savedir)  -- restore directory **
  1232. ;endif
  1233.  
  1234.  
  1235.  
  1236. /******************************************************/
  1237. /*                                                    */
  1238. /*   Read LOG file and find errors in source code     */
  1239. /*                                                    */
  1240. /******************************************************/
  1241.  
  1242. defc tex_locate_error
  1243.    universal tex_log_file_name
  1244.  
  1245. -- lockout if there is no "current" log file yet
  1246. if not tex_current_log() then
  1247.    sayerror TEX_NOCURRLOG_STRING
  1248.    RETURN
  1249. endif
  1250.  
  1251. if tex_more_errors() then  -- more errors to be shown?
  1252.     call tex_find_errors()
  1253. else
  1254.     sayerror TEX_NOERRORS_STRING
  1255. endif
  1256.  
  1257.  
  1258.  
  1259. /***************************/
  1260. /*                         */
  1261. /*   Product information   */
  1262. /*                         */
  1263. /***************************/
  1264. defc tex_ver
  1265.    call WinMessageBox(TEX_ABOUT_TITLE,
  1266.                       'TeX Front End'||TEXFE_VERSION_STRING||TEXFE_VERSION\13||
  1267.                       TEXFE_COPYRIGHT_STRING\13\13||
  1268.                       TEXFE_THANKS_STRING,
  1269.                       MB_OK+MB_INFORMATION+MB_DEFBUTTON1+MB_MOVEABLE)
  1270.  
  1271. /*
  1272. ┌────────────────────────────────────────────────────────────────────────────┐
  1273. │  Procedure definitions                                                     │
  1274. └────────────────────────────────────────────────────────────────────────────┘
  1275. */
  1276. -----------------------------------------------------------------------------
  1277. -- Determine format to use with this file from first line of the file.
  1278. -- Same specification as Eberhard Mattes' TEXIT.CMD distributed with emTeX.
  1279. -- The default format is DEFAULT_FORMAT.
  1280.  
  1281. defproc tex_auto_format =
  1282.     universal app_hini
  1283.  
  1284.     format = ''
  1285.     getline line, 1
  1286.     line = translate(line)
  1287.     parse value line with '%'  'FORMAT' ':' format .
  1288.     if format = '' then
  1289.         parse value line with '%'  'FORMAT' format .
  1290.     endif
  1291.  
  1292.     if format = '' then
  1293.        format = queryprofile (app_hini, TEX_APP, 'DEFAULT_FORMAT')
  1294.        sayerror TEX_NO_FORMAT_STRING||format||TEX_USE_FORMAT_STRING
  1295.     else
  1296.        sayerror TEX_FORMAT_STRING||format||TEX_USE_FORMAT_STRING
  1297.     endif
  1298.     return format
  1299.  
  1300.  
  1301. -----------------------------------------------------------------------------
  1302. compile if TEXFEPRO 
  1303. -- Called from mymniuni.e to determine if file of given type exists for the 
  1304. -- associated master file, or for current file.
  1305. -- Returns:  1 if file does not exist or if the master file does not exist
  1306. --           0 if the file exists 
  1307.  
  1308. defproc tex_check_exist(FileExt) =
  1309.     universal  app_hini
  1310.  
  1311. -- If master file system is enabled, then check for master file
  1312.     if queryprofile( app_hini, TEX_APP, 'TEX_MASTERFILE') then 
  1313.         master = tex_master_name()
  1314.         if master = '' then
  1315.             fname = .filename
  1316.         else
  1317.             fname = master
  1318.         endif
  1319.     else
  1320.         fname = .filename
  1321.     endif -- master file support
  1322.     if fname = '-1' then
  1323.        ret = 1
  1324.     else
  1325.        if FileExt = '' then
  1326.           ret= 0
  1327.        else
  1328.           call tex_parse_filename(fname,dr,dir,stem,ext)
  1329.           ret = not exist(dr||dir||stem||FileExt)
  1330.        endif
  1331.     endif
  1332. return ret
  1333. compile endif /* TEXFEPRO */
  1334.  
  1335. -----------------------------------------------------------------------------
  1336. compile if TEXFEPRO
  1337. -- get the value of TEX_USER?_EXT
  1338.  
  1339. defproc get_tex_user_ext =
  1340.     universal  app_hini
  1341.  
  1342.     if arg(1) = 1 then
  1343.         return  queryprofile(app_hini, TEX_APP, 'USER1_EXT')
  1344.     elseif arg(1) = 2 then
  1345.         return  queryprofile(app_hini, TEX_APP, 'USER2_EXT')
  1346.     elseif arg(1) = 3 then
  1347.         return  queryprofile(app_hini, TEX_APP, 'USER3_EXT')
  1348.     elseif arg(1) = 4 then
  1349.         return  queryprofile(app_hini, TEX_APP, 'USER4_EXT')
  1350.     else
  1351.          return ''
  1352.     endif
  1353. compile endif /* TEXFEPRO */
  1354.  
  1355. -----------------------------------------------------------------------------
  1356. compile if TEXFEPRO
  1357. -- determine if TEX_USER?_MENU_TEXT is defined
  1358.  
  1359. defproc tex_check_user_exec =
  1360.     universal app_hini
  1361.  
  1362.     if arg(1) = 1 then
  1363.         return  queryprofile(app_hini, TEX_APP, 'USER1_MENU_TEXT') <> ''
  1364.     elseif arg(1) = 2 then
  1365.         return  queryprofile(app_hini, TEX_APP, 'USER2_MENU_TEXT') <> ''
  1366.     elseif arg(1) = 3 then
  1367.         return  queryprofile(app_hini, TEX_APP, 'USER3_MENU_TEXT') <> ''
  1368.     elseif arg(1) = 4 then
  1369.         return  queryprofile(app_hini, TEX_APP, 'USER4_MENU_TEXT') <> ''
  1370.     else
  1371.          return 0
  1372.     endif
  1373. compile endif /* TEXFEPRO */
  1374.  
  1375. -----------------------------------------------------------------------------
  1376. --  Check to see if current file has been modified.  If it has, save it.
  1377.  
  1378. defproc tex_check_for_save =
  1379.  
  1380.     if .modify then
  1381.        'Save'
  1382.     endif
  1383.  
  1384. -----------------------------------------------------------------------------
  1385. /*
  1386. Extract master file name from first line of file
  1387.  
  1388. Returns: a) '' if master file is not specified;
  1389.          b) master file name with path added on if file exists;
  1390.          c) '-1', if master file is specified but doesn't exist.
  1391.  
  1392. If arg(1) <> '' AND the master file is specified, but doesn't
  1393. exist, a warning message is displayed, using arg(1) as the title.
  1394. */
  1395.  
  1396. defproc tex_master_name
  1397.     universal  app_hini
  1398.  
  1399.     master = ''
  1400.     getline line, 1
  1401.     parse value line with '%' . 'master' ':' master .
  1402.     if master = '' then
  1403.         parse value line with '%' . 'master' master .
  1404.         if master = '' then
  1405.             parse value line with '%' . 'Master'  ':' master .
  1406.             if master = '' then
  1407.                 parse value line with '%' . 'Master'  master .
  1408.             endif
  1409.         endif
  1410.     endif
  1411.  
  1412.     if master <> '' then
  1413.         master = translate(master,'\','/') -- convert to DOS format
  1414.         if lastpos('\', master) >= lastpos('.',master) then
  1415.            -- there is no '.' in the name
  1416.            master = master||'.tex'
  1417.         endif
  1418. --  *** bug: filename. -> filename..tex
  1419.  
  1420. --  Now, make the master filename fully qualified.  We assume master is
  1421. --  in current directory unless specified name is fully qualified.
  1422. --      If only a stem.ext add current drive and dir
  1423.         tex_parse_filename(.filename,dr,dir,stem,ext)
  1424.         if lastpos('\',master) = 0 then
  1425.             master = dr||dir||master
  1426.         else
  1427. --          if no drive letter add current drive
  1428.             if leftstr(master,1) = '\' then
  1429.                 master = dr||master
  1430.             endif
  1431.         endif
  1432. -- Does the master file exist?
  1433.         if not exist(master) then
  1434.            if arg(1) <> '' then
  1435.               call WinMessageBox(arg(1), TEX_M_MASTER_STRING||master||
  1436.                                          TEX_NOTFOUND_STRING,
  1437.                                  MB_OK+MB_WARNING+MB_MOVEABLE)
  1438.            endif
  1439.            master = '-1'
  1440.         endif
  1441.     endif
  1442.  
  1443.     return master
  1444.  
  1445. -----------------------------------------------------------------------------
  1446. -- Parse a file name:  d:\dir1\dir2\file.ext
  1447. --                     \dir1\dir2\file.ext
  1448. --                     file.ext
  1449. --                     .ext
  1450. --                     \dir1\.ext
  1451. --                     ...etc,  but NOT d:test2.ext
  1452. -- returns  dr      d:
  1453. --          dir     \dir1\dir2\    if any of these does not exist,
  1454. --          stem    file           a null is returned.
  1455. --          ext     ext
  1456.  
  1457. defproc tex_parse_filename(fname, var dr, var dir, var stem, var ext)
  1458.  
  1459. -- Translate from Unix-style to OS/2-style names
  1460.     fname = translate(fname,'\','/')
  1461.     n = lastpos('\',fname)
  1462.     tmp = substr(fname,n+1)
  1463.     parse value tmp with  stem '.' ext
  1464.     tmp = substr(fname,1,n)
  1465.     n = pos(':',tmp)
  1466.     dr = substr(tmp,1,n)
  1467.     dir = substr(tmp,n+1)
  1468.  
  1469.  
  1470.  
  1471. -----------------------------------------------------------------------------
  1472. -- Determine if a file already is in ring.
  1473.  
  1474. defproc tex_file_in_ring(fname)
  1475.    universal tex_debug
  1476.    
  1477.    getfileid id, fname
  1478.    return (id <> '')
  1479. /*
  1480.     tex_parse_filename(fname,dr,dir,stem,ext)
  1481.     if ext = '' then
  1482.        return pfile_exists(stem)
  1483.     else
  1484.        return pfile_exists(stem||'.'||ext)
  1485.     endif
  1486. */
  1487.  
  1488. -----------------------------------------------------------------------------
  1489. -- Called to determine whether or not to disable
  1490. -- the error browsing facility.
  1491. -- Returns 1 if there can be more errors, 
  1492. --         0 if not or no "current" log file exists
  1493.  
  1494. defproc tex_more_errors
  1495.    universal  tex_log_file_line,
  1496.               tex_log_file_last,
  1497.               tex_log_file_name
  1498.  
  1499.    if tex_log_file_name <> '' then    -- a current log file exists
  1500.      if tex_file_in_ring(tex_log_file_name) then   -- loaded?
  1501.         -- can there still be errors in it?
  1502.         res = ( tex_log_file_line < tex_log_file_last )
  1503.      else
  1504.         res = 1
  1505.      endif  -- file in ring
  1506.    else
  1507.       res = 0
  1508.    endif -- current log file exists
  1509. return res
  1510.  
  1511.  
  1512. -----------------------------------------------------------------------------
  1513. -- Determine whether there is a "current" log file.
  1514. -- Returns 1 if so.
  1515.  
  1516. defproc tex_current_log
  1517.    universal tex_log_file_name
  1518. return tex_log_file_name <> ''
  1519.  
  1520. -----------------------------------------------------------------------------
  1521. --  Read LOG file and find errors in source code
  1522.  
  1523. defproc tex_find_errors
  1524.     universal  tex_log_file_line,
  1525.                tex_log_file_curr,
  1526.                tex_log_file_last,
  1527.                tex_log_file_name,
  1528.                tex_error_fname,
  1529.                name_count,
  1530.                par_count,
  1531.                EPM_utility_array_ID,
  1532.                app_hini,
  1533.                tex_debug
  1534.  
  1535.     empty = ''
  1536.     getfileid tex_return_to_fid
  1537.  
  1538.     tex_parse_filename(tex_log_file_name,dr,dir,stem,ext)
  1539.  
  1540.     if tex_file_in_ring(tex_log_file_name) = 1 then
  1541.         getfileid log_fid,tex_log_file_name
  1542.         activatefile log_fid
  1543.     else
  1544.         if not exist(tex_log_file_name) then
  1545.            call WinMessageBox(TEX_LOCERR_TITLE, TEX_L_LOG_STRING||
  1546.                         tex_log_file_name||TEX_NOTFOUND_STRING,
  1547.                         MB_OK+MB_WARNING+MB_MOVEABLE)
  1548.            -- clear the current log file name
  1549.            tex_log_file_name = ''
  1550.            call setprofile(app_hini, TEX_APP, 'LOGFILE', '')
  1551.            RETURN
  1552.         endif
  1553.         'edit /d /r' tex_log_file_name
  1554.         getfileid log_fid
  1555.         tex_error_fname = dr||dir||stem||'.tex'  -- ?
  1556.         call tex_parse_init()
  1557.     endif
  1558.     call tex_cd()
  1559.  
  1560.     do while (tex_log_file_line < tex_log_file_last)
  1561.  
  1562.       getline line, tex_log_file_line
  1563.  
  1564.       if leftstr(line,1) = '!' then
  1565.           -- memorize line number of the current error
  1566.           tex_log_file_curr = tex_log_file_line
  1567.           parse value line with '!'error_msg
  1568.           -- search for line containing line number of error;
  1569.           -- if none is present, we must not run over the end of the file;
  1570.           -- better: realise this situation before -- how?
  1571.           do forever
  1572.               tex_log_file_line = tex_log_file_line + 1
  1573.               if tex_log_file_line > tex_log_file_last then leave endif
  1574.               getline line, tex_log_file_line
  1575.               if (leftstr(line,1) = 'l') or (leftstr(line,1) = '!')  then
  1576.                  leave
  1577.               endif
  1578.           enddo
  1579. -- The message:
  1580.           parse value line with 'l.' linenum contexttext
  1581.           if isnum(linenum) then 
  1582.               sayerror error_msg': 'contexttext
  1583.           else 
  1584.               sayerror TEX_NOLOC_STRING||tex_error_fname
  1585.           endif
  1586. -- Where is the error?
  1587.           if  not isnum(linenum) then
  1588.               -- position of error cannot be determined,
  1589.               -- so we stay in the log file:
  1590.               .line = tex_log_file_curr
  1591.           elseif pos('.___',tex_error_fname) then 
  1592.               -- A marked region has been processed; 
  1593.               -- don't edit the temporary file!
  1594.               -- Stay on the error message in the .log file:
  1595.               .line = tex_log_file_line
  1596.           elseif tex_file_in_ring(tex_error_fname) = 1 then
  1597.               -- The file is already in the editor.
  1598.               getfileid tex_error_fid,tex_error_fname
  1599.               activatefile tex_error_fid
  1600.               if tex_debug > 1 then sayerror 'next file: 'tex_error_fname endif
  1601.           else
  1602.               -- This file should exist since we 'just' compiled it.
  1603.               'edit /d' tex_error_fname
  1604.               if tex_debug > 1 then sayerror 'next file: 'tex_error_fname endif
  1605.           endif
  1606. -- How to proceed?
  1607.           if not isnum(linenum) then
  1608.               -- Procced with line after the error message:
  1609.               tex_log_file_line = tex_log_file_curr + 1
  1610.               -- *** possible bug, perhaps ... +2 ?
  1611.           elseif pos('.___',tex_error_fname) then 
  1612.               -- proceed with next line
  1613.               tex_log_file_line = tex_log_file_line + 1
  1614.           elseif linenum > .last then
  1615.              -- Don't run over the last line, show log file instead
  1616.              activatefile log_fid
  1617.              .line = tex_log_file_curr
  1618.              sayerror TEX_ERRERR_STRING||tex_error_fname
  1619.           else
  1620.              -- OK, proceed and show the error in the source code:
  1621.              getline errorline, linenum
  1622.              tex_log_file_line = tex_log_file_line + 1
  1623.              if length(contexttext) > 4 then
  1624.                  chopum = 4
  1625.              else
  1626.                  chopum = 1
  1627.              endif
  1628.              col1 = pos( substr(contexttext,chopum), errorline)
  1629.              col2 = col1 + length(contexttext) - chopum + 1
  1630.              .line = linenum
  1631.              .col  = col2
  1632.              'PostMe tex_circleit '||col1
  1633.           endif
  1634.           RETURN
  1635.       else    /* This is not a line starting with '!' */
  1636.  
  1637.           do while not ( line = '')
  1638.  
  1639.               if tex_debug > 2 then sayerror 'line='line; endif
  1640.               left_par =  pos('(',line)
  1641.               right_par = pos(')',line)
  1642.               if tex_debug > 2 then sayerror 'left_par='left_par'  right_par='right_par; endif
  1643. -- EPM5 can only handle lines of 255 chars anyway, so make them 256 if the
  1644. -- are 0 to simplify things a bit.
  1645.               if left_par = 0 then left_par = 256 endif
  1646.               if right_par = 0 then right_par = 256 endif
  1647.  
  1648.               if (right_par < left_par) then
  1649.                   par_count = par_count - 1
  1650.                   if tex_debug > 2 then sayerror 'par_count (decreased) ='par_count; endif
  1651.                   if par_count = 0 then
  1652.                       if tex_debug > 2 then sayerror 'Erasing name 'name_count' from array'; endif
  1653.                       do_array 2, EPM_utility_array_ID, 'tex_fname.'name_count, empty
  1654.                       do_array 2, EPM_utility_array_ID, 'tex_par.'name_count, empty
  1655.                       name_count = name_count - 1
  1656. -- name_count will be 0 when we are finished
  1657.                       if name_count > 0 then
  1658.                           do_array 3, EPM_utility_array_ID, 'tex_fname.'name_count, tex_error_fname
  1659.                           do_array 3, EPM_utility_array_ID, 'tex_par.'name_count, par_count
  1660.                           if tex_debug > 2 then sayerror 'Got 'tex_error_fname'('name_count') and par_count='par_count; endif
  1661.                       else
  1662.                           if tex_debug > 2 then sayerror 'name_count = 0'; endif
  1663.                       endif
  1664.                   endif
  1665.                   if tex_debug > 2 then sayerror 'line=   'line; endif
  1666.                   line = substr(line,right_par+1)
  1667.                   if tex_debug > 2 then sayerror 'newline='line; endif
  1668.               else
  1669.                   if not (left_par = 256) then
  1670.                       line = substr(line,left_par+1)
  1671.                       if tex_debug > 1  then
  1672.                          sayerror 'searching for filename in:'line
  1673.                       endif
  1674.                       if tex_extract_fname(line,dr,dir) = 0 then
  1675.                           par_count = par_count + 1
  1676.                           if tex_debug > 2 then sayerror 'par_count (increased) ='par_count; endif
  1677.                       else
  1678.                           par_count = 1
  1679.                           if tex_debug > 2 then sayerror 'par_count set to 1'; endif
  1680.                       endif
  1681.                   else
  1682.                       line = ''
  1683.                   endif
  1684.               endif
  1685.           enddo  /*  while not (line='')  */
  1686.           tex_log_file_line = tex_log_file_line + 1
  1687.       endif /* line starts with ! */
  1688.  
  1689.     enddo     /*  while (tex_log_file_line < tex_log_file_last)  */
  1690.  
  1691.     if not (tex_log_file_line < tex_log_file_last) then
  1692.         activatefile tex_return_to_fid
  1693.         sayerror TEX_NOERRORS_STRING
  1694.     endif
  1695.  
  1696. -----------------------------------------------------------------------------
  1697. -- executed (if requested) after the above routine returns to the user
  1698. defc tex_circleit
  1699.    circleit 3, .line, arg(1), .col, LIGHT_RED
  1700.    -- thick light-red circle; well visible,
  1701.    -- except on red background, which is unlikely
  1702. return
  1703.  
  1704. -----------------------------------------------------------------------------
  1705. -- we are in the log file and initialize the error parsing facility
  1706. defproc tex_parse_init
  1707.    universal tex_log_file_line,
  1708.              tex_log_file_curr,
  1709.              tex_log_file_last,
  1710.              name_count,
  1711.              par_count
  1712.  
  1713.    tex_log_file_line = 3
  1714.    tex_log_file_curr = 3
  1715.    tex_log_file_last = .last
  1716.    name_count = 0
  1717.    par_count = 1
  1718. return
  1719.  
  1720. -----------------------------------------------------------------------------
  1721. -- This routine is called by tex_find_errors .
  1722. -- Its 1st argument is a part of a line from the log file, starting after a '('.
  1723. -- It determines whether or not the text following the '(' is a filename.
  1724. -- If it is, tex_error_fname is changed to that name, and the routine
  1725. -- returns 1.  Otherwise, a 0 is returned.
  1726. --
  1727. -- The logic goes like this:
  1728. --  1) search for '(', ')' and ' '; throw away what follows
  1729. --  2) make sure there is a '.' in the remaining string
  1730. --  3) parse it into pieces before '.' and after '.'
  1731. --  4) make sure that the first part is not empty 
  1732. --  5) the name is fully qualified and placed in
  1733. --     tex_error_fname, and is also put into an array.
  1734. --  6) take name out of "line"
  1735. --  7) return
  1736.  
  1737. defproc tex_extract_fname(var line, dr, dir)
  1738.     universal  tex_error_fname,
  1739.                par_count,
  1740.                name_count,
  1741.                EPM_utility_array_ID,
  1742.                tex_debug 
  1743.  
  1744.     flag = 0
  1745.     tmp = line
  1746.     -- truncate before a possible space, '(' or ')':
  1747.     ppos = pos(' ', tmp)
  1748.     if ppos > 0 then
  1749.        tmp = leftstr(tmp, (ppos-1))
  1750.     endif
  1751.     ppos = pos('(', tmp)
  1752.     if ppos > 0 then
  1753.        tmp = leftstr(tmp, (ppos-1))
  1754.     endif
  1755.     ppos = pos(')', tmp)
  1756.     if ppos > 0 then
  1757.        tmp = leftstr(tmp, (ppos-1))
  1758.     endif
  1759.     -- now make sure there is still a '.' in it:
  1760.     if  pos('.', tmp) then
  1761.         -- break it into pieces before and after the '.'
  1762.         parse value tmp with tmp1 '.' tmp2
  1763.         if tmp1 <> '' then -- yes, it was a filename
  1764.             if tmp2 = '' then -- take tmp1 only
  1765.                tmpname = tmp1
  1766.             else
  1767.                tmpname = tmp1||'.'||tmp2
  1768.             endif
  1769. --              Translate from Unix-style to OS/2-style file names
  1770.                 tex_error_fname = translate(tmpname,'\','/')
  1771. --  Now, name the name fully qualified
  1772. --              If only a stem.ext
  1773.                 if lastpos('\',tex_error_fname) = 0 then
  1774.                     tex_error_fname = dr||dir||tex_error_fname
  1775.                     if tex_debug > 2 then sayerror 'tex_error_fname (again1)='tex_error_fname; endif
  1776.                 else
  1777. --                  if no drive letter
  1778.                     if leftstr(tex_error_fname,1) = '\' then
  1779.                         tex_error_fname = dr||tex_error_fname
  1780.                         if tex_debug > 2 then sayerror 'tex_error_fname (again2)='tex_error_fname; endif
  1781.                     endif
  1782.                 endif
  1783.                 name_count = name_count + 1
  1784.                 if tex_debug > 2 then  sayerror 'Putting 'tex_error_fname' on stack with par_count='par_count' at position 'name_count; endif
  1785.                 do_array 2, EPM_utility_array_ID, 'tex_fname.'name_count, tex_error_fname
  1786.                 do_array 2, EPM_utility_array_ID, 'tex_par.'name_count, par_count
  1787.                 flag = 1
  1788. -- Take the filename out of line for next loop
  1789. ;                line = substr(line,pos(tmpname,line)+length(tmpname))
  1790.                 line = substr(line,pos(tmp,line)+length(tmp)) -- *** v1.1
  1791.         endif
  1792.     endif
  1793.  
  1794.     return flag
  1795.  
  1796. -----------------------------------------------------------------------------
  1797. /*
  1798. -- A procedure to expand environment variables in user defined constants
  1799. --
  1800. -- searches for $variable: in user defined constants and expands 'variable'
  1801. -- if found
  1802.  
  1803. defproc Expand_Env(Input)
  1804.  
  1805.    Parse Value Input with Lead_Var '$' Env_Var ':' Trail_Var
  1806.  
  1807.    if Env_Var <> '' & LastPos(':',Input) > Pos('$',Input) then
  1808.       Output = Lead_Var || Get_Env(Env_Var) || Trail_Var
  1809.    else
  1810.       Output = Input
  1811.    endif
  1812.  
  1813. return Output
  1814. */
  1815.  
  1816. -----------------------------------------------------------------------------
  1817. -- A procedure to check whether the current file is a TeX document
  1818.  
  1819. defproc tex_is_doc
  1820.    universal app_hini
  1821.  
  1822. types = queryprofile( app_hini, TEX_APP, 'DOCTYPES')
  1823. return wordpos(filetype(), types)
  1824.  
  1825.  
  1826. -----------------------------------------------------------------------------
  1827. -- A procedure to check whether the current file is a TeX style file
  1828.  
  1829. defproc tex_is_style
  1830.    universal app_hini
  1831.  
  1832. types = queryprofile( app_hini, TEX_APP, 'STYLETYPES')
  1833. return wordpos(filetype(), types)
  1834.  
  1835.  
  1836. -----------------------------------------------------------------------------
  1837. -- A procedure to check whether the current file is a TeX auxiliary file
  1838.  
  1839. defproc tex_is_aux
  1840.    universal app_hini
  1841.  
  1842. types = queryprofile( app_hini, TEX_APP, 'FILETYPES')
  1843. return wordpos(filetype(), types)
  1844.  
  1845.  
  1846. ----------------------------------------------------------------------------
  1847. -- A procedure to check whether the current file is a TeX file
  1848.  
  1849. defproc tex_is_file
  1850.    universal app_hini
  1851.  
  1852. auxtypes   = queryprofile( app_hini, TEX_APP, 'FILETYPES')
  1853. doctypes   = queryprofile( app_hini, TEX_APP, 'DOCTYPES')
  1854. styletypes = queryprofile( app_hini, TEX_APP, 'STYLETYPES')
  1855. return wordpos(filetype(), doctypes auxtypes styletypes)
  1856.  
  1857. -----------------------------------------------------------------------------
  1858. -- Substitute the arg specifieres %**N and %**F within a command string
  1859.  
  1860. defproc tex_makecmd(command, fname, ext)
  1861. -- we perform the following substitutions:
  1862. -- %**N   ->  filename without extension
  1863. -- %**F   ->  filename with extension
  1864.  
  1865.     do forever
  1866.        posi=pos('%**N', command)
  1867.        if posi then
  1868.           command=delstr(command, posi, 4)
  1869.           command = insertstr(fname, command, (posi-1))
  1870.        else
  1871.           leave
  1872.        endif
  1873.     enddo
  1874.     do forever
  1875.        posi=pos('%**F', command)
  1876.        if posi then
  1877.           command=delstr(command, posi, 4)
  1878.           command = insertstr(fname'.'ext, command, (posi-1))
  1879.        else
  1880.           leave
  1881.        endif
  1882.     enddo
  1883.     return command
  1884.  
  1885. -----------------------------------------------------------------------------
  1886. -- check a variable from the INI file, return its value as 'ON' or 'OFF'
  1887.  
  1888. defproc tex_querysetting(name)
  1889.    universal app_hini
  1890.    if queryprofile(app_hini, TEX_APP, name) then
  1891.       return(TEX_ON_STRING)
  1892.    else
  1893.       return(TEX_OFF_STRING)
  1894.    endif
  1895. return
  1896.  
  1897. -----------------------------------------------------------------------------
  1898. -- toggle a variable from the INI file
  1899.  
  1900. defproc tex_togglesetting(name)
  1901.    universal app_hini
  1902.    if queryprofile(app_hini, TEX_APP, name) then
  1903.       call setprofile(app_hini, TEX_APP, name, '')
  1904.    else
  1905.       call setprofile(app_hini, TEX_APP, name, '1')
  1906.    endif
  1907. return
  1908.  
  1909. -----------------------------------------------------------------------------
  1910. -- Switch to the directory of the current file
  1911.  
  1912. defproc tex_cd
  1913.    universal tex_debug
  1914.  
  1915.    dirpos=lastpos('\',.filename)
  1916.    if dirpos>1 then
  1917.       if  tex_debug then
  1918.          sayerror '.filename ='.filename', cd 'substr(.filename,1,dirpos-1)
  1919.       endif
  1920.       call directory(substr(.filename,1,dirpos-1))
  1921.    endif
  1922. return
  1923.  
  1924. -----------------------------------------------------------------------------
  1925. -- Pop up a warning about a command that crashed
  1926.  
  1927. defproc tex_cmderror(title)
  1928.    call WinMessageBox(title, TEX_CMDERR_STRING,
  1929.                       MB_OK+MB_ERROR+MB_MOVEABLE)
  1930. return
  1931.  
  1932.  
  1933. /************************************/
  1934. /*                                  */
  1935. /*   The OS/2 related procedures    */
  1936. /*                                  */
  1937. /************************************/
  1938.  
  1939. defc tex_osshell
  1940.  
  1941.    call tex_cd()
  1942.    title = 'Shell - 'directory()
  1943.    command = 'start "'title'" /F /K MODE CO80, 40'
  1944.    command
  1945.    if rc <> 0 then
  1946.      sayerror command||TEX_CMDFAIL_STRING||rc
  1947.      call tex_cmderror(TEX_OSSHELL_TITLE)
  1948.    endif
  1949. return
  1950.  
  1951.  
  1952. defc tex_fm -- 'fm' means 'file manager' :-)
  1953.  
  1954.    call tex_cd()
  1955.    command = 'start /F /C /MIN TFEFM.CMD'
  1956.    command
  1957.    if rc <> 0 then
  1958.      sayerror command||TEX_CMDFAIL_STRING||rc
  1959.      call tex_cmderror(TEX_FOLDER_TITLE)
  1960.    endif
  1961. return
  1962.  
  1963.  
  1964. /********************************************************/
  1965. /*                                                      */
  1966. /*   All the procedures to change/show the settings     */
  1967. /*                                                      */
  1968. /********************************************************/
  1969.  
  1970. defc tex_debuglevel
  1971.    universal tex_debug
  1972.    if arg(1) = '' then
  1973.       sayerror 'TeX_debuglevel: 'tex_debug
  1974.    else
  1975.       tex_debug = arg(1)
  1976.    endif
  1977.  
  1978.  
  1979. compile if TEXFEPRO and WANT_TEX_MENU
  1980.  
  1981. defproc check_tex_master --  check whether master file support is enabled
  1982.    universal app_hini
  1983.    if queryprofile(app_hini, TEX_APP, 'TEX_MASTERFILE') then
  1984.       return 1
  1985.    else
  1986.       return 0
  1987.    endif
  1988. return
  1989.  
  1990. defproc check_tex_menuon -- check whether menu should always be on
  1991.    universal app_hini
  1992.    if queryprofile(app_hini, TEX_APP, 'TEX_MENUON') then
  1993.       return 1
  1994.    else
  1995.       return 0
  1996.    endif
  1997. return
  1998.  
  1999. defc tex_master_file_support
  2000.    call tex_togglesetting('TEX_MASTERFILE')
  2001. return
  2002.  
  2003. defc tex_menu_always_on
  2004.    call tex_togglesetting('TEX_MENUON')
  2005. return
  2006.  
  2007. compile endif /* TEXFEPRO and WANT_TEX_MENU */
  2008.  
  2009.  
  2010. defproc tex_set_data(id) -- change user settings
  2011.    universal app_hini
  2012. compile if EXTENDED_LATEX_ASSIST
  2013.    universal TeX_Margin
  2014. compile endif
  2015.    
  2016.    if id='1' then -- document file types
  2017.  
  2018.       current_types = queryprofile(app_hini, TEX_APP, 'DOCTYPES')
  2019.       types = strip(entrybox(TEX_DOCTYPES_STRING, TEX_EC_BUTTONS,
  2020.                               current_types,60,40))
  2021.       if types <> '' then
  2022.          call setprofile(app_hini, TEX_APP, 'DOCTYPES', translate(types))
  2023.       endif
  2024.  
  2025.    elseif id='2' then -- style file types
  2026.  
  2027.       current_types = queryprofile(app_hini, TEX_APP, 'STYLETYPES')
  2028.       types = strip(entrybox(TEX_STYLETYPES_STRING, TEX_EC_BUTTONS,
  2029.                               current_types,60,40))
  2030.       if types <> '' then
  2031.          call setprofile(app_hini, TEX_APP, 'STYLETYPES', translate(types))
  2032.       endif
  2033.  
  2034.    elseif id='3' then -- auxiliary file types
  2035.  
  2036.       current_types = queryprofile(app_hini, TEX_APP, 'FILETYPES')
  2037.       types = strip(entrybox(TEX_FILETYPES_STRING, TEX_EC_BUTTONS,
  2038.                               current_types,60,40))
  2039.       if types <> '' then
  2040.          call setprofile(app_hini, TEX_APP, 'FILETYPES', translate(types))
  2041.       endif
  2042.  
  2043.    elseif id='4' then -- accelerator keys
  2044.  
  2045.       call tex_togglesetting('TEX_KEYS')
  2046.  
  2047.    elseif id='5' then -- highlighting
  2048.  
  2049.       call tex_togglesetting('TEX_SYNTAXHILITE')
  2050.  
  2051.    elseif id='6' then -- default format
  2052.  
  2053.       current_format = queryprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT')
  2054.       format = strip(entrybox(TEX_FORMAT_TITLE, TEX_EC_BUTTONS,
  2055.                                current_format,60,40))
  2056.       if format <> '' then
  2057.          call setprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT', format)
  2058.       endif
  2059.  
  2060.    elseif id='7' then -- master file support
  2061.  
  2062.       call tex_togglesetting('TEX_MASTERFILE')
  2063.       
  2064. compile if EXTENDED_LATEX_ASSIST
  2065.    elseif id='8' then -- TeX margin
  2066.  
  2067.       ma = strip(entrybox(TEX_MA_TITLE, TEX_EC_BUTTONS,
  2068.                             TeX_Margin,60,40))
  2069.       if (ma <> '') and isnum(ma) then
  2070.          call setprofile(app_hini, TEX_APP, 'MARGIN', ma)
  2071.          TeX_Margin = ma
  2072.          -- We do not only save the value in the INI file, 
  2073.          -- we also save it in a universal variable, because
  2074.          -- this value must be read each time the <space> or 
  2075.          -- <enter> key is pressed.
  2076.       endif
  2077. compile endif
  2078.  
  2079.    endif
  2080. return /* tex_set_data() */
  2081.  
  2082.  
  2083. defc texfe_settings_window
  2084. -- contributed by Wonkoo Kim (wkim+@pitt.edu), November 14, 1997;
  2085.  
  2086.      universal app_hini
  2087. compile if EXTENDED_LATEX_ASSIST
  2088.      universal TeX_Margin
  2089. compile endif
  2090.  
  2091.      if arg(1) = '' then
  2092.      id = 1
  2093.      else
  2094.      id = arg(1)
  2095.      endif
  2096.  
  2097.      menu_title = TEX_CONF_TITLE
  2098.      settings = ''
  2099.      no = 1
  2100.      settings = settings||\1no||' 'TEX_S1' = '||queryprofile(app_hini, TEX_APP, 'DOCTYPES')
  2101.      no = no + 1
  2102.      settings = settings||\1no||' 'TEX_S2' = '||queryprofile(app_hini, TEX_APP, 'STYLETYPES')
  2103.      no = no + 1
  2104.      settings = settings||\1no||' 'TEX_S3' = '||queryprofile(app_hini, TEX_APP, 'FILETYPES')
  2105.      no = no + 1
  2106.      settings = settings||\1no||' 'TEX_S4' = '||tex_querysetting('TEX_KEYS')
  2107.      no = no + 1
  2108.      settings = settings||\1no||' 'TEX_S5' = '||tex_querysetting('TEX_SYNTAXHILITE')
  2109.      no = no + 1 
  2110.      settings = settings||\1no||' 'TEX_S6' = '||queryprofile(app_hini, TEX_APP, 'DEFAULT_FORMAT')
  2111.      no = no + 1
  2112.      settings = settings||\1no||' 'TEX_S7' = '||tex_querysetting('TEX_MASTERFILE')
  2113. compile if EXTENDED_LATEX_ASSIST
  2114.      no = no + 1
  2115.      settings = settings||\1no||' 'TEX_S8' = '||TeX_Margin
  2116. compile endif
  2117. -- 
  2118.      y = min(25,.windowheight+2)
  2119.      x = min(15,.windowwidth*.3)
  2120.      h = min(8,.windowheight*.75)
  2121.      w = min(70,.windowwidth)
  2122.      sbuf = listbox(menu_title, settings,
  2123.         TEX_MO_BUTTONS,
  2124.      y,x,h,w, -- row,col,height,width
  2125.      gethwnd(APP_HANDLE) ||
  2126.      atoi(id) ||    -- initial item # selected (start from 1)
  2127.      atoi(1) ||    -- default button # selected (start from 1)
  2128.      atoi(0) ||    -- help panel ID (0 for no help)
  2129.      ''\0);          -- prompt
  2130.      button = asc(leftstr(sbuf,1))
  2131.      if button = 1 then
  2132.      EOS = pos(\0, sbuf, 2)          -- CHR(0) signifies End Of String
  2133.      select = substr(sbuf, 2, EOS-2)
  2134.      else
  2135.      return
  2136.      endif
  2137.      -- 'TeX_'||word(select,2)
  2138.      call tex_set_data( word(select,1) )
  2139.      'texfe_settings_window' word(select,1)
  2140.  
  2141. /* Finis */
  2142.  
  2143.