Hi guys!
I'm not a super great C programmer, but I'm trying to knock out a "simple" MPW Tool to print the data contained in the 'ckid' resource that gets created by Projector when you check out a file. Unfortunately, most of the data I want is in Pascal strings.
The format of the 'ckid' resource is documented in Appendix A in the "Bldg & Mng Progs in MPW 2ed.pdf" file that comes with MPW. But the data structure is only described in Pascal format. Here is a C struct that I made that seems to me like it should be equivalent:
#include <time.h>
typedef unsigned long uLong;
typedef unsigned short uShort;
typedef struct{
uLong checkSum; // checkSum
long LOC; // location identifier
short version; // ckid version number
short readOnly; // checkout state; 0=modifiable
char branch; // if modifiable & byte not 0, then branch was made on checkout
Boolean modifyReadOnly; // Did user execute "ModifyReadOnly"?
uShort history; // 1 if history present, 0 if not
uShort commentLength; // length of current comment if history is present
time_t checkoutDate; // date and time of checkout
time_t modificationDate; // modification date of file
uLong PIDa; // PID.a
uLong PIDb; // PID.b
short userID; // user ID
short fileID; // file ID
short revisionID; // revision ID
Str255 projectPath; // project path
char pad1;
Str255 userName; // user name
char pad2;
Str255 revisionNum; // revision number
char pad3;
Str255 fileName; // filename
char pad4;
Str255 taskDesc; // task
char pad5;
Str255 comment; // comment
char pad6;
} CKIDRec, *CKIDPtr, **CKIDHandle;
In the program, I do something like this (Again, not sure this is the best, but it sort of works):
Handle ResHandle;
CKIDRec CkidRecord;
refnum = openresfile(argv[1]);
ResHandle = Get1Resource('ckid',128);
HLock(ResHandle);
CkidRecord = **(CKIDRec **)ResHandle;
This works pretty well, and I can access everything up to projectPath using CkidRecord.checkSum, etc. But once I try to get to the Str255's, it starts returning garbage or crashing.
So I found another example for dealing with Pascal strings, and added this:
StringPtr projectPathPtr, userNamePtr;
Str255 projectPath, userName;
Size bytes;
projectPathPtr = (**(CKIDHandle)ResHandle).projectPath;
bytes = (**(CKIDHandle)ResHandle).projectPath[0] + 1;
BlockMove(projectPathPtr, projectPath, bytes);
userNamePtr = (**(CKIDHandle)ResHandle).userName;
bytes = (**(CKIDHandle)ResHandle).userName[0] + 1;
BlockMove(userNamePtr, userName, bytes);
After that, 'projectPath' contains the Project Path, but there's garbage in front of and behind it. 'userName' always contains garbage. I can view what should be the correct data using ResEdit, however.
I wonder if it would be easier to take everything in the struct after revisionID as one big chunk and then manually parse through it, but I've tried that a few times and haven't come up with a scheme that works and doesn't crash my machine.
Does all that make sense? Does anyone have any suggestions or examples of code that uses a similar stucture and how to deal with it? Or am I looking at this all wrong?
Many thanks in advance!