static    char    sccsid[]="%Z% %M% %I% %E% %U%";
/********************************************************************/
/* <clprdeftype.c>                                                  */
/*      Define process   　                          */
/*                                            (2009/05/17 Ver 0.01) */
/********************************************************************/

#include "colmn.h"

extern condList CLcList;
extern CLPRTBL  *pGLprocTable;
extern CLPRTBL  *pCLprocTable;
extern GlobalCt *pGlobTable;
extern CLCOMMON CLcommon;
extern int giOptions[];
extern char cmp_sep2[];

#if 1	/* 2020.10.25 */
static char *gsep=" \t(){}[],'=+-*/&|";
#else
static char *gsep=" \t(){}[],'=";
#endif

/************************************/
/*	cl_get_def_attr_check			*/
/************************************/
int cl_get_def_attr_check(nparm,ppParm,iParm,opt)
int nparm;
tdtInfoParm *ppParm[];
int iParm[];
int opt;
{
	static char *name="cl_get_def_attr_check";
	int rc,n,attr,size,opt2;
	int dec_pre,dec_sca;
	char *p0;

	dec_pre = dec_sca = 0;
	attr = iParm[0];
	size = iParm[1];
	if (attr == DEF_ZOK_DECI) {
		rc = cl_get_parm_bin(ppParm[0],&dec_pre,"cl_get_def_attr_check: ");
		if (rc) {
			p0 = NULL;
			if ((rc=parm_to_char(ppParm[0],&p0,NULL)) < 0) return rc;
			/* %s: 精度(%s)が誤っています。rc=%d */
			ERROROUT3(FORMAT(463),name,p0,rc);
			return ECL_SCRIPT_ERROR;
		}
		if (dec_pre<=0 || dec_pre>m_get_nmpa10()) {
			/* %s: 精度(%d)が誤っています。 */
			ERROROUT2(FORMAT(464),name,dec_pre);
			return ECL_SCRIPT_ERROR;
		}
		if (nparm >= 2) {
			rc = cl_get_parm_bin(ppParm[1],&dec_sca,"cl_get_def_attr_check: ");
			if (rc) {
				p0 = NULL;
				if ((rc=parm_to_char(ppParm[1],&p0,NULL)) < 0) return rc;
				/* %s: 位取り(%s)が誤っています。rc=%d */
				ERROROUT3(FORMAT(475),name,p0,rc);
				return ECL_SCRIPT_ERROR;
			}
			if (X_ABS(dec_sca) > dec_pre) {
				/* %s: 位取り(%d)が誤っています。 */
				ERROROUT2(FORMAT(476),name,dec_sca);
				return ECL_SCRIPT_ERROR;
			}
		}
	}
	else {
		opt2 = opt & 0x02;
		if (opt2 || (attr==DEF_ZOK_CHAR || attr==DEF_ZOK_BULK)) {
			rc = cl_get_parm_bin(ppParm[0],&size,"cl_get_def_attr_check: ");
			if (rc) {
				p0 = NULL;
				if ((rc=parm_to_char(ppParm[0],&p0,NULL)) < 0) return rc;
				/* %s: サイズ(%s)が誤っています。rc=%d */
				ERROROUT3(FORMAT(461),name,p0,rc);
				return ECL_SCRIPT_ERROR;
			}
			if (size <= 0) {
				/* %s: サイズ(%d)が誤っています。 */
				ERROROUT2(FORMAT(462),name,size);
				return ECL_SCRIPT_ERROR;
			}
		}
	}
	iParm[1] = size;
	iParm[2] = dec_pre;
	iParm[3] = dec_sca;
/*
printf("%s: attr=%d size=%d dec_pre=%d dec_sca=%d\n",name,attr,size, dec_pre,dec_sca);
*/
	return 0;
}

/************************************/
/*	_get_def_attr					*/
/************************************/
static int _get_def_attr(line0,llen,iParm,opt,bxobj,Obj)
char *line0;
int   llen;
int   iParm[];
int   opt;
GXObject *bxobj[];
tdtRbChain *Obj;
{
	int rc,nparm,attr,opt1;
	char *line;
	tdtInfoParm *ppParm[2],tInfoParm2[2],*pInfoParm;

	line = line0;
/*
printf("_get_def_attr: llen=%d line=[%s]\n",llen,line);
*/
	if (*line == '(') {
		line++;
		llen -=2 ;
	}
	nparm = rc = 0;
	attr = iParm[0];
/*
	iParm[2] = 0;
	iParm[3] = 0;
*/
	if ((opt & 0x02) || attr==DEF_ZOK_CHAR || attr==DEF_ZOK_BULK || attr==DEF_ZOK_DECI) {
		iParm[2] = 0;
		iParm[3] = 0;
		opt1 = (opt & D_GX_OPT_GET_DEF_ATTR) | D_GX_OPT_PARMINFO2;
		rc = cl_gx_expsn_obj_opt(line,llen,bxobj,Obj,tInfoParm2,opt1);
		if (rc) {
			/* %s: 長さ、または、精度、位取りの指定(%s)が誤っています。rc=%d */
			ERROROUT3(FORMAT(478),"_get_def_attr",strtemp(line,llen),rc);
			return ECL_SCRIPT_ERROR;
		}
		else {
			if (nparm=tInfoParm2[1].pi_pos) {
				if (!(rc=tInfoParm2[1].pi_hlen)) {
					pInfoParm = (tdtInfoParm *)tInfoParm2[1].pi_data;
					ppParm[0] = pInfoParm;
					if (nparm >= 2) {
						ppParm[1] = pInfoParm + 1;
						nparm = 2;
					}
				}
			}
			else {
				ppParm[0] = tInfoParm2;
				nparm = 1;
			}
			if (!rc) rc = cl_get_def_attr_check(nparm,ppParm,iParm,opt);
		}
	}
	return rc;
}

/************************************/
/*	cl_get_def_attr_opt				*/
/************************************/
int cl_get_def_attr_opt(varnam,vnlen,iParm,opt,bxobj,Obj)
char *varnam;
int   vnlen;
int   iParm[];
int   opt;
GXObject *bxobj[];
tdtRbChain *Obj;
{
	int rc,len,attr,size,line_len,iGET;
	qSubCommand *sc;
	char *line;
/*
printf("cl_get_def_attr_opt: vnlen=%d varnam=[%s]\n",vnlen,varnam);
*/
	iGET = 0;
	if (varnam && vnlen>0) {
		attr = 0;
		size = sizeof(tdtInfoParm *);
		len = akxnskipto(varnam,vnlen,"(");
		if (sc=cl_get_name_attr2(varnam,len,0x01,0x20)) {
			size = sc->size;
			attr = sc->attr;
			if ((opt & 0x01) && (attr==DEF_ZOK_CHAR || attr==DEF_ZOK_BULK)) size = 0;
		}
		iParm[0] = attr & DEF_ZOK_MASK;	/* add & DEF_ZOK_MASK 2021.11.4 */
		iParm[1] = size;
		iParm[2] = 0;
		iParm[3] = attr & DEF_ZOK_USMASK;	/* add 2021.11.4 */
		if (iParm[0]==DEF_ZOK_BINA && (cl_get_option(17,0) & 0x100))
			iParm[3] |= DEF_ZOK_USMASK;
		line     = varnam + len;
		line_len = vnlen - len;
		if (vnlen > len) iGET = 1;
	}
	else {
		line     = "";
		line_len = 0;
		if (bxobj && bxobj[0]) iGET = 1;
	}
	rc = 0;
	if (iGET) {
	/*	rc = _get_def_attr(varnam+len,vnlen-len,iParm,opt,bxobj,Obj);	*/
		rc = _get_def_attr(line,line_len,iParm,opt,bxobj,Obj);
	}
	return rc;
}

/************************************/
/*	cl_set_parm_init				*/
/************************************/
int cl_set_parm_init(pInfoParm,iParm,opt)
tdtInfoParm *pInfoParm;
int iParm[],opt;
{
	int rc,attr,size,im;
	char *p;

	size = iParm[1];
	switch (attr=iParm[0]) {
		case 0:					/* add 2021.12.31 */
		case DEF_ZOK_VARI:
			rc = cl_parm_set0(pInfoParm);
			break;
		case DEF_ZOK_CHAR:
			rc = cl_set_parm_char(pInfoParm,NULL,0);
			break;
		case DEF_ZOK_BINA:
			rc = cl_set_parm_bin(pInfoParm,0);
			if (iParm[3] == DEF_ZOK_USMASK) pInfoParm->pi_scale |= D_DATA_UNSIGNED;
			break;
		case DEF_ZOK_FLOA:
			rc = cl_set_parm_double(pInfoParm,0.0);
			break;
		case DEF_ZOK_DECI:
		case DEF_ZOK_DATE:
			if (!(rc=cl_set_parm_mpa(pInfoParm,NULL))) {
				pInfoParm->pi_attr = attr;
				pInfoParm->pi_hlen = iParm[2];	/* precision */
				pInfoParm->pi_pos  = iParm[3];	/* scale */
			}
			break;
		case DEF_ZOK_BULK:
			rc = cl_set_parm_char(pInfoParm,NULL,0);
			pInfoParm->pi_attr = attr;
			break;
		default:
			rc = -100;
	}
	if ((opt & 0x01) && attr && (attr!=DEF_ZOK_VARI) && !rc) {
		pInfoParm->pi_len = size;
		pInfoParm->pi_aux[0] = attr;
		if (attr!=DEF_ZOK_BINA && attr!=DEF_ZOK_FLOA) {
			if (attr == DEF_ZOK_CHAR) size++;
			else if (attr == DEF_ZOK_BULK) size += sizeof(int);
			im = (opt & D_GX_OPT_ALC_MASK)>>12;
			if (!im) im = D_OPT_ALC_MALLOC;
			if (im & (D_OPT_ALC_TMP | D_OPT_ALC_MALLOC)) {
				if (p = cl_opt_malloc(im,size)) {
					if ((attr==DEF_ZOK_DECI || attr==DEF_ZOK_DATE) && pInfoParm->pi_data)
						memcpy(p,pInfoParm->pi_data,size);
					else memset(p,0,size);
					if (im == D_OPT_ALC_MALLOC) pInfoParm->pi_scale |= D_DATA_MALLOC;
				}
				else rc = -1;
				pInfoParm->pi_data = p;
			}
			else rc = -1;
		}
		pInfoParm->pi_paux = pInfoParm->pi_data;
	}
DEBUGOUT_InfoParm(151,"cl_set_parm_init: attr=%d rc=%d",pInfoParm,attr,rc);
	return rc;
}

