/* ECMA-262 3rd Edition    9.6 */
HRESULT to_uint32(script_ctx_t *ctx, jsval_t val, DWORD *ret)
{
    double n;
    HRESULT hres;

    hres = to_number(ctx, val, &n);
    if(FAILED(hres))
        return hres;

    *ret = isnan(n) || isinf(n) ? 0 : n;
    return S_OK;
}
/* print disk drive geometry information for a particular drive */
static void do_geom(char *bios)
{
    int dr;
    struct disk_geom geom;

#if 0    
    dr = my_atoi(bios);
#endif
    dr = to_number(bios);
    if (get_geom(dr, &geom)==0) print_geom(dr, geom);
    else printf("Unrecognized BIOS device code 0x%02x\n", dr);
    
}
Exemple #3
0
static HRESULT error_constr(script_ctx_t *ctx, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r, jsdisp_t *constr) {
    jsdisp_t *err;
    UINT num = 0;
    jsstr_t *msg = NULL;
    HRESULT hres;

    if(argc) {
        double n;

        hres = to_number(ctx, argv[0], &n);
        if(FAILED(hres)) /* FIXME: really? */
            n = NAN;
        if(isnan(n))
            hres = to_string(ctx, argv[0], &msg);
        if(FAILED(hres))
            return hres;
        num = n;
    }

    if(!msg) {
        if(argc > 1) {
            hres = to_string(ctx, argv[1], &msg);
            if(FAILED(hres))
                return hres;
        }else {
            msg = jsstr_empty();
        }
    }

    switch(flags) {
    case INVOKE_FUNC:
    case DISPATCH_CONSTRUCT:
        hres = create_error(ctx, constr, num, msg, &err);
        jsstr_release(msg);
        if(FAILED(hres))
            return hres;

        if(r)
            *r = jsval_obj(err);
        else
            jsdisp_release(err);
        return S_OK;

    default:
        if(msg)
            jsstr_release(msg);
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }
}
Exemple #4
0
static HRESULT sort_cmp(script_ctx_t *ctx, jsdisp_t *cmp_func, jsval_t v1, jsval_t v2, INT *cmp)
{
    HRESULT hres;

    if(cmp_func) {
        jsval_t args[2] = {v1, v2};
        jsval_t res;
        double n;

        hres = jsdisp_call_value(cmp_func, NULL, DISPATCH_METHOD, 2, args, &res);
        if(FAILED(hres))
            return hres;

        hres = to_number(ctx, res, &n);
        jsval_release(res);
        if(FAILED(hres))
            return hres;

        if(n == 0)
            *cmp = 0;
        *cmp = n > 0.0 ? 1 : -1;
    }else if(is_undefined(v1)) {
        *cmp = is_undefined(v2) ? 0 : 1;
    }else if(is_undefined(v2)) {
        *cmp = -1;
    }else if(is_number(v1) && is_number(v2)) {
        double d = get_number(v1)-get_number(v2);
        if(d > 0.0)
            *cmp = 1;
        else
            *cmp = d < -0.0 ? -1 : 0;
    }else {
        jsstr_t *x, *y;

        hres = to_string(ctx, v1, &x);
        if(FAILED(hres))
            return hres;

        hres = to_string(ctx, v2, &y);
        if(SUCCEEDED(hres)) {
            *cmp = jsstr_cmp(x, y);
            jsstr_release(y);
        }
        jsstr_release(x);
        if(FAILED(hres))
            return hres;
    }

    return S_OK;
}
Exemple #5
0
static INT index_from_val(script_ctx_t *ctx, jsval_t v)
{
    double n;
    HRESULT hres;

    hres = to_number(ctx, v, &n);
    if(FAILED(hres)) {
        clear_ei(ctx); /* FIXME: Move ignoring exceptions to to_primitive */
        return 0;
    }

    n = floor(n);
    return is_int32(n) ? n : 0;
}
/* ECMA-262 3rd Edition    9.4 */
HRESULT to_integer(script_ctx_t *ctx, jsval_t v, double *ret)
{
    double n;
    HRESULT hres;

    hres = to_number(ctx, v, &n);
    if(FAILED(hres))
        return hres;

    if(isnan(n))
        *ret = 0;
    else
        *ret = n >= 0.0 ? floor(n) : -floor(-n);
    return S_OK;
}
Exemple #7
0
static HRESULT Math_atan2(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei)
{
    double x, y;
    HRESULT hres;

    TRACE("\n");

    if(arg_cnt(dp)<2) {
        if(retv) num_set_nan(retv);
        return S_OK;
    }

    hres = to_number(ctx, get_arg(dp, 0), ei, &y);
    if(FAILED(hres))
        return hres;

    hres = to_number(ctx, get_arg(dp, 1), ei, &x);
    if(FAILED(hres))
        return hres;

    if(retv) num_set_val(retv, atan2(y, x));
    return S_OK;
}
Exemple #8
0
/* ECMA-262 3rd Edition    9.4 */
HRESULT to_integer(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret)
{
    VARIANT num;
    HRESULT hres;

    hres = to_number(ctx, v, ei, &num);
    if(FAILED(hres))
        return hres;

    if(V_VT(&num) == VT_I4)
        *ret = num;
    else
        num_set_val(ret, V_R8(&num) >= 0.0 ? floor(V_R8(&num)) : -floor(-V_R8(&num)));

    return S_OK;
}
Exemple #9
0
/* ECMA-262 3rd Edition    9.5 */
HRESULT to_int32(script_ctx_t *ctx, jsval_t v, INT *ret)
{
    double n;
    HRESULT hres;

    const double p32 = (double)0xffffffff + 1;

    hres = to_number(ctx, v, &n);
    if(FAILED(hres))
        return hres;

    if(is_finite(n))
        n = n > 0 ? fmod(n, p32) : -fmod(-n, p32);
    else
        n = 0;

    *ret = (UINT32)n;
    return S_OK;
}
Exemple #10
0
Fichier : mh.c Projet : buzz/claws
static void mh_get_last_num(Folder *folder, FolderItem *item)
{
	gchar *path;
	GDir *dp;
	const gchar *d;
	GError *error = NULL;
	gint max = 0;
	gint num;

	cm_return_if_fail(item != NULL);

	debug_print("mh_get_last_num(): Scanning %s ...\n", item->path?item->path:"(null)");

	path = folder_item_get_path(item);
	cm_return_if_fail(path != NULL);
	if (change_dir(path) < 0) {
		g_free(path);
		return;
	}
	g_free(path);

	if ((dp = g_dir_open(".", 0, &error)) == NULL) {
		g_message("Couldn't open current directory: %s (%d).\n",
				error->message, error->code);
		g_error_free(error);
		return;
	}

	while ((d = g_dir_read_name(dp)) != NULL) {
		if ((num = to_number(d)) > 0 &&
		    g_file_test(d, G_FILE_TEST_IS_REGULAR)) {
			if (max < num)
				max = num;
		}
		if (num % 2000 == 0)
			GTK_EVENTS_FLUSH();
	}
	g_dir_close(dp);

	debug_print("Last number in dir %s = %d\n", item->path?item->path:"(null)", max);
	item->last_num = max;
}
Exemple #11
0
Fichier : mh.c Projet : buzz/claws
gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean *old_uids_valid)
{

	gchar *path;
	GDir *dp;
	const gchar *d;
	GError *error = NULL;
	gint num, nummsgs = 0;

	cm_return_val_if_fail(item != NULL, -1);

	debug_print("mh_get_num_list(): Scanning %s ...\n", item->path?item->path:"(null)");

	*old_uids_valid = TRUE;

	path = folder_item_get_path(item);
	cm_return_val_if_fail(path != NULL, -1);
	if (change_dir(path) < 0) {
		g_free(path);
		return -1;
	}
	g_free(path);

	if ((dp = g_dir_open(".", 0, &error)) == NULL) {
		g_message("Couldn't open current directory: %s (%d).\n",
				error->message, error->code);
		g_error_free(error);
		return -1;
	}

	while ((d = g_dir_read_name(dp)) != NULL) {
		if ((num = to_number(d)) > 0) {
			*list = g_slist_prepend(*list, GINT_TO_POINTER(num));
		   	nummsgs++;
		}
	}
	g_dir_close(dp);

	mh_set_mtime(folder, item);
	return nummsgs;
}
Exemple #12
0
    bool isValidSudoku(vector<vector<char> > &board) {
        bool **rows;
        bool **cols;
        bool **blocks;

        rows = new bool*[9];
        cols = new bool*[9];
        blocks = new bool*[9];

        for (int i = 0; i < 9; ++i)
        {
            rows[i] = new bool[9];
            cols[i] = new bool[9];
            blocks[i] = new bool[9];
        }

        for (int i = 0; i < 9; ++i)
        {
            for (int j = 0; j < 9; ++j)
            {
                rows[i][j] = cols[i][j] = blocks[i][j] = false;
            }
        }


        for (int i = 0; i < 9; ++i)
        {
            for (int j = 0; j < 9; ++j)
            {
                int c = to_number(board[i][j]);
                if (c == -1) continue;

                if (rows[i][c] || cols[j][c] || blocks[i - i % 3 + j / 3][c]) return false;

                rows[i][c] = cols[j][c] = blocks[i - i % 3 + j / 3][c] = true;
            }
        }

        return true;

    }
Exemple #13
0
static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei)
{
    ArrayInstance *This = array_from_vdisp(jsthis);

    TRACE("%p %d\n", This, This->length);

    switch(flags) {
    case DISPATCH_PROPERTYGET:
        V_VT(retv) = VT_I4;
        V_I4(retv) = This->length;
        break;
    case DISPATCH_PROPERTYPUT: {
        DOUBLE len = -1;
        DWORD i;
        HRESULT hres;

        hres = to_number(ctx, get_arg(dp, 0), ei, &len);
        if(FAILED(hres))
            return hres;

        len = floor(len);
        if(len!=(DWORD)len)
            return throw_range_error(ctx, ei, JS_E_INVALID_LENGTH, NULL);

        for(i=len; i<This->length; i++) {
            hres = jsdisp_delete_idx(&This->dispex, i);
            if(FAILED(hres))
                return hres;
        }

        This->length = len;
        break;
    }
    default:
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }

    return S_OK;
}
Exemple #14
0
/* ECMA-262 3rd Edition    15.8.2.15 */
static HRESULT Math_round(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei)
{
    double x;
    HRESULT hres;

    TRACE("\n");

    if(!arg_cnt(dp)) {
        num_set_nan(retv);
        return S_OK;
    }

    hres = to_number(ctx, get_arg(dp, 0), ei, &x);
    if(FAILED(hres))
        return hres;

    if(retv)
        num_set_val(retv, floor(x+0.5));
    return S_OK;
}
Exemple #15
0
static HRESULT Array_length(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    ArrayInstance *This = array_from_vdisp(jsthis);

    TRACE("%p %d\n", This, This->length);

    switch(flags) {
    case DISPATCH_PROPERTYGET:
        *r = jsval_number(This->length);
        break;
    case DISPATCH_PROPERTYPUT: {
        DOUBLE len = -1;
        DWORD i;
        HRESULT hres;

        hres = to_number(ctx, argv[0], &len);
        if(FAILED(hres))
            return hres;

        len = floor(len);
        if(len!=(DWORD)len)
            return throw_range_error(ctx, JS_E_INVALID_LENGTH, NULL);

        for(i=len; i<This->length; i++) {
            hres = jsdisp_delete_idx(&This->dispex, i);
            if(FAILED(hres))
                return hres;
        }

        This->length = len;
        break;
    }
    default:
        FIXME("unimplemented flags %x\n", flags);
        return E_NOTIMPL;
    }

    return S_OK;
}
Exemple #16
0
static void mh_get_last_num(Folder *folder, FolderItem *item)
{
	gchar *path;
	DIR *dp;
	struct dirent *d;
	gint max = 0;
	gint num;

	cm_return_if_fail(item != NULL);

	debug_print("mh_get_last_num(): Scanning %s ...\n", item->path?item->path:"(null)");

	path = folder_item_get_path(item);
	cm_return_if_fail(path != NULL);
	if (change_dir(path) < 0) {
		g_free(path);
		return;
	}
	g_free(path);

	if ((dp = opendir(".")) == NULL) {
		FILE_OP_ERROR(item->path, "opendir");
		return;
	}

	while ((d = readdir(dp)) != NULL) {
		if ((num = to_number(d->d_name)) > 0 &&
		    dirent_is_regular_file(d)) {
			if (max < num)
				max = num;
		}
		if (num % 2000 == 0)
			GTK_EVENTS_FLUSH();
	}
	closedir(dp);

	debug_print("Last number in dir %s = %d\n", item->path?item->path:"(null)", max);
	item->last_num = max;
}
Exemple #17
0
/* ECMA-262 3rd Edition    15.8.2.12 */
static HRESULT Math_abs(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    double d;
    HRESULT hres;

    TRACE("\n");

    if(!argc) {
        if(r)
            *r = jsval_number(NAN);
        return S_OK;
    }

    hres = to_number(ctx, argv[0], &d);
    if(FAILED(hres))
        return hres;

    if(r)
        *r = jsval_number(d < 0.0 ? -d : d);
    return S_OK;
}
Exemple #18
0
/* ECMA-262 3rd Edition    9.3 */
HRESULT to_number(script_ctx_t *ctx, VARIANT *v, jsexcept_t *ei, VARIANT *ret)
{
    switch(V_VT(v)) {
    case VT_EMPTY:
        num_set_nan(ret);
        break;
    case VT_NULL:
        V_VT(ret) = VT_I4;
        V_I4(ret) = 0;
        break;
    case VT_I4:
    case VT_R8:
        *ret = *v;
        break;
    case VT_BSTR:
        return str_to_number(V_BSTR(v), ret);
    case VT_DISPATCH: {
        VARIANT prim;
        HRESULT hres;

        hres = to_primitive(ctx, v, ei, &prim);
        if(FAILED(hres))
            return hres;

        hres = to_number(ctx, &prim, ei, ret);
        VariantClear(&prim);
        return hres;
    }
    case VT_BOOL:
        V_VT(ret) = VT_I4;
        V_I4(ret) = V_BOOL(v) ? 1 : 0;
        break;
    default:
        FIXME("unimplemented for vt %d\n", V_VT(v));
        return E_NOTIMPL;
    }

    return S_OK;
}
Exemple #19
0
static HRESULT Math_acos(script_ctx_t *ctx, vdisp_t *jsthis, WORD flags, unsigned argc, jsval_t *argv,
        jsval_t *r)
{
    double x;
    HRESULT hres;

    TRACE("\n");

    if(!argc) {
        if(r)
            *r = jsval_number(NAN);
        return S_OK;
    }

    hres = to_number(ctx, argv[0], &x);
    if(FAILED(hres))
        return hres;

    if(r)
        *r = jsval_number(x < -1.0 || x > 1.0 ? NAN : acos(x));
    return S_OK;
}
Exemple #20
0
/* Copy each item in a feed to the new directory */
static void rssyl_update_format_move_contents(FolderItem *olditem,
		FolderItem *newitem)
{
	gchar *oldpath, *newpath, *fname, *fpath, *nfpath;
	GDir *d = NULL;
	GError *error = NULL;

	oldpath = _old_rssyl_item_get_path(NULL, olditem);
	newpath = folder_item_get_path(newitem);

	if ((d = g_dir_open(oldpath, 0, &error)) == NULL) {
		debug_print("RSSyl: (FORMAT) couldn't open dir '%s': %s\n", oldpath,
				error->message);
		g_error_free(error);
		return;
	}

	debug_print("RSSyl: (FORMAT) moving contents of '%s' to '%s'\n",
			oldpath, newpath);

	while ((fname = (gchar *)g_dir_read_name(d)) != NULL) {
		gboolean migrate_file = to_number(fname) > 0 || strstr(fname, ".claws_") == fname;
		fpath = g_strconcat(oldpath, G_DIR_SEPARATOR_S, fname, NULL);
		if (migrate_file && g_file_test(fpath, G_FILE_TEST_IS_REGULAR)) {
			nfpath = g_strconcat(newpath, G_DIR_SEPARATOR_S, fname, NULL);
			move_file(fpath, nfpath, FALSE);
			g_free(nfpath);
		}
		g_remove(fpath);
		g_free(fpath);
	}

	g_dir_close(d);
	g_rmdir(oldpath);

	g_free(oldpath);
	g_free(newpath);
}
Exemple #21
0
gint mh_get_num_list(Folder *folder, FolderItem *item, GSList **list, gboolean *old_uids_valid)
{

	gchar *path;
	DIR *dp;
	struct dirent *d;
	gint num, nummsgs = 0;

	cm_return_val_if_fail(item != NULL, -1);

	debug_print("mh_get_num_list(): Scanning %s ...\n", item->path?item->path:"(null)");

	*old_uids_valid = TRUE;

	path = folder_item_get_path(item);
	cm_return_val_if_fail(path != NULL, -1);
	if (change_dir(path) < 0) {
		g_free(path);
		return -1;
	}
	g_free(path);

	if ((dp = opendir(".")) == NULL) {
		FILE_OP_ERROR(item->path, "opendir");
		return -1;
	}

	while ((d = readdir(dp)) != NULL) {
		if ((num = to_number(d->d_name)) > 0) {
			*list = g_slist_prepend(*list, GINT_TO_POINTER(num));
		   	nummsgs++;
		}
	}
	closedir(dp);

	mh_set_mtime(folder, item);
	return nummsgs;
}
Exemple #22
0
void permute_and_check(int start, int end)
{
	int i, tmp;

	if (start == end-1) {
		if (check_prop())
			sum += to_number(0, 9);
		return;
	}

	permute_and_check(start+1, end);
	for (i = start+1; i < end; i++) {
		tmp = digits[start];
		digits[start] = digits[i];
		digits[i] = tmp;
		permute_and_check(start+1, end);
	}

	tmp = digits[start];
	for (i = start; i < end-1; i++)
		digits[i] = digits[i+1];
	digits[end-1] = tmp;
}
/* ECMA-262 3rd Edition    9.3 */
HRESULT to_number(script_ctx_t *ctx, jsval_t val, double *ret)
{
    switch(jsval_type(val)) {
    case JSV_UNDEFINED:
        *ret = NAN;
        return S_OK;
    case JSV_NULL:
        *ret = 0;
        return S_OK;
    case JSV_NUMBER:
        *ret = get_number(val);
        return S_OK;
    case JSV_STRING:
        return str_to_number(get_string(val), ret);
    case JSV_OBJECT: {
        jsval_t prim;
        HRESULT hres;

        hres = to_primitive(ctx, val, &prim, HINT_NUMBER);
        if(FAILED(hres))
            return hres;

        hres = to_number(ctx, prim, ret);
        jsval_release(prim);
        return hres;
    }
    case JSV_BOOL:
        *ret = get_bool(val) ? 1 : 0;
        return S_OK;
    case JSV_VARIANT:
        FIXME("unimplemented for variant %s\n", debugstr_variant(get_variant(val)));
        return E_NOTIMPL;
    };

    assert(0);
    return E_FAIL;
}
Exemple #24
0
static void mh_scan_tree_recursive(FolderItem *item)
{
	Folder *folder;
#ifdef G_OS_WIN32
	GDir *dir;
#else
	DIR *dp;
	struct dirent *d;
#endif
	const gchar *dir_name;
	struct stat s;
 	gchar *real_path, *entry, *utf8entry, *utf8name;
	gint n_msg = 0;

	cm_return_if_fail(item != NULL);
	cm_return_if_fail(item->folder != NULL);

	folder = item->folder;

	real_path = item->path ? mh_filename_from_utf8(item->path) : g_strdup(".");
#ifdef G_OS_WIN32
	dir = g_dir_open(real_path, 0, NULL);
	if (!dir) {
		g_warning("failed to open directory: %s\n", real_path);
		g_free(real_path);
		return;
	}
#else
	dp = opendir(real_path);
	if (!dp) {
		FILE_OP_ERROR(real_path, "opendir");
		return;
	}
#endif
	g_free(real_path);

	debug_print("scanning %s ...\n",
		    item->path ? item->path
		    : LOCAL_FOLDER(item->folder)->rootpath);
	if (folder->ui_func)
		folder->ui_func(folder, item, folder->ui_func_data);

#ifdef G_OS_WIN32
	while ((dir_name = g_dir_read_name(dir)) != NULL) {
#else
	while ((d = readdir(dp)) != NULL) {
		dir_name = d->d_name;
#endif
		if (dir_name[0] == '.') continue;

		utf8name = mh_filename_to_utf8(dir_name);
		if (item->path)
			utf8entry = g_strconcat(item->path, G_DIR_SEPARATOR_S,
						utf8name, NULL);
		else
			utf8entry = g_strdup(utf8name);
		entry = mh_filename_from_utf8(utf8entry);

		if (
#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
			d->d_type == DT_DIR ||
			(d->d_type == DT_UNKNOWN &&
#endif
			g_stat(entry, &s) == 0 && S_ISDIR(s.st_mode)
#if !defined(G_OS_WIN32) && defined(HAVE_DIRENT_D_TYPE)
			)
#endif
		   ) {
			FolderItem *new_item = NULL;
			GNode *node;

			node = item->node;
			for (node = node->children; node != NULL; node = node->next) {
				FolderItem *cur_item = FOLDER_ITEM(node->data);
				gchar *curpath = mh_filename_from_utf8(cur_item->path);
				if (!strcmp2(curpath, entry)) {
					new_item = cur_item;
					g_free(curpath);
					break;
				}
				g_free(curpath);
			}
			if (!new_item) {
				debug_print("new folder '%s' found.\n", entry);
				new_item = folder_item_new(folder, utf8name, utf8entry);
				folder_item_append(item, new_item);
			}

			if (!item->path) {
				if (!folder->inbox &&
				    !strcmp(dir_name, INBOX_DIR)) {
					new_item->stype = F_INBOX;
					folder->inbox = new_item;
				} else if (!folder->outbox &&
					   !strcmp(dir_name, OUTBOX_DIR)) {
					new_item->stype = F_OUTBOX;
					folder->outbox = new_item;
				} else if (!folder->draft &&
					   !strcmp(dir_name, DRAFT_DIR)) {
					new_item->stype = F_DRAFT;
					folder->draft = new_item;
				} else if (!folder->queue &&
					   !strcmp(dir_name, QUEUE_DIR)) {
					new_item->stype = F_QUEUE;
					folder->queue = new_item;
				} else if (!folder->trash &&
					   !strcmp(dir_name, TRASH_DIR)) {
					new_item->stype = F_TRASH;
					folder->trash = new_item;
				}
			}

			mh_scan_tree_recursive(new_item);
		} else if (to_number(dir_name) > 0) n_msg++;

		g_free(entry);
		g_free(utf8entry);
		g_free(utf8name);
	}

#ifdef G_OS_WIN32
	g_dir_close(dir);
#else
	closedir(dp);
#endif

	mh_set_mtime(folder, item);
}

static gboolean mh_rename_folder_func(GNode *node, gpointer data)
{
	FolderItem *item = node->data;
	gchar **paths = data;
	const gchar *oldpath = paths[0];
	const gchar *newpath = paths[1];
	gchar *base;
	gchar *new_itempath;
	gint oldpathlen;

	oldpathlen = strlen(oldpath);
	if (strncmp(oldpath, item->path, oldpathlen) != 0) {
		g_warning("path doesn't match: %s, %s\n", oldpath, item->path);
		return TRUE;
	}

	base = item->path + oldpathlen;
	while (*base == G_DIR_SEPARATOR) base++;
	if (*base == '\0')
		new_itempath = g_strdup(newpath);
	else
		new_itempath = g_strconcat(newpath, G_DIR_SEPARATOR_S, base,
					   NULL);
	g_free(item->path);
	item->path = new_itempath;

	return FALSE;
}
Exemple #25
0
/* ECMA-262 3rd Edition    15.4.4.10 */
static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, DISPPARAMS *dp,
        VARIANT *retv, jsexcept_t *ei)
{
    jsdisp_t *arr, *jsthis;
    DOUBLE range;
    DWORD length, start, end, idx;
    HRESULT hres;

    TRACE("\n");

    hres = get_length(ctx, vthis, ei, &jsthis, &length);
    if(FAILED(hres))
        return hres;

    if(arg_cnt(dp)) {
        hres = to_number(ctx, get_arg(dp, 0), ei, &range);
        if(FAILED(hres))
            return hres;

        range = floor(range);
        if(-range>length || isnan(range)) start = 0;
        else if(range < 0) start = range+length;
        else if(range <= length) start = range;
        else start = length;
    }
    else start = 0;

    if(arg_cnt(dp)>1) {
        hres = to_number(ctx, get_arg(dp, 1), ei, &range);
        if(FAILED(hres))
            return hres;

        range = floor(range);
        if(-range>length) end = 0;
        else if(range < 0) end = range+length;
        else if(range <= length) end = range;
        else end = length;
    }
    else end = length;

    hres = create_array(ctx, (end>start)?end-start:0, &arr);
    if(FAILED(hres))
        return hres;

    for(idx=start; idx<end; idx++) {
        VARIANT v;

        hres = jsdisp_get_idx(jsthis, idx, &v, ei);
        if(hres == DISP_E_UNKNOWNNAME)
            continue;

        if(SUCCEEDED(hres)) {
            hres = jsdisp_propput_idx(arr, idx-start, &v, ei);
            VariantClear(&v);
        }

        if(FAILED(hres)) {
            jsdisp_release(arr);
            return hres;
        }
    }

    if(retv)
        var_set_jsdisp(retv, arr);
    else
        jsdisp_release(arr);

    return S_OK;
}
Exemple #26
0
	int main(int argc,char **argv)
	{
		char *name,*reboot_arg,*ident_opt,*new_root;
		char *tell_param, *uninst_dev, *param, *act1, *act2, ch;
		static char *bitmap_file;
		int more,version,uninstall,validate,activate,instmbr,geom;
		int fd, temp=0, tell_early=0;
		int raid_offset;
#if !__MSDOS__
		struct stat st;
#endif /* !__MSDOS__ */

		errstd = stderr;
#if VERSION_MINOR>=50
		if (sizeof(MENUTABLE)!=256) die("MENUTABLE is not 256 bytes (common.h)");
#if !__MSDOS__
		cfg_alpha_check();
#endif /* !__MSDOS__ */
#endif
		config_file = DFL_CONFIG;
		act1 = act2 = tell_param = 
			reboot_arg = identify = ident_opt = new_root = uninst_dev = NULL;
		do_md_install = zflag =
			version = uninstall = validate = activate = instmbr = 0;
		verbose = -1;
#if !__MSDOS__
		name = *argv;
#else  /* __MSDOS__ */
		name = "lilo";
#endif /* __MSDOS__ */
		argc--;

#if !__MSDOS__    
		if (atexit( (void(*)(void)) sync)) die("atexit(sync)");
		if (atexit( (void(*)(void)) purge)) die("atexit(purge)");
#endif /* !__MSDOS__ */

		cfg_init(cf_options);
		while (argc && **++argv == '-') {
			argc--;
			/* first those options with a mandatory parameter */
			/* Notably absent are "RuUvw" */
			if (strchr("AbBCdDEfiImMPrsSTxZ", ch=(*argv)[1])) {
				if ((*argv)[2]) param = (*argv)+2;
				else {
					param = *++argv;
					if(argc-- <= 0) usage(name);
				}
			} else { 
				param = NULL;
				if (strchr("cFglLpqtVXz", ch)	/* those with no args */
						&& (*argv)[2]) usage(name);
			}
#if 0
			fprintf(errstd,"argc=%d, *argv=%s, ch=%c param=%s\n", argc, *argv, ch, param);
#endif
			switch (ch) {
#if !__MSDOS__
				case 'A':
					activate = 1;
					act1 = param;
					if (argc && argv[1][0] != '-') {
						act2 = *++argv;
						argc--;
					}
					break;
				case 'b':
					cfg_set(cf_options,"boot",param,NULL);
					break;
				case 'B':
					cfg_set(cf_options,"bitmap",param,NULL);
					break;
				case 'c':
					cfg_set(cf_options,"compact",NULL,NULL);
					compact = 1;
					break;
#endif /* !__MSDOS */
				case 'C':
					config_file = param;
					break;
#if !__MSDOS__
				case 'd':
					cfg_set(cf_options,"delay",param,NULL);
					break;
				case 'D':
					cfg_set(cf_options,"default",param,NULL);
					break;
				case 'E':
					eflag=1;
					bitmap_file = param;
					break;
				case 'f':
					cfg_set(cf_options,"disktab",param,NULL);
					break;
				case 'F':
					force_fs=1;
					break;
				case 'g':
					geometric |= AD_GEOMETRIC;
					break;
				case 'H':
					force_raid=1;
					break;
				case 'i':
					cfg_set(cf_options,"install",param,NULL);
					break;
				case 'I':
					identify = param;
					if (argc && *argv[1] != '-') {
						ident_opt = *++argv;
						argc--;
					} else {
						ident_opt = "i";
					}
					break;
				case 'l':
					geometric |= AD_LINEAR;
					break;
				case 'L':
					geometric |= AD_LBA32;
					break;
#endif /* !__MSDOS__ */
				case 'm':
					cfg_set(cf_options,"map",param,NULL);
					break;
#if !__MSDOS__
				case 'M':
					instmbr = 1;
					act1 = param;
#if !defined LCF_BUILTIN	|| 1
					if (argc && argv[1][0] != '-') {
						act2 = *++argv;
						argc--;
					}
#endif
					break;
				case 'p':
					passw = 1;	/* force re-gen of password file */
					break;
				case 'P':
					if ((act1=strchr(param,'='))) {
						*act1++ = 0;	/* null terminate */
						cfg_set(cf_options,param,act1,NULL);
					}
					else if (!strcasecmp(param,"fix"))
						cfg_set(cf_options,"fix-table",NULL,NULL);
					else if (!strcasecmp(param,"ignore"))
						cfg_set(cf_options,"ignore-table",NULL,NULL);
					else if (!strcasecmp(param,"x"))
						extended_pt = 1;
					else
						cfg_set(cf_options,param,NULL,NULL);
					break;
#endif /* !__MSDOS__ */
				case 'q':
					query = 1;
					break;
#if !__MSDOS__
				case 'r':
					new_root = param;
					break;
#endif /* !__MSDOS__ */
				case 'R':
					if (*(param = (*argv)+2)) argc++;
					else if (argc) param = *++argv;
					else reboot_arg = "";

					while (argc) {
						if (!reboot_arg)
							*(reboot_arg = alloc(strlen(param)+1)) = 0;
						else {
							param = *++argv;
							strcat(reboot_arg = ralloc(reboot_arg,
										strlen(reboot_arg)+strlen(param)+2)," ");
						}
						strcat(reboot_arg, param);
						argc--;
					}
#if 0
					fprintf(errstd,"REBOOT=\"%s\"\n", reboot_arg);		    
#endif
					break;
#if !__MSDOS__
				case 's':
					cfg_set(cf_options,"backup",param,NULL);
					break;
				case 'S':
					cfg_set(cf_options,"force-backup",param,NULL);
					break;
				case 't':
					test = 1;
					break;
				case 'T':
					tell_param = param;
					break;
				case 'u':
					validate = 1;
					/* fall through */
				case 'U':	/* argument to -u or -U is optional */
					uninstall = 1;
					if ((*argv)[2]) param = (*argv)+2;
					else if (argc && argv[1][0] != '-') {
						param = *++argv;
						argc--;
					}
					uninst_dev = param;
					break;
#endif /* !__MSDOS__ */
				case 'v':
					if ((*argv)[2]) param = (*argv)+2;
					else if (argc && argv[1][0]>='0' && argv[1][0]<='9') {
						param = *++argv;
						argc--;
					}
					if (param) 
						verbose = to_number(param);
					else
						if (verbose<0) verbose = 1;
						else verbose++;
					if (verbose) errstd = stdout;
					break;
				case 'V':
					version = 1;
					break;
#if !__MSDOS__
				case 'w':
					cfg_set(cf_options,"nowarn",NULL,NULL);
					nowarn = 1;
					if ( (*argv)[2] == '+' ) nowarn = -1;
					break;
				case 'x':
					cfg_set(cf_options,RAID_EXTRA_BOOT,param,NULL);
					break;
#endif /* !__MSDOS__ */
				case 'X':
					configuration();
					exit(0);
#if !__MSDOS__
				case 'z':
					zflag++;	/* force zero of MBR 8-byte area */
					break;
				case 'Z':
					cfg_set(cf_options,"bios-passes-dl",param,NULL);
					break;
#endif /* !__MSDOS__ */
				default:
					usage(name);
			}
		}
		if (argc) usage(name);
#if !__MSDOS__
		if (!new_root) new_root = getenv("ROOT");
		if (new_root && *new_root) {
			pp_fd = fopen(PARTITIONS, "r");
			if (chroot(new_root) < 0) die("chroot %s: %s",new_root,strerror(errno));
			if (chdir("/dev") < 0)
				warn("root at %s has no /dev directory", new_root);
			if (chdir("/") < 0) die("chdir /: %s",strerror(errno));
		}
		if (atexit(temp_remove)) die("atexit() failed");
		if (version+activate+instmbr+(tell_param!=NULL) > 1) usage(name);
		if (activate) do_activate(act1, act2);
#endif /* !__MSDOS__ */

		if (verbose > 0 || version) {
			printf("LILO version %d.%d%s", VERSION_MAJOR, VERSION_MINOR, VERSION_EDIT);
			if (test)
				printf(" (test mode)\n");
			else
				printf(" (released %s)\n", VERSION_DATE);
			if (version && verbose<=0) {
				/* exit if user asks for version and no verbose */
				return 0;
			}
			printf("  * Copyright (C) 1992-1998 Werner Almesberger  (until v20)\n"
					"  * Copyright (C) 1999-2007 John Coffman  (until v22)\n"
					"  * Copyright (C) 2009-2011 Joachim Wiedorn  (since v23)\n"
					"This program comes with ABSOLUTELY NO WARRANTY. This is free software \n"
					"distributed under the BSD License (3-clause). Details can be found in \n"
					"the file COPYING, which is distributed with this software.\n"
				  );
			if (verbose>0) {
#if !__MSDOS__
#include <sys/utsname.h>
				struct utsname buf;
#endif
				printf("Compiled at %s on %s%s\n", __TIME__, __DATE__, semi);
#if !__MSDOS__
				if (verbose>=2 && uname(&buf)==0) {
					printf("Running %s kernel %s on %s\n",
							buf.sysname, buf.release, buf.machine);
				}
#endif
			}
			printf("\n");
			if (version) {
				if (verbose>=2) configuration();
				return 0;
			}
		}

		if (verbose > 0) errstd = stdout;
#if !__MSDOS__
		preload_types();
		if (geometric & (geometric-1))
			die ("Only one of '-g', '-l', or '-L' may be specified");

		if (tell_param) tell_early = strcasecmp(tell_param, "chrul")
			&& strcasecmp(tell_param, "ebda");
		if (eflag) do_bitmap_edit(bitmap_file);
		if (tell_param && tell_early) probe_tell(tell_param);
		if (instmbr) do_install_mbr(act1, act2);
#endif /* !__MSDOS__ */    

		fd = cfg_open(config_file);
		more = fd<0 ? 0 : cfg_parse(cf_options);

#if !__MSDOS__
		temp = cfg_get_flag(cf_options,"nowarn");
		if (nowarn < 0) nowarn = 0;
		else nowarn = temp;
		/* All warnings appear if very verbose modes used */
		if (verbose>=3) nowarn = 0;
#endif /* !__MSDOS__ */

		if (verbose>=6) printf("main: cfg_parse returns %d\n", more);

#if !__MSDOS__
		if (tell_param && !tell_early) probe_tell(tell_param);

		if (fstat(fd,&st) < 0)
			die("fstat %s: %s", config_file, strerror(errno) );

		if (S_ISREG(st.st_mode)) {
			if (st.st_uid)
				warn("%s should be owned by root", config_file);
			else if (st.st_mode & (S_IWGRP | S_IWOTH))
				warn("%s should be writable only for root", config_file);
			config_read = !!(st.st_mode & (S_IRGRP | S_IROTH));
		}

		if (!cfg_get_flag(cf_options,"nodevcache"))  preload_dev_cache();

		if (verbose<0 && cfg_get_strg(cf_options,"verbose"))
			verbose = to_number(cfg_get_strg(cf_options,"verbose"));
		if (verbose<0) verbose = 0;
		if (verbose) errstd = stdout;

		compact = cfg_get_flag(cf_options,"compact");
		geom = cfg_get_flag(cf_options,"geometric");
		linear = cfg_get_flag(cf_options,"linear");
		lba32  = cfg_get_flag(cf_options,"lba32");

		if (geom+linear+lba32 > 1)
			die("May specify only one of GEOMETRIC, LINEAR or LBA32");
		if (geometric) {
			if (geom+linear+lba32 > 0)  
				warn("Ignoring entry '%s'", geom ? "geometric" :
						linear ? "linear" : "lba32");
			geom = linear = lba32 = 0;
			if (geometric==AD_LBA32) lba32 = 1;
			else if (geometric==AD_LINEAR) linear = 1;
			else if (geometric==AD_GEOMETRIC) geom = 1;
		}    
		if (geom+linear+lba32 == 0) {
			warn("LBA32 addressing assumed");
			lba32 = 1;
		}
		if (linear) warn(
				"LINEAR is deprecated in favor of LBA32:  LINEAR specifies 24-bit\n"
				"  disk addresses below the 1024 cylinder limit; LBA32 specifies 32-bit disk\n"
				"  addresses not subject to cylinder limits on systems with EDD-BIOS extensions;\n"
				"  use LINEAR only if you are aware of its limitations.");

		if (identify) identify_image(identify,ident_opt);

		if (uninstall)
			bsect_uninstall(uninst_dev ? uninst_dev : cfg_get_strg(cf_options,
						"boot"),cfg_get_strg(cf_options,"backup"),validate);
#endif /* !__MSDOS__ */

		if (reboot_arg) {
			map_patch_first(cfg_get_strg(cf_options,"map") ? cfg_get_strg(
						cf_options,"map") : MAP_FILE, reboot_arg);
			exit(0);
		}

#if !__MSDOS__
		if ( (param = cfg_get_strg(cf_options,"bios-passes-dl")) ) {
			if (strchr("YyTt1", *param)) bios_passes_dl = DL_GOOD;
			if (strchr("NnFf0", *param)) bios_passes_dl = DL_BAD;
		}
		if (bios_passes_dl == DL_NOT_SET) 	check_bios();	/* in probe.c */

		if (compact && (linear || lba32) && verbose>=4)
			warn("COMPACT may conflict with %s on some "
					"systems", lba32 ? "LBA32" : "LINEAR");

		geo_init(cfg_get_strg(cf_options,"disktab"));
#endif /* !__MSDOS__ */
		if (query)
			show_images(!cfg_get_strg(cf_options,"map") ? MAP_FILE :
					cfg_get_strg(cf_options,"map"));

#if !__MSDOS__
		/*************************************************/
		/*  Doing a real install (may be test mode)      */
		/*************************************************/

		/* test for a RAID installation */
		raid_offset = raid_setup();
		if (verbose >= 2) {
			printf("raid_setup returns offset = %08X  ndisk = %d\n", raid_offset, ndisk);
			dump_serial_nos();    
		}

		if (verbose >=2 && do_md_install)
			printf("raid flags: at bsect_open  0x%02X\n", raid_flags);

		bsect_open(
				cfg_get_strg(cf_options,"boot"),
				cfg_get_strg(cf_options,"map") ?
				cfg_get_strg(cf_options,"map") : MAP_FILE,
				cfg_get_strg(cf_options,"install"),
				cfg_get_strg(cf_options,"delay") ?
				timer_number(cfg_get_strg(cf_options,"delay")) : 0,
				cfg_get_strg(cf_options,"timeout") ?
				timer_number(cfg_get_strg(cf_options,"timeout")) : -1,
				raid_offset );
		if (more) {
			cfg_init(cf_top);
			if (cfg_parse(cf_top)) cfg_error("Syntax error");
		}

		temp = bsect_number();
		if (temp==0) die("No images have been defined.");
		else if (temp<0) die("Default image doesn't exist.");

#ifdef LCF_VIRTUAL
		check_vmdefault();
#endif
#ifdef LCF_NOKEYBOARD
		check_nokbdefault();
#endif
		check_fallback();
		check_unattended();

		if (verbose>=2) dump_serial_nos();
		if (do_md_install) raid_final();
		else if (!test) {
			char *cp;

			if (verbose) printf("Writing boot sector.\n");

			cp = cfg_get_strg(cf_options,"force-backup");
			if (cp) bsect_update(cp,1,0);
			else bsect_update(cfg_get_strg(cf_options,"backup"),0,0);

		} 
		else {
			bsect_cancel();
			if (passw)
				printf("The password crc file has *NOT* been updated.\n");

			printf("The boot sector and the map file have *NOT* been "
					"altered.\n");
		}
		if (verbose>=4) dump_serial_nos();
		if (warnings) {
			if (warnings>1)
				printf("%d warnings were ", warnings);
			else printf("One warning was ");
			printf("%sed.\n", nowarn ? "suppress" : "issu");
		}
#else  /* __MSDOS__ */
		die("No option switches specified:  -q, -R, or -V");
#endif /* __MSDOS__ */

		return 0;
	}
