| OLD | NEW |
| 1 /* | 1 /* |
| 2 ****************************************************************************** | 2 ****************************************************************************** |
| 3 * | 3 * |
| 4 * Copyright (C) 2009-2012, International Business Machines | 4 * Copyright (C) 2009-2014, International Business Machines |
| 5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
| 6 * | 6 * |
| 7 ****************************************************************************** | 7 ****************************************************************************** |
| 8 * | 8 * |
| 9 * FILE NAME : icuplug.c | 9 * FILE NAME : icuplug.c |
| 10 * | 10 * |
| 11 * Date Name Description | 11 * Date Name Description |
| 12 * 10/29/2009 sl New. | 12 * 10/29/2009 sl New. |
| 13 ****************************************************************************** | 13 ****************************************************************************** |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include "unicode/icuplug.h" | 16 #include "unicode/icuplug.h" |
| 17 #include "icuplugimp.h" | 17 #include "icuplugimp.h" |
| 18 #include "cstring.h" | 18 #include "cstring.h" |
| 19 #include "cmemory.h" | 19 #include "cmemory.h" |
| 20 #include "putilimp.h" | 20 #include "putilimp.h" |
| 21 #include "ucln.h" | 21 #include "ucln.h" |
| 22 #include <stdio.h> | 22 #include <stdio.h> |
| 23 #ifdef __MVS__ /* defined by z/OS compiler */ | 23 #ifdef __MVS__ /* defined by z/OS compiler */ |
| 24 #define _POSIX_SOURCE | 24 #define _POSIX_SOURCE |
| 25 #include <cics.h> /* 12 Nov 2011 JAM iscics() function */ | 25 #include <cics.h> /* 12 Nov 2011 JAM iscics() function */ |
| 26 #endif | 26 #endif |
| 27 #include "charstr.h" |
| 28 |
| 29 using namespace icu; |
| 27 | 30 |
| 28 #ifndef UPLUG_TRACE | 31 #ifndef UPLUG_TRACE |
| 29 #define UPLUG_TRACE 0 | 32 #define UPLUG_TRACE 0 |
| 30 #endif | 33 #endif |
| 31 | 34 |
| 32 #if UPLUG_TRACE | 35 #if UPLUG_TRACE |
| 33 #include <stdio.h> | 36 #include <stdio.h> |
| 34 #define DBG(x) fprintf(stderr, "%s:%d: ",__FILE__,__LINE__); fprintf x | 37 #define DBG(x) fprintf(stderr, "%s:%d: ",__FILE__,__LINE__); fprintf x |
| 35 #endif | 38 #endif |
| 36 | 39 |
| (...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 DBG((stderr, " Done Loading Plugs. Level: %d\n", (int32_t)uplug_getCurrentLev
el())); | 695 DBG((stderr, " Done Loading Plugs. Level: %d\n", (int32_t)uplug_getCurrentLev
el())); |
| 693 #endif | 696 #endif |
| 694 } | 697 } |
| 695 | 698 |
| 696 /* Name of the plugin config file */ | 699 /* Name of the plugin config file */ |
| 697 static char plugin_file[2048] = ""; | 700 static char plugin_file[2048] = ""; |
| 698 #endif | 701 #endif |
| 699 | 702 |
| 700 U_INTERNAL const char* U_EXPORT2 | 703 U_INTERNAL const char* U_EXPORT2 |
| 701 uplug_getPluginFile() { | 704 uplug_getPluginFile() { |
| 702 #if U_ENABLE_DYLOAD | 705 #if U_ENABLE_DYLOAD && !UCONFIG_NO_FILE_IO |
| 703 return plugin_file; | 706 return plugin_file; |
| 704 #else | 707 #else |
| 705 return NULL; | 708 return NULL; |
| 706 #endif | 709 #endif |
| 707 } | 710 } |
| 708 | 711 |
| 709 | 712 |
| 710 U_CAPI void U_EXPORT2 | 713 U_CAPI void U_EXPORT2 |
| 711 uplug_init(UErrorCode *status) { | 714 uplug_init(UErrorCode *status) { |
| 712 #if !U_ENABLE_DYLOAD | 715 #if !U_ENABLE_DYLOAD |
| 713 (void)status; /* unused */ | 716 (void)status; /* unused */ |
| 714 #else | 717 #elif !UCONFIG_NO_FILE_IO |
| 715 const char *plugin_dir; | 718 CharString plugin_dir; |
| 719 const char *env = getenv("ICU_PLUGINS"); |
| 716 | 720 |
| 717 if(U_FAILURE(*status)) return; | 721 if(U_FAILURE(*status)) return; |
| 718 plugin_dir = getenv("ICU_PLUGINS"); | 722 if(env != NULL) { |
| 723 plugin_dir.append(env, -1, *status); |
| 724 } |
| 725 if(U_FAILURE(*status)) return; |
| 719 | 726 |
| 720 #if defined(DEFAULT_ICU_PLUGINS) | 727 #if defined(DEFAULT_ICU_PLUGINS) |
| 721 if(plugin_dir == NULL || !*plugin_dir) { | 728 if(plugin_dir.isEmpty()) { |
| 722 plugin_dir = DEFAULT_ICU_PLUGINS; | 729 plugin_dir.append(DEFAULT_ICU_PLUGINS, -1, *status); |
| 723 } | 730 } |
| 724 #endif | 731 #endif |
| 725 | 732 |
| 726 #if UPLUG_TRACE | 733 #if UPLUG_TRACE |
| 727 DBG((stderr, "ICU_PLUGINS=%s\n", plugin_dir)); | 734 DBG((stderr, "ICU_PLUGINS=%s\n", plugin_dir.data())); |
| 728 #endif | 735 #endif |
| 729 | 736 |
| 730 if(plugin_dir != NULL && *plugin_dir) { | 737 if(!plugin_dir.isEmpty()) { |
| 731 FILE *f; | 738 FILE *f; |
| 732 | 739 |
| 733 | 740 CharString pluginFile; |
| 734 #ifdef OS390BATCH | 741 #ifdef OS390BATCH |
| 735 /* There are potentially a lot of ways to implement a plugin directory on OS390/
zOS */ | 742 /* There are potentially a lot of ways to implement a plugin directory on OS390/
zOS */ |
| 736 /* Keeping in mind that unauthorized file access is logged, monitored, and enfor
ced */ | 743 /* Keeping in mind that unauthorized file access is logged, monitored, and enfor
ced */ |
| 737 /* I've chosen to open a DDNAME if BATCH and leave it alone for (presumably) UNI
X */ | 744 /* I've chosen to open a DDNAME if BATCH and leave it alone for (presumably) UNI
X */ |
| 738 /* System Services. Alternative techniques might be allocating a member in
*/ | 745 /* System Services. Alternative techniques might be allocating a member in
*/ |
| 739 /* SYS1.PARMLIB or setting an environment variable "ICU_PLUGIN_PATH" (?). The
*/ | 746 /* SYS1.PARMLIB or setting an environment variable "ICU_PLUGIN_PATH" (?). The
*/ |
| 740 /* DDNAME can be connected to a file in the HFS if need be.
*/ | 747 /* DDNAME can be connected to a file in the HFS if need be.
*/ |
| 741 | 748 |
| 742 uprv_strncpy(plugin_file,"//DD:ICUPLUG", 2047); /* JAM 20 Oct 2011 */ | 749 pluginFile.append("//DD:ICUPLUG", -1, *status); /* JAM 20 Oct 2011 */ |
| 743 #else | 750 #else |
| 744 uprv_strncpy(plugin_file, plugin_dir, 2047); | 751 pluginFile.append(plugin_dir, *status); |
| 745 uprv_strncat(plugin_file, U_FILE_SEP_STRING,2047); | 752 pluginFile.append(U_FILE_SEP_STRING, -1, *status); |
| 746 uprv_strncat(plugin_file, "icuplugins",2047); | 753 pluginFile.append("icuplugins", -1, *status); |
| 747 uprv_strncat(plugin_file, U_ICU_VERSION_SHORT ,2047); | 754 pluginFile.append(U_ICU_VERSION_SHORT, -1, *status); |
| 748 uprv_strncat(plugin_file, ".txt" ,2047); | 755 pluginFile.append(".txt", -1, *status); |
| 749 #endif | 756 #endif |
| 757 |
| 758 #if UPLUG_TRACE |
| 759 DBG((stderr, "status=%s\n", u_errorName(*status))); |
| 760 #endif |
| 761 |
| 762 if(U_FAILURE(*status)) { |
| 763 return; |
| 764 } |
| 765 if((size_t)pluginFile.length() > (sizeof(plugin_file)-1)) { |
| 766 *status = U_BUFFER_OVERFLOW_ERROR; |
| 767 #if UPLUG_TRACE |
| 768 DBG((stderr, "status=%s\n", u_errorName(*status))); |
| 769 #endif |
| 770 return; |
| 771 } |
| 772 |
| 773 /* plugin_file is not used for processing - it is only used |
| 774 so that uplug_getPluginFile() works (i.e. icuinfo) |
| 775 */ |
| 776 uprv_strncpy(plugin_file, pluginFile.data(), sizeof(plugin_file)); |
| 750 | 777 |
| 751 #if UPLUG_TRACE | 778 #if UPLUG_TRACE |
| 752 DBG((stderr, "pluginfile= %s\n", plugin_file)); | 779 DBG((stderr, "pluginfile= %s len %d/%d\n", plugin_file, (int)strlen(plugin_f
ile), (int)sizeof(plugin_file))); |
| 753 #endif | 780 #endif |
| 754 | 781 |
| 755 #ifdef __MVS__ | 782 #ifdef __MVS__ |
| 756 if (iscics()) /* 12 Nov 2011 JAM */ | 783 if (iscics()) /* 12 Nov 2011 JAM */ |
| 757 { | 784 { |
| 758 f = NULL; | 785 f = NULL; |
| 759 } | 786 } |
| 760 else | 787 else |
| 761 #endif | 788 #endif |
| 762 { | 789 { |
| 763 f = fopen(plugin_file, "r"); | 790 f = fopen(pluginFile.data(), "r"); |
| 764 } | 791 } |
| 765 | 792 |
| 766 if(f != NULL) { | 793 if(f != NULL) { |
| 767 char linebuf[1024]; | 794 char linebuf[1024]; |
| 768 char *p, *libName=NULL, *symName=NULL, *config=NULL; | 795 char *p, *libName=NULL, *symName=NULL, *config=NULL; |
| 769 int32_t line = 0; | 796 int32_t line = 0; |
| 770 | 797 |
| 771 | 798 |
| 772 while(fgets(linebuf,1023,f)) { | 799 while(fgets(linebuf,1023,f)) { |
| 773 line++; | 800 line++; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 } else { | 861 } else { |
| 835 #if UPLUG_TRACE | 862 #if UPLUG_TRACE |
| 836 DBG((stderr, "Can't open plugin file %s\n", plugin_file)); | 863 DBG((stderr, "Can't open plugin file %s\n", plugin_file)); |
| 837 #endif | 864 #endif |
| 838 } | 865 } |
| 839 } | 866 } |
| 840 uplug_loadWaitingPlugs(status); | 867 uplug_loadWaitingPlugs(status); |
| 841 #endif /* U_ENABLE_DYLOAD */ | 868 #endif /* U_ENABLE_DYLOAD */ |
| 842 ucln_registerCleanup(UCLN_UPLUG, uplug_cleanup); | 869 ucln_registerCleanup(UCLN_UPLUG, uplug_cleanup); |
| 843 } | 870 } |
| OLD | NEW |