* clear out some warnings by gcc 9.3.1.
[alpine.git] / pith / state.c
bloba7728d67fbbfb21d10706a8edb7a8c7ebb493ff0
1 #if !defined(lint) && !defined(DOS)
2 static char rcsid[] = "$Id: state.c 1074 2008-06-04 00:08:43Z hubert@u.washington.edu $";
3 #endif
5 /*
6 * ========================================================================
7 * Copyright 2013-2020 Eduardo Chappa
8 * Copyright 2006-2008 University of Washington
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * ========================================================================
19 /*======================================================================
20 state.c
21 Implements the Pine state management routines
22 ====*/
25 #include "../pith/headers.h"
26 #include "../pith/state.h"
27 #include "../pith/conf.h"
28 #include "../pith/init.h"
29 #include "../pith/sort.h"
30 #include "../pith/atttype.h"
31 #include "../pith/util.h"
32 #include "../pith/mailindx.h"
33 #include "../pith/remote.h"
34 #include "../pith/list.h"
35 #include "../pith/smime.h"
36 #include "../pith/ical.h"
37 #include "../pith/bldaddr.h"
40 * Globals referenced throughout pine...
42 struct pine *ps_global; /* THE global variable! */
44 #ifdef DEBUG
46 * Debug level and output file defined here, referenced globally.
47 * The debug file is opened and initialized below...
49 int debug = DEFAULT_DEBUG;
50 #endif
53 /*----------------------------------------------------------------------
54 General use big buffer. It is used in the following places:
55 compose_mail: while parsing header of postponed message
56 append_message2: while writing header into folder
57 q_status_messageX: while doing printf formatting
58 addr_book: Used to return expanded address in. (Can only use here
59 because mm_log doesn't q_status on PARSE errors !)
60 alpine.c: When address specified on command line
61 init.c: When expanding variable values
62 and many many more...
64 ----*/
65 char tmp_20k_buf[SIZEOF_20KBUF];
69 * new_pine_struct - allocate and fill in with default values a new pine struct
71 struct pine *
72 new_pine_struct(void)
74 struct pine *p;
76 p = (struct pine *)fs_get(sizeof (struct pine));
77 memset((void *) p, 0, sizeof(struct pine));
78 p->def_sort = SortArrival;
79 p->sort_types[0] = SortSubject;
80 p->sort_types[1] = SortArrival;
81 p->sort_types[2] = SortFrom;
82 p->sort_types[3] = SortTo;
83 p->sort_types[4] = SortCc;
84 p->sort_types[5] = SortDate;
85 p->sort_types[6] = SortSize;
86 p->sort_types[7] = SortSubject2;
87 p->sort_types[8] = SortScore;
88 p->sort_types[9] = SortThread;
89 p->sort_types[10] = EndofList;
90 #ifdef SMIME
92 * We need to have access to p->smime even before calling
93 * smime_init() so that we can set do_encrypt and do_sign.
95 p->smime = new_smime_struct();
96 #endif /* SMIME */
97 p->atmts = (ATTACH_S *) fs_get(sizeof(ATTACH_S));
98 p->atmts_allocated = 1;
99 p->atmts->description = NULL;
100 p->low_speed = 1;
101 p->init_context = -1;
102 /* msgno_init(&p->msgmap, 0L, SortArrival, 0);*/
103 init_init_vars(p);
105 return(p);
111 * free_pine_struct -- free up allocated data in pine struct and then the
112 * struct itself
114 void
115 free_pine_struct(struct pine **pps)
117 if(!(pps && (*pps)))
118 return;
120 if((*pps)->free_initial_cmds != NULL)
121 fs_give((void **) &(*pps)->free_initial_cmds);
123 if((*pps)->id != NULL)
124 mail_free_idlist(&(*pps)->id);
126 if((*pps)->hostname != NULL)
127 fs_give((void **)&(*pps)->hostname);
129 if((*pps)->localdomain != NULL)
130 fs_give((void **)&(*pps)->localdomain);
132 if((*pps)->ttyo != NULL)
133 fs_give((void **)&(*pps)->ttyo);
135 if((*pps)->home_dir != NULL)
136 fs_give((void **)&(*pps)->home_dir);
138 if((*pps)->folders_dir != NULL)
139 fs_give((void **)&(*pps)->folders_dir);
141 if((*pps)->html_dir != NULL)
142 fs_give((void **)&(*pps)->html_dir);
144 if((*pps)->html_dir_list != NULL)
145 free_html_log(&(*pps)->html_dir_list);
147 if((*pps)->ui.homedir)
148 fs_give((void **)&(*pps)->ui.homedir);
150 if((*pps)->ui.login)
151 fs_give((void **)&(*pps)->ui.login);
153 if((*pps)->ui.fullname)
154 fs_give((void **)&(*pps)->ui.fullname);
156 free_index_format(&(*pps)->index_disp_format);
158 if((*pps)->conv_table){
159 if((*pps)->conv_table->table)
160 fs_give((void **) &(*pps)->conv_table->table);
162 if((*pps)->conv_table->from_charset)
163 fs_give((void **) &(*pps)->conv_table->from_charset);
165 if((*pps)->conv_table->to_charset)
166 fs_give((void **) &(*pps)->conv_table->to_charset);
168 fs_give((void **)&(*pps)->conv_table);
171 if((*pps)->pinerc)
172 fs_give((void **)&(*pps)->pinerc);
174 #if defined(DOS) || defined(OS2)
175 if((*pps)->pine_dir)
176 fs_give((void **)&(*pps)->pine_dir);
178 if((*pps)->aux_files_dir)
179 fs_give((void **)&(*pps)->aux_files_dir);
180 #endif
182 if((*pps)->display_charmap)
183 fs_give((void **)&(*pps)->display_charmap);
185 if((*pps)->keyboard_charmap)
186 fs_give((void **)&(*pps)->keyboard_charmap);
188 if((*pps)->posting_charmap)
189 fs_give((void **)&(*pps)->posting_charmap);
191 #ifdef SMIME
192 if((*pps)->pwdcertdir)
193 fs_give((void **)&(*pps)->pwdcertdir);
195 if((*pps)->pwdcert){
196 PERSONAL_CERT *pc;
198 pc = (PERSONAL_CERT *) (*pps)->pwdcert;
199 free_personal_certs(&pc);
200 (*pps)->pwdcert = NULL;
203 if((*pps)->pwdcertlist){
204 CertList *cert;
206 cert = (CertList *) (*pps)->pwdcertlist;
207 free_certlist(&cert);
208 (*pps)->pwdcertlist = NULL;
211 if((*pps)->backuppassword){
212 CertList *cert;
214 cert = (CertList *) (*pps)->backuppassword;
215 free_certlist(&cert);
216 (*pps)->backuppassword = NULL;
218 #endif /* SMIME */
221 #ifdef PASSFILE
222 if((*pps)->passfile)
223 fs_give((void **)&(*pps)->passfile);
224 #endif /* PASSFILE */
226 if((*pps)->hdr_colors)
227 free_spec_colors(&(*pps)->hdr_colors);
229 if((*pps)->index_token_colors)
230 free_spec_colors(&(*pps)->index_token_colors);
232 if((*pps)->keywords)
233 free_keyword_list(&(*pps)->keywords);
235 if((*pps)->kw_colors)
236 free_spec_colors(&(*pps)->kw_colors);
238 if((*pps)->atmts){
239 int i;
241 for(i = 0; (*pps)->atmts[i].description; i++){
242 fs_give((void **) &(*pps)->atmts[i].description);
243 fs_give((void **) &(*pps)->atmts[i].number);
246 fs_give((void **) &(*pps)->atmts);
249 if((*pps)->msgmap)
250 msgno_give(&(*pps)->msgmap);
252 free_vars(*pps);
254 fs_give((void **) pps);
258 void
259 free_pinerc_strings(struct pine **pps)
261 if((*pps)->prc){
262 if((*pps)->prc->outstanding_pinerc_changes)
263 write_pinerc((*pps), Main, WRP_NONE);
265 if((*pps)->prc->rd)
266 rd_close_remdata(&(*pps)->prc->rd);
268 free_pinerc_s(&(*pps)->prc);
271 if((*pps)->pconf)
272 free_pinerc_s(&(*pps)->pconf);
274 if((*pps)->post_prc){
275 if((*pps)->post_prc->outstanding_pinerc_changes)
276 write_pinerc((*pps), Post, WRP_NONE);
278 if((*pps)->post_prc->rd)
279 rd_close_remdata(&(*pps)->post_prc->rd);
281 free_pinerc_s(&(*pps)->post_prc);
287 * free_vars -- give back resources acquired when we defined the
288 * variables list
290 void
291 free_vars(struct pine *ps)
293 register int i;
295 for(i = 0; ps && i <= V_LAST_VAR; i++)
296 free_variable_values(&ps->vars[i]);
300 void
301 free_variable_values(struct variable *var)
303 if(var){
304 if(var->is_list){
305 free_list_array(&var->current_val.l);
306 free_list_array(&var->main_user_val.l);
307 free_list_array(&var->post_user_val.l);
308 free_list_array(&var->global_val.l);
309 free_list_array(&var->fixed_val.l);
310 free_list_array(&var->cmdline_val.l);
312 else{
313 if(var->current_val.p)
314 fs_give((void **)&var->current_val.p);
315 if(var->main_user_val.p)
316 fs_give((void **)&var->main_user_val.p);
317 if(var->post_user_val.p)
318 fs_give((void **)&var->post_user_val.p);
319 if(var->global_val.p)
320 fs_give((void **)&var->global_val.p);
321 if(var->fixed_val.p)
322 fs_give((void **)&var->fixed_val.p);
323 if(var->cmdline_val.p)
324 fs_give((void **)&var->cmdline_val.p);
330 PINERC_S *
331 new_pinerc_s(char *name)
333 PINERC_S *prc = NULL;
335 if(name){
336 prc = (PINERC_S *)fs_get(sizeof(*prc));
337 memset((void *)prc, 0, sizeof(*prc));
338 prc->name = cpystr(name);
339 if(IS_REMOTE(name))
340 prc->type = RemImap;
341 else
342 prc->type = Loc;
345 return(prc);
349 void
350 free_pinerc_s(PINERC_S **prc)
352 if(prc && *prc){
353 if((*prc)->name)
354 fs_give((void **)&(*prc)->name);
356 if((*prc)->rd)
357 rd_free_remdata(&(*prc)->rd);
359 if((*prc)->pinerc_lines)
360 free_pinerc_lines(&(*prc)->pinerc_lines);
362 fs_give((void **)prc);
366 void
367 free_pith_module_globals(void)
369 free_filter_module_globals();
370 ical_free_all();
371 free_bldaddr_module_globals();
372 fname_to_locale(NULL);
373 fname_to_utf8(NULL);