]> git.sur5r.net Git - cc65/blob - src/sp65/attr.h
d7df963d77ff0b9d2615f110445e663053de41b3
[cc65] / src / sp65 / attr.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  attr.h                                   */
4 /*                                                                           */
5 /*                          Command line attributes                          */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2012,      Ullrich von Bassewitz                                      */
10 /*                Roemerstrasse 52                                           */
11 /*                D-70794 Filderstadt                                        */
12 /* EMail:         uz@cc65.org                                                */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef ATTRCOLL_H
37 #define ATTRCOLL_H
38
39
40
41 /* common */
42 #include "coll.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Data                                    */
48 /*****************************************************************************/
49
50
51
52 /* Attribute flags */
53 enum AttrFlags {
54     afNone,
55     afInt,                              /* Integer number */
56 };
57 typedef enum AttrFlags AttrFlags;
58
59 /* */
60 typedef struct Attr Attr;
61 struct Attr {
62     AttrFlags   Flags;                  /* Attribute flags */
63     char*       Name;                   /* Attribute name */
64     char        Value[1];               /* Attribute value */
65 };
66
67
68
69 /*****************************************************************************/
70 /*                                   Code                                    */
71 /*****************************************************************************/
72
73
74
75 Attr* NewAttr (const char* Name, const char* Value);
76 /* Create a new attribute */
77
78 void FreeAttr (Attr* A);
79 /* Free an attribute structure */
80
81 void DumpAttrColl (const Collection* C);
82 /* Dump a collection of attribute/value pairs for debugging */
83
84 int FindAttr (const Collection* C, const char* Name, unsigned* Index);
85 /* Search for an attribute with the given name in the collection. If it is
86  * found, the function returns true and Index contains the index of the
87  * entry. If Name isn't found, the function returns false and Index
88  * will contain the insert position.
89  */
90
91 const Attr* GetAttr (const Collection* C, const char* Name);
92 /* Search for an attribute with the given name and return it. The function
93  * returns NULL if the attribute wasn't found.
94  */
95
96 const Attr* NeedAttr (const Collection* C, const char* Name, const char* Op);
97 /* Search for an attribute with the given name and return it. If the attribute
98  * is not found, the function terminates with an error using Op as additional
99  * context in the error message.
100  */
101
102 const char* GetAttrVal (const Collection* C, const char* Name);
103 /* Search for an attribute with the given name and return its value. The
104  * function returns NULL if the attribute wasn't found.
105  */
106
107 const char* NeedAttrVal (const Collection* C, const char* Name, const char* Op);
108 /* Search for an attribute with the given name and return its value. If the
109  * attribute wasn't not found, the function terminates with an error using
110  * Op as additional context in the error message.
111  */
112
113 void AddAttr (Collection* C, const char* Name, const char* Value);
114 /* Add an attribute to an alphabetically sorted attribute collection */
115
116 void SplitAddAttr (Collection* C, const char* Combined, const char* Name);
117 /* Split a combined name/value pair and add it as an attribute to C. Some
118  * attributes may not need a name. If the name is missing, use Name. If
119  * Name is NULL, terminate with an error.
120  */
121
122 Collection* ParseAttrList (const char* List, const char** NameList, unsigned NameCount);
123 /* Parse a list containing name/value pairs into a sorted collection. Some
124  * attributes may not need a name, so NameList contains these names. If there
125  * were no errors, the function returns a alphabetically sorted collection
126  * containing Attr entries.
127  */
128
129 void FreeAttrList (Collection* C);
130 /* Free a list of attributes */
131
132
133
134 /* End of attr.h */
135
136 #endif
137
138
139