Beispiel #1
0
/* This function concatenates messages in the queue of the specified type and
 * returns them as an SLstring.
 */
char *_pSLerr_get_error_from_queue (_pSLerr_Error_Queue_Type *q, int type)
{
   Error_Message_Type *m;
   unsigned int len;
   char *err, *err1, *err_max;
   int nl_len;

   if ((q == NULL) 
       && (NULL == (q = Default_Error_Queue)))
     return NULL;

   len = 0;
   /* Only _SLERR_MSG_ERROR type errors need \n to separate them. */
   nl_len = (type == _SLERR_MSG_ERROR) ? 1 : 0;
   m = q->head;
   while (m != NULL)
     {
	if (m->msg_type == type)
	  len += nl_len + strlen (m->msg);

	m = m->next;
     }
   
   if (len) 
     len -= nl_len;			       /* last \n not needed */

   if (NULL == (err = _pSLallocate_slstring (len)))
     return NULL;
   
   err_max = err + len;
   err1 = err;
   m = q->head;
   while (m != NULL)
     {
	if (m->msg_type == type)
	  {
	     unsigned int dlen = strlen (m->msg);
	     strcpy (err1, m->msg);
	     err1 += dlen;
	     if (nl_len && (err1 != err_max))
	       *err1++ = '\n';
	  }
	m = m->next;
     }
   *err1 = 0;
   
   return _pSLcreate_via_alloced_slstring (err, len);
}
Beispiel #2
0
/* Note, a and b may be ordinary strings.  The result is an slstring */
char *SLang_concat_slstrings (char *a, char *b)
{
   unsigned int lena, len;
   char *c;

   lena = strlen (a);
   len = lena + strlen (b);

   c = _pSLallocate_slstring (len);
   if (c == NULL)
     return NULL;

   strcpy (c, a);
   strcpy (c + lena, b);

   return _pSLcreate_via_alloced_slstring (c, len);
}
Beispiel #3
0
/* Note, a and b may be ordinary strings.  The result is an slstring */
char *SLang_concat_slstrings (char *a, char *b)
{
   unsigned int lena, lenb, len;
   char *c;

   lena = _pSLstring_bytelen (a);
   lenb = _pSLstring_bytelen (b);
   len = lena + lenb;

   c = _pSLallocate_slstring (len);
   if (c == NULL)
     return NULL;

   memcpy (c, a, lena);
   memcpy (c + lena, b, lenb);
   c[len] = 0;

   return _pSLcreate_via_alloced_slstring (c, len);
}
Beispiel #4
0
/* Returns an SLstring */
SLstr_Type *SLutf8_subst_wchar (SLuchar_Type *u, SLuchar_Type *umax,
				SLwchar_Type wch, unsigned int pos,
				int ignore_combining)
{
   SLuchar_Type *a, *a1, *b;
   unsigned int dpos;
   SLuchar_Type buf[SLUTF8_MAX_MBLEN+1];
   SLstr_Type *c;
   unsigned int n1, n2, n3, len;

   a = SLutf8_skip_chars (u, umax, pos, &dpos, ignore_combining);

   if ((dpos != pos) || (a == umax))
     {
	_pSLang_verror (SL_INDEX_ERROR, "Specified character position is invalid for string");
	return NULL;
     }

   a1 = SLutf8_skip_chars (a, umax, 1, NULL, ignore_combining);
   
   b = SLutf8_encode (wch, buf, SLUTF8_MAX_MBLEN);
   if (b == NULL)
     {
	_pSLang_verror (SL_UNICODE_ERROR, "Unable to encode wchar 0x%lX", (unsigned long)wch);
	return NULL;
     }
   
   n1 = (a-u);
   n2 = (b-buf);
   n3 = (umax-a1);
   len = n1 + n2 + n3;
   c = _pSLallocate_slstring (len);
   if (c == NULL)
     return NULL;
   
   memcpy (c, (char *)u, n1);
   memcpy (c+n1, (char *)buf, n2);
   memcpy (c+n1+n2, (char *)a1, n3);
   c[len] = 0;

   /* No need to worry about this failing-- it frees its argument */
   return _pSLcreate_via_alloced_slstring (c, len);
}