Exemplo n.º 1
0
int encode_to_mbs_size(const char *src, int srcsz)
{
	int unicode_size;
    wchar_t *unicode;
	//int unicode_len;
    int /*chars,*/ err;

	unicode_size = u8_wc_size(src, srcsz);
	unicode = (wchar_t *) alloca((unicode_size + 1) * sizeof(unsigned short));
	unicode[unicode_size] = L'\0';
	u8_toucs(unicode, unicode_size, src, srcsz);

    err = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode, unicode_size, NULL, 0, NULL, NULL);
    return err;
}
Exemplo n.º 2
0
int encode_to_mbs(char *dest, int sz, const char *src, int srcsz)
{
	int unicode_size;
    wchar_t *unicode;
	//int unicode_len;
    int /*chars,*/ err;

	unicode_size = u8_wc_size(src, srcsz);
	unicode = (wchar_t *) alloca((unicode_size + 1) * sizeof(unsigned short));
	unicode[unicode_size] = L'\0';
	u8_toucs(unicode, unicode_size, src, srcsz);

    err = WideCharToMultiByte(GetConsoleCP(), WC_COMPOSITECHECK, unicode, unicode_size, dest, sz, NULL, NULL);
    if(err < 1)
    {
        fprintf(stderr, "Unicode translation error %d\n", GetLastError());
        return -1;
    }

    return err;
}
Exemplo n.º 3
0
static Something systemSystem(Thread *thread) {
    char *command = stringToChar(stackGetVariable(0, thread).object->value);
    FILE *f = popen(command, "r");
    free(command);
    
    if (!f) {
        return NOTHINGNESS;
    }
    
    size_t bufferUsedSize = 0;
    int bufferSize = 50;
    Object *buffer = newArray(bufferSize);
    
    while (fgets((char *)buffer->value + bufferUsedSize, bufferSize - (int)bufferUsedSize, f) != NULL) {
        bufferUsedSize = strlen(buffer->value);
        
        if (bufferSize - bufferUsedSize < 2) {
            bufferSize *= 2;
            buffer = resizeArray(buffer, bufferSize);
        }
    }
    
    bufferUsedSize = strlen(buffer->value);
    
    EmojicodeInteger len = u8_strlen_l(buffer->value, bufferUsedSize);
    
    Object *so = newObject(CL_STRING);
    stackSetVariable(0, somethingObject(so), thread);
    String *string = so->value;
    string->length = len;
    
    Object *chars = newArray(len * sizeof(EmojicodeChar));
    string = stackGetVariable(0, thread).object->value;
    string->characters = chars;
    
    u8_toucs(characters(string), len, buffer->value, bufferUsedSize);
    
    return stackGetVariable(0, thread);
}
Exemplo n.º 4
0
static void systemSystem(Thread *thread) {
    FILE *f = popen(stringToCString(thread->variable(0).object), "r");

    if (f == nullptr) {
        thread->returnNothingnessFromFunction();
        return;
    }

    size_t bufferUsedSize = 0;
    int bufferSize = 50;
    auto buffer = thread->retain(newArray(bufferSize));

    while (fgets(buffer->val<char>() + bufferUsedSize, bufferSize - (int)bufferUsedSize, f) != nullptr) {
        bufferUsedSize = strlen(buffer->val<char>());

        if (bufferSize - bufferUsedSize < 2) {
            bufferSize *= 2;
            buffer = resizeArray(buffer.unretainedPointer(), bufferSize, thread);
        }
    }

    bufferUsedSize = strlen(buffer->val<char>());

    EmojicodeInteger len = u8_strlen_l(buffer->val<char>(), bufferUsedSize);

    auto so = thread->retain(newObject(CL_STRING));
    auto *string = so->val<String>();
    string->length = len;

    Object *chars = newArray(len * sizeof(EmojicodeChar));
    string = so->val<String>();
    string->charactersObject = chars;

    u8_toucs(string->characters(), len, buffer->val<char>(), bufferUsedSize);
    thread->release(2);
    thread->returnFromFunction(so.unretainedPointer());
}
Exemplo n.º 5
0
int unichars(const char* src)
{
   long ssz = strlen(src);
   u_int32_t* unic = NULL;
   u_int32_t* myunic = NULL;
   char* mys = NULL;

   int i = 0;
   int j = 0;
   int n = 0, nn = 0;
   int m = 0;
   bool repeated = false;

   unic = (u_int32_t*) malloc(ssz*sizeof(u_int32_t));
   myunic = (u_int32_t*) malloc(ssz*sizeof(u_int32_t));
   mys = (char*) malloc(ssz*sizeof(char));

   if(unic==NULL)
	exit(1);
   else if(myunic==NULL)
   {
	free(unic);
	exit(2);
   }
   else if(mys==NULL)
   {
	free(unic);
	free(myunic);
	exit(3);
   }

   m = u8_toucs(unic, ssz, (char*)src, -1);

   for(i=0; i<m; i++)
   {
	repeated = false;
	for(j=0; j<i; j++)
	{
	   if(unic[i] == unic[j])
	   {
		repeated = true;
		break;
	   }
	}
	if(unic[i]>127 && !repeated)
	   myunic[n++] = unic[i];
   }
   myunic[n] = 0;

   nn = u8_toutf8(mys, ssz, myunic, -1);

   printf("\n*************************\n");
   printf("%s", mys);
   printf("\n*************************\n");

   free(mys);
   free(unic);
   free(myunic);

   return nn;
}