~ubuntu-branches/ubuntu/trusty/grub2/trusty-updates

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2012-09-13 18:02:04 UTC
  • mfrom: (1.17.15 upstream)
  • mto: (17.6.27 experimental)
  • mto: This revision was merged to the branch mainline in revision 145.
  • Revision ID: package-import@ubuntu.com-20120913180204-mojnmocbimlom4im
Tags: upstream-2.00
ImportĀ upstreamĀ versionĀ 2.00

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <grub/env.h>
25
25
#include <grub/normal.h>
26
26
#include <grub/charset.h>
 
27
#include <grub/i18n.h>
27
28
 
28
29
struct term_state
29
30
{
30
31
  struct term_state *next;
31
32
  const struct grub_unicode_glyph *backlog_glyphs;
32
33
  const grub_uint32_t *backlog_ucs4;
 
34
  int backlog_fixed_tab;
33
35
  grub_size_t backlog_len;
34
36
 
35
37
  void *free;
37
39
  char *term_name;
38
40
};
39
41
 
 
42
static int
 
43
print_ucs4_real (const grub_uint32_t * str,
 
44
                 const grub_uint32_t * last_position,
 
45
                 int margin_left, int margin_right,
 
46
                 struct grub_term_output *term, int backlog,
 
47
                 int dry_run, int fixed_tab);
 
48
 
40
49
static struct term_state *term_states = NULL;
41
50
 
42
51
/* If the more pager is active.  */
43
52
static int grub_more;
44
53
 
45
54
static void
46
 
putcode_real (grub_uint32_t code, struct grub_term_output *term);
 
55
putcode_real (grub_uint32_t code, struct grub_term_output *term, int fixed_tab);
47
56
 
48
57
void
49
58
grub_normal_reset_more (void)
63
72
 
64
73
  pos = grub_term_save_pos ();
65
74
 
66
 
  grub_utf8_to_ucs4_alloc ("--MORE--", &unicode_str,
 
75
  /* TRANSLATORS: This has to fit on one line.  It's ok to include few
 
76
     words but don't write poems.  */
 
77
  grub_utf8_to_ucs4_alloc (_("--MORE--"), &unicode_str,
67
78
                           &unicode_last_position);
68
79
 
69
80
  if (!unicode_str)
232
243
      return;
233
244
    }
234
245
 
235
 
  grub_print_ucs4 (unicode_str, unicode_last_position, 0, 0, term);
 
246
  print_ucs4_real (unicode_str, unicode_last_position, 0, 0, term, 0, 0, 0);
236
247
  grub_free (unicode_str);
237
248
}
238
249
 
305
316
      return;
306
317
    }
307
318
  
308
 
  filename = grub_xasprintf ("%s/terminal.lst", prefix);
 
319
  filename = grub_xasprintf ("%s/" GRUB_TARGET_CPU "-" GRUB_PLATFORM
 
320
                             "/terminal.lst", prefix);
309
321
  if (!filename)
310
322
    {
311
323
      grub_errno = GRUB_ERR_NONE;
334
346
      if (! buf)
335
347
        break;
336
348
 
337
 
      switch (buf[0])
 
349
      p = buf;
 
350
      while (grub_isspace (p[0]))
 
351
        p++;
 
352
 
 
353
      switch (p[0])
338
354
        {
339
355
        case 'i':
340
356
          target = &grub_term_input_autoload;
347
363
      if (!target)
348
364
        continue;
349
365
      
350
 
      name = buf + 1;
 
366
      name = p + 1;
351
367
            
352
368
      p = grub_strchr (name, ':');
353
369
      if (! p)
354
370
        continue;
355
 
      
356
 
      *p = '\0';
357
 
      while (*++p == ' ')
358
 
        ;
 
371
      *p = 0;
 
372
 
 
373
      p++;
 
374
      while (*p == ' ' || *p == '\t')
 
375
        p++;
359
376
 
360
377
      cur = grub_malloc (sizeof (*cur));
361
378
      if (!cur)
390
407
}
391
408
 
392
409
static void
393
 
putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term)
 
410
putglyph (const struct grub_unicode_glyph *c, struct grub_term_output *term,
 
411
          int fixed_tab)
394
412
{
395
413
  struct grub_unicode_glyph c2 =
396
414
    {
401
419
      .estimated_width = 1
402
420
    };
403
421
 
 
422
  if (c->base == '\t' && fixed_tab)
 
423
    {
 
424
      int n;
 
425
 
 
426
      n = GRUB_TERM_TAB_WIDTH;
 
427
      c2.base = ' ';
 
428
      while (n--)
 
429
        (term->putchar) (term, &c2);
 
430
 
 
431
      return;
 
432
    }
 
433
 
404
434
  if (c->base == '\t' && term->getxy)
405
435
    {
406
436
      int n;
407
437
 
408
 
      n = 8 - ((term->getxy (term) >> 8) & 7);
 
438
      n = GRUB_TERM_TAB_WIDTH - ((term->getxy (term) >> 8)
 
439
                                 % GRUB_TERM_TAB_WIDTH);
409
440
      c2.base = ' ';
410
441
      while (n--)
411
442
        (term->putchar) (term, &c2);
461
492
}
462
493
 
463
494
static void
464
 
putcode_real (grub_uint32_t code, struct grub_term_output *term)
 
495
putcode_real (grub_uint32_t code, struct grub_term_output *term, int fixed_tab)
465
496
{
466
497
  struct grub_unicode_glyph c =
467
498
    {
473
504
    };
474
505
 
475
506
  c.base = map_code (code, term);
476
 
  putglyph (&c, term);
 
507
  putglyph (&c, term, fixed_tab);
477
508
}
478
509
 
479
510
/* Put a Unicode character.  */
484
515
  if (grub_unicode_get_comb_type (code) != GRUB_UNICODE_COMB_NONE)
485
516
    return;
486
517
 
487
 
  putcode_real (code, term);
 
518
  putcode_real (code, term, 0);
488
519
}
489
520
 
490
521
static grub_ssize_t
516
547
                     int margin_left, int margin_right,
517
548
                     struct grub_term_output *term,
518
549
                     struct term_state *state,
519
 
                     int dry_run)
 
550
                     int dry_run, int fixed_tab)
520
551
{
521
552
  const grub_uint32_t *ptr;
522
553
  grub_ssize_t startwidth = dry_run ? 0 : get_startwidth (term, margin_left);
574
605
                      && grub_unicode_get_comb_type (*ptr2)
575
606
                      != GRUB_UNICODE_COMB_NONE)
576
607
                    continue;
577
 
                  putcode_real (*ptr2, term);
 
608
                  putcode_real (*ptr2, term, fixed_tab);
578
609
                }
579
610
 
580
611
              grub_print_spaces (term, margin_right);
585
616
                  state->backlog_ucs4 = (ptr == last_space || *ptr == '\n') 
586
617
                    ? ptr + 1 : ptr;
587
618
                  state->backlog_len = last_position - state->backlog_ucs4;
 
619
                  state->backlog_fixed_tab = fixed_tab;
588
620
                  return 1;
589
621
                }
590
622
            }
611
643
              && grub_unicode_get_comb_type (*ptr2)
612
644
              != GRUB_UNICODE_COMB_NONE)
613
645
            continue;
614
 
          putcode_real (*ptr2, term);
 
646
          putcode_real (*ptr2, term, fixed_tab);
615
647
        }
616
648
    }
617
649
  return dry_run ? lines : 0;
644
676
                     grub_ssize_t visual_len,
645
677
                     int margin_left, int margin_right,
646
678
                     struct grub_term_output *term,
647
 
                     struct term_state *state)
 
679
                     struct term_state *state, int fixed_tab)
648
680
{
649
681
  const struct grub_unicode_glyph *visual_ptr;
650
682
  for (visual_ptr = visual; visual_ptr < visual + visual_len; visual_ptr++)
651
683
    {
652
684
      if (visual_ptr->base == '\n')
653
685
        grub_print_spaces (term, margin_right);
654
 
      putglyph (visual_ptr, term);
 
686
      putglyph (visual_ptr, term, fixed_tab);
655
687
      if (visual_ptr->base == '\n')
656
688
        {
657
689
          if (state && ++state->num_lines
659
691
            {
660
692
              state->backlog_glyphs = visual_ptr + 1;
661
693
              state->backlog_len = visual_len - (visual_ptr - visual) - 1;
 
694
              state->backlog_fixed_tab = fixed_tab;
662
695
              return 1;
663
696
            }
664
697
 
683
716
      int ret;
684
717
      ret = print_ucs4_terminal (state->backlog_ucs4,
685
718
                                 state->backlog_ucs4 + state->backlog_len,
686
 
                                 margin_left, margin_right, term, state, 0);
 
719
                                 margin_left, margin_right, term, state, 0,
 
720
                                 state->backlog_fixed_tab);
687
721
      if (!ret)
688
722
        {
689
723
          grub_free (state->free);
699
733
      int ret;
700
734
      ret = put_glyphs_terminal (state->backlog_glyphs,
701
735
                                 state->backlog_len,
702
 
                                 margin_left, margin_right, term, state);
 
736
                                 margin_left, margin_right, term, state,
 
737
                                 state->backlog_fixed_tab);
703
738
      if (!ret)
704
739
        {
705
740
          grub_free (state->free);
718
753
                 const grub_uint32_t * last_position,
719
754
                 int margin_left, int margin_right,
720
755
                 struct grub_term_output *term, int backlog,
721
 
                 int dry_run)
 
756
                 int dry_run, int fixed_tab)
722
757
{
723
758
  struct term_state *state = NULL;
724
759
 
772
807
      else
773
808
        {
774
809
          ret = put_glyphs_terminal (visual, visual_len, margin_left,
775
 
                                     margin_right, term, state);
 
810
                                     margin_right, term, state, fixed_tab);
776
811
          if (!ret)
777
812
            grub_free (visual);
778
813
          else
781
816
      return ret;
782
817
    }
783
818
  return print_ucs4_terminal (str, last_position, margin_left, margin_right,
784
 
                              term, state, dry_run);
 
819
                              term, state, dry_run, fixed_tab);
785
820
}
786
821
 
787
822
void
791
826
                 struct grub_term_output *term)
792
827
{
793
828
  print_ucs4_real (str, last_position, margin_left, margin_right,
794
 
                   term, 0, 0);
 
829
                   term, 0, 0, 1);
795
830
}
796
831
 
797
832
int
801
836
                       struct grub_term_output *term)
802
837
{
803
838
  return print_ucs4_real (str, last_position, margin_left, margin_right,
804
 
                          term, 0, 1);
 
839
                          term, 0, 1, 1);
805
840
}
806
841
 
807
842
void
851
886
  {
852
887
    int cur;
853
888
    cur = print_ucs4_real (unicode_str, unicode_last_position, 0, 0,
854
 
                           term, grub_more, 0);
 
889
                           term, grub_more, 0, 0);
855
890
    if (cur)
856
891
      backlog = 1;
857
892
  }