Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 27 Jan 1997 13:38:34 +0100
From:      griepent@wias-berlin.de
Subject:   	FreeBSD 2.1.5 ci command interpreter test failed 
Message-ID:  <9701271238.AA32414@pascal.wias-berlin.de>

next in thread | raw e-mail | index | archive | help
Hello, bugs@FreeBSD.org !

I am going to use numerical applications on a X11 Window desktop and
I do not want to miss the nice and stable FreeBSD system,
because I like it so much, much more than Linux.
To stay compatible with our institute I want to work with our
self-written command interpreter ci. To compile a test version tci
there are necessary the following three files

	ci.h, ci.c and tci.c:

------------------------------------------------------------------------------
----------------------------------- ci.h -------------------------------------
------------------------------------------------------------------------------

/*
 * $Id: ci.h,v 2.1 1996/09/04 09:19:21 fuhrmann Exp $
 */

/*--------------------------------------------------------------------- 
                          CI 2.0
               Command Interpreter Interface 

Author: Juergen Fuhrmann 
        Weierstrass-Institut fuer Angewandte Analysis und Stochastik
        Mohrenstrasse 39
        10117 Berlin	

-------------------------------------------------------------------------*/
#ifndef CI
#define CI
#include <stdio.h>

#define DEFAULT_CI
#ifndef PARM
#ifdef NOPROTO
#define PARM(list) ()
#else
#define PARM(list) list
#endif
#endif

#ifndef STRING
#ifdef NOACPP
#define STRING(x) "x"
#define CONCAT(x,y) x/* */y
#else
#define STRING(x)  #x
#define CONCAT(x,y) x##y
#endif
#endif

#define CMD(cmd) CONCAT(c_,cmd)

#define  CI_BUFSIZE   512
#define  CI_LINSIZE   256
#define  CI_IDTSIZE   32
#define  CI_MAXARGS   8


/* Common procedures  - always active */

typedef struct tdsc *ciType;

ciType ciDefineType PARM((   char * name,
			     int(*  xtos ) PARM((char* ,void* )),
			     int(*  stox ) PARM((void* ,char* ))
                         ));

extern ciType     ciString,
                  ciIdent,
                  ciDec,
                  ciHex,
                  ciOct,
                  ciDouble,
                  ciFloat;

void  ciInit    PARM((void));
void  ciReInit  PARM((void));
void  ciBreak PARM((char * prompt));
int  ciDummy PARM((void));


/* default ci prototypes */


typedef int (*dciCommandProc) PARM((void));

typedef struct { 
        char * name; 
        dciCommandProc proc; 
}
dciCommandList;

int   dciGetArguments PARM((void));
void  dciDefineModule    PARM(( char * name, dciCommandList *commands, int qualify));
void  dciDefineArgument    PARM(( char * name, void * address, ciType type));
int   dciExecute    PARM(( FILE * input, FILE * output, char *prompt));


/*-----------------------------------------------------------*/
#ifdef PYTHON

#undef DEFAULT_CI

/* includes */
#define HAVE_STDLIB_H
#include "allobjects.h"
#include "modsupport.h"

/* interface prototypes */
typedef struct methodlist pyciCommandList;
void  pyciDefineArgument    PARM(( char * name,void * address, ciType type));

int pyciGetArguments PARM(( object *self, object *args));

/* interface definition */
#define ciCommandList                       pyciCommandList
#define ciDefineArgument(name,address,type) pyciDefineArgument(name,address,type)
#define ciDefineModule(name,list,qual)           initmodule(name,list)
#define ciReturn(i)                         return newintobject(i)
#define ciCommand(cmd)                      object * CMD(cmd) (pyciSelf,pyciArgs) object *pyciSelf,*pyciArgs;
#define ciGetArguments                      if(!pyciGetArguments(pyciSelf,pyciArgs)) ciReturn(1);ciDummy
#define ciExecute(in,out,prompt)            run(in,prompt)

#endif

/*-----------------------------------------------------------*/
#ifdef LISSI
#undef DEFAULT_CI
/* includes */
#include "fp.h"
#include "xinterf.h"
/* interface prototypes */

typedef int (*xciCommandProc) PARM((int ex));

typedef struct { 
         char * name; 
         xciCommandProc proc; 
}
xciCommandList;


int   xciGetArguments PARM(( int ex));
void  xciDefineArgument    PARM(( char * name,void * address, ciType type));
void  xciDefineModule    PARM(( char * name, xciCommandList *commands,int qualify));

/* interface definition */
#define ciCommandList                       xciCommandList
#define ciDefineArgument(name,address,type) xciDefineArgument(name,address,type)
#define ciDefineModule(name,list,qual)           xciDefineModule(name,list,qual);
#define ciReturn(i)                         return (!i)
#define ciCommand(cmd)                      int CMD(cmd)(ex) int ex;
#define ciGetArguments                      if(!xciGetArguments(ex)) ciReturn(1);ciDummy
#define ciExecute(in,out,prompt)            xInterpret(1,prompt,"xxx",in,out,out);

