예제 #1
0
파일: flow.c 프로젝트: evanrmurphy/PicoLisp
// (dm sym . fun|cls2) -> sym
// (dm (sym . cls) . fun|cls2) -> sym
// (dm (sym sym2 [. cls]) . fun|cls2) -> sym
any doDm(any ex) {
   any x, y, msg, cls;

   x = cdr(ex);
   if (!isCell(car(x)))
      msg = car(x),  cls = val(Class);
   else {
      msg = caar(x);
      cls = !isCell(cdar(x))? cdar(x) :
         get(isNil(cddar(x))? val(Class) : cddar(x), cadar(x));
   }
   if (msg != T)
      redefine(ex, msg, val(Meth));
   if (isSym(cdr(x))) {
      y = val(cdr(x));
      for (;;) {
         if (!isCell(y) || !isCell(car(y)))
            err(ex, msg, "Bad message");
         if (caar(y) == msg) {
            x = car(y);
            break;
         }
         y = cdr(y);
      }
   }
   for (y = val(cls);  isCell(y) && isCell(car(y));  y = cdr(y))
      if (caar(y) == msg) {
         if (!equal(cdr(x), cdar(y)))
            redefMsg(msg, cls);
         cdar(y) = cdr(x);
         putSrc(cls, msg);
         return msg;
      }
   if (!isCell(car(x)))
      val(cls) = cons(x, val(cls));
   else
      val(cls) = cons(cons(msg, cdr(x)), val(cls));
   putSrc(cls, msg);
   return msg;
}
예제 #2
0
	//-----------------------------------------------------------------------
	Plane::Plane (const Vector3& rkPoint0, const Vector3& rkPoint1,
		const Vector3& rkPoint2)
	{
		redefine(rkPoint0, rkPoint1, rkPoint2);
	}
예제 #3
0
	//-----------------------------------------------------------------------
	Plane::Plane (const Vector3& rkNormal, const Vector3& rkPoint)
	{
		redefine(rkNormal, rkPoint);
	}
예제 #4
0
int include_file(char *name) {

    static int first_load = 0;
    int file_size, id;
    char *tmp_b, *n, *tmp_c;
    FILE *f;


    /* create the full output file name */
    if (use_incdir == YES)
        tmp_c = ext_incdir;
    else
        tmp_c = include_dir;

    if (create_full_name(tmp_c, name) == FAILED)
        return FAILED;

    f = fopen(full_name, "rb");
    id = 0;

    if (f == NULL && (tmp_c == NULL || tmp_c[0] == 0)) {
        sprintf(emsg, "Error opening file \"%s\".\n", name);
        if (first_load == 0)
            fprintf(stderr, "INCLUDE_FILE: %s", emsg);
        else
            print_error(emsg, ERROR_INC);
        return FAILED;
    }

    /* if not found in ext_incdir silently try the include directory */
    if (f == NULL && use_incdir == YES) {
        if (create_full_name(include_dir, name) == FAILED)
            return FAILED;

        f = fopen(full_name, "rb");
        id = 0;

        if (f == NULL && (include_dir == NULL || include_dir[0] == 0)) {
            sprintf(emsg, "Error opening file \"%s\".\n", name);
            if (first_load == 0)
                fprintf(stderr, "INCLUDE_FILE: %s", emsg);
            else
                print_error(emsg, ERROR_INC);
            return FAILED;
        }
    }

    /* if failed try to find the file in the current directory */
    if (f == NULL) {
        fprintf(stderr, "%s:%d: ", get_file_name(active_file_info_last->filename_id), active_file_info_last->line_current);
        fprintf(stderr, "INCLUDE_FILE: Could not open \"%s\", trying \"%s\"... ", full_name, name);
        f = fopen(name, "rb");
        id = 1;
    }

    if (f == NULL) {
        fprintf(stderr, "not found.\n");
        sprintf(emsg, "Error opening file \"%s\".\n", full_name);
        if (first_load == 0)
            fprintf(stderr, "INCLUDE_FILE: %s", emsg);
        else
            print_error(emsg, ERROR_INC);
        return FAILED;
    }

    if (id == 1) {
        fprintf(stderr, "found.\n");
        strcpy(full_name, name);
    }

    first_load = 1;

    if (extra_definitions == ON) {
        redefine("WLA_FILENAME", 0.0, name, DEFINITION_TYPE_STRING, strlen(name));
        redefine("wla_filename", 0.0, name, DEFINITION_TYPE_STRING, strlen(name));
    }

    fseek(f, 0, SEEK_END);
    file_size = ftell(f);
    fseek(f, 0, SEEK_SET);

    active_file_info_tmp = malloc(sizeof(struct active_file_info));
    if (active_file_info_tmp == NULL) {
        sprintf(emsg, "Out of memory while trying allocate error tracking data structure for file \"%s\".\n", full_name);
        print_error(emsg, ERROR_INC);
        return FAILED;
    }
    active_file_info_tmp->next = NULL;

    if (active_file_info_first == NULL) {
        active_file_info_first = active_file_info_tmp;
        active_file_info_last = active_file_info_tmp;
        active_file_info_tmp->prev = NULL;
    }
    else {
        active_file_info_tmp->prev = active_file_info_last;
        active_file_info_last->next = active_file_info_tmp;
        active_file_info_last = active_file_info_tmp;
    }

    active_file_info_tmp->line_current = 1;

    /* name */
    file_name_info_tmp = file_name_info_first;
    id = 0;
    while (file_name_info_tmp != NULL) {
        if (strcmp(file_name_info_tmp->name, full_name) == 0) {
            id = file_name_info_tmp->id;
            active_file_info_tmp->filename_id = id;
            break;
        }
        file_name_info_tmp = file_name_info_tmp->next;
    }

    if (id == 0) {
        file_name_info_tmp = malloc(sizeof(struct file_name_info));
        n = malloc(strlen(full_name)+1);
        if (file_name_info_tmp == NULL || n == NULL) {
            if (file_name_info_tmp != NULL)
                free(file_name_info_tmp);
            if (n != NULL)
                free(n);
            sprintf(emsg, "Out of memory while trying allocate info structure for file \"%s\".\n", full_name);
            print_error(emsg, ERROR_INC);
            return FAILED;
        }
        file_name_info_tmp->next = NULL;

        if (file_name_info_first == NULL) {
            file_name_info_first = file_name_info_tmp;
            file_name_info_last = file_name_info_tmp;
        }
        else {
            file_name_info_last->next = file_name_info_tmp;
            file_name_info_last = file_name_info_tmp;
        }

        strcpy(n, full_name);
        file_name_info_tmp->name = n;
        active_file_info_tmp->filename_id = file_name_id;
        file_name_info_tmp->id = file_name_id;
        file_name_id++;
    }

    /* reallocate buffer */
    if (include_in_tmp_size < file_size) {
        if (include_in_tmp != NULL)
            free(include_in_tmp);

        include_in_tmp = malloc(sizeof(char) * file_size);
        if (include_in_tmp == NULL) {
            sprintf(emsg, "Out of memory while trying to allocate room for \"%s\".\n", full_name);
            print_error(emsg, ERROR_INC);
            return FAILED;
        }

        include_in_tmp_size = file_size;
    }

    /* read the whole file into a buffer */
    fread(include_in_tmp, 1, file_size, f);
    fclose(f);

    if (size == 0) {
        buffer = malloc(sizeof(char) * (file_size + 4));
        if (buffer == NULL) {
            sprintf(emsg, "Out of memory while trying to allocate room for \"%s\".\n", full_name);
            print_error(emsg, ERROR_INC);
            return FAILED;
        }

        /* preprocess */
        preprocess_file(include_in_tmp, include_in_tmp + file_size, buffer, &size, full_name);

        buffer[size++] = 0xA;
        buffer[size++] = '.';
        buffer[size++] = 'E';
        buffer[size++] = ' ';

        open_files++;

        return SUCCEEDED;
    }

    tmp_b = malloc(sizeof(char) * (size + file_size + 4));
    if (tmp_b == NULL) {
        sprintf(emsg, "Out of memory while trying to expand the project to incorporate file \"%s\".\n", full_name);
        print_error(emsg, ERROR_INC);
        return FAILED;
    }

    /* reallocate tmp_a */
    if (tmp_a_size < file_size + 4) {
        if (tmp_a != NULL)
            free(tmp_a);

        tmp_a = malloc(sizeof(char) * (file_size + 4));
        if (tmp_a == NULL) {
            sprintf(emsg, "Out of memory while allocating new room for \"%s\".\n", full_name);
            print_error(emsg, ERROR_INC);
            return FAILED;
        }

        tmp_a_size = file_size + 4;
    }

    /* preprocess */
    inz = 0;
    preprocess_file(include_in_tmp, include_in_tmp + file_size, tmp_a, &inz, full_name);

    tmp_a[inz++] = 0xA;
    tmp_a[inz++] = '.';
    tmp_a[inz++] = 'E';
    tmp_a[inz++] = ' ';

    open_files++;

    memcpy(tmp_b, buffer, i);
    memcpy(tmp_b + i, tmp_a, inz);
    memcpy(tmp_b + i + inz, buffer + i, size - i);

    free(buffer);

    size += inz;
    buffer = tmp_b;

    return SUCCEEDED;
}
예제 #5
0
 //-----------------------------------------------------------------------
 DiPlane::DiPlane (const DiVec3& rkPoint0, const DiVec3& rkPoint1,
     const DiVec3& rkPoint2)
 {
     redefine(rkPoint0, rkPoint1, rkPoint2);
 }
예제 #6
0
 //-----------------------------------------------------------------------
 DiPlane::DiPlane (const DiVec3& rkNormal, const DiVec3& rkPoint)
 {
     redefine(rkNormal, rkPoint);
 }
예제 #7
0
파일: flow.c 프로젝트: evanrmurphy/PicoLisp
// (de sym . any) -> sym
any doDe(any ex) {
   redefine(ex, cadr(ex), cddr(ex));
   return cadr(ex);
}
예제 #8
0
	Array2D( int w, int h ){
		redefine( w, h );
	}