]> git.sur5r.net Git - cc65/blob - src/ca65/toknode.c
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / src / ca65 / toknode.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                 toknode.c                                 */
4 /*                                                                           */
5 /*                Token list node 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 <string.h>
37
38 #include "mem.h"
39 #include "scanner.h"
40 #include "toknode.h"
41
42
43
44 /*****************************************************************************/
45 /*                                   Code                                    */
46 /*****************************************************************************/
47
48
49
50 TokNode* NewTokNode (void)
51 /* Create and return a token node with the current token value */
52 {
53     TokNode* T;
54
55     /* Allocate memory */
56     unsigned Len = TokHasSVal (Tok)? strlen (SVal) : 0;
57     T = Xmalloc (sizeof (TokNode) + Len);
58
59     /* Initialize the token contents */
60     T->Next     = 0;
61     T->Tok      = Tok;
62     T->WS       = WS;
63     T->IVal     = IVal;
64     memcpy (T->SVal, SVal, Len);
65     T->SVal [Len] = '\0';
66
67     /* Return the node */
68     return T;
69 }
70
71
72
73 void FreeTokNode (TokNode* T)
74 /* Free the given token node */
75 {
76     Xfree (T);
77 }
78
79
80
81 void TokSet (TokNode* T)
82 /* Set the scanner token from the given token node */
83 {
84     /* Set the values */
85     Tok  = T->Tok;
86     WS   = T->WS;
87     IVal = T->IVal;
88     strcpy (SVal, T->SVal);
89 }
90
91
92
93 enum TC TokCmp (const TokNode* T)
94 /* Compare the token given as parameter against the current token */
95 {
96     if (T->Tok != Tok) {
97         /* Different token */
98         return tcDifferent;
99     }
100      
101     /* If the token has string attribute, check it */
102     if (TokHasSVal (T->Tok)) {
103         if (strcmp  (T->SVal, SVal) != 0) {
104             return tcSameToken;
105         }
106     } else if (TokHasIVal (T->Tok)) {
107         if (T->IVal != IVal) {
108             return tcSameToken;
109         }
110     }
111          
112     /* Tokens are identical */
113     return tcIdentical;
114 }
115
116
117