Main Page   Class Hierarchy   Data Structures   File List   Data Fields   Globals  

runtime_help.C

Go to the documentation of this file.
00001 #include "stdinc.h"
00002 
00006 
00007 #ifndef TOOLBOX
00008 
00009 local char* stredit(char* s, char c1, char c2)  // duplicate in kira_init.C
00010 {
00011     if (!s) return NULL;
00012 
00013     char* s1 = new char[strlen(s)+1];
00014     if (!s1) return NULL;
00015 
00016     strcpy(s1, s);
00017 
00018     char* ss = s1;
00019     while (*ss != '\0') {
00020         if (*ss == c1) *ss = c2;
00021         ss++;
00022     }
00023 
00024     return s1;
00025 }
00026 
00027 void get_runtime_help(char* source_file, char* compile_date, int level)
00028 {
00029     // Extract help information from the specified source file.
00030     // source_file was the location of the file in question at the
00031     // time the program was compiled, but we should allow for the
00032     // possibilities that the name has changed or the file has
00033     // become inaccessible.
00034 
00035     // As of Sep 2001, source_file has the STARLAB_PATH environment
00036     // removed.
00037 
00038     cerr << endl
00039          << "    Starlab version " << STARLAB_VERSION << endl;
00040 
00041     char* s = stredit(compile_date, '_', ' ');
00042     if (s) {
00043         cerr << "    program created " << s << endl;
00044         delete s;
00045     }
00046 
00047     // Look for the source file.  First try the name verbatim, then
00048     // try prepending the current STARLAB_PATH environment string.
00049 
00050     char src[1024];
00051     bool exists = false;
00052 
00053     strcpy(src, source_file);
00054     ifstream file(src);
00055 
00056     if (file) {
00057 
00058         exists = true;
00059         file.close();
00060 
00061     } else {
00062 
00063         // See if we can construct a file name from the environment.
00064 
00065         if (getenv("STARLAB_PATH")) {
00066             sprintf(src, "%s/%s", getenv("STARLAB_PATH"), source_file);
00067             ifstream file(src);
00068             if (file) {
00069                 exists = true;
00070                 file.close();
00071             }
00072         }
00073     }
00074 
00075     cerr << "    source file ";
00076     if (!exists) {
00077         cerr << "unavailable" << endl;
00078         exit(0);
00079     } else
00080         cerr << "    " << src << endl << endl;
00081 
00082     // First, find and print out level-1 help lines.
00083 
00084     char cmd[1024];
00085     strcpy(cmd, "grep '^////' ");
00086     strcat(cmd, src);
00087     strcat(cmd, " | sed s%////%\"   \"%");
00088 
00089     // Assume that help lines begin with "//// " (level 1)
00090     // or "//++ " (level 2).
00091 
00092     system(cmd);
00093     cerr<< endl;
00094 
00095     // Now check for level-2 help.
00096 
00097     if (level > 1) {
00098         strcpy(cmd, "grep '^//++' ");
00099         strcat(cmd, src);
00100         strcat(cmd, " | sed s%//++%\"    + \"%");
00101 
00102         system(cmd);
00103         cerr << endl;
00104     }
00105 
00106     exit(0);
00107 }
00108 
00109 void check_runtime_help(int argc, char** argv,
00110                         char* source_file, char* compile_date)
00111 {
00112     int help_level = 0;
00113 
00114     for (int i = 1; i < argc; i++) {
00115         if (strstr(argv[i], "-help")) help_level++;
00116         if (strstr(argv[i], "-HELP")) help_level = 2;
00117     }
00118 
00119     if (help_level) get_runtime_help(source_file, compile_date, help_level);
00120 }
00121 
00122 #else
00123 
00124 main(int argc, char** argv)
00125 {
00126     check_help();
00127 }
00128 
00129 #endif

Generated at Sun Feb 24 09:57:14 2002 for STARLAB by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001