/* DIVIDE_START=options.c */
/*
	ＮＩＦＴＹのＬＯＧ整理				options.c
*/
#include	"catlog.h"
#include	<time.h>

#define	TEST
#undef	TEST

	int		set_option_sw = NO;

#ifdef	TEST
static	void	ms( char *mes , char *d )
{
	printf("変数<%s>は <%s> です。\n" , mes , d );
}

static	void	md( char *mes , int d )
{
	printf("変数<%s>は %d です。\n" , mes , d );
}

static	void	mi( char *mes , int d )
{
	printf("スイッチ<%s>は " , mes );
	if ( d == YES ) { printf("YES"); } else { printf("NO"); };
	printf(" です。\n");
}

void	main_loop_sub()
{
	mi( "error" , error );
	md( "max_catlog" , max_catlog );

	mi( "MessSw" , MessSw );
	mi( "QuietSw" , QuietSw );
	mi( "NotSearchSubDirSw" , NotSearchSubDirSw );
	mi( "NoPartitionLineSw" , NoPartitionLineSw );
	mi( "MakeNewFile001Sw" , MakeNewFile001Sw );
	mi( "DeleteOldFileSw" , DeleteOldFileSw );
	mi( "search_all_file_sw" , search_all_file_sw );
	mi( "DisplayLogFileSw" , DisplayLogFileSw );
	mi( "collect_1_ID_sw" , collect_1_ID_sw );
	mi( "NoTimeStampFile" , NoTimeStampFile );
	mi( "ExtractLzhFileSw" , ExtractLzhFileSw );

	get_yesno();

	mi( "Print_Del_Mes_Hyoudai" , Print_Del_Mes_Hyoudai );
	mi( "UpdateLzhFileSw" , UpdateLzhFileSw );
	mi( "ResortLogSw" , ResortLogSw );
	mi( "BreakCatlogSw" , BreakCatlogSw );
	mi( "DoStage1Sw" , DoStage1Sw );
	mi( "DoStage2Sw" , DoStage2Sw );
	mi( "DoStage3Sw" , DoStage3Sw );

	md( "touroku_su" , touroku_su );
	md( "hatugen_su" , hatugen_su );
	md( "max_mojisu" , max_mojisu );

	ms( "collect_1_ID" , collect_1_ID );
	ms( "OutDir" , OutDir );
	ms( "InDir" , InDir );
	ms( "TmpDir" , TmpDir );
}
#endif	/* TEST */

static	void	append_dir( char *path )
{
	char	*p;

	if ( *path == '\0' )									return;
	p = path;
	while ( *p )	p++;
	if (	*(p-1) != ':'
	&&		*(p-1) != '\\'
	) {							*p++ = '\\';	*p = '\0';		};
	touppers( path );
}

struct	Command {
		char	*mes;				/* 画面表示文字列 */
		char	*sw_name;			/* CATLOG.DEF内のスイッチの綴り */
		void	(*func)( int sw );	/* 関数へのポインタ なければNULL */
};

static	void	DisplaySwSet( int sw ){
	if ( sw == TRUE ) {
		MessSw = YES;	QuietSw = NO;	DisplayLogFileSw = YES;
	} else {
		MessSw = YES;	QuietSw = NO;	DisplayLogFileSw = NO;
	};
}

static	void	SilenceSwSet( int sw )
{
	if ( sw == TRUE ) {		MessSw = NO;
	} else {				MessSw = YES;
	};
};

static	void	ShutUpSwSet( int sw )
{
	if ( sw == TRUE ) {		MessSw = NO;	QuietSw = YES;
	} else {				MessSw = YES;	QuietSw = NO;
	};
};

static	void	NoDirSwSet( int sw )
{
	if ( sw == TRUE ) {	NotSearchSubDirSw = YES;
	} else {			NotSearchSubDirSw = NO;
	};
};

static	void	NewFile001SwSet( int sw )
{
	if ( sw == TRUE ) {	MakeNewFile001Sw = YES;
	} else {			MakeNewFile001Sw = NO;
	};
};

static	void	NewFilex01SwSet( int sw )
{
	if ( sw == TRUE ) {	MakeNewFileX01Sw = YES;
	} else {			MakeNewFileX01Sw = NO;
	};
};

static	void	NewFilesmallSwSet( int sw )
{
	if ( sw == TRUE ) {	MakeNewFileSmallSw = YES;
	} else {			MakeNewFileSmallSw = NO;
	};
};

static	void	PartitionSwSet( int sw )
{
	if ( sw == TRUE ) {	NoPartitionLineSw = YES;
	} else {			NoPartitionLineSw = NO;
	};
};

static	void	DelOldFileSwSet( int sw )
{
	if ( sw == TRUE ) {	DeleteOldFileSw = YES;
	} else {			DeleteOldFileSw = NO;
	};
};

static	void	ForcedDelOldFileSwSet( int sw )
{
	if ( sw == TRUE ) {	ForcedDeleteOldFileSw = YES;
	} else {			ForcedDeleteOldFileSw = NO;
	};
};

static	void	DelFAPXResFileSwSet( int sw )	/* FAPXのRESファイルの削除 */
{
	if ( sw == TRUE ) {	DeleteFapxResFileSw = YES;
	} else {			DeleteFapxResFileSw = NO;
	};
};

static	void	SearchAllFileSwSet( int sw )
{
	if ( sw == TRUE ) {	search_all_file_sw = YES;
	} else {			search_all_file_sw = NO;
	};
};

static	void	WithoutHPSwSet( int sw )
{
	if ( sw == TRUE ) {	WithoutHPSaySw = YES;
	} else {			WithoutHPSaySw = NO;
	};
};

static	void	WithoutPATIOSwSet( int sw )
{
	if ( sw == TRUE ) {	WithoutPATIOSaySw = YES;
	} else {			WithoutPATIOSaySw = NO;
	};
};

static	void	WithoutMESSwSet( int sw )
{
	if ( sw == TRUE ) {	WithoutMESSaySw = YES;
	} else {			WithoutMESSaySw = NO;
	};
};

static	void	WithoutMAILSwSet( int sw )
{
	if ( sw == TRUE ) {	WithoutMAILSaySw = YES;
	} else {			WithoutMAILSaySw = NO;
	};
};

static	void	WithoutLIBSwSet( int sw )
{
	if ( sw == TRUE ) {	WithoutLIBSaySw = YES;
	} else {			WithoutLIBSaySw = NO;
	};
};

static	void	WithoutBILLSwSet( int sw )
{
	if ( sw == TRUE ) {	WithoutBILLSaySw = YES;
	} else {			WithoutBILLSaySw = NO;
	};
};

static	void	ReSortLogSwSet( int sw )
{
	if ( sw == TRUE ) {		ResortLogSw = YES;
	} else {				ResortLogSw = NO;
	};
};

static	void	BreakCatlogSwSet( int sw )
{
	if ( sw == TRUE ) {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = NO;
		BreakCatlogSw = YES;
	} else {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;
	};
};

static	void	ContinueSwSet( int sw )
{
	if ( sw == TRUE ) {
		DoStage1Sw = NO;	DoStage2Sw = NO;	DoStage3Sw = YES;
		BreakCatlogSw = NO;	main_loop();		/* すぐ実行する */
	} else {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;
	};
};

static	void	ForumNameLineSwSet( int sw )
{
	if ( sw == TRUE ) {	DelForumNameLineSw = 0;
	} else {			DelForumNameLineSw = 1;
	};
};

static	void	TimeStampFileSwSet( int sw )
{
	if ( sw == TRUE ) {	NoTimeStampFile = YES;
	} else {			NoTimeStampFile = NO;
	};
};

static	void	QuoteAllSaySwSet( int sw )
{
	if ( sw == TRUE ) {	QuoteAllSaySw = YES;
	} else {			QuoteAllSaySw = NO;
	};
};

static	void	SetTimeStampSwSet( int sw )
{
	if ( sw == TRUE ) {	NoTimeStampFile = NO;
	} else {			NoTimeStampFile = YES;
	};
};

static	void	ExtractLZHFileSwSet( int sw )
{
	if ( sw == TRUE ) {	ExtractLzhFileSw = YES;
	} else {			ExtractLzhFileSw = NO;
	};
};

static	void	PrintDelMesHyoudaiSwSet( int sw )
{
	if ( sw == TRUE ) {	Print_Del_Mes_Hyoudai = YES;
	} else {			Print_Del_Mes_Hyoudai = NO;
	};
};

static	void	DeleteDeletedSaySwSet( int sw )	/* 削除した発言は削除する */
{
	if ( sw == TRUE ) {	DeleteDeletedSaySw = YES;
	} else {			DeleteDeletedSaySw = NO;
	};
};

static	void	UpdateLZHFileSwSet( int sw )
{
	if ( sw == TRUE ) {	UpdateLzhFileSw = YES;
	} else {			UpdateLzhFileSw = NO;
	};
};

static	void	DoFromStage2SwSet( int sw )
{
	if ( sw == TRUE ) {
		DoStage1Sw = NO;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;	main_loop();		/* すぐ実行する */
	} else {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;
	};
};

static	void	DoFromStage3SwSet( int sw )
{
	if ( sw == TRUE ) {
		DoStage1Sw = NO;	DoStage2Sw = NO;	DoStage3Sw = YES;
		BreakCatlogSw = NO;	main_loop();		/* すぐ実行する */
	} else {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;
	};
};

static	void	DoOnlyStage1SwSet( int sw )
{
	if ( sw == TRUE ) {
		DoStage1Sw = YES;	DoStage2Sw = NO;	DoStage3Sw = NO;
		BreakCatlogSw = NO;
	} else {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;
	};
};

