コード例 #1
0
ファイル: file.c プロジェクト: nielssp/ctodo
void write_todolist(STREAM *output, TODOLIST *todolist) {
  OPTION *opt = NULL;
  TASK *task = NULL;
  int width = 0;
  stream_printf(output, "%s\n", todolist->title);
  task = todolist->first;
  while (task) {
    stream_printf(output, "[%c] %s\n",
        task->done ? 'X' : ' ', task->message);
    task = task->next;
  }
  opt = todolist->first_option;
  if (opt) {
    width += stream_printf(output, "#");
    while (opt) {
      if (width >= 80) {
        stream_printf(output, "\n#");
        width = 1;
      }
      width += 2;
      stream_putc(' ', output);
      width += escape_string(output, opt->key);
      stream_putc('=', output);
      width += escape_string(output, opt->value);
      opt = opt->next;
    }
    stream_printf(output, "\n");
  }
}
コード例 #2
0
/**
 * Return information 
 */
static void _dump_events(gds_stream_t * stream, sched_t * self)
{
  sched_static_t * sched= (sched_static_t *) self;
  _event_t * event;
  uint32_t depth;
  uint32_t max_depth;
  uint32_t start;
  unsigned int index;

  depth= sched->events->current_depth;
  max_depth= sched->events->max_depth;
  start= sched->events->start_index;
  stream_printf(stream, "Number of events queued: %u (%u)\n",
	     depth, max_depth);
  for (index= 0; index < depth; index++) {
    event= (_event_t *) sched->events->items[(start+index) % max_depth];
    stream_printf(stream, "(%d) ", (start+index) % max_depth);
    stream_flush(stream);
    if (event->ops->dump != NULL) {
      event->ops->dump(stream, event->ctx);
    } else {
      stream_printf(stream, "unknown");
    }
    stream_printf(stream, "\n");
  }
}
コード例 #3
0
ファイル: ipip.c プロジェクト: KTrel/c-bgp_updated
// -----[ _ipip_proto_dump_msg ]-------------------------------------
static void _ipip_proto_dump_msg(gds_stream_t * stream, net_msg_t * msg)
{
  net_msg_t * encap_msg= (net_msg_t *) msg->payload;
  stream_printf(stream, "msg:[");
  message_dump(stream, encap_msg);
  stream_printf(stream, "]");
}
コード例 #4
0
ファイル: as-level.c プロジェクト: gvsurenderreddy/cbgp
// -----[ aslevel_perror ]-------------------------------------------
void aslevel_perror(gds_stream_t * stream, int error)
{
  char * error_msg= aslevel_strerror(error);
  if (error_msg != NULL)
    stream_printf(stream, error_msg);
  else
    stream_printf(stream, "unknown error (%i)", error);
}
コード例 #5
0
ファイル: error.c プロジェクト: gvsurenderreddy/cbgp
/**
 * Dump an error message for the given error code.
 */
void network_perror(gds_stream_t * stream, int error)
{
  const char * error_msg= network_strerror(error);
  if (error_msg != NULL)
    stream_printf(stream, error_msg);
  else
    stream_printf(stream, "unknown error (%i)", error);    
}
コード例 #6
0
ファイル: route-input.c プロジェクト: KTrel/c-bgp_updated
// -----[ bgp_input_perror ]-----------------------------------------
void bgp_input_perror(gds_stream_t * stream,
		      bgp_input_error_t error)
{
  const char * msg= bgp_input_strerror(error);
  if (msg != NULL)
    stream_printf(stream, "%s", msg);
  else
    stream_printf(stream, "unknown error code (%d)", error);
}
コード例 #7
0
ファイル: iface.c プロジェクト: gvsurenderreddy/cbgp
// -----[ net_iface_dump ]-------------------------------------------
void net_iface_dump(gds_stream_t * stream, net_iface_t * iface, int with_dest)
{
  net_iface_dump_type(stream, iface);
  stream_printf(stream, "\t");
  net_iface_dump_id(stream, iface);
  if (with_dest) {
    stream_printf(stream, "\t");
    net_iface_dump_dest(stream, iface);
  }
}
コード例 #8
0
ファイル: gsasl.c プロジェクト: baohaojun/dico
static void
send_challenge(dico_stream_t str, char *data)
{
    if (data[0]) { 
	 stream_printf(str, "130 challenge follows\n");
	 /* FIXME: use dicod_ostream_create */
	 stream_writez(str, data);
	 stream_writez(str, "\n.\n");
    }
    stream_printf(str, "330 send response\n");
}    
コード例 #9
0
ファイル: target.c プロジェクト: apoelstra/RamseyScript
void target_usage (stream_t *out)
{
  int i;
  stream_printf (out,
    "Usage: \n"
    "  target clear     Remove all targets\n"
    "  target <target>  Add a target\n"
    "\n"
    "Available targets:\n");
  for (i = 0; i < g_n_targets; ++i)
    stream_printf (out, "  %20s  %s\n", g_target[i].name, g_target[i].help);
}
コード例 #10
0
ファイル: filter.c プロジェクト: apoelstra/RamseyScript
void filter_usage (stream_t *out)
{
  int i;
  stream_printf (out,
    "Usage: \n"
    "  filter clear      Remove all filters\n"
    "  filter <filter>   Add a filter\n"
    "\n"
    "Available filters:\n");
  for (i = 0; i < g_n_filters; ++i)
    stream_printf (out, "  %20s  %s\n", g_filter[i].name, g_filter[i].help);
}
コード例 #11
0
static void _set_log_progress(sched_t * self, const char * filename)
{
  sched_static_t * sched= (sched_static_t *) self;

  if (sched->pProgressLogStream != NULL)
    stream_destroy(&sched->pProgressLogStream);

  if (filename != NULL) {
    sched->pProgressLogStream= stream_create_file(filename);
    stream_printf(sched->pProgressLogStream, "# C-BGP Queue Progress\n");
    stream_printf(sched->pProgressLogStream, "# <step> <time (us)> <depth>\n");
  }
}
コード例 #12
0
ファイル: markup.c プロジェクト: baohaojun/dico
static void
dicod_markup(dico_stream_t str, int argc, char **argv)
{
    const char *p;
    if (argc == 2) {
        /* Report current markup type */
        stream_printf(str, "280 %s is current markup type\n",
                      dico_markup_type);
    } else if ((p = dico_markup_lookup(argv[2]))) {
        dico_markup_type = p;
        stream_printf(str, "250 markup type set to %s\n", dico_markup_type);
    } else
        stream_writez(str, "500 invalid argument\n");
}
コード例 #13
0
ファイル: net.c プロジェクト: gvsurenderreddy/cbgp
static int _net_flow_src_ip_handler(flow_t * flow, flow_field_map_t * map,
				    void * ctx)
{
  flow_stats_t * stats= (flow_stats_t *) ctx;
  ip_trace_t * trace= NULL;
  net_error_t result;
  ip_opt_t opts;

  net_node_t * src_node= network_find_node(network_get_default(), flow->src_addr);
  if (src_node == NULL) {
    printf("Source node not found\n");
    return -1;
  }

  ip_options_init(&opts);
  if (flow_field_map_isset(map, FLOW_FIELD_DST_MASK)) {
    ip_pfx_t pfx= {
      .network=flow->dst_addr,
      .mask=flow->dst_mask,
    };
    ip_options_alt_dest(&opts, pfx);
  }

  result= node_load_flow(src_node, NET_ADDR_ANY, flow->dst_addr, flow->bytes,
			 stats, &trace, &opts);
  if (result < 0)
    return 0;

  if (trace != NULL) {
    stream_printf(gdsout, "TRACE=[");
    ip_trace_dump(gdsout, trace, 0);
    stream_printf(gdsout, "]\n");
    ip_trace_destroy(&trace);
  }
  return 0;
}

static int _net_flow_src_asn_handler(flow_t * flow, flow_field_map_t * map,
				     void * ctx)
{
  // Find source based on source ASN
  as_level_topo_t * topo= aslevel_get_topo();
  if (topo == NULL) {
    printf("no AS-level topology loaded\n");
    return -1;
  }
  flow->src_addr= topo->addr_mapper(flow->src_asn);
  return _net_flow_src_ip_handler(flow, map, ctx);
}
コード例 #14
0
ファイル: net_node_iface.c プロジェクト: gvsurenderreddy/cbgp
/**
 * context: {iface}
 * tokens: {}
 */
static int cli_iface_load_show(cli_ctx_t * ctx, cli_cmd_t * cmd)
{
  net_iface_t * iface= _iface_from_context(ctx);
  net_link_dump_load(gdsout, iface);
  stream_printf(gdsout, "\n");
  return CLI_SUCCESS;
}
コード例 #15
0
ファイル: unparse.c プロジェクト: welterde/NuMOO
static void
unparse_stmt_catch(Stream * str, struct Stmt_Catch catchstmt, int indent)
{
    Except_Arm *ex;

    stream_add_string(str, "try");
    output(str);
    unparse_stmt(catchstmt.body, indent + 2);
    for (ex = catchstmt.excepts; ex; ex = ex->next) {
	indent_stmt(str, indent);
	stream_add_string(str, "except ");
	if (ex->id >= 0)
	    stream_printf(str, "%s ", prog->var_names[ex->id]);
	stream_add_char(str, '(');
	if (ex->codes)
	    unparse_arglist(str, ex->codes);
	else
	    stream_add_string(str, "ANY");
	stream_add_char(str, ')');
	output(str);
	unparse_stmt(ex->stmt, indent + 2);
    }
    indent_stmt(str, indent);
    stream_add_string(str, "endtry");
    output(str);
}
コード例 #16
0
enum proto_accept_error
proto_accept_connection(int listener_fd, int *read_fd, int *write_fd,
			const char **name)
{
    int timeout = server_int_option("name_lookup_timeout", 5);
    int fd;
    struct sockaddr_in address;
    size_t addr_length = sizeof(address);
    static Stream *s = 0;

    if (!s)
	s = new_stream(100);

    fd = accept(listener_fd, (struct sockaddr *) &address, &addr_length);
    if (fd < 0) {
	if (errno == EMFILE)
	    return PA_FULL;
	else {
	    log_perror("Accepting new network connection");
	    return PA_OTHER;
	}
    }
    *read_fd = *write_fd = fd;
    stream_printf(s, "%s, port %d",
		  lookup_name_from_addr(&address, timeout),
		  (int) ntohs(address.sin_port));
    *name = reset_stream(s);
    return PA_OKAY;
}
コード例 #17
0
ファイル: node.c プロジェクト: gvsurenderreddy/cbgp
// -----[ _node_netflow_handler ]------------------------------------
static int _node_netflow_handler(flow_t * flow, flow_field_map_t * map,
				 void * context)
{
  _netflow_ctx_t * ctx= (_netflow_ctx_t *) context;
  net_node_t * node= ctx->target_node;
  ip_trace_t * trace;

  if (ctx->options & NET_NODE_NETFLOW_OPTIONS_DETAILS) {
    stream_printf(gdsout, "src:");
    ip_address_dump(gdsout, flow->src_addr);
    stream_printf(gdsout, " dst:");
    ip_address_dump(gdsout, flow->dst_addr);
    if (flow_field_map_isset(map, FLOW_FIELD_DST_MASK))
      stream_printf(gdsout, "/%u", flow->dst_mask);
    stream_printf(gdsout, " octets:%u ", flow->bytes);
  }

  if (node_load_flow(node, flow->src_addr, flow->dst_addr,
		     flow->bytes, ctx->stats, &trace, NULL) < 0) {
    if (ctx->options & NET_NODE_NETFLOW_OPTIONS_DETAILS)
      stream_printf(gdsout, "failed\n");
    return NETFLOW_ERROR;
  }

  if (ctx->options & NET_NODE_NETFLOW_OPTIONS_DETAILS) {
    stream_printf(gdsout, "status: ");
    network_perror(gdsout, trace->status);
    stream_printf(gdsout, "\n");
  }

  ip_trace_destroy(&trace);
  return NETFLOW_SUCCESS;
}
コード例 #18
0
ファイル: edit.c プロジェクト: kotuku-aero/diy-efis
void display_message(editor_t *ed, char *fmt, ...)
  {
  gotoxy(ed, 0, ed->lines);
  outstr(ed, STATUS_COLOR);

  stream_printf(ed->console_out, fmt, printf_args, (&fmt)+1);

  outstr(ed, CLREOL TEXT_COLOR);
  }
