Personal tools
You are here: Home Projects C++ Cfront releases Release 3.0.3 source libSC G2++ g2++lib putbuf.c
Document Actions

putbuf.c

by Michael L Powell last modified 2007-01-26 03:23

Click here to get the file

Size 2.3 kB - File type text/plain

File contents

/*ident	"@(#)G2++:g2++lib/putbuf.c	3.1" */
/******************************************************************************
*
* C++ Standard Components, Release 3.0.
*
* Copyright (c) 1991, 1992 AT&T and Unix System Laboratories, Inc.
* Copyright (c) 1988, 1989, 1990 AT&T.  All Rights Reserved.
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T and Unix System
* Laboratories, Inc.  The copyright notice above does not evidence
* any actual or intended publication of such source code.
*
******************************************************************************/

#include <g2debug.h>
#include <g2ctype.h>
#include <g2io.h>
#include <g2tree.h>
#include <stream.h>

//  Local functions

static void putstr(
    ostream&		os,
    const String& 	s
);
static void puttabs (
    ostream&	os,
    int 	n
);
static void puttree(
    int 	level, 
    G2NODE* 	np, 
    ostream&	os
);

static String stack[G2MAXDEPTH_ATTLC];
static int stacklevel;	// previously emitted, still valid levels 
static int nonempty;

int putbuf_ATTLC(
    G2BUF* 	bp, 
    ostream&	os
){
    DEBUG(cerr << "in putbuf_ATTLC, *bp=\n";)
    DEBUG(showbuf_ATTLC(bp);)
    if( 
	bp->root 
    ){
	nonempty = 0;
	stacklevel = 0;
	puttree(0, bp->root, os);

	if( 
	    !nonempty 
	){
	    putstr(os, bp->root->name);
	    os << '\n';
	}
	if( 
	    Cchksum(os) 
	){
	    _g2putdot_ATTLC(os);
	}else{
	    os << '\n';
	}
	/*Eor(os);*/
    }
    return(Check_error(os)? -1 : 0);
}

static void putstr(
    ostream&		os,
    const String& 	s
){
    int i=0;

    while( 
	i< s.length() && 
	isprint_ATTLC(s.char_at(i)) 
    ){
	os << s.char_at(i);
	i++;
    }
}

static void puttabs(
    ostream&	os,
    int 	n
){
    while( 
	--n >= 0 
    ){
	os << '\t';
    }
}

static void puttree(
    int 	level, 
    G2NODE* 	np, 
    ostream&	os
){
    if( 
	np->child 
    ){
	register G2NODE* tp = np->child;
	stack[level] = np->name;

	do{
	    puttree(level+1, tp, os);
	}while( tp = tp->next );

    }else if( 
	!(np->val).is_empty() 
    ){
	nonempty = 1;

	for(
	    ; 
	    stacklevel < level; 
	    stacklevel++
	){
	    puttabs(os, stacklevel);
	    putstr(os, stack[stacklevel]);
	    os << '\n';
	}
	puttabs(os, level);
	putstr(os, np->name);	
	os << '\t';
	putstr(os, np->val);
	os << '\n';
    }
    if(
	stacklevel > level
    ){
	stacklevel = level;
    }
}
« May 2024 »
Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: