00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 00003 /* 00004 * utilities.cc 00005 * Copyright (C) 1997 by the University of Southern California 00006 * $Id: utilities.cc,v 1.4 2005/08/25 18:58:11 johnh Exp $ 00007 * 00008 * This program is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU General Public License, 00010 * version 2, as published by the Free Software Foundation. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License along 00018 * with this program; if not, write to the Free Software Foundation, Inc., 00019 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. 00020 * 00021 * 00022 * The copyright of this module includes the following 00023 * linking-with-specific-other-licenses addition: 00024 * 00025 * In addition, as a special exception, the copyright holders of 00026 * this module give you permission to combine (via static or 00027 * dynamic linking) this module with free software programs or 00028 * libraries that are released under the GNU LGPL and with code 00029 * included in the standard release of ns-2 under the Apache 2.0 00030 * license or under otherwise-compatible licenses with advertising 00031 * requirements (or modified versions of such code, with unchanged 00032 * license). You may copy and distribute such a system following the 00033 * terms of the GNU GPL for this module and the licenses of the 00034 * other code concerned, provided that you include the source code of 00035 * that other code when and as the GNU GPL requires distribution of 00036 * source code. 00037 * 00038 * Note that people who make modified versions of this module 00039 * are not obligated to grant this special exception for their 00040 * modified versions; it is their choice whether to do so. The GNU 00041 * General Public License gives permission to release a modified 00042 * version without this exception; this exception also makes it 00043 * possible to release a modified version which carries forward this 00044 * exception. 00045 * 00046 */ 00047 00048 // 00049 // utilities.cc 00050 // Debugging routines. 00051 // 00052 // Author: 00053 // Mohit Talwar (mohit@catarina.usc.edu) 00054 // 00055 // $Header: /nfs/jade/vint/CVSROOT/ns-2/rap/utilities.cc,v 1.4 2005/08/25 18:58:11 johnh Exp $ 00056 00057 #include <stdarg.h> 00058 #include "utilities.h" 00059 00060 // Constants... 00061 00062 #ifndef NAME_MAX 00063 // Maximum length of a file name 00064 // In case that it's not defined in limits.h 00065 #define NAME_MAX 14 00066 #endif 00067 00068 //---------------------------------------------------------------------- 00069 // DebugEnable 00070 // Enable DEBUG messages. 00071 //---------------------------------------------------------------------- 00072 00073 FILE * DebugEnable(unsigned int nodeid) 00074 { 00075 FILE *log; // Logfile for debug messages 00076 char logFileName[NAME_MAX]; 00077 00078 sprintf(logFileName, "rap.%u.log", nodeid); 00079 log = fopen(logFileName, "w"); 00080 assert(log != NULL); 00081 00082 return log; 00083 } 00084 00085 //---------------------------------------------------------------------- 00086 // Debug 00087 // Print a debug message if debugFlag is enabled. Like printf. 00088 //---------------------------------------------------------------------- 00089 00090 void Debug(int debugFlag, FILE *log, char *format, ...) 00091 { 00092 if (debugFlag) 00093 { 00094 va_list ap; 00095 va_start(ap, format); 00096 vfprintf(log, format, ap); 00097 va_end(ap); 00098 fflush(log); 00099 } 00100 } 00101 00102 // Data structures 00103 void DoubleList::destroy() 00104 { 00105 DoubleListElem *p = head_, *q; 00106 while (p != NULL) { 00107 q = p; 00108 p = p->next(); 00109 delete q; 00110 } 00111 head_ = tail_ = NULL; 00112 } 00113
1.4.6