home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format 52 / af052sub.adf / newlist.lha / NewList / Docs / FormatTutorial.doc next >
Text File  |  1993-07-16  |  4KB  |  146 lines

  1. @node "tutorial"
  2. $VER: Newlist8 (19-Jun-93) Format help
  3.  
  4.  
  5.    For those of you that do not know how to format a printf() statement for
  6.    use with -F, -C, -M, and -D, this little segment should help.
  7.  
  8.    --------- A Tutorial on How to Make Custom Printf Formats ---------
  9.  
  10.    To form a custom format, you simply make a string of the flags you
  11.    want to appear:
  12.  
  13.              ie    nl  -F " %n %v"
  14.  
  15.    The above format will display the filename and then the filesize.
  16.  
  17.              ie    Aliases.info 597
  18.                    Commodore.README 353
  19.  
  20.    Notice how the information is NOT in a columnar format.  This is because
  21.    the filename (%n) is of variable length.  To make the filename of
  22.    fixed length, you must give the flag %n a numeric qualifier specifying
  23.    how large you want the data to be.  This qualifier goes after the %
  24.    and before the meta-character (in this case n).
  25.  
  26.             ie     nl  -F "%20n %v"
  27.                             ^
  28.                             length is 20
  29.  
  30.    The above format says to make the name 20 characters no matter
  31.    how short the name is.  The output will be like:
  32.  
  33.             ie              Aliases.info 597
  34.                         Commodore.README 353
  35.                     ^
  36.                     Starts here
  37.  
  38.    Notice how the output is right justified.  To make the data left
  39.    justified, put a minus sign (-) in front of the numeric qualifier.
  40.  
  41.            ie     nl  -F "%-20n %v"
  42.  
  43.    The output will now look like:
  44.  
  45.            ie     Aliases.info         597
  46.                   Commodore.README     353
  47.                   ^
  48.                   Starts here
  49.  
  50.    One disadvantage of the numeric qualifer is that if a file length
  51.    is larger than the fixed length, the output will not be columnized
  52.    anymore.
  53.  
  54.           ie  nl  -F " %-13n %6v"
  55.  
  56.  
  57.            Times.doc.info   597     <- This name is 14 (larger than 13).
  58.            History       18107         As a result, the output is slightly
  59.            Aliases        2676         messed up.
  60.  
  61.    To fix the problem, you should make the qualifier large.  Commodore
  62.    restricts the file length to something like 30 chars, so %-30n will
  63.    ALWAYS work.  I prefer to use %-22n since itis small enough for the
  64.    display, yet large enough for most big names.
  65.  
  66.    Or truncation:
  67.  
  68.    If you want to restrict a field to be only X characters long, you
  69.    can give a .x qualifier where x is a number.  For example:
  70.  
  71.              nl -F " %.5n"
  72.  
  73.    will output:
  74.  
  75.              Times
  76.              Histo
  77.              Alias
  78.  
  79.    Note how the filenames got truncated to 5 chars.  This truncating
  80.    field is very handy for making pseudo-abbreviations.  For example:
  81.    
  82.             nl -D "%.3D"    will make day name abbreviations
  83.                              (Saturday truncated to Sat)
  84.  
  85.  
  86.    You may also mix justification qualifiers with the length restriction
  87.    qualifier.  For example:
  88.  
  89.              nl -F " %7.5n"
  90.  
  91.    This says to make the names to be ONLY 5 chars long, then right justify
  92.    this to be 7 chars (add 2 spaces in front).
  93.  
  94. ----
  95.  
  96.    Now we are not quite done.  '%v' is also a variable length field.
  97.    Sometimes it will be 1 or 2 digits (<=99 bytes) or it may be
  98.    very long (100000 bytes etc.).  In order for our format to work
  99.    in every case (when files are very big), we should put a large
  100.    qualifier in %v.  I would use %6v or %7v to handle even the biggest
  101.    files.
  102.  
  103.    The output will be like:
  104.  
  105.       555
  106.       666666
  107.  
  108.    If you would like to have the numeric places held by a 0, then insert
  109.    a zero after the %.
  110.  
  111.    ie  nl "%07v"
  112.             ^
  113.             Note that it's NOT  %7v
  114.   
  115.       0000555
  116.       0666666
  117.  
  118. ----
  119.  
  120.    One final note:  a patron of mine was having problems with his string
  121.    outputs.  He was doing the following:
  122.  
  123.             nl -D "%09D"
  124.                     ^
  125.                     the culprit!
  126.  
  127.         w/  000Friday
  128.             0Saturday      as outputs.
  129.  
  130.    The reason for the 0's in front of the day name is because of the 0 in 
  131.    %09.  That 0 tells it to pad the spaces with the 0 character.  Thus you
  132.    only want to do this with digit type stuff. To correct the problem above:
  133.  
  134.             nl -df "%9D"     <- Notice no leading 0.
  135.  
  136.          w/    Friday
  137.              Saturday      as outputs.
  138.  
  139.    Hope that this helps.
  140.    Review the formats in the included alias file 
  141.      or consult a C book for info about printf().
  142.  
  143.    Phil Dietz
  144.  
  145. @EndNode
  146.