?? qdos.c
字號:
/* Copyright (c) 1990-2002 Info-ZIP. All rights reserved. See the accompanying file LICENSE, version 2000-Apr-09 or later (the contents of which are also included in unzip.h) for terms of use. If, for some reason, these files are missing, the Info-ZIP license also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html*//*--------------------------------------------------------------------------- qdos.c QDOS-specific routines for use with Info-ZIP's UnZip 5.3 and later. Contains: Qstrfix() QFilename() QMatch() chowner() Qgetch() QReturn() LastDir() screensize() do_wild() <-- generic enough to put in file_io.c? mapattr() mapname() checkdir() qfix() close_outfile() stamp_file() getp() version() ---------------------------------------------------------------------------*/#define UNZIP_INTERNAL#include "unzip.h"#include "crypt.h"#include "ttyio.h"#include <dirent.h>#include "izqdos.h"#include "unzvers.h"#ifndef SFXchar _prog_name[] = "UnZip";#elsechar _prog_name[] = "??Special Flag for unzipsfx hack ??";#endif/* sorrid hack at request of GRR follows; hope the compiler stays kind to us */char _version[] = {UZ_MAJORVER+'0','.',UZ_MINORVER+'0',UZ_PATCHLEVEL+'0'};char _extra[] = " " UZ_BETALEVEL;char _copyright[] = "(c) Info-ZIP Group";char * _endmsg = NULL;long _stack = 16*1024; /* huge stack (for qdos) */extern void consetup_title(chanid_t,struct WINDOWDEF *);void (*_consetup)(chanid_t,struct WINDOWDEF *) = consetup_title;struct WINDOWDEF _condetails ={ 2, 1, 0, 7, 500, 220, 2, 30};static jobid_t chowner(chanid_t chan){ extern char *_sys_var; char *scht; long *cdb; long jid; scht = *((char **)(_sys_var + 0x78)); cdb = *(long **)((long *)scht + (chan & 0xffff)); jid = *(cdb + 2); return jid;}int QReturn(int err){ jobid_t me,you; me = getpid(); you = chowner(getchid(0)); if((me == you) && ((qlflag & 4) == 0)) { if(isatty(0) && isatty(2) && qlwait) { char c = 0; fputs("Press a key to exit", stderr); if((io_fbyte(getchid(0), qlwait, &c) == 0) && c == 27) { io_fbyte(getchid(0), -1, &c); } } } if(err > 0) err = -err; /* We like -ve err nos (exclusively, alas) */ exit(err);}#ifndef FUNZIPstatic int created_dir; /* used in mapname(), checkdir() */static int renamed_fullpath; /* ditto */char *Qstrfix (char *p){ char *q; for (q = p; (q = strstr(q, ".zip"));) { *q = '_'; q += 4; } return p;}void QFilename(char *f){ char *o,*p,*q = strdup(f); p = q; if(*q == '.' && *(q+1) == '/') q += 2; o = q; for(;*q;q++) { if(*q == '/') *q = '_'; if((qlflag & 1) == 0) { if(*q == '.') *q = '_'; } } strcpy(f,o); free(p);}int QMatch(uch c1, uch c2){ int m =0; if(c1 != c2) { if(c1 == '_' && (c2 == '.' || c2 == '/')) { m = 1; } } else { m = 1; } return m;}int Qgetch(void){ char ch; if(io_fbyte(getchid(0), -1, &ch) < 0) { return EOF; } else { return (int) ch; }}int screensize(int *tt_rows, int *tt_cols){ QLRECT_t rect; if(0 == sd_chenq(getchid(1), -1, &rect)) { if(tt_cols) *tt_cols = rect.q_width; if(tt_rows) *tt_rows = rect.q_height; } else { if(tt_cols) *tt_cols = 80; if(tt_rows) *tt_rows = 24; } return 0;}#ifndef SFXchar *LastDir(char *ws){ char *p; char *q = ws; struct stat s; for(p = ws; *p; p++) { if(*p == '_') { char c; p++; c = *p; *p = 0; if(stat(ws, &s) == 0 && S_ISDIR(s.st_mode)) { q = p; } *p = c; } } return q;}/**********************//* Function do_wild() */ /* for porting: dir separator; match(ignore_case) *//**********************/char *do_wild(__G__ wildspec) __GDEF ZCONST char *wildspec; /* only used first time on a given dir */{ static DIR *wild_dir = (DIR *)NULL; static ZCONST char *wildname; static char *dirname, matchname[FILNAMSIZ]; static int notfirstcall=FALSE, have_dirname, dirnamelen; struct dirent *file; char basedir[40]; /* Even when we're just returning wildspec, we *always* do so in * matchname[]--calling routine is allowed to append four characters * to the returned string, and wildspec may be a pointer to argv[]. */ if (!notfirstcall) { /* first call: must initialize everything */ char *ws = NULL, *us = NULL; notfirstcall = TRUE; /* break the wildspec into a directory part and a wildcard filename */ ws = (char *) iswild(wildspec); if(ws == NULL) { strcpy(matchname, wildspec); return matchname; } us = LastDir(wildspec); if(us == wildspec) { dirname = basedir; getcwd(basedir, sizeof(basedir)-1); dirnamelen = strlen(basedir); have_dirname = FALSE; wildname = wildspec; } else { wildname = us; /* point at character after '/' */ dirnamelen = wildname - wildspec; if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) { Info(slide, 0x201, ((char *)slide, "warning: cannot allocate wildcard buffers\n")); strcpy(matchname, wildspec); return matchname; /* but maybe filespec was not a wildcard */ } strncpy(dirname, wildspec, dirnamelen); dirname[dirnamelen] = '\0'; /* terminate for strcpy below */ have_dirname = TRUE; } if ((wild_dir = opendir(dirname)) != (DIR *)NULL) { while ((file = readdir(wild_dir)) != (struct dirent *)NULL) { if (match(file->d_name, wildname, 2)) { /* 0 == case sens. */ if (have_dirname) { strcpy(matchname, dirname); strcpy(matchname+dirnamelen, file->d_name); } else strcpy(matchname, file->d_name); return matchname; } } /* if we get to here directory is exhausted, so close it */ closedir(wild_dir); wild_dir = (DIR *)NULL; } /* return the raw wildspec in case that works (e.g., directory not * searchable, but filespec was not wild and file is readable) */ strcpy(matchname, wildspec); return matchname; } /* last time through, might have failed opendir but returned raw wildspec */ if (wild_dir == (DIR *)NULL) { notfirstcall = FALSE; /* nothing left to try--reset for new wildspec */ if (have_dirname) free(dirname); return (char *)NULL; } /* If we've gotten this far, we've read and matched at least one entry * successfully (in a previous call), so dirname has been copied into * matchname already. */ while ((file = readdir(wild_dir)) != (struct dirent *)NULL) { if (match(file->d_name, wildname, 2)) { /* 0 == don't ignore case */ if (have_dirname) { /* strcpy(matchname, dirname); */ strcpy(matchname+dirnamelen, file->d_name); } else strcpy(matchname, file->d_name); return matchname; } } closedir(wild_dir); /* have read at least one entry; nothing left */ wild_dir = (DIR *)NULL; notfirstcall = FALSE; /* reset for new wildspec */ if (have_dirname) free(dirname); return (char *)NULL;} /* end function do_wild() */#endif /* !SFX *//**********************//* Function mapattr() *//**********************/int mapattr(__G) __GDEF{ ulg tmp = G.crec.external_file_attributes; switch (G.pInfo->hostnum) { case AMIGA_: tmp = (unsigned)(tmp>>17 & 7); /* Amiga RWE bits */ G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp); break; case THEOS_: tmp &= 0xF1FFFFFFL; if ((tmp & 0xF0000000L) != 0x40000000L) tmp &= 0x01FFFFFFL; /* not a dir, mask all ftype bits */ else tmp &= 0x41FFFFFFL; /* leave directory bit as set */ /* fall through! */ case QDOS_: case UNIX_: case VMS_: case ACORN_: case ATARI_: case BEOS_: case TANDEM_: G.pInfo->file_attr = (unsigned)(tmp >> 16); if (G.pInfo->file_attr != 0 || !G.extra_field) { return 0; } else {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -