コード例 #1
0
ファイル: actor.c プロジェクト: BPaden/garglk
/*======================================================================*/
ScriptEntry *scriptOf(int actor) {
    ScriptEntry *scr;

    if (admin[actor].script != 0) {
        for (scr = (ScriptEntry *) pointerTo(header->scriptTableAddress); !isEndOfArray(scr); scr++)
            if (scr->code == admin[actor].script)
                break;
        if (!isEndOfArray(scr))
            return scr;
    }
    return NULL;
}
コード例 #2
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
bool equalParameterArrays(Parameter parameters1[], Parameter parameters2[])
{
    int i;

    if ((parameters1 == NULL) != (parameters2 == NULL))
        return FALSE;
    if (parameters1 == NULL) // Because then parameter2 is also NULL
        return TRUE;
    for (i = 0; i < lengthOfParameterArray(parameters1); i++) {
        if (isEndOfArray(&parameters2[i])) return FALSE;
        if (parameters1[i].instance != parameters2[i].instance) return FALSE;
    }
    return isEndOfArray(&parameters2[i]);
}
コード例 #3
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
bool inParameterArray(Parameter theArray[], Aword theCode)
{
    int i;

    for (i = 0; !isEndOfArray(&theArray[i]) && theArray[i].instance != theCode; i++);
    return (theArray[i].instance == theCode);
}
コード例 #4
0
ファイル: Container.c プロジェクト: cspiegel/garglk
/*======================================================================*/
bool passesContainerLimits(Aint theContainer, Aint theAddedInstance) {
    LimitEntry *limit;
    Aword props;

    if (!isAContainer(theContainer))
        syserr("Checking limits for a non-container.");

    /* Find the container properties */
    props = instances[theContainer].container;

    if (containers[props].limits != 0) { /* Any limits at all? */
        for (limit = (LimitEntry *) pointerTo(containers[props].limits); !isEndOfArray(limit); limit++)
            if (limit->atr == 1-I_COUNT) { /* TODO This is actually some encoding of the attribute number, right? */
                if (countInContainer(theContainer) >= limit->val) {
                    interpret(limit->stms);
                    return(FALSE);
                }
            } else {
                if (sumAttributeInContainer(theContainer, limit->atr) + getInstanceAttribute(theAddedInstance, limit->atr) > limit->val) {
                    interpret(limit->stms);
                    return(FALSE);
                }
            }
    }
    return(TRUE);
}
コード例 #5
0
ファイル: params.c プロジェクト: BPaden/garglk
/* A parameter position with code == 0 means this is a multiple position.
 * We must loop over this position (and replace it by each present in the
 * matched list)
 */
int findMultiplePosition(Parameter parameters[]) {
    // TODO: this should look at the isAll and isExplicitMultiple flags instead
    int multiplePosition;
    for (multiplePosition = 0; !isEndOfArray(&parameters[multiplePosition]); multiplePosition++)
	if (parameters[multiplePosition].instance == 0)
	    return multiplePosition;
    return -1;
}
コード例 #6
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
void printParameterArray(Parameter parameters[]) {
    int i;
    printf("[");
    for (i = 0; !isEndOfArray(&parameters[i]); i++) {
	printf("%d ", (int)parameters[i].instance);
    }
    printf("]\n");
}
コード例 #7
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
void addParameter(Parameter theArrayPosition[], Parameter *theParameter)
{
    if (theArrayPosition == NULL) syserr("Adding to null parameter array");

	if (isEndOfArray(&theArrayPosition[0]))
		clearParameter(&theArrayPosition[0], NULL);
	copyParameter(&theArrayPosition[0], theParameter);
    setEndOfArray(&theArrayPosition[1]);
}
コード例 #8
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
void intersectParameterArrays(Parameter one[], Parameter other[])
{
    int i, last = 0;

    for (i = 0; !isEndOfArray(&one[i]); i++)
		if (inParameterArray(other, one[i].instance))
			one[last++] = one[i];
    setEndOfArray(&one[last]);
}
コード例 #9
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
void copyReferencesToParameterArray(Aint references[], Parameter parameterArray[])
{
    int i;

    for (i = 0; !isEndOfArray(&references[i]); i++) {
        parameterArray[i].instance = references[i];
        parameterArray[i].firstWord = EOF; /* Ensure that there is no word that can be used */
    }
    setEndOfArray(&parameterArray[i]);
}
コード例 #10
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
int lengthOfParameterArray(Parameter theArray[])
{
    int i = 0;

    if (theArray == NULL) return 0;

    while (!isEndOfArray(&theArray[i]))
        i++;
    return i;
}
コード例 #11
0
ファイル: attribute.c プロジェクト: cspiegel/garglk
/*----------------------------------------------------------------------*/
static AttributeEntry *findAttribute(AttributeEntry *attributeTable, int attributeCode)
{
  AttributeEntry *attribute = attributeTable;
  while (attribute->code != attributeCode) {
    attribute++;
    if (isEndOfArray(attribute))
      syserr("Attribute not found.");
  }
  return attribute;
}
コード例 #12
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
void subtractParameterArrays(Parameter theArray[], Parameter remove[])
{
    int i;
    
    if (remove == NULL) return;

    for (i = 0; !isEndOfArray(&theArray[i]); i++)
        if (inParameterArray(remove, theArray[i].instance))
            theArray[i].instance = 0;		/* Mark empty */
    compressParameterArray(theArray);
}
コード例 #13
0
ファイル: save.c プロジェクト: BPaden/garglk
/*----------------------------------------------------------------------*/
static void saveSets(AFILE saveFile) {
  SetInitEntry *initEntry;

  if (header->setInitTable != 0)
    for (initEntry = (SetInitEntry *)pointerTo(header->setInitTable);
	 !isEndOfArray(initEntry); initEntry++) {
      Set *attr = (Set *)getInstanceSetAttribute(initEntry->instanceCode, initEntry->attributeCode);
      fwrite((void *)&attr->size, sizeof(attr->size), 1, saveFile);
      fwrite((void *)attr->members, sizeof(attr->members[0]), attr->size, saveFile);
    }
}
コード例 #14
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
void copyParameterArray(Parameter to[], Parameter from[])
{
    int i;

    if (to == NULL && from == NULL) return;

    if (to == NULL) syserr("Copying to null parameter array");

	setEndOfArray(&to[0]);
    for (i = 0; !isEndOfArray(&from[i]); i++)
        addParameter(&to[i], &from[i]);
}
コード例 #15
0
ファイル: save.c プロジェクト: BPaden/garglk
/*----------------------------------------------------------------------*/
static void saveStrings(AFILE saveFile) {

  StringInitEntry *initEntry;

  if (header->stringInitTable != 0)
    for (initEntry = (StringInitEntry *)pointerTo(header->stringInitTable);
	 !isEndOfArray(initEntry); initEntry++) {
      char *attr = (char *)getInstanceStringAttribute(initEntry->instanceCode, initEntry->attributeCode);
      Aint length = strlen(attr) + 1;
      fwrite((void *)&length, sizeof(length), 1, saveFile);
      fwrite((void *)attr, 1, length, saveFile);
    }
}
コード例 #16
0
ファイル: save.c プロジェクト: BPaden/garglk
/*----------------------------------------------------------------------*/
static void restoreStrings(AFILE saveFile) {
  StringInitEntry *initEntry;

  if (header->stringInitTable != 0)
    for (initEntry = (StringInitEntry *)pointerTo(header->stringInitTable);
	 !isEndOfArray(initEntry); initEntry++) {
      Aint length;
      char *string;
      fread((void *)&length, sizeof(Aint), 1, saveFile);
      string = allocate(length+1);
      fread((void *)string, 1, length, saveFile);
      setInstanceAttribute(initEntry->instanceCode, initEntry->attributeCode, (Aptr)string);
    }
}
コード例 #17
0
ファイル: checkentry.c プロジェクト: BPaden/garglk
/*======================================================================*/
bool checksFailed(Aaddr adr, bool execute)
{
	CheckEntry *chk = (CheckEntry *) pointerTo(adr);
	if (chk->exp == 0) {
		if (execute == EXECUTE_CHECK_BODY_ON_FAIL)
			interpret(chk->stms);
		return TRUE;
	} else {
		while (!isEndOfArray(chk)) {
			if (!evaluate(chk->exp)) {
				if (execute == EXECUTE_CHECK_BODY_ON_FAIL)
					interpret(chk->stms);
				return TRUE;
			}
			chk++;
		}
		return FALSE;
	}
}
コード例 #18
0
ファイル: debug.c プロジェクト: BPaden/garglk
/*----------------------------------------------------------------------*/
static void showAttributes(AttributeEntry *attributes)
{
    AttributeEntry *at;
    int i;
    char str[80];

    if (attributes == 0)
        return;

    i = 1;
    for (at = attributes; !isEndOfArray(at); at++) {
        sprintf(str, "$i$t%s[%d] = %d", (char *) pointerTo(at->id), at->code, (int)at->value);
#if ISO == 0
        fromIso(str, str);
#endif
        output(str);
        i++;
    }
}
コード例 #19
0
ファイル: save.c プロジェクト: BPaden/garglk
/*----------------------------------------------------------------------*/
static void restoreSets(AFILE saveFile) {
  SetInitEntry *initEntry;

  if (header->setInitTable != 0)
    for (initEntry = (SetInitEntry *)pointerTo(header->setInitTable);
	 !isEndOfArray(initEntry); initEntry++) {
      Aint setSize;
      Set *set;
      int i;

      fread((void *)&setSize, sizeof(setSize), 1, saveFile);
      set = newSet(setSize);
      for (i = 0; i < setSize; i++) {
	Aword member;
	fread((void *)&member, sizeof(member), 1, saveFile);
	addToSet(set, member);
      }
      setInstanceAttribute(initEntry->instanceCode, initEntry->attributeCode, (Aptr)set);
    }
}
コード例 #20
0
ファイル: params.c プロジェクト: BPaden/garglk
/*======================================================================*/
Parameter *findEndOfParameterArray(Parameter *parameters) {
    Parameter *parameter;
    for (parameter = parameters; !isEndOfArray(parameter); parameter++);
    return parameter;
}