Ejemplo n.º 1
0
void  QP_solver<Rep_>::
init_r_B_O()
{
  CGAL_qpe_precondition(!check_tag(Is_in_standard_form()) &&
			!check_tag(Is_linear()));
  r_B_O.resize(B_O.size());
  multiply__2D_B_OxN_O(r_B_O.begin());
}
Ejemplo n.º 2
0
void  QP_solver<Rep_>::
init_w()
{
  CGAL_qpe_precondition(!check_tag(Is_in_standard_form()) &&
			!check_tag(Is_linear()));
  w.resize(qp_n);
  multiply__2D_OxN_O(w.begin());
}
Ejemplo n.º 3
0
/*
 * Get server data and make sure there is a continuation response inside them.
 */
int
response_continuation(session *ssn, int tag)
{
	int r;
	ssize_t n;

	buffer_reset(&ibuf);

	do {
		buffer_check(&ibuf, ibuf.len + INPUT_BUF);
		if ((n = receive_response(ssn, ibuf.data + ibuf.len, 0, 1)) ==
		    -1)
			return -1;
		ibuf.len += n;

		if (check_bye(ibuf.data))
			return STATUS_BYE;
	} while ((r = check_tag(ibuf.data, ssn, tag)) == STATUS_NONE &&
	    !check_continuation(ibuf.data));

	if (r == STATUS_NO &&
	    (check_trycreate(ibuf.data) || get_option_boolean("create")))
		return STATUS_TRYCREATE;

	if (r == STATUS_NONE)
		return STATUS_CONTINUE;

	return r;
}
Ejemplo n.º 4
0
/*
 * run the program with these tags:
 * 		-f <filename>
 * 		checks if this file has an mp3 tag
 *
 * 		-v <filename>
 * 		removes the tag from the file
 */
int main(int argc, char **argv) {
	int c = 0;

	opterr = 0;
	while (EOF != (c = getopt(argc, argv, "f:v:"))) {
		if (c == 'f')
			check_tag(optarg);
		else if (c == 'v')
			remove_v2(optarg);
		else if (c == '?') {
			fprintf(stderr, "do not recognize option...\n");
			exit(EXIT_SUCCESS);
		}
	}

	if (optind < argc) {
		printf ("non-option arguments: ");
		while (optind < argc)
			printf ("%s ", argv[optind++]);
		printf ("\n");
	}

	printf("finished parsing command line...\n");
	return 1;
}
Ejemplo n.º 5
0
typename QP_solver<Rep_>::ET
QP_solver<Rep_>::nonbasic_original_variable_value(int i) const
{
  if (check_tag(Is_in_standard_form()))
    return et0;

  CGAL_assertion(!is_basic(i));
  return original_variable_value(i);
}
Ejemplo n.º 6
0
/*
 * Process the data that server sent due to IMAP FETCH BODY[] client request,
 * ie. FETCH BODY[HEADER], FETCH BODY[TEXT], FETCH BODY[HEADER.FIELDS
 * (<fields>)], FETCH BODY[<part>].
 */
int
response_fetchbody(session *ssn, int tag, char **body, size_t *len)
{
	int r, match;
	unsigned int offset;
	ssize_t n;
	regexp *re;

	if (tag == -1)
		return -1;

	buffer_reset(&ibuf);

	match = -1;
	offset = 0;
	
	re = &responses[RESPONSE_FETCH_BODY];

	do {
		buffer_check(&ibuf, ibuf.len + INPUT_BUF);
		if ((n = receive_response(ssn, ibuf.data + ibuf.len, 0, 1)) ==
		    -1)
			return -1;
		ibuf.len += n;

		if (match != 0) {
			match = regexec(re->preg, ibuf.data, re->nmatch,
			    re->pmatch, 0);
			
			if (match == 0 && re->pmatch[2].rm_so != -1 &&
			    re->pmatch[2].rm_eo != -1) {
				*len = strtoul(ibuf.data + re->pmatch[2].rm_so,
				    NULL, 10);
				offset = re->pmatch[0].rm_eo + *len;
			}
		}

		if (offset != 0 && ibuf.len >= offset) {
			if (check_bye(ibuf.data + offset))
				return STATUS_BYE;
		}
	} while (ibuf.len < offset || (r = check_tag(ibuf.data + offset, ssn,
	    tag)) == STATUS_NONE);

	if (match == 0) {
		if (re->pmatch[2].rm_so != -1 &&
		    re->pmatch[2].rm_eo != -1) {
			*body = ibuf.data + re->pmatch[0].rm_eo;
		} else {
			*body = ibuf.data + re->pmatch[3].rm_so;
			*len = re->pmatch[3].rm_eo - re->pmatch[3].rm_so;
		}
	}

	return r;
}
Ejemplo n.º 7
0
int parse_value(char *buf, size_t buflen, int *pos, value_descriptor *desc, void **value, size_t *_value_len)
{
	if (*pos+3 > buflen) return 0;

	char *b=buf+*pos;
	if (!check_tag(&b[0],sizeof(key),keys,sizeof(keys)/sizeof(keys[0]))) return 0;
	if (!check_tag(&b[1],sizeof(field),fields,sizeof(fields)/sizeof(fields[0]))) return 0;
	if (b[1]!=LP_RECORD && !check_tag(&b[2],sizeof(datatype),datatypes,sizeof(datatypes)/sizeof(datatypes[0]))) return 0;

	memcpy(desc, b, sizeof (*desc));
	b+=3;
	struct hash_item i={desc->f, desc->t, b};
	*_value_len=value_len(i);
	if (*pos+3+*_value_len>buflen) return 0;
	*value=(void*)b;
	*pos+=3+*_value_len;

	return 1;

}
Ejemplo n.º 8
0
/*     long read_line_opt(char *tag,char *defaultline,char *format,...)
 *
 *     On process 0, this program reads a line of text and data from stdin
 *     in a controlled manner. The tag cannot
 *     be the empty string "", the program searches
 *     for the tag in the current section. If the tag is not
 *     found, default values are assigned to the variables. The program returns
 *     the offset of the line from the beginning
 *     of the file and positions the file pointer to the next line. On
 *     processes other than 0, the program does nothing and returns -1L.
 *
 */
