1 /*---------------------------------------------------------------------------
5 Routines to allocate and initialize globals, with or without threads.
7 Contents: registerGlobalPointer()
8 deregisterGlobalPointer()
12 ---------------------------------------------------------------------------*/
15 #define UNZIP_INTERNAL
19 /* initialization of sigs is completed at runtime so unzip(sfx) executable
20 * won't look like a zipfile
22 char central_hdr_sig
[4] = {0, 0, 0x01, 0x02};
23 char local_hdr_sig
[4] = {0, 0, 0x03, 0x04};
24 char end_central_sig
[4] = {0, 0, 0x05, 0x06};
25 /* extern char extd_local_sig[4] = {0, 0, 0x07, 0x08}; NOT USED YET */
27 ZCONST
char *fnames
[2] = {"*", NULL
}; /* default filenames vector */
37 # else /* USETHREADID */
38 # define THREADID_ENTRIES 0x40
41 Uz_Globs
*threadPtrTable
[THREADID_ENTRIES
];
42 ulg threadIdTable
[THREADID_ENTRIES
] = {
43 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
44 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* Make sure there are */
45 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* THREADID_ENTRIES 0s */
46 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
49 static ZCONST
char Far TooManyThreads
[] =
50 "error: more than %d simultaneous threads.\n\
51 Some threads are probably not calling DESTROYTHREAD()\n";
52 static ZCONST
char Far EntryNotFound
[] =
53 "error: couldn't find global pointer in table.\n\
54 Maybe somebody accidentally called DESTROYTHREAD() twice.\n";
55 static ZCONST
char Far GlobalPointerMismatch
[] =
56 "error: global pointer in table does not match pointer passed as\
59 static void registerGlobalPointer
OF((__GPRO
));
63 static void registerGlobalPointer(__G
)
67 ulg tid
= GetThreadId();
69 while (threadIdTable
[scan
] && scan
< THREADID_ENTRIES
)
72 if (scan
== THREADID_ENTRIES
) {
73 ZCONST
char *tooMany
= LoadFarString(TooManyThreads
);
74 Info(slide
, 0x421, ((char *)slide
, tooMany
, THREADID_ENTRIES
));
76 EXIT(PK_MEM
); /* essentially memory error before we've started */
79 threadIdTable
[scan
] = tid
;
80 threadPtrTable
[scan
] = pG
;
86 void deregisterGlobalPointer(__G
)
90 ulg tid
= GetThreadId();
93 while (threadIdTable
[scan
] != tid
&& scan
< THREADID_ENTRIES
)
96 /*---------------------------------------------------------------------------
97 There are two things we can do if we can't find the entry: ignore it or
98 scream. The most likely reason for it not to be here is the user calling
99 this routine twice. Since this could cause BIG problems if any globals
100 are accessed after the first call, we'd better scream.
101 ---------------------------------------------------------------------------*/
103 if (scan
== THREADID_ENTRIES
|| threadPtrTable
[scan
] != pG
) {
104 ZCONST
char *noEntry
;
105 if (scan
== THREADID_ENTRIES
)
106 noEntry
= LoadFarString(EntryNotFound
);
108 noEntry
= LoadFarString(GlobalPointerMismatch
);
109 Info(slide
, 0x421, ((char *)slide
, noEntry
));
110 EXIT(PK_WARN
); /* programming error, but after we're all done */
113 threadIdTable
[scan
] = 0;
115 free(threadPtrTable
[scan
]);
120 Uz_Globs
*getGlobalPointer()
123 ulg tid
= GetThreadId();
125 while (threadIdTable
[scan
] != tid
&& scan
< THREADID_ENTRIES
)
128 /*---------------------------------------------------------------------------
129 There are two things we can do if we can't find the entry: ignore it or
130 scream. The most likely reason for it not to be here is the user calling
131 this routine twice. Since this could cause BIG problems if any globals
132 are accessed after the first call, we'd better scream.
133 ---------------------------------------------------------------------------*/
135 if (scan
== THREADID_ENTRIES
) {
136 ZCONST
char *noEntry
= LoadFarString(EntryNotFound
);
137 fprintf(stderr
, noEntry
); /* can't use Info w/o a global pointer */
138 EXIT(PK_ERR
); /* programming error while still working */
141 return threadPtrTable
[scan
];
144 # endif /* ?USETHREADID */
145 #endif /* ?REENTRANT */
149 Uz_Globs
*globalsCtor()
152 Uz_Globs
*pG
= (Uz_Globs
*)malloc(sizeof(Uz_Globs
));
155 return (Uz_Globs
*)NULL
;
156 #endif /* REENTRANT */
158 /* for REENTRANT version, G is defined as (*pG) */
160 memzero(&G
, sizeof(Uz_Globs
));
170 G
.pfnames
= (char **)fnames
;
171 G
.pxnames
= (char **)&fnames
[1];
173 G
.sol
= TRUE
; /* at start of line */
175 G
.message
= UzpMessagePrnt
;
176 G
.input
= UzpInput
; /* not used by anyone at the moment... */
177 #if defined(WINDLL) || defined(MACOS)
178 G
.mpause
= NULL
; /* has scrollbars: no need for pausing */
180 G
.mpause
= UzpMorePause
;
182 G
.decr_passwd
= UzpPassword
;
185 #if (!defined(DOS_FLX_H68_OS2_W32) && !defined(AMIGA) && !defined(RISCOS))
186 #if (!defined(MACOS) && !defined(ATARI) && !defined(VMS))
188 #endif /* !(MACOS || ATARI || VMS) */
189 #endif /* !(DOS_FLX_H68_OS2_W32 || AMIGA || RISCOS) */
191 #ifdef SYSTEM_SPECIFIC_CTOR
192 SYSTEM_SPECIFIC_CTOR(__G
);
197 registerGlobalPointer(__G
);
200 #endif /* ?USETHREADID */
201 #endif /* REENTRANT */