GithubHelp home page GithubHelp logo

Comments (4)

luser-dr00g avatar luser-dr00g commented on May 3, 2024

Thanks for digging into this. It seems to me that the whole code could probably be simpler overall since it doesn't need to worry about partial digits like the <hex> syntax does.

for( n=0; !eof && n < S.comp_.sz; n++ ){
    do (c[0] = xpost_file_getc(f)) == EOF && ++eof; while( ! (eof || strchr(hex, c[0])) );
    if( !eof ){
        do (c[1] = xpost_file_getc(f)) == EOF && ++eof; while( ! (eof || strchr(hex, c[1])) );
        if( !eof ) s[n] = ((strchr(hex, toupper(c[0])) - hex) << 4)
                            |  (strchr(hex, toupper(c[1])) - hex);
    }
}
S.comp_.sz = n;

This version seems more correct given your analysis but I'll put it through some tests before committing. And probably the style I have here is too compact per our style rules. The do...while loops could probably be factored into a helper function with a descriptive name.

from xpost.

luser-dr00g avatar luser-dr00g commented on May 3, 2024

Oops. This still has the n++ problem you already diagnosed.

from xpost.

luser-dr00g avatar luser-dr00g commented on May 3, 2024

Take 2.

int readhexdigit( Xpost_File *f, int *p ){
    int eof = 0;
    do (*p = xpost_file_getc(f)) == EOF && ++eof;
    while( ! (eof || strchr(hex, *p)) );
    return eof;
}

for( n = 0; !eof && n < S.comp_.sz; n++ ){
    eof += readhexdigit(f, &c[0]);
    if( !eof ) eof += readhexdigit(f, &c[1]);
    if( eof ) break;
    s[n] = ((strchr(hex, toupper(c[0])) - hex) << 4) | (strchr(hex, toupper(c[1])) - hex);
}
S.comp_.sz = n;

from xpost.

luser-dr00g avatar luser-dr00g commented on May 3, 2024

Written, tested, committed, pushed.

from xpost.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.