* Set the information buffer size to count lines. We do this by creating * a circular linked list of elements, each of which represents a line of * text. New buffers are created as needed, old ones are freed if they * are no longer used. */
| 282 | * are no longer used. |
| 283 | */ |
| 284 | static void |
| 285 | set_circle_buf(struct mesg_info_t *mesg_info, int count) |
| 286 | { |
| 287 | int i; |
| 288 | struct line_element *tail, *curr, *head; |
| 289 | |
| 290 | if (count < 0) |
| 291 | panic("set_circle_buf: bad count [= %d]", count); |
| 292 | if (count == mesg_info->num_lines) |
| 293 | return; /* no change in size */ |
| 294 | |
| 295 | if (count < mesg_info->num_lines) { |
| 296 | /* |
| 297 | * Toss num_lines - count line entries from our circular list. |
| 298 | * |
| 299 | * We lose lines from the front (top) of the list. We _know_ |
| 300 | * the list is non_empty. |
| 301 | */ |
| 302 | tail = get_previous(mesg_info->head); |
| 303 | for (i = mesg_info->num_lines - count; i > 0; i--) { |
| 304 | curr = mesg_info->head; |
| 305 | mesg_info->head = curr->next; |
| 306 | if (curr->line) |
| 307 | free((genericptr_t) curr->line); |
| 308 | free((genericptr_t) curr); |
| 309 | } |
| 310 | if (count == 0) { |
| 311 | /* make sure we don't have a dangling pointer */ |
| 312 | mesg_info->head = (struct line_element *) 0; |
| 313 | } else { |
| 314 | tail->next = mesg_info->head; /* link the tail to the head */ |
| 315 | } |
| 316 | } else { |
| 317 | /* |
| 318 | * Add count - num_lines blank lines to the head of the list. |
| 319 | * |
| 320 | * Create a separate list, keeping track of the tail. |
| 321 | */ |
| 322 | for (head = tail = 0, i = 0; i < count - mesg_info->num_lines; i++) { |
| 323 | curr = (struct line_element *) alloc(sizeof(struct line_element)); |
| 324 | curr->line = 0; |
| 325 | curr->buf_length = 0; |
| 326 | curr->str_length = 0; |
| 327 | if (tail) { |
| 328 | tail->next = curr; |
| 329 | tail = curr; |
| 330 | } else { |
| 331 | head = tail = curr; |
| 332 | } |
| 333 | } |
| 334 | /* |
| 335 | * Complete the circle by making the new tail point to the old head |
| 336 | * and the old tail point to the new head. If our line count was |
| 337 | * zero, then make the new list circular. |
| 338 | */ |
| 339 | if (mesg_info->num_lines) { |
| 340 | curr = get_previous(mesg_info->head); /* get end of old list */ |
| 341 |
no test coverage detected