long read_line_opt(char *tag,char *defaultline,char *format, ...)
{
   int my_rank,is,ic;
   long tofs;
   char *pl,*p;
   va_list args;

   MPI_Comm_rank(MPI_COMM_WORLD,&my_rank);

   if (my_rank==0)
   {
      check_tag(tag);

      error_root(tag[0]=='\0',1,"read_line_opt [mutils.c]",
              "optional parameters must have a non empty tag");

      tofs=find_tag_opt(tag);
      if(tofs != -1L)
      {
         get_line();
         pl=line+strspn(line," \t");
         pl+=strcspn(pl," \t\n");
      }else
      {
         /* optional parameter gets default value */
         error_root(strlen(defaultline)+strlen(tag)+1>NAME_SIZE,1,
             "read_line_opt [mutils.c]",
             "default line too long");
         sprintf(line,"%s %s",tag,defaultline);
         pl=line+strspn(line," \t");
         pl+=strcspn(pl," \t\n");
      }

      va_start(args,format);

      for (p=format;;)
      {
         p+=strspn(p," ");
         ic=0;
         is=2;

         if ((p[0]=='\0')||(p[0]=='\n'))
            break;
         else if (p==strstr(p,"%s"))
            ic=sscanf(pl,"%s",va_arg(args,char*));
         else if (p==strstr(p,"%d"))
            ic=sscanf(pl,"%d",va_arg(args,int*));
         else if (p==strstr(p,"%f"))
Ejemplo n.º 9
0
void  QP_solver<Rep_>::
multiply__2D_OxN_O(Value_iterator out) const
{
  CGAL_qpe_precondition(!check_tag(Is_in_standard_form()));

  // initialize with zero vector:
  std::fill_n(out, B_O.size(), et0);
  
  for (int row_it = 0; row_it < qp_n; ++row_it, ++out) {
    D_pairwise_accessor d_row(qp_D, row_it);
    for (int i = 0; i < qp_n; ++i)
      if (!is_basic(i)) {
	const ET value = nonbasic_original_variable_value(i);
	*out += d_row(i) * value;
      }
  }
}
Ejemplo n.º 10
0
void  QP_solver<Rep_>::
multiply__A_CxN_O(Value_iterator out) const
{
  CGAL_qpe_precondition(!check_tag(Is_in_standard_form()));
  
  // initialize with zero vector:
  std::fill_n(out, C.size(), et0);
  
  for (int i = 0; i < qp_n; ++i)
    if (!is_basic(i)) {
      const ET x_i = nonbasic_original_variable_value(i);
      const A_column a_col = qp_A[i];
      Value_iterator out_it = out;
      for (Index_const_iterator row_it = C.begin();
	   row_it != C.end();
	   ++row_it, ++out_it)
	*out_it += x_i * a_col[*row_it];
    }
}
Ejemplo n.º 11
0
typename QP_solver<Rep_>::ET
QP_solver<Rep_>::original_variable_value(int i) const
{
  CGAL_assertion(!check_tag(Is_in_standard_form()) && i<qp_n);
  switch (x_O_v_i[i]) {
  case UPPER:
    return qp_u[i];
    break;
  case ZERO:
    return et0;
    break;
  case LOWER:
  case FIXED:
    return qp_l[i];
    break;
  case BASIC:
    CGAL_qpe_assertion(false);
  }
  return et0; // dummy
}
Ejemplo n.º 12
0
int main(int argc, char **argv) {
	int c = 0;

	opterr = 0;
	while (-1 != (c = getopt(argc, argv, "f:e"))) {
		if (c == (int)'f') {
			check_tag(optarg);
		}
		else if (c == (int)'?') {
			fprintf(stderr, "do not recognize flag %c...\n", c);
			exit(EXIT_FAILURE);
		}
	}

	if (optind < argc) {
		printf ("non-option arguments: ");
		while (optind < argc)
			printf ("%s ", argv[optind++]);
		printf ("\n");
	}

	printf("finished parsing command line...\n");
	return 1;
}
Ejemplo n.º 13
0
static double parse_wav_header_buffer(char* buffer, int buffer_size, int* sample_rate, int* num_of_channels, int* sample_size, int* data_start_offset, int* type){
    int n_ch;
    int sam_siz;
    int sr;
    char* cp;
    int wav_file_size;
    int data_size;
    int data_offset;
    int audio_format;
    int byte_rate;
    int block_align;

    if (buffer_size < 44)
        return 0.0;

    if (!check_tag(buffer,"RIFF"))
    	return 0.0;

    wav_file_size = get_tag_size(buffer);

    if (!check_tag(buffer + 8 ,"WAVE"))
    	return 0.0;

    cp = buffer + 12;

    while (cp - buffer <= buffer_size - 8){

		if (check_tag(cp, "fmt ")){
	//20        2   AudioFormat      PCM = 1 (i.e. Linear quantization)
	//                               Values other than 1 indicate some
	//                               form of compression.
	//				 MuLaw = 7
	//				 ALaw = 6
	//22        2   NumChannels      Mono = 1, Stereo = 2, etc.
	//24        4   SampleRate       8000, 44100, etc.
	//28        4   ByteRate         == SampleRate * NumChannels * BitsPerSample/8
	//32        2   BlockAlign       == NumChannels * BitsPerSample/8
	//                               The number of bytes for one sample including
	//                               all channels. I wonder what happens when
	//                               this number isn't an integer?
	//34        2   BitsPerSample    8 bits = 8, 16 bits = 16, etc.
	//	    2   ExtraInfoSize
			audio_format = ((unsigned short*)(cp+8) )[0];
			n_ch 		= ((unsigned short*)(cp+10) )[0];
			sr   		= ((unsigned int*)(cp+12) )[0];
			byte_rate   = ((unsigned int*)(cp+16) )[0];
			block_align = ((unsigned short*)(cp+20) )[0];
			sam_siz     = ((unsigned short*)(cp+22) )[0];


		}else if (check_tag(cp, "data")){
			data_size = get_tag_size(cp);
			data_offset = (cp - buffer) + 8;
			break;
		}
		cp += 8 + get_tag_size(cp);
    }

    if (type)
    	*type = audio_format;

    if (sample_rate)
        *sample_rate = sr;
    if (num_of_channels)
        *num_of_channels = n_ch;
    if (sample_size)
        *sample_size = sam_siz;
    if (data_start_offset)
        *data_start_offset = data_offset;

    return (double)data_size / (double)(n_ch * (sam_siz / 8) * sr);
}
Ejemplo n.º 14
0
/*
 * [mk-bv-repeat <rational> <bv>]
 */
static void smt_check_mk_bv_repeat(tstack_t *stack, stack_elem_t *f, uint32_t n) {
  check_op(stack, MK_BV_REPEAT);
  check_size(stack, n == 2);
  check_tag(stack, f, TAG_RATIONAL);
}
Ejemplo n.º 15
0
void parse_item(char* buffer, int size)
  /*@ requires FORALLP_C &*& FORALLP_CS &*&
               [?f1]world(?pub, ?key_clsfy) &*&
               [?f2]crypto_chars(?kind, buffer, size, ?ccs) &*&
               size > TAG_LENGTH &*&
               kind == normal ? true :
                 [_]item_constraints(?i, ccs, pub); @*/
  /*@ ensures  [f1]world(pub, key_clsfy) &*&
               [f2]crypto_chars(kind, buffer, size, ccs) &*&
               true == well_formed_ccs(forallc, forallcs, nat_length(ccs), ccs); @*/
{
  //@ open [f1]world(pub, key_clsfy);
  //@ close [f1]world(pub, key_clsfy);
  //@ crypto_chars_limits(buffer);
  //@ crypto_chars_split(buffer, TAG_LENGTH);
  //@ assert [f2]crypto_chars(kind, buffer, TAG_LENGTH, ?ccs_tag);
  /*@ assert [f2]crypto_chars(kind, buffer + TAG_LENGTH,
                              size - TAG_LENGTH,  ?cs_cont); @*/
  /*@ switch (kind)
      {
        case normal:
          crypto_chars_to_chars(buffer, TAG_LENGTH);
        case secret:
          assert [_]item_constraints(?i, ccs, pub);
          OPEN_ITEM_CONSTRAINTS(i, ccs, pub);
          public_crypto_chars(buffer, TAG_LENGTH);
      }
  @*/
  //@ open [f2]chars(buffer, TAG_LENGTH, ?cs_tag);
  //@ assert ccs_tag == cs_to_ccs(cs_tag);
  char t = *(buffer);
  //@ close [f2]chars(buffer, TAG_LENGTH, cs_tag);
  check_tag(buffer, t);
  //@ cs_to_ccs_full_tag(t);
  //@ assert cs_tag == full_tag(t);
  //@ length_equals_nat_length(ccs);
  //@ SWITCH_TAG(t)
  switch (t)
  {
    case TAG_DATA:
      break;
    case TAG_PAIR:
      //@ close exists(ccs_tag);
      parse_pair_item(buffer + TAG_LENGTH, size - TAG_LENGTH);
      break;
    case TAG_NONCE:
      if (size != TAG_LENGTH + 1 + NONCE_SIZE)
        abort_crypto_lib("Could not parse nonce: illegal size");
      break;
    case TAG_HASH:
      if (size != TAG_LENGTH + HASH_SIZE)
        abort_crypto_lib("Could not parse hash: illegal size");
      break;
    case TAG_SYMMETRIC_KEY:
      if (size != TAG_LENGTH + GCM_KEY_SIZE)
        abort_crypto_lib("Could not parse symmetric key: illegal size");
      break;
    case TAG_PUBLIC_KEY:
      if (size != TAG_LENGTH + RSA_SERIALIZED_KEY_SIZE)
        abort_crypto_lib("Could not parse public key: illegal size");
      break;
    case TAG_PRIVATE_KEY:
      if (size != TAG_LENGTH + RSA_SERIALIZED_KEY_SIZE)
        abort_crypto_lib("Could not parse private key: illegal size");
      break;
    case TAG_HMAC:
      if (size != TAG_LENGTH + HMAC_SIZE)
        abort_crypto_lib("Could not parse private key: illegal size");
      break;
    case TAG_SYMMETRIC_ENC:
      if (size < TAG_LENGTH + GCM_IV_SIZE + MINIMAL_STRING_SIZE)
        abort_crypto_lib("Could not parse symmetric encrypted item: illegal size");
      break;
    case TAG_ASYMMETRIC_ENC:
      if (size > TAG_LENGTH + RSA_SERIALIZED_KEY_SIZE ||
          size < TAG_LENGTH + MINIMAL_STRING_SIZE)
        abort_crypto_lib("Could not parse asymmetric encrypted item: illegal size");
      break;
    case TAG_ASYMMETRIC_SIG:
      if (size > TAG_LENGTH + RSA_SERIALIZED_KEY_SIZE ||
          size < TAG_LENGTH + MINIMAL_STRING_SIZE)
        abort_crypto_lib("Could not parse asymmetric signature item: illegal size");
      break;
    default:
      abort_crypto_lib("Found illegal tag during deserialization");
  }
  /*@ if (!exists_t<char>(forallc, (valid_ctag)(head(ccs))))
      {
        forall_t_elim(forallc, (notf)((valid_ctag)(head(ccs))), t);
        assert false;
      }
  @*/
  //@ assert true == well_formed_ccs(forallc, forallcs, nat_length(ccs), ccs);
  //@ if (kind == normal) chars_to_crypto_chars(buffer, TAG_LENGTH);
  //@ if (kind == secret) chars_to_secret_crypto_chars(buffer, TAG_LENGTH);
  //@ crypto_chars_join(buffer);
}
Ejemplo n.º 16
0
/*
 * [mk-bv-rotate-left <rational> <bv>]
 * arguments are swapped: Yices uses (rotate <bv> <rational>)
 */
static void smt_check_mk_bv_rotate_left(tstack_t *stack, stack_elem_t *f, uint32_t n) {
  check_op(stack, MK_BV_ROTATE_LEFT);
  check_size(stack, n == 2);
  check_tag(stack, f, TAG_RATIONAL);
}
Ejemplo n.º 17
0
/*
 * [mk-bv-const <value> <size>]
 * - arguments are swapped. The Yices version is (mk-bvconst <size> <value>)
 */
static void smt_check_mk_bv_const(tstack_t *stack, stack_elem_t *f, uint32_t n) {
  check_op(stack, MK_BV_CONST);
  check_size(stack, n == 2);
  check_tag(stack, f, TAG_RATIONAL);
  check_tag(stack, f+1, TAG_RATIONAL);
}
Ejemplo n.º 18
0
/*
 * SMT-LIB variant [mk-bv-zero-extend <rational> <bv>]
 * rational n = number of bits to add
 */
static void smt_check_mk_bv_zero_extend(tstack_t *stack, stack_elem_t *f, uint32_t n) {
  check_op(stack, MK_BV_ZERO_EXTEND);
  check_size(stack, n == 2);
  check_tag(stack, f, TAG_RATIONAL);
}