Exemplo n.º 1
0
int
main(int argc, char **argv)
{
	status_t error;
	device_node_cookie root;

	if ((error = init_dm_wrapper()) < 0) {
		printf("Error initializing device manager (%s)\n", strerror(error));
		return error;
	}

	if (argc > 2)
		usage();

	if (argc == 2) {
		if (!strcmp(argv[1], "-d")) {
			gMode = DUMP_MODE;
		} else {
			usage();
		}
	}

	if (gMode == DUMP_MODE) {
		get_root(&root);
		dump_nodes(&root, 0);
	} else {
		get_root(&root);
		display_nodes(&root, 0);
	}

	uninit_dm_wrapper();

	return 0;
}
Exemplo n.º 2
0
void spawnnode(int x, int y, char direction, node_t *parent, char target, int targetx, int targety)
{
	int idx;
	int tx;
	int ty;

	if (nodecount >= 2048)
	{
		dump_nodes();
		fprintf(logfile, "Ran out of nodes to %c @ %i.%i (I'm at %i.%i)\n", target, targetx, targety, myx, myy);
		return;
	}

	if (y < 2 || y > 22)
	{
		return;
	}

	whereidbe(direction, &tx, &ty);
	if (notebuffer[myy * 80 + myx] & NOTE_OPENDOOR || notebuffer[ty * 80 + tx] & NOTE_OPENDOOR)
	{
		if (notebuffer[ty * 80 + tx] & NOTE_OPENDOOR && ismonster(target) && targetx == tx && targety == ty)
		{
			// just trap against the next if
		}
		else if (direction == '1' || direction == '3' || direction == '7' || direction == '9')
		{
			return;
		}
	}
	/*if (notebuffer[ty * 80 + tx] & NOTE_TRAP)
	{
		return;
	}*/

	for (idx = 0; idx < nodecount; idx++)
	{
		if (node[idx].x == x && node[idx].y == y)
		{
			return;
		}
	}

	if (impassable(framebuffer[y * 80 + x], x, y) && (framebuffer[y * 80 + x] != target || x != targetx || y != targety))
	{
		return;
	}
	if (framebuffer[y * 80 + x] == ' ' && (target != ' ' || x != targetx || y != targety))
	{
		return;
	}

	node[nodecount].x = x;
	node[nodecount].y = y;
	node[nodecount].closed = 0;
	node[nodecount].direction = direction;
	node[nodecount].parent = parent;
	nodecount++;
}
Exemplo n.º 3
0
static void
write_node (GtkTreeModel* model,
	    GtkTreeIter * iter,
	    FILE        * file)
{
	gchar const* text;
	CTask      * task = c_task_list_get_task (C_TASK_LIST (model), iter);

	text = c_task_get_text (task);
	g_return_if_fail (g_utf8_validate (text, -1, NULL));

	fprintf (file, "<task uuid=\"%s\">", c_task_get_uuid (task));
	for (; text && *text; text = g_utf8_next_char (text)) {
		gunichar c = g_utf8_get_char (text);

		if (c < 32 && c != 10) {
			// ASCII control chars
			g_warning ("FIXME: ascii control char %d encountered, ignoring.",
				   c);
		} else if (c > 127) {
			// UTF-8 multibyte chars
			fprintf (file, "&#%d;", c);
		} else {
			gchar const* entity = NULL;

			switch (c) {
			case '"':
				entity = "quot";
				break;
			case '\'':
				entity = "apos";
				break;
			case '&':
				entity = "amp";
				break;
			case '<':
				entity = "lt";
				break;
			case '>':
				entity = "gt";
				break;
			}

			if (G_UNLIKELY (entity)) {
				fprintf (file, "&%s;", entity);
			} else {
				fprintf (file, "%c", c);
			}
		}
	}

	dump_nodes (C_TASK_LIST (model), file, iter);

	fprintf (file, "</task>");
}
Exemplo n.º 4
0
static void
dump_nodes(device_node_cookie *node, uint8 level)
{
	status_t err;
	device_node_cookie child = *node;
	dump_device(node, level);

	if (get_child(&child) != B_OK)
		return;

	do {
		dump_nodes(&child, level + 1);
	} while ((err = get_next_child(&child)) == B_OK);

}
Exemplo n.º 5
0
char pathto(int x, int y, char target, unsigned char test)
{
	char tmpact;
	char v = findpath(myx, myy, x, y, target);

	if (!test)
		dump_nodes();

	if (test || v != '!')
		return v;

	getact:
	tmpact = ((rand() % 2) ? ('s') : pickrandomdirection());
	if (tmpact == '5')
	{
		goto getact;
	}

	return tmpact;
}
Exemplo n.º 6
0
/*
 * dump_nodes --
 *	dump the NODEs from `cur', based in the directory `dir'.
 *	if pathlast is none zero, print the path last, otherwise print
 *	it first.
 */
