home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / CLIPPER / PPP.ZIP / PPPDEMO.PRG < prev    next >
Text File  |  1994-03-21  |  4KB  |  112 lines

  1. /*
  2.  
  3.     P O W E R   P A C K E D   P R I N T O U T S
  4.     Copyright (c) 1994
  5.     Stephen L. Woolstenhulme
  6.     All Rights Reserved
  7.  
  8.     CIS:  73060,1302
  9.  
  10. */
  11.  
  12. // PPPdemo.prg:   demo program turns default directory into a report.
  13.  
  14. #include "ppp.ch"
  15. #include "inkey.ch"
  16.  
  17. function PPPdemo()
  18.    local i
  19.    local aItem := {}
  20.    local nFiles := 0
  21.    local nSize := 0
  22.  
  23.    // get data for the report.  
  24.    local aDirectory := directory( '*.*' )
  25.    
  26.    // set up page and column headers.
  27.    local aPageHead := { 'Files in ' + curdir(), date(), '' }
  28.    
  29.    local aColumnHead := { ;
  30.       '===================================================', ;
  31.       'File              Size       Date      Time    Attr', ;
  32.       '============  ===========  ========  ========  ====' ;
  33.       }
  34.    
  35.    // Store the new values into the static array.  Note you need store
  36.    // only values you want changed.  All others can be left to default
  37.    // values.
  38.  
  39.    // See PPP.CH for a list of all variables you can set.
  40.  
  41.    pppSet( PPP_PAGEHEAD,    aPageHead   )  // set new page header. 
  42.    pppSet( PPP_COLUMNHEAD,  aColumnHead )  // set new column header.
  43.    pppSet( PPP_COLUMNSPACE, 2 )            // double space between columns.
  44.    pppSet( PPP_DESPOOL, .f. )              // gather before printing.
  45.    pppSet( PPP_COPIES, 1 )                 // don't waste paper <g>.
  46.  
  47.    // Stick in code to set 80 column print on an HP.  Use chr( 18 ) on Epson.
  48.    pppSet( PPP_PRNINIT, chr(27) + chr(38) + 'k0S' )
  49.    
  50.    // And a printer reset afterward.
  51.    pppSet( PPP_PRNRESET, chr(27) + 'E' )
  52.  
  53.    if ! pppInit() == 'E'                   // Returns S for screen, P for
  54.                                            // printer, F for file, or 
  55.                                            // E for exit.  You can optionally
  56.                                            // pass in S or P as a parameter
  57.                                            // and the program won't pause to
  58.                                            // ask.
  59.       
  60.       // let's sort it to make it pretty.  This slows things just a bit.
  61.       aDirectory := asort( aDirectory,,, { | x, y | x[1] < y[1] } )
  62.  
  63.       for i := 1 to len( aDirectory )
  64.          
  65.          // build an array of items to send.  
  66.          aItem := array( 5 )
  67.          aItem[1] := strtran( aDirectory[ i, 1 ], '.', space( 13 - len( aDirectory[ i, 1 ] ) ) )
  68.          aItem[2] := transform( aDirectory[ i, 2 ], '999,999,999' )
  69.          aItem[3] := aDirectory[ i, 3 ]
  70.          aItem[4] := aDirectory[ i, 4 ]
  71.          aItem[5] := padc( aDirectory[ i, 5 ], 4 )
  72.          
  73.          // send array to be printed, with each element as a separate column.
  74.          pppLine( aItem )
  75.  
  76.          // accumulate totals.
  77.          nFiles++
  78.          nSize += aDirectory[ i, 2 ]
  79.  
  80.          if stopNow()
  81.             exit
  82.          endif
  83.  
  84.       next
  85.       
  86.       // print underlines.
  87.       pppLine( aColumnHead[ 3 ] )
  88.       
  89.       // format and print grand totals.
  90.       aItem := { padr( ltrim( str( nFiles ) ) + ' files', 12 ), ;
  91.                  transform( nSize, '999,999,999' ) }
  92.       pppLine( aItem )
  93.  
  94.       // adds final underline, lets user browse;
  95.       // cleans up temp files and clears settings after.
  96.       pppDone()
  97.    endif
  98.  
  99. return NIL
  100.  
  101.  
  102. Function stopNow
  103.    local nPause := inkey()
  104.    local lRetVal := .f.
  105.  
  106.    if ! nPause == 0
  107.       lRetVal := alert( ' You pressed a key.  Please select... ', ;
  108.                       { ' Continue ' , ' Quit ' }  ) == 2
  109.    endif
  110.  
  111. return lRetVal
  112.