English Language flag
// Log In
// CVSweb
Project: FreeWRT
// Summary // Activity // Search // Tracker // Lists // News // SCM // Wiki

SCM Repository

ViewVC logotype

Diff of /branches/freewrt_1_0/tools/paxmirabilis/src/options.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2714 by wbx, Thu Sep 28 10:42:55 2006 UTC revision 2715 by tg, Tue Jun 5 14:52:44 2007 UTC
# Line 1  Line 1 
1  /**     $MirOS: src/bin/pax/options.c,v 1.19 2006/07/16 17:58:39 tg Exp $ */  /**     $MirOS: src/bin/pax/options.c,v 1.24 2007/02/17 04:52:41 tg Exp $ */
2  /*      $OpenBSD: options.c,v 1.64 2006/04/09 03:35:34 jaredy Exp $     */  /*      $OpenBSD: options.c,v 1.64 2006/04/09 03:35:34 jaredy Exp $     */
3  /*      $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $  */  /*      $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $  */
4    
5  /*-  /*-
6   * Copyright (c) 2005, 2006 Thorsten Glaser <tg@66h.42h.de>   * Copyright (c) 2005, 2006, 2007 Thorsten Glaser <tg@66h.42h.de>
7   * Copyright (c) 1992 Keith Muller.   * Copyright (c) 1992 Keith Muller.
8   * Copyright (c) 1992, 1993   * Copyright (c) 1992, 1993
9   *      The Regents of the University of California.  All rights reserved.   *      The Regents of the University of California.  All rights reserved.
# Line 57  Line 57 
57  #include "extern.h"  #include "extern.h"
58    
59  __SCCSID("@(#)options.c 8.2 (Berkeley) 4/18/94");  __SCCSID("@(#)options.c 8.2 (Berkeley) 4/18/94");
60  __RCSID("$MirOS: src/bin/pax/options.c,v 1.19 2006/07/16 17:58:39 tg Exp $");  __RCSID("$MirOS: src/bin/pax/options.c,v 1.24 2007/02/17 04:52:41 tg Exp $");
61    
62  #ifdef __GLIBC__  #ifdef __GLIBC__
63  char *fgetln(FILE *, size_t *);  char *fgetln(FILE *, size_t *);
# Line 77  static int c_frmt(const void *, const vo Line 77  static int c_frmt(const void *, const vo
77  static off_t str_offt(char *);  static off_t str_offt(char *);
78  static char *getline(FILE *fp);  static char *getline(FILE *fp);
79  static void pax_options(int, char **);  static void pax_options(int, char **);
80  static void pax_usage(void);  static void pax_usage(void) __attribute__((noreturn));
81    static void tar_set_action(int);
82  static void tar_options(int, char **);  static void tar_options(int, char **);
83  static void tar_usage(void);  static void tar_usage(void) __attribute__((noreturn));
84    static void cpio_set_action(int);
85  static void cpio_options(int, char **);  static void cpio_options(int, char **);
86  static void cpio_usage(void);  static void cpio_usage(void) __attribute__((noreturn));
87  int mkpath(char *);  int mkpath(char *);
88    
89  static void process_M(const char *, void (*)(void));  static void process_M(const char *, void (*)(void));
# Line 213  static void Line 215  static void
215  pax_options(int argc, char **argv)  pax_options(int argc, char **argv)
216  {  {
217          int c;          int c;
218          int i;          size_t i;
219          unsigned int flg = 0;          unsigned int flg = 0;
220          unsigned int bflg = 0;          unsigned int bflg = 0;
221          char *pt;          char *pt;
# Line 222  pax_options(int argc, char **argv) Line 224  pax_options(int argc, char **argv)
224          /*          /*
225           * process option flags           * process option flags
226           */           */
227          while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ0"))          while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLM:OPT:U:XYZ0"))
228              != -1) {              != -1) {
229                  switch (c) {                  switch (c) {
230                  case 'a':                  case 'a':
# Line 475  pax_options(int argc, char **argv) Line 477  pax_options(int argc, char **argv)
477                          Lflag = 1;                          Lflag = 1;
478                          flg |= CLF;                          flg |= CLF;
479                          break;                          break;
480                    case 'M':
481                            /*
482                             * MirOS extension: archive normaliser
483                             */
484                            process_M(optarg, pax_usage);
485                            break;
486                  case 'O':                  case 'O':
487                          /*                          /*
488                           * Force one volume.  Non standard option.                           * Force one volume.  Non standard option.
# Line 622  pax_options(int argc, char **argv) Line 630  pax_options(int argc, char **argv)
630   */   */
631    
632  static void  static void
633    tar_set_action(int op)
634    {
635            if (act != ERROR && act != op)
636                    tar_usage();
637            act = op;
638    }
639    
640    static void
641  tar_options(int argc, char **argv)  tar_options(int argc, char **argv)
642  {  {
643          int c;          int c;
# Line 660  tar_options(int argc, char **argv) Line 676  tar_options(int argc, char **argv)
676                          /*                          /*
677                           * create an archive                           * create an archive
678                           */                           */
679                          act = ARCHIVE;                          tar_set_action(ARCHIVE);
680                          break;                          break;
681                  case 'e':                  case 'e':
682                          /*                          /*
# Line 720  tar_options(int argc, char **argv) Line 736  tar_options(int argc, char **argv)
736                          /*                          /*
737                           * append to the archive                           * append to the archive
738                           */                           */
739                          act = APPND;                          tar_set_action(APPND);
740                          break;                          break;
741                  case 'R':                  case 'R':
742                          Oflag = 3;                          Oflag = 3;
# Line 743  tar_options(int argc, char **argv) Line 759  tar_options(int argc, char **argv)
759                          /*                          /*
760                           * list contents of the tape                           * list contents of the tape
761                           */                           */
762                          act = LIST;                          tar_set_action(LIST);
763                          break;                          break;
764                  case 'v':                  case 'v':
765                          /*                          /*
# Line 762  tar_options(int argc, char **argv) Line 778  tar_options(int argc, char **argv)
778                           * extract an archive, preserving mode,                           * extract an archive, preserving mode,
779                           * and mtime if possible.                           * and mtime if possible.
780                           */                           */
781                          act = EXTRACT;                          tar_set_action(EXTRACT);
782                          pmtime = 1;                          pmtime = 1;
783                          break;                          break;
784                  case 'z':                  case 'z':
# Line 852  tar_options(int argc, char **argv) Line 868  tar_options(int argc, char **argv)
868          argc -= optind;          argc -= optind;
869          argv += optind;          argv += optind;
870    
871            /* Tar requires an action. */
872            if (act == ERROR)
873                    tar_usage();
874    
875          /* Traditional tar behaviour (pax uses stderr unless in list mode) */          /* Traditional tar behaviour (pax uses stderr unless in list mode) */
876          if (fstdin == 1 && act == ARCHIVE)          if (fstdin == 1 && act == ARCHIVE)
877                  listf = stderr;                  listf = stderr;
# Line 1069  mkpath(char *path) Line 1089  mkpath(char *path)
1089    
1090          return (0);          return (0);
1091  }  }
1092    
1093    static void
1094    cpio_set_action(int op)
1095    {
1096            if ((act == APPND && op == ARCHIVE) || (act == ARCHIVE && op == APPND))
1097                    act = APPND;
1098            else if ((act == LIST && op == EXTRACT) || (act == EXTRACT && op == LIST))
1099                    act = LIST;
1100            else if (act != ERROR && act != op)
1101                    cpio_usage();
1102            else
1103                    act = op;
1104    }
1105    
1106  /*  /*
1107   * cpio_options()   * cpio_options()
1108   *      look at the user specified flags. set globals as required and check if   *      look at the user specified flags. set globals as required and check if
# Line 1078  mkpath(char *path) Line 1112  mkpath(char *path)
1112  static void  static void
1113  cpio_options(int argc, char **argv)  cpio_options(int argc, char **argv)
1114  {  {
1115          int c, i;          int c;
1116            size_t i;
1117          char *str;          char *str;
1118          FSUB tmp;          FSUB tmp;
1119          FILE *fp;          FILE *fp;
# Line 1089  cpio_options(int argc, char **argv) Line 1124  cpio_options(int argc, char **argv)
1124          pmtime = 0;          pmtime = 0;
1125          arcname = NULL;          arcname = NULL;
1126          dflag = 1;          dflag = 1;
         act = -1;  
1127          nodirs = 1;          nodirs = 1;
1128          while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LM:O:SZ6")) != -1)          while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LM:O:SZ6")) != -1)
1129                  switch (c) {                  switch (c) {
# Line 1126  cpio_options(int argc, char **argv) Line 1160  cpio_options(int argc, char **argv)
1160                                  /*                                  /*
1161                                   * restore an archive                                   * restore an archive
1162                                   */                                   */
1163                                  act = EXTRACT;                                  cpio_set_action(EXTRACT);
1164                                  break;                                  break;
1165                          case 'k':                          case 'k':
1166                                  break;                                  break;
# Line 1146  cpio_options(int argc, char **argv) Line 1180  cpio_options(int argc, char **argv)
1180                                  /*                                  /*
1181                                   * create an archive                                   * create an archive
1182                                   */                                   */
1183                                  act = ARCHIVE;                                  cpio_set_action(ARCHIVE);
1184                                  frmt = &(fsub[F_CPIO]);                                  frmt = &(fsub[F_CPIO]);
1185                                  break;                                  break;
1186                          case 'p':                          case 'p':
1187                                  /*                                  /*
1188                                   * copy-pass mode                                   * copy-pass mode
1189                                   */                                   */
1190                                  act = COPY;                                  cpio_set_action(COPY);
1191                                  break;                                  break;
1192                          case 'r':                          case 'r':
1193                                  /*                                  /*
# Line 1170  cpio_options(int argc, char **argv) Line 1204  cpio_options(int argc, char **argv)
1204                                  /*                                  /*
1205                                   * list contents of archive                                   * list contents of archive
1206                                   */                                   */
1207                                  act = LIST;                                  cpio_set_action(LIST);
1208                                  listf = stdout;                                  listf = stdout;
1209                                  break;                                  break;
1210                          case 'u':                          case 'u':
# Line 1195  cpio_options(int argc, char **argv) Line 1229  cpio_options(int argc, char **argv)
1229                                  /*                                  /*
1230                                   * append mode                                   * append mode
1231                                   */                                   */
1232                                  act = APPND;                                  cpio_set_action(APPND);
1233                                  break;                                  break;
1234                          case 'B':                          case 'B':
1235                                  /*                                  /*
# Line 1372  printflg(unsigned int flg) Line 1406  printflg(unsigned int flg)
1406  static int  static int
1407  c_frmt(const void *a, const void *b)  c_frmt(const void *a, const void *b)
1408  {  {
1409          return(strcmp(((FSUB *)a)->name, ((FSUB *)b)->name));          return(strcmp(((const FSUB *)a)->name, ((const FSUB *)b)->name));
1410  }  }
1411    
1412  /*  /*
# Line 1608  pax_usage(void) Line 1642  pax_usage(void)
1642              "\t  [-o options] [-p string] [-s replstr] [-T [from_date][,to_date]]\n"              "\t  [-o options] [-p string] [-s replstr] [-T [from_date][,to_date]]\n"
1643              "\t  [-U user] [pattern ...]\n"              "\t  [-U user] [pattern ...]\n"
1644              "       pax -w [-0adHiLOPtuvXz] [-B bytes] [-b blocksize] [-f archive]\n"              "       pax -w [-0adHiLOPtuvXz] [-B bytes] [-b blocksize] [-f archive]\n"
1645              "\t  [-G group] [-o options] [-s replstr]\n"              "\t  [-G group] [-M value] [-o options] [-s replstr]\n"
1646              "\t  [-T [from_date][,to_date][/[c][m]]] [-U user] [-x format] [file ...]\n"              "\t  [-T [from_date][,to_date][/[c][m]]] [-U user] [-x format] [file ...]\n"
1647              "       pax -r -w [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] [-s replstr]\n"              "       pax -r -w [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] [-s replstr]\n"
1648              "\t  [-T [from_date][,to_date][/[c][m]]] [-U user] [file ...] directory\n",              "\t  [-T [from_date][,to_date][/[c][m]]] [-U user] [file ...] directory\n",
# Line 1655  anonarch_init(void) Line 1689  anonarch_init(void)
1689  {  {
1690          if (anonarch & ANON_VERBOSE) {          if (anonarch & ANON_VERBOSE) {
1691                  anonarch &= ~ANON_VERBOSE;                  anonarch &= ~ANON_VERBOSE;
1692                  paxwarn(0, "debug: -M 0x%08X", anonarch);                  paxwarn(0, "debug: -M 0x%08X -x %s", anonarch, frmt->name);
1693          }          }
1694  }  }
1695    

Legend:
Removed from v.2714  
changed lines
  Added in v.2715

root@freewrt.org:443
ViewVC Help
Powered by ViewVC 1.1.20