static	void	DoOnlyStage2SwSet( int sw )
{
	if ( sw == TRUE ) {
		DoStage1Sw = NO;	DoStage2Sw = YES;	DoStage3Sw = NO;
		BreakCatlogSw = NO;	main_loop();		/* すぐ実行する */
	} else {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;
	};
};
static	void	DoOnlyStage3SwSet( int sw )
{
	if ( sw == TRUE ) {
		DoStage1Sw = NO;	DoStage2Sw = NO;	DoStage3Sw = YES;
		BreakCatlogSw = NO;	main_loop();		/* すぐ実行する */
	} else {
		DoStage1Sw = YES;	DoStage2Sw = YES;	DoStage3Sw = YES;
		BreakCatlogSw = NO;
	};
};

static	void	MakeIndexFromCATLOGFile( int sw )
{
	if ( sw == TRUE ) {
		set_option_sw = YES;
		check_index_mode();					/* makeidx.c */
		check_MakeUpMAIL_mode();			/* sortlog.c */
		makeidx_from_catlog_file_main();	/* makeidx.c */
	};
}

static	char	*Kiken_na_Switch[] = {
			"このスイッチは危険なスイッチなので設定できません",
			"このスイッチは本当に危険なスイッチなので設定できません",
			"そんなに言ってもだめですよ",
			"だめはだめなんです",
			"…………………………",
			"わかりました もう１回設定して下さい 設定されます"
};
static	AnswerAllYesCount=0;
static	void	AnswerAllYesSwSet( int sw )
{
	if ( AnswerAllYesCount < 6 ) {
		printf( "%s。\n", Kiken_na_Switch[ AnswerAllYesCount++ ] );
		return;
	};
	if ( sw == TRUE ) {		answer_all_sw = YES;	AnswerSw = YES;
	} else {				answer_all_sw = NO;
	};
}

static	AnswerAllNoCount=0;
static	void	AnswerAllNoSwSet( int sw )
{
	if ( AnswerAllNoCount < 6 ) {
		printf( "%s。\n", Kiken_na_Switch[ AnswerAllNoCount++ ] );
		return;
	};
	if ( sw == TRUE ) {		answer_all_sw = YES;	AnswerSw = NO;
	} else {				answer_all_sw = NO;
	};
}

static	void	CancelAnswerAllSwSet( int sw )
{
	AnswerAllYesCount= AnswerAllNoCount= 0;
	printf( "危険なスイッチを解除しましたね。良かった良かった。\n" );
	if ( sw == TRUE ) {		answer_all_sw = NO;
	} else {				answer_all_sw = NO;
	};
}

static	void	ClearCollectID( int sw )
{
	max_collect_ID = 0;
};

/************************************/
/* メールは１つのファイルで処理する */
/************************************/
static	void	MakeUpMAILInto1FileSwSet( int sw )
{
	if ( sw == TRUE ) {		MakeUpMAILInto1FileSw = YES;
	} else {				MakeUpMAILInto1FileSw = NO;
	};
}

static	struct	Command	MainCommand[] = {
	{"ログ表示する",				"Display",			DisplaySwSet		},
	{"静かに!! モードで実行",		"Silence",			SilenceSwSet		},
	{"だまれ!! モードで実行",		"Shut-up",			ShutUpSwSet			},
	{"ｻﾌﾞ･ﾃﾞｨﾚｸﾄﾘの検索を行わない",	"No-dir",			NoDirSwSet			},
	{"発言番号x01で新ﾌｧｲﾙを作る",	"New-file-x01",		NewFilex01SwSet		},
	{"発言番号001で新ﾌｧｲﾙを作る",	"New-file-001",		NewFile001SwSet		},
	{"より小さな発言番号で新ﾌｧｲﾙ",	"New-file-small",	NewFilesmallSwSet	},
	{"｢*****log整理｣を入れない",	"No-partition",		PartitionSwSet		},
	{"今日より古いﾌｧｲﾙの削除",		"Del-old-file",		DelOldFileSwSet		},
	{"今日より古いﾌｧｲﾙの強制削除",	"Forced-Del-old-file",
			ForcedDelOldFileSwSet											},
	{"FAPX の RES ﾌｧｲﾙの削除",		"Del-FAPX-RES-file",DelFAPXResFileSwSet	},
	{"全てのﾌｧｲﾙを検索の対象に",	"Search-all-file",	SearchAllFileSwSet	},

	{"ＨＰは整理しない",			"Without-HP",		WithoutHPSwSet		},
	{"ＰＡＴＩＯは整理しない",		"Without-PATIO",	WithoutPATIOSwSet	},
	{"会議室は整理しない",			"Without-MES",		WithoutMESSwSet		},
	{"ＭＡＩＬは整理しない",		"Without-MAIL",		WithoutMAILSwSet	},
	{"ＬＩＢは整理しない",			"Without-LIB",		WithoutLIBSwSet		},
	{"ＢＩＬＬは整理しない",		"Without-BILL",		WithoutBILLSwSet	},

