~ubuntu-branches/ubuntu/intrepid/unzip/intrepid

« back to all changes in this revision

Viewing changes to tops20/tops20.c

  • Committer: Bazaar Package Importer
  • Author(s): Santiago Vila
  • Date: 2004-06-06 17:57:46 UTC
  • Revision ID: james.westby@ubuntu.com-20040606175746-nl7p2dgp3aobyc2c
Tags: upstream-5.51
ImportĀ upstreamĀ versionĀ 5.51

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
  tops20.c
 
12
 
 
13
  TOPS20-specific routines for use with Info-ZIP's UnZip 5.1 and later.
 
14
 
 
15
  Contains:  mapattr()
 
16
             close_outfile()
 
17
             version()
 
18
             upper()
 
19
             enquote()
 
20
             dequote()
 
21
             fnlegal()
 
22
 
 
23
  (not yet ported:  do_wild(), mapname(), checkdir(), ...)
 
24
 
 
25
  ---------------------------------------------------------------------------*/
 
26
 
 
27
 
 
28
#define UNZIP_INTERNAL
 
29
#include "unzip.h"
 
30
 
 
31
 
 
32
/**********************/
 
33
/* Function mapattr() */
 
34
/**********************/
 
35
 
 
36
int mapattr(__G)        /* just like Unix except no umask() */
 
37
    __GDEF
 
38
{
 
39
    ulg  tmp = G.crec.external_file_attributes;
 
40
 
 
41
    switch (G.pInfo->hostnum) {
 
42
        case UNIX_:
 
43
        case VMS_:
 
44
        case ACORN_:
 
45
        case ATARI_:
 
46
        case BEOS_:
 
47
        case QDOS_:
 
48
            G.pInfo->file_attr = (unsigned)(tmp >> 16);
 
49
            break;
 
50
        case AMIGA_:
 
51
            tmp = (unsigned)(tmp>>1 & 7);   /* Amiga RWE bits */
 
52
            G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
 
53
            break;
 
54
        case FS_FAT_:   /* MSDOS half of attributes should always be correct */
 
55
        case FS_HPFS_:
 
56
        case FS_NTFS_:
 
57
        case MAC_:
 
58
        case TOPS20_:
 
59
        default:
 
60
            tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
 
61
            G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
 
62
            break;
 
63
#if 0
 
64
        case ATARI_:
 
65
        case TOPS20_:
 
66
        default:
 
67
            G.pInfo->file_attr = 0666;
 
68
            break;
 
69
#endif
 
70
    } /* end switch (host-OS-created-by) */
 
71
 
 
72
    return 0;
 
73
 
 
74
} /* end function mapattr() */
 
75
 
 
76
 
 
77
 
 
78
 
 
79
 
 
80
/****************************/
 
81
/* Function close_outfile() */
 
82
/****************************/
 
83
 
 
84
void close_outfile(__G)
 
85
    __GDEF
 
86
{
 
87
#   define JSYS_CLASS           0070000000000
 
88
#   define FLD(val,mask)        (((unsigned)(val)*((mask)&(-(mask))))&(mask))
 
89
#   define _DEFJS(name,class)   (FLD(class,JSYS_CLASS) | (monsym(name)&0777777))
 
90
#   define IDTIM                _DEFJS("IDTIM%", 1)
 
91
#   define SFTAD                _DEFJS("SFTAD%", 0)
 
92
#   define YRBASE               1900
 
93
    int ablock[5], tblock[2];
 
94
    int yr, mo, dy, hh, mm, ss;
 
95
    char temp[100];
 
96
    unsigned tad;
 
97
#ifdef USE_EF_UT_TIME
 
98
    iztimes z_utime;
 
99
    struct tm *t;
 
100
 
 
101
 
 
102
    if (G.extra_field &&
 
103
#ifdef IZ_CHECK_TZ
 
104
        G.tz_is_valid &&
 
105
#endif
 
106
        (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
 
107
                          G.lrec.last_mod_dos_date, &z_utime, NULL)
 
108
         & EB_UT_FL_MTIME))
 
109
        t = localtime(&(z_utime.mtime));
 
110
    else
 
111
        t = (struct tm *)NULL;
 
112
 
 
113
    if (t != (struct tm *)NULL)
 
114
    {
 
115
        yr = t->tm_year + 1900;
 
116
        mo = t->tm_mon;
 
117
        dy = t->tm_mday;
 
118
        hh = t->tm_hour;
 
119
        mm = t->tm_min;
 
120
        ss = t->tm_sec;
 
121
    }
 
122
    else
 
123
    {
 
124
        /* dissect the date */
 
125
        yr = ((G.lrec.last_mod_dos_date >> 9) & 0x7f) + 1980;
 
126
        mo = ((G.lrec.last_mod_dos_date >> 5) & 0x0f) - 1;
 
127
        dy = (G.lrec.last_mod_dos_date & 0x1f);
 
128
 
 
129
        /* dissect the time */
 
130
        hh = (G.lrec.last_mod_dos_time >> 11) & 0x1f;
 
131
        mm = (G.lrec.last_mod_dos_time >> 5) & 0x3f;
 
132
        ss = (G.lrec.last_mod_dos_time & 0x1f) * 2;
 
133
    }
 
134
#else /* !USE_EF_UT_TIME */
 
135
 
 
136
    /* dissect the date */
 
137
    yr = ((G.lrec.last_mod_dos_datetime >> 25) & 0x7f) + (1980 - YRBASE);
 
138
    mo = (G.lrec.last_mod_dos_datetime >> 21) & 0x0f;
 
139
    dy = (G.lrec.last_mod_dos_datetime >> 16) & 0x1f;
 
140
 
 
141
    /* dissect the time */
 
142
    hh = (G.lrec.last_mod_dos_datetime >> 11) & 0x1f;
 
143
    mm = (G.lrec.last_mod_dos_datetime >> 5) & 0x3f;
 
144
    ss = (G.lrec.last_mod_dos_datetime << 1) & 0x1f;
 
145
#endif /* ?USE_EF_UT_TIME */
 
146
 
 
147
    sprintf(temp, "%02d/%02d/%02d %02d:%02d:%02d", mo, dy, yr, hh, mm, ss);
 
148
 
 
149
    ablock[1] = (int)(temp - 1);
 
150
    ablock[2] = 0;
 
151
    if (!jsys(IDTIM, ablock)) {
 
152
        Info(slide, 1, ((char *)slide, "error:  IDTIM failure for %s\n",
 
153
          G.filename));
 
154
        fclose(G.outfile);
 
155
        return;
 
156
    }
 
157
 
 
158
    tad = ablock[2];
 
159
    tblock[0] = tad;
 
160
    tblock[1] = tad;
 
161
    tblock[2] = -1;
 
162
 
 
163
    ablock[1] = fcntl(fileno(G.outfile), F_GETSYSFD, 0);
 
164
                                                /* _uffd[outfd]->uf_ch */
 
165
    ablock[2] = (int) tblock;
 
166
    ablock[3] = 3;
 
167
    if (!jsys(SFTAD, ablock))
 
168
        Info(slide, 1,((char *)slide, "error:  cannot set the time for %s\n",
 
169
          G.filename));
 
170
 
 
171
    fclose(G.outfile);
 
172
 
 
173
} /* end function close_outfile() */
 
174
 
 
175
 
 
176
 
 
177
 
 
178
 
 
179
#ifndef SFX
 
180
 
 
181
/************************/
 
182
/*  Function version()  */
 
183
/************************/
 
184
 
 
185
void version(__G)
 
186
    __GDEF
 
187
{
 
188
#if 0
 
189
    char buf[40];
 
190
#endif
 
191
 
 
192
    sprintf((char *)slide, LoadFarString(CompiledWith),
 
193
 
 
194
#ifdef __GNUC__
 
195
      "gcc ", __VERSION__,
 
196
#else
 
197
#  if 0
 
198
      "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
 
199
#  else
 
200
#  ifdef __COMPILER_KCC__
 
201
      "KCC", "",
 
202
#  else
 
203
      "unknown compiler", "",
 
204
#  endif
 
205
#  endif
 
206
#endif
 
207
 
 
208
      "TOPS-20",
 
209
 
 
210
#if defined(foobar) || defined(FOOBAR)
 
211
      " (Foo BAR)",   /* OS version or hardware */
 
212
#else
 
213
      "",
 
214
#endif /* Foo BAR */
 
215
 
 
216
#ifdef __DATE__
 
217
      " on ", __DATE__
 
218
#else
 
219
      "", ""
 
220
#endif
 
221
    );
 
222
 
 
223
    (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
 
224
 
 
225
} /* end function version() */
 
226
 
 
227
#endif /* !SFX */
 
228
 
 
229
 
 
230
 
 
231
 
 
232
 
 
233
/**********************/
 
234
/*  Function upper()  */
 
235
/**********************/
 
236
 
 
237
int upper(s)        /* returns s in uppercase */
 
238
    char *s;        /* string to be uppercased */
 
239
{
 
240
    for (;  *s;  ++s)
 
241
        *s = toupper(*s);
 
242
}
 
243
 
 
244
 
 
245
 
 
246
 
 
247
 
 
248
/************************/
 
249
/*  Function enquote()  */
 
250
/************************/
 
251
 
 
252
int enquote(s)      /* calls dequote(s) to normalize string, then */
 
253
    char *s;        /*  inserts ^Vs before otherwise illegal characters */
 
254
{                   /*  in s, assuming that s is a TOPS-20 filename */
 
255
    char d[100];
 
256
    char *p, *q;
 
257
    char c;
 
258
 
 
259
    if (s && *s) {
 
260
        dequote(s);
 
261
        p = s - 1;
 
262
        q = d - 1;
 
263
        while (c = *++p) {
 
264
            if (!fnlegal(c))
 
265
                *++q = '\026';
 
266
            *++q = c;
 
267
        }
 
268
        *++q = '\0';
 
269
        strcpy(s, d);
 
270
    }
 
271
    return 0;
 
272
}
 
273
 
 
274
 
 
275
 
 
276
 
 
277
 
 
278
/************************/
 
279
/*  Function dequote()  */
 
280
/************************/
 
281
 
 
282
int dequote(s)        /* returns s without ^Vs */
 
283
    char *s;          /* string to be dequoted */
 
284
{
 
285
    char d[100];
 
286
    char *p, *q;
 
287
    int c;
 
288
 
 
289
    if (s && *s) {
 
290
        p = s - 1;
 
291
        q = d - 1;
 
292
        while (c = *++p)
 
293
            if (c != '\026')
 
294
                *++q = c;
 
295
        *++q = '\0';
 
296
        strcpy(s, d);
 
297
    }
 
298
    return 0;
 
299
}
 
300
 
 
301
 
 
302
 
 
303
 
 
304
 
 
305
/************************/
 
306
/*  Function fnlegal()  */
 
307
/************************/
 
308
 
 
309
int fnlegal(c)         /* returns TRUE if c is a member of the */
 
310
    char c;            /*  legal character set for filenames */
 
311
{
 
312
    char *q;
 
313
    static char *legals = {"$%**-<>>AZ[[]]__az"};
 
314
 
 
315
    q = legals;
 
316
    while (*q)
 
317
        if (c < *q++)
 
318
            break;
 
319
        else if (c <= *q++)
 
320
            return TRUE;
 
321
 
 
322
    return FALSE;
 
323
}