home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / cvs-1.8.7-src.tgz / tar.out / fsf / cvs / src / fileattr.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  5KB  |  127 lines

  1. /* Declarations for file attribute munging features.
  2.  
  3.    This program is free software; you can redistribute it and/or modify
  4.    it under the terms of the GNU General Public License as published by
  5.    the Free Software Foundation; either version 2, or (at your option)
  6.    any later version.
  7.  
  8.    This program is distributed in the hope that it will be useful,
  9.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.    GNU General Public License for more details.
  12.  
  13.    You should have received a copy of the GNU General Public License
  14.    along with this program; if not, write to the Free Software
  15.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  16.  
  17. #ifndef FILEATTR_H
  18.  
  19. /* File containing per-file attributes.  Format is a series of entries:
  20.  
  21.    ENT-TYPE FILENAME <tab> ATTRNAME = ATTRVAL
  22.      {; ATTRNAME = ATTRVAL} <linefeed>
  23.  
  24.    ENT-TYPE is 'F' for a file, in which case the entry specifies the
  25.    attributes for that file.
  26.  
  27.    ENT-TYPE is 'D', and FILENAME empty, to specify default attributes
  28.    to be used for newly added files.
  29.  
  30.    There is currently no way of quoting tabs or linefeeds in the
  31.    filename, '=' in ATTRNAME, ';' in ATTRVAL, etc.  I'm not sure
  32.    whether I think we need one.  Note: the current implementation also
  33.    doesn't handle '\0' in any of the fields.
  34.  
  35.    By convention, ATTRNAME starting with '_' is for an attribute given
  36.    special meaning by CVS; other ATTRNAMEs are for user-defined attributes
  37.    (or will be, once we add commands to manipulate user-defined attributes).
  38.  
  39.    Builtin attributes:
  40.  
  41.    _watched: Present means the file is watched and should be checked out
  42.    read-only.
  43.  
  44.    _watchers: Users with watches for this file.  Value is
  45.    WATCHER > TYPE { , WATCHER > TYPE }
  46.    where WATCHER is a username, and TYPE is edit,unedit,commit separated by
  47.    + (or nothing if none; there is no "none" or "all" keyword).
  48.  
  49.    _editors: Users editing this file.  Value is
  50.    EDITOR > VAL { , EDITOR > VAL }
  51.    where EDITOR is a username, and VAL is TIME+HOSTNAME+PATHNAME, where
  52.    TIME is when the "cvs edit" command happened,
  53.    and HOSTNAME and PATHNAME are for the working directory.  */
  54.  
  55. #define CVSREP_FILEATTR "CVS/fileattr"
  56.  
  57. /* Prepare for a new directory with repository REPOS.  If REPOS is NULL,
  58.    then prepare for a "non-directory"; the caller can call fileattr_write
  59.    and fileattr_free, but must not call fileattr_get or fileattr_set.  */
  60. extern void fileattr_startdir PROTO ((char *repos));
  61.  
  62. /* Get the attribute ATTRNAME for file FILENAME.  The return value
  63.    points into memory managed by the fileattr_* routines, should not
  64.    be altered by the caller, and is only good until the next call to
  65.    fileattr_clear or fileattr_set.  It points to the value, terminated
  66.    by '\0' or ';'.  Return NULL if said file lacks said attribute.
  67.    If FILENAME is NULL, return default attributes (attributes for
  68.    files created in the future).  */
  69. extern char *fileattr_get PROTO ((const char *filename, const char *attrname));
  70.  
  71. /* Like fileattr_get, but return a pointer to a newly malloc'd string
  72.    terminated by '\0' (or NULL if said file lacks said attribute).  */
  73. extern char *fileattr_get0 PROTO ((const char *filename,
  74.                    const char *attrname));
  75.  
  76. /* This is just a string manipulation function; it does not manipulate
  77.    file attributes as such.  
  78.  
  79.    LIST is in the format
  80.  
  81.    ATTRNAME NAMEVALSEP ATTRVAL {ENTSEP ATTRNAME NAMEVALSEP ATTRVAL}
  82.  
  83.    And we want to put in an attribute with name NAME and value VAL,
  84.    replacing the already-present attribute with name NAME if there is
  85.    one.  Or if VAL is NULL remove attribute NAME.  Return a new
  86.    malloc'd list; don't muck with the one passed in.  If we are removing
  87.    the last attribute return NULL.  LIST can be NULL to mean that we
  88.    started out without any attributes.
  89.  
  90.    Examples:
  91.  
  92.    fileattr_modify ("abc=def", "xxx", "val", '=', ';')) => "abc=def;xxx=val"
  93.    fileattr_modify ("abc=def", "abc", "val", '=', ';')) => "abc=val"
  94.    fileattr_modify ("abc=v1;def=v2", "abc", "val", '=', ';'))
  95.      => "abc=val;def=v2"
  96.    fileattr_modify ("abc=v1;def=v2", "def", "val", '=', ';'))
  97.      => "abc=v1;def=val"
  98.    fileattr_modify ("abc=v1;def=v2", "xxx", "val"))
  99.      => "abc=v1;def=v2;xxx=val"
  100.    fileattr_modify ("abc=v1;def=v2;ghi=v3", "def", "val", '=', ';'))
  101.      => "abc=v1;def=val;ghi=v3"
  102. */
  103.  
  104. extern char *fileattr_modify PROTO ((char *list, const char *attrname,
  105.                      const char *attrval, int namevalsep,
  106.                      int entsep));
  107.  
  108. /* Set attribute ATTRNAME for file FILENAME to ATTRVAL.  If ATTRVAL is NULL,
  109.    the attribute is removed.  Changes are not written to disk until the
  110.    next call to fileattr_write.  If FILENAME is NULL, set attributes for
  111.    files created in the future.  If ATTRVAL is NULL, remove that attribute.  */
  112. extern void fileattr_set PROTO ((const char *filename, const char *attrname,
  113.                  const char *attrval));
  114.  
  115. /* Set the attributes for file FILENAME in whatever manner is appropriate
  116.    for a newly created file.  */
  117. extern void fileattr_newfile PROTO ((const char *filename));
  118.  
  119. /* Write out all modified attributes.  */
  120. extern void fileattr_write PROTO ((void));
  121.  
  122. /* Free all memory allocated by fileattr_*.  */
  123. extern void fileattr_free PROTO ((void));
  124.  
  125. #define FILEATTR_H 1
  126. #endif /* fileattr.h */
  127.