⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zooext.c

📁 汇编大全 中国矿业大学计算机学院 汇编实验5
💻 C
📖 第 1 页 / 共 2 页
字号:
            this_file = zoocreate (extfname);
#ifdef FATTR
				/* if can't open file, and OO option, make it writable first */
				if (this_file == NOFILE && overwrite >= 4 && 
						(direntry.fattr >> 22) == 1 && exists(extfname)) {
					setfattr (extfname, (unsigned long) (1L << 7) | direntry.fattr);
					this_file = zoocreate (extfname);
				}
#endif /* FATTR */
         } else {
            if (exists (extfname)) {
               present = 1;
               this_file = NOFILE;
            } else
               this_file = zoocreate (extfname);
         }
			error_message = 1;
         if (this_file == NOFILE) {
            if (present == 1) {      /* if file exists already */
					char ans[20];          /* answer to "Overwrite?" */
               do {
#ifdef EXT_ANYWAY
                  printf ("%s exists; extract anyway? [Yes/No/All] ",
                           extfname);
#else
                  printf ("Overwrite %s (Yes/No/All)? ", extfname);
#endif
                  fflush (stdin);
                  fgets (ans, sizeof(ans), stdin);
                  str_lwr (ans);
               } while (*ans != 'y' && *ans != 'n' && *ans != 'a');
   
               if (*ans == 'a')
                  overwrite++;
               if (*ans == 'y' || *ans == 'a') {
                  this_file = zoocreate(extfname);
                  error_message = 1; /* give error message if open fails */
               } else {
                  error_message = 0; /* user said 'n', so no error message */
               }
            } else {
               error_message = 1;   /* Real error -- give error message */
            }
         } /* end if */
      } /* end if */

      if (this_file == NOFILE) {         /* file couldn't be opened */
         if (error_message == 1) {
            prterror ('e', "Can't open %s for output.\n", extfname);
				exit_status = 1;

#ifndef PORTABLE
            /* if error was due to full disk, abort */
            if (space(0, &alloc_size) < alloc_size)
               prterror ('f', disk_full);
#endif

         }
      } else if (zooseek (zoo_file, (direntry.offset + dat_ofs), 0) == -1L) {
         prterror ('e', "Could not seek to file data.\n");
			exit_status = 1;
         close_file (this_file);
      } else {
#ifndef PORTABLE
         /* check msdos's free disk space if we seem to be running low 
            (within 1 cluster of being full) */
         if (tofile && disk_space < direntry.org_size + alloc_size) {
            disk_space = space (0, &alloc_size);
            if (disk_space < alloc_size) {
               close_file (this_file);
               unlink (extfname);
               prterror ('f', disk_full);
            }              
         }
#endif
         if (tofile && disk_space < direntry.org_size) {
#ifdef PORTABLE
            ;
#else
				prterror ('e', no_space, prtfname);
            unlink (extfname);               /* delete any created file */
#endif   /* portable */

         } else { 

#ifndef PORTABLE
            if (fast_ext) {            /* fast ext -> create header */
               void make_tnh PARMS((struct tiny_header *, struct direntry *));
               struct tiny_header tiny_header;
               make_tnh(&tiny_header, &direntry);
               zoowrite (this_file, (char *) &tiny_header, sizeof(tiny_header));

               if (direntry.cmt_size != 0) { /* copy comment */
                  long save_pos;
                  save_pos = zootell (zoo_file);
                  zooseek (zoo_file, direntry.comment, 0);
                  getfile (zoo_file, this_file, 
                          (long) direntry.cmt_size, 0);
                  zooseek (zoo_file, save_pos, 0);
               }
            }
#endif /* ifndef PORTABLE */

            crccode = 0;      /* Initialize CRC before extraction */
               if (!pipe) {
#ifdef PORTABLE
                  prterror ('m', "%-14s -- ", prtfname);
#else
                  if (fast_ext)
                     prterror ('m', "%-12s ==> %-12s -- ", 
                        prtfname,  extfname);
                  else
                     prterror ('m', "%-12s -- ", prtfname);
#endif /* PORTABLE */

               } else {            /* must be pipe */
                  prterror ('M',"\n\n********\n%s\n********\n",prtfname);

#ifdef SETMODE
                  MODE_BIN(this_file);           /* make std output binary so
                                                   ^Z won't cause error */
#endif
               }
#ifndef NOSIGNAL
            if (tofile)
               {
                  oldsignal = signal (SIGINT, SIG_IGN);
                  if (oldsignal != SIG_IGN) 
                     signal (SIGINT, ctrl_c); /* Trap ^C & erase partial file */
               }
#endif /* not NOSIGNAL */

            if (direntry.packing_method == 0)
               /* 4th param 1 means CRC update */
               status = getfile (zoo_file, this_file, direntry.size_now, 1);

#ifndef PORTABLE
            else if (fast_ext)
               /* 4th param 0 means no CRC update */
               status = getfile (zoo_file, this_file, direntry.size_now, 0);
#endif

            else if (direntry.packing_method == 1) {
#ifdef UNBUF_IO
#include "ERROR"
					/* NOT PORTABLE -- DO NOT TRY THIS AT HOME */
					long lseek PARMS ((int, long, int));
					long tell PARMS ((int));
					int this_fd, zoo_fd;
			
					/* get file descriptors */
					this_fd = null_device ? -2 : fileno (this_file);
					zoo_fd = fileno (zoo_file);

					zooseek (zoo_file, zootell (zoo_file), 0);	/* synch */
					lseek (zoo_fd, zootell (zoo_file), 0);			/* ..again */
					if (!null_device) {
						zooseek (this_file, zootell (this_file), 0);	/* synch */
						lseek (this_fd, zootell (this_file), 0);		/* ..again */
					}
			      status = lzd(zoo_fd, this_fd);			/* uncompress */
					zooseek (zoo_file, tell (zoo_fd), 0);	/* resynch	*/
					if (!null_device)
						zooseek (this_file, tell (this_fd), 0);/* resynch	*/
#else
               status = lzd (zoo_file, this_file); 	/* uncompress */
#endif
				} else if (direntry.packing_method == 2) {
               status = lzh_decode (zoo_file, this_file);
            } else {
               prterror ('e', "File %s:  impossible packing method.\n",
                  whichname);
                  unlink(extfname);
                  goto loop_again;
            }


#ifndef NOSIGNAL
            if (tofile)
               signal (SIGINT, oldsignal);
#endif /* not NOSIGNAL */

#ifdef SETMODE
            if (pipe)
               MODE_TEXT(this_file);          /* restore text mode */
#endif
   
            if (tofile) {
               /* set date/time of file being extracted */
#ifdef GETTZ
					void tzadj();
					/* adjust for original timezone */
					tzadj (&direntry);
#endif
#ifdef NIXTIME
               close_file (this_file);
               setutime (extfname, direntry.date, direntry.time);
#else
               settime (this_file, direntry.date, direntry.time);
               close_file (this_file);
#endif
#ifdef FATTR
/* Restore file attributes. Bit 23==1 means system-specific; we currently 
don't recognize this.  Bit 23==0 means use portable format, in which case 
bit 22==0 means ignore attributes.  Thus attributes are ignored if both 
bits 23 and 22 are zero, which is the effect of a zero-filled file 
attribute field.  Currently we restore file attributes if and only if
bit 23==0 and bit 22==1. */

					if ((direntry.fattr >> 22) == 1) {
						setfattr (extfname, direntry.fattr);
					}
#endif /* FATTR */
            } /* end of if (tofile) ... */
            if (status != 0) {
					exit_status = 1;
               if (tofile)
                  unlink (extfname);
               if (status == 2) {	/* was 1 (wrong) */
                  memerr(0);
               /* To avoid spurious errors due to ^Z being sent to screen,
                  we don't check for I/O error if output was piped */
               } else if (!pipe && (status == 2 || status == 3)) {
                     prterror ('e', no_space, prtfname);
               }
            } else {
               /* file extracted, so update disk space.  */
               /* we subtract the original size of the file, rounded
                  UP to the nearest multiple of the disk allocation
                  size. */
#ifndef PORTABLE
               {
                  unsigned long temp;
                  temp = (direntry.org_size + alloc_size) / alloc_size;
                  disk_space -= temp * alloc_size;
               }
#endif

               if (
#ifndef PORTABLE
					      !fast_ext && 
#endif
							direntry.file_crc != crccode
						) {
                  badcrc_count++;
						exit_status = 1;
                  if (!pipe) {
                     if (!null_device)
                        prterror ('M', "extracted   ");
                     prterror ('w', bad_crc, prtfname);
                  }
                  else {   /* duplicate to standard error */
                     static char stars[] = "\n******\n";
                     putstr (stars);
                     prterror ('w', bad_crc, prtfname);
                     putstr (stars);
                     fprintf (stderr, "WARNING:  ");
                     fprintf (stderr, bad_crc, prtfname);
                  }
               } else
                  if (!pipe)
                     prterror ('M', null_device ? "OK\n" : "extracted\n");

            } /* end if */
         } /* end if */
      } /* end if */
   } /* end if */

