Esempio n. 1
0
File: ssl.c Progetto: ezc/elinks
static void
init_gnutls(struct module *module)
{
	int ret = gnutls_global_init();
	unsigned char *ca_file = get_opt_str("connection.ssl.trusted_ca_file",
					     NULL);

	if (ret < 0)
		INTERNAL("GNUTLS init failed: %s", gnutls_strerror(ret));

	ret = gnutls_anon_allocate_client_credentials(&anon_cred);
	if (ret < 0)
		INTERNAL("GNUTLS anon credentials alloc failed: %s",
			 gnutls_strerror(ret));

	ret = gnutls_certificate_allocate_credentials(&xcred);
	if (ret < 0)
		INTERNAL("GNUTLS X509 credentials alloc failed: %s",
			 gnutls_strerror(ret));
	/* Here, we should load certificate files etc. */
	if (*ca_file) {
		/* FIXME: check returned values. --witekfl */
		gnutls_certificate_set_x509_trust_file(xcred, ca_file,
			GNUTLS_X509_FMT_PEM);

		gnutls_certificate_set_verify_flags(xcred,
				GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
	}

}
Esempio n. 2
0
/*
* Routine: int dist_weight
* Purpose: return the weight of a particular member of a distribution
* Algorithm:
* Data Structures:
*
* Params:	distribution *d
*			int index: which "row"
*			int wset: which set of weights
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: 
*	20000405 need to add error checking
*/
int
dist_weight(int *dest, char *d, int index, int wset)
{
	d_idx_t *d_idx;
	dist_t *dist;
	int res;
	
	if ((d_idx = find_dist(d)) == NULL)
	{
		char msg[80];
		sprintf(msg, "Invalid distribution name '%s'", d);
		INTERNAL(msg);
	}
	
	dist = d_idx->dist;
	
	res = dist->weight_sets[wset - 1][index - 1];
	/* reverse the accumulation of weights */
	if (index > 1)
		res -= dist->weight_sets[wset - 1][index - 2];
	
	if (dest == NULL)
		return(res);
	
	*dest = res;
	
	return(0);
}
Esempio n. 3
0
Error registerReplaceHook(const std::string& name, 
                          CCODE hook,
                          CCODE* pOriginal)
{
   // ensure a name was passed
   if (name.empty())
      return Error(errc::SymbolNotFoundError, ERROR_LOCATION);
   
   // find SEXP for function
   SEXP symbolSEXP = Rf_install(name.c_str());
   SEXP functionSEXP = INTERNAL(symbolSEXP) ;
   if (functionSEXP == R_NilValue || functionSEXP == R_UnboundValue)
   {
      functionSEXP = SYMVALUE(symbolSEXP);
      if (functionSEXP == R_NilValue || functionSEXP == R_UnboundValue)
      {
         Error error = Error(errc::SymbolNotFoundError, ERROR_LOCATION);
         error.addProperty("symbol", name);
         return error;
      }
   }
   
   // provide the original to the caller if requested
   if (pOriginal != NULL)
      *pOriginal = PRIMFUN(functionSEXP);
   
   // add the hook
   SET_PRIMFUN(functionSEXP, hook);
   
   return Success();
}
Esempio n. 4
0
/*
* Routine: MakeListExpr()
* Purpose: add LIST/RANGE modifiers to an expression
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
expr_t *
MakeListExpr(int nModifier, expr_t *pExpr, int nArg)
{
	expr_t *pArgExpr;

	switch(nModifier)
	{
	case KW_LIST:
		pExpr->nValueCount = nArg;
      pExpr->nFlags |= EXPR_FL_LIST;
		break;
	case KW_ULIST:
		pExpr->nValueCount = nArg;
      pExpr->nFlags |= EXPR_FL_ULIST;
		break;
	case KW_RANGE:
		pExpr->nValueCount = 2;
      pExpr->nFlags |= EXPR_FL_RANGE;
		break;
	default:
		INTERNAL("Bad modifier in MakeListExpr()");
		break;
	}

	pArgExpr = MakeIntConstant(nArg);
	addList(pExpr->ArgList, pArgExpr);

	return(pExpr);
}
Esempio n. 5
0
draw_char_data(struct terminal *term, int x, int y, unsigned char data)
#endif /* CONFIG_UTF8 */
{
	struct screen_char *screen_char = get_char(term, x, y);

	if (!screen_char) return;

	screen_char->data = data;

#ifdef CONFIG_UTF8
#ifdef CONFIG_DEBUG
	/* Detect attempt to draw double-width char on the last
	 * column of terminal.  The unicode_to_cell(data) call is
	 * in principle wrong if CONFIG_UTF8 is defined but the
	 * charset of the terminal is not UTF-8, because @data
	 * is then a byte in that charset; but unicode_to_cell
	 * returns 1 for U+0000...U+00FF so it's not a problem.  */
	if (unicode_to_cell(data) == 2 && x + 1 > term->width)
		INTERNAL("Attempt to draw double-width glyph on last column!");
#endif /* CONFIG_DEBUG */

	if (data == UCS_NO_CHAR)
		screen_char->attr = 0;
#endif /* CONFIG_UTF8 */

	set_screen_dirty(term->screen, y, y);
}
Esempio n. 6
0
LOOKUP_TYPE *
GETFUNC_NAME (void)
{
  static size_t buffer_size;
  static union
  {
    LOOKUP_TYPE l;
    void *ptr;
  } resbuf;
  LOOKUP_TYPE *result;
  int save;

  /* Get lock.  */
  __libc_lock_lock (lock);

  result = (LOOKUP_TYPE *)
    __nss_getent ((getent_r_function) INTERNAL (REENTRANT_GETNAME),
		  &resbuf.ptr, &buffer, BUFLEN, &buffer_size,
		  H_ERRNO_VAR);

  save = errno;
  __libc_lock_unlock (lock);
  __set_errno (save);
  return result;
}
Esempio n. 7
0
unsigned int
cometd_loop_gthread_start(cometd_loop* loop)
{
  INTERNAL(loop)->thread = g_thread_new("cometd_loop_gthread_run",
                                        cometd_loop_gthread_run,
                                        loop->cometd);
	return 0;
}
Esempio n. 8
0
INT
#ifdef weak_function
weak_function
#endif
strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr,
	int base LOCALE_PARAM_PROTO)
{
  return INTERNAL (strtol) (nptr, endptr, base, 0 LOCALE_PARAM);
}
Esempio n. 9
0
File: Parser.cpp Progetto: ThQ/qd
   ulong
   Parser::parse_line(vm::OpCode* opc, std::string content, ulong start, ulong end)
   {
      INTERNAL("Parser::parse_line from %lu to %lu.\n", start, end);
      ulong result = start;
      if (end > start + 1)
      {
         opc->type = content[start];
         opc->method = content[start + 1];
         result += 2;
      }
      else
      {
         opc->type = OPC_NS_NIL;
      }

      INTERNAL("/ Parser::parse_line.\n");
      return result;
   }
