Exemplo n.º 1
0
int test_write_header()
{
	 struct setec_astronomy_header w_header, r_header;
	 char temp_file[] = TEST_DATA_DIR "temp";

	 
	 init_header(&w_header);
	 init_header(&r_header);

	 create_header(&w_header, DEFAULT_IV_LEN, DEFAULT_SALT_LEN, 
								 DEFAULT_HASH_COUNT, DEFAULT_PASSWORD, DEFAULT_HASH_LEN);
	 
	 test_equals(write_header(&w_header, temp_file), SA_SUCCESS);	 
	 test_equals(read_header(&r_header, temp_file), SA_SUCCESS);
	 
	 test_equals(w_header.salt_len, r_header.salt_len);
	 test_equals(w_header.hash_count, r_header.hash_count);
	 test_equals(w_header.hash_len, w_header.hash_len);
	 test_equals(w_header.iv_len, r_header.iv_len);
	 
	 test_equals(strncmp(w_header.salt, r_header.salt, w_header.salt_len), 0);
	 test_equals(strncmp(w_header.hash, r_header.hash, w_header.hash_len), 0);
	 test_equals(strncmp(w_header.iv, r_header.iv, w_header.iv_len), 0);
	 test_equals(strncmp(w_header.hash, r_header.hash, w_header.hash_len), 0);

	 free_header(&w_header);
	 free_header(&r_header);
	 
	 return 0;
}
Exemplo n.º 2
0
int on_header_field(http_parser *parser, const char *at, size_t len) {
  http_state *st = parser->data;
  if (st->last_header_cb_was_value) {
    if (st->header_cb != NULL) {
      st->header_cb(st);
    }
    st->last_header->next = init_header();
    st->last_header = st->last_header->next;
    st->num_headers++;
    if (st->num_headers > MAX_HEADERS) {
      disconnectAndClean(st->mc);
    }

    st->last_header->field_len = len;
    st->last_header->field = malloc(len + 1);
    memcpy(st->last_header->field, at, len);
    st->last_header->field[len] = '\0';
  } else {
    if (st->headers == NULL) {
      st->headers = init_header();
      st->last_header = st->headers;
    }
    int old_len = st->last_header->field_len;
    st->last_header->field_len += len;
    st->last_header->field = realloc(st->last_header->field, st->last_header->field_len + 1);
    memcpy(st->last_header->field + old_len, at, len);
    st->last_header->field[st->last_header->field_len] = '\0';
  }

  st->last_header_cb_was_value = 0;
  return 0;
}
   static void swap_nodes(const node_ptr &this_node, const node_ptr &other_node)
   {
      if (other_node == this_node)
         return;
      bool this_inited  = inited(this_node);
      bool other_inited = inited(other_node);
      if(this_inited){
         init_header(this_node);
      }
      if(other_inited){
         init_header(other_node);
      }

      node_ptr next_this(NodeTraits::get_next(this_node));
      node_ptr prev_this(NodeTraits::get_previous(this_node));
      node_ptr next_other(NodeTraits::get_next(other_node));
      node_ptr prev_other(NodeTraits::get_previous(other_node));
      //these first two swaps must happen before the other two
      swap_prev(next_this, next_other);
      swap_next(prev_this, prev_other);
      swap_next(this_node, other_node);
      swap_prev(this_node, other_node);

      if(this_inited){
         init(other_node);
      }
      if(other_inited){
         init(this_node);
      }
   }
Exemplo n.º 4
0
static void			*ft_head(int fd, t_header *header)
{
	int			name;
	int			comment;
	t_token		tok;
	char		*str;

	name = 0;
	comment = 0;
	init_header(header);
	while ((tok = next_token(fd, &str)) != END)
		if (tok != ENDLINE)
		{
			if (name == 0 && tok == COMMAND_NAME)
				name += ft_name(fd, header);
			else if (comment == 0 && tok == COMMAND_COMMENT)
				comment += ft_comm(fd, header);
			else
				ft_tok_error(tok, str, NULL, 0);
			free(str);
			if (name == 1 && comment == 1)
				return (header);
		}
	ft_tok_error(tok, str, NULL, 0);
	free(header);
	return (header);
}
Exemplo n.º 5
0
int init(int argc, char **argv, bcf_hdr_t *in, bcf_hdr_t *out)
{
    static struct option loptions[] =
    {
        {"replace",0,0,'r'},
        {"gp-to-gl",0,0,1},
        {0,0,0,0}
    };
    char c;
    while ((c = getopt_long(argc, argv, "?hr",loptions,NULL)) >= 0)
    {
        switch (c) 
        {
            case  1 : mode = GP_TO_GL; break;
            case 'r': drop_source_tag = 1; break;
            case 'h':
            case '?':
            default: error("%s", usage()); break;
        }
    }
    if ( !mode ) mode = GP_TO_GL;

    in_hdr  = in;
    out_hdr = out;

    if ( mode==GP_TO_GL )
        init_header(out_hdr,drop_source_tag?"GP":NULL,BCF_HL_FMT,"##FORMAT=<ID=GL,Number=G,Type=Float,Description=\"Genotype Likelihoods\">");

    return 0;
}
Exemplo n.º 6
0
void addindexfile(SWISH *sw, char *line)
{
    IndexFILE *head = sw->indexlist;
    IndexFILE *indexf = (IndexFILE *) emalloc(sizeof(IndexFILE));

    memset( indexf, 0, sizeof(IndexFILE) );

    indexf->sw = sw;  /* save parent object */
    indexf->line = estrdup(line);
    init_header(&indexf->header);
    indexf->next = NULL;


    /* Add default meta names -- these will be replaced if reading from an index file */
    add_default_metanames(indexf);

    /* Add index to end of list */

    if ( head == NULL )  /* first entry? */
        sw->indexlist = head = indexf;
    else
        head->nodep->next = indexf;  /* point the previous last one to the new last one */
    
    head->nodep = indexf;  /* set the last pointer */
}
Exemplo n.º 7
0
static void init_ite(composite_t *c, occ_t t1, occ_t t2, occ_t t3) {
  init_header(c, mk_ite_tag());
  c->child[0] = t1;
  c->child[1] = t2;
  c->child[2] = t3;
  init_hooks(c);
}
Exemplo n.º 8
0
/*
 * Initialize the "r_info" array
 */
static errr init_r_info(void)
{
	int i;
	errr err;

	/* Init the header */
	init_header(&r_head, z_info->r_max, sizeof(monster_race));

	/* Save a pointer to the parsing function */
	r_head.parse_info_txt = parse_r_info;

	/* Save a pointer to the evaluate power function*/
	r_head.eval_info_post = eval_r_power;

	/* Save a pointer to the text file output function*/
	if (arg_rebalance) r_head.emit_info_txt_index = emit_r_info_index;

	err = init_info("monster", &r_head);

	/* Set the global variables */
	r_info = r_head.info_ptr;
	r_name = r_head.name_ptr;
	r_text = r_head.text_ptr;
	tot_mon_power = 0;
	for (i = 0; i < z_info->r_max; i++) 
	{
		tot_mon_power += r_info[i].power;
	} 

	return (err);
}
Exemplo n.º 9
0
static int write_suspend_image(void)
{
	int error;
	swp_entry_t prev = { 0 };

	init_header();

	if ((error = write_data()))
		goto FreeData;

	if ((error = write_pagedir()))
		goto FreePagedir;

	if ((error = write_header(&prev)))
		goto FreePagedir;

	error = mark_swapfiles(prev);
 Done:
	return error;
 FreePagedir:
	free_pagedir_entries();
 FreeData:
	free_data();
	goto Done;
}
Exemplo n.º 10
0
static int query_get_string_answer(cmd_request_t cmd)
{
	struct booth_site *site;
	struct boothc_header reply;
	char *data;
	int data_len;
	int rv;
	struct booth_transport const *tpt;

	data = NULL;
	init_header(&cl.msg.header, cmd, 0, cl.options, 0, 0, sizeof(cl.msg));

	if (!*cl.site)
		site = local;
	else if (!find_site_by_name(cl.site, &site, 1)) {
		log_error("cannot find site \"%s\"", cl.site);
		rv = ENOENT;
		goto out;
	}

	tpt = booth_transport + TCP;
	rv = tpt->open(site);
	if (rv < 0)
		goto out_free;

	rv = tpt->send(site, &cl.msg, sizeof(cl.msg));
	if (rv < 0)
		goto out_free;

	rv = tpt->recv(site, &reply, sizeof(reply));
	if (rv < 0)
		goto out_free;

	data_len = ntohl(reply.length) - sizeof(reply);
	/* no tickets? */
	if (!data_len) {
		rv = 0;
		goto out_close;
	}

	data = malloc(data_len);
	if (!data) {
		rv = -ENOMEM;
		goto out_free;
	}
	rv = tpt->recv(site, data, data_len);
	if (rv < 0)
		goto out_free;

	do_write(STDOUT_FILENO, data, data_len);
	rv = 0;

out_free:
	free(data);
out_close:
	tpt->close(site);
out:
	return rv;
}
Exemplo n.º 11
0
void
init_tables(void)
{
    font_table_init(); /* subsidiary fonts in virtual fonts */
    init_header();
    init_planes();
    init_measures();
}
Exemplo n.º 12
0
int test_read_header()
{
	 struct setec_astronomy_header r_header;
	 unsigned char * hash;
	 
	 /* Start off with a good test */
	 init_header(&r_header);
	 
	 test_equals(read_header(&r_header, GOOD_HEADER_TEST), SA_SUCCESS);

	 /* Check to make sure that the read and write headers are identical */
	 test_equals(r_header.salt_len, DEFAULT_SALT_LEN);
	 test_equals(r_header.hash_count, DEFAULT_HASH_COUNT);
	 test_equals(r_header.hash_len, DEFAULT_HASH_LEN);
	 test_equals(r_header.iv_len, DEFAULT_IV_LEN);
	 
	 hash = malloc(r_header.hash_len);
	 PKCS5_PBKDF2_HMAC_SHA1(DEFAULT_PASSWORD, strlen(DEFAULT_PASSWORD), 
													r_header.salt, r_header.salt_len, 
													r_header.hash_count*2, r_header.hash_len, hash);
	 test_equals(memcmp(r_header.hash, hash, r_header.hash_len), 0);

	 free(hash);
	 free_header(&r_header);

	 /* Now try to read a header from a file that doesn't exist */
	 init_header(&r_header);
	 
	 test_equals(read_header(&r_header, "thisfiledoesntexists"), 
							 SA_FILE_NOT_FOUND);

	 free_header(&r_header);

	 /* Test against a file that exists but has no data */
	 init_header(&r_header);
	 test_equals(read_header(&r_header, NO_DATA_TEST), SA_NO_DATA);
	 free_header(&r_header);

	 /* Test against a file that exists and has some but not enough data */
	 init_header(&r_header);
	 test_equals(read_header(&r_header, NOT_ENOUGH_DATA_TEST), SA_NO_DATA);
	 free_header(&r_header);

	 return UT_SUCCESS;
}
Exemplo n.º 13
0
int gfsc_mountgroup_nodes(char *name, int type, int max, int *count,
			 struct gfsc_node *nodes)
{
	struct gfsc_header h, *rh;
	char *reply;
	int reply_len;
	int fd, rv, result, node_count;

	init_header(&h, GFSC_CMD_MOUNTGROUP_NODES, name, 0);
	h.option = type;
	h.data = max;

	reply_len = sizeof(struct gfsc_header) +
		    (max * sizeof(struct gfsc_node));
	reply = malloc(reply_len);
	if (!reply) {
		rv = -1;
		goto out;
	}
	memset(reply, 0, reply_len);

	fd = do_connect(GFSC_QUERY_SOCK_PATH);
	if (fd < 0) {
		rv = fd;
		goto out;
	}

	rv = do_write(fd, &h, sizeof(h));
	if (rv < 0)
		goto out_close;

