#include <stdlib.h>
#include <ctype.h>
#include <string.h>

#include "extern.h"

/* ﾐﾀﾞｼ ﾍﾝｺｳ ｼｮﾘ */
exerename()
   {  
      int i,fnoz,fnumb;
      char title[31],fno[5];
      long ptr;
      
      if ( chgchk() )  return(0);
      strcpy(ssent,": 新しいタイトルをどうぞ(キャンセルは cr )\n");
      strcat(ssent,"       *--------+---------+---------*\n");
      strcat(ssent,"ﾀｲﾄﾙ =>");
      rsout();
      
      rsin(0);
      if ( *(rsent) == '\n' )  { strcpy(ssent,"\n: キャンセルされました\n");
                                 rsout();
                                 return(0);
                               }

	  chktitle();
      
      for ( i = 0 ; i < 30 ; i++ )
          { if (rsent[i] == '\n' || rsent[i] == NULL ) break;
            title[i] = rsent[i];
          }
      
      for ( ; i < 30 ; i++ ) { title[i] = 0x20; }
      title[30] = NULL;
     
   /* ﾌｧｲﾙ No. ﾊｱｸ */
      i = strlen(pfna); i -= 4;
      substr(pfna,i,4,fno);
      fnumb = atoi(fno);

  /* ﾍｯﾀﾞ ﾌｧｲﾙ ｺｳｼﾝ */
	  if ( strcmp(nowjle,mailjle) )  { fpw = fopen(HDR_FIL,"r+"); }
           else                      { fpw = fopen(MAIL_HDR,"r+"); }
      if ( fpw == NULL ) return(0);
      while(1)
        { if ( fgets(fbuff,5,fpw) == NULL ) { fclose(fpw);
                                              return(0);
                                            }
          substr(fbuff,0,4,fno);
          fnoz = atoi(fno);
          if ( ( ! isdigit(*fbuff) ) || fnoz != fnumb  )
             { fgets(fbuff,255,fpw); continue; }
          ptr = ftell(fpw) + 11;
          fseek(fpw,ptr,0);
          fputs(title,fpw);
          break;
       }
     fclose(fpw);
     
  /* ﾒｯｾｰｼﾞ ﾌｧｲﾙ ｺｳｼﾝ */
     fpw = fopen(pfna,"r+");
     if ( fpw == NULL ) return(0);
     fseek(fpw,11L,0);
     fputs(title,fpw);
     fclose(fpw);
     
	 *(fname) = NULL;

     if ( ! strncmp(nowjle,"PDS",3) )
       { 
       makfname("PDS",fnumb,fname);
  	      }

     if ( ! strncmp(nowjle,"DAT",3) )
         { 
      makfname("DAT",fnumb,fname);
         }

	if ( *(fname) )
		{     fpw = fopen(fname,"r+");
         	  if ( fpw == NULL ) return(0);
     		  fseek(fpw,11L,0);
    		  fputs(title,fpw);
     		  fclose(fpw);
     	}

     return(0);
     }
