Esempio n. 1
0
std::string LenTable::DumpDot() const {
    std::string res = "digraph G {\n";
    for (size_t nodeIdx = 0; nodeIdx < nodes.size(); ++nodeIdx) {
        HuffmanNode const& node = nodes[nodeIdx];
        res += dumpNode(node.left, nodeIdx, "0");
        res += dumpNode(node.right, nodeIdx, "1");
    }
    return res + "}";
}
Esempio n. 2
0
static int processSection(xmlElement *element, xml2lpc_context *ctx) {
	xmlNode *cur_node = NULL;
	xmlNode *cur_attr = NULL;
	const char *name = NULL;

	for (cur_attr = (xmlNode *)element->attributes; cur_attr; cur_attr = cur_attr->next) {
		dumpAttr(cur_attr, ctx);
		if(strcmp((const char*)cur_attr->name, "name") == 0) {
			name = (const char*)cur_attr->children->content;
		}
	}

	if(name != NULL) {
		for (cur_node = element->children; cur_node; cur_node = cur_node->next) {
			dumpNode(cur_node, ctx);
			if (cur_node->type == XML_ELEMENT_NODE) {
				if(strcmp((const char*)cur_node->name, "entry") == 0 ) {
					processEntry((xmlElement*)cur_node, name, ctx);
				}
			}

		}
		} else {
			xml2lpc_log(ctx, XML2LPC_WARNING, "ignored section with no \"name\" attribute, line:%d", xmlGetLineNo((xmlNode*)element));
		}

		return 0;
}
Esempio n. 3
0
void SCsTranslator::dumpNode(pANTLR3_BASE_TREE node, std::ofstream &stream)
{
    StringStream ss;
    ss << node;

    String s_root = ss.str().substr(3);
    pANTLR3_COMMON_TOKEN tok = node->getToken(node);
    if (tok)
    {
        stream << s_root << " [shape=box];" << std::endl;
        String label((const char*) node->getText(node)->chars);
        std::replace(label.begin(), label.end(), '"', '\'');
        stream << s_root << " [label=\"" << label << "\"];" << std::endl;
    }
    else
        stream << s_root << " [shape=circle];" << std::endl;

    uint32 n = node->getChildCount(node);
    for (uint32 i = 0; i < n; ++i)
    {
        pANTLR3_BASE_TREE child = (pANTLR3_BASE_TREE) node->getChild(node, i);
        StringStream s1;
        s1 << child;

        stream << s_root << " -> " << s1.str().substr(3) << ";" << std::endl;
        dumpNode(child, stream);
    }
}
Esempio n. 4
0
void dumpNode( TidyNode tnod, int indent )
{
	TidyNode child;

	for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) )
	{
		ctmbstr name;
		switch ( tidyNodeGetType(child) )
		{
		case TidyNode_Root:       name = "Root";                    break;
		case TidyNode_DocType:    name = "DOCTYPE";                 break;
		case TidyNode_Comment:    name = "Comment";                 break;
		case TidyNode_ProcIns:    name = "Processing Instruction";  break;
		case TidyNode_Text:       name = "Text";                    break;
		case TidyNode_CDATA:      name = "CDATA";                   break;
		case TidyNode_Section:    name = "XML Section";             break;
		case TidyNode_Asp:        name = "ASP";                     break;
		case TidyNode_Jste:       name = "JSTE";                    break;
		case TidyNode_Php:        name = "PHP";                     break;
		case TidyNode_XmlDecl:    name = "XML Declaration";         break;

		case TidyNode_Start:
		case TidyNode_End:
		case TidyNode_StartEnd:
		default:
			name = tidyNodeGetName( child );
			break;
		}
		assert( name != NULL );
		TRACE( "------%d,%d, %s,%s", indent, indent, " ", name );
		dumpNode( child, indent + 4 );
	}
}
void LLXmlTree::dump()
{
	if( mRoot )
	{
		dumpNode( mRoot, "    " );
	}
}
Esempio n. 6
0
/* Traverse the document tree */
void dumpNode(TidyDoc doc, TidyNode tnod, int indent )
{
  TidyNode child;
  for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) )
  {
    ctmbstr name = tidyNodeGetName( child );
    if ( name )
    {
      /* if it has a name, then it's an HTML tag ... */
      TidyAttr attr;
      printf( "%*.*s%s ", indent, indent, "<", name);
      /* walk the attribute list */
      for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) {
        printf(tidyAttrName(attr));
        tidyAttrValue(attr)?printf("=\"%s\" ",
                                   tidyAttrValue(attr)):printf(" ");
      }
      printf( ">\n");
    }
    else {
      /* if it doesn't have a name, then it's probably text, cdata, etc... */
      TidyBuffer buf;
      tidyBufInit(&buf);
      tidyNodeGetText(doc, child, &buf);
      printf("%*.*s\n", indent, indent, buf.bp?(char *)buf.bp:"");
      tidyBufFree(&buf);
    }
    dumpNode( doc, child, indent + 4 ); /* recursive */
  }
}
Esempio n. 7
0
void GraphVizContext::connect(MemNode* node, MemNode* other, const char* dst)
{
  dumpNode(other);

  fprintf(file, "  NODE_%p:%s -> NODE_%p:C", node, dst, other);
  if (other->red) fprintf(file, " [style=bold, color=red]");
  fprintf(file, ";\n");
}
Esempio n. 8
0
void SCsTranslator::dumpDot(pANTLR3_BASE_TREE tree)
{
    std::ofstream out("test.dot");

    out << "digraph g {" << std::endl;
    dumpNode(tree, out);
    out << "}" << std::endl;

    out.close();
}
void LLXmlTree::dumpNode( LLXmlTreeNode* node, const std::string& prefix )
{
	node->dump( prefix );

	std::string new_prefix = prefix + "    ";
	for( LLXmlTreeNode* child = node->getFirstChild(); child; child = node->getNextChild() )
	{
		dumpNode( child, new_prefix );
	}
}
Esempio n. 10
0
static int processDoc(xmlNode *node, xml2lpc_context *ctx) {
	dumpNode(node, ctx);

	if (node->type == XML_ELEMENT_NODE &&
		strcmp((const char*)node->name, "config") == 0 ) {
		processConfig((xmlElement*)node, ctx);
	} else {
		xml2lpc_log(ctx, XML2LPC_WARNING, "root element is not \"config\", line:%d", xmlGetLineNo(node));
	}
	return 0;
}
Esempio n. 11
0
int main(int argc, char **argv )
{
  CURL *curl;
  char curl_errbuf[CURL_ERROR_SIZE];
  TidyDoc tdoc;
  TidyBuffer docbuf = {0};
  TidyBuffer tidy_errbuf = {0};
  int err;
  if ( argc == 2) {
    curl = curl_easy_init();
    curl_easy_setopt(curl, CURLOPT_URL, argv[1]);
    curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
    curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);

    tdoc = tidyCreate();
    tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */
    tidyOptSetInt(tdoc, TidyWrapLen, 4096);
    tidySetErrorBuffer( tdoc, &tidy_errbuf );
    tidyBufInit(&docbuf);

    curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);
    err=curl_easy_perform(curl);
    if ( !err ) {
      err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */
      if ( err >= 0 ) {
        err = tidyCleanAndRepair(tdoc); /* fix any problems */
        if ( err >= 0 ) {
          err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */
          if ( err >= 0 ) {
            dumpNode( tdoc, tidyGetRoot(tdoc), 0 ); /* walk the tree */
            fprintf(stderr, "%s\n", tidy_errbuf.bp); /* show errors */
          }
        }
      }
    }
    else
      fprintf(stderr, "%s\n", curl_errbuf);

    /* clean-up */
    curl_easy_cleanup(curl);
    tidyBufFree(&docbuf);
    tidyBufFree(&tidy_errbuf);
    tidyRelease(tdoc);
    return(err);

  }
  else
    printf( "usage: %s <url>\n", argv[0] );

  return(0);
}
Esempio n. 12
0
static int processConfig(xmlElement *element, xml2lpc_context *ctx) {
	xmlNode *cur_node = NULL;

	for (cur_node = element->children; cur_node; cur_node = cur_node->next) {
		dumpNode(cur_node, ctx);
		if (cur_node->type == XML_ELEMENT_NODE &&
			strcmp((const char*)cur_node->name, "section") == 0 ) {
			processSection((xmlElement*)cur_node, ctx);
			}

		}
	return 0;
}
Esempio n. 13
0
// full-line dump of a NodeCore
// override this to completely re-implement the dump format for your Node type
void NodeCore::dump()
{
 dumpNode();
	if (!mReferences.empty()) {
		Debug::dump(" {");
		for (ReferenceSet::const_iterator it = mReferences.begin(); it != mReferences.end(); it++) {
			Debug::dump(" %p", it->get());
			if ((*it)->mReferent != this)
				Debug::dump("!*INVALID*");
		}
		Debug::dump(" }");
	}
	Debug::dump("\n");
}
Esempio n. 14
0
void KateCodeFoldingTree::dumpNode(KateCodeFoldingNode *node, const TQString &prefix)
{
  //output node properties
  kdDebug(13000)<<prefix<<TQString(TQString("Type: %1, startLineValid %2, startLineRel %3, endLineValid %4, endLineRel %5, visible %6").
      arg(node->type).arg(node->startLineValid).arg(node->startLineRel).arg(node->endLineValid).
      arg(node->endLineRel).arg(node->visible))<<endl;

  //output child node properties recursive
  if (node->noChildren())
    return;

  TQString newprefix(prefix + "   ");
  for ( uint i=0; i < node->childCount(); ++i )
    dumpNode (node->child(i),newprefix);
}
Esempio n. 15
0
        std::string dumpNode(std::size_t level, const_level_iterator it) const
        {
            std::string result;

            for(size_t i = 0; it.valid(); ++it, i++)
            {
                result.append(level * 4, ' ');        // add indent
                result += std::to_string(i) + ": ";   // index
                result += *it;                        // value
                result += '\n';

                if (it.children_count() > 0)
                    result += dumpNode(level + 1, it.begin());
            }

            return result;
        }
