comparison src/xdisp.c @ 52458:031533a680d7

(pint2hrstr): New function. (decode_mode_spec): Add `%i' and `%I' specs.
author Lute Kamstra <lute@gnu.org>
date Mon, 08 Sep 2003 07:51:08 +0000
parents cb455e3c2603
children a15080fc1b51
comparison
equal deleted inserted replaced
52457:6d5981c8551c 52458:031533a680d7
770 static int invisible_text_between_p P_ ((struct it *, int, int)); 770 static int invisible_text_between_p P_ ((struct it *, int, int));
771 #endif 771 #endif
772 772
773 static int next_element_from_ellipsis P_ ((struct it *)); 773 static int next_element_from_ellipsis P_ ((struct it *));
774 static void pint2str P_ ((char *, int, int)); 774 static void pint2str P_ ((char *, int, int));
775 static void pint2hrstr P_ ((char *, int, int));
775 static struct text_pos run_window_scroll_functions P_ ((Lisp_Object, 776 static struct text_pos run_window_scroll_functions P_ ((Lisp_Object,
776 struct text_pos)); 777 struct text_pos));
777 static void reconsider_clip_changes P_ ((struct window *, struct buffer *)); 778 static void reconsider_clip_changes P_ ((struct window *, struct buffer *));
778 static int text_outside_line_unchanged_p P_ ((struct window *, int, int)); 779 static int text_outside_line_unchanged_p P_ ((struct window *, int, int));
779 static void store_frame_title_char P_ ((char)); 780 static void store_frame_title_char P_ ((char));
15580 *buf++ = *p; 15581 *buf++ = *p;
15581 *p-- = d; 15582 *p-- = d;
15582 } 15583 }
15583 } 15584 }
15584 15585
15586 /* Write a null-terminated, right justified decimal and "human
15587 readable" representation of the nonnegative integer D to BUF using
15588 a minimal field width WIDTH. D should be smaller than 999.5e24. */
15589
15590 static const char power_letter[] =
15591 {
15592 0, /* not used */
15593 'k', /* kilo */
15594 'M', /* mega */
15595 'G', /* giga */
15596 'T', /* tera */
15597 'P', /* peta */
15598 'E', /* exa */
15599 'Z', /* zetta */
15600 'Y' /* yotta */
15601 };
15602
15603 static void
15604 pint2hrstr (buf, width, d)
15605 char *buf;
15606 int width;
15607 int d;
15608 {
15609 /* We aim to represent the nonnegative integer D as
15610 QUOTIENT.TENTHS * 10 ^ (3 * EXPONENT). */
15611 int quotient = d;
15612 int remainder = 0;
15613 /* -1 means: do not use TENTHS. */
15614 int tenths = -1;
15615 int exponent = 0;
15616
15617 /* Length of QUOTIENT.TENTHS as a string. */
15618 int length;
15619
15620 char * psuffix;
15621 char * p;
15622
15623 if (1000 <= quotient)
15624 {
15625 /* Scale to the appropriate EXPONENT. */
15626 do
15627 {
15628 remainder = quotient % 1000;
15629 quotient /= 1000;
15630 exponent++;
15631 }
15632 while (1000 <= quotient);
15633
15634 /* Round to nearest and decide whether to use TENTHS or not. */
15635 if (quotient <= 9)
15636 {
15637 tenths = remainder / 100;
15638 if (50 <= remainder % 100)
15639 if (tenths < 9)
15640 tenths++;
15641 else
15642 {
15643 quotient++;
15644 if (quotient == 10)
15645 tenths = -1;
15646 else
15647 tenths = 0;
15648 }
15649 }
15650 else
15651 if (500 <= remainder)
15652 if (quotient < 999)
15653 quotient++;
15654 else
15655 {
15656 quotient = 1;
15657 exponent++;
15658 tenths = 0;
15659 }
15660 }
15661
15662 /* Calculate the LENGTH of QUOTIENT.TENTHS as a string. */
15663 if (tenths == -1 && quotient <= 99)
15664 if (quotient <= 9)
15665 length = 1;
15666 else
15667 length = 2;
15668 else
15669 length = 3;
15670 p = psuffix = buf + max (width, length);
15671
15672 /* Print EXPONENT. */
15673 if (exponent)
15674 *psuffix++ = power_letter[exponent];
15675 *psuffix = '\0';
15676
15677 /* Print TENTHS. */
15678 if (tenths >= 0)
15679 {
15680 *--p = '0' + tenths;
15681 *--p = '.';
15682 }
15683
15684 /* Print QUOTIENT. */
15685 do
15686 {
15687 int digit = quotient % 10;
15688 *--p = '0' + digit;
15689 }
15690 while ((quotient /= 10) != 0);
15691
15692 /* Print leading spaces. */
15693 while (buf < p)
15694 *--p = ' ';
15695 }
15696
15585 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF. 15697 /* Set a mnemonic character for coding_system (Lisp symbol) in BUF.
15586 If EOL_FLAG is 1, set also a mnemonic character for end-of-line 15698 If EOL_FLAG is 1, set also a mnemonic character for end-of-line
15587 type of CODING_SYSTEM. Return updated pointer into BUF. */ 15699 type of CODING_SYSTEM. Return updated pointer into BUF. */
15588 15700
15589 static unsigned char invalid_eol_type[] = "(*invalid*)"; 15701 static unsigned char invalid_eol_type[] = "(*invalid*)";
15781 return "Emacs"; 15893 return "Emacs";
15782 15894
15783 case 'f': 15895 case 'f':
15784 obj = b->filename; 15896 obj = b->filename;
15785 break; 15897 break;
15898
15899 case 'i':
15900 {
15901 int size = ZV - BEGV;
15902 pint2str (decode_mode_spec_buf, field_width, size);
15903 return decode_mode_spec_buf;
15904 }
15905
15906 case 'I':
15907 {
15908 int size = ZV - BEGV;
15909 pint2hrstr (decode_mode_spec_buf, field_width, size);
15910 return decode_mode_spec_buf;
15911 }
15786 15912
15787 case 'l': 15913 case 'l':
15788 { 15914 {
15789 int startpos = XMARKER (w->start)->charpos; 15915 int startpos = XMARKER (w->start)->charpos;
15790 int startpos_byte = marker_byte_position (w->start); 15916 int startpos_byte = marker_byte_position (w->start);