#pragma ident "@(#) ase.cc 3.0.4 2010.04.01,12:21"
/*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*
名称
	オートマチック　サブフォーム　エディタ
	ASE(Automatic Subform Editor)

  概要
	本プログラムはサブフォーム画面を簡単に作成するために開発された画面設計ツール
	です。
	このツールを使用することで、矛盾のないサブフォーム定義ファイルを作成すること
	が出来ます。
	また、PostgreSQLでの開発をECPGプリプロセッサで行う場合、DBの構造に合わせて
	テーブルを設計することが出来ます。
	aseの画面ファイルから生成する定義ファイル(ファイル名の前にアンダースコアが付
	いている)は、テーブルの各列の型(文字列型、数値型、DATE型、通貨型)、や属性
	(文字列の長さ等)が定義出来、aseのECGPソース生成機能により、自動的にECPGソース
	ファイルを生成します。
	つまり、PstogreSQLのテーブル作成から、DB操作を行うC言語のインターフェースまで
	を ase の画面設計で行うことが出来ます。

	画面ファイルは [source-file-name].def
	画面定義ファイルは _[source-file-name].def
	ECPGソースファイルは [source-file-name].pgc
	SQLファイルは create[source-file-name].sql

	サブフォームライブラリとECPGの混在したコンパイルは以下のコマンドラインで
	行うことが出来ます。makefile に記述します。

	ecpg schdytbl.pgc
	gcc -g -I../libsubform -I/usr/include/postgresql -c schdytbl.c
	gcc -O -o schdytbl schdytbl.o ../libsubform/libsubform.a -lncurses -L/usr/lib/postgresql/lib -lecpg
      
  構文
    ase -c[ 1colums - COLS ] -l[ 3lines - (LINES -1)] subform.def
                                       画面ファイルの幅と高さを指定出来ます。
    ase [ -e -v -x -s -a ] subform.def EGA/VGA/XGA/SXGA/MAX-DISPLAYを確定します。
    ase subform.def                    指定されたファイルの大きさに合わせます。
      
  説明
	s: ラベル、テキストボックス、グリッドの左上を指定します。
	e: グリッドの右下を指定します。
	E: テキストボックスの右下を指定します。
	^E: ラベルの右下を指定します。
	K_IC(Insert-key):DB_TITLE(テーブルの列名)を入力します。
	r: 実行時指定した画面設計ファイルを読み込みます。
	c: サブフォーム定義ファイルを書き込みます。(DB設計があれば.pgcを生成する)
	W: 画面設計ファイルを書き込みます。
	^W: 画面設計ファイルを変換して(_定義ファイル名.def.c)に書き込みます。
	S: コピーを開始する位置を決定します。
	C: コピーを終了する位置を決定します。
	P: ペーストを開始する位置を決定します。
	ESC: ECPキーで直前の開始コマンドのマークを元に戻します。
	.: . の文字で画面を戻します。
	-(L): （ｌ）左詰、（ｔ）テキスト型、（e）編集可能の属性を設定します。
	D: （ｒ）右詰、（ｄ）DATE型、（e）編集可能の属性を設定します。
	R: （ｒ）右詰、（＄）通貨型、（e）編集可能の属性を設定します。
	^R: （ｒ）右詰、（ｎ）Numeric型、（e）編集可能の属性を設定します
	K: （p）ステップの設定を行います
	^K: （k)スキップの設定を行います
	j: カーソルを下に移動します。矢印キーでも可能です。
	k: カーソルを上に移動します。矢印キーでも可能です。
	h: カーソルを左に移動します。矢印キーでも可能です。
	l: カーソルを右に移動します。矢印キーでも可能です。
    
	※基本的に編集属性が設定されます。編集属性をNONEにしたい場合は生成された定義
	  ファイルを手作業で修正してください。EDIT --> NONE
	※新しく追加されたDB_TITLEの項目は{}の中に入力用ウインドウで英数字記述します。
	  DB_TITLEは複数行に渡って記述することが出来ます。
	  例：{Schedule_name:16}{Cmd_line:256}{Update_date}
	  ：と右に数字が無い場合はセルの長さが既定値となります。
	※ECPGソースにおいて、DATE型は基本的にchar型として操作されます。

  多言語化対応
    日本語と英語

  診断
      

  例
	sample.defを参考にしてください。

  参照
	ncurses(5),ecpg(1)
      
  バグ

      
  著者
	Shigeki Ono Copyright(c) 2001/01/10(versoin 1.0.5) - 2006/08/13(version 2.2.2)

      
  現狃犁

*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*X*/

#include "ase.h"

AseEditor *aseeditor;
//AseLocalFiler *asefiler;

static char ehelpbuff[24][80] =
	{" s: appoint it on a label, textbox, the left of the grid.\n",
	" e: end pont of grid position.\n",
	" E: end pont of textbox position.\n",
	"^E: end pont of label position.\n",
	" K_IC(Insert-key):DB_TITLE(table-colume-name) input.\n",
	" r: read of screen-file.\n",
	" c: create to screen-define file.\n",
	" W: write to screen file.\n",
	"^W: write to _filename.def.c-source-file.\n",
	" S: start point of copy position.\n",
	" C: end point of copy position.\n",
	" P: end point of of paste position.\n",
	"ESC: return the mark of a start command just before that with an ESC key.\n",
	" .: return of (.) charcter for edit area.\n",
	" -(L): set of (l t e p)<--->attributes.\n",
	" D: set of (r d e p)attributes.\n",
	" R: set of (r $ e p)attributes.\n",
	"^R: set of (r n e p)attributes.\n",
	" K: set of (l t e k)attributes.\n",
	"^K: set of (r n e k)attributes.\n",
	"  ('r' - RIGHT 'l' - LEFT 'e' - EDIT 'p/k' - STEP/SKIP)\n",
	"  ('t' -> TEXT 'n' -> NUMERIC '$' -> CURRENCY)\n",
	" j:cursor down k:cursor up h:cursor left l:cursor right\n",
	" "
	};

static char jhelpbuff[25][128] =
	{" s: ラベル、テキストボックス、グリッドの左上を指定します。",
	" e: グリッドの右下を指定します。",
	" E: テキストボックスの右下を指定します。",
	" ^E: ラベルの右下を指定します。",
	" K_IC(Insert-key):DB_TITLE(テーブルの列名)を入力します。",
	" r: 実行時指定した画面設計ファイルを読み込みます。",
	" c: サブフォーム定義ファイルを書き込みます。(DB設計があれば.pgcを生成する)",
	" W: 画面設計ファイルを書き込みます。",
	" ^W: 画面設計ファイルを変換して(_定義ファイル名.def.c)に書き込みます。",
	" S: コピーを開始する位置を決定します。",
	" C: コピーを終了する位置を決定します。",
	" P: ペーストを開始する位置を決定します。",
	" ESC: ECPキーで直前の開始コマンドのマークを元に戻します。",
	" .: . の文字で画面を戻します。",
	" -:(l)左詰,(t)テキスト型,(e)編集可能の属性を設定します。",
	" D:(r)右詰,(d)ＤＡＴＥ型,(e)編集可能の属性を設定します。",
	" R:(r)右詰,($)通貨型,(e)編集可能の属性を設定します。",
	" ^R:(r)右詰,(n)Numeric型,(e)編集可能の属性を設定します",
	" K: (p)ステップの設定を行います",
	" ^K: (k)スキップの設定を行います",
	" j: カーソルを下に移動します。矢印キーでも可能です。",
	" k: カーソルを上に移動します。矢印キーでも可能です。",
	" h: カーソルを左に移動します。矢印キーでも可能です。",
	" l: カーソルを右に移動します。矢印キーでも可能",
	" "
	};

	int fulldisplay;
	int readflg;
	int nonopt;
	int dbtitle;

	static int text_num = 0;
	static int KEYCOUNT = 0;

/************************************************************************/
/* NAME      :void helpmsg()*/ 
/* FUNCTION  :ヘルプを表示する*/ 
/*            未使用*/ 
/*            */ 
/*            */ 
/* RETURN    :なし*/
/************************************************************************/
//void AseEditor::ehelpmsg(int x,int y)
static void ehelpmsg(int x,int y)
{
	WINDOW *pvs;
	int ch;
	int i;
	pvs = newwin(26,78,y,x);

	wattron(pvs,A_REVERSE);
	wattroff(pvs,A_REVERSE);
	mvwprintw(pvs,0,0,"+");
	mvwprintw(pvs,0,78,"+");
	mvwprintw(pvs,26,0,"+");
	mvwprintw(pvs,26,78,"+");

	noecho();
	for(i=0;i<24;i++)
		mvwprintw(pvs,i,1,"%s",ehelpbuff[i]);
	wrefresh(pvs);
	wgetch(pvs);
	delwin(pvs);
}

/************************************************************************/
/* NAME      :void jhelpmsg()*/ 
/* FUNCTION  :ヘルプを表示する*/ 
/*            未使用*/ 
/*            */ 
/*            */ 
/* RETURN    :なし*/
/************************************************************************/
//void AseEditor::jhelpmsg(int x,int y)
static void jhelpmsg(int x,int y)
{
	WINDOW *pvs;
	int ch;
	int i;
	pvs = newwin(27,78,y,x);

	wattron(pvs,A_REVERSE);
	wattroff(pvs,A_REVERSE);
	mvwprintw(pvs,0,0,"+");
	mvwprintw(pvs,0,78,"+");
	mvwprintw(pvs,26,0,"+");
	mvwprintw(pvs,26,78,"+");

	noecho();
	for(i=0;i<25;i++)
		mvwprintw(pvs,i,1,"%s",jhelpbuff[i]);
	wrefresh(pvs);
	wgetch(pvs);
	delwin(pvs);
}

//void AseEditor::asehelp(void )
static void asehelp(void )
{
	printf("Usage: ase -c[1 - 174] -l[3 - 78] [MAX screen define file name]\n");
	printf("       ase -a [screen define file name] maximum display\n");
	printf("       ase -e -v -x -s for 80/24-EGA and 97/29-VGA 125/37XGA S-XGA\n");
	printf("Command Reference\n");
	printf(" s: appoint it on a label, textbox, the left of the grid.\n");
	printf(" e: end pont of grid position.\n");
	printf(" E: end pont of textbox position.\n");
	printf("^E: end pont of label position.\n");
	printf(" K_IC(Insert-key):DB_TITLE(table-colume-name) input.\n");
	printf(" r: read of screen-file.\n");
	printf(" c: create to screen-define file.\n");
	printf(" W: write to screen file.\n");
	printf("^W: write to _filename.def.c-source-file.\n");
	printf(" S: start point of copy position.\n");
	printf(" C: end point of copy position.\n");
	printf(" P: end point of of paste position.\n");
	printf("ESC: return the mark of a start command just before that with an ESC key.\n");
	printf(" .: return of (.) charcter for edit area.\n");
	printf("  D: set of (r d e p)attributes.\n");
	printf("  R: set of (r $ e p)attributes.\n");
	printf(" ^R: set of (r n e p)attributes.\n");
	printf("  K: set of (l t e k)attributes.\n");
	printf(" ^K: set of (r n e k)attributes.\n");
	printf("   ('r' -> RIGHT 'l' -> LEFT 'e' -> EDIT 'p/k' -> STEP/SKIP)\n");
	printf("   ('t' -> TEXT 'n' -> NUMERIC '$' -> CURRENCY)\n");
	printf("  j: cursor down.\n");
	printf("  k: cursor up.\n");
	printf("  h: cursor left.\n");
	printf("  l: cursor right.\n");
}

/************************************************************************/
/* NAME      :int input_window()*/ 
/* FUNCTION  :ユーザに入力を促すポップアップウインドウを表示する*/ 
/*            */ 
/*            */ 
/*            */ 
/* RETURN    :なし*/
/************************************************************************/
void *input_window(int x,int y,char *buff,char *msg)
{
	WINDOW *mvs;
	mvs = newwin(5,64,y,x);
	wattroff(mvs,A_REVERSE);
	box(mvs,'|','-');
	mvwprintw(mvs,4,0,"+");
	mvwprintw(mvs,4,63,"+");
	mvwprintw(mvs,1,4,msg);
	wattron(mvs,A_REVERSE);
	mvwprintw(mvs,0,0,"                     Input  Window                              ");

	mvwprintw(mvs,2,4,"                                                     ");
	wrefresh(mvs);

	mvwprintw(mvs,2,4,"                                                     ");
	echo();
	nocbreak();
	nl();

	mvwgetstr(mvs,2,4,buff);

	noecho();
	cbreak();
	/*
	nonl();
	*/


	wrefresh(mvs);

	wattroff(mvs,A_REVERSE);
	noecho();
	delwin(mvs);
	return(NULL);
}

int AseEditor::convlabel(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int sx,sy,ex,ey;
	int flg;
	int cell_length[512];
	char cell_align[512][12];
	char cell_title[512][138];
	char cell_fieldtype[512][12];
	int tmp = 51;

	sprintf(tmpbuff1,"_%s",f);
	if((fp = fopen(tmpbuff1,"w")) == (FILE *)NULL)
	{
		return(-1);
	}

	sx = sy = ex = ey = 0;

	flg = 0;
	k = m = n = 0;
	l = 0;

	fprintf(fp,"#Automatic Subform Editor v3.0.0\n");

	fprintf(fp,"COLS=%d\n",xcol);
	fprintf(fp,"ROWS=%d\n",xrow);

	memset(cell_length,'\n',sizeof(cell_length));
	fprintf(fp,"LABEL_LENGTH=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				cell_length[n] = l;
				l++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				cell_length[n] = l;
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				cell_length[n] = l;
				fprintf(fp,"%d,",cell_length[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	memset(cell_align,0,sizeof(cell_align));
	fprintf(fp,"LABEL_ALIGN=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				sprintf(cell_align[n],"%s","LEFT");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				wrefresh(pt2[j][i].vs);
				sprintf(cell_align[n],"%s","LEFT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"r")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"l")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","LEFT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"c")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","CENTER");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				if(cell_align[n][0] != '-')
					sprintf(cell_align[n],"LEFT");
				fprintf(fp,"%s,",cell_align[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				sx = j;
				sy = i;
				goto skip;
			}
		}
	}
	skip:

	flg = 0;
	k = m = n = 0;
	memset(cell_title,' ',sizeof(cell_title));
	fprintf(fp,"LABEL_TEXT=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				sprintf(cell_title[n],"Label_%d",n+1);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				if(cell_title[n][0] != 'L')
					sprintf(cell_title[n],"%s%d","Label_",n+1);
				fprintf(fp,"%s,",cell_title[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"LABEL_X=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",j+1);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"LABEL_Y=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",i);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
			//2009.08.07 Bug
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	fclose(fp);
	return(0);
}

int AseEditor::convlabel2(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int sx,sy,ex,ey;
	int flg;
	int cell_length[512];
	char cell_align[512][12];
	char cell_title[512][138];
	char cell_fieldtype[512][12];
	int tmp = 51;

	sprintf(tmpbuff1,"_%s.c",f);
	if((fp = fopen(tmpbuff1,"w")) == (FILE *)NULL)
	{
		return(-1);
	}

	sx = sy = ex = ey = 0;

	flg = 0;
	k = m = n = 0;
	l = 0;

	fprintf(fp,"//Automatic Subform Editor v3.0.0\n");
	fprintf(fp,"//以下の関数は定義ファイルを利用しないインターフェースで利用可能\n");
	fprintf(fp,"//他のソースファイルの initscr() 以下の行に挿入して利用可能\n");

	fprintf(fp,"int %s(void)\n",f);
	fprintf(fp,"{\n");

//	fprintf(fp,"COLS=%d\n",xcol);
//	fprintf(fp,"ROWS=%d\n",xrow);
	fprintf(fp,"	static int xcol = %d;\n",xcol);
	fprintf(fp,"	static int rows = %d;\n\n",xrow);

	memset(cell_length,'\n',sizeof(cell_length));
	fprintf(fp,"//for label\n");
	fprintf(fp,"	static int label_length[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				cell_length[n] = l;
				l++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				cell_length[n] = l;
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				cell_length[n] = l;
				fprintf(fp,"%d,",cell_length[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	fprintf(fp,"	static int label_no[] = {");
	for(i=0;i<n;i++)
	{
		fprintf(fp,"%d,",i);
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	memset(cell_align,0,sizeof(cell_align));
	fprintf(fp,"	static int label_align[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				sprintf(cell_align[n],"%s","2");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				wrefresh(pt2[j][i].vs);
				sprintf(cell_align[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"r")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"l")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"c")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","3");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				if(cell_align[n][0] != '-')
					sprintf(cell_align[n],"2");
				fprintf(fp,"%s,",cell_align[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				sx = j;
				sy = i;
				goto skip;
			}
		}
	}
	skip:

	flg = 0;
	memset(cell_title,' ',sizeof(cell_title));
	fprintf(fp,"	static char *label_text[%d][128] = {",n+1);

	k = m = n = 0;
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				sprintf(cell_title[n],"Label_%d",n+1);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				if(cell_title[n][0] != 'L')
					sprintf(cell_title[n],"%s%d","Label_",n+1);
				fprintf(fp,"\"%s\",",cell_title[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"\"\"};\n");

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"	static int label_x[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",j+1);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"	static int label_y[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"("))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",i);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
			//2009.08.07 Bug
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,")"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	fclose(fp);
	return(0);
}

int AseEditor::convtextbox(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int sx,sy,ex,ey;
	int flg;
	int cell_length[512];
	char cell_align[512][12];
	char cell_action[512][12];
	char cell_fieldtype[512][12];
	char cell_skipstep[512][12];
	int tmp = 51;

	sprintf(tmpbuff1,"_%s",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	sx = sy = ex = ey = 0;

	flg = 0;
	k = m = n = 0;
	l = 0;

	memset(cell_length,'\n',sizeof(cell_length));
	fprintf(fp,"TEXTBOX_LENGTH=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				cell_length[n] = l;
				l++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				cell_length[n] = l;
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				cell_length[n] = l;
				fprintf(fp,"%d,",cell_length[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	memset(cell_align,0,sizeof(cell_align));
	fprintf(fp,"TEXTBOX_ALIGN=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				wrefresh(pt2[j][i].vs);
				sprintf(cell_align[n],"%s","LEFT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"r")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"l")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","LEFT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"c")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","CENTER");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				//2009.09.04
				if(strlen(cell_align[n]) == 0)
				{
					sprintf(cell_align[n],"%s","LEFT");
				}
				fprintf(fp,"%s,",cell_align[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);


	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				sx = j;
				sy = i;
				goto skip;
			}
		}
	}
	skip:

	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_action[i],' ',sizeof(cell_action[i]));
	fprintf(fp,"TEXTBOX_ACTION=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				sprintf(cell_action[n],"%s","EDIT");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","EDIT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"e")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","EDIT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"o")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","NONE");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				fprintf(fp,"%s,",cell_action[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_skipstep[i],' ',sizeof(cell_skipstep[i]));
	fprintf(fp,"TEXTBOX_SKIP_STEP=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
			//Bug.2001/01/08
				sprintf(cell_skipstep[n],"%s","STEP");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","STEP");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"p")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","STEP");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"k")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","SKIP");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				fprintf(fp,"%s,",cell_skipstep[n]);
				k++;
				n++;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_fieldtype[i],' ',sizeof(cell_fieldtype[i]));
	fprintf(fp,"TEXTBOX_FIELD_TYPE=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				sprintf(cell_fieldtype[n],"%s","TEXT");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","TEXT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","TEXT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","DATE");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","NUMERIC");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","CURRENCY");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				fprintf(fp,"%s,",cell_fieldtype[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"TEXTBOX_X=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",j);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"TEXTBOX_Y=");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",i);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	fclose(fp);
	return(0);
}

int AseEditor::convtextbox2(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int sx,sy,ex,ey;
	int flg;
	int cell_length[512];
	char cell_align[512][12];
	char cell_action[512][12];
	char cell_fieldtype[512][12];
	char cell_skipstep[512][12];
	int tmp = 51;

	sprintf(tmpbuff1,"_%s.c",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	sx = sy = ex = ey = 0;

	flg = 0;
	k = m = n = 0;
	l = 0;

	memset(cell_length,'\n',sizeof(cell_length));
	fprintf(fp,"//for textbox\n");
	fprintf(fp,"	static int textbox_length[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				cell_length[n] = l;
				l++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				cell_length[n] = l;
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				cell_length[n] = l;
				fprintf(fp,"%d,",cell_length[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	fprintf(fp,"	static int textbox_no[] = {");
	for(i=0;i<n;i++)
	{
		fprintf(fp,"%d,",i);
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	memset(cell_align,0,sizeof(cell_align));
	fprintf(fp,"	static int textbox_align[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				wrefresh(pt2[j][i].vs);
				sprintf(cell_align[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"r")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"l")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"c")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","3");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				//2009.09.04
				if(strlen(cell_align[n]) == 0)
				{
					sprintf(cell_align[n],"%s","2");
				}
				fprintf(fp,"%s,",cell_align[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");


	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				sx = j;
				sy = i;
				goto skip;
			}
		}
	}
	skip:

	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_action[i],' ',sizeof(cell_action[i]));
	fprintf(fp,"	static int textbox_action[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				sprintf(cell_action[n],"%s","0");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","0");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"e")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","0");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"o")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","1");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				fprintf(fp,"%s,",cell_action[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_skipstep[i],' ',sizeof(cell_skipstep[i]));
	fprintf(fp,"	static int textbox_skipstep[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
			//Bug.2001/01/08
				sprintf(cell_skipstep[n],"%s","1");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"p")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"k")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","0");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				fprintf(fp,"%s,",cell_skipstep[n]);
				k++;
				n++;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_fieldtype[i],' ',sizeof(cell_fieldtype[i]));
	fprintf(fp,"	static int textbox_field[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				sprintf(cell_fieldtype[n],"%s","1");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","5");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","4");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				fprintf(fp,"%s,",cell_fieldtype[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"	static int textbox_x[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",j);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	fprintf(fp,"	static int textbox_y[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"<"))
			{
				flg = 1;
				k++;
				fprintf(fp,"%d,",i);
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,">"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");
	fprintf(fp,"\n\n");
	//2010.03.14
	text_num = n;

	fclose(fp);
	return(0);
}

int AseEditor::convgrid(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int sx,sy,ex,ey;
	int flg;
	int cell_length[512];
	char cell_align[512][12];
	char cell_action[512][12];
	char cell_fieldtype[512][12];
	char cell_skipstep[512][12];
	char cell_title[512][138];
	char *coln;
	int tmp = 51;

	sprintf(tmpbuff1,"_%s",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	for(i=0;i<512;i++)
		pgc[i].keyflg = 0;

	KEYCOUNT = 0;

	sx = sy = ex = ey = 0;

	flg = 0;
	k = m = n = 0;
	l = 0;


	memset(cell_length,0,sizeof(cell_length));
	fprintf(fp,"CELL_LENGTH=");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				flg = 1;
				k++;
				cell_length[n] = l;
				l++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				cell_length[n] = l;
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				cell_length[n] = l;
				fprintf(fp,"%d,",cell_length[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	memset(cell_align,0,sizeof(cell_align));
	fprintf(fp,"CELL_ALIGN=");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sprintf(cell_align[n],"%s","LEFT");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				wrefresh(pt2[j][i].vs);
				sprintf(cell_align[n],"%s","LEFT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"r")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"l")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","LEFT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"c")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","CENTER");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","RIGHT");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_align[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"%d\n",0);


	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sx = j;
				sy = i;
				goto skip;
			}
		}
	}
	skip:

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_action[i],' ',sizeof(cell_action[i]));
	fprintf(fp,"CELL_ACTION=");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sprintf(cell_action[n],"%s","EDIT");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","EDIT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"e")) && flg == 1)
			{
			//2009.08.07 Bug?
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				sprintf(cell_action[n],"%s","EDIT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"o")) && flg == 1)
			{
			//2009.08.07 Bug?
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				sprintf(cell_action[n],"%s","NONE");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_action[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_fieldtype[i],' ',sizeof(cell_fieldtype[i]));
	fprintf(fp,"GRID_FIELD_TYPE=");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				if(strlen(cp[j][i].s) < 2)
					sprintf(cell_fieldtype[n],"%s","NUMERIC");
				else
					sprintf(cell_fieldtype[n],"%s","TEXT");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","TEXT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","TEXT");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","DATE");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","NUMERIC");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","CURRENCY");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_fieldtype[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_skipstep[i],' ',sizeof(cell_skipstep[i]));
	fprintf(fp,"GRID_SKIP_STEP=");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sprintf(cell_skipstep[n],"%s","STEP");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","STEP");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"p")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","STEP");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"k")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","SKIP");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_skipstep[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_title[i],' ',sizeof(cell_title[i]));
	fprintf(fp,"GRID_TITLES=");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				flg = 1;
				k++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				sprintf(cell_title[n],"Grid_%d",n+1);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				if(cell_title[n][0] != 'G')
					sprintf(cell_title[n],"%s%d","Grid_",n+1);
				fprintf(fp,"%s,",cell_title[n]);
				sprintf(pgc[n].cell_title,"%s",cell_title[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	dbtitle = 0;
	flg = 0;
	k = n = 0;
	for(i=0;i<512;i++)
		memset(cell_title[i],' ',sizeof(cell_title[i]));
	fprintf(fp,"DB_TITLES=");
	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"{"))
			{
				flg = 1;
				continue;
			}
			if((cp[j][i].s[0] >= 0x30 && cp[j][i].s[0] <= 0x7a) && flg == 1)
			{
				cell_title[n][k] = cp[j][i].s[0];
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"}"))
			{
				dbtitle = 1;
				cell_title[n][k] = '\0';
				if((coln = strchr(cell_title[n],':')) != (char *)NULL)
				{
					coln++;
					cell_length[n] = atoi(coln);
					*(coln-1) = '\0';
					fprintf(fp,"%s,",cell_title[n]);
					pgc[n].cell_length = cell_length[n];
				}
				else if((coln = strchr(cell_title[n],'@')) != (char *)NULL)
				{
					coln++;
					cell_length[n] = atoi(coln);
					*(coln-1) = '\0';
					fprintf(fp,"\"%s\",",cell_title[n]);
					pgc[n].cell_length = cell_length[n];
					pgc[n].keyflg = 1;
					KEYCOUNT += 1;
				}
				else
				{
					fprintf(fp,"%s,",cell_title[n]);
					pgc[n].cell_length = cell_length[n];
				}
				sprintf(pgc[n].cell_title,"%s",cell_title[n]);
				k = 0;
				n++;
				flg = 0;
			}
		}
	}
	fprintf(fp,"%d\n",0);

	flg = 0;
	k = m = n = 0;
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				flg = 1;
				k++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"GRID_SX=%d\n",sx);
	fprintf(fp,"GRID_EX=%d\n",ex-1);
	fprintf(fp,"GRID_SY=%d\n",sy);
	fprintf(fp,"GRID_EY=%d\n",ey);

	fclose(fp);
	return(0);
}

