File: wool.c

package info (click to toggle)
gwm 1.8d-2
  • links: PTS
  • area: main
  • in suites: potato, woody
  • size: 5,120 kB
  • ctags: 3,030
  • sloc: ansic: 19,617; makefile: 1,763; lisp: 437; sh: 321; ml: 21
file content (2190 lines) | stat: -rw-r--r-- 50,637 bytes parent folder | download
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

/* Copyright 1989 GROUPE BULL -- See license conditions in file COPYRIGHT
 * Copyright 1989 Massachusetts Institute of Technology
 */
/**************************************************************\
* 							       *
* WOOL.c:						       *
* main body of interpreter				       *
* 							       *
* Here are defined Wool-only functions.			       *
* To add a function:					       *
* 	- declare it (coded in or extern)		       *
* 	- add it to the declaration of predefined functions    *
* 	  in the wool_init function			       *
* 							       *
* 'Kludged' to support the flex skeleton parser for V2.3.7   *
*				Dec 1992, O. Kirch	       *
\**************************************************************/

#if defined SVR4
#define SYSV
#endif

#include <stdio.h>
#include <sys/types.h>
#include <sys/file.h> 
#include <sys/times.h>
#include <signal.h> 
#include <sys/stat.h>
#if defined(IBM_RT) && defined(SYSV)
#include <unistd.h>
#endif /* IBM_RT && SYSV */
#if defined(i386) || defined(stellar)
#include <unistd.h>
#endif /* i386 */
#if defined(sun) && defined(SYSV)
#include <unistd.h>
#endif /* sun && SYSV */
#if defined(linux)
#include <unistd.h>
#endif /* linux */
#if defined(SYSV)
#include <limits.h>
#endif

#include "INTERN.h"
#include "wool.h"
#include "EXTERN.h"
#include "wl_atom.h"
#include "wl_coll.h"
#include "wl_func.h"
#include "wl_list.h"
#include "wl_number.h"
#include "wl_string.h"
#include "wl_pointer.h"
#include "wl_active.h"
#include "wl_name.h"
#include "yacc.h"

#ifdef SYSV
#include <string.h>
#include <sys/utsname.h>
#else /* SYSV */
#include <sys/wait.h>
#include <strings.h>
#include <sys/timeb.h>
#endif /* SYSV */

#ifdef STATS
extern WOOL_OBJECT zrtstats();
extern WOOL_OBJECT wlcfstats();
#endif /* STATS */
extern WOOL_OBJECT progn();
extern WOOL_OBJECT wool_print_nary();
extern WOOL_OBJECT wool_with(), wool_with_eval(); 
extern int 	wool_error_in_profile;
extern char 	*yytext;
DECLARE_strchr;

#ifdef DEBUG
#ifdef GWM
extern WOOL_OBJECT WLFsm_fp();
extern WOOL_OBJECT WLState_fp();
extern WOOL_OBJECT WLArc_fp();
#endif /* GWM */
#endif /* DEBUG */

/* VARS */

#ifdef SECURE
/* some helps */
char *wool_methods_names[] = {
    "WOOL_type_name",
    "WOOL_eval",
    "WOOL_print",
    "WOOL_free",
    "WOOL_execute",
    "WOOL_set",
    "WOOL_get_C_value",
    "WOOL_open",
    "WOOL_close",
    "WOOL_process_event",
    "WOOL_copy",
    "WOOL_get_dimensions",
    "WOOL_draw",
    "WOOL_equal",
    "WOOL_reconfigure",
    "WOOL_setq",
    "WOOL_silent_eval",
    "WOOL_UNDEFINED",
    "WOOL_UNDEFINED",
    "WOOL_UNDEFINED",
    "WOOL_UNDEFINED"
};

#endif /* SECURE */

#ifdef DO_BUS_ERROR
#define DoABusError() *((int *)0) = 1
#else /* DO_BUS_ERROR */
#define DoABusError()
#endif /* DO_BUS_ERROR */

/*
 * all constructors sets reference count of the object to 0
 * You should call check_reference on this object if it was only
 * a temporary one!
 */

/*******************\
* 		    *
*  run-time errors  *
* 		    *
\*******************/

static int             wool_error_position;
static char 	      *wool_error_expecting;
static int	       wool_error_print_argc;
static WOOL_OBJECT    *wool_error_print_argv;

/* echoes 1st, 2nd, 3rd, nth */

char *
English_enumeration_postfix(n)
int n;
{
    switch (n) {
	case 1: return "st";
	case 2: return "nd";
	case 3: return "rd";
	default: return "th";
    }
}

#ifdef __STDC__
extern void wool_print_error_message(int error, const void *message, char *text);
#else
extern void wool_print_error_message();
#endif

/*
 * wool_error:
 * This is the standard error function. It is really brutal, as it wool_prints
 * an error message an then LONGJMPs to "wool_goes_here_on_error" with an
 * error value, for now 1.
 * You can feel free to redefine wool_goes_here_on_error.
 * 
 * WARNING: Don't forget to clean your structures before going here,
 * you won't return!
 */

WOOL_OBJECT
#ifdef __STDC__
_wool_error(int error, const void *message)
#else
_wool_error(error, message)
int             error;		/* error number (see wool.h) */
char           *message;	/* anything, in fact */
#endif
{
    static int      is_in_wool_error;

    if (is_in_wool_error) {
	stop_if_in_dbx();
	goto direct_longjmp;
    }
    is_in_wool_error = 1;
    if (wool_do_print_errors && error != SILENT_ERROR) {
	wool_print_error_message(error, message, "WOOL ERROR: ");
	wool_stack_dump(0);
	fflush(stdout);
	fflush(stderr);
    }
    if (!wool_continue_reading_on_error)
	wool_error_status = 1;
    wool_error_handler();		/* C package handler */
    DoABusError();			/* debug only */
    WLStackFrame_pop_to(wool_stackframe_on_error);
    calling_function_current = calling_function_stack +
	calling_function_on_error;
direct_longjmp:
    is_in_wool_error = 0;
    stop_if_in_dbx();
    longjmp(wool_goes_here_on_error, 1);
    /* NOTREACHED *//* for lint */
    return NIL;
}

void
#ifdef __STDC__
wool_print_error_message(int error, const void *message, char *text)
#else
wool_print_error_message(error, message, text)
int             error;		/* error number (see wool.h) */
char           *message;	/* anything, in fact */
char           *text;		/* WOOL ERROR: */
#endif
{
#ifndef DEBUG
    wool_newline();
#endif /* DEBUG */
    if (wool_is_reading_file) {
	wool_printf("\"%s\"", wool_is_reading_file);
	wool_printf(": line %d\n", yylineno);
    }
    wool_puts(text);
    switch (error) {
    case UNDEFINED_VARIABLE:
	wool_printf("undefined variable: %s", message);
	break;
    case BAD_NUMBER_OF_ARGS:
	wool_printf("bad number of arguments %d", message);
	break;
    case UNDEFINED_FUNCTION:
	wool_puts("undefined function: ");
	wool_print(message);
	break;
    case BAD_DEFUN:
	wool_printf("bad definition of function: %s", message);
	break;
    case BAD_ARG_TYPE:
	wool_printf("bad %d", wool_error_position + 1);
	wool_printf("%s argument: ",
		    English_enumeration_postfix(wool_error_position + 1));
	wool_print(message);
	if (wool_error_expecting) {
	    wool_puts(" (its type is \"");
	    wool_print(((WOOL_OBJECT) message) -> type[0]);
	    if (wool_error_expecting[0])
	      wool_printf("\", was expecting a \"%s",
			  wool_error_expecting);
	    wool_puts("\")");
	}
	break;
    case RELEASING_ATOM:
	wool_printf("Internal error: trying to free atom: %s", message);
	break;
    case NOT_AN_ATOM:
	wool_printf("Not an atom: %s", message);
	break;
    case BAD_LOCAL_SYNTAX:
	wool_printf("bad local variable declaration. %s", message);
	break;
    case SYNTAX_ERROR:
	wool_printf("%s", message);
	break;
    case INTERNAL_ERROR:
	wool_printf("Internal error: %s", message);
	break;
    case TIME_EXCEEDED:
	wool_printf("Evaluation took longer than %ld second(s) -- Aborted",
		    message);
	break;
    case CANNOT_SET:
	wool_puts("Cannot set a \"");
	wool_print_type(message);
	wool_puts("\": ");
	wool_print(message);
	break;
    case CANNOT_GET_C_VALUE:
	wool_puts("Cannot figure how to get a number from a \"");
	wool_print_type(message);
	wool_puts("\": ");
	wool_print(message);
	break;
    case TOO_MANY_PARAMETERS:
	wool_puts("Too many parameters for a C function call: ");
	wool_print(message);
	break;
    case NON_WOOL_OBJECT:
	wool_printf("%s on a non wool object.", message);
	break;
    case UNDEFINED_METHOD:
#ifdef DEBUG
	wool_printf("Undef WOOL method %s for type \"",
		    wool_methods_names[WOOL_current_method]);
#else /* DEBUG */
	wool_puts("Bad object type \"");
#endif /* DEBUG */
	WLAtom_print(((WOOL_OBJECT) message) -> type[0]);
	wool_puts("\" for object: ");
	wool_print(message);
	break;
    case NO_MEMORY:
	wool_puts("No more memory, bye...\n");
	wool_end(1);
	break;
    case NOT_REDEFINABLE:
	wool_puts("Cannot redefine object: ");
	wool_print(message);
	break;
    case NOT_MODIFIABLE:
	wool_puts("Cannot modify object: ");
	wool_print(message);
	break;
    case USER_ERROR:
	wool_print_nary(wool_error_print_argc, wool_error_print_argv);
	break;
    default:			/* suppose first arg was a string! */
	wool_printf(error, message);
    }
    wool_newline();
}

/* wool_trigger_error
 * triggers an error from wool
 */

WOOL_OBJECT
wool_trigger_error(argc, argv)
int argc;
WOOL_OBJECT	argv[];
{
    wool_error_print_argc = argc;
    wool_error_print_argv = argv;
    return wool_error(USER_ERROR, 0);
}

/* wool_error_has_occurred:
 * encapsulates statements to trap errors without printing them
 */

WOOL_OBJECT
wool_error_has_occurred(argc, argv)
int argc;
WOOL_OBJECT	argv[];
{
    int             we_got_an_error = 0;
    int old_wool_do_print_errors = wool_do_print_errors;

    save_wool_error_resume_point();
    wool_do_print_errors = 0;
    if (set_wool_error_resume_point()) {
	we_got_an_error = 1;
    } else {
	progn(argc, argv);
    }
    wool_do_print_errors = old_wool_do_print_errors;
    restore_wool_error_resume_point();
    return (we_got_an_error ? TRU : NIL);
}

/* bad argument call
 */

WOOL_OBJECT
bad_argument(argument, position, expecting)
WOOL_OBJECT	argument;
int		position;
char	       *expecting;
{
    wool_error_position = position;
    wool_error_expecting = expecting;
    return wool_error(BAD_ARG_TYPE, argument);
}

/* wool warning messages 
 * returns 1 if printed
 */

int
wool_warning(alarm_text)
char	*alarm_text;
{
    if(wool_do_print_errors){
	wool_puts(alarm_text);
	if (wool_is_reading_file) {
	    wool_printf("\"%s\"", wool_is_reading_file);
	    wool_printf(": line %d, ", yylineno);
	}
	wool_stack_dump(0);
	return 1;
    } else
    	return 0;
}

int
wool_warning1(alarm_text, data)
char	*alarm_text;
char    *data;
{
    char msg[MAX_TEMP_STRING_SIZE];

    sprintf(msg, alarm_text, data);
    return wool_warning(msg);
}


/* executes an expression, returns if error (do not jump to toplevel)
 * return eval if no error occurred, NULL otherwise
 */

WOOL_OBJECT
wool_eval_and_catch_errors(wool_expr)
WOOL_OBJECT wool_expr;
{
    WOOL_OBJECT	    result = 0;

    save_wool_error_resume_point();	/* contains decls */
    if (set_wool_error_resume_point()) {
	result = 0;
    } else {
	result = WOOL_send(WOOL_eval, wool_expr, (wool_expr));
    }
    restore_wool_error_resume_point();
    return  result;
}

/* same but do not return a value
 */

wool_eval_and_catch_errors_proc(wool_expr)
WOOL_OBJECT wool_expr;
{
    int             local_zrt_size = zrt_size;

    wool_eval_and_catch_errors(wool_expr);
    zrt_gc(local_zrt_size);
}
  

/* 
 * undefined method, one for each number of parameters.
 */

WOOL_OBJECT
wool_undefined_method_1(object)
WOOL_OBJECT object;
{
    return wool_error(UNDEFINED_METHOD, object);
}

WOOL_OBJECT
wool_undefined_method_2(object, param1)
WOOL_OBJECT object;
WOOL_OBJECT param1;
{
    return wool_error(UNDEFINED_METHOD, object);
}

#ifdef DEBUG
#define RMAGIC		0x5555	/* magic # on range info (see malloc.c)*/

extern char *malloc_zone_begin, *malloc_zone_end;

wool_send_is_valid(message, object)
int message;
WOOL_OBJECT object;
{
    if (!object
	|| ((char *) object) < malloc_zone_begin
	|| ((char *) object) >= malloc_zone_end
	|| *((int *) object) == FREED_MAGIC
	|| ((((WOOL_Atom) object -> type[0]) -> type != WLAtom)
	    && (((WOOL_Atom) object -> type[0]) -> type != WLActive)
	    && (((WOOL_Atom) object -> type[0]) -> type != WLPointer)
	    && (((WOOL_Atom) object -> type[0]) -> type != WLName)))
	wool_error(NON_WOOL_OBJECT, wool_methods_names[message]);
}

wool_object_is_valid(object)
WOOL_OBJECT object;
{
    if (!object
	|| ((char *) object) < malloc_zone_begin
	|| ((char *) object) >= malloc_zone_end
	|| *((int *) object) == FREED_MAGIC
	|| ((((WOOL_Atom) object -> type[0]) -> type != WLAtom)
	    && (((WOOL_Atom) object -> type[0]) -> type != WLActive)
	    && (((WOOL_Atom) object -> type[0]) -> type != WLPointer)
	    && (((WOOL_Atom) object -> type[0]) -> type != WLName)))
	return 0;
    else
	return 1;
}

#endif /* DEBUG */

/*********************************************************\
* 							  *
* The definition of C WOOL routines			  *
* These constitue the WOOL interface to the C programmer  *
* 							  *
\*********************************************************/

/*
 * wool_read:
 * reads an expression from the input (string or stream).
 * returns this expression or NULL if EOF reached
 * In case of syntax error, returns NIL
 * the read expression is in the global variable wool_read_expr,
 * if you need it. (this global is maintained for ref count purposes)
 * You don't need to free it since it's done at the beginning of this
 * routine.
 * Beware that it could be overwritten by a subsequent call to wool_eval
 * or wool_read !
 */

WOOL_OBJECT
wool_read()
{
    if (yyparse())
	return NULL;		/* returns NULL if error */
    else
	return wool_read_expr;	/* returns parsed expression */
}

/*
 * wool_pool:
 * this routine MUST be used when you want to make successive calls to
 * wool_read to parse an expression. It stores the string passed as argument
 * and returns the parenthese level. Thus a normal use would be to call
 * wool_pool with successive lines, while it returns a non-zero value,
 * and then call wool_read on the pooled buffer maintained by wool_poll,
 * whose address is stored in the global wool_pool_buffer.
 * (the parenthese level is in the int wool_pool_parenthese_level)
 * The buffer is reset by calling wool_pool with a NULL argument.
 */

