Print formatted output line. Uses mostly arbitrary field sizes, probably will need tweaking if any of the localization stuff is done, or for 64 bit pids, etc. */
| 224 | will need tweaking if any of the localization stuff is done, or for 64 bit |
| 225 | pids, etc. */ |
| 226 | static void |
| 227 | print_line (char const *user, const char state, |
| 228 | char const *line, |
| 229 | char const *time_str, char const *idle, char const *pid, |
| 230 | char const *comment, char const *exitstr) |
| 231 | { |
| 232 | static char mesg[3] = { ' ', 'x', '\0' }; |
| 233 | char *buf; |
| 234 | char x_idle[1 + IDLESTR_LEN + 1]; |
| 235 | char x_pid[1 + INT_STRLEN_BOUND (pid_t) + 1]; |
| 236 | char *x_exitstr; |
| 237 | |
| 238 | mesg[1] = state; |
| 239 | |
| 240 | if (include_idle && !short_output && strlen (idle) < sizeof x_idle - 1) |
| 241 | sprintf (x_idle, " %-6s", idle); |
| 242 | else |
| 243 | *x_idle = '\0'; |
| 244 | |
| 245 | if (!short_output && strlen (pid) < sizeof x_pid - 1) |
| 246 | sprintf (x_pid, " %10s", pid); |
| 247 | else |
| 248 | *x_pid = '\0'; |
| 249 | |
| 250 | x_exitstr = xmalloc (include_exit ? 1 + MAX (12, strlen (exitstr)) + 1 : 1); |
| 251 | if (include_exit) |
| 252 | sprintf (x_exitstr, " %-12s", exitstr); |
| 253 | else |
| 254 | *x_exitstr = '\0'; |
| 255 | |
| 256 | buf = xasprintf ("%-8s" |
| 257 | "%s" |
| 258 | " %-12s" |
| 259 | " %-*s" |
| 260 | "%s" |
| 261 | "%s" |
| 262 | " %-8s" |
| 263 | "%s" |
| 264 | , |
| 265 | user ? user : " .", |
| 266 | include_mesg ? mesg : "", |
| 267 | line, |
| 268 | time_format_width, |
| 269 | time_str, |
| 270 | x_idle, |
| 271 | x_pid, |
| 272 | /* FIXME: it's not really clear whether the following |
| 273 | field should be in the short_output. A strict reading |
| 274 | of SUSv2 would suggest not, but I haven't seen any |
| 275 | implementations that actually work that way... */ |
| 276 | comment, |
| 277 | x_exitstr |
| 278 | ); |
| 279 | |
| 280 | { |
| 281 | /* Remove any trailing spaces. */ |
| 282 | char *p = buf + strlen (buf); |
| 283 | while (*--p == ' ') |
no outgoing calls
no test coverage detected