/****************************************/
/*										*/
/****************************************/
int cl_skip_to_delm(s,slen,delms,ssp,sep,level)
char *s,*delms,*sep;
int  slen;
SSPL_S *ssp;
int  level;
{
	char c,delm1,delm2;
	int len;
	int kk_level;	/* ()のネストレベル */

	kk_level = level;
	delm1 = delms[0];
	delm2 = delms[1];
	ssp->wdmax = 0;
	while ((len=akxtgwnsl(s,slen,ssp,sep,0x41)) > 0) {
		if (ssp->attr[0] > 10) {
			c = *ssp->wd;
/*
printf("cl_skip_to_delm: sp=%d c=[%c]\n",ssp->sp,c);
*/
			if (c == delm1) kk_level++;
			else if (c == delm2) {
				if (kk_level > 0) {
					kk_level--;
					if (!kk_level) break;
				}
				else return -2;
			}
		}
	}
	if (len < 0) kk_level = len;
/*
printf("cl_skip_to_delm: sp=%d kk_level=%d\n",ssp->sp,kk_level);
*/
	return kk_level;
}

/****************************************/
/*										*/
/****************************************/
int clpeeksl(s,slen,ssp,sep,opt)
char *s,*sep;
int  slen,opt;
SSPL_S  *ssp;
{
	int sp,len;

	if (!ssp) return -1;

	sp = ssp->sp;
	len = akxtgwnsl(s,slen,ssp,sep,opt);
	ssp->sp = sp;
	return len;
}

/************************************/
/*	cl_get_def_attr_SSP_opt_sub		*/
/*  OUT : ssp->sp : int,dec(p,q)等、または、それ以外の1ワードを読み込んだ位置 */
/************************************/
int cl_get_def_attr_SSP_opt_sub(s,slen,ssp,sep,iParm,opt,bxobj,Obj)
char *s;
int   slen;
SSPL_S *ssp;
char  *sep;
int   iParm[];
int   opt;	/* 0x01:size=0, 0x02:int(n), 0x04:only error when (, 0x08: error when no attr */
GXObject *bxobj[];
tdtRbChain *Obj;
{
	static char *_fn_="cl_get_def_attr_SSP_opt";
	int rc,len,pos,wdmax_save;
	int attr,size,dec_pre,dec_sca;
	qSubCommand *sc;
	char *line,*attr_name,*wrk,c,*wd_save;
/*
printf("cl_get_def_attr_SSP_opt_sub:Enter ssp->sp=%d\n",ssp->sp);
*/
	if ((!s || slen<=0) && (bxobj && bxobj[0])) {
		return _get_def_attr("",0,iParm,opt,bxobj,Obj);
	}
	rc = 0;
	attr = dec_pre = dec_sca = 0;
	size = sizeof(tdtInfoParm *);
	iParm[0] = 0;
	iParm[1] = size;
	iParm[2] = 0;
	iParm[3] = 0;
	wd_save = ssp->wd;
	wdmax_save = ssp->wdmax;
	ssp->wdmax = 0;
	len = akxtgwnsl(s,slen,ssp,sep,0x1);
	attr_name = ssp->wd;
/*
printf("cl_get_def_attr_SSP_opt_sub:1 ssp->sp=%d\n",ssp->sp);
*/
	if (len>0 && (((c=*attr_name)>='A' && c<='Z') || (c>='a' && c<='z') || (opt & 0x08))) {
		if (sc=cl_get_name_attr2(attr_name,len,0x01,0x20)) {
			size = sc->size;
			attr = sc->attr;
			if ((opt & 0x01) && (attr==DEF_ZOK_CHAR || attr==DEF_ZOK_BULK)) size = 0;
			iParm[0] = attr & DEF_ZOK_MASK;	/* add & DEF_ZOK_MASK 2021.11.4 */
			iParm[1] = size;
			iParm[3] = attr & DEF_ZOK_USMASK;	/* add 2021.11.4 */
		}
		if ((opt & 0x08) && !sc) goto AttrErr;
		else if (sc || ((opt & 0x04) && !sc)) {
			clpeeksl(s,slen,ssp,sep,0x41);
/*
printf("cl_get_def_attr_SSP_opt_sub:2 ssp->sp=%d\n",ssp->sp);
*/
			if (*ssp->wd == '(') {
				if (!sc) goto AttrErr;
				if ((opt & 0x02) ||
				    (attr==DEF_ZOK_CHAR || attr==DEF_ZOK_DECI || attr==DEF_ZOK_BULK)) {
					pos = ssp->sp;
					line = s + pos;
					if (rc=cl_skip_to_delm(s,slen,"()",ssp,sep,0)) {
						/* %s: カッコが閉じていません。 */
						ERROROUT1(FORMAT(433),_fn_);
						rc = ECL_SCRIPT_ERROR;
					}
					else {
						rc = _get_def_attr(line,ssp->sp-pos,iParm,opt|D_GX_OPT_GET_DEF_ATTR,bxobj,Obj);
					}
				}
			}
		}
	}
	else if (opt & 0x08) {
		/* %s: 属性指定がありません。 */
		ERROROUT1(FORMAT(498),_fn_);
		rc = ECL_SCRIPT_ERROR;
	}
	goto End;
 AttrErr:
	wrk = strname(attr_name,len);
	/* %s: 属性が誤っています。attr=[%s] */
	ERROROUT2(FORMAT(477),_fn_,wrk);
	rc = ECL_SCRIPT_ERROR;
 End:
	ssp->wd = wd_save;
	ssp->wdmax = wdmax_save;
	return rc;
}

/************************************/
/*	cl_get_def_attr_SSP_opt			*/
/************************************/
int cl_get_def_attr_SSP_opt(s,slen,ssp,sep,iParm,opt,bxobj,Obj)
char *s;
int   slen;
SSPL_S *ssp;
char  *sep;
int   iParm[];
int   opt;	/* 0x01:size=0, 0x02:int(n), 0x04:only error when (, 0x08: error when no attr */
GXObject *bxobj[];
tdtRbChain *Obj;
{
	int rc,spw,iParm2[8];

	rc = cl_get_def_attr_SSP_opt_sub(s,slen,ssp,sep,iParm,opt,bxobj,Obj);
	if (!rc && iParm[0]>0) {
		spw = ssp->sp;
		if (rc=cl_get_def_attr_SSP_opt_sub(s,slen,ssp,sep,iParm2,0,NULL,Obj)) return rc;
		else if (iParm2[0] > 0) {
			ERROROUT1(FORMAT(365),FORMAT(588));	/* データ型指定が重複しています。 */
			rc = ECL_DUPLICATE;
		}
		else ssp->sp = spw;
	}
	return rc;
}

/************************************/
/*	cl_get_def_attr_SSP				*/
/************************************/
int cl_get_def_attr_SSP(s,slen,ssp,sep,iParm,bxobj,Obj)
char *s;
int   slen;
SSPL_S *ssp;
char  *sep;
int   iParm[];
GXObject *bxobj[];
tdtRbChain *Obj;
{
	return cl_get_def_attr_SSP_opt(s,slen,ssp,sep,iParm,0x01,bxobj,Obj);
}

/************************************/
/*	cl_im_parmset					*/
/************************************/
int cl_im_parmset(im,qprmp,pp,len)
int  im;
parmList *qprmp[];
char *pp;
int  len;
{
	parmList *prmp;
	char *p;
	int rc;

	if (!(p=cl_opt_malloc(im,sizeof(parmList)+len+1))) return ECL_MALLOC_ERROR;
	prmp = (parmList *)p;
	memset(prmp,0,sizeof(parmList));
	p += sizeof(parmList);
	memzcpy(p,pp,len);
/*
printf("cl_im_parmset: n=%d len=%d wd=[%s]\n",n,len,p);
*/
	prmp->prp = p;
	prmp->prmlen = len;
	qprmp[0] = prmp;
	return 0;
}

/************************************/
/*	cl_im_parmcpy					*/
/************************************/
int cl_im_parmcpy(im,qprmp,prmp0)
int  im;
parmList *qprmp[],*prmp0;
{
	int rc;
	parmList *prmp;

	if (rc=cl_im_parmset(im,qprmp,prmp0->prp,prmp0->prmlen)) return rc;
	prmp = qprmp[0];
	prmp->opt = prmp0->opt;
	prmp->bxobj = prmp0->bxobj;
/*
printf("cl_im_parmcpy: bxobj=%08x\n",prmp->bxobj);
*/
	return 0;
}

/************************************/
/*	_parmset						*/
/************************************/
static int _parmset(qprmp,nmax,n,pp,len)
parmList *qprmp[];
int   nmax,n;
char *pp;
int  len;
{
	int rc;

	if ((rc=cl_im_parmset(D_OPT_ALC_TMP,&qprmp[n],pp,len)) >= 0) rc = n + 1;
	return rc;
}

