Ejemplo n.º 1
0
int find_exact(ENTRY *pe, IX_DESC *pix)
{
    int  ret;
    ENTRY e;
    copy_entry(&e, pe);
    ret = find_key(&e, pix);
    if ( ret && pci->duplicate)
    {
        do
        {
            ret = (e.recptr == pe->recptr);
            if(!ret)  
            {
                ret = next_key(&e, pci);
            }
            /*if (ret) ret = (strcmp(e.key, pe->key) == 0);*/
            if (ret) 
            {
                ret = (key_cmp(e.key, pe->key) == 0);
            }
            else
            {
                return 0;
            }

        } while(!ret);
    }

    copy_entry(pe, &e);

    return ret;
} 
Ejemplo n.º 2
0
static void ins_level(int l, ENTRY *e)
{
    int  i;
    if ( l < 0)
    {  
        for (i = 1; i < MAX_LEVELS; i++)
        {  
            CO(MAX_LEVELS - i) = CO(MAX_LEVELS - i - 1);
            CB(MAX_LEVELS - i) = CB(MAX_LEVELS - i - 1);
        }

        memcpy(spare_block, &(pci->root), sizeof(BLOCK));
        spare_block->brec = get_free();
        write_if(pci->ixfile, spare_block->brec,(char *) spare_block, sizeof(BLOCK));
        pci->root.p0 = spare_block->brec;
        copy_entry((ENTRY *) (pci->root.entries), e);
        pci->root.bend = ENT_SIZE(e);
        CO(0) = 0;
        pci->level = 0;
        (pci->dx.nl)++;
        update_root(&(pci->root));
    }
    else 
    {
        ins_block(block_ptr,e,CO(l));
    }
} 
Ejemplo n.º 3
0
int before_block_exec(CPUState *env, TranslationBlock *tb) {
    uint64_t count = rr_get_guest_instr_count();
    if (!snipping && count+tb->icount > start_count) {
        sassert((oldlog = fopen(rr_nondet_log->name, "r")), 8);
        sassert(fread(&orig_last_prog_point, sizeof(RR_prog_point), 1, oldlog) == 1, 9);
        printf("Original ending prog point: ");
        rr_spit_prog_point(orig_last_prog_point);

        actual_start_count = count;
        printf("Saving snapshot at instr count %lu...\n", count);

        // Force running state
        global_state_store_running();
        printf("writing snapshot:\t%s\n", snp_name);
        QIOChannelFile* ioc =
            qio_channel_file_new_path(snp_name, O_WRONLY | O_CREAT, 0660, NULL);
        QEMUFile* snp = qemu_fopen_channel_output(QIO_CHANNEL(ioc));
        qemu_savevm_state(snp, NULL);
        qemu_fclose(snp);

        printf("Beginning cut-and-paste process at prog point:\n");
        rr_spit_prog_point(rr_prog_point());
        printf("Writing entries to %s...\n", nondet_name);
        newlog = fopen(nondet_name, "w");
        sassert(newlog, 10);
        // We'll fix this up later.
        RR_prog_point prog_point = {0};
        fwrite(&prog_point.guest_instr_count,
                sizeof(prog_point.guest_instr_count), 1, newlog);

        fseek(oldlog, ftell(rr_nondet_log->fp), SEEK_SET);

        // If there are items in the queue, then start copying the log
        // from there
        RR_log_entry *item = rr_get_queue_head();
        if (item != NULL) fseek(oldlog, item->header.file_pos, SEEK_SET);

        while (prog_point.guest_instr_count < end_count && !feof(oldlog)) {
            prog_point = copy_entry();
        }
        if (!feof(oldlog)) { // prog_point is the first one AFTER what we want
            printf("Reached end of old nondet log.\n");
        } else {
            printf("Past desired ending point for log.\n");
        }

        snipping = true;
        printf("Continuing with replay.\n");
    }

    if (snipping && !done && count > end_count) {
        end_snip();

        rr_end_replay_requested = 1;
    }

    return 0;
}
Ejemplo n.º 4
0
static void ins_block(BLOCK *pb, ENTRY *pe, int off)
{
    int size;
    update_root(pb);
    size = ENT_SIZE(pe);
    moveup(pb,off,size);
    copy_entry(ENT_ADR(pb,off),pe);
    pb->bend += size;
} 
Ejemplo n.º 5
0
config_t copy_sequences(const config_t conf, config_t com){
    
    int i = CONFIG_PROGRAM;
    for(; i < N_CONFIG_VARIABLES; i++){
        com = update_entry(i,
            copy_entry(get_entry(i, conf)),
            com);
    }
    return com;
}
Ejemplo n.º 6
0
int find_key(ENTRY *pe, IX_DESC *pix)
{
    int ret;
    ret = find_ix(pe, pix, 1);
    if (ret)
    {
        copy_entry(pe, ENT_ADR(block_ptr, CO(pci->level)));
    }

    return ret;
} 
Ejemplo n.º 7
0
config_t copy_config(config_t other){
    if(other == NULL){
        
        return NULL;
    }
    config_t r = new_config(other->size);
    int i = 0;
    for(;i< other->size; i++){
        r->map[i] = copy_entry(other->map[i]);
    }
    return r;
}
Ejemplo n.º 8
0
static int
new_entry(lua_State *L, layout_entry_t *entry)
{
	layout_entry_t *nentry =
		(layout_entry_t *) lua_newuserdata(L, sizeof(layout_entry_t));

	luaL_getmetatable(L, LAYOUT_ENTRY_USERDATA);
	lua_setmetatable(L, -2);

	copy_entry(nentry, entry);
	return 1;
}
Ejemplo n.º 9
0
int before_block_exec(CPUState *env, TranslationBlock *tb) {
    uint64_t count = rr_prog_point.guest_instr_count;
    if (!snipping && count+tb->num_guest_insns > start_count) {
        sassert((oldlog = fopen(rr_nondet_log->name, "r")));
        sassert(fread(&orig_last_prog_point, sizeof(RR_prog_point), 1, oldlog) == 1);
        printf("Original ending prog point: ");
        rr_spit_prog_point(orig_last_prog_point);

        actual_start_count = count;
        printf("Saving snapshot at instr count %lu...\n", count);
        do_savevm_rr(get_monitor(), snp_name);

        printf("Beginning cut-and-paste process at prog point:\n");
        rr_spit_prog_point(rr_prog_point);
        printf("Writing entries to %s...\n", nondet_name);
        newlog = fopen(nondet_name, "w");
        sassert(newlog);
        // We'll fix this up later.
        RR_prog_point prog_point = {0, 0, 0};
        fwrite(&prog_point, sizeof(RR_prog_point), 1, newlog);

        fseek(oldlog, ftell(rr_nondet_log->fp), SEEK_SET);

        RR_log_entry *item = rr_get_queue_head();
        while (item != NULL && item->header.prog_point.guest_instr_count < end_count) {
            write_entry(item);
            item = item->next;
        }
        while (prog_point.guest_instr_count < end_count && !feof(oldlog)) {
            prog_point = copy_entry();
        } 
        if (!feof(oldlog)) { // prog_point is the first one AFTER what we want
            printf("Reached end of old nondet log.\n");
        } else {
            printf("Past desired ending point for log.\n");
        }

        snipping = true;
        printf("Continuing with replay.\n");
    }

    if (snipping && !done && count > end_count) {
        end_snip();

        init_timer_alarm();
        rr_do_end_replay(0);
    }

    return 0;
}
Ejemplo n.º 10
0
bool hardened_shadow_copy_dir_contents(const char *source,
                                       const char *destination,
                                       uid_t uid,
                                       gid_t gid) {
  if (uid == (uid_t)-1 || gid == (gid_t)-1)
    return false;

  DIR *dir = opendir(source);
  if (!dir)
    return false;

  char *source_path = NULL;
  char *destination_path = NULL;
  bool result = true;

  struct dirent *dirent;
  while ((dirent = readdir(dir))) {
    if (strcmp(dirent->d_name, ".") == 0 ||
        strcmp(dirent->d_name, "..") == 0) {
      continue;
    }

    if (asprintf(&source_path, "%s/%s", source, dirent->d_name) < 0) {
      result = false;
      goto out;
    }

    if (asprintf(&destination_path, "%s/%s", destination, dirent->d_name) < 0) {
      result = false;
      goto out;
    }

    if (!copy_entry(source_path, destination_path, uid, gid)) {
      result = false;
      goto out;
    }

    free(source_path);
    source_path = NULL;

    free(destination_path);
    destination_path = NULL;
  }

out:
  closedir(dir);
  free(source_path);
  free(destination_path);
  return result;
}
Ejemplo n.º 11
0
int locate_key(ENTRY *pe, IX_DESC *pix)
{
    int ret;
    //ENTRY e;
    ret = find_ix(pe, pix, 1);
    if (ret) 
    {
        copy_entry(pe, ENT_ADR(block_ptr, CO(pci->level)));
    }
    else if (next_key(pe,pix) == EOIX) 
    {
        ret = EOIX;
    }

    return ret;
} 
Ejemplo n.º 12
0
/*  insert new entries into tree  */
static bool split(int l, ENTRY *pe, ENTRY *e)
{
    int  half, ins_pos, size;
    ins_pos = CO(pci->level);
    half = scan_blk(block_ptr->bend / 2 + sizeof(RECPOS));
    if (half == ins_pos)
    {
        *e = *pe;
    }
    else
    {
        copy_entry(e, ENT_ADR(block_ptr, half));
        size = ENT_SIZE(e);
        movedown(block_ptr, half, size);
        block_ptr->bend -= size;
        update_root(block_ptr);
    }

    spare_block = &BUFBLOCK(new_cache());
    memcpy(spare_block->entries,
            ENT_ADR(block_ptr,half),
            block_ptr->bend - half);
    spare_block->brec = get_free();
    spare_block->bend = block_ptr->bend - half;
    spare_block->p0 = e->idxptr;
    block_ptr->bend = half;
    e->idxptr = spare_block->brec;
    if (ins_pos < half)
    {
        ins_block(block_ptr,pe,ins_pos);
    }

    else if (ins_pos > half)
    {
        ins_pos -= ENT_SIZE(e);
        ins_block(spare_block,pe,ins_pos - half);
        CB(l) = e->idxptr;
        CO(l) = CO(l) - half;
    }
    write_if(pci->ixfile, spare_block->brec,(char *) spare_block, sizeof(BLOCK));

    return TRUE;
} 
Ejemplo n.º 13
0
int prev_key(ENTRY *pe, IX_DESC *pix)
{
    RECPOS  address;
    pci = pix;
    retrieve_block(pci->level, CB(pci->level));
    prev_entry(CO(pci->level));
    if (CO(pci->level) == -1)
    {
        address = block_ptr->p0;
    }
    else
    {
        address = ENT_ADR(block_ptr, CO(pci->level))->idxptr;
    }

    if (address != NULLREC)
    { 
        do
        {
            retrieve_block(++(pci->level), address);
            address = ENT_ADR(block_ptr, last_entry())->idxptr;
        } while (address != NULLREC);
    }
    if (CO(pci->level) == -1)
    { 
        do
        {
            if(pci->level == 0)
            {
                first_key(pci);
                return (EOIX);
            }
            --(pci->level);

        } while (CO(pci->level) == -1);

        retrieve_block(pci->level, CB(pci->level));
    }
    copy_entry(pe, ENT_ADR(block_ptr, CO(pci->level)));

    return ( IX_OK );
} 
Ejemplo n.º 14
0
/*  get next, previous entries  */
int next_key(ENTRY *pe, IX_DESC *pix)
{
    RECPOS  address;
    if(block_ptr->bend == 0)
    {
        return IX_FAIL;
    }

    pci = pix;
    retrieve_block(pci->level, CB(pci->level));
    address = ENT_ADR(block_ptr, CO(pci->level))->idxptr;
    while (address != NULLREC)
    {
        retrieve_block(++(pci->level), address);
        CO(pci->level) = -1;
        address = block_ptr->p0;
    }
    next_entry(CO(pci->level));
    if (CO(pci->level) == block_ptr->bend)
    {
        do
        { 
            if(pci->level == 0)
            {
                last_key(pci);
                return (EOIX);
            }

            --(pci->level);
            retrieve_block(pci->level, CB(pci->level));
            next_entry(CO(pci->level));

        } while (CO(pci->level) == block_ptr->bend);
    }
    copy_entry(pe, ENT_ADR(block_ptr, CO(pci->level)));

    return ( IX_OK );
} 
Ejemplo n.º 15
0
static void
on_get_all_done_for_info (GObject *object,
                          GAsyncResult *res,
                          gpointer user_data)
{
  GetServiceInfoData *data = user_data;
  GError *error = NULL;
  gs_unref_variant GVariant *reply = g_dbus_connection_call_finish (G_DBUS_CONNECTION (object), res, &error);

  if (error)
    {
      end_invocation_take_gerror (data->invocation, error);
      g_free (data);
      return;
    }

  gs_unref_variant GVariant *props;
  g_variant_get (reply, "(@a{sv})", &props);

  GVariantBuilder bob;
  g_variant_builder_init (&bob, G_VARIANT_TYPE("a{sv}"));

  copy_entry (&bob, props, "Id");
  copy_entry (&bob, props, "Description");
  copy_entry (&bob, props, "LoadState");
  copy_entry (&bob, props, "ActiveState");
  copy_entry (&bob, props, "SubState");
  copy_entry (&bob, props, "UnitFileState");
  copy_entry (&bob, props, "ExecMainStartTimestamp");
  copy_entry (&bob, props, "ExecMainExitTimestamp");
  copy_entry (&bob, props, "ActiveEnterTimestamp");
  copy_entry (&bob, props, "ActiveExitTimestamp");
  copy_entry (&bob, props, "InactiveEnterTimestamp");
  copy_entry (&bob, props, "InactiveExitTimestamp");
  copy_entry (&bob, props, "ConditionTimestamp");
  copy_entry (&bob, props, "SourcePath");
  copy_entry (&bob, props, "FragmentPath");
  copy_entry (&bob, props, "LoadError");
  copy_entry (&bob, props, "ConditionResult");
  copy_entry (&bob, props, "StatusText");
  copy_entry (&bob, props, "DefaultControlGroup");

  const gchar *id = NULL, *cgroup = NULL;
  uint32_t main_pid = 0, exec_main_pid = 0, control_pid = 0;

  g_variant_lookup (props, "Id", "&s", &id);
  g_variant_lookup (props, "DefaultControlGroup", "&s", &cgroup);
  g_variant_lookup (props, "ExecMainPid", "u", &exec_main_pid);
  g_variant_lookup (props, "MainPid", "u", &main_pid);
  g_variant_lookup (props, "ControlPid", "u", &control_pid);

  if (cgroup)
    {
      pid_t extra_pids[3];
      int n_extra_pids = 0;
      if (main_pid > 0)
        extra_pids[n_extra_pids++] = main_pid;
      if (exec_main_pid > 0)
        extra_pids[n_extra_pids++] = exec_main_pid;
      if (control_pid > 0)
        extra_pids[n_extra_pids++] = control_pid;

      GVariant *c = collect_cgroup_and_extra_by_spec (cgroup, FALSE, TRUE, extra_pids, n_extra_pids);
      if (c)
        g_variant_builder_add (&bob, "{sv}", "Processes", c);
    }

  cockpit_services_complete_get_service_info (COCKPIT_SERVICES (data->services), data->invocation,
                                              g_variant_builder_end (&bob));
  g_free (data);
}
Ejemplo n.º 16
0
/*
 * copy_tree - copy files in a directory tree
 *
 *	copy_tree() walks a directory tree and copies ordinary files
 *	as it goes.
 *
 *	When reset_selinux is enabled, extended attributes (and thus
 *	SELinux attributes) are not copied.
 *
 *	old_uid and new_uid are used to set the ownership of the copied
 *	files. Unless old_uid is set to -1, only the files owned by
 *	old_uid have their ownership changed to new_uid. In addition, if
 *	new_uid is set to -1, no ownership will be changed.
 *
 *	The same logic applies for the group-ownership and
 *	old_gid/new_gid.
 */
int copy_tree (const char *src_root, const char *dst_root,
               bool copy_root, bool reset_selinux,
               uid_t old_uid, uid_t new_uid,
               gid_t old_gid, gid_t new_gid)
{
    int err = 0;
    bool set_orig = false;
    struct DIRECT *ent;
    DIR *dir;

    if (copy_root) {
        struct stat sb;
        if (access (dst_root, F_OK) == 0) {
            return -1;
        }

        if (LSTAT (src_root, &sb) == -1) {
            return -1;
        }

        if (!S_ISDIR (sb.st_mode)) {
            fprintf (stderr,
                     "%s: %s is not a directory",
                     Prog, src_root);
            return -1;
        }

        return copy_entry (src_root, dst_root, reset_selinux,
                           old_uid, new_uid, old_gid, new_gid);
    }

    /*
     * Make certain both directories exist.  This routine is called
     * after the home directory is created, or recursively after the
     * target is created.  It assumes the target directory exists.
     */

    if (   (access (src_root, F_OK) != 0)
            || (access (dst_root, F_OK) != 0)) {
        return -1;
    }

    /*
     * Open the source directory and read each entry.  Every file
     * entry in the directory is copied with the UID and GID set
     * to the provided values.  As an added security feature only
     * regular files (and directories ...) are copied, and no file
     * is made set-ID.
     */
    dir = opendir (src_root);
    if (NULL == dir) {
        return -1;
    }

    if (src_orig == NULL) {
        src_orig = src_root;
        dst_orig = dst_root;
        set_orig = true;
    }
    while ((0 == err) && (ent = readdir (dir)) != NULL) {
        /*
         * Skip the "." and ".." entries
         */
        if ((strcmp (ent->d_name, ".") != 0) &&
                (strcmp (ent->d_name, "..") != 0)) {
            char *src_name;
            char *dst_name;
            size_t src_len = strlen (ent->d_name) + 2;
            size_t dst_len = strlen (ent->d_name) + 2;
            src_len += strlen (src_root);
            dst_len += strlen (dst_root);

            src_name = (char *) malloc (src_len);
            dst_name = (char *) malloc (dst_len);

            if ((NULL == src_name) || (NULL == dst_name)) {
                err = -1;
            } else {
                /*
                 * Build the filename for both the source and
                 * the destination files.
                 */
                (void) snprintf (src_name, src_len, "%s/%s",
                                 src_root, ent->d_name);
                (void) snprintf (dst_name, dst_len, "%s/%s",
                                 dst_root, ent->d_name);

                err = copy_entry (src_name, dst_name,
                                  reset_selinux,
                                  old_uid, new_uid,
                                  old_gid, new_gid);
            }
            if (NULL != src_name) {
                free (src_name);
            }
            if (NULL != dst_name) {
                free (dst_name);
            }
        }
    }
    (void) closedir (dir);

    if (set_orig) {
        src_orig = NULL;
        dst_orig = NULL;
        /* FIXME: clean links
         * Since there can be hardlinks elsewhere on the device,
         * we cannot check that all the hardlinks were found:
        assert (NULL == links);
         */
    }

#ifdef WITH_SELINUX
    /* Reset SELinux to create files with default contexts.
     * Note that the context is only reset on exit of copy_tree (it is
     * assumed that the program would quit without needing a restored
     * context if copy_tree failed previously), and that copy_tree can
     * be called recursively (hence the context is set on the
     * sub-functions of copy_entry).
     */
    if (reset_selinux_file_context () != 0) {
        err = -1;
    }
#endif				/* WITH_SELINUX */

    return err;
}
Ejemplo n.º 17
0
/*
 * copy_tree - copy files in a directory tree
 *
 *	copy_tree() walks a directory tree and copies ordinary files
 *	as it goes.
 */
int copy_tree (const char *src_root, const char *dst_root,
               long int uid, long int gid)
{
	int err = 0;
	bool set_orig = false;
	struct DIRECT *ent;
	DIR *dir;

	/*
	 * Make certain both directories exist.  This routine is called
	 * after the home directory is created, or recursively after the
	 * target is created.  It assumes the target directory exists.
	 */

	if (   (access (src_root, F_OK) != 0)
	    || (access (dst_root, F_OK) != 0)) {
		return -1;
	}

	/*
	 * Open the source directory and read each entry.  Every file
	 * entry in the directory is copied with the UID and GID set
	 * to the provided values.  As an added security feature only
	 * regular files (and directories ...) are copied, and no file
	 * is made set-ID.
	 */
	dir = opendir (src_root);
	if (NULL == dir) {
		return -1;
	}

	if (src_orig == NULL) {
		src_orig = src_root;
		dst_orig = dst_root;
		set_orig = true;
	}
	while ((0 == err) && (ent = readdir (dir)) != NULL) {
		/*
		 * Skip the "." and ".." entries
		 */
		if ((strcmp (ent->d_name, ".") != 0) &&
		    (strcmp (ent->d_name, "..") != 0)) {
			char *src_name;
			char *dst_name;
			size_t src_len = strlen (ent->d_name) + 2;
			size_t dst_len = strlen (ent->d_name) + 2;
			src_len += strlen (src_root);
			dst_len += strlen (dst_root);

			src_name = (char *) malloc (src_len);
			dst_name = (char *) malloc (dst_len);

			if ((NULL == src_name) || (NULL == dst_name)) {
				err = -1;
			} else {
				/*
				 * Build the filename for both the source and
				 * the destination files.
				 */
				snprintf (src_name, src_len, "%s/%s",
				          src_root, ent->d_name);
				snprintf (dst_name, dst_len, "%s/%s",
				          dst_root, ent->d_name);

				err = copy_entry (src_name, dst_name, uid, gid);
			}
			if (NULL != src_name) {
				free (src_name);
			}
			if (NULL != dst_name) {
				free (dst_name);
			}
		}
	}
	(void) closedir (dir);

	if (set_orig) {
		src_orig = NULL;
		dst_orig = NULL;
	}

#ifdef WITH_SELINUX
	/* Reset SELinux to create files with default contexts */
	setfscreatecon (NULL);
#endif

	/* FIXME: with the call to remove_link, we could also check that
	 *        no links remain in links.
	 * assert (NULL == links); */

	return err;
}
Ejemplo n.º 18
0
int font::load(int *not_found, int head_only)
{
  char *path;
  FILE *fp;
  if ((fp = open_file(name, &path)) == NULL) {
    if (not_found)
      *not_found = 1;
    else
      error("can't find font file `%1'", name);
    return 0;
  }
  text_file t(fp, path);
  t.skip_comments = 1;
  t.silent = head_only;
  char *p;
  for (;;) {
    if (!t.next()) {
      t.error("missing charset command");
      return 0;
    }
    p = strtok(t.buf, WS);
    if (strcmp(p, "name") == 0) {
    }
    else if (strcmp(p, "spacewidth") == 0) {
      p = strtok(0, WS);
      int n;
      if (p == 0 || sscanf(p, "%d", &n) != 1 || n <= 0) {
	t.error("bad argument for spacewidth command");
	return 0;
      }
      space_width = n;
    }
    else if (strcmp(p, "slant") == 0) {
      p = strtok(0, WS);
      double n;
      if (p == 0 || sscanf(p, "%lf", &n) != 1 || n >= 90.0 || n <= -90.0) {
	t.error("bad argument for slant command", p);
	return 0;
      }
      slant = n;
    }
    else if (strcmp(p, "ligatures") == 0) {
      for (;;) {
	p = strtok(0, WS);
	if (p == 0 || strcmp(p, "0") == 0)
	  break;
	if (strcmp(p, "ff") == 0)
	  ligatures |= LIG_ff;
	else if (strcmp(p, "fi") == 0)
	  ligatures |= LIG_fi;
	else if (strcmp(p, "fl") == 0)
	  ligatures |= LIG_fl;
	else if (strcmp(p, "ffi") == 0)
	  ligatures |= LIG_ffi;
	else if (strcmp(p, "ffl") == 0)
	  ligatures |= LIG_ffl;
	else {
	  t.error("unrecognised ligature `%1'", p);
	  return 0;
	}
      }
    }
    else if (strcmp(p, "internalname") == 0) {
      p = strtok(0, WS);
      if (!p) {
	t.error("`internalname command requires argument");
	return 0;
      }
      internalname = new char[strlen(p) + 1];
      strcpy(internalname, p);
    }
    else if (strcmp(p, "special") == 0) {
      special = 1;
    }
    else if (strcmp(p, "kernpairs") != 0 && strcmp(p, "charset") != 0) {
      char *command = p;
      p = strtok(0, "\n");
      handle_unknown_font_command(command, trim_arg(p), t.path, t.lineno);
    }
    else
      break;
  }
  if (head_only)
    return 1;
  char *command = p;
  int had_charset = 0;
  t.skip_comments = 0;
  while (command) {
    if (strcmp(command, "kernpairs") == 0) {
      for (;;) {
	if (!t.next()) {
	  command = 0;
	  break;
	}
	char *c1 = strtok(t.buf, WS);
	if (c1 == 0)
	  continue;
	char *c2 = strtok(0, WS);
	if (c2 == 0) {
	  command = c1;
	  break;
	}
	p = strtok(0, WS);
	if (p == 0) {
	  t.error("missing kern amount");
	  return 0;
	}
	int n;
	if (sscanf(p, "%d", &n) != 1) {
	  t.error("bad kern amount `%1'", p);
	  return 0;
	}
	int i1 = name_to_index(c1);
	if (i1 < 0) {
	  t.error("invalid character `%1'", c1);
	  return 0;
	}
	int i2 = name_to_index(c2);
	if (i2 < 0) {
	  t.error("invalid character `%1'", c2);
	  return 0;
	}
	add_kern(i1, i2, n);
      }
    }
    else if (strcmp(command, "charset") == 0) {
      had_charset = 1;
      int last_index = -1;
      for (;;) {
	if (!t.next()) {
	  command = 0;
	  break;
	}
	char *nm = strtok(t.buf, WS);
	if (nm == 0)
	  continue;			// I dont think this should happen
	p = strtok(0, WS);
	if (p == 0) {
	  command = nm;
	  break;
	}
	if (p[0] == '"') {
	  if (last_index == -1) {
	    t.error("first charset entry is duplicate");
	    return 0;
	  }
	  if (strcmp(nm, "---") == 0) {
	    t.error("unnamed character cannot be duplicate");
	    return 0;
	  }
	  int idx = name_to_index(nm);
	  if (idx < 0) {
	    t.error("invalid character `%1'", nm);
	    return 0;
	  }
	  copy_entry(idx, last_index);
	}
	else {
	  font_char_metric metric;
	  metric.height = 0;
	  metric.depth = 0;
	  metric.pre_math_space = 0;
	  metric.italic_correction = 0;
	  metric.subscript_correction = 0;
	  int nparms = sscanf(p, "%d,%d,%d,%d,%d,%d",
			      &metric.width, &metric.height, &metric.depth,
			      &metric.italic_correction,
			      &metric.pre_math_space,
			      &metric.subscript_correction);
	  if (nparms < 1) {
	    t.error("bad width for `%1'", nm);
	    return 0;
	  }
	  p = strtok(0, WS);
	  if (p == 0) {
	    t.error("missing character type for `%1'", nm);
	    return 0;
	  }
	  int type;
	  if (sscanf(p, "%d", &type) != 1) {
	    t.error("bad character type for `%1'", nm);
	    return 0;
	  }
	  if (type < 0 || type > 255) {
	    t.error("character type `%1' out of range", type);
	    return 0;
	  }
	  metric.type = type;
	  p = strtok(0, WS);
	  if (p == 0) {
	    t.error("missing code for `%1'", nm);
	    return 0;
	  }
	  char *ptr;
	  metric.code = (int)strtol(p, &ptr, 0);
	  if (metric.code == 0 && ptr == p) {
	    t.error("bad code `%1' for character `%2'", p, nm);
	    return 0;
	  }
	  p = strtok(0, WS);
	  if ((p == NULL) || (strcmp(p, "--") == 0)) {
	    metric.special_device_coding = NULL;
	  }
	  else {
	    char *nam = new char[strlen(p) + 1];
	    strcpy(nam, p);
	    metric.special_device_coding = nam;
	  }
	  if (strcmp(nm, "---") == 0) {
	    last_index = number_to_index(metric.code);
	    add_entry(last_index, metric);
	  }
	  else {
	    last_index = name_to_index(nm);
	    if (last_index < 0) {
	      t.error("invalid character `%1'", nm);
	      return 0;
	    }
	    add_entry(last_index, metric);
	    copy_entry(number_to_index(metric.code), last_index);
	  }
	}
      }
      if (last_index == -1) {
	t.error("I didn't seem to find any characters");
	return 0;
      }
    }
    else {
      t.error("unrecognised command `%1' after `kernpairs' or `charset' command", command);
      return 0;
    }
  }
  if (!had_charset) {
    t.error("missing charset command");
    return 0;
  }
  if (space_width == 0)
    space_width = scale_round(unitwidth, res, 72*3*sizescale);
  compact();
  return 1;
}
Ejemplo n.º 19
0
int combineblk(RECPOS ads, int size)
{
    ENTRY  e;
    RECPOS address;
    int    esize, off, ret, saveoff, ibuff;
    ret = 0;
    saveoff = CO(--(pci->level));
    retrieve_block(pci->level, CB(pci->level));
    if ((off = next_entry( saveoff )) < block_ptr->bend)
        /* combine with page on right */
    {
        if ((ENT_SIZE(ENT_ADR(block_ptr, off)) + size) < (uint32_t)split_size)
        {
            copy_entry(&e, ENT_ADR(block_ptr, off));
            address = ENT_ADR(block_ptr, CO(pci->level))->idxptr;
            retrieve_block(++pci->level, address);
            ibuff = cache_ptr;
            spare_block = block_ptr;
            retrieve_block(pci->level, ads);
            esize = ENT_SIZE(&e);
            if(((block_ptr->bend + spare_block->bend + esize) >= split_size)&& (spare_block->bend <= block_ptr->bend + esize)) 
            {
                return  ret;
            }

            e.idxptr = spare_block->p0;
            ins_block(block_ptr, &e, block_ptr->bend);
            update_block();
            if ((block_ptr->bend + spare_block->bend) < split_size)
                /* combine the blocks */
            {
                memcpy(ENT_ADR(block_ptr, block_ptr->bend),ENT_ADR(spare_block, 0),spare_block->bend);
                block_ptr->bend += spare_block->bend;
                write_free(spare_block->brec, spare_block);
                BUFDIRTY(ibuff) = 0;
                BUFHANDLE(ibuff) = 0;
                --pci->level;
                ret = 1;
            }
            else
                /* move an entry up to replace the one moved */
            {
                copy_entry(&e, ENT_ADR(spare_block, 0));
                esize = ENT_SIZE(&e);
                movedown(spare_block, 0, esize);
                spare_block->bend -= esize;
                spare_block->p0 = e.idxptr;
                BUFDIRTY(ibuff) = 1;
                --(pci->level);
                replace_entry(&e);
            }
        }
    }
    else
        /* move from page on left */
    {
        if ( (ENT_SIZE(ENT_ADR(block_ptr, CO(pci->level))) + size) < (uint32_t)split_size)
        {
            copy_entry(&e, ENT_ADR(block_ptr, saveoff));
            off = prev_entry(saveoff);

            if (CO(pci->level) == -1) 
                address = block_ptr->p0;
            else 
                address = ENT_ADR(block_ptr, CO(pci->level))->idxptr;

            retrieve_block(++pci->level, address);
            off = last_entry();
            ibuff = cache_ptr;
            spare_block = block_ptr;
            retrieve_block(pci->level, ads);
            esize = ENT_SIZE(&e);

            if(((block_ptr->bend + spare_block->bend + esize) >= split_size)&& (spare_block->bend <= block_ptr->bend + esize))
            {
                return ret;
            }

            BUFDIRTY(ibuff) = 1;
            CO(pci->level) = 0;
            e.idxptr = block_ptr->p0;
            ins_block(block_ptr, &e, 0);
            if ((block_ptr->bend + spare_block->bend) < split_size)
                /* combine the blocks */
            {
                memcpy(ENT_ADR(spare_block, spare_block->bend),ENT_ADR(block_ptr, 0),block_ptr->bend);
                spare_block->bend += block_ptr->bend;
                write_free(block_ptr->brec, block_ptr);
                BUFDIRTY(cache_ptr) = 0;
                BUFHANDLE(cache_ptr) = 0;
                CO(--(pci->level)) = saveoff;
                ret = 1;
            }
            else
                /* move an entry up to replace the one moved */
            {
                block_ptr->p0 = ENT_ADR(spare_block,off)->idxptr;
                copy_entry(&e, ENT_ADR(spare_block, off));
                spare_block->bend = off;
                update_block();
                CO(--(pci->level)) = saveoff;
                replace_entry(&e);
            }
        }
    }
    root_dirty = 1;

    return ret;
} 
Ejemplo n.º 20
0
/* BPLUS delete key functions */
int delete_key(ENTRY *pe, IX_DESC *pix)
{
    ENTRY   e;
    RECPOS  ads;
    int     h, leveli, levelf;
    if (!find_exact(pe, pix))  
    {
        return (IX_NOTEXISTED);
    }
    h = 1;
    if ((ads = pe->idxptr) != NULLREC)
    {
        leveli = pci->level;
        do
        {
            retrieve_block(++(pci->level), ads);
            CO(pci->level) = -1;
        }

        while ((ads = block_ptr->p0) != NULLREC);
        CO(pci->level) = 0;
        copy_entry(&e, ENT_ADR(block_ptr, CO(pci->level)));
        levelf = pci->level;
        pci->level = leveli;
        replace_entry(&e);
        pci->level = levelf;
        /*update_root(&pci->root);*/
    }
    while ( h )
    {
        retrieve_block(pci->level, CB(pci->level));
        del_block(block_ptr, CO(pci->level));
        update_block();
        if ( (pci->level == 0) && (block_ptr->bend == 0))
            /* tree was reduced in height */
        {
            if (pci->root.p0 != NULLREC)
            {
                retrieve_block(++pci->level, pci->root.p0);
                memcpy(&(pci->root), block_ptr, sizeof(BLOCK));
                (pci->dx.nl)--;
                write_free(block_ptr->brec, block_ptr);
                BUFDIRTY(cache_ptr) = 0;
                BUFHANDLE(cache_ptr) = 0;
                update_root(&pci->root);
            }

            break;
        }
        h = (block_ptr->bend < comb_size) && (pci->level > 0);
        if ( h )
        {
            h = combineblk(CB(pci->level), block_ptr->bend);
        }
    }

    /*return flush_index(pix);*/
    if(root_dirty == 1)
    {
        flush_index(pix);
        root_dirty = 0;
    }

    return(IX_OK);
} 
Ejemplo n.º 21
0
static void
do_copy (GConfDefaults          *mechanism,
	 gboolean                mandatory,
	 const char            **includes,
	 const char            **excludes,
	 DBusGMethodInvocation  *context,
	 GConfChangeSet        **changeset_out)
{
        char *address = NULL;
	GConfClient *source = NULL;
	GConfClient *dest = NULL;
	GConfChangeSet *changes = NULL;
	GConfEngine *engine;
	GError *error;
	GError *error2;
	const char *action;
	const char *annotation_key;
	const char *default_action;
	const char *dest_address;
	int i;

	if (changeset_out)
		*changeset_out = NULL;

        stop_killtimer ();

	/* check privileges for each include */
	if (mandatory) {
		annotation_key = "org.gnome.gconf.defaults.set-mandatory.prefix"; 
		default_action = "org.gnome.gconf.defaults.set-mandatory";
		dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.mandatory";
	}
	else {
		annotation_key = "org.gnome.gconf.defaults.set-system.prefix";
		default_action = "org.gnome.gconf.defaults.set-system";
		dest_address = "xml:merged:" SYSGCONFDIR "/gconf.xml.system";
	}

	for (i = 0; includes[i]; i++) {
		action = polkit_action_for_gconf_path (mechanism, annotation_key, includes[i]);
		if (action == NULL)
			action = default_action;

		if (!check_polkit_for_action (mechanism, context, action))
			goto out;
	}

	error = NULL;
	engine = gconf_engine_get_local (dest_address, &error);
	if (error)
		goto cleanup;

	dest = gconf_client_get_for_engine (engine);
	gconf_engine_unref (engine);

	/* find the address to from the caller id */
	address = gconf_address_for_caller (mechanism, context, &error);
	if (error)
		goto cleanup;

	engine = gconf_engine_get_local (address, &error);
	if (error)
		goto cleanup;

	source = gconf_client_get_for_engine (engine);
	gconf_engine_unref (engine);

	changes = gconf_change_set_new ();

 	/* recursively copy each include, leaving out the excludes */
	for (i = 0; includes[i]; i++) {
		if (gconf_client_dir_exists (source, includes[i], NULL))
			copy_tree (source, includes[i], changes, excludes);
		else
			copy_entry (source, includes[i], changes, excludes);
	}

	gconf_client_commit_change_set (dest, changes, FALSE, &error);
	gconf_client_suggest_sync (dest, NULL);

	if (changeset_out) {
		*changeset_out = changes;
		changes = NULL;
	}

cleanup:
	g_free (address);
	if (changes)
		gconf_change_set_unref (changes);
	if (dest)
		g_object_unref (dest);
	if (source)
		g_object_unref (source);

	if (error) {
		g_print ("failed to set GConf values:  %s\n", error->message);
		error2 = g_error_new_literal (GCONF_DEFAULTS_ERROR,
					      GCONF_DEFAULTS_ERROR_GENERAL,
					      error->message);
		g_error_free (error);

		dbus_g_method_return_error (context, error2);
		g_error_free (error2);
	}
	else
		dbus_g_method_return (context);

out:
	start_killtimer ();
}
Ejemplo n.º 22
0
char twotail_exact(struct tw *m, double *cp, double *sp)
#define PR (*cp)
#define FT (*sp)
  {
  char k;
  struct entry em;
  double sec_prob, check, orig_p;
  int orig_cross;
        em=copy_entry(m);
        if( !(em.x1 * em.x4 - em.x2 * em.x3) ) {
	  printf("exact fit -> det = 0\n");
          *cp=1.;
          *sp=0.5;
          exactfit=1;
          return 1;
        }

                            /* probability of the original table */
        if((PR=hypergeom(&em)) < 0.0) {
	   PR=FT=DMY;
	   return -1;
        }

        k=minx(&em);
    orig_p=PR;
    switch (k) {   /* first tail */

      case 1:
        while( em.x1 && em.x4 ) {
           --em.x1;       /* decrement 11-22 diagonal */
           --em.x4;
           ++em.x2;
           ++em.x3;
           if((check=hypergeom(&em)) < 0.0) {
                        PR=FT=DMY;
			return -1;
           }
           PR+=check;
        }
      break;

      case 2:
        while( em.x2 && em.x3 ) {
           --em.x2;        /* decrement 12-21 diagonal */
           --em.x3;
           ++em.x1;
           ++em.x4;
           if((check=hypergeom(&em)) < 0.0) {
			PR=FT=DMY;
                        return -1;
           }
           PR+=check;
        }
      break;
    }
#define X1 em.x1
#define X2 em.x2
#define X3 em.x3
#define X4 em.x4


    /* second tail */

    em=copy_entry(m);
    orig_cross = ABS( X1*X4 - X2*X3 );
    sec_prob=0.0;
    switch (k) {

        case 1:
        while( em.x2 && em.x3 ) {
           --em.x2;        /* decrement 12-21 diagonal */
           --em.x3;
           ++em.x1;
           ++em.x4;
	   if ( ABS( X1*X4 - X2*X3 ) < orig_cross ) continue;
           if((check=hypergeom(&em)) < 0.0) {
                        PR=FT=DMY;
                        return -1;
           }
           if(check > orig_p) continue;
           sec_prob+=check;
        }
        break;

        case 2:
        while( em.x1 && em.x4 ) {
           --em.x1;        /* decrement  11-22 diagonal */
	   --em.x4;
           ++em.x2;
           ++em.x3;
           if ( ABS( X1*X4 - X2*X3 ) < orig_cross  ) continue;
           if((check=hypergeom(&em)) < 0.0) {
                        PR=FT=DMY;
                        return -1;
           }
           if(check > orig_p) continue;
           sec_prob+=check;
        }
        break;
    }

    /* probabilities  */
    FT=PR;         /* first tail (closest) */
    PR+=sec_prob;  /* both tails */
    return 1;

    #undef PR
    #undef FT
    #undef X1
    #undef X2
    #undef X3
    #undef X4
  }
