Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Beginning work in earnest on Tip#430 and Tip#453 Renamed zipfs.c to tclZipfs.c. Eliminated tclZipfs.h. Removed the bootstrap introduced by Odie/Androwish. With zipfs in the core one only needs to specify the TclPreInitScript The project at least builds on OSX. Working on Windows under MSYS/MinGW next Added a local snapshot of practcl. |
|---|---|
| Timelines: | family | ancestors | descendants | both | core_zip_vfs |
| Files: | files | file ages | folders |
| SHA1: |
ad6641bb82e855b1df384627fea315d4 |
| User & Date: | hypnotoad 2016-09-14 13:33:32.414 |
Context
|
2016-09-14
| ||
| 13:36 | Fixed the line endings on practcl.tcl check-in: b2dbde2130 user: hypnotoad tags: core_zip_vfs | |
| 13:33 | Beginning work in earnest on Tip#430 and Tip#453 Renamed zipfs.c to tclZipfs.c. Eliminated tclZipfs... check-in: ad6641bb82 user: hypnotoad tags: core_zip_vfs | |
|
2016-09-08
| ||
| 03:01 | Pulling changes from Trunk check-in: c20e962d80 user: hypnotoad tags: core_zip_vfs | |
Changes
Changes to generic/tclBasic.c.
| ︙ | ︙ | |||
978 979 980 981 982 983 984 985 986 987 988 989 990 991 |
* compile and link against.
*/
#ifdef HAVE_ZLIB
if (TclZlibInit(interp) != TCL_OK) {
Tcl_Panic("%s", Tcl_GetString(Tcl_GetObjResult(interp)));
}
#endif
TOP_CB(iPtr) = NULL;
return interp;
}
static void
| > > > | 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 |
* compile and link against.
*/
#ifdef HAVE_ZLIB
if (TclZlibInit(interp) != TCL_OK) {
Tcl_Panic("%s", Tcl_GetString(Tcl_GetObjResult(interp)));
}
if (TclZipfsInit(interp) != TCL_OK) {
Tcl_Panic("%s", Tcl_GetString(Tcl_GetObjResult(interp)));
}
#endif
TOP_CB(iPtr) = NULL;
return interp;
}
static void
|
| ︙ | ︙ |
Changes to generic/tclIOUtil.c.
| ︙ | ︙ | |||
186 187 188 189 190 191 192 |
TclpObjLstat,
/* Needs casts since we're using version_2. */
(Tcl_FSLoadFileProc *) TclpDlopen,
(Tcl_FSGetCwdProc *) TclpGetNativeCwd,
TclpObjChdir
};
| < < | 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
TclpObjLstat,
/* Needs casts since we're using version_2. */
(Tcl_FSLoadFileProc *) TclpDlopen,
(Tcl_FSGetCwdProc *) TclpGetNativeCwd,
TclpObjChdir
};
/*
* Define the tail of the linked list. Note that for unconventional uses of
* Tcl without a native filesystem, we may in the future wish to modify the
* current approach of hard-coding the native filesystem in the lookup list
* 'filesystemList' below.
*
* We initialize the record so that it thinks one file uses it. This means it
|
| ︙ | ︙ | |||
1408 1409 1410 1411 1412 1413 1414 |
* native filesystem (i.e. '/' on unix is native).
*/
firstFsRecPtr = FsGetFirstFilesystem();
Claim();
for (fsRecPtr=firstFsRecPtr; fsRecPtr!=NULL; fsRecPtr=fsRecPtr->nextPtr) {
| < < < < < < < < < < < < < < < < | 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 |
* native filesystem (i.e. '/' on unix is native).
*/
firstFsRecPtr = FsGetFirstFilesystem();
Claim();
for (fsRecPtr=firstFsRecPtr; fsRecPtr!=NULL; fsRecPtr=fsRecPtr->nextPtr) {
if (fsRecPtr->fsPtr != &tclNativeFilesystem) {
continue;
}
/*
* TODO: Assume that we always find the native file system; it should
* always be there...
|
| ︙ | ︙ | |||
1448 1449 1450 1451 1452 1453 1454 |
/*
* Skip the native system next time through.
*/
if (fsRecPtr->fsPtr == &tclNativeFilesystem) {
continue;
}
| < < < | 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 |
/*
* Skip the native system next time through.
*/
if (fsRecPtr->fsPtr == &tclNativeFilesystem) {
continue;
}
if (fsRecPtr->fsPtr->normalizePathProc != NULL) {
startAt = fsRecPtr->fsPtr->normalizePathProc(interp, pathPtr,
startAt);
}
/*
|
| ︙ | ︙ | |||
2931 2932 2933 2934 2935 2936 2937 |
}
if (Tcl_FSGetNormalizedPath(NULL, pathPtr) == NULL) {
Tcl_SetErrno(ENOENT);
return retVal;
}
fsPtr = Tcl_FSGetFileSystemForPath(pathPtr);
| < < < < < < < < < < < < < | 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 |
}
if (Tcl_FSGetNormalizedPath(NULL, pathPtr) == NULL) {
Tcl_SetErrno(ENOENT);
return retVal;
}
fsPtr = Tcl_FSGetFileSystemForPath(pathPtr);
if (fsPtr != NULL) {
if (fsPtr->chdirProc != NULL) {
/*
* If this fails, an appropriate errno will have been stored using
* 'Tcl_SetErrno()'.
*/
|
| ︙ | ︙ |
Changes to generic/tclInt.h.
| ︙ | ︙ | |||
3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 | MODULE_SCOPE void TclFinalizeThreadDataThread(void); MODULE_SCOPE void TclFinalizeThreadStorage(void); #ifdef TCL_WIDE_CLICKS MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void); MODULE_SCOPE double TclpWideClicksToNanoseconds(Tcl_WideInt clicks); #endif MODULE_SCOPE int TclZlibInit(Tcl_Interp *interp); MODULE_SCOPE void * TclpThreadCreateKey(void); MODULE_SCOPE void TclpThreadDeleteKey(void *keyPtr); MODULE_SCOPE void TclpThreadSetMasterTSD(void *tsdKeyPtr, void *ptr); MODULE_SCOPE void * TclpThreadGetMasterTSD(void *tsdKeyPtr); MODULE_SCOPE void TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length); | > > > > | 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 | MODULE_SCOPE void TclFinalizeThreadDataThread(void); MODULE_SCOPE void TclFinalizeThreadStorage(void); #ifdef TCL_WIDE_CLICKS MODULE_SCOPE Tcl_WideInt TclpGetWideClicks(void); MODULE_SCOPE double TclpWideClicksToNanoseconds(Tcl_WideInt clicks); #endif MODULE_SCOPE int TclZlibInit(Tcl_Interp *interp); MODULE_SCOPE int TclZipfsInit(Tcl_Interp *interp); MODULE_SCOPE int TclZipfsMount(Tcl_Interp *interp, const char *zipname, const char *mntpt, const char *passwd); MODULE_SCOPE int TclZipfsUnmount(Tcl_Interp *interp, const char *zipname); MODULE_SCOPE void * TclpThreadCreateKey(void); MODULE_SCOPE void TclpThreadDeleteKey(void *keyPtr); MODULE_SCOPE void TclpThreadSetMasterTSD(void *tsdKeyPtr, void *ptr); MODULE_SCOPE void * TclpThreadGetMasterTSD(void *tsdKeyPtr); MODULE_SCOPE void TclErrorStackResetIf(Tcl_Interp *interp, const char *msg, int length); |
| ︙ | ︙ |
Name change from generic/zipfs.c to generic/tclZipfs.c.
1 | /* | | | > > < > > > | | 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 | /* * tclZipfs.c -- * * Implementation of the ZIP filesystem used in TIP 430 * Adapted from the implentation for AndroWish. * * Coptright (c) 2016 Sean Woods <yoda@etoyoc.com> * Copyright (c) 2013-2015 Christian Werner <chw@ch-werner.de> * * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #include "tclInt.h" #include "tclFileSystem.h" #if !defined(_WIN32) && !defined(_WIN64) #include <sys/mman.h> #endif #include <errno.h> #include <string.h> #include <sys/stat.h> #include <time.h> #include <stdlib.h> #include <fcntl.h> #ifdef HAVE_ZLIB #include "zlib.h" #include "zcrypt.h" #define ZIPFS_VOLUME "zipfs:/" #define ZIPFS_VOLUME_LEN 7 /* * Various constants and offsets found in ZIP archive files */ #define ZIP_SIG_LEN 4 /* Local header of ZIP archive member (at very beginning of each member). */ #define ZIP_LOCAL_HEADER_SIG 0x04034b50 #define ZIP_LOCAL_HEADER_LEN 30 |
| ︙ | ︙ | |||
490 491 492 493 494 495 496 | * Side effects: * Modifies the specified Tcl_DString. * *------------------------------------------------------------------------- */ static char * | | | > | < > | | | > | | | | | > | | | | > | > > > > > > > | | | > > > > > > | > | | > | > | | > | | > > > > > > > > > > > > > > > > > > > > > > > > | | | | | > > | | | | | | > > > > > | | < | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | > > > | 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 |
* Side effects:
* Modifies the specified Tcl_DString.
*
*-------------------------------------------------------------------------
*/
static char *
CanonicalPath(const char *root, const char *tail, Tcl_DString *dsPtr,int ZIPFSPATH)
{
char *path;
char *result;
int i, j, c, isunc = 0, isvfs=0, n=0;
#if HAS_DRIVES
int zipfspath=1;
if ((tail[0] != '\0') && (strchr(drvletters, tail[0]) != NULL) &&
(tail[1] == ':')) {
tail += 2;
zipfspath=0;
}
/* UNC style path */
if (tail[0] == '\\') {
root = "";
++tail;
zipfspath=0;
}
if (tail[0] == '\\') {
root = "/";
++tail;
zipfspath=0;
}
if(zipfspath) {
#endif
/* UNC style path */
if(root && strncmp(root,ZIPFS_VOLUME,ZIPFS_VOLUME_LEN)==0) {
isvfs=1;
} else if (tail && strncmp(tail,ZIPFS_VOLUME,ZIPFS_VOLUME_LEN) == 0) {
isvfs=2;
}
if(isvfs!=1) {
if ((root[0] == '/') && (root[1] == '/')) {
isunc = 1;
}
}
#if HAS_DRIVES
}
#endif
if(isvfs!=2) {
if (tail[0] == '/') {
if(isvfs!=1) {
root = "";
}
++tail;
isunc = 0;
}
if (tail[0] == '/') {
if(isvfs!=1) {
root = "/";
}
++tail;
isunc = 1;
}
}
i = strlen(root);
j = strlen(tail);
if(isvfs==1) {
if(i>ZIPFS_VOLUME_LEN) {
Tcl_DStringSetLength(dsPtr, i + j + 1);
path = Tcl_DStringValue(dsPtr);
memcpy(path, root, i);
path[i++] = '/';
memcpy(path + i, tail, j);
} else {
Tcl_DStringSetLength(dsPtr, i + j);
path = Tcl_DStringValue(dsPtr);
memcpy(path, root, i);
memcpy(path + i, tail, j);
}
} else if(isvfs==2) {
Tcl_DStringSetLength(dsPtr, j);
path = Tcl_DStringValue(dsPtr);
memcpy(path, tail, j);
} else {
if (ZIPFSPATH) {
Tcl_DStringSetLength(dsPtr, i + j + ZIPFS_VOLUME_LEN);
path = Tcl_DStringValue(dsPtr);
memcpy(path, ZIPFS_VOLUME, ZIPFS_VOLUME_LEN);
memcpy(path + ZIPFS_VOLUME_LEN + i , tail, j);
} else {
Tcl_DStringSetLength(dsPtr, i + j + 1);
path = Tcl_DStringValue(dsPtr);
memcpy(path, root, i);
path[i++] = '/';
memcpy(path + i, tail, j);
}
}
#if HAS_DRIVES
for (i = 0; path[i] != '\0'; i++) {
if (path[i] == '\\') {
path[i] = '/';
}
}
#endif
if(ZIPFSPATH) {
n=ZIPFS_VOLUME_LEN;
} else {
n=0;
}
for (i = j = n; (c = path[i]) != '\0'; i++) {
if (c == '/') {
int c2 = path[i + 1];
if (c2 == '/') {
continue;
}
if (c2 == '.') {
int c3 = path[i + 2];
if ((c3 == '/') || (c3 == '\0')) {
i++;
continue;
}
if ((c3 == '.') &&
((path[i + 3] == '/') || (path [i + 3] == '\0'))) {
i += 2;
while ((j > 0) && (path[j - 1] != '/')) {
j--;
}
if (j > isunc) {
--j;
while ((j > 1 + isunc) && (path[j - 2] == '/')) {
j--;
}
}
continue;
}
}
}
path[j++] = c;
}
if (j == 0) {
path[j++] = '/';
}
path[j] = 0;
Tcl_DStringSetLength(dsPtr, j);
result=Tcl_DStringValue(dsPtr);
return result;
}
/*
*-------------------------------------------------------------------------
*
* AbsolutePath --
*
* This function computes the absolute path from a given
|
| ︙ | ︙ | |||
598 599 600 601 602 603 604 | * Modifies the specified Tcl_DString. * *------------------------------------------------------------------------- */ static char * AbsolutePath(const char *path, | < < < | > | < < < < < < | | | | | < < < < < < | | | | | < < < < < < < < < < < < | | | | < < < < < < < < < < < | | | | 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 |
* Modifies the specified Tcl_DString.
*
*-------------------------------------------------------------------------
*/
static char *
AbsolutePath(const char *path,
Tcl_DString *dsPtr,
int ZIPFSPATH)
{
char *result;
if (*path == '~') {
Tcl_DStringAppend(dsPtr, path, -1);
return Tcl_DStringValue(dsPtr);
}
if (*path != '/') {
Tcl_DString pwd;
/* relative path */
Tcl_DStringInit(&pwd);
Tcl_GetCwd(NULL, &pwd);
result = Tcl_DStringValue(&pwd);
result = CanonicalPath(result, path, dsPtr,ZIPFSPATH);
Tcl_DStringFree(&pwd);
} else {
/* absolute path */
result = CanonicalPath("", path, dsPtr,ZIPFSPATH);
}
return result;
}
/*
*-------------------------------------------------------------------------
*
* ZipFSLookup --
*
|
| ︙ | ︙ | |||
681 682 683 684 685 686 687 |
*
*-------------------------------------------------------------------------
*/
static ZipEntry *
ZipFSLookup(char *filename)
{
| | > | | | < < < < | < | < < < | | | < < < < < | | 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 |
*
*-------------------------------------------------------------------------
*/
static ZipEntry *
ZipFSLookup(char *filename)
{
char *realname;
Tcl_HashEntry *hPtr;
ZipEntry *z;
Tcl_DString ds;
Tcl_DStringInit(&ds);
realname = AbsolutePath(filename, &ds, 1);
hPtr = Tcl_FindHashEntry(&ZipFS.fileHash, realname);
z = hPtr ? (ZipEntry *) Tcl_GetHashValue(hPtr) : NULL;
Tcl_DStringFree(&ds);
return z;
}
#ifdef NEVER_USED
/*
*-------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
728 729 730 731 732 733 734 |
*
*-------------------------------------------------------------------------
*/
static int
ZipFSLookupMount(char *filename)
{
| | | | | | | < < < < | < | < < < | | | < < < < < < | | | | | | | | | | 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 |
*
*-------------------------------------------------------------------------
*/
static int
ZipFSLookupMount(char *filename)
{
char *realname;
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
ZipFile *zf;
Tcl_DString ds;
int match = 0;
Tcl_DStringInit(&ds);
realname = AbsolutePath(filename, &ds, 1);
hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &search);
while (hPtr != NULL) {
if ((zf = (ZipFile *) Tcl_GetHashValue(hPtr)) != NULL) {
if (strcmp(zf->mntpt, realname) == 0) {
match = 1;
break;
}
}
hPtr = Tcl_NextHashEntry(&search);
}
Tcl_DStringFree(&ds);
return match;
}
#endif
/*
*-------------------------------------------------------------------------
*
* ZipFSCloseArchive --
|
| ︙ | ︙ | |||
1032 1033 1034 1035 1036 1037 1038 |
ZipFSCloseArchive(interp, zf);
return TCL_ERROR;
}
/*
*-------------------------------------------------------------------------
*
| | | | | | | | | | < < < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | < < < | | | < < < < < < < < < < < < < | | < | | | | | | | | | | | | | | | | | | | < | < < < | | | | | | < < < | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < < < < < < | | | | | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < < < | < | < < < | | | | | | | | | | < < < < < < | | | | | | | | | | | | | | | | | | | | | | | | | | 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 |
ZipFSCloseArchive(interp, zf);
return TCL_ERROR;
}
/*
*-------------------------------------------------------------------------
*
* TclZipfsMount --
*
* This procedure is invoked to mount a given ZIP archive file on
* a given mountpoint with optional ZIP password.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* A ZIP archive file is read, analyzed and mounted, resources are
* allocated.
*
*-------------------------------------------------------------------------
*/
int
TclZipfsMount(Tcl_Interp *interp, const char *zipname, const char *mntpt,
const char *passwd)
{
char *realname, *p;
int i, pwlen, isNew;
ZipFile *zf, zf0;
ZipEntry *z;
Tcl_HashEntry *hPtr;
Tcl_DString ds, dsm, fpBuf;
unsigned char *q;
ReadLock();
if (!ZipFS.initialized) {
if (interp != NULL) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("not initialized", -1));
}
Unlock();
return TCL_ERROR;
}
if (zipname == NULL) {
Tcl_HashSearch search;
int ret = TCL_OK;
i = 0;
hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &search);
while (hPtr != NULL) {
if ((zf = (ZipFile *) Tcl_GetHashValue(hPtr)) != NULL) {
if (interp != NULL) {
Tcl_AppendElement(interp, zf->mntpt);
Tcl_AppendElement(interp, zf->name);
}
++i;
}
hPtr = Tcl_NextHashEntry(&search);
}
if (interp == NULL) {
ret = (i > 0) ? TCL_OK : TCL_BREAK;
}
Unlock();
return ret;
}
if (mntpt == NULL) {
if (interp == NULL) {
Unlock();
return TCL_OK;
}
Tcl_DStringInit(&ds);
p = AbsolutePath(zipname, &ds, 0);
hPtr = Tcl_FindHashEntry(&ZipFS.zipHash, p);
if (hPtr != NULL) {
if ((zf = Tcl_GetHashValue(hPtr)) != NULL) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj(zf->mntpt, zf->mntptlen));
}
}
Unlock();
Tcl_DStringFree(&ds);
return TCL_OK;
}
Unlock();
pwlen = 0;
if (passwd != NULL) {
pwlen = strlen(passwd);
if ((pwlen > 255) || (strchr(passwd, 0xff) != NULL)) {
if (interp) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("illegal password", -1));
}
return TCL_ERROR;
}
}
if (ZipFSOpenArchive(interp, zipname, 1, &zf0) != TCL_OK) {
return TCL_ERROR;
}
Tcl_DStringInit(&ds);
realname = AbsolutePath(zipname, &ds, 0);
/*
* Mount point can come from Tcl_GetNameOfExecutable()
* which sometimes is a relative or otherwise denormalized path.
* But an absolute name is needed as mount point here.
*/
Tcl_DStringInit(&dsm);
mntpt = CanonicalPath("", mntpt, &dsm, 1);
WriteLock();
hPtr = Tcl_CreateHashEntry(&ZipFS.zipHash, realname, &isNew);
Tcl_DStringSetLength(&ds, 0);
if (!isNew) {
zf = (ZipFile *) Tcl_GetHashValue(hPtr);
if (interp != NULL) {
Tcl_AppendResult(interp, "already mounted on \"", zf->mntptlen ?
zf->mntpt : "/", "\"", (char *) NULL);
}
Unlock();
Tcl_DStringFree(&ds);
Tcl_DStringFree(&dsm);
ZipFSCloseArchive(interp, &zf0);
return TCL_ERROR;
}
if (strcmp(mntpt, "/") == 0) {
mntpt = "";
}
zf = (ZipFile *) Tcl_AttemptAlloc(sizeof (*zf) + strlen(mntpt) + 1);
if (zf == NULL) {
if (interp != NULL) {
Tcl_AppendResult(interp, "out of memory", (char *) NULL);
}
Unlock();
Tcl_DStringFree(&ds);
Tcl_DStringFree(&dsm);
ZipFSCloseArchive(interp, &zf0);
return TCL_ERROR;
}
*zf = zf0;
zf->name = Tcl_GetHashKey(&ZipFS.zipHash, hPtr);
strcpy(zf->mntpt, mntpt);
zf->mntptlen = strlen(zf->mntpt);
zf->entries = NULL;
zf->topents = NULL;
zf->nopen = 0;
Tcl_SetHashValue(hPtr, (ClientData) zf);
if ((zf->pwbuf[0] == 0) && pwlen) {
int k = 0;
i = pwlen;
zf->pwbuf[k++] = i;
while (i > 0) {
zf->pwbuf[k] = (passwd[i - 1] & 0x0f) |
pwrot[(passwd[i - 1] >> 4) & 0x0f];
k++;
i--;
}
zf->pwbuf[k] = '\0';
}
if (mntpt[0] != '\0') {
z = (ZipEntry *) Tcl_Alloc(sizeof (*z));
z->name = NULL;
z->tnext = NULL;
z->depth = CountSlashes(mntpt);
z->zipfile = zf;
z->isdir = 1;
z->isenc = 0;
z->offset = zf->baseoffs;
z->crc32 = 0;
z->timestamp = 0;
z->nbyte = z->nbytecompr = 0;
z->cmeth = ZIP_COMPMETH_STORED;
z->data = NULL;
hPtr = Tcl_CreateHashEntry(&ZipFS.fileHash, mntpt, &isNew);
if (!isNew) {
/* skip it */
Tcl_Free((char *) z);
} else {
Tcl_SetHashValue(hPtr, (ClientData) z);
z->name = Tcl_GetHashKey(&ZipFS.fileHash, hPtr);
z->next = zf->entries;
zf->entries = z;
}
}
q = zf->data + zf->centoffs;
Tcl_DStringInit(&fpBuf);
for (i = 0; i < zf->nfiles; i++) {
int pathlen, comlen, extra, isdir = 0, dosTime, dosDate, nbcompr, offs;
unsigned char *lq, *gq = NULL;
char *fullpath, *path;
pathlen = zip_read_short(q + ZIP_CENTRAL_PATHLEN_OFFS);
comlen = zip_read_short(q + ZIP_CENTRAL_FCOMMENTLEN_OFFS);
extra = zip_read_short(q + ZIP_CENTRAL_EXTRALEN_OFFS);
Tcl_DStringSetLength(&ds, 0);
Tcl_DStringAppend(&ds, (char *) q + ZIP_CENTRAL_HEADER_LEN, pathlen);
path = Tcl_DStringValue(&ds);
if ((pathlen > 0) && (path[pathlen - 1] == '/')) {
Tcl_DStringSetLength(&ds, pathlen - 1);
path = Tcl_DStringValue(&ds);
isdir = 1;
}
if ((strcmp(path, ".") == 0) || (strcmp(path, "..") == 0)) {
goto nextent;
}
lq = zf->data + zf->baseoffs +
zip_read_int(q + ZIP_CENTRAL_LOCALHDR_OFFS);
if ((lq < zf->data) || (lq > (zf->data + zf->length))) {
goto nextent;
}
nbcompr = zip_read_int(lq + ZIP_LOCAL_COMPLEN_OFFS);
if (!isdir && (nbcompr == 0) &&
(zip_read_int(lq + ZIP_LOCAL_UNCOMPLEN_OFFS) == 0) &&
(zip_read_int(lq + ZIP_LOCAL_CRC32_OFFS) == 0)) {
gq = q;
nbcompr = zip_read_int(gq + ZIP_CENTRAL_COMPLEN_OFFS);
}
offs = (lq - zf->data)
+ ZIP_LOCAL_HEADER_LEN
+ zip_read_short(lq + ZIP_LOCAL_PATHLEN_OFFS)
+ zip_read_short(lq + ZIP_LOCAL_EXTRALEN_OFFS);
if ((offs + nbcompr) > zf->length) {
goto nextent;
}
if (!isdir && (mntpt[0] == '\0') && !CountSlashes(path)) {
#ifdef ANDROID
/*
* When mounting the ZIP archive on the root directory try
* to remap top level regular files of the archive to
* /assets/.root/... since this directory should not be
* in a valid APK due to the leading dot in the file name
* component. This trick should make the files
* AndroidManifest.xml, resources.arsc, and classes.dex
* visible to Tcl.
*/
Tcl_DString ds2;
Tcl_DStringInit(&ds2);
Tcl_DStringAppend(&ds2, "assets/.root/", -1);
Tcl_DStringAppend(&ds2, path, -1);
hPtr = Tcl_FindHashEntry(&ZipFS.fileHash, Tcl_DStringValue(&ds2));
if (hPtr != NULL) {
/* should not happen but skip it anyway */
Tcl_DStringFree(&ds2);
goto nextent;
}
Tcl_DStringSetLength(&ds, 0);
Tcl_DStringAppend(&ds, Tcl_DStringValue(&ds2),
Tcl_DStringLength(&ds2));
path = Tcl_DStringValue(&ds);
Tcl_DStringFree(&ds2);
#else
/*
* Regular files skipped when mounting on root.
*/
goto nextent;
#endif
}
Tcl_DStringSetLength(&fpBuf, 0);
fullpath = CanonicalPath(mntpt, path, &fpBuf, 1);
z = (ZipEntry *) Tcl_Alloc(sizeof (*z));
z->name = NULL;
z->tnext = NULL;
z->depth = CountSlashes(fullpath);
z->zipfile = zf;
z->isdir = isdir;
z->isenc = (zip_read_short(lq + ZIP_LOCAL_FLAGS_OFFS) & 1)
&& (nbcompr > 12);
z->offset = offs;
if (gq != NULL) {
z->crc32 = zip_read_int(gq + ZIP_CENTRAL_CRC32_OFFS);
dosDate = zip_read_short(gq + ZIP_CENTRAL_MDATE_OFFS);
dosTime = zip_read_short(gq + ZIP_CENTRAL_MTIME_OFFS);
z->timestamp = DosTimeDate(dosDate, dosTime);
z->nbyte = zip_read_int(gq + ZIP_CENTRAL_UNCOMPLEN_OFFS);
z->cmeth = zip_read_short(gq + ZIP_CENTRAL_COMPMETH_OFFS);
} else {
z->crc32 = zip_read_int(lq + ZIP_LOCAL_CRC32_OFFS);
dosDate = zip_read_short(lq + ZIP_LOCAL_MDATE_OFFS);
dosTime = zip_read_short(lq + ZIP_LOCAL_MTIME_OFFS);
z->timestamp = DosTimeDate(dosDate, dosTime);
z->nbyte = zip_read_int(lq + ZIP_LOCAL_UNCOMPLEN_OFFS);
z->cmeth = zip_read_short(lq + ZIP_LOCAL_COMPMETH_OFFS);
}
z->nbytecompr = nbcompr;
z->data = NULL;
hPtr = Tcl_CreateHashEntry(&ZipFS.fileHash, fullpath, &isNew);
if (!isNew) {
/* should not happen but skip it anyway */
Tcl_Free((char *) z);
} else {
Tcl_SetHashValue(hPtr, (ClientData) z);
z->name = Tcl_GetHashKey(&ZipFS.fileHash, hPtr);
z->next = zf->entries;
zf->entries = z;
if (isdir && (mntpt[0] == '\0') && (z->depth == 1)) {
z->tnext = zf->topents;
zf->topents = z;
}
if (!z->isdir && (z->depth > 1)) {
char *dir, *end;
ZipEntry *zd;
Tcl_DStringSetLength(&ds, strlen(z->name) + 8);
Tcl_DStringSetLength(&ds, 0);
Tcl_DStringAppend(&ds, z->name, -1);
dir = Tcl_DStringValue(&ds);
end = strrchr(dir, '/');
while ((end != NULL) && (end != dir)) {
Tcl_DStringSetLength(&ds, end - dir);
hPtr = Tcl_FindHashEntry(&ZipFS.fileHash, dir);
if (hPtr != NULL) {
break;
}
zd = (ZipEntry *) Tcl_Alloc(sizeof (*zd));
zd->name = NULL;
zd->tnext = NULL;
zd->depth = CountSlashes(dir);
zd->zipfile = zf;
zd->isdir = 1;
zd->isenc = 0;
zd->offset = z->offset;
zd->crc32 = 0;
zd->timestamp = z->timestamp;
zd->nbyte = zd->nbytecompr = 0;
zd->cmeth = ZIP_COMPMETH_STORED;
zd->data = NULL;
hPtr = Tcl_CreateHashEntry(&ZipFS.fileHash, dir, &isNew);
if (!isNew) {
/* should not happen but skip it anyway */
Tcl_Free((char *) zd);
} else {
Tcl_SetHashValue(hPtr, (ClientData) zd);
zd->name = Tcl_GetHashKey(&ZipFS.fileHash, hPtr);
zd->next = zf->entries;
zf->entries = zd;
if ((mntpt[0] == '\0') && (zd->depth == 1)) {
zd->tnext = zf->topents;
zf->topents = zd;
}
}
end = strrchr(dir, '/');
}
}
}
nextent:
q += pathlen + comlen + extra + ZIP_CENTRAL_HEADER_LEN;
}
Unlock();
Tcl_DStringFree(&fpBuf);
Tcl_DStringFree(&ds);
Tcl_DStringFree(&dsm);
Tcl_FSMountsChanged(NULL);
return TCL_OK;
}
/*
*-------------------------------------------------------------------------
*
* TclZipfsUnmount --
*
* This procedure is invoked to unmount a given ZIP archive.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* A mounted ZIP archive file is unmounted, resources are free'd.
*
*-------------------------------------------------------------------------
*/
int
TclZipfsUnmount(Tcl_Interp *interp, const char *zipname)
{
char *realname;
ZipFile *zf;
ZipEntry *z, *znext;
Tcl_HashEntry *hPtr;
Tcl_DString ds;
int ret = TCL_OK, unmounted = 0;
Tcl_DStringInit(&ds);
realname = AbsolutePath(zipname, &ds, 0);
WriteLock();
if (!ZipFS.initialized) {
goto done;
}
hPtr = Tcl_FindHashEntry(&ZipFS.zipHash, realname);
if (hPtr == NULL) {
/* don't report error */
goto done;
}
zf = (ZipFile *) Tcl_GetHashValue(hPtr);
if (zf->nopen > 0) {
if (interp != NULL) {
Tcl_SetObjResult(interp,
Tcl_NewStringObj("filesystem is busy", -1));
}
ret = TCL_ERROR;
goto done;
}
Tcl_DeleteHashEntry(hPtr);
for (z = zf->entries; z; z = znext) {
znext = z->next;
hPtr = Tcl_FindHashEntry(&ZipFS.fileHash, z->name);
if (hPtr) {
Tcl_DeleteHashEntry(hPtr);
}
if (z->data != NULL) {
Tcl_Free((char *) z->data);
}
Tcl_Free((char *) z);
}
ZipFSCloseArchive(interp, zf);
Tcl_Free((char *) zf);
unmounted = 1;
done:
Unlock();
Tcl_DStringFree(&ds);
if (unmounted) {
Tcl_FSMountsChanged(NULL);
}
return ret;
}
/*
*-------------------------------------------------------------------------
*
* ZipFSMountObjCmd --
*
|
| ︙ | ︙ | |||
1524 1525 1526 1527 1528 1529 1530 |
int objc, Tcl_Obj *const objv[])
{
if (objc > 4) {
Tcl_WrongNumArgs(interp, 1, objv,
"?zipfile? ?mountpoint? ?password?");
return TCL_ERROR;
}
| | | 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 |
int objc, Tcl_Obj *const objv[])
{
if (objc > 4) {
Tcl_WrongNumArgs(interp, 1, objv,
"?zipfile? ?mountpoint? ?password?");
return TCL_ERROR;
}
return TclZipfsMount(interp, (objc > 1) ? Tcl_GetString(objv[1]) : NULL,
(objc > 2) ? Tcl_GetString(objv[2]) : NULL,
(objc > 3) ? Tcl_GetString(objv[3]) : NULL);
}
/*
*-------------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
1553 1554 1555 1556 1557 1558 1559 |
ZipFSUnmountObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[])
{
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "zipfile");
return TCL_ERROR;
}
| | | 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 |
ZipFSUnmountObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[])
{
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "zipfile");
return TCL_ERROR;
}
return TclZipfsUnmount(interp, Tcl_GetString(objv[1]));
}
/*
*-------------------------------------------------------------------------
*
* ZipFSMkKeyObjCmd --
*
|
| ︙ | ︙ | |||
2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 |
* Always TCL_OK.
*
* Side effects:
* None.
*
*-------------------------------------------------------------------------
*/
static int
ZipFSExistsObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[])
{
char *filename;
int exists;
if (objc != 2) {
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | | | | 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 |
* Always TCL_OK.
*
* Side effects:
* None.
*
*-------------------------------------------------------------------------
*/
static int
ZipFSCanonicalObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[])
{
char *mntpoint=NULL;
char *filename=NULL;
char *result;
Tcl_DString dPath;
if (objc != 2 && objc != 3 && objc!=4) {
Tcl_WrongNumArgs(interp, 1, objv, "?mntpnt? filename ?ZIPFS?");
return TCL_ERROR;
}
Tcl_DStringInit(&dPath);
if(objc==2) {
filename = Tcl_GetString(objv[1]);
result=CanonicalPath("",filename,&dPath,1);
} else if (objc==3) {
mntpoint = Tcl_GetString(objv[1]);
filename = Tcl_GetString(objv[2]);
result=CanonicalPath(mntpoint,filename,&dPath,1);
} else {
int zipfs=0;
if(Tcl_GetBooleanFromObj(interp,objv[3],&zipfs)) {
return TCL_ERROR;
}
mntpoint = Tcl_GetString(objv[1]);
filename = Tcl_GetString(objv[2]);
result=CanonicalPath(mntpoint,filename,&dPath,zipfs);
}
Tcl_SetObjResult(interp,Tcl_NewStringObj(result,-1));
return TCL_OK;
}
/*
*-------------------------------------------------------------------------
*
* ZipFSExistsObjCmd --
*
* This procedure is invoked to process the "zipfs::exists" command.
* It tests for the existence of a file in the ZIP filesystem and
* places a boolean into the interp's result.
*
* Results:
* Always TCL_OK.
*
* Side effects:
* None.
*
*-------------------------------------------------------------------------
*/
static int
ZipFSExistsObjCmd(ClientData clientData, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[])
{
char *filename;
int exists;
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "filename");
return TCL_ERROR;
}
filename = Tcl_GetStringFromObj(objv[1], 0);
ReadLock();
exists = ZipFSLookup(filename) != NULL;
Unlock();
Tcl_SetObjResult(interp,Tcl_NewBooleanObj(exists));
return TCL_OK;
}
/*
*-------------------------------------------------------------------------
*
* ZipFSInfoObjCmd --
|
| ︙ | ︙ | |||
3251 3252 3253 3254 3255 3256 3257 | * results are lappend'ed to resultPtr (which must be a valid object). * * Side effects: * None. * *------------------------------------------------------------------------- */ | < | | | | < < < | < < < < < < < | | | | | | | | < | < < < | | | | < < < < < < < < | | < < < < | < < < < < < | | < | < < < < < | | | | | | | | | | | | < | | < | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | < | | | | | | | | | | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 |
* results are lappend'ed to resultPtr (which must be a valid object).
*
* Side effects:
* None.
*
*-------------------------------------------------------------------------
*/
static int
Zip_FSMatchInDirectoryProc(Tcl_Interp* interp, Tcl_Obj *result,
Tcl_Obj *pathPtr, const char *pattern,
Tcl_GlobTypeData *types)
{
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
int scnt, len, l, dirOnly = -1, prefixLen, strip = 0;
char *pat, *prefix, *path;
Tcl_DString ds, dsPref;
if (types != NULL) {
dirOnly = (types->type & TCL_GLOB_TYPE_DIR) == TCL_GLOB_TYPE_DIR;
}
Tcl_DStringInit(&ds);
Tcl_DStringInit(&dsPref);
prefix = Tcl_GetStringFromObj(pathPtr, &prefixLen);
Tcl_DStringAppend(&dsPref, prefix, prefixLen);
prefix = Tcl_DStringValue(&dsPref);
path = AbsolutePath(prefix, &ds, 1);
len = Tcl_DStringLength(&ds);
if (strcmp(prefix, path) == 0) {
prefix = NULL;
} else {
strip = len + 1;
}
if (prefix != NULL) {
Tcl_DStringAppend(&dsPref, "/", 1);
prefixLen++;
prefix = Tcl_DStringValue(&dsPref);
}
ReadLock();
if ((types != NULL) && (types->type == TCL_GLOB_TYPE_MOUNT)) {
l = CountSlashes(path);
if (path[len - 1] == '/') {
len--;
} else {
l++;
}
if ((pattern == NULL) || (pattern[0] == '\0')) {
pattern = "*";
}
hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &search);
while (hPtr != NULL) {
ZipFile *zf = (ZipFile *) Tcl_GetHashValue(hPtr);
if (zf->mntptlen == 0) {
ZipEntry *z = zf->topents;
while (z != NULL) {
int lenz = strlen(z->name);
if ((lenz > len + 1) &&
(strncmp(z->name, path, len) == 0) &&
(z->name[len] == '/') &&
(CountSlashes(z->name) == l) &&
Tcl_StringCaseMatch(z->name + len + 1, pattern, 0)) {
if (prefix != NULL) {
Tcl_DStringAppend(&dsPref, z->name, lenz);
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(Tcl_DStringValue(&dsPref),
Tcl_DStringLength(&dsPref)));
Tcl_DStringSetLength(&dsPref, prefixLen);
} else {
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(z->name, lenz));
}
}
z = z->tnext;
}
} else if ((zf->mntptlen > len + 1) &&
(strncmp(zf->mntpt, path, len) == 0) &&
(zf->mntpt[len] == '/') &&
(CountSlashes(zf->mntpt) == l) &&
Tcl_StringCaseMatch(zf->mntpt + len + 1, pattern, 0)) {
if (prefix != NULL) {
Tcl_DStringAppend(&dsPref, zf->mntpt, zf->mntptlen);
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(Tcl_DStringValue(&dsPref),
Tcl_DStringLength(&dsPref)));
Tcl_DStringSetLength(&dsPref, prefixLen);
} else {
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(zf->mntpt, zf->mntptlen));
}
}
hPtr = Tcl_NextHashEntry(&search);
}
goto end;
}
if ((pattern == NULL) || (pattern[0] == '\0')) {
hPtr = Tcl_FindHashEntry(&ZipFS.fileHash, path);
if (hPtr != NULL) {
ZipEntry *z = (ZipEntry *) Tcl_GetHashValue(hPtr);
if ((dirOnly < 0) ||
(!dirOnly && !z->isdir) ||
(dirOnly && z->isdir)) {
if (prefix != NULL) {
Tcl_DStringAppend(&dsPref, z->name, -1);
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(Tcl_DStringValue(&dsPref),
Tcl_DStringLength(&dsPref)));
Tcl_DStringSetLength(&dsPref, prefixLen);
} else {
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(z->name, -1));
}
}
}
goto end;
}
l = strlen(pattern);
pat = Tcl_Alloc(len + l + 2);
memcpy(pat, path, len);
while ((len > 1) && (pat[len - 1] == '/')) {
--len;
}
if ((len > 1) || (pat[0] != '/')) {
pat[len] = '/';
++len;
}
memcpy(pat + len, pattern, l + 1);
scnt = CountSlashes(pat);
for (hPtr = Tcl_FirstHashEntry(&ZipFS.fileHash, &search);
hPtr != NULL; hPtr = Tcl_NextHashEntry(&search)) {
ZipEntry *z = (ZipEntry *) Tcl_GetHashValue(hPtr);
if ((dirOnly >= 0) &&
((dirOnly && !z->isdir) || (!dirOnly && z->isdir))) {
continue;
}
if ((z->depth == scnt) && Tcl_StringCaseMatch(z->name, pat, 0)) {
if (prefix != NULL) {
Tcl_DStringAppend(&dsPref, z->name + strip, -1);
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(Tcl_DStringValue(&dsPref),
Tcl_DStringLength(&dsPref)));
Tcl_DStringSetLength(&dsPref, prefixLen);
} else {
Tcl_ListObjAppendElement(NULL, result,
Tcl_NewStringObj(z->name + strip, -1));
}
}
}
Tcl_Free(pat);
end:
Unlock();
Tcl_DStringFree(&dsPref);
Tcl_DStringFree(&ds);
return TCL_OK;
}
/*
*-------------------------------------------------------------------------
*
* Zip_FSPathInFilesystemProc --
*
|
| ︙ | ︙ | |||
3506 3507 3508 3509 3510 3511 3512 |
{
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
ZipFile *zf;
int ret = -1, len;
char *path;
Tcl_DString ds;
| < < < > > > > < < < | < < < < < < < < < < | | | < < < < < | < < < < < < | | < | | | | | | | | | | | | | | | | 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 |
{
Tcl_HashEntry *hPtr;
Tcl_HashSearch search;
ZipFile *zf;
int ret = -1, len;
char *path;
Tcl_DString ds;
path = Tcl_GetStringFromObj(pathPtr, &len);
if(strncmp(path,ZIPFS_VOLUME,ZIPFS_VOLUME_LEN)!=0) {
return -1;
}
Tcl_DStringInit(&ds);
path = CanonicalPath("",path, &ds, 1);
len = Tcl_DStringLength(&ds);
ReadLock();
hPtr = Tcl_FindHashEntry(&ZipFS.fileHash, path);
if (hPtr != NULL) {
ret = TCL_OK;
goto endloop;
}
hPtr = Tcl_FirstHashEntry(&ZipFS.zipHash, &search);
while (hPtr != NULL) {
zf = (ZipFile *) Tcl_GetHashValue(hPtr);
if (zf->mntptlen == 0) {
ZipEntry *z = zf->topents;
while (z != NULL) {
int lenz = strlen(z->name);
if ((len >= lenz) &&
(strncmp(path, z->name, lenz) == 0)) {
ret = TCL_OK;
goto endloop;
}
z = z->tnext;
}
} else if ((len >= zf->mntptlen) &&
(strncmp(path, zf->mntpt, zf->mntptlen) == 0)) {
ret = TCL_OK;
goto endloop;
}
hPtr = Tcl_NextHashEntry(&search);
}
endloop:
Unlock();
Tcl_DStringFree(&ds);
return ret;
}
|
| ︙ | ︙ | |||
3588 3589 3590 3591 3592 3593 3594 | * The list of volumes. * * Side effects: * None * *------------------------------------------------------------------------- */ | < | < < < < < < < < < < < < < < < < < | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 |
* The list of volumes.
*
* Side effects:
* None
*
*-------------------------------------------------------------------------
*/
static Tcl_Obj *
Zip_FSListVolumesProc(void) {
return Tcl_NewStringObj(ZIPFS_VOLUME, -1);
}
/*
*-------------------------------------------------------------------------
*
* Zip_FSFileAttrStringsProc --
*
|
| ︙ | ︙ | |||
3945 3946 3947 3948 3949 3950 3951 |
sizeof (Tcl_Filesystem),
TCL_FILESYSTEM_VERSION_2,
Zip_FSPathInFilesystemProc,
NULL, /* dupInternalRepProc */
NULL, /* freeInternalRepProc */
NULL, /* internalToNormalizedProc */
NULL, /* createInternalRepProc */
| | | 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 |
sizeof (Tcl_Filesystem),
TCL_FILESYSTEM_VERSION_2,
Zip_FSPathInFilesystemProc,
NULL, /* dupInternalRepProc */
NULL, /* freeInternalRepProc */
NULL, /* internalToNormalizedProc */
NULL, /* createInternalRepProc */
NULL, /* normalizePathProc */
Zip_FSFilesystemPathTypeProc,
Zip_FSFilesystemSeparatorProc,
Zip_FSStatProc,
Zip_FSAccessProc,
Zip_FSOpenFileChannelProc,
Zip_FSMatchInDirectoryProc,
NULL, /* utimeProc */
|
| ︙ | ︙ | |||
3967 3968 3969 3970 3971 3972 3973 |
NULL, /* deleteFileProc */
NULL, /* copyFileProc */
NULL, /* renameFileProc */
NULL, /* copyDirectoryProc */
NULL, /* lstatProc */
(Tcl_FSLoadFileProc *) Zip_FSLoadFile,
NULL, /* getCwdProc */
| | | < < < < < < < | < < < < < < < < < < < < < < < < < | | | > > > > > > > > > > > > > > > > > > > | | | | | | | | | | | | < < < < < < | | < | | | | | | | | | | | | | | | | | | | < < | | | < | < | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | | | | | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 |
NULL, /* deleteFileProc */
NULL, /* copyFileProc */
NULL, /* renameFileProc */
NULL, /* copyDirectoryProc */
NULL, /* lstatProc */
(Tcl_FSLoadFileProc *) Zip_FSLoadFile,
NULL, /* getCwdProc */
NULL, /* chdirProc*/
};
#endif /* HAVE_ZLIB */
/*
*-------------------------------------------------------------------------
*
* TclZipfsInit --
*
* Perform per interpreter initialization of this module.
*
* Results:
* The return value is a standard Tcl result.
*
* Side effects:
* Initializes this module if not already initialized, and adds
* module related commands to the given interpreter.
*
*-------------------------------------------------------------------------
*/
int
TclZipfsInit(Tcl_Interp *interp)
{
#ifdef HAVE_ZLIB
/* one-time initialization */
WriteLock();
if (!ZipFS.initialized) {
#ifdef TCL_THREADS
static const Tcl_Time t = { 0, 0 };
/*
* Inflate condition variable.
*/
Tcl_MutexLock(&ZipFSMutex);
Tcl_ConditionWait(&ZipFSCond, &ZipFSMutex, &t);
Tcl_MutexUnlock(&ZipFSMutex);
#endif
Tcl_FSRegister(NULL, &zipfsFilesystem);
Tcl_InitHashTable(&ZipFS.fileHash, TCL_STRING_KEYS);
Tcl_InitHashTable(&ZipFS.zipHash, TCL_STRING_KEYS);
ZipFS.initialized = ZipFS.idCount = 1;
}
Unlock();
if(interp != NULL) {
static const EnsembleImplMap initMap[] = {
{"mount", ZipFSMountObjCmd, NULL, NULL, NULL, 0},
{"unmount", ZipFSUnmountObjCmd, NULL, NULL, NULL, 0},
{"mkkey", ZipFSMkKeyObjCmd, NULL, NULL, NULL, 0},
{"mkimg", ZipFSMkImgObjCmd, NULL, NULL, NULL, 0},
{"mkzip", ZipFSMkZipObjCmd, NULL, NULL, NULL, 0},
{"lmkimg", ZipFSLMkImgObjCmd, NULL, NULL, NULL, 0},
{"lmkzip", ZipFSLMkZipObjCmd, NULL, NULL, NULL, 0},
{"exists", ZipFSExistsObjCmd, NULL, NULL, NULL, 1},
{"info", ZipFSInfoObjCmd, NULL, NULL, NULL, 1},
{"list", ZipFSListObjCmd, NULL, NULL, NULL, 1},
{"canonical", ZipFSCanonicalObjCmd, NULL, NULL, NULL, 1},
{NULL, NULL, NULL, NULL, NULL, 0}
};
static const char findproc[] =
"namespace eval zipfs {}\n"
"proc ::zipfs::find dir {\n"
" set result {}\n"
" if {[catch {glob -directory $dir -tails -nocomplain * .*} list]} {\n"
" return $result\n"
" }\n"
" foreach file $list {\n"
" if {$file eq \".\" || $file eq \"..\"} {\n"
" continue\n"
" }\n"
" set file [file join $dir $file]\n"
" lappend result $file\n"
" foreach file [::zipfs::find $file] {\n"
" lappend result $file\n"
" }\n"
" }\n"
" return [lsort $result]\n"
"}\n";
Tcl_EvalEx(interp, findproc, -1, TCL_EVAL_GLOBAL);
Tcl_LinkVar(interp, "::zipfs::wrmax", (char *) &ZipFS.wrmax,
TCL_LINK_INT);
TclMakeEnsemble(interp, "zipfs", initMap);
Tcl_PkgProvide(interp, "zipfs", "1.0");
}
return TCL_OK;
#else
if (interp != NULL) {
Tcl_SetObjResult(interp, Tcl_NewStringObj("no zlib available", -1));
}
return TCL_ERROR;
#endif
}
#ifndef HAVE_ZLIB
/*
*-------------------------------------------------------------------------
*
* TclZipfsMount, TclZipfsUnmount --
*
* Dummy version when no ZLIB support available.
*
*-------------------------------------------------------------------------
*/
int
TclZipfsMount(Tcl_Interp *interp, const char *zipname, const char *mntpt,
const char *passwd)
{
return TclZipFsInit(interp, 1);
}
int
TclZipfsUnmount(Tcl_Interp *interp, const char *zipname)
{
return TclZipFsInit(interp, 1);
}
#endif
/*
* Local Variables:
* mode: c
* c-basic-offset: 4
* fill-column: 78
* End:
*/
|
Deleted generic/tclZipfs.h.
|
| < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < |
Added library/practcl/pkgIndex.tcl.
> > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 | # Tcl package index file, version 1.1 # This file is generated by the "pkg_mkIndex" command # and sourced either when an application starts up or # by a "package unknown" script. It invokes the # "package ifneeded" command to set up package-related # information so that packages will be loaded automatically # in response to "package require" commands. When this # script is sourced, the variable $dir must contain the # full path name of this file's directory. package ifneeded practcl 0.5 [list source [file join $dir practcl.tcl]] |
Added library/practcl/practcl.tcl.
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 |
###
# Practcl
# An object oriented templating system for stamping out Tcl API calls to C
###
puts [list LOADED practcl.tcl from [info script]]
package require TclOO
proc ::debug args {
#puts $args
::practcl::cputs ::DEBUG_INFO $args
}
###
# Drop in a static copy of Tcl
###
proc ::doexec args {
puts [list {*}$args]
exec {*}$args >&@ stdout
}
proc ::dotclexec args {
puts [list [info nameofexecutable] {*}$args]
exec [info nameofexecutable] {*}$args >&@ stdout
}
proc ::domake {path args} {
set PWD [pwd]
cd $path
puts [list *** $path ***]
puts [list make {*}$args]
exec make {*}$args >&@ stdout
cd $PWD
}
proc ::domake.tcl {path args} {
set PWD [pwd]
cd $path
puts [list *** $path ***]
puts [list make.tcl {*}$args]
exec [info nameofexecutable] make.tcl {*}$args >&@ stdout
cd $PWD
}
proc ::fossil {path args} {
set PWD [pwd]
cd $path
puts [list {*}$args]
exec fossil {*}$args >&@ stdout
cd $PWD
}
proc ::fossil_status {dir} {
if {[info exists ::fosdat($dir)]} {
return $::fosdat($dir)
}
set result {
tags experimental
version {}
}
set pwd [pwd]
cd $dir
set info [exec fossil status]
cd $pwd
foreach line [split $info \n] {
if {[lindex $line 0] eq "checkout:"} {
set hash [lindex $line end-3]
set maxdate [lrange $line end-2 end-1]
dict set result hash $hash
dict set result maxdate $maxdate
regsub -all {[^0-9]} $maxdate {} isodate
dict set result isodate $isodate
}
if {[lindex $line 0] eq "tags:"} {
set tags [lrange $line 1 end]
dict set result tags $tags
break
}
}
set ::fosdat($dir) $result
return $result
}
###
# Seek out Tcllib if it's available
###
set tcllib_path {}
foreach path {.. ../.. ../../..} {
foreach path [glob -nocomplain [file join [file normalize $path] tcllib* modules]] {
set tclib_path $path
lappend ::auto_path $path
break
}
if {$tcllib_path ne {}} break
}
###
# Build utility functions
###
namespace eval ::practcl {}
proc ::practcl::os {} {
if {[info exists ::project(TEACUP_OS)] && $::project(TEACUP_OS) ni {"@TEACUP_OS@" {}}} {
return $::project(TEACUP_OS)
}
set info [::practcl::config.tcl $::project(builddir)]
if {[dict exists $info TEACUP_OS]} {
return [dict get $info TEACUP_OS]
}
return unknown
}
###
# Detect local platform
###
proc ::practcl::config.tcl {path} {
dict set result buildpath $path
set result {}
if {[file exists [file join $path config.tcl]]} {
set fin [open [file join $path config.tcl] r]
set bufline {}
set rawcount 0
set linecount 0
while {[gets $fin thisline]>=0} {
incr rawcount
append bufline \n $thisline
if {![info complete $bufline]} continue
set line [string trimleft $bufline]
set bufline {}
if {[string index [string trimleft $line] 0] eq "#"} continue
incr linecount
set key [lindex $line 0]
set value [lindex $line 1]
dict set result $key $value
}
dict set result sandbox [file dirname [dict get $result srcdir]]
dict set result download [file join [dict get $result sandbox] download]
dict set result teapot [file join [dict get $result sandbox] teapot]
set result [::practcl::de_shell $result]
}
# If data is available from autoconf, defer to that
if {[dict exists $result TEACUP_OS] && [dict get $result TEACUP_OS] ni {"@TEACUP_OS@" {}}} {
return $result
}
# If autoconf hasn't run yet, assume we are not cross compiling
# and defer to local checks
dict set result TEACUP_PROFILE unknown
dict set result TEACUP_OS unknown
dict set result EXEEXT {}
if {$::tcl_platform(platform) eq "windows"} {
set system "windows"
set arch ix86
dict set result TEACUP_PROFILE win32-ix86
dict set result TEACUP_OS windows
dict set result EXEEXT .exe
} else {
set system [exec uname -s]-[exec uname -r]
set arch unknown
dict set result TEACUP_OS generic
}
dict set result TEA_PLATFORM $system
dict set result TEA_SYSTEM $system
switch -glob $system {
Linux* {
dict set result TEACUP_OS linux
set arch [exec uname -m]
dict set result TEACUP_PROFILE "linux-glibc2.3-$arch"
}
GNU* {
set arch [exec uname -m]
dict set result TEACUP_OS "gnu"
}
NetBSD-Debian {
set arch [exec uname -m]
dict set result TEACUP_OS "netbsd-debian"
}
OpenBSD-* {
set arch [exec arch -s]
dict set result TEACUP_OS "openbsd"
}
Darwin* {
set arch [exec uname -m]
dict set result TEACUP_OS "macosx"
if {$arch eq "x86_64"} {
dict set result TEACUP_PROFILE "macosx10.5-i386-x86_84"
} else {
dict set result TEACUP_PROFILE "macosx-universal"
}
}
OpenBSD* {
set arch [exec arch -s]
dict set result TEACUP_OS "openbsd"
}
}
if {$arch eq "unknown"} {
catch {set arch [exec uname -m]}
}
switch -glob $arch {
i*86 {
set arch "ix86"
}
amd64 {
set arch "x86_64"
}
}
dict set result TEACUP_ARCH $arch
if {[dict get $result TEACUP_PROFILE] eq "unknown"} {
dict set result TEACUP_PROFILE [dict get $result TEACUP_OS]-$arch
}
return $result
}
###
# Convert an MSYS path to a windows native path
###
if {$::tcl_platform(platform) eq "windows"} {
proc ::practcl::msys_to_tclpath msyspath {
return [exec sh -c "cd $msyspath ; pwd -W"]
}
} else {
proc ::practcl::msys_to_tclpath msyspath {
return [file normalize $msyspath]
}
}
###
# Bits stolen from fileutil
###
proc ::practcl::cat fname {
set fname [open $fname r]
set data [read $fname]
close $fname
return $data
}
proc ::practcl::file_lexnormalize {sp} {
set spx [file split $sp]
# Resolution of embedded relative modifiers (., and ..).
if {
([lsearch -exact $spx . ] < 0) &&
([lsearch -exact $spx ..] < 0)
} {
# Quick path out if there are no relative modifiers
return $sp
}
set absolute [expr {![string equal [file pathtype $sp] relative]}]
# A volumerelative path counts as absolute for our purposes.
set sp $spx
set np {}
set noskip 1
while {[llength $sp]} {
set ele [lindex $sp 0]
set sp [lrange $sp 1 end]
set islast [expr {[llength $sp] == 0}]
if {[string equal $ele ".."]} {
if {
($absolute && ([llength $np] > 1)) ||
(!$absolute && ([llength $np] >= 1))
} {
# .. : Remove the previous element added to the
# new path, if there actually is enough to remove.
set np [lrange $np 0 end-1]
}
} elseif {[string equal $ele "."]} {
# Ignore .'s, they stay at the current location
continue
} else {
# A regular element.
lappend np $ele
}
}
if {[llength $np] > 0} {
return [eval [linsert $np 0 file join]]
# 8.5: return [file join {*}$np]
}
return {}
}
proc ::practcl::file_relative {base dst} {
# Ensure that the link to directory 'dst' is properly done relative to
# the directory 'base'.
if {![string equal [file pathtype $base] [file pathtype $dst]]} {
return -code error "Unable to compute relation for paths of different pathtypes: [file pathtype $base] vs. [file pathtype $dst], ($base vs. $dst)"
}
set base [file_lexnormalize [file join [pwd] $base]]
set dst [file_lexnormalize [file join [pwd] $dst]]
set save $dst
set base [file split $base]
set dst [file split $dst]
while {[string equal [lindex $dst 0] [lindex $base 0]]} {
set dst [lrange $dst 1 end]
set base [lrange $base 1 end]
if {![llength $dst]} {break}
}
set dstlen [llength $dst]
set baselen [llength $base]
if {($dstlen == 0) && ($baselen == 0)} {
# Cases:
# (a) base == dst
set dst .
} else {
# Cases:
# (b) base is: base/sub = sub
# dst is: base = {}
# (c) base is: base = {}
# dst is: base/sub = sub
while {$baselen > 0} {
set dst [linsert $dst 0 ..]
incr baselen -1
}
# 8.5: set dst [file join {*}$dst]
set dst [eval [linsert $dst 0 file join]]
}
return $dst
}
###
# Unpack the source of a fossil project into a designated location
###
proc ::practcl::fossil_sandbox {pkg args} {
if {[llength $args]==1} {
set info [lindex $args 0]
} else {
set info $args
}
set result $info
if {[dict exists $info srcroot]} {
set srcroot [dict get $info srcroot]
} elseif {[dict exists $info sandbox]} {
set srcroot [file join [dict get $info sandbox] $pkg]
} else {
set srcroot [file join $::CWD .. $pkg]
}
dict set result srcroot $srcroot
puts [list fossil_sandbox $pkg $srcroot]
if {[dict exists $info download]} {
###
# Source is actually a zip archive
###
set download [dict get $info download]
if {[file exists [file join $download $pkg.zip]]} {
if {![info exists $srcroot]} {
package require zipfile::decode
::zipfile::decode::unzipfile [file join $download $pkg.zip] $srcroot
}
return
}
}
variable fossil_dbs
if {![::info exists fossil_dbs]} {
# Get a list of local fossil databases
set fossil_dbs [exec fossil all list]
}
set CWD [pwd]
if {![dict exists $info tag]} {
set tag trunk
} else {
set tag [dict get $info tag]
}
dict set result tag $tag
try {
if {[file exists [file join $srcroot .fslckout]]} {
if {[dict exists $info update] && [dict get $info update]==1} {
catch {
puts "FOSSIL UPDATE"
cd $srcroot
doexec fossil update $tag
}
}
} elseif {[file exists [file join $srcroot _FOSSIL_]]} {
if {[dict exists $info update] && [dict get $info update]==1} {
catch {
puts "FOSSIL UPDATE"
cd $srcroot
doexec fossil update $tag
}
}
} else {
puts "OPEN AND UNPACK"
set fosdb {}
foreach line [split $fossil_dbs \n] {
set line [string trim $line]
if {[file rootname [file tail $line]] eq $pkg} {
set fosdb $line
break
}
}
if {$fosdb eq {}} {
file mkdir [file join $download fossil]
set fosdb [file join $download fossil $pkg.fos]
set cloned 0
if {[dict exists $info localmirror]} {
set localmirror [dict get $info localmirror]
catch {
doexec fossil clone $localmirror/$pkg $fosdb
set cloned 1
}
}
if {!$cloned && [dict exists $info fossil_url]} {
set localmirror [dict get $info fossil_url]
catch {
doexec fossil clone $localmirror/$pkg $fosdb
set cloned 1
}
}
if {!$cloned} {
doexec fossil clone http://fossil.etoyoc.com/fossil/$pkg $fosdb
}
}
file mkdir $srcroot
cd $srcroot
puts "FOSSIL OPEN [pwd]"
doexec fossil open $fosdb $tag
}
} on error {result opts} {
puts [list ERR [dict get $opts -errorinfo]]
return {*}$opts
} finally {
cd $CWD
}
return $result
}
###
# topic: e71f3f61c348d56292011eec83e95f0aacc1c618
# description: Converts a XXX.sh file into a series of Tcl variables
###
proc ::practcl::read_sh_subst {line info} {
regsub -all {\x28} $line \x7B line
regsub -all {\x29} $line \x7D line
#set line [string map $key [string trim $line]]
foreach {field value} $info {
catch {set $field $value}
}
if [catch {subst $line} result] {
return {}
}
set result [string trim $result]
return [string trim $result ']
}
###
# topic: 03567140cca33c814664c7439570f669b9ab88e6
###
proc ::practcl::read_sh_file {filename {localdat {}}} {
set fin [open $filename r]
set result {}
if {$localdat eq {}} {
set top 1
set local [array get ::env]
dict set local EXE {}
} else {
set top 0
set local $localdat
}
while {[gets $fin line] >= 0} {
set line [string trim $line]
if {[string index $line 0] eq "#"} continue
if {$line eq {}} continue
catch {
if {[string range $line 0 6] eq "export "} {
set eq [string first "=" $line]
set field [string trim [string range $line 6 [expr {$eq - 1}]]]
set value [read_sh_subst [string range $line [expr {$eq+1}] end] $local]
dict set result $field [read_sh_subst $value $local]
dict set local $field $value
} elseif {[string range $line 0 7] eq "include "} {
set subfile [read_sh_subst [string range $line 7 end] $local]
foreach {field value} [read_sh_file $subfile $local] {
dict set result $field $value
}
} else {
set eq [string first "=" $line]
if {$eq > 0} {
set field [read_sh_subst [string range $line 0 [expr {$eq - 1}]] $local]
set value [string trim [string range $line [expr {$eq+1}] end] ']
#set value [read_sh_subst [string range $line [expr {$eq+1}] end] $local]
dict set local $field $value
dict set result $field $value
}
}
} err opts
if {[dict get $opts -code] != 0} {
#puts $opts
puts "Error reading line:\n$line\nerr: $err\n***"
return $err {*}$opts
}
}
return $result
}
###
# A simpler form of read_sh_file tailored
# to pulling data from (tcl|tk)Config.sh
###
proc ::practcl::read_Config.sh filename {
set fin [open $filename r]
set result {}
set linecount 0
while {[gets $fin line] >= 0} {
set line [string trim $line]
if {[string index $line 0] eq "#"} continue
if {$line eq {}} continue
catch {
set eq [string first "=" $line]
if {$eq > 0} {
set field [string range $line 0 [expr {$eq - 1}]]
set value [string trim [string range $line [expr {$eq+1}] end] ']
#set value [read_sh_subst [string range $line [expr {$eq+1}] end] $local]
dict set result $field $value
incr $linecount
}
} err opts
if {[dict get $opts -code] != 0} {
#puts $opts
puts "Error reading line:\n$line\nerr: $err\n***"
return $err {*}$opts
}
}
return $result
}
###
# A simpler form of read_sh_file tailored
# to pulling data from a Makefile
###
proc ::practcl::read_Makefile filename {
set fin [open $filename r]
set result {}
while {[gets $fin line] >= 0} {
set line [string trim $line]
if {[string index $line 0] eq "#"} continue
if {$line eq {}} continue
catch {
set eq [string first "=" $line]
if {$eq > 0} {
set field [string trim [string range $line 0 [expr {$eq - 1}]]]
set value [string trim [string trim [string range $line [expr {$eq+1}] end] ']]
switch $field {
PKG_LIB_FILE {
dict set result libfile $value
}
srcdir {
if {$value eq "."} {
dict set result srcdir [file dirname $filename]
} else {
dict set result srcdir $value
}
}
PACKAGE_NAME {
dict set result name $value
}
PACKAGE_VERSION {
dict set result version $value
}
LIBS {
dict set result PRACTCL_LIBS $value
}
PKG_LIB_FILE {
dict set result libfile $value
}
}
}
} err opts
if {[dict get $opts -code] != 0} {
#puts $opts
puts "Error reading line:\n$line\nerr: $err\n***"
return $err {*}$opts
}
# the Compile field is about where most TEA files start getting silly
if {$field eq "compile"} {
break
}
}
return $result
}
## Append arguments to a buffer
# The command works like puts in that each call will also insert
# a line feed. Unlike puts, blank links in the interstitial are
# suppressed
proc ::practcl::cputs {varname args} {
upvar 1 $varname buffer
if {[llength $args]==1 && [string length [string trim [lindex $args 0]]] == 0} {
}
if {[info exist buffer]} {
if {[string index $buffer end] ne "\n"} {
append buffer \n
}
} else {
set buffer \n
}
# Trim leading \n's
append buffer [string trimleft [lindex $args 0] \n] {*}[lrange $args 1 end]
}
proc ::practcl::tcl_to_c {body} {
set result {}
foreach rawline [split $body \n] {
set line [string map [list \" \\\" \\ \\\\] $rawline]
cputs result "\n \"$line\\n\" \\"
}
return [string trimright $result \\]
}
proc ::practcl::_tagblock {text {style tcl} {note {}}} {
if {[string length [string trim $text]]==0} {
return {}
}
set output {}
switch $style {
tcl {
::practcl::cputs output "# BEGIN $note"
}
c {
::practcl::cputs output "/* BEGIN $note */"
}
default {
::practcl::cputs output "# BEGIN $note"
}
}
::practcl::cputs output $text
switch $style {
tcl {
::practcl::cputs output "# END $note"
}
c {
::practcl::cputs output "/* END $note */"
}
default {
::practcl::cputs output "# END $note"
}
}
return $output
}
proc ::practcl::_isdirectory name {
return [file isdirectory $name]
}
###
# Return true if the pkgindex file contains
# any statement other than "package ifneeded"
# and/or if any package ifneeded loads a DLL
###
proc ::practcl::_pkgindex_directory {path} {
set buffer {}
set pkgidxfile [file join $path pkgIndex.tcl]
if {![file exists $pkgidxfile]} {
# No pkgIndex file, read the source
foreach file [glob -nocomplain $path/*.tm] {
set file [file normalize $file]
set fname [file rootname [file tail $file]]
###
# We used to be able to ... Assume the package is correct in the filename
# No hunt for a "package provides"
###
set package [lindex [split $fname -] 0]
set version [lindex [split $fname -] 1]
###
# Read the file, and override assumptions as needed
###
set fin [open $file r]
set dat [read $fin]
close $fin
# Look for a teapot style Package statement
foreach line [split $dat \n] {
set line [string trim $line]
if { [string range $line 0 9] != "# Package " } continue
set package [lindex $line 2]
set version [lindex $line 3]
break
}
# Look for a package provide statement
foreach line [split $dat \n] {
set line [string trim $line]
if { [string range $line 0 14] != "package provide" } continue
set package [lindex $line 2]
set version [lindex $line 3]
break
}
append buffer "package ifneeded $package $version \[list source \[file join \$dir [file tail $file]\]\]" \n
}
foreach file [glob -nocomplain $path/*.tcl] {
if { [file tail $file] == "version_info.tcl" } continue
set fin [open $file r]
set dat [read $fin]
close $fin
if {![regexp "package provide" $dat]} continue
set fname [file rootname [file tail $file]]
# Look for a package provide statement
foreach line [split $dat \n] {
set line [string trim $line]
if { [string range $line 0 14] != "package provide" } continue
set package [lindex $line 2]
set version [lindex $line 3]
if {[string index $package 0] in "\$ \["} continue
if {[string index $version 0] in "\$ \["} continue
append buffer "package ifneeded $package $version \[list source \[file join \$dir [file tail $file]\]\]" \n
break
}
}
return $buffer
}
set fin [open $pkgidxfile r]
set dat [read $fin]
close $fin
set thisline {}
foreach line [split $dat \n] {
append thisline $line \n
if {![info complete $thisline]} continue
set line [string trim $line]
if {[string length $line]==0} {
set thisline {} ; continue
}
if {[string index $line 0] eq "#"} {
set thisline {} ; continue
}
try {
# Ignore contditionals
if {[regexp "if.*catch.*package.*Tcl.*return" $thisline]} continue
if {[regexp "if.*package.*vsatisfies.*package.*provide.*return" $thisline]} continue
if {![regexp "package.*ifneeded" $thisline]} {
# This package index contains arbitrary code
# source instead of trying to add it to the master
# package index
return {source [file join $dir pkgIndex.tcl]}
}
append buffer $thisline \n
} on error {err opts} {
puts ***
puts "GOOF: $pkgidxfile"
puts $line
puts $err
puts [dict get $opts -errorinfo]
puts ***
} finally {
set thisline {}
}
}
return $buffer
}
proc ::practcl::_pkgindex_path_subdir {path} {
set result {}
foreach subpath [glob -nocomplain [file join $path *]] {
if {[file isdirectory $subpath]} {
lappend result $subpath {*}[_pkgindex_path_subdir $subpath]
}
}
return $result
}
###
# Index all paths given as though they will end up in the same
# virtual file system
###
proc ::practcl::pkgindex_path args {
set stack {}
set buffer {
lappend ::PATHSTACK $dir
}
foreach base $args {
set base [file normalize $base]
set paths [::practcl::_pkgindex_path_subdir $base]
set i [string length $base]
# Build a list of all of the paths
foreach path $paths {
if {$path eq $base} continue
set path_indexed($path) 0
}
set path_indexed($base) 1
set path_indexed([file join $base boot tcl]) 1
#set path_index([file join $base boot tk]) 1
foreach path $paths {
if {$path_indexed($path)} continue
set thisdir [file_relative $base $path]
#set thisdir [string range $path $i+1 end]
set idxbuf [::practcl::_pkgindex_directory $path]
if {[string length $idxbuf]} {
incr path_indexed($path)
append buffer "set dir \[set PKGDIR \[file join \[lindex \$::PATHSTACK end\] $thisdir\]\]" \n
append buffer [string map {$dir $PKGDIR} [string trimright $idxbuf]] \n
}
}
}
append buffer {
set dir [lindex $::PATHSTACK end]
set ::PATHSTACK [lrange $::PATHSTACK 0 end-1]
}
return $buffer
}
###
# topic: 64319f4600fb63c82b2258d908f9d066
# description: Script to build the VFS file system
###
proc ::practcl::installDir {d1 d2} {
puts [format {%*sCreating %s} [expr {4 * [info level]}] {} [file tail $d2]]
file delete -force -- $d2
file mkdir $d2
foreach ftail [glob -directory $d1 -nocomplain -tails *] {
set f [file join $d1 $ftail]
if {[file isdirectory $f] && [string compare CVS $ftail]} {
installDir $f [file join $d2 $ftail]
} elseif {[file isfile $f]} {
file copy -force $f [file join $d2 $ftail]
if {$::tcl_platform(platform) eq {unix}} {
file attributes [file join $d2 $ftail] -permissions 0644
} else {
file attributes [file join $d2 $ftail] -readonly 1
}
}
}
if {$::tcl_platform(platform) eq {unix}} {
file attributes $d2 -permissions 0755
} else {
file attributes $d2 -readonly 1
}
}
proc ::practcl::copyDir {d1 d2} {
#puts [list $d1 -> $d2]
#file delete -force -- $d2
file mkdir $d2
foreach ftail [glob -directory $d1 -nocomplain -tails *] {
set f [file join $d1 $ftail]
if {[file isdirectory $f] && [string compare CVS $ftail]} {
copyDir $f [file join $d2 $ftail]
} elseif {[file isfile $f]} {
file copy -force $f [file join $d2 $ftail]
}
}
}
::oo::class create ::practcl::metaclass {
superclass ::oo::object
method script script {
eval $script
}
method source filename {
source $filename
}
method initialize {} {}
method define {submethod args} {
my variable define
switch $submethod {
dump {
return [array get define]
}
add {
set field [lindex $args 0]
if {![info exists define($field)]} {
set define($field) {}
}
foreach arg [lrange $args 1 end] {
if {$arg ni $define($field)} {
lappend define($field) $arg
}
}
return $define($field)
}
remove {
set field [lindex $args 0]
if {![info exists define($field)]} {
return
}
set rlist [lrange $args 1 end]
set olist $define($field)
set nlist {}
foreach arg $olist {
if {$arg in $rlist} continue
lappend nlist $arg
}
set define($field) $nlist
return $nlist
}
exists {
set field [lindex $args 0]
return [info exists define($field)]
}
getnull -
get -
cget {
set field [lindex $args 0]
if {[info exists define($field)]} {
return $define($field)
}
return [lindex $args 1]
}
set {
if {[llength $args]==1} {
set arglist [lindex $args 0]
} else {
set arglist $args
}
array set define $arglist
if {[dict exists $arglist class]} {
my select
}
}
default {
array $submethod define {*}$args
}
}
}
method graft args {
my variable organs
if {[llength $args] == 1} {
error "Need two arguments"
}
set object {}
foreach {stub object} $args {
dict set organs $stub $object
oo::objdefine [self] forward <${stub}> $object
oo::objdefine [self] export <${stub}>
}
return $object
}
method organ {{stub all}} {
my variable organs
if {![info exists organs]} {
return {}
}
if { $stub eq "all" } {
return $organs
}
if {[dict exists $organs $stub]} {
return [dict get $organs $stub]
}
}
method link {command args} {
my variable links
switch $command {
object {
foreach obj $args {
foreach linktype [$obj linktype] {
my link add $linktype $obj
}
}
}
add {
###
# Add a link to an object that was externally created
###
if {[llength $args] ne 2} { error "Usage: link add LINKTYPE OBJECT"}
lassign $args linktype object
if {[info exists links($linktype)] && $object in $links($linktype)} {
return
}
lappend links($linktype) $object
}
remove {
set object [lindex $args 0]
if {[llength $args]==1} {
set ltype *
} else {
set ltype [lindex $args 1]
}
foreach {linktype elements} [array get links $ltype] {
if {$object in $elements} {
set nlist {}
foreach e $elements {
if { $object ne $e } { lappend nlist $e }
}
set links($linktype) $nlist
}
}
}
list {
if {[llength $args]==0} {
return [array get links]
}
if {[llength $args] != 1} { error "Usage: link list LINKTYPE"}
set linktype [lindex $args 0]
if {![info exists links($linktype)]} {
return {}
}
return $links($linktype)
}
dump {
return [array get links]
}
}
}
method select {} {
my variable define
set class {}
if {[info exists define(class)]} {
if {[info command $define(class)] ne {}} {
set class $define(class)
} elseif {[info command ::practcl::$define(class)] ne {}} {
set class ::practcl::$define(class)
} else {
switch $define(class) {
default {
set class ::practcl::object
}
}
}
}
if {$class ne {}} {
::oo::objdefine [self] class $class
}
if {[::info exists define(oodefine)]} {
::oo::objdefine [self] $define(oodefine)
unset define(oodefine)
}
}
}
proc ::practcl::trigger {args} {
foreach name $args {
if {[dict exists $::make_objects $name]} {
[dict get $::make_objects $name] triggers
}
}
}
proc ::practcl::depends {args} {
foreach name $args {
if {[dict exists $::make_objects $name]} {
[dict get $::make_objects $name] check
}
}
}
proc ::practcl::target {name info} {
set obj [::practcl::target_obj new $name $info]
dict set ::make_objects $name $obj
if {[dict exists $info aliases]} {
foreach item [dict get $info aliases] {
if {![dict exists $::make_objects $item]} {
dict set ::make_objects $item $obj
}
}
}
set ::make($name) 0
set ::trigger($name) 0
set filename [$obj define get filename]
if {$filename ne {}} {
set ::target($name) $filename
}
}
### Batch Tasks
namespace eval ::practcl::build {}
## method DEFS
# This method populates 4 variables:
# name - The name of the package
# version - The version of the package
# defs - C flags passed to the compiler
# includedir - A list of paths to feed to the compiler for finding headers
#
proc ::practcl::build::DEFS {PROJECT DEFS namevar versionvar defsvar} {
upvar 1 $namevar name $versionvar version NAME NAME $defsvar defs
set name [string tolower [${PROJECT} define get name [${PROJECT} define get pkg_name]]]
set NAME [string toupper $name]
set version [${PROJECT} define get version [${PROJECT} define get pkg_vers]]
if {$version eq {}} {
set version 0.1a
}
set defs {}
append defs " -DPACKAGE_NAME=\"${name}\" -DPACKAGE_VERSION=\"${version}\""
append defs " -DPACKAGE_TARNAME=\"${name}\" -DPACKAGE_STRING=\"${name}\x5c\x20${version}\""
set NAME [string toupper $name]
set idx 0
set count 0
while {$idx>=0} {
set ndx [string first " -D" $DEFS $idx+1]
set item [string range $DEFS $idx $ndx]
set item [string trim $item]
set item [string trimleft $item -D]
if {[string range $item 0 7] eq "PACKAGE_"} {
set idx $ndx
continue
}
set eqidx [string first = $item ]
if {$eqidx < 0} {
append defs { } $item
set idx $ndx
continue
}
set field [string range $item 0 [expr {$eqidx-1}]]
set value [string range $item [expr {$eqidx+1}] end]
set emap {}
lappend emap \x5c \x5c\x5c \x20 \x5c\x20 \x22 \x5c\x22 \x28 \x5c\x28 \x29 \x5c\x29
if {[string is integer -strict $value]} {
append defs " -D${field}=$value"
} else {
append defs " -D${field}=[string map $emap $value]"
}
set idx $ndx
}
return $defs
}
proc ::practcl::build::tclkit_main {PROJECT PKG_OBJS} {
###
# Build static package list
###
set statpkglist {}
dict set statpkglist Tk {autoload 0}
puts [list TCLKIT MAIN $PROJECT]
foreach {ofile info} [${PROJECT} compile-products] {
puts [list * PROD $ofile $info]
if {![dict exists $info object]} continue
set cobj [dict get $info object]
foreach {pkg info} [$cobj static-packages] {
dict set statpkglist $pkg $info
}
}
foreach cobj [list {*}${PKG_OBJS} $PROJECT] {
puts [list * PROG $cobj]
foreach {pkg info} [$cobj static-packages] {
puts [list * PKG $pkg $info]
dict set statpkglist $pkg $info
}
}
set result {}
$PROJECT include {<tcl.h>}
$PROJECT include {"tclInt.h"}
$PROJECT include {"tclFileSystem.h"}
$PROJECT include {<assert.h>}
$PROJECT include {<stdio.h>}
$PROJECT include {<stdlib.h>}
$PROJECT include {<string.h>}
$PROJECT include {<math.h>}
$PROJECT code header {
#ifndef MODULE_SCOPE
# define MODULE_SCOPE extern
#endif
/*
** Provide a dummy Tcl_InitStubs if we are using this as a static
** library.
*/
#ifndef USE_TCL_STUBS
# undef Tcl_InitStubs
# define Tcl_InitStubs(a,b,c) TCL_VERSION
#endif
#define STATIC_BUILD 1
#undef USE_TCL_STUBS
/* Make sure the stubbed variants of those are never used. */
#undef Tcl_ObjSetVar2
#undef Tcl_NewStringObj
#undef Tk_Init
#undef Tk_MainEx
#undef Tk_SafeInit
}
# Build an area of the file for #define directives and
# function declarations
set define {}
set mainhook [$PROJECT define get TCL_LOCAL_MAIN_HOOK Tclkit_MainHook]
set mainfunc [$PROJECT define get TCL_LOCAL_APPINIT Tclkit_AppInit]
set mainscript [$PROJECT define get main.tcl main.tcl]
set vfsroot [$PROJECT define get vfsroot zipfs:/app]
set vfs_main "${vfsroot}/${mainscript}"
set vfs_tcl_library "${vfsroot}/boot/tcl"
set vfs_tk_library "${vfsroot}/boot/tk"
set map {}
foreach var {
vfsroot mainhook mainfunc vfs_main vfs_tcl_library vfs_tk_library
} {
dict set map %${var}% [set $var]
}
set preinitscript {
set ::odie(boot_vfs) {%vfsroot%}
set ::SRCDIR {%vfsroot%}
if {[file exists {%vfs_tcl_library%}]} {
set ::tcl_library {%vfs_tcl_library%}
set ::auto_path {}
}
if {[file exists {%vfs_tk_library%}]} {
set ::tk_library {%vfs_tk_library%}
}
} ; # Preinitscript
set zvfsboot {
/*
* %mainhook% --
* Performs the argument munging for the shell
*/
}
::practcl::cputs zvfsboot {
CONST char *archive;
Tcl_FindExecutable(*argv[0]);
archive=Tcl_GetNameOfExecutable();
Tclzipfs_Init(NULL);
}
# We have to initialize the virtual filesystem before calling
# Tcl_Init(). Otherwise, Tcl_Init() will not be able to find
# its startup script files.
$PROJECT include {"tclZipfs.h"}
::practcl::cputs zvfsboot " if(!TclZipfsMount(NULL, archive, \"%vfsroot%\", NULL)) \x7B "
::practcl::cputs zvfsboot {
Tcl_Obj *vfsinitscript;
vfsinitscript=Tcl_NewStringObj("%vfs_main%",-1);
Tcl_IncrRefCount(vfsinitscript);
if(Tcl_FSAccess(vfsinitscript,F_OK)==0) {
/* Startup script should be set before calling Tcl_AppInit */
Tcl_SetStartupScript(vfsinitscript,NULL);
}
}
::practcl::cputs zvfsboot " TclSetPreInitScript([::practcl::tcl_to_c $preinitscript])\;"
::practcl::cputs zvfsboot " \x7D else \x7B"
::practcl::cputs zvfsboot " TclSetPreInitScript([::practcl::tcl_to_c {
foreach path {
../tcl
} {
set p [file join $path library init.tcl]
if {[file exists [file join $path library init.tcl]]} {
set ::tcl_library [file normalize [file join $path library]]
break
}
}
foreach path {
../tk
} {
if {[file exists [file join $path library tk.tcl]]} {
set ::tk_library [file normalize [file join $path library]]
break
}
}
}])\;"
::practcl::cputs zvfsboot " \x7D"
::practcl::cputs zvfsboot " return TCL_OK;"
if {[$PROJECT define get os] eq "windows"} {
set header {int %mainhook%(int *argc, TCHAR ***argv)}
} else {
set header {int %mainhook%(int *argc, char ***argv)}
}
$PROJECT c_function [string map $map $header] [string map $map $zvfsboot]
practcl::cputs appinit "int %mainfunc%(Tcl_Interp *interp) \x7B"
# Build AppInit()
set appinit {}
practcl::cputs appinit {
if ((Tcl_Init)(interp) == TCL_ERROR) {
return TCL_ERROR;
}
}
set main_init_script {}
foreach {statpkg info} $statpkglist {
set initfunc {}
if {[dict exists $info initfunc]} {
set initfunc [dict get $info initfunc]
}
if {$initfunc eq {}} {
set initfunc [string totitle ${statpkg}]_Init
}
# We employ a NULL to prevent the package system from thinking the
# package is actually loaded into the interpreter
$PROJECT code header "extern Tcl_PackageInitProc $initfunc\;\n"
set script [list package ifneeded $statpkg [dict get $info version] [list ::load {} $statpkg]]
append main_init_script \n [list set ::kitpkg(${statpkg}) $script]
if {[dict get $info autoload]} {
::practcl::cputs appinit " if(${initfunc}(interp)) return TCL_ERROR\;"
::practcl::cputs appinit " Tcl_StaticPackage(interp,\"$statpkg\",$initfunc,NULL)\;"
} else {
::practcl::cputs appinit "\n Tcl_StaticPackage(NULL,\"$statpkg\",$initfunc,NULL)\;"
append main_init_script \n $script
}
}
append main_init_script \n {
if {[file exists [file join $::SRCDIR packages.tcl]]} {
#In a wrapped exe, we don't go out to the environment
set dir $::SRCDIR
source [file join $::SRCDIR packages.tcl]
}
# Specify a user-specific startup file to invoke if the application
# is run interactively. Typically the startup file is "~/.apprc"
# where "app" is the name of the application. If this line is deleted
# then no user-specific startup file will be run under any conditions.
}
append main_init_script \n [list set tcl_rcFileName [$PROJECT define get tcl_rcFileName ~/.tclshrc]]
practcl::cputs appinit " Tcl_Eval(interp,[::practcl::tcl_to_c $main_init_script]);"
practcl::cputs appinit { return TCL_OK;}
$PROJECT c_function [string map $map "int %mainfunc%(Tcl_Interp *interp)"] [string map $map $appinit]
}
proc ::practcl::build::compile-sources {PROJECT COMPILE {CPPCOMPILE {}}} {
set EXTERN_OBJS {}
set OBJECTS {}
set result {}
set builddir [$PROJECT define get builddir]
file mkdir [file join $builddir objs]
set debug [$PROJECT define get debug 0]
if {$CPPCOMPILE eq {}} {
set CPPCOMPILE $COMPILE
}
set task [${PROJECT} compile-products]
###
# Compile the C sources
###
foreach {ofile info} $task {
dict set task $ofile done 0
if {[dict exists $info external] && [dict get $info external]==1} {
dict set task $ofile external 1
} else {
dict set task $ofile external 0
}
if {[dict exists $info library]} {
dict set task $ofile done 1
continue
}
# Products with no cfile aren't compiled
if {![dict exists $info cfile] || [set cfile [dict get $info cfile]] eq {}} {
dict set task $ofile done 1
continue
}
set cfile [dict get $info cfile]
set ofilename [file join $builddir objs [file tail $ofile]]
if {$debug} {
set ofilename [file join $builddir objs [file rootname [file tail $ofile]].debug.o]
}
dict set task $ofile filename $ofilename
if {[file exists $ofilename] && [file mtime $ofilename]>[file mtime $cfile]} {
lappend result $ofilename
dict set task $ofile done 1
continue
}
if {![dict exist $info command]} {
if {[file extension $cfile] in {.c++ .cpp}} {
set cmd $CPPCOMPILE
} else {
set cmd $COMPILE
}
if {[dict exists $info extra]} {
append cmd " [dict get $info extra]"
}
append cmd " -c $cfile"
append cmd " -o $ofilename"
dict set task $ofile command $cmd
}
}
set completed 0
while {$completed==0} {
set completed 1
foreach {ofile info} $task {
set waiting {}
if {[dict exists $info done] && [dict get $info done]} continue
if {[dict exists $info depend]} {
foreach file [dict get $info depend] {
if {[dict exists $task $file command] && [dict exists $task $file done] && [dict get $task $file done] != 1} {
set waiting $file
break
}
}
}
if {$waiting ne {}} {
set completed 0
puts "$ofile waiting for $waiting"
continue
}
if {[dict exists $info command]} {
set cmd [dict get $info command]
puts "$cmd"
exec {*}$cmd >&@ stdout
}
lappend result [dict get $info filename]
dict set task $ofile done 1
}
}
return $result
}
proc ::practcl::de_shell {data} {
set values {}
foreach flag {DEFS TCL_DEFS TK_DEFS} {
if {[dict exists $data $flag]} {
set value {}
foreach item [dict get $data $flag] {
append value " " [string map {{ } {\ }} $item]
}
dict set values $flag $value
}
}
set map {}
lappend map {${PKG_OBJECTS}} %LIBRARY_OBJECTS%
lappend map {$(PKG_OBJECTS)} %LIBRARY_OBJECTS%
lappend map {${PKG_STUB_OBJECTS}} %LIBRARY_STUB_OBJECTS%
lappend map {$(PKG_STUB_OBJECTS)} %LIBRARY_STUB_OBJECTS%
lappend map %LIBRARY_NAME% [dict get $data name]
lappend map %LIBRARY_VERSION% [dict get $data version]
lappend map %LIBRARY_VERSION_NODOTS% [string map {. {}} [dict get $data version]]
if {[dict exists $data libprefix]} {
lappend map %LIBRARY_PREFIX% [dict get $data libprefix]
} else {
lappend map %LIBRARY_PREFIX% [dict get $data prefix]
}
foreach flag [dict keys $data] {
if {$flag in {TCL_DEFS TK_DEFS DEFS}} continue
dict set map "%${flag}%" [dict get $data $flag]
dict set map "\$\{${flag}\}" [dict get $data $flag]
dict set map "\$\(${flag}\)" [dict get $data $flag]
dict set values $flag [dict get $data $flag]
#dict set map "\$\{${flag}\}" $proj($flag)
}
set changed 1
while {$changed} {
set changed 0
foreach {field value} $values {
if {$field in {TCL_DEFS TK_DEFS DEFS}} continue
dict with values {}
set newval [string map $map $value]
if {$newval eq $value} continue
set changed 1
dict set values $field $newval
}
}
return $values
}
proc ::practcl::build::Makefile {path PROJECT} {
array set proj [$PROJECT define dump]
set path $proj(builddir)
cd $path
set includedir .
#lappend includedir [::practcl::file_relative $path $proj(TCL_INCLUDES)]
lappend includedir [::practcl::file_relative $path [file normalize [file join $proj(TCL_SRC_DIR) generic]]]
lappend includedir [::practcl::file_relative $path [file normalize [file join $proj(srcdir) generic]]]
foreach include [$PROJECT generate-include-directory] {
set cpath [::practcl::file_relative $path [file normalize $include]]
if {$cpath ni $includedir} {
lappend includedir $cpath
}
}
set INCLUDES "-I[join $includedir " -I"]"
set NAME [string toupper $proj(name)]
set result {}
set products {}
set libraries {}
set thisline {}
::practcl::cputs result "${NAME}_DEFS = $proj(DEFS)\n"
::practcl::cputs result "${NAME}_INCLUDES = -I\"[join $includedir "\" -I\""]\"\n"
::practcl::cputs result "${NAME}_COMPILE = \$(CC) \$(CFLAGS) \$(PKG_CFLAGS) \$(${NAME}_DEFS) \$(${NAME}_INCLUDES) \$(INCLUDES) \$(AM_CPPFLAGS) \$(CPPFLAGS) \$(AM_CFLAGS)"
::practcl::cputs result "${NAME}_CPPCOMPILE = \$(CXX) \$(CFLAGS) \$(PKG_CFLAGS) \$(${NAME}_DEFS) \$(${NAME}_INCLUDES) \$(INCLUDES) \$(AM_CPPFLAGS) \$(CPPFLAGS) \$(AM_CFLAGS)"
foreach {ofile info} [$PROJECT compile-products] {
dict set products $ofile $info
if {[dict exists $info library]} {
lappend libraries $ofile
continue
}
if {[dict exists $info depend]} {
::practcl::cputs result "\n${ofile}: [dict get $info depend]"
} else {
::practcl::cputs result "\n${ofile}:"
}
set cfile [dict get $info cfile]
if {[file extension $cfile] in {.c++ .cpp}} {
set cmd "\t\$\(${NAME}_CPPCOMPILE\)"
} else {
set cmd "\t\$\(${NAME}_COMPILE\)"
}
if {[dict exists $info extra]} {
append cmd " [dict get $info extra]"
}
append cmd " -c [dict get $info cfile] -o \$@\n\t"
::practcl::cputs result $cmd
}
set map {}
lappend map %LIBRARY_NAME% $proj(name)
lappend map %LIBRARY_VERSION% $proj(version)
lappend map %LIBRARY_VERSION_NODOTS% [string map {. {}} $proj(version)]
lappend map %LIBRARY_PREFIX% [$PROJECT define getnull libprefix]
if {[string is true [$PROJECT define get SHARED_BUILD]]} {
set outfile [$PROJECT define get libfile]
} else {
set outfile [$PROJECT shared_library]
}
$PROJECT define set shared_library $outfile
::practcl::cputs result "
${NAME}_SHLIB = $outfile
${NAME}_OBJS = [dict keys $products]
"
#lappend map %OUTFILE% {\[$]@}
lappend map %OUTFILE% $outfile
lappend map %LIBRARY_OBJECTS% "\$(${NAME}_OBJS)"
::practcl::cputs result "$outfile: \$(${NAME}_OBJS)"
::practcl::cputs result "\t[string map $map [$PROJECT define get PRACTCL_SHARED_LIB]]"
if {[$PROJECT define get PRACTCL_VC_MANIFEST_EMBED_DLL] ni {: {}}} {
::practcl::cputs result "\t[string map $map [$PROJECT define get PRACTCL_VC_MANIFEST_EMBED_DLL]]"
}
::practcl::cputs result {}
if {[string is true [$PROJECT define get SHARED_BUILD]]} {
#set outfile [$PROJECT static_library]
set outfile $proj(name).a
} else {
set outfile [$PROJECT define get libfile]
}
$PROJECT define set static_library $outfile
dict set map %OUTFILE% $outfile
::practcl::cputs result "$outfile: \$(${NAME}_OBJS)"
::practcl::cputs result "\t[string map $map [$PROJECT define get PRACTCL_STATIC_LIB]]"
::practcl::cputs result {}
return $result
}
###
# Produce a dynamic library
###
proc ::practcl::build::library {outfile PROJECT} {
array set proj [$PROJECT define dump]
set path $proj(builddir)
cd $path
set includedir .
#lappend includedir [::practcl::file_relative $path $proj(TCL_INCLUDES)]
lappend includedir [::practcl::file_relative $path [file normalize [file join $proj(TCL_SRC_DIR) generic]]]
lappend includedir [::practcl::file_relative $path [file normalize [file join $proj(srcdir) generic]]]
if {[$PROJECT define get tk 0]} {
lappend includedir [::practcl::file_relative $path [file normalize [file join $proj(TK_SRC_DIR) generic]]]
lappend includedir [::practcl::file_relative $path [file normalize [file join $proj(TK_SRC_DIR) ttk]]]
lappend includedir [::practcl::file_relative $path [file normalize [file join $proj(TK_SRC_DIR) xlib]]]
lappend includedir [::practcl::file_relative $path [file normalize $proj(TK_BIN_DIR)]]
}
foreach include [$PROJECT generate-include-directory] {
set cpath [::practcl::file_relative $path [file normalize $include]]
if {$cpath ni $includedir} {
lappend includedir $cpath
}
}
::practcl::build::DEFS $PROJECT $proj(DEFS) name version defs
set NAME [string toupper $name]
set debug [$PROJECT define get debug 0]
set os [$PROJECT define get os]
set INCLUDES "-I[join $includedir " -I"]"
if {$debug} {
set COMPILE "$proj(CC) $proj(CFLAGS_DEBUG) -ggdb \
$proj(CFLAGS_WARNING) $INCLUDES $defs"
if {[info exists proc(CXX)]} {
set COMPILECPP "$proj(CXX) $defs $INCLUDES $proj(CFLAGS_DEBUG) -ggdb \
$proj(DEFS) $proj(CFLAGS_WARNING)"
} else {
set COMPILECPP $COMPILE
}
} else {
set COMPILE "$proj(CC) $proj(CFLAGS) $defs $INCLUDES "
if {[info exists proc(CXX)]} {
set COMPILECPP "$proj(CXX) $defs $INCLUDES $proj(CFLAGS) $proj(DEFS)"
} else {
set COMPILECPP $COMPILE
}
}
set products [compile-sources $PROJECT $COMPILE $COMPILECPP]
set map {}
lappend map %LIBRARY_NAME% $proj(name)
lappend map %LIBRARY_VERSION% $proj(version)
lappend map %LIBRARY_VERSION_NODOTS% [string map {. {}} $proj(version)]
lappend map %OUTFILE% $outfile
lappend map %LIBRARY_OBJECTS% $products
lappend map {${CFLAGS}} "$proj(CFLAGS_DEFAULT) $proj(CFLAGS_WARNING)"
if {[string is true [$PROJECT define get SHARED_BUILD 1]]} {
set cmd [$PROJECT define get PRACTCL_SHARED_LIB]
append cmd " [$PROJECT define get PRACTCL_LIBS]"
set cmd [string map $map $cmd]
puts $cmd
exec {*}$cmd >&@ stdout
if {[$PROJECT define get PRACTCL_VC_MANIFEST_EMBED_DLL] ni {: {}}} {
set cmd [string map $map [$PROJECT define get PRACTCL_VC_MANIFEST_EMBED_DLL]]
puts $cmd
exec {*}$cmd >&@ stdout
}
} else {
set cmd [string map $map [$PROJECT define get PRACTCL_STATIC_LIB]]
puts $cmd
exec {*}$cmd >&@ stdout
}
}
###
# Produce a static executable
###
proc ::practcl::build::static-tclsh {outfile PROJECT} {
puts " BUILDING STATIC TCLSH "
set TCLOBJ [$PROJECT project TCLCORE]
set TKOBJ [$PROJECT project TKCORE]
set ODIEOBJ [$PROJECT project odie]
set PKG_OBJS {}
foreach item [$PROJECT link list package] {
if {[string is true [$item define get static]]} {
lappend PKG_OBJS $item
}
}
array set TCL [$TCLOBJ config.sh]
array set TK [$TKOBJ config.sh]
set path [file dirname $outfile]
cd $path
###
# For a static Tcl shell, we need to build all local sources
# with the same DEFS flags as the tcl core was compiled with.
# The DEFS produced by a TEA extension aren't intended to operate
# with the internals of a staticly linked Tcl
###
::practcl::build::DEFS $PROJECT $TCL(defs) name version defs
set debug [$PROJECT define get debug 0]
set NAME [string toupper $name]
set result {}
set libraries {}
set thisline {}
set OBJECTS {}
set EXTERN_OBJS {}
foreach obj $PKG_OBJS {
$obj compile
set config($obj) [$obj config.sh]
}
set os [$PROJECT define get os]
set TCLSRCDIR [$TCLOBJ define get srcroot]
set TKSRCDIR [$TKOBJ define get srcroot]
set includedir .
foreach include [$TCLOBJ generate-include-directory] {
set cpath [::practcl::file_relative $path [file normalize $include]]
if {$cpath ni $includedir} {
lappend includedir $cpath
}
}
lappend includedir [::practcl::file_relative $path [file normalize ../tcl/compat/zlib]]
foreach include [$PROJECT generate-include-directory] {
set cpath [::practcl::file_relative $path [file normalize $include]]
if {$cpath ni $includedir} {
lappend includedir $cpath
}
}
set INCLUDES "-I[join $includedir " -I"]"
if {$debug} {
set COMPILE "$TCL(cc) $TCL(shlib_cflags) $TCL(cflags_debug) -ggdb \
$TCL(cflags_warning) $TCL(extra_cflags) $INCLUDES"
} else {
set COMPILE "$TCL(cc) $TCL(shlib_cflags) $TCL(cflags_optimize) \
$TCL(cflags_warning) $TCL(extra_cflags) $INCLUDES"
}
append COMPILE " " $defs
lappend OBJECTS {*}[compile-sources $PROJECT $COMPILE $COMPILE]
if {[${PROJECT} define get platform] eq "windows"} {
set RSOBJ [file join $path build tclkit.res.o]
set RCSRC [${PROJECT} define get kit_resource_file]
if {$RCSRC eq {} || ![file exists $RCSRC]} {
set RCSRC [file join $TKSRCDIR win rc wish.rc]
}
set cmd [list windres -o $RSOBJ -DSTATIC_BUILD]
set TCLSRC [file normalize $TCLSRCDIR]
set TKSRC [file normalize $TKSRCDIR]
lappend cmd --include [::practcl::file_relative $path [file join $TCLSRC generic]] \
--include [::practcl::file_relative $path [file join $TKSRC generic]] \
--include [::practcl::file_relative $path [file join $TKSRC win]] \
--include [::practcl::file_relative $path [file join $TKSRC win rc]]
foreach item [${PROJECT} define get resource_include] {
lappend cmd --include [::practcl::file_relative $path [file normalize $item]]
}
lappend cmd $RCSRC
doexec {*}$cmd
lappend OBJECTS $RSOBJ
set LDFLAGS_CONSOLE {-mconsole -pipe -static-libgcc}
set LDFLAGS_WINDOW {-mwindows -pipe -static-libgcc}
} else {
set LDFLAGS_CONSOLE {}
set LDFLAGS_WINDOW {}
}
puts "***"
if {$debug} {
set cmd "$TCL(cc) $TCL(shlib_cflags) $TCL(cflags_debug) \
$TCL(cflags_warning) $TCL(extra_cflags) $INCLUDES"
} else {
set cmd "$TCL(cc) $TCL(shlib_cflags) $TCL(cflags_optimize) \
$TCL(cflags_warning) $TCL(extra_cflags) $INCLUDES"
}
append cmd " $OBJECTS"
append cmd " $EXTERN_OBJS "
# On OSX it is impossibly to generate a completely static
# executable
if {[$PROJECT define get TEACUP_OS] ne "macosx"} {
append cmd " -static "
}
parray TCL
if {$debug} {
if {$os eq "windows"} {
append cmd " -L${TCL(src_dir)}/win -ltcl86g"
append cmd " -L${TK(src_dir)}/win -ltk86g"
} else {
append cmd " -L${TCL(src_dir)}/unix -ltcl86g"
append cmd " -L${TK(src_dir)}/unix -ltk86g"
}
} else {
append cmd " $TCL(build_lib_spec) $TK(build_lib_spec)"
}
foreach obj $PKG_OBJS {
append cmd " [$obj linker-products $config($obj)]"
}
append cmd " $TCL(libs) $TK(libs)"
foreach obj $PKG_OBJS {
append cmd " [$obj linker-external $config($obj)]"
}
if {$debug} {
if {$os eq "windows"} {
append cmd " -L${TCL(src_dir)}/win ${TCL(stub_lib_flag)}"
append cmd " -L${TK(src_dir)}/win ${TK(stub_lib_flag)}"
} else {
append cmd " -L${TCL(src_dir)}/unix ${TCL(stub_lib_flag)}"
append cmd " -L${TK(src_dir)}/unix ${TK(stub_lib_flag)}"
}
} else {
append cmd " $TCL(build_stub_lib_spec)"
append cmd " $TK(build_stub_lib_spec)"
}
append cmd " -o $outfile $LDFLAGS_CONSOLE"
puts "LINK: $cmd"
exec {*}$cmd >&@ stdout
}
::oo::class create ::practcl::target_obj {
superclass ::practcl::metaclass
constructor {name info} {
my variable define triggered domake
set triggered 0
set domake 0
set define(name) $name
set data [uplevel 2 [list subst $info]]
array set define $data
my select
my initialize
}
method do {} {
my variable domake
return $domake
}
method check {} {
my variable needs_make domake
if {$domake} {
return 1
}
if {[info exists needs_make]} {
return $needs_make
}
set needs_make 0
foreach item [my define get depends] {
if {![dict exists $::make_objects $item]} continue
set depobj [dict get $::make_objects $item]
if {$depobj eq [self]} {
puts "WARNING [self] depends on itself"
continue
}
if {[$depobj check]} {
set needs_make 1
}
}
if {!$needs_make} {
set filename [my define get filename]
if {$filename ne {} && ![file exists $filename]} {
set needs_make 1
}
}
return $needs_make
}
method triggers {} {
my variable triggered domake define
if {$triggered} {
return $domake
}
set triggered 1
foreach item [my define get depends] {
puts [list $item [dict exists $::make_objects $item]]
if {![dict exists $::make_objects $item]} continue
set depobj [dict get $::make_objects $item]
if {$depobj eq [self]} {
puts "WARNING [self] triggers itself"
continue
} else {
set r [$depobj check]
puts [list $depobj check $r]
if {$r} {
puts [list $depobj TRIGGER]
$depobj triggers
}
}
}
if {[info exists ::make($define(name))] && $::make($define(name))} {
return
}
set ::make($define(name)) 1
::practcl::trigger {*}[my define get triggers]
}
}
###
# Define the metaclass
###
::oo::class create ::practcl::object {
superclass ::practcl::metaclass
constructor {parent args} {
my variable links define
set organs [$parent child organs]
my graft {*}$organs
array set define $organs
array set define [$parent child define]
array set links {}
if {[llength $args]==1 && [file exists [lindex $args 0]]} {
my InitializeSourceFile [lindex $args 0]
} elseif {[llength $args] == 1} {
set data [uplevel 1 [list subst [lindex $args 0]]]
array set define $data
my select
my initialize
} else {
array set define [uplevel 1 [list subst $args]]
my select
my initialize
}
}
method include_dir args {
my define add include_dir {*}$args
}
method include_directory args {
my define add include_dir {*}$args
}
method Collate_Source CWD {}
method child {method} {
return {}
}
method InitializeSourceFile filename {
my define set filename $filename
set class {}
switch [file extension $filename] {
.tcl {
set class ::practcl::dynamic
}
.h {
set class ::practcl::cheader
}
.c {
set class ::practcl::csource
}
.ini {
switch [file tail $filename] {
module.ini {
set class ::practcl::module
}
library.ini {
set class ::practcl::subproject
}
}
}
.so -
.dll -
.dylib -
.a {
set class ::practcl::clibrary
}
}
if {$class ne {}} {
oo::objdefine [self] class $class
my initialize
}
}
method add args {
my variable links
set object [::practcl::object new [self] {*}$args]
foreach linktype [$object linktype] {
lappend links($linktype) $object
}
return $object
}
method go {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable links
foreach {linktype objs} [array get links] {
foreach obj $objs {
$obj go
}
}
debug [list /[self] [self method] [self class]]
}
method code {section body} {
my variable code
::practcl::cputs code($section) $body
}
method Ofile filename {
set lpath [my <module> define get localpath]
if {$lpath eq {}} {
set lpath [my <module> define get name]
}
return ${lpath}_[file rootname [file tail $filename]].o
}
method compile-products {} {
set filename [my define get filename]
set result {}
if {$filename ne {}} {
if {[my define exists ofile]} {
set ofile [my define get ofile]
} else {
set ofile [my Ofile $filename]
my define set ofile $ofile
}
lappend result $ofile [list cfile $filename extra [my define get extra] external [string is true -strict [my define get external]] object [self]]
}
foreach item [my link list subordinate] {
lappend result {*}[$item compile-products]
}
return $result
}
method generate-include-directory {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set result [my define get include_dir]
foreach obj [my link list product] {
foreach path [$obj generate-include-directory] {
lappend result $path
}
}
return $result
}
method generate-debug {{spaces {}}} {
set result {}
::practcl::cputs result "$spaces[list [self] [list class [info object class [self]] filename [my define get filename]] links [my link list]]"
foreach item [my link list subordinate] {
practcl::cputs result [$item generate-debug "$spaces "]
}
return $result
}
# Empty template methods
method generate-cheader {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code cfunct cstruct methods tcltype tclprocs
set result {}
if {[info exists code(header)]} {
::practcl::cputs result $code(header)
}
foreach obj [my link list product] {
# Exclude products that will generate their own C files
if {[$obj define get output_c] ne {}} continue
::practcl::cputs result "/* BEGIN [$obj define get filename] generate-cheader */"
::practcl::cputs result [$obj generate-cheader]
::practcl::cputs result "/* END [$obj define get filename] generate-cheader */"
}
debug [list cfunct [info exists cfunct]]
if {[info exists cfunct]} {
foreach {funcname info} $cfunct {
if {[dict get $info public]} continue
::practcl::cputs result "[dict get $info header]\;"
}
}
debug [list tclprocs [info exists tclprocs]]
if {[info exists tclprocs]} {
foreach {name info} $tclprocs {
if {[dict exists $info header]} {
::practcl::cputs result "[dict get $info header]\;"
}
}
}
debug [list methods [info exists methods] [my define get cclass]]
if {[info exists methods]} {
set thisclass [my define get cclass]
foreach {name info} $methods {
if {[dict exists $info header]} {
::practcl::cputs result "[dict get $info header]\;"
}
}
# Add the initializer wrapper for the class
::practcl::cputs result "static int ${thisclass}_OO_Init(Tcl_Interp *interp)\;"
}
return $result
}
method generate-public-define {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code
set result {}
if {[info exists code(public-define)]} {
::practcl::cputs result $code(public-define)
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach mod [my link list product] {
::practcl::cputs result [$mod generate-public-define]
}
return $result
}
method generate-public-macro {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code
set result {}
if {[info exists code(public-macro)]} {
::practcl::cputs result $code(public-macro)
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach mod [my link list product] {
::practcl::cputs result [$mod generate-public-macro]
}
return $result
}
method generate-public-typedef {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code cstruct
set result {}
if {[info exists code(public-typedef)]} {
::practcl::cputs result $code(public-typedef)
}
if {[info exists cstruct]} {
# Add defintion for native c data structures
foreach {name info} $cstruct {
::practcl::cputs result "typedef struct $name ${name}\;"
if {[dict exists $info aliases]} {
foreach n [dict get $info aliases] {
::practcl::cputs result "typedef struct $name ${n}\;"
}
}
}
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach mod [my link list product] {
::practcl::cputs result [$mod generate-public-typedef]
}
return $result
}
method generate-public-structure {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code cstruct
set result {}
if {[info exists code(public-structure)]} {
::practcl::cputs result $code(public-structure)
}
if {[info exists cstruct]} {
foreach {name info} $cstruct {
if {[dict exists $info comment]} {
::practcl::cputs result [dict get $info comment]
}
::practcl::cputs result "struct $name \{[dict get $info body]\}\;"
}
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach mod [my link list product] {
::practcl::cputs result [$mod generate-public-structure]
}
return $result
}
method generate-public-headers {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code tcltype
set result {}
if {[info exists code(public-header)]} {
::practcl::cputs result $code(public-header)
}
if {[info exists tcltype]} {
foreach {type info} $tcltype {
if {![dict exists $info cname]} {
set cname [string tolower ${type}]_tclobjtype
dict set tcltype $type cname $cname
} else {
set cname [dict get $info cname]
}
::practcl::cputs result "extern const Tcl_ObjType $cname\;"
}
}
if {[info exists code(public)]} {
::practcl::cputs result $code(public)
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach mod [my link list product] {
::practcl::cputs result [$mod generate-public-headers]
}
return $result
}
method generate-stub-function {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code cfunct tcltype
set result {}
foreach mod [my link list product] {
foreach {funct def} [$mod generate-stub-function] {
dict set result $funct $def
}
}
if {[info exists cfunct]} {
foreach {funcname info} $cfunct {
if {![dict get $info export]} continue
dict set result $funcname [dict get $info header]
}
}
return $result
}
method generate-public-function {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code cfunct tcltype
set result {}
if {[my define get initfunc] ne {}} {
::practcl::cputs result "int [my define get initfunc](Tcl_Interp *interp);"
}
if {[info exists cfunct]} {
foreach {funcname info} $cfunct {
if {![dict get $info public]} continue
::practcl::cputs result "[dict get $info header]\;"
}
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach mod [my link list product] {
::practcl::cputs result [$mod generate-public-function]
}
return $result
}
method generate-public-includes {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set includes {}
foreach item [my define get public-include] {
if {$item ni $includes} {
lappend includes $item
}
}
foreach mod [my link list product] {
foreach item [$mod generate-public-includes] {
if {$item ni $includes} {
lappend includes $item
}
}
}
return $includes
}
method generate-public-verbatim {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set includes {}
foreach item [my define get public-verbatim] {
if {$item ni $includes} {
lappend includes $item
}
}
foreach mod [my link list subordinate] {
foreach item [$mod generate-public-verbatim] {
if {$item ni $includes} {
lappend includes $item
}
}
}
return $includes
}
###
# This methods generates the contents of an amalgamated .h file
# which describes the public API of this module
###
method generate-h {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set result {}
set includes [my generate-public-includes]
foreach inc $includes {
if {[string index $inc 0] ni {< \"}} {
::practcl::cputs result "#include \"$inc\""
} else {
::practcl::cputs result "#include $inc"
}
}
foreach file [my generate-public-verbatim] {
::practcl::cputs result "/* BEGIN $file */"
::practcl::cputs result [::practcl::cat $file]
::practcl::cputs result "/* END $file */"
}
foreach method {
generate-public-define
generate-public-macro
generate-public-typedef
generate-public-structure
generate-public-headers
generate-public-function
} {
::practcl::cputs result "/* BEGIN SECTION $method */"
::practcl::cputs result [my $method]
::practcl::cputs result "/* END SECTION $method */"
}
return $result
}
###
# This methods generates the contents of an amalgamated .c file
# which implements the loader for a batch of tools
###
method generate-c {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set result {
/* This file was generated by practcl */
}
set includes {}
lappend headers <tcl.h> <tclOO.h>
if {[my define get tk 0]} {
lappend headers <tk.h>
}
lappend headers {*}[my define get include]
if {[my define get output_h] ne {}} {
lappend headers "\"[my define get output_h]\""
}
foreach mod [my link list product] {
# Signal modules to formulate final implementation
$mod go
}
foreach mod [my link list dynamic] {
foreach inc [$mod define get include] {
if {$inc ni $headers} {
lappend headers $inc
}
}
}
foreach inc $headers {
if {[string index $inc 0] ni {< \"}} {
::practcl::cputs result "#include \"$inc\""
} else {
::practcl::cputs result "#include $inc"
}
}
foreach {method} {
generate-cheader
generate-cstruct
generate-constant
generate-cfunct
generate-cmethod
} {
::practcl::cputs result "/* BEGIN $method [my define get filename] */"
::practcl::cputs result [my $method]
::practcl::cputs result "/* END $method [my define get filename] */"
}
debug [list /[self] [self method] [self class] -- [my define get filename] [info object class [self]]]
return $result
}
method generate-loader {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set result {}
if {[my define get initfunc] eq {}} return
::practcl::cputs result "
extern int DLLEXPORT [my define get initfunc]( Tcl_Interp *interp ) \{"
::practcl::cputs result {
/* Initialise the stubs tables. */
#ifdef USE_TCL_STUBS
if (Tcl_InitStubs(interp, "8.6", 0)==NULL) return TCL_ERROR;
if (TclOOInitializeStubs(interp, "1.0") == NULL) return TCL_ERROR;
}
if {[my define get tk 0]} {
::practcl::cputs result { if (Tk_InitStubs(interp, "8.6", 0)==NULL) return TCL_ERROR;}
}
::practcl::cputs result { #endif}
set TCLINIT [my generate-tcl]
::practcl::cputs result " if(Tcl_Eval(interp,[::practcl::tcl_to_c $TCLINIT])) return TCL_ERROR ;"
foreach item [my link list product] {
if {[$item define get output_c] ne {}} {
::practcl::cputs result [$item generate-cinit-external]
} else {
::practcl::cputs result [$item generate-cinit]
}
}
if {[my define exists pkg_name]} {
::practcl::cputs result " if (Tcl_PkgProvide(interp, \"[my define get pkg_name [my define get name]]\" , \"[my define get pkg_vers [my define get version]]\" )) return TCL_ERROR\;"
}
::practcl::cputs result " return TCL_OK\;\n\}\n"
return $result
}
###
# This methods generates any Tcl script file
# which is required to pre-initialize the C library
###
method generate-tcl {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set result {}
my variable code
if {[info exists code(tcl)]} {
::practcl::cputs result $code(tcl)
}
set result [::practcl::_tagblock $result tcl [my define get filename]]
foreach mod [my link list product] {
::practcl::cputs result [$mod generate-tcl]
}
return $result
}
method static-packages {} {
set result [my define get static_packages]
set statpkg [my define get static_pkg]
set initfunc [my define get initfunc]
if {$initfunc ne {}} {
set pkg_name [my define get pkg_name]
if {$pkg_name ne {}} {
dict set result $pkg_name initfunc $initfunc
dict set result $pkg_name version [my define get version [my define get pkg_vers]]
dict set result $pkg_name autoload [my define get autoload 0]
}
}
foreach item [my link list subordinate] {
foreach {pkg info} [$item static-packages] {
dict set result $pkg $info
}
}
return $result
}
method target {method args} {
switch $method {
is_unix { return [expr {$::tcl_platform(platform) eq "unix"}] }
}
}
}
::oo::class create ::practcl::product {
superclass ::practcl::object
method linktype {} {
return {subordinate product}
}
method include header {
my define add include $header
}
method cstructure {name definition {argdat {}}} {
my variable cstruct
dict set cstruct $name body $definition
foreach {f v} $argdat {
dict set cstruct $name $f $v
}
}
method generate-cinit {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code
set result {}
if {[info exists code(cinit)]} {
::practcl::cputs result $code(cinit)
}
if {[my define get initfunc] ne {}} {
::practcl::cputs result " if([my define get initfunc](interp)!=TCL_OK) return TCL_ERROR\;"
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach obj [my link list product] {
::practcl::cputs result [$obj generate-cinit]
}
return $result
}
}
###
# Dynamic blocks do not generate their own .c files,
# instead the contribute to the amalgamation
# of the main library file
###
::oo::class create ::practcl::dynamic {
superclass ::practcl::product
# Retrieve any additional source files required
method compile-products {} {
set filename [my define get output_c]
set result {}
if {$filename ne {}} {
if {[my define exists ofile]} {
set ofile [my define get ofile]
} else {
set ofile [my Ofile $filename]
my define set ofile $ofile
}
lappend result $ofile [list cfile $filename extra [my define get extra] external [string is true -strict [my define get external]]]
} else {
set filename [my define get cfile]
if {$filename ne {}} {
if {[my define exists ofile]} {
set ofile [my define get ofile]
} else {
set ofile [my Ofile $filename]
my define set ofile $ofile
}
lappend result $ofile [list cfile $filename extra [my define get extra] external [string is true -strict [my define get external]]]
}
}
foreach item [my link list subordinate] {
lappend result {*}[$item compile-products]
}
return $result
}
method implement path {
my go
my Collate_Source $path
if {[my define get output_c] eq {}} return
set filename [file join $path [my define get output_c]]
my define set cfile $filename
set fout [open $filename w]
puts $fout [my generate-c]
puts $fout "extern int DLLEXPORT [my define get initfunc]( Tcl_Interp *interp ) \x7B"
puts $fout [my generate-cinit]
if {[my define get pkg_name] ne {}} {
puts $fout " Tcl_PkgProvide(interp, \"[my define get pkg_name]\", \"[my define get pkg_vers]\");"
}
puts $fout " return TCL_OK\;"
puts $fout "\x7D"
close $fout
}
method initialize {} {
set filename [my define get filename]
if {$filename eq {}} {
return
}
if {[my define get name] eq {}} {
my define set name [file tail [file rootname $filename]]
}
if {[my define get localpath] eq {}} {
my define set localpath [my <module> define get localpath]_[my define get name]
}
::source $filename
}
method linktype {} {
return {subordinate product dynamic}
}
###
# Populate const static data structures
###
method generate-cstruct {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code cstruct methods tcltype
set result {}
if {[info exists code(struct)]} {
::practcl::cputs result $code(struct)
}
foreach obj [my link list dynamic] {
# Exclude products that will generate their own C files
if {[$obj define get output_c] ne {}} continue
::practcl::cputs result [$obj generate-cstruct]
}
return $result
}
method generate-constant {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set result {}
my variable code cstruct methods tcltype
if {[info exists code(constant)]} {
::practcl::cputs result "/* [my define get filename] CONSTANT */"
::practcl::cputs result $code(constant)
}
if {[info exists cstruct]} {
foreach {name info} $cstruct {
set map {}
lappend map @NAME@ $name
lappend map @MACRO@ GET[string toupper $name]
if {[dict exists $info deleteproc]} {
lappend map @DELETEPROC@ [dict get $info deleteproc]
} else {
lappend map @DELETEPROC@ NULL
}
if {[dict exists $info cloneproc]} {
lappend map @CLONEPROC@ [dict get $info cloneproc]
} else {
lappend map @CLONEPROC@ NULL
}
::practcl::cputs result [string map $map {
const static Tcl_ObjectMetadataType @NAME@DataType = {
TCL_OO_METADATA_VERSION_CURRENT,
"@NAME@",
@DELETEPROC@,
@CLONEPROC@
};
#define @MACRO@(OBJCONTEXT) (@NAME@ *) Tcl_ObjectGetMetadata(OBJCONTEXT,&@NAME@DataType)
}]
}
}
if {[info exists tcltype]} {
foreach {type info} $tcltype {
dict with info {}
::practcl::cputs result "const Tcl_ObjType $cname = \{\n .freeIntRepProc = &${freeproc},\n .dupIntRepProc = &${dupproc},\n .updateStringProc = &${updatestringproc},\n .setFromAnyProc = &${setfromanyproc}\n\}\;"
}
}
if {[info exists methods]} {
set mtypes {}
foreach {name info} $methods {
set callproc [dict get $info callproc]
set methodtype [dict get $info methodtype]
if {$methodtype in $mtypes} continue
lappend mtypes $methodtype
###
# Build the data struct for this method
###
::practcl::cputs result "const static Tcl_MethodType $methodtype = \{"
::practcl::cputs result " .version = TCL_OO_METADATA_VERSION_CURRENT,\n .name = \"$name\",\n .callProc = $callproc,"
if {[dict exists $info deleteproc]} {
set deleteproc [dict get $info deleteproc]
} else {
set deleteproc NULL
}
if {$deleteproc ni { {} NULL }} {
::practcl::cputs result " .deleteProc = $deleteproc,"
} else {
::practcl::cputs result " .deleteProc = NULL,"
}
if {[dict exists $info cloneproc]} {
set cloneproc [dict get $info cloneproc]
} else {
set cloneproc NULL
}
if {$cloneproc ni { {} NULL }} {
::practcl::cputs result " .cloneProc = $cloneproc\n\}\;"
} else {
::practcl::cputs result " .cloneProc = NULL\n\}\;"
}
dict set methods $name methodtype $methodtype
}
}
foreach obj [my link list dynamic] {
# Exclude products that will generate their own C files
if {[$obj define get output_c] ne {}} continue
::practcl::cputs result [$obj generate-constant]
}
return $result
}
###
# Generate code that provides subroutines called by
# Tcl API methods
###
method generate-cfunct {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code cfunct
set result {}
if {[info exists code(funct)]} {
::practcl::cputs result $code(funct)
}
if {[info exists cfunct]} {
foreach {funcname info} $cfunct {
::practcl::cputs result "[dict get $info header]\{[dict get $info body]\}\;"
}
}
foreach obj [my link list dynamic] {
# Exclude products that will generate their own C files
if {[$obj define get output_c] ne {}} {
continue
}
::practcl::cputs result [$obj generate-cfunct]
}
return $result
}
###
# Generate code that provides implements Tcl API
# calls
###
method generate-cmethod {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
my variable code methods tclprocs
set result {}
if {[info exists code(method)]} {
::practcl::cputs result $code(method)
}
if {[info exists tclprocs]} {
foreach {name info} $tclprocs {
if {![dict exists $info body]} continue
set callproc [dict get $info callproc]
set header [dict get $info header]
set body [dict get $info body]
::practcl::cputs result "${header} \{${body}\}"
}
}
if {[info exists methods]} {
set thisclass [my define get cclass]
foreach {name info} $methods {
if {![dict exists $info body]} continue
set callproc [dict get $info callproc]
set header [dict get $info header]
set body [dict get $info body]
::practcl::cputs result "${header} \{${body}\}"
}
# Build the OO_Init function
::practcl::cputs result "static int ${thisclass}_OO_Init(Tcl_Interp *interp) \{"
::practcl::cputs result [string map [list @CCLASS@ $thisclass @TCLCLASS@ [my define get class]] {
/*
** Build the "@TCLCLASS@" class
*/
Tcl_Obj* nameObj; /* Name of a class or method being looked up */
Tcl_Object curClassObject; /* Tcl_Object representing the current class */
Tcl_Class curClass; /* Tcl_Class representing the current class */
/*
* Find the "@TCLCLASS@" class, and attach an 'init' method to it.
*/
nameObj = Tcl_NewStringObj("@TCLCLASS@", -1);
Tcl_IncrRefCount(nameObj);
if ((curClassObject = Tcl_GetObjectFromObj(interp, nameObj)) == NULL) {
Tcl_DecrRefCount(nameObj);
return TCL_ERROR;
}
Tcl_DecrRefCount(nameObj);
curClass = Tcl_GetObjectAsClass(curClassObject);
}]
if {[dict exists $methods constructor]} {
set mtype [dict get $methods constructor methodtype]
::practcl::cputs result [string map [list @MTYPE@ $mtype] {
/* Attach the constructor to the class */
Tcl_ClassSetConstructor(interp, curClass, Tcl_NewMethod(interp, curClass, NULL, 1, &@MTYPE@, NULL));
}]
}
foreach {name info} $methods {
dict with info {}
if {$name in {constructor destructor}} continue
::practcl::cputs result [string map [list @NAME@ $name @MTYPE@ $methodtype] {
nameObj=Tcl_NewStringObj("@NAME@",-1);
Tcl_NewMethod(interp, curClass, nameObj, 1, &@MTYPE@, (ClientData) NULL);
Tcl_DecrRefCount(nameObj);
}]
if {[dict exists $info aliases]} {
foreach alias [dict get $info aliases] {
if {[dict exists $methods $alias]} continue
::practcl::cputs result [string map [list @NAME@ $alias @MTYPE@ $methodtype] {
nameObj=Tcl_NewStringObj("@NAME@",-1);
Tcl_NewMethod(interp, curClass, nameObj, 1, &@MTYPE@, (ClientData) NULL);
Tcl_DecrRefCount(nameObj);
}]
}
}
}
::practcl::cputs result " return TCL_OK\;\n\}\n"
}
foreach obj [my link list dynamic] {
# Exclude products that will generate their own C files
if {[$obj define get output_c] ne {}} continue
::practcl::cputs result [$obj generate-cmethod]
}
return $result
}
method generate-cinit-external {} {
if {[my define get initfunc] eq {}} {
return "/* [my define get filename] declared not initfunc */"
}
return " if([my define get initfunc](interp)) return TCL_ERROR\;"
}
###
# Generate code that runs when the package/module is
# initialized into the interpreter
###
method generate-cinit {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set result {}
my variable code methods tclprocs
if {[info exists code(nspace)]} {
::practcl::cputs result " \{\n Tcl_Namespace *modPtr;"
foreach nspace $code(nspace) {
::practcl::cputs result [string map [list @NSPACE@ $nspace] {
modPtr=Tcl_FindNamespace(interp,"@NSPACE@",NULL,TCL_NAMESPACE_ONLY);
if(!modPtr) {
modPtr = Tcl_CreateNamespace(interp, "@NSPACE@", NULL, NULL);
}
}]
}
::practcl::cputs result " \}"
}
if {[info exists code(tclinit)]} {
::practcl::cputs result $code(tclinit)
}
if {[info exists code(cinit)]} {
::practcl::cputs result $code(cinit)
}
if {[info exists code(initfuncts)]} {
foreach func $code(initfuncts) {
::practcl::cputs result " if (${func}(interp) != TCL_OK) return TCL_ERROR\;"
}
}
if {[info exists tclprocs]} {
foreach {name info} $tclprocs {
set map [list @NAME@ $name @CALLPROC@ [dict get $info callproc]]
::practcl::cputs result [string map $map { Tcl_CreateObjCommand(interp,"@NAME@",(Tcl_ObjCmdProc *)@CALLPROC@,NULL,NULL);}]
if {[dict exists $info aliases]} {
foreach alias [dict get $info aliases] {
set map [list @NAME@ $alias @CALLPROC@ [dict get $info callproc]]
::practcl::cputs result [string map $map { Tcl_CreateObjCommand(interp,"@NAME@",(Tcl_ObjCmdProc *)@CALLPROC@,NULL,NULL);}]
}
}
}
}
if {[info exists code(nspace)]} {
::practcl::cputs result " \{\n Tcl_Namespace *modPtr;"
foreach nspace $code(nspace) {
::practcl::cputs result [string map [list @NSPACE@ $nspace] {
modPtr=Tcl_FindNamespace(interp,"@NSPACE@",NULL,TCL_NAMESPACE_ONLY);
Tcl_CreateEnsemble(interp, modPtr->fullName, modPtr, TCL_ENSEMBLE_PREFIX);
Tcl_Export(interp, modPtr, "[a-z]*", 1);
}]
}
::practcl::cputs result " \}"
}
set result [::practcl::_tagblock $result c [my define get filename]]
foreach obj [my link list product] {
# Exclude products that will generate their own C files
if {[$obj define get output_c] ne {}} {
::practcl::cputs result [$obj generate-cinit-external]
} else {
::practcl::cputs result [$obj generate-cinit]
}
}
return $result
}
method c_header body {
my variable code
::practcl::cputs code(header) $body
}
method c_code body {
my variable code
::practcl::cputs code(funct) $body
}
method c_function {header body} {
my variable code cfunct
foreach regexp {
{(.*) ([a-zA-Z_][a-zA-Z0-9_]*) *\((.*)\)}
{(.*) (\x2a[a-zA-Z_][a-zA-Z0-9_]*) *\((.*)\)}
} {
if {[regexp $regexp $header all keywords funcname arglist]} {
dict set cfunct $funcname header $header
dict set cfunct $funcname body $body
dict set cfunct $funcname keywords $keywords
dict set cfunct $funcname arglist $arglist
dict set cfunct $funcname public [expr {"static" ni $keywords}]
dict set cfunct $funcname export [expr {"STUB_EXPORT" in $keywords}]
return
}
}
::practcl::cputs code(header) "$header\;"
# Could not parse that block as a function
# append it verbatim to our c_implementation
::practcl::cputs code(funct) "$header [list $body]"
}
method cmethod {name body {arginfo {}}} {
my variable methods code
foreach {f v} $arginfo {
dict set methods $name $f $v
}
dict set methods $name body "Tcl_Object thisObject = Tcl_ObjectContextObject(objectContext); /* The current connection object */
$body"
}
method c_tclproc_nspace nspace {
my variable code
if {![info exists code(nspace)]} {
set code(nspace) {}
}
if {$nspace ni $code(nspace)} {
lappend code(nspace) $nspace
}
}
method c_tclproc_raw {name body {arginfo {}}} {
my variable tclprocs code
foreach {f v} $arginfo {
dict set tclprocs $name $f $v
}
dict set tclprocs $name body $body
}
method go {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
next
my variable methods code cstruct tclprocs
if {[info exists methods]} {
debug [self] methods [my define get cclass]
set thisclass [my define get cclass]
foreach {name info} $methods {
# Provide a callproc
if {![dict exists $info callproc]} {
set callproc [string map {____ _ ___ _ __ _} [string map {{ } _ : _} OOMethod_${thisclass}_${name}]]
dict set methods $name callproc $callproc
} else {
set callproc [dict get $info callproc]
}
if {[dict exists $info body] && ![dict exists $info header]} {
dict set methods $name header "static int ${callproc}(ClientData clientData, Tcl_Interp *interp, Tcl_ObjectContext objectContext ,int objc ,Tcl_Obj *const *objv)"
}
if {![dict exists $info methodtype]} {
set methodtype [string map {{ } _ : _} MethodType_${thisclass}_${name}]
dict set methods $name methodtype $methodtype
}
}
if {![info exists code(initfuncts)] || "${thisclass}_OO_Init" ni $code(initfuncts)} {
lappend code(initfuncts) "${thisclass}_OO_Init"
}
}
set thisnspace [my define get nspace]
if {[info exists tclprocs]} {
debug [self] tclprocs [dict keys $tclprocs]
foreach {name info} $tclprocs {
if {![dict exists $info callproc]} {
set callproc [string map {____ _ ___ _ __ _} [string map {{ } _ : _} Tclcmd_${thisnspace}_${name}]]
dict set tclprocs $name callproc $callproc
} else {
set callproc [dict get $info callproc]
}
if {[dict exists $info body] && ![dict exists $info header]} {
dict set tclprocs $name header "static int ${callproc}(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv\[\])"
}
}
}
debug [list /[self] [self method] [self class]]
}
# Once an object marks itself as some
# flavor of dynamic, stop trying to morph
# it into something else
method select {} {}
method tcltype {name argdat} {
my variable tcltype
foreach {f v} $argdat {
dict set tcltype $name $f $v
}
if {![dict exists tcltype $name cname]} {
dict set tcltype $name cname [string tolower $name]_tclobjtype
}
lappend map @NAME@ $name
set info [dict get $tcltype $name]
foreach {f v} $info {
lappend map @[string toupper $f]@ $v
}
foreach {func fpat template} {
freeproc {@Name@Obj_freeIntRepProc} {void @FNAME@(Tcl_Obj *objPtr)}
dupproc {@Name@Obj_dupIntRepProc} {void @FNAME@(Tcl_Obj *srcPtr,Tcl_Obj *dupPtr)}
updatestringproc {@Name@Obj_updateStringRepProc} {void @FNAME@(Tcl_Obj *objPtr)}
setfromanyproc {@Name@Obj_setFromAnyProc} {int @FNAME@(Tcl_Interp *interp,Tcl_Obj *objPtr)}
} {
if {![dict exists $info $func]} {
error "$name does not define $func"
}
set body [dict get $info $func]
# We were given a function name to call
if {[llength $body] eq 1} continue
set fname [string map [list @Name@ [string totitle $name]] $fpat]
my c_function [string map [list @FNAME@ $fname] $template] [string map $map $body]
dict set tcltype $name $func $fname
}
}
}
::oo::class create ::practcl::cheader {
superclass ::practcl::product
method compile-products {} {}
method generate-cinit {} {}
}
::oo::class create ::practcl::csource {
superclass ::practcl::product
}
::oo::class create ::practcl::clibrary {
superclass ::practcl::product
method linker-products {configdict} {
return [my define get filename]
}
}
###
# In the end, all C code must be loaded into a module
# This will either be a dynamically loaded library implementing
# a tcl extension, or a compiled in segment of a custom shell/app
###
::oo::class create ::practcl::module {
superclass ::practcl::dynamic
method child which {
switch $which {
organs {
return [list project [my define get project] module [self]]
}
}
}
method initialize {} {
set filename [my define get filename]
if {$filename eq {}} {
return
}
if {[my define get name] eq {}} {
my define set name [file tail [file dirname $filename]]
}
if {[my define get localpath] eq {}} {
my define set localpath [my <project> define get name]_[my define get name]
}
debug [self] SOURCE $filename
my source $filename
}
method implement path {
my go
my Collate_Source $path
foreach item [my link list dynamic] {
if {[catch {$item implement $path} err]} {
puts "Skipped $item: $err"
}
}
foreach item [my link list module] {
if {[catch {$item implement $path} err]} {
puts "Skipped $item: $err"
}
}
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set filename [my define get output_c]
if {$filename eq {}} {
debug [list /[self] [self method] [self class]]
return
}
set cout [open [file join $path [file rootname $filename].c] w]
puts $cout [subst {/*
** This file is generated by the [info script] script
** any changes will be overwritten the next time it is run
*/}]
puts $cout [my generate-c]
puts $cout [my generate-loader]
close $cout
debug [list /[self] [self method] [self class]]
}
method linktype {} {
return {subordinate product dynamic module}
}
}
::oo::class create ::practcl::autoconf {
###
# find or fake a key/value list describing this project
###
method config.sh {} {
my variable conf_result
if {[info exists conf_result]} {
return $conf_result
}
set result {}
set name [my define get name]
set PWD $::CWD
set builddir [my define get builddir]
my unpack
set srcroot [my define get srcroot]
if {![file exists $builddir]} {
my Configure
}
set filename [file join $builddir config.tcl]
# Project uses the practcl template. Use the leavings from autoconf
if {[file exists $filename]} {
set dat [::practcl::config.tcl $builddir]
foreach {item value} [lsort -stride 2 -dictionary $dat] {
dict set result $item $value
}
set conf_result $result
return $result
}
set filename [file join $builddir ${name}Config.sh]
if {[file exists $filename]} {
set l [expr {[string length $name]+1}]
foreach {field dat} [::practcl::read_Config.sh $filename] {
set field [string tolower $field]
if {[string match ${name}_* $field]} {
set field [string range $field $l end]
}
dict set result $field $dat
}
set conf_result $result
return $result
}
###
# Oh man... we have to guess
###
set filename [file join $builddir Makefile]
if {![file exists $filename]} {
error "Could not locate any configuration data in $srcroot"
}
foreach {field dat} [::practcl::read_Makefile $filename] {
dict set result $field $dat
}
set conf_result $result
cd $PWD
return $result
}
}
::oo::class create ::practcl::project {
superclass ::practcl::module ::practcl::autoconf
constructor args {
my variable define
if {[llength $args] == 1} {
if {[catch {uplevel 1 [list subst [lindex $args 0]]} contents]} {
set contents [lindex $args 0]
}
} else {
if {[catch {uplevel 1 [list subst $args]} contents]} {
set contents $args
}
}
array set define $contents
my select
my initialize
}
method add_project {pkg info {oodefine {}}} {
set os [my define get os]
if {$os eq {}} {
set os [::practcl::os]
my define set os $os
}
set fossilinfo [list download [my define get download] tag trunk sandbox [my define get sandbox]]
if {[dict exists $info os] && ($os ni [dict get $info os])} return
# Select which tag to use here.
# For production builds: tag-release
if {[::info exists ::env(FOSSIL_MIRROR)]} {
dict set info localmirror $::env(FOSSIL_MIRROR)
}
set profile [my define get profile release]:
if {[dict exists $info profile $profile]} {
dict set info tag [dict get $info profile $profile]
}
set obj [namespace current]::PROJECT.$pkg
if {[info command $obj] eq {}} {
set obj [::practcl::subproject create $obj [self] [dict merge $fossilinfo [list name $pkg pkg_name $pkg static 0] $info]]
}
my link object $obj
oo::objdefine $obj $oodefine
$obj define set masterpath $::CWD
$obj go
return $obj
}
method child which {
switch $which {
organs {
# A library can be a project, it can be a module. Any
# subordinate modules will indicate their existance
return [list project [self] module [self]]
}
}
}
method linktype {} {
return project
}
# Exercise the methods of a sub-object
method project {pkg args} {
set obj [namespace current]::PROJECT.$pkg
if {[llength $args]==0} {
return $obj
}
tailcall ${obj} {*}$args
}
}
::oo::class create ::practcl::library {
superclass ::practcl::project
method compile-products {} {
set result {}
foreach item [my link list subordinate] {
lappend result {*}[$item compile-products]
}
set filename [my define get output_c]
if {$filename ne {}} {
set ofile [file rootname [file tail $filename]]_main.o
lappend result $ofile [list cfile $filename extra [my define get extra] external [string is true -strict [my define get external]]]
}
return $result
}
method generate-tcl-loader {} {
set result {}
set PKGINIT [my define get pkginit]
set PKG_NAME [my define get name [my define get pkg_name]]
set PKG_VERSION [my define get pkg_vers [my define get version]]
if {[string is true [my define get SHARED_BUILD 0]]} {
set LIBFILE [my define get libfile]
::practcl::cputs result [string map \
[list @LIBFILE@ $LIBFILE @PKGINIT@ $PKGINIT @PKG_NAME@ $PKG_NAME @PKG_VERSION@ $PKG_VERSION] {
# Shared Library Style
load [file join [file dirname [file join [pwd] [info script]]] @LIBFILE@] @PKGINIT@
package provide @PKG_NAME@ @PKG_VERSION@
}]
} else {
::practcl::cputs result [string map \
[list @PKGINIT@ $PKGINIT @PKG_NAME@ $PKG_NAME @PKG_VERSION@ $PKG_VERSION] {
# Tclkit Style
load {} @PKGINIT@
package provide @PKG_NAME@ @PKG_VERSION@
}]
}
return $result
}
method go {} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set name [my define getnull name]
if {$name eq {}} {
set name generic
my define name generic
}
if {[my define get tk] eq {@TEA_TK_EXTENSION@}} {
my define set tk 0
}
set output_c [my define getnull output_c]
if {$output_c eq {}} {
set output_c [file rootname $name].c
my define set output_c $output_c
}
set output_h [my define getnull output_h]
if {$output_h eq {}} {
set output_h [file rootname $output_c].h
my define set output_h $output_h
}
set output_tcl [my define getnull output_tcl]
#if {$output_tcl eq {}} {
# set output_tcl [file rootname $output_c].tcl
# my define set output_tcl $output_tcl
#}
#set output_mk [my define getnull output_mk]
#if {$output_mk eq {}} {
# set output_mk [file rootname $output_c].mk
# my define set output_mk $output_mk
#}
set initfunc [my define getnull initfunc]
if {$initfunc eq {}} {
set initfunc [string totitle $name]_Init
my define set initfunc $initfunc
}
set output_decls [my define getnull output_decls]
if {$output_decls eq {}} {
set output_decls [file rootname $output_c].decls
my define set output_decls $output_decls
}
my variable links
foreach {linktype objs} [array get links] {
foreach obj $objs {
$obj go
}
}
debug [list /[self] [self method] [self class] -- [my define get filename] [info object class [self]]]
}
method implement path {
my go
my Collate_Source $path
foreach item [my link list dynamic] {
if {[catch {$item implement $path} err]} {
puts "Skipped $item: $err"
}
}
foreach item [my link list module] {
if {[catch {$item implement $path} err]} {
puts "Skipped $item: $err"
}
}
set cout [open [file join $path [my define get output_c]] w]
puts $cout [subst {/*
** This file is generated by the [info script] script
** any changes will be overwritten the next time it is run
*/}]
puts $cout [my generate-c]
puts $cout [my generate-loader]
close $cout
set macro HAVE_[string toupper [file rootname [my define get output_h]]]_H
set hout [open [file join $path [my define get output_h]] w]
puts $hout [subst {/*
** This file is generated by the [info script] script
** any changes will be overwritten the next time it is run
*/}]
puts $hout "#ifndef ${macro}"
puts $hout "#define ${macro}"
puts $hout [my generate-h]
puts $hout "#endif"
close $hout
set output_tcl [my define get output_tcl]
if {$output_tcl ne {}} {
set tclout [open [file join $path [my define get output_tcl]] w]
puts $tclout "###
# This file is generated by the [info script] script
# any changes will be overwritten the next time it is run
###"
puts $tclout [my generate-tcl]
puts $tclout [my generate-tcl-loader]
close $tclout
}
}
method generate-decls {pkgname path} {
debug [list [self] [self method] [self class] -- [my define get filename] [info object class [self]]]
set outfile [file join $path/$pkgname.decls]
###
# Build the decls file
###
set fout [open $outfile w]
puts $fout [subst {###
# $outfile
#
# This file was generated by [info script]
###
library $pkgname
interface $pkgname
}]
###
# Generate list of functions
###
set stubfuncts [my generate-stub-function]
set thisline {}
set functcount 0
foreach {func header} $stubfuncts {
puts $fout [list declare [incr functcount] $header]
}
puts $fout [list export "int [my define get initfunc](Tcl_Inter *interp)"]
puts $fout [list export "char *[string totitle [my define get name]]_InitStubs(Tcl_Inter *interp, char *version, int exact)"]
close $fout
###
# Build [package]Decls.h
###
set hout [open [file join $path ${pkgname}Decls.h] w]
close $hout
set cout [open [file join $path ${pkgname}StubInit.c] w]
puts $cout [string map [list %pkgname% $pkgname %PkgName% [string totitle $pkgname]] {
#ifndef USE_TCL_STUBS
#define USE_TCL_STUBS
#endif
#undef USE_TCL_STUB_PROCS
#include "tcl.h"
#include "%pkgname%.h"
/*
** Ensure that Tdom_InitStubs is built as an exported symbol. The other stub
** functions should be built as non-exported symbols.
*/
#undef TCL_STORAGE_CLASS
#define TCL_STORAGE_CLASS DLLEXPORT
%PkgName%Stubs *%pkgname%StubsPtr;
/*
**----------------------------------------------------------------------
**
** %PkgName%_InitStubs --
**
** Checks that the correct version of %PkgName% is loaded and that it
** supports stubs. It then initialises the stub table pointers.
**
** Results:
** The actual version of %PkgName% that satisfies the request, or
** NULL to indicate that an error occurred.
**
** Side effects:
** Sets the stub table pointers.
**
**----------------------------------------------------------------------
*/
char *
%PkgName%_InitStubs (Tcl_Interp *interp, char *version, int exact)
{
char *actualVersion;
actualVersion = Tcl_PkgRequireEx(interp, "%pkgname%", version, exact,(ClientData *) &%pkgname%StubsPtr);
if (!actualVersion) {
return NULL;
}
if (!%pkgname%StubsPtr) {
Tcl_SetResult(interp,"This implementation of %PkgName% does not support stubs",TCL_STATIC);
return NULL;
}
return actualVersion;
}
}]
close $cout
}
# Backward compadible call
method generate-make path {
::practcl::build::Makefile $path [self]
}
method install-headers {} {
set result {}
return $result
}
method linktype {} {
return library
}
# Create a "package ifneeded"
# Args are a list of aliases for which this package will answer to
method package-ifneeded {args} {
set result {}
set name [my define get pkg_name [my define get name]]
set version [my define get pkg_vers [my define get version]]
if {$version eq {}} {
set version 0.1a
}
set output_tcl [my define get output_tcl]
if {$output_tcl ne {}} {
set script "\[list source \[file join \$dir $output_tcl\]\]"
} elseif {[string is true -strict [my define get SHARED_BUILD]]} {
set script "\[list load \[file join \$dir [my define get libfile]\] $name\]"
} else {
# Provide a null passthrough
set script [list package provide $name $version]
}
set result "package ifneeded [list $name] [list $version] $script"
foreach alias $args {
set script "package require $name $version \; package provide $alias $version"
append result \n\n [list package ifneeded $alias $version $script]
}
return $result
}
method shared_library {} {
set name [string tolower [my define get name [my define get pkg_name]]]
set NAME [string toupper $name]
set version [my define get version [my define get pkg_vers]]
set map {}
lappend map %LIBRARY_NAME% $name
lappend map %LIBRARY_VERSION% $version
lappend map %LIBRARY_VERSION_NODOTS% [string map {. {}} $version]
lappend map %LIBRARY_PREFIX% [my define getnull libprefix]
set outfile [string map $map [my define get PRACTCL_NAME_LIBRARY]][my define get SHLIB_SUFFIX]
return $outfile
}
}
::oo::class create ::practcl::tclkit {
superclass ::practcl::library
method Collate_Source CWD {
my define set SHARED_BUILD 0
set name [my define get name]
if {![my define exists TCL_LOCAL_APPINIT]} {
my define set TCL_LOCAL_APPINIT Tclkit_AppInit
}
if {![my define exists TCL_LOCAL_MAIN_HOOK]} {
my define set TCL_LOCAL_MAIN_HOOK Tclkit_MainHook
}
set PROJECT [self]
set os [$PROJECT define get os]
set TCLOBJ [$PROJECT project TCLCORE]
set TKOBJ [$PROJECT project TKCORE]
set ODIEOBJ [$PROJECT project odie]
set TCLSRCDIR [$TCLOBJ define get srcroot]
set TKSRCDIR [$TKOBJ define get srcroot]
set PKG_OBJS {}
foreach item [$PROJECT link list package] {
if {[string is true [$item define get static]]} {
lappend PKG_OBJS $item
}
}
# Arrange to build an main.c that utilizes TCL_LOCAL_APPINIT and TCL_LOCAL_MAIN_HOOK
if {$os eq "windows"} {
set PLATFORM_SRC_DIR win
my add class csource filename [file join $TCLSRCDIR win tclWinReg.c] initfunc Registry_Init pkg_name registry pkg_vers 1.3.1 autoload 1
my add class csource filename [file join $TCLSRCDIR win tclWinDde.c] initfunc Dde_Init pkg_name dde pkg_vers 1.4.0 autoload 1
my add class csource ofile [my define get name]_appinit.o filename [file join $TCLSRCDIR win tclAppInit.c] extra [list -DTCL_LOCAL_MAIN_HOOK=[my define get TCL_LOCAL_MAIN_HOOK Tclkit_MainHook] -DTCL_LOCAL_APPINIT=[my define get TCL_LOCAL_APPINIT Tclkit_AppInit]]
} else {
set PLATFORM_SRC_DIR unix
my add class csource ofile [my define get name]_appinit.o filename [file join $TCLSRCDIR unix tclAppInit.c] extra [list -DTCL_LOCAL_MAIN_HOOK=[my define get TCL_LOCAL_MAIN_HOOK Tclkit_MainHook] -DTCL_LOCAL_APPINIT=[my define get TCL_LOCAL_APPINIT Tclkit_AppInit]]
}
###
# Add local static Zlib implementation
###
set cdir [file join $TCLSRCDIR compat zlib]
foreach file {
adler32.c compress.c crc32.c
deflate.c infback.c inffast.c
inflate.c inftrees.c trees.c
uncompr.c zutil.c
} {
my add [file join $cdir $file]
}
###
# Pre 8.7, Tcl doesn't include a Zipfs implementation
# in the core. Grab the one from odielib
###
set zipfs [file join $TCLSRCDIR generic zvfs.c]
if {![file exists $zipfs]} {
# The Odie project maintains a mirror of the version
# released with the Tcl core
my add_project odie {
tag trunk
class subproject
vfsinstall 0
}
my project odie unpack
set ODIESRCROOT [my project odie define get srcroot]
set cdir [file join $ODIESRCROOT compat zipfs]
my define add include_dir $cdir
set zipfs [file join $cdir zvfs.c]
}
my add class csource filename $zipfs initfunc Tclzipfs_Init pkg_name zipfs pkg_vers 1.0 autoload 1
my define add include_dir [file join $TKSRCDIR generic]
my define add include_dir [file join $TKSRCDIR $PLATFORM_SRC_DIR]
my define add include_dir [file join $TKSRCDIR bitmaps]
my define add include_dir [file join $TKSRCDIR xlib]
my define add include_dir [file join $TCLSRCDIR generic]
my define add include_dir [file join $TCLSRCDIR $PLATFORM_SRC_DIR]
my define add include_dir [file join $TCLSRCDIR compat zlib]
# This file will implement TCL_LOCAL_APPINIT and TCL_LOCAL_MAIN_HOOK
::practcl::build::tclkit_main $PROJECT $PKG_OBJS
}
## Wrap an executable
#
method wrap {PWD exename vfspath args} {
cd $PWD
if {![file exists $vfspath]} {
file mkdir $vfspath
}
foreach item [my link list core.library] {
set name [$item define get name]
set libsrcroot [$item define get srcroot]
if {[file exists [file join $libsrcroot library]]} {
::practcl::copyDir [file join $libsrcroot library] [file join $vfspath boot $name]
}
}
if {[my define get installdir] ne {}} {
::practcl::copyDir [file join [my define get installdir] [string trimleft [my define get prefix] /] lib] [file join $vfspath lib]
}
foreach arg $args {
::practcl::copyDir $arg $vfspath
}
set fout [open [file join $vfspath packages.tcl] w]
puts $fout {
set ::PKGIDXFILE [info script]
set dir [file dirname $::PKGIDXFILE]
}
#set BASEVFS [my define get BASEVFS]
set EXEEXT [my define get EXEEXT]
set tclkit_bare [my define get tclkit_bare]
set buffer [::practcl::pkgindex_path $vfspath]
puts $fout $buffer
puts $fout {
# Advertise statically linked packages
foreach {pkg script} [array get ::kitpkg] {
eval $script
}
}
close $fout
package require zipfile::mkzip
::zipfile::mkzip::mkzip ${exename}${EXEEXT} -runtime $tclkit_bare -directory $vfspath
if { [my define get platform] ne "windows" } {
file attributes ${exename}${EXEEXT} -permissions a+x
}
}
}
###
# Meta repository
# The default is an inert source code block
###
oo::class create ::practcl::subproject {
superclass ::practcl::object
method compile {} {}
method go {} {
set platform [my <project> define get platform]
my define get USEMSVC [my <project> define get USEMSVC]
set name [my define get name]
if {![my define exists srcroot]} {
my define set srcroot [file join [my <project> define get sandbox] $name]
}
set srcroot [my define get srcroot]
my define set localsrcdir $srcroot
my define add include_dir [file join $srcroot generic]
my sources
}
# Install project into the local build system
method install-local {} {
my unpack
}
# Install project into the virtual file system
method install-vfs {} {}
method linktype {} {
return {subordinate package}
}
method linker-products {configdict} {}
method linker-external {configdict} {
if {[dict exists $configdict PRACTCL_LIBS]} {
return [dict get $configdict PRACTCL_LIBS]
}
}
method sources {} {}
method unpack {} {
set name [my define get name]
puts [list $name [self] UNPACK]
my define set [::practcl::fossil_sandbox $name [my define dump]]
}
method update {} {
set name [my define get name]
my define set [::practcl::fossil_sandbox $name [dict merge [my define dump] {update 1}]]
}
}
###
# A project which the kit compiles and integrates
# the source for itself
###
oo::class create ::practcl::subproject.source {
superclass ::practcl::subproject ::practcl::library
method linktype {} {
return {subordinate package source}
}
}
# a copy from the teapot
oo::class create ::practcl::subproject.teapot {
superclass ::practcl::subproject
method install-local {} {
my install-vfs
}
method install-vfs {} {
set pkg [my define get pkg_name [my define get name]]
set download [my <project> define get download]
my unpack
set DEST [my <project> define get installdir]
set prefix [string trimleft [my <project> define get prefix] /]
# Get tcllib from our destination
set dir [file join $DEST $prefix lib tcllib]
source [file join $DEST $prefix lib tcllib pkgIndex.tcl]
package require zipfile::decode
::zipfile::decode::unzipfile [file join $download $pkg.zip] [file join $DEST $prefix lib $pkg]
}
}
oo::class create ::practcl::subproject.sak {
superclass ::practcl::subproject
method install-local {} {
my install-vfs
}
method install-vfs {} {
###
# Handle teapot installs
###
set pkg [my define get pkg_name [my define get name]]
my unpack
set DEST [my <project> define get installdir]
set prefix [string trimleft [my <project> define get prefix] /]
set srcroot [my define get srcroot]
::dotclexec [file join $srcroot installer.tcl] \
-pkg-path [file join $DEST $prefix lib $pkg] \
-no-examples -no-html -no-nroff \
-no-wait -no-gui -no-apps
}
}
###
# A binary package
###
oo::class create ::practcl::subproject.binary {
superclass ::practcl::subproject ::practcl::autoconf
method compile-products {} {}
method ConfigureOpts {} {
set opts {}
set builddir [my define get builddir]
if {[my define get broken_destroot 0]} {
set PREFIX [my <project> define get prefix_broken_destdir]
} else {
set PREFIX [my <project> define get prefix]
}
if {[my <project> define get HOST] != [my <project> define get TARGET]} {
lappend opts --host=[my <project> define get TARGET]
}
if {[my <project> define exists tclsrcdir]} {
set TCLSRCDIR [::practcl::file_relative [file normalize $builddir] [file normalize [file join $::CWD [my <project> define get tclsrcdir]]]]
set TCLGENERIC [::practcl::file_relative [file normalize $builddir] [file normalize [file join $::CWD [my <project> define get tclsrcdir] .. generic]]]
lappend opts --with-tcl=$TCLSRCDIR --with-tclinclude=$TCLGENERIC
}
if {[my <project> define exists tksrcdir]} {
set TKSRCDIR [::practcl::file_relative [file normalize $builddir] [file normalize [file join $::CWD [my <project> define get tksrcdir]]]]
set TKGENERIC [::practcl::file_relative [file normalize $builddir] [file normalize [file join $::CWD [my <project> define get tksrcdir] .. generic]]]
lappend opts --with-tk=$TKSRCDIR --with-tkinclude=$TKGENERIC
}
lappend opts {*}[my define get config_opts]
lappend opts --prefix=$PREFIX
#--exec_prefix=$PREFIX
#if {$::tcl_platform(platform) eq "windows"} {
# lappend opts --disable-64bit
#}
if {[my define get static 1]} {
lappend opts --disable-shared --disable-stubs
#
} else {
lappend opts --enable-shared
}
return $opts
}
method go {} {
next
my define set builddir [my BuildDir [my define get masterpath]]
}
method linker-products {configdict} {
if {![my define get static 0]} {
return {}
}
set srcdir [my define get builddir]
if {[dict exists $configdict libfile]} {
return " [file join $srcdir [dict get $configdict libfile]]"
}
}
method static-packages {} {
if {![my define get static 0]} {
return {}
}
set result [my define get static_packages]
set statpkg [my define get static_pkg]
set initfunc [my define get initfunc]
if {$initfunc ne {}} {
set pkg_name [my define get pkg_name]
if {$pkg_name ne {}} {
dict set result $pkg_name initfunc $initfunc
set version [my define get version]
if {$version eq {}} {
set info [my config.sh]
set version [dict get $info version]
set pl {}
if {[dict exists $info patch_level]} {
set pl [dict get $info patch_level]
append version $pl
}
my define set version $version
}
dict set result $pkg_name version $version
dict set result $pkg_name autoload [my define get autoload 0]
}
}
foreach item [my link list subordinate] {
foreach {pkg info} [$item static-packages] {
dict set result $pkg $info
}
}
return $result
}
method BuildDir {PWD} {
set name [my define get name]
return [my define get builddir [file join $PWD pkg.$name]]
}
method compile {} {
set name [my define get name]
set PWD $::CWD
cd $PWD
my go
set srcroot [file normalize [my define get srcroot]]
my Collate_Source $PWD
###
# Build a starter VFS for both Tcl and wish
###
set srcroot [my define get srcroot]
if {[my define get static 1]} {
puts "BUILDING Static $name $srcroot"
} else {
puts "BUILDING Dynamic $name $srcroot"
}
if {[my define get USEMSVC 0]} {
cd $srcroot
doexec nmake -f makefile.vc INSTALLDIR=[my <project> define get installdir] release
} else {
cd $::CWD
set builddir [file normalize [my define get builddir]]
file mkdir $builddir
if {![file exists [file join $builddir Makefile]]} {
my Configure
}
if {[file exists [file join $builddir make.tcl]]} {
domake.tcl $builddir library
} else {
domake $builddir all
}
}
cd $PWD
}
method Configure {} {
cd $::CWD
my unpack
my TeaConfig
set builddir [file normalize [my define get builddir]]
file mkdir $builddir
set srcroot [file normalize [my define get srcroot]]
if {[my define get USEMSVC 0]} {
return
}
set opts [my ConfigureOpts]
puts [list [self] CONFIGURE]
puts [list PWD [pwd]]
puts [list LOCALSRC $srcroot]
puts [list BUILDDIR $builddir]
puts [list CONFIGURE {*}$opts]
cd $builddir
exec sh [file join $srcroot configure] {*}$opts >& [file join $builddir practcl.log]
cd $::CWD
}
method install-vfs {} {
set PWD [pwd]
set PKGROOT [my <project> define get installdir]
set PREFIX [my <project> define get prefix]
###
# Handle teapot installs
###
set pkg [my define get pkg_name [my define get name]]
if {[my <project> define get teapot] ne {}} {
set TEAPOT [my <project> define get teapot]
set found 0
foreach ver [my define get pkg_vers [my define get version]] {
set teapath [file join $TEAPOT $pkg$ver]
if {[file exists $teapath]} {
set dest [file join $PKGROOT [string trimleft $PREFIX /] lib [file tail $teapath]]
::practcl::copyDir $teapath $dest
return
}
}
}
my compile
if {[my define get USEMSVC 0]} {
set srcroot [my define get srcroot]
cd $srcroot
puts "[self] VFS INSTALL $PKGROOT"
doexec nmake -f makefile.vc INSTALLDIR=$PKGROOT install
} else {
set builddir [my define get builddir]
if {[file exists [file join $builddir make.tcl]]} {
# Practcl builds can inject right to where we need them
puts "[self] VFS INSTALL $PKGROOT (Practcl)"
domake.tcl $builddir install-package $PKGROOT
} elseif {[my define get broken_destroot 0] == 0} {
# Most modern TEA projects understand DESTROOT in the makefile
puts "[self] VFS INSTALL $PKGROOT (TEA)"
domake $builddir install DESTDIR=$PKGROOT
} else {
# But some require us to do an install into a fictitious filesystem
# and then extract the gooey parts within.
# (*cough*) TkImg
set PREFIX [my <project> define get prefix]
set BROKENROOT [::practcl::msys_to_tclpath [my <project> define get prefix_broken_destdir]]
file delete -force $BROKENROOT
file mkdir $BROKENROOT
domake $builddir $install
::practcl::copyDir $BROKENROOT [file join $PKGROOT [string trimleft $PREFIX /]]
file delete -force $BROKENROOT
}
}
cd $PWD
}
method TeaConfig {} {
set srcroot [file normalize [my define get srcroot]]
set copytea 0
if {![file exists [file join $srcroot tclconfig]]} {
set copytea 1
} else {
if {![file exists [file join $srcroot tclconfig practcl.tcl]] || ![file exists [file join $srcroot tclconfig config.tcl.in]]} {
set copytea 1
}
}
# ensure we have tclconfig with all of the trimming
if {$copytea} {
set tclconfiginfo [::practcl::fossil_sandbox tclconfig [list sandbox [my <project> define get sandbox]]]
::practcl::copyDir [dict get $tclconfiginfo srcroot] [file join $srcroot tclconfig]
if {$::tcl_platform(platform) ne "windows"} {
set pwd [pwd]
cd $srcroot
# On windows there's no practical way to execute
# autoconf. We'll have to trust that configure
# us up to date
foreach template {configure.ac configure.in} {
set input [file join $srcroot $template]
if {[file exists $input]} {
puts "autoconf -f $input > [file join $srcroot configure]"
exec autoconf -f $input > [file join $srcroot configure]
}
}
cd $pwd
}
}
}
}
oo::class create ::practcl::subproject.core {
superclass ::practcl::subproject.binary
# On the windows platform MinGW must build
# from the platform directory in the source repo
method BuildDir {PWD} {
return [my define get localsrcdir]
}
method Configure {} {
if {[my define get USEMSVC 0]} {
return
}
set opts [my ConfigureOpts]
puts [list PWD [pwd]]
puts [list [self] CONFIGURE]
set builddir [file normalize [my define get builddir]]
set localsrcdir [file normalize [my define get localsrcdir]]
puts [list LOCALSRC $localsrcdir]
puts [list BUILDDIR $builddir]
puts [list CONFIGURE {*}$opts]
cd $localsrcdir
exec sh [file join $localsrcdir configure] {*}$opts >& [file join $builddir practcl.log]
}
method ConfigureOpts {} {
set opts {}
set builddir [file normalize [my define get builddir]]
set PREFIX [my <project> define get prefix]
if {[my <project> define get HOST] != [my <project> define get TARGET]} {
lappend opts --host=[my <project> define get TARGET]
}
lappend opts {*}[my define get config_opts]
lappend opts --prefix=$PREFIX
#--exec_prefix=$PREFIX
lappend opts --disable-shared
return $opts
}
method go {} {
set name [my define get name]
set platform [my <project> define get platform]
if {![my define exists srcroot]} {
my define set srcroot [file join [my <project> define get sandbox] $name]
}
set srcroot [my define get srcroot]
my define add include_dir [file join $srcroot generic]
switch $platform {
windows {
my define set localsrcdir [file join $srcroot win]
my define add include_dir [file join $srcroot win]
}
default {
my define set localsrcdir [file join $srcroot unix]
my define add include_dir [file join $srcroot $name unix]
}
}
my define set builddir [my BuildDir [my define get masterpath]]
}
method linktype {} {
return {subordinate core.library}
}
}
package provide practcl 0.5
|
Changes to unix/Makefile.in.
| ︙ | ︙ | |||
304 305 306 307 308 309 310 | tclObj.o tclOptimize.o tclPanic.o tclParse.o tclPathObj.o tclPipe.o \ tclPkg.o tclPkgConfig.o tclPosixStr.o \ tclPreserve.o tclProc.o tclRegexp.o \ tclResolve.o tclResult.o tclScan.o tclStringObj.o \ tclStrToD.o tclThread.o \ tclThreadAlloc.o tclThreadJoin.o tclThreadStorage.o tclStubInit.o \ tclTimer.o tclTrace.o tclUtf.o tclUtil.o tclVar.o tclZlib.o \ | | | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
tclObj.o tclOptimize.o tclPanic.o tclParse.o tclPathObj.o tclPipe.o \
tclPkg.o tclPkgConfig.o tclPosixStr.o \
tclPreserve.o tclProc.o tclRegexp.o \
tclResolve.o tclResult.o tclScan.o tclStringObj.o \
tclStrToD.o tclThread.o \
tclThreadAlloc.o tclThreadJoin.o tclThreadStorage.o tclStubInit.o \
tclTimer.o tclTrace.o tclUtf.o tclUtil.o tclVar.o tclZlib.o \
tclTomMathInterface.o tclZipfs.o
OO_OBJS = tclOO.o tclOOBasic.o tclOOCall.o tclOODefineCmds.o tclOOInfo.o \
tclOOMethod.o tclOOStubInit.o
TOMMATH_OBJS = bncore.o bn_reverse.o bn_fast_s_mp_mul_digs.o \
bn_fast_s_mp_sqr.o bn_mp_add.o bn_mp_and.o \
bn_mp_add_d.o bn_mp_clamp.o bn_mp_clear.o bn_mp_clear_multi.o \
|
| ︙ | ︙ | |||
369 370 371 372 373 374 375 | GENERIC_HDRS = \ $(GENERIC_DIR)/tcl.h \ $(GENERIC_DIR)/tclDecls.h \ $(GENERIC_DIR)/tclInt.h \ $(GENERIC_DIR)/tclIntDecls.h \ $(GENERIC_DIR)/tclIntPlatDecls.h \ | < | 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | GENERIC_HDRS = \ $(GENERIC_DIR)/tcl.h \ $(GENERIC_DIR)/tclDecls.h \ $(GENERIC_DIR)/tclInt.h \ $(GENERIC_DIR)/tclIntDecls.h \ $(GENERIC_DIR)/tclIntPlatDecls.h \ $(GENERIC_DIR)/tclTomMath.h \ $(GENERIC_DIR)/tclTomMathDecls.h \ $(GENERIC_DIR)/tclOO.h \ $(GENERIC_DIR)/tclOODecls.h \ $(GENERIC_DIR)/tclOOInt.h \ $(GENERIC_DIR)/tclOOIntDecls.h \ $(GENERIC_DIR)/tclPatch.h \ |
| ︙ | ︙ | |||
950 951 952 953 954 955 956 | else true; \ fi; \ done; @echo "Installing header files to $(INCLUDE_INSTALL_DIR)/"; @for i in $(GENERIC_DIR)/tcl.h $(GENERIC_DIR)/tclDecls.h \ $(GENERIC_DIR)/tclOO.h $(GENERIC_DIR)/tclOODecls.h \ $(GENERIC_DIR)/tclPlatDecls.h \ | < | 949 950 951 952 953 954 955 956 957 958 959 960 961 962 | else true; \ fi; \ done; @echo "Installing header files to $(INCLUDE_INSTALL_DIR)/"; @for i in $(GENERIC_DIR)/tcl.h $(GENERIC_DIR)/tclDecls.h \ $(GENERIC_DIR)/tclOO.h $(GENERIC_DIR)/tclOODecls.h \ $(GENERIC_DIR)/tclPlatDecls.h \ $(GENERIC_DIR)/tclTomMath.h \ $(GENERIC_DIR)/tclTomMathDecls.h ; \ do \ $(INSTALL_DATA) $$i "$(INCLUDE_INSTALL_DIR)"; \ done; # Optional target to install private headers |
| ︙ | ︙ | |||
1320 1321 1322 1323 1324 1325 1326 | tclVar.o: $(GENERIC_DIR)/tclVar.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclVar.c tclZlib.o: $(GENERIC_DIR)/tclZlib.c $(CC) -c $(CC_SWITCHES) $(ZLIB_INCLUDE) $(GENERIC_DIR)/tclZlib.c | | | | 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 | tclVar.o: $(GENERIC_DIR)/tclVar.c $(CC) -c $(CC_SWITCHES) $(GENERIC_DIR)/tclVar.c tclZlib.o: $(GENERIC_DIR)/tclZlib.c $(CC) -c $(CC_SWITCHES) $(ZLIB_INCLUDE) $(GENERIC_DIR)/tclZlib.c tclZipfs.o: $(GENERIC_DIR)/tclZipfs.c $(CC) -c $(CC_SWITCHES) $(ZLIB_INCLUDE) $(GENERIC_DIR)/tclZipfs.c tclTest.o: $(GENERIC_DIR)/tclTest.c $(IOHDR) $(TCLREHDRS) $(CC) -c $(APP_CC_SWITCHES) $(GENERIC_DIR)/tclTest.c tclTestObj.o: $(GENERIC_DIR)/tclTestObj.c $(MATHHDRS) $(CC) -c $(APP_CC_SWITCHES) $(GENERIC_DIR)/tclTestObj.c |
| ︙ | ︙ |
Changes to unix/tclAppInit.c.
| ︙ | ︙ | |||
11 12 13 14 15 16 17 | * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #undef BUILD_tcl #undef STATIC_BUILD #include "tcl.h" | | < < | 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ #undef BUILD_tcl #undef STATIC_BUILD #include "tcl.h" #ifdef TCL_TEST extern Tcl_PackageInitProc Tcltest_Init; extern Tcl_PackageInitProc Tcltest_SafeInit; #endif /* TCL_TEST */ #ifdef TCL_XT_TEST extern void XtToolkitInitialize(void); |
| ︙ | ︙ | |||
38 39 40 41 42 43 44 | #define TCL_LOCAL_APPINIT Tcl_AppInit #endif #ifndef MODULE_SCOPE # define MODULE_SCOPE extern #endif MODULE_SCOPE int TCL_LOCAL_APPINIT(Tcl_Interp *); MODULE_SCOPE int main(int, char **); | < | 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #define TCL_LOCAL_APPINIT Tcl_AppInit #endif #ifndef MODULE_SCOPE # define MODULE_SCOPE extern #endif MODULE_SCOPE int TCL_LOCAL_APPINIT(Tcl_Interp *); MODULE_SCOPE int main(int, char **); /* * The following #if block allows you to change how Tcl finds the startup * script, prime the library or encoding paths, fiddle with the argv, etc., * without needing to rewrite Tcl_Main() */ |
| ︙ | ︙ | |||
79 80 81 82 83 84 85 |
#ifdef TCL_XT_TEST
XtToolkitInitialize();
#endif
#ifdef TCL_LOCAL_MAIN_HOOK
TCL_LOCAL_MAIN_HOOK(&argc, &argv);
#endif
| | < < < < < | 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
#ifdef TCL_XT_TEST
XtToolkitInitialize();
#endif
#ifdef TCL_LOCAL_MAIN_HOOK
TCL_LOCAL_MAIN_HOOK(&argc, &argv);
#endif
Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
return 0; /* Needed only to prevent compiler warning. */
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
115 116 117 118 119 120 121 |
int
Tcl_AppInit(
Tcl_Interp *interp) /* Interpreter for application. */
{
if ((Tcl_Init)(interp) == TCL_ERROR) {
return TCL_ERROR;
}
| < < < | < | 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
int
Tcl_AppInit(
Tcl_Interp *interp) /* Interpreter for application. */
{
if ((Tcl_Init)(interp) == TCL_ERROR) {
return TCL_ERROR;
}
#ifdef TCL_XT_TEST
if (Tclxttest_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
#endif
#ifdef TCL_TEST
|
| ︙ | ︙ |
Changes to win/Makefile.in.
| ︙ | ︙ | |||
148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
TEST_LIB_FILE = @LIBPREFIX@tcltest$(VER)${LIBSUFFIX}
ZLIB_DLL_FILE = zlib1.dll
SHARED_LIBRARIES = $(TCL_DLL_FILE) @ZLIB_DLL_FILE@
STATIC_LIBRARIES = $(TCL_LIB_FILE)
TCLSH = tclsh$(VER)${EXESUFFIX}
CAT32 = cat32$(EXEEXT)
MAN2TCL = man2tcl$(EXEEXT)
# For cross-compiled builds, TCL_EXE is the name of a tclsh executable that is
# available *BEFORE* running make for the first time. Certain build targets
# (make genstubs, make install) need it to be available on the PATH. This
# executable should *NOT* be required just to do a normal build although
| > | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
TEST_LIB_FILE = @LIBPREFIX@tcltest$(VER)${LIBSUFFIX}
ZLIB_DLL_FILE = zlib1.dll
SHARED_LIBRARIES = $(TCL_DLL_FILE) @ZLIB_DLL_FILE@
STATIC_LIBRARIES = $(TCL_LIB_FILE)
TCLSH = tclsh$(VER)${EXESUFFIX}
TCLKIT = tclkit$(VER)${EXESUFFIX}
CAT32 = cat32$(EXEEXT)
MAN2TCL = man2tcl$(EXEEXT)
# For cross-compiled builds, TCL_EXE is the name of a tclsh executable that is
# available *BEFORE* running make for the first time. Certain build targets
# (make genstubs, make install) need it to be available on the PATH. This
# executable should *NOT* be required just to do a normal build although
|
| ︙ | ︙ | |||
299 300 301 302 303 304 305 | tclTimer.$(OBJEXT) \ tclTomMathInterface.$(OBJEXT) \ tclTrace.$(OBJEXT) \ tclUtf.$(OBJEXT) \ tclUtil.$(OBJEXT) \ tclVar.$(OBJEXT) \ tclZlib.$(OBJEXT) \ | | | 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
tclTimer.$(OBJEXT) \
tclTomMathInterface.$(OBJEXT) \
tclTrace.$(OBJEXT) \
tclUtf.$(OBJEXT) \
tclUtil.$(OBJEXT) \
tclVar.$(OBJEXT) \
tclZlib.$(OBJEXT) \
tclZipfs.$(OBJEXT)
TOMMATH_OBJS = \
bncore.${OBJEXT} \
bn_reverse.${OBJEXT} \
bn_fast_s_mp_mul_digs.${OBJEXT} \
bn_fast_s_mp_sqr.${OBJEXT} \
bn_mp_add.${OBJEXT} \
|
| ︙ | ︙ | |||
395 396 397 398 399 400 401 402 403 404 405 406 407 408 | STUB_OBJS = \ tclStubLib.$(OBJEXT) \ tclTomMathStubLib.$(OBJEXT) \ tclOOStubLib.$(OBJEXT) TCLSH_OBJS = tclAppInit.$(OBJEXT) ZLIB_OBJS = \ adler32.$(OBJEXT) \ compress.$(OBJEXT) \ crc32.$(OBJEXT) \ deflate.$(OBJEXT) \ infback.$(OBJEXT) \ inffast.$(OBJEXT) \ | > > | 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
STUB_OBJS = \
tclStubLib.$(OBJEXT) \
tclTomMathStubLib.$(OBJEXT) \
tclOOStubLib.$(OBJEXT)
TCLSH_OBJS = tclAppInit.$(OBJEXT)
TCLKIT_OBJS = tclkitMain.${OBJEXT} tclkit.${OBJEXT}
ZLIB_OBJS = \
adler32.$(OBJEXT) \
compress.$(OBJEXT) \
crc32.$(OBJEXT) \
deflate.$(OBJEXT) \
infback.$(OBJEXT) \
inffast.$(OBJEXT) \
|
| ︙ | ︙ | |||
416 417 418 419 420 421 422 | TCL_DOCS = "$(ROOT_DIR_NATIVE)"/doc/*.[13n] all: binaries libraries doc packages tcltest: $(TCLSH) $(TEST_DLL_FILE) | | > > > > > | 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 |
TCL_DOCS = "$(ROOT_DIR_NATIVE)"/doc/*.[13n]
all: binaries libraries doc packages
tcltest: $(TCLSH) $(TEST_DLL_FILE)
binaries: $(TCL_STUB_LIB_FILE) @LIBRARIES@ winextensions $(TCLSH) $(TCLKIT)
winextensions: ${DDE_DLL_FILE} ${REG_DLL_FILE}
libraries:
doc:
$(TCLSH): $(TCLSH_OBJS) @LIBRARIES@ $(TCL_STUB_LIB_FILE) tclsh.$(RES)
$(CC) $(CFLAGS) $(TCLSH_OBJS) $(TCL_LIB_FILE) $(TCL_STUB_LIB_FILE) $(LIBS) \
tclsh.$(RES) $(CC_EXENAME) $(LDFLAGS_CONSOLE)
@VC_MANIFEST_EMBED_EXE@
$(TCLKIT): $(TCLKIT_OBJ) @LIBRARIES@ $(TCL_STUB_LIB_FILE) tclsh.$(RES)
$(CC) $(CFLAGS) $(TCLKIT_OBJ) $(TCL_LIB_FILE) $(TCL_STUB_LIB_FILE) $(LIBS) \
tclsh.$(RES) $(CC_EXENAME) $(LDFLAGS_CONSOLE)
@VC_MANIFEST_EMBED_EXE@
cat32.$(OBJEXT): cat.c
$(CC) -c $(CC_SWITCHES) @DEPARG@ $(CC_OBJNAME)
$(CAT32): cat32.$(OBJEXT)
$(CC) $(CFLAGS) cat32.$(OBJEXT) $(CC_EXENAME) $(LIBS) $(LDFLAGS_CONSOLE)
|
| ︙ | ︙ | |||
492 493 494 495 496 497 498 499 500 501 502 503 504 505 |
testMain.${OBJEXT}: tclAppInit.c
$(CC) -c $(CC_SWITCHES) -DTCL_TEST @DEPARG@ $(CC_OBJNAME)
tclMain2.${OBJEXT}: tclMain.c
$(CC) -c $(CC_SWITCHES) -DBUILD_tcl -DTCL_ASCII_MAIN @DEPARG@ $(CC_OBJNAME)
# TIP #59, embedding of configuration information into the binary library.
#
# Part of Tcl's configuration information are the paths where it was installed
# and where it will look for its libraries (which can be different). We derive
# this information from the variables which can be overridden by the user. As
# every path can be configured separately we do not remember one general
# prefix/exec_prefix but all the different paths individually.
| > > > | 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 |
testMain.${OBJEXT}: tclAppInit.c
$(CC) -c $(CC_SWITCHES) -DTCL_TEST @DEPARG@ $(CC_OBJNAME)
tclMain2.${OBJEXT}: tclMain.c
$(CC) -c $(CC_SWITCHES) -DBUILD_tcl -DTCL_ASCII_MAIN @DEPARG@ $(CC_OBJNAME)
tclkitMain.${OBJEXT}: tclAppInit.c
$(CC) -c $(CC_SWITCHES) -DTCL_LOCAL_MAIN_HOOK="Tclkit_MainHook" -DTCL_LOCAL_APPINIT="Tclkit_AppInit" @DEPARG@ $(CC_OBJNAME)
# TIP #59, embedding of configuration information into the binary library.
#
# Part of Tcl's configuration information are the paths where it was installed
# and where it will look for its libraries (which can be different). We derive
# this information from the variables which can be overridden by the user. As
# every path can be configured separately we do not remember one general
# prefix/exec_prefix but all the different paths individually.
|
| ︙ | ︙ |
Changes to win/makefile.vc.
| ︙ | ︙ | |||
341 342 343 344 345 346 347 | $(TMP_DIR)\tclTimer.obj \ $(TMP_DIR)\tclTomMathInterface.obj \ $(TMP_DIR)\tclTrace.obj \ $(TMP_DIR)\tclUtf.obj \ $(TMP_DIR)\tclUtil.obj \ $(TMP_DIR)\tclVar.obj \ $(TMP_DIR)\tclZlib.obj \ | | | 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | $(TMP_DIR)\tclTimer.obj \ $(TMP_DIR)\tclTomMathInterface.obj \ $(TMP_DIR)\tclTrace.obj \ $(TMP_DIR)\tclUtf.obj \ $(TMP_DIR)\tclUtil.obj \ $(TMP_DIR)\tclVar.obj \ $(TMP_DIR)\tclZlib.obj \ $(TMP_DIR)\tclZipfs.obj ZLIBOBJS = \ $(TMP_DIR)\adler32.obj \ $(TMP_DIR)\compress.obj \ $(TMP_DIR)\crc32.obj \ $(TMP_DIR)\deflate.obj \ $(TMP_DIR)\infback.obj \ |
| ︙ | ︙ |
Changes to win/tclAppInit.c.
| ︙ | ︙ | |||
21 22 23 24 25 26 27 | #undef STRICT #undef WIN32_LEAN_AND_MEAN #include <locale.h> #include <stdlib.h> #include <tchar.h> #ifdef TCL_TEST | < < < | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #undef STRICT #undef WIN32_LEAN_AND_MEAN #include <locale.h> #include <stdlib.h> #include <tchar.h> #ifdef TCL_TEST extern Tcl_PackageInitProc Tcltest_Init; extern Tcl_PackageInitProc Tcltest_SafeInit; #endif /* TCL_TEST */ #if defined(STATIC_BUILD) && TCL_USE_STATIC_PACKAGES extern Tcl_PackageInitProc Registry_Init; extern Tcl_PackageInitProc Dde_Init; extern Tcl_PackageInitProc Dde_SafeInit; #endif #ifdef TCL_BROKEN_MAINARGS |
| ︙ | ︙ | |||
124 125 126 127 128 129 130 |
*p = '/';
}
}
#ifdef TCL_LOCAL_MAIN_HOOK
TCL_LOCAL_MAIN_HOOK(&argc, &argv);
#endif
| | < < < < < < | 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
*p = '/';
}
}
#ifdef TCL_LOCAL_MAIN_HOOK
TCL_LOCAL_MAIN_HOOK(&argc, &argv);
#endif
Tcl_Main(argc, argv, TCL_LOCAL_APPINIT);
return 0; /* Needed only to prevent compiler warning. */
}
/*
*----------------------------------------------------------------------
*
|
| ︙ | ︙ | |||
161 162 163 164 165 166 167 |
int
Tcl_AppInit(
Tcl_Interp *interp) /* Interpreter for application. */
{
if ((Tcl_Init)(interp) == TCL_ERROR) {
return TCL_ERROR;
}
| < < < < < < | 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 |
int
Tcl_AppInit(
Tcl_Interp *interp) /* Interpreter for application. */
{
if ((Tcl_Init)(interp) == TCL_ERROR) {
return TCL_ERROR;
}
#if defined(STATIC_BUILD) && TCL_USE_STATIC_PACKAGES
if (Registry_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_StaticPackage(interp, "registry", Registry_Init, NULL);
if (Dde_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_StaticPackage(interp, "dde", Dde_Init, Dde_SafeInit);
#endif
#ifdef TCL_TEST
if (Tcltest_Init(interp) == TCL_ERROR) {
return TCL_ERROR;
}
Tcl_StaticPackage(interp, "Tcltest", Tcltest_Init, Tcltest_SafeInit);
#endif /* TCL_TEST */
/*
* Call the init procedures for included packages. Each call should look
* like this:
*
* if (Mod_Init(interp) == TCL_ERROR) {
|
| ︙ | ︙ |