Channels.pm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. # Copyright (C) 2002-2012 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 2, or (at your option)
  5. # any later version.
  6. # This program is distributed in the hope that it will be useful,
  7. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. # GNU General Public License for more details.
  10. # You should have received a copy of the GNU General Public License
  11. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. ###############################################################
  13. # The main copy of this file is in Automake's git repository. #
  14. # Updates should be sent to automake-patches@gnu.org. #
  15. ###############################################################
  16. package Autom4te::Channels;
  17. =head1 NAME
  18. Autom4te::Channels - support functions for error and warning management
  19. =head1 SYNOPSIS
  20. use Autom4te::Channels;
  21. # Register a channel to output warnings about unused variables.
  22. register_channel 'unused', type => 'warning';
  23. # Register a channel for system errors.
  24. register_channel 'system', type => 'error', exit_code => 4;
  25. # Output a message on channel 'unused'.
  26. msg 'unused', "$file:$line", "unused variable '$var'";
  27. # Make the 'unused' channel silent.
  28. setup_channel 'unused', silent => 1;
  29. # Turn on all channels of type 'warning'.
  30. setup_channel_type 'warning', silent => 0;
  31. # Redirect all channels to push messages on a Thread::Queue using
  32. # the specified serialization key.
  33. setup_channel_queue $queue, $key;
  34. # Output a message pending in a Thread::Queue.
  35. pop_channel_queue $queue;
  36. # Treat all warnings as errors.
  37. $warnings_are_errors = 1;
  38. # Exit with the greatest exit code encountered so far.
  39. exit $exit_code;
  40. =head1 DESCRIPTION
  41. This perl module provides support functions for handling diagnostic
  42. channels in programs. Channels can be registered to convey fatal,
  43. error, warning, or debug messages. Each channel has various options
  44. (e.g. is the channel silent, should duplicate messages be removed,
  45. etc.) that can also be overridden on a per-message basis.
  46. =cut
  47. use 5.006;
  48. use strict;
  49. use Exporter;
  50. use Carp;
  51. use File::Basename;
  52. use vars qw (@ISA @EXPORT %channels $me);
  53. @ISA = qw (Exporter);
  54. @EXPORT = qw ($exit_code $warnings_are_errors
  55. &reset_local_duplicates &reset_global_duplicates
  56. &register_channel &msg &exists_channel &channel_type
  57. &setup_channel &setup_channel_type
  58. &dup_channel_setup &drop_channel_setup
  59. &buffer_messages &flush_messages
  60. &setup_channel_queue &pop_channel_queue
  61. US_GLOBAL US_LOCAL
  62. UP_NONE UP_TEXT UP_LOC_TEXT);
  63. $me = basename $0;
  64. =head2 Global Variables
  65. =over 4
  66. =item C<$exit_code>
  67. The greatest exit code seen so far. C<$exit_code> is updated from
  68. the C<exit_code> options of C<fatal> and C<error> channels.
  69. =cut
  70. use vars qw ($exit_code);
  71. $exit_code = 0;
  72. =item C<$warnings_are_errors>
  73. Set this variable to 1 if warning messages should be treated as
  74. errors (i.e. if they should update C<$exit_code>).
  75. =cut
  76. use vars qw ($warnings_are_errors);
  77. $warnings_are_errors = 0;
  78. =back
  79. =head2 Constants
  80. =over 4
  81. =item C<UP_NONE>, C<UP_TEXT>, C<UP_LOC_TEXT>
  82. Possible values for the C<uniq_part> options. This selects the part
  83. of the message that should be considered when filtering out duplicates.
  84. If C<UP_LOC_TEXT> is used, the location and the explanation message
  85. are used for filtering. If C<UP_TEXT> is used, only the explanation
  86. message is used (so the same message will be filtered out if it appears
  87. at different locations). C<UP_NONE> means that duplicate messages
  88. should be output.
  89. =cut
  90. use constant UP_NONE => 0;
  91. use constant UP_TEXT => 1;
  92. use constant UP_LOC_TEXT => 2;
  93. =item C<US_LOCAL>, C<US_GLOBAL>
  94. Possible values for the C<uniq_scope> options.
  95. Use C<US_GLOBAL> for error messages that should be printed only
  96. once during the execution of the program, C<US_LOCAL> for message that
  97. should be printed only once per file. (Actually, C<Channels> does not
  98. do this now when files are changed, it relies on you calling
  99. C<reset_local_duplicates> when this happens.)
  100. =cut
  101. # possible values for uniq_scope
  102. use constant US_LOCAL => 0;
  103. use constant US_GLOBAL => 1;
  104. =back
  105. =head2 Options
  106. Channels accept the options described below. These options can be
  107. passed as a hash to the C<register_channel>, C<setup_channel>, and C<msg>
  108. functions. The possible keys, with their default value are:
  109. =over
  110. =item C<type =E<gt> 'warning'>
  111. The type of the channel. One of C<'debug'>, C<'warning'>, C<'error'>, or
  112. C<'fatal'>. Fatal messages abort the program when they are output.
  113. Error messages update the exit status. Debug and warning messages are
  114. harmless, except that warnings are treated as errors if
  115. C<$warnings_are_errors> is set.
  116. =item C<exit_code =E<gt> 1>
  117. The value to update C<$exit_code> with when a fatal or error message
  118. is emitted. C<$exit_code> is also updated for warnings output
  119. when C<$warnings_are_errors> is set.
  120. =item C<file =E<gt> \*STDERR>
  121. The file where the error should be output.
  122. =item C<silent =E<gt> 0>
  123. Whether the channel should be silent. Use this do disable a
  124. category of warning, for instance.
  125. =item C<ordered =E<gt> 1>
  126. Whether, with multi-threaded execution, the message should be queued
  127. for ordered output.
  128. =item C<uniq_part =E<gt> UP_LOC_TEXT>
  129. The part of the message subject to duplicate filtering. See the
  130. documentation for the C<UP_NONE>, C<UP_TEXT>, and C<UP_LOC_TEXT>
  131. constants above.
  132. C<uniq_part> can also be set to an arbitrary string that will be used
  133. instead of the message when considering duplicates.
  134. =item C<uniq_scope =E<gt> US_LOCAL>
  135. The scope of duplicate filtering. See the documentation for the
  136. C<US_LOCAL>, and C<US_GLOBAL> constants above.
  137. =item C<header =E<gt> ''>
  138. A string to prepend to each message emitted through this channel.
  139. With partial messages, only the first part will have C<header>
  140. prepended.
  141. =item C<footer =E<gt> ''>
  142. A string to append to each message emitted through this channel.
  143. With partial messages, only the final part will have C<footer>
  144. appended.
  145. =item C<backtrace =E<gt> 0>
  146. Die with a stack backtrace after displaying the message.
  147. =item C<partial =E<gt> 0>
  148. When set, indicates a partial message that should
  149. be output along with the next message with C<partial> unset.
  150. Several partial messages can be stacked this way.
  151. Duplicate filtering will apply to the I<global> message resulting from
  152. all I<partial> messages, using the options from the last (non-partial)
  153. message. Linking associated messages is the main reason to use this
  154. option.
  155. For instance the following messages
  156. msg 'channel', 'foo:2', 'redefinition of A ...';
  157. msg 'channel', 'foo:1', '... A previously defined here';
  158. msg 'channel', 'foo:3', 'redefinition of A ...';
  159. msg 'channel', 'foo:1', '... A previously defined here';
  160. will result in
  161. foo:2: redefinition of A ...
  162. foo:1: ... A previously defined here
  163. foo:3: redefinition of A ...
  164. where the duplicate "I<... A previously defined here>" has been
  165. filtered out.
  166. Linking these messages using C<partial> as follows will prevent the
  167. fourth message to disappear.
  168. msg 'channel', 'foo:2', 'redefinition of A ...', partial => 1;
  169. msg 'channel', 'foo:1', '... A previously defined here';
  170. msg 'channel', 'foo:3', 'redefinition of A ...', partial => 1;
  171. msg 'channel', 'foo:1', '... A previously defined here';
  172. Note that because the stack of C<partial> messages is printed with the
  173. first non-C<partial> message, most options of C<partial> messages will
  174. be ignored.
  175. =back
  176. =cut
  177. use vars qw (%_default_options %_global_duplicate_messages
  178. %_local_duplicate_messages);
  179. # Default options for a channel.
  180. %_default_options =
  181. (
  182. type => 'warning',
  183. exit_code => 1,
  184. file => \*STDERR,
  185. silent => 0,
  186. ordered => 1,
  187. queue => 0,
  188. queue_key => undef,
  189. uniq_scope => US_LOCAL,
  190. uniq_part => UP_LOC_TEXT,
  191. header => '',
  192. footer => '',
  193. backtrace => 0,
  194. partial => 0,
  195. );
  196. # Filled with output messages as keys, to detect duplicates.
  197. # The value associated with each key is the number of occurrences
  198. # filtered out.
  199. %_local_duplicate_messages = ();
  200. %_global_duplicate_messages = ();
  201. sub _reset_duplicates (\%)
  202. {
  203. my ($ref) = @_;
  204. my $dup = 0;
  205. foreach my $k (keys %$ref)
  206. {
  207. $dup += $ref->{$k};
  208. }
  209. %$ref = ();
  210. return $dup;
  211. }
  212. =head2 Functions
  213. =over 4
  214. =item C<reset_local_duplicates ()>
  215. Reset local duplicate messages (see C<US_LOCAL>), and
  216. return the number of messages that have been filtered out.
  217. =cut
  218. sub reset_local_duplicates ()
  219. {
  220. return _reset_duplicates %_local_duplicate_messages;
  221. }
  222. =item C<reset_global_duplicates ()>
  223. Reset local duplicate messages (see C<US_GLOBAL>), and
  224. return the number of messages that have been filtered out.
  225. =cut
  226. sub reset_global_duplicates ()
  227. {
  228. return _reset_duplicates %_global_duplicate_messages;
  229. }
  230. sub _merge_options (\%%)
  231. {
  232. my ($hash, %options) = @_;
  233. local $_;
  234. foreach (keys %options)
  235. {
  236. if (exists $hash->{$_})
  237. {
  238. $hash->{$_} = $options{$_}
  239. }
  240. else
  241. {
  242. confess "unknown option '$_'";
  243. }
  244. }
  245. if ($hash->{'ordered'})
  246. {
  247. confess "fatal messages cannot be ordered"
  248. if $hash->{'type'} eq 'fatal';
  249. confess "backtrace cannot be output on ordered messages"
  250. if $hash->{'backtrace'};
  251. }
  252. }
  253. =item C<register_channel ($name, [%options])>
  254. Declare channel C<$name>, and override the default options
  255. with those listed in C<%options>.
  256. =cut
  257. sub register_channel ($;%)
  258. {
  259. my ($name, %options) = @_;
  260. my %channel_opts = %_default_options;
  261. _merge_options %channel_opts, %options;
  262. $channels{$name} = \%channel_opts;
  263. }
  264. =item C<exists_channel ($name)>
  265. Returns true iff channel C<$name> has been registered.
  266. =cut
  267. sub exists_channel ($)
  268. {
  269. my ($name) = @_;
  270. return exists $channels{$name};
  271. }
  272. =item C<channel_type ($name)>
  273. Returns the type of channel C<$name> if it has been registered.
  274. Returns the empty string otherwise.
  275. =cut
  276. sub channel_type ($)
  277. {
  278. my ($name) = @_;
  279. return $channels{$name}{'type'} if exists_channel $name;
  280. return '';
  281. }
  282. # _format_sub_message ($LEADER, $MESSAGE)
  283. # ---------------------------------------
  284. # Split $MESSAGE at new lines and add $LEADER to each line.
  285. sub _format_sub_message ($$)
  286. {
  287. my ($leader, $message) = @_;
  288. return $leader . join ("\n" . $leader, split ("\n", $message)) . "\n";
  289. }
  290. # Store partial messages here. (See the 'partial' option.)
  291. use vars qw ($partial);
  292. $partial = '';
  293. # _format_message ($LOCATION, $MESSAGE, %OPTIONS)
  294. # -----------------------------------------------
  295. # Format the message. Return a string ready to print.
  296. sub _format_message ($$%)
  297. {
  298. my ($location, $message, %opts) = @_;
  299. my $msg = ($partial eq '' ? $opts{'header'} : '') . $message
  300. . ($opts{'partial'} ? '' : $opts{'footer'});
  301. if (ref $location)
  302. {
  303. # If $LOCATION is a reference, assume it's an instance of the
  304. # Autom4te::Location class and display contexts.
  305. my $loc = $location->get || $me;
  306. $msg = _format_sub_message ("$loc: ", $msg);
  307. for my $pair ($location->get_contexts)
  308. {
  309. $msg .= _format_sub_message ($pair->[0] . ": ", $pair->[1]);
  310. }
  311. }
  312. else
  313. {
  314. $location ||= $me;
  315. $msg = _format_sub_message ("$location: ", $msg);
  316. }
  317. return $msg;
  318. }
  319. # _enqueue ($QUEUE, $KEY, $UNIQ_SCOPE, $TO_FILTER, $MSG, $FILE)
  320. # -------------------------------------------------------------
  321. # Push message on a queue, to be processed by another thread.
  322. sub _enqueue ($$$$$$)
  323. {
  324. my ($queue, $key, $uniq_scope, $to_filter, $msg, $file) = @_;
  325. $queue->enqueue ($key, $msg, $to_filter, $uniq_scope);
  326. confess "message queuing works only for STDERR"
  327. if $file ne \*STDERR;
  328. }
  329. # _dequeue ($QUEUE)
  330. # -----------------
  331. # Pop a message from a queue, and print, similarly to how
  332. # _print_message would do it. Return 0 if the queue is
  333. # empty. Note that the key has already been dequeued.
  334. sub _dequeue ($)
  335. {
  336. my ($queue) = @_;
  337. my $msg = $queue->dequeue || return 0;
  338. my $to_filter = $queue->dequeue;
  339. my $uniq_scope = $queue->dequeue;
  340. my $file = \*STDERR;
  341. if ($to_filter ne '')
  342. {
  343. # Do we want local or global uniqueness?
  344. my $dups;
  345. if ($uniq_scope == US_LOCAL)
  346. {
  347. $dups = \%_local_duplicate_messages;
  348. }
  349. elsif ($uniq_scope == US_GLOBAL)
  350. {
  351. $dups = \%_global_duplicate_messages;
  352. }
  353. else
  354. {
  355. confess "unknown value for uniq_scope: " . $uniq_scope;
  356. }
  357. # Update the hash of messages.
  358. if (exists $dups->{$to_filter})
  359. {
  360. ++$dups->{$to_filter};
  361. return 1;
  362. }
  363. else
  364. {
  365. $dups->{$to_filter} = 0;
  366. }
  367. }
  368. print $file $msg;
  369. return 1;
  370. }
  371. # _print_message ($LOCATION, $MESSAGE, %OPTIONS)
  372. # ----------------------------------------------
  373. # Format the message, check duplicates, and print it.
  374. sub _print_message ($$%)
  375. {
  376. my ($location, $message, %opts) = @_;
  377. return 0 if ($opts{'silent'});
  378. my $msg = _format_message ($location, $message, %opts);
  379. if ($opts{'partial'})
  380. {
  381. # Incomplete message. Store, don't print.
  382. $partial .= $msg;
  383. return;
  384. }
  385. else
  386. {
  387. # Prefix with any partial message send so far.
  388. $msg = $partial . $msg;
  389. $partial = '';
  390. }
  391. msg ('note', '', 'warnings are treated as errors', uniq_scope => US_GLOBAL)
  392. if ($opts{'type'} eq 'warning' && $warnings_are_errors);
  393. # Check for duplicate message if requested.
  394. my $to_filter;
  395. if ($opts{'uniq_part'} ne UP_NONE)
  396. {
  397. # Which part of the error should we match?
  398. if ($opts{'uniq_part'} eq UP_TEXT)
  399. {
  400. $to_filter = $message;
  401. }
  402. elsif ($opts{'uniq_part'} eq UP_LOC_TEXT)
  403. {
  404. $to_filter = $msg;
  405. }
  406. else
  407. {
  408. $to_filter = $opts{'uniq_part'};
  409. }
  410. # Do we want local or global uniqueness?
  411. my $dups;
  412. if ($opts{'uniq_scope'} == US_LOCAL)
  413. {
  414. $dups = \%_local_duplicate_messages;
  415. }
  416. elsif ($opts{'uniq_scope'} == US_GLOBAL)
  417. {
  418. $dups = \%_global_duplicate_messages;
  419. }
  420. else
  421. {
  422. confess "unknown value for uniq_scope: " . $opts{'uniq_scope'};
  423. }
  424. # Update the hash of messages.
  425. if (exists $dups->{$to_filter})
  426. {
  427. ++$dups->{$to_filter};
  428. return 0;
  429. }
  430. else
  431. {
  432. $dups->{$to_filter} = 0;
  433. }
  434. }
  435. my $file = $opts{'file'};
  436. if ($opts{'ordered'} && $opts{'queue'})
  437. {
  438. _enqueue ($opts{'queue'}, $opts{'queue_key'}, $opts{'uniq_scope'},
  439. $to_filter, $msg, $file);
  440. }
  441. else
  442. {
  443. print $file $msg;
  444. }
  445. return 1;
  446. }
  447. =item C<msg ($channel, $location, $message, [%options])>
  448. Emit a message on C<$channel>, overriding some options of the channel with
  449. those specified in C<%options>. Obviously C<$channel> must have been
  450. registered with C<register_channel>.
  451. C<$message> is the text of the message, and C<$location> is a location
  452. associated to the message.
  453. For instance to complain about some unused variable C<mumble>
  454. declared at line 10 in F<foo.c>, one could do:
  455. msg 'unused', 'foo.c:10', "unused variable 'mumble'";
  456. If channel C<unused> is not silent (and if this message is not a duplicate),
  457. the following would be output:
  458. foo.c:10: unused variable 'mumble'
  459. C<$location> can also be an instance of C<Autom4te::Location>. In this
  460. case, the stack of contexts will be displayed in addition.
  461. If C<$message> contains newline characters, C<$location> is prepended
  462. to each line. For instance,
  463. msg 'error', 'somewhere', "1st line\n2nd line";
  464. becomes
  465. somewhere: 1st line
  466. somewhere: 2nd line
  467. If C<$location> is an empty string, it is replaced by the name of the
  468. program. Actually, if you don't use C<%options>, you can even
  469. elide the empty C<$location>. Thus
  470. msg 'fatal', '', 'fatal error';
  471. msg 'fatal', 'fatal error';
  472. both print
  473. progname: fatal error
  474. =cut
  475. use vars qw (@backlog %buffering);
  476. # See buffer_messages() and flush_messages() below.
  477. %buffering = (); # The map of channel types to buffer.
  478. @backlog = (); # The buffer of messages.
  479. sub msg ($$;$%)
  480. {
  481. my ($channel, $location, $message, %options) = @_;
  482. if (! defined $message)
  483. {
  484. $message = $location;
  485. $location = '';
  486. }
  487. confess "unknown channel $channel" unless exists $channels{$channel};
  488. my %opts = %{$channels{$channel}};
  489. _merge_options (%opts, %options);
  490. if (exists $buffering{$opts{'type'}})
  491. {
  492. push @backlog, [$channel, $location->clone, $message, %options];
  493. return;
  494. }
  495. # Print the message if needed.
  496. if (_print_message ($location, $message, %opts))
  497. {
  498. # Adjust exit status.
  499. if ($opts{'type'} eq 'error'
  500. || $opts{'type'} eq 'fatal'
  501. || ($opts{'type'} eq 'warning' && $warnings_are_errors))
  502. {
  503. my $es = $opts{'exit_code'};
  504. $exit_code = $es if $es > $exit_code;
  505. }
  506. # Die on fatal messages.
  507. confess if $opts{'backtrace'};
  508. if ($opts{'type'} eq 'fatal')
  509. {
  510. # flush messages explicitly here, needed in worker threads.
  511. STDERR->flush;
  512. exit $exit_code;
  513. }
  514. }
  515. }
  516. =item C<setup_channel ($channel, %options)>
  517. Override the options of C<$channel> with those specified by C<%options>.
  518. =cut
  519. sub setup_channel ($%)
  520. {
  521. my ($name, %opts) = @_;
  522. confess "unknown channel $name" unless exists $channels{$name};
  523. _merge_options %{$channels{$name}}, %opts;
  524. }
  525. =item C<setup_channel_type ($type, %options)>
  526. Override the options of any channel of type C<$type>
  527. with those specified by C<%options>.
  528. =cut
  529. sub setup_channel_type ($%)
  530. {
  531. my ($type, %opts) = @_;
  532. foreach my $channel (keys %channels)
  533. {
  534. setup_channel $channel, %opts
  535. if $channels{$channel}{'type'} eq $type;
  536. }
  537. }
  538. =item C<dup_channel_setup ()>, C<drop_channel_setup ()>
  539. Sometimes it is necessary to make temporary modifications to channels.
  540. For instance one may want to disable a warning while processing a
  541. particular file, and then restore the initial setup. These two
  542. functions make it easy: C<dup_channel_setup ()> saves a copy of the
  543. current configuration for later restoration by
  544. C<drop_channel_setup ()>.
  545. You can think of this as a stack of configurations whose first entry
  546. is the active one. C<dup_channel_setup ()> duplicates the first
  547. entry, while C<drop_channel_setup ()> just deletes it.
  548. =cut
  549. use vars qw (@_saved_channels @_saved_werrors);
  550. @_saved_channels = ();
  551. @_saved_werrors = ();
  552. sub dup_channel_setup ()
  553. {
  554. my %channels_copy;
  555. foreach my $k1 (keys %channels)
  556. {
  557. $channels_copy{$k1} = {%{$channels{$k1}}};
  558. }
  559. push @_saved_channels, \%channels_copy;
  560. push @_saved_werrors, $warnings_are_errors;
  561. }
  562. sub drop_channel_setup ()
  563. {
  564. my $saved = pop @_saved_channels;
  565. %channels = %$saved;
  566. $warnings_are_errors = pop @_saved_werrors;
  567. }
  568. =item C<buffer_messages (@types)>, C<flush_messages ()>
  569. By default, when C<msg> is called, messages are processed immediately.
  570. Sometimes it is necessary to delay the output of messages.
  571. For instance you might want to make diagnostics before
  572. channels have been completely configured.
  573. After C<buffer_messages(@types)> has been called, messages sent with
  574. C<msg> to a channel whose type is listed in C<@types> will be stored in a
  575. list for later processing.
  576. This backlog of messages is processed when C<flush_messages> is
  577. called, with the current channel options (not the options in effect,
  578. at the time of C<msg>). So for instance, if some channel was silenced
  579. in the meantime, messages to this channel will not be printed.
  580. C<flush_messages> cancels the effect of C<buffer_messages>. Following
  581. calls to C<msg> are processed immediately as usual.
  582. =cut
  583. sub buffer_messages (@)
  584. {
  585. foreach my $type (@_)
  586. {
  587. $buffering{$type} = 1;
  588. }
  589. }
  590. sub flush_messages ()
  591. {
  592. %buffering = ();
  593. foreach my $args (@backlog)
  594. {
  595. &msg (@$args);
  596. }
  597. @backlog = ();
  598. }
  599. =item C<setup_channel_queue ($queue, $key)>
  600. Set the queue to fill for each channel that is ordered,
  601. and the key to use for serialization.
  602. =cut
  603. sub setup_channel_queue ($$)
  604. {
  605. my ($queue, $key) = @_;
  606. foreach my $channel (keys %channels)
  607. {
  608. setup_channel $channel, queue => $queue, queue_key => $key
  609. if $channels{$channel}{'ordered'};
  610. }
  611. }
  612. =item C<pop_channel_queue ($queue)>
  613. pop a message off the $queue; the key has already been popped.
  614. =cut
  615. sub pop_channel_queue ($)
  616. {
  617. my ($queue) = @_;
  618. return _dequeue ($queue);
  619. }
  620. =back
  621. =head1 SEE ALSO
  622. L<Autom4te::Location>
  623. =head1 HISTORY
  624. Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
  625. =cut
  626. 1;
  627. ### Setup "GNU" style for perl-mode and cperl-mode.
  628. ## Local Variables:
  629. ## perl-indent-level: 2
  630. ## perl-continued-statement-offset: 2
  631. ## perl-continued-brace-offset: 0
  632. ## perl-brace-offset: 0
  633. ## perl-brace-imaginary-offset: 0
  634. ## perl-label-offset: -2
  635. ## cperl-indent-level: 2
  636. ## cperl-brace-offset: 0
  637. ## cperl-continued-brace-offset: 0
  638. ## cperl-label-offset: -2
  639. ## cperl-extra-newline-before-brace: t
  640. ## cperl-merge-trailing-else: nil
  641. ## cperl-continued-statement-offset: 2
  642. ## End: