Path: blob/main/crypto/krb5/src/tests/asn.1/t_trval.c
34890 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright (C) 1992,1993 Trusted Information Systems, Inc.3*4* Permission to include this software in the Kerberos V5 distribution5* was graciously provided by Trusted Information Systems.6*7* Trusted Information Systems makes no representation about the8* suitability of this software for any purpose. It is provided9* "as is" without express or implied warranty.10*11* Copyright (C) 1994 Massachusetts Institute of Technology12*13* Export of this software from the United States of America may14* require a specific license from the United States Government.15* It is the responsibility of any person or organization contemplating16* export to obtain such a license before exporting.17*18* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and19* distribute this software and its documentation for any purpose and20* without fee is hereby granted, provided that the above copyright21* notice appear in all copies and that both that copyright notice and22* this permission notice appear in supporting documentation, and that23* the name of M.I.T. not be used in advertising or publicity pertaining24* to distribution of the software without specific, written prior25* permission. Furthermore if you modify this software you must label26* your software as modified software and not distribute it in such a27* fashion that it might be confused with the original M.I.T. software.28* M.I.T. makes no representations about the suitability of29* this software for any purpose. It is provided "as is" without express30* or implied warranty.31*/3233/* Split out from "#ifdef STANDALONE" code previously in trval.c, so34that trval.o could be linked into other tests too without the35-DSTANDALONE code. */36#include "trval.c"3738static void39usage(void)40{41fprintf(stderr, "Usage: trval [--types] [--krb5] [--krb5decode] [--hex] [-notypebytes] [file]\n");42exit(1);43}4445/*46* Returns true if the option was selected. Allow "-option" and47* "--option" syntax, since we used to accept only "-option"48*/49static int50check_option(char *word, char *option)51{52if (word[0] != '-')53return 0;54if (word[1] == '-')55word++;56if (strcmp(word+1, option))57return 0;58return 1;59}6061int62main(int argc, char **argv)63{64int optflg = 1;65FILE *fp;66int r = 0;6768while (--argc > 0) {69argv++;70if (optflg && *(argv)[0] == '-') {71if (check_option(*argv, "help"))72usage();73else if (check_option(*argv, "types"))74print_types = 1;75else if (check_option(*argv, "notypes"))76print_types = 0;77else if (check_option(*argv, "krb5"))78print_krb5_types = 1;79else if (check_option(*argv, "hex"))80do_hex = 1;81else if (check_option(*argv, "notypebytes"))82print_id_and_len = 0;83else if (check_option(*argv, "krb5decode")) {84print_id_and_len = 0;85print_krb5_types = 1;86print_types = 1;87} else {88fprintf(stderr,"trval: unknown option: %s\n", *argv);89usage();90}91} else {92optflg = 0;93if ((fp = fopen(*argv,"r")) == NULL) {94fprintf(stderr,"trval: unable to open %s\n", *argv);95continue;96}97r = trval(fp, stdout);98fclose(fp);99}100}101if (optflg) r = trval(stdin, stdout);102103exit(r);104}105106107