File: tops20.c

package info (click to toggle)
unzip 5.32-1
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 3,616 kB
  • ctags: 5,353
  • sloc: ansic: 35,010; cpp: 3,775; makefile: 1,269; asm: 1,113; sh: 133
file content (308 lines) | stat: -rw-r--r-- 6,844 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
/*---------------------------------------------------------------------------

  tops20.c

  TOPS20-specific routines for use with Info-ZIP's UnZip 5.1 and later.

  Contains:  mapattr()
             close_outfile()
             version()
             upper()
             enquote()
             dequote()
             fnlegal()

  (not yet ported:  do_wild(), mapname(), checkdir(), ...)

  ---------------------------------------------------------------------------*/


#define UNZIP_INTERNAL
#include "unzip.h"


/**********************/
/* Function mapattr() */
/**********************/

int mapattr(__G)        /* just like Unix except no umask() */
    __GDEF
{
    ulg  tmp = G.crec.external_file_attributes;

    switch (G.pInfo->hostnum) {
        case UNIX_:
        case VMS_:
        case ACORN_:
        case ATARI_:
        case BEOS_:
        case QDOS_:
            G.pInfo->file_attr = (unsigned)(tmp >> 16);
            break;
        case AMIGA_:
            tmp = (unsigned)(tmp>>1 & 7);   /* Amiga RWE bits */
            G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
            break;
        case FS_FAT_:   /* MSDOS half of attributes should always be correct */
        case FS_HPFS_:
        case FS_NTFS_:
        case MAC_:
        case TOPS20_:
        default:
            tmp = !(tmp & 1) << 1;   /* read-only bit --> write perms bits */
            G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
            break;
#if 0
        case ATARI_:
        case TOPS20_:
        default:
            G.pInfo->file_attr = 0666;
            break;
#endif
    } /* end switch (host-OS-created-by) */

    return 0;

} /* end function mapattr() */





/****************************/
/* Function close_outfile() */
/****************************/

void close_outfile(__G)
    __GDEF
{
#   define JSYS_CLASS           0070000000000
#   define FLD(val,mask)        (((unsigned)(val)*((mask)&(-(mask))))&(mask))
#   define _DEFJS(name,class)   (FLD(class,JSYS_CLASS) | (monsym(name)&0777777))
#   define IDTIM                _DEFJS("IDTIM%", 1)
#   define SFTAD                _DEFJS("SFTAD%", 0)
#   define YRBASE               1900
    int ablock[5], tblock[2];
    int yr, mo, dy, hh, mm, ss;
    char temp[100];
    unsigned tad;
#ifdef USE_EF_UT_TIME
    iztimes z_utime;


    if (G.extra_field &&
        (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
                          G.lrec.last_mod_file_date, &z_utime, NULL)
         & EB_UT_FL_MTIME))
    {
        struct tm *t = localtime(&(z_utime.mtime));

        yr = t->tm_year + 1900;
        mo = t->tm_mon;
        dy = t->tm_mday;
        hh = t->tm_hour;
        mm = t->tm_min;
        ss = t->tm_sec;
    }
    else
    {
        /* dissect the date */
        yr = ((G.lrec.last_mod_file_date >> 9) & 0x7f) + 1980;
        mo = ((G.lrec.last_mod_file_date >> 5) & 0x0f) - 1;
        dy = (G.lrec.last_mod_file_date & 0x1f);

        /* dissect the time */
        hh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
        mm = (G.lrec.last_mod_file_time >> 5) & 0x3f;
        ss = (G.lrec.last_mod_file_time & 0x1f) * 2;
    }
#else /* !USE_EF_UT_TIME */

    /* dissect the date */
    yr = ((G.lrec.last_mod_file_date >> 9) & 0x7f) + (1980 - YRBASE);
    mo = (G.lrec.last_mod_file_date >> 5) & 0x0f;
    dy = G.lrec.last_mod_file_date & 0x1f;

    /* dissect the time */
    hh = (G.lrec.last_mod_file_time >> 11) & 0x1f;
    mm = (G.lrec.last_mod_file_time >> 5) & 0x3f;
    ss = (G.lrec.last_mod_file_time & 0x1f) * 2;
