|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that the above copyright notice and this paragraph are ! 7: * duplicated in all such forms and that any documentation, ! 8: * advertising materials, and other materials related to such ! 9: * distribution and use acknowledge that the software was developed ! 10: * by the University of California, Berkeley. The name of the ! 11: * University may not be used to endorse or promote products derived ! 12: * from this software without specific prior written permission. ! 13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 16: */ ! 17: ! 18: #ifndef lint ! 19: static char sccsid[] = "@(#)schedule.c 5.3 (Berkeley) 6/18/88"; ! 20: #endif /* not lint */ ! 21: ! 22: # include "trek.h" ! 23: ! 24: /* ! 25: ** SCHEDULE AN EVENT ! 26: ** ! 27: ** An event of type 'type' is scheduled for time NOW + 'offset' ! 28: ** into the first available slot. 'x', 'y', and 'z' are ! 29: ** considered the attributes for this event. ! 30: ** ! 31: ** The address of the slot is returned. ! 32: */ ! 33: ! 34: struct event *schedule(type, offset, x, y, z) ! 35: int type; ! 36: double offset; ! 37: char x, y; ! 38: char z; ! 39: { ! 40: register struct event *e; ! 41: register int i; ! 42: double date; ! 43: ! 44: date = Now.date + offset; ! 45: for (i = 0; i < MAXEVENTS; i++) ! 46: { ! 47: e = &Event[i]; ! 48: if (e->evcode) ! 49: continue; ! 50: /* got a slot */ ! 51: # ifdef xTRACE ! 52: if (Trace) ! 53: printf("schedule: type %d @ %.2f slot %d parm %d %d %d\n", ! 54: type, date, i, x, y, z); ! 55: # endif ! 56: e->evcode = type; ! 57: e->date = date; ! 58: e->x = x; ! 59: e->y = y; ! 60: e->systemname = z; ! 61: Now.eventptr[type] = e; ! 62: return (e); ! 63: } ! 64: syserr("Cannot schedule event %d parm %d %d %d", type, x, y, z); ! 65: } ! 66: ! 67: ! 68: /* ! 69: ** RESCHEDULE AN EVENT ! 70: ** ! 71: ** The event pointed to by 'e' is rescheduled to the current ! 72: ** time plus 'offset'. ! 73: */ ! 74: ! 75: reschedule(e1, offset) ! 76: struct event *e1; ! 77: double offset; ! 78: { ! 79: double date; ! 80: register struct event *e; ! 81: ! 82: e = e1; ! 83: ! 84: date = Now.date + offset; ! 85: e->date = date; ! 86: # ifdef xTRACE ! 87: if (Trace) ! 88: printf("reschedule: type %d parm %d %d %d @ %.2f\n", ! 89: e->evcode, e->x, e->y, e->systemname, date); ! 90: # endif ! 91: return; ! 92: } ! 93: ! 94: ! 95: /* ! 96: ** UNSCHEDULE AN EVENT ! 97: ** ! 98: ** The event at slot 'e' is deleted. ! 99: */ ! 100: ! 101: unschedule(e1) ! 102: struct event *e1; ! 103: { ! 104: register struct event *e; ! 105: ! 106: e = e1; ! 107: ! 108: # ifdef xTRACE ! 109: if (Trace) ! 110: printf("unschedule: type %d @ %.2f parm %d %d %d\n", ! 111: e->evcode, e->date, e->x, e->y, e->systemname); ! 112: # endif ! 113: Now.eventptr[e->evcode & E_EVENT] = 0; ! 114: e->date = 1e50; ! 115: e->evcode = 0; ! 116: return; ! 117: } ! 118: ! 119: ! 120: /* ! 121: ** Abreviated schedule routine ! 122: ** ! 123: ** Parameters are the event index and a factor for the time ! 124: ** figure. ! 125: */ ! 126: ! 127: struct event *xsched(ev1, factor, x, y, z) ! 128: int ev1; ! 129: int factor; ! 130: int x, y, z; ! 131: { ! 132: register int ev; ! 133: ! 134: ev = ev1; ! 135: return (schedule(ev, -Param.eventdly[ev] * Param.time * log(franf()) / factor, x, y, z)); ! 136: } ! 137: ! 138: ! 139: /* ! 140: ** Simplified reschedule routine ! 141: ** ! 142: ** Parameters are the event index, the initial date, and the ! 143: ** division factor. Look at the code to see what really happens. ! 144: */ ! 145: ! 146: xresched(e1, ev1, factor) ! 147: struct event *e1; ! 148: int ev1; ! 149: int factor; ! 150: { ! 151: register int ev; ! 152: register struct event *e; ! 153: ! 154: ev = ev1; ! 155: e = e1; ! 156: reschedule(e, -Param.eventdly[ev] * Param.time * log(franf()) / factor); ! 157: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.