|
|
1.1 root 1: /* move.c - */
2:
3: #ifndef lint
4: static char *rcsid = "$Header: /f/osi/quipu/dish/RCS/move.c,v 7.0 89/11/23 22:20:16 mrose Rel $";
5: #endif
6:
7: /*
8: * $Header: /f/osi/quipu/dish/RCS/move.c,v 7.0 89/11/23 22:20:16 mrose Rel $
9: *
10: *
11: * $Log: move.c,v $
12: * Revision 7.0 89/11/23 22:20:16 mrose
13: * Release 6.0
14: *
15: */
16:
17: /*
18: * NOTICE
19: *
20: * Acquisition, use, and distribution of this module and related
21: * materials are subject to the restrictions of a license agreement.
22: * Consult the Preface in the User's Manual for the full terms of
23: * this agreement.
24: *
25: */
26:
27:
28: #include "quipu/util.h"
29: #include "quipu/name.h"
30:
31: extern DN dn;
32:
33: #define OPT (!frompipe || rps -> ps_byteno == 0 ? opt : rps)
34: #define RPS (!frompipe || opt -> ps_byteno == 0 ? rps : opt)
35: extern char frompipe;
36: extern PS opt, rps;
37:
38: extern char move_flag;
39:
40: DN fixed_pos = NULLDN;
41:
42: call_moveto (argc,argv)
43: int argc;
44: char ** argv;
45: {
46: char pwd_flag = FALSE;
47: char check_move = TRUE;
48: int x;
49:
50: if (argc == 1) {
51: Usage (argv[0]);
52: return;
53: }
54:
55: move_flag = FALSE;
56:
57: for (x = 1; x < argc; x++) {
58: if (test_arg (argv[x],"-pwd",1))
59: pwd_flag = TRUE;
60: else if (test_arg (argv[x],"-nopwd",3))
61: pwd_flag = FALSE;
62: else if (test_arg (argv[x],"-check",1))
63: check_move = TRUE;
64: else if (test_arg (argv[x],"-nocheck",3))
65: check_move = FALSE;
66: else if (test_arg (argv[x], "-sequence",3)) {
67: if (x + 1 == argc) {
68: ps_printf (OPT, "We need a sequence name.\n");
69: return;
70: } else {
71: shuffle_up (argc--, argv, x);
72: set_sequence (argv[x]);
73: }
74: } else if (move (argv[x]) == OK) {
75: if (move_flag == TRUE) {
76: ps_print (RPS,"Too many parameters !\n");
77: Usage (argv[0]);
78: return;
79: }
80: move_flag = TRUE;
81: } else {
82: move_flag = FALSE;
83: if (*argv[x] != '-')
84: ps_printf (OPT,"Unknown entity '%s'\n",argv[x]);
85: else
86: Usage (argv[0]);
87: return;
88: }
89: }
90:
91: if (check_move)
92: if (test_move_dn() != TRUE) {
93: move_flag = FALSE;
94: return;
95: }
96:
97: if (move_flag == TRUE)
98: consolidate_move ();
99:
100: if (pwd_flag) {
101: dn_print (RPS, fixed_pos, EDBOUT);
102: ps_print (RPS, "\n");
103: }
104:
105: }
106:
107: consolidate_move ()
108: {
109: if (move_flag) {
110: move_flag = FALSE;
111: dn_free (fixed_pos);
112: fixed_pos = dn_cpy (dn);
113: }
114: }
115:
116: set_current_pos ()
117: {
118: move_flag = FALSE;
119: dn_free (dn);
120: dn = dn_cpy (fixed_pos);
121: }
122:
123: move (arg)
124: char *arg;
125: {
126: extern int print_parse_errors;
127:
128: DN user_down ();
129: DN str2dn_aux ();
130: DN sequence_dn();
131: DN tmpdn;
132: char * ptr;
133: char alias = FALSE;
134:
135: print_parse_errors = FALSE;
136:
137: if (*arg == '-') {
138: print_parse_errors = TRUE;
139: return (NOTOK); /* can't be a move if it starts with a minus */
140: }
141:
142: if (*arg == '+')
143: arg++; /* old style call */
144:
145: ptr = arg;
146: while (*ptr != 0) {
147: if (! isdigit (*ptr))
148: break;
149: ptr++;
150: }
151:
152: if (*ptr == 0) {
153: /* sequence move */
154: dn_free (dn);
155: dn = dn_cpy (sequence_dn(atoi(arg)));
156: print_parse_errors = TRUE;
157: if (dn == NULLDN) {
158: ps_printf (OPT,"Invalid sequence number %s\n",arg);
159: return (NOTOK);
160: } else
161: return (OK);
162: }
163:
164: if ((ptr = index (arg,'@')) != NULLCP) {
165: *ptr = 0;
166:
167: if (*arg == 0) {
168: /* from root */
169: dn_free (dn);
170: dn = NULLDN;
171: *ptr ='@';
172: arg = ++ptr;
173: if (*arg == 0) {
174: print_parse_errors = TRUE;
175: return (OK); /* @ -> move to root */
176: }
177: if ((ptr = index (arg,'@')) != NULLCP)
178: *ptr = 0;
179: }
180: } else {
181: dn_free (dn);
182: dn = dn_cpy (fixed_pos);
183: }
184:
185: if (strcmp (arg,"..") == 0) {
186: do {
187: DN dnptr;
188: DN trail;
189:
190: if (dn == NULLDN) {
191: print_parse_errors = TRUE;
192: ps_print (OPT, "Can't go back past root\n");
193: return (NOTOK);
194: }
195: if (dn->dn_parent == NULLDN) {
196: dn_free (dn);
197: dn = NULLDN;
198: } else {
199: for (dnptr = dn; dnptr->dn_parent != NULLDN; dnptr = dnptr->dn_parent)
200: trail = dnptr;
201:
202: dn_comp_free (dnptr);
203: trail->dn_parent = NULLDN;
204: }
205: if (ptr == NULLCP) {
206: print_parse_errors = TRUE;
207: return (OK);
208: }
209: arg = ++ptr;
210: if ((ptr = index (arg,'@')) != NULLCP)
211: *ptr = 0;
212: } while (strcmp (arg,"..") == 0);
213: }
214:
215: if (ptr != NULL)
216: *ptr = '@';
217:
218: if ((tmpdn = str2dn_aux (arg,&alias)) != NULLDN) {
219: if (dn == NULLDN)
220: dn = tmpdn;
221: else {
222: if (alias) {
223: dn_free (dn);
224: dn = tmpdn;
225: } else
226: dn_append (dn,tmpdn);
227: }
228: print_parse_errors = TRUE;
229: return (OK);
230: } else {
231: print_parse_errors = TRUE;
232: return (NOTOK);
233: }
234:
235: }
236:
237: test_move_dn ()
238: {
239: char * name = "moveto";
240:
241: /* Might do something else here... */
242: /* current policy is to read the entry and cache it ! */
243:
244: if (dn == NULLDN)
245: return (TRUE); /* assume root exists - read will fail */
246:
247: return (read_cache (1,&name));
248: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.