File: xcoral.c

package info (click to toggle)
xcoral 1%3A3.40-2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 15,484 kB
  • ctags: 4,970
  • sloc: ansic: 48,884; lisp: 11,570; yacc: 1,829; lex: 1,262; sh: 152; makefile: 144
file content (391 lines) | stat: -rw-r--r-- 10,075 bytes parent folder | download
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
/* ########################################################################
   
   xcoral.c
   
   File: xcoral.c
   Path: /home/fournigault/c/X11/xcoral-2.31/xcoral.c
   Description: 
   Created: Fri Jan 27 10:42:00 MET 1995
   Author: Lionel Fournigault
   Modified: Fri Jan 27 10:42:01 MET 1995
   Last maintained by: Lionel Fournigault
   
   RCS $Revision: 1.1 $ $State: Exp $
   
   
   ########################################################################
   
   Note: 
   
   ########################################################################
   
   Copyright (c) : Lionel Fournigault
   
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.
   
   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.
   
   ######################################################################## */


#include <stdio.h>
#include <signal.h>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include <sys/param.h>

#include <ctype.h>
#include <locale.h>
#include <unistd.h>

#include "options.h"
#include "xcoral.h"
#include "parse.h"
#include "shadow.h"
#include "main_events.h"
#include "browser_init.h"
#include "warn_box.h"
#include "list_box.h"
#include "dial_box.h"
#include "fs_box.h"
#include "man_box.h"
#include "input_str.h"
#include "get_file.h"
#include "selection.h"
#include "new_window.h"
#include "tool_bar.h"

#if HAVE_STRING_H
#  include <string.h>
#  if !HAVE_BZERO
extern FCT (void, bzero, (char *dst, int len) );
extern FCT (void, bcopy, (char *src, char *dst, int len) );
#  endif
#else
#  include <strings.h>
#endif

Display		*dpy;
EdWin		*TWin [MAXWIN], *edwin; /* La table des fenetres */
XContext	EdContext; /* Pour switcher */
int no_window;

FCT (static RETSIGTYPE, contHandler, () );
FCT (static RETSIGTYPE, stopHandler, () );

extern init_smac();

/*
 **	Initialise les resources, les menus, les bouttons etc...
 **	Creer la premiere fenetre de texte et entre dans
 **	la boucle d'evenements.
 */
main ( argc, argv ) 
    int argc;
    char **argv;
{
  EdWin *CreateWindow ();
  char pathname [MAXPATHLEN + 2];
  char *msg;
  char tmp[MAXPATHLEN];
  char *xcoralrc = 0;
  extern char *ie_load_file ();
  extern void exit ();
  extern char  *getcwd();
  extern FCT(RETSIGTYPE, error_ctrl_c,(int));
  extern char *getenv ();
  extern int _startup;
  FILE *fd;
  char pp[BUFSIZ];
  
#if defined(DEBUG) && defined(sparc)
  malloc_debug(2);
  malloc_verify();
#endif
  no_window = True;
  /*
   * Ou suis-je dans quelle etagere.
   */
#if HAVE_GETCWD
  if ( getcwd ( (char *) pathname, MAXPATHLEN ) == 0 ) {
#else
  if ( getwd  ( (char *) pathname) == 0 ) {
#endif
    (void) fprintf ( stderr, "Getwd error\n" );
    (void) exit ( 1 );
  }
  (void) bzero ( (char *) TWin, MAXWIN );
  setlocale(LC_CTYPE, "");

  /*
   * Initialisation du ressource manager, connexion avec le serveur,
   * creation d'un contexte graphique pour le top et bottom shadow.
   * Calcul des options ( parametres de la commande, .Xdefaults etc... )
   */
  XrmInitialize ();		
  ParseOpenDisp ( &argc, argv );
  CreateRGC ( dpy );
  GetUserDatabase ();
  MergeOptions ();
  
  EdContext = XUniqueContext ();
  
  InitMode ();
  
  /*
   * Initialisation des ressources pour les elements Text,
   * Menus et Panel de controle.
   * Les ressources sont :
   * 	une fonte et 4 couleurs (foreground, background,
   *	top_shadow et bottom shadow ).
   */
  InitTextRes ( dpy, GetOpFont ( OP_TEXT_FONT ), GetOpColor ( OP_TEXT_FG ),
	       GetOpColor ( OP_TEXT_BG ), GetOpColor ( OP_MENU_TS ),
	       GetOpColor ( OP_MENU_BS ));
  
  InitMenusRes ( dpy, GetOpFont ( OP_MENU_FONT ), GetOpColor ( OP_MENU_FG ),
		GetOpColor ( OP_MENU_BG ), GetOpColor ( OP_MENU_TS ),
		GetOpColor ( OP_MENU_BS ));
  
  InitControlRes ( GetOpColor ( OP_CTRL_FG ), GetOpColor ( OP_CTRL_BG ),
		  GetOpColor ( OP_CTRL_TS ),  GetOpColor ( OP_CTRL_BS ));
  
  /*
   * Encore quelques initialisations.
   */
  InitEvent ();
  InitScroll ( dpy );
  InitBrowser ();
  (void) InitWarningBox ();
  (void) InitListBox ();
  (void) InitDialogBox ();
  (void) InitFsBox ();
  (void) InitManBox ();
  SetBrowserMode ( (Mode *) GetMode ("C++mode") );
  SetBrowserDir ( (char *) pathname );
  init_smac(1024, 18);
  InitIconPixmap ();
  InitSelection (dpy,GetOpColor ( OP_TEXT_FG ), GetOpColor ( OP_TEXT_BG ));
  InitToolBar(GetOpColor ( OP_MENU_BG ), GetOpColor ( OP_MENU_TS ),
	      GetOpColor ( OP_MENU_BS ));
  InitTrombinesBox ();
  InitPcmap ();
  
  /* Chargement de .xcoralrc et SmacLib */
  /* On verifie d'abord l'existence de SmacLib */
  (void) sprintf(tmp,"%s/xcoralrc.lf",XCORAL_LIB_DIR);
  if (access(tmp,R_OK)==0){
    /* SmacLib Ok */
    bzero ( tmp, MAXPATHLEN );
    xcoralrc = (char *) getenv ("XCORALRC");
    if (!xcoralrc) {
      (void) sprintf ( tmp, (char *) getenv ( "HOME" ) );
      (void) strcat ( tmp, "/.xcoralrc" );
    }
    else 
      (void) strcpy ( tmp, xcoralrc );

    if (access(tmp,R_OK)!=0){
      /* pas de xcoralrc defini, ca craint */
      /* On copie celui qui est dans SmacLib */
      (void) sprintf (tmp, "cp %s/xcoralrc.lf %s/.xcoralrc\n",
		      XCORAL_LIB_DIR,(char *)getenv ("HOME"));
      system(tmp);
      (void) sprintf (tmp, (char *) getenv ("HOME"));
      (void) strcat (tmp, "/.xcoralrc");
    }
    else {
      /* On verifie que la version est correcte */
      if ((fd = fopen((char *)tmp,"r"))!=0){
	fgets(pp,8,fd);
	if (strncmp((char *)(pp+3),CURRENT_VERSION,4)!=0){
	  /* .xcoralrc ne correspond pas a la version courante. Copie */
	  (void) sprintf(pp,"%s/.xcoralrc.old",(char *)getenv ("HOME"));
	  rename (tmp,pp);
	  /* On copie celui qui est dans SmacLib */
	  (void) sprintf (tmp, "cp %s/xcoralrc.lf %s/.xcoralrc\n",
			  XCORAL_LIB_DIR,(char *)getenv ("HOME"));
	  system(tmp);
	  (void) sprintf (tmp, (char *) getenv ("HOME"));
	  (void) strcat (tmp, "/.xcoralrc");
	  (void) fprintf (stderr,"Your .xcoralrc file is obsolete so it has been moved as .xcoralrc.old\n");
	  (void) fprintf (stderr,"A new .xcoralrc file has been created in your home directory\n");
	}
      }
    }
    msg = (char *) ie_load_file ( (Text *) 0, tmp ) ;      
  }
  else {
    (void) fprintf ( stderr, "%s\n", "Warning: SmacLib not installed");    
  }
  
  chdir(pathname );
  /*
   * Le mode 'input_str'
   */
  InitInputString ();
  
  /*
   * Allons-y pour les premieres fenetres d'edition. 
   */
  edwin = 0; /* Pour etre sur */
  if (! *(argv + 1)) {
    /* pas de nom de fichier */
    if ( (edwin = CreateWindow ()) == 0 ) { 
      ( void ) fprintf ( stderr,"Create window error\n" );
      (void) exit (1);
    }
    
    SetCtrMode ( edwin -> text -> mwin, edwin -> text -> current_mode );
    (void) strcpy ( edwin -> text -> filename, (char *) GetOpFilename () );
    (void) strcpy ( edwin -> text -> current_dir, pathname );
  }
  else {
    while (*++argv) {
      EdWin * win;
      
      if (! (win  = CreateWindow ()))
	/* trop de fenetre */
	break;
      if ( ! edwin )
	edwin = win;
      SetCtrMode ( win -> text -> mwin, win -> text -> current_mode );
      (void) strcpy ( win -> text -> filename, *argv );
      (void) strcpy ( win -> text -> current_dir, pathname );
      _startup ++;
      if ( LoadFile ( win -> text, (char *) *argv, NEW ) != -1 )
	chdir(pathname);
      else
	SetDirAndFilename ( win -> text, *argv );
    }
  }
  
  /*
   * On ignore les signaux habituels, et on attrape le stop et
   * le continue (pour des raisons tordues).
   */
  (void) signal ( SIGINT, error_ctrl_c );
/* #define DEBUG */
#ifndef DEBUG
  (void) signal ( SIGQUIT, SIG_IGN );
#endif
#undef DEBUG
  /* 
   * Affichage des premieres fenetres et on attend que les Events y se
   * pointent.
   */
  {
    int i;
    
    for (i = 0; (i != MAXWIN) && TWin[i]; i += 1) {
      XMapWindow ( dpy, TWin[i]->w_frame );
      XFlush ( dpy );
    }
  }
  no_window = False;

  WaitForEvent ();
  
  /*NOTREACHED*/
}

/*
**	Name : stopHandler
**
**	Description : Attrape le signal 'stop'. S'il reste des requetes
**		ou des	evenements on ignore le signal.
**
*/
static RETSIGTYPE stopHandler ()
{
#ifdef DEBUG
  (void) fprintf ( stderr, "Stop\n" );
#endif
  (void) signal ( SIGTSTP, SIG_IGN );
  XSync ( dpy, False );
  if ( QLength ( dpy ) == 0 ) { /* On peut stopper */
    (void) signal ( SIGCONT, contHandler );
    (void) signal ( SIGTSTP, SIG_DFL );
    (void) kill ( getpid(), SIGTSTP );
  }
  else
    (void) signal ( SIGTSTP, stopHandler );
}


/*
**	Name : contHandler 
**
**	Description : Attrape le signal 'continue' pour virer tous
**		les evenements de type ButtonPress recus pendant que le
**		process etait stoppe. 
*/
static RETSIGTYPE contHandler ()
{
  XEvent event;
#ifdef DEBUG
  (void) fprintf ( stderr, "Continue\n" );
#endif
  (void) signal ( SIGCONT, SIG_IGN );
  
  XSync ( dpy, False );
  if ( QLength ( dpy ) != 0 ) 
    while ( XCheckMaskEvent ( dpy, ButtonPress, &event ));
  
  (void) signal ( SIGTSTP, stopHandler );
  (void) signal ( SIGCONT, SIG_DFL );
  (void) kill ( getpid (), SIGCONT );
  
  XFlush ( dpy ); 
}

#if HAVE_STRING_H

#if !HAVE_BZERO
#  if HAVE_MEMORY_H
#    include <memory.h>
#  endif
void bzero(dst, len)
  char *dst;
  int   len;
{
  memset((char *)dst, 0, len);
}

void bcopy(src, dst, len)
  char *src;
  char *dst;
  int   len;
{
  memmove((char *)dst, (char *)src, len);
}
#endif
#endif

#if !HAVE_STRDUP
char*
strdup(src)
  char* src;
{
  int   len;
  char* dst;

  len = strlen(src) + 1;
  dst = (char*) malloc(len);
  bcopy(src, dst, len);

  return(dst);
}
#endif