home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 2: PC / frozenfish_august_1995.bin / bbs / d03xx / d0342.lha / SKsh / View.doc < prev    next >
Text File  |  1990-04-15  |  12KB  |  331 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.4
  29.  
  30.  
  31.                                (Copyright) 1989, 1990
  32.  
  33.                                      Steve Koren
  34.  
  35.                                    March 19, 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
  77.             logical type of a file  and  deal  with  it  appropriately   in
  78.             a  user definable way.  It  is   actually   an   extension   of
  79.             the  "file" command found  on  many  Un*x  systems   and   will
  80.             emulate  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
  109.             provides   much  the  same  functionality   as   the   "default
  110.             tool"  concept  from workbench; you can just   view   a   file,
  111.             and  be  assured  that something  logical  will  happen.    You
  112.             can  think  of  it  as  a "more" command  that  can  cope  with
  113.             more than just text files.
  114.  
  115.             "view"  is  also  extensible;    it    can    handle    several
  116.             different methods for determining  the  type  of  a  file,  new
  117.             types  can  be added at will, and user  definable  actions  can
  118.             be added.
  119.  
  120.             The  disadvantage  of  "view"  is  that   it   requires    some
  121.             initial setup that must be done on a system   specific   basis;
  122.             everyone has their favorite text and picture viewers, etc,  and
  123.             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
  150.             operation as fast as possible.  In  the  best  Un*x  tradition,
  151.             this file is cryptic, nearly  unreadable,  and  unforgiving  of
  152.             format 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
  192.             except 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 file 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
  214.             depends 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
  259.  
  260.  
  261.           SKsh Amiga Shell               Page 4                View Manual
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.             keywords).
  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
  279.             ACTION, and the fourth must be a string  to  be  executed.   If
  280.             the string contains a "%s", this will  be  replaced   with  the
  281.             name of the current file.  The fourth field in an  ACTION  line
  282.             may itself contain a colon, which is useful for path names.  It
  283.             is 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
  292.             DEFAULT 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 magic file.  It is  best
  307.             to copy the magic file to a ram disk in your  startup-sequence;
  308.             the file is small, and  having  it  there  will  greatly  speed
  309.             view.
  310.  
  311.             There are several options for view:
  312.  
  313.                view -v             prints the version of view
  314.  
  315.                view -t file ...    prints the type of each file passed to
  316.                                    view.
  317.  
  318.                view -type file ... same as above
  319.  
  320.                view file ...       uses the action for each file type.
  321.  
  322.  
  323.  
  324.  
  325.  
  326.  
  327.           SKsh Amiga Shell               Page 5                View Manual
  328.  
  329.  
  330.  
  331.