⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 search.pl

📁 UNIX下perl实现代码
💻 PL
📖 第 1 页 / 共 4 页
字号:
.TP.BI -dpath " GLOB"This option exists, but is probably not very useful. It probably wants tobe like the '-below' or something I mention in the "TODO" section..TP.BI -idpath " GLOB"Case-insensitive version of.BR -dpath ..TP.BI -idskip " GLOB"Case-insensitive version of.BR -dskip ..TP.BI -idregex " REGEX"Case-insensitive version of.BR -dregex ..TP.B -allIgnore any 'magic' or 'option' lines in the startup file.The effect is that all files that would otherwise be automaticallyexcluded are considered..TP.BI -x SPECIALArguments starting with.B -x(except.BR -xdev ,explained elsewhere) do special interaction with the.I ~/.searchstartup file. Something like.nf	-xflag1 -xflag2.fiwill turn on "flag1" and "flag2" in the startup file (and isthe same as "-xflag1,flag2"). You can use this to write your ownrules for what kinds of files are to be considered.For example, the internal-default startup file contains the line.nf	<!~> option: -skip '~ #'.fiThis means that if the.B -x~flag is.I notseen, the option.nf    -skip '~ #'.fishould be done.The effect is that emacs temp and backup files are not normallyconsidered, but you can included them with the -x~ flag.You can write your own rules to customize.I searchin powerful ways. See the STARTUP FILE section below..TP.B -whyPrint a message (to stderr) when and why a file is not considered..SH "OPTIONS TELLING WHAT TO DO WITH FILES THAT WILL BE CONSIDERED".TP.B -find(you can use.B -fas well).This option changes the basic action of.IR search .Normally, if a file is considered, it is searchedfor the regular expressions as described earlier. However, if this optionis given, the filename is printed and no searching takes place. This turns.I searchinto a 'find' of some sorts.In this case, no regular expressions are needed on the command line(any that are there are silently ignored).This is not intended to be a replacement for the 'find' program,but to aidyou in understanding just what files are getting past the exclusion checks.If you really want to use it as a sort of replacement for the 'find' program,you might want to use.B -allso that it doesn't waste time checking to see if the file is binary, etc(unless you really want that, of course).If you use.BR -find ,none of the "GREP-LIKE OPTIONS" (below) matter.As a replacement for 'find',.I searchis probably a bit slower (or in the case of GNU find, a lot slower --GNU find is.I unbelievablyfast).However, "search -ffind"might be more useful than 'find' when options such as.B -skipare used (at least until 'find' gets such functionality)..TP.B -ffind(or.BR -ff )A faster more 'find'-like find. Does.nf    -find  -all -dorep.fi.SH "GREP-LIKE OPTIONS"These options control how a searched file is accessed,and how things are printed..TP.B -iIgnore letter case when matching..TP.B -wConsider only whole-word matches ("whole word" as defined by perl's "\\b"regex)..TP.B -uIf the regex(es) is/are simple, try to modify them so that they'll workin manpage-like underlined text (i.e. like _^Ht_^Hh_^Hi_^Hs).This is very rudimentary at the moment..TP.B -list(you can use.B -ltoo).Don't print matching lines, but the names of files that contain matchinglines. This will likely be *much* faster, as special optimizations aremade -- particularly with large files..TP.B -nPepfix each line by its line number..TP.B -niceNot a grep-like option, but similar to.BR -list ,so included here..B -nicewill have the output be a bit more human-readable, with matching lines printedslightly indented after the filename, a'la.nf   % search foo   somedir/somefile: line with foo in it   somedir/somefile: some food for thought   anotherdir/x: don't be a buffoon!   %.fiwill become.nf   % search -nice foo   somedir/somefile:     line with foo in it     some food for thought   anotherdir/x:     don't be a buffoon!   %.fiThis option due to Lionel Cons..TP.B -nniceBe a bit nicer than.BR -nice .Prefix each file's output by a rule line, and follow with an extra blank line..TP.B -hDon't prepend each output line with the name of the file(meaningless when.B -findor.B -lare given)..SH "OTHER OPTIONS".TP.B -helpPrint the usage information..TP.B -versionPrint the version information and quit..TP.B -vSet the level of message verbosity..B -vwill print a note whenever a new directory is entered..B -vvwill also print a note "every so often". This can be useful to seewhat's happening when searching huge directories..B -vvvwill print a new with every file..B -vvvvis-vvvplus.BR -why ..TP.B -eThis ends the options, and can be useful if the regex begins with '-'..TP.B -showrcShows what is being considered in the startup file, then exits..TP.B -dorepNormally, an identical file won't be checked twice (even with multiplehard or symbolic links). If you're just trying to do a fast.BR -find ,the bookkeeping to remember which files have been seen is not desirable,so you can eliminate the bookkeeping with this flag..SH "STARTUP FILE"When.I searchstarts up, it processes the directives in.IR ~/.search .If no such file exists, a defaultinternal version is used.The internal version looks like:.nf   magic: 32 : $H =~ m/[\ex00-\ex06\ex10-\ex1a\ex1c-\ex1f\ex80\exff]{2}/   option: -skip '.a .COM .elc .EXE .gz .o .pbm .xbm .dvi'   option: -iskip '.tarz .zip .z .lzh .jpg .jpeg .gif .uu'   <!~> option: -skip '~ #'.fiIf you wish to create your own "~/.search",you might consider copying the above, and then working from there.There are two kinds of directives in a startup file: "magic" and "option"..RS 0n.TPOPTIONOption lines will automatically do the command-line options given.For example, the line.nf	option: -v.fiin you startup file will turn on -v every time, without needing to type iton the command line.The text on the line after the "option:" directive is processedlike the Bourne shell, so make sure to pay attention to quoting..nf	option: -skip .exe .com.fiwill give an error (".com" by itself isn't a valid option), while.nf	option: -skip ".exe .com".fiwill properly include it as part of -skip's argument..TPMAGICMagic lines are used to determine if a file should be considered a binaryor not (the term "magic" refers to checking a file's magic number).  Theseare described in more detail below..REBlank lines and comments (lines beginning with '#') are allowed.If a line begins with  <...>, then it's a check to see if thedirective on the line should be done or not. The stuff inside the <...>can contain perl's && (and), || (or), ! (not), and parens for grouping,along with "flags" that might be indicated by the user with.BI -x flagoptions.For example, using "-xfoo" will cause "foo" to be true inside the <...>blocks. Therefore, a line beginning with "<foo>" would be done only when"-xfoo" had been specified, while a line beginning with "<!foo>" would bedone only when "-xfoo" is not specified (of course, a line without any <...>is done in either case).A realistic example might be.nf	<!v> -vv.fiThis will cause -vv messages to be the default, but allow "-xv" to override.There are a few flags that are set automatically:.RS.TP.B TTYtrue if the output is to the screen (as opposed to being redirected to a file).You can force this (as with all the other automatic flags) with -xTTY..TP.B -vTrue if -v was specified. If -vv was specified, both .B -vand.B -vvflags are true (and so on)..TP.B -niceTrue if -nice was specified. Same thing about -nnice as for -vv..PP.TP.B -listtrue if -list (or -l) was given..TP.B -dirtrue if -dir was given..REUsing this info, you might change the last example to.nf    <!v && !-v> option: -vv.fiThe added "&& !-v" means "and if the '-v' option not given".This will allow you to use "-v" alone on the command line, and nothave this directive add the more verbose "-vv" automatically..RS 0Some other examples:.TP<!-dir && !here> option: -dir ~/Effectively make the default directory your home directory (instead of thecurrent directory). Using -dir or -xhere will undo this..TP<tex> option: -name .tex -dir ~/pubCreate '-xtex' to search only "*.tex" files in your ~/pub directory tree.Actually, this could be made a bit better. If you combine '-xtex' and '-dir'on the command line, this directive will add ~/pub to the list, when youprobably want to use the -dir directory only. You could do.nf   <tex> option: -name .tex   <tex && !-dir> option: -dir ~/pub.fito will allow '-xtex' to work as before, but allow a command-line "-dir"to take precedence with respect to ~/pub..TP<fluff> option: -nnice -sort -i -vvvCombine a few user-friendly options into one '-xfluff' option..TP<man> option: -ddir /usr/man -v -wWhen the '-xman' option is given, search "/usr/man" for whole-words(of whatever regex or regexes are given on the command line), with -v..REThe lines in the startup file are executed from top to bottom, so somethinglike.nf   <both> option: -xflag1 -xflag2   <flag1> option: ...whatever...   <flag2> option: ...whatever....fiwill allow '-xboth' to be the same as '-xflag1 -xflag2' (or '-xflag1,flag2'for that matter). However, if you put the "<both>" line below the others,they will not be true when encountered, so the result would be different(and probably undesired).The "magic" directives are used to determine if a file looks to be binaryor not. The form of a magic line is.nf    magic: \fISIZE\fP : \fIPERLCODE\fP.fiwhere.I SIZEis the number of bytes of the file you need to check, and.I PERLCODEis the code to do the check. Within.IR PERLCODE ,the variable $H will hold at least the first.I SIZEbytes of the file (unless the file is shorter than that, of course).It might hold more bytes. The perl should evaluate to true if the fileshould be considered a binary.An example might be.nf    magic: 6 : substr($H, 0, 6) eq 'GIF87a'.fito test for a GIF ("-iskip .gif" is better, but this might be usefulif you have images in files without the ".gif" extension).Since the startup file is checked from top to bottom, you can be a bitefficient:.nf    magic: 6 : ($x6 = substr($H, 0, 6)) eq 'GIF87a'    magic: 6 :  $x6                     eq 'GIF89a'.fiYou could also write the same thing as.nf  magic: 6 : (($x6 = substr($H, 0, 6)) eq 'GIF87a') || ## an old gif, or.. \e	       $x6                     eq 'GIF89a'     ## .. a new one..fisince newlines may be escaped.The default internal startup file includes.nf   magic: 32 : $H =~ m/[\ex00-\ex06\ex10-\ex1a\ex1c-\ex1f\ex80\exff]{2}/.fiwhich checks for certain non-printable characters, and catches a largenumber of binary files, including most system's executables, linkableobjects, compressed, tarred, and otherwise folded, spindled, and mutilatedfiles.Another example might be.nf    ## an archive library    magic: 17 : substr($H, 0, 17) eq "!<arch>\en__.SYMDEF".fi.SH "RETURN VALUE".I Searchreturns zero if lines (or files, if appropriate) were found,or if no work was requested (such as with.BR -help ).Returns 1 if no lines (or files) were found.Returns 2 on error..SH TODOThings I'd like to add some day:.nf  + show surrounding lines (context).  + highlight matched portions of lines.  + add '-and', which can go between regexes to override    the default logical or of the regexes.  + add something like      -below GLOB    which will examine a tree and only consider files that    lie in a directory deeper than one named by the pattern.  + add 'warning' and 'error' directives.  + add 'help' directive..fi.SH BUGSIf -xdev and multiple -dir arguments are given, any file in any of thetarget filesystems are allowed. It would be better to allow each filesystemfor each separate tree.Multiple -dir args might also cause some confusing effects. Doing.nf   -dir some/dir -dir other.fiwill search "some/dir" completely, then search "other" completely. Thisis good. However, something like.nf   -dir some/dir -dir some/dir/more/specific.fiwill search "some/dir" completely *except for* "some/dir/more/specific",after which it will return and be searched. Not really a bug, but just sortof odd.File times (for -newer, etc.) of symbolic links are for the file, not thelink. This could cause some misunderstandings.Probably more. Please let me know..SH AUTHORJeffrey Friedl, Omron Corp (jfriedl@omron.co.jp).brhttp://www.wg.omron.co.jp/cgi-bin/j-e/jfriedl.html.SH "LATEST SOURCE"See http://www.wg.omron.co.jp/~jfriedl/perl/index.html

⌨️ 快捷键说明

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