int
wool_pool(s)
char           *s;		/* the string to be put in the pool */
{
    int             required_length;

    if (!wool_pool_buffer)
	wool_pool_buffer =
	    (char *) Malloc(wool_pool_buffer_size);
    if (!s) {
	*wool_pool_buffer = '\0';
	return wool_pool_parentheses_level = 0;
    } else {
	if ((int) (strlen(wool_pool_buffer) + (required_length = strlen(s)))
	    >= wool_pool_buffer_size) {
	    wool_pool_buffer_size +=
		Max(wool_pool_buffer_size, required_length) + 4;
	    wool_pool_buffer = (char *)
		Realloc(wool_pool_buffer, wool_pool_buffer_size);
	}
	strcat(wool_pool_buffer, "\n");
	strcat(wool_pool_buffer, s);
	{
	    char           *oldstream, old_input_buf[AHEAD_BUF_SIZE];
	    int             old_type;

	    old_type = wool_input_redirect(1, s, &oldstream, old_input_buf);
	    while (yylex() != END_OF_FILE);
	    wool_input_redirect(old_type, oldstream, NULL, NULL);
	    wool_unput(old_input_buf);
	    return wool_pool_parentheses_level;
	}
    }
}

/*
 * wool_eval:
 * evals an expression given as argument;
 * returns the result of the evaluation
 * if you want to keep the result, increase its reference count!
 * In case of eval error, calls wool_error which returns NIL
 */

WOOL_OBJECT
wool_eval(read_expr)
WOOL_OBJECT read_expr;
{
    return WOOL_send(WOOL_eval, read_expr, (read_expr));
}

/***************************************************************************\
* 									    *
* WOOL USER routines:							    *
* here are the definition of the standard routines binded to wool atoms by  *
* wool_init								    *
* 									    *
\***************************************************************************/

/*
 * The NULL function is there only as a placeholder
 */

WOOL_OBJECT
NIL_FUNC()
{
    return NIL;
}

/*
 * quoting can be implemented as a function:
 * 'foo ==> (quote foo)
 */

WOOL_OBJECT
wool_quote(obj)
WOOL_OBJECT obj;
{
    return obj;
}

/*
 * eval is the opposite of quoting
 */

WOOL_OBJECT
eval(obj)
WOOL_OBJECT     obj;
{
    return WOOL_send(WOOL_eval, obj, (obj));
}

/* copy an object (useful for lists)
 */

WOOL_OBJECT
wool_copy(obj)
WOOL_OBJECT     obj;
{
    return WOOL_send(WOOL_copy, obj, (obj));
}

/*
 * Arithmetic functions, patterned along Le_Lisp ones
 */

WOOL_OBJECT
wool_divide(n1, n2)
WOOL_Number n1, n2;
{
    return (WOOL_OBJECT) WLNumber_make(n2 -> number ?
				       n1 -> number / n2 -> number : 0);
}

WOOL_OBJECT
wool_modulo(n1, n2)
WOOL_Number n1, n2;
{
    Num tmp = n2 -> number ? n1 -> number % n2 -> number : 0;
    
    if (tmp < 0)
	tmp = tmp + n2 -> number;
    
    return (WOOL_OBJECT) WLNumber_make(tmp);
}

WOOL_OBJECT
wool_multiply(n1, n2)
WOOL_Number n1, n2;
{
    return (WOOL_OBJECT) WLNumber_make(n1 -> number * n2 -> number);
}

WOOL_OBJECT
wool_add(argc,argv)
int		argc;
WOOL_Number     argv[];
{
    WOOL_TYPE       type;

    if (argc == 0)
	wool_error(BAD_NUMBER_OF_ARGS, (char *)argc);
    type = argv[0] -> type;
    if (type == WLList || argv[0] == (WOOL_Number) NIL)
	return WLList_concat(argc, argv);
    else if (type == WLNumber)
	return add_numbers(argc, argv);
    else
	must_be_string(argv[0], 0);
    return add_strings(argc, argv);
}

WOOL_OBJECT
wool_minus(argc, argv)
int		argc;
WOOL_Number     argv[];
{
    switch (argc) {
    case 1:
	return (WOOL_OBJECT) WLNumber_make(-(argv[0] -> number));
    case 2:
	return (WOOL_OBJECT) WLNumber_make(
				 (argv[0] -> number) - (argv[1] -> number));
    case 0:
	return wool_error(BAD_NUMBER_OF_ARGS, (char *)argc);
    default: {int i, result = argv[0] -> number;
	      for (i = 1; i < argc; i++)
		  result -= argv[i] -> number;
	      return (WOOL_OBJECT) WLNumber_make(result);
	  }	
    }
}

/* comparisons
 */

WOOL_OBJECT
wool_equal(o1, o2)
WOOL_OBJECT     o1, o2;
{
    return WOOL_send(WOOL_equal, o1, (o1, o2));
}

WOOL_OBJECT
wool_eq(o1, o2)
WOOL_OBJECT     o1, o2;
{
    if (o1 == o2)
	return TRU;
    else
	return NIL;
}

WOOL_OBJECT
greater_than(o1, o2)
WOOL_OBJECT     o1, o2;
{
    if (o1 -> type != o2 -> type)
	return NIL;
    if (((o1 -> type == WLNumber) &&
	 (((WOOL_Number) o1) -> number > ((WOOL_Number) o2) -> number))
	|| ((o1 -> type == WLString) &&
	    strcmp(((WOOL_String) o1) -> string,
		   ((WOOL_String) o2) -> string) == 1))
	return TRU;
    else
	return NIL;
}

WOOL_OBJECT
lesser_than(o1, o2)
WOOL_OBJECT     o1, o2;
{
    if (o1 -> type != o2 -> type)
	return NIL;
    if (((o1 -> type == WLNumber) &&
	 (((WOOL_Number) o1) -> number < ((WOOL_Number) o2) -> number))
	|| ((o1 -> type == WLString) &&
	    strcmp(((WOOL_String) o1) -> string,
		   ((WOOL_String) o2) -> string) == -1))
	return TRU;
    else
	return NIL;
}
    
/* wool_compare returns -1, 0, +1 if <, =, > and () if not comparable.
 */

WOOL_OBJECT
wool_compare(o1, o2)
WOOL_Number     o1, o2;
{
    if (o1 -> type != o2 -> type)
	return NIL;
    if (o1 -> type == WLNumber) {
	if (o1 -> number < o2 -> number)
	    return (WOOL_OBJECT) WLNumber_make(-1);
	else if (o1 -> number > o2 -> number)
	    return (WOOL_OBJECT) WLNumber_make(1);
	else
	    return (WOOL_OBJECT) WLNumber_make(0);
    } else {
	must_be_string(o1, 0);
	return (WOOL_OBJECT) WLNumber_make(
					strcmp(((WOOL_String) o1) -> string,
					     ((WOOL_String) o2) -> string));
    }
}

/* member of a list, or substring of a string:
 * returns position in list or string or NIL if not found
 */

WOOL_OBJECT
wool_member(obj, list)
WOOL_String	obj;
WOOL_List	list;
{
    if (list -> type == WLList) {	/* list */
	WOOL_OBJECT    *p = list -> list;
	WOOL_OBJECT    *last = p + list -> size;

	while (p < last) {
	    if (WOOL_send(WOOL_equal, obj, (obj, *p)) != NIL)
		return (WOOL_OBJECT) WLNumber_make(p - list -> list);
	    p++;
	}
	return NIL;
    } else if (list == (WOOL_List) NIL) {	/* () */
	return NIL;
    } else {				/* substring of a string */
	char           *p, *string;
	int             length;

	must_be_string(list, 1);
	must_be_string(obj, 0);
	string = ((WOOL_String) list) -> string;
	length = strlen(obj -> string);
	for (p = string; *p; p++)
	    if (!strncmp(obj -> string, p, length))
		return (WOOL_OBJECT) WLNumber_make(p - string);
	return NIL;
    }
}

/* logical operations
 */

WOOL_OBJECT
not(obj)
WOOL_OBJECT     obj;
{
    if (obj == NIL)
	return TRU;
    else
	return NIL;
}

WOOL_OBJECT
and(argc, argv)
int		argc;
WOOL_OBJECT     argv[];
{
    int    i;

    for (i = 0; i < argc; i++)
	if (WOOL_send(WOOL_eval, argv[i], (argv[i])) == NIL)
	    return NIL;
    return TRU;
}

WOOL_OBJECT
or(argc, argv)
int		argc;
WOOL_OBJECT     argv[];
{
    int    i;
    WOOL_OBJECT tmp;

    for (i = 0; i < argc; i++)
	if ((tmp = WOOL_send(WOOL_eval, argv[i], (argv[i]))) != NIL)
	    return tmp;
    return NIL;
}

/*
 * bitwise-operators
 */

WOOL_OBJECT
wool_bitwise_or(argc, argv)
int argc;
WOOL_Number argv[];
{
    int             num = 0;

    while (argc--)
	num |= argv[argc] -> number;
    return (WOOL_OBJECT) WLNumber_make(num);
}

WOOL_OBJECT
wool_bitwise_and(argc, argv)
int argc;
WOOL_Number argv[];
{
    int             num = argv[0] -> number;

    while (argc--)
	num &= argv[argc] -> number;
    return (WOOL_OBJECT) WLNumber_make(num);
}

WOOL_OBJECT
wool_bitwise_xor(argc, argv)
int argc;
WOOL_Number argv[];
{
    int             num = 0;

    while (argc--)
	num ^= argv[argc] -> number;
    return (WOOL_OBJECT) WLNumber_make(num);
}

/*
 * Setq, the most important function
 * implemented as a method
 */

WOOL_OBJECT
setq(atom, value)
WOOL_Atom atom;
WOOL_OBJECT value;
{
    return WOOL_send(WOOL_set, atom, (atom, value));
}

WOOL_OBJECT
set(atom, value)
WOOL_Atom atom;
WOOL_OBJECT value;
{
    return WOOL_send(WOOL_setq, atom, (atom, value));
}

/*
 * unbind: release storage of an atom
 */

WOOL_OBJECT
wool_unbind(atom)
WOOL_Atom atom;
{
    extern WOOL_OBJECT WLAtom_unbind(), WLName_unbind();

    if (atom -> type == WLAtom)
	return WLAtom_unbind(atom);
    else if (atom -> type == WLName)
	return WLName_unbind(atom);
    else
	return bad_argument(atom, 0, "atom or name");
}

/*
 * boundp: tests if atom has already be defined
 */

WOOL_OBJECT
wool_boundp(atom)
WOOL_OBJECT atom;
{
    WOOL_OBJECT	value = WOOL_send(WOOL_silent_eval, atom, (atom));

    if (value && value != UNDEFINED_WOOL_VALUE)
	return (atom == NIL ? TRU : atom);
    else
	return NIL;
}

/*
 * list: makes a list of its evaluated arguments
 */

WOOL_OBJECT
wool_list(argc, argv)
int argc;
WOOL_OBJECT     argv[];
{
    WOOL_List list;
    WOOL_OBJECT *q, *last;

    if (!argc)
	return NIL;
    list = wool_list_make(argc);
    q = list -> list;
    last = argv + argc;

    while (argv < last)
        increase_reference(*q++ = *argv++);
    return (WOOL_OBJECT) list;
}

/*
 * length: of a string or list
 */

WOOL_Number
wool_length(obj)
WOOL_List     obj;
{
    if (obj -> type == WLList)
	return WLNumber_make(obj -> size);
    else if (obj == (WOOL_List) NIL)
	return WLNumber_make(0);
    else {
	must_be_string(obj, 0);
	return WLNumber_make(strlen(((WOOL_String) obj) -> string));
    }
}

/*
 * BEWARE: hacker's corner!
 * returns the object of the same type found at location number!
 * 	type		action
 * 	number		*int
 * 	string		*char
 * 	()		object
 * 	atom		adress of pointer object
 */

WOOL_OBJECT
wool_hack(type, pointer)
WOOL_OBJECT type;
WOOL_Number pointer;
{
    if (type -> type == WLNumber)
	return (WOOL_OBJECT) WLNumber_make(*((int *) pointer -> number));
    else if (type -> type == WLString)
	return (WOOL_OBJECT) WLString_make(pointer -> number);
    else if (type == NIL) {
	increase_reference(pointer -> number);
	return (WOOL_OBJECT) pointer -> number;
    } else if (type -> type == WLAtom)
	return (WOOL_OBJECT) WLNumber_make(pointer);
    else
	return NIL;
}

/* used time function expressed in milliseconds
 */

#ifdef CLK_TCK
#define TIME_UNIT CLK_TCK
#else
#define TIME_UNIT 60
#endif

WOOL_OBJECT
wool_used_time()
{
    long time;

#ifdef SYSV_TIME
    struct tms buffer;

#ifdef CLK_TCK
    time = (times(&buffer) * 1000) / TIME_UNIT;
#else
    times(&buffer);
    time = ((buffer.tms_utime + buffer.tms_stime) * 1000 ) / TIME_UNIT;
#endif
#else /* !SYSV_TIME */
    struct timeb time_bsd;

    ftime(&time_bsd);
    time = 1000 * time_bsd.time + time_bsd.millitm;
#endif /* !SYSV_TIME */

    return (WOOL_OBJECT) WLNumber_make(time);
}

/*
 * atoi and itoa
 */

WOOL_OBJECT
wool_atoi(obj)
WOOL_String obj;
{
    must_be_string(obj, 0);
    return (WOOL_OBJECT) WLNumber_make(atoi(obj -> string));
}

WOOL_OBJECT
wool_itoa(obj)
WOOL_Number obj;
{
    char tmp_str[20];

    must_be_number(obj, 0);
    sprintf(tmp_str, "%d", obj -> number);
    return (WOOL_OBJECT) WLString_make(tmp_str);
}

/*
 * Shell escape: executes a SYSTEM of the string (or atom) argument
 */

WOOL_OBJECT
shell(argc, argv)
int		argc;
WOOL_String     argv[];
{
    int             i;
    char          **program_args = (char **) Malloc(sizeof(char *) * (argc + 1));

    if (!argc)
	wool_error(BAD_NUMBER_OF_ARGS, (char *)argc);
    for (i = 0; i < argc; i++) {
	must_be_string(argv[i], i);
	program_args[i] = argv[i] -> string;
    }
    program_args[argc] = NULL;
    if (!fork()) {
	wool_clean_before_exec();
	execvp(program_args[0], program_args);
	exit(127);
    }
    Free(program_args);
    return NIL;
}

/* signals management avoiding defunct processes */

#if defined SYSV || defined SVR4
void
ChildDeathHandler(sig)
int sig;
{
    wait(0);
    signal(SIGCLD, ChildDeathHandler);
}

SignalsInit()
{
    signal(SIGCLD, ChildDeathHandler);
}
#else /* SYSV */
#include <sys/time.h>
#include <sys/resource.h>
void
ChildDeathHandler(sig)
int sig;
{
    int status;

    wait3(&status, WNOHANG, 0);
    signal(SIGCHLD, ChildDeathHandler);
}

SignalsInit()
{
    signal(SIGCHLD, ChildDeathHandler);
}
#endif /* SYSV */

/*
 *  print value of an object
 */

WOOL_OBJECT
wool_print(obj)
WOOL_OBJECT     obj;
{
    wool_print_level = 0;
    return WOOL_send(WOOL_print, obj, (obj));
}

WOOL_OBJECT
wool_print_nary(argc, argv)
int argc;
WOOL_OBJECT     argv[];
{
    int             i;
    WOOL_OBJECT	result = NIL;

    wool_print_level = 0;
    for (i = 0; i < argc; i++)
	result = WOOL_send(WOOL_print, argv[i], (argv[i]));
    yyoutflush();
    return result;
}