/********1*********2*********3*********4*********5*********6*********/
/*	cl_get_array_def_parm											*/
/*	(nmax<=0 || !qprmp)のときは、配列定義を読み飛ばす。				*/
/*	復帰するとき、ssp.spは、配列定義の次のワードを読んだ後の位置、	*/
/*	配列定義がないときは、最初にワードを読んだ後の位置、			*/
/*  または、slenを指す。											*/
/********************************************************************/
int cl_get_array_def_parm(s,slen,dlm,ssp,sep,nmax,qprmp,iEQU)
char *s;
int   slen;
char  *dlm;
SSPL_S  *ssp;
char  *sep;
int   nmax;
parmList *qprmp[];
int  *iEQU;
{
	static char *name="cl_get_array_def_parm";
	int len,kk,n,iSET,iRANGE,is,atr0,kk_level,i,atr_gw;
	char c,c1,*p,*pp,wrk[128],k1,k2,wsep[37],*pat;
	parmList *prmp;
	SSPL_S  sspl;
	uchar uc;
/*
printf("%s:Enter: nmax=%d dlm=[%s] sep=[%s]\n",name,nmax,dlm,sep);
printf("%s:Enter: sp=%d slen=%d s=[%s]\n",name,ssp->sp,slen,s);
*/
	/*sep = cmp_sep2;*/	/* 2020.10.25 */
	len = clpeeksl(s,slen,ssp,sep,0x41);
/*
printf("%s: len=%d sp=%d\n",name,len,ssp->sp);
*/
	n = 0;
/*	if (len==4 && !memicmp(pp=ssp->wd,"HASH",4)) {	*/
	if (len > 0) {
		pp = strmem(ssp->wd,len);
/*
printf("%s: wd=%s\n",name,pp);
*/
		if (!stricmp(pp,"HASH")) {
			len = akxtgwnsl(s,slen,ssp,sep,0x41);
			if (n<nmax && qprmp) {
				if ((n=_parmset(qprmp,nmax,n,pp,len)) < 0) {
					return n;
				}
			}
			len = clpeeksl(s,slen,ssp,sep,0x41);
		}
#if 0	/* 2021.5.7 */
		else if (ssp->attr[0] == 1) {
			if (cl_is_yoyakugo(pp)) {
				ERROROUT2(FORMAT(121),name,pp);	/* %s: [%s]は予約語です。 */
				return ECL_EX_DEFINE;
			}
		}
#endif
	}
	if (len <= 0) {
/*
printf("%s:Exit: n=%d sp=%d wd=[%s]\n",name,n,ssp->sp,strmem(ssp->wd,len));
*/
		return n;
	}
	strcpy(p=wsep," \t'+-*/&|");
	p += strlen(p);
	pp = dlm;
	for (i=0;i<30 && (uc=*pp++);i++) {
		if (uc == '`');
		else if ((uc>=' ' && uc<'0') || (uc>'9' && uc <'A') ||
		    (uc>'Z' && uc<'a') || (uc>'z' && uc <0x7f)) *p++ = uc;
	}
	*p = '\0';
	if ((k1=*ssp->wd)=='[' || k1=='(') {
		kk = 1;
		akxtgwnsl(s,slen,ssp,sep,0x41);
		is = ssp->sp;
		if (k1 == '[') k2 = ']';
		else k2 = ')';
		*p++ = k1;
		*p++ = k2;
		strcpy(p,",");
		kk_level = 1;
	}
	else {
		is = ssp->sp;
		kk = 0;
	}
/*
printf("%s: kk=%d wsep=[%s]\n",name,kk,wsep);
*/
	iSET = iRANGE = 0;
	while ((len=akxtgwnsl(s,slen,ssp,wsep,0x41)) > 0) {
/*
printf("%s: n=%d sp=%d wd=[%s]\n",name,n,ssp->sp,strtemp(ssp->wd,len));
*/
		c = *ssp->wd;
		if (kk) {
			if (c == k2) {
				if (kk_level > 0) kk_level--;
				else {
					ERROROUT2("%s: '%c' unmatched.\n",name,c);
						return ECL_EX_DEFINE;
				}
				if (kk_level > 0) continue;
				iSET = ssp->sp;
/*
printf("%s: sp=%d\n",name,ssp->sp);
*/
				if ((len=akxtgwnsl(s,slen,ssp,wsep,0x41)) > 0) {
/*
printf("%s: len=%d sp=%d wd=[%s]\n",name,len,ssp->sp,strmem(ssp->wd,len));
*/
					if (*dlm == '`')
						pat = strname3("`",1,ssp->wd,len,"`",1);
					else
						pat = strname(ssp->wd,len);
/*
printf("%s: pat=[%s]\n",name,pat);
*/
					if (!inistr(dlm,pat)) {
#if 1	/* 2021.5.7 */
						ERROROUT2(FORMAT(567),name,pat);	/* %%s: 余分な文字(%s)があります。 */
#else
						ERROROUT1(FORMAT(171),name);	/* %s: SYNTAXエラー。 */
#endif
						return ECL_EX_DEFINE;
					}
					if (iEQU) *iEQU = ssp->sp;
				}
/*
printf("%s: len=%d sp=%d wd=[%s]\n",name,len,ssp->sp,strmem(ssp->wd,len));
*/
			}
			else if (c == ',') {
				iSET = ssp->sp;
			}
			else {
				if (c == k1) kk_level++;
				continue;
			}
		}
		else {
			if (instrchar("+-*/&|",c) > 0) {
				c1 = *(s+ssp->sp);
/*
printf("%s: c1=[%c]\n",name,c1);
*/
				if (c1 == '=') {
					ERROROUT1(FORMAT(171),name);	/* %s: SYNTAXエラー。 */
					return ECL_EX_DEFINE;
				}
				else if (c1!=' ' && c1!='\t') continue;
				c1 = *(s+ssp->sp-2);
				if (c1!=' ' && c1!='\t') continue;
			}
			if (*dlm == '`')
				pat = strname3("`",1,ssp->wd,len,"`",1);
			else
				pat = strname(ssp->wd,len);
/*
printf("%s: pat=[%s]\n",name,pat);
*/
			if (inistr(dlm,pat)) {
/*
printf("%s: c=[%c]\n",name,c);
*/
				if (c=='=' && n>0) {
					sspl.sp = 0;
					sspl.wd = wrk;
					sspl.wdmax = sizeof(wrk);
					p = stradd(qprmp[n-1]->prp,"=");
					atr0 = cmpgwnsl(p,qprmp[n-1]->prmlen+1,&sspl);
/*
printf("%s: atr0=%d p=[%s]\n",name,atr0,p);
*/
					if (atr0>=71 && atr0<=90) n--;
				}
				if (c == '=') {
					if (iEQU) *iEQU = ssp->sp;
				}
				break;
			}
			pp = s + ssp->sp;
			for (i=ssp->sp;i<slen;i++) {
/*
printf("%s: i=%d c=[%c]\n",name,i,*pp);
*/
				if (instrchar(" \t\n\r,]=",*pp) > 0) break;
				pp++;
			}
			ssp->sp = i;
			iSET = ssp->sp + 1;
		}
		if (n<nmax && qprmp) {
		/*	if (kk) {	*/
				len = iSET - is - 1;
				pp = s + is;
		/*	}
			else pp = ssp->wd;	*/
#if 1	/* 2021.5.7 */
			pp = strmem(pp,len);
			if (!stricmp(pp,"HASH")) {
				ERROROUT2(FORMAT(469),name,pp);	/* %s: \"%s\"の位置が不正です。*/
				return ECL_EX_DEFINE;
			}
			else if (cl_is_yoyakugo(pp)) {
				ERROROUT2(FORMAT(121),name,pp);	/* %s: [%s]は予約語です。 */
				return ECL_EX_DEFINE;
			}
#endif
/*
printf("%s: n=%d sp=%d pp=[%s]\n",name,n,ssp->sp,strmem(pp,len));
*/
			if ((n=_parmset(qprmp,nmax,n,pp,len)) < 0) break;
		}
/*
printf("%s: c=[%c]\n",name,c);
*/
		if (c == k2) break;
		is = iSET;
	}
/*
printf("%s:Exit: n=%d sp=%d\n",name,n,ssp->sp);
*/
	return n;
}

/************************************/
/*	_def_type_mappedarray			*/
/************************************/
static int _def_type_mappedarray(nparm,qprmp,pIndex)
int nparm;
parmList *qprmp[];
tdtArrayIndex *pIndex;
{
	static char *_name_="_def_type_mappedarray";
	int *index,i,rc;

	memset(pIndex,0,sizeof(tdtArrayIndex));
	pIndex->uAttr[0] = DEF_ZOK_VARI;
	pIndex->size = sizeof(tdtInfoParm *);
	index = pIndex->index;
	index[0] = 1;
	index[2] = 0;
	for (i=0;i<=index[0];i++) index[i+3] = 1;
	index[4] = 10;
	index[1] = index[4];
	if (rc = _set_index(0,nparm,qprmp,0,index,_name_)) return rc;
	if (index[3]+index[1]-1 < 0) {
		/* %s: 範囲指定([%d,%d,%d])が配列の最大個数(%d)を超えています。 */
		ERROROUT5(FORMAT(448),_name_,index[1],index[2],index[3],INT_MAX);
		return ECL_SCRIPT_ERROR;
	}
	return 0;
}

/****************************************/
/*	_get_def_member						*/
/*  type = array:						*/
/*		[データ型] 配列型名 配列の定義	*/
/*  type = mappedarray:					*/
/*				   配列型名 配列の定義	*/
/*  type = struct:						*/
/*		[データ型] 変数名   配列の定義	*/
/****************************************/
static int _get_def_member(s,slen,ssp,varlen,pTypeInfo,parmName,type,opt,pos,bxobj,Obj)
char *s;
int  slen;
SSPL_S *ssp;
int  varlen;
tdtInfoParm *pTypeInfo[];
parmList  *parmName[];
int  type,opt,pos;
GXObject *bxobj[];
tdtRbChain *Obj;
{
	static char *_func="_get_def_member";
	int  i,iParmNo,rc,vnlen,attr,len,nparm,n,attr_set,kk,nset,is;
	int  size;
	char c,*varnam,*pp,*p,*argv[6],*name,id;
	tdtInfoParm *pInfoParm,tInfoParm,tInfoParm2[2],tInfoType,*pInfoDef;
	tdtArrayIndex tIndex,*pIndex;
	int *index;
	int dec_pre,dec_sca,iParm[4];
	parmList *pL,**ppPrm,*prmpi,prmW;
	parmList *qprmp[4];
	ProcCT *proc;

	id = 'R';
	if (type == D_AUX0_TYPE_STRUCT) {
		name = FORMAT(465);	/* メンバ名 */
		nset = 3;
	}
	else {
		name = FORMAT(466);	/* 型定義名 */
		if (type == D_AUX0_TYPE_ARRAY) nset = 3;
		else {
			nset = 4;
			id = 'A';
		}
	}

	varnam = ssp->wd;
	vnlen  = varlen;

	/* 項目有無チェック */
	vnlen = akxtpknsl(s,slen,ssp,gsep,0x41);
	if (vnlen<=0 || *varnam==',') {
		ERROROUT2(FORMAT(76),_func,name);	/* %s: %sがありません。 */
		return ECL_EX_DEFINE;
	}

	/* 変数用InfoParmの取得 */
	if (!(pInfoParm=(tdtInfoParm *)Malloc(sizeof(tdtInfoParm)))) return ECL_MALLOC_ERROR;
	cl_parm_set0(pInfoParm);	/* add 2021.12.31 */
	pTypeInfo[0] = pInfoParm;

	/* 属性の取得 */
	if (id == 'R') {	/* MAPPEDARRAYのときは、属性は指定できない */
		is = ssp->sp;
		if (rc=cl_get_def_attr_SSP(s,slen,ssp,gsep,iParm,NULL,NULL)) return rc;
		/* この時点でデータ型の指定がなかったときは、ssp->wdには変数名が入り、*/
		/* ssp->spは変数名の後ろに移動している */
		/* データ型の指定があったときは、その後ろの変数名を読み込む必要がある */
		attr_set = iParm[0];	/* >0 のとき、データ型の指定あり */
#if 1	/* 2021.11.20 */
		if (!attr_set) {
		/*	iParm[0] = DEF_ZOK_VARI;	*/
			proc = cl_search_proc_ct();
			if ((rc=cl_get_def_type(s,slen,ssp,is,proc,NULL,0,iParm,&tInfoType)) < 0) return rc;
			/* この時点でデータ型の指定がなかったときは、ssp->spは元の位置に戻っている */
			attr_set = 1;
			if (!iParm[0]) {
				if (pInfoDef = (tdtInfoParm *)iParm[2]) {
					iParm[0] = pInfoDef->pi_aux[0];
					cl_gx_rep_info_set_ign(pInfoParm,pInfoDef,1);
				}
				else iParm[0] = DEF_ZOK_VARI;
			}
		}
#else
		if (!attr_set) iParm[0] = DEF_ZOK_VARI;
#endif
		else {
			attr = iParm[0];
			size = iParm[1];
			cl_set_parm_init(pInfoParm,iParm,0);
			if (attr != DEF_ZOK_VARI) {
				pInfoParm->pi_aux[0] = attr;
				pInfoParm->pi_len = size;
			}
		}
	}
	else {
		attr_set = 1;	/* ssp->spは変数名の前にあるので、変数名を読み込んで、
							変数名の後に移動させるため */
		iParm[0] = attr = DEF_ZOK_VARI;
		cl_set_parm_init(pInfoParm,iParm,0);
	}
/*
printf("%s: id=[%c] iParm[0]=%d attr_set=%d sp=%d\n",_func,id,iParm[0],attr_set,ssp->sp);
*/
	/* 変数名の取得 */
	if (attr_set) {
		vnlen = akxtgwnsl(s,slen,ssp,gsep,0x41);
		if (vnlen <= 0) {
			ERROROUT2(FORMAT(76),_func,name);	/* %s: %sがありません。 */
			return ECL_EX_DEFINE;
		}
		varnam = ssp->wd;
	}
#if 1
/*
printf("%s: vnlen=%d varnam=[%s]\n",_func,vnlen,strname(varnam,vnlen));
*/
	if ((c=*varnam)=='%' || c=='#') {
		ERROROUT2(FORMAT(125),_func,strname(varnam,vnlen));	/* %s: [%s]が誤っています。*/
		return ECL_EX_DEFINE;
	}
	if (rc=cl_def_chk_name(varnam,vnlen,_func,name)) return rc;
	if (c == '$') {
		varnam++;
		vnlen--;
	}
#endif
	if (!(pL=(parmList *)Malloc(sizeof(parmList)))) return ECL_MALLOC_ERROR;
	parmName[0] = pL;
	pL->prp = Memdup(varnam,vnlen);
	pL->prmlen = vnlen;
	pL->opt = pos;
	if (attr == DEF_ZOK_BULK) size += sizeof(int);
	if (pInfoParm->pi_aux[0])
		pos += ((size+sizeof(int)-1)/sizeof(int))*sizeof(int);
#if 0
/*
printf("varnam=[%s] vnlen=%d\n",pL->prp,vnlen);
*/
	if (rc=cl_def_chk_name(varnam,vnlen,_func,name)) return rc;
#endif

	/* 配列定義の取得 */
	n = cl_get_array_def_parm(s,slen,",",ssp,gsep,nset,qprmp,NULL);
	if (n < 0) return n;
	else if (n>0 || (type==D_AUX0_TYPE_ARRAY || type==D_AUX0_TYPE_MAPPED)) {
		if (id == 'R') {
			if (rc=_def_array(n,qprmp,opt|D_GX_OPT_NOALLOC_INDX,iParm,&tIndex,0,0)) return rc;
		}
		else {
			if (rc=_def_type_mappedarray(n,qprmp,&tIndex)) return rc;
		}
		attr = iParm[0];
		pInfoParm->pi_id   = id;
		pInfoParm->pi_scale = D_DATA_MALLOC | D_DATA_INDEX_FREE;
		pInfoParm->pi_attr = DEF_ZOK_BULK;	/* attr;	*/
		pInfoParm->pi_dlen  = sizeof(tdtArrayIndex);
		if (!(pInfoParm->pi_data = Malloc(sizeof(tdtArrayIndex)))) return ECL_MALLOC_ERROR;
		memcpy(pInfoParm->pi_data,&tIndex,sizeof(tdtArrayIndex));
		if (!(p=Malloc(vnlen+1))) {
			ERROROUT1("%s: Array name area malloc",_func);
			rc = ECL_MALLOC_ERROR;
			goto Error;
		}
		strnzcpy(p,varnam,vnlen);
		pInfoParm->pi_pos = (long)p;
		index = tIndex.index;
		size = tIndex.size;
		if (attr=tIndex.uAttr[0]) {
			if (attr == DEF_ZOK_CHAR) size++;
			else if (attr == DEF_ZOK_BULK) size += sizeof(int);
			len = index[1]*size;
			pos = pL->opt + ((len+sizeof(int)-1)/sizeof(int))*sizeof(int);
		}
		else pos = pL->opt;

DEBUGOUT_InfoParm(194,"cl_pr_ex_def_type: attr=%d size=%d",pInfoParm,attr,size);

/*
len = akxtgwnsl(s,slen,ssp,gsep,0x41);
printf("cl_pr_ex_def_type: len=%d *wd=[%c]\n",len,*ssp->wd);
*/
	}
	return pos;
 Error:
	return rc;
}

/************************************/
/*	cl_pr_ex_def_type				*/
/************************************/
int cl_pr_ex_def_type(prmnum, pprmp, scrct, proc, opt)
int      prmnum;
parmList **pprmp;
ScrPrCT  *scrct;
ProcCT   *proc;
int      opt;
{
	static char *sep=" \t(){}[],'";
	static MCAT mcat={'M','C',256,0,0,0,NULL,0};
	XHASHB *pha_vname,*xhp;
	tdtInfoParm ***pTBL_vname;
	int  i,iParmNo,rc,vnlen,attr,len,nparm,n,attr_set,type,is;
	int  size,pos,slen;
	char c,*varnam,*pp,*p,*argv[6],*s;
	tdtInfoParm *pInfoParm,tInfoParm,tInfoParm2[2];
	tdtArrayIndex tIndex,*pIndex;
	int *index;
	int dec_pre,dec_sca,iParm[4];
	parmList  *parmName[MAX_MEMBER],*pL,**ppPrm,*prmpi,prmW;
	tdtInfoParm *pTypeInfo[MAX_MEMBER];
	tdtDefType *pDeftype;
	int ntype;
	SSPL_S ssp;
	parmList *qprmp[3];

	argv[0] = "cl_pr_ex_def_type";
	/* parameter check */
	/* DEFINE TYPE STRUCT name
	      var_type var_name,
	      var_type var_name;
	   DEFINE TYPE ARRAY var_type var_name;
	   DEFINE TYPE MAPPEDARRAY var_type var_name;	*/
	nparm = 3;
	if (prmnum >= 2) {
		p = pprmp[1]->prp;
		if (!stricmp(p,"ARRAY")) type = D_AUX0_TYPE_ARRAY;
		else if (!stricmp(p,"MAPPEDARRAY")) type = D_AUX0_TYPE_MAPPED;
		else if (!stricmp(p,"STRUCT")) {
			type = D_AUX0_TYPE_STRUCT;
			nparm++;
		}
		else type = -1;
	}
	if (prmnum < nparm) {
		/* %s: パラメータが足りません。prmnum=%d */
		ERROROUT2(FORMAT(467),argv[0],prmnum);
		return ECL_EX_DEFINE;
	}

	is = 2;
	pha_vname = NULL;
	if (type == D_AUX0_TYPE_STRUCT) {
		varnam = pprmp[2]->prp;
		vnlen  = pprmp[2]->prmlen;
		if ((c=*varnam)=='%' || c=='#') {
			ERROROUT2(FORMAT(125),argv[0],strname(varnam,vnlen));	/* %s: [%s]が誤っています。*/
			return ECL_EX_DEFINE;
		}
		if (rc=cl_def_chk_name(varnam,vnlen,argv[0],FORMAT(466))) return rc;	/* 型定義名 */
		is = 3;
	}
	else if (type!=D_AUX0_TYPE_ARRAY && type!=D_AUX0_TYPE_MAPPED) {
		/* %s: 型指定が誤っています。type=[%s] */
		ERROROUT2(FORMAT(468),argv[0],p);
		return ECL_EX_DEFINE;
	}

	ntype = pos = 0;
	s = pprmp[is]->prp;
	slen = pprmp[is]->prmlen;
/*
printf("cl_pr_ex_def_type: type=%d slen=%d s=[%s]\n",type,slen,s);
*/
	memset(&ssp,0,sizeof(SSPL_S));
	if (type==D_AUX0_TYPE_ARRAY || type==D_AUX0_TYPE_MAPPED) {
		if ((vnlen=clpeeksl(s,slen,&ssp,gsep,0x41)) > 0) {
			if ((pos=_get_def_member(s,slen,&ssp,vnlen,&pTypeInfo[0],&parmName[0],type,opt,pos,0,0)) < 0) {
				rc = pos;
				goto Error;
			}
			varnam = parmName[0]->prp;
			vnlen  = parmName[0]->prmlen;
		}
	}
	else {
		while ((vnlen=clpeeksl(s,slen,&ssp,sep,0x41)) > 0) {
			if ((pos=_get_def_member(s,slen,&ssp,vnlen,&pTypeInfo[ntype],&parmName[ntype],type,opt,pos,0,0)) < 0) {
				rc = pos;
				goto Error;
			}
			ntype++;
		}
		varnam = pprmp[2]->prp;
		vnlen  = pprmp[2]->prmlen;
	}
 	if (!(opt & D_GX_OPT_SET_SCOPE)) {
		if (proc) {
			if (!(pGlobTable->options[9] & 0x01) && (scrct->pFlag & D_SCRPT_NEW_LEX))
				opt |= D_GX_OPT_SET_LOCAL;
			else opt |= D_GX_OPT_SET_PRIVATE;
		}
		else opt |= D_GX_OPT_SET_PRIVATE;
	}
	attr = DEF_ZOK_BULK;
	if ((c=*varnam) == '$') {
		varnam++;
		vnlen--;
	}
	if ((rc=_chk_define(scrct,proc,varnam,vnlen,opt,argv)) < 0) return rc;
	pha_vname  = (XHASHB *)argv[4];
	pTBL_vname = (tdtInfoParm ***)argv[5];

	if ((iParmNo=cl_gx_chk_vnam('s',pha_vname,varnam,vnlen)) < 1) {
		/* %s: %sの%sエントリ用の空きがありません。 */
		ERROROUT3(FORMAT(323),argv[0],varnam,argv[3]);
		rc = ECL_SCRIPT_ERROR;
		goto Error;
	}
	pInfoParm = cl_get_var_ent(pTBL_vname,iParmNo);
	if (!pInfoParm) return ECL_SCRIPT_ERROR;

	info_parm_clear(pInfoParm);
	if (type==D_AUX0_TYPE_STRUCT) {
		pInfoParm->pi_scale = D_DATA_MALLOC | D_DATA_INDEX_FREE;
		pInfoParm->pi_attr = attr;
		pInfoParm->pi_dlen = sizeof(tdtDefType);
		pInfoParm->pi_aux[1] |= D_AUX1_PROTECTED;
		if (!(pDeftype=(tdtDefType *)Malloc(sizeof(tdtDefType)))) return ECL_MALLOC_ERROR;
		memset(pDeftype,0,sizeof(tdtDefType));
		pDeftype->size = pos;
		pDeftype->ntype = ntype;
		pInfoParm->pi_data = (char *)pDeftype;
		if (!(pDeftype->vname=(parmList **)Malloc(ntype*sizeof(parmList *)))) return ECL_MALLOC_ERROR;
		memcpy(pDeftype->vname,parmName,ntype*sizeof(parmList *));
		if (!(pDeftype->pType=(tdtInfoParm **)Malloc(ntype*sizeof(tdtInfoParm *)))) return ECL_MALLOC_ERROR;
		memcpy(pDeftype->pType,pTypeInfo,ntype*sizeof(tdtInfoParm *));
		if (!(p=Malloc(vnlen+1))) {
			ERROROUT1("%s: Type def name area malloc",argv[0]);
			rc = ECL_MALLOC_ERROR;
			goto Error;
		}
		strnzcpy(p,varnam,vnlen);
		pInfoParm->pi_pos = (long)p;
	}
	else {
		*pInfoParm = *pTypeInfo[0];
		pInfoParm->pi_aux[1] |= D_AUX1_PROTECTED;
	}
	pInfoParm->pi_id     = 'P';
	pInfoParm->pi_aux[0] = type;
	pInfoParm->pi_len    = ++pGLprocTable->gid;
	i = akxs_xhasl(pGLprocTable->pha_gid,'S',pInfoParm->pi_len,0);
/*
printf("cl_pr_ex_def_type: Store gid=%ld ix=%d\n",pInfoParm->pi_len,i);
*/
#if 1	/* 2021.3.30 */
	pInfoParm->pi_hlen = _get_gid(scrct,proc,opt);
#else
	if (opt & D_GX_OPT_SET_LOCAL) pInfoParm->pi_hlen = proc->ProcGid;
	else if (opt & D_GX_OPT_SET_PRIVATE) pInfoParm->pi_hlen = scrct->ScrGid;
#endif

DEBUGOUT_InfoParm(194,"cl_pr_ex_def_type: attr=%d",pInfoParm,attr,0);

	rc =  0;

 Error:
	return rc;
}

