⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nkflib.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 5 页
字号:
0x00,0x00,0x00,0x00,0x25,0x50,0x25,0x53,0x25,0x56,0x25,0x59,0x25,0x5c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* X0201 kana conversion table for han-daguten *//* 90-9F A0-DF */unsigned char ev[]= { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x51,0x25,0x54,0x25,0x57,0x25,0x5a,0x25,0x5d,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* X0208 kigou conversion table *//* 0x8140 - 0x819e */unsigned char fv[] = {0x00,0x00,0x00,0x00,0x2c,0x2e,0x00,0x3a,0x3b,0x3f,0x21,0x00,0x00,0x27,0x60,0x00,0x5e,0x00,0x5f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2d,0x00,0x2f,0x5c,0x00,0x00,0x7c,0x00,0x00,0x60,0x27,0x22,0x22,0x28,0x29,0x00,0x00,0x5b,0x5d,0x7b,0x7d,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x2b,0x2d,0x00,0x00,0x00,0x3d,0x00,0x3c,0x3e,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x24,0x00,0x00,0x25,0x23,0x26,0x2a,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00} ;/* SFILE 簇息簇眶 */static SFILE *ssopen(SFILE *sf, char *string, signed int maxsize, char *md){  char *st;  strcpy(sf->mode,md);  if (strstr(sf->mode,"newstr"))  {      if(maxsize <= sizeof(sfile_buffer))	  st = sfile_buffer;      else	  st = (char *)safe_malloc(maxsize);  }  else    st=string;  sf->pointer=sf->head=(unsigned char *)st;  if (strstr(sf->mode,"stdout"))    sstdout=sf;  else if (strstr(sf->mode,"stdin"))  {    sstdin=sf;    maxsize=strlen((char *)st);  }  sf->tail=sf->head+maxsize;  return sf;}static voidsclose(SFILE *sf){  if (sf==NULL)    return;  if (strstr(sf->mode,"stdout"))      sstdout=NULL;  if (strstr(sf->mode,"stdin"))      sstdin=NULL;  if (strstr(sf->mode,"newstr") && sf->head != (unsigned char *)sfile_buffer)      free(sf->head);}static intsgetc(SFILE *sf){  if (sf==NULL)    return SEOF;  if(sf->pointer<sf->tail)      return (int)*sf->pointer++;  return SEOF;}static intsungetc(int c, SFILE *sf){  if (sf==NULL)    return SEOF;  if (sf->head<sf->pointer) {    *--sf->pointer=(unsigned char)c;    return c;  } else    return SEOF;}static intsputc(int c, SFILE *sf){  if (sf==NULL)    return SEOF;  if (sf->pointer<sf->tail)      return (int)(*sf->pointer++=(unsigned char)c);  return SEOF;}/* public 簇眶 start *//* nkf 戳机コンバ〖ト簇眶 *//* si must be terminated with '\0' */char *nkf_convert(char *si, char *so, int maxsize, char *in_mode, char *out_mode){/* 涟借妄 */  SFILE *fi,*fo;  SFILE xfi,xfo;  int a;  reinit(); /* 蝗脱々 */  if(maxsize == -1)    maxsize = SAFE_CONVERT_LENGTH(strlen(si));  else if(maxsize == 0)    return si;  fi = &xfi;  fo = &xfo;  if (so!=NULL) {    ssopen(fi,si,0,"stdin");    ssopen(fo,so,maxsize,"stdout");  } else {    ssopen(fi,si,0,"stdin");    ssopen(fo,so,maxsize,"newstr stdout");  }/* 恃眶をデフォルト肋年 */  unbuf_f = FALSE;  estab_f = FALSE;  rot_f = FALSE;	/* rot14/43 mode */  input_f = FALSE;	/* non fixed input code	 */  alpha_f = FALSE;	/* convert JIx0208 alphbet to ASCII */  mime_f = FALSE;	/* convert MIME base64 */  broken_f = FALSE;	/* convert ESC-less broken JIS */  iso8859_f = FALSE;	/* ISO8859 through */#ifdef MSDOS  x0201_f = TRUE;	/* Assume JISX0201 kana */#else  x0201_f = NO_X0201;	/* Assume NO JISX0201 */#endif  line = 0;	/* chars in line */  prev = 0;  fold_f  = FALSE;  fold_len  = 0;  kanji_intro = DEFAULT_J;  ascii_intro = DEFAULT_R;  output_mode = ASCII;	/* output kanji mode */  input_mode = ASCII;	/* input kanji mode */  shift_mode = FALSE;	/* TRUE shift out, or X0201  */  mime_mode = FALSE;	/* MIME mode B base64, Q hex */  #if	0/* No X0201->X0208 conversion 染逞カナを铜跟に*/  x0201_f = FALSE;#else/* 染逞カナを链逞にする */  x0201_f = TRUE;#endif/* オプション mode 豺老 */  oconv=e_oconv;  if (strstr(out_mode,"EUCK")||strstr(out_mode,"euck")||strstr(out_mode,"ujisk")){    /*Hankaku Enable (For WRD File )*/    oconv=e_oconv;     /* No X0201->X0208 conversion 染逞カナを铜跟に*/    x0201_f = FALSE;  }  else if (strstr(out_mode,"SJISK")||strstr(out_mode,"sjisk")){    /*Hankaku Enable (For WRD File )*/    oconv=s_oconv;     /* No X0201->X0208 conversion 染逞カナを铜跟に*/    x0201_f = FALSE;  }  else if (strstr(out_mode,"JISK")||strstr(out_mode,"jisk")){    /*Hankaku Enable (For WRD File )*/    oconv=j_oconv;     /* No X0201->X0208 conversion 染逞カナを铜跟に*/    x0201_f = FALSE;  }  else if (strstr(out_mode,"EUC")||strstr(out_mode,"euc")||strstr(out_mode,"ujis"))    oconv=e_oconv;  else if (strstr(out_mode,"SJIS")||strstr(out_mode,"sjis"))    oconv=s_oconv;  else if (strstr(out_mode,"JIS")||strstr(out_mode,"jis"))    oconv=j_oconv;  /* 粕み哈みコ〖ドのチェック */  input_f = -1;  if(in_mode != NULL)  {      if(strstr(in_mode,"EUC")||strstr(in_mode,"euc")||strstr(in_mode,"ujis"))	  input_f = JIS_INPUT;      else if (strstr(in_mode,"SJIS")||strstr(in_mode,"sjis"))	  input_f = SJIS_INPUT;      else if (strstr(in_mode,"JIS")||strstr(in_mode,"jis"))	  input_f = JIS_INPUT;  }  if(input_f == -1)  {      /* Auto detect */      input_f = check_kanji_code((unsigned char *)si);      if(input_f == -1)	  input_f = SJIS_INPUT;      else if(input_f == EUC_INPUT)	  input_f = JIS_INPUT;      if(input_f == SJIS_INPUT && x0201_f == NO_X0201)	  x0201_f = TRUE;  }  /* コンバ〖ト */  kanji_convert(fi);/* 稿借妄 */  sputchar('\0');  if (so==NULL) {    /* Copy `fo' buffer to `si' */    a = fo->pointer - fo->head; /* Stored length */    if(a > maxsize)	a = maxsize;    memcpy(si, fo->head, a); /* Do copy */    so = si;  }  sclose(fi);  sclose(fo);  return so;}char *nkf_conv(char *si, char *so, char *mode){  return nkf_convert(si,so,-1,NULL,mode);}/* public 簇眶 end */#define IS_SJIS_HANKAKU(c)	(0xa0 <= (c) && (c) <= 0xdf)#define IS_SJIS_BYTE1(c)	((0x81 <= (c) && (c) <= 0x9f) ||\				 (0xe0 <= (c) && (c) <= 0xfc))#define IS_SJIS_BYTE2(c)	((0x40 <= (c) && (c) <= 0x7e) ||\				 (0x80 <= (c) && (c) <= 0xfc))#define IS_EUC_BYTE1(c)		(0xa1 <= (c) && (c) <= 0xf4)#ifdef EUC_STRICT_CHECK#define IS_EUC_BYTE2(c)		(0xa1 <= (c) && (c) <= 0xfe)#else#define IS_EUC_BYTE2(c)		(0xa0 <= (c) && (c) <= 0xff)#endif /* EUC_STRICT_CHECK */#ifdef EUC_STRICT_CHECK#define EUC_GAP_LIST_SIZE (16*2)static unsigned int euc_gap_list[EUC_GAP_LIST_SIZE] ={    0xa2af, 0xa2b9,    0xa2c2, 0xa2c9,    0xa2d1, 0xa2db,    0xa2eb, 0xa2f1,    0xa2fa, 0xa2fd,    0xa3a1, 0xa3af,    0xa3ba, 0xa3c0,    0xa3db, 0xa3e0,    0xa3fb, 0xa3fe,    0xa4f4, 0xa4fe,    0xa5f7, 0xa5fe,    0xa6b9, 0xa6c0,    0xa6d9, 0xa6fe,    0xa7c2, 0xa7d0,    0xa7f2, 0xa7fe,    0xa8c1, 0xaffe};#endif /* EUC_STRICT_CHECK */static int check_kanji_code(unsigned char *p){    int c1, c2, mode;    int noteuc;    /* check JIS or ASCII code */    mode = ASCII;    while(*p)    {	if(*p < SPACE || *p >= DEL)	{	    if(*p == ESC)		return JIS_INPUT;	    mode = -1; /* None ASCII */	    break;	}	p++;    }    if(mode == ASCII)	return ASCII;    /* EUC or SJIS */    noteuc = 0;    while(*p)    {        /* skip ASCII */        while(*p && *p <= DEL)	    p++;	if(!*p)	    return -1;	c1 = p[0];	c2 = p[1];	if(c2 == 0)	{	    if(IS_SJIS_HANKAKU(c1))		return SJIS_INPUT;	    return -1;	}	if(IS_SJIS_HANKAKU(c1))	{#ifdef EUC_STRICT_CHECK	    unsigned int c;#endif /* EUC_STRICT_CHECK *//*            0xa0   0xa1              0xdf   0xf4   0xfe             |<-----+---- SH -------->|      |      |     SH: SJIS-HANKAKU                    |<------- E1 ----------->|      |     E1: EUC (MSB)                    |<--------E2------------------->|     E2: EUC (LSB)*/	    if(!IS_EUC_BYTE1(c1) || !IS_EUC_BYTE2(c2))		return SJIS_INPUT;	    if(!IS_SJIS_HANKAKU(c2)) /* (0xdf..0xfe] */		return EUC_INPUT;#ifdef EUC_STRICT_CHECK	    if(!noteuc)	    {		int i;		/* Checking more strictly */		c = (((unsigned int)c1)<<8 | (unsigned int)c2);		for(i = 0; i < EUC_GAP_LIST_SIZE; i += 2)		    if(euc_gap_list[i] <= c && c <= euc_gap_list[i + 1])		    {			noteuc = 1;			break;		    }	    }#endif /* EUC_STRICT_CHECK */	    p += 2;	}	else if(IS_SJIS_BYTE1(c1) && IS_SJIS_BYTE2(c2))	{	    if(!(IS_EUC_BYTE1(c1) && IS_EUC_BYTE2(c2)))		return SJIS_INPUT;	    p += 2;	}	else if(IS_EUC_BYTE1(c1) && IS_EUC_BYTE2(c2))	{	    return EUC_INPUT;	}	else	    p++; /* What?  Is this japanese?  Try check again. */    }    if(noteuc)	return SJIS_INPUT;    return -1;}#ifdef EUC_STRICT_CHECKstatic void fix_euc_code(unsigned char *s, int len){    int i, j, c;    for(i = 0; i < len - 1; i++)    {	if(s[i] & 0x80)	{	    c = (((unsigned int)s[i])<<8 | (unsigned int)s[i + 1]);	    for(j = 0; j < EUC_GAP_LIST_SIZE; j += 2)		if(euc_gap_list[j] <= c && c <= euc_gap_list[j + 1])		{		    s[i] = 0xa1;		    s[i + 1] = 0xa1;		    break;		}	    i++;	}    }}#endif /* EUC_STRICT_CHECK */static int             file_out = FALSE;static int             add_cr = FALSE;static int             del_cr = FALSE;static int             end_check;#if 0#ifndef PERL_XSintmain(argc, argv)    int             argc;    char          **argv;{    FILE  *fin;    char  *cp;#ifdef EASYWIN /*Easy Win */    _BufferSize.y = 400;/*Set Scroll Buffer Size*/#endif    for (argc--,argv++; (argc > 0) && **argv == '-'; argc--, argv++) {        cp = *argv;	arguments(cp);    }    if(iso8859_f && (oconv != j_oconv || !x0201_f )) {        fprintf(stderr,"Mixed ISO8859/JISX0201/SJIS/EUC output is not allowed.\n");        exit(1);    }    if(binmode_f == TRUE)#ifdef __OS2__    if(freopen("","wb",stdout) == NULL) 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -