清明临近,脚本继续

截止今天,总体上把14443的typeB的协议完整仔细的看了一遍(我指的是发送格式,以及数据传输的帧格式和命令)。

下一步可以开始着手来分析着写代码了。

但这不是今天要谈的重点,今天的重点是我掌握了使用csh编程里从控制台取得参数来进行编程处理的基本技术,事出有因,在linux下用gcc是非常方便的,谁用谁知道,那么我就萌生了自己写个编译gcc的脚本的想法,一通百通,就再次写了一个直接编译verilog文件的脚本。下面上脚本

 1 #! /bin/csh -f
2 #////////////////////////////////////////////////////////////////////////////////////////////////////
3 #// SCRIPT NAME : GCC PROCESSED SCRIPT //
4 #// DATE : Tue Mar 27 21:30:48 CST 2012 //
5 #// DESCRIPTION : This script purpose is to compile and link c file conveniently //
6 #////////////////////////////////////////////////////////////////////////////////////////////////////
7 set top_entity = $1
8 set file_list = "${argv[*]}"
9 set var_num = ${#argv}
10
11 echo ""
12 if(${var_num} == 0) then
13 echo "Error, no file has been given to processed."
14 exit 2
15 endif
16
17 while ($#argv)
18 if(!(-e $argv[1])) then
19 echo "Error, '$argv[1]' file not exist."
20 exit 2
21 endif
22
23 if("$argv[1]" !~ *.c) then
24 echo "Error, '$argv[1]' is not a c file."
25 exit 2
26 endif
27
28 shift
29 end
30
31 if(${var_num} == 1) then
32 echo "The file '$top_entity' is the top entity, $var_num file has been processed."
33 else
34 echo "The first file '$top_entity' is the top entity, $var_num files have been processed."
35 endif
36 echo "Result of gcc processed"
37 echo ""
38
39 rm ${top_entity}.out
40 gcc -Wall ${file_list} -o ${top_entity}.out
41
42 echo ""
43 echo "Job done"


带有错误报警的脚本,轻松又愉快。下面上编译verilog文件的。

 1 #! /bin/csh -f
2 #////////////////////////////////////////////////////////////////////////////////////////////////////
3 #// SCRIPT NAME : NC-VERILOG SIMULATION SCRIPT //
4 #// DATE : Tue Mar 27 21:35:10 CST 2012 //
5 #// DESCRIPTION : This script is for handy simulation for the verilog files //
6 #////////////////////////////////////////////////////////////////////////////////////////////////////
7 set file_list = "${argv[*]}"
8 set file_name = ""
9 set var_num = ${#argv}
10
11 echo ""
12
13 if(${var_num} == 0) then
14 echo "Error, no file has been given to processed."
15 exit 2
16 endif
17
18 while ($#argv)
19 if(!(-e $argv[1])) then
20 echo "Error, '$argv[1]' file not exist."
21 exit 2
22 endif
23
24 if("$argv[1]" !~ *.v) then
25 echo "Error, '$argv[1]' is not a verilog file."
26 exit 2
27 endif
28
29 shift
30 end
31
32 echo "File processing..."
33 echo ""
34
35
36 rm ncverilog.key ncverilog.log INCA_libs -fr
37 ncverilog +gui +access+rwc +notimingcheck +nospecify ${file_list}


基本的从命令行取得参数的就不多说一看就懂,其实我花了很多时间在foreach和while上面,就是进行错误报告那里,基本的例程格式给出。

foreach,好像用法都是和if一起,来判断什么什么,值得注意的是什么时候变量要用“”给包起来。看好了,这里判断的=~是用来判断正则表达式的时候用的,所以此时一定是字符串所以一定要记得加上“”

1 foreach arg ($argv)
2 #does it begin with - ?
3 if ("$arg" =~ -*) then
4 echo "Argument is an option"
5 else
6 echo "Argument is a filename"
7 endif
8 end


而while呢好像不能像c一样写个变量减减什么的(很有可能是我太2了,不会搞),一般都是像这样用

1 while ($#argv)
2 if (-f $argv[1]) then
3 wc -l $argv[1]
4 else
5 echo "$argv[1] is not a regular file"
6 endif
7 shift
8 end

这里的shift和while连用是一种很好的判断输入进来的命令行参量某种逻辑的方式,常常这样用。值得注意的就是if的语法风格,一定记得写上then,不然shell编译器提示的信息你一辈子也不知道自己错在了哪里了。

if的语法形式有以下这三种形式

if (expr) then     
    cmds           
endif              

if (expr) then
    cmds1       
else          
    cmds2       
endif         

if (expr) then
    cmds1
else if (expr) then
    cmds2
else
    cmds3
endif

结论就是一定要写then啊!!对错误的处理exit 2就是很简单的报错退出。

本来萌生了写一个数字信号发生器的想法,就是在一块ROM里面写好一些数,用查找表的形式往外读数就可以了,比如用一块1KX32的ROM就可以,外面包一个controller,做成频率可调的,就OK了。嗯,好像不难的样子,就这么弄

posted @ 2012-03-27 22:48  poiu_elab  阅读(388)  评论(0编辑  收藏  举报