/************************************/
/*	_def_var_array_member			*/
/************************************/
int _def_var_array_member(pParm)
tdtInfoParm *pParm;
{
	tdtArrayIndex *pIndex;
	int *index,attr,size,len,n,iParmW[4],rc;
	char *p,*p0;

DEBUGOUT_InfoParm(170,"_def_var_array_member:Enter:",pParm,0,0);

	if (!(pIndex = (tdtArrayIndex *)Malloc(sizeof(tdtArrayIndex)))) return -1;
	memcpy(pIndex,pParm->pi_data,sizeof(tdtArrayIndex));
	pParm->pi_data = (char *)pIndex;
#if 1	/* 2021.3.1 */
	if (p0=(char *)pParm->pi_pos) {
		if (!(p=Malloc((len=strlen(p0))+1))) {
			ERROROUT("_def_var_array_member: array name area malloc");
			return ECL_MALLOC_ERROR;
		}
		strnzcpy(p,p0,len);
		pParm->pi_pos = (long)p;
	}
#endif
	index = pIndex->index;
	if (index[2] < 0) {	/* HASH */
		if (!(pIndex->xhp = akxs_xhash_new2(0,index[4],0,pIndex->size))) return -9;
	}
	else {
		iParmW[0] = pIndex->uAttr[0];
		iParmW[1] = pIndex->size;
		iParmW[2] = 0;
		if ((size=cl_get_def_alsize(iParmW)) < 0) return size;
		n = index[1];
		if (rc=_def_array_set_init_by_attr(iParmW[0],n,size,pIndex,iParmW)) return rc;
	}
	pParm->pi_hlen = 0;
	pParm->pi_paux = (char *)pParm;	/* コピーされたときに、この配列が有効化をチェックするために保存する */
	return 0;
}

/************************************/
/*	_def_var_struct					*/
/*  作成 : 2020.10.12				*/
/************************************/
int _def_var_struct(pInfoParm,pDeftypeP,pDefname,opt)
tdtInfoParm *pInfoParm;
tdtDefType *pDeftypeP;
char *pDefname;
int opt;
{
	tdtInfoParm *pParm,*pInfoP,**pTypeD,**pTypeS;
	tdtDefType *pDeftype,*pDef;
	parmList  **parmName;
	int  j,rc,ntype,attr,size,type;
	char id,*p,*p1,*p0;
	uchar uAux0;

DEBUGOUT_InfoParm(170,"_def_var_struct:Enter: pDefname=[%s] opt=%08x",pInfoParm,nval(pDefname),opt);
DEBUGOUTL1(170,"_def_var_struct: pDeftypeP=%08x",pDeftypeP);
/*
printf("_def_var_struct:Enter: pDefname=[%s]\n",nval(pDefname));
*/
	pInfoParm->pi_id = 'T';
	pDeftype = (tdtDefType *)pInfoParm->pi_data;
	ntype = pDeftype->ntype;
	parmName = pDeftype->vname;
	pTypeS = pDeftypeP->pType;
	if (!(pDeftype->pType=(tdtInfoParm **)Malloc(ntype*sizeof(tdtInfoParm *)))) return -1;
/*	if (!(pTypeD=(tdtInfoParm **)Malloc(ntype*sizeof(tdtInfoParm *)))) return -1;*/
	rc = 0;
	for (j=0;j<ntype;j++) {
		if (!(pParm=(tdtInfoParm *)Malloc(sizeof(tdtInfoParm)))) return -1;
		pDeftype->pType[j] = pParm;
	/*	pInfoP = pDeftypeP->pType[j];	*/
		pInfoP = pTypeS[j];
DEBUGOUT_InfoParm(170,"_def_var_struct: pInfoP=",pInfoP,0,0);
#if 1	/* 2021.11.23 */
		uAux0 = pInfoP->pi_aux[0];
		if (rc=cl_gx_rep_info_set_ign(pParm,pInfoP,1)) return rc;
		pParm->pi_aux[0] = uAux0;
#else
		cl_gx_copy_info(pParm,pInfoP);
#endif
DEBUGOUT_InfoParm(170,"_def_var_struct: pParm=",pParm,0,0);
		if ((id=pParm->pi_id)=='A' || id=='R') {
			if (rc=_def_var_array_member(pParm)) return rc;
		}
		else if (id == 'P') {
			type = pParm->pi_aux[0];
			pDef = (tdtDefType *)pInfoP->pi_data;
			if (type == D_AUX0_TYPE_STRUCT) {
DEBUGOUTL1(170,"_def_var_struct: pDef=%08x",pDef);
				if (rc=_def_var_struct(pParm,pDef,(char *)pInfoP->pi_pos,opt)) return rc;
			}
			else {
				if (type == D_AUX0_TYPE_ARRAY) {
					pParm->pi_id = 'R';
					if (rc=_def_var_array_member(pParm)) return rc;
				}
				else pParm->pi_id = 'A';
			}
		}
		else if (attr=pParm->pi_aux[0]) {
			if (attr!=DEF_ZOK_BINA && attr!=DEF_ZOK_FLOA) {
				size = pParm->pi_len;
				if (attr == DEF_ZOK_CHAR) size++;
				else if (attr == DEF_ZOK_BULK)
					size += sizeof(int);
				if (p = Malloc(size)) {
					if (attr==DEF_ZOK_DECI || attr==DEF_ZOK_DATE)
						memcpy(p,pParm->pi_data,size);
					else strcpy(p,pParm->pi_data);
					pParm->pi_scale |= D_DATA_MALLOC;
				}
				else rc = -1;
				pParm->pi_data = p;
			}
			pParm->pi_paux = pParm->pi_data;
			pParm->pi_aux[1] &= ~D_AUX1_PROTECTED;
		}
	}
	rc = cl_set_struct_name(pInfoParm,pDefname);
	pInfoParm->pi_hlen = _get_gid(NULL,NULL,opt);
/*
printf("_def_var_struct: rc=%d\n",rc);
*/
	return rc;
}

/************************************/
/*	cl_set_struct_name_len			*/
/************************************/
int cl_get_struct_name_len(pDefname)
char *pDefname;
{
	int pos;

	if (pDefname) {
		if ((pos=instrchar(pDefname,'.')) < 0) return pos;
		else if (pos > 0) {
			pos--;
		}
		else pos = strlen(pDefname);
	}
	else pos = -1;
/*
printf("cl_get_struct_name_len:Exit: pos=%d\n",pos);
*/
	return pos;
}

/************************************/
/*	cl_set_struct_name				*/
/************************************/
int cl_set_struct_name(pInfoParm,pDefname)
tdtInfoParm *pInfoParm;
char *pDefname;
{
	int pos;
	char *p,*p0,*p1;

	if ((pos=cl_get_struct_name_len(pDefname)) >= 0) {
		if (!(p=Malloc(strlen(p1=(char *)pInfoParm->pi_pos)+pos+2))) return ECL_MALLOC_ERROR;
		p0 = p;
		memzcpy(p,pDefname,pos);
		p += pos;
		*p++ = '.';
		strcpy(p,p1);
		pInfoParm->pi_pos = (long)p0;
/*
printf("cl_set_struct_name:Exit: name=[%s]\n",p0);
*/
		pos = 0;
	}
	return pos;
}

