Debian Codegraph @

gcc/m2/gm2-compiler/M2ColorString.mod

raw
1 (* M2ColorString.mod provides procedures for obtaining GCC color strings.
2
3 Copyright (C) 2019-2025 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <[email protected]>.
5
6 This file is part of GNU Modula-2.
7
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Modula-2; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. *)
21
22 IMPLEMENTATION MODULE M2ColorString ;
23
24 FROM m2color IMPORT colorize_start, colorize_stop, open_quote, close_quote ;
25 FROM DynamicStrings IMPORT InitString, InitStringCharStar,
26 ConCat, ConCatChar, Mark, string, KillString,
27 Dup, char, Length, Mult ;
28 FROM StrLib IMPORT StrLen ;
29 FROM libc IMPORT printf ;
30 FROM SYSTEM IMPORT ADR ;
31
32
33 VAR
34 EnableColor: BOOLEAN ;
35
36
37 (*
38 SetEnableColor - sets the global variable to, b, and returns
39 the previous value.
40 *)
41
42 PROCEDURE SetEnableColor (b: BOOLEAN) : BOOLEAN ;
43 VAR
44 previous: BOOLEAN ;
45 BEGIN
46 previous := EnableColor ;
47 EnableColor := b ;
48 RETURN previous
49 END SetEnableColor ;
50
51
52 (*
53 append - appends color string, name, to the end of string, s,
54 and returns, s.
55 *)
56
57 PROCEDURE append (s: String; name: ARRAY OF CHAR) : String ;
58 VAR
59 c: String ;
60 BEGIN
61 c := InitStringCharStar (colorize_start (EnableColor, ADR (name), StrLen (name))) ;
62 s := ConCat (s, c) ;
63 c := KillString (c) ;
64 RETURN s
65 END append ;
66
67
68 (*
69 quoteOpen - adds an open quote to string, s.
70 *)
71
72 PROCEDURE quoteOpen (s: String) : String ;
73 BEGIN
74 RETURN ConCat (append (s, "quote"), Mark (InitStringCharStar (open_quote ())))
75 END quoteOpen ;
76
77
78 (*
79 quoteClose - adds a close quote to string, s.
80 *)
81
82 PROCEDURE quoteClose (s: String) : String ;
83 BEGIN
84 s := endColor (s) ;
85 s := append (s, "quote") ;
86 s := ConCat (s, Mark (InitStringCharStar (close_quote ()))) ;
87 s := endColor (s) ;
88 RETURN s
89 END quoteClose ;
90
91
92 (*
93 endColor - stops using color.
94 *)
95
96 PROCEDURE endColor (s: String) : String ;
97 VAR
98 c: String ;
99 BEGIN
100 c := InitStringCharStar (colorize_stop (EnableColor)) ;
101 s := ConCat (s, c) ;
102 c := KillString (c) ;
103 RETURN s
104 END endColor ;
105
106
107 (*
108 quoteColor - adds quote color to string, s.
109 *)
110
111 PROCEDURE quoteColor (s: String) : String ;
112 BEGIN
113 RETURN append (s, "quote")
114 END quoteColor ;
115
116
117 (*
118 errorColor - adds error color to string, s.
119 *)
120
121 PROCEDURE errorColor (s: String) : String ;
122 BEGIN
123 RETURN append (s, "error")
124 END errorColor ;
125
126
127 (*
128 warningColor - adds warning color to string, s.
129 *)
130
131 PROCEDURE warningColor (s: String) : String ;
132 BEGIN
133 RETURN append (s, "warning")
134 END warningColor ;
135
136
137 (*
138 noteColor - adds note color to string, s.
139 *)
140
141 PROCEDURE noteColor (s: String) : String ;
142 BEGIN
143 RETURN append (s, "note")
144 END noteColor ;
145
146
147 (*
148 locusColor - adds locus color to string, s.
149 *)
150
151 PROCEDURE locusColor (s: String) : String ;
152 BEGIN
153 RETURN append (s, "locus")
154 END locusColor ;
155
156
157 (*
158 insertColor - adds fixit-insert color to string, s.
159 *)
160
161 PROCEDURE insertColor (s: String) : String ;
162 BEGIN
163 RETURN append (s, "fixit-insert")
164 END insertColor ;
165
166
167 (*
168 deleteColor - adds fixit-insert color to string, s.
169 *)
170
171 PROCEDURE deleteColor (s: String) : String ;
172 BEGIN
173 RETURN append (s, "fixit-delete")
174 END deleteColor ;
175
176
177 (*
178 filenameColor - adds filename color to string, s.
179 *)
180
181 PROCEDURE filenameColor (s: String) : String ;
182 BEGIN
183 RETURN append (s, "diff-filename")
184 END filenameColor ;
185
186
187 (*
188 typeColor - adds type color to string, s.
189 *)
190
191 PROCEDURE typeColor (s: String) : String ;
192 BEGIN
193 RETURN append (s, "type")
194 END typeColor ;
195
196
197 (*
198 range1Color - adds type color to string, s.
199 *)
200
201 PROCEDURE range1Color (s: String) : String ;
202 BEGIN
203 RETURN append (s, "range1")
204 END range1Color ;
205
206
207 (*
208 range2Color - adds type color to string, s.
209 *)
210
211 PROCEDURE range2Color (s: String) : String ;
212 BEGIN
213 RETURN append (s, "range2")
214 END range2Color ;
215
216
217 BEGIN
218 EnableColor := TRUE
219 END M2ColorString.