mkerror.c 2.55 KB

/*---------------------------------------------------------------------*
        Copyright (C) 1998 Nintendo.
        
        $RCSfile: mkerror.c,v $
        $Revision: 1.1.1.1 $
        $Date: 2002/05/02 03:28:44 $
 *---------------------------------------------------------------------*/

/*---------------------------------------------------------------------*
        Copyright (C) 1998 Nintendo.
        
        : header,v : 1.2 : 1998/09/17 05:17:19 ---------------------------------------------------------------------*/

#include <stdlib.h>
#ifdef WIN32
#define DEV_U64_DATA	"PARTNER-N64"
#else
#include <sys/u64gio.h> 
#endif
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <ultrahost.h>
#ifndef WIN32 /* { */
#include <unistd.h>
#endif /* } */

#include "sub.h"

char NULLSTR[]={24,0};
FILE *fp,*fp2;

#define s q
#define sb2(x,y)     sbYes(ddd(x),y,0,0)
#define sb3(x,y,z)   sbYes(x,y,z,0)

void sbErrStop2(FILE * p , char * str);

int
sbYes(int x,int y,int z,int k)
{
  return x+y+z+k;
}

void
putLong(s32 val)
{
 u8 buf[4];
  buf[0] = ( val >> 24 ) & 0xFF;
  buf[1] = ( val >> 16 ) & 0xFF;
  buf[2] = ( val >> 8  ) & 0xFF;
  buf[3] = ( val >> 0  ) & 0xFF;
 
  fwrite(buf,sizeof(char),4,fp);
}

char bigbuf[512][1024];

int main(int argc, char **argv)
{
  int c1,c2,i;
  char *t1 ,*t2;
  char buf[1024],_err_no[512],_err_mes[1024];
  long err_num;

  int count=0;

  for(i=0;i<512;i++) bigbuf[i][0]=0;

  sbGetOpts(argv,argc,"h0o:");
  if( TGTPYAS == 1 )
	{
	  t1 = TGTPYA[0] ;
	  t2 = (char *)OPTIA[1];
	}
  else
	{
	  printf("mkerror error.fmt [-o output file]");
	  exit(0);
	}
  fp = sbOpen( t1 ,"r");

  count=0;	

  for(;;)
	{
	  if( feof(fp) ) break;

	  if( fgets(buf,1024,fp) == NULL )
		if( ferror(fp) ) sbErrStop("read error");
		else break;

	  if( sbSplit(buf,'\t',_err_no, _err_mes ) != 2 )
			sbErrStop2(fp,"format error");
  
	  err_num = strtol( _err_no ,NULL ,10 );
	  if( err_num > 511 || err_num <= 0 )
			sbErrStop2(fp,"format error");
	  
	  sprintf( bigbuf[err_num],"%s",_err_mes);

	  ++count;
	} 

  sbClose(fp);

  fp2 = (t2 == NULSTR) ? sbOpen( "oserr.h" ,"w") : sbOpen( t2 ,"w");

  fputs("char NULSTR[1] = {0};\n",fp2);
  fputs("char *__os_error_message[]={\n",fp2);
  fputs("NULSTR,\n",fp2);

  i=0;
  do
	{
	  if( ++i > 511 ) break;
	  if(bigbuf[i][0])
		{
		  fputs(bigbuf[i],fp2);
		  fputs(",",fp2);
		  count--;
		}
	  else
		{
		  fputs("NULSTR,\n",fp2);
		}
	}
  while(count>0); 

  fputs("NULSTR };\n",fp2);

  sbClose(fp2);

  return(0);
}

void
sbErrStop2(FILE * p , char * str)
{
  sbClose(p);
  sbErrStop(str);
}