1
#if !defined(lint) && !defined(DOS)
2
static char rcsid[] = "$Id: state.c 172 2006-10-06 17:00:18Z hubert@u.washington.edu $";
6
* ========================================================================
7
* Copyright 2006 University of Washington
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
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* ========================================================================
18
/*======================================================================
20
Implements the Pine state management routines
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"
34
* Globals referenced throughout pine...
36
struct pine *ps_global; /* THE global variable! */
40
* Debug level and output file defined here, referenced globally.
41
* The debug file is opened and initialized below...
43
int debug = DEFAULT_DEBUG;
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
59
char tmp_20k_buf[SIZEOF_20KBUF];
63
* new_pine_struct - allocate and fill in with default values a new pine struct
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;
89
msgno_init(&p->msgmap, 0L, SortArrival, 0);
98
* free_pine_struct -- free up allocated data in pine struct and then the
102
free_pine_struct(struct pine **pps)
104
if((*pps)->hostname != NULL)
105
fs_give((void **)&(*pps)->hostname);
107
if((*pps)->localdomain != NULL)
108
fs_give((void **)&(*pps)->localdomain);
110
if((*pps)->ttyo != NULL)
111
fs_give((void **)&(*pps)->ttyo);
113
if((*pps)->home_dir != NULL)
114
fs_give((void **)&(*pps)->home_dir);
116
if((*pps)->folders_dir != NULL)
117
fs_give((void **)&(*pps)->folders_dir);
119
if((*pps)->ui.homedir)
120
fs_give((void **)&(*pps)->ui.homedir);
123
fs_give((void **)&(*pps)->ui.login);
125
if((*pps)->ui.fullname)
126
fs_give((void **)&(*pps)->ui.fullname);
128
if((*pps)->index_disp_format)
129
fs_give((void **)&(*pps)->index_disp_format);
131
if((*pps)->conv_table){
132
if((*pps)->conv_table->table)
133
fs_give((void **) &(*pps)->conv_table->table);
135
if((*pps)->conv_table->from_charset)
136
fs_give((void **) &(*pps)->conv_table->from_charset);
138
if((*pps)->conv_table->to_charset)
139
fs_give((void **) &(*pps)->conv_table->to_charset);
141
fs_give((void **)&(*pps)->conv_table);
145
fs_give((void **)&(*pps)->pinerc);
147
#if defined(DOS) || defined(OS2)
149
fs_give((void **)&(*pps)->pine_dir);
151
if((*pps)->aux_files_dir)
152
fs_give((void **)&(*pps)->aux_files_dir);
154
if((*pps)->display_charmap)
155
fs_give((void **)&(*pps)->display_charmap);
157
if((*pps)->keyboard_charmap)
158
fs_give((void **)&(*pps)->keyboard_charmap);
160
if((*pps)->posting_charmap)
161
fs_give((void **)&(*pps)->posting_charmap);
166
fs_give((void **)&(*pps)->passfile);
167
#endif /* PASSFILE */
169
if((*pps)->hdr_colors)
170
free_spec_colors(&(*pps)->hdr_colors);
173
free_keyword_list(&(*pps)->keywords);
175
if((*pps)->kw_colors)
176
free_spec_colors(&(*pps)->kw_colors);
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);
186
fs_give((void **) &(*pps)->atmts);
191
fs_give((void **) pps);
196
free_pinerc_strings(struct pine **pps)
199
if((*pps)->prc->outstanding_pinerc_changes)
200
write_pinerc((*pps), Main, WRP_NONE);
203
rd_close_remdata(&(*pps)->prc->rd);
205
free_pinerc_s(&(*pps)->prc);
209
free_pinerc_s(&(*pps)->pconf);
211
if((*pps)->post_prc){
212
if((*pps)->post_prc->outstanding_pinerc_changes)
213
write_pinerc((*pps), Post, WRP_NONE);
215
if((*pps)->post_prc->rd)
216
rd_close_remdata(&(*pps)->post_prc->rd);
218
free_pinerc_s(&(*pps)->post_prc);
224
* free_vars -- give back resources acquired when we defined the
228
free_vars(struct pine *ps)
232
for(i = 0; ps && i <= V_LAST_VAR; i++)
233
free_variable_values(&ps->vars[i]);
238
free_variable_values(struct variable *var)
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);
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);
259
fs_give((void **)&var->fixed_val.p);
260
if(var->cmdline_val.p)
261
fs_give((void **)&var->cmdline_val.p);
268
new_pinerc_s(char *name)
270
PINERC_S *prc = NULL;
273
prc = (PINERC_S *)fs_get(sizeof(*prc));
274
memset((void *)prc, 0, sizeof(*prc));
275
prc->name = cpystr(name);
287
free_pinerc_s(PINERC_S **prc)
291
fs_give((void **)&(*prc)->name);
294
rd_free_remdata(&(*prc)->rd);
296
if((*prc)->pinerc_lines)
297
free_pinerc_lines(&(*prc)->pinerc_lines);
299
fs_give((void **)prc);