示例#1
0
static void
test_simple (TestCase *tc,
             gconstpointer unused)
{
  CockpitPortal *portal;
  GBytes *sent;

  portal = mock_portal_simple_new (tc->transport, mock_filter_upper, "--upper");

  /* Connect to fallback implementation */
  g_signal_connect (tc->transport, "control", G_CALLBACK (on_transport_control), tc);

  /* The filter should ignore this */
  emit_string (tc, NULL, "{\"command\": \"hello\"}");

  emit_string (tc, NULL, "{\"command\": \"open\", \"channel\": \"a\", \"payload\": \"upper\"}");
  emit_string (tc, "a", "oh marmalade");

  while ((sent = mock_transport_pop_channel (tc->transport, "a")) == NULL)
    g_main_context_iteration (NULL, TRUE);

  cockpit_assert_bytes_eq (sent, "OH MARMALADE", -1);

  /* The fallback channel was not created */
  g_assert (tc->channel == NULL);

  g_object_unref (portal);
}
示例#2
0
/* --- entry point --- */
static int cstruct_chardef(chardef *cp, FILE *fp, int col1)
{
    /* ------------------------------------------------------------
    Allocations and Declarations
    ------------------------------------------------------------ */
    /* field within output line */
    char    field[64];
    /* ------------------------------------------------------------
    emit   charnum, location, name  /  hirow, hicol,  lorow, locol
    ------------------------------------------------------------ */
    /* --- charnum, location, name --- */
    /*char#,location*/
    sprintf(field, "{ %3d,%5d,\n", cp->charnum, cp->location);
    emit_string(fp, col1, field, "character number, location");
    /* --- toprow, topleftcol,   botrow, botleftcol  --- */
    sprintf(field, "  %3d,%2d,  %3d,%2d,\n",    /* format... */
            cp->toprow, cp->topleftcol,           /* toprow, topleftcol, */
            /* and botrow, botleftcol */
            cp->botrow, cp->botleftcol);
    emit_string(fp, col1, field, "topleft row,col, and botleft row,col");
    /* ------------------------------------------------------------
    emit raster and chardef's closing brace, and then return to caller
    ------------------------------------------------------------ */
    /* emit raster */
    cstruct_raster(&cp->image, fp, col1 + 4);
    /* emit closing brace */
    emit_string(fp, 0, "  }", NULL);
    /* back to caller with 1=okay, 0=failed */
    return (1);
} /* --- end-of-function cstruct_chardef() --- */
示例#3
0
static void
test_failover (TestCase *tc,
               gconstpointer unused)
{
  CockpitPortal *portal;
  GBytes *sent;

  portal = mock_portal_failover_new (tc->transport, mock_filter_lower, "--lower");

  /* The filter should ignore this */
  emit_string (tc, NULL, "{\"command\": \"hello\"}");

  emit_string (tc, NULL, "{\"command\": \"open\", \"channel\": \"a\", \"payload\": \"lower\"}");
  emit_string (tc, "a", "Oh Marmalade");

  while ((sent = mock_transport_pop_channel (tc->transport, "a")) == NULL)
    g_main_context_iteration (NULL, TRUE);

  cockpit_assert_bytes_eq (sent, "oh marmalade", -1);

  /* The fallback channel was not created */
  g_assert (tc->channel == NULL);

  g_object_unref (portal);
}
示例#4
0
static void
test_fallback (TestCase *tc,
               gconstpointer unused)
{
  CockpitPortal *portal;
  GBytes *sent;

  portal = mock_portal_fail_new (tc->transport, mock_filter_upper_fallback);

  /* Connect to fallback implementation */
  g_signal_connect (tc->transport, "control", G_CALLBACK (on_transport_control), tc);

  emit_string (tc, NULL, "{\"command\": \"open\", \"channel\": \"a\", \"payload\": \"upper\"}");
  emit_string (tc, "a", "Oh MarmaLade");

  while ((sent = mock_transport_pop_channel (tc->transport, "a")) == NULL)
    g_main_context_iteration (NULL, TRUE);

  /* The fallback just echos */
  cockpit_assert_bytes_eq (sent, "Oh MarmaLade", -1);

  /* The fallback channel was created */
  g_assert (tc->channel != NULL);

  g_object_unref (portal);
}
示例#5
0
/* --- entry point --- */
static int cstruct_raster(raster *rp, FILE *fp, int col1)
{
    /* ------------------------------------------------------------
    Allocations and Declarations
    ------------------------------------------------------------ */
    /* field within output line */
    char    field[64];
    /* type cast for pixmap string */
    char    typecast[64] = "(pixbyte *)";
    /* to emit raster bitmap */
    int hex_bitmap();
    /* emit a string and comment */
    int emit_string();
    /* ------------------------------------------------------------
    emit width and height
    ------------------------------------------------------------ */
    sprintf(field, "{ %2d,  %3d,%2d,%2d, %s\n", /* format width,height,pixsz */
            rp->width, rp->height, rp->format, rp->pixsz, typecast);
    emit_string(fp, col1, field, "width,ht, fmt,pixsz,map...");
    /* ------------------------------------------------------------
    emit bitmap and closing brace, and return to caller
    ------------------------------------------------------------ */
    /* emit bitmap */
    hex_bitmap(rp, fp, col1 + 2, 1);
    /* emit closing brace */
    emit_string(fp, 0, " }", NULL);
    /* back to caller with 1=okay, 0=failed */
    return (1);
} /* --- end-of-function cstruct_raster() --- */
示例#6
0
static void DumpVisitor_visitLoopStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt)
{
	DUMPER(self)->indent++;
	emit_string("Loop", "", "", DUMPER(self)->indent - 1);
	handleExpr(kctx, self, Stmt_getFirstExpr(kctx, stmt));
	emit_string("Body", "", "", DUMPER(self)->indent - 1);
	visitBlock(kctx, self, Stmt_getFirstBlock(kctx, stmt));
	DUMPER(self)->indent--;
}
示例#7
0
static void DumpVisitor_visitIfStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt)
{
	DUMPER(self)->indent++;
	emit_string("If", "", "", DUMPER(self)->indent - 1);
	handleExpr(kctx, self, Stmt_getFirstExpr(kctx, stmt));
	emit_string("Then", "", "", DUMPER(self)->indent - 1);
	visitBlock(kctx, self, Stmt_getFirstBlock(kctx, stmt));
	emit_string("Else", "", "", DUMPER(self)->indent - 1);
	visitBlock(kctx, self, Stmt_getElseBlock(kctx, stmt));
	DUMPER(self)->indent--;
}
示例#8
0
static void DumpVisitor_visitLetExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	DUMPER(self)->indent++;
	emit_string("LET ", "", "", DUMPER(self)->indent);
	DUMPER(self)->indent++;
	handleExpr(kctx, self, kExpr_at(expr, 1));
	emit_string(":=", "", "", DUMPER(self)->indent);
	handleExpr(kctx, self, kExpr_at(expr, 2));
	DUMPER(self)->indent--;
	DUMPER(self)->indent--;
}
示例#9
0
文件: wisdom.c 项目: dskinner/sndobj
static void emit_int(int n, void *data)
{
     char buf[128];

     sprintf(buf, "%d", n);
     emit_string(buf, data);
}
示例#10
0
static void DumpVisitor_visitLocalExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	char buf[128];
	snprintf(buf, 128, "LOCAL(%d, %s)", (int)expr->index, CT_t(CT_(expr->ty)));
	emit_string(buf, "", "", DUMPER(self)->indent);

}
示例#11
0
文件: if.c 项目: cglinden/autocook
static void
emit(stmt_ty *that)
{
    stmt_if_ty      *this;
    size_t          j;

    trace(("if::emit()\n{\n"));
    this = (stmt_if_ty *)that;
    emit_line_number
    (
        this->condition->list[0]->line_number,
        this->condition->list[0]->file_name
    );
    emit_str("#if");
    for (j = 0; j < this->condition->length; ++j)
    {
        emit_char(' ');
        emit_string(this->condition->list[j]->text);
    }
    emit_char('\n');

    stmt_emit(this->then_clause);
    emit_bol();

    if (this->else_clause)
    {
        emit_str("#else\n");
        stmt_emit(this->else_clause);
        emit_bol();
    }
    emit_str("#endif\n");
    trace(("}\n"));
}
示例#12
0
文件: wisdom.c 项目: dskinner/sndobj
/* dump wisdom in lisp-like format */
void fftw_export_wisdom(void (*emitter) (char c, void *), void *data)
{
     struct wisdom *p;

     /* install the output handler */
     emit = emitter;

     emit('(', data);
     emit_string(WISDOM_FORMAT_VERSION, data);

     for (p = wisdom_list; p; p = p->next) {
	  emit(' ', data);	/* separator to make the output nicer */
	  emit('(', data);
	  emit_int((int) p->n, data);
	  emit(' ', data);
	  emit_int((int) p->flags, data);
	  emit(' ', data);
	  emit_int((int) p->dir, data);
	  emit(' ', data);
	  emit_int((int) p->category, data);
	  emit(' ', data);
	  emit_int((int) p->istride, data);
	  emit(' ', data);
	  emit_int((int) p->ostride, data);
	  emit(' ', data);
	  emit_int((int) p->type, data);
	  emit(' ', data);
	  emit_int((int) p->signature, data);
	  emit(' ', data);
	  emit_int((int) p->recurse_kind, data);
	  emit(')', data);
     }
     emit(')', data);
}
示例#13
0
static void DumpVisitor_visitReturnStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt)
{
	emit_string("Return", "", "", DUMPER(self)->indent);
	kExpr* expr = Stmt_getFirstExpr(kctx, stmt);
	if(expr != NULL && IS_Expr(expr)) {
		handleExpr(kctx, self, expr);
	}
}
示例#14
0
static void DumpVisitor_visitCallExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	KGrowingBuffer wb;
	KLIB Kwb_init(&(kctx->stack->cwb), &wb);
	kMethod *mtd = CallExpr_getMethod(expr);
	KLIB Kwb_printf(kctx, &wb, "CALL: '%s%s'", T_mn(mtd->mn));
	DUMPER(self)->indent++;
	emit_string(KLIB Kwb_top(kctx, &wb, 1), "(", "", DUMPER(self)->indent);
	DUMPER(self)->indent++;
	unsigned i;
	for (i = 1; i < kArray_size(expr->cons); ++i) {
		handleExpr(kctx, self, kExpr_at(expr, i));
	}
	DUMPER(self)->indent--;
	emit_string(")", "", "", DUMPER(self)->indent);
	DUMPER(self)->indent--;
	KLIB Kwb_free(&wb);
}
示例#15
0
static void DumpVisitor_visitOrExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	unsigned i;
	emit_string("OR", "", "", DUMPER(self)->indent);
	DUMPER(self)->indent++;
	for (i = 1; i < kArray_size(expr->cons); ++i) {
		handleExpr(kctx, self, kExpr_at(expr, i));
	}
	DUMPER(self)->indent--;
}
示例#16
0
void save_yank(FILE *f)
{
	UNDOREC *rec;
	for (rec = yanked.link.next; rec != &yanked; rec = rec->link.next) {
		if (rec->len < SMALL) {
			fprintf(f,"	");
			emit_string(f,rec->small,rec->len);
			fprintf(f,"\n");
		}
	}
	fprintf(f,"done\n");
}
示例#17
0
static void
test_fail (TestCase *tc,
           gconstpointer unused)
{
  CockpitPortal *portal;
  JsonObject *sent;

  portal = mock_portal_fail_new (tc->transport, mock_filter_lower);

  emit_string (tc, NULL, "{\"command\": \"open\", \"channel\": \"a\", \"payload\": \"lower\"}");
  emit_string (tc, "a", "Oh Marmalade");

  while ((sent = mock_transport_pop_control (tc->transport)) == NULL)
    g_main_context_iteration (NULL, TRUE);

  cockpit_assert_json_eq (sent, "{\"command\":\"close\",\"channel\":\"a\",\"problem\":\"not-supported\"}");

  /* The fallback channel was not created */
  g_assert (tc->channel == NULL);

  g_object_unref (portal);
}
示例#18
0
static void DumpVisitor_visitConstExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	KGrowingBuffer wb;
	KLIB Kwb_init(&(kctx->stack->cwb), &wb);
	KonohaStack sfp[1];
	kObject *obj = expr->objectConstValue;
	sfp[0].asObject = obj;
	O_ct(obj)->p(kctx, sfp, 0, &wb, 0);
	char  *str = (char *) KLIB Kwb_top(kctx, &wb, 0);
	char buf[128];
	snprintf(buf, 128, "CONST:%s:'%s'", CT_t(O_ct(obj)), str);
	emit_string(buf, "", "", DUMPER(self)->indent);
	KLIB Kwb_free(&wb);
}
示例#19
0
static void DumpVisitor_visitNConstExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	KGrowingBuffer wb;
	KLIB Kwb_init(&(kctx->stack->cwb), &wb);
	KonohaStack sfp[1];
	unsigned long unboxVal = expr->unboxConstValue;
	KonohaClass *ct = CT_(expr->ty);
	sfp[0].unboxValue = unboxVal;
	ct->p(kctx, sfp, 0, &wb, 0);
	char  *str = (char *) KLIB Kwb_top(kctx, &wb, 0);
	char buf[128];
	snprintf(buf, 128, "NCONST:'%s'", str);
	emit_string(buf, "", "", DUMPER(self)->indent);
	KLIB Kwb_free(&wb);
}
示例#20
0
static void DumpVisitor_init(KonohaContext *kctx, struct IRBuilder *builder, kMethod *mtd)
{
	unsigned i;
	KGrowingBuffer wb;
	KLIB Kwb_init(&(kctx->stack->cwb), &wb);
	kParam *pa = Method_param(mtd);
	KLIB Kwb_printf(kctx, &wb, "METHOD %s%s(", T_mn(mtd->mn));
	for (i = 0; i < pa->psize; i++) {
		if(i != 0) {
			KLIB Kwb_write(kctx, &wb, ", ", 2);
		}
		KLIB Kwb_printf(kctx, &wb, "%s %s", TY_t(pa->paramtypeItems[i].ty), SYM_t(pa->paramtypeItems[i].fn));
	}
	emit_string(KLIB Kwb_top(kctx, &wb, 1), "", ") {", 0);
	builder->local_fields = (void *) KMalloc_UNTRACE(sizeof(int));
	DUMPER(builder)->indent = 0;
}
示例#21
0
int Plotter::label(const char *s)
{
	char *t;
	bool was_clean;

	// copy since we may alter the string
	t = (char *) malloc(strlen(s) + 1);
	if (!t) {
		(*errstream) << "ERROR: Can't allocate memory" << endl;
		return 0;
	}
	strcpy_s(t,strlen(s), s);
	was_clean = clean_iso_string((unsigned char *) t);
	if (!was_clean)
		(*errstream) << "libplot: ignoring control character (e.g. CR or LF) in label" << endl;

	emit_byte((int) O_LABEL);
	emit_string(t);
	free(t);

	return 0;
}
示例#22
0
static void DumpVisitor_visitNullExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	char buf[128];
	snprintf(buf, 128, "%s.NULL", CT_t(CT_(expr->ty)));
	emit_string(buf, "", "", DUMPER(self)->indent);
}
示例#23
0
void emit_expr(ivl_scope_t scope, ivl_expr_t expr, unsigned wid)
{
      switch (ivl_expr_type(expr)) {
	case IVL_EX_ARRAY:
	    emit_expr_array(scope, expr, wid);
	    break;
	case IVL_EX_BINARY:
	    emit_expr_binary(scope, expr, wid);
	    break;
	case IVL_EX_CONCAT:
	    emit_expr_concat(scope, expr, wid);
	    break;
	case IVL_EX_DELAY:
	    emit_expr_delay(scope, expr, wid);
	    break;
	case IVL_EX_ENUMTYPE:
	    fprintf(vlog_out, "<enum>");
	    fprintf(stderr, "%s:%u: vlog95 error: Enum expressions "
	                    "are not supported.\n",
	                    ivl_expr_file(expr),
	                    ivl_expr_lineno(expr));
	    vlog_errors += 1;
	    break;
	case IVL_EX_EVENT:
	    emit_expr_event(scope, expr, wid);
	    break;
	case IVL_EX_NUMBER:
	    emit_number(ivl_expr_bits(expr), ivl_expr_width(expr),
	                ivl_expr_signed(expr), ivl_expr_file(expr),
	                ivl_expr_lineno(expr));
	    break;
	case IVL_EX_REALNUM:
	    emit_real_number(ivl_expr_dvalue(expr));
	    break;
	case IVL_EX_SCOPE:
	    emit_expr_scope(scope, expr, wid);
	    break;
	case IVL_EX_SELECT:
	    emit_expr_select(scope, expr, wid);
	    break;
	case IVL_EX_SFUNC:
	    fprintf(vlog_out, "%s", ivl_expr_name(expr));
	    emit_expr_func(scope, expr, wid);
	    break;
	case IVL_EX_SIGNAL:
	    emit_expr_signal(scope, expr, wid);
	    break;
	case IVL_EX_STRING:
	    emit_string(ivl_expr_string(expr));
	    break;
	case IVL_EX_TERNARY:
	    emit_expr_ternary(scope, expr, wid);
	    break;
	case IVL_EX_UFUNC:
	    emit_scope_path(scope, ivl_expr_def(expr));
	    emit_expr_func(scope, expr, wid);
	    break;
	case IVL_EX_UNARY:
	    emit_expr_unary(scope, expr, wid);
	    break;
	default:
	    fprintf(vlog_out, "<unknown>");
	    fprintf(stderr, "%s:%u: vlog95 error: Unknown expression "
	                    "type (%d).\n",
	                    ivl_expr_file(expr),
	                    ivl_expr_lineno(expr),
	                    (int)ivl_expr_type(expr));
	    vlog_errors += 1;
	    break;
      }
}
示例#24
0
static void DumpVisitor_visitFieldExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	emit_string("FIELD", "", "", DUMPER(self)->indent);
}
示例#25
0
static void DumpVisitor_visitBlockExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	emit_string("BLOCK", "", "", DUMPER(self)->indent);
	visitBlock(kctx, self, expr->block);
}
示例#26
0
static void DumpVisitor_visitErrStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt)
{
	emit_string(S_text(kStmt_getObjectNULL(kctx, stmt, KW_ERR)), "", "", DUMPER(self)->indent);
}
示例#27
0
static void DumpVisitor_visitStackTopExpr(KonohaContext *kctx, IRBuilder *self, kExpr *expr)
{
	emit_string("STACKTOP", "", "", DUMPER(self)->indent);
}
示例#28
0
void DumpVisitor_free(KonohaContext *kctx, struct IRBuilder *builder, kMethod *mtd)
{
	emit_string("}", "", "", 0);
	KFree(builder->local_fields, sizeof(int));
}
示例#29
0
int Plotter::linemod(const char *s)
{
	emit_byte((int) O_LINEMOD);
	emit_string(s);
	return 0;
}
示例#30
0
static void DumpVisitor_visitUndefinedStmt(KonohaContext *kctx, IRBuilder *self, kStmt *stmt)
{
	emit_string("UNDEF", "", "", DUMPER(self)->indent);
}