void
dump_nodes(const char *dir, NODE *root, int pathlast)
{
	NODE	*cur;
	char	path[MAXPATHLEN];
	const char *name;
	char	*str;
	char	*p, *q;

	for (cur = root; cur != NULL; cur = cur->next) {
		if (cur->type != F_DIR && !matchtags(cur))
			continue;

		if (snprintf(path, sizeof(path), "%s%s%s",
		    dir, *dir ? "/" : "", cur->name)
		    >= (int)sizeof(path))
			mtree_err("Pathname too long.");

		if (!pathlast)
			printf("%s", vispath(path));

#define MATCHFLAG(f)	((keys & (f)) && (cur->flags & (f)))
		if (MATCHFLAG(F_TYPE))
			appendfield(pathlast, "type=%s", nodetype(cur->type));
		if (MATCHFLAG(F_UID | F_UNAME)) {
			if (keys & F_UNAME &&
			    (name = user_from_uid(cur->st_uid, 1)) != NULL)
				appendfield(pathlast, "uname=%s", name);
			else
				appendfield(pathlast, "uid=%u", cur->st_uid);
		}
		if (MATCHFLAG(F_GID | F_GNAME)) {
			if (keys & F_GNAME &&
			    (name = group_from_gid(cur->st_gid, 1)) != NULL)
				appendfield(pathlast, "gname=%s", name);
			else
				appendfield(pathlast, "gid=%u", cur->st_gid);
		}
		if (MATCHFLAG(F_MODE))
			appendfield(pathlast, "mode=%#o", cur->st_mode);
		if (MATCHFLAG(F_DEV) &&
		    (cur->type == F_BLOCK || cur->type == F_CHAR))
			appendfield(pathlast, "device=%#llx", (long long)cur->st_rdev);
		if (MATCHFLAG(F_NLINK))
			appendfield(pathlast, "nlink=%d", cur->st_nlink);
		if (MATCHFLAG(F_SLINK))
			appendfield(pathlast, "link=%s", vispath(cur->slink));
		if (MATCHFLAG(F_SIZE))
			appendfield(pathlast, "size=%lld", (long long)cur->st_size);
		if (MATCHFLAG(F_TIME))
			appendfield(pathlast, "time=%lld.%09ld",
			    (long long)cur->st_mtimespec.tv_sec,
			    cur->st_mtimespec.tv_nsec);
		if (MATCHFLAG(F_CKSUM))
			appendfield(pathlast, "cksum=%lu", cur->cksum);
		if (MATCHFLAG(F_MD5))
			appendfield(pathlast, "%s=%s", MD5KEY, cur->md5digest);
		if (MATCHFLAG(F_RMD160))
			appendfield(pathlast, "%s=%s", RMD160KEY,
			    cur->rmd160digest);
		if (MATCHFLAG(F_SHA1))
			appendfield(pathlast, "%s=%s", SHA1KEY,
			    cur->sha1digest);
		if (MATCHFLAG(F_SHA256))
			appendfield(pathlast, "%s=%s", SHA256KEY,
			    cur->sha256digest);
		if (MATCHFLAG(F_SHA384))
			appendfield(pathlast, "%s=%s", SHA384KEY,
			    cur->sha384digest);
		if (MATCHFLAG(F_SHA512))
			appendfield(pathlast, "%s=%s", SHA512KEY,
			    cur->sha512digest);
		if (MATCHFLAG(F_FLAGS)) {
			str = flags_to_string(cur->st_flags, "none");
			appendfield(pathlast, "flags=%s", str);
			free(str);
		}
		if (MATCHFLAG(F_IGN))
			appendfield(pathlast, "ignore");
		if (MATCHFLAG(F_OPT))
			appendfield(pathlast, "optional");
		if (MATCHFLAG(F_TAGS)) {
			/* don't output leading or trailing commas */
			p = cur->tags;
			while (*p == ',')
				p++;
			q = p + strlen(p);
			while(q > p && q[-1] == ',')
				q--;
			appendfield(pathlast, "tags=%.*s", (int)(q - p), p);
		}
		puts(pathlast ? vispath(path) : "");

		if (cur->child)
			dump_nodes(path, cur->child, pathlast);
	}
}
Exemplo n.º 7
0
char pathto(int x, int y, char target, unsigned char test)
{
    int idx;
    int timeout = 0;
    int cx = myx;
    int cy = myy;
    int leastidx = -1;
    int leastscore;
    char tmpact;
    node_t *nodeptr;

    //fprintf(logfile, "Pathing to %i.%i, I am @ %i.%i\n", x, y, myx, myy);

    if (x == myx && y == myy)
    {
        return 's';
    }

    nodecount = 0;
    while (timeout < 250)
    {
        if (leastidx != -1)
        {
            node[leastidx].closed = 1;
        }
        if (leastidx != -1)
        {
            spawnnodesaround(cx, cy, &node[leastidx], target, x, y, test);
        }
        else
        {
            spawnnodesaround(cx, cy, NULL, target, x, y, test);
        }

        if (!nodecount)
        {
            return 's';
        }
        for (idx = 0; idx < nodecount; idx++)
        {
            if (!node[idx].closed)
            {
                break;
            }
        }
        if (idx == nodecount)
        {
            break;
        }
        /*fprintf(logfile, "%i nodes\n", nodecount);
        for (idx = 0; idx < nodecount; idx++)
        {
        	if (node[idx].closed)
        	{
        		continue;
        	}
        	fprintf(logfile, "%i: %i (%c) (%i.%i) %c\n", idx, node[idx].score, node[idx].direction, node[idx].x, node[idx].y, (node[idx].closed) ? 'c' : 'o');
        }*/

        leastidx = -1;
        for (idx = 0; idx < nodecount; idx++)
        {
            if (node[idx].closed)
            {
                continue;
            }
            if (leastidx == -1 || node[idx].score < leastscore)
            {
                leastscore = node[idx].score;
                leastidx = idx;
            }
        }
        if (leastidx == -1)
        {
            break;
        }
        //fprintf(logfile, "node %i has lowest score of %i\n", leastidx, node[leastidx].score);
        /*for (idx = 0; idx < nodecount; idx++)
        {
        	if (idx != leastidx)
        	{
        		node[idx].closed = 1;
        	}
        }*/

        cx = node[leastidx].x;
        cy = node[leastidx].y;

        if (cx == x && cy == y)
        {
            nodeptr = &node[leastidx];
            while (nodeptr->parent)
            {
                nodeptr->used = 1;
                nodeptr = nodeptr->parent;
            }
            if (!test)
            {
                dump_nodes();
            }
            return nodeptr->direction;
        }

        timeout++;
    }

    if (test)
    {
        return '!';
    }

getact:
    tmpact = ((rand() % 2) ? ('s') : pickrandomdirection());
    if (tmpact == '5')
    {
        goto getact;
    }

    if (!test)
    {
        dump_nodes();
        fprintf(logfile, "Unable to resolve %i.%i (%c), I am at %i.%i. Searching\n", x, y, target, myx, myy);
    }

    return tmpact;
}
Exemplo n.º 8
0
void spawnnode(int x, int y, char direction, node_t *parent, char target, int targetx, int targety, int cx, int cy, unsigned char test)
{
    int idx;
    int tx;
    int ty;

    if (nodecount >= 2048)
    {
        dump_nodes();
        fprintf(logfile, "Ran out of nodes to %c @ %i.%i (I'm at %i.%i)\n", target, targetx, targety, myx, myy);
        return;
    }

    if (y < 2 || y > 22)
    {
        return;
    }

    whereidbe(direction, &tx, &ty);
    if (notebuffer[cy * 80 + cx] & NOTE_OPENDOOR || notebuffer[y * 80 + x] & NOTE_OPENDOOR || notebuffer[ty * 80 + tx] & NOTE_OPENDOOR)
    {
        if (notebuffer[ty * 80 + tx] & NOTE_OPENDOOR && ismonster(target) && targetx == tx && targety == ty)

        {
            // just trap against the next if
        }
        else if (direction == '1' || direction == '3' || direction == '7' || direction == '9')
        {
            return;
        }
    }
    // if it's a trap, don't step on it, unless it's unavoidable (no way to
    // path around it)
    /*
    if (notebuffer[ty * 80 + tx] & NOTE_TRAP && avoidabletrap(tx, ty) && (framebuffer[ty * 80 + tx] != target || tx != x || ty != y))
    {
    	return;
    }
    */

    for (idx = 0; idx < nodecount; idx++)
    {
        if (node[idx].x == x && node[idx].y == y)
        {
            return;
        }
    }

    if (impassable(framebuffer[y * 80 + x], x, y))
    {
        // don't move into a NOTOUCH monster no matter what, unless
        // we're only TESTING pathability
        if (framebuffer[y * 80 + x] == target && x == targetx && y == targety && (target != NOTOUCH_MONSTER || test))
        {
            // trap against else for clarity
        }
        else
        {
            return;
        }
    }
    if (framebuffer[y * 80 + x] == ' ' && (target != ' ' || x != targetx || y != targety))
    {
        return;
    }

    node[nodecount].x = x;
    node[nodecount].y = y;
    node[nodecount].closed = 0;
    node[nodecount].direction = direction;
    node[nodecount].parent = parent;
    node[nodecount].used = 0;
    if (parent)
    {
        node[nodecount].score = makescore(targetx, targety, x, y, target) + parent->score;
    }
    else
    {
        node[nodecount].score = makescore(targetx, targety, x, y, target);
    }
    nodecount++;
}
Exemplo n.º 9
0
static RETSIGTYPE sigusr2_handler(int a) {
	devops.dump_stats();
	dump_nodes();
	dump_edges();
	dump_subnets();
}
Exemplo n.º 10
0
void
dump_node(int indent, Node *node)
{
  switch (node->kind) {
    case NODE_ROOT:
    case NODE_DECLN:
    case NODE_COMPOUND_STMT:
      indented_puts(indent, kind_label(node->kind));
      dump_vector(indent + 1, node->children);
      break;
    case NODE_PTR:
    case NODE_RETURN:
      indented_puts(indent, kind_label(node->kind));
      if (node->param) dump_node(indent + 1, node->param);
      break;
    case NODE_FUNC:
      indented_puts(indent, kind_label(node->kind));
      dump_nodes(indent + 1, 3, node->type, node->spec, node->stmts);
      break;
    case NODE_PARAM_DECL:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->type);
      if (node->spec) dump_node(indent + 1, node->spec);
      break;
    case NODE_FUNC_DECL:
    case NODE_VAR_DECL:
      indented_puts(indent, kind_label(node->kind));
      dump_nodes(indent + 1, 2, node->type, node->spec);
      break;
    case NODE_FUNCALL:
    case NODE_FUNC_SPEC:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->func);
      dump_vector(indent + 1, node->params);
      break;
    case NODE_TYPE:
      indented_printf(indent, "%s", kind_label(node->kind));
      print_types(node);
      printf("\n");
      if (node->fields) dump_vector(indent + 1, node->fields);
      break;
    case NODE_FIELD:
      indented_printf(indent, "%s\n", kind_label(node->kind));
      dump_node(indent + 1, node->field_type);
      dump_vector(indent + 1, node->fields);
      break;
    case NODE_IDENTIFIER:
    case NODE_SPEC:
    case NODE_STRING:
    case NODE_DEFINED:
      indented_printf(indent, "%s id=%s\n", kind_label(node->kind), node->id);
      break;
    case NODE_INTEGER:
      indented_printf(indent, "%s ival=%d\n", kind_label(node->kind), node->ival);
      break;
    case NODE_BINOP:
      indented_printf(indent, "%s '%c'\n", kind_label(node->kind), node->op);
      dump_node(indent + 1, node->lhs);
      dump_node(indent + 1, node->rhs);
      break;
    case NODE_UNARY:
      if ((int)node->op >= 256) {
        indented_printf(indent, "%s token %d\n", kind_label(node->kind), (int)node->op);
      } else {
        indented_printf(indent, "%s %c\n", kind_label(node->kind), node->op);
      }
      if (node->lhs) dump_node(indent + 1, node->lhs);
      if (node->rhs) dump_node(indent + 1, node->rhs);
      break;
    case NODE_IF:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->cond);
      dump_node(indent + 1, node->if_stmt);
      if (node->else_stmt) dump_node(indent + 1, node->else_stmt);
      break;
    case NODE_ARRAY_SPEC:
      indented_puts(indent, kind_label(node->kind));
      dump_node(indent + 1, node->lhs);
      dump_node(indent + 1, node->rhs);
      break;
    default:
      indented_puts(indent, kind_label(node->kind));
      break;
  }
}
int
main(int argc, char **argv)
{
	int	ch, status;
	unsigned int	i;
	int	cflag, Cflag, Dflag, Uflag, wflag;
	char	*dir, *p;
	FILE	*spec1, *spec2;

	setprogname(argv[0]);

	cflag = Cflag = Dflag = Uflag = wflag = 0;
	dir = NULL;
	init_excludes();
	spec1 = stdin;
	spec2 = NULL;

	while ((ch = getopt(argc, argv,
	    "bcCdDeE:f:F:I:ijk:K:lLmMnN:O:p:PqrR:s:StuUwWxX:"))
	    != -1) {
		switch((char)ch) {
		case 'b':
			bflag = 1;
			break;
		case 'c':
			cflag = 1;
			break;
		case 'C':
			Cflag = 1;
			break;
		case 'd':
			dflag = 1;
			break;
		case 'D':
			Dflag = 1;
			break;
		case 'E':
			parsetags(&excludetags, optarg);
			break;
		case 'e':
			eflag = 1;
			break;
		case 'f':
			if (spec1 == stdin) {
				spec1 = fopen(optarg, "r");
				if (spec1 == NULL)
					mtree_err("%s: %s", optarg,
					    strerror(errno));
			} else if (spec2 == NULL) {
				spec2 = fopen(optarg, "r");
				if (spec2 == NULL)
					mtree_err("%s: %s", optarg,
					    strerror(errno));
			} else
				usage();
			break;
		case 'F':
			for (i = 0; i < __arraycount(flavors); i++)
				if (strcmp(optarg, flavors[i].name) == 0) {
					flavor = flavors[i].flavor;
					break;
				}
			if (i == __arraycount(flavors))
				usage();
			break;
		case 'i':
			iflag = 1;
			break;
		case 'I':
			parsetags(&includetags, optarg);
			break;
		case 'j':
			jflag = 1;
			break;
		case 'k':
			keys = F_TYPE;
			while ((p = strsep(&optarg, " \t,")) != NULL)
				if (*p != '\0')
					keys |= parsekey(p, NULL);
			break;
		case 'K':
			while ((p = strsep(&optarg, " \t,")) != NULL)
				if (*p != '\0')
					keys |= parsekey(p, NULL);
			break;
		case 'l':
			lflag = 1;
			break;
		case 'L':
			ftsoptions &= ~FTS_PHYSICAL;
			ftsoptions |= FTS_LOGICAL;
			break;
		case 'm':
			mflag = 1;
			break;
		case 'M':
			mtree_Mflag = 1;
			break;
		case 'n':
			nflag = 1;
			break;
		case 'N':
			if (! setup_getid(optarg))
				mtree_err(
			    "Unable to use user and group databases in `%s'",
				    optarg);
			break;
		case 'O':
			load_only(optarg);
			break;
		case 'p':
			dir = optarg;
			break;
		case 'P':
			ftsoptions &= ~FTS_LOGICAL;
			ftsoptions |= FTS_PHYSICAL;
			break;
		case 'q':
			qflag = 1;
			break;
		case 'r':
			rflag++;
			break;
		case 'R':
			while ((p = strsep(&optarg, " \t,")) != NULL)
				if (*p != '\0')
					keys &= ~parsekey(p, NULL);
			break;
		case 's':
			sflag = 1;
			crc_total = ~strtol(optarg, &p, 0);
			if (*p)
				mtree_err("illegal seed value -- %s", optarg);
			break;
		case 'S':
			mtree_Sflag = 1;
			break;
		case 't':
			tflag = 1;
			break;
		case 'u':
			uflag = 1;
			break;
		case 'U':
			Uflag = uflag = 1;
			break;
		case 'w':
			wflag = 1;
			break;
		case 'W':
			mtree_Wflag = 1;
			break;
		case 'x':
			ftsoptions |= FTS_XDEV;
			break;
		case 'X':
			read_excludes_file(optarg);
			break;
		case '?':
		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (argc)
		usage();

	switch (flavor) {
	case F_FREEBSD9:
		if (cflag && iflag) {
			warnx("-c and -i passed, replacing -i with -j for "
			    "FreeBSD compatibility");
			iflag = 0;
			jflag = 1;
		}
		if (dflag && !bflag) {
			warnx("Adding -b to -d for FreeBSD compatibility");
			bflag = 1;
		}
		if (uflag && !iflag) {
			warnx("Adding -i to -%c for FreeBSD compatibility",
			    Uflag ? 'U' : 'u');
			iflag = 1;
		}
		if (uflag && !tflag) {
			warnx("Adding -t to -%c for FreeBSD compatibility",
			    Uflag ? 'U' : 'u');
			tflag = 1;
		}
		if (wflag)
			warnx("The -w flag is a no-op");
		break;
	default:
		if (wflag)
			usage();
	}

	if (spec2 && (cflag || Cflag || Dflag))
		mtree_err("Double -f, -c, -C and -D flags are mutually "
		    "exclusive");

	if (dir && spec2)
		mtree_err("Double -f and -p flags are mutually exclusive");

	if (dir && chdir(dir))
		mtree_err("%s: %s", dir, strerror(errno));

	if ((cflag || sflag) && !getcwd(fullpath, sizeof(fullpath)))
		mtree_err("%s", strerror(errno));

	if ((cflag && Cflag) || (cflag && Dflag) || (Cflag && Dflag))
		mtree_err("-c, -C and -D flags are mutually exclusive");

	if (iflag && mflag)
		mtree_err("-i and -m flags are mutually exclusive");

	if (lflag && uflag)
		mtree_err("-l and -u flags are mutually exclusive");

	if (cflag) {
		cwalk(stdout);
		exit(0);
	}
	if (Cflag || Dflag) {
		dump_nodes(stdout, "", spec(spec1), Dflag);
		exit(0);
	}
	if (spec2 != NULL)
		status = mtree_specspec(spec1, spec2);
	else
		status = verify(spec1);
	if (Uflag && (status == MISMATCHEXIT))
		status = 0;
	exit(status);
}
Exemplo n.º 12
0
static void
task_list_io_xml_save (CTaskList  * self,
                       gchar const* path)
{
        GMappedFile* old_version;
        gchar* xml_path = task_list_io_xml_path (path);
        FILE* file;

	/* we don't care if this fails */
	old_version = g_mapped_file_new (xml_path, FALSE, NULL);
	if (old_version) {
		gchar* backup_path = g_strdup_printf ("%s.%li", xml_path, time (NULL));
		g_file_set_contents (backup_path,
				     g_mapped_file_get_contents (old_version),
				     g_mapped_file_get_length (old_version),
				     NULL);
		g_free (backup_path);
		g_mapped_file_free (old_version);
	}

        file = fopen (xml_path, "w");
        if (!file)
          {
            int old_errno = errno;
            GtkWidget* dialog;

            if (old_errno == ENOENT)
              {
                gchar* folder = g_path_get_dirname (xml_path);
                if (g_mkdir_with_parents (folder, 0755) == 0)
                  {
                    file = fopen (xml_path, "w");
                  }

                g_free (folder);

                if (file)
                  {
                    goto cont;
                  }
              }

            /* FIXME: the user should be able to save to a different place */
            old_errno = errno;
            dialog = gtk_message_dialog_new (NULL, /* FIXME: add window */
                                             0, /* FIXME: make modal */
                                             GTK_MESSAGE_ERROR,
                                             GTK_BUTTONS_CLOSE,
                                             "%s", _("Error saving to file"));
            gtk_message_dialog_format_secondary_markup (GTK_MESSAGE_DIALOG (dialog),
                                                        _("Couldn't open file \"%s\" for writing:\n\n"
                                                          "<span style='italic'>%s</span>"),
                                                        xml_path,
                                                        strerror (old_errno));

            gtk_dialog_run (GTK_DIALOG (dialog));
            gtk_widget_destroy (dialog);

            goto cleanup;
          }
cont:
        fprintf (file, "<?xml version=\"1.0\" encoding=\"iso-8859-15\"?>\n");
        fprintf (file, "<tasks>\n");
        dump_nodes (self, file, NULL);
        fprintf (file, "</tasks>\n");
        if (fclose (file) != 0)
          {
            /* FIXME: come up with a proper fallback solution */
            g_warning ("error closing file: %s", strerror (errno));
          }
cleanup:
        g_free (xml_path);
}
Exemplo n.º 13
0
char pathto(int x, int y, char target, unsigned char test)
{
	int idx;
	int least = 9999999;
	int leastidx = -1;
	int timeout = 0;
	node_t *nodeptr;
	int oldnodecount;
	char tmpact;

	nodecount = 0;
	spawnnodesaround(myx, myy, NULL, target, x, y);
	for (idx = 0; idx < nodecount; idx++)
	{
		if (node[idx].x == x && node[idx].y == y)
		{
			if (node[idx].direction == '5')
			{
				node[idx].direction = '.';
			}
			if (!test)
			{
				dump_nodes();
				fprintf(logfile, "Resolved %i.%i as %c (I'm at %i.%i)\n", x, y, node[idx].direction, myx, myy);
			}
			return node[idx].direction;
		}
	}

	do
	{
		oldnodecount = nodecount;
		for (idx = 0; idx < oldnodecount; idx++)
		{
			if (!node[idx].closed)
			{
				spawnnodesaround(node[idx].x, node[idx].y, &node[idx], target, x, y);
				node[idx].closed = 1;
			}
		}
		for (idx = 0; idx < nodecount; idx++)
		{
			if (node[idx].closed)
			{
				continue;
			}
			if (node[idx].x == x && node[idx].y == y)
			{
				nodeptr = &node[idx];
				while (nodeptr->parent)
				{
					nodeptr = nodeptr->parent;
				}
				if (!test)
				{
					dump_nodes();
					fprintf(logfile, "Resolved %i.%i as %c (I'm at %i.%i)\n", x, y, nodeptr->direction, myx, myy);
				}
				if (nodeptr->direction == '5')
				{
					nodeptr->direction = '.';
				}
				return nodeptr->direction;
			}
		}
		timeout++;
	} while (timeout < 200);

	if (test)
	{
		return '!';
	}

	getact:
	tmpact = (rand() % 2 ? ('s') : pickrandomdirection());
	if (tmpact == '5')
	{
		goto getact;
	}

	if (test)
	{
		dump_nodes();
		fprintf(logfile, "Unable to resolve %i.%i (%c), I am at %i.%i. Searching\n", x, y, target, myx, myy);
	}

	return tmpact;
}
Exemplo n.º 14
0
/*
 * dump_nodes --
 *	dump the NODEs from `cur', based in the directory `dir'.
 *	if pathlast is none zero, print the path last, otherwise print
 *	it first.
 */
void
dump_nodes(const char *dir, NODE *root, int pathlast)
{
	NODE	*cur;
	char	path[MAXPATHLEN];
	const char *name;

	for (cur = root; cur != NULL; cur = cur->next) {
		if (cur->type != F_DIR && !matchtags(cur))
			continue;

		if (snprintf(path, sizeof(path), "%s%s%s",
		    dir, *dir ? "/" : "", cur->name)
		    >= sizeof(path))
			mtree_err("Pathname too long.");

		if (!pathlast)
			printf("%s ", vispath(path));

#define MATCHFLAG(f)	((keys & (f)) && (cur->flags & (f)))
		if (MATCHFLAG(F_TYPE))
			printf("type=%s ", nodetype(cur->type));
		if (MATCHFLAG(F_UID | F_UNAME)) {
			if (keys & F_UNAME &&
			    (name = user_from_uid(cur->st_uid, 1)) != NULL)
				printf("uname=%s ", name);
			else
				printf("uid=%u ", cur->st_uid);
		}
		if (MATCHFLAG(F_GID | F_GNAME)) {
			if (keys & F_GNAME &&
			    (name = group_from_gid(cur->st_gid, 1)) != NULL)
				printf("gname=%s ", name);
			else
				printf("gid=%u ", cur->st_gid);
		}
		if (MATCHFLAG(F_MODE))
			printf("mode=%#o ", cur->st_mode);
		if (MATCHFLAG(F_DEV) &&
		    (cur->type == F_BLOCK || cur->type == F_CHAR))
			printf("device=%#x ", cur->st_rdev);
		if (MATCHFLAG(F_NLINK))
			printf("nlink=%d ", cur->st_nlink);
		if (MATCHFLAG(F_SLINK))
			printf("link=%s ", cur->slink);
		if (MATCHFLAG(F_SIZE))
			printf("size=%lld ", (long long)cur->st_size);
		if (MATCHFLAG(F_TIME))
			printf("time=%ld.%ld ", (long)cur->st_mtimespec.tv_sec,
			    cur->st_mtimespec.tv_nsec);
		if (MATCHFLAG(F_CKSUM))
			printf("cksum=%lu ", cur->cksum);
		if (MATCHFLAG(F_MD5))
			printf("md5=%s ", cur->md5digest);
		if (MATCHFLAG(F_RMD160))
			printf("rmd160=%s ", cur->rmd160digest);
		if (MATCHFLAG(F_SHA1))
			printf("sha1=%s ", cur->sha1digest);
		if (MATCHFLAG(F_FLAGS))
			printf("flags=%s ",
			    flags_to_string(cur->st_flags, "none"));
		if (MATCHFLAG(F_IGN))
			printf("ignore ");
		if (MATCHFLAG(F_OPT))
			printf("optional ");
		if (MATCHFLAG(F_TAGS))
			printf("tags=%s ", cur->tags);
		puts(pathlast ? vispath(path) : "");

		if (cur->child)
			dump_nodes(path, cur->child, pathlast);
	}
}