Esempio n. 10
0
bool aConn::CheckIOVTotalWritten(int start, int count, int *iovEnd,
		uint32_t *totalptr, uint32_t writeret) {

	uint32_t tmptotal, total = 0;
	int i;
	int found = -1;
	int seek;
	char abc[256];

	tmptotal = 0;
	for (i = 0; i < count; i++) {
		total = total + ACONN_IOVREPLY_IOVECLEN(this,start+i);
		DBUG((ALOG_TCONN),"CONN(%p):DIFF:index:%d desc:%d ptr (%p) len %d count:%d",this,start+i,
				ISSET_AC_IOVREPLY_DESC(this,start+i,AC_IOVREPLY_DESC_WRITTEN),ACONN_IOVREPLY_IOVECBASE(this,start+i),ACONN_IOVREPLY_IOVECLEN(this,start+i),
				total);
		sprintf(abc,"Writing:start:%d count:%d writeret:%d index:%d len:%d",start,count,writeret, start+i, ACONN_IOVREPLY_IOVECLEN(this,start+i));
		hexdump((char *)ACONN_IOVREPLY_IOVECBASE(this,start+i),ACONN_IOVREPLY_IOVECLEN(this,start+i),abc,0);
		if ( total >= writeret && !tmptotal ) {
			found = i;
			tmptotal = total;
		}
	}
	*totalptr = total;
	if (tmptotal) {
		total = tmptotal;
		i = found;
	}

	if (total == writeret) {
		i++;
		*iovEnd = start + i;
		return true;

	} else if (total > writeret) {

		*iovEnd = start + i;

		total = total - ACONN_IOVREPLY_IOVECLEN(this,*iovEnd);
		DBUG(ALOG_TCONN,
				"CONN(%p):loop out i:%d ret:%d count:%d len:%d ", this, *iovEnd, writeret, total, ACONN_IOVREPLY_IOVECLEN(this,*iovEnd));

		seek = writeret - total;
		ACONN_IOVREPLY_IOVECBASE(this,*iovEnd)= (char *)(ACONN_IOVREPLY_IOVECBASE(this,*iovEnd)) + seek;
		ACONN_IOVREPLY_IOVECLEN(this,*iovEnd)= ACONN_IOVREPLY_IOVECLEN(this,*iovEnd) - seek;

	} else { // (total < writeret )
		INTERNAL(ALOG_INTERNAL, "CONN(%p):ALERT:Total:%d < write ret:%d", this,total,writeret );
		//assert(0);
	}

	return false;
}
Esempio n. 11
0
static snd_pcm_sframes_t snd_pcm_file_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
	snd_pcm_file_t *file = pcm->private_data;
	snd_pcm_sframes_t err;
	snd_pcm_uframes_t n;
	
	n = snd_pcm_frames_to_bytes(pcm, frames);
	if (file->wbuf_used_bytes + n > file->wbuf_size_bytes)
		frames = snd_pcm_bytes_to_frames(pcm, file->wbuf_size_bytes - file->wbuf_used_bytes);
	err = INTERNAL(snd_pcm_forward)(file->gen.slave, frames);
	if (err > 0) {
		file->appl_ptr = (file->appl_ptr + err) % file->wbuf_size;
		n = snd_pcm_frames_to_bytes(pcm, err);
		file->wbuf_used_bytes += n;
	}
	return err;
}
Esempio n. 12
0
/* Locates the nearest terminal color. */
static inline unsigned char
get_color(color_T color, struct rgb *palette, int level)
{
	static struct rgb_cache_entry cache[RGB_HASH_SIZE];
	struct rgb_cache_entry *rgb_cache = &cache[HASH_RGB(color, level)];

	/* Uninitialized cache entries have level set to zero. */
	if (rgb_cache->level == 0
	    || rgb_cache->level != level
	    || rgb_cache->rgb != color) {
		struct rgb rgb = INIT_RGB(color);
		unsigned char nearest_color = 0;
		int min_dist = color_distance(&rgb, &palette[0]);
		int i;

#ifdef CONFIG_DEBUG
		if (level <= 0)
			INTERNAL("get_color() called with @level <= 0");
#endif

		for (i = 1; i < level; i++) {
			int dist = color_distance(&rgb, &palette[i]);

			if (dist < min_dist) {
				min_dist = dist;
				nearest_color = i;
			}
		}

		rgb_cache->color = nearest_color;
		rgb_cache->level = level;
		rgb_cache->rgb = color;
	}

	return rgb_cache->color;
}
Esempio n. 13
0
INT
INTERNAL (strtol) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
		   int base, int group)
{
  return INTERNAL (__strtol_l) (nptr, endptr, base, group, _NL_CURRENT_LOCALE);
}
Esempio n. 14
0
INT
__strtol (const STRING_TYPE *nptr, STRING_TYPE **endptr, int base)
{
  return INTERNAL (__strtol_l) (nptr, endptr, base, 0, _NL_CURRENT_LOCALE);
}
Esempio n. 15
0
LOOKUP_TYPE *
FUNCTION_NAME (ADD_PARAMS)
{
  static size_t buffer_size;
  static LOOKUP_TYPE resbuf;
  LOOKUP_TYPE *result;
#ifdef NEED_H_ERRNO
  int h_errno_tmp = 0;
#endif

  /* Get lock.  */
  __libc_lock_lock (lock);

  if (buffer == NULL)
    {
      buffer_size = BUFLEN;
      buffer = (char *) malloc (buffer_size);
    }

#ifdef HANDLE_DIGITS_DOTS
  if (buffer != NULL)
    {
      if (__nss_hostname_digits_dots (name, &resbuf, &buffer,
				      &buffer_size, 0, &result, NULL, AF_VAL,
				      H_ERRNO_VAR_P))
	goto done;
    }
#endif

  while (buffer != NULL
	 && (INTERNAL (REENTRANT_NAME) (ADD_VARIABLES, &resbuf, buffer,
					buffer_size, &result H_ERRNO_VAR)
	     == ERANGE)
#ifdef NEED_H_ERRNO
	 && h_errno_tmp == NETDB_INTERNAL
#endif
	 )
    {
      char *new_buf;
      buffer_size *= 2;
      new_buf = (char *) realloc (buffer, buffer_size);
      if (new_buf == NULL)
	{
	  /* We are out of memory.  Free the current buffer so that the
	     process gets a chance for a normal termination.  */
	  free (buffer);
	  __set_errno (ENOMEM);
	}
      buffer = new_buf;
    }

  if (buffer == NULL)
    result = NULL;

#ifdef HANDLE_DIGITS_DOTS
done:
#endif
  /* Release lock.  */
  __libc_lock_unlock (lock);

#ifdef NEED_H_ERRNO
  if (h_errno_tmp != 0)
    __set_h_errno (h_errno_tmp);
#endif

  return result;
}
Esempio n. 16
0
File: Parser.cpp Progetto: ThQ/qd
   ulong
   Parser::parse_lines(std::string content, t::Block**& blocks)
   {
      INTERNAL("Parser::parse_lines : %s.\n", content.c_str());

      blocks = NULL;
      ulong block_count = 0;
      ulong block_rooms = 0;
      uint block_step = 10;
      uint at = 0;
      uint last_at = 0;
      t::Block* block = NULL;

      //svm::OpCode* previous_opcode = NULL;
      while ((at = content.find('\n', (size_t)last_at)) != std::string::npos)
      {
         vm::OpCode* opc = new vm::OpCode();
         last_at = Parser::parse_line(opc, content, last_at, at);
         opc->content.clear();

         if (last_at + 3 <= at && content[last_at] == ':' && content[last_at+1]=='"')
         {
            last_at += 2;
            for(; last_at < at ; ++ last_at)
            {
               if (content[last_at] != '"')
               {
                  opc->content.append(&(content[last_at]), 1);
               }
               else
               {
                  ++last_at;
                  break;
               }
            }
         }
         opc->argc = Parser::parse_arguments(content, last_at, at + 1, opc->argv);

         INTERNAL(
            "<opcode:%c%c> [%d arguments] found in content[%d:%d].\n",
            opc->type,
            opc->method,
            opc->argc,
            last_at,
            at
         );

         ASSERT_NOT_NULL(opc);

         // Current opcode marks a block start
         if (opc->type == OPC_NS_BLOCK && opc->method == OPC_BLOCK_NEW)
         {
            INTERNAL("<block:%s> found.\n", opc->content.c_str())

            //previous_opcode = NULL;

            block = new t::Block();
            t::Object::pick(block);
            block->name = opc->content;
            block->argc = opc->argc;
            block->argv = opc->argv;

            block_count ++;

            if (block_rooms < block_count)
            {
               block_rooms += block_step;
               ulong new_size = sizeof(t::Block*) * block_rooms;
               blocks = (t::Block**)REALLOC(blocks, new_size);
            }

            blocks[block_count - 1] = block;

            delete opc;
         }
         // Current opcode is a real opcode, adding to current block
         else
         {
            t::Object::assert_not_null(block);
            block->append(opc);
         }

         last_at = at + 1;
      }
      /*if (block->first_opcode != NULL)
      {
         block->last_opcode = previous_opcode;
      }*/

      INTERNAL("/ Parser::parse_lines\n");
      return block_count;
   }
Esempio n. 17
0
static inline void
scan_css_token(struct scanner *scanner, struct scanner_token *token)
{
	const unsigned char *string = scanner->position;
	unsigned char first_char = *string;
	enum css_token_type type = CSS_TOKEN_GARBAGE;
	int real_length = -1;

	assert(first_char);
	token->string = string++;

	if (is_css_char_token(first_char)) {
		type = first_char;

	} else if (is_css_digit(first_char) || first_char == '.') {
		scan_css(scanner, string, CSS_CHAR_DIGIT);

		/* First scan the full number token */
		if (*string == '.') {
			string++;

			if (is_css_digit(*string)) {
				type = CSS_TOKEN_NUMBER;
				scan_css(scanner, string, CSS_CHAR_DIGIT);
			}
		}

		/* Check what kind of number we have */
		if (*string == '%') {
			if (first_char != '.')
				type = CSS_TOKEN_PERCENTAGE;
			string++;

		} else if (!is_css_ident_start(*string)) {
			type = CSS_TOKEN_NUMBER;

		} else {
			const unsigned char *ident = string;

			scan_css(scanner, string, CSS_CHAR_IDENT);
			type = map_scanner_string(scanner, ident, string,
						  CSS_TOKEN_DIMENSION);
		}

	} else if (is_css_ident_start(first_char)) {
		scan_css(scanner, string, CSS_CHAR_IDENT);

		if (*string == '(') {
			const unsigned char *function_end = string + 1;

			/* Make sure that we have an ending ')' */
			skip_css(scanner, function_end, ')');
			if (*function_end == ')') {
				type = map_scanner_string(scanner, token->string,
						string, CSS_TOKEN_FUNCTION);

				/* If it is not a known function just skip the
				 * how arg stuff so we don't end up generating
				 * a lot of useless tokens. */
				if (type == CSS_TOKEN_FUNCTION) {
					string = function_end;

				} else if (type == CSS_TOKEN_URL) {
					/* Extracting the URL first removes any
					 * leading or ending whitespace and
					 * then see if the url is given in a
					 * string. If that is the case the
					 * string delimiters are also trimmed.
					 * This is not totally correct because
					 * we should of course handle escape
					 * sequences .. but that will have to
					 * be fixed later.  */
					const unsigned char *from = string + 1;
					const unsigned char *to = function_end - 1;

					scan_css(scanner, from, CSS_CHAR_WHITESPACE);
					scan_back_css(scanner, to, CSS_CHAR_WHITESPACE);

					if (isquote(*from)) from++;
					if (isquote(*to)) to--;

					token->string = from;
					/* Given "url( )", @to and @from will
					 * cross when they scan forwards and
					 * backwards, respectively, for a non-
					 * whitespace character, and @to - @from
					 * will be negative.  If there is
					 * anything between the parentheses,
					 * @to and @from will not cross and @to
					 * - @from will not become negative. */
					real_length = int_max(0, to - from + 1);
					string = function_end;
				}

				assert(type != CSS_TOKEN_RGB || *string == '(');
				assert(type != CSS_TOKEN_URL || *string == ')');
				assert(type != CSS_TOKEN_FUNCTION || *string == ')');
			}

			string++;

		} else {
			type = CSS_TOKEN_IDENT;
		}

	} else if (!is_css_token_start(first_char)) {
		/* TODO: Better composing of error tokens. For now we just
		 * split them down into char tokens */

	} else if (first_char == '#') {
		/* Check whether it is hexcolor or hash token */
		if (is_css_hexdigit(*string)) {
			int hexdigits;

			scan_css(scanner, string, CSS_CHAR_HEX_DIGIT);

			/* Check that the hexdigit sequence is either 3 or 6
			 * chars and it isn't just start of some non-hex ident
			 * string. */
			hexdigits = string - token->string - 1;
			if ((hexdigits == 3 || hexdigits == 6)
			    && !is_css_ident(*string)) {
				type = CSS_TOKEN_HEX_COLOR;
			} else {
				scan_css(scanner, string, CSS_CHAR_IDENT);
				type = CSS_TOKEN_HASH;
			}

		} else if (is_css_ident(*string)) {
			/* Not *_ident_start() because hashes are #<name>. */
			scan_css(scanner, string, CSS_CHAR_IDENT);
			type = CSS_TOKEN_HASH;
		}

	} else if (first_char == '@') {
		/* Compose token containing @<ident> */
		if (is_css_ident_start(*string)) {
			const unsigned char *ident = string;

			/* Scan both ident start and ident */
			scan_css(scanner, string, CSS_CHAR_IDENT);
			type = map_scanner_string(scanner, ident, string,
						  CSS_TOKEN_AT_KEYWORD);
		}

	} else if (first_char == '*') {
		if (*string == '=') {
			type = CSS_TOKEN_SELECT_CONTAINS;
			string++;
		} else {
			type = CSS_TOKEN_IDENT;
		}

	} else if (first_char == '^') {
		if (*string == '=') {
			type = CSS_TOKEN_SELECT_BEGIN;
			string++;
		}

	} else if (first_char == '$') {
		if (*string == '=') {
			type = CSS_TOKEN_SELECT_END;
			string++;
		}

	} else if (first_char == '|') {
		if (*string == '=') {
			type = CSS_TOKEN_SELECT_HYPHEN_LIST;
			string++;
		}

	} else if (first_char == '!') {
		scan_css(scanner, string, CSS_CHAR_WHITESPACE);
		if (!c_strncasecmp(string, "important", 9)) {
			type = CSS_TOKEN_IMPORTANT;
			string += 9;
		}

	} else if (isquote(first_char)) {
		/* TODO: Escaped delimiters --jonas */
		int size = scanner->end - string;
		unsigned char *string_end = memchr(string, first_char, size);

		if (string_end) {
			/* We don't want the delimiters in the token */
			token->string++;
			real_length = string_end - token->string;
			string = string_end + 1;
			type = CSS_TOKEN_STRING;
		}

	} else if (first_char == '<' || first_char == '-') {
		/* Try to navigate SGML tagsoup */

		if (*string == '/') {
			/* Some kind of SGML tag end ... better bail out screaming */
			type = CSS_TOKEN_NONE;

		} else {
			const unsigned char *sgml = string;

			/* Skip anything looking like SGML "<!--" and "-->"
			 * comments + <![CDATA[ and ]]> notations. */
			scan_css(scanner, sgml, CSS_CHAR_SGML_MARKUP);

			if (sgml - string >= 2
			    && ((first_char == '<' && *string == '!')
				|| (first_char == '-' && sgml[-1] == '>'))) {
				type = CSS_TOKEN_SKIP;
				string = sgml;
			}
		}

	} else if (first_char == '/') {
		/* Comments */
		if (*string == '*') {
			type = CSS_TOKEN_SKIP;

			for (string++; string < scanner->end; string++)
				if (*string == '*' && string[1] == '/') {
					string += 2;
					break;
				}
		}

	} else {
		INTERNAL("Someone forgot to put code for recognizing tokens "
			 "which start with '%c'.", first_char);
	}

	token->type = type;
	token->length = real_length > 0 ? real_length : string - token->string;
	token->precedence = get_css_precedence(type);
	scanner->position = string;
}
Esempio n. 18
0
/* Takes care about rendering of each listbox item. */
static int
display_listbox_item(struct listbox_item *item, void *data_, int *offset)
{
	struct listbox_context *data = (struct listbox_context *)data_;
	int len; /* Length of the current text field. */
	struct color_pair *tree_color, *text_color;
	int depth = item->depth + 1;
	int d;
	int x, y;

	tree_color = get_bfu_color(data->term, (const unsigned char *)"menu.normal");
	if (item == data->box->sel) {
		text_color = get_bfu_color(data->term, (const unsigned char *)"menu.selected");

	} else if (item->marked) {
		text_color = get_bfu_color(data->term, (const unsigned char *)"menu.marked");

	} else {
		text_color = tree_color;
	}

	y = data->widget_data->box.y + data->offset;
	for (d = 0; d < depth - 1; d++) {
		struct listbox_item *root = item;
		struct listbox_item *child = item;
		int i, x;

		for (i = depth - d; i; i--) {
			child = root;
			if (root) root = data->box->ops->get_root(root);
		}

		/* XXX */
		x = data->widget_data->box.x + d * 5;
		draw_text(data->term, x, y, (const unsigned char *)"     ", 5, 0, tree_color);

		if (root ? root->child.prev == child
			 : data->box->items->prev == child)
			continue; /* We were the last branch. */

		draw_border_char(data->term, x + 1, y, BORDER_SVLINE, tree_color);
	}

	if (depth) {
		unsigned char str[5] =
			{ 32, BORDER_SRTEE, BORDER_SHLINE, BORDER_SHLINE, 32 };
		int i;

		switch (item->type) {
		case BI_LEAF:
		case BI_SEPARATOR:
		{
			const struct listbox_item *prev;

			prev = traverse_listbox_items_list(item, data->box,
			                                   -1, 1, NULL, NULL);

			if (item == prev) {
				/* There is no visible item before @item, so it
				 * must be the first item in the listbox. */
				str[1] = BORDER_SULCORNER;
			} else {
				const struct listbox_item *next;

				next = traverse_listbox_items_list(item,
				                  data->box, 1, 1, NULL, NULL);

				if (item == next
				    || item->depth != next->depth) {
					/* There is no visible item after @item
					 * at the same depth, so it must be the
					 * last in its folder. */
					str[1] = BORDER_SDLCORNER;
				}
			}
			break;
		}
		case BI_FOLDER:
			str[0] = '[';
			str[1] = (item->expanded) ? '-' : '+';
			str[2] = ']';
			break;
		default:
			INTERNAL("Unknown item type");
			break;
		}

		if (item->marked) str[4] = '*';

		x = data->widget_data->box.x + (depth - 1) * 5;
		for (i = 0; i < 5; i++) {
			draw_border_char(data->term, x + i, y, str[i], tree_color);
		}
	}

	x = data->widget_data->box.x + depth * 5;

	if (item->type == BI_SEPARATOR) {
		int i;
		int width = data->widget_data->box.width - depth * 5;

		for (i = 0; i < width; i++) {
			draw_border_char(data->term, x + i, y, BORDER_SHLINE, text_color);
		}

	} else if (data->box->ops && data->box->ops->draw) {
		int width = data->widget_data->box.width - depth * 5;

		data->box->ops->draw(item, data, x, y, width);

	} else {
		unsigned char *text;
		const struct listbox_ops *ops = data->box->ops;
		int len_bytes;

		assert(ops && ops->get_info);

		text = ops->get_text(item, data->term);
		if (!text) return 0;

		len = strlen((const char *)text);
		int_upper_bound(&len, int_max(0, data->widget_data->box.width - depth * 5));
#ifdef CONFIG_UTF8
		if (data->term->utf8_cp)
			len_bytes = utf8_cells2bytes(text, len, NULL);
		else
#endif /* CONFIG_UTF8 */
			len_bytes = len;

		draw_text(data->term, x, y, text, len_bytes, 0, text_color);

		mem_free(text);
	}

	if (item == data->box->sel) {
		/* For blind users: */
		x = data->widget_data->box.x + 5 + item->depth * 5;
		set_cursor(data->term, x, y, 1);
		set_window_ptr(data->dlg_data->win, x, y);
	}

	data->offset++;

	return 0;
}
Esempio n. 19
0
void
draw_text(struct terminal *term, int x, int y,
	  const unsigned char *text, int length,
	  int attr, struct color_pair *color)
{
	int end_pos;
	struct screen_char *pos, *end;

	assert(text && length >= 0);
	if_assert_failed return;

	if (x >= term->width || y >= term->height) return;

#ifdef CONFIG_UTF8
	if (term->utf8_cp) {
		draw_text_utf8(term, x, y, text, length, attr, color);
		return;
	}
#endif /* CONFIG_UTF8 */

	if (length <= 0) return;
	pos = get_char(term, x, y);
	if (!pos) return;

	end_pos = int_min(length, term->width - x) - 1;

#ifdef CONFIG_DEBUG
	/* Detect attempt to set @end to a point outside @text,
	 * it may occur in case of bad calculations. --Zas */
	if (end_pos < 0) {
		INTERNAL("end_pos < 0 !!");
		end_pos = 0;
	} else {
		int textlen = strlen((const char *)text);

		if (end_pos >= textlen) {
			INTERNAL("end_pos (%d) >= text length (%d) !!", end_pos, textlen);
			end_pos = textlen - 1;
		}
	}
#endif

	end = &pos[int_max(0, end_pos)];

	if (color) {
		/* Use the last char as template. */
		end->attr = attr;
		set_term_color(end, color, 0,
			       get_opt_int_tree(term->spec, (const unsigned char *)"colors", NULL));

		for (; pos < end && *text; text++, pos++) {
			end->data = *text;
			copy_screen_chars(pos, end, 1);
		}

		end->data = *text;

	} else {
		for (; pos <= end && *text; text++, pos++) {
			pos->data = *text;
		}
	}

	set_screen_dirty(term->screen, y, y);
}
Esempio n. 20
0
File: Parser.cpp Progetto: ThQ/qd
   // TODO: Stop intensive REALLOC'ing
   uint
   Parser::parse_arguments(std::string content, ulong start, ulong end, t::Object**& argv)
   {
      INTERNAL("Parser::parse_arguments\n");
      UShort step = 0;
      std::string buff = "";
      uint argc = 0;

      for (uint i = start ; i < end ; ++ i)
      {
         char c = content[i];
         switch (step)
         {
            case 0:
               if (c == '"')
               {
                  step = 1;
               }
               else if (c == '@')
               {
                  step = 2;
               }
               else if (c == '$')
               {
                  step = 3;
               }
               else if (c == '-' || (c >= '0' && c <= '9'))
               {
                  step = 4;
                  --i;
               }
               else if (c == 'F'  || c== 'T')
               {
                  ++ argc;
                  argv = (t::Object**)REALLOC(argv, sizeof(t::Object*) * argc);
                  if (c == 'F') argv[argc - 1] = t::gFALSE;
                  else argv[argc - 1] = t::gTRUE;
                  t::Object::pick(argv[argc - 1]);
                  INTERNAL("<Bool> argument found: %d.\n", c == 'T');
               }
               else if (c == 'N')
               {
                  ++argc;
                  argv = (t::Object**)REALLOC(argv, sizeof(t::Object*) * argc);
                  ASSERT_REALLOC(argv);
                  t::Object::pick(t::gNULL);
                  argv[argc - 1] = t::gNULL;
                  INTERNAL("<Null> argument found.\n");
               }
               break;

            case 1:
               if (c == '"')
               {
                  ++ argc;
                  argv = (t::Object**)REALLOC(argv, sizeof(t::Object*) * argc);
                  t::Object* obj = t::String::build(buff);
                  t::Object::pick(obj);
                  argv[argc - 1 ] = obj;
                  buff = "";
                  step = 0;
                  INTERNAL("<String> argument found: \"%s\".\n", buff.c_str());
               }
               else
               {
                  buff.append(&c, 1);
               }
               break;

            case 2:
               ++ argc;
               argv = (t::Object**)REALLOC(argv, sizeof(t::Object*) * argc);
               argv [ argc - 1 ] = t::HeapObject::build(false, c - 48);
               t::Object::pick(argv[argc - 1]);
               step = 0;
               break;

            case 3:
               ++ argc;
               argv = (t::Object**)REALLOC(argv, sizeof(t::Object*) * argc);
               argv [ argc - 1 ] = t::HeapObject::build(true, c - 48);
               step = 0;
               break;


            case 4:
               if (c == ' ' || c == '\n')
               {
                  long len = buff.length();
                  long num = 0;
                  bool negative;
                  if ((negative = buff.find("-") != std::string::npos))
                  {
                     --len;
                  }

                  for (int i = 0 ; i < len ; ++ i)
                  {
                     num += (buff[buff.length() - 1 - i] - 48) * pow(10, i);
                  }
                  if (negative)
                  {
                     num = num * -1;
                  }
                  ++argc;
                  argv = (t::Object**)REALLOC(argv, sizeof(t::Object*) * argc);
                  argv [ argc - 1 ] = t::Int::build(num);
                  t::Object::pick(argv[argc - 1]);
                  step = 0;
                  buff = "";
               }
               else
               {
                  buff += c;
               }
               break;
         }
      }

      INTERNAL("Parser::parse_arguments\n");

      return argc;
   }
