11.3 Script Utilities
EntryRef *LocateEntry(char *name);
Locates the entry named by), so that attributes can be accessed.name
in the script. If the entry is not found,NULL
is 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 inbuffer
with the (simple) name of the referenced entry.buffer
should 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
.def
should 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,ConfigErr
is 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 returnsNULL
if the referenced entry is not owned.
int ReferenceSameEntry(EntryRef *ref1, EntryRef *ref2);
ReturnsTRUE
of the references are to the same physical entry.
EntryRef *GetThisForReference(EntryRef *ref);
Returns the reference which would result in an evaluation of theTHIS
operator within the referenced entry.
EntryRef *MakeTempEntry(char *definitionString, EntryRef *carry);
Creates a temporary entry defined by the given string, with the content and attributes ofcarry
appended to it (carry
may 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 namedname
that belongs to the referenced entry.NULL
is 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 thewhich
th attribute of the referenced entry.
EntryRef *AddAttribType(EntryRef *ref, char *name, int reserved);
Adds an attribute namedname
to the referenced entry. The attribute is intiialized with no tokens. Pass inTRUE
forreserved
.
void KillAttribType(EntryRef *ref, char *name);
Deletes the attribute namedname
from the referenced entry.
void MoveAttribute(EntryRef *dest, EntryRef *src, char *aname, int destructive);
Copies the attribute namedaname
from thesrc
entry to a new attribute of thedest
entry, including all content values and subattributes. Ifdestructive
isTRUE
, the original attribute in thesrc
entry is deleted.
char *GetATok(EntryRef *ref, int which);
Finds thewhich
th token inref
and copies it to a character buffer.which
starts from 0. It returns a pointer to this buffer if it is successful, orNULL
if 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 thewhich
th token of the referenced entry is an entry reference (or sublist list reference), it returns a the reference.which
starts from 0. If it is not a reference or the token does not exist,NULL
is returned, the user is notified,andConfigErr
is 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
(ifverPtr
is 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.*type
should be-1
on input; it will be set tostring_tok_info
orreference_tok_info
on return, specifying wether achar *
orEntryRef *
was returned. Ifinfo
is non-NULL
, then it is filled in with inheritance information (see "11.3.4 Inheritance"). IfverPtr
is 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 thewhich
th token (usingGetATokWithVersions()
) and converts it to a number. If there is nowhich
th token, or if it does not convert to a number, thendef
is passed back.
void SetATok(EntryRef *ref, int which, char *newTok);
Finds thewhich
th token in the referenced entry and replaces it withnewTok
.which
starts 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 setConfigErr
toCantSetTok
. If there is nowhich
th token, no changes are made andConfigErr
is 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);
AddsnewTok
just before thewhich
th token in the referenced entry.which
starts from 0. Ifwhich
is greater than or equal to the number of tokens, a new token is added to the end of the list.If
depth
isDEEP
, the new token is placed as "deep" as possible following token references. Ifdepth
isSHALLOW
, it is placed as "shallow" as possible.
void SetOrAddATok(EntryRef *ref, int which, char *newTok);
Attempts to set the token usingSetATok()
; ifConfigErr
gets set toReplacePastEnd
, the token is added usingAddATok(ref, which, DEEP, newTok)
.
void KillATok(EntryRef *ref, int which, int killVersion);
Removes the expression generating thewhich
th token from the refernced entry.which
starts from 0. Thewhich
th token has to be derived from literal expression ifkillVersion
isKILL_LIT
; if thewhich
th token is from a non-literal expression andKILL_LIT
is used, no expressions are deleted, the user is notified, andConfigErr
is settoCantSetTok
.If
killVersion
isKILL_ALL
, any type of expression may be deleted -- even if the expression is responsibel for multiple tokens.If there is no
which
th token, then no changes are made andConfigErr
is set toReplacePastEnd
.
void KillAllToksAfter(EntryRef *ref, int which, int killVersion);
Kills expressions yeilding tokens past and including thewhich
th token.killVersion
is 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 namedattrib
and work on the attribute. If the attribute is not found, the user is notified andConfigErr
is set toAttribNotFound
.
char *AllTokOneStr(char *name, char *buffer, long buffsize);
Takes an entry name inname
and 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 andConfigErr
is set toAttribNotFound
.
int IsInListOfToksWithVersions(EntryRef *in_ref, char *tok, VersionMarker **vm); #define IsInListOfToks(ir, t) IsInListOfToksWithVersions(ir, t, 0L)
Looks for a token with valuetok
in 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*vm
ifvm
is 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 thevalidateRefList
flag 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 newTokenValue
array.*size
is set to the size of the returned array. Ifvm
is 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,ConfigErr
is set toDirAccess
and 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,ConfigErr
is set toRefFailed
and 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 newTokenValue
record to the given array and returns a pointer to the expanded array. Iftoks
isNULL
, a new array is created.curCount
should be the starting size of the array; the new size will becurCount
+ 1.
type
should bestring_tok_info
orref_tok_info
. data should be achar *
orEntryRef *
, depending ontype
.info
is optional; a copy is made ifinfo
is supplied, so thatinfo
should 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 thewhich
th 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 thewhich
th 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 offrom
to the content ofto
, adding or deleting expressions into
as needed.
int CheckExpressionValidity(char *expr, char *reasonBuffer);
ReturnsTRUE
of the given expression is syntactically valid. IfFALSE
is returned,reasonBuffer
will contain a string describing the reason.reasonBuffer
should be at least 256 bytes long.
int IsInListOfExpressions(EntryRef *ref, char *expr);
Searches for an expression that matchesexpr
in 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 namedname
given 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 theInheritRec
pointer is passed directly.
int EqualInheritRecs(InheritRec *one, InheritRec *two);
ReturnsTRUE
if the inheritance paths are the same.
InheritRec *AppendInheritRecs(InheritRec *one, InheritRec *appendToOne);
Returns an inheritance path that isone
followed byappendToOne
.one
is automaticallyfreed, butappendToOne
is 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);
ReturnsTRUE
if 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);VersionMarker
array that isdest
followed bysrc
.dest
is automatically freed, butsrc
is not.
Appends the version of the referenced entry tovm
and returns a newVersionMarker
array;vm
is automatcially freed. If the referenced entry is already included invm
's state information, then vm will be returned without modification.The state information about
ref
that 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 inchanges
all changes that are made to the script. This information can be later used to reverse all changes.Calls to
StartRememberingChanges()
may be nested, butChangeRecord
s 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 aChangesRecord
without affecting the script. The change annotations are permanently lost.
void ForgetChanges(ChangesRecord changes);
Frees aChangesRecord
without 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 thatchanges
is 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);TRUE
if the error represented byerrCode
is masked from the user; i.e., when an error of typeerrCode
would normally be reported to the user, the warning dialog is skipped. IfFALSE
is returned, errors of this type are reported normally. The mask setting does not affect whetherConfigErr
is set.
Sets the mask state of the error represented byerrCode
. SeeGetErrMask()
.
Generated with CERN WebMaker