~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to gd/gd_io.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
/*
 
4
   * io.c
 
5
   *
 
6
   * Implements the imple I/O 'helper' routines.
 
7
   *
 
8
   * Not really essential, but these routines were used extensively in GD,
 
9
   * so they were moved here. They also make IOCtx calls look better...
 
10
   *
 
11
   * Written (or, at least, moved) 1999, Philip Warner.
 
12
   *
 
13
 */
 
14
 
 
15
#include <math.h>
 
16
#include <string.h>
 
17
#include <stdlib.h>
 
18
#include "gd.h"
 
19
 
 
20
/* Use this for commenting out debug-print statements. */
 
21
/* Just use the first '#define' to allow all the prints... */
 
22
/*#define IO_DBG(s) (s) */
 
23
#define IO_DBG(s)
 
24
 
 
25
 
 
26
/*
 
27
 * Write out a word to the I/O context pointer
 
28
 */
 
29
void
 
30
Putword (int w, gdIOCtx * ctx)
 
31
{
 
32
  unsigned char buf[2];
 
33
  buf[0] = w & 0xff;
 
34
  buf[1] = (w / 256) & 0xff;
 
35
  (ctx->putBuf) (ctx, (char *) buf, 2);
 
36
}
 
37
 
 
38
void
 
39
Putchar (int c, gdIOCtx * ctx)
 
40
{
 
41
  (ctx->putC) (ctx, c & 0xff);
 
42
}
 
43
 
 
44
void
 
45
gdPutC (const unsigned char c, gdIOCtx * ctx)
 
46
{
 
47
  (ctx->putC) (ctx, c);
 
48
}
 
49
 
 
50
void
 
51
gdPutWord (int w, gdIOCtx * ctx)
 
52
{
 
53
  IO_DBG (printf ("Putting word...\n"));
 
54
  (ctx->putC) (ctx, (unsigned char) (w >> 8));
 
55
  (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
 
56
  IO_DBG (printf ("put.\n"));
 
57
}
 
58
 
 
59
void
 
60
gdPutInt (int w, gdIOCtx * ctx)
 
61
{
 
62
  IO_DBG (printf ("Putting int...\n"));
 
63
  (ctx->putC) (ctx, (unsigned char) (w >> 24));
 
64
  (ctx->putC) (ctx, (unsigned char) ((w >> 16) & 0xFF));
 
65
  (ctx->putC) (ctx, (unsigned char) ((w >> 8) & 0xFF));
 
66
  (ctx->putC) (ctx, (unsigned char) (w & 0xFF));
 
67
  IO_DBG (printf ("put.\n"));
 
68
}
 
69
 
 
70
int
 
71
gdGetC (gdIOCtx * ctx)
 
72
{
 
73
  return ((ctx->getC) (ctx));
 
74
}
 
75
 
 
76
 
 
77
 
 
78
int
 
79
gdGetByte (int *result, gdIOCtx * ctx)
 
80
{
 
81
  int r;
 
82
  r = (ctx->getC) (ctx);
 
83
  if (r == EOF)
 
84
    {
 
85
      return 0;
 
86
    }
 
87
  *result = r;
 
88
  return 1;
 
89
}
 
90
 
 
91
int
 
92
gdGetWord (int *result, gdIOCtx * ctx)
 
93
{
 
94
  int r;
 
95
  r = (ctx->getC) (ctx);
 
96
  if (r == EOF)
 
97
    {
 
98
      return 0;
 
99
    }
 
100
  *result = r << 8;
 
101
  r = (ctx->getC) (ctx);
 
102
  if (r == EOF)
 
103
    {
 
104
      return 0;
 
105
    }
 
106
  *result += r;
 
107
  return 1;
 
108
}
 
109
 
 
110
 
 
111
int
 
112
gdGetInt (int *result, gdIOCtx * ctx)
 
113
{
 
114
  int r;
 
115
  r = (ctx->getC) (ctx);
 
116
  if (r == EOF)
 
117
    {
 
118
      return 0;
 
119
    }
 
120
  *result = r << 24;
 
121
 
 
122
  r = (ctx->getC) (ctx);
 
123
  if (r == EOF)
 
124
    {
 
125
      return 0;
 
126
    }
 
127
  *result += r << 16;
 
128
 
 
129
  r = (ctx->getC) (ctx);
 
130
  if (r == EOF)
 
131
    {
 
132
      return 0;
 
133
    }
 
134
  *result += r << 8;
 
135
 
 
136
  r = (ctx->getC) (ctx);
 
137
  if (r == EOF)
 
138
    {
 
139
      return 0;
 
140
    }
 
141
  *result += r;
 
142
 
 
143
  return 1;
 
144
}
 
145
 
 
146
int
 
147
gdPutBuf (const void *buf, int size, gdIOCtx * ctx)
 
148
{
 
149
  IO_DBG (printf ("Putting buf...\n"));
 
150
  return (ctx->putBuf) (ctx, buf, size);
 
151
  IO_DBG (printf ("put.\n"));
 
152
}
 
153
 
 
154
int
 
155
gdGetBuf (void *buf, int size, gdIOCtx * ctx)
 
156
{
 
157
  return (ctx->getBuf) (ctx, buf, size);
 
158
}
 
159
 
 
160
 
 
161
int
 
162
gdSeek (gdIOCtx * ctx, const int pos)
 
163
{
 
164
  IO_DBG (printf ("Seeking...\n"));
 
165
  return ((ctx->seek) (ctx, pos));
 
166
  IO_DBG (printf ("Done.\n"));
 
167
}
 
168
 
 
169
long
 
170
gdTell (gdIOCtx * ctx)
 
171
{
 
172
  IO_DBG (printf ("Telling...\n"));
 
173
  return ((ctx->tell) (ctx));
 
174
  IO_DBG (printf ("told.\n"));
 
175
}