Найдите 10 различий....
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено ++ 03 сентября 2005 г. 16:43
В ответ на: Нет, наверно ни сильны, иначе бы не дали такой идиотский совет. отправлено haker_fox 03 сентября 2005 г. 15:49


int printf(const char *_format, ...)
{ va_list _ap;
int rval;
char *fptr = (char *)_format;
if(stdout->fd == -1) return (-1);
va_start(_ap, _format);
rval = _printfi(&fptr, _ap, (void *)stdout, _outc, _outs);
va_end(_ap);
return (rval);
}
int sprintf(char *_string, const char *_format, ...)
{ va_list _ap;
int rval;
char *fptr = (char *)_format;
out_end = _string;
va_start(_ap, _format);
rval = _printfi(&fptr, _ap, (void *)_string, _outc, _outs);
*out_end = '\0';
va_end(_ap);
return (rval);
}


/*--------------------------*/
/*****************************************************************************/
/* _PRINTFI - Perform the main printf routine */
/* */
/* This function processes the format string. It copies the format */
/* string into the result string until a '%' is encountered, where any */
/* flags, the field width, the precision, and the type of conversion are */
/* read in, stored in a structure called PFIELD, and passed to _SETFIELD, */
/* where the actual conversion is processed. This function returns */
/* the number of characters output. */
/* */
/*****************************************************************************/
int _printfi(char **_format, va_list _ap, void *_op,
int (*_outc)(char, void *), int (*_outs)(char *, void *))
{
/*------------------------------------------------------------------------*/
/* Local Variables */
/* */
/* *end - A pointer to the end of the format string */
/* *pfield - A pointer to a structure _PFIELD, which stores all of */
/* flags and parameters needed to perform a conversion. */
/*------------------------------------------------------------------------*/
char *end = *_format + strlen(*_format);
int count = 0;
_PFIELD pfield;

/*------------------------------------------------------------------------*/
/* Iterate through the format string until the end of it is reached. */
/*------------------------------------------------------------------------*/
while(*_format < end)
{
/*---------------------------------------------------------------------*/
/* Initialize PFIELD. */
/*---------------------------------------------------------------------*/
pfield.flags = 0;
pfield.fwidth = 0;
pfield.precision = -1;
pfield.conv = 0;

/*---------------------------------------------------------------------*/
/* Copy the format string directly to the target string until a '%' */
/* is encountered. */
/*---------------------------------------------------------------------*/
for(; **_format != '%' && **_format != '\0';
_outc(*((*_format)++), _op), count++);

/*---------------------------------------------------------------------*/
/* If the end of the format string has been reached, break out of the */
/* while loop. */
/*---------------------------------------------------------------------*/
if(! (**_format)) break;

(*_format)++; /* Skip to the character after the '%' */

/*---------------------------------------------------------------------*/
/* Process the flags immediately after the '%'. */
/*---------------------------------------------------------------------*/
_pproc_fflags(&pfield, _format);

/*---------------------------------------------------------------------*/
/* Convert the field width and precision into numbers. */
/*---------------------------------------------------------------------*/
_pproc_fwp(&pfield, _format, &_ap);

/*---------------------------------------------------------------------*/
/* If the h, l, or L flag was specified, set the corresponding flag */
/* in pfield. */
/*---------------------------------------------------------------------*/
if(**_format == 'h' || **_format == 'l' || **_format == 'L')
{
_SET(&pfield, (**_format == 'h') ? _MFH : (**_format == 'l') ?
_MFL : _MFLD);
(*_format)++;
}
/*---------------------------------------------------------------------*/
/* Set the conversion character in pfield. */
/*---------------------------------------------------------------------*/
pfield.conv = *((*_format)++);

/*---------------------------------------------------------------------*/
/* If 'n' is the conversion specifier, process it in this function, */
/* since it is the only one that makes no conversions. It just stores */
/* the number of characters printed so far into the next argument. */
/* Otherwise, call _SETFIELD which performs the conversion. */
/*---------------------------------------------------------------------*/
if(pfield.conv == 'n')
switch (pfield.flags & (_MFL | _MFH))
{
/* The 'l' flag was specified */
case _MFL : *(va_arg(_ap, long*)) = (long)count;
break;

/* The 'h' flag was specified */
case _MFH : *(va_arg(_ap, short*)) = (short)count;
break;

default : *(va_arg(_ap, int*)) = (int)count;
break;

}
else if(pfield.conv == 's')
_pproc_str(&pfield, _op, &_ap, &count, _outs);
else
{
/*------------------------------------------------------------------*/
/* Append the converted string to the result string, and reposition */
/* its iterator, it2. */
/*------------------------------------------------------------------*/
count += _outs(_setfield(&pfield, &_ap), _op);
}
}

return (count);
}


Составить ответ  |||  Конференция  |||  Архив

Ответы



Перейти к списку ответов  |||  Конференция  |||  Архив  |||  Главная страница  |||  Содержание  |||  Без кадра

E-mail: info@telesys.ru