|
|
@ -0,0 +1,139 @@ |
|
|
|
/* |
|
|
|
* adfgvx |
|
|
|
* (C) 2008 Damien Goutte-Gattat <damien.goutte-gattat@e.ujf-grenoble.fr> |
|
|
|
* |
|
|
|
* This program is free software; you can redistribute it and/or modify it |
|
|
|
* under the terms of the GNU General Public License as published by the Free |
|
|
|
* Software Foundation; either version 2 of the License, or (at your option) |
|
|
|
* any later version. |
|
|
|
* |
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|
|
|
* more details. |
|
|
|
* |
|
|
|
* You should have received a copy of the GNU General Public License along |
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc., |
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
|
|
* |
|
|
|
*/ |
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H |
|
|
|
#include <config.h> |
|
|
|
#endif |
|
|
|
|
|
|
|
#define _GNU_SOURCE |
|
|
|
#include <stdio.h> |
|
|
|
#include <getopt.h> |
|
|
|
#include <locale.h> |
|
|
|
#include <errno.h> |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* Help and informations about the program |
|
|
|
*/ |
|
|
|
|
|
|
|
static void |
|
|
|
usage(int status) |
|
|
|
{ |
|
|
|
printf(_("\ |
|
|
|
Usage: %s [options] [FILE]\n\ |
|
|
|
\n\ |
|
|
|
"), program_invocation_name); |
|
|
|
|
|
|
|
puts(_("Options:\n\ |
|
|
|
-h, --help Display this help message.\n\ |
|
|
|
-v, --version Display the version message.\n\ |
|
|
|
")); |
|
|
|
|
|
|
|
puts(_("\ |
|
|
|
-d, --decrypt Decrypt the given file (default action).\n\ |
|
|
|
-e, --encrypt Encrypt the given file.\n\ |
|
|
|
-k, --key FILE Use the key in the specified file.\n\ |
|
|
|
-o, --output FILE Send output to FILE instead of stdout.\n\ |
|
|
|
")); |
|
|
|
|
|
|
|
exit(status); |
|
|
|
} |
|
|
|
|
|
|
|
static void |
|
|
|
info(void) |
|
|
|
{ |
|
|
|
printf(_("\ |
|
|
|
%s - v%s\n\ |
|
|
|
(C) 2008 Damien Goutte-Gattat <damien.goutte-gattat@e.ujf-grenoble.fr>\n\ |
|
|
|
\n\ |
|
|
|
This program is released under the GNU General Public License.\n\ |
|
|
|
"), program_invocation_name, VERSION); |
|
|
|
|
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* Main function |
|
|
|
*/ |
|
|
|
|
|
|
|
int |
|
|
|
main(int argc, char *const argv[]) |
|
|
|
{ |
|
|
|
char c; |
|
|
|
|
|
|
|
struct option options[] = { |
|
|
|
{ "help", 0, NULL, 'h' }, |
|
|
|
{ "version", 0, NULL, 'v' }, |
|
|
|
{ "decrypt", 0, NULL, 'd' }, |
|
|
|
{ "encrypt", 0, NULL, 'e' }, |
|
|
|
{ "key", 1, NULL, 'k' }, |
|
|
|
{ "output", 1, NULL, 'o' }, |
|
|
|
{ NULL, 0, NULL, 0 } |
|
|
|
}; |
|
|
|
|
|
|
|
setlocale(LC_ALL, ""); |
|
|
|
#ifdef ENABLE_NLS |
|
|
|
bindtextdomain(PACKAGE, LOCALEDIR); |
|
|
|
textdomain(PACKAGE); |
|
|
|
#endif |
|
|
|
|
|
|
|
program_invocation_name = argv[0]; |
|
|
|
|
|
|
|
while ( (c = getopt_long(argc, argv, "hvdek:o:", |
|
|
|
options, NULL)) != -1 ) { |
|
|
|
switch ( c ) { |
|
|
|
case 'h': |
|
|
|
usage(EXIT_SUCCESS); |
|
|
|
break; |
|
|
|
|
|
|
|
case '?': |
|
|
|
usage(EXIT_FAILURE); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'v': |
|
|
|
info(); |
|
|
|
break; |
|
|
|
|
|
|
|
case 'd': |
|
|
|
/* decrypt */ |
|
|
|
break; |
|
|
|
|
|
|
|
case 'e': |
|
|
|
/* encrypt */ |
|
|
|
break; |
|
|
|
|
|
|
|
case 'k': |
|
|
|
/* load key */ |
|
|
|
break; |
|
|
|
|
|
|
|
case 'o': |
|
|
|
if ( freopen(optarg, "w", stdout) == NULL ) { |
|
|
|
error(_("cannot open file %s: %s\n"), optarg, |
|
|
|
strerror(errno)); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
exit(EXIT_SUCCESS); |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |