<?php
/*
fortran のコメントを除去するためのPHPスクリプト
[1] 1カラム目が"C","*"
[2] "!"以降、行末まで
USAGE> php delCom.php hoge.f
*/
echo "C FILE: ".$argv[1]."\n";
$basename= basename($argv[1],".".pathinfo($argv[1],PATHINFO_EXTENSION));
$handle= fopen($argv[1],"r");
if ( $handle ) {
$text="";
while ( !feof($handle) ) {
$line= fgets($handle);
$line= mb_convert_encoding($line,"SJIS","EUC-JP");
if ( !eregi("(c|\*)",substr($line,0,1)) ) {
if ( eregi("!",$line) ) {
$strlen= stripos($line,"!");
$string= rtrim(substr($line,0,$strlen));
}else{
$string= rtrim($line);
}
if ( strlen($string) > 0 ) {
echo $string."\n";
$text.= $string."\r\n";
}
}
}
file_put_contents($basename."NC.f",$text);
fclose($handle);
}