• Bug in xHarbour

    From Enrico Maria Giordano@e.m.giordano@emagsoftware.it to comp.lang.xharbour on Tue Nov 25 11:53:08 2025
    From Newsgroup: comp.lang.xharbour

    Somebody could help me to fix this bug?

    FUNCTION MAIN()

    ? TEST1(), "< /b>" $ TEST1(), LEN( TEST1() )
    ? TEST2(), "< /b>" $ TEST2(), LEN( TEST2() )
    ? [</b>], "< /b>" $ [</b>], LEN( [</b>] )

    INKEY( 0 )

    RETURN NIL


    STATIC FUNCTION TEST1()

    RETURN [</b>]


    STATIC FUNCTION TEST2()

    LOCAL cStr := [</b>]

    RETURN cStr

    Result:

    < /b> .T. 5
    </b> .F. 4
    </b> .F. 4

    Expected:

    </b> .F. 4
    </b> .F. 4
    </b> .F. 4
    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Leonardo Rufino@leonardorufino@servinn.com.br to comp.lang.xharbour on Tue Nov 25 16:21:28 2025
    From Newsgroup: comp.lang.xharbour

    I can't compile it and I don't know much about C, but after talking to chatgpt, he generated this in the PP_NextLine function of the pp.c file:

    int PP_NextLine(FILE *pPPO, char *sLine, PARSER_CONTEXT *Parser_pContext)
    {
    char cChar, cLastChar = 0;
    char *pSemiColon = NULL;
    char cTerminator = 0;

    PP_iLineLen = 0;

    while ((cChar = getc(Parser_pContext->Files.pLast->hFile)) != EOF)
    {
    if (Parser_pContext->iLine && (Parser_pContext->iLine % 100) ==
    0 && Parser_pContext->bMute == FALSE)
    {
    printf("\r%i", Parser_pContext->iLine);
    fflush(stdout);
    }

    // printf( "Pos: %i, Char: %c pSemiColon: %p\n", PP_iLineLen,
    cChar, pSemiColon );

    if (cChar == '\n')
    {
    Parser_pContext->iLine = ++Parser_pContext->Files.pLast->iLine;

    while (PP_iLineLen && isspace(PP_LineBuffer[--PP_iLineLen]))
    {
    }

    if (PP_iLineLen == 0)
    {
    continue;
    }

    if (PP_LineBuffer[PP_iLineLen] == ';')
    {
    // Override the semi colon and continue with next line.
    // printf( "Continue after ';' at: %i\n", PP_iLineLen );
    pSemiColon = NULL;
    continue;
    }

    ++PP_iLineLen;

    PP_LineBuffer[PP_iLineLen++] = '\n';
    break;
    }
    else if (cTerminator == 0 && pSemiColon == NULL && cChar == ';')
    {
    pSemiColon = PP_LineBuffer + PP_iLineLen;
    cLastChar = cChar;
    }
    else if (cTerminator == 0 && pSemiColon && !isspace(cChar))
    {
    ungetc(cChar, Parser_pContext->Files.pLast->hFile);

    while (PP_LineBuffer[--PP_iLineLen] != ';')
    {
    ungetc(PP_LineBuffer[PP_iLineLen], Parser_pContext->Files.pLast->hFile);
    }

    PP_LineBuffer[PP_iLineLen++] = '\n';
    break;
    }
    else
    {
    if (cTerminator)
    {
    if (cChar == cTerminator)
    {
    cTerminator = 0;
    cLastChar = cChar;
    }
    }
    else
    {
    if (cChar == '"')
    {
    cTerminator = '"';
    }
    else if (cChar == '\'')
    {
    cTerminator = '\'';
    }
    else if (cChar == '[')
    {
    BOOL bLiteral = FALSE;

    /* Regra original: '[' depois de char n|uo
    alfanum|-rico e n|uo pertencendo a ")]}.\"'" */
    if (!isalnum(cLastChar) && strchr(")]}.\"'",
    cLastChar) == NULL)
    {
    bLiteral = TRUE;
    }
    else
    {
    /* NOVO: tratar 'RETURN [ ... ]' como literal
    entre colchetes */
    int i = 0, j = 0;
    char kw[7] = {0};

    /* pula espa|oos do in|!cio da linha */
    while (i < PP_iLineLen &&
    isspace(PP_LineBuffer[i]))
    i++;

    /* l|- at|- 6 letras em mai||sculo para comparar
    com "RETURN" */
    while (i < PP_iLineLen &&
    j < 6 &&
    isalpha(PP_LineBuffer[i]))
    {
    kw[j++] = (char)toupper(PP_LineBuffer[i]);
    i++;
    }

    if (j == 6 && memcmp(kw, "RETURN", 6) == 0)
    {
    /* entre o fim de RETURN e o '[' atual s||
    pode ter espa|oo */
    while (i < PP_iLineLen && isspace(PP_LineBuffer[i]))
    i++;

    if (i == PP_iLineLen)
    {
    /* a linha |- basicamente "RETURN [..."; tratamos como literal */
    bLiteral = TRUE;
    }
    }
    }

    if (bLiteral)
    {
    cTerminator = ']';
    }
    else if (!isspace(cChar))
    {
    cLastChar = cChar;
    }
    }
    else if (!isspace(cChar))
    {
    cLastChar = cChar;
    }
    }
    }

    PP_LineBuffer[PP_iLineLen++] = cChar;
    }

    // printf( "Len: %i\n", PP_iLineLen );

    if (PP_iLineLen)
    {
    strncpy(sLine, PP_LineBuffer, PP_iLineLen);
    sLine[PP_iLineLen] = '\0';
    // printf( "Source: >%s<\n", sLine );
    }
    else
    {
    // printf( "EOF!\n" );
    }

    return PP_iLineLen;
    }



    Em 25/11/2025 07:53, Enrico Maria Giordano escreveu:
    Somebody could help me to fix this bug?

    FUNCTION MAIN()

    -a-a-a ? TEST1(), "< /b>" $ TEST1(), LEN( TEST1() )
    -a-a-a ? TEST2(), "< /b>" $ TEST2(), LEN( TEST2() )
    -a-a-a ? [</b>], "< /b>" $ [</b>], LEN( [</b>] )

    -a-a-a INKEY( 0 )

    -a-a-a RETURN NIL


    STATIC FUNCTION TEST1()

    -a-a-a RETURN [</b>]


    STATIC FUNCTION TEST2()

    -a-a-a LOCAL cStr := [</b>]

    -a-a-a RETURN cStr

    Result:

    < /b> .T.-a-a-a-a-a-a-a-a-a 5
    </b> .F.-a-a-a-a-a-a-a-a-a 4
    </b> .F.-a-a-a-a-a-a-a-a-a 4

    Expected:

    </b> .F.-a-a-a-a-a-a-a-a-a 4
    </b> .F.-a-a-a-a-a-a-a-a-a 4
    </b> .F.-a-a-a-a-a-a-a-a-a 4


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Enrico Maria Giordano@e.m.giordano@emagsoftware.it to comp.lang.xharbour on Tue Nov 25 21:17:31 2025
    From Newsgroup: comp.lang.xharbour



    Il 25/11/2025 20:21, Leonardo Rufino ha scritto:

    I can't compile it and I don't know much about C, but after talking to chatgpt, he generated this in the PP_NextLine function of the pp.c file:

    int PP_NextLine(FILE *pPPO, char *sLine, PARSER_CONTEXT *Parser_pContext)

    This function does not exist in the xHarbour repository. :-(

    Me too had a loooong session with Copilot with no result so far.
    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Leonardo Rufino@leonardorufino@servinn.com.br to comp.lang.xharbour on Tue Nov 25 17:36:20 2025
    From Newsgroup: comp.lang.xharbour

    Em 25/11/2025 17:17, Enrico Maria Giordano escreveu:


    Il 25/11/2025 20:21, Leonardo Rufino ha scritto:

    I can't compile it and I don't know much about C, but after talking to
    chatgpt, he generated this in the PP_NextLine function of the pp.c file:

    int PP_NextLine(FILE *pPPO, char *sLine, PARSER_CONTEXT *Parser_pContext)

    This function does not exist in the xHarbour repository. :-(

    Me too had a loooong session with Copilot with no result so far.



    I found it here: https://github.com/xHarbour-org/xharbour/blob/main/xHarbourBuilder/x/Source/Compiler/pp.c
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Enrico Maria Giordano@e.m.giordano@emagsoftware.it to comp.lang.xharbour on Wed Nov 26 00:00:34 2025
    From Newsgroup: comp.lang.xharbour



    Il 25/11/2025 21:36, Leonardo Rufino ha scritto:

    This function does not exist in the xHarbour repository. :-(

    I found it here: https://github.com/xHarbour-org/xharbour/blob/main/ xHarbourBuilder/x/Source/Compiler/pp.c

    xHarbour Builder has nothing to do with xHarbour.
    --
    Enrico Maria Giordano

    http://www.emagsoftware.it
    http://www.emagsoftware.it/emgmusic
    http://www.emagsoftware.it/spectrum
    http://www.emagsoftware.it/tbosg
    --- Synchronet 3.21a-Linux NewsLink 1.2