コード例 #1
0
ファイル: wrtjava.c プロジェクト: gitpan/ponie
static void 
alias_write_java(struct SResource *res,UErrorCode *status) {
    static const char str[] = "new ICUListResourceBundle.Alias(";
    write_tabs(out);
    T_FileStream_write(out,str,uprv_strlen(str));
    
    /*str_write_java(res->u.fString.fChars,res->u.fString.fLength,FALSE,status);*/
    /*if(*res->u.fString.fChars == RES_PATH_SEPARATOR) {*/
        /* there is a path included 
        locale = u_strchr(res->u.fString.fChars +1, RES_PATH_SEPARATOR);
        *locale = 0;
        locale++;
        
        T_FileStream_write(out,"\"/",2);
        T_FileStream_write(out,apName,(int32_t)uprv_strlen(apName));
        T_FileStream_write(out,"/",1);
        T_FileStream_write(out,abName,(int32_t)uprv_strlen(abName));
        T_FileStream_write(out,"/\"+",3);
        str_write_java(locale,res->u.fString.fLength-(locale-res->u.fString.fChars),FALSE,status);
    } else {
        str_write_java(res->u.fString.fChars,res->u.fString.fLength,FALSE,status);
    }*/
    
    str_write_java(res->u.fString.fChars,res->u.fString.fLength,FALSE,status);
    
    T_FileStream_write(out,"),\n",3);
}
コード例 #2
0
ファイル: wrtjava.c プロジェクト: gitpan/ponie
/* Writing Functions */
static void 
string_write_java(struct SResource *res,UErrorCode *status) {       
    if(uprv_strcmp(srBundle->fKeys+res->fKey,"%%UCARULES")==0 ){
        char fileName[1024] ={0};
        const char* file = "UCARules.utf8";
        FileStream* datFile = NULL;
        const char* type = "new ICUListResourceBundle.ResourceString(";
        char* dest  = (char*) uprv_malloc( 8 * res->u.fString.fLength);
        int32_t len = 0;
        if(outDir){
            uprv_strcat(fileName,outDir);
            if(outDir[uprv_strlen(outDir)-1]!=U_FILE_SEP_CHAR){
                uprv_strcat(fileName,U_FILE_SEP_STRING);
            }
        }
        uprv_strcat(fileName,file);/* UCARULES.utf8 UTF-8 file */
        
        write_tabs(out);

        T_FileStream_write(out, type, (int32_t)uprv_strlen(type));
        T_FileStream_write(out, "\"", 1);
        T_FileStream_write(out, file, (int32_t)uprv_strlen(file));
        T_FileStream_write(out, "\")\n", 3);
        datFile=T_FileStream_open(fileName,"w");
        
        if(!dest){
            *status=U_MEMORY_ALLOCATION_ERROR;
        }
        
        u_strToUTF8(dest,8*res->u.fString.fLength,&len,res->u.fString.fChars,res->u.fString.fLength,status);
        if(U_FAILURE(*status)){
            T_FileStream_close(datFile);
            uprv_free(dest);
            return;
        }
        T_FileStream_write(datFile,dest,len);
        T_FileStream_close(datFile);
        uprv_free(dest);
           
    }else{
        str_write_java(res->u.fString.fChars,res->u.fString.fLength,TRUE,status);

        if(uprv_strcmp(srBundle->fKeys+res->fKey,"Rule")==0){
            UChar* buf = (UChar*) uprv_malloc(sizeof(UChar)*res->u.fString.fLength);
            uprv_memcpy(buf,res->u.fString.fChars,res->u.fString.fLength);      
            uprv_free(buf);
        }
    }

}
コード例 #3
0
static void
int_write_java(struct SResource *res,UErrorCode *status) {
    const char* intC   =  "new Integer(";
    char buf[100];
    int len =0;
    buf[0]=0;

    /* write the binary data */
    write_tabs(out);
    T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC));
    len=itostr(buf, res->u.fIntValue.fValue, 10, 0);
    T_FileStream_write(out,buf,len);
    T_FileStream_write(out,"),\n",3 );

}
コード例 #4
0
static int32_t write_utf8_file(FileStream* fileStream, UnicodeString outString)
{
    UErrorCode status = U_ZERO_ERROR;
    int32_t len = 0;

    // preflight to get the destination buffer size
    u_strToUTF8(NULL,
                0,
                &len,
                outString.getBuffer(),
                outString.length(),
                &status);

    // allocate the buffer
    char* dest = (char*)uprv_malloc(len);
    status = U_ZERO_ERROR;

    // convert the data
    u_strToUTF8(dest,
                len,
                &len,
                outString.getBuffer(),
                outString.length(),
                &status);

    // write data to out file
    int32_t ret = T_FileStream_write(fileStream, dest, len);
    uprv_free(dest);
    return (ret);
}
コード例 #5
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI void U_EXPORT2
udata_writeBlock(UNewDataMemory *pData, const void *s, int32_t length) {
    if(pData!=NULL && pData->file!=NULL) {
        if(length>0) {
            T_FileStream_write(pData->file, s, length);
        }
    }
}
コード例 #6
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI void U_EXPORT2
udata_writePadding(UNewDataMemory *pData, int32_t length) {
    static const uint8_t padding[16]={
        0xaa, 0xaa, 0xaa, 0xaa,
        0xaa, 0xaa, 0xaa, 0xaa,
        0xaa, 0xaa, 0xaa, 0xaa,
        0xaa, 0xaa, 0xaa, 0xaa
    };
    if(pData!=NULL && pData->file!=NULL) {
        while(length>=16) {
            T_FileStream_write(pData->file, padding, 16);
            length-=16;
        }
        if(length>0) {
            T_FileStream_write(pData->file, padding, length);
        }
    }
}
コード例 #7
0
ファイル: pkgtypes.c プロジェクト: venkatarajasekhar/Qt
const char *pkg_writeCharListWrap(FileStream *s, CharList *l, const char *delim, const char *brk, int32_t quote)
{
    int32_t ln = 0;
    char buffer[1024];
    while(l != NULL)
    {
        if(l->str)
        {
            uprv_strncpy(buffer, l->str, 1020);
            buffer[1019]=0;

            if(quote < 0) { /* remove quotes */
                if(buffer[uprv_strlen(buffer)-1] == '"') {
                    buffer[uprv_strlen(buffer)-1] = '\0';
                }
                if(buffer[0] == '"') {
                    uprv_strcpy(buffer, buffer+1);
                }
            } else if(quote > 0) { /* add quotes */
                if(l->str[0] != '"') {
                    uprv_strcpy(buffer, "\"");
                    uprv_strncat(buffer, l->str,1020);
                }
                if(l->str[uprv_strlen(l->str)-1] != '"') {
                    uprv_strcat(buffer, "\"");
                }
            }
            T_FileStream_write(s, buffer, (int32_t)uprv_strlen(buffer));

            ln += (int32_t)uprv_strlen(l->str);
        }

        if(l->next && delim)
        {
            if(ln > 60 && brk) {
                ln  = 0;
                T_FileStream_write(s, brk, (int32_t)uprv_strlen(brk));
            }
            T_FileStream_write(s, delim, (int32_t)uprv_strlen(delim));
        }
        l = l->next;
    }
    return NULL;
}
コード例 #8
0
ファイル: pkgtypes.c プロジェクト: venkatarajasekhar/Qt
const char *pkg_writeCharList(FileStream *s, CharList *l, const char *delim, int32_t quote)
{
    char buffer[1024];
    while(l != NULL)
    {
        if(l->str)
        {
            uprv_strncpy(buffer, l->str, 1023);
            buffer[1023]=0;
            if(uprv_strlen(l->str) >= 1023)
            {
                fprintf(stderr, "%s:%d: Internal error, line too long (greater than 1023 chars)\n",
                        __FILE__, __LINE__);
                exit(0);
            }
            if(quote < 0) { /* remove quotes */
                if(buffer[uprv_strlen(buffer)-1] == '"') {
                    buffer[uprv_strlen(buffer)-1] = '\0';
                }
                if(buffer[0] == '"') {
                    uprv_strcpy(buffer, buffer+1);
                }
            } else if(quote > 0) { /* add quotes */
                if(l->str[0] != '"') {
                    uprv_strcpy(buffer, "\"");
                    uprv_strcat(buffer, l->str);
                }
                if(l->str[uprv_strlen(l->str)-1] != '"') {
                    uprv_strcat(buffer, "\"");
                }
            }
            T_FileStream_write(s, buffer, (int32_t)uprv_strlen(buffer));
        }

        if(l->next && delim)
        {
            T_FileStream_write(s, delim, (int32_t)uprv_strlen(delim));
        }
        l = l->next;
    }
    return NULL;
}
コード例 #9
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI void U_EXPORT2
udata_writeUString(UNewDataMemory *pData, const UChar *s, int32_t length) {
    if(pData!=NULL && pData->file!=NULL) {
        if(length==-1) {
            length=u_strlen(s);
        }
        if(length>0) {
            T_FileStream_write(pData->file, s, length*sizeof(UChar));
        }
    }
}
コード例 #10
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI void U_EXPORT2
udata_writeString(UNewDataMemory *pData, const char *s, int32_t length) {
    if(pData!=NULL && pData->file!=NULL) {
        if(length==-1) {
            length=(int32_t)uprv_strlen(s);
        }
        if(length>0) {
            T_FileStream_write(pData->file, s, length);
        }
    }
}
コード例 #11
0
ファイル: wrtjava.cpp プロジェクト: AlexanderPankiv/node
static void
array_write_java(const ArrayResource *res, UErrorCode *status) {

    uint32_t  i         = 0;
    const char* arr ="new String[] { \n";
    struct SResource *current = NULL;
    UBool allStrings    = TRUE;

    if (U_FAILURE(*status)) {
        return;
    }

    if (res->fCount > 0) {

        current = res->fFirst;
        i = 0;
        while(current != NULL){
            if(!current->isString()){
                allStrings = FALSE;
                break;
            }
            current= current->fNext;
        }

        current = res->fFirst;
        if(allStrings==FALSE){
            const char* object = "new Object[]{\n";
            write_tabs(out);
            T_FileStream_write(out, object, (int32_t)uprv_strlen(object));
            tabCount++;
        }else{
            write_tabs(out);
            T_FileStream_write(out, arr, (int32_t)uprv_strlen(arr));
            tabCount++;
        }
        while (current != NULL) {
            /*if(current->isString()){
                write_tabs(out);
            }*/
            res_write_java(current, status);
            if(U_FAILURE(*status)){
                return;
            }
            i++;
            current = current->fNext;
        }
        T_FileStream_write(out,"\n",1);

        tabCount--;
        write_tabs(out);
        T_FileStream_write(out,"},\n",3);

    } else {
        write_tabs(out);
        T_FileStream_write(out,arr,(int32_t)uprv_strlen(arr));
        write_tabs(out);
        T_FileStream_write(out,"},\n",3);
    }
}
コード例 #12
0
static void
intvector_write_java( struct SResource *res, UErrorCode *status) {
    uint32_t i = 0;
    const char* intArr = "new int[] {\n";
    /* const char* intC   = "new Integer(";   */
    const char* stringArr = "new String[]{\n";
    char resKeyBuffer[8];
    const char *resname = res_getKeyString(srBundle, res, resKeyBuffer);
    char buf[100];
    int len =0;
    buf[0]=0;
    write_tabs(out);

    if(resname != NULL && uprv_strcmp(resname,"DateTimeElements")==0){
        T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr));
        tabCount++;
        for(i = 0; i<res->u.fIntVector.fCount; i++) {
            write_tabs(out);
            len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
            T_FileStream_write(out,"\"",1);
            T_FileStream_write(out,buf,len);
            T_FileStream_write(out,"\",",2);
            T_FileStream_write(out,"\n",1);
        }
    }else{
        T_FileStream_write(out, intArr, (int32_t)uprv_strlen(intArr));
        tabCount++;
        for(i = 0; i<res->u.fIntVector.fCount; i++) {
            write_tabs(out);
            /* T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC)); */
            len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
            T_FileStream_write(out,buf,len);
            /* T_FileStream_write(out,"),",2);  */
            /* T_FileStream_write(out,"\n",1);  */
            T_FileStream_write(out,",\n",2);
        }
    }
    tabCount--;
    write_tabs(out);
    T_FileStream_write(out,"},\n",3);
}
コード例 #13
0
static void write_tabs(FileStream* os){
    int i=0;
    for(;i<=tabCount;i++){
        T_FileStream_write(os,"    ",4);
    }
}
コード例 #14
0
void
bundle_write_java(struct SRBRoot *bundle, const char *outputDir,const char* outputEnc,
                  char *writtenFilename, int writtenFilenameLen,
                  const char* packageName, const char* bundleName,
                  UErrorCode *status) {

    char fileName[256] = {'\0'};
    char className[256]={'\0'};
    /*char constructor[1000] = { 0 };*/
    /*UBool j1 =FALSE;*/
    outDir = outputDir;

    start = TRUE;                        /* Reset the start indictor*/

    bName = (bundleName==NULL) ? "LocaleElements" : bundleName;
    pName = (packageName==NULL)? "com.ibm.icu.impl.data" : packageName;

    uprv_strcpy(className, bName);
    srBundle = bundle;
    if(uprv_strcmp(srBundle->fLocale,"root")!=0){
        uprv_strcat(className,"_");
        uprv_strcat(className,srBundle->fLocale);
    }
    if(outputDir){
        uprv_strcpy(fileName, outputDir);
        if(outputDir[uprv_strlen(outputDir)-1] !=U_FILE_SEP_CHAR){
            uprv_strcat(fileName,U_FILE_SEP_STRING);
        }
        uprv_strcat(fileName,className);
        uprv_strcat(fileName,".java");
    }else{
        uprv_strcat(fileName,className);
        uprv_strcat(fileName,".java");
    }

    if (writtenFilename) {
        uprv_strncpy(writtenFilename, fileName, writtenFilenameLen);
    }

    if (U_FAILURE(*status)) {
        return;
    }

    out= T_FileStream_open(fileName,"w");

    if(out==NULL){
        *status = U_FILE_ACCESS_ERROR;
        return;
    }
    if(getIncludeCopyright()){
        T_FileStream_write(out, copyRight, (int32_t)uprv_strlen(copyRight));
        T_FileStream_write(out, warningMsg, (int32_t)uprv_strlen(warningMsg));
    }
    T_FileStream_write(out,"package ",(int32_t)uprv_strlen("package "));
    T_FileStream_write(out,pName,(int32_t)uprv_strlen(pName));
    T_FileStream_write(out,";\n\n",3);
    T_FileStream_write(out, javaClass, (int32_t)uprv_strlen(javaClass));
    T_FileStream_write(out, className, (int32_t)uprv_strlen(className));
	T_FileStream_write(out, javaClass1, (int32_t)uprv_strlen(javaClass1));

    /* if(j1){
          T_FileStream_write(out, javaClass1, (int32_t)uprv_strlen(javaClass1));
       }else{
           sprintf(constructor,javaClassICU,className);
           T_FileStream_write(out, constructor, (int32_t)uprv_strlen(constructor));
       }
    */

    if(outputEnc && *outputEnc!='\0'){
        /* store the output encoding */
        enc = outputEnc;
        conv=ucnv_open(enc,status);
        if(U_FAILURE(*status)){
            return;
        }
    }
    res_write_java(bundle->fRoot, status);

    T_FileStream_write(out, closeClass, (int32_t)uprv_strlen(closeClass));

    T_FileStream_close(out);

    ucnv_close(conv);
}
コード例 #15
0
static void
table_write_java(struct SResource *res, UErrorCode *status) {
    uint32_t  i         = 0;
    UBool allStrings =TRUE;
    struct SResource *current = NULL;
    struct SResource *save = NULL;
    const char* obj = "new Object[][]{\n";

    if (U_FAILURE(*status)) {
        return ;
    }

    if (res->u.fTable.fCount > 0) {
        if(start==FALSE){
            write_tabs(out);
            T_FileStream_write(out, obj, (int32_t)uprv_strlen(obj));
            tabCount++;
        }
        start = FALSE;
        save = current = res->u.fTable.fFirst;
        i       = 0;


        while (current != NULL) {
            char currentKeyBuffer[8];
            const char *currentKeyString = res_getKeyString(srBundle, current, currentKeyBuffer);

            assert(i < res->u.fTable.fCount);
            write_tabs(out);

            T_FileStream_write(out, openBrace, 2);


            tabCount++;
            allStrings=FALSE;

            write_tabs(out);
            if(currentKeyString != NULL) {
                T_FileStream_write(out, "\"", 1);
                T_FileStream_write(out, currentKeyString,
                                   (int32_t)uprv_strlen(currentKeyString));
                T_FileStream_write(out, "\",\n", 2);

                T_FileStream_write(out, "\n", 1);
            }
            res_write_java(current, status);
            if(U_FAILURE(*status)){
                return;
            }
            i++;
            current = current->fNext;
            tabCount--;
            write_tabs(out);
            T_FileStream_write(out, "},\n", 3);
        }
        if(tabCount>4){
            tabCount--;
            write_tabs(out);
            T_FileStream_write(out, "},\n", 3);
        }

    } else {
        write_tabs(out);
        T_FileStream_write(out,obj,(int32_t)uprv_strlen(obj));

        write_tabs(out);
        T_FileStream_write(out,"},\n",3);

    }

}
コード例 #16
0
static void
bytes_write_java( struct SResource *res, UErrorCode *status) {
	const char* type  = "new byte[] {";
	const char* byteDecl = "%i, ";
    char byteBuffer[100] = { 0 };
	uint8_t*  byteArray = NULL;
    int byteIterator = 0;
	
    int32_t srcLen=res->u.fBinaryValue.fLength;
	
    if(srcLen>0 )
	{
        byteArray = res->u.fBinaryValue.fData;

        write_tabs(out);
        T_FileStream_write(out, type, (int32_t)uprv_strlen(type));
        T_FileStream_write(out, "\n", 1);
        tabCount++;

		for (;byteIterator<srcLen;byteIterator++)
		{
            if (byteIterator%16 == 0)
			{
			    write_tabs(out);
			}

			if (byteArray[byteIterator] < 128)
			{
                sprintf(byteBuffer, byteDecl, byteArray[byteIterator]);
			}
			else
			{
                sprintf(byteBuffer, byteDecl, (byteArray[byteIterator]-256));
			}

            T_FileStream_write(out, byteBuffer, (int32_t)uprv_strlen(byteBuffer));

			if (byteIterator%16 == 15)
			{
                T_FileStream_write(out, "\n", 1);
			}

		}

        if (((byteIterator-1)%16) != 15)
		{
            T_FileStream_write(out, "\n", 1);
	    }

		tabCount--;
        write_tabs(out);
		T_FileStream_write(out, "},\n", 3);

	}
	else
    {
		/* Empty array */
        write_tabs(out);
        T_FileStream_write(out,type,(int32_t)uprv_strlen(type));
		T_FileStream_write(out,"},\n",3);
    }

}
コード例 #17
0
ファイル: wrtjava.c プロジェクト: gitpan/ponie
static void 
intvector_write_java( struct SResource *res, UErrorCode *status) {
    uint32_t i = 0;
    const char* intArr = "new Integer[] {\n";
    const char* intC   = "new Integer(";
    const char* stringArr = "new String[]{\n"; 
    char buf[100];
    int len =0;
    buf[0]=0;
    write_tabs(out);

    if(uprv_strcmp(srBundle->fKeys+res->fKey,"DateTimeElements")==0){
        T_FileStream_write(out, stringArr, (int32_t)uprv_strlen(stringArr));
        tabCount++;
        for(i = 0; i<res->u.fIntVector.fCount; i++) {
            write_tabs(out);
            len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
            T_FileStream_write(out,"\"",1);
            T_FileStream_write(out,buf,len);
            T_FileStream_write(out,"\",",2);
            T_FileStream_write(out,"\n",1);
        }
    }else{
        T_FileStream_write(out, intArr, (int32_t)uprv_strlen(intArr));
        tabCount++;
        for(i = 0; i<res->u.fIntVector.fCount; i++) {
            write_tabs(out);
            T_FileStream_write(out, intC, (int32_t)uprv_strlen(intC));
            len=itostr(buf,res->u.fIntVector.fArray[i],10,0);
            T_FileStream_write(out,buf,len);
            T_FileStream_write(out,"),",2);
            T_FileStream_write(out,"\n",1);
        }
    }
    tabCount--;
    write_tabs(out);
    T_FileStream_write(out,"},\n",3);
}
コード例 #18
0
static void
str_write_java( uint16_t* src, int32_t srcLen, UBool printEndLine, UErrorCode *status){

    uint32_t length = srcLen*8;
    uint32_t bufLen = 0;
    uint32_t columnCount;
    char* buf = (char*) malloc(sizeof(char)*length);

    if(buf == NULL) {
        *status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    columnCount = getColumnCount(srcLen);
    memset(buf,0,length);

    bufLen = uCharsToChars(buf,length,src,srcLen,status);

    if(printEndLine)
        write_tabs(out);

    if(U_FAILURE(*status)){
        uprv_free(buf);
        return;
    }

    if(bufLen+(tabCount*4) > columnCount  ){
        uint32_t len = 0;
        char* current = buf;
        uint32_t add;
        while(len < bufLen){
            add = columnCount-(tabCount*4)-5/* for ", +\n */;
            current = buf +len;
            if (add < (bufLen-len)) {
                uint32_t idx = strrch(current,add,'\\');
                if (idx > add) {
                    idx = add;
                } else {
                    int32_t num =idx-1;
                    uint32_t seqLen;
                    while(num>0){
                        if(current[num]=='\\'){
                            num--;
                        }else{
                            break;
                        }
                    }
                    if ((idx-num)%2==0) {
                        idx--;
                    }
                    seqLen = (current[idx+1]=='u') ? 6 : 2;
                    if ((add-idx) < seqLen) {
                        add = idx + seqLen;
                    }
                }
            }
            T_FileStream_write(out,"\"",1);
            if(len+add<bufLen){
                T_FileStream_write(out,current,add);
                T_FileStream_write(out,"\" +\n",4);
                write_tabs(out);
            }else{
                T_FileStream_write(out,current,bufLen-len);
            }
            len+=add;
        }
    }else{
        T_FileStream_write(out,"\"",1);
        T_FileStream_write(out, buf,bufLen);
    }
    if(printEndLine){
        T_FileStream_write(out,"\",\n",3);
    }else{
        T_FileStream_write(out,"\"",1);
    }
    uprv_free(buf);
}
コード例 #19
0
ファイル: crestst.c プロジェクト: icu-project/icu4c
static void TestFileStream(void){
    int32_t c = 0;
    int32_t c1=0;
    UErrorCode status = U_ZERO_ERROR;
    const char* testdatapath = loadTestData(&status);
    char* fileName = (char*) malloc(uprv_strlen(testdatapath) +10);
    FileStream* stream = NULL;
    /* these should not be closed */
    FileStream* pStdin  = T_FileStream_stdin();
    FileStream* pStdout = T_FileStream_stdout();
    FileStream* pStderr = T_FileStream_stderr();

    const char* testline = "This is a test line";
    int32_t bufLen = (int32_t)strlen(testline)+10;
    char* buf = (char*) malloc(bufLen);
    int32_t retLen = 0;

    if(pStdin==NULL){
        log_err("failed to get T_FileStream_stdin()");
    }
    if(pStdout==NULL){
        log_err("failed to get T_FileStream_stdout()");
    }
    if(pStderr==NULL){
        log_err("failed to get T_FileStream_stderr()");
    }

    uprv_strcpy(fileName,testdatapath);
    uprv_strcat(fileName,".dat");
    stream = T_FileStream_open(fileName, "r");
    if(stream==NULL){
        log_data_err("T_FileStream_open failed to open %s\n",fileName);
    } else {
      if(!T_FileStream_file_exists(fileName)){
        log_data_err("T_FileStream_file_exists failed to verify existence of %s \n",fileName);
      }
      
      retLen=T_FileStream_read(stream,&c,1);
      if(retLen==0){
        log_data_err("T_FileStream_read failed to read from %s \n",fileName);
      }
      retLen=0;
      T_FileStream_rewind(stream);
      T_FileStream_read(stream,&c1,1);
      if(c!=c1){
        log_data_err("T_FileStream_rewind failed to rewind %s \n",fileName);
      }
      T_FileStream_rewind(stream);
      c1 = T_FileStream_peek(stream);
      if(c!=c1){
        log_data_err("T_FileStream_peek failed to peekd %s \n",fileName);
      }
      c = T_FileStream_getc(stream);
      T_FileStream_ungetc(c,stream);
      if(c!= T_FileStream_getc(stream)){
        log_data_err("T_FileStream_ungetc failed to d %s \n",fileName);
      }
      
      if(T_FileStream_size(stream)<=0){
        log_data_err("T_FileStream_size failed to d %s \n",fileName);
      }
      if(T_FileStream_error(stream)){
        log_data_err("T_FileStream_error shouldn't have an error %s\n",fileName);
      }
      if(!T_FileStream_error(NULL)){
        log_err("T_FileStream_error didn't get an error %s\n",fileName);
      }
      T_FileStream_putc(stream, 0x20);
      if(!T_FileStream_error(stream)){
        /*
          Warning 
          writing to a read-only file may not consistently fail on all platforms
          (e.g. HP-UX, FreeBSD, MacOSX)
        */
        log_verbose("T_FileStream_error didn't get an error when writing to a readonly file %s\n",fileName);
      }

      T_FileStream_close(stream);
    }
    /* test writing function */
    stream=NULL;
    uprv_strcpy(fileName,testdatapath);
    uprv_strcat(fileName,".tmp");
    stream = T_FileStream_open(fileName,"w+");

    if(stream == NULL){
        log_data_err("Could not open %s for writing\n",fileName);
    } else {
      c= '$';
      T_FileStream_putc(stream,c);
      T_FileStream_rewind(stream);
      if(c != T_FileStream_getc(stream)){
        log_data_err("T_FileStream_putc failed %s\n",fileName);
      }

      T_FileStream_rewind(stream);
      T_FileStream_writeLine(stream,testline);
      T_FileStream_rewind(stream);
      T_FileStream_readLine(stream,buf,bufLen);
      if(uprv_strncmp(testline, buf,uprv_strlen(buf))!=0){
        log_data_err("T_FileStream_writeLine failed %s\n",fileName);
      }

      T_FileStream_rewind(stream);
      T_FileStream_write(stream,testline,(int32_t)strlen(testline));
      T_FileStream_rewind(stream);
      retLen = T_FileStream_read(stream, buf, bufLen);
      if(uprv_strncmp(testline, buf,retLen)!=0){
        log_data_err("T_FileStream_write failed %s\n",fileName);
      }

      T_FileStream_close(stream);
    }
    if(!T_FileStream_remove(fileName)){
        log_data_err("T_FileStream_remove failed to delete %s\n",fileName);
    }


    free(fileName);
    free(buf);

}
コード例 #20
0
ファイル: wrtjava.cpp プロジェクト: AlexanderPankiv/node
static void
str_write_java(const UChar *src, int32_t srcLen, UBool printEndLine, UErrorCode *status) {

    uint32_t length = srcLen*8;
    uint32_t bufLen = 0;
    uint32_t columnCount;
    char* buf = (char*) malloc(sizeof(char)*length);

    if(buf == NULL) {
        *status = U_MEMORY_ALLOCATION_ERROR;
        return;
    }

    columnCount = getColumnCount(srcLen);
    memset(buf,0,length);

    bufLen = uCharsToChars(buf,length,src,srcLen,status);
    // buflen accounts for extra bytes added due to multi byte encoding of
    //        non ASCII characters
    if(printEndLine)
        write_tabs(out);

    if(U_FAILURE(*status)){
        uprv_free(buf);
        return;
    }

    if(bufLen+(tabCount*4) > columnCount  ){
        uint32_t len = 0;
        char* current = buf;
        uint32_t add;
        while(len < bufLen){
            add = columnCount-(tabCount*4)-5/* for ", +\n */;
            current = buf +len;
            if (add < (bufLen-len)) {
                uint32_t idx = strrch(current,add,'\\');
                if (idx > add) {
                    idx = add;
                } else {
                    int32_t num =idx-1;
                    uint32_t seqLen;
                    while(num>0){
                        if(current[num]=='\\'){
                            num--;
                        }else{
                            break;
                        }
                    }
                    if ((idx-num)%2==0) {
                        idx--;
                    }
                    seqLen = (current[idx+1]=='u') ? 6 : 2;
                    if ((add-idx) < seqLen) {
                        add = idx + seqLen;
                    }
                }
            }
            T_FileStream_write(out,"\"",1);
            uint32_t byteIndex = 0;
            uint32_t trailBytes = 0;
            if(len+add<bufLen){
                // check the trail bytes to be added to the output line
                while (byteIndex < add) {
                    if (U8_IS_LEAD(*(current + byteIndex))) {
                        trailBytes = U8_COUNT_TRAIL_BYTES(*(current + byteIndex));
                        add += trailBytes;
                    }
                    byteIndex++;
                }
                T_FileStream_write(out,current,add);
                if (len + add < bufLen) {
                    T_FileStream_write(out,"\" +\n",4);
                    write_tabs(out);
                }
            }else{
                T_FileStream_write(out,current,bufLen-len);
            }
            len+=add;
        }
    }else{
        T_FileStream_write(out,"\"",1);
        T_FileStream_write(out, buf,bufLen);
    }
    if(printEndLine){
        T_FileStream_write(out,"\",\n",3);
    }else{
        T_FileStream_write(out,"\"",1);
    }
    uprv_free(buf);
}
コード例 #21
0
ファイル: wrtjava.c プロジェクト: gitpan/ponie
static void 
bin_write_java( struct SResource *res, UErrorCode *status) {
    const char* type = "new ICUListResourceBundle.CompressedBinary(";
    const char* ext;
    int32_t srcLen=res->u.fBinaryValue.fLength;

    if(srcLen>0 ){
        uint16_t* target=NULL;
        uint16_t* saveTarget = NULL;
        int32_t tgtLen = 0;

        if(uprv_strcmp(srBundle->fKeys+res->fKey,"%%CollationBin")==0 || uprv_strcmp(srBundle->fKeys+res->fKey,"BreakDictionaryData")==0){
            char fileName[1024] ={0};
            char fn[1024] =  {0};
            FileStream* datFile = NULL;
            if(uprv_strcmp(srBundle->fKeys+res->fKey,"BreakDictionaryData")==0){
                uprv_strcat(fileName,"BreakDictionaryData");
                ext = ".brk";
            }else{
                uprv_strcat(fileName,"CollationElements");
                ext=".col";
            }
            if(uprv_strcmp(srBundle->fLocale,"root")!=0){
                uprv_strcat(fileName,"_");
                uprv_strcat(fileName,srBundle->fLocale);
            }
            
            uprv_strcat(fileName,ext);
            if(outDir ){
                uprv_strcat(fn,outDir);
                if(outDir[uprv_strlen(outDir)-1]!=U_FILE_SEP_CHAR){
                    uprv_strcat(fn,U_FILE_SEP_STRING);
                }
            }
            uprv_strcat(fn,fileName);
            type = "new ICUListResourceBundle.ResourceBinary(";
            write_tabs(out);
            T_FileStream_write(out, type, (int32_t)uprv_strlen(type));
            T_FileStream_write(out, "\"", 1);
            T_FileStream_write(out, fileName, (int32_t)uprv_strlen(fileName));
            T_FileStream_write(out, "\"),\n", 4);

            datFile=T_FileStream_open(fn,"w");
            T_FileStream_write(datFile, res->u.fBinaryValue.fData, res->u.fBinaryValue.fLength);
            T_FileStream_close(datFile);

        }else{

            srcLen = res->u.fBinaryValue.fLength;
            tgtLen = srcLen * 2;
            target = (uint16_t*)malloc(sizeof(uint16_t) * tgtLen);
            saveTarget  = target;
            if(target){
                tgtLen = byteArrayToRLEString(res->u.fBinaryValue.fData,
                                              srcLen,target, tgtLen,status);
                if(U_FAILURE(*status)){
                     printf("Could not encode got error : %s \n", u_errorName(*status));
                     return;
                }
#if DEBUG
                /***************** Test Roundtripping *********************/
                {
                    int32_t myTargetLen = rleStringToByteArray(target,tgtLen,NULL,0,status);
                    uint8_t* myTarget = (uint8_t*) malloc(sizeof(uint8_t) * myTargetLen);

                    /* test for NULL */
                    if(myTarget == NULL) {
                        *status = U_MEMORY_ALLOCATION_ERROR;
                        return; 
                    }

                    int i=0;
                    int32_t retVal=0;

                    *status = U_ZERO_ERROR;
                    retVal=rleStringToByteArray(target,tgtLen,myTarget,myTargetLen,status);
                    if(U_SUCCESS(*status)){

                        for(i=0; i< srcLen;i++){
                            if(res->u.fBinaryValue.fData[i]!= myTarget[i]){
                                printf("the encoded string cannot be decoded Expected : 0x%02X Got : %: 0x%02X at %i\n",res->u.fBinaryValue.fData[i],myTarget[i], i);
                            }
                        }
                    }else{
                        printf("Could not decode got error : %s \n", u_errorName(*status));
                    }
                    free(myTarget);

                }
#endif

            }else{
                *status = U_MEMORY_ALLOCATION_ERROR;
                return;
            }

            write_tabs(out);
            T_FileStream_write(out, type, (int32_t)uprv_strlen(type));
            T_FileStream_write(out, "\n", 1);
            tabCount++;
            write_tabs(out);
            str_write_java(target, tgtLen,FALSE, status);
            tabCount--;
            T_FileStream_write(out, "),\n", 3);

            free(target);

        }
    
   }else{
        write_tabs(out);
        T_FileStream_write(out,type,uprv_strlen(type));
        T_FileStream_write(out,"null),\n",7);
   }

}
コード例 #22
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI UNewDataMemory * U_EXPORT2
udata_create(const char *dir, const char *type, const char *name,
             const UDataInfo *pInfo,
             const char *comment,
             UErrorCode *pErrorCode) {
    UNewDataMemory *pData;
    uint16_t headerSize, commentLength;
    char filename[512];
    uint8_t bytes[16];
    int length;

    if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
        return NULL;
    } else if(name==NULL || *name==0 || pInfo==NULL) {
        *pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
        return NULL;
    }

    /* allocate the data structure */
    pData=(UNewDataMemory *)uprv_malloc(sizeof(UNewDataMemory));
    if(pData==NULL) {
        *pErrorCode=U_MEMORY_ALLOCATION_ERROR;
        return NULL;
    }
    
    /* Check that the full path won't be too long */
    length = 0;					/* Start with nothing */
    if(dir != NULL  && *dir !=0)	/* Add directory length if one was given */
    {
    	length += strlen(dir);
	
    	/* Add 1 if dir doesn't end with path sep */
        if (dir[strlen(dir) - 1]!= U_FILE_SEP_CHAR) {
            length++;
        }
	}
    length += strlen(name);		/* Add the filename length */

    if(type != NULL  && *type !=0) { /* Add directory length if  given */
        length += strlen(type);
    }

        
     /* LDH buffer Length error check */
    if(length  > (sizeof(filename) - 1))
    {
   	    *pErrorCode = U_BUFFER_OVERFLOW_ERROR;
   	    uprv_free(pData);
	    return NULL;
    }
   
    /* open the output file */
    if(dir!=NULL && *dir!=0) { /* if dir has a value, we prepend it to the filename */
        char *p=filename+strlen(dir);
        uprv_strcpy(filename, dir);
        if (*(p-1)!=U_FILE_SEP_CHAR) {
            *p++=U_FILE_SEP_CHAR;
            *p=0;
        }
    } else { /* otherwise, we'll output to the current dir */
        filename[0]=0;
    }
    uprv_strcat(filename, name);
    if(type!=NULL && *type!=0) {
        uprv_strcat(filename, ".");
        uprv_strcat(filename, type);
    }
    pData->file=T_FileStream_open(filename, "wb");
    if(pData->file==NULL) {
        uprv_free(pData);
        *pErrorCode=U_FILE_ACCESS_ERROR;
        return NULL;
    }

    /* write the header information */
    headerSize=(uint16_t)(pInfo->size+4);
    if(comment!=NULL && *comment!=0) {
        commentLength=(uint16_t)(uprv_strlen(comment)+1);
        headerSize+=commentLength;
    } else {
        commentLength=0;
    }

    /* write the size of the header, take padding into account */
    pData->headerSize=(uint16_t)((headerSize+15)&~0xf);
    pData->magic1=0xda;
    pData->magic2=0x27;
    T_FileStream_write(pData->file, &pData->headerSize, 4);

    /* write the information data */
    T_FileStream_write(pData->file, pInfo, pInfo->size);

    /* write the comment */
    if(commentLength>0) {
        T_FileStream_write(pData->file, comment, commentLength);
    }

    /* write padding bytes to align the data section to 16 bytes */
    headerSize&=0xf;
    if(headerSize!=0) {
        headerSize=(uint16_t)(16-headerSize);
        uprv_memset(bytes, 0, headerSize);
        T_FileStream_write(pData->file, bytes, headerSize);
    }

    return pData;
}
コード例 #23
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI void U_EXPORT2
udata_write8(UNewDataMemory *pData, uint8_t byte) {
    if(pData!=NULL && pData->file!=NULL) {
        T_FileStream_write(pData->file, &byte, 1);
    }
}
コード例 #24
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI void U_EXPORT2
udata_write16(UNewDataMemory *pData, uint16_t word) {
    if(pData!=NULL && pData->file!=NULL) {
        T_FileStream_write(pData->file, &word, 2);
    }
}
コード例 #25
0
ファイル: unewdata.c プロジェクト: venkatarajasekhar/Qt
U_CAPI void U_EXPORT2
udata_write32(UNewDataMemory *pData, uint32_t wyde) {
    if(pData!=NULL && pData->file!=NULL) {
        T_FileStream_write(pData->file, &wyde, 4);
    }
}