From 9066cfe9886ac131c34d59ed0e2d287b0e3c0087 Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Tue, 3 Mar 2009 19:31:44 -0800 Subject: auto import from //depot/cupcake/@135843 --- tools/aidl/options.cpp | 138 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 tools/aidl/options.cpp (limited to 'tools/aidl/options.cpp') diff --git a/tools/aidl/options.cpp b/tools/aidl/options.cpp new file mode 100644 index 0000000..57b10ae --- /dev/null +++ b/tools/aidl/options.cpp @@ -0,0 +1,138 @@ + +#include "options.h" + +#include +#include +#include + +static int +usage() +{ + fprintf(stderr, + "usage: aidl OPTIONS INPUT [OUTPUT]\n" + " aidl --preprocess OUTPUT INPUT...\n" + "\n" + "OPTIONS:\n" + " -I search path for import statements.\n" + " -d generate dependency file.\n" + " -p file created by --preprocess to import.\n" + " -b fail when trying to compile a parcelable.\n" + "\n" + "INPUT:\n" + " An aidl interface file.\n" + "\n" + "OUTPUT:\n" + " The generated interface files. If omitted, the input filename is used, with the .aidl extension changed to a .java extension.\n" + ); + return 1; +} + +int +parse_options(int argc, const char* const* argv, Options *options) +{ + int i = 1; + + if (argc >= 2 && 0 == strcmp(argv[1], "--preprocess")) { + if (argc < 4) { + return usage(); + } + options->outputFileName = argv[2]; + for (int i=3; ifilesToPreprocess.push_back(argv[i]); + } + options->task = PREPROCESS_AIDL; + return 0; + } + + options->task = COMPILE_AIDL; + options->failOnParcelable = false; + + // OPTIONS + while (i < argc) { + const char* s = argv[i]; + int len = strlen(s); + if (s[0] == '-') { + if (len > 1) { + // -I + if (s[1] == 'I') { + if (len > 2) { + options->importPaths.push_back(s+2); + } else { + fprintf(stderr, "-I option (%d) requires a path.\n", i); + return usage(); + } + } + else if (s[1] == 'd') { + if (len > 2) { + options->depFileName = s+2; + } else { + fprintf(stderr, "-d option (%d) requires a file.\n", i); + return usage(); + } + } + else if (s[1] == 'p') { + if (len > 2) { + options->preprocessedFiles.push_back(s+2); + } else { + fprintf(stderr, "-p option (%d) requires a file.\n", i); + return usage(); + } + } + else if (len == 2 && s[1] == 'b') { + options->failOnParcelable = true; + } + else { + // s[1] is not known + fprintf(stderr, "unknown option (%d): %s\n", i, s); + return usage(); + } + } else { + // len <= 1 + fprintf(stderr, "unknown option (%d): %s\n", i, s); + return usage(); + } + } else { + // s[0] != '-' + break; + } + i++; + } + + // INPUT + if (i < argc) { + options->inputFileName = argv[i]; + i++; + } else { + fprintf(stderr, "INPUT required\n"); + return usage(); + } + + // OUTPUT + if (i < argc) { + options->outputFileName = argv[i]; + i++; + } else { + // copy input into output and change the extension from .aidl to .java + options->outputFileName = options->inputFileName; + string::size_type pos = options->outputFileName.size()-5; + if (options->outputFileName.compare(pos, 5, ".aidl") == 0) { // 5 = strlen(".aidl") + options->outputFileName.replace(pos, 5, ".java"); // 5 = strlen(".aidl") + } else { + fprintf(stderr, "INPUT is not an .aidl file.\n"); + return usage(); + } + } + + // anything remaining? + if (i != argc) { + fprintf(stderr, "unknown option%s:", (i==argc-1?(const char*)"":(const char*)"s")); + for (; i