1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
[~ autogen5 template
h
gperf=debughash.gperf
# Copyright 2001 Alexandre Duret-Lutz <duret_g@epita.fr>
#
# This file is part of Heroes.
#
# Heroes is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your
# option) any later version.
#
# Heroes is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
~]
[~ CASE (suffix) ~]
[~ == h ~][~ (dne "** " "/*\t\t\t\t") ~]
*/
/*
[~ (gpl "Heroes" "** ") ~]
*/
[~ (begin
(define *chn_counter* 1)
(define (chn_counter)
(let ((counter *chn_counter*))
(set! *chn_counter* (* counter 2))
counter))) ~]
typedef enum debug_lvl { [~ FOR channel ',' ~]
D_[~
(sprintf "%-16s = %6d /* %s */"
(string-upcase! (get "name"))
(chn_counter)
(get "descr")) ~][~
ENDFOR channel ~]
} debug_lvl;
[~ == gperf ~]%{
[~ (dne "** " "/*\t\t\t\t") ~]
*/
/*
[~ (gpl "Heroes" "** ") ~]
*/
#include "system.h"
#include "debughash.h"
#include "errors.h"
#include "fstrcmp.h"
/* prototype in_channel_set as static */
static struct debug_channel_s *
in_channel_set (register const char *str, register unsigned int len);
%}
struct debug_channel_s {
const char *name;
const char *doc;
enum debug_lvl number;
};
%%
[~ (define (print-line name descr enum)
(sprintf "%-17s N_(\"%-40s %s"
(string-append name ",")
(string-append descr "\"),")
(string-upcase! enum))) ~][~
(print-line "all" "all messages" "-1") ~]
[~ FOR channel '' ~][~
(print-line (get "name") (get "descr") (string-append "D_" (get "name"))) ~]
[~ ENDFOR ~]%%
static const struct debug_channel_s *
get_channel_approx (const char *name)
{
int i;
const struct debug_channel_s *res = 0;
double best_weight = 0.7;
for (i = MIN_HASH_VALUE; i <= MAX_HASH_VALUE; ++i) {
if (channel_set[i].name[0]) {
double weight = fstrcmp (name, channel_set[i].name);
if (weight > best_weight) {
best_weight = weight;
res = &(channel_set[i]);
}
}
}
return res;
}
enum debug_lvl
get_channel_number (const char *name)
{
const struct debug_channel_s *res = in_channel_set (name, strlen (name));
if (!res) {
/* try to find a channel which name is close to the given name */
res = get_channel_approx (name);
if (res)
wmsg (_("%s: no such channel, assuming you meant '%s'."),
name, res->name);
else
emsg (_("%s: no such channel (--list=debug will list "
"all known channels)"), name);
}
return res->number;
}
void
print_debug_channels (void)
{
int i;
for (i = MIN_HASH_VALUE; i <= MAX_HASH_VALUE; ++i) {
if (channel_set[i].name[0]) {
printf ("%-16s %s\n", channel_set[i].name, _(channel_set[i].doc));
}
}
}
[~ == texi ~][~ (import-head "DEBUGCHN") ~]
@table @samp[~ FOR channel '' ~]
@item [~ (string-upcase! (get "name")) ~]
[~ ? doc (get "doc") (string-append (string-capitalize (get "descr")) ".") ~]
[~ ENDFOR ~]
@item ALL
All of the above.
@end table
[~ (import-tail "DEBUGCHN") ~][~ ESAC ~]
|