Announcement

Collapse
No announcement yet.

Powerful yet easy ways to search PB source code with uCalc

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Powerful yet easy ways to search PB source code with uCalc

    uCalc patterns are ideal for searching through PB source code in ways that are not possible by other means, as far as I know. This statement is also a challenge for anyone reading this to point out other means you're aware of for easily performing the searches described below. uCalc is designed to handle many patterns concurrently. However, the simple examples here use mostly just one or two Find patterns.

    A few years ago, I took the time to consider over 80 items that performed searches, ranging from web browsing, word processing, and text editing tools, to IDEs, online search engines, grep tools, and operating system search tools. I even looked into search-related contributions by other PB users. I learned quite a bit. Many tools brought something interesting to the table. But I also found a category of searches that cannot be performed directly by other methods.



    IMPORTANT: You may want to permanently include a pattern that skips over comments (' {Comments: ".*"}) otherwise some examples in real world source code files may not work. You may also want to toggle Quote-sensitive to OFF for some examples if the code you're searching through has missing quotes.

    Find the word ANY in your source code (not case-sensitive):
    Code:
    Find: ANY
    Find only uppercase ANY:
    Code:
    Find: ANY           Toggle Case sensitive property
    Find words that start with ANY, but not the word ANY itself:
    Code:
    Find: {"ANY[a-z]+"}
    Find either ANY by itself, or words that start with ANY:
    Code:
    Find: {"ANY([a-z]+)?"}
    Find occurrences of ANY, but not when it's in a comment:
    Code:
    Find: ANY
    Find: ' {Comment}  [Skip over]     Note: Skip over property set to True
    Find the first 5 occurrences of ANY:
    Code:
    Find: ANY               Note: Set Stop after property to 5
    Find only the 5th occurrence of ANY:
    Code:
    Find: ANY               Note: Set Start after and Stop after properties to 4 and 1
    Find all occurrences of ANY only if there are at least 5 or more of them:
    Code:
    Find: ANY               Note: Set Min property to 5
    Find all occurrences of ANY only if there no more than 5 of them:
    Code:
    Find: ANY               Note: Set Max property to 5
    Find the word ANY only if it is not part of another word and it is not within quoted string literals:
    Note: This is actually the default behavior in uCalc Transform.
    Toggle the Quote sensitive property so it can searches within quotes.

    Code:
    Find: ANY               Note: Toggle the Quote sensitive property
    Find the word ANY only when it is not preceded by AS
    Code:
    Find: ANY
    Find: AS ANY  [Skip over]           Note: Skip over property set to True
    Find the AS ANY, regardless of spacing between AS and ANY:
    Code:
    Find: AS ANY
    Note: this is the default behavior

    Find AS ANY with exactly one space in between the two words:
    Code:
    Find: {"AS ANY"}
    Find the AS ANY only when it's in a comment:
    Code:
    Find: ' [{etc}] As Any
    Find ANY only when it's in a string literal:
    Code:
    Find: {q}[{etc}] Any
    Find occurrences of INSTR containing ANY in it:
    Code:
    Find: InStr([{n}, ] {MainStr}, ANY {MatchStr})
    Find occurrences of either InStr, Tally, or Trim with ANY in it:
    Code:
    Find: { InStr | Tally | Trim$ } ({arg}, ANY {Match})
    Find occurrences of any string function with ANY in it:
    Code:
    Find: {func:1}[$]({args}, ANY {Match})
    Find occurrences of any string function with ANY,
    except for InStr, Tally, or Trim$:
    Code:
    Find: {func:1}[$]({args}, ANY {Match})
    Find:      [Skip over]
    Find Chr$() only when it has two or more arguments:
    Code:
    Find: Chr$({arg1}, {MoreArgs})
    Find Chr$() only when it has exactly 2 arguments:
    Code:
    Find: Chr$({arg1}, {arg2})
    Find: Chr$({arg1}, {arg2}, {MoreArgs})      [Skip over]
    Find Chr$() with one arg that is a string literal within quotes:
    Code:
    Find: Chr$({q}{text}{q})
    Find Cb. allong with the subsequent keyword:
    Code:
    Find: Cb.{word:1}
    Find all pointer members of a pointer
    Code:
    Find: @{item:1}.@{member:1}
    Find Dim statements in the form of Dim variables As Local
    Code:
    Find: Dim {def} As Local
    Find Chr$() which contains a range in it:
    Code:
    Find: Chr$({etc1} To {etc2})
    Find MsgBox only as a function:
    Code:
    Find: MsgBox({args})
    Find MsgBox statement only when the title$ arg is used:
    Code:
    Find: MsgBox {txt}, [{style}], {title}
    Find MsgBox function with only when %MB_ICONERROR is the style:
    Code:
    Find: MsgBox({txt}, %MB_ICONERROR [, {etc}])
    Find MsgBox function when %MB_ICONERROR is part of the style:
    Code:
    Find: MsgBox({txt}, [{etc}]%MB_ICONERROR [{etc2}])
    Find MsgBox statement where a numeric argument is used for the style instead of equates:
    Code:
    Find: MsgBox {txt}, {number:" *[0-9]+"}
    Find a FOR/NEXT only when it has a STEP in it
    Code:
    Find: For {count} = {start} To {stop} STEP {increment}
    Find FOR/NEXT blocks containing an EXIT FOR in it:
    Code:
    Find: FOR {etc}{nl}
             [{SomeCode+}]
             EXIT FOR
             [{MoreCode+}]
          NEXT
    Find Sub with Optional ByRef String Arg
    Code:
    Find: Sub {etc} ([{etc2}] { Optional | Opt } [{etc3}] ByRef {arg} As String [{etc4}] )
    Find BIT SET or BIT RESET or BIT TOGGLE:
    Code:
    Find: BIT { SET | RESET | TOGGLE }
    Find all Type/End Type blocks that contain exactly one member
    Code:
    Find: {nl}Type {etc}{nl}
              {member}
            {nl}End Type
    Find: Type Set [Skip over]
    Find file OPEN statements where the optional # is used in front of the file number:
    Code:
    Find: OPEN {etc} AS #{etc2}
    Find numbers in the &H... hex notation:
    Code:
    Find: {"&H[0-9a-f]+"}
    Find all comments (in ' form):
    Code:
    Find: ' {Comment:".*"}
    Find comments only at the start of a line:
    Code:
    Find: {nl} ' {Comment:".*"}
    Find all comments, starting only after the 5th one:
    Code:
    Find: ' {Comment:".*"}         Set Start after property to 5
    Find string literals that have an opening quote, but not a closing quote:
    Code:
    Find: {"\q[\q\n]*\n"}
    Find single-line IF statements:
    Code:
    Find: If {cond} Then {Statement}
    Find single-line IF with multiple statements:
    Code:
    Find: If {cond} Then {Statement}:{MoreStatements}
    Find multi-line IF block:
    Code:
    Find: If {cond} Then {nl}
            {code+}
         End If
    Find CONTROL ADD BUTTON only when it has a callback:
    Code:
    Find: CONTROL BUTTON {etc} Call {callback}
    Find CONTROL ADD for any control, when it has a callback:
    Code:
    Find: CONTROL ADD {etc} CALL {callback}
    Find CONTROL ADD occurrences that don't have a callback:
    Code:
    Find: CONTROL ADD {etc} Call
    Find: CONTROL ADD {etc} Call {callback}   [Skip over]
    Find occurrences of COMBOBOX with exactly 8 tokens in between COMBOBOX and TO:
    Code:
    Find: COMBOBOX {tokens:8} TO
    Find any control statement with "Click me" passed as one of the arguments:
    Code:
    Find: CONTROL {etc}, {q}Click me{q} [{etc2}]
    Find any control with %IDTEXT as an argument
    Code:
    Find: CONTROL {etc}, IdMyText [{etc2}]
    Given that ArcSinH = LOG(x + Sqr(x*x+1))
    Find math expressions that match the ArcSinH formula:
    Code:
    Find: LOG({x} + Sqr({x}*{x}+1)
    Find occurrences of MID$ as a statement instead of as a function:
    Code:
    Find: {Sep: {nl} | : | Then | Else } Mid$({args})
    Find occurrences of VarPtr of the first element of any array:
    Code:
    Find: VarPtr({ArrayName}(0))
    Find ARRAY SORT with CALL
    Code:
    Find: ARRAY SORT {etc} CALL {func}
    Find SUBs that have EXPORT, but do not have ALIAS
    Code:
    Find: SUB {etc} EXPORT
    Find: SUB {etc} ALIAS     [Skip over]
    Find PRINT statements that end with a ; (semicolon)
    Code:
    Find: PRINT {etc}; { {nl} | : }
    Find PRINT statements that end with either a ; (semicolon) or a , (comma)
    Code:
    Find: PRINT {etc>} { ; || , } { {nl} | : }
    Find all functions defined with a String return value:
    Code:
    Find: Function [{etc}] [({args})] As String

    Find only functions defined before PBMain
    Code:
    Find: [Thread] Function {etc}
    Find: {nl}Function PBMain {ToTheEnd:"[\x00-\xFF]+"}     [Skip over]
    Find all ASM statements:
    Code:
    Find: {nl}{ ASM | ! } {code}
    Find all ASM statements that contain a comment:
    Code:
    Find: {nl}{ ASM | ! } {code} ; {comment}
    Find all variables, args or members defined as pointer
    Code:
    Find: As {type:1} Ptr
    Find string literals that start with a quote but do not have a closing quote:
    Code:
    Find: {StringLiteral:"\q[^\q\n]*\n"}
    Find Declare statement spanning more than one line; and the line separator might have a comment:
    Code:
    Find: Declare {etc} _ [{comment}] {nl}    Note: Set Code block to FALSE
    Givien lines such as:
    #Resource Icon logo "\icons\logo.ico"
    #Resource Icon restart "\icons\restart.ico"
    Find the just the icons file names (just the file)
    Code:
    Find: {file:1}.ico       Note: Toggle Quote sensitive OFF
    Find occurrences of all PB keywords:
    Code:
    Find: {Keyword: {@Eval: Retain(File("PBKeywords.txt"), "{'.*'}", Delim(" | ")) } }
    Find numeric equate definitions:
    Code:
    Find: {nl}%{Equate}
    Find equate occurrences other than equate definitions:
    Code:
    Find: %{Equate:1}
    Find: {nl}%    [Skip over]
    Find equates set to a hex number
    Code:
    Find: {nl}%{Equate} = &{"h[0-9a-f]+"}
    Find all string literals that are 15 characters long:
    Code:
    Find: {chars:"\q[^\q]{15}\q"}
    Find a Format$() statement with "##" as the second arg:
    Code:
    Find: Format$({arg1}, {q}##{q})
    Find occurrences of Max or Min with 5 or more args:
    Code:
    Find: { Max | Min }[{& | $}]({arg1}, {arg2}, {arg3}, {arg4}, {more})

    Some of these can be tested with FindTest.Bas.
    Try some of the others on your own code, or code posted in the forums, or sample programs that come with PB.
    Daniel Corbier
    uCalc Fast Math Parser
    uCalc Language Builder
    sigpic
Working...
X