home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Kernel / h / macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-17  |  2.3 KB  |  52 lines

  1. /*  C O P Y R I G H T   N O T I C E :                                     */
  2. /* Copyright 1986 Eric Jul.  May not be used for any               */
  3. /* purpose without written permission from the author.              */
  4.  
  5. /* MAX(i,j) MIN(i,j) return the maximimum or minimum of two numbers       */
  6. #define MAX(i,j) ((i) > (j) ? i : j)
  7. #define MIN(i,j) ((i) < (j) ? i : j)
  8.  
  9. /* PUSHIT(stackPtr, newElement)  pushes an int element onto a stack whose
  10.    stackPtr is kept in a variable. */
  11.  
  12. #define PUSHIT(stackPtr, newElem) \
  13.     (* ( -- (int *) (stackPtr)) =  (int) (newElem))
  14.  
  15. #define POPIT(stackPtr, newElem) \
  16.      ( * ((int *) &(newElem)) =  * (((int *) (stackPtr))++))
  17.  
  18. /* mPLURAL generates a plural s, if necessary. */
  19. #define mPLURAL(value) ((value) == 1 ? "" : "s")
  20. #define mPLURALY(value) ((value) == 1 ? "y" : "ies")
  21.  
  22. /* Queueing macros. 
  23.  *  These macros maintain FIFO queues using only one link field.
  24.  *  The queues are circular, single link with the head being a single
  25.  *  variable pointing to the LAST element in the queue.
  26.  *  Assumption:  NULL == 0
  27.  */
  28.  
  29. #define QueueIns(QHead, newElt, Next)                                   \
  30.   {                                                                     \
  31.     if ( QHead ) { /* Insert into non-empty queue. */                   \
  32.         (newElt)->Next = (QHead)->Next;                                 \
  33.         (QHead)->Next  = newElt;                                        \
  34.         (QHead) = newElt;                                               \
  35.     } else { /* New element in empty queue. */                          \
  36.         (QHead) = (newElt)->Next = newElt;                              \
  37.     }                                                                   \
  38.   }
  39.  
  40. #define QueueRmv(QHead, Element, Next)                                  \
  41.   {                                                                     \
  42.     if ((QHead) == (QHead)->Next) {                                     \
  43.         (Element) = (QHead);  QHead = NULL;                             \
  44.     } else {                                                            \
  45.         (Element) = (QHead)->Next;  (QHead)->Next = (Element)->Next;    \
  46.     };                                                                  \
  47.   }
  48.  
  49. #define QueueInit(Q)    Q = NULL
  50.  
  51. /**********************************************************************/
  52.