	{"再度 sort しなおす",			"Re-sort-log",		ReSortLogSwSet		},
	{"処理を途中で中断する",		"Break-catlog",		BreakCatlogSwSet	},
	{"処理を続行する",				"Continue-catlog",	ContinueSwSet		},
	{"-FRAV MES(xx)の行を削除",
		"Del-forum-name-line",							ForumNameLineSwSet	},
	{"整理済のﾌｧｲﾙからｲﾝﾃﾞｯｸｽを作る",
		"Make-Index-from-CATLOG-File",				MakeIndexFromCATLOGFile	},
	{"全ての質問にＹＥＳと答える",	"Answer-All-YES",	AnswerAllYesSwSet	},
	{"全ての質問にＮＯと答える",	"Answer-All-NO",	AnswerAllNoSwSet	},
	{"コンソール入力を許可する",
		"Cancel-Answer-All-Sw",						CancelAnswerAllSwSet	},
	{"全部引用発言とする",			"Quote-All-Say",	QuoteAllSaySwSet	},
	{"CATLOG.DONﾌｧｲﾙを作らない",
		"No-Time-Stamp-file",							TimeStampFileSwSet	},
	{"CATLOG.DONﾌｧｲﾙを作る",
		"Set-Time-Stamp-file",							SetTimeStampSwSet	},
	{"*.lzhﾌｧｲﾙを解凍する",			"Extract-LZH-file",	ExtractLZHFileSwSet	},
	{"整理しない発言の表題を表示",
		"Print-Del-Mes-Hyoudai",					PrintDelMesHyoudaiSwSet	},
	{"削除した発言は削除する",
		"Delete-Deleted-Say",						DeleteDeletedSaySwSet	},
	{"ﾛｸﾞをﾃﾞｨﾚｸﾄﾘ毎に凍結",		"Update-LZH-file",	UpdateLZHFileSwSet	},
	{"clear Collect-ID",			"Clear-Collect-ID",	ClearCollectID		},
	{"メールは１つのﾌｧｲﾙで処理する",
		"MakeUpMAIL-Into1File",						MakeUpMAILInto1FileSwSet},
	{"第２段階から実行",	"Do-from-stage-2",	DoFromStage2SwSet		},
	{"第３段階から実行",	"Do-from-stage-3",	DoFromStage3SwSet		},
	{"第１段階のみ実行",	"Do-only-stage-1",	DoOnlyStage1SwSet		},
	{"第２段階のみ実行",	"Do-only-stage-2",	DoOnlyStage2SwSet		},
	{"第３段階のみ実行",	"Do-only-stage-3",	DoOnlyStage3SwSet		},
	{"",					"",					CATLOG_exit				}
};

#define		OP_FILE		1
#define		OP_DIR		2
#define		OP_DATE		3
#define		OP_ID		4
#define		OP_MODE		5
#define		OP_DIGIT	6

struct	Op_Command {
		char	*mes;				/* 画面表示文字列 */
		char	*sw_name;			/* CATLOG.DEF内のｽｲｯﾁの綴り */
		void	(*func)( char * );	/* 関数へのポインタ */
		int		opType;				/* オプションのタイプ */
};

static	void	IndexPathSet( char *str )
{
	strcpy( IndexDir, str );	append_dir( IndexDir );
};
static	void	IndexModeSet( char *str ){	IndexMode = atoi( str );	};
static	void	FAPXLOGModeSet( char *str )
{
	FapxLogMode = atoi( str );
};

static	void	MojisuSet( char *str ){	max_mojisu = atol( str ) * 1024L;};
static	void	OutputDirSet( char *str ){
	strcpy( OutDir , str );			append_dir( OutDir );
};

static	void	OutputDLListdirSet( char *str ){
	strcpy( DLListDir , str );	append_dir( DLListDir );
};

static	void
OutputMESListdirSet_sub( const char *f_name , const char *f_n )
{
			int		done;
	FILE	*fp;
			char	*p;

	done  = isCATLOGFile( f_name );
	if ( done == 0 )		return;
	if ( ( fp=fopen( f_name , "r" ) ) == NULL ) {
		/* 起こり得ないエラー */
		strcpy( file_name , f_name );
		error_open_file( "OutputMESListdirSet_loop(read)" );
	};
	fgets( str , LINE , fp );
	p = str;	while( *p != ' ' ) p++;		*p = '\0';
	if ( done > 0 ) {					/* フォーラムの会議室 */
		fgets( str , LINE , fp );	fgets( str , LINE , fp );
	};
	fclose( fp );
	without_crlf( str );
	if ( ( fp = fopen( MesKaigiListDir , "a" ) ) == NULL ) {
		strcpy( file_name , MesKaigiListDir );
		error_open_file( "OutputMESListdirSet_loop(write)" );
	};
	fprintf( fp , "%s\n%s\n\n" , f_name , str );
	fclose( fp );
}