static int
expand_string_stream (str)
  WOOL_STRING_STREAM str;
{
    char *new_buf;
    int nbytes = str->last - str->buffer + 1;
    int ptr_pos = str->ptr - str->buffer;

    str->buffer = Realloc (str->buffer, 2*nbytes);        
    str->last = str->buffer + nbytes - 1;
    str->ptr = str->buffer + ptr_pos;
}

WOOL_OBJECT
wool_with_output_to_string (argc, argv)
  int argc;
  WOOL_OBJECT *argv;
{
    WOOL_STRING_STREAM str, WOOL_STRING_STREAM_make (); 
    int old_type;
    char *old_stream;
    WOOL_OBJECT result;

    str = WOOL_STRING_STREAM_make (256, expand_string_stream);
    old_type = wool_output_redirect (1, str, &old_stream);
    progn (argc, argv);
    wool_output_redirect (old_type, old_stream, NULL);

    result = (WOOL_OBJECT) WLString_make (str->buffer);
    WOOL_STRING_STREAM_free (str);
    return result;
}

WOOL_OBJECT
wool_with_output_to_file (argc, argv)
  int argc;
  WOOL_OBJECT *argv;
{
    FILE* f;
    WOOL_String fname;
    int old_type;
    char *old_stream;
    char* filename;
    int ok;

    fname = (WOOL_String) WOOL_send(WOOL_eval, *argv, (*argv));
    must_be_string(fname, 0);
    f = fopen(fname->string, "w");
    if (f) {
        old_type = wool_output_redirect (0, f, &old_stream);
        progn (argc-1, argv+1);
        wool_output_redirect (old_type, old_stream, NULL);
        fclose(f);
        return TRU;
    } else {
	wool_puts(wool_application_NAME);
    	wool_printf(": could not open file : %s\n", fname->string);
	return NIL;
    }
}

/*
 * (progn inst1 ... instn)
 * evals the n instructions then return the last one's result
 */

WOOL_OBJECT
progn(argc, argv)
int    argc;
WOOL_OBJECT *argv;
{
    if (argc) {
	int             local_zrt_size = zrt_size;

	while (--argc > 0) {
	    WOOL_send(WOOL_eval, *argv, (*argv));
	    zrt_gc(local_zrt_size);
	    argv++;
	}
	return WOOL_send(WOOL_eval, *argv, (*argv));
    } else {
	return NIL;
    }
}

/*
 * if "a la emacs"
 * if test thenclause [test thenclause]* [elseclause]
 * nearly a COND, in fact
 */

WOOL_OBJECT
wool_if(argc, argv)
int    argc;
WOOL_OBJECT *argv;
{
    while (argc > 1) {
	if (WOOL_send(WOOL_eval, *argv, (*argv)) != NIL) {
	    return WOOL_send(WOOL_eval, *(argv + 1), (*(argv + 1)));
	}
	argc -= 2;
	argv += 2;
	if (argc == 1) {
	    return WOOL_send(WOOL_eval, *argv, (*argv));
	}
    }
    return NIL;
}

/*
 * while cond inst1 ... instn
 * classical while
 */

WOOL_OBJECT
wool_while(argc, argv)
int    argc;
WOOL_OBJECT *argv;
{
    while (WOOL_send(WOOL_eval, *argv, (*argv)) != NIL) {
	progn(argc - 1, argv + 1);
    }
    return NIL;
}

/*
 * for:
 * (for var list-of-values instructions...)
 */

WOOL_OBJECT
wool_for_loop(argc, argv, map)
int    argc;
WOOL_List *argv;
int		map;
{
    WOOL_List       list, result_list;
    WOOL_OBJECT	    /* previous_value, */ result;
    int i;

    if (argc < 3)
	wool_error(BAD_NUMBER_OF_ARGS, (char *)argc);
    must_be_atom(argv[0], 0);
    list = (WOOL_List) WOOL_send(WOOL_eval, argv[1], (argv[1]));
    if (WLList_length(list) == 0)  /* (list == (WOOL_List) NIL) */
    	return NIL;

    WLStackFrame_push_value(argv[0]);

    if(map) {
    	result_list = wool_list_make(list -> size);
    	for (i = 0; i < list -> size; i++) {
	    WOOL_send(WOOL_setq, argv[0], (argv[0], list -> list[i]));
	    increase_reference(result_list -> list[i] =
		progn(argc - 2, argv + 2));
        }
    } else {
	for (i = 0; i < list -> size; i++) {
            WOOL_send(WOOL_setq, argv[0], (argv[0], list -> list[i]));
            result = progn(argc - 2, argv + 2);
	}
    }

    WLStackFrame_pop();

    return (map ? (WOOL_OBJECT) result_list : result);
}

WOOL_OBJECT
wool_for(argc, argv)
int    argc;
WOOL_List *argv;
{
    return wool_for_loop(argc, argv, 0);
}

WOOL_OBJECT
wool_mapfor(argc, argv)
int    argc;
WOOL_List *argv;
{
    return wool_for_loop(argc, argv, 1);
}



/*
 * TAG/EXIT:
 * (tag tag insts...)
 * (exit tag insts...)
 */

typedef struct _JumpingPoint {
    WOOL_StackFrame frame;
    int 	    level; 		/* in calling_function_stack */
    jmp_buf	    jump_buffer;
    WOOL_OBJECT	result;
} *JumpingPoint;

WOOL_OBJECT
wool_tag(argc, argv)
int             argc;
WOOL_String    *argv;
{
    struct _JumpingPoint tag;
    WOOL_OBJECT     result;
    WOOL_Pointer    tag_name;

    if (argc < 2)
	wool_error(BAD_NUMBER_OF_ARGS, (char *)argc);
    must_be_string(argv[0], 0);
    wool_self_pointer_make(argv[0] -> string, '\024', &tag_name);
    *(tag_name -> ptr) = (long) &tag;
    tag.frame = wool_current_stackframe;
    tag.level = calling_function_current - calling_function_stack;
    if (setjmp(tag.jump_buffer) != 0) /* nonzero is return from longjmp */
	result = tag.result;
    else
	result = progn(argc - 1, argv + 1);
    *(tag_name -> ptr) = 0;
    return result;
}
	
WOOL_OBJECT
wool_exit(argc, argv)
int             argc;
WOOL_String    *argv;
{
    JumpingPoint    tag;
    WOOL_Pointer    tag_name;
    WOOL_OBJECT     result;

    if (argc < 1)
	wool_error(BAD_NUMBER_OF_ARGS, (char *)argc);
    must_be_string(argv[0], 0);
    if (wool_self_pointer_make(argv[0] -> string, '\024', &tag_name)
	&& *(tag_name -> ptr)) {
	tag = (JumpingPoint) * (tag_name -> ptr);
	result = argc > 1 ? progn(argc - 1, argv + 1) : NIL;
	WLStackFrame_pop_to(tag -> frame);
	calling_function_current = calling_function_stack + tag -> level;
	tag -> result = result;
	longjmp(tag -> jump_buffer, -1);
    } else
	wool_error(UNDEFINED_VARIABLE, argv[0] -> string);
    return NIL;
}

/* the host name as a string
 */

WOOL_OBJECT
wool_hostname_get()
{
    if (!wool_host_name) {
	char buf[256];
	int maxlen = 256;
	int len;
#ifdef SYSV
	struct utsname name;
	
	uname (&name);
	len = strlen (name.nodename);
	if (len >= maxlen) len = maxlen - 1;
	strncpy (buf, name.nodename, len);
	buf[len] = '\0';
#else /* SYSV */
	buf[0] = '\0';
	(void) gethostname (buf, maxlen);
	buf [maxlen - 1] = '\0';
	len = strlen(buf);
#endif /* SYSV */
	increase_reference(wool_host_name = (WOOL_OBJECT) WLString_make(buf));
    }
    return  wool_host_name;
}

/*
 * very useful: de and df!
 * USAGE:
 * (de <func-name> (parameter-list) inst1 ... instn)
 * returns  the atom pointing to the subr
 */

WOOL_OBJECT
de(argc, argv)
int             argc;
WOOL_OBJECT    *argv;
{
    return defun(WLExpr, argc, argv);
}

WOOL_OBJECT
df(argc, argv)
int             argc;
WOOL_OBJECT    *argv;
{
    return defun(WLFExpr, argc, argv);
}

/*
 * wool_loadfile:
 * raw loadfile function: search EXACTLY for name in parameter
 */

WOOL_OBJECT
wool_loadfile(string)
char           *string;
{
    FILE           *fd, *oldinput;
    char            filename[MAX_TEMP_STRING_SIZE];
    int             local_zrt_size = zrt_size;

    if (!string)
	return NIL;
    strcpy(filename, string);
    fd = fopen(filename, "r");
    if (fd) {
	int             we_got_an_error = 0;
	char           *old_file = wool_is_reading_file;
	char            old_input_buffer[AHEAD_BUF_SIZE];
	int             oldtype = wool_input_redirect(0, fd, &oldinput,
						      old_input_buffer);
	int             old_yylineno = yylineno;

	save_wool_error_resume_point();	/* contains decls */
	yylineno = 1;
	wool_is_reading_file = filename;
	/* now, we must close the file and redirect input on error */
	if (wool_continue_reading_on_error) {
	    set_wool_error_resume_point();
	    while (wool_read()) {
		wool_eval(wool_read_expr);
		zrt_gc(local_zrt_size);
	    }
	} else {
	    if (set_wool_error_resume_point()) {
		we_got_an_error = 1;
	    } else {
		while (wool_read()) {
#ifdef READ_ECHO
		    printf("\"%s\"[%d]: ", filename, yylineno);
		    wool_print(wool_read_expr);
		    wool_puts("\n");
		    fflush(stdout);
		    fflush(stderr);
#endif
		    wool_eval(wool_read_expr);
		    zrt_gc(local_zrt_size);
		}
	    }
	}
	wool_input_redirect(oldtype, oldinput, 0, 0);
	wool_unput(old_input_buffer);
	fclose(fd);
	restore_wool_error_resume_point();
	wool_is_reading_file = old_file;
	yylineno = old_yylineno;
	if (we_got_an_error)
	    _wool_error(SILENT_ERROR, 0);
	return TRU;
    } else {
	return NIL;
    }
}

/* executes a given string */

WOOL_OBJECT
wool_execute_string(string)
char           *string;
{
    FILE           *oldinput;
    int             we_got_an_error = 0;
    char           *old_file = wool_is_reading_file;
    char            old_input_buffer[AHEAD_BUF_SIZE];
    int             oldtype = wool_input_redirect(1, string, &oldinput,
						  old_input_buffer);
    int             old_yylineno = yylineno;
    int             local_zrt_size = zrt_size;

    save_wool_error_resume_point();
    yylineno = 1;
    wool_is_reading_file = 0;
    /* now, we redirect input on error */
    if (set_wool_error_resume_point()) {
	we_got_an_error = 1;
    } else {
	while (wool_read()) {
	    wool_eval(wool_read_expr);
	    zrt_gc(local_zrt_size);
	}
    }
    wool_input_redirect(oldtype, oldinput, 0, 0);
    wool_unput(old_input_buffer);
    restore_wool_error_resume_point();
    wool_is_reading_file = old_file;
    yylineno = old_yylineno;
    if (we_got_an_error)
	return NIL;
    else
	return TRU;
}

/* same callable from wool */

WOOL_OBJECT
wool_execute_wool_string(string)
WOOL_String string;
{
    return wool_execute_string(string -> string);
}

/*
 * tests if file exists and is readable
 */

char *
file_exists(name)
char *name;
{
    /* Should detect if the file is a regular file, not a directory */
    struct stat sbuf;

    if ((stat(name, &sbuf)) < 0)
	return 0;
    if ((sbuf.st_mode & S_IFMT) == S_IFREG) {	/* regular file */
	if (access(name, R_OK)) {	/* good mode flags */
	    return 0;
	} else
	    return name;
    } else
	return 0;
}

/*
 * file_with_optional_extension:
 * see if file exists with extension
 */

char *
file_with_optional_extension(filename, extension)
char           *filename;
char           *extension;
{
    static char     filename_wl[MAX_TEMP_STRING_SIZE];

    strcpy(filename_wl, filename);
    strcat(filename_wl, extension);
    if(file_exists(filename_wl))
    	return filename_wl;
    return file_exists(filename);
}

/*
 * file_in_path:
 * find file with using path, extensions, etc...
 * complete_filename is a pointer to temporary space
 */

char *
file_in_path(filename, extension, path, complete_filename)
char           *filename, *extension, *path, *complete_filename;
{
    char  *directory, *name;
    int 	    dirlen;

    if (strchr(filename, '/')) {	/* absolute pathname */
	return (file_with_optional_extension(filename, extension));
    } else {			/* relative pathname */
	while (*path) {
	    directory = path;
	    dirlen = 0;
	    while (*path && (*path != ':')) {
		path++;
		dirlen++;
	    }
	    if (*path)
		path++;
	    complete_filename[dirlen] = '\0';
	    if (dirlen) {
		strncpy(complete_filename, directory, dirlen);
		if (complete_filename[dirlen - 1] != '/')
		    strcat(complete_filename, "/");
	    }
	    strcat(complete_filename, filename);
	    if (name = file_with_optional_extension(complete_filename,
						    extension))
		return name;
	}
	return 0;
    }
}


/*
 * loading a file (callable from wool)
 */

WOOL_OBJECT
wool_loadfile_in_path(string)
WOOL_String     string;
{
    char            temp_filename[MAX_TEMP_STRING_SIZE];
    char	   *actual_pathname = file_in_path(string -> string,
    			wool_text_extension, wool_path, temp_filename);

    if(NIL == wool_loadfile(actual_pathname)) {
	wool_puts(wool_application_NAME);
    	wool_printf(": file not found: %s\n", string -> string);
	return NIL;
    } else {
    	return (WOOL_OBJECT) WLString_make(actual_pathname);
    }
}

/*
 * cond for compatibility
 */

WOOL_OBJECT 
wool_cond(argc, argv)
int    argc;
WOOL_OBJECT *argv;
{
    WOOL_OBJECT    *list;
    WOOL_OBJECT     result = wool_if(argc * 2,
				  list = wool_flatten_pairlist(argc, argv));

    Free(list);
    return result;
}

/*
 * A context is a list of pairs variable-name/variable-values (atom/object).
 * Context operations are:
 * 
 * 	context-save: archives in the context the current values of
 * 		variables (sets to () undefined ones...)
 * 	context-restore: sets the variables to their archived values
 */

must_be_context(context, n)
WOOL_List	context;
int		n;
{
    if ((context != (WOOL_List) NIL)
	 && ((context -> type != WLList)
             || (context -> size % 2)))
	bad_argument(context, n, "even-sized list");
}

