Add.
[shishi.git] / src / ccache2shishi.c
blob33f6e795c93f672202ea12e1e89e0c2ca7226fd5
1 /* ccache2shishi.c --- Print and convert MIT ccache files.
2 * Copyright (C) 2006 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Shishi; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 #if HAVE_CONFIG_H
23 # include "config.h"
24 #endif
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <ctype.h>
30 #include <string.h>
31 #include <errno.h>
33 /* For getuid. */
34 #include <sys/types.h>
35 #include <unistd.h>
37 /* Get i18n. */
38 #ifdef HAVE_LOCALE_H
39 # include <locale.h>
40 #else
41 # define setlocale(Category, Locale) /* empty */
42 #endif
43 #include <gettext.h>
44 #define _(String) gettext (String)
45 #define gettext_noop(String) String
46 #define N_(String) gettext_noop (String)
48 #include <shishi.h>
50 /* Get set_program_name and program_name. */
51 #include "progname.h"
53 /* Get error. */
54 #include "error.h"
56 #include "ccache2shishi_cmd.h"
58 int
59 main (int argc, char *argv[])
61 struct gengetopt_args_info args;
62 Shishi *sh;
63 char *infile = NULL;
64 char *outfile = NULL;
65 int rc;
67 setlocale (LC_ALL, "");
68 bindtextdomain (PACKAGE, LOCALEDIR);
69 textdomain (PACKAGE);
70 set_program_name (argv[0]);
72 if (cmdline_parser (argc, argv, &args) != 0)
73 error (EXIT_FAILURE, 0, _("Try `%s --help' for more information."),
74 program_name);
76 if (args.inputs_num > 0)
77 infile = args.inputs[0];
79 if (args.inputs_num > 1)
80 outfile = args.inputs[1];
82 if (args.inputs_num > 2)
84 error (0, 0, _("too many arguments"));
85 error (EXIT_FAILURE, 0, _("Try `%s --help' for more information."),
86 program_name);
89 if (args.help_given)
91 cmdline_parser_print_help ();
92 printf (_("\nMandatory arguments to long options are "
93 "mandatory for short options too.\n\nReport bugs to <%s>.\n"),
94 PACKAGE_BUGREPORT);
95 return EXIT_SUCCESS;
98 sh = shishi ();
99 if (!sh)
100 error (EXIT_FAILURE, 0, _("Could not initialize libshishi."));
102 if (args.verbose_given > 0)
103 shishi_cfg (sh, "verbose");
104 if (args.verbose_given > 1)
105 shishi_cfg (sh, "verbose-noise");
106 if (args.verbose_given > 2)
107 shishi_cfg (sh, "verbose-asn1");
108 if (args.verbose_given > 3)
109 shishi_cfg (sh, "verbose-crypto");
110 if (args.verbose_given > 4)
111 shishi_cfg (sh, "verbose-crypto-noise");
113 if (!infile)
114 infile = shishi_tkts_default_ccache (sh);
116 if (!outfile)
117 outfile = shishi_tkts_default_file (sh);
120 Shishi_tkts *tkts;
122 rc = shishi_tkts_from_ccache_file (sh, infile, &tkts);
123 if (rc != SHISHI_OK)
124 error (EXIT_FAILURE, errno, "%s: %s", infile, shishi_strerror (rc));
126 if (args.verbose_given)
127 shishi_tkts_print (tkts, stdout);
129 rc = shishi_tkts_to_file (tkts, outfile);
130 if (rc != SHISHI_OK)
131 error (EXIT_FAILURE, errno, "%s:%s", outfile, shishi_strerror (rc));
133 if (!args.quiet_flag)
135 size_t ntkts = shishi_tkts_size (tkts);
136 if (ntkts == 0)
137 printf (_("No tickets written.\n"));
138 else
139 printf (ngettext ("%d ticket written.\n",
140 "%d tickets written.\n", ntkts), ntkts);
143 shishi_tkts_done (&tkts);
146 shishi_done (sh);
148 return EXIT_SUCCESS;