TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: All
from: Frank Adam
date: 1996-08-21 08:53:00
subject: Bars anyone ?

Hi guys,

/*
This place is getting very quiet again and i was bored, so why
shouldn't i bore you guys too.:-)
This is one cute way of making a progress bar and handling sequential data,
probably the least recommended way too, as it's rather hungry :-)
I still like it but..
Docs are kept to a minimum 'cause somehow i don't think this'll make
the Hall of Fame.:-)
It's not very complicated to grasp anyway.
*/

/*
   Oh, did i mention VidMgr ? You must have it to run this..
   Andrew sends me a cheque every time i say that :-)

   Btw, Andrew i think i've found another bug,
   have to look at vm_printf and vm_xputch the screen positions don't
   seem to correspond. Didn't want to bother now, but take a look at
   the initial function call to Stream_Bar() and the output after.
*/

#include 
#include 
#include 
#include "vidmgr.h"


#define Set_Attrib(fore,back) (((back << 4) + fore) & 127)

#define STREAMBAR "%ld%d%d%d%d%c%c%c%c"
    /* size,barlen,barchar,x,y,barattrib */
    /* backattrib, percentage x, percentage y*/

#define NEXTBAR ""

unsigned long Stream_Bar(char *fmt,...)
{
 va_list argptr;
 static unsigned long blocksize,lastblocksize;
 static int done = 0,barlen = 0,steps;
 static char barchar,attrib;
 static char xpos,ypos;
 static char percx,percy;
 static float j = 0,j1;
 int i;

 if(*fmt)
 {
  unsigned long size;
  char fattr,battr;
  va_start(argptr, fmt);
   size = va_arg(argptr,long);
   barlen = va_arg(argptr,int);
   barchar= va_arg(argptr,int);
   xpos = va_arg(argptr,int);
   ypos = va_arg(argptr,int);
   fattr = va_arg(argptr,char);
   battr = va_arg(argptr,char);
   percx = va_arg(argptr,char);
   percy = va_arg(argptr,char);
  va_end(argptr);

   blocksize = size/(long) barlen;
   attrib = Set_Attrib(fattr,battr); /* vm_mkcolor(fattr,battr);  */
   lastblocksize = size - (blocksize * barlen);
   j1 = (float) 100/barlen;
   if(blocksize == 0 && lastblocksize > 0)
   {
    steps = barlen;
    blocksize = lastblocksize;
    lastblocksize = 0;
    done = 1;
    }
   else steps = 1;

   for(i = xpos; i < (barlen + xpos);i++)
   {
    vm_xputch(i,ypos,attrib,' ');
    }
  return blocksize;
  }

else if(barlen > -1)
{
  switch(barlen)
  {
   case 0  : done = 1;break;

   case 1  : if(lastblocksize) blocksize = lastblocksize;
       else blocksize = 0;

   default : for (i = 0;i < steps; i++)
      {
       vm_xputch(xpos,ypos,attrib,barchar);
       barlen--;xpos++;
       }
    }
  }


if(!done)
{
 if(percx && percy)
 {
  j += j1;
  vm_printf(percx,percy,"%3d% Done",(int)(j+.1));
  }
 return blocksize;
 }

return 0;
}


int main( void )
{
 unsigned long num = 9000171L; /* eg.: a file's size */
 int xpos = 10,ypos = 10,barlen = 65,ch = 178;
 unsigned long count = 0;
 unsigned long blocks;
 unsigned long j;

 vm_paintclearscreen(Set_Attrib(7,0));
 blocks = Stream_Bar(STREAMBAR,num,barlen,ch,xpos,ypos,1,11,1,10);

 while(blocks)
 {
   for(j=0L;j * Origin: The Software Parlour (3:635/544)
SEEN-BY: 50/99 620/243 623/630 632/349 635/503 544 727 711/401 409 410 413
SEEN-BY: 711/430 808 809 932 934 712/515 713/888 714/906 800/1
@PATH: 635/544 50/99 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.