72 char mod = '\0'; |
72 char mod = '\0'; |
73 |
73 |
74 // handle modifiers |
74 // handle modifiers |
75 if (fmt[pos + ofs] == 's' || fmt[pos + ofs] == 'x') |
75 if (fmt[pos + ofs] == 's' || fmt[pos + ofs] == 'x') |
76 { |
76 { |
77 mod = fmt[ pos + ofs ]; |
77 mod = fmt[pos + ofs]; |
78 ofs++; |
78 ofs++; |
79 } |
79 } |
80 |
80 |
81 if (!isdigit (fmt[pos + ofs])) |
81 if (!isdigit (fmt[pos + ofs])) |
82 { |
82 { |
83 fprintf (stderr, "bad format string, expected digit with optional " |
83 fprintf (stderr, "bad format string, expected digit with optional " |
84 "modifier after '%%':\n"); |
84 "modifier after '%%':\n"); |
85 draw_pos (fmt, pos); |
85 draw_pos (fmt, pos); |
86 return fmt; |
86 return fmt; |
87 } |
87 } |
88 |
88 |
89 int i = fmt[pos + ofs] - '0'; |
89 int i = fmt[pos + ofs] - '0'; |
94 return fmt; |
94 return fmt; |
95 } |
95 } |
96 |
96 |
97 string repl = args[i].as_string(); |
97 string repl = args[i].as_string(); |
98 |
98 |
99 if (mod == 's') |
99 switch (mod) |
100 { |
100 { |
101 repl = (repl == "1") ? "" : "s"; |
101 case 's': repl = (repl == "1") ? "" : "s"; break; |
102 } |
102 case 'd': repl.sprintf ("%d", repl[0]); break; |
103 |
103 case 'x': repl.sprintf ("0x%X", repl.to_long()); break; |
104 elif (mod == 'd') |
104 default: break; |
105 { |
|
106 repl.sprintf ("%d", repl[0]); |
|
107 } |
|
108 elif (mod == 'x') |
|
109 { |
|
110 // modifier x: reinterpret the argument as hex |
|
111 repl.sprintf ("0x%X", strtol (repl.chars(), null, 10)); |
|
112 } |
105 } |
113 |
106 |
114 fmt.replace (pos, 1 + ofs, repl); |
107 fmt.replace (pos, 1 + ofs, repl); |
115 pos += repl.length(); |
108 pos += repl.length(); |
116 } |
109 } |