Browse Source

* Get rid of the last long types in the API.

* Use size_t and ssize_t where appropriate.
tags/v0.99.beta14
Sam Hocevar sam 16 years ago
parent
commit
ec68a634cf
13 changed files with 77 additions and 75 deletions
  1. +2
    -1
      caca/driver_ncurses.c
  2. +2
    -1
      caca/driver_slang.c
  3. +1
    -1
      cucul/canvas.c
  4. +11
    -11
      cucul/charset.c
  5. +7
    -7
      cucul/cucul.h
  6. +2
    -0
      cucul/cucul_types.h.in
  7. +23
    -23
      cucul/export.c
  8. +13
    -15
      cucul/import.c
  9. +2
    -2
      cxx/cucul++.cpp
  10. +2
    -2
      cxx/cucul++.h
  11. +2
    -2
      examples/font2tga.c
  12. +5
    -5
      src/aafire.c
  13. +5
    -5
      src/cacademo.c

+ 2
- 1
caca/driver_ncurses.c View File

@@ -420,7 +420,8 @@ static int ncurses_get_event(caca_display_t *dp, caca_privevent_t *ev)
int keys[7]; /* Necessary for ungetch(); */
char utf8[7];
uint32_t utf32;
unsigned int i, bytes = 0;
unsigned int i;
size_t bytes = 0;

keys[0] = intkey;
utf8[0] = intkey;


+ 2
- 1
caca/driver_slang.c View File

@@ -328,7 +328,8 @@ static int slang_get_event(caca_display_t *dp, caca_privevent_t *ev)
int keys[7]; /* Necessary for ungetkey(); */
char utf8[7];
uint32_t utf32;
unsigned int i, bytes = 0;
unsigned int i;
size_t bytes = 0;

keys[0] = intkey;
utf8[0] = intkey;


+ 1
- 1
cucul/canvas.c View File