コード例 #19
0
ファイル: piglatin.c プロジェクト: MrVertinskis/smalltalk
/* Just to show how easy it is to write your own:
   here is specifier function which writes pig latin to a STREAM. */
static void
pig_latin (STREAM *stream, struct printf_info *const pinfo, union printf_arg const *args)
{
  const char *string = args->pa_string;
  int len = strlen (string);

  /* printf extravaganza :-) */
  stream_printf (stream, "%c%.*say", string[len - 1], len - 1, string);
}
コード例 #20
0
enum error
proto_make_listener(Var desc, int *fd, Var * canon, const char **name)
{
    struct sockaddr_in address;
    int s, port, option = 1;
    static Stream *st = 0;

    if (!st)
	st = new_stream(20);

    if (desc.type != TYPE_INT)
	return E_TYPE;

    port = desc.v.num;
    s = socket(AF_INET, SOCK_STREAM, 0);
    if (s < 0) {
	log_perror("Creating listening socket");
	return E_QUOTA;
    }
    if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
		   (char *) &option, sizeof(option)) < 0) {
	log_perror("Setting listening socket options");
	close(s);
	return E_QUOTA;
    }
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = bind_local_ip;
    address.sin_port = htons(port);
    if (bind(s, (struct sockaddr *) &address, sizeof(address)) < 0) {
	enum error e = E_QUOTA;

	log_perror("Binding listening socket");
	if (errno == EACCES)
	    e = E_PERM;
	close(s);
	return e;
    }
    if (port == 0) {
	size_t length = sizeof(address);

	if (getsockname(s, (struct sockaddr *) &address, &length) < 0) {
	    log_perror("Discovering local port number");
	    close(s);
	    return E_QUOTA;
	}
	canon->type = TYPE_INT;
	canon->v.num = ntohs(address.sin_port);
    } else
	*canon = var_ref(desc);

    stream_printf(st, "port %d", canon->v.num);
    *name = reset_stream(st);

    *fd = s;
    return E_NONE;
}
コード例 #21
0
ファイル: node.c プロジェクト: gvsurenderreddy/cbgp
// ----- node_links_save --------------------------------------------
void node_links_save(gds_stream_t * stream, net_node_t * node)
{
  gds_enum_t * ifaces= net_links_get_enum(node->ifaces);
  net_iface_t * iface;

  while (enum_has_next(ifaces)) {
    iface= *((net_iface_t **) enum_get_next(ifaces));
  
    // Skip tunnels
    if ((iface->type == NET_IFACE_VIRTUAL) ||
	(iface->type == NET_IFACE_LOOPBACK))
      continue;
  
    // This side of the link
    ip_address_dump(stream, node->rid);
    stream_printf(stream, "\t");
    net_iface_dump_id(stream, iface);
    stream_printf(stream, "\t");

    // Other side of the link
    switch (iface->type) {
    case NET_IFACE_RTR:
      ip_address_dump(stream, iface->dest.iface->owner->rid);
      stream_printf(stream, "\t");
      ip_address_dump(stream, node->rid);
      stream_printf(stream, "/32");
      break;
    case NET_IFACE_PTP:
      ip_address_dump(stream, iface->dest.iface->owner->rid);
      stream_printf(stream, "\t");
      ip_address_dump(stream, node->rid);
      stream_printf(stream, "/32");      
      break;
    case NET_IFACE_PTMP:
      ip_prefix_dump(stream, iface->dest.subnet->prefix);
      stream_printf(stream, "\t---");
      break;
    default:
      abort();
    }

    // Link load
    stream_printf(stream, "\t%u", iface->phys.load);
    stream_printf(stream, "\t%u\n", iface->phys.capacity);
  }
    
  enum_destroy(&ifaces);
}
コード例 #22
0
ファイル: fork.c プロジェクト: apoelstra/RamseyScript
static int _target_record (data_collector_t *dc, const ramsey_t *ram, stream_t *out)
{
  long depth = ram->get_length (ram);
  struct _target_priv *priv = (struct _target_priv *) dc;

  (void) out;

  assert (dc != NULL);
  assert (ram != NULL);

  if (out && depth == priv->fork_depth)
    {
      stream_printf (out, "search %ss ", ram->get_type (ram));
      ram->print (ram, out);
      stream_printf (out, "\n");
      return 1;
    }
  return 0;
}
コード例 #23
0
ファイル: file.c プロジェクト: nielssp/ctodo
char *stringify_todolist(TODOLIST *todolist) {
  size_t size = 100;
  char *str = (char *)malloc(size);
  STREAM *output = stream_buffer(str, size);
  write_todolist(output, todolist);
  stream_printf(output, "\0");
  str = stream_get_content(output);
  stream_close(output);
  return str;
}
コード例 #24
0
ファイル: serial.c プロジェクト: cjeustis/senior-project
/* Function called by printf to send data to created stream */
int stream_printf(unsigned char var, FILE *stream) {
    if (var == '\n') 
    {
        stream_printf('\r', 0);                 // Translate \n to \r for terminal
    }

    usart_transmit(var);                        // Transmit data
    
    return 0;
}
コード例 #25
0
ファイル: net_path.c プロジェクト: KTrel/c-bgp_updated
void net_path_dump(gds_stream_t * stream, net_path_t * path)
{
  unsigned int index;

  for (index= 0; index < uint32_array_size(path); index++) {
    if (index > 0)
      stream_printf(stream, " ");
    ip_address_dump(stream, path->data[index]);
  }
}
コード例 #26
0
ファイル: node.c プロジェクト: gvsurenderreddy/cbgp
void node_info(gds_stream_t * stream, net_node_t * node)
{
  unsigned int index;

  stream_printf(stream, "id       : ");
  ip_address_dump(stream, node->rid);
  stream_printf(stream, "\n");
  stream_printf(stream, "domain   :");
  for (index= 0; index < uint16_array_size(node->domains); index++) {
    stream_printf(stream, " %d", node->domains->data[index]);
  }
  stream_printf(stream, "\n");
  if (node->name != NULL)
    stream_printf(stream, "name     : %s\n", node->name);
  stream_printf(stream, "addresses: ");
  node_addresses_dump(stream, node);
  stream_printf(stream, "\n");
  stream_printf(stream, "latitude : %f\n", node->coord.latitude);
  stream_printf(stream, "longitude: %f\n", node->coord.longitude);
}
コード例 #27
0
ファイル: node.c プロジェクト: gvsurenderreddy/cbgp
/**
 * This function shows the list of interfaces of a given node's, along
 * with their type.
 */
