int IoList_compare(IoList *self, IoList *otherList) { if (!ISLIST(otherList)) { return IoObject_defaultCompare(self, otherList); } else { size_t s1 = List_size(DATA(self)); size_t s2 = List_size(DATA(otherList)); size_t i; if (s1 != s2) { return s1 > s2 ? 1 : -1; } for (i = 0; i < s1; i ++) { IoObject *v1 = LIST_AT_(DATA(self), i); IoObject *v2 = LIST_AT_(DATA(otherList), i); int c = IoObject_compare(v1, v2); if (c) { return c; } } } return 0; }
TERM bpx_get_car(TERM t) { XDEREF(t); if (ISLIST(t)) { return GET_CAR(t); } else { bpx_raise("list expected"); } }
Word CYLIMPFORM(Word C, Word P, Word k, Word A) { Word SF,L,Lp,c,S,t,Q,As,Ap,Fp,F,Lt,Lf,s,Si,Fi,Qp,SF2; Step1: /* Set L to a list of all (k-1)-level cells over which there are k-level cells with SC_TMPM of TRUE. */ if (k == 0) { if (LELTI(C,SC_TMPM) == TRUE) SF = LIST1(TRUE); else SF = LIST1(FALSE); goto Return; } SF = NIL; L = NIL; for(Lp = PCADCL(C,k-1); Lp != NIL; Lp = RED(Lp)) { c = FIRST(Lp); S = LELTI(c,SC_CDTV); if (!ISLIST(S)) continue; for(t = 0; S != NIL && !t; S = RED(S)) t = (LELTI(FIRST(S),SC_TMPM) == TRUE); if (t) L = COMP(c,L); } Step2: /* Construct formula for the k-level cells. */ Lt = NIL; Lf = NIL; S = NIL; for(Lp = L; Lp != NIL; Lp = RED(Lp)) S = CCONC(LELTI(FIRST(Lp),SC_CDTV),S); for(S = PCADCL(C,k); S != NIL; S = RED(S)) { s = FIRST(S); if (LELTI(s,SC_TMPM) == TRUE) Lt = COMP(s,Lt); else Lf = COMP(s,Lf); } F = NAIVESF(SPCADCBDD(Lt,k),Lf,A,P); Step3: /* */ S = GEOPARTII(FMASORT(FMA2DNF(F)),L,P,NIL); /* Construct definiting formula from each (Si,Fi) in S. */ for(; S != NIL; S = RED(S)) { FIRST2(FIRST(S),&Si,&Fi); ESCSLKMF(C,k-1); for(Qp = Si; Qp != NIL; Qp = RED(Qp)) SLELTI(FIRST(Qp),SC_TMPM,TRUE); SF2 = CYLIMPFORM(C,P,k-1,A); SF = COMP(LIST3(ANDOP,SF2,CLEANUPFORM(Si,Fi,P)),SF); } Step4: /* Convert SF from a list of formulas to a formula. */ if (LENGTH(SF) > 1) SF = COMP(OROP,SF); else SF = FIRST(SF); Return: /* Prepare to return. */ return SF; }
TERM bpx_get_cdr(TERM t) { XDEREF(t); if (ISLIST(t)) { return GET_CDR(t); } else { bpx_raise("list expected"); } return NULL_TERM; /* should not be reached */ }
Word FMAOPCOMBINE(Word F) { Word L,M,Fp,f,a,b,Lp,Mp,Lb; switch(FIRST(F)) { case OROP: /* Set L to a list of all top level atomic formulas. */ L = NIL; M = NIL; for(Fp = RED(F); Fp != NIL; Fp = RED(Fp)) { f = FIRST(Fp); if (ISLIST(FIRST(f))) L = COMP(f,L); else M = COMP(f,M); } /* Create Lp from L */ Lp = NIL; while(L != NIL) { a = FIRST(L); if (FMAQEXTAF(a)) { Lp = COMP(a,Lp); L = RED(L); continue; } Lb = RED(L); for(L = NIL; Lb != NIL; Lb = RED(Lb)) { b = FIRST(Lb); if (FMAQEXTAF(b) || ! EQUAL(FIRST(b),FIRST(a))) L = COMP(b,L); else a = LIST2(FIRST(a),SECOND(a) | SECOND(b)); } if (SECOND(a) > 6) Lp = COMP(LIST1(TRUE),Lp); else Lp = COMP(a,Lp); } /* Create Mp from M. */ for(Mp = NIL; M != NIL; M = RED(M)) Mp = COMP(FMAOPCOMBINE(FIRST(M)),Mp); Fp = COMP(OROP,CCONC(Lp,Mp)); break; case ANDOP: Fp = NIL; for(L = CINV(RED(F)); L != NIL; L = RED(L)) Fp = COMP(FMAOPCOMBINE(FIRST(L)),Fp); Fp = COMP(ANDOP,Fp); break; default: Fp = F; } return Fp; }
Word singleFMADMQ(Word F,Word C,Word k,Word P) { Word t,L; if (k == 0 || !ISLIST(LELTI(C,SC_CDTV))) t = (FMACELLEVAL(F,C,P) == LELTI(C,SC_TMPM)); else { L = LELTI(C,SC_CDTV); for(t = 1; t && L != NIL; L = RED(L)) t = singleFMADMQ(F,FIRST(L),k-1,P); } return t; }
Word FTYPEINFO(Word A) { if (ISLIST(FIRST(A))) return NIL; if (FIRST(A) == ANDOP) return ANDOP; if (FIRST(A) == OROP) return OROP; if (FIRST(A) == TRUE) return TRUE; if (FIRST(A) == FALSE) return FALSE; }
intptr_t marshal(IoDynLib *self, IoObject *arg) { intptr_t n = 0; if (ISNUMBER(arg)) { n = IoNumber_asInt(arg); } else if (ISSYMBOL(arg)) { n = (intptr_t)CSTRING(arg); } else if (ISLIST(arg)) { int i; intptr_t *l = io_calloc(1, IoList_rawSize(arg) * sizeof(intptr_t)); for (i = 0; i < IoList_rawSize(arg); i ++) l[i] = marshal(self, List_rawAt_(IoList_rawList(arg), i)); n = (intptr_t)l; } else if (ISBUFFER(arg)) { n = (intptr_t)IoSeq_rawBytes(arg); } else if (ISBLOCK(arg)) { unsigned char *blk = io_calloc(1, 20), *p = blk; // FIXME: need trampoline code for other architectures *p++ = 0x68; *((intptr_t *)p) = (intptr_t)arg; p += sizeof(intptr_t); *p++ = 0xb8; *((intptr_t *)p) = (intptr_t)bouncer; p += sizeof(intptr_t); *p++ = 0xff; *p++ = 0xd0; *p++ = 0x83; *p++ = 0xc4; *p++ = 0x04; *p++ = 0xc3; n = (intptr_t)blk; } else { n = (intptr_t)arg; //IONIL(self); } return n; }
Word CYLFORM(Word C, Word P, Word k, Word A) { Word SF,L,Lp,c,S,t,Q,As,Ap,Fp,F,Lt,Lf,s; Step1: /* Set L to a list of all (k-1)-level cells over which there are k-level cells with SC_TMPM of TRUE. */ if (k == 0) { SF = LIST1(TRUE); goto Return; } SF = NIL; L = NIL; for(Lp = PCADCL(C,k-1); Lp != NIL; Lp = RED(Lp)) { c = FIRST(Lp); S = LELTI(c,SC_CDTV); if (!ISLIST(S)) continue; for(t = 0; S != NIL && !t; S = RED(S)) t = (LELTI(FIRST(S),SC_TMPM) == TRUE); if (t) L = COMP(c,L); } Step3: /* Construct formula for the k-level cells. */ Lt = NIL; Lf = NIL; S = NIL; for(Lp = L; Lp != NIL; Lp = RED(Lp)) S = CCONC(LELTI(FIRST(Lp),SC_CDTV),S); for(S = PCADCL(C,k); S != NIL; S = RED(S)) { s = FIRST(S); if (LELTI(s,SC_TMPM) == TRUE) Lt = COMP(s,Lt); else Lf = COMP(s,Lf); } F = NAIVESF(SPCADCBDD(Lt,k),Lf,A,P); Step2: /* Formula for the projection. */ for(Q = L; Q != NIL; Q = RED(Q)) SLELTI(FIRST(Q),SC_TMPM,TRUE); As = NIL; for(Ap = CINV(A); Ap != NIL; Ap = RED(Ap)) if (FMALEVEL(FIRST(Ap)) < k) As = COMP(FIRST(Ap),As); Fp = CYLFORM(C,P,k-1,As); SF = LIST3(ANDOP,Fp,F); Return: /* Prepare to return. */ return SF; }
Word NORMAETF(Word A) { Word X,T,j,P,r,I,s,c,L,Lr,Fs,Fa,L_i,e_i,P_i,rk_i,Pk_i,F; Step1: /* Get the components. */ FIRST6(A,&X,&T,&j,&P,&r,&I); Step2: /* Factor \v{P}. */ if (!ISLIST(FIRST(P))) IPFACDB(r,P,&s,&c,&L); else { Word Lp = NIL; for(; P != NIL; P = RED(P)) Lp = COMP(LIST2(1,FIRST(P)),Lp); L = CINV(Lp); } Step3: /* Sign of content is irrelevant in _root_ expressions! */ Step4: /* Simplify the representation of the polys in \v{L}. */ Lr = NIL; /* r-level factors */ Fs = NIL; /* factors of level less than r can't be zero! */ while (L != NIL) { ADV(L,&L_i,&L); FIRST2(L_i,&e_i,&P_i); PSIMREP(r,P_i,&rk_i,&Pk_i); if (rk_i < r) Fs = COMP(LIST4(NEOP,Pk_i,rk_i,NIL),Fs); else Lr = COMP(Pk_i,Lr); } Lr = INV(Lr); Step5: /* Create formula */ Fa = LIST6(IROOT,T,j,Lr,r,NIL); F = COMP(Fa,Fs); F = COMP(ANDOP,CINV(F)); Return: /* Prepare for return. */ return(F); }
void QepcadCls::SEPPIVNONPIV(Word Q_k, Word k, Word *PP_, Word *NP_) { Word C,NP,PP,L,l; Step1: /* No pivot at this level. */ if ((!ISLIST(GVPIVOT)) || (LENGTH(GVPIVOT) < k) || ((C = LELTI(GVPIVOT,k)) == NIL)) { PP = Q_k; NP = NIL; goto Return; } Step2: /* There is a pivot at this level. */ NP = NIL; PP = NIL; L = Q_k; while (L != NIL) { ADV(L,&l,&L); if ( !MEMBER(LELTI(l,PO_LABEL),C) ) NP = COMP(l,NP); else PP = COMP(l,PP); } Return:/* Return. */ *PP_ = PP; *NP_ = NP; return; }
IoObject *demarshal(IoObject *self, IoObject *arg, intptr_t n) { if (ISNUMBER(arg)) { return IONUMBER(n); } else if (ISSYMBOL(arg)) { if (n == 0) return IOSYMBOL(""); return IOSYMBOL((char*)n); } else if (ISLIST(arg)) { intptr_t *values = (intptr_t *)n; int i; for (i = 0; i < IoList_rawSize(arg); i ++) { IoObject *value = List_at_(IoList_rawList(arg), i); List_at_put_(IoList_rawList(arg), i, demarshal(self, value, values[i])); } io_free(values); return arg; } else if (ISBUFFER(arg)) { return arg; } else if (ISBLOCK(arg)) { return arg; } return IONIL(self); }
Word QepcadCls::PROJMCmod(Word r, Word A) { Word A1,A2,Ap,Ap1,Ap2,App,D,L,Lh,P,R,W,i,t,Q,j,S,Sp; Step1: /* Obtain coefficients. */ P = NIL; Ap = A; while (Ap != NIL) { ADV(Ap,&A1,&Ap); Ap1 = LELTI(A1,PO_POLY); /* Deal with projection points! */ if (LELTI(A1,PO_TYPE) == PO_POINT) { W = MPOLY(RED(Ap1),NIL,LIST1(LIST2(PT_PRJ,A1)),PO_POINT,PO_KEEP); P = COMP(W,P); continue; } /* Handle the leading coefficient! */ L = PLDCF(Ap1); Lh = NIL; t = 0; /* if (!PCONST(r - 1,L)) {*/ if (!VERIFYCONSTSIGN(r-1,IPIP(r-1,ISIGNF(PLBCF(r-1,L)),L),1,GVNA.W)) { W = MPOLY(L,NIL,LIST1(LIST3(PO_LCO,0,A1)),PO_OTHER,PO_KEEP); P = COMP(W,P); Lh = COMP(L,Lh); t = 1; } /* If r = 2 then we know the leading coefficient is always enough! */ if (r == 2) t = 0; /* If x_{r-1} is a bound variable, and the quantifier is either F or G, then we know we'll only be lifting over full dimensional cells so we don't have to add more coefficients! */ if (t) { j = r - GVNFV - 1; if (j > 0) { Q = LELTI(GVQ,j); /* Quantifier for x_{r-1} */ if (Q == FULLDE || Q == FULLDA) t = 0; } } /* If PCMZERROR is set to true, then we only need leading coefficients when projecting polynomials of level k+1 or lower. */ if (t && PCMZERROR && r <= GVNFV + 1) t = 0; /* If it can be determined that the system of coefficients is inconsistent ... we can stop with just the leading coeff! */ if (t) { j = CLOCK(); S = COEFSYS(r,Ap1); if (S == 1 || (Sp = SIMPLIFYSYSLIST(r-1,S,GVNA == NIL ? TRUE : GVNA.W)) == 1) t = 0; else { QepcadCls Q; Word G; for(t = 0; t == 0 && Sp != NIL; Sp = RED(Sp)) if ((G = SYSSOLVECAD(r-1,FIRST(Sp),GVNA == NIL ? TRUE : GVNA.W,GVVL,Q)) != NIL) { /* If there are finitely many solutions, add those points as projection points. */ if (ISLIST(G)) { for(Word Lp = G; Lp != NIL; Lp = RED(Lp)) { /* ADD POINTS to PROJECTION POLS! */ Word X = NIL; /* List of all sample points up to and inluding FIRST(G) */ Word c = Q.GVPC; for(Word I = LELTI(FIRST(Lp),INDX); I != NIL; I = RED(I)) { c = LELTI(LELTI(c,CHILD),FIRST(I)); Word s = LELTI(c,SAMPLE); X = COMP(ISPRIMIT(s) ? (LENGTH(s) > 3 ? FOURTH(s) : s) : s,X); } W = MPOLY(X,NIL,LIST1(LIST2(PT_NUL,A1)),PO_POINT,PO_KEEP); P = COMP(W,P); } } else t = 1; /* Instead of adding all the other coeffs, better to add system! */ } } j = CLOCK() - j; if (PCVERBOSE) { SWRITE("Coef consistency check took "); IWRITE(j); SWRITE("ms\n"); if (!t) SWRITE("Found system inconsistent for "); else SWRITE("Unable to determine consistency for "); IPDWRITE(r,Ap1,GVVL); SWRITE("\n"); } } /* Handle the rest of the coefficients as needed. */ i = 0; while (t) { Ap1 = PRED(Ap1); i++; L = PLDCF(Ap1); t = 0; if (Ap1 != 0) if (!PCONST(r - 1,L)) if (!IPFZT(r - 1,Lh)) { W = MPOLY(L,NIL,LIST1(LIST3(PO_LCO,i,A1)),PO_OTHER,PO_KEEP); P = COMP(W,P); Lh = COMP(L,Lh); t = 1; } } } Step2: /* Obtain discriminants. */ Ap = A; while (Ap != NIL) { ADV(Ap,&A1,&Ap); if (LELTI(A1,PO_TYPE) == PO_POINT) continue; if (PCEQC && LELTI(A1,PO_TYPE) != PO_ECON) continue; Ap1 = LELTI(A1,PO_POLY); if (PDEG(Ap1) >= 2) { D = IPDSCRQE(r,Ap1); W = MPOLY(D,NIL,LIST1(LIST4(PO_DIS,0,0,A1)),PO_OTHER,PO_KEEP); P = COMP(W,P); } } Step3: /* Obtain resultants. */ Ap = A; while (Ap != NIL) { ADV(Ap,&A1,&Ap); if (LELTI(A1,PO_TYPE) == PO_POINT) continue; Ap1 = LELTI(A1,PO_POLY); App = Ap; while (App != NIL) { ADV(App,&A2,&App); if (LELTI(A2,PO_TYPE) == PO_POINT) continue; if (PCEQC && LELTI(A1,PO_TYPE) != PO_ECON && LELTI(A2,PO_TYPE) != PO_ECON) continue; Ap2 = LELTI(A2,PO_POLY); R = IPRESQE(r,Ap1,Ap2); W = MPOLY(R,NIL,LIST1(LIST6(PO_RES,0,0,A1,0,A2)),PO_OTHER,PO_KEEP); P = COMP(W,P); } } Step4: /* Finish. */ P = INV(P); goto Return; Return: /* Prepare for return. */ return(P); }
static void pax_options(int argc, char **argv) { int c; unsigned i; unsigned int flg = 0; unsigned int bflg = 0; char *pt; /* * process option flags */ while ((c=getopt(argc,argv,"ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ0")) != -1) { switch (c) { case 'a': /* * append */ flg |= AF; break; case 'b': /* * specify blocksize */ flg |= BF; if ((wrblksz = (int)str_offt(optarg)) <= 0) { paxwarn(1, "Invalid block size %s", optarg); pax_usage(); } break; case 'c': /* * inverse match on patterns */ cflag = 1; flg |= CF; break; case 'd': /* * match only dir on extract, not the subtree at dir */ dflag = 1; flg |= DF; break; case 'f': /* * filename where the archive is stored */ arcname = optarg; flg |= FF; break; case 'i': /* * interactive file rename */ iflag = 1; flg |= IF; break; case 'j': /* * use bzip2. Non standard option. */ gzip_program = BZIP2_CMD; break; case 'k': /* * do not clobber files that exist */ kflag = 1; flg |= KF; break; case 'l': /* * try to link src to dest with copy (-rw) */ lflag = 1; flg |= LF; break; case 'n': /* * select first match for a pattern only */ nflag = 1; flg |= NF; break; case 'o': /* * pass format specific options */ flg |= OF; if (opt_add(optarg) < 0) pax_usage(); break; case 'p': /* * specify file characteristic options */ for (pt = optarg; *pt != '\0'; ++pt) { switch (*pt) { case 'a': /* * do not preserve access time */ patime = 0; break; case 'e': /* * preserve user id, group id, file * mode, access/modification times */ pids = 1; pmode = 1; patime = 1; pmtime = 1; break; case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'o': /* * preserve uid/gid */ pids = 1; break; case 'p': /* * preserve file mode bits */ pmode = 1; break; default: paxwarn(1, "Invalid -p string: %c", *pt); pax_usage(); break; } } flg |= PF; break; case 'r': /* * read the archive */ flg |= RF; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { pax_usage(); break; } flg |= SF; break; case 't': /* * preserve access time on filesystem nodes we read */ tflag = 1; flg |= TF; break; case 'u': /* * ignore those older files */ uflag = 1; flg |= UF; break; case 'v': /* * verbose operation mode */ vflag = 1; flg |= VF; break; case 'w': /* * write an archive */ flg |= WF; break; case 'x': /* * specify an archive format on write */ for (i = 0; i < sizeof(fsub)/sizeof(FSUB); ++i) if (fsub[i].name != NULL && strcmp(fsub[i].name, optarg) == 0) break; if (i < sizeof(fsub)/sizeof(FSUB)) { frmt = &fsub[i]; flg |= XF; break; } paxwarn(1, "Unknown -x format: %s", optarg); (void)fputs("pax: Known -x formats are:", stderr); for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) if (fsub[i].name != NULL) (void)fprintf(stderr, " %s", fsub[i].name); (void)fputs("\n\n", stderr); pax_usage(); break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'B': /* * non-standard option on number of bytes written on a * single archive volume. */ if ((wrlimit = str_offt(optarg)) <= 0) { paxwarn(1, "Invalid write limit %s", optarg); pax_usage(); } if (wrlimit % BLKMULT) { paxwarn(1, "Write limit is not a %d byte multiple", BLKMULT); pax_usage(); } flg |= CBF; break; case 'D': /* * On extraction check file inode change time before the * modification of the file name. Non standard option. */ Dflag = 1; flg |= CDF; break; case 'E': /* * non-standard limit on read faults * 0 indicates stop after first error, values * indicate a limit, "NONE" try forever */ flg |= CEF; if (strcmp(NONE, optarg) == 0) maxflt = -1; else if ((maxflt = atoi(optarg)) < 0) { paxwarn(1, "Error count value must be positive"); pax_usage(); } break; case 'G': /* * non-standard option for selecting files within an * archive by group (gid or name) */ if (grp_add(optarg) < 0) { pax_usage(); break; } flg |= CGF; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; flg |= CHF; break; case 'L': /* * follow symlinks */ Lflag = 1; flg |= CLF; break; case 'O': /* * Force one volume. Non standard option. */ force_one_volume = 1; break; case 'P': /* * do NOT follow symlinks (default) */ Lflag = 0; flg |= CPF; break; case 'T': /* * non-standard option for selecting files within an * archive by modification time range (lower,upper) */ if (trng_add(optarg) < 0) { pax_usage(); break; } flg |= CTF; break; case 'U': /* * non-standard option for selecting files within an * archive by user (uid or name) */ if (usr_add(optarg) < 0) { pax_usage(); break; } flg |= CUF; break; case 'X': /* * do not pass over mount points in the file system */ Xflag = 1; flg |= CXF; break; case 'Y': /* * On extraction check file inode change time after the * modification of the file name. Non standard option. */ Yflag = 1; flg |= CYF; break; case 'Z': /* * On extraction check modification time after the * modification of the file name. Non standard option. */ Zflag = 1; flg |= CZF; break; case '0': /* * Use \0 as pathname terminator. * (For use with the -print0 option of find(1).) */ zeroflag = 1; flg |= C0F; break; default: pax_usage(); break; } } /* * figure out the operation mode of pax read,write,extract,copy,append * or list. check that we have not been given a bogus set of flags * for the operation mode. */ if (ISLIST(flg)) { act = LIST; listf = stdout; bflg = flg & BDLIST; } else if (ISEXTRACT(flg)) { act = EXTRACT; bflg = flg & BDEXTR; } else if (ISARCHIVE(flg)) { act = ARCHIVE; bflg = flg & BDARCH; } else if (ISAPPND(flg)) { act = APPND; bflg = flg & BDARCH; } else if (ISCOPY(flg)) { act = COPY; bflg = flg & BDCOPY; } else pax_usage(); if (bflg) { printflg(flg); pax_usage(); } /* * if we are writing (ARCHIVE) we use the default format if the user * did not specify a format. when we write during an APPEND, we will * adopt the format of the existing archive if none was supplied. */ if (!(flg & XF) && (act == ARCHIVE)) frmt = &(fsub[DEFLT]); /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: for (; optind < argc; optind++) if (pat_add(argv[optind], NULL) < 0) pax_usage(); break; case COPY: if (optind >= argc) { paxwarn(0, "Destination directory was not supplied"); pax_usage(); } --argc; dirptr = argv[argc]; /* FALL THROUGH */ case ARCHIVE: case APPND: for (; optind < argc; optind++) if (ftree_add(argv[optind], 0) < 0) pax_usage(); /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } }
IoObject *IoMessage_locals_listArgAt_(IoMessage *self, IoObject *locals, int n) { IoObject *v = IoMessage_locals_valueArgAt_(self, locals, n); if (!ISLIST(v)) IoMessage_locals_numberArgAt_errorForType_(self, locals, n, "List"); return v; }
Word FMAQEXTAF(Word F) { return (ISLIST(FIRST(F)) && ISLIST(SECOND(F))); }
static void pax_options(int argc, char **argv) { int c; size_t i; u_int64_t flg = 0; u_int64_t bflg = 0; char *pt; FSUB tmp; /* * process option flags */ while ((c = getopt_long(argc, argv, "0ab:cdf:ijklno:p:rs:tuvwx:zAB:DE:G:HLMN:OPT:U:VXYZ", pax_longopts, NULL)) != -1) { switch (c) { case '0': sep = '\0'; break; case 'a': /* * append */ flg |= AF; break; case 'b': /* * specify blocksize */ flg |= BF; if ((wrblksz = (int)str_offt(optarg)) <= 0) { tty_warn(1, "Invalid block size %s", optarg); pax_usage(); } break; case 'c': /* * inverse match on patterns */ cflag = 1; flg |= CF; break; case 'd': /* * match only dir on extract, not the subtree at dir */ dflag = 1; flg |= DF; break; case 'f': /* * filename where the archive is stored */ arcname = optarg; flg |= FF; break; case 'i': /* * interactive file rename */ iflag = 1; flg |= IF; break; case 'j': /* * pass through bzip2 */ gzip_program = BZIP2_CMD; break; case 'k': /* * do not clobber files that exist */ kflag = 1; flg |= KF; break; case 'l': /* * try to link src to dest with copy (-rw) */ lflag = 1; flg |= LF; break; case 'n': /* * select first match for a pattern only */ nflag = 1; flg |= NF; break; case 'o': /* * pass format specific options */ flg |= OF; if (opt_add(optarg) < 0) pax_usage(); break; case 'p': /* * specify file characteristic options */ for (pt = optarg; *pt != '\0'; ++pt) { switch(*pt) { case 'a': /* * do not preserve access time */ patime = 0; break; case 'e': /* * preserve user id, group id, file * mode, access/modification times * and file flags. */ pids = 1; pmode = 1; patime = 1; pmtime = 1; pfflags = 1; break; #if 0 case 'f': /* * do not preserve file flags */ pfflags = 0; break; #endif case 'm': /* * do not preserve modification time */ pmtime = 0; break; case 'o': /* * preserve uid/gid */ pids = 1; break; case 'p': /* * preserve file mode bits */ pmode = 1; break; default: tty_warn(1, "Invalid -p string: %c", *pt); pax_usage(); break; } } flg |= PF; break; case 'r': /* * read the archive */ flg |= RF; break; case 's': /* * file name substitution name pattern */ if (rep_add(optarg) < 0) { pax_usage(); break; } flg |= SF; break; case 't': /* * preserve access time on filesystem nodes we read */ tflag = 1; flg |= TF; break; case 'u': /* * ignore those older files */ uflag = 1; flg |= UF; break; case 'v': /* * verbose operation mode */ vflag = 1; flg |= VF; break; case 'w': /* * write an archive */ flg |= WF; break; case 'x': /* * specify an archive format on write */ tmp.name = optarg; frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub, sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt); if (frmt != NULL) { flg |= XF; break; } tty_warn(1, "Unknown -x format: %s", optarg); (void)fputs("pax: Known -x formats are:", stderr); for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) (void)fprintf(stderr, " %s", fsub[i].name); (void)fputs("\n\n", stderr); pax_usage(); break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'A': Aflag = 1; flg |= CAF; break; case 'B': /* * non-standard option on number of bytes written on a * single archive volume. */ if ((wrlimit = str_offt(optarg)) <= 0) { tty_warn(1, "Invalid write limit %s", optarg); pax_usage(); } if (wrlimit % BLKMULT) { tty_warn(1, "Write limit is not a %d byte multiple", BLKMULT); pax_usage(); } flg |= CBF; break; case 'D': /* * On extraction check file inode change time before the * modification of the file name. Non standard option. */ Dflag = 1; flg |= CDF; break; case 'E': /* * non-standard limit on read faults * 0 indicates stop after first error, values * indicate a limit, "none" try forever */ flg |= CEF; if (strcmp(none, optarg) == 0) maxflt = -1; else if ((maxflt = atoi(optarg)) < 0) { tty_warn(1, "Error count value must be positive"); pax_usage(); } break; case 'G': /* * non-standard option for selecting files within an * archive by group (gid or name) */ if (grp_add(optarg) < 0) { pax_usage(); break; } flg |= CGF; break; case 'H': /* * follow command line symlinks only */ Hflag = 1; flg |= CHF; break; case 'L': /* * follow symlinks */ Lflag = 1; flg |= CLF; break; #ifdef SMALL case 'M': case 'N': tty_warn(1, "Support for -%c is not compiled in", c); exit(1); #else /* !SMALL */ case 'M': /* * Treat list of filenames on stdin as an * mtree(8) specfile. Non standard option. */ Mflag = 1; flg |= CMF; break; case 'N': /* * Use alternative directory for user db lookups. */ if (!setup_getid(optarg)) { tty_warn(1, "Unable to use user and group databases in `%s'", optarg); pax_usage(); } break; #endif /* !SMALL */ case 'O': /* * Force one volume. Non standard option. */ force_one_volume = 1; break; case 'P': /* * do NOT follow symlinks (default) */ Lflag = 0; flg |= CPF; break; case 'T': /* * non-standard option for selecting files within an * archive by modification time range (lower,upper) */ if (trng_add(optarg) < 0) { pax_usage(); break; } flg |= CTF; break; case 'U': /* * non-standard option for selecting files within an * archive by user (uid or name) */ if (usr_add(optarg) < 0) { pax_usage(); break; } flg |= CUF; break; case 'V': /* * somewhat verbose operation mode (no listing) */ Vflag = 1; flg |= VSF; break; case 'X': /* * do not pass over mount points in the file system */ Xflag = 1; flg |= CXF; break; case 'Y': /* * On extraction check file inode change time after the * modification of the file name. Non standard option. */ Yflag = 1; flg |= CYF; break; case 'Z': /* * On extraction check modification time after the * modification of the file name. Non standard option. */ Zflag = 1; flg |= CZF; break; case OPT_INSECURE: secure = 0; break; case OPT_FORCE_LOCAL: forcelocal = 1; break; case OPT_USE_COMPRESS_PROGRAM: gzip_program = optarg; break; case OPT_XZ: gzip_program = XZ_CMD; break; case OPT_GNU: is_gnutar = 1; break; case '?': default: pax_usage(); break; } } /* * figure out the operation mode of pax read,write,extract,copy,append * or list. check that we have not been given a bogus set of flags * for the operation mode. */ if (ISLIST(flg)) { act = LIST; listf = stdout; bflg = flg & BDLIST; } else if (ISEXTRACT(flg)) { act = EXTRACT; bflg = flg & BDEXTR; } else if (ISARCHIVE(flg)) { act = ARCHIVE; bflg = flg & BDARCH; } else if (ISAPPND(flg)) { act = APPND; bflg = flg & BDARCH; } else if (ISCOPY(flg)) { act = COPY; bflg = flg & BDCOPY; } else pax_usage(); if (bflg) { printflg(flg); pax_usage(); } /* * if we are writing (ARCHIVE) we use the default format if the user * did not specify a format. when we write during an APPEND, we will * adopt the format of the existing archive if none was supplied. */ if (!(flg & XF) && (act == ARCHIVE)) frmt = &(fsub[DEFLT]); /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: for (; optind < argc; optind++) if (pat_add(argv[optind], NULL, 0) < 0) pax_usage(); break; case COPY: if (optind >= argc) { tty_warn(0, "Destination directory was not supplied"); pax_usage(); } --argc; dirptr = argv[argc]; if (mkpath(dirptr) < 0) exit(1); /* FALLTHROUGH */ case ARCHIVE: case APPND: for (; optind < argc; optind++) if (ftree_add(argv[optind], 0) < 0) pax_usage(); /* * no read errors allowed on updates/append operation! */ maxflt = 0; break; } }
bool bpx_is_list(TERM t) { XDEREF(t); return ISLIST(t); }
static void cpio_options(int argc, char **argv) { FSUB tmp; u_int64_t flg = 0; u_int64_t bflg = 0; int c; size_t i; FILE *fp; char *str; uflag = 1; kflag = 1; pids = 1; pmode = 1; pmtime = 0; arcname = NULL; dflag = 1; nodirs = 1; /* * process option flags */ while ((c = getoldopt(argc, argv, "+abcdfiklmoprstuvzABC:E:F:H:I:LM:O:R:SVZ6", cpio_longopts, NULL)) != -1) { switch(c) { case 'a': /* * preserve access time on filesystem nodes we read */ tflag = 1; flg |= TF; break; #ifdef notyet case 'b': /* * swap bytes and half-words when reading data */ break; #endif case 'c': /* * ASCII cpio header */ frmt = &fsub[F_SV4CPIO]; break; case 'd': /* * create directories as needed * pax does this by default .. */ nodirs = 0; break; case 'f': /* * inverse match on patterns */ cflag = 1; flg |= CF; break; case 'i': /* * read the archive */ cpio_set_action(EXTRACT); flg |= RF; break; #ifdef notyet case 'k': break; #endif case 'l': /* * try to link src to dest with copy (-rw) */ lflag = 1; flg |= LF; break; case 'm': /* * preserve mtime */ flg |= PF; pmtime = 1; break; case 'o': /* * write an archive */ cpio_set_action(ARCHIVE); frmt = &(fsub[F_SV4CRC]); flg |= WF; break; case 'p': /* * cpio -p is like pax -rw */ cpio_set_action(COPY); flg |= RF | WF; break; case 'r': /* * interactive file rename */ iflag = 1; flg |= IF; break; #ifdef notyet case 's': /* * swap bytes after reading data */ break; #endif case 't': /* * list contents of archive */ cpio_set_action(LIST); listf = stdout; flg &= ~RF; break; case 'u': /* * don't ignore those older files */ uflag = 0; kflag = 0; flg |= UF; break; case 'v': /* * verbose operation mode */ vflag = 1; flg |= VF; break; case 'z': /* * use gzip. Non standard option. */ gzip_program = GZIP_CMD; break; case 'A': /* * append to an archive */ cpio_set_action(APPND); flg |= AF; break; case 'B': /* * set blocksize to 5120 */ blksz = 5120; break; case 'C': /* * specify blocksize */ if ((blksz = (int)str_offt(optarg)) <= 0) { tty_warn(1, "Invalid block size %s", optarg); cpio_usage(); } break; case 'E': /* * file with patterns to extract or list */ if ((fp = fopen(optarg, "r")) == NULL) { tty_warn(1, "Unable to open file '%s' for read", optarg); cpio_usage(); } while ((str = get_line(fp)) != NULL) { pat_add(str, NULL, 0); } fclose(fp); if (get_line_error) { tty_warn(1, "Problem with file '%s'", optarg); cpio_usage(); } break; case 'H': /* * specify an archive format on write */ tmp.name = optarg; frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub, sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt); if (frmt != NULL) { flg |= XF; break; } tty_warn(1, "Unknown -H format: %s", optarg); (void)fputs("cpio: Known -H formats are:", stderr); for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) (void)fprintf(stderr, " %s", fsub[i].name); (void)fputs("\n\n", stderr); cpio_usage(); break; case 'F': case 'I': case 'O': /* * filename where the archive is stored */ if ((optarg[0] == '-') && (optarg[1]== '\0')) { /* * treat a - as stdin */ arcname = NULL; break; } arcname = optarg; break; case 'L': /* * follow symlinks */ Lflag = 1; flg |= CLF; break; #ifdef notyet case 'M': arg = optarg; break; case 'R': arg = optarg; break; #endif case 'S': /* * swap halfwords after reading data */ cpio_swp_head = 1; break; #ifdef notyet case 'V': /* print a '.' for each file processed */ break; #endif case 'V': /* * semi-verbose operation mode (no listing) */ Vflag = 1; flg |= VF; break; case 'Z': /* * use compress. Non standard option. */ gzip_program = COMPRESS_CMD; break; case '6': /* * process Version 6 cpio format */ frmt = &(fsub[F_BCPIO]); break; case OPT_FORCE_LOCAL: forcelocal = 1; break; case OPT_INSECURE: secure = 0; break; case OPT_SPARSE: /* do nothing; we already generate sparse files */ break; case OPT_XZ: gzip_program = XZ_CMD; break; default: cpio_usage(); break; } } /* * figure out the operation mode of cpio. check that we have not been * given a bogus set of flags for the operation mode. */ if (ISLIST(flg)) { act = LIST; bflg = flg & BDLIST; } else if (ISEXTRACT(flg)) { act = EXTRACT; bflg = flg & BDEXTR; } else if (ISARCHIVE(flg)) { act = ARCHIVE; bflg = flg & BDARCH; } else if (ISAPPND(flg)) { act = APPND; bflg = flg & BDARCH; } else if (ISCOPY(flg)) { act = COPY; bflg = flg & BDCOPY; } else cpio_usage(); if (bflg) { cpio_usage(); } /* * if we are writing (ARCHIVE) we use the default format if the user * did not specify a format. when we write during an APPEND, we will * adopt the format of the existing archive if none was supplied. */ if (!(flg & XF) && (act == ARCHIVE)) frmt = &(fsub[F_BCPIO]); /* * process the args as they are interpreted by the operation mode */ switch (act) { case LIST: case EXTRACT: for (; optind < argc; optind++) if (pat_add(argv[optind], NULL, 0) < 0) cpio_usage(); break; case COPY: if (optind >= argc) { tty_warn(0, "Destination directory was not supplied"); cpio_usage(); } --argc; dirptr = argv[argc]; /* FALLTHROUGH */ case ARCHIVE: case APPND: if (argc != optind) { for (; optind < argc; optind++) if (ftree_add(argv[optind], 0) < 0) cpio_usage(); break; } /* * no read errors allowed on updates/append operation! */ maxflt = 0; while ((str = get_line(stdin)) != NULL) { ftree_add(str, 0); } if (get_line_error) { tty_warn(1, "Problem while reading stdin"); cpio_usage(); } break; default: cpio_usage(); break; } }