Check-in [1c4bcabb30]

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

Overview
Comment:Initial Checkin
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:1c4bcabb3090d5724ce116fb2d3c7c3829ec75e9
User & Date: jim 2011-12-20 23:23:59
Context
2012-01-23
09:42
Buildable version check-in: 08e112a8b0 user: jim tags: trunk
2011-12-20
23:23
Initial Checkin check-in: 1c4bcabb30 user: jim tags: trunk
23:23
initial empty check-in check-in: bedb57848a user: jim tags: trunk
Changes

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
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
/*
 *  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
 *		19-Aug-2006	JS	Add connect routine & rename creates
 *		21-Aug-2006	JS	Fix connect routine to put active socket in
 *						to_socket
 */

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

static NETCOM_CHANNEL *base = NULL;

/****************************************************************************************
*
*  NETCOM_CHANNEL *netcom_netcreate_listen(  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_listen( 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_netcreate_connnect(  int port,char *ip )
*
*	INPUT:	port	- Port number to use
*			ip		- Attach to this address (NOTE NOT NULL)
*
*	OUTPUT:	Pointer to open channel bound to port
*			NULL if we cannot create it
*
*   NOTE: The channel is opened OUT to an external IP
*
*******************************************************************************************/

NETCOM_CHANNEL *netcom_netcreate_connect( 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;
	inet_aton( ip,(struct in_addr *)&(ch->addr.sin_addr.s_addr));
	ch->addr.sin_port = htons(port);
	
	// (2) Create the connecting 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) Attach to the endpoint

	val = connect(ch->socket,
				(const struct sockaddr *)&(ch->addr),
				sizeof(struct sockaddr_in));
				
	if( val < 0 )
	{
		close( ch->socket );		// Delete unused socket
		MEMFREE( ch );
		return( NULL );
	}
		
	// All done, mark this and attach to list
	
	ch->valid = NETCOM_VALID;
	ch->type = NETCOM_TCP;
	ch->state = NETCOM_READY;
	ch->duplicate = FALSE;
	ch->to_socket = ch->socket;		// Add this socket for I/O
									// since all the I/O code uses this
									// as the I/O channel
	
	
	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;
	
	// (0) Quit if bad channel
	
	if( net == NULL  )
		return;
	
	// (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;
	
	if( net == NULL )
		return( FALSE );		// Bail if bad net
		
	// (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;
	
	if( net != NULL )
	{
		
		// 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 = 0;
	
	if( net != NULL )
		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 = 0;
	
	if( net != NULL )
		count = write(net->to_socket,buf,len);
	return( count );
}


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
/*
 *  netcom.h
 *  TULIP
 *
 *  Created by Jim on Sat Oct 12 2002.
 *  Copyright (c) 2002 Pandora Products. All rights reserved.
 *
 *		19-Aug-2006	JS	Add connect routine & rename creates
 */
 
 #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_listen( int port,char *ip );
NETCOM_CHANNEL *netcom_netcreate_connect( 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);
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/NULMODEM.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
#LyX 1.4.0 created this file. For more info see http://www.lyx.org/
\lyxformat 245
\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
\language english
\inputencoding auto
\fontscheme pslatex
\graphics default
\paperfontsize 11
\spacing single
\papersize letterpaper
\use_geometry false
\use_amsmath 1
\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 true
\end_header

\begin_body

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Standard


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

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Standard


\backslash
renewcommand{
\backslash
reportTopic}{nulmodem TCP/IP Link}
\end_layout

\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Standard


\backslash
renewcommand{
\backslash
revisionNumber}{0.2}
\end_layout

\end_inset


\end_layout

\begin_layout Title
Pandora Products Manual
\begin_inset ERT
status collapsed

\begin_layout Standard


\backslash

\backslash
 
\backslash
reportTopic
\end_layout

\end_inset


\end_layout

\begin_layout Author
Jim Schimpf
\end_layout

\begin_layout Date
21 August 2006
\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Standard


\backslash
thispagestyle{empty}
\end_layout

\end_inset


\end_layout

\begin_layout Standard

\newpage

\begin_inset ERT
status collapsed

\begin_layout Standard


\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

\newpage

\end_layout

\begin_layout Section*
Document Revision History
\end_layout

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

\begin_layout Standard
Version
\end_layout

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

\begin_layout Standard
Author
\end_layout

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

\begin_layout Standard
Description
\end_layout

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

\begin_layout Standard
Date
\end_layout

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

\begin_layout Standard
0.1
\end_layout

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

\begin_layout Standard
js
\end_layout

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

\begin_layout Standard
Initial Version
\end_layout

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

\begin_layout Standard
21-Aug-2006
\end_layout

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

\begin_layout Standard
0.2
\end_layout

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

\begin_layout Standard
js
\end_layout

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

\begin_layout Standard
Editing update
\end_layout

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

\begin_layout Standard
24-Oct-2006
\end_layout

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

\end_inset


\end_layout

\begin_layout Standard

\newpage

\begin_inset LatexCommand \tableofcontents{}

\end_inset


\end_layout

\begin_layout Section
Introduction
\end_layout

\begin_layout Standard

\series bold
nulmodem
\series default
 is designed to act like the hardware NUL modem used in RS-232 work to link
 two connectors of the same sex together.
 When you have two RS-232 ports that are both say male you have to have
 a female-female adapter but in additon you usually have to swap pins 2
 and 3 so the transmit of one unit is connected to the receive of the other.
 
\series bold
nulmodem
\series default
 is designed to do a similar function for TCP/IP connections.
 
\end_layout

\begin_layout Standard
For TCP/IP connections you have some programs like 
\series bold
telnet
\series default
 where they link out to an address.
 If you want to have two telnet programs talk to each other you cannot do
 it directly.
 There must be something between them that would accept connections from
 each program than cross connect the transmit data from one side to the
 receive of the other.
\end_layout

\begin_layout Standard

\series bold
nulmodem
\series default
 has a number of modes where it can do the following:
\end_layout

\begin_layout Itemize
Accept connection on both ports.
\end_layout

\begin_layout Itemize
Make an outbound connection on one port and accept connections on the other.
\end_layout

\begin_layout Itemize
Make outbound connections from both ports.
\end_layout

\begin_layout Itemize
Accept a connection on a single port and echo received data back to the
 sender.
\end_layout

\begin_layout Standard
In additon 
\series bold
nulmodem
\series default
 can be scripted using a Lua5
\begin_inset LatexCommand \cite{Lua5,LuaBook}

\end_inset

 script.
 The Lua script will have functions with defined names (see 
\begin_inset LatexCommand \ref{SCRIPT_USE}

\end_inset

) and these functions will be called by events in 
\series bold
nulmodem
\series default
.
 
\end_layout

\begin_layout Section
Syntax
\end_layout

\begin_layout LyX-Code

\size small
nulmodem [-p0 <port #>][-ip0 <IP address>]
\end_layout

\begin_layout LyX-Code

\size small
         [-p1 <port #>][-ip1 <IP address>]
\end_layout

\begin_layout LyX-Code

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

\begin_layout LyX-Code
        [-loop][-log]
\end_layout

\begin_layout LyX-Code

\size small
         [-v]
\end_layout

\begin_layout LyX-Code

\end_layout

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

\begin_layout Standard
Flag
\end_layout

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

\begin_layout Standard
Field
\end_layout

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

\begin_layout Standard
Use
\end_layout

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

\begin_layout Standard
-p0
\end_layout

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

\begin_layout Standard
TCP Port
\end_layout

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

\begin_layout Standard
Port used by channel 0
\end_layout

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

\begin_layout Standard
-ip0
\end_layout

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

\begin_layout Standard
TCP Address
\end_layout

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

\begin_layout Standard
Addess used by channel 0
\end_layout

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

\begin_layout Standard
-p1
\end_layout

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

\begin_layout Standard
TCP Port
\end_layout

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

\begin_layout Standard
Port used by channel 1
\end_layout

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

\begin_layout Standard
-ip1
\end_layout

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

\begin_layout Standard
TCP Address
\end_layout

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

\begin_layout Standard
Address used by channel 1
\end_layout

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

\begin_layout Standard
-loop
\end_layout

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

\begin_layout Standard
NONE
\end_layout

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

\begin_layout Standard
Enables loop back
\end_layout

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

\begin_layout Standard
-log
\end_layout

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

\begin_layout Standard
NONE
\end_layout

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

\begin_layout Standard
Enable logging
\end_layout

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

\begin_layout Standard
-v
\end_layout

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

\begin_layout Standard
NONE
\end_layout

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

\begin_layout Standard
Show syntax - don't run
\end_layout

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

\end_inset


\end_layout

\begin_layout Standard
The program has two channels (0 and 1) and the command line options specify
 how each of these channels will connect.
 If only the port is specified for a channel then it is a server and will
 wait for a connection to it.
 If both port and IP address are given for a channel it will attempt to
 connect to this address.
 
\end_layout

\begin_layout Subsection
Option Details
\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-p0}

\end_inset

-p0 <TCP Port> 
\end_layout

\begin_layout Standard
This sets the port used by channel 0 and can be any number between 1 and
 65535.
 If given alone without an -ip0 flag then 
\series bold
nulmodem
\series default
 will wait for a connection on this port.
 In this case use of ports below 1024 will require admin priviledges.
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = NONE
\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-ip0}

\end_inset

-ip0 <IP Address> 
\end_layout

\begin_layout Standard
This is the IP address used for channel 0.
 If given along with a port value (-p0) then 
\series bold
nulmodem
\series default
 will attempt to connect to this address (the program will shutdown if it
 cannot).
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = NONE
\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-p1}

\end_inset

-p1 <TCP Port> 
\end_layout

\begin_layout Standard
This sets the port used by channel 1 and can be any number between 1 and
 65535.
 If given alone without an -ip0 flag then 
\series bold
nulmodem
\series default
 will wait for a connection on this port.
 In this case use of ports below 1024 will require admin priviledges.
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = NONE
\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-ip1}

\end_inset

-ip1 <IP Address> 
\end_layout

\begin_layout Standard
This is the IP address used for channel 1.
 If given along with a port value (-p1) then 
\series bold
nulmodem
\series default
 will attempt to connect to this address (the program will shutdown if it
 cannot).
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = NONE
\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-loop}

\end_inset

-loop
\end_layout

\begin_layout Standard
When present this will tell 
\series bold
nulmodem
\series default
 to loop the transmit data from channel 0 back to the receive data.
 Thus you only need to set up channel 0 and any data input will be echoed
 back to the output.
 Useful for testing applications.
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = NO LOOP
\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-log}

\end_inset

-log
\end_layout

\begin_layout Standard
When present will tell 
\series bold
nulmodem
\series default
 to put all data from either channel to stdout.
 Useful to monitor data flow
\end_layout

\begin_layout Standard

\series bold
DEFAULT
\series default
 = NO LOG
\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-c}

\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 LatexCommand \ref{SCRIPT_USE}

\end_inset


\end_layout

\begin_layout Subsubsection
\begin_inset LatexCommand \index{-v}

\end_inset

-v 
\end_layout

\begin_layout Standard
When present 
\series bold
nulmodem
\series default
 will print the following and NOT run
\end_layout

\begin_layout LyX-Code
nulmodem TCP/IP <=> TCP/IP Connect [Aug 21 2006 14:16:28]
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code
nulmodem - TCP/IP 0 <-> TCP/IP 1 Version Aug 21 2006 14:16:28
\end_layout

\begin_layout LyX-Code
SYNTAX: nulmodem[-p0 <TCP/IP Port 0>]
\end_layout

\begin_layout LyX-Code
               [-tcp0 <TCP/IP Port 0>]
\end_layout

\begin_layout LyX-Code
               [-p1 <TCP/IP Port 1>]
\end_layout

\begin_layout LyX-Code
               [-tcp1 <TCP/IP Port 1>]
\end_layout

\begin_layout LyX-Code
               [-c <Lua connect Script>]
\end_layout

\begin_layout LyX-Code
               [-loop]
\end_layout

\begin_layout LyX-Code
               [-log]
\end_layout

\begin_layout LyX-Code
               [-v]
\end_layout

\begin_layout LyX-Code
    -p0    <TCP/IP Port 0> DEFAULT = NONE
\end_layout

\begin_layout LyX-Code
    -tcp0  <TCP/IP Port 0> DEFAULT = NONE (connect)
\end_layout

\begin_layout LyX-Code
    -p1    <TCP/IP Port 1> DEFAULT = NONE
\end_layout

\begin_layout LyX-Code
    -tcp1  <TCP/IP Port 1> DEFAULT = NONE (connect)
\end_layout

\begin_layout LyX-Code
    -c     <Lua script>    DEFAULT = NONE
\end_layout

\begin_layout LyX-Code
    -loop  Loop back on 0  DEFAULT = OFF
\end_layout

\begin_layout LyX-Code
    -log   Log to stdout   DEFAULT = OFF
\end_layout

\begin_layout LyX-Code
    -c <Lua Script>        DEFAULT = NONE
\end_layout

\begin_layout LyX-Code
    -v     Show this message and return
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout Section
nulmodem Use
\end_layout

\begin_layout Subsection
Introduction
\end_layout

\begin_layout Standard

\series bold
nulmodem
\series default
 is used to connect to TCP/IP connections together.
 For example if you wish to connect two telnet sessions together so that
 what is typed one appears on the other.
 This is not possible directly since telnet is a client and connects out.
 But if you set up 
\series bold
nulmodem
\series default
 to be a server on both sides then you just connect to both sides with the
 two telnets.
 Thus
\end_layout

\begin_layout LyX-Code
nulmodem -po 7000 -p1 7010
\end_layout

\begin_layout Standard
Now the two telnet sessions would:
\end_layout

\begin_layout LyX-Code
telnet localhost 7000   -- To connect in on channel 0
\end_layout

\begin_layout Standard
the second session would be:
\end_layout

\begin_layout LyX-Code
telnet localhost 7010   -- To connect in on channel 1
\end_layout

\begin_layout Subsection
Use cases
\end_layout

\begin_layout Subsubsection
Connecting two clients
\end_layout

\begin_layout Standard
This would be similar to connecting the two telnet sessions shown in the
 introduction
\end_layout

\begin_layout Subsubsection
Connecting two servers
\end_layout

\begin_layout Standard
In this case you would set both channel 0 and channel 1 to connect to each
 server then either they would talk to each other or you would use a Lua
 script to control communication.
\end_layout

\begin_layout LyX-Code
nulmodem -ip <server 0> -p0 7000 -ip1 <server 1> -p1 7010
\end_layout

\begin_layout Subsubsection
Connecting a server and client
\end_layout

\begin_layout Standard
Technically this isn't necessary since they could connect themselves but
 if you want to use logging or a lua script it might be useful.
 So if the client is on channel 0 and the server is on channel 1 you get:
\end_layout

\begin_layout LyX-Code
nulmodem -p0 7000 -ip1 <server 1> -p1 7010
\end_layout

\begin_layout Section
\begin_inset LatexCommand \label{SCRIPT_USE}

\end_inset

Lua Script Use
\end_layout

\begin_layout Subsection
Scripting
\end_layout

\begin_layout Standard
Information on the Lua language can be found here: 
\begin_inset LatexCommand \htmlurl[Lua language site]{www.Lua.org}

\end_inset

 and this book 
