~darkmuggle-deactivatedaccount/ubuntu/quantal/grub2/fix-872244

« back to all changes in this revision

Viewing changes to grub-core/normal/term.c

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2011-05-17 23:59:10 UTC
  • mto: (17.3.55 sid)
  • mto: This revision was merged to the branch mainline in revision 122.
  • Revision ID: james.westby@ubuntu.com-20110517235910-ma8u889vyjdfro27
Tags: upstream-1.99
ImportĀ upstreamĀ versionĀ 1.99

Show diffs side-by-side

added added

removed removed

Lines of Context:
515
515
                     const grub_uint32_t * last_position,
516
516
                     int margin_left, int margin_right,
517
517
                     struct grub_term_output *term,
518
 
                     struct term_state *state)
 
518
                     struct term_state *state,
 
519
                     int dry_run)
519
520
{
520
521
  const grub_uint32_t *ptr;
521
 
  grub_ssize_t startwidth = get_startwidth (term, margin_left);
 
522
  grub_ssize_t startwidth = dry_run ? 0 : get_startwidth (term, margin_left);
522
523
  grub_ssize_t line_width = startwidth;
523
524
  grub_ssize_t lastspacewidth = 0;
524
525
  grub_ssize_t max_width = get_maxwidth (term, margin_left, margin_right);
525
526
  const grub_uint32_t *line_start = str, *last_space = str - 1;
 
527
  int lines = 0;
526
528
 
527
529
  for (ptr = str; ptr < last_position; ptr++)
528
530
    {
552
554
          if (line_width > max_width && last_space > line_start)
553
555
            ptr = last_space;
554
556
          else if (line_width > max_width 
555
 
                   && line_start == str && startwidth != 0)
 
557
                   && line_start == str && line_width - lastspacewidth < max_width - 5)
556
558
            {
557
559
              ptr = str;
558
560
              lastspacewidth = startwidth;
560
562
          else
561
563
            lastspacewidth = line_width - last_width;
562
564
 
563
 
          for (ptr2 = line_start; ptr2 < ptr; ptr2++)
564
 
            {
565
 
              /* Skip combining characters on non-UTF8 terminals.  */
566
 
              if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) 
567
 
                  != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL
568
 
                  && grub_unicode_get_comb_type (*ptr2)
569
 
                  != GRUB_UNICODE_COMB_NONE)
570
 
                continue;
571
 
              putcode_real (*ptr2, term);
572
 
            }
573
 
 
574
 
          grub_print_spaces (term, margin_right);
575
 
          grub_putcode ('\n', term);
576
 
          if (state && ++state->num_lines
577
 
              >= (grub_ssize_t) grub_term_height (term) - 2)
578
 
            {
579
 
              state->backlog_ucs4 = (ptr == last_space || *ptr == '\n') 
580
 
                ? ptr + 1 : ptr;
581
 
              state->backlog_len = last_position - state->backlog_ucs4;
582
 
              return 1;
 
565
          lines++;
 
566
 
 
567
          if (!dry_run)
 
568
            {
 
569
              for (ptr2 = line_start; ptr2 < ptr; ptr2++)
 
570
                {
 
571
                  /* Skip combining characters on non-UTF8 terminals.  */
 
572
                  if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) 
 
573
                      != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL
 
574
                      && grub_unicode_get_comb_type (*ptr2)
 
575
                      != GRUB_UNICODE_COMB_NONE)
 
576
                    continue;
 
577
                  putcode_real (*ptr2, term);
 
578
                }
 
579
 
 
580
              grub_print_spaces (term, margin_right);
 
581
              grub_putcode ('\n', term);
 
582
              if (state && ++state->num_lines
 
583
                  >= (grub_ssize_t) grub_term_height (term) - 2)
 
584
                {
 
585
                  state->backlog_ucs4 = (ptr == last_space || *ptr == '\n') 
 
586
                    ? ptr + 1 : ptr;
 
587
                  state->backlog_len = last_position - state->backlog_ucs4;
 
588
                  return 1;
 
589
                }
583
590
            }
584
591
 
585
592
          line_width -= lastspacewidth;
586
 
          grub_print_spaces (term, margin_left);
 
593
          if (!dry_run)
 
594
            grub_print_spaces (term, margin_left);
587
595
          if (ptr == last_space || *ptr == '\n')
588
596
            ptr++;
589
597
          line_start = ptr;
590
598
        }
591
599
    }
592
600
 
593
 
  {
594
 
    const grub_uint32_t *ptr2;
595
 
    for (ptr2 = line_start; ptr2 < last_position; ptr2++)
596
 
      {
597
 
        /* Skip combining characters on non-UTF8 terminals.  */
598
 
        if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) 
599
 
            != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL
600
 
            && grub_unicode_get_comb_type (*ptr2)
601
 
            != GRUB_UNICODE_COMB_NONE)
