TweetFollow Us on Twitter

HyperAppleTalk 2
Volume Number:5
Issue Number:2
Column Tag:HyperChat™

Related Info: AppleTalk Mgr

XCMD Corner: HyperAppleTalk, Part II

By Don Koscheka, Aurthur Young & Company, MacTutor Contributing Editor

Last month I introduced access to AppleTalk from HyperCard. Over the next few months I will continue this theme. Adding a multi-user dimension to your stacks should yield some very interesting and exciting results. This month I will introduce the Name Binding Protocol and leave you with a set of XCMDs that implement the more salient features of NBP.

The Basics

First, a quick review of the basics. Sending information across AppleTalk requires two mechanisms: (1) a way of identifying entities on the network so that any two devices can find each other and (2) a “transaction protocol”, some method of sending packets of information between any two entities. AppleTalk implements the first of these mechanism with the Name Binding Protocol (NBP) which serves as a sort of “directory assistance for the network. Several protocols exist for sending information between nodes. One of the earliest is the AppleTalk Transaction Protocol which manages quite well for fixed-size packages. A newer and more sophisticated transaction mechanism has recently been introduced by Apple and is called the AppleTalk Data Stream Protocol (ADSP). This protocol is straightforward and easy to understand, which is why I chose it for this project. If you must have access to the network now, I’ve implemented the ATP protocol which is available in the “HyperAppleTalk” toolkit from Apple. If you want to get a glimpse of the future of easy-to-program networks, I will be discussing ADSP in greater detail next month.

Naming entities on the network is really a courtesy to the user. AppleTalk does not use names to address entities. Each node on the network is assigned a unique address consisting of a network id, a node id and a socket id. These three elements comprise a “phone number” of sorts. AppleTalk identifies entities on the network by the network address. Like the phone system, when you wish to call someone, you pick up the phone and dial that party’s number. With no further intervention (until your party picks up the phone at the other end), the phone system establishes the connection and notifies your party with a ringing telephone.

Because AppleTalk does not care who is at the other end of a connection, identifying a party becomes impossible in all but the smallest of network configurations (n=2). Imagine that your local phone directory contained the phone numbers of everyone in your town, but not the names associated with those phone numbers. From the telephone system’s point of view, the phone book is complete, every phone number is listed in the phone book. From a human interface perspective, a phone book that listed the numbers but not the names would only be useful to if you didn’t care who was at the other end of the line.

The network becomes useful to the end user if some sort of mechanism associates entity names with network addresses. An entity name can be anything you choose. As an example, the chooser dialog allows you to enter a name for your node. Entering a name from the chooser, however, doesn’t mean that your name is automatically registered on the network. In fact, AppleTalk ignores this name; it is simply placed in a globally accessible “STR “ resource (-16906) and made available to any application that wants to know it. You cannot register the name until you receive an address from the network (Imagine that you are applying for a new phone number from Ma Bell. Once the phone number is assigned, the operator will ask you how you want to be registered in the phone book).

Last Month

Last month’s column provided a lot of nebulous code in the form of ADSPOpen and NBPOpen. Presenting this material resulted in a bit of a chicken and egg problem. I wanted to introduce NBP first because you already understand it in another form - directory assistance. In order to use NBP, you need a network address (if you were to look someone up in the phone book and not find a phone number next to their name, you might tend to believe that the phone book is not very useful except as a spelling checker). Thus, I needed to present just enough of the transaction side of the equation to cajole an address out of the network. If you compile last month’s code and run it on a system that has ADSP installed, about all you will get for your troubles is the address of a connection listener.

When we invoked adspOpen, we first initialized some records that will be used by our network code. Pointers are indicated because HyperCard is fussy about the state of its heap. Our network code executes asynchronously. This technique allows us to get some semblance of background networking out of the system. In effect, we issue a request to send some information on the network and then go away. When the network can, it will send our information and then notify us when the dialog completes, allowing us to move on without waiting for the communication to complete (which can take a long time on the network).

Memory can’t be moving around on us because we have no idea when our information will actually be looked at by the network. Normally, allocating our data in handles and then locking down those handles during a dialog would suffice. But, as the saying goes, “HyperCard abhors a locked handle” and will unceremonioulsy unlock it if it needs to fix up its heap (once you get the hang of this in XCMD programming you begin to appreciate the beauty of it). This poses no problem since we can force our data not to move by allocating non-relocatable memory in pointers. This is not inconsistent with Inside Macintosh, and it allows us to leave HyperCard’s heap in the state that it expects to find it (HyperCard is quite effective at handling pointers always pushing them to the bottom of the heap).

Registering

After allocating and initializing the data, we ask the network to consider us as a node by telling the network manager that we are capable of listening and responding to connection requests from another entity. This is just like hooking up a telephone in your house. Once the phone is installed and the phone company gives you a phone number, anytime the phone rings, you have a good idea that someone is trying to call you. A connection listener performs the same task, notifying us when another party calls. For the moment, let’s leave the phone ringing and get back to the matter of how we identify parties on the line.

If you’ve ever applied for a telephone number you know the phone company will give you a number and then ask how you want to be listed. NBP provides just this feature on the network. Once you get your network address, you want to tell the network what name you can be reached by. This is why we do the adspopen before the nbpopen. First we apply for a phone number; if we get it we list our name in the phone book using the NBPRegister call to AppleTalk.

The first element in the record tells us whether we are registered or not. If we are, then we probably don’t need to register again (would registering under several aliases serve any purpose?) NTEntry is of type NamesTableEntry, a special AppleTalk type that glues names to addresses (figure 1). To register an entity with the network, we must place both its internet address (in this case obtained from last month’s ADSPOpen XFCN) as well as the name into the names table entry.

A registered name consists of three parts: (1) zone, (2) name and (3) a type. For now, the zone name is always “*” (we’ll relax this constraint when we introduce the concept of inter network addressing in a future article). The name can be anything but most likely you will use the name already entered in the “User Name” edit box in the chooser.

This is a matter of personal choice and need. Your code might first check the chooser for a name and , if no name is found, then ask the user directly for a name. This HyperTalk script will register the entity using the name in the chooser and setting the type to “HyperPeople”:

--1

on MouseUp
 global myRegisteredType, myRegisteredName
 
 Put NBPRegisterName() into errorMessage

 if errorMessage is empty then
 -- myRegisteredName now contains the same name
 -- as is entered in the chooser
 else
 -- report error to user 
 end if
end MouseUp

The type is quite important. We don’t want to send HyperCard messages to entities that are not capable of understanding them so we apply a filter to names: communicate only with entities that are registered as a given type. This makes sense, if you have two entities on the network simultaneously playing chess and checkers you don’t want the messages to get crossed (kings, for example, have dramatically different powers in both games). I feel the type is important, so if the user (your stack) doesn’t choose one, I set the default to “HyperPeople”. This is a type that is capable of reading any HyperCard message whether it makes sense or not!

The rest is pretty easy to figure out. If you know the address of an entity then it should be an easy task to provide that address along with a name and a type to some xcmd that registers that name with the network. NBPRegisterName (Listing 1) does just that. The code is quite straightforward.

The flow of information from node to node in a computer network is governed by the underlying physics of the network. Appletalk’s physics may beset be described as a case of organized chaos. I like to think of it as a “mobocratic” system, run by mob rule. While any two entities are passing information between themselves, all other entities must wait for the transaction to complete. The moment the transaction completes, the next entity to get its request on the wire is the winner. It may take several tries to be the next entity on the wire. The network’s dynamics govern the number of retries and the time interval between retries; the busier the network, the more you’ll have to wait. When you attempt to register with the net, you want to make sure that every entity has an opportunity to update their local copy of the phone book at the time you register. To make sure as many nodes as possible see you register, you specify a retry count. This is just like repeating yourself to a large gathering in hopes that more of the crowd will hear you. Interval specifies the time to wait between retries. The unit time is the “decatick”. There are sixty ticks per second so an interval of 6 specifies a waiting period of one second.

The last parameter that we pass to NBPRegisterName is the verify flag. If set true we want the name verified at registration time. Verification is another convenience item. If any node is already registered with that name, you won’t be able to register. The error message is quite explicit so you may wish to ask the user for another name. It’s okay to have duplicate names registered, although this can lead to some confusion. Just as when you look up a Smith in the phone book, “Now which Smith is it that I want to call?”

NBPUnRegisterName (listing 2) removes the registered name from the network. This is useful if, for example, you want to register under a new name. The following Script will invoke NBPUnRegisterName:

--2

on mouseUp
  global myRegisteredname, myRegisteredType
  
  Put NbpUnRegisterName()into error
  if error is not empty then put error
end mouseUp

Once registered with the network, other entities can see us and send connection requests to us (next month). To be able to see other entities, we need some method of looking up other parties in some sort of directory.

NBPLookupnames (Listing 3) returns a list of the network entities currently visible to us. This is exactly like requesting a phone book from the phone company, except that you will always get the very latest copy. One word of note: the latest copy of the directory may not contain ALL entities on the network, just those that happened to be visible and responded to the update request at the time that the look up was issued.

NBPLookupNames issues a request to find all entities on the network. This function becomes more useful when we limit the process to only entities of a certain type. Since we are really only interested in finding entities that speak HyperTalk, we can filter our request to find only entities of type ‘Hyperpeople’ (or whatever type you register).

The lookup uses three of the fields in the NBPBlock structure that we introduced last month. EntCount is set to the number of entities that the function actually saw (initially set to zero indicating that no lookup has been performed). We place an upper limit of 100 (maxnodes) entities on the lookup. You can tune this constant to suit the individual needs of your network.

LookupBuffer is a handle to the list of visible entities. You’ll use NBPExtractName to pull entities out of the list. NBPLocal is used internally by NBP itself. You provide this buffer to NBP and leave it alone. NBP wants that space and doesn’t want us fussing with it. So we don’t.

Once the lookup completes, LookupBuffer contains a handle to the entities that were found on the network. The internal structure of the lookup table is somewhat complicated by the intermixing of names and their addresses. To help in extracting information from the table.

This is by no means an exhaustive list of all the capabilities of NBP; but since such a list would truly be exhausting, I’ve intentionally left some of the NBP routines out of the picture. For the sake of completeness, we will cover these routines as we go ahead with the project. Next month we will introduce the AppleTalk Data Stream Protocol and provide a stack example that uses these routines.

The data declarations used in these modules are defined in Listing 4. You should refer to last month’s article for information on opening a connection listener.

--------------------------------------------
(**************************************)
(* file:  NBPRegisterName.p *)
(* *)
(* Register a name with the *)
(* network...    *)
(* *)
(* Requires that GlobalNBPData be  *)
(* initialized and that the global *)
(* myRegisteredName be defined     *)
(* --------------------------------*)
(* © 1988, Donald Koscheka*)
(* 10-November, 1988 *)
(* All Rights Reserved    *)
(* *)
(**************************************)

(*******************************
 MPW Build Sequence
 
pascal NBPRegisterName.p -o NBPRegisterName.p.o
link -m ENTRYPOINT  -rt XFCN=2003 -sn Main=NBPRegisterName
 NBPRegisterName.p.o
 “{libraries}”Interface.o 
 -o YourStackNameHere

*******************************)

{$R-}
{$S NBPRegisterName}

UNIT Donald_Koscheka;

(*******************************)
 INTERFACE
(*******************************)

Uses  
 MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf, HyperXCmd, 
 AppleTalk, nbpxcmd;

Procedure EntryPoint( paramPtr : XCmdPtr );


(*******************************)
 IMPLEMENTATION
(*******************************)

 
PROCEDURE NBPRegisterName( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
Begin
 NBPRegisterName( paramPtr );
End;

PROCEDURE NBPRegisterName( paramPtr: XCmdPtr );
(**********************************
* Register this entity on the network
* using the name and type specified.
*
* Set the globalvariable, ‘myRegisteredName’
* to the name that was registered. Note
* that NBPOpen must be called before
* attempting to register.
*
* params[1] theName
* Params[2] theType
* params[3] count
* params[4] interval
* params[5] verifyFlag
*
* The type is in the global myRegisteredType
* ----------------------------------
*
* defaults are: 
*name = (from chooser)
*type = ‘HyperPeople’
*count  = 2
*interval= 8
*verify = false;
*
* NOTE: will not register if a socket
* is not open on this node!
**********************************)
VAR
nbp: NBPBlkPtr;  {*** our global nbp data    ***}
theName: Str255; {*** name to register ***}
theType: Str255; {*** type for this node     ***}
theZone: Str255; {*** always ‘*’(zone name)  ***}
str: Str255;{*** used in getting globs ***}
myName: Handle;  {*** used for chooser name  ***}
tempH: Handle; {*** used in getting globs    ***} 
count: Byte;{*** number of retries ***}
interval: Byte;  {*** wait between retires   ***}
verify: Byte;  {*** name must be unique***}
error: OSErr;  {*** result code    ***}
i,j: INTEGER;  {*** pascal string length     ***}
Mpb: MPPParamBlock;{*** param block  ***}

{$I XCMDGlue.Inc }

BEGIN
 error := noErr; 
 nbp  := NIL; 
 
 {*** Retrieve pointer to our NBPData***}
 tempH := GetGlobal( ‘GLOBALNBPDATA’ );
 
 {*** Convert the string to a handle ***}
 IF (tempH <> NIL) THEN
 BEGIN
 HLock( tempH );
 ZeroToPas( tempH^, Str );
 nbp := NBPBlkPtr( StrToLong( Str ));
 HUnlock( tempH );
 DisposHandle( tempH );
 END;

 IF ( nbp <> NIL ) AND ( NOT nbp^.Registered ) THEN
 BEGIN
 
 {*** Before registering, we need  ***}
 {*** the internet address stored in ***}
 {*** string form in a container   ***}
 tempH := GetGlobal( ‘mySocketListener’ );
 
 {*** Convert the string to a network***}
 {*** address (longinteger) ***}
 IF ( tempH <> NIL ) THEN
 BEGIN
 HLock( tempH );
 ZeroToPas( tempH^, Str );
 nbp^.NTEntry.nteAddress:= AddrBlock(StrToLong(Str));
 HUnlock( tempH );
 DisposHandle( tempH );
 END; 
 
 nbp^.NTEntry.qLink := NIL; 
 
 WITH ParamPtr^ DO
 BEGIN
 {*** If  user specifies a name  ***}
 {*** we’ll use it, otherwise use  ***}
 {*** the name in the Chooser ***}
 IF ( params[1] = nil ) OR (params[1]^^ = 0) THEN
 BEGIN  {*** Get name from chooser ***}
 myName := GetResource( ‘STR ‘, NODE_NAME );
 
 IF myName <> NIL THEN
 BlockMove( myName^, @theName[0],
 GetHandleSize( myName ) );
 END
 ELSE
 BEGIN  {*** Use name passed in  ***}
 HLock( params[1] );
 ZeroToPas( params[1]^, theName );
 HUnlock( params[1] );
 END;
 
 {*** IF the user provides a type  ***}
 {*** use it otherwise, use the  ***}
 {*** default type ***}
 IF (params[2] = nil) OR (params[2]^^ = 0) THEN
 theType := ‘HyperPeople’
 ELSE
 BEGIN
 HLock( params[2] );
 ZeroToPas( params[2]^, theType );
 HUnlock( params[2] );
 END;

 {*** AppleTalk, Zone Name must    ***}
 {*** be ‘*’ (this zone)  ***}
 theZone := ‘*’;
 
 {*** Put the name away in the***}
 {*** entity data part of the names***}
 {*** table entry.  Inside Macintosh ***}
 {*** vol II p.321 (figure 13) depicts ***}
 {*** the structure of a names table ***}
 {*** element.  Note that the first  ***}
 {*** byte in the nteData array is used***}
 {*** internally.  We put the chars***}
 {*** away starting at array offset 2***}
 
 i := 2;
 
 FOR j := 0 TO Length( theName ) DO  
 BEGIN
 nbp^.NTEntry.nteData[i] := theName[j];
 i := i + 1;
 END;
 
 {*** The type gets tacked to the  ***}
 {*** end of the names string. This***}
 {*** is not the same as the concat***}
 {*** function, each string keeps  ***}
 {*** its length byte.    ***}
 
 FOR j := 0 TO Length( theType ) DO  
 BEGIN
 nbp^.NTEntry.nteData[i] := TheType[j];
 i := i + 1;
 END;

 {*** Likewise, theZone gets tacked***}
 {*** to the end of the type string***}
 FOR j := 0 TO Length( theZone ) DO  
 BEGIN
 nbp^.NTEntry.nteData[i] := TheZone[j];
 i := i + 1;
 END;
 
 {*** Number of times to register  ***}
 IF params[3] <> NIL THEN
 BEGIN
 HLock( params[3] );
 ZeroToPas( params[3]^, str );
 count := INTEGER( StrToLong( Str ));
 HUnlock( Params[3] );
 END
 ELSE
 count := 2;
 
 {*** 10X ticks between requests ***}
 IF params[4] <> NIL THEN
 BEGIN
 HLock( params[4] );
 ZeroToPas( params[4]^, str );
 interval := INTEGER( StrToLong( Str ));
 HUnlock( Params[4] );
 END
 ELSE
 Interval := 8;  
 
 {*** If the last parameter is true***}
 {*** make sure that the  name is  ***}
 {*** not already in use  ***}
 IF params[5] <> NIL THEN
 BEGIN
 HLock( params[5] );
 ZeroToPas( params[5]^, str );
 verify  := BYTE(strToNum( str ));
 HUnlock( Params[5] );
 END
 ELSE
 verify := 0;
 END; 
 
 {*** Now set up an make the call  ***}
 {*** to register this enitity***}
 Mpb.ioCompletion:= NIL;  
 Mpb.interval    := interval;
 Mpb.count:= count;
 Mpb.entityPtr   := @nbp^.NTEntry;
 Mpb.verifyFlag  := verify;

 error := PRegisterName( @Mpb, SYNC);
 
 IF error = noErr THEN
 BEGIN
 paramPtr^.returnValue := PasToZero( ‘’ );
 {*** As a courtesy to the system, ***}
 {*** save name off in a global    ***}
 {*** this is an easy way to get   ***}
 {*** name from the chooser ***}
 nbp^.Registered := TRUE;
 SetGlobal( ‘MyRegisteredName’,PasToZero(theName));
 END
 ELSE
 paramPtr^.returnValue:=PasToZero(numToStr(longint(error)));
 
 END;
END;

END.

Listing 1. NBPRegisterName

--------------------------------------------
(********************************)
(*file: NBPUnRegisterName.p *)
(* *)
(* Remove name from the network  *)
(* if that name if currently  *)
(* registered.   *)
(* *)
(* Requires GlobalNBPData be*)
(* initialized and that global*)
(* myRegisteredName be defined   *)
(* ----------------------------  *)
(* © 1988, Donald Koscheka*)
(* 8-December, 1988*)
(* All Rights Reserved    *)
(* *)
(********************************)

(*******************************
 MPW Build Sequence
 
pascal NBPUnRegisterName.p -o NBPUnRegisterName.p.o
link -m ENTRYPOINT  -rt XFCN=2004 -sn Main=NBPUnRegisterName
 NBPUnRegisterName.p.o
 “{libraries}”Interface.o 
 -o yourStackNameHere

*******************************)

{$R-}
{$S NBPUnRegisterName}

UNIT Donald_Koscheka;

(*******************************)
 INTERFACE
(*******************************)

Uses  
 MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf, HyperXCmd, 
 AppleTalk, nbpxcmd;


Procedure EntryPoint( paramPtr : XCmdPtr );

(*******************************)
 IMPLEMENTATION
(*******************************)
 
PROCEDURE NBPUnRegisterName( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
Begin
 NBPUnRegisterName( paramPtr );
End;

PROCEDURE NBPUnRegisterName( paramPtr: XCmdPtr );
(**********************************
* UnRegister this entity on the network
* using the information already contained
* in the NBP data block.  
*
* Upon successful completion, clear the
* global variable, ‘myRegisteredName’ and
* set the state of the “Registered” flag
* for this connection to FALSE.
* ----------------------------------
**********************************)
VAR
nbp: NBPBlkPtr;  {*** our global nbp data    ***}
tempH: Handle; {*** used in getting globs    ***} 
error: OSErr;  {*** result code    ***}
Mpb: MPPParamBlock;{*** param block  ***}
Str: Str255;
 
{$I XCMDGlue.Inc }

BEGIN
 error := noErr; 
 nbp  := NIL; 
 
 {*** Retrieve pointer to our NBPData***}
 tempH := GetGlobal( ‘GLOBALNBPDATA’ );
 
 {*** Convert the string to a handle ***}
 IF (tempH <> NIL) THEN
 BEGIN
 HLock( tempH );
 ZeroToPas( tempH^, Str );
 nbp := NBPBlkPtr( StrToLong( Str ));
 HUnlock( tempH );
 DisposHandle( tempH );
 END;

 IF ( nbp <> NIL ) AND ( nbp^.Registered ) THEN
 BEGIN
 Mpb.ioCompletion:= NIL;  
 Mpb.entityPtr   := @nbp^.NTEntry.nteData[2];
 error := PRemoveName( @Mpb, SYNC);
 
 IF error = noErr THEN
 BEGIN
 paramPtr^.returnValue := PasToZero( ‘’ );
 {*** As a courtesy to the system, ***}
 {*** save name off in a global    ***}
 {*** this is an easy way to get   ***}
 {*** name from the chooser ***}
 nbp^.Registered := FALSE;
 SetGlobal( ‘MyRegisteredName’, PasToZero( ‘’ ) );
 END
 ELSE
 paramPtr^.returnValue := 
 PasToZero(numToStr(longint(error)));

 END;

END.

Listing 2. NBPUnRegisterName

--------------------------------------------
(********************************)
(* file:  NBPLookup.p*)
(* *)
(* params[1] = theType    *)
(* params[2] = theZone    *)
(* params[3] = number to look up*)
(* params[4] = count *)
(* params[5] = interval   *)
(* *)
(* Entity names are returned*)
(* in a list and sent to the  *)
(* HyperCard global: *)
(* ‘NBPLookUpTable’*)
(* *)
(* ReturnValue is set to the*) 
(* result of the lookup   *)
(* *)
(* ----------------------------  *)
(* Defaults:*)
(* *)
(* name = ‘=’ ( All names)*)
(* type = ‘=’ ( all types ) *)
(* zone = ‘*’ (current zone)*)
(* num  = 100 ( 100 names)  *)
(* count= 2   ( do 3 lookups) *)
(* interval= 4( decaticks)*)
(* *)
(* ----------------------------  *)
(* © 1988, Donald Koscheka*)
(* All Rights Reserved    *)
(* *)
(* 05-Nov-88*)
(* ----------------------------  *)
(********************************)

(*******************************
 MPW Build Sequence
 
pascal NBPLookupNames.p -o NBPLookupNames.p.o
link -m ENTRYPOINT  -rt XFCN=2005 -sn Main=NBPLookupNames
 NBPLookupNames.p.o
 “{libraries}”Interface.o 
 “{plibraries}”PasLib.o 
 -o yourStackNameHere

*******************************)

{$R-}
{$S NBPLookupNames}

UNIT Donald_Koscheka;

(*******************************)
 INTERFACE
(*******************************)

Uses  
 MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf, HyperXCmd, 
 AppleTalk, nbpxcmd;

Procedure EntryPoint( paramPtr : XCmdPtr );

(*******************************)
 IMPLEMENTATION
(*******************************)

CONST
 DEFAULT_ERR= 128; {*** some sort of mem error     ***}

TYPE
 Str255Ptr= ^Str255;
 
PROCEDURE NBPLookupNames( paramPtr: XCmdPtr ); FORWARD;

Procedure EntryPoint( paramPtr : XCmdPtr );
Begin
 NBPLookupNames( paramPtr );
End;

PROCEDURE NBPLookupNames( paramPtr: XCmdPtr );
(**********************
* Lookup  entities of the 
* requested type and zone
* (up to num elements):
*
**********************)
VAR
 tempH  : Handle;
 nbp    : NBPBlkPtr;
 EntSize  : LongInt;
 i,j,cnt, err,
 intr, total,
 num    : INTEGER;
 str    : Str255;
 ent    : NamesTableEntry;
 Mpb    : MPPParamBlock;
 theType,
 theZone: Str255;
 
{$I XCMDGlue.Inc }

 FUNCTION ReturnNames: Handle;
 (*****************************
 * Return a list of entities as
 * found in the lookup table
 *
 *****************************)
 VAR
 eAddr  : AddrBlock; {*** Needed by the extract    ***}
 newHand: Handle;{*** current entity name&typ      ***}
 theTable: Handle; {*** Lookup Data to return            ***}
 ret  : String[1]; {*** newline after each ent     ***}
 oldSize: LongInt; {*** Previous size of table     ***}
 newSize: LongInt; {*** size to add to table       ***}
 i : INTEGER;  {*** loop control variable          ***}
 theEnt : EntityName;{*** names from the names table     ***}
 
 BEGIN
 oldSize  := 1;
 theTable := NewHandle( oldSize );
 
 IF theTable <> NIL THEN
 BEGIN
 theTable^^ := 0;{*** set theTable to EMPTY***}
 ret[0] := CHR( 1 );
 ret[1] := CHR( 13);
 
 FOR i := 1 TO nbp^.EntCount DO
 BEGIN
 {*** extract name i from the list ***}
 WITH nbp^ DO
 BEGIN
 HLock( LookUpBuffer );
 err := NBPExtract( LookUpBuffer^, 
 total, i, theEnt, eAddr);
 HUnlock( LookUpBuffer );
 END;
 
 IF err = noErr THEN
 BEGIN
 {*** each line in the list gets   ***}
 {*** entities name and type***}
 Str := ‘’;

 Str := Concat( theEnt.objStr, 
 ‘,’,theEnt.typeStr,ret);
 newHand:= PasToZero( Str );
 newSize:=GetHandleSize(newHand);
 oldSize:=GetHandleSize(theTable);
 SetHandleSize(theTable,newSize+oldSize);
 BlockMove(newHand^,
    Ptr(ORD(theTable^)+oldSize-1),
    NewSize);
 DisposHandle( newHand );
 END; 
 END; {*** FOR i := 1 to Total ***}
 
 {*** make sure  return string is null ***}
 {*** terminated or hypercard will have***}
 {*** a fit ***}
 END; {*** IF theTable <> NIL ***}
 ReturnNames := theTable;
 END;
 
BEGIN
 err := noErr;
 
 {*** Retrieve pointer to our NBPData***}
 tempH := GetGlobal( ‘GLOBALNBPDATA’ );
 
 {*** Convert the string to a handle ***}
 IF (tempH <> NIL) THEN
 BEGIN
 HLock( tempH );
 ZeroToPas( tempH^, Str );
 nbp := NBPBlkPtr( StrToLong( Str ));
 HUnlock( tempH );
 DisposHandle( tempH );
 END;

 IF ( nbp <> NIL ) THEN {*** okay to lookup ***}
 BEGIN
 WITH paramPtr^ DO
 BEGIN
 IF params[1] = NIL THEN
 theType := ‘=’
 ELSE 
 BEGIN
 HLock( params[1] );
 ZeroToPas( params[1]^, theType );
 HUnlock( params[1] );
 END;
 
 IF params[2] = NIL THEN
 theZone := ‘*’
 ELSE
 BEGIN
 HLock( params[2] );
 ZeroToPas( params[2]^, theZone );
 HUnlock( params[2] );
 END;
 
 IF params[3] <> NIL THEN
 BEGIN
 HLock( params[3] );
 ZeroToPas( params[3]^, Str );
 num := INTEGER(StrToNum( Str ) );
 HUnlock( params[3] );
 END
 ELSE
 num := MAXNODES;
 
 IF params[4] <> NIL THEN
 BEGIN
 HLock( params[4] );
 ZeroToPas( params[4]^, Str );
 cnt := INTEGER(StrToNum( Str ) );
 HUnlock( params[4] );
 END
 ELSE
 cnt := 2;
 
 IF params[5] <> NIL THEN
 BEGIN
 HLock( params[5] );
 ZeroToPas( params[5]^, Str );
 intr := INTEGER( StrToNum( Str ) );
 HUnlock( params[5] );
 END
 ELSE
 intr := 4; 
 END; {*** with paramPtr^ ***}
 
 {*** Concatenate the name, type and zone string   ***}
 ent.nteData[2] := CHR(1);
 ent.nteData[3] := ‘=’;
 i := 4;
 
 FOR j := 0 TO Length( theType ) DO  
 BEGIN
 ent.nteData[i] := TheType[j];
 i := i + 1;
 END;

 {*** Likewise, theZone gets tacked***}
 {*** to the end of the type string***}
 FOR j := 0 TO Length( theZone ) DO  
 BEGIN
 ent.nteData[i] := TheZone[j];
 i := i + 1;
 END;

 {*** The lookup data is stored as a handle in     ***}
 {*** our NBPBlock. Since a new lookup supercedes***}
 {*** the previous data, delete previous (if any)***}
 IF nbp^.LookupBuffer <> NIL THEN
 BEGIN
 HUnlock( nbp^.LookUpBuffer );
 DisposHandle( nbp^.LookUpBuffer );
 END;
 
 nbp^.EntCount := 0;
 EntSize:= sizeof( NamesTableEntry );
 nbp^.LookUpBuffer:= NewHandle( num *  EntSize );

 IF nbp^.LookUpBuffer <> NIL THEN
 BEGIN
 MoveHHi( nbp^.LookUpBuffer );
 HLock( nbp^.LookUpBuffer );
 
 WITH mpb DO
 BEGIN
 EntityPtr:= @ent.nteData[2];
 retBuffPtr := nbp^.LookUpBuffer^;
 retBuffSize   := INTEGER( EntSize*num );
 maxToGet := num;
 interval := intr;
 count  := cnt;
 END; {*** with mpb ***}  
 err  := PLookUpName( @Mpb, SYNC );
 
 IF err = noErr THEN
 BEGIN
 nbp^.EntCount := Mpb.numGotten;
 SetGlobal(‘NBPLookupTable’,ReturnNames );
 paramPtr^.returnValue := PasToZero( ‘’ );
 END
 ELSE
 paramPtr^.returnValue := 
 PasToZero(numToStr(longint(err)));
 
 HUnlock( nbp^.LookUpBuffer );
 END
 ELSE
 err := DEFAULT_ERR; {*** no room in the heap? ***}
 END;
END;
END.

Listing 3. NBPLookUpNames

--------------------------------------------
(********************************)
(* file:  NBPXCMD.p*)
(* *)
(* Constant and type declaration*)
(* file for nbp xcmds*)
(* ----------------------------  *)
(* © Donald Koscheka *)
(* 6-October, 1988 *)
(* All Rights Reserved    *)
(* *)
(* -------------------------- *)
(********************************)

UNIT  NBPXCMD;

(*******************************)
 INTERFACE
(*******************************)

USES  Memtypes, QuickDraw, OSIntf, ToolIntf, AppleTalk;

CONST

ASYNC   = TRUE;
SYNC    = FALSE;
NODE_NAME = -16096;(* STR resource name from Chooser     *)
MAXNODES= 100;   (* maximum # of nodes for  zone   *)
NBPLSIZE= 120;   (* size of a local buffer for NBP *)
NN = 30;(* # of names in lookup table*)
ENTITYSIZE= 110; (* size of entity in lookupbuffer *)

TYPE

Str31 = String[31];

NBPBlkPtr = ^NBPBlock;
NBPBlock = RECORD
Registered: BOOLEAN; (* true = registered          *)
EntCount: INTEGER; (* # of entities visible        *)
LookUpBuffer: Handle;(* lookup buffer*)
NTEntry : NamesTableEntry;(* entry in names table  *)
NBPLocal: array[1..NBPLSIZE] of Char;(* used by NBP      *)
END;
END.

Listing 4. Definitions needed for the XFCNs

--------------------------------------------

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »

Price Scanner via MacPrices.net

13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, available for $759 for 8-Core CPU/7-Core GPU/256GB models and $929 for 8-Core CPU/8-Core GPU/512GB models. Apple’s one-year warranty is... Read more
Updated Apple MacBook Price Trackers
Our Apple award-winning MacBook Price Trackers are continually updated with the latest information on prices, bundles, and availability for 16″ and 14″ MacBook Pros along with 13″ and 15″ MacBook... Read more
Every model of Apple’s 13-inch M3 MacBook Air...
Best Buy has Apple 13″ MacBook Airs with M3 CPUs in stock and on sale today for $100 off MSRP. Prices start at $999. Their prices are the lowest currently available for new 13″ M3 MacBook Airs among... Read more
Sunday Sale: Apple iPad Magic Keyboards for 1...
Walmart has Apple Magic Keyboards for 12.9″ iPad Pros, in Black, on sale for $150 off MSRP on their online store. Sale price for online orders only, in-store price may vary. Order online and choose... Read more

Jobs Board

Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.