~ubuntu-branches/ubuntu/edgy/net-snmp/edgy-updates

« back to all changes in this revision

Viewing changes to agent/mibgroup/host/hr_print.c

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-03-31 04:21:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050331042137-z0vw1grslj6cek9k
Tags: 5.1.2-6ubuntu2
Apply safe-but-hackish patch by Henrique de Moraes Holschuh to
fix the libdir in libsnmp5-dev's .la files (Ubuntu bug #8393)

Show diffs side-by-side

added added

removed removed

Lines of Context:
196
196
 
197
197
static int      HRP_index;
198
198
static char   **HRP_name;
199
 
static int      HRP_names, HRP_maxnames;
 
199
static int      HRP_nbrnames, HRP_maxnames;
 
200
 
 
201
#define HRP_MAX_INCR 10
200
202
 
201
203
void
202
204
Init_HR_Print(void)
212
214
    FILE           *p;
213
215
#endif
214
216
 
 
217
    HRP_index = 0;              /* fail safe at Get_Next_HR_Print */
 
218
 
215
219
    if (HRP_name) {
216
 
        for (i = 0; i < HRP_names; i++)
 
220
        for (i = 0; i < HRP_nbrnames; i++)
217
221
            free(HRP_name[i]);
218
 
        HRP_names = 0;
219
 
    } else {
220
 
        HRP_maxnames = 5;
221
 
        HRP_name = (char **) calloc(HRP_maxnames, sizeof(char *));
222
 
        if (!HRP_name)
223
 
            return;
 
222
        HRP_nbrnames = 0;
 
223
        HRP_maxnames = 0;
 
224
        SNMP_FREE(HRP_name);
224
225
    }
225
226
 
226
227
#if HAVE_PRINTCAP
241
242
#elif HAVE_CGETNEXT
242
243
    {
243
244
        char           *buf = NULL, *ptr;
244
 
        while (cgetnext(&buf, caps)) {
 
245
        while (cgetnext(&buf, caps) > 0) {
245
246
            if ((ptr = strchr(buf, ':')))
246
247
                *ptr = 0;
247
248
            if ((ptr = strchr(buf, '|')))
253
254
        while (fgets(buf, sizeof buf, p)) {
254
255
            sscanf(buf, "%*s %*s %[^:]", ptr);
255
256
#endif
256
 
            if (HRP_names == HRP_maxnames) {
 
257
            if (HRP_nbrnames == HRP_maxnames) {
257
258
                char          **tmp;
258
 
                HRP_maxnames += 5;
259
 
                tmp = (char **) calloc(HRP_maxnames, sizeof(char *));
 
259
                tmp = (char **) calloc(HRP_maxnames + HRP_MAX_INCR, sizeof(char *));
260
260
                if (!tmp)
261
261
                    goto finish;
262
 
                memcpy(tmp, HRP_name, HRP_names * sizeof(char *));
 
262
                if (HRP_name) {
 
263
                        memcpy(tmp, HRP_name, HRP_nbrnames * sizeof(char *));
 
264
                        free(HRP_name);
 
265
                }
 
266
                HRP_maxnames += HRP_MAX_INCR;
263
267
                HRP_name = tmp;
264
268
            }
265
 
            HRP_name[HRP_names++] = strdup(ptr);
266
 
#if HAVE_CGETNEXT
 
269
            HRP_name[HRP_nbrnames++] = strdup(ptr);
 
270
#if !defined(HAVE_PRINTCAP) && defined(HAVE_CGETNEXT)
267
271
            if (buf)
268
272
                free(buf);
269
273
#endif
279
283
#endif
280
284
    }
281
285
#endif                          /* HAVE_anything */
282
 
 
283
 
    HRP_index = 0;
284
286
}
285
287
 
286
288
int
292
294
     *   no real idea how to detect them,
293
295
     *   so don't bother.
294
296
     */
295
 
    if (HRP_index < HRP_names)  /* No printer */
 
297
    if (HRP_index < HRP_nbrnames)  /* No printer */
296
298
        return (HRDEV_PRINTER << HRDEV_TYPE_SHIFT) + HRP_index++;
297
299
    else
298
300
        return -1;
301
303
const char     *
302
304
describe_printer(int idx)
303
305
{
 
306
    if (HRP_index == 0)  /* return empty string if not initialized */
 
307
        return "";
 
308
 
304
309
    DEBUGMSGTL(("host/hr_print", "describe p: %d/%d %s\n", HRP_index, idx,
305
310
                HRP_name[HRP_index - 1]));
306
311
    return HRP_name[HRP_index - 1];