1*55060911SKatayama Hirofumi MZ /*
2*55060911SKatayama Hirofumi MZ * PROJECT: ReactOS WHERE command
3*55060911SKatayama Hirofumi MZ * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4*55060911SKatayama Hirofumi MZ * PURPOSE: Providing string list
5*55060911SKatayama Hirofumi MZ * COPYRIGHT: Copyright 2021 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6*55060911SKatayama Hirofumi MZ */
7*55060911SKatayama Hirofumi MZ
8*55060911SKatayama Hirofumi MZ #pragma once
9*55060911SKatayama Hirofumi MZ
10*55060911SKatayama Hirofumi MZ #define str_clone _wcsdup
11*55060911SKatayama Hirofumi MZ
12*55060911SKatayama Hirofumi MZ typedef struct strlist_t
13*55060911SKatayama Hirofumi MZ {
14*55060911SKatayama Hirofumi MZ LPWSTR *ppsz;
15*55060911SKatayama Hirofumi MZ unsigned int count;
16*55060911SKatayama Hirofumi MZ } strlist_t;
17*55060911SKatayama Hirofumi MZ #define strlist_default { NULL, 0 }
18*55060911SKatayama Hirofumi MZ
strlist_init(strlist_t * plist)19*55060911SKatayama Hirofumi MZ static inline void strlist_init(strlist_t *plist)
20*55060911SKatayama Hirofumi MZ {
21*55060911SKatayama Hirofumi MZ plist->ppsz = NULL;
22*55060911SKatayama Hirofumi MZ plist->count = 0;
23*55060911SKatayama Hirofumi MZ }
24*55060911SKatayama Hirofumi MZ
strlist_get_at(strlist_t * plist,unsigned int i)25*55060911SKatayama Hirofumi MZ static inline LPWSTR strlist_get_at(strlist_t *plist, unsigned int i)
26*55060911SKatayama Hirofumi MZ {
27*55060911SKatayama Hirofumi MZ return plist->ppsz[i];
28*55060911SKatayama Hirofumi MZ }
29*55060911SKatayama Hirofumi MZ
strlist_add(strlist_t * plist,LPCWSTR psz)30*55060911SKatayama Hirofumi MZ static int strlist_add(strlist_t *plist, LPCWSTR psz)
31*55060911SKatayama Hirofumi MZ {
32*55060911SKatayama Hirofumi MZ LPWSTR *ppsz, clone = str_clone(psz);
33*55060911SKatayama Hirofumi MZ if (!clone)
34*55060911SKatayama Hirofumi MZ return 0;
35*55060911SKatayama Hirofumi MZ ppsz = (LPWSTR *)realloc(plist->ppsz, (plist->count + 1) * sizeof(LPWSTR));
36*55060911SKatayama Hirofumi MZ if (!ppsz)
37*55060911SKatayama Hirofumi MZ {
38*55060911SKatayama Hirofumi MZ free(clone);
39*55060911SKatayama Hirofumi MZ return 0;
40*55060911SKatayama Hirofumi MZ }
41*55060911SKatayama Hirofumi MZ plist->ppsz = ppsz;
42*55060911SKatayama Hirofumi MZ plist->ppsz[plist->count] = clone;
43*55060911SKatayama Hirofumi MZ ++(plist->count);
44*55060911SKatayama Hirofumi MZ return 1;
45*55060911SKatayama Hirofumi MZ }
46*55060911SKatayama Hirofumi MZ
strlist_destroy(strlist_t * plist)47*55060911SKatayama Hirofumi MZ static void strlist_destroy(strlist_t *plist)
48*55060911SKatayama Hirofumi MZ {
49*55060911SKatayama Hirofumi MZ unsigned int i;
50*55060911SKatayama Hirofumi MZ for (i = 0; i < plist->count; ++i)
51*55060911SKatayama Hirofumi MZ free(plist->ppsz[i]);
52*55060911SKatayama Hirofumi MZ plist->count = 0;
53*55060911SKatayama Hirofumi MZ free(plist->ppsz);
54*55060911SKatayama Hirofumi MZ plist->ppsz = NULL;
55*55060911SKatayama Hirofumi MZ }
56*55060911SKatayama Hirofumi MZ
strlist_find_i(strlist_t * plist,LPCWSTR psz)57*55060911SKatayama Hirofumi MZ static inline int strlist_find_i(strlist_t *plist, LPCWSTR psz)
58*55060911SKatayama Hirofumi MZ {
59*55060911SKatayama Hirofumi MZ unsigned int i;
60*55060911SKatayama Hirofumi MZ for (i = 0; i < plist->count; ++i)
61*55060911SKatayama Hirofumi MZ {
62*55060911SKatayama Hirofumi MZ if (_wcsicmp(plist->ppsz[i], psz) == 0)
63*55060911SKatayama Hirofumi MZ return i;
64*55060911SKatayama Hirofumi MZ }
65*55060911SKatayama Hirofumi MZ return -1;
66*55060911SKatayama Hirofumi MZ }
67