loop_again:
   zooseek (zoo_file, next_ptr, 0); /* ..seek to next dir entry */
} /* end while */

close_file (zoo_file);
if (!matched)
   putstr (no_match);

if (badcrc_count) {
   prterror ('w', "%d File(s) with bad CRC.\n", badcrc_count);
} else if (null_device)
   prterror ('m', "Archive seems OK.\n");

zooexit (exit_status);

} /* end zooext */

/* close_file() */
/* closes a file if and only if we aren't sending output to 
   a pipe or to the null device */

void close_file (file)
ZOOFILE file;
{
   if (tofile)
      zooclose (file);
}

/* Ctrl_c() is called if ^C is hit while a file is being extracted.
   It closes the files, deletes it, and exits. */
T_SIGNAL ctrl_c()
{
#ifndef NOSIGNAL
   signal (SIGINT, SIG_IGN);     /* ignore any more */
#endif
   zooclose (this_file);
   unlink (extfname);
   zooexit (1);
}

#ifndef PORTABLE
/* make_tnh copies creates a tiny_header */
void make_tnh (tiny_header, direntry)
struct tiny_header *tiny_header;
struct direntry *direntry;
{
   tiny_header->tinytag = TINYTAG;
   tiny_header->type = 1;
   tiny_header->packing_method = direntry->packing_method;
   tiny_header->date = direntry->date;
   tiny_header->time = direntry->time;
   tiny_header->file_crc = direntry->file_crc;
   tiny_header->org_size = direntry->org_size;
   tiny_header->size_now = direntry->size_now;
   tiny_header->major_ver = direntry->major_ver;
   tiny_header->minor_ver = direntry->minor_ver;
   tiny_header->cmt_size = direntry->cmt_size;
   strcpy (tiny_header->fname, direntry->fname);
} 
#endif /* ifndef PORTABLE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -