IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/sys/psTrace.c

    r1406 r1407  
     1
    12/** @file psTrace.c
    23 *  \brief basic run-time trace facilities
     
    910 *  @author George Gusciora, MHPCC
    1011 *
    11  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-08-06 22:34:05 $
     12 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-07 00:06:06 $
    1314 *
    1415 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    1516 */
     17
    1618/*****************************************************************************
    1719    NOTES:
     
    3436#ifndef PS_NO_TRACE
    3537
    36 #include <stdlib.h>
    37 #include <stdio.h>
    38 #include <string.h>
    39 #include <stdarg.h>
    40 #include "psMemory.h"
    41 #include "psTrace.h"
    42 #include "psString.h"
    43 #include "psError.h"
    44 
    45 static p_psComponent *p_psCroot = NULL;       // The root of the trace component
    46 static FILE *p_psTraceFP = NULL;          // File destination for messages.
    47 
    48 static void componentFree(p_psComponent *comp);
    49 static p_psComponent *componentAlloc(const char *name,int level);
     38#    include <stdlib.h>
     39#    include <stdio.h>
     40#    include <string.h>
     41#    include <stdarg.h>
     42#    include "psMemory.h"
     43#    include "psTrace.h"
     44#    include "psString.h"
     45#    include "psError.h"
     46
     47static p_psComponent *p_psCroot = NULL; // The root of the trace component
     48static FILE *p_psTraceFP = NULL;        // File destination for messages.
     49
     50static void componentFree(p_psComponent * comp);
     51static p_psComponent *componentAlloc(const char *name, int level);
    5052
    5153/*****************************************************************************
    5254componentAlloc(): allocate memory for a new node, and initialize members.
    5355 *****************************************************************************/
    54 static p_psComponent *componentAlloc(const char *name,
    55                                      int level)
     56static p_psComponent *componentAlloc(const char *name, int level)
    5657{
    5758    p_psComponent *comp = psAlloc(sizeof(p_psComponent));
    58     p_psMemSetDeallocator(comp,(psFreeFcn)componentFree);
     59
     60    p_psMemSetDeallocator(comp, (psFreeFcn) componentFree);
    5961    comp->name = psStringCopy(name);
    6062    comp->level = level;
     
    6466}
    6567
    66 
    6768/*****************************************************************************
    6869componentFree(): free the current node in the root tree, and all children
    6970nodes as well.
    7071 *****************************************************************************/
    71 static void componentFree(p_psComponent *comp)
     72static void componentFree(p_psComponent * comp)
    7273{
    7374    if (comp == NULL) {
     
    8586}
    8687
    87 
    8888/*****************************************************************************
    8989initTrace(): simply initialize the component root tree.
     
    9696}
    9797
    98 
    9998/*****************************************************************************
    10099Set all trace levels to zero.
    101100 *****************************************************************************/
    102 void p_psTraceReset(p_psComponent *currentNode)
     101void p_psTraceReset(p_psComponent * currentNode)
    103102{
    104103    int i = 0;
     
    109108
    110109    currentNode->level = 0;
    111     for (i=0;i<currentNode->n;i++) {
     110    for (i = 0; i < currentNode->n; i++) {
    112111        if (NULL == currentNode->subcomp[i]) {
    113112            psError(__func__,
    114                     "Sub-component %d of node %s in the trace tree is NULL.\n",
    115                     i, currentNode->name);
     113                    "Sub-component %d of node %s in the trace tree is NULL.\n", i, currentNode->name);
    116114        } else {
    117115            p_psTraceReset(currentNode->subcomp[i]);
     
    129127}
    130128
    131 
    132129/*****************************************************************************
    133130Free all nodes in the component tree.
     
    137134    psFree(p_psCroot);
    138135}
    139 
    140136
    141137/*****************************************************************************
     
    145141to ANSI-C.
    146142 *****************************************************************************/
    147 static void componentAdd(const char *addNodeName,
    148                          int         level)
    149 {
    150     int        i = 0;                         // Loop index variable.
    151     char       name[strlen(addNodeName) + 1]; // buffer for writeable copy.
    152     char      *pname=name;
    153     char      *firstComponent = NULL;       // first component of name
     143static void componentAdd(const char *addNodeName, int level)
     144{
     145    int i = 0;                  // Loop index variable.
     146    char name[strlen(addNodeName) + 1]; // buffer for writeable copy.
     147    char *pname = name;
     148    char *firstComponent = NULL;        // first component of name
    154149    p_psComponent *currentNode = p_psCroot;
    155     int        nodeExists = 0;
    156 
    157     // Is this the root node?  If so, simply set level and return.
     150    int nodeExists = 0;
     151
     152    // Is this the root node? If so, simply set level and return.
    158153    if (strcmp(".", addNodeName) == 0) {
    159154        p_psCroot->level = level;
     
    162157
    163158    if (addNodeName[0] != '.') {
    164         printf("ERROR: failed to add %s to the root component tree.\n",
    165                addNodeName);
     159        printf("ERROR: failed to add %s to the root component tree.\n", addNodeName);
    166160        exit(1);
    167161    }
     
    188182        if (nodeExists == 0) {
    189183            currentNode->subcomp = psRealloc(currentNode->subcomp,
    190                                              (currentNode->n + 1) * sizeof(p_psComponent*));
    191             currentNode->n = (currentNode->n)+1;
    192 
    193             currentNode->subcomp[(currentNode->n)-1] =
    194                 componentAlloc(firstComponent, level);
    195         }
    196     }
    197 }
    198 
     184                                             (currentNode->n + 1) * sizeof(p_psComponent *));
     185            currentNode->n = (currentNode->n) + 1;
     186
     187            currentNode->subcomp[(currentNode->n) - 1] = componentAlloc(firstComponent, level);
     188        }
     189    }
     190}
    199191
    200192/*****************************************************************************
     
    210202*****************************************************************************/
    211203int psTraceSetLevel(const char *comp,   // component of interest
    212                     int level)          // desired trace level
     204                    int level)  // desired trace level
    213205{
    214206    // If the root component tree does not exist, then initialize it.
     
    216208        initTrace();
    217209    }
    218 
    219210    // Add the new component to the component tree.
    220211    componentAdd(comp, level);
     
    223214    return 0;
    224215}
    225 
    226216
    227217/*****************************************************************************
     
    241231static int doGetTraceLevel(const char *aname)
    242232{
    243     char       name[strlen(aname) + 1]; // need a writeable copy: for strsep()
    244     char      *pname=name;
    245     char      *firstComponent = NULL;   // first component of name
     233    char name[strlen(aname) + 1];      // need a writeable copy: for strsep()
     234    char *pname = name;
     235    char *firstComponent = NULL;        // first component of name
    246236    p_psComponent *currentNode = p_psCroot;
    247     int        i = 0;
     237    int i = 0;
    248238
    249239    if (NULL == currentNode) {
    250         return(PS_UNKNOWN_TRACE_LEVEL);
     240        return (PS_UNKNOWN_TRACE_LEVEL);
    251241    }
    252242
    253243    if (strcmp(".", aname) == 0) {
    254         return(p_psCroot->level);
     244        return (p_psCroot->level);
    255245    }
    256246
    257247    if (aname[0] != '.') {
    258         return(PS_UNKNOWN_TRACE_LEVEL);
     248        return (PS_UNKNOWN_TRACE_LEVEL);
    259249    }
    260250
     
    266256            if (NULL == currentNode->subcomp[i]) {
    267257                psError(__func__,
    268                         "Sub-component %d of node %s in trace tree is NULL.\n",
    269                         i, currentNode->name);
     258                        "Sub-component %d of node %s in trace tree is NULL.\n", i, currentNode->name);
    270259            }
    271260
     
    273262                currentNode = currentNode->subcomp[i];
    274263                if (pname == NULL) {
    275                     return(currentNode->level);
     264                    return (currentNode->level);
    276265                }
    277266            }
    278267        }
    279268    }
    280     return(PS_UNKNOWN_TRACE_LEVEL);
    281 }
    282 
     269    return (PS_UNKNOWN_TRACE_LEVEL);
     270}
    283271
    284272/*****************************************************************************
     
    297285{
    298286    if (p_psCroot == NULL) {
    299         return(PS_UNKNOWN_TRACE_LEVEL);
    300     }
    301 
     287        return (PS_UNKNOWN_TRACE_LEVEL);
     288    }
    302289    // Search the component root tree, determine the trace level.
    303     return(doGetTraceLevel(name));
    304 }
    305 
     290    return (doGetTraceLevel(name));
     291}
    306292
    307293/*****************************************************************************
     
    317303 null
    318304 *****************************************************************************/
    319 static void doPrintTraceLevels(const p_psComponent *comp,
    320                                int depth)
     305static void doPrintTraceLevels(const p_psComponent * comp, int depth)
    321306{
    322307    int i = 0;
     
    327312    } else {
    328313        if (comp->level == PS_UNKNOWN_TRACE_LEVEL) {
    329             printf("%*s%-*s %s\n", depth, "", 20 - depth,
    330                    comp->name, ".");
     314            printf("%*s%-*s %s\n", depth, "", 20 - depth, comp->name, ".");
    331315        } else {
    332             printf("%*s%-*s %d\n", depth, "", 20 - depth,
    333                    comp->name, comp->level);
     316            printf("%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
    334317        }
    335318    }
    336319
    337320    for (i = 0; i < comp->n; i++) {
    338         doPrintTraceLevels(comp->subcomp[i], depth+1);
    339     }
    340 }
    341 
     321        doPrintTraceLevels(comp->subcomp[i], depth + 1);
     322    }
     323}
    342324
    343325/*****************************************************************************
     
    359341    doPrintTraceLevels(p_psCroot, 0);
    360342}
    361 
    362343
    363344/*****************************************************************************
     
    376357 *****************************************************************************/
    377358void p_psTrace(const char *comp,        // component being traced
    378                int level,               // desired trace level
    379                ...)                     // arguments
     359               int level,       // desired trace level
     360               ...)             // arguments
    380361{
    381362    char *fmt = NULL;
     
    384365
    385366    if (NULL == comp) {
    386         psError(__func__,
    387                 "p_psTrace() called on a NULL trace level tree\n");
    388     }
    389 
     367        psError(__func__, "p_psTrace() called on a NULL trace level tree\n");
     368    }
    390369    // Only display this message if it's trace level is less than the level
    391370    // of it's associatedcomponent.
     
    413392        va_end(ap);
    414393    }
    415 
    416     // NOTE: should we free *fmt as well?  Read the man page.
    417 }
    418 
    419 void psTraceSetDestination(FILE *fp)
     394    // NOTE: should we free *fmt as well? Read the man page.
     395}
     396
     397void psTraceSetDestination(FILE * fp)
    420398{
    421399    p_psTraceFP = fp;
Note: See TracChangeset for help on using the changeset viewer.