/*
*******************************************************************************
*
-* Copyright (C) 2005-2010, International Business Machines
+* Copyright (C) 2005-2012, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#include "writesrc.h"
static FILE *
-usrc_createWithHeader(const char *path, const char *filename, const char *header) {
+usrc_createWithHeader(const char *path, const char *filename,
+ const char *generator, const char *header) {
char buffer[1024];
const char *p;
char *q;
time(&t);
lt=localtime(&t);
strftime(year, sizeof(year), "%Y", lt);
- strftime(buffer, sizeof(buffer), "%Y-%m-%d", lt);
- fprintf(f, header, year, filename, buffer);
+ if(generator==NULL) {
+ strftime(buffer, sizeof(buffer), "%Y-%m-%d", lt);
+ fprintf(f, header, year, filename, buffer);
+ } else {
+ fprintf(f, header, year, filename, generator);
+ }
} else {
fprintf(
stderr,
}
U_CAPI FILE * U_EXPORT2
-usrc_create(const char *path, const char *filename) {
- const char *header=
+usrc_create(const char *path, const char *filename, const char *generator) {
+ static const char *header=
"/*\n"
" * Copyright (C) 1999-%s, International Business Machines\n"
" * Corporation and others. All Rights Reserved.\n"
" *\n"
" * file name: %s\n"
" *\n"
- " * machine-generated on: %s\n"
+ " * machine-generated by: %s\n"
" */\n\n";
- return usrc_createWithHeader(path, filename, header);
+ return usrc_createWithHeader(path, filename, generator, header);
}
U_CAPI FILE * U_EXPORT2
-usrc_createTextData(const char *path, const char *filename) {
- const char *header=
+usrc_createTextData(const char *path, const char *filename, const char *generator) {
+ static const char *header=
"# Copyright (C) 1999-%s, International Business Machines\n"
"# Corporation and others. All Rights Reserved.\n"
"#\n"
"# file name: %s\n"
"#\n"
- "# machine-generated on: %s\n"
+ "# machine-generated by: %s\n"
"#\n\n";
- return usrc_createWithHeader(path, filename, header);
+ return usrc_createWithHeader(path, filename, generator, header);
}
U_CAPI void U_EXPORT2
fputs(postfix, f);
}
}
+
+U_CAPI void U_EXPORT2
+usrc_writeArrayOfMostlyInvChars(FILE *f,
+ const char *prefix,
+ const char *p, int32_t length,
+ const char *postfix) {
+ int32_t i, col;
+ int prev2, prev, c;
+
+ if(prefix!=NULL) {
+ fprintf(f, prefix, (long)length);
+ }
+ prev2=prev=-1;
+ for(i=col=0; i<length; ++i, ++col) {
+ c=(uint8_t)p[i];
+ if(i>0) {
+ /* Break long lines. Try to break at interesting places, to minimize revision diffs. */
+ if(
+ /* Very long line. */
+ col>=32 ||
+ /* Long line, break after terminating NUL. */
+ (col>=24 && prev2>=0x20 && prev==0) ||
+ /* Medium-long line, break before non-NUL, non-character byte. */
+ (col>=16 && (prev==0 || prev>=0x20) && 0<c && c<0x20)
+ ) {
+ fputs(",\n", f);
+ col=0;
+ } else {
+ fputc(',', f);
+ }
+ }
+ fprintf(f, c<0x20 ? "%u" : "'%c'", c);
+ prev2=prev;
+ prev=c;
+ }
+ if(postfix!=NULL) {
+ fputs(postfix, f);
+ }
+}