Jump to content

Recommended Posts

Posted (edited)

Hi All,

I have this sample C code.                                                                                                  

I would like to get some insights regarding my problem

My script should

(1) detecting pragma - this is easy

(2) I would like to detect if pragma is enclosing a specific function - (e.g. UB Func3 in line 28-36), not its declaration as in line 1-7

#pragma section
#pragma mode=far
static void Func1();
static void Func2();
static void Func3();
#pragma section=default
#pragma mode=default

/****************************************************************************************************************/
/*  ???   : UB Func1( void )                                                                                                                                   */
/****************************************************************************************************************/
UB Func1( void )
{
    UB rtn, jdg ;

    rtn = 0;
    return ( rtn ) ;
}

/****************************************************************************************************************/
/*  ???   : UB Func2( void )                                                                                                                                   */
/****************************************************************************************************************/
UB Func2( void )
{
    return ( SCRAP_METHODVER ) ;
}

#pragma ghs section text=".ra_scrap"
/****************************************************************************************************************/
/*  ???   : UB Func3( void )                                                                                                                                   */
/****************************************************************************************************************/
UB Func3( void )
{
    /* some code */
}
#pragma ghs section text=default

reason:

i would like to comment this pragma.

 

Thanks.

sample.au3

Edited by CiaronJohn
Posted

thanks @markyrocks,

I can now edit the file, here's my logic

$aArrayB = FileReadToArray($sourceCode[1])
Local $iLineCountA = @extended
If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
    Else
    For $i = 1 To $iLineCountA -1
        If StringInStr ($aArrayB[$i], '#pragma') Then
            $iPragma_Count = $iPragma_Count + 1   ; Pragma counter
        EndIf
    Next
EndIf

;~ Condition if Pragma is found
If $iPragma_Count > 0 Then
    ReDim $iLine_Count[$iLineCountA]
    ; Getting Line number of pragma
    For $i = 1 To $iLineCountA -1
        If StringInStr ($aArrayB[$i], '#pragma') Then
            $iLine_Count[$x] = $i
            $x = $x + 1
        EndIf
    Next
    $iFunction_Definition_Count = 0
    ReDim $iLine_Count[$x + 1]
    ; Loop for number of pragma found
    For $x = 0 To (UBound($iLine_Count) -1)
        ; loop for checking in-between of two consecutive pragmas
        If $iLine_Count[$x] <> "" Then
            For $k = $iLine_Count[$x] To $iLine_Count[$x+1]
                ; if next line is another pragma, proceed to next iteration of line
                If StringInStr ($aArrayB[$k], '関数名') Then
                    $iFunction_Definition_Count = $iFunction_Definition_Count + 1
                EndIf
            Next
            If $iFunction_Definition_Count = 1 Then
                    _FileWriteToLine($sourceCode[1], $iLine_Count[$x] + 1, '/* ' & $aArrayB[$iLine_Count[$x]]& ' */', 1)
                    _FileWriteToLine($sourceCode[1], $iLine_Count[$x+1] +1, '/* ' & $aArrayB[$iLine_Count[$x + 1]]& ' */', 1)
                    ; checking if there are
            EndIf
            $iFunction_Definition_Count = 0
        EndIf
    Next
EndIf

i will now create logic if there are 2 or more pragmas enclosing

#pragma section=".ra_scrap"
#pragma text=".ra_scrap"
/****************************************************************************************************************/
/*  ???   : UB Func3( void )                                                                                                                                   */
/****************************************************************************************************************/
UB Func3( void )
{
    /* some code */
}
#pragma section=default
#pragma text=default

thanks

Posted

AutoIT code will still result from error even if i send all the complete autoIT script, since most of its parameters are coming from confidential files.

Posted
Just now, CiaronJohn said:

AutoIT code will still result from error even if i send all the complete autoIT script, since most of its parameters are coming from confidential files.

When I say I need to see where a variable is coming from I'm referring to the declaration and subsequent changes.   I don't want to see your confidential files.  Sounds like someone needs a refund. 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...