WOOL_OBJECT
wool_context_save(context)
WOOL_List	context;
{
    int             i;
    WOOL_List       new;

    must_be_context(context, 0);
    if (context == (WOOL_List) NIL)
        return NIL;
    new = wool_list_make(context -> size);
    for (i = 0; i < context -> size; i += 2) {
#ifdef        STUPID
      WOOL_OBJECT tmp;
#endif 
      increase_reference(new -> list[i] = context -> list[i]);
#ifdef  STUPID
      tmp = context -> list[i];
      if (tmp -> type == WLAtom &&
#else
      if (context -> list[i] -> type == WLAtom &&
#endif
	    (!((WOOL_Atom) context -> list[i]) -> c_val)) 
	    /*
	     * if atom is undefined, take the following element of the list
	     * as a value of new context 
	     */
	    increase_reference(new -> list[i + 1] = context -> list[i + 1]);
	else
	    increase_reference(new -> list[i + 1] =
	    WOOL_send(WOOL_eval, context -> list[i], (context -> list[i])));
    }
    return (WOOL_OBJECT) new;
}

WOOL_OBJECT
wool_context_restore(context)
WOOL_List	context;
{
    int             i;

    must_be_context(context, 0);
    for (i = 0; i < context -> size; i += 2)
	WOOL_send(WOOL_setq, context -> list[i],
		  (context -> list[i], context -> list[i + 1]));
    return (WOOL_OBJECT) context;
}

/*
 * wool_getenv:
 * makes the WOOL_String out of getenv(wool_string)
 */

WOOL_OBJECT
wool_getenv(obj)
WOOL_String obj;
{
    char  *result;

    if (result = (char *) getenv(obj -> string))
	return (WOOL_OBJECT) WLString_make(result);
    else
	return (WOOL_OBJECT) NIL_STRING;
}

/*
 * makes an atom out of a string
 */

WOOL_OBJECT
wool_atom_of_string(s)
WOOL_String	s;
{
    return (WOOL_OBJECT) wool_atom(s -> string);
}

/*
 * if object is from type, ok.
 * if not, evaluates it and call wool_error if result is still not
 * YOU MUST check reference on result when no longer needed!
 */

WOOL_OBJECT
wool_type_or_evaluate(object, type)
WOOL_OBJECT object;
WOOL_TYPE   type;
{
    if ((object == NIL) || (object -> type == type))
	return object;
    if (((object = WOOL_send(WOOL_eval, object, (object))) -> type == type)
	|| (object == NIL))
	return object;
    if (object == UNDEFINED_WOOL_VALUE)
	return wool_error(UNDEFINED_VARIABLE, "");
    return bad_argument(object, 0, WOOL_TYPE_P_NAME(type));
}

wool_user_end()
{
    wool_puts("Bye.\n");
    wool_end(0);
}

#ifdef DEBUG 			/* some routines convenient for debugging: */

stop_if_in_dbx(){} /* used in dbx */

int		dbxi = 0; 
WOOL_Atom 	dbxa;
WOOL_OBJECT 	dbxo;

PO(n)
int n;
{
    wool_print(n);
    wool_newline();
    fflush(stdout);
}

/*
 * break function for gwm for debugging purposes
 */

WOOL_OBJECT
wool_break(){return NIL;}	/* WOOL user break! */

WOOL_OBJECT
wp(obj)
WOOL_OBJECT     obj;
{
    wool_print_level = 0;
    WOOL_send(WOOL_print, obj, (obj));
    wool_newline();
    yyoutflush();
}

/*
 * type(obj) prints its type (under dbx!)
 */

wt(obj)
WOOL_OBJECT obj;
{
    printf("%s\n", ((WOOL_Atom) obj -> type[0]) -> p_name);
}

char *
type(obj)
WOOL_OBJECT obj;
{
    return ((WOOL_Atom) obj -> type[0]) -> p_name;
}


WOOL_OBJECT
wool_print_newline(obj)
WOOL_OBJECT     obj;
{
    WOOL_send(WOOL_print, obj, (obj));
    putchar('\n');
    return obj;
}

struct _UniqId {
    int size;
    int last;
    int *list;
};

int
UniqId(UI, n)
struct _UniqId *UI;
int n;
{
    int i;
    if (!UI->size) {
	UI->size = 4000;
	UI->list = (int *) Malloc(UI->size);
    }
    for (i=0; i< UI->last; i++) {
	if (UI->list[i] == n) {
	    return i;
	}
    }
    UI->list[i] = n;
    return (UI->last)++;
}

/* checksum on jump-buffers */

int
jmpbuf_checksum(jmpbuf)
int *jmpbuf;
{
    int i, result = 0;
    static struct _UniqId UI;
    for(i=0; i < sizeof(jmp_buf)/sizeof(int); i++)
	result = (result << 3) + (result >> 28) + jmpbuf[i];
    return UniqId(&UI, result);
}

#endif /* DEBUG */

WOOL_OBJECT
wool_type(obj)
WOOL_OBJECT obj;
{
    return (WOOL_OBJECT) obj->type[0];
}

wool_print_type(obj)
WOOL_OBJECT obj;
{
    WLAtom_print(obj -> type[0]);
}

#ifdef MONITOR
WOOL_OBJECT
wool_moncontrol(num)
WOOL_Number	num;
{
    moncontrol(num ->number);
}
#endif /* MONITOR */

/* tracing info
 */

WOOL_OBJECT
wool_get_trace()
{
    return (WOOL_OBJECT) WLNumber_make(wool_tracing_on);
}

/* (trace obj)
 * obj = expr, evals expr at each eval of list
 * obj = 0/1 turns tracing on/off (without resetting expr)
 * obj = t resets expr
 */

WOOL_OBJECT
wool_set_trace(obj)
WOOL_OBJECT obj;
{

    if(obj -> type == WLNumber) {
	wool_tracing_on = ((WOOL_Number) obj) -> number;
    } else if(obj == NIL) {
	wool_tracing_on = 0;
    } else {
	wool_tracing_on = 1;
	decrease_reference(wool_tracing_on_EXPR);
	if (obj == TRU)
	    wool_tracing_on_EXPR = 0;
	else
	    increase_reference(wool_tracing_on_EXPR = obj);
    }
    wool_still_tracing = wool_tracing_on;
    return obj;
}

/***************************************************************************\
* 									    *
* add .:$HOME:$HOME/gwm: before built-in-path (INSTALL_DIR) and returns it  *
* (malloced)								    *
* 									    *
\***************************************************************************/

char *
wool_fix_path(built_in_path)
char *built_in_path;
{
    char           *home = (char *) getenv("HOME");
    char           *path =
    Malloc(strlen(built_in_path) + 9 + 2*(home ? strlen(home) : 0));

    strcpy(path, ".:");
    if (home) {
	strcat(path, home);
	strcat(path, ":");
	strcat(path, home);
	strcat(path, "/");
	strcat(path, WOOL_APP_name);
	strcat(path, ":");
    }
    strcat(path, built_in_path);
    return path;
}

/****************************************\
* 					 *
*  INITIALISATION:			 *
*  to be called before everything else 	 *
* 					 *
\****************************************/

/*
 * wool_init returns 0 if all is ok
 * It calls its parameter function if not NULL, just before reading user
 * profile. Used by GWM for setting default keywords
 */

int
wool_init(client_initialisation)
int	(*client_initialisation)();
{
    /* initialize tables */
    zrt_init();
    dft_init();
    WLNumber_init();
    HashTable_init();

    /* initialize signals */
    SignalsInit();

    /* initialize wool's objects */

    wool_atom_make(WOOL_OBJECT, NIL, "()", NIL);	/* atoms */
    increase_reference(wool_atom("nil") -> c_val = NIL);
    wool_atom_make(WOOL_OBJECT, TRU, "t", TRU);
    NIL_STRING_make();
    WA_progn = (WOOL_OBJECT) wool_atom("progn");

    /* init stack */
    WLStackFrame_init();
    calling_function_init();

    /* intitialise predefined functions (Subrs) */
    QUOTE = wool_subr_make(WLFSubr, wool_quote, "quote", 1);
    wool_subr_make(WLFSubr, setq, "setq", 2);
    wool_subr_make(WLFSubr, setq, ":", 2);
    wool_subr_make(WLSubr, set, "set", 2);
    wool_subr_make(WLSubr, wool_multiply, "*", 2);
    wool_subr_make(WLSubr, wool_divide, "/", 2);
    wool_subr_make(WLSubr, wool_modulo, "%", 2);
    wool_subr_make(WLSubr, wool_add, "+", NARY);
    wool_subr_make(WLSubr, wool_minus, "-", NARY);
    increase_reference(wool_atom("defun") -> c_val =
		       wool_subr_make(WLFSubr, de, "de", NARY));
    increase_reference(wool_atom("defunq") -> c_val =
		       wool_subr_make(WLFSubr, df, "df", NARY));
    wool_subr_make(WLFSubr, wool_lambda_make, "lambda", NARY);
    wool_subr_make(WLFSubr, wool_lambdaq_make, "lambdaq", NARY);
    wool_subr_make(WLSubr, wool_atom_of_string, "atom", 1);
    wool_subr_make(WLFSubr, progn, "progn", NARY);
    wool_subr_make(WLFSubr, wool_if, "if", NARY);
    wool_subr_make(WLFSubr, wool_cond, "cond", NARY);
    increase_reference(wool_atom("equal") -> c_val =
		       wool_subr_make(WLSubr, wool_equal, "=", 2));
    wool_subr_make(WLSubr, wool_eq, "eq", 2);
    wool_subr_make(WLSubr, greater_than, ">", 2);
    wool_subr_make(WLSubr, lesser_than, "<", 2);
    wool_subr_make(WLSubr, wool_compare, "compare", 2);
    wool_subr_make(WLSubr, shell, "!", NARY);
    increase_reference(wool_atom("print") -> c_val =
		       wool_subr_make(WLSubr, wool_print_nary, "?", NARY));
    wool_subr_make(WLFSubr, wool_with_output_to_string,
                   "with-output-to-string", NARY);
    wool_subr_make(WLFSubr, wool_with_output_to_file,
                   "with-output-to-file", NARY);
    wool_subr_make(WLSubr, not, "not", 1);
    wool_subr_make(WLFSubr, and, "and", NARY);
    wool_subr_make(WLFSubr, or, "or", NARY);
    increase_reference(wool_atom("together") -> c_val =
	       wool_subr_make(WLSubr, wool_bitwise_or, "bitwise-or", NARY));
    wool_subr_make(WLSubr, wool_bitwise_and, "bitwise-and", NARY);
    wool_subr_make(WLSubr, wool_bitwise_xor, "bitwise-xor", NARY);
    wool_subr_make(WLFSubr, wool_while, "while", NARY);
    wool_subr_make(WLFSubr, wool_for, "for", NARY);
    wool_subr_make(WLFSubr, wool_mapfor, "mapfor", NARY);
    wool_subr_make(WLFSubr, wool_with, "with", NARY);
    wool_subr_make(WLFSubr, wool_with_eval, "with-eval", NARY);
    wool_subr_make(WLSubr, wool_context_save, "context-save", 1);
    wool_subr_make(WLSubr, wool_context_restore, "context-restore", 1);
    wool_subr_make(WLSubr, wool_loadfile_in_path, "load", 1);
    wool_subr_make(WLSubr, wool_execute_wool_string, "execute-string", 1);
    wool_subr_make(WLSubr, eval, "eval", 1);
    wool_subr_make(WLSubr, wool_getenv, "getenv", 1);
    wool_subr_make(WLSubr, wool_unbind, "unbind", 1);
    wool_subr_make(WLSubr, wool_boundp, "boundp", 1);
    wool_subr_make(WLSubr, WLString_match, "match", NARY);
    wool_subr_make(WLSubr, wool_length, "length", 1);
    wool_subr_make(WLSubr, WLList_sub, "sublist", NARY);
    increase_reference(wool_atom("nth") -> c_val =
		       wool_subr_make(WLSubr, WLList_nth, "#", NARY));
    increase_reference(wool_atom("replace-nth") -> c_val =
		    wool_subr_make(WLSubr, WLList_replace_nth, "##", NARY));
    wool_subr_make(WLSubr, WLList_delete_nth, "delete-nth", 2);
    wool_subr_make(WLFSubr, wool_user_end, "end", 0);
    wool_subr_make(WLSubr, wool_atoi, "atoi", 1);
    wool_subr_make(WLSubr, wool_itoa, "itoa", 1);
    wool_subr_make(WLSubr, wool_hack, "hack", 2);
    wool_subr_make(WLSubr, wool_list, "list", NARY);
    wool_subr_make(WLFSubr, wool_tag, "tag", NARY);
    wool_subr_make(WLFSubr, wool_exit, "exit", NARY);
    wool_subr_make(WLSubr, wool_type, "type", 1);
    wool_subr_make(WLFSubr, wool_error_has_occurred, "error-occurred", NARY);
    wool_subr_make(WLSubr, wool_trigger_error, "trigger-error", NARY);
    wool_subr_make(WLSubr, wool_copy, "copy", 1);
    wool_subr_make(WLSubr, wool_used_time, "elapsed-time", 0);
    wool_subr_make(WLSubr, wool_member, "member", 2);
    wool_subr_make(WLSubr, WLNamespace_make, "namespace-make", 0);
    wool_subr_make(WLSubr, WLNamespace_add, "namespace-add", 1);
    wool_subr_make(WLSubr, WLNamespace_remove, "namespace-remove", 2);
    wool_subr_make(WLSubr, WLName_add, "defname", NARY);
    wool_subr_make(WLSubr, WLNamespace_set_current, "namespace", 2);
    wool_subr_make(WLSubr, WLName_namespace, "namespace-of", 1);
    wool_subr_make(WLSubr, WLNamespace_size, "namespace-size", 1);
    wool_subr_make(WLSubr, WLList_qsort, "sort", 2);
    wool_active_make("hostname", wool_hostname_get, NULL);

    /* --- */
#ifdef STATS
    wool_subr_make(WLFSubr, zrtstats, "gcinfo", 0);
    wool_subr_make(WLFSubr, wlcfstats, "wlcfinfo", 0);
    wool_subr_make(WLFSubr, WlMstats, "meminfo", 0);
    wool_subr_make(WLFSubr, hashstats, "hashinfo", 0);
    wool_subr_make(WLFSubr, oblist, "oblist", 0);
#else /* STATS */
    wool_subr_make(WLFSubr, NIL_FUNC, "gcinfo", 0);
    wool_subr_make(WLFSubr, NIL_FUNC, "wlcfinfo", 0);
    wool_subr_make(WLFSubr, NIL_FUNC, "meminfo", 0);
    wool_subr_make(WLFSubr, NIL_FUNC, "hashinfo", 0);
    wool_subr_make(WLFSubr, NIL_FUNC, "oblist", 0);
#endif /* STATS */
#ifdef DEBUG
    wool_subr_make(WLFSubr, wool_break, "break", 0);
#ifdef GWM
    wool_subr_make(WLSubr, WLFsm_fp, "print-fsm", 1);
    wool_subr_make(WLSubr, WLState_fp, "print-state", 1);
    wool_subr_make(WLSubr, WLArc_fp, "print-arc", 1);
#endif
#else /* DEBUG */
    wool_subr_make(WLFSubr, NIL_FUNC, "break", 0);
#endif /* DEBUG */
#ifdef MONITOR
    wool_subr_make(WLSubr, wool_moncontrol, "moncontrol", 1);
#endif /* MONITOR */
#ifdef USER_DEBUG
    wool_active_make("trace", wool_get_trace, wool_set_trace);
    wool_pointer_make("trace-level", &wool_tracing_level);
#endif /* USER_DEBUG */

    wool_pointer_make("print-level", &wool_max_print_level);
    wool_pointer_make("stack-print-level", &wool_max_stack_print_level);

    /* here do client inits before the profile is read */
    if (client_initialisation)
	(*client_initialisation) ();

    /* first time, load the user file */
    wool_error_status = 0;
    if (!set_wool_error_resume_point()) {
	zrt_gc(0);
	if (wool_loadfile_in_path(wool_atom(wool_user_profile_name)) == NIL) {
	    return 1;
	}
    }
    wlcf_flush();
    wool_error_in_profile = wool_error_status;
    set_wool_error_resume_point();
    dft_gc();

    return 0;
}