/*
	ftally.C

	Version 1.5

	Tally all files matching the user-specified filespec.

	Copyright (C) 1993, Geoff Friesen B.Sc.
	All rights reserved.

	Developed with: Borland C++ 3.1
*/

/*
	set ti=c:\borlandc\tsr\tsrlib
	t ftally -hf -i
*/

#if !defined(__TINY__)
#error Tiny Memory Model Expected
#endif

#include "tsrlib.H"

char *title = "\r\n"

"ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»\r\n"
"º ±±±±± ±±±±±   ±   ±     ±     ±   ±             º\r\n"
"º ±       ±    ± ±  ±     ±     ±   ±             º\r\n"
"º ±       ±   ±   ± ±     ±     ±   ±             º\r\n"
"º ±±±±    ±   ±±±±± ±     ±      ±±±  Version 1.5 º\r\n"
"º ±       ±   ±   ± ±     ±       ±               º\r\n"
"º ±       ±   ±   ± ±     ±       ±               º\r\n"
"º ±       ±   ±   ± ±±±±± ±±±±±   ±               º\r\n"
"º                                                 º\r\n"
"º Copyright (C) 1993, Geoff Friesen B.Sc.         º\r\n"
"º All rights reserved.                            º\r\n"
"ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¼\r\n"
"$";

#define	SPECLEN	60

char filespec [SPECLEN+1];

#define	NCOLS	SPECLEN+14
#define	NROWS	7

char buffer [(NCOLS+1)*(NROWS+1)*2];

void main (void)
{
   long total_size;
   struct ffblk ffblk;
   int cshape, done, i, tally = 0, vmode, x, y;

   if ((vmode = v_getmode ()) != BW80 && vmode != C80 && vmode != MONO)
       return;

   cshape = v_getshape ();
   v_setshape (0x2000);         /* hide cursor */

   x = v_wherex ();
   y = v_wherey ();

   v_screen (SCREEN_SAVE, 1, 1, NCOLS+1, NROWS+1, buffer);

   v_setattr (LIGHTGRAY << 4);
   v_border (SINGLE_LINE, 1, 1, NCOLS, NROWS);
   v_gotoxy (3, 1);
   v_cputs ("¹ FTALLY v1.0 þ Press ESC to exit. Ì");
   v_shadow (1, 1, NCOLS, NROWS);
   v_clear(2, 2, NCOLS-2, NROWS-2);

   v_gotoxy (2, 3);
   v_cputs ("File Spec: ");

   while (1)
   {
      filespec [0] = '\0';

      if (getstr (filespec, SPECLEN) == ESC)
	  break;

      tally = 0;
      total_size = 0;

      done = findfirst (filespec, &ffblk, 0);
      while (!done)
      {
	 tally++;
	 total_size += ffblk.ff_fsize;
	 done = findnext (&ffblk);
      }

      v_gotoxy (2, 5);
      v_cprintf ("Total files = %05d and size = %10lu", tally, total_size);
      v_gotoxy (2, 6);
      v_cprintf ("Total files = %04x and size = %0*lX", tally, 9,
		 total_size);

      v_gotoxy (13, 3);
   }

   v_screen (SCREEN_RESTORE, 1, 1, NCOLS+1, NROWS+1, buffer);
   v_gotoxy (x, y);
   v_setshape (cshape);
}

#ifndef INCL_FIND
#include "find.C"
#endif

#ifndef INCL_GETSTR
#include "getstr.C"
#endif

#ifndef INCL_KFETCH
#include "kfetch.C"
#endif

#ifndef INCL_SPRINTF
#include "sprintf.C"
#endif

#ifndef INCL_VBORDER
#include "vborder.C"
#endif

#ifndef INCL_VCPRINTF
#include "vcprintf.C"
#endif

#ifndef INCL_VCPUTS
#include "vcputs.C"
#endif

#ifndef INCL_VGETMODE
#include "vgetmode.C"
#endif

#ifndef INCL_VGETSHAPE
#include "vgetshap.C"
#endif

#ifndef INCL_VGOTOXY
#include "vgotoxy.C"
#endif

#ifndef INCL_VPAINT
#include "vpaint.C"
#endif

#ifndef INCL_VSCREEN
#include "vscreen.C"
#endif

#ifndef INCL_VSETATTR
#include "vsetattr.C"
#endif

#ifndef INCL_VSETSHAPE
#include "vsetshape.C"
#endif

#ifndef INCL_VSHADOW
#include "vshadow.C"
#endif

#ifndef INCL_VWHEREX
#include "vwherex.C"
#endif

#ifndef INCL_VWHEREY
#include "vwherey.C"
#endif