aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLute Kamstra2003-09-08 07:51:08 +0000
committerLute Kamstra2003-09-08 07:51:08 +0000
commit525b8b09830b549e6c1b89729a915f64934f77bf (patch)
tree3b2cd84fa76b2abb63d97a2eec8665d02bc063a5 /src
parent16dbbed6b98f8c358891f6b9f2bccbb24aa9c302 (diff)
downloademacs-525b8b09830b549e6c1b89729a915f64934f77bf.tar.gz
emacs-525b8b09830b549e6c1b89729a915f64934f77bf.zip
(pint2hrstr): New function.
(decode_mode_spec): Add `%i' and `%I' specs.
Diffstat (limited to 'src')
-rw-r--r--src/xdisp.c126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/xdisp.c b/src/xdisp.c
index 6a1cba06a52..629d210daa8 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -772,6 +772,7 @@ static int invisible_text_between_p P_ ((struct it *, int, int));
772 772
773static int next_element_from_ellipsis P_ ((struct it *)); 773static int next_element_from_ellipsis P_ ((struct it *));
774static void pint2str P_ ((char *, int, int)); 774static void pint2str P_ ((char *, int, int));
775static void pint2hrstr P_ ((char *, int, int));
775static struct text_pos run_window_scroll_functions P_ ((Lisp_Object, 776static struct text_pos run_window_scroll_functions P_ ((Lisp_Object,
776 struct text_pos)); 777 struct text_pos));
777static void reconsider_clip_changes P_ ((struct window *, struct buffer *)); 778static void reconsider_clip_changes P_ ((struct window *, struct buffer *));
@@ -15582,6 +15583,117 @@ pint2str (buf, width, 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
15590static 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
15603static void
15604pint2hrstr (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. */
@@ -15784,6 +15896,20 @@ decode_mode_spec (w, c, field_width, precision, multibyte)
15784 obj = b->filename; 15896 obj = b->filename;
15785 break; 15897 break;
15786 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 }
15912
15787 case 'l': 15913 case 'l':
15788 { 15914 {
15789 int startpos = XMARKER (w->start)->charpos; 15915 int startpos = XMARKER (w->start)->charpos;