/* begincopyright
  Copyright (c) 1988 Xerox Corporation. All rights reserved.
  Use and copying of this software and preparation of derivative works based
  upon this software are permitted. Any distribution of this software or
  derivative works must comply with all applicable United States export
  control laws. This software is made available AS IS, and Xerox Corporation
  makes no warranty about the software, its performance or its conformity to
  any specification. Any person obtaining a copy of this software is requested
  to send their name and post office or electronic mail address to:
    PCR Coordinator
    Xerox PARC
    3333 Coyote Hill Rd.
    Palo Alto, CA 94304
  endcopyright */

/*
 * CommandLoop.h
 *
 * PCR command line and read-eval-print.
 *
 * Demers April 15, 1990 11:43:47 am PDT
 */

 
#ifndef ←XR←COMMAND←LOOP←
#define ←XR←COMMAND←LOOP← 1

#ifndef ←XR←BASIC←TYPES←
#   include "xr/BasicTypes.h"
#endif

#ifndef ←XR←COMMAND←LINE←
#   include "xr/CommandLine.h"
#endif


/*
 * The global handles ...
 */

    
extern XR←CLHandle
XR←globalCLHandle;
/*
    Starts out as handle on original PCR command line arguments.
    Gets modified as result of package setup code.
*/


extern XR←CLProcsHandle
XR←globalCLProcsHandle;
/*
    Procs for sequentially-executed command-line or command-file
      argument groups.
    PCR components (GC, IL, ...) register procs here during setup.
*/

extern XR←MesaProc XR←stdOutCLMsgSink;
/*
    Closure for void (*sink)(char *buf, int nBytes, XR←MesaProc self)
    A message sink for stdout.
    Used in initial call to CLApply on global handles.
    Monitored, so it may also be used by clients.
*/


/*
 * Global state for command proc execution ... may be used by procs
 *   that don't get the call environment passed to them, provided
 *   they expect to be invoked only thru the global commander thread.
 */

extern XR←CLCallEnv
XR←GetTopLevelCLCallEnv();

extern XR←CLCallEnv
XR←SetTopLevelCLCallEnv(/* XR←CLCallEnv clce */);
/*
    Call environment at top of command stack.
*/



extern XR←JmpBuf
XR←GetTopLevelJumpBuf();
/*
    An XR←longjmp here simulates return from current command line proc.
*/


extern void
XR←StoreTopLevelCLErrorHandler(/* XR←MesaProc handler */);
/*
    A CLProc may store a handler for command errors.
    The handler is a closure for
      (int) (*handler)(int prevResult, XR←MesaProc self)
    The result returned by the handler is returned from
      the enclosing call to CommandLine.h.XR←CLApply. 
    A NIL handler just propagates the error result.
*/


/*
 * Some global PCR state
 *   (possibly this doesn`t belong here, but ...)
 */

extern int
XR←SetPCRFileName(/* char *fn */);
/*
    Set name of PCR symbols file.
    Setting it to NIL turns of symbol table initialization
      and thus disables dynamic loading.
*/

extern char *
XR←GetPCRFileName();
/*
    Get name of PCR symbols file.
*/


extern int
XR←SetTmpDirectory(/* char *dirName */);
/*
    Set name for tmp file directory.
*/

extern char *
XR←GetTmpDirectory();
/*
    Get name for tmp file directory.
*/


extern int
XR←SetDBXScriptName(/* char *n */);
/*
    Set name for dbx script.
    Setting to NIL turns it off.
*/

extern char *
XR←GetDBXScriptName();
/*
    Get name of dbx script.
*/

/*
 * Utilities ...
 */

extern int
XR←CLCallProc(/*
    XR←UntypedProc proc,
    int argc, 
    XR←Pointer *argv,
    XR←Pointer *resultP
*/);
/*
    Call proc with args.
    If resultP != NIL, store result (assumed to be 1 word) in *resultP.
    Return
        0 (success)
        -1 (argc too big -- promise to support argc <= 6)
        < -1 (other failure).
*/

/*
 * OBSOLETE, but still in use as of April 9, 1990, sigh ...
 */

typedef XR←Pointer (**CommandProc)(/*
    char *cmd,
    XR←Pointer clientData,
    CommandProc self
*/);
/*
    Called with entire arg group as a string ... so it has to reparse it!
*/

extern void
XR←register(/*
    char *key,
    CommandProc proc,
    char *doc,
    XR←Pointer clientData
*/);
/*
    Register given command proc as processor for given command.
*/

extern char *
XR←get←loader←directory();
/*
    Return immutable string = name of loader temp directory.
    Equivalent to XR←GetTmpDirectory().
*/


extern char *
XR←GetCurrentCommand();
/*
    Return command currently being executed by a CommandProc,
      or set by SetCurrentCommand.
*/

extern void
XR←SetCurrentCommand(/* char *c */);
/*
    Set command to be returned by GetCurrentCommand.
*/



#endif /* ←XR←COMMAND←LOOP← */