Back to index

lightning-sunbird  0.9+nobinonly
Classes | Enumerations | Functions
cairo-output-stream.c File Reference
#include <stdio.h>
#include <locale.h>
#include <ctype.h>
#include "cairoint.h"

Go to the source code of this file.

Classes

struct  _cairo_output_stream

Enumerations

enum  { LENGTH_MODIFIER_LONG = 0x100 }

Functions

cairo_output_stream_t * _cairo_output_stream_create (cairo_write_func_t write_data, void *closure)
void _cairo_output_stream_destroy (cairo_output_stream_t *stream)
cairo_status_t _cairo_output_stream_write (cairo_output_stream_t *stream, const void *data, size_t length)
void _cairo_output_stream_write_hex_string (cairo_output_stream_t *stream, const char *data, size_t length)
static int dtostr (char *buffer, size_t size, double d)
cairo_status_t _cairo_output_stream_vprintf (cairo_output_stream_t *stream, const char *fmt, va_list ap)
cairo_status_t _cairo_output_stream_printf (cairo_output_stream_t *stream, const char *fmt,...)
long _cairo_output_stream_get_position (cairo_output_stream_t *stream)
cairo_status_t _cairo_output_stream_get_status (cairo_output_stream_t *stream)
static cairo_status_t stdio_write (void *closure, const unsigned char *data, unsigned int length)
cairo_output_stream_t * _cairo_output_stream_create_for_file (const char *filename)

Class Documentation

struct _cairo_output_stream

Definition at line 46 of file cairo-output-stream.c.

Collaboration diagram for _cairo_output_stream:
Class Members
void * closure
cairo_bool_t owns_closure_is_file
unsigned long position
cairo_status_t status
cairo_write_func_t write_data

Enumeration Type Documentation

anonymous enum
Enumerator:
LENGTH_MODIFIER_LONG 

Definition at line 166 of file cairo-output-stream.c.

     {
    LENGTH_MODIFIER_LONG = 0x100
};

Function Documentation

cairo_output_stream_t* _cairo_output_stream_create ( cairo_write_func_t  write_data,
void closure 
)

Definition at line 55 of file cairo-output-stream.c.

{
    cairo_output_stream_t *stream;

    stream = malloc (sizeof (cairo_output_stream_t));
    if (stream == NULL)
       return NULL;

    stream->write_data = write_data;
    stream->closure = closure;
    stream->owns_closure_is_file = FALSE;
    stream->position = 0;
    stream->status = CAIRO_STATUS_SUCCESS;

    return stream;
}

Here is the caller graph for this function:

cairo_output_stream_t* _cairo_output_stream_create_for_file ( const char *  filename)

Definition at line 298 of file cairo-output-stream.c.

{
    FILE *fp;
    cairo_output_stream_t *stream;

    fp = fopen (filename, "wb");
    if (fp == NULL)
       return NULL;
    
    stream = _cairo_output_stream_create (stdio_write, fp);
    if (stream == NULL)
       fclose (fp);
    stream->owns_closure_is_file = TRUE;

    return stream;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void _cairo_output_stream_destroy ( cairo_output_stream_t *  stream)

Definition at line 74 of file cairo-output-stream.c.

{
    if (stream->owns_closure_is_file) {
       FILE *file = stream->closure;
       fflush (file);
       fclose (file);
    }
    free (stream);
}

Here is the call graph for this function:

Here is the caller graph for this function:

long _cairo_output_stream_get_position ( cairo_output_stream_t *  stream)

Definition at line 271 of file cairo-output-stream.c.

{
    return stream->position;
}

Here is the caller graph for this function:

cairo_status_t _cairo_output_stream_get_status ( cairo_output_stream_t *  stream)

Definition at line 277 of file cairo-output-stream.c.

{
    return stream->status;
}

Here is the caller graph for this function:

cairo_status_t _cairo_output_stream_printf ( cairo_output_stream_t *  stream,
const char *  fmt,
  ... 
)

Definition at line 255 of file cairo-output-stream.c.

{
    va_list ap;
    cairo_status_t status;    

    va_start (ap, fmt);

    status = _cairo_output_stream_vprintf (stream, fmt, ap);

    va_end (ap);

    return status;
}

Here is the call graph for this function:

cairo_status_t _cairo_output_stream_vprintf ( cairo_output_stream_t *  stream,
const char *  fmt,
va_list  ap 
)

Definition at line 180 of file cairo-output-stream.c.

{
    char buffer[512];
    char *p;
    const char *f;
    int length_modifier;

    f = fmt;
    p = buffer;
    while (*f != '\0') {
       if (p == buffer + sizeof (buffer)) {
           _cairo_output_stream_write (stream, buffer, sizeof (buffer));
           p = buffer;
       }

       if (*f != '%') {
           *p++ = *f++;
           continue;
       }

       f++;

       _cairo_output_stream_write (stream, buffer, p - buffer);
       p = buffer;

       length_modifier = 0;
       if (*f == 'l') {
           length_modifier = LENGTH_MODIFIER_LONG;
           f++;
       }

       switch (*f | length_modifier) {
       case '%':
           buffer[0] = *f;
           buffer[1] = 0;
           break;
       case 'd':
           snprintf (buffer, sizeof buffer, "%d", va_arg (ap, int));
           break;
       case 'd' | LENGTH_MODIFIER_LONG:
           snprintf (buffer, sizeof buffer, "%ld", va_arg (ap, long int));
           break;
       case 'u':
           snprintf (buffer, sizeof buffer, "%u", va_arg (ap, unsigned int));
           break;
       case 'u' | LENGTH_MODIFIER_LONG:
           snprintf (buffer, sizeof buffer, "%lu", va_arg (ap, long unsigned int));
           break;
       case 'o':
           snprintf (buffer, sizeof buffer, "%o", va_arg (ap, int));
           break;
       case 's':
           snprintf (buffer, sizeof buffer, "%s", va_arg (ap, const char *));
           break;
       case 'f':
           dtostr (buffer, sizeof buffer, va_arg (ap, double));
           break;
       case 'c':
           buffer[0] = va_arg (ap, int);
           buffer[1] = 0;
           break;
       default:
           ASSERT_NOT_REACHED;
       }
       p = buffer + strlen (buffer);
       f++;
    }
    
    _cairo_output_stream_write (stream, buffer, p - buffer);

    return stream->status;
}

Here is the call graph for this function:

Here is the caller graph for this function:

cairo_status_t _cairo_output_stream_write ( cairo_output_stream_t *  stream,
const void data,
size_t  length 
)

Definition at line 85 of file cairo-output-stream.c.

{
    if (length == 0)
       return CAIRO_STATUS_SUCCESS;

    stream->status = stream->write_data (stream->closure, data, length);
    stream->position += length;

    return stream->status;
}

Here is the caller graph for this function:

void _cairo_output_stream_write_hex_string ( cairo_output_stream_t *  stream,
const char *  data,
size_t  length 
)

Definition at line 98 of file cairo-output-stream.c.

{
    const char hex_chars[] = "0123456789abcdef";
    char buffer[2];
    int i, column;

    for (i = 0, column = 0; i < length; i++, column++) {
       if (column == 38) {
           _cairo_output_stream_write (stream, "\n", 1);
           column = 0;
       }
       buffer[0] = hex_chars[(data[i] >> 4) & 0x0f];
       buffer[1] = hex_chars[data[i] & 0x0f];
       _cairo_output_stream_write (stream, buffer, 2);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int dtostr ( char *  buffer,
size_t  size,
double  d 
) [static]

Definition at line 123 of file cairo-output-stream.c.

{
  struct lconv *locale_data;
  const char *decimal_point;
  int decimal_point_len;
  char *p;
  int decimal_len;

  snprintf (buffer, size, "%f", d);
    
  locale_data = localeconv ();
  decimal_point = locale_data->decimal_point;
  decimal_point_len = strlen (decimal_point);
  
  assert (decimal_point_len != 0);
  p = buffer;
                         
  if (*p == '+' || *p == '-')
      p++;

  while (isdigit (*p))
      p++;
                                   
  if (strncmp (p, decimal_point, decimal_point_len) == 0) {
      *p = '.';
      decimal_len = strlen (p + decimal_point_len);
      memmove (p + 1, p + decimal_point_len, decimal_len);
      p[1 + decimal_len] = 0;

      /* Remove trailing zeros and decimal point if possible. */
      for (p = p + decimal_len; *p == '0'; p--)
         *p = 0;

      if (*p == '.') {
         *p = 0;
         p--;
      }
  }
                                           
  return p + 1 - buffer;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static cairo_status_t stdio_write ( void closure,
const unsigned char *  data,
unsigned int  length 
) [static]

Definition at line 287 of file cairo-output-stream.c.

Here is the call graph for this function:

Here is the caller graph for this function: