1 /********************************************************************************
2 *                                                                               *
3 *                     T h e   A d i e   T e x t   E d i t o r                   *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 1998,2005 by Jeroen van der Zijp.   All Rights Reserved.        *
7 *********************************************************************************
8 * This program is free software; you can redistribute it and/or modify          *
9 * it under the terms of the GNU General Public License as published by          *
10 * the Free Software Foundation; either version 2 of the License, or             *
11 * (at your option) any later version.                                           *
12 *                                                                               *
13 * This program is distributed in the hope that it will be useful,               *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
16 * GNU General Public License for more details.                                  *
17 *                                                                               *
18 * You should have received a copy of the GNU General Public License             *
19 * along with this program; if not, write to the Free Software                   *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.    *
21 *********************************************************************************
22 * $Id: main.cpp,v 1.16 2005/01/16 16:06:06 fox Exp $                            *
23 ********************************************************************************/
24 #include "fx.h"
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <sys/stat.h>
28 #include <signal.h>
29 #ifndef WIN32
30 #include <unistd.h>
31 #endif
32 #include <ctype.h>
33 #include "FXRex.h"
34 #include "FXArray.h"
35 #include "Hilite.h"
36 #include "TextWindow.h"
37 #include "Adie.h"
38 #include "icons.h"
39 
40 /*
41   Note:
42 */
43 
44 
45 /*******************************************************************************/
46 
47 // Print command line help
printusage()48 void printusage(){
49   fprintf(stderr,"Usage: adie [options] files...\n");
50   fprintf(stderr,"  options:\n");
51   fprintf(stderr,"  -h, --help                          Print help.\n");
52   fprintf(stderr,"  -V, --version                       Print version number.\n");
53   fprintf(stderr,"  -v, --view                          View, don't edit file.\n");
54   fprintf(stderr,"  -e, --edit                          Edit file.\n");
55   fprintf(stderr,"  -g GEOMETRY, --geometry GEOMETRY    Specify window size.\n");
56   fprintf(stderr,"  -l NUM, --line NUM                  Jump to line number.\n");
57   fprintf(stderr,"  -m LANGUAGE, --mode LANGUAGE        Force language mode.\n");
58   fprintf(stderr,"  -t TAGS, --tags TAGS                Load tags file.\n");
59   }
60 
61 
62 // Start the whole thing
main(int argc,char * argv[])63 int main(int argc,char *argv[]){
64   TextWindow *window=NULL;
65   FXchar     *language=NULL;
66   FXchar     *tags=NULL;
67   FXbool      edit=TRUE;
68   FXint       line=0;
69   FXString    file;
70   FXint       arg;
71   FXint       x,y,w,h,g;
72 
73   // Make application
74   Adie application("Adie");
75 
76   // Open display
77   application.init(argc,argv);
78 
79   // Make a tool tip
80   new FXToolTip(&application,0);
81 
82   // Create it
83   application.create();
84 
85   // Loop over args
86   for(arg=1; arg<argc; ++arg){
87 
88     // Parse a few options
89     if(compare(argv[arg],"-v")==0 || compare(argv[arg],"--view")==0){
90       edit=FALSE;
91       }
92     else if(compare(argv[arg],"-e")==0 || compare(argv[arg],"--edit")==0){
93       edit=TRUE;
94       }
95     else if(compare(argv[arg],"-h")==0 || compare(argv[arg],"--help")==0){
96       printusage();
97       exit(0);
98       }
99     else if(compare(argv[arg],"-l")==0 || compare(argv[arg],"--line")==0){
100       if(++arg>=argc){ fprintf(stderr,"Adie: missing line number argument.\n"); exit(1); }
101       sscanf(argv[arg],"%d",&line);
102       }
103     else if(compare(argv[arg],"-t")==0 || compare(argv[arg],"--tags")==0){
104       if(++arg>=argc){ fprintf(stderr,"Adie: missing tags file argument.\n"); exit(1); }
105       tags=argv[arg];
106       }
107     else if(compare(argv[arg],"-m")==0 || compare(argv[arg],"--mode")==0){
108       if(++arg>=argc){ fprintf(stderr,"Adie: missing language mode argument.\n"); exit(1); }
109       language=argv[arg];
110       }
111     else if(compare(argv[arg],"-g")==0 || compare(argv[arg],"--geometry")==0){
112       if(++arg>=argc){ fprintf(stderr,"Adie: missing geometry argument.\n"); exit(1); }
113       g=fxparsegeometry(argv[arg],x,y,w,h);
114       }
115     else if(compare(argv[arg],"-V")==0 || compare(argv[arg],"--version")==0){
116       fprintf(stdout,"Adie - ADvanced Interactive Editor %d.%d.%d.\nCopyright (C) 1998,2003 Jeroen van der Zijp.\n\n",VERSION_MAJOR,VERSION_MINOR,VERSION_PATCH);
117       exit(0);
118       }
119 
120     // Load the file
121     else{
122       file=FXFile::absolute(argv[arg]);
123       window=new TextWindow(&application,"untitled");
124       window->create();
125       window->loadFile(file);
126       window->readBookmarks(file);
127       window->readView(file);
128       window->setEditable(edit);
129       if(language) window->forceSyntax(language);
130       if(line) window->visitLine(line);
131       }
132     }
133 
134   // Make window, if none opened yet
135   if(!window){
136     window=new TextWindow(&application,"untitled");
137     window->create();
138     if(language) window->forceSyntax(language);
139     }
140 
141   // Run
142   return application.run();
143   }
144 
145 
146