clientprog.cc #1

  • //
  • guest/
  • Newtopian/
  • p4/
  • 2015.1/
  • client/
  • clientprog.cc
  • View
  • Commits
  • Open Download .zip Download (1 KB)
/*
 * Copyright 1995, 2011 Perforce Software.  All rights reserved.
 *
 * This file is part of Perforce - the FAST SCM System.
 */

# include <clientapi.h>
# include <clientprog.h>
# include <timer.h>
# include <progress.h>

ClientProgressText::ClientProgressText( int ty )
    : typeOfProgress( ty ), total( 0 ), cnt( 0 ), backup( 0 )
{
}

ClientProgressText::~ClientProgressText()
{
}

void
ClientProgressText::Description( const StrPtr *description, int units )
{
	desc.Set( description );
	printf( "%s ", desc.Text() );
	cnt = 0;
	backup = 0;
	total = 0;
}

void
ClientProgressText::Total( long t )
{
	total = t;
}

int
ClientProgressText::Update( long pos )
{
	StrBuf res;

	if( cnt == 40 )
	{
	    // every 40 updates, rewrite description

	    printf( "\r%s ", desc.Text() );
	    backup = 0;
	    cnt = 0;
	}
	if( total )
	{
	    int pct = int(100.0 * pos / total);

	    res << pct;
	    res.Extend( '%' );
	}
	else
	    res << pos;
	res.Extend( ' ' );
	res.Extend( "|/-\\"[ cnt++ & 3 ] );
	res.Terminate();

	while( backup-- > 0 )
		putchar( '\b' );

	fputs( res.Text(), stdout );
	backup = res.Length();

	fflush(stdout);

	return 0;
}

void
ClientProgressText::Done( int fail )
{
	if( backup )
	    putchar( '\b' );
	printf( fail == CPP_FAILDONE ? "failed!\n" : "finishing\n");
}
# Change User Description Committed
#1 14945 Newtopian Merging

//guest/perforce_software/p4/...

to //guest/Newtopian/p4/...
//guest/perforce_software/p4/2015.1/client/clientprog.cc
#1 12190 Matt Attaway Initial drop of 2015.1 p4/p4api source