/[ascend]/trunk/base/generic/compiler/braced.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/braced.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 16 - (show annotations) (download) (as text)
Thu Nov 25 22:52:42 2004 UTC (19 years, 6 months ago) by ben.allan
File MIME type: text/x-csrc
File size: 2456 byte(s)
replaced nonportable strdup with ascend equivalent.
1 /*
2 * Braced Text Module
3 * By Benjamin Allan
4 * March 20, 1998.
5 * Part of ASCEND
6 * Version: $Revision: 1.4 $
7 * Version control file: $RCSfile: braced.c,v $
8 * Date last modified: $Date: 1998/06/16 16:38:38 $
9 * Last modified by: $Author: mthomas $
10 *
11 * This file is part of the Ascend Language Interpreter.
12 *
13 * Copyright (C) 1998 Carnegie Mellon University
14 *
15 * The Ascend Language Interpreter is free software; you can
16 * redistribute it and/or modify it under the terms of the GNU
17 * General Public License as published by the Free Software
18 * Foundation; either version 2 of the License, or (at your option)
19 * any later version.
20 *
21 * The Ascend Language Interpreter is distributed in hope that it
22 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
23 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
24 * See the GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with the program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check
29 * the file named COPYING.
30 */
31
32 #include "utilities/ascConfig.h"
33 #include "utilities/ascMalloc.h"
34 #include "compiler/compiler.h"
35
36 /* We expect things in this file to get much more complicated
37 * to deal with notes.
38 */
39
40 struct bracechar {
41 symchar *lang;
42 char *string;
43 int slen;
44 int refcount;
45 };
46
47 #define BCMALLOC (struct bracechar *)ascmalloc(sizeof(struct bracechar))
48 #define BCFREE(bc) ascfree(bc)
49
50 struct bracechar *AddBraceChar(CONST char *s, symchar *l)
51 {
52 struct bracechar *bc;
53 assert(s != NULL);
54 bc = BCMALLOC;
55 assert(bc!= NULL);
56 bc->lang = l;
57 bc->string = ascstrdup((char *)s); /* fixme */
58 bc->slen = strlen((char *)s);
59 bc->refcount = 0;
60 return bc;
61 }
62
63 struct bracechar *CopyBraceChar(struct bracechar *bc)
64 {
65 if (bc!=NULL) {
66 bc->refcount++;
67 }
68 return bc;
69 }
70
71 void DestroyBraceChar(struct bracechar *bc)
72 {
73 if (bc==NULL) {
74 return;
75 }
76 if (bc->refcount == 0) {
77 ascfree(bc->string); /* fixme */
78 bc->slen = -1;
79 bc->lang = NULL;
80 bc->string = NULL;
81 BCFREE(bc);
82 } else {
83 bc->refcount--;
84 }
85 }
86
87 CONST char *BraceCharString(struct bracechar *bc)
88 {
89 assert(bc!=NULL);
90 return bc->string;
91 }
92
93 symchar *BraceCharLang(struct bracechar *bc)
94 {
95 assert(bc!=NULL);
96 return bc->lang;
97 }
98
99 int BraceCharLen(struct bracechar *bc)
100 {
101 assert(bc!=NULL);
102 return bc->slen;
103 }
104

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22