~ubuntu-branches/ubuntu/maverick/tn5250/maverick

« back to all changes in this revision

Viewing changes to lib5250/record.c

  • Committer: Bazaar Package Importer
  • Author(s): Carey Evans
  • Date: 2009-12-17 22:23:00 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20091217222300-cyutcin1bc0m9wrd
Tags: 0.17.4-2
Fix many compiler warnings, especially implicit pointer conversions
(closes: #561165, #561166).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* TN5250 - An implementation of the 5250 telnet protocol.
 
2
 * Copyright (C) 1997-2008 Michael Madore
 
3
 * 
 
4
 * This file is part of TN5250.
 
5
 *
 
6
 * TN5250 is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU Lesser General Public License as published by
 
8
 * the Free Software Foundation; either version 2.1, or (at your option)
 
9
 * any later version.
 
10
 * 
 
11
 * TN5250 is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU Lesser General Public License for more details.
 
15
 * 
 
16
 * You should have received a copy of the GNU Lesser General Public License
 
17
 * along with this software; see the file COPYING.  If not, write to
 
18
 * the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 
19
 * Boston, MA 02111-1307 USA
 
20
 * 
 
21
 */
 
22
#include "tn5250-private.h"
 
23
 
 
24
/****f* lib5250/tn5250_record_new
 
25
 * NAME
 
26
 *    tn5250_record_new
 
27
 * SYNOPSIS
 
28
 *    ret = tn5250_record_new ();
 
29
 * INPUTS
 
30
 *    None
 
31
 * DESCRIPTION
 
32
 *    DOCUMENT ME!!!
 
33
 *****/
 
34
Tn5250Record *tn5250_record_new()
 
35
{
 
36
   Tn5250Record *This = tn5250_new(Tn5250Record, 1);
 
37
   if (This == NULL)
 
38
      return NULL;
 
39
 
 
40
   tn5250_buffer_init (&(This->data));
 
41
 
 
42
   This->cur_pos = 0;
 
43
   This->prev = NULL;
 
44
   This->next = NULL;
 
45
   return This;
 
46
}
 
47
 
 
48
/****f* lib5250/tn5250_record_destroy
 
49
 * NAME
 
50
 *    tn5250_record_destroy
 
51
 * SYNOPSIS
 
52
 *    tn5250_record_destroy (This);
 
53
 * INPUTS
 
54
 *    Tn5250Record *       This       - 
 
55
 * DESCRIPTION
 
56
 *    DOCUMENT ME!!!
 
57
 *****/
 
58
void tn5250_record_destroy(Tn5250Record * This)
 
59
{
 
60
   if (This != NULL) {
 
61
      tn5250_buffer_free (&(This->data));
 
62
      free(This);
 
63
   }
 
64
}
 
65
 
 
66
/****f* lib5250/tn5250_record_get_byte
 
67
 * NAME
 
68
 *    tn5250_record_get_byte
 
69
 * SYNOPSIS
 
70
 *    ret = tn5250_record_get_byte (This);
 
71
 * INPUTS
 
72
 *    Tn5250Record *       This       - 
 
73
 * DESCRIPTION
 
74
 *    DOCUMENT ME!!!
 
75
 *****/
 
76
unsigned char tn5250_record_get_byte(Tn5250Record * This)
 
77
{
 
78
   This->cur_pos++;
 
79
   TN5250_ASSERT(This->cur_pos <= tn5250_record_length(This));
 
80
   return (tn5250_buffer_data (&(This->data)))[This->cur_pos - 1];
 
81
}
 
82
 
 
83
/****f* lib5250/tn5250_record_unget_byte
 
84
 * NAME
 
85
 *    tn5250_record_unget_byte
 
86
 * SYNOPSIS
 
87
 *    tn5250_record_unget_byte (This);
 
88
 * INPUTS
 
89
 *    Tn5250Record *       This       - 
 
90
 * DESCRIPTION
 
91
 *    DOCUMENT ME!!!
 
92
 *****/
 
93
void tn5250_record_unget_byte(Tn5250Record * This)
 
94
{
 
95
   TN5250_LOG(("Record::UnGetByte: entered.\n"));
 
96
   TN5250_ASSERT(This->cur_pos > 0);
 
97
   This->cur_pos--;
 
98
}
 
99
 
 
100
/****f* lib5250/tn5250_record_is_chain_end
 
101
 * NAME
 
102
 *    tn5250_record_is_chain_end
 
103
 * SYNOPSIS
 
104
 *    ret = tn5250_record_is_chain_end (This);
 
105
 * INPUTS
 
106
 *    Tn5250Record *       This       - 
 
107
 * DESCRIPTION
 
108
 *    DOCUMENT ME!!!
 
109
 *****/
 
110
int tn5250_record_is_chain_end(Tn5250Record * This)
 
111
{
 
112
   return tn5250_record_length(This) == This->cur_pos;
 
113
}
 
114
 
 
115
/****f* lib5250/tn5250_record_is_chain_end
 
116
 * NAME
 
117
 *    tn5250_record_skip_to_end
 
118
 * SYNOPSIS
 
119
 *    ret = tn5250_record_skip_to_end (This);
 
120
 * INPUTS
 
121
 *    Tn5250Record *       This       - 
 
122
 * DESCRIPTION
 
123
 *    DOCUMENT ME!!!
 
124
 *****/
 
125
void tn5250_record_skip_to_end(Tn5250Record * This)
 
126
{
 
127
   This->cur_pos = tn5250_record_length(This);
 
128
}
 
129
 
 
130
/****f* lib5250/tn5250_record_dump
 
131
 * NAME
 
132
 *    tn5250_record_dump
 
133
 * SYNOPSIS
 
134
 *    tn5250_record_dump (This);
 
135
 * INPUTS
 
136
 *    Tn5250Record *       This       - 
 
137
 * DESCRIPTION
 
138
 *    DOCUMENT ME!!!
 
139
 *****/
 
140
void tn5250_record_dump(Tn5250Record * This)
 
141
{
 
142
   tn5250_buffer_log (&(This->data),"@record");
 
143
   TN5250_LOG (("@eor\n"));
 
144
}
 
145
 
 
146
/****f* lib5250/tn5250_record_list_add
 
147
 * NAME
 
148
 *    tn5250_record_list_add
 
149
 * SYNOPSIS
 
150
 *    ret = tn5250_record_list_add (list, record);
 
151
 * INPUTS
 
152
 *    Tn5250Record *       list       - 
 
153
 *    Tn5250Record *       record     - 
 
154
 * DESCRIPTION
 
155
 *    Add a record to the end of a list of records.
 
156
 *****/
 
157
Tn5250Record *tn5250_record_list_add(Tn5250Record * list, Tn5250Record * record)
 
158
{
 
159
   if (list == NULL) {
 
160
      list = record->next = record->prev = record;
 
161
      return list;
 
162
   }
 
163
   record->next = list;
 
164
   record->prev = list->prev;
 
165
   record->prev->next = record;
 
166
   record->next->prev = record;
 
167
   return list;
 
168
}
 
169
 
 
170
/****f* lib5250/tn5250_record_list_remove
 
171
 * NAME
 
172
 *    tn5250_record_list_remove
 
173
 * SYNOPSIS
 
174
 *    ret = tn5250_record_list_remove (list, record);
 
175
 * INPUTS
 
176
 *    Tn5250Record *       list       - 
 
177
 *    Tn5250Record *       record     - 
 
178
 * DESCRIPTION
 
179
 *    Remove a record from a list of records.
 
180
 *****/
 
181
Tn5250Record *tn5250_record_list_remove(Tn5250Record * list, Tn5250Record * record)
 
182
{
 
183
   if (list == NULL)
 
184
      return NULL;
 
185
   if (list->next == list) {
 
186
      record->prev = record->next = NULL;
 
187
      return NULL;
 
188
   }
 
189
 
 
190
   if (list == record)
 
191
      list = list->next;
 
192
 
 
193
   record->next->prev = record->prev;
 
194
   record->prev->next = record->next;
 
195
   record->next = record->prev = NULL;
 
196
   return list;
 
197
}
 
198
 
 
199
/****f* lib5250/tn5250_record_list_destroy
 
200
 * NAME
 
201
 *    tn5250_record_list_destroy
 
202
 * SYNOPSIS
 
203
 *    ret = tn5250_record_list_destroy (list);
 
204
 * INPUTS
 
205
 *    Tn5250Record *       list       - 
 
206
 * DESCRIPTION
 
207
 *    Destroy all records in a record list and return NULL.
 
208
 *****/
 
209
Tn5250Record *tn5250_record_list_destroy(Tn5250Record * list)
 
210
{
 
211
   Tn5250Record *iter, *next;
 
212
 
 
213
   if ((iter = list) != NULL) {
 
214
      do {
 
215
         next = iter->next;
 
216
         tn5250_record_destroy(iter);
 
217
         iter = next;
 
218
      } while (iter != list);
 
219
   }
 
220
   return NULL;
 
221
}
 
222