• Sets

    From Sean Dennis@618:618/1 to All on Fri Oct 9 11:31:50 2009
    Hi, everyone.

    I'm trying to figure out how to properly use sets in Borland/Turbo Pascal. Telegard (the BBS software I use) uses sets to do some "bit-twiddling" with certain settings on a user's record, such as if the user is "hidden", et al. While I have an excellent college textbook on TP, the section on sets is either
    too vague or I'm too thick-headed to understand. :) Anyone care to help me figure this out?

    Thanks,
    Sean

    // sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    --- Telegard/2 v3.09.g2-sp4/mL
    * Origin: Nocturnal State BBS - bbs.nsbbs.info (618:618/1)
  • From Scott Little@3:712/848 to Sean Dennis on Mon Oct 12 17:45:42 2009
    [ On 2009-10-09 at 11:31:50, Sean Dennis wrote to All ]

    Telegard (the BBS software I use) uses sets to do some
    "bit-twiddling" with certain settings on a user's record, such as if
    the user is "hidden", et al.

    Sets are fancy bitfields. A set is made of one or more values of an ordinal type, which can be reduced to an integer and therefore a bit number.

    eg. an enumerated (ordinal) type, specifying the days of the week:

    type
    Day = (Mon, Tue, Wed, Thu, Fri, Sat, Sun);
    Days = set of Day;

    var
    d: Days;

    Then you can set one or more days:

    d := [Mon, Wed, Fri];

    Since ord(Mon) = 0, ord(Wed) = 2, ord(Fri) = 4, the above will flip bits 0, 2 and 4 to on. Byte(d) = 21.

    The compiler will automatically size the set to accomodate all the potential values. Since there are seven days, sizeof(Days) = 1. A set of Char would be 32 bytes (256 possible values divided by 8 bits per byte).

    You can also do set math, eg.

    if Mon in [Mon, Wed, Fri] - [Wed, Fri] then writeln('Wed and Fri are gone, Mon is left');
    if not (Mon in [Mon, Wed, Fri] - [Mon]) then writeln('Mon is gone, Wed and Fri are left');
    if Mon in [Mon, Wed, Fri] * [Mon, Fri] then writeln('Mon and Fri are common to both sets');

    The same can be done manually with bitwise operations, but sets are easier to read.

    Clear as mud? ;)


    -- Scott Little [fidonet#3:712/848 / sysgod@sysgod.org]

    --- The government solution to a problem is usually as bad as the problem.
    * Origin: What the hell are you waiting for? Christmas? (3:712/848)
  • From Sean Dennis@1:18/200 to Scott Little on Mon Oct 12 17:58:21 2009
    Hello, Scott.

    Monday October 12 2009 at 17:45, you wrote to me:

    The same can be done manually with bitwise operations, but sets are
    easier to read.

    Clear as mud? ;)

    Actually, that makes perfect sense.

    What I'm wanting to do is this: Telegard BBS has a bit setting to make the user
    "hidden" when calling, so that user doesn't show up in the "who's online" and "today's callers" bulletins. I have a DOS program that I use to do it for my board but with the board being OS/2 native and the DOS program takes a few seconds to activate.

    Here's the part of the Telegard structures that I'm dealing with:

    === Cut ===
    userflag= { USERS.DAT user flags }
    (
    newusermsg, { sent newuser message }
    clsmsg, { clear screen before messages }
    flinput, { full line input }
    hotkey, { menu hotkeys active }
    pause, { pause }
    novice, { user is at novice help level }
    hiddenlog, { not displayed in call/online listings }
    hiddenlist { not displayed in user listings }
    );
    userflags = set of userflag;
    === Cut ===

    So what I'm wondering is how would I set those two bits ("hiddenlog" and "hiddenlist") on? I understand how sets work now, but I'm not sure how I'd turn the bits on and off.

    Thanks for your help in this. Since my car accident last year, it can be hard for me to wrap my mind around certain concepts after my concussion. :)

    Later,
    Sean

    //sean@nsbbs.info | http://nsbbs.info | ICQ: 19965647

    ... Any given program will expand to fill all available resources.
    --- GoldED/2 3.0.1
    * Origin: Nocturnal State BBS - Johnson City, TN - bbs.nsbbs.info (1:18/200)