Esempio n. 16
0
int
main(int argc, char ** argv) 
{
    /* this is not a stream parser, let's read as much as we can up to a
     * reasonable limit  (1 meg) */
    static unsigned char inbuf[MAX_INPUT_TEXT];
    size_t tot = 0, rd;
    while (0 < (rd = read(0, (void *) (inbuf + tot), MAX_INPUT_TEXT)))
        tot += rd;

    {
        orderly_node * n;
        orderlyTestMemoryContext memStats;
        orderly_parse_status s;
        const char *error;
        orderly_alloc_funcs oaf = {
            orderlyTestMalloc,
            orderlyTestRealloc,
            orderlyTestFree,
            &memStats
        };
        memset((void *) &memStats, 0, sizeof(memStats));
        
        s = orderly_parse(&oaf, inbuf, tot, &error, &n, NULL);
        printf("parse complete (%s):\n", statusToStr(s, error));
        dumpNode(&oaf, n, 0); /* here's where we'll map over and output the returned tree */ 
        /* TODO: ugly alloc routine crap here, perhaps we should give the
         *       ultimate client a parse handle and make the ownership of
         *       the parse tree held by the parse handle? */
        orderly_free_node(&oaf, &n);

        /* now memstats! */
        if (memStats.numFrees < memStats.numMallocs)
        {
            printf("MEMORY LEAK: %d allocations/%d frees\n",
                   memStats.numMallocs, memStats.numFrees);
        }
    }
    
    return 0;
}
Esempio n. 17
0
int main(int argc, char **argv )
{
   CURL *curl;
   char curl_errbuf[CURL_ERROR_SIZE];
   char url[URL_BUF_SIZE];
   char *username;
   TidyDoc tdoc;
   TidyBuffer docbuf = {0};
   TidyBuffer tidy_errbuf = {0};
   int err;
   if ( argc == 2) 
   {
      username = argv[1];
   }
   else
   {
      username = "******";
   }
   WeatherData data;
   snprintf(url, URL_BUF_SIZE, "http://www.weatherlink.com/user/%s/index.php?view=summary&headers=0&type=2", username);
   curl = curl_easy_init();
   curl_easy_setopt(curl, CURLOPT_URL, url);
   curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_errbuf);
   curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L);
   curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
   curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb);

   tdoc = tidyCreate();
   tidyOptSetBool(tdoc, TidyForceOutput, yes); /* try harder */
   tidyOptSetInt(tdoc, TidyWrapLen, 4096);
   tidySetErrorBuffer( tdoc, &tidy_errbuf );
   tidyBufInit(&docbuf);

   curl_easy_setopt(curl, CURLOPT_WRITEDATA, &docbuf);
   err=curl_easy_perform(curl);
   if ( !err ) 
   {
      err = tidyParseBuffer(tdoc, &docbuf); /* parse the input */
      if ( err >= 0 ) 
      {
         err = tidyCleanAndRepair(tdoc); /* fix any problems */
         if ( err >= 0 ) 
         {
            dumpNode( tdoc, tidyGetRoot(tdoc), 0, &data ); /* walk the tree */
            //err = tidyRunDiagnostics(tdoc); /* load tidy error buffer */
            //if ( err >= 0 ) 
            //{
               //dumpNode( tdoc, tidyGetRoot(tdoc), 0 ); /* walk the tree */
            //   fprintf(stderr, ">> %s\n", tidy_errbuf.bp); /* show errors */
            //}
         }
      }
   }
   else
   {
      fprintf(stderr, "%s\n", curl_errbuf);
   }
   printf("Outside temp: %f\n", data.outsideTemp );
   printf("Outside humidity: %d\n", data.outsideHumidity );
   printf("Dew Point: %f\n", data.dewPoint );
   printf("Barometer: %f\n", data.barometer );
   printf("Wind speed: %f\n", data.instantWindSpeed );
   printf("Wind direction: %d\n", data.instantWindDirection );
   printf("Average Wind: %f\n", data.avgWindSpeed_2min );
   printf("Wind Gust: %f\n", data.windGust_10min);
   printf("rainRate: %f\n", data.rainRate );
   printf("dailyRain: %f\n", data.dailyRain );
   printf("lastHourRain: %f\n", data.lastHourRain );

   /* clean-up */
   curl_easy_cleanup(curl);
   tidyBufFree(&docbuf);
   //tidyBufFree(&tidy_errbuf);
   tidyRelease(tdoc);
   return(err);


  return(0);
}
Esempio n. 18
0
unsigned int writeNode(FILE *out,struct countnode *n,char *s,
		       /* Terminations don't get counted internally in a node,
			  but are used when encoding and decoding the node,
			  so we have to pass it in here. */
		       int totalCountIncludingTerminations,int threshold)
{
  nodesWritten++;
  char schild[128];
  int i;

  long long totalCount=0;

  int debug=0;

  for(i=0;i<CHARCOUNT;i++) totalCount+=getCount(n,i);
  if (totalCount!=n->count) {
    fprintf(stderr,"Sequence '%s' counts don't add up: %lld vs %lld\n",
	    s,totalCount,n->count);
  }

  if (debug) fprintf(stderr,"sequence '%s' occurs %lld times (%d inc. terminals).\n",
		 s,totalCount,totalCountIncludingTerminations);
  /* Don't go any deeper if the sequence is too rare */
  if (totalCount<threshold) return 0;

  int children=0;
  if (n->allChildren) {
    for(i=0;i<CHARCOUNT;i++) 
      if (n->allChildren[i]) children++;
  } else {
    for(i=0;i<FEW;i++) if (n->fewChildIds[i]) children++;
  }
      
  range_coder *c=range_new_coder(1024);

  int childAddresses[CHARCOUNT];
  int childCount=0;
  int storedChildren=0;

  /* Encode children first so that we know where they live */
  for(i=0;i<CHARCOUNT;i++) {
    childAddresses[i]=0;

    struct countnode **nn;
    nn=getChild(n,i,0);
    if (nn&&*nn&&(*nn)->count>=threshold) {
      if (0) fprintf(stderr,"n->children[%d]->count=%lld\n",i,(*nn)->count);
      snprintf(schild,128,"%s%c",s,chars[i]);
      childAddresses[i]=writeNode(out,*nn,schild,totalCount,threshold);
      storedChildren++;
    }
    if (getCount(n,i)) {
      childCount++;
    }
  }
  
  /* Write total count in this node */
  range_encode_equiprobable(c,totalCountIncludingTerminations+1,totalCount);
  /* Write number of children with counts */
  range_encode_equiprobable(c,CHARCOUNT+1,childCount);
  /* Now number of children that we are storing sub-nodes for */
  range_encode_equiprobable(c,CHARCOUNT+1,storedChildren);

  unsigned int highAddr=ftell(out);
  unsigned int lowAddr=0;
  if (debug) fprintf(stderr,"  lowAddr=0x%x, highAddr=0x%x\n",lowAddr,highAddr);

  if (debug)
    fprintf(stderr,
	    "wrote: childCount=%d, storedChildren=%d, count=%lld, superCount=%d @ 0x%x\n",
	    childCount,storedChildren,totalCount,totalCountIncludingTerminations,
	    (unsigned int)ftello(out));

  unsigned int remainingCount=totalCount;
  // XXX - we can improve on these probabilities by adjusting them
  // according to the remaining number of children and stored children.
  unsigned int hasCount=(CHARCOUNT-childCount)*0xffffff/CHARCOUNT;
  unsigned int isStored=(CHARCOUNT-storedChildren)*0xffffff/CHARCOUNT;
  for(i=0;i<CHARCOUNT;i++) {
    hasCount=(CHARCOUNT-i-childCount)*0xffffff/(CHARCOUNT-i);

    if (getCount(n,i)) {
      snprintf(schild,128,"%c%s",chars[i],s);
      if (debug) 
	fprintf(stderr, "writing: '%s' x %d\n",
		schild,getCount(n,i));
      if (debug) fprintf(stderr,":  writing %d of %d count for '%c'\n",
			 getCount(n,i),remainingCount+1,chars[i]);

      range_encode_symbol(c,&hasCount,2,1);
      range_encode_equiprobable(c,remainingCount+1,getCount(n,i));

      remainingCount-=getCount(n,i);
      childCount--;
    } else {
      range_encode_symbol(c,&hasCount,2,0);
    }
  }
      
  for(i=0;i<CHARCOUNT;i++) {
    isStored=(CHARCOUNT-i-storedChildren)*0xffffff/(CHARCOUNT-i);
    if (childAddresses[i]) {
      range_encode_symbol(c,&isStored,2,1);
      if (debug) fprintf(stderr,":    writing child %d (address attached)\n",i);
	
      /* Encode address of child node compactly.
	 For starters, we know that it must preceed us in the bit stream.
	 We also know that we write them in order, so once we know the address
	 of a previous one, we can narrow the range further. */
      range_encode_equiprobable(c,highAddr-lowAddr+1,childAddresses[i]-lowAddr);
      if (debug) fprintf(stderr,":    writing addr = %d of %d (lowAddr=%d)\n",
			 childAddresses[i]-lowAddr,highAddr-lowAddr+1,lowAddr);
      lowAddr=childAddresses[i];
      storedChildren--;
    } else {
      range_encode_symbol(c,&isStored,2,0);
    }  
  }

  range_conclude(c);

  /* Unaccounted for observations are observations that terminate at this point.
     They are totall normal and expected. */
  if (debug)
    if (remainingCount) {    
      fprintf(stderr,"'%s' Count incomplete: %d of %lld not accounted for.\n",
	      s,remainingCount,totalCount);
    }
  
  unsigned int addr = ftello(out);
  int bytes=c->bits_used>>3;
  if (c->bits_used&7) bytes++;
  fwrite(c->bit_stream,bytes,1,out);

  /* Verify */
  {
    /* Make pretend stats handle to extract from */
    stats_handle h;
    h.file=(FILE*)0xdeadbeef;
    h.mmap=c->bit_stream;
    h.dummyOffset=addr;
    h.fileLength=addr+bytes;
    if (0) fprintf(stderr,"verifying node @ 0x%x\n",addr);
    struct node *v=extractNodeAt(NULL,0,addr,totalCountIncludingTerminations,&h,
				 0 /* don't extract whole tree */,debug);

    int i;
    int error=0;
    for(i=0;i<CHARCOUNT;i++)
      {
	if (v->counts[i]!=getCount(n,i)) {
	  if (!error) {
	    fprintf(stderr,"Verify error writing node for '%s'\n",s);
	    fprintf(stderr,"  n->count=%lld, totalCount=%lld\n",
		    n->count,totalCount);
	  }
	  fprintf(stderr,"  '%c' (%d) : %d versus %d written.\n",
		  chars[i],i,v->counts[i],getCount(n,i));
	  error++;
	}
      }
    if (error) {
      fprintf(stderr,"Bit stream (%d bytes):",bytes);
      for(i=0;i<bytes;i++) fprintf(stderr," %02x",c->bit_stream[i]);
      fprintf(stderr,"\n");
      exit(-1);
    }
#ifdef DEBUG
    if ((!strcmp(s,"esae"))||(!strcmp(s,"esael")))
      {
	fprintf(stderr,"%s 0x%x (%f bits) totalCountIncTerms=%d\n",
		s,addr,c->entropy,totalCountIncludingTerminations);
	dumpNode(v);
      }
#endif
    node_free(v);
  }
  range_coder_free(c);

  return addr;
}
Esempio n. 19
0
        std::string dump() const
        {
            const std::string result = empty()? "": dumpNode( 0, const_level_iterator(begin()) );

            return result;
        }
Esempio n. 20
0
void KateCodeFoldingTree::debugDump()
{
  //dump all nodes for debugging
  kdDebug(13000)<<"The parsed region/block tree for code folding"<<endl;
  dumpNode(&m_root, "");
}
Esempio n. 21
0
/**
 * Dumps an entire subtree
 *
 * @param [in] node The root node of the subtree.
 * @param [in] depth The depth of the node.
 * @param [in] dir which subtree (negative: left, positive: right)
 * @param [in] dumpFn Dump function first argument is the key, second is the value.
 */
static void dumpSubtree(const AVL_Node *node, int depth, char dir, void (*dumpFn)(const void*, const void*))
{
    if (node) dumpSubtree(node->left, depth + 1, -1, dumpFn);
    dumpNode(node, depth, dir, dumpFn);
    if (node) dumpSubtree(node->right, depth + 1, 1, dumpFn);
}
Esempio n. 22
0
static void dumpNode(orderly_alloc_funcs * oaf, orderly_node * n, unsigned int indent)
{
    orderly_buf b = orderly_buf_alloc(oaf);
    char * indentStr = (char *) malloc(indent * 4 + 1);
    memset((void *) indentStr, ' ', indent * 4);
    indentStr[indent*4] = 0;

    if (n) {
        const char * type = orderly_node_type_to_string(n->t);
        if (NULL == type) type = "unknown";

        printf("%s%s [%s]%s%s\n", indentStr, n->name ? n->name : "", type,
               n->optional ? " OPTIONAL" : "",
               n->additional_properties ? " OPEN" : "");
        if (n->default_value) {
            orderly_buf_clear(b);
            orderly_write_json(oaf, n->default_value, b, 0);
            printf("%s--> default: %s\n", indentStr, orderly_buf_data(b));
        }
        
        if (n->values) {
            orderly_buf_clear(b);
            orderly_write_json(oaf, n->values, b, 0);
            printf("%s--> enum: %s\n", indentStr, orderly_buf_data(b));
        }
        if (n->requires) {
            const char ** p = n->requires;
            printf("%s--> requires: ", indentStr);
            while (p && *p) {
                if (p != n->requires) printf(", ");
                printf("%s", *p);
                p++;
            }
            printf("\n");
        }
        
        if (n->regex) printf("%s--> regex: %s\n", indentStr, n->regex);        
        if (ORDERLY_RANGE_SPECIFIED(n->range)) {
            printf("%s--> range: {", indentStr);
            if (ORDERLY_RANGE_LHS_DOUBLE & n->range.info)
                printf("%g", n->range.lhs.d);
            else if (ORDERLY_RANGE_LHS_INT & n->range.info)            
                printf("%ld", n->range.lhs.i);
            printf(",");
            if (ORDERLY_RANGE_RHS_DOUBLE & n->range.info)
                printf("%g", n->range.rhs.d);
            else if (ORDERLY_RANGE_RHS_INT & n->range.info)            
                printf("%ld", n->range.rhs.i);
            printf("}\n");
        }
        if (n->child) {
            printf("%schildren:\n", indentStr);
            dumpNode(oaf, n->child, indent + 1);
        }
        if (n->sibling) {
            dumpNode(oaf, n->sibling, indent);
        }
    } else {
        printf("%s(null)\n", indentStr);
    }
    free(indentStr);
    orderly_buf_free(b);
}
Esempio n. 23
0
/* Traverse the document tree */
int dumpNode(TidyDoc doc, TidyNode tnod, int element, WeatherData *data )
{
  TidyNode child;
  for ( child = tidyGetChild(tnod); child; child = tidyGetNext(child) )
  {
    element++;
    ctmbstr name = tidyNodeGetName( child );
    if ( name )
    {
      /* if it has a name, then it's an HTML tag ... */
      //TidyAttr attr;
      //printf( "%*.*s%s ", indent, indent, "<", name);
      /* walk the attribute list */
      //for ( attr=tidyAttrFirst(child); attr; attr=tidyAttrNext(attr) ) {
        //printf(tidyAttrName(attr));
        //tidyAttrValue(attr)?printf("=\"%s\" ",
                                   //tidyAttrValue(attr)):printf(" ");
      //}
      //printf( ">\n");
    }
    else {
      /* if it doesn't have a name, then it's probably text, cdata, etc... */
      TidyBuffer buf;
      tidyBufInit(&buf);
      tidyNodeGetText(doc, child, &buf);
      //printf("[%d]%s\n", element, buf.bp?(char *)buf.bp:"");
      switch (element)
      {
         case 133:
            sscanf( (char*)buf.bp, "%lf", &(data->outsideTemp) );
            break;
         case 159:
            sscanf( (char*)buf.bp, "%d", &(data->outsideHumidity));
            break;
         case 301:
            sscanf( (char*)buf.bp, "%lf", &(data->dewPoint));
            break;
         case 333:
            sscanf( (char*)buf.bp, "%lf", &(data->barometer));
            break;
         case 391: // wind speed
            if ( sscanf( (char*)buf.bp, "%lf", &(data->instantWindSpeed)) == 0)
            {
               data->instantWindSpeed = 0;
            }
            break;
         case 417: // wind direction
            {
               char b[100];
               int i,j=0;
               for ( i=0; i<strlen((char*)buf.bp); i++)
               {
                  if ( isdigit( ((char*)buf.bp)[i]))
                  {
                     b[j] = ((char*)buf.bp)[i];
                     j++;
                  }
               }
               b[j] = 0;
               sscanf( b, "%d", &(data->instantWindDirection));
            }
            break;
         case 503:
            if ( sscanf( (char*)buf.bp, "%lf", &(data->avgWindSpeed_2min)) == 0 )
            {
               data->avgWindSpeed_2min = 0;
            }
            break;
         case 533:
            if ( sscanf( (char*)buf.bp, "%lf", &(data->windGust_10min)) == 0 )
            {
               data->windGust_10min = 0;
            }
            break;
         case 599:
            sscanf( (char*)buf.bp, "%lf", &(data->rainRate));
            break;
         case 603:
            sscanf( (char*)buf.bp, "%lf", &(data->dailyRain));
            break;
         case 625:
            sscanf( (char*)buf.bp, "%lf", &(data->lastHourRain));
            break;
      }
      tidyBufFree(&buf);
    }
    element++;
    element = dumpNode( doc, child, element, data ); /* recursive */
  }
  return element;
}