]> git.sur5r.net Git - cc65/blob - src/ca65/feature.c
71f5f055b6f841512e303c52e107d4c1f8a21539
[cc65] / src / ca65 / feature.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 feature.c                                 */
4 /*                                                                           */
5 /*                  Subroutines for the emulation features                   */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000     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 <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 */
51 static const char* FeatureKeys[FEAT_COUNT] = {
52     "dollar_is_pc",
53     "labels_without_colons",
54     "loose_string_term",
55     "at_in_identifiers",
56     "dollar_in_identifiers",
57     "pc_assignment",
58 };
59
60
61
62 /*****************************************************************************/
63 /*                                   Code                                    */
64 /*****************************************************************************/
65
66
67
68 feature_t FindFeature (const char* Key)
69 /* Find the feature in a table and return the corresponding enum value. If the
70  * feature is invalid, return FEAT_UNKNOWN.
71  */
72 {
73     feature_t F;
74
75     /* This is not time critical, so do a linear search */
76     for (F = (feature_t) 0; F < FEAT_COUNT; ++F) {
77         if (strcmp (Key, FeatureKeys[F]) == 0) {
78             /* Found, index is enum value */
79             return F;
80         }
81     }
82
83     /* Not found */
84     return FEAT_UNKNOWN;
85 }
86
87
88
89 feature_t SetFeature (const char* Key)
90 /* Find the feature and set the corresponding flag if the feature is known.
91  * In any case, return the feature found. An invalid Key will return
92  * FEAT_UNKNOWN.
93  */
94 {
95     /* Map the string to an enum value */
96     feature_t Feature = FindFeature (Key);
97
98     /* Set the flags */
99     switch (Feature) {
100         case FEAT_DOLLAR_IS_PC:          DollarIsPC     = 1;    break;
101         case FEAT_LABELS_WITHOUT_COLONS: NoColonLabels  = 1;    break;
102         case FEAT_LOOSE_STRING_TERM:     LooseStringTerm= 1;    break;
103         case FEAT_AT_IN_IDENTIFIERS:     AtInIdents     = 1;    break;
104         case FEAT_DOLLAR_IN_IDENTIFIERS: DollarInIdents = 1;    break;
105         case FEAT_PC_ASSIGNMENT:         PCAssignment   = 1;    break;
106         default:                         /* Keep gcc silent */  break;
107     }
108
109     /* Return the value found */
110     return Feature;
111 }
112
113
114