-
Notifications
You must be signed in to change notification settings - Fork 0
/
crpad.c.bak
executable file
·2468 lines (2174 loc) · 95.2 KB
/
crpad.c.bak
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
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*static char *sccsid = "%Z% %M% %I% - %G% %U%";*/
/***************************************************************
*
* ARPUS/Ce text editor and terminal emulator modeled after the
* Apollo(r) Domain systems.
* Copyright 1988 - 2002 Enabling Technologies Group
* Copyright 2003 - 2005 Robert Styma Consulting
*
* 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
* of the License, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Original Authors: Robert Styma and Kevin Plyler
* Email: [email protected]
*
***************************************************************/
/**************************************************************
*
* MODULE crpad.c main program for crpad
*
* ARGUMENTS:
* See summary in pw.c. This is where the usage prompt is.
*
*
* OVERVIEW
* The ce program is a programmers editor modeled after
* the Apollo DM editor. The program executable is named ce
* and is aliased to names cv and crpad. argv[0] is looked at
* to determine which name was used. cv and crpad bring the
* editor up in read only mode. The file, if specified, must
* exist and be readable. ce brings the editor up in read/write
* mode. The file either must exist and be writeable or not
* exist and the directory is writable.
*
* The windows get set up, some data read in, and the
* window is put up. When there is nothing to do, the
* rest of the data is read in. This allows the user to
* interact with the window sooner.
*
* Actual text drawing is done into a pixmap. It is then
* copied to the displayable window via XCopyArea. This
* makes expose events easy to process. Since a corner
* of the window may need to be redrawn. There is no
* pixmap backing for the DM windows. They are completely
* redrawn when the screen is exposed.
*
* There is a structure called DRAWABLE_DESCR. It has all the
* interesting information about a window. There are actually
* two for each window. One describes the window. The other
* describes the usable portion of the window. I leave a margin
* around the window. There is a pair for the main window, a
* pair for the dm input window, and a pair for the dm_output
* window.
*
* Configure_Notify is for when the screen changes size and shape.
* The pixmap must be rebuilt, the screen redrawn, and the DM
* windows remap. The DM subwindows, are unmapped on resize and
* therefore need to be sized and then mapped. A window only
* appears on the display when it and all its ancestors (parent
* windows) are mapped.
*
* Keypress and mouse events are translated into DM commands and the
* commands executed. Note that there is some code left over from
* before I had the DM stuff started.
*
* BUFF_DESCR stuctures describe buffer information in a window.
* the newbuffer is set up from cursor motion. There is a current
* buffer structure for each window which is referenced from the
* newbuffer structure. I am not yet sure I have all the correct
* information in this structure. The idea is that if you type a bit
* and then do a tdm command, some data about the target buffer needs
* to be kept around. This stuff is in preparation for the editor.
*
* NAMING
* There are a number of similar names in use. The convention they
* follow is demonstrated by the following example for the DM kd command.
*
* DM_kd - Defined constant in dmsyms.h. Numerical id number for this
* command.
* DMC_kd - Typedef of the command structure for the internal parsed form
* of the command.
* dmc->kd.cmdid - DMC is a union of all the DMC command structures. Done just
* like the XEvent structure. kd is the element in the structure.
* dm_kd - The routine to execute a kd command if it is not done in line.
*
* TRANSIENT CODE INFO:
* When code is going to be gotten rid of, it is often bracketed with conditional
* compilatin code until we are sure we really want to get rid of this code and
* not see it again. The bracketing code is:
* #ifdef blah
* #endif
*
* DEBUGGING INFO:
*
* The following is a list of the debugging bits which affect this program.
* To activate the various types of debugging info, use the environment variable
* DEBUG.
* For example:
*
* DEBUG=@1-3-4-5
* export DEBUG
*
* This will turn on DEBUG, DEBUG1, DEBUG3, DEBUG4, and DEBUG5.
* The program has to be compiled with -DDebuG for the debug to have
* any effect.
*
* DEBUG (any) - Basic setup info, font names, gc contents, event mask, error messages
*
* DEBUG0 - Memdata test for valid token
* DEBUG1 - Window setup, parms, intialization data, crpad.c dmwin.c
* DEBUG2 - mark/copy/paste/find mark.c dmfind.c
* DEBUG3 - Memdata debugging and Line / text insertion /replace
* DEBUG4 - DM cmd parsing, assignment, and execution crpad.c kd.c parsedm.c
* DEBUG5 - cursor movement, window repositioning mvcursor.c
* DEBUG6 - undo/redo
* DEBUG7 - typing es, ed, ee, en typing.c
* DEBUG8 - Text Cursor Motion (txcursor and highlight cursor motion)
* DEBUG9 - Set _Xdebug on (sync events in X)
* DEBUG10 - Warping cursor data, as opposed to incoming handled with DEBUG8
* DEBUG11 - Keysym translation kd.c, initial keydef loading in serverdef.c
* DEBUG12 - Screen drawing and copying from pixmap (split out from DEBUG10)
* DEBUG13 - Search
* DEBUG14 - event dump for cursor motion events plus cursor pixel dumping
* DEBUG15 - Event reception for non-motion events
* DEBUG16 - Pad support (shell window) pad.c
* DEBUG17 - Set copy / paste incr size to 128, forces X INCR processing also dm_rec tracing
* DEBUG18 - cc (carbon copy and multi window edit)
* DEBUG19 - unix pad routines in unixpad.c
* DEBUG20 - wdf and wdc and color(ca) processing
* DEBUG21 - Local Malloc routine debugging (macro CE_MALLOC)
* DEBUG22 - I/O signals coming from Shell socket and X socket
* DEBUG23 - vt100 mode emulation in vt100.c and scroll bar in sbwin.c
* DEBUG24 - dump atoms on property notify events, in crpad.c
* DEBUG25 - Keep track of signals in pad.c also low level text highlighting
* DEBUG26 - Hash table lookup stats in hsearch.c
* DEBUG27 - File locking in lock.c
* DEBUG28 - Indent processing ind.c
* DEBUG29 - Pulldown creation and processing in pd.c
* DEBUG30 - dde testing bit for ceterm, turns off the usleeps to avoid SIGALARM signals
* DEBUG31
* DEBUG32 - dynamic debugging (for debugging on the fly)
*
* MISC NOTES:
*
* 1. In this application the term keyboard events is used to
* refer to Key press and release events and Mouse button
* press and release events.
*
* CONDITION CODE:
*
* The following -D flags are also tested for withing Ce:
*
* -DDebuG - The DEBUG macro uses -DDebuG to include the code necessary
* for debugging.
*
* -DPAD - Used to conditionally compile in terminal emulation
* support. This is all of pad.c, unixpad.c, unixwin.c,
* and pieces of many other modules.
*
* -DARPUS_CE - Used in modules such as normalize.c which are
* part of other programs. This flag allows
* calls to dm_error and CE_MALLOC to be
* conditionally compiled in.
*
* -DNeedFunctionPrototypes - Tested for in the system X11 includes
*
* -DCE_LITTLE_ENDIAN - Used on Little Endian (reverse byte order)
* machines such as the dec, and intel machines.
*
* -DUSE_BSD_SIGNALS - Used in module usleep.c which is
* used on platforms which do not support
* the usleep function.
*
* -DSYS5 - Used to specify SYS5 as opposed to BSD
* code in pad.c. Set automatically for
* _INCLUDE_HPUX_SOURCE and solaris and Linux.
*
* -D_INCLUDE_HPUX_SOURCE - Used on HP/UX boxes for system calls which are different on
* HP/UX from other boxes. HP/UX requires a bunch of other includes
* to compile correctly, but we do not test them explicetly.
*
*
*
* -DTRACER - In pad.c this includes code involed in calls to
* ptrace, an experiment to access the working
* directory of the invoked shell. Not currently used.
*
* -DIBMRS6000 - Set on the IBM RS6000, used in pad.c
*
* -Dsolaris - Set on the Sun Solaris machine.
*
*
* The following are major ifdefs which are not set via -D
* These are all used only in pad.c
*
* ultrix - Defined by the system on any Dec Ultrix machine
*
* __alpha - Defined by the system on any Dec Alpha machine
*
* DECBOX - defined in pad.c if either ultrix or __alpha are defined.
*
* sun - Defined by the system on any Sun machine (either solaris or sunos).
*
* _BSD - turned on when neither _INCLUDE_HPUX_SOURCE nor solaris
* are specified. Gets BSD stuff included on Apollo
*
* blah - Used to get rid of code prior to actually deleting it.
*
* There are some other tests for constants in include files
* which are platform dependent but not under our control.
*
***************************************************************/
#include <stdio.h> /* /usr/include/stdio.h */
#include <errno.h> /* /usr/include/errno.h */
#include <string.h> /* /usr/include/string.h */
#include <limits.h> /* /usr/include/limits.h */
#ifndef WIN32
#include <signal.h> /* "/usr/include/signal.h" /usr/include/sys/signal.h */
#endif
#include <sys/types.h> /* "/usr/include/sys/types.h" */
#include <time.h> /* "/usr/include/time.h" */
#include <stdlib.h> /* needed on linux for exit */
#ifdef WIN32
#include <windows.h>
#ifdef WIN32_XNT
#include "xnt.h"
#else
#include "X11/Xlib.h" /* /usr/include/X11/Xlib.h */
#include "X11/keysym.h" /* /usr/include/X11/keysym.h /usr/include/X11/keysymdef.h */
#include "X11/cursorfont.h" /* /usr/include/X11/cursorfont.h */
#include "X11/Xatom.h" /* /usr/include/X11/Xatom.h */
#endif
#else
#include <X11/Xlib.h> /* /usr/include/X11/Xlib.h */
#include <X11/keysym.h> /* /usr/include/X11/keysym.h /usr/include/X11/keysymdef.h */
#include <X11/cursorfont.h> /* /usr/include/X11/cursorfont.h */
#include <X11/Xatom.h> /* /usr/include/X11/Xatom.h */
#endif
#ifdef WIN32
#include <io.h>
#endif
#define MAX_KEY_NAME_LEN 16
#define MAX_WINDOW_NAME_LEN 80
#define _MAIN_ 1
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "cc.h"
#include "cswitch.h"
#include "debug.h"
#include "display.h"
#include "dmc.h"
#include "dmwin.h"
#include "dumpxevent.h"
#include "emalloc.h"
#include "execute.h"
#include "expose.h"
#include "pw.h"
#include "getevent.h"
#include "getxopts.h"
#ifndef HAVE_CONFIG_H
#include "help.h"
#endif
#include "hexdump.h"
#include "init.h"
#include "kd.h"
#include "keypress.h"
#include "lineno.h"
#include "mark.h"
#include "memdata.h"
#include "mvcursor.h"
#include "netlist.h"
#include "normalize.h"
#ifdef PAD
#include "pad.h"
#endif
#ifdef WIN32
#include "X11/Xw32defs.h"
#endif
#include "parms.h"
#include "pastebuf.h"
#include "pd.h"
#include "prompt.h"
#include "record.h"
#include "redraw.h"
#include "sbwin.h"
#include "sendevnt.h"
#include "serverdef.h"
#include "tab.h"
#include "titlebar.h"
#include "txcursor.h"
#include "typing.h"
#include "undo.h"
#ifdef PAD
#include "unixpad.h"
#include "unixwin.h"
#include "vt100.h"
#endif
#include "wc.h"
#include "window.h"
#include "windowdefs.h"
#include "winsetup.h"
#include "xerror.h"
#include "xerrorpos.h"
#include "xutil.h"
/***************************************************************
*
* System routines which have no built in defines
*
***************************************************************/
char *getenv(const char *name);
int getppid(void);
int getpid(void);
int setpgrp(int pid, int pgrp); /* bsd version */
int isatty(int fd);
#ifndef WIN32
void gethostname(char *target, int size);
#endif
/*char *getcwd(char *buf, int size); creates error on solaris*/
/***************************************************************
*
* Local Protypes
*
***************************************************************/
static int realloc_pixmap(DRAWABLE_DESCR *pix,
Display *display,
#ifdef WIN32
Drawable *x_pixmap,
#else
Pixmap *x_pixmap,
#endif
Window main_window);
static void reset_geo_parm(DRAWABLE_DESCR *window,
char **option_value);
#ifdef CE_LITTLE_ENDIAN
int magic_numbers[] = {1700949842, 1394635890, 1634564468, 1260398112, 1852405349, 2037141536, 544367980, 0}; /* time differentials */
#else
int magic_numbers[] = {1383031397, 1920213075, 1954114913, 539369547, 1702259054, 542141561, 1818587680, 0}; /* time differentials */
#endif
static void check_differentials(int *m);
#ifdef DebuG
static void dump_atom(XEvent *event);
#endif
static void process_dash_e_parm(int *argc, char *argv[]);
#ifdef WIN32
static int dash_term_present(int argc, char *argv[]);
#endif
#ifndef WIN32
static void setup_signal_handlers(void);
#endif
extern char *compile_date;
extern char *compile_time;
int main(int argc, char *argv[])
{
XEvent event_union; /* The event structure filled in by X as events occur */
int redraw_needed; /* bitmask flag to tell when window redraw is needed and also what kind */
int warp_needed; /* Boolean flag to show that an XWarpCursor call is needed */
int shell_fd = -1; /* in pad mode, this is the file descriptor for the 2 way socket to the shell */
int cmd_fd; /* When -input is specified, this is the file descriptor for the alterate source of DM commands */
int read_locked; /* Set from -readlock option, locks windows and child windows into read only. */
int padmode_shell_pid; /* in pad mode, pid of the shell we are connected to */
int pid; /* process id of forked processes when forking away from the terminal - localized use only */
PAD_DESCR *from_buffer; /* Buffer matched to an X event */
int cursor_row; /* work variable used when processing cursor motion events - localized use */
int cursor_col; /* " " " " */
int window_echo; /* Boolean work variable used when processing cursor motion events - shows the current window has text highlighting */
int open_for_write; /* Boolean work variable used to hold data about opening file and main window for r/w before memdata token is set up */
static int conf_event = ConfigureNotify; /* constant used to eat extra configure notify events */
static int motion_event = MotionNotify; /* constant used to eat extra motion events */
char *p,*q; /* localized use scrap variables */
int i;
#ifndef WIN32
unsigned int ui;
#endif
int old_lines_on_screen;
int window_resized;
char msg[MAX_LINE];
/***************************************************************
*
* Set the command name
*
***************************************************************/
#ifdef WIN32
cmd_path = argv[0];
p = strrchr(argv[0], '\\');
if (!p) p = strrchr(argv[0], '/');
#else
p = strrchr(argv[0], '/');
#endif
if (p == NULL)
cmdname = argv[0];
else
cmdname = p+1;
#ifdef WIN32
p = strstr(cmdname, ".exe");
if (!p) p = strstr(cmdname, ".EXE");
if (p)
{
q = strdup(cmdname);
q[p-cmdname] = '\0';
cmdname = q;
}
#endif
#ifndef WIN32
/***************************************************************
*
* If this is not pad mode, drop the setuid right away.
* This block of code added 10/10/95 RES
*
***************************************************************/
if (strncmp(cmdname, "ceterm", 6) != 0)
if (getuid() && !geteuid())
{
setuid(getuid());
}
#endif
/***************************************************************
*
* Set up our malloc protection scheme. This supports the
* CE_MALLOC macro defined in "malloc.h" (local).
* 2048 is the revserve storage used in case of failure.
* That storage will be freed on failure to allow enough space
* to try to do a save.
*
***************************************************************/
malloc_init(2048);
set_global_dspl(init_display()); /* set_global_dspl in getevent.c init_display in display.c */
dspl_descr->next = dspl_descr; /* circular linked list with one element */
#ifdef WIN32
dspl_descr->term_mainpad_mutex = (unsigned long)CreateMutex(NULL, False, NULL);
dspl_descr->main_thread_id = GetCurrentThreadId();
#endif
/***************************************************************
*
* Set the current working directory variables used by ce_getcwd
*
***************************************************************/
#ifdef PAD
ce_setcwd(NULL); /* NULL pointer tells ce_setcwd to do initialization in pad.c */
#endif
/***************************************************************
*
* Get debugging flag from the environment. If it is high
* enough turn on X syncronization with the server.
*
***************************************************************/
#ifdef DebuG
DEBUG0(Debug(DEBUG_ENV_NAME);) /* in debug.c */
#endif
/***************************************************************
*
* If this is ceterm or ntterm, see if the special -e option
* exists, If so, we will modify the parm list so everything after
* the -e is placed in one big parm.
*
***************************************************************/
#ifdef WIN32
if ((strncmp(cmdname, "ceterm", 6) == 0) || (strncmp(cmdname, "ntterm", 6) == 0) || (dash_term_present(argc, argv)))
#else
if (strncmp(cmdname, "ceterm", 6) == 0)
#endif
process_dash_e_parm(&argc, argv);
/***************************************************************
*
* Get the command line options and merge them with stuff from
* the .Xdefaults file and such. getxopts in getxopts.c
*
***************************************************************/
getxopts(cmd_options, OPTION_COUNT, defaults, &argc, argv, OPTION_VALUES, OPTION_FROM_PARM, &(dspl_descr->display), DISPLAY_IDX, NAME_IDX, resource_class);
#ifndef WIN32
if (DELAY_PARM)
{
float secs;
sscanf(DELAY_PARM, "%f", &secs);
ui = (ABSVALUE(secs) * 1e6);
usleep(ui);
}
#endif /* WIN32 */
/***************************************************************
* -version just prints the version and quits.
***************************************************************/
if (VERSION_PARM)
{
fprintf(stdout, PACKAGE_STRING, VERSION);
fprintf(stdout, ", Compiled: %s %s\n", compile_date, compile_time);
return(0); /* return from main */
}
/***************************************************************
* -oplist prints the options supplied and quits.
***************************************************************/
if (OPLIST)
{
for (i = 0; i < OPTION_COUNT; i++)
if (OPTION_VALUES[i])
fprintf(stdout, "%s%s : %s\n", cmdname, cmd_options[i].specifier, OPTION_VALUES[i]);
return(0); /* return from main */
}
/***************************************************************
* -help prints the list of available options and resources
***************************************************************/
if (HELP_PARM)
{
usage(argv[0]);
return(0); /* return from main */
}
/***************************************************************
* You can specify the directory for the ce .hlp files in the
* app-defaults/Ce file (ce_install), or in the .Xdefaults, or
* in the .profile.
***************************************************************/
if (CEHELPDIR)
{
p = getenv("CEHELPDIR");
if (!p || !(*p))
{
snprintf(msg, sizeof(msg), "CEHELPDIR=%s", CEHELPDIR);
p = malloc_copy(msg);
if (p)
putenv(p);
}
}
/***************************************************************
* If the environment variable CE_KDP is set to a non-blank
* value and -kdp was not specfied on the command line,
* then set the -kdb property from the environment variable.
***************************************************************/
p = getenv("CE_KDP");
if (p && *p && !OPTION_FROM_PARM[KDP_IDX])
{
if (KEYDEF_PROP)
free(KEYDEF_PROP);
KEYDEF_PROP = malloc_copy(p);
}
#ifdef DebuG
if (DebuG_PARM) /* Macro defined in parms.h */
{
snprintf(msg, sizeof(msg), "%s=%s", DEBUG_ENV_NAME, DebuG_PARM);
p = malloc_copy(msg);
if (p)
putenv(p);
Debug(DEBUG_ENV_NAME);
}
#else
if (DebuG_PARM && *DebuG_PARM)
dm_error("Ce not compiled with Debug enabled", DM_ERROR_BEEP);
#endif
/****************************************************************
*
* getxopts opens the display, make sure it is indeed open.
*
****************************************************************/
if (dspl_descr->display == NULL)
{
snprintf(msg, sizeof(msg), "%s: cannot connect to X server %s (%s)\n",
argv[0], XDisplayName(DISPLAY_NAME), strerror(errno));
dm_error(msg, DM_ERROR_LOG);
return(1); /* return from main */
}
/***************************************************************
*
* If the display name was set in the option values, make it
* the default.
*
***************************************************************/
if (OPTION_FROM_PARM[DISPLAY_IDX])
{
snprintf(msg, sizeof(msg), "DISPLAY=%s", DISPLAY_NAME);
p = malloc_copy(msg);
if (p)
putenv(p);
}
#ifdef WIN32
#define _XFlush XFlush
#endif
DEBUG1(socketfd2hostinet(ConnectionNumber(dspl_descr->display), DISPLAY_PORT_LOCAL);socketfd2hostinet(ConnectionNumber(dspl_descr->display), DISPLAY_PORT_REMOTE);)
DEBUG32(_XFlush(dspl_descr->display);)
DEBUG9(XERRORPOS)
if (XSYNCHRONIZE)
(void)XSynchronize(dspl_descr->display, True); /* RES 5/1/1998, temp fix for X terminals X server */
else
DEBUG9( (void)XSynchronize(dspl_descr->display, True);)
/***************************************************************
*
* Get the expression mode set real early on the first pass.
* Processing $ chars in the name depend upon it.
*
***************************************************************/
if (UNIXEXPR_ERR)
{
fprintf(stderr, "Invalid value for Ce.expr (%s), Aegis or Unix must be capitalized\n", OPTION_VALUES[EXPR_IDX]);
fprintf(stderr, "The cpp pass over the .Xdefaults file may convert \"unix\" or \"aegis\" to \"1\"\n");
}
if (UNIXEXPR)
dspl_descr->escape_char = '\\';
else
dspl_descr->escape_char = '@';
/*escape_char = dspl_descr->escape_char;*/
/***************************************************************
*
* If the program is being called as ce_merge, do the merge
* operation and quit.
*
***************************************************************/
if (strcmp(cmdname, "ce_merge") == 0)
{
i = ce_merge(dspl_descr);
return(i); /* return from main */
}
/***************************************************************
*
* If the -load option was specified, just load the key defintions
* into the server, if needed, and quit.
*
***************************************************************/
if ((LOAD_PARM) || (RELOAD_PARM))
{
if (RELOAD_PARM)
dm_delsd(dspl_descr->display, KEYDEF_PROP, dspl_descr->properties); /* in serverdef.c */
init_dm_keys(APP_KEYDEF, TABSTOPS, dspl_descr); /* in kd.c */
while(process_some_keydefs(dspl_descr)); /* in kd.c */
XFlush(dspl_descr->display);
DEBUG9(XERRORPOS)
XCloseDisplay(dspl_descr->display);
return(0); /* return from main */
}
check_differentials(magic_numbers);
/***************************************************************
*
* There should be one or zero arguments left, this is the
* file name to open. If zero, we will read stdin.
* validate file either works or bails out.
*
***************************************************************/
if (set_file_from_parm(dspl_descr, argc, argv, edit_file) != 0) /* in pw.c */
return(1); /* return from main */
/***************************************************************
*
* Decide whether we plan on writing on this file. The default
* for ce is write, cv is read, crpad is read.
*
***************************************************************/
if (((cmdname[0] == 'c') && (cmdname[1] == 'v')) || (strcmp(cmdname, "crpad") == 0) || (strcmp(edit_file, STDIN_FILE_STRING) == 0))
open_for_write = False;
else
open_for_write = True;
#ifdef PAD
/***************************************************************
*
* If the cmd_name is ce_pad, turn on cmd mode.
*
***************************************************************/
#ifdef WIN32
if ((strncmp(cmdname, "ceterm", 6) == 0) || (strncmp(cmdname, "ntterm", 6) == 0))
#else
if (strncmp(cmdname, "ceterm", 6) == 0)
#endif
{
dspl_descr->pad_mode = True;
open_for_write = False; /* pad is not user writable */
if (TRANSPAD)
{
dm_error("-transpad option ignored in ceterm", DM_ERROR_BEEP);
free(OPTION_VALUES[TRANSPAD_IDX]);
OPTION_VALUES[TRANSPAD_IDX] = (char *)strdup("no");
}
}
else
dspl_descr->pad_mode = False;
#endif
#ifdef WIN32
/***************************************************************
*
* For WIN32, process the -term, -edit, and -browse options.
* If -term was not specified and pad_mode is on anyway, the
* program name is ntterm or ceterm. If this is the case and
* a file was specifed which is not executable, then someone
* dragged a file onto the ntterm icon. Come up in browse.
*
***************************************************************/
if (TERM_MODE)
{
dspl_descr->pad_mode = True;
open_for_write = False; /* pad is not user writable */
}
if (BROWSE_MODE)
open_for_write = False;
if ((EDIT_MODE) && (strcmp(edit_file, STDIN_FILE_STRING) != 0))
open_for_write = True;
#endif
/***************************************************************
*
* If the input is stdin, make sure it is not pointing to the
* terminal and waiting for the poor fool to type a bunch of
* lines. Unless the transpad option was specified.
*
***************************************************************/
/* 6/24/1999, don't need ifdef pad, just test pad mode */
if (!dspl_descr->pad_mode && !TRANSPAD && (strcmp(edit_file, STDIN_FILE_STRING) == 0) && (isatty(0)))
{
#ifdef WIN32
if (do_open_file_dialog(edit_file, 256, True) != 0) /* in pad.c */
return(1); /* return from main */
#else
fprintf(stderr, "%s: Input from stdin requested and stdin is a terminal, exiting\n\n", argv[0]);
usage(argv[0]);
fprintf(stderr, "\n%s: Input from stdin requested and stdin is a terminal, exiting\n", argv[0]);
return(1); /* return from main */
#endif
}
/***************************************************************
*
* Set up the error handlers for problems with X.
* The first one is for protocol problems, run out of server memory
* and so forth.
*
* The second is for things like a server crash.
*
* This set of calls is done twice, once here for intial_file_open
* and once later to allow reinitialization for reopening.
*
***************************************************************/
DEBUG9(XERRORPOS)
XSetErrorHandler(ce_xerror);
DEBUG9(XERRORPOS)
XSetIOErrorHandler(ce_xioerror);
#ifdef PAD
if (dspl_descr->pad_mode)
{
change_background_work(dspl_descr, MAIN_WINDOW_EOF, True);
/* Get rid of the CE_EDIT_DIR env var if it exists. see pw.h */
if (getenv(CE_EDIT_DIR) != NULL)
{
snprintf(msg, sizeof(msg), "%s=", CE_EDIT_DIR);
p = malloc_copy(msg);
if (p)
putenv(p);
}
}
else
#endif
{
/***************************************************************
* If we are not in pad mode, Open the input file, which may be stdin.
* The open_for_write flag may be change if the file exists and
* is not writeable.
*
* Put the edit file name in an environment variable. indent
* processing may need this.
***************************************************************/
snprintf(msg, sizeof(msg), "CE_FILENAME=%s", edit_file);
p = malloc_copy(msg);
if (p)
putenv(p);
/***************************************************************
* Make sure the keydefs are loaded. LSF processing requires
* the hash table.
***************************************************************/
if (LSF)
{
init_dm_keys(APP_KEYDEF, TABSTOPS, dspl_descr); /* in kd.c */
while(process_some_keydefs(dspl_descr));
}
instream = initial_file_open(edit_file, &open_for_write, dspl_descr); /* in pw.c */
if (instream == NULL)
return(3); /* return from main */
}
#ifndef WIN32
/***************************************************************
*
* Check the -stdin parm to see if there is an alternate
* source of DM commands. WIN32 does this later
*
***************************************************************/
if (TRANSPAD || (STDIN_CMDS && (dspl_descr->pad_mode || (strcmp(edit_file, STDIN_FILE_STRING) != 0))))
cmd_fd = 0;
else
cmd_fd = -1;
#else
cmd_fd = -1;
#endif
/***************************************************************
*
* If the -w parm was not specified, go background.
*
***************************************************************/
#ifndef CYGNUS
if (!WAIT_PARM)
{
pid = spoon();
#ifdef PAD
if (((pid == -1) && dspl_descr->pad_mode) || (pid > 0))
return(0); /* return from main */
#else
if (pid != 0)
return(0); /* return from main */
#endif
}
#endif
/***************************************************************
*
* Set up signal handlers for attention type interupts so we
* can try to create a crash file.
* catch_quit is in xerror.c
*
***************************************************************/
#ifndef WIN32 /* no signal handlers in WIN32 */
setup_signal_handlers(); /* local to this module */
#endif /* not WIN32 */
/**************************************************************
*
* Start loading the key definitions we will be using.
* This is continued in background mode.
*
***************************************************************/
if (!LSF)
init_dm_keys(APP_KEYDEF, TABSTOPS, dspl_descr); /* in kd.c */
/**************************************************************
*
* If -readlock was specified, start in read only mode and
* disable the ro command.
*
***************************************************************/
read_locked = READLOCK;
if (read_locked)
open_for_write = False;
/**************************************************************
*
* Make sure the paste buffer directory is set. Variable
* paste_buff_dir in in pastebuf.h and is used by pastebuf.c
*
***************************************************************/
if (PASTE_DIR != NULL)
strncpy(paste_buff_dir, PASTE_DIR, sizeof(paste_buff_dir));
else
strcpy(paste_buff_dir, "~/.CePaste");
translate_tilde(paste_buff_dir); /* process names starting with ~ if the name starts that way */
/***************************************************************
*
* Build the windows
*
***************************************************************/
win_setup(dspl_descr, edit_file, resource_class, open_for_write, argv[0]); /* in winsetup.c */
#ifdef WIN32
/***************************************************************
*
* Check the -stdin parm to see if there is an alternate
* source of DM commands. Non-WIN32 does this earlier in setup.
*
***************************************************************/
if (TRANSPAD || (STDIN_CMDS && (dspl_descr->pad_mode || (strcmp(edit_file, STDIN_FILE_STRING) != 0))))
transpad_input(dspl_descr); /* in unixpad.c */
#endif
#ifdef PAD
/***************************************************************
*
* If we are in pad mode, call the routine to start the shell.
* Strip the command name down to the parm.
*
***************************************************************/
if (dspl_descr->pad_mode)
{
/***************************************************************
* Save the window id for the error routine. Sometimes because
* of timing, window events come in for the unixcmd window
* after we have issued a close for the window. A error is
* generated when we try to move the cursor. This is hard to
* prevent, so we will just suppress the message.
* ce_error_unixcmd_window is global data in xerror.h.
***************************************************************/
ce_error_unixcmd_window = dspl_descr->unix_pad->x_window;
/***************************************************************
* Put the edit file name in an environment variable. indent
* processing may need this.
***************************************************************/
snprintf(msg, sizeof(msg), "CE_FILENAME=");
p = malloc_copy(msg);
if (p)
putenv(p);
shell_fd = ConnectionNumber(dspl_descr->display); /* pass in the fd for X, get out the fd for the shell */
#ifdef WIN32
padmode_shell_pid = pad_init(edit_file, &shell_fd, (MAKE_UTMP ? dspl_descr->display_host_name : NULL), LOGINSHELL, dspl_descr);
#else
padmode_shell_pid = pad_init(edit_file, &shell_fd, (MAKE_UTMP ? dspl_descr->display_host_name : NULL), LOGINSHELL);
#endif
if (padmode_shell_pid < 0)
{