File: objects.c

package info (click to toggle)
neomutt 20251211%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,164 kB
  • sloc: ansic: 172,058; sh: 5,357; perl: 1,121; tcl: 1,065; python: 443; makefile: 48
file content (128 lines) | stat: -rw-r--r-- 2,754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/**
 * @file
 * Parse objects
 *
 * @authors
 * Copyright (C) 2025 Richard Russon <rich@flatcap.org>
 *
 * @copyright
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @page cli_objects Parse objects
 *
 * Parse objects
 */

#include "config.h"
#include <stddef.h>
#include "mutt/lib.h"
#include "objects.h"

/**
 * sa_clear - Empty a StringArray
 * @param sa String Array
 *
 * @note The Array itself isn't freed
 */
static void sa_clear(struct StringArray *sa)
{
  const char **cp = NULL;
  ARRAY_FOREACH(cp, sa)
  {
    FREE(cp);
  }

  ARRAY_FREE(sa);
}

/**
 * cli_shared_clear - Clear a CliShared
 * @param shared CliShared to clear
 */
static void cli_shared_clear(struct CliShared *shared)
{
  buf_dealloc(&shared->log_file);
  buf_dealloc(&shared->log_level);
  buf_dealloc(&shared->mbox_type);

  sa_clear(&shared->commands);
  sa_clear(&shared->user_files);
}

/**
 * cli_info_clear - Clear a CliInfo
 * @param info CliInfo to clear
 */
static void cli_info_clear(struct CliInfo *info)
{
  sa_clear(&info->alias_queries);
  sa_clear(&info->queries);
}

/**
 * cli_send_clear - Clear a CliSend
 * @param send CliSend to clear
 */
static void cli_send_clear(struct CliSend *send)
{
  sa_clear(&send->addresses);
  sa_clear(&send->attach);
  sa_clear(&send->bcc_list);
  sa_clear(&send->cc_list);

  buf_dealloc(&send->draft_file);
  buf_dealloc(&send->include_file);
  buf_dealloc(&send->subject);
}

/**
 * cli_tui_clear - Clear a CliTui
 * @param tui CliTui to clear
 */
static void cli_tui_clear(struct CliTui *tui)
{
  buf_dealloc(&tui->folder);
  buf_dealloc(&tui->nntp_server);
}

/**
 * command_line_new - Create a new CommandLine
 * @retval ptr New CommandLine
 */
struct CommandLine *command_line_new(void)
{
  return MUTT_MEM_CALLOC(1, struct CommandLine);
}

/**
 * command_line_free - Free a CommandLine
 * @param ptr CommandLine to free
 */
void command_line_free(struct CommandLine **ptr)
{
  if (!ptr || !*ptr)
    return;

  struct CommandLine *cl = *ptr;

  // cl->help - nothing to do
  cli_shared_clear(&cl->shared);
  cli_info_clear(&cl->info);
  cli_send_clear(&cl->send);
  cli_tui_clear(&cl->tui);

  FREE(ptr);
}