static enum dom_code
append_node_text(struct dom_config *config, struct dom_node *node)
{
	struct dom_node *prev = get_dom_node_prev(node);
	size_t length;
	struct dom_string dest;
	struct dom_string src;
	int error = 0;

	copy_struct(&src, &node->string);

	if (!prev || prev->type != DOM_NODE_TEXT) {
		/* Preserve text nodes with no one to append to. */
		if (node->type == DOM_NODE_TEXT)
			return DOM_CODE_OK;

		prev = NULL;
		set_dom_string(&dest, NULL, 0);

	} else {
		if (prev->allocated) {
			copy_struct(&dest, &prev->string);
		} else {
			set_dom_string(&dest, NULL, 0);
			if (!add_to_dom_string(&dest, prev->string.string, prev->string.length))
				return DOM_CODE_ALLOC_ERR;
			set_dom_string(&prev->string, dest.string, dest.length);
			prev->allocated = 1;
		}
	}

	length = dest.length;

	switch (node->type) {
	case DOM_NODE_CDATA_SECTION:
	case DOM_NODE_TEXT:
		if (!add_to_dom_string(&dest, src.string, src.length))
			error = 1;
		break;

	case DOM_NODE_ENTITY_REFERENCE:
		/* FIXME: Until we will have uniform encoding at this point
		 * (UTF-8) we just add the entity reference unexpanded assuming
		 * that convert_string() will eventually do the work of
		 * expanding it. */
		if (!add_to_dom_string(&dest, "&", 1)
		    || !add_to_dom_string(&dest, src.string, src.length)
		    || !add_to_dom_string(&dest, ";", 1)) {
			error = 1;
		}
		break;

	default:
		INTERNAL("Cannot append from node %d", node->type);
	}

	if (error) {
		if (prev)
			prev->string.length = length;
		else
			done_dom_string(&dest);
		return DOM_CODE_ALLOC_ERR;
	}

	if (prev) {
		copy_struct(&prev->string, &dest);

		if ((config->flags & DOM_CONFIG_NORMALIZE_WHITESPACE)
		    && node->type != DOM_NODE_ENTITY_REFERENCE) {
			/* XXX: Ignore errors since we want to always
			 * free the appended node at this point. */
			normalize_text_node_whitespace(prev);
		}

		return DOM_CODE_FREE_NODE;

	} else {
		int was_cdata_section = node->type == DOM_NODE_CDATA_SECTION;

		node->type = DOM_NODE_TEXT;
		memset(&node->data, 0, sizeof(node->data));
		node->allocated = 1;
		copy_struct(&node->string, &dest);

		if ((config->flags & DOM_CONFIG_NORMALIZE_WHITESPACE)
		    && was_cdata_section) {
			/* XXX: Ignore errors since we want to always ok the
			 * append. */
			normalize_text_node_whitespace(node);
		}

		return DOM_CODE_OK;
	}
}
Esempio n. 22
0
/* There is no `long double' type, use the `double' implementations.  */
long double
INTERNAL (__STRTOLD) (const STRING_TYPE *nptr, STRING_TYPE **endptr,
		      int group, __locale_t loc)
{
  return INTERNAL (__STRTOD) (nptr, endptr, group, loc);
}
Esempio n. 23
0
/**  Returns the internal sexp of a symbol.
  *
  *  @param sexp An R value of sexptype SYMSXP.
  *  @return The internal value of a symbol.
  */
CAMLprim value ocamlr_inspect_symsxp_internal (value sexp) {
  return(Val_sexp(INTERNAL(Sexp_val(sexp))));
}
Esempio n. 24
0
long double
weak_function
__STRTOLD (const STRING_TYPE *nptr, STRING_TYPE **endptr, __locale_t loc)
{
  return INTERNAL (__STRTOD) (nptr, endptr, 0, loc);
}
static int snd_pcm_ioplug_hw_params(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
{
	ioplug_priv_t *io = pcm->private_data;
	int err;

	INTERNAL(snd_pcm_hw_params_get_access)(params, &io->data->access);
	INTERNAL(snd_pcm_hw_params_get_format)(params, &io->data->format);
	INTERNAL(snd_pcm_hw_params_get_channels)(params, &io->data->channels);
	INTERNAL(snd_pcm_hw_params_get_rate)(params, &io->data->rate, 0);
	INTERNAL(snd_pcm_hw_params_get_period_size)(params, &io->data->period_size, 0);
	INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &io->data->buffer_size);
	if (io->data->callback->hw_params) {
		err = io->data->callback->hw_params(io->data, params);
		if (err < 0)
			return err;
		INTERNAL(snd_pcm_hw_params_get_access)(params, &io->data->access);
		INTERNAL(snd_pcm_hw_params_get_format)(params, &io->data->format);
		INTERNAL(snd_pcm_hw_params_get_channels)(params, &io->data->channels);
		INTERNAL(snd_pcm_hw_params_get_rate)(params, &io->data->rate, 0);
		INTERNAL(snd_pcm_hw_params_get_period_size)(params, &io->data->period_size, 0);
		INTERNAL(snd_pcm_hw_params_get_buffer_size)(params, &io->data->buffer_size);
	}
	return 0;
}
Esempio n. 26
0
/*
* Routine: set_pricing(int nTabId, ds_pricing_t *pPricing)
* Purpose: handle the various pricing calculations for the fact tables
* Notes:
*	the RNG usage is not kept in sync between sales pricing and returns pricing. If the calculations look wrong, it may 
*	be necessary to "waste" some RNG calls on one side or the other to bring things back in line
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
void set_pricing(int nTabId, ds_pricing_t *pPricing)
{
	static int nLastId = -1, 
		init = 0,
		nQuantityMax,
		nQuantityMin = 1;
	static decimal_t dQuantity, dMarkupMin, dDiscountMin, dWholesaleMin,
		 dMarkupMax, dDiscountMax, dWholesaleMax, dCouponMin, dCouponMax,
		 dZero, dOneHalf, d9pct, dOne, dTemp, dHundred;
	decimal_t dMarkup, dCoupon, dShipping, dDiscount, dTemp2;
	int i,
		nCashPct,
		nCreditPct,
		nCouponUsage;
	
	if (!init)
	{
		strtodec(&dMarkupMin, "0.00");
		strtodec(&dDiscountMin, "0.00");
		strtodec(&dWholesaleMin, "1.00");
		strtodec(&dCouponMin, "0.00");
		strtodec(&dZero, "0.00");
		strtodec(&dOneHalf, "0.50");
		strtodec(&d9pct, "0.09");
		strtodec(&dWholesaleMin, "1.00");
		strtodec(&dHundred, "100.00");
		strtodec(&dOne, "1.00");

		init = 1;
	}
	
	if (nTabId != nLastId)
	{
		nLastId = -1;
		for (i=0; i < MAX_LIMIT; i++)
		{
			if (nTabId == aPriceLimits[i].nId)
				nLastId = i;
		}
		if (nLastId == -1)
			INTERNAL("No pricing limits defined");
		nQuantityMax = atoi(aPriceLimits[nLastId].szQuantity);
		strtodec(&dDiscountMax, aPriceLimits[nLastId].szDiscount);
		strtodec(&dMarkupMax, aPriceLimits[nLastId].szMarkUp);
		strtodec(&dWholesaleMax, aPriceLimits[nLastId].szWholesale);
		strtodec(&dCouponMax, aPriceLimits[nLastId].szCoupon);
	}

	switch(nTabId)
	{
	case SS_PRICING:
	case CS_PRICING:
	case WS_PRICING:
	case S_PLINE_PRICING:
	case S_CLIN_PRICING:
	case S_WLIN_PRICING:
		genrand_integer(&pPricing->quantity, DIST_UNIFORM, nQuantityMin, nQuantityMax, 0, nTabId);
		itodec(&dQuantity, pPricing->quantity);
		genrand_decimal(&pPricing->wholesale_cost, DIST_UNIFORM, &dWholesaleMin, &dWholesaleMax, NULL, nTabId);

		/* ext_wholesale_cost = wholesale_cost * quantity */
		decimal_t_op(&pPricing->ext_wholesale_cost, OP_MULT, &dQuantity, &pPricing->wholesale_cost);
		
		/* list_price = wholesale_cost * (1 + markup) */
		genrand_decimal(&dMarkup, DIST_UNIFORM, &dMarkupMin, &dMarkupMax, NULL, nTabId);
		decimal_t_op(&dMarkup, OP_PLUS, &dMarkup, &dOne);
		decimal_t_op(&pPricing->list_price, OP_MULT, &pPricing->wholesale_cost, &dMarkup);
		
		/* sales_price = list_price * (1 - discount)*/
		genrand_decimal(&dDiscount, DIST_UNIFORM, &dDiscountMin, &dDiscountMax, NULL, nTabId);
		NegateDecimal(&dDiscount);
		decimal_t_op(&pPricing->ext_discount_amt, OP_PLUS, &dDiscount, &dOne);
		decimal_t_op(&pPricing->sales_price, OP_MULT, &pPricing->list_price, &pPricing->ext_discount_amt);
		
		/* ext_list_price = list_price * quantity */
		decimal_t_op(&pPricing->ext_list_price, OP_MULT, &pPricing->list_price, &dQuantity);
		
		/* ext_sales_price = sales_price * quantity */
		decimal_t_op(&pPricing->ext_sales_price, OP_MULT, &pPricing->sales_price, &dQuantity);
		
		/* ext_discount_amt = ext_list_price - ext_sales_price */
		decimal_t_op(&pPricing->ext_discount_amt, OP_MINUS, &pPricing->ext_list_price, &pPricing->ext_sales_price);
		
		/* coupon_amt = ext_sales_price * coupon */
		genrand_decimal(&dCoupon, DIST_UNIFORM, &dZero, &dOne, NULL, nTabId);
		genrand_integer(&nCouponUsage, DIST_UNIFORM, 1, 100, 0, nTabId);
		if (nCouponUsage <= 20)	/* 20% of sales employ a coupon */
			decimal_t_op(&pPricing->coupon_amt, OP_MULT, &pPricing->ext_sales_price, &dCoupon);
		else
			memcpy(&pPricing->coupon_amt, &dZero, sizeof(decimal_t));
		
		/* net_paid = ext_sales_price - coupon_amt */
		decimal_t_op(&pPricing->net_paid, OP_MINUS, &pPricing->ext_sales_price, &pPricing->coupon_amt);
		
		/* shipping_cost = list_price * shipping */
		genrand_decimal(&dShipping, DIST_UNIFORM, &dZero, &dOneHalf, NULL, nTabId);
		decimal_t_op(&pPricing->ship_cost, OP_MULT, &pPricing->list_price, &dShipping);

      /* ext_shipping_cost = shipping_cost * quantity */
		decimal_t_op(&pPricing->ext_ship_cost, OP_MULT, &pPricing->ship_cost, &dQuantity);
		
		/* net_paid_inc_ship = net_paid + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship, OP_PLUS, &pPricing->net_paid, &pPricing->ext_ship_cost);
		
		/* ext_tax = tax * net_paid */
		genrand_decimal(&pPricing->tax_pct, DIST_UNIFORM, &dZero, &d9pct, NULL, nTabId);
		decimal_t_op(&pPricing->ext_tax, OP_MULT, &pPricing->net_paid, &pPricing->tax_pct);
		
		/* net_paid_inc_tax = net_paid + ext_tax */
		decimal_t_op(&pPricing->net_paid_inc_tax, OP_PLUS, &pPricing->net_paid, &pPricing->ext_tax);
		
		/* net_paid_inc_ship_tax = net_paid_inc_tax + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship_tax, OP_PLUS, &pPricing->net_paid_inc_ship, &pPricing->ext_tax);
		
		/* net_profit = net_paid - ext_wholesale_cost */
		decimal_t_op(&pPricing->net_profit, OP_MINUS, &pPricing->net_paid, &pPricing->ext_wholesale_cost);
		break;
	case CR_PRICING:
	case SR_PRICING:
	case WR_PRICING:
		/* quantity is determined before we are called */
		/* ext_wholesale_cost = wholesale_cost * quantity */
		itodec(&dQuantity, pPricing->quantity);
		decimal_t_op(&pPricing->ext_wholesale_cost, OP_MULT, &dQuantity, &pPricing->wholesale_cost);
		
		/* ext_list_price = list_price * quantity */
		decimal_t_op(&pPricing->ext_list_price, OP_MULT, &pPricing->list_price, &dQuantity);
		
		/* ext_sales_price = sales_price * quantity */
		decimal_t_op(&pPricing->ext_sales_price, OP_MULT, &pPricing->sales_price, &dQuantity);
		
		/* net_paid = ext_list_price (couppons don't effect returns) */
		memcpy(&pPricing->net_paid, &pPricing->ext_sales_price, sizeof(decimal_t));
		
		/* shipping_cost = list_price * shipping */
		genrand_decimal(&dShipping, DIST_UNIFORM, &dZero, &dOneHalf, NULL, nTabId);
		decimal_t_op(&pPricing->ship_cost, OP_MULT, &pPricing->list_price, &dShipping);

      /* ext_shipping_cost = shipping_cost * quantity */
		decimal_t_op(&pPricing->ext_ship_cost, OP_MULT, &pPricing->ship_cost, &dQuantity);
				
		/* net_paid_inc_ship = net_paid + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship, OP_PLUS, &pPricing->net_paid, &pPricing->ext_ship_cost);
		
		/* ext_tax = tax * net_paid */
		decimal_t_op(&pPricing->ext_tax, OP_MULT, &pPricing->net_paid, &pPricing->tax_pct);
		
		/* net_paid_inc_tax = net_paid + ext_tax */
		decimal_t_op(&pPricing->net_paid_inc_tax, OP_PLUS, &pPricing->net_paid, &pPricing->ext_tax);
		
		/* net_paid_inc_ship_tax = net_paid_inc_tax + ext_shipping_cost */
		decimal_t_op(&pPricing->net_paid_inc_ship_tax, OP_PLUS, &pPricing->net_paid_inc_ship, &pPricing->ext_tax);
		
		/* net_profit = net_paid - ext_wholesale_cost */
		decimal_t_op(&pPricing->net_profit, OP_MINUS, &pPricing->net_paid, &pPricing->ext_wholesale_cost);
		
		/* see to it that the returned amounts add up to the total returned */
		/* allocate some of return to cash */
		genrand_integer(&nCashPct, DIST_UNIFORM, 0, 100, 0, nTabId);
		itodec(&dTemp, nCashPct);
		decimal_t_op(&pPricing->refunded_cash, OP_DIV, &dTemp, &dHundred);
		decimal_t_op(&pPricing->refunded_cash, OP_MULT, &pPricing->refunded_cash, &pPricing->net_paid);
		
		/* allocate some to reversed charges */
		genrand_integer(&nCreditPct, DIST_UNIFORM, 1, 100, 0, nTabId);
		itodec(&dTemp2, nCreditPct);
		decimal_t_op(&dTemp, OP_DIV, &dTemp2, &dHundred);
		decimal_t_op(&dTemp2, OP_MINUS, &pPricing->net_paid, &pPricing->refunded_cash);
		decimal_t_op(&pPricing->reversed_charge, OP_MULT, &dTemp2, &dTemp);
		
		/* the rest is store credit */
		decimal_t_op(&pPricing->store_credit, OP_MINUS, &pPricing->net_paid, &pPricing->reversed_charge);
		decimal_t_op(&pPricing->store_credit, OP_MINUS, &pPricing->store_credit, &pPricing->refunded_cash);
		
		/* pick a fee for the return */
		genrand_decimal(&pPricing->fee, DIST_UNIFORM, &dOneHalf, &dHundred, &dZero, nTabId);
		
		/* and calculate the net effect */
		decimal_t_op(&pPricing->net_loss, OP_MINUS, &pPricing->net_paid_inc_ship_tax, &pPricing->store_credit);
		decimal_t_op(&pPricing->net_loss, OP_MINUS, &pPricing->net_loss, &pPricing->refunded_cash);
		decimal_t_op(&pPricing->net_loss, OP_MINUS, &pPricing->net_loss, &pPricing->reversed_charge);
		decimal_t_op(&pPricing->net_loss, OP_PLUS, &pPricing->net_loss, &pPricing->fee);
		break;
	}

	return;

}
Esempio n. 27
0
static int set_hw_params(snd_pcm_t *pcm,
                         snd_pcm_hw_params_t *hw_params,
                         unsigned int *rate,
                         unsigned int channels,
                         snd_pcm_format_t format,
                         snd_pcm_subformat_t subformat,
                         unsigned int *buffer_time,
                         unsigned int *period_time,
                         snd_pcm_access_t access)
{
    int err;

    /*
     * hardware parameters
     */
    err = snd_pcm_hw_params_any(pcm, hw_params);
    if (err < 0)
        return err;
    err = snd_pcm_hw_params_set_access(pcm, hw_params, access);
    if (err < 0)
        return err;
    err = snd_pcm_hw_params_set_format(pcm, hw_params, format);
    if (err < 0)
        return err;
    if (subformat != SND_PCM_SUBFORMAT_STD) {
        err = snd_pcm_hw_params_set_subformat(pcm, hw_params, subformat);
        if (err < 0)
            return err;
    }
    err = snd_pcm_hw_params_set_channels(pcm, hw_params, channels);
    if (err < 0)
        return err;
    err = INTERNAL(snd_pcm_hw_params_set_rate_near)(pcm, hw_params, rate, 0);
    if (err < 0)
        return err;
    err = INTERNAL(snd_pcm_hw_params_set_buffer_time_near)(pcm, hw_params, buffer_time, NULL);
    if (err < 0)
        return err;
    if (period_time == NULL || *period_time == 0) {
        unsigned int periods = 3;
        err = INTERNAL(snd_pcm_hw_params_set_periods_near)(pcm, hw_params, &periods, NULL);
        if (err < 0)
            return err;
        if (periods == 1)
            return -EINVAL;
        if (*period_time == 0) {
            err = INTERNAL(snd_pcm_hw_params_get_period_time)(hw_params, period_time, NULL);
            if (err < 0)
                return err;
        }
    } else {
        err = snd_pcm_hw_params_set_period_time(pcm, hw_params, *period_time, 0);
        if (err < 0)
            return err;
        if (*buffer_time == *period_time)
            return -EINVAL;
    }
    err = snd_pcm_hw_params(pcm, hw_params);
    if (err < 0)
        return err;
    return 0;
}
Esempio n. 28
0
/* Many execution paths may lead to this code so it needs to take appropriate
 * precausions to stuff like doc_view and doc_view->vs being NULL. */
enum frame_event_status
do_action(struct session *ses, enum main_action action_id, int verbose)
{
	enum frame_event_status status = FRAME_EVENT_OK;
	struct terminal *term = ses->tab->term;
	struct document_view *doc_view = current_frame(ses);
	struct link *link = NULL;

	if (action_id == -1) goto unknown_action;

	if (doc_view && doc_view->vs) {
		if (action_prefix_is_link_number(KEYMAP_MAIN, action_id)
		    && !try_jump_to_link_number(ses, doc_view))
			goto ignore_action;

		link = get_current_link(doc_view);

	} else if (action_requires_view_state(KEYMAP_MAIN, action_id)) {
		goto ignore_action;
	}

	if (action_requires_location(KEYMAP_MAIN, action_id)
	    && !have_location(ses))
		return FRAME_EVENT_OK;

	if (action_requires_link(KEYMAP_MAIN, action_id)
	    && !link)
		goto ignore_action;

	if (action_requires_form(KEYMAP_MAIN, action_id)
	    && (!link || !link_is_form(link)))
		goto ignore_action;

	if (!action_is_anonymous_safe(KEYMAP_MAIN, action_id)
	    && get_cmd_opt_bool("anonymous"))
		goto ignore_action;

	/* Please keep in alphabetical order for now. Later we can sort by most
	 * used or something. */
	switch (action_id) {
		case ACT_MAIN_ABORT_CONNECTION:
			abort_loading(ses, 1);
			print_screen_status(ses);
			break;

		case ACT_MAIN_ADD_BOOKMARK:
#ifdef CONFIG_BOOKMARKS
			launch_bm_add_doc_dialog(term, NULL, ses);
#endif
			break;
		case ACT_MAIN_ADD_BOOKMARK_LINK:
#ifdef CONFIG_BOOKMARKS
			launch_bm_add_link_dialog(term, NULL, ses);
#endif
			break;
		case ACT_MAIN_ADD_BOOKMARK_TABS:
#ifdef CONFIG_BOOKMARKS
			bookmark_terminal_tabs_dialog(term);
#endif
			break;

		case ACT_MAIN_AUTH_MANAGER:
			auth_manager(ses);
			break;

		case ACT_MAIN_BACKSPACE_PREFIX:

			if (!ses->kbdprefix.repeat_count) break;

			set_kbd_repeat_count(ses,
			                     ses->kbdprefix.repeat_count / 10);

			/* Keep send_event from resetting repeat_count. */
			status = FRAME_EVENT_SESSION_DESTROYED;

			break;

		case ACT_MAIN_BOOKMARK_MANAGER:
#ifdef CONFIG_BOOKMARKS
			bookmark_manager(ses);
#endif
			break;

		case ACT_MAIN_CACHE_MANAGER:
			cache_manager(ses);
			break;

		case ACT_MAIN_CACHE_MINIMIZE:
			shrink_memory(1);
			break;

		case ACT_MAIN_COOKIES_LOAD:
#ifdef CONFIG_COOKIES
			if (!get_opt_bool("cookies.save", NULL)) break;
			load_cookies();
#endif
			break;

		case ACT_MAIN_COOKIE_MANAGER:
#ifdef CONFIG_COOKIES
			cookie_manager(ses);
#endif
			break;

		case ACT_MAIN_COPY_CLIPBOARD:
			status = copy_current_link_to_clipboard(ses, doc_view, 0);
			break;

		case ACT_MAIN_DOCUMENT_INFO:
			document_info_dialog(ses);
			break;

		case ACT_MAIN_DOWNLOAD_MANAGER:
			download_manager(ses);
			break;

		case ACT_MAIN_EXMODE:
#ifdef CONFIG_EXMODE
			exmode_start(ses);
#endif
			break;

		case ACT_MAIN_FILE_MENU:
			activate_bfu_technology(ses, 0);
			break;

		case ACT_MAIN_FIND_NEXT:
			status = find_next(ses, doc_view, 1);
			break;

		case ACT_MAIN_FIND_NEXT_BACK:
			status = find_next(ses, doc_view, -1);
			break;

		case ACT_MAIN_FORGET_CREDENTIALS:
			free_auth();
			shrink_memory(1); /* flush caches */
			break;

		case ACT_MAIN_FORMHIST_MANAGER:
#ifdef CONFIG_FORMHIST
			formhist_manager(ses);
#endif
			break;

		case ACT_MAIN_FRAME_EXTERNAL_COMMAND:
			status = pass_uri_to_command(ses, doc_view,
			                             PASS_URI_FRAME);
			break;

		case ACT_MAIN_FRAME_NEXT:
			next_frame(ses, 1);
			draw_formatted(ses, 0);
			break;

		case ACT_MAIN_FRAME_MAXIMIZE:
			status = set_frame(ses, doc_view, 0);
			break;

		case ACT_MAIN_FRAME_PREV:
			next_frame(ses, -1);
			draw_formatted(ses, 0);
			break;

		case ACT_MAIN_GOTO_URL:
			goto_url_action(ses, NULL);
			break;

		case ACT_MAIN_GOTO_URL_CURRENT:
			goto_url_action(ses, get_current_url);
			break;

		case ACT_MAIN_GOTO_URL_CURRENT_LINK:
			goto_url_action(ses, get_current_link_url);
			break;

		case ACT_MAIN_GOTO_URL_HOME:
			goto_url_home(ses);
			break;

		case ACT_MAIN_HEADER_INFO:
			protocol_header_dialog(ses);
			break;

		case ACT_MAIN_HISTORY_MANAGER:
#ifdef CONFIG_GLOBHIST
			history_manager(ses);
#endif
			break;

		case ACT_MAIN_HISTORY_MOVE_BACK:
		{
			int count = int_max(1, eat_kbd_repeat_count(ses));

			go_history_by_n(ses, -count);
			break;
		}
		case ACT_MAIN_HISTORY_MOVE_FORWARD:
		{
			int count = int_max(1, eat_kbd_repeat_count(ses));

			go_history_by_n(ses, count);
			break;
		}
		case ACT_MAIN_JUMP_TO_LINK:
			break;

		case ACT_MAIN_KEYBINDING_MANAGER:
			keybinding_manager(ses);
			break;

		case ACT_MAIN_KILL_BACKGROUNDED_CONNECTIONS:
			abort_background_connections();
			break;

		case ACT_MAIN_LINK_DIALOG:
			open_link_dialog(ses);
			break;

		case ACT_MAIN_LINK_DOWNLOAD:
		case ACT_MAIN_LINK_DOWNLOAD_IMAGE:
		case ACT_MAIN_LINK_DOWNLOAD_RESUME:
			status = download_link(ses, doc_view, action_id);
			break;

		case ACT_MAIN_LINK_EXTERNAL_COMMAND:
			status = pass_uri_to_command(ses, doc_view,
			                             PASS_URI_LINK);
			break;

		case ACT_MAIN_LINK_FOLLOW:
			status = enter(ses, doc_view, 0);
			break;

		case ACT_MAIN_LINK_FOLLOW_RELOAD:
			status = enter(ses, doc_view, 1);
			break;

		case ACT_MAIN_LINK_INFO:
			link_info_dialog(ses);
			break;
			
		case ACT_MAIN_LINK_MENU:
			link_menu(term, NULL, ses);
			break;

		case ACT_MAIN_LINK_FORM_MENU:
			link_form_menu(ses);
			break;

		case ACT_MAIN_LUA_CONSOLE:
#ifdef CONFIG_SCRIPTING_LUA
			trigger_event_name("dialog-lua-console", ses);
#endif
			break;

		case ACT_MAIN_MARK_SET:
#ifdef CONFIG_MARKS
			ses->kbdprefix.mark = KP_MARK_SET;
			status = FRAME_EVENT_REFRESH;
#endif
			break;

		case ACT_MAIN_MARK_GOTO:
#ifdef CONFIG_MARKS
			/* TODO: Show promptly a menu (or even listbox?)
			 * with all the marks. But the next letter must
			 * still choose a mark directly! --pasky */
			ses->kbdprefix.mark = KP_MARK_GOTO;
			status = FRAME_EVENT_REFRESH;
#endif
			break;

		case ACT_MAIN_MENU:
			activate_bfu_technology(ses, -1);
			break;

		case ACT_MAIN_MOVE_CURRENT_TOP:
			status = move_current_top(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_CURSOR_UP:
			status = move_cursor_up(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_CURSOR_DOWN:
			status = move_cursor_down(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_CURSOR_LEFT:
			status = move_cursor_left(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_CURSOR_RIGHT:
			status = move_cursor_right(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_CURSOR_LINE_START:
			status = move_cursor_line_start(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_HALF_PAGE_DOWN:
			status = move_half_page_down(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_HALF_PAGE_UP:
			status = move_half_page_up(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_DOWN:
			status = move_link_down(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_DOWN_LINE:
			status = move_link_down_line(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_LEFT:
			status = move_link_left(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_LEFT_LINE:
			status = move_link_prev_line(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_NEXT:
			status = move_link_next(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_PREV:
			status = move_link_prev(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_RIGHT:
			status = move_link_right(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_RIGHT_LINE:
			status = move_link_next_line(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_UP:
			status = move_link_up(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_LINK_UP_LINE:
			status = move_link_up_line(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_PAGE_DOWN:
			status = move_page_down(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_PAGE_UP:
			status = move_page_up(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_DOCUMENT_START:
			status = move_document_start(ses, doc_view);
			break;

		case ACT_MAIN_MOVE_DOCUMENT_END:
			status = move_document_end(ses, doc_view);
			break;

		case ACT_MAIN_OPEN_LINK_IN_NEW_TAB:
			open_current_link_in_new_tab(ses, 0);
			break;

		case ACT_MAIN_OPEN_LINK_IN_NEW_TAB_IN_BACKGROUND:
			open_current_link_in_new_tab(ses, 1);
			break;

		case ACT_MAIN_OPEN_LINK_IN_NEW_WINDOW:
			open_in_new_window(term, send_open_in_new_window, ses);
			break;

		case ACT_MAIN_OPEN_NEW_TAB:
			open_uri_in_new_tab(ses, NULL, 0, 1);
			break;

		case ACT_MAIN_OPEN_NEW_TAB_IN_BACKGROUND:
			open_uri_in_new_tab(ses, NULL, 1, 1);
			break;

		case ACT_MAIN_OPEN_NEW_WINDOW:
			open_in_new_window(term, send_open_new_window, ses);
			break;

		case ACT_MAIN_OPEN_OS_SHELL:
			exec_shell(term);
			break;

		case ACT_MAIN_OPTIONS_MANAGER:
			options_manager(ses);
			break;

		case ACT_MAIN_QUIT:
			exit_prog(ses, 1);
			break;

		case ACT_MAIN_REALLY_QUIT:
			exit_prog(ses, 0);
			break;

		case ACT_MAIN_REDRAW:
			redraw_terminal_cls(term);
			break;

		case ACT_MAIN_RELOAD:
			reload(ses, CACHE_MODE_INCREMENT);
			break;

		case ACT_MAIN_RERENDER:
			draw_formatted(ses, 2);
			break;

		case ACT_MAIN_RESET_FORM:
			status = reset_form(ses, doc_view, 0);
			break;

		case ACT_MAIN_RESOURCE_INFO:
			resource_info(term);
			break;

		case ACT_MAIN_SAVE_AS:
			status = save_as(ses, doc_view, 0);
			break;

		case ACT_MAIN_SAVE_FORMATTED:
			status = save_formatted_dlg(ses, doc_view, 0);
			break;

		case ACT_MAIN_SAVE_OPTIONS:
			write_config(term);
			break;

		case ACT_MAIN_SAVE_URL_AS:
			save_url_as(ses);
			break;

		case ACT_MAIN_SCROLL_DOWN:
			status = scroll_down(ses, doc_view);
			break;

		case ACT_MAIN_SCROLL_LEFT:
			status = scroll_left(ses, doc_view);
			break;

		case ACT_MAIN_SCROLL_RIGHT:
			status = scroll_right(ses, doc_view);
			break;

		case ACT_MAIN_SCROLL_UP:
			status = scroll_up(ses, doc_view);
			break;

		case ACT_MAIN_SEARCH:
			status = search_dlg(ses, doc_view, 1);
			break;

		case ACT_MAIN_SEARCH_BACK:
			status = search_dlg(ses, doc_view, -1);
			break;

		case ACT_MAIN_SEARCH_TYPEAHEAD:
		case ACT_MAIN_SEARCH_TYPEAHEAD_LINK:
		case ACT_MAIN_SEARCH_TYPEAHEAD_TEXT:
		case ACT_MAIN_SEARCH_TYPEAHEAD_TEXT_BACK:
			status = search_typeahead(ses, doc_view, action_id);
			break;

		case ACT_MAIN_SHOW_TERM_OPTIONS:
			terminal_options(term, NULL, ses);
			break;

		case ACT_MAIN_SUBMIT_FORM:
			status = submit_form(ses, doc_view, 0);
			break;

		case ACT_MAIN_SUBMIT_FORM_RELOAD:
			status = submit_form(ses, doc_view, 1);
			break;

		case ACT_MAIN_TAB_CLOSE:
			close_tab(term, ses);
			status = FRAME_EVENT_SESSION_DESTROYED;
			break;

		case ACT_MAIN_TAB_CLOSE_ALL_BUT_CURRENT:
			close_all_tabs_but_current(ses);
			break;

		case ACT_MAIN_TAB_EXTERNAL_COMMAND:
			status = pass_uri_to_command(ses, doc_view,
			                             PASS_URI_TAB);
			break;

		case ACT_MAIN_TAB_MOVE_LEFT:
			move_current_tab(ses, -1);
			break;

		case ACT_MAIN_TAB_MOVE_RIGHT:
			move_current_tab(ses, 1);
			break;

		case ACT_MAIN_TAB_MENU:
			assert(ses->tab == get_current_tab(term));

			if (ses->status.show_tabs_bar)
				tab_menu(ses, ses->tab->xpos,
					 term->height - 1
					  - ses->status.show_status_bar,
					 1);
			else
				tab_menu(ses, 0, 0, 0);

			break;

		case ACT_MAIN_TAB_NEXT:
			switch_current_tab(ses, 1);
			break;

		case ACT_MAIN_TAB_PREV:
			switch_current_tab(ses, -1);
			break;

		case ACT_MAIN_TERMINAL_RESIZE:
			resize_terminal_dialog(term);
			break;

		case ACT_MAIN_TOGGLE_CSS:
#ifdef CONFIG_CSS
			toggle_document_option(ses, "document.css.enable");
#endif
			break;

		case ACT_MAIN_TOGGLE_DISPLAY_IMAGES:
			toggle_document_option(ses, "document.browse.images.show_as_links");
			break;

		case ACT_MAIN_TOGGLE_DISPLAY_TABLES:
			toggle_document_option(ses, "document.html.display_tables");
			break;

		case ACT_MAIN_TOGGLE_DOCUMENT_COLORS:
			toggle_document_option(ses, "document.colors.use_document_colors");
			break;

		case ACT_MAIN_TOGGLE_HTML_PLAIN:
			toggle_plain_html(ses, ses->doc_view, 0);
			break;

		case ACT_MAIN_TOGGLE_MOUSE:
#ifdef CONFIG_MOUSE
			toggle_mouse();
#endif
			break;

		case ACT_MAIN_TOGGLE_NUMBERED_LINKS:
			toggle_document_option(ses, "document.browse.links.numbering");
			break;

		case ACT_MAIN_TOGGLE_PLAIN_COMPRESS_EMPTY_LINES:
			toggle_document_option(ses, "document.plain.compress_empty_lines");
			break;

		case ACT_MAIN_TOGGLE_WRAP_TEXT:
			toggle_wrap_text(ses, ses->doc_view, 0);
			break;

		case ACT_MAIN_VIEW_IMAGE:
			status = view_image(ses, doc_view, 0);
			break;

		case ACT_MAIN_SCRIPTING_FUNCTION:
		case ACT_MAIN_NONE:
		case MAIN_ACTIONS:
		default:
unknown_action:
			if (verbose) {
				INTERNAL("No action handling defined for '%s'.",
					 get_action_name(KEYMAP_MAIN, action_id));
			}

			status = FRAME_EVENT_IGNORED;
	}

ignore_action:
	/* XXX: At this point the session may have been destroyed */

	if (status != FRAME_EVENT_SESSION_DESTROYED
	    && ses->insert_mode == INSERT_MODE_ON
	    && link != get_current_link(doc_view))
		ses->insert_mode = INSERT_MODE_OFF;

	if (status == FRAME_EVENT_REFRESH && doc_view)
		refresh_view(ses, doc_view, 0);

	return status;
}
Esempio n. 29
0
snd_pcm_sframes_t snd_pcm_generic_forward(snd_pcm_t *pcm, snd_pcm_uframes_t frames)
{
    snd_pcm_generic_t *generic = pcm->private_data;
    return INTERNAL(snd_pcm_forward)(generic->slave, frames);
}
Esempio n. 30
0
/*
* Routine: 
* Purpose: 
* Algorithm:
* Data Structures:
*
* Params:
* Returns:
* Called By: 
* Calls: 
* Assumptions:
* Side Effects:
* TODO: None
*/
int MatchDistWeight(void *dest, char *szDist, int nWeight, int nWeightSet, int ValueSet)
{
		d_idx_t *d;
		dist_t *dist;
		int	index = 0,
			dt,
			i_res,
			nRetcode;
		char *char_val;
		
		if ((d = find_dist(szDist)) == NULL)
		{
			char msg[80];
			sprintf(msg, "Invalid distribution name '%s'", szDist);
			INTERNAL(msg);
		}
		
		dist = d->dist;
		nWeight %= dist->maximums[nWeightSet - 1];
		
		while (nWeight > dist->weight_sets[nWeightSet - 1][index] && 
			index < d->length)
			index += 1;
		dt = ValueSet - 1;
		if (index >= d->length)
			index = d->length - 1;
		char_val = dist->strings + dist->value_sets[dt][index];
		
		switch(dist->type_vector[dt])
		{
		case TKN_VARCHAR:
			if (dest)
				*(char **)dest = (char *)char_val;
			break;
		case TKN_INT:
			i_res = atoi(char_val);
			if (dest)
				*(int *)dest = i_res;
			break;
		case TKN_DATE:
			if (dest == NULL)
			{
				dest = (date_t *)malloc(sizeof(date_t));
				MALLOC_CHECK(dest);
			}
			strtodt(*(date_t **)dest, char_val);
			break;
		case TKN_DECIMAL:
			if (dest == NULL)
			{
				dest = (decimal_t *)malloc(sizeof(decimal_t));
				MALLOC_CHECK(dest);
			}
			strtodec(*(decimal_t **)dest,char_val);
			break;
		}
		
		nRetcode = 1;
		index = 1;
		while (index < dist->maximums[nWeightSet - 1])
		{
			nRetcode += 1;
			index *= 2;
		}

		return(nRetcode);
}