1 #include "esl_config.h"
2
3 #include <stdlib.h>
4 #include <string.h>
5
6 #include "easel.h"
7
8 /* Function: esl_arr3_SSizeof()
9 * Synopsis: Returns size of 3D array of \0-terminated strings, in bytes
10 * Incept: SRE, Fri Nov 3 15:19:53 2017
11 */
12 size_t
esl_arr3_SSizeof(char *** s,int dim1,int dim2)13 esl_arr3_SSizeof(char ***s, int dim1, int dim2)
14 {
15 size_t n = 0;
16 int i,j;
17
18 if (s)
19 {
20 n += sizeof(char **) * dim1;
21 for (i = 0; i < dim1; i++)
22 if (s[i])
23 {
24 n += sizeof(char *) * dim2;
25 for (j = 0; j < dim2; j++)
26 {
27 if (s[i][j])
28 n += sizeof(char) * (1 + strlen(s[i][j]));
29 }
30 }
31 }
32 return n;
33 }
34
35
36
37 /* Function: esl_arr3_Destroy()
38 * Synopsis: Free a 3D array.
39 * Incept: SRE, Fri Nov 3 15:38:39 2017
40 *
41 * Purpose: Free a 3D pointer array <p>, where first and second
42 * dimensions are <dim1>,<dim2>. (That is, the array is
43 * <p[0..dim1-1][0..dim2-1][]>.) Tolerates any of the
44 * pointers being NULL, to allow sparse arrays.
45 *
46 * Returns: (void)
47 *
48 * Throws: (no abnormal error conditions)
49 *
50 * Xref: Was <esl_Free3D()>.
51 */
52 void
esl_arr3_Destroy(void *** p,int dim1,int dim2)53 esl_arr3_Destroy(void ***p, int dim1, int dim2)
54 {
55 int i, j;
56
57 if (p)
58 {
59 for (i = 0; i < dim1; i++)
60 if (p[i])
61 {
62 for (j = 0; j < dim2; j++)
63 if (p[i][j])
64 free(p[i][j]);
65 free(p[i]);
66 }
67 free(p);
68 }
69 }
70