IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 14494


Ignore:
Timestamp:
Aug 14, 2007, 2:38:13 PM (19 years ago)
Author:
jhoblitt
Message:

add pxNodePrint()
add pxTreeCrawl()

Location:
trunk/ippTools/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/Makefile.am

    r14489 r14494  
    1414        warptool \
    1515        pzgetimfiles \
     16        ttree \
    1617        pztool
    1718
     
    6566# for pxtools.h
    6667AM_CPPFLAGS = -I$(top_srcdir)/src$
     68
     69
     70ttree_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
     71ttree_LDADD = $(PSLIB_LIBS) $(PSMODULES_LIBS) $(IPPDB_LIBS) libpxtools.la
     72ttree_SOURCES = \
     73    ttree.c
    6774
    6875pztool_CFLAGS = $(PSLIB_CFLAGS) $(PSMODULES_CFLAGS) $(IPPDB_CFLAGS)
  • trunk/ippTools/src/pxtree.c

    r14489 r14494  
    5757    return node;
    5858}
     59
     60
     61void pxNodePrint(FILE *stream, pxNode *node)
     62{
     63    fprintf(stream, "node name: %s\n", node->name);
     64    fprintf(stream, "node parent's name: %s\n", node->parent
     65                                              ?  node->parent->name
     66                                              : NULL);
     67    psListIterator *iter = psListIteratorAlloc(node->children, 0, false);                                         
     68    pxNode *child = NULL;
     69    while ((child = psListGetAndIncrement(iter))) {
     70        fprintf(stream, "node child's name: %s\n", child->name);
     71    }
     72    psFree(iter);
     73}
     74
     75
     76bool pxTreeCrawl(pxNode *node, pxNodeFunc func)
     77{
     78    // if func() returns false, stop
     79    if (!func(node)) {
     80        return false;
     81    }
     82
     83    psListIterator *iter = psListIteratorAlloc(node->children, 0, false);                                         
     84    pxNode *child = NULL;
     85    while ((child = psListGetAndIncrement(iter))) {
     86        // if func() returns false, pxTreeCrawl() well return false, and we
     87        // should stop
     88        if (!pxTreeCrawl(child, func)) {
     89            return false;
     90        }
     91    }
     92    psFree(iter);
     93
     94    return true;
     95}
  • trunk/ippTools/src/pxtree.h

    r14489 r14494  
    2121#define PXTREE_H 1
    2222
     23#include <stdio.h>
     24#include <stdbool.h>
     25
    2326#include <pslib.h>
     27
    2428
    2529typedef struct pxNode {
     
    2933} pxNode;
    3034
     35typedef bool (*pxNodeFunc)(pxNode *node);
     36
    3137pxNode *pxNodeAlloc(
    3238    const char *name,
    3339    pxNode  *parent
    3440) PS_ATTR_MALLOC;
     41
     42void pxNodePrint(
     43    FILE *stream,
     44    pxNode  *node
     45);
     46
     47bool pxTreeCrawl(
     48    pxNode  *node,
     49    pxNodeFunc func
     50);
    3551
    3652/*
Note: See TracChangeset for help on using the changeset viewer.