View Issue Details

IDProjectCategoryView StatusLast Update
0000435LDMud 3.5Efunspublic2019-09-24 08:24
Reporteriago3Assigned ToGnomi  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Summary0000435: New efun: wcstombs()
Description==Edits to func_spec=========================================================

string wcstombs(int|int*);

==Edits to efuns.c===========================================================

#include <wchar.h>
#include <wctype.h>

/*-------------------------------------------------------------------------*/
svalue_t *
f_wcstombs (svalue_t * sp)

/* EFUN wcstombs()
 *
 * string wcstombs(int wchar|int *wchars)
 *
 * Takes a wide character or array of wide characters and returns a multibyte string
 */

{
    char *mbdest;
    size_t len;
    wchar_t *wcdest, **wcdest_ptr;
    string_t *result;
    if(sp->type == T_POINTER) {
        vector_t *vec;
        svalue_t *svp;
        size_t i;
        vec=sp->u.vec;
        result=mstring_new_string("");
        for(i = 0, svp = vec->item; ++i <= VEC_SIZE(vec); svp++) {
            if(svp->type == T_NUMBER) {
                if(svp->u.number==0) result=mstring_append_txt(result,"\0",1);
                else if(svp->u.number>0) {
                    wcdest_ptr=xalloc(sizeof(wchar_t *));
                    wcdest=xalloc(sizeof(wchar_t)*2);
                    memset(wcdest,0,sizeof(wchar_t)*2);
                    *wcdest=(wchar_t)svp->u.number;
                    *wcdest_ptr=wcdest;
                    len=wcsrtombs(NULL,(const wchar_t **)wcdest_ptr,0,(mbstate_t *)NULL);
                    if(len>0) {
                        mbdest=xalloc(len+1);
                        memset(mbdest,0,len+1);
                        len=wcsrtombs(mbdest,(const wchar_t **)wcdest_ptr,len,(mbstate_t *)NULL);
                        if(len>0) result=mstring_append_txt(result,mbdest,len);
                        xfree(mbdest);
                    }
                    xfree(wcdest_ptr);
                    xfree(wcdest);
                }
            } else if(svp->type == T_STRING) {
                result=mstring_append_txt(result,get_txt(svp->u.str),mstrsize(svp->u.str));
            }
        }
        free_svalue(sp);
        put_string(sp,result);
    } else {
        result=mstring_new_string("");
        if(sp->u.number==0) result=mstring_append_txt(result,"\0",1);
        else if(sp->u.number>0) {
            wcdest_ptr=xalloc(sizeof(wchar_t *));
            wcdest=xalloc(sizeof(wchar_t)*2);
            memset(wcdest,0,sizeof(wchar_t)*2);
            *wcdest=(wchar_t)sp->u.number;
            *wcdest_ptr=wcdest;
            len=wcsrtombs(NULL,(const wchar_t **)wcdest_ptr,0,(mbstate_t *)NULL);
            if(len>0) {
                mbdest=xalloc(len+1);
                memset(mbdest,0,len+1);
                len=wcsrtombs(mbdest,(const wchar_t **)wcdest_ptr,len,(mbstate_t *)NULL);
                if(len>0) result=mstring_append_txt(result,mbdest,len);
                xfree(mbdest);
            }
            xfree(wcdest_ptr);
            xfree(wcdest);
        }
        free_svalue(sp);
        put_string(sp,result);
    }
    return sp;
} /* f_wcstombs() */
TagsNo tags attached.

Relationships

child of 0000432 resolvedGnomi LDMud 3.6 Add string efuns with multibyte character support 

Activities

iago3

2006-01-06 19:48

reporter   ~0000466

Explainer: This bug is desinged to add support for multibyte character sets to string efuns, as designed in bug#432

Gnomi

2019-09-24 08:24

manager   ~0002480

Implemented as efun to_text().

Issue History

Date Modified Username Field Change
2006-01-06 19:39 iago3 New Issue
2006-01-06 19:48 iago3 Note Added: 0000466
2008-07-02 01:15 Gnomi Project LDMud => LDMud 3.5
2008-07-02 01:17 Gnomi Relationship added child of 0000432
2019-09-24 08:24 Gnomi Assigned To => Gnomi
2019-09-24 08:24 Gnomi Status new => closed
2019-09-24 08:24 Gnomi Resolution open => fixed
2019-09-24 08:24 Gnomi Note Added: 0002480