Evince
Evince is a document viewer capable of displaying multiple and single page document formats like PDF and Postscript.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
common.c File Reference
#include <config.h>
#include <stdlib.h>
#include <string.h>
#include "common.h"
+ Include dependency graph for common.c:

Go to the source code of this file.

Functions

long fsgetn (FILE *p, size_t n)
 
Ulong fugetn (FILE *p, size_t n)
 
long msgetn (const Uchar *p, size_t n)
 
Ulong mugetn (const Uchar *p, size_t n)
 
char * read_string (FILE *in, int s, char *buffer, size_t len)
 
size_t read_bcpl (FILE *in, char *buffer, size_t maxlen, size_t wanted)
 
char * read_alloc_bcpl (FILE *in, size_t maxlen, size_t *size)
 
void buff_free (Buffer *buf)
 
void buff_init (Buffer *buf)
 
size_t buff_add (Buffer *buf, const char *data, size_t len)
 
char * buff_gets (Buffer *buf, size_t *length)
 

Function Documentation

size_t buff_add ( Buffer buf,
const char *  data,
size_t  len 
)

Definition at line 134 of file common.c.

135 {
136  if(!len && data)
137  len = strlen(data);
138  if(buf->length + len + 1 > buf->size) {
139  buf->size = buf->length + len + 256;
140  buf->data = mdvi_realloc(buf->data, buf->size);
141  }
142  memcpy(buf->data + buf->length, data, len);
143  buf->length += len;
144  return buf->length;
145 }

+ Here is the caller graph for this function:

void buff_free ( Buffer buf)

Definition at line 120 of file common.c.

121 {
122  if(buf->data)
123  mdvi_free(buf->data);
124  buff_init(buf);
125 }
char* buff_gets ( Buffer buf,
size_t *  length 
)

Definition at line 147 of file common.c.

148 {
149  char *ptr;
150  char *ret;
151  size_t len;
152 
153  ptr = strchr(buf->data, '\n');
154  if(ptr == NULL)
155  return NULL;
156  ptr++; /* include newline */
157  len = ptr - buf->data;
158  ret = mdvi_malloc(len + 1);
159  if(len > 0) {
160  memcpy(ret, buf->data, len);
161  memmove(buf->data, buf->data + len, buf->length - len);
162  buf->length -= len;
163  }
164  ret[len] = 0;
165  if(length) *length = len;
166  return ret;
167 }
void buff_init ( Buffer buf)

Definition at line 127 of file common.c.

128 {
129  buf->data = NULL;
130  buf->size = 0;
131  buf->length = 0;
132 }

+ Here is the caller graph for this function:

long fsgetn ( FILE *  p,
size_t  n 
)

Definition at line 25 of file common.c.

26 {
27  long v;
28 
29  v = fgetbyte(p);
30  if(v & 0x80)
31  v -= 0x100;
32  while(--n > 0)
33  v = (v << 8) | fgetbyte(p);
34  return v;
35 }
Ulong fugetn ( FILE *  p,
size_t  n 
)

Definition at line 37 of file common.c.

38 {
39  Ulong v;
40 
41  v = fgetbyte(p);
42  while(--n > 0)
43  v = (v << 8) | fgetbyte(p);
44  return v;
45 }

+ Here is the caller graph for this function:

long msgetn ( const Uchar p,
size_t  n 
)

Definition at line 47 of file common.c.

48 {
49  long v = (long)*p++;
50 
51  if(v & 0x80)
52  v -= 0x100;
53  while(--n > 0)
54  v = (v << 8) | *p++;
55  return v;
56 }

+ Here is the caller graph for this function:

Ulong mugetn ( const Uchar p,
size_t  n 
)

Definition at line 58 of file common.c.

59 {
60  Ulong v = (Ulong)*p++;
61 
62  while(--n > 0)
63  v = (v << 8) | *p++;
64  return v;
65 }

+ Here is the caller graph for this function:

char* read_alloc_bcpl ( FILE *  in,
size_t  maxlen,
size_t *  size 
)

Definition at line 98 of file common.c.

99 {
100  size_t i;
101  char *buffer;
102 
103  i = (size_t)fuget1(in);
104  if(maxlen && i > maxlen)
105  i = maxlen;
106  buffer = (char *)malloc(i + 1);
107  if(buffer == NULL)
108  return NULL;
109  if(fread(buffer, i, 1, in) != 1) {
110  free(buffer);
111  return NULL;
112  }
113  buffer[i] = '\0';
114  if(size) *size = i;
115  return buffer;
116 }
size_t read_bcpl ( FILE *  in,
char *  buffer,
size_t  maxlen,
size_t  wanted 
)

Definition at line 83 of file common.c.

84 {
85  size_t i;
86 
87  i = (int)fuget1(in);
88  if(maxlen && i > maxlen)
89  i = maxlen;
90  if(fread(buffer, i, 1, in) != 1)
91  return -1;
92  buffer[i] = '\0';
93  while(wanted-- > i)
94  (void)fgetc(in);
95  return i;
96 }
char* read_string ( FILE *  in,
int  s,
char *  buffer,
size_t  len 
)

Definition at line 67 of file common.c.

68 {
69  int n;
70  char *str;
71 
72  n = fugetn(in, s ? s : 1);
73  if((str = buffer) == NULL || n + 1 > len)
74  str = mdvi_malloc(n + 1);
75  if(fread(str, 1, n, in) != n) {
76  if(str != buffer) mdvi_free(str);
77  return NULL;
78  }
79  str[n] = 0;
80  return str;
81 }

+ Here is the caller graph for this function: