Lines 1-10
Link Here
|
1 |
/* |
|
|
2 |
$Header: /fs/mumon/aware/piercarl/Cmd./Commands./team.c,v 3.1 1994/01/13 15:03:25 piercarl Exp piercarl $ |
3 |
*/ |
4 |
|
1 |
|
5 |
static char Notice[] = |
2 |
static char Notice[] = |
6 |
"Copyright 1987,1989 Piercarlo Grandi. All rights reserved."; |
3 |
"Copyright 1987,1989 Piercarlo Grandi. All rights reserved."; |
7 |
|
4 |
|
|
|
5 |
static char Notice2[] = |
6 |
"Copyright 2021 David Gilbert. All rights reserved."; |
7 |
|
8 |
/* |
8 |
/* |
9 |
This program is free software; you can redistribute it and/or |
9 |
This program is free software; you can redistribute it and/or |
10 |
modify it under the terms of the GNU General Public License as |
10 |
modify it under the terms of the GNU General Public License as |
Lines 118-124
Link Here
|
118 |
#else |
118 |
#else |
119 |
# define call (void) |
119 |
# define call (void) |
120 |
# define were if |
120 |
# define were if |
121 |
# define fast register |
|
|
122 |
# define global /* extern */ |
121 |
# define global /* extern */ |
123 |
# define local static |
122 |
# define local static |
124 |
# define when break; case |
123 |
# define when break; case |
Lines 129-140
Link Here
|
129 |
# define false 0 |
128 |
# define false 0 |
130 |
# define nil(type) ((type) 0) |
129 |
# define nil(type) ((type) 0) |
131 |
# define scalar int |
130 |
# define scalar int |
132 |
typedef char *pointer; |
131 |
|
133 |
# if (defined(SMALL_M)) |
132 |
typedef void *pointer; |
134 |
typedef unsigned address; |
133 |
typedef size_t address; |
135 |
# else |
134 |
|
136 |
typedef long address; |
|
|
137 |
# endif |
138 |
# if (__STDC__) |
135 |
# if (__STDC__) |
139 |
# define of(list) list |
136 |
# define of(list) list |
140 |
# define on(list) |
137 |
# define on(list) |
Lines 162-168
Link Here
|
162 |
void mesg(char *a, ...) |
159 |
void mesg(char *a, ...) |
163 |
{ |
160 |
{ |
164 |
va_list ap; |
161 |
va_list ap; |
165 |
|
162 |
char buf[256]; |
|
|
163 |
|
166 |
va_start(ap, a); |
164 |
va_start(ap, a); |
167 |
|
165 |
|
168 |
# if (defined F_SETLKW) |
166 |
# if (defined F_SETLKW) |
Lines 173-179
Link Here
|
173 |
# if (defined LOCK_EX) |
171 |
# if (defined LOCK_EX) |
174 |
flock(fileno(stderr),LOCK_EX); |
172 |
flock(fileno(stderr),LOCK_EX); |
175 |
# endif |
173 |
# endif |
176 |
vfprintf(stderr,a,ap); |
174 |
snprintf(buf, sizeof(buf), "%d: %s", getpid(), a); |
|
|
175 |
vfprintf(stderr,buf,ap); |
177 |
# if (defined LOCK_EX) |
176 |
# if (defined LOCK_EX) |
178 |
flock(fileno(stderr),LOCK_UN); |
177 |
flock(fileno(stderr),LOCK_UN); |
179 |
# endif |
178 |
# endif |
Lines 182-193
Link Here
|
182 |
# endif |
181 |
# endif |
183 |
} |
182 |
} |
184 |
|
183 |
|
185 |
local bool verbose = false; |
184 |
static bool verbose = false; |
186 |
local bool report = true; |
185 |
static bool report = true; |
187 |
local bool guyhaderror = false; |
186 |
static bool guyhaderror = false; |
188 |
|
187 |
|
189 |
// extern int errno; |
188 |
// extern int errno; |
190 |
local time_t origin; |
189 |
static time_t origin; |
191 |
|
190 |
|
192 |
|
191 |
|
193 |
/* |
192 |
/* |
Lines 209-222
Link Here
|
209 |
UOFF_T size; |
208 |
UOFF_T size; |
210 |
}; |
209 |
}; |
211 |
|
210 |
|
212 |
local Fd FdIn,FdOut; |
211 |
static Fd FdIn,FdOut; |
213 |
|
212 |
|
214 |
local bool FdOpen on((fd,ffd,size)) is |
213 |
static bool FdOpen (Fd *fd, int ffd, UOFF_T size) |
215 |
( |
|
|
216 |
fast Fd *fd |
217 |
_ int ffd |
218 |
_ UOFF_T size |
219 |
) |
220 |
{ |
214 |
{ |
221 |
fd->status = (ffd >= 0) ? FdOPEN : FdCLOSED; |
215 |
fd->status = (ffd >= 0) ? FdOPEN : FdCLOSED; |
222 |
fd->fd = ffd; |
216 |
fd->fd = ffd; |
Lines 227-236
Link Here
|
227 |
return ffd >= 0; |
221 |
return ffd >= 0; |
228 |
} |
222 |
} |
229 |
|
223 |
|
230 |
local bool FdClose on((fd)) is |
224 |
static bool FdClose(Fd *fd) |
231 |
( |
|
|
232 |
fast Fd *fd |
233 |
) |
234 |
{ |
225 |
{ |
235 |
int ffd; |
226 |
int ffd; |
236 |
|
227 |
|
Lines 242-252
Link Here
|
242 |
return close(ffd) >= 0; |
233 |
return close(ffd) >= 0; |
243 |
} |
234 |
} |
244 |
|
235 |
|
245 |
local bool FdCopy on((to,from)) is |
236 |
static bool FdCopy(Fd *to, Fd *from) |
246 |
( |
|
|
247 |
fast Fd *to |
248 |
_ fast Fd *from |
249 |
) |
250 |
{ |
237 |
{ |
251 |
to->size = from->size; |
238 |
to->size = from->size; |
252 |
to->status = from->status; |
239 |
to->status = from->status; |
Lines 255-265
Link Here
|
255 |
return to->fd >= 0; |
242 |
return to->fd >= 0; |
256 |
} |
243 |
} |
257 |
|
244 |
|
258 |
local void FdSet on((to,from)) is |
245 |
static void FdSet(Fd *to, Fd *from) |
259 |
( |
|
|
260 |
fast Fd *to |
261 |
_ fast Fd *from |
262 |
) |
263 |
{ |
246 |
{ |
264 |
if (from->fd < 0) |
247 |
if (from->fd < 0) |
265 |
mesg("team: set an invalid fd\n"); |
248 |
mesg("team: set an invalid fd\n"); |
Lines 268-280
Link Here
|
268 |
to->fd = from->fd; |
251 |
to->fd = from->fd; |
269 |
} |
252 |
} |
270 |
|
253 |
|
271 |
local UOFF_T FdRetry on((fd,which,done,space)) is |
254 |
static UOFF_T FdRetry(Fd *fd, char *which, UOFF_T done, UOFF_T space) |
272 |
( |
|
|
273 |
fast Fd *fd |
274 |
_ char *which |
275 |
_ UOFF_T done |
276 |
_ UOFF_T space |
277 |
) |
278 |
{ |
255 |
{ |
279 |
int tty; |
256 |
int tty; |
280 |
char reply[2]; |
257 |
char reply[2]; |
Lines 314-322
Link Here
|
314 |
(void) sprintf(errmsg,"Error %d",errno); |
291 |
(void) sprintf(errmsg,"Error %d",errno); |
315 |
#endif |
292 |
#endif |
316 |
if (errno) |
293 |
if (errno) |
317 |
mesg("'%s' on %s after %quk. Continue [cyn] ? ",errmsg,which,done>>10); |
294 |
mesg("'%s' on %s after %luM. Continue [cyn] ? ",errmsg,which,done>>20); |
318 |
else |
295 |
else |
319 |
mesg("EOF on %s after %quk. Continue [cyn] ? ",which,done>>10); |
296 |
mesg("EOF on %s after %luM. Continue [cyn] ? ",which,done>>20); |
320 |
|
297 |
|
321 |
read(tty,reply,sizeof reply); |
298 |
read(tty,reply,sizeof reply); |
322 |
} |
299 |
} |
Lines 338-364
Link Here
|
338 |
return space; |
315 |
return space; |
339 |
} |
316 |
} |
340 |
|
317 |
|
341 |
local unsigned FdCanDo on((remaining,available)) is |
318 |
static unsigned FdCanDo(address remaining, UOFF_T available) |
342 |
( |
|
|
343 |
fast address remaining |
344 |
_ fast UOFF_T available |
345 |
) |
346 |
{ |
319 |
{ |
347 |
return (remaining < available) |
320 |
return (remaining < available) |
348 |
? (unsigned) remaining : (unsigned) available; |
321 |
? (unsigned) remaining : (unsigned) available; |
349 |
} |
322 |
} |
350 |
|
323 |
|
351 |
local address FdRead on((fd,buffer,todo,done)) is |
324 |
static address FdRead(Fd *fd, pointer buffer, address todo, UOFF_T done) |
352 |
( |
|
|
353 |
fast Fd *fd |
354 |
_ pointer buffer |
355 |
_ fast address todo |
356 |
_ UOFF_T done |
357 |
) |
358 |
{ |
325 |
{ |
359 |
fast UOFF_T space; |
326 |
UOFF_T space; |
360 |
fast int bytesRead; |
327 |
int bytesRead; |
361 |
fast address justDone; |
328 |
address justDone; |
362 |
|
329 |
|
363 |
switch (fd->status) |
330 |
switch (fd->status) |
364 |
{ |
331 |
{ |
Lines 390-406
Link Here
|
390 |
assert(0); |
357 |
assert(0); |
391 |
} |
358 |
} |
392 |
|
359 |
|
393 |
local address FdWrite on((fd,buffer,todo,done)) is |
360 |
static address FdWrite(Fd *fd, pointer buffer, address todo, UOFF_T done) |
394 |
( |
|
|
395 |
fast Fd *fd |
396 |
_ pointer buffer |
397 |
_ fast address todo |
398 |
_ UOFF_T done |
399 |
) |
400 |
{ |
361 |
{ |
401 |
fast UOFF_T space; |
362 |
UOFF_T space; |
402 |
fast int bytesWritten; |
363 |
size_t bytesWritten; |
403 |
fast address justDone; |
364 |
address justDone; |
404 |
|
365 |
|
405 |
switch (fd->status) |
366 |
switch (fd->status) |
406 |
{ |
367 |
{ |
Lines 409-424
Link Here
|
409 |
when FdCLOSED: return -1; |
370 |
when FdCLOSED: return -1; |
410 |
|
371 |
|
411 |
when FdOPEN: |
372 |
when FdOPEN: |
412 |
|
|
|
413 |
space = fd->size - done%fd->size; |
373 |
space = fd->size - done%fd->size; |
414 |
|
374 |
|
|
|
375 |
Mesg(("FdWrite %d going to write %p %d bytes last %d\n",fd->fd,buffer,todo,bytesWritten)); |
376 |
|
415 |
for (justDone = 0; space != 0L && justDone < todo;) |
377 |
for (justDone = 0; space != 0L && justDone < todo;) |
416 |
{ |
378 |
{ |
417 |
bytesWritten = write(fd->fd,buffer+justDone, |
379 |
bytesWritten = write(fd->fd,buffer+justDone, |
418 |
FdCanDo(todo-justDone,space-justDone)); |
380 |
FdCanDo(todo-justDone,space-justDone)); |
419 |
|
381 |
|
420 |
if (bytesWritten <= 0 || (justDone += bytesWritten) == space) |
382 |
if (bytesWritten <= 0 || (justDone += bytesWritten) == space) |
421 |
space = FdRetry(fd,"output",done+justDone,space-justDone); |
383 |
space = FdRetry(fd,"output",done+justDone,space-justDone); |
422 |
} |
384 |
} |
423 |
|
385 |
|
424 |
Mesg(("FdWrite %d writes %d last %d\n",fd->fd,justDone,bytesWritten)); |
386 |
Mesg(("FdWrite %d writes %d last %d\n",fd->fd,justDone,bytesWritten)); |
Lines 452-462
Link Here
|
452 |
abstraction for input and output... |
414 |
abstraction for input and output... |
453 |
*/ |
415 |
*/ |
454 |
|
416 |
|
455 |
local bool StreamPipe on((downstream,upstream)) is |
417 |
static bool StreamPipe(Fd *downstream, Fd *upstream) |
456 |
( |
|
|
457 |
fast Fd *downstream |
458 |
_ fast Fd *upstream |
459 |
) |
460 |
{ |
418 |
{ |
461 |
int links[2]; |
419 |
int links[2]; |
462 |
|
420 |
|
Lines 479-493
Link Here
|
479 |
UOFF_T done; |
437 |
UOFF_T done; |
480 |
}; |
438 |
}; |
481 |
|
439 |
|
482 |
local bool StreamSend on((fd,token,status,done)) is |
440 |
static bool StreamSend(Fd *fd, Token token, short status, UOFF_T done) |
483 |
( |
|
|
484 |
fast Fd *fd |
485 |
_ Token token |
486 |
_ short status |
487 |
_ UOFF_T done |
488 |
) |
489 |
{ |
441 |
{ |
490 |
fast int n; |
442 |
int n; |
491 |
StreamMsg message; |
443 |
StreamMsg message; |
492 |
|
444 |
|
493 |
message.token = token; |
445 |
message.token = token; |
Lines 501-515
Link Here
|
501 |
return n == sizeof message; |
453 |
return n == sizeof message; |
502 |
} |
454 |
} |
503 |
|
455 |
|
504 |
local bool StreamReceive on((fd,tokenp,statusp,donep)) is |
456 |
static bool StreamReceive(Fd *fd, Token *tokenp, short *statusp, UOFF_T *donep) |
505 |
( |
|
|
506 |
fast Fd *fd |
507 |
_ Token *tokenp |
508 |
_ short *statusp |
509 |
_ UOFF_T *donep |
510 |
) |
511 |
{ |
457 |
{ |
512 |
fast int n; |
458 |
int n; |
513 |
StreamMsg message; |
459 |
StreamMsg message; |
514 |
|
460 |
|
515 |
n = read(fd->fd,(pointer) &message,(unsigned) sizeof message); |
461 |
n = read(fd->fd,(pointer) &message,(unsigned) sizeof message); |
Lines 535-547
Link Here
|
535 |
Fd downStream; |
481 |
Fd downStream; |
536 |
}; |
482 |
}; |
537 |
|
483 |
|
538 |
local bool GuyOpen on((guy,pid,upstream,downstream)) is |
484 |
static bool GuyOpen(Guy *guy, int pid, Fd *upstream, Fd *downstream) |
539 |
( |
|
|
540 |
fast Guy *guy |
541 |
_ int pid |
542 |
_ Fd *upstream |
543 |
_ Fd *downstream |
544 |
) |
545 |
{ |
485 |
{ |
546 |
Mesg(("GuyOpen pid %u upstream %u downstream %u\n", |
486 |
Mesg(("GuyOpen pid %u upstream %u downstream %u\n", |
547 |
pid,upstream->fd,downstream->fd)); |
487 |
pid,upstream->fd,downstream->fd)); |
Lines 559-580
Link Here
|
559 |
#define GuyRECEIVE(guy,tokenp,statusp,donep) \ |
499 |
#define GuyRECEIVE(guy,tokenp,statusp,donep) \ |
560 |
StreamReceive(&guy->upStream,tokenp,statusp,donep) |
500 |
StreamReceive(&guy->upStream,tokenp,statusp,donep) |
561 |
|
501 |
|
562 |
local bool GuyStop of((Guy *,char *,UOFF_T)); |
502 |
static bool GuyStop(Guy *,char *,UOFF_T); |
563 |
|
503 |
|
564 |
local bool GuyStart on((guy,bufsize)) is |
504 |
static bool GuyStart(Guy *guy, address bufsize) |
565 |
( |
|
|
566 |
fast Guy *guy |
567 |
_ address bufsize |
568 |
) |
569 |
{ |
505 |
{ |
570 |
fast char *buffer; |
506 |
char *buffer; |
571 |
Token token; |
507 |
Token token; |
572 |
short status; |
508 |
short status; |
573 |
UOFF_T done; |
509 |
UOFF_T done; |
574 |
bool received; |
510 |
bool received; |
575 |
static int bytesRead,bytesWritten; |
511 |
static int bytesRead,bytesWritten; |
576 |
|
512 |
|
577 |
Mesg(("GuyStart guy %#o bufsize %u\n",guy,bufsize)); |
513 |
Mesg(("GuyStart guy %p bufsize %u\n",guy,bufsize)); |
578 |
|
514 |
|
579 |
buffer = (pointer) malloc((unsigned) bufsize); |
515 |
buffer = (pointer) malloc((unsigned) bufsize); |
580 |
if (buffer == nil(pointer)) |
516 |
if (buffer == nil(pointer)) |
Lines 600-606
Link Here
|
600 |
done += bytesRead; |
536 |
done += bytesRead; |
601 |
|
537 |
|
602 |
if (verbose) |
538 |
if (verbose) |
603 |
mesg("%quk read \r",done>>10); |
539 |
mesg("%luk read \r",done>>10); |
604 |
|
540 |
|
605 |
if (!GuySEND(guy,TokenREAD,FdIn.status,done)) |
541 |
if (!GuySEND(guy,TokenREAD,FdIn.status,done)) |
606 |
GuyStop(guy,"guy cannot send READ",done); |
542 |
GuyStop(guy,"guy cannot send READ",done); |
Lines 618-624
Link Here
|
618 |
done += bytesWritten; |
554 |
done += bytesWritten; |
619 |
|
555 |
|
620 |
if (verbose) |
556 |
if (verbose) |
621 |
mesg("%quk written\r",done>>10); |
557 |
mesg("%luk written\r",done>>10); |
622 |
|
558 |
|
623 |
if (!GuySEND(guy,TokenWRITE,FdOut.status,done)) |
559 |
if (!GuySEND(guy,TokenWRITE,FdOut.status,done)) |
624 |
GuyStop(guy,"guy cannot send WRITE",done); |
560 |
GuyStop(guy,"guy cannot send WRITE",done); |
Lines 639-658
Link Here
|
639 |
/*return true;*/ |
575 |
/*return true;*/ |
640 |
} |
576 |
} |
641 |
|
577 |
|
642 |
local bool GuyStop on((guy,errormsg,done)) is |
578 |
static bool GuyStop(Guy *guy, char *errormsg, UOFF_T done) |
643 |
( |
|
|
644 |
fast Guy *guy |
645 |
_ char *errormsg |
646 |
_ UOFF_T done |
647 |
) |
648 |
{ |
579 |
{ |
649 |
Mesg(("GuyStop guy %#o\n",guy)); |
580 |
Mesg(("GuyStop guy %p\n",guy)); |
650 |
|
581 |
|
651 |
if (done) |
582 |
if (done) |
652 |
{ |
583 |
{ |
653 |
if (report) |
584 |
if (report) |
654 |
mesg("%qu kilobytes, %lu seconds\r\n", |
585 |
mesg("%qu kilobytes, %lu seconds\r\n", |
655 |
done>>10,(UOFF_T) (time((time_t *) 0)-origin)); |
586 |
done>>10,(UOFF_T) (time((time_t *) 0)-origin)); |
656 |
else if (verbose) |
587 |
else if (verbose) |
657 |
mesg("\n"); |
588 |
mesg("\n"); |
658 |
} |
589 |
} |
Lines 675-684
Link Here
|
675 |
/*NOTREACHED*/ |
606 |
/*NOTREACHED*/ |
676 |
} |
607 |
} |
677 |
|
608 |
|
678 |
local bool GuyClose on((guy)) is |
609 |
static bool GuyClose(Guy *guy) |
679 |
( |
|
|
680 |
fast Guy *guy |
681 |
) |
682 |
{ |
610 |
{ |
683 |
return FdClose(&guy->upStream) && FdClose(&guy->downStream); |
611 |
return FdClose(&guy->upStream) && FdClose(&guy->downStream); |
684 |
} |
612 |
} |
Lines 696-706
Link Here
|
696 |
short unsigned active; |
624 |
short unsigned active; |
697 |
}; |
625 |
}; |
698 |
|
626 |
|
699 |
local bool TeamOpen on((team,nominalsize)) is |
627 |
static bool TeamOpen(Team *team, short unsigned nominalsize) |
700 |
( |
|
|
701 |
Team *team |
702 |
_ short unsigned nominalsize |
703 |
) |
704 |
{ |
628 |
{ |
705 |
Mesg(("TeamOpen nominalsize %u\n",nominalsize)); |
629 |
Mesg(("TeamOpen nominalsize %u\n",nominalsize)); |
706 |
|
630 |
|
Lines 717-729
Link Here
|
717 |
return true; |
641 |
return true; |
718 |
} |
642 |
} |
719 |
|
643 |
|
720 |
local bool TeamStart on((team,bufsize,isize,osize)) is |
644 |
static bool TeamStart(Team *team, address bufsize, UOFF_T isize, UOFF_T osize) |
721 |
( |
|
|
722 |
fast Team *team |
723 |
_ address bufsize |
724 |
_ UOFF_T isize |
725 |
_ UOFF_T osize |
726 |
) |
727 |
{ |
645 |
{ |
728 |
/* |
646 |
/* |
729 |
When generating each guy, we pass it an upstream link that |
647 |
When generating each guy, we pass it an upstream link that |
Lines 760-774
Link Here
|
760 |
Fd this_downstream; |
678 |
Fd this_downstream; |
761 |
Fd next_upstream; |
679 |
Fd next_upstream; |
762 |
|
680 |
|
763 |
Mesg(("TeamStart team %#o size %u bufsize %u\n", |
681 |
Mesg(("TeamStart team %p size %u bufsize %u\n", |
764 |
team,team->size,bufsize)); |
682 |
team,team->size,bufsize)); |
765 |
|
683 |
|
766 |
call FdOpen(&FdIn,0,isize); call FdOpen(&FdOut,1,osize); |
684 |
call FdOpen(&FdIn,0,isize); call FdOpen(&FdOut,1,osize); |
767 |
|
685 |
|
768 |
for (team->active = 0; team->active < team->size; team->active++) |
686 |
for (team->active = 0; team->active < team->size; team->active++) |
769 |
{ |
687 |
{ |
770 |
fast Guy *guy; |
688 |
Guy *guy; |
771 |
fast int pid; |
689 |
int pid; |
772 |
|
690 |
|
773 |
guy = team->guys+team->active; |
691 |
guy = team->guys+team->active; |
774 |
|
692 |
|
Lines 801-813
Link Here
|
801 |
perror("team: cannot copy last downstream"); |
719 |
perror("team: cannot copy last downstream"); |
802 |
} |
720 |
} |
803 |
|
721 |
|
804 |
Mesg(("TeamStart going to fork for guy %#o\n",guy)); |
722 |
Mesg(("TeamStart going to fork for guy %p\n",guy)); |
805 |
|
723 |
|
806 |
pid = fork(); |
724 |
pid = fork(); |
807 |
|
725 |
|
808 |
if (pid > 0) |
726 |
if (pid > 0) |
809 |
{ |
727 |
{ |
810 |
Mesg(("TeamStart forked guy %#o as pid %u\n",guy,pid)); |
728 |
Mesg(("TeamStart forked guy %p as pid %u\n",guy,pid)); |
811 |
guy->pid = pid; |
729 |
guy->pid = pid; |
812 |
|
730 |
|
813 |
if (!FdClose(&this_upstream)) |
731 |
if (!FdClose(&this_upstream)) |
Lines 861-870
Link Here
|
861 |
return true; |
779 |
return true; |
862 |
} |
780 |
} |
863 |
|
781 |
|
864 |
local bool TeamWait on((team)) is |
782 |
static bool TeamWait(Team *team) |
865 |
( |
|
|
866 |
fast Team *team |
867 |
) |
868 |
{ |
783 |
{ |
869 |
while (team->active != 0) |
784 |
while (team->active != 0) |
870 |
{ |
785 |
{ |
Lines 874-880
Link Here
|
874 |
guypid = wait(&status); |
789 |
guypid = wait(&status); |
875 |
if (guypid >= 0) |
790 |
if (guypid >= 0) |
876 |
{ |
791 |
{ |
877 |
fast short unsigned guyno; |
792 |
short unsigned guyno; |
878 |
|
793 |
|
879 |
for (guyno = 0; guyno < team->size; guyno++) |
794 |
for (guyno = 0; guyno < team->size; guyno++) |
880 |
if (guypid == team->guys[guyno].pid) |
795 |
if (guypid == team->guys[guyno].pid) |
Lines 906-923
Link Here
|
906 |
return true; |
821 |
return true; |
907 |
} |
822 |
} |
908 |
|
823 |
|
909 |
local bool TeamStop on((team)) is |
824 |
static bool TeamStop(Team *team) |
910 |
( |
|
|
911 |
fast Team *team |
912 |
) |
913 |
{ |
825 |
{ |
914 |
fast short unsigned guyno; |
826 |
short unsigned guyno; |
915 |
|
827 |
|
916 |
Mesg(("TeamStop team %#o\n",team)); |
828 |
Mesg(("TeamStop team %p\n",team)); |
917 |
|
829 |
|
918 |
for (guyno = 0; guyno < team->size; guyno++) |
830 |
for (guyno = 0; guyno < team->size; guyno++) |
919 |
{ |
831 |
{ |
920 |
fast Guy *guy; |
832 |
Guy *guy; |
921 |
|
833 |
|
922 |
guy = team->guys+guyno; |
834 |
guy = team->guys+guyno; |
923 |
if (guy->pid >= 0) |
835 |
if (guy->pid >= 0) |
Lines 930-939
Link Here
|
930 |
return team->active == 0; |
842 |
return team->active == 0; |
931 |
} |
843 |
} |
932 |
|
844 |
|
933 |
local bool TeamClose on((team)) is |
845 |
static bool TeamClose(Team *team) |
934 |
( |
|
|
935 |
fast Team *team |
936 |
) |
937 |
{ |
846 |
{ |
938 |
for (; team->size != 0; --team->size) |
847 |
for (; team->size != 0; --team->size) |
939 |
continue; |
848 |
continue; |
Lines 943-949
Link Here
|
943 |
return true; |
852 |
return true; |
944 |
} |
853 |
} |
945 |
|
854 |
|
946 |
local void usage of((noparms)) |
855 |
static void usage(void) |
947 |
{ |
856 |
{ |
948 |
fprintf(stderr,"\ |
857 |
fprintf(stderr,"\ |
949 |
syntax: team [-[vr]] [-iI[bkm] [-oO[bkm] [N[bkm] [P]]\n\ |
858 |
syntax: team [-[vr]] [-iI[bkm] [-oO[bkm] [N[bkm] [P]]\n\ |
Lines 962-973
Link Here
|
962 |
/*NOTREACHED*/ |
871 |
/*NOTREACHED*/ |
963 |
} |
872 |
} |
964 |
|
873 |
|
965 |
local UOFF_T atos on((s)) is |
874 |
static UOFF_T atos(char *s) |
966 |
( |
|
|
967 |
fast char *s |
968 |
) |
969 |
{ |
875 |
{ |
970 |
fast UOFF_T l; |
876 |
UOFF_T l; |
971 |
|
877 |
|
972 |
for ( |
878 |
for ( |
973 |
l = 0L; |
879 |
l = 0L; |
Lines 983-993
Link Here
|
983 |
return l; |
889 |
return l; |
984 |
} |
890 |
} |
985 |
|
891 |
|
986 |
global int main on((argc,argv)) is |
892 |
global int main(int argc, char *(argv[])) |
987 |
( |
|
|
988 |
int argc |
989 |
_ char *(argv[]) |
990 |
) |
991 |
{ |
893 |
{ |
992 |
Team team; |
894 |
Team team; |
993 |
short unsigned teamsize; |
895 |
short unsigned teamsize; |
Lines 996-1002
Link Here
|
996 |
UOFF_T isize; |
898 |
UOFF_T isize; |
997 |
UOFF_T osize; |
899 |
UOFF_T osize; |
998 |
int opt; |
900 |
int opt; |
999 |
|
901 |
// NB: we never free these. |
|
|
902 |
char *input_filename=0, *output_filename=0; |
903 |
|
1000 |
teamsize = TeamDTEAMSZ; |
904 |
teamsize = TeamDTEAMSZ; |
1001 |
bufsize = TeamDBUFSZ; |
905 |
bufsize = TeamDBUFSZ; |
1002 |
isize = TeamHVOLSZ; |
906 |
isize = TeamHVOLSZ; |
Lines 1006-1035
Link Here
|
1006 |
while ((opt = getopt(argc,argv,"vri:o:")) != -1) |
910 |
while ((opt = getopt(argc,argv,"vri:o:")) != -1) |
1007 |
switch (opt) |
911 |
switch (opt) |
1008 |
{ |
912 |
{ |
1009 |
when 'i': |
913 |
case 'i': |
1010 |
isize = atos(optarg); |
914 |
isize = atos(optarg); |
1011 |
if (isize < TeamLVOLSZ || isize > TeamHVOLSZ) |
915 |
if (isize < TeamLVOLSZ || isize > TeamHVOLSZ) |
1012 |
{ |
916 |
{ |
1013 |
fprintf(stderr,"team: invalid input volume size %lu\n",isize); |
917 |
fprintf(stderr,"team: invalid input volume size %lu\n",isize); |
1014 |
usage(); |
918 |
usage(); |
1015 |
} |
919 |
} |
1016 |
|
920 |
break; |
1017 |
when 'o': |
921 |
|
|
|
922 |
case 'o': |
1018 |
osize = atos(optarg); |
923 |
osize = atos(optarg); |
1019 |
if (osize < TeamLVOLSZ || osize > TeamHVOLSZ) |
924 |
if (osize < TeamLVOLSZ || osize > TeamHVOLSZ) |
1020 |
{ |
925 |
{ |
1021 |
fprintf(stderr,"team: invalid output volume size %lu\n",osize); |
926 |
fprintf(stderr,"team: invalid output volume size %lu\n",osize); |
1022 |
usage(); |
927 |
usage(); |
1023 |
} |
928 |
} |
1024 |
|
929 |
break; |
1025 |
when 'v': |
930 |
|
|
|
931 |
case 'v': |
1026 |
verbose ^= 1; |
932 |
verbose ^= 1; |
1027 |
|
933 |
break; |
1028 |
when 'r': |
934 |
|
|
|
935 |
case 'r': |
1029 |
report ^= 1; |
936 |
report ^= 1; |
1030 |
|
937 |
break; |
1031 |
otherwise: |
938 |
|
|
|
939 |
default: |
1032 |
usage(); |
940 |
usage(); |
|
|
941 |
break; |
942 |
|
1033 |
} |
943 |
} |
1034 |
|
944 |
|
1035 |
argc -= optind, argv += optind; |
945 |
argc -= optind, argv += optind; |