4 VERBOSE=$(test "x$2x" != "xx" && echo "1" || echo "0")
8 if test $VERBOSE -eq 1; then
9 echo "Removing ${TMP_FNAME}" > /dev/stderr
14 trap rm_tmpfile TERM INT
16 process_fname() # $1 = file name, n_pass
21 sed -rn '1h;1!H;${;g;s!((\$|jQuery)([\n \t]|/\*.*\*/)*\.([\n \t]|/\*.*\*/)*widget([\n \t]|/\*.*\*/)*\(([\n \t]|/\*.*\*/)*")([^"]*)("[^{]*\{)!\1'$'\1''\7'$'\1''\8!g;p;}' | \
22 sed -rn '1h;1!H;${;g;s!(/\*|\*/|//|[{}])!'$'\1''\1'$'\1''!g;p;}' | \
24 -v 'nPass='"${N_PASS}" \
33 -v 'needAnotherPass=0' \
34 -v 'needToAddComma=0' \
36 function dumpProto(protoName) {
37 protoFile = "'"${WIDGET_BASE_DIR}"'/proto-html/" protoName ".prototype.html";
38 if (system("test -r " protoFile)) {
39 print "\033[7minline-protos.sh: Warning: " protoFile " not found\033[0m" > "/dev/stderr";
40 printf("\"%s\"", protoName);
44 printf("\n [ \"<div>");
45 while (1 == (getline inputLine < protoFile)) {
46 for (Nix1 = 1 ; Nix1 <= length(inputLine) ; Nix1++) {
47 theChar = substr(inputLine, Nix1, 1);
53 if (insideTag && "\"" == theChar)
55 printf("%s", theChar);
59 printf("</div>\" ].join(\"\")");
64 function establishInliningVariables(widgetName, token) {
65 if (1 == inWidgetBody) {
66 if (1 == braceCount) {
67 if (match(token, /[ \t]([^: \t]*):/, arToken))
68 inHtmlProto = ((arToken[1] == "_htmlProto") ? 1 : 0);
72 if (inHtmlProto == 1) {
73 if (nPass == 1 && seenSource == 0) {
74 printf("\nsource:\n");
75 dumpProto(widgetName);
79 if (braceCount == 2) {
80 sourceTokenHasMatched = 0;
81 if (match(token, /[ \t]([a-zA-Z0-9_]*)[ \t]*:/, arToken)) {
82 sourceToken = ((arToken[1] == "source") ? 1 : 0);
83 sourceTokenHasMatched = 1;
84 if (needToAddComma == 1) {
90 if (sourceToken == 0) {
91 if (sourceValue != "") {
92 if (match(sourceValue, /^[\n\t ]*("([^"]*)")/, sourceWidgetAr)) {
93 sourceWidgetName = sourceWidgetAr[2];
94 printf("%s", substr(sourceValue, 1, sourceWidgetAr[1, "start"] - 1));
95 dumpProto(sourceWidgetName);
96 printf("%s", substr(sourceValue, sourceWidgetAr[1, "start"] + sourceWidgetAr[1, "length"]));
99 printf("%s", sourceValue);
105 if (sourceTokenHasMatched) {
106 nArSource = split(token, arSource, ":");
107 printf("%s:", arSource[1]);
109 for (idxArSource = 2 ; idxArSource <= nArSource ; idxArSource++) {
111 sourceValue = sourceValue arSource[idxArSource];
112 if (idxArSource < nArSource)
113 sourceValue = sourceValue ":";
118 sourceValue = sourceValue token;
133 n = split($0, ar, /\001/);
135 for (Nix = 1 ; Nix <= n ; Nix++) {
136 if (ar[Nix] == "/*") {
138 printf("%s", ar[Nix]);
141 if (ar[Nix] == "*/") {
143 printf("%s", ar[Nix]);
146 if (ar[Nix] == "//") {
147 for (; Nix <= n ; Nix++)
148 printf("%s", ar[Nix]);
152 printf("%s", ar[Nix]);
155 establishInliningVariables(widgetName, ar[Nix]);
158 /* ar[Nix] is an interesting token not inside comments */
159 if ("{" == ar[Nix] || "}" == ar[Nix]) {
160 if (widgetName != "" && inWidgetBody == 0) {
166 if (inWidgetBody == 1) {
170 if ("}" == ar[Nix]) {
171 if (inHtmlProto == 1 && braceCount == 2) {
181 split(ar[Nix], arWidget, ".");
182 widgetName = arWidget[2];
184 if (widgetName == "")
185 printf("%s", ar[Nix]);
187 printf("%s", ar[Nix]);
196 establishInliningVariables(widgetName, $0 "\n");
198 END { exit(needAnotherPass); }
202 if test "x${WIDGET_BASE_DIR}x" = "xx"; then
203 echo "Usage: $(basename $0) <widget_base_dir>"
207 for FNAME in ${WIDGET_BASE_DIR}/js/*.js; do
210 while ! process_fname $FNAME $N_PASS > $TMP_FNAME; do
211 if test $VERBOSE -eq 1; then
212 echo "Going for another pass with ${TMP_FNAME}" > /dev/stderr
214 N_PASS=`expr "$N_PASS" + 1`