#endif

/*-----------------------------------------------------------*/
#ifdef TCL
#undef DEFAULT_CI
typedef int (*tclciCommandProc) PARM((int argc ,char *argv[]));
typedef struct { 
        char * name; 
        tclciCommandProc proc; 
}
tclciCommandList

int tclciGetArguments PARM(( int argc, char *argv[]))

/* interface definition */
#define ciCommandList                       tclciCommandList
#define ciDefineArgument(name,address,type) xDefine(xVariable,name,address,type,1)
#define ciDefineModule(name,list,qual)           xciDefineModule(name,list,qual);
#define ciReturn(i)                         return (i)
#define ciCommand(cmd)                      int CMD(cmd) (argc,argv) int argc; char*argv[];
#define ciGetArguments()                    if(!xciGetArguments(argc,argv)ciReturn(1);ciDummy

#endif


/*-------------------------------------------------------------*/
#ifdef DEFAULT_CI
/* interface definition */

#define ciCommandList                       dciCommandList
#define ciDefineArgument(name,address,type) dciDefineArgument(name,address,type)
#define ciDefineModule(name,list,qual)      dciDefineModule(name,list,qual);
#define ciReturn(i)                         return (i)
#define ciCommand(cmd)                      int CMD(cmd) PARM((void)) 
#define ciGetArguments                      if (!dciGetArguments())  ciReturn(1);ciDummy
#define ciExecute(in,out,prompt)            dciExecute(in,out,prompt)
#endif
/*--------------------------------------------------------------*/


/* the dummy declarations are for forcing ';'s at 
  the end of variable definitions 
  */


#define ciDoubleVariable(var,inival,callback)\
    double var=(inival); static ciCommand(var)\
 { ciDefineArgument("value",&var,ciDouble);ciGetArguments();\
   printf("ci: %s:=%e\n",STRING(var),var);ciReturn(callback());}int  ciDummy PARM((void))

#define ciIntegerVariable(var,inival,callback)\
    int var=(inival); static ciCommand(var)\
 { ciDefineArgument("value",&var,ciDec);ciGetArguments();\
   printf("ci: %s:=%d\n",STRING(var),var);ciReturn(callback());}int  ciDummy PARM((void))

#define ciIdentVariable(var,inival,callback)\
    char var[32]; static ciCommand(var)\
 { static char init=0; if(!init) {strcpy(var,inival);init=1;}\
     ciDefineArgument("value",var,ciIdent);ciGetArguments();\
   printf("ci: %s:=%s\n",STRING(var),var);ciReturn(callback());}int  ciDummy PARM((void))

#define ciDeclareVariable(var) {STRING(var),CMD(var)}
#define ciDeclareCommand(cmd)  {STRING(cmd),CMD(cmd)}
#define ciDeclareEnd           {NULL,NULL}




#endif



/* $Log: ci.h,v $
 * Revision 2.1  1996/09/04  09:19:21  fuhrmann
 * ciReInit() introduced
 *
 * Revision 2.0  1996/02/15  19:52:37  fuhrmann
 * First meta-stable distribution
 *
 * Revision 1.1  1995/10/20  15:12:40  fuhrmann
 * Initial revision
 *
 */

------------------------------------------------------------------------------
---------------------------------- ci.c --------------------------------------
------------------------------------------------------------------------------

static char *rcsid= "$Id: ci.c,v 2.1 1996/09/04 09:19:09 fuhrmann Exp $";

/*---------------------------------------------------------------------
                          CI 2.0
                   Command Interpreter 
----------------------------------------------------------------------*/
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "ci.h"


#define str2double xstr2double

#define TRUE 1
#define FALSE 0
#define lst_new(top,typ) {typ * c;\
                             c=(typ *)ciAlloc( sizeof(typ) );\
                             c->prv=top;\
                             top=c;}

#define lst_dsp(top,typ) {typ * c;\
                             c=top->prv;\
                             free(top);\
                             top=c;}

typedef struct tdsc typ_dsc;


struct tdsc
{
    struct tdsc *prv;
    char *idt;
    int  (*xtos)PARM((char*,void*));
    int  (*stox)PARM((void *,char *));
}; 

typedef struct pdsc{ struct pdsc *prv;
                     char *idt;
                     void *val;
                     typ_dsc *typ;
                   } par_dsc;

typedef struct mdsc { struct mdsc *prv;
                 		 char *idt;
                    } mnu_dsc;

typedef struct cdsc { struct cdsc *prv;
                      char *idt;
                      dciCommandProc cmd;
                      par_dsc *par;
                      mnu_dsc *mnu;
                     } cmd_dsc;


typedef struct ddsc { struct ddsc *prv;
                      char *idt;
                      char *rpl;
                    } def_dsc;




static cmd_dsc *cmd_top=NULL;
static def_dsc *def_top=NULL;
static mnu_dsc *mnu_top=NULL;
static typ_dsc *typ_top=NULL;

static FILE *ciIn  =NULL,
            *ciOut =NULL,
            *hlp_file=NULL,
            *pro_file=NULL;

static int echo  =1,
       is_end    =0;
int    ciBreaked=0;

static char ciBuf[CI_BUFSIZE],
            inp_buf[CI_BUFSIZE];




/*--------------------------------------------------------------*/
/* private  */
/*--------------------------------------------------------------*/
#ifndef NOPROTO
static void * ciAlloc(int n);
static void ciDebug(void);

static cmd_dsc *str2cmd(char *s);
static int ciPar(cmd_dsc *c);
static void readln(char * b);
static char * def_replace(char *s);
static int get_buf(void);
static int get_par(char *ci,char *par,char *val,typ_dsc *typ,char*s);
static int ciExecute0(void);

#endif


static void * ciAlloc(n) int n;
{ void * p;
  p=malloc((unsigned)n);
	 if (p==NULL) 
	 { printf("ci: FATAL ERROR - cannot xallocate\n");
	   abort();
	 };
 return p;
}





static void ciDebug() {;}
int ciDummy() {return 1;}

static void readln(b)
char * b;
{
    fgets(b,CI_LINSIZE,ciIn);
    if (feof(ciIn))
	{ 
	    /*
               fputs("%CI: End of file reached in command input\n",ciOut);
	       fflush(ciOut); 
	       exit(1);
	       */
	    *b='\0';
	    is_end=TRUE;
	}
   while (1)
       {
	   if (*b=='\n') { *b='\0'; return; }
	   if (*b=='\0') { *b='\0'; return; }
	   if (*b=='#')  { *b='\0'; return; }
	   b++;
       }

}


/*--------------------------------------------------------------*/
static int noalias=0;
/*Abschaltung des Alias-Mechanismus */

static char * def_replace(s)
char *s;
{ def_dsc * d;
  if (noalias) return NULL;
  d=def_top;
  while(d!=NULL)
  { if (strcmp(s,d->idt)==0) return d->rpl;
    d=d->prv;
  };
  return NULL;
}

/*--------------------------------------------------------------*/
static int get_buf()
{ 
    char *tok,
	*rpl,
	*bpos;
    int l;
    for(bpos=inp_buf;
	(bpos!=NULL)&&((bpos-inp_buf)<CI_BUFSIZE);
	bpos=strchr(inp_buf,'\\')) 
	readln(bpos);
    if (is_end) return 0;
    tok=strtok(inp_buf," ");
    strcpy(ciBuf,"");
    bpos=inp_buf;
    while (tok!=NULL)
	{ 
	    rpl=def_replace(tok);
	    l=strlen(tok);
	    if (rpl!=NULL)
		{ 
		    strcat(ciBuf, " ");
		    strcat(ciBuf,rpl);
		} 
	    else
		strncat(ciBuf,bpos,(int)((tok+l)-bpos));
	    bpos=tok+l;
	    tok=strtok(NULL," \n");
	    *bpos=' ';
	};
    return 0;
}

/*--------------------------------------------------------------*/
static int get_par (ci,par,val,typ,s)
char *ci, *par,*val,*s;
typ_dsc *typ;
{ char id[CI_IDTSIZE];
  int rc;
  if (s!=NULL)   rc=(*typ->stox)(val,s);
  else
  if (echo>0)
   { rc=(*typ->xtos)(id,val);
     fprintf(ciOut,"_%-8s%10s.%-10s[=%10s]=",typ->idt,ci,par,id);
     fflush(ciOut);
     get_buf();
     s=strtok(ciBuf," ");
     if (s!=NULL)
     rc=(*typ->stox)(val,s);
     } else
    { (*typ->xtos)(id,val);
      fprintf(ciOut,"\nci: The parameter %10s %10s.%-10s=%10s remains unchanged\n",typ->idt,ci,par,id);
      fflush(ciOut);
  };
   if (rc!=0)  
    fprintf(ciOut,"\nci: type conversion failed for type %s.\n",
          typ->idt); 
  fflush(ciOut);
  return rc;
}

