示例#1
0
文件: tree.c 项目: UraKn0x/gbdk
/* printtree1 - recursively print tree p */
static void printtree1(Tree p, int fd, int lev) {
	FILE *f = fd == 1 ? stdout : stderr;
	int i;
	static char blanks[] = "                                                   ";

	if (p == 0 || *printed(i = nodeid(p)))
		return;
	fprint(f, "#%d%S%S", i, blanks, i < 10 ? 2 : i < 100 ? 1 : 0, blanks, lev);
	fprint(f, "%s %t", opname(p->op), p->type);
	*printed(i) = 1;
	for (i = 0; i < NELEMS(p->kids); i++)
		if (p->kids[i])
			fprint(f, " #%d", nodeid(p->kids[i]));
	if (p->op == FIELD && p->u.field)
		fprint(f, " %s %d..%d", p->u.field->name,
			fieldsize(p->u.field) + fieldright(p->u.field), fieldright(p->u.field));
	else if (generic(p->op) == CNST)
		fprint(f, " %s", vtoa(p->type, p->u.v));
	else if (p->u.sym)
		fprint(f, " %s", p->u.sym->name);
	if (p->node)
		fprint(f, " node=%p", p->node);
	fprint(f, "\n");
	for (i = 0; i < NELEMS(p->kids); i++)
		printtree1(p->kids[i], fd, lev + 1);
}
示例#2
0
static void do_list(const char *msgnum)
{
unsigned i;
char	buf[NUMBUFSIZE];

	if (msgnum)
	{
		if ((i=getmsgnum(msgnum)) != 0)
		{
			printed(printf("+OK %u %s\r\n", i,
				       libmail_str_off_t(msglist_a[i-1]->size,
							 buf)));
			fflush(stdout);
		}
		return;
	}

	printed(printf("+OK POP3 clients that break here, they violate STD53.\r\n"));
	for (i=0; i<msglist_cnt; i++)
	{
		if (msglist_a[i]->isdeleted)	continue;
		printed(printf("%u %s\r\n", i+1, libmail_str_off_t(msglist_a[i]->size, buf)));
	}
	printed(printf(".\r\n"));
	fflush(stdout);
}
示例#3
0
void ScriptConsoleTest::evaluateLine_shouldReturnFalseForIncorrectScript()
{
    ScriptConsole console;    
    QSignalSpy printed(&console, SIGNAL(printed(QString)));
    QSignalSpy error(&console, SIGNAL(error(QString)));

    QVERIFY(!console.execCommand(wrongScript));
    QVERIFY(printed.isEmpty());
    QVERIFY(!error.isEmpty());
}
示例#4
0
void ScriptConsoleTest::evaluateLine_shouldReturnTrueForCorrectScript()
{
    ScriptConsole console;
    QSignalSpy printed(&console, SIGNAL(printed(QString)));
    QSignalSpy error(&console, SIGNAL(error(QString)));

    QVERIFY(console.execCommand(simpleScript));

    QVERIFY(printed.isEmpty());
    QVERIFY(error.isEmpty());
}
示例#5
0
文件: clog.cpp 项目: dosnut/nut
	void CLog::operator<<(QString text) {
		emit printed(text);

		if (m_fileLoggingEnabled) {
			m_outStream << text << endl;
		}
	}
