/* * lsbd - mklsbd.c * Copyright (C) 2010 Krzysztof Mazur * * 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 Fundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include #include #include #include #include #include static char *device = NULL; static void show_info(void) { fprintf(stderr, "mklsbd "PACKAGE_VERSION"\n" "Copyright (C) 2010 " "Krzysztof Mazur \n\n"); } static void show_usage(char *name) { show_info(); fprintf(stderr, "usage: %s [options] (file)\n" "Options:\n" " -c, --compat Linux MiniDEBUG compatibility " "mode\n" " -i, --io set io access method\n" " -h, --help show this help\n" " --noreadline don't use readline\n" " --readline use readline\n" " -q, --quiet quiet mode\n" " -V, --version show version\n", (name == NULL) ? "mklsbd" : name); exit(0); } static void parse_command_line(int argc, char **args) { int c; int option_index = 0; static struct option long_options[] = { {"help", 0, 0, 'h'}, {"version", 0, 0, 'V'}, {0, 0, 0, 0}, }; while (1) { c = getopt_long(argc, args, "hV", long_options, &option_index); if (c == -1) break; switch (c) { case 'h': show_usage(args[0]); break; case 'V': exit(0); break; default: fprintf(stderr, "Unknown option.\n"); exit(1); } } if (optind < argc) { device = args[optind++]; if (optind < argc) fprintf(stderr, "warning: unknown parameters detected." "\n"); } } int main(int argc, char **argv) { struct lsbd *p; int ret; parse_command_line(argc, argv); if (device == NULL) { fprintf(stderr, "error: device option is required\n"); exit(EXIT_FAILURE); } p = lsbd_alloc(); ret = lsbd_open(p, device, LSBD_FORMAT); if (ret) { perror("lsbd_open"); exit(EXIT_FAILURE); } return 0; }