1 // editor '93
2 // Copyright (C) 2000 Core Technologies.
3 
4 // This file is part of e93.
5 //
6 // e93 is free software; you can redistribute it and/or modify
7 // it under the terms of the e93 LICENSE AGREEMENT.
8 //
9 // e93 is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // e93 LICENSE AGREEMENT for more details.
13 //
14 // You should have received a copy of the e93 LICENSE AGREEMENT
15 // along with e93; see the file "LICENSE.TXT".
16 
17 #include	"includes.h"
18 
UnInitEditor()19 static void UnInitEditor()
20 // Undo what InitEditor did
21 {
22 	UnInitUserAbort();
23 	UnInitClipboard();
24 	UnInitBuffers();
25 	UnInitSyntaxMaps();
26 	UnInitKeyBindingTable();
27 }
28 
InitEditor()29 static bool InitEditor()
30 // Initialize all high-level editor concepts
31 // If there is a problem, set the error and return false.
32 {
33 	if(InitKeyBindingTable())
34 	{
35 		if(InitSyntaxMaps())
36 		{
37 			if(InitBuffers())
38 			{
39 				if(InitClipboard())
40 				{
41 					if(InitUserAbort())
42 					{
43 						return(true);
44 					}
45 					else
46 					{
47 						SetError("Failed to initialize user abort");
48 					}
49 					UnInitClipboard();
50 				}
51 				else
52 				{
53 					SetError("Failed to initialize clipboard");
54 				}
55 				UnInitBuffers();
56 			}
57 			else
58 			{
59 				SetError("Failed to initialize buffers");
60 			}
61 			UnInitSyntaxMaps();
62 		}
63 		else
64 		{
65 			SetError("Failed to initialize syntax maps");
66 		}
67 		UnInitKeyBindingTable();
68 	}
69 	else
70 	{
71 		SetError("Failed to initialize key bindings");
72 	}
73 	return(false);
74 }
75 
main(int argc,char * argv[])76 int main(int argc,char *argv[])
77 // The e93 entry point
78 {
79 	bool
80 		fail;
81 	UINT32
82 		numPointers;
83 
84 	fail=false;
85 	programName=argv[0];								// point to the program name forever more
86 	setlocale(LC_ALL,"");								// adjust to local customs
87 	if(EarlyInit())										// give process a chance to do whatever it would like (NOTE: if it returns false, exit without complaint (so it can fork if it wants to))
88 	{
89 		if(InitErrors())
90 		{
91 			ClearErrorTrace();
92 			if(InitEnvironment())						// handle low level GUI and environment init
93 			{
94 				ClearErrorTrace();
95 				if(InitEditor())						// handle high level initialization
96 				{
97 					ShellLoop(argc,argv);				// start the shell looping
98 					UnInitEditor();
99 				}
100 				else
101 				{
102 					fprintf(stderr,"Failed to initialize editor: %s\n",GetErrorTrace());
103 					fail=true;
104 				}
105 				UnInitEnvironment();
106 			}
107 			else
108 			{
109 				fprintf(stderr,"Failed to initialize environment: %s\n",GetErrorTrace());
110 				fail=true;
111 			}
112 			UnInitErrors();
113 		}
114 		else
115 		{
116 			fprintf(stderr,"Could not initialize error handlers\n");
117 			fail=true;
118 		}
119 		EarlyUnInit();
120 	}
121 	if((numPointers=MGetNumAllocatedPointers()))
122 	{
123 		fprintf(stderr,"Had %d pointer(s) allocated on exit\n",numPointers);
124 		fail=true;
125 	}
126 	if(fail)
127 	{
128 		return(1);										// tell OS bad things happened
129 	}
130 	return(0);
131 }
132