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

📄 support.c

📁 MIDI解码程序(用VC编写)
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    TiMidity++ -- MIDI to WAVE converter and player    Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>    Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; if not, write to the Free Software    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    support.c - Define missing function                Written by Masanao Izumo <mo@goice.co.jp>*/#ifdef HAVE_CONFIG_H#include "config.h"#endif /* HAVE_CONFIG_H */#include <stdio.h>#include <stdlib.h>#ifdef HAVE_UNISTD_H#include <unistd.h>#endif /* HAVE_UNISTD_H */#include <stdarg.h>#ifdef HAVE_SYS_TIME_H#include <sys/time.h>#endif /* HAVE_SYS_TIME_H */#ifdef HAVE_SYS_TYPES_H#include <sys/types.h>#endif /* HAVE_SYS_TYPES_H */#ifndef NO_STRING_H#include <string.h>#else#include <strings.h>#endif#ifdef __W32__#include <windows.h>#endif /* __W32__ */#ifdef HAVE_SYS_PARAM_H#include <sys/param.h>#endif /* HAVE_SYS_PARAM_H */#include <ctype.h>#include "timidity.h"#include "common.h"#include "mblock.h"#ifdef __MACOS__#include <Threads.h>#endif#ifndef HAVE_VSNPRINTF/* From glib-1.1.13:gstrfuncs.c * Modified by Masanao Izumo <mo@goice.co.jp> */static int printf_string_upper_bound (const char* format,			     va_list      args){  int len = 1;  while (*format)    {      int long_int = 0;      int extra_long = 0;      char c;            c = *format++;            if (c == '%')	{	  int done = 0;	  	  while (*format && !done)	    {	      switch (*format++)		{		  char *string_arg;		  		case '*':		  len += va_arg (args, int);		  break;		case '1':		case '2':		case '3':		case '4':		case '5':		case '6':		case '7':		case '8':		case '9':		  /* add specified format length, since it might exceed the		   * size we assume it to have.		   */		  format -= 1;		  len += strtol (format, (char**) &format, 10);		  break;		case 'h':		  /* ignore short int flag, since all args have at least the		   * same size as an int		   */		  break;		case 'l':		  if (long_int)		    extra_long = 1; /* linux specific */		  else		    long_int = 1;		  break;		case 'q':		case 'L':		  long_int = 1;		  extra_long = 1;		  break;		case 's':		  string_arg = va_arg (args, char *);		  if (string_arg)		    len += strlen (string_arg);		  else		    {		      /* add enough padding to hold "(null)" identifier */		      len += 16;		    }		  done = 1;		  break;		case 'd':		case 'i':		case 'o':		case 'u':		case 'x':		case 'X':#ifdef	G_HAVE_GINT64		  if (extra_long)		    (void) va_arg (args, gint64);		  else#endif	/* G_HAVE_GINT64 */		    {		      if (long_int)			(void) va_arg (args, long);		      else			(void) va_arg (args, int);		    }		  len += extra_long ? 64 : 32;		  done = 1;		  break;		case 'D':		case 'O':		case 'U':		  (void) va_arg (args, long);		  len += 32;		  done = 1;		  break;		case 'e':		case 'E':		case 'f':		case 'g':#ifdef HAVE_LONG_DOUBLE		  if (extra_long)		    (void) va_arg (args, long double);		  else#endif	/* HAVE_LONG_DOUBLE */		    (void) va_arg (args, double);		  len += extra_long ? 64 : 32;		  done = 1;		  break;		case 'c':		  (void) va_arg (args, int);		  len += 1;		  done = 1;		  break;		case 'p':		case 'n':		  (void) va_arg (args, void*);		  len += 32;		  done = 1;		  break;		case '%':		  len += 1;		  done = 1;		  break;		default:		  /* ignore unknow/invalid flags */		  break;		}	    }	}      else	len += 1;    }  return len;}void vsnprintf(char *buff, size_t bufsiz, const char *fmt, va_list ap){    MBlockList pool;    char *tmpbuf = buff;    init_mblock(&pool);    tmpbuf = new_segment(&pool, printf_string_upper_bound(fmt, ap));    vsprintf(tmpbuf, fmt, ap);    strncpy(buff, tmpbuf, bufsiz-1);    buff[bufsiz-1] = '\0';    reuse_mblock(&pool);}#endif /* HAVE_VSNPRINTF */#ifndef HAVE_SNPRINTFvoid snprintf(char *buff, size_t bufsiz, const char *fmt, ...){    va_list ap;    va_start(ap, fmt);    vsnprintf(buff, bufsiz, fmt, ap);    va_end(ap);}#endif /* HAVE_VSNPRINTF */#ifndef HAVE_STRERROR#ifndef HAVE_ERRNO_Hchar *strerror(int errnum) {    static char s[32];    sprintf(s, "ERROR %d", errnum);    return s;}#elsechar *strerror(int errnum){    int i;    static char s[32];    struct {	int id;	char *str;    } error_list[] = {#ifdef EPERM    {EPERM, "Not super-user"},#endif /* EPERM */#ifdef ENOENT    {ENOENT, "No such file or directory"},#endif /* ENOENT */#ifdef ESRCH    {ESRCH, "No such process"},#endif /* ESRCH */#ifdef EINTR    {EINTR, "interrupted system call"},#endif /* EINTR */#ifdef EIO    {EIO, "I/O error"},#endif /* EIO */#ifdef ENXIO    {ENXIO, "No such device or address"},#endif /* ENXIO */#ifdef E2BIG    {E2BIG, "Arg list too long"},#endif /* E2BIG */#ifdef ENOEXEC    {ENOEXEC, "Exec format error"},#endif /* ENOEXEC */#ifdef EBADF    {EBADF, "Bad file number"},#endif /* EBADF */#ifdef ECHILD    {ECHILD, "No children"},#endif /* ECHILD */#ifdef EAGAIN    {EAGAIN, "Resource temporarily unavailable"},#endif /* EAGAIN */#ifdef EWOULDBLOCK    {EWOULDBLOCK, "Resource temporarily unavailable"},#endif /* EWOULDBLOCK */#ifdef ENOMEM    {ENOMEM, "Not enough core"},#endif /* ENOMEM */#ifdef EACCES    {EACCES, "Permission denied"},#endif /* EACCES */#ifdef EFAULT    {EFAULT, "Bad address"},#endif /* EFAULT */#ifdef ENOTBLK    {ENOTBLK, "Block device required"},#endif /* ENOTBLK */#ifdef EBUSY    {EBUSY, "Mount device busy"},#endif /* EBUSY */#ifdef EEXIST    {EEXIST, "File exists"},#endif /* EEXIST */#ifdef EXDEV    {EXDEV, "Cross-device link"},#endif /* EXDEV */#ifdef ENODEV    {ENODEV, "No such device"},#endif /* ENODEV */#ifdef ENOTDIR    {ENOTDIR, "Not a directory"},#endif /* ENOTDIR */#ifdef EISDIR    {EISDIR, "Is a directory"},#endif /* EISDIR */#ifdef EINVAL    {EINVAL, "Invalid argument"},#endif /* EINVAL */#ifdef ENFILE    {ENFILE, "File table overflow"},#endif /* ENFILE */#ifdef EMFILE    {EMFILE, "Too many open files"},#endif /* EMFILE */#ifdef ENOTTY    {ENOTTY, "Inappropriate ioctl for device"},#endif /* ENOTTY */#ifdef ETXTBSY    {ETXTBSY, "Text file busy"},#endif /* ETXTBSY */#ifdef EFBIG    {EFBIG, "File too large"},#endif /* EFBIG */#ifdef ENOSPC    {ENOSPC, "No space left on device"},#endif /* ENOSPC */#ifdef ESPIPE    {ESPIPE, "Illegal seek"},#endif /* ESPIPE */#ifdef EROFS    {EROFS, "Read only file system"},#endif /* EROFS */#ifdef EMLINK    {EMLINK, "Too many links"},#endif /* EMLINK */#ifdef EPIPE    {EPIPE, "Broken pipe"},#endif /* EPIPE */#ifdef EDOM    {EDOM, "Math arg out of domain of func"},#endif /* EDOM */#ifdef ERANGE    {ERANGE, "Math result not representable"},#endif /* ERANGE */#ifdef ENOMSG    {ENOMSG, "No message of desired type"},#endif /* ENOMSG */#ifdef EIDRM    {EIDRM, "Identifier removed"},#endif /* EIDRM */#ifdef ECHRNG    {ECHRNG, "Channel number out of range"},#endif /* ECHRNG */#ifdef EL2NSYNC    {EL2NSYNC, "Level 2 not synchronized"},#endif /* EL2NSYNC */#ifdef EL3HLT    {EL3HLT, "Level 3 halted"},#endif /* EL3HLT */#ifdef EL3RST    {EL3RST, "Level 3 reset"},#endif /* EL3RST */#ifdef ELNRNG    {ELNRNG, "Link number out of range"},#endif /* ELNRNG */#ifdef EUNATCH    {EUNATCH, "Protocol driver not attached"},#endif /* EUNATCH */#ifdef ENOCSI    {ENOCSI, "No CSI structure available"},#endif /* ENOCSI */#ifdef EL2HLT    {EL2HLT, "Level 2 halted"},#endif /* EL2HLT */#ifdef EDEADLK    {EDEADLK, "Deadlock condition."},#endif /* EDEADLK */#ifdef ENOLCK    {ENOLCK, "No record locks available."},#endif /* ENOLCK */#ifdef ECANCELED    {ECANCELED, "Operation canceled"},#endif /* ECANCELED */#ifdef ENOTSUP    {ENOTSUP, "Operation not supported"},#endif /* ENOTSUP */#ifdef EDQUOT    {EDQUOT, "Disc quota exceeded"},#endif /* EDQUOT */#ifdef EBADE    {EBADE, "invalid exchange"},#endif /* EBADE */#ifdef EBADR    {EBADR, "invalid request descriptor"},#endif /* EBADR */#ifdef EXFULL    {EXFULL, "exchange full"},#endif /* EXFULL */#ifdef ENOANO    {ENOANO, "no anode"},#endif /* ENOANO */#ifdef EBADRQC    {EBADRQC, "invalid request code"},#endif /* EBADRQC */#ifdef EBADSLT    {EBADSLT, "invalid slot"},#endif /* EBADSLT */#ifdef EDEADLOCK

⌨️ 快捷键说明

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