/*--------------------------------------------------------------------*/
/* Belegung der Parameter */
static int ciPar(c)
cmd_dsc *c;
{ int rc;
  par_dsc *p;
  char * tok;
  rc=0;
  for (p=c->par;
       p!=NULL;
       p=p->prv)
    if (p->typ==ciString)
    { if ((tok=strtok(NULL,""))==NULL)  strcpy(p->val,"");
      else                              strcpy(p->val,tok);
    }
    else
    { rc=get_par(c->idt,p->idt,p->val,p->typ,strtok(NULL," "));
      if (rc!=0) return rc;
    }
 return 0;
}

/*--------------------------------------------------------------------*/
static cmd_dsc * str2cmd(name) char *name;
{ cmd_dsc *c=cmd_top,*xc;
  int len=strlen(name);
   
 while (strncmp(name,c->idt,len)!=0)
  {  c=c->prv;
     if (c==NULL) 
     { fprintf(ciOut,"\nci: No such command : \"%s\"\n",name);
       fflush(ciOut);
       return NULL;
     }
  }

 xc=c->prv;
 if (xc!=NULL)
 while (strncmp(name,xc->idt,len)!=0)
  {  xc=xc->prv;
     if (xc==NULL) return c;
    
  }
  else return c;

 fprintf(ciOut,"\nci: Ambiguous command : \"%s\", try \"%s\" or \"%s\"\n",
         name,c->idt,xc->idt);
  fflush(ciOut);
 return NULL;
       
}


/* Test, ob Kommando vorhanden, Ausfuehrung */
static int ciExecute0()
{ char * tok;
  cmd_dsc *c;
  int rc;
  tok=strtok(ciBuf," ");
  if (tok==NULL) return 0;
  
  c=str2cmd(tok);
  if (c==NULL) return 1; 

  
   rc=ciPar(c);
   if (rc!=0)
   { fprintf(ciOut,"\nci: Conversion error,no Execution of %s.\n",c->idt);
      fflush(ciOut);
      return rc;
    }
    rc=(*c->cmd)();
    if (!rc) fprintf(ciOut,"\nci: Error in command \"%s\".\n",c->idt);
    fflush(ciOut);
    return rc;

  fflush(ciOut);
  return rc;
}

/*--------------------------------------------------------------*/
/* public  */
/*--------------------------------------------------------------*/
/*  Definition eines Moduls */
int ciArgs(int self,int args)
{
   return args;
}

static int inCdef=0;
int ciCdef(name,proc)
char *name;
dciCommandProc proc;
{  int rc;
   cmd_dsc *c;


   for(c=cmd_top;c!=NULL;c=c->prv)
   if ( (strncmp(c->idt,name,strlen(c->idt))*
        strncmp(c->idt,name,strlen(name)))==0) break;
   
   if (c!=NULL) 
   {   printf("ci: new command \"%s\" would be ambiguous with \"%s\"\n",
         name,c->idt);
       return 1;
     }
   
   
   lst_new(cmd_top,cmd_dsc);
   cmd_top->cmd=proc;
   cmd_top->idt=malloc(strlen(name));
   strcpy(cmd_top->idt,name);
   cmd_top->par=NULL;
   cmd_top->mnu=mnu_top;
   inCdef=1; 
   rc=(*proc)();
   inCdef=0;
   if (!rc) 
     printf("ci: initialization of command \"%s\" failed\n",name);
   return rc;
}

void dciDefineModule(name,commands,qualify)
char *name;
dciCommandList commands[];
int qualify;
{ 
    int i;
    lst_new(mnu_top,mnu_dsc);
    mnu_top->idt=name;
    i=0;
    while (commands[i].name!=NULL)
	{   if (qualify) 
	    {
		sprintf(ciBuf,"%s.%s",name,commands[i].name);
		ciCdef(ciBuf,commands[i].proc);
	    }
	else
	    ciCdef(commands[i].name,commands[i].proc);
	i++;
	}
    return;
}

/*--------------------------------------------------------------*/
void ciAlias(idt,rpl)
char * idt,  * rpl;
{ def_dsc * d=def_top;
  while(d!=NULL)
  { if (strcmp(idt,d->idt)==0) 
    { free(d->rpl);
      d->rpl=(char *)ciAlloc(strlen(rpl)+1);
      strcpy(d->rpl,rpl);
      return;
    }
    d=d->prv;
  }

  lst_new(def_top,def_dsc);
  def_top->rpl=(char *)ciAlloc(strlen(rpl)+1);
  strcpy(def_top->rpl,rpl);
  def_top->idt=(char *)ciAlloc(strlen(idt)+1);
  strcpy(def_top->idt,idt);
  return;
}
/*--------------------------------------------------------------*/
/* Start des Interpreters */
int dciExecute(in,out,pr)
FILE *in,*out;
char *pr;
{ int rc;
  if (in==stdin) echo=1; else echo=0;
  is_end=FALSE;
   do
  { ciIn=in;
    ciOut=out;
    ciBreaked=0;
    if (ciIn==stdin) echo=1; else echo=0;
    if ((echo>0)&(!is_end)) { fprintf(ciOut,"\n%s>",pr);fflush(ciOut);};
    get_buf();
    if (!is_end) rc=ciExecute0();
  } while (!is_end);
  is_end=FALSE;
  return 0;
}

/*  Definition eines Stellungsparameters */
void dciDefineArgument(name,address,type)
char *name;
void *address;
typ_dsc *type;
{ 
       par_dsc * pnew,*p;      
      cmd_dsc *c;
   if (!inCdef) return;
 
  c=cmd_top;
  p=c->par;
  
  for (;;)
      { if (p==NULL)  break;
        if (p->prv==NULL) break;
        p=p->prv;
      }

    pnew=(par_dsc *)ciAlloc( sizeof(par_dsc) ); 
    pnew->prv=NULL;
    if (p==NULL) c->par=pnew;
    else p->prv=pnew;
 
    pnew->idt=name;
    pnew->val=address;
    pnew->typ=type;
}

int dciGetArguments()
{
 if (inCdef) return 0; else return 1;
}

/*--------------------------------------------------------------*/
/*  Definition eines Typs */
ciType ciDefineType(name,_xtos,_stox)
char *name;
int (*_xtos) PARM ((char * ss,void * xx));
int (*_stox) PARM((void * x, char * s));

{  lst_new(typ_top,typ_dsc);
   typ_top->idt=name;
   typ_top->xtos=_xtos;
   typ_top->stox=_stox;
   return typ_top;
}



/*--------------------------------------------------------------------*/
/* predefined */
/*--------------------------------------------------------------*/
/* types */
/*--------------------------------------------------------------*/
#ifndef NOPROTO
static int dec2str(char *s, void *x);
static int str2dec(void *x,char *s);
static int oct2str(char *s,void *x);
static int str2oct(void *x,char *s);
static int hex2str(char *s,void *x);
static int str2hex( void *x,char *s);
static int double2str(char *s,void *x);
static int str2double(void *x,char *s);
static int float2str(char *s,void *x);
static int str2float(void *x,char *s);
static int ident2str(char *s,void *x);
static int str2ident(void *x,char *s);

#endif
static int dec2str(s,x) 
char *s; void *x;
{ sprintf(s,"%d",*(int *)x);
  return 0;
}

static int str2dec(x,s)
char *s; void *x;
{ *(int*)x=atoi(s);
  return 0;
}
/*--------------------------------------------------------------*/
static int oct2str(s,x)
char *s;void *x;
{ sprintf(s,"%o",*(int*)x);
  return 0;
}

static int str2oct(x,s)
char *s; void *x;
{ sscanf(s,"%o",(int*)x);
  return 0;
}
/*--------------------------------------------------------------*/
static int hex2str(s,x)
char *s; void *x;
{ sprintf(s,"%x",*(int*)x);
  return 0;
}

static int str2hex(x,s)
char *s; void *x;
{ sscanf(s,"%x",(int*)x);
  return 0;
}
/*--------------------------------------------------------------*/
static int double2str(s,x)
char *s; void *x;
{ sprintf(s,"%e",*(double*)x);
  return 0;
}

static int str2double(x,s)
char *s; void *x;
{ *(double*)x=atof(s);
  return 0;
}

/*--------------------------------------------------------------*/
static int float2str(s,x)
char *s; void *x;
{ sprintf(s,"%e",*(float*)x);
  return 0;
}

static int str2float(x,s)
char *s; void *x;
{ *(float*)x=(float)atof(s);
  return 0;
}
/*--------------------------------------------------------------*/
static int ident2str(s,x)
char *s; void *x;
{ strcpy(s,(char *)x);
  return 0;
}

static int str2ident(x,s)
char *s; void *x;
{ strcpy((char *)x,s);
  return 0;
}

/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
/*--------------------------------------------------------------*/
/* commands */

/*--------------------------------------------------------------*/
static char def_lin_buf[CI_LINSIZE];
static char def_idt_buf[CI_IDTSIZE];

ciCommand(alias)
{
    def_dsc * d;
    int j;
 
    ciDefineArgument("string",def_idt_buf,ciIdent);
    ciDefineArgument("replace",def_lin_buf,ciString);
    ciGetArguments();
  
    if (strcmp(def_idt_buf,"?")==0)
	{ fputs("%CI : Alias list:\n",ciOut);
	for(d=def_top,j=10; d!=NULL;j++,d=d->prv)
	    fprintf(ciOut,"%15s = %-s\n",d->idt,d->rpl);
	if (noalias) 
	    fputs("%CI : Alias is off\n",ciOut);
	else
	    fputs("%CI : Alias is on        \n",ciOut);
	fflush(ciOut);
	ciReturn(1);
	}

 if (strcmp(def_idt_buf,"off")==0)
  { noalias=1;
  ciReturn(1);
  }

 if (strcmp(def_idt_buf,"on")==0)
  { noalias=0;
  ciReturn(1);
  }
  
  ciAlias(def_idt_buf,def_lin_buf);

ciReturn(1);

}
/*--------------------------------------------------------------*/
static char fname[CI_LINSIZE]={'\0'};
static char prompt[CI_LINSIZE]={'\0'};

