home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / tools / rbdump / uprint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-10-19  |  2.2 KB  |  82 lines

  1. /*
  2. *******************************************************************************
  3. *                                                                             *
  4. * COPYRIGHT:                                                                  *
  5. *   (C) Copyright International Business Machines Corporation, 1998, 1999     *
  6. *   Licensed Material - Program-Property of IBM - All Rights Reserved.        *
  7. *   US Government Users Restricted Rights - Use, duplication, or disclosure   *
  8. *   restricted by GSA ADP Schedule Contract with IBM Corp.                    *
  9. *                                                                             *
  10. *******************************************************************************
  11. *
  12. * File date.c
  13. *
  14. * Modification History:
  15. *
  16. *   Date        Name        Description
  17. *   06/14/99    stephen     Creation.
  18. *******************************************************************************
  19. */
  20.  
  21. #include "uprint.h"
  22.  
  23. #include "ucnv.h"
  24. #include "ustring.h"
  25.  
  26. #define BUF_SIZE 128
  27.  
  28. /* Print a ustring to the specified FILE* in the default codepage */
  29. void
  30. uprint(const UChar *s,
  31.        FILE *f,
  32.        UErrorCode *status)
  33. {
  34.   /* converter */
  35.   UConverter *converter;
  36.   char buf [BUF_SIZE];
  37.   int32_t sourceLen;
  38.   const UChar *mySource;
  39.   const UChar *mySourceEnd;
  40.   char *myTarget;
  41.   int32_t arraySize;
  42.  
  43.   if(s == 0) return;
  44.  
  45.   /* set up the conversion parameters */
  46.   sourceLen    = u_strlen(s);
  47.   mySource     = s;
  48.   mySourceEnd  = mySource + sourceLen;
  49.   myTarget     = buf;
  50.   arraySize    = BUF_SIZE;
  51.  
  52.   /* open a default converter */
  53.   converter = ucnv_open(0, status);
  54.   
  55.   /* if we failed, clean up and exit */
  56.   if(U_FAILURE(*status)) goto finish;
  57.   
  58.   /* perform the conversion */
  59.   do {
  60.     /* reset the error code */
  61.     *status = U_ZERO_ERROR;
  62.  
  63.     /* perform the conversion */
  64.     ucnv_fromUnicode(converter, &myTarget,  myTarget + arraySize,
  65.              &mySource, mySourceEnd, NULL,
  66.              TRUE, status);
  67.  
  68.     /* Write the converted data to the FILE* */
  69.     fwrite(buf, sizeof(char), myTarget - buf, f);
  70.  
  71.     /* update the conversion parameters*/
  72.     myTarget     = buf;
  73.     arraySize    = BUF_SIZE;
  74.   }
  75.   while(*status == U_INDEX_OUTOFBOUNDS_ERROR); 
  76.  
  77.  finish:
  78.   
  79.   /* close the converter */
  80.   ucnv_close(converter);
  81. }
  82.