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 convertquotes($in)
21 for ($x=0;$x<strlen($in); $x++
)
32 if ($x < strlen($in) && $in[$x+
1] == '"')
44 function utf_fgets($fp, &$state)
50 if (ord($s[0])==0xff && ord($s[1]) == 0xfe) $state=1; // UTF-16LE
51 else if (ord($s[0])==0xfe && ord($s[1]) == 0xff) $state=2; // UTF-16BE
52 else if (ord($s[0])==0xef && ord($s[1]) == 0xbb)
55 if (ord($s2[0]) != 0xbf) return $s . $s2 . fgets($fp,4096);
58 if ($state < 0) return fgets($fp,4096);
61 while ($s = fread($fp,2))
63 if ($state == 1) $s = ord($s[0]) |
(ord($s[1])<<8);
64 else $s = ord($s[1]) |
(ord($s[0])<<8);
68 if ($s == ord("\n")) break;
70 else if ($s <= 0x7ff) $ret .= chr(0xc0 |
(($s>>6)&0x1f)) . chr(0x80 |
($s&0x3f));
71 else $ret .= chr(0xe0 |
(($s>>12)&0xf)) . chr(0x80 |
(($s)>>6)&0x3f) . chr(0x80 |
($s&0x3f));
77 function swell_rc2cpp_dialog($fp) // returns array with ["data"] and optionally ["error"]
79 fseek($fp,0,SEEK_SET
);
84 $retstr .= '#ifndef SWELL_DLG_SCALE_AUTOGEN' . "\n";
85 $retstr .= '#ifdef __APPLE__' . "\n";
86 $retstr .= ' #define SWELL_DLG_SCALE_AUTOGEN 1.7' . "\n";
87 $retstr .= '#else' . "\n";
88 $retstr .= ' #define SWELL_DLG_SCALE_AUTOGEN 1.8' . "\n";
89 $retstr .= '#endif' . "\n";
90 $retstr .= '#endif' . "\n";
91 $retstr .= '#ifndef SWELL_DLG_FLAGS_AUTOGEN' . "\n";
92 $retstr .= '#define SWELL_DLG_FLAGS_AUTOGEN SWELL_DLG_WS_FLIPPED|SWELL_DLG_WS_NOAUTOSIZE' . "\n";
93 $retstr .= "#endif\n";
96 $dlg_state=0; // 1 = before BEGIN, 2=after BEGIN
102 $dlg_styles = "SWELL_DLG_FLAGS_AUTOGEN";
108 if ($next_line != "") { $x=$next_line; $next_line =""; }
109 else if (!($x=utf_fgets($fp,$utf_state))) break;
110 $x = convertquotes($x);
115 if (preg_match("/^LTEXT(.*), *WS_EX_RIGHT$/",$y,$match)) $y = "RTEXT" . $match[1];
116 $dlg_contents .= $y . "\n";
119 if ($dlg_state==2) $dlg_styles.="|SWELL_DLG_WS_OPAQUE";
120 $retstr .= "#ifndef SET_$dlg_name" . "_SCALE\n";
121 $retstr .= "#define SET_$dlg_name" . "_SCALE SWELL_DLG_SCALE_AUTOGEN\n";
122 $retstr .= "#endif\n";
123 $retstr .= "#ifndef SET_$dlg_name" . "_STYLE\n";
124 $retstr .= "#define SET_$dlg_name" . "_STYLE $dlg_styles\n";
125 $retstr .= "#endif\n";
126 $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";
127 $dlg_contents=str_replace("NOT WS_VISIBLE","SWELL_NOT_WS_VISIBLE",$dlg_contents);
128 $dlg_contents=str_replace("NOT\nWS_VISIBLE","SWELL_NOT_WS_VISIBLE",$dlg_contents);
129 $dlg_contents=str_replace("NOT \nWS_VISIBLE","SWELL_NOT_WS_VISIBLE",$dlg_contents);
130 $retstr .= $dlg_contents;
131 $retstr .= "SWELL_DEFINE_DIALOG_RESOURCE_END($dlg_name)\n\n\n";
134 else if (strlen($y)>1) $dlg_state=3;
138 $parms = explode(" ", $y);
139 if (count($parms) > 0)
143 // if (substr($parms[0],0,8) == "IDD_PREF")
144 if (count($parms)>4 && ($parms[1] == 'DIALOGEX'||
$parms[1] == 'DIALOG'))
148 if ($parms[$rdidx] == 'DISCARDABLE') $rdidx++
;
149 while ($parms[$rdidx] == "" && $rdidx < count($parms)) $rdidx++
;
151 $dlg_size_w = str_replace(",","",$parms[$rdidx++
]);
152 $dlg_size_h = str_replace(",","",$parms[$rdidx++
]);
153 if (count($parms) >= $rdidx && $dlg_size_w != "" && $dlg_size_h != "")
156 $dlg_styles="SWELL_DLG_FLAGS_AUTOGEN";
160 else $errstr .= "WARNING: corrupted $dlg_name resource\n";
163 else if ($dlg_state == 1)
165 if ($parms[0] == "BEGIN")
168 $dlg_contents = $y ."\n";
172 if ($parms[0] == "CAPTION")
174 $dlg_title = str_replace("\"","",trim(substr($y,8)));
176 else if ($parms[0] == "STYLE" ||
$parms[0] == "EXSTYLE")
181 $next_line = utf_fgets($fp,$utf_state);
182 if (!($next_line )) { $next_line=""; break; }
183 if (substr($next_line,0,1)==" " ||
substr($next_line,0,1)=="\t")
185 $y .= " " . trim(convertquotes($next_line));
191 if ($rep) $parms = explode(" ", $y);
194 while ($rdidx < count($parms))
196 if ($parms[$rdidx] == '|') { $opmode=0; }
197 else if ($parms[$rdidx] == 'NOT') { $opmode=1; }
198 else if ($parms[$rdidx] == 'WS_CHILD')
200 if (!$opmode) $dlg_styles .= "|SWELL_DLG_WS_CHILD";
202 else if ($parms[$rdidx] == 'WS_THICKFRAME')
204 if (!$opmode) $dlg_styles .= "|SWELL_DLG_WS_RESIZABLE";
206 else if ($parms[$rdidx] == 'WS_EX_ACCEPTFILES')
208 if (!$opmode) $dlg_styles .= "|SWELL_DLG_WS_DROPTARGET";
220 $errstr .= "WARNING: there may have been a truncated dialog resource ($dlg_name)\n";
222 $retstr .= "\n//EOF\n\n";
224 $rv["data"] = $retstr;
225 $rv["error"] = $errstr;
229 function swell_rc2cpp_menu($fp) // returns array with ["data"] and optionally ["error"]
234 fseek($fp,0,SEEK_SET
);
239 while (($x=utf_fgets($fp,$utf_state)))
241 $x = convertquotes($x);
244 if ($menu_symbol == "")
246 $parms = explode(" ", $y);
248 if (count($parms) >= 2 && $parms[1] == $tok)
250 $menu_symbol = $parms[0];
252 $retstr .= "SWELL_DEFINE_MENU_RESOURCE_BEGIN($menu_symbol)\n";
260 if ($menu_depth == 0)
262 $retstr .= "SWELL_DEFINE_MENU_RESOURCE_END($menu_symbol)\n\n\n";
264 if ($menu_depth < 1) $menu_symbol="";
268 if (substr($y,-strlen(", HELP")) == ", HELP")
270 $x=substr(rtrim($x),0,-strlen(", HELP")) . "\n";
274 if ($y == "BEGIN") $menu_depth+
=1;
278 $retstr .= "\n//EOF\n\n";
280 $rv["data"] = $retstr;
281 $rv["error"] = $errstr;
286 if (count($argv)<2) die("usage: mac_resgen.php [--force] file.rc ...\n");
290 if ($argv[$x] == "--force") { $forcemode=1; $x++
; }
292 $lp = dirname(__FILE__
);
297 for (; $x < count($argv); $x ++
)
300 if ($srcfn == "--quiet")
305 if (!stristr($srcfn,".rc") ||
!($fp = @fopen
($srcfn,"r")))
308 echo "$srcfn: not valid or not found!\n";
311 $ofnmenu = $srcfn . "_mac_menu";
312 $ofndlg = $srcfn . "_mac_dlg";
314 $res = swell_rc2cpp_dialog($fp);
315 $res2 = swell_rc2cpp_menu($fp);
317 if ($res["error"] != "" ||
$res2["error"] != "")
320 echo "$srcfn: error";
321 if ($res["error"] != "") echo " dialog: " . $res["error"];
322 if ($res2["error"] != "") echo " menu: " . $res2["error"];
327 if ($forcemode ||
!file_exists($ofndlg) ||
file_get_contents($ofndlg) != $res["data"])
330 if (!file_put_contents($ofndlg,$res["data"],LOCK_EX
)) { echo "error writing $ofndlg\n"; $err++
; }
332 if ($forcemode ||
!file_exists($ofnmenu) ||
file_get_contents($ofnmenu) != $res2["data"])
334 if ($f != "") $f .= ", ";
335 $f .= "menu updated";
336 if (!file_put_contents($ofnmenu,$res2["data"],LOCK_EX
)) { echo "error writing $ofnmenu\n"; $err++
; }
349 if (!$quiet) echo "$srcfn: $f\n";
351 if (!$quiet ||
$proc ||
$err) echo "processed $proc, skipped $skipped, error $err\n";