示例#6
0
static void print_uidl(unsigned i)
{
	const char *p;

	if (enomem_1msg)
		/* Error recovery - out of disk space, see comments
		** at the beginning of this file.
		*/
	{
		char dev_buf[NUMBUFSIZE];
		char ino_buf[NUMBUFSIZE];
		char mtime_buf[NUMBUFSIZE];

		printed(printf("ENOMEM-%s-%s-%s\r\n",
			       libmail_strh_time_t(enomem_stat.st_mtime, mtime_buf),
			       libmail_strh_dev_t(enomem_stat.st_dev, dev_buf),
			       libmail_strh_ino_t(enomem_stat.st_ino, ino_buf))
			);
		return;
	}

	if (msglist_a[i]->uid.n != 0)
	{
		/* VERSION 1 and VERSION 2 UIDL */

		printed(printf((msglist_a[i]->uid.uidv ?
				"UID%lu-%lu\r\n":"UID%lu\r\n"),
			       msglist_a[i]->uid.n, msglist_a[i]->uid.uidv));
		return;
	}

	/* VERSION 0 UIDL */

	p=strchr(msglist_a[i]->filename, '/')+1;

	while (*p && *p != MDIRSEP[0])
	{
		if (*p < 0x21 || *p > 0x7E || *p == '\'' || *p == '"' ||
			*p == '+')
			printed(printf("+%02X", (int)(unsigned char)*p));
		else
			printchar(*p);
		++p;
	}
	printed(printf("\r\n"));
}
TEST_F(TextScanOperatorTest, ScanTest) {
  std::string golden_string = LoadGoldenOutput();

  const relation_id output_relation_id = relation_->getID();

  // Setup the InsertDestination proto in the query context proto.
  serialization::QueryContext query_context_proto;

  QueryContext::insert_destination_id output_destination_index = query_context_proto.insert_destinations_size();
  serialization::InsertDestination *output_destination_proto = query_context_proto.add_insert_destinations();

  output_destination_proto->set_insert_destination_type(serialization::InsertDestinationType::BLOCK_POOL);
  output_destination_proto->set_relation_id(output_relation_id);
  output_destination_proto->set_need_to_add_blocks_from_relation(false);
  output_destination_proto->set_relational_op_index(kOpIndex);
  output_destination_proto->set_foreman_client_id(tmb::kClientIdNone);

  std::unique_ptr<TextScanOperator> text_scan_op(
      new TextScanOperator(input_filename,
                           '\t',
                           true,
                           false,
                           output_relation_id,
                           output_destination_index,
                           tmb::kClientIdNone /* foreman_client_id */,
                           nullptr /* TMB */));

  // Setup query_context_.
  query_context_.reset(new QueryContext(query_context_proto,
                                        db_.get(),
                                        storage_manager_.get(),
                                        nullptr /* TMB */));

  fetchAndExecuteWorkOrders(text_scan_op.get());
  text_scan_op.reset(nullptr);

  MemStream print_stream;
  PrintToScreen::PrintRelation(*relation_,
                               storage_manager_.get(),
                               print_stream.file());
  std::string printed(print_stream.str());

  EXPECT_EQ(golden_string, printed);
  if (golden_string != printed) {
    FILE *failure_output = std::fopen(failure_output_filename, "w");
    CHECK_NOTNULL(failure_output);
    const std::size_t written
        = std::fwrite(printed.c_str(), 1, printed.length(), failure_output);
    CHECK_EQ(printed.length(), written);
    std::fclose(failure_output);
  }
}
示例#8
0
static unsigned getmsgnum(const char *p)
{
unsigned i;

	if (!p || (i=atoi(p)) > msglist_cnt || i == 0 ||
		msglist_a[i-1]->isdeleted)
	{
		printed(printf("-ERR Invalid message number.\r\n"));
		fflush(stdout);
		return (0);
	}
	return (i);
}
示例#9
0
static void do_uidl(const char *msgnum)
{
unsigned i;

	if (msgnum)
	{
		if ((i=getmsgnum(msgnum)) != 0)
		{
			printed(printf("+OK %u ", i));
			print_uidl(i-1);
			fflush(stdout);
		}
		return;
	}
	printed(printf("+OK\r\n"));
	for (i=0; i<msglist_cnt; i++)
	{
		if (msglist_a[i]->isdeleted)	continue;
		printed(printf("%u ", i+1));
		print_uidl(i);
	}
	printed(printf(".\r\n"));
	fflush(stdout);
}
示例#10
0
    void Logger::print(const QString &mess, mongo::logger::LogSeverity level, bool notify)
    {
        // v0.9
//        LOG(level) << "[" PROJECT_NAME_TITLE "] " << QtUtils::toStdString(mess) << std::endl;
        if (notify) {
            // Make uniform log level strings e.g "Error: ", "Info: " etc...
            auto logLevelStr = QString::fromStdString(level.toStringData().toString());
            if (!logLevelStr.isEmpty()) {
                logLevelStr = logLevelStr.toLower();
                logLevelStr[0] = logLevelStr[0].toUpper();
                logLevelStr += ": ";
            }
            emit printed(logLevelStr + mess, level);
        }
    }