@@ -219,7 +219,7 @@ uint32_t cucul_get_char(cucul_canvas_t const *cv, int x, int y)
*/
int cucul_put_str(cucul_canvas_t *cv, int x, int y, char const *s)
{
unsigned int rd;
size_t rd;

if(y < 0 || y >= (int)cv->height || x >= (int)cv->width)
return 0;


+ 11
- 11
cucul/charset.c View File

@@ -111,9 +111,9 @@ static uint32_t const cp437_lookup2[] =
* \return The corresponding UTF-32 character, or zero if the character
* is incomplete.
*/
uint32_t cucul_utf8_to_utf32(char const *s, unsigned int *read)
uint32_t cucul_utf8_to_utf32(char const *s, size_t *bytes)
{
unsigned int bytes = trailing[(int)(unsigned char)*s];
unsigned int todo = trailing[(int)(unsigned char)*s];
unsigned int i = 0;
uint32_t ret = 0;

@@ -121,18 +121,18 @@ uint32_t cucul_utf8_to_utf32(char const *s, unsigned int *read)
{
if(!*s)
{
if(read)
*read = 0;
if(bytes)
*bytes = 0;
return 0;
}

ret += ((uint32_t)(unsigned char)*s++) << (6 * (bytes - i));
ret += ((uint32_t)(unsigned char)*s++) << (6 * (todo - i));

if(bytes == i++)
if(todo == i++)
{
if(read)
*read = i;
return ret - offsets[bytes];
if(bytes)
*bytes = i;
return ret - offsets[todo];
}
}
}
@@ -150,7 +150,7 @@ uint32_t cucul_utf8_to_utf32(char const *s, unsigned int *read)
* \param ch The UTF-32 character.
* \return The number of bytes written.
*/
unsigned int cucul_utf32_to_utf8(char *buf, uint32_t ch)
size_t cucul_utf32_to_utf8(char *buf, uint32_t ch)
{
static const uint8_t mark[7] =
{
@@ -158,7 +158,7 @@ unsigned int cucul_utf32_to_utf8(char *buf, uint32_t ch)
};

char *parser = buf;
int bytes;
size_t bytes;

if(ch < 0x80)
{


+ 7
- 7
cucul/cucul.h View File

@@ -162,8 +162,8 @@ __extern void cucul_attr_to_argb64(uint32_t, uint8_t[8]);
* These functions perform conversions between usual character sets.
*
* @{ */
__extern uint32_t cucul_utf8_to_utf32(char const *, unsigned int *);
__extern unsigned int cucul_utf32_to_utf8(char *, uint32_t);
__extern uint32_t cucul_utf8_to_utf32(char const *, size_t *);
__extern size_t cucul_utf32_to_utf8(char *, uint32_t);
__extern uint8_t cucul_utf32_to_cp437(uint32_t);
__extern uint32_t cucul_cp437_to_utf32(uint8_t);
__extern char cucul_utf32_to_ascii(uint32_t);
@@ -288,13 +288,13 @@ __extern int cucul_put_figchar(cucul_canvas_t *, uint32_t);
* the current canvas to various text formats.
*
* @{ */
__extern long int cucul_import_memory(cucul_canvas_t *, void const *,
unsigned long int, char const *);
__extern long int cucul_import_file(cucul_canvas_t *, char const *,
char const *);
__extern ssize_t cucul_import_memory(cucul_canvas_t *, void const *,
size_t, char const *);
__extern ssize_t cucul_import_file(cucul_canvas_t *, char const *,
char const *);
__extern char const * const * cucul_get_import_list(void);
__extern void *cucul_export_memory(cucul_canvas_t const *, char const *,
unsigned long int *);
size_t *);
__extern char const * const * cucul_get_export_list(void);
/* @} */



+ 2
- 0
cucul/cucul_types.h.in View File

@@ -37,10 +37,12 @@
typedef signed char int8_t;
typedef signed short int16_t;
typedef signed long int int32_t;
typedef signed long long int int64_t;

typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned long int uint32_t;
typedef unsigned long long int uint64_t;

typedef long int intptr_t;
typedef unsigned long int uintptr_t;


+ 23
- 23
cucul/export.c View File

@@ -44,16 +44,16 @@ static inline int sprintu16(char *s, uint16_t x)
return 2;
}

static void *export_caca(cucul_canvas_t const *, unsigned long int *);
static void *export_ansi(cucul_canvas_t const *, unsigned long int *);
static void *export_utf8(cucul_canvas_t const *, unsigned long int *, int);
static void *export_html(cucul_canvas_t const *, unsigned long int *);
static void *export_html3(cucul_canvas_t const *, unsigned long int *);
static void *export_bbfr(cucul_canvas_t const *, unsigned long int *);
static void *export_irc(cucul_canvas_t const *, unsigned long int *);
static void *export_ps(cucul_canvas_t const *, unsigned long int *);
static void *export_svg(cucul_canvas_t const *, unsigned long int *);
static void *export_tga(cucul_canvas_t const *, unsigned long int *);
static void *export_caca(cucul_canvas_t const *, size_t *);
static void *export_ansi(cucul_canvas_t const *, size_t *);
static void *export_utf8(cucul_canvas_t const *, size_t *, int);
static void *export_html(cucul_canvas_t const *, size_t *);
static void *export_html3(cucul_canvas_t const *, size_t *);
static void *export_bbfr(cucul_canvas_t const *, size_t *);
static void *export_irc(cucul_canvas_t const *, size_t *);
static void *export_ps(cucul_canvas_t const *, size_t *);
static void *export_svg(cucul_canvas_t const *, size_t *);
static void *export_tga(cucul_canvas_t const *, size_t *);

/** \brief Export a canvas into a foreign format.
*
@@ -78,12 +78,12 @@ static void *export_tga(cucul_canvas_t const *, unsigned long int *);
*
* \param cv A libcucul canvas
* \param format A string describing the requested output format.
* \param bytes A pointer to an unsigned long integer where the number of
* allocated bytes will be written.
* \param bytes A pointer to a size_t where the number of allocated bytes
* will be written.
* \return A pointer to the exported memory area, or NULL in case of error.
*/
void *cucul_export_memory(cucul_canvas_t const *cv, char const *format,
unsigned long int *bytes)
size_t *bytes)
{
if(!strcasecmp("caca", format))
return export_caca(cv, bytes);
@@ -159,7 +159,7 @@ char const * const * cucul_get_export_list(void)
*/

/* Generate a native libcaca canvas file. */
static void *export_caca(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_caca(cucul_canvas_t const *cv, size_t *bytes)
{
char *data, *cur;
unsigned int f, n;
@@ -212,7 +212,7 @@ static void *export_caca(cucul_canvas_t const *cv, unsigned long int *bytes)
}

/* Generate UTF-8 representation of current canvas. */
static void *export_utf8(cucul_canvas_t const *cv, unsigned long int *bytes,
static void *export_utf8(cucul_canvas_t const *cv, size_t *bytes,
int cr)
{
static uint8_t const palette[] =
@@ -293,7 +293,7 @@ static void *export_utf8(cucul_canvas_t const *cv, unsigned long int *bytes,
}

/* Generate ANSI representation of current canvas. */
static void *export_ansi(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_ansi(cucul_canvas_t const *cv, size_t *bytes)
{
static uint8_t const palette[] =
{
@@ -373,7 +373,7 @@ static void *export_ansi(cucul_canvas_t const *cv, unsigned long int *bytes)
}

/* Generate HTML representation of current canvas. */
static void *export_html(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_html(cucul_canvas_t const *cv, size_t *bytes)
{
char *data, *cur;
unsigned int x, y, len;
@@ -455,7 +455,7 @@ static void *export_html(cucul_canvas_t const *cv, unsigned long int *bytes)
* but permits viewing in old browsers (or limited ones such as links). It
* will not work under gecko (mozilla rendering engine) unless you set a
* correct header. */
static void *export_html3(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_html3(cucul_canvas_t const *cv, size_t *bytes)
{
char *data, *cur;
unsigned int x, y, len;
@@ -556,7 +556,7 @@ static void *export_html3(cucul_canvas_t const *cv, unsigned long int *bytes)
return data;
}

static void *export_bbfr(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_bbfr(cucul_canvas_t const *cv, size_t *bytes)
{
char *data, *cur;
unsigned int x, y, len;
@@ -657,7 +657,7 @@ static void *export_bbfr(cucul_canvas_t const *cv, unsigned long int *bytes)
}

/* Export a text file with IRC colours */
static void *export_irc(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_irc(cucul_canvas_t const *cv, size_t *bytes)
{
static uint8_t const palette[] =
{
@@ -764,7 +764,7 @@ static void *export_irc(cucul_canvas_t const *cv, unsigned long int *bytes)
}

/* Export a PostScript document. */
static void *export_ps(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_ps(cucul_canvas_t const *cv, size_t *bytes)
{
static char const *ps_header =
"%!\n"
@@ -873,7 +873,7 @@ static void *export_ps(cucul_canvas_t const *cv, unsigned long int *bytes)
}

/* Export an SVG vector image */
static void *export_svg(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_svg(cucul_canvas_t const *cv, size_t *bytes)
{
static char const svg_header[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
@@ -959,7 +959,7 @@ static void *export_svg(cucul_canvas_t const *cv, unsigned long int *bytes)
}

/* Export a TGA image */
static void *export_tga(cucul_canvas_t const *cv, unsigned long int *bytes)
static void *export_tga(cucul_canvas_t const *cv, size_t *bytes)
{
char const * const *fontlist;
char *data, *cur;


+ 13
- 15
cucul/import.c View File

@@ -52,9 +52,9 @@ struct import
uint8_t faint, strike, proportional; /* unsupported */
};

static long int import_caca(cucul_canvas_t *, void const *, unsigned int);
static long int import_text(cucul_canvas_t *, void const *, unsigned int);
static long int import_ansi(cucul_canvas_t *, void const *, unsigned int, int);
static ssize_t import_caca(cucul_canvas_t *, void const *, size_t);
static ssize_t import_text(cucul_canvas_t *, void const *, size_t);
static ssize_t import_ansi(cucul_canvas_t *, void const *, size_t, int);

static void ansi_parse_grcm(cucul_canvas_t *, struct import *,
unsigned int, unsigned int const *);
@@ -86,8 +86,8 @@ static void ansi_parse_grcm(cucul_canvas_t *, struct import *,
* \return The number of bytes read, or 0 if there was not enough data,
* or -1 if an error occurred.
*/
long int cucul_import_memory(cucul_canvas_t *cv, void const *data,
unsigned long int len, char const *format)
ssize_t cucul_import_memory(cucul_canvas_t *cv, void const *data,
size_t len, char const *format)
{
if(!strcasecmp("caca", format))
return import_caca(cv, data, len);
@@ -151,8 +151,8 @@ long int cucul_import_memory(cucul_canvas_t *cv, void const *data,
* \return The number of bytes read, or 0 if there was not enough data,
* or -1 if an error occurred.
*/
long int cucul_import_file(cucul_canvas_t *cv, char const *filename,
char const *format)
ssize_t cucul_import_file(cucul_canvas_t *cv, char const *filename,
char const *format)
{
#if defined __KERNEL__
seterrno(ENOSYS);
@@ -160,7 +160,7 @@ long int cucul_import_file(cucul_canvas_t *cv, char const *filename,
#else
FILE *fp;
void *data;
long int size;
ssize_t size;
int ret;

fp = fopen(filename, "rb");
@@ -219,8 +219,7 @@ char const * const * cucul_get_import_list(void)
* XXX: the following functions are local.
*/

static long int import_caca(cucul_canvas_t *cv,
void const *data, unsigned int size)
static ssize_t import_caca(cucul_canvas_t *cv, void const *data, size_t size)
{
uint8_t const *buf = (uint8_t const *)data;
unsigned int control_size, data_size, expected_size, frames, f, n;
@@ -337,8 +336,7 @@ invalid_caca:
return -1;
}

static long int import_text(cucul_canvas_t *cv,
void const *data, unsigned int size)
static ssize_t import_text(cucul_canvas_t *cv, void const *data, size_t size)
{
char const *text = (char const *)data;
unsigned int width = 0, height = 0, x = 0, y = 0, i;
@@ -380,8 +378,8 @@ static long int import_text(cucul_canvas_t *cv,
return size;
}

static long int import_ansi(cucul_canvas_t *cv,
void const *data, unsigned int size, int utf8)
static ssize_t import_ansi(cucul_canvas_t *cv, void const *data,
size_t size, int utf8)
{
struct import im;
unsigned char const *buffer = (unsigned char const*)data;
@@ -682,7 +680,7 @@ static long int import_ansi(cucul_canvas_t *cv,
/* Get the character we’re going to paste */
else if(utf8)
{
unsigned int bytes;
size_t bytes;

if(i + 6 < size)
ch = cucul_utf8_to_utf32((char const *)(buffer + i), &bytes);


+ 2
- 2
cxx/cucul++.cpp View File

@@ -25,11 +25,11 @@
#include "cucul++.h"


uint32_t Charset::utf8ToUtf32(char const *s, unsigned int *read)
uint32_t Charset::utf8ToUtf32(char const *s, size_t *read)
{
return cucul_utf8_to_utf32(s, read);
}
unsigned int Charset::utf32ToUtf8(char *buf, uint32_t ch)
size_t Charset::utf32ToUtf8(char *buf, uint32_t ch)
{
return cucul_utf32_to_utf8(buf, ch);
}


+ 2
- 2
cxx/cucul++.h View File

@@ -38,8 +38,8 @@ class Cucul;
__class Charset
{
public:
uint32_t utf8ToUtf32(char const *, unsigned int *);
unsigned int utf32ToUtf8(char *, uint32_t);
uint32_t utf8ToUtf32(char const *, size_t *);
size_t utf32ToUtf8(char *, uint32_t);
uint8_t utf32ToCp437(uint32_t);
uint32_t cp437ToUtf32(uint8_t);
};


+ 2
- 2
examples/font2tga.c View File

@@ -23,12 +23,12 @@

int main(int argc, char *argv[])
{
unsigned long int const *blocks;
uint32_t const *blocks;
cucul_font_t *f;
char const * const * fonts;
cucul_canvas_t *cv;
void *buffer;
unsigned long int len;
size_t len;
unsigned int i, j, x, y, cells, width;

fonts = cucul_get_font_list();


+ 5
- 5
src/aafire.c View File

@@ -45,7 +45,7 @@ static caca_display_t *dp;
static int XSIZ, YSIZ;
static cucul_dither_t *cucul_dither;
static char *bitmap;
static int pause = 0;
static int paused = 0;
#else
static aa_context *context;
static aa_renderparams *params;
@@ -212,8 +212,8 @@ drawfire (void)
#ifndef LIBCACA
char *bitmap = aa_image (context);
#else
if(pause)
goto paused;
if(paused)
goto _paused;
#endif

height++;
@@ -237,7 +237,7 @@ drawfire (void)
i = 0;
firemain ();
#ifdef LIBCACA
paused:
_paused:
cucul_dither_bitmap(cv, 0, 0, cucul_get_canvas_width(cv),
cucul_get_canvas_height(cv), cucul_dither, bitmap);
cucul_set_color_ansi(cv, CUCUL_WHITE, CUCUL_BLUE);
@@ -279,7 +279,7 @@ game (void)
case CACA_KEY_CTRL_C:
case CACA_KEY_CTRL_Z:
case CACA_KEY_ESCAPE: return;
case ' ': pause = !pause;
case ' ': paused = !paused;
}
}
#endif


+ 5
- 5
src/cacademo.c View File

@@ -72,7 +72,7 @@ int main(int argc, char **argv)
static caca_display_t *dp;
static cucul_canvas_t *frontcv, *backcv, *mask;

int demo, next = -1, pause = 0, next_transition = DEMO_FRAMES;
int demo, next = -1, paused = 0, next_transition = DEMO_FRAMES;
unsigned int i;
int tmode = cucul_rand(0, TRANSITION_COUNT);

@@ -117,7 +117,7 @@ int main(int argc, char **argv)
case CACA_KEY_CTRL_Z:
goto end;
case ' ':
pause = !pause;
paused = !paused;
break;
case '\r':
if(next == -1)
@@ -132,8 +132,8 @@ int main(int argc, char **argv)
cucul_set_canvas_size(mask, cucul_get_canvas_width(frontcv),
cucul_get_canvas_height(frontcv));

if(pause)
goto paused;
if(paused)
goto _paused;

/* Update demo's data */
fn[demo](UPDATE, frontcv);
@@ -159,7 +159,7 @@ int main(int argc, char **argv)
fn[next](UPDATE, backcv);

frame++;
paused:
_paused:
/* Render main demo's canvas */
fn[demo](RENDER, frontcv);



Loading…
Cancel
Save