117721Speter/* Declarations for file attribute munging features.
217721Speter
317721Speter   This program is free software; you can redistribute it and/or modify
417721Speter   it under the terms of the GNU General Public License as published by
517721Speter   the Free Software Foundation; either version 2, or (at your option)
617721Speter   any later version.
717721Speter
817721Speter   This program is distributed in the hope that it will be useful,
917721Speter   but WITHOUT ANY WARRANTY; without even the implied warranty of
1017721Speter   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1125839Speter   GNU General Public License for more details.  */
1217721Speter
1317721Speter#ifndef FILEATTR_H
1417721Speter
1554427Speter/* File containing per-file attributes.  The format of this file is in
1654427Speter   cvs.texinfo but here is a quick summary.  The file contains a
1754427Speter   series of entries:
1817721Speter
1917721Speter   ENT-TYPE FILENAME <tab> ATTRNAME = ATTRVAL
2017721Speter     {; ATTRNAME = ATTRVAL} <linefeed>
2117721Speter
2254427Speter   ENT-TYPE is 'F' for a file.
2317721Speter
2454427Speter   ENT-TYPE is 'D', and FILENAME empty, for default attributes.
2517721Speter
2654427Speter   Other ENT-TYPE are reserved for future expansion.
2725839Speter
2825839Speter   Note that the order of the line is not significant; CVS is free to
2925839Speter   rearrange them at its convenience.
3025839Speter
3154427Speter   FIXME: this implementation doesn't handle '\0' in any of the
3254427Speter   fields.  We are encouraged to fix this (by cvs.texinfo).
3317721Speter
3417721Speter   By convention, ATTRNAME starting with '_' is for an attribute given
3517721Speter   special meaning by CVS; other ATTRNAMEs are for user-defined attributes
3617721Speter   (or will be, once we add commands to manipulate user-defined attributes).
3717721Speter
3817721Speter   Builtin attributes:
3917721Speter
4017721Speter   _watched: Present means the file is watched and should be checked out
4117721Speter   read-only.
4217721Speter
4317721Speter   _watchers: Users with watches for this file.  Value is
4417721Speter   WATCHER > TYPE { , WATCHER > TYPE }
4517721Speter   where WATCHER is a username, and TYPE is edit,unedit,commit separated by
4617721Speter   + (or nothing if none; there is no "none" or "all" keyword).
4717721Speter
4817721Speter   _editors: Users editing this file.  Value is
4917721Speter   EDITOR > VAL { , EDITOR > VAL }
5017721Speter   where EDITOR is a username, and VAL is TIME+HOSTNAME+PATHNAME, where
5117721Speter   TIME is when the "cvs edit" command happened,
5217721Speter   and HOSTNAME and PATHNAME are for the working directory.  */
5317721Speter
5417721Speter#define CVSREP_FILEATTR "CVS/fileattr"
5517721Speter
5617721Speter/* Prepare for a new directory with repository REPOS.  If REPOS is NULL,
5717721Speter   then prepare for a "non-directory"; the caller can call fileattr_write
5817721Speter   and fileattr_free, but must not call fileattr_get or fileattr_set.  */
59128266Speterextern void fileattr_startdir PROTO ((const char *repos));
6017721Speter
6117721Speter/* Get the attribute ATTRNAME for file FILENAME.  The return value
6217721Speter   points into memory managed by the fileattr_* routines, should not
6317721Speter   be altered by the caller, and is only good until the next call to
6417721Speter   fileattr_clear or fileattr_set.  It points to the value, terminated
6517721Speter   by '\0' or ';'.  Return NULL if said file lacks said attribute.
6617721Speter   If FILENAME is NULL, return default attributes (attributes for
6717721Speter   files created in the future).  */
6825839Speterextern char *fileattr_get PROTO ((const char *filename, const char *attrname));
6917721Speter
7017721Speter/* Like fileattr_get, but return a pointer to a newly malloc'd string
7117721Speter   terminated by '\0' (or NULL if said file lacks said attribute).  */
7225839Speterextern char *fileattr_get0 PROTO ((const char *filename,
7325839Speter				   const char *attrname));
7417721Speter
7517721Speter/* This is just a string manipulation function; it does not manipulate
7617721Speter   file attributes as such.
7717721Speter
7817721Speter   LIST is in the format
7917721Speter
8017721Speter   ATTRNAME NAMEVALSEP ATTRVAL {ENTSEP ATTRNAME NAMEVALSEP ATTRVAL}
8117721Speter
8217721Speter   And we want to put in an attribute with name NAME and value VAL,
8317721Speter   replacing the already-present attribute with name NAME if there is
8417721Speter   one.  Or if VAL is NULL remove attribute NAME.  Return a new
8517721Speter   malloc'd list; don't muck with the one passed in.  If we are removing
8617721Speter   the last attribute return NULL.  LIST can be NULL to mean that we
8717721Speter   started out without any attributes.
8817721Speter
8917721Speter   Examples:
9017721Speter
9117721Speter   fileattr_modify ("abc=def", "xxx", "val", '=', ';')) => "abc=def;xxx=val"
9217721Speter   fileattr_modify ("abc=def", "abc", "val", '=', ';')) => "abc=val"
9317721Speter   fileattr_modify ("abc=v1;def=v2", "abc", "val", '=', ';'))
9417721Speter     => "abc=val;def=v2"
9517721Speter   fileattr_modify ("abc=v1;def=v2", "def", "val", '=', ';'))
9617721Speter     => "abc=v1;def=val"
9725839Speter   fileattr_modify ("abc=v1;def=v2", "xxx", "val", '=', ';'))
9817721Speter     => "abc=v1;def=v2;xxx=val"
9917721Speter   fileattr_modify ("abc=v1;def=v2;ghi=v3", "def", "val", '=', ';'))
10017721Speter     => "abc=v1;def=val;ghi=v3"
10117721Speter*/
10217721Speter
10325839Speterextern char *fileattr_modify PROTO ((char *list, const char *attrname,
10425839Speter				     const char *attrval, int namevalsep,
10517721Speter				     int entsep));
10617721Speter
10717721Speter/* Set attribute ATTRNAME for file FILENAME to ATTRVAL.  If ATTRVAL is NULL,
10817721Speter   the attribute is removed.  Changes are not written to disk until the
10917721Speter   next call to fileattr_write.  If FILENAME is NULL, set attributes for
11017721Speter   files created in the future.  If ATTRVAL is NULL, remove that attribute.  */
11125839Speterextern void fileattr_set PROTO ((const char *filename, const char *attrname,
11225839Speter				 const char *attrval));
11317721Speter
11432785Speter/* Get all the attributes for file FILENAME.  They are returned as malloc'd
11532785Speter   data in an unspecified format which is guaranteed only to be good for
11632785Speter   passing to fileattr_setall, or NULL if no attributes.  If FILENAME is
11732785Speter   NULL, get default attributes.  */
11832785Speterextern char *fileattr_getall PROTO ((const char *filename));
11932785Speter
12032785Speter/* Set the attributes for file FILENAME to ATTRS, overwriting all previous
12132785Speter   attributes for that file.  ATTRS was obtained from a previous call to
12232785Speter   fileattr_getall (malloc'd data or NULL).  */
12332785Speterextern void fileattr_setall PROTO ((const char *filename, const char *attrs));
12432785Speter
12517721Speter/* Set the attributes for file FILENAME in whatever manner is appropriate
12617721Speter   for a newly created file.  */
12725839Speterextern void fileattr_newfile PROTO ((const char *filename));
12817721Speter
12917721Speter/* Write out all modified attributes.  */
13017721Speterextern void fileattr_write PROTO ((void));
13117721Speter
13217721Speter/* Free all memory allocated by fileattr_*.  */
13317721Speterextern void fileattr_free PROTO ((void));
13417721Speter
13517721Speter#define FILEATTR_H 1
13617721Speter#endif /* fileattr.h */
137