void node_ifaces_dump(gds_stream_t * stream, net_node_t * node)
{
  unsigned int index;
  net_iface_t * iface;

  // Show network interfaces
  for (index= 0; index < net_ifaces_size(node->ifaces); index++) {
    iface= net_ifaces_at(node->ifaces, index);
    net_iface_dump(stream, iface, 0);
    stream_printf(stream, "\n");
  }
}
コード例 #28
0
ファイル: unparse.c プロジェクト: GunioRobot/stunt
static void
unparse_stmt_list(Stream * str, struct Stmt_List list, int indent)
{
    stream_printf(str, "for %s in (", prog->var_names[list.id]);
    unparse_expr(str, list.expr);
    stream_add_char(str, ')');
    output(str);
    unparse_stmt(list.body, indent + 2);
    indent_stmt(str, indent);
    stream_add_string(str, "endfor");
    output(str);
}
コード例 #29
0
ファイル: db_file.c プロジェクト: diatomic-ge/HellCore
static const char *
fmt_verb_name(void *data)
{
    db_verb_handle *h = data;
    static Stream *s = 0;

    if (!s)
	s = new_stream(40);

    stream_printf(s, "#%d:%s", db_verb_definer(*h), db_verb_names(*h));
    return reset_stream(s);
}
コード例 #30
0
ファイル: ipip.c プロジェクト: gvsurenderreddy/cbgp
static inline void ___ipip_debug(const char * msg, ...)
{
#ifdef IPIP_DEBUG
  va_list ap;

  va_start(ap, msg);
  stream_printf(gdsout, "IPIP_DBG::");
  str_format_for_each(gdsout, _debug_for_each, &ap, msg);
  stream_flush(gdsout);
  va_end(ap);
#endif /* IPIP_DEBUG */
}