static	void	OutputMESListdirSet( char *str )
{
	set_option_sw = YES;
	strcpy( MesKaigiListDir , str );
	catlog_findfirst_mes_sw = NO;
	catlog_findfirst( OutDir, OutputMESListdirSet_sub, YES, YES );
};

static	void
OutputBATFileSet_sub( const char *f_name , const char *f_n )
{
			int		done;
	FILE	*fp;
			char	*p;

	done  = isCATLOGFile( f_name );
	if ( done == 0 )		return;
	if ( ( fp=fopen( f_name , "r" ) ) == NULL ) {
		/* 起こり得ないエラー */
		strcpy( file_name , f_name );
		error_open_file( "OutputBATFileSet_sub(read)" );
	};
	fgets( str , LINE , fp );
	p = str;	while( *p != ' ' ) p++;		*p = '\0';
	if ( done > 0 ) {					/* フォーラムの会議室 */
		fgets( str , LINE , fp );	fgets( str , LINE , fp );
	};
	fclose( fp );
	without_crlf( str );
	if ( ( fp = fopen( MesKaigiListDir , "a" ) ) == NULL ) {
		strcpy( file_name , MesKaigiListDir );
		error_open_file( "OutputBATFileSet_sub(write)" );
	};
	fprintf( fp , "rem\t%s\nren\t%s\t%s\n\n" , str , f_name , f_n );
	fclose( fp );
}

static	void	OutputBATFileSet( char *str )
{
	set_option_sw = YES;
	strcpy( MesKaigiListDir , str );
	catlog_findfirst_mes_sw = NO;
	catlog_findfirst( OutDir, OutputBATFileSet_sub, YES, YES );
};

static	void	TempdirSet( char *str )
{
	char	*p;

	strcpy(TmpDir,str);	append_dir( TmpDir );
	p= TmpDir;	while ( *p ) p++;
	if (	*(p-1) == ':'
	||		strcmp( TmpDir+1, ":\\") == 0
	)	strcat( TmpDir, "catlog.tmp\\" );
	check_and_make_output_path( TmpDir );
};
/*************************/
/* ','で区切って指定する */
/* 終了は行末 or ';'     */
/*************************/
static	void	SearchfileSet( char *str0 )
{
	char	*p;

	while( *str0 ) {
		str0= skip_space( str0 );
		if ( *str0 == '\0' )	break;
		if ( *str0 == ',' )	{	str0++;	continue;	};
		if ( *str0 == ';' )	break;
		p = str;
		while( *str0 ) {
			if ( isspace( *str0 ) )	break;
			if ( *str0 == ',' )		break;
			if ( *str0 == ';' )		break;
			*p++ = *str0++;
		};
		*p = '\0';
		if ( strlen( str ) > 12 ) {
			printf("S:%s はファイルの長さが長過ぎます",str);
		};
		p = str;
		touppers( str );
		if ( maxSearchFileName >= MAX_SEARCH_FILE ) {
			printf("\nこれ以上 S:xxxxx の指定はできません。\n" );
			return;
		};
		strcpy( SearchFileName[ maxSearchFileName++ ] , str );
		str0= skip_space( str0 );
		if ( *str0 == ',' )	str0++;
		if ( *str0 == ';' )	break;
	};
};

static	void
InputDirSet( char *str0 )
{
	char	*p;

	if ( *str0 == '\0' ) {
		set_option_sw = NO;
		maxInPutPath = 0;	return;
	};

	while( *str0 ) {
		str0= skip_space( str0 );
		if ( *str0 == '\0' )	break;
		if ( *str0 == ',' )	{	str0++;	continue;	};
		if ( *str0 == ';' )	break;
		p = str;
		while( *str0 ) {
			if ( isspace( *str0 ) )	break;
			if ( *str0 == ',' )		break;
			if ( *str0 == ';' )		break;
			*p++ = *str0++;
		};
		if ( ( str < p ) && ( *(p-1) != '\\' ) )	*p++ = '\\';
		*p = '\0';
		p = str;
		touppers( str );
		if ( maxInPutPath >= MAX_INPUT_PATH ) {
			strcpy(str,"I:xxxxx の指定が多すぎます。");	error_return( str );
		};
		strcpy( InDir[ maxInPutPath++ ] , str );
		str0= skip_space( str0 );
		if ( *str0 == ',' )	str0++;
		if ( *str0 == ';' )	break;
	};
	set_option_sw = YES;
	main_loop();
};

