Back to index

lightning-sunbird  0.9+nobinonly
mozce_internal.h
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code, released
00017  * Jan 28, 2003.
00018  *
00019  * The Initial Developer of the Original Code is
00020  * Netscape Communications Corporation.
00021  * Portions created by the Initial Developer are Copyright (C) 2003
00022  * the Initial Developer. All Rights Reserved.
00023  *
00024  * Contributor(s):
00025  *   Garrett Arch Blythe, 28-January-2003
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 
00042 
00043 #if !defined __mozce_internal_h
00044 #define __mozce_internal_h
00045 
00046 #include <windows.h>
00047 #include <winsock2.h>
00048 
00049 #include "mozce_defs.h"
00050 
00051 /*
00052 **  Perform the requested conversion using the buffer provided.
00053 **
00054 **  inACPString     The wide character string to convert.
00055 **  inACPChars      Count of acp multibyte characters in inACPString to be
00056 **                      converted.
00057 **                  If -1, assume a terminated string and the terminating
00058 **                      character will also be appended to outWideString.
00059 **  outWideString   The buffer to store the converted string.
00060 **  inWideChars     Number of characters (not bytes) outWideString can hold.
00061 **                  If this value is zero, then the character count required
00062 **                      for the conversion is returned and outWideString is
00063 **                      untouched.
00064 **  returns int     The number of characters (not bytes) converted/required.
00065 **                  Zero indicates failure.
00066 **                  Generally you could use this value - 1 to avoid a
00067 **                      wcslen() call after the conversion took place
00068 **                      should the string be terminated (i.e. if inACPChars
00069 **                      included a terminating character for the conversion).
00070 */
00071 
00072 int a2w_buffer(const char* inACPString, int inACPChars, unsigned short* outWideString, int inWideChars);
00073 
00074 /*
00075 **  Perform the requested conversion using heap memory.
00076 **  The caller/client of this function must use free() to release the
00077 **      resultant string to the heap once finished with said string.
00078 **  This function is best used when the conversion length of inACPString
00079 **      is not known beforehand.
00080 **
00081 **  inACPString     The acp multibyte character string to convert.
00082 **  inACPChars      Count of acp multibyte characters in inACPString to be
00083 **                      converted.
00084 **                  If -1, assume a terminated string and the terminating
00085 **                      character will also be appended to the return value.
00086 **  outWideChars    Optional argument, can be NULL.
00087 **                  Holds number of characters (not bytes) written into
00088 **                      return value.
00089 **                  Generally you would use outWideChars - 1 to avoid a
00090 **                      wcslen() call after the conversion took place
00091 **                      should the string be terminated (i.e. if inACPChars
00092 **                      included a terminating character for the conversion).
00093 **  returns LPWSTR  The malloced converted string which must eventually be
00094 **                      free()d.
00095 **                  NULL on failure.
00096 */
00097 
00098 unsigned short* a2w_malloc(const char* inACPString, int inACPChars, int* outWideChars);
00099 
00100 /*
00101 **  Perform the requested conversion using the buffer provided.
00102 **
00103 **  inWideString    The wide character string to convert.
00104 **  inWideChars     Count of wide characters (not bytes) in
00105 **                      inWideString to be converted.
00106 **                  If -1, assume a terminated string and the terminating
00107 **                      character will also be appended to outACPString.
00108 **  outACPString    The buffer to store the converted string.
00109 **  inACPChars      Number of characters outACPString can hold.
00110 **                  If this value is zero, then the character count required
00111 **                      for the conversion is returned and outACPString is
00112 **                      untouched.
00113 **  returns int     The number of characters converted or required.
00114 **                  Zero indicates failure.
00115 **                  Generally you could use this value - 1 to avoid a
00116 **                      strlen() call after the conversion took place
00117 **                      should the string be terminated (i.e. if inWideChars
00118 **                      included a terminating character for the conversion).
00119 */
00120 int w2a_buffer(const unsigned short* inWideString, int inWideChars, char* outACPString, int inACPChars);
00121 
00122 /*
00123 **  Perform the requested conversion using heap memory.
00124 **  The caller/client of this function must use free() to release the
00125 **      resultant string to the heap once finished with said string.
00126 **  This function is best used when the conversion length of inWideString
00127 **      is not known beforehand.
00128 **
00129 **  inWideString    The wide character string to convert.
00130 **  inWideChars     Count of wide characters (not bytes) in
00131 **                      inWideString to be converted.
00132 **                  If -1, assume a terminated string and the terminating
00133 **                      character will also be appended to the return value.
00134 **  outACPChars     Optional argument, can be NULL.
00135 **                  Holds number of characters written into return value.
00136 **                  Generally you would use outACPChars - 1 to avoid a
00137 **                      strlen() call after the conversion took place
00138 **                      should the string be terminated (i.e. if inWideChars
00139 **                      included a terminating character for the conversion).
00140 **  returns LPSTR   The malloced converted string which must eventually be
00141 **                      free()d.
00142 **                  NULL on failure.
00143 */
00144 
00145 char* w2a_malloc(unsigned short* inWideString, int inWideChars, int* outACPChars);
00146 
00147 
00148 void dumpMemoryInfo();
00149 
00150 #define charcount(array) (sizeof(array) / sizeof(array[0]))
00151 
00152 
00153 // We use this API internally as well as externally.
00154 #ifdef __cplusplus
00155 extern "C" {
00156 #endif
00157 
00158        MOZCE_SHUNT_API int mozce_printf(const char *, ...);
00159 
00160 #ifdef __cplusplus
00161 };
00162 #endif
00163 
00164 int nclog (const char *fmt, ...);
00165 void nclograw(const char* data, long length);
00166 
00167 //#define MOZCE_PRECHECK                                                     \
00168 //{                                                                          \
00169 //    MEMORYSTATUS memStats;                                                 \
00170 //    memStats.dwLength = sizeof( memStats);                                 \
00171 //                                                                           \
00172 //    GlobalMemoryStatus( (LPMEMORYSTATUS)&memStats );                       \
00173 //                                                                           \
00174 //    char buffer[100];                                                      \
00175 //    sprintf(buffer, ">> dwAvailPhys (%d)\n", memStats.dwAvailPhys / 1024); \
00176 //                                                                           \
00177 //    nclograw(buffer, strlen(buffer));                                      \
00178 //}                                                                          \
00179 
00180 #define MOZCE_PRECHECK                 \
00181 {                                      \
00182     SetLastError(0);                   \
00183 }
00184 
00185 
00186 #endif /* __mozce_internal_h */