home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Tele / C / Comet2.1.3 Folder / Comet / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-16  |  5.4 KB  |  249 lines  |  [TEXT/????]

  1. /*
  2.     Copyright Cornell University 1986.  All rights are reserved.
  3.     
  4.     util.c contains routines which display error alerts, fill text
  5.     windows, and display the free space on the current volume.
  6. */
  7.  
  8. #include <em.h>
  9.  
  10. #include <resdefs.h>
  11. #include <h19.h>
  12. #include <cntl.h>
  13. #include <cntldefs.h>
  14. #include <task.h>
  15.  
  16. beep()
  17. {
  18.     static unsigned long lastbeep;
  19.     
  20.     if (lastbeep + 20 < cticks || lastbeep > cticks) {
  21.                                     /* ^ watch out for wrap */
  22.         SysBeep(6);
  23.         lastbeep = cticks;
  24.     }
  25. }
  26.  
  27. /* turn slashes into colons */
  28.  
  29. macpath(sfile, fdname)
  30. char * sfile;        /* source string */
  31. char * fdname;        /* destination */
  32. {
  33.     char * sfp;
  34.  
  35.     for (sfp = sfile; *sfp; sfp++, fdname++) {
  36.         if (*sfp == '/')
  37.             *fdname = ':';
  38.         else
  39.             *fdname = *sfp;
  40.     }
  41.     *fdname = '\0';
  42. }
  43.  
  44.  
  45. /* find amount of free space on a volume */
  46.  
  47. #define GETVOLSAFE
  48. #ifdef GETVOLSAFE
  49.     ParamBlkRec vinfo;
  50.     char tmpname[256];
  51.  
  52. unsigned long
  53. free_sp(pathname)
  54. char * pathname;
  55. {
  56.     register char * tmpp;
  57.  
  58.     macpath(pathname, tmpname);
  59. #define DONTAVOIDCOLON
  60. #ifdef DONTAVOIDCOLON
  61.     for (tmpp = tmpname; *tmpp && *tmpp != ':'; tmpp++) 
  62.         ;
  63.  
  64.     if (*tmpp) {
  65.         /* we found a colon in the string, and so have a good volume spec */
  66.         ctop(tmpname);
  67.         vinfo.u.vp.ioVolIndex = -1;
  68.         vinfo.ioVRefNum = -1;
  69.         vinfo.ioNamePtr = tmpname;
  70.     }
  71.     else {
  72.         /* set up the call to use default volume info */
  73.         /* this will set vinfo.ioVRefNum */
  74.         vinfo.ioNamePtr = NULL;
  75.         if (PBGetVol(&vinfo, (Boolean) FALSE))
  76.             return(0L);
  77.         vinfo.u.vp.ioVolIndex = 0;    /* was 0 */
  78.     }
  79. #else
  80.     ctop(tmpname);
  81.     vinfo.u.vp.ioVolIndex = -1;
  82.     vinfo.ioVRefNum = -1;
  83.     vinfo.ioNamePtr = tmpname;
  84. #endif
  85.     if (PBGetVInfo(&vinfo, (Boolean) FALSE))
  86.         return(0L);
  87.     else 
  88.         return( (unsigned long) vinfo.u.vp.ioVAlBlkSiz * (unsigned long) vinfo.u.vp.ioVFrBlk);
  89. }
  90. #else
  91. unsigned long
  92. free_sp(pathname)
  93. char * pathname;
  94. {
  95.     return((unsigned long) 0xFFFFFFFF);
  96. }
  97. #endif
  98.  
  99.  
  100. /* from mac/q.c */
  101.  
  102. /*  Copyright 1984 by the Massachusetts Institute of Technology  */
  103.  
  104. /*
  105.     Copyright Cornell University 1986.  All rights are reserved.
  106.  
  107.     As of 4/10/86:
  108.     This source file may have no changes from the M.I.T original
  109.     other than this notice; but it has been tested as part of 
  110.     Cornell's Aztec-C port.  See notice.h
  111.  
  112. */
  113.  
  114. /* 10/24/86 kevin changed 0 to (... *) NULL in pointer comparisons */
  115. /* 11/16/87 kevin started to add q_addb to add q queue element before a 
  116.     specified element */
  117. /* 11/19/87 kevin added return(FALSE) if 0 q len in q_del */
  118.  
  119. /*  See permission and disclaimer notice in file "notice.h"  */
  120.  
  121. /* General-purpose queue manipulation routines.  Contains the following
  122.  * routines:
  123.  *    q_deq        dequeue and return first element from queue
  124.  *    q_del        delete element from queue
  125.  * All other general-purpose queue manipulation routines are macros
  126.  * defined in "q.h".
  127.  */
  128.  
  129. q_elt q_deq (q)
  130.  
  131. /* Dequeue and return the first element of the specified queue.  Returns
  132.  * a pointer to the first element if any, or 0 if the queue is empty.
  133.  *
  134.  * Arguments:
  135.  */
  136.  
  137. register queue    *q;
  138. {
  139.     register q_elt    temp;        /* temp for result */
  140.     
  141.     if ((temp = q->q_head) == NULL)    {
  142.         /* queue is empty */
  143.         return (NULL); 
  144.     }
  145.  
  146.     q->q_head = temp->qe_next;    /* else unlink */
  147.     temp->qe_next = NULL;        /* avoid dangling pointers */
  148.     if (q->q_head == NULL)        /* queue empty? */
  149.         q->q_tail = NULL;    /* yes, update tail pointer too */
  150.     q->q_len--;            /* update queue length */
  151.     if (q->q_len < q->q_min) 
  152.         q->q_min = q->q_len;
  153.     return(temp);
  154. }
  155.  
  156.  
  157. q_del (q, elt)
  158.  
  159. /* Delete the specified element from the queue.  This requires scanning
  160.  * the queue from the top to find and remove the element, so it takes
  161.  * O(queue length) time to execute.  Note that this routine must not
  162.  * run at interrupt level.
  163.  */
  164.  
  165. register queue    *q;            /* the queue */
  166. register q_elt    elt;            /* element to delete */
  167. {
  168.     register q_elt    *tmp;        /* temp for chaining */
  169.     
  170.     if (q->q_len == 0)
  171.         return(FALSE);    /* no matches possible in 0-len queue */
  172.  
  173.     for (tmp = &q->q_head; *tmp != elt;
  174.          tmp = (q_elt *)(((q_elt)tmp)->qe_next))
  175.         if (*tmp == NULL)    /* find ptr. in queue to elt. */
  176.             return FALSE;        /* if not in queue, punt */
  177.             
  178.     *tmp = (*tmp)->qe_next;        /* else link it out of the queue */
  179.  
  180.     if (q->q_tail == elt) {        /* at end of queue? */
  181.         if (tmp == &q->q_head)    /* yes; if first elt, zero out tail */
  182.             q->q_tail = NULL;
  183.         else            /* otherwise tail is previous elt */
  184.             q->q_tail = (q_elt)tmp;
  185.     }
  186.     elt->qe_next = NULL;        /* avoid dangling pointers */
  187.     q->q_len--;            /* update element count */
  188.     if (q->q_len < q->q_min) 
  189.         q->q_min = q->q_len;
  190.     return TRUE;
  191. }
  192.  
  193. q_elt aq_deq(q)
  194.     queue *q; 
  195. {
  196.     register q_elt temp;
  197.  
  198.     int_off(); 
  199.     temp = q_deq(q);
  200.     int_on(); 
  201.     return temp;
  202. }
  203.  
  204.  
  205. queue *q_create() 
  206. {
  207.     register queue *q;
  208.  
  209.     q = (queue *)malloc(sizeof(queue));
  210.     if (q == NULL) 
  211.         return(NULL);
  212.  
  213.     q->q_head = NULL;
  214.     q->q_tail = NULL;
  215.     q->q_len = q->q_max = q->q_min = 0;
  216.     return q;
  217. }
  218.  
  219.  
  220. /* Add an element before a specified element in the queue.  */
  221. /* if head is NULL or succ, just patch new elt right in 
  222.     if not, run down list to find previous elt and patch in 
  223. */
  224.  
  225. q_addb(theq, succ, new)
  226. register struct queue * theq;
  227. q_elt succ;
  228. q_elt new;
  229. {
  230.     q_elt tmpelt;    /* temp ptr running down list */
  231.  
  232.     if (theq->q_head == NULL || theq->q_head == succ ) {
  233.         new->qe_next = theq->q_head;
  234.         if (theq->q_head == NULL)
  235.             theq->q_tail = new;
  236.         theq->q_head = new;
  237.     }
  238.     else {
  239.         new->qe_next = succ;
  240.         tmpelt = theq->q_head;
  241.         while (tmpelt->qe_next != succ) {
  242.             tmpelt = tmpelt->qe_next;
  243.         }
  244.         tmpelt->qe_next = new;
  245.     }
  246.     if (++theq->q_len > theq->q_max) 
  247.         theq->q_max = theq->q_len;
  248. }
  249.