602
 
          continue;
603
 
        putcode_real (*ptr2, term);
604
 
      }
605
 
  }
606
 
  return 0;
 
601
  if (line_start < last_position)
 
602
    lines++;
 
603
  if (!dry_run)
 
604
    {
 
605
      const grub_uint32_t *ptr2;
 
606
      for (ptr2 = line_start; ptr2 < last_position; ptr2++)
 
607
        {
 
608
          /* Skip combining characters on non-UTF8 terminals.  */
 
609
          if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) 
 
610
              != GRUB_TERM_CODE_TYPE_UTF8_LOGICAL
 
611
              && grub_unicode_get_comb_type (*ptr2)
 
612
              != GRUB_UNICODE_COMB_NONE)
 
613
            continue;
 
614
          putcode_real (*ptr2, term);
 
615
        }
 
616
    }
 
617
  return dry_run ? lines : 0;
607
618
}
608
619
 
609
620
static struct term_state *
672
683
      int ret;
673
684
      ret = print_ucs4_terminal (state->backlog_ucs4,
674
685
                                 state->backlog_ucs4 + state->backlog_len,
675
 
                                 margin_left, margin_right, term, state);
 
686
                                 margin_left, margin_right, term, state, 0);
676
687
      if (!ret)
677
688
        {
678
689
          grub_free (state->free);
706
717
print_ucs4_real (const grub_uint32_t * str,
707
718
                 const grub_uint32_t * last_position,
708
719
                 int margin_left, int margin_right,
709
 
                 struct grub_term_output *term, int backlog)
 
720
                 struct grub_term_output *term, int backlog,
 
721
                 int dry_run)
710
722
{
711
723
  struct term_state *state = NULL;
712
724
 
713
 
  if (backlog)
714
 
    state = find_term_state (term);
 
725
  if (!dry_run)
 
726
    {
 
727
      if (backlog)
 
728
        state = find_term_state (term);
715
729
 
716
 
  if (((term->getxy (term) >> 8) & 0xff) < margin_left)
717
 
    grub_print_spaces (term, margin_left - ((term->getxy (term) >> 8) & 0xff));
 
730
      if (((term->getxy (term) >> 8) & 0xff) < margin_left)
 
731
        grub_print_spaces (term, margin_left - ((term->getxy (term) >> 8) & 0xff));
 
732
    }
718
733
 
719
734
  if ((term->flags & GRUB_TERM_CODE_TYPE_MASK) 
720
735
      == GRUB_TERM_CODE_TYPE_VISUAL_GLYPHS
743
758
          grub_print_error ();
744
759
          return 0;
745
760
        }
746
 
      ret = put_glyphs_terminal (visual, visual_len, margin_left, margin_right,
747
 
                                 term, state);
748
 
      if (!ret)
749
 
        grub_free (visual);
 
761
      if (dry_run)
 
762
        {
 
763
          struct grub_unicode_glyph *vptr;
 
764
          ret = 0;
 
765
          for (vptr = visual; vptr < visual + visual_len; vptr++)
 
766
            if (vptr->base == '\n')
 
767
              ret++;
 
768
          if (visual_len && visual[visual_len - 1].base != '\n')
 
769
            ret++;
 
770
          grub_free (visual);
 
771
        }
750
772
      else
751
 
        state->free = visual;
 
773
        {
 
774
          ret = put_glyphs_terminal (visual, visual_len, margin_left,
 
775
                                     margin_right, term, state);
 
776
          if (!ret)
 
777
            grub_free (visual);
 
778
          else
 
779
            state->free = visual;
 
780
        }
752
781
      return ret;
753
782
    }
754
783
  return print_ucs4_terminal (str, last_position, margin_left, margin_right,
755
 
                              term, state);
 
784
                              term, state, dry_run);
756
785
}
757
786
 
758
787
void
762
791
                 struct grub_term_output *term)
763
792
{
764
793
  print_ucs4_real (str, last_position, margin_left, margin_right,
765
 
                   term, 0);
 
794
                   term, 0, 0);
766
795
}
767
796
 
 
797
int
 
798
grub_ucs4_count_lines (const grub_uint32_t * str,
 
799
                       const grub_uint32_t * last_position,
 
800
                       int margin_left, int margin_right,
 
801
                       struct grub_term_output *term)
 
802
{
 
803
  return print_ucs4_real (str, last_position, margin_left, margin_right,
 
804
                          term, 0, 1);
 
805
}
768
806
 
769
807
void
770
808
grub_xputs_normal (const char *str)
813
851
  {
814
852
    int cur;
815
853
    cur = print_ucs4_real (unicode_str, unicode_last_position, 0, 0,
816
 
                           term, grub_more);
 
854
                           term, grub_more, 0);
817
855
    if (cur)
818
856
      backlog = 1;
819
857
  }