Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2069 → Rev 2070

/trunk/uspace/fb/fb.c
149,30 → 149,35
}
 
/* Conversion routines between different color representations */
static void rgb_byte0888(void *dst, int rgb)
static void
rgb_byte0888(void *dst, int rgb)
{
*(int *)dst = rgb;
}
 
static int byte0888_rgb(void *src)
static int
byte0888_rgb(void *src)
{
return (*(int *)src) & 0xffffff;
}
 
static void bgr_byte0888(void *dst, int rgb)
static void
bgr_byte0888(void *dst, int rgb)
{
*((uint32_t *) dst) = BLUE(rgb, 8) << 16 | GREEN(rgb, 8) << 8 |
RED(rgb, 8);
}
 
static int byte0888_bgr(void *src)
static int
byte0888_bgr(void *src)
{
int color = *(uint32_t *)(src);
return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) | ((color
>> 16) & 0xff);
return ((color & 0xff) << 16) | (((color >> 8) & 0xff) << 8) |
((color >> 16) & 0xff);
}
 
static void rgb_byte888(void *dst, int rgb)
static void
rgb_byte888(void *dst, int rgb)
{
uint8_t *scr = dst;
#if defined(FB_INVERT_ENDIAN)
186,7 → 191,8
#endif
}
 
static int byte888_rgb(void *src)
static int
byte888_rgb(void *src)
{
uint8_t *scr = src;
#if defined(FB_INVERT_ENDIAN)
197,7 → 203,8
}
 
/** 16-bit depth (5:5:5) */
static void rgb_byte555(void *dst, int rgb)
static void
rgb_byte555(void *dst, int rgb)
{
/* 5-bit, 5-bits, 5-bits */
*((uint16_t *)(dst)) = RED(rgb, 5) << 10 | GREEN(rgb, 5) << 5 |
205,15 → 212,17
}
 
/** 16-bit depth (5:5:5) */
static int byte555_rgb(void *src)
static int
byte555_rgb(void *src)
{
int color = *(uint16_t *)(src);
return (((color >> 10) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x1f) <<
(8 + 3)) | ((color & 0x1f) << 3);
return (((color >> 10) & 0x1f) << (16 + 3)) |
(((color >> 5) & 0x1f) << (8 + 3)) | ((color & 0x1f) << 3);
}
 
/** 16-bit depth (5:6:5) */
static void rgb_byte565(void *dst, int rgb)
static void
rgb_byte565(void *dst, int rgb)
{
/* 5-bit, 6-bits, 5-bits */
*((uint16_t *)(dst)) = RED(rgb, 5) << 11 | GREEN(rgb, 6) << 5 |
221,25 → 230,28
}
 
/** 16-bit depth (5:6:5) */
static int byte565_rgb(void *src)
static int
byte565_rgb(void *src)
{
int color = *(uint16_t *)(src);
return (((color >> 11) & 0x1f) << (16 + 3)) | (((color >> 5) & 0x3f) <<
(8 + 2)) | ((color & 0x1f) << 3);
return (((color >> 11) & 0x1f) << (16 + 3)) |
(((color >> 5) & 0x3f) << (8 + 2)) | ((color & 0x1f) << 3);
}
 
/** Put pixel - 8-bit depth (3:2:3) */
static void rgb_byte8(void *dst, int rgb)
static void
rgb_byte8(void *dst, int rgb)
{
*(uint8_t *)dst = RED(rgb, 3) << 5 | GREEN(rgb, 2) << 3 | BLUE(rgb, 3);
}
 
/** Return pixel color - 8-bit depth (3:2:3) */
static int byte8_rgb(void *src)
static int
byte8_rgb(void *src)
{
int color = *(uint8_t *)src;
return (((color >> 5) & 0x7) << (16 + 5)) | (((color >> 3) & 0x3) <<
(8 + 6)) | ((color & 0x7) << 5);
return (((color >> 5) & 0x7) << (16 + 5)) |
(((color >> 3) & 0x3) << (8 + 6)) | ((color & 0x7) << 5);
}
 
/** Put pixel into viewport
249,14 → 261,15
* @param y Y coord relative to viewport
* @param color RGB color
*/
static void putpixel(viewport_t *vport, unsigned int x, unsigned int y, int
color)
static void
putpixel(viewport_t *vport, unsigned int x, unsigned int y, int color)
{
int dx = vport->x + x;
int dy = vport->y + y;
 
if (! (vport->paused && vport->dbdata))
(*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)], COLOR(color));
(*screen.rgb2scr)(&screen.fbaddress[POINTPOS(dx,dy)],
COLOR(color));
 
if (vport->dbdata) {
int dline = (y + vport->dboffset) % vport->height;
266,21 → 279,23
}
 
/** Get pixel from viewport */
static int getpixel(viewport_t *vport, unsigned int x, unsigned int y)
static int
getpixel(viewport_t *vport, unsigned int x, unsigned int y)
{
int dx = vport->x + x;
int dy = vport->y + y;
 
return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx,dy)]));
return COLOR((*screen.scr2rgb)(&screen.fbaddress[POINTPOS(dx, dy)]));
}
 
static inline void putpixel_mem(char *mem, unsigned int x, unsigned int y, int
color)
static inline void
putpixel_mem(char *mem, unsigned int x, unsigned int y, int color)
{
(*screen.rgb2scr)(&mem[POINTPOS(x,y)], COLOR(color));
}
 
static void draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy,
static void
draw_rectangle(viewport_t *vport, unsigned int sx, unsigned int sy,
unsigned int width, unsigned int height, int color)
{
unsigned int x, y;
315,7 → 330,8
}
 
/** Fill viewport with background color */
static void clear_port(viewport_t *vport)
static void
clear_port(viewport_t *vport)
{
draw_rectangle(vport, 0, 0, vport->width, vport->height,
vport->style.bg_color);
326,7 → 342,8
* @param vport Viewport to scroll
* @param lines Positive number - scroll up, negative - scroll down
*/
static void scroll_port_nodb(viewport_t *vport, int lines)
static void
scroll_port_nodb(viewport_t *vport, int lines)
{
int y;
 
350,7 → 367,8
}
 
/** Refresh given viewport from double buffer */
static void refresh_viewport_db(viewport_t *vport)
static void
refresh_viewport_db(viewport_t *vport)
{
unsigned int y, srcy, srcoff, dsty, dstx;
 
368,7 → 386,8
}
 
/** Scroll viewport that has double buffering enabled */
static void scroll_port_db(viewport_t *vport, int lines)
static void
scroll_port_db(viewport_t *vport, int lines)
{
++vport->paused;
if (lines > 0) {
393,7 → 412,8
}
 
/** Scrolls viewport given number of lines */
static void scroll_port(viewport_t *vport, int lines)
static void
scroll_port(viewport_t *vport, int lines)
{
if (vport->dbdata)
scroll_port_db(vport, lines);
402,7 → 422,8
}
 
static void invert_pixel(viewport_t *vport, unsigned int x, unsigned int y)
static void
invert_pixel(viewport_t *vport, unsigned int x, unsigned int y)
{
putpixel(vport, x, y, ~getpixel(vport, x, y));
}
419,7 → 440,8
* @param style Color of the character
* @param transparent If false, print background color
*/
static void draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx,
static void
draw_glyph(viewport_t *vport,uint8_t glyph, unsigned int sx,
unsigned int sy, style_t style, int transparent)
{
int i;
440,7 → 462,8
}
 
/** Invert character at given position */
static void invert_char(viewport_t *vport,unsigned int row, unsigned int col)
static void
invert_char(viewport_t *vport,unsigned int row, unsigned int col)
{
unsigned int x;
unsigned int y;
459,12 → 482,13
*
* @return New viewport number
*/
static int viewport_create(unsigned int x, unsigned int y,unsigned int width,
static int
viewport_create(unsigned int x, unsigned int y,unsigned int width,
unsigned int height)
{
int i;
 
for (i=0; i < MAX_VIEWPORTS; i++) {
for (i = 0; i < MAX_VIEWPORTS; i++) {
if (!viewports[i].initialized)
break;
}
491,7 → 515,6
return i;
}
 
 
/** Initialize framebuffer as a chardev output device
*
* @param addr Address of theframebuffer
502,7 → 525,8
* @param invert_colors Inverted colors.
*
*/
static bool screen_init(void *addr, unsigned int xres, unsigned int yres,
static bool
screen_init(void *addr, unsigned int xres, unsigned int yres,
unsigned int scan, unsigned int visual, bool invert_colors)
{
switch (visual) {
558,7 → 582,8
}
 
/** Hide cursor if it is shown */
static void cursor_hide(viewport_t *vport)
static void
cursor_hide(viewport_t *vport)
{
if (vport->cursor_active && vport->cursor_shown) {
invert_char(vport, vport->cur_row, vport->cur_col);
567,7 → 592,8
}
 
/** Show cursor if cursor showing is enabled */
static void cursor_print(viewport_t *vport)
static void
cursor_print(viewport_t *vport)
{
/* Do not check for cursor_shown */
if (vport->cursor_active) {
577,7 → 603,8
}
 
/** Invert cursor, if it is enabled */
static void cursor_blink(viewport_t *vport)
static void
cursor_blink(viewport_t *vport)
{
if (vport->cursor_shown)
cursor_hide(vport);
593,8 → 620,9
* @param col Screen position relative to viewport
* @param transparent If false, print background color with character
*/
static void draw_char(viewport_t *vport, char c, unsigned int row, unsigned int
col, style_t style, int transparent)
static void
draw_char(viewport_t *vport, char c, unsigned int row, unsigned int col,
style_t style, int transparent)
{
/* Optimize - do not hide cursor if we are going to overwrite it */
if (vport->cursor_active && vport->cursor_shown &&
622,7 → 650,8
* @param vport Viewport id
* @param data Text data fitting exactly into viewport
*/
static void draw_text_data(viewport_t *vport, keyfield_t *data)
static void
draw_text_data(viewport_t *vport, keyfield_t *data)
{
int i;
int col,row;
641,19 → 670,20
cursor_print(vport);
}
 
 
/** Return first free pixmap */
static int find_free_pixmap(void)
static int
find_free_pixmap(void)
{
int i;
for (i=0;i < MAX_PIXMAPS;i++)
for (i = 0;i < MAX_PIXMAPS;i++)
if (!pixmaps[i].data)
return i;
return -1;
}
 
static void putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
static void
putpixel_pixmap(int pm, unsigned int x, unsigned int y, int color)
{
pixmap_t *pmap = &pixmaps[pm];
int pos = (y * pmap->width + x) * screen.pixelbytes;
662,7 → 692,8
}
 
/** Create a new pixmap and return appropriate ID */
static int shm2pixmap(unsigned char *shm, size_t size)
static int
shm2pixmap(unsigned char *shm, size_t size)
{
int pm;
pixmap_t *pmap;
705,7 → 736,8
* note: this function is not threads safe, you would have
* to redefine static variables with __thread
*/
static int shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
static int
shm_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
{
static keyfield_t *interbuffer = NULL;
static size_t intersize = 0;
717,7 → 749,7
int handled = 1;
int retval = 0;
viewport_t *vport = &viewports[vp];
unsigned int x,y;
unsigned int x, y;
 
switch (IPC_GET_METHOD(*call)) {
case IPC_M_AS_AREA_SEND:
774,8 → 806,8
}
ppm_draw(shm, shm_size, IPC_GET_ARG1(*call),
IPC_GET_ARG2(*call), vport->width - x, vport->height -
y, (putpixel_cb_t)putpixel, vport);
IPC_GET_ARG2(*call), vport->width - x,
vport->height - y, (putpixel_cb_t)putpixel, vport);
break;
case FB_DRAW_TEXT_DATA:
if (!interbuffer) {
798,7 → 830,8
return handled;
}
 
static void copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
static void
copy_vp_to_pixmap(viewport_t *vport, pixmap_t *pmap)
{
int y;
int rowsize;
814,8 → 847,8
rowsize = width * screen.pixelbytes;
 
for (y = 0; y < height; y++) {
tmp = (vport->y + y) * screen.scanline + vport->x *
screen.pixelbytes;
tmp = (vport->y + y) * screen.scanline +
vport->x * screen.pixelbytes;
memcpy(pmap->data + rowsize * y, screen.fbaddress + tmp,
rowsize);
}
822,7 → 855,8
}
 
/** Save viewport to pixmap */
static int save_vp_to_pixmap(viewport_t *vport)
static int
save_vp_to_pixmap(viewport_t *vport)
{
int pm;
pixmap_t *pmap;
873,9 → 907,9
srcrowsize = vport->width * screen.pixelbytes;
realrowsize = realwidth * screen.pixelbytes;
 
for (y=0; y < realheight; y++) {
tmp = (vport->y + y) * screen.scanline + vport->x *
screen.pixelbytes;
for (y = 0; y < realheight; y++) {
tmp = (vport->y + y) * screen.scanline +
vport->x * screen.pixelbytes;
memcpy(screen.fbaddress + tmp, pmap->data + y * srcrowsize,
realrowsize);
}
883,7 → 917,8
}
 
/** Tick animation one step forward */
static void anims_tick(void)
static void
anims_tick(void)
{
int i;
static int counts = 0;
893,7 → 928,7
if (counts)
return;
 
for (i=0; i < MAX_ANIMATIONS; i++) {
for (i = 0; i < MAX_ANIMATIONS; i++) {
if (!animations[i].animlen || !animations[i].initialized ||
!animations[i].enabled)
continue;
910,9 → 945,10
static int pointer_vport = -1;
static int pointer_pixmap = -1;
 
static void mouse_show(void)
static void
mouse_show(void)
{
int i,j;
int i, j;
int visibility;
int color;
int bytepos;
941,8 → 977,8
for (i = 0; i < pointer_height; i++)
for (j = 0; j < pointer_width; j++) {
bytepos = i * ((pointer_width - 1) / 8 + 1) + j / 8;
visibility = pointer_mask_bits[bytepos] & (1 << (j %
8));
visibility = pointer_mask_bits[bytepos] &
(1 << (j % 8));
if (visibility) {
color = pointer_bits[bytepos] & (1 << (j % 8))
? 0 : 0xffffff;
949,13 → 985,14
if (pointer_x + j < screen.xres && pointer_y +
i < screen.yres)
putpixel(&viewports[0], pointer_x + j,
pointer_y+i, color);
pointer_y + i, color);
}
}
pointer_shown = 1;
}
 
static void mouse_hide(void)
static void
mouse_hide(void)
{
/* Restore image under the cursor */
if (pointer_shown) {
964,7 → 1001,8
}
}
 
static void mouse_move(unsigned int x, unsigned int y)
static void
mouse_move(unsigned int x, unsigned int y)
{
mouse_hide();
pointer_x = x;
972,7 → 1010,8
mouse_show();
}
 
static int anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
static int
anim_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
{
int handled = 1;
int retval = 0;
1069,7 → 1108,8
}
 
/** Handler for messages concerning pixmap handling */
static int pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
static int
pixmap_handle(ipc_callid_t callid, ipc_call_t *call, int vp)
{
int handled = 1;
int retval = 0;
1122,7 → 1162,8
/** Function for handling connections to FB
*
*/
static void fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
static void
fb_client_connection(ipc_callid_t iid, ipc_call_t *icall)
{
ipc_callid_t callid;
ipc_call_t call;
1143,7 → 1184,7
 
while (1) {
if (vport->cursor_active || anims_enabled)
callid = async_get_call_timeout(&call,250000);
callid = async_get_call_timeout(&call, 250000);
else
callid = async_get_call(&call);
 
1178,7 → 1219,7
retval = EINVAL;
break;
}
ipc_answer_fast(callid,0,0,0);
ipc_answer_fast(callid, 0, 0, 0);
 
draw_char(vport, c, row, col, vport->style,
IPC_GET_METHOD(call) == FB_TRANS_PUTCHAR);
1264,8 → 1305,9
break;
case FB_VIEWPORT_CREATE:
retval = viewport_create(IPC_GET_ARG1(call) >> 16,
IPC_GET_ARG1(call) & 0xffff, IPC_GET_ARG2(call)
>> 16, IPC_GET_ARG2(call) & 0xffff);
IPC_GET_ARG1(call) & 0xffff,
IPC_GET_ARG2(call) >> 16,
IPC_GET_ARG2(call) & 0xffff);
break;
case FB_VIEWPORT_DELETE:
i = IPC_GET_ARG1(call);
1300,12 → 1342,13
default:
retval = ENOENT;
}
ipc_answer_fast(callid,retval,0,0);
ipc_answer_fast(callid,retval, 0, 0);
}
}
 
/** Initialization of framebuffer */
int fb_init(void)
int
fb_init(void)
{
void *fb_ph_addr;
unsigned int fb_width;
/trunk/uspace/console/console.c
119,7 → 119,6
static void curs_goto(int row, int col)
{
async_msg_2(fb_info.phone, FB_CURSOR_GOTO, row, col);
}
 
static void set_style(style_t *style)
136,7 → 135,6
static void prtchr(char c, int row, int col)
{
async_msg_3(fb_info.phone, FB_PUTCHAR, c, row, col);
}
 
/** Check key and process special keys.
/trunk/uspace/console/gcons.c
89,14 → 89,12
unsigned int width, unsigned int height)
{
return async_req_2(fbphone, FB_VIEWPORT_CREATE,
(x << 16) | y, (width << 16) | height,
NULL, NULL);
(x << 16) | y, (width << 16) | height, NULL, NULL);
}
 
static void clear(void)
{
async_msg(fbphone, FB_CLEAR, 0);
}
 
static void set_style(int fgcolor, int bgcolor)
122,10 → 120,10
async_msg_2(fbphone, FB_VP_DRAW_PIXMAP, cstatus_vp[consnum],
ic_pixmaps[state]);
 
if (state != CONS_DISCONNECTED && state != CONS_KERNEL && state !=
CONS_DISCONNECTED_SEL) {
if (state != CONS_DISCONNECTED && state != CONS_KERNEL &&
state != CONS_DISCONNECTED_SEL) {
snprintf(data, 5, "%d", consnum + 1);
for (i=0; data[i]; i++)
for (i = 0; data[i]; i++)
tran_putch(data[i], 1, 2 + i);
}
}
168,8 → 166,8
if (!use_gcons)
return;
 
if (consnum == active_console || console_state[consnum] ==
CONS_HAS_DATA)
if (consnum == active_console ||
console_state[consnum] == CONS_HAS_DATA)
return;
 
console_state[consnum] = CONS_HAS_DATA;
357,12 → 355,12
vp_switch(0);
set_style(MAIN_COLOR, MAIN_COLOR);
clear();
draw_pixmap(_binary_helenos_ppm_start, (size_t)
&_binary_helenos_ppm_size, xres - 66, 2);
draw_pixmap(_binary_nameic_ppm_start, (size_t)
&_binary_nameic_ppm_size, 5, 17);
draw_pixmap(_binary_helenos_ppm_start,
(size_t) &_binary_helenos_ppm_size, xres - 66, 2);
draw_pixmap(_binary_nameic_ppm_start,
(size_t) &_binary_nameic_ppm_size, 5, 17);
 
for (i=0;i < CONSOLE_COUNT; i++)
for (i = 0;i < CONSOLE_COUNT; i++)
redraw_state(i);
vp_switch(console_vp);
}
430,20 → 428,20
if (an < 0)
return;
 
pm = make_pixmap(_binary_anim_1_ppm_start, (int)
&_binary_anim_1_ppm_size);
pm = make_pixmap(_binary_anim_1_ppm_start,
(int) &_binary_anim_1_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
pm = make_pixmap(_binary_anim_2_ppm_start, (int)
&_binary_anim_2_ppm_size);
pm = make_pixmap(_binary_anim_2_ppm_start,
(int) &_binary_anim_2_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
pm = make_pixmap(_binary_anim_3_ppm_start, (int)
&_binary_anim_3_ppm_size);
pm = make_pixmap(_binary_anim_3_ppm_start,
(int) &_binary_anim_3_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
pm = make_pixmap(_binary_anim_4_ppm_start, (int)
&_binary_anim_4_ppm_size);
pm = make_pixmap(_binary_anim_4_ppm_start,
(int) &_binary_anim_4_ppm_size);
async_msg_2(fbphone, FB_ANIM_ADDPIXMAP, an, pm);
 
async_msg(fbphone, FB_ANIM_START, an);
478,9 → 476,9
 
/* create console viewport */
/* Align width & height to character size */
console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP, ALIGN_DOWN(xres -
2 * CONSOLE_MARGIN, 8), ALIGN_DOWN(yres - (CONSOLE_TOP +
CONSOLE_MARGIN), 16));
console_vp = vp_create(CONSOLE_MARGIN, CONSOLE_TOP,
ALIGN_DOWN(xres - 2 * CONSOLE_MARGIN, 8),
ALIGN_DOWN(yres - (CONSOLE_TOP + CONSOLE_MARGIN), 16));
if (console_vp < 0)
return;
487,8 → 485,8
/* Create status buttons */
status_start += (xres - 800) / 2;
for (i = 0; i < CONSOLE_COUNT; i++) {
cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN + i *
(STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
cstatus_vp[i] = vp_create(status_start + CONSOLE_MARGIN +
i * (STATUS_WIDTH + STATUS_SPACE), STATUS_TOP,
STATUS_WIDTH, STATUS_HEIGHT);
if (cstatus_vp[i] < 0)
return;
498,16 → 496,16
/* Initialize icons */
ic_pixmaps[CONS_SELECTED] =
make_pixmap(_binary_cons_selected_ppm_start, (int)
&_binary_cons_selected_ppm_size);
ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start, (int)
&_binary_cons_idle_ppm_size);
make_pixmap(_binary_cons_selected_ppm_start,
(int) &_binary_cons_selected_ppm_size);
ic_pixmaps[CONS_IDLE] = make_pixmap(_binary_cons_idle_ppm_start,
(int) &_binary_cons_idle_ppm_size);
ic_pixmaps[CONS_HAS_DATA] =
make_pixmap(_binary_cons_has_data_ppm_start, (int)
&_binary_cons_has_data_ppm_size);
make_pixmap(_binary_cons_has_data_ppm_start,
(int) &_binary_cons_has_data_ppm_size);
ic_pixmaps[CONS_DISCONNECTED] =
make_pixmap(_binary_cons_idle_ppm_start, (int)
&_binary_cons_idle_ppm_size);
make_pixmap(_binary_cons_idle_ppm_start,
(int) &_binary_cons_idle_ppm_size);
ic_pixmaps[CONS_KERNEL] = make_pixmap(_binary_cons_kernel_ppm_start,
(int) &_binary_cons_kernel_ppm_size);
ic_pixmaps[CONS_DISCONNECTED_SEL] = ic_pixmaps[CONS_SELECTED];
/trunk/uspace/libc/generic/io/printf_core.c
245,15 → 245,15
/* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */
if (flags & __PRINTF_FLAG_PREFIX) {
switch(base) {
case 2: /* Binary formating is not standard, but usefull */
size += 2;
break;
case 8:
size++;
break;
case 16:
size += 2;
break;
case 2: /* Binary formating is not standard, but usefull */
size += 2;
break;
case 8:
size++;
break;
case 16:
size += 2;
break;
}
}
 
305,32 → 305,32
if (flags & __PRINTF_FLAG_PREFIX) {
switch(base) {
case 2: /* Binary formating is not standard, but usefull */
if (printf_putchar('0', ps) == 1)
case 2: /* Binary formating is not standard, but usefull */
if (printf_putchar('0', ps) == 1)
counter++;
if (flags & __PRINTF_FLAG_BIGCHARS) {
if (printf_putchar('B', ps) == 1)
counter++;
if (flags & __PRINTF_FLAG_BIGCHARS) {
if (printf_putchar('B', ps) == 1)
counter++;
} else {
if (printf_putchar('b', ps) == 1)
counter++;
}
break;
case 8:
if (printf_putchar('o', ps) == 1)
} else {
if (printf_putchar('b', ps) == 1)
counter++;
break;
case 16:
if (printf_putchar('0', ps) == 1)
}
break;
case 8:
if (printf_putchar('o', ps) == 1)
counter++;
break;
case 16:
if (printf_putchar('0', ps) == 1)
counter++;
if (flags & __PRINTF_FLAG_BIGCHARS) {
if (printf_putchar('X', ps) == 1)
counter++;
if (flags & __PRINTF_FLAG_BIGCHARS) {
if (printf_putchar('X', ps) == 1)
counter++;
} else {
if (printf_putchar('x', ps) == 1)
counter++;
}
break;
} else {
if (printf_putchar('x', ps) == 1)
counter++;
}
break;
}
}
 
471,12 → 471,12
do {
++i;
switch (c = fmt[i]) {
case '#': flags |= __PRINTF_FLAG_PREFIX; break;
case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
default: end = 1;
case '#': flags |= __PRINTF_FLAG_PREFIX; break;
case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break;
case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break;
case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break;
case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break;
default: end = 1;
};
} while (end == 0);
520,29 → 520,29
}
 
switch (fmt[i++]) {
/** TODO: unimplemented qualifiers:
* t ptrdiff_t - ISO C 99
*/
case 'h': /* char or short */
qualifier = PrintfQualifierShort;
if (fmt[i] == 'h') {
i++;
qualifier = PrintfQualifierByte;
}
break;
case 'l': /* long or long long*/
qualifier = PrintfQualifierLong;
if (fmt[i] == 'l') {
i++;
qualifier = PrintfQualifierLongLong;
}
break;
case 'z': /* size_t */
qualifier = PrintfQualifierSizeT;
break;
default:
qualifier = PrintfQualifierInt; /* default type */
--i;
/** TODO: unimplemented qualifiers:
* t ptrdiff_t - ISO C 99
*/
case 'h': /* char or short */
qualifier = PrintfQualifierShort;
if (fmt[i] == 'h') {
i++;
qualifier = PrintfQualifierByte;
}
break;
case 'l': /* long or long long*/
qualifier = PrintfQualifierLong;
if (fmt[i] == 'l') {
i++;
qualifier = PrintfQualifierLongLong;
}
break;
case 'z': /* size_t */
qualifier = PrintfQualifierSizeT;
break;
default:
qualifier = PrintfQualifierInt; /* default type */
--i;
}
base = 10;
552,63 → 552,63
/*
* String and character conversions.
*/
case 's':
if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
goto minus_out;
};
case 's':
if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) {
goto minus_out;
}
counter += retval;
j = i + 1;
goto next_char;
case 'c':
c = va_arg(ap, unsigned int);
if ((retval = print_char(c, width, flags, ps)) < 0) {
goto minus_out;
};
counter += retval;
j = i + 1;
goto next_char;
counter += retval;
j = i + 1;
goto next_char;
case 'c':
c = va_arg(ap, unsigned int);
if ((retval = print_char(c, width, flags, ps)) < 0) {
goto minus_out;
}
 
/*
* Integer values
*/
case 'P': /* pointer */
flags |= __PRINTF_FLAG_BIGCHARS;
case 'p':
flags |= __PRINTF_FLAG_PREFIX;
base = 16;
qualifier = PrintfQualifierPointer;
break;
case 'b':
base = 2;
break;
case 'o':
base = 8;
break;
case 'd':
case 'i':
flags |= __PRINTF_FLAG_SIGNED;
case 'u':
break;
case 'X':
flags |= __PRINTF_FLAG_BIGCHARS;
case 'x':
base = 16;
break;
/* percentile itself */
case '%':
j = i;
goto next_char;
/*
* Bad formatting.
*/
default:
/* Unknown format
* now, the j is index of '%' so we will
* print whole bad format sequence
*/
goto next_char;
counter += retval;
j = i + 1;
goto next_char;
 
/*
* Integer values
*/
case 'P': /* pointer */
flags |= __PRINTF_FLAG_BIGCHARS;
case 'p':
flags |= __PRINTF_FLAG_PREFIX;
base = 16;
qualifier = PrintfQualifierPointer;
break;
case 'b':
base = 2;
break;
case 'o':
base = 8;
break;
case 'd':
case 'i':
flags |= __PRINTF_FLAG_SIGNED;
case 'u':
break;
case 'X':
flags |= __PRINTF_FLAG_BIGCHARS;
case 'x':
base = 16;
break;
/* percentile itself */
case '%':
j = i;
goto next_char;
/*
* Bad formatting.
*/
default:
/* Unknown format
* now, the j is index of '%' so we will
* print whole bad format sequence
*/
goto next_char;
}
615,36 → 615,36
/* Print integers */
/* print number */
switch (qualifier) {
case PrintfQualifierByte:
size = sizeof(unsigned char);
number = (uint64_t)va_arg(ap, unsigned int);
break;
case PrintfQualifierShort:
size = sizeof(unsigned short);
number = (uint64_t)va_arg(ap, unsigned int);
break;
case PrintfQualifierInt:
size = sizeof(unsigned int);
number = (uint64_t)va_arg(ap, unsigned int);
break;
case PrintfQualifierLong:
size = sizeof(unsigned long);
number = (uint64_t)va_arg(ap, unsigned long);
break;
case PrintfQualifierLongLong:
size = sizeof(unsigned long long);
number = (uint64_t)va_arg(ap, unsigned long long);
break;
case PrintfQualifierPointer:
size = sizeof(void *);
number = (uint64_t)(unsigned long)va_arg(ap, void *);
break;
case PrintfQualifierSizeT:
size = sizeof(size_t);
number = (uint64_t)va_arg(ap, size_t);
break;
default: /* Unknown qualifier */
goto minus_out;
case PrintfQualifierByte:
size = sizeof(unsigned char);
number = (uint64_t)va_arg(ap, unsigned int);
break;
case PrintfQualifierShort:
size = sizeof(unsigned short);
number = (uint64_t)va_arg(ap, unsigned int);
break;
case PrintfQualifierInt:
size = sizeof(unsigned int);
number = (uint64_t)va_arg(ap, unsigned int);
break;
case PrintfQualifierLong:
size = sizeof(unsigned long);
number = (uint64_t)va_arg(ap, unsigned long);
break;
case PrintfQualifierLongLong:
size = sizeof(unsigned long long);
number = (uint64_t)va_arg(ap, unsigned long long);
break;
case PrintfQualifierPointer:
size = sizeof(void *);
number = (uint64_t)(unsigned long)va_arg(ap, void *);
break;
case PrintfQualifierSizeT:
size = sizeof(size_t);
number = (uint64_t)va_arg(ap, size_t);
break;
default: /* Unknown qualifier */
goto minus_out;
}