parseconfig

来自「一个用在mips体系结构中的操作系统」· 代码 · 共 82 行

TXT
82
字号
#!/usr/local/bin/perl5## Copyright (C) 1996-1998 by the Board of Trustees#    of Leland Stanford Junior University.# # This file is part of the SimOS distribution. # See LICENSE file for terms of the license. #if ($ARGV[0]) {    open (CONFIG, $ARGV[0]);} else {    open (CONFIG, "./simconfig.c");}$beginconfig = 0;while (<CONFIG>) {    if(/SimConfigDefaults\(void\)/) {	$beginconfig = 1;    }    if(/^#define\s+(\S+)\s+(\S+)/) {       $defarr{$1} = $2;	   }				    if($beginconfig == 0) {	next;    }    if(/\/\* ENDCONFIG \*\//) {	last;    }    if(/^\s*SimConfigSet(\w+)\s*\(\s*"(\w+)"\s*,\s*(\S+)\s*\)\s*;(\s*\/\*([^*]+)(\*\/)?)?/) {	$tag = join('', $2, ":");	$comment = $5;	$cont = $6;	$token = $1;	if(($1 eq "String") || ($1 eq "Line") || ($1 eq "Bool")) {   	    $3 =~ /"(\S*)"/;	    if($defarr{$1}) {		$defarr{$1} =~ /"(\S*)"/;	    } 	    $val = $1;	} else {	    if($defarr{$3}) {		$val = $defarr{$3};	    } else {		$val = $3;	    }	}	printf "%-25s %-25s#%-6s", $tag, $val, $token;	if($comment) {	    if(!$cont) {		chop $comment;	    }	    printf ": %s\n", $comment;	    while(!($cont) && ($cline = <CONFIG>)) {		if($cline =~ /^\s*(\* )?([^*]*)(\*\/)?/) {		    $cont = $3;		    if($2) {			printf "%51s# %s", "", $2;		    }		}	    }	} else {	    print "\n";	}	next;	          }    if(/\/\*\s*(.+)\s*\*\//) {	print "\n# $1\n";    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?