ciCommand(source)
{ 
    FILE *in=ciIn;
    FILE *out=ciOut;
    
    ciDefineArgument("file",fname,ciIdent);
    ciDefineArgument("prompt",prompt,ciString);
    ciGetArguments();
    
    if (strcmp(fname,"tty")==0)
	ciIn=stdin;
    else
	{ 
	    if( (ciIn=fopen(fname,"r"))==NULL)
		{ fprintf(ciOut,
			  "\nci: file %s not found.\n",
				  fname);
		fflush(ciOut);
		ciIn=in;
ciReturn(0);
		} 
	}
    if (prompt[0]=='\0') strcpy(prompt,fname);
    ciExecute(ciIn,ciOut,prompt);
    if (ciIn!=stdin) fclose(ciIn);
    ciIn=in;
    ciOut=out;
    fname[0]='\0';
    prompt[0]='\0';

    ciReturn(1);

}



/*--------------------------------------------------------------*/
ciCommand(quit)
{ 
    ciGetArguments();
 is_end=TRUE;   ciReturn(1);}

ciCommand(exit)
{ 
    ciGetArguments();
 is_end=TRUE;   ciReturn(1);}

char hlp_idt_buf[CI_IDTSIZE]={'?','\0'};

ciCommand(help)
{ int i,j;
  char locked;
  cmd_dsc * c;
  par_dsc * p;
  mnu_dsc * m;
  char id[CI_IDTSIZE];
 
  ciDefineArgument("command",hlp_idt_buf,ciIdent);
     ciGetArguments();
 


  if (strcmp("?",hlp_idt_buf)==0)
  {
    for(j=1,c=cmd_top;c!=NULL;j++)
    {  m=c->mnu;
       printf("\nmodule %s:\n",m->idt);
       for(;(c!=NULL)&&(c->mnu==m);)
       { for(i=0;(i<4)&&(c!=NULL)&&(c->mnu==m);i++,c=c->prv)
         { 
           printf("%-18s",c->idt);
         }
          fputs("\n",ciOut);
       }
     }
    fflush(ciOut);
    goto exit;
  }

  else
   { c=str2cmd(hlp_idt_buf);
     if(c!=NULL)
     { fprintf(ciOut,"\nCOMMAND    = %s\n",c->idt);
       fprintf(ciOut,  "PARAMETERS : \n");
       p=c->par;
       if (p==NULL) fprintf(ciOut,"none\n");
       while(p!=NULL)
       {if (p->typ==ciString)
	  fprintf(ciOut,"string     %-12s %-30s\n",p->idt,p->val);
        else
	      { (*p->typ->xtos)(id,p->val);
	 fprintf(ciOut,"%-10s %-20s = %s\n", p->typ->idt,p->idt,id);
        }
        p=p->prv;
        }

      }
       
    fprintf(ciOut,"You will get a command list by typing  \"help ? \"\n");

    goto exit;
  }
exit:
  fflush(ciOut);
  ciReturn(1);
}


/*--------------------------------------------------------------*/
ciCommand(halt)
{ 
    ciGetArguments();

  { fprintf(ciOut,"ci: halt\n");
    fflush(ciOut);
    exit(1);
  }
  ciReturn(1);
}
/*--------------------------------------------------------------*/
static char  msg_lin_buf[CI_LINSIZE]={'\0','\0'};

ciCommand(echo)
{  
    ciDefineArgument("msg",msg_lin_buf,ciString);
    ciGetArguments();
    fprintf(ciOut,"%s\n",msg_lin_buf);
     fflush(ciOut);  
  ciReturn(1);
   
}

ciCommand(system)
{

  
    ciDefineArgument("command",msg_lin_buf,ciString);
       ciGetArguments();

 if (strcmp(msg_lin_buf,"")==0)
      fprintf(ciOut,"ci: system\n");
    fflush(ciOut);
    system(msg_lin_buf);
    if (strcmp(msg_lin_buf,"")==0)
      fprintf(ciOut,"ci: back\n");
    fflush(ciOut);
  ciReturn(1);
 }

  




/*--------------------------------------------------------------*/
/*--------- INTERRUPT HANDLING ---------------------------------*/
ciCommand(break)
{ 

      ciGetArguments();

  ciBreaked=1;
  is_end=TRUE;
 ciReturn(1);
}

