Path: blob/main/crypto/krb5/src/kadmin/dbutil/t_tdumputil.c
34907 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/* kdc/t_tdumputil.c - test tdumputil.c functions */2/*3* Copyright (C) 2015 by the Massachusetts Institute of Technology.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12*13* * Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in15* the documentation and/or other materials provided with the16* distribution.17*18* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS19* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT20* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS21* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE22* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,23* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES24* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR25* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)26* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,27* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)28* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED29* OF THE POSSIBILITY OF SUCH DAMAGE.30*/3132#include <stdio.h>33#include <stdlib.h>34#include <unistd.h>3536#include "tdumputil.h"3738static char *argv0;3940static void41usage(void)42{43fprintf(stderr,44"usage: %s: [-T rectype] [-c] nfields {fieldnames} {fields}\n",45argv0);46exit(1);47}4849int50main(int argc, char **argv)51{52int ch, csv = 0, i, nf;53char **a, *rectype = NULL;54struct rechandle *h;5556argv0 = argv[0];57while ((ch = getopt(argc, argv, "T:c")) != -1) {58switch (ch) {59case 'T':60rectype = optarg;61break;62case 'c':63csv = 1;64break;65default:66usage();67break;68}69}70argc -= optind;71argv += optind;7273if (csv)74h = rechandle_csv(stdout, rectype);75else76h = rechandle_tabsep(stdout, rectype);77if (h == NULL)78exit(1);7980if (*argv == NULL)81usage();82nf = atoi(*argv);83argc--;84argv++;85a = calloc(nf + 1, sizeof(*a));86if (a == NULL)87exit(1);8889for (i = 0; argv[i] != NULL && i < nf; i++)90a[i] = argv[i];91if (i != nf)92usage();93argv += nf;94a[nf] = NULL;9596if (rectype == NULL && writeheader(h, a) < 0)97exit(1);98free(a);99100while (*argv != NULL) {101if (startrec(h) < 0)102exit(1);103for (i = 0; argv[i] != NULL && i < nf; i++) {104if (writefield(h, "%s", argv[i]) < 0)105exit(1);106}107if (i != nf)108usage();109argv += nf;110if (endrec(h) < 0)111exit(1);112}113exit(0);114}115116117