#endif /* ?USE_EF_UT_TIME */

    sprintf(temp, "%02d/%02d/%02d %02d:%02d:%02d", mo, dy, yr, hh, mm, ss);

    ablock[1] = (int)(temp - 1);
    ablock[2] = 0;
    if (!jsys(IDTIM, ablock)) {
        Info(slide, 1, ((char *)slide, "error:  IDTIM failure for %s\n",
          G.filename));
        fclose(G.outfile);
        return;
    }

    tad = ablock[2];
    tblock[0] = tad;
    tblock[1] = tad;
    tblock[2] = -1;

    ablock[1] = fcntl(fileno(G.outfile), F_GETSYSFD, 0);
                                                /* _uffd[outfd]->uf_ch */
    ablock[2] = (int) tblock;
    ablock[3] = 3;
    if (!jsys(SFTAD, ablock))
        Info(slide, 1,((char *)slide, "error:  cannot set the time for %s\n",
          G.filename));

    fclose(G.outfile);

} /* end function close_outfile() */





#ifndef SFX

/************************/
/*  Function version()  */
/************************/

void version(__G)
    __GDEF
{
#if 0
    char buf[40];
#endif

    sprintf((char *)slide, LoadFarString(CompiledWith),

#ifdef __GNUC__
      "gcc ", __VERSION__,
#else
#  if 0
      "cc ", (sprintf(buf, " version %d", _RELEASE), buf),
#  else
#  ifdef __COMPILER_KCC__
      "KCC", "",
#  else
      "unknown compiler", "",
#  endif
#  endif
#endif

      "TOPS-20",

#if defined(foobar) || defined(FOOBAR)
      " (Foo BAR)",   /* OS version or hardware */
#else
      "",
#endif /* Foo BAR */

#ifdef __DATE__
      " on ", __DATE__
#else
      "", ""
#endif
    );

    (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);

} /* end function version() */

#endif /* !SFX */





/**********************/
/*  Function upper()  */
/**********************/

int upper(s)        /* returns s in uppercase */
    char *s;        /* string to be uppercased */
{
    for (;  *s;  ++s)
        *s = toupper(*s);
}





/************************/
/*  Function enquote()  */
/************************/

int enquote(s)      /* calls dequote(s) to normalize string, then */
    char *s;        /*  inserts ^Vs before otherwise illegal characters */
{                   /*  in s, assuming that s is a TOPS-20 filename */
    char d[100];
    char *p, *q;
    char c;

    if (s && *s) {
        dequote(s);
        p = s - 1;
        q = d - 1;
        while (c = *++p) {
            if (!fnlegal(c))
                *++q = '\026';
            *++q = c;
        }
        *++q = '\0';
        strcpy(s, d);
    }
    return 0;
}





/************************/
/*  Function dequote()  */
/************************/

int dequote(s)        /* returns s without ^Vs */
    char *s;          /* string to be dequoted */
{
    char d[100];
    char *p, *q;
    int c;

    if (s && *s) {
        p = s - 1;
        q = d - 1;
        while (c = *++p)
            if (c != '\026')
                *++q = c;
        *++q = '\0';
        strcpy(s, d);
    }
    return 0;
}





/************************/
/*  Function fnlegal()  */
/************************/

int fnlegal(c)         /* returns TRUE if c is a member of the */
    char c;            /*  legal character set for filenames */
{
    char *q;
    static char *legals = {"$%**-<>>AZ[[]]__az"};

    q = legals;
    while (*q)
        if (c < *q++)
            break;
        else if (c <= *q++)
            return TRUE;

    return FALSE;
}