]> git.sur5r.net Git - cc65/blob - src/ca65/options.c
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / src / ca65 / options.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 options.c                                 */
4 /*                                                                           */
5 /*              Object file options for the ca65 macroassembler              */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998     Ullrich von Bassewitz                                        */
10 /*              Wacholderweg 14                                              */
11 /*              D-70597 Stuttgart                                            */
12 /* EMail:       uz@musoftware.de                                             */
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 #include "../common/optdefs.h"
37
38 #include "mem.h"
39 #include "error.h"
40 #include "objfile.h"
41 #include "options.h"
42
43
44
45 /*****************************************************************************/
46 /*                                   Data                                    */
47 /*****************************************************************************/
48
49
50
51 /* Option list */
52 static Option*          OptRoot = 0;
53 static Option*          OptLast = 0;
54 static unsigned         OptCount = 0;
55
56
57
58 /*****************************************************************************/
59 /*                                   Code                                    */
60 /*****************************************************************************/
61
62
63
64 static Option* NewOption (unsigned char Type)
65 /* Create a new option, insert it into the list and return it */
66 {
67     Option* Opt;
68
69     /* Allocate memory */
70     Opt = Xmalloc (sizeof (*Opt));
71
72     /* Initialize fields */
73     Opt->Next  = 0;
74     Opt->Type  = Type;
75     Opt->V.Str = 0;
76
77     /* Insert it into the list */
78     if (OptRoot == 0) {
79         OptRoot = Opt;
80     } else {
81         OptLast->Next = Opt;
82     }
83     OptLast = Opt;
84
85     /* One more option now */
86     ++OptCount;
87
88     /* Return the new struct */
89     return Opt;
90 }
91
92
93
94 void OptStr (unsigned char Type, const char* Text)
95 /* Add a string option */
96 {
97     Option* O;
98
99     /* String must have less than 255 bytes */
100     if (strlen (Text) > 255) {
101         Fatal (FAT_STRING_TOO_LONG);
102     }
103     O        = NewOption (Type);
104     O->V.Str = StrDup (Text);
105 }
106
107
108
109 void OptComment (const char* Comment)
110 /* Add a comment */
111 {
112     OptStr (OPT_COMMENT, Comment);
113 }
114
115
116
117 void OptAuthor (const char* Author)
118 /* Add an author statement */
119 {
120     OptStr (OPT_AUTHOR, Author);
121 }
122
123
124
125 void OptTranslator (const char* Translator)
126 /* Add a translator option */
127 {
128     OptStr (OPT_TRANSLATOR, Translator);
129 }
130
131
132
133 void OptCompiler (const char* Compiler)
134 /* Add a compiler option */
135 {
136     OptStr (OPT_COMPILER, Compiler);
137 }
138
139
140
141 void OptOS (const char* OS)
142 /* Add an operating system option */
143 {
144     OptStr (OPT_OS, OS);
145 }
146
147
148
149 void OptDateTime (unsigned long DateTime)
150 /* Add a date/time option */
151 {
152     Option* O = NewOption (OPT_DATETIME);
153     O->V.Val = DateTime;
154 }
155
156
157
158 void WriteOptions (void)
159 /* Write the options to the object file */
160 {
161     Option* O;
162
163     /* Tell the object file module that we're about to start the options */
164     ObjStartOptions ();
165
166     /* Write the option count */
167     ObjWrite16 (OptCount);
168
169     /* Walk through the list and write the options */
170     O = OptRoot;
171     while (O) {
172
173         /* Write the type of the option */
174         ObjWrite8 (O->Type);
175
176         /* Write the argument */
177         switch (O->Type & OPT_ARGMASK) {
178
179             case OPT_ARGSTR:
180                 ObjWriteStr (O->V.Str);
181                 break;
182
183             case OPT_ARGNUM:
184                 ObjWrite32 (O->V.Val);
185                 break;
186
187             default:
188                 Internal ("Invalid option type: $%02X", O->Type & 0xFF);
189
190         }
191
192         /* Next option */
193         O = O->Next;
194
195     }
196
197     /* Done writing options */
198     ObjEndOptions ();
199 }
200
201
202