00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <basis/convert_utf.h>
00021 #include <basis/function.h>
00022 #include <basis/istring.h>
00023 #ifdef _AFXDLL
00024 #include <mfc_ext/info_edit.h>
00025 #include <mfc_ext/tiny_app.cpp>
00026 #include <mfc_ext/tiny_shell.h>
00027 #else
00028 #include <opsystem/application_shell.h>
00029 #endif
00030 #include <opsystem/ini_config.h>
00031 #include <data_struct/static_memory_gremlin.h>
00032
00033 #include <stdio.h>
00034 #include <stdlib.h>
00035
00036 #define BASE_LOG(to_print) program_wide_logger().log(to_print)
00037 #define LOG(to_print) STAMPED_EMERGENCY_LOG(program_wide_logger(), to_print)
00038
00039 #ifdef _AFXDLL
00040 class query_text : public tiny_shell
00041 #else
00042 class query_text : public application_shell
00043 #endif
00044 {
00045 public:
00046 #ifdef _AFXDLL
00047 query_text() : tiny_shell("not to be seen", "query_text") {}
00048 #else
00049 query_text() : application_shell("query_text") {}
00050 #endif
00051 virtual ~query_text() {}
00052 IMPLEMENT_CLASS_NAME("query_text");
00053 virtual int execute();
00054 };
00055
00057
00058 const char *help_info = \
00059 "This program requires a title and a description as the first and second\r\n\
00060 parameters. The third parameter is the initial value for the edit field\r\n\
00061 that the user fills in. The fourth parameter must be an INI file where\r\n\
00062 the result of the edit will be written. The INI file format is as follows:\r\n\
00063 \t[query]\r\n\
00064 \tanswer=USER-ENTERED-INFORMATION";
00065
00066 int query_text::execute()
00067 {
00068 FUNCDEF("execute");
00069
00070
00071
00072 #ifdef _AFXDLL
00073 ShowWindow(SW_HIDE);
00074 #endif
00075 if (__argc < 4) {
00076 #ifdef _AFXDLL
00077 MessageBox(to_unicode_temp(help_info),
00078 to_unicode_temp("Insufficient Parameters"), MB_OK);
00079 PostMessage(WM_CLOSE);
00080 #else
00081 BASE_LOG(help_info);
00082 #endif
00083 return 1;
00084 }
00085 istring title = __argv[1];
00086 istring description = __argv[2];
00087 istring initial_edit = __argv[3];
00088 istring outfile = __argv[4];
00089
00090
00091 for (int i = 0; i < description.length(); i++) {
00092 if ( (description[i] == '\\') && (i <= description.length() - 4) ) {
00093
00094 if ( (description[i + 1] == 'r') && (description[i + 2] == '\\')
00095 && (description[i + 3] == 'n') ) {
00096
00097 description.zap(i, i + 3);
00098 description.insert(i, "\r\n");
00099 }
00100 }
00101 }
00102
00103 istring to_return;
00104 while (!to_return) {
00105 #ifdef _AFXDLL
00106 info_edit querier(0, initial_edit.s(), 100, description.s(), title.s());
00107 if (querier.DoModal() == IDOK) {
00108
00109 to_return = querier.text();
00110 } else break;
00111 #else
00112 BASE_LOG(title);
00113 BASE_LOG("-------");
00114 BASE_LOG(description);
00115 BASE_LOG(istring("default value: ") + initial_edit);
00116 BASE_LOG("Please enter a value for the query...");
00117 char buff[2049];
00118 if (fscanf(stdin, "%2047s", buff) >= 1)
00119 to_return = buff;
00120
00121 BASE_LOG(istring("got answer of: \"") + to_return + "\"");
00122
00123 #endif
00124 }
00125
00126 if (to_return.t()) {
00127 ini_configurator ini(outfile, configurator::RETURN_ONLY);
00128 ini.store("query", "answer", to_return);
00129 #ifdef _AFXDLL
00130 PostMessage(WM_CLOSE);
00131 #endif
00132 return 0;
00133 } else {
00134
00135 #ifdef _AFXDLL
00136 PostMessage(WM_CLOSE);
00137 #endif
00138 return 1;
00139 }
00140 }
00141
00143
00144 HOOPLE_MAIN(query_text, )
00145