Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

utilities.cc

Go to the documentation of this file.
00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 //
00003 // Copyright (c) 1997 by the University of Southern California
00004 // All rights reserved.
00005 //
00006 // Permission to use, copy, modify, and distribute this software and its
00007 // documentation in source and binary forms for non-commercial purposes
00008 // and without fee is hereby granted, provided that the above copyright
00009 // notice appear in all copies and that both the copyright notice and
00010 // this permission notice appear in supporting documentation. and that
00011 // any documentation, advertising materials, and other materials related
00012 // to such distribution and use acknowledge that the software was
00013 // developed by the University of Southern California, Information
00014 // Sciences Institute.  The name of the University may not be used to
00015 // endorse or promote products derived from this software without
00016 // specific prior written permission.
00017 //
00018 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about
00019 // the suitability of this software for any purpose.  THIS SOFTWARE IS
00020 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
00021 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
00022 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00023 //
00024 // Other copyrights might apply to parts of this software and are so
00025 // noted when applicable.
00026 //
00027 // utilities.cc
00028 //      Debugging routines.
00029 //
00030 // Author:
00031 //   Mohit Talwar (mohit@catarina.usc.edu)
00032 // 
00033 // $Header: /nfs/jade/vint/CVSROOT/ns-2/rap/utilities.cc,v 1.3 1999/09/24 23:44:43 haoboy Exp $
00034 
00035 #include <stdarg.h>
00036 #include "utilities.h"
00037 
00038 // Constants...
00039 
00040 #ifndef NAME_MAX
00041 // Maximum length of a file name
00042 // In case that it's not defined in limits.h
00043 #define NAME_MAX 14
00044 #endif
00045 
00046 //----------------------------------------------------------------------
00047 // DebugEnable
00048 //      Enable DEBUG messages.
00049 //----------------------------------------------------------------------
00050 
00051 FILE * DebugEnable(unsigned int nodeid)
00052 {
00053   FILE *log;                    // Logfile for debug messages
00054   char logFileName[NAME_MAX];
00055 
00056   sprintf(logFileName, "rap.%u.log", nodeid);
00057   log = fopen(logFileName, "w"); 
00058   assert(log != NULL);
00059 
00060   return log;
00061 }
00062   
00063 //----------------------------------------------------------------------
00064 // Debug
00065 //      Print a debug message if debugFlag is enabled. Like printf.
00066 //----------------------------------------------------------------------
00067 
00068 void Debug(int debugFlag, FILE *log, char *format, ...)
00069 {
00070   if (debugFlag) 
00071     {
00072       va_list ap;
00073       va_start(ap, format);
00074       vfprintf(log, format, ap);
00075       va_end(ap);
00076       fflush(log);
00077     }
00078 }
00079 
00080 // Data structures
00081 void DoubleList::destroy()
00082 {
00083         DoubleListElem *p = head_, *q;
00084         while (p != NULL) {
00085                 q = p;
00086                 p = p->next();
00087                 delete q;
00088         }
00089         head_ = tail_ = NULL;
00090 }
00091 

Generated on Tue Apr 20 12:14:38 2004 for NS2.26SourcesOriginal by doxygen 1.3.3