home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk381.lzh / SKsh / View.doc < prev    next >
Text File  |  1990-10-20  |  13KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.  
  21.                           "view" - A File Type Encapsulator
  22.  
  23.  
  24.                                         SKsh
  25.  
  26.                            A ksh-like Shell for the Amiga
  27.  
  28.                                      Version 1.6
  29.  
  30.  
  31.                                (Copyright) 1989, 1990
  32.  
  33.                                      Steve Koren
  34.  
  35.                                    October 4, 1990
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.           Introduction
  75.  
  76.             "view" is  a  program which attempts  to  determine  the  logi-
  77.             cal type of a file  and  deal  with   it   appropriately  in  a
  78.             user  definable way.  It  is   actually  an  extension  of  the
  79.             "file"  command found  on  many  Un*x  systems  and  will  emu-
  80.             late  the function of that command if desired.
  81.  
  82.             "view"  assumes that files  come   in   types;   for   example,
  83.             some files are plain ASCII text, some are IFF   picture  files,
  84.             some are ANIM files, some are zoo  files  or  arc  files,  etc.
  85.             Each  of these file types   has  a  given   operation  that  is
  86.             commonly  performed on it.  You might  "more"  a   text   file,
  87.             "xd"  binary data, and "show" a picture file:
  88.  
  89.                [dh0:]: more mydoc.txt
  90.                [dh0:]: show mypic.ham
  91.                [dh0:]: xd mydata
  92.                [dh0:]: zoo -list myarchive.zoo
  93.                [dh0:]: arc -v myarchive.arc
  94.                [dh0:]: showanim -C myanim.anim
  95.  
  96.             Using "view" (which is  best  aliased  to  "v"),  all  of   the
  97.             above can be performed as:
  98.  
  99.                [dh0:]: v mydoc.txt
  100.                [dh0:]: v mypic.ham
  101.                [dh0:]: v mydata
  102.                [dh0:]: v myarchive.zoo
  103.                [dh0:]: v myarchive.arc
  104.                [dh0:]: v myanim.anim
  105.  
  106.             View  saves  you  from  having  to  remember how to  deal  with
  107.             each kind of file (if you have   ever   accidentally "catted" a
  108.             binary file, you will know why  this  is  valuable).   It  pro-
  109.             vides  much  the  same  functionality  as  the  "default  tool"
  110.             concept  from  workbench; you can just  view  a  file,  and  be
  111.             assured  that  something logical will happen.   You  can  think
  112.             of  it  as  a "more"  command that can cope with more than just
  113.             text files.
  114.  
  115.             "view" is  also  extensible;  it  can  handle  several  differ-
  116.             ent  methods  for  determining the type of a file,  new   types
  117.             can   be  added  at  will,  and  user  definable actions can be
  118.             added.
  119.  
  120.             The  disadvantage of "view" is that   it   requires  some  ini-
  121.             tial setup that must  be  done  on  a  system  specific  basis;
  122.             everyone  has  their  favorite text and  picture viewers, etc.,
  123.             and   everyone has them in  different  places.   However,  once
  124.             this      initial   configuration  is  done,  it  won't  change
  125.             frequently.
  126.  
  127.  
  128.  
  129.           SKsh Amiga Shell               Page 2                View Manual
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.             View will perform a few other services for you as  well;
  140.             these  will be explained later.
  141.  
  142.           How View Works
  143.  
  144.             When  view  begins  execution, it loads  a  "magic"  file  into
  145.             memory.  This  magic  file  contains information on the various
  146.             file types and  the  actions that are associated with each file
  147.             type.   It  can  be   located  anywhere, since it is referenced
  148.             through a "vmagic:"  assignment, but it is best copied to a ram
  149.             disk in your  startup sequence.  This will allow view to opera-
  150.             tion as fast as possible.  In  the  best  Un*x  tradition, this
  151.             file  is  cryptic, nearly unreadable, and unforgiving of format
  152.             errors, but it is read by view fairly quickly.
  153.  
  154.             View supports several methods of determining a file's type:
  155.  
  156.             *  The  OFFSET  method  allows view to  determine a file's type
  157.                from  a  fixed  sequence of bytes that is located at a given
  158.                place in the  file.   The  OFFSET type is used to find 'zoo'
  159.                files, for example.  It  is  also  reliable; if the zoo file
  160.                is  renamed to end   with   ".arc",  the  OFFSET method will
  161.                still properly identify the file as a zoo archive.
  162.  
  163.             *  The WORDS  method  allows view to look for certain key words
  164.                in a file.   For  example, view uses this method to find 'c'
  165.                code and English text.
  166.  
  167.             *  The  SUFFIX method  determines file type based upon the file
  168.                name.   This  is  not  always reliable, but it works if your
  169.                files  have  a  naming convention.  For example, if all your
  170.                lharc files end with ".lzh", you can use  the  SUFFIX method
  171.                to find them.
  172.  
  173.             *  The  CHARS  method  allows file time to be  determined based
  174.                upon  the  characters in a file.   For  example,  ASCII text
  175.                files might contain the characters 0x20 to 0x7f.
  176.  
  177.             A  special  DIRECTORY method is used  to  identify directories.
  178.             Since  directories are not files  per  se  under AmigaDos, this
  179.             method  is  somewhat of  a  special case.  (NOTE: the DIRECTORY
  180.             method is not yet implemented in this release of view).
  181.  
  182.  
  183.           The Format of the Magic File
  184.  
  185.             The magic file  contains colon (":") separated records, one per
  186.             line.  Each line is  limited to 255 characters (and this is not
  187.             checked for by view, so  it  would  be  advisable to stay under
  188.             this limit).  Lines may be empty if their  only  character is a
  189.             newline, and a  "#"  in  the  first  character of a line causes
  190.             view  to  ignore the rest of the line.  The first  record of  a
  191.             line is a type name, which may  contain any ASCII character ex-
  192.             cept  a  colon.   The  second is a keyword, and must be exactly
  193.  
  194.  
  195.           SKsh Amiga Shell               Page 3                View Manual
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.             one of:
  206.  
  207.  
  208.  
  209.                OFFSET, WORDS, SUFFIX, CHARS, DIRECTORY, ACTION, DEFAULT
  210.  
  211.             View will  complain if the second field does not contain one of
  212.             the above  values (which must be in upper case).  The third and
  213.             fourth fields are data  fields,  and  their  interpretation de-
  214.             pends on the contents of the second field.
  215.  
  216.             As an example, here are a few lines from my magic file:
  217.  
  218.                zoo archive:OFFSET:20:dca7c4fd
  219.                IFF ilbm file:OFFSET:0:464f524d........494c424d424d4844
  220.                c source:WORDS:5:include ,define ,/*,*/,int ,char , printf
  221.                object file:SUFFIX::.o
  222.                ascii text:CHARS::20-7f
  223.  
  224.                zoo archive:ACTION::sys:usr/bin/zoo -list %s
  225.                IFF ilbm file:ACTION::sys:bin/show %s
  226.                object file:ACTION::sys:usr/local/bin/xd %s
  227.                all:DEFAULT::c:more %s
  228.  
  229.             My  actual magic file is about 3 times  that  large,  but  this
  230.             subset will  suffice for an example.  The lines may come in any
  231.             order.
  232.  
  233.             The  first  line  identifies a zoo archive.  The first field is
  234.             the type name (which is  arbitrary).  The second indicates that
  235.             view  should  use  the  OFFSET  method.  The third field  is  a
  236.             decimal  integer less than  1023  which  tells  view  where  it
  237.             should  start  checking the file contents.  The fourth field is
  238.             a  sequence of characters, which, when taken in pairs, identify
  239.             hexadecimal byte values.  They  may  optionally be separated by
  240.             commas for  readability.   In  this  example, view will move to
  241.             the spot 20 bytes from  the  beginning of the file, and examine
  242.             the next four  bytes  for  the  indicated values.  If the bytes
  243.             match exactly, view assumes the file is a zoo file.
  244.  
  245.             The second line is almost like the first, but it illustrates
  246.             that bytes may be skipped  ("don't care" values).  Two dots
  247.             will skip one byte in the file.
  248.  
  249.             The third line uses  the  WORDS  method.   In  my  actual file,
  250.             there are  more  identifying words, but this will suffice as an
  251.             example.  The third  field  is  a  decimal integer representing
  252.             the  number  of  keywords that must be found in the first  1024
  253.             bytes of the file for  view  to  assume that the file is of the
  254.             given type.  For  example, it may attempt to tell c source code
  255.             from  English text from a SKsh script file.  In this case, 5 of
  256.             the  keywords must be found.  The fourth field contains a comma
  257.             separated list of keywords.   Spaces  are  significant and must
  258.             be  matched  exactly  (notice the spaces after some of the key-
  259.  
  260.  
  261.           SKsh Amiga Shell               Page 4                View Manual
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.             words).
  272.  
  273.             The fourth  line  identifies an object file by its suffix.  The
  274.             suffix should  include any "." and must be in the fourth field,
  275.             not the third.
  276.  
  277.             Three  ACTION lines follow the type definitions.  Each one must
  278.             begin with the name of  a  type,  the  second field must be AC-
  279.             TION, and the fourth must be a string to be executed.   If  the
  280.             string  contains a "%s", this will  be  replaced  with the name
  281.             of  the  current file.  The fourth field in an  ACTION line may
  282.             itself  contain a  colon, which is useful for path names. It is
  283.             best  to  supply the full path name  to  a  utility program for
  284.             fast lookup, and it is  necessary if the program is not in your
  285.             AmigaDos path.
  286.  
  287.             The last line is  a  DEFAULT line.  If a type is found (such as
  288.             for c source code), and no  corresponding ACTION line is found,
  289.             the  action from the last field  of  the  DEFAULT line is used.
  290.             This is  usually something like "more", "less" or your favorite
  291.             text reader.  An  empty  ACTION statement will override the DE-
  292.             FAULT line.
  293.  
  294.             You can put your own data types and actions in this file.
  295.  
  296.  
  297.           Using view
  298.  
  299.             First of all, it  is  best  to  alias  view  to  something very
  300.             short.  Also, the full path name can be put in  the  alias  for
  301.             speed.  Using SKsh, this can be accomplished as follows:
  302.  
  303.                alias v=sys:usr/local/bin/view
  304.  
  305.             (substitute the path to  the  view  binary on your own system).
  306.             Also,  you  must  assign "vmagic:" to the  directory containing
  307.             the magic file.  It is best to copy the magic  file  to  a  ram
  308.             disk in your startup-sequence; the file is  small,  and  having
  309.             it there will greatly speed view.
  310.  
  311.             There are several options for view:
  312.  
  313.                view -magic fspec   use fspec as the magic file
  314.  
  315.                view -v             prints the version of view
  316.  
  317.                view -t file ...    prints the type of each file passed to
  318.                                    view.
  319.  
  320.                view -type file ... same as above
  321.  
  322.                view file ...       uses the action for each file type.
  323.  
  324.  
  325.  
  326.  
  327.           SKsh Amiga Shell               Page 5                View Manual
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.           Using Multiple View Magic Files
  338.  
  339.             "view" can use  multiple magic files as easily as one.  For ex-
  340.             ample,  perhaps you wish to have one magic file which lists the
  341.             contents of a  file,  and  another which edits it.  View can be
  342.             copied  to  another file name (such as "edit"), and will  auto-
  343.             matically use a new magic file  formed  by  using the base name
  344.             of the command.   For  example, if named "view", the magic file
  345.             will be "vmagic:view.magic".  If named "edit", the  magic  file
  346.             will be "vmagic:edit.magic".  (In AmigaDos 2.0,  it  should  be
  347.             possible to use file links to link view to  another name).  Any
  348.             number  of  these  commands may be created.  Each one will take
  349.             only about 6700 bytes of disk space.
  350.  
  351.             In  addition, view can be told to  use  a  specific magic file.
  352.             For example,
  353.  
  354.               view -magic ram:myfile file1 file2
  355.  
  356.             would  view  file1  and  file2  using the magic file  found  in
  357.             ram:myfile.  This can  be  useful if you want to store only one
  358.             copy of view on your disk, but wish to use  aliases  to  accom-
  359.             plish the same effect.
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.  
  367.  
  368.  
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.           SKsh Amiga Shell               Page 6                View Manual
  394.  
  395.  
  396.  
  397.