Mercurial > hg > octave-lyh
comparison src/utils.cc @ 1358:dc9c01f66a19
[project @ 1995-09-05 21:10:01 by jwe]
author | jwe |
---|---|
date | Tue, 05 Sep 1995 21:12:04 +0000 |
parents | 19c10b8657d5 |
children | ed5757e3333b |
comparison
equal
deleted
inserted
replaced
1357:749071f48336 | 1358:dc9c01f66a19 |
---|---|
400 | 400 |
401 i++; | 401 i++; |
402 | 402 |
403 if (i == num_max - 1) | 403 if (i == num_max - 1) |
404 { | 404 { |
405 // Reallocate the array. Only copy pointers, not the strings they | 405 // Reallocate the array. Only copy pointers, not |
406 // point to, then only delete the original array of pointers, and not | 406 // the strings they point to, then only delete the |
407 // the strings they point to. | 407 // original array of pointers, and not the strings |
408 // they point to. | |
408 | 409 |
409 num_max += 256; | 410 num_max += 256; |
410 char **tmp = new char * [num_max]; | 411 char **tmp = new char * [num_max]; |
411 for (int j = 0; j < i; j++) | 412 for (int j = 0; j < i; j++) |
412 tmp[j] = retval[j]; | 413 tmp[j] = retval[j]; |
449 int tmp_num; | 450 int tmp_num; |
450 char **names = get_fcn_file_names (tmp_num, elt_dir, no_suffix); | 451 char **names = get_fcn_file_names (tmp_num, elt_dir, no_suffix); |
451 | 452 |
452 if (i + tmp_num >= num_max - 1) | 453 if (i + tmp_num >= num_max - 1) |
453 { | 454 { |
454 // Reallocate the array. Only copy pointers, not the strings they | 455 // Reallocate the array. Only copy pointers, not |
455 // point to, then only delete the original array of pointers, and not | 456 // the strings they point to, then only delete the |
456 // the strings they point to. | 457 // original array of pointers, and not the strings |
458 // they point to. | |
457 | 459 |
458 num_max += 1024; | 460 num_max += 1024; |
459 char **tmp = new char * [num_max]; | 461 char **tmp = new char * [num_max]; |
460 for (int j = 0; j < i; j++) | 462 for (int j = 0; j < i; j++) |
461 tmp[j] = retval[j]; | 463 tmp[j] = retval[j]; |
566 // should maybe be in utils.cc. | 568 // should maybe be in utils.cc. |
567 | 569 |
568 ostrstream& | 570 ostrstream& |
569 list_in_columns (ostrstream& os, char **list) | 571 list_in_columns (ostrstream& os, char **list) |
570 { | 572 { |
571 // Compute the maximum name length. | 573 // Compute the maximum name length. |
572 | 574 |
573 int max_name_length = 0; | 575 int max_name_length = 0; |
574 int total_names = 0; | 576 int total_names = 0; |
575 char **names = 0; | 577 char **names = 0; |
576 for (names = list; *names; names++) | 578 for (names = list; *names; names++) |
579 int name_length = strlen (*names); | 581 int name_length = strlen (*names); |
580 if (name_length > max_name_length) | 582 if (name_length > max_name_length) |
581 max_name_length = name_length; | 583 max_name_length = name_length; |
582 } | 584 } |
583 | 585 |
584 // Allow at least two spaces between names. | 586 // Allow at least two spaces between names. |
585 | 587 |
586 max_name_length += 2; | 588 max_name_length += 2; |
587 | 589 |
588 // Calculate the maximum number of columns that will fit. | 590 // Calculate the maximum number of columns that will fit. |
589 | 591 |
590 int line_length = terminal_columns (); | 592 int line_length = terminal_columns (); |
591 int cols = line_length / max_name_length; | 593 int cols = line_length / max_name_length; |
592 if (cols == 0) | 594 if (cols == 0) |
593 cols = 1; | 595 cols = 1; |
594 | 596 |
595 // Calculate the number of rows that will be in each column except | 597 // Calculate the number of rows that will be in each column except |
596 // possibly for a short column on the right. | 598 // possibly for a short column on the right. |
597 | 599 |
598 int rows = total_names / cols + (total_names % cols != 0); | 600 int rows = total_names / cols + (total_names % cols != 0); |
599 | 601 |
600 // Recalculate columns based on rows. | 602 // Recalculate columns based on rows. |
601 | 603 |
602 cols = total_names / rows + (total_names % rows != 0); | 604 cols = total_names / rows + (total_names % rows != 0); |
603 | 605 |
604 names = list; | 606 names = list; |
605 int count; | 607 int count; |
606 for (int row = 0; row < rows; row++) | 608 for (int row = 0; row < rows; row++) |
607 { | 609 { |
608 count = row; | 610 count = row; |
609 int pos = 0; | 611 int pos = 0; |
610 | 612 |
611 // Print the next row. | 613 // Print the next row. |
612 | 614 |
613 while (1) | 615 while (1) |
614 { | 616 { |
615 os << *(names + count); | 617 os << *(names + count); |
616 int name_length = strlen (*(names + count)); | 618 int name_length = strlen (*(names + count)); |