zoukankan      html  css  js  c++  java
  • codefind.pl

    #!/usr/bin/perl
    #
    # Find a pattern in a the book's source collection (DOS/Windows version)
    #
    # (C) Copyright 2000-2002 Diomidis Spinellis
    # 
    # Permission to use, copy, and distribute this software and its
    # documentation for any purpose and without fee is hereby granted,
    # provided that the above copyright notice appear in all copies and that
    # both that copyright notice and this permission notice appear in
    # supporting documentation.
    # 
    # THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
    # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
    # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
    #
    
    # Heuristic to see if we are running under Windows / DOS or Unix
    $windows = (-r 'nul' && !-r '/dev/null');
    
    if ($#ARGV != 2) {
    	print STDERR "Usage:		$0 source-directory file-suffix-regex code-regex
    ";
    	if ($windows) {
    		print STDERR "Example:	perl $0 d:\ace \.[ch] main
    ";
    	} else {
    		print STDERR "Example:	$0 d:\booksrc\ace '\.[ch]' main
    ";
    	}
    	exit 1;
    }
    
    $path = shift(@ARGV);
    $filepat = shift(@ARGV);
    $pat = shift(@ARGV);
    
    # Open pipe to get the list of files
    if ($windows) {
    	# Probably DOS/Windows
    	open(FLIST, "dir /b/s $path |") || die "Unable to get file list using dir: $!
    ";
    } else {
    	# Hope it's Unix
    	open(FLIST, "find $path -print |") || die "Unable to get file list using find: $!
    ";
    }
    
    file: while (<FLIST>) {
    	chop;
    	next unless (/${filepat}$/);
    	if ($windows) {
    		# Exclude implicit device names (e.g. /foo/prn.c)
    		next if (/\comd/i);
    		next if (/\lptd/i);
    		next if (/\prn/i);
    		next if (/\aux/i);
    	}
    	next unless (-f $_);
    	if (!open(FCONT, $fname = $_)) {
    		print STDERR "Unable to open file $_:$!
    ";
    		next file;
    	}
    	while (<FCONT>) {
    		print "$fname: $_" if ($_ =~ m/$pat/o);
    	}
    }
    
  • 相关阅读:
    gulp-API介绍
    前端构建工具gulpjs的使用介绍及技巧(转载)
    atom插件之less-autocompile
    atom-安装插件
    gulp入门1
    edp 基于node.js和npm的前端开发平台
    (转)详解JavaScript模块化开发
    require.js
    thinkcmf5 iis+php重写配置
    thinkcmf5 模板版变量的加载过程 和 新增网站配置项怎么全局使用
  • 原文地址:https://www.cnblogs.com/catgatp/p/9064541.html
Copyright © 2011-2022 走看看