Example #1
0
/**
 * Write the hit record.
 *
 * \param ctx GL context.
 *
 * Write the hit record, i.e., the number of names in the stack, the minimum and
 * maximum depth values and the number of names in the name stack at the time
 * of the event. Resets the hit flag.
 *
 * \sa gl_selection.
 */
static void
write_hit_record(struct gl_context *ctx)
{
    GLuint i;
    GLuint zmin, zmax, zscale = (~0u);

    /* HitMinZ and HitMaxZ are in [0,1].  Multiply these values by */
    /* 2^32-1 and round to nearest unsigned integer. */

    assert( ctx != NULL ); /* this line magically fixes a SunOS 5.x/gcc bug */
    zmin = (GLuint) ((GLfloat) zscale * ctx->Select.HitMinZ);
    zmax = (GLuint) ((GLfloat) zscale * ctx->Select.HitMaxZ);

    write_record( ctx, ctx->Select.NameStackDepth );
    write_record( ctx, zmin );
    write_record( ctx, zmax );
    for (i = 0; i < ctx->Select.NameStackDepth; i++) {
        write_record( ctx, ctx->Select.NameStack[i] );
    }

    ctx->Select.Hits++;
    ctx->Select.HitFlag = GL_FALSE;
    ctx->Select.HitMinZ = 1.0;
    ctx->Select.HitMaxZ = -1.0;
}
Example #2
0
static int bwrite (int chan, void *buffer, int nelem, char *dtype)
     /* To fill the write buffer of initialized channel "chan". When
	the write buffer "chn[chan].buffer" is full, it will write the contents
	out to the data file related to the channel */
{
  int nb, i, j, msg;

  msg = send_command_to_server(chn[chan].gchannel, "WRITE");
#ifdef DEBUG
  printf("mgilib2::bwrite(), ==\n");
#endif

  if(*dtype == 'I' || *dtype == 'R')
    {
      nb = write_record(chn[chan].gchannel, (unsigned char *)buffer, nelem, sizeof(int));
      get_ack_nack(chn[chan].gchannel);
    }

  else if(*dtype == 'D')
    {
      nb = write_record(chn[chan].gchannel, (char *)buffer, nelem, sizeof(double));
      get_ack_nack(chn[chan].gchannel);

    }
  
  else if(*dtype == 'C')
    {
      nb = write_record(chn[chan].gchannel, buffer, nelem, 1);
      get_ack_nack(chn[chan].gchannel);
    }
  return nb;
}
Example #3
0
static int encode(FILE *in, FILE *out) {
    unsigned bank = 0, address = 0;
    unsigned char buffer[0x10];
    size_t nbytes;

    /* write data records, 16 bytes each */
    while ((nbytes = fread(buffer, 1, sizeof(buffer), in)) > 0) {
        write_record(out, (size_t)nbytes, address,
                     0, buffer);

        address += (size_t)nbytes;
        if (address >= BANK_SIZE) {
            /* switch to next bank */
            bank++;
            address %= BANK_SIZE;

            write_record(out, 0, 0, 0x10 + bank, NULL);
        }
    }

    /* write end-of-file record */
    write_record(out, 0, 0, 1, NULL);

    return 0;
}
Example #4
0
static int save_serial(ulong address, ulong count)
{
	int i, c, reclen, checksum, length;
	char *hex = "0123456789ABCDEF";
	char record[2*SREC_BYTES_PER_RECORD+16]; /* buffer for one S-Record */
	char data[2*SREC_BYTES_PER_RECORD+1];	/* buffer for hex data	*/

	reclen = 0;
	checksum = 0;

	if (write_record(SREC3_START))	/* write the header */
		return -1;

	do {
		if (count) {		/* collect hex data in the buffer  */
			c = *(volatile uchar*)(address + reclen);	/* get one byte    */
			checksum += c;	/* accumulate checksum */
			data[2*reclen]   = hex[(c>>4)&0x0f];
			data[2*reclen+1] = hex[c & 0x0f];
			data[2*reclen+2] = '\0';
			++reclen;
			--count;
		}

		if (reclen == SREC_BYTES_PER_RECORD || count == 0) {
			/* enough data collected for one record: dump it */
			if (reclen) {	/* build & write a data record: */
				/* address + data + checksum */
				length = 4 + reclen + 1;

				/* accumulate length bytes into checksum */
				for (i = 0; i < 2; i++)
					checksum += (length >> (8*i)) & 0xff;

				/* accumulate address bytes into checksum: */
				for (i = 0; i < 4; i++)
					checksum += (address >> (8*i)) & 0xff;

				/* make proper checksum byte: */
				checksum = ~checksum & 0xff;

				/* output one record: */
				sprintf(record, SREC3_FORMAT, length, address, data, checksum);
				if (write_record(record))
					return -1;
			}
			address  += reclen;  /* increment address */
			checksum  = 0;
			reclen    = 0;
		}
	} while (count);

	if (write_record(SREC3_END))	/* write the final record */
		return -1;
	return 0;
}
Example #5
0
int main (int argc, char *argv[])  {
    // Déclare un timer, ainsi que deux recorder qui vont contenir les résultats de l'exécution du programme
    timer *t = timer_alloc();
    recorder *bash_rec = recorder_alloc("shell-bash.csv");
    recorder *prog_rec = recorder_alloc("shell-prog.csv");

    // Nom du programme C et du script à comparer
    char * progr = "./shell-program ";
    char * bash =  "./shell-bash.sh ";

    // Cette variable contient la transformation du nombre d'instruction (i).
    // Puisque cette variable est un int, 7 caractères suffisent à sa représentation.
    char  nbr[7];
    int i;

    // Allocation des emplacements contenant la commande à exécuter
    char*argProgr = (char *) malloc(24*sizeof(char));
    char*argBash = (char *) malloc(24*sizeof(char));

    if(argProgr == NULL || argBash == NULL)
        exit(EXIT_FAILURE);


    for(i=1; i<MAX_SIZE; i+=1) {
        // Convertit "i" en char* et le place dans nbr
        snprintf(nbr, 7, "%d", i);

        // Concatene les deux parties de la commande
        strncpy(argProgr, progr, 24);
        strncpy(argBash, bash, 24);
        strncat(argProgr, nbr, 7);
        strncat(argBash, nbr, 7);

        // Commence le timer et lance la commande, puis écrit le résultat dans le record approprié
        start_timer(t);
        system(argProgr);
        write_record(prog_rec, i, stop_timer(t));

        start_timer(t);
        system(argBash);
        write_record(bash_rec, i, stop_timer(t));
    }

    // Libère la mémoire
    recorder_free(bash_rec);
    recorder_free(prog_rec);
    timer_free(t);

    return EXIT_SUCCESS;
}
Example #6
0
static void
generate_process64ex_record(const char *directory, const char *record_filename,
    u_int32_t type)
{
	token_t *process64ex_token;
	char *buf;

	buf = (char *)malloc(strlen(record_filename) + 6);
	if (type == AU_IPv6) {
		inet_pton(AF_INET6, "fe80::1", process64_tid_addr.at_addr);
		process64_tid_addr.at_type = AU_IPv6;
		sprintf(buf, "%s%s", record_filename, "-IPv6");
	} else {
		process64_tid_addr.at_addr[0] = inet_addr("127.0.0.1");
		process64_tid_addr.at_type = AU_IPv4;
		sprintf(buf, "%s%s", record_filename, "-IPv4");
	}

	process64ex_token = au_to_process64_ex(process64_auid, process64_euid,
	    process64_egid, process64_ruid, process64_rgid, process64_pid,
	    process64_sid, &process64_tid_addr);
	if (process64ex_token == NULL)
		err(EX_UNAVAILABLE, "au_to_process64_ex");
	write_record(directory, buf, process64ex_token, AUE_NULL);
	free(buf);
}
Example #7
0
void save_area(struct element *xy, int num_points, int category)
{
    int incr;
    float first_cell, last_cell;

    for (incr = 0; incr < num_points;) {

	if (START_ROW != STOP_ROW) {
	    fprintf(stderr, "ERROR: start and end row not same\n");
	    for (incr = 0; incr < num_points; incr += 2) {
		fprintf(stderr, "%d: %d %f %d %f\n",
			incr, xy[incr].row, xy[incr].col,
			xy[incr + 1].row, xy[incr + 1].col);
	    }
	    incr++;
	    continue;
	}

	first_cell = START_COL + 1.;
	last_cell = STOP_COL;
	if (last_cell >= first_cell)
	    write_record(START_ROW, first_cell, last_cell, category);
	incr += 2;
    }
}
Example #8
0
/* Tries to write the specified number of records. Stops when the log gets
   full. Returns the number of records written. Spins for random
   number of times, up to 'max_spin_count', between writes. */
static size_t write_records_to_log(int writer_id, int32_t record_size,
                                   int32_t num_records,
                                   int32_t max_spin_count) {
  int32_t ix;
  int counter = 0;
  for (ix = 0; ix < num_records; ++ix) {
    int32_t jx;
    int32_t spin_count = max_spin_count ? rand() % max_spin_count : 0;
    char *record;
    if (counter++ == num_records / 10) {
      printf("   Writer %d: %d out of %d written\n", writer_id, ix,
             num_records);
      counter = 0;
    }
    record = (char *)(census_log_start_write(record_size));
    if (record == NULL) {
      return ix;
    }
    write_record(record, record_size);
    census_log_end_write(record, record_size);
    for (jx = 0; jx < spin_count; ++jx) {
      GPR_ASSERT(jx >= 0);
    }
  }
  return num_records;
}
Example #9
0
gboolean
amar_file_close(
    amar_file_t *file,
    GError **error)
{
    gboolean success = TRUE;
    amar_t *archive = file->archive;

    /* close all attributes that haven't already written EOA */
    g_hash_table_foreach(file->attributes, foreach_attr_close, error);
    if (*error)
	success = FALSE;

    /* write an EOF record */
    if (success) {
	if (!write_record(archive, file->filenum, AMAR_ATTR_EOF, 1,
			  NULL, 0, error))
	    success = FALSE;
    }

    /* remove from archive->file list */
    g_hash_table_remove(archive->files, &file->filenum);

    /* clean up */
    g_hash_table_destroy(file->attributes);
    amfree(file);

    return success;
}
Example #10
0
void entry_menu()
{
  int ch,num;
  clrscr();
  cout<<"\n\n\n\t\tENTRY MENU";
  cout<<"\n\n\t1.CREATE STUDENT RECORD";
  cout<<"\n\n\t2.DISPLAY ALL STUDENTS RECORD";
  cout<<"\n\n\t3.SEARCH STUDENT RECORD";
  cout<<"\n\n\t4.MODIFY STUDENT RECORD ";
  cout<<"\n\n\t5.DELETE STUDENT RECORD ";
  cout<<"\n\n\t6.RETURN TO MAIN MENU";
  cout<<"\n\nPlease Enter Your Choice(1-6).......";
  cin>>ch;
  clrscr();
  switch(ch)
  {
	  case 1:write_record();break;
	  case 2:read_record();break;
	  case 3:cout<<"\n\n\tPlease enter the roll no. of student ";
		 cin>>num;
		 display(num);
		 break;
	  case 4:cout<<"\n\n\tPlease enter the roll no. of student ";
		 cin>>num;
		 modify_record(num);
		 break;
	  case 5:cout<<"\n\n\tPlease enter the roll no. of student ";
		 cin>>num;
	    delete_record(num);
		 break;
     case 6:break;
     default : cout<<"\a";entry_menu();
  }
}
Example #11
0
void DbDumperWriter::run(tbsys::CThread *thr_, void *arg)
{
  last_rotate_time_ = time(NULL);
  UNUSED(thr_);
  UNUSED(arg);

  int ret = OB_SUCCESS;

  while(running_ || !records_.empty()) {
    ret = OB_SUCCESS;
    bool flush = !running_;

    if (need_rotate_output_file()) {
      ret = rotate_output_file();
      if (ret != OB_SUCCESS) {
        TBSYS_LOG(ERROR, "can't rotate file");
        break;
      }
    }

    if (ret == OB_SUCCESS) {
      ret = write_record(flush); 

      if (ret != OB_SUCCESS) {
        TBSYS_LOG(ERROR, "write record failed, %d", ret);
        sleep(1);
      }
    }
  }

  //mv last_file.TMP to last_file
  if (ret == OB_SUCCESS)
    mv_output_file();
}
Example #12
0
void TeamEdit::save() {
    dbo::Transaction t(tApp->session());
    write_record(team_.modify(), /* init */ false);
    team_chat(team_, "change name/description of the team", tApp->user());
    t.commit();
    t_emit(TEAM_OBJECT, team_.id());
}
Example #13
0
int main (int argc, char *argv[])  {
  timer *t = timer_alloc();
  recorder *parent_rec = recorder_alloc("parent.csv");
  recorder *child_rec = recorder_alloc("child.csv");

  pid_t pid;
  int status, i;

  for (i = 0; i < N; i++) {
    start_timer(t);
    pid = fork();

    if (pid == -1) {
      // erreur à l'exécution de fork
      perror("fork");
      return EXIT_FAILURE;
    }
    // pas d'erreur
    // BEGIN
    if (pid == 0) {
      // processus fils
      write_record(child_rec, i, stop_timer(t));

      recorder_free(child_rec);
      recorder_free(parent_rec);
      timer_free(t);

      return EXIT_SUCCESS;
    }
    else {
      // processus père
      write_record(parent_rec, i, stop_timer(t));
      pid = waitpid(pid, &status, 0);
      if (pid == -1) {
        perror("wait");
        return EXIT_FAILURE;
      }
    }
    // END
  }

  recorder_free(child_rec);
  recorder_free(parent_rec);
  timer_free(t);

  return EXIT_SUCCESS;
}
Example #14
0
int mcs_file::save(const char* file, void* data, int len)
{
	FILE* f;
	int rc = -1;
    int addr, addr_offs, count;
	const int buff_len = 16;
	union {
		u8 buff[buff_len];
		u16 word;
	} u;

	f = fopen(file, "wt");
	if (f == NULL)
	{
		msgf(STR_UNABLE_TO_OPEN_FILE);
		return -1;
	}

    addr = 0;
    addr_offs = 0;
    
    u.word = 0x0000;
    if (write_record(f, 2, 0, RECORD_ADDRESS, u.buff))
        goto cleanup;
    
    while (addr_offs + addr < len)
    {
        if (addr_offs + addr + buff_len < len)
            count = buff_len;
        else
            count = len - addr_offs - addr;

        if (write_record(f, count, addr, RECORD_DATA, (u8*)data + addr_offs + addr))
            goto cleanup;

        addr += count;

        if (addr >= 0x10000 && addr_offs + addr < len)
        {
            addr_offs += 0x10000;
            addr &= 0xFFFF;
            u.word = HTON16(addr_offs >> 16);
            if (write_record(f, 2, 0, RECORD_ADDRESS, u.buff))
                goto cleanup;
        }
    }
Example #15
0
void file_bstore::write_root(const std::vector<char>& record)
{
    if (m_cur_slab == NULL)
        throw io_exception("file_store is not open");
    lock_t lock(m_mutex);
    m_root = write_record('R', record);
    //printf("Writing root record: %d\n", (int) m_root);
}
Example #16
0
int avro_schema_to_json(const avro_schema_t schema, avro_writer_t out)
{
	check_param(EINVAL, is_avro_schema(schema), "schema");
	check_param(EINVAL, out, "writer");

	int rval;

	if (is_avro_primitive(schema)) {
		check(rval, avro_write_str(out, "{\"type\":\""));
	}

	switch (avro_typeof(schema)) {
	case AVRO_STRING:
		check(rval, avro_write_str(out, "string"));
		break;
	case AVRO_BYTES:
		check(rval, avro_write_str(out, "bytes"));
		break;
	case AVRO_INT32:
		check(rval, avro_write_str(out, "int"));
		break;
	case AVRO_INT64:
		check(rval, avro_write_str(out, "long"));
		break;
	case AVRO_FLOAT:
		check(rval, avro_write_str(out, "float"));
		break;
	case AVRO_DOUBLE:
		check(rval, avro_write_str(out, "double"));
		break;
	case AVRO_BOOLEAN:
		check(rval, avro_write_str(out, "boolean"));
		break;
	case AVRO_NULL:
		check(rval, avro_write_str(out, "null"));
		break;
	case AVRO_RECORD:
		return write_record(out, avro_schema_to_record(schema));
	case AVRO_ENUM:
		return write_enum(out, avro_schema_to_enum(schema));
	case AVRO_FIXED:
		return write_fixed(out, avro_schema_to_fixed(schema));
	case AVRO_MAP:
		return write_map(out, avro_schema_to_map(schema));
	case AVRO_ARRAY:
		return write_array(out, avro_schema_to_array(schema));
	case AVRO_UNION:
		return write_union(out, avro_schema_to_union(schema));
	case AVRO_LINK:
		return write_link(out, avro_schema_to_link(schema));
	}

	if (is_avro_primitive(schema)) {
		return avro_write_str(out, "\"}");
	}
	avro_set_error("Unknown schema type");
	return EINVAL;
}
Example #17
0
static void at_exit(void)
{
	write_log();
	write_record();
	if (unlink(lockname) < 0) {
		fprintf(stderr, "%s: cannot unlink '%s'\n", PACKAGE_NAME, lockname);
		fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno));
	}
}
Example #18
0
int main(int argc, char *argv[]) {

    FILE *in_fp                = NULL;
    FILE *out_fp               = NULL;
    FILE *err_fp               = NULL;
    char *in_file              = "/dev/stdin";
    char *out_file             = NULL;
    char *err_file             = NULL;
    int   byte_no              = 0;
    int   record_no            = 0;
    int   rc                   = 0;
    int   time_travel          = DEFAULT_TIME_TRAVEL;
    struct futmpx record, last_valid_record;

    debug("Record length: %i\n\n", RECORD_LENGTH);
    (void)memset(&last_valid_record, 0, RECORD_LENGTH);
    (void)memset(&record, 0, RECORD_LENGTH);

    /* Functions parse_args() and open_files() exit on error: */
    parse_args(argc, argv, &out_file, &err_file, &time_travel);
    open_files(in_file, &in_fp, out_file, &out_fp, err_file, &err_fp);

    /* Loop over input file records */
    byte_no = 0;
    record_no = 0;
    while(1 == fread(&record, RECORD_LENGTH, 1, in_fp)) {
        byte_no += RECORD_LENGTH;
        record_no++;

        if(g_DEBUG) {
            print_record(stderr, record_no, byte_no, record);
        }
        if(is_record_valid(last_valid_record, record, time_travel)) {
            if(out_fp) {
                write_record(out_fp, record);
            }
            (void)memcpy(&last_valid_record, &record, RECORD_LENGTH);
        } else {
            rc = 1;
            debug("Invalid record encountered at byte %i, seeking\n", byte_no);
            seek_valid_record(in_fp, &byte_no, time_travel, last_valid_record, &record, err_fp);
        }

    }
    if(ferror(in_fp)) {
        error("a read error occurred at or around byte %i\n", byte_no);
        rc = 1;
    }

    /* Tidy up and exit */
    rc |= flush_and_close_files(in_file, in_fp, out_file, out_fp, err_file, err_fp);
    rc |= check_out_file_size(out_file);

    return rc;

}
Example #19
0
static void
generate_ipc_record(const char *directory, const char *record_filename)
{
	token_t *ipc_token;

	ipc_token = au_to_ipc(ipc_type, ipc_id);
	if (ipc_token == NULL)
		err(EX_UNAVAILABLE, "au_to_ipc");
	write_record(directory, record_filename, ipc_token, AUE_NULL);
}
Example #20
0
static void
arraystorage_backup(void *self, FILE *f){
  if (self == 0)
    return;
  int i;
  CountryStorage *rs = (CountryStorage *) self;

  for (i=0; i < rs->maxid; i++)
    write_record(f,rs->countries[i]);
}
Example #21
0
static void
generate_file_record(const char *directory, const char *record_filename)
{
	token_t *file_token;

	file_token = au_to_file("test", file_token_timeval);
	if (file_token == NULL)
		err(EX_UNAVAILABLE, "au_to_file");
	write_record(directory, record_filename, file_token, AUE_NULL);
}
Example #22
0
static void
generate_zonename_record(const char *directory, const char *record_filename)
{
	token_t *zonename_token;

	zonename_token = au_to_zonename(zonename_sample);
	if (zonename_token == NULL)
		err(EX_UNAVAILABLE, "au_to_zonename");
	write_record(directory, record_filename, zonename_token, AUE_NULL);
}
Example #23
0
static void
generate_opaque_record(const char *directory, const char *record_filename)
{
	token_t *opaque_token;

	opaque_token = au_to_opaque(opaque_token_data, opaque_token_bytes);
	if (opaque_token == NULL)
		err(EX_UNAVAILABLE, "au_to_opaque");
	write_record(directory, record_filename, opaque_token, AUE_NULL);
}
Example #24
0
static void
generate_seq_record(const char *directory, const char *record_filename)
{
	token_t *seq_token;

	seq_token = au_to_seq(seq_audit_count);
	if (seq_token == NULL)
		err(EX_UNAVAILABLE, "au_to_seq");
	write_record(directory, record_filename, seq_token, AUE_NULL);
}
Example #25
0
static void
generate_text_record(const char *directory, const char *record_filename)
{
	token_t *text_token;

	text_token = au_to_text(text_token_text);
	if (text_token == NULL)
		err(EX_UNAVAILABLE, "au_to_text");
	write_record(directory, record_filename, text_token, AUE_NULL);
}
Example #26
0
static void
generate_path_record(const char *directory, const char *record_filename)
{
	token_t *path_token;

	path_token = au_to_path(path_token_path);
	if (path_token == NULL)
		err(EX_UNAVAILABLE, "au_to_path");
	write_record(directory, record_filename, path_token, AUE_NULL);
}
static void
write_recent_blocks (union block *h, size_t blocks)
{
  size_t i;
  for (i = 0; i < blocks; i++)
    {
      new_record[new_blocks++] = h[i];
      if (new_blocks == blocking_factor)
	write_record (1);
    }
}
Example #28
0
static void
generate_arg32_record(const char *directory, const char *record_filename)
{
	token_t *arg32_token;

	arg32_token = au_to_arg32(arg32_token_n, arg32_token_text,
	    arg32_token_v);
	if (arg32_token == NULL)
		err(EX_UNAVAILABLE, "au_to_arg32");
	write_record(directory, record_filename, arg32_token, AUE_NULL);
}
Example #29
0
static void
generate_return32_record(const char *directory, const char *record_filename)
{
	token_t *return32_token;

	return32_token = au_to_return32(au_errno_to_bsm(return32_status),
	    return32_ret);
	if (return32_token == NULL)
		err(EX_UNAVAILABLE, "au_to_return32");
	write_record(directory, record_filename, return32_token, AUE_NULL);
}
Example #30
0
static void
generate_data_record(const char *directory, const char *record_filename)
{
	token_t *data_token;

	data_token = au_to_data(data_token_unit_print, data_token_unit_type,
	    data_token_unit_count, data_token_data);
	if (data_token == NULL)
		err(EX_UNAVAILABLE, "au_to_data");
	write_record(directory, record_filename, data_token, AUE_NULL);
}