00001 #include "stdinc.h"
00002
00006
00007 #ifndef TOOLBOX
00008
00009 local char* stredit(char* s, char c1, char c2)
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
00030
00031
00032
00033
00034
00035
00036
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
00048
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
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
00083
00084 char cmd[1024];
00085 strcpy(cmd, "grep '^////' ");
00086 strcat(cmd, src);
00087 strcat(cmd, " | sed s%////%\" \"%");
00088
00089
00090
00091
00092 system(cmd);
00093 cerr<< endl;
00094
00095
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