Nugget
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions
xprintf.c File Reference
#include "psyqo/xprintf.h"
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include "psyqo/alloc.h"
Include dependency graph for xprintf.c:

Classes

struct  s_info
 
struct  s_strargument
 
struct  sgMprintf
 

Macros

#define NINFO   (sizeof(fmtinfo) / sizeof(info)) /* Size of the fmtinfo table */
 
#define BUFSIZE   100 /* Size of the output buffer */
 
#define SPACESIZE   (sizeof(spaces) - 1)
 

Typedefs

typedef struct s_info info
 

Enumerations

enum  e_type {
  RADIX , FIXED , SIZE , STRING ,
  PERCENT , CHAR , ERROR , CHARLIT ,
  SEEIT , MEM_STRING , ORDINAL
}
 

Functions

int vxprintf (void(*func)(const char *, int, void *), void *arg, const char *format, va_list ap)
 Prints a formatted string to a callback.
 
int vsprintf (char *buf, const char *fmt, va_list ap)
 Prints a formatted string to a string.
 
int vsnprintf (char *buf, size_t n, const char *fmt, va_list ap)
 Prints a formatted string to a length-limited string.
 
int vasprintf (char **out, const char *zFormat, va_list ap)
 Prints a formatted string to a newly allocated string.
 

Macro Definition Documentation

◆ BUFSIZE

#define BUFSIZE   100 /* Size of the output buffer */

◆ NINFO

#define NINFO   (sizeof(fmtinfo) / sizeof(info)) /* Size of the fmtinfo table */

◆ SPACESIZE

#define SPACESIZE   (sizeof(spaces) - 1)

Typedef Documentation

◆ info

Initial value:
{
register int n asm("t1") = 0x03

Enumeration Type Documentation

◆ e_type

enum e_type
Enumerator
RADIX 
FIXED 
SIZE 
STRING 
PERCENT 
CHAR 
ERROR 
CHARLIT 
SEEIT 
MEM_STRING 
ORDINAL 

Function Documentation

◆ vasprintf()

int vasprintf ( char **  out,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a newly allocated string.

This function is a helper around vxprintf, which will print to a string, and otherwise behaves the same as normal glibc (v)asprintf. The string will be allocated using psyqo_malloc(), and must be freed using psyqo_free().

Parameters
outThe pointer to the string to allocate.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.

◆ vsnprintf()

int vsnprintf ( char *  buf,
size_t  n,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a length-limited string.

This function is a helper around vxprintf, which will print to a string, and otherwise behaves the same as normal libc (v)snprintf.

Parameters
bufThe buffer to print to.
nThe maximum number of bytes to write, including the terminating null byte.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.

◆ vsprintf()

int vsprintf ( char *  buf,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a string.

This function is a helper around vxprintf, which will print to a string, and otherwise behaves the same as normal libc (v)sprintf.

Parameters
bufThe buffer to print to.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.

◆ vxprintf()

int vxprintf ( void(*)(const char *, int, void *)  func,
void opaque,
const char *  fmt,
va_list  ap 
)

Prints a formatted string to a callback.

This function behaves mostly as you'd expect from a typical printf, with some extra formatting options: The '=' flag (similar to '-') causes the output to be centered in the appropriately sized field. The b field outputs an integer in binary notation. The c field now accepts a precision. The character output is repeated by the number of times the precision specifies. The ' field works like c, but takes as its character the next character of the format string, instead of the next. This is useful for when using the precision modifier. For example, ‘printf("%.78&rsquo;-")` prints 78 minus signs, the same as `printf("%.78c", '-')would. S will display a string that has its control characters escaped using the caret notation. For example, character 26, also known as EOF, will be displayed as ^Z. z will display a string, and immediately dispose of it using psyqo_free()‘. r will display a number as an English ordinal. For example, 1 will be displayed as "1st", 2 as "2nd", etc... Another difference with normal printf, is that %#x will output "0x0" instead of "0" for the value 0. Last but not least, the f, e, and a format specifiers are expecting fixed point values. The scale of the fixed point value will default to 4096 for f and e, and 1024 for a, making it suitable for displaying angles. The scale can be specified using the ’/' sign. For instance, "%8.3/255f" will render a fixed point number using 8 characters, with 3 decimal places, and a scale of 255. The f and a format specifiers will render the fixed point number as a signed number, while the e format specifier will render it as an unsigned one. Finally, the callback function will be called with the string to print, and the length of the string. The third argument will be the opaque pointer passed through. The xprintf variant is also available.

Parameters
funcThe callback function to use.
opaqueThe opaque pointer to pass to the callback.
fmtThe format string.
apThe vararg list of arguments.
Returns
int The number of bytes written.