1/*****************************************************************************/
2/* */
3/* feature.c */
4/* */
5/* Subroutines for the emulation features */
6/* */
7/* */
8/* */
9/* (C) 2000-2013, 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/* ca65 */
39#include "global.h"
40#include "feature.h"
41
42
43
44/*****************************************************************************/
45/* Data */
46/*****************************************************************************/
47
48
49
50/* Names of the features */
51static const char* const FeatureKeys[FEAT_COUNT] = {
52 "dollar_is_pc",
53 "labels_without_colons",
54 "loose_string_term",
55 "loose_char_term",
56 "at_in_identifiers",
57 "dollar_in_identifiers",
58 "leading_dot_in_identifiers",
59 "org_per_seg",
60 "pc_assignment",
61 "missing_char_term",
62 "ubiquitous_idents",
63 "c_comments",
64 "force_range",
65 "underline_in_numbers",
66 "addrsize",
67 "bracket_as_indirect",
68 "string_escapes",
69};
70
71
72
73/*****************************************************************************/
74/* Code */
75/*****************************************************************************/
76
77
78
79feature_t FindFeature (const StrBuf* Key)
80/* Find the feature in a table and return the corresponding enum value. If the
81** feature is invalid, return FEAT_UNKNOWN.
82*/
83{
84 feature_t F;
85
86 /* This is not time critical, so do a linear search */
87 for (F = (feature_t) 0; F < FEAT_COUNT; ++F) {
88 if (SB_CompareStr (Key, FeatureKeys[F]) == 0) {
89 /* Found, index is enum value */
90 return F;
91 }
92 }
93
94 /* Not found */
95 return FEAT_UNKNOWN;
96}
97
98
99
100feature_t SetFeature (const StrBuf* Key)
101/* Find the feature and set the corresponding flag if the feature is known.
102** In any case, return the feature found. An invalid Key will return
103** FEAT_UNKNOWN.
104*/
105{
106 /* Map the string to an enum value */
107 feature_t Feature = FindFeature (Key);
108
109 /* Set the flags */
110 switch (Feature) {
111 case FEAT_DOLLAR_IS_PC: DollarIsPC = 1; break;
112 case FEAT_LABELS_WITHOUT_COLONS: NoColonLabels = 1; break;
113 case FEAT_LOOSE_STRING_TERM: LooseStringTerm = 1; break;
114 case FEAT_LOOSE_CHAR_TERM: LooseCharTerm = 1; break;
115 case FEAT_AT_IN_IDENTIFIERS: AtInIdents = 1; break;
116 case FEAT_DOLLAR_IN_IDENTIFIERS: DollarInIdents = 1; break;
117 case FEAT_LEADING_DOT_IN_IDENTIFIERS: LeadingDotInIdents= 1; break;
118 case FEAT_ORG_PER_SEG: OrgPerSeg = 1; break;
119 case FEAT_PC_ASSIGNMENT: PCAssignment = 1; break;
120 case FEAT_MISSING_CHAR_TERM: MissingCharTerm = 1; break;
121 case FEAT_UBIQUITOUS_IDENTS: UbiquitousIdents = 1; break;
122 case FEAT_C_COMMENTS: CComments = 1; break;
123 case FEAT_FORCE_RANGE: ForceRange = 1; break;
124 case FEAT_UNDERLINE_IN_NUMBERS: UnderlineInNumbers= 1; break;
125 case FEAT_ADDRSIZE: AddrSize = 1; break;
126 case FEAT_BRACKET_AS_INDIRECT: BracketAsIndirect = 1; break;
127 case FEAT_STRING_ESCAPES: StringEscapes = 1; break;
128 default: /* Keep gcc silent */ break;
129 }
130
131 /* Return the value found */
132 return Feature;
133}
134