#include <string.h>

#include "extern.h"

exesign()
	{
		char passw1[9],passw2[9];

		if ( strcmp(hiscall,guestid) )
		{
			long fpos;

			strcpy(ynsent,"パスワードの変更ですね");
			if ( y_or_n() ) return(0);

			strcpy(ssent,"\n          パスワードをどうぞ ==>");  rsout();
			rsin(1); idcpy(passw1,rsent);
			strcpy(ssent,"\nもういちどパスワードをどうぞ ==>"); rsout();
			rsin(1); idcpy(passw2,rsent);
			if ( strcmp(passw1,passw2) )
				{ strcpy(ssent,"\n二度入れたパスワードが違っています\n");
				  rsout();
				  strcpy(ssent,"登録ができません\n");
				  rsout();
				  return(1);
				}

			fpw = fopen(PASSWORD,"r+");
			while(1)
				{   fpos = ftell(fpw);
					if ( fgets(fbuff,255,fpw) == NULL )  break;
					if ( strncmp(hiscall,fbuff,8) )  continue;
					fseek(fpw,fpos + 9L,0);
					nwdate();
					fprintf(fpw,"%s %s %s",passw1,nowdate,nowtime);
					strcpy(ssent,"\nパスワードの変更を完了しました\n");
					rsout();
					break;
				}						
			fclose(fpw);

			return(0);
		}

		else

		{
			char hisid[9];

			if ( ! signup )  {  strcpy(ssent,"\nこの機能は使用できません\n");
								rsout();
								return(1);
							}
			strcpy(ynsent,"\n当ＢＢＳにＩＤ登録をしますか");
			if ( y_or_n() ) return(1);

			strcpy(ssent,"\n                               +------+\nID をどうぞ(最大８文字まで）==>");
			rsout();
			rsin(0);
			idcpy(hisid,rsent);
			if ( ! strcmp(hisid,"        ") )
				{ printf("\nこの ID は登録できません\n");  rsout();
				  return(1);
				}
			sprintf(ynsent,"\n登録ID は %s ですね",hisid);
			if ( y_or_n() ) return(1);

			fpw = fopen(PASSWORD,"r");
			while( fpw != NULL )
				{
					if ( fgets(fbuff,255,fpw) == NULL )  break;
					if ( strncmp(hisid,fbuff,8) )  continue;
					strcpy(ssent,"\nおなじＩＤをもつかたがおられます\n");
					rsout();
					strcpy(ssent,"\n登録に失敗しました\n");
					rsout();
					fclose(fpw);
					return(1);
				}						
			fclose(fpw);

			strcpy(ssent,"\n          パスワードをどうぞ ==>");  rsout();
			rsin(1); idcpy(passw1,rsent);
			strcpy(ssent,"もういちどパスワードをどうぞ ==>"); rsout();
			rsin(1); idcpy(passw2,rsent);
			if ( strcmp(passw1,passw2) )
				{ strcpy(ssent,"\n\n二度入れたパスワードが違っています\n");
				  rsout();
				  strcpy(ssent,"\n登録ができません\n");
				  rsout();
				  return(1);
				}

			fpw = fopen(PASSWORD,"a");
			nwdate();
			fprintf(fpw,"%s %s %s %s\n",hisid,passw1,nowdate,nowtime);
			strcpy(ssent,"\n登録を完了しました\n");
			rsout();
			fclose(fpw);
			strcpy(hiscall,hisid);
		}
	return(0);
	}