void handle_interrupt(isig)int isig;
{
 signal(isig,handle_interrupt);
 ciExecute(stdin,stdout,"interrupt::ci");
 if (ciBreaked)
    fprintf(ciOut,"\n\nci: break\n");
  else 
    fprintf(ciOut,"\n\nci: continue\n");
 fflush(ciOut);
}

void ciBreak(prompt)
char * prompt;
{  ciExecute(stdin,stdout,prompt);
}

void ci_()
{
   fflush(ciOut);
   ciExecute(stdin,stdout,"debug::ci");
   fflush(ciOut);
}



ciCommand(debug)
{
    ciGetArguments();

   fprintf(ciOut,"ci: debugger\n");
   fflush(ciOut);
   ciDebug();
   fprintf(ciOut,"ci: back\n") ;
   fflush(ciOut);
  ciReturn(1);
} 


/*-----------------------------------------------------------------------*/
#ifdef PYTHON

static char  argstr[CI_MAXARGS+3];
static void* argaddr[CI_MAXARGS+1];

static char* stringaddr[CI_MAXARGS+1];
static char* xstringaddr[CI_MAXARGS+1];

int iarg=1;

void pyciDefineArgument(name,address,type)
char *name;
void *address;
typ_dsc *type;
{int i;
    if (iarg>=CI_MAXARGS) 
	{
	    printf("ci: define arg: too many args\n");
            return;
	}

     
   stringaddr[iarg]=NULL;
    
    argaddr[iarg]=address;
    if (type==ciDec)
	{ 
	    argstr[iarg]='i';
	    argaddr[iarg]=address;
	}
 else   if (type==ciDouble)
	{ 
	    argstr[iarg]='d';
	    argaddr[iarg]=address;
	}
 else if (type==ciFloat)
	{ 
	    argstr[iarg]='f';
	    argaddr[iarg]=address;
	}
  
    else if (type==ciString)
	{ 
	    argstr[iarg]='s';
	    argaddr[iarg]=&xstringaddr[iarg];
	    stringaddr[iarg]=address;
            
	}
    else if (type==ciIdent)
	{ 
	    argstr[iarg]='s';
	    argaddr[iarg]=&xstringaddr[iarg];
	    stringaddr[iarg]=address;
	}
    else
      {
	  printf("ci: type not defined\n");
      }
    iarg++;
}

int pyciGetArguments(self,args)
object * self,*args;
{ 
    register int i,j;
    if (iarg==1) return 1;
   
     if (iarg==2)
	 {
	     argstr[iarg]='\0';
	 }
else
    {
	argstr[0]='(';
	argstr[iarg]=')';
	argstr[iarg+1]='\0';
    }
    switch(iarg-1)
     { 
     case 1: if (!getargs(args,argstr+1,argaddr[1])) goto error; break;
     case 2: if (!getargs(args,argstr,argaddr[1],argaddr[2])) goto error; break;
     case 3: if (!getargs(args,argstr,argaddr[1],argaddr[2],argaddr[3])) goto error; break;
     default: 
	 printf("ci: too many args\n");
     }
    for(i=1;i<=iarg;i++) 
     if (stringaddr[i]!=NULL)
	 {  strcpy(stringaddr[i],xstringaddr[i]);
	 }

    iarg=1;
    
    return 1;
  error:
    printf("ci: python argument conversion error\n");
    iarg=1;
    return 0;
}
#endif

/*--------------------------------------------------------------------------*/
#ifdef LISSI
int   xciGetArguments PARM(( int ex))
{
 if (ex<1) return 0; else return 1;

}

void  xciDefineArgument( char * name,void * address, ciType type)
{
if (inCdef)
    {
    if (type==ciDec)
	{ 
	    xDefine(xVariable,name,address,1,xInteger);

	}
 else   if (type==ciDouble)
	{ 
	    xDefine(xVariable,name,address,1,xReal);
	}
    else if (type==ciString)
	{ 
	    xDefine(xVariable,name,address,CI_LINSIZE,xCharacter);
            
	}
    else if (type==ciIdent)
	{ 
	    xDefine(xVariable,name,address,CI_IDTSIZE,xCharacter);
	}
    else
      {
	  printf("ci: lissi type not defined\n");
      }
    }
}

void  xciDefineModule ( char * name, xciCommandList *commands, int qualify)
{
  int i;
  if (qualify)
      xDefineStructure(name);
   i=0;
   while (commands[i].name!=NULL)
       {
	   xDefineCommand(commands[i].name,commands[i].proc);
           inCdef=1;
           commands[i].proc(0);
           inCdef=0; 
	   xEndDefinition();
	   i++;
       }
  if (qualify)
      xEndDefinition();
   return;
}
#endif
/*--------------------------------------------------------------------------*/