	/* won't usually get back the full reply_len */
	do_read(fd, reply, reply_len);

	rh = (struct gfsc_header *)reply;
	result = rh->data;
	if (result < 0 && result != -E2BIG) {
		rv = result;
		goto out_close;
	}

	if (result == -E2BIG) {
		*count = -E2BIG;
		node_count = max;
	} else {
		*count = result;
		node_count = result;
	}
	rv = 0;

	memcpy(nodes, (char *)reply + sizeof(struct gfsc_header),
	       node_count * sizeof(struct gfsc_node));
 out_close:
	close(fd);
 out:
	return rv;
}
Exemplo n.º 14
0
static void init_packet(struct dhcpMessage *packet, struct dhcpMessage *oldpacket, char type)
{
	init_header(packet, type);
	packet->xid = oldpacket->xid;
	memcpy(packet->chaddr, oldpacket->chaddr, 16);
	packet->flags = oldpacket->flags;
	packet->giaddr = oldpacket->giaddr;
	packet->ciaddr = oldpacket->ciaddr;
	add_simple_option(packet->options, DHCP_SERVER_ID, server_config.server);
}
Exemplo n.º 15
0
void Libni_Sender::init(uint32_t client_id) {
  this->client_id = client_id;
  message = new byte[MAX_BUFFER_SIZE];
  for(int i=0; i<MAX_BUFFER_SIZE; i++) {
    message[i]=0; // init
  }

  // init header
  init_header();
}
Exemplo n.º 16
0
static int
write_mhli (Itdb_DB *db, iPodBuffer *buffer )
{
	GList *it = NULL;
	MhliHeader *mhli;
	unsigned int total_bytes;
	int num_thumbs;

	mhli = (MhliHeader *)init_header (buffer, "mhli", sizeof (MhliHeader));
	if (mhli == NULL) {
		return -1;
	}

	num_thumbs = 0;
	total_bytes = get_gint32 (mhli->header_len, buffer->byte_order);
	switch (buffer->db_type) {
	case DB_TYPE_PHOTO:
		it = db_get_photodb(db)->photos;
		break;
	case DB_TYPE_ITUNES:
		it = db_get_itunesdb(db)->tracks;
		break;
	default:
	        g_return_val_if_reached (-1);
	}
	while (it != NULL) {
		Itdb_Track *song;
		int bytes_written;
		iPodBuffer *sub_buffer;
		if (buffer->db_type == DB_TYPE_ITUNES) {
			song = (Itdb_Track*)it->data;
			if (!song->artwork->thumbnail || (song->artwork->dbid == 0)) {
				it = it->next;
				continue;
			}
		}
		sub_buffer = ipod_buffer_get_sub_buffer (buffer, total_bytes);
		if (sub_buffer == NULL) {
			break;
		}
		bytes_written = write_mhii (db, it->data, sub_buffer);
		ipod_buffer_destroy (sub_buffer);
		if (bytes_written != -1) {
			num_thumbs++;
			total_bytes += bytes_written;
		}
		it = it->next;
	}
	mhli = ipod_buffer_get_pointer (buffer);
	mhli->num_children = get_gint32 (num_thumbs, buffer->byte_order);
	dump_mhl ((MhlHeader *)mhli, "mhli");

	return total_bytes;
}
Exemplo n.º 17
0
static void init_distinct(composite_t *c, uint32_t n, occ_t *a) {
  uint32_t i;

  assert(n >= 2); // ? 3 is a better limit

  init_header(c, mk_distinct_tag(n));
  for (i=0; i<n; i++) {
    c->child[i] = a[i];
  }
  init_hooks(c);
}
Exemplo n.º 18
0
static int
write_mhni (Itdb_DB *db, Itdb_Thumb_Ipod_Item *item, iPodBuffer *buffer)
{
	MhniHeader *mhni;
	unsigned int total_bytes;
	int bytes_written;
	iPodBuffer *sub_buffer;
        const Itdb_ArtworkFormat *format;

	if (item == NULL) {
		return -1;
	}

	mhni = (MhniHeader *)init_header (buffer, "mhni",
					  sizeof (MhniHeader));
	if (mhni == NULL) {
		return -1;
	}
	total_bytes =          get_gint32 (mhni->header_len,
					   buffer->byte_order);
	mhni->total_len =      get_gint32 (total_bytes,
					   buffer->byte_order);
        format = item->format;
	mhni->format_id = get_gint32 (format->format_id, buffer->byte_order);
	mhni->image_width =    get_gint16 (item->width, buffer->byte_order);
	mhni->image_height =   get_gint16 (item->height, buffer->byte_order);
	mhni->image_size =     get_gint32 (item->size, buffer->byte_order);
	mhni->ithmb_offset =   get_gint32 (item->offset, buffer->byte_order);
	mhni->vertical_padding = get_gint16 (item->vertical_padding,
					     buffer->byte_order);
	mhni->horizontal_padding = get_gint16 (item->horizontal_padding,
					       buffer->byte_order);

	sub_buffer = ipod_buffer_get_sub_buffer (buffer, total_bytes);
	if (sub_buffer == NULL) {
		return  -1;
	}
	bytes_written = write_mhod_type_3 (item->filename, sub_buffer);
	ipod_buffer_destroy (sub_buffer);
	if (bytes_written == -1) {
		return -1;
	}
	total_bytes += bytes_written;
	mhni = ipod_buffer_get_pointer (buffer);
	mhni->total_len = get_gint32 (total_bytes, buffer->byte_order);
	/* Only update number of children when all went well to try to get
	 * something somewhat consistent when there are errors
	 */
	mhni->num_children = get_gint32 (1, buffer->byte_order);

	dump_mhni (mhni);

	return total_bytes;
}
Exemplo n.º 19
0
static void init_tuple(composite_t *c, uint32_t n, occ_t *a) {
  uint32_t i;

  assert(n >= 1);

  init_header(c, mk_tuple_tag(n));
  for (i=0; i<n; i++) {
    c->child[i] = a[i];
  }
  init_hooks(c);
}
Exemplo n.º 20
0
static void init_update(composite_t *c, occ_t f, uint32_t n, occ_t *a, occ_t v) {
  uint32_t i;

  assert(n >= 1);
  init_header(c, mk_update_tag(n + 2));
  c->child[0] = f;
  for (i=0; i<n; i++) {
    c->child[i+1] = a[i];
  }
  c->child[n+1] = v;
  init_hooks(c);
}
Exemplo n.º 21
0
static void init_apply(composite_t *c, occ_t f, uint32_t n, occ_t *a) {
  uint32_t i;

  assert(n >= 1);

  init_header(c, mk_apply_tag(n + 1));
  c->child[0] = f;
  for (i=0; i<n; i++) {
    c->child[i+1] = a[i];
  }
  init_hooks(c);
}
Exemplo n.º 22
0
static
int queue(struct buffer *buffer)
{
  init_header(&buffer->header, buffer->pcm_data, buffer->pcm_nsamples,
	      config_channels, config_speed, config_precision);

  if (soundcmd(QUEUE, bufferCmd,   0, (long) &buffer->header) == -1 ||
      soundcmd(QUEUE, callBackCmd, 0, (long) buffer) == -1)
    return -1;

  return 0;
}
Exemplo n.º 23
0
static int do_list(void)
{
	struct boothc_header h, *rh;
	char *reply = NULL, *data;
	int data_len;
	int fd, rv;

	init_header(&h, BOOTHC_CMD_LIST, 0, 0, 0);

	fd = do_connect(BOOTHC_SOCK_PATH);
	if (fd < 0) {
		rv = fd;
		goto out;
	}

	rv = do_write(fd, &h, sizeof(h));
	if (rv < 0)
		goto out_close;

	reply = malloc(sizeof(struct boothc_header));
	if (!reply) {
		rv = -ENOMEM;
		goto out_close;
	}

	rv = do_read(fd, reply, sizeof(struct boothc_header));
	if (rv < 0)
		goto out_free;

	rh = (struct boothc_header *)reply;
	data_len = rh->len;

	reply = realloc(reply, sizeof(struct boothc_header) + data_len);
	if (!reply) {
		rv = -ENOMEM;
		goto out_free;
	}
	data = reply + sizeof(struct boothc_header);
	rv = do_read(fd, data, data_len);
	if (rv < 0)
		goto out_free;

	do_write(STDOUT_FILENO, data, data_len);
	rv = 0;

out_free:
	free(reply);
out_close:
	close(fd);
out:
	return rv;
}
Exemplo n.º 24
0
int gfsc_fs_join(int fd, struct gfsc_mount_args *ma)
{
	char msg[sizeof(struct gfsc_header) + sizeof(struct gfsc_mount_args)];
	struct gfsc_header *h = (struct gfsc_header *)msg;
	char *name = strstr(ma->table, ":") + 1;

	init_header(h, GFSC_CMD_FS_JOIN, name, sizeof(struct gfsc_mount_args));

	memcpy(msg + sizeof(struct gfsc_header), ma,
	       sizeof(struct gfsc_mount_args));

	return do_write(fd, msg, sizeof(msg));
}
Exemplo n.º 25
0
void VbExporter::translate(t_output &out, t_programa &prog) {
	
	// cppcheck-suppress unusedScopedObject
	TiposExporter(prog,false); // para que se cargue el mapa_memorias con memorias que tengan ya definidos los tipos de variables que correspondan
	
	// cabecera
	init_header(out,"' ");
	out.push_back(string("Module ")+main_process_name);
	if (!for_test) out.push_back("");
	// procesos y subprocesos
	translate_all_procs(out,prog,"\t");
	out.push_back("End Module");
}
Exemplo n.º 26
0
Arquivo: main.c Projeto: Taihun/booth
static int do_revoke(void)
{
	char *buf;
	struct boothc_header *h, reply;
	int buflen;
	int fd, rv;

	buflen = sizeof(struct boothc_header) + sizeof(cl.ticket);
	buf = malloc(buflen);
	if (!buf) {
		rv = -ENOMEM;
		goto out;
	}
	h = (struct boothc_header *)buf;
	init_header(h, BOOTHC_CMD_REVOKE, 0, 0, 0, sizeof(cl.ticket));
	strcpy(buf + sizeof(struct boothc_header), cl.ticket);

	fd = do_connect(BOOTHC_SOCK_PATH);
	if (fd < 0) {
		rv = fd;
		goto out_free;
	}
        
	rv = do_write(fd, buf, buflen);
        if (rv < 0)
                goto out_close;

	rv = do_read(fd, &reply, sizeof(struct boothc_header));
	if (rv < 0)
		goto out_close;
	if (reply.result == BOOTHC_RLT_ASYNC) {
		log_info("revoke command sent, but result is async.");
		rv = 0;
	} else if (reply.result == BOOTHC_RLT_SYNC_SUCC) {
		log_info("revoke succeeded!");
		rv = 0;
	} else if (reply.result == BOOTHC_RLT_SYNC_FAIL) {
		log_info("revoke failed!");
		rv = 0;
	} else {
		log_error("internal error!");
		rv = -1;
	}

out_close:
	close(fd);
out_free:
	free(buf);
out:
	return rv;
}
Exemplo n.º 27
0
composite_t *new_or_composite_var(uint32_t n, occ_t *a) {
  composite_t *tmp;
  uint32_t i;

  assert(n <= MAX_COMPOSITE_ARITY);

  tmp = (composite_t *) safe_malloc(sizeof(composite_t) + n * sizeof(int32_t));
  init_header(tmp, mk_or_tag(n));
  for (i=0; i<n; i++) {
    tmp->child[i] = a[i];
  }

  return tmp;
}
Exemplo n.º 28
0
void MatLabExporter::translate(t_output &out, t_programa &prog) {
	// cppcheck-suppress unusedScopedObject
	TiposExporter(prog,false); // para que se cargue el mapa_memorias con memorias que tengan ya definidos los tipos de variables que correspondan
	
	// procesos y subprocesos
	t_output out_aux;
	translate_all_procs(out_aux,prog);
	
	// cabecera
	init_header(out,"% ");
	if (!for_test) insertar(out,"");
	if (use_string_matrix && !for_test) {
		insertar(out,"% El algoritmo generado declara uno o más vectores/matrices cuyos elementos son");
		insertar(out,"% cadenas de caracteres En MatLab, estos no son arreglos comunes, sino arreglos de");
		insertar(out,"% celdas (se crean con la función cell en lugar de zeros como losdemás), y por");
		insertar(out,"% ello deben ser accedidos utilizando llaves {} en lugar de paréntisis () para");
		insertar(out,"% sus índices. Es posible que el código generado utilice paréntesis donde deberían");
		insertar(out,"% ir llaves, por lo que deberá realizar estas correcciones manualmente.");
		insertar(out,"");
	}
	if (use_comparar_cadenas) {
		if (!for_test) {
			insertar(out,"% No hay en matlab una función para comparar cadenas completas por mayor/menor,");
			insertar(out,"% solo por igualdad/desigualdad. Por eso se crea esta función auxiliar que lo hace");
			insertar(out,"% realizando comparaciones letra y por letra y de sus longitudes. Su comportamiento");
			insertar(out,"% es similar al strcmp de C, al comparar el resultado con 0 se obtiene el mismo");
			insertar(out,"% resultado que si compararamos las dos cadenas.");
			insertar(out,"%	Ej: para hacer a<=b usamos comparar_cadenas(a,b)<=0");
		}
		insertar(out,"function r=comparar_cadenas(a,b)");
		insertar(out,"\tn1=length(a);");
		insertar(out,"\tn2=length(b);");
		insertar(out,"\tn=min(n1,n2);");
		insertar(out,"\ti=0;");
		insertar(out,"\twhile i<n");
		insertar(out,"\t\tif (a(i)!=b(i))");
		insertar(out,"\t\t\tr=a(i)-b(i);");
		insertar(out,"\t\t\tbreak;");
		insertar(out,"\t\tend");
		insertar(out,"\t\ti=i+1;");
		insertar(out,"\tend");
		insertar(out,"\tif i==n");
		insertar(out,"\t\tr=n1-n2;");
		insertar(out,"\tend");
		insertar(out,"end");
		if (!for_test) insertar(out,"");
	}

	insertar_out(out,out_aux);
}
Exemplo n.º 29
0
void FC_FUNC_(write_binary,WRITE_BINARY)
     (const int * np, void * f, int * type, int * ierr, STR_F_TYPE fname STR_ARG1)
{
  header_t * h;
  char * filename;
  int fd;
  ssize_t moved;

  h = (header_t *) malloc(sizeof(header_t));
  assert(h != NULL);

  *ierr = 0;

  TO_C_STR1(fname, filename);
  fd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, 
	     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH );
  if( fd < 0 ) {
    inf_error("octopus.write_binary", ierr);
    *ierr = 2;
    return;
  }
  free(filename);

  /* create header */
  init_header(h);
  h->np = *np;
  h->type = *type;

  /* write header */
  moved = write(fd, h, sizeof(header_t));

  if(moved < sizeof(header_t)){
    inf_error("octopus.write_binary", ierr);
    close(fd);
    return;
  }

  /* now write the values */
  moved = write(fd, f, (*np)*size_of[(*type)]);

  if(moved < (*np)*size_of[(*type)]){
    inf_error("octopus.write_binary", ierr);
  }

  /* close the file */
  close(fd);
  free(h);

}
Exemplo n.º 30
0
  void VariableScope::setup_as_block(VariableScope* top, VariableScope* parent, CompiledMethod* cm, int num, Object* self) {
    init_header(UnspecifiedZone, InvalidType);

    parent_ = parent;
    self_ = self;

    method_ = cm;
    module_ = top->module();
    block_ =  top->block();
    number_of_locals_ = num;

    for(int i = 0; i < num; i++) {
      locals_[i] = Qnil;
    }
  }