home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / CMDAPP.H < prev    next >
C/C++ Source or Header  |  1996-01-05  |  4KB  |  112 lines

  1. /****************************************************************************
  2.     $Id: cmdapp.h 501.0 1995/03/07 12:26:40 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Declarations for command line application classes and functions.
  10.  
  11.     $Log: cmdapp.h $
  12.     Revision 501.0  1995/03/07 12:26:40  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.8  1995/01/31 16:29:16  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.7  1995/01/18  18:53:21  ron
  18.     Added support for Windows NT
  19.  
  20.     Revision 1.6  1994/10/05  18:19:11  ron
  21.     Renamed TLx...() functions to tl...()
  22.  
  23.     Revision 1.5  1994/09/28  14:25:16  ron
  24.     Removed Macintosh-style #include references
  25.  
  26.     Revision 1.4  1994/09/27  20:24:56  ron
  27.     Changed path separator from / to \
  28.  
  29.     Revision 1.3  1994/09/26  15:15:10  ron
  30.     Changed OS_DOS check to OS_DOSXXX
  31.  
  32.     Revision 1.2  1994/09/06  14:00:06  ron
  33.     Small change from OS_WIN to OS_WIN16 support
  34.  
  35.     Revision 1.1  1994/08/16  18:06:44  ron
  36.     Initial revision
  37.  
  38. ****************************************************************************/
  39.  
  40. #ifndef _TLX_CMDAPP_H
  41. #define _TLX_CMDAPP_H
  42.  
  43. #ifndef _TLX_TLX_H
  44. #include <tlx\501\tlx.h>
  45. #endif
  46.  
  47. /*---------------------------------------------------------------------------
  48.     Declarations for general application attributes, such as command-line
  49.     options.
  50. ---------------------------------------------------------------------------*/
  51.  
  52. #if OS_DOSXXX || OS_OS2 || OS_WINXXX
  53.     const char        gOptionChar = '/';
  54. #elif OS_MAC || OS_UNIX
  55.     const char        gOptionChar = '-';
  56. #else
  57.     #error Unsupported operating system
  58. #endif
  59.  
  60. inline bool  tlIsOption(const char *arg) { return arg[0] == gOptionChar; }
  61.  
  62. /*---------------------------------------------------------------------------
  63.     getopt() - UNIX style command line option parser.
  64. ---------------------------------------------------------------------------*/
  65.  
  66. extern int    _TLXDATA    gOptInd;    // Next argument index
  67. extern int    _TLXDATA    gOptErr;    // Nonzero enables error message
  68. extern char * _TLXDATA    gOptArg;    // Pointer to current option argument
  69.  
  70. int           _TLXFUNC    tlGetOpt(int, char *[], const char *);
  71.  
  72. /*---------------------------------------------------------------------------
  73.     TLBatchApp -
  74.  
  75.     Models a typical batch processing program.
  76. ---------------------------------------------------------------------------*/
  77.  
  78. class _TLXCLASS TLBatchApp
  79. {
  80.     int            mDone;        // Set when about to terminate
  81.     int            mRetCode;    // Desired return code
  82.  
  83. protected:
  84.     int            mArgCnt;    // Number of arguments
  85.     char **        mArgs;        // Command line arguments
  86.     int            mCurArg;    // Current argument
  87.     const char *    mVersion;    // Application version ID
  88.  
  89. public:
  90.     TLBatchApp(int, char *[], const char *);
  91.     virtual ~TLBatchApp();
  92.  
  93.     int            Run();
  94.     const char *    Version() const { return mVersion; }
  95.  
  96. protected:
  97.     // Functions that may be overridden by derived classes
  98.     virtual bool     PreProcess();
  99.     virtual bool     PostProcess();
  100.     virtual void    DoFile(const char *);
  101.     virtual void    DoOption(const char *);
  102.     virtual void    PrintLogo();
  103.     virtual void    PrintSyntax();
  104.  
  105.     // Utility functions for derived classes
  106.     void        Terminate(int);    // Exit in an orderly fashion
  107.     void        Abort(int);    // Exit without postprocessing
  108.     void        SetRetCode(int);
  109. };
  110.  
  111. #endif    // _TLX_CMDAPP_H
  112.