ciType   ciString,
           ciIdent,
           ciDec,
           ciOct,
           ciHex,
	          ciDouble,
	          ciFloat,
	          ciFloat_array,
	          ciDouble_array;
static ciCommandList systemlist[]={
   ciDeclareCommand(echo),
   ciDeclareCommand(debug),
   ciDeclareCommand(halt),
   ciDeclareCommand(break),
   ciDeclareCommand(system),
#ifndef PYTHON
   ciDeclareCommand(help),
   ciDeclareCommand(quit),
   ciDeclareCommand(exit),
   ciDeclareCommand(alias),
   ciDeclareCommand(source),
 
#endif
   ciDeclareEnd};
   

static void read_profile()
{
#ifdef PYTHON
  pro_file=fopen(".pyrc","r");
  if(pro_file!=NULL)
    { 
      run_script(pro_file,"init");
    }
#endif
  
#ifdef DEFAULT_CI
  pro_file=fopen(".circ","r");
  
  if(pro_file!=NULL)
    { 
      ciExecute(pro_file,stdout,"init");
    }
#endif   
  
}

static int init_flag=0;
void  ciInit()
{  
  if (init_flag) return;
  ciString=NULL;
  ciDouble   = ciDefineType("double",   double2str,   str2double);
  ciDec   = ciDefineType("dec",   dec2str,   str2dec);
  ciOct   = ciDefineType("oct",   oct2str,   str2oct);
  ciHex   = ciDefineType("hex",   hex2str,   str2hex);
  ciIdent = ciDefineType("ident", ident2str, str2ident);

#ifdef PYTHON
  initall();
#endif
  
#ifdef LISSI
  xinterfInit();
#endif

  
  ciDefineModule("ci",systemlist,0);


  ciIn=stdin;
  ciOut=stdout;
  
  signal(SIGINT,handle_interrupt);
  read_profile();
  init_flag=1;
}

void  ciReInit()
{
  def_dsc *d=def_top;
  ciInit();
  fprintf(stdout,"ci: reinitialization, alias list cleared\n");
  while (def_top!=NULL)
    { 
      free(def_top->idt);
      free(def_top->rpl);
      d=def_top;
      def_top=d->prv;
      free(d);
    }
  read_profile();
}

/*
 * $Log: ci.c,v $
 * Revision 2.1  1996/09/04  09:19:09  fuhrmann
 * ciReInit() introduced
 *
 * Revision 2.0  1996/02/15  19:52:37  fuhrmann
 * First meta-stable distribution
 *
 * Revision 1.2  1995/10/23  20:14:27  fuhrmann
 * strdup 'rausgenommen
 *
 * Revision 1.1  1995/10/20  15:12:12  fuhrmann
 * Initial revision
 *
 */

---------------------------------------------------------------------------
----------------------------- tci.c ---------------------------------------
---------------------------------------------------------------------------

#include "ci.h"


void main(int argc, char* argv[])
{
  ciInit();
  ciExecute(stdin,stdout,"tci");
}


---------------------------------------------------------------------------
----------------------------- end of code ---------------------------------
---------------------------------------------------------------------------

The command interpreter ci/tci was successfully GCC compiled on several
architectures like Linux, DEC UNIX, SunOS 4.1.x and IRIX 5.x, for instance,
and it works flawlessly.
On my i486/FreeBSD 2.1.5 machine I was also able to compile tci with
gcc-2.6.3, but the executable code does not work at all, some of the
command interpreter functions are not available. It seems to be a
memory allocation problem, because the listing of the interpreter commands
(you can get it with the help command) shows the strange ascii symbol "o"
as an executable interpreter command! Here you can see a terminal dump:

bash$ gcc -o tci tci.c ci.c
bash$ ls -l tci*
-rwxr-xr-x  1 johnny  johnny  18842 Oct 15 18:55 tci*
-rw-------  1 johnny  johnny    102 Oct 15 14:49 tci.c
bash$ ./tci
ci: new command "quit" would be ambiguous with ""
ci: new command "exit" would be ambiguous with ""
ci: new command "alias" would be ambiguous with ""
ci: new command "source" would be ambiguous with ""

tci>help ?

module ci:
help              system            break                               
debug             o                 

tci>system
ci: system
ci: back

tci>debug
ci: debugger
ci: back

tci>break
bash$ 

I do not know, whether there is a mistake in our code or somewhere
in the operating system. Our code seems to be stable on all of the 
above architectures.
Please, extract and try out our code on one of your machines!
It would be very nice, if you could give me an answer to my problem!

Jens Griepentrog
Weierstrass Institute for Applied Analysis and Stochastics
Mohrenstrasse 39
D-10117 Berlin	
Germany
griepent@wias-berlin.de



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9701271238.AA32414>