'); } $from_modlist_file = $argv[1]; $to_modlist_file = $argv[2]; if ( is_dir($from_modlist_file) ) { $from_modlist_file .= '\modlist.txt'; } if ( is_dir($to_modlist_file) ) { $to_modlist_file .= '\modlist.txt'; } if ( !is_readable($from_modlist_file) ) { throw new Exception($from_modlist_file . ' is not readable'); } if ( !is_readable($to_modlist_file) ) { throw new Exception($to_modlist_file . ' is not readable'); } $from_modlist = get_modlist($from_modlist_file); $to_modlist = get_modlist($to_modlist_file); apply_modlist($from_modlist, $to_modlist); } catch (Exception $e) { echo $e->GetMessage() . PHP_EOL; } function get_modlist($modlist_file) { $ret = []; $fp = fopen($modlist_file, 'r'); while ( !feof($fp) ) { $buf = fgets($fp); $buf = trim($buf); if ( strlen($buf) == 0 ) { continue; } $ret[] = $buf; } fclose($fp); return $ret; } function apply_modlist($from_modlist, $to_modlist) { $fp = fopen('modlist.txt', 'w'); foreach ($from_modlist as $mod) { $flag = substr($mod, 0, 1); if ( $flag == '-' || $flag == '+' ) { $body = substr($mod, 1); if ( in_array('+' . $body, $to_modlist) ) { $mod = '+' . $body; } else { $mod = '-' . $body; } } fputs($fp, $mod . PHP_EOL); } fclose($fp); }