home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / newc_dev / newlist6.lzh / NewList6 / FormatTutorial.doc next >
Text File  |  1991-12-18  |  3KB  |  116 lines

  1.  
  2.    For those of you that do not how to format a printf() statement for
  3.    use with -F and -df, this little segment should help.
  4.  
  5.    --------- A Tutorial on How to Make Custom Printf Formats ---------
  6.  
  7.    To form a custom format, you simply make a string of the flags you
  8.    want to appear:
  9.  
  10.        ie    nl  -F " %n %v"
  11.  
  12.    The above format will display the filename and then the filesize.
  13.  
  14.        ie    Aliases.info 597
  15.              Commodore.README 353
  16.  
  17.    Notice how the information is NOT in a columnar format.  This is because
  18.    the filename (%n) is of variable length.  To make the filename of
  19.    fixed length, you must give %n a numeric qualifier specifying how
  20.    large you want the data to be.  This qualifier goes after the %
  21.    and before the meta-character (in this case n).
  22.  
  23.       ie     nl  -F "%20n %v"
  24.  
  25.    The above format says to make the name 20 characters no matter
  26.    how short the name is.  The output will be like:
  27.  
  28.      ie               Aliases.info 597
  29.                   Commodore.README 353
  30.               ^
  31.               Starts here
  32.  
  33.    Notice how the output is right justified.  To make the data left
  34.    justified, put a minus sign (-) in front of the numeric qualifier.
  35.  
  36.      ie     nl  -F "%-20n %v"
  37.  
  38.    The output will now look like:
  39.  
  40.      ie     Aliases.info         597
  41.             Commodore.README     353
  42.             ^
  43.             Starts here
  44.  
  45.    One disadvantage of the numeric qualifer is that if a file length
  46.    is larger than the fixed length, the output will not be columnized
  47.    anymore.
  48.  
  49.     ie  nl  -F " %-13n %v"
  50.  
  51.  
  52.      Times.doc.info   597     <- This name is 14 (larger than 13).
  53.      History       18107         As a result, the output is slightly
  54.      Aliases        2676         messed up.
  55.  
  56.    To fix the problem, the only thing you can really do is to make the
  57.    qualifier large.  Commodore restricts the file length to something like
  58.    30 chars, so %-30n will ALWAYS work.  I prefer to use %-22n since it
  59.    is small enough for the display, yet large enough for most big names.
  60.  
  61.  
  62.    If you want to restrict a field to be only X characters long, you
  63.    can give a .x qualifier where x is a number.  For example:
  64.  
  65.        nl -F " %.5n"
  66.  
  67.    will output:
  68.  
  69.        Times
  70.        Histo
  71.        Alias
  72.  
  73.    Note how the filenames got truncated to 5 chars.  This truncating
  74.    field is very handy for making pseudo-abbreviations.  For example:
  75.    
  76.       nl -ds "%.3t"    will make day name abbreviations
  77.                        (Saturday truncated to Sat)
  78.  
  79.  
  80.    You may also mix justification qualifiers with the length restriction
  81.    qualifier.  For example:
  82.  
  83.        nl -F " %7.5n"
  84.  
  85.    This says to make the names be ONLY 5 chars long, then right justify
  86.    this to be 7 chars (add 2 spaces in front).
  87.  
  88. ----
  89.  
  90.    Now we are not quite done.  '%v' is also a variable length field.
  91.    Sometimes it will be 1 or 2 digits (<=99 bytes) or it may be
  92.    very long (100000 bytes etc.).  In order for our format to work
  93.    in every case (when files are very big), we should put a large
  94.    qualifier in %v.  I would use %6v or %7v to handle even the biggest
  95.    files.
  96.  
  97.    The output will be like:
  98.  
  99.       555
  100.       666666
  101.  
  102.    If you would like to have the numeric places held by a 0, then insert
  103.    a zero after the %.
  104.  
  105.    ie  nl "%07v"
  106.             ^
  107.             Note that it's NOT  %7v
  108.   
  109.       0000555
  110.       0666666
  111.  
  112. ----
  113.  
  114.    Hope that this helps.
  115.    Phil Dietz
  116.