home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- util.c contains routines which display error alerts, fill text
- windows, and display the free space on the current volume.
- */
-
- #include <em.h>
-
- #include <resdefs.h>
- #include <h19.h>
- #include <cntl.h>
- #include <cntldefs.h>
- #include <task.h>
-
- beep()
- {
- static unsigned long lastbeep;
-
- if (lastbeep + 20 < cticks || lastbeep > cticks) {
- /* ^ watch out for wrap */
- SysBeep(6);
- lastbeep = cticks;
- }
- }
-
- /* turn slashes into colons */
-
- macpath(sfile, fdname)
- char * sfile; /* source string */
- char * fdname; /* destination */
- {
- char * sfp;
-
- for (sfp = sfile; *sfp; sfp++, fdname++) {
- if (*sfp == '/')
- *fdname = ':';
- else
- *fdname = *sfp;
- }
- *fdname = '\0';
- }
-
-
- /* find amount of free space on a volume */
-
- #define GETVOLSAFE
- #ifdef GETVOLSAFE
- ParamBlkRec vinfo;
- char tmpname[256];
-
- unsigned long
- free_sp(pathname)
- char * pathname;
- {
- register char * tmpp;
-
- macpath(pathname, tmpname);
- #define DONTAVOIDCOLON
- #ifdef DONTAVOIDCOLON
- for (tmpp = tmpname; *tmpp && *tmpp != ':'; tmpp++)
- ;
-
- if (*tmpp) {
- /* we found a colon in the string, and so have a good volume spec */
- ctop(tmpname);
- vinfo.u.vp.ioVolIndex = -1;
- vinfo.ioVRefNum = -1;
- vinfo.ioNamePtr = tmpname;
- }
- else {
- /* set up the call to use default volume info */
- /* this will set vinfo.ioVRefNum */
- vinfo.ioNamePtr = NULL;
- if (PBGetVol(&vinfo, (Boolean) FALSE))
- return(0L);
- vinfo.u.vp.ioVolIndex = 0; /* was 0 */
- }
- #else
- ctop(tmpname);
- vinfo.u.vp.ioVolIndex = -1;
- vinfo.ioVRefNum = -1;
- vinfo.ioNamePtr = tmpname;
- #endif
- if (PBGetVInfo(&vinfo, (Boolean) FALSE))
- return(0L);
- else
- return( (unsigned long) vinfo.u.vp.ioVAlBlkSiz * (unsigned long) vinfo.u.vp.ioVFrBlk);
- }
- #else
- unsigned long
- free_sp(pathname)
- char * pathname;
- {
- return((unsigned long) 0xFFFFFFFF);
- }
- #endif
-
-
- /* from mac/q.c */
-
- /* Copyright 1984 by the Massachusetts Institute of Technology */
-
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- As of 4/10/86:
- This source file may have no changes from the M.I.T original
- other than this notice; but it has been tested as part of
- Cornell's Aztec-C port. See notice.h
-
- */
-
- /* 10/24/86 kevin changed 0 to (... *) NULL in pointer comparisons */
- /* 11/16/87 kevin started to add q_addb to add q queue element before a
- specified element */
- /* 11/19/87 kevin added return(FALSE) if 0 q len in q_del */
-
- /* See permission and disclaimer notice in file "notice.h" */
-
- /* General-purpose queue manipulation routines. Contains the following
- * routines:
- * q_deq dequeue and return first element from queue
- * q_del delete element from queue
- * All other general-purpose queue manipulation routines are macros
- * defined in "q.h".
- */
-
- q_elt q_deq (q)
-
- /* Dequeue and return the first element of the specified queue. Returns
- * a pointer to the first element if any, or 0 if the queue is empty.
- *
- * Arguments:
- */
-
- register queue *q;
- {
- register q_elt temp; /* temp for result */
-
- if ((temp = q->q_head) == NULL) {
- /* queue is empty */
- return (NULL);
- }
-
- q->q_head = temp->qe_next; /* else unlink */
- temp->qe_next = NULL; /* avoid dangling pointers */
- if (q->q_head == NULL) /* queue empty? */
- q->q_tail = NULL; /* yes, update tail pointer too */
- q->q_len--; /* update queue length */
- if (q->q_len < q->q_min)
- q->q_min = q->q_len;
- return(temp);
- }
-
-
- q_del (q, elt)
-
- /* Delete the specified element from the queue. This requires scanning
- * the queue from the top to find and remove the element, so it takes
- * O(queue length) time to execute. Note that this routine must not
- * run at interrupt level.
- */
-
- register queue *q; /* the queue */
- register q_elt elt; /* element to delete */
- {
- register q_elt *tmp; /* temp for chaining */
-
- if (q->q_len == 0)
- return(FALSE); /* no matches possible in 0-len queue */
-
- for (tmp = &q->q_head; *tmp != elt;
- tmp = (q_elt *)(((q_elt)tmp)->qe_next))
- if (*tmp == NULL) /* find ptr. in queue to elt. */
- return FALSE; /* if not in queue, punt */
-
- *tmp = (*tmp)->qe_next; /* else link it out of the queue */
-
- if (q->q_tail == elt) { /* at end of queue? */
- if (tmp == &q->q_head) /* yes; if first elt, zero out tail */
- q->q_tail = NULL;
- else /* otherwise tail is previous elt */
- q->q_tail = (q_elt)tmp;
- }
- elt->qe_next = NULL; /* avoid dangling pointers */
- q->q_len--; /* update element count */
- if (q->q_len < q->q_min)
- q->q_min = q->q_len;
- return TRUE;
- }
-
- q_elt aq_deq(q)
- queue *q;
- {
- register q_elt temp;
-
- int_off();
- temp = q_deq(q);
- int_on();
- return temp;
- }
-
-
- queue *q_create()
- {
- register queue *q;
-
- q = (queue *)malloc(sizeof(queue));
- if (q == NULL)
- return(NULL);
-
- q->q_head = NULL;
- q->q_tail = NULL;
- q->q_len = q->q_max = q->q_min = 0;
- return q;
- }
-
-
- /* Add an element before a specified element in the queue. */
- /* if head is NULL or succ, just patch new elt right in
- if not, run down list to find previous elt and patch in
- */
-
- q_addb(theq, succ, new)
- register struct queue * theq;
- q_elt succ;
- q_elt new;
- {
- q_elt tmpelt; /* temp ptr running down list */
-
- if (theq->q_head == NULL || theq->q_head == succ ) {
- new->qe_next = theq->q_head;
- if (theq->q_head == NULL)
- theq->q_tail = new;
- theq->q_head = new;
- }
- else {
- new->qe_next = succ;
- tmpelt = theq->q_head;
- while (tmpelt->qe_next != succ) {
- tmpelt = tmpelt->qe_next;
- }
- tmpelt->qe_next = new;
- }
- if (++theq->q_len > theq->q_max)
- theq->q_max = theq->q_len;
- }
-