Newlines in C function definition between function name and round bracket

Newlines in C function definition between function name and round bracket

7
NewbieNewbie
7

    Nov 01, 2010#1

    Hi I'm using ultraedit 14.20.1.1001 on Windows XP Service pack 3.

    My function strings are:
    /Function String = "%^([a-zA-Z_0-9^[^]*]+^)[ ^t]+^p^r^n([^p*&:, ^t^[^]a-zA-Z_0-9.!]++)[~;]"
    /Function String 1 = "%[a-zA-Z_0-9*]*::^([a-zA-Z_0-9^~]+^)[ ^t^p]++([^p*&:, ^t^[^]/*^-'=:&a-zA-Z_0-9./(!]++)[~;]"
    /Function String 2 = "%[a-zA-Z_0-9][a-zA-Z_0-9^[^]]+[ ^t*]+^([a-zA-Z_0-9]+^)[ ^t]++([^p*&:, ^t^[^]a-zA-Z_0-9./(!]++)[~;]"
    /Function String 3 = "%[a-zA-Z_0-9*&$^[^]*]+[ ^t]+[a-zA-Z_0-9*&$^[^]]+[ ^t*]+^([a-zA-Z_0-9]+^)[ ^t]++([^p*&:, ^t^[^]a-zA-Z_0-9./(!]++)[~;]"
    /Function String 4 = "%[a-z_0-9^[^]*]++ [a-z_0-9*^[^]]+[ ^t]++[a-z_0-9*^[^]]+[ ^t]++^([*a-z_0-9]+^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
    /Function String 5 = "%^([a-zA-Z_0-9^[^]*]+^)[ ^t]++([^p*&:, ^t^[^]a-zA-Z_0-9./()!]++)[~;]"

    I have some functions which are in the format:

    Code: Select all

    void func
    ( int param1,
      int param2
    )
    {
      .....
    }
    Functions written as above don't show up in my function list.
    I've tried modifying the regular expressions to account for the newline/CR between the function name and the parameter list to no avail. Does anyone know how to do this?

    Thank you.

    6,686585
    Grand MasterGrand Master
    6,686585

      Nov 02, 2010#2

      Use the following function strings taken from standard wordfile for C/C++ installed with UE v16.20.0.1011:

      /Function String = "%^([a-z_][a-z_0-9^[^]*]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./()!]++)[~;]"
      /Function String 1 = "%[a-z_][a-z_0-9^[^]:&]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t^p]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
      /Function String 2 = "%[a-z_][:a-z_0-9*&$^[^]*]++[ ^t]+[a-z_][:a-z_0-9*&$^[^]]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
      /Function String 3 = "%[a-z_][:a-z_0-9^[^]*&]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"
      /Function String 4 = "%[ ^t]++[a-z_][a-z_0-9^[^]:&]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++){++$"

      Note: I removed original function string 1 which is for C++ only, and made the small red highlighted change to find also those function definitions as in your example.

      Don't use ^r and ^n in function strings in the wordfile. In comparison to Find/Replace with UltraEdit regexp engine they are interpreted as letters R/r and letters N/n in function strings in the wordfile. ^p in the wordfile matches DOS, UNIX and MAC line terminations. That is special for function strings in wordfiles.
      Best regards from an UC/UE/UES for Windows user from Austria

      7
      NewbieNewbie
      7

        Nov 02, 2010#3

        I really appreciate that Mofi. I need to absorb that change. These function strings require a little concentration.

        Whoops. How are these function strings evaluated? Your solution helped with the newlines but I also have functions with newlines that are static, i. e. extra word:

        Code: Select all

        static int ParseCommandString
        (char *commandstring,
         int *record_source,
         int *debugmode,
         int *shutdown_all,
         message_control *message)
        {
        ...
        
        }
        Cheers.

        6,686585
        Grand MasterGrand Master
        6,686585

          Nov 04, 2010#4

          First, you should know that the regular expression searches executed with the defined regular expression strings are executed ALWAYS with option Match Case not enabled. Therefore the expression [A-Za-z] is equal [A-Z] and equal [a-z]. As for a not case sensitive expression all letters in range A-Z are converted to lower case before applying the regular expression, it is definitely enough to use only [a-z] whenever a letter in any case should be matched. [A-Za-z] can be nevertheless used, but it makes the expression string just longer in comparison to [a-z].

          /Function String = "%^([a-z_][a-z_0-9^[^]*]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./()!]++)[~;]"

          This regular expression is for functions without return type or return type above the line with the function name. Something like:

          foo1()
          foo2 (int)

          void
          foo3(void)

          If in your C files there is no such function definition because all have at least return type void or int on beginning the line with the function name, you should remove this function string from your wordfile to make updating the function list faster.

          % means start of line.

          ^(^) means tag the string found by the expression inside the round brackets. This part of the found string is displayed in the function list view. By looking for ^(^) you can quite easily identify for what type of function definition a regular expression is for as you can see below.

          [a-z_] means that the first character on the line must be a letter a-z in any case (always not case-sensitive search) or an underscore.

          [a-z_0-9^[^]*]++ there can follow zero or more occurrences of letters, underscores, square brackets and asterisk. Of course [] or * are only allowed at end of a function name.

          [ ^t]++ spaces or tabs can follow the function name. ++ means zero or more occurrences.

          ( means that the next character must be an opening round bracket.

          [^p*&:, ^t^[^]a-z_0-9./()!]++ matches zero or more occurrences of any of these characters. This expression matches the function parameter list which can also include line or block comments which is the reason for / being in this character set definition.

          ) the next character must be a closing round bracket.

          [~;] the character after closing round bracket is not allowed to be a semicolon to exclude function declarations.

          Note: In C files parameters can be passed only by value (int iValue) or by pointer (int *pValue). It is not possible to pass parameters by reference (int& iValue) as in C++. Therefore you could remove from all expressions all occurrences of &.

          Well, while writing the explanation for you I think that this regular expression is not really correct. The * can't be after the function name. It must be at start of the function name. So the expression should be:

          /Function String = "%^([a-z_*][a-z_0-9^[^]]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./()!]++)[~;]"

          And I'm also not sure about the square brackets. I have to read in a C and a C++ book if * or [] can be used at end of a function name. I never used that in my C and C++ files and therefore I'm not sure if C/C++ or only C++ allow such function definitions at all. It could be that this expression must be corrected.

          /Function String 1 = "%[a-z_][a-z_0-9^[^]:&]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t^p]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"

          If you compare that regular expression with the first one you will see that starting from ^( it is the same as the first one, except ^p which I inserted for your type of function definitions with ( on the next line. The inserted first part matches now the return type. So this function string is for something like:

          void foo1()
          int* foo2 (void)
          long *foo3(int iValue)

          /Function String 2 = "%[a-z_][:a-z_0-9*&$^[^]*]++[ ^t]+[a-z_][:a-z_0-9*&$^[^]]++[ ^t^p*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"

          This expression is for function definitions with 2 words left the function name. I inserted the ^p for matching also your example. Again I must look into the books if * is really possible between function name and opening round bracket.

          /Function String 3 = "%[a-z_][:a-z_0-9^[^]*&]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[a-z_][:a-z_0-9*&^[^]]++[ ^t]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++)[~;]"

          This expression is for function definitions with 3 words left the function name.

          /Function String 4 = "%[ ^t]++[a-z_][a-z_0-9^[^]:&]++[ ^t*]+[*&]++^([a-z_][a-z_0-9]++^)[ ^t]++([^p*&:, ^t^[^]a-z_0-9./(!]++){++$"

          This expression is for function definitions with spaces/tabs at start of the line followed by the return type and the function name. It is very unusual to start a function definition not at start of the line. You may remove that from your function string list if you don't have function definitions with preceding spaces/tabs.

          7
          NewbieNewbie
          7

            Nov 04, 2010#5

            I wish that IDM would put examples like that in their function string/regex help.

            Thanks

            1
            NewbieNewbie
            1

              Dec 03, 2010#6

              I recently wrote some function definition strings that work well for C/C++ functions

              They are ok for the cases in this forum

              The functions also add to the list C++ class and struct definition

              The UE version I developed them for is 13.20a+1

              Number 3 and 4 are for C++ class constructors and destructors

              /Function String = "%[ ^t]++[A-Za-z][~(){};^p|^^!]+[ ^t]^([A-Za-z][~(){};^p&|^^!]+^)[ ^t^p]++([~{};()]++)[~{};&|^^!]++{"
              /Function String 1 = "%[ ^t]++^(^{struct^}^{class^}[ ^t]++^{_export^}^{^}[ ^t]+[_a-zA-Z]+[a-zA-Z_0-9 ]++^)[~;]++{"
              /Function String 2 = "%[ ^t]++^([A-Za-z][A-Za-z_$]+::[A-Za-z~][A-Za-z_$]+^)[ ^t^p]++([~{};()]++)[ ^t^p]++^{{^}^{:^}"
              /Function String 3 = "%[ ^t]++^([A-Za-z][A-Za-z_$]+::~[A-Za-z_$]+^)[ ^t^p]++([~{};()]++)[ ^t^p]++{"

              7
              NewbieNewbie
              7

                Jan 10, 2013#7

                @amedeo:

                Your first string was causing false positives for "else if". I replaced it with the following:

                "%[ ^t]++[A-Za-z]+^(^{[A-Za-hj-z]^}^{i[~f^p]^}[~(){};^p|^^!]+[ ^t][A-Za-z][~(){};^p&|^^!]+^)[ ^t^p]++([~{};()]++)[~{};&|^^!]++{"

                Remove quotes ("...") to use.

                Thanks,
                Bassam