Exemple #27
0
void rssyl_update_comments(RFolderItem *ritem)
{
	FolderItem *item = &ritem->item;
	FeedItem *fi = NULL;
	RFetchCtx *ctx = NULL;
	GDir *dp;
	const gchar *d;
	GError *error = NULL;
	gint num;
	gchar *path, *msg, *fname;
	MainWindow *mainwin = mainwindow_get_mainwindow();

	g_return_if_fail(ritem != NULL);

	if( ritem->fetch_comments == FALSE )
		return;

	path = folder_item_get_path(item);
	g_return_if_fail(path != NULL);

	debug_print("RSSyl: starting to parse comments, path is '%s'\n", path);

	if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
		debug_print("g_dir_open on \"%s\" failed with error %d (%s)\n",
				path, error->code, error->message);
		g_error_free(error);
		g_free(path);
		return;
	}

	ritem->fetching_comments = TRUE;

	while( (d = g_dir_read_name(dp)) != NULL ) {
		if (claws_is_exiting()) {
			g_dir_close(dp);
			g_free(path);
			debug_print("RSSyl: bailing out, app is exiting\n");
			return;
		}

		if( (num = to_number(d)) > 0) {
			fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d);
			if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR))
				continue;

			debug_print("RSSyl: starting to parse '%s'\n", d);

			if( (fi = rssyl_parse_folder_item_file(fname)) != NULL ) {
				if( feed_item_get_comments_url(fi) && feed_item_get_id(fi) &&
						(ritem->fetch_comments_max_age == -1 ||
						 time(NULL) - feed_item_get_date_modified(fi) <= ritem->fetch_comments_max_age*86400)) {
					msg = g_strdup_printf(_("Updating comments for '%s'..."),
							feed_item_get_title(fi));
					debug_print("RSSyl: updating comments for '%s' (%s)\n",
							feed_item_get_title(fi), feed_item_get_comments_url(fi));
					STATUSBAR_PUSH(mainwin, msg);

					ctx = rssyl_prep_fetchctx_from_url(feed_item_get_comments_url(fi));
					g_return_if_fail(ctx != NULL);
					feed_set_ssl_verify_peer(ctx->feed, ritem->ssl_verify_peer);

					rssyl_fetch_feed(ctx, FALSE);
					
					if( ctx->success && feed_n_items(ctx->feed) > 0 ) {
						g_free(ctx->feed->title);
						ctx->feed->title = g_strdup(ritem->official_title);

						feed_foreach_item(ctx->feed, rssyl_update_reference_func,
								feed_item_get_id(fi));

						if( !rssyl_parse_feed(ritem, ctx->feed) ) {
							debug_print("RSSyl: Error processing comments feed\n");
							log_error(LOG_PROTOCOL, RSSYL_LOG_ERROR_PROC, ctx->feed->url);
						}
					}
				}

				STATUSBAR_POP(mainwin);

				feed_item_free(fi);
			}

			g_free(fname);
		}
	}

	g_dir_close(dp);
	g_free(path);

	ritem->fetching_comments = FALSE;

	debug_print("RSSyl: rssyl_update_comments() is done\n");
}
Exemple #28
0
Fichier : mh.c Projet : buzz/claws
static FolderItem *mh_create_folder(Folder *folder, FolderItem *parent,
				    const gchar *name)
{
	gchar *path, *real_name;
	gchar *fullpath;
	FolderItem *new_item;
	gchar *mh_sequences_filename;
	FILE *mh_sequences_file;

	cm_return_val_if_fail(folder != NULL, NULL);
	cm_return_val_if_fail(parent != NULL, NULL);
	cm_return_val_if_fail(name != NULL, NULL);

	path = folder_item_get_path(parent);
	if (!is_dir_exist(path)) 
		if (make_dir_hier(path) != 0)
			return NULL;

	real_name = mh_filename_from_utf8(name);
	fullpath = g_strconcat(path, G_DIR_SEPARATOR_S, real_name, NULL);
	g_free(real_name);
	g_free(path);

	if (to_number(name) > 0) {
		MsgInfo *info = folder_item_get_msginfo(parent, to_number(name));
		if (info != NULL) {
			gboolean ok = mh_renumber_msg(info);
			procmsg_msginfo_free(info);
			if (!ok) {
				g_free(fullpath);
				return NULL;
			}
		}
	}

	if (make_dir(fullpath) < 0) {
		g_free(fullpath);
		return NULL;
	}

	g_free(fullpath);

	if (parent->path)
		path = g_strconcat(parent->path, G_DIR_SEPARATOR_S, name,
				   NULL);
	else
		path = g_strdup(name);
	new_item = folder_item_new(folder, name, path);
	folder_item_append(parent, new_item);

	g_free(path);

	path = folder_item_get_path(new_item);
	mh_sequences_filename = g_strconcat(path, G_DIR_SEPARATOR_S,
					    ".mh_sequences", NULL);
	if ((mh_sequences_file = g_fopen(mh_sequences_filename, "a+b")) != NULL) {
		fclose(mh_sequences_file);
	}
	g_free(mh_sequences_filename);
	g_free(path);

	return new_item;
}
Exemple #29
0
int main(int argc,char **argv)
{
    char *name,*config_file,*reboot_arg,*identify,*ident_opt,*new_root;
    char *uninst_dev;
    int query,more,version,uninstall,validate,do_md_install,pass;
    BOOT_SECTOR dummy;
    IMAGE_DESCR dummy2;
    struct stat st;
    int fd, md_fd;
    md_array_info_t md_array_info;
    md_disk_info_t md_disk_info;
    char md_boot_name[MAX_TOKEN+1];
    char md_boot_map[MAX_TOKEN+1];
    DT_ENTRY md_disk;
    DT_ENTRY *disk;

    config_file = DFL_CONFIG;
    reboot_arg = identify = ident_opt = new_root = uninst_dev = NULL;
    pass = do_md_install = query = version = uninstall = validate = 0;
    name = *argv++;
    argc--;
    cfg_init(cf_options);
    while (argc && **argv == '-') {
	argc--;
	if (argv[0][2]) usage(name);
	switch ((*argv++)[1]) {
	    case 'b':
		if (!argc) usage(name);
		cfg_set(cf_options,"boot",*argv++,NULL);
		argc--;
		break;
	    case 'c':
		cfg_set(cf_options,"compact",NULL,NULL);
		compact = 1;
		break;
	    case 'd':
		if (!argc) usage(name);
		cfg_set(cf_options,"delay",*argv++,NULL);
		argc--;
		break;
	    case 'D':
		if (!argc) usage(name);
		cfg_set(cf_options,"default",*argv++,NULL);
		argc--;
		break;
	    case 'f':
		if (!argc) usage(name);
		cfg_set(cf_options,"disktab",*argv++,NULL);
		argc--;
		break;
	    case 'l':
		cfg_set(cf_options,"linear",NULL,NULL);
		linear = 1;
		break;
	    case 'm':
		if (!argc) usage(name);
		cfg_set(cf_options,"map",*argv++,NULL);
		argc--;
		break;
	    case 'i':
		if (!argc) usage(name);
		cfg_set(cf_options,"install",*argv++,NULL);
		argc--;
		break;
	    case 'I':
		if (!argc) usage(name);
		identify = *argv++;
		if (--argc) {
		    ident_opt = *argv++;
		    argc--;
		}
		break;
	    case 'X':
		printf("-DIMAGES=%d -DCODE_START_1=%d -DCODE_START_2=%d "
		  "-DDESCR_SIZE=%d -DDSC_OFF=%d -DDSC_OFF2=%d -DDFCMD_OFF=%d "
		  "-DMSG_OFF=%d -DFLAGS_OFF=%d\n",MAX_IMAGES,
		  sizeof(BOOT_PARAMS_1),sizeof(BOOT_PARAMS_2),
		  sizeof(IMAGE_DESCR),
		  (void *) &dummy.par_1.descr[0]-(void *) &dummy,
		  (void *) &dummy.par_1.descr[1]-(void *) &dummy,
		  (void *) &dummy.par_1.descr[2]-(void *) &dummy,
		  (void *) &dummy.par_1.msg_len-(void *) &dummy,
		  (void *) &dummy2.flags-(void *) &dummy2);
		exit(0);
	    case 'C':
		if (!argc) usage(name);
		config_file = *argv++;
		argc--;
		break;
	    case 'S':
		if (!argc) usage(name);
		cfg_set(cf_options,"force-backup",*argv++,NULL);
		argc--;
		break;
	    case 's':
		if (!argc) usage(name);
		cfg_set(cf_options,"backup",*argv++,NULL);
		argc--;
		break;
	    case 'P':
		if (!argc) usage(name);
		if (!strcmp(*argv,"fix"))
		    cfg_set(cf_options,"fix-table",NULL,NULL);
		else if (!strcmp(*argv,"ignore"))
			cfg_set(cf_options,"ignore-table",NULL,NULL);
		    else usage(name);
		argv++;
		argc--;
		break;
	    case 'q':
		query = 1;
		break;
	    case 'r':
		if (!argc) usage(name);
		new_root = *argv++;
		argc--;
		break;
	    case 'R':
		if (!argc) reboot_arg = "";
		else while (argc) {
			if (!reboot_arg)
			    *(reboot_arg = alloc(strlen(*argv)+1)) = 0;
			else strcat(reboot_arg = ralloc(reboot_arg,
			      strlen(reboot_arg)+strlen(*argv)+2)," ");
			strcat(reboot_arg,*argv++);
			argc--;
		    }
		break;
	    case 't':
		test = 1;
		break;
	    case 'u':
		validate = 1;
		/* fall through */
	    case 'U':
		uninstall = 1;
		if (argc) {
		    if (argc-- > 1) usage(name);
		    uninst_dev = *argv;
		}
		break;
	    case 'v':
		verbose++;
		break;
	    case 'V':
		version = 1;
		break;
	    case 'w':
		cfg_set(cf_options,"nowarn",NULL,NULL);
		nowarn = 1;
		break;
	    default:
		usage(name);
	}
    }
    if (!new_root) new_root = getenv("ROOT");
    if (new_root && *new_root) {
	if (chroot(new_root) < 0) die("chroot %s: %s",new_root,strerror(errno));
	if (chdir("/") < 0) die("chdir /: %s",strerror(errno));
    }
    if (atexit(temp_remove)) die("atexit() failed");
    if (verbose > 0 || version) {
	printf("LILO version 21%s",version ? "\n" : "");
	if (version) return 0;
	printf(", Copyright 1992-1998 Werner Almesberger\n\n");
    }
#if 0
    if (((install || test || boot_device || disktab_file || compact) && !argc)
      || (compact && linear && 0)) usage(name);
#endif
    if (!nowarn && compact && linear)
	fprintf(stderr,"Warning: COMPACT may conflict with LINEAR on some "
	  "systems\n");
    preload_types();
    fd = cfg_open(config_file);
    more = cfg_parse(cf_options);
    if (!nowarn) {
	if (fstat(fd,&st) < 0) {
	    fprintf(stderr,"fstat %s: %s\n",config_file,strerror(errno));
	    exit(1);
	}
	if (S_ISREG(st.st_mode)) {
	    if (st.st_uid)
		fprintf(stderr,"Warning: %s should be owned by root\n",
		  config_file);
	    else if (st.st_mode & (S_IWGRP | S_IWOTH))
		    fprintf(stderr,"Warning: %s should be writable only for "
		      "root\n",config_file);
		else if ((cfg_get_strg(cf_all,"password") || cfg_get_strg(
		      cf_options,"password")) && (st.st_mode & (S_IRGRP |
		      S_IROTH)))
			fprintf(stderr,"Warning: %s should be readable only "
			  "for root if using PASSWORD\n",config_file);
	}
    }
    preload_dev_cache();
    if (identify) identify_image(identify,ident_opt);
    if (strncmp("/dev/md",cfg_get_strg(cf_options,"boot"),7) == 0) {
	if ((md_fd=open(cfg_get_strg(cf_options,"boot"),O_NOACCESS)) < 0)
	    die("Unable to open %s",cfg_get_strg(cf_options,"boot"));
	if (fstat(md_fd,&st) < 0)
	    die("Unable to stat %s",cfg_get_strg(cf_options,"boot"));
	if (!S_ISBLK(st.st_mode))
	    die("%s is not a block device",cfg_get_strg(cf_options,"boot"));
	if (ioctl(md_fd,GET_ARRAY_INFO,&md_array_info) < 0)
	    die("Unable to get RAID info on %s",cfg_get_strg(cf_options,"boot"));
	if ((md_array_info.major_version == 0) && (md_array_info.minor_version < 90))
	    die("Raid versions < 0.90 are not supported");
	if (md_array_info.level != 1)
	    die("Only RAID1 devices are supported as boot devices");
	do_md_install = 1;
	strcpy(md_boot_name,cfg_get_strg(cf_options,"boot"));
	if (cfg_get_strg(cf_options,"map"))
	    strcpy(md_boot_map,cfg_get_strg(cf_options,"map"));
	else
	    strcpy(md_boot_map,MAP_FILE);
	md_disk.device = (MD_MAJOR << 8) | md_array_info.md_minor;
	md_disk.bios = 0x80;
	md_disk.next = disktab;
	disktab = &md_disk;
    }
    while( (pass == 0) || (do_md_install && (pass < md_array_info.nr_disks)) ) {
	if(do_md_install) {
	    GEOMETRY geo;
	    DEVICE dev;
	    int device,disk_fd;
	    char new_name[MAX_TOKEN+1];

	    if(pass > 0) {
		close(fd);
		cfg_init(cf_options);
		fd = cfg_open(config_file);
		more = cfg_parse(cf_options);
	    }
	    md_disk_info.number = pass;
	    if (ioctl(md_fd,GET_DISK_INFO,&md_disk_info) < 0)
		die("main: GET_DISK_INFO: %s", strerror(errno));
	    device = (md_disk_info.major << 8) | md_disk_info.minor;
	    disk_fd = dev_open(&dev,device,O_NOACCESS);
	    if (md_disk_info.state == MD_DISK_FAULTY) {
		printf("disk %s marked as faulty, skipping\n",dev.name);
		pass++;
		continue;
	    }
	    geo_query_dev(&geo,device,1);
	    disk = alloc_t(DT_ENTRY);
	    disk->bios = 0x80;
	    disk->device = device & 0xfff0;
	    disk->sectors = geo.sectors;
	    disk->heads = geo.heads;
	    disk->cylinders = geo.cylinders;
	    disk->start = geo.start;
	    disk->next = disktab;
	    disktab = disk;
	    if (cfg_get_strg(cf_options,"boot")) cfg_unset(cf_options,"boot");
	    if (cfg_get_strg(cf_options,"map")) cfg_unset(cf_options,"map");
	    strncpy(new_name,dev.name,8);
	    new_name[8] = '\0';
	    cfg_set(cf_options,"boot",new_name,NULL);
	    snprintf(new_name,MAX_TOKEN,"%s.%04x",md_boot_map,device);
	    cfg_set(cf_options,"map",new_name,NULL);
	    printf("boot = %s, map = %s\n", cfg_get_strg(cf_options,"boot"),
		cfg_get_strg(cf_options,"map"));
	    md_disk.sectors = geo.sectors;
	    md_disk.heads = geo.heads;
	    md_disk.cylinders = geo.cylinders;
	    md_disk.start = geo.start;
	}
	    
	pass++;
	if (uninstall)
	    bsect_uninstall(uninst_dev ? uninst_dev : cfg_get_strg(cf_options,
	      "boot"),cfg_get_strg(cf_options,"backup"),validate);
	compact = cfg_get_flag(cf_options,"compact");
	linear = cfg_get_flag(cf_options,"linear");
	nowarn = cfg_get_flag(cf_options,"nowarn");
	if (cfg_get_strg(cf_options,"verbose"))
	    verbose += to_number(cfg_get_strg(cf_options,"verbose"));
	if (reboot_arg) {
	    map_patch_first(cfg_get_strg(cf_options,"map") ? cfg_get_strg(
	      cf_options,"map") : MAP_FILE,reboot_arg);
	    exit(0);
	}
	if (argc) usage(name);
	geo_init(cfg_get_strg(cf_options,"disktab"));
	if (query)
	    show_images(!cfg_get_strg(cf_options,"map") ? MAP_FILE :
	      cfg_get_strg(cf_options,"map"));
	bsect_open(cfg_get_strg(cf_options,"boot"),cfg_get_strg(cf_options,"map") ?
	  cfg_get_strg(cf_options,"map") : MAP_FILE,cfg_get_strg(cf_options,
	  "install"),cfg_get_strg(cf_options,"delay") ? to_number(cfg_get_strg(
	  cf_options,"delay")) : 0,cfg_get_strg(cf_options,"timeout") ?
	  to_number(cfg_get_strg(cf_options,"timeout")) : -1);
	if (more) {
            cfg_init(cf_top);
            if (cfg_parse(cf_top)) cfg_error("Syntax error");
	}
	if (!bsect_number()) die("No images have been defined.");
	check_fallback();
	if (!test)
	    if (cfg_get_strg(cf_options,"force-backup"))
		bsect_update(cfg_get_strg(cf_options,"force-backup"),1);
	    else bsect_update(cfg_get_strg(cf_options,"backup"),0);
	else {
	    bsect_cancel();
	    fprintf(stderr,"The boot sector and the map file have *NOT* been "
	      "altered.\n");
	}
    }
    return 0;
}
Exemple #30
0
/* ECMA-262 3rd Edition    15.4.4.10 */
static HRESULT Array_slice(script_ctx_t *ctx, vdisp_t *vthis, WORD flags, unsigned argc, jsval_t *argv, jsval_t *r)
{
    jsdisp_t *arr, *jsthis;
    DOUBLE range;
    DWORD length, start, end, idx;
    HRESULT hres;

    TRACE("\n");

    hres = get_length(ctx, vthis, &jsthis, &length);
    if(FAILED(hres))
        return hres;

    if(argc) {
        hres = to_number(ctx, argv[0], &range);
        if(FAILED(hres))
            return hres;

        range = floor(range);
        if(-range>length || isnan(range)) start = 0;
        else if(range < 0) start = range+length;
        else if(range <= length) start = range;
        else start = length;
    }
    else start = 0;

    if(argc > 1) {
        hres = to_number(ctx, argv[1], &range);
        if(FAILED(hres))
            return hres;

        range = floor(range);
        if(-range>length) end = 0;
        else if(range < 0) end = range+length;
        else if(range <= length) end = range;
        else end = length;
    }
    else end = length;

    hres = create_array(ctx, (end>start)?end-start:0, &arr);
    if(FAILED(hres))
        return hres;

    for(idx=start; idx<end; idx++) {
        jsval_t v;

        hres = jsdisp_get_idx(jsthis, idx, &v);
        if(hres == DISP_E_UNKNOWNNAME)
            continue;

        if(SUCCEEDED(hres)) {
            hres = jsdisp_propput_idx(arr, idx-start, v);
            jsval_release(v);
        }

        if(FAILED(hres)) {
            jsdisp_release(arr);
            return hres;
        }
    }

    if(r)
        *r = jsval_obj(arr);
    else
        jsdisp_release(arr);

    return S_OK;
}