Rizin
unix-like reverse engineering framework and cli tools
hold.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2006-2021 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_config.h>
5 
7  free(hc->key);
8  free(hc->value);
9  free(hc);
10 }
11 
13  free(hc->key);
14  free(hc);
15 }
16 
17 static int key_cmp_hold_s(const void *a, const void *b) {
18  const char *a_s = (const char *)a;
19  const RzConfigHoldChar *b_s = (const RzConfigHoldChar *)b;
20  return strcmp(a_s, b_s->key);
21 }
22 
23 static int key_cmp_hold_i(const void *a, const void *b) {
24  const char *a_s = (const char *)a;
25  const RzConfigHoldNum *b_s = (const RzConfigHoldNum *)b;
26  return strcmp(a_s, b_s->key);
27 }
28 
41  va_list ap;
42  char *key;
43  va_start(ap, h);
44  if (!h->list_char) {
46  if (!h->list_char) {
47  va_end(ap);
48  return false;
49  }
50  }
51  while ((key = va_arg(ap, char *))) {
52  if (rz_list_find(h->list_char, key, key_cmp_hold_s)) {
53  continue;
54  }
55  const char *val = rz_config_get(h->cfg, key);
56  if (!val) {
57  continue;
58  }
60  if (hc) {
61  hc->key = strdup(key);
62  hc->value = strdup(val);
63  rz_list_append(h->list_char, hc);
64  }
65  }
66  va_end(ap);
67  return true;
68 }
69 
82  va_list ap;
83  char *key;
84  if (!h) {
85  return false;
86  }
87  if (!h->list_num) {
89  if (!h->list_num) {
90  return false;
91  }
92  }
93  va_start(ap, h);
94  while ((key = va_arg(ap, char *))) {
95  if (rz_list_find(h->list_num, key, key_cmp_hold_i)) {
96  continue;
97  }
99  if (!hc) {
100  continue;
101  }
102  hc->key = strdup(key);
103  hc->value = rz_config_get_i(h->cfg, key);
104  rz_list_append(h->list_num, hc);
105  }
106  va_end(ap);
107  return true;
108 }
109 
117  if (cfg) {
119  if (hold) {
120  hold->cfg = cfg;
121  return hold;
122  }
123  }
124  return NULL;
125 }
126 
133  RzListIter *iter;
134  RzConfigHoldChar *hchar;
135  RzConfigHoldNum *hnum;
136  if (h) {
137  RzConfig *cfg = h->cfg;
138  rz_list_foreach (h->list_num, iter, hnum) {
139  (void)rz_config_set_i(cfg, hnum->key, hnum->value);
140  }
141  rz_list_foreach (h->list_char, iter, hchar) {
142  (void)rz_config_set(cfg, hchar->key, hchar->value);
143  }
144  }
145 }
146 
153  if (h) {
154  rz_list_free(h->list_num);
155  rz_list_free(h->list_char);
156  RZ_FREE(h);
157  }
158 }
ut16 val
Definition: armass64_const.h:6
RZ_API ut64 rz_config_get_i(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:119
RZ_API RzConfigNode * rz_config_set(RzConfig *cfg, RZ_NONNULL const char *name, const char *value)
Definition: config.c:267
RZ_API RzConfigNode * rz_config_set_i(RzConfig *cfg, RZ_NONNULL const char *name, const ut64 i)
Definition: config.c:419
RZ_API RZ_BORROW const char * rz_config_get(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:75
#define RZ_API
#define NULL
Definition: cris-opc.c:27
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
Definition: sflib.h:118
static int key_cmp_hold_s(const void *a, const void *b)
Definition: hold.c:17
RZ_API void rz_config_hold_restore(RzConfigHold *h)
Restore whatever config options were previously saved in h.
Definition: hold.c:132
RZ_API RzConfigHold * rz_config_hold_new(RzConfig *cfg)
Create an opaque object to save/restore some configuration options.
Definition: hold.c:116
RZ_API bool rz_config_hold_s(RzConfigHold *h,...)
Save the current values of a list of config options that have string values.
Definition: hold.c:40
static void rz_config_hold_char_free(RzConfigHoldChar *hc)
Definition: hold.c:6
static void rz_config_hold_num_free(RzConfigHoldNum *hc)
Definition: hold.c:12
RZ_API bool rz_config_hold_i(RzConfigHold *h,...)
Save the current values of a list of config options that have integer values.
Definition: hold.c:81
static int key_cmp_hold_i(const void *a, const void *b)
Definition: hold.c:23
RZ_API void rz_config_hold_free(RzConfigHold *h)
Free a RzConfigHold object h.
Definition: hold.c:152
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_BORROW RzListIter * rz_list_find(RZ_NONNULL const RzList *list, const void *p, RZ_NONNULL RzListComparator cmp)
Returns RzListIter element which matches via the RzListComparator.
Definition: list.c:620
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_FREE(x)
Definition: rz_types.h:369
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
#define h(i)
Definition: sha256.c:48
RzConfig * cfg
Definition: rz_config.h:71