home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / x / volume3 / awm2 / part11 / support.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-21  |  2.4 KB  |  116 lines

  1.  
  2.  
  3.  
  4. #ifndef lint
  5. static char *rcsid_support_c = "$Header: /usr/graph2/X11.3/contrib/windowmgrs/awm/RCS/support.c,v 1.2 89/02/07 21:25:47 jkh Exp $";
  6. #endif  lint
  7.  
  8. #include "X11/copyright.h"
  9. /*
  10.  *
  11.  * Copyright 1987, 1988 by Ardent Computer Corporation, Sunnyvale, Ca.
  12.  *
  13.  * Copyright 1987 by Jordan Hubbard.
  14.  *
  15.  *
  16.  *                         All Rights Reserved
  17.  *
  18.  * Permission to use, copy, modify, and distribute this software and its
  19.  * documentation for any purpose and without fee is hereby granted,
  20.  * provided that the above copyright notice appear in all copies and that
  21.  * both that copyright notice and this permission notice appear in
  22.  * supporting documentation, and that the name of Ardent Computer
  23.  * Corporation or Jordan Hubbard not be used in advertising or publicity
  24.  * pertaining to distribution of the software without specific, written
  25.  * prior permission.
  26.  *
  27.  * REVISION HISTORY:
  28.  *
  29.  * 1.2 -- Version of strlen() that accepts NULL strings added (#ifdef it
  30.  * in if your system needs it).
  31.  */
  32.  
  33. #include "support.h"
  34. #include <stdio.h>
  35.      
  36. int _rtn_level;
  37. int _rtn_trace;
  38.  
  39. static struct func_stack {
  40.      char *rtn_name;
  41.      struct func_stack *next;
  42. } *Head;
  43.  
  44. char *curr_rtn()
  45. {
  46.      if (!Head)
  47.       return((char *)0);
  48.      else
  49.       return(Head->rtn_name);
  50. }
  51.  
  52. void push_rtn(s)
  53. register char *s;
  54. {
  55.      if (!Head) {
  56.       Head = (struct func_stack *)malloc(sizeof(struct func_stack));
  57.       if (!Head) {
  58.            fprintf(stderr, "Couldn't malloc new func_stack entry!\n");
  59.            exit(1);
  60.       }
  61.       Head->rtn_name = s;
  62.       Head->next = 0;
  63.      }
  64.      else {
  65.       struct func_stack *ptr;
  66.       
  67.       ptr =  (struct func_stack *)malloc(sizeof(struct func_stack));
  68.       if (!ptr) {
  69.            fprintf(stderr, "Couldn't malloc new func_stack entry!\n");
  70.            exit(1);
  71.       }
  72.       ptr->rtn_name = s;
  73.       ptr->next = Head;
  74.       Head = ptr;
  75.      }
  76.      _rtn_level++;
  77.      if (_rtn_trace) {
  78.       int i;
  79.       
  80.       for (i = 0; i < _rtn_level; i++)
  81.            putchar('\t');
  82.       printf("%s(%d)\n", Head->rtn_name, _rtn_level);
  83.      }
  84. }
  85.  
  86. void pop_rtn()
  87. {
  88.      struct func_stack *ptr;
  89.  
  90.      if (!Head)
  91.       return;
  92.      ptr = Head;
  93.      Head = Head->next;
  94.      free(ptr);
  95.      _rtn_level--;
  96. }
  97.  
  98. /*
  99.  * Some systems retch when you pass strlen() a NULL pointer.
  100.  * Here's a way of getting around it.
  101.  */
  102.  
  103. #if defined(hlh) || defined(titan)
  104. strlen(s)
  105. char *s;
  106. {
  107.     int count = 0;
  108.  
  109.     if (s == 0)
  110.         return(0);
  111.     while (*s++)
  112.         count++;
  113.     return(count);
  114. }
  115. #endif /* hlh */
  116.