Changeset 2012 in kBuild
- Timestamp:
- Nov 1, 2008 2:27:34 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kbuild.c
r2011 r2012 2357 2357 struct kbet_prop 2358 2358 { 2359 const char *pch; 2359 2360 unsigned int cch; 2360 const char *pch; 2361 enum kbet_prop_enum { kPropSingle, kPropDeferred, kPropAccumulateL, kPropAccumulateR } 2362 enmType; 2361 2363 } *paProps; 2362 2364 unsigned int cProps; 2363 2365 unsigned int iProp; 2364 unsigned int iPropsSingle;2365 unsigned int iPropsSingleEnd;2366 unsigned int iPropsDeferred;2367 unsigned int iPropsDeferredEnd;2368 unsigned int iPropsAccumulateL;2369 unsigned int iPropsAccumulateLEnd;2370 unsigned int iPropsAccumulateR;2371 unsigned int iPropsAccumulateREnd;2372 2366 size_t cchMaxProp; 2373 2367 struct variable *pVarTrg; … … 2449 2443 2450 2444 pProps = kbuild_get_variable_n(ST("PROPS_SINGLE")); 2451 iPropsSingle = iProp;2452 2445 pszIter = pProps->value; 2453 2446 while ((paProps[iProp].pch = find_next_token(&pszIter, &paProps[iProp].cch))) 2454 if (++iProp >= cProps) 2455 { 2456 cProps += PROP_ALLOC_INC; 2457 paProps = xrealloc(paProps, sizeof(*paProps) * cProps); 2458 } 2459 iPropsSingleEnd = iProp; 2460 2461 pProps = kbuild_get_variable_n(ST("PROPS_DEFERRED")); 2462 iPropsDeferred = iProp; 2463 pszIter = pProps->value; 2464 while ((paProps[iProp].pch = find_next_token(&pszIter, &paProps[iProp].cch))) 2447 { 2448 paProps[iProp].enmType = kPropSingle; 2465 2449 if (++iProp >= cProps) 2466 2450 { … … 2468 2452 paProps = xrealloc(paProps, sizeof(*paProps) * cProps); 2469 2453 } 2470 iPropsDeferredEnd = iProp; 2471 2472 pProps = kbuild_get_variable_n(ST("PROPS_ACCUMULATE_L")); 2473 iPropsAccumulateL = iProp;2454 2455 } 2456 2457 pProps = kbuild_get_variable_n(ST("PROPS_DEFERRED")); 2474 2458 pszIter = pProps->value; 2475 2459 while ((paProps[iProp].pch = find_next_token(&pszIter, &paProps[iProp].cch))) 2460 { 2461 paProps[iProp].enmType = kPropDeferred; 2476 2462 if (++iProp >= cProps) 2477 2463 { … … 2479 2465 paProps = xrealloc(paProps, sizeof(*paProps) * cProps); 2480 2466 } 2481 iPropsAccumulateLEnd = iProp; 2482 2483 pProps = kbuild_get_variable_n(ST("PROPS_ACCUMULATE_R")); 2484 iPropsAccumulateR = iProp; 2467 } 2468 2469 pProps = kbuild_get_variable_n(ST("PROPS_ACCUMULATE_L")); 2485 2470 pszIter = pProps->value; 2486 2471 while ((paProps[iProp].pch = find_next_token(&pszIter, &paProps[iProp].cch))) 2472 { 2473 paProps[iProp].enmType = kPropAccumulateL; 2487 2474 if (++iProp >= cProps) 2488 2475 { … … 2490 2477 paProps = xrealloc(paProps, sizeof(*paProps) * cProps); 2491 2478 } 2492 iPropsAccumulateREnd = iProp; 2479 } 2480 2481 pProps = kbuild_get_variable_n(ST("PROPS_ACCUMULATE_R")); 2482 pszIter = pProps->value; 2483 while ((paProps[iProp].pch = find_next_token(&pszIter, &paProps[iProp].cch))) 2484 { 2485 paProps[iProp].enmType = kPropAccumulateR; 2486 if (++iProp >= cProps) 2487 { 2488 cProps += PROP_ALLOC_INC; 2489 paProps = xrealloc(paProps, sizeof(*paProps) * cProps); 2490 } 2491 } 2493 2492 #undef PROP_ALLOC_INC 2494 2493 cProps = iProp; … … 2610 2609 #define BY_REF_LIMIT 64 /*(cchSrcVar * 4 > 64 ? cchSrcVar * 4 : 64)*/ 2611 2610 2612 /* single: copy template prop if target doesn't define it. */ 2613 for (iProp = iPropsSingle; iProp < iPropsSingleEnd; iProp++) 2611 for (iProp = 0; iProp < cProps; iProp++) 2614 2612 { 2615 2613 memcpy(pszTrgProp, paProps[iProp].pch, paProps[iProp].cch); … … 2637 2635 *pszTrgEnd = '\0'; 2638 2636 pVarTrg = kbuild_query_recursive_variable_n(pszTrg, pszTrgEnd - pszTrg); 2639 if (pVarTrg) 2640 continue; 2641 2642 /* copy the variable if its short, otherwise reference it. */ 2643 if (pVarSrc->value_length < BY_REF_LIMIT) 2644 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2645 pVarSrc->value, pVarSrc->value_length, 2646 1 /* duplicate_value */, 2647 o_file, 2648 pVarSrc->recursive, 2649 NULL /* flocp */); 2650 else 2637 2638 switch (paProps[iProp].enmType) 2651 2639 { 2652 pszSrc[cchSrcVar] = ')'; 2653 pszSrc[cchSrcVar + 1] = '\0'; 2654 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2655 pszSrcRef, 2 + cchSrcVar + 1, 2656 1 /* duplicate_value */, 2657 o_file, 2658 1 /* recursive */, 2659 NULL /* flocp */); 2640 case kPropAccumulateL: 2641 case kPropAccumulateR: 2642 if (pVarTrg) 2643 { 2644 /* Append to existing variable. If the source is recursive, 2645 or we append by reference, we'll have to make sure the 2646 target is recusive as well. */ 2647 if ( !pVarTrg->recursive 2648 && ( pVarSrc->value_length >= BY_REF_LIMIT 2649 || pVarSrc->recursive)) 2650 pVarTrg->recursive = 1; 2651 2652 if (pVarSrc->value_length < BY_REF_LIMIT) 2653 append_string_to_variable(pVarTrg, pVarSrc->value, pVarSrc->value_length, 2654 paProps[iProp].enmType == kPropAccumulateL /* append */); 2655 else 2656 { 2657 pszSrc[cchSrcVar] = ')'; 2658 pszSrc[cchSrcVar + 1] = '\0'; 2659 append_string_to_variable(pVarTrg, pszSrcRef, 2 + cchSrcVar + 1, 2660 paProps[iProp].enmType == kPropAccumulateL /* append */); 2661 } 2662 break; 2663 } 2664 /* else: the target variable doesn't exist, create it. */ 2665 /* fall thru */ 2666 2667 case kPropSingle: 2668 case kPropDeferred: 2669 if (pVarTrg) 2670 continue; /* skip ahead if it already exists. */ 2671 2672 /* copy the variable if its short, otherwise reference it. */ 2673 if (pVarSrc->value_length < BY_REF_LIMIT) 2674 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2675 pVarSrc->value, pVarSrc->value_length, 2676 1 /* duplicate_value */, 2677 o_file, 2678 pVarSrc->recursive, 2679 NULL /* flocp */); 2680 else 2681 { 2682 pszSrc[cchSrcVar] = ')'; 2683 pszSrc[cchSrcVar + 1] = '\0'; 2684 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2685 pszSrcRef, 2 + cchSrcVar + 1, 2686 1 /* duplicate_value */, 2687 o_file, 2688 1 /* recursive */, 2689 NULL /* flocp */); 2690 } 2691 break; 2692 2660 2693 } 2694 2661 2695 } /* foreach key */ 2662 } /* foreach single prop */ 2663 2664 /* deferred: copy template prop if target doesn't define it. */ 2665 for (iProp = iPropsDeferred; iProp < iPropsDeferredEnd; iProp++) 2666 { 2667 memcpy(pszTrgProp, paProps[iProp].pch, paProps[iProp].cch); 2668 pszTrgKey = pszTrgProp + paProps[iProp].cch; 2669 2670 memcpy(pszSrcProp, paProps[iProp].pch, paProps[iProp].cch); 2671 pszSrcKey = pszSrcProp + paProps[iProp].cch; 2672 2673 for (iKey = 0; iKey < cKeys; iKey++) 2674 { 2675 char *pszTrgEnd; 2676 size_t cchSrcVar; 2677 2678 /* lookup source, skip ahead if it doesn't exist. */ 2679 memcpy(pszSrcKey, aKeys[iKey].psz, aKeys[iKey].cch); 2680 cchSrcVar = pszSrcKey - pszSrc + aKeys[iKey].cch; 2681 pszSrc[cchSrcVar] = '\0'; 2682 pVarSrc = kbuild_query_recursive_variable_n(pszSrc, cchSrcVar); 2683 if (!pVarSrc) 2684 continue; 2685 2686 /* lookup target, skip ahead if it exists. */ 2687 memcpy(pszTrgKey, aKeys[iKey].psz, aKeys[iKey].cch); 2688 pszTrgEnd = pszTrgKey + aKeys[iKey].cch; 2689 *pszTrgEnd = '\0'; 2690 pVarTrg = kbuild_query_recursive_variable_n(pszTrg, pszTrgEnd - pszTrg); 2691 if (pVarTrg) 2692 continue; 2693 2694 /* copy the variable if its short, otherwise reference it. */ 2695 if (pVarSrc->value_length < BY_REF_LIMIT) 2696 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2697 pVarSrc->value, pVarSrc->value_length, 2698 1 /* duplicate_value */, 2699 o_file, 2700 pVarSrc->recursive, 2701 NULL /* flocp */); 2702 else 2703 { 2704 pszSrc[cchSrcVar] = ')'; 2705 pszSrc[cchSrcVar + 1] = '\0'; 2706 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2707 pszSrcRef, 2 + cchSrcVar + 1, 2708 1 /* duplicate_value */, 2709 o_file, 2710 1 /* recursive */, 2711 NULL /* flocp */); 2712 } 2713 } /* foreach key */ 2714 } /* foreach deferred prop */ 2715 2716 /* accumulate_l: append the unexpanded template variable to the . */ 2717 for (iProp = iPropsAccumulateL; iProp < iPropsAccumulateLEnd; iProp++) 2718 { 2719 memcpy(pszTrgProp, paProps[iProp].pch, paProps[iProp].cch); 2720 pszTrgKey = pszTrgProp + paProps[iProp].cch; 2721 2722 memcpy(pszSrcProp, paProps[iProp].pch, paProps[iProp].cch); 2723 pszSrcKey = pszSrcProp + paProps[iProp].cch; 2724 2725 for (iKey = 0; iKey < cKeys; iKey++) 2726 { 2727 char *pszTrgEnd; 2728 size_t cchSrcVar; 2729 2730 /* lookup source, skip ahead if it doesn't exist. */ 2731 memcpy(pszSrcKey, aKeys[iKey].psz, aKeys[iKey].cch); 2732 cchSrcVar = pszSrcKey - pszSrc + aKeys[iKey].cch; 2733 pszSrc[cchSrcVar] = '\0'; 2734 pVarSrc = kbuild_query_recursive_variable_n(pszSrc, cchSrcVar); 2735 if (!pVarSrc) 2736 continue; 2737 2738 /* lookup target, skip ahead if it exists. */ 2739 memcpy(pszTrgKey, aKeys[iKey].psz, aKeys[iKey].cch); 2740 pszTrgEnd = pszTrgKey + aKeys[iKey].cch; 2741 *pszTrgEnd = '\0'; 2742 pVarTrg = kbuild_query_recursive_variable_n(pszTrg, pszTrgEnd - pszTrg); 2743 if (!pVarTrg) 2744 { 2745 /* The target doesn't exist, copy the source if it's short, 2746 otherwise just reference it. */ 2747 if (pVarSrc->value_length < BY_REF_LIMIT) 2748 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2749 pVarSrc->value, pVarSrc->value_length, 2750 1 /* duplicate_value */, 2751 o_file, 2752 pVarSrc->recursive, 2753 NULL /* flocp */); 2754 else 2755 { 2756 pszSrc[cchSrcVar] = ')'; 2757 pszSrc[cchSrcVar + 1] = '\0'; 2758 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2759 pszSrcRef, 2 + cchSrcVar + 1, 2760 1 /* duplicate_value */, 2761 o_file, 2762 1 /* recursive */, 2763 NULL /* flocp */); 2764 } 2765 } 2766 else 2767 { 2768 /* Append to existing variable. If the source is recursive, 2769 or we append by reference, we'll have to make sure the 2770 target is recusive as well. */ 2771 if ( !pVarTrg->recursive 2772 && ( pVarSrc->value_length >= BY_REF_LIMIT 2773 || pVarSrc->recursive)) 2774 pVarTrg->recursive = 1; 2775 2776 if (pVarSrc->value_length < BY_REF_LIMIT) 2777 append_string_to_variable(pVarTrg, pVarSrc->value, pVarSrc->value_length, 1 /* append */); 2778 else 2779 { 2780 pszSrc[cchSrcVar] = ')'; 2781 pszSrc[cchSrcVar + 1] = '\0'; 2782 append_string_to_variable(pVarTrg, pszSrcRef, 2 + cchSrcVar + 1, 1 /* append */); 2783 } 2784 } 2785 } /* foreach key */ 2786 } /* foreach accumulate_l prop */ 2787 2788 /* accumulate_r: prepend the unexpanded template variable to the . */ 2789 for (iProp = iPropsAccumulateR; iProp < iPropsAccumulateREnd; iProp++) 2790 { 2791 memcpy(pszTrgProp, paProps[iProp].pch, paProps[iProp].cch); 2792 pszTrgKey = pszTrgProp + paProps[iProp].cch; 2793 2794 memcpy(pszSrcProp, paProps[iProp].pch, paProps[iProp].cch); 2795 pszSrcKey = pszSrcProp + paProps[iProp].cch; 2796 2797 for (iKey = 0; iKey < cKeys; iKey++) 2798 { 2799 char *pszTrgEnd; 2800 size_t cchSrcVar; 2801 2802 /* lookup source, skip ahead if it doesn't exist. */ 2803 memcpy(pszSrcKey, aKeys[iKey].psz, aKeys[iKey].cch); 2804 cchSrcVar = pszSrcKey - pszSrc + aKeys[iKey].cch; 2805 pszSrc[cchSrcVar] = '\0'; 2806 pVarSrc = kbuild_query_recursive_variable_n(pszSrc, cchSrcVar); 2807 if (!pVarSrc) 2808 continue; 2809 2810 /* lookup target, skip ahead if it exists. */ 2811 memcpy(pszTrgKey, aKeys[iKey].psz, aKeys[iKey].cch); 2812 pszTrgEnd = pszTrgKey + aKeys[iKey].cch; 2813 *pszTrgEnd = '\0'; 2814 pVarTrg = kbuild_query_recursive_variable_n(pszTrg, pszTrgEnd - pszTrg); 2815 if (!pVarTrg) 2816 { 2817 /* The target doesn't exist, copy the source if it's short, 2818 otherwise just reference it. */ 2819 if (pVarSrc->value_length < BY_REF_LIMIT) 2820 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2821 pVarSrc->value, pVarSrc->value_length, 2822 1 /* duplicate_value */, 2823 o_file, 2824 pVarSrc->recursive, 2825 NULL /* flocp */); 2826 else 2827 { 2828 pszSrc[cchSrcVar] = ')'; 2829 pszSrc[cchSrcVar + 1] = '\0'; 2830 define_variable_vl_global(pszTrg, pszTrgEnd - pszTrg, 2831 pszSrcRef, 2 + cchSrcVar + 1, 2832 1 /* duplicate_value */, 2833 o_file, 2834 1 /* recursive */, 2835 NULL /* flocp */); 2836 } 2837 } 2838 else 2839 { 2840 /* Append to existing variable. If the source is recursive, 2841 or we append by reference, we'll have to make sure the 2842 target is recusive as well. */ 2843 if ( !pVarTrg->recursive 2844 && ( pVarSrc->value_length >= BY_REF_LIMIT 2845 || pVarSrc->recursive)) 2846 pVarTrg->recursive = 1; 2847 2848 if (pVarSrc->value_length < BY_REF_LIMIT) 2849 append_string_to_variable(pVarTrg, pVarSrc->value, pVarSrc->value_length, 0 /* prepend */); 2850 else 2851 { 2852 pszSrc[cchSrcVar] = ')'; 2853 pszSrc[cchSrcVar + 1] = '\0'; 2854 append_string_to_variable(pVarTrg, pszSrcRef, 2 + cchSrcVar + 1, 0 /* append */); 2855 } 2856 } 2857 } /* foreach key */ 2858 } /* foreach accumulate_r prop */ 2859 2696 } /* foreach prop */ 2860 2697 #undef BY_REF_LIMIT 2861 2698 } /* foreach target */
Note:
See TracChangeset
for help on using the changeset viewer.