editor.cxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00030
00031
00032
00035
00036 #include <cxxtls/viewermanager.h>
00037 #include <cxxtls/file.h>
00038 #include <list>
00039 #include <set>
00040 #include <cxxtls/directoryviewer.h>
00041 #include <cxxtls/textviewer.h>
00042 #include <cxxtls/keyviewer.h>
00043 #include <texteditor.hxx>
00044 #include <cxxtls/ftpviewer.h>
00045 #include <cxxtls/csvviewer.h>
00046 #include <cxxtls/scripttableviewer.h>
00047 #include <cxxtls/options.h>
00048 #include <cxxtls/symbolviewer.h>
00049
00050 #include <stdlib.h>
00051
00052 using namespace cxxtls;
00053
00054 extern char const *editversion;
00055
00056 typedef CursorWindow::input_event input_event;
00057
00058 using namespace std;
00059
00060 Viewer* read_only_edit(ViewerManager*vm, std::string &fullname)
00061 {
00062 TextEditor* rv = static_cast<TextEditor*>(TextEditor::app(vm,fullname));
00063
00064 if(rv)
00065 {
00066 rv->set_read_only();
00067 }
00068
00069 return rv;
00070
00071 }
00072
00073
00074
00075 int main(int argc, char **argv, char **environ)
00076 {
00077
00078 static char const *allowed_arguments=
00079 "-ftp,"
00080 "-h,"
00081 "-help,"
00082 "-s,"
00083 "-l:"
00084 ;
00085
00086 ProgramOptions::global_options_ = new ProgramOptions(allowed_arguments,
00087 argc,
00088 argv,
00089 environ);
00090
00091 ProgramOptions &options = *ProgramOptions::global_options_;
00092
00093 ViewerManager vm;
00094
00095 vm.executable_version_ = editversion;
00096 vm.executable_name_ = options.argv[0];
00097
00098 vm.open();
00099
00100
00101
00102
00103
00104 vm.add_app(DirectoryViewer::app, DirectoryViewer::app_name);
00105 vm.set_directory_app(DirectoryViewer::app);
00106
00107 vm.add_app(TextViewer::app, TextViewer::app_name);
00108
00109 vm.add_viewer_app(read_only_edit, "");
00110
00111 vm.add_app(TextEditor::app, TextEditor::app_name);
00112 vm.add_editor_app(TextEditor::app, "");
00113
00114 vm.add_app(CsvViewer::app, "CsvViewer");
00115 vm.add_editor_app(CsvViewer::app, ".csv");
00116
00117 vm.add_app(CsvViewer::app, "TsvViewer");
00118 vm.add_editor_app(CsvViewer::app, ".tsv");
00119
00120 vm.add_app(KeyViewer::app, KeyViewer::app_name);
00121
00122 vm.add_app(FTPviewer::app, FTPviewer::app_name);
00123
00124 vm.add_app(ScriptTableViewer::app, "TableCommander");
00125 vm.add_editor_app(ScriptTableViewer::app, ".stvsh");
00126
00127 vm.add_app(SymbolViewer::app, "SymbolViewer");
00128 vm.add_viewer_app(SymbolViewer::app, ".tagpp");
00129
00130 vm.add_viewer_app(SymbolViewer::app, ".cpptagdb");
00131
00132
00133
00134
00135
00136
00137
00138 if(options.option("-h") || options.option("-help"))
00139 {
00140 vm.close();
00141
00142 FileName me;
00143
00144 if(options.argv.size() >= 1)
00145 me = options.argv[0];
00146
00147 string prog = me.basename();
00148
00149
00150 cout << "This program supports the following command line options" << endl
00151 << endl
00152 << " " << allowed_arguments << endl
00153 << endl
00154 ;
00155 cout
00156 << "Options have the following meaning and parameters:" << endl
00157 << " (none) -- list the current directory" << endl
00158 << " filedir -- edit the named file or directory" << endl
00159 << " -s file -- view the named file" << endl
00160 << " -l n file -- edit fil and position to line n" <<endl
00161 << endl
00162 << " -ftp [h] [u] [p] [d] -- start ftp session" << endl
00163 << " host, user, password, and local directory are optional" << endl
00164 ;
00165 exit(1);
00166 }
00167 else
00168 if(options.option("-ftp"))
00169 {
00170 string path;
00171
00172 if(options.argv.size() > 1)
00173 {
00174
00175
00176 for(size_t i=1; i < options.argv.size(); ++i)
00177 {
00178 path += options.argv[i];
00179 path += ' ';
00180 }
00181
00182 }
00183
00184 Viewer* ftpviewer = FTPviewer::app(&vm, path);
00185
00186 if(ftpviewer)
00187 {
00188 vm.add(ftpviewer, path);
00189 }
00190 else
00191 {
00192 vm.close();
00193 exit(1);
00194 }
00195
00196 }
00197 else
00198 if(options.argv.size() == 2)
00199 {
00200
00201
00202 FileName pathname(options.argv[1]);
00203
00204 pathname = pathname.expand_tildes();
00205
00206 pathname.convert_to_absolute_path();
00207
00208 if(pathname.is_dir())
00209 {
00210 pathname.convertToDirectorySearchPattern();
00211 }
00212
00213
00214 Viewer* editor;
00215
00216 if(options.option("-s"))
00217 editor = vm.open(pathname);
00218 else
00219 editor = vm.edit(pathname);
00220
00221 if(editor == 0)
00222 {
00223 vm.close();
00224 cout << "Error, couldn't find an editor for '" << pathname << "'" << endl;
00225 exit(1);
00226 }
00227
00228 int line=1;
00229
00230 if(options.option("-l"))
00231 {
00232 ProgramOptions::value_iterator first = options.option("-l").begin();
00233
00234 sscanf(first->c_str(), "%d", &line);
00235
00236 editor->set_row_col_hint(line-1,0);
00237 }
00238
00239
00240 vm.add(editor, pathname);
00241
00242 }
00243 else
00244 if(options.argv.size() > 2)
00245 {
00246 for(size_t i = 1; i < options.argv.size(); ++i)
00247 {
00248 FileName pathname(options.argv[i]);
00249
00250 pathname = pathname.expand_tildes();
00251
00252 pathname.convert_to_absolute_path();
00253
00254 if(pathname.is_dir())
00255 {
00256 pathname.convertToDirectorySearchPattern();
00257 }
00258
00259 Viewer* editor;
00260
00261 if(options.option("-s"))
00262 editor = vm.open(pathname);
00263 else
00264 editor = vm.edit(pathname);
00265
00266 if(editor == 0)
00267 {
00268 vm.close();
00269 cout << "Error, couldn't find an editor for '" << pathname << "'" << endl;
00270 exit(1);
00271 }
00272
00273
00274 if(options.option("-l"))
00275 {
00276 int line=1;
00277
00278 sscanf(options.option("-l").begin()->c_str(), "%d", &line);
00279
00280 editor->set_row_col_hint(line-1,0);
00281 }
00282
00283 vm.add(editor, pathname);
00284
00285 }
00286 }
00287 else
00288 {
00289 FileName curdir(".");
00290 curdir.convert_to_absolute_path();
00291 curdir.convertToDirectorySearchPattern();
00292 vm.add(vm.edit(curdir), curdir);
00293 }
00294
00295
00296 vm.run();
00297
00298
00299 return 0;
00300 }