int AseEditor::convgrid2(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int sx,sy,ex,ey;
	int flg;
	int cell_length[512];
	char cell_align[512][12];
	char cell_action[512][12];
	char cell_fieldtype[512][12];
	char cell_skipstep[512][12];
	char cell_title[512][138];
	char *coln;
	int tmp = 51;

	int nn;	//for def.c

	sprintf(tmpbuff1,"_%s.c",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	for(i=0;i<512;i++)
		pgc[i].keyflg = 0;

	KEYCOUNT = 0;

	sx = sy = ex = ey = 0;

	flg = 0;
	k = m = n = nn = 0;
	l = 0;


	memset(cell_length,0,sizeof(cell_length));
	fprintf(fp,"//for grid\n");
	fprintf(fp,"	static int cell_length[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				flg = 1;
				k++;
				cell_length[n] = l;
				l++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				cell_length[n] = l;
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				cell_length[n] = l;
				fprintf(fp,"%d,",cell_length[n]);
				k++;
				n++;
				nn++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"0};\n");

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	memset(cell_align,0,sizeof(cell_align));
	fprintf(fp,"	static int cell_align[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sprintf(cell_align[n],"%s","1");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				wrefresh(pt2[j][i].vs);
				sprintf(cell_align[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"r")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"l")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"c")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","3");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_align[n],"%s","1");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_align[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"0};\n");


	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sx = j;
				sy = i;
				goto skip;
			}
		}
	}
	skip:

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_action[i],' ',sizeof(cell_action[i]));
	fprintf(fp,"	static int cell_action[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sprintf(cell_action[n],"%s","0");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_action[n],"%s","0");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"e")) && flg == 1)
			{
			//2009.08.07 Bug?
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				sprintf(cell_action[n],"%s","0");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"o")) && flg == 1)
			{
			//2009.08.07
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				sprintf(cell_action[n],"%s","1");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_action[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"0};\n");

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_fieldtype[i],' ',sizeof(cell_fieldtype[i]));
	fprintf(fp,"	static int grid_field[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				if(strlen(cp[j][i].s) < 2)
					sprintf(cell_fieldtype[n],"%s","2");
				else
					sprintf(cell_fieldtype[n],"%s","1");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","5");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","2");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(cell_fieldtype[n],"%s","4");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_fieldtype[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"0};\n");

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_skipstep[i],' ',sizeof(cell_skipstep[i]));
	fprintf(fp,"	static int grid_skipstep[] = {");
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				sprintf(cell_skipstep[n],"%s","1");
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"p")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","1");
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"k")) && flg == 1)
			{
				sprintf(cell_skipstep[n],"%s","0");
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				fprintf(fp,"%s,",cell_skipstep[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"0};\n");

	fprintf(fp,"	char *grid_titles[%d][128] = {", n+1);

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
		memset(cell_title[i],' ',sizeof(cell_title[i]));

	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				flg = 1;
				k++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
				sprintf(cell_title[n],"Grid_%d",n+1);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				if(cell_title[n][0] != 'G')
					sprintf(cell_title[n],"%s%d","Grid_",n+1);
				fprintf(fp,"\"%s\",",cell_title[n]);
				sprintf(pgc[n].cell_title,"%s",cell_title[n]);
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"\"\"};\n");

	fprintf(fp,"//	static char *db_titles[%d][128] = {", n+1);

	dbtitle = 0;
	flg = 0;
	k = n = 0;
	for(i=0;i<512;i++)
		memset(cell_title[i],' ',sizeof(cell_title[i]));
	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"{"))
			{
				flg = 1;
				continue;
			}
			if((cp[j][i].s[0] >= 0x30 && cp[j][i].s[0] <= 0x7a) && flg == 1)
			{
				cell_title[n][k] = cp[j][i].s[0];
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"}"))
			{
				dbtitle = 1;
				cell_title[n][k] = '\0';
				if((coln = strchr(cell_title[n],':')) != (char *)NULL)
				{
					coln++;
					cell_length[n] = atoi(coln);
					*(coln-1) = '\0';
					fprintf(fp,"\"%s\",",cell_title[n]);
					pgc[n].cell_length = cell_length[n];
				}
				else if((coln = strchr(cell_title[n],'@')) != (char *)NULL)
				{
					coln++;
					cell_length[n] = atoi(coln);
					*(coln-1) = '\0';
					fprintf(fp,"\"%s\",",cell_title[n]);
					pgc[n].cell_length = cell_length[n];
					pgc[n].keyflg = 1;
					KEYCOUNT += 1;
				}
				else
				{
					fprintf(fp,"\"%s\",",cell_title[n]);
					pgc[n].cell_length = cell_length[n];
				}
				sprintf(pgc[n].cell_title,"%s",cell_title[n]);
				k = 0;
				n++;
				flg = 0;
			}
		}
	}
	fprintf(fp,"0};\n");

	flg = 0;
	k = m = n = 0;
	for(i=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				flg = 1;
				k++;
				continue;
			}
			if(((!strcmp(cp[j][i].s,"-")) || 
				(!strcmp(cp[j][i].s,"e")) ||
				(!strcmp(cp[j][i].s,"r")) ||
				(!strcmp(cp[j][i].s,"l")) ||
				(!strcmp(cp[j][i].s,"t")) ||
				(!strcmp(cp[j][i].s,"d")) ||
				(!strcmp(cp[j][i].s,"p")) ||
				(!strcmp(cp[j][i].s,"k")) ||
				(!strcmp(cp[j][i].s,"$")) ||
				(!strcmp(cp[j][i].s,"n"))) 
				&& flg == 1)
			{
			//	sprintf(cp[j][i].s," ");
				mvwprintw(pt2[j][i].vs,0,0,"%s"," ");
				wrefresh(pt2[j][i].vs);
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				ex = j;
				ey = i;
				k++;
				n++;
				l = 0;
				flg = 0;
			}
		}
	}
	fprintf(fp,"	static int grid_sx = %d;\n",sx);
	fprintf(fp,"	static int grid_ex = %d;\n",ex-1);
	fprintf(fp,"	static int grid_sy = %d;\n",sy);
	fprintf(fp,"	static int grid_ey = %d;\n",ey);

	fprintf(fp,"\n");
	fprintf(fp,"	static int maxtext;\n");
	fprintf(fp,"	static int no = 0;\n\n");

	fprintf(fp,"	char **gt;\n");
	fprintf(fp,"	char **lt;\n\n");

	fprintf(fp,"	gt = (char **)&grid_titles;\n\n");

	fprintf(fp,"	xcol = MakeWsubForm(no,xcol,rows,0,2,grid_sx,grid_sy,grid_ex,grid_ey,cell_length,cell_align,cell_action,grid_field,grid_skipstep,gt,%d);\n",nn);

	fprintf(fp,"\n");
	fprintf(fp,"	lt = (char **)&label_text;\n\n");

	fprintf(fp,"	maxtext = MakeTextBox(no,0,2,xcol,rows,label_no,lt,label_x,label_y,label_length,textbox_no,textbox_x,textbox_y,textbox_length,textbox_align,textbox_action,textbox_field,textbox_skipstep, %d);\n",text_num);

	fprintf(fp,"\n}\n");

	fclose(fp);
	return(0);
}

int AseEditor::putecpg(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int flg;
	int tmp = 51;
	char *dot;

	
	if((dot = strchr(f,'.')) != (char *)NULL)
	{
		*dot = '\0';
	}
	sprintf(tmpbuff1,"%s.pgc",f);
	if(stat(tmpbuff1,fptr) == 0)
	{
		sprintf(tmpbuff2,"%s が存在します。上書きしますがよろしいですか？",tmpbuff1);
		if(popmsg((80/2)-24,(LINES/2)-4,tmpbuff2) == 0)
		{
			return(0);
		}
	}
	if((fp = fopen(tmpbuff1,"w")) == (FILE *)NULL)
	{
		return(-1);
	}

	flg = 0;
	k = m = n = 0;
	l = 0;


	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<512;i++)
	{
		memset(pgc[i].cell_fieldtype,' ',sizeof(pgc[i].cell_fieldtype));
	}

	fprintf(fp,"#include \"wsubform.h\"	//サブフォーム専用ヘッダファイルをインクルードする。\n");
	fprintf(fp,"\n");
	fprintf(fp,"#define Textbox	1	//操作関数用(サンプルを参照)\n");
	fprintf(fp,"#define Grid	2	//操作関数用(サンプルを参照)\n");
	fprintf(fp,"#define Panel	3	//操作関数用(サンプルを参照)\n");
	fprintf(fp,"\n");
	fprintf(fp,"#define Tret	199	//textboxでF12ファンクションキーが返す番号\n");
	fprintf(fp,"#define Gret	299	//gridでF12ファンクションキーが返す番号\n");
	fprintf(fp,"#define Pret	399	//paneltextでF12ファンクションキーが返す番号\n");
	fprintf(fp,"\n");
	fprintf(fp,"extern int wmode;	//挿入／上書のモード切替用\n");
	fprintf(fp,"extern char gridtitles[MAX_POS][MAX_LEN];	//wsubformが利用するgridのタイトル。\n");
	fprintf(fp,"\n");
	fprintf(fp,"extern TextBox	 *begin;	//textboxで使用する連鎖ポインタの開始位置\n");
	fprintf(fp,"extern TextBox	 *tp;	//textboxで使用する連鎖ポインタ\n");
	fprintf(fp,"\n");
	fprintf(fp,"typedef struct stat Dir;	//ファイル操作用\n");
	fprintf(fp,"static Dir dirptr;\n");
	fprintf(fp,"static Dir  *fptr = &dirptr;\n");
	fprintf(fp,"\n");
	fprintf(fp,"char tmp[MAX_STR];\n");
	fprintf(fp,"static int sqlcode = 0;	//PostgreSQLの返すコード\n");
	fprintf(fp,"static int DBcount = 0;	//wsubformで利用するDBの現在の最大行数\n");
	fprintf(fp,"\n");

	fprintf(fp,"int DBConnect(void)\n");
	fprintf(fp,"{\n");
	fprintf(fp,"	// DB接続用変数宣言です。DB名、ユーザ名、パスワードを設定してください。\n");
	fprintf(fp,"	EXEC SQL BEGIN DECLARE SECTION;\n");
	fprintf(fp,"		char dbname[12];\n");
	fprintf(fp,"		char user[12];\n");
	fprintf(fp,"		char passwd[12];\n");
	fprintf(fp,"	EXEC SQL END DECLARE SECTION;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	strcpy(dbname,\"DB-NAME\");\n");
	fprintf(fp,"	strcpy(user,\"USER\");\n");
	fprintf(fp,"	strcpy(passwd,\"PASSWD\");\n");
	fprintf(fp,"\n");
	fprintf(fp,"#ifdef DEBUG\n");
	fprintf(fp,"	// ECPGデバッグ文出力\n");
	fprintf(fp,"	ECPGdebug (0, stderr);\n");
	fprintf(fp,"#endif\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// 接続\n");
	fprintf(fp,"	memset (sqlca.sqlstate, \'0\', 5);\n");
	fprintf(fp,"	EXEC SQL CONNECT TO :dbname AS dbConnection user :user USING :passwd;\n");
	fprintf(fp,"	if (memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(tmp,\"CONNECT エラー。終了します。:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		exit (EXIT_FAILURE);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"}\n");
	fprintf(fp,"\n");

	fprintf(fp,"int Fetch_%s(int no)\n",f);
	fprintf(fp,"{\n");
	fprintf(fp,"	static char DBbuff[MAX_STR];\n");
	fprintf(fp,"	int i = 0;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	DBConnect();\n");
	fprintf(fp,"\n");
	fprintf(fp,"	memset (sqlca.sqlstate, \'0\', 5);\n");
	fprintf(fp,"\n");
  	fprintf(fp,"	EXEC SQL BEGIN DECLARE SECTION;\n");
	fprintf(fp,"		int rec_count;\n");

	flg = 0;
	k = m = n = 0;
	l = 0;

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;

		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				if(strlen(cp[j][i].s) < 2)
					sprintf(pgc[n].cell_fieldtype,"%s","int");
				else
					sprintf(pgc[n].cell_fieldtype,"%s","char");
				flg = 1;
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","date");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				if(!strcmp(pgc[n].cell_fieldtype,"char"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//TEXT\n",pgc[n].cell_fieldtype,pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"date"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//DATE\n","char",pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"int"))
				{
					fprintf(fp,"		%s		%s;		//NUMERIC\n",pgc[n].cell_fieldtype,pgc[n].cell_title);
				}
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"	EXEC SQL END DECLARE SECTION;\n");
	fprintf(fp,"\n");
    fprintf(fp,"	sqlcode = 0;\n");
    fprintf(fp,"	DBcount = 0;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	rec_count = 0;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// DBの行数を取得\n");
	fprintf(fp,"	EXEC SQL \n");
  	fprintf(fp,"	SELECT \n");
	fprintf(fp,"	COUNT(*)\n");
	fprintf(fp,"	INTO :rec_count\n");
	fprintf(fp,"	FROM	%s;\n",f);
