! sqrsh (sqr shell)
! Copyright (C) 1997 Ray Ontko & Company
!
! This program is free software; you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation; either version 2 of the License, or
! (at your option) any later version.
!
! This program is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with this program; if not, write to the Free Software
! Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
!
!++
!
! sqrsh
!
! sqrsh (sqr shell) is a command line interpreter which is written
! in sqr and is designed for use by sqr programmers.
!
! Some commands:
!
! * help
! * exit
! * quit
! * end
! * show - show a file
! * more - displays a file by pages
! * host - allows execution of a host command
! * gensqrsh - allows user-defined add-ins to this program
!   debug - interactive debugger
! * trace - trace procedural exection
! * profile - statement level execution profiler
!   htmlform - creates an html form generator/cgibin program
!   calls - shows which routines calls/called by others
!   includes - shows which programs are possibly included by a program
!   sqlextract - extracts sql from a program
!   explain - explains sql in a program
!   opt - optimizes a program (let->move,etc.)
!   lint - check for common programming errors
! * bsearch - creates a binary search routine for an array
!   lsearch - creates a linear search routine for an array
!   qsort - creates a quick sort routine for an array
!   ssort - creates a shell sort routine for an array
!   bsort - creates a bubble sort routine for an array
! * libr - inserts ifndefs for #include files
! * autodoc - extracts comments between !++ and !--
!   copyright - inserts a copyright notice in the top of a bunch of files
! * modhist - inserts a modification history sectoin after !--
! * pretty - beautifies a program
! O connect - connects to a database
! O sql - allows execution of a begin-sql command
! O columns - displays the columns by table
!   indexes - displays the indexes by table
!   constraints - displays the constraints by table
!   @ - invokes a file of sqrsh commands
!   edit - opens a simple editor on a text file
!   droptabs - drop tables
!   dropcons - drop constraints
! O fk - creates an integrity constraint checker for disabled fk constraints
!
! * = done
! O = Oracle only
! others are proposed or under construction
!
!--
! Some things to fix:
!
! easier to add new commands (perhaps a command that reads
! a file containing the names of the commands and generates
! a sqrsh program)
!
! a better name for the program?  I think what we have here
! is an interactive tool kit, more than a shell.
!
! because we allow some functions which use begin-sql or begin-select
! we require that a valid database login be given.  Ideally,
! we could allow use of the shell without a connect.  Is there
! a way to allow this?
!
! we have a [More...] feature in a number of modules.  The size
! of the screen should be settable by the user.  It should also
! be possible to disable the feature (for listings, etc.)
! this could be done using a SET command, which saves a
! value into an array of define variables, which would then
! be checked by the programs.
!
! add command line recall and editing features.  This may not
! be easy.
!
! add the ability to redirect to a file, or something.  When I
! do columns or any of the listings, I'd like to be able to save
! it to a file or print it.  We might be able to just spool to
! a file always, and then use more if they don't give us an output
! file.  I don't know that we need pipes.
!
! Modification History
!
! Name             Date       Comments
! ---------------- ---------- ----------------------------------------
! Ray Ontko        1996.10.26 Created
! Ray Ontko        1997.06.09 Added sqr-database default value UNKNOWN
!

! The following definition for SQR-DATABASE was added to support
! versions of SQR prior to 3.0 in which SQR-DATABASE is undefined.
!
#ifndef SQR-DATABASE
#define SQR-DATABASE UNKNOWN
#end-if

#define SQRSH_LINE_MAX 500

begin-setup
!%% - generated BEGIN-SETUP section begins

 ! gensqrsh setup begins
 ! gensqrsh setup ends

 ! profile begin-setup
 #define PROFILE_ARRAY_SIZE 1000
 create-array
    name=profile_array
    size={PROFILE_ARRAY_SIZE}
    field=name:char
    field=line:number
 ! profile end-setup
!%% - generated BEGIN-SETUP section ends
end-setup

begin-report
   move 1 to #looping
   while #looping
      show 'sqrsh> ' noline
      input $command noprompt
      if substr($command,1,1) <> '!!'
         let $c = ltrim($command,' ')
         unstring $c by ' ' into $p0 $p1 $p2 $p3 $p4 $p5 $p6 $p7 $p8
         uppercase $p0
         evaluate $p0
            when = ''
               break
!%% - generated WHEN section begins
            when = 'AUTODOC'
               do autodoc
               break
            when = 'BSEARCH'
               do bsearch
               break
            when = 'END'
               do end
               break
            when = 'EXIT'
               do exit
               break
            when = 'GENSQRSH'
               do gensqrsh
               break
            when = 'HELP'
               do help
               break
            when = 'HOST'
               do host
               break
            when = 'LIBR'
               do libr
               break
            when = 'MODHIST'
               do modhist
               break
            when = 'MORE'
               do more
               break
            when = 'OPTIMIZE'
               do optimize
               break
            when = 'PRETTY'
               do pretty
               break
            when = 'PROFILE'
               do profile
               break
            when = 'QUIT'
               do quit
               break
            when = 'SHOW'
               do show
               break
            when = 'TRACE'
               do trace
               break
            when = 'COLUMNS'
               do columns
               break
            when = 'CONNECT'
               do connect
               break
            when = 'FK'
               do fk
               break
            when = 'SQL'
               do sql
               break
!%% - generated WHEN section ends
            when-other
               show 'sqrsh: Unknown command ' $p0
               break
         end-evaluate
      end-if
   end-while
end-report

#include 'sqrsh.sqh'

!%% - generated INCLUDE section begins
#include 'autodoc.sqh'
#include 'bsearch.sqh'
#include 'end.sqh'
#include 'exit.sqh'
#include 'gensqrsh.sqh'
#include 'help.sqh'
#include 'host.sqh'
#include 'libr.sqh'
#include 'modhist.sqh'
#include 'more.sqh'
#include 'optimize.sqh'
#include 'pretty.sqh'
#include 'profile.sqh'
#include 'quit.sqh'
#include 'show.sqh'
#include 'trace.sqh'
#include 'columns.sqh'
#include 'connect.sqh'
#include 'fk.sqh'
#include 'sql.sqh'
!%% - generated INCLUDE section ends
