// ==============================================================
//#+ This module generated by Mumps Compiler 5.05a - Oct 11 2002
//#+  
//#+ Portions of this code are part of the Mumps Compiler
//#+ 
//#+ Copyright (C) A.D. 2000, 2001, 2002 by Kevin C. O'Kane  
//#+ Copyright (C) A.D. 2002 by Matthew J. Lockner  
//#+ Copyright (C) A.D. 2002 by Michael Janssen
//#+ 
//#+ Kevin C. O'Kane, Ph.D.
//#+ Computer Science Department
//#+ University of Northern Iowa
//#+ Cedar Falls, IA 50614-0507
//#+ Tel 319 273 7322
//#+ okane@cs.uni.edu
//#+ http://www.cs.uni.edu/~okane
//#+ -----------------------------------
//#+ 
//#+ Matthew J. Lockner
//#+ Department of Computer Science
//#+ University of Northern Iowa
//#+ Cedar Falls, IA  50614-0507
//#+ lockner@cns.uni.edu
//#+ http://student.cns.uni.edu/~lockner/
//#+ -----------------------------------
//#+ 
//#+ Michael Janssen
//#+ Department of Computer Science
//#+ University of Northern Iowa
//#+ Cedar Falls, IA  50614-0507
//#+ janssen@cns.uni.edu
//#+ http://student.cns.uni.edu/~janssen/
//#+ -----------------------------------
//#+ 
//#+ The runtime libraries are covered by the following license:
//#+  
//#+ This library is free software; you can redistribute it and/or
//#+ modify it under the terms of the GNU Lesser General Public
//#+ License as published by the Free Software Foundation; either
//#+ version 2.1 of the License, or (at your option) any later version.
//#+ 
//#+ This library 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
//#+ Lesser General Public License for more details.
//#+ 
//#+ You should have received a copy of the GNU Lesser General Public
//#+ License along with this library; if not, write to the Free Software
//#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//#+ 
//#+ This code is unverified - use at your own risk 
//#+==============================================================

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <setjmp.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif
#include <mumpsc/strmax.h>
#define SYM_MAX 100 /* Max Symbol Table Depth */
#define FORPARM 32  /* Size of For loop parameter */
#ifdef SUB /* declarations if this is not a sub function */
#include <mumpsc/externs.h>
extern int (*__label_lookup)(char *);
extern char * (*__text_function)(int);
#endif
#ifndef SUB
char cfgdata[256]; /* old globals data file */
char cfgkey[256]; /* old globals btree file */
long g; /* global array handler action parm */
int (*__label_lookup)(char *);
char * (*__text_function)(int);
long io=5; /* current i/o unit number */
long tpx=0; /* $test */
int NOERR=0,ERROR=0; /* error message surpress */
FILE *in_file[10]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; /* file ptrs */
FILE *out_file[10]={NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL}; /* file ptrs */
int hor[10]={0,0,0,0,0,0,0,0,0,0}; /* horizontal cursors */
int ver[10]={1,1,1,1,1,1,1,1,1,1}; /* vertical cursors */
int _Sym=0; /* symbol table layer */
long LineNumber=0; /* runtime line number */
jmp_buf _doStack[128]; /* <do> return stack mechanism */
short   _doStackN[128]={0}; /* <do> return stack mechanism */
int     _doStx=0; /* <do> return stack mechanism */
int gpad=0; /* global collating sequence flag */
#else
/*** Sub-function */
char cfgdata[256]; /* old globals data file */
char cfgkey[256]; /* old globals btree file */
extern long g;  /* global array handler action parameter */
extern long io;  /* current i/o unit */
int NOERR=0,ERROR=0; /* error message surpress */
extern FILE *in_file[10];  /* file pointers */
extern FILE *out_file[10];  /* file pointers */
extern int hor[10];  /* horizontal cursors */
extern int ver[10];  /* vertical cursors */
extern int _Sym;  /* symbol table layer */
extern long LineNumber;  /* runtime line number */
extern jmp_buf _doStack[100];  /* DO-return stack */
extern short   _doStackN[100];  /* DO-New stack */
extern int _doStx;  /* DO-return stack top */
extern int gpad;  /* global collating sequence flag */
#endif
void zfcn(unsigned char *, unsigned char *); /* z functions */
char * sym_(int, unsigned char *, unsigned char *); /* symbol table */
char * makeLock(char *, char *, char *, char *); /* global array lock service */
char * cleanLocks(char *, char *); /* global array lock service */
char * releaseLock(char *, char *, char *); /* global array lock service */
char * eraseLocks(char *); /* global array lock service */
void add(char *a,char *b,char *c); /* math function */
void sub(char *a,char *b,char *c); /* math function */
void mult(char *a,char *b,char *c); /* math function */
void divx(char *a,char *b,char *c); /* math function */
void divi(char *a,char *b,char *c); /* math function */
void _fnumber(unsigned char *,unsigned char *,
       unsigned char *,unsigned char *); /* math function */
