Changeset 103503 in vbox for trunk/src/libs/xpcom18a4/xpcom
- Timestamp:
- Feb 21, 2024 6:47:53 PM (12 months ago)
- Location:
- trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl.c
r1 r103503 39 39 * Main xpidl program entry point. 40 40 */ 41 #include <iprt/initterm.h> 41 42 42 43 #include "xpidl.h" … … 94 95 } 95 96 96 #if defined(XP_MAC) && defined(XPIDL_PLUGIN)97 #define main xpidl_main98 int xpidl_main(int argc, char *argv[]);99 #endif100 101 97 int main(int argc, char *argv[]) 102 98 { 99 RTR3InitExeNoArguments(0); 100 103 101 int i; 104 102 IncludePathEntry *inc, *inc_head, **inc_tail; … … 111 109 112 110 inc_head = xpidl_malloc(sizeof *inc); 113 #ifndef XP_MAC114 111 inc_head->directory = "."; 115 #else116 inc_head->directory = "";117 #endif118 112 inc_head->next = NULL; 119 113 inc_tail = &inc_head->next; -
trunk/src/libs/xpcom18a4/xpcom/typelib/xpidl/xpidl_idl.c
r103140 r103503 40 40 * Common IDL-processing code. 41 41 */ 42 #include <iprt/errcore.h> 43 #include <iprt/file.h> 44 #include <iprt/mem.h> 42 45 43 46 #include "xpidl.h" 44 45 #ifdef XP_MAC46 #include <stat.h>47 #endif48 47 49 48 static gboolean parsed_empty_file; … … 65 64 return TRUE; 66 65 } 67 68 #if defined(XP_MAC) && defined(XPIDL_PLUGIN)69 extern void mac_warning(const char* warning_message);70 #endif71 66 72 67 static int … … 89 84 warning_message = g_strdup_printf("%s:%d: %s\n", file, line, message); 90 85 91 #if defined(XP_MAC) && defined(XPIDL_PLUGIN)92 mac_warning(warning_message);93 #else94 86 fputs(warning_message, stderr); 95 #endif96 97 87 g_free(warning_message); 98 88 return 1; … … 125 115 } input_callback_state; 126 116 127 static FILE * 128 fopen_from_includes(const char *filename, const char *mode, 129 IncludePathEntry *include_path) 117 static void * 118 file_read_from_includes(const char *filename, IncludePathEntry *include_path, size_t *pcbFile) 130 119 { 131 120 IncludePathEntry *current_path = include_path; 132 121 char *pathname; 133 FILE *inputfile;134 if (!strcmp(filename, "-"))135 return stdin;136 122 137 123 if (filename[0] != '/') { … … 141 127 if (!pathname) 142 128 return NULL; 143 inputfile = fopen(pathname, mode); 129 void *pvFile = NULL; 130 int vrc = RTFileReadAll(pathname, &pvFile, pcbFile); 144 131 g_free(pathname); 145 if ( inputfile)146 return inputfile;132 if (RT_SUCCESS(vrc)) 133 return pvFile; 147 134 current_path = current_path->next; 148 135 } 149 136 } else { 150 inputfile = fopen(filename, mode); 151 if (inputfile) 152 return inputfile; 137 void *pvFile = NULL; 138 int vrc = RTFileReadAll(filename, &pvFile, pcbFile); 139 if (RT_SUCCESS(vrc)) 140 return pvFile; 153 141 } 154 142 return NULL; … … 163 151 { 164 152 input_data *new_data; 165 FILE *inputfile; 166 char *buffer = NULL; 167 size_t offset = 0; 168 size_t buffer_size; 169 #ifdef XP_MAC 170 size_t i; 171 #endif 172 173 #if defined(XP_MAC) && defined(XPIDL_PLUGIN) 174 /* on Mac, fopen knows how to find files. */ 175 inputfile = fopen(filename, "r"); 176 #elif defined(XP_OS2) || defined(XP_WIN32) 177 /* 178 * if filename is fully qualified (starts with driver letter), then 179 * just call fopen(); else, go with fopen_from_includes() 180 */ 181 if( filename[1] == ':' ) 182 inputfile = fopen(filename, "r"); 183 else 184 inputfile = fopen_from_includes(filename, "r", include_path); 185 #else 186 inputfile = fopen_from_includes(filename, "r", include_path); 187 #endif 188 189 if (!inputfile) 190 return NULL; 191 192 #ifdef XP_MAC 193 { 194 struct stat input_stat; 195 if (fstat(fileno(inputfile), &input_stat)) 196 return NULL; 197 buffer = malloc(input_stat.st_size + 1); 198 if (!buffer) 199 return NULL; 200 offset = fread(buffer, 1, input_stat.st_size, inputfile); 201 if (ferror(inputfile)) 202 return NULL; 203 } 204 #else 153 205 154 /* 206 155 * Rather than try to keep track of many different varieties of state 207 156 * around the boundaries of a circular buffer, we just read in the entire 208 157 * file. 209 *210 * We iteratively grow the buffer here; an alternative would be to use211 * stat to find the exact buffer size we need, as xpt_dump does.212 158 */ 213 for (buffer_size = 8191; ; buffer_size *= 2) { 214 size_t just_read; 215 buffer = realloc(buffer, buffer_size + 1); /* +1 for trailing nul */ 216 just_read = fread(buffer + offset, 1, buffer_size - offset, inputfile); 217 if (ferror(inputfile)) 218 { 219 free(buffer); 220 return NULL; 221 } 222 223 if (just_read < buffer_size - offset || just_read == 0) { 224 /* Done reading. */ 225 offset += just_read; 226 break; 227 } 228 offset += just_read; 229 } 230 #endif 231 232 fclose(inputfile); 233 234 #ifdef XP_MAC 235 /* 236 * libIDL doesn't speak '\r' properly - always make sure lines end with 237 * '\n'. 238 */ 239 for (i = 0; i < offset; i++) { 240 if (buffer[i] == '\r') 241 buffer[i] = '\n'; 242 } 243 #endif 159 size_t cbFile = 0; 160 void *pvFile = file_read_from_includes(filename, include_path, &cbFile); 161 if (!pvFile) 162 return NULL; 163 164 /* Need to copy the data over into a new buffer in order to be able to append a zero terminator. */ 165 char *pbBuf = (char *)RTMemDupEx(pvFile, cbFile, 1 /* for the zero terminator */); 166 if (!pbBuf) 167 { 168 RTFileReadAllFree(pvFile, cbFile); 169 return NULL; 170 } 171 172 memcpy(pbBuf, pvFile, cbFile); 173 RTFileReadAllFree(pvFile, cbFile); 244 174 245 175 new_data = xpidl_malloc(sizeof (struct input_data)); 246 new_data->point = new_data->buf = buffer; 247 new_data->max = buffer + offset; 176 if (!new_data) 177 { 178 RTMemFree(pbBuf); 179 return NULL; 180 } 181 182 new_data->point = new_data->buf = pbBuf; 183 new_data->max = pbBuf + cbFile; 248 184 *new_data->max = '\0'; 249 185 new_data->filename = xpidl_strdup(filename); … … 251 187 new_data->lineno = 2; 252 188 new_data->next = NULL; 253 254 189 return new_data; 255 190 } … … 630 565 next = data->next; 631 566 free(data->filename); 632 free(data->buf);567 RTMemFree(data->buf); 633 568 free(data); 634 569 data = next; … … 656 591 657 592 /* Pick up unlink. */ 658 #ifdef XP_UNIX659 593 #include <unistd.h> 660 #elif XP_WIN661 /* We get it from stdio.h. */662 #endif663 594 664 595 int … … 747 678 real_outname = g_strdup(outname); 748 679 } else { 749 /* 750 *This combination seems a little strange, what about OS/2? 751 * Assume it's some build issue 752 */ 753 #if defined(XP_UNIX) || defined(XP_WIN) 680 754 681 if (!file_basename) { 755 682 out_basename = xpidl_basename(outname); … … 757 684 out_basename = outname; 758 685 } 759 #else 760 out_basename = outname; 761 #endif 686 762 687 real_outname = g_strdup_printf("%s.%s", out_basename, mode->suffix); 763 688 if (out_basename != outname) … … 806 731 * driver code, if the compiler returns failure.) 807 732 */ 808 #if defined(XP_UNIX) || defined(XP_WIN)809 733 if (!ok) 810 734 unlink(real_outname); 811 #endif 735 812 736 g_free(real_outname); 813 737 }
Note:
See TracChangeset
for help on using the changeset viewer.