//	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// SELECTエラー \n");
	fprintf(fp,"	if(memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(tmp,\"データベースSELECT COUNTエラー:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(-1) ;\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");
	fprintf(fp,"	DBcount = rec_count;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	EXEC SQL DECLARE %s_CURSOR CURSOR FOR \n",f);
  	fprintf(fp,"	SELECT \n");

	for(j=0;j<xcol;j++)
	{
		if(!strcmp(pgc[j].cell_fieldtype,"char"))
		{
			fprintf(fp,"		coalesce(%s,\' \',\'0\')",pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"date"))
		{
			fprintf(fp,"		TO_TIMESTAMP(:%s, \'YYYY/MM/DD HH24:MI:SS\')",pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"int"))
		{
			fprintf(fp,"		%s",pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
	}

	fprintf(fp,"	FROM	%s\n",f);
	fprintf(fp,"	ORDER BY %s;\n",pgc[0].cell_title);
//	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// カーソルオープン\n");
	fprintf(fp,"	EXEC SQL OPEN %s_CURSOR;\n",f);
	fprintf(fp,"\n");
	fprintf(fp,"	// SELECT OPENエラー \n");
	fprintf(fp,"	if (memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(tmp,\"データベースSELECT OPENエラー:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(-1);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");

	fprintf(fp,	"	for(i=0;i<DBcount;i++)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		EXEC SQL FETCH %s_CURSOR INTO\n",f);
	for(j=0;j<n-1;j++)
	{
		fprintf(fp,"			:%s,\n",pgc[j].cell_title);
	}
	fprintf(fp,"			:%s;\n",pgc[j].cell_title);
	fprintf(fp,"\n");


	fprintf(fp,"		if (memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"		{\n");
	fprintf(fp,"			sprintf(tmp,\"データベースFETCHエラー:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"			popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"			return(-1);\n");
	fprintf(fp,"		}\n");

	fprintf(fp,"	// テーブル項目をsplitbDBbuff[][]にセットする\n");
	for(j=0;j<xcol;j++)
	{
		if(!strcmp(pgc[j].cell_fieldtype,"char"))
		{
			fprintf(fp,"		sf_assgetDB(no,i,%d,%s,%d + 1);\n",j,pgc[j].cell_title,pgc[j].cell_length);
		}
		if(!strcmp(pgc[j].cell_fieldtype,"date"))
		{
			fprintf(fp,"		sf_assgetDB(no,i,%d,%s,%d + 1);\n",j,pgc[j].cell_title,pgc[j].cell_length);	//DATE型を文字に変換する。\n",pgc[j].cell_title);
		}
		if(!strcmp(pgc[j].cell_fieldtype,"int"))
		{
			fprintf(fp,"		sf_to_text(%s,DBbuff);	//NUMERIC型(int)を文字に変換する。\n",pgc[j].cell_title);
			fprintf(fp,"		sf_assgetDB(no,i,%d,DBbuff,%d + 1);\n",j,pgc[j].cell_length);
		}
	}

	fprintf(fp,"\n");
	fprintf(fp,"		if (memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"		{\n");
	fprintf(fp,"			EXEC SQL CLOSE %s_CURSOR;\n",f);
//	fprintf(fp,"			EXEC SQL END;\n");
	fprintf(fp,"			sprintf(tmp,\"データベースFETCHエラー:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"			popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"			return(-1);\n");
	fprintf(fp,"		}\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"	// カーソルクローズ \n");
	fprintf(fp,"	EXEC SQL CLOSE %s_CURSOR;\n",f);
//	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	DBcount = rec_count;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// 結果チェック\n");
	fprintf(fp,"	if (sqlca.sqlcode != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(tmp,\"データベースFETCH結果チェック:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(0);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"	// 切断\n");
	fprintf(fp,"	sqlca.sqlcode = 0;\n");
	fprintf(fp,"	EXEC SQL DISCONNECT dbConnection;\n");
	fprintf(fp,"	return(0);\n");
	fprintf(fp,"}\n");
	fprintf(fp,"\n");

	fclose(fp);
	return(n);
}

int AseEditor::putecpgINSERT(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int flg;
	int tmp = 51;
	char *dot;
	
	sprintf(tmpbuff1,"%s.pgc",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	flg = 0;
	k = m = n = 0;
	l = 0;

	tmp = 51;
	flg = 0;
	k = m = n = 0;

	for(i=0;i<512;i++)
	{
		memset(pgc[i].cell_fieldtype,' ',sizeof(pgc[i].cell_fieldtype));
	}

	fprintf(fp,"int Insert_%s(int no)\n",f);
	fprintf(fp,"{\n");
	fprintf(fp,"	static char DBbuff[MAX_STR];\n");
	fprintf(fp,"	int i = 0;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	DBConnect();\n");
	fprintf(fp,"\n");
	fprintf(fp,"	memset (sqlca.sqlstate, \'0\', 5);\n");
	fprintf(fp,"\n");
  	fprintf(fp,"	EXEC SQL BEGIN DECLARE SECTION;\n");
	fprintf(fp,"		int rec_count;\n");

	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;

		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				if(strlen(cp[j][i].s) < 2)
					sprintf(pgc[n].cell_fieldtype,"%s","int");
				else
					sprintf(pgc[n].cell_fieldtype,"%s","char");
				flg = 1;
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","date");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				if(!strcmp(pgc[n].cell_fieldtype,"char"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//TEXT\n",pgc[n].cell_fieldtype,pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"date"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//DATE\n","char",pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"int"))
				{
					fprintf(fp,"		%s		%s;		//NUMERIC\n",pgc[n].cell_fieldtype,pgc[n].cell_title);
				}
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"	EXEC SQL END DECLARE SECTION;\n");
	fprintf(fp,"\n");
    fprintf(fp,"	sqlcode = 0;\n");
	fprintf(fp,"\n");

	fprintf(fp,"	// インサート\n");
	fprintf(fp,"	// テーブル項目をsplitbDBbuff[]からDB配列にセットする\n");
	for(j=0;j<xcol;j++)
	{
		if(!strcmp(pgc[j].cell_fieldtype,"char"))
		{
			fprintf(fp,"	sf_assputDB(no,%d,%s,%d + 1);\n",j,pgc[j].cell_title,pgc[j].cell_length);
		}
		if(!strcmp(pgc[j].cell_fieldtype,"date"))
		{
			fprintf(fp,"	sf_assputDB(no,%d,%s,%d + 1);\n",j,pgc[j].cell_title,pgc[j].cell_length);	//DATE型も文字に変換する。\n",pgc[j].cell_title);
		}
		if(!strcmp(pgc[j].cell_fieldtype,"int"))
		{
			fprintf(fp,"	sf_assputDB(no,%d,DBbuff,%d + 1);\n",j,pgc[j].cell_length);
			fprintf(fp,"	%s = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。\n",pgc[j].cell_title);
		}
	}
	fprintf(fp,"\n");

  	fprintf(fp,"	// 対象レコードをADD\n");
	fprintf(fp,"	EXEC SQL INSERT INTO %s\n",f);
	fprintf(fp,"	(\n");
	for(j=0;j<n-1;j++)
	{
		fprintf(fp,"		%s,\n",pgc[j].cell_title);
	}
	fprintf(fp,"		%s\n",pgc[j].cell_title);
	fprintf(fp,"	)\n");
	fprintf(fp,"	VALUES\n");
	fprintf(fp,"	(\n");
	for(j=0;j<n-1;j++)
	{
		if(!strcmp(pgc[j].cell_fieldtype,"char"))
		{
			fprintf(fp,"		coalesce(:%s,\' \',\'0\')",pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"date"))
		{
			fprintf(fp,"		TO_TIMESTAMP(:%s, \'YYYY/MM/DD HH24:MI:SS\')",pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"int"))
		{
			fprintf(fp,"		:%s",pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
	}
	if(!strcmp(pgc[j].cell_fieldtype,"char"))
	{
		fprintf(fp,"		coalesce(:%s,\' \',\'0\')",pgc[j].cell_title);
		if(j == n-1)
			fprintf(fp,"\n");
		else
			fprintf(fp,",\n");
	}
	if(!strcmp(pgc[j].cell_fieldtype,"date"))
	{
		fprintf(fp,"		TO_TIMESTAMP(:%s, \'YYYY/MM/DD HH24:MI:SS\')",pgc[j].cell_title);
		if(j == n-1)
			fprintf(fp,"\n");
		else
			fprintf(fp,",\n");
	}
	if(!strcmp(pgc[j].cell_fieldtype,"int"))
	{
		fprintf(fp,"		:%s",pgc[j].cell_title);
		if(j == n-1)
			fprintf(fp,"\n");
		else
			fprintf(fp,",\n");
	}

	fprintf(fp,"	);\n");
//	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");

	fprintf(fp,"	// 登録エラー\n");
	fprintf(fp,"	if (memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"	{\n");
  	fprintf(fp,"		// ロールバック\n");
	fprintf(fp,"		EXEC SQL ROLLBACK WORK;\n");
	fprintf(fp,"		EXEC SQL END;\n");
	fprintf(fp,"		sprintf(tmp,\"データベースINSERTエラー:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(-1);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");

	fprintf(fp,"	// コミット\n");
	fprintf(fp,"	EXEC SQL COMMIT;\n");
	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");

	fprintf(fp,"	// 結果チェック\n");
	fprintf(fp,"	if (sqlca.sqlcode != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(tmp,\"データベースINSERT結果チェック:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(0);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// 切断\n");
	fprintf(fp,"	sqlca.sqlcode = 0;\n");
	fprintf(fp,"	EXEC SQL DISCONNECT dbConnection;\n");
	fprintf(fp,"	return(0);\n");
	fprintf(fp,"}\n");
	fprintf(fp,"\n");

	fclose(fp);
	return(n);
}

int AseEditor::putecpgUPDATE(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int flg;
	int tmp = 51;
	char *dot;

	
	sprintf(tmpbuff1,"%s.pgc",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	flg = 0;
	k = m = n = 0;
	l = 0;

	tmp = 51;
	flg = 0;
	k = m = n = 0;

	for(i=0;i<512;i++)
	{
		memset(pgc[i].cell_fieldtype,' ',sizeof(pgc[i].cell_fieldtype));
	}

	fprintf(fp,"int	Update_%s(int no,const char* key1,const char* key2,int sqlcode,int line)\n",f);
	fprintf(fp,"{\n");
	fprintf(fp,"	static char DBbuff[MAX_STR];\n");
	fprintf(fp,"	int i = 0;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	DBConnect();\n");
	fprintf(fp,"\n");
	fprintf(fp,"	memset (sqlca.sqlstate, \'0\', 5);\n");
	fprintf(fp,"\n");
  	fprintf(fp,"	EXEC SQL BEGIN DECLARE SECTION;\n");
	fprintf(fp,"		int rec_count;\n");

	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;

		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				if(strlen(cp[j][i].s) < 2)
					sprintf(pgc[n].cell_fieldtype,"%s","int");
				else
					sprintf(pgc[n].cell_fieldtype,"%s","char");
				flg = 1;
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","date");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				if(!strcmp(pgc[n].cell_fieldtype,"char"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//TEXT\n",pgc[n].cell_fieldtype,pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"date"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//DATE\n","char",pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"int"))
				{
					fprintf(fp,"		%s		%s;		//NUMERIC\n",pgc[n].cell_fieldtype,pgc[n].cell_title);
				}
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
	fprintf(fp,"	EXEC SQL END DECLARE SECTION;\n");
	fprintf(fp,"\n");
    fprintf(fp,"	sqlcode = 0;\n");
	fprintf(fp,"\n");

	fprintf(fp,"	strncpy((char *)%s,key1,sizeof(%s));	//KEY1\n",pgc[0].cell_title,pgc[0].cell_title);
	fprintf(fp,"	strncpy((char *)%s,key2,sizeof(%s));	//KEY2\n",pgc[1].cell_title,pgc[1].cell_title);

	fprintf(fp,"	// アップデート\n");
	fprintf(fp,"	// テーブル項目をsplitbDBbuff[]からDB配列にセットする\n");
	for(j=0;j<xcol;j++)
	{
		if(!strcmp(pgc[j].cell_fieldtype,"char"))
		{
			fprintf(fp,"	sf_assputDB(no,%d,%s,%d + 1);\n",j,pgc[j].cell_title,pgc[j].cell_length);
		}
		if(!strcmp(pgc[j].cell_fieldtype,"date"))
		{
			fprintf(fp,"	sf_assputDB(no,%d,%s,%d + 1);\n",j,pgc[j].cell_title,pgc[j].cell_length);	//DATE型も文字に変換する。\n",pgc[j].cell_title);
		}
		if(!strcmp(pgc[j].cell_fieldtype,"int"))
		{
			fprintf(fp,"	sf_assputDB(no,%d,DBbuff,%d + 1);\n",j,pgc[j].cell_length);
			fprintf(fp,"	%s = sf_to_integer(DBbuff);	//文字(char)をNUMERIC型(int)に変換する。\n",pgc[j].cell_title);
		}
	}
	fprintf(fp,"\n");

  	fprintf(fp,"	// 対象レコードをUPDATE\n");
//	fprintf(fp,	"	for(i=0;i<DBcount;i++)\n");
//	fprintf(fp,"	{\n");
	fprintf(fp,"	EXEC SQL UPDATE %s\n",f);
	fprintf(fp,"	SET\n");
	/*
	for(j=0;j<n-1;j++)
	{
		fprintf(fp,"			%s =	:%s,\n",pgc[j].cell_title,pgc[j].cell_title);
	}
	*/

	for(j=0;j<n-1;j++)
	{
		if(!strcmp(pgc[j].cell_fieldtype,"char"))
		{
			fprintf(fp,"		%s =	coalesce(:%s,\' \',\'0\')",pgc[j].cell_title,pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"date"))
		{
			fprintf(fp,"		%s = 	TO_TIMESTAMP(:%s, \'YYYY/MM/DD HH24:MI:SS\')",pgc[j].cell_title,pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"int"))
		{
			fprintf(fp,"		%s = 	:%s",pgc[j].cell_title,pgc[j].cell_title);
			if(j == n-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
	}
	if(!strcmp(pgc[j].cell_fieldtype,"char"))
	{
		fprintf(fp,"		%s =	coalesce(:%s,\' \',\'0\')",pgc[j].cell_title,pgc[j].cell_title);
		if(j == n-1)
			fprintf(fp,"\n");
		else
			fprintf(fp,",\n");
	}
	if(!strcmp(pgc[j].cell_fieldtype,"date"))
	{
		fprintf(fp,"		%s = 	TO_TIMESTAMP(:%s, \'YYYY/MM/DD HH24:MI:SS\')",pgc[j].cell_title,pgc[j].cell_title);
		if(j == n-1)
			fprintf(fp,"\n");
		else
			fprintf(fp,",\n");
	}
	if(!strcmp(pgc[j].cell_fieldtype,"int"))
	{
		fprintf(fp,"		%s = 	:%s",pgc[j].cell_title,pgc[j].cell_title);
		if(j == n-1)
			fprintf(fp,"\n");
		else
			fprintf(fp,",\n");
	}
	fprintf(fp,"	WHERE %s = :%s AND %s = :%s;\n",pgc[0].cell_title,pgc[0].cell_title,pgc[1].cell_title,pgc[1].cell_title);
	fprintf(fp,"	EXEC SQL END;\n");
//	fprintf(fp,"	}\n");
	fprintf(fp,"\n");

	fprintf(fp,"	if (memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"	// 更新エラー\n");
  	fprintf(fp,"		// ロールバック\n");
  	fprintf(fp,"		EXEC SQL ROLLBACK WORK;\n");
	fprintf(fp,"		EXEC SQL END;\n");
	fprintf(fp,"		sprintf(tmp,\"データベースUPDATEエラー:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(-1);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");

  	fprintf(fp,"	//コミットする\n");
	fprintf(fp,"	EXEC SQL COMMIT;\n");
	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");

	fprintf(fp,"\n");
	fprintf(fp,"	// 結果チェック\n");
	fprintf(fp,"	if (sqlca.sqlcode != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(tmp,\"データベースUPDATE結果チェック:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(0);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// 切断\n");
	fprintf(fp,"	sqlca.sqlcode = 0;\n");
	fprintf(fp,"	EXEC SQL DISCONNECT dbConnection;\n");
	fprintf(fp,"	return(0);\n");
	fprintf(fp,"}\n");
	fprintf(fp,"\n");

	fclose(fp);
	return(n);
}

int AseEditor::putecpgDELETE(WINDOW *vs,int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j,k,l,m,n;
	int flg;
	int tmp = 51;
	char *dot;
	
	sprintf(tmpbuff1,"%s.pgc",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	fprintf(fp,"int	Delete_%s(const char *key1,char *key2,int sqlcode)\n",f);
	fprintf(fp,"{\n");
	fprintf(fp,"	static char DBbuff[MAX_STR];\n");
	fprintf(fp,"	int i = 0;\n");
	fprintf(fp,"\n");
	fprintf(fp,"	DBConnect();\n");
	fprintf(fp,"\n");
	fprintf(fp,"	memset (sqlca.sqlstate, \'0\', 5);\n");
	fprintf(fp,"\n");
  	fprintf(fp,"	EXEC SQL BEGIN DECLARE SECTION;\n");

	flg = 0;
	k = m = n = 0;
	l = 0;

	tmp = 51;
	flg = 0;
	k = m = n = 0;
	for(i=0;i<xrow;i++,m++)
	{
		if(i > tmp)
			break;

		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				if(strlen(cp[j][i].s) < 2)
					sprintf(pgc[n].cell_fieldtype,"%s","int");
				else
					sprintf(pgc[n].cell_fieldtype,"%s","char");
				flg = 1;
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"t")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","char");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"d")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","date");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"n")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"$")) && flg == 1)
			{
				sprintf(pgc[n].cell_fieldtype,"%s","int");
				l++;
				k++;
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				if(!strcmp(pgc[n].cell_fieldtype,"char"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//TEXT\n",pgc[n].cell_fieldtype,pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"date"))
				{
					fprintf(fp,"		%s	%s[%d + 1];	//DATE\n","char",pgc[n].cell_title,pgc[n].cell_length);
				}
				if(!strcmp(pgc[n].cell_fieldtype,"int"))
				{
					fprintf(fp,"		%s		%s;		//NUMERIC\n",pgc[n].cell_fieldtype,pgc[n].cell_title);
				}
				k++;
				n++;
				l = 0;
				flg = 0;
				tmp = i;
			}
		}
	}
//fprintf(fp,"		%s	%s[%d + 1];	//TEXT\n",pgc[0].cell_fieldtype,pgc[0].cell_title,pgc[0].cell_length);
//fprintf(fp,"		%s	%s[%d + 1];	//TEXT\n",pgc[1].cell_fieldtype,pgc[1].cell_title,pgc[1].cell_length);
	fprintf(fp,"	EXEC SQL END DECLARE SECTION;\n");
	fprintf(fp,"\n");
    fprintf(fp,"	sqlcode = 0;\n");
	fprintf(fp,"\n");

	fprintf(fp,"	// キー項目設定\n");
	fprintf(fp,"	memset((char *)%s, \'\\0\', sizeof(%s));\n",pgc[0].cell_title,pgc[0].cell_title);
	fprintf(fp,"	memset((char *)%s, \'\\0\', sizeof(%s));\n",pgc[1].cell_title,pgc[1].cell_title);
	fprintf(fp,"	strncpy((char *)%s,key1,sizeof(%s));	//KEY1\n",pgc[0].cell_title,pgc[0].cell_title);
	fprintf(fp,"	strncpy((char *)%s,key2,sizeof(%s));	//KEY2\n",pgc[1].cell_title,pgc[1].cell_title);
	fprintf(fp,"\n");

  	fprintf(fp,"	// 削除対象レコードをDELETE\n");
	fprintf(fp,"	EXEC SQL DELETE FROM %s\n",f);
	fprintf(fp,"	WHERE %s = :%s AND %s = :%s;\n",pgc[0].cell_title,pgc[0].cell_title,pgc[1].cell_title,pgc[1].cell_title);
	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");

	fprintf(fp,"	if (memcmp (sqlca.sqlstate, \"00\", 2) != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"	// 削除エラー\n");
  	fprintf(fp,"		// ロールバック\n");
  	fprintf(fp,"		EXEC SQL ROLLBACK WORK;\n");
	fprintf(fp,"		EXEC SQL END;\n");
	fprintf(fp,"		sprintf(tmp,\"データベースUPDATEエラー:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(-1);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");

  	fprintf(fp,"	//コミットする\n");
	fprintf(fp,"	EXEC SQL COMMIT;\n");
	fprintf(fp,"	EXEC SQL END;\n");
	fprintf(fp,"\n");

	fprintf(fp,"\n");
	fprintf(fp,"	// 結果チェック\n");
	fprintf(fp,"	if (sqlca.sqlcode != 0)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(tmp,\"データベースUPDATE結果チェック:%%d - %%s\",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);\n");
	fprintf(fp,"		popmsg((COLS/2)-24,(LINES/2)-4,tmp);\n");
	fprintf(fp,"		return(0);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"\n");
	fprintf(fp,"	// 切断\n");
	fprintf(fp,"	sqlca.sqlcode = 0;\n");
	fprintf(fp,"	EXEC SQL DISCONNECT dbConnection;\n");
	fprintf(fp,"	return(0);\n");
	fprintf(fp,"}\n");
	fprintf(fp,"\n");

	fclose(fp);
	return(0);
}

int AseEditor::putecpgInterFace(char *f)
{
	FILE *fp;
	
	sprintf(tmpbuff1,"%s.pgc",f);
	if((fp = fopen(tmpbuff1,"a")) == (FILE *)NULL)
	{
		return(-1);
	}

	fprintf(fp,"// 以下の二つの関数は入出力画面(ウインドウ)とのインターフェース関数です。\n");
	fprintf(fp,"// FETCHしたgridにDBの行列を書き込みます。\n");
	fprintf(fp,"int grid_disp(int no, int startline, int maxcol)\n");
	fprintf(fp,"{\n");
	fprintf(fp,"	int i, j;\n");
	fprintf(fp,"	char s[MAX_TMP];\n");
	fprintf(fp,"\n");
	fprintf(fp,"	if((Fetch_%s(no)) == 0)\n",f);
	fprintf(fp,"	{\n");
	fprintf(fp,"		for(i=startline;i<DBcount;i++)\n");
	fprintf(fp,"		{\n");
	fprintf(fp,"			for(j=0;j<maxcol;j++)\n");
	fprintf(fp,"			{\n");
	fprintf(fp,"				sf_gputDB(no,i,j,startline,s);\n");
	fprintf(fp,"			}\n");
	fprintf(fp,"		}\n");
	fprintf(fp,"		return(0);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"	else\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		return(-1);\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"}\n");
	fprintf(fp,"\n");
	fprintf(fp,"// DBから入出力(画面)ウインドウに書き込みます。\n");
	fprintf(fp,"void inputwin_write(int no, int get, int line,int maxcol)\n");
	fprintf(fp,"{\n");
	fprintf(fp,"	int i;\n");
	fprintf(fp,"	char s[MAX_TMP];\n");
	fprintf(fp,"	\n");
	fprintf(fp,"	sf_tbegin();\n");
	fprintf(fp,"	for(i=0;tp->next !=(TextBox *)NULL;i++)\n");
	fprintf(fp,"	{\n");
	fprintf(fp,"		sprintf(s,\"%%s\",ft[get].splitDBbuff[line][i]);\n");
	fprintf(fp,"		sf_tput(no,i,s);\n");
	fprintf(fp,"		sf_tnext();\n");
	fprintf(fp,"	}\n");
	fprintf(fp,"	sprintf(s,\"%%s\",ft[get].splitDBbuff[line][i]);\n");
	fprintf(fp,"	sf_tput(no,i,s);\n");
	fprintf(fp,"}\n");
	fprintf(fp,"\n");

	fclose(fp);
	return(0);
}

int AseEditor::putCreateSQL(WINDOW *vs,int xcol, int xrow, char *f, int nline)
{
	FILE *fp;
	int i,j,k,l,m;
	int flg;
	int tmp = 51;
	char *dot;

	
//	dot = strchr(f,'.');
//	*dot = '\0';
	sprintf(tmpbuff1,"create_%s.sql",f);
	if((fp = fopen(tmpbuff1,"w")) == (FILE *)NULL)
	{
		return(-1);
	}

	fprintf(fp,"create table %s\n",f);
	fprintf(fp,"(\n");

	for(j=0;j<xcol;j++)
	{
		if(!strcmp(pgc[j].cell_fieldtype,"char"))
		{
			fprintf(fp,"	%s	VARCHAR(%d)",pgc[j].cell_title,pgc[j].cell_length);
			if(j == nline-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"date"))
		{
			fprintf(fp,"	%s	DATE",pgc[j].cell_title);
			if(j == nline-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
		if(!strcmp(pgc[j].cell_fieldtype,"int"))
		{
			fprintf(fp,"	%s	INTEGER",pgc[j].cell_title);
			if(j == nline-1)
				fprintf(fp,"\n");
			else
				fprintf(fp,",\n");
		}
	}
	fprintf(fp,");\n");

	fclose(fp);
	return(0);
}

int AseEditor::rightcell(int xcol, int xrow)
{
	int i,j,k,m;
	int flg = 0;
	for(i=0,k=0,m=0;i<xrow;i++,m++)
	{
		for(j=0;j<xcol;j++)
		{
			if(!strcmp(cp[j][i].s,"["))
			{
				flg = 1;
				k++;
				continue;
			}
			if((!strcmp(cp[j][i].s,"-")) && flg == 1)
			{
				if(j%2)
				{
					sprintf(cp[j][i].s,"r");
					mvwprintw(pt2[j][i].vs,0,0,"%s","r");
					wrefresh(pt2[j][i].vs);
					k++;
				}
				else
				{
					sprintf(cp[j][i].s,"e");
					mvwprintw(pt2[j][i].vs,0,0,"%s","r");
					wrefresh(pt2[j][i].vs);
					k++;
				}
				continue;
			}
			if(!strcmp(cp[j][i].s,"]"))
			{
				k++;
				flg = 0;
			}
		}
	}
}

int AseEditor::freads(int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j;
	unsigned int c;
	if((fp = fopen(f,"r")) == (FILE *)NULL)
	{
		return(-1);
	}
	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol+1;j++)
		{
			if((c = fgetc(fp)) == EOF)
				goto end;
			if(c == '\n')
			{
				break;
			}
			cp[j][i].s[0] = c;
			cp[j][i].s[1] = '\0';
			mvwprintw(pt2[j][i].vs,0,0,"%c",cp[j][i].s[0]);
			wrefresh(pt2[j][i].vs);
		}
	}
	end:
	fclose(fp);
	return(0);
}

int AseEditor::fwrites(int xcol, int xrow, char *f)
{
	FILE *fp;
	int i,j;
	sprintf(tmpbuff1,"%s",f);
	if((fp = fopen(tmpbuff1,"w")) == (FILE *)NULL)
	{
		return(-1);
	}
	for(i=0;i<xrow;i++)
	{
		for(j=0;j<xcol;j++)
		{
			fprintf(fp,"%s",cp[j][i].s);
		}
		fprintf(fp,"\n");
	}
	fclose(fp);
	return(0);
}

int AseEditor::ase(int xcol,int xrow,char *f,int command)
{
	WINDOW *vs;
	int ch;
	int i,j,k,l,m,n,o,p;
	int maxcell;
	char *nl;
	char st[256][256];
	int basewin_width;
	int basewin_Hight;
	int subwin_cols;
	int subwin_rows;
	int cell_len;
	char attr[5];
	char field[5];
	char action[5];
	char skipstep[5];
	char tmp[5];
	int tmpi, tmpj;
	int ret;
	int len;

	if(command == 1)
	{
		if(xcol > 174 || xrow > 78)
		{
			fprintf(stderr,"Check LINES or COLS this terminal - %d/%d\n",xrow,xcol);
			exit(1);
		}
		initscr();
		cbreak();
		noecho();

		if(xcol > COLS || xrow > (LINES - 1))
		{
			echo();
			endwin();
			if(xcol > COLS)
				fprintf(stderr,"COLS=%d/%d\n",COLS,xcol);
			if(xrow > (LINES - 1))
				fprintf(stderr,"LINES=%d/%d\n",LINES,xrow);
			exit(1);
		}
		if(fulldisplay  == 1)
		{
			xcol = COLS - 2;
			xrow = LINES - 1;
		}
	}
	else
	{
		if(xcol > COLS-1 || xrow > (LINES - 1))
		{
			popmsg((80/2)-24,(LINES/2)-4,(char *)"Over Colums or Rows");
			return(-1);
		}
	}

	vs = newwin(xrow,xcol,1,1);
	keypad(vs,TRUE);
	meta(vs, TRUE);
	refresh();

	i = 0;
	for(k=0;k<xcol;k++)
	{
		for(j=0;j<xrow;j++)
		{
			pt2[k][j].vs = subwin(vs,1,1,j+1,k+1);
			keypad(pt2[k][j].vs,TRUE);
			meta(pt2[k][j].vs, TRUE);
			cp[k][j].no = i;
			cp[k][j].x = k+1;
			cp[k][j].y = j+1;
			cp[k][j].c = k;
			memset(cp[k][j].s,' ',1);
			sprintf(tmpbuff1,".");
			sprintf(cp[k][j].s,"%s",tmpbuff1);
			i++;
		}
	}
	i--;

	maxcell = i;

	for(i=0;i<(xrow+0);i++)
	{
		mvwprintw(stdscr,i+1,xcol+2,"%-2d",i+1);
	}
	for(i=1;i<(xcol+1);i++)
	{
		if(!(i%10))
		{
			if(i>99)
			{
				sprintf(tmpbuff1,"%d",i-100);
			}
			else
			{
				sprintf(tmpbuff1,"%-2d",i);
			}
			mvwprintw(stdscr,0,i,tmpbuff1);
		}
		else
		{
			sprintf(tmpbuff1,"_");
			mvwprintw(stdscr,0,i,tmpbuff1);
		}
	}
	refresh();

	for(k=0;k<xcol;k++)
	{
		for(j=0;j<xrow;j++)
		{
			mvwprintw(pt2[k][j].vs,0,0,"%s",cp[k][j].s);
			wrefresh(pt2[k][j].vs);
		}
	}

	wrefresh(vs);
	i = 0;
	j = 0;
	l = 0;
	m = 0;
	sprintf(attr,"%s","-");
	sprintf(field,"%s","-");
	sprintf(action,"%s","-");
	sprintf(skipstep,"%s","-");
	memset(tmp,'\0',sizeof(tmp));
	tmpi = tmpj = 0;

	if(readflg == 1)
	{
		if(stat(f,fptr) == 0)
			freads(xcol,xrow,f);
	}

	while(1)
	{
		wattron(pt2[i][j].vs, A_BOLD | A_DIM | A_REVERSE | A_PROTECT);
		mvwprintw(pt2[i][j].vs,1,1,"%s",cp[i][j].s);
		wattroff(pt2[i][j].vs, A_BOLD | A_DIM | A_REVERSE | A_PROTECT);
		wrefresh(pt2[i][j].vs);

		mvwprintw(stdscr,0,COLS-25,"(%s%s%s%s)[%4d %3d %3d %3d]",attr,field,action,skipstep,cp[i][j].no,cp[i][j].x,cp[i][j].y,cp[i][j].c);
		refresh();
		wrefresh(vs);
		wrefresh(pt2[i][j].vs);

		ch = wgetch(vs);
		mvwprintw(pt2[i][j].vs,0,0,"%s",cp[i][j].s);
		wrefresh(pt2[i][j].vs);
		wrefresh(vs);

		switch(ch)
		{
		case KEY_F(1):
			break;
		case KEY_IC:
			k = 0;
			n = 0;
			l = j;
			m = i;
			memset(tmp,'\0',sizeof(tmp));
			sprintf(tmp,"%s",cp[i][j].s);
			tmpi = i;
			tmpj = j;

			input_window(4,2,tmpbuff1,(char *)"作成する列名を入力してください。(英数字のみ)");
			len = strlen(tmpbuff1);
			if(len < 1)
			{
				touchwin(vs);
				break;
			}
			mvwprintw(pt2[m][l].vs,0,0,"{");
			sprintf(cp[m][l].s,"%s","{");
			wrefresh(pt2[m][l].vs);
			for (n=m+1;n<(len+m+1);n++)
			{
				mvwaddch(pt2[n][l].vs,0,0,tmpbuff1[k]);
				wrefresh(pt2[n][l].vs);
				tmpbuff2[0] = tmpbuff1[k];
				tmpbuff2[1] = '\0';
				sprintf(cp[n][l].s,"%s",tmpbuff2);
				k++;
			}
			mvwprintw(pt2[n][l].vs,0,0,"}");
			sprintf(cp[n][l].s,"%s","}");
			wrefresh(pt2[n][l].vs);
			touchwin(vs);
			break;
		case '?':
			ehelpmsg(1,1);
			touchwin(vs);
			break;
		case 'H':
			jhelpmsg(1,1);
			touchwin(vs);
			break;
		case '.':
			sprintf(attr,"%s",".");
			sprintf(field,"%s",".");
			sprintf(action,"%s",".");
			sprintf(skipstep,"%s",".");
			break;
		case '-': case 'L':
			sprintf(attr,"%s","-");
			sprintf(field,"%s","-");
			sprintf(action,"%s","-");
			sprintf(skipstep,"%s","-");
			break;
		case 'D':
			sprintf(attr,"%s","r");
			sprintf(field,"%s","d");
			sprintf(action,"%s","e");
			sprintf(skipstep,"%s","p");
			break;
		case 'R':
			sprintf(attr,"%s","r");
			sprintf(field,"%s","$");
			sprintf(action,"%s","e");
			sprintf(skipstep,"%s","p");
			break;
		case 'T':
			sprintf(attr,"%s","l");
			sprintf(field,"%s","t");
			sprintf(action,"%s","e");
			sprintf(skipstep,"%s","p");
			break;
		case 'K':
			sprintf(attr,"%s","l");
			sprintf(field,"%s","t");
			sprintf(action,"%s","e");
			sprintf(skipstep,"%s","k");
			break;
		case '':
			sprintf(attr,"%s","r");
			sprintf(field,"%s","n");
			sprintf(action,"%s","e");
			sprintf(skipstep,"%s","k");
			break;
		case '':
			sprintf(attr,"%s","r");
			sprintf(field,"%s","n");
			sprintf(action,"%s","e");
			sprintf(skipstep,"%s","p");
			break;
		case 'i':
			vs_ieee_c(pt2[i][j].vs,0,0,tmpbuff1,0);
			sprintf(cp[i][j].s,"%s",tmpbuff1);
			mvwprintw(pt2[i][j].vs,1,1,"%s",cp[i][j].s);
			wrefresh(pt2[i][j].vs);
			break;
		case '':
			sprintf(tmpbuff1,"画面定義ソースファイルを作成します。 [_%s.c] Ok?",f);
			if(popmsg((80/2)-24,(LINES/2)-4,tmpbuff1) == 0)
			{
				touchwin(vs);
				break;
			}
		//	mvwprintw(stdscr,LINES-1,1,"%s",tmpbuff1);
			convlabel2(vs,xcol,xrow,f);
			convtextbox2(vs,xcol,xrow,f);
			convgrid2(vs,xcol,xrow,f);
			if(!dbtitle)
			{
				wrefresh(vs);
				touchwin(vs);
				break;
			}
			break;
		case 'c':
			sprintf(tmpbuff1,"画面定義ファイルを作成します。 [_%s] Ok?",f);
			if(popmsg((80/2)-24,(LINES/2)-4,tmpbuff1) == 0)
			{
				touchwin(vs);
				break;
			}
		//	mvwprintw(stdscr,LINES-1,1,"%s",tmpbuff1);
			convlabel(vs,xcol,xrow,f);
			convtextbox(vs,xcol,xrow,f);
			convgrid(vs,xcol,xrow,f);
			if(!dbtitle)
			{
				wrefresh(vs);
				touchwin(vs);
				break;
			}
			sprintf(tmpbuff2,"ECPG ソースを作成します。よろしいですか？",tmpbuff1);
			if(popmsg((80/2)-24,(LINES/2)-4,tmpbuff2) == 0)
			{
				wrefresh(vs);
				touchwin(vs);
				break;
			}
			ret = putecpg(vs,xcol,xrow,f);
			if(ret == 0)
			{
				for(k=0;k<xcol;k++)
				{
					for(m=0;m<xrow;m++)
					{
						mvwprintw(pt2[k][m].vs,0,0,"%s",cp[k][m].s);
						wrefresh(pt2[k][m].vs);
					}
				}
				wrefresh(vs);
				touchwin(vs);
				break;
			}
			putecpgINSERT(vs,xcol,xrow,f);
			putecpgUPDATE(vs,xcol,xrow,f);
			putecpgDELETE(vs,xcol,xrow,f);
			putecpgInterFace(f);
			putCreateSQL(vs,xcol,xrow,f,ret);
			touchwin(vs);
			break;
		case 'r':
			sprintf(tmpbuff1,"ファイルから再読み込みますか[_%s]?",f);
			if(popmsg((80/2)-24,(LINES/2)-4,tmpbuff1) == 0)
			{
				wrefresh(vs);
				touchwin(vs);
				break;
			}
			wrefresh(vs);
			touchwin(vs);
			if(stat(f,fptr) == 0)
				freads(xcol,xrow,f);
			break;
		case 'W':
			if(f[0] == '-')
			{
				input_window(4,2,tmpbuff1,(char *)"作成するファイル名を入力してください。");
				sprintf(f,"%s.def",tmpbuff1);
			}
			sprintf(tmpbuff1,"Over Write? %s",f);
			if(popmsg((80/2)-24,(LINES/2)-4,tmpbuff1) == 0)
			{
				touchwin(vs);
				break;
			}
		//	mvwprintw(stdscr,LINES-1,1,"%s",tmpbuff1);
			fwrites(xcol,xrow,f);
			touchwin(vs);
			break;
		case 0x1b:
			sprintf(cp[tmpi][tmpj].s,"%s",tmp);
			mvwprintw(pt2[tmpi][tmpj].vs,0,0,tmp);
			wrefresh(pt2[tmpi][tmpj].vs);
			memset(tmp,'\0',sizeof(tmp));
			break;
		case 's':
			k = 0;
			n = 0;
			l = j;
			m = i;
			memset(tmp,'\0',sizeof(tmp));
			sprintf(tmp,"%s",cp[i][j].s);
			tmpi = i;
			tmpj = j;
			mvwprintw(pt2[i][j].vs,0,0,attr);
			sprintf(cp[i][j].s,"%s",attr);
			break;
		case 'S':
			k = 0;
			n = 0;
			l = j;
			m = i;
			break;
		case 'C':
			sprintf(tmpbuff1,"Copy End.");
		//	mvwprintw(stdscr,LINES-1,1,"%s",tmpbuff1);
			for (o=0;o<256;o++)
				for (p=0;p<78;p++)
					memset(copybuff[o][p],'\0',256);
			for (k=l,o=0;k<j;k++)
			{
				for (n=m,p=0;n<i;n++)
				{
					sprintf(copybuff[p][o],"%s",cp[n][k].s);
					p++;
				}
				o++;
			}
			l = o;
			m = p;
			break;
		case 'P':
			for (k=j,o=0;k<j+l;k++)
			{
				for (n=i,p=0;n<i+m;n++)
				{
					sprintf(cp[n][k].s,"%s",copybuff[p][o]);
					mvwprintw(pt2[n][k].vs,0,0,copybuff[p][o]);
					wrefresh(pt2[n][k].vs);
					p++;
				}
				o++;
			}
			break;
		case 'e':
			if(strcmp(attr,".") == 0)
			{
				for (k=l;k<j;k++)
				{
					for (n=m;n<i;n++)
					{
						mvwprintw(pt2[n][k].vs,0,0,attr);
						sprintf(cp[n][k].s,"%s",attr);
						wrefresh(pt2[n][k].vs);
					}
				}
			}
			else
			for (k=l;k<j;k++)
			{
				mvwprintw(pt2[m][k].vs,0,0,"[");
				sprintf(cp[m][k].s,"%s","[");
				wrefresh(pt2[m][k].vs);
				for (n=m+1;n<i-1;n++)
				{
					if(!((n-m)%2))
					{
						mvwprintw(pt2[n][k].vs,0,0,field);
						sprintf(cp[n][k].s,"%s",field);
						wrefresh(pt2[n][k].vs);
						if(!((n-m)%4))
						{
							mvwprintw(pt2[n][k].vs,0,0,action);
							sprintf(cp[n][k].s,"%s",action);
							wrefresh(pt2[n][k].vs);
						}
					}
					else
					{
						if(!((n-m)%3))
						{
							mvwprintw(pt2[n][k].vs,0,0,skipstep);
							sprintf(cp[n][k].s,"%s",skipstep);
							wrefresh(pt2[n][k].vs);
						}
						else
						{
							mvwprintw(pt2[n][k].vs,0,0,attr);
							sprintf(cp[n][k].s,"%s",attr);
							wrefresh(pt2[n][k].vs);
						}
					}
					if((n-m) > 4)
					{
						mvwprintw(pt2[n][k].vs,0,0,field);
						sprintf(cp[n][k].s,"%s",field);
						wrefresh(pt2[n][k].vs);
					}
				}
				mvwprintw(pt2[n][k].vs,0,0,"]");
				sprintf(cp[n][k].s,"%s","]");
				wrefresh(pt2[n][k].vs);
			}
			memset(tmp,'\0',sizeof(tmp));
			break;
		case 'E':
			for (k=l;k<j;k++)
			{
				mvwprintw(pt2[m][k].vs,0,0,"<");
				sprintf(cp[m][k].s,"%s","<");
				wrefresh(pt2[m][k].vs);
				for (n=m+1;n<i-1;n++)
				{
					if(!((n-m)%2))
					{
						mvwprintw(pt2[n][k].vs,0,0,field);
						sprintf(cp[n][k].s,"%s",field);
						wrefresh(pt2[n][k].vs);
						if(!((n-m)%4))
						{
							mvwprintw(pt2[n][k].vs,0,0,action);
							sprintf(cp[n][k].s,"%s",action);
							wrefresh(pt2[n][k].vs);
						}
					}
					else
					{
						if(!((n-m)%3))
						{
							mvwprintw(pt2[n][k].vs,0,0,skipstep);
							sprintf(cp[n][k].s,"%s",skipstep);
							wrefresh(pt2[n][k].vs);
						}
						else
						{
							mvwprintw(pt2[n][k].vs,0,0,attr);
							sprintf(cp[n][k].s,"%s",attr);
							wrefresh(pt2[n][k].vs);
						}
					}
					if((n-m) > 4)
					{
						mvwprintw(pt2[n][k].vs,0,0,field);
						sprintf(cp[n][k].s,"%s",field);
						wrefresh(pt2[n][k].vs);
					}
				}
				mvwprintw(pt2[n][k].vs,0,0,">");
				sprintf(cp[n][k].s,"%s",">");
				wrefresh(pt2[n][k].vs);
			}
			memset(tmp,'\0',sizeof(tmp));
			break;
		case '':
			for (k=l;k<j;k++)
			{
				mvwprintw(pt2[m][k].vs,0,0,"(");
				sprintf(cp[m][k].s,"%s","(");
				wrefresh(pt2[m][k].vs);
				for (n=m+1;n<i-1;n++)
				{
					if(!((n-m)%2))
					{
						mvwprintw(pt2[n][k].vs,0,0,field);
						sprintf(cp[n][k].s,"%s",field);
						wrefresh(pt2[n][k].vs);
						if(!((n-m)%4))
						{
							mvwprintw(pt2[n][k].vs,0,0,action);
							sprintf(cp[n][k].s,"%s",action);
							wrefresh(pt2[n][k].vs);
						}
					}
					else
					{
						if(!((n-m)%3))
						{
							mvwprintw(pt2[n][k].vs,0,0,skipstep);
							sprintf(cp[n][k].s,"%s",skipstep);
							wrefresh(pt2[n][k].vs);
						}
						else
						{
							mvwprintw(pt2[n][k].vs,0,0,attr);
							sprintf(cp[n][k].s,"%s",attr);
							wrefresh(pt2[n][k].vs);
						}
					}
					if((n-m) > 4)
					{
						mvwprintw(pt2[n][k].vs,0,0,field);
						sprintf(cp[n][k].s,"%s",field);
						wrefresh(pt2[n][k].vs);
					}
				}
				mvwprintw(pt2[n][k].vs,0,0,")");
				sprintf(cp[n][k].s,"%s",")");
				wrefresh(pt2[n][k].vs);
			}
			memset(tmp,'\0',sizeof(tmp));
			break;
		case 'x':
			break;
		case 'y':
			break;
		case 'q':
			if(popmsg((80/2)-24,(LINES/2)-4,(char *)"Exit ase ok?") == 1)
			{
				if(nonopt == 1)
				{
					return(0);
				}
				endwin();
				exit(0);
			}
			touchwin(vs);
			break;
		case 'j': case KEY_DOWN:
			if(j < (xrow-1))
			{
				j++;
			}
			break;
		case 'k': case KEY_UP:
			if(j > 0)
			{
				j--;
			}
			break;
		case 'l': case KEY_RIGHT:
			if(i < xcol-1)
			{
				i++;
			}
			break;
		case 'h': case KEY_LEFT:
			if(i > 0)
			{
				i--;
			}
			break;
		case 't':
			j = 0;
			break;
		case 'G':
			j = xrow-1;
			break;
		case '':
			i = 0;
			break;
		case '':
			i = xcol-1;
			break;
		case 'm':
			j = (xrow-1)/2;
			break;
		case 'M':
			i = (xcol-1)/2;
			break;
		case '0':
			sprintf(tmpbuff1,"%d/%d",cp[i][j].x,cp[i][j].y);
			break;
		}
	}
	echo();
	endwin();
}

int main(int argc, char *argv[])
{
	FILE *fp;
	int i,j,k;
	char *f;
	static char *nl;
	char buff[256 + 1];
	char opt[24];
	int colsel;
	int apinit;
	int xcol,xrow;
	int resp;
	char *vp;

	setlocale(LC_ALL,"");

	aseeditor = new AseEditor();
//	asefiler = new AseLocalFiler();

	if(argc == 1)
	{
	/*
		if((vp = getenv("HOME")) == (char *)NULL)
		{
		
			aseeditor->sys_errmsg(4,10,"環境変数 HOME が設定されていません /home を使用します");
			sprintf(aseeditor->homedirname,"/home");
		}
		else
		{
			sprintf(aseeditor->homedirname,"%s",vp);
		}
		getcwd(aseeditor->startdirname,256 + 1);
		aseeditor->readowner();
		aseeditor->readgroup();

		initscr();
		cbreak();
		noecho();

		colsel = 0;
		apinit = 1;
		readflg = 1;
		nonopt = 1;
		aseeditor->filer(1,54);
		echo();
		endwin();
	*/
		printf("Usage: ase -c[1 - 174] -l[3 - 78] [MAX screen define file name]\n");
		printf("       ase -a [screen define file name] maximum display\n");
		printf("       ase -e -v -x -s -w for 80/24-EGA and 97/29-VGA 125/37-XGA 178/68-WXGA 174/51-SXGA\n");
		exit(0);
	}
	if(argc < 2 || argc > 4)
	{
		printf("Usage: ase -c[1 - 178] -l[3 - 78] file-name\n");
		printf("       ase -[ e v x a] file-name (5 type display and full)\n");
		printf("Help : ase -?\n");
		exit(0);
	}

	f = (char *)malloc(256);
	xcol = 1;
	strcpy(f,argv[argc-1]);
	if(argc < 5 && argc > 2)
	{
		for(i=0;i<argc;i++)
		{
			switch(argv[i][0])
			{
			case '?':
				asehelp();
				exit(0);
				break;
			case '-': case '/':
				if(argv[i][1] == '\0')
					exit(2);
				for(j=1;j < strlen(argv[i]);j++)
				{
					switch(argv[i][j])
					{
					case 'a':
						fulldisplay = 1;
						colsel = 0;
						apinit = 1;
						readflg = 1;
						xcol = COLS - 2;
						xrow = LINES - 1;
						strcpy(f,argv[argc-1]);
						break;
					case '?':
					//	aseeditor->asehelp();
						asehelp();
						exit(0);
					case 'c':
						if(argv[i][2] == '\0')
							exit(2);
						colsel = 0;
						apinit = 1;
						for(k=2;argv[i][k] != 0;k++)
						{
							if(argv[i][k] >= '0' && argv[i][k] <= '9')
							{
								opt[k-2] = argv[i][k];
							}
							else
							{
								break;
							}
						}
						opt[k-2] = '\0';
						xcol = atoi(opt);
						if(xcol < 1)
							xcol = 1;
						if(xcol > 178)
							xcol = 178;
						strcpy(f,argv[argc-1]);
						break;
					case 'l':
						if(argv[i][2] == '\0')
							exit(2);
						colsel = 0;
						apinit = 1;
						for(k=2;argv[i][k] != 0;k++)
						{
							if(argv[i][k] >= '0' && argv[i][k] <= '9')
							{
								opt[k-2] = argv[i][k];
							}
							else
							{
								break;
							}
						}
						opt[k-2] = '\0';
						xrow = atoi(opt);
						if(xrow < 1)
							xrow = 1;
						if(xrow > 78)
							xrow = 78;
						strcpy(f,argv[argc-1]);
						break;
					case 'e':
						apinit = 0;
						xcol = 78;
						xrow = 23;
						colsel = 0;
						apinit = 1;
						readflg = 1;
						strcpy(f,argv[argc-1]);
						break;
					case 'v':
						apinit = 0;
						xcol = 98;
						xrow = 29;
						colsel = 0;
						apinit = 1;
						readflg = 1;
						strcpy(f,argv[argc-1]);
						break;
					case 'x':
						apinit = 0;
						xcol = 126;
						xrow = 37;
						colsel = 0;
						apinit = 1;
						readflg = 1;
						strcpy(f,argv[argc-1]);
						break;
					case 's':
						apinit = 0;
						xcol = 174;
						xrow = 51;
						colsel = 0;
						apinit = 1;
						readflg = 1;
						strcpy(f,argv[argc-1]);
						break;
					case 'w':
						apinit = 0;
						xcol = 178;
						xrow = 68;
						colsel = 0;
						apinit = 1;
						readflg = 1;
						strcpy(f,argv[argc-1]);
						break;
					default:
						break;
					}
				}
				break;
			default:
				break;
			}
		}
	}
	else
	{
		i=0;
		if((fp =fopen(f,"r")) == (FILE *)NULL)
		{
			exit(1);
		}
		while(fgets(buff,256,fp) != (char *)NULL)
		{
			if((nl = strchr(buff,'\n')) != (char *)NULL)
			{
				*nl = '\0';
				i++;
			}
		}
		fclose(fp);
		xcol = strlen(buff);
		xrow = i;
		if(xcol > 178)
		{
			fprintf(stderr,"Over colums 178\n");
			exit(1);
		}
		if(xrow > 78)
		{
			fprintf(stderr,"Over rows 78\n");
			exit(1);
		}
		if(xrow < 3)
		{
			fprintf(stderr,"div rows 3\n");
			exit(1);
		}
		colsel = 0;
		apinit = 1;
		readflg = 1;
	}

	if((stat(f,fptr) == 0) && readflg == 0)
	{
		printf("%s is exist. over write? Y or N: ",f);
		while((resp = getchar()))
		{
			switch(resp)
			{
			case 'y': case 'Y':
				readflg = 1;
				goto exec;
			default:
				goto exec;
			}
		}
	}
exec:
	aseeditor->ase(xcol,xrow,f,1);
err_exit:
	exit(0);
}
