4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1995, 1996, 1997 Alexandre Julliard
7 * Copyright 1997 Eric Youngdale
8 * Copyright 1999 Ulrich Weigand
14 #include "wine/exception.h"
15 #include "builtin16.h"
18 #include "stackframe.h"
23 extern unsigned short __get_cs(void);
24 __ASM_GLOBAL_FUNC( __get_cs, "movw %cs,%ax\n\tret" );
26 static inline unsigned short __get_cs(void) { return 0; }
30 /*******************************************************************
33 * Store a list of ints into a byte array.
35 static int StoreVariableCode( unsigned char *buffer, int size, ORDDEF *odp )
42 for (i = 0; i < odp->u.var.n_values; i++)
43 buffer[i] = odp->u.var.values[i];
46 for (i = 0; i < odp->u.var.n_values; i++)
47 ((unsigned short *)buffer)[i] = odp->u.var.values[i];
50 for (i = 0; i < odp->u.var.n_values; i++)
51 ((unsigned int *)buffer)[i] = odp->u.var.values[i];
54 return odp->u.var.n_values * size;
58 /*******************************************************************
61 * Build the in-memory representation of a 16-bit NE module, and dump it
62 * as a byte stream into the assembly code.
64 static int BuildModule16( FILE *outfile, int max_code_offset,
70 SEGTABLEENTRY *pSegment;
73 ET_BUNDLE *bundle = 0;
78 * OFSTRUCT File information
79 * SEGTABLEENTRY Segment 1 (code)
80 * SEGTABLEENTRY Segment 2 (data)
81 * WORD[2] Resource table (empty)
82 * BYTE[2] Imported names (empty)
83 * BYTE[n] Resident names table
87 buffer = xmalloc( 0x10000 );
89 pModule = (NE_MODULE *)buffer;
90 memset( pModule, 0, sizeof(*pModule) );
91 pModule->magic = IMAGE_OS2_SIGNATURE;
94 pModule->flags = NE_FFLAGS_SINGLEDATA | NE_FFLAGS_BUILTIN | NE_FFLAGS_LIBMODULE;
96 pModule->heap_size = DLLHeapSize;
97 pModule->stack_size = 0;
102 pModule->seg_count = 2;
103 pModule->modref_count = 0;
104 pModule->nrname_size = 0;
105 pModule->modref_table = 0;
106 pModule->nrname_fpos = 0;
107 pModule->moveable_entries = 0;
108 pModule->alignment = 0;
109 pModule->truetype = 0;
110 pModule->os_flags = NE_OSFLAGS_WINDOWS;
111 pModule->misc_flags = 0;
112 pModule->dlls_to_init = 0;
113 pModule->nrname_handle = 0;
114 pModule->min_swap_area = 0;
115 pModule->expected_version = 0;
116 pModule->module32 = 0;
118 pModule->self_loading_sel = 0;
120 /* File information */
122 pFileInfo = (OFSTRUCT *)(pModule + 1);
123 pModule->fileinfo = (int)pFileInfo - (int)pModule;
124 memset( pFileInfo, 0, sizeof(*pFileInfo) - sizeof(pFileInfo->szPathName) );
125 pFileInfo->cBytes = sizeof(*pFileInfo) - sizeof(pFileInfo->szPathName)
126 + strlen(DLLFileName);
127 strcpy( pFileInfo->szPathName, DLLFileName );
128 pstr = (char *)pFileInfo + pFileInfo->cBytes + 1;
130 #ifdef __i386__ /* FIXME: Alignment problems! */
134 pSegment = (SEGTABLEENTRY *)pstr;
135 pModule->seg_table = (int)pSegment - (int)pModule;
136 pSegment->filepos = 0;
137 pSegment->size = max_code_offset;
139 pSegment->minsize = max_code_offset;
143 pModule->dgroup_entry = (int)pSegment - (int)pModule;
144 pSegment->filepos = 0;
145 pSegment->size = max_data_offset;
146 pSegment->flags = NE_SEGFLAGS_DATA;
147 pSegment->minsize = max_data_offset;
153 pstr = (char *)pSegment;
154 pModule->res_table = (int)pstr - (int)pModule;
155 pstr += output_res16_directory( pstr );
157 /* Imported names table */
159 pModule->import_table = (int)pstr - (int)pModule;
163 /* Resident names table */
165 pModule->name_table = (int)pstr - (int)pModule;
166 /* First entry is module name */
167 *pstr = strlen(DLLName );
168 strcpy( pstr + 1, DLLName );
171 pstr += sizeof(WORD);
172 /* Store all ordinals */
173 for (i = 1; i <= Limit; i++)
175 ORDDEF *odp = Ordinals[i];
176 if (!odp || !odp->name[0]) continue;
177 *pstr = strlen( odp->name );
178 strcpy( pstr + 1, odp->name );
179 strupper( pstr + 1 );
182 pstr += sizeof(WORD);
188 pModule->entry_table = (int)pstr - (int)pModule;
189 for (i = 1; i <= Limit; i++)
192 ORDDEF *odp = Ordinals[i];
203 selector = 1; /* Code selector */
209 selector = 2; /* Data selector */
213 selector = 0xfe; /* Constant selector */
217 selector = 0; /* Invalid selector */
224 if ( bundle && bundle->last+1 == i )
229 bundle->next = (char *)pstr - (char *)pModule;
231 bundle = (ET_BUNDLE *)pstr;
235 pstr += sizeof(ET_BUNDLE);
238 /* FIXME: is this really correct ?? */
239 entry = (ET_ENTRY *)pstr;
240 entry->type = 0xff; /* movable */
241 entry->flags = 3; /* exported & public data */
242 entry->segnum = selector;
243 entry->offs = odp->offset;
244 pstr += sizeof(ET_ENTRY);
249 /* Dump the module content */
251 dump_bytes( outfile, (char *)pModule, (int)pstr - (int)pModule, "Module", 0 );
252 return (int)pstr - (int)pModule;
256 /*******************************************************************
257 * BuildCallFrom16Func
259 * Build a 16-bit-to-Wine callback glue function.
261 * The generated routines are intended to be used as argument conversion
262 * routines to be called by the CallFrom16... core. Thus, the prototypes of
263 * the generated routines are (see also CallFrom16):
265 * extern WORD WINAPI PREFIX_CallFrom16_C_word_xxx( FARPROC func, LPBYTE args );
266 * extern LONG WINAPI PREFIX_CallFrom16_C_long_xxx( FARPROC func, LPBYTE args );
267 * extern void WINAPI PREFIX_CallFrom16_C_regs_xxx( FARPROC func, LPBYTE args,
268 * CONTEXT86 *context );
269 * extern void WINAPI PREFIX_CallFrom16_C_intr_xxx( FARPROC func, LPBYTE args,
270 * CONTEXT86 *context );
272 * where 'C' is the calling convention ('p' for pascal or 'c' for cdecl),
273 * and each 'x' is an argument ('w'=word, 's'=signed word, 'l'=long,
274 * 'p'=linear pointer, 't'=linear pointer to null-terminated string,
275 * 'T'=segmented pointer to null-terminated string).
277 * The generated routines fetch the arguments from the 16-bit stack (pointed
278 * to by 'args'); the offsets of the single argument values are computed
279 * according to the calling convention and the argument types. Then, the
280 * 32-bit entry point is called with these arguments.
282 * For register functions, the arguments (if present) are converted just
283 * the same as for normal functions, but in addition the CONTEXT86 pointer
284 * filled with the current register values is passed to the 32-bit routine.
285 * (An 'intr' interrupt handler routine is treated exactly like a register
286 * routine, except that upon return, the flags word pushed onto the stack
287 * by the interrupt is removed by the 16-bit call stub.)
290 static void BuildCallFrom16Func( FILE *outfile, char *profile, char *prefix, int local )
292 int i, pos, argsize = 0;
296 char *args = profile + 7;
299 /* Parse function type */
301 if (!strncmp( "c_", profile, 2 )) usecdecl = 1;
302 else if (strncmp( "p_", profile, 2 ))
304 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
308 if (!strncmp( "word_", profile + 2, 5 )) short_ret = 1;
309 else if (!strncmp( "regs_", profile + 2, 5 )) reg_func = 1;
310 else if (!strncmp( "intr_", profile + 2, 5 )) reg_func = 2;
311 else if (strncmp( "long_", profile + 2, 5 ))
313 fprintf( stderr, "Invalid function name '%s', ignored\n", profile );
317 for ( i = 0; args[i]; i++ )
321 case 's': /* s_word */
325 case 'l': /* long or segmented pointer */
326 case 'T': /* segmented pointer to null-terminated string */
327 case 'p': /* linear pointer */
328 case 't': /* linear pointer to null-terminated string */
333 ret_type = reg_func? "void" : short_ret? "WORD" : "LONG";
335 fprintf( outfile, "typedef %s WINAPI (*proc_%s_t)( ",
338 for ( i = 0; args[i]; i++ )
340 if ( i ) fprintf( outfile, ", " );
343 case 'w': fprintf( outfile, "WORD" ); break;
344 case 's': fprintf( outfile, "INT16" ); break;
345 case 'l': case 'T': fprintf( outfile, "LONG" ); break;
346 case 'p': case 't': fprintf( outfile, "LPVOID" ); break;
350 fprintf( outfile, "%sstruct _CONTEXT86 *", i? ", " : "" );
352 fprintf( outfile, "void" );
353 fprintf( outfile, " );\n" );
355 fprintf( outfile, "%s%s WINAPI %s_CallFrom16_%s( FARPROC proc, LPBYTE args%s )\n{\n",
356 local? "static " : "", ret_type, prefix, profile,
357 reg_func? ", struct _CONTEXT86 *context" : "" );
359 fprintf( outfile, " %s((proc_%s_t) proc) (\n",
360 reg_func? "" : "return ", profile );
362 pos = !usecdecl? argsize : 0;
363 for ( i = 0; args[i]; i++ )
365 if ( i ) fprintf( outfile, ",\n" );
366 fprintf( outfile, " " );
370 if ( !usecdecl ) pos -= 2;
371 fprintf( outfile, "*(WORD *)(args+%d)", pos );
372 if ( usecdecl ) pos += 2;
375 case 's': /* s_word */
376 if ( !usecdecl ) pos -= 2;
377 fprintf( outfile, "*(INT16 *)(args+%d)", pos );
378 if ( usecdecl ) pos += 2;
381 case 'l': /* long or segmented pointer */
382 case 'T': /* segmented pointer to null-terminated string */
383 if ( !usecdecl ) pos -= 4;
384 fprintf( outfile, "*(LONG *)(args+%d)", pos );
385 if ( usecdecl ) pos += 4;
388 case 'p': /* linear pointer */
389 case 't': /* linear pointer to null-terminated string */
390 if ( !usecdecl ) pos -= 4;
391 fprintf( outfile, "PTR_SEG_TO_LIN( *(SEGPTR *)(args+%d) )", pos );
392 if ( usecdecl ) pos += 4;
396 fprintf( stderr, "Unknown arg type '%c'\n", args[i] );
400 fprintf( outfile, "%s context", i? ",\n" : "" );
401 fprintf( outfile, " );\n}\n\n" );
405 /*******************************************************************
408 * Build a Wine-to-16-bit callback glue function.
410 * Prototypes for the CallTo16 functions:
411 * extern WORD CALLBACK PREFIX_CallTo16_word_xxx( FARPROC16 func, args... );
412 * extern LONG CALLBACK PREFIX_CallTo16_long_xxx( FARPROC16 func, args... );
414 * These routines are provided solely for convenience; they simply
415 * write the arguments onto the 16-bit stack, and call the appropriate
416 * CallTo16... core routine.
418 * If you have more sophisticated argument conversion requirements than
419 * are provided by these routines, you might as well call the core
420 * routines by yourself.
423 static void BuildCallTo16Func( FILE *outfile, char *profile, char *prefix )
425 char *args = profile + 5;
426 int i, argsize = 0, short_ret = 0;
428 if (!strncmp( "word_", profile, 5 )) short_ret = 1;
429 else if (strncmp( "long_", profile, 5 ))
431 fprintf( stderr, "Invalid function name '%s'.\n", profile );
435 fprintf( outfile, "%s %s_CallTo16_%s( FARPROC16 proc",
436 short_ret? "WORD" : "LONG", prefix, profile );
438 for ( i = 0; args[i]; i++ )
440 fprintf( outfile, ", " );
443 case 'w': fprintf( outfile, "WORD" ); argsize += 2; break;
444 case 'l': fprintf( outfile, "LONG" ); argsize += 4; break;
446 fprintf( outfile, " arg%d", i+1 );
448 fprintf( outfile, " )\n{\n" );
451 fprintf( outfile, " LPBYTE args = (LPBYTE)CURRENT_STACK16;\n" );
454 for ( i = 0; args[i]; i++ )
458 case 'w': fprintf( outfile, " args -= sizeof(WORD); *(WORD" ); break;
459 case 'l': fprintf( outfile, " args -= sizeof(LONG); *(LONG" ); break;
460 default: fprintf( stderr, "Unexpected case '%c' in BuildCallTo16Func\n",
463 fprintf( outfile, " *)args = arg%d;\n", i+1 );
466 fprintf( outfile, " return CallTo16%s( proc, %d );\n}\n\n",
467 short_ret? "Word" : "Long", argsize );
471 /*******************************************************************
474 static int Spec16TypeCompare( const void *e1, const void *e2 )
476 const ORDDEF *odp1 = *(const ORDDEF **)e1;
477 const ORDDEF *odp2 = *(const ORDDEF **)e2;
479 int type1 = (odp1->type == TYPE_CDECL) ? 0
480 : (odp1->type == TYPE_REGISTER) ? 3
481 : (odp1->type == TYPE_INTERRUPT) ? 4
482 : (odp1->type == TYPE_PASCAL_16) ? 1 : 2;
484 int type2 = (odp2->type == TYPE_CDECL) ? 0
485 : (odp2->type == TYPE_REGISTER) ? 3
486 : (odp2->type == TYPE_INTERRUPT) ? 4
487 : (odp2->type == TYPE_PASCAL_16) ? 1 : 2;
489 int retval = type1 - type2;
491 retval = strcmp( odp1->u.func.arg_types, odp2->u.func.arg_types );
497 /*******************************************************************
500 * Output the functions for stub entry points
502 static void output_stub_funcs( FILE *outfile )
507 for (i = 0; i <= Limit; i++)
509 ORDDEF *odp = Ordinals[i];
510 if (!odp || odp->type != TYPE_STUB) continue;
511 fprintf( outfile, "#ifdef __GNUC__\n" );
512 fprintf( outfile, "static void __wine_unimplemented( const char *func ) __attribute__((noreturn));\n" );
513 fprintf( outfile, "#endif\n" );
514 fprintf( outfile, "static void __wine_unimplemented( const char *func )\n{\n" );
515 fprintf( outfile, " struct exc_record {\n" );
516 fprintf( outfile, " unsigned int code, flags;\n" );
517 fprintf( outfile, " void *rec, *addr;\n" );
518 fprintf( outfile, " unsigned int params;\n" );
519 fprintf( outfile, " const void *info[15];\n" );
520 fprintf( outfile, " } rec;\n" );
521 fprintf( outfile, " extern void RtlRaiseException( struct exc_record * );\n\n" );
522 fprintf( outfile, " rec.code = 0x%08x;\n", EXCEPTION_WINE_STUB );
523 fprintf( outfile, " rec.flags = %d;\n", EH_NONCONTINUABLE );
524 fprintf( outfile, " rec.rec = 0;\n" );
525 fprintf( outfile, " rec.params = 2;\n" );
526 fprintf( outfile, " rec.info[0] = dllname;\n" );
527 fprintf( outfile, " rec.info[1] = func;\n" );
528 fprintf( outfile, "#ifdef __GNUC__\n" );
529 fprintf( outfile, " rec.addr = __builtin_return_address(1);\n" );
530 fprintf( outfile, "#else\n" );
531 fprintf( outfile, " rec.addr = 0;\n" );
532 fprintf( outfile, "#endif\n" );
533 fprintf( outfile, " for (;;) RtlRaiseException( &rec );\n}\n\n" );
536 for (i = 0; i <= Limit; i++)
538 ORDDEF *odp = Ordinals[i];
539 if (!odp || odp->type != TYPE_STUB) continue;
540 strcpy( odp->u.func.link_name, "__stub_" );
541 strcat( odp->u.func.link_name, odp->name );
542 for (p = odp->u.func.link_name; *p; p++) if (!isalnum(*p)) *p = '_';
543 fprintf( outfile, "static void %s(void) { __wine_unimplemented(\"%s\"); }\n",
544 odp->u.func.link_name, odp->name );
549 /*******************************************************************
552 * Build a Win16 assembly file from a spec file.
554 void BuildSpec16File( FILE *outfile )
556 ORDDEF **type, **typelist;
557 int i, nFuncs, nTypes;
558 int code_offset, data_offset, module_size, res_size;
560 unsigned short code_selector = __get_cs();
564 fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n",
566 fprintf( outfile, "#include \"builtin16.h\"\n\n" );
568 fprintf( outfile, "extern void RELAY_Unimplemented16(void);\n\n" );
570 data = (unsigned char *)xmalloc( 0x10000 );
571 memset( data, 0, 16 );
575 fprintf( outfile, "static const char dllname[] = \"%s\";\n\n", DLLName );
576 output_stub_funcs( outfile );
578 /* Build sorted list of all argument types, without duplicates */
580 typelist = (ORDDEF **)calloc( Limit+1, sizeof(ORDDEF *) );
582 for (i = nFuncs = 0; i <= Limit; i++)
584 ORDDEF *odp = Ordinals[i];
594 typelist[nFuncs++] = odp;
601 qsort( typelist, nFuncs, sizeof(ORDDEF *), Spec16TypeCompare );
606 typelist[nTypes++] = typelist[i++];
607 while ( i < nFuncs && Spec16TypeCompare( typelist + i, typelist + nTypes-1 ) == 0 )
611 /* Output CallFrom16 routines needed by this .spec file */
613 for ( i = 0; i < nTypes; i++ )
617 sprintf( profile, "%s_%s_%s",
618 (typelist[i]->type == TYPE_CDECL) ? "c" : "p",
619 (typelist[i]->type == TYPE_REGISTER) ? "regs" :
620 (typelist[i]->type == TYPE_INTERRUPT) ? "intr" :
621 (typelist[i]->type == TYPE_PASCAL_16) ? "word" : "long",
622 typelist[i]->u.func.arg_types );
624 BuildCallFrom16Func( outfile, profile, DLLName, TRUE );
627 /* Output the DLL functions prototypes */
629 for (i = 0; i <= Limit; i++)
631 ORDDEF *odp = Ordinals[i];
640 fprintf( outfile, "extern void %s();\n", odp->u.func.link_name );
647 /* Output code segment */
649 fprintf( outfile, "\nstatic struct\n{\n CALLFROM16 call[%d];\n"
650 " ENTRYPOINT16 entry[%d];\n} Code_Segment = \n{\n {\n",
654 for ( i = 0; i < nTypes; i++ )
656 char profile[101], *arg;
659 sprintf( profile, "%s_%s_%s",
660 (typelist[i]->type == TYPE_CDECL) ? "c" : "p",
661 (typelist[i]->type == TYPE_REGISTER) ? "regs" :
662 (typelist[i]->type == TYPE_INTERRUPT) ? "intr" :
663 (typelist[i]->type == TYPE_PASCAL_16) ? "word" : "long",
664 typelist[i]->u.func.arg_types );
666 if ( typelist[i]->type != TYPE_CDECL )
667 for ( arg = typelist[i]->u.func.arg_types; *arg; arg++ )
671 case 's': /* s_word */
674 case 'l': /* long or segmented pointer */
675 case 'T': /* segmented pointer to null-terminated string */
676 case 'p': /* linear pointer */
677 case 't': /* linear pointer to null-terminated string */
682 if ( typelist[i]->type == TYPE_INTERRUPT )
685 fprintf( outfile, " { 0x68, %s_CallFrom16_%s, 0x9a, CallFrom16%s,\n",
687 (typelist[i]->type == TYPE_REGISTER
688 || typelist[i]->type == TYPE_INTERRUPT)? "Register":
689 typelist[i]->type == TYPE_PASCAL_16? "Word" : "Long" );
691 fprintf( outfile, " 0x%04x, 0x66, 0xca, %d, \"%s\" },\n",
692 code_selector, argsize, profile );
694 fprintf( outfile, " 0x%04x, 0x66, 0xcb, 0x9090, \"%s\" },\n",
695 code_selector, profile );
697 code_offset += sizeof(CALLFROM16);
699 fprintf( outfile, " },\n {\n" );
701 for (i = 0; i <= Limit; i++)
703 ORDDEF *odp = Ordinals[i];
708 odp->offset = LOWORD(odp->u.abs.value);
712 odp->offset = data_offset;
713 data_offset += StoreVariableCode( data + data_offset, 1, odp);
717 odp->offset = data_offset;
718 data_offset += StoreVariableCode( data + data_offset, 2, odp);
722 odp->offset = data_offset;
723 data_offset += StoreVariableCode( data + data_offset, 4, odp);
732 type = bsearch( &odp, typelist, nTypes, sizeof(ORDDEF *), Spec16TypeCompare );
735 fprintf( outfile, " /* %s.%d */ ", DLLName, i );
736 fprintf( outfile, "{ 0x5566, 0x68, %s, 0xe866, %d /* %s_%s_%s */ },\n",
737 odp->u.func.link_name,
738 (type-typelist)*sizeof(CALLFROM16) -
739 (code_offset + sizeof(ENTRYPOINT16)),
740 (odp->type == TYPE_CDECL) ? "c" : "p",
741 (odp->type == TYPE_REGISTER) ? "regs" :
742 (odp->type == TYPE_INTERRUPT) ? "intr" :
743 (odp->type == TYPE_PASCAL_16) ? "word" : "long",
744 odp->u.func.arg_types );
745 odp->offset = code_offset;
746 code_offset += sizeof(ENTRYPOINT16);
750 fprintf(stderr,"build: function type %d not available for Win16\n",
756 fprintf( outfile, " }\n};\n" );
758 /* Output data segment */
760 dump_bytes( outfile, data, data_offset, "Data_Segment", 0 );
762 /* Build the module */
764 module_size = BuildModule16( outfile, code_offset, data_offset );
765 res_size = output_res16_data( outfile );
767 /* Output the DLL descriptor */
769 fprintf( outfile, "\nstatic const BUILTIN16_DESCRIPTOR descriptor = \n{\n" );
770 fprintf( outfile, " \"%s\",\n", DLLName );
771 fprintf( outfile, " Module,\n" );
772 fprintf( outfile, " sizeof(Module),\n" );
773 fprintf( outfile, " &Code_Segment,\n" );
774 fprintf( outfile, " Data_Segment,\n" );
775 fprintf( outfile, " \"%s\",\n", owner_name );
776 fprintf( outfile, " %s\n", res_size ? "resource_data" : "0" );
777 fprintf( outfile, "};\n" );
779 /* Output the DLL constructor */
781 fprintf( outfile, "#ifdef __GNUC__\n" );
782 fprintf( outfile, "static void %s_init(void) __attribute__((constructor));\n", DLLName );
783 fprintf( outfile, "#else /* defined(__GNUC__) */\n" );
784 fprintf( outfile, "static void __asm__dummy_dll_init(void) {\n" );
785 fprintf( outfile, "asm(\"\\t.section\t.init ,\\\"ax\\\"\\n\"\n" );
786 fprintf( outfile, " \"\\tcall %s_init\\n\"\n", DLLName );
787 fprintf( outfile, " \"\\t.previous\\n\");\n" );
788 fprintf( outfile, "}\n" );
789 fprintf( outfile, "#endif /* defined(__GNUC__) */\n" );
790 fprintf( outfile, "static void %s_init(void) { BUILTIN_RegisterDLL( &descriptor ); }\n",
795 /*******************************************************************
798 * Build the 16-bit-to-Wine/Wine-to-16-bit callback glue code
800 void BuildGlue( FILE *outfile, FILE *infile )
806 fprintf( outfile, "/* File generated automatically from %s; do not edit! */\n\n",
808 fprintf( outfile, "#include \"builtin16.h\"\n" );
809 fprintf( outfile, "#include \"stackframe.h\"\n\n" );
811 fprintf( outfile, "extern WORD CALLBACK CallTo16Word( FARPROC16 target, INT nArgs );\n" );
812 fprintf( outfile, "extern LONG CALLBACK CallTo16Long( FARPROC16 target, INT nArgs );\n" );
814 /* Build the callback glue functions */
816 while (fgets( buffer, sizeof(buffer), infile ))
818 if (strstr( buffer, "### start build ###" )) break;
820 while (fgets( buffer, sizeof(buffer), infile ))
823 if ( (p = strstr( buffer, "CallFrom16_" )) != NULL )
825 char *q, *profile = p + strlen( "CallFrom16_" );
826 for (q = profile; (*q == '_') || isalpha(*q); q++ )
829 for (q = p-1; q > buffer && ((*q == '_') || isalnum(*q)); q-- )
831 if ( ++q < p ) p[-1] = '\0'; else q = "";
832 BuildCallFrom16Func( outfile, profile, q, FALSE );
834 if ( (p = strstr( buffer, "CallTo16_" )) != NULL )
836 char *q, *profile = p + strlen( "CallTo16_" );
837 for (q = profile; (*q == '_') || isalpha(*q); q++ )
840 for (q = p-1; q > buffer && ((*q == '_') || isalnum(*q)); q-- )
842 if ( ++q < p ) p[-1] = '\0'; else q = "";
843 BuildCallTo16Func( outfile, profile, q );
845 if (strstr( buffer, "### stop build ###" )) break;