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