4 if (!function_exists('file_put_contents')) {
5 function file_put_contents($filename, $data, $lockflag) {
6 $f = @fopen
($filename, 'w');
10 $bytes = fwrite($f, $data);
17 function swell_rc2cpp_dialog($fp) // returns array with ["data"] and optionally ["error"]
19 fseek($fp,0,SEEK_SET
);
23 $retstr .= '#ifndef SWELL_DLG_SCALE_AUTOGEN' . "\n";
24 $retstr .= '#define SWELL_DLG_SCALE_AUTOGEN 1.7' . "\n";
25 $retstr .= '#endif' . "\n";
26 $retstr .= '#ifndef SWELL_DLG_FLAGS_AUTOGEN' . "\n";
27 $retstr .= '#define SWELL_DLG_FLAGS_AUTOGEN SWELL_DLG_WS_FLIPPED|SWELL_DLG_WS_NOAUTOSIZE' . "\n";
28 $retstr .= "#endif\n";
31 $dlg_state=0; // 1 = before BEGIN, 2=after BEGIN
37 $dlg_styles = "SWELL_DLG_FLAGS_AUTOGEN";
43 if ($next_line != "") { $x=$next_line; $next_line =""; }
44 else if (!($x=fgets($fp))) break;
49 $dlg_contents .= $y . "\n";
52 if ($dlg_state==2) $dlg_styles.="|SWELL_DLG_WS_OPAQUE";
53 $retstr .= "#ifndef SET_$dlg_name" . "_SCALE\n";
54 $retstr .= "#define SET_$dlg_name" . "_SCALE SWELL_DLG_SCALE_AUTOGEN\n";
55 $retstr .= "#endif\n";
56 $retstr .= "#ifndef SET_$dlg_name" . "_STYLE\n";
57 $retstr .= "#define SET_$dlg_name" . "_STYLE $dlg_styles\n";
58 $retstr .= "#endif\n";
59 $retstr .= "SWELL_DEFINE_DIALOG_RESOURCE_BEGIN($dlg_name,SET_$dlg_name" . "_STYLE,\"$dlg_title\",$dlg_size_w,$dlg_size_h,SET_$dlg_name" . "_SCALE)\n";
60 $dlg_contents=str_replace("NOT WS_VISIBLE","SWELL_NOT_WS_VISIBLE",$dlg_contents);
61 $dlg_contents=str_replace("NOT\nWS_VISIBLE","SWELL_NOT_WS_VISIBLE",$dlg_contents);
62 $dlg_contents=str_replace("NOT \nWS_VISIBLE","SWELL_NOT_WS_VISIBLE",$dlg_contents);
63 $retstr .= $dlg_contents;
64 $retstr .= "SWELL_DEFINE_DIALOG_RESOURCE_END($dlg_name)\n\n\n";
67 else if (strlen($y)>1) $dlg_state=3;
71 $parms = explode(" ", $y);
72 if (count($parms) > 0)
76 // if (substr($parms[0],0,8) == "IDD_PREF")
77 if (count($parms)>4 && ($parms[1] == 'DIALOGEX'||
$parms[1] == 'DIALOG'))
81 if ($parms[$rdidx] == 'DISCARDABLE') $rdidx++
;
82 while ($parms[$rdidx] == "" && $rdidx < count($parms)) $rdidx++
;
84 $dlg_size_w = str_replace(",","",$parms[$rdidx++
]);
85 $dlg_size_h = str_replace(",","",$parms[$rdidx++
]);
86 if (count($parms) >= $rdidx && $dlg_size_w != "" && $dlg_size_h != "")
89 $dlg_styles="SWELL_DLG_FLAGS_AUTOGEN";
93 else $errstr .= "WARNING: corrupted $dlg_name resource\n";
96 else if ($dlg_state == 1)
98 if ($parms[0] == "BEGIN")
101 $dlg_contents = $y ."\n";
105 if ($parms[0] == "CAPTION")
107 $dlg_title = str_replace("\"","",trim(substr($y,8)));
109 else if ($parms[0] == "STYLE" ||
$parms[0] == "EXSTYLE")
114 $next_line = fgets($fp,4096);
115 if (!($next_line )) { $next_line=""; break; }
116 if (substr($next_line,0,1)==" " ||
substr($next_line,0,1)=="\t")
118 $y .= " " . trim($next_line);
124 if ($rep) $parms = explode(" ", $y);
127 while ($rdidx < count($parms))
129 if ($parms[$rdidx] == '|') { $opmode=0; }
130 else if ($parms[$rdidx] == 'NOT') { $opmode=1; }
131 else if ($parms[$rdidx] == 'WS_CHILD')
133 if (!$opmode) $dlg_styles .= "|SWELL_DLG_WS_CHILD";
135 else if ($parms[$rdidx] == 'WS_THICKFRAME')
137 if (!$opmode) $dlg_styles .= "|SWELL_DLG_WS_RESIZABLE";
139 else if ($parms[$rdidx] == 'WS_EX_ACCEPTFILES')
141 if (!$opmode) $dlg_styles .= "|SWELL_DLG_WS_DROPTARGET";
153 $errstr .= "WARNING: there may have been a truncated dialog resource ($dlg_name)\n";
155 $retstr .= "\n//EOF\n\n";
157 $rv["data"] = $retstr;
158 $rv["error"] = $errstr;
162 function swell_rc2cpp_menu($fp) // returns array with ["data"] and optionally ["error"]
167 fseek($fp,0,SEEK_SET
);
171 while (($x=fgets($fp)))
173 $a=strpos($x, "\"\"");
177 $c=strpos($x, "\"", $a+
1);
178 if ($b && $c && $b < $a && $c > $a)
180 $x=str_replace("\"\"", "\\\"", $x);
185 if ($menu_symbol == "")
187 $parms = explode(" ", $y);
189 if (count($parms) >= 2 && $parms[1] == $tok)
191 $menu_symbol = $parms[0];
193 $retstr .= "SWELL_DEFINE_MENU_RESOURCE_BEGIN($menu_symbol)\n";
201 if ($menu_depth == 0)
203 $retstr .= "SWELL_DEFINE_MENU_RESOURCE_END($menu_symbol)\n\n\n";
205 if ($menu_depth < 1) $menu_symbol="";
209 if (substr($y,-strlen(", HELP")) == ", HELP")
211 $x=substr(rtrim($x),0,-strlen(", HELP")) . "\n";
215 if ($y == "BEGIN") $menu_depth+
=1;
219 $retstr .= "\n//EOF\n\n";
221 $rv["data"] = $retstr;
222 $rv["error"] = $errstr;
227 if (count($argv)<2) die("usage: mac_resgen.php [--force] file.rc ...\n");
231 if ($argv[$x] == "--force") { $forcemode=1; $x++
; }
233 $lp = dirname(__FILE__
);
237 for (; $x < count($argv); $x ++
)
240 if (!stristr($srcfn,".rc") ||
!($fp = @fopen
($srcfn,"r")))
243 echo "$srcfn: not valid or not found!\n";
247 $ofnmenu = $srcfn . "_mac_menu";
248 $ofndlg = $srcfn . "_mac_dlg";
250 $res = swell_rc2cpp_dialog($fp);
251 $res2 = swell_rc2cpp_menu($fp);
253 if ($res["error"] != "" ||
$res2["error"] != "")
257 if ($res["error"] != "") echo " dialog: " . $res["error"];
258 if ($res2["error"] != "") echo " menu: " . $res2["error"];
263 if ($forcemode ||
!file_exists($ofndlg) ||
file_get_contents($ofndlg) != $res["data"])
266 if (!file_put_contents($ofndlg,$res["data"],LOCK_EX
)) { echo "error writing $ofndlg\n"; $err++
; }
268 if ($forcemode ||
!file_exists($ofnmenu) ||
file_get_contents($ofnmenu) != $res2["data"])
270 if ($f != "") $f .= ", ";
271 $f .= "menu updated";
272 if (!file_put_contents($ofnmenu,$res2["data"],LOCK_EX
)) { echo "error writing $ofnmenu\n"; $err++
; }
277 else echo "skipped\n";
278 if ($f != "") $proc++
;
281 echo "processed $proc, skipped $skipped, error $err\n";