chiark / gitweb /
Sources placed under CVS control.
[become] / src / utils.h
index 09ee6d2e72374f2206a4f63b34a1871e4757704b..dce373e6a35146a54db1c489284704c86c79d2d6 100644 (file)
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: utils.h,v 1.1 1997/07/21 13:47:42 mdw Exp $
+ * $Id: utils.h,v 1.2 1997/08/04 10:24:26 mdw Exp $
  *
  * Miscellaneous useful bits of code.
  *
  * (c) 1997 Mark Wooding
  */
 
-/*----- Licencing notice --------------------------------------------------*
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of `become'
  *
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with `become'; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * along with `become'; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  */
 
 /*----- Revision history --------------------------------------------------*
  *
  * $Log: utils.h,v $
- * Revision 1.1  1997/07/21 13:47:42  mdw
+ * Revision 1.2  1997/08/04 10:24:26  mdw
+ * Sources placed under CVS control.
+ *
+ * Revision 1.1  1997/07/21  13:47:42  mdw
  * Initial revision
  *
  */
    (p)[2] = ((unsigned long)(v) >> 16) & 0xFF,                         \
    (p)[3] = ((unsigned long)(v) >> 24) & 0xFF)
 
+/*----- Other macros ------------------------------------------------------*/
+
+/* --- @burn@ --- *
+ *
+ * Arguments:  @obj@ = some object
+ *
+ * Use:                Writes zero bytes over the object.
+ */
+
+#define burn(obj) ((void)memset(&obj, 0, sizeof(obj)))
+
 /*----- Program name handling ---------------------------------------------*/
 
 /* --- @quis@ --- *
@@ -129,6 +143,88 @@ extern void moan(const char */*f*/, ...);
 
 extern void die(const char */*f*/, ...);
 
+/*----- Trace messages ----------------------------------------------------*/
+
+#if !defined(NDEBUG) && !defined(TRACING)
+#  define TRACING
+#endif
+
+#ifdef TRACING
+
+/* --- @trace@ --- *
+ *
+ * Arguments:  @unsigned int lvl@ = trace level for output
+ *             @const char *f@ = a @printf@-style format string
+ *             @...@ = other arguments
+ *
+ * Returns:    ---
+ *
+ * Use:                Reports a message to the trace output.
+ */
+
+extern void trace(unsigned int /*lvl*/, const char */*f*/, ...);
+
+/* --- @traceblk@ --- *
+ *
+ * Arguments:  @unsigned int lvl@ = trace level for output
+ *             @const char *hdr@ = some header string to write
+ *             @const void *blk@ = pointer to a block of memory to dump
+ *             @size_t sz@ = size of the block of memory
+ *
+ * Returns:    ---
+ *
+ * Use:                Dumps the contents of a block to the trace output.
+ */
+
+extern void traceblk(unsigned int /*lvl*/, const char */*hdr*/,
+                    const void */*blk*/, size_t /*sz*/);
+
+/* --- @traceon@ --- *
+ *
+ * Arguments:  @FILE *fp@ = a file to trace on
+ *             @unsigned int lvl@ = trace level to set
+ *
+ * Returns:    ---
+ *
+ * Use:                Enables tracing to a file.
+ */
+
+extern void traceon(FILE */*fp*/, unsigned int /*lvl*/);
+
+/* --- @tracesetlvl@ --- *
+ *
+ * Arguments:  @unsigned int lvl@ = trace level to set
+ *
+ * Returns:    ---
+ *
+ * Use:                Sets the tracing level.
+ */
+
+extern void tracesetlvl(unsigned int /*lvl*/);
+
+/* --- @tracing@ --- *
+ *
+ * Arguments:  ---
+ *
+ * Returns:    Zero if not tracing, tracing level if tracing.
+ *
+ * Use:                Informs the caller whether tracing is enabled.
+ */
+
+extern unsigned int tracing(void);
+
+#endif
+
+/* --- Some hacky macros --- */
+
+#ifdef TRACING
+#  define T(x) x
+#  define IF_TRACING(lvl, x) if ((lvl) & tracing()) x
+#else
+#  define T(x)
+#  define IF_TRACING(lvl, x)
+#endif
+
 /*----- Memory management functions ---------------------------------------*/
 
 /* --- @xmalloc@ --- *