File: Main.cpp

package info (click to toggle)
yudit 2.9.6-8
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 13,868 kB
  • sloc: cpp: 70,516; perl: 4,299; ansic: 1,957; makefile: 846; sh: 331
file content (409 lines) | stat: -rw-r--r-- 11,675 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
/** 
 *  Yudit Unicode Editor Source File
 *
 *  GNU Copyright (C) 1997-2006  Gaspar Sinai <gaspar@yudit.org>  
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License, version 2,
 *  dated June 1991. See file COPYYING for details.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifdef USE_GETTEXT
extern "C"
{
#include <libintl.h>
}
#endif
#include <stdlib.h>

#include "gui/Main.h"
#include "gui/SYudit.h"

#include "stoolkit/SString.h"
#include "stoolkit/SStringVector.h"
#include "stoolkit/SProperties.h"
#include "stoolkit/SIO.h"
#include "stoolkit/SIOStream.h"
#include "stoolkit/SUniMap.h"
#include "stoolkit/SUtil.h"
#include "swindow/SFontImpl.h"
#include "stoolkit/syntax/SSyntax.h"

#include "swindow/SAwt.h"

#ifndef USE_WINAPI
#include <unistd.h> 
#include <pwd.h>
#include <sys/types.h>
#endif

int
main (int argc, char* argv[])
{
  /* have to set the path before awt */
  SUniMap::guessPath ();
  SSyntax::guessPath ();

  unsigned int i; unsigned int j;
  SString home = getHome();
  SString yuditdir = getPrefix();
  
  SString dotdir = home;
  dotdir.append ("/");
  dotdir.append (".yudit");
  SDir d (dotdir);
  if (!d.exists())
  {
    if (d.create())
    {
      fprintf (stderr, "yudit: created directory `%*.*s'\n",
         SSARGS (dotdir));
    }
    else
    {
      fprintf (stderr, "yudit: can not create directory `%*.*s'\n",
         SSARGS (dotdir));
      // don't exit on windows ! They won't know a thing.
      //exit (1);
    }
  }
  else if (!d.readable())
  {
    fprintf (stderr, "yudit: Can not read directory `%*.*s'\n",
        SSARGS (dotdir));
  }

  SString fontdir(dotdir);
  fontdir.append ("/");
  fontdir.append ("fonts");
  SDir dfont (fontdir);
  if (!dfont.exists())
  {
    dfont.create ();
  }
  SString dotdata(dotdir);
  dotdata.append ("/");
  dotdata.append ("data");
  SDir ddotdata (dotdata);
  if (!ddotdata.exists())
  {
    ddotdata.create ();
  }
  SString dotsyntax(dotdir);
  dotsyntax.append ("/");
  dotsyntax.append ("syntax");
  SDir ddotsyntax (dotsyntax);
  if (!ddotsyntax.exists())
  {
    ddotsyntax.create ();
  }

  SStringVector args;
  SProperties   properties;

  

  /**
   *-----------------------------------------------------------------------
   * The default configuration section this will always be here.
   *-----------------------------------------------------------------------
   */
  //properties.put ("yudit.datapath", );
  //properties.put ("yudit.fontpath", );
  properties.put ("yudit.background", "gray50");
  properties.put ("yudit.label.foreground", "moccasin");
  properties.put ("yudit.title.foreground", "white");


  properties.put ("yudit.default.font", "default");
  properties.put ("yudit.default.fontsize", "16");
  properties.put ("yudit.default.geometry", "765x510");
  properties.put ("yudit.freehand.converter", "kanji");

  properties.put ("yudit.editor.background", "black");
  properties.put ("yudit.editor.left.foreground", "green");
  properties.put ("yudit.editor.right.foreground", "yellow");

  properties.put ("yudit.editor.caret.left.foreground", "red");
  properties.put ("yudit.editor.caret.right.foreground", "red");
  properties.put ("yudit.editor.showbreak", "true");

  /* enable syntax simple for people with old config file */
  properties.put ("yudit.editor.syntax", "simple");

  /* don't enable wordwrap for people with old config file */
  properties.put ("yudit.editor.wordwrap", "false");

  /* do over-the spot xim */
  properties.put ("yudit.editor.xinputs.style", "preedit-over-status-under");

  properties.put ("yudit.command.background", "black");
  properties.put ("yudit.command.left.foreground", "green");
  properties.put ("yudit.command.right.foreground", "yellow");
  properties.put ("yudit.command.caret.left.foreground", "red");
  properties.put ("yudit.command.caret.right.foreground", "red");
  properties.put ("yudit.slider.background", "#497986");
  properties.put ("yudit.editor.fontsizes", "10,12,14,16,24,48");
  properties.put ("yudit.editor.fonts", "default,TrueType,Bitmap");
#ifdef USE_WINAPI
  properties.put ("yudit.editor.inputs", 
    "straight,unicode,WindowsIM,Hungarian,Hangul,"
    "Kana,Mnemonic,Esperanto,Arabic,Hebrew,"
    "Russian,HungarianRunes");
#else
  properties.put ("yudit.editor.inputs", 
    "straight,unicode,kinput2,Hungarian,Hangul,"
    "Kana,Mnemonic,Esperanto,Arabic,Hebrew,"
    "Russian,HungarianRunes");
#endif
  if (isWinAPI())
  {
    properties.put ("yudit.editor.xinputs", "");
  }
  else
  {
    properties.put ("yudit.editor.xinputs", "utf-8:en_GB,utf-8:hu_HU,kinput2:ja_JP.eucJP,xcin:zh_TW.big5,Ami:ko_KR,xcin-zh_CN.GB2312:zh_CN.GB2312");
  }
  properties.put ("yudit.editor.fontsize", "16");
  properties.put ("yudit.editor.font", "default");
  properties.put ("yudit.editor.input", "straight");
  properties.put ("yudit.fonts", "default,TrueType,Bitmap");
  properties.put ("yudit.font.TrueType", 
       "arial.ttf,msgothic.ttf,gulim.ttf,"
       "-*-*-*-*-*--*-*-*-*-*-*-iso8859-1,"
       "cyberbit.ttf,yudit.ttf:cp-1250");

  properties.put ("yudit.font.Bitmap", 
   "-gnu-unifont-medium-r-normal--16-160-75-75-c-80-iso10646-1,*-iso8859-1,"
   "jisx0208.1983-0,"
   "jisx0201.1976-0,"
   "-sony-fixed-medium-r-normal--*-230-75-75-c-120-iso8859-1");

  properties.put ("yudit.default.printer.options", "");
  properties.put ("yudit.default.preview.command", "gv");

  /**
   * override everything with system prop 
   */
  SString yuditconfig(yuditdir);
  yuditconfig.append ("/config/yudit.properties");
  if (!loadProperties (yuditconfig, &properties))
  {
    fprintf (stderr, "could not load `%*.*s'.\n", SSARGS(yuditconfig));
  }
  else
  {
    //fprintf (stderr, "loaded `%*.*s'.\n", SSARGS(yuditconfig));
  }

  /**
   * User defined properties 
   */
  SProperties userProperties;
  userProperties.put ("yudit.default.clipboard.encoding", "iso-2022-x11");
  userProperties.put ("yudit.default.filetype", "utf-8");

  SString userconfig (dotdir);
  userconfig.append ("/yudit.properties");
  bool firsttime = false;
  if (!loadProperties (userconfig, &userProperties))
  {
    firsttime = true;
    //fprintf (stderr, "could not load `%*.*s'(not an error).\n", 
    //       SSARGS(userconfig));
  }
  else
  {
    //fprintf (stderr, "loaded `%*.*s'.\n", SSARGS(userconfig));
    const SString *str = userProperties.get ("yudit.default.preview.command");
    /* compatibility. remove this. */
    if (str!=0)
    { 
      const SString& ustr = *str;
      if (ustr.size() > 0 && ustr[0] == '-' && ustr[1] == 'e')
      {
         const SString& gvle = properties["yudit.default.preview.command"];
         fprintf (stderr, "moving yudit.default.preview.command '%*.*s' to '%*.*s' (compatibility 2.5).\n", 
           SSARGS(ustr), SSARGS(gvle));
         fprintf (stderr, "To get rid of this message set your yudit.default.preview.command in %*.*s (like: gv).\n", 
           SSARGS (userconfig));
         userProperties.put ("yudit.default.preview.command", SString(gvle));
      }
    }
  }
  
  SProperties allProperties(properties);
  userProperties.remove ("00HEADER.#");
  userProperties.remove ("yudit.default.language.#");

  // rewrite old user properties
  if (userProperties.get ("00HEADER.version.yudit") == 0 
     || userProperties["00HEADER.version.yudit"].compare (SD_YUDIT_VERSION) < 0)
  {
    // upgrade: our preferred geometry has changed.
    userProperties.put ("yudit.default.geometry", "765x510");
  }
  allProperties.merge (userProperties);
  if (allProperties.get ("yudit.default.file")==0)
  {
    allProperties.put ("yudit.default.file", "untitled.utf8");
  }

  /* you can not override this */
  allProperties.put ("yudit.config", userconfig);
  SStringVector ve(allProperties["yudit.editor.fonts"]);
  SStringVector vy(allProperties["yudit.fonts"]);

  for (i=0; i<ve.size(); i++)
  {
    for (j=0; j<vy.size(); j++)
    {
       if (vy[j] == ve[i]) break;
    }
    if (j == vy.size()) vy.append (ve[i]);
  }

  /**
   * Check if all fonts are defined.
   */
  SProperties fontProps;
  for (i=0; i<vy.size(); )
  {
    if (vy[i] == "default")
    {
      i++;
      continue;
    }
    SString str("yudit.font.");
    str.append (vy[i]);
    if (!allProperties.get (str))

    {
      fprintf (stderr, "removing: '%*.*s' from list - not defined.\n", SSARGS(str));
      //fprintf (stderr, "ALL=\n%*.*s\n", SSARGS(allProperties.toString()));
      vy.remove(i);
      i=0;
    }
    else
    {
      fontProps.put (vy[i], allProperties[str]);
      i++;
    }
  }

  SAwt awt;
  if (!awt.implemented())
  {
    if (!awt.hasGUI()) 
    {
      fprintf (stderr, "AWT is not implemented on this platform.\n");
      fprintf (stderr, "This can happen if X11 Development libraries\n"); 
      fprintf (stderr, "were missing when configure was executed.\n"); 
      fprintf (stderr, "Other Yudit programs (uniconv, uniprint) should work.\n"); 
      return 2;
    }
    else
    {
      fprintf (stderr, "Try to set your DISPLAY environment variable.\n");
      return 1;
    }
  }

  /* have to set the path after first awt */
  SFontImpl::guessPath ();
  SString clipEnc = allProperties["yudit.default.clipboard.encoding"];
  if (clipEnc.size())
  {
    awt.setEncoding (clipEnc);
//SStringVector all = SUniMap::getPath();
//SString s = all.join (",");
//fprintf (stderr, "setting clipboard encoder to %*.*s\n", SSARGS(clipEnc));
  }

  /* init fonts */
  for (i=0; i< vy.size(); i++)
  {
    SString key = vy[i];
    if (key == "default") continue;
    SString str = fontProps[key];
    SStringVector curr(str);
    
    SFontImplVector list;
    for (j=0; j<curr.size(); j++)
    {
      /* encoding is optional */
      SStringVector v(curr[j], ":");
      SString enc = v[0];
      if (v.size()>1 && v[1].size()!=0) enc = v[1];
      SFontImpl impl (v[0], enc);

      if (v.size()>2 && v[2].size()>0)
      {
         SStringVector pvect(v[2], ";");
         SProperties props;
         for (unsigned int j=0; j<pvect.size(); j++)
         {
            SStringVector vv(pvect[j], "=", true);
            if (vv.size() > 1)
            {
               props.put (vv[0], vv[1]);
            }
            else
            {
               props.put (vv[0], "true");
            }
         }
         impl.setAttributes(props);
      }
      list.append (impl);
    }
    //fprintf (stderr, "initializing %*.*s\n", SSARGS(key));
    SFont::put (key, list);
  }

  int k; 
  for (k=0; k<argc; k++)
  {
    args.append (argv[k]);
  }
  if (argc==1 && firsttime)
  {
    args.append ("-help");
  }
  SString ldir (yuditdir);
  ldir.append ("/locale");
  initTranslate ("yudit", ldir);
  if (allProperties.get ("yudit.default.language"))
  {
    SString lang = allProperties["yudit.default.language"];
    lang.replaceAll(" ", "");
    if (lang.size()>0 && lang!=SString("default"))
    {
       /* no spaces */
       setLanguage (lang);
    }
    else if (lang==SString("default"))
    {
      setLanguage (getSystemLanguage ("en"));
    }
  }

  SYudit *yudit = new SYudit (args, allProperties);
#ifdef USE_WINAPI
  /* they have no concept of window managers */
  yudit->center();
#endif
  yudit->show();
  SEventHandler::start();
  return 0;
}