Ejemplo n.º 23
0
static void
do_copy_authorized (GConfDefaults          *mechanism,
                    DBusGMethodInvocation  *context,
		    gpointer                user_data)
{
        CopyData    *data = user_data;
	GConfClient *source = NULL;
	GConfClient *dest = NULL;
	GConfChangeSet *changes = NULL;
	GConfEngine *engine;
        char *address = NULL;
        gint i;
	GError *error;

	error = NULL;
	engine = gconf_engine_get_local (data->dest_address, &error);
	if (error)
		goto cleanup;

	dest = gconf_client_get_for_engine (engine);
	gconf_engine_unref (engine);

	/* find the address to from the caller id */
        address = gconf_address_for_caller (data->mechanism, data->context, &error);
	if (error)
		goto cleanup;

	engine = gconf_engine_get_local (address, &error);
	if (error)
		goto cleanup;

	source = gconf_client_get_for_engine (engine);
	gconf_engine_unref (engine);

	changes = gconf_change_set_new ();

	if (data->value) {
		g_assert (data->includes[1] == NULL);
                g_assert (data->excludes == NULL);

		gconf_change_set_set (changes, data->includes[0], data->value);
	}
	else {
	 	/* recursively copy each include, leaving out the excludes */
		for (i = 0; data->includes[i]; i++) {
			if (gconf_client_dir_exists (source, data->includes[i], NULL))
				copy_tree (source, data->includes[i], changes, (const char **)data->excludes);
			else
				copy_entry (source, data->includes[i], changes, (const char **)data->excludes);
		}
	}

	gconf_client_commit_change_set (dest, changes, FALSE, &error);
	gconf_client_suggest_sync (dest, NULL);

	if (data->changeset_callback) {
		data->changeset_callback (data->mechanism, changes, data->user_data);
	}

cleanup:
	g_free (address);
	if (changes)
		gconf_change_set_unref (changes);
	if (dest)
		g_object_unref (dest);
	if (source)
		g_object_unref (source);

	if (error) {
		throw_error (data->context,
			     GCONF_DEFAULTS_ERROR_GENERAL,
			     "%s", error->message);
		g_error_free (error);
	}
	else
        	dbus_g_method_return (data->context);
}