1cfc0a495SScott Long /* $NetBSD: progressbar.c,v 1.21 2009/04/12 10:18:52 lukem Exp $ */ 2cfc0a495SScott Long 3cfc0a495SScott Long /*- 4*b61a5730SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 51de7b4b8SPedro F. Giffuni * 6cfc0a495SScott Long * Copyright (c) 1997-2012 The NetBSD Foundation, Inc. 7cfc0a495SScott Long * All rights reserved. 8cfc0a495SScott Long * 9cfc0a495SScott Long * This code is derived from software contributed to The NetBSD Foundation 10cfc0a495SScott Long * by Luke Mewburn. 11cfc0a495SScott Long * 12cfc0a495SScott Long * Redistribution and use in source and binary forms, with or without 13cfc0a495SScott Long * modification, are permitted provided that the following conditions 14cfc0a495SScott Long * are met: 15cfc0a495SScott Long * 1. Redistributions of source code must retain the above copyright 16cfc0a495SScott Long * notice, this list of conditions and the following disclaimer. 17cfc0a495SScott Long * 2. Redistributions in binary form must reproduce the above copyright 18cfc0a495SScott Long * notice, this list of conditions and the following disclaimer in the 19cfc0a495SScott Long * documentation and/or other materials provided with the distribution. 20cfc0a495SScott Long * 21cfc0a495SScott Long * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22cfc0a495SScott Long * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23cfc0a495SScott Long * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24cfc0a495SScott Long * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25cfc0a495SScott Long * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26cfc0a495SScott Long * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27cfc0a495SScott Long * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28cfc0a495SScott Long * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29cfc0a495SScott Long * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30cfc0a495SScott Long * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31cfc0a495SScott Long * POSSIBILITY OF SUCH DAMAGE. 32cfc0a495SScott Long */ 33cfc0a495SScott Long 34cfc0a495SScott Long #ifndef PROGRESS_H_ 35cfc0a495SScott Long #define PROGRESS_H_ 20100228 36cfc0a495SScott Long 37cfc0a495SScott Long #include <sys/types.h> 38cfc0a495SScott Long 39cfc0a495SScott Long #include <inttypes.h> 40cfc0a495SScott Long 41cfc0a495SScott Long /* structure used to display a progress meter */ 42cfc0a495SScott Long typedef struct progress_t { 43cfc0a495SScott Long char *prefix; /* any prefix explanation */ 44cfc0a495SScott Long uint64_t size; /* total of bytes/units to be counted */ 45cfc0a495SScott Long uint64_t done; /* number of units counted to date */ 46cfc0a495SScott Long uint64_t percent; /* cache the percentage complete */ 47cfc0a495SScott Long time_t start; /* time we started this */ 48cfc0a495SScott Long time_t now; /* time now */ 49cfc0a495SScott Long time_t eta; /* estimated # of secs until completion */ 50cfc0a495SScott Long int64_t elapsed; /* cached # of elapsed seconds */ 51cfc0a495SScott Long int32_t ttywidth; /* width of tty in columns */ 52cfc0a495SScott Long } progress_t; 53cfc0a495SScott Long 54cfc0a495SScott Long int progress_init(progress_t */*meter*/, const char */*prefix*/, uint64_t /*size*/); 55cfc0a495SScott Long int progress_update(progress_t */*meter*/, uint64_t /*done*/); 56cfc0a495SScott Long int progress_draw(progress_t */*meter*/); 57cfc0a495SScott Long int progress_reset_size(progress_t */*meter*/, uint64_t /*size*/); 58cfc0a495SScott Long int progress_complete(progress_t */*meter*/, uint64_t /*done*/); 59cfc0a495SScott Long 60cfc0a495SScott Long #endif 61