Uwe Hermann | 7eb845e | 2008-11-02 17:01:06 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the bayou project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | #include <getopt.h> |
| 23 | #include "pbuilder.h" |
| 24 | |
| 25 | static void usage(void) |
| 26 | { |
| 27 | printf("./pbuilder [-c config] [create|show] [LAR]\n"); |
| 28 | } |
| 29 | |
| 30 | int main(int argc, char **argv) |
| 31 | { |
| 32 | char *config = NULL; |
| 33 | |
| 34 | while (1) { |
| 35 | signed ch = getopt(argc, argv, "c:"); |
| 36 | if (ch == -1) |
| 37 | break; |
| 38 | |
| 39 | switch (ch) { |
| 40 | case 'c': |
| 41 | config = optarg; |
| 42 | break; |
| 43 | default: |
| 44 | usage(); |
| 45 | return -1; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | if (optind >= argc) { |
| 50 | usage(); |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | if (!strcmp(argv[optind], "create")) { |
| 55 | if (config == NULL) { |
| 56 | warn("E: No config was provided\n"); |
| 57 | usage(); |
| 58 | return -1; |
| 59 | } |
| 60 | |
| 61 | if (optind + 1 >= argc) { |
| 62 | warn("E: No LAR name was given\n"); |
| 63 | usage(); |
| 64 | return -1; |
| 65 | } |
| 66 | |
| 67 | create_lar_from_config((const char *)config, |
| 68 | (const char *)argv[optind + 1]); |
| 69 | } else if (!strcmp(argv[optind], "show")) { |
| 70 | if (optind + 1 >= argc) { |
| 71 | warn("E: No LAR name was given\n"); |
| 72 | usage(); |
| 73 | return -1; |
| 74 | } |
| 75 | pbuilder_show_lar((const char *)argv[optind + 1]); |
| 76 | } else { |
| 77 | usage(); |
| 78 | return -1; |
| 79 | } |
| 80 | |
| 81 | return 0; |
| 82 | } |