/************************************/
/*	cl_def_var_mult					*/
/************************************/
int cl_def_var_mult(cmdobj,prmnum,pprmp,scrct,proc,opt,iParm)
CMDObject *cmdobj;
int      prmnum;
parmList **pprmp;
ScrPrCT  *scrct;
ProcCT   *proc;
int      opt,iParm[];
{
	XHASHB *pha_vname;
	tdtInfoParm ***pTBL_vname;
	int  i,j,k,iParmNo,rc,vnlen,is,ias,ntype,datalen,nvar,rc_srch_equ,pos,pos_var_end;
	int line_len,sp_save,type,vlen,n;
	int check[4],*obj,npr,iob,exec_flg,ipr,ida,ipr_pos,ida_nam,iob_ary;
	int iARRAY,iEQU,iCONST,iSKIP,iSTATIC,iCLEAR,iCOM,iARRAY0,iMAPPED;
	char c,*varnam,*p,id,*argv[6],*line,wrk[128],*pp,*vnam,**da;
	tdtInfoParm *pInfoParm,*pParm,*pInfoDef;
	tdtDefType *pDeftype,*pDeftypeP;
	parmList  **parmName;
	tdtArrayIndex *pIndex;
	int *index,attr,size,len;
	SSPL_S ssp;
	parmList *pPrmp;
	parmList *qprmp3[MAX_ARRAY_DIM+1];
	parmList *qprmp[MAX_ARRAY_DIM+1];
	tdtObjHead *pObj;
	GXObject *bxobj[2];
	uchar ucLOCAL;

	argv[0] = "cl_def_var_mult";
/*
printf("%s: Enter opt=%08x iParm=%d %d %08x %d\n",
argv[0],opt,iParm[0],iParm[1],iParm[2],iParm[3]);
*/
	type = iParm[0];
	pDeftypeP = NULL;
#if defined(_LP64)	/* 2021.2.13 */
	memcpy(&p,iParm+2,sizeof(char *));
	if (!type && p) {
		if (pInfoDef = (tdtInfoParm *)p) {
#else
	if (!type && iParm[2]) {
		if (pInfoDef = (tdtInfoParm *)iParm[2]) {
#endif
			pDeftypeP = (tdtDefType *)pInfoDef->pi_data;
			type = pInfoDef->pi_aux[0];
		}
	}

	line = pprmp[0]->prp;
	line_len = pprmp[0]->prmlen;
	memset(&ssp,0,sizeof(SSPL_S));

	iob = cmdobj->nobj;
	ida = cmdobj->nda;
	obj = cmdobj->exobj;
	da  = cmdobj->da;
	pos         = iParm[6];
	pos_var_end = iParm[7];
	npr         = iParm[8];
	ipr_pos     = iParm[9];
/*
printf("%s: pos=%d pos_var_end=%d npr=%d ipr_pos=%d iob=%d ida=%d\n",
argv[0],pos,pos_var_end,npr,ipr_pos,iob,ida);
*/
	ssp.sp = pos;
	obj[iob++] = pos;
	nvar = 0;
	iCOM = 1;
	iMAPPED = iARRAY = iCONST = 0;
	if (opt & D_GX_OPT_SET_ARRAY) iARRAY = 1;
	if (opt & D_GX_OPT_SET_MAPPED) {
		iARRAY = iMAPPED = 1;
	}
	if (opt & D_GX_OPT_SET_CONST) iCONST = D_AUX1_PROTECTED;
	iARRAY0 = iARRAY;
	while ((vnlen=akxtgwnsl(line,pos_var_end,&ssp,gsep,0x41)) > 0) {
		is = ssp.sp - vnlen;
		memnzcpy(wrk,ssp.wd,vnlen,sizeof(wrk));
		varnam = wrk;
/*
printf("%s 0: is=%d ssp.sp=%d vnlen=%d varnam=[%s]\n",argv[0],is,ssp.sp,vnlen,varnam);
*/
DEBUGOUTL5(170,"%s 0: is=%d ssp.sp=%d vnlen=%d varnam=[%s]",argv[0],is,ssp.sp,vnlen,varnam);
DEBUGOUTL3(170,"%s 0: ssp.attr[0]=%d iCOM=%d",argv[0],ssp.attr[0],iCOM);

		iSKIP = 0;
		c = *varnam;
		if (instrchar("+-*/&|",c) > 0) {
			if (*(line+ssp.sp) == '=') break;
			iSKIP = 2;
		}
		else if (!stricmp(varnam,"AS") || c=='=') break;
		else if (c == ',') {
			if (iCOM) {
				ERROROUT1(FORMAT(458),argv[0]);	/* %s: 変数名は省略できません。 */
				return ECL_EX_DEFINE;
			}
			iCOM = 1;
			continue;
		}
#if 0	/* これがなくても cl_get_array_def_parm()の中でエラーなるが、念のため残す */
		/* 2021.5.24 これがあると、カンマの後の配列名が「〜がありません」のエラーになるので、
		   また、ここでは、cl_chk_name()ができない(配列名が変数のときがある)ので、削除する。*/
		else if (!iCOM) {
			p = varnam;
			if (c=='$' || c=='%' || c=='#') {
				p++;
				vnlen--;
			}
			if (cl_chk_name(p, vnlen))
				ERROROUT2(FORMAT(125),argv[0],varnam);	/* %s: [%s]が誤っています。*/
			else
				ERROROUT3(FORMAT(540),argv[0],FORMAT(474),varnam);	/* %s: %sがありません。(at %s) カンマ */
			return ECL_EX_DEFINE;
		}
#endif
/*
printf("%s 1: pos=%d vnlen=%d varnam=[%s]\n",argv[0],pos,vnlen,varnam);
*/
DEBUGOUTL3(170,"%s 1: vnlen=%d varnam=[%s]",argv[0],vnlen,varnam);
		iCOM = 0;
		if (c == '(') iSKIP = 1;
		else if (c == '\'') iSKIP = 3;
		else if (!instrchar("()[] \t,",*(line+ssp.sp))) iSKIP = 2;
		else {
			clpeeksl(line,pos_var_end,&ssp,gsep,0x41);
			if (*ssp.wd == '(') {
				len = akxnskipin(varnam,vnlen,"$%#");
				if (len >= vnlen) iSKIP = 1;
			}
		}
		if (iSKIP) {
			if (iSKIP == 1) {
				ssp.sp = is;
				if (len=cl_skip_to_delm(line,pos_var_end,"()",&ssp,gsep,0)) {
					ERROROUT1(FORMAT(433),argv[0]);	/* %s: カッコが閉じていません。 */
					return ECL_SCRIPT_ERROR;
				}
			}
			else { /*if (iSKIP == 2) {*/
				len = akxnskipto(line+ssp.sp,pos_var_end-ssp.sp," \t");
				ssp.sp += len;
			}
			memnzcpy(wrk,line+is,ssp.sp-is,sizeof(wrk));
			varnam = wrk;
			vnlen = strlen(varnam);
/*
printf("%s SKIP: vnlen=%d varnam=[%s] ssp.sp=%d\n",argv[0],vnlen,varnam,ssp.sp);
*/
		}

		cl_im_expand(CLcList.mcat_obj,iob+13,&obj);
		cl_im_expand(CLcList.mcat_da,ida+2,&da);

		/* 変数名の取得 */
		npr++;
		obj[ipr_pos] = iob;
		obj[iob++] = 3;	/* 処理ＩＤ＝変数名取得の処理 */
		ipr_pos = iob++;
		c = *varnam;
		obj[iob++] = ida;
		ida_nam = ida;
		da[ida++] = NULL;	/*clstrdup(varnam,0);*/
		/* 配列名に変数を指定可能とする */
		obj[iob] = ida;	/*-1; 2020.10.28 */
		da[ida] = NULL;
		da[ida_nam] = clstrdup(varnam,0);
/*
printf("%s 2: ida_nam=%d vnlen=%d varnam=[%s] ssp.sp=%d\n",argv[0],ida_nam,vnlen,varnam,ssp.sp);
*/
		nvar++;
		ida++;
		iob++;

		pos = ssp.sp;
		iARRAY = iARRAY0;
		npr++;
		obj[ipr_pos] = iob;
		obj[iob++] = 2;	/* 処理ＩＤ＝配列定義取得の処理 */
		ipr_pos = iob++;

		if (!(opt & D_GX_OPT_REDEFINE) && proc && !iARRAY && !type) {
			clpeeksl(line,line_len,&ssp,gsep,0x41);
			if (*ssp.wd == '[') iARRAY = -1;	/* 配列要素と見なす */
		}
		iob_ary = iob;
		obj[iob++] = iARRAY;	/* 配列定義式処理 */
		n = 0;
		if (iARRAY >= 0) {
			/* 配列定義の取得 */
			n = cl_get_array_def_parm(line,pos_var_end,",=",&ssp,gsep,MAX_ARRAY_DIM,qprmp,NULL);
			if (n < 0) return n;
			else if (n) iARRAY = 1;	/* 配列定義あり */
			else {
				if (iARRAY) {
					if (proc) iARRAY = 2;	/* defineではなくて、arrayがある */
				}
				else iARRAY = -1;	/* arrayも配列定義もない==>変数の定義または式 */
/*
printf("%s: n=%d iARRAY=%d\n",argv[0],n,iARRAY);
*/
			}
			if (iARRAY==2 && (iCLEAR || iCONST || iParm[0]/* || (opt & D_GX_OPT_SET_SCOPE)*/)) iARRAY = 1;
			/* defineではなくて、arrayがあり、clearかconstか属性が指定されている */
			/* ARRAY=1: 配列変数の定義 */
			/* ARRAY=2: 配列変数へのデータ設定 */
#if 0	/* 2021.8.28 */
			if (iARRAY==1 && (type & 0x10) && type!=D_AUX0_TYPE_STRUCT) {
						/* %s: 変数[%s]の配列定義ができない属性(%d)です。 */
				ERROROUT3(FORMAT(473),argv[0],varnam,type);
				return ECL_EX_DEFINE;
			}
#endif
			obj[iob++] = ida;	/* 配列定義 */
			obj[iob++] = n;
			iob_ary = iob;
		/*	if (iARRAY > 0) iARRAY |= iMAPPED;	*/
			obj[iob++] = iARRAY;

			cl_im_expand(CLcList.mcat_da,ida+n,&da);

			for (i=0;i<n;i++) {
				cl_im_parmcpy(D_OPT_ALC_LEAF,&da[ida++],qprmp[i]);
			}
			memcpy(qprmp,&da[ida-n],sizeof(parmList *)*n);
			if (!n) ssp.sp = pos;
		}
		else {
			/* 配列定義を読み飛ばす */
			rc = cl_get_array_def_parm(line,pos_var_end,",=",&ssp,gsep,0,NULL,NULL);
			if (rc < 0) return n;
		}
/*
printf("%s: n=%d iARRAY=%d\n",argv[0],n,iARRAY);
*/
DEBUGOUTL3(170,"%s: n=%d iARRAY=%d",argv[0],n,iARRAY);

		npr++;
		obj[ipr_pos] = iob;
		obj[iob++] = 4;	/* 処理ＩＤ＝変数定義/再定義処理 */
		ipr_pos = iob++;
/*
printf("%s: sp=%d\n",argv[0],ssp.sp);
*/
	}
/*
printf("%s: nvar=%d iARRAY=%d iCOM=%d\n",argv[0],nvar,iARRAY,iCOM);
*/
	if (iCOM) {
		ERROROUT1(FORMAT(458),argv[0]);	/* %s: 変数名は省略できません。 */
		return ECL_EX_DEFINE;
	}
	else if (!nvar) {
		ERROROUT2(FORMAT(111),argv[0],FORMAT(329));	/* %s: %s名が必要です。*/ /* 変数 */
		return ECL_EX_DEFINE;
	}
/*
printf("%s: iob=%d ida=%d obj=%08x da=%08x\n",argv[0],iob,ida,obj,da);
*/
	cmdobj->nobj  = iob;
	cmdobj->nda   = ida;
	cmdobj->exobj = obj;
	cmdobj->da    = da;
	iParm[8] = npr;
	iParm[9] = ipr_pos;
	iParm[10] = nvar;
	iParm[11] = iARRAY;
	iParm[12] = iob_ary;
	return 0;
}

/************************************/
/*	cl_get_def_type					*/
/*  sp_save : データ型名開始位置	*/
/*  エラーまたはデータ型でないときは、ssp.sp=sp_save */
/************************************/
int cl_get_def_type(line,line_len,ssp,sp_save,proc,pbxobj,iERROROUT,iParm,pInfoParm)
char *line;
int line_len,sp_save,iERROROUT,iParm[];
SSPL_S *ssp;
ProcCT   *proc;
GXObject **pbxobj;
tdtInfoParm *pInfoParm;
{
	static char *_fn_="cl_get_def_type";
	int type,len,vnlen,rc,opt;
	char c,*varnam,*pp;
	parmList qprmp;
	tdtInfoParm tInfoParmW,*pInfoParmW;

DEBUGOUTL4(170,"cl_get_def_type:Enter: sp_save=%d iERROROUT=%d line_len=%d line=[%s]",sp_save,iERROROUT,line_len,line);
/*
printf("cl_get_def_type:Enter: sp_save=%d line_len=%d line=[%s]\n",sp_save,line_len,line+sp_save);
*/
	rc = type = 0;
	ssp->sp = sp_save;
	if ((vnlen=akxtgwnsl(line,line_len,ssp,gsep,0x41)) <= 0) {
		if (iERROROUT) {
			ERROROUT1(FORMAT(457),_fn_);	/* %s: 型指定がありません。 */
			rc = ECL_EX_DEFINE;
		}
		goto NotType;
	}
	varnam = clmemdup(ssp->wd,vnlen,3);
	/* 型定義名に変数を指定可能とする */
	c = *varnam;
	if (c=='(' || c=='$') {
		ssp->sp = sp_save;
		if ((len=_get_varname(line,line_len,ssp,proc,pbxobj,&pp)) < 0) {
			rc = len;
			goto NotType;
		}
		else if (len > 0) {
			varnam = pp;
			vnlen = len;
		}
	}
	if (iERROROUT) {
		if (rc=cl_def_chk_name(varnam,vnlen,_fn_,FORMAT(466))) goto NotType;	/* 型定義名 */
	}
	qprmp.prp = varnam;
	qprmp.prmlen = vnlen;

	if (iERROROUT) opt = 0;
	else opt = D_GX_OPT_NOERROR_NDEF | D_GX_OPT_NOEROUT_NDEF | D_GX_OPT_NOHOLD_NDEF;

#if 1	/* 2021.2.6 */
	rc = cl_conv_parm_opt(&qprmp,pInfoParm,opt|D_GX_OPT_SET_ADDR);
	if (pInfoParm->pi_id == 'S') pInfoParmW = (tdtInfoParm *)pInfoParm->pi_pos;
	else pInfoParmW = pInfoParm;
#else
	pInfoParmW = &tInfoParmW;
	rc = cl_conv_parm_opt(&qprmp,pInfoParmW,opt|D_GX_OPT_SET_ADDR);
	if (pInfoParmW->pi_id == 'S') pInfoParmW = (tdtInfoParm *)pInfoParmW->pi_pos;
	cl_gx_copy_info(pInfoParm,pInfoParmW);
#endif
	if (!rc || rc==ECL_DEFINED_ARRAY) {
		if (pInfoParmW->pi_id == 'P') {
			type = pInfoParmW->pi_aux[0];
			if (pInfoParm->pi_id != 'S') {	/* このケースは、有得ないが念のため */
				if (!(pInfoParmW = (tdtInfoParm *)cl_opt_malloc(0,sizeof(tdtInfoParm)))) return ECL_MALLOC_ERROR;
				cl_gx_rep_info_set_ign(pInfoParmW,pInfoParm,1);
			}
			pp = Memdup(line+sp_save,ssp->sp-sp_save);
/*
printf("%s: sp_save=%d ssp.sp=%d pp=[%s]\n",_fn_,sp_save,ssp->sp,pp);
*/
#if defined(_LP64)	/* 2021.2.13 */
			memcpy(iParm+2,&pInfoParmW,sizeof(char *));
			memcpy(iParm+4,&pp,sizeof(char *));
#else
			iParm[2] = (int)pInfoParmW;
			iParm[4] = (int)pp;
#endif
		}
		else {
			if (iERROROUT) {
				/* %s: 型指定が誤っています。type=[%s] */
				ERROROUT2(FORMAT(468),_fn_,varnam);
				rc = ECL_EX_DEFINE;
			}
			goto NotType;
		}
	}
	else {
		if (iERROROUT) {
			if ((rc==ECL_NDEFVAR_ERROR || rc==ECL_NO_DATA_ERROR) && (opt & D_GX_OPT_NOERROR_NDEF)) rc = 0;
		}
		else rc = 0;
		goto NotType;
	}
/*
printf("%s: type=%d\n",_fn_,type);
*/
	return type;
NotType:
	ssp->sp = sp_save;
	return rc;
}

/************************************/
/*	cl_pr_ex_def_var				*/
/************************************/
int cl_pr_ex_def_var(cmdobj, prmnum, pprmp, scrct, proc, opt)
CMDObject *cmdobj;
int      prmnum;
parmList **pprmp;
ScrPrCT  *scrct;
ProcCT   *proc;
int      opt;
{
	XHASHB *pha_vname;
	tdtInfoParm ***pTBL_vname;
	int i,j,k,iParmNo,rc,vnlen,is,ias,ntype,datalen,iCONST,nvar,posa[4],kind;
	int iParm[MAX_ARRAY_DIM+1],check[4],*obj,npr,iob,exec_flg,ipr,ida,ipr_pos,ida_nam,iob_ary;
	int iEQU,line_len,sp_save,pos,iCOM,type,vlen,iARRAY,n,pos_var_end;
	char c,*varnam,*p,id,*argv[6],*line,wrk[128],*pp,*vnam,**da;
	tdtInfoParm *pInfoParm,tInfoParm,*pParm,*pParmIO[2];
	tdtDefType *pDeftype,*pDeftypeP;
	parmList  **parmName;
	tdtArrayIndex *pIndex;
	int *index,attr,size,len;
	SSPL_S ssp;
	parmList qprmp,*pPrmp;
	parmList *qprmp3[4];
	tdtObjHead *pObj;
	GXObject *bxobj[2];
	uchar ucLOCAL;

	argv[0] = "cl_pr_ex_def_var";
	/* parameter check */
	/* DEFINE VAR [GLOBAL|PUBLIC|PRIVATE|LOCAL] var_name AS type; */
	if (prmnum < 1) {
		/* %s: パラメータが足りません。prmnum=%d */
		ERROROUT2(FORMAT(467),argv[0],prmnum);
		return ECL_EX_DEFINE;
	}

	bxobj[0] = bxobj[1] = NULL;
	pha_vname = NULL;
	iCONST = iEQU = 0;
	line = pprmp[0]->prp;
	line_len = pprmp[0]->prmlen;
/*
printf("%s: prmnum=%d line_len=%d line=[%s]\n",argv[0],prmnum,line_len,line);
*/
DEBUGOUTL4(170,"%s: prmnum=%d line_len=%d line=[%s]",argv[0],prmnum,line_len,line);

	if (proc) pObj = proc->Obj;
	else pObj = scrct->Obj;
/*
printf("cl_pr_ex_def_var: proc=%08x scrct=%08x pObj=%08x\n",proc,scrct,pObj);
*/
	memset(&ssp,0,sizeof(SSPL_S));

	if (cmdobj->nobj) goto Exobj;	/* 2020.12.4 暫定対応 */

	if (!(obj=cmdobj->exobj)) cl_im_expand(CLcList.mcat_obj,50,&obj);
	if (!(da=cmdobj->da)) cl_im_expand(CLcList.mcat_da,10,&da);
	npr = ida = 0;
	obj[0] = 0;	/* sub_id */
	obj[1] = 0;	/* npr */
	obj[2] = 3;	/* ipr_pos */
	iob = obj[2];

	/* アクセス属性の取得 */
	exec_flg = 1;
	npr++;
	obj[iob++] = 1;	/* 処理ＩＤ＝属性の取得 */
	ipr_pos = iob++;
	obj[iob++] = ida;	/* 属性指定式処理 */
	da[ida] = NULL;
	check[1] = 0x03;	/* only const,scope */
	if ((rc=cl_get_def_modifier_SSP(line,line_len,&ssp,gsep,check,iParm,NULL,NULL)) < 0) return rc;
	else if (rc > 0) {
		if (check[2] & 0x01) opt &= ~D_GX_OPT_SET_SCOPE;
		opt |= check[3];
		if (!proc && (opt & D_GX_OPT_SET_LOCAL)) {
			ERROROUT1(FORMAT(443),argv[0]);	/* %s: LOCALは指定できません。 */
			return ECL_SCRIPT_ERROR;
		}
		if (opt & D_GX_OPT_SET_CONST) iCONST = D_AUX1_PROTECTED;
		if (iParm[0] > 0) {
			/* %s: \"%s\"の位置が不正です。 */
			ERROROUT2(FORMAT(469),argv[0],cl_get_attr_name(iParm));
			return ECL_SCRIPT_ERROR;
		}
	}
/*
printf("%s: ssp.sp=%d\n",argv[0],ssp.sp);
*/
	/* 代入文のサーチ */
	pos = ssp.sp;
	if ((len=_define_srch_equ(line,line_len,&ssp,posa)) < 0) return len;
	iEQU = posa[0];
	pos_var_end = posa[1];
	kind = posa[2];
	if (len < 0) {
		ERROROUT1(FORMAT(171),argv[0]);	/* %s: SYNTAXエラー。 */
		return ECL_EX_DEFINE;
	}
	iARRAY = 0;
	if (kind & 4) {	/* AS */
		/* データ型または型定義名の取得 */
		sp_save = ssp.sp;
		if (rc=cl_get_def_attr_SSP(line,line_len,&ssp,gsep,iParm,&da[ida],pObj)) return rc;
		type = 0;
		cl_parm_set0(&tInfoParm);
		if (!iParm[0]) {
			if ((type=cl_get_def_type(line,line_len,&ssp,sp_save,proc,&pprmp[0]->bxobj,1,iParm,&tInfoParm)) < 0) return type;
		}
	}
	else {
		iParm[0] = DEF_ZOK_VARI;
		type = 0;
		if (!len) ssp.sp--;
	}
	if (!(opt & D_GX_OPT_SET_SCOPE)) {
		if (proc) {
			if (!(pGlobTable->options[9] & 0x01) && (scrct->pFlag & D_SCRPT_NEW_LEX))
				opt |= D_GX_OPT_SET_LOCAL;
			else opt |= D_GX_OPT_SET_PRIVATE;
		}
		else opt |= D_GX_OPT_SET_PRIVATE;
	}

	ida++;
	memcpy(&obj[iob],iParm,sizeof(int)*6);
	iob += 6;
	obj[iob++] = opt;
	obj[iob++] = iEQU;	/* add 2020.11.3 */
	obj[iob++] = iCONST;

	if ((len=akxtgwnsl(line,line_len,&ssp,gsep,0x41)) < 0) return len;
	else if (*ssp.wd == '=') iEQU = ssp.sp;

	/* 変数の定義 */
	iParm[6] = pos;
	iParm[7] = pos_var_end;
	iParm[8] = npr;
	iParm[9] = ipr_pos;
	cmdobj->nobj  = iob;
	cmdobj->nda   = ida;
	cmdobj->exobj = obj;
	cmdobj->da    = da;
	rc = cl_def_var_mult(cmdobj,prmnum,pprmp,scrct,proc,opt,iParm);
	if (rc < 0) return rc;
	npr     = iParm[8];
	ipr_pos = iParm[9];
	iob = cmdobj->nobj;
	ida = cmdobj->nda;
	obj = cmdobj->exobj;
	da  = cmdobj->da;

	cl_im_expand(CLcList.mcat_obj,iob+4,&obj);
	cl_im_expand(CLcList.mcat_da,ida+1,&da);

	npr++;
	obj[ipr_pos] = iob;
	obj[iob++] = 5;	/* 処理ＩＤ＝代入処理 */
	ipr_pos = iob++;

	npr++;
	obj[ipr_pos] = iob;
	obj[iob++] = 6;	/* 処理ＩＤ＝CONST処理 */
	ipr_pos = iob++;

	npr++;
	obj[ipr_pos] = iob;
	obj[iob++] = 7;	/* 処理ＩＤ＝pInfoParmを返す処理 */
	ipr_pos = iob++;
/*
printf("%s: iob=%d ida=%d da=%08x npr=%d\n",argv[0],iob,ida,da,npr);
*/
	obj[iob++] = ida++;

	obj[1] = npr;

if (DEBUGOUTCHECK(250)) {
for (i=0;i<iob;i++)
DEBUGOUTL2(250,"ARRY: obj[%d]=%d",i,obj[i]);
for (i=0;i<ida;i++)
DEBUGOUTL3(250,"ARRY: da[%d]=0x%08x[%s]",i,da[i],da[i]);
}
	cmdobj->nobj  = iob;
	cmdobj->nda   = ida;
	cmdobj->exobj = (int *)clmemdup(obj,iob*sizeof(int),0);
	cmdobj->da    = (char **)clmemdup(da,ida*sizeof(char *),0);

	if (iEQU && (kind & 2)) {
		memzcpy(wrk,line+posa[3],iEQU-posa[3]);
				/* %s:(W)演算子[%s]は、指定できません。'='と見なします。 */
		ERROROUT2(FORMAT(608),argv[0],wrk);
	}

Exobj:

	rc = cl_pr_ex_def_array_engine(cmdobj,prmnum,pprmp,scrct,proc,opt);
/*
printf("%s: return cl_pr_ex_def_array_engine() rc=%d\n",argv[0],rc);
*/
#if 0
	if (!rc && iEQU) {
		pInfoParm = (tdtInfoParm *)cmdobj->da[ida-1];
/*
printf("cl_pr_ex_def_array: pInfoParm=%08x\n",pInfoParm);
*/
		if (pInfoParm) {
			pprmp[1]->prp = line + iEQU;
			pprmp[1]->prmlen = line_len - iEQU;
			if (proc) pObj = proc->Obj;
			else pObj = scrct->Obj;
			if (rc = _set_array_values(pInfoParm,1,&pprmp[1],pObj)) return rc;
		}
	}
	else
#endif
	if (rc == C_EX_DEF_SCALAR) rc = 0;
	return rc;
}

/****************************************/
/*										*/
/****************************************/
int cl_free_deftype(id,pDeftype)
char id;
tdtDefType *pDeftype;
{
	int i,ntype;
	parmList *pL,**pparmL;
	tdtInfoParm **ppParm,*pInfoParm;

	ntype = pDeftype->ntype;
	if (id == 'P') {
		pparmL = pDeftype->vname;
		for (i=0;i<ntype;i++) {
			pL = *pparmL++;
			Free(pL->prp);
			Free(pL);
		}
		Free(pDeftype->vname);
	}
	ppParm = pDeftype->pType;
	for (i=0;i<ntype;i++) {
		cl_free_info_parm(pInfoParm=*ppParm);
		Free(pInfoParm);
		ppParm++;
	}
	Free(pDeftype->pType);
	return 0;
}

/****************************/
/* _chk_kakko				*/
/****************************/
static int _chk_kakko(stack,j)
SSPL_S *stack;
int j;
{
	int rc;
	long i,jj;
/*
printf("_chk_kakko:Enter: j=%d\n",j);
*/
	if (j<1 || j>6) return -12;
/*
printf("_chk_kakko:Enter: max=%d sp=%d\n",stack->wdmax,stack->sp);
*/
	rc = 0;
	if (j <= 3) {
		jj = j;
		rc = akxs_stack_push(stack,(char *)jj);
	}
	else {
		rc = akxs_stack_peek(stack,(char **)&i);
/*
printf("_chk_kakko:peek i=%d\n",i);
*/
		if (i<1 || i>3) rc = -13;
		else if (i == j-3) rc = akxs_stack_pop(stack,(char **)&i);
		else rc = -11;
	}
	if (rc > 0) rc = 0;
/*
printf("_chk_kakko:Exit: rc=%d\n",rc);
*/
	return rc;
}

int _define_srch_equ(line,line_len,ssp,posa)
char *line;
int line_len,posa[];
SSPL_S *ssp;
{
	static char *_fn_="_define_srch_equ";
	SSPL_S stack,sspl;
	long w[50],j;
	int len,rc,iEQU,pos_var_end,kind,atr0,sp,pos_enzan;
	char c,wrk[128],buf[256];
/*
printf("%s:Enter ssp->sp=%d line_len=%d line=[%s]\n",_fn_,ssp->sp,line_len,line);
*/
	stack.wd = (char *)w;
	akxs_stack_init(&stack,50);
	rc = iEQU = kind = pos_enzan = 0;
	pos_var_end = line_len;
	posa[0] = iEQU;
	posa[1] = pos_var_end;
	posa[2] = 0;
	while ((len=akxtgwnsl(line,line_len,ssp,gsep,0x41)) > 0) {
/*
printf("%s: sp=%d len=%d wd=[%s]\n",_fn_,ssp->sp,len,strtemp(ssp->wd,len));
*/
		if (len == 1) {
			c = *ssp->wd;
			if (j=instrchar("({[)}]",c)) {
				if ((rc=_chk_kakko(&stack,j)) < 0) return rc;
			}
			else if (!stack.sp && c=='=') {
				iEQU = ssp->sp;
				pos_enzan = iEQU - 1;
				if (!kind) pos_var_end = iEQU - 1;
				kind |= 1;
				break;
			}
		}
		if (!stack.sp && *(line+ssp->sp)=='=') {
			sspl.sp = 0;
			sspl.wd = wrk;
			sspl.wdmax = sizeof(wrk);
			memcpy(buf,ssp->wd,len);
			memcpy(buf+len,"=",2);
			atr0 = cmpgwnsl(buf,len+1,&sspl);
/*
printf("%s: atr0=%d buf=[%s]\n",_fn_,atr0,buf);
*/
			if (atr0>=71 && atr0<=90) {
				iEQU = ssp->sp + 1;
				pos_enzan = ssp->sp - len;
				if (!kind) pos_var_end = ssp->sp - len;
				kind |= 2;
				break;
			}
		}
		else if (!stricmp(strtemp(ssp->wd,len),"AS")) {
			if (kind & 4) {
				return ECL_SYNTAX_ERROR;
			}
			pos_var_end = ssp->sp - (len+1);
			kind |= 4;
			sp = ssp->sp;
		/*	break;	*/
		}
	}
	if (kind & 4) ssp->sp = sp;
	posa[0] = iEQU;
	posa[1] = pos_var_end;
	posa[2] = kind;
	posa[3] = pos_enzan;
/*
printf("%s: iEQU=%d pos_var_end=%d kind=%d ssp->sp=%d\n",_fn_,iEQU,pos_var_end,kind,ssp->sp);
*/
	return len;
}