#include <mumpsc/global.h>  /* Global array definitions */
  /* Interface to Mglobal(): */
  /* g = command */
  /* key = key sought or stored */
  /* bd = value returned or stored */
#ifndef SUB
#include <mumpsc/fcns.h>  /* System support functions */
#include <mumpsc/globalvars.h>  /* Many common global variables */
#include <mumpsc/sysfunc.h>  /* Many common global variables */
#endif
/*=================================================================================*/
//       zmain
/*=================================================================================*/

int main(int argc, char *argv[]) {

//#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//#+ Intermediate temporary variables used during execution of string expressions
//#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

char _ftmp[STR_MAX]; /* intermediate temp */
/*** Temporary variables */
//#+  intermediate variables
char for1_incr[FORPARM],for1_lim[FORPARM],for1_init[FORPARM];
int for1F; int for1T; long for1; double for1D;
char for2_incr[FORPARM],for2_lim[FORPARM],for2_init[FORPARM];
int for2F; int for2T; long for2; double for2D;
jmp_buf for0J;
jmp_buf for1J;
jmp_buf for2J;
char _Arg0[STR_MAX];
char tmp0[STR_MAX];
char tmp1[STR_MAX];
char tmp2[STR_MAX];
char tmp3[STR_MAX];
char _dummy[STR_MAX]; /* temporary variable */
unsigned char atmp[STR_MAX]; /* temporary variable */
unsigned char gtmp[STR_MAX]; /* temporary variable */
unsigned char gtmpL[STR_MAX]; /* temporary variable */
unsigned char tmp[STR_MAX]; /* temporary variable */
int _label_lookup(char *); /* resolution of labels */
char * _text_function(int);
static unsigned char _ReturnVal[STR_MAX]; /* function returns */
int _ArgCount=0; /* Nbr of args to extrinsic */
long i,_jj,_j,_k,_new;
int f=0;

int SymLoadFlg=0; /* was the symbol table loaded from disk? */
in_file[5]=stdin; /* console default */
out_file[5]=stdout; /* console default */
__label_lookup=_label_lookup;
__text_function=_text_function;
signal(SIGINT,&sigint);  //* trap Ctrl-C


#ifdef CLIENT
if (argc < 2) {
#ifdef DEFAULT_IP
   printf("Warning: Using default IP\n");
   client_init(DEFAULT_IP);
#else
   printf("Usage: %s <server IP>\n", argv[0]);
   exit(-1);
#endif
} else {
   client_init(argv[1]);
}
#endif
#ifndef _MSC_VER
	 if (strcmp(argv[0],"***")!=0) SymLoadFlg=SysLoad((long)getppid()); /* load symbol table? */
	 else SymLoadFlg=SysLoad((long)getpid()); /* load symbol table? */
#else
	 if (strcmp(argv[0],"***")!=0) SymLoadFlg=SysLoad(999L); /* load symbol table? */
	 else SymLoadFlg=SysLoad(999L); /* load symbol table? */
#endif
/*=================================================================================*/
LineNumber=2; //       k ^a
/*=================================================================================*/
	 strmove(gtmp,"");
	 strcat(gtmp,"^a");
	 {	unsigned char tmp14[STR_MAX],tmp15[STR_MAX];
		keyfix(gtmp);
		 _k=strlen(gtmp);
		 strmove(tmp14,gtmp);
		 Mglobal(GKILL,gtmp,tmp15);
		 while(1) {
		 _j=Mglobal(XNEXT,gtmp,tmp15);
		 if (_j&&strncmp(tmp14,gtmp,_k)==0) {
			 Mglobal(GKILL,gtmp,tmp15);
			 continue;
			 }
		break;
		 }
	 }
/*=================================================================================*/
LineNumber=3; //       f i=0:1:9 s ^a(i)=i f j=0:1:9 s ^a(i,j)=j
/*=================================================================================*/
	 strmove(for1_init,"0");
	 strmove(for1_incr,"1");
	 strmove(for1_lim,"9");
	 if (strchr(for1_incr,'.')) { 
	     for1D=atof(for1_incr);
	     for1F=for1D<0.0 ? 1 : 0;
	     for1T=1;
	     }
	 else { 
	     for1=atol(for1_incr); 
	     for1F=for1<0 ? 1 : 0;
	     for1T=0;
	     } /* increment */
	 for ( sym_(0,"i",for1_init);        /* initialize loop variable */
	       for1F ? numcomp(sym_(11,"i",_dummy),for1_lim)>=0: /* limit expression */
	                numcomp(sym_(11,"i",_dummy),for1_lim)<=0; /* select compare method */
	       for1T ? add3(sym_(11,"i",_dummy),for1D,_dummy), sym_(0,"i",_dummy)
	              : add1(sym_(11,"i",_dummy),for1,_dummy), sym_(0,"i",_dummy))
	 if (setjmp(for1J)==0) goto For1;
	 goto For1Exit; /* bypass block */
For1: /* FOR loop entry point */
	 do { 
	 LineNumber=3;
	 if (sym_(11,"i",tmp0)==NULL) VariableNotFound(LineNumber);
	 strmove(gtmpL,"^a\xce");
	 strcat(gtmpL,tmp0);
	 strcat(gtmpL,"\xcf");
	 if (sym_(11,"i",tmp0)==NULL) VariableNotFound(LineNumber);
	 f=Mglobal(STORE,gtmpL,tmp0);
	 strmove(for2_init,"0");
	 strmove(for2_incr,"1");
	 strmove(for2_lim,"9");
	 if (strchr(for2_incr,'.')) { 
	     for2D=atof(for2_incr);
	     for2F=for2D<0.0 ? 1 : 0;
	     for2T=1;
	     }
	 else { 
	     for2=atol(for2_incr); 
	     for2F=for2<0 ? 1 : 0;
	     for2T=0;
	     } /* increment */
	 for ( sym_(0,"j",for2_init);        /* initialize loop variable */
	       for2F ? numcomp(sym_(11,"j",_dummy),for2_lim)>=0: /* limit expression */
	                numcomp(sym_(11,"j",_dummy),for2_lim)<=0; /* select compare method */
	       for2T ? add3(sym_(11,"j",_dummy),for2D,_dummy), sym_(0,"j",_dummy)
	              : add1(sym_(11,"j",_dummy),for2,_dummy), sym_(0,"j",_dummy))
	 if (setjmp(for2J)==0) goto For2;
	 goto For2Exit; /* bypass block */
For2: /* FOR loop entry point */
	 do { 
	 LineNumber=3;
	 if (sym_(11,"i",tmp0)==NULL) VariableNotFound(LineNumber);
	 if (sym_(11,"j",tmp1)==NULL) VariableNotFound(LineNumber);
	 strmove(gtmpL,"^a\xce");
	 strcat(gtmpL,tmp0);
	 strcat(gtmpL,"\xd0");
	 strcat(gtmpL,tmp1);
	 strcat(gtmpL,"\xcf");
	 if (sym_(11,"j",tmp0)==NULL) VariableNotFound(LineNumber);
	 f=Mglobal(STORE,gtmpL,tmp0);
	 } while (0); longjmp(for2J,99); /* FOR loop 2 close */
For2Exit:
	 } while (0); longjmp(for1J,99); /* FOR loop 1 close */
For1Exit:
/*=================================================================================*/
LineNumber=4; //       w $n(^a(-1)),!
/*=================================================================================*/
	 if (out_file[io]==NULL) ErrorMessage("Write to input file",LineNumber);
	 mult1("1",-1,tmp0);
	 g=2;
	 strmove(gtmp,"^a\x01");
	 strcatx(gtmp,tmp0);
	 strmove(tmp1,gtmp);
	 f=Mglobal(g,tmp1,tmp2); 
	 if (g==RETRIEVE && f==0)  VariableNotFound(LineNumber);
	 hor[io]+=fprintf(out_file[io],"%s",tmp2);
	 fprintf(out_file[io],"\n"); hor[io]=0; ver[io]++;
/*=================================================================================*/
LineNumber=5; //       w $n(^a(0,-1)),!
/*=================================================================================*/
	 if (out_file[io]==NULL) ErrorMessage("Write to input file",LineNumber);
	 mult1("1",-1,tmp0);
	 g=2;
	 strmove(gtmp,"^a\x01");
	 strcatx(gtmp,"0");
	 strcatx(gtmp,tmp0);
	 strmove(tmp1,gtmp);
	 f=Mglobal(g,tmp1,tmp2); 
	 if (g==RETRIEVE && f==0)  VariableNotFound(LineNumber);
	 hor[io]+=fprintf(out_file[io],"%s",tmp2);
	 fprintf(out_file[io],"\n"); hor[io]=0; ver[io]++;
/*=================================================================================*/
LineNumber=6; //       w ^a(0),!
/*=================================================================================*/
	 if (out_file[io]==NULL) ErrorMessage("Write to input file",LineNumber);
	 g=0;
	 strmove(gtmp,"^a\x01");
	 strcatx(gtmp,"0");
	 strmove(tmp0,gtmp);
	 f=Mglobal(g,tmp0,tmp1); 
	 if (g==RETRIEVE && f==0)  VariableNotFound(LineNumber);
	 hor[io]+=fprintf(out_file[io],"%s",tmp1);
	 fprintf(out_file[io],"\n"); hor[io]=0; ver[io]++;
/*=================================================================================*/
LineNumber=7; //       w ^a(0,0),!
/*=================================================================================*/
	 if (out_file[io]==NULL) ErrorMessage("Write to input file",LineNumber);
	 g=0;
	 strmove(gtmp,"^a\x01");
	 strcatx(gtmp,"0");
	 strcatx(gtmp,"0");
	 strmove(tmp0,gtmp);
	 f=Mglobal(g,tmp0,tmp1); 
	 if (g==RETRIEVE && f==0)  VariableNotFound(LineNumber);
	 hor[io]+=fprintf(out_file[io],"%s",tmp1);
	 fprintf(out_file[io],"\n"); hor[io]=0; ver[io]++;
/*=================================================================================*/
LineNumber=8; //       w $n(^a(0)),!
/*=================================================================================*/
	 if (out_file[io]==NULL) ErrorMessage("Write to input file",LineNumber);
	 g=2;
	 strmove(gtmp,"^a\x01");
	 strcatx(gtmp,"0");
	 strmove(tmp0,gtmp);
	 f=Mglobal(g,tmp0,tmp1); 
	 if (g==RETRIEVE && f==0)  VariableNotFound(LineNumber);
	 hor[io]+=fprintf(out_file[io],"%s",tmp1);
	 fprintf(out_file[io],"\n"); hor[io]=0; ver[io]++;

//=================================================================================
_epilogue: tmp0[0]=0; tmp1[0]=0;  /*  Function Epilogue */
#ifndef _MSC_VER
	 Mltoa(getpid(),atmp);
	 cleanLocks("",atmp);
#endif
	 Mglobal(GCLOSE,tmp0,tmp1);  /* Close Globals */
#ifndef _MSC_VER
	 if (SymLoadFlg) SysDump((long) getppid()); /* dump symbol table */
#else
	 if (SymLoadFlg) SysDump((long) 999L); /* dump symbol table */
#endif
	 return 0; }  /* Terminate */
//=================================================================================



int _label_lookup(char *label) { return -1; }
char * _text_function(int disp) { return NULL; }

