#!/usr/bin/perl
###############################################################################
#
#  機能 :
#         ＲＯＭマップを出力するためのシェルを生成する
#  書式 :
#         MkRommapShell.pl <ＲＯＭマップ・セグメントリスト>
#
#  $Id: MkRommapShell.pl,v 1.6 2000-05-26 10:12:09+09 otsuki Exp $
#
###############################################################################
{
    $tmp_srcfile = "srcfile";
    $tmp_outfile = "outfile";

    print "#! /bin/tcsh -f\n";
    print "echo ###########################################################\n";
    print "echo # ROM Map \n";
    print "echo ###########################################################\n";

    print "ConvSegmentMap.pl < \$1 > $tmp_srcfile\n";

    open(ROMMAP_SEGLST_F, $ARGV[0])
	|| die "ファイル $ARGV[$0] をオープンできない!!\n";

    $is_top = 1;
    while($_ = <ROMMAP_SEGLST_F>) {
	if ($_ =~ /\*/) {
	    if ($is_top == 0) {
		print "MapTotal.pl $tmp_outfile \n";
		print "\n";
	    }
	    s/\*//;
	    print "echo ==== $_";
	    $is_first = 1;
	    $is_top = 0;
	}
	else {
	    if (($_ =~ /[a-zA-Z0-9_]/) && !($_ =~ /\#/)) {
		chop;
		print "grep $_ $tmp_srcfile ";
		if ($is_first == 0) {
		    print ">";
		}
		print "> $tmp_outfile \n";
		$is_first = 0;
	    }
	}
    }
    print "MapTotal.pl $tmp_outfile \n";
    close(ROMMAP_SEGLST_F);

    print "\n";
    print "echo ==== その他 \n";
    print "UnRommapSeg.pl $tmp_srcfile $ARGV[0] > $tmp_outfile\n";
    print "MapTotal.pl $tmp_outfile\n";
    print "\n";
    print "grep \">>>\" $tmp_srcfile\n";

    print "\n";
    print "rm -rf $tmp_srcfile $tmp_outfile \n";
}
