File: warning.c

package info (click to toggle)
acorn-fdisk 3.0.6-13
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,068 kB
  • sloc: ansic: 5,422; makefile: 99
file content (49 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (10)
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
/*
 * lib/util/warning.c
 *
 * Copyright (C) 1997,1998 Russell King
 */
#include <ctype.h>
#include <stdarg.h>
#include <stdio.h>

#include "util/warning.h"

static char warning_message[2048];

/* Function: void issue_warning (const char *fmt, ...)
 * Purpose : Set warning string
 * Params  : fmt - printf-like format
 */
void issue_warning (const char *fmt, ...)
{
  va_list ap;

  if (fmt) {
    int characters = 0;
    char *p, *s, *e;

    va_start (ap, fmt);
    p = warning_message;
    p += sprintf(p, "Warning: ");
    vsprintf (p, fmt, ap);
    va_end (ap);

    for (p = s = e = warning_message;; p += 1) {
      if (!*p) {
      	if (characters)
      	  printf("%s\n", s);
        break;
      }
      characters += 1;
      if (isspace(*p))
        e = p;
      if (characters > 60) {
      	*e = '\0';
        printf("%s\n", s);
        s = (p = e) + 1;
        characters = 0;
      }
    }
  }
}