⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 debug.c

📁 最经典的分子对结软件
💻 C
字号:
/*************************************************************************** Debug.cc****   Jim Arnold, 21 April, 1999****   This module allows conditional debug flags to be defined in C **   programs.  The values of the flags can be read in from a file such**   as combidock.dbg.  That gives you conditional debug statements that**   can be changed from file (they do not require a re-compile/link)**   and that can be used to prove the correctness of functions as they**   are written.  The statements serve as diagnostics, and to comment**   the code.*************************************************************************/#include <stdio.h>#include "string.h"#include "logical.h"#include "debug.h"/******************* mark globals *****************/int DB_STRUCT[NUMBER_DEBUG_FLAGS];/**************************** ** mark prototypes private ****************************/int        DebugSetFlagsI(FILE *dbfilePF);void       DebugPrintFlags();/** mark DebugInitI **//**************************************************************************** AUTHOR:  Jim Arnold**** PURPOSE:  Initializes the global debug array, Opens the debug file,**           sets the flags that are on.**** INPUT:  Strings containing the directory and file names.**** OUTPUT:  Returns true if the file is opened, otherwise returns false.**** NOTES:  Uses the global debug array:  DB_STRUCT[].**************************************************************************/int DebugInitI(STRING100 dirS, STRING100 nameS){   int         i, retI = true;   STRING200   fileS;   FILE        *dbfilePF = NULL;      sprintf(fileS, "%s/%s", dirS, nameS);/*      printf("  The debug file name is: |%s|.\n", fileS);*/   dbfilePF = fopen(fileS, "r");   if (dbfilePF equal NULL)   {      printf("!! Error, unable to open debug file: |%s|.\n",fileS);      retI = false;   }   else   {      /** Set the values of the DB_STRUCT to be false. **/      for (i = 0; i < NUMBER_DEBUG_FLAGS; i++)      {         DB_STRUCT[i] = false;      }      if (not DebugSetFlagsI(dbfilePF))      {         printf("\n  GUARD:  debug flags not set from file: |%s|.\n", fileS);      }      else      {/*         printf("\n  Debug flags set correctly from file: |%s|.\n", fileS);*/      }   }      return (retI);}/** mark DebugSetFlagsI **//**************************************************************************** AUTHOR:  Jim Arnold**** PURPOSE:  Reads the opened debug file and sets the flags in the debug**           array from it.**** INPUT:  The opened debug file.**** OUTPUT:  Returns true if the file is in a readable form.**** NOTES:  Uses the global debug array.  Comments are indicated with a**         "#" in the first column of a line.**************************************************************************/int DebugSetFlagsI(FILE *dbfilePF){   int         retI = true, valueI;   char        *cC;   STRING200   lineS;   extern int  DB_STRUCT[];   while (fgets(lineS, 200, dbfilePF) != NULL)   {      if ((strncmp(lineS, "#", 1)) equal 0)      {         ; /** skip the commented lines. **/      }      else      {         if (strchr(lineS, 'flag'))	 {            cC = strrchr(lineS, 'flag');            cC++;            sscanf(cC, "%d", &valueI);            if ((valueI < 0) or (valueI >= NUMBER_DEBUG_FLAGS))	    {               printf("!! Error:  debug flag: %d is outside array bounds.\n", valueI);	    }            else	    {               DB_STRUCT[valueI] = true;/*               printf("  Set position %d in debug array to: %d.\n", valueI, DB_STRUCT[valueI]);*/	    }	 }      }   }      return (retI);}/** mark DebugPrintFlags  **//**************************************************************************** AUTHOR:  Jim Arnold**** PURPOSE:  Prints the flags that are on in the debug file.**** INPUT:  NULL.**** OUTPUT:  void.**** NOTES:  Uses the global debug array.**************************************************************************/void DebugPrintFlags(){   int          i;   extern int   DB_STRUCT[];   printf("  Printing the Debug Flags that are on.\n\n");   for (i = 0; i < NUMBER_DEBUG_FLAGS; i++)   {      if (DB_STRUCT[i] != 0)      {         printf("  Debug Flag %d is: %d.\n",i,DB_STRUCT[i]);      }   }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -