Article View: comp.sys.mac
Article #46412Re: How does a program find out the (Chooser) User Name?
From: Alexis Rosen
Date: Fri, 16 Feb 1990 11:17
Date: Fri, 16 Feb 1990 11:17
64 lines
2866 bytes
2866 bytes
Ouch. David's example will work. Most of the time. Problem is, a file in
the resource search path might have the same string. It shouldn't but it might.
(This is particularly a problem if you're writing an XCMD, as I was.) And
more to the point, what about deallocating that handle? The following is
the code to an XCMD that does the trick, which I wrote about a million years
ago...
Implementation
Procedure main (p: XCmdBlockPtr);
Var
saveResFile, nameLength: Integer;
nameH: Handle;
Procedure ShowErr (err: String);
Var
junk: integer;
Begin
ParamText(err, '', '', '');
junk := Alert(264, Nil)
End;
Begin
If p^.paramCount <> 0 Then
ShowErr('Error: The GetNodeName XFCN takes no arguments and returns the chooser node name.');
saveResFile := CurResFile;
UseResFile(0);
nameH := GetResource('STR ', -16096);
If nameH <> Nil Then
DetachResource(nameH);
UseResFile(saveResFile);
nameLength := SignedByte(nameH^^);
Handle(p^.returnValue) := NewHandle(1 + nameLength);
BlockMove(Pointer(Longint(nameH^) + 1), Pointer(p^.returnValue^), nameLength);
p^.returnValue^^[nameLength + 1] := 0;
DisposHandle(nameH)
End; { Main }
End.
ShowErr does the obvious thing (and exits back to the caller).
Now that I look at this, I can see that it's not perfect either- if the
string's not there, it's nice enough not to Detach the resource, but then it
derefs to get the string length. Stupid... On the other hand, it hasn't crashed
yet. (Not surprising...)
BTW, p is an XCMD parameter block, and p^.returnValue is the choosername.
Nothing else in p^ matters.
If you like C and don't like Pascal, I thing DTS released an equivalent
routine in C a year ago or so. Check tech notes (?)
--While we're talking about chooser stuff-- Why isn't there a programmatic
interface to the chooser??? I can mess with imagwriter resources by hand
(in a way that's guaranteed to break at some pont in the future), but there's
absolutely NO WAY to do things with a third-party driver (how many look like
Apple's internally?). It gets even worse with network things, like LaserWriters,
netmodems, whatever. This is a deplorable situation and needs fixing ASAP.
Sadly, it doesn't look like System 7 will address this...
Too late to type straight,
Alexis Rosen
(too late for .sig, too)
Technical Details
Message-ID:
<903@panix.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!yale!cmcl2!panix!alexisReferences:
<1990Feb12.220022.19862@utzoo.uucp> <25d7743b.425f@polyslo.CalPoly.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!yale!cmcl2!panix!alexis From: alexis@panix.UUCP (Alexis Rosen) Newsgroups: comp.sys.mac Subject: Re: How does a program find out the (Chooser) User Name? Message-ID: <903@panix.UUCP> Date: 16 Feb 90 11:17:41 GMT References: <1990Feb12.220022.19862@utzoo.uucp> <25d7743b.425f@polyslo.CalPoly.EDU> Reply-To: alexis@panix.UUCP (Alexis Rosen) Organization: PANIX - Public Access Computer Systems of NY Lines: 64