~ubuntu-branches/ubuntu/trusty/wget/trusty-updates

« back to all changes in this revision

Viewing changes to src/log.c

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2009-12-12 08:15:59 UTC
  • mfrom: (2.1.5 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091212081559-mvccl4kzdqb138y3
Tags: 1.12-1.1ubuntu1
* Merge from debian testing, remaining changes:
  - Add wget-udeb to ship wget.gnu as alternative to busybox wget
    implementation.
* Keep build dependencies in main:
  - debian/control: remove info2man build-dep
  - debian/patches/00list: disable wget-infopod_generated_manpage.dpatch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Messages logging.
2
2
   Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3
 
   2007, 2008 Free Software Foundation, Inc.
 
3
   2007, 2008, 2009 Free Software Foundation, Inc.
4
4
 
5
5
This file is part of GNU Wget.
6
6
 
28
28
shall include the source code for the parts of OpenSSL used as well
29
29
as that of the covered work.  */
30
30
 
31
 
#include <config.h>
 
31
#include "wget.h"
32
32
 
33
33
#include <stdio.h>
34
34
#include <string.h>
40
40
#include <assert.h>
41
41
#include <errno.h>
42
42
 
43
 
#include "wget.h"
44
43
#include "utils.h"
45
44
#include "log.h"
46
45
 
47
 
/* This file impplement support for "logging".  Logging means printing
 
46
/* 2005-10-25 SMS.
 
47
   VMS log files are often VFC record format, not stream, so fputs() can
 
48
   produce multiple records, even when there's no newline terminator in
 
49
   the buffer.  The result is unsightly output with spurious newlines.
 
50
   Using fprintf() instead of fputs(), along with inhibiting some
 
51
   fflush() activity below, seems to solve the problem.
 
52
*/
 
53
#ifdef __VMS
 
54
# define FPUTS( s, f) fprintf( (f), "%s", (s))
 
55
#else /* def __VMS */
 
56
# define FPUTS( s, f) fputs( (s), (f))
 
57
#endif /* def __VMS [else] */
 
58
 
 
59
/* This file implements support for "logging".  Logging means printing
48
60
   output, plus several additional features:
49
61
 
50
62
   - Cataloguing output by importance.  You can specify that a log
308
320
    return;
309
321
  CHECK_VERBOSE (o);
310
322
 
311
 
  fputs (s, fp);
 
323
  FPUTS (s, fp);
312
324
  if (save_context_p)
313
325
    saved_append (s);
314
326
  if (flush_log_p)
398
410
 
399
411
  /* Writing succeeded. */
400
412
  saved_append (write_ptr);
401
 
  fputs (write_ptr, fp);
 
413
  FPUTS (write_ptr, fp);
402
414
  if (state->bigmsg)
403
415
    xfree (state->bigmsg);
404
416
 
417
429
{
418
430
  FILE *fp = get_log_fp ();
419
431
  if (fp)
420
 
    fflush (fp);
 
432
    {
 
433
/* 2005-10-25 SMS.
 
434
   On VMS, flush only for a terminal.  See note at FPUTS macro, above.
 
435
*/
 
436
#ifdef __VMS
 
437
      if (isatty( fileno( fp)))
 
438
        {
 
439
          fflush (fp);
 
440
        }
 
441
#else /* def __VMS */
 
442
      fflush (fp);
 
443
#endif /* def __VMS [else] */
 
444
    }
421
445
  needs_flushing = false;
422
446
}
423
447
 
584
608
    {
585
609
      struct log_ln *ln = log_lines + num;
586
610
      if (ln->content)
587
 
        fputs (ln->content, fp);
 
611
        FPUTS (ln->content, fp);
588
612
      ROT_ADVANCE (num);
589
613
    }
590
614
  while (num != log_line_current);
591
615
  if (trailing_line)
592
616
    if (log_lines[log_line_current].content)
593
 
      fputs (log_lines[log_line_current].content, fp);
 
617
      FPUTS (log_lines[log_line_current].content, fp);
594
618
  fflush (fp);
595
619
}
596
620
 
597
621
/* String escape functions. */
598
622
 
599
623
/* Return the number of non-printable characters in SOURCE.
600
 
   Non-printable characters are determined as per safe-ctype.c.  */
 
624
   Non-printable characters are determined as per c-ctype.c.  */
601
625
 
602
626
static int
603
627
count_nonprint (const char *source)
605
629
  const char *p;
606
630
  int cnt;
607
631
  for (p = source, cnt = 0; *p; p++)
608
 
    if (!ISPRINT (*p))
 
632
    if (!c_isprint (*p))
609
633
      ++cnt;
610
634
  return cnt;
611
635
}
645
669
    {
646
670
    case 8:
647
671
      while ((c = *from++) != '\0')
648
 
        if (ISPRINT (c))
 
672
        if (c_isprint (c))
649
673
          *to++ = c;
650
674
        else
651
675
          {
657
681
      break;
658
682
    case 16:
659
683
      while ((c = *from++) != '\0')
660
 
        if (ISPRINT (c))
 
684
        if (c_isprint (c))
661
685
          *to++ = c;
662
686
        else
663
687
          {
763
787
void
764
788
log_cleanup (void)
765
789
{
766
 
  int i;
 
790
  size_t i;
767
791
  for (i = 0; i < countof (ring); i++)
768
792
    xfree_null (ring[i].buffer);
769
793
}
782
806
  logfp = unique_create (DEFAULT_LOGFILE, false, &logfile);
783
807
  if (logfp)
784
808
    {
785
 
      fprintf (stderr, _("\n%s received, redirecting output to `%s'.\n"),
786
 
               redirect_request_signal_name, logfile);
 
809
      fprintf (stderr, _("\n%s received, redirecting output to %s.\n"),
 
810
               redirect_request_signal_name, quote (logfile));
787
811
      xfree (logfile);
788
812
      /* Dump the context output to the newly opened log.  */
789
813
      log_dump_context ();