TERMS

Check-in [7ae03fea4e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Initial Commit
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1:7ae03fea4e792ce6708610e9fc2f6c3471f4986f
User & Date: jim 2010-05-06 10:54:25
Context
2010-05-06
10:54
Initial Commit Leaf check-in: 7ae03fea4e user: jim tags: trunk
10:54
initial empty check-in check-in: 6fae84c4b6 user: jim tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added COMS/netcom.c.





































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 *  netcom.c
 *  TULIP
 *	Berkley Sockets I/O 
 *  Created by Jim on Sat Oct 12 2002.
 *  Copyright (c) 2002 Pandora Products. All rights reserved.
 *
 *		 8-Feb-2003 JS	Create duplicate socket rtn
 *		30-Apr-2003 JS	Add local address string routine
 *		18-Apr-2009 Add netcom_stat() for sense of data
 *		21-Apr-2009 Fix netcom_stat() to sense correct socket (to_socket)
 *					not socket
 */

#include <sys/types.h>
#include <sys/sysctl.h>
#include <netdb.h>
#include "netcom.h"

static NETCOM_CHANNEL *base = NULL;

/****************************************************************************************
*
*  NETCOM_CHANNEL *netcom_netcreate(  int port,char *ip )
*
*	INPUT:	port	- Port number to use
*			ip		- Bind to this address if not NULL
*
*	OUTPUT:	Pointer to open channel bound to port
*			NULL if we cannot create it
*
*   NOTE: The channel if created is added to the internal list
*
*******************************************************************************************/

NETCOM_CHANNEL *netcom_netcreate( int port,char *ip )
{
	NETCOM_CHANNEL *ch;
	int val;
	int	opts;
	
	// (1) Build a channel and bail if we cannot
	
	ch = (NETCOM_CHANNEL *)MEMALLOC( sizeof(NETCOM_CHANNEL) );
	if( ch == NULL )
		return( NULL );
		
	// (1) OK, build the binding endpoint
	
	ch->addr.sin_family = AF_INET;
	if( ip != NULL )
		inet_aton( ip,(struct in_addr *)&(ch->addr.sin_addr.s_addr));
	else
		ch->addr.sin_addr.s_addr = htonl(INADDR_ANY);		// NONE speced
	ch->addr.sin_port = htons(port);
	
	// (2) Create the binding socket
	
	ch->socket = socket(AF_INET,SOCK_STREAM,0);
	if( ch->socket < 0 )
	{
		MEMFREE( ch );
		return( NULL );			// Could not create socket 
    }

	opts = 1;			// Set the reuse option on
	val = setsockopt(ch->socket,
						SOL_SOCKET,
						SO_REUSEADDR,
						&opts,sizeof(int));
		
	// (3) Connect to the endpoint

	val = bind(ch->socket,
				(const struct sockaddr *)&(ch->addr),
				sizeof(struct sockaddr_in));
				
	if( val < 0 )
	{
		close( ch->socket );		// Delete unused socket
		MEMFREE( ch );
		return( NULL );
	}
	
	// (3a) Set backlog length
	
    if (listen(ch->socket, 1) < 0) 
    {
        close(ch->socket);
        MEMFREE( ch );
        return(NULL);
    }
	
	// All done, mark this and attach to list
	
	ch->valid = NETCOM_VALID;
	ch->type = NETCOM_TCP;
	ch->state = NETCOM_OPEN;
	ch->duplicate = FALSE;
	
	if( base != NULL )
	{
		ch->next = base->next;
	}
	base = ch;		// To head of list

	return( ch );
}

/****************************************************************************************
*
*  NETCOM_CHANNEL *netcom_netduplicate(  NETCOM_CHANNEL *net )
*
*	INPUT:	net	- Duplicate this one
*
*	OUTPUT:	Pointer to open channel bound to port
*			NULL if we cannot create it
*			Mark as duplicate
*
*   NOTE: The channel if created is added to the internal list
*
*******************************************************************************************/

NETCOM_CHANNEL *netcom_netduplicate( NETCOM_CHANNEL *net )
{
	NETCOM_CHANNEL *ch;
	
	// (1) Build a channel and bail if we cannot
	
	ch = (NETCOM_CHANNEL *)MEMALLOC( sizeof(NETCOM_CHANNEL) );
	if( ch == NULL )
		return( NULL );
		
	// (1) Duplicate the socket
	
	ch->socket = net->socket;
	
	// All done, mark this and attach to list
	
	ch->valid = NETCOM_VALID;
	ch->type = NETCOM_TCP;
	ch->state = NETCOM_OPEN;
	ch->duplicate = TRUE;
	
	// Cross link the buddies
	
	ch->buddy = net;
	net->buddy = ch;
	
	if( base != NULL )
	{
		ch->next = base->next;
	}
	base = ch;		// To head of list

	return( ch );
}

/****************************************************************************************
*
*  void netcom_netdestroy( NETCOM_CHANNEL *net )
*
*	INPUT:	net	- NETCOM STRUCTURE
*
*	OUTPUT:	NONE
*
*   NOTE: Close the channel
*
*******************************************************************************************/

void netcom_netdestroy( NETCOM_CHANNEL *net )
{
	NETCOM_CHANNEL *ch,*prev;
	
	// (1) Remove this from the list
	
	ch = base;
	prev = NULL;
	while( ch != NULL )
	{
		if( ch == net )
		{
			break;
		}
		else
		{
			prev = ch;
			ch = ch->next;
		}
	}
	
	if( ch == NULL )
		return;					// NOT FOUND
		
	// If found, two cases, prev == null then
	// we are first in list link around from start
	// If prev != null then use it to link around
	
	if( prev == NULL )
	{
		base = ch->next;
	}
	else
	{
		prev->next = ch->next;
	}
	
	// (2) Ok net is unlinked so destroy it
	// Close the sockets & free the memory
	
	if( !net->duplicate )
	{
		// Only come here if we are NOT a duplicate
		
		if( net->socket > 0 )
			close( net->socket );
		if( net->to_socket > 0 )
			close( net->to_socket );
	}
	MEMFREE( net );

}

/******************************************************************************************
								*** NETCOM I/O ***
*******************************************************************************************/
/****************************************************************************************
*
*  TG_BOOL netcom_select(int msec,NETCOM_CHANNEL *net)	- Check for connection attemp
*
*	INPUT:	msec	- # Seconds to wait for input on each channel
*
*	OUTPUT:	TRUE if connection attempted and accepted
*	
*******************************************************************************************/

TG_BOOL netcom_select(int msec,NETCOM_CHANNEL *net)
{
	struct timeval to;
	fd_set ready;
	int val;
	
	// (1) Set up to select
	
	FD_ZERO( &ready );
	FD_SET( net->socket,&ready );
	to.tv_sec = msec/100;
	to.tv_usec = 1000 * (msec%1000);
	
	// (2) Wait on a select

	val = select(net->socket+1,&ready,NULL,NULL,&to);
	if( val == 0 )
		return( FALSE );
	
	// (3) Ok, accept the socket
	
	if( FD_ISSET( net->socket,&ready) )
	{
		net->to_socket = accept(net->socket,(struct sockaddr *)0,(socklen_t *)0);
		if( net->to_socket > 0 )
		{
			// Mark socket as READY
			
			net->state = NETCOM_READY;
			
			// Also fill in the buddies to socket if we have one
			
			if( net->buddy != NULL )
			{
				net->buddy->to_socket = net->to_socket;
			}
			return( TRUE );
		}
		else
			return( FALSE );
	}
	else
		return( FALSE );
}

/****************************************************************************************
*
*  int netcom_gets( NETCOM_CHANNEL *net,char *buf,int len )	 - Read the channel
*
*	INPUT:	echo	- TRUE to echo input
*			net		- Read on the to socket
*			buf		- Buffer to fill
*			len		- With this many bytes
*
*	OUTPUT:	# bytes received
*
*	Read till CR\LF seen
*	
*******************************************************************************************/

int netcom_gets( TG_BOOL echo,NETCOM_CHANNEL *net,char *buf,int len )
{
	int count;
    int total = 0;
    char *bptr = buf;
    TG_BOOL flag = TRUE;
	
    // Loop till 
    // (a) CR/LF seen
    // (b) total characters seen
    
    while( flag )
    {
        count = read(net->to_socket,bptr,len);
        total += count;
        
        // Should we echo
        
        if( echo )
        {
            write(net->to_socket,bptr,count );
        }
        
        switch( bptr[count-1] )
        {
            case '\r':
            case '\n':			// (a) Quit now at end of line
                                flag = FALSE;
                                break;
                                
            default:			// (b) Are we over the total
                                bptr += count;
                                if( total >= len )
                                {
                                    flag = FALSE;
                                }
                                break;
        }
    }
        
	return( total );
}


/****************************************************************************************
*
*  int netcom_read( NETCOM_CHANNEL *net,char *buf,int len )	 - Read the channel
*
*	INPUT:	net		- Read on the to socket
*			buf		- Buffer to fill
*			len		- With this many bytes
*
*	OUTPUT:	# bytes received
*	
*******************************************************************************************/

int netcom_read( NETCOM_CHANNEL *net,char *buf,int len )
{
	int count;
	
	count = read(net->to_socket,buf,len);
	return( count );
}

/****************************************************************************************
*
*  int netcom_write( NETCOM_CHANNEL *net,char *buf,int len )	 - Writ3e the channel
*
*	INPUT:	net		- Write on the to socket
*			buf		- Buffer send
*			len		- Buffer len
*
*	OUTPUT:	# bytes sendt
*	
*******************************************************************************************/

int netcom_write( NETCOM_CHANNEL *net,char *buf,int len )
{
	int count;
	
	count = write(net->to_socket,buf,len);
	return( count );
}

/****************************************************************************************
*
*  TG_BOOL netcom_stat(int msec,NETCOM_CHANNEL *net)	- Check for data
*
*	INPUT:	msec	- # Seconds to wait for input on each channel
*
*	OUTPUT:	TRUE if data ready
*
*  21-Apr-2009	Fix to use the to_socket rather than socket as that's where the
*				data arrives.
*	
*******************************************************************************************/

TG_BOOL netcom_stat(int msec,NETCOM_CHANNEL *net)
{
	struct timeval to;
	fd_set ready;
	int val;
	TG_BOOL rtnval = FALSE;
	
	// (1) Set up to select
	
	FD_ZERO( &ready );
	FD_SET( net->to_socket,&ready );
	to.tv_sec = msec/1000;
	to.tv_usec = 1000 * (msec%1000);
	
	// (2) Wait on a select

	val = select(net->to_socket+1,&ready,NULL,NULL,&to);
	if( val > 0 )
		rtnval = TRUE;
		
	return( rtnval );
	
}


Added COMS/netcom.h.

















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
 *  netcom.h
 *  TULIP
 *
 *  Created by Jim on Sat Oct 12 2002.
 *  Copyright (c) 2002 Pandora Products. All rights reserved.
 *
 *	18-Apr-2009 Add netcom_stat() for sense of data
 *
 */
 
 #ifndef NETCOM_H
 #define NETCOM_H	1

#include "tgtypes.h"
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/socketvar.h>
#include <net/route.h>
#include <net/if.h>
#include <sys/queue.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

typedef enum {
				NETCOM_SER,
				NETCOM_TCP
			} NETCOM_TYPE;
			
typedef enum {
				NETCOM_OPEN,
				NETCOM_READY
			} NETCOM_STATE;

#define NETCOM_VALID	'NETC'

typedef struct comlist_struct {
			TG_UINT32 valid;
			int duplicate;			// TRUE if duplicate socket
			struct comlist_struct *next;
			int socket;             // Socket handle
			int to_socket;			// Other end
			struct sockaddr_in addr;// IP address data
			NETCOM_TYPE type;
			NETCOM_STATE state;
			struct comlist_struct *buddy;	// Put dup handle here
		} NETCOM_CHANNEL;
		
		
NETCOM_CHANNEL *netcom_netcreate( int port,char *ip );
NETCOM_CHANNEL *netcom_netduplicate( NETCOM_CHANNEL *net );

void netcom_netdestroy( NETCOM_CHANNEL *net );
TG_BOOL netcom_select(int msec,NETCOM_CHANNEL *net);
TG_BOOL netcom_stat(int msec,NETCOM_CHANNEL *net);
int netcom_read( NETCOM_CHANNEL *net,char *buf,int len );
int netcom_gets( TG_BOOL echo,NETCOM_CHANNEL *net,char *buf,int len );
int netcom_write( NETCOM_CHANNEL *net,char *buf,int len);

#endif


Added Docs/TERMSTR.lyx.

























































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
#LyX 1.6.0 created this file. For more info see http://www.lyx.org/
\lyxformat 345
\begin_document
\begin_header
\textclass article
\begin_preamble

% Include the proper LaTeX packages:
%----------------------------------------------------------------------------------------------------
\usepackage{graphicx}
\usepackage{titling}
\usepackage{ifthen}
\usepackage[absolute]{textpos}
\usepackage[colorlinks=true,
                       pagecolor=black,
                       menucolor=black,
                       linkcolor=black,
                       citecolor=blue,
                       pagebordercolor=1 1 1,
                       urlcolor=red,
                       plainpages=false,
                       pdfpagelabels=true,
                       bookmarksnumbered=true]{hyperref}
\usepackage{lastpage}

\newcommand{\reportTopic}{<reportTopic>}
\newcommand{\revisionNumber}{<rev. no.>}
\newcommand{\documentNumber}{<doc. no.>}


% Setup the right-hand header to display the current doc section:
%----------------------------------------------------------------------------------------------------
\renewcommand{\sectionmark}[1]{\markright{#1}}
\renewcommand{\subsectionmark}[1]{\markright{#1}}

% Setup for roman numeral page numbers until TOC:
%----------------------------------------------------------------------------------------------------
\newboolean{romanpn}

\pagenumbering{roman}
\setboolean{romanpn}{true}
\let\myTOC\tableofcontents

\renewcommand\tableofcontents{%
\myTOC
\clearpage
\pagenumbering{arabic}
\setboolean{romanpn}{false}
}

% Modify titlepage format:
%----------------------------------------------------------------------------------------------------
\setlength{\TPHorizModule}{1in}
\setlength{\TPVertModule}{\TPHorizModule}
\textblockorigin{3.25in}{1in}

\pretitle
 {
    \begin{flushright}\LARGE\sffamily 
    \thispagestyle{empty}
    \begin{textblock}{4}(0,0)
    \includegraphics[width=4in,keepaspectratio=true]{/Users/Shared/LyX/Templates/Images/logo.png}
    \end{textblock}
    \vspace{2in}
  }

\posttitle{\par\end{flushright}}

\preauthor{\begin{flushright} \large \sffamily \lineskip 0.5em 
\begin{tabular}[t]{c}}
\postauthor{\end{tabular} \par\end{flushright}}

\predate{\begin{flushright}\large \sffamily Document Number: \documentNumber \\ Revision Number: \revisionNumber \\}

\postdate{
\vspace{2in}
\\Pandora Products.
\\215 Uschak Road
\\Derry, PA  15627
\par\end{flushright}}

% Setup "fancy" page layout:
%----------------------------------------------------------------------------------------------------
\fancyhf{}
\setlength{\topmargin}{-1in}
\setlength{\headheight}{1in}
\setlength{\headsep}{0.5in}
\setlength{\oddsidemargin}{0.25in}
\setlength{\evensidemargin}{\oddsidemargin}
\setlength{\textwidth}{6in}
\setlength{\headwidth}{\textwidth}
\setlength{\textheight}{8.375in}
\setlength{\footskip}{0.5in}

% Setup header:
%------------------------------------------------------------------------------------------
\fancyhead[L]{\sffamily \bfseries \large Pandora Products.\\\mdseries \reportTopic}
\fancyhead[R]{\sffamily \bfseries \large Program Manual\\ \mdseries \nouppercase{\rightmark}}

% Setup footer:
%------------------------------------------------------------------------------------------
\renewcommand{\footrulewidth}{0.4pt}
\fancyfoot[L]{\sffamily \bfseries \documentNumber \\ \mdseries Revision:  \revisionNumber}
\fancyfoot[C]{\sffamily \bfseries\thedate \\ \mdseries \reportTopic}
\fancyfoot[R]{\ifthenelse{\boolean{romanpn}}{\sffamily  \thepage}{\sffamily \bfseries Page \thepage\ of \pageref{LastPage}}}
\end_preamble
\use_default_options false
\language english
\inputencoding auto
\font_roman times
\font_sans helvet
\font_typewriter courier
\font_default_family default
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100

\graphics default
\paperfontsize 11
\spacing single
\use_hyperref false
\papersize letterpaper
\use_geometry false
\use_amsmath 1
\use_esint 0
\cite_engine basic
\use_bibtopic false
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation skip
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle fancy
\tracking_changes false
\output_changes false
\author "" 
\end_header

\begin_body

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
renewcommand{
\backslash
documentNumber}{PAM-200512002}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
renewcommand{
\backslash
reportTopic}{TERMS Terminal Server}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
renewcommand{
\backslash
revisionNumber}{0.4}
\end_layout

\end_inset


\end_layout

\begin_layout Title
Pandora Products Manual
\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash

\backslash
 
\backslash
reportTopic
\end_layout

\end_inset


\end_layout

\begin_layout Author
Jim Schimpf
\end_layout

\begin_layout Date
18 December 2005
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout


\backslash
thispagestyle{empty}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash
copyright
\end_layout

\end_inset

2005-2006 Pandora Products.
 All rights reserved.
 All other product names mentioned herein are trademarks or registered trademark
s of their respective owners.
 
\end_layout

\begin_layout Standard
\begin_inset VSpace medskip
\end_inset

Pandora Products.
 
\end_layout

\begin_layout Standard
215 Uschak Road 
\end_layout

\begin_layout Standard
Derry, PA 15627 
\end_layout

\begin_layout Standard
\begin_inset VSpace medskip
\end_inset

Phone: 412.829.8145 
\end_layout

\begin_layout Standard
Fax: 724.539.1276 
\end_layout

\begin_layout Standard
Web: pandora.dyn-o-saur.com:8080/~jim/ 
\end_layout

\begin_layout Standard
Email: vze35xda@verizon.net 
\end_layout

\begin_layout Standard
\begin_inset VSpace medskip
\end_inset

Pandora Products.
 has carefully checked the information in this document and believes it
 to be accurate.
 However, Pandora Products assumes no responsibility for any inaccuracies
 that this document may contain.
 In no event will Pandora Products.
 be liable for direct, indirect, special, exemplary, incidental, or consequentia
l damages resulting from any defect or omission in this document, even if
 advised of the possibility of such damages.
 
\end_layout

\begin_layout Standard
In the interest of product development, Pandora Products reserves the right
 to make improvements to the information in this document and the products
 that it describes at any time, without notice or obligation.
 
\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\end_layout

\begin_layout Section*
Document Revision History
\end_layout

\begin_layout Standard
\align center
\begin_inset Tabular
<lyxtabular version="3" rows="5" columns="4">
<features>
<column alignment="center" valignment="top" width="0.5in">
<column alignment="center" valignment="top" width="0.5in">
<column alignment="block" valignment="top" width="3in">
<column alignment="center" valignment="top" width="1in">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
Version
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
Author
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
Description
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
Date
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
0.1
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
js
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Initial Version
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
25-Jun-2004
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
0.2
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
js
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Convert to TR Format
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
18-Dec-2005
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
0.3
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
js
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Add telnet use section
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
22-Dec-2005
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
0.4
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
js
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Update telent use with bash script
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
13-Apr-2006
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Newpage newpage
\end_inset


\begin_inset CommandInset toc
LatexCommand tableofcontents

\end_inset


\end_layout

\begin_layout Section
Introduction
\end_layout

\begin_layout Standard
TERMS is a simple terminal server running in a UNIX/Linux system.
 It connects a single serial port to a single TCP/IP port.
 In addition it is extendible via a Lua 
\begin_inset CommandInset citation
LatexCommand cite
key "Lua5,LuaBook"

\end_inset

 script.
 The Lua script will have functions with defined names (see 
\begin_inset CommandInset ref
LatexCommand ref
reference "SCRIPT_USE"

\end_inset

) and these functions will be called by events in TERMS.
 
\end_layout

\begin_layout Standard
A terminal server is simply a device that connects a logical TCP/IP socket
 to a physical serial port.
 This allows use of normally serial only devices over a TCP/IP network.
 The terminal server has two major states, idle and connected.
 Idle means it owns the serial port and has an available socket on the TCP/IP
 network but no one is connected to the socket.
 It enters the connected state when a it accepts a TCP/IP socket connection.
 When the TCP/IP socket connection is dropped it then returns to idle.
\end_layout

\begin_layout Standard
Run with no options TERMS does this but when used with a Lua script, functions
 in that script can be called on these changes of state.
 This means for example it can toggle the serial DTR line on a connect or
 send keep alive messages to the serial port while connected.
\end_layout

\begin_layout Standard
This program makes it possible to access a serial port on a machine from
 anywhere on a network.
 Running it with existing programs like 
\series bold
telnet
\series default
 a free VT100 serial terminal can be created.
\end_layout

\begin_layout Section
Syntax
\end_layout

\begin_layout LyX-Code

\size small
TERMS [-p <port #/Name>] [-baud <baud rate>] [-tcp_p <Port #>] 
\end_layout

\begin_layout LyX-Code

\size small
      [-c <Lua Script>] [-v]
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout Standard
\align center
\begin_inset Tabular
<lyxtabular version="3" rows="6" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
Option
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
Default
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
TERMS
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-p <serial port #/Path
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
1
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-baud <Baud Rate>
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
38,400
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-tcp_p <TCP/IP Port #>
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
6000
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-c <Lua Script>
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
NONE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-v
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
NONE
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Standard
TERMS is run from the command line and with no options will be a terminal
 server connecting Serial port 1 to TCP/IP socket 6000.
 The serial port will be set at 38,400 baud and none of the control lines
 (DTR,RTS...) will be asserted.
\end_layout

\begin_layout Subsection
Option Details
\end_layout

\begin_layout Subsubsection
\begin_inset Index
status collapsed

\begin_layout Plain Layout
-p
\end_layout

\end_inset

-p <Serial port #/Path> 
\end_layout

\begin_layout Standard
This specifies the serial port number or path.
 If the -v option returns a list of ports you can use the slot number from
 that list as the port #.
 If not you may use the device path i.e.
 /dev/ttyS0
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = 
\begin_inset Quotes eld
\end_inset

1
\begin_inset Quotes erd
\end_inset


\end_layout

\begin_layout Subsubsection
\begin_inset Index
status collapsed

\begin_layout Plain Layout
-baud
\end_layout

\end_inset

-baud <Baud Rate> 
\end_layout

\begin_layout Standard
This would set the baud rate for the port.
 Use a valid rate since there is no checking at the program level of this
 value, the underlying OS might check but try to use a 
\emph on
standard
\emph default
 value.
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = 38,400 baud
\end_layout

\begin_layout Subsubsection
\begin_inset Index
status collapsed

\begin_layout Plain Layout
-tcp
\begin_inset ERT
status collapsed

\begin_layout Plain Layout


\backslash
_
\end_layout

\end_inset

p
\end_layout

\end_inset

-tcp_p <TCP/IP Port #> 
\end_layout

\begin_layout Standard
This is the TCP/IP side of the connection.
 It specifies the port TERMS will open on its machine.
 TCP/IP connections would be made to <TERMS machine>:port#.
 This can be any value from 1-65535 but don't use ports already in use by
 your machine or in the case of UNIX non-admin users, they cannot use any
 port less than 1024.
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = 6000
\end_layout

\begin_layout Subsubsection
\begin_inset Index
status collapsed

\begin_layout Plain Layout
-c
\end_layout

\end_inset

-c <Lua script> 
\end_layout

\begin_layout Standard
The name following this is a Lua script that can modify the behavior of
 TERMS.
 See 
\begin_inset CommandInset ref
LatexCommand ref
reference "SCRIPT_USE"

\end_inset


\end_layout

\begin_layout Subsubsection
\begin_inset Index
status collapsed

\begin_layout Plain Layout
-v
\end_layout

\end_inset

-v 
\end_layout

\begin_layout Standard
When present TERMS will print the following and NOT run
\end_layout

\begin_layout LyX-Code

\size footnotesize
TERMS TCP/IP <=> SER SERVER [Dec  2 2005 10:29:20]
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size footnotesize
TERMS - TCP -> SERIAL SERVER Version Dec  2 2005 10:29:20
\end_layout

\begin_layout LyX-Code

\size footnotesize
SYNTAX: TERMS   [-p <serial port #>]
\end_layout

\begin_layout LyX-Code

\size footnotesize
                [-baud <Baud rate>]
\end_layout

\begin_layout LyX-Code

\size footnotesize
                [-tcp_p <Port #>]
\end_layout

\begin_layout LyX-Code

\size footnotesize
                [-c <Lua connect Script>]
\end_layout

\begin_layout LyX-Code

\size footnotesize
                [-e]
\end_layout

\begin_layout LyX-Code

\size footnotesize
                [-v]
\end_layout

\begin_layout LyX-Code

\size footnotesize
    -p     <Serial port #>     DEFAULT = 1
\end_layout

\begin_layout LyX-Code

\size footnotesize
    -baud  <Rate>          DEFAULT = 38400
\end_layout

\begin_layout LyX-Code

\size footnotesize
    -tcp_p <TCP Port #>    DEFAULT = 6000
\end_layout

\begin_layout LyX-Code

\size footnotesize
    -c     <Lua script>    DEFAULT = NONE
\end_layout

\begin_layout LyX-Code

\size footnotesize
    -e Eat echo characters DEFAULT = Allow echo
\end_layout

\begin_layout LyX-Code

\size footnotesize
    -v     Show this message and return
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size footnotesize
----- PORT LIST ----
\end_layout

\begin_layout LyX-Code

\size footnotesize
[1] [cu.usbserial0] [/dev/cu.usbserial0]
\end_layout

\begin_layout LyX-Code

\size footnotesize
[2] [cu.Bluetooth-PDA-Sync][/dev/cu.Bluetooth-PDA-Sync]
\end_layout

\begin_layout LyX-Code

\size footnotesize
--------------------
\end_layout

\begin_layout Section
Terminal Server Use
\end_layout

\begin_layout Subsection
Introduction
\end_layout

\begin_layout Standard
TERMS attaches a serial port to a TCP/IP port and allows communication between
 them.
 This has numerous uses allowing the local serial port to be used by any
 machine on the network (or on the Internet).
 The connecting program can be a special purpose system designed to talk
 to the hardware attached to the serial port or it can be 
\series bold
telnet
\series default
 used for user communication over the serial port.
\end_layout

\begin_layout Subsection
telnet Use
\end_layout

\begin_layout Standard
This is one of the more interesting uses of TERMS.
 You can connect to the TERMS serviced serial port with telnet and in effect
 have serial terminal.
 
\series bold
telnet
\series default
 is a good client for this since it supports the VT100 command set.
\end_layout

\begin_layout Standard
For very nice VT100 emulation you can use a script like this run TERMS and
 telnet in the same window.
 
\end_layout

\begin_layout LyX-Code
#!/bin/bash
\end_layout

\begin_layout LyX-Code
#----- Start up TERMINAL session in a window
\end_layout

\begin_layout LyX-Code
# Syntax: myterm <ser port> <tcpip port>
\end_layout

\begin_layout LyX-Code
# Uses Default baud rate 38400# You can add more parameters or set them
\end_layout

\begin_layout LyX-Code
# to fixed values
\end_layout

\begin_layout LyX-Code
# The TCP/IP port set value is present so I can run
\end_layout

\begin_layout LyX-Code
# multiple terminals on multiple ports and not have them
\end_layout

\begin_layout LyX-Code
# try for the same IP port
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
TERMS -p $1 -tcp_p $2 &
\end_layout

\begin_layout LyX-Code
# Wait for TERMS to run
\end_layout

\begin_layout LyX-Code
sleep 2 
\end_layout

\begin_layout LyX-Code
# Now run TELNET to that port
\end_layout

\begin_layout LyX-Code
telnet localhost $2
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
# Kill that running TERMS service
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
kill %+
\end_layout

\begin_layout Standard
The script starts TERMS in the background with the default baud rate on
 a user specified IP port using a user specified serial port.
 This script is only a suggestion, you can put in any sorts of values you
 need for your particular use.
 The result of this is a single window with TERMS running the background
 with 
\series bold
telnet
\series default
 acting as a VT100 terminal.
 When you exit telnet the kill%+ acts to kill the TERMS which is still running.
\end_layout

\begin_layout Subsection
telnet Initialization
\end_layout

\begin_layout Standard
In some cases to get correct appearence when typing or receiving characters
 you will need to set 
\series bold
telnet
\series default
 for binary transfer.
 In that case you can modify the .telnetrc file in your local directory to
 be as follows:
\end_layout

\begin_layout LyX-Code
#
\end_layout

\begin_layout LyX-Code
#----- TELNET STARTUP FILE ----
\end_layout

\begin_layout LyX-Code
# Binary/Character mode for DMU's
\end_layout

\begin_layout LyX-Code
# Line/non-binary for LC servers
\end_layout

\begin_layout LyX-Code
#
\end_layout

\begin_layout LyX-Code
DEFAULT mode character
\end_layout

\begin_layout LyX-Code
DEFAULT set binary
\end_layout

\begin_layout Standard
You can also issue these commands to 
\series bold
telnet
\series default
 by escaping the terminal mode and getting to the > prompt then typing:
\end_layout

\begin_layout LyX-Code
mode character
\end_layout

\begin_layout LyX-Code
set binary
\end_layout

\begin_layout Section
\begin_inset CommandInset label
LatexCommand label
name "SCRIPT_USE"

\end_inset

Lua Script Use
\end_layout

\begin_layout Subsection
Scripting
\end_layout

\begin_layout Standard
Terminal servers by their nature need some customization so their behavior
 can change to suit the wide variety of serial devices that can be connected.
 Lua the scripting language allows TERMS controled by the script, then the
 actions it takes can be customized.
\end_layout

\begin_layout Standard
The mechanism for customization is to have TERMS call specific Lua functions
 on events.
 That is when TERMS starts up it calls the Lua function ON_START(), when
 a client connnects, it calls ON_CONN() and so on.
 If these functions are not present the program just keeps on going.
 Thus to customize the program you only need write functions to handle actions
 of importance any unneeded functions can just be skipped.
\end_layout

\begin_layout Standard
Information on the Lua language can be found here: Lua language site 
\begin_inset Flex URL
status collapsed

\begin_layout Plain Layout

www.Lua.org
\end_layout

\end_inset

 and this book 
\begin_inset CommandInset citation
LatexCommand cite
key "LuaBook"

\end_inset

.
 
\end_layout

\begin_layout Subsection
Lua Event Functions
\end_layout

\begin_layout Standard
The state leading to the function call will be detailed below, see 
\begin_inset CommandInset ref
LatexCommand ref
reference "Extensions"

\end_inset

 for further information on what functions are available.
\end_layout

\begin_layout Subsubsection
ON_START()
\end_layout

\begin_layout Standard
This function is called as TERMS is starting but before it has begun monitoring
 for TCP/IP connection.
 
\end_layout

\begin_layout Subsubsection
ON_CONN()
\end_layout

\begin_layout Standard
This function is called when a new TCP/IP connection is accepted but before
 TERMS enters into the terminal server loop, or the connected state.
\end_layout

\begin_layout Subsubsection
ON_DROP() 
\end_layout

\begin_layout Standard
This function is called after the TCP/IP connection is dropped and before
 TERMS enters the idle loop.
\end_layout

\begin_layout Subsubsection
ON_CTS()
\end_layout

\begin_layout Standard
This function is called when CTS changes state (there are functions to see
 the current state see 
\begin_inset CommandInset ref
LatexCommand ref
reference "Extensions"

\end_inset

).
\end_layout

\begin_layout Subsubsection
ON_PERIODIC()
\end_layout

\begin_layout Standard
This function is called every second TERMS is running (in both idle and
 connected states)
\end_layout

\begin_layout Section
\begin_inset CommandInset label
LatexCommand label
name "Extensions"

\end_inset

Lua Extensions
\end_layout

\begin_layout Standard
There are libraries added to this embedded Lua to supply the specialized
 functions for TERMS operation.
 There are three libraries added, timer, serial and net.
 
\end_layout

\begin_layout Subsection
timer - Library
\end_layout

\begin_layout Subsubsection
Open a timer timer.topen()
\begin_inset Index
status collapsed

\begin_layout Plain Layout
timer.topen()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function is used to open a millisecond timer for delay loops or other
 timing operations.
 There can be any number of these timers created during a run of TERMS.
\end_layout

\begin_layout LyX-Code
t = timer.topen()
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
t
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Handle to created timer struct or nil if failure
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Close a timer timer.tclose(t)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
timer.tclose()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function is used to free the memory used by a timer after use.
\end_layout

\begin_layout LyX-Code
timer.tclose(t)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
t
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
This is the handle of a timer, the memory will be freed 
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
NONE
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Restart a timer timer.tstart(t)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
timer.topen()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function is used to zero a timer.
 For example after a delay has elapsed then start can be called and the
 delay re-run.
\end_layout

\begin_layout LyX-Code
timer.tstart(t)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
t
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
This timer will be re-started after this call
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
NONE
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Check a timer for done timer.tdone(t,delay)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
timer.tdone()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will return 1 when the timer passes the delay time.
 Up to that time it will return nil.
 
\end_layout

\begin_layout LyX-Code
done = timer.tdone(t,delay)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="4" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
t
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
This is the handle of a timer 
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
delay
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Delay time in ms
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
done
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
nil till the timer passes the delay time and 1 after
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsection
ser - Library
\end_layout

\begin_layout Standard
This libary is used to access the open serial port of TERMS.
 It will be used to send or recieve data.
 In addition it can monitor and change the other serial control lines (DTR,CTS)
\end_layout

\begin_layout Subsubsection
Write data to serial port ser.swrite(data)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
ser.swrite()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will send data to the open serial port.
\end_layout

\begin_layout LyX-Code
count = ser.swrite(data)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
data
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
This string of data will be sent to the serial port
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
count
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
# of bytes sent
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Read data from serial port ser.sread(len)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
ser.sread()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will read data from the serial port.
 This is a blocking read.
\end_layout

\begin_layout LyX-Code
data = ser.sread(len)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
len
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
# Bytes of data to read
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
data
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Data as read from the port
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Serial data status ser.sstat()
\begin_inset Index
status collapsed

\begin_layout Plain Layout
ser.sstat()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will return the count of available serial data bytes.
\end_layout

\begin_layout LyX-Code
count = ser.sstat()
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
count
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
# Bytes waiting to be read from serial port
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Read serial control lines ser.sgetstate()
\begin_inset Index
status collapsed

\begin_layout Plain Layout
ser.sgetstate()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will return the status of the serial port status lines (CTS,RTS....).
 At present it only returns status of CTS
\end_layout

\begin_layout LyX-Code
cts[,rts....] = ser.sgetstate()
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
cts
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
1 if CTS asserted, 0 if not
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Set serial control lines ser.ssetstate(dtr)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
ser.sstat()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will set the state of the serial port status lines (DTR,RTS...).
 At present it only sets DTR
\end_layout

\begin_layout LyX-Code
ser.ssetstate(dtr)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
dtr
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Desired state of DTR, 1 = asserted, 0 = not
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
NONE
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsection
net - Library
\end_layout

\begin_layout Standard
This libary is used to access the open TCP/IP port of TERMS.
 It will be used to send or recieve data.
 In addition it can monitor the connection status.
\end_layout

\begin_layout Subsubsection
Write data to TCP/IP port net.swrite(data)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
net.swrite()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will send data to the open TCP/IP port.
\end_layout

\begin_layout LyX-Code
count = net.swrite(data)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
data
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
This string of data will be sent to the TCP/IP port
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
count
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
# of bytes sent
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Read data from TCP/IP port net.sread(len)
\begin_inset Index
status collapsed

\begin_layout Plain Layout
net.sread()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will read data from the TCP/IP port.
 It will read up to len bytes and returns.
\end_layout

\begin_layout LyX-Code
data = net.sread(len)
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
len
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
# Bytes of data to read
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
data
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
Data as read from the port
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Control TCP/IP connection net.drop()
\begin_inset Index
status collapsed

\begin_layout Plain Layout
net.drop()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
When called this will drop the TCP/IP connection
\end_layout

\begin_layout LyX-Code
net.drop()
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
NONE
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Subsubsection
Read TCP/IP connection status net.cstat()
\begin_inset Index
status collapsed

\begin_layout Plain Layout
ser.cstat()
\end_layout

\end_inset


\end_layout

\begin_layout Standard
This function will return the status of the TCP/IP connection, 1 if connected
 and nil if idle
\end_layout

\begin_layout LyX-Code
status = net.cstat()
\end_layout

\begin_layout LyX-Code
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="3">
<features>
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<column alignment="center" valignment="top" width="0sp">
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
INPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
NAME
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
USE
\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
-
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\end_layout

\end_inset
</cell>
</row>
<row>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout

\series bold
OUTPUT
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
status
\end_layout

\end_inset
</cell>
<cell alignment="center" valignment="top" topline="true" bottomline="true" leftline="true" rightline="true" usebox="none">
\begin_inset Text

\begin_layout Plain Layout
1 if connection up, nil if idle
\end_layout

\end_inset
</cell>
</row>
</lyxtabular>

\end_inset


\end_layout

\begin_layout Section
Example Script
\end_layout

\begin_layout Standard
This is a simple example script that uses all the TERMS Lua functions.
 It will show a message on start, toggle DTR on connect, drop DTR on drop,
 show the state of CTS and put out periodic messages while a client is connected
 to the port.
\end_layout

\begin_layout LyX-Code

\size scriptsize
--------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- function ON_START()    - Run at TERMS startup
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- INPUT:   NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- OUTPUT:  NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
---------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
function ON_START()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local out
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
   print()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print("-------------------------------------")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   out = string.format("**** TERMS SERVER UP *****")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print(out)
\end_layout

\begin_layout LyX-Code

\size scriptsize
   out = string.format("[%s]
\backslash
n[%s]",
\end_layout

\begin_layout LyX-Code

\size scriptsize
                           "Lua 5.0.2",                            
\end_layout

\begin_layout LyX-Code

\size scriptsize
            "R.
 Ierusalimschy, L.
 H.
 de Figueiredo & W.
 Celes")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print(out)
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print("-------------------------------------")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print()
\end_layout

\begin_layout LyX-Code

\size scriptsize
end
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
--------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- function ON_CONN()    - Run at network connection startup
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- INPUT:   NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- OUTPUT:  NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--          This version will toggle DTR on connection and
\end_layout

\begin_layout LyX-Code

\size scriptsize
--          send a crcr out of the serial port
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
---------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
function ON_CONN()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local out
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local t
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local count
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
   out = string.format("Connection UP
\backslash
n")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print(out)
\end_layout

\begin_layout LyX-Code

\size scriptsize
   net.swrite(out)
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
   -- Now Lower DTR hold for 2 seconds then raise
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
   print("Togging DTR")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   ser.ssetstate( 0 )
\end_layout

\begin_layout LyX-Code

\size scriptsize
   t = timer.topen()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   if( t ~= nil )
\end_layout

\begin_layout LyX-Code

\size scriptsize
   then
\end_layout

\begin_layout LyX-Code

\size scriptsize
       while( timer.tdone(t,2000) == nil )
\end_layout

\begin_layout LyX-Code

\size scriptsize
       do
\end_layout

\begin_layout LyX-Code

\size scriptsize
          out = nil
\end_layout

\begin_layout LyX-Code

\size scriptsize
       end
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
       timer.tclose(t)
\end_layout

\begin_layout LyX-Code

\size scriptsize
   end
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print("DTR ASSERTED")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   ser.ssetstate( 1 )
\end_layout

\begin_layout LyX-Code

\size scriptsize
   ser.swrite("
\backslash
r
\backslash
n")
\end_layout

\begin_layout LyX-Code

\size scriptsize
end
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
--------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- function ON_DROP()    - Run at network drop
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- INPUT:   NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- OUTPUT:  NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--          This will lower DTR on exit which will cause the connected
\end_layout

\begin_layout LyX-Code

\size scriptsize
--          unit to logout
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
---------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
function ON_DROP()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local out
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
   out = string.format("Connection DOWN")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print(out)
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print("Lower DTR")
\end_layout

\begin_layout LyX-Code

\size scriptsize
   ser.ssetstate( 0 )
\end_layout

\begin_layout LyX-Code

\size scriptsize
end
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
--------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- function ON_CTS()    - Run at CTS change
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- INPUT:   NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- OUTPUT:  NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
---------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
function ON_CTS()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local out
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local val
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
   val = ser.sgetstate()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   out = string.format("CTS = [%d]",val)
\end_layout

\begin_layout LyX-Code

\size scriptsize
   print(out)
\end_layout

\begin_layout LyX-Code

\size scriptsize
end
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
-- These globals used by ON_PERIODIC
\end_layout

\begin_layout LyX-Code

\size scriptsize
count = 0
\end_layout

\begin_layout LyX-Code

\size scriptsize
nettime = 0
\end_layout

\begin_layout LyX-Code

\size scriptsize
--------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- function ON_PERIODIC()    - Run every second
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- INPUT:   NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
-- OUTPUT:  NONE
\end_layout

\begin_layout LyX-Code

\size scriptsize
--          Print connection status and time
\end_layout

\begin_layout LyX-Code

\size scriptsize
--
\end_layout

\begin_layout LyX-Code

\size scriptsize
---------------------------------------------------------------------
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
function ON_PERIODIC()
\end_layout

\begin_layout LyX-Code

\size scriptsize
   local out
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\size scriptsize
   count = count + 1
\end_layout

\begin_layout LyX-Code

\size scriptsize
   if( count > 5 )
\end_layout

\begin_layout LyX-Code

\size scriptsize
   then
\end_layout

\begin_layout LyX-Code

\size scriptsize
       if( net.cstat() )
\end_layout

\begin_layout LyX-Code

\size scriptsize
       then
\end_layout

\begin_layout LyX-Code

\size scriptsize
           out = string.format("Periodic Message [NET UP %d sec]",      
                                                nettime)
\end_layout

\begin_layout LyX-Code

\size scriptsize
           nettime = nettime + 5
\end_layout

\begin_layout LyX-Code

\size scriptsize
       else
\end_layout

\begin_layout LyX-Code

\size scriptsize
           out = string.format("Periodic Message")
\end_layout

\begin_layout LyX-Code

\size scriptsize
           nettime = 0
\end_layout

\begin_layout LyX-Code

\size scriptsize
       end
\end_layout

\begin_layout LyX-Code

\size scriptsize
              
\end_layout

\begin_layout LyX-Code

\size scriptsize
       print(out)
\end_layout

\begin_layout LyX-Code

\size scriptsize
       count = 0
\end_layout

\begin_layout LyX-Code

\size scriptsize
   end
\end_layout

\begin_layout LyX-Code

\size scriptsize
end
\end_layout

\begin_layout Standard
\begin_inset CommandInset index_print
LatexCommand printindex

\end_inset


\end_layout

\begin_layout Standard
\begin_inset CommandInset bibtex
LatexCommand bibtex
bibfiles "/Users/jschimpf/Public/TSANIXII/DOCS/tg"
options "bibtotoc,ieeetr"

\end_inset


\end_layout

\end_body
\end_document

Added Docs/TERMSTR.pdf.

cannot compute difference between binary files

Added Docs/refman-5.0.pdf.

cannot compute difference between binary files

Added SERIAL/Linux/linserial.c.





































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2005. Pandora Products. All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         LINSERIAL		- Serial Support on a Linux system
*
*  Description:         This will list,open,setup and close serial ports
*						on Linux
*
*  Author:              Jim Schimpf
*
*  Revision History:	1 Dec 2005 Initial version
*
*		USER-API	PORT_LIST *ListPorts()
*					void ListPortsFree( PORT_LIST *l);
*					PORT_HANDLE *OpenPort( int psn,
*											PORT_LIST *e,
*											int baud,
*											int stop,
*											int parity);
*					ClosePort( PORT_HANDLE *h );
*					int StatPort( PORT_HANDLE *h );
*					int WritePort( char *data,int size,PORT_HANDLE *h );
*					int ReadPort( char *data,int size,PORT_HANDLE *h );
*/
//************************************************************************

#include "linserial.h"

// **** LOCAL FUNCTIONS ***

static int GetPortState( PORT_HANDLE *h );
static int SetPortState( int state,PORT_HANDLE *h );

#pragma mark -- PORT MGMT API --

/****************************************************************
*
*  PORT_LIST *ListPorts()	- Get a list of SERIAL RS-232 ports
*
*	INPUT:NONE
*
*	OUTPUT:	NULL
*	This is not supported in Linux now so just return NULL
*
*****************************************************************/

PORT_LIST *ListPorts(void)
{
	PORT_LIST *base = NULL;
	
	return( base );
}

/****************************************************************
*
*  void FreePorts(PORT_LIST *base ) - Free port list
*
*	INPUT:	base	- Port list
*
*	OUTPUT:	NONE
*
*****************************************************************/

void FreePorts(PORT_LIST *base )
{
	PORT_LIST *npl;
	
	// (1) Loop through ports and free as seen
	
	while( base != NULL )
	{
		// (2) Save the next for later
		
		npl = base->next;
		
		// (3) Free up the parts
		
		if( base->path != NULL )
			MEMFREE( base->path );
		if( base->name != NULL )
			MEMFREE( base->name );
			
		// (4) Free the main part and move to next
		
		MEMFREE( base );
		base = npl;
	}
}

#pragma mark -- PORT OPEN/CLOSE API --

/****************************************************************
*
*  PORT_HANDLE *OpenPort( int psn,PORT_LIST *p,
*						int baud,
*						PORT_STOP stop,
*						PORT_PARITY parity)		- Open a port
*
*	INPUT:	psn		- Psn in list (base = 1)
*			p		- PORT_LIST 
*			baud	- Baud rate desired
*			stop	- # Stop bits (1,2)
*			parity	- NONE/ODD/EVEN
*
*	OUTPUT: Open file handle
*			NULL if failed
*
*****************************************************************/

PORT_HANDLE *OpenPort( int psn,
						PORT_LIST *base,
						int baud,
						SER_PORT_STOP stop,
						SER_PORT_PARITY parity)
{
	PORT_HANDLE *h;
	int i;
	int error;
	PORT_LIST *p;
	
	// (0) Find the slot in the port list
	
	for( i=0, p = base; i<psn-1 && p != NULL ; i++ )
	{
		p = p->next;
	}
	
	if( p == NULL )
		return( NULL );
	
	// (1) Create the handle
	
	h = NEW_PORT_HANDLE;
	if( h == NULL )
	{
		return( NULL );		// FAILURE
	}
	h->fd = -1;				// Set bad descriptor
	
	// (1a) Fill the name and path fields
	
	i = strlen(p->path);
	h->path = (char *)MEMALLOC( i + 1 );
	if( h->path == NULL )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	strcpy(h->path,p->path);
	
	i = strlen( p->name );
	h->name = (char *)MEMALLOC( i + 1 );
	if( h->name == NULL )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	strcpy(h->name,p->name);
	
	// (2) Try to open the port
	
	h->fd = open(p->path, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if( h->fd == -1 )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	ioctl(h->fd, TIOCEXCL);	// Set for exclusive OPEN
	
	// (2a) Get current values fron port
	// Save originals and copy into run area
    if (tcgetattr(h->fd, &(h->orig)) == -1)
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	memcpy(&(h->run),&(h->orig),sizeof(struct termios));
	
    // (3) Set options to baud rate, 8 bits, parity, & size no flow
    // Init flags then set
	
	//*********** CONTROL FLAG SET
    h->run.c_cflag = 0;
	
	if( parity == SER_PARITY_NONE )
		h->run.c_cflag |= CS8;			// 8 Bit words
	else
	{
		h->run.c_cflag |= CS7;			// 7 Bit words with parity
		h->run.c_cflag |= PARENB;		// Parity enable
		if( parity == SER_PARITY_ODD )
			h->run.c_cflag |= PARODD;	// ODD parity
	}
		
	if( stop == SER_STOP_TWO )
		h->run.c_cflag |= CSTOPB;		// Two stop bits (1 by default)
		
    h->run.c_cflag |= CREAD;		// Enable input
    h->run.c_cflag |= CLOCAL;		// Ignore modem cntl lines
    
	//************* INPUT FLAGS SET
    h->run.c_iflag = 0;
    h->run.c_iflag |= IGNBRK;
	if( parity != SER_PARITY_NONE )
		h->run.c_iflag |= INPCK;	// Parity check
    
	//************* LINE FLAGS SET
    h->run.c_lflag = 0;				// No echo input
    
	//************* OPTION CHARACTERS
    for( i=0; i<NCCS; i++ )			// REF:JS12052003 Change to clear all option chars
        h->run.c_cc[i] = 0;
        
    h->run.c_cc[VMIN] = 0;			// Non blocking input
    h->run.c_cc[VTIME] = 0;			// REF:JS12052003 Set to not wait
									// for either min char or time

    printf("Options set now: CFLAG [%X] IFLAG [%X] OFLAG [%X]\n",
                    (int)h->run.c_cflag,
                    (int)h->run.c_iflag,
                    (int)h->run.c_oflag);
    // (4) Set the baud rates, if you try this in reverse order
    // then the c_flag -> 0 and will wipe out the baud rates
    // (i.e. baudrate = 0)
    
	error = cfsetospeed( &(h->run),baud );
	error = cfsetispeed( &(h->run),baud );

    // (5) Cause the new options to take effect immediately.
    if (tcsetattr(h->fd, TCSANOW, &(h->run)) == -1)
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	
    // (6) Print the new input and output baud rates & return the results
    
    printf("Input baud rate changed to %d\n", (int) cfgetispeed(&(h->run)));
    printf("Output baud rate changed to %d\n", (int) cfgetospeed(&(h->run)));

	return( h );
}

/****************************************************************
*
*  void ClosePort( PORT_HANDLE *h )	- Close the port
*
*	INPUT:	h	- Close this open port
*
*	OUTPUT: NONE
*
*****************************************************************/

void ClosePort( PORT_HANDLE *h )
{
	// (1) C heck for valid handle
	
	if( h != NULL )
	{
		// (2) If descriptor valid then reset port back to original
		
		if( h->fd != -1 )
		{
			tcsetattr(h->fd, TCSANOW, &(h->orig));
			close(h->fd);
		}
		
		// (3) Free up the allocated fields
		
		if( h->path != NULL )
			MEMFREE( h->path );
		if( h->name != NULL )
			MEMFREE( h->name );
		
		// (4) Free the handle
		
		MEMFREE( h );
	}
}
#pragma mark -- PORT I/O API --

/***********************************************************************
*
* int WritePort( char *buffer,int size,PORT_HANDLE *h) - Write to a port
*
*	INPUT:	buffer	- Buffer to send
*			size	- # Bytes to send
*			h		- To this port
*
*	OUTPUT:	# bytes written
*
************************************************************************/

int WritePort( char *buffer,int size,PORT_HANDLE *h)
{
	int rtn = -1;
	
	// (1) Good handle ?
	
	if( h != NULL )
	{
		// (2) Ok, so do I/O 
		
		rtn = write(h->fd,buffer,size );
	}
	
	return( rtn );
}

/***********************************************************************
*
* int ReadPort( char *buffer,int size,PORT_HANDLE *h) - Read from a port
*
*	INPUT:	buffer	- Buffer to read
*			size	- # Bytes to read
*			h		- From this port
*
*	OUTPUT:	# bytes read
*
************************************************************************/

int ReadPort( char *buffer, int size,PORT_HANDLE *h )
{
	int rtn = -1;
	
	// (1) Good handle ?
	
	if( h != NULL )
	{
		// (2) Ok, so do I/O 
		
		rtn = read(h->fd,buffer,size );
	}
	
	return( rtn );
}

#pragma mark -- PORT MISC --
/***********************************************************************
*
* int CTSPort( PORT_HANDLE *h ) - Return CTS state
*
*	INPUT: h	- Port handle
*
*	OUTPUT:	1 = CTS asserted, 0 - CTS not asserted
*
************************************************************************/

int CTSPort( PORT_HANDLE *h )
{
	int state = GetPortState( h );		// Get current state
	int cts;
	
	// Extract RTS state
	
	if( state & TIOCM_CTS )
	{
		cts = 1;
	}
	else
	{
		cts = 0;
	}
	
	return( cts );
}

/***********************************************************************
*
* void DTRPort( int flag,PORT_HANDLE *h) - Set DTR state
*
*	INPUT:	flag	- 1 -> Assert DTR, 0 Remove DTR
*			h		- Port to work on
*
*	OUTPUT:	NONE
*
************************************************************************/

void DTRPort( int dtr,PORT_HANDLE *h)
{
	int state = GetPortState( h );		// Get current state
	
	// (1) Set or CLEAR
	
	if( dtr )
	{
		state = state | TIOCM_DTR;		// Assert DTR
	}
	else
	{
		state = state & ~TIOCM_DTR;		// Clear DTR
	}
	
	SetPortState( state,h );
}

#pragma mark -- Support (INTERNAL) --

/***********************************************************************
*
* PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl) - Add names into struct
*
*	INPUT: 	portstr		- Port path string
*			pl			- Port list struct to have names added
*						NOTE: Struct NEW so all pointers NULL
*
*	OUTPUT:	pl	- Pointer to original pl filled out if OK
*			NULL if failure
*
************************************************************************/

static PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl)
{
	int len;
	char *ptr;
	
	// (1) Get the length and put in the whole path
	
	len = strlen(portstr);
	pl->path = (char *)MEMALLOC(len+1);
	if( pl->path == NULL )
	{
		MEMFREE( pl );			// FAILURE
		return( NULL );
	}
	strcpy(pl->path,portstr);
	
	// (2) Now walk back through the portstr and find the first "/"
	// from there to the end is the name of the port
	
	ptr = portstr;
	ptr += len;			// Move to the end of the string
	// Scan backwards through the string
	for( ; ptr >= portstr; ptr-- )
	{
		if( *ptr == '/' )
			break;				// We have found the left end of the name
								// Actually 1 less than that see below
	}
	
	ptr++;						// Move to start of name
								// Now build the name holder
	len = strlen(ptr);
	pl->name = (char *)MEMALLOC(len+1);
	if( pl->name == NULL )
	{
		MEMFREE(pl->path);	// FAILURE
		MEMFREE(pl);
		return( NULL );
	}
	strcpy(pl->name,ptr);
	
	// (3) All done return filled out struct
	
	return( pl );
}


/***********************************************************************
*
* int GetPortState(PORT_HANDLE *h)	- Get state value from tty
*
*	INPUT: 	xh		- Handle to open serial port
*
*	OUTPUT:	Terminal state as per bits in sys/ioctl.h
*			Return 0 if bad state
*
************************************************************************/

static int GetPortState( PORT_HANDLE *h )
{
    int state = 0;
	int val;
	
	// (2) Read state
	
	val = ioctl(h->fd,TIOCMGET,&state);
	if( val < 0 )
	{
		state = 0;		// ERROR
	}
	return( state );
}

/***********************************************************************
*
* int SetPortState(int state, PORT_HANDLE *h)	- Set state value for tty
*
*	INPUT:  state   - Set TTY state to this
*			xh		- Handle to open serial port
*
*	OUTPUT:	Return 1 if OK, 0 if fail
*
************************************************************************/

static int SetPortState( int state,PORT_HANDLE *h )
{
    int rtnval = 0;
	int val;
	
	// (1) Is it valid ?
	
	// (2) Set state
	
	val = ioctl(h->fd,TIOCMSET,&state);
	if( val >= 0 )
	{
		rtnval = 1;		// SUCCESS
	}
	return( rtnval );
}

Added SERIAL/Linux/linserial.h.































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2005. Pandora Products. All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         LINSERIAL		- Serial Support on a Linux system
*
*  Description:         This will list,open,setup and close serial ports
*						on Linux
*
*  Author:              Jim Schimpf
*
*  Revision History:	1 Dec 2005 Initial version
*
*		USER-API	PORT_LIST *ListPorts()				- NOP here
*					void ListPortsFree( PORT_LIST *l);
*					PORT_HANDLE *OpenPort( PORT_LIST *e,
*											int baud,
*											int stop,
*											int parity);
*					ClosePort( PORT_HANDLE *h );
*					int StatPort( PORT_HANDLE *h );
*					int WritePort( char *data,int size,PORT_HANDLE *h );
*					int ReadPort( char *data,int size,PORT_HANDLE *h );
*/
//************************************************************************

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <paths.h>
#include <termios.h>
#include <sysexits.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include "tgtypes.h"

#ifndef LINSERIAL_H
#define LINSERIAL_H	1

#pragma mark -- Structures --

typedef struct sdummy {
						struct sdummy *next;
						char *path;				// Path of port
						char *name;				// Just the name part of the port
					} PORT_LIST;
					
#define NEW_PORT_LIST		((PORT_LIST *)MEMALLOC(sizeof(PORT_LIST)))

// Parity & Stop bit defs

typedef enum {
				SER_PARITY_NONE,
				SER_PARITY_EVEN,
				SER_PARITY_ODD
			} SER_PORT_PARITY;
			
typedef enum {
				SER_STOP_ONE,
				SER_STOP_TWO
			} SER_PORT_STOP;

typedef struct {
					char *path;
					char *name;
					
					// PORT DATA
					struct termios orig;	// Original values
					struct termios run;		// Run values
					int fd;					// Port descriptor
					
				} PORT_HANDLE;
				
#define NEW_PORT_HANDLE		((PORT_HANDLE *)MEMALLOC(sizeof(PORT_HANDLE)))

#pragma mark -- API --

// **** PORT DETERMINATION ****
PORT_LIST *ListPorts(void);
void FreePorts(PORT_LIST *base );

// **** PORT OPEN/CLOSE

PORT_HANDLE *OpenPort( int psn,
						PORT_LIST *p,
						int baud,
						SER_PORT_STOP stop,
						SER_PORT_PARITY parity);
void ClosePort( PORT_HANDLE *h );

// **** PORT I/O

int StatPort( PORT_HANDLE *h );
int WritePort( char *buffer,int size,PORT_HANDLE *h);
int ReadPort( char *buffer, int size,PORT_HANDLE *h );

// *** PORT MISC

int CTSPort( PORT_HANDLE *h );				// Read CTS
void DTRPort( int flag,PORT_HANDLE *h);		// Set DTR

#endif

Added SERIAL/OSX/bsdserial.c.









































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2005. Pandora Products. All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         BSDSERIAL		- Serial Support on a BSD system
*
*  Description:         This will list,open,setup and close serial ports
*						on BSD
*
*  Author:              Jim Schimpf
*
*  Revision History:	21 Jan 2005 Initial version
*						 2 Dec 2005 Convert the open to find the value in the
*									port list & add DTR, CTS functions
*						16-Apr-2009	Add ability to use modem ports
*						17 Apr 2009 Add working StatPort() 
*
*		USER-API	PORT_LIST *ListPorts()
*					void ListPortsFree( PORT_LIST *l);
*					PORT_HANDLE *OpenPort( int psn,
*											PORT_LIST *e,
*											int baud,
*											int stop,
*											int parity);
*					ClosePort( PORT_HANDLE *h );
*					int StatPort( PORT_HANDLE *h );
*					int WritePort( char *data,int size,PORT_HANDLE *h );
*					int ReadPort( char *data,int size,PORT_HANDLE *h );
*/
//************************************************************************

#include "bsdserial.h"

// **** LOCAL FUNCTIONS ***

static kern_return_t FindPorts(bool modem_flag,io_iterator_t *matchingServices);
static kern_return_t GetPortPath(int port,
								io_iterator_t serialPortIterator, 
								char *bsdPath, 
								CFIndex maxPathSize);
static PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl);
static int GetPortState( PORT_HANDLE *h );
static int SetPortState( int state,PORT_HANDLE *h );

#pragma mark -- PORT MGMT API --

/****************************************************************
*
*  PORT_LIST *ListPorts(int modems)	- Get a list of SERIAL RS-232 ports
*
*	INPUT:modems	- If <> 0 then look for modems too
*
*	OUTPUT:	Linked list of port data
*			NULL if none
*
*****************************************************************/

PORT_LIST *ListPorts(int modems)
{
	char portstr[256];
	io_iterator_t matchingServices;
	int pcount = 0;
	PORT_LIST *base = NULL;
	PORT_LIST *pl;
	PORT_LIST *last = NULL;
	
	// (1) Now loop through available ports and build a list
	
	while( 1 )
	{
		// (2) Build an iterator for our list of ports
		
		if( FindPorts( modems,&matchingServices ) != KERN_SUCCESS )
		{
			break;		// Failure - no ports
		}

		if( GetPortPath(pcount,
					matchingServices,
					portstr,
					sizeof(portstr)) != KERN_SUCCESS )
		{
			break;			// Done....
		}
		
		// (2a) We have a port here so build a PORT_LIST from the 
		// string we just received
		
		pl = NEW_PORT_LIST;
		if( pl == NULL )
			break;				// FAILURE !!!
			
		pl = add_port_names(portstr,pl);
		if( pl == NULL )
			break;				// FAILURE
			
		// (3) Now add the element to the end of the list
		// Two cases:
		//		base == NULL	- First element just replace
		//		base != NULL	- Just add after last
		
		if( base == NULL )
		{
			base = pl;
			last = pl;
		}
		else
		{
			last->next = pl;
			last = pl;
		}
		pcount = pcount + 1;
	}
	
	return( base );
}

/****************************************************************
*
*  void FreePorts(PORT_LIST *base ) - Free port list
*
*	INPUT:	base	- Port list
*
*	OUTPUT:	NONE
*
*****************************************************************/

void FreePorts(PORT_LIST *base )
{
	PORT_LIST *npl;
	
	// (1) Loop through ports and free as seen
	
	while( base != NULL )
	{
		// (2) Save the next for later
		
		npl = base->next;
		
		// (3) Free up the parts
		
		if( base->path != NULL )
			MEMFREE( base->path );
		if( base->name != NULL )
			MEMFREE( base->name );
			
		// (4) Free the main part and move to next
		
		MEMFREE( base );
		base = npl;
	}
}

#pragma mark -- PORT OPEN/CLOSE API --

/****************************************************************
*
*  PORT_HANDLE *OpenPort( int psn,PORT_LIST *p,
*						int baud,
*						PORT_STOP stop,
*						PORT_PARITY parity)		- Open a port
*
*	INPUT:	psn		- Psn in list (base = 1)
*			p		- PORT_LIST 
*			baud	- Baud rate desired
*			stop	- # Stop bits (1,2)
*			parity	- NONE/ODD/EVEN
*
*	OUTPUT: Open file handle
*			NULL if failed
*
*****************************************************************/

PORT_HANDLE *OpenPort( int psn,
						PORT_LIST *base,
						int baud,
						SER_PORT_STOP stop,
						SER_PORT_PARITY parity)
{
	PORT_HANDLE *h;
	int i;
	int error;
	PORT_LIST *p;
	
	// (0) Find the slot in the port list
	
	for( i=0, p = base; i<psn-1 && p != NULL ; i++ )
	{
		p = p->next;
	}
	
	if( p == NULL )
		return( NULL );
	
	// (1) Create the handle
	
	h = NEW_PORT_HANDLE;
	if( h == NULL )
	{
		return( NULL );		// FAILURE
	}
	h->fd = -1;				// Set bad descriptor
	
	// (1a) Fill the name and path fields
	
	i = strlen(p->path);
	h->path = (char *)MEMALLOC( i + 1 );
	if( h->path == NULL )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	strcpy(h->path,p->path);
	
	i = strlen( p->name );
	h->name = (char *)MEMALLOC( i + 1 );
	if( h->name == NULL )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	strcpy(h->name,p->name);
	
	// (2) Try to open the port
	
	h->fd = open(p->path, O_RDWR | O_NOCTTY | O_NONBLOCK);
	if( h->fd == -1 )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	ioctl(h->fd, TIOCEXCL);	// Set for exclusive OPEN
	
	// (2a) Get current values fron port
	// Save originals and copy into run area
    if (tcgetattr(h->fd, &(h->orig)) == -1)
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	memcpy(&(h->run),&(h->orig),sizeof(struct termios));
	
    // (3) Set options to baud rate, 8 bits, parity, & size no flow
    // Init flags then set
	
	//*********** CONTROL FLAG SET
    h->run.c_cflag = 0;
	
	if( parity == SER_PARITY_NONE )
		h->run.c_cflag |= CS8;			// 8 Bit words
	else
	{
		h->run.c_cflag |= CS7;			// 7 Bit words with parity
		h->run.c_cflag |= PARENB;		// Parity enable
		if( parity == SER_PARITY_ODD )
			h->run.c_cflag |= PARODD;	// ODD parity
	}
		
	if( stop == SER_STOP_TWO )
		h->run.c_cflag |= CSTOPB;		// Two stop bits (1 by default)
		
    h->run.c_cflag |= CREAD;		// Enable input
    h->run.c_cflag |= CLOCAL;		// Ignore modem cntl lines
    
	//************* INPUT FLAGS SET
    h->run.c_iflag = 0;
    h->run.c_iflag |= IGNBRK;
	if( parity != SER_PARITY_NONE )
		h->run.c_iflag |= INPCK;	// Parity check
    
	//************* LINE FLAGS SET
    h->run.c_lflag = 0;				// No echo input
    
	//************* OPTION CHARACTERS
    for( i=0; i<NCCS; i++ )			// REF:JS12052003 Change to clear all option chars
        h->run.c_cc[i] = 0;
        
    h->run.c_cc[VMIN] = 0;			// Non blocking input
    h->run.c_cc[VTIME] = 0;			// REF:JS12052003 Set to not wait
									// for either min char or time

    printf("Options set now: CFLAG [%X] IFLAG [%X] OFLAG [%X]\n",
                    (int)h->run.c_cflag,
                    (int)h->run.c_iflag,
                    (int)h->run.c_oflag);
    // (4) Set the baud rates, if you try this in reverse order
    // then the c_flag -> 0 and will wipe out the baud rates
    // (i.e. baudrate = 0)
    
	error = cfsetospeed( &(h->run),baud );
	error = cfsetispeed( &(h->run),baud );

    // (5) Cause the new options to take effect immediately.
    if (tcsetattr(h->fd, TCSANOW, &(h->run)) == -1)
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	
    // (6) Print the new input and output baud rates & return the results
    
    printf("Input baud rate changed to %d\n", (int) cfgetispeed(&(h->run)));
    printf("Output baud rate changed to %d\n", (int) cfgetospeed(&(h->run)));

	return( h );
}

/****************************************************************
*
*  void ClosePort( PORT_HANDLE *h )	- Close the port
*
*	INPUT:	h	- Close this open port
*
*	OUTPUT: NONE
*
*****************************************************************/

void ClosePort( PORT_HANDLE *h )
{
	// (1) C heck for valid handle
	
	if( h != NULL )
	{
		// (2) If descriptor valid then reset port back to original
		
		if( h->fd != -1 )
		{
			tcsetattr(h->fd, TCSANOW, &(h->orig));
			close(h->fd);
		}
		
		// (3) Free up the allocated fields
		
		if( h->path != NULL )
			MEMFREE( h->path );
		if( h->name != NULL )
			MEMFREE( h->name );
		
		// (4) Free the handle
		
		MEMFREE( h );
	}
}
#pragma mark -- PORT I/O API --

/***********************************************************************
*
* int StatPort( PORT_HANDLE *h )	- Data present on port ?
*
*	INPUT:	dwelltime	- # MS to scan for data 0 => no wait
*			h			- To this port
*
*	OUTPUT:	1	- Data present for read, 0 no data
*
************************************************************************/

int StatPort( int dwelltime,PORT_HANDLE *h )
{
	int rtnval = 0;
	fd_set scan;
	struct timeval seltime; // Select timeout time
	
	// (1) Build scan array and set up time
	
	FD_ZERO( &scan );
	FD_SET( h->fd,&scan );
	seltime.tv_sec = dwelltime / 1000;
	seltime.tv_usec = (dwelltime - (1000 * seltime.tv_sec)) * 1000;
	
	// (2) Do a select on the socket
	
	rtnval = select(h->fd+1,&scan,NULL,NULL,&seltime);
	if( rtnval < 0 )
		rtnval = 0;		// If failure return 0
		
	return( rtnval );
}

/***********************************************************************
*
* int WritePort( char *buffer,int size,PORT_HANDLE *h) - Write to a port
*
*	INPUT:	buffer	- Buffer to send
*			size	- # Bytes to send
*			h		- To this port
*
*	OUTPUT:	# bytes written
*
************************************************************************/

int WritePort( char *buffer,int size,PORT_HANDLE *h)
{
	int rtn = -1;
	
	// (1) Good handle ?
	
	if( h != NULL )
	{
		// (2) Ok, so do I/O 
		
		rtn = write(h->fd,buffer,size );
	}
	
	return( rtn );
}

/***********************************************************************
*
* int ReadPort( char *buffer,int size,PORT_HANDLE *h) - Read from a port
*
*	INPUT:	buffer	- Buffer to read
*			size	- # Bytes to read
*			h		- From this port
*
*	OUTPUT:	# bytes read
*
************************************************************************/

int ReadPort( char *buffer, int size,PORT_HANDLE *h )
{
	int rtn = -1;
	
	// (1) Good handle ?
	
	if( h != NULL )
	{
		// (2) Ok, so do I/O 
		
		rtn = read(h->fd,buffer,size );
	}
	
	return( rtn );
}

#pragma mark -- PORT MISC --
/***********************************************************************
*
* int CTSPort( PORT_HANDLE *h ) - Return CTS state
*
*	INPUT: h	- Port handle
*
*	OUTPUT:	1 = CTS asserted, 0 - CTS not asserted
*
************************************************************************/

int CTSPort( PORT_HANDLE *h )
{
	int state = GetPortState( h );		// Get current state
	int cts;
	
	// Extract RTS state
		
	if( state & TIOCM_CTS )
	{
		cts = 1;
	}
	else
	{
		cts = 0;
	}
	
	return( cts );
}

/***********************************************************************
*
* void DTRPort( int flag,PORT_HANDLE *h) - Set DTR state
*
*	INPUT:	flag	- 1 -> Assert DTR, 0 Remove DTR
*			h		- Port to work on
*
*	OUTPUT:	NONE
*
************************************************************************/

void DTRPort( int dtr,PORT_HANDLE *h)
{
	int state = GetPortState( h );		// Get current state
	
	// (1) Set or CLEAR
	
	if( dtr )
	{
		state = state | TIOCM_DTR;		// Assert DTR
	}
	else
	{
		state = state & ~TIOCM_DTR;		// Clear DTR
	}
	
	SetPortState( state,h );
}

#pragma mark -- Support (INTERNAL) --
// ------- Support functions ------- READ OUT PORTS

/***********************************************************************
*
* FindPorts(io_iterator_t *i)	- Find an iterator to serial ports
*
*	INPUT: modem_flag				- TRUE if we are looking for a modem
*			matchingServices		- Fill with iterator to open ports
*
*	OUTPUT:	KERN_SUCCESS if OK
*
************************************************************************/
// Returns an iterator across all known modems. Caller is responsible for
// releasing the iterator when iteration is complete.
static kern_return_t FindPorts(bool modem_flag,io_iterator_t *matchingServices)
{
    kern_return_t		kernResult; 
    mach_port_t			masterPort;
    CFMutableDictionaryRef	classesToMatch;

/*! @function IOMasterPort
    @abstract Returns the mach port used to initiate communication with IOKit.
    @discussion Functions that don't specify an existing object require the IOKit master port to be passed. 
    @This function obtains that port.
    @param bootstrapPort Pass MACH_PORT_NULL for the default.
    @param masterPort The master port is returned.
    @result A kern_return_t error code. */

    kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
    if (KERN_SUCCESS != kernResult)
    {
        printf("IOMasterPort returned %d\n", kernResult);
		goto exit;
    }
        
/*! @function IOServiceMatching
    @abstract Create a matching dictionary that specifies an IOService class match.
    @discussion A very common matching criteria for IOService is based on its class. IOServiceMatching will create a matching dictionary that specifies any IOService of a class, or its subclasses. The class is specified by C-string name.
    @param name The class name, as a const C-string. Class matching is successful on IOService's of this class or any subclass.
    @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */

    // Serial devices are instances of class IOSerialBSDClient
    classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
    if (classesToMatch == NULL)
    {
        printf("IOServiceMatching returned a NULL dictionary.\n");
    }
    else {
/*!
	@function CFDictionarySetValue
	Sets the value of the key in the dictionary.
	@param theDict The dictionary to which the value is to be set. If this
		parameter is not a valid mutable CFDictionary, the behavior is
		undefined. If the dictionary is a fixed-capacity dictionary and
		it is full before this operation, and the key does not exist in
		the dictionary, the behavior is undefined.
	@param key The key of the value to set into the dictionary. If a key 
		which matches this key is already present in the dictionary, only
		the value is changed ("add if absent, replace if present"). If
		no key matches the given key, the key-value pair is added to the
		dictionary. If added, the key is retained by the dictionary,
		using the retain callback provided
		when the dictionary was created. If the key is not of the sort
		expected by the key retain callback, the behavior is undefined.
	@param value The value to add to or replace into the dictionary. The value
		is retained by the dictionary using the retain callback provided
		when the dictionary was created, and the previous value if any is
		released. If the value is not of the sort expected by the
		retain or release callbacks, the behavior is undefined.
*/
		if( modem_flag )
		{
			// LOOK for MODEM HERE
			CFDictionarySetValue(classesToMatch,
                             CFSTR(kIOSerialBSDTypeKey),
							 //CFSTR(kIOSerialBSDModemType));
							 CFSTR(kIOSerialBSDAllTypes));
		}
		else
		{
			CFDictionarySetValue(classesToMatch,
                             CFSTR(kIOSerialBSDTypeKey),
							 CFSTR(kIOSerialBSDRS232Type));
		}
		
        // Each serial device object has a property with key
        // kIOSerialBSDTypeKey and a value that is one of kIOSerialBSDAllTypes,
        // kIOSerialBSDModemType, or kIOSerialBSDRS232Type. You can experiment with the
        // matching by changing the last parameter in the above call to CFDictionarySetValue.
        
        // As shipped, this sample is only interested in modems,
        // so add this property to the CFDictionary we're matching on. 
        // This will find devices that advertise themselves as modems,
        // such as built-in and USB modems. However, this match won't find serial modems.
    }
    
    /*! @function IOServiceGetMatchingServices
        @abstract Look up registered IOService objects that match a matching dictionary.
        @discussion This is the preferred method of finding IOService objects currently registered by IOKit. IOServiceAddNotification can also supply this information and install a notification of new IOServices. The matching information used in the matching dictionary may vary depending on the class of service being looked up.
        @param masterPort The master port obtained from IOMasterPort().
        @param matching A CF dictionary containing matching information, of which one reference is consumed by this function. IOKitLib can contruct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOOpenFirmwarePathMatching.
        @param existing An iterator handle is returned on success, and should be released by the caller when the iteration is finished.
        @result A kern_return_t error code. */

    kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, matchingServices);    
    if (KERN_SUCCESS != kernResult)
    {
        //printf("IOServiceGetMatchingServices returned %d\n", kernResult);
		goto exit;
    }
        
exit:
    return kernResult;
}

/***********************************************************************
*
* GetPortPath(int port,
*				io_iterator_t serialPortIterator, 
*				char *bsdPath, 
*				CFIndex maxPathSize)			- Get Path to port
*
*	INPUT: 	port				- Port # to open (0 based)
*			serialPortIterator	- pointer to linked list of port
*			bsdPath				- Return port path here
*			maxPathSize			- Max length of bsdPath
*
*	OUTPUT:	KERN_SUCCESS if OK
*
************************************************************************/
// Given an iterator across a set of ports, return the BSD path to the first one.
// If no ports are found the path name is set to an empty string.
static kern_return_t GetPortPath(int port,
								io_iterator_t serialPortIterator, 
								char *bsdPath, 
								CFIndex maxPathSize)
{
    io_object_t		modemService;
    kern_return_t	kernResult = KERN_FAILURE;
    Boolean			modemFound = false;
    
    // Initialize the returned path
    *bsdPath = '\0';
    
    // Iterate across all modems found. In this example, use port to count the correct path
    
    while ((modemService = IOIteratorNext(serialPortIterator)) && !modemFound)
    {
    	if( port == 0 )
    	{
	        CFTypeRef	bsdPathAsCFString;

		// Get the callout device's path (/dev/cu.xxxxx). The callout device should almost always be
		// used: the dialin device (/dev/tty.xxxxx) would be used when monitoring a serial port for
		// incoming calls, e.g. a fax listener.
		
			bsdPathAsCFString = IORegistryEntryCreateCFProperty(modemService,
	                                                            CFSTR(kIOCalloutDeviceKey),
	                                                            kCFAllocatorDefault,
	                                                            0);
	        if (bsdPathAsCFString)
	        {
	            Boolean result;
	            
	            // Convert the path from a CFString to a C (NUL-terminated) string for use
		    	// with the POSIX open() call.
		    
		    	result = CFStringGetCString((const CFStringRef)bsdPathAsCFString,
	                                        (char *)bsdPath,
	                                        (long)maxPathSize, 
	                                        kCFStringEncodingASCII);
	            CFRelease(bsdPathAsCFString);
	            
	            if (result)
		    	{
	                //printf("BSD path: %s", bsdPath);
	                modemFound = true;
	                kernResult = KERN_SUCCESS;
	            }
	        }
	  	}
	  	else
	  	{
	  		port = port - 1;		// Next port
	  	}

	  	// Release the io_service_t now that we are done with it.
		
		(void) IOObjectRelease(modemService);
    }
        
    return kernResult;
}

/***********************************************************************
*
* PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl) - Add names into struct
*
*	INPUT: 	portstr		- Port path string
*			pl			- Port list struct to have names added
*						NOTE: Struct NEW so all pointers NULL
*
*	OUTPUT:	pl	- Pointer to original pl filled out if OK
*			NULL if failure
*
************************************************************************/

static PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl)
{
	int len;
	char *ptr;
	
	// (1) Get the length and put in the whole path
	
	len = strlen(portstr);
	pl->path = (char *)MEMALLOC(len+1);
	if( pl->path == NULL )
	{
		MEMFREE( pl );			// FAILURE
		return( NULL );
	}
	strcpy(pl->path,portstr);
	
	// (2) Now walk back through the portstr and find the first "/"
	// from there to the end is the name of the port
	
	ptr = portstr;
	ptr += len;			// Move to the end of the string
	// Scan backwards through the string
	for( ; ptr >= portstr; ptr-- )
	{
		if( *ptr == '/' )
			break;				// We have found the left end of the name
								// Actually 1 less than that see below
	}
	
	ptr++;						// Move to start of name
								// Now build the name holder
	len = strlen(ptr);
	pl->name = (char *)MEMALLOC(len+1);
	if( pl->name == NULL )
	{
		MEMFREE(pl->path);	// FAILURE
		MEMFREE(pl);
		return( NULL );
	}
	strcpy(pl->name,ptr);
	
	// (3) All done return filled out struct
	
	return( pl );
}


/***********************************************************************
*
* int GetPortState(PORT_HANDLE *h)	- Get state value from tty
*
*	INPUT: 	xh		- Handle to open serial port
*
*	OUTPUT:	Terminal state as per bits in sys/ioctl.h
*			Return 0 if bad state
*
************************************************************************/

static int GetPortState( PORT_HANDLE *h )
{
    int state = 0;
	int val;
	
	// (2) Read state
	
	val = ioctl(h->fd,TIOCMGET,&state);
	//val = ioctl(h->fd,TIOCMODG,&state);
	if( val < 0 )
	{
		state = 0;		// ERROR
	}
	return( state );
}

/***********************************************************************
*
* int SetPortState(int state, PORT_HANDLE *h)	- Set state value for tty
*
*	INPUT:  state   - Set TTY state to this
*			xh		- Handle to open serial port
*
*	OUTPUT:	Return 1 if OK, 0 if fail
*
************************************************************************/

static int SetPortState( int state,PORT_HANDLE *h )
{
    int rtnval = 0;
	int val;
	
	// (1) Is it valid ?
	
	// (2) Set state
	
	val = ioctl(h->fd,TIOCMSET,&state);
	if( val >= 0 )
	{
		rtnval = 1;		// SUCCESS
	}
	return( rtnval );
}

Added SERIAL/OSX/bsdserial.h.















































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2005. Pandora Products. All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         BSDSERIAL		- Serial Support on a BSD system
*
*  Description:         This will list,open,setup and close serial ports
*						on BSD
*
*  Author:              Jim Schimpf
*
*  Revision History:	21 Jan 2005 Initial version
*						 2 Dec 2005 Change OpenPort slightly and add
*									DTR,CTS functions
*						16-Apr-2009	Change list ports to show modems
*						17 Apr 2009 Add working StatPort() 
*
*		USER-API	PORT_LIST *ListPorts(int modems)
*					void ListPortsFree( PORT_LIST *l);
*					PORT_HANDLE *OpenPort( PORT_LIST *e,
*											int baud,
*											int stop,
*											int parity);
*					ClosePort( PORT_HANDLE *h );
*					int StatPort( PORT_HANDLE *h );
*					int WritePort( char *data,int size,PORT_HANDLE *h );
*					int ReadPort( char *data,int size,PORT_HANDLE *h );
*/
//************************************************************************

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <paths.h>
#include <termios.h>
#include <sysexits.h>
#include <sys/param.h>
#include <sys/select.h>
#include <sys/time.h>
#include <time.h>
#include <CoreFoundation/CoreFoundation.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/serial/IOSerialKeys.h>
#include <IOKit/IOBSD.h>
#include "tgtypes.h"

#ifndef BSDSERIAL_H
#define BSDSERIAL_H	1

#pragma mark -- Structures --

typedef struct sdummy {
						struct sdummy *next;
						char *path;				// Path of port
						char *name;				// Just the name part of the port
					} PORT_LIST;
					
#define NEW_PORT_LIST		((PORT_LIST *)MEMALLOC(sizeof(PORT_LIST)))

// Parity & Stop bit defs

typedef enum {
				SER_PARITY_NONE,
				SER_PARITY_EVEN,
				SER_PARITY_ODD
			} SER_PORT_PARITY;
			
typedef enum {
				SER_STOP_ONE,
				SER_STOP_TWO
			} SER_PORT_STOP;

typedef struct {
					char *path;
					char *name;
					
					// PORT DATA
					struct termios orig;	// Original values
					struct termios run;		// Run values
					int fd;					// Port descriptor
					
				} PORT_HANDLE;
				
#define NEW_PORT_HANDLE		((PORT_HANDLE *)MEMALLOC(sizeof(PORT_HANDLE)))

#pragma mark -- API --

// **** PORT DETERMINATION ****
PORT_LIST *ListPorts(int modems);
void FreePorts(PORT_LIST *base );

// **** PORT OPEN/CLOSE

PORT_HANDLE *OpenPort( int psn,
						PORT_LIST *p,
						int baud,
						SER_PORT_STOP stop,
						SER_PORT_PARITY parity);
void ClosePort( PORT_HANDLE *h );

// **** PORT I/O

int StatPort( int dwelltime,PORT_HANDLE *h );
int WritePort( char *buffer,int size,PORT_HANDLE *h);
int ReadPort( char *buffer, int size,PORT_HANDLE *h );

// *** PORT MISC

int CTSPort( PORT_HANDLE *h );				// Read CTS
void DTRPort( int flag,PORT_HANDLE *h);		// Set DTR

#endif

Added SERIAL/PC/pcserial.c.

















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2005. Pandora Products. All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         PCSERIAL		- Serial Support on a PC system
*
*  Description:         This will list,open,setup and close serial ports
*						on Windows
*
*  Author:              Jim Schimpf
*
*  Revision History:	21 Jan 2005 Initial version
*
*		USER-API	PORT_LIST *ListPorts()
*					void ListPortsFree( PORT_LIST *l);
*					PORT_HANDLE *OpenPort( PORT_LIST *e,
*											int baud,
*											int stop,
*											int parity);
*					ClosePort( PORT_HANDLE *h );
*					int StatPort( PORT_HANDLE *h );
*					int WritePort( char *data,int size,PORT_HANDLE *h );
*					int ReadPort( char *data,int size,PORT_HANDLE *h );
*/
//************************************************************************

#include "pcserial.h"

// **** LOCAL FUNCTIONS ***
#ifdef SQUIGGLE
static kern_return_t FindPorts(bool modem_flag,io_iterator_t *matchingServices);
static kern_return_t GetPortPath(int port,
								io_iterator_t serialPortIterator, 
								char *bsdPath, 
								CFIndex maxPathSize);
#endif

static PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl);

#ifndef false
#define false	0
#define true	1
#endif

#pragma mark -- PORT MGMT API --

/****************************************************************
*
*  PORT_LIST *ListPorts()	- Get a list of SERIAL RS-232 ports
*
*	INPUT:NONE
*
*	OUTPUT:	Linked list of port data
*			NULL if none
*
*****************************************************************/

PORT_LIST *ListPorts(void)
{
	PORT_LIST *base = NULL;
	char portstr[256];
	int pcount = 0;
	PORT_LIST *pl;
	PORT_LIST *last = NULL;
	int i;
	
	// (1) Build a dummy port list with 9 ports
	
	for( i=1; i<10; i++ )
	{
		pl = NEW_PORT_LIST;
		
		sprintf(portstr,"\\\\.\\COM%d",i);
		pl = add_port_names(portstr,pl);
		if( pl == NULL )
			break;				// FAILURE
			
		// (3) Now add the element to the end of the list
		// Two cases:
		//		base == NULL	- First element just replace
		//		base != NULL	- Just add after last
		
		if( base == NULL )
		{
			base = pl;
			last = pl;
		}
		else
		{
			last->next = pl;
			last = pl;
		}
		pcount = pcount + 1;
	}
	return( base );
}

/****************************************************************
*
*  void FreePorts(PORT_LIST *base ) - Free port list
*
*	INPUT:	base	- Port list
*
*	OUTPUT:	NONE
*
*****************************************************************/

void FreePorts(PORT_LIST *base )
{
	PORT_LIST *npl;
	
	// (1) Loop through ports and free as seen
	
	while( base != NULL )
	{
		// (2) Save the next for later
		
		npl = base->next;
		
		// (3) Free up the parts
		
		if( base->path != NULL )
			MEMFREE( base->path );
		if( base->name != NULL )
			MEMFREE( base->name );
			
		// (4) Free the main part and move to next
		
		MEMFREE( base );
		base = npl;
	}
}

#pragma mark -- PORT OPEN/CLOSE API --

/****************************************************************
*
*  PORT_HANDLE *OpenPort( PORT_LIST *p,
*						int baud,
*						PORT_STOP stop,
*						PORT_PARITY parity)		- Open a port
*
*	INPUT:	p		- PORT_LIST element
*			baud	- Baud rate desired
*			stop	- # Stop bits (1,2)
*			parity	- NONE/ODD/EVEN
*
*	OUTPUT: Open file handle
*			NULL if failed
*
*****************************************************************/

PORT_HANDLE *OpenPort( PORT_LIST *p,
						int baud,
						SER_PORT_STOP stop,
						SER_PORT_PARITY parity)
{
	PORT_HANDLE *h = NULL;
	int i;
	
	// (0) Do we have a port list ?
	
	if( p == NULL )
		return( NULL );
	
	// (1) Create the handle
	
	h = NEW_PORT_HANDLE;
	if( h == NULL )
	{
		return( NULL );		// FAILURE
	}
	h->fd = INVALID_HANDLE_VALUE;	// Set bad descriptor
	
	// (1a) Fill the name and path fields
	
	i = strlen(p->path);
	h->path = (char *)MEMALLOC( i + 1 );
	if( h->path == NULL )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	strcpy(h->path,p->path);
	
	i = strlen( p->name );
	h->name = (char *)MEMALLOC( i + 1 );
	if( h->name == NULL )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	strcpy(h->name,p->name);
	
	// (2) Try to open the port
	
	h->fd = CreateFile( 	p->name,
			    	GENERIC_READ | GENERIC_WRITE,
				    0,		// Share mode
				    0,		// Security
				    OPEN_EXISTING,
				    FILE_ATTRIBUTE_NORMAL,
				    0);		// Template

	if( h->fd == INVALID_HANDLE_VALUE )
	{
		ClosePort( h );		// FAILURE
		return( NULL );
	}
	
	if( !GetCommState( h->fd, &(h->original) ) )
	{
		ClosePort( h );
		return( NULL );
	}

	if( !GetCommTimeouts( h->fd, &(h->timeouts) ) )
	{
		ClosePort( h );
		return( NULL );
	}

 	/* (3) Now set things up for our run ( baud etc)
           Get a good DCB to fill out
    */

	if( !GetCommState( h->fd,&(h->current) ) )  // Get current values
	{
		ClosePort( h );
		return( NULL );
	}

    // 29 March 2000 JS.
    // There is something undocumented in the DCB that controls
    // UART word size.  If you use the DCB above with no mod then
    // it will have the default word size, if it's 7 you are SOL
    // since then NOPARITY => EVEN PARITY.
    // What to do well we get the DCB filled out for the current
    // state, then run it through BuildCommDCB which fills out
    // the buad rate parity and stuff + sets the WORD SIZE (somewhere ?)
    // Then we fill in the parameters we want for our "real" use
    // and things are OK.
    // NOTE: I couldn't just use the DCB out of BuildCommDCB and
    //       fill in stuff below.  This failed the SET.  I don't
    //       know why at this point but this is a "fix" for the
    //       parity problem.
    //BuildCommDCB( "38400,n,8,1",&dset );
    // Fix II Found the "undocumented field - ByteSize"
    // Just set that....

    h->current.ByteSize = 8;          		// Set for 8 Bits
	h->current.BaudRate = baud;
	h->current.fBinary = true;				// Set to binary mode
	h->current.fOutxCtsFlow = false;		// No HDW flow control
	h->current.fOutxDsrFlow = false;		// No HDW flow control
	h->current.fDtrControl = DTR_CONTROL_DISABLE;	// DTR low when opened

	h->current.fDsrSensitivity = false;		// No input HDW control
	h->current.fOutX = false;				// No output XON/XOFF
	h->current.fInX = false;				// No input XON/XOFF
	h->current.fNull = false;				// Keep NUL bytes
	h->current.fRtsControl = RTS_CONTROL_DISABLE; // RTS low when opened
	h->current.fAbortOnError = false;		// Keep cranking
    h->current.fParity = true;       		// Set parity
	h->current.Parity = parity;				// Rather obvious
	h->current.StopBits = stop;				// Rather obvious again

	if( !SetCommState( h->fd,&(h->current) ) )
	{
		ClosePort( h );
		return( NULL );
	}

	return( h );
}

/****************************************************************
*
*  void ClosePort( PORT_HANDLE *h )	- Close the port
*
*	INPUT:	h	- Close this open port
*
*	OUTPUT: NONE
*
*****************************************************************/

void ClosePort( PORT_HANDLE *h )
{
	// (1) C heck for valid handle
	
	if( h != NULL )
	{
		// (2) If descriptor valid then reset port back to original
		
		if( h->fd != INVALID_HANDLE_VALUE )
		{
			SetCommState( h->fd, &(h->original));
			CloseHandle(h->fd);
		}
		
		// (3) Free up the allocated fields
		
		if( h->path != NULL )
			MEMFREE( h->path );
		if( h->name != NULL )
			MEMFREE( h->name );
		
		// (4) Free the handle
		
		MEMFREE( h );
	}

}
#pragma mark -- PORT I/O API --

//int StatPort( PORT_HANDLE *h );
/***********************************************************************
*
* int WritePort( char *buffer,int size,PORT_HANDLE *h) - Write to a port
*
*	INPUT:	buffer	- Buffer to send
*			size	- # Bytes to send
*			h		- To this port
*
*	OUTPUT:	# bytes written
*
************************************************************************/

+ WritePort( char *buffer,int size,PORT_HANDLE *h)
{
	int rtn = -1;
#ifdef SQUIGGLE	
	// (1) Good handle ?
	
	if( h != NULL )
	{
		// (2) Ok, so do I/O 
		
		rtn = write(h->fd,buffer,size );
	}
#endif	
	return( rtn );
}

/***********************************************************************
*
* int ReadPort( char *buffer,int size,PORT_HANDLE *h) - Read from a port
*
*	INPUT:	buffer	- Buffer to read
*			size	- # Bytes to read
*			h		- From this port
*
*	OUTPUT:	# bytes read
*
************************************************************************/

int ReadPort( char *buffer, int size,PORT_HANDLE *h )
{
	int rtn = -1;
#ifdef SQUIGGLE	
	// (1) Good handle ?
	
	if( h != NULL )
	{
		// (2) Ok, so do I/O 
		
		rtn = read(h->fd,buffer,size );
	}
#endif	
	return( rtn );
}

#ifdef SQUIGGLE
#pragma mark -- Support (INTERNAL) --
// ------- Support functions ------- READ OUT PORTS

/***********************************************************************
*
* FindPorts(io_iterator_t *i)	- Find an iterator to serial ports
*
*	INPUT: modem_flag				- TRUE if we are looking for a modem
*			matchingServices		- Fill with iterator to open ports
*
*	OUTPUT:	KERN_SUCCESS if OK
*
************************************************************************/
// Returns an iterator across all known modems. Caller is responsible for
// releasing the iterator when iteration is complete.
static kern_return_t FindPorts(bool modem_flag,io_iterator_t *matchingServices)
{
    kern_return_t		kernResult; 
    mach_port_t			masterPort;
    CFMutableDictionaryRef	classesToMatch;

/*! @function IOMasterPort
    @abstract Returns the mach port used to initiate communication with IOKit.
    @discussion Functions that don't specify an existing object require the IOKit master port to be passed. 
    @This function obtains that port.
    @param bootstrapPort Pass MACH_PORT_NULL for the default.
    @param masterPort The master port is returned.
    @result A kern_return_t error code. */

    kernResult = IOMasterPort(MACH_PORT_NULL, &masterPort);
    if (KERN_SUCCESS != kernResult)
    {
        printf("IOMasterPort returned %d\n", kernResult);
		goto exit;
    }
        
/*! @function IOServiceMatching
    @abstract Create a matching dictionary that specifies an IOService class match.
    @discussion A very common matching criteria for IOService is based on its class. IOServiceMatching will create a matching dictionary that specifies any IOService of a class, or its subclasses. The class is specified by C-string name.
    @param name The class name, as a const C-string. Class matching is successful on IOService's of this class or any subclass.
    @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */

    // Serial devices are instances of class IOSerialBSDClient
    classesToMatch = IOServiceMatching(kIOSerialBSDServiceValue);
    if (classesToMatch == NULL)
    {
        printf("IOServiceMatching returned a NULL dictionary.\n");
    }
    else {
/*!
	@function CFDictionarySetValue
	Sets the value of the key in the dictionary.
	@param theDict The dictionary to which the value is to be set. If this
		parameter is not a valid mutable CFDictionary, the behavior is
		undefined. If the dictionary is a fixed-capacity dictionary and
		it is full before this operation, and the key does not exist in
		the dictionary, the behavior is undefined.
	@param key The key of the value to set into the dictionary. If a key 
		which matches this key is already present in the dictionary, only
		the value is changed ("add if absent, replace if present"). If
		no key matches the given key, the key-value pair is added to the
		dictionary. If added, the key is retained by the dictionary,
		using the retain callback provided
		when the dictionary was created. If the key is not of the sort
		expected by the key retain callback, the behavior is undefined.
	@param value The value to add to or replace into the dictionary. The value
		is retained by the dictionary using the retain callback provided
		when the dictionary was created, and the previous value if any is
		released. If the value is not of the sort expected by the
		retain or release callbacks, the behavior is undefined.
*/
		if( modem_flag )
		{
			// LOOK for MODEM HERE
			CFDictionarySetValue(classesToMatch,
                             CFSTR(kIOSerialBSDTypeKey),
							 CFSTR(kIOSerialBSDModemType));
		}
		else
		{
			CFDictionarySetValue(classesToMatch,
                             CFSTR(kIOSerialBSDTypeKey),
							 CFSTR(kIOSerialBSDRS232Type));
		}
		
        // Each serial device object has a property with key
        // kIOSerialBSDTypeKey and a value that is one of kIOSerialBSDAllTypes,
        // kIOSerialBSDModemType, or kIOSerialBSDRS232Type. You can experiment with the
        // matching by changing the last parameter in the above call to CFDictionarySetValue.
        
        // As shipped, this sample is only interested in modems,
        // so add this property to the CFDictionary we're matching on. 
        // This will find devices that advertise themselves as modems,
        // such as built-in and USB modems. However, this match won't find serial modems.
    }
    
    /*! @function IOServiceGetMatchingServices
        @abstract Look up registered IOService objects that match a matching dictionary.
        @discussion This is the preferred method of finding IOService objects currently registered by IOKit. IOServiceAddNotification can also supply this information and install a notification of new IOServices. The matching information used in the matching dictionary may vary depending on the class of service being looked up.
        @param masterPort The master port obtained from IOMasterPort().
        @param matching A CF dictionary containing matching information, of which one reference is consumed by this function. IOKitLib can contruct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOOpenFirmwarePathMatching.
        @param existing An iterator handle is returned on success, and should be released by the caller when the iteration is finished.
        @result A kern_return_t error code. */

    kernResult = IOServiceGetMatchingServices(masterPort, classesToMatch, matchingServices);    
    if (KERN_SUCCESS != kernResult)
    {
        //printf("IOServiceGetMatchingServices returned %d\n", kernResult);
		goto exit;
    }
        
exit:
    return kernResult;
}

/***********************************************************************
*
* GetPortPath(int port,
*				io_iterator_t serialPortIterator, 
*				char *bsdPath, 
*				CFIndex maxPathSize)			- Get Path to port
*
*	INPUT: 	port				- Port # to open (0 based)
*			serialPortIterator	- pointer to linked list of port
*			bsdPath				- Return port path here
*			maxPathSize			- Max length of bsdPath
*
*	OUTPUT:	KERN_SUCCESS if OK
*
************************************************************************/
// Given an iterator across a set of ports, return the BSD path to the first one.
// If no ports are found the path name is set to an empty string.
static kern_return_t GetPortPath(int port,
								io_iterator_t serialPortIterator, 
								char *bsdPath, 
								CFIndex maxPathSize)
{
    io_object_t		modemService;
    kern_return_t	kernResult = KERN_FAILURE;
    Boolean			modemFound = false;
    
    // Initialize the returned path
    *bsdPath = '\0';
    
    // Iterate across all modems found. In this example, use port to count the correct path
    
    while ((modemService = IOIteratorNext(serialPortIterator)) && !modemFound)
    {
    	if( port == 0 )
    	{
	        CFTypeRef	bsdPathAsCFString;

		// Get the callout device's path (/dev/cu.xxxxx). The callout device should almost always be
		// used: the dialin device (/dev/tty.xxxxx) would be used when monitoring a serial port for
		// incoming calls, e.g. a fax listener.
		
			bsdPathAsCFString = IORegistryEntryCreateCFProperty(modemService,
	                                                            CFSTR(kIOCalloutDeviceKey),
	                                                            kCFAllocatorDefault,
	                                                            0);
	        if (bsdPathAsCFString)
	        {
	            Boolean result;
	            
	            // Convert the path from a CFString to a C (NUL-terminated) string for use
		    	// with the POSIX open() call.
		    
		    	result = CFStringGetCString((const CFStringRef)bsdPathAsCFString,
	                                        (char *)bsdPath,
	                                        (long)maxPathSize, 
	                                        kCFStringEncodingASCII);
	            CFRelease(bsdPathAsCFString);
	            
	            if (result)
		    	{
	                //printf("BSD path: %s", bsdPath);
	                modemFound = true;
	                kernResult = KERN_SUCCESS;
	            }
	        }
	  	}
	  	else
	  	{
	  		port = port - 1;		// Next port
	  	}

	  	// Release the io_service_t now that we are done with it.
		
		(void) IOObjectRelease(modemService);
    }
        
    return kernResult;
}

#endif


/***********************************************************************
*
* PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl) - Add names into struct
*
*	INPUT: 	portstr		- Port path string
*			pl			- Port list struct to have names added
*						NOTE: Struct NEW so all pointers NULL
*
*	OUTPUT:	pl	- Pointer to original pl filled out if OK
*			NULL if failure
*
************************************************************************/

static PORT_LIST *add_port_names(char *portstr,PORT_LIST *pl)
{
	int len;
	char *ptr;
	
	// (1) Get the length and put in the whole path
	
	len = strlen(portstr);
	pl->path = (char *)MEMALLOC(len+1);
	if( pl->path == NULL )
	{
		MEMFREE( pl );			// FAILURE
		return( NULL );
	}
	strcpy(pl->path,portstr);
	
	// (2) Just do it again for the name
	
	len = strlen(portstr);
	pl->name = (char *)MEMALLOC(len+1);
	if( pl->name == NULL )
	{
		MEMFREE( pl );			// FAILURE
		return( NULL );
	}
	strcpy(pl->name,portstr);
		
	// (3) All done return filled out struct
	
	return( pl );
}

Added SERIAL/PC/pcserial.h.











































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2005. Pandora Products. All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         PCSERIAL		- Serial Support on a PC system
*
*  Description:         This will list,open,setup and close serial ports
*						on Windows
*
*  Author:              Jim Schimpf
*
*  Revision History:	21 Jan 2005 Initial version
*
*		USER-API	PORT_LIST *ListPorts()
*					void ListPortsFree( PORT_LIST *l);
*					PORT_HANDLE *OpenPort( PORT_LIST *e,
*											int baud,
*											int stop,
*											int parity);
*					ClosePort( PORT_HANDLE *h );
*					int StatPort( PORT_HANDLE *h );
*					int WritePort( char *data,int size,PORT_HANDLE *h );
*					int ReadPort( char *data,int size,PORT_HANDLE *h );
*/
//************************************************************************

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#include <io.h>
#include "tgtypes.h"

#ifndef PCSERIAL_H
#define PCSERIAL_H	1

#pragma mark -- Structures --

typedef struct sdummy {
						struct sdummy *next;
						char *path;				// Path of port
						char *name;				// Just the name part of the port
					} PORT_LIST;
					
#define NEW_PORT_LIST		((PORT_LIST *)MEMALLOC(sizeof(PORT_LIST)))

// Parity & Stop bit defs

typedef enum {
				SER_PARITY_NONE,
				SER_PARITY_EVEN,
				SER_PARITY_ODD
			} SER_PORT_PARITY;
			
typedef enum {
				SER_STOP_ONE,
				SER_STOP_TWO
			} SER_PORT_STOP;

typedef struct {
					char *path;
					char *name;
					
					// PORT DATA
					//struct termios orig;	// Original values
					//struct termios run;		// Run values
					HANDLE fd;					// Port descriptor
					
					// And other data
					
					DCB	original;
					DCB	current;
					COMMTIMEOUTS timeouts;	
					
				} PORT_HANDLE;
				
#define NEW_PORT_HANDLE		((PORT_HANDLE *)MEMALLOC(sizeof(PORT_HANDLE)))

#pragma mark -- API --

// **** PORT DETERMINATION ****
PORT_LIST *ListPorts(void);
void FreePorts(PORT_LIST *base );

// **** PORT OPEN/CLOSE

PORT_HANDLE *OpenPort( PORT_LIST *p,
						int baud,
						SER_PORT_STOP stop,
						SER_PORT_PARITY parity);
void ClosePort( PORT_HANDLE *h );

// **** PORT I/O

int StatPort( PORT_HANDLE *h );
int WritePort( char *buffer,int size,PORT_HANDLE *h);
int ReadPort( char *buffer, int size,PORT_HANDLE *h );

#endif

Added Scripts/reader.lua.

















































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
--------------------------------------------------------------------------------
--
-- File Mover script
--	This script will be used to move files to a serial port in a paced fashion
--  The input file is assumed to be an ASCII text file and will be read
-- 	line by line and sent to the serial port
--
--	SYNTAX:	LUA5 -c reader.lua -port 
--					"TCP=<IP address> PORT=#"		IP/PORT of terminal server
--					-f <input file> 				File to be send
--					-ld <line delay MS>				Delay at end of each line
--					-cd <character delay MS>		Delay between characters
--	port and file data is REQUIRED
--	-ld and -cd are optional.  		-ld DEFAULT = 200 ms
--									-cd DEFAULT = 0   ms
--
--	Revisions:
--			18-Nov-2007		Initial version
--
--------------------------------------------------------------------------------

-------------------------------------------------------------------------------
--
--  find_arg( argv,flag,data )   - Find the port in the argument list
--
--  INPUT:      argv    - Program argument list
--              flag    - Look for this string (i.e. -flag) in list
--              data    - If non-nil get the field following flag slot
--
--  OUTPUT      If data = nil return nil if flag not found and 1 if found
--              If data <> nil return nil if flag not found or next field if 
--				found
--
-------------------------------------------------------------------------------

function flag_srch( argv,flag,data )
    local rtnval = nil
    
    -- Loop over the list and check each item for match
    
    for i=1,table.getn(argv) 
    do
        if( flag == argv[i] )
        then
            -- Found so two cases 
            -- (a) If data == nil then return 1
            -- (b) If data != nil then return argv[i+1]
            
            if( data == nil  )
            then
                rtnval = 1
            else
                rtnval = argv[i+1]
            end
            
            -- In either case just break out
            
            break
        end
    end
    
    return( rtnval )
end
-------------------------------------------------------------------------------
-- Main Code
-------------------------------------------------------------------------------

-- (1) Get the input parameters
-- NOTE: Port and FILE must be present others
-- are defaulted
port = flag_srch( ARGS,"-port",1 )
file = flag_srch( ARGS,"-f",1 )
ld = flag_srch( ARGS,"-ld",1 )
cd = flag_srch( ARGS,"-cd",1 )

if( port == nil or file == nil )
then
	print()
	print"SYNTAX: LUA5 -c reader.lua "
	print("              -port \"IP=xx PORT=#\"      REQUIRED")
	print("              -f <Input file>           REQUIRED")
	print("              -ld <Line dly MS>         DEF=200")
	print("              -cd <Char dly MS>         DEF=0")
	print()
	if( port == nil )
	then
		print("** PORT/IP required")
	end
	if( file == nil )
	then
		print("*** FILE required")
	end
	
	return( 0 )
end

-- Now set defaults (if any)

if( ld ~= nil )
then
	ld = tonumber( ld )
else
	ld = 200
end
if( cd ~= nil )
then
	cd = tonumber( cd )
else
	cd = 0
end

-- (2) Open the telnet port and then open the file, fail
-- if either fails

net = limo.new( port )
if( net == nil )
then
	out = string.format("*** FAILURE CANNOT OPEN NET [%s] ***",port) 
	print(out)
	return( 0 )
end

fp = io.open(file,"r")
if( fp == nil )
then
	out = string.format("*** FAILURE CANNOT OPEN FILE [%s] ***",file)
	print(out)
	return( 0 )
end


-- (3) Now loop reading the file by lines and quit when done

lt = timer.new()
ct = timer.new()

while( 1 )
do
	line = fp:read("*l")
	if( line == nil )
	then
		break
	end
	
	-- (4) Two methods of sending the line
	-- if cd == 0 send the whole line as one
	-- chunk, if not send one character at a time
	
	if( cd == 0 )
	then
		-- (4a) Send whole line at once
		-- Send the line as one chunk and then
		-- do a wait after the return
		
		net:puts( line .. "\r" )
		lt:start()
		while( lt:done( ld ) == nil )
		do
		end
	else
		-- (4b) Send one character at a time
		-- Do with character delays
		-- Send the line one character at a time
		-- and do the line end delays
		
		n = string.len(line)
		for i=1,n
		do
			-- Line output with character delays
			ch = string.sub(line,i,i)
			net:puts( ch )
			ct:start()
			while( ct:done(cd) == nil )
			do
			end
		end
		-- Line end delay
		net:puts( "\r" )
		lt:start()
		while( lt:done( ld ) == nil )
		do
		end
	end
end

-- (5) All done, delete timers, close file and close net

lt:delete()
ct:delete()

fp:close()
net:delete()

print()
print("---- END RUN ----")
		




Added TERMS.xcodeproj/jim.mode1.































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>ActivePerspectiveName</key>
	<string>Project</string>
	<key>AllowedModules</key>
	<array>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXSmartGroupTreeModule</string>
			<key>Name</key>
			<string>Groups and Files Outline View</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXNavigatorGroup</string>
			<key>Name</key>
			<string>Editor</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCTaskListModule</string>
			<key>Name</key>
			<string>Task List</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCDetailModule</string>
			<key>Name</key>
			<string>File and Smart Group Detail Viewer</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXBuildResultsModule</string>
			<key>Name</key>
			<string>Detailed Build Results Viewer</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXProjectFindModule</string>
			<key>Name</key>
			<string>Project Batch Find Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXRunSessionModule</string>
			<key>Name</key>
			<string>Run Log</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXBookmarksModule</string>
			<key>Name</key>
			<string>Bookmarks Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXClassBrowserModule</string>
			<key>Name</key>
			<string>Class Browser</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXCVSModule</string>
			<key>Name</key>
			<string>Source Code Control Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXDebugBreakpointsModule</string>
			<key>Name</key>
			<string>Debug Breakpoints Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCDockableInspector</string>
			<key>Name</key>
			<string>Inspector</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXOpenQuicklyModule</string>
			<key>Name</key>
			<string>Open Quickly Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXDebugSessionModule</string>
			<key>Name</key>
			<string>Debugger</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXDebugCLIModule</string>
			<key>Name</key>
			<string>Debug Console</string>
		</dict>
	</array>
	<key>Description</key>
	<string>DefaultDescriptionKey</string>
	<key>DockingSystemVisible</key>
	<false/>
	<key>Extension</key>
	<string>mode1</string>
	<key>FavBarConfig</key>
	<dict>
		<key>PBXProjectModuleGUID</key>
		<string>38A6DCBF08683085001824A0</string>
		<key>XCBarModuleItemNames</key>
		<dict/>
		<key>XCBarModuleItems</key>
		<array/>
	</dict>
	<key>FirstTimeWindowDisplayed</key>
	<false/>
	<key>Identifier</key>
	<string>com.apple.perspectives.project.mode1</string>
	<key>MajorVersion</key>
	<integer>31</integer>
	<key>MinorVersion</key>
	<integer>1</integer>
	<key>Name</key>
	<string>Default</string>
	<key>Notifications</key>
	<array>
		<dict>
			<key>XCObserverAutoDisconnectKey</key>
			<true/>
			<key>XCObserverDefintionKey</key>
			<dict/>
			<key>XCObserverFactoryKey</key>
			<string>XCPerspectivesSpecificationIdentifier</string>
			<key>XCObserverGUIDKey</key>
			<string>XCObserverProjectIdentifier</string>
			<key>XCObserverNotificationKey</key>
			<string>PBXStatusBuildStateMessageNotification</string>
			<key>XCObserverTargetKey</key>
			<string>XCMainBuildResultsModuleGUID</string>
			<key>XCObserverTriggerKey</key>
			<string>awakenModuleWithObserver:</string>
			<key>XCObserverValidationKey</key>
			<dict/>
		</dict>
	</array>
	<key>OpenEditors</key>
	<array/>
	<key>PerspectiveWidths</key>
	<array>
		<integer>-1</integer>
		<integer>-1</integer>
	</array>
	<key>Perspectives</key>
	<array>
		<dict>
			<key>ChosenToolbarItems</key>
			<array>
				<string>active-buildstyle-popup</string>
				<string>active-target-popup</string>
				<string>build</string>
				<string>debug</string>
				<string>build-and-debug</string>
				<string>com.apple.ide.PBXToolbarStopButton</string>
				<string>NSToolbarSeparatorItem</string>
				<string>servicesModulefind</string>
				<string>servicesModulebreakpoints</string>
				<string>servicesModuleproject</string>
			</array>
			<key>ControllerClassBaseName</key>
			<string></string>
			<key>IconName</key>
			<string>WindowOfProjectWithEditor</string>
			<key>Identifier</key>
			<string>perspective.project</string>
			<key>IsVertical</key>
			<false/>
			<key>Layout</key>
			<array>
				<dict>
					<key>BecomeActive</key>
					<true/>
					<key>ContentConfiguration</key>
					<dict>
						<key>PBXBottomSmartGroupGIDs</key>
						<array>
							<string>1C37FBAC04509CD000000102</string>
							<string>1C37FAAC04509CD000000102</string>
							<string>1C08E77C0454961000C914BD</string>
							<string>1C37FABC05509CD000000102</string>
							<string>1C37FABC05539CD112110102</string>
							<string>E2644B35053B69B200211256</string>
							<string>1C37FABC04509CD000100104</string>
							<string>1CC0EA4004350EF90044410B</string>
							<string>1CC0EA4004350EF90041110B</string>
						</array>
						<key>PBXProjectModuleGUID</key>
						<string>1CE0B1FE06471DED0097A5F4</string>
						<key>PBXProjectModuleLabel</key>
						<string>Files</string>
						<key>PBXProjectStructureProvided</key>
						<string>yes</string>
						<key>PBXSmartGroupTreeModuleColumnData</key>
						<dict>
							<key>PBXSmartGroupTreeModuleColumnWidthsKey</key>
							<array>
								<real>186</real>
							</array>
							<key>PBXSmartGroupTreeModuleColumnsKey_v4</key>
							<array>
								<string>MainColumn</string>
							</array>
						</dict>
						<key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key>
						<dict>
							<key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key>
							<array>
								<string>08FB7794FE84155DC02AAC07</string>
								<string>08FB7795FE84155DC02AAC07</string>
								<string>1C37FBAC04509CD000000102</string>
								<string>1C37FAAC04509CD000000102</string>
								<string>1C37FABC05509CD000000102</string>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
							<array>
								<array>
									<integer>0</integer>
								</array>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
							<string>{{0, 0}, {186, 499}}</string>
						</dict>
						<key>PBXTopSmartGroupGIDs</key>
						<array/>
						<key>XCIncludePerspectivesSwitch</key>
						<true/>
						<key>XCSharingToken</key>
						<string>com.apple.Xcode.GFSharingToken</string>
					</dict>
					<key>GeometryConfiguration</key>
					<dict>
						<key>Frame</key>
						<string>{{0, 0}, {203, 517}}</string>
						<key>GroupTreeTableConfiguration</key>
						<array>
							<string>MainColumn</string>
							<real>186</real>
						</array>
						<key>RubberWindowFrame</key>
						<string>-1183 140 639 558 -1280 -256 1280 1024 </string>
					</dict>
					<key>Module</key>
					<string>PBXSmartGroupTreeModule</string>
					<key>Proportion</key>
					<string>203pt</string>
				</dict>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CE0B20306471E060097A5F4</string>
								<key>PBXProjectModuleLabel</key>
								<string></string>
								<key>PBXSplitModuleInNavigatorKey</key>
								<dict>
									<key>Split0</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1CE0B20406471E060097A5F4</string>
										<key>PBXProjectModuleLabel</key>
										<string></string>
									</dict>
									<key>SplitCount</key>
									<string>1</string>
								</dict>
								<key>StatusBarVisibility</key>
								<true/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {431, 0}}</string>
								<key>RubberWindowFrame</key>
								<string>-1183 140 639 558 -1280 -256 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>0pt</string>
						</dict>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CE0B20506471E060097A5F4</string>
								<key>PBXProjectModuleLabel</key>
								<string>Detail</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 5}, {431, 512}}</string>
								<key>RubberWindowFrame</key>
								<string>-1183 140 639 558 -1280 -256 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>XCDetailModule</string>
							<key>Proportion</key>
							<string>512pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>431pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Project</string>
			<key>ServiceClasses</key>
			<array>
				<string>XCModuleDock</string>
				<string>PBXSmartGroupTreeModule</string>
				<string>XCModuleDock</string>
				<string>PBXNavigatorGroup</string>
				<string>XCDetailModule</string>
			</array>
			<key>TableOfContents</key>
			<array>
				<string>38256C370CC8F51A005F1339</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>38256C380CC8F51A005F1339</string>
				<string>1CE0B20306471E060097A5F4</string>
				<string>1CE0B20506471E060097A5F4</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.default</string>
		</dict>
		<dict>
			<key>ControllerClassBaseName</key>
			<string></string>
			<key>IconName</key>
			<string>WindowOfProject</string>
			<key>Identifier</key>
			<string>perspective.morph</string>
			<key>IsVertical</key>
			<integer>0</integer>
			<key>Layout</key>
			<array>
				<dict>
					<key>BecomeActive</key>
					<integer>1</integer>
					<key>ContentConfiguration</key>
					<dict>
						<key>PBXBottomSmartGroupGIDs</key>
						<array>
							<string>1C37FBAC04509CD000000102</string>
							<string>1C37FAAC04509CD000000102</string>
							<string>1C08E77C0454961000C914BD</string>
							<string>1C37FABC05509CD000000102</string>
							<string>1C37FABC05539CD112110102</string>
							<string>E2644B35053B69B200211256</string>
							<string>1C37FABC04509CD000100104</string>
							<string>1CC0EA4004350EF90044410B</string>
							<string>1CC0EA4004350EF90041110B</string>
						</array>
						<key>PBXProjectModuleGUID</key>
						<string>11E0B1FE06471DED0097A5F4</string>
						<key>PBXProjectModuleLabel</key>
						<string>Files</string>
						<key>PBXProjectStructureProvided</key>
						<string>yes</string>
						<key>PBXSmartGroupTreeModuleColumnData</key>
						<dict>
							<key>PBXSmartGroupTreeModuleColumnWidthsKey</key>
							<array>
								<real>186</real>
							</array>
							<key>PBXSmartGroupTreeModuleColumnsKey_v4</key>
							<array>
								<string>MainColumn</string>
							</array>
						</dict>
						<key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key>
						<dict>
							<key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key>
							<array>
								<string>29B97314FDCFA39411CA2CEA</string>
								<string>1C37FABC05509CD000000102</string>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
							<array>
								<array>
									<integer>0</integer>
								</array>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
							<string>{{0, 0}, {186, 337}}</string>
						</dict>
						<key>PBXTopSmartGroupGIDs</key>
						<array/>
						<key>XCIncludePerspectivesSwitch</key>
						<integer>1</integer>
						<key>XCSharingToken</key>
						<string>com.apple.Xcode.GFSharingToken</string>
					</dict>
					<key>GeometryConfiguration</key>
					<dict>
						<key>Frame</key>
						<string>{{0, 0}, {203, 355}}</string>
						<key>GroupTreeTableConfiguration</key>
						<array>
							<string>MainColumn</string>
							<real>186</real>
						</array>
						<key>RubberWindowFrame</key>
						<string>373 269 690 397 0 0 1440 878 </string>
					</dict>
					<key>Module</key>
					<string>PBXSmartGroupTreeModule</string>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Morph</string>
			<key>PreferredWidth</key>
			<integer>300</integer>
			<key>ServiceClasses</key>
			<array>
				<string>XCModuleDock</string>
				<string>PBXSmartGroupTreeModule</string>
			</array>
			<key>TableOfContents</key>
			<array>
				<string>11E0B1FE06471DED0097A5F4</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.default.short</string>
		</dict>
	</array>
	<key>PerspectivesBarVisible</key>
	<false/>
	<key>ShelfIsVisible</key>
	<false/>
	<key>SourceDescription</key>
	<string>file at '/System/Library/PrivateFrameworks/DevToolsInterface.framework/Versions/A/Resources/XCPerspectivesSpecificationMode1.xcperspec'</string>
	<key>StatusbarIsVisible</key>
	<true/>
	<key>TimeStamp</key>
	<real>214496717.555168</real>
	<key>ToolbarDisplayMode</key>
	<integer>1</integer>
	<key>ToolbarIsVisible</key>
	<true/>
	<key>ToolbarSizeMode</key>
	<integer>2</integer>
	<key>Type</key>
	<string>Perspectives</string>
	<key>UpdateMessage</key>
	<string>The Default Workspace in this version of Xcode now includes support to hide and show the detail view (what has been referred to as the "Metro-Morph" feature).  You must discard your current Default Workspace settings and update to the latest Default Workspace in order to gain this feature.  Do you wish to update to the latest Workspace defaults for project '%@'?</string>
	<key>WindowJustification</key>
	<integer>5</integer>
	<key>WindowOrderList</key>
	<array>
		<string>383E6108086891C300865B6E</string>
		<string>/Users/jim/Desktop/TERMS/TERMS.xcodeproj</string>
	</array>
	<key>WindowString</key>
	<string>-1183 140 639 558 -1280 -256 1280 1024 </string>
	<key>WindowTools</key>
	<array>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.build</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CD0528F0623707200166675</string>
								<key>PBXProjectModuleLabel</key>
								<string></string>
								<key>StatusBarVisibility</key>
								<true/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {671, 330}}</string>
								<key>RubberWindowFrame</key>
								<string>47 118 671 612 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>330pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>XCMainBuildResultsModuleGUID</string>
								<key>PBXProjectModuleLabel</key>
								<string>Build</string>
								<key>XCBuildResultsTrigger_Collapse</key>
								<integer>1022</integer>
								<key>XCBuildResultsTrigger_Open</key>
								<integer>1010</integer>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 335}, {671, 236}}</string>
								<key>RubberWindowFrame</key>
								<string>47 118 671 612 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>PBXBuildResultsModule</string>
							<key>Proportion</key>
							<string>236pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>571pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Build Results</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXBuildResultsModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>383E6108086891C300865B6E</string>
				<string>38256C350CC8F50B005F1339</string>
				<string>1CD0528F0623707200166675</string>
				<string>XCMainBuildResultsModuleGUID</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.build</string>
			<key>WindowString</key>
			<string>47 118 671 612 0 0 1024 746 </string>
			<key>WindowToolGUID</key>
			<string>383E6108086891C300865B6E</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.debugger</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>Debugger</key>
								<dict>
									<key>HorizontalSplitView</key>
									<dict>
										<key>_collapsingFrameDimension</key>
										<real>0.0</real>
										<key>_indexOfCollapsedView</key>
										<integer>0</integer>
										<key>_percentageOfCollapsedView</key>
										<real>0.0</real>
										<key>isCollapsed</key>
										<string>yes</string>
										<key>sizes</key>
										<array>
											<string>{{0, 0}, {323, 304}}</string>
											<string>{{323, 0}, {527, 304}}</string>
										</array>
									</dict>
									<key>VerticalSplitView</key>
									<dict>
										<key>_collapsingFrameDimension</key>
										<real>0.0</real>
										<key>_indexOfCollapsedView</key>
										<integer>0</integer>
										<key>_percentageOfCollapsedView</key>
										<real>0.0</real>
										<key>isCollapsed</key>
										<string>yes</string>
										<key>sizes</key>
										<array>
											<string>{{0, 0}, {850, 304}}</string>
											<string>{{0, 304}, {850, 323}}</string>
										</array>
									</dict>
								</dict>
								<key>LauncherConfigVersion</key>
								<string>8</string>
								<key>PBXProjectModuleGUID</key>
								<string>1C162984064C10D400B95A72</string>
								<key>PBXProjectModuleLabel</key>
								<string>Debug - GLUTExamples (Underwater)</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>DebugConsoleDrawerSize</key>
								<string>{100, 120}</string>
								<key>DebugConsoleVisible</key>
								<string>None</string>
								<key>DebugConsoleWindowFrame</key>
								<string>{{200, 200}, {500, 300}}</string>
								<key>DebugSTDIOWindowFrame</key>
								<string>{{200, 200}, {500, 300}}</string>
								<key>Frame</key>
								<string>{{0, 0}, {850, 627}}</string>
								<key>RubberWindowFrame</key>
								<string>-1183 26 850 668 -1280 -256 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>PBXDebugSessionModule</string>
							<key>Proportion</key>
							<string>627pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>627pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Debugger</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXDebugSessionModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>1CD10A99069EF8BA00B06720</string>
				<string>38DFAEAD0CC8EE8500A5E164</string>
				<string>1C162984064C10D400B95A72</string>
				<string>38DFAEAE0CC8EE8500A5E164</string>
				<string>38DFAEAF0CC8EE8500A5E164</string>
				<string>38DFAEB00CC8EE8500A5E164</string>
				<string>38DFAEB10CC8EE8500A5E164</string>
				<string>38DFAEB20CC8EE8500A5E164</string>
				<string>38DFAEB30CC8EE8500A5E164</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.debug</string>
			<key>WindowString</key>
			<string>-1183 26 850 668 -1280 -256 1280 1024 </string>
			<key>WindowToolGUID</key>
			<string>1CD10A99069EF8BA00B06720</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.find</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Dock</key>
							<array>
								<dict>
									<key>ContentConfiguration</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1CDD528C0622207200134675</string>
										<key>PBXProjectModuleLabel</key>
										<string>terms.c</string>
										<key>StatusBarVisibility</key>
										<true/>
									</dict>
									<key>GeometryConfiguration</key>
									<dict>
										<key>Frame</key>
										<string>{{0, 0}, {781, 212}}</string>
										<key>RubberWindowFrame</key>
										<string>76 40 781 470 0 0 1024 746 </string>
									</dict>
									<key>Module</key>
									<string>PBXNavigatorGroup</string>
									<key>Proportion</key>
									<string>781pt</string>
								</dict>
							</array>
							<key>Proportion</key>
							<string>212pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CD0528E0623707200166675</string>
								<key>PBXProjectModuleLabel</key>
								<string>Project Find</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 217}, {781, 212}}</string>
								<key>RubberWindowFrame</key>
								<string>76 40 781 470 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>PBXProjectFindModule</string>
							<key>Proportion</key>
							<string>212pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>429pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Project Find</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXProjectFindModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>1C530D57069F1CE1000CFCEE</string>
				<string>38DFAECF0CC8F06600A5E164</string>
				<string>38DFAED00CC8F06600A5E164</string>
				<string>1CDD528C0622207200134675</string>
				<string>1CD0528E0623707200166675</string>
			</array>
			<key>WindowString</key>
			<string>76 40 781 470 0 0 1024 746 </string>
			<key>WindowToolGUID</key>
			<string>1C530D57069F1CE1000CFCEE</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>MENUSEPARATOR</string>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.debuggerConsole</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1C78EAAC065D492600B07095</string>
								<key>PBXProjectModuleLabel</key>
								<string>Debugger Console</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {508, 359}}</string>
								<key>RubberWindowFrame</key>
								<string>-576 361 508 400 -1280 -256 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>PBXDebugCLIModule</string>
							<key>Proportion</key>
							<string>359pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>359pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Debugger Console</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXDebugCLIModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>38A6DCCA086830B4001824A0</string>
				<string>38DFAEB40CC8EE8500A5E164</string>
				<string>1C78EAAC065D492600B07095</string>
			</array>
			<key>WindowString</key>
			<string>-576 361 508 400 -1280 -256 1280 1024 </string>
			<key>WindowToolGUID</key>
			<string>38A6DCCA086830B4001824A0</string>
			<key>WindowToolIsVisible</key>
			<true/>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.run</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>LauncherConfigVersion</key>
								<string>3</string>
								<key>PBXProjectModuleGUID</key>
								<string>1CD0528B0623707200166675</string>
								<key>PBXProjectModuleLabel</key>
								<string>Run</string>
								<key>Runner</key>
								<dict>
									<key>HorizontalSplitView</key>
									<dict>
										<key>_collapsingFrameDimension</key>
										<real>0.0</real>
										<key>_indexOfCollapsedView</key>
										<integer>0</integer>
										<key>_percentageOfCollapsedView</key>
										<real>0.0</real>
										<key>isCollapsed</key>
										<string>yes</string>
										<key>sizes</key>
										<array>
											<string>{{0, 0}, {493, 167}}</string>
											<string>{{0, 176}, {493, 267}}</string>
										</array>
									</dict>
									<key>VerticalSplitView</key>
									<dict>
										<key>_collapsingFrameDimension</key>
										<real>0.0</real>
										<key>_indexOfCollapsedView</key>
										<integer>0</integer>
										<key>_percentageOfCollapsedView</key>
										<real>0.0</real>
										<key>isCollapsed</key>
										<string>yes</string>
										<key>sizes</key>
										<array>
											<string>{{0, 0}, {405, 443}}</string>
											<string>{{414, 0}, {514, 443}}</string>
										</array>
									</dict>
								</dict>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {460, 159}}</string>
								<key>RubberWindowFrame</key>
								<string>316 696 459 200 0 0 1280 1002 </string>
							</dict>
							<key>Module</key>
							<string>PBXRunSessionModule</string>
							<key>Proportion</key>
							<string>159pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>159pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Run Log</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXRunSessionModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<integer>1</integer>
			<key>TableOfContents</key>
			<array>
				<string>1C0AD2B3069F1EA900FABCE6</string>
				<string>1C0AD2B4069F1EA900FABCE6</string>
				<string>1CD0528B0623707200166675</string>
				<string>1C0AD2B5069F1EA900FABCE6</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.run</string>
			<key>WindowString</key>
			<string>316 696 459 200 0 0 1280 1002 </string>
			<key>WindowToolGUID</key>
			<string>1C0AD2B3069F1EA900FABCE6</string>
			<key>WindowToolIsVisible</key>
			<integer>0</integer>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.scm</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1C78EAB2065D492600B07095</string>
								<key>PBXProjectModuleLabel</key>
								<string>&lt;No Editor&gt;</string>
								<key>PBXSplitModuleInNavigatorKey</key>
								<dict>
									<key>Split0</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1C78EAB3065D492600B07095</string>
									</dict>
									<key>SplitCount</key>
									<string>1</string>
								</dict>
								<key>StatusBarVisibility</key>
								<integer>1</integer>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {452, 0}}</string>
								<key>RubberWindowFrame</key>
								<string>743 379 452 308 0 0 1280 1002 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>0pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<integer>1</integer>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CD052920623707200166675</string>
								<key>PBXProjectModuleLabel</key>
								<string>SCM</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>ConsoleFrame</key>
								<string>{{0, 259}, {452, 0}}</string>
								<key>Frame</key>
								<string>{{0, 7}, {452, 259}}</string>
								<key>RubberWindowFrame</key>
								<string>743 379 452 308 0 0 1280 1002 </string>
								<key>TableConfiguration</key>
								<array>
									<string>Status</string>
									<real>30</real>
									<string>FileName</string>
									<real>199</real>
									<string>Path</string>
									<real>197.09500122070312</real>
								</array>
								<key>TableFrame</key>
								<string>{{0, 0}, {452, 250}}</string>
							</dict>
							<key>Module</key>
							<string>PBXCVSModule</string>
							<key>Proportion</key>
							<string>262pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>266pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>SCM</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXCVSModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<integer>1</integer>
			<key>TableOfContents</key>
			<array>
				<string>1C78EAB4065D492600B07095</string>
				<string>1C78EAB5065D492600B07095</string>
				<string>1C78EAB2065D492600B07095</string>
				<string>1CD052920623707200166675</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.scm</string>
			<key>WindowString</key>
			<string>743 379 452 308 0 0 1280 1002 </string>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.breakpoints</string>
			<key>IsVertical</key>
			<false/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXBottomSmartGroupGIDs</key>
								<array>
									<string>1C77FABC04509CD000000102</string>
								</array>
								<key>PBXProjectModuleGUID</key>
								<string>1CE0B1FE06471DED0097A5F4</string>
								<key>PBXProjectModuleLabel</key>
								<string>Files</string>
								<key>PBXProjectStructureProvided</key>
								<string>no</string>
								<key>PBXSmartGroupTreeModuleColumnData</key>
								<dict>
									<key>PBXSmartGroupTreeModuleColumnWidthsKey</key>
									<array>
										<real>168</real>
									</array>
									<key>PBXSmartGroupTreeModuleColumnsKey_v4</key>
									<array>
										<string>MainColumn</string>
									</array>
								</dict>
								<key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key>
								<dict>
									<key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key>
									<array>
										<string>1C77FABC04509CD000000102</string>
									</array>
									<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
									<array>
										<array>
											<integer>0</integer>
										</array>
									</array>
									<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
									<string>{{0, 0}, {168, 350}}</string>
								</dict>
								<key>PBXTopSmartGroupGIDs</key>
								<array/>
								<key>XCIncludePerspectivesSwitch</key>
								<false/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {185, 368}}</string>
								<key>GroupTreeTableConfiguration</key>
								<array>
									<string>MainColumn</string>
									<real>168</real>
								</array>
								<key>RubberWindowFrame</key>
								<string>79 299 744 409 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>PBXSmartGroupTreeModule</string>
							<key>Proportion</key>
							<string>185pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CA1AED706398EBD00589147</string>
								<key>PBXProjectModuleLabel</key>
								<string>Detail</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{190, 0}, {554, 368}}</string>
								<key>RubberWindowFrame</key>
								<string>79 299 744 409 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>XCDetailModule</string>
							<key>Proportion</key>
							<string>554pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>368pt</string>
				</dict>
			</array>
			<key>MajorVersion</key>
			<integer>2</integer>
			<key>MinorVersion</key>
			<integer>0</integer>
			<key>Name</key>
			<string>Breakpoints</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXSmartGroupTreeModule</string>
				<string>XCDetailModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>38DFAEB50CC8EE8500A5E164</string>
				<string>38DFAEB60CC8EE8500A5E164</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>1CA1AED706398EBD00589147</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.breakpoints</string>
			<key>WindowString</key>
			<string>79 299 744 409 0 0 1024 746 </string>
			<key>WindowToolGUID</key>
			<string>38DFAEB50CC8EE8500A5E164</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.debugAnimator</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>100%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Debug Visualizer</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXNavigatorGroup</string>
			</array>
			<key>StatusbarIsVisible</key>
			<integer>1</integer>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.debugAnimator</string>
			<key>WindowString</key>
			<string>100 100 700 500 0 0 1280 1002 </string>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.bookmarks</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Module</key>
							<string>PBXBookmarksModule</string>
							<key>Proportion</key>
							<string>100%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Bookmarks</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXBookmarksModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<integer>0</integer>
			<key>WindowString</key>
			<string>538 42 401 187 0 0 1280 1002 </string>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.classBrowser</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>BecomeActive</key>
							<integer>1</integer>
							<key>ContentConfiguration</key>
							<dict>
								<key>OptionsSetName</key>
								<string>Hierarchy, all classes</string>
								<key>PBXProjectModuleGUID</key>
								<string>1CA6456E063B45B4001379D8</string>
								<key>PBXProjectModuleLabel</key>
								<string>Class Browser - NSObject</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>ClassesFrame</key>
								<string>{{0, 0}, {374, 96}}</string>
								<key>ClassesTreeTableConfiguration</key>
								<array>
									<string>PBXClassNameColumnIdentifier</string>
									<real>208</real>
									<string>PBXClassBookColumnIdentifier</string>
									<real>22</real>
								</array>
								<key>Frame</key>
								<string>{{0, 0}, {630, 331}}</string>
								<key>MembersFrame</key>
								<string>{{0, 105}, {374, 395}}</string>
								<key>MembersTreeTableConfiguration</key>
								<array>
									<string>PBXMemberTypeIconColumnIdentifier</string>
									<real>22</real>
									<string>PBXMemberNameColumnIdentifier</string>
									<real>216</real>
									<string>PBXMemberTypeColumnIdentifier</string>
									<real>97</real>
									<string>PBXMemberBookColumnIdentifier</string>
									<real>22</real>
								</array>
								<key>PBXModuleWindowStatusBarHidden2</key>
								<integer>1</integer>
								<key>RubberWindowFrame</key>
								<string>385 179 630 352 0 0 1440 878 </string>
							</dict>
							<key>Module</key>
							<string>PBXClassBrowserModule</string>
							<key>Proportion</key>
							<string>332pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>332pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Class Browser</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXClassBrowserModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<integer>0</integer>
			<key>TableOfContents</key>
			<array>
				<string>1C0AD2AF069F1E9B00FABCE6</string>
				<string>1C0AD2B0069F1E9B00FABCE6</string>
				<string>1CA6456E063B45B4001379D8</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.classbrowser</string>
			<key>WindowString</key>
			<string>385 179 630 352 0 0 1440 878 </string>
			<key>WindowToolGUID</key>
			<string>1C0AD2AF069F1E9B00FABCE6</string>
			<key>WindowToolIsVisible</key>
			<integer>0</integer>
		</dict>
	</array>
</dict>
</plist>

Added TERMS.xcodeproj/jim.mode1v3.































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>ActivePerspectiveName</key>
	<string>Project</string>
	<key>AllowedModules</key>
	<array>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXSmartGroupTreeModule</string>
			<key>Name</key>
			<string>Groups and Files Outline View</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXNavigatorGroup</string>
			<key>Name</key>
			<string>Editor</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCTaskListModule</string>
			<key>Name</key>
			<string>Task List</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCDetailModule</string>
			<key>Name</key>
			<string>File and Smart Group Detail Viewer</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXBuildResultsModule</string>
			<key>Name</key>
			<string>Detailed Build Results Viewer</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXProjectFindModule</string>
			<key>Name</key>
			<string>Project Batch Find Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCProjectFormatConflictsModule</string>
			<key>Name</key>
			<string>Project Format Conflicts List</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXBookmarksModule</string>
			<key>Name</key>
			<string>Bookmarks Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXClassBrowserModule</string>
			<key>Name</key>
			<string>Class Browser</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXCVSModule</string>
			<key>Name</key>
			<string>Source Code Control Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXDebugBreakpointsModule</string>
			<key>Name</key>
			<string>Debug Breakpoints Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCDockableInspector</string>
			<key>Name</key>
			<string>Inspector</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>PBXOpenQuicklyModule</string>
			<key>Name</key>
			<string>Open Quickly Tool</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXDebugSessionModule</string>
			<key>Name</key>
			<string>Debugger</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>1</string>
			<key>Module</key>
			<string>PBXDebugCLIModule</string>
			<key>Name</key>
			<string>Debug Console</string>
		</dict>
		<dict>
			<key>BundleLoadPath</key>
			<string></string>
			<key>MaxInstances</key>
			<string>n</string>
			<key>Module</key>
			<string>XCSnapshotModule</string>
			<key>Name</key>
			<string>Snapshots Tool</string>
		</dict>
	</array>
	<key>Description</key>
	<string>DefaultDescriptionKey</string>
	<key>DockingSystemVisible</key>
	<false/>
	<key>Extension</key>
	<string>mode1v3</string>
	<key>FavBarConfig</key>
	<dict>
		<key>PBXProjectModuleGUID</key>
		<string>383B153A0E09A3130044C2B6</string>
		<key>XCBarModuleItemNames</key>
		<dict/>
		<key>XCBarModuleItems</key>
		<array/>
	</dict>
	<key>FirstTimeWindowDisplayed</key>
	<false/>
	<key>Identifier</key>
	<string>com.apple.perspectives.project.mode1v3</string>
	<key>MajorVersion</key>
	<integer>33</integer>
	<key>MinorVersion</key>
	<integer>0</integer>
	<key>Name</key>
	<string>Default</string>
	<key>Notifications</key>
	<array>
		<dict>
			<key>XCObserverAutoDisconnectKey</key>
			<true/>
			<key>XCObserverDefintionKey</key>
			<dict/>
			<key>XCObserverFactoryKey</key>
			<string>XCPerspectivesSpecificationIdentifier</string>
			<key>XCObserverGUIDKey</key>
			<string>XCObserverProjectIdentifier</string>
			<key>XCObserverNotificationKey</key>
			<string>PBXStatusBuildStateMessageNotification</string>
			<key>XCObserverTargetKey</key>
			<string>XCMainBuildResultsModuleGUID</string>
			<key>XCObserverTriggerKey</key>
			<string>awakenModuleWithObserver:</string>
			<key>XCObserverValidationKey</key>
			<dict/>
		</dict>
	</array>
	<key>OpenEditors</key>
	<array/>
	<key>PerspectiveWidths</key>
	<array>
		<integer>-1</integer>
		<integer>-1</integer>
	</array>
	<key>Perspectives</key>
	<array>
		<dict>
			<key>ChosenToolbarItems</key>
			<array>
				<string>active-combo-popup</string>
				<string>buildOrClean</string>
				<string>build-and-go</string>
				<string>go</string>
				<string>debugger-enable-breakpoints</string>
				<string>servicesModulebreakpoints</string>
				<string>com.apple.ide.PBXToolbarStopButton</string>
				<string>servicesModulefind</string>
			</array>
			<key>ControllerClassBaseName</key>
			<string></string>
			<key>IconName</key>
			<string>WindowOfProjectWithEditor</string>
			<key>Identifier</key>
			<string>perspective.project</string>
			<key>IsVertical</key>
			<false/>
			<key>Layout</key>
			<array>
				<dict>
					<key>BecomeActive</key>
					<true/>
					<key>ContentConfiguration</key>
					<dict>
						<key>PBXBottomSmartGroupGIDs</key>
						<array>
							<string>1C37FBAC04509CD000000102</string>
							<string>1C37FAAC04509CD000000102</string>
							<string>1C37FABC05509CD000000102</string>
							<string>1C37FABC05539CD112110102</string>
							<string>E2644B35053B69B200211256</string>
							<string>1C37FABC04509CD000100104</string>
							<string>1CC0EA4004350EF90044410B</string>
							<string>1CC0EA4004350EF90041110B</string>
						</array>
						<key>PBXProjectModuleGUID</key>
						<string>1CE0B1FE06471DED0097A5F4</string>
						<key>PBXProjectModuleLabel</key>
						<string>Files</string>
						<key>PBXProjectStructureProvided</key>
						<string>yes</string>
						<key>PBXSmartGroupTreeModuleColumnData</key>
						<dict>
							<key>PBXSmartGroupTreeModuleColumnWidthsKey</key>
							<array>
								<real>186</real>
							</array>
							<key>PBXSmartGroupTreeModuleColumnsKey_v4</key>
							<array>
								<string>MainColumn</string>
							</array>
						</dict>
						<key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key>
						<dict>
							<key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key>
							<array>
								<string>08FB7794FE84155DC02AAC07</string>
								<string>08FB7795FE84155DC02AAC07</string>
								<string>381D0BEE065AF2A80030AFEF</string>
								<string>381D0BEB065AF29F0030AFEF</string>
								<string>381D0C13065AF3620030AFEF</string>
								<string>1C37FBAC04509CD000000102</string>
								<string>1C37FAAC04509CD000000102</string>
								<string>1C37FABC05509CD000000102</string>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
							<array>
								<array>
									<integer>2</integer>
									<integer>1</integer>
									<integer>0</integer>
								</array>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
							<string>{{0, 0}, {186, 601}}</string>
						</dict>
						<key>PBXTopSmartGroupGIDs</key>
						<array/>
						<key>XCIncludePerspectivesSwitch</key>
						<true/>
						<key>XCSharingToken</key>
						<string>com.apple.Xcode.GFSharingToken</string>
					</dict>
					<key>GeometryConfiguration</key>
					<dict>
						<key>Frame</key>
						<string>{{0, 0}, {203, 619}}</string>
						<key>GroupTreeTableConfiguration</key>
						<array>
							<string>MainColumn</string>
							<real>186</real>
						</array>
						<key>RubberWindowFrame</key>
						<string>145 118 854 660 0 0 1280 778 </string>
					</dict>
					<key>Module</key>
					<string>PBXSmartGroupTreeModule</string>
					<key>Proportion</key>
					<string>203pt</string>
				</dict>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CE0B20306471E060097A5F4</string>
								<key>PBXProjectModuleLabel</key>
								<string></string>
								<key>PBXSplitModuleInNavigatorKey</key>
								<dict>
									<key>Split0</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1CE0B20406471E060097A5F4</string>
										<key>PBXProjectModuleLabel</key>
										<string></string>
									</dict>
									<key>SplitCount</key>
									<string>1</string>
								</dict>
								<key>StatusBarVisibility</key>
								<true/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {646, 0}}</string>
								<key>RubberWindowFrame</key>
								<string>145 118 854 660 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>0pt</string>
						</dict>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CE0B20506471E060097A5F4</string>
								<key>PBXProjectModuleLabel</key>
								<string>Detail</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 5}, {646, 614}}</string>
								<key>RubberWindowFrame</key>
								<string>145 118 854 660 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>XCDetailModule</string>
							<key>Proportion</key>
							<string>614pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>646pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Project</string>
			<key>ServiceClasses</key>
			<array>
				<string>XCModuleDock</string>
				<string>PBXSmartGroupTreeModule</string>
				<string>XCModuleDock</string>
				<string>PBXNavigatorGroup</string>
				<string>XCDetailModule</string>
			</array>
			<key>TableOfContents</key>
			<array>
				<string>382533B41192D61500B8B3F7</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>382533B51192D61500B8B3F7</string>
				<string>1CE0B20306471E060097A5F4</string>
				<string>1CE0B20506471E060097A5F4</string>
			</array>
			<key>ToolbarConfigUserDefaultsMinorVersion</key>
			<string>2</string>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.defaultV3</string>
		</dict>
		<dict>
			<key>ControllerClassBaseName</key>
			<string></string>
			<key>IconName</key>
			<string>WindowOfProject</string>
			<key>Identifier</key>
			<string>perspective.morph</string>
			<key>IsVertical</key>
			<false/>
			<key>Layout</key>
			<array>
				<dict>
					<key>BecomeActive</key>
					<integer>1</integer>
					<key>ContentConfiguration</key>
					<dict>
						<key>PBXBottomSmartGroupGIDs</key>
						<array>
							<string>1C37FBAC04509CD000000102</string>
							<string>1C37FAAC04509CD000000102</string>
							<string>1C08E77C0454961000C914BD</string>
							<string>1C37FABC05509CD000000102</string>
							<string>1C37FABC05539CD112110102</string>
							<string>E2644B35053B69B200211256</string>
							<string>1C37FABC04509CD000100104</string>
							<string>1CC0EA4004350EF90044410B</string>
							<string>1CC0EA4004350EF90041110B</string>
						</array>
						<key>PBXProjectModuleGUID</key>
						<string>11E0B1FE06471DED0097A5F4</string>
						<key>PBXProjectModuleLabel</key>
						<string>Files</string>
						<key>PBXProjectStructureProvided</key>
						<string>yes</string>
						<key>PBXSmartGroupTreeModuleColumnData</key>
						<dict>
							<key>PBXSmartGroupTreeModuleColumnWidthsKey</key>
							<array>
								<real>186</real>
							</array>
							<key>PBXSmartGroupTreeModuleColumnsKey_v4</key>
							<array>
								<string>MainColumn</string>
							</array>
						</dict>
						<key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key>
						<dict>
							<key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key>
							<array>
								<string>29B97314FDCFA39411CA2CEA</string>
								<string>1C37FABC05509CD000000102</string>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
							<array>
								<array>
									<integer>0</integer>
								</array>
							</array>
							<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
							<string>{{0, 0}, {186, 337}}</string>
						</dict>
						<key>PBXTopSmartGroupGIDs</key>
						<array/>
						<key>XCIncludePerspectivesSwitch</key>
						<integer>1</integer>
						<key>XCSharingToken</key>
						<string>com.apple.Xcode.GFSharingToken</string>
					</dict>
					<key>GeometryConfiguration</key>
					<dict>
						<key>Frame</key>
						<string>{{0, 0}, {203, 355}}</string>
						<key>GroupTreeTableConfiguration</key>
						<array>
							<string>MainColumn</string>
							<real>186</real>
						</array>
						<key>RubberWindowFrame</key>
						<string>373 269 690 397 0 0 1440 878 </string>
					</dict>
					<key>Module</key>
					<string>PBXSmartGroupTreeModule</string>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Morph</string>
			<key>PreferredWidth</key>
			<integer>300</integer>
			<key>ServiceClasses</key>
			<array>
				<string>XCModuleDock</string>
				<string>PBXSmartGroupTreeModule</string>
			</array>
			<key>TableOfContents</key>
			<array>
				<string>11E0B1FE06471DED0097A5F4</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.default.shortV3</string>
		</dict>
	</array>
	<key>PerspectivesBarVisible</key>
	<false/>
	<key>ShelfIsVisible</key>
	<false/>
	<key>StatusbarIsVisible</key>
	<true/>
	<key>TimeStamp</key>
	<real>294835733.69576299</real>
	<key>ToolbarDisplayMode</key>
	<integer>1</integer>
	<key>ToolbarIsVisible</key>
	<true/>
	<key>ToolbarSizeMode</key>
	<integer>1</integer>
	<key>Type</key>
	<string>Perspectives</string>
	<key>UpdateMessage</key>
	<string>The Default Workspace in this version of Xcode now includes support to hide and show the detail view (what has been referred to as the "Metro-Morph" feature).  You must discard your current Default Workspace settings and update to the latest Default Workspace in order to gain this feature.  Do you wish to update to the latest Workspace defaults for project '%@'?</string>
	<key>WindowJustification</key>
	<integer>5</integer>
	<key>WindowOrderList</key>
	<array>
		<string>38F656DC0F9771F30065A124</string>
		<string>/Users/jim/Desktop/TERMS/TERMS.xcodeproj</string>
	</array>
	<key>WindowString</key>
	<string>145 118 854 660 0 0 1280 778 </string>
	<key>WindowToolsV3</key>
	<array>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.build</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CD0528F0623707200166675</string>
								<key>PBXProjectModuleLabel</key>
								<string></string>
								<key>StatusBarVisibility</key>
								<true/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {671, 330}}</string>
								<key>RubberWindowFrame</key>
								<string>81 143 671 612 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>330pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>XCMainBuildResultsModuleGUID</string>
								<key>PBXProjectModuleLabel</key>
								<string>Build Results</string>
								<key>XCBuildResultsTrigger_Collapse</key>
								<integer>1024</integer>
								<key>XCBuildResultsTrigger_Open</key>
								<integer>1010</integer>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 335}, {671, 236}}</string>
								<key>RubberWindowFrame</key>
								<string>81 143 671 612 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXBuildResultsModule</string>
							<key>Proportion</key>
							<string>236pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>571pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Build Results</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXBuildResultsModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>38F656DC0F9771F30065A124</string>
				<string>382533B31192D61300B8B3F7</string>
				<string>1CD0528F0623707200166675</string>
				<string>XCMainBuildResultsModuleGUID</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.buildV3</string>
			<key>WindowString</key>
			<string>81 143 671 612 0 0 1280 778 </string>
			<key>WindowToolGUID</key>
			<string>38F656DC0F9771F30065A124</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.debugger</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>Debugger</key>
								<dict>
									<key>HorizontalSplitView</key>
									<dict>
										<key>_collapsingFrameDimension</key>
										<real>0.0</real>
										<key>_indexOfCollapsedView</key>
										<integer>0</integer>
										<key>_percentageOfCollapsedView</key>
										<real>0.0</real>
										<key>isCollapsed</key>
										<string>yes</string>
										<key>sizes</key>
										<array>
											<string>{{0, 0}, {351, 355}}</string>
											<string>{{351, 0}, {573, 355}}</string>
										</array>
									</dict>
									<key>VerticalSplitView</key>
									<dict>
										<key>_collapsingFrameDimension</key>
										<real>0.0</real>
										<key>_indexOfCollapsedView</key>
										<integer>0</integer>
										<key>_percentageOfCollapsedView</key>
										<real>0.0</real>
										<key>isCollapsed</key>
										<string>yes</string>
										<key>sizes</key>
										<array>
											<string>{{0, 0}, {924, 355}}</string>
											<string>{{0, 355}, {924, 316}}</string>
										</array>
									</dict>
								</dict>
								<key>LauncherConfigVersion</key>
								<string>8</string>
								<key>PBXProjectModuleGUID</key>
								<string>1C162984064C10D400B95A72</string>
								<key>PBXProjectModuleLabel</key>
								<string>Debug - GLUTExamples (Underwater)</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>DebugConsoleVisible</key>
								<string>None</string>
								<key>DebugConsoleWindowFrame</key>
								<string>{{200, 200}, {500, 300}}</string>
								<key>DebugSTDIOWindowFrame</key>
								<string>{{200, 200}, {500, 300}}</string>
								<key>Frame</key>
								<string>{{0, 0}, {924, 671}}</string>
								<key>PBXDebugSessionStackFrameViewKey</key>
								<dict>
									<key>DebugVariablesTableConfiguration</key>
									<array>
										<string>Name</string>
										<real>120</real>
										<string>Value</string>
										<real>85</real>
										<string>Summary</string>
										<real>343</real>
									</array>
									<key>Frame</key>
									<string>{{351, 0}, {573, 355}}</string>
									<key>RubberWindowFrame</key>
									<string>-1067 39 924 712 -1280 -224 1280 1024 </string>
								</dict>
								<key>RubberWindowFrame</key>
								<string>-1067 39 924 712 -1280 -224 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>PBXDebugSessionModule</string>
							<key>Proportion</key>
							<string>671pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>671pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Debugger</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXDebugSessionModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>1CD10A99069EF8BA00B06720</string>
				<string>38AFF7E8107F83560025F301</string>
				<string>1C162984064C10D400B95A72</string>
				<string>38AFF7E9107F83560025F301</string>
				<string>38AFF7EA107F83560025F301</string>
				<string>38AFF7EB107F83560025F301</string>
				<string>38AFF7EC107F83560025F301</string>
				<string>38AFF7ED107F83560025F301</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.debugV3</string>
			<key>WindowString</key>
			<string>-1067 39 924 712 -1280 -224 1280 1024 </string>
			<key>WindowToolGUID</key>
			<string>1CD10A99069EF8BA00B06720</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.find</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Dock</key>
							<array>
								<dict>
									<key>ContentConfiguration</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1CDD528C0622207200134675</string>
										<key>PBXProjectModuleLabel</key>
										<string>&lt;No Editor&gt;</string>
										<key>StatusBarVisibility</key>
										<true/>
									</dict>
									<key>GeometryConfiguration</key>
									<dict>
										<key>Frame</key>
										<string>{{0, 0}, {781, 212}}</string>
										<key>RubberWindowFrame</key>
										<string>156 99 781 470 0 0 1280 778 </string>
									</dict>
									<key>Module</key>
									<string>PBXNavigatorGroup</string>
									<key>Proportion</key>
									<string>781pt</string>
								</dict>
							</array>
							<key>Proportion</key>
							<string>212pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CD0528E0623707200166675</string>
								<key>PBXProjectModuleLabel</key>
								<string>Project Find</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 217}, {781, 212}}</string>
								<key>RubberWindowFrame</key>
								<string>156 99 781 470 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXProjectFindModule</string>
							<key>Proportion</key>
							<string>212pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>429pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Project Find</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXProjectFindModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>1C530D57069F1CE1000CFCEE</string>
				<string>3867C248106BF481009CFFD4</string>
				<string>3867C249106BF481009CFFD4</string>
				<string>1CDD528C0622207200134675</string>
				<string>1CD0528E0623707200166675</string>
			</array>
			<key>WindowString</key>
			<string>156 99 781 470 0 0 1280 778 </string>
			<key>WindowToolGUID</key>
			<string>1C530D57069F1CE1000CFCEE</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>MENUSEPARATOR</string>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.debuggerConsole</string>
			<key>IsVertical</key>
			<true/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1C78EAAC065D492600B07095</string>
								<key>PBXProjectModuleLabel</key>
								<string>Debugger Console</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {508, 359}}</string>
								<key>RubberWindowFrame</key>
								<string>-576 393 508 400 -1280 -224 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>PBXDebugCLIModule</string>
							<key>Proportion</key>
							<string>359pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>359pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Debugger Console</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXDebugCLIModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>1C78EAAD065D492600B07095</string>
				<string>38AFF7EE107F83560025F301</string>
				<string>1C78EAAC065D492600B07095</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.consoleV3</string>
			<key>WindowString</key>
			<string>-576 393 508 400 -1280 -224 1280 1024 </string>
			<key>WindowToolGUID</key>
			<string>1C78EAAD065D492600B07095</string>
			<key>WindowToolIsVisible</key>
			<true/>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.snapshots</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Module</key>
							<string>XCSnapshotModule</string>
							<key>Proportion</key>
							<string>100%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Snapshots</string>
			<key>ServiceClasses</key>
			<array>
				<string>XCSnapshotModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<string>Yes</string>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.snapshots</string>
			<key>WindowString</key>
			<string>315 824 300 550 0 0 1440 878 </string>
			<key>WindowToolIsVisible</key>
			<string>Yes</string>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.scm</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1C78EAB2065D492600B07095</string>
								<key>PBXProjectModuleLabel</key>
								<string>&lt;No Editor&gt;</string>
								<key>PBXSplitModuleInNavigatorKey</key>
								<dict>
									<key>Split0</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1C78EAB3065D492600B07095</string>
									</dict>
									<key>SplitCount</key>
									<string>1</string>
								</dict>
								<key>StatusBarVisibility</key>
								<integer>1</integer>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {452, 0}}</string>
								<key>RubberWindowFrame</key>
								<string>743 379 452 308 0 0 1280 1002 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>0pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<integer>1</integer>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CD052920623707200166675</string>
								<key>PBXProjectModuleLabel</key>
								<string>SCM</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>ConsoleFrame</key>
								<string>{{0, 259}, {452, 0}}</string>
								<key>Frame</key>
								<string>{{0, 7}, {452, 259}}</string>
								<key>RubberWindowFrame</key>
								<string>743 379 452 308 0 0 1280 1002 </string>
								<key>TableConfiguration</key>
								<array>
									<string>Status</string>
									<real>30</real>
									<string>FileName</string>
									<real>199</real>
									<string>Path</string>
									<real>197.09500122070312</real>
								</array>
								<key>TableFrame</key>
								<string>{{0, 0}, {452, 250}}</string>
							</dict>
							<key>Module</key>
							<string>PBXCVSModule</string>
							<key>Proportion</key>
							<string>262pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>266pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>SCM</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXCVSModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>1C78EAB4065D492600B07095</string>
				<string>1C78EAB5065D492600B07095</string>
				<string>1C78EAB2065D492600B07095</string>
				<string>1CD052920623707200166675</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.scm</string>
			<key>WindowString</key>
			<string>743 379 452 308 0 0 1280 1002 </string>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.breakpoints</string>
			<key>IsVertical</key>
			<false/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXBottomSmartGroupGIDs</key>
								<array>
									<string>1C77FABC04509CD000000102</string>
								</array>
								<key>PBXProjectModuleGUID</key>
								<string>1CE0B1FE06471DED0097A5F4</string>
								<key>PBXProjectModuleLabel</key>
								<string>Files</string>
								<key>PBXProjectStructureProvided</key>
								<string>no</string>
								<key>PBXSmartGroupTreeModuleColumnData</key>
								<dict>
									<key>PBXSmartGroupTreeModuleColumnWidthsKey</key>
									<array>
										<real>168</real>
									</array>
									<key>PBXSmartGroupTreeModuleColumnsKey_v4</key>
									<array>
										<string>MainColumn</string>
									</array>
								</dict>
								<key>PBXSmartGroupTreeModuleOutlineStateKey_v7</key>
								<dict>
									<key>PBXSmartGroupTreeModuleOutlineStateExpansionKey</key>
									<array>
										<string>1C77FABC04509CD000000102</string>
									</array>
									<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
									<array>
										<array>
											<integer>0</integer>
										</array>
									</array>
									<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
									<string>{{0, 0}, {168, 350}}</string>
								</dict>
								<key>PBXTopSmartGroupGIDs</key>
								<array/>
								<key>XCIncludePerspectivesSwitch</key>
								<false/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {185, 368}}</string>
								<key>GroupTreeTableConfiguration</key>
								<array>
									<string>MainColumn</string>
									<real>168</real>
								</array>
								<key>RubberWindowFrame</key>
								<string>151 327 744 409 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXSmartGroupTreeModule</string>
							<key>Proportion</key>
							<string>185pt</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>ContentConfiguration</key>
							<dict>
								<key>PBXProjectModuleGUID</key>
								<string>1CA1AED706398EBD00589147</string>
								<key>PBXProjectModuleLabel</key>
								<string>Detail</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{190, 0}, {554, 368}}</string>
								<key>RubberWindowFrame</key>
								<string>151 327 744 409 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>XCDetailModule</string>
							<key>Proportion</key>
							<string>554pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>368pt</string>
				</dict>
			</array>
			<key>MajorVersion</key>
			<integer>3</integer>
			<key>MinorVersion</key>
			<integer>0</integer>
			<key>Name</key>
			<string>Breakpoints</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXSmartGroupTreeModule</string>
				<string>XCDetailModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>TableOfContents</key>
			<array>
				<string>3867C259106BF501009CFFD4</string>
				<string>3867C25A106BF501009CFFD4</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>1CA1AED706398EBD00589147</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.breakpointsV3</string>
			<key>WindowString</key>
			<string>151 327 744 409 0 0 1280 778 </string>
			<key>WindowToolGUID</key>
			<string>3867C259106BF501009CFFD4</string>
			<key>WindowToolIsVisible</key>
			<true/>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.debugAnimator</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>100%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Debug Visualizer</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXNavigatorGroup</string>
			</array>
			<key>StatusbarIsVisible</key>
			<true/>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.debugAnimatorV3</string>
			<key>WindowString</key>
			<string>100 100 700 500 0 0 1280 1002 </string>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.bookmarks</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Module</key>
							<string>PBXBookmarksModule</string>
							<key>Proportion</key>
							<string>100%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Bookmarks</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXBookmarksModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<false/>
			<key>WindowString</key>
			<string>538 42 401 187 0 0 1280 1002 </string>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.projectFormatConflicts</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>Module</key>
							<string>XCProjectFormatConflictsModule</string>
							<key>Proportion</key>
							<string>100%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Project Format Conflicts</string>
			<key>ServiceClasses</key>
			<array>
				<string>XCProjectFormatConflictsModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<false/>
			<key>WindowContentMinSize</key>
			<string>450 300</string>
			<key>WindowString</key>
			<string>50 850 472 307 0 0 1440 877</string>
		</dict>
		<dict>
			<key>FirstTimeWindowDisplayed</key>
			<false/>
			<key>Identifier</key>
			<string>windowTool.classBrowser</string>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>BecomeActive</key>
							<integer>1</integer>
							<key>ContentConfiguration</key>
							<dict>
								<key>OptionsSetName</key>
								<string>Hierarchy, all classes</string>
								<key>PBXProjectModuleGUID</key>
								<string>1CA6456E063B45B4001379D8</string>
								<key>PBXProjectModuleLabel</key>
								<string>Class Browser - NSObject</string>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>ClassesFrame</key>
								<string>{{0, 0}, {374, 96}}</string>
								<key>ClassesTreeTableConfiguration</key>
								<array>
									<string>PBXClassNameColumnIdentifier</string>
									<real>208</real>
									<string>PBXClassBookColumnIdentifier</string>
									<real>22</real>
								</array>
								<key>Frame</key>
								<string>{{0, 0}, {630, 331}}</string>
								<key>MembersFrame</key>
								<string>{{0, 105}, {374, 395}}</string>
								<key>MembersTreeTableConfiguration</key>
								<array>
									<string>PBXMemberTypeIconColumnIdentifier</string>
									<real>22</real>
									<string>PBXMemberNameColumnIdentifier</string>
									<real>216</real>
									<string>PBXMemberTypeColumnIdentifier</string>
									<real>97</real>
									<string>PBXMemberBookColumnIdentifier</string>
									<real>22</real>
								</array>
								<key>PBXModuleWindowStatusBarHidden2</key>
								<integer>1</integer>
								<key>RubberWindowFrame</key>
								<string>385 179 630 352 0 0 1440 878 </string>
							</dict>
							<key>Module</key>
							<string>PBXClassBrowserModule</string>
							<key>Proportion</key>
							<string>332pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>332pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Class Browser</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXClassBrowserModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<false/>
			<key>TableOfContents</key>
			<array>
				<string>1C0AD2AF069F1E9B00FABCE6</string>
				<string>1C0AD2B0069F1E9B00FABCE6</string>
				<string>1CA6456E063B45B4001379D8</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.classbrowser</string>
			<key>WindowString</key>
			<string>385 179 630 352 0 0 1440 878 </string>
			<key>WindowToolGUID</key>
			<string>1C0AD2AF069F1E9B00FABCE6</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.refactoring</string>
			<key>IncludeInToolsMenu</key>
			<false/>
			<key>Layout</key>
			<array>
				<dict>
					<key>Dock</key>
					<array>
						<dict>
							<key>BecomeActive</key>
							<true/>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{0, 0}, {500, 335}</string>
								<key>RubberWindowFrame</key>
								<string>{0, 0}, {500, 335}</string>
							</dict>
							<key>Module</key>
							<string>XCRefactoringModule</string>
							<key>Proportion</key>
							<string>100%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>100%</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Refactoring</string>
			<key>ServiceClasses</key>
			<array>
				<string>XCRefactoringModule</string>
			</array>
			<key>WindowString</key>
			<string>200 200 500 356 0 0 1920 1200 </string>
		</dict>
	</array>
</dict>
</plist>

Added TERMS.xcodeproj/jim.pbxuser.









































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
// !$*UTF8*$!
{
	08FB7793FE84155DC02AAC07 /* Project object */ = {
		activeBuildConfigurationName = Development;
		activeExecutable = 381D0BE3065AF2780030AFEF /* TERMS */;
		activeTarget = 8DD76FA90486AB0100D96B5E /* TERMS */;
		addToTargets = (
			8DD76FA90486AB0100D96B5E /* TERMS */,
		);
		breakpoints = (
			380EE4090F9E4AD400D9D8E5 /* netcom.c:411 */,
			380EE4330F9E4C2500D9D8E5 /* netcom.c:406 */,
			38AFF7E2107F81520025F301 /* terms.c:256 */,
			38AFF7F9107F86920025F301 /* terms.c:232 */,
		);
		codeSenseManager = 381D0C0E065AF3380030AFEF /* Code sense */;
		executables = (
			381D0BE3065AF2780030AFEF /* TERMS */,
		);
		perUserDictionary = {
			"PBXConfiguration.PBXBreakpointsDataSource.v1:1CA1AED706398EBD00589147" = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXBreakpointsDataSource_BreakpointID;
				PBXFileTableDataSourceColumnWidthsKey = (
					20,
					20,
					210,
					20,
					110,
					109,
					20,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXBreakpointsDataSource_ActionID,
					PBXBreakpointsDataSource_TypeID,
					PBXBreakpointsDataSource_BreakpointID,
					PBXBreakpointsDataSource_UseID,
					PBXBreakpointsDataSource_LocationID,
					PBXBreakpointsDataSource_ConditionID,
					PBXBreakpointsDataSource_ContinueID,
				);
			};
			PBXConfiguration.PBXFileTableDataSource3.PBXErrorsWarningsDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXErrorsWarningsDataSource_LocationID;
				PBXFileTableDataSourceColumnWidthsKey = (
					20,
					443,
					45.20849609375,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXErrorsWarningsDataSource_TypeID,
					PBXErrorsWarningsDataSource_MessageID,
					PBXErrorsWarningsDataSource_LocationID,
				);
			};
			PBXConfiguration.PBXFileTableDataSource3.PBXExecutablesDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXExecutablesDataSource_NameID;
				PBXFileTableDataSourceColumnWidthsKey = (
					22,
					599,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXExecutablesDataSource_ActiveFlagID,
					PBXExecutablesDataSource_NameID,
				);
			};
			PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
				PBXFileTableDataSourceColumnWidthsKey = (
					20,
					428,
					20,
					27,
					43,
					43,
					20,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXFileDataSource_FiletypeID,
					PBXFileDataSource_Filename_ColumnID,
					PBXFileDataSource_Built_ColumnID,
					PBXFileDataSource_ObjectSize_ColumnID,
					PBXFileDataSource_Errors_ColumnID,
					PBXFileDataSource_Warnings_ColumnID,
					PBXFileDataSource_Target_ColumnID,
				);
			};
			PBXConfiguration.PBXFileTableDataSource3.PBXFindDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXFindDataSource_LocationID;
				PBXFileTableDataSourceColumnWidthsKey = (
					125.2974,
					127.2085,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXFindDataSource_MessageID,
					PBXFindDataSource_LocationID,
				);
			};
			PBXConfiguration.PBXFileTableDataSource3.PBXSymbolsDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = 1;
				PBXFileTableDataSourceColumnSortingKey = PBXSymbolsDataSource_SymbolTypeIconID;
				PBXFileTableDataSourceColumnWidthsKey = (
					16,
					121.8008,
					150.0356,
					127.2085,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXSymbolsDataSource_SymbolTypeIconID,
					PBXSymbolsDataSource_SymbolNameID,
					PBXSymbolsDataSource_SymbolTypeID,
					PBXSymbolsDataSource_ReferenceNameID,
				);
			};
			PBXConfiguration.PBXTargetDataSource.PBXTargetDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
				PBXFileTableDataSourceColumnWidthsKey = (
					20,
					200,
					12,
					20,
					48,
					43,
					43,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXFileDataSource_FiletypeID,
					PBXFileDataSource_Filename_ColumnID,
					PBXTargetDataSource_PrimaryAttribute,
					PBXFileDataSource_Built_ColumnID,
					PBXFileDataSource_ObjectSize_ColumnID,
					PBXFileDataSource_Errors_ColumnID,
					PBXFileDataSource_Warnings_ColumnID,
				);
			};
			PBXPerProjectTemplateStateSaveDate = 294835724;
			PBXPrepackagedSmartGroups_v2 = (
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					activationKey = OldTargetSmartGroup;
					clz = PBXTargetSmartGroup;
					description = "Displays all targets of the project.";
					globalID = 1C37FABC04509CD000000102;
					name = Targets;
					preferences = {
						image = Targets;
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = PBXTargetSmartGroup2;
					description = "Displays all targets of the project as well as nested build phases.";
					globalID = 1C37FBAC04509CD000000102;
					name = Targets;
					preferences = {
						image = Targets;
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = PBXExecutablesSmartGroup;
					description = "Displays all executables of the project.";
					globalID = 1C37FAAC04509CD000000102;
					name = Executables;
					preferences = {
						image = Executable;
					};
				},
				{
					" PBXTransientLocationAtTop " = bottom;
					absolutePathToBundle = "";
					clz = PBXErrorsWarningsSmartGroup;
					description = "Displays files with errors or warnings.";
					globalID = 1C08E77C0454961000C914BD;
					name = "Errors and Warnings";
					preferences = {
						fnmatch = "";
						image = WarningsErrors;
						recursive = 1;
						regex = "";
						root = "<PROJECT>";
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = PBXFilenameSmartGroup;
					description = "Filters items in a given group (potentially recursively) based on matching the name with the regular expression of the filter.";
					globalID = 1CC0EA4004350EF90044410B;
					name = "Implementation Files";
					preferences = {
						canSave = 1;
						fnmatch = "";
						image = SmartFolder;
						isLeaf = 0;
						recursive = 1;
						regex = "?*\\.[mcMC]";
						root = "<PROJECT>";
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = PBXFilenameSmartGroup;
					description = "This group displays Interface Builder NIB Files.";
					globalID = 1CC0EA4004350EF90041110B;
					name = "NIB Files";
					preferences = {
						canSave = 1;
						fnmatch = "*.nib";
						image = SmartFolder;
						isLeaf = 0;
						recursive = 1;
						regex = "";
						root = "<PROJECT>";
					};
				},
				{
					PBXTransientLocationAtTop = no;
					absolutePathToBundle = "";
					clz = PBXFindSmartGroup;
					description = "Displays Find Results.";
					globalID = 1C37FABC05509CD000000102;
					name = "Find Results";
					preferences = {
						image = spyglass;
					};
				},
				{
					PBXTransientLocationAtTop = no;
					absolutePathToBundle = "";
					clz = PBXBookmarksSmartGroup;
					description = "Displays Project Bookmarks.";
					globalID = 1C37FABC05539CD112110102;
					name = Bookmarks;
					preferences = {
						image = Bookmarks;
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = XCSCMSmartGroup;
					description = "Displays files with interesting SCM status.";
					globalID = E2644B35053B69B200211256;
					name = SCM;
					preferences = {
						image = PBXRepository;
						isLeaf = 0;
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = PBXSymbolsSmartGroup;
					description = "Displays all symbols for the project.";
					globalID = 1C37FABC04509CD000100104;
					name = "Project Symbols";
					preferences = {
						image = ProjectSymbols;
						isLeaf = 1;
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = PBXFilenameSmartGroup;
					description = "Filters items in a given group (potentially recursively) based on matching the name with the regular expression of the filter.";
					globalID = PBXTemplateMarker;
					name = "Simple Filter SmartGroup";
					preferences = {
						canSave = 1;
						fnmatch = "*.nib";
						image = SmartFolder;
						isLeaf = 0;
						recursive = 1;
						regex = "";
						root = "<PROJECT>";
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					absolutePathToBundle = "";
					clz = PBXFilenameSmartGroup;
					description = "Filters items in a given group (potentially recursively) based on matching the name with the regular expression of the filter.";
					globalID = PBXTemplateMarker;
					name = "Simple Regular Expression SmartGroup";
					preferences = {
						canSave = 1;
						fnmatch = "";
						image = SmartFolder;
						isLeaf = 0;
						recursive = 1;
						regex = "?*\\.[mcMC]";
						root = "<PROJECT>";
					};
				},
				{
					PBXTransientLocationAtTop = bottom;
					clz = XDDesignSmartGroup;
					description = "Displays Xdesign models";
					globalID = 2E4A936305E6979E00701470;
					name = Design;
					preferences = {
						image = Design;
						isLeaf = 0;
					};
				},
			);
			PBXWorkspaceContents = (
				{
					PBXProjectWorkspaceModule_StateKey_Rev39 = {
						PBXProjectWorkspaceModule_DataSourceSelectionKey_Rev6 = {
							BoundsStr = "{{0, 0}, {261, 559}}";
							Rows = (
								0,
							);
							VisibleRectStr = "{{0, 0}, {261, 559}}";
						};
						PBXProjectWorkspaceModule_EditorOpen = false;
						PBXProjectWorkspaceModule_EmbeddedNavigatorGroup = {
							PBXSplitModuleInNavigatorKey = {
								SplitCount = 1;
							};
						};
						PBXProjectWorkspaceModule_GeometryKey_Rev15 = {
							PBXProjectWorkspaceModule_SGTM_Geometry = {
								_collapsingFrameDimension = 0;
								_indexOfCollapsedView = 0;
								_percentageOfCollapsedView = 0;
								sizes = (
									"{{0, 0}, {182, 576}}",
									"{{182, 0}, {276, 576}}",
								);
							};
						};
						PBXProjectWorkspaceModule_OldDetailFrame = "{{0, 0}, {276, 576}}";
						PBXProjectWorkspaceModule_OldEditorFrame = "{{0, 0}, {750, 480}}";
						PBXProjectWorkspaceModule_OldSuperviewFrame = "{{182, 0}, {276, 576}}";
						PBXProjectWorkspaceModule_SGTM = {
							PBXBottomSmartGroupGIDs = (
								1C37FBAC04509CD000000102,
								1C37FAAC04509CD000000102,
								1C08E77C0454961000C914BD,
								1CC0EA4004350EF90044410B,
								1CC0EA4004350EF90041110B,
								1C37FABC05509CD000000102,
								1C37FABC05539CD112110102,
								E2644B35053B69B200211256,
								1C37FABC04509CD000100104,
							);
							PBXSmartGroupTreeModuleColumnData = {
								PBXSmartGroupTreeModuleColumnWidthsKey = (
									165,
								);
								PBXSmartGroupTreeModuleColumnsKey_v4 = (
									MainColumn,
								);
							};
							PBXSmartGroupTreeModuleOutlineStateKey_v7 = {
								PBXSmartGroupTreeModuleOutlineStateExpansionKey = (
									08FB7794FE84155DC02AAC07,
									08FB7795FE84155DC02AAC07,
									1C37FAAC04509CD000000102,
									1C37FABC05509CD000000102,
								);
								PBXSmartGroupTreeModuleOutlineStateSelectionKey = (
									(
										2,
										1,
										0,
									),
								);
								PBXSmartGroupTreeModuleOutlineStateVisibleRectKey = "{{0, 0}, {165, 558}}";
							};
							PBXTopSmartGroupGIDs = (
							);
						};
					};
				},
			);
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXBuildResultsModule" = {
			};
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXDebugBreakpointsModule" = {
			};
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXDebugCLIModule" = {
			};
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXDebugSessionModule" = {
				Debugger = {
					HorizontalSplitView = {
						_collapsingFrameDimension = 0;
						_indexOfCollapsedView = 0;
						_percentageOfCollapsedView = 0;
						isCollapsed = yes;
						sizes = (
							"{{0, 0}, {280, 250}}",
							"{{280, 0}, {468, 250}}",
						);
					};
					VerticalSplitView = {
						_collapsingFrameDimension = 0;
						_indexOfCollapsedView = 0;
						_percentageOfCollapsedView = 0;
						isCollapsed = yes;
						sizes = (
							"{{0, 0}, {748, 250}}",
							"{{0, 250}, {748, 284}}",
						);
					};
				};
				LauncherConfigVersion = 8;
			};
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXDebugSingleDataValueViewModule" = {
			};
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXNavigatorGroup" = {
				PBXSplitModuleInNavigatorKey = {
					SplitCount = 1;
				};
			};
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXProjectFindModule" = {
			};
			"PBXWorkspaceContents:PBXConfiguration.PBXModule.PBXProjectWorkspaceModule" = {
				PBXProjectWorkspaceModule_StateKey_Rev39 = {
					PBXProjectWorkspaceModule_DataSourceSelectionKey_Rev6 = {
						BoundsStr = "{{0, 0}, {261, 559}}";
						Rows = (
							0,
						);
						VisibleRectStr = "{{0, 0}, {261, 559}}";
					};
					PBXProjectWorkspaceModule_EditorOpen = false;
					PBXProjectWorkspaceModule_EmbeddedNavigatorGroup = {
						PBXSplitModuleInNavigatorKey = {
							SplitCount = 1;
						};
					};
					PBXProjectWorkspaceModule_GeometryKey_Rev15 = {
						PBXProjectWorkspaceModule_SGTM_Geometry = {
							_collapsingFrameDimension = 0;
							_indexOfCollapsedView = 0;
							_percentageOfCollapsedView = 0;
							sizes = (
								"{{0, 0}, {182, 576}}",
								"{{182, 0}, {276, 576}}",
							);
						};
					};
					PBXProjectWorkspaceModule_OldDetailFrame = "{{0, 0}, {276, 576}}";
					PBXProjectWorkspaceModule_OldEditorFrame = "{{0, 0}, {750, 480}}";
					PBXProjectWorkspaceModule_OldSuperviewFrame = "{{182, 0}, {276, 576}}";
					PBXProjectWorkspaceModule_SGTM = {
						PBXBottomSmartGroupGIDs = (
							1C37FBAC04509CD000000102,
							1C37FAAC04509CD000000102,
							1C08E77C0454961000C914BD,
							1CC0EA4004350EF90044410B,
							1CC0EA4004350EF90041110B,
							1C37FABC05509CD000000102,
							1C37FABC05539CD112110102,
							E2644B35053B69B200211256,
							1C37FABC04509CD000100104,
						);
						PBXSmartGroupTreeModuleColumnData = {
							PBXSmartGroupTreeModuleColumnWidthsKey = (
								165,
							);
							PBXSmartGroupTreeModuleColumnsKey_v4 = (
								MainColumn,
							);
						};
						PBXSmartGroupTreeModuleOutlineStateKey_v7 = {
							PBXSmartGroupTreeModuleOutlineStateExpansionKey = (
								08FB7794FE84155DC02AAC07,
								08FB7795FE84155DC02AAC07,
								1C37FAAC04509CD000000102,
								1C37FABC05509CD000000102,
							);
							PBXSmartGroupTreeModuleOutlineStateSelectionKey = (
								(
									2,
									1,
									0,
								),
							);
							PBXSmartGroupTreeModuleOutlineStateVisibleRectKey = "{{0, 0}, {165, 558}}";
						};
						PBXTopSmartGroupGIDs = (
						);
					};
				};
			};
			PBXWorkspaceGeometries = (
				{
					Frame = "{{0, 0}, {458, 576}}";
					PBXProjectWorkspaceModule_GeometryKey_Rev15 = {
					};
					RubberWindowFrame = "174 92 458 618 0 0 1024 746 ";
				},
			);
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXBuildResultsModule" = {
				Frame = "{{0, 0}, {631, 367}}";
				PBXModuleWindowStatusBarHidden = YES;
				RubberWindowFrame = "183 114 631 388 0 0 1024 746 ";
			};
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXDebugBreakpointsModule" = {
				BreakpointsTreeTableConfiguration = (
					enabledColumn,
					16,
					breakpointColumn,
					282.583,
				);
				Frame = "{{0, 0}, {208, 496}}";
				PBXModuleWindowStatusBarHidden = YES;
				RubberWindowFrame = "-976 308 208 517 -1280 -96 1280 960 ";
			};
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXDebugCLIModule" = {
				Frame = "{{0, 0}, {400, 201}}";
				PBXModuleWindowStatusBarHidden = YES;
				RubberWindowFrame = "50 718 400 222 0 0 1024 746 ";
			};
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXDebugSessionModule" = {
				DebugConsoleDrawerSize = "{100, 120}";
				DebugConsoleVisible = Drawer;
				DebugConsoleWindowFrame = "{{200, 200}, {500, 300}}";
				DebugSTDIOWindowFrame = "{{-726, 179}, {545, 489}}";
				Frame = "{{0, 0}, {748, 534}}";
				RubberWindowFrame = "50 170 748 576 0 0 1024 746 ";
			};
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXDebugSingleDataValueViewModule" = {
				Frame = "{{0, 0}, {400, 289}}";
				RubberWindowFrame = "20 303 400 331 0 0 1024 746 ";
			};
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXNavigatorGroup" = {
				Frame = "{{0, 0}, {750, 481}}";
				PBXModuleWindowStatusBarHidden = YES;
				RubberWindowFrame = "222 50 750 502 0 0 1024 746 ";
			};
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXProjectFindModule" = {
				Frame = "{{0, 0}, {614, 316}}";
				RubberWindowFrame = "183 318 614 358 0 0 1024 746 ";
			};
			"PBXWorkspaceGeometries:PBXConfiguration.PBXModule.PBXProjectWorkspaceModule" = {
				Frame = "{{0, 0}, {458, 576}}";
				PBXProjectWorkspaceModule_GeometryKey_Rev15 = {
					PBXProjectWorkspaceModule_BuildResultsWindowVisible = true;
				};
				RubberWindowFrame = "174 92 458 618 0 0 1024 746 ";
			};
			PBXWorkspaceStateSaveDate = 294835724;
		};
		sourceControlManager = 381D0C0D065AF3380030AFEF /* Source Control */;
		userBuildSettings = {
		};
	};
	380EE4090F9E4AD400D9D8E5 /* netcom.c:411 */ = {
		isa = PBXFileBreakpoint;
		actions = (
		);
		breakpointStyle = 0;
		continueAfterActions = 0;
		countType = 0;
		delayBeforeContinue = 0;
		fileReference = 381D0C00065AF2EE0030AFEF /* netcom.c */;
		functionName = "netcom_stat()";
		hitCount = 0;
		ignoreCount = 0;
		lineNumber = 411;
		location = TERMS;
		modificationTime = 276792982.580259;
		originalNumberOfMultipleMatches = 0;
		state = 2;
	};
	380EE4330F9E4C2500D9D8E5 /* netcom.c:406 */ = {
		isa = PBXFileBreakpoint;
		actions = (
		);
		breakpointStyle = 0;
		continueAfterActions = 0;
		countType = 0;
		delayBeforeContinue = 0;
		fileReference = 381D0C00065AF2EE0030AFEF /* netcom.c */;
		functionName = "netcom_stat()";
		hitCount = 0;
		ignoreCount = 0;
		lineNumber = 406;
		location = TERMS;
		modificationTime = 276792982.580295;
		originalNumberOfMultipleMatches = 0;
		state = 2;
	};
	381D0BE3065AF2780030AFEF /* TERMS */ = {
		isa = PBXExecutable;
		activeArgIndices = (
			NO,
			NO,
			NO,
			NO,
			NO,
			NO,
			NO,
			YES,
		);
		argumentStrings = (
			"-v -modem",
			"-p 1 -baud 38400 ",
			"-c test.lua",
			"-p 4 -baud 9600 -tcp_p 7004",
			"-p 3 -baud 9600 -tcp_p 7004 -tcp_p2 7005",
			"-p 1 -dtr 1",
			"-p 2",
			"-p 2 -tcp_p 1234",
		);
		autoAttachOnCrash = 1;
		breakpointsEnabled = 1;
		configStateDict = {
		};
		customDataFormattersEnabled = 1;
		dataTipCustomDataFormattersEnabled = 1;
		dataTipShowTypeColumn = 1;
		dataTipSortType = 0;
		debuggerPlugin = GDBDebugging;
		disassemblyDisplayState = 0;
		dylibVariantSuffix = "";
		enableDebugStr = 1;
		environmentEntries = (
		);
		executableSystemSymbolLevel = 0;
		executableUserSymbolLevel = 0;
		libgmallocEnabled = 0;
		name = TERMS;
		savedGlobals = {
		};
		showTypeColumn = 0;
		sourceDirectories = (
		);
		variableFormatDictionary = {
			"state-int-CTSPort" = 6;
			"state-int-DTRPort" = 6;
		};
	};
	381D0BFA065AF2DB0030AFEF /* tgtimer.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {703, 1568}}";
			sepNavSelRange = "{0, 0}";
			sepNavVisRange = "{0, 886}";
			sepNavVisRect = "{{0, 0}, {711, 429}}";
			sepNavWindowFrame = "{{81, 59}, {750, 558}}";
		};
	};
	381D0BFB065AF2DB0030AFEF /* tgtimer.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {639, 896}}";
			sepNavSelRange = "{1984, 12}";
			sepNavVisRect = "{{0, 380}, {639, 516}}";
			sepNavWindowFrame = "{{-1058, 25}, {678, 645}}";
		};
	};
	381D0C00065AF2EE0030AFEF /* netcom.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {642, 5684}}";
			sepNavSelRange = "{392, 0}";
			sepNavVisRange = "{612, 1062}";
			sepNavVisRect = "{{0, 3446}, {803, 291}}";
			sepNavWindowFrame = "{{150, 88}, {689, 690}}";
		};
	};
	381D0C01065AF2EE0030AFEF /* netcom.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {703, 1022}}";
			sepNavSelRange = "{133, 51}";
			sepNavVisRange = "{781, 894}";
			sepNavVisRect = "{{0, 93}, {705, 429}}";
			sepNavWindowFrame = "{{349, 220}, {750, 558}}";
		};
	};
	381D0C09065AF3120030AFEF /* tgtypes.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 1204}}";
			sepNavSelRange = "{618, 42}";
			sepNavVisRect = "{{0, 775}, {711, 429}}";
			sepNavWindowFrame = "{{130, 180}, {750, 558}}";
		};
	};
	381D0C0D065AF3380030AFEF /* Source Control */ = {
		isa = PBXSourceControlManager;
		fallbackIsa = XCSourceControlManager;
		isSCMEnabled = 0;
		scmConfiguration = {
			repositoryNamesForRoots = {
				"" = "";
			};
		};
		scmType = scm.cvs;
	};
	381D0C0E065AF3380030AFEF /* Code sense */ = {
		isa = PBXCodeSenseManager;
		indexTemplatePath = "";
	};
	3869B6F00662332D00AF20B2 /* lua_serial.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {732, 2884}}";
			sepNavSelRange = "{3876, 7}";
			sepNavVisRange = "{3787, 303}";
			sepNavVisRect = "{{0, 1884}, {545, 504}}";
			sepNavWindowFrame = "{{119, 57}, {584, 633}}";
		};
	};
	3869B6F50662345500AF20B2 /* lua_serial.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 429}}";
			sepNavSelRange = "{400, 0}";
			sepNavVisRect = "{{0, 0}, {711, 429}}";
			sepNavWindowFrame = "{{38, 162}, {750, 558}}";
		};
	};
	3869B70B0662446200AF20B2 /* lua_timer.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 2758}}";
			sepNavSelRange = "{2487, 11}";
			sepNavVisRect = "{{0, 0}, {711, 429}}";
			sepNavWindowFrame = "{{76, 180}, {750, 558}}";
		};
	};
	3869B712066244A600AF20B2 /* lua_timer.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 429}}";
			sepNavSelRange = "{584, 16}";
			sepNavVisRect = "{{0, 0}, {711, 429}}";
			sepNavWindowFrame = "{{-852, -16}, {750, 558}}";
		};
	};
	3869B71B06627FA600AF20B2 /* lua_net.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {506, 2744}}";
			sepNavSelRange = "{1302, 0}";
			sepNavVisRect = "{{0, 0}, {506, 560}}";
			sepNavWindowFrame = "{{332, -4}, {545, 689}}";
		};
	};
	3869B72006627FBE00AF20B2 /* lua_net.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 449}}";
			sepNavSelRange = "{694, 14}";
			sepNavVisRect = "{{0, 0}, {711, 449}}";
			sepNavWindowFrame = "{{-834, -46}, {750, 558}}";
		};
	};
	3869B75206637D7300AF20B2 /* refman-5.0.pdf */ = {
		uiCtxt = {
			sepNavWindowFrame = "{{-1127, 175}, {750, 558}}";
		};
	};
	38730C7C093FCCA9003BEB15 /* bsdserial.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {661, 11704}}";
			sepNavSelRange = "{10570, 9}";
			sepNavVisRange = "{10036, 606}";
			sepNavVisRect = "{{0, 3908}, {803, 291}}";
			sepNavWindowFrame = "{{570, 116}, {708, 650}}";
		};
	};
	38730C7D093FCCA9003BEB15 /* bsdserial.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {501, 1750}}";
			sepNavSelRange = "{2939, 7}";
			sepNavVisRange = "{2138, 856}";
			sepNavVisRect = "{{0, 1132}, {509, 520}}";
			sepNavWindowFrame = "{{243, 104}, {548, 649}}";
		};
	};
	38A58AE3065B507A00B45C7D /* terms.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {639, 12936}}";
			sepNavSelRange = "{1611, 0}";
			sepNavVisRange = "{6576, 920}";
			sepNavVisRect = "{{0, 6161}, {694, 727}}";
			sepNavWindowFrame = "{{594, 80}, {686, 683}}";
		};
	};
	38A58AE4065B507A00B45C7D /* terms.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {662, 1288}}";
			sepNavSelRange = "{0, 1328}";
			sepNavVisRange = "{1630, 802}";
			sepNavVisRect = "{{0, 0}, {682, 542}}";
			sepNavWindowFrame = "{{104, 254}, {721, 671}}";
		};
	};
	38AFF7E2107F81520025F301 /* terms.c:256 */ = {
		isa = PBXFileBreakpoint;
		actions = (
		);
		breakpointStyle = 0;
		continueAfterActions = 0;
		countType = 0;
		delayBeforeContinue = 0;
		fileReference = 38A58AE3065B507A00B45C7D /* terms.c */;
		functionName = "main()";
		hitCount = 1;
		ignoreCount = 0;
		lineNumber = 256;
		location = TERMS;
		modificationTime = 276793158.757935;
		originalNumberOfMultipleMatches = 1;
		state = 1;
	};
	38AFF7F9107F86920025F301 /* terms.c:232 */ = {
		isa = PBXFileBreakpoint;
		actions = (
		);
		breakpointStyle = 0;
		continueAfterActions = 0;
		countType = 0;
		delayBeforeContinue = 0;
		fileReference = 38A58AE3065B507A00B45C7D /* terms.c */;
		functionName = "main()";
		hitCount = 1;
		ignoreCount = 0;
		lineNumber = 232;
		location = TERMS;
		modificationTime = 276792983.140927;
		originalNumberOfMultipleMatches = 1;
		state = 1;
	};
	38FAA7FE0660D37600191844 /* lua.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 5488}}";
			sepNavSelRange = "{6631, 61}";
			sepNavVisRect = "{{0, 3195}, {711, 429}}";
			sepNavWindowFrame = "{{-1150, 196}, {750, 558}}";
		};
	};
	38FAA7FF0660D37600191844 /* lualib.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 797}}";
			sepNavSelRange = "{566, 31}";
			sepNavVisRect = "{{0, 84}, {711, 449}}";
			sepNavWindowFrame = "{{15, 183}, {750, 558}}";
		};
	};
	38FAA80E0660D41B00191844 /* lapi.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {705, 12922}}";
			sepNavSelRange = "{13420, 64}";
			sepNavVisRect = "{{0, 8879}, {705, 429}}";
			sepNavWindowFrame = "{{207, 134}, {750, 558}}";
		};
	};
	38FAA8110660D41B00191844 /* lcode.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 1049}}";
			sepNavSelRange = "{486, 48}";
			sepNavVisRect = "{{0, 0}, {711, 449}}";
			sepNavWindowFrame = "{{-1081, 133}, {750, 558}}";
		};
	};
	38FAA8140660D41B00191844 /* ldo.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {709, 6607}}";
			sepNavSelRange = "{7283, 0}";
			sepNavVisRect = "{{0, 3537}, {709, 249}}";
		};
	};
	38FAA8350660D43900191844 /* lstate.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 3093}}";
			sepNavSelRange = "{4586, 37}";
			sepNavVisRect = "{{0, 2303}, {711, 449}}";
			sepNavWindowFrame = "{{84, 120}, {750, 558}}";
		};
	};
	38FAA8360660D43900191844 /* lstate.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 2813}}";
			sepNavSelRange = "{3315, 9}";
			sepNavVisRect = "{{0, 1897}, {711, 449}}";
			sepNavWindowFrame = "{{38, 162}, {750, 558}}";
		};
	};
	38FAA8370660D43900191844 /* lstring.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {809, 1442}}";
			sepNavSelRange = "{2245, 0}";
			sepNavVisRect = "{{0, 972}, {809, 366}}";
		};
	};
	38FAA8650660D47E00191844 /* lauxlib.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 8287}}";
			sepNavSelRange = "{14811, 6}";
			sepNavVisRect = "{{0, 7833}, {711, 449}}";
			sepNavWindowFrame = "{{-1081, 133}, {750, 558}}";
		};
	};
	38FAA8690660D47E00191844 /* lmathlib.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {711, 3457}}";
			sepNavSelRange = "{5207, 312}";
			sepNavVisRect = "{{0, 3008}, {711, 449}}";
			sepNavWindowFrame = "{{-922, 75}, {750, 558}}";
		};
	};
	38FAA86B0660D47E00191844 /* lstrlib.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {622, 11004}}";
			sepNavSelRange = "{17008, 0}";
			sepNavVisRange = "{16684, 631}";
		};
	};
	38FAA86C0660D47E00191844 /* ltablib.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {606, 3514}}";
			sepNavSelRange = "{0, 0}";
			sepNavVisRect = "{{0, 0}, {606, 562}}";
			sepNavWindowFrame = "{{15, 50}, {645, 691}}";
		};
	};
	8DD76FA90486AB0100D96B5E /* TERMS */ = {
		activeExec = 0;
		executables = (
			381D0BE3065AF2780030AFEF /* TERMS */,
		);
	};
}

Added TERMS.xcodeproj/project.pbxproj.

































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
// !$*UTF8*$!
{
	archiveVersion = 1;
	classes = {
	};
	objectVersion = 46;
	objects = {

/* Begin PBXBuildFile section */
		381D0BFC065AF2DB0030AFEF /* tgtimer.c in Sources */ = {isa = PBXBuildFile; fileRef = 381D0BFA065AF2DB0030AFEF /* tgtimer.c */; };
		381D0BFD065AF2DB0030AFEF /* tgtimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 381D0BFB065AF2DB0030AFEF /* tgtimer.h */; };
		381D0C02065AF2EE0030AFEF /* netcom.c in Sources */ = {isa = PBXBuildFile; fileRef = 381D0C00065AF2EE0030AFEF /* netcom.c */; };
		381D0C03065AF2EE0030AFEF /* netcom.h in Headers */ = {isa = PBXBuildFile; fileRef = 381D0C01065AF2EE0030AFEF /* netcom.h */; };
		381D0C0A065AF3120030AFEF /* tgtypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 381D0C09065AF3120030AFEF /* tgtypes.h */; };
		381D0C17065AF37D0030AFEF /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 381D0C16065AF37D0030AFEF /* IOKit.framework */; };
		381D0CB6065AF38E0030AFEF /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 381D0CB5065AF38E0030AFEF /* CoreFoundation.framework */; };
		3869B6F10662332D00AF20B2 /* lua_serial.c in Sources */ = {isa = PBXBuildFile; fileRef = 3869B6F00662332D00AF20B2 /* lua_serial.c */; };
		3869B6F60662345500AF20B2 /* lua_serial.h in Headers */ = {isa = PBXBuildFile; fileRef = 3869B6F50662345500AF20B2 /* lua_serial.h */; };
		3869B70C0662446200AF20B2 /* lua_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = 3869B70B0662446200AF20B2 /* lua_timer.c */; };
		3869B713066244A600AF20B2 /* lua_timer.h in Headers */ = {isa = PBXBuildFile; fileRef = 3869B712066244A600AF20B2 /* lua_timer.h */; };
		3869B71C06627FA600AF20B2 /* lua_net.c in Sources */ = {isa = PBXBuildFile; fileRef = 3869B71B06627FA600AF20B2 /* lua_net.c */; };
		3869B72106627FBE00AF20B2 /* lua_net.h in Headers */ = {isa = PBXBuildFile; fileRef = 3869B72006627FBE00AF20B2 /* lua_net.h */; };
		3869B75306637D7300AF20B2 /* refman-5.0.pdf in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3869B75206637D7300AF20B2 /* refman-5.0.pdf */; };
		38730C7E093FCCA9003BEB15 /* bsdserial.c in Sources */ = {isa = PBXBuildFile; fileRef = 38730C7C093FCCA9003BEB15 /* bsdserial.c */; };
		38730C7F093FCCA9003BEB15 /* bsdserial.h in Headers */ = {isa = PBXBuildFile; fileRef = 38730C7D093FCCA9003BEB15 /* bsdserial.h */; };
		38A58AE5065B507A00B45C7D /* terms.c in Sources */ = {isa = PBXBuildFile; fileRef = 38A58AE3065B507A00B45C7D /* terms.c */; };
		38A58AE6065B507A00B45C7D /* terms.h in Headers */ = {isa = PBXBuildFile; fileRef = 38A58AE4065B507A00B45C7D /* terms.h */; };
		38CBD7380692DF4000E97226 /* TERMS.pdf in CopyFiles */ = {isa = PBXBuildFile; fileRef = 38CBD7370692DF4000E97226 /* TERMS.pdf */; };
		38FAA8000660D37600191844 /* lauxlib.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA7FD0660D37600191844 /* lauxlib.h */; };
		38FAA8010660D37600191844 /* lua.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA7FE0660D37600191844 /* lua.h */; };
		38FAA8020660D37600191844 /* lualib.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA7FF0660D37600191844 /* lualib.h */; };
		38FAA81B0660D41B00191844 /* lapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA80E0660D41B00191844 /* lapi.c */; };
		38FAA81C0660D41B00191844 /* lapi.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA80F0660D41B00191844 /* lapi.h */; };
		38FAA81D0660D41B00191844 /* lcode.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8100660D41B00191844 /* lcode.c */; };
		38FAA81E0660D41B00191844 /* lcode.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8110660D41B00191844 /* lcode.h */; };
		38FAA81F0660D41B00191844 /* ldebug.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8120660D41B00191844 /* ldebug.c */; };
		38FAA8200660D41B00191844 /* ldebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8130660D41B00191844 /* ldebug.h */; };
		38FAA8210660D41B00191844 /* ldo.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8140660D41B00191844 /* ldo.c */; };
		38FAA8220660D41B00191844 /* ldo.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8150660D41B00191844 /* ldo.h */; };
		38FAA8230660D41B00191844 /* ldump.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8160660D41B00191844 /* ldump.c */; };
		38FAA8240660D41B00191844 /* lfunc.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8170660D41B00191844 /* lfunc.c */; };
		38FAA8250660D41B00191844 /* lfunc.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8180660D41B00191844 /* lfunc.h */; };
		38FAA8260660D41B00191844 /* lgc.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8190660D41B00191844 /* lgc.c */; };
		38FAA8270660D41B00191844 /* lgc.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA81A0660D41B00191844 /* lgc.h */; };
		38FAA83E0660D43900191844 /* llex.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA82A0660D43900191844 /* llex.c */; };
		38FAA83F0660D43900191844 /* llex.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA82B0660D43900191844 /* llex.h */; };
		38FAA8400660D43900191844 /* llimits.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA82C0660D43900191844 /* llimits.h */; };
		38FAA8410660D43900191844 /* lmem.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA82D0660D43900191844 /* lmem.c */; };
		38FAA8420660D43900191844 /* lmem.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA82E0660D43900191844 /* lmem.h */; };
		38FAA8430660D43900191844 /* lobject.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA82F0660D43900191844 /* lobject.c */; };
		38FAA8440660D43900191844 /* lobject.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8300660D43900191844 /* lobject.h */; };
		38FAA8450660D43900191844 /* lopcodes.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8310660D43900191844 /* lopcodes.c */; };
		38FAA8460660D43900191844 /* lopcodes.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8320660D43900191844 /* lopcodes.h */; };
		38FAA8470660D43900191844 /* lparser.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8330660D43900191844 /* lparser.c */; };
		38FAA8480660D43900191844 /* lparser.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8340660D43900191844 /* lparser.h */; };
		38FAA8490660D43900191844 /* lstate.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8350660D43900191844 /* lstate.c */; };
		38FAA84A0660D43900191844 /* lstate.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8360660D43900191844 /* lstate.h */; };
		38FAA84B0660D43900191844 /* lstring.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8370660D43900191844 /* lstring.c */; };
		38FAA84C0660D43900191844 /* lstring.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8380660D43900191844 /* lstring.h */; };
		38FAA84D0660D43900191844 /* ltable.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8390660D43900191844 /* ltable.c */; };
		38FAA84E0660D43900191844 /* ltable.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA83A0660D43900191844 /* ltable.h */; };
		38FAA84F0660D43900191844 /* ltests.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA83B0660D43900191844 /* ltests.c */; };
		38FAA8500660D43900191844 /* ltm.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA83C0660D43900191844 /* ltm.c */; };
		38FAA8510660D43900191844 /* ltm.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA83D0660D43900191844 /* ltm.h */; };
		38FAA85A0660D45400191844 /* lundump.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8540660D45400191844 /* lundump.c */; };
		38FAA85B0660D45400191844 /* lundump.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8550660D45400191844 /* lundump.h */; };
		38FAA85C0660D45400191844 /* lvm.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8560660D45400191844 /* lvm.c */; };
		38FAA85D0660D45400191844 /* lvm.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8570660D45400191844 /* lvm.h */; };
		38FAA85E0660D45400191844 /* lzio.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8580660D45400191844 /* lzio.c */; };
		38FAA85F0660D45400191844 /* lzio.h in Headers */ = {isa = PBXBuildFile; fileRef = 38FAA8590660D45400191844 /* lzio.h */; };
		38FAA86D0660D47E00191844 /* lauxlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8650660D47E00191844 /* lauxlib.c */; };
		38FAA86E0660D47E00191844 /* lbaselib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8660660D47E00191844 /* lbaselib.c */; };
		38FAA86F0660D47E00191844 /* ldblib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8670660D47E00191844 /* ldblib.c */; };
		38FAA8700660D47E00191844 /* liolib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8680660D47E00191844 /* liolib.c */; };
		38FAA8710660D47E00191844 /* lmathlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA8690660D47E00191844 /* lmathlib.c */; };
		38FAA8720660D47E00191844 /* loadlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA86A0660D47E00191844 /* loadlib.c */; };
		38FAA8730660D47E00191844 /* lstrlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA86B0660D47E00191844 /* lstrlib.c */; };
		38FAA8740660D47E00191844 /* ltablib.c in Sources */ = {isa = PBXBuildFile; fileRef = 38FAA86C0660D47E00191844 /* ltablib.c */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
		8DD76FAF0486AB0100D96B5E /* CopyFiles */ = {
			isa = PBXCopyFilesBuildPhase;
			buildActionMask = 8;
			dstPath = /usr/share/man/man1/;
			dstSubfolderSpec = 0;
			files = (
				3869B75306637D7300AF20B2 /* refman-5.0.pdf in CopyFiles */,
				38CBD7380692DF4000E97226 /* TERMS.pdf in CopyFiles */,
			);
			runOnlyForDeploymentPostprocessing = 1;
		};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
		381D0BFA065AF2DB0030AFEF /* tgtimer.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = tgtimer.c; sourceTree = SOURCE_ROOT; };
		381D0BFB065AF2DB0030AFEF /* tgtimer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = tgtimer.h; sourceTree = SOURCE_ROOT; };
		381D0C00065AF2EE0030AFEF /* netcom.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = netcom.c; path = COMS/netcom.c; sourceTree = SOURCE_ROOT; };
		381D0C01065AF2EE0030AFEF /* netcom.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = netcom.h; path = COMS/netcom.h; sourceTree = SOURCE_ROOT; };
		381D0C09065AF3120030AFEF /* tgtypes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = tgtypes.h; sourceTree = SOURCE_ROOT; };
		381D0C16065AF37D0030AFEF /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = ../../../../../System/Library/Frameworks/IOKit.framework; sourceTree = SOURCE_ROOT; };
		381D0CB5065AF38E0030AFEF /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = ../../../../../System/Library/Frameworks/CoreFoundation.framework; sourceTree = SOURCE_ROOT; };
		3869B6F00662332D00AF20B2 /* lua_serial.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = lua_serial.c; path = TGLuaLibs/lua_serial.c; sourceTree = SOURCE_ROOT; };
		3869B6F50662345500AF20B2 /* lua_serial.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lua_serial.h; path = TGLuaLibs/lua_serial.h; sourceTree = SOURCE_ROOT; };
		3869B70B0662446200AF20B2 /* lua_timer.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lua_timer.c; path = TGLuaLibs/lua_timer.c; sourceTree = SOURCE_ROOT; };
		3869B712066244A600AF20B2 /* lua_timer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lua_timer.h; path = TGLuaLibs/lua_timer.h; sourceTree = SOURCE_ROOT; };
		3869B71B06627FA600AF20B2 /* lua_net.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lua_net.c; path = TGLuaLibs/lua_net.c; sourceTree = SOURCE_ROOT; };
		3869B72006627FBE00AF20B2 /* lua_net.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lua_net.h; path = TGLuaLibs/lua_net.h; sourceTree = SOURCE_ROOT; };
		3869B75206637D7300AF20B2 /* refman-5.0.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = "refman-5.0.pdf"; sourceTree = SOURCE_ROOT; };
		38730C7C093FCCA9003BEB15 /* bsdserial.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.c; fileEncoding = 30; name = bsdserial.c; path = SERIAL/OSX/bsdserial.c; sourceTree = SOURCE_ROOT; };
		38730C7D093FCCA9003BEB15 /* bsdserial.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = bsdserial.h; path = SERIAL/OSX/bsdserial.h; sourceTree = SOURCE_ROOT; };
		38A58AE3065B507A00B45C7D /* terms.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = terms.c; sourceTree = SOURCE_ROOT; };
		38A58AE4065B507A00B45C7D /* terms.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = terms.h; sourceTree = SOURCE_ROOT; };
		38CBD7370692DF4000E97226 /* TERMS.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = TERMS.pdf; path = ../../DOCS/TERMS.pdf; sourceTree = SOURCE_ROOT; };
		38FAA7FD0660D37600191844 /* lauxlib.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lauxlib.h; path = "lua-5.0.2/include/lauxlib.h"; sourceTree = SOURCE_ROOT; };
		38FAA7FE0660D37600191844 /* lua.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lua.h; path = "lua-5.0.2/include/lua.h"; sourceTree = SOURCE_ROOT; };
		38FAA7FF0660D37600191844 /* lualib.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lualib.h; path = "lua-5.0.2/include/lualib.h"; sourceTree = SOURCE_ROOT; };
		38FAA80E0660D41B00191844 /* lapi.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lapi.c; path = "lua-5.0.2/src/lapi.c"; sourceTree = SOURCE_ROOT; };
		38FAA80F0660D41B00191844 /* lapi.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lapi.h; path = "lua-5.0.2/src/lapi.h"; sourceTree = SOURCE_ROOT; };
		38FAA8100660D41B00191844 /* lcode.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lcode.c; path = "lua-5.0.2/src/lcode.c"; sourceTree = SOURCE_ROOT; };
		38FAA8110660D41B00191844 /* lcode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lcode.h; path = "lua-5.0.2/src/lcode.h"; sourceTree = SOURCE_ROOT; };
		38FAA8120660D41B00191844 /* ldebug.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldebug.c; path = "lua-5.0.2/src/ldebug.c"; sourceTree = SOURCE_ROOT; };
		38FAA8130660D41B00191844 /* ldebug.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ldebug.h; path = "lua-5.0.2/src/ldebug.h"; sourceTree = SOURCE_ROOT; };
		38FAA8140660D41B00191844 /* ldo.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldo.c; path = "lua-5.0.2/src/ldo.c"; sourceTree = SOURCE_ROOT; };
		38FAA8150660D41B00191844 /* ldo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ldo.h; path = "lua-5.0.2/src/ldo.h"; sourceTree = SOURCE_ROOT; };
		38FAA8160660D41B00191844 /* ldump.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldump.c; path = "lua-5.0.2/src/ldump.c"; sourceTree = SOURCE_ROOT; };
		38FAA8170660D41B00191844 /* lfunc.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lfunc.c; path = "lua-5.0.2/src/lfunc.c"; sourceTree = SOURCE_ROOT; };
		38FAA8180660D41B00191844 /* lfunc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lfunc.h; path = "lua-5.0.2/src/lfunc.h"; sourceTree = SOURCE_ROOT; };
		38FAA8190660D41B00191844 /* lgc.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lgc.c; path = "lua-5.0.2/src/lgc.c"; sourceTree = SOURCE_ROOT; };
		38FAA81A0660D41B00191844 /* lgc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lgc.h; path = "lua-5.0.2/src/lgc.h"; sourceTree = SOURCE_ROOT; };
		38FAA82A0660D43900191844 /* llex.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = llex.c; path = "lua-5.0.2/src/llex.c"; sourceTree = SOURCE_ROOT; };
		38FAA82B0660D43900191844 /* llex.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = llex.h; path = "lua-5.0.2/src/llex.h"; sourceTree = SOURCE_ROOT; };
		38FAA82C0660D43900191844 /* llimits.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = llimits.h; path = "lua-5.0.2/src/llimits.h"; sourceTree = SOURCE_ROOT; };
		38FAA82D0660D43900191844 /* lmem.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lmem.c; path = "lua-5.0.2/src/lmem.c"; sourceTree = SOURCE_ROOT; };
		38FAA82E0660D43900191844 /* lmem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lmem.h; path = "lua-5.0.2/src/lmem.h"; sourceTree = SOURCE_ROOT; };
		38FAA82F0660D43900191844 /* lobject.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lobject.c; path = "lua-5.0.2/src/lobject.c"; sourceTree = SOURCE_ROOT; };
		38FAA8300660D43900191844 /* lobject.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lobject.h; path = "lua-5.0.2/src/lobject.h"; sourceTree = SOURCE_ROOT; };
		38FAA8310660D43900191844 /* lopcodes.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lopcodes.c; path = "lua-5.0.2/src/lopcodes.c"; sourceTree = SOURCE_ROOT; };
		38FAA8320660D43900191844 /* lopcodes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lopcodes.h; path = "lua-5.0.2/src/lopcodes.h"; sourceTree = SOURCE_ROOT; };
		38FAA8330660D43900191844 /* lparser.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lparser.c; path = "lua-5.0.2/src/lparser.c"; sourceTree = SOURCE_ROOT; };
		38FAA8340660D43900191844 /* lparser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lparser.h; path = "lua-5.0.2/src/lparser.h"; sourceTree = SOURCE_ROOT; };
		38FAA8350660D43900191844 /* lstate.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lstate.c; path = "lua-5.0.2/src/lstate.c"; sourceTree = SOURCE_ROOT; };
		38FAA8360660D43900191844 /* lstate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lstate.h; path = "lua-5.0.2/src/lstate.h"; sourceTree = SOURCE_ROOT; };
		38FAA8370660D43900191844 /* lstring.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lstring.c; path = "lua-5.0.2/src/lstring.c"; sourceTree = SOURCE_ROOT; };
		38FAA8380660D43900191844 /* lstring.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lstring.h; path = "lua-5.0.2/src/lstring.h"; sourceTree = SOURCE_ROOT; };
		38FAA8390660D43900191844 /* ltable.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltable.c; path = "lua-5.0.2/src/ltable.c"; sourceTree = SOURCE_ROOT; };
		38FAA83A0660D43900191844 /* ltable.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ltable.h; path = "lua-5.0.2/src/ltable.h"; sourceTree = SOURCE_ROOT; };
		38FAA83B0660D43900191844 /* ltests.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltests.c; path = "lua-5.0.2/src/ltests.c"; sourceTree = SOURCE_ROOT; };
		38FAA83C0660D43900191844 /* ltm.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltm.c; path = "lua-5.0.2/src/ltm.c"; sourceTree = SOURCE_ROOT; };
		38FAA83D0660D43900191844 /* ltm.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ltm.h; path = "lua-5.0.2/src/ltm.h"; sourceTree = SOURCE_ROOT; };
		38FAA8540660D45400191844 /* lundump.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lundump.c; path = "lua-5.0.2/src/lundump.c"; sourceTree = SOURCE_ROOT; };
		38FAA8550660D45400191844 /* lundump.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lundump.h; path = "lua-5.0.2/src/lundump.h"; sourceTree = SOURCE_ROOT; };
		38FAA8560660D45400191844 /* lvm.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lvm.c; path = "lua-5.0.2/src/lvm.c"; sourceTree = SOURCE_ROOT; };
		38FAA8570660D45400191844 /* lvm.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lvm.h; path = "lua-5.0.2/src/lvm.h"; sourceTree = SOURCE_ROOT; };
		38FAA8580660D45400191844 /* lzio.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lzio.c; path = "lua-5.0.2/src/lzio.c"; sourceTree = SOURCE_ROOT; };
		38FAA8590660D45400191844 /* lzio.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lzio.h; path = "lua-5.0.2/src/lzio.h"; sourceTree = SOURCE_ROOT; };
		38FAA8650660D47E00191844 /* lauxlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lauxlib.c; path = "lua-5.0.2/src/lib/lauxlib.c"; sourceTree = SOURCE_ROOT; };
		38FAA8660660D47E00191844 /* lbaselib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lbaselib.c; path = "lua-5.0.2/src/lib/lbaselib.c"; sourceTree = SOURCE_ROOT; };
		38FAA8670660D47E00191844 /* ldblib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldblib.c; path = "lua-5.0.2/src/lib/ldblib.c"; sourceTree = SOURCE_ROOT; };
		38FAA8680660D47E00191844 /* liolib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = liolib.c; path = "lua-5.0.2/src/lib/liolib.c"; sourceTree = SOURCE_ROOT; };
		38FAA8690660D47E00191844 /* lmathlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lmathlib.c; path = "lua-5.0.2/src/lib/lmathlib.c"; sourceTree = SOURCE_ROOT; };
		38FAA86A0660D47E00191844 /* loadlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = loadlib.c; path = "lua-5.0.2/src/lib/loadlib.c"; sourceTree = SOURCE_ROOT; };
		38FAA86B0660D47E00191844 /* lstrlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lstrlib.c; path = "lua-5.0.2/src/lib/lstrlib.c"; sourceTree = SOURCE_ROOT; };
		38FAA86C0660D47E00191844 /* ltablib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltablib.c; path = "lua-5.0.2/src/lib/ltablib.c"; sourceTree = SOURCE_ROOT; };
		8DD76FB20486AB0100D96B5E /* TERMS */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TERMS; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
		8DD76FAD0486AB0100D96B5E /* Frameworks */ = {
			isa = PBXFrameworksBuildPhase;
			buildActionMask = 2147483647;
			files = (
				381D0C17065AF37D0030AFEF /* IOKit.framework in Frameworks */,
				381D0CB6065AF38E0030AFEF /* CoreFoundation.framework in Frameworks */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
		08FB7794FE84155DC02AAC07 /* TERMS */ = {
			isa = PBXGroup;
			children = (
				08FB7795FE84155DC02AAC07 /* Source */,
				381D0C13065AF3620030AFEF /* External Frameworks */,
				C6A0FF2B0290797F04C91782 /* Documentation */,
				1AB674ADFE9D54B511CA2CBB /* Products */,
			);
			name = TERMS;
			sourceTree = "<group>";
		};
		08FB7795FE84155DC02AAC07 /* Source */ = {
			isa = PBXGroup;
			children = (
				38A58AE3065B507A00B45C7D /* terms.c */,
				38A58AE4065B507A00B45C7D /* terms.h */,
				38FAA7F40660D32800191844 /* LUA */,
				381D0BEE065AF2A80030AFEF /* Serial */,
				381D0BEB065AF29F0030AFEF /* Network */,
				381D0C06065AF2FE0030AFEF /* Include */,
			);
			name = Source;
			sourceTree = "<group>";
		};
		1AB674ADFE9D54B511CA2CBB /* Products */ = {
			isa = PBXGroup;
			children = (
				8DD76FB20486AB0100D96B5E /* TERMS */,
			);
			name = Products;
			sourceTree = "<group>";
		};
		381D0BEB065AF29F0030AFEF /* Network */ = {
			isa = PBXGroup;
			children = (
				381D0C00065AF2EE0030AFEF /* netcom.c */,
				381D0C01065AF2EE0030AFEF /* netcom.h */,
			);
			name = Network;
			sourceTree = "<group>";
		};
		381D0BEE065AF2A80030AFEF /* Serial */ = {
			isa = PBXGroup;
			children = (
				38730C7C093FCCA9003BEB15 /* bsdserial.c */,
				38730C7D093FCCA9003BEB15 /* bsdserial.h */,
				381D0BFA065AF2DB0030AFEF /* tgtimer.c */,
				381D0BFB065AF2DB0030AFEF /* tgtimer.h */,
			);
			name = Serial;
			sourceTree = "<group>";
		};
		381D0C06065AF2FE0030AFEF /* Include */ = {
			isa = PBXGroup;
			children = (
				381D0C09065AF3120030AFEF /* tgtypes.h */,
			);
			name = Include;
			sourceTree = "<group>";
		};
		381D0C13065AF3620030AFEF /* External Frameworks */ = {
			isa = PBXGroup;
			children = (
				381D0CB5065AF38E0030AFEF /* CoreFoundation.framework */,
				381D0C16065AF37D0030AFEF /* IOKit.framework */,
			);
			name = "External Frameworks";
			sourceTree = "<group>";
		};
		38FAA7F40660D32800191844 /* LUA */ = {
			isa = PBXGroup;
			children = (
				38FAA8770660DBA800191844 /* TERMS Lib */,
				38FAA8620660D46000191844 /* Libraries */,
				38FAA8050660D38200191844 /* CORE */,
				38FAA7FA0660D35600191844 /* Include */,
			);
			name = LUA;
			sourceTree = "<group>";
		};
		38FAA7FA0660D35600191844 /* Include */ = {
			isa = PBXGroup;
			children = (
				38FAA7FD0660D37600191844 /* lauxlib.h */,
				38FAA7FE0660D37600191844 /* lua.h */,
				38FAA7FF0660D37600191844 /* lualib.h */,
			);
			name = Include;
			sourceTree = "<group>";
		};
		38FAA8050660D38200191844 /* CORE */ = {
			isa = PBXGroup;
			children = (
				38FAA8540660D45400191844 /* lundump.c */,
				38FAA8550660D45400191844 /* lundump.h */,
				38FAA8560660D45400191844 /* lvm.c */,
				38FAA8570660D45400191844 /* lvm.h */,
				38FAA8580660D45400191844 /* lzio.c */,
				38FAA8590660D45400191844 /* lzio.h */,
				38FAA82A0660D43900191844 /* llex.c */,
				38FAA82B0660D43900191844 /* llex.h */,
				38FAA82C0660D43900191844 /* llimits.h */,
				38FAA82D0660D43900191844 /* lmem.c */,
				38FAA82E0660D43900191844 /* lmem.h */,
				38FAA82F0660D43900191844 /* lobject.c */,
				38FAA8300660D43900191844 /* lobject.h */,
				38FAA8310660D43900191844 /* lopcodes.c */,
				38FAA8320660D43900191844 /* lopcodes.h */,
				38FAA8330660D43900191844 /* lparser.c */,
				38FAA8340660D43900191844 /* lparser.h */,
				38FAA8350660D43900191844 /* lstate.c */,
				38FAA8360660D43900191844 /* lstate.h */,
				38FAA8370660D43900191844 /* lstring.c */,
				38FAA8380660D43900191844 /* lstring.h */,
				38FAA8390660D43900191844 /* ltable.c */,
				38FAA83A0660D43900191844 /* ltable.h */,
				38FAA83B0660D43900191844 /* ltests.c */,
				38FAA83C0660D43900191844 /* ltm.c */,
				38FAA83D0660D43900191844 /* ltm.h */,
				38FAA80E0660D41B00191844 /* lapi.c */,
				38FAA80F0660D41B00191844 /* lapi.h */,
				38FAA8100660D41B00191844 /* lcode.c */,
				38FAA8110660D41B00191844 /* lcode.h */,
				38FAA8120660D41B00191844 /* ldebug.c */,
				38FAA8130660D41B00191844 /* ldebug.h */,
				38FAA8140660D41B00191844 /* ldo.c */,
				38FAA8150660D41B00191844 /* ldo.h */,
				38FAA8160660D41B00191844 /* ldump.c */,
				38FAA8170660D41B00191844 /* lfunc.c */,
				38FAA8180660D41B00191844 /* lfunc.h */,
				38FAA8190660D41B00191844 /* lgc.c */,
				38FAA81A0660D41B00191844 /* lgc.h */,
			);
			name = CORE;
			sourceTree = "<group>";
		};
		38FAA8620660D46000191844 /* Libraries */ = {
			isa = PBXGroup;
			children = (
				38FAA8650660D47E00191844 /* lauxlib.c */,
				38FAA8660660D47E00191844 /* lbaselib.c */,
				38FAA8670660D47E00191844 /* ldblib.c */,
				38FAA8680660D47E00191844 /* liolib.c */,
				38FAA8690660D47E00191844 /* lmathlib.c */,
				38FAA86A0660D47E00191844 /* loadlib.c */,
				38FAA86B0660D47E00191844 /* lstrlib.c */,
				38FAA86C0660D47E00191844 /* ltablib.c */,
			);
			name = Libraries;
			sourceTree = "<group>";
		};
		38FAA8770660DBA800191844 /* TERMS Lib */ = {
			isa = PBXGroup;
			children = (
				3869B712066244A600AF20B2 /* lua_timer.h */,
				3869B70B0662446200AF20B2 /* lua_timer.c */,
				3869B6F50662345500AF20B2 /* lua_serial.h */,
				3869B6F00662332D00AF20B2 /* lua_serial.c */,
				3869B72006627FBE00AF20B2 /* lua_net.h */,
				3869B71B06627FA600AF20B2 /* lua_net.c */,
			);
			name = "TERMS Lib";
			sourceTree = "<group>";
		};
		C6A0FF2B0290797F04C91782 /* Documentation */ = {
			isa = PBXGroup;
			children = (
				38CBD7370692DF4000E97226 /* TERMS.pdf */,
				3869B75206637D7300AF20B2 /* refman-5.0.pdf */,
			);
			name = Documentation;
			sourceTree = "<group>";
		};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
		8DD76FAA0486AB0100D96B5E /* Headers */ = {
			isa = PBXHeadersBuildPhase;
			buildActionMask = 2147483647;
			files = (
				381D0BFD065AF2DB0030AFEF /* tgtimer.h in Headers */,
				381D0C03065AF2EE0030AFEF /* netcom.h in Headers */,
				381D0C0A065AF3120030AFEF /* tgtypes.h in Headers */,
				38A58AE6065B507A00B45C7D /* terms.h in Headers */,
				38FAA8000660D37600191844 /* lauxlib.h in Headers */,
				38FAA8010660D37600191844 /* lua.h in Headers */,
				38FAA8020660D37600191844 /* lualib.h in Headers */,
				38FAA81C0660D41B00191844 /* lapi.h in Headers */,
				38FAA81E0660D41B00191844 /* lcode.h in Headers */,
				38FAA8200660D41B00191844 /* ldebug.h in Headers */,
				38FAA8220660D41B00191844 /* ldo.h in Headers */,
				38FAA8250660D41B00191844 /* lfunc.h in Headers */,
				38FAA8270660D41B00191844 /* lgc.h in Headers */,
				38FAA83F0660D43900191844 /* llex.h in Headers */,
				38FAA8400660D43900191844 /* llimits.h in Headers */,
				38FAA8420660D43900191844 /* lmem.h in Headers */,
				38FAA8440660D43900191844 /* lobject.h in Headers */,
				38FAA8460660D43900191844 /* lopcodes.h in Headers */,
				38FAA8480660D43900191844 /* lparser.h in Headers */,
				38FAA84A0660D43900191844 /* lstate.h in Headers */,
				38FAA84C0660D43900191844 /* lstring.h in Headers */,
				38FAA84E0660D43900191844 /* ltable.h in Headers */,
				38FAA8510660D43900191844 /* ltm.h in Headers */,
				38FAA85B0660D45400191844 /* lundump.h in Headers */,
				38FAA85D0660D45400191844 /* lvm.h in Headers */,
				38FAA85F0660D45400191844 /* lzio.h in Headers */,
				3869B6F60662345500AF20B2 /* lua_serial.h in Headers */,
				3869B713066244A600AF20B2 /* lua_timer.h in Headers */,
				3869B72106627FBE00AF20B2 /* lua_net.h in Headers */,
				38730C7F093FCCA9003BEB15 /* bsdserial.h in Headers */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXHeadersBuildPhase section */

/* Begin PBXNativeTarget section */
		8DD76FA90486AB0100D96B5E /* TERMS */ = {
			isa = PBXNativeTarget;
			buildConfigurationList = 38A6DCA308682EB2001824A0 /* Build configuration list for PBXNativeTarget "TERMS" */;
			buildPhases = (
				8DD76FAA0486AB0100D96B5E /* Headers */,
				8DD76FAB0486AB0100D96B5E /* Sources */,
				8DD76FAD0486AB0100D96B5E /* Frameworks */,
				8DD76FAE0486AB0100D96B5E /* Rez */,
				8DD76FAF0486AB0100D96B5E /* CopyFiles */,
			);
			buildRules = (
			);
			dependencies = (
			);
			name = TERMS;
			productInstallPath = "$(HOME)/bin";
			productName = TERMS;
			productReference = 8DD76FB20486AB0100D96B5E /* TERMS */;
			productType = "com.apple.product-type.tool";
		};
/* End PBXNativeTarget section */

/* Begin PBXProject section */
		08FB7793FE84155DC02AAC07 /* Project object */ = {
			isa = PBXProject;
			buildConfigurationList = 38A6DCA708682EB2001824A0 /* Build configuration list for PBXProject "TERMS" */;
			compatibilityVersion = "Xcode 3.2";
			hasScannedForEncodings = 1;
			mainGroup = 08FB7794FE84155DC02AAC07 /* TERMS */;
			projectDirPath = "";
			projectRoot = "";
			targets = (
				8DD76FA90486AB0100D96B5E /* TERMS */,
			);
		};
/* End PBXProject section */

/* Begin PBXRezBuildPhase section */
		8DD76FAE0486AB0100D96B5E /* Rez */ = {
			isa = PBXRezBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXRezBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
		8DD76FAB0486AB0100D96B5E /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				381D0BFC065AF2DB0030AFEF /* tgtimer.c in Sources */,
				381D0C02065AF2EE0030AFEF /* netcom.c in Sources */,
				38A58AE5065B507A00B45C7D /* terms.c in Sources */,
				38FAA81B0660D41B00191844 /* lapi.c in Sources */,
				38FAA81D0660D41B00191844 /* lcode.c in Sources */,
				38FAA81F0660D41B00191844 /* ldebug.c in Sources */,
				38FAA8210660D41B00191844 /* ldo.c in Sources */,
				38FAA8230660D41B00191844 /* ldump.c in Sources */,
				38FAA8240660D41B00191844 /* lfunc.c in Sources */,
				38FAA8260660D41B00191844 /* lgc.c in Sources */,
				38FAA83E0660D43900191844 /* llex.c in Sources */,
				38FAA8410660D43900191844 /* lmem.c in Sources */,
				38FAA8430660D43900191844 /* lobject.c in Sources */,
				38FAA8450660D43900191844 /* lopcodes.c in Sources */,
				38FAA8470660D43900191844 /* lparser.c in Sources */,
				38FAA8490660D43900191844 /* lstate.c in Sources */,
				38FAA84B0660D43900191844 /* lstring.c in Sources */,
				38FAA84D0660D43900191844 /* ltable.c in Sources */,
				38FAA84F0660D43900191844 /* ltests.c in Sources */,
				38FAA8500660D43900191844 /* ltm.c in Sources */,
				38FAA85A0660D45400191844 /* lundump.c in Sources */,
				38FAA85C0660D45400191844 /* lvm.c in Sources */,
				38FAA85E0660D45400191844 /* lzio.c in Sources */,
				38FAA86D0660D47E00191844 /* lauxlib.c in Sources */,
				38FAA86E0660D47E00191844 /* lbaselib.c in Sources */,
				38FAA86F0660D47E00191844 /* ldblib.c in Sources */,
				38FAA8700660D47E00191844 /* liolib.c in Sources */,
				38FAA8710660D47E00191844 /* lmathlib.c in Sources */,
				38FAA8720660D47E00191844 /* loadlib.c in Sources */,
				38FAA8730660D47E00191844 /* lstrlib.c in Sources */,
				38FAA8740660D47E00191844 /* ltablib.c in Sources */,
				3869B6F10662332D00AF20B2 /* lua_serial.c in Sources */,
				3869B70C0662446200AF20B2 /* lua_timer.c in Sources */,
				3869B71C06627FA600AF20B2 /* lua_net.c in Sources */,
				38730C7E093FCCA9003BEB15 /* bsdserial.c in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
		38A6DCA408682EB2001824A0 /* Development */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				COPY_PHASE_STRIP = NO;
				DEBUGGING_SYMBOLS = YES;
				FRAMEWORK_SEARCH_PATHS = "";
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_ENABLE_TRIGRAPHS = NO;
				GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
				GCC_OPTIMIZATION_LEVEL = 0;
				GCC_PRECOMPILE_PREFIX_HEADER = NO;
				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
				GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
				GCC_WARN_UNKNOWN_PRAGMAS = NO;
				HEADER_SEARCH_PATHS = "";
				INSTALL_PATH = "$(HOME)/bin";
				LIBRARY_SEARCH_PATHS = "";
				OTHER_CFLAGS = "";
				OTHER_LDFLAGS = "";
				OTHER_REZFLAGS = "";
				PRODUCT_NAME = TERMS;
				REZ_EXECUTABLE = YES;
				SECTORDER_FLAGS = "";
				WARNING_CFLAGS = (
					"-Wmost",
					"-Wno-four-char-constants",
					"-Wno-unknown-pragmas",
				);
				ZERO_LINK = NO;
			};
			name = Development;
		};
		38A6DCA508682EB2001824A0 /* Deployment */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = (
					ppc,
					i386,
				);
				COPY_PHASE_STRIP = YES;
				FRAMEWORK_SEARCH_PATHS = "";
				GCC_ENABLE_FIX_AND_CONTINUE = NO;
				GCC_ENABLE_TRIGRAPHS = NO;
				GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
				GCC_OPTIMIZATION_LEVEL = 1;
				GCC_PRECOMPILE_PREFIX_HEADER = NO;
				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
				GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
				GCC_WARN_UNKNOWN_PRAGMAS = NO;
				HEADER_SEARCH_PATHS = "";
				INSTALL_PATH = "$(HOME)/bin";
				LIBRARY_SEARCH_PATHS = "";
				OTHER_CFLAGS = "";
				OTHER_LDFLAGS = "";
				OTHER_REZFLAGS = "";
				PRODUCT_NAME = TERMS;
				REZ_EXECUTABLE = YES;
				SECTORDER_FLAGS = "";
				WARNING_CFLAGS = (
					"-Wmost",
					"-Wno-four-char-constants",
					"-Wno-unknown-pragmas",
				);
				ZERO_LINK = NO;
			};
			name = Deployment;
		};
		38A6DCA608682EB2001824A0 /* Default */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				FRAMEWORK_SEARCH_PATHS = "";
				GCC_ENABLE_TRIGRAPHS = NO;
				GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
				GCC_PRECOMPILE_PREFIX_HEADER = NO;
				GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
				GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
				GCC_WARN_UNKNOWN_PRAGMAS = NO;
				HEADER_SEARCH_PATHS = "";
				INSTALL_PATH = "$(HOME)/bin";
				LIBRARY_SEARCH_PATHS = "";
				OTHER_CFLAGS = "";
				OTHER_LDFLAGS = "";
				OTHER_REZFLAGS = "";
				PRODUCT_NAME = TERMS;
				REZ_EXECUTABLE = YES;
				SECTORDER_FLAGS = "";
				WARNING_CFLAGS = (
					"-Wmost",
					"-Wno-four-char-constants",
					"-Wno-unknown-pragmas",
				);
			};
			name = Default;
		};
		38A6DCA808682EB2001824A0 /* Development */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
				MACOSX_DEPLOYMENT_TARGET = 10.4;
				SDKROOT = macosx10.6;
			};
			name = Development;
		};
		38A6DCA908682EB2001824A0 /* Deployment */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = (
					ppc,
					i386,
				);
				MACOSX_DEPLOYMENT_TARGET = 10.4;
				SDKROOT = macosx10.6;
			};
			name = Deployment;
		};
		38A6DCAA08682EB2001824A0 /* Default */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				MACOSX_DEPLOYMENT_TARGET = 10.4;
				SDKROOT = macosx10.6;
			};
			name = Default;
		};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
		38A6DCA308682EB2001824A0 /* Build configuration list for PBXNativeTarget "TERMS" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				38A6DCA408682EB2001824A0 /* Development */,
				38A6DCA508682EB2001824A0 /* Deployment */,
				38A6DCA608682EB2001824A0 /* Default */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Default;
		};
		38A6DCA708682EB2001824A0 /* Build configuration list for PBXProject "TERMS" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				38A6DCA808682EB2001824A0 /* Development */,
				38A6DCA908682EB2001824A0 /* Deployment */,
				38A6DCAA08682EB2001824A0 /* Default */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Default;
		};
/* End XCConfigurationList section */
	};
	rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
}

Added TGLuaLibs/lua_net.c.







































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2004. Pandora Products All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         lua_serial	- Lua network Support
*
*  Description:         This library supports TCP/IP I/O interface for the 
*						terminal server in LUA
*
*  Author:              Jim Schimpf
*
*  Revision History:	24 May 2004 Initial version
*
*		Functions:
*			net.write( data )
*			data = net.read()
*			count = net.stat()
*			net.sdrop()
*/
//************************************************************************

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "terms.h"
#include "tgtimer.h"
#include "lua_net.h"

/**********************************************************************
*
* net.swrite(data)		- Write data out the network port
*
*	INPUT:	data	- String to be written, error if not present
*
*	OUTPUT:	# Bytes written
*
**********************************************************************/

static int swrite (lua_State *L) 
{
	MY_ENV *env = L->env;
	char *ptr;
	int len;
	double dval;
	
	// (1) Get the object on the stack
	
	if( !lua_isstring( L,-1) )
	{
		return(0);			// Return NIL failure
	}
	ptr = (char *)lua_tostring(L,-1);
	len = strlen(ptr);
	
	// (2) Now write the value via the serial port
	
	len = netcom_write(env->tcp_socket,ptr,len);
	dval = (double)len;
	lua_pushnumber(L,dval);
	return(1);
}

/**********************************************************************
*
* data = net.read(n)		- Read data from the serial port
*
*	INPUT:	n	- # Bytes to read
*
*	OUTPUT:	Data buffer with n or less bytes or nil if failure
*
**********************************************************************/

static int sread (lua_State *L) 
{
	MY_ENV *env = L->env;
	const char *ptr;
	int len;
	double dval;
	
	// (1) Get the object on the stack
	
	if( !lua_isnumber( L,-1) )
	{
		return(0);			// Return NIL failure
	}
	dval = lua_tonumber(L,-1);
	len = (int)dval;
	
	// (2) Create a buffer and read the data into it
	
	ptr = MEMALLOC( len + 10 );
	if( ptr == NULL )
	{
		// FAILURE - return nil
		
		return(0);
	}
	
	// (2) Read in the serial data and stack the result
	
	len = netcom_read( env->tcp_socket,(char *)ptr,len);
	lua_pushlstring(L,ptr,len);
	MEMFREE((char *)ptr);
	return(1);
}

/**********************************************************************
*
* count = net.sstat()   - Return # characters waiting for input
*
*	INPUT:	data	- String to be written, error if not present
*
*	OUTPUT:	# Bytes written
*		STUBBED OUT - RETURNS 0 ALWAYS
*
**********************************************************************/

static int sstat (lua_State *L) 
{
	double dval = 0.0;
	
	lua_pushnumber(L,dval);
	return(1);
}

/**********************************************************************
*
* count = ser.drop()   - Drop TCP/IP connection
*
*	INPUT:	NONE
*
*	OUTPUT:	NONE
*			TCP/IP connection dropped
*
**********************************************************************/

static int drop (lua_State *L) 
{
	MY_ENV *env = L->env;

	close( env->tcp_socket->to_socket );		// Close the com socket
	env->tcp_socket->state = NETCOM_OPEN;		// Return to wait for conn
												// state
	return(0);
}

/**********************************************************************
*
* count = net.cstat()   - Network connection status
*
*	INPUT:	NONE
*
*	OUTPUT:	1   - Connected to network
*			0   - No connection
*
**********************************************************************/

static int cstat (lua_State *L) 
{
	MY_ENV *env = L->env;
	
	switch(  env->tcp_socket->state )
	{
		case NETCOM_READY:		// We are connected return
								// on stack
								lua_pushnumber(L,1.0);
								return( 1 );
								break;
								
		default:				return( 0 );		// Nothing
	}
	
	return( 0 );		// Default exit
}

/**********************************************************************
*   Library Create function
**********************************************************************/

static const luaL_reg netlib[] = {
  {"swrite",swrite},
  {"sread",sread},
  {"sstat",sstat},
  {"drop",drop},
  {"cstat",cstat},
  {NULL, NULL}
};

LUALIB_API int luaopen_netlib (lua_State *L) {
  luaL_openlib(L, LUA_NETNAME, netlib, 0);
  return 1;
}

Added TGLuaLibs/lua_net.h.

















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//*************************************************************************
/*
    Copyright (c) 2004. Pandora Products All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         lua_serial	- Lua network Support
*
*  Description:         This library supports TCP/IP I/O interface for the 
*						terminal server in LUA
*
*  Author:              Jim Schimpf
*
*  Revision History:	24 May 2004 Initial version
*
*		Functions:
*			net.write( data )
*			data = net.read()
*			count = net.stat()
*/
//************************************************************************

#define LUA_NETNAME	"net"
LUALIB_API int luaopen_netlib (lua_State *L);

Added TGLuaLibs/lua_serial.c.

























































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2004. Pandora Products All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         lua_serial	- Lua Serial Support
*
*  Description:         This library supports serial I/O interface for the 
*						terminal server in LUA
*
*  Author:              Jim Schimpf
*
*  Revision History:	24 May 2004 Initial version
*
*		Functions:
*			ser.swrite( data )
*			data = ser.sread()
*			count = ser.sstat()
*			cts = ser.sgetstate()
*			ser.ssetstate(dtr)
*/
//************************************************************************

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "terms.h"
#include "tgtimer.h"
#include "lua_serial.h"

/**********************************************************************
*
* ser.swrite(data)		- Write data out the serial port
*
*	INPUT:	data	- String to be written, error if not present
*
*	OUTPUT:	# Bytes written
*
**********************************************************************/

static int swrite (lua_State *L) 
{
	MY_ENV *env = L->env;
	const char *ptr;
	int len;
	double dval;
	
	// (1) Get the object on the stack
	
	if( !lua_isstring( L,-1) )
	{
		return(0);			// Return NIL failure
	}
	ptr = lua_tostring(L,-1);
	len = strlen(ptr);
	
	// (2) Now write the value via the serial port
	
	len = WritePort((char *)ptr,len,env->ser);
	dval = (double)len;
	lua_pushnumber(L,dval);
	return(1);
}

/**********************************************************************
*
* data = ser.read(n)		- Read data from the serial port
*
*	INPUT:	n	- # Bytes to read
*
*	OUTPUT:	Data buffer with n or less bytes or nil if failure
*
**********************************************************************/

static int sread (lua_State *L) 
{
	MY_ENV *env = L->env;
	const char *ptr;
	int len;
	double dval;
	
	// (1) Get the object on the stack
	
	if( !lua_isnumber( L,-1) )
	{
		return(0);			// Return NIL failure
	}
	dval = lua_tonumber(L,-1);
	len = (int)dval;
	
	// (2) Create a buffer and read the data into it
	
	ptr = MEMALLOC( len + 10 );
	if( ptr == NULL )
	{
		// FAILURE - return nil
		
		return(0);
	}
	
	// (2) Read in the serial data and stack the result
	
	len = ReadPort((char *)ptr,len,env->ser);
	lua_pushlstring(L,ptr,len);
	MEMFREE((char *)ptr);
	return(1);
}

/**********************************************************************
*
* count = ser.sstat()   - Return # characters waiting for input
*
*	INPUT:	data	- String to be written, error if not present
*
*	OUTPUT:	# Bytes written
*		STUBBED OUT - RETURNS 0 ALWAYS
*
**********************************************************************/

static int sstat (lua_State *L) 
{
	double dval = 0.0;
	
	lua_pushnumber(L,dval);
	return(1);
}

/**********************************************************************
*
* cts = ser.getstate()		- Return serial line data
*
*	INPUT:	NONE
*
*	OUTPUT:	cts = 1 asserted, 0 non-asserted 
*
**********************************************************************/

static int sgetstate (lua_State *L) 
{
	MY_ENV *env = L->env;
	int cts;
	double dval;
	
	// (1) Get the line state
	
	cts = CTSPort(env->ser);
	
	// (2) Push result to stack
	
	dval = (double)cts;
	lua_pushnumber(L,dval);
	return(1);
}

/**********************************************************************
*
* data = ser.ssetstate(dtr)		- Set DTR to requested value
*
*	INPUT:	dtr - 1 assert DTR, 0 - remove dtr
*
*	OUTPUT:	NONE
*
**********************************************************************/

static int ssetstate (lua_State *L) 
{
	MY_ENV *env = L->env;
	int dtr;
	double dval;
	
	// (1) Get the object on the stack
	
	if( !lua_isnumber( L,-1) )
	{
		return(0);			// Return NIL failure
	}
	dval = lua_tonumber(L,-1);
	dtr = (int)dval;
	
	// (2) Set DTR to requested value
	
	DTRPort( dtr,env->ser );
	return( 0 );
}

/**********************************************************************
*   Library Create function
**********************************************************************/

static const luaL_reg serlib[] = {
  {"swrite",swrite},
  {"sread",sread},
  {"sstat",sstat},
  {"sgetstate",sgetstate},
  {"ssetstate",ssetstate},
  {NULL, NULL}
};

LUALIB_API int luaopen_serlib (lua_State *L) {
  luaL_openlib(L, LUA_SERNAME, serlib, 0);
  return 1;
}

Added TGLuaLibs/lua_serial.h.





















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2004. Pandora Products All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         lua_serial	- Lua Serial Support
*
*  Description:         This library supports serial I/O interface for the 
*						terminal server in LUA
*
*  Author:              Jim Schimpf
*
*  Revision History:	24 May 2004 Initial version
*
*		Functions:
*			ser.write( data )
*			data = ser.read()
*			count = ser.stat()
*			dtr,rts = ser.getstate()
*			ser.setstate( cts,...)
*/
//************************************************************************

#define LUA_SERNAME	"ser"
LUALIB_API int luaopen_serlib (lua_State *L);

Added TGLuaLibs/lua_timer.c.









































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
//*************************************************************************
/*
    Copyright (c) 2004. Pandora Products All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         lua_timer	- Lua Timer Support
*
*  Description:         This library supports timer functions
*
*  Author:              Jim Schimpf
*
*  Revision History:	24 May 2004 Initial version
*
*		Functions:
*			timer.topen()   - Open a timer
*			timer.tclose()  - Close a timer
*			timer.tstart()  - Reset timer
*			timer.tdone(t,et)- Test a timer
*/
//************************************************************************

#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
#include "terms.h"
#include "tgtimer.h"
#include "lua_timer.h"

/**********************************************************************
*
* t = timer.topen()		- Create a timer
*
*	INPUT:	NONE
*
*	OUTPUT:	Timer handle or nil
*
**********************************************************************/

static int topen (lua_State *L) 
{
	TG_TIMER_STRUCT *t;
	void *hdl;
	
	// (1) Create a timer struct if possible
	
	t = (TG_TIMER_STRUCT *)MEMALLOC( sizeof(TG_TIMER_STRUCT));
	if( t != NULL )
	{
		// (2) Init the timer
		
		TIMER_Start( t );
		
		// (2) Return as user handle to user
		
		hdl = (void *)t;
		lua_pushlightuserdata(L,hdl);
		return( 1 );
	}
	
	// (3) Failure, so return no handle
	
	return( 0 );
}
		
/**********************************************************************
*
* timer.tclose(t)		- Close a timer
*
*	INPUT:	h   - Handle to timer
*
*	OUTPUT:	NONE
*				Free timer data struct
*
**********************************************************************/

static int tclose (lua_State *L) 
{
	const void *hdl;
	
	// (1) Get the object on the stack
	
	if( !lua_islightuserdata( L,-1) )
	{
		return(0);			// Return NIL failure
	}
	hdl = lua_topointer(L,-1);
	if( hdl != NULL )
	{
		MEMFREE( (void *)hdl );
	}
	
	return(0);
}

/**********************************************************************
*
* timer.tstart(t)   - Reset timer back to 0
*
*	INPUT:	t   - Timer handle
*
*	OUTPUT:	NONE
*
**********************************************************************/

static int tstart (lua_State *L) 
{
	TG_TIMER_STRUCT *t;
	
	// (1) Get the object on the stack
	
	if( !lua_islightuserdata( L,-1) )
	{
		return(0);			// Return NIL failure
	}
	
	// (2) Get Timer handle and reset to 0
	
	t = (TG_TIMER_STRUCT *)lua_topointer(L,-1);
	TIMER_Start( t );
	
	return(0);
}

/**********************************************************************
*
* timer.tdone(t,et)		- Check timer for done
*
*	INPUT:	t		- Timer handle
*			et		- Timer period in ms
*
*	OUTPUT:	1   if Timer done
*			nil if not
*
**********************************************************************/

static int tdone (lua_State *L) 
{
	TG_TIMER_STRUCT *t;
	double dval;
	int et;
	
	// (1) Get the timer on the stack
	
	if( !lua_islightuserdata( L,-2) )
	{
		return(0);			// Return NIL failure
	}
	t = (TG_TIMER_STRUCT *)lua_topointer(L,-2);
	
	// (2) Get the et off the stack
	
	if( !lua_isnumber(L,-1) )
	{
		return( 0 );		// Return NIL failure
	}
	
	dval = lua_tonumber(L,-1);
	et = (int)(dval + 0.5);
	
	// (3) Now look at result
	
	if( TIMER_Finished(t,et) )
	{
		dval = 1.0;
		lua_pushnumber( L,dval );		// Return TRUE
		return( 1 );
	}
	else
	{
		// Failure - just return NIL
		
		return( 0 );
	}
	
	return(0);
}


/**********************************************************************
*   Library Create function
**********************************************************************/

static const luaL_reg timerlib[] = {
  {"topen",topen},
  {"tclose",tclose},
  {"tstart",tstart},
  {"tdone",tdone},
  {NULL, NULL}
};

LUALIB_API int luaopen_timerlib (lua_State *L) {
  luaL_openlib(L, LUA_TIMERNAME, timerlib, 0);
  return 1;
}

Added TGLuaLibs/lua_timer.h.









































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//*************************************************************************
/*
    Copyright (c) 2004. Pandora Products All Rights Reserved.
*/
//*************************************************************************
/*
*  Module Name:         lua_timer	- Lua Timer Support
*
*  Description:         This library supports timer functions
*
*  Author:              Jim Schimpf
*
*  Revision History:	24 May 2004 Initial version
*
*		Functions:
*/
//************************************************************************

#define LUA_TIMERNAME	"timer"
LUALIB_API int luaopen_timerlib (lua_State *L);

Added bin/TERMS.

cannot compute difference between binary files

Added bin/myterm.sh.













































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
#!/bin/bash
#----- Start up TERMINAL session in a window
# 16-Apr-2009 Change here to allow all serial ports to be
# used not just RS232

# MACRO to show usage
printusage () {
cat << EOF

usage: myterm.sh <Serial Port #> [<baud>] [<TCP/IP> Port used>]
       Serial Port # REQUIRED
       baud        DEFAULT = 38400
       port        DEFAULT = 7000 + serial port #
EOF
}

port=$1		# First VAR = serial port	REQUIRED
baud=$2		# Next baud rate			OPTIONAL
tport=$3	# Last TCP/IP port #		OPTIONAL

# Check for parameter count, if too small bail

if [  $#  == 0 ]
then
	TERMS -v -modem
	echo 'Must have a serial port # '
	printusage
	exit 1
fi

# If baud not present then set to 38400

if [ -z $baud ]
then 
	baud='38400'
fi

# If tport not present then set to 7000 + port #

if [  -z $tport  ]
then 
	tport=$((7000 + $port))
fi

#  Ok, crank up the terminal server
# and then the telnet session

TERMS -p $port -tcp_p $tport -baud $baud -modem &
sleep 5
telnet localhost $tport

# Kill that running TERMS service

kill %+

Added lua-5.0.2/Makefile.













































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# makefile for Lua hierarchy
# see INSTALL for installation instructions
# see config for customization instructions

LUA= .

include $(LUA)/config

# primary targets ("co" and "klean" are used for making the distribution)
all clean co klean:	dirs
	cd include; $(MAKE) $@
	cd src; $(MAKE) $@
	cd src/lib; $(MAKE) $@
	cd src/luac; $(MAKE) $@
	cd src/lua; $(MAKE) $@

# in case they were not created during unpacking
dirs:	bin lib

bin lib:
	mkdir -p $@

# simple test to see Lua working
test:	all
	bin/lua test/hello.lua

# remove debug information from binaries
strip:
	$(STRIP) bin/*

# official installation
install: all strip
	mkdir -p $(INSTALL_BIN) $(INSTALL_INC) $(INSTALL_LIB) $(INSTALL_MAN)
	$(INSTALL_EXEC) bin/* $(INSTALL_BIN)
	$(INSTALL_DATA) include/*.h $(INSTALL_INC)
	$(INSTALL_DATA) lib/*.a $(INSTALL_LIB)
	$(INSTALL_DATA) doc/*.1 $(INSTALL_MAN)

# shared libraries (for Linux)
so:
	ld -o lib/liblua.so.$V -shared src/*.o
	ld -o lib/liblualib.so.$V -shared src/lib/*.o
	cd lib; ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so

# binaries using shared libraries
sobin:
	rm -f bin/*
	cd src/lua; $(MAKE)
	cd src/luac; $(MAKE)

# install shared libraries
soinstall:
	$(INSTALL_EXEC) lib/*.so.* $(INSTALL_LIB)
	cd $(INSTALL_LIB); ln -fs liblua.so.$V liblua.so; ln -fs liblualib.so.$V liblualib.so

# clean shared libraries
soclean:
	rm -f lib/*.so* bin/*

# echo config parameters
echo:
	@echo ""
	@echo "These are the parameters currently set in $(LUA)/config to build Lua $V:"
	@echo ""
	@echo "LOADLIB = $(LOADLIB)"
	@echo "DLLIB = $(DLLIB)"
	@echo "NUMBER = $(NUMBER)"
	@echo "POPEN = $(POPEN)"
	@echo "TMPNAM = $(TMPNAM)"
	@echo "DEGREES = $(DEGREES)"
	@echo "USERCONF = $(USERCONF)"
	@echo "CC = $(CC)"
	@echo "WARN = $(WARN)"
	@echo "MYCFLAGS = $(MYCFLAGS)"
	@echo "MYLDFLAGS = $(MYLDFLAGS)"
	@echo "EXTRA_LIBS = $(EXTRA_LIBS)"
	@echo "AR = $(AR)"
	@echo "RANLIB = $(RANLIB)"
	@echo "STRIP = $(STRIP)"
	@echo "INSTALL_ROOT = $(INSTALL_ROOT)"
	@echo "INSTALL_BIN = $(INSTALL_BIN)"
	@echo "INSTALL_INC = $(INSTALL_INC)"
	@echo "INSTALL_LIB = $(INSTALL_LIB)"
	@echo "INSTALL_MAN = $(INSTALL_MAN)"
	@echo "INSTALL_EXEC = $(INSTALL_EXEC)"
	@echo "INSTALL_DATA = $(INSTALL_DATA)"
	@echo ""
	@echo "Edit $(LUA)/config if needed to suit your platform and then run make."
	@echo ""

# turn config into Lua code
# uncomment the last sed expression if you want nil instead of empty strings
lecho:
	@echo "-- $(LUA)/config for Lua $V"
	@echo "VERSION = '$(V)'"
	@make echo | grep = | sed -e 's/= /= "/' -e 's/$$/"/' #-e 's/""/nil/'
	@echo "-- EOF"

newer:
	@find . -newer MANIFEST -type f

# (end of Makefile)

Added lua-5.0.2/bin/lua.

cannot compute difference between binary files

Added lua-5.0.2/bin/luac.

cannot compute difference between binary files

Added lua-5.0.2/config.





































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# configuration file for making Lua 5.0
# see INSTALL for installation instructions

# These are default values. Skip this section and see the explanations below.

LOADLIB=
DLLIB=
NUMBER=
POPEN=
TMPNAM=
DEGREES=
USERCONF=

# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================

# --------------------------------------------------------------- Lua libraries

# Support for dynamically loading C libraries for Lua is a very important
# feature, which we strongly recommend be enabled. By default, this support is
# enabled on Windows systems (see below) but disabled on other systems because
# it relies on system-dependent code that is not part of ANSI C. For more
# information on dynamic loading, read the comments in src/lib/liolib.c .
#
# To enable support for dynamic loading on Unix systems that support the dlfcn
# interface (e.g., Linux, Solaris, IRIX, BSD, AIX, HPUX, and probably others),
# uncomment the next two lines.
#
#LOADLIB= -DUSE_DLOPEN=1
#DLLIB= -ldl
#
# In Linux with gcc, you should also uncomment the next definition for
# MYLDFLAGS, which passes -E (= -export-dynamic) to the linker. This option
# allows dynamic libraries to link back to the `lua' program, so that they do
# not need the Lua libraries. (Other systems may have an equivalent facility.)
#
#MYLDFLAGS= -Wl,-E
#
# On Windows systems. support for dynamic loading is enabled by default.
# To disable this support, uncomment the next line.
#
#LOADLIB= -DUSE_DLL=0

# The Lua IO library (src/lib/liolib.c) has support for pipes using popen and
# pclose. This support is enabled by default on POSIX systems.
# If your system is not POSIX but has popen and pclose, define USE_POPEN=1.
# If you don't want to support pipes, define USE_POPEN=0.
#
#POPEN= -DUSE_POPEN=1
#POPEN= -DUSE_POPEN=0
#
# The form below will probably work in (some) Windows systems.
#
#POPEN= -DUSE_POPEN=1 -Dpopen=_popen -Dpclose=_pclose

# The Lua OS library (src/lib/liolib.c) exports an interface to the C function
# tmpnam, which gcc now thinks is `dangerous'. So, support for tmpnam is
# disabled by default when compiling with gcc.
# If you still want to use tmpnam, define USE_TMPNAME=1. If you don't want to
# use tmpnam even if you're not compiling with gcc, define USE_TMPNAME=0.
#
#TMPNAM= -DUSE_TMPNAME=1
#TMPNAM= -DUSE_TMPNAME=0

# The Lua math library (src/lib/lmathlib.c) now operates in radians, unlike
# previous versions of Lua, which used degrees. To use degrees instead of
# radians, define USE_DEGREES.
#
#DEGREES= -DUSE_DEGREES

# ------------------------------------------------------------------ Lua core

# Lua uses double for numbers. To change this, uncomment and edit the following
# line, changing USE_XXX to one of USE_DOUBLE, USE_FLOAT, USE_LONG, USE_INT.
#
#NUMBER= -DLUA_USER_H='"../etc/luser_number.h"' -DUSE_XXX

# When compiling Lua with gcc on a Pentium machine, using a fast rounding
# method for the conversion of doubles to ints can give around 20% speed
# improvement. To use this rounding method, uncomment the following line.
#NUMBER= -DLUA_USER_H='"../etc/luser_number.h"' -DUSE_FASTROUND

# For partial compatibility with old upvalue syntax, define LUA_COMPATUPSYNTAX.
# For partial compatibility with old upvalue behavior in C functions, define
# LUA_COMPATUPVALUES. Add these definitions to MYCFLAGS.
#
# -DLUA_COMPATUPSYNTAX -DLUA_COMPATUPVALUES

# ------------------------------------------------------------- Lua interpreter

# The stand-alone Lua interpreter needs the math functions, which are usually
# in libm.a (-lm).  If your C library already includes the math functions,
# or if you are using a modified interpreter that does not need them,
# then comment the following line or add the appropriates libraries.
#
EXTRA_LIBS= -lm

# If you want to customize the stand-alone Lua interpreter, uncomment and
# edit the following two lines; also edit etc/saconfig.c to suit your needs.
# -DUSE_READLINE adds line editing and history to the interpreter. You need
# to add -lreadline (and perhaps also -lhistory and -lcurses or -lncurses)
# to EXTRA_LIBS.
#
#USERCONF=-DLUA_USERCONFIG='"$(LUA)/etc/saconfig.c"' -DUSE_READLINE
#EXTRA_LIBS= -lm -ldl -lreadline # -lhistory -lcurses -lncurses

# ------------------------------------------------------------------ C compiler

# You need an ANSI C compiler. gcc is a popular one. We do not use -ansi in
# WARN because it disables POSIX features used in the libraries.
#
CC= gcc
WARN= -Wall

# ------------------------------------------------------------------ C options

# Write here any options you may need for your C compiler.
# If you are using gcc, -O3 will get you a faster but larger code. You can
# also add -fomit-frame-pointer to get even faster code at the cost of losing
# debug information. If you only want the shared libraries, you may want to
# add -fPIC to MYCFLAGS.
#
MYCFLAGS= -O2
#MYCFLAGS= -O3 -fomit-frame-pointer # -fPIC

# Write here any options you may need for your C linker.
#MYLDFLAGS=

# ------------------------------------------------------------------ librarian

# This should work in all Unix systems.
#
AR= ar rcu

# If your system doesn't have (or need) ranlib, use RANLIB=true.
# On some systems, "ar s" does what ranlib would do.
#
RANLIB= ranlib
#RANLIB= ar s
#RANLIB= true

# ------------------------------------------------------------------ stripper

# This should work in all Unix systems, but you may want to add options.
#
STRIP= strip

# ------------------------------------------------------------------ install

# Locations for "make install". You may need to be root do "make install".
#
INSTALL_ROOT= /usr/local
INSTALL_BIN= $(INSTALL_ROOT)/bin
INSTALL_INC= $(INSTALL_ROOT)/include
INSTALL_LIB= $(INSTALL_ROOT)/lib
INSTALL_MAN= $(INSTALL_ROOT)/man/man1

# You may prefer to use "install" instead of "cp" if you have it.
# If you use "install", you may also want to change the permissions after -m.
#
INSTALL_EXEC= cp
INSTALL_DATA= cp
#INSTALL_EXEC= install -m 0755
#INSTALL_DATA= install -m 0644

# == END OF USER SETTINGS. NO NEED TO CHANGE ANYTHING BELOW THIS LINE =========

V=5.0

BIN= $(LUA)/bin
INC= $(LUA)/include
LIB= $(LUA)/lib

INCS= -I$(INC) $(EXTRA_INCS)
DEFS= $(NUMBER) $(EXTRA_DEFS)

CFLAGS= $(MYCFLAGS) $(WARN) $(INCS) $(DEFS)

# (end of config)

Added lua-5.0.2/include/Makefile.



































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# makefile for Lua distribution (includes)

LUA= ..

include $(LUA)/config

SRCS= lua.h lualib.h lauxlib.h

all:

clean:

co:
	co -q -f -M $(SRCS)

klean:	clean
	rm -f $(SRCS)

Added lua-5.0.2/include/lauxlib.h.



































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: lauxlib.h,v 1.60 2003/04/03 13:35:34 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/


#ifndef lauxlib_h
#define lauxlib_h


#include <stddef.h>
#include <stdio.h>

#include "lua.h"


#ifndef LUALIB_API
#define LUALIB_API	LUA_API
#endif



typedef struct luaL_reg {
  const char *name;
  lua_CFunction func;
} luaL_reg;


LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
                               const luaL_reg *l, int nup);
LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *e);
LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *e);
LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname);
LUALIB_API int luaL_argerror (lua_State *L, int numarg, const char *extramsg);
LUALIB_API const char *luaL_checklstring (lua_State *L, int numArg, size_t *l);
LUALIB_API const char *luaL_optlstring (lua_State *L, int numArg,
                                           const char *def, size_t *l);
LUALIB_API lua_Number luaL_checknumber (lua_State *L, int numArg);
LUALIB_API lua_Number luaL_optnumber (lua_State *L, int nArg, lua_Number def);

LUALIB_API void luaL_checkstack (lua_State *L, int sz, const char *msg);
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
LUALIB_API void luaL_checkany (lua_State *L, int narg);

LUALIB_API int   luaL_newmetatable (lua_State *L, const char *tname);
LUALIB_API void  luaL_getmetatable (lua_State *L, const char *tname);
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname);

LUALIB_API void luaL_where (lua_State *L, int lvl);
LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...);

LUALIB_API int luaL_findstring (const char *st, const char *const lst[]);

LUALIB_API int luaL_ref (lua_State *L, int t);
LUALIB_API void luaL_unref (lua_State *L, int t, int ref);

LUALIB_API int luaL_getn (lua_State *L, int t);
LUALIB_API void luaL_setn (lua_State *L, int t, int n);

LUALIB_API int luaL_loadfile (lua_State *L, const char *filename);
LUALIB_API int luaL_loadbuffer (lua_State *L, const char *buff, size_t sz,
                                const char *name);



/*
** ===============================================================
** some useful macros
** ===============================================================
*/

#define luaL_argcheck(L, cond,numarg,extramsg) if (!(cond)) \
                                               luaL_argerror(L, numarg,extramsg)
#define luaL_checkstring(L,n)	(luaL_checklstring(L, (n), NULL))
#define luaL_optstring(L,n,d)	(luaL_optlstring(L, (n), (d), NULL))
#define luaL_checkint(L,n)	((int)luaL_checknumber(L, n))
#define luaL_checklong(L,n)	((long)luaL_checknumber(L, n))
#define luaL_optint(L,n,d)	((int)luaL_optnumber(L, n,(lua_Number)(d)))
#define luaL_optlong(L,n,d)	((long)luaL_optnumber(L, n,(lua_Number)(d)))


/*
** {======================================================
** Generic Buffer manipulation
** =======================================================
*/


#ifndef LUAL_BUFFERSIZE
#define LUAL_BUFFERSIZE	  BUFSIZ
#endif


typedef struct luaL_Buffer {
  char *p;			/* current position in buffer */
  int lvl;  /* number of strings in the stack (level) */
  lua_State *L;
  char buffer[LUAL_BUFFERSIZE];
} luaL_Buffer;

#define luaL_putchar(B,c) \
  ((void)((B)->p < ((B)->buffer+LUAL_BUFFERSIZE) || luaL_prepbuffer(B)), \
   (*(B)->p++ = (char)(c)))

#define luaL_addsize(B,n)	((B)->p += (n))

LUALIB_API void luaL_buffinit (lua_State *L, luaL_Buffer *B);
LUALIB_API char *luaL_prepbuffer (luaL_Buffer *B);
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l);
LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s);
LUALIB_API void luaL_addvalue (luaL_Buffer *B);
LUALIB_API void luaL_pushresult (luaL_Buffer *B);


/* }====================================================== */



/*
** Compatibility macros and functions
*/

LUALIB_API int   lua_dofile (lua_State *L, const char *filename);
LUALIB_API int   lua_dostring (lua_State *L, const char *str);
LUALIB_API int   lua_dobuffer (lua_State *L, const char *buff, size_t sz,
                               const char *n);


#define luaL_check_lstr 	luaL_checklstring
#define luaL_opt_lstr 	luaL_optlstring 
#define luaL_check_number 	luaL_checknumber 
#define luaL_opt_number	luaL_optnumber
#define luaL_arg_check	luaL_argcheck
#define luaL_check_string	luaL_checkstring
#define luaL_opt_string	luaL_optstring
#define luaL_check_int	luaL_checkint
#define luaL_check_long	luaL_checklong
#define luaL_opt_int	luaL_optint
#define luaL_opt_long	luaL_optlong


#endif


Added lua-5.0.2/include/lua.h.















































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: lua.h,v 1.175b 2003/03/18 12:31:39 roberto Exp $
** Lua - An Extensible Extension Language
** Tecgraf: Computer Graphics Technology Group, PUC-Rio, Brazil
** http://www.lua.org	mailto:info@lua.org
** See Copyright Notice at the end of this file
*/


#ifndef lua_h
#define lua_h

#include <stdarg.h>
#include <stddef.h>


#define LUA_VERSION	"Lua 5.0.2"
#define LUA_COPYRIGHT	"Copyright (C) 1994-2004 Tecgraf, PUC-Rio"
#define LUA_AUTHORS 	"R. Ierusalimschy, L. H. de Figueiredo & W. Celes"



/* option for multiple returns in `lua_pcall' and `lua_call' */
#define LUA_MULTRET	(-1)


/*
** pseudo-indices
*/
#define LUA_REGISTRYINDEX	(-10000)
#define LUA_GLOBALSINDEX	(-10001)
#define lua_upvalueindex(i)	(LUA_GLOBALSINDEX-(i))


/* error codes for `lua_load' and `lua_pcall' */
#define LUA_ERRRUN	1
#define LUA_ERRFILE	2
#define LUA_ERRSYNTAX	3
#define LUA_ERRMEM	4
#define LUA_ERRERR	5


typedef struct lua_State lua_State;

typedef int (*lua_CFunction) (lua_State *L);


/*
** functions that read/write blocks when loading/dumping Lua chunks
*/
typedef const char * (*lua_Chunkreader) (lua_State *L, void *ud, size_t *sz);

typedef int (*lua_Chunkwriter) (lua_State *L, const void* p,
                                size_t sz, void* ud);


/*
** basic types
*/
#define LUA_TNONE	(-1)

#define LUA_TNIL	0
#define LUA_TBOOLEAN	1
#define LUA_TLIGHTUSERDATA	2
#define LUA_TNUMBER	3
#define LUA_TSTRING	4
#define LUA_TTABLE	5
#define LUA_TFUNCTION	6
#define LUA_TUSERDATA	7
#define LUA_TTHREAD	8


/* minimum Lua stack available to a C function */
#define LUA_MINSTACK	20


/*
** generic extra include file
*/
#ifdef LUA_USER_H
#include LUA_USER_H
#endif


/* type of numbers in Lua */
#ifndef LUA_NUMBER
typedef double lua_Number;
#else
typedef LUA_NUMBER lua_Number;
#endif


/* mark for all API functions */
#ifndef LUA_API
#define LUA_API		extern
#endif


/*
** state manipulation
*/
LUA_API lua_State *lua_open (void);
LUA_API void       lua_close (lua_State *L);
LUA_API lua_State *lua_newthread (lua_State *L);

LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf);


/*
** basic stack manipulation
*/
LUA_API int   lua_gettop (lua_State *L);
LUA_API void  lua_settop (lua_State *L, int idx);
LUA_API void  lua_pushvalue (lua_State *L, int idx);
LUA_API void  lua_remove (lua_State *L, int idx);
LUA_API void  lua_insert (lua_State *L, int idx);
LUA_API void  lua_replace (lua_State *L, int idx);
LUA_API int   lua_checkstack (lua_State *L, int sz);

LUA_API void  lua_xmove (lua_State *from, lua_State *to, int n);


/*
** access functions (stack -> C)
*/

LUA_API int             lua_isnumber (lua_State *L, int idx);
LUA_API int             lua_isstring (lua_State *L, int idx);
LUA_API int             lua_iscfunction (lua_State *L, int idx);
LUA_API int             lua_isuserdata (lua_State *L, int idx);
LUA_API int             lua_type (lua_State *L, int idx);
LUA_API const char     *lua_typename (lua_State *L, int tp);

LUA_API int            lua_equal (lua_State *L, int idx1, int idx2);
LUA_API int            lua_rawequal (lua_State *L, int idx1, int idx2);
LUA_API int            lua_lessthan (lua_State *L, int idx1, int idx2);

LUA_API lua_Number      lua_tonumber (lua_State *L, int idx);
LUA_API int             lua_toboolean (lua_State *L, int idx);
LUA_API const char     *lua_tostring (lua_State *L, int idx);
LUA_API size_t          lua_strlen (lua_State *L, int idx);
LUA_API lua_CFunction   lua_tocfunction (lua_State *L, int idx);
LUA_API void	       *lua_touserdata (lua_State *L, int idx);
LUA_API lua_State      *lua_tothread (lua_State *L, int idx);
LUA_API const void     *lua_topointer (lua_State *L, int idx);


/*
** push functions (C -> stack)
*/
LUA_API void  lua_pushnil (lua_State *L);
LUA_API void  lua_pushnumber (lua_State *L, lua_Number n);
LUA_API void  lua_pushlstring (lua_State *L, const char *s, size_t l);
LUA_API void  lua_pushstring (lua_State *L, const char *s);
LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
                                                    va_list argp);
LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...);
LUA_API void  lua_pushcclosure (lua_State *L, lua_CFunction fn, int n);
LUA_API void  lua_pushboolean (lua_State *L, int b);
LUA_API void  lua_pushlightuserdata (lua_State *L, void *p);


/*
** get functions (Lua -> stack)
*/
LUA_API void  lua_gettable (lua_State *L, int idx);
LUA_API void  lua_rawget (lua_State *L, int idx);
LUA_API void  lua_rawgeti (lua_State *L, int idx, int n);
LUA_API void  lua_newtable (lua_State *L);
LUA_API void *lua_newuserdata (lua_State *L, size_t sz);
LUA_API int   lua_getmetatable (lua_State *L, int objindex);
LUA_API void  lua_getfenv (lua_State *L, int idx);


/*
** set functions (stack -> Lua)
*/
LUA_API void  lua_settable (lua_State *L, int idx);
LUA_API void  lua_rawset (lua_State *L, int idx);
LUA_API void  lua_rawseti (lua_State *L, int idx, int n);
LUA_API int   lua_setmetatable (lua_State *L, int objindex);
LUA_API int   lua_setfenv (lua_State *L, int idx);


/*
** `load' and `call' functions (load and run Lua code)
*/
LUA_API void  lua_call (lua_State *L, int nargs, int nresults);
LUA_API int   lua_pcall (lua_State *L, int nargs, int nresults, int errfunc);
LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud);
LUA_API int   lua_load (lua_State *L, lua_Chunkreader reader, void *dt,
                        const char *chunkname);

LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data);


/*
** coroutine functions
*/
LUA_API int  lua_yield (lua_State *L, int nresults);
LUA_API int  lua_resume (lua_State *L, int narg);

/*
** garbage-collection functions
*/
LUA_API int   lua_getgcthreshold (lua_State *L);
LUA_API int   lua_getgccount (lua_State *L);
LUA_API void  lua_setgcthreshold (lua_State *L, int newthreshold);

/*
** miscellaneous functions
*/

LUA_API const char *lua_version (void);

LUA_API int   lua_error (lua_State *L);

LUA_API int   lua_next (lua_State *L, int idx);

LUA_API void  lua_concat (lua_State *L, int n);



/* 
** ===============================================================
** some useful macros
** ===============================================================
*/

#define lua_boxpointer(L,u) \
	(*(void **)(lua_newuserdata(L, sizeof(void *))) = (u))

#define lua_unboxpointer(L,i)	(*(void **)(lua_touserdata(L, i)))

#define lua_pop(L,n)		lua_settop(L, -(n)-1)

#define lua_register(L,n,f) \
	(lua_pushstring(L, n), \
	 lua_pushcfunction(L, f), \
	 lua_settable(L, LUA_GLOBALSINDEX))

#define lua_pushcfunction(L,f)	lua_pushcclosure(L, f, 0)

#define lua_isfunction(L,n)	(lua_type(L,n) == LUA_TFUNCTION)
#define lua_istable(L,n)	(lua_type(L,n) == LUA_TTABLE)
#define lua_islightuserdata(L,n)	(lua_type(L,n) == LUA_TLIGHTUSERDATA)
#define lua_isnil(L,n)		(lua_type(L,n) == LUA_TNIL)
#define lua_isboolean(L,n)	(lua_type(L,n) == LUA_TBOOLEAN)
#define lua_isnone(L,n)		(lua_type(L,n) == LUA_TNONE)
#define lua_isnoneornil(L, n)	(lua_type(L,n) <= 0)

#define lua_pushliteral(L, s)	\
	lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1)



/*
** compatibility macros and functions
*/


LUA_API int lua_pushupvalues (lua_State *L);

#define lua_getregistry(L)	lua_pushvalue(L, LUA_REGISTRYINDEX)
#define lua_setglobal(L,s)	\
   (lua_pushstring(L, s), lua_insert(L, -2), lua_settable(L, LUA_GLOBALSINDEX))

#define lua_getglobal(L,s)	\
		(lua_pushstring(L, s), lua_gettable(L, LUA_GLOBALSINDEX))


/* compatibility with ref system */

/* pre-defined references */
#define LUA_NOREF	(-2)
#define LUA_REFNIL	(-1)

#define lua_ref(L,lock)	((lock) ? luaL_ref(L, LUA_REGISTRYINDEX) : \
      (lua_pushstring(L, "unlocked references are obsolete"), lua_error(L), 0))

#define lua_unref(L,ref)	luaL_unref(L, LUA_REGISTRYINDEX, (ref))

#define lua_getref(L,ref)	lua_rawgeti(L, LUA_REGISTRYINDEX, ref)



/*
** {======================================================================
** useful definitions for Lua kernel and libraries
** =======================================================================
*/

/* formats for Lua numbers */
#ifndef LUA_NUMBER_SCAN
#define LUA_NUMBER_SCAN		"%lf"
#endif

#ifndef LUA_NUMBER_FMT
#define LUA_NUMBER_FMT		"%.14g"
#endif

/* }====================================================================== */


/*
** {======================================================================
** Debug API
** =======================================================================
*/


/*
** Event codes
*/
#define LUA_HOOKCALL	0
#define LUA_HOOKRET	1
#define LUA_HOOKLINE	2
#define LUA_HOOKCOUNT	3
#define LUA_HOOKTAILRET 4


/*
** Event masks
*/
#define LUA_MASKCALL	(1 << LUA_HOOKCALL)
#define LUA_MASKRET	(1 << LUA_HOOKRET)
#define LUA_MASKLINE	(1 << LUA_HOOKLINE)
#define LUA_MASKCOUNT	(1 << LUA_HOOKCOUNT)

typedef struct lua_Debug lua_Debug;  /* activation record */

typedef void (*lua_Hook) (lua_State *L, lua_Debug *ar);


LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar);
LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar);
LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n);
LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n);
LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n);

LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count);
LUA_API lua_Hook lua_gethook (lua_State *L);
LUA_API int lua_gethookmask (lua_State *L);
LUA_API int lua_gethookcount (lua_State *L);


#define LUA_IDSIZE	60

struct lua_Debug {
  int event;
  const char *name;	/* (n) */
  const char *namewhat;	/* (n) `global', `local', `field', `method' */
  const char *what;	/* (S) `Lua', `C', `main', `tail' */
  const char *source;	/* (S) */
  int currentline;	/* (l) */
  int nups;		/* (u) number of upvalues */
  int linedefined;	/* (S) */
  char short_src[LUA_IDSIZE]; /* (S) */
  /* private part */
  int i_ci;  /* active function */
};

/* }====================================================================== */


/******************************************************************************
* Copyright (C) 1994-2004 Tecgraf, PUC-Rio.  All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
******************************************************************************/


#endif

Added lua-5.0.2/include/lualib.h.

















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: lualib.h,v 1.28 2003/03/18 12:24:26 roberto Exp $
** Lua standard libraries
** See Copyright Notice in lua.h
*/


#ifndef lualib_h
#define lualib_h

#include "lua.h"


#ifndef LUALIB_API
#define LUALIB_API	LUA_API
#endif


#define LUA_COLIBNAME	"coroutine"
LUALIB_API int luaopen_base (lua_State *L);

#define LUA_TABLIBNAME	"table"
LUALIB_API int luaopen_table (lua_State *L);

#define LUA_IOLIBNAME	"io"
#define LUA_OSLIBNAME	"os"
LUALIB_API int luaopen_io (lua_State *L);

#define LUA_STRLIBNAME	"string"
LUALIB_API int luaopen_string (lua_State *L);

#define LUA_MATHLIBNAME	"math"
LUALIB_API int luaopen_math (lua_State *L);

#define LUA_DBLIBNAME	"debug"
LUALIB_API int luaopen_debug (lua_State *L);


LUALIB_API int luaopen_loadlib (lua_State *L);


/* to help testing the libraries */
#ifndef lua_assert
#define lua_assert(c)		/* empty */
#endif


/* compatibility code */
#define lua_baselibopen	luaopen_base
#define lua_tablibopen	luaopen_table
#define lua_iolibopen	luaopen_io
#define lua_strlibopen	luaopen_string
#define lua_mathlibopen	luaopen_math
#define lua_dblibopen	luaopen_debug

#endif

Added lua-5.0.2/lib/liblua.a.

cannot compute difference between binary files

Added lua-5.0.2/lib/liblualib.a.

cannot compute difference between binary files

Added lua-5.0.2/src/Makefile.











































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# makefile for Lua core library

LUA= ..

include $(LUA)/config

OBJS=	\
	lapi.o \
	lcode.o \
	ldebug.o \
	ldo.o \
	ldump.o \
	lfunc.o \
	lgc.o \
	llex.o \
	lmem.o \
	lobject.o \
	lopcodes.o \
	lparser.o \
	lstate.o \
	lstring.o \
	ltable.o \
	ltests.o \
	ltm.o \
	lundump.o \
	lvm.o \
	lzio.o

SRCS=	\
	lapi.c \
	lcode.c \
	ldebug.c \
	ldo.c \
	ldump.c \
	lfunc.c \
	lgc.c \
	llex.c \
	lmem.c \
	lobject.c \
	lopcodes.c \
	lparser.c \
	lstate.c \
	lstring.c \
	ltable.c \
	ltests.c \
	ltm.c \
	lundump.c \
	lvm.c \
	lzio.c \
	lapi.h \
	lcode.h \
	ldebug.h \
	ldo.h \
	lfunc.h \
	lgc.h \
	llex.h \
	llimits.h \
	lmem.h \
	lobject.h \
	lopcodes.h \
	lparser.h \
	lstate.h \
	lstring.h \
	ltable.h \
	ltm.h \
	lundump.h \
	lvm.h \
	lzio.h

T= $(LIB)/liblua.a

all:	$T

$T:	$(OBJS)
	$(AR) $@ $(OBJS)
	$(RANLIB) $@

clean:
	rm -f $(OBJS) $T

co:
	co -q -f -M $(SRCS)

klean:	clean
	rm -f $(SRCS)

Added lua-5.0.2/src/README.











>
>
>
>
>
1
2
3
4
5
This is the Lua core.

The standard Lua library are in lib/.
A sample interpreter is in lua/.
A standalone compiler is in luac/.

Added lua-5.0.2/src/lapi.c.





















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: lapi.c,v 1.235 2003/04/07 14:36:08 roberto Exp $
** Lua API
** See Copyright Notice in lua.h
*/


#include <assert.h>
#include <string.h>

#define lapi_c

#include "lua.h"

#include "lapi.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lundump.h"
#include "lvm.h"


const char lua_ident[] =
  "$Lua: " LUA_VERSION " " LUA_COPYRIGHT " $\n"
  "$Authors: " LUA_AUTHORS " $\n"
  "$URL: www.lua.org $\n";



#ifndef api_check
#define api_check(L, o)		/*{ assert(o); }*/
#endif

#define api_checknelems(L, n)	api_check(L, (n) <= (L->top - L->base))

#define api_incr_top(L)   {api_check(L, L->top < L->ci->top); L->top++;}




static TObject *negindex (lua_State *L, int idx) {
  if (idx > LUA_REGISTRYINDEX) {
    api_check(L, idx != 0 && -idx <= L->top - L->base);
    return L->top+idx;
  }
  else switch (idx) {  /* pseudo-indices */
    case LUA_REGISTRYINDEX: return registry(L);
    case LUA_GLOBALSINDEX: return gt(L);
    default: {
      TObject *func = (L->base - 1);
      idx = LUA_GLOBALSINDEX - idx;
      lua_assert(iscfunction(func));
      return (idx <= clvalue(func)->c.nupvalues)
                ? &clvalue(func)->c.upvalue[idx-1]
                : NULL;
    }
  }
}


static TObject *luaA_index (lua_State *L, int idx) {
  if (idx > 0) {
    api_check(L, idx <= L->top - L->base);
    return L->base + idx - 1;
  }
  else {
    TObject *o = negindex(L, idx);
    api_check(L, o != NULL);
    return o;
  }
}


static TObject *luaA_indexAcceptable (lua_State *L, int idx) {
  if (idx > 0) {
    TObject *o = L->base+(idx-1);
    api_check(L, idx <= L->stack_last - L->base);
    if (o >= L->top) return NULL;
    else return o;
  }
  else
    return negindex(L, idx);
}


void luaA_pushobject (lua_State *L, const TObject *o) {
  setobj2s(L->top, o);
  incr_top(L);
}


LUA_API int lua_checkstack (lua_State *L, int size) {
  int res;
  lua_lock(L);
  if ((L->top - L->base + size) > LUA_MAXCSTACK)
    res = 0;  /* stack overflow */
  else {
    luaD_checkstack(L, size);
    if (L->ci->top < L->top + size)
      L->ci->top = L->top + size;
    res = 1;
  }
  lua_unlock(L);
  return res;
}


LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) {
  int i;
  lua_lock(to);
  api_checknelems(from, n);
  from->top -= n;
  for (i = 0; i < n; i++) {
    setobj2s(to->top, from->top + i);
    api_incr_top(to);
  }
  lua_unlock(to);
}


LUA_API lua_CFunction lua_atpanic (lua_State *L, lua_CFunction panicf) {
  lua_CFunction old;
  lua_lock(L);
  old = G(L)->panic;
  G(L)->panic = panicf;
  lua_unlock(L);
  return old;
}


LUA_API lua_State *lua_newthread (lua_State *L) {
  lua_State *L1;
  lua_lock(L);
  luaC_checkGC(L);
  L1 = luaE_newthread(L);
  setthvalue(L->top, L1);
  api_incr_top(L);
  lua_unlock(L);
  lua_userstateopen(L1);
  return L1;
}



/*
** basic stack manipulation
*/


LUA_API int lua_gettop (lua_State *L) {
  return (L->top - L->base);
}


LUA_API void lua_settop (lua_State *L, int idx) {
  lua_lock(L);
  if (idx >= 0) {
    api_check(L, idx <= L->stack_last - L->base);
    while (L->top < L->base + idx)
      setnilvalue(L->top++);
    L->top = L->base + idx;
  }
  else {
    api_check(L, -(idx+1) <= (L->top - L->base));
    L->top += idx+1;  /* `subtract' index (index is negative) */
  }
  lua_unlock(L);
}


LUA_API void lua_remove (lua_State *L, int idx) {
  StkId p;
  lua_lock(L);
  p = luaA_index(L, idx);
  while (++p < L->top) setobjs2s(p-1, p);
  L->top--;
  lua_unlock(L);
}


LUA_API void lua_insert (lua_State *L, int idx) {
  StkId p;
  StkId q;
  lua_lock(L);
  p = luaA_index(L, idx);
  for (q = L->top; q>p; q--) setobjs2s(q, q-1);
  setobjs2s(p, L->top);
  lua_unlock(L);
}


LUA_API void lua_replace (lua_State *L, int idx) {
  lua_lock(L);
  api_checknelems(L, 1);
  setobj(luaA_index(L, idx), L->top - 1);  /* write barrier */
  L->top--;
  lua_unlock(L);
}


LUA_API void lua_pushvalue (lua_State *L, int idx) {
  lua_lock(L);
  setobj2s(L->top, luaA_index(L, idx));
  api_incr_top(L);
  lua_unlock(L);
}



/*
** access functions (stack -> C)
*/


LUA_API int lua_type (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  return (o == NULL) ? LUA_TNONE : ttype(o);
}


LUA_API const char *lua_typename (lua_State *L, int t) {
  UNUSED(L);
  return (t == LUA_TNONE) ? "no value" : luaT_typenames[t];
}


LUA_API int lua_iscfunction (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  return (o == NULL) ? 0 : iscfunction(o);
}


LUA_API int lua_isnumber (lua_State *L, int idx) {
  TObject n;
  const TObject *o = luaA_indexAcceptable(L, idx);
  return (o != NULL && tonumber(o, &n));
}


LUA_API int lua_isstring (lua_State *L, int idx) {
  int t = lua_type(L, idx);
  return (t == LUA_TSTRING || t == LUA_TNUMBER);
}


LUA_API int lua_isuserdata (lua_State *L, int idx) {
  const TObject *o = luaA_indexAcceptable(L, idx);
  return (o != NULL && (ttisuserdata(o) || ttislightuserdata(o)));
}


LUA_API int lua_rawequal (lua_State *L, int index1, int index2) {
  StkId o1 = luaA_indexAcceptable(L, index1);
  StkId o2 = luaA_indexAcceptable(L, index2);
  return (o1 == NULL || o2 == NULL) ? 0  /* index out of range */
                                    : luaO_rawequalObj(o1, o2);
}


LUA_API int lua_equal (lua_State *L, int index1, int index2) {
  StkId o1, o2;
  int i;
  lua_lock(L);  /* may call tag method */
  o1 = luaA_indexAcceptable(L, index1);
  o2 = luaA_indexAcceptable(L, index2);
  i = (o1 == NULL || o2 == NULL) ? 0  /* index out of range */
                                 : equalobj(L, o1, o2);
  lua_unlock(L);
  return i;
}


LUA_API int lua_lessthan (lua_State *L, int index1, int index2) {
  StkId o1, o2;
  int i;
  lua_lock(L);  /* may call tag method */
  o1 = luaA_indexAcceptable(L, index1);
  o2 = luaA_indexAcceptable(L, index2);
  i = (o1 == NULL || o2 == NULL) ? 0  /* index out-of-range */
                                 : luaV_lessthan(L, o1, o2);
  lua_unlock(L);
  return i;
}



LUA_API lua_Number lua_tonumber (lua_State *L, int idx) {
  TObject n;
  const TObject *o = luaA_indexAcceptable(L, idx);
  if (o != NULL && tonumber(o, &n))
    return nvalue(o);
  else
    return 0;
}


LUA_API int lua_toboolean (lua_State *L, int idx) {
  const TObject *o = luaA_indexAcceptable(L, idx);
  return (o != NULL) && !l_isfalse(o);
}


LUA_API const char *lua_tostring (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  if (o == NULL)
    return NULL;
  else if (ttisstring(o))
    return svalue(o);
  else {
    const char *s;
    lua_lock(L);  /* `luaV_tostring' may create a new string */
    s = (luaV_tostring(L, o) ? svalue(o) : NULL);
    luaC_checkGC(L);
    lua_unlock(L);
    return s;
  }
}


LUA_API size_t lua_strlen (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  if (o == NULL)
    return 0;
  else if (ttisstring(o))
    return tsvalue(o)->tsv.len;
  else {
    size_t l;
    lua_lock(L);  /* `luaV_tostring' may create a new string */
    l = (luaV_tostring(L, o) ? tsvalue(o)->tsv.len : 0);
    lua_unlock(L);
    return l;
  }
}


LUA_API lua_CFunction lua_tocfunction (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  return (o == NULL || !iscfunction(o)) ? NULL : clvalue(o)->c.f;
}


LUA_API void *lua_touserdata (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  if (o == NULL) return NULL;
  switch (ttype(o)) {
    case LUA_TUSERDATA: return (uvalue(o) + 1);
    case LUA_TLIGHTUSERDATA: return pvalue(o);
    default: return NULL;
  }
}


LUA_API lua_State *lua_tothread (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  return (o == NULL || !ttisthread(o)) ? NULL : thvalue(o);
}


LUA_API const void *lua_topointer (lua_State *L, int idx) {
  StkId o = luaA_indexAcceptable(L, idx);
  if (o == NULL) return NULL;
  else {
    switch (ttype(o)) {
      case LUA_TTABLE: return hvalue(o);
      case LUA_TFUNCTION: return clvalue(o);
      case LUA_TTHREAD: return thvalue(o);
      case LUA_TUSERDATA:
      case LUA_TLIGHTUSERDATA:
        return lua_touserdata(L, idx);
      default: return NULL;
    }
  }
}



/*
** push functions (C -> stack)
*/


LUA_API void lua_pushnil (lua_State *L) {
  lua_lock(L);
  setnilvalue(L->top);
  api_incr_top(L);
  lua_unlock(L);
}


LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
  lua_lock(L);
  setnvalue(L->top, n);
  api_incr_top(L);
  lua_unlock(L);
}


LUA_API void lua_pushlstring (lua_State *L, const char *s, size_t len) {
  lua_lock(L);
  luaC_checkGC(L);
  setsvalue2s(L->top, luaS_newlstr(L, s, len));
  api_incr_top(L);
  lua_unlock(L);
}


LUA_API void lua_pushstring (lua_State *L, const char *s) {
  if (s == NULL)
    lua_pushnil(L);
  else
    lua_pushlstring(L, s, strlen(s));
}


LUA_API const char *lua_pushvfstring (lua_State *L, const char *fmt,
                                      va_list argp) {
  const char *ret;
  lua_lock(L);
  luaC_checkGC(L);
  ret = luaO_pushvfstring(L, fmt, argp);
  lua_unlock(L);
  return ret;
}


LUA_API const char *lua_pushfstring (lua_State *L, const char *fmt, ...) {
  const char *ret;
  va_list argp;
  lua_lock(L);
  luaC_checkGC(L);
  va_start(argp, fmt);
  ret = luaO_pushvfstring(L, fmt, argp);
  va_end(argp);
  lua_unlock(L);
  return ret;
}


LUA_API void lua_pushcclosure (lua_State *L, lua_CFunction fn, int n) {
  Closure *cl;
  lua_lock(L);
  luaC_checkGC(L);
  api_checknelems(L, n);
  cl = luaF_newCclosure(L, n);
  cl->c.f = fn;
  L->top -= n;
  while (n--)
    setobj2n(&cl->c.upvalue[n], L->top+n);
  setclvalue(L->top, cl);
  api_incr_top(L);
  lua_unlock(L);
}


LUA_API void lua_pushboolean (lua_State *L, int b) {
  lua_lock(L);
  setbvalue(L->top, (b != 0));  /* ensure that true is 1 */
  api_incr_top(L);
  lua_unlock(L);
}


LUA_API void lua_pushlightuserdata (lua_State *L, void *p) {
  lua_lock(L);
  setpvalue(L->top, p);
  api_incr_top(L);
  lua_unlock(L);
}



/*
** get functions (Lua -> stack)
*/


LUA_API void lua_gettable (lua_State *L, int idx) {
  StkId t;
  lua_lock(L);
  t = luaA_index(L, idx);
  setobj2s(L->top - 1, luaV_gettable(L, t, L->top - 1, 0));
  lua_unlock(L);
}


LUA_API void lua_rawget (lua_State *L, int idx) {
  StkId t;
  lua_lock(L);
  t = luaA_index(L, idx);
  api_check(L, ttistable(t));
  setobj2s(L->top - 1, luaH_get(hvalue(t), L->top - 1));
  lua_unlock(L);
}


LUA_API void lua_rawgeti (lua_State *L, int idx, int n) {
  StkId o;
  lua_lock(L);
  o = luaA_index(L, idx);
  api_check(L, ttistable(o));
  setobj2s(L->top, luaH_getnum(hvalue(o), n));
  api_incr_top(L);
  lua_unlock(L);
}


LUA_API void lua_newtable (lua_State *L) {
  lua_lock(L);
  luaC_checkGC(L);
  sethvalue(L->top, luaH_new(L, 0, 0));
  api_incr_top(L);
  lua_unlock(L);
}


LUA_API int lua_getmetatable (lua_State *L, int objindex) {
  const TObject *obj;
  Table *mt = NULL;
  int res;
  lua_lock(L);
  obj = luaA_indexAcceptable(L, objindex);
  if (obj != NULL) {
    switch (ttype(obj)) {
      case LUA_TTABLE:
        mt = hvalue(obj)->metatable;
        break;
      case LUA_TUSERDATA:
        mt = uvalue(obj)->uv.metatable;
        break;
    }
  }
  if (mt == NULL || mt == hvalue(defaultmeta(L)))
    res = 0;
  else {
    sethvalue(L->top, mt);
    api_incr_top(L);
    res = 1;
  }
  lua_unlock(L);
  return res;
}


LUA_API void lua_getfenv (lua_State *L, int idx) {
  StkId o;
  lua_lock(L);
  o = luaA_index(L, idx);
  setobj2s(L->top, isLfunction(o) ? &clvalue(o)->l.g : gt(L));
  api_incr_top(L);
  lua_unlock(L);
}


/*
** set functions (stack -> Lua)
*/


LUA_API void lua_settable (lua_State *L, int idx) {
  StkId t;
  lua_lock(L);
  api_checknelems(L, 2);
  t = luaA_index(L, idx);
  luaV_settable(L, t, L->top - 2, L->top - 1);
  L->top -= 2;  /* pop index and value */
  lua_unlock(L);
}


LUA_API void lua_rawset (lua_State *L, int idx) {
  StkId t;
  lua_lock(L);
  api_checknelems(L, 2);
  t = luaA_index(L, idx);
  api_check(L, ttistable(t));
  setobj2t(luaH_set(L, hvalue(t), L->top-2), L->top-1);  /* write barrier */
  L->top -= 2;
  lua_unlock(L);
}


LUA_API void lua_rawseti (lua_State *L, int idx, int n) {
  StkId o;
  lua_lock(L);
  api_checknelems(L, 1);
  o = luaA_index(L, idx);
  api_check(L, ttistable(o));
  setobj2t(luaH_setnum(L, hvalue(o), n), L->top-1);  /* write barrier */
  L->top--;
  lua_unlock(L);
}


LUA_API int lua_setmetatable (lua_State *L, int objindex) {
  TObject *obj, *mt;
  int res = 1;
  lua_lock(L);
  api_checknelems(L, 1);
  obj = luaA_index(L, objindex);
  mt = (!ttisnil(L->top - 1)) ? L->top - 1 : defaultmeta(L);
  api_check(L, ttistable(mt));
  switch (ttype(obj)) {
    case LUA_TTABLE: {
      hvalue(obj)->metatable = hvalue(mt);  /* write barrier */
      break;
    }
    case LUA_TUSERDATA: {
      uvalue(obj)->uv.metatable = hvalue(mt);  /* write barrier */
      break;
    }
    default: {
      res = 0;  /* cannot set */
      break;
    }
  }
  L->top--;
  lua_unlock(L);
  return res;
}


LUA_API int lua_setfenv (lua_State *L, int idx) {
  StkId o;
  int res = 0;
  lua_lock(L);
  api_checknelems(L, 1);
  o = luaA_index(L, idx);
  L->top--;
  api_check(L, ttistable(L->top));
  if (isLfunction(o)) {
    res = 1;
    clvalue(o)->l.g = *(L->top);
  }
  lua_unlock(L);
  return res;
}


/*
** `load' and `call' functions (run Lua code)
*/

LUA_API void lua_call (lua_State *L, int nargs, int nresults) {
  StkId func;
  lua_lock(L);
  api_checknelems(L, nargs+1);
  func = L->top - (nargs+1);
  luaD_call(L, func, nresults);
  lua_unlock(L);
}



/*
** Execute a protected call.
*/
struct CallS {  /* data to `f_call' */
  StkId func;
  int nresults;
};


static void f_call (lua_State *L, void *ud) {
  struct CallS *c = cast(struct CallS *, ud);
  luaD_call(L, c->func, c->nresults);
}



LUA_API int lua_pcall (lua_State *L, int nargs, int nresults, int errfunc) {
  struct CallS c;
  int status;
  ptrdiff_t func;
  lua_lock(L);
  func = (errfunc == 0) ? 0 : savestack(L, luaA_index(L, errfunc));
  c.func = L->top - (nargs+1);  /* function to be called */
  c.nresults = nresults;
  status = luaD_pcall(L, f_call, &c, savestack(L, c.func), func);
  lua_unlock(L);
  return status;
}


/*
** Execute a protected C call.
*/
struct CCallS {  /* data to `f_Ccall' */
  lua_CFunction func;
  void *ud;
};


static void f_Ccall (lua_State *L, void *ud) {
  struct CCallS *c = cast(struct CCallS *, ud);
  Closure *cl;
  cl = luaF_newCclosure(L, 0);
  cl->c.f = c->func;
  setclvalue(L->top, cl);  /* push function */
  incr_top(L);
  setpvalue(L->top, c->ud);  /* push only argument */
  incr_top(L);
  luaD_call(L, L->top - 2, 0);
}


LUA_API int lua_cpcall (lua_State *L, lua_CFunction func, void *ud) {
  struct CCallS c;
  int status;
  lua_lock(L);
  c.func = func;
  c.ud = ud;
  status = luaD_pcall(L, f_Ccall, &c, savestack(L, L->top), 0);
  lua_unlock(L);
  return status;
}


LUA_API int lua_load (lua_State *L, lua_Chunkreader reader, void *data,
                      const char *chunkname) {
  ZIO z;
  int status;
  int c;
  lua_lock(L);
  if (!chunkname) chunkname = "?";
  luaZ_init(&z, reader, data, chunkname);
  c = luaZ_lookahead(&z);
  status = luaD_protectedparser(L, &z, (c == LUA_SIGNATURE[0]));
  lua_unlock(L);
  return status;
}


LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) {
  int status;
  TObject *o;
  lua_lock(L);
  api_checknelems(L, 1);
  o = L->top - 1;
  if (isLfunction(o) && clvalue(o)->l.nupvalues == 0) {
    luaU_dump(L, clvalue(o)->l.p, writer, data);
    status = 1;
  }
  else
    status = 0;
  lua_unlock(L);
  return status;
}


/*
** Garbage-collection functions
*/

/* GC values are expressed in Kbytes: #bytes/2^10 */
#define GCscalel(x)		((x)>>10)
#define GCscale(x)		(cast(int, GCscalel(x)))
#define GCunscale(x)		(cast(lu_mem, x)<<10)

LUA_API int lua_getgcthreshold (lua_State *L) {
  int threshold;
  lua_lock(L);
  threshold = GCscale(G(L)->GCthreshold);
  lua_unlock(L);
  return threshold;
}

LUA_API int lua_getgccount (lua_State *L) {
  int count;
  lua_lock(L);
  count = GCscale(G(L)->nblocks);
  lua_unlock(L);
  return count;
}

LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
  lua_lock(L);
  if (cast(lu_mem, newthreshold) > GCscalel(MAX_LUMEM))
    G(L)->GCthreshold = MAX_LUMEM;
  else
    G(L)->GCthreshold = GCunscale(newthreshold);
  luaC_checkGC(L);
  lua_unlock(L);
}


/*
** miscellaneous functions
*/


LUA_API const char *lua_version (void) {
  return LUA_VERSION;
}


LUA_API int lua_error (lua_State *L) {
  lua_lock(L);
  api_checknelems(L, 1);
  luaG_errormsg(L);
  lua_unlock(L);
  return 0;  /* to avoid warnings */
}


LUA_API int lua_next (lua_State *L, int idx) {
  StkId t;
  int more;
  lua_lock(L);
  t = luaA_index(L, idx);
  api_check(L, ttistable(t));
  more = luaH_next(L, hvalue(t), L->top - 1);
  if (more) {
    api_incr_top(L);
  }
  else  /* no more elements */
    L->top -= 1;  /* remove key */
  lua_unlock(L);
  return more;
}


LUA_API void lua_concat (lua_State *L, int n) {
  lua_lock(L);
  luaC_checkGC(L);
  api_checknelems(L, n);
  if (n >= 2) {
    luaV_concat(L, n, L->top - L->base - 1);
    L->top -= (n-1);
  }
  else if (n == 0) {  /* push empty string */
    setsvalue2s(L->top, luaS_newlstr(L, NULL, 0));
    api_incr_top(L);
  }
  /* else n == 1; nothing to do */
  lua_unlock(L);
}


LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
  Udata *u;
  lua_lock(L);
  luaC_checkGC(L);
  u = luaS_newudata(L, size);
  setuvalue(L->top, u);
  api_incr_top(L);
  lua_unlock(L);
  return u + 1;
}


LUA_API int lua_pushupvalues (lua_State *L) {
  Closure *func;
  int n, i;
  lua_lock(L);
  api_check(L, iscfunction(L->base - 1));
  func = clvalue(L->base - 1);
  n = func->c.nupvalues;
  luaD_checkstack(L, n + LUA_MINSTACK);
  for (i=0; i<n; i++) {
    setobj2s(L->top, &func->c.upvalue[i]);
    L->top++;
  }
  lua_unlock(L);
  return n;
}


static const char *aux_upvalue (lua_State *L, int funcindex, int n,
                                TObject **val) {
  Closure *f;
  StkId fi = luaA_index(L, funcindex);
  if (!ttisfunction(fi)) return NULL;
  f = clvalue(fi);
  if (f->c.isC) {
    if (n > f->c.nupvalues) return NULL;
    *val = &f->c.upvalue[n-1];
    return "";
  }
  else {
    Proto *p = f->l.p;
    if (n > p->sizeupvalues) return NULL;
    *val = f->l.upvals[n-1]->v;
    return getstr(p->upvalues[n-1]);
  }
}


LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
  const char *name;
  TObject *val;
  lua_lock(L);
  name = aux_upvalue(L, funcindex, n, &val);
  if (name) {
    setobj2s(L->top, val);
    api_incr_top(L);
  }
  lua_unlock(L);
  return name;
}


LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
  const char *name;
  TObject *val;
  lua_lock(L);
  api_checknelems(L, 1);
  name = aux_upvalue(L, funcindex, n, &val);
  if (name) {
    L->top--;
    setobj(val, L->top);  /* write barrier */
  }
  lua_unlock(L);
  return name;
}

Added lua-5.0.2/src/lapi.h.

































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
** $Id: lapi.h,v 1.21 2002/03/04 21:29:41 roberto Exp $
** Auxiliary functions from Lua API
** See Copyright Notice in lua.h
*/

#ifndef lapi_h
#define lapi_h


#include "lobject.h"


void luaA_pushobject (lua_State *L, const TObject *o);

#endif

Added lua-5.0.2/src/lcode.c.





















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: lcode.c,v 1.117 2003/04/03 13:35:34 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/


#include <stdlib.h>

#define lcode_c

#include "lua.h"

#include "lcode.h"
#include "ldebug.h"
#include "ldo.h"
#include "llex.h"
#include "lmem.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"
#include "ltable.h"


#define hasjumps(e)	((e)->t != (e)->f)


void luaK_nil (FuncState *fs, int from, int n) {
  Instruction *previous;
  if (fs->pc > fs->lasttarget &&  /* no jumps to current position? */
      GET_OPCODE(*(previous = &fs->f->code[fs->pc-1])) == OP_LOADNIL) {
    int pfrom = GETARG_A(*previous);
    int pto = GETARG_B(*previous);
    if (pfrom <= from && from <= pto+1) {  /* can connect both? */
      if (from+n-1 > pto)
        SETARG_B(*previous, from+n-1);
      return;
    }
  }
  luaK_codeABC(fs, OP_LOADNIL, from, from+n-1, 0);  /* else no optimization */
}


int luaK_jump (FuncState *fs) {
  int jpc = fs->jpc;  /* save list of jumps to here */
  int j;
  fs->jpc = NO_JUMP;
  j = luaK_codeAsBx(fs, OP_JMP, 0, NO_JUMP);
  luaK_concat(fs, &j, jpc);  /* keep them on hold */
  return j;
}


static int luaK_condjump (FuncState *fs, OpCode op, int A, int B, int C) {
  luaK_codeABC(fs, op, A, B, C);
  return luaK_jump(fs);
}


static void luaK_fixjump (FuncState *fs, int pc, int dest) {
  Instruction *jmp = &fs->f->code[pc];
  int offset = dest-(pc+1);
  lua_assert(dest != NO_JUMP);
  if (abs(offset) > MAXARG_sBx)
    luaX_syntaxerror(fs->ls, "control structure too long");
  SETARG_sBx(*jmp, offset);
}


/*
** returns current `pc' and marks it as a jump target (to avoid wrong
** optimizations with consecutive instructions not in the same basic block).
*/
int luaK_getlabel (FuncState *fs) {
  fs->lasttarget = fs->pc;
  return fs->pc;
}


static int luaK_getjump (FuncState *fs, int pc) {
  int offset = GETARG_sBx(fs->f->code[pc]);
  if (offset == NO_JUMP)  /* point to itself represents end of list */
    return NO_JUMP;  /* end of list */
  else
    return (pc+1)+offset;  /* turn offset into absolute position */
}


static Instruction *getjumpcontrol (FuncState *fs, int pc) {
  Instruction *pi = &fs->f->code[pc];
  if (pc >= 1 && testOpMode(GET_OPCODE(*(pi-1)), OpModeT))
    return pi-1;
  else
    return pi;
}


/*
** check whether list has any jump that do not produce a value
** (or produce an inverted value)
*/
static int need_value (FuncState *fs, int list, int cond) {
  for (; list != NO_JUMP; list = luaK_getjump(fs, list)) {
    Instruction i = *getjumpcontrol(fs, list);
    if (GET_OPCODE(i) != OP_TEST || GETARG_C(i) != cond) return 1;
  }
  return 0;  /* not found */
}


static void patchtestreg (Instruction *i, int reg) {
  if (reg == NO_REG) reg = GETARG_B(*i);
  SETARG_A(*i, reg);
}


static void luaK_patchlistaux (FuncState *fs, int list,
          int ttarget, int treg, int ftarget, int freg, int dtarget) {
  while (list != NO_JUMP) {
    int next = luaK_getjump(fs, list);
    Instruction *i = getjumpcontrol(fs, list);
    if (GET_OPCODE(*i) != OP_TEST) {
      lua_assert(dtarget != NO_JUMP);
      luaK_fixjump(fs, list, dtarget);  /* jump to default target */
    }
    else {
      if (GETARG_C(*i)) {
        lua_assert(ttarget != NO_JUMP);
        patchtestreg(i, treg);
        luaK_fixjump(fs, list, ttarget);
      }
      else {
        lua_assert(ftarget != NO_JUMP);
        patchtestreg(i, freg);
        luaK_fixjump(fs, list, ftarget);
      }
    }
    list = next;
  }
}


static void luaK_dischargejpc (FuncState *fs) {
  luaK_patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc, NO_REG, fs->pc);
  fs->jpc = NO_JUMP;
}


void luaK_patchlist (FuncState *fs, int list, int target) {
  if (target == fs->pc)
    luaK_patchtohere(fs, list);
  else {
    lua_assert(target < fs->pc);
    luaK_patchlistaux(fs, list, target, NO_REG, target, NO_REG, target);
  }
}


void luaK_patchtohere (FuncState *fs, int list) {
  luaK_getlabel(fs);
  luaK_concat(fs, &fs->jpc, list);
}


void luaK_concat (FuncState *fs, int *l1, int l2) {
  if (l2 == NO_JUMP) return;
  else if (*l1 == NO_JUMP)
    *l1 = l2;
  else {
    int list = *l1;
    int next;
    while ((next = luaK_getjump(fs, list)) != NO_JUMP)  /* find last element */
      list = next;
    luaK_fixjump(fs, list, l2);
  }
}


void luaK_checkstack (FuncState *fs, int n) {
  int newstack = fs->freereg + n;
  if (newstack > fs->f->maxstacksize) {
    if (newstack >= MAXSTACK)
      luaX_syntaxerror(fs->ls, "function or expression too complex");
    fs->f->maxstacksize = cast(lu_byte, newstack);
  }
}


void luaK_reserveregs (FuncState *fs, int n) {
  luaK_checkstack(fs, n);
  fs->freereg += n;
}


static void freereg (FuncState *fs, int reg) {
  if (reg >= fs->nactvar && reg < MAXSTACK) {
    fs->freereg--;
    lua_assert(reg == fs->freereg);
  }
}


static void freeexp (FuncState *fs, expdesc *e) {
  if (e->k == VNONRELOC)
    freereg(fs, e->info);
}


static int addk (FuncState *fs, TObject *k, TObject *v) {
  const TObject *idx = luaH_get(fs->h, k);
  if (ttisnumber(idx)) {
    lua_assert(luaO_rawequalObj(&fs->f->k[cast(int, nvalue(idx))], v));
    return cast(int, nvalue(idx));
  }
  else {  /* constant not found; create a new entry */
    Proto *f = fs->f;
    luaM_growvector(fs->L, f->k, fs->nk, f->sizek, TObject,
                    MAXARG_Bx, "constant table overflow");
    setobj2n(&f->k[fs->nk], v);
    setnvalue(luaH_set(fs->L, fs->h, k), cast(lua_Number, fs->nk));
    return fs->nk++;
  }
}


int luaK_stringK (FuncState *fs, TString *s) {
  TObject o;
  setsvalue(&o, s);
  return addk(fs, &o, &o);
}


int luaK_numberK (FuncState *fs, lua_Number r) {
  TObject o;
  setnvalue(&o, r);
  return addk(fs, &o, &o);
}


static int nil_constant (FuncState *fs) {
  TObject k, v;
  setnilvalue(&v);
  sethvalue(&k, fs->h);  /* cannot use nil as key; instead use table itself */
  return addk(fs, &k, &v);
}


void luaK_setcallreturns (FuncState *fs, expdesc *e, int nresults) {
  if (e->k == VCALL) {  /* expression is an open function call? */
    SETARG_C(getcode(fs, e), nresults+1);
    if (nresults == 1) {  /* `regular' expression? */
      e->k = VNONRELOC;
      e->info = GETARG_A(getcode(fs, e));
    }
  }
}


void luaK_dischargevars (FuncState *fs, expdesc *e) {
  switch (e->k) {
    case VLOCAL: {
      e->k = VNONRELOC;
      break;
    }
    case VUPVAL: {
      e->info = luaK_codeABC(fs, OP_GETUPVAL, 0, e->info, 0);
      e->k = VRELOCABLE;
      break;
    }
    case VGLOBAL: {
      e->info = luaK_codeABx(fs, OP_GETGLOBAL, 0, e->info);
      e->k = VRELOCABLE;
      break;
    }
    case VINDEXED: {
      freereg(fs, e->aux);
      freereg(fs, e->info);
      e->info = luaK_codeABC(fs, OP_GETTABLE, 0, e->info, e->aux);
      e->k = VRELOCABLE;
      break;
    }
    case VCALL: {
      luaK_setcallreturns(fs, e, 1);
      break;
    }
    default: break;  /* there is one value available (somewhere) */
  }
}


static int code_label (FuncState *fs, int A, int b, int jump) {
  luaK_getlabel(fs);  /* those instructions may be jump targets */
  return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
}


static void discharge2reg (FuncState *fs, expdesc *e, int reg) {
  luaK_dischargevars(fs, e);
  switch (e->k) {
    case VNIL: {
      luaK_nil(fs, reg, 1);
      break;
    }
    case VFALSE:  case VTRUE: {
      luaK_codeABC(fs, OP_LOADBOOL, reg, e->k == VTRUE, 0);
      break;
    }
    case VK: {
      luaK_codeABx(fs, OP_LOADK, reg, e->info);
      break;
    }
    case VRELOCABLE: {
      Instruction *pc = &getcode(fs, e);
      SETARG_A(*pc, reg);
      break;
    }
    case VNONRELOC: {
      if (reg != e->info)
        luaK_codeABC(fs, OP_MOVE, reg, e->info, 0);
      break;
    }
    default: {
      lua_assert(e->k == VVOID || e->k == VJMP);
      return;  /* nothing to do... */
    }
  }
  e->info = reg;
  e->k = VNONRELOC;
}


static void discharge2anyreg (FuncState *fs, expdesc *e) {
  if (e->k != VNONRELOC) {
    luaK_reserveregs(fs, 1);
    discharge2reg(fs, e, fs->freereg-1);
  }
}


static void luaK_exp2reg (FuncState *fs, expdesc *e, int reg) {
  discharge2reg(fs, e, reg);
  if (e->k == VJMP)
    luaK_concat(fs, &e->t, e->info);  /* put this jump in `t' list */
  if (hasjumps(e)) {
    int final;  /* position after whole expression */
    int p_f = NO_JUMP;  /* position of an eventual LOAD false */
    int p_t = NO_JUMP;  /* position of an eventual LOAD true */
    if (need_value(fs, e->t, 1) || need_value(fs, e->f, 0)) {
      int fj = NO_JUMP;  /* first jump (over LOAD ops.) */
      if (e->k != VJMP)
        fj = luaK_jump(fs);
      p_f = code_label(fs, reg, 0, 1);
      p_t = code_label(fs, reg, 1, 0);
      luaK_patchtohere(fs, fj);
    }
    final = luaK_getlabel(fs);
    luaK_patchlistaux(fs, e->f, p_f, NO_REG, final, reg, p_f);
    luaK_patchlistaux(fs, e->t, final, reg, p_t, NO_REG, p_t);
  }
  e->f = e->t = NO_JUMP;
  e->info = reg;
  e->k = VNONRELOC;
}


void luaK_exp2nextreg (FuncState *fs, expdesc *e) {
  luaK_dischargevars(fs, e);
  freeexp(fs, e);
  luaK_reserveregs(fs, 1);
  luaK_exp2reg(fs, e, fs->freereg - 1);
}


int luaK_exp2anyreg (FuncState *fs, expdesc *e) {
  luaK_dischargevars(fs, e);
  if (e->k == VNONRELOC) {
    if (!hasjumps(e)) return e->info;  /* exp is already in a register */ 
    if (e->info >= fs->nactvar) {  /* reg. is not a local? */
      luaK_exp2reg(fs, e, e->info);  /* put value on it */
      return e->info;
    }
  }
  luaK_exp2nextreg(fs, e);  /* default */
  return e->info;
}


void luaK_exp2val (FuncState *fs, expdesc *e) {
  if (hasjumps(e))
    luaK_exp2anyreg(fs, e);
  else
    luaK_dischargevars(fs, e);
}


int luaK_exp2RK (FuncState *fs, expdesc *e) {
  luaK_exp2val(fs, e);
  switch (e->k) {
    case VNIL: {
      if (fs->nk + MAXSTACK <= MAXARG_C) {  /* constant fit in argC? */
        e->info = nil_constant(fs);
        e->k = VK;
        return e->info + MAXSTACK;
      }
      else break;
    }
    case VK: {
      if (e->info + MAXSTACK <= MAXARG_C)  /* constant fit in argC? */
        return e->info + MAXSTACK;
      else break;
    }
    default: break;
  }
  /* not a constant in the right range: put it in a register */
  return luaK_exp2anyreg(fs, e);
}


void luaK_storevar (FuncState *fs, expdesc *var, expdesc *exp) {
  switch (var->k) {
    case VLOCAL: {
      freeexp(fs, exp);
      luaK_exp2reg(fs, exp, var->info);
      return;
    }
    case VUPVAL: {
      int e = luaK_exp2anyreg(fs, exp);
      luaK_codeABC(fs, OP_SETUPVAL, e, var->info, 0);
      break;
    }
    case VGLOBAL: {
      int e = luaK_exp2anyreg(fs, exp);
      luaK_codeABx(fs, OP_SETGLOBAL, e, var->info);
      break;
    }
    case VINDEXED: {
      int e = luaK_exp2RK(fs, exp);
      luaK_codeABC(fs, OP_SETTABLE, var->info, var->aux, e);
      break;
    }
    default: {
      lua_assert(0);  /* invalid var kind to store */
      break;
    }
  }
  freeexp(fs, exp);
}


void luaK_self (FuncState *fs, expdesc *e, expdesc *key) {
  int func;
  luaK_exp2anyreg(fs, e);
  freeexp(fs, e);
  func = fs->freereg;
  luaK_reserveregs(fs, 2);
  luaK_codeABC(fs, OP_SELF, func, e->info, luaK_exp2RK(fs, key));
  freeexp(fs, key);
  e->info = func;
  e->k = VNONRELOC;
}


static void invertjump (FuncState *fs, expdesc *e) {
  Instruction *pc = getjumpcontrol(fs, e->info);
  lua_assert(testOpMode(GET_OPCODE(*pc), OpModeT) &&
             GET_OPCODE(*pc) != OP_TEST);
  SETARG_A(*pc, !(GETARG_A(*pc)));
}


static int jumponcond (FuncState *fs, expdesc *e, int cond) {
  if (e->k == VRELOCABLE) {
    Instruction ie = getcode(fs, e);
    if (GET_OPCODE(ie) == OP_NOT) {
      fs->pc--;  /* remove previous OP_NOT */
      return luaK_condjump(fs, OP_TEST, NO_REG, GETARG_B(ie), !cond);
    }
    /* else go through */
  }
  discharge2anyreg(fs, e);
  freeexp(fs, e);
  return luaK_condjump(fs, OP_TEST, NO_REG, e->info, cond);
}


void luaK_goiftrue (FuncState *fs, expdesc *e) {
  int pc;  /* pc of last jump */
  luaK_dischargevars(fs, e);
  switch (e->k) {
    case VK: case VTRUE: {
      pc = NO_JUMP;  /* always true; do nothing */
      break;
    }
    case VFALSE: {
      pc = luaK_jump(fs);  /* always jump */
      break;
    }
    case VJMP: {
      invertjump(fs, e);
      pc = e->info;
      break;
    }
    default: {
      pc = jumponcond(fs, e, 0);
      break;
    }
  }
  luaK_concat(fs, &e->f, pc);  /* insert last jump in `f' list */
}


void luaK_goiffalse (FuncState *fs, expdesc *e) {
  int pc;  /* pc of last jump */
  luaK_dischargevars(fs, e);
  switch (e->k) {
    case VNIL: case VFALSE: {
      pc = NO_JUMP;  /* always false; do nothing */
      break;
    }
    case VTRUE: {
      pc = luaK_jump(fs);  /* always jump */
      break;
    }
    case VJMP: {
      pc = e->info;
      break;
    }
    default: {
      pc = jumponcond(fs, e, 1);
      break;
    }
  }
  luaK_concat(fs, &e->t, pc);  /* insert last jump in `t' list */
}


static void codenot (FuncState *fs, expdesc *e) {
  luaK_dischargevars(fs, e);
  switch (e->k) {
    case VNIL: case VFALSE: {
      e->k = VTRUE;
      break;
    }
    case VK: case VTRUE: {
      e->k = VFALSE;
      break;
    }
    case VJMP: {
      invertjump(fs, e);
      break;
    }
    case VRELOCABLE:
    case VNONRELOC: {
      discharge2anyreg(fs, e);
      freeexp(fs, e);
      e->info = luaK_codeABC(fs, OP_NOT, 0, e->info, 0);
      e->k = VRELOCABLE;
      break;
    }
    default: {
      lua_assert(0);  /* cannot happen */
      break;
    }
  }
  /* interchange true and false lists */
  { int temp = e->f; e->f = e->t; e->t = temp; }
}


void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) {
  t->aux = luaK_exp2RK(fs, k);
  t->k = VINDEXED;
}


void luaK_prefix (FuncState *fs, UnOpr op, expdesc *e) {
  if (op == OPR_MINUS) {
    luaK_exp2val(fs, e);
    if (e->k == VK && ttisnumber(&fs->f->k[e->info]))
      e->info = luaK_numberK(fs, -nvalue(&fs->f->k[e->info]));
    else {
      luaK_exp2anyreg(fs, e);
      freeexp(fs, e);
      e->info = luaK_codeABC(fs, OP_UNM, 0, e->info, 0);
      e->k = VRELOCABLE;
    }
  }
  else  /* op == NOT */
    codenot(fs, e);
}


void luaK_infix (FuncState *fs, BinOpr op, expdesc *v) {
  switch (op) {
    case OPR_AND: {
      luaK_goiftrue(fs, v);
      luaK_patchtohere(fs, v->t);
      v->t = NO_JUMP;
      break;
    }
    case OPR_OR: {
      luaK_goiffalse(fs, v);
      luaK_patchtohere(fs, v->f);
      v->f = NO_JUMP;
      break;
    }
    case OPR_CONCAT: {
      luaK_exp2nextreg(fs, v);  /* operand must be on the `stack' */
      break;
    }
    default: {
      luaK_exp2RK(fs, v);
      break;
    }
  }
}


static void codebinop (FuncState *fs, expdesc *res, BinOpr op,
                       int o1, int o2) {
  if (op <= OPR_POW) {  /* arithmetic operator? */
    OpCode opc = cast(OpCode, (op - OPR_ADD) + OP_ADD);  /* ORDER OP */
    res->info = luaK_codeABC(fs, opc, 0, o1, o2);
    res->k = VRELOCABLE;
  }
  else {  /* test operator */
    static const OpCode ops[] = {OP_EQ, OP_EQ, OP_LT, OP_LE, OP_LT, OP_LE};
    int cond = 1;
    if (op >= OPR_GT) {  /* `>' or `>='? */
      int temp;  /* exchange args and replace by `<' or `<=' */
      temp = o1; o1 = o2; o2 = temp;  /* o1 <==> o2 */
    }
    else if (op == OPR_NE) cond = 0;
    res->info = luaK_condjump(fs, ops[op - OPR_NE], cond, o1, o2);
    res->k = VJMP;
  }
}


void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
  switch (op) {
    case OPR_AND: {
      lua_assert(e1->t == NO_JUMP);  /* list must be closed */
      luaK_dischargevars(fs, e2);
      luaK_concat(fs, &e1->f, e2->f);
      e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->t = e2->t;
      break;
    }
    case OPR_OR: {
      lua_assert(e1->f == NO_JUMP);  /* list must be closed */
      luaK_dischargevars(fs, e2);
      luaK_concat(fs, &e1->t, e2->t);
      e1->k = e2->k; e1->info = e2->info; e1->aux = e2->aux; e1->f = e2->f;
      break;
    }
    case OPR_CONCAT: {
      luaK_exp2val(fs, e2);
      if (e2->k == VRELOCABLE && GET_OPCODE(getcode(fs, e2)) == OP_CONCAT) {
        lua_assert(e1->info == GETARG_B(getcode(fs, e2))-1);
        freeexp(fs, e1);
        SETARG_B(getcode(fs, e2), e1->info);
        e1->k = e2->k; e1->info = e2->info;
      }
      else {
        luaK_exp2nextreg(fs, e2);
        freeexp(fs, e2);
        freeexp(fs, e1);
        e1->info = luaK_codeABC(fs, OP_CONCAT, 0, e1->info, e2->info);
        e1->k = VRELOCABLE;
      }
      break;
    }
    default: {
      int o1 = luaK_exp2RK(fs, e1);
      int o2 = luaK_exp2RK(fs, e2);
      freeexp(fs, e2);
      freeexp(fs, e1);
      codebinop(fs, e1, op, o1, o2);
    }
  }
}


void luaK_fixline (FuncState *fs, int line) {
  fs->f->lineinfo[fs->pc - 1] = line;
}


int luaK_code (FuncState *fs, Instruction i, int line) {
  Proto *f = fs->f;
  luaK_dischargejpc(fs);  /* `pc' will change */
  /* put new instruction in code array */
  luaM_growvector(fs->L, f->code, fs->pc, f->sizecode, Instruction,
                  MAX_INT, "code size overflow");
  f->code[fs->pc] = i;
  /* save corresponding line information */
  luaM_growvector(fs->L, f->lineinfo, fs->pc, f->sizelineinfo, int,
                  MAX_INT, "code size overflow");
  f->lineinfo[fs->pc] = line;
  return fs->pc++;
}


int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {
  lua_assert(getOpMode(o) == iABC);
  return luaK_code(fs, CREATE_ABC(o, a, b, c), fs->ls->lastline);
}


int luaK_codeABx (FuncState *fs, OpCode o, int a, unsigned int bc) {
  lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
  return luaK_code(fs, CREATE_ABx(o, a, bc), fs->ls->lastline);
}

Added lua-5.0.2/src/lcode.h.





















































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: lcode.h,v 1.38 2002/12/11 12:34:22 roberto Exp $
** Code generator for Lua
** See Copyright Notice in lua.h
*/

#ifndef lcode_h
#define lcode_h

#include "llex.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"


/*
** Marks the end of a patch list. It is an invalid value both as an absolute
** address, and as a list link (would link an element to itself).
*/
#define NO_JUMP (-1)


/*
** grep "ORDER OPR" if you change these enums
*/
typedef enum BinOpr {
  OPR_ADD, OPR_SUB, OPR_MULT, OPR_DIV, OPR_POW,
  OPR_CONCAT,
  OPR_NE, OPR_EQ,
  OPR_LT, OPR_LE, OPR_GT, OPR_GE,
  OPR_AND, OPR_OR,
  OPR_NOBINOPR
} BinOpr;

#define binopistest(op)	((op) >= OPR_NE)

typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_NOUNOPR } UnOpr;


#define getcode(fs,e)	((fs)->f->code[(e)->info])

#define luaK_codeAsBx(fs,o,A,sBx)	luaK_codeABx(fs,o,A,(sBx)+MAXARG_sBx)

int luaK_code (FuncState *fs, Instruction i, int line);
int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
void luaK_fixline (FuncState *fs, int line);
void luaK_nil (FuncState *fs, int from, int n);
void luaK_reserveregs (FuncState *fs, int n);
void luaK_checkstack (FuncState *fs, int n);
int luaK_stringK (FuncState *fs, TString *s);
int luaK_numberK (FuncState *fs, lua_Number r);
void luaK_dischargevars (FuncState *fs, expdesc *e);
int luaK_exp2anyreg (FuncState *fs, expdesc *e);
void luaK_exp2nextreg (FuncState *fs, expdesc *e);
void luaK_exp2val (FuncState *fs, expdesc *e);
int luaK_exp2RK (FuncState *fs, expdesc *e);
void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
void luaK_goiftrue (FuncState *fs, expdesc *e);
void luaK_goiffalse (FuncState *fs, expdesc *e);
void luaK_storevar (FuncState *fs, expdesc *var, expdesc *e);
void luaK_setcallreturns (FuncState *fs, expdesc *var, int nresults);
int luaK_jump (FuncState *fs);
void luaK_patchlist (FuncState *fs, int list, int target);
void luaK_patchtohere (FuncState *fs, int list);
void luaK_concat (FuncState *fs, int *l1, int l2);
int luaK_getlabel (FuncState *fs);
void luaK_prefix (FuncState *fs, UnOpr op, expdesc *v);
void luaK_infix (FuncState *fs, BinOpr op, expdesc *v);
void luaK_posfix (FuncState *fs, BinOpr op, expdesc *v1, expdesc *v2);


#endif

Added lua-5.0.2/src/ldebug.c.



















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: ldebug.c,v 1.150 2003/03/19 21:24:04 roberto Exp $
** Debug Interface
** See Copyright Notice in lua.h
*/


#include <stdlib.h>
#include <string.h>

#define ldebug_c

#include "lua.h"

#include "lapi.h"
#include "lcode.h"
#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lvm.h"



static const char *getfuncname (CallInfo *ci, const char **name);


#define isLua(ci)	(!((ci)->state & CI_C))


static int currentpc (CallInfo *ci) {
  if (!isLua(ci)) return -1;  /* function is not a Lua function? */
  if (ci->state & CI_HASFRAME)  /* function has a frame? */
    ci->u.l.savedpc = *ci->u.l.pc;  /* use `pc' from there */
  /* function's pc is saved */
  return pcRel(ci->u.l.savedpc, ci_func(ci)->l.p);
}


static int currentline (CallInfo *ci) {
  int pc = currentpc(ci);
  if (pc < 0)
    return -1;  /* only active lua functions have current-line information */
  else
    return getline(ci_func(ci)->l.p, pc);
}


void luaG_inithooks (lua_State *L) {
  CallInfo *ci;
  for (ci = L->ci; ci != L->base_ci; ci--)  /* update all `savedpc's */
    currentpc(ci);
  L->hookinit = 1;
}


/*
** this function can be called asynchronous (e.g. during a signal)
*/
LUA_API int lua_sethook (lua_State *L, lua_Hook func, int mask, int count) {
  if (func == NULL || mask == 0) {  /* turn off hooks? */
    mask = 0;
    func = NULL;
  }
  L->hook = func;
  L->basehookcount = count;
  resethookcount(L);
  L->hookmask = cast(lu_byte, mask);
  L->hookinit = 0;
  return 1;
}


LUA_API lua_Hook lua_gethook (lua_State *L) {
  return L->hook;
}


LUA_API int lua_gethookmask (lua_State *L) {
  return L->hookmask;
}


LUA_API int lua_gethookcount (lua_State *L) {
  return L->basehookcount;
}


LUA_API int lua_getstack (lua_State *L, int level, lua_Debug *ar) {
  int status;
  CallInfo *ci;
  lua_lock(L);
  for (ci = L->ci; level > 0 && ci > L->base_ci; ci--) {
    level--;
    if (!(ci->state & CI_C))  /* Lua function? */
      level -= ci->u.l.tailcalls;  /* skip lost tail calls */
  }
  if (level > 0 || ci == L->base_ci) status = 0;  /* there is no such level */
  else if (level < 0) {  /* level is of a lost tail call */
    status = 1;
    ar->i_ci = 0;
  }
  else {
    status = 1;
    ar->i_ci = ci - L->base_ci;
  }
  lua_unlock(L);
  return status;
}


static Proto *getluaproto (CallInfo *ci) {
  return (isLua(ci) ? ci_func(ci)->l.p : NULL);
}


LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
  const char *name;
  CallInfo *ci;
  Proto *fp;
  lua_lock(L);
  name = NULL;
  ci = L->base_ci + ar->i_ci;
  fp = getluaproto(ci);
  if (fp) {  /* is a Lua function? */
    name = luaF_getlocalname(fp, n, currentpc(ci));
    if (name)
      luaA_pushobject(L, ci->base+(n-1));  /* push value */
  }
  lua_unlock(L);
  return name;
}


LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
  const char *name;
  CallInfo *ci;
  Proto *fp;
  lua_lock(L);
  name = NULL;
  ci = L->base_ci + ar->i_ci;
  fp = getluaproto(ci);
  L->top--;  /* pop new value */
  if (fp) {  /* is a Lua function? */
    name = luaF_getlocalname(fp, n, currentpc(ci));
    if (!name || name[0] == '(')  /* `(' starts private locals */
      name = NULL;
    else
      setobjs2s(ci->base+(n-1), L->top);
  }
  lua_unlock(L);
  return name;
}


static void funcinfo (lua_Debug *ar, StkId func) {
  Closure *cl = clvalue(func);
  if (cl->c.isC) {
    ar->source = "=[C]";
    ar->linedefined = -1;
    ar->what = "C";
  }
  else {
    ar->source = getstr(cl->l.p->source);
    ar->linedefined = cl->l.p->lineDefined;
    ar->what = (ar->linedefined == 0) ? "main" : "Lua";
  }
  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
}


static const char *travglobals (lua_State *L, const TObject *o) {
  Table *g = hvalue(gt(L));
  int i = sizenode(g);
  while (i--) {
    Node *n = gnode(g, i);
    if (luaO_rawequalObj(o, gval(n)) && ttisstring(gkey(n)))
      return getstr(tsvalue(gkey(n)));
  }
  return NULL;
}


static void info_tailcall (lua_State *L, lua_Debug *ar) {
  ar->name = ar->namewhat = "";
  ar->what = "tail";
  ar->linedefined = ar->currentline = -1;
  ar->source = "=(tail call)";
  luaO_chunkid(ar->short_src, ar->source, LUA_IDSIZE);
  ar->nups = 0;
  setnilvalue(L->top);
}


static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar,
                    StkId f, CallInfo *ci) {
  int status = 1;
  for (; *what; what++) {
    switch (*what) {
      case 'S': {
        funcinfo(ar, f);
        break;
      }
      case 'l': {
        ar->currentline = (ci) ? currentline(ci) : -1;
        break;
      }
      case 'u': {
        ar->nups = clvalue(f)->c.nupvalues;
        break;
      }
      case 'n': {
        ar->namewhat = (ci) ? getfuncname(ci, &ar->name) : NULL;
        if (ar->namewhat == NULL) {
          /* try to find a global name */
          if ((ar->name = travglobals(L, f)) != NULL)
            ar->namewhat = "global";
          else ar->namewhat = "";  /* not found */
        }
        break;
      }
      case 'f': {
        setobj2s(L->top, f);
        break;
      }
      default: status = 0;  /* invalid option */
    }
  }
  return status;
}


LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
  int status = 1;
  lua_lock(L);
  if (*what == '>') {
    StkId f = L->top - 1;
    if (!ttisfunction(f))
      luaG_runerror(L, "value for `lua_getinfo' is not a function");
    status = auxgetinfo(L, what + 1, ar, f, NULL);
    L->top--;  /* pop function */
  }
  else if (ar->i_ci != 0) {  /* no tail call? */
    CallInfo *ci = L->base_ci + ar->i_ci;
    lua_assert(ttisfunction(ci->base - 1));
    status = auxgetinfo(L, what, ar, ci->base - 1, ci);
  }
  else
    info_tailcall(L, ar);
  if (strchr(what, 'f')) incr_top(L);
  lua_unlock(L);
  return status;
}


/*
** {======================================================
** Symbolic Execution and code checker
** =======================================================
*/

#define check(x)		if (!(x)) return 0;

#define checkjump(pt,pc)	check(0 <= pc && pc < pt->sizecode)

#define checkreg(pt,reg)	check((reg) < (pt)->maxstacksize)



static int precheck (const Proto *pt) {
  check(pt->maxstacksize <= MAXSTACK);
  check(pt->sizelineinfo == pt->sizecode || pt->sizelineinfo == 0);
  lua_assert(pt->numparams+pt->is_vararg <= pt->maxstacksize);
  check(GET_OPCODE(pt->code[pt->sizecode-1]) == OP_RETURN);
  return 1;
}


static int checkopenop (const Proto *pt, int pc) {
  Instruction i = pt->code[pc+1];
  switch (GET_OPCODE(i)) {
    case OP_CALL:
    case OP_TAILCALL:
    case OP_RETURN: {
      check(GETARG_B(i) == 0);
      return 1;
    }
    case OP_SETLISTO: return 1;
    default: return 0;  /* invalid instruction after an open call */
  }
}


static int checkRK (const Proto *pt, int r) {
  return (r < pt->maxstacksize || (r >= MAXSTACK && r-MAXSTACK < pt->sizek));
}


static Instruction luaG_symbexec (const Proto *pt, int lastpc, int reg) {
  int pc;
  int last;  /* stores position of last instruction that changed `reg' */
  last = pt->sizecode-1;  /* points to final return (a `neutral' instruction) */
  check(precheck(pt));
  for (pc = 0; pc < lastpc; pc++) {
    const Instruction i = pt->code[pc];
    OpCode op = GET_OPCODE(i);
    int a = GETARG_A(i);
    int b = 0;
    int c = 0;
    checkreg(pt, a);
    switch (getOpMode(op)) {
      case iABC: {
        b = GETARG_B(i);
        c = GETARG_C(i);
        if (testOpMode(op, OpModeBreg)) {
          checkreg(pt, b);
        }
        else if (testOpMode(op, OpModeBrk))
          check(checkRK(pt, b));
        if (testOpMode(op, OpModeCrk))
          check(checkRK(pt, c));
        break;
      }
      case iABx: {
        b = GETARG_Bx(i);
        if (testOpMode(op, OpModeK)) check(b < pt->sizek);
        break;
      }
      case iAsBx: {
        b = GETARG_sBx(i);
        break;
      }
    }
    if (testOpMode(op, OpModesetA)) {
      if (a == reg) last = pc;  /* change register `a' */
    }
    if (testOpMode(op, OpModeT)) {
      check(pc+2 < pt->sizecode);  /* check skip */
      check(GET_OPCODE(pt->code[pc+1]) == OP_JMP);
    }
    switch (op) {
      case OP_LOADBOOL: {
        check(c == 0 || pc+2 < pt->sizecode);  /* check its jump */
        break;
      }
      case OP_LOADNIL: {
        if (a <= reg && reg <= b)
          last = pc;  /* set registers from `a' to `b' */
        break;
      }
      case OP_GETUPVAL:
      case OP_SETUPVAL: {
        check(b < pt->nups);
        break;
      }
      case OP_GETGLOBAL:
      case OP_SETGLOBAL: {
        check(ttisstring(&pt->k[b]));
        break;
      }
      case OP_SELF: {
        checkreg(pt, a+1);
        if (reg == a+1) last = pc;
        break;
      }
      case OP_CONCAT: {
        /* `c' is a register, and at least two operands */
        check(c < MAXSTACK && b < c);
        break;
      }
      case OP_TFORLOOP:
        checkreg(pt, a+c+5);
        if (reg >= a) last = pc;  /* affect all registers above base */
        /* go through */
      case OP_FORLOOP:
        checkreg(pt, a+2);
        /* go through */
      case OP_JMP: {
        int dest = pc+1+b;
	check(0 <= dest && dest < pt->sizecode);
        /* not full check and jump is forward and do not skip `lastpc'? */
        if (reg != NO_REG && pc < dest && dest <= lastpc)
          pc += b;  /* do the jump */
        break;
      }
      case OP_CALL:
      case OP_TAILCALL: {
        if (b != 0) {
          checkreg(pt, a+b-1);
        }
        c--;  /* c = num. returns */
        if (c == LUA_MULTRET) {
          check(checkopenop(pt, pc));
        }
        else if (c != 0)
          checkreg(pt, a+c-1);
        if (reg >= a) last = pc;  /* affect all registers above base */
        break;
      }
      case OP_RETURN: {
        b--;  /* b = num. returns */
        if (b > 0) checkreg(pt, a+b-1);
        break;
      }
      case OP_SETLIST: {
        checkreg(pt, a + (b&(LFIELDS_PER_FLUSH-1)) + 1);
        break;
      }
      case OP_CLOSURE: {
        int nup;
        check(b < pt->sizep);
        nup = pt->p[b]->nups;
        check(pc + nup < pt->sizecode);
        for (; nup>0; nup--) {
          OpCode op1 = GET_OPCODE(pt->code[pc+nup]);
          check(op1 == OP_GETUPVAL || op1 == OP_MOVE);
        }
        break;
      }
      default: break;
    }
  }
  return pt->code[last];
}

#undef check
#undef checkjump
#undef checkreg

/* }====================================================== */


int luaG_checkcode (const Proto *pt) {
  return luaG_symbexec(pt, pt->sizecode, NO_REG);
}


static const char *kname (Proto *p, int c) {
  c = c - MAXSTACK;
  if (c >= 0 && ttisstring(&p->k[c]))
    return svalue(&p->k[c]);
  else
    return "?";
}


static const char *getobjname (CallInfo *ci, int stackpos, const char **name) {
  if (isLua(ci)) {  /* a Lua function? */
    Proto *p = ci_func(ci)->l.p;
    int pc = currentpc(ci);
    Instruction i;
    *name = luaF_getlocalname(p, stackpos+1, pc);
    if (*name)  /* is a local? */
      return "local";
    i = luaG_symbexec(p, pc, stackpos);  /* try symbolic execution */
    lua_assert(pc != -1);
    switch (GET_OPCODE(i)) {
      case OP_GETGLOBAL: {
        int g = GETARG_Bx(i);  /* global index */
        lua_assert(ttisstring(&p->k[g]));
        *name = svalue(&p->k[g]);
        return "global";
      }
      case OP_MOVE: {
        int a = GETARG_A(i);
        int b = GETARG_B(i);  /* move from `b' to `a' */
        if (b < a)
          return getobjname(ci, b, name);  /* get name for `b' */
        break;
      }
      case OP_GETTABLE: {
        int k = GETARG_C(i);  /* key index */
        *name = kname(p, k);
        return "field";
      }
      case OP_SELF: {
        int k = GETARG_C(i);  /* key index */
        *name = kname(p, k);
        return "method";
      }
      default: break;
    }
  }
  return NULL;  /* no useful name found */
}


static const char *getfuncname (CallInfo *ci, const char **name) {
  Instruction i;
  if ((isLua(ci) && ci->u.l.tailcalls > 0) || !isLua(ci - 1))
    return NULL;  /* calling function is not Lua (or is unknown) */
  ci--;  /* calling function */
  i = ci_func(ci)->l.p->code[currentpc(ci)];
  if (GET_OPCODE(i) == OP_CALL || GET_OPCODE(i) == OP_TAILCALL)
    return getobjname(ci, GETARG_A(i), name);
  else
    return NULL;  /* no useful name can be found */
}


/* only ANSI way to check whether a pointer points to an array */
static int isinstack (CallInfo *ci, const TObject *o) {
  StkId p;
  for (p = ci->base; p < ci->top; p++)
    if (o == p) return 1;
  return 0;
}


void luaG_typeerror (lua_State *L, const TObject *o, const char *op) {
  const char *name = NULL;
  const char *t = luaT_typenames[ttype(o)];
  const char *kind = (isinstack(L->ci, o)) ?
                         getobjname(L->ci, o - L->base, &name) : NULL;
  if (kind)
    luaG_runerror(L, "attempt to %s %s `%s' (a %s value)",
                op, kind, name, t);
  else
    luaG_runerror(L, "attempt to %s a %s value", op, t);
}


void luaG_concaterror (lua_State *L, StkId p1, StkId p2) {
  if (ttisstring(p1)) p1 = p2;
  lua_assert(!ttisstring(p1));
  luaG_typeerror(L, p1, "concatenate");
}


void luaG_aritherror (lua_State *L, const TObject *p1, const TObject *p2) {
  TObject temp;
  if (luaV_tonumber(p1, &temp) == NULL)
    p2 = p1;  /* first operand is wrong */
  luaG_typeerror(L, p2, "perform arithmetic on");
}


int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2) {
  const char *t1 = luaT_typenames[ttype(p1)];
  const char *t2 = luaT_typenames[ttype(p2)];
  if (t1[2] == t2[2])
    luaG_runerror(L, "attempt to compare two %s values", t1);
  else
    luaG_runerror(L, "attempt to compare %s with %s", t1, t2);
  return 0;
}


static void addinfo (lua_State *L, const char *msg) {
  CallInfo *ci = L->ci;
  if (isLua(ci)) {  /* is Lua code? */
    char buff[LUA_IDSIZE];  /* add file:line information */
    int line = currentline(ci);
    luaO_chunkid(buff, getstr(getluaproto(ci)->source), LUA_IDSIZE);
    luaO_pushfstring(L, "%s:%d: %s", buff, line, msg);
  }
}


void luaG_errormsg (lua_State *L) {
  if (L->errfunc != 0) {  /* is there an error handling function? */
    StkId errfunc = restorestack(L, L->errfunc);
    if (!ttisfunction(errfunc)) luaD_throw(L, LUA_ERRERR);
    setobjs2s(L->top, L->top - 1);  /* move argument */
    setobjs2s(L->top - 1, errfunc);  /* push function */
    incr_top(L);
    luaD_call(L, L->top - 2, 1);  /* call it */
  }
  luaD_throw(L, LUA_ERRRUN);
}


void luaG_runerror (lua_State *L, const char *fmt, ...) {
  va_list argp;
  va_start(argp, fmt);
  addinfo(L, luaO_pushvfstring(L, fmt, argp));
  va_end(argp);
  luaG_errormsg(L);
}

Added lua-5.0.2/src/ldebug.h.































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: ldebug.h,v 1.32 2002/11/18 11:01:55 roberto Exp $
** Auxiliary functions from Debug Interface module
** See Copyright Notice in lua.h
*/

#ifndef ldebug_h
#define ldebug_h


#include "lstate.h"


#define pcRel(pc, p)	(cast(int, (pc) - (p)->code) - 1)

#define getline(f,pc)	(((f)->lineinfo) ? (f)->lineinfo[pc] : 0)

#define resethookcount(L)	(L->hookcount = L->basehookcount)


void luaG_inithooks (lua_State *L);
void luaG_typeerror (lua_State *L, const TObject *o, const char *opname);
void luaG_concaterror (lua_State *L, StkId p1, StkId p2);
void luaG_aritherror (lua_State *L, const TObject *p1, const TObject *p2);
int luaG_ordererror (lua_State *L, const TObject *p1, const TObject *p2);
void luaG_runerror (lua_State *L, const char *fmt, ...);
void luaG_errormsg (lua_State *L);
int luaG_checkcode (const Proto *pt);


#endif

Added lua-5.0.2/src/ldo.c.















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
/*
** $Id: ldo.c,v 1.217a 2003/04/03 13:35:34 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/


#include <setjmp.h>
#include <stdlib.h>
#include <string.h>

#define ldo_c

#include "lua.h"

#include "ldebug.h"
#include "ldo.h"
#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lopcodes.h"
#include "lparser.h"
#include "lstate.h"
#include "lstring.h"
#include "ltable.h"
#include "ltm.h"
#include "lundump.h"
#include "lvm.h"
#include "lzio.h"




/*
** {======================================================
** Error-recovery functions (based on long jumps)
** =======================================================
*/


/* chain list of long jump buffers */
struct lua_longjmp {
  struct lua_longjmp *previous;
  jmp_buf b;
  volatile int status;  /* error code */
};


static void seterrorobj (lua_State *L, int errcode, StkId oldtop) {
  switch (errcode) {
    case LUA_ERRMEM: {
      setsvalue2s(oldtop, luaS_new(L, MEMERRMSG));
      break;
    }
    case LUA_ERRERR: {
      setsvalue2s(oldtop, luaS_new(L, "error in error handling"));
      break;
    }
    case LUA_ERRSYNTAX:
    case LUA_ERRRUN: {
      setobjs2s(oldtop, L->top - 1);  /* error message on current top */
      break;
    }
  }
  L->top = oldtop + 1;
}


void luaD_throw (lua_State *L, int errcode) {
  if (L->errorJmp) {
    L->errorJmp->status = errcode;
    longjmp(L->errorJmp->b, 1);
  }
  else {
    G(L)->panic(L);
    exit(EXIT_FAILURE);
  }
}


int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) {
  struct lua_longjmp lj;
  lj.status = 0;
  lj.previous = L->errorJmp;  /* chain new error handler */
  L->errorJmp = &lj;
  if (setjmp(lj.b) == 0)
    (*f)(L, ud);
  L->errorJmp = lj.previous;  /* restore old error handler */
  return lj.status;
}


static void restore_stack_limit (lua_State *L) {
  L->stack_last = L->stack+L->stacksize-1;
  if (L->size_ci > LUA_MAXCALLS) {  /* there was an overflow? */
    int inuse = (L->ci - L->base_ci);
    if (inuse + 1 < LUA_MAXCALLS)  /* can `undo' overflow? */
      luaD_reallocCI(L, LUA_MAXCALLS);
  }
}

/* }====================================================== */


static void correctstack (lua_State *L, TObject *oldstack) {
  CallInfo *ci;
  GCObject *up;
  L->top = (L->top - oldstack) + L->stack;
  for (up = L->openupval; up != NULL; up = up->gch.next)
    gcotouv(up)->v = (gcotouv(up)->v - oldstack) + L->stack;
  for (ci = L->base_ci; ci <= L->ci; ci++) {
    ci->top = (ci->top - oldstack) + L->stack;
    ci->base = (ci->base - oldstack) + L->stack;
  }
  L->base = L->ci->base;
}


void luaD_reallocstack (lua_State *L, int newsize) {
  TObject *oldstack = L->stack;
  luaM_reallocvector(L, L->stack, L->stacksize, newsize, TObject);
  L->stacksize = newsize;
  L->stack_last = L->stack+newsize-1-EXTRA_STACK;
  correctstack(L, oldstack);
}


void luaD_reallocCI (lua_State *L, int newsize) {
  CallInfo *oldci = L->base_ci;
  luaM_reallocvector(L, L->base_ci, L->size_ci, newsize, CallInfo);
  L->size_ci = cast(unsigned short, newsize);
  L->ci = (L->ci - oldci) + L->base_ci;
  L->end_ci = L->base_ci + L->size_ci;
}


void luaD_growstack (lua_State *L, int n) {
  if (n <= L->stacksize)  /* double size is enough? */
    luaD_reallocstack(L, 2*L->stacksize);
  else
    luaD_reallocstack(L, L->stacksize + n + EXTRA_STACK);
}


static void luaD_growCI (lua_State *L) {
  if (L->size_ci > LUA_MAXCALLS)  /* overflow while handling overflow? */
    luaD_throw(L, LUA_ERRERR);
  else {
    luaD_reallocCI(L, 2*L->size_ci);
    if (L->size_ci > LUA_MAXCALLS)
      luaG_runerror(L, "stack overflow");
  }
}


void luaD_callhook (lua_State *L, int event, int line) {
  lua_Hook hook = L->hook;
  if (hook && L->allowhook) {
    ptrdiff_t top = savestack(L, L->top);
    ptrdiff_t ci_top = savestack(L, L->ci->top);
    lua_Debug ar;
    ar.event = event;
    ar.currentline = line;
    if (event == LUA_HOOKTAILRET)
      ar.i_ci = 0;  /* tail call; no debug information about it */
    else
      ar.i_ci = L->ci - L->base_ci;
    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */
    L->ci->top = L->top + LUA_MINSTACK;
    L->allowhook = 0;  /* cannot call hooks inside a hook */
    lua_unlock(L);
    (*hook)(L, &ar);
    lua_lock(L);
    lua_assert(!L->allowhook);
    L->allowhook = 1;
    L->ci->top = restorestack(L, ci_top);
    L->top = restorestack(L, top);
  }
}


static void adjust_varargs (lua_State *L, int nfixargs, StkId base) {
  int i;
  Table *htab;
  TObject nname;
  int actual = L->top - base;  /* actual number of arguments */
  if (actual < nfixargs) {
    luaD_checkstack(L, nfixargs - actual);
    for (; actual < nfixargs; ++actual)
      setnilvalue(L->top++);
  }
  actual -= nfixargs;  /* number of extra arguments */
  htab = luaH_new(L, actual, 1);  /* create `arg' table */
  for (i=0; i<actual; i++)  /* put extra arguments into `arg' table */
    setobj2n(luaH_setnum(L, htab, i+1), L->top - actual + i);
  /* store counter in field `n' */
  setsvalue(&nname, luaS_newliteral(L, "n"));
  setnvalue(luaH_set(L, htab, &nname), cast(lua_Number, actual));
  L->top -= actual;  /* remove extra elements from the stack */
  sethvalue(L->top, htab);
  incr_top(L);
}


static StkId tryfuncTM (lua_State *L, StkId func) {
  const TObject *tm = luaT_gettmbyobj(L, func, TM_CALL);
  StkId p;
  ptrdiff_t funcr = savestack(L, func);
  if (!ttisfunction(tm))
    luaG_typeerror(L, func, "call");
  /* Open a hole inside the stack at `func' */
  for (p = L->top; p > func; p--) setobjs2s(p, p-1);
  incr_top(L);
  func = restorestack(L, funcr);  /* previous call may change stack */
  setobj2s(func, tm);  /* tag method is the new function to be called */
  return func;
}


StkId luaD_precall (lua_State *L, StkId func) {
  LClosure *cl;
  ptrdiff_t funcr = savestack(L, func);
  if (!ttisfunction(func)) /* `func' is not a function? */
    func = tryfuncTM(L, func);  /* check the `function' tag method */
  if (L->ci + 1 == L->end_ci) luaD_growCI(L);
  else condhardstacktests(luaD_reallocCI(L, L->size_ci));
  cl = &clvalue(func)->l;
  if (!cl->isC) {  /* Lua function? prepare its call */
    CallInfo *ci;
    Proto *p = cl->p;
    if (p->is_vararg)  /* varargs? */
      adjust_varargs(L, p->numparams, func+1);
    luaD_checkstack(L, p->maxstacksize);
    ci = ++L->ci;  /* now `enter' new function */
    L->base = L->ci->base = restorestack(L, funcr) + 1;
    ci->top = L->base + p->maxstacksize;
    ci->u.l.savedpc = p->code;  /* starting point */
    ci->u.l.tailcalls = 0;
    ci->state = CI_SAVEDPC;
    while (L->top < ci->top)
      setnilvalue(L->top++);
    L->top = ci->top;
    return NULL;
  }
  else {  /* if is a C function, call it */
    CallInfo *ci;
    int n;
    luaD_checkstack(L, LUA_MINSTACK);  /* ensure minimum stack size */
    ci = ++L->ci;  /* now `enter' new function */
    L->base = L->ci->base = restorestack(L, funcr) + 1;
    ci->top = L->top + LUA_MINSTACK;
    ci->state = CI_C;  /* a C function */
    if (L->hookmask & LUA_MASKCALL)
      luaD_callhook(L, LUA_HOOKCALL, -1);
    lua_unlock(L);
#ifdef LUA_COMPATUPVALUES
    lua_pushupvalues(L);
#endif
    n = (*clvalue(L->base - 1)->c.f)(L);  /* do the actual call */
    lua_lock(L);
    return L->top - n;
  }
}


static StkId callrethooks (lua_State *L, StkId firstResult) {
  ptrdiff_t fr = savestack(L, firstResult);  /* next call may change stack */
  luaD_callhook(L, LUA_HOOKRET, -1);
  if (!(L->ci->state & CI_C)) {  /* Lua function? */
    while (L->ci->u.l.tailcalls--)  /* call hook for eventual tail calls */
      luaD_callhook(L, LUA_HOOKTAILRET, -1);
  }
  return restorestack(L, fr);
}


void luaD_poscall (lua_State *L, int wanted, StkId firstResult) { 
  StkId res;
  if (L->hookmask & LUA_MASKRET)
    firstResult = callrethooks(L, firstResult);
  res = L->base - 1;  /* res == final position of 1st result */
  L->ci--;
  L->base = L->ci->base;  /* restore base */
  /* move results to correct place */
  while (wanted != 0 && firstResult < L->top) {
    setobjs2s(res++, firstResult++);
    wanted--;
  }
  while (wanted-- > 0)
    setnilvalue(res++);
  L->top = res;
}


/*
** Call a function (C or Lua). The function to be called is at *func.
** The arguments are on the stack, right after the function.
** When returns, all the results are on the stack, starting at the original
** function position.
*/ 
void luaD_call (lua_State *L, StkId func, int nResults) {
  StkId firstResult;
  lua_assert(!(L->ci->state & CI_CALLING));
  if (++L->nCcalls >= LUA_MAXCCALLS) {
    if (L->nCcalls == LUA_MAXCCALLS)
      luaG_runerror(L, "C stack overflow");
    else if (L->nCcalls >= (LUA_MAXCCALLS + (LUA_MAXCCALLS>>3)))
      luaD_throw(L, LUA_ERRERR);  /* error while handing stack error */
  }
  firstResult = luaD_precall(L, func);
  if (firstResult == NULL)  /* is a Lua function? */
    firstResult = luaV_execute(L);  /* call it */
  luaD_poscall(L, nResults, firstResult);
  L->nCcalls--;
  luaC_checkGC(L);
}


static void resume (lua_State *L, void *ud) {
  StkId firstResult;
  int nargs = *cast(int *, ud);
  CallInfo *ci = L->ci;
  if (ci == L->base_ci) {  /* no activation record? */
    lua_assert(nargs < L->top - L->base);
    luaD_precall(L, L->top - (nargs + 1));  /* start coroutine */
  }
  else {  /* inside a yield */
    lua_assert(ci->state & CI_YIELD);
    if (ci->state & CI_C) {  /* `common' yield? */
      /* finish interrupted execution of `OP_CALL' */
      int nresults;
      lua_assert((ci-1)->state & CI_SAVEDPC);
      lua_assert(GET_OPCODE(*((ci-1)->u.l.savedpc - 1)) == OP_CALL ||
                 GET_OPCODE(*((ci-1)->u.l.savedpc - 1)) == OP_TAILCALL);
      nresults = GETARG_C(*((ci-1)->u.l.savedpc - 1)) - 1;
      luaD_poscall(L, nresults, L->top - nargs);  /* complete it */
      if (nresults >= 0) L->top = L->ci->top;
    }
    else {  /* yielded inside a hook: just continue its execution */
      ci->state &= ~CI_YIELD;
    }
  }
  firstResult = luaV_execute(L);
  if (firstResult != NULL)   /* return? */
    luaD_poscall(L, LUA_MULTRET, firstResult);  /* finalize this coroutine */
}


static int resume_error (lua_State *L, const char *msg) {
  L->top = L->ci->base;
  setsvalue2s(L->top, luaS_new(L, msg));
  incr_top(L);
  lua_unlock(L);
  return LUA_ERRRUN;
}


LUA_API int lua_resume (lua_State *L, int nargs) {
  int status;
  lu_byte old_allowhooks;
  lua_lock(L);
  if (L->ci == L->base_ci) {
    if (nargs >= L->top - L->base)
      return resume_error(L, "cannot resume dead coroutine");
  }
  else if (!(L->ci->state & CI_YIELD))  /* not inside a yield? */
    return resume_error(L, "cannot resume non-suspended coroutine");
  old_allowhooks = L->allowhook;
  lua_assert(L->errfunc == 0 && L->nCcalls == 0);
  status = luaD_rawrunprotected(L, resume, &nargs);
  if (status != 0) {  /* error? */
    L->ci = L->base_ci;  /* go back to initial level */