Changeset 1243
- Timestamp:
- 09/05/08 01:24:43 (3 months ago)
- Files:
-
- 1.8.3/branches/devel/game/txt/hlp/pennfunc.hlp (modified) (1 diff)
- 1.8.3/branches/devel/src/funmath.c (modified) (4 diffs)
- 1.8.3/branches/devel/src/tables.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/devel/game/txt/hlp/pennfunc.hlp
r1240 r1243 580 580 581 581 Converts <number>, which is in base <from base> into base <to base>. 582 The bases can be between 2 (binary) and 36. 582 The bases can be between 2 (binary) and 64, inclusive. 583 584 All bases over 64 use base64 url string: 585 586 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_" 587 588 But using base64 as a 'from' will also understand + as 61 and / as 62. 583 589 & BEEP() 584 590 beep([<number>]) 1.8.3/branches/devel/src/funmath.c
r1177 r1243 1108 1108 FUNCTION(fun_log) 1109 1109 { 1110 NVAL num, base; 1110 NVAL num; 1111 NVAL base = 10.0; 1111 1112 bool base_is_e = false; 1112 1113 … … 1129 1130 if (nargs == 2) { 1130 1131 if (!is_number(args[1])) { 1131 if (args[1][0] == 'e' && args[1][1] == '\0') 1132 if (args[1][0] == 'e' && args[1][1] == '\0') { 1132 1133 base_is_e = true; 1133 else {1134 } else { 1134 1135 safe_str(T(e_nums), buff, bp); 1135 1136 return; … … 1775 1776 } 1776 1777 1778 extern char from_base_64[256]; 1779 extern char to_base_64[]; 1780 1781 extern char from_base_36[256]; 1782 extern char to_base_36[]; 1783 1777 1784 FUNCTION(fun_baseconv) 1778 1785 { 1779 1786 long n; 1787 int m; 1780 1788 int from, to; 1781 char *end; 1789 char *ptr; 1790 char numbuff[BUFFER_LEN], *nbp; 1791 1792 1793 // Base 36 by default. 1794 char *frombase = from_base_36; 1795 char *tobase = to_base_36; 1782 1796 1783 1797 if (!(is_integer(args[1]) && is_integer(args[2]))) { … … 1786 1800 } 1787 1801 1788 from = strtol(args[1], NULL, 10);1789 to = strtol(args[2], NULL, 10);1790 1791 if (from < 2 || from > 36) {1802 from = parse_integer(args[1]); 1803 to = parse_integer(args[2]); 1804 1805 if (from < 2 || from > 64) { 1792 1806 safe_str(T("#-1 FROM BASE OUT OF RANGE"), buff, bp); 1793 1807 return; 1794 1808 } 1795 1809 1796 if (to < 2 || to > 36) { 1810 if (from > 36) { 1811 frombase = from_base_64; 1812 } 1813 1814 if (to < 2 || to > 64) { 1797 1815 safe_str(T("#-1 TO BASE OUT OF RANGE"), buff, bp); 1798 1816 return; 1799 1817 } 1800 1818 1801 n = strtol(trim_space_sep(args[0], ' '), &end, from); 1802 1803 if (*end != '\0') { 1804 safe_str(T("#-1 MALFORMED NUMBER"), buff, bp); 1805 return; 1806 } 1807 1808 format_long(n, buff, bp, BUFFER_LEN, to); 1819 if (to > 36) { 1820 tobase = to_base_64; 1821 } 1822 1823 // Parse it. 1824 ptr = trim_space_sep(args[0], ' '); 1825 n = 0; 1826 while (ptr && *ptr) { 1827 n *= from; 1828 if (frombase[(unsigned char) *ptr] >= 0) { 1829 n += frombase[(unsigned char) *ptr]; 1830 ptr++; 1831 } else { 1832 safe_str(T("#-1 MALFORMED NUMBER"), buff, bp); 1833 return; 1834 } 1835 } 1836 1837 // Handle the 0-case. (And quickly handle < to_base case, too!) 1838 if (n < to) { 1839 safe_chr(tobase[(unsigned char) n], buff, bp); 1840 return; 1841 } 1842 1843 nbp = numbuff; 1844 1845 // This comes out backwards. 1846 while (n > 0) { 1847 m = n % to; 1848 n = n / to; 1849 safe_chr(tobase[(unsigned char) m], numbuff, &nbp); 1850 } 1851 1852 // Reverse back onto buff. 1853 nbp--; 1854 while (nbp >= numbuff) { 1855 safe_chr(*nbp, buff, bp); 1856 nbp--; 1857 } 1809 1858 } 1810 1859 1.8.3/branches/devel/src/tables.c
r1239 r1243 21 21 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 22 22 }; 23 24 char from_base_64[256] = { 25 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 26 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 27 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, 62, -1, 63, 28 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, 29 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 30 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, 63, 31 -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 32 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1, 33 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 34 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 35 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 36 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 37 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 38 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 39 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 40 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 41 }; 42 43 char to_base_64[] = 44 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; 45 46 char from_base_36[256] = { 47 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 48 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 49 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 50 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, 51 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 52 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, 53 -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 54 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, 55 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 56 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 57 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 58 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 59 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 60 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 61 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 63 }; 64 65 char to_base_36[] = "0123456789abcdefghijklmnopqrstuvwxyz"; 23 66 24 67 char active_table[256] = {
