Add the support for BSD format specifiers. This was adopted from the
[dragonfly.git] / gnu / usr.bin / cc34 / cc_prep / patches / c-format.c.patch
1 $DragonFly: src/gnu/usr.bin/cc34/cc_prep/patches/c-format.c.patch,v 1.1 2004/07/02 16:42:19 joerg Exp $
2
3 --- c-format.c.orig     2004-06-20 04:14:48.000000000 +0200
4 +++ c-format.c  2004-07-02 16:58:22.000000000 +0200
5 @@ -772,6 +772,19 @@
6    { "S",   1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",       "R"  },
7    /* GNU conversion specifiers.  */
8    { "m",   0, STD_EXT, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",       ""   },
9 +  /* BSD conversion specifiers.  */
10 +  /* DragonFly kernel extensions (src/sys/kern/subr_prf.c).
11 +     The format %b is supported to decode error registers.
12 +     Its usage is:     printf("reg=%b\n", regval, "<base><arg>*");
13 +     which produces:   reg=3<BITTWO,BITONE>
14 +     The format %D provides a hexdump given a pointer and separator string:
15 +     ("%6D", ptr, ":")         -> XX:XX:XX:XX:XX:XX
16 +     ("%*D", len, ptr, " ")    -> XX XX XX XX ...
17 +   */
18 +  { "D",   1, STD_EXT, { T89_C,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      "cR" },
19 +  { "b",   1, STD_EXT, { T89_C,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp",      ""   },
20 +  { "ry",  0, STD_EXT, { T89_I,  BADLEN,   BADLEN,   T89_L,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN  }, "-wp0 +#",  "i"  },
21 +  { "z",   0, STD_EXT, { T89_UI,  T99_UC,  T89_US,  T89_UL,  T9L_ULL, TEX_ULL, T99_ST,  T99_UPD, T99_UIM }, "-wp0#",     "i" },
22    { NULL,  0, 0, NOLENGTHS, NULL, NULL }
23  };
24  
25 @@ -1998,6 +2011,57 @@
26             }
27         }
28  
29 +      if (*format_chars == 'b')
30 +       {
31 +         /* There should be an int arg to control the string arg.  */
32 +         if (params == 0)
33 +           {
34 +             status_warning (status, "too few arguments for format");
35 +             return;
36 +           }
37 +           if (info->first_arg_num != 0)
38 +           {
39 +             cur_param = TREE_VALUE (params);
40 +             params = TREE_CHAIN (params);
41 +             ++arg_num;
42 +             if ((TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
43 +                  != integer_type_node)
44 +                 &&
45 +                 (TYPE_MAIN_VARIANT (TREE_TYPE (cur_param))
46 +                  != unsigned_type_node))
47 +               {
48 +                 status_warning (status, "bitmap is not type int (arg %d)",
49 +                                 arg_num);
50 +               }
51 +           }
52 +       }
53 +      if (*format_chars == 'D')
54 +       {
55 +         /* There should be an unsigned char * arg before the string arg.  */
56 +         if (params == 0)
57 +           {
58 +             status_warning (status, "too few arguments for format");
59 +             return;
60 +           }
61 +           if (info->first_arg_num != 0)
62 +           {
63 +             tree cur_type;
64 +
65 +             cur_param = TREE_VALUE (params);
66 +             params = TREE_CHAIN (params);
67 +             ++arg_num;
68 +             cur_type = TREE_TYPE (cur_param);
69 +             if (TREE_CODE (cur_type) != POINTER_TYPE
70 +                 || TYPE_MAIN_VARIANT (TREE_TYPE (cur_type))
71 +                    != unsigned_char_type_node)
72 +               {
73 +                 status_warning (status,
74 +                     "ethernet address is not type unsigned char * (arg %d)",
75 +                                 arg_num);
76 +               }
77 +           }
78 +        }
79 +
80        format_char = *format_chars;
81        if (format_char == 0
82           || (!(fki->flags & (int) FMT_FLAG_FANCY_PERCENT_OK)
83 @@ -2124,7 +2188,7 @@
84           else if (strchr (fci->flags2, '2') != 0)
85             y2k_level = 2;
86           if (y2k_level == 3)
87 -           status_warning (status, "`%%%c' yields only last 2 digits of year in some locales",
88 +           status_warning (status, "`%%%c' yields only last 2 digits of year in some locals on non-BSD systems",
89                             format_char);
90           else if (y2k_level == 2)
91             status_warning (status, "`%%%c' yields only last 2 digits of year", format_char);