~ubuntu-branches/debian/stretch/alpine/stretch

« back to all changes in this revision

Viewing changes to pith/state.c

  • Committer: Bazaar Package Importer
  • Author(s): Asheesh Laroia
  • Date: 2007-02-17 13:17:42 UTC
  • Revision ID: james.westby@ubuntu.com-20070217131742-99x5c6cpg1pbkdhw
Tags: upstream-0.82+dfsg
ImportĀ upstreamĀ versionĀ 0.82+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if !defined(lint) && !defined(DOS)
 
2
static char rcsid[] = "$Id: state.c 172 2006-10-06 17:00:18Z hubert@u.washington.edu $";
 
3
#endif
 
4
 
 
5
/*
 
6
 * ========================================================================
 
7
 * Copyright 2006 University of Washington
 
8
 *
 
9
 * Licensed under the Apache License, Version 2.0 (the "License");
 
10
 * you may not use this file except in compliance with the License.
 
11
 * You may obtain a copy of the License at
 
12
 *
 
13
 *     http://www.apache.org/licenses/LICENSE-2.0
 
14
 *
 
15
 * ========================================================================
 
16
 */
 
17
 
 
18
/*======================================================================
 
19
     state.c
 
20
     Implements the Pine state management routines
 
21
  ====*/
 
22
 
 
23
 
 
24
#include "../pith/headers.h"
 
25
#include "../pith/state.h"
 
26
#include "../pith/conf.h"
 
27
#include "../pith/init.h"
 
28
#include "../pith/sort.h"
 
29
#include "../pith/atttype.h"
 
30
#include "../pith/util.h"
 
31
 
 
32
 
 
33
/*
 
34
 * Globals referenced throughout pine...
 
35
 */
 
36
struct pine *ps_global;                         /* THE global variable! */
 
37
 
 
38
#ifdef  DEBUG
 
39
/*
 
40
 * Debug level and output file defined here, referenced globally.
 
41
 * The debug file is opened and initialized below...
 
42
 */
 
43
int          debug        = DEFAULT_DEBUG;
 
44
#endif
 
45
 
 
46
 
 
47
/*----------------------------------------------------------------------
 
48
  General use big buffer. It is used in the following places:
 
49
    compose_mail:    while parsing header of postponed message
 
50
    append_message2: while writing header into folder
 
51
    q_status_messageX: while doing printf formatting
 
52
    addr_book: Used to return expanded address in. (Can only use here 
 
53
               because mm_log doesn't q_status on PARSE errors !)
 
54
    alpine.c: When address specified on command line
 
55
    init.c: When expanding variable values
 
56
    and many many more...
 
57
 
 
58
 ----*/
 
59
char         tmp_20k_buf[SIZEOF_20KBUF];
 
60
 
 
61
 
 
62
/*
 
63
 * new_pine_struct - allocate and fill in with default values a new pine struct
 
64
 */
 
65
struct pine *
 
66
new_pine_struct(void)
 
67
{
 
68
    struct pine *p;
 
69
 
 
70
    p                  = (struct pine *)fs_get(sizeof (struct pine));
 
71
    memset((void *) p, 0, sizeof(struct pine));
 
72
    p->def_sort        = SortArrival;
 
73
    p->sort_types[0]   = SortSubject;
 
74
    p->sort_types[1]   = SortArrival;
 
75
    p->sort_types[2]   = SortFrom;
 
76
    p->sort_types[3]   = SortTo;
 
77
    p->sort_types[4]   = SortCc;
 
78
    p->sort_types[5]   = SortDate;
 
79
    p->sort_types[6]   = SortSize;
 
80
    p->sort_types[7]   = SortSubject2;
 
81
    p->sort_types[8]   = SortScore;
 
82
    p->sort_types[9]   = SortThread;
 
83
    p->sort_types[10]  = EndofList;
 
84
    p->atmts           = (ATTACH_S *) fs_get(sizeof(ATTACH_S));
 
85
    p->atmts_allocated = 1;
 
86
    p->atmts->description = NULL;
 
87
    p->low_speed       = 1;
 
88
    p->init_context    = -1;
 
89
    msgno_init(&p->msgmap, 0L, SortArrival, 0);
 
90
    init_init_vars(p);
 
91
 
 
92
    return(p);
 
93
}
 
94
 
 
95
 
 
96
 
 
97
/*
 
98
 * free_pine_struct -- free up allocated data in pine struct and then the
 
99
 *                     struct itself
 
100
 */
 
101
void
 
102
free_pine_struct(struct pine **pps)
 
103
 
104
    if((*pps)->hostname != NULL)
 
105
      fs_give((void **)&(*pps)->hostname);
 
106
 
 
107
    if((*pps)->localdomain != NULL)
 
108
      fs_give((void **)&(*pps)->localdomain);
 
109
 
 
110
    if((*pps)->ttyo != NULL)
 
111
      fs_give((void **)&(*pps)->ttyo);
 
112
 
 
113
    if((*pps)->home_dir != NULL)
 
114
      fs_give((void **)&(*pps)->home_dir);
 
115
 
 
116
    if((*pps)->folders_dir != NULL)
 
117
      fs_give((void **)&(*pps)->folders_dir);
 
118
 
 
119
    if((*pps)->ui.homedir)
 
120
      fs_give((void **)&(*pps)->ui.homedir);
 
121
 
 
122
    if((*pps)->ui.login)
 
123
      fs_give((void **)&(*pps)->ui.login);
 
124
 
 
125
    if((*pps)->ui.fullname)
 
126
      fs_give((void **)&(*pps)->ui.fullname);
 
127
 
 
128
    if((*pps)->index_disp_format)
 
129
      fs_give((void **)&(*pps)->index_disp_format);
 
130
 
 
131
    if((*pps)->conv_table){
 
132
        if((*pps)->conv_table->table)
 
133
          fs_give((void **) &(*pps)->conv_table->table);
 
134
        
 
135
        if((*pps)->conv_table->from_charset)
 
136
          fs_give((void **) &(*pps)->conv_table->from_charset);
 
137
        
 
138
        if((*pps)->conv_table->to_charset)
 
139
          fs_give((void **) &(*pps)->conv_table->to_charset);
 
140
 
 
141
        fs_give((void **)&(*pps)->conv_table);
 
142
    }
 
143
 
 
144
    if((*pps)->pinerc)
 
145
      fs_give((void **)&(*pps)->pinerc);
 
146
 
 
147
#if defined(DOS) || defined(OS2)
 
148
    if((*pps)->pine_dir)
 
149
      fs_give((void **)&(*pps)->pine_dir);
 
150
 
 
151
    if((*pps)->aux_files_dir)
 
152
      fs_give((void **)&(*pps)->aux_files_dir);
 
153
 
 
154
    if((*pps)->display_charmap)
 
155
      fs_give((void **)&(*pps)->display_charmap);
 
156
 
 
157
    if((*pps)->keyboard_charmap)
 
158
      fs_give((void **)&(*pps)->keyboard_charmap);
 
159
 
 
160
    if((*pps)->posting_charmap)
 
161
      fs_give((void **)&(*pps)->posting_charmap);
 
162
#endif
 
163
 
 
164
#ifdef PASSFILE
 
165
    if((*pps)->passfile)
 
166
      fs_give((void **)&(*pps)->passfile);
 
167
#endif /* PASSFILE */
 
168
 
 
169
    if((*pps)->hdr_colors)
 
170
      free_spec_colors(&(*pps)->hdr_colors);
 
171
 
 
172
    if((*pps)->keywords)
 
173
      free_keyword_list(&(*pps)->keywords);
 
174
 
 
175
    if((*pps)->kw_colors)
 
176
      free_spec_colors(&(*pps)->kw_colors);
 
177
 
 
178
    if((*pps)->atmts){
 
179
        int i;
 
180
 
 
181
        for(i = 0; (*pps)->atmts[i].description; i++){
 
182
            fs_give((void **) &(*pps)->atmts[i].description);
 
183
            fs_give((void **) &(*pps)->atmts[i].number);
 
184
        }
 
185
 
 
186
        fs_give((void **) &(*pps)->atmts);
 
187
    }
 
188
    
 
189
    free_vars(*pps);
 
190
 
 
191
    fs_give((void **) pps);
 
192
}
 
193
 
 
194
 
 
195
void
 
196
free_pinerc_strings(struct pine **pps)
 
197
{
 
198
    if((*pps)->prc){
 
199
        if((*pps)->prc->outstanding_pinerc_changes)
 
200
          write_pinerc((*pps), Main, WRP_NONE);
 
201
 
 
202
        if((*pps)->prc->rd)
 
203
          rd_close_remdata(&(*pps)->prc->rd);
 
204
        
 
205
        free_pinerc_s(&(*pps)->prc);
 
206
    }
 
207
 
 
208
    if((*pps)->pconf)
 
209
      free_pinerc_s(&(*pps)->pconf);
 
210
 
 
211
    if((*pps)->post_prc){
 
212
        if((*pps)->post_prc->outstanding_pinerc_changes)
 
213
          write_pinerc((*pps), Post, WRP_NONE);
 
214
 
 
215
        if((*pps)->post_prc->rd)
 
216
          rd_close_remdata(&(*pps)->post_prc->rd);
 
217
        
 
218
        free_pinerc_s(&(*pps)->post_prc);
 
219
    }
 
220
}
 
221
 
 
222
 
 
223
/*
 
224
 * free_vars -- give back resources acquired when we defined the
 
225
 *              variables list
 
226
 */
 
227
void
 
228
free_vars(struct pine *ps)
 
229
{
 
230
    register int i;
 
231
 
 
232
    for(i = 0; ps && i <= V_LAST_VAR; i++)
 
233
      free_variable_values(&ps->vars[i]);
 
234
}
 
235
 
 
236
 
 
237
void
 
238
free_variable_values(struct variable *var)
 
239
{
 
240
    if(var){
 
241
        if(var->is_list){
 
242
            free_list_array(&var->current_val.l);
 
243
            free_list_array(&var->main_user_val.l);
 
244
            free_list_array(&var->post_user_val.l);
 
245
            free_list_array(&var->global_val.l);
 
246
            free_list_array(&var->fixed_val.l);
 
247
            free_list_array(&var->cmdline_val.l);
 
248
        }
 
249
        else{
 
250
            if(var->current_val.p)
 
251
              fs_give((void **)&var->current_val.p);
 
252
            if(var->main_user_val.p)
 
253
              fs_give((void **)&var->main_user_val.p);
 
254
            if(var->post_user_val.p)
 
255
              fs_give((void **)&var->post_user_val.p);
 
256
            if(var->global_val.p)
 
257
              fs_give((void **)&var->global_val.p);
 
258
            if(var->fixed_val.p)
 
259
              fs_give((void **)&var->fixed_val.p);
 
260
            if(var->cmdline_val.p)
 
261
              fs_give((void **)&var->cmdline_val.p);
 
262
        }
 
263
    }
 
264
}
 
265
 
 
266
 
 
267
PINERC_S *
 
268
new_pinerc_s(char *name)
 
269
{
 
270
    PINERC_S *prc = NULL;
 
271
 
 
272
    if(name){
 
273
        prc = (PINERC_S *)fs_get(sizeof(*prc));
 
274
        memset((void *)prc, 0, sizeof(*prc));
 
275
        prc->name = cpystr(name);
 
276
        if(IS_REMOTE(name))
 
277
          prc->type = RemImap;
 
278
        else
 
279
          prc->type = Loc;
 
280
    }
 
281
 
 
282
    return(prc);
 
283
}
 
284
 
 
285
 
 
286
void
 
287
free_pinerc_s(PINERC_S **prc)
 
288
{
 
289
    if(prc && *prc){
 
290
        if((*prc)->name)
 
291
          fs_give((void **)&(*prc)->name);
 
292
 
 
293
        if((*prc)->rd)
 
294
          rd_free_remdata(&(*prc)->rd);
 
295
 
 
296
        if((*prc)->pinerc_lines)
 
297
          free_pinerc_lines(&(*prc)->pinerc_lines);
 
298
 
 
299
        fs_give((void **)prc);
 
300
    }
 
301
}