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
unarr-imp.h File Reference
#include "../unarr.h"
#include "allocator.h"
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include <inttypes.h>
+ Include dependency graph for unarr-imp.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ar_stream_s
 
struct  ar_archive_s
 

Macros

#define warn(...)   ar_log("!", __FILE__, __LINE__, __VA_ARGS__)
 
#define log(...)   ar_log("-", __FILE__, __LINE__, __VA_ARGS__)
 

Typedefs

typedef void(* ar_stream_close_fn )(void *data)
 
typedef size_t(* ar_stream_read_fn )(void *data, void *buffer, size_t count)
 
typedef bool(* ar_stream_seek_fn )(void *data, off64_t offset, int origin)
 
typedef off64_t(* ar_stream_tell_fn )(void *data)
 
typedef void(* ar_archive_close_fn )(ar_archive *ar)
 
typedef bool(* ar_parse_entry_fn )(ar_archive *ar, off64_t offset)
 
typedef const char *(* ar_entry_get_name_fn )(ar_archive *ar)
 
typedef bool(* ar_entry_uncompress_fn )(ar_archive *ar, void *buffer, size_t count)
 
typedef size_t(* ar_get_global_comment_fn )(ar_archive *ar, void *buffer, size_t count)
 

Functions

size_t ar_conv_rune_to_utf8 (wchar_t rune, char *out, size_t size)
 
char * ar_conv_dos_to_utf8 (const char *astr)
 
time64_t ar_conv_dosdate_to_filetime (uint32_t dosdate)
 
uint32_t ar_crc32 (uint32_t crc32, const unsigned char *data, size_t data_len)
 
ar_streamar_open_stream (void *data, ar_stream_close_fn close, ar_stream_read_fn read, ar_stream_seek_fn seek, ar_stream_tell_fn tell)
 
void ar_log (const char *prefix, const char *file, int line, const char *msg,...)
 
ar_archivear_open_archive (ar_stream *stream, size_t struct_size, ar_archive_close_fn close, ar_parse_entry_fn parse_entry, ar_entry_get_name_fn get_name, ar_entry_uncompress_fn uncompress, ar_get_global_comment_fn get_comment, off64_t first_entry_offset)
 

Macro Definition Documentation

#define log (   ...)    ar_log("-", __FILE__, __LINE__, __VA_ARGS__)

Definition at line 49 of file unarr-imp.h.

#define warn (   ...)    ar_log("!", __FILE__, __LINE__, __VA_ARGS__)

Definition at line 47 of file unarr-imp.h.

Typedef Documentation

typedef void(* ar_archive_close_fn)(ar_archive *ar)

Definition at line 55 of file unarr-imp.h.

typedef const char*(* ar_entry_get_name_fn)(ar_archive *ar)

Definition at line 57 of file unarr-imp.h.

typedef bool(* ar_entry_uncompress_fn)(ar_archive *ar, void *buffer, size_t count)

Definition at line 58 of file unarr-imp.h.

typedef size_t(* ar_get_global_comment_fn)(ar_archive *ar, void *buffer, size_t count)

Definition at line 59 of file unarr-imp.h.

typedef bool(* ar_parse_entry_fn)(ar_archive *ar, off64_t offset)

Definition at line 56 of file unarr-imp.h.

typedef void(* ar_stream_close_fn)(void *data)

Definition at line 30 of file unarr-imp.h.

typedef size_t(* ar_stream_read_fn)(void *data, void *buffer, size_t count)

Definition at line 31 of file unarr-imp.h.

typedef bool(* ar_stream_seek_fn)(void *data, off64_t offset, int origin)

Definition at line 32 of file unarr-imp.h.

typedef off64_t(* ar_stream_tell_fn)(void *data)

Definition at line 33 of file unarr-imp.h.

Function Documentation

char* ar_conv_dos_to_utf8 ( const char *  astr)

Definition at line 53 of file conv.c.

54 {
55  char *str, *out;
56  const char *in;
57  size_t size;
58 
59  size = 0;
60  for (in = astr; *in; in++) {
61  char buf[4];
62  size += ar_conv_rune_to_utf8(gCp437[(uint8_t)*in], buf, sizeof(buf));
63  }
64 
65  if (size == (size_t)-1)
66  return NULL;
67  str = malloc(size + 1);
68  if (!str)
69  return NULL;
70 
71  for (in = astr, out = str; *in; in++) {
72  out += ar_conv_rune_to_utf8(gCp437[(uint8_t)*in], out, str + size - out);
73  }
74  *out = '\0';
75 
76  return str;
77 }

+ Here is the caller graph for this function:

time64_t ar_conv_dosdate_to_filetime ( uint32_t  dosdate)

Definition at line 79 of file conv.c.

80 {
81  struct tm tm;
82  time_t t1, t2;
83 
84  tm.tm_sec = (dosdate & 0x1F) * 2;
85  tm.tm_min = (dosdate >> 5) & 0x3F;
86  tm.tm_hour = (dosdate >> 11) & 0x1F;
87  tm.tm_mday = (dosdate >> 16) & 0x1F;
88  tm.tm_mon = ((dosdate >> 21) & 0x0F) - 1;
89  tm.tm_year = ((dosdate >> 25) & 0x7F) + 80;
90  tm.tm_isdst = -1;
91 
92  t1 = mktime(&tm);
93  t2 = mktime(gmtime(&t1));
94 
95  return (time64_t)(2 * t1 - t2 + 11644473600) * 10000000;
96 }

+ Here is the caller graph for this function:

size_t ar_conv_rune_to_utf8 ( wchar_t  rune,
char *  out,
size_t  size 
)

Definition at line 28 of file conv.c.

29 {
30  if (size < 1)
31  return 0;
32  if (rune < 0x0080) {
33  *out++ = rune & 0x7F;
34  return 1;
35  }
36  if (rune < 0x0800 && size >= 2) {
37  *out++ = 0xC0 | ((rune >> 6) & 0x1F);
38  *out++ = 0x80 | (rune & 0x3F);
39  return 2;
40  }
41  if (size >= 3) {
42  if ((0xD800 <= rune && rune <= 0xDFFF) || rune >= 0x10000)
43  rune = 0xFFFD;
44  *out++ = 0xE0 | ((rune >> 12) & 0x0F);
45  *out++ = 0x80 | ((rune >> 6) & 0x3F);
46  *out++ = 0x80 | (rune & 0x3F);
47  return 3;
48  }
49  *out++ = '?';
50  return 1;
51 }

+ Here is the caller graph for this function:

uint32_t ar_crc32 ( uint32_t  crc32,
const unsigned char *  data,
size_t  data_len 
)

Definition at line 13 of file crc32.c.

14 {
15  if (!crc_table_ready) {
16  uint32_t i, j;
17  uint32_t h = 1;
18  crc_table[0] = 0;
19  for (i = 128; i; i >>= 1) {
20  h = (h >> 1) ^ ((h & 1) ? 0xEDB88320 : 0);
21  for (j = 0; j < 256; j += 2 * i) {
22  crc_table[i + j] = crc_table[j] ^ h;
23  }
24  }
25  crc_table_ready = true;
26  }
27 
28  crc32 = crc32 ^ 0xFFFFFFFF;
29  while (data_len-- > 0) {
30  crc32 = (crc32 >> 8) ^ crc_table[(crc32 ^ *data++) & 0xFF];
31  }
32  return crc32 ^ 0xFFFFFFFF;
33 }

+ Here is the caller graph for this function:

void ar_log ( const char *  prefix,
const char *  file,
int  line,
const char *  msg,
  ... 
)

Definition at line 95 of file unarr.c.

96 {
97  va_list args;
98  va_start(args, msg);
99  if (prefix)
100  fprintf(stderr, "%s ", prefix);
101  if (strrchr(file, '/'))
102  file = strrchr(file, '/') + 1;
103  if (strrchr(file, '\\'))
104  file = strrchr(file, '\\') + 1;
105  fprintf(stderr, "%s:%d: ", file, line);
106  vfprintf(stderr, msg, args);
107  fprintf(stderr, "\n");
108  va_end(args);
109 }
ar_archive* ar_open_archive ( ar_stream stream,
size_t  struct_size,
ar_archive_close_fn  close,
ar_parse_entry_fn  parse_entry,
ar_entry_get_name_fn  get_name,
ar_entry_uncompress_fn  uncompress,
ar_get_global_comment_fn  get_comment,
off64_t  first_entry_offset 
)

Definition at line 6 of file unarr.c.

9 {
10  ar_archive *ar = malloc(struct_size);
11  if (!ar)
12  return NULL;
13  memset(ar, 0, struct_size);
14  ar->close = close;
15  ar->parse_entry = parse_entry;
16  ar->get_name = get_name;
17  ar->uncompress = uncompress;
18  ar->get_comment = get_comment;
19  ar->stream = stream;
20  ar->entry_offset_first = first_entry_offset;
21  ar->entry_offset_next = first_entry_offset;
22  return ar;
23 }

+ Here is the caller graph for this function:

ar_stream* ar_open_stream ( void *  data,
ar_stream_close_fn  close,
ar_stream_read_fn  read,
ar_stream_seek_fn  seek,
ar_stream_tell_fn  tell 
)

Definition at line 6 of file stream.c.

7 {
8  ar_stream *stream = malloc(sizeof(ar_stream));
9  if (!stream) {
10  close(data);
11  return NULL;
12  }
13  stream->data = data;
14  stream->close = close;
15  stream->read = read;
16  stream->seek = seek;
17  stream->tell = tell;
18  return stream;
19 }

+ Here is the caller graph for this function: