2013年8月7日 星期三

remove windows new line & carrier return symbol


[bash, Perl] A script to remove new line & carrier return symbol derived from Windows



#!/bin/bash
# Shell script to find out all the files under a directory and
#its subdirectories. This takes into consideration only those files
#or directories which do not have spaces or newlines in their names

# how to use it?
#    bash remove_cr.sh your_directoryname

DIR=`pwd`/$1

function list_files()
{
    if !(test -d $1)
    then echo $1; return;
    fi

    cd $1
    echo; echo `pwd`:; #Display Directory name

    for i in * ## [TODO] this will list all of files in the directory?
    do
               if test -d $i  #if dictionary
                then
                    list_files $i #recursively list files
                    cd ..
                else
                    echo $i; #Display File name
                    perl -p -i -e 's/\r\n$/\n/g' $i   ## use Perl to replace end \r\n with \n
                fi

    done
}

## if no argument input, then start from current directory ($# : number of argument input )
if [ $# -eq 0 ]
then list_files .
exit 0
fi



for i in $*
do
    DIR=$1
    list_files $DIR
    shift 1 #To read next directory/file name
done


## $* means whole arguments , shift could help to shift argement to next one.
## http://linuxpoison.blogspot.tw/2012/07/bash-script-using-shift-statement-to.html




2013年8月6日 星期二

Verilog 101 - get start

reference : http://design-ark.blogspot.tw/2012/12/hello-verilog.html
reference : http://iverilog.wikia.com/wiki/Getting_Started


[1] The simplest code for Verilog, please save it as hello.v 

code :


module main;
initial
    begin
      $display("Hello, World");
      $finish ; /* optional */
    end
endmodule



ps : 
module, endmodule -> declaration
main -> module name
$display -> just like printf in C

[2] compiler : Icarus Verilog

- Please download from  : http://bleyer.org/icarus/
-  setup the environment path

[3]  compile & execution (in case you use Windows and work in C:\ directory)

-  c:\iverilog -o hello hello.v
-   c:\vvp hello