示例#11
0
static void do_stat()
{
off_t	n=0;
unsigned i, j;
char	buf[NUMBUFSIZE];

	j=0;
	for (i=0; i<msglist_cnt; i++)
	{
		if (msglist_a[i]->isdeleted)	continue;
		n += msglist_a[i]->size;
		++j;
	}

	printed(printf("+OK %u %s\r\n", j, libmail_str_off_t(n, buf)));
	fflush(stdout);
}
示例#12
0
文件: tree.c 项目: UraKn0x/gbdk
/* printtree - print tree p on fd */
void printtree(Tree p, int fd) {
	(void)printed(0);
	printtree1(p, fd, 1);
}
示例#13
0
static void loop()
{
char	buf[BUFSIZ];
char	*p;
int	c;

	signal(SIGALRM, bye);
	while (alarm(300), fgets(buf, sizeof(buf), stdin))
	{
		bytes_received_count += strlen(buf);

		alarm(0);
		if ((p=strchr(buf, '\n')) != 0)
			*p=0;
		else while ((c=getc(stdin)) >= 0 && c != '\n')
			;
		p=strtok(buf, " \t\r");
		if (!p)	p="";

		mkupper(p);
		if (strcmp(p, "QUIT") == 0)
		{
			printed(printf("+OK Bye-bye.\r\n"));
			fflush(stdout);
			cleanup();
			acctout("INFO: LOGOUT");
			return;
		}

		if (strcmp(p, "STAT") == 0)
		{
			do_stat();
			continue;
		}

		if (strcmp(p, "LIST") == 0)
		{
			do_list(strtok(NULL, " \t\r"));
			continue;
		}

		if (strcmp(p, "RETR") == 0)
		{
		unsigned	i;

			if ((i=getmsgnum(strtok(NULL, " \t\r"))) == 0)
				continue;

			do_retr(i-1, 0);
			continue;
		}

		if (strcmp(p, "CAPA") == 0)
		{
			pop3dcapa();
			continue;
		}

		if (strcmp(p, "DELE") == 0)
		{
		unsigned	i;

			if ((i=getmsgnum(strtok(NULL, " \t\r"))) == 0)
				continue;

			msglist_a[i-1]->isdeleted=1;
			printed(printf("+OK Deleted.\r\n"));
			fflush(stdout);
			continue;
		}

		if (strcmp(p, "NOOP") == 0)
		{
			printed(printf("+OK Yup.\r\n"));
			fflush(stdout);
			continue;
		}

		if (strcmp(p, "RSET") == 0)
		{
		unsigned i;

			for (i=0; i<msglist_cnt; i++)
				msglist_a[i]->isdeleted=0;
			printed(printf("+OK Resurrected.\r\n"));
			fflush(stdout);
			continue;
		}

		if (strcmp(p, "TOP") == 0)
		{
		unsigned	i, j;
		const	char *q;

			if ((i=getmsgnum(strtok(NULL, " \t\r"))) == 0)
				continue;

			q=strtok(NULL, " \t\r");

			if (!q)	goto error;

			j=atoi(q);
			do_retr(i-1, &j);
			continue;
		}

		if (strcmp(p, "UIDL") == 0)
		{
			do_uidl(strtok(NULL, " \t\r"));
			continue;
		}

error:
		printed(printf("-ERR Invalid command.\r\n"));
		fflush(stdout);
	}
	acctout("INFO: DISCONNECTED");
}
示例#14
0
static void do_retr(unsigned i, unsigned *lptr)
{
FILE	*f=fopen(msglist_a[i]->filename, "r");
char	*p;
int	c, lastc='\n';
int	inheader=1;
char	buf[NUMBUFSIZE];
unsigned long *cntr;

	if (!f)
	{
		printed(printf("-ERR Can't open the message file - it's gone!\r\n"));
		fflush(stdout);
		return;
	}
	printed(printf( (lptr ? "+OK headers follow.\r\n":"+OK %s octets follow.\r\n"),
			libmail_str_off_t(msglist_a[i]->size, buf)));

	cntr= &retr_count;
	if (lptr)
		cntr= &top_count;

	for (lastc=0; (c=getc(f)) >= 0; lastc=c)
	{
		if (lastc == '\n')
		{
			if (lptr)
			{
				if (inheader)
				{
					if (c == '\n')	inheader=0;
				}
				else if ( (*lptr)-- == 0)	break;
			}

			if (c == '.')
				printchar('.');
		}
		if (c == '\n')	printchar('\r');
		printchar(c);
		++*cntr;
	}
	if (ferror(f)) {
		/* Oops! All we can do is drop the connection */
		fprintf(stderr, "ERR: I/O error while reading message file %s: %s\n",
			msglist_a[i]->filename, strerror(errno));
		acctout("INFO: I/O error disconnect");
		exit(1);
	}
	if (lastc != '\n')	printed(printf("\r\n"));
	printed(printf(".\r\n"));
	fflush(stdout);
	fclose(f);
	if (lptr)	return;

	if ((p=strchr(msglist_a[i]->filename, MDIRSEP[0])) != 0 &&
		(p[1] != '2' || p[2] != ',' || strchr(p, 'S') != 0))
		return;

	if ((p=malloc(strlen(msglist_a[i]->filename)+5)) == 0)
		return;

	strcpy(p, msglist_a[i]->filename);
	if (strchr(p, MDIRSEP[0]) == 0)	strcat(p, MDIRSEP "2,");
	strcat(p, "S");

	if (lptr	/* Don't mark as seen for TOP */
	    || rename(msglist_a[i]->filename, p))
	{
		free(p);
		return;
	}
	free(msglist_a[i]->filename);
	msglist_a[i]->filename=p;
}
示例#15
0
int main(int argc, char **argv)
{
char	*p;

#ifdef HAVE_SETVBUF_IOLBF
	setvbuf(stderr, NULL, _IOLBF, BUFSIZ);
#endif
	time(&start_time);

	if ((authaddr=getenv("AUTHADDR")) == NULL ||
	    *authaddr == 0)
	{
		authaddr=getenv("AUTHENTICATED");
		if (authaddr == NULL || *authaddr == 0)
			authaddr="nobody";
	}

	if ((remoteip=getenv("TCPREMOTEIP")) == NULL)
		remoteip="127.0.0.1";

	if ((remoteport=getenv("TCPREMOTEPORT")) == NULL)
		remoteport="0";

	{
	struct	stat	buf;

		if ( stat(".", &buf) < 0 || buf.st_mode & S_ISVTX)
		{
			fprintf(stderr, "INFO: LOCKED, user=%s, ip=[%s], port=[%s]\n",
							authaddr, remoteip, remoteport);
			printed(printf("-ERR Your account is temporarily unavailable (+t bit set on home directory).\r\n"));
			exit(0);
		}
	}

	if (argc > 1)
		p=argv[1];
	else
		p=getenv("MAILDIR");

	if (!p)
		p="./Maildir";

	if (chdir(p))
	{
		fprintf(stderr, "chdir %s: %s\n", p, strerror(errno));
		printed(printf("-ERR chdir %s failed\n", p));
		fflush(stdout);
		exit(1);
	}
	
	maildir_loginexec();

	if (auth_getoptionenvint("disablepop3"))
	{
		printed(printf("-ERR POP3 access disabled for this account.\r\n"));
		fflush(stdout);
		exit(1);
	}

	if (    auth_getoptionenvint("disableinsecurepop3")
	    && ((p=getenv("POP3_TLS")) == NULL || !atoi(p)))
	{
		printed(printf("-ERR POP3 access disabled via insecure connection.\r\n"));
		fflush(stdout);
		exit(1);
	}

	fprintf(stderr, "INFO: LOGIN, user=%s, ip=[%s], port=[%s]\n",
			authaddr,
					remoteip,
					remoteport);
	fflush(stderr);

	msglist_cnt=0;
	msglist_l=0;
	msglist_a=0;
	purgetmp();
	maildir_getnew(".", INBOX, NULL, NULL);
	if (scancur())
	{
		printed(printf("-ERR Maildir invalid (no 'cur' directory)\r\n"));
		return (0);
	}
	sortmsgs();
	printed(printf("+OK logged in.\r\n"));
	fflush(stdout);
	loop();
	return (0);
}
示例#16
0
void ScriptUnit::print(const QString &message)
{
    emit printed(message);
}