Check-in [c0a223cb24]
Not logged in

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

Overview
Comment:merge with trunk
Timelines: family | ancestors | descendants | both | wtf-8-experiment
Files: files | file ages | folders
SHA1: c0a223cb249df6ae7a69d11ba6e442827d7ba349
User & Date: chw 2020-03-23 06:41:22.154
Context
2020-03-23
09:22
merge with trunk check-in: 8de44882ad user: chw tags: wtf-8-experiment
06:41
merge with trunk check-in: c0a223cb24 user: chw tags: wtf-8-experiment
06:40
add selected tcl upstream changes check-in: 44684572fa user: chw tags: trunk
2020-03-20
18:56
merge with trunk check-in: a6fce014cf user: chw tags: wtf-8-experiment
Changes
Unified Diff Ignore Whitespace Patch
Changes to jni/sdl2tk/macosx/tkMacOSXDraw.c.
1842
1843
1844
1845
1846
1847
1848

1849
1850
1851
1852
1853
1854
1855

    if (macDraw->winPtr && macDraw->flags & TK_CLIP_INVALID) {
	TkMacOSXUpdateClipRgn(macDraw->winPtr);
#ifdef TK_MAC_DEBUG_DRAWING
	TkMacOSXDbgMsg("%s", macDraw->winPtr->pathName);

	NSView *view = TkMacOSXDrawableView(macDraw);


	CGContextSaveGState(context);
	CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0,
	      -1.0, 0.0, [view bounds].size.height));
	ChkErr(HIShapeReplacePathInCGContext, macDraw->visRgn, context);
	CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.1);
	CGContextEOFillPath(context);







>







1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856

    if (macDraw->winPtr && macDraw->flags & TK_CLIP_INVALID) {
	TkMacOSXUpdateClipRgn(macDraw->winPtr);
#ifdef TK_MAC_DEBUG_DRAWING
	TkMacOSXDbgMsg("%s", macDraw->winPtr->pathName);

	NSView *view = TkMacOSXDrawableView(macDraw);
	CGContextRef context = GET_CGCONTEXT;

	CGContextSaveGState(context);
	CGContextConcatCTM(context, CGAffineTransformMake(1.0, 0.0, 0.0,
	      -1.0, 0.0, [view bounds].size.height));
	ChkErr(HIShapeReplacePathInCGContext, macDraw->visRgn, context);
	CGContextSetRGBFillColor(context, 0.0, 1.0, 0.0, 0.1);
	CGContextEOFillPath(context);
Changes to jni/sdl2tk/unix/tkUnixKey.c.
344
345
346
347
348
349
350




351
352
353
354
355
356
357
 * Side effects:
 *	In the first call for a given display, keycode-to-KeySym maps get
 *	loaded.
 *
 *----------------------------------------------------------------------
 */





KeySym
TkpGetKeySym(
    TkDisplay *dispPtr,		/* Display in which to map keycode. */
    XEvent *eventPtr)		/* Description of X event. */
{
    KeySym sym;
    int index;







>
>
>
>







344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
 * Side effects:
 *	In the first call for a given display, keycode-to-KeySym maps get
 *	loaded.
 *
 *----------------------------------------------------------------------
 */

#ifdef __GNUC__
#   pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

KeySym
TkpGetKeySym(
    TkDisplay *dispPtr,		/* Display in which to map keycode. */
    XEvent *eventPtr)		/* Description of X event. */
{
    KeySym sym;
    int index;
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
    }
    if ((eventPtr->xkey.state & ShiftMask)
	    || ((dispPtr->lockUsage != LU_IGNORE)
	    && (eventPtr->xkey.state & LockMask))) {
	index += 1;
    }

#ifdef __GNUC__
#   pragma GCC diagnostic push
#   pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#endif

    sym = TkKeycodeToKeysym(dispPtr, eventPtr->xkey.keycode, 0,
	    index);

    /*
     * Special handling: if the key was shifted because of Lock, but lock is
     * only caps lock, not shift lock, and the shifted keysym isn't upper-case
     * alphabetic, then switch back to the unshifted keysym.







<
<
<
<
<







405
406
407
408
409
410
411





412
413
414
415
416
417
418
    }
    if ((eventPtr->xkey.state & ShiftMask)
	    || ((dispPtr->lockUsage != LU_IGNORE)
	    && (eventPtr->xkey.state & LockMask))) {
	index += 1;
    }






    sym = TkKeycodeToKeysym(dispPtr, eventPtr->xkey.keycode, 0,
	    index);

    /*
     * Special handling: if the key was shifted because of Lock, but lock is
     * only caps lock, not shift lock, and the shifted keysym isn't upper-case
     * alphabetic, then switch back to the unshifted keysym.
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
    max = 8 * modMapPtr->max_keypermod;
    for (i = 0; i < max; i++, codePtr++) {
	if (*codePtr == 0) {
	    continue;
	}
	keysym = TkKeycodeToKeysym(dispPtr, *codePtr, 0, 0);

#ifdef __GNUC__
#   pragma GCC diagnostic pop
#endif

	if (keysym == XK_Mode_switch) {
	    dispPtr->modeModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
	}
	if ((keysym == XK_Meta_L) || (keysym == XK_Meta_R)) {
	    dispPtr->metaModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
	}
	if ((keysym == XK_Alt_L) || (keysym == XK_Alt_R)) {







<
<
<
<







509
510
511
512
513
514
515




516
517
518
519
520
521
522
    max = 8 * modMapPtr->max_keypermod;
    for (i = 0; i < max; i++, codePtr++) {
	if (*codePtr == 0) {
	    continue;
	}
	keysym = TkKeycodeToKeysym(dispPtr, *codePtr, 0, 0);





	if (keysym == XK_Mode_switch) {
	    dispPtr->modeModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
	}
	if ((keysym == XK_Meta_L) || (keysym == XK_Meta_R)) {
	    dispPtr->metaModMask |= ShiftMask << (i/modMapPtr->max_keypermod);
	}
	if ((keysym == XK_Alt_L) || (keysym == XK_Alt_R)) {
Added jni/src/doc/ble.n.






































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
'\"
'\" Copyright (c) 1993 The Regents of the University of California.
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
'\" Copyright (c) 2020 Christian Werner <chw at ch minus werner dot de>
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH ble n 8.6 Tcl "Tcl Extension Commands"
.\" ---- man.macros begin ----
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
.\"	and indent is equivalent to second arg of .IP (shouldn't ever be
.\"	needed;  use .AS below instead)
.\"
.\" .AS ?type? ?name?
.\"	Give maximum sizes of arguments for setting tab stops.  Type and
.\"	name are examples of largest possible arguments that will be passed
.\"	to .AP later.  If args are omitted, default tab stops are used.
.\"
.\" .BS
.\"	Start box enclosure.  From here until next .BE, everything will be
.\"	enclosed in one large box.
.\"
.\" .BE
.\"	End of box enclosure.
.\"
.\" .CS
.\"	Begin code excerpt.
.\"
.\" .CE
.\"	End code excerpt.
.\"
.\" .VS ?version? ?br?
.\"	Begin vertical sidebar, for use in marking newly-changed parts
.\"	of man pages.  The first argument is ignored and used for recording
.\"	the version when the .VS was added, so that the sidebars can be
.\"	found and removed when they reach a certain age.  If another argument
.\"	is present, then a line break is forced before starting the sidebar.
.\"
.\" .VE
.\"	End of vertical sidebar.
.\"
.\" .DS
.\"	Begin an indented unfilled display.
.\"
.\" .DE
.\"	End of indented unfilled display.
.\"
.\" .SO ?manpage?
.\"	Start of list of standard options for a Tk widget. The manpage
.\"	argument defines where to look up the standard options; if
.\"	omitted, defaults to "options". The options follow on successive
.\"	lines, in three columns separated by tabs.
.\"
.\" .SE
.\"	End of list of standard options for a Tk widget.
.\"
.\" .OP cmdName dbName dbClass
.\"	Start of description of a specific option.  cmdName gives the
.\"	option's name as specified in the class command, dbName gives
.\"	the option's name in the option database, and dbClass gives
.\"	the option's class in the option database.
.\"
.\" .UL arg1 arg2
.\"	Print arg1 underlined, then print arg2 normally.
.\"
.\" .QW arg1 ?arg2?
.\"	Print arg1 in quotes, then arg2 normally (for trailing punctuation).
.\"
.\" .PQ arg1 ?arg2?
.\"	Print an open parenthesis, arg1 in quotes, then arg2 normally
.\"	(for trailing punctuation) and then a closing parenthesis.
.\"
.\"	# Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
.\"	# Start an argument description
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
.   ie !"\\$2"" .TP \\n()Cu
.   el          .TP 15
.\}
.ta \\n()Au \\n()Bu
.ie !"\\$3"" \{\
\&\\$1 \\fI\\$2\\fP (\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1	\\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
.\"	# define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
.AS Tcl_Interp Tcl_CreateInterp in/out
.\"	# BS - start boxed text
.\"	# ^y = starting y location
.\"	# ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
.\"	# BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\"	Draw four-sided box normally, but don't draw top of
.\"	box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
.\"	# VS - start vertical sidebar
.\"	# ^Y = starting y location
.\"	# ^v = 1 (for troff;  for nroff this doesn't matter)
.de VS
.if !"\\$2"" .br
.mk ^Y
.ie n 'mc \s12\(br\s0
.el .nr ^v 1u
..
.\"	# VE - end of vertical sidebar
.de VE
.ie n 'mc
.el \{\
.ev 2
.nf
.ti 0
.mk ^t
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
.sp -1
.fi
.ev
.\}
.nr ^v 0
..
.\"	# Special macro to handle page bottom:  finish off current
.\"	# box/sidebar if in box/sidebar mode, then invoked standard
.\"	# page bottom macro.
.de ^B
.ev 2
'ti 0
'nf
.mk ^t
.if \\n(^b \{\
.\"	Draw three-sided box if this is the box's first page,
.\"	draw two sides but no top otherwise.
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.\}
.if \\n(^v \{\
.nr ^x \\n(^tu+1v-\\n(^Yu
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
.\}
.bp
'fi
.ev
.if \\n(^b \{\
.mk ^y
.nr ^b 2
.\}
.if \\n(^v \{\
.mk ^Y
.\}
..
.\"	# DS - begin display
.de DS
.RS
.nf
.sp
..
.\"	# DE - end display
.de DE
.fi
.RE
.sp
..
.\"	# SO - start of list of standard options
.de SO
'ie '\\$1'' .ds So \\fBoptions\\fR
'el .ds So \\fB\\$1\\fR
.SH "STANDARD OPTIONS"
.LP
.nf
.ta 5.5c 11c
.ft B
..
.\"	# SE - end of list of standard options
.de SE
.fi
.ft R
.LP
See the \\*(So manual entry for details on the standard options.
..
.\"	# OP - start of full description for a single option
.de OP
.LP
.nf
.ta 4c
Command-Line Name:	\\fB\\$1\\fR
Database Name:	\\fB\\$2\\fR
Database Class:	\\fB\\$3\\fR
.fi
.IP
..
.\"	# CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
..
.\"	# CE - end code excerpt
.de CE
.fi
.RE
..
.\"	# UL - underline word
.de UL
\\$1\l'|0\(ul'\\$2
..
.\"	# QW - apply quotation marks to word
.de QW
.ie '\\*(lq'"' ``\\$1''\\$2
.\"" fix emacs highlighting
.el \\*(lq\\$1\\*(rq\\$2
..
.\"	# PQ - apply parens and quotation marks to word
.de PQ
.ie '\\*(lq'"' (``\\$1''\\$2)\\$3
.\"" fix emacs highlighting
.el (\\*(lq\\$1\\*(rq\\$2)\\$3
..
.\"	# QR - quoted range
.de QR
.ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
.\"" fix emacs highlighting
.el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
..
.\"	# MT - "empty" string
.de MT
.QW ""
..
.\" ---- man.macros end ----
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
\fBble\fR \- interact with Bluetooth Low Energy (BLE) devices. Requires Android 4.3 or higher.
.SH SYNOPSIS
\fBpackage require Ble\fR
.br
\fBble\fR \fIsubcommand ?options?\fR
.BE
.SH DESCRIPTION
.PP
This command is used to deal with Bluetooth Low Energy (BLE) devices. The
legal command forms with \fIsubcommands\fR (which may be abbreviated) are:
.TP
\fBble abort\fR \fIhandle\fR
.
Abort the current write transaction on the BLE connection identified by
\fIhandle\fR which was obtained earlier by a \fBble connect\fR command.
Returns an integer indicating success (1), failure (0), or system error
(less than 0).
.TP
\fBble begin\fR \fIhandle\fR
.
Starts a write transaction on the BLE connection identified by
\fIhandle\fR which was obtained earlier by a \fBble connect\fR command.
Returns an integer indicating success (1), failure (0), or system error
(less than 0).
.TP
\fBble callback\fR \fIhandle ?callback?\fR
.
If the \fIcallback\fR argument is provided that argument replaces the
callback function on the BLE connection identified by \fIhandle\fR and
returns the old callback function. Otherwise the current callback function
is returned. In contrast to e.g. the Tk event bind mechanism, the
\fIcallback\fR argument has not all the freedom of a Tcl bind script, i.e.
it must be a single command and be parseable as a list since internally the
Tcl core function \fBTcl_EvalObjv()\fR is used for executing the callback
instead of the \fBTcl_Eval*()\fR function family supporting full scripts.
.TP
\fBble characteristics\fR \fIhandle suuid sinstance\fR
.
Returns a list of characteristics of the service described by its UUID
\fIsuuid\fR and instance number \fIinstance\fR on the BLE connection
\fIhandle\fR. The list is layed out as a table with the five columns
characteristic UUID, characteristic instance number, permissions,
properties, and write type suitable for iterating using
.sp 0
.nf
\fCforeach {cuuid cinstance perm prop wrtype} \\
    [ble characteristics ...] {...}\fR
.fi
.TP
\fBble close\fR \fIhandle\fR
.
Closes the BLE connection identified by \fIhandle\fR which was obtained
earlier by a \fBble connect\fR or \fBble scanner\fR command.
.TP
\fBble connect\fR \fIaddress callback ?flag?\fR
Connects to the Bluetooth LE device with address \fIaddress\fR (expressed
as six hexadecimal 8 bit numbers separated by colons, like a Ethernet MAC
address), and arranges for the \fIcallback\fR command to be invoked on
events on the connection to this device. The optional \fIflag\fR is a
boolean with default false controlling automatic connection setup
(see the Android documentation in
\fBhttps://developer.android.com/reference/android/bluetooth/BluetoothGatt.html\fR
for more details). The callback command is called with two additional
arguments, the first is a string (\fBconnection\fR, \fBscan\fR,
\fBservice\fR, \fBcharacteristic\fR, \fBdescriptor\fR, or
\fBtransaction\fR) indicating the kind of event, the second is a
dictionary with event related information, see the section \fBEVENT DATA\fR
below. For restrictions of the \fIcallback\fR argument see the description
in \fBble callback\fR above. The result of the \fBble connect\fR command
is a handle (a string identifying the BLE connection) to be used in other
\fBble\fR subcommands. During connection establishment an automatic
discovery takes place which detects all advertised services, characteristics,
and descriptors of the remote Bluetooth LE device.
.TP
\fBble descriptors\fR \fIhandle suuid sinstance cuuid cinstance\fR
.
Returns a list of descriptors of the service and characteristic described
by its UUIDs \fIsuuid\fR and \fIcuuid\fR and instance numbers \fIsinstance\fR
and \fIcinstance\fR on the BLE connection \fIhandle\fR. The list is layed
out as a table with the two columns descriptor UUID and permissions suitable
for iterating using
.sp 0
.nf
\fCforeach {duuid perm} \\
    [ble descriptors ...] {...}\fR
.fi
.TP
\fBble disable\fR \fIhandle suuid sinstance cuuid cinstance\fR
.
Turns off notifications of a characteristic of the BLE connection
\fIhandle\fR identified by \fIsuuid\fR (128 bit service UUID),
\fIsinstance\fR (service instance identifier, integer, usually 0),
\fIcuuid\fR (128 bit characteristic UUID), and
\fIcinstance\fR (characteristic identifier, integer, usually 0).
.TP
\fBble disconnect\fR \fIhandle\fR
.
Initiates a disconnect of the BLE connection \fIhandle\fR if the
current connection state is disconnected. When the operation completes
the callback function of the connection is invoked.
.TP
\fBble dread\fR \fIhandle suuid sinstance cuuid cinstance duuid\fR
.
Initiates the read of a descriptor of the BLE connection \fIhandle\fR
identified by \fIsuuid\fR (128 bit service UUID),
\fIsinstance\fR (service instance identifier, integer, usually 0),
\fIcuuid\fR (128 bit characteristic UUID),
\fIcinstance\fR (characteristic identifier, integer, usually 0),
and \fIduuid\fR (128 bit descriptor UUID). The result is a positive
integer when the descriptor read operation is in progress, 0 or negative
on error. The completion of the descriptor read operation is indicated
through the callback function of the connection.
.TP
\fBble dwrite\fR \fIhandle suuid sinstance cuuid cinstance duuid value\fR
.
Initiates the write of a descriptor of the BLE connection \fIhandle\fR
identified by \fIsuuid\fR (128 bit service UUID),
\fIsinstance\fR (service instance identifier, integer, usually 0),
\fIcuuid\fR (128 bit characteristic UUID),
\fIcinstance\fR (characteristic identifier, integer, usually 0),
and \fIduuid\fR (128 bit descriptor UUID).
\fIvalue\fR is the value to be written and should be a string or byte array.
The result is a positive integer when the descriptor write operation is in
progress, 0 or negative on error. The completion of the descriptor write
operation is indicated through the callback function of the connection.
.TP
\fBble enable\fR \fIhandle suuid sinstance cuuid cinstance\fR
.
Turns on notifications of a characteristic of the BLE connection \fIhandle\fR
identified by \fIsuuid\fR (128 bit service UUID),
\fIsinstance\fR (service instance identifier, integer, usually 0),
\fIcuuid\fR (128 bit characteristic UUID), and
\fIcinstance\fR (characteristic identifier, integer, usually 0).
.TP
\fBble equal\fR \fIhandle uuid1 uuid2\fR
.
Tests if the given UUIDs are equal. Both can be specified in abbreviated
form and are expanded before comparison. Returns true, if the UUIDs are
the same. Unknown abbreviated or long UUIDs with respect to the connection
\fIhandle\fR compare always to false.
.TP
\fBble execute\fR \fIhandle\fR
.
Dispatches execute (commit) of the current write transaction which was
started earlier using \fBble begin\fR on the BLE connection identified
by \fIhandle\fR which was obtained earlier by a \fBble connect\fR
command. Returns an integer indicating success (1), failure (0), or
system error (less than 0). The result of the transaction is reported
in the callback with event kind \fBtransaction\fR.
.TP
\fBble expand\fR \fIhandle uuid\fR
.
Expands the given (abbreviated, short) UUID to its 128 bit (long, canonical)
form and returns a 128 bit UUID string. An error is reported if an
abbreviated or long UUID is unknown with respect to the connection
\fIhandle\fR.
.TP
\fBble getrssi\fR \fIhandle\fR
.
Requests remote SSI information from the BLE connection identified by
\fIhandle\fR which was obtained earlier by a \fBble connect\fR command.
Returns an integer indicating success (1), failure (0), or system error
(less than 0). The updated remote SSI is reported in later callbacks.
.TP
\fBble info\fR \fI?handle?\fR
.
Returns information of the BLE connection identified by \fIhandle\fR as
a dictionary made up the fields \fIhandle\fR (the connection identifier),
\fIaddress\fR (Bluetooth address), and \fIstate\fR (connection state,
one of \fBdisconnected\fR, \fBdiscovery\fR, \fBscanning\fR,
\fBconnected\fR, or \fBidle\fR. If \fIhandle\fR is omitted, a list of
all known connection identifiers is returned.
.TP
\fBble pair\fR \fIaddress\fR
.
 Initiates pairing with the Bluetooth device with address \fIaddress\fR
(expressed as six hexadecimal 8 bit numbers separated by colons, like a
Ethernet MAC address).
.TP
\fBble read\fR \fIhandle suuid sinstance cuuid cinstance\fR
.
Initiates the read of a characteristic of the BLE connection \fIhandle\fR
identified by \fIsuuid\fR (128 bit service UUID),
\fIsinstance\fR (service instance identifier, integer, usually 0),
\fIcuuid\fR (128 bit characteristic UUID), and
\fIcinstance\fR (characteristic identifier, integer, usually 0).
The result is a positive integer when the read operation is in progress,
0 or negative on error. The completion of the read operation is indicated
through the callback function of the connection.
.TP
\fBble reconnect\fR \fIhandle\fR
.
Initiates a reconnect of the BLE connection \fIhandle\fR if the
current connection state is disconnected. When the operation completes
the callback function of the connection is invoked with information on
the new connection state.
.TP
\fBble scanner\fR \fIcallback\fR
.
Creates a BLE connection to be used for detection (scan) of BLE devices
and returns a handle (a string identifying the BLE scanner) to be used
to deal with this scanner and arranges for the \fIcallback\fR command
to be invoked on events on the connection. See the description of
\fBble connect\fR and the section \fBEVENT DATA\fR for more details
on the \fIcallback\fR argument.
.TP
\fBble services\fR \fIhandle\fR
.
Returns a list of services of the BLE connection \fIhandle\fR. The list
is layed out as a table with the three columns service UUID, service
instance number, and service type suitable for iterating using
.sp 0
.nf
\fCforeach {suuid sinstance type} \\
    [ble services ...] {...}\fR
.fi
.TP
\fBble shorten\fR \fIhandle uuid\fR
.
Shorten the given (long, canonical) UUID to its shortest (16 or 32 bit)
form. An error is reported if the long UUID is unknown with respect to
the connection \fIhandle\fR. If no unique abbreviation is found, the
full 128 bit UUID is returned.
.TP
\fBble start\fR \fIhandle\fR
.
Starts scanning for BLE devices. Scan status and scan results are
indicated by invocations of the \fIcallback\fR function given to
the corresponding \fBble scanner\fR command.
.TP
\fBble stop\fR \fIhandle\fR
.
Stops scanning for BLE devices. Scan status is indicated by invocations
of the \fIcallback\fR function given to the corresponding \fBble scanner\fR
command.
.TP
\fBble unpair\fR \fIaddress\fR
.
Initiates release of the pairing with the Bluetooth device with address
\fIaddress\fR (expressed as six hexadecimal 8 bit numbers separated by
colons, like a Ethernet MAC address).
.TP
\fBble userdata\fR \fIhandle ?data?\fR
.
Associate or retrieve user data with the BLE connection \fIhandle\fR.
When \fIdata\fR is given it replaces the former associated user data.
When omitted, the current user data or an empty list is returned.  
.TP
\fBble write\fR \fIhandle suuid sinstance cuuid cinstance value\fR
.
Initiates the write of a characteristic of the BLE connection \fIhandle\fR
identified by \fIsuuid\fR (128 bit service UUID),
\fIsinstance\fR (service instance identifier, integer, usually 0),
\fIcuuid\fR (128 bit characteristic UUID), and
\fIcinstance\fR (characteristic identifier, integer, usually 0).
\fIvalue\fR is the value to be written and should be a string or byte array.
The result is a positive integer when the write operation is in progress,
0 or negative on error. The completion of the write operation is indicated
through the callback function of the connection.  Note: not all Android
implementations allow more than one active command (example, issuing a
\fBble read\fR immediately after a \fBble write\fR). For best compatibility,
you should wait for the callback that your write operation has completed
before issuing the next \fBble write\fR or \fBble read\fR command.
.
.SH "ABBREVIATED UUIDs"
.PP
The 128 bit UUID arguments to \fBble\fR commands can be specified
in abbreviated 16 or 32 bit form as long as the value is unique with
respect to the UUIDs learned during the discovery phase. Examples:
.sp 1
.nf
\fC
 TI SensorTag Base UUID:        F0000000-0451-4000-B000-000000000000

 IR Temperature Sensor Service: F000AA00-0451-4000-B000-000000000000
          abbreviated (32 bit): F000AA00
          abbreviated (16 bit):     AA00

 IR Temperature Sensor Value:   F000AA01-0451-4000-B000-000000000000
          abbreviated (32 bit): F000AA01
          abbreviated (16 bit):     AA01

 Generic descriptor for notify: 00002902-0000-1000-8000-00805F9B34FB
          abbreviated (32 bit): 00002902
          abbreviated (16 bit):     2902
\fR
.fi

.SH "EVENT DATA"
.PP
The first argument to callback functions is the type of event,
as described below.
.TP
\fBconnection\fR
.
Indicates change in connection state.
.TP
\fBscan\fR
.
Indicates change in scan state or reports newly detected Bluetooth LE devices.
.TP
\fBservice\fR
.
Information about a service.
.TP
\fBcharacteristic\fR
.
Information about a characteristic, used for data exchange.
.TP
\fBdescriptor\fR
.
Information about a descriptor (meta information of a characteristic).
.TP
\fBtransaction\fR
.
Indicates status of a write transaction.
.PP
The second argument to callback functions is a dictionary with keys
depending on the kind of the event. The following paragraphs list the
various event formats.
.TP
\fBhandle\fR \fIh\fR \fBstate\fR \fIs\fR
.
Connection state event for \fBble scan\fR. \fBstate\fR can be one of
\fBscanning\fR or \fBidle\fR.
.TP
\fBhandle\fR \fIh\fR \fBaddress\fR \fIa\fR \fBstate\fR \fIs\fR \fBrssi\fR \fIr\fR
.
Connection state event for \fBble connect\fR. \fBstate\fR can be one
of \fBdisconnected\fR, \fBdiscovery\fR, or \fBconnected\fR.
In the discovery phase the services, characteristics, and descriptors
of the remote device are gathered. The \fBrssi\fR field contains the
last read remote SSI (signal strength indicator) in dBm as integer number.
.TP
\fBhandle\fR \fIh\fR \fBstate\fR \fIs\fR \fBaddress\fR \fIa\fR \fBname\fR \fIn\fR \fBtype\fR \fIt\fR \fBrssi\fR \fIr\fR
.
Scan result event. \fBaddress\fR is the Bluetooth address of the remote
device, \fBname\fR it's advertised friendly name, \fBtype\fR the device
type as integer, \fBrssi\fR the receive SSI in dBm as integer.
.TP
\fBhandle\fR \fIh\fR \fBaddress\fR \fIa\fR \fBstate\fR \fIs\fR \fBrssi\fR \fIr\fR \fBsuuid\fR \fIsu\fR \fBsinstance\fR \fIsi\fR \fBtype\fR \fIt\fR
.
Service discovery event. \fBsuuid\fR is the UUID of the service,
\fBsinstance\fR the instance of that service as integer number.
Refer to \fBhttps://developer.android.com/reference/android/bluetooth/BluetoothGattService.html\fR for details.
.TP
\fBhandle\fR \fIh\fR \fBaddress\fR \fIa\fR \fBstate\fR \fIs\fR \fBrssi\fR \fIr\fR \fBsuuid\fR \fIsu\fR \fBsinstance\fR \fIsi\fR \fBcuuid\fR \fIci\fR \fBcinstance\fR \fIci\fR \fBpermissions\fR \fIp\fR \fBproperties\fR \fIq\fR \fBwritetype\fR \fIw\fR \fBaccess\fR \fIa\fR \fBvalue\fR \fIv\fR
.
Characteristic event. \fBcuuid\fR is the UUID of the characteristic,
\fBcinstance\fR the instance of that characteristic as integer number.
The items \fBpermission\fR, \fBproperties\fR, and \fBwritetype\fR are
integer numbers, too. The \fBaccess\fR item contains a one letter code
indicating the type of access (\fBc\fR for change notification,
\fBd\fR for discovery, \fBr\fR for read, \fBw\fR for write).
The \fBvalue\fR item holds the data of the characteristic as a byte array.
It's interpretation is device/characteristic depending. This event is
reported during discovery and normal operation when \fBble read\fR
or \fBble write\fR are performed locally or notifications for the
characteristic are enabled using \fBble enable\fR. Refer to
\fBhttps://developer.android.com/reference/android/bluetooth/BluetoothGattCharacteristic.html\fR for details.
.TP
\fBhandle\fR \fIh\fR \fBaddress\fR \fIa\fR \fBstate\fR \fIs\fR \fBrssi\fR \fIr\fR \fBsuuid\fR \fIsu\fR \fBsinstance\fR \fIsi\fR \fBcuuid\fR \fIci\fR \fBcinstance\fR \fIci\fR \fBduuid\fR \fIdi\fR \fBpermissions\fR \fIp\fR \fBaccess\fR \fIa\fR \fBvalue\fR \fIv\fR
.
Descriptor event. \fBduuid\fR is the UUID of the descriptor.
The item \fBpermissions\fR is an integer number, too.
The \fBaccess\fR item contains a one letter code indicating the type
of access (\fBd\fR for discovery, \fBr\fR for read, \fBw\fR for write).
The \fBvalue\fR item holds the data of the descriptor as a byte array.
It's interpretation is device/characteristic/descriptor depending.
This event is reported during discovery and normal operation when
\fBble dread\fR or \fBble dwrite\fR are performed locally. Refer to
\fBhttps://developer.android.com/reference/android/bluetooth/BluetoothGattDescriptor.html\fR for details.
.TP
\fBhandle\fR \fIh\fR \fBsuccess\fR \fIs\fR
.
Transaction result event. \fBsuccess\fR is the transaction result and is
1 for success or 0 for failure.
.SH EXAMPLE
.PP
The following example scans for Bluetooth LE devices, connects to a
TI Sensor Tag (see \fBhttp://www.ti.com/tool/cc2541dk-sensor\fR)
and enables notifications of the buttons of the device.
.sp 1
.nf
\fC
proc ble_handler {what data} {
    switch -- $what {
        scan {
            if {[dict get $data name] eq "SensorTag"} {
                # found the TI SensorTag, connect it, stop the scanner
                ble connect [dict get $data address] ble_handler 1
                ble close [dict get $data handle]
            }
        }
        connection {
            if {[dict get $data state] == "disconnected"} {
                # fall back to scanning
                ble close [dict get $data handle]
                ble start [ble scanner ble_handler]
            } elseif {[dict get $data state] == "connected"} {
                # if the TI SensorTag buttons were found,
                # it will be enabled for notifications now
                set handle [dict get $data handle]
                set cmd [ble userdata $handle]
                if {$cmd ne {}} {
                    if {[{*}$cmd]} {
                        # success, clear userdata
                        ble userdata $handle {}
                    }
                }
            }
        }
        descriptor {
            if {[string match "*2902-*" [dict get $data duuid]] &&
                [string match "*FFE1-*" [dict get $data cuuid]]} {
                # descriptor for TI SensorTag buttons found
                set flag 0
                # notification enable state, 16 bit little-endian
                #  0x0000 = disabled, 0x0001 = enabled
                binary scan [dict get $data value] s flag
                if {!$flag} {
                    # later turn on notifications of button changes
                    set handle [dict get $data handle]
                    ble userdata $handle [list ble enable $handle \\
                        [dict get $data suuid] [dict get $data sinstance] \\
                        [dict get $data cuuid] [dict get $data cinstance]]
                }
            }
        }
    }
    # dump data to stdout
    if {[dict exists $data value]} {
        # make hex string from byte array
        binary scan [dict get $data value] H* value
        dict set data value $value
    }
    puts "$what: $data"
}

ble start [ble scanner ble_handler]
\fR
.fi
Added jni/src/doc/borg.n.
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
'\"
'\" Copyright (c) 1993 The Regents of the University of California.
'\" Copyright (c) 1994-1996 Sun Microsystems, Inc.
'\" Copyright (c) 2020 Christian Werner <chw at ch minus werner dot de>
'\"
'\" See the file "license.terms" for information on usage and redistribution
'\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
'\"
.TH borg n 8.6 Tcl "Tcl Extension Commands"
.\" ---- man.macros begin ----
.\" The -*- nroff -*- definitions below are for supplemental macros used
.\" in Tcl/Tk manual entries.
.\"
.\" .AP type name in/out ?indent?
.\"	Start paragraph describing an argument to a library procedure.
.\"	type is type of argument (int, etc.), in/out is either "in", "out",
.\"	or "in/out" to describe whether procedure reads or modifies arg,
.\"	and indent is equivalent to second arg of .IP (shouldn't ever be
.\"	needed;  use .AS below instead)
.\"
.\" .AS ?type? ?name?
.\"	Give maximum sizes of arguments for setting tab stops.  Type and
.\"	name are examples of largest possible arguments that will be passed
.\"	to .AP later.  If args are omitted, default tab stops are used.
.\"
.\" .BS
.\"	Start box enclosure.  From here until next .BE, everything will be
.\"	enclosed in one large box.
.\"
.\" .BE
.\"	End of box enclosure.
.\"
.\" .CS
.\"	Begin code excerpt.
.\"
.\" .CE
.\"	End code excerpt.
.\"
.\" .VS ?version? ?br?
.\"	Begin vertical sidebar, for use in marking newly-changed parts
.\"	of man pages.  The first argument is ignored and used for recording
.\"	the version when the .VS was added, so that the sidebars can be
.\"	found and removed when they reach a certain age.  If another argument
.\"	is present, then a line break is forced before starting the sidebar.
.\"
.\" .VE
.\"	End of vertical sidebar.
.\"
.\" .DS
.\"	Begin an indented unfilled display.
.\"
.\" .DE
.\"	End of indented unfilled display.
.\"
.\" .SO ?manpage?
.\"	Start of list of standard options for a Tk widget. The manpage
.\"	argument defines where to look up the standard options; if
.\"	omitted, defaults to "options". The options follow on successive
.\"	lines, in three columns separated by tabs.
.\"
.\" .SE
.\"	End of list of standard options for a Tk widget.
.\"
.\" .OP cmdName dbName dbClass
.\"	Start of description of a specific option.  cmdName gives the
.\"	option's name as specified in the class command, dbName gives
.\"	the option's name in the option database, and dbClass gives
.\"	the option's class in the option database.
.\"
.\" .UL arg1 arg2
.\"	Print arg1 underlined, then print arg2 normally.
.\"
.\" .QW arg1 ?arg2?
.\"	Print arg1 in quotes, then arg2 normally (for trailing punctuation).
.\"
.\" .PQ arg1 ?arg2?
.\"	Print an open parenthesis, arg1 in quotes, then arg2 normally
.\"	(for trailing punctuation) and then a closing parenthesis.
.\"
.\"	# Set up traps and other miscellaneous stuff for Tcl/Tk man pages.
.if t .wh -1.3i ^B
.nr ^l \n(.l
.ad b
.\"	# Start an argument description
.de AP
.ie !"\\$4"" .TP \\$4
.el \{\
.   ie !"\\$2"" .TP \\n()Cu
.   el          .TP 15
.\}
.ta \\n()Au \\n()Bu
.ie !"\\$3"" \{\
\&\\$1 \\fI\\$2\\fP (\\$3)
.\".b
.\}
.el \{\
.br
.ie !"\\$2"" \{\
\&\\$1	\\fI\\$2\\fP
.\}
.el \{\
\&\\fI\\$1\\fP
.\}
.\}
..
.\"	# define tabbing values for .AP
.de AS
.nr )A 10n
.if !"\\$1"" .nr )A \\w'\\$1'u+3n
.nr )B \\n()Au+15n
.\"
.if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n
.nr )C \\n()Bu+\\w'(in/out)'u+2n
..
.AS Tcl_Interp Tcl_CreateInterp in/out
.\"	# BS - start boxed text
.\"	# ^y = starting y location
.\"	# ^b = 1
.de BS
.br
.mk ^y
.nr ^b 1u
.if n .nf
.if n .ti 0
.if n \l'\\n(.lu\(ul'
.if n .fi
..
.\"	# BE - end boxed text (draw box now)
.de BE
.nf
.ti 0
.mk ^t
.ie n \l'\\n(^lu\(ul'
.el \{\
.\"	Draw four-sided box normally, but don't draw top of
.\"	box if the box started on an earlier page.
.ie !\\n(^b-1 \{\
\h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.el \}\
\h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul'
.\}
.\}
.fi
.br
.nr ^b 0
..
.\"	# VS - start vertical sidebar
.\"	# ^Y = starting y location
.\"	# ^v = 1 (for troff;  for nroff this doesn't matter)
.de VS
.if !"\\$2"" .br
.mk ^Y
.ie n 'mc \s12\(br\s0
.el .nr ^v 1u
..
.\"	# VE - end of vertical sidebar
.de VE
.ie n 'mc
.el \{\
.ev 2
.nf
.ti 0
.mk ^t
\h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n'
.sp -1
.fi
.ev
.\}
.nr ^v 0
..
.\"	# Special macro to handle page bottom:  finish off current
.\"	# box/sidebar if in box/sidebar mode, then invoked standard
.\"	# page bottom macro.
.de ^B
.ev 2
'ti 0
'nf
.mk ^t
.if \\n(^b \{\
.\"	Draw three-sided box if this is the box's first page,
.\"	draw two sides but no top otherwise.
.ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c
.\}
.if \\n(^v \{\
.nr ^x \\n(^tu+1v-\\n(^Yu
\kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c
.\}
.bp
'fi
.ev
.if \\n(^b \{\
.mk ^y
.nr ^b 2
.\}
.if \\n(^v \{\
.mk ^Y
.\}
..
.\"	# DS - begin display
.de DS
.RS
.nf
.sp
..
.\"	# DE - end display
.de DE
.fi
.RE
.sp
..
.\"	# SO - start of list of standard options
.de SO
'ie '\\$1'' .ds So \\fBoptions\\fR
'el .ds So \\fB\\$1\\fR
.SH "STANDARD OPTIONS"
.LP
.nf
.ta 5.5c 11c
.ft B
..
.\"	# SE - end of list of standard options
.de SE
.fi
.ft R
.LP
See the \\*(So manual entry for details on the standard options.
..
.\"	# OP - start of full description for a single option
.de OP
.LP
.nf
.ta 4c
Command-Line Name:	\\fB\\$1\\fR
Database Name:	\\fB\\$2\\fR
Database Class:	\\fB\\$3\\fR
.fi
.IP
..
.\"	# CS - begin code excerpt
.de CS
.RS
.nf
.ta .25i .5i .75i 1i
..
.\"	# CE - end code excerpt
.de CE
.fi
.RE
..
.\"	# UL - underline word
.de UL
\\$1\l'|0\(ul'\\$2
..
.\"	# QW - apply quotation marks to word
.de QW
.ie '\\*(lq'"' ``\\$1''\\$2
.\"" fix emacs highlighting
.el \\*(lq\\$1\\*(rq\\$2
..
.\"	# PQ - apply parens and quotation marks to word
.de PQ
.ie '\\*(lq'"' (``\\$1''\\$2)\\$3
.\"" fix emacs highlighting
.el (\\*(lq\\$1\\*(rq\\$2)\\$3
..
.\"	# QR - quoted range
.de QR
.ie '\\*(lq'"' ``\\$1''\\-``\\$2''\\$3
.\"" fix emacs highlighting
.el \\*(lq\\$1\\*(rq\\-\\*(lq\\$2\\*(rq\\$3
..
.\"	# MT - "empty" string
.de MT
.QW ""
..
.\" ---- man.macros end ----
.BS
'\" Note:  do not modify the .SH NAME line immediately below!
.SH NAME
\fBborg\fR \- control and interact with the Android OS.
.SH SYNOPSIS
\fBpackage require Borg\fR
.br
\fBborg\fR \fIsubcommand ?arg ...?\fR
.BE
.SH DESCRIPTION
.
This command integrates the capabilities of Tcl/Tk with Android by way of
several subcommands. These allow Tcl/Tk to go where it has never gone
before by querying and controlling Bluetooth functionality, OS notifications
(including device vibration and even speech), location information, etc.
.SH "BLUETOOTH-RELATED COMMANDS"
.
For communication over Bluetooth see the description of the \fBrfcomm\fR
command. For handling of Bluetooth Low Energy (Bluetooth Smart) devices
see the description of the \fBble\fR command.
.TP
\fBborg bluetooth devices\fR
.
Returns a list suited for \fBarray set\fR or \fBdict create\fR commands
containing the Bluetooth address and friendly name of all paired
Bluetooth devices.
.TP
\fBborg bluetooth state\fR
.
Returns the current Bluetooth state: \fBoff\fR, \fRon\fR, \fBturning_off\fR,
or \fBturning_on\fR.
.TP
\fBborg bluetooth scanmode\fR
.
Returns the current Bluetooth scan mode: \fBconnectable\fR, \fBoff\fR,
\fBpassive\fR, or \fBvisible\fR.
.TP
\fBborg bluetooth myaddress\fR
.
Returns the Bluetooth address of the local default Bluetooth adapter.
.TP
\fBborg bluetooth remoteaddress\fR \fIaddress\fR
.
Returns the friendly name for the given Bluetooth \fIaddress\fR.
.TP
\fBborg bluetooth on\fR
.
Quote from \fBhttp://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#enable()\fR:
do not use without explicit user action to turn on Bluetooth.
Tries to turn the Bluetooth adapter on. Returns 1 if the adapter
is already or going to be turned on, 0 otherwise.
.TP
\fBborg bluetooth off\fR
.
Quote from \fBhttp://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#disable()\fR:
do not use without explicit user action to turn off Bluetooth.
Tries to turn the Bluetooth adapter off. Returns 1 if the adapter is
already or going to be turned off, 0 otherwise.
.SH "USB-RELATED COMMANDS"
.
For communication over USB serial converters see the description of
the \fBusbserial\fR command.
.TP
\fBborg usbdevices\fR \fI?extended?\fR
.
If \fIextended\fR is omitted or false, a list suitable for the
\fBarray set\fR or \fBdict create\fR commands containing the USB
device name and vendor/product identifier of all currently connected
USB devices is returned. Otherwise, i.e. \fIextended\fR is true,
three elements per USB device are returned: USB device name,
product/vendor identifier, and USB interface information as in
Linux \fBudev\fR.
.TP
\fBborg usbpermission\fR \fIdevname ?ask?\fR
.
Queries permission for the USB device \fIdevname\fR and returns 1
if the device is usable, 0 if not, and a negative number on error.
If the optional boolean argument \fIask\fR is specified as true,
a system dialog is shown allowing the user to grant or deny permission
for the USB device.
.SH "NETWORK-RELATED COMMANDS"
.
.TP
\fBborg networkinfo\fR
.
Returns the current state of the network: \fBnone\fR,
\fBwifi\fR, \fBmobile gsm\fR, etc. An update of this information
is indicated by the \fB<<NetworkInfo>>\fR virtual event sent to
all toplevel widgets.
.TP
\fBborg tetherinfo\fR
.
Returns the current state of tethering as a list suited for
\fBarray set\fR or \fBdict create\fR with zero or three entries
\fBactive\fR, \fBavailable\fR, and \fBerror\fR which usually
contain interface names. An update of this information is indicated
by the \fB<<TetherInfo>>\fR virtual event sent to all toplevel widgets.
.SH "DESKTOP-RELATED COMMANDS"
.TP
\fBborg shortcut add\fR \fIname-of-shortcut script-to-run ?png-icon-as-base-64-string\fR
.
Adds an icon to the desktop, with the label \fIname-of-shortcut\fR specified.
The script, specified as \fIscript-to-run\fR must use an absolute path as
a \fBfile://\fR URI and must be readable by the user id under which the
AndroWish package has been registered by the Android installer. The last
(optional) parameter \fIpng-icon-as-base-64-string\fR allows the icon
graphic to be specified. If not provided, a default AndroWish icon is used.
According to the guidelines on iconography in
\fBhttp://developer.android.com/design/style/iconography.html\fR,
icons should have an aspect ratio of 48 by 48 pixels (192 x 192 is
recommended, at 4 times 48x48 pixels). Example (pseudo code):
.sp 1
.nf
\fC
package require base64
proc read_binary_file {name} { # whatever is needed to read bytes ... }
set icondata [read_binary_file "/mnt/sdcard/appicon_48_48.png"]
set iconbase64 [::base64::encode -maxlen 0 $icondata]
borg shortcut add "My App" file://mnt/sdcard/speaktest.tcl $iconbase64
\fR
.fi
.TP
\fBborg shortcut delete\fR \fIname-of-shortcut\fR
.
Deletes an icon shortcut from desktop (depends on Android launcher support).
.SH "NOTIFICATION-RELATED COMMANDS"
.TP
\fBborg notification add\fR \fIid title ?text icon action uri type categories component arguments\fR
.
Adds a notification with \fItitle\fR and \fItext\fR into the Android
notification area. The integer \fIid\fR, specified by the caller, is
used to identify the notification for later modification or deletion.
The optional parameters starting from \fIaction\fR form an activity
(see \fBborg activity ...\fR) to be carried out when the user clicks
on the notification. See the description of \fBborg alarm set\fR below
for special treatment of the \fIcomponent\fR. The optional
\fIicon\fR must be a PNG or JPG image encoded as base64 string. The size
of the icon should be 24 by 24 pixels.
.TP
\fBborg notification delete\fR \fI?id?\fR
.
Deletes a notification identified that was created with the \fIid\fR
specified. If no \fIid\fR is provided, all notifications are deleted.
.TP
\fBborg notification led\fR \fIid argb onms offms\fR
.
Adds a notification controlling the device LED. The integer \fIid\fR,
specified by the caller, is used to identify the notification for later
modification or deletion. The integer parameter \fIargb\fR is the LED
color as combined RGB value with alpha channel, \fIonms\fR and \fIoffms\fR
are integers, too, controlling the duty cycle of blinking.
.TP
\fBborg vibrate\fR \fIms\fR
.
Turns the vibration motor on for integer \fIms\fR milliseconds.
.TP
\fBborg beep\fR \fI?uri?\fR
.
Plays a notification sound. If \fIuri\fR is specified and not an
empty string, it is played as notification/ringtone/alarm sound.
If given as empty string, the current playback is stopped. If
omitted or unable to be resolved, the default notification sound
is played. The URI typically has the pattern
\fBcontent://media/{internal,external}/audio/media/<id>\fR, where
\fB<id>\fR is an integer number identifying a sound file. The
\fBborg content ...\fR command can be used to obtain information
on notification sounds from Android's media provider.
.TP
\fBborg speak\fR \fItext ?lang pitch rate?\fR
.
Gets the Android to read out the string \fItext\fR. Optional
parameter \fIlang\fR is the language code for the spoken language, e.g.
\fBen\fR, \fBen_US\fR, \fBde\fR, \fBes\fR, etc. Optional parameters
\fIpitch\fR and \fIrate\fR control the voice and speed as float values.
On success an integer number >= 1000 is returned which identifies the
text to be spoken in various virtual events. On error a negative number
is returned. See
\fBhttp://developer.android.com/reference/android/speech/tts/TextToSpeech.html\fR
for more information.
.TP
\fBborg stopspeak\fR
.
Stops speech output.
.TP
\fBborg isspeaking\fR
.
Returns a small integer indicating the state of speech output. Zero
indicates initialization of speech output has been performed but no
speech output is currently active. One is returned when speech output
is active. A small negative number indicates an error, temporary or
permanent unavailability of the text-to-speech facility. In order to
start up the text-to-speech facility this command can be used.
The first call usually returns -1 and calls some few hundred
milliseconds later return zero, indicating availability of the
text-to-speech facility.
.TP
\fBborg endspeak\fR
.
Stops speech output and releases system resources.
.TP
\fBborg toast\fR \fItext ?flag?\fR
.
Displays a text notification \fItext\fR for a short period of time.
The duration of that display is somewhat longer when \fIflag\fR
is specified as true.
.TP
\fBborg spinner on|off\fR
.
Displays or withdraws a spinner (rotating symbol indicating busy state)
depending on argument.
.SH "LOCATION-RELATED COMMANDS"
.TP
\fBborg location start\fR \fI?minrate-in-ms ?min-dist-in-m??\fR
.
Begins acquiring location data via the Android OS (which may choose
to use GPS, network info, etc.).
.TP
\fBborg location stop\fR
-
Ends location data acquisition.
.TP
\fBborg location get\fR
.
Returns the location data (as an \fBarray set\fR or \fBdict create\fR form)
where the key is the location source. Location updates trigger a virtual
event \fB<<LocationUpdate>>\fR that is sent to all toplevel widgets.
These toplevel event-handlers should, in turn, invoke \fBborg location get\fR
to refresh their knowledge.
.TP
\fBborg location gps\fR
.
Returns GPS information in \fBarray set\fR or \fBdict create\fR form with
the keys \fBstate\fR (\fBon\fR or \fBoff\fR) and \fBfirst_fix\fR
(time in seconds until first fix expected). Updates in GPS information
are indicated by the \fB<<GPSUpdate>>\fR virtual event sent to all
toplevel widgets.
.TP
\fBborg location satellites\fR
.
Returns GPS satellite information in \fBarray set\fR or \fBdict create\fR
form where the key is a numerical index and the values are per satellite
information in \fBarray set\fR or \fBdict create\fR form containing the
fields \fBindex\fR, \fBazimuth\fR, \fBelevation\fR, \fBprn\fR,
\fBsnr\fR, \fBalmanac\fR, \fBephemeris\fR, and \fBinfix\fR. Updates
in GPS information are indicated by the \fB<<GPSUpdate>>\fR virtual
event sent to all toplevel widgets.
.TP
\fBborg location nmea\fR
.
Returns a string made up of the NMEA sentences collected over the last
second. Updates in this string are indicated by the \fB<<NMEAUpdate>>\fR
virtual event sent to all toplevel widgets.
.SH "SYSTEM-RELATED COMMANDS"
.TP
\fBborg displaymetrics\fR
.
Returns information about the display in form suited for
\fBarray set\fR or \fBdict create\fR, e.g. display resolution,
pixel density. The entry \fBrotation\fR gives the current screen
rotation in degrees. The 0 degree point varies between devices,
typical smart phones report 0 for portrait, tablets report 0 for
landscape orientation. Refer to
\fBhttp://developer.android.com/reference/android/util/DisplayMetrics.html\fR
for more information.
.TP
\fBborg osbuildinfo\fR
.
Returns information about the operating system and device in form
suited for \fBarray set\fR or \fBdict create\fR, e.g. Android API
level, version, device name, manufacturer etc.
Refer to \fBhttp://developer.android.com/reference/android/os/Build.html\fR
for more information.
.TP
\fBborg queryfeatures\fR
.
Returns information about features of the system (a lengthy list of strings)
which is obtained from \fBhttp://developer.android.com/reference/android/content/pm/PackageManager.html#getSystemAvailableFeatures()\fR.
.TP
\fBborg queryconsts\fR \fIclassname\fR
.
Returns a dictionary of constants of the (loaded) Java class
\fIclassname\fR. The keys are the names of the constants,
the values their value. For example, the symbols of
\fBSYSTEM_UI_*\fR flags are available when you evaluate:
.sp 1
.nf
\fC
borg queryconsts android.view.View
\fR
.fi
.TP
\fBborg queryfields\fR \fIclassname\fR
.
Returns a dictionary of constants and static fields of the (loaded)
Java class \fIclassname\fR. This is similar to \fBborg queryconsts\fR
but allows to retrieve non-constant strings, too. Most useful in
combination with \fBhttp://developer.android.com/reference/android/os/Environment.html\fR.
.TP
\fBborg packageinfo\fR \fI?name?\fR
.
Returns information about installed packages or an individual package
if its \fIname\fR is given. In the first case, a list with package names
is returned, in the latter case a list of key value pairs with package
information which can be used for \fBarray set\fR or \fBdict create\fR.
.TP
\fBborg providerinfo\fR
.
Returns the authority names of all content providers known to the system
as a list.
.TP
\fBborg log\fR \fIprio tag message\fR
.
Writes the message \fImessage\fR to Android's system log with priority
\fIprio\fR (one of \fBverbose\fR, \fBdebug\fR, \fBinfo\fR, \fBwarn\fR,
\fBerror\fR, or \fBfatal\fR) and a user chosen prefix \fItag\fR. These
log messages can be displayed using \fBadb logcat\fR on the development
system.
.TP
\fBborg trace\fR \fImessage script\fR
.
Evaluates \fIscript\fR and adds \fImessage\fR before and after that
evaluation to Android's system trace buffer. This is supported only
on newer Android OS versions (4.3 and above) and further described
in \fBhttp://developer.android.com/reference/android/os/Trace.html\fR.
.TP
\fBborg systemproperties\fR \fI?name?\fR
.
Returns a list of system properties (a lengthy list of key value pairs)
or the value of a specific system property if \fIname\fR is given.
.TP
\fBborg checkpermission\fR \fIname\fR
.
Returns true or false depending on manifest permission \fIname\fR.
For a detailed list see the description in
\fBhttp://developer.android.com/reference/android/Manifest.permission.html\fR.
.SH "SENSOR-RELATED COMMANDS"
.TP
\fBborg sensor list\fR
.
Returns a list of the available sensors of the device. Each item is suited
for \fBarray set\fR or \fBdict create\fR and contains the fields
\fBindex\fR (integer index of the sensor, used to identify it),
\fBtype\fR (sensor type, one of \fBaccelerometer\fR, \fBtemperature\fR,
\fBgame_rotation_vector\fR, \fBgeomagnetic_rotation_vector\fR,
\fBgravity\fR, \fBgyroscope\fR, \fBgyroscope_uncalibrated\fR,
\fBlight\fR, \fBlinear_acceleration\fR, \fBmagnetic_field\fR,
\fBmagnetic_field_uncalibrated\fR, \fBorientation\fR,
\fBpressure\fR, \fBproximity\fR, \fBrelative_humidity\fR,
\fBrotation_vector\fR, \fBstep_counter\fR, and \fBstep_detector\fR),
\fBmindelay\fR (minimum update interval in milliseconds),
\fBmaxrange\fR (maximum range, floating point),
\fBresolution\fR (floating point),
\fBpower\fR (in mA, floating point),
and \fBname\fR (name of the sensor). See
\fBhttp://developer.android.com/reference/android/hardware/Sensor.html\fR
for more information.
.TP
\fBborg sensor enable|disable|state\fR \fIindex\fR
.
Turns the sensor identified by \fIindex\fR on or off, or returns its
state (0=off, 1=on). An enabled sensor generates \fB<<SensorUpdate>>\fR
virtual events which are sent to toplevel windows. These events are
either periodic updates or change notifications depending on the kind
of sensor and its refresh rate. If a sensor is not read out using
\fBborg sensor get ...\fR for a certain amount of time that sensor
is automatically disabled to conserve battery power. If the application
enters background (see virtual event \fB<<WillEnterBackground>>\fR) all
enabled sensors are disabled and re-enabled again when the application
comes back to foreground (see virtual event \fB<<WillEnterForeground>>\fR).
.TP
\fBborg sensor get\fR \fIindex\fR
.
Returns the last value acquired from the sensor identified by
\fIindex\fR as a list suited for \fBarray set\fR or \fBdict create\fR
containing the fields \fBindex\fR (integer),
\fBenabled\fR (sensor state, 0 or 1),
\fBmaxrange\fR (see above),
\fBresolution\fR (see above),
\fBaccuracy\fR (the accuracy of this value),
\fBvalues\fR (the sensor value, zero or more floating point numbers).
When both \fBaccelerometer\fR and \fRmagnetic_field\fR sensors are turned
on, the information for the \fBmagnetic_field\fR sensor has two additional
entries \fBorientation\fR (3 element list of azimuth, pitch, roll) and
\fBinclination\fR. The \fBpressure\fR sensor has an additional entry
\fBaltitude\fR (meters above sea level). See
\fBhttp://developer.android.com/reference/android/hardware/SensorEvent.html\fR
for more information.
.SH "ANDROID CONTENT (SHARED DATABASES)
.TP
\fBborg content query\fR \fIuri ?columns ?where ?whereargs ?orderby????\fR
.
Performs a query on an Android content provider given by \fIuri\fR and
returns a cursor token (a Tcl command which deals with that cursor).
The optional \fIcolumns\fR are a list of database columns to appear in
the result set, e.g.
.sp 1
.nf
\fC
set cursor [borg content query content://contacts/people {display_name _id}]
\fR
.fi
where an empty list of database columns works like the SQL statement "SELECT *".
The optional \fIwhere\fR and \fIwhereargs\fR parameters form the SQL WHERE
clause of the query. Question mark parameter markers in \fIwhere\fR are
positionally substituted by the information from the \fIwhereargs\fR list.
If the \fIwhere\fR parameter does not use a question mark parameter marker,
an empty parameter string is obligatory as in
.sp 1
.nf
\fC
set cursor [borg content query content://contacts/people {} "_id=810" {}]
\fR
.fi
which is equivalent to
.sp 1
.nf
\fC
set cursor [borg content query content://contacts/people {} "_id=?" 810]
\fR
.fi
The optional \fIorderby\fR forms the SQL ORDERBY part of the query.
Here's another example demonstrating how data is retrieved:
.sp 1
.nf
\fR
set cursor [borg content query content://settings/system]
# initially, cursor points before first row
while {[$cursor move 1]} {
    puts [$cursor getrow]
}
\fC
.fi
.TP
\fBborg content delete\fR \fIuri selection ?value ...?\fR
.
Deletes rows from an Android content provider given by \fIuri\fR and
returns the number of deleted rows. \fIselection\fR forms the SQL WHERE
clause of the deletion where question mark parameter markers are substituted
\fIvalue\fR. Example:
.sp 1
.nf
\fC
borg content delete content://settings/system name=? my_item
\fR
.fi
.TP
.
\fBborg content insert\fR \fIuri key value ...\fR
.
Inserts a row into an Android content provider given by \fIuri\fR and
returns another URI which identifies the inserted row. \fIkey\fR and
\fIvalue\fR are pairs of column name and column value for the SQL INSERT
operation. Example:
.sp 1
.nf
\fC
borg content insert content://settings/system name my_item value "Some value"
    -> content://settings/system/4711
\fR
.fi
.TP
\fBborg content update\fB \fIuri values ?selection ?args??\fR
.
Updates zero or more rows of an Android content provider given by \fIuri\fR
and returns the number of updated rows. \fIvalues\fR is a list made up of
a sequence of column names and column values. \fIselection\fR is the
optional SQL WHERE clause with question mark parameter markers. The
parameter markers are substituted by the values from \fIargs\fR. Example:
.sp 1
.nf
\fC
# system settings wants the name in the URI
borg content update content://settings/system/my_item {value {New Value}}
\fR
.fi
.SH "CURSORS FROM ANDROID CONTENT QUERIES"
When a \fBborg content\fR query returned a cursor token, this token is
a Tcl command to deal with the query's result set:
.TP
\fI$cursor\fR \fBclose\fR
.
Finishes the query and deletes the Tcl command.
.TP
\fI$cursor\fR \fBcolumnnames\fR
.
Returns a list of column names of the result set.
.TP
\fI$cursor\fR \fBcount\fR
.
Returns the number of rows of the result set.
.TP
\fI$cursor\fR \fBgetblob\fR \fIindex\fR
.
Returns the \fIindex\fRth column (zero-based) of the current row of the
result set as a base64 encoded string.
.TP
\fI$cursor\fR \fBgetdouble\fR \fIindex\fR
.
Returns the \fIindex\fRth column (zero-based) of the current row of the
result set as a floating point number.
.TP
\fI$cursor\fR \fBgetint\fR \fIindex\fR
.
Returns the \fIindex\fRth column (zero-based) of the current row of the
result set as a integer number.
.TP
\fI$cursor\fR \fBgetpos\fR
.
Returns the index of the current row (zero-based).
.TP
\fI$cursor\fR \fBgetrow\fR
.
Returns the current row as a Tcl list made up of column names and values,
like \fB{name1 value1 name2 value2}\fR in the order specified by the
cursor's constructor. Blobs from the result set are converted into
base64 encoded strings.
.TP
\fI$cursor\fR \fBgetstring\fR \fIindex\fR
.
Returns the \fIindex\fRth column (zero-based) of the current row of the
result set as a string.
.TP
\fI$cursor\fR \fBisnull\fR \fIindex\fR
.
Returns true when the \fIindex\fRth column (zero-based) of the current
row of the result set is an SQL NULL value.
.TP
\fI$cursor\fR \fBmove\fR \fIpos\fR
.
Relative move of the current row index. Negative \fIpos\fR goes backward.
.TP
\fI$cursor\fR \fBmoveto\fR \fIpos\fR
.
Absolute move of the current row index.
.SH "SPEECH RECOGNITION"
.TP
\fBborg speechrecognition intent\fR \fIargs cmd\fR
.
Use the speech recognition service. \fIargs\fR is a parameter list to
control the speech recognition (see
\fBhttp://developer.android.com/reference/android/speech/RecognizerIntent.html\fR
for more information). \fIcmd\fR is invoked when the speech recognition
is complete. That procedure receives the parameters \fIretcode\fR and
\fRdata\fR as in the callback for \fBborg activity\fR. \fIdata\fR is a
list of key value pairs suited for \fBarray set\fR or \fBdict create\fR.
.TP
\fBborg speechrecognition callback\fR \fIcmd\fR
.
Establishes \fIcmd\fR as global callback procedure receiving speech
recognition events as described by the RecognitionListener interface
(see \fBhttp://developer.android.com/reference/android/speech/RecognitionListener.html\fR
for more information). That procedure receives the parameters \fIretcode\fR
and \fIdata\fR as in the callback for \fBborg activity\fR. \fIdata\fR is a
list of key value pairs suited for \fBarray set\fR or \fBdict create\fR.
There are up to two special keys present in data: \fItype\fR giving the
event type (one of \fBresult\fR, \fBpartialresult\fR, \fBready\fR,
\fBevent\fR, \fBrms\fR, \fBend\fR, \fBbegin\fR) and \fIvalue\fR giving
numeric values for certain event types (error code for \fBerror\fR,
audio level for \fBrms\fR).
.TP
\fBborg speechrecognition start\fB \fIargs\fR
.
Starts the speech recognition. For \fIargs\fR see the description in
\fBborg speechrecognition intent ....\fR.
.TP
\fBborg speechrecognition cancel\fR
.
Immediately cancels the speech recognition. No further events are
reported through the global callback procedure.
.TP
\fBborg speechrecognition stop\fR
.
Stops the speech recognition. Events can be still reported through
the global callback procedure.
.SH "TELEPHONE-RELATED COMMANDS"
.TP
\fBborg phoneinfo\fR
Returns information about the current state of the telephone as a
list suited for \fBarray set\fR or \fBdict create\fR. This information
is only available when the application manifest has the
\fBandroid.permission.READ_PHONE_STATE\fR permission (which is left out
in current AndroWish releases). For further information see the Android
documentation on the classes
\fBhttp://developer.android.com/reference/android/telephony/TelephonyManager.html\fR,
\fBhttp://developer.android.com/reference/android/telephony/PhoneStateListener.html\fR, and
\fBhttp://developer.android.com/reference/android/telephony/SignalStrength.html\fR.
.TP
\fBborg sendsms phonenumber msg\fR \fI?action_send action_delivered smsc?\fR
.
Sends an SMS text message \fImsg\fR to \fIphonenumber\fR. The optional
arguments \fIaction_send\fR and \fIaction_delivered\fR are the action
names of broadcast intents which are generated on state changes regarding
the SMS message and can be captured by a broadcast listener callback
(see \fBborg broadcast register\fR et.al.). The optional argument
\fIsmsc\fR is the SMS message center. The command returns 1 on successful
start of the send operation, 0 otherwise. It is only available when the
application manifest has the \fBandroid.permission.SEND_SMS\fR permission
(which is left out in current AndroWish releases). For further information
see the Android documentation on the class
\fBhttp://developer.android.com/reference/android/telephony/SmsManager.html\fR.
.SH BROADCAST
.TP
\fBborg broadcast list\fR \fI?action?\fR
.
Returns a list of all registered broadcast handlers in the interpreter
when \fIaction\fR is omitted. Otherwise it returns the command to be
invoked when the broadcast \fIaction\fR is received.
.TP
\fBborg broadcast register\fR \fIaction cmd\fR
.
Registers the command \fIcmd\fR to be invoked when the broadcast \fIaction\fR
is received.
.TP
\fBborg broadcast unregister\fR \fIaction\fR
.
Unregisters the command bound to the reception of the broadcast \fIaction\fR.
.TP
\fBborg broadcast send\fR \fIaction ?uri type categories arguments?\fR
.
Sends the broadcast \fIaction\fR with the optional properties/arguments
\fIuri\fR, \fItype\fR, \fIcategories\fR, and \fIarguments\fR. For the
optional items see the description in \fBborg activity\fR.
.SH LOCALE
.TP
\fBborg locale ?default?\fR
.
Returns information about the current default locale of the JVM. The result
is in a form suitable for \fBarray set\fR or \fBdict get\fR and contains
the fields \fBcountry\fR, \fBdisplay_country\fR, \fBdisplay_language\fR,
\fBdisplay_name\fR, \fBdisplay_variant\fR, \fBiso3_country\fR,
\fBiso3_language\fR, \fBlanguage\fR, and \fBvariant\fR.
.TP
\fBborg locale\fR \fIlang\fR
.
Returns information about the locale identified by \fIlang\fR, which must
be specified as a two letter code with an optional variant and an optional
encoding part, e.g. \fBde\fR, \fBfr_BE\fR, or \fBen_GB.UTF-8\fR.
.TP
\fBborg locale tts\fR
.
Returns information about the locale used for text-to-speech. If
text-to-speech facilities weren't used when the command is invoked,
the returned information is identical with \fBborg locale default\fR.
.TP
\fBborg locale set\fR \fIlang\fR
.
Changes the current locale of the JVM to the language code \fIlang\fR.
If the locale change succeeded, the environment variable \fBenv(LANG)\fR
is changed accordingly.
.SH "CAMERA-RELATED COMMANDS
.
Camera support is available on devices with Android 3.0 or newer.
.TP
\fBborg camera close\fR
.
Close the camera. Returns non-zero on success, zero otherwise,
 e.g. when the camera was already closed.
.TP
\fBborg camera current\fR
.
Returns the currently opened camera number or -1 when the camera
is not opened. On many tablets camera 0 is the back-facing camera,
and camera 1 the front-facing one.
.TP
\fBborg camera grayimage\fR \fI?photo?\fR
.br
\fBborg camera greyimage\fR \fI?photo?\fR
.
Copies the most recent camera preview as grey image into the photo
image identified by \fIphoto\fR. Returns non-zero on success or zero
if no data transfer has taken place. If \fIphoto\fR is omitted, a four
element list is returned with the first element being the image width,
the second the image height, the third the number of bytes per pixel,
and the last the image's grey values with 1 byte per pixel as a byte array.
In this case an error is indicated by throwing an exception. An experimental
feature is direct rendering into a widget. In this case the \fIphoto\fR
parameter must be the path name of a Tk window which should be a frame
or toplevel widget. When the camera is started the background color of
the widget should be set to an empty string so that no drawing calls from
Tk are carried out. When the camera is stopped, it should be reset to black.
.TP
\fBborg camera image\fR \fI?photo?\fR
.
Copies the most recent camera preview as color image into the photo
image identified by \fIphoto\fR. Returns non-zero on success or zero
if no data transfer has taken place. If \fIphoto\fR is omitted, a four
element list is returned with the first element being the image width,
the second the image height, the third the number of bytes per pixel,
and the last the image's RGB values with 3 bytes per pixel in red, green,
blue order as a byte array. In this case an error is indicated by
throwing an exception. An experimental feature is direct rendering into
a widget. In this case the \fIphoto\fR parameter must be the path name
of a Tk window which should be a frame or toplevel widget. When the camera
is started the background color of the widget should be set to an empty
string so that no drawing calls from Tk are carried out. When the camera
is stopped, it should be reset to black.
.TP
\fBborg camera info\fR
.
Returns information about the currently opened camera as a two element
list made up of integer numbers. The first is the rotation of the camera
relative to the screen, the second an indication for front-facing (1) or
back-facing (0) view of the camera relative to the screen. If no camera
is opened the result is an empty list.
.TP
\fBborg camera jpeg\fR
.
Returns a JPEG image of the camera as a byte array after preview has been
started using \fBborg camera start\fR and JPEG capture has been initiated
with \fBborg camera takejpeg\fR. In contrast to \fBborg camera image ...\fR
this command consumes the image. If no JPEG picture is available when the
command is invoked, an error is thrown.
.TP
\fBborg camera mirror \fI?x y?\fR
.
Controls mirroring of preview images which are mirrored along the X axis
when \fIx\fR is one and along the Y axis when \fIy\fR is one.
\fBborg camera mirror 0 1\fR is useful to mirror the preview image of a
front-facing camera.
.TP
\fBborg camera numcameras\fR
.
Returns the number of available cameras.
.TP
\fBborg camera open \fI?num?\fR
.
Opens camera number \fInum\fR and returns non-zero on success. Only one
camera can be opened at any one time. On error or when a camera is already
opened, zero is returned. When \fInum\fR is omitted the first camera is
opened (usually the back-facing if two cameras are available).
.TP
\fBborg camera orientation\fR \fI?degrees?\fR
.
Returns the current orientation of the preview image relative to the
screen or changes it to \fIdegrees\fR.
.TP
\fBborg camera parameters\fR \fI?key value ...?\fR
.
Returns or changes camera parameters given as key-value pairs, e.g.
\fBpreview-size 320x240\fR will change the size of preview images to
width 320 and height 240. The command returns the current camera
parameters (after the potential change, when keys and values where given)
as a key-value list which can be processed with \fBarray set\fR or
\fBdict get\fR.
.TP
\fBborg camera start\fR
.
Starts the camera. Acquired preview images are reported by the virtual
event \fB<<ImageCapture>>\fR. Returns non-zero on success, zero when the
camera is already started or an error has been detected. When the
acquisition of camera preview images is running \fBborg camera image\fR or
\fBborg camera greyimage\fR must be invoked within 5 seconds, otherwise
image acquisition is automatically stopped and needs to be restarted with
another \fBborg camera start\fR command.
.TP
\fBborg camera state\fR
.
Returns the current camera state as string: \fBunknown\fR, \fBclosed\fR,
\fBstopped\fR, or \fBcapture\fR.
.TP
\fBborg camera stop\fR
.
Stops the camera, i.e. no more images are acquired. Returns non-zero
on success, zero when the camera is already stopped or an error has
been detected.
.TP
\fBborg camera takejpeg\fR
.
Requests the camera to take a JPEG image. It is required that the
camera is capturing, i.e. \fBborg camera start\fR has been called
already. The point in time when acquisition of the JPEG image starts
is indicated by the virtual event \fB<<Shutter>>\fR. When the JPEG image
is ready for processing the virtual event \fB<<PictureTaken>>\fR is sent.
The command returns a non-zero value when JPEG capture is in progress,
zero on error.
.SH "NFC RELATED COMMANDS"
.
Many devices have hardware support for NFC (Near Field Communication)
tags. In order to deal with such items, a callback command for the
broadcast \fBtk.tcl.wish.nfc\fR must be registered. The callback's
arguments contain information on the NFC tag in these keys:
.TP
\fBandroid.nfc.extra.ID\fR
.
The the base64 encoded ID of the tag.
.TP
\fBandroid.nfc.extra.TAG\fR
.
The underlying/supported technologies of the tag as a string.
Currently only \fBandroid.nfc.tech.Ndef\fR and
\fBandroid.nfc.tech.NdefFormatable\fR are detected and handled.
.TP
\fBandroid.nfc.extra.NDEF_MESSAGES\fR
.
If present contains the NDEF formatted information contained in
the tag encoded in base64.
.PP
The last read tag ID is remembered and can be dealt with using these
\fBborg\fR subcommands:
.TP
\fBborg ndefread\fR \fItagid ?cached?\fR
.
Returns the current or \fIcached\fR NDEF formatted information
contained in the tag given \fItagid\fR as base64 encoded string.
.TP
\fBborg ndefwrite\fR \fItagid ndefmsg\fR
.
Writes the NDEF formatted information (one or more NDEF records) in
\fIndefmsg\fR which must be base64 encoded into the tag given \fItagid\fR.
.TP
\fBborg ndefformat\fR \fItagid ndefmsg\fR
.
Formats an empty tag and like \fBborg ndefwrite\fR writes NDEF formatted
information into the tag. An unformatted tag can be detected in the
\fBtk.tcl.wish.nfc\fR callback procedure by inspecting the technology
information: The string \fBandroid.nfc.tech.Ndef\fR is absent but the
string \fBandroid.nfc.tech.NdefFormatable\fR is present.
.SH "OS ENVIRONMENT"
.
Information provided by the \fBhttp://developer.android.com/reference/android/os/Environment.html\fR class.
.TP
\fBborg osenvironment datadir\fR
.
Return the user data directory (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#getDataDirectory()\fR).
.TP
\fBborg osenvironment downloadcachedir\fR
.
Return the download/cache content directory (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#getDownloadCacheDirectory()\fR).
.TP
\fBborg osenvironment externalstoragedir\fR
.
Return the primary shared/external storage directory (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#getExternalStorageDirectory()\fR).
.TP
\fBborg osenvironment externalstoragepublicdir\fB \fI?type?\fR
.
Get a top-level shared/external storage directory for placing files of
a particular type (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#getExternalStoragePublicDirectory(java.lang.String)\fR).
The parameter \fItype\fR can be obtained by using information returned from
\fBborg queryfields android.os.Environment\fR.
.TP
\fBborg osenvironment externalstoragestate\fR
.
Returns the current state of the primary shared/external storage media (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#getExternalStorageState()\fR).
.TP
\fBborg osenvironment isexternalstorageemulated\fR
.
Returns whether the primary shared/external storage media is emulated (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#isExternalStorageEmulated()\fR).
.TP
\fBborg osenvironment isexternalstorageremovable\fR
.
Returns whether the primary shared/external storage media is physically
removable (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#isExternalStorageRemovable()\fR).
.TP
\fBborg osenvironment rootdir\fR
.
Return root of the "system" partition holding the core Android OS (see
\fBhttp://developer.android.com/reference/android/os/Environment.html#getRootDirectory()\fR).
.SH "SHARED PREFERENCES"
.
An interface to
\fBhttps://developer.android.com/reference/android/content/SharedPreferences.html\fR
is provided using the \fBborg sharedpreferences\fR subcommand. This
allows to load/store typed values of an application in a key-value store
which does not require extra file permissions.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBgetboolean\fR \fIkey default\fR
.
Return a boolean value (using \fIdefault\fR if not present) from the
shared preference file identified by \fIfile\fR stored under the name
\fIkey\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBgetfloat\fR \fIkey default\fR
.
Return a floating point value (using \fIdefault\fR if not present) from the
shared preference file identified by \fIfile\fR stored under the name
\fIkey\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBgetint\fR \fIkey default\fR
.
Return an integer value (using \fIdefault\fR if not present) from the
shared preference file identified by \fIfile\fR stored under the name
\fIkey\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBgetlong\fR \fIkey default\fR
.
Return a 64 bit integer value (using \fIdefault\fR if not present) from the
shared preference file identified by \fIfile\fR stored under the name
\fIkey\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBgetstring\fB \fIkey default\fR
.
Return a string value (using \fIdefault\fR if not present) from the
shared preference file identified by \fIfile\fR stored under the name
\fIkey\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBsetboolean\fR \fIkey value\fR
.
Store the boolean \fIvalue\fR into the shared preference file identified
by \fIfile\fR under the name \fIkey\fR.
.TP
\fBborg sharedpreferences \fIfile\fR \fBsetfloat\fR \fIkey value\fR
.
Store the floating point \fIvalue\fR into the shared preference file identified
by \fIfile\fR under the name \fIkey\fR.
.TP
\fBborg sharedpreferences \fIfile\fR \fBsetint\fB \fIkey value\fR
.
Store the integer \fIvalue\fR into the shared preference file identified
by \fIfile\fR under the name \fIkey\fR.
.TP
\fBborg sharedpreferences \fIfile\fR \fBsetlong\fR \fIkey value\fR
.
Store the 64 bit integer \fIvalue\fR into the shared preference file identified
by \fIfile\fR under the name \fIkey\fR.
.TP
\fBborg sharedpreferences \fIfile\fR \fBsetstring\fR \fIkey value\fR
.
Store the string \fIvalue\fR into the shared preference file identified
by \fIfile\fR under the name \fIkey\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fI \fBremove\fR \fIkey\fR
.
Remove the value stored under the name \fIkey\fR from the shared
preference file identified by \fIfile\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBclear\fR
.
Remove all key-value pairs stored in the shared preference file
identified by \fIfile\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBall\fR
.
Return a Tcl list suitable for \fBarray set\fR of all key-value pairs
from the shared preference file identified by \fIfile\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBalltypes\fR
.
Return a Tcl list suitable for \fBarray set\fR of all keys and their
respective value types from the shared preference file identified
by \fIfile\fR.
.TP
\fBborg sharedpreferences\fR \fIfile\fR \fBkeys\fR
.
Return a Tcl list of all keys from the shared preference file identified
by \fIfile\fR.
.SH GENERAL
.TP
\fBborg withdraw\fR
.
Hides the application window by putting it to the end of Android's
activity stack. Can be useful when bound to the Back key (\fB<Key-Break>\fR
in AndroWish). There's no opposite command, i.e. the application can be
brought to front again only by user interaction.
.TP
\fBborg brightness\fR \fI?percent?\fR
.
Sets or gets the screen brightness. If the percentage is negative,
the default value is restored.
.TP
\fBborg onintent\fR \fI?command?\fR
.
Sets or gets the callback \fIcommand\fR which is evaluated when the
application received an Android intent. When evaluating that command,
the parameters action name, URI, MIME type, categories, arguments from
the intent are appended. When the callback is set for the first time,
it gets immediately evaluated with the parameters of the current
(startup) intent.
.TP
\fBborg queryactivites\fR \fIaction ?uri type categories component?\fR
.
Queries Android's activity manager for activities on the given intent
parameters. \fIcategories\fR and \fIcomponent\fR are optional lists.
The latter when non-empty must contain the two elements package name and
class name.
.TP
\fBborg queryservices\fR \fIaction ?uri type categories component?\fR
.
Queries Android's activity manager for services on the given intent
parameters, similar to \fBborg queryactivities\fR.
.TP
\fBborg querybroadcastreceivers\fR \fIaction ?uri type categories component?\fR
.
Queries Android's activity manager for broadcast receivers on the given
intent parameters, similar to \fBborg queryactivities\fR.
.TP
\fBborg screenorientation\fR \fI?orient?\fR
.
Queries or switches the screen orientation, \fIorient\fR can be one of
\fBunspecified\fR, \fBlandscape\fR, \fBportrait\fR, \fBuser\fR,
\fBbehind\fR, \fBsensor\fR, \fBnosensor\fR, \fBsensorlandscape\fR,
\fBsensorportrait\fR, \fBreverselandscape\fR, \fBreverseportrait\fR,
\fBfullsensor\fR, \fBuserlandscape\fR, \fBuserportrait\fR,
\fBfulluser\fR, or \fBlocked\fR.
.TP
\fBborg keyboardinfo\fR
.
Returns information about the current keyboard configuration as a list
suited for \fBarray set\fR or \fBdict create\fR with these fields:
\fBkeyboard\fR with possible values \fBnone\fR, \fB12key\fR, and
\fBqwerty\fR, \fBhidden\fR and \fBhard_hidden\fR with values 0 (not hidden),
1, (hidden), and -1 (unknown). This can be read out any time. An update
in keyboard configuration state is indicated by the virtual event
\fB<<KeyboardInfo>>\fR.
.TP
\fBborg alarm clear\fR \fIaction ?uri type categories component?\fR
.
Clears an alarm whose pattern matches the given intent parameters.
.TP
\fBborg alarm set\fR \fIwhen repeat action ?uri type categories component arg ...?\fR
.
Sets an alarm to fire at \fIwhen\fR (UN*X epoch, seconds) with repetition
each \fIrepeat\fR seconds, when \fIrepeat\fR is greater than 0. The alarm
sends an intent made up of the given intent parameters (\fIaction\fR etc.).
The \fIcomponent\fR parameter is interpreted specially: when empty no
component is set on the intent, when given as self the calling package/class
is set as component for the intent (sending the intent to itself, i.e. the
callback of \fBborg onintent\fR will receive it). In all other cases
component must be a list with the two elements package name and class name.
\fIarg\fR and following parameters are added to the intent as key value pairs
of extra data.
.TP
\fBborg alarm wakeup\fR \fIwhen repeat action ?uri type categories component arg ...?\fR
.
Like \fBborg alarm set\fR but this type of alarm is able to wake up the
device when suspended (device behavior depends on lock screen settings).
.TP
\fBborg activity\fR \fIaction uri type ?categories ?component ?arguments ?callback????\fR
.
This a very flexible command that allows extensive access to the Android
OS and other applications. \fIcategories\fR, \fIcomponent\fR, and
\fIarguments\fI are optional lists. \fIcallback\fR is the name of
the procedure that is evaluated when the activity \fIaction\fR is
complete. \fIarguments\fR are key-value pairs where the values are
mapped to Java strings by default. If the key is a 2-element list
made up of a data type indicator (\fBint\fR, \fBbyte\fR, \fBshort\fR,
\fBchar\fR, \fBlong\fR, \fBfloat\fR, \fBdouble\fR, \fBUri\fR)
followed by the key, the value is converted to that data type.
See below for some examples of this command.
.TP
\fBborg systemui\fR \fI?flags?\fR
.
Returns or sets various flags to control certain aspects of system UI
elements displayed on the device's screen. This is currently supported
only on Android 4.4 and newer versions. See the documentation in
\fBhttp://developer.android.com/reference/android/view/View.html\fR
for a description of the \fBSYSTEM_UI_*\fR flags.
.SH EVENTS
.
These events are generated for/by certain \fBborg\fR related commands.
They are reported to toplevel widgets only.
.TP
\fB<<LocationUpdate>>\fR
.
Location information has been updated and can be read out using
\fBborg location get\fR.
.TP
\fB<<GPSUpdate>>\fR
.
GPS related information has been updated and can be read out using
\fBborg location gps\fR and \fBborg location satellites\fR.
.TP
\fB<<NMEAUpdate>>\fR
.
NMEA data has been updated and can be read out using
\fBborg location nmea\fR.
.TP
\fB<<NetworkInfo>>\fR
.
Network state has changed and can be read out using
\fBborg networkinfo\fR.
.TP
\fB<<TetherInfo>>\fR
.
Tethering state has changed and can be read out using
\fBborg tetherinfo\fR.
.TP
\fB<<Bluetooth>>\fR
.
A change in Bluetooth state and/or scan mode has occured and
can be read out using \fBborg bluetooth state\fR and/or
\fBborg bluetooth scanmode\fR.
.TP
\fB<<SensorUpdate>>\fR
.
A sensor can be read using \fBborg sensor get\fR.
The field \fB%x\fR identifies the sensor.
.TP
\fB<<KeyboardInfo>>\fR
.
The keyboard configuration did change and can be obtained by
\fBborg keyboardinfo\fR.
.TP
\fB<<PhoneCallState>>\fR
.
The call state of the telephone has changed and can be obtained by
\fBborg phoneinfo\fR.
.TP
\fB<<PhoneDataActivity>>\fR
.
The state of the telephone's data state has changed and can be
obtained by \fBborg phoneinfo\fR.
.TP
\fB<<PhoneConnectionState>>\fR
.
The state of the telephone's connectivity has changed and can be
obtained by \fBborg phoneinfo\fR.
.TP
\fB<<PhoneServiceState>>\fR
.
The service state of the telephone has changed and can be
obtained by \fBborg phoneinfo\fR.
.TP
\fB<<PhoneSignalStrength>>\fR
.
The signal quality of the telephone has changed and can be
obtained by \fBborg phoneinfo\fR.
.TP
\fB<<ImageCapture>>\fR
.
A preview camera image is ready and can be obtained by
\fBborg camera image\fR or \fBborg camera greyimage\fR.
The field \fB%x\fR represents the camera capture state
(true when preview images are captured, false when capture will be stopped).
.TP
\fB<<Shutter>>\fR
.
The camera is about to take a JPEG image.
.TP
\fB<<PictureTaken>>\fR
.
The camera has taken a JPEG picture which can be obtained and
consumed by \fBborg camera jpeg\fR. When the event is reported,
image capture of preview images is automatically stopped.
.TP
\fB<<USBAttached>>\fR
.
A USB device was attached. To find out information about the device,
use the \fBborg usbdevices\fR command. This event is generated on
Android 4.4 and newer.
.TP
\fB<<USBDetached>>\fR
.
An USB device was detached (opposite of \fB<<USBAttached>>\fB).
.TP
\fB<<TTSInit>>\fR
.
The text-to-speech facility has been started up or shut down.
The \fB%x\fR substitution gives an indication for startup (=0),
error (=-1), and unavailability (<-1). Supported in Android 4.1 and higher.
.TP
\fB<<TTSStart>>\fR
.
Speech output of a string has started. The \fB%x\fR substitution
is equal to the integer returned by the corresponding
\fBborg speak\fR command. Supported in Android 4.1 and higher.
.TP
\fB<<TTSError>>\fR
.
Error indication for a string to be spoken by \fBborg speak\fR.
The \fB%x\fR substitution is equal to the integer returned by
the corresponding \fBborg speak\fR command as for the \fB<<TTSStart>>\fR
event. Supported in Android 4.1 and higher.
.TP
\fB<<TTSDone>>\fR
.
End of speech indication for a string to be spoken. The \fB%x\fR
substitution is equal to the integer returned by the corresponding
\fBborg speak\fR command as for the \fB<<TTSStart>>\fR event.
Supported in Android 4.1 and higher.
.SH "BORG ACTIVITY EXAMPLES"
.
Sample code to open a browser on the Tcl'ers wiki:
.sp 1
.nf
\fC
borg activity android.intent.action.VIEW http://wiki.tcl.tk text/html
\fR
.fi
.sp 1
Sample code to launch the "wifi settings" page:
.sp 1
.nf
\fC
borg activity android.settings.WIFI_SETTINGS {} {} {} {} {}
\fR
.fi
.sp 1
Sample code to capture an image (only makes thumbnails):
.sp 1
.nf
\fC
proc callback {retcode action uri mimetype categories data} {
    if {$retcode == -1} {
        # SUCCESS
        array set result $data
        if {[info exists result(data)]} {
            myphoto configure -data $result(data)
        }
    }
}
package require Img
image create photo myphoto
borg activity android.media.action.IMAGE_CAPTURE {} {} {} {} {} callback
\fR
.fi
.sp 1
Sample code to capture an image, which makes full size images but
requires a file on external storage:
.sp 1
.nf
\fC
proc callback {filename retcode action uri mimetype categories data} {
    if {$retcode == -1} {
        # SUCCESS
        myphoto configure -file $filename
        catch {file delete -force $filename}
    }
}
package require Img
image create photo myphoto
set filename [file join $env(EXTERNAL_FILES) myphoto.jpeg]
borg activity android.media.action.IMAGE_CAPTURE {} {} {} {} \\
    [list {Uri output} file://$filename] [list callback $filename]
\fR
.fi
.sp 1
Reading barcodes using the barcode scanner from
\fBhttp://code.google.com/p/zxing\fR (which needs to be be
installed on your device):
.sp 1
.nf
\fC
proc barcode_read {code action uri type cat data} {
    array set result $data
    if {[info exists result(SCAN_RESULT)]} {
        # that is the barcode
        # result(SCAN_RESULT_FORMAT) is the barcode format
    }
}
borg activity com.google.zxing.client.android.SCAN \\
    {} {} {} {} {} barcode_read
\fC
.fi
Changes to jni/tcl/generic/regcustom.h.
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
typedef int celt;		/* Type to hold chr, or NOCELT */
#define	NOCELT (-1)		/* Celt value which is not valid chr */
#define	CHR(c) (UCHAR(c))	/* Turn char literal into chr literal */
#define	DIGITVAL(c) ((c)-'0')	/* Turn chr digit into its value */
#if TCL_UTF_MAX > 3
#define	CHRBITS	32		/* Bits in a chr; must not use sizeof */
#define	CHR_MIN	0x00000000	/* Smallest and largest chr; the value */
#define	CHR_MAX	0xffffffff	/* CHR_MAX-CHR_MIN+1 should fit in uchr */
#else
#define	CHRBITS	16		/* Bits in a chr; must not use sizeof */
#define	CHR_MIN	0x0000		/* Smallest and largest chr; the value */
#define	CHR_MAX	0xffff		/* CHR_MAX-CHR_MIN+1 should fit in uchr */
#endif

/*
 * Functions operating on chr.
 */

#define	iscalnum(x)	Tcl_UniCharIsAlnum(x)







|



|







88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
typedef int celt;		/* Type to hold chr, or NOCELT */
#define	NOCELT (-1)		/* Celt value which is not valid chr */
#define	CHR(c) (UCHAR(c))	/* Turn char literal into chr literal */
#define	DIGITVAL(c) ((c)-'0')	/* Turn chr digit into its value */
#if TCL_UTF_MAX > 3
#define	CHRBITS	32		/* Bits in a chr; must not use sizeof */
#define	CHR_MIN	0x00000000	/* Smallest and largest chr; the value */
#define	CHR_MAX	0xFFFFFFFF	/* CHR_MAX-CHR_MIN+1 should fit in uchr */
#else
#define	CHRBITS	16		/* Bits in a chr; must not use sizeof */
#define	CHR_MIN	0x0000		/* Smallest and largest chr; the value */
#define	CHR_MAX	0xFFFF		/* CHR_MAX-CHR_MIN+1 should fit in uchr */
#endif

/*
 * Functions operating on chr.
 */

#define	iscalnum(x)	Tcl_UniCharIsAlnum(x)
Changes to jni/tcl/generic/regguts.h.
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

#define	NOTREACHED	0
#define	xxx		1

#define	DUPMAX	_POSIX2_RE_DUP_MAX
#define	DUPINF	(DUPMAX+1)

#define	REMAGIC	0xfed7		/* magic number for main struct */

/*
 * debugging facilities
 */
#ifdef REG_DEBUG
/* FDEBUG does finite-state tracing */
#define	FDEBUG(arglist)	{ if (v->eflags&REG_FTRACE) printf arglist; }







|







97
98
99
100
101
102
103
104
105
106
107
108
109
110
111

#define	NOTREACHED	0
#define	xxx		1

#define	DUPMAX	_POSIX2_RE_DUP_MAX
#define	DUPINF	(DUPMAX+1)

#define	REMAGIC	0xFED7		/* magic number for main struct */

/*
 * debugging facilities
 */
#ifdef REG_DEBUG
/* FDEBUG does finite-state tracing */
#define	FDEBUG(arglist)	{ if (v->eflags&REG_FTRACE) printf arglist; }
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

/*
 * the insides of a regex_t, hidden behind a void *
 */

struct guts {
    int magic;
#define	GUTSMAGIC	0xfed9
    int cflags;			/* copy of compile flags */
    long info;			/* copy of re_info */
    size_t nsub;		/* copy of re_nsub */
    struct subre *tree;
    struct cnfa search;		/* for fast preliminary search */
    int ntree;			/* number of subre's, plus one */
    struct colormap cmap;







|







413
414
415
416
417
418
419
420
421
422
423
424
425
426
427

/*
 * the insides of a regex_t, hidden behind a void *
 */

struct guts {
    int magic;
#define	GUTSMAGIC	0xFED9
    int cflags;			/* copy of compile flags */
    long info;			/* copy of re_info */
    size_t nsub;		/* copy of re_nsub */
    struct subre *tree;
    struct cnfa search;		/* for fast preliminary search */
    int ntree;			/* number of subre's, plus one */
    struct colormap cmap;
Changes to jni/tcl/win/tclWin32Dll.c.
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

	"movq	%[rptr],	%%rdi"		"\n\t"
	"movl	%[index],	%%eax"		"\n\t"
	"cpuid"					"\n\t"
	"movl	%%eax,		0x0(%%rdi)"	"\n\t"
	"movl	%%ebx,		0x4(%%rdi)"	"\n\t"
	"movl	%%ecx,		0x8(%%rdi)"	"\n\t"
	"movl	%%edx,		0xc(%%rdi)"	"\n\t"

	:
	/* No outputs */
	:
	[index]		"m"	(index),
	[rptr]		"m"	(regsPtr)
	:







|







635
636
637
638
639
640
641
642
643
644
645
646
647
648
649

	"movq	%[rptr],	%%rdi"		"\n\t"
	"movl	%[index],	%%eax"		"\n\t"
	"cpuid"					"\n\t"
	"movl	%%eax,		0x0(%%rdi)"	"\n\t"
	"movl	%%ebx,		0x4(%%rdi)"	"\n\t"
	"movl	%%ecx,		0x8(%%rdi)"	"\n\t"
	"movl	%%edx,		0xC(%%rdi)"	"\n\t"

	:
	/* No outputs */
	:
	[index]		"m"	(index),
	[rptr]		"m"	(regsPtr)
	:
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

	"leal	%[registration], %%edx"		"\n\t"
	"movl	%%fs:0,		%%eax"		"\n\t"
	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
	"leal	1f,		%%eax"		"\n\t"
	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
	"movl	%%esp,		0xc(%%edx)"	"\n\t" /* esp */
	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */

	/*
	 * Link the TCLEXCEPTION_REGISTRATION on the chain
	 */

	"movl	%%edx,		%%fs:0"		"\n\t"

	/*
	 * Do the CPUID instruction, and save the results in the 'regsPtr'
	 * area.
	 */

	"movl	%[rptr],	%%edi"		"\n\t"
	"movl	%[index],	%%eax"		"\n\t"
	"cpuid"					"\n\t"
	"movl	%%eax,		0x0(%%edi)"	"\n\t"
	"movl	%%ebx,		0x4(%%edi)"	"\n\t"
	"movl	%%ecx,		0x8(%%edi)"	"\n\t"
	"movl	%%edx,		0xc(%%edi)"	"\n\t"

	/*
	 * Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION and
	 * store a TCL_OK status.
	 */

	"movl	%%fs:0,		%%edx"		"\n\t"







|



















|







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

	"leal	%[registration], %%edx"		"\n\t"
	"movl	%%fs:0,		%%eax"		"\n\t"
	"movl	%%eax,		0x0(%%edx)"	"\n\t" /* link */
	"leal	1f,		%%eax"		"\n\t"
	"movl	%%eax,		0x4(%%edx)"	"\n\t" /* handler */
	"movl	%%ebp,		0x8(%%edx)"	"\n\t" /* ebp */
	"movl	%%esp,		0xC(%%edx)"	"\n\t" /* esp */
	"movl	%[error],	0x10(%%edx)"	"\n\t" /* status */

	/*
	 * Link the TCLEXCEPTION_REGISTRATION on the chain
	 */

	"movl	%%edx,		%%fs:0"		"\n\t"

	/*
	 * Do the CPUID instruction, and save the results in the 'regsPtr'
	 * area.
	 */

	"movl	%[rptr],	%%edi"		"\n\t"
	"movl	%[index],	%%eax"		"\n\t"
	"cpuid"					"\n\t"
	"movl	%%eax,		0x0(%%edi)"	"\n\t"
	"movl	%%ebx,		0x4(%%edi)"	"\n\t"
	"movl	%%ecx,		0x8(%%edi)"	"\n\t"
	"movl	%%edx,		0xC(%%edi)"	"\n\t"

	/*
	 * Come here on a normal exit. Recover the TCLEXCEPTION_REGISTRATION and
	 * store a TCL_OK status.
	 */

	"movl	%%fs:0,		%%edx"		"\n\t"
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728

	/*
	 * Come here however we exited. Restore context from the
	 * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	 */

	"2:"					"\t"
	"movl	0xc(%%edx),	%%esp"		"\n\t"
	"movl	0x8(%%edx),	%%ebp"		"\n\t"
	"movl	0x0(%%edx),	%%eax"		"\n\t"
	"movl	%%eax,		%%fs:0"		"\n\t"

	:
	/* No outputs */
	:







|







714
715
716
717
718
719
720
721
722
723
724
725
726
727
728

	/*
	 * Come here however we exited. Restore context from the
	 * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	 */

	"2:"					"\t"
	"movl	0xC(%%edx),	%%esp"		"\n\t"
	"movl	0x8(%%edx),	%%ebp"		"\n\t"
	"movl	0x0(%%edx),	%%eax"		"\n\t"
	"movl	%%eax,		%%fs:0"		"\n\t"

	:
	/* No outputs */
	:
Changes to jni/tcl/win/tclWinChan.c.
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982

    handle = CreateFileW(nativeName, accessMode, shareMode,
	    NULL, createMode, flags, (HANDLE) NULL);

    if (handle == INVALID_HANDLE_VALUE) {
	DWORD err = GetLastError();

	if ((err & 0xffffL) == ERROR_OPEN_FAILED) {
	    err = (mode & O_CREAT) ? ERROR_FILE_EXISTS : ERROR_FILE_NOT_FOUND;
	}
	TclWinConvertError(err);
	if (interp != (Tcl_Interp *) NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "couldn't open \"%s\": %s",
		    TclGetString(pathPtr), Tcl_PosixError(interp)));







|







968
969
970
971
972
973
974
975
976
977
978
979
980
981
982

    handle = CreateFileW(nativeName, accessMode, shareMode,
	    NULL, createMode, flags, (HANDLE) NULL);

    if (handle == INVALID_HANDLE_VALUE) {
	DWORD err = GetLastError();

	if ((err & 0xFFFFL) == ERROR_OPEN_FAILED) {
	    err = (mode & O_CREAT) ? ERROR_FILE_EXISTS : ERROR_FILE_NOT_FOUND;
	}
	TclWinConvertError(err);
	if (interp != (Tcl_Interp *) NULL) {
	    Tcl_SetObjResult(interp, Tcl_ObjPrintf(
		    "couldn't open \"%s\": %s",
		    TclGetString(pathPtr), Tcl_PosixError(interp)));
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172

	    "leal       %[registration], %%edx"         "\n\t"
	    "movl       %%fs:0,         %%eax"          "\n\t"
	    "movl       %%eax,          0x0(%%edx)"     "\n\t" /* link */
	    "leal       1f,             %%eax"          "\n\t"
	    "movl       %%eax,          0x4(%%edx)"     "\n\t" /* handler */
	    "movl       %%ebp,          0x8(%%edx)"     "\n\t" /* ebp */
	    "movl       %%esp,          0xc(%%edx)"     "\n\t" /* esp */
	    "movl       $0,             0x10(%%edx)"    "\n\t" /* status */

	    /*
	     * Link the TCLEXCEPTION_REGISTRATION on the chain.
	     */

	    "movl       %%edx,          %%fs:0"         "\n\t"







|







1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172

	    "leal       %[registration], %%edx"         "\n\t"
	    "movl       %%fs:0,         %%eax"          "\n\t"
	    "movl       %%eax,          0x0(%%edx)"     "\n\t" /* link */
	    "leal       1f,             %%eax"          "\n\t"
	    "movl       %%eax,          0x4(%%edx)"     "\n\t" /* handler */
	    "movl       %%ebp,          0x8(%%edx)"     "\n\t" /* ebp */
	    "movl       %%esp,          0xC(%%edx)"     "\n\t" /* esp */
	    "movl       $0,             0x10(%%edx)"    "\n\t" /* status */

	    /*
	     * Link the TCLEXCEPTION_REGISTRATION on the chain.
	     */

	    "movl       %%edx,          %%fs:0"         "\n\t"
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212

	    /*
	     * Come here however we exited. Restore context from the
	     * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	     */

	    "2:"                                        "\t"
	    "movl       0xc(%%edx),     %%esp"          "\n\t"
	    "movl       0x8(%%edx),     %%ebp"          "\n\t"
	    "movl       0x0(%%edx),     %%eax"          "\n\t"
	    "movl       %%eax,          %%fs:0"         "\n\t"

	    :
	    /* No outputs */
	    :







|







1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212

	    /*
	     * Come here however we exited. Restore context from the
	     * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	     */

	    "2:"                                        "\t"
	    "movl       0xC(%%edx),     %%esp"          "\n\t"
	    "movl       0x8(%%edx),     %%ebp"          "\n\t"
	    "movl       0x0(%%edx),     %%eax"          "\n\t"
	    "movl       %%eax,          %%fs:0"         "\n\t"

	    :
	    /* No outputs */
	    :
Changes to jni/tcl/win/tclWinFCmd.c.
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

	"leal	    %[registration], %%edx"	    "\n\t"
	"movl	    %%fs:0,	    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x0(%%edx)"	    "\n\t" /* link */
	"leal	    1f,		    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x4(%%edx)"	    "\n\t" /* handler */
	"movl	    %%ebp,	    0x8(%%edx)"	    "\n\t" /* ebp */
	"movl	    %%esp,	    0xc(%%edx)"	    "\n\t" /* esp */
	"movl	    $0,		    0x10(%%edx)"    "\n\t" /* status */

	/*
	 * Link the TCLEXCEPTION_REGISTRATION on the chain.
	 */

	"movl	    %%edx,	    %%fs:0"	    "\n\t"







|







200
201
202
203
204
205
206
207
208
209
210
211
212
213
214

	"leal	    %[registration], %%edx"	    "\n\t"
	"movl	    %%fs:0,	    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x0(%%edx)"	    "\n\t" /* link */
	"leal	    1f,		    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x4(%%edx)"	    "\n\t" /* handler */
	"movl	    %%ebp,	    0x8(%%edx)"	    "\n\t" /* ebp */
	"movl	    %%esp,	    0xC(%%edx)"	    "\n\t" /* esp */
	"movl	    $0,		    0x10(%%edx)"    "\n\t" /* status */

	/*
	 * Link the TCLEXCEPTION_REGISTRATION on the chain.
	 */

	"movl	    %%edx,	    %%fs:0"	    "\n\t"
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

	/*
	 * Come here however we exited. Restore context from the
	 * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	 */

	"2:"					    "\t"
	"movl	    0xc(%%edx),	    %%esp"	    "\n\t"
	"movl	    0x8(%%edx),	    %%ebp"	    "\n\t"
	"movl	    0x0(%%edx),	    %%eax"	    "\n\t"
	"movl	    %%eax,	    %%fs:0"	    "\n\t"

	:
	/* No outputs */
	:







|







241
242
243
244
245
246
247
248
249
250
251
252
253
254
255

	/*
	 * Come here however we exited. Restore context from the
	 * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	 */

	"2:"					    "\t"
	"movl	    0xC(%%edx),	    %%esp"	    "\n\t"
	"movl	    0x8(%%edx),	    %%ebp"	    "\n\t"
	"movl	    0x0(%%edx),	    %%eax"	    "\n\t"
	"movl	    %%eax,	    %%fs:0"	    "\n\t"

	:
	/* No outputs */
	:
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
	return retval;
    }

    TclWinConvertError(GetLastError());

    srcAttr = GetFileAttributesW(nativeSrc);
    dstAttr = GetFileAttributesW(nativeDst);
    if (srcAttr == 0xffffffff) {
	if (GetFullPathNameW(nativeSrc, 0, NULL,
		NULL) >= MAX_PATH) {
	    errno = ENAMETOOLONG;
	    return TCL_ERROR;
	}
	srcAttr = 0;
    }
    if (dstAttr == 0xffffffff) {
	if (GetFullPathNameW(nativeDst, 0, NULL,
		NULL) >= MAX_PATH) {
	    errno = ENAMETOOLONG;
	    return TCL_ERROR;
	}
	dstAttr = 0;
    }







|







|







279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
	return retval;
    }

    TclWinConvertError(GetLastError());

    srcAttr = GetFileAttributesW(nativeSrc);
    dstAttr = GetFileAttributesW(nativeDst);
    if (srcAttr == 0xFFFFFFFF) {
	if (GetFullPathNameW(nativeSrc, 0, NULL,
		NULL) >= MAX_PATH) {
	    errno = ENAMETOOLONG;
	    return TCL_ERROR;
	}
	srcAttr = 0;
    }
    if (dstAttr == 0xFFFFFFFF) {
	if (GetFullPathNameW(nativeDst, 0, NULL,
		NULL) >= MAX_PATH) {
	    errno = ENAMETOOLONG;
	    return TCL_ERROR;
	}
	dstAttr = 0;
    }
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

	"leal	    %[registration], %%edx"	    "\n\t"
	"movl	    %%fs:0,	    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x0(%%edx)"	    "\n\t" /* link */
	"leal	    1f,		    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x4(%%edx)"	    "\n\t" /* handler */
	"movl	    %%ebp,	    0x8(%%edx)"	    "\n\t" /* ebp */
	"movl	    %%esp,	    0xc(%%edx)"	    "\n\t" /* esp */
	"movl	    $0,		    0x10(%%edx)"    "\n\t" /* status */

	/*
	 * Link the TCLEXCEPTION_REGISTRATION on the chain.
	 */

	"movl	    %%edx,	    %%fs:0"	    "\n\t"







|







587
588
589
590
591
592
593
594
595
596
597
598
599
600
601

	"leal	    %[registration], %%edx"	    "\n\t"
	"movl	    %%fs:0,	    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x0(%%edx)"	    "\n\t" /* link */
	"leal	    1f,		    %%eax"	    "\n\t"
	"movl	    %%eax,	    0x4(%%edx)"	    "\n\t" /* handler */
	"movl	    %%ebp,	    0x8(%%edx)"	    "\n\t" /* ebp */
	"movl	    %%esp,	    0xC(%%edx)"	    "\n\t" /* esp */
	"movl	    $0,		    0x10(%%edx)"    "\n\t" /* status */

	/*
	 * Link the TCLEXCEPTION_REGISTRATION on the chain.
	 */

	"movl	    %%edx,	    %%fs:0"	    "\n\t"
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643

	/*
	 * Come here however we exited. Restore context from the
	 * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	 */

	"2:"					    "\t"
	"movl	    0xc(%%edx),	    %%esp"	    "\n\t"
	"movl	    0x8(%%edx),	    %%ebp"	    "\n\t"
	"movl	    0x0(%%edx),	    %%eax"	    "\n\t"
	"movl	    %%eax,	    %%fs:0"	    "\n\t"

	:
	/* No outputs */
	:







|







629
630
631
632
633
634
635
636
637
638
639
640
641
642
643

	/*
	 * Come here however we exited. Restore context from the
	 * TCLEXCEPTION_REGISTRATION in case the stack is unbalanced.
	 */

	"2:"					    "\t"
	"movl	    0xC(%%edx),	    %%esp"	    "\n\t"
	"movl	    0x8(%%edx),	    %%ebp"	    "\n\t"
	"movl	    0x0(%%edx),	    %%eax"	    "\n\t"
	"movl	    %%eax,	    %%fs:0"	    "\n\t"

	:
	/* No outputs */
	:
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
	return TCL_ERROR;
    }
    if (Tcl_GetErrno() == EACCES) {
	DWORD srcAttr, dstAttr;

	srcAttr = GetFileAttributesW(nativeSrc);
	dstAttr = GetFileAttributesW(nativeDst);
	if (srcAttr != 0xffffffff) {
	    if (dstAttr == 0xffffffff) {
		dstAttr = 0;
	    }
	    if ((srcAttr & FILE_ATTRIBUTE_DIRECTORY) ||
		    (dstAttr & FILE_ATTRIBUTE_DIRECTORY)) {
		if (srcAttr & FILE_ATTRIBUTE_REPARSE_POINT) {
		    /* Source is a symbolic link -- copy it */
		    if (TclWinSymLinkCopyDirectory(nativeSrc, nativeDst)==0) {







|
|







673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
	return TCL_ERROR;
    }
    if (Tcl_GetErrno() == EACCES) {
	DWORD srcAttr, dstAttr;

	srcAttr = GetFileAttributesW(nativeSrc);
	dstAttr = GetFileAttributesW(nativeDst);
	if (srcAttr != 0xFFFFFFFF) {
	    if (dstAttr == 0xFFFFFFFF) {
		dstAttr = 0;
	    }
	    if ((srcAttr & FILE_ATTRIBUTE_DIRECTORY) ||
		    (dstAttr & FILE_ATTRIBUTE_DIRECTORY)) {
		if (srcAttr & FILE_ATTRIBUTE_REPARSE_POINT) {
		    /* Source is a symbolic link -- copy it */
		    if (TclWinSymLinkCopyDirectory(nativeSrc, nativeDst)==0) {
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
    if (DeleteFileW(path) != FALSE) {
	return TCL_OK;
    }
    TclWinConvertError(GetLastError());

    if (Tcl_GetErrno() == EACCES) {
	attr = GetFileAttributesW(path);
	if (attr != 0xffffffff) {
	    if (attr & FILE_ATTRIBUTE_DIRECTORY) {
		if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
		    /*
		     * It is a symbolic link - remove it.
		     */
		    if (TclWinSymLinkDelete(path, 0) == 0) {
			return TCL_OK;







|







764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
    if (DeleteFileW(path) != FALSE) {
	return TCL_OK;
    }
    TclWinConvertError(GetLastError());

    if (Tcl_GetErrno() == EACCES) {
	attr = GetFileAttributesW(path);
	if (attr != 0xFFFFFFFF) {
	    if (attr & FILE_ATTRIBUTE_DIRECTORY) {
		if (attr & FILE_ATTRIBUTE_REPARSE_POINT) {
		    /*
		     * It is a symbolic link - remove it.
		     */
		    if (TclWinSymLinkDelete(path, 0) == 0) {
			return TCL_OK;
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
		if (res != 0) {
		    SetFileAttributesW(path, attr);
		}
	    }
	}
    } else if (Tcl_GetErrno() == ENOENT) {
	attr = GetFileAttributesW(path);
	if (attr != 0xffffffff) {
	    if (attr & FILE_ATTRIBUTE_DIRECTORY) {
		/*
		 * Windows 95 reports removing a directory as ENOENT instead
		 * of EISDIR.
		 */

		Tcl_SetErrno(EISDIR);







|







799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
		if (res != 0) {
		    SetFileAttributesW(path, attr);
		}
	    }
	}
    } else if (Tcl_GetErrno() == ENOENT) {
	attr = GetFileAttributesW(path);
	if (attr != 0xFFFFFFFF) {
	    if (attr & FILE_ATTRIBUTE_DIRECTORY) {
		/*
		 * Windows 95 reports removing a directory as ENOENT instead
		 * of EISDIR.
		 */

		Tcl_SetErrno(EISDIR);
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
	}
    }

    TclWinConvertError(GetLastError());

    if (Tcl_GetErrno() == EACCES) {
	attr = GetFileAttributesW(nativePath);
	if (attr != 0xffffffff) {
	    if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
		/*
		 * Windows 95 reports calling RemoveDirectory on a file as an
		 * EACCES, not an ENOTDIR.
		 */

		Tcl_SetErrno(ENOTDIR);







|







1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
	}
    }

    TclWinConvertError(GetLastError());

    if (Tcl_GetErrno() == EACCES) {
	attr = GetFileAttributesW(nativePath);
	if (attr != 0xFFFFFFFF) {
	    if ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0) {
		/*
		 * Windows 95 reports calling RemoveDirectory on a file as an
		 * EACCES, not an ENOTDIR.
		 */

		Tcl_SetErrno(ENOTDIR);
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205

    nativeSource = (WCHAR *) Tcl_DStringValue(sourcePtr);
    nativeTarget = (WCHAR *)
	    (targetPtr == NULL ? NULL : Tcl_DStringValue(targetPtr));

    oldSourceLen = Tcl_DStringLength(sourcePtr);
    sourceAttr = GetFileAttributesW(nativeSource);
    if (sourceAttr == 0xffffffff) {
	nativeErrfile = nativeSource;
	goto end;
    }

    if (sourceAttr & FILE_ATTRIBUTE_REPARSE_POINT) {
	/*
	 * Process the symbolic link







|







1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205

    nativeSource = (WCHAR *) Tcl_DStringValue(sourcePtr);
    nativeTarget = (WCHAR *)
	    (targetPtr == NULL ? NULL : Tcl_DStringValue(targetPtr));

    oldSourceLen = Tcl_DStringLength(sourcePtr);
    sourceAttr = GetFileAttributesW(nativeSource);
    if (sourceAttr == 0xFFFFFFFF) {
	nativeErrfile = nativeSource;
	goto end;
    }

    if (sourceAttr & FILE_ATTRIBUTE_REPARSE_POINT) {
	/*
	 * Process the symbolic link
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
    DWORD result;
    const WCHAR *nativeName;
    int attr;

    nativeName = Tcl_FSGetNativePath(fileName);
    result = GetFileAttributesW(nativeName);

    if (result == 0xffffffff) {
	StatError(interp, fileName);
	return TCL_ERROR;
    }

    attr = (int)(result & attributeArray[objIndex]);
    if ((objIndex == WIN_HIDDEN_ATTRIBUTE) && (attr != 0)) {
	/*







|







1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
    DWORD result;
    const WCHAR *nativeName;
    int attr;

    nativeName = Tcl_FSGetNativePath(fileName);
    result = GetFileAttributesW(nativeName);

    if (result == 0xFFFFFFFF) {
	StatError(interp, fileName);
	return TCL_ERROR;
    }

    attr = (int)(result & attributeArray[objIndex]);
    if ((objIndex == WIN_HIDDEN_ATTRIBUTE) && (attr != 0)) {
	/*
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
    DWORD fileAttributes, old;
    int yesNo, result;
    const WCHAR *nativeName;

    nativeName = Tcl_FSGetNativePath(fileName);
    fileAttributes = old = GetFileAttributesW(nativeName);

    if (fileAttributes == 0xffffffff) {
	StatError(interp, fileName);
	return TCL_ERROR;
    }

    result = Tcl_GetBooleanFromObj(interp, attributePtr, &yesNo);
    if (result != TCL_OK) {
	return result;







|







1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
    DWORD fileAttributes, old;
    int yesNo, result;
    const WCHAR *nativeName;

    nativeName = Tcl_FSGetNativePath(fileName);
    fileAttributes = old = GetFileAttributesW(nativeName);

    if (fileAttributes == 0xFFFFFFFF) {
	StatError(interp, fileName);
	return TCL_ERROR;
    }

    result = Tcl_GetBooleanFromObj(interp, attributePtr, &yesNo);
    if (result != TCL_OK) {
	return result;
Changes to jni/tcl/win/tclWinPipe.c.
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
	    NULL, createMode, flags, NULL);
    Tcl_DStringFree(&ds);

    if (handle == INVALID_HANDLE_VALUE) {
	DWORD err;

	err = GetLastError();
	if ((err & 0xffffL) == ERROR_OPEN_FAILED) {
	    err = (mode & O_CREAT) ? ERROR_FILE_EXISTS : ERROR_FILE_NOT_FOUND;
	}
	TclWinConvertError(err);
	return NULL;
    }

    /*







|







605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
	    NULL, createMode, flags, NULL);
    Tcl_DStringFree(&ds);

    if (handle == INVALID_HANDLE_VALUE) {
	DWORD err;

	err = GetLastError();
	if ((err & 0xFFFFL) == ERROR_OPEN_FAILED) {
	    err = (mode & O_CREAT) ? ERROR_FILE_EXISTS : ERROR_FILE_NOT_FOUND;
	}
	TclWinConvertError(err);
	return NULL;
    }

    /*
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349

	/*
	 * Ignore matches on directories or data files, return if identified a
	 * known type.
	 */

	attr = GetFileAttributesW(nativeFullPath);
	if ((attr == 0xffffffff) || (attr & FILE_ATTRIBUTE_DIRECTORY)) {
	    continue;
	}
	strcpy(fullName, Tcl_WinTCharToUtf((TCHAR *)nativeFullPath, -1, &ds));
	Tcl_DStringFree(&ds);

	ext = strrchr(fullName, '.');
	if ((ext != NULL) &&







|







1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349

	/*
	 * Ignore matches on directories or data files, return if identified a
	 * known type.
	 */

	attr = GetFileAttributesW(nativeFullPath);
	if ((attr == 0xFFFFFFFF) || (attr & FILE_ATTRIBUTE_DIRECTORY)) {
	    continue;
	}
	strcpy(fullName, Tcl_WinTCharToUtf((TCHAR *)nativeFullPath, -1, &ds));
	Tcl_DStringFree(&ds);

	ext = strrchr(fullName, '.');
	if ((ext != NULL) &&
Changes to jni/tcl/win/tclWinPort.h.
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#endif

#ifndef WIFSIGNALED
#   define WIFSIGNALED(stat) ((*((int *) &(stat))) & 0xC0000000)
#endif

#ifndef WTERMSIG
#   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7f)
#endif

#ifndef WIFSTOPPED
#   define WIFSTOPPED(stat)  0
#endif

#ifndef WSTOPSIG
#   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xff)
#endif

/*
 * Define constants for waitpid() system call if they aren't defined
 * by a system header file.
 */








|







|







310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
#endif

#ifndef WIFSIGNALED
#   define WIFSIGNALED(stat) ((*((int *) &(stat))) & 0xC0000000)
#endif

#ifndef WTERMSIG
#   define WTERMSIG(stat)    ((*((int *) &(stat))) & 0x7F)
#endif

#ifndef WIFSTOPPED
#   define WIFSTOPPED(stat)  0
#endif

#ifndef WSTOPSIG
#   define WSTOPSIG(stat)    (((*((int *) &(stat))) >> 8) & 0xFF)
#endif

/*
 * Define constants for waitpid() system call if they aren't defined
 * by a system header file.
 */

486
487
488
489
490
491
492

493
494
495
496
497
498
499

/*
 * MSVC 8.0 started to mark many standard C library functions depreciated
 * including the *printf family and others. Tell it to shut up.
 * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0)
 */
#if defined(_MSC_VER)

#   pragma warning(disable:4244)
#   if _MSC_VER >= 1400
#	pragma warning(disable:4267)
#	pragma warning(disable:4996)
#   endif
#endif








>







486
487
488
489
490
491
492
493
494
495
496
497
498
499
500

/*
 * MSVC 8.0 started to mark many standard C library functions depreciated
 * including the *printf family and others. Tell it to shut up.
 * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0)
 */
#if defined(_MSC_VER)
#   pragma warning(disable:4146)
#   pragma warning(disable:4244)
#   if _MSC_VER >= 1400
#	pragma warning(disable:4267)
#	pragma warning(disable:4996)
#   endif
#endif

Changes to jni/tcl/win/tclWinTest.c.
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471

    attr = GetFileAttributesA(nativePath);

    /*
     * nativePath not found
     */

    if (attr == 0xffffffff) {
	res = -1;
	goto done;
    }

    /*
     * If nativePath is not a directory, there is no special handling.
     */







|







457
458
459
460
461
462
463
464
465
466
467
468
469
470
471

    attr = GetFileAttributesA(nativePath);

    /*
     * nativePath not found
     */

    if (attr == 0xFFFFFFFF) {
	res = -1;
	goto done;
    }

    /*
     * If nativePath is not a directory, there is no special handling.
     */
Changes to jni/tcl/win/tclWinTime.c.
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
		 */

		SYSTEM_INFO systemInfo;
		unsigned int regs[4];

		GetSystemInfo(&systemInfo);
		if (TclWinCPUID(0, regs) == TCL_OK
			&& regs[1] == 0x756e6547	/* "Genu" */
			&& regs[3] == 0x49656e69	/* "ineI" */
			&& regs[2] == 0x6c65746e	/* "ntel" */
			&& TclWinCPUID(1, regs) == TCL_OK
			&& ((regs[0]&0x00000F00) == 0x00000F00 /* Pentium 4 */
			|| ((regs[0] & 0x00F00000)	/* Extended family */
			&& (regs[3] & 0x10000000)))	/* Hyperthread */
			&& (((regs[1]&0x00FF0000) >> 16)/* CPU count */
			    == systemInfo.dwNumberOfProcessors)) {
		    timeInfo.perfCounterAvailable = TRUE;







|
|
|







491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
		 */

		SYSTEM_INFO systemInfo;
		unsigned int regs[4];

		GetSystemInfo(&systemInfo);
		if (TclWinCPUID(0, regs) == TCL_OK
			&& regs[1] == 0x756E6547	/* "Genu" */
			&& regs[3] == 0x49656E69	/* "ineI" */
			&& regs[2] == 0x6C65746E	/* "ntel" */
			&& TclWinCPUID(1, regs) == TCL_OK
			&& ((regs[0]&0x00000F00) == 0x00000F00 /* Pentium 4 */
			|| ((regs[0] & 0x00F00000)	/* Extended family */
			&& (regs[3] & 0x10000000)))	/* Hyperthread */
			&& (((regs[1]&0x00FF0000) >> 16)/* CPU count */
			    == systemInfo.dwNumberOfProcessors)) {
		    timeInfo.perfCounterAvailable = TRUE;