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