/*---------------------------------------------------------------------------- File name : conicap.c Author : Y. Jung Created on : June 2001 Description : CONICA recipe launcher ---------------------------------------------------------------------------*/ /* $Id: conicap.c,v 1.13 2002/01/29 00:32:27 yjung Exp $ $Author: yjung $ $Date: 2002/01/29 00:32:27 $ $Revision: 1.13 $ */ /*---------------------------------------------------------------------------- Includes ---------------------------------------------------------------------------*/ #include #include #include #include /* Get eclipse functionalities */ #include "eclipse.h" /* Get command-line handling routines */ #include "cmdline.h" /* Get recipe definitions */ #include "recipes.h" /* Get man page for this executable */ #include "conicap_man.h" /* A CONICA engine has a fixed prototype */ typedef int (*engine)(void*); /* Registration table: associate strings to recipes */ struct { const char * name ; /* Recipe name */ const char * desc ; /* One-liner description */ const char * version ; /* Recipe version */ const char * date ; /* Recipe modification date */ engine func ; /* Main recipe function */ cmdline_spec * cmd ; /* Command-line specs */ const char * man_page ; /* Complete man page */ } engine_table[] = { { "correltest", "Correlation test recipe", conica_correltest_version, conica_correltest_date, conica_correltest_main, conica_correltest_cmd, conica_correltest_man }, { "dark", "Dark recipe", conica_dark_version, conica_dark_date, conica_dark_main, conica_dark_cmd, conica_dark_man }, { "detlin", "Detector linearity", conica_detlin_version, conica_detlin_date, conica_detlin_main, conica_detlin_cmd, conica_detlin_man }, { "jitter", "Jitter imaging", conica_jitter_version, conica_jitter_date, conica_jitter_main, conica_jitter_cmd, conica_jitter_man }, { "pstest", "Point source test recipe", conica_pstest_version, conica_pstest_date, conica_pstest_main, conica_pstest_cmd, conica_pstest_man }, { "refpixel", "Reference pixel recipe", conica_refpixel_version, conica_refpixel_date, conica_refpixel_main, conica_refpixel_cmd, conica_refpixel_man }, { "strehl", "Strehl ratio computation", conica_strehl_version, conica_strehl_date, conica_strehl_main, conica_strehl_cmd, conica_strehl_man }, { "twflat", "Twilight flat-field processing", conica_twflat_version, conica_twflat_date, conica_twflat_main, conica_twflat_cmd, conica_twflat_man }, { "zpoint", "Zero point recipe", conica_zpoint_version, conica_zpoint_date, conica_zpoint_main, conica_zpoint_cmd, conica_zpoint_man }, /* The following NULL definition ensures end of iteration */ {NULL, NULL, NULL, NULL, NULL, NULL, NULL} } ; /* * Usage for this program */ static void usage(void) { int i ; hello_world("conicap", "CONICA pipeline"); printf( "------------------------------------------------------------------------\n" "\n" "use: conicap man [recipe] get a recipe documentation\n" "use: conicap version [recipe] get a recipe version number\n" "use: conicap recipe in [parameters] launch a recipe\n" "\n" "Registered recipes are:\n" "------------------------------------------------------------------------\n"); i=0 ; while (engine_table[i].name!=NULL) { printf("%15s -- %s\n", engine_table[i].name, engine_table[i].desc); i++ ; } printf( "------------------------------------------------------------------------\n"); return ; } /* * Help system for all recipes */ static void help(char * what) { int i ; int found ; i=0 ; found=0 ; while (engine_table[i].name!=NULL) { if (!strcmp(what, engine_table[i].name)) { printf( "------------------------------------------------------------------------\n" " Parameters for %s version %s\n" "------------------------------------------------------------------------\n" "\n", engine_table[i].name, rcs_value((char*)engine_table[i].version)); if (engine_table[i].cmd==NULL) { printf("No parameter for this command\n"); } else { cmdline_dump(engine_table[i].cmd); } printf("\n\n"); found++ ; break ; } i++ ; } if (!found) { e_error("cannot find anything about [%s]", what); } return ; } /* * Versioning for all recipes */ static void version(char * what) { int i ; int found ; if (what==NULL) { /* Get all version numbers */ printf( "------------------------------------------------------------------------\n"); printf("eclipse version: %s\n", get_eclipse_version()); printf( "------------------------------------------------------------------------\n"); i=0 ; while (engine_table[i].name!=NULL) { printf("%15s -- %5s ", engine_table[i].name, rcs_value((char*)engine_table[i].version)); printf("(%s)\n", rcs_value((char*)engine_table[i].date)); i++; } printf( "------------------------------------------------------------------------\n"); } else { /* Find relevant subject */ if (!strcmp(what, "eclipse")) { printf("eclipse version: %s\n", get_eclipse_version()); return ; } i=0 ; found=0 ; while (engine_table[i].name!=NULL) { if (!strcmp(what, engine_table[i].name)) { printf("%15s -- %s\n", engine_table[i].name, rcs_value((char*)engine_table[i].version)); found++ ; break ; } i++; } if (!found) { e_error("cannot find anything about [%s]", what); } } return ; } /* * Man pages for all recipes */ static void man_page(char * what) { int i ; int found ; if (what==NULL) { /* Give more help */ printf( "%s", conicap_man); return ; } i=0 ; found=0 ; while (engine_table[i].name!=NULL) { if (!strcmp(what, engine_table[i].name)) { printf( "------------------------------------------------------------------------\n" ); printf(" Man page for %s v%s", what, rcs_value((char*)engine_table[i].version)); printf(" -- Last updated %s\n", rcs_value((char*)engine_table[i].date)); printf( "------------------------------------------------------------------------\n" ); printf("%s", engine_table[i].man_page); found++ ; break ; } i++; } if (!found) { e_error("cannot find anything about [%s]", what); } return ; } /* * Generic engine caller */ static int call_engine(char * name, int argc, char ** argv) { int i ; int found ; int status ; dictionary * d ; i=0 ; found = -1 ; /* Look for requested name in the table */ while (engine_table[i].name != NULL) { if (!strcmp(engine_table[i].name, name)) { /* Found the requested recipe */ found = i ; break ; } i++ ; } if (found<0) { /* No corresponding name was found in the table */ e_error("no recipe called [%s]", name); return -1 ; } /* If no further option was passed, print out help message */ if (argc==1) { help(name); return 1 ; } /* Correct options were passed, launch the recipe engine */ d = cmdline_parse(argc, argv, engine_table[found].cmd); if (d==NULL) { return -1 ; } /* Execute engine */ status = engine_table[found].func(d); /* Discard dictionary and exit */ dictionary_del(d); return status ; } /*---------------------------------------------------------------------------- Main code ---------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { int status ; /* No argument: print out usage */ if (argc<2) { usage(); return 1 ; } status=0 ; /* See if a special command was given */ if (!strcmp(argv[1], "version") || !strcmp(argv[1], "--version")) { if (argc>2) version(argv[2]); else version(NULL); } else if (!strcmp(argv[1], "man")) { if (argc>2) { status = 1 ; man_page(argv[2]); } else { status = 1 ; man_page(NULL); } } else if (!strcmp(argv[1], "license")) { eclipse_display_license(); status = 1; } else { /* Initialize eclipse environment */ eclipse_init(); status = call_engine(argv[1], argc-1, argv+1); } if (debug_active()) xmemory_status() ; return status ; }