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. |
Uwe Hermann | 7eb845e | 2008-11-02 17:01:06 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <stdio.h> |
| 17 | #include <string.h> |
| 18 | #include <getopt.h> |
| 19 | #include "pbuilder.h" |
| 20 | |
| 21 | static void usage(void) |
| 22 | { |
| 23 | printf("./pbuilder [-c config] [create|show] [LAR]\n"); |
| 24 | } |
| 25 | |
| 26 | int main(int argc, char **argv) |
| 27 | { |
| 28 | char *config = NULL; |
| 29 | |
| 30 | while (1) { |
| 31 | signed ch = getopt(argc, argv, "c:"); |
| 32 | if (ch == -1) |
| 33 | break; |
| 34 | |
| 35 | switch (ch) { |
| 36 | case 'c': |
| 37 | config = optarg; |
| 38 | break; |
| 39 | default: |
| 40 | usage(); |
| 41 | return -1; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | if (optind >= argc) { |
| 46 | usage(); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | if (!strcmp(argv[optind], "create")) { |
| 51 | if (config == NULL) { |
| 52 | warn("E: No config was provided\n"); |
| 53 | usage(); |
| 54 | return -1; |
| 55 | } |
| 56 | |
| 57 | if (optind + 1 >= argc) { |
| 58 | warn("E: No LAR name was given\n"); |
| 59 | usage(); |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | create_lar_from_config((const char *)config, |
| 64 | (const char *)argv[optind + 1]); |
| 65 | } else if (!strcmp(argv[optind], "show")) { |
| 66 | if (optind + 1 >= argc) { |
| 67 | warn("E: No LAR name was given\n"); |
| 68 | usage(); |
| 69 | return -1; |
| 70 | } |
| 71 | pbuilder_show_lar((const char *)argv[optind + 1]); |
| 72 | } else { |
| 73 | usage(); |
| 74 | return -1; |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |