4 WIDGET_BASE_DIR="`dirname ${WIDGET_FNAME}`"
5 VERBOSE=$(test "x$2x" != "xx" && echo "1" || echo "0")
9 if test $VERBOSE -eq 1; then
10 echo "Removing ${TMP_FNAME}" > /dev/stderr
15 trap rm_tmpfile TERM INT
17 process_fname() # $1 = file name, n_pass
22 sed -rn '1h;1!H;${;g;s!((\$|jQuery)([\n \t]|/\*.*\*/)*\.([\n \t]|/\*.*\*/)*widget([\n \t]|/\*.*\*/)*\(([\n \t]|/\*.*\*/)*")([^"]*)("[^{]*\{)!\1'$'\1''\7'$'\1''\8!g;p;}' | \
23 sed -rn '1h;1!H;${;g;s!(/\*|\*/|//|[{}])!'$'\1''\1'$'\1''!g;p;}' | \
25 -v 'nPass='"${N_PASS}" \
34 -v 'needAnotherPass=0' \
35 -v 'needToAddComma=0' \
37 function dumpProto(protoName) {
38 protoFile = "'"${WIDGET_BASE_DIR}"'/proto-html/" protoName ".prototype.html";
39 if (system("test -r " protoFile)) {
40 print "\033[7minline-protos.sh: Warning: " protoFile " not found\033[0m" > "/dev/stderr";
41 printf("\"%s\"", protoName);
45 printf("\n [ \"<div>");
46 while (1 == (getline inputLine < protoFile)) {
47 for (Nix1 = 1 ; Nix1 <= length(inputLine) ; Nix1++) {
48 theChar = substr(inputLine, Nix1, 1);
54 if (insideTag && "\"" == theChar)
56 printf("%s", theChar);
60 printf("</div>\" ].join(\"\")");
65 function establishInliningVariables(widgetName, token) {
66 if (1 == inWidgetBody) {
67 if (1 == braceCount) {
68 if (match(token, /[ \t]([^: \t]*):/, arToken))
69 inHtmlProto = ((arToken[1] == "_htmlProto") ? 1 : 0);
73 if (inHtmlProto == 1) {
74 if (nPass == 1 && seenSource == 0) {
75 printf("\nsource:\n");
76 dumpProto(widgetName);
80 if (braceCount == 2) {
81 sourceTokenHasMatched = 0;
82 if (match(token, /[ \t]([a-zA-Z0-9_]*)[ \t]*:/, arToken)) {
83 sourceToken = ((arToken[1] == "source") ? 1 : 0);
84 sourceTokenHasMatched = 1;
85 if (needToAddComma == 1) {
91 if (sourceToken == 0) {
92 if (sourceValue != "") {
93 if (match(sourceValue, /^[\n\t ]*("([^"]*)")/, sourceWidgetAr)) {
94 sourceWidgetName = sourceWidgetAr[2];
95 printf("%s", substr(sourceValue, 1, sourceWidgetAr[1, "start"] - 1));
96 dumpProto(sourceWidgetName);
97 printf("%s", substr(sourceValue, sourceWidgetAr[1, "start"] + sourceWidgetAr[1, "length"]));
100 printf("%s", sourceValue);
106 if (sourceTokenHasMatched) {
107 nArSource = split(token, arSource, ":");
108 printf("%s:", arSource[1]);
110 for (idxArSource = 2 ; idxArSource <= nArSource ; idxArSource++) {
112 sourceValue = sourceValue arSource[idxArSource];
113 if (idxArSource < nArSource)
114 sourceValue = sourceValue ":";
119 sourceValue = sourceValue token;
134 n = split($0, ar, /\001/);
136 for (Nix = 1 ; Nix <= n ; Nix++) {
137 if (ar[Nix] == "/*") {
139 printf("%s", ar[Nix]);
142 if (ar[Nix] == "*/") {
144 printf("%s", ar[Nix]);
147 if (ar[Nix] == "//") {
148 for (; Nix <= n ; Nix++)
149 printf("%s", ar[Nix]);
153 printf("%s", ar[Nix]);
156 establishInliningVariables(widgetName, ar[Nix]);
159 /* ar[Nix] is an interesting token not inside comments */
160 if ("{" == ar[Nix] || "}" == ar[Nix]) {
161 if (widgetName != "" && inWidgetBody == 0) {
167 if (inWidgetBody == 1) {
171 if ("}" == ar[Nix]) {
172 if (inHtmlProto == 1 && braceCount == 2) {
182 split(ar[Nix], arWidget, ".");
183 widgetName = arWidget[2];
185 if (widgetName == "")
186 printf("%s", ar[Nix]);
188 printf("%s", ar[Nix]);
197 establishInliningVariables(widgetName, $0 "\n");
199 END { exit(needAnotherPass); }
203 if test "x${WIDGET_BASE_DIR}x" = "xx"; then
204 echo "Usage: $(basename $0) <widget_file_path>"
208 FNAME=${WIDGET_FNAME}
211 while ! process_fname $FNAME $N_PASS > $TMP_FNAME; do
212 if test $VERBOSE -eq 1; then
213 echo "Going for another pass with ${TMP_FNAME}" > /dev/stderr
215 N_PASS=`expr "$N_PASS" + 1`