11.3 Script Utilities
EntryRef *LocateEntry(char *name);
Locates the entry named by), so that attributes can be accessed.namein the script. If the entry is not found,NULLis returned.LocateEntry()will accept full-path entry names (see PsyScope User Manual 12.2.3 Entry Syntax 325
char *GetEntryName(char *buffer, EntryRef *ref);
Fills inbufferwith the (simple) name of the referenced entry.buffershould be at least 256 bytes long.
char *BuildExtendedName(EntryRef *ref);
Returns a pointer to the extended name of the referenced entry. The extended name is put into an internal buffer; the contents will be changed whenBuildExtendedName()is called again, and this may happen if any of the other Script Utility funtions are called.
int ValidRef(EntryRef *ref);
Checks the validity of an entry reference, returning TRUE if it is still valid. (The entry may have been deleted, etc.)
int ValidateRef(EntryRef *ref);
Same asValidRef(), but this function gives the user an error message ifValidRef()fails.
void UntrashRef(EntryRef *vector); void TrashRef(EntryRef *vector);
Secures/unsecures a entry reference. Any number of calls toUntrashEntry()can be made for a givenEntryRef *, but each call toUntrashEntry()should be eventually balanced with a call toTrashEntry(). A reference needs to be untrashed only if it is needed accross system event checks or accross trial compilations.
EntryRef *AllocNewEntry(char *name, int reserved);
Creates a new entry in the script named byname. The entry is initialized with no tokens or attributes, and it will be added to the end of the script when it is saved. Pass in TRUE forreserved.
EntryRef *AllocNewEntryInBlock(char *name, int reserved, char *block);
LikeAllocNewEntry(), but the entry is added in the section of the script marked by#>block, if such a section exists. Pass in TRUE forreserved.
EntryRef *AllocNewEntryInBlockWithDef(char *keywd, int reserved, char *block, char *def);
LikeAllocNewEntryInBlock(), but a content/attribute block defintion may be passed in throughdef.defshould be in the same format as it would be in the script.
void ChangeEntryName(EntryRef *ref, char *newName);
Changes the name of the referenced entry in the script. Attribute names may be changed with this function, but inline entry names may not. Existing references to the entry will still be valid.
void DeleteEntry(char *name);
Removes an entry from the script. If the entry is not found,ConfigErris set toRefFailed.
long CountTokens(EntryRef *ref);
Returns the number of tokens in the referenced entry, evaluating expressions only to the extent needed to count tokens.
long CountTokensWithVersions(EntryRef *ref, VersionMarker **vm);
Same asCountTokens(), but with version tracking.
EntryRef *GetOwnerForReference(EntryRef *ref);
For attributes or inline entries, this returns a reference to the owning entry. It returnsNULLif the referenced entry is not owned.
int ReferenceSameEntry(EntryRef *ref1, EntryRef *ref2);
ReturnsTRUEof the references are to the same physical entry.
EntryRef *GetThisForReference(EntryRef *ref);
Returns the reference which would result in an evaluation of theTHISoperator within the referenced entry.
EntryRef *MakeTempEntry(char *definitionString, EntryRef *carry);
Creates a temporary entry defined by the given string, with the content and attributes ofcarryappended to it (carrymay be NULL). The reference need not be freed, as usual; when the reference is purged, the entry itself will be deleted. The content of a temporary entry cannot be modified.
EntryRef *MakeHiddenEntry(char *name);
Creates a hidden entry. It can be written to and read from, but it is not in the script and cannot be found withLocateEntry(). Once the reference is purged, the entry will be deleted.
EntryRef *LocateAttrib(EntryRef *ref, char *name);
Attempts to locate an attribute namednamethat belongs to the referenced entry.NULLis returned if the attribute cannot be found.
EntryRef *LocateOrCreateAttrib(EntryRef *ref, char *name);
Same asLocateAttrib(), except that the attribute is created of it is not found.
EntryRef *LocateIndexedAttrib(EntryRef *ref, int which);
Returns a reference to thewhichth attribute of the referenced entry.
EntryRef *AddAttribType(EntryRef *ref, char *name, int reserved);
Adds an attribute namednameto the referenced entry. The attribute is intiialized with no tokens. Pass inTRUEforreserved.
void KillAttribType(EntryRef *ref, char *name);
Deletes the attribute namednamefrom the referenced entry.
void MoveAttribute(EntryRef *dest, EntryRef *src, char *aname, int destructive);
Copies the attribute namedanamefrom thesrcentry to a new attribute of thedestentry, including all content values and subattributes. IfdestructiveisTRUE, the original attribute in thesrcentry is deleted.
char *GetATok(EntryRef *ref, int which);
Finds thewhichth token inrefand copies it to a character buffer.whichstarts from 0. It returns a pointer to this buffer if it is successful, orNULLif there is no such token.The buffer allows string to be up to 500 bytes long; for arbitrarily long tokens, you have to use
GetToks(). CallingGetATok()a second time will change the contents of the buffer.
EntryRef *GetAReference(EntryRef *ref, int which)
If thewhichth token of the referenced entry is an entry reference (or sublist list reference), it returns a the reference.whichstarts from 0. If it is not a reference or the token does not exist,NULLis returned, the user is notified,andConfigErris set toRefFailed.
char *GetATokWithInfoAndVersions(EntryRef *ref, int which, TokInfo *info, VersionMarker **verPtr); #define GetATokWithInfo(ref, which, info) \ GetATokWithInfoAndVersions(ref, which, info, 0L) #define GetATokWithVersions(ref, which, versions) \ GetATokWithInfoAndVersions(ref, which, 0L, versions)
LikeGetATok(), but inheritance information is put intoinfo(if it is non-NULL) and version marking information is appended to*verPtr(ifverPtris non-NULL). See also "11.3.4 Inheritance" and "11.3.3 Version Markers".
EntryRef *GetAReferenceWithInfoAndVersions(EntryRef *ref, int which, TokInfo *info, VersionMarker **verPtr); #define GetAReferenceWithInfo(ref, which, info) \ GetAReferenceWithInfoAndVersions(ref, which, info, 0L) #define GetAReferenceWithVersions(ref, which, version) \ GetAReferenceWithInfoAndVersions(ref, which, 0L, version)
SeeGetAReference()andGetATokWithInfoAndVersions().
Ptr GetATokOrRefWithInfoAndVersions(EntryRef *ref, int which, int *type, TokInfo *info, VersionMarker **verPtr); #define GetATokOrRef(ref, which, type) \ GetATokOrRefWithInfoAndVersions(ref, which, type, 0L, 0L) #define GetATokOrRefWithInfo(ref, which, type, info) \ GetATokOrRefWithInfoAndVersions(ref, which, type, info, 0L) #define GetATokOrRefWithVersions(ref, which, type, vm) \ GetATokOrRefWithInfoAndVersions(ref, which, type, 0L, vm)
This is the most general token-getting function.*typeshould be-1on input; it will be set tostring_tok_infoorreference_tok_infoon return, specifying wether achar *orEntryRef *was returned. Ifinfois non-NULL, then it is filled in with inheritance information (see "11.3.4 Inheritance"). IfverPtris non-NULL, version marking information is appended to*verPtr(see "11.3.3 Version Markers").
long GetANumberWithVersions(EntryRef *ref, int which, long def, VersionMarker **vm); #define GetANumber(ref, which, def) \ GetNumberWithVersions(ref, which, def, 0L)
Gets thewhichth token (usingGetATokWithVersions()) and converts it to a number. If there is nowhichth token, or if it does not convert to a number, thendefis passed back.
void SetATok(EntryRef *ref, int which, char *newTok);
Finds thewhichth token in the referenced entry and replaces it withnewTok.whichstarts from 0. Only literal expressions may be replaced; attempting to replace a token that is an operation sentence will return an error to the user and setConfigErrtoCantSetTok. If there is nowhichth token, no changes are made andConfigErris set toReplacePastEnd.
void SetInlineEntry(EntryRef *ref, int which, char *name);
Replaces a literal expressionwith an inline entry definition with the given name.
void AddATok(EntryRef *ref, int which, int depth, char *newTok);
AddsnewTokjust before thewhichth token in the referenced entry.whichstarts from 0. Ifwhichis greater than or equal to the number of tokens, a new token is added to the end of the list.If
depthisDEEP, the new token is placed as "deep" as possible following token references. IfdepthisSHALLOW, it is placed as "shallow" as possible.
void SetOrAddATok(EntryRef *ref, int which, char *newTok);
Attempts to set the token usingSetATok(); ifConfigErrgets set toReplacePastEnd, the token is added usingAddATok(ref, which, DEEP, newTok).
void KillATok(EntryRef *ref, int which, int killVersion);
Removes the expression generating thewhichth token from the refernced entry.whichstarts from 0. Thewhichth token has to be derived from literal expression ifkillVersionisKILL_LIT; if thewhichth token is from a non-literal expression andKILL_LITis used, no expressions are deleted, the user is notified, andConfigErris settoCantSetTok.If
killVersionisKILL_ALL, any type of expression may be deleted -- even if the expression is responsibel for multiple tokens.If there is no
whichth token, then no changes are made andConfigErris set toReplacePastEnd.
void KillAllToksAfter(EntryRef *ref, int which, int killVersion);
Kills expressions yeilding tokens past and including thewhichth token.killVersionis as withKillATok().
void EmptyContentLine(EntryRef *ref);
Deletes all expressions from the content line of the referenced entry.
char *GetAttribTok(EntryRef *ref, char *attrib, int which); char *GetAttribTokWithVersions(EntryRef *ref, char *keyword, int which, VersionMarker **vm); void SetAttribTok(EntryRef *ref, char *attrib, int which, char *newTok); void AddAttribTok(EntryRef *ref, char *attrib, int which, int depth, char *newTok); void KillAttribTok(EntryRef *ref, char *attrib, int which, int killVersion); long GetAttribNumberWithVersions(EntryRef *ref, char *attrib, int which, long defval, VersionMarker **vm); #define GetAttribNumber(ref, attr, which, def) \ GetNumberWithVersions(ref, attr, which, def, NULL)
See the corresponding non-attribute versions (i.e. same function name, but withoutAttrib) above. Instead of working onref, these functions look for an attribute of the referenced entry namedattriband work on the attribute. If the attribute is not found, the user is notified andConfigErris set toAttribNotFound.
char *AllTokOneStr(char *name, char *buffer, long buffsize);
Takes an entry name innameand dumps all of the values from the content line of the entry intobuffer. Separate tokens with spaces in them will be quoted withinbuffer.
int EntriesToBufferWithVersions(EntryRef *ref, char *buffer, int pretty, long bufsize, VersionMarker **); #define min_prettiness (-1) /* Quote everything */ #define med_prettiness 0 /* Always quote when needed */ #define max_prettiness 1 /* Don't quote if it's just one token */ #define EntriesToBuffer(ref, buffer, pretty, size) \ EntriesToBufferWithVersions(ref, buffer, pretty, size, 0L)
LikeAllTokOneStr(), but an entry reference is specified instead, and more control is available over the format of the string throughpretty.
int EntriesToStringWithVersions(EntryRef *ref, infstr inf, int pretty, VersionMarker **versions);
LikeEntriesToBufferWithVersions(), but for infinite strings (see ??).
char *AttribsToBuffer(EntryRef *ref, char *attrib, char *buffer, long bufsize);
LikeEntriesToBuffer(), but the tokens are taken from an attribute of the referenced entry namedattrib. If the attribute is not found, the user is notified andConfigErris set toAttribNotFound.
int IsInListOfToksWithVersions(EntryRef *in_ref, char *tok, VersionMarker **vm); #define IsInListOfToks(ir, t) IsInListOfToksWithVersions(ir, t, 0L)
Looks for a token with valuetokin the content of the referenced entry. If such a token is found, its position in the token list will be returned, indexed from 1 instead of the usual 0. If no matching token is found, 0 is returned. Version markers are appened to*vmifvmis non-NULL(see "11.3.3 Version Markers").
int IsInListOfRefsWithVersions(EntryRef *in_ref, EntryRef *ref, VersionMarker **vm); #define IsInListOfRefs(ir, r) IsInListOfRefsWithVersions(ir, r, 0L) extern intvalidateRefList;
LikeIsInListOfToks(), but for searching for a reference-valued token. This function will delete tokens with invalid references values without warning unless thevalidateRefListflag is turned off.
TokenValue *GetToksAndRefsWithVersions(EntryRef *ref, int *size, VersionMarker **vm); #define GetToksAndRefs(ref, size) \ GetToksAndRefsWithVersions(ref, size, 0L)
Resolves all tokens in the content of the referenced entry and returns a newTokenValuearray.*sizeis set to the size of the returned array. Ifvmis non-NULL, version markers are appended to*vm(see "11.3.3 Version Markers"). See also "11.3.2 Token Values".On return,
*size== 0 does not imply that the return value isNULL. This can happen if the content of the referenced token is empty.
TokenValue *GetToksWithVersions(EntryRef *ref, int *size, VersionMarker **vm); #define GetToks(r, s) GetToksWithVersions(r, s, 0L)
LikeGetToksAndRefsWithVersions(), except if a reference-valued token found,ConfigErris set toDirAccessand the user is notified. Depending on the user's response, other valid tokens may or may not be returned.
TokenValue *GetRefsWithVersions(EntryRef *ref, int *size, VersionMarker **vm); #define GetRefs(r, s) GetRefsWithVersions(r, s, 0L)
LikeGetToksAndRefsWithVersions(), except if an entry referenced by token cannot befound,ConfigErris set toRefFailedand the user is notified. Depending on the user's response, other valid tokens may or may not be returned.
TokenValue *GetValidRefsWithVersions(EntryRef *ref, int *count, VersionMarker **vm);
LikeGetRefsWithVersions(), but no error is given if an invaid reference is encountered; instead, the invalid reference is deleted from the script.
TokenValue *ExpandTokenValueList(TokenValue *toks, int curCount, void *data, int type, TokInfo *info); #define MakeSingleTokenValue(v, i) \ ExpandTokenValueList(0L, 0, v, string_tok_info, i) #define AddTokenValueString(toks, count, str) \ ExpandTokenValueList(toks, count, str, string_tok_info, 0L) #define AddTokenValueRef(toks, count, ref) \ ExpandTokenValueList(toks, count, ref, reference_tok_info, 0L)
Add a newTokenValuerecord to the given array and returns a pointer to the expanded array. IftoksisNULL, a new array is created.curCountshould be the starting size of the array; the new size will becurCount+ 1.
typeshould bestring_tok_infoorref_tok_info. data should be achar *orEntryRef *, depending ontype.infois optional; a copy is made ifinfois supplied, so thatinfoshould still be freed.
int TokenValuesToInfStrWithVersions(TokenValue *toks, int count, infstr inf, int pretty, VersionMarker **vm); #define TokenValuesToInfStr(t, c, i, p) \ TokenValuesToInfStrWithVersions(t, c, i, p, 0L)
LikeEntriesToStringWithVersions(), but an array of tokens is passed in instead of an entry reference.
extern void FreeToks(TokenValue *toks, int count);
Frees structure returned byGetToks()et al. See also "11.3.2 Token Values".
TokenValue *DuplicateToks(TokenValue *toks, int count);
Returns a copy oftoks, which has to be freed separately.
int GetAnExpression(EntryRef *ref, int which, char *buffer, int buflen);
Gets a copy of thewhichth expression in the content of the referenced entry. No token references are evaluated. Use this utility sparingly.
void SetAnExpression(EntryRef *ref, int which, char *expr);
Sets thewhichth expression in the content of the referenced entry. No token references are evaluated. There are no internal checks guaranteeing the validity ofexpr. Use this utility sparingly.
int GetAllExpressions(EntryRef *ref, ECSList strings);
Gets copies of all of the expressions in the content of the referenced entry. The expressions are appended tostrings. Use this utility sparingly.
void SetAllExpressions(EntryRef *ref, ECSList strings);
Sets all of the expreesions in teh content of the referenced entry. Expressions may be added or deleted as necessary. There are no internal checks guaranteeing the validity of of the expressions. Use this utility sparingly.
int CountExpressions(EntryRef *ref);
Returns the number of expressions in the content of the referenced entry. This has no a priori relationship to the number of tokens that can be obtained from the content of the entry.
void CopyEntry(EntryRef *to, EntryRef *from);
Copies all of the expressions in the content offromto the content ofto, adding or deleting expressions intoas needed.
int CheckExpressionValidity(char *expr, char *reasonBuffer);
ReturnsTRUEof the given expression is syntactically valid. IfFALSEis returned,reasonBufferwill contain a string describing the reason.reasonBuffershould be at least 256 bytes long.
int IsInListOfExpressions(EntryRef *ref, char *expr);
Searches for an expression that matchesexprin the content of the referennced entry. If the expression is found, its position (index from 1) is returned.
EntryRef *LocateAttribFromInherit(InheritRec *inh, char *name);
Attempts to locate an inherited attribute namednamegiven the inheritance information. See also "11.3.4 Inheritance".
void FreeTokInfo(TokInfo *info);
Frees inheritance information ininfo. See also "11.3.4 Inheritance".
EntryRef *GetActualLocation(TokInfo *info);
Returns a reference to the entry which will be the first searched for inherited attributes.
EntryRef *GetActualLocationFromInherit(InheritRec *inh);
Same asGetActualLocation(), but theInheritRecpointer is passed directly.
int EqualInheritRecs(InheritRec *one, InheritRec *two);
ReturnsTRUEif the inheritance paths are the same.
InheritRec *AppendInheritRecs(InheritRec *one, InheritRec *appendToOne);
Returns an inheritance path that isonefollowed byappendToOne.oneis automaticallyfreed, butappendToOneis not.
InheritRec *PreceedInheritsWithRef(InheritRec *inh, EntryRef *ref);
Adds one reference to the beginning of the inheritance path; inh is automatically freed.
int SameVersions(VersionMarker *vm);
ReturnsTRUEif the script is unchanged from the state information stored invm. See also "11.3.3 Version Markers".
VersionMarker *AppendVersionMarkers(VersionMarker *dest, VersionMarker *src);
Returns aVersionMarker *AppendOneVersion(VersionMarker *vm, EntryRef *ref);VersionMarkerarray that isdestfollowed bysrc.destis automatically freed, butsrcis not.
Appends the version of the referenced entry tovmand returns a newVersionMarkerarray;vmis automatcially freed. If the referenced entry is already included invm's state information, then vm will be returned without modification.The state information about
refthat is kept in the new array includes attributes owned by the referenced entry, expressions in content of the entry (but not the content of the attributes), and the list access state of the entry.
VersionMarker *AppendOneExprVersion(VersionMarker *vm, EntryRef *ref);
LikeAppendOneVersion(), except that the list access state of the referenced entry is ignored.
int GetEntryVersion(EntryRef *ref);
Returns a number representing the "version" of the referenced entry. This number will change if any attributes are added to the entry, or if any expression in the content of the entry is modified.
long GetEffectiveVersion(EntryRef *ref, int accessed);
LikeGetEntryVersion(), except that this number is also influenced by the access state of the tokens in the referenced entry's content line. When the current item is changed, this number will change, but it will be the same whenever a particular item is current (all else constant).
ChangesRecord NewChangesRecord(void);
Allocates a new record for containg script-change annotations. This record can be activated withStartRemberingChanges(). The changes record should eventually be freed withDisposeChanges(),ForgetChanges(), orUndoChanges().
void StartRememberingChanges(ChangesRecord changes);
Begins recording inchangesall changes that are made to the script. This information can be later used to reverse all changes.Calls to
StartRememberingChanges()may be nested, butChangeRecords must be deactivated withStopRememberingChanges()in the reverse order in which they are activated.
void StopRememberingChanges(ChangesRecord changes);
Stops recording change information in changes. See alsoStartRememberingChanges(). You can start and stop change recording multiple times for one change record.
ChangesRecord CurrentChangesRecord(void);
Returns the record into which script changes are currently being recorded.
void DisposeChanges(ChangesRecord changes);
Frees aChangesRecordwithout affecting the script. The change annotations are permanently lost.
void ForgetChanges(ChangesRecord changes);
Frees aChangesRecordwithout affecting the script, but the change annotations may be appended to a currently active record..
void UndoChanges(ChangesRecord changes);
Frees aChangesRecord, reversing the recorded changes in the process.
ChangesRecord UndoChangesWithRedo(ChangesRecord changes);
LikeUndoChanges(), except thatchangesis not disposed; it is instead filled with the changes that revrsed the original changes, so that the changes can be redone.
int GetErrMask(int errCode);
This function returnsvoid SetErrMask(int errCode, int state);TRUEif the error represented byerrCodeis masked from the user; i.e., when an error of typeerrCodewould normally be reported to the user, the warning dialog is skipped. IfFALSEis returned, errors of this type are reported normally. The mask setting does not affect whetherConfigErris set.
Sets the mask state of the error represented byerrCode. SeeGetErrMask().
Generated with CERN WebMaker