static	void
WithoutInputdirSet( char *str0 )
{
	char	*p;

	set_option_sw = NO;
	if ( *str0 == '\0' ) {
		maxWithoutInPutPath = 0;	return;
	};

	while( *str0 ) {
		str0= skip_space( str0 );
		if ( *str0 == '\0' )	break;
		if ( *str0 == ',' )	{	str0++;	continue;	};
		if ( *str0 == ';' )	break;
		p = str;
		while( *str0 ) {
			if ( isspace( *str0 ) )	break;
			if ( *str0 == ',' )		break;
			if ( *str0 == ';' )		break;
			*p++ = *str0++;
		};
		*p = '\0';
		touppers( str );
		if ( maxWithoutInPutPath >= MAX_WITHOUT_INPUT_PATH ) {
			strcpy(str,"Without-I:xxxxx の指定が多すぎます。");
			error_return( str );
		};
		strcpy( WithoutInPutPath[ maxWithoutInPutPath++ ] , str );
		set_option_sw = YES;
		str0= skip_space( str0 );
		if ( *str0 == ',' )	str0++;
		if ( *str0 == ';' )	break;
	};
};

void	CollectIDSet( char *str )
{
	int		i,sw;
	char	id[ 24 ] , *p;

	while ( *str ) {
		str= skip_space( str );
		if ( *str == ';' )	break;			/* 指定がない */
		if ( *str == '\0' )	break;			/* 指定がない */
		/* ８文字コピー */
		p = id;		sw = TRUE;
		for ( i=0 ; i<8 ; i++ ) {
			if ( ( ! isalpha( *str ) ) && ( ! isdigit( *str ) ) ) {
				sw = FALSE;		break;
			};
			*p++ = *str++;
		};
		*p = '\0';
		/* 大文字にする */
		p = id;		for ( i=0 ; i<8 ; i++ ) *p++ = toupper( *p );
		if ( sw == FALSE || isIDname( id ) == NO ) {
			printf("\n<%s>←ＩＤの指定が間違っていますよ。",id);
			printf("\n英字３文字＋数字５文字で指定して下さい。");
			error_end();
		};
		if ( max_collect_ID >= MAX_COLLECT_ID ) {
			printf("\n検索するＩＤの数が多すぎます。<%d>以下です。\n",
				MAX_COLLECT_ID
			);
			error_end();
		};
		strcpy( CollectIds[ max_collect_ID ] , id );
		max_collect_ID++;
		collect_ID_sw = YES;

		/* 次の指定 */
		str= skip_space( str );

		if ( *str == ',' ) {	str++;		continue;		};
		if ( *str!=';' && *str!='\0' ) {
			/* error */
			printf("<%s>←区切りの指定は','です。\n",str);
			if (isalpha(*str)) continue; /* まあ、次も調べよう */
		};
		return;
	};
};

static	void	CatlogMesFileSet( char *str )
{
	mess_check	printf("\n");
	catlog_mes_file_name_sw = YES;
	strcpy( CatlogMesFileName , str );
	catlog_mes_file_open();	/* すぐｵｰﾌﾟﾝする 1992.9.15 */
};

/* ○月△日以降の発言を集める */
static	void	SearchSayStartDateSet( char *str )
{
	int		i,sw;

	/* YYMMDD の形式で指定 ? */
	sw = TRUE;
	if ( strlen( str ) != 6 ) sw = FALSE;
	for ( i=0 ; i<6 ; i++ ) if ( ! isdigit( str[ i ] ) ) sw = FALSE;
	if ( sw != TRUE ) {
		error_return( "\nYYMMDD（年月日）の６桁の数字で指定して下さい。");
		return;
	};
	strcpy( SearchSayStartDate , str );
	SearchSayStartDateSw = YES;
}

/* □月×日以前の発言を集める */
static	void	SearchSayEndDateSet( char *str )
{
	int		i,sw;

	/* YYMMDD の形式で指定 ? */
	sw = TRUE;
	if ( strlen( str ) != 6 ) sw = FALSE;
	for ( i=0 ; i<6 ; i++ ) if ( ! isdigit( str[ i ] ) ) sw = FALSE;
	if ( sw != TRUE ) {
		error_return( "\nYYMMDD（年月日）の６桁の数字で指定して下さい。");
		return;
	};
	strcpy( SearchSayEndDate , str );
	SearchSayEndDateSw = YES;
}

static	void	MaxTmp0SizeSet( char *str )
{
	max_tmp0_size = atoi( str );
	if ( max_tmp0_size <=0 ) max_tmp0_size = 10240;
}

static	void	IDHandleSet( char *str )
{
	set_option_sw = YES;
	mess_check	print_now_time();
	search_id_name_main( str /* 出力ﾌｧｲﾙ名 */ );		/* search.c */
	mess_check	print_now_time();
}

static	void	SearchIDFromCATLOGFile( char *str )
{
	char	path[ 128 ];

	set_option_sw = YES;
	strcpy( path , str );
	append_dir( path );									/* main.c */
	search_id_mes_main( path );							/* search.c */
}

void	def_file( char *filename );

static	char	*main_set_file_name( char *dst , char *src )
{
	int		i;
	char	*p;

	p = dst;
	for ( i=0 ; i<13 ; i++ ) {
		if ( ! isalnum( *src ) ) {
			if (	*src != '?'
			&&		*src != '*'
			&&		*src != '.'
			&&		*src != '_'
			)	break;
		};
		*p++ = *src++;
	};
	*p = '\0';
	touppers( dst );		/* 大文字にする */
	return( src );
}

static	void	WithoutSearchfileSet( char *str )
{
	char	id[ 24 ];

	if ( *str == '\0' )		return;
	while ( *str ) {
		str= skip_space( str );
		if ( *str == ';' )	break;			/* 指定がない */
		if ( *str == '\0' )	break;			/* 指定がない */
		str = main_set_file_name( id , str );	/* １３文字コピー */
		if ( max_WithoutSearchFileName >= MAX_WITHOUT_SEARCH_FILE ) {
			printf("\n除外するファイル名の指定が多すぎます。<%d>以下です。\n",
				MAX_WITHOUT_SEARCH_FILE );
			error_end();
		};
		strcpy( WithoutSearchFileName[ max_WithoutSearchFileName ] , id );
		max_WithoutSearchFileName++;

		/* 次の指定 */
		str= skip_space( str );

		if ( *str == ',' ) {	str++;		continue;		};
		if ( *str!=';' && *str!='\0' ) {
			/* error */
			printf("<%s>←区切りの指定は','です。\n",str);
			if (isalnum(*str)) continue; /* まあ、次も調べよう */
		};
		break;
	};
};

static	void	WithoutDelFileSwSet( char *str )
{
	char	id[ 24 ];

	if ( *str == '\0' )		return;
	while ( *str ) {
		str= skip_space( str );
		if ( *str == ';' )	break;			/* 指定がない */
		if ( *str == '\0' )	break;			/* 指定がない */
		str = main_set_file_name( id , str );	/* １３文字コピー */
		if ( max_WithoutDelFileName >= MAX_WITHOUT_DEL_FILE ) {
			printf("\nファイル名の指定が多すぎます。<%d>以下です。\n",
				MAX_WITHOUT_DEL_FILE);
			error_end();
		};
		strcpy( WithoutDelFileName[ max_WithoutDelFileName ] , id );
		max_WithoutDelFileName++;

		/* 次の指定 */
		str= skip_space( str );

		if ( *str == ',' ) {	str++;		continue;		};
		if ( *str!=';' && *str!='\0' ) {
			/* error */
			printf("<%s>←区切りの指定は','です。\n",str);
			if (isalnum(*str)) continue; /* まあ、次も調べよう */
		};
		break;
	};
}

static	void	MakeUpDLInto1FileSwSet( char *str )
{
	mess_check	print_now_time();
	MakeUpDLInto1File_main( str );		/* lib.c */
	mess_check	print_now_time();
}

static	void	ForumNameLineModeSwSet( char *str )
{
	DelForumNameLineSw = atoi( str );
};

static	struct	Op_Command main_op_command[] = {
	{"CATLOGのﾒｯｾｰｼﾞを記録するﾌｧｲﾙ",				"CATLOG-MES-FILE:",
		CatlogMesFileSet,		OP_FILE									},
	{"インデックスのパス",							"Index-Path:",
		IndexPathSet,			OP_DIR									},
	{"インデックスのモード",						"Index-Mode:",
		IndexModeSet,			OP_MODE									},
	{"ＦＡＰＸのログ保存のモード",					"FAPX-LOG-Mode:",
		FAPXLOGModeSet,			OP_MODE									},
	{"１ﾌｧｲﾙの大きさ(1Kﾊﾞｲﾄ単位)",					"Moji:",
		MojisuSet,				OP_DIGIT								},
	{"TmpFile のﾃﾞｨﾚｸﾄﾘ指定",						"Set-tmp:",
		TempdirSet,				OP_DIR									},
	{"TmpFile の最大値(1Kﾊﾞｲﾄ単位)",				"Max-TMP0-Size:",
		MaxTmp0SizeSet,			OP_DIGIT								},
	{"出力ﾄﾞﾗｲﾌﾞ:ﾃﾞｨﾚｸﾄﾘ",							"O:",
		OutputDirSet,			OP_DIR									},
	{"出力ﾄﾞﾗｲﾌﾞ:ﾃﾞｨﾚｸﾄﾘ(ﾃﾞｰﾀﾗｲﾌﾞﾗﾘｰ)",				"DL-O:",
		OutputDLListdirSet,		OP_DIR									},
	{"ﾃﾞｰﾀﾗｲﾌﾞﾗﾘｰを1つのﾌｧｲﾙにまとめる",			"MakeUpDL-Into1File:",
		MakeUpDLInto1FileSwSet,	OP_FILE									},
	{"-FRAV MES(xx)の行削除モード",					"DelForumNameLineMode:",
		ForumNameLineModeSwSet,	OP_DIGIT								},
	{"ﾌｧｲﾙと会議室名の関係",						"MES-Name-O:",
		OutputMESListdirSet,	OP_FILE									},
	{"入力ﾄﾞﾗｲﾌﾞ:ﾃﾞｨﾚｸﾄﾘ",							"I:",
		InputDirSet,			OP_DIR									},
	{"読み飛ばす入力ﾃﾞｨﾚｸﾄﾘ",						"Without-I:",
		WithoutInputdirSet,		OP_DIR									},
	{"検索するﾌｧｲﾙ",								"S:",
		SearchfileSet,			OP_FILE									},
	{"検索しないﾌｧｲﾙ",								"Without-S:",
		WithoutSearchfileSet,	OP_FILE									},
	{"○月△日以降の発言を集める",					"Search-Start-Day:",
		SearchSayStartDateSet,	OP_DATE									},
	{"×月□日以前の発言を集める",					"Search-End-Day:",
		SearchSayEndDateSet,	OP_DATE									},
	{"IDの発言を集める",							"CollectId:",
		CollectIDSet,			OP_ID									},
	{"IDの発言を集める",							"Collect-ID:",
		CollectIDSet,			OP_ID									},
	{"１人のIDの発言を集める",						"Collect-1-ID:",
		CollectIDSet,			OP_ID									},
	{"整理済のﾌｧｲﾙからIDで発言の収集",				"Search-ID-I:",
		SearchIDFromCATLOGFile,	OP_DIR									},
	{"ﾌｧｲﾙ名変更用ﾊﾞｯﾁﾌｧｲﾙを作る",					"BAT-Name-O:",
		OutputBATFileSet,		OP_FILE									},
	{"IDとﾊﾝﾄﾞﾙの対応ﾌｧｲﾙを作る",					"ID-Handle:",
		IDHandleSet,			OP_FILE									},
	{"CATLOG.DEFﾌｧｲﾙを指定する",					"f:",
		def_file,				OP_FILE									},
	{"削除から除くﾌｧｲﾙ名",							"Without-Del-FN:",
		WithoutDelFileSwSet,	OP_FILE									},
	{"","",NULL,0														}
};

static	void	main_mes_sub( char *str1, char *str2, int sw )
{
	char	*p;

	if ( sw == 0 ) {
		sprintf( str, "  -%-27s %-8s %s", str1, "", str2 );
	} else {
		switch( sw ) {
			case OP_FILE:	p= "FileName";	break;
			case OP_DIR:	p= "DirName";	break;
			case OP_DATE:	p= "yyddmm";	break;
			case OP_ID:		p= "ID番号";	break;
			case OP_MODE:	p= "1 or 2";	break;
			case OP_DIGIT:	p= "数字";		break;
			default:		p= "xxxxx ";	break;
		};
		sprintf( str, "  -%-23s %-8s     %s", str1, p, str2 );
	};
#ifdef	TYPE_LINUX
	strcat( str , "。" );
#else
	strcat( str , "。\n" );
#endif
	for ( p= str + 4; p < str + 42 ; p++ ) {
		if ( *p == ' ' )	*p = '･';
	};
	puts( str );
}

static	int	main_mes_sw= FALSE;

void	main_mes()
{
	int		i;

	/* ２度実行しないようにする */
	if ( main_mes_sw == TRUE )					return;
	main_mes_sw = TRUE;

	printf("catlog [-options]\n\ntype 1 options is ...\n\n");
	for ( i = 0; strlen( MainCommand[i].mes ) != 0 ; i++ ) {
		main_mes_sub(	MainCommand[i].sw_name,
						MainCommand[i].mes,
						0
		);
	};
	printf("\ntype 2 options is ...\n\n");
	for ( i = 0; strlen( main_op_command[i].mes ) != 0 ; i++ ) {
		main_mes_sub(	main_op_command[i].sw_name,
						main_op_command[i].mes,
						main_op_command[i].opType
		);
	};
/*
	get_yesno();
	putchar( '\n' );
*/
}

void	setOptions( char *str )
{
	int		i , len , sw;
	char	*p;
	void	(*func)( );

	if ( strlen( str ) == 0 ) return;

	for ( i = 0; strlen( MainCommand[i].mes ) != 0 ; i++ ) {
		ForcedEndCheck();
		p = MainCommand[i].sw_name;	len = strlen( p );
		if ( strncmp( str , p , len ) == 0 ) {
			sw = TRUE;
			if ( str[ len ] == '-' )	sw = FALSE;
			func = MainCommand[i].func;	(*func)( sw );
			return;
		};
	};

	for ( i = 0; strlen( main_op_command[i].mes ) != 0 ; i++ ) {
		ForcedEndCheck();
		p = main_op_command[i].sw_name;
		len = strlen( p );
		if ( strncmp( str , p , len ) == 0 ) {
			p = str + len;
			func = main_op_command[i].func;		(*func)( p );
			return;
		};
	};

	printf("\nError Option : <%s>\n\n",str);
	get_yesno();

	main_mes();		error_end( );
}

/* DIVIDE_END */
