コード例 #1
0
ファイル: psyntree.c プロジェクト: AkankshaGovil/Automation
RVAPI pstNodeType RVCALLCONV /* type of node */
pstGetNodeType(
           IN  HPST hSyn,
           IN  int nodeId
           )
{
    stNodeExt* node;

    if (hSyn != NULL)
    {
        node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, nodeId);
        if (node != NULL)
            return (pstNodeType)m_type(node);
    }

    return (pstNodeType)RVERROR;
}
コード例 #2
0
ファイル: psyntree.c プロジェクト: AkankshaGovil/Automation
/************************************************************************
 * pstPrintNode
 * purpose: Print the information of a syntax tree node to a buffer
 * input  : hSyn    - Syntax tree handle
 *          nodeId  - Node to print
 *          buf     - Result buffer to use
 *          len     - Length of buffer
 * output : none
 * return : Number of characters printed
 ************************************************************************/
int pstPrintNode(
    IN  HPST            hSyn,
    IN  int             nodeId,
    IN  char*           buf,
    IN  int             len)
{
    stNodeExt*  node;
    char*       ptr = buf;
    char*       fromString;
    stNodeExt*  ofNode;

    /* Get the node itself */
    node = (stNodeExt *)stGetNodeDataByNodeId(hSyn, nodeId);
    if (node == NULL) return 0;

    /* 1. GENERAL TYPE */
    ptr += sprintf(ptr, "%s ", nprn(pstGetTokenName((pstNodeType)(m_type(node)))));

    /* 2. TAG */
    if (m_tag(node) >= 0)
      ptr += sprintf(ptr, "[%s %d] ", nprn(pstGetTagClassName((pstTagClass)m_tagClass(node))), m_tag(node));

    /* 3. FROM-TO */
    if ((m_from(node) > 0) || (m_to(node) > 0))
    {
        /* Check for negative boundaries */
        if (m_from(node) <= m_to(node))
            ptr += sprintf(ptr, "(%d..%d) ", m_from(node), m_to(node));
        else
            ptr += sprintf(ptr, "(%u..%u)or(%d..%d) ", m_from(node), m_to(node), m_from(node), m_to(node));
    }

    /* 4. FROM CHARS */
    if (m_fromId(node) >= 0)
    {
        fromString = stGetNameByNameId(hSyn, m_fromId(node), NULL);
        if (fromString[0])
            ptr += sprintf(ptr, "FROM '%s' ", fromString);
    }

    /* 5. EXTENSION */
    if (m_isExtension(node))
    {
        strcpy(ptr, "... ");
        ptr += 4;
    }

    /* 6. SEQUENCE OF recursion */
    switch (m_type(node))
    {
        case pstOf:
        case pstSequenceOf:
        case pstSetOf:
            ofNode = (stNodeExt *)stGetNodeDataByNodeId(hSyn, m_ofId(node));
            if (ofNode != NULL)
            {
                int printedChars = (ptr - buf);
                return printedChars + pstPrintNode(hSyn, m_ofId(node), ptr, len - printedChars);
            }
        default:
            break;
    }

    return (ptr - buf);
}
コード例 #3
0
ファイル: pop3d.c プロジェクト: jturner/pop3d
int
main(int argc, char *argv[])
{
	struct passwd	*pw;
	struct event	ev_sigint, ev_sigterm, ev_sighup, ev_sigchld;
	const char	*path = NULL, *mtype_str = "mbox";
	int		ch, d = 0, pair[2];

	while ((ch = getopt(argc, argv, "dp:t:46")) != -1) {
		switch (ch) {
		case '4':
			afamily = AF_INET;
			break;
		case '6':
			afamily = AF_INET6;
			break;
		case 'd':
			d = 1;
			break;
		case 'p':
			path = optarg;
			break;
		case 't':
			if ((mtype = m_type(optarg)) == -1)
				errx(1, "%s invalid argument", optarg);
			mtype_str = optarg;
			break;
		default:
			usage();
		}
	}

	argc -= optind;
	argv += optind;
	if (argc > 0 || *argv)
		usage();

	if (path)
		mpath = path;
	else
		mpath = (mtype == M_MAILDIR) ? MAILDIR_PATH : MBOX_PATH;

	log_init(d);
	if (geteuid())
		fatalx("need root privileges");

	if (!d && daemon(1, 0) == -1)
		fatal("failed to daemonize");

	if (socketpair(AF_UNIX, SOCK_STREAM, AF_UNSPEC, pair) == -1)
		fatal("socketpair");

	set_nonblocking(pair[0]);
	set_nonblocking(pair[1]);
	if ((pw = getpwnam(POP3D_USER)) == NULL)
		fatalx("main: getpwnam " POP3D_USER);

	pop3_main(pair, afamily, pw);
	close(pair[1]);
	setproctitle("[priv]");
	logit(LOG_INFO, "pop3d ready; type:%s, path:%s", mtype_str, mpath);
	event_init();
	signal_set(&ev_sigint, SIGINT, sig_handler, NULL);
	signal_set(&ev_sighup, SIGHUP, sig_handler, NULL);
	signal_set(&ev_sigterm, SIGTERM, sig_handler, NULL);
	signal_set(&ev_sigchld, SIGCHLD, sig_handler, NULL);
	signal_add(&ev_sigint, NULL);
	signal_add(&ev_sighup, NULL);
	signal_add(&ev_sigterm, NULL);
	signal_add(&ev_sigchld, NULL);
	imsgev_init(&iev_pop3e, pair[0], NULL, pop3e_imsgev, needfd);
	if (event_dispatch() < 0)
		fatal("event_dispatch");

	logit(LOG_INFO, "pop3d exiting");
	return (0);
}