/* Copyright 2006 Paul Querna. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "proton.h" #include "pwt_version.h" #include #include #ifndef PWT_ROOT_ENV #define PWT_ROOT_ENV "PROTON_ROOT" #endif static void show_usage() { fprintf(stderr, "usage: proton [--version] [-R /path/to/root]\n"); fprintf(stderr, "\n"); fprintf(stderr, "Enviromental Variables:\n"); fprintf(stderr, " " PWT_ROOT_ENV " - Alternative to -R argument.\n"); exit(1); } static void show_version() { fprintf(stdout, "proton " PWT_VERSION_STRING "\n"); exit(0); } static void show_error(pwt_error_t* err) { char buf[128]; fprintf(stderr, "\n*** [%s:%d] err: %s: (%d) %s\n\n", err->file, err->line, err->msg, err->err, apr_strerror(err->err, buf, sizeof(buf))); pwt_error_destroy(err); exit(1); } static int run_pwt(const char* root) { pwt_ctxt_t *pwt; pwt_error_t *err; pwt_init(&pwt); pwt_root_set(pwt, root); err = pwt_startup(pwt); if (err) { show_error(err); } pwt_execute(pwt); pwt_cgi_write_header(pwt); pwt_cgi_write_body(pwt); pwt_destroy(&pwt); return 0; } int main(int argc, const char * const argv[]) { const char* root = NULL; int i; for (i = 1; i < argc; i++) { if (strcmp("--version", argv[i]) == 0) { show_version(); } else if (strcmp("-R", argv[i]) == 0 && i+1 < argc) { root = argv[++i]; } else { show_usage(); } } if (!root) { root = getenv(PWT_ROOT_ENV); if (!root) { fprintf(stderr, "err: Proton Root not defined.\n\n"); show_usage(); } } return run_pwt(root); }