• Great code

    From Bonita Montero@3:633/10 to All on Mon Jun 15 11:10:46 2026
    I've written a tool called "bg" to combine Windows' runas with start.
    One parameter is the affinity-mask for the processors which the star-
    ted program is attached to. The below code is the parsing function.
    The code wouldn't apply if this function has to be performance since
    I work with regexes. But having this this way makes the code rather
    short for what is required - imagine you'd have to do that in C.

    bool params::state::checkAffinity( params &pms )
    {
    if( _wcsicmp( m_todo.front(), L"--affinity" ) != 0 )
    return false;
    if( m_todo.size() < 2 )
    {
    m_todo = {};
    m_errs.emplace_back( L"please specify affinity" );
    cerr << "" << endl;
    return false;
    };
    DWORD_PTR dwpAff = 0;
    match_results<wstring_view::iterator> match;
    defer chop2( [&] { m_todo = m_todo.subspan( 2 ); } );
    wstring_view svPattern( m_todo[1] );
    constexpr const wchar_t
    *RxHex = L"^0x([0-9a-f]+)$",
    *RxBin = sizeof( DWORD_PTR ) == 8 ? L"^b((?:[01]+){1,64})$" : L"^b((?:[01]+){1,32})$",
    *RxRange = L"^([0-9]+)(?:-([0-9]+))?(,)?";
    if( wregex rxHex( RxHex, regex_constants::icase ); regex_match( svPattern.begin(), svPattern.end(), match, rxHex ) )
    wistringstream( wstring( svPattern ) ) >> hex >> dwpAff;
    else if( wregex rxBinary( RxBin, regex_constants::icase );
    regex_match( svPattern.begin(), svPattern.end(), match, rxBinary ) )
    for( wchar_t c : wstring_view( match[1].first, match[1].second ) )
    dwpAff = dwpAff << 1 | (c - '0');
    else
    {
    defer affZero( [&] { dwpAff = 0; } );
    auto it = svPattern.begin();
    wregex rx( RxRange );
    match_results<wstring_view::iterator> match;
    for( ; regex_search( it, svPattern.end(), match, rx ); it = match[0].second )
    {
    if( match[3].matched && match[3].second == svPattern.end() )
    break;
    unsigned from, to;
    wistringstream( wstring( match[1].first, match[1].second )
    ) >> from;
    if( match[2].matched )
    {
    wistringstream( wstring( match[2].first,
    match[2].second ) ) >> to;
    ++to;
    }
    else
    to = from + 1;
    constexpr unsigned BITS = sizeof(ULONG_PTR) * 8;
    if( from >= to || from >= BITS || to > BITS )
    break;
    constexpr DWORD_PTR ALL = -1;
    DWORD_PTR dwpBits = ALL << from;
    if( to < BITS )
    dwpBits &= ~(ALL << to);
    dwpAff |= dwpBits;
    }
    if( it == svPattern.end() )
    affZero.disable();
    }
    if( !dwpAff )
    {
    wostringstream woss;
    woss << "invalid affinity pattern: " << svPattern;
    m_errs.emplace_back( woss.str() );
    return true;
    }
    DWORD_PTR dwpProc, dwpSys;
    GetProcessAffinityMask( GetCurrentProcess(), &dwpProc, &dwpSys );
    if( (dwpAff &= dwpProc) )
    pms.dwpAffinity = dwpAff;
    return true;
    }

    --- PyGate Linux v1.5.16
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Scott Lurndal@3:633/10 to All on Mon Jun 15 14:41:12 2026
    Bonita Montero <Bonita.Montero@gmail.com> writes:
    I've written a tool called "bg" to combine Windows' runas with start.

    Which as nothing to do with either C or C++. Did you post
    to the wrong group again?


    --- PyGate Linux v1.5.16
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Mon Jun 15 17:32:19 2026
    Am 15.06.2026 um 16:41 schrieb Scott Lurndal:

    Bonita Montero <Bonita.Montero@gmail.com> writes:

    I've written a tool called "bg" to combine Windows' runas with start.

    Which as nothing to do with either C or C++. Did you post
    to the wrong group again?

    The code is in C++, and the discussion centered on the
    advantages of the C++ methodology over that of C.

    --- PyGate Linux v1.5.16
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From boltar@3:633/10 to All on Tue Jun 16 08:13:08 2026
    On Mon, 15 Jun 2026 17:32:19 +0200
    Bonita Montero <Bonita.Montero@gmail.com> gabbled:
    Am 15.06.2026 um 16:41 schrieb Scott Lurndal:

    Bonita Montero <Bonita.Montero@gmail.com> writes:

    I've written a tool called "bg" to combine Windows' runas with start.

    Which as nothing to do with either C or C++. Did you post
    to the wrong group again?

    The code is in C++, and the discussion centered on the
    advantages of the C++ methodology over that of C.

    Not sure why you feel the need to do that on a C++ group. Preaching to the converted is a phrase that comes to mind.


    --- PyGate Linux v1.5.17
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Bonita Montero@3:633/10 to All on Tue Jun 16 13:56:10 2026
    Am 16.06.2026 um 10:13 schrieb boltar@caprica.universe:
    On Mon, 15 Jun 2026 17:32:19 +0200
    Bonita Montero <Bonita.Montero@gmail.com> gabbled:
    Am 15.06.2026 um 16:41 schrieb Scott Lurndal:

    Bonita Montero <Bonita.Montero@gmail.com> writes:

    I've written a tool called "bg" to combine Windows' runas with start.

    Which as nothing to do with either C or C++.ÿÿ Did you post
    to the wrong group again?

    The code is in C++, and the discussion centered on the
    advantages of the C++ methodology over that of C.

    Not sure why you feel the need to do that on a C++ group. Preaching to the converted is a phrase that comes to mind.

    I've set the Follow-Up initially. But Scott redirected to comp.lang.c.
    My initial objection was to compare between C and C++ in terms of code
    size with this example.


    --- PyGate Linux v1.5.17
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Tue Jun 16 13:13:02 2026
    On 6/15/2026 2:10 AM, Bonita Montero wrote:
    I've written a tool called "bg" to combine Windows' runas with start.
    One parameter is the affinity-mask for the processors which the star-
    ted program is attached to. The below code is the parsing function.
    The code wouldn't apply if this function has to be performance since
    I work with regexes. But having this this way makes the code rather
    short for what is required - imagine you'd have to do that in C.
    [...]

    How about run as and on...

    It gives you a map of the topology. Then you can specify the affinity
    mask, and it runs the process on that. ;^)


    --- PyGate Linux v1.5.17
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Tue Jun 16 13:18:07 2026
    On 6/16/2026 1:13 PM, Chris M. Thomasson wrote:
    On 6/15/2026 2:10 AM, Bonita Montero wrote:
    I've written a tool called "bg" to combine Windows' runas with start.
    One parameter is the affinity-mask for the processors which the star-
    ted program is attached to. The below code is the parsing function.
    The code wouldn't apply if this function has to be performance since
    I work with regexes. But having this this way makes the code rather
    short for what is required - imagine you'd have to do that in C.
    [...]

    How about run as and on...

    It gives you a map of the topology. Then you can specify the affinity
    mask, and it runs the process on that. ;^)


    So run as and on... Run as admin. It pops up a GUI with the topology.
    The user selects... Hits run. The process is pinned.

    --- PyGate Linux v1.5.17
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)
  • From Chris M. Thomasson@3:633/10 to All on Tue Jun 16 13:19:47 2026
    On 6/16/2026 1:18 PM, Chris M. Thomasson wrote:
    On 6/16/2026 1:13 PM, Chris M. Thomasson wrote:
    On 6/15/2026 2:10 AM, Bonita Montero wrote:
    I've written a tool called "bg" to combine Windows' runas with start.
    One parameter is the affinity-mask for the processors which the star-
    ted program is attached to. The below code is the parsing function.
    The code wouldn't apply if this function has to be performance since
    I work with regexes. But having this this way makes the code rather
    short for what is required - imagine you'd have to do that in C.
    [...]

    How about run as and on...

    It gives you a map of the topology. Then you can specify the affinity
    mask, and it runs the process on that. ;^)


    So run as and on... Run as admin. It pops up a GUI with the topology.
    The user selects... Hits run. The process is pinned.

    Should be better than using task manager or something.

    --- PyGate Linux v1.5.17
    * Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)