\begin_inset LatexCommand \cite{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 LatexCommand \ref{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_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 LatexCommand \label{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 LatexCommand \index{timer.topen()}

\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" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0sp">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
-
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
t
\end_layout

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

\begin_layout Standard
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 LatexCommand \index{timer.tclose()}

\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" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0sp">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
t
\end_layout

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

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

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
NONE
\end_layout

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

\begin_layout Standard

\end_layout

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

\end_inset


\end_layout

\begin_layout Subsubsection
Restart a timer timer.tstart(t)
\begin_inset LatexCommand \index{timer.topen()}

\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" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0sp">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
t
\end_layout

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

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

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
NONE
\end_layout

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

\begin_layout Standard

\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 LatexCommand \index{timer.tdone()}

\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" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0sp">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
t
\end_layout

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

\begin_layout Standard
This is the handle of a timer 
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
delay
\end_layout

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

\begin_layout Standard
Delay time in ms
\end_layout

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
done
\end_layout

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

\begin_layout Standard
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
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[0/1](data)
\begin_inset LatexCommand \index{net.swrite()}

\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.swrite0(data) -- for channel 0
\end_layout

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

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
data
\end_layout

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

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

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
count
\end_layout

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

\begin_layout Standard
# 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[0/1](len)
\begin_inset LatexCommand \index{net.sread()}

\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.sread0(len)  -- For channel 0
\end_layout

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

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
len
\end_layout

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

\begin_layout Standard
# Bytes of data to read
\end_layout

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
data
\end_layout

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

\begin_layout Standard
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 LatexCommand \index{net.drop()}

\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" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0sp">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
-
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
NONE
\end_layout

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

\begin_layout Standard

\end_layout

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

\end_inset


\end_layout

\begin_layout Subsubsection
Read TCP/IP connection status net.cstat()
\begin_inset LatexCommand \index{ser.cstat()}

\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" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" width="0sp">
<column alignment="center" valignment="top" leftline="true" rightline="true" width="0sp">
<row topline="true" bottomline="true">
<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
\begin_inset Text

\begin_layout Standard

\series bold
INPUT
\end_layout

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

\begin_layout Standard

\series bold
NAME
\end_layout

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

\begin_layout Standard

\series bold
USE
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard
-
\end_layout

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

\begin_layout Standard

\end_layout

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

\begin_layout Standard

\series bold
OUTPUT
\end_layout

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

\begin_layout Standard
status
\end_layout

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

\begin_layout Standard
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 
\series bold
nulmodem
\series default
 Lua functions.
 It will show a message on start 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 nulmodem 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("**** nulmodem 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 will put out message to Channel 0 & 1
\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.swrite0(out)
\end_layout

\begin_layout LyX-Code

\size footnotesize
   net.swrite1(out)
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\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
--          
\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
end
\end_layout

\begin_layout LyX-Code

\end_layout

\begin_layout LyX-Code

\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 LatexCommand \printindex{}

\end_inset


\end_layout

\begin_layout Standard
\begin_inset LatexCommand \bibtex[bibtotoc,ieeetr]{/Users/jschimpf/Public/TSANIXII/DOCS/tg}

\end_inset


\end_layout

\end_body
\end_document

Added DOCS/NULMODEM.pdf.

cannot compute difference between binary files

Added NULMODEM.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
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
<?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>3873945B0A971C6300545E38</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>387393B80A9716ED00545E38</string>
								<string>387393B30A9716ED00545E38</string>
								<string>387394640A971C7300545E38</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, 552}}</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, 570}}</string>
						<key>GroupTreeTableConfiguration</key>
						<array>
							<string>MainColumn</string>
							<real>186</real>
						</array>
						<key>RubberWindowFrame</key>
						<string>-939 98 712 611 -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>MyNewFile14.java</string>
								<key>PBXSplitModuleInNavigatorKey</key>
								<dict>
									<key>Split0</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1CE0B20406471E060097A5F4</string>
										<key>PBXProjectModuleLabel</key>
										<string>MyNewFile14.java</string>
									</dict>
									<key>SplitCount</key>
									<string>1</string>
								</dict>
								<key>StatusBarVisibility</key>
								<true/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {504, 0}}</string>
								<key>RubberWindowFrame</key>
								<string>-939 98 712 611 -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}, {504, 565}}</string>
								<key>RubberWindowFrame</key>
								<string>-939 98 712 611 -1280 -256 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>XCDetailModule</string>
							<key>Proportion</key>
							<string>565pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>504pt</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>38DFAE980CC7FC5600A5E164</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>38DFAE990CC7FC5600A5E164</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>214432669.82478601</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>/Users/jschimpf/Public/TSANIXII/TOOLS/NULMODEM/NULMODEM.xcodeproj</string>
	</array>
	<key>WindowString</key>
	<string>-939 98 712 611 -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}, {753, 173}}</string>
								<key>RubberWindowFrame</key>
								<string>66 109 753 455 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>173pt</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, 178}, {753, 236}}</string>
								<key>RubberWindowFrame</key>
								<string>66 109 753 455 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>PBXBuildResultsModule</string>
							<key>Proportion</key>
							<string>236pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>414pt</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>387394180A9717DA00545E38</string>
				<string>38016DAC0A9A458000D2F81E</string>
				<string>1CD0528F0623707200166675</string>
				<string>XCMainBuildResultsModuleGUID</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.build</string>
			<key>WindowString</key>
			<string>66 109 753 455 0 0 1024 746 </string>
			<key>WindowToolGUID</key>
			<string>387394180A9717DA00545E38</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}, {352, 289}}</string>
											<string>{{352, 0}, {446, 289}}</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}, {798, 289}}</string>
											<string>{{0, 289}, {798, 261}}</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>{{179, 426}, {500, 300}}</string>
								<key>Frame</key>
								<string>{{0, 0}, {798, 550}}</string>
								<key>RubberWindowFrame</key>
								<string>-1037 249 798 591 -1280 -155 1280 1024 </string>
							</dict>
							<key>Module</key>
							<string>PBXDebugSessionModule</string>
							<key>Proportion</key>
							<string>550pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>550pt</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>38016CFF0A9A268900D2F81E</string>
				<string>1C162984064C10D400B95A72</string>
				<string>38016D000A9A268900D2F81E</string>
				<string>38016D010A9A268900D2F81E</string>
				<string>38016D020A9A268900D2F81E</string>
				<string>38016D030A9A268900D2F81E</string>
				<string>38016D040A9A268900D2F81E</string>
				<string>38016D050A9A268900D2F81E</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.debug</string>
			<key>WindowString</key>
			<string>-1037 249 798 591 -1280 -155 1280 1024 </string>
			<key>WindowToolGUID</key>
			<string>1CD10A99069EF8BA00B06720</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</dict>
		<dict>
			<key>Identifier</key>
			<string>windowTool.find</string>
			<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>PBXSplitModuleInNavigatorKey</key>
										<dict>
											<key>Split0</key>
											<dict>
												<key>PBXProjectModuleGUID</key>
												<string>1CD0528D0623707200166675</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}, {781, 167}}</string>
										<key>RubberWindowFrame</key>
										<string>62 385 781 470 0 0 1440 878 </string>
									</dict>
									<key>Module</key>
									<string>PBXNavigatorGroup</string>
									<key>Proportion</key>
									<string>781pt</string>
								</dict>
							</array>
							<key>Proportion</key>
							<string>50%</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<integer>1</integer>
							<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>{{8, 0}, {773, 254}}</string>
								<key>RubberWindowFrame</key>
								<string>62 385 781 470 0 0 1440 878 </string>
							</dict>
							<key>Module</key>
							<string>PBXProjectFindModule</string>
							<key>Proportion</key>
							<string>50%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>428pt</string>
				</dict>
			</array>
			<key>Name</key>
			<string>Project Find</string>
			<key>ServiceClasses</key>
			<array>
				<string>PBXProjectFindModule</string>
			</array>
			<key>StatusbarIsVisible</key>
			<integer>1</integer>
			<key>TableOfContents</key>
			<array>
				<string>1C530D57069F1CE1000CFCEE</string>
				<string>1C530D58069F1CE1000CFCEE</string>
				<string>1C530D59069F1CE1000CFCEE</string>
				<string>1CDD528C0622207200134675</string>
				<string>1C530D5A069F1CE1000CFCEE</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>1CD0528E0623707200166675</string>
			</array>
			<key>WindowString</key>
			<string>62 385 781 470 0 0 1440 878 </string>
			<key>WindowToolGUID</key>
			<string>1C530D57069F1CE1000CFCEE</string>
			<key>WindowToolIsVisible</key>
			<integer>0</integer>
		</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}, {588, 359}}</string>
								<key>RubberWindowFrame</key>
								<string>22 328 588 400 0 0 1024 746 </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>3873948F0A9720A700545E38</string>
				<string>38016D060A9A268900D2F81E</string>
				<string>1C78EAAC065D492600B07095</string>
			</array>
			<key>WindowString</key>
			<string>22 328 588 400 0 0 1024 746 </string>
			<key>WindowToolGUID</key>
			<string>3873948F0A9720A700545E38</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>BecomeActive</key>
							<true/>
							<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>71 298 744 409 0 0 1024 746 </string>
							</dict>
							<key>Module</key>
							<string>PBXSmartGroupTreeModule</string>
							<key>Proportion</key>
							<string>185pt</string>
						</dict>
						<dict>
							<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>71 298 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>38016D1B0A9A28DD00D2F81E</string>
				<string>38016D1C0A9A28DD00D2F81E</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>1CA1AED706398EBD00589147</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.breakpoints</string>
			<key>WindowString</key>
			<string>71 298 744 409 0 0 1024 746 </string>
			<key>WindowToolGUID</key>
			<string>38016D1B0A9A28DD00D2F81E</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 NULMODEM.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
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
<?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>3849D9EC1042E11A00376E6F</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>387393B80A9716ED00545E38</string>
								<string>387393760A9716ED00545E38</string>
								<string>387393770A9716ED00545E38</string>
								<string>387394640A971C7300545E38</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, 552}}</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, 570}}</string>
						<key>GroupTreeTableConfiguration</key>
						<array>
							<string>MainColumn</string>
							<real>186</real>
						</array>
						<key>RubberWindowFrame</key>
						<string>64 140 712 611 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>MyNewFile14.java</string>
								<key>PBXSplitModuleInNavigatorKey</key>
								<dict>
									<key>Split0</key>
									<dict>
										<key>PBXProjectModuleGUID</key>
										<string>1CE0B20406471E060097A5F4</string>
										<key>PBXProjectModuleLabel</key>
										<string>MyNewFile14.java</string>
									</dict>
									<key>SplitCount</key>
									<string>1</string>
								</dict>
								<key>StatusBarVisibility</key>
								<true/>
							</dict>
							<key>GeometryConfiguration</key>
							<dict>
								<key>Frame</key>
								<string>{{0, 0}, {504, 0}}</string>
								<key>RubberWindowFrame</key>
								<string>64 140 712 611 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}, {504, 565}}</string>
								<key>RubberWindowFrame</key>
								<string>64 140 712 611 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>XCDetailModule</string>
							<key>Proportion</key>
							<string>565pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>504pt</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>387A5F1A13BA5EA3005164DF</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>387A5F1B13BA5EA3005164DF</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>330981027.84825999</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>1CD10A99069EF8BA00B06720</string>
		<string>3849D9E81042E11700376E6F</string>
		<string>/Users/jschimpf/Public/TOOLS/NULMODEM/NULMODEM.xcodeproj</string>
	</array>
	<key>WindowString</key>
	<string>64 140 712 611 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}, {753, 173}}</string>
								<key>RubberWindowFrame</key>
								<string>128 165 753 455 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXNavigatorGroup</string>
							<key>Proportion</key>
							<string>173pt</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, 178}, {753, 236}}</string>
								<key>RubberWindowFrame</key>
								<string>128 165 753 455 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXBuildResultsModule</string>
							<key>Proportion</key>
							<string>236pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>414pt</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>3849D9E81042E11700376E6F</string>
				<string>387A5F1513BA5E96005164DF</string>
				<string>1CD0528F0623707200166675</string>
				<string>XCMainBuildResultsModuleGUID</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.buildV3</string>
			<key>WindowString</key>
			<string>128 165 753 455 0 0 1280 778 </string>
			<key>WindowToolGUID</key>
			<string>3849D9E81042E11700376E6F</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}, {353, 291}}</string>
											<string>{{353, 0}, {445, 291}}</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}, {798, 291}}</string>
											<string>{{0, 291}, {798, 259}}</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>{{179, 426}, {500, 300}}</string>
								<key>Frame</key>
								<string>{{0, 0}, {798, 550}}</string>
								<key>PBXDebugSessionStackFrameViewKey</key>
								<dict>
									<key>DebugVariablesTableConfiguration</key>
									<array>
										<string>Name</string>
										<real>169</real>
										<string>Value</string>
										<real>169</real>
										<string>Summary</string>
										<real>82</real>
									</array>
									<key>Frame</key>
									<string>{{353, 0}, {445, 291}}</string>
									<key>RubberWindowFrame</key>
									<string>243 177 798 591 0 0 1280 778 </string>
								</dict>
								<key>RubberWindowFrame</key>
								<string>243 177 798 591 0 0 1280 778 </string>
							</dict>
							<key>Module</key>
							<string>PBXDebugSessionModule</string>
							<key>Proportion</key>
							<string>550pt</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>550pt</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>387A5F1C13BA5EA3005164DF</string>
				<string>1C162984064C10D400B95A72</string>
				<string>387A5F1D13BA5EA3005164DF</string>
				<string>387A5F1E13BA5EA3005164DF</string>
				<string>387A5F1F13BA5EA3005164DF</string>
				<string>387A5F2013BA5EA3005164DF</string>
				<string>387A5F2113BA5EA3005164DF</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.debugV3</string>
			<key>WindowString</key>
			<string>243 177 798 591 0 0 1280 778 </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>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>PBXSplitModuleInNavigatorKey</key>
										<dict>
											<key>Split0</key>
											<dict>
												<key>PBXProjectModuleGUID</key>
												<string>1CD0528D0623707200166675</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}, {781, 167}}</string>
										<key>RubberWindowFrame</key>
										<string>62 385 781 470 0 0 1440 878 </string>
									</dict>
									<key>Module</key>
									<string>PBXNavigatorGroup</string>
									<key>Proportion</key>
									<string>781pt</string>
								</dict>
							</array>
							<key>Proportion</key>
							<string>50%</string>
						</dict>
						<dict>
							<key>BecomeActive</key>
							<integer>1</integer>
							<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>{{8, 0}, {773, 254}}</string>
								<key>RubberWindowFrame</key>
								<string>62 385 781 470 0 0 1440 878 </string>
							</dict>
							<key>Module</key>
							<string>PBXProjectFindModule</string>
							<key>Proportion</key>
							<string>50%</string>
						</dict>
					</array>
					<key>Proportion</key>
					<string>428pt</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>1C530D58069F1CE1000CFCEE</string>
				<string>1C530D59069F1CE1000CFCEE</string>
				<string>1CDD528C0622207200134675</string>
				<string>1C530D5A069F1CE1000CFCEE</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>1CD0528E0623707200166675</string>
			</array>
			<key>WindowString</key>
			<string>62 385 781 470 0 0 1440 878 </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}, {588, 359}}</string>
								<key>RubberWindowFrame</key>
								<string>35 358 588 400 0 0 1280 778 </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>3849DA101042E5B100376E6F</string>
				<string>1C78EAAC065D492600B07095</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.consoleV3</string>
			<key>WindowString</key>
			<string>35 358 588 400 0 0 1280 778 </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>136 326 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>136 326 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>3849DA111042E5B100376E6F</string>
				<string>3849DA121042E5B100376E6F</string>
				<string>1CE0B1FE06471DED0097A5F4</string>
				<string>1CA1AED706398EBD00589147</string>
			</array>
			<key>ToolbarConfiguration</key>
			<string>xcode.toolbar.config.breakpointsV3</string>
			<key>WindowString</key>
			<string>136 326 744 409 0 0 1280 778 </string>
			<key>WindowToolGUID</key>
			<string>3849DA111042E5B100376E6F</string>
			<key>WindowToolIsVisible</key>
			<false/>
		</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 NULMODEM.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
// !$*UTF8*$!
{
	08FB7793FE84155DC02AAC07 /* Project object */ = {
		activeBuildConfigurationName = Debug;
		activeExecutable = 3873936F0A9716D200545E38 /* nulmodem */;
		activeTarget = 8DD76FA90486AB0100D96B5E /* nulmodem */;
		addToTargets = (
			8DD76FA90486AB0100D96B5E /* nulmodem */,
		);
		breakpoints = (
		);
		codeSenseManager = 387393730A9716DC00545E38 /* Code sense */;
		executables = (
			3873936F0A9716D200545E38 /* nulmodem */,
		);
		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,
					300,
					155.20849609375,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXErrorsWarningsDataSource_TypeID,
					PBXErrorsWarningsDataSource_MessageID,
					PBXErrorsWarningsDataSource_LocationID,
				);
			};
			PBXConfiguration.PBXFileTableDataSource3.PBXExecutablesDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXExecutablesDataSource_NameID;
				PBXFileTableDataSourceColumnWidthsKey = (
					22,
					300,
					153,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXExecutablesDataSource_ActiveFlagID,
					PBXExecutablesDataSource_NameID,
					PBXExecutablesDataSource_CommentsID,
				);
			};
			PBXConfiguration.PBXFileTableDataSource3.PBXFileTableDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
				PBXFileTableDataSourceColumnWidthsKey = (
					20,
					265,
					20,
					48,
					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 = (
					200,
					279,
				);
				PBXFileTableDataSourceColumnsKey = (
					PBXFindDataSource_MessageID,
					PBXFindDataSource_LocationID,
				);
			};
			PBXConfiguration.PBXTargetDataSource.PBXTargetDataSource = {
				PBXFileTableDataSourceColumnSortingDirectionKey = "-1";
				PBXFileTableDataSourceColumnSortingKey = PBXFileDataSource_Filename_ColumnID;
				PBXFileTableDataSourceColumnWidthsKey = (
					20,
					200,
					10,
					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 = 330980585;
			PBXWorkspaceStateSaveDate = 330980585;
		};
		sourceControlManager = 387393720A9716DC00545E38 /* Source Control */;
		userBuildSettings = {
		};
	};
	3873936F0A9716D200545E38 /* nulmodem */ = {
		isa = PBXExecutable;
		activeArgIndices = (
			NO,
			NO,
			NO,
			NO,
			NO,
			NO,
			NO,
			YES,
		);
		argumentStrings = (
			"-v",
			"-p0 7000 -tcp0 10.1.10.200 -p1 7010 -tcp1 10.1.10.20",
			"-p0 23 -tcp0 10.1.13.150 -p1 7000",
			"-p0 7000 -loop -log",
			"-p0 7000 -p1 7010 -log",
			"-loop",
			"-p0 7000 -tcp0 10.1.10.200 -loop",
			"-loop -p0 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 = nulmodem;
		savedGlobals = {
		};
		showTypeColumn = 0;
		sourceDirectories = (
		);
		variableFormatDictionary = {
		};
	};
	387393720A9716DC00545E38 /* Source Control */ = {
		isa = PBXSourceControlManager;
		fallbackIsa = XCSourceControlManager;
		isSCMEnabled = 0;
		scmConfiguration = {
			repositoryNamesForRoots = {
				"" = "";
			};
		};
		scmType = "";
	};
	387393730A9716DC00545E38 /* Code sense */ = {
		isa = PBXCodeSenseManager;
		indexTemplatePath = "";
	};
	387393790A9716ED00545E38 /* lua_timer.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {706, 2758}}";
			sepNavSelRange = "{742, 0}";
			sepNavVisRect = "{{0, 287}, {706, 141}}";
			sepNavWindowFrame = "{{-986, 99}, {764, 643}}";
		};
	};
	3873937C0A9716ED00545E38 /* lua_net.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {805, 650}}";
			sepNavSelRange = "{0, 0}";
			sepNavVisRange = "{0, 711}";
			sepNavWindowFrame = "{{15, 0}, {852, 778}}";
		};
	};
	3873937D0A9716ED00545E38 /* lua_net.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {717, 4592}}";
			sepNavSelRange = "{0, 0}";
			sepNavVisRange = "{6256, 774}";
			sepNavVisRect = "{{0, 4078}, {719, 514}}";
			sepNavWindowFrame = "{{0, 78}, {764, 643}}";
		};
	};
	3873937F0A9716ED00545E38 /* lauxlib.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {719, 8288}}";
			sepNavSelRange = "{0, 0}";
			sepNavVisRect = "{{0, 0}, {719, 514}}";
			sepNavWindowFrame = "{{-963, 78}, {764, 643}}";
		};
	};
	387393990A9716ED00545E38 /* lstate.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {719, 3094}}";
			sepNavSelRange = "{4691, 0}";
			sepNavVisRect = "{{0, 2580}, {719, 514}}";
			sepNavWindowFrame = "{{-1009, 120}, {764, 643}}";
		};
	};
	3873939A0A9716ED00545E38 /* lstate.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {719, 2814}}";
			sepNavSelRange = "{857, 17}";
			sepNavVisRect = "{{0, 2300}, {719, 514}}";
			sepNavWindowFrame = "{{-986, 99}, {764, 643}}";
		};
	};
	387393B90A9716ED00545E38 /* netcom.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {717, 6454}}";
			sepNavSelRange = "{481, 37}";
			sepNavVisRange = "{0, 1062}";
			sepNavVisRect = "{{0, 4875}, {719, 570}}";
			sepNavWindowFrame = "{{640, -37}, {764, 643}}";
		};
	};
	387393BA0A9716ED00545E38 /* netcom.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {719, 1008}}";
			sepNavSelRange = "{1291, 24}";
			sepNavVisRect = "{{0, 418}, {719, 514}}";
			sepNavWindowFrame = "{{-1264, 77}, {764, 643}}";
		};
	};
	387393FF0A97171100545E38 /* nulmodem.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {630, 11718}}";
			sepNavSelRange = "{12336, 0}";
			sepNavVisRange = "{19385, 886}";
			sepNavVisRect = "{{0, 7133}, {592, 576}}";
			sepNavWindowFrame = "{{316, 126}, {637, 649}}";
		};
	};
	387394000A97171100545E38 /* nulmodem.h */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {717, 1204}}";
			sepNavSelRange = "{1976, 14}";
			sepNavVisRange = "{1283, 730}";
			sepNavVisRect = "{{0, 681}, {719, 514}}";
			sepNavWindowFrame = "{{-738, 24}, {764, 643}}";
		};
	};
	387394210A971AC500545E38 /* bsdserial.c */ = {
		uiCtxt = {
			sepNavIntBoundsRect = "{{0, 0}, {688, 11396}}";
			sepNavSelRange = "{0, 0}";
			sepNavVisRange = "{4331, 848}";
			sepNavWindowFrame = "{{15, 37}, {735, 736}}";
		};
	};
	8DD76FA90486AB0100D96B5E /* nulmodem */ = {
		activeExec = 0;
		executables = (
			3873936F0A9716D200545E38 /* nulmodem */,
		);
	};
}

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

/* Begin PBXBuildFile section */
		38016B8E0A99D97400D2F81E /* CoreFoundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38016B8D0A99D97400D2F81E /* CoreFoundation.framework */; };
		38016BBA0A99D98900D2F81E /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 38016BB90A99D98900D2F81E /* IOKit.framework */; };
		387393BF0A9716ED00545E38 /* lua_timer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393780A9716ED00545E38 /* lua_timer.h */; };
		387393C00A9716ED00545E38 /* lua_timer.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393790A9716ED00545E38 /* lua_timer.c */; };
		387393C30A9716ED00545E38 /* lua_net.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873937C0A9716ED00545E38 /* lua_net.h */; };
		387393C40A9716ED00545E38 /* lua_net.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873937D0A9716ED00545E38 /* lua_net.c */; };
		387393C50A9716ED00545E38 /* lauxlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873937F0A9716ED00545E38 /* lauxlib.c */; };
		387393C60A9716ED00545E38 /* lbaselib.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393800A9716ED00545E38 /* lbaselib.c */; };
		387393C70A9716ED00545E38 /* ldblib.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393810A9716ED00545E38 /* ldblib.c */; };
		387393C80A9716ED00545E38 /* liolib.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393820A9716ED00545E38 /* liolib.c */; };
		387393C90A9716ED00545E38 /* lmathlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393830A9716ED00545E38 /* lmathlib.c */; };
		387393CA0A9716ED00545E38 /* loadlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393840A9716ED00545E38 /* loadlib.c */; };
		387393CB0A9716ED00545E38 /* lstrlib.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393850A9716ED00545E38 /* lstrlib.c */; };
		387393CC0A9716ED00545E38 /* ltablib.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393860A9716ED00545E38 /* ltablib.c */; };
		387393CD0A9716ED00545E38 /* lundump.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393880A9716ED00545E38 /* lundump.c */; };
		387393CE0A9716ED00545E38 /* lundump.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393890A9716ED00545E38 /* lundump.h */; };
		387393CF0A9716ED00545E38 /* lvm.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873938A0A9716ED00545E38 /* lvm.c */; };
		387393D00A9716ED00545E38 /* lvm.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873938B0A9716ED00545E38 /* lvm.h */; };
		387393D10A9716ED00545E38 /* lzio.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873938C0A9716ED00545E38 /* lzio.c */; };
		387393D20A9716ED00545E38 /* lzio.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873938D0A9716ED00545E38 /* lzio.h */; };
		387393D30A9716ED00545E38 /* llex.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873938E0A9716ED00545E38 /* llex.c */; };
		387393D40A9716ED00545E38 /* llex.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873938F0A9716ED00545E38 /* llex.h */; };
		387393D50A9716ED00545E38 /* llimits.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393900A9716ED00545E38 /* llimits.h */; };
		387393D60A9716ED00545E38 /* lmem.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393910A9716ED00545E38 /* lmem.c */; };
		387393D70A9716ED00545E38 /* lmem.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393920A9716ED00545E38 /* lmem.h */; };
		387393D80A9716ED00545E38 /* lobject.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393930A9716ED00545E38 /* lobject.c */; };
		387393D90A9716ED00545E38 /* lobject.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393940A9716ED00545E38 /* lobject.h */; };
		387393DA0A9716ED00545E38 /* lopcodes.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393950A9716ED00545E38 /* lopcodes.c */; };
		387393DB0A9716ED00545E38 /* lopcodes.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393960A9716ED00545E38 /* lopcodes.h */; };
		387393DC0A9716ED00545E38 /* lparser.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393970A9716ED00545E38 /* lparser.c */; };
		387393DD0A9716ED00545E38 /* lparser.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393980A9716ED00545E38 /* lparser.h */; };
		387393DE0A9716ED00545E38 /* lstate.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393990A9716ED00545E38 /* lstate.c */; };
		387393DF0A9716ED00545E38 /* lstate.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873939A0A9716ED00545E38 /* lstate.h */; };
		387393E00A9716ED00545E38 /* lstring.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873939B0A9716ED00545E38 /* lstring.c */; };
		387393E10A9716ED00545E38 /* lstring.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873939C0A9716ED00545E38 /* lstring.h */; };
		387393E20A9716ED00545E38 /* ltable.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873939D0A9716ED00545E38 /* ltable.c */; };
		387393E30A9716ED00545E38 /* ltable.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873939E0A9716ED00545E38 /* ltable.h */; };
		387393E40A9716ED00545E38 /* ltests.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873939F0A9716ED00545E38 /* ltests.c */; };
		387393E50A9716ED00545E38 /* ltm.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393A00A9716ED00545E38 /* ltm.c */; };
		387393E60A9716ED00545E38 /* ltm.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393A10A9716ED00545E38 /* ltm.h */; };
		387393E70A9716ED00545E38 /* lapi.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393A20A9716ED00545E38 /* lapi.c */; };
		387393E80A9716ED00545E38 /* lapi.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393A30A9716ED00545E38 /* lapi.h */; };
		387393E90A9716ED00545E38 /* lcode.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393A40A9716ED00545E38 /* lcode.c */; };
		387393EA0A9716ED00545E38 /* lcode.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393A50A9716ED00545E38 /* lcode.h */; };
		387393EB0A9716ED00545E38 /* ldebug.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393A60A9716ED00545E38 /* ldebug.c */; };
		387393EC0A9716ED00545E38 /* ldebug.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393A70A9716ED00545E38 /* ldebug.h */; };
		387393ED0A9716ED00545E38 /* ldo.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393A80A9716ED00545E38 /* ldo.c */; };
		387393EE0A9716ED00545E38 /* ldo.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393A90A9716ED00545E38 /* ldo.h */; };
		387393EF0A9716ED00545E38 /* ldump.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393AA0A9716ED00545E38 /* ldump.c */; };
		387393F00A9716ED00545E38 /* lfunc.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393AB0A9716ED00545E38 /* lfunc.c */; };
		387393F10A9716ED00545E38 /* lfunc.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393AC0A9716ED00545E38 /* lfunc.h */; };
		387393F20A9716ED00545E38 /* lgc.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393AD0A9716ED00545E38 /* lgc.c */; };
		387393F30A9716ED00545E38 /* lgc.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393AE0A9716ED00545E38 /* lgc.h */; };
		387393F40A9716ED00545E38 /* lauxlib.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393B00A9716ED00545E38 /* lauxlib.h */; };
		387393F50A9716ED00545E38 /* lua.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393B10A9716ED00545E38 /* lua.h */; };
		387393F60A9716ED00545E38 /* lualib.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393B20A9716ED00545E38 /* lualib.h */; };
		387393FB0A9716ED00545E38 /* netcom.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393B90A9716ED00545E38 /* netcom.c */; };
		387393FC0A9716ED00545E38 /* netcom.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393BA0A9716ED00545E38 /* netcom.h */; };
		387393FD0A9716ED00545E38 /* tgtypes.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387393BC0A9716ED00545E38 /* tgtypes.h */; };
		387394010A97171100545E38 /* nulmodem.c in Sources */ = {isa = PBXBuildFile; fileRef = 387393FF0A97171100545E38 /* nulmodem.c */; };
		387394020A97171100545E38 /* nulmodem.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387394000A97171100545E38 /* nulmodem.h */; };
		387394230A971AC500545E38 /* bsdserial.c in Sources */ = {isa = PBXBuildFile; fileRef = 387394210A971AC500545E38 /* bsdserial.c */; };
		387394240A971AC500545E38 /* bsdserial.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 387394220A971AC500545E38 /* bsdserial.h */; };
		3873942F0A971B0300545E38 /* tgtimer.c in Sources */ = {isa = PBXBuildFile; fileRef = 3873942D0A971B0300545E38 /* tgtimer.c */; };
		387394300A971B0300545E38 /* tgtimer.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3873942E0A971B0300545E38 /* tgtimer.h */; };
		8DD76FB00486AB0100D96B5E /* NULMODEM.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = C6A0FF2C0290799A04C91782 /* NULMODEM.1 */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
		8DD76FAF0486AB0100D96B5E /* CopyFiles */ = {
			isa = PBXCopyFilesBuildPhase;
			buildActionMask = 8;
			dstPath = /usr/share/man/man1/;
			dstSubfolderSpec = 0;
			files = (
				8DD76FB00486AB0100D96B5E /* NULMODEM.1 in CopyFiles */,
				387393BF0A9716ED00545E38 /* lua_timer.h in CopyFiles */,
				387393C30A9716ED00545E38 /* lua_net.h in CopyFiles */,
				387393CE0A9716ED00545E38 /* lundump.h in CopyFiles */,
				387393D00A9716ED00545E38 /* lvm.h in CopyFiles */,
				387393D20A9716ED00545E38 /* lzio.h in CopyFiles */,
				387393D40A9716ED00545E38 /* llex.h in CopyFiles */,
				387393D50A9716ED00545E38 /* llimits.h in CopyFiles */,
				387393D70A9716ED00545E38 /* lmem.h in CopyFiles */,
				387393D90A9716ED00545E38 /* lobject.h in CopyFiles */,
				387393DB0A9716ED00545E38 /* lopcodes.h in CopyFiles */,
				387393DD0A9716ED00545E38 /* lparser.h in CopyFiles */,
				387393DF0A9716ED00545E38 /* lstate.h in CopyFiles */,
				387393E10A9716ED00545E38 /* lstring.h in CopyFiles */,
				387393E30A9716ED00545E38 /* ltable.h in CopyFiles */,
				387393E60A9716ED00545E38 /* ltm.h in CopyFiles */,
				387393E80A9716ED00545E38 /* lapi.h in CopyFiles */,
				387393EA0A9716ED00545E38 /* lcode.h in CopyFiles */,
				387393EC0A9716ED00545E38 /* ldebug.h in CopyFiles */,
				387393EE0A9716ED00545E38 /* ldo.h in CopyFiles */,
				387393F10A9716ED00545E38 /* lfunc.h in CopyFiles */,
				387393F30A9716ED00545E38 /* lgc.h in CopyFiles */,
				387393F40A9716ED00545E38 /* lauxlib.h in CopyFiles */,
				387393F50A9716ED00545E38 /* lua.h in CopyFiles */,
				387393F60A9716ED00545E38 /* lualib.h in CopyFiles */,
				387393FC0A9716ED00545E38 /* netcom.h in CopyFiles */,
				387393FD0A9716ED00545E38 /* tgtypes.h in CopyFiles */,
				387394020A97171100545E38 /* nulmodem.h in CopyFiles */,
				387394240A971AC500545E38 /* bsdserial.h in CopyFiles */,
				387394300A971B0300545E38 /* tgtimer.h in CopyFiles */,
			);
			runOnlyForDeploymentPostprocessing = 1;
		};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
		38016B8D0A99D97400D2F81E /* CoreFoundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreFoundation.framework; path = ../../../../../../System/Library/Frameworks/CoreFoundation.framework; sourceTree = SOURCE_ROOT; };
		38016BB90A99D98900D2F81E /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = ../../../../../../System/Library/Frameworks/IOKit.framework; sourceTree = SOURCE_ROOT; };
		387393780A9716ED00545E38 /* lua_timer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lua_timer.h; path = TGLuaLibs/lua_timer.h; sourceTree = SOURCE_ROOT; };
		387393790A9716ED00545E38 /* lua_timer.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lua_timer.c; path = TGLuaLibs/lua_timer.c; sourceTree = SOURCE_ROOT; };
		3873937C0A9716ED00545E38 /* lua_net.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lua_net.h; path = TGLuaLibs/lua_net.h; sourceTree = SOURCE_ROOT; };
		3873937D0A9716ED00545E38 /* lua_net.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lua_net.c; path = TGLuaLibs/lua_net.c; sourceTree = SOURCE_ROOT; };
		3873937F0A9716ED00545E38 /* lauxlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lauxlib.c; path = "../TERMS/lua-5.0.2/src/lib/lauxlib.c"; sourceTree = SOURCE_ROOT; };
		387393800A9716ED00545E38 /* lbaselib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lbaselib.c; path = "../TERMS/lua-5.0.2/src/lib/lbaselib.c"; sourceTree = SOURCE_ROOT; };
		387393810A9716ED00545E38 /* ldblib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldblib.c; path = "../TERMS/lua-5.0.2/src/lib/ldblib.c"; sourceTree = SOURCE_ROOT; };
		387393820A9716ED00545E38 /* liolib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = liolib.c; path = "../TERMS/lua-5.0.2/src/lib/liolib.c"; sourceTree = SOURCE_ROOT; };
		387393830A9716ED00545E38 /* lmathlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lmathlib.c; path = "../TERMS/lua-5.0.2/src/lib/lmathlib.c"; sourceTree = SOURCE_ROOT; };
		387393840A9716ED00545E38 /* loadlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = loadlib.c; path = "../TERMS/lua-5.0.2/src/lib/loadlib.c"; sourceTree = SOURCE_ROOT; };
		387393850A9716ED00545E38 /* lstrlib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lstrlib.c; path = "../TERMS/lua-5.0.2/src/lib/lstrlib.c"; sourceTree = SOURCE_ROOT; };
		387393860A9716ED00545E38 /* ltablib.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltablib.c; path = "../TERMS/lua-5.0.2/src/lib/ltablib.c"; sourceTree = SOURCE_ROOT; };
		387393880A9716ED00545E38 /* lundump.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lundump.c; path = "../TERMS/lua-5.0.2/src/lundump.c"; sourceTree = SOURCE_ROOT; };
		387393890A9716ED00545E38 /* lundump.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lundump.h; path = "../TERMS/lua-5.0.2/src/lundump.h"; sourceTree = SOURCE_ROOT; };
		3873938A0A9716ED00545E38 /* lvm.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lvm.c; path = "../TERMS/lua-5.0.2/src/lvm.c"; sourceTree = SOURCE_ROOT; };
		3873938B0A9716ED00545E38 /* lvm.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lvm.h; path = "../TERMS/lua-5.0.2/src/lvm.h"; sourceTree = SOURCE_ROOT; };
		3873938C0A9716ED00545E38 /* lzio.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lzio.c; path = "../TERMS/lua-5.0.2/src/lzio.c"; sourceTree = SOURCE_ROOT; };
		3873938D0A9716ED00545E38 /* lzio.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lzio.h; path = "../TERMS/lua-5.0.2/src/lzio.h"; sourceTree = SOURCE_ROOT; };
		3873938E0A9716ED00545E38 /* llex.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = llex.c; path = "../TERMS/lua-5.0.2/src/llex.c"; sourceTree = SOURCE_ROOT; };
		3873938F0A9716ED00545E38 /* llex.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = llex.h; path = "../TERMS/lua-5.0.2/src/llex.h"; sourceTree = SOURCE_ROOT; };
		387393900A9716ED00545E38 /* llimits.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = llimits.h; path = "../TERMS/lua-5.0.2/src/llimits.h"; sourceTree = SOURCE_ROOT; };
		387393910A9716ED00545E38 /* lmem.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lmem.c; path = "../TERMS/lua-5.0.2/src/lmem.c"; sourceTree = SOURCE_ROOT; };
		387393920A9716ED00545E38 /* lmem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lmem.h; path = "../TERMS/lua-5.0.2/src/lmem.h"; sourceTree = SOURCE_ROOT; };
		387393930A9716ED00545E38 /* lobject.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lobject.c; path = "../TERMS/lua-5.0.2/src/lobject.c"; sourceTree = SOURCE_ROOT; };
		387393940A9716ED00545E38 /* lobject.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lobject.h; path = "../TERMS/lua-5.0.2/src/lobject.h"; sourceTree = SOURCE_ROOT; };
		387393950A9716ED00545E38 /* lopcodes.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lopcodes.c; path = "../TERMS/lua-5.0.2/src/lopcodes.c"; sourceTree = SOURCE_ROOT; };
		387393960A9716ED00545E38 /* lopcodes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lopcodes.h; path = "../TERMS/lua-5.0.2/src/lopcodes.h"; sourceTree = SOURCE_ROOT; };
		387393970A9716ED00545E38 /* lparser.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lparser.c; path = "../TERMS/lua-5.0.2/src/lparser.c"; sourceTree = SOURCE_ROOT; };
		387393980A9716ED00545E38 /* lparser.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lparser.h; path = "../TERMS/lua-5.0.2/src/lparser.h"; sourceTree = SOURCE_ROOT; };
		387393990A9716ED00545E38 /* lstate.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lstate.c; path = "../TERMS/lua-5.0.2/src/lstate.c"; sourceTree = SOURCE_ROOT; };
		3873939A0A9716ED00545E38 /* lstate.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lstate.h; path = "../TERMS/lua-5.0.2/src/lstate.h"; sourceTree = SOURCE_ROOT; };
		3873939B0A9716ED00545E38 /* lstring.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lstring.c; path = "../TERMS/lua-5.0.2/src/lstring.c"; sourceTree = SOURCE_ROOT; };
		3873939C0A9716ED00545E38 /* lstring.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lstring.h; path = "../TERMS/lua-5.0.2/src/lstring.h"; sourceTree = SOURCE_ROOT; };
		3873939D0A9716ED00545E38 /* ltable.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltable.c; path = "../TERMS/lua-5.0.2/src/ltable.c"; sourceTree = SOURCE_ROOT; };
		3873939E0A9716ED00545E38 /* ltable.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ltable.h; path = "../TERMS/lua-5.0.2/src/ltable.h"; sourceTree = SOURCE_ROOT; };
		3873939F0A9716ED00545E38 /* ltests.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltests.c; path = "../TERMS/lua-5.0.2/src/ltests.c"; sourceTree = SOURCE_ROOT; };
		387393A00A9716ED00545E38 /* ltm.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ltm.c; path = "../TERMS/lua-5.0.2/src/ltm.c"; sourceTree = SOURCE_ROOT; };
		387393A10A9716ED00545E38 /* ltm.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ltm.h; path = "../TERMS/lua-5.0.2/src/ltm.h"; sourceTree = SOURCE_ROOT; };
		387393A20A9716ED00545E38 /* lapi.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lapi.c; path = "../TERMS/lua-5.0.2/src/lapi.c"; sourceTree = SOURCE_ROOT; };
		387393A30A9716ED00545E38 /* lapi.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lapi.h; path = "../TERMS/lua-5.0.2/src/lapi.h"; sourceTree = SOURCE_ROOT; };
		387393A40A9716ED00545E38 /* lcode.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lcode.c; path = "../TERMS/lua-5.0.2/src/lcode.c"; sourceTree = SOURCE_ROOT; };
		387393A50A9716ED00545E38 /* lcode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lcode.h; path = "../TERMS/lua-5.0.2/src/lcode.h"; sourceTree = SOURCE_ROOT; };
		387393A60A9716ED00545E38 /* ldebug.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldebug.c; path = "../TERMS/lua-5.0.2/src/ldebug.c"; sourceTree = SOURCE_ROOT; };
		387393A70A9716ED00545E38 /* ldebug.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ldebug.h; path = "../TERMS/lua-5.0.2/src/ldebug.h"; sourceTree = SOURCE_ROOT; };
		387393A80A9716ED00545E38 /* ldo.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldo.c; path = "../TERMS/lua-5.0.2/src/ldo.c"; sourceTree = SOURCE_ROOT; };
		387393A90A9716ED00545E38 /* ldo.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ldo.h; path = "../TERMS/lua-5.0.2/src/ldo.h"; sourceTree = SOURCE_ROOT; };
		387393AA0A9716ED00545E38 /* ldump.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = ldump.c; path = "../TERMS/lua-5.0.2/src/ldump.c"; sourceTree = SOURCE_ROOT; };
		387393AB0A9716ED00545E38 /* lfunc.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lfunc.c; path = "../TERMS/lua-5.0.2/src/lfunc.c"; sourceTree = SOURCE_ROOT; };
		387393AC0A9716ED00545E38 /* lfunc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lfunc.h; path = "../TERMS/lua-5.0.2/src/lfunc.h"; sourceTree = SOURCE_ROOT; };
		387393AD0A9716ED00545E38 /* lgc.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = lgc.c; path = "../TERMS/lua-5.0.2/src/lgc.c"; sourceTree = SOURCE_ROOT; };
		387393AE0A9716ED00545E38 /* lgc.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lgc.h; path = "../TERMS/lua-5.0.2/src/lgc.h"; sourceTree = SOURCE_ROOT; };
		387393B00A9716ED00545E38 /* lauxlib.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lauxlib.h; path = "../TERMS/lua-5.0.2/include/lauxlib.h"; sourceTree = SOURCE_ROOT; };
		387393B10A9716ED00545E38 /* lua.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lua.h; path = "../TERMS/lua-5.0.2/include/lua.h"; sourceTree = SOURCE_ROOT; };
		387393B20A9716ED00545E38 /* lualib.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = lualib.h; path = "../TERMS/lua-5.0.2/include/lualib.h"; sourceTree = SOURCE_ROOT; };
		387393B90A9716ED00545E38 /* netcom.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = netcom.c; path = COMS/netcom.c; sourceTree = SOURCE_ROOT; };
		387393BA0A9716ED00545E38 /* netcom.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = netcom.h; path = COMS/netcom.h; sourceTree = SOURCE_ROOT; };
		387393BC0A9716ED00545E38 /* tgtypes.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = tgtypes.h; sourceTree = "<group>"; };
		387393FF0A97171100545E38 /* nulmodem.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = nulmodem.c; sourceTree = SOURCE_ROOT; };
		387394000A97171100545E38 /* nulmodem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = nulmodem.h; sourceTree = SOURCE_ROOT; };
		387394210A971AC500545E38 /* bsdserial.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = bsdserial.c; path = SERIAL/OSX/bsdserial.c; sourceTree = SOURCE_ROOT; };
		387394220A971AC500545E38 /* bsdserial.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = bsdserial.h; path = SERIAL/OSX/bsdserial.h; sourceTree = SOURCE_ROOT; };
		3873942D0A971B0300545E38 /* tgtimer.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; path = tgtimer.c; sourceTree = SOURCE_ROOT; };
		3873942E0A971B0300545E38 /* tgtimer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = tgtimer.h; sourceTree = SOURCE_ROOT; };
		8DD76FB20486AB0100D96B5E /* nulmodem */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = nulmodem; sourceTree = BUILT_PRODUCTS_DIR; };
		C6A0FF2C0290799A04C91782 /* NULMODEM.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = NULMODEM.1; sourceTree = "<group>"; };
/* End PBXFileReference section */

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

/* Begin PBXGroup section */
		08FB7794FE84155DC02AAC07 /* NULMODEM */ = {
			isa = PBXGroup;
			children = (
				08FB7795FE84155DC02AAC07 /* Source */,
				387394640A971C7300545E38 /* External Frameworks */,
				C6A0FF2B0290797F04C91782 /* Documentation */,
				1AB674ADFE9D54B511CA2CBB /* Products */,
			);
			name = NULMODEM;
			sourceTree = "<group>";
		};
		08FB7795FE84155DC02AAC07 /* Source */ = {
			isa = PBXGroup;
			children = (
				387393FF0A97171100545E38 /* nulmodem.c */,
				387394000A97171100545E38 /* nulmodem.h */,
				387393BB0A9716ED00545E38 /* Include */,
				387393B80A9716ED00545E38 /* Network */,
				387393B30A9716ED00545E38 /* OSX */,
				387393760A9716ED00545E38 /* LUA */,
			);
			name = Source;
			sourceTree = "<group>";
		};
		1AB674ADFE9D54B511CA2CBB /* Products */ = {
			isa = PBXGroup;
			children = (
				8DD76FB20486AB0100D96B5E /* nulmodem */,
			);
			name = Products;
			sourceTree = "<group>";
		};
		387393760A9716ED00545E38 /* LUA */ = {
			isa = PBXGroup;
			children = (
				387393AF0A9716ED00545E38 /* Include */,
				387393870A9716ED00545E38 /* CORE */,
				3873937E0A9716ED00545E38 /* Libraries */,
				387393770A9716ED00545E38 /* TERMS Lib */,
			);
			name = LUA;
			sourceTree = SOURCE_ROOT;
		};
		387393770A9716ED00545E38 /* TERMS Lib */ = {
			isa = PBXGroup;
			children = (
				387393780A9716ED00545E38 /* lua_timer.h */,
				387393790A9716ED00545E38 /* lua_timer.c */,
				3873937C0A9716ED00545E38 /* lua_net.h */,
				3873937D0A9716ED00545E38 /* lua_net.c */,
			);
			name = "TERMS Lib";
			sourceTree = SOURCE_ROOT;
		};
		3873937E0A9716ED00545E38 /* Libraries */ = {
			isa = PBXGroup;
			children = (
				3873937F0A9716ED00545E38 /* lauxlib.c */,
				387393800A9716ED00545E38 /* lbaselib.c */,
				387393810A9716ED00545E38 /* ldblib.c */,
				387393820A9716ED00545E38 /* liolib.c */,
				387393830A9716ED00545E38 /* lmathlib.c */,
				387393840A9716ED00545E38 /* loadlib.c */,
				387393850A9716ED00545E38 /* lstrlib.c */,
				387393860A9716ED00545E38 /* ltablib.c */,
			);
			name = Libraries;
			sourceTree = SOURCE_ROOT;
		};
		387393870A9716ED00545E38 /* CORE */ = {
			isa = PBXGroup;
			children = (
				387393880A9716ED00545E38 /* lundump.c */,
				387393890A9716ED00545E38 /* lundump.h */,
				3873938A0A9716ED00545E38 /* lvm.c */,
				3873938B0A9716ED00545E38 /* lvm.h */,
				3873938C0A9716ED00545E38 /* lzio.c */,
				3873938D0A9716ED00545E38 /* lzio.h */,
				3873938E0A9716ED00545E38 /* llex.c */,
				3873938F0A9716ED00545E38 /* llex.h */,
				387393900A9716ED00545E38 /* llimits.h */,
				387393910A9716ED00545E38 /* lmem.c */,
				387393920A9716ED00545E38 /* lmem.h */,
				387393930A9716ED00545E38 /* lobject.c */,
				387393940A9716ED00545E38 /* lobject.h */,
				387393950A9716ED00545E38 /* lopcodes.c */,
				387393960A9716ED00545E38 /* lopcodes.h */,
				387393970A9716ED00545E38 /* lparser.c */,
				387393980A9716ED00545E38 /* lparser.h */,
				387393990A9716ED00545E38 /* lstate.c */,
				3873939A0A9716ED00545E38 /* lstate.h */,
				3873939B0A9716ED00545E38 /* lstring.c */,
				3873939C0A9716ED00545E38 /* lstring.h */,
				3873939D0A9716ED00545E38 /* ltable.c */,
				3873939E0A9716ED00545E38 /* ltable.h */,
				3873939F0A9716ED00545E38 /* ltests.c */,
				387393A00A9716ED00545E38 /* ltm.c */,
				387393A10A9716ED00545E38 /* ltm.h */,
				387393A20A9716ED00545E38 /* lapi.c */,
				387393A30A9716ED00545E38 /* lapi.h */,
				387393A40A9716ED00545E38 /* lcode.c */,
				387393A50A9716ED00545E38 /* lcode.h */,
				387393A60A9716ED00545E38 /* ldebug.c */,
				387393A70A9716ED00545E38 /* ldebug.h */,
				387393A80A9716ED00545E38 /* ldo.c */,
				387393A90A9716ED00545E38 /* ldo.h */,
				387393AA0A9716ED00545E38 /* ldump.c */,
				387393AB0A9716ED00545E38 /* lfunc.c */,
				387393AC0A9716ED00545E38 /* lfunc.h */,
				387393AD0A9716ED00545E38 /* lgc.c */,
				387393AE0A9716ED00545E38 /* lgc.h */,
			);
			name = CORE;
			sourceTree = SOURCE_ROOT;
		};
		387393AF0A9716ED00545E38 /* Include */ = {
			isa = PBXGroup;
			children = (
				387393B00A9716ED00545E38 /* lauxlib.h */,
				387393B10A9716ED00545E38 /* lua.h */,
				387393B20A9716ED00545E38 /* lualib.h */,
			);
			name = Include;
			sourceTree = SOURCE_ROOT;
		};
		387393B30A9716ED00545E38 /* OSX */ = {
			isa = PBXGroup;
			children = (
				3873942D0A971B0300545E38 /* tgtimer.c */,
				3873942E0A971B0300545E38 /* tgtimer.h */,
				387394210A971AC500545E38 /* bsdserial.c */,
				387394220A971AC500545E38 /* bsdserial.h */,
			);
			name = OSX;
			path = SERIAL/OSX;
			sourceTree = SOURCE_ROOT;
		};
		387393B80A9716ED00545E38 /* Network */ = {
			isa = PBXGroup;
			children = (
				387393B90A9716ED00545E38 /* netcom.c */,
				387393BA0A9716ED00545E38 /* netcom.h */,
			);
			name = Network;
			sourceTree = SOURCE_ROOT;
		};
		387393BB0A9716ED00545E38 /* Include */ = {
			isa = PBXGroup;
			children = (
				387393BC0A9716ED00545E38 /* tgtypes.h */,
			);
			name = Include;
			sourceTree = SOURCE_ROOT;
		};
		387394640A971C7300545E38 /* External Frameworks */ = {
			isa = PBXGroup;
			children = (
				38016BB90A99D98900D2F81E /* IOKit.framework */,
				38016B8D0A99D97400D2F81E /* CoreFoundation.framework */,
			);
			name = "External Frameworks";
			sourceTree = SOURCE_ROOT;
		};
		C6A0FF2B0290797F04C91782 /* Documentation */ = {
			isa = PBXGroup;
			children = (
				C6A0FF2C0290799A04C91782 /* NULMODEM.1 */,
			);
			name = Documentation;
			sourceTree = "<group>";
		};
/* End PBXGroup section */

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

/* Begin PBXProject section */
		08FB7793FE84155DC02AAC07 /* Project object */ = {
			isa = PBXProject;
			buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "NULMODEM" */;
			compatibilityVersion = "Xcode 3.2";
			developmentRegion = English;
			hasScannedForEncodings = 1;
			knownRegions = (
				English,
				Japanese,
				French,
				German,
			);
			mainGroup = 08FB7794FE84155DC02AAC07 /* NULMODEM */;
			projectDirPath = "";
			projectRoot = "";
			targets = (
				8DD76FA90486AB0100D96B5E /* nulmodem */,
			);
		};
/* End PBXProject section */

/* Begin PBXSourcesBuildPhase section */
		8DD76FAB0486AB0100D96B5E /* Sources */ = {
			isa = PBXSourcesBuildPhase;
			buildActionMask = 2147483647;
			files = (
				387393C00A9716ED00545E38 /* lua_timer.c in Sources */,
				387393C40A9716ED00545E38 /* lua_net.c in Sources */,
				387393C50A9716ED00545E38 /* lauxlib.c in Sources */,
				387393C60A9716ED00545E38 /* lbaselib.c in Sources */,
				387393C70A9716ED00545E38 /* ldblib.c in Sources */,
				387393C80A9716ED00545E38 /* liolib.c in Sources */,
				387393C90A9716ED00545E38 /* lmathlib.c in Sources */,
				387393CA0A9716ED00545E38 /* loadlib.c in Sources */,
				387393CB0A9716ED00545E38 /* lstrlib.c in Sources */,
				387393CC0A9716ED00545E38 /* ltablib.c in Sources */,
				387393CD0A9716ED00545E38 /* lundump.c in Sources */,
				387393CF0A9716ED00545E38 /* lvm.c in Sources */,
				387393D10A9716ED00545E38 /* lzio.c in Sources */,
				387393D30A9716ED00545E38 /* llex.c in Sources */,
				387393D60A9716ED00545E38 /* lmem.c in Sources */,
				387393D80A9716ED00545E38 /* lobject.c in Sources */,
				387393DA0A9716ED00545E38 /* lopcodes.c in Sources */,
				387393DC0A9716ED00545E38 /* lparser.c in Sources */,
				387393DE0A9716ED00545E38 /* lstate.c in Sources */,
				387393E00A9716ED00545E38 /* lstring.c in Sources */,
				387393E20A9716ED00545E38 /* ltable.c in Sources */,
				387393E40A9716ED00545E38 /* ltests.c in Sources */,
				387393E50A9716ED00545E38 /* ltm.c in Sources */,
				387393E70A9716ED00545E38 /* lapi.c in Sources */,
				387393E90A9716ED00545E38 /* lcode.c in Sources */,
				387393EB0A9716ED00545E38 /* ldebug.c in Sources */,
				387393ED0A9716ED00545E38 /* ldo.c in Sources */,
				387393EF0A9716ED00545E38 /* ldump.c in Sources */,
				387393F00A9716ED00545E38 /* lfunc.c in Sources */,
				387393F20A9716ED00545E38 /* lgc.c in Sources */,
				387393FB0A9716ED00545E38 /* netcom.c in Sources */,
				387394010A97171100545E38 /* nulmodem.c in Sources */,
				387394230A971AC500545E38 /* bsdserial.c in Sources */,
				3873942F0A971B0300545E38 /* tgtimer.c in Sources */,
			);
			runOnlyForDeploymentPostprocessing = 0;
		};
/* End PBXSourcesBuildPhase section */

/* Begin XCBuildConfiguration section */
		1DEB928608733DD80010E9CD /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				COPY_PHASE_STRIP = NO;
				GCC_DYNAMIC_NO_PIC = NO;
				GCC_ENABLE_FIX_AND_CONTINUE = YES;
				GCC_MODEL_TUNING = G5;
				GCC_OPTIMIZATION_LEVEL = 0;
				INSTALL_PATH = "$(HOME)/bin";
				PRODUCT_NAME = nulmodem;
				ZERO_LINK = NO;
			};
			name = Debug;
		};
		1DEB928708733DD80010E9CD /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				ARCHS = (
					ppc,
					i386,
				);
				GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
				GCC_MODEL_TUNING = G5;
				GCC_OPTIMIZATION_LEVEL = 0;
				INSTALL_PATH = "$(HOME)/bin";
				PRODUCT_NAME = nulmodem;
			};
			name = Release;
		};
		1DEB928A08733DD80010E9CD /* Debug */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_WARN_ABOUT_RETURN_TYPE = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				PREBINDING = NO;
			};
			name = Debug;
		};
		1DEB928B08733DD80010E9CD /* Release */ = {
			isa = XCBuildConfiguration;
			buildSettings = {
				GCC_WARN_ABOUT_RETURN_TYPE = YES;
				GCC_WARN_UNUSED_VARIABLE = YES;
				PREBINDING = NO;
			};
			name = Release;
		};
/* End XCBuildConfiguration section */

/* Begin XCConfigurationList section */
		1DEB928508733DD80010E9CD /* Build configuration list for PBXNativeTarget "nulmodem" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				1DEB928608733DD80010E9CD /* Debug */,
				1DEB928708733DD80010E9CD /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
		1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "NULMODEM" */ = {
			isa = XCConfigurationList;
			buildConfigurations = (
				1DEB928A08733DD80010E9CD /* Debug */,
				1DEB928B08733DD80010E9CD /* Release */,
			);
			defaultConfigurationIsVisible = 0;
			defaultConfigurationName = Release;
		};
/* End XCConfigurationList section */
	};
	rootObject = 08FB7793FE84155DC02AAC07 /* Project object */;
}

Added NULMODEM.xcodeproj/project.xcworkspace/contents.xcworkspacedata.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
   version = "1.0">
   <FileRef
      location = "self:NULMODEM.xcodeproj">
   </FileRef>
</Workspace>

Added NULMODEM.xcodeproj/project.xcworkspace/xcuserdata/jim.xcuserdatad/UserInterfaceState.xcuserstate.

cannot compute difference between binary files

Added NULMODEM.xcodeproj/xcuserdata/jim.xcuserdatad/xcschemes/nulmodem.xcscheme.













































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
   version = "1.3">
   <BuildAction
      parallelizeBuildables = "YES"
      buildImplicitDependencies = "YES">
      <BuildActionEntries>
         <BuildActionEntry
            buildForTesting = "YES"
            buildForRunning = "YES"
            buildForProfiling = "YES"
            buildForArchiving = "YES"
            buildForAnalyzing = "YES">
            <BuildableReference
               BuildableIdentifier = "primary"
               BlueprintIdentifier = "8DD76FA90486AB0100D96B5E"
               BuildableName = "nulmodem"
               BlueprintName = "nulmodem"
               ReferencedContainer = "container:NULMODEM.xcodeproj">
            </BuildableReference>
         </BuildActionEntry>
      </BuildActionEntries>
   </BuildAction>
   <TestAction
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
      shouldUseLaunchSchemeArgsEnv = "YES"
      buildConfiguration = "Debug">
      <Testables>
      </Testables>
      <MacroExpansion>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "8DD76FA90486AB0100D96B5E"
            BuildableName = "nulmodem"
            BlueprintName = "nulmodem"
            ReferencedContainer = "container:NULMODEM.xcodeproj">
         </BuildableReference>
      </MacroExpansion>
   </TestAction>
   <LaunchAction
      selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.GDB"
      selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.GDB"
      launchStyle = "0"
      useCustomWorkingDirectory = "NO"
      buildConfiguration = "Debug"
      debugDocumentVersioning = "YES"
      allowLocationSimulation = "YES">
      <BuildableProductRunnable>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "8DD76FA90486AB0100D96B5E"
            BuildableName = "nulmodem"
            BlueprintName = "nulmodem"
            ReferencedContainer = "container:NULMODEM.xcodeproj">
         </BuildableReference>
      </BuildableProductRunnable>
      <CommandLineArguments>
         <CommandLineArgument
            argument = "-v"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-p0 7000 -tcp0 10.1.10.200 -p1 7010 -tcp1 10.1.10.20"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-p0 23 -tcp0 10.1.13.150 -p1 7000"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-p0 7000 -loop -log"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-p0 7000 -p1 7010 -log"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-loop"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-p0 7000 -tcp0 10.1.10.200 -loop"
            isEnabled = "NO">
         </CommandLineArgument>
         <CommandLineArgument
            argument = "-loop -p0 1234"
            isEnabled = "YES">
         </CommandLineArgument>
      </CommandLineArguments>
      <AdditionalOptions>
      </AdditionalOptions>
   </LaunchAction>
   <ProfileAction
      shouldUseLaunchSchemeArgsEnv = "YES"
      savedToolIdentifier = ""
      useCustomWorkingDirectory = "NO"
      buildConfiguration = "Release"
      debugDocumentVersioning = "YES">
      <BuildableProductRunnable>
         <BuildableReference
            BuildableIdentifier = "primary"
            BlueprintIdentifier = "8DD76FA90486AB0100D96B5E"
            BuildableName = "nulmodem"
            BlueprintName = "nulmodem"
            ReferencedContainer = "container:NULMODEM.xcodeproj">
         </BuildableReference>
      </BuildableProductRunnable>
   </ProfileAction>
   <AnalyzeAction
      buildConfiguration = "Debug">
   </AnalyzeAction>
   <ArchiveAction
      buildConfiguration = "Release"
      revealArchiveInOrganizer = "YES">
   </ArchiveAction>
</Scheme>

Added NULMODEM.xcodeproj/xcuserdata/jim.xcuserdatad/xcschemes/xcschememanagement.plist.













































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?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>SchemeUserState</key>
	<dict>
		<key>nulmodem.xcscheme</key>
		<dict>
			<key>orderHint</key>
			<integer>0</integer>
		</dict>
	</dict>
	<key>SuppressBuildableAutocreation</key>
	<dict>
		<key>8DD76FA90486AB0100D96B5E</key>
		<dict>
			<key>primary</key>
			<true/>
		</dict>
	</dict>
</dict>
</plist>

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
//*************************************************************************
/*
    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
*
*		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()	- Get a list of SERIAL RS-232 ports
*
*	INPUT:NONE
*
*	OUTPUT:	Linked list of port data
*			NULL if none
*
*****************************************************************/

PORT_LIST *ListPorts(void)
{
	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( 0,&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 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));
		}
		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);
	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
//*************************************************************************
/*
    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
*
*		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 <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(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/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 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
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
//*************************************************************************
/*
    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 "nulmodem.h"
#include "tgtimer.h"
#include "lua_net.h"

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

static int swrite0 (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->tcp0,ptr,len);
	dval = (double)len;
	lua_pushnumber(L,dval);
	return(1);
}

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

static int swrite1 (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->tcp1,ptr,len);
	dval = (double)len;
	lua_pushnumber(L,dval);
	return(1);
}

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

static int sread0 (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->tcp0,(char *)ptr,len);
	lua_pushlstring(L,ptr,len);
	MEMFREE((char *)ptr);
	return(1);
}

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

static int sread1 (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->tcp1,(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.drop0()   - Drop TCP/IP 0 connection
*
*	INPUT:	NONE
*
*	OUTPUT:	NONE
*			TCP/IP connection dropped
*
**********************************************************************/

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

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

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

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

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

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

static int cstat0 (lua_State *L) 
{
	MY_ENV *env = L->env;
	
	switch(  env->tcp0->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
}

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

static int cstat1 (lua_State *L) 
{
	MY_ENV *env = L->env;
	
	switch(  env->tcp1->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[] = {
  {"swrite0",swrite0},
  {"swrite1",swrite1},
  {"sread0",sread0},
  {"sread1",sread1},
  {"sstat",sstat},
  {"drop0",drop0},
  {"drop1",drop1},
  {"cstat0",cstat0},
  {"cstat1",cstat1},
  {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 "nulmodem.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 "nulmodem.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 build/Debug/nulmodem.

cannot compute difference between binary files

Added build/Release/nulmodem.

cannot compute difference between binary files

Added linuxbuildmake.sh.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
#!/bin/sh
#  Build a the Linux version of the makefile
#  This will set all the parameters needed for a 
#  Linux build

pbtomake -i TERMS.xcodeproj -cc /usr/bin/gcc-3.3 -cc_opt " -DLINUX_VERSION=1 -w  -ggdb" -link_opt "-lm -lpthread" -debug

Added lrhlinuxbuildmake.sh.















>
>
>
>
>
>
>
1
2
3
4
5
6
7
#!/bin/sh
#  Build a the Linux version of the makefile
#  This will set all the parameters needed for a 
#  Linux build

pbtomake -i TERMS.xcodeproj -cc /usr/bin/cc -cc_opt " -DLINUX_VERSION=1 -w  -ggdb" -link_opt "-lm -lpthread" -debug

Added lrhmakefile.

































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
###################################################
#
# Makefile for TERMS
# Creator [PBTOMAKE]
# Created: [Mon Feb 20 16:20:17 2006]
#
###################################################

#
# Macros
#

CC = /usr/bin/cc
CC_OPTIONS =  -DLINUX_VERSION=1 -w  -ggdb
LNK_OPTIONS = -lm -lpthread


#
# INCLUDE directories for TERMS
#

INCLUDE = -I.\
		-ICOMS\
		-ITGLuaLibs\
		-ISERIAL/Linux\
		-Ilua-5.0.2/include\
		-Ilua-5.0.2/src


#
# Build TERMS
#

TERMS : \
		tgtimer.o\
		netcom.o\
		lua_serial.o\
		lua_timer.o\
		lua_net.o\
		linserial.o\
		terms.o\
		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\
		lauxlib.o\
		lbaselib.o\
		ldblib.o\
		liolib.o\
		lmathlib.o\
		loadlib.o\
		lstrlib.o\
		ltablib.o
	$(CC) $(LNK_OPTIONS) \
		tgtimer.o\
		netcom.o\
		lua_serial.o\
		lua_timer.o\
		lua_net.o\
		linserial.o\
		terms.o\
		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\
		lauxlib.o\
		lbaselib.o\
		ldblib.o\
		liolib.o\
		lmathlib.o\
		loadlib.o\
		lstrlib.o\
		ltablib.o\
		-o TERMS

#
# Build the parts of TERMS
#


# Item # 1 -- tgtimer --
tgtimer.o : tgtimer.c
	$(CC) $(CC_OPTIONS) tgtimer.c -c $(INCLUDE) -o tgtimer.o


# Item # 2 -- netcom --
netcom.o : COMS/netcom.c
	$(CC) $(CC_OPTIONS) COMS/netcom.c -c $(INCLUDE) -o netcom.o


# Item # 3 -- lua_serial --
lua_serial.o : TGLuaLibs/lua_serial.c
	$(CC) $(CC_OPTIONS) TGLuaLibs/lua_serial.c -c $(INCLUDE) -o lua_serial.o


# Item # 4 -- lua_timer --
lua_timer.o : TGLuaLibs/lua_timer.c
	$(CC) $(CC_OPTIONS) TGLuaLibs/lua_timer.c -c $(INCLUDE) -o lua_timer.o


# Item # 5 -- lua_net --
lua_net.o : TGLuaLibs/lua_net.c
	$(CC) $(CC_OPTIONS) TGLuaLibs/lua_net.c -c $(INCLUDE) -o lua_net.o


# Item # 6 -- linserial --
linserial.o : SERIAL/Linux/linserial.c
	$(CC) $(CC_OPTIONS) SERIAL/Linux/linserial.c -c $(INCLUDE) -o linserial.o


# Item # 7 -- terms --
terms.o : terms.c
	$(CC) $(CC_OPTIONS) terms.c -c $(INCLUDE) -o terms.o


# Item # 8 -- lapi --
lapi.o : lua-5.0.2/src/lapi.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lapi.c -c $(INCLUDE) -o lapi.o


# Item # 9 -- lcode --
lcode.o : lua-5.0.2/src/lcode.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lcode.c -c $(INCLUDE) -o lcode.o


# Item # 10 -- ldebug --
ldebug.o : lua-5.0.2/src/ldebug.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/ldebug.c -c $(INCLUDE) -o ldebug.o


# Item # 11 -- ldo --
ldo.o : lua-5.0.2/src/ldo.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/ldo.c -c $(INCLUDE) -o ldo.o


# Item # 12 -- ldump --
ldump.o : lua-5.0.2/src/ldump.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/ldump.c -c $(INCLUDE) -o ldump.o


# Item # 13 -- lfunc --
lfunc.o : lua-5.0.2/src/lfunc.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lfunc.c -c $(INCLUDE) -o lfunc.o


# Item # 14 -- lgc --
lgc.o : lua-5.0.2/src/lgc.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lgc.c -c $(INCLUDE) -o lgc.o


# Item # 15 -- llex --
llex.o : lua-5.0.2/src/llex.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/llex.c -c $(INCLUDE) -o llex.o


# Item # 16 -- lmem --
lmem.o : lua-5.0.2/src/lmem.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lmem.c -c $(INCLUDE) -o lmem.o


# Item # 17 -- lobject --
lobject.o : lua-5.0.2/src/lobject.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lobject.c -c $(INCLUDE) -o lobject.o


# Item # 18 -- lopcodes --
lopcodes.o : lua-5.0.2/src/lopcodes.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lopcodes.c -c $(INCLUDE) -o lopcodes.o


# Item # 19 -- lparser --
lparser.o : lua-5.0.2/src/lparser.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lparser.c -c $(INCLUDE) -o lparser.o


# Item # 20 -- lstate --
lstate.o : lua-5.0.2/src/lstate.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lstate.c -c $(INCLUDE) -o lstate.o


# Item # 21 -- lstring --
lstring.o : lua-5.0.2/src/lstring.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lstring.c -c $(INCLUDE) -o lstring.o


# Item # 22 -- ltable --
ltable.o : lua-5.0.2/src/ltable.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/ltable.c -c $(INCLUDE) -o ltable.o


# Item # 23 -- ltests --
ltests.o : lua-5.0.2/src/ltests.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/ltests.c -c $(INCLUDE) -o ltests.o


# Item # 24 -- ltm --
ltm.o : lua-5.0.2/src/ltm.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/ltm.c -c $(INCLUDE) -o ltm.o


# Item # 25 -- lundump --
lundump.o : lua-5.0.2/src/lundump.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lundump.c -c $(INCLUDE) -o lundump.o


# Item # 26 -- lvm --
lvm.o : lua-5.0.2/src/lvm.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lvm.c -c $(INCLUDE) -o lvm.o


# Item # 27 -- lzio --
lzio.o : lua-5.0.2/src/lzio.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lzio.c -c $(INCLUDE) -o lzio.o


# Item # 28 -- lauxlib --
lauxlib.o : lua-5.0.2/src/lib/lauxlib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/lauxlib.c -c $(INCLUDE) -o lauxlib.o


# Item # 29 -- lbaselib --
lbaselib.o : lua-5.0.2/src/lib/lbaselib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/lbaselib.c -c $(INCLUDE) -o lbaselib.o


# Item # 30 -- ldblib --
ldblib.o : lua-5.0.2/src/lib/ldblib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/ldblib.c -c $(INCLUDE) -o ldblib.o


# Item # 31 -- liolib --
liolib.o : lua-5.0.2/src/lib/liolib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/liolib.c -c $(INCLUDE) -o liolib.o


# Item # 32 -- lmathlib --
lmathlib.o : lua-5.0.2/src/lib/lmathlib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/lmathlib.c -c $(INCLUDE) -o lmathlib.o


# Item # 33 -- loadlib --
loadlib.o : lua-5.0.2/src/lib/loadlib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/loadlib.c -c $(INCLUDE) -o loadlib.o


# Item # 34 -- lstrlib --
lstrlib.o : lua-5.0.2/src/lib/lstrlib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/lstrlib.c -c $(INCLUDE) -o lstrlib.o


# Item # 35 -- ltablib --
ltablib.o : lua-5.0.2/src/lib/ltablib.c
	$(CC) $(CC_OPTIONS) lua-5.0.2/src/lib/ltablib.c -c $(INCLUDE) -o ltablib.o


##### END RUN ####

Added lship.sh.























>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
#!/bin/sh
#  Build a copy of this with correct line endings
# Put on my desktop after zipping it.
# To unwrap on the other end
# gzip -d TERMS.tar.gz      -> Makes TERMS.tar
# tar -xvf TERMS.tar        -> Build TERMS directory
#

cd /Users/jim/Desktop
lfconvert -i /Users/jschimpf/Public/TSANIXII/TOOLS/TERMS -o TERMS
tar -c -v TERMS | gzip > TERMS.tar.gz

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 */
    L->base = L->ci->base;
    L->nCcalls = 0;
    luaF_close(L, L->base);  /* close eventual pending closures */
    seterrorobj(L, status, L->base);
    L->allowhook = old_allowhooks;
    restore_stack_limit(L);
  }
  lua_unlock(L);
  return status;
}


LUA_API int lua_yield (lua_State *L, int nresults) {
  CallInfo *ci;
  lua_lock(L);
  ci = L->ci;
  if (L->nCcalls > 0)
    luaG_runerror(L, "attempt to yield across metamethod/C-call boundary");
  if (ci->state & CI_C) {  /* usual yield */
    if ((ci-1)->state & CI_C)
      luaG_runerror(L, "cannot yield a C function");
    if (L->top - nresults > L->base) {  /* is there garbage in the stack? */
      int i;
      for (i=0; i<nresults; i++)  /* move down results */
        setobjs2s(L->base + i, L->top - nresults + i);
      L->top = L->base + nresults;
    }
  } /* else it's an yield inside a hook: nothing to do */
  ci->state |= CI_YIELD;
  lua_unlock(L);
  return -1;
}


int luaD_pcall (lua_State *L, Pfunc func, void *u,
                ptrdiff_t old_top, ptrdiff_t ef) {
  int status;
  unsigned short oldnCcalls = L->nCcalls;
  ptrdiff_t old_ci = saveci(L, L->ci);
  lu_byte old_allowhooks = L->allowhook;
  ptrdiff_t old_errfunc = L->errfunc;
  L->errfunc = ef;
  status = luaD_rawrunprotected(L, func, u);
  if (status != 0) {  /* an error occurred? */
    StkId oldtop = restorestack(L, old_top);
    luaF_close(L, oldtop);  /* close eventual pending closures */
    seterrorobj(L, status, oldtop);
    L->nCcalls = oldnCcalls;
    L->ci = restoreci(L, old_ci);
    L->base = L->ci->base;
    L->allowhook = old_allowhooks;
    restore_stack_limit(L);
  }
  L->errfunc = old_errfunc;
  return status;
}



/*
** Execute a protected parser.
*/
struct SParser {  /* data to `f_parser' */
  ZIO *z;
  Mbuffer buff;  /* buffer to be used by the scanner */
  int bin;
};

static void f_parser (lua_State *L, void *ud) {
  struct SParser *p;
  Proto *tf;
  Closure *cl;
  luaC_checkGC(L);
  p = cast(struct SParser *, ud);
  tf = p->bin ? luaU_undump(L, p->z, &p->buff) : luaY_parser(L, p->z, &p->buff);
  cl = luaF_newLclosure(L, 0, gt(L));
  cl->l.p = tf;
  setclvalue(L->top, cl);
  incr_top(L);
}


int luaD_protectedparser (lua_State *L, ZIO *z, int bin) {
  struct SParser p;
  int status;
  ptrdiff_t oldtopr = savestack(L, L->top);  /* save current top */
  p.z = z; p.bin = bin;
  luaZ_initbuffer(L, &p.buff);
  status = luaD_rawrunprotected(L, f_parser, &p);
  luaZ_freebuffer(L, &p.buff);
  if (status != 0) {  /* error? */
    StkId oldtop = restorestack(L, oldtopr);
    seterrorobj(L, status, oldtop);
  }
  return status;
}


Added lua-5.0.2/src/ldo.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
/*
** $Id: ldo.h,v 1.56 2002/12/04 17:29:32 roberto Exp $
** Stack and Call structure of Lua
** See Copyright Notice in lua.h
*/

#ifndef ldo_h
#define ldo_h


#include "lobject.h"
#include "lstate.h"
#include "lzio.h"


/*
** macro to control inclusion of some hard tests on stack reallocation
*/ 
#ifndef HARDSTACKTESTS
#define condhardstacktests(x)	{ /* empty */ }
#else
#define condhardstacktests(x)	x
#endif


#define luaD_checkstack(L,n)	\
  if ((char *)L->stack_last - (char *)L->top <= (n)*(int)sizeof(TObject)) \
    luaD_growstack(L, n); \
  else condhardstacktests(luaD_reallocstack(L, L->stacksize));


#define incr_top(L) {luaD_checkstack(L,1); L->top++;}

#define savestack(L,p)		((char *)(p) - (char *)L->stack)
#define restorestack(L,n)	((TObject *)((char *)L->stack + (n)))

#define saveci(L,p)		((char *)(p) - (char *)L->base_ci)
#define restoreci(L,n)		((CallInfo *)((char *)L->base_ci + (n)))


/* type of protected functions, to be ran by `runprotected' */
typedef void (*Pfunc) (lua_State *L, void *ud);

void luaD_resetprotection (lua_State *L);
int luaD_protectedparser (lua_State *L, ZIO *z, int bin);
void luaD_callhook (lua_State *L, int event, int line);
StkId luaD_precall (lua_State *L, StkId func);
void luaD_call (lua_State *L, StkId func, int nResults);
int luaD_pcall (lua_State *L, Pfunc func, void *u,
                ptrdiff_t oldtop, ptrdiff_t ef);
void luaD_poscall (lua_State *L, int wanted, StkId firstResult);
void luaD_reallocCI (lua_State *L, int newsize);
void luaD_reallocstack (lua_State *L, int newsize);
void luaD_growstack (lua_State *L, int n);

void luaD_throw (lua_State *L, int errcode);
int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);


#endif

Added lua-5.0.2/src/ldump.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
/*
** $Id: ldump.c,v 1.4 2003/02/11 23:52:12 lhf Exp $
** save bytecodes
** See Copyright Notice in lua.h
*/

#include <stddef.h>

#define ldump_c

#include "lua.h"

#include "lobject.h"
#include "lopcodes.h"
#include "lstate.h"
#include "lundump.h"

#define DumpVector(b,n,size,D)	DumpBlock(b,(n)*(size),D)
#define DumpLiteral(s,D)	DumpBlock("" s,(sizeof(s))-1,D)

typedef struct {
 lua_State* L;
 lua_Chunkwriter write;
 void* data;
} DumpState;

static void DumpBlock(const void* b, size_t size, DumpState* D)
{
 lua_unlock(D->L);
 (*D->write)(D->L,b,size,D->data);
 lua_lock(D->L);
}

static void DumpByte(int y, DumpState* D)
{
 char x=(char)y;
 DumpBlock(&x,sizeof(x),D);
}

static void DumpInt(int x, DumpState* D)
{
 DumpBlock(&x,sizeof(x),D);
}

static void DumpSize(size_t x, DumpState* D)
{
 DumpBlock(&x,sizeof(x),D);
}

static void DumpNumber(lua_Number x, DumpState* D)
{
 DumpBlock(&x,sizeof(x),D);
}

static void DumpString(TString* s, DumpState* D)
{
 if (s==NULL || getstr(s)==NULL)
  DumpSize(0,D);
 else
 {
  size_t size=s->tsv.len+1;		/* include trailing '\0' */
  DumpSize(size,D);
  DumpBlock(getstr(s),size,D);
 }
}

static void DumpCode(const Proto* f, DumpState* D)
{
 DumpInt(f->sizecode,D);
 DumpVector(f->code,f->sizecode,sizeof(*f->code),D);
}

static void DumpLocals(const Proto* f, DumpState* D)
{
 int i,n=f->sizelocvars;
 DumpInt(n,D);
 for (i=0; i<n; i++)
 {
  DumpString(f->locvars[i].varname,D);
  DumpInt(f->locvars[i].startpc,D);
  DumpInt(f->locvars[i].endpc,D);
 }
}

static void DumpLines(const Proto* f, DumpState* D)
{
 DumpInt(f->sizelineinfo,D);
 DumpVector(f->lineinfo,f->sizelineinfo,sizeof(*f->lineinfo),D);
}

static void DumpUpvalues(const Proto* f, DumpState* D)
{
 int i,n=f->sizeupvalues;
 DumpInt(n,D);
 for (i=0; i<n; i++) DumpString(f->upvalues[i],D);
}

static void DumpFunction(const Proto* f, const TString* p, DumpState* D);

static void DumpConstants(const Proto* f, DumpState* D)
{
 int i,n;
 DumpInt(n=f->sizek,D);
 for (i=0; i<n; i++)
 {
  const TObject* o=&f->k[i];
  DumpByte(ttype(o),D);
  switch (ttype(o))
  {
   case LUA_TNUMBER:
	DumpNumber(nvalue(o),D);
	break;
   case LUA_TSTRING:
	DumpString(tsvalue(o),D);
	break;
   case LUA_TNIL:
	break;
   default:
	lua_assert(0);			/* cannot happen */
	break;
  }
 }
 DumpInt(n=f->sizep,D);
 for (i=0; i<n; i++) DumpFunction(f->p[i],f->source,D);
}

static void DumpFunction(const Proto* f, const TString* p, DumpState* D)
{
 DumpString((f->source==p) ? NULL : f->source,D);
 DumpInt(f->lineDefined,D);
 DumpByte(f->nups,D);
 DumpByte(f->numparams,D);
 DumpByte(f->is_vararg,D);
 DumpByte(f->maxstacksize,D);
 DumpLines(f,D);
 DumpLocals(f,D);
 DumpUpvalues(f,D);
 DumpConstants(f,D);
 DumpCode(f,D);
}

static void DumpHeader(DumpState* D)
{
 DumpLiteral(LUA_SIGNATURE,D);
 DumpByte(VERSION,D);
 DumpByte(luaU_endianness(),D);
 DumpByte(sizeof(int),D);
 DumpByte(sizeof(size_t),D);
 DumpByte(sizeof(Instruction),D);
 DumpByte(SIZE_OP,D);
 DumpByte(SIZE_A,D);
 DumpByte(SIZE_B,D);
 DumpByte(SIZE_C,D);
 DumpByte(sizeof(lua_Number),D);
 DumpNumber(TEST_NUMBER,D);
}

/*
** dump function as precompiled chunk
*/
void luaU_dump (lua_State* L, const Proto* Main, lua_Chunkwriter w, void* data)
{
 DumpState D;
 D.L=L;
 D.write=w;
 D.data=data;
 DumpHeader(&D);
 DumpFunction(Main,NULL,&D);
}

Added lua-5.0.2/src/lfunc.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
/*
** $Id: lfunc.c,v 1.67 2003/03/18 12:50:04 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/


#include <stdlib.h>

#define lfunc_c

#include "lua.h"

#include "lfunc.h"
#include "lgc.h"
#include "lmem.h"
#include "lobject.h"
#include "lstate.h"


#define sizeCclosure(n)	(cast(int, sizeof(CClosure)) + \
                         cast(int, sizeof(TObject)*((n)-1)))

#define sizeLclosure(n)	(cast(int, sizeof(LClosure)) + \
                         cast(int, sizeof(TObject *)*((n)-1)))



Closure *luaF_newCclosure (lua_State *L, int nelems) {
  Closure *c = cast(Closure *, luaM_malloc(L, sizeCclosure(nelems)));
  luaC_link(L, valtogco(c), LUA_TFUNCTION);
  c->c.isC = 1;
  c->c.nupvalues = cast(lu_byte, nelems);
  return c;
}


Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e) {
  Closure *c = cast(Closure *, luaM_malloc(L, sizeLclosure(nelems)));
  luaC_link(L, valtogco(c), LUA_TFUNCTION);
  c->l.isC = 0;
  c->l.g = *e;
  c->l.nupvalues = cast(lu_byte, nelems);
  return c;
}


UpVal *luaF_findupval (lua_State *L, StkId level) {
  GCObject **pp = &L->openupval;
  UpVal *p;
  UpVal *v;
  while ((p = ngcotouv(*pp)) != NULL && p->v >= level) {
    if (p->v == level) return p;
    pp = &p->next;
  }
  v = luaM_new(L, UpVal);  /* not found: create a new one */
  v->tt = LUA_TUPVAL;
  v->marked = 1;  /* open upvalues should not be collected */
  v->v = level;  /* current value lives in the stack */
  v->next = *pp;  /* chain it in the proper position */
  *pp = valtogco(v);
  return v;
}


void luaF_close (lua_State *L, StkId level) {
  UpVal *p;
  while ((p = ngcotouv(L->openupval)) != NULL && p->v >= level) {
    setobj(&p->value, p->v);  /* save current value (write barrier) */
    p->v = &p->value;  /* now current value lives here */
    L->openupval = p->next;  /* remove from `open' list */
    luaC_link(L, valtogco(p), LUA_TUPVAL);
  }
}


Proto *luaF_newproto (lua_State *L) {
  Proto *f = luaM_new(L, Proto);
  luaC_link(L, valtogco(f), LUA_TPROTO);
  f->k = NULL;
  f->sizek = 0;
  f->p = NULL;
  f->sizep = 0;
  f->code = NULL;
  f->sizecode = 0;
  f->sizelineinfo = 0;
  f->sizeupvalues = 0;
  f->nups = 0;
  f->upvalues = NULL;
  f->numparams = 0;
  f->is_vararg = 0;
  f->maxstacksize = 0;
  f->lineinfo = NULL;
  f->sizelocvars = 0;
  f->locvars = NULL;
  f->lineDefined = 0;
  f->source = NULL;
  return f;
}


void luaF_freeproto (lua_State *L, Proto *f) {
  luaM_freearray(L, f->code, f->sizecode, Instruction);
  luaM_freearray(L, f->p, f->sizep, Proto *);
  luaM_freearray(L, f->k, f->sizek, TObject);
  luaM_freearray(L, f->lineinfo, f->sizelineinfo, int);
  luaM_freearray(L, f->locvars, f->sizelocvars, struct LocVar);
  luaM_freearray(L, f->upvalues, f->sizeupvalues, TString *);
  luaM_freelem(L, f);
}


void luaF_freeclosure (lua_State *L, Closure *c) {
  int size = (c->c.isC) ? sizeCclosure(c->c.nupvalues) :
                          sizeLclosure(c->l.nupvalues);
  luaM_free(L, c, size);
}


/*
** Look for n-th local variable at line `line' in function `func'.
** Returns NULL if not found.
*/
const char *luaF_getlocalname (const Proto *f, int local_number, int pc) {
  int i;
  for (i = 0; i<f->sizelocvars && f->locvars[i].startpc <= pc; i++) {
    if (pc < f->locvars[i].endpc) {  /* is variable active? */
      local_number--;
      if (local_number == 0)
        return getstr(f->locvars[i].varname);
    }
  }
  return NULL;  /* not found */
}

Added lua-5.0.2/src/lfunc.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
/*
** $Id: lfunc.h,v 1.21 2003/03/18 12:50:04 roberto Exp $
** Auxiliary functions to manipulate prototypes and closures
** See Copyright Notice in lua.h
*/

#ifndef lfunc_h
#define lfunc_h


#include "lobject.h"


Proto *luaF_newproto (lua_State *L);
Closure *luaF_newCclosure (lua_State *L, int nelems);
Closure *luaF_newLclosure (lua_State *L, int nelems, TObject *e);
UpVal *luaF_findupval (lua_State *L, StkId level);
void luaF_close (lua_State *L, StkId level);
void luaF_freeproto (lua_State *L, Proto *f);
void luaF_freeclosure (lua_State *L, Closure *c);

const char *luaF_getlocalname (const Proto *func, int local_number, int pc);


#endif

Added lua-5.0.2/src/lgc.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
/*
** $Id: lgc.c,v 1.171a 2003/04/03 13:35:34 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/

#include <string.h>

#define lgc_c

#include "lua.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"


typedef struct GCState {
  GCObject *tmark;  /* list of marked objects to be traversed */
  GCObject *wk;  /* list of traversed key-weak tables (to be cleared) */
  GCObject *wv;  /* list of traversed value-weak tables */
  GCObject *wkv;  /* list of traversed key-value weak tables */
  global_State *g;
} GCState;


/*
** some userful bit tricks
*/
#define setbit(x,b)	((x) |= (1<<(b)))
#define resetbit(x,b)	((x) &= cast(lu_byte, ~(1<<(b))))
#define testbit(x,b)	((x) & (1<<(b)))

#define unmark(x)	resetbit((x)->gch.marked, 0)
#define ismarked(x)	((x)->gch.marked & ((1<<4)|1))

#define stringmark(s)	setbit((s)->tsv.marked, 0)


#define isfinalized(u)		(!testbit((u)->uv.marked, 1))
#define markfinalized(u)	resetbit((u)->uv.marked, 1)


#define KEYWEAKBIT    1
#define VALUEWEAKBIT  2
#define KEYWEAK         (1<<KEYWEAKBIT)
#define VALUEWEAK       (1<<VALUEWEAKBIT)



#define markobject(st,o) { checkconsistency(o); \
  if (iscollectable(o) && !ismarked(gcvalue(o))) reallymarkobject(st,gcvalue(o)); }

#define condmarkobject(st,o,c) { checkconsistency(o); \
  if (iscollectable(o) && !ismarked(gcvalue(o)) && (c)) \
    reallymarkobject(st,gcvalue(o)); }

#define markvalue(st,t) { if (!ismarked(valtogco(t))) \
		reallymarkobject(st, valtogco(t)); }



static void reallymarkobject (GCState *st, GCObject *o) {
  lua_assert(!ismarked(o));
  setbit(o->gch.marked, 0);  /* mark object */
  switch (o->gch.tt) {
    case LUA_TUSERDATA: {
      markvalue(st, gcotou(o)->uv.metatable);
      break;
    }
    case LUA_TFUNCTION: {
      gcotocl(o)->c.gclist = st->tmark;
      st->tmark = o;
      break;
    }
    case LUA_TTABLE: {
      gcotoh(o)->gclist = st->tmark;
      st->tmark = o;
      break;
    }
    case LUA_TTHREAD: {
      gcototh(o)->gclist = st->tmark;
      st->tmark = o;
      break;
    }
    case LUA_TPROTO: {
      gcotop(o)->gclist = st->tmark;
      st->tmark = o;
      break;
    }
    default: lua_assert(o->gch.tt == LUA_TSTRING);
  }
}


static void marktmu (GCState *st) {
  GCObject *u;
  for (u = st->g->tmudata; u; u = u->gch.next) {
    unmark(u);  /* may be marked, if left from previous GC */
    reallymarkobject(st, u);
  }
}


/* move `dead' udata that need finalization to list `tmudata' */
size_t luaC_separateudata (lua_State *L) {
  size_t deadmem = 0;
  GCObject **p = &G(L)->rootudata;
  GCObject *curr;
  GCObject *collected = NULL;  /* to collect udata with gc event */
  GCObject **lastcollected = &collected;
  while ((curr = *p) != NULL) {
    lua_assert(curr->gch.tt == LUA_TUSERDATA);
    if (ismarked(curr) || isfinalized(gcotou(curr)))
      p = &curr->gch.next;  /* don't bother with them */

    else if (fasttm(L, gcotou(curr)->uv.metatable, TM_GC) == NULL) {
      markfinalized(gcotou(curr));  /* don't need finalization */
      p = &curr->gch.next;
    }
    else {  /* must call its gc method */
      deadmem += sizeudata(gcotou(curr)->uv.len);
      *p = curr->gch.next;
      curr->gch.next = NULL;  /* link `curr' at the end of `collected' list */
      *lastcollected = curr;
      lastcollected = &curr->gch.next;
    }
  }
  /* insert collected udata with gc event into `tmudata' list */
  *lastcollected = G(L)->tmudata;
  G(L)->tmudata = collected;
  return deadmem;
}


static void removekey (Node *n) {
  setnilvalue(gval(n));  /* remove corresponding value ... */
  if (iscollectable(gkey(n)))
    setttype(gkey(n), LUA_TNONE);  /* dead key; remove it */
}


static void traversetable (GCState *st, Table *h) {
  int i;
  int weakkey = 0;
  int weakvalue = 0;
  const TObject *mode;
  markvalue(st, h->metatable);
  lua_assert(h->lsizenode || h->node == st->g->dummynode);
  mode = gfasttm(st->g, h->metatable, TM_MODE);
  if (mode && ttisstring(mode)) {  /* is there a weak mode? */
    weakkey = (strchr(svalue(mode), 'k') != NULL);
    weakvalue = (strchr(svalue(mode), 'v') != NULL);
    if (weakkey || weakvalue) {  /* is really weak? */
      GCObject **weaklist;
      h->marked &= ~(KEYWEAK | VALUEWEAK);  /* clear bits */
      h->marked |= cast(lu_byte, (weakkey << KEYWEAKBIT) |
                                 (weakvalue << VALUEWEAKBIT));
      weaklist = (weakkey && weakvalue) ? &st->wkv :
                              (weakkey) ? &st->wk :
                                          &st->wv;
      h->gclist = *weaklist;  /* must be cleared after GC, ... */
      *weaklist = valtogco(h);  /* ... so put in the appropriate list */
    }
  }
  if (!weakvalue) {
    i = h->sizearray;
    while (i--)
      markobject(st, &h->array[i]);
  }
  i = sizenode(h);
  while (i--) {
    Node *n = gnode(h, i);
    if (!ttisnil(gval(n))) {
      lua_assert(!ttisnil(gkey(n)));
      condmarkobject(st, gkey(n), !weakkey);
      condmarkobject(st, gval(n), !weakvalue);
    }
  }
}


static void traverseproto (GCState *st, Proto *f) {
  int i;
  stringmark(f->source);
  for (i=0; i<f->sizek; i++) {  /* mark literal strings */
    if (ttisstring(f->k+i))
      stringmark(tsvalue(f->k+i));
  }
  for (i=0; i<f->sizeupvalues; i++)  /* mark upvalue names */
    stringmark(f->upvalues[i]);
  for (i=0; i<f->sizep; i++)  /* mark nested protos */
    markvalue(st, f->p[i]);
  for (i=0; i<f->sizelocvars; i++)  /* mark local-variable names */
    stringmark(f->locvars[i].varname);
  lua_assert(luaG_checkcode(f));
}



static void traverseclosure (GCState *st, Closure *cl) {
  if (cl->c.isC) {
    int i;
    for (i=0; i<cl->c.nupvalues; i++)  /* mark its upvalues */
      markobject(st, &cl->c.upvalue[i]);
  }
  else {
    int i;
    lua_assert(cl->l.nupvalues == cl->l.p->nups);
    markvalue(st, hvalue(&cl->l.g));
    markvalue(st, cl->l.p);
    for (i=0; i<cl->l.nupvalues; i++) {  /* mark its upvalues */
      UpVal *u = cl->l.upvals[i];
      if (!u->marked) {
        markobject(st, &u->value);
        u->marked = 1;
      }
    }
  }
}


static void checkstacksizes (lua_State *L, StkId max) {
  int used = L->ci - L->base_ci;  /* number of `ci' in use */
  if (4*used < L->size_ci && 2*BASIC_CI_SIZE < L->size_ci)
    luaD_reallocCI(L, L->size_ci/2);  /* still big enough... */
  else condhardstacktests(luaD_reallocCI(L, L->size_ci));
  used = max - L->stack;  /* part of stack in use */
  if (4*used < L->stacksize && 2*(BASIC_STACK_SIZE+EXTRA_STACK) < L->stacksize)
    luaD_reallocstack(L, L->stacksize/2);  /* still big enough... */
  else condhardstacktests(luaD_reallocstack(L, L->stacksize));
}


static void traversestack (GCState *st, lua_State *L1) {
  StkId o, lim;
  CallInfo *ci;
  markobject(st, gt(L1));
  lim = L1->top;
  for (ci = L1->base_ci; ci <= L1->ci; ci++) {
    lua_assert(ci->top <= L1->stack_last);
    lua_assert(ci->state & (CI_C | CI_HASFRAME | CI_SAVEDPC));
    if (lim < ci->top)
      lim = ci->top;
  }
  for (o = L1->stack; o < L1->top; o++)
    markobject(st, o);
  for (; o <= lim; o++)
    setnilvalue(o);
  checkstacksizes(L1, lim);
}


static void propagatemarks (GCState *st) {
  while (st->tmark) {  /* traverse marked objects */
    switch (st->tmark->gch.tt) {
      case LUA_TTABLE: {
        Table *h = gcotoh(st->tmark);
        st->tmark = h->gclist;
        traversetable(st, h);
        break;
      }
      case LUA_TFUNCTION: {
        Closure *cl = gcotocl(st->tmark);
        st->tmark = cl->c.gclist;
        traverseclosure(st, cl);
        break;
      }
      case LUA_TTHREAD: {
        lua_State *th = gcototh(st->tmark);
        st->tmark = th->gclist;
        traversestack(st, th);
        break;
      }
      case LUA_TPROTO: {
        Proto *p = gcotop(st->tmark);
        st->tmark = p->gclist;
        traverseproto(st, p);
        break;
      }
      default: lua_assert(0);
    }
  }
}


static int valismarked (const TObject *o) {
  if (ttisstring(o))
    stringmark(tsvalue(o));  /* strings are `values', so are never weak */
  return !iscollectable(o) || testbit(o->value.gc->gch.marked, 0);
}


/*
** clear collected keys from weaktables
*/
static void cleartablekeys (GCObject *l) {
  while (l) {
    Table *h = gcotoh(l);
    int i = sizenode(h);
    lua_assert(h->marked & KEYWEAK);
    while (i--) {
      Node *n = gnode(h, i);
      if (!valismarked(gkey(n)))  /* key was collected? */
        removekey(n);  /* remove entry from table */
    }
    l = h->gclist;
  }
}


/*
** clear collected values from weaktables
*/
static void cleartablevalues (GCObject *l) {
  while (l) {
    Table *h = gcotoh(l);
    int i = h->sizearray;
    lua_assert(h->marked & VALUEWEAK);
    while (i--) {
      TObject *o = &h->array[i];
      if (!valismarked(o))  /* value was collected? */
        setnilvalue(o);  /* remove value */
    }
    i = sizenode(h);
    while (i--) {
      Node *n = gnode(h, i);
      if (!valismarked(gval(n)))  /* value was collected? */
        removekey(n);  /* remove entry from table */
    }
    l = h->gclist;
  }
}


static void freeobj (lua_State *L, GCObject *o) {
  switch (o->gch.tt) {
    case LUA_TPROTO: luaF_freeproto(L, gcotop(o)); break;
    case LUA_TFUNCTION: luaF_freeclosure(L, gcotocl(o)); break;
    case LUA_TUPVAL: luaM_freelem(L, gcotouv(o)); break;
    case LUA_TTABLE: luaH_free(L, gcotoh(o)); break;
    case LUA_TTHREAD: {
      lua_assert(gcototh(o) != L && gcototh(o) != G(L)->mainthread);
      luaE_freethread(L, gcototh(o));
      break;
    }
    case LUA_TSTRING: {
      luaM_free(L, o, sizestring(gcotots(o)->tsv.len));
      break;
    }
    case LUA_TUSERDATA: {
      luaM_free(L, o, sizeudata(gcotou(o)->uv.len));
      break;
    }
    default: lua_assert(0);
  }
}


static int sweeplist (lua_State *L, GCObject **p, int limit) {
  GCObject *curr;
  int count = 0;  /* number of collected items */
  while ((curr = *p) != NULL) {
    if (curr->gch.marked > limit) {
      unmark(curr);
      p = &curr->gch.next;
    }
    else {
      count++;
      *p = curr->gch.next;
      freeobj(L, curr);
    }
  }
  return count;
}


static void sweepstrings (lua_State *L, int all) {
  int i;
  for (i=0; i<G(L)->strt.size; i++) {  /* for each list */
    G(L)->strt.nuse -= sweeplist(L, &G(L)->strt.hash[i], all);
  }
}


static void checkSizes (lua_State *L, size_t deadmem) {
  /* check size of string hash */
  if (G(L)->strt.nuse < cast(ls_nstr, G(L)->strt.size/4) &&
      G(L)->strt.size > MINSTRTABSIZE*2)
    luaS_resize(L, G(L)->strt.size/2);  /* table is too big */
  /* check size of buffer */
  if (luaZ_sizebuffer(&G(L)->buff) > LUA_MINBUFFER*2) {  /* buffer too big? */
    size_t newsize = luaZ_sizebuffer(&G(L)->buff) / 2;
    luaZ_resizebuffer(L, &G(L)->buff, newsize);
  }
  G(L)->GCthreshold = 2*G(L)->nblocks - deadmem;  /* new threshold */
}


static void do1gcTM (lua_State *L, Udata *udata) {
  const TObject *tm = fasttm(L, udata->uv.metatable, TM_GC);
  if (tm != NULL) {
    setobj2s(L->top, tm);
    setuvalue(L->top+1, udata);
    L->top += 2;
    luaD_call(L, L->top - 2, 0);
  }
}


void luaC_callGCTM (lua_State *L) {
  lu_byte oldah = L->allowhook;
  L->allowhook = 0;  /* stop debug hooks during GC tag methods */
  L->top++;  /* reserve space to keep udata while runs its gc method */
  while (G(L)->tmudata != NULL) {
    GCObject *o = G(L)->tmudata;
    Udata *udata = gcotou(o);
    G(L)->tmudata = udata->uv.next;  /* remove udata from `tmudata' */
    udata->uv.next = G(L)->rootudata;  /* return it to `root' list */
    G(L)->rootudata = o;
    setuvalue(L->top - 1, udata);  /* keep a reference to it */
    unmark(o);
    markfinalized(udata);
    do1gcTM(L, udata);
  }
  L->top--;
  L->allowhook = oldah;  /* restore hooks */
}


void luaC_sweep (lua_State *L, int all) {
  if (all) all = 256;  /* larger than any mark */
  sweeplist(L, &G(L)->rootudata, all);
  sweepstrings(L, all);
  sweeplist(L, &G(L)->rootgc, all);
}


/* mark root set */
static void markroot (GCState *st, lua_State *L) {
  global_State *g = st->g;
  markobject(st, defaultmeta(L));
  markobject(st, registry(L));
  traversestack(st, g->mainthread);
  if (L != g->mainthread)  /* another thread is running? */
    markvalue(st, L);  /* cannot collect it */
}


static size_t mark (lua_State *L) {
  size_t deadmem;
  GCState st;
  GCObject *wkv;
  st.g = G(L);
  st.tmark = NULL;
  st.wkv = st.wk = st.wv = NULL;
  markroot(&st, L);
  propagatemarks(&st);  /* mark all reachable objects */
  cleartablevalues(st.wkv);
  cleartablevalues(st.wv);
  wkv = st.wkv;  /* keys must be cleared after preserving udata */
  st.wkv = NULL;
  st.wv = NULL;
  deadmem = luaC_separateudata(L);  /* separate userdata to be preserved */
  marktmu(&st);  /* mark `preserved' userdata */
  propagatemarks(&st);  /* remark, to propagate `preserveness' */
  cleartablekeys(wkv);
  /* `propagatemarks' may resuscitate some weak tables; clear them too */
  cleartablekeys(st.wk);
  cleartablevalues(st.wv);
  cleartablekeys(st.wkv);
  cleartablevalues(st.wkv);
  return deadmem;
}


void luaC_collectgarbage (lua_State *L) {
  size_t deadmem = mark(L);
  luaC_sweep(L, 0);
  checkSizes(L, deadmem);
  luaC_callGCTM(L);
}


void luaC_link (lua_State *L, GCObject *o, lu_byte tt) {
  o->gch.next = G(L)->rootgc;
  G(L)->rootgc = o;
  o->gch.marked = 0;
  o->gch.tt = tt;
}

Added lua-5.0.2/src/lgc.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
/*
** $Id: lgc.h,v 1.19a 2003/02/28 19:45:15 roberto Exp $
** Garbage Collector
** See Copyright Notice in lua.h
*/

#ifndef lgc_h
#define lgc_h


#include "lobject.h"


#define luaC_checkGC(L) { lua_assert(!(L->ci->state & CI_CALLING)); \
	if (G(L)->nblocks >= G(L)->GCthreshold) luaC_collectgarbage(L); }


size_t luaC_separateudata (lua_State *L);
void luaC_callGCTM (lua_State *L);
void luaC_sweep (lua_State *L, int all);
void luaC_collectgarbage (lua_State *L);
void luaC_link (lua_State *L, GCObject *o, lu_byte tt);


#endif

Added lua-5.0.2/src/lib/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
# makefile for Lua standard library

LUA= ../..

include $(LUA)/config

EXTRA_DEFS= $(POPEN) $(TMPNAM) $(DEGREES) $(LOADLIB)

OBJS= lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o ltablib.o lstrlib.o loadlib.o
SRCS= lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c ltablib.c lstrlib.c loadlib.c

T= $(LIB)/liblualib.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/lib/README.

















>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
This is the standard Lua library.

The code of the standard library can be read as an example of how to export
C functions to Lua. The easiest library to read is lmathlib.c.

The library is implemented entirely on top of the official Lua API as declared
in lua.h, using lauxlib.c, which contains several useful functions for writing
libraries. We encourage developers to use lauxlib.c in their own libraries.

Added lua-5.0.2/src/lib/lauxlib.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
/*
** $Id: lauxlib.c,v 1.100 2003/04/07 14:35:00 roberto Exp $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/


#include <ctype.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>


/* This file uses only the official API of Lua.
** Any function declared here could be written as an application function.
*/

#define lauxlib_c

#include "lua.h"

#include "lauxlib.h"


/* number of prereserved references (for internal use) */
#define RESERVED_REFS	2

/* reserved references */
#define FREELIST_REF	1	/* free list of references */
#define ARRAYSIZE_REF	2	/* array sizes */


/* convert a stack index to positive */
#define abs_index(L, i)		((i) > 0 || (i) <= LUA_REGISTRYINDEX ? (i) : \
					lua_gettop(L) + (i) + 1)


/*
** {======================================================
** Error-report functions
** =======================================================
*/


LUALIB_API int luaL_argerror (lua_State *L, int narg, const char *extramsg) {
  lua_Debug ar;
  lua_getstack(L, 0, &ar);
  lua_getinfo(L, "n", &ar);
  if (strcmp(ar.namewhat, "method") == 0) {
    narg--;  /* do not count `self' */
    if (narg == 0)  /* error is in the self argument itself? */
      return luaL_error(L, "calling `%s' on bad self (%s)", ar.name, extramsg);
  }
  if (ar.name == NULL)
    ar.name = "?";
  return luaL_error(L, "bad argument #%d to `%s' (%s)",
                        narg, ar.name, extramsg);
}


LUALIB_API int luaL_typerror (lua_State *L, int narg, const char *tname) {
  const char *msg = lua_pushfstring(L, "%s expected, got %s",
                                    tname, lua_typename(L, lua_type(L,narg)));
  return luaL_argerror(L, narg, msg);
}


static void tag_error (lua_State *L, int narg, int tag) {
  luaL_typerror(L, narg, lua_typename(L, tag)); 
}


LUALIB_API void luaL_where (lua_State *L, int level) {
  lua_Debug ar;
  if (lua_getstack(L, level, &ar)) {  /* check function at level */
    lua_getinfo(L, "Snl", &ar);  /* get info about it */
    if (ar.currentline > 0) {  /* is there info? */
      lua_pushfstring(L, "%s:%d: ", ar.short_src, ar.currentline);
      return;
    }
  }
  lua_pushliteral(L, "");  /* else, no information available... */
}


LUALIB_API int luaL_error (lua_State *L, const char *fmt, ...) {
  va_list argp;
  va_start(argp, fmt);
  luaL_where(L, 1);
  lua_pushvfstring(L, fmt, argp);
  va_end(argp);
  lua_concat(L, 2);
  return lua_error(L);
}

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


LUALIB_API int luaL_findstring (const char *name, const char *const list[]) {
  int i;
  for (i=0; list[i]; i++)
    if (strcmp(list[i], name) == 0)
      return i;
  return -1;  /* name not found */
}


LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
  lua_pushstring(L, tname);
  lua_rawget(L, LUA_REGISTRYINDEX);  /* get registry.name */
  if (!lua_isnil(L, -1))  /* name already in use? */
    return 0;  /* leave previous value on top, but return 0 */
  lua_pop(L, 1);
  lua_newtable(L);  /* create metatable */
  lua_pushstring(L, tname);
  lua_pushvalue(L, -2);
  lua_rawset(L, LUA_REGISTRYINDEX);  /* registry.name = metatable */
  lua_pushvalue(L, -1);
  lua_pushstring(L, tname);
  lua_rawset(L, LUA_REGISTRYINDEX);  /* registry[metatable] = name */
  return 1;
}


LUALIB_API void  luaL_getmetatable (lua_State *L, const char *tname) {
  lua_pushstring(L, tname);
  lua_rawget(L, LUA_REGISTRYINDEX);
}


LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
  const char *tn;
  if (!lua_getmetatable(L, ud)) return NULL;  /* no metatable? */
  lua_rawget(L, LUA_REGISTRYINDEX);  /* get registry[metatable] */
  tn = lua_tostring(L, -1);
  if (tn && (strcmp(tn, tname) == 0)) {
    lua_pop(L, 1);
    return lua_touserdata(L, ud);
  }
  else {
    lua_pop(L, 1);
    return NULL;
  }
}


LUALIB_API void luaL_checkstack (lua_State *L, int space, const char *mes) {
  if (!lua_checkstack(L, space))
    luaL_error(L, "stack overflow (%s)", mes);
}


LUALIB_API void luaL_checktype (lua_State *L, int narg, int t) {
  if (lua_type(L, narg) != t)
    tag_error(L, narg, t);
}


LUALIB_API void luaL_checkany (lua_State *L, int narg) {
  if (lua_type(L, narg) == LUA_TNONE)
    luaL_argerror(L, narg, "value expected");
}


LUALIB_API const char *luaL_checklstring (lua_State *L, int narg, size_t *len) {
  const char *s = lua_tostring(L, narg);
  if (!s) tag_error(L, narg, LUA_TSTRING);
  if (len) *len = lua_strlen(L, narg);
  return s;
}


LUALIB_API const char *luaL_optlstring (lua_State *L, int narg,
                                        const char *def, size_t *len) {
  if (lua_isnoneornil(L, narg)) {
    if (len)
      *len = (def ? strlen(def) : 0);
    return def;
  }
  else return luaL_checklstring(L, narg, len);
}


LUALIB_API lua_Number luaL_checknumber (lua_State *L, int narg) {
  lua_Number d = lua_tonumber(L, narg);
  if (d == 0 && !lua_isnumber(L, narg))  /* avoid extra test when d is not 0 */
    tag_error(L, narg, LUA_TNUMBER);
  return d;
}


LUALIB_API lua_Number luaL_optnumber (lua_State *L, int narg, lua_Number def) {
  if (lua_isnoneornil(L, narg)) return def;
  else return luaL_checknumber(L, narg);
}


LUALIB_API int luaL_getmetafield (lua_State *L, int obj, const char *event) {
  if (!lua_getmetatable(L, obj))  /* no metatable? */
    return 0;
  lua_pushstring(L, event);
  lua_rawget(L, -2);
  if (lua_isnil(L, -1)) {
    lua_pop(L, 2);  /* remove metatable and metafield */
    return 0;
  }
  else {
    lua_remove(L, -2);  /* remove only metatable */
    return 1;
  }
}


LUALIB_API int luaL_callmeta (lua_State *L, int obj, const char *event) {
  obj = abs_index(L, obj);
  if (!luaL_getmetafield(L, obj, event))  /* no metafield? */
    return 0;
  lua_pushvalue(L, obj);
  lua_call(L, 1, 1);
  return 1;
}


LUALIB_API void luaL_openlib (lua_State *L, const char *libname,
                              const luaL_reg *l, int nup) {
  if (libname) {
    lua_pushstring(L, libname);
    lua_gettable(L, LUA_GLOBALSINDEX);  /* check whether lib already exists */
    if (lua_isnil(L, -1)) {  /* no? */
      lua_pop(L, 1);
      lua_newtable(L);  /* create it */
      lua_pushstring(L, libname);
      lua_pushvalue(L, -2);
      lua_settable(L, LUA_GLOBALSINDEX);  /* register