1/*****************************************************************************/
2/* */
3/* options.c */
4/* */
5/* Object file options for the ca65 macroassembler */
6/* */
7/* */
8/* */
9/* (C) 1998-2008, 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#include <string.h>
37
38/* common */
39#include "optdefs.h"
40#include "xmalloc.h"
41
42/* ca65 */
43#include "error.h"
44#include "objfile.h"
45#include "options.h"
46#include "spool.h"
47
48
49
50/*****************************************************************************/
51/* Data */
52/*****************************************************************************/
53
54
55
56/* Option list */
57static Option* OptRoot = 0;
58static Option* OptLast = 0;
59static unsigned OptCount = 0;
60
61
62
63/*****************************************************************************/
64/* Code */
65/*****************************************************************************/
66
67
68
69static Option* NewOption (unsigned char Type, unsigned long Val)
70/* Create a new option, insert it into the list and return it */
71{
72 Option* Opt;
73
74 /* Allocate memory */
75 Opt = xmalloc (sizeof (*Opt));
76
77 /* Initialize fields */
78 Opt->Next = 0;
79 Opt->Type = Type;
80 Opt->Val = Val;
81
82 /* Insert it into the list */
83 if (OptRoot == 0) {
84 OptRoot = Opt;
85 } else {
86 OptLast->Next = Opt;
87 }
88 OptLast = Opt;
89
90 /* One more option now */
91 ++OptCount;
92
93 /* Return the new struct */
94 return Opt;
95}
96
97
98
99void OptStr (unsigned char Type, const StrBuf* Text)
100/* Add a string option */
101{
102 NewOption (Type, GetStrBufId (Text));
103}
104
105
106
107void OptComment (const StrBuf* Comment)
108/* Add a comment */
109{
110 NewOption (OPT_COMMENT, GetStrBufId (Comment));
111}
112
113
114
115void OptAuthor (const StrBuf* Author)
116/* Add an author statement */
117{
118 NewOption (OPT_AUTHOR, GetStrBufId (Author));
119}
120
121
122
123void OptTranslator (const StrBuf* Translator)
124/* Add a translator option */
125{
126 NewOption (OPT_TRANSLATOR, GetStrBufId (Translator));
127}
128
129
130
131void OptCompiler (const StrBuf* Compiler)
132/* Add a compiler option */
133{
134 NewOption (OPT_COMPILER, GetStrBufId (Compiler));
135}
136
137
138
139void OptOS (const StrBuf* OS)
140/* Add an operating system option */
141{
142 NewOption (OPT_OS, GetStrBufId (OS));
143}
144
145
146
147void OptDateTime (unsigned long DateTime)
148/* Add a date/time option */
149{
150 NewOption (OPT_DATETIME, DateTime);
151}
152
153
154
155void WriteOptions (void)
156/* Write the options to the object file */
157{
158 Option* O;
159
160 /* Tell the object file module that we're about to start the options */
161 ObjStartOptions ();
162
163 /* Write the option count */
164 ObjWriteVar (OptCount);
165
166 /* Walk through the list and write the options */
167 O = OptRoot;
168 while (O) {
169
170 /* Write the type of the option, then the value */
171 ObjWrite8 (O->Type);
172 ObjWriteVar (O->Val);
173
174 /* Next option */
175 O = O->Next;
176
177 }
178
179 /* Done writing options */
180 ObjEndOptions ();
181}
182
183
184
185
186