esig_asc.c

来自「speech signal process tools」· C语言 代码 · 共 3,198 行 · 第 1/5 页

C
3,198
字号
	if (isalpha(ch) || ch == '_' || ch == ',')	    return FALSE;    }    else    {	ax = (char **) malloc(rank * sizeof(*ax));	if (ax == NULL)	    return FALSE;	i = 0;	do {	    ch = GetNonSpace(file);	    if (isalpha(ch) || ch == '_')	    {		str = NULL;		len = 0;		alloc_len = 0;		if (!AddChar(ch, &str, &alloc_len, &len))		{		    FreeAxisNames(ax, rank);		    return FALSE;		}		for (ch = getc(file);		     isalnum(ch) || ch == '_';		     ch = getc(file))		{		    if (!AddChar(ch, &str, &alloc_len, &len))		    {			FreeAxisNames(ax, rank);			return FALSE;		    }		}		if (!AddChar('\0', &str, &alloc_len, &len))		{		    FreeAxisNames(ax, rank);		    return FALSE;		}		ax[i] = str;		ch = SkipSpace(ch, file);	    }	    else		ax[i] = NULL;	    i++;	} while (ch == ',' && i < rank);	if (ch == ',')	{	    FreeAxisNames(ax, rank);	    return FALSE;	}	else	    for ( ; i < rank; i++)		ax[i] = NULL;    }    ungetc(ch, file);    if (axis_names != NULL)	*axis_names = ax;    return TRUE;}/* * Read from file an "occurrence" construct (which occurs in Ascii field * specifications: <g>, <r>, <o>, <v), or <i>.  Assign the corresponding code * (GLOBAL, REQUIRED, OPTIONAL, VIRTUAL, or INCLUDED) to the variable * whose address is occurrence (unless that argument is NULL). * Return TRUE for success, FALSE for failure. */static intReadAsciiOccurrence(short *occurrence, FILE *file){    int     ch;    int     occ;    ch = GetNonSpace(file);    if (ch != '<')	return FALSE;    switch (getc(file))    {    case 'g':	occ = GLOBAL;	break;    case 'r':	occ = REQUIRED;	break;    case 'o':	occ = OPTIONAL;	break;    case 'v':	occ = VIRTUAL;	break;    case 'i':	occ = INCLUDED;	break;    default:	return FALSE;    }    if (getc(file) != '>')	return FALSE;    if (occurrence != NULL)	*occurrence = occ;    return TRUE;}/* * Read from "file" a sequence of length "length" of values of data * type "type" (in Ascii representation); store the results starting * at the location indicated by "datap".  Return the number of values * successfully read, which will be less than "length" in case of * error. */static intAsciiRead(void	*datap,	  int	type,	  long	length,	  FILE	*file){    long    j;    int     ch;    if (length == 0)	return TRUE;    if (!ReadOptSpace(file))	return 0;    j = 0;    switch (type)    {    case ARRAY:	{	    Array   *data = (Array *) datap;	    do {		ch = getc(file);		if (ch != '(')		    return j;		if (!ReadOptSpace(file)		    || !ReadAsciiArray(&data[j], file))		{		    return j;		}		ch = GetNonSpace(file);		if (ch != ')')		    return j;	    } while (++j < length && ReadSpace(file));	}	break;    case DOUBLE:	{	    double  *data = (double *) datap;	    do {		if (fscanf(file, "%lf", &data[j]) != 1)		    return j;	    } while (++j < length && ReadSpace(file));	}	break;    case FLOAT:	{	    float   *data = (float *) datap;	    do {		if (fscanf(file, "%f", &data[j]) != 1)		    return j;	    } while (++j < length && ReadSpace(file));	}	break;    case LONG:	{	    long    *data = (long *) datap;	    do {		if (fscanf(file, "%ld", &data[j]) != 1)		    return j;	    } while (++j < length && ReadSpace(file));	}	break;    case ULONG:	{	    unsigned long   *data = (unsigned long *) datap;	    do {		if (fscanf(file, "%lu", &data[j]) != 1)		    return j;	    } while (++j < length && ReadSpace(file));	}	break;    case SHORT:	{	    short   *data = (short *) datap;	    do {		if (fscanf(file, "%hd", &data[j]) != 1)		    return j;	    } while (++j < length && ReadSpace(file));	}	break;    case USHORT:	{	    unsigned short  *data = (unsigned short *) datap;	    do {		if (fscanf(file, "%hu", &data[j]) != 1)		    return j;	    } while (++j < length && ReadSpace(file));	}	break;    case SCHAR:	{	    Schar   *data = (Schar *) datap;	    int     n;	    do {		if (fscanf(file, "%d", &n) != 1)		    return j;		data[j] = n;	    } while (++j < length && ReadSpace(file));	}	break;    case UCHAR:	{	    Uchar	*data = (Uchar *) datap;	    unsigned	u;	    do {		if (fscanf(file, "%u", &u) != 1)		    return j;		data[j] = u;	    } while (++j < length && ReadSpace(file));	}	break;    case BOOL:	{	    Bool    *data = (Bool *) datap;	    do {		switch (getc(file))		{		case '0':		    data[j] = 0;		    break;		case '1':		    data[j] = 1;		    break;		default:		    return j;		}	    } while (++j < length && ReadOptSpace(file));	}	break;    case DOUBLE_COMPLEX:	{	    DoubleComplex   *data = (DoubleComplex *) datap;	    double	    re, im;	    do {		if (fscanf(file, "%lf", &re) == 1)		{		    if (!ReadSpace(file)			|| fscanf(file, "%lf", &im) != 1)		    {			return j;		    }		}		else		{		    ch = getc(file);		    if (ch != '(')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%lf", &re) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ',')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%lf", &im) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ')')			return j;		}		data[j].real = re;		data[j].imag = im;	    } while (++j < length && ReadSpace(file));	}	break;    case FLOAT_COMPLEX:	{	    FloatComplex    *data = (FloatComplex *) datap;	    float	    re, im;	    do {		if (fscanf(file, "%f", &re) == 1)		{		    if (!ReadSpace(file)			|| fscanf(file, "%f", &im) != 1)		    {			return j;		    }		}		else		{		    ch = getc(file);		    if (ch != '(')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%f", &re) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ',')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%f", &im) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ')')			return j;		}		data[j].real = re;		data[j].imag = im;	    } while (++j < length && ReadSpace(file));	}	break;    case LONG_COMPLEX:	{	    LongComplex	    *data = (LongComplex *) datap;	    long	    re, im;	    do {		if (fscanf(file, "%ld", &re) == 1)		{		    if (!ReadSpace(file)			|| fscanf(file, "%ld", &im) != 1)		    {			return j;		    }		}		else		{		    ch = getc(file);		    if (ch != '(')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%ld", &re) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ',')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%ld", &im) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ')')			return j;		}		data[j].real = re;		data[j].imag = im;	    } while (++j < length && ReadSpace(file));	}	break;    case SHORT_COMPLEX:	{	    ShortComplex    *data = (ShortComplex *) datap;	    short	    re, im;	    do {		if (fscanf(file, "%hd", &re) == 1)		{		    if (!ReadSpace(file)			|| fscanf(file, "%hd", &im) != 1)		    {			return j;		    }		}		else		{		    ch = getc(file);		    if (ch != '(')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%hd", &re) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ',')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%hd", &im) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ')')			return j;		}		data[j].real = re;		data[j].imag = im;	    } while (++j < length && ReadSpace(file));	}	break;    case SCHAR_COMPLEX:	{	    ScharComplex    *data = (ScharComplex *) datap;	    int		    re, im;	    do {		if (fscanf(file, "%d", &re) == 1)		{		    if (!ReadSpace(file)			|| fscanf(file, "%d", &im) != 1)		    {			return j;		    }		}		else		{		    ch = getc(file);		    if (ch != '(')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%d", &re) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ',')			return j;		    if (!ReadOptSpace(file)			|| fscanf(file, "%d", &im) != 1)		    {			return j;		    }		    ch = GetNonSpace(file);		    if (ch != ')')			return j;		}		data[j].real = re;		data[j].imag = im;	    } while (++j < length && ReadSpace(file));	}	break;    case CHAR:	{	    char	    *data = (char *) datap;	    unsigned long   val;	    ch = getc(file);	    if (ch == '"')	    {		for (j = 0; j < length; j++)		{		    ch = getc(file);		    if (ch == '"')		    {			if (j == 0)			    return j;			ch = GetNonSpace(file);			if (ch != '"')			    return j;			ch = getc(file);		    }		    if (ch == '\\')		    {			if (ReadAsciiEscape(&val, file)			    && val <= UCHAR_MAX)			{			    data[j] = val;			}			else			    return j;		    }		    else if (ch == '"')			return j;		    else if (isprint(ch))			data[j] = ch;		    else			return j;		}		ch = getc(file);		if (ch != '"')		    return j;	    }	    else if (length > 0)		return j;	    else if (ch != EOF)		ungetc(ch, file);	}	break;    case WCHAR:	{	    Wchar	    *data = (Wchar *) datap;	    unsigned long   val;	    ch = getc(file);	    if (ch == '"')	    {		for (j = 0; j < length; j++)		{		    ch = getc(file);		    if (ch == '"')		    {			if (j == 0)			    return j;			ch = GetNonSpace(file);			if (ch != '"')			    return j;			ch = getc(file);		    }		    if (ch == '\\')		    {			if (ReadAsciiEscape(&val, file)			    && val <= USHRT_MAX)			    data[j] = val;			else			    return j;		    }		    else if (ch == '"')			return j;		    else if (isprint(ch))			data[j] = ch;		    else			return j;		}		ch = getc(file);		if (ch != '"')		    return j;	    }	    else if (length > 0)		return j;	    else if (ch != EOF)		ungetc(ch, file);	}	break;    default:	return 0;    }    return j;}/* * Read from file an escape sequence like those in C character constants * and string literals and the Esignal Ascii representations of CHAR * and WCHAR data.  The initial backslash (\) is assumed to have already * been read; this function reads the rest of the construct.  The backslash * can be followed by various single characters, by an octal number with * up to three digits, or by an "x" followed by a hexadecimal number with * any number of digits.  Assign the corresponding Ascii numeric value * to the variable whose address is val (which must not be NULL). */static intReadAsciiEscape(unsigned long	*val,

⌨️ 快捷键说明

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