Debian Codegraph @

Source/ShConstants.cpp

raw
1 /*
2 * ShConstants.cpp
3 *
4 * This file is a part of NSIS.
5 *
6 * Copyright (C) 1999-2026 Nullsoft and Contributors
7 *
8 * Licensed under the zlib/libpng license (the "License");
9 * you may not use this file except in compliance with the License.
10 *
11 * Licence details can be found in the file COPYING.
12 *
13 * This software is provided 'as-is', without any express or implied
14 * warranty.
15 *
16 * Unicode support by Jim Park -- 08/24/2007
17 */
18
19 #include "ShConstants.h"
20
21 ConstantsStringList::ConstantsStringList()
22 {
23 m_index = 0;
24 }
25
26 int ConstantsStringList::add(const TCHAR *name, int value1, int value2)
27 {
28 int pos=SortedStringListND<struct constantstring>::add(name);
29 if (pos == -1) return -1;
30
31 constantstring *ptr = ((constantstring*) m_gr.get()) + pos;
32 ptr->index = m_index;
33 ptr->pos = pos;
34 ptr->value1 = value1;
35 ptr->value2 = value2;
36
37 int temp = m_index;
38 m_index++;
39
40 return temp;
41 }
42
43 int ConstantsStringList::get(const TCHAR *name, int n_chars /*= -1*/)
44 {
45 int v=SortedStringListND<struct constantstring>::find(name, n_chars);
46 if (v==-1) return -1;
47 return (((struct constantstring*) m_gr.get())[v].index);
48 }
49
50 int ConstantsStringList::getnum()
51 {
52 return m_index;
53 }
54
55 int ConstantsStringList::get_value1(int idx)
56 {
57 int pos=get_internal_idx(idx);
58 if (pos==-1) return -1;
59 return (((struct constantstring*) m_gr.get())[pos].value1);
60 }
61
62 int ConstantsStringList::get_value2(int idx)
63 {
64 int pos=get_internal_idx(idx);
65 if (pos==-1) return -1;
66 return (((struct constantstring*) m_gr.get())[pos].value2);
67 }
68
69 TCHAR* ConstantsStringList::idx2name(int idx)
70 {
71 int pos=get_internal_idx(idx);
72 if (pos==-1) return NULL;
73 struct constantstring *data=(struct constantstring *) m_gr.get();
74 return ((TCHAR*) m_strings.get() + data[pos].name);
75 }
76
77 int ConstantsStringList::get_internal_idx(int idx)
78 {
79 struct constantstring *data=(struct constantstring *) m_gr.get();
80
81 // We do a linear search because the strings are sorted.
82 for (int i = 0; i < m_index; i++)
83 {
84 if (data[i].index == idx)
85 {
86 return i;
87 }
88 }
89 return -1;
90 }
91
92 bool ConstantsStringList::set_values(const TCHAR *name, int val1, int val2)
93 {
94 int v = SortedStringListND<struct constantstring>::find(name, -1);
95 if (-1 == v) return false;
96
97 struct constantstring & cs = ((struct constantstring*) m_gr.get())[v];
98 cs.value1 = val1;
99 cs.value2 = val2;
100 return true;
101 }