00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 # include "lclintMacros.nf"
00033 # include "basic.h"
00034
00035 cstringSList
00036 cstringSList_new ()
00037 {
00038 return cstringSList_undefined;
00039 }
00040
00041 static cstringSList
00042 cstringSList_newEmpty (void)
00043 {
00044 cstringSList s = (cstringSList) dmalloc (sizeof (*s));
00045
00046 s->nelements = 0;
00047 s->nspace = cstringSListBASESIZE;
00048 s->elements = (cstring *) dmalloc (sizeof (*s->elements) * cstringSListBASESIZE);
00049
00050 return (s);
00051 }
00052
00053 static void
00054 cstringSList_grow ( cstringSList s)
00055 {
00056 int i;
00057 cstring *newelements;
00058
00059 s->nspace += cstringSListBASESIZE;
00060
00061 newelements = (cstring *) dmalloc (sizeof (*newelements)
00062 * (s->nelements + s->nspace));
00063
00064
00065 if (newelements == (cstring *) 0)
00066 {
00067 llfatalerror (cstring_makeLiteral ("cstringSList_grow: out of memory!"));
00068 }
00069
00070 for (i = 0; i < s->nelements; i++)
00071 {
00072 newelements[i] = s->elements[i];
00073 }
00074
00075 sfree (s->elements);
00076 s->elements = newelements;
00077 }
00078
00079 cstringSList cstringSList_single ( cstring el)
00080 {
00081 cstringSList s = cstringSList_new ();
00082 s = cstringSList_add (s, el);
00083 return s;
00084 }
00085
00086 cstringSList cstringSList_add (cstringSList s, cstring el)
00087 {
00088 if (!cstringSList_isDefined (s))
00089 {
00090 s = cstringSList_newEmpty ();
00091 }
00092
00093 if (s->nspace <= 0)
00094 {
00095 cstringSList_grow (s);
00096 }
00097
00098 s->nspace--;
00099 s->elements[s->nelements] = el;
00100 s->nelements++;
00101
00102 return s;
00103 }
00104
00105 cstring
00106 cstringSList_unparse (cstringSList s)
00107 {
00108 return cstringSList_unparseSep (s, cstring_makeLiteralTemp (", "));
00109 }
00110
00111 cstring
00112 cstringSList_unparseSep (cstringSList s, cstring sep)
00113 {
00114 cstring st = cstring_undefined;
00115
00116 if (cstringSList_isDefined (s))
00117 {
00118 int i;
00119
00120 for (i = 0; i < s->nelements; i++)
00121 {
00122 if (i == 0)
00123 {
00124 st = cstring_copy (s->elements[i]);
00125 }
00126 else
00127 st = message ("%q%s%s", st, sep, s->elements[i]);
00128 }
00129 }
00130
00131 return st;
00132 }
00133
00134 void
00135 cstringSList_printSpaced (cstringSList s, int indent, int gap, int linelen)
00136 {
00137 if (cstringSList_isDefined (s))
00138 {
00139 cstring line = cstring_undefined;
00140 cstring istring = cstring_fill (cstring_undefined, indent);
00141 cstring gstring = cstring_fill (cstring_undefined, gap);
00142 int numcol;
00143 int longest = 0;
00144 int i;
00145
00146
00147
00148
00149
00150 for (i = 0; i < s->nelements; i++)
00151 {
00152 int len = cstring_length (s->elements[i]);
00153
00154 if (len > longest)
00155 {
00156 longest = len;
00157 }
00158 }
00159
00160 numcol = (linelen - indent) / (longest + gap);
00161
00162 if (numcol <= 1)
00163 {
00164 numcol = 1;
00165 }
00166
00167 for (i = 0; i < s->nelements; i++)
00168 {
00169 if (i % numcol == 0)
00170 {
00171 if (i != 0)
00172 {
00173 llmsg (line);
00174 }
00175
00176 line = message ("%s%q", istring,
00177 cstring_fill (s->elements[i], longest));
00178 }
00179 else
00180 {
00181 line = message ("%q%s%q", line, gstring,
00182 cstring_fill (s->elements[i], longest));
00183 }
00184 }
00185
00186 cstring_free (line);
00187 cstring_free (istring);
00188 cstring_free (gstring);
00189 }
00190 }
00191
00192 cstring
00193 cstringSList_unparseAbbrev (cstringSList s)
00194 {
00195 cstring st = cstring_undefined;
00196
00197 if (cstringSList_isDefined (s))
00198 {
00199 int i;
00200
00201 for (i = 0; i < s->nelements; i++)
00202 {
00203 if (i == 0)
00204 {
00205 st = cstring_copy (s->elements[i]);
00206 }
00207 else if (i > 3 && s->nelements > 5)
00208 {
00209 st = message ("%q, ...", st);
00210 break;
00211 }
00212 else
00213 {
00214 st = message ("%q, %s", st, s->elements[i]);
00215 }
00216 }
00217 }
00218
00219 return st;
00220 }
00221
00222 void
00223 cstringSList_free (cstringSList s)
00224 {
00225 if (cstringSList_isDefined (s))
00226 {
00227
00228
00229
00230
00231
00232
00233
00234 sfree (s->elements);
00235
00236
00237 sfree (s);
00238 }
00239 }
00240
00241 void
00242 cstringSList_alphabetize (cstringSList s)
00243 {
00244 if (cstringSList_isDefined (s))
00245 {
00246
00247 qsort (s->elements, (size_t) s->nelements,
00248 sizeof (*s->elements), (int (*)(const void *, const void *)) cstring_xcompare);
00249
00250 }
00251 }
00252