1 /*
2 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
3
4 See the accompanying file LICENSE, version 2000-Apr-09 or later
5 (the contents of which are also included in unzip.h) for terms of use.
6 If, for some reason, all these files are missing, the Info-ZIP license
7 also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
8 */
9 /*---------------------------------------------------------------------------
10
11 globalsf.c
12 *** This is only needed to build funzip correctly and is a direct copy
13 of globals.c. Don't forget to update here if you update globals.c!! ***
14
15 ---------------------------------------------------------------------------*/
16
17
18 #define FUNZIP
19 #define UNZIP_INTERNAL
20 #include "unzip.h"
21
22 #ifndef FUNZIP
23 /* initialization of sigs is completed at runtime so unzip(sfx) executable
24 * won't look like a zipfile
25 */
26 char central_hdr_sig[4] = {0, 0, 0x01, 0x02};
27 char local_hdr_sig[4] = {0, 0, 0x03, 0x04};
28 char end_central_sig[4] = {0, 0, 0x05, 0x06};
29 /* extern char extd_local_sig[4] = {0, 0, 0x07, 0x08}; NOT USED YET */
30
31 ZCONST char *fnames[2] = {"*", NULL}; /* default filenames vector */
32 #endif
33
34
35 #ifndef REENTRANT
36 Uz_Globs G;
37 #else /* REENTRANT */
38
39 # ifndef USETHREADID
40 Uz_Globs *GG;
41 # else /* USETHREADID */
42 # define THREADID_ENTRIES 0x40
43
44 int lastScan;
45 Uz_Globs *threadPtrTable[THREADID_ENTRIES];
46 ulg threadIdTable [THREADID_ENTRIES] = {
47 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
48 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* Make sure there are */
49 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* THREADID_ENTRIES 0s */
50 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
51 };
52
53 static ZCONST char Far TooManyThreads[] =
54 "error: more than %d simultaneous threads.\n\
55 Some threads are probably not calling DESTROYTHREAD()\n";
56 static ZCONST char Far EntryNotFound[] =
57 "error: couldn't find global pointer in table.\n\
58 Maybe somebody accidentally called DESTROYTHREAD() twice.\n";
59 static ZCONST char Far GlobalPointerMismatch[] =
60 "error: global pointer in table does not match pointer passed as\
61 parameter\n";
62
63 static void registerGlobalPointer OF((__GPRO));
64
65
66
registerGlobalPointer(__G)67 static void registerGlobalPointer(__G)
68 __GDEF
69 {
70 int scan=0;
71 ulg tid = GetThreadId();
72
73 while (threadIdTable[scan] && scan < THREADID_ENTRIES)
74 scan++;
75
76 if (scan == THREADID_ENTRIES) {
77 ZCONST char *tooMany = LoadFarString(TooManyThreads);
78 Info(slide, 0x421, ((char *)slide, tooMany, THREADID_ENTRIES));
79 free(pG);
80 EXIT(PK_MEM); /* essentially memory error before we've started */
81 }
82
83 threadIdTable [scan] = tid;
84 threadPtrTable[scan] = pG;
85 lastScan = scan;
86 }
87
88
89
deregisterGlobalPointer(__G)90 void deregisterGlobalPointer(__G)
91 __GDEF
92 {
93 int scan=0;
94 ulg tid = GetThreadId();
95
96
97 while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
98 scan++;
99
100 /*---------------------------------------------------------------------------
101 There are two things we can do if we can't find the entry: ignore it or
102 scream. The most likely reason for it not to be here is the user calling
103 this routine twice. Since this could cause BIG problems if any globals
104 are accessed after the first call, we'd better scream.
105 ---------------------------------------------------------------------------*/
106
107 if (scan == THREADID_ENTRIES || threadPtrTable[scan] != pG) {
108 ZCONST char *noEntry;
109 if (scan == THREADID_ENTRIES)
110 noEntry = LoadFarString(EntryNotFound);
111 else
112 noEntry = LoadFarString(GlobalPointerMismatch);
113 Info(slide, 0x421, ((char *)slide, noEntry));
114 EXIT(PK_WARN); /* programming error, but after we're all done */
115 }
116
117 threadIdTable [scan] = 0;
118 lastScan = scan;
119 free(threadPtrTable[scan]);
120 }
121
122
123
getGlobalPointer()124 Uz_Globs *getGlobalPointer()
125 {
126 int scan=0;
127 ulg tid = GetThreadId();
128
129 while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
130 scan++;
131
132 /*---------------------------------------------------------------------------
133 There are two things we can do if we can't find the entry: ignore it or
134 scream. The most likely reason for it not to be here is the user calling
135 this routine twice. Since this could cause BIG problems if any globals
136 are accessed after the first call, we'd better scream.
137 ---------------------------------------------------------------------------*/
138
139 if (scan == THREADID_ENTRIES) {
140 ZCONST char *noEntry = LoadFarString(EntryNotFound);
141 fprintf(stderr, noEntry); /* can't use Info w/o a global pointer */
142 EXIT(PK_ERR); /* programming error while still working */
143 }
144
145 return threadPtrTable[scan];
146 }
147
148 # endif /* ?USETHREADID */
149 #endif /* ?REENTRANT */
150
151
152
globalsCtor()153 Uz_Globs *globalsCtor()
154 {
155 #ifdef REENTRANT
156 Uz_Globs *pG = (Uz_Globs *)malloc(sizeof(Uz_Globs));
157
158 if (!pG)
159 return (Uz_Globs *)NULL;
160 #endif /* REENTRANT */
161
162 /* for REENTRANT version, G is defined as (*pG) */
163
164 memzero(&G, sizeof(Uz_Globs));
165
166 #ifndef FUNZIP
167 #ifdef CMS_MVS
168 uO.aflag=1;
169 uO.C_flag=1;
170 #endif
171 #ifdef TANDEM
172 uO.aflag=1; /* default to '-a' auto create Text Files as type 101 */
173 #endif
174
175 uO.lflag=(-1);
176 G.wildzipfn = "";
177 G.pfnames = (char **)fnames;
178 G.pxnames = (char **)&fnames[1];
179 G.pInfo = G.info;
180 G.sol = TRUE; /* at start of line */
181
182 G.message = UzpMessagePrnt;
183 G.input = UzpInput; /* not used by anyone at the moment... */
184 #if defined(WINDLL) || defined(MACOS)
185 G.mpause = NULL; /* has scrollbars: no need for pausing */
186 #else
187 G.mpause = UzpMorePause;
188 #endif
189 G.decr_passwd = UzpPassword;
190 #endif /* !FUNZIP */
191
192 #if (!defined(DOS_FLX_H68_NLM_OS2_W32) && !defined(AMIGA) && !defined(RISCOS))
193 #if (!defined(MACOS) && !defined(ATARI) && !defined(VMS))
194 G.echofd = -1;
195 #endif /* !(MACOS || ATARI || VMS) */
196 #endif /* !(DOS_FLX_H68_NLM_OS2_W32 || AMIGA || RISCOS) */
197
198 #ifdef SYSTEM_SPECIFIC_CTOR
199 SYSTEM_SPECIFIC_CTOR(__G);
200 #endif
201
202 #ifdef REENTRANT
203 #ifdef USETHREADID
204 registerGlobalPointer(__G);
205 #else
206 GG = &G;
207 #endif /* ?USETHREADID */
208 #endif /* REENTRANT */
209
210 return &G;
211 }
212