Changeset 1935
- Timestamp:
- Oct 25, 2008, 5:04:06 PM (17 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/function.c
r1934 r1935 1678 1678 return o; 1679 1679 } 1680 1681 /* Optimizes the content of one or more variables to save time in 1682 the eval functions. This function will collapse line continuations 1683 and remove comments. */ 1684 static char * 1685 func_eval_optimize_variable (char *o, char **argv, const char *funcname) 1686 { 1687 unsigned int i; 1688 1689 for (i = 0; argv[i]; i++) 1690 { 1691 struct variable *v = lookup_variable (argv[i], strlen (argv[i])); 1692 if (v && !v->rdonly_val) 1693 { 1694 char *eos, *src; 1695 1696 eos = collapse_continuations (v->value, v->value_length); 1697 v->value_length = eos - v->value; 1698 1699 /* remove comments */ 1700 1701 src = memchr (v->value, '#', v->value_length); 1702 if (src) 1703 { 1704 unsigned char ch; 1705 char *dst = src; 1706 do 1707 { 1708 /* drop blanks preceeding the comment */ 1709 while (dst > v->value) 1710 { 1711 ch = (unsigned char)dst[-1]; 1712 if (!isblank (ch)) 1713 break; 1714 dst--; 1715 } 1716 1717 /* advance SRC to eol / eos. */ 1718 src = memchr (src, '\n', eos - src); 1719 if (!src) 1720 break; 1721 1722 /* drop a preceeding newline if possible (full line comment) */ 1723 if (dst > v->value && dst[-1] == '\n') 1724 dst--; 1725 1726 /* copy till next comment or eol. */ 1727 while (src < eos) 1728 { 1729 ch = *src++; 1730 if (ch == '#') 1731 break; 1732 *dst++ = ch; 1733 } 1734 } 1735 while (ch == '#' && src < eos); 1736 1737 *dst = '\0'; 1738 v->value_length = dst - v->value; 1739 } 1740 } 1741 } 1742 1743 return o; 1744 } 1745 1680 1746 #endif /* CONFIG_WITH_EVALPLUS */ 1681 1747 … … 4457 4523 { STRING_SIZE_TUPLE("evalcall"), 1, 0, 1, func_call}, 4458 4524 { STRING_SIZE_TUPLE("evalcall2"), 1, 0, 1, func_call}, 4525 { STRING_SIZE_TUPLE("eval-opt-var"), 1, 0, 1, func_eval_optimize_variable}, 4459 4526 #endif 4460 4527 #ifdef EXPERIMENTAL -
trunk/src/kmk/misc.c
r1925 r1935 112 112 if (in == 0) 113 113 return line + linelen; 114 if (in == line || in[-1] != '\\') 115 { 116 do 117 { 118 unsigned int off_in = in - line; 119 if (off_in == linelen) 120 return in; 121 in = memchr (in + 1, '\n', linelen - off_in - 1); 122 if (in == 0) 123 return line + linelen; 124 } 125 while (in[-1] != '\\'); 126 } 114 127 #endif 115 128 -
trunk/src/kmk/variable.c
r1934 r1935 1205 1205 " expr if-expr" 1206 1206 " which" 1207 " evalctx evalval evalvalctx evalcall evalcall2 "1207 " evalctx evalval evalvalctx evalcall evalcall2 eval-opt-var" 1208 1208 " make-stats" 1209 1209 " commands" … … 1259 1259 # endif 1260 1260 # if defined (CONFIG_WITH_EVALPLUS) 1261 strcat (buf, " evalctx evalval evalvalctx evalcall evalcall2 ");1261 strcat (buf, " evalctx evalval evalvalctx evalcall evalcall2 eval-opt-var"); 1262 1262 # endif 1263 1263 # if defined (CONFIG_WITH_MAKE_STATS) || defined (CONFIG_WITH_MINIMAL_STATS)
Note:
See TracChangeset
for help on using the changeset viewer.