* src/vm/jit/stacktrace.h (stacktrace_getCallingClassLoader): Renamed
[cacao.git] / src / cacaoh / headers.c
1 /* src/cacaoh/headers.c - functions for header generation
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Reinhard Grafl
28
29    Changes: Mark Probst
30             Philipp Tomsich
31             Christian Thalinger
32
33    $Id: headers.c 4433 2006-02-04 20:15:23Z twisti $
34
35 */
36
37
38 #include <assert.h>
39 #include <ctype.h>
40 #include <stdarg.h>
41 #include <stdlib.h>
42 #include <string.h>
43
44 #include "config.h"
45 #include "vm/types.h"
46
47 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
48 # if defined(__DARWIN__)
49 #  include <signal.h>
50 # endif
51 # include <ucontext.h>
52 #endif
53
54 #include "mm/boehm.h"
55 #include "mm/memory.h"
56 #include "native/include/java_lang_String.h"
57 #include "native/include/java_lang_Throwable.h"
58 #include "toolbox/chain.h"
59 #include "toolbox/logging.h"
60 #include "vm/builtin.h"
61 #include "vm/class.h"
62 #include "vm/global.h"
63 #include "vm/method.h"
64 #include "vm/loader.h"
65 #include "vm/options.h"
66 #include "vm/stringlocal.h"
67 #include "vm/jit/asmpart.h"
68
69
70 #if defined(ENABLE_INTRP)
71 /* dummy interpreter stack to keep the compiler happy */
72
73 u1 intrp_main_stack[1];
74 #endif
75
76
77 /* for raising exceptions from native methods *********************************/
78
79 #if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
80 java_objectheader *_no_threads_exceptionptr = NULL;
81 #endif
82
83
84 /* replace some non-vmcore functions ******************************************/
85
86 functionptr native_findfunction(utf *cname, utf *mname, utf *desc,
87                                                                 bool isstatic)
88 {
89         /* return something different than NULL, otherwise we get an exception */
90
91         return (functionptr) 1;
92 }
93
94 java_objectheader *native_new_and_init(classinfo *c) { return NULL; }
95 java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s) { return NULL; }
96 java_objectheader *native_new_and_init_int(classinfo *c, s4 i) { return NULL; }
97 java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t) { return NULL; }
98
99
100 #if defined(ENABLE_JIT)
101 java_objectheader *asm_calljavafunction(methodinfo *m,
102                                                                                 void *arg1, void *arg2,
103                                                                                 void *arg3, void *arg4)
104 { return NULL; }
105 #endif
106
107 #if defined(ENABLE_INTRP)
108 java_objectheader *intrp_asm_calljavafunction(methodinfo *m,
109                                                                                           void *arg1, void *arg2,
110                                                                                           void *arg3, void *arg4)
111 { return NULL; }
112 #endif
113
114
115 /* code patching functions */
116 void patcher_builtin_arraycheckcast(u1 *sp) {}
117
118 #if defined(__MIPS__)
119 long compare_and_swap(long *p, long oldval, long newval)
120 {
121         if (*p == oldval) {
122                 *p = newval;
123                 return oldval;
124         } else
125                 return *p;
126 }
127 #endif
128
129
130 u1 *createcompilerstub(methodinfo *m) { return NULL; }
131 #if defined(ENABLE_INTRP)
132 u1 *intrp_createcompilerstub(methodinfo *m) { return NULL; }
133 #endif
134
135 u1 *codegen_createnativestub(functionptr f, methodinfo *m) { return NULL; }
136
137 void removecompilerstub(u1 *stub) {}
138 void removenativestub(u1 *stub) {}
139
140 void asm_perform_threadswitch(u1 **from, u1 **to, u1 **stackTop) {}
141 u1* asm_initialize_thread_stack(void *func, u1 *stack) { return NULL; }
142
143 void *asm_switchstackandcall(void *stack, void *func, void **stacktopsave, void * p) { return NULL; }
144
145 void asm_handle_builtin_exception(classinfo *c) {}
146
147
148 #if defined(ENABLE_JIT)
149 void asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out) {}
150 #endif
151
152 #if defined(ENABLE_INTRP)
153 void intrp_asm_getclassvalues_atomic(vftbl_t *super, vftbl_t *sub, castinfo *out) {}
154 #endif
155
156
157 void *Java_java_lang_VMObject_clone(void *env, void *clazz, void * this)
158 {
159         return NULL;
160 }
161
162 typecheck_result typeinfo_is_assignable_to_class(typeinfo *value,classref_or_classinfo dest)
163 {
164         return typecheck_TRUE;
165 }
166
167 void typeinfo_init_classinfo(typeinfo *info,classinfo *c)
168 {
169 }
170
171 bool typeinfo_init_class(typeinfo *info,classref_or_classinfo c)
172 {
173         return true;
174 }
175
176 void typeinfo_print(FILE *file,typeinfo *info,int indent) {}
177
178 void exceptions_print_exception(java_objectheader *xptr) {}
179 void stacktrace_print_trace(java_objectheader *xptr) {}
180
181
182 /* exception functions ********************************************************/
183
184 /* these should not be called */
185
186 void throw_main_exception_exit(void) { assert(0); }
187 void throw_exception(void) { assert(0); }
188 void throw_exception_exit(void) { assert(0); }
189
190 java_objectheader *new_verifyerror(methodinfo *m, const char *message)
191 {
192         assert(0);
193
194         /* keep compiler happy */
195
196         return NULL;
197 }
198
199 java_objectheader *new_exception_throwable(const char *classname, java_lang_Throwable *throwable)
200 {
201         assert(0);
202
203         /* keep compiler happy */
204
205         return NULL;
206 }
207
208
209 void throw_cacao_exception_exit(const char *exception, const char *message, ...)
210 {
211         va_list ap;
212
213         fprintf(stderr, "%s: ", exception);
214
215         va_start(ap, message);
216         vfprintf(stderr, message, ap);
217         va_end(ap);
218
219         fputc('\n', stderr);
220
221         exit(1);
222 }
223
224
225 void exceptions_throw_outofmemory_exit(void)
226 {
227         fprintf(stderr, "java.lang.InternalError: Out of memory\n");
228         exit(1);
229 }
230
231
232 java_objectheader *new_exception(const char *classname)
233 {
234         fprintf(stderr, "%s\n", classname);
235         exit(1);
236
237         /* keep compiler happy */
238
239         return NULL;
240 }
241
242
243 java_objectheader *new_exception_message(const char *classname, const char *message)
244 {
245         fprintf(stderr, "%s: %s\n", classname, message);
246         exit(1);
247
248         /* keep compiler happy */
249
250         return NULL;
251 }
252
253
254 java_objectheader *new_exception_utfmessage(const char *classname, utf *message)
255 {
256         fprintf(stderr, "%s: ", classname);
257         utf_display(message);
258         fputc('\n', stderr);
259
260         exit(1);
261
262         /* keep compiler happy */
263
264         return NULL;
265 }
266
267
268 java_objectheader *new_exception_javastring(const char *classname,
269                                                                                         java_lang_String *message)
270 {
271         fprintf(stderr, "%s: ", classname);
272         /* TODO print message */
273         fputc('\n', stderr);
274
275         exit(1);
276
277         /* keep compiler happy */
278
279         return NULL;
280 }
281
282
283 java_objectheader *new_classformaterror(classinfo *c, const char *message, ...)
284 {
285         va_list ap;
286
287         utf_display(c->name);
288         fprintf(stderr, ": ");
289
290         va_start(ap, message);
291         vfprintf(stderr, message, ap);
292         va_end(ap);
293
294         fputc('\n', stderr);
295
296         exit(1);
297
298         /* keep compiler happy */
299
300         return NULL;
301 }
302
303
304 void exceptions_throw_classformaterror(classinfo *c, const char *message, ...)
305 {
306         va_list ap;
307
308         va_start(ap, message);
309         (void) new_classformaterror(c, message, ap);
310         va_end(ap);
311 }
312
313
314 java_objectheader *new_classnotfoundexception(utf *name)
315 {
316         fprintf(stderr, "java.lang.ClassNotFoundException: ");
317         utf_fprint(stderr, name);
318         fputc('\n', stderr);
319
320         exit(1);
321
322         /* keep compiler happy */
323
324         return NULL;
325 }
326
327
328 java_objectheader *new_noclassdeffounderror(utf *name)
329 {
330         fprintf(stderr, "java.lang.NoClassDefFoundError: ");
331         utf_fprint(stderr, name);
332         fputc('\n', stderr);
333
334         exit(1);
335
336         /* keep compiler happy */
337
338         return NULL;
339 }
340
341
342 java_objectheader *exceptions_new_linkageerror(const char *message,
343                                                                                            classinfo *c)
344 {
345         fprintf(stderr, "java.lang.LinkageError: %s",message);
346         if (c) {
347                 utf_fprint_classname(stderr, c->name);
348         }
349         fputc('\n', stderr);
350
351         exit(1);
352
353         /* keep compiler happy */
354
355         return NULL;
356 }
357
358 java_objectheader *exceptions_new_nosuchmethoderror(classinfo *c,
359                                                                                                         utf *name, utf *desc)
360 {
361         fprintf(stderr, "java.lang.NoSuchMethodError: ");
362         utf_fprint(stderr, c->name);
363         fprintf(stderr, ".");
364         utf_fprint(stderr, name);
365         utf_fprint(stderr, desc);
366         fputc('\n', stderr);
367
368         exit(1);
369
370         /* keep compiler happy */
371
372         return NULL;
373 }
374
375
376 java_objectheader *new_internalerror(const char *message, ...)
377 {
378         va_list ap;
379
380         fprintf(stderr, "%s: ", string_java_lang_InternalError);
381
382         va_start(ap, message);
383         vfprintf(stderr, message, ap);
384         va_end(ap);
385
386         exit(1);
387
388         /* keep compiler happy */
389
390         return NULL;
391 }
392
393
394 java_objectheader *new_unsupportedclassversionerror(classinfo *c, const char *message, ...)
395 {
396         va_list ap;
397
398         fprintf(stderr, "%s: ", string_java_lang_UnsupportedClassVersionError);
399
400         utf_display(c->name);
401         fprintf(stderr, ": ");
402
403         va_start(ap, message);
404         vfprintf(stderr, message, ap);
405         va_end(ap);
406
407         exit(1);
408
409         /* keep compiler happy */
410
411         return NULL;
412 }
413
414
415 java_objectheader *new_illegalmonitorstateexception(void)
416 {
417         fprintf(stderr, "%s", string_java_lang_IllegalMonitorStateException);
418         exit(1);
419
420         /* keep compiler happy */
421
422         return NULL;
423 }
424
425
426 java_objectheader *new_negativearraysizeexception(void)
427 {
428         fprintf(stderr, "%s", string_java_lang_NegativeArraySizeException);
429         exit(1);
430
431         /* keep compiler happy */
432
433         return NULL;
434 }
435
436
437 void exceptions_throw_negativearraysizeexception(void)
438 {
439         (void) new_negativearraysizeexception();
440 }
441
442
443 java_objectheader *new_nullpointerexception(void)
444 {
445         fprintf(stderr, "%s", string_java_lang_NullPointerException);
446         exit(1);
447
448         /* keep compiler happy */
449
450         return NULL;
451 }
452
453
454 void exceptions_throw_nullpointerexception(void)
455 {
456         (void) new_nullpointerexception();
457 }
458
459
460 void classnotfoundexception_to_noclassdeffounderror(void)
461 {
462 }
463
464 /* machine dependent stuff ****************************************************/
465
466 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
467 threadcritnode asm_criticalsections;
468 void thread_restartcriticalsection(ucontext_t *uc) {}
469 #endif
470
471 void md_param_alloc(methoddesc *md) {}
472
473
474 #if defined(ENABLE_INTRP)
475 void print_dynamic_super_statistics(void) {}
476 #endif
477
478
479 /************************ global variables **********************/
480
481 chain *ident_chain;     /* chain with method and field names in current class */
482 FILE *file = NULL;
483 static u4 outputsize;
484 static bool dopadding;
485
486
487 static void printIDpart(int c)
488 {
489         if ((c >= 'a' && c <= 'z') ||
490                 (c >= 'A' && c <= 'Z') ||
491                 (c >= '0' && c <= '9') ||
492                 (c == '_'))
493                 putc(c, file);
494         else
495                 putc('_', file);
496 }
497
498
499 void printID(utf *u)
500 {
501         char *utf_ptr = u->text;
502         int i;
503
504         for (i = 0; i < utf_strlen(u); i++) 
505                 printIDpart(utf_nextu2(&utf_ptr));
506 }
507
508
509 static void addoutputsize (int len)
510 {
511         u4 newsize,i;
512         if (!dopadding) return;
513
514         newsize = ALIGN(outputsize, len);
515         
516         for (i = outputsize; i < newsize; i++) fprintf(file, "   u1 pad%d\n", (int) i);
517         outputsize = newsize;
518 }
519
520
521 void printOverloadPart(utf *desc)
522 {
523         char *utf_ptr=desc->text;
524         u2 c;
525
526         fprintf(file, "__");
527
528         while ((c = utf_nextu2(&utf_ptr)) != ')') {
529                 switch (c) {
530                 case 'I':
531                 case 'S':
532                 case 'B':
533                 case 'C':
534                 case 'Z':
535                 case 'J':
536                 case 'F':
537                 case 'D': 
538                         fprintf(file, "%c", (char) c);
539                         break;
540                 case '[':
541                         fprintf(file, "_3");
542                         break;
543                 case 'L':
544                         putc('L', file);
545                         while ((c = utf_nextu2(&utf_ptr)) != ';')
546                                 printIDpart(c);
547                         fprintf(file, "_2");
548                         break;
549                 case '(':
550                         break;
551                 default: 
552                         log_text("invalid method descriptor");
553                         assert(0);
554                 }
555         }
556 }
557
558 static char *printtype(char *utf_ptr)
559 {
560         u2 c;
561
562         switch (utf_nextu2(&utf_ptr)) {
563         case 'V': fprintf (file, "void");
564                 break;
565         case 'I':
566         case 'S':
567         case 'B':
568         case 'C':
569         case 'Z': addoutputsize (4);
570                 fprintf (file, "s4");
571                 break;
572         case 'J': addoutputsize (8);
573                 fprintf (file, "s8");
574                 break;
575         case 'F': addoutputsize (4);
576                 fprintf (file, "float");
577                 break;
578         case 'D': addoutputsize (8);
579                 fprintf (file, "double");
580                 break;
581         case '[':
582                 addoutputsize ( sizeof(java_arrayheader*) ); 
583                 switch (utf_nextu2(&utf_ptr)) {
584                 case 'I':  fprintf (file, "java_intarray*"); break;
585                 case 'J':  fprintf (file, "java_longarray*"); break;
586                 case 'Z':  fprintf (file, "java_booleanarray*"); break;
587                 case 'B':  fprintf (file, "java_bytearray*"); break;
588                 case 'S':  fprintf (file, "java_shortarray*"); break;
589                 case 'C':  fprintf (file, "java_chararray*"); break;
590                 case 'F':  fprintf (file, "java_floatarray*"); break;
591                 case 'D':  fprintf (file, "java_doublearray*"); break;
592                                 
593                 case '[': fprintf(file, "java_objectarray*");
594                         while ((c = utf_nextu2(&utf_ptr)) == '[');
595                         if (c == 'L')
596                                 while (utf_nextu2(&utf_ptr) != ';');
597                         break;
598                            
599                 case 'L':  fprintf(file, "java_objectarray*");
600                         while (utf_nextu2(&utf_ptr) != ';');
601                         break;
602                 default:
603                         log_text("invalid type descriptor");
604                         assert(0);
605                 }
606                 break;
607                 
608         case 'L': 
609                 addoutputsize ( sizeof(java_objectheader*));
610                 fprintf (file, "struct ");
611                 while ( (c = utf_nextu2(&utf_ptr)) != ';' ) printIDpart (c);     
612                 fprintf (file, "*");
613                 break;
614                                         
615         default:
616                 log_text("Unknown type in field descriptor");
617                 assert(0);
618         }
619         
620         return utf_ptr;
621 }
622
623
624 /***** determine the number of entries of a utf string in the ident chain *****/
625
626 static int searchidentchain_utf(utf *ident) 
627 {
628         utf *u = chain_first(ident_chain);     /* first element of list */
629         int count = 0;
630
631         while (u) {
632                 if (u==ident) count++;         /* string found */
633                 u = chain_next(ident_chain);   /* next element in list */ 
634         }
635
636         return count;
637 }
638
639
640 /************** print structure for direct access to objects ******************/
641
642 static void printfields(classinfo *c)
643 {
644         u4 i;
645         fieldinfo *f;
646         int ident_count;
647         
648         if (!c) {
649                 addoutputsize(sizeof(java_objectheader));
650                 fprintf(file, "   java_objectheader header;\n");
651                 return;
652         }
653                 
654         printfields(c->super.cls);
655         
656         for (i = 0; i < c->fieldscount; i++) {
657                 f = &(c->fields[i]);
658                 
659                 if (!(f->flags & ACC_STATIC)) {
660                         fprintf(file, "   ");
661                         printtype(f->descriptor->text);
662                         fprintf(file, " ");
663                         utf_fprint(file, f->name);
664
665                         /* rename multiple fieldnames */
666                         if ((ident_count = searchidentchain_utf(f->name)))
667                                 fprintf(file, "%d", ident_count - 1);
668                         chain_addlast(ident_chain, f->name);    
669
670                         fprintf(file, ";\n");
671                 }
672         }
673 }
674
675
676 /***************** store prototype for native method in file ******************/
677
678 void printmethod(methodinfo *m)
679 {
680         char *utf_ptr;
681         u2 paramnum = 1;
682
683         /* search for return-type in descriptor */      
684         utf_ptr = m->descriptor->text;
685         while (utf_nextu2(&utf_ptr) != ')');
686
687         /* create remarks */
688         fprintf(file, "\n/*\n * Class:     ");
689         utf_fprint(file, m->class->name);
690         fprintf(file, "\n * Method:    ");
691         utf_fprint(file, m->name);
692         fprintf(file, "\n * Signature: ");
693         utf_fprint(file, m->descriptor);
694         fprintf(file, "\n */\n");
695
696         /* create prototype */                  
697         fprintf(file, "JNIEXPORT ");
698         printtype(utf_ptr);
699         fprintf(file, " JNICALL Java_");
700         printID(m->class->name);
701
702         chain_addlast(ident_chain, m->name);
703
704         fprintf(file, "_");
705         printID(m->name);
706
707         /* ATTENTION: We use the methodinfo's isleafmethod variable as
708            nativelyoverloaded, so we can save some space during
709            runtime. */
710
711         if (m->isleafmethod)
712                 printOverloadPart(m->descriptor);
713
714         fprintf(file, "(JNIEnv *env");
715         
716         utf_ptr = m->descriptor->text + 1;
717                         
718         if (!(m->flags & ACC_STATIC)) {
719                 fprintf(file, ", struct ");
720                 printID(m->class->name);
721                 fprintf(file, "* this");
722
723         } else {
724                 fprintf(file, ", jclass clazz");
725         }
726
727         if ((*utf_ptr) != ')') fprintf(file, ", ");
728                         
729         while ((*utf_ptr) != ')') {
730                 utf_ptr = printtype(utf_ptr);
731                 fprintf(file, " par%d", paramnum++);
732                 if ((*utf_ptr)!=')') fprintf(file, ", ");
733         }
734                         
735         fprintf(file, ");\n\n");
736 }
737
738
739 /******* remove package-name in fully-qualified classname *********************/
740
741 void gen_header_filename(char *buffer, utf *u)
742 {
743         s4 i;
744   
745         for (i = 0; i < utf_strlen(u); i++) {
746                 if ((u->text[i] == '/') || (u->text[i] == '$')) {
747                         buffer[i] = '_';  /* convert '$' and '/' to '_' */
748
749                 } else {
750                         buffer[i] = u->text[i];
751                 }
752         }
753         buffer[utf_strlen(u)] = '\0';
754 }
755
756
757 /* create headerfile for classes and store native methods in chain ************/
758
759 void headerfile_generate(classinfo *c, char *opt_directory)
760 {
761         char header_filename[1024] = "";
762         char classname[1024]; 
763         char uclassname[1024];
764         u2 i;
765         methodinfo *m;                  
766         u2 j;
767         methodinfo *m2;
768         bool nativelyoverloaded;
769
770         /* prevent compiler warnings */
771
772         nativelyoverloaded = false;
773
774         /* open headerfile for class */
775         gen_header_filename(classname, c->name);
776
777         /* create chain for renaming fields */
778         ident_chain = chain_new();
779         
780         if (opt_directory) {
781                 sprintf(header_filename, "%s/%s.h", opt_directory, classname);
782
783         } else {
784                 sprintf(header_filename, "%s.h", classname);
785         }
786
787         file = fopen(header_filename, "w");
788         if (!file) {
789                 log_text("Can not open file to store header information");
790                 assert(0);
791         }
792
793         fprintf(file, "/* This file is machine generated, don't edit it! */\n\n");
794
795         /* convert to uppercase */
796         for (i = 0; classname[i]; i++) {
797                 uclassname[i] = toupper(classname[i]);
798         }
799         uclassname[i] = '\0';
800
801         fprintf(file, "#ifndef _%s_H\n#define _%s_H\n\n", uclassname, uclassname);
802
803         /* create structure for direct access to objects */     
804         fprintf(file, "/* Structure information for class: ");
805         utf_fprint(file, c->name);
806         fprintf(file, " */\n\n");
807         fprintf(file, "typedef struct ");
808         printID(c->name);                                                       
809         fprintf(file, " {\n");
810         outputsize = 0;
811         dopadding = true;
812
813         printfields(c);
814
815         fprintf(file, "} ");
816         printID(c->name);
817         fprintf(file, ";\n\n");
818
819         /* create chain for renaming overloaded methods */
820         chain_free(ident_chain);
821         ident_chain = chain_new();
822
823         /* create method-prototypes */
824                                 
825         /* find overloaded methods */
826
827         for (i = 0; i < c->methodscount; i++) {
828                 m = &(c->methods[i]);
829
830                 if (!(m->flags & ACC_NATIVE))
831                         continue;
832
833                 /* We use the methodinfo's isleafmethod variable as
834                    nativelyoverloaded, so we can save some space during
835                    runtime. */
836
837                 if (!m->isleafmethod) {
838                         nativelyoverloaded = false;
839
840                         for (j = i + 1; j < c->methodscount; j++) {
841                                 m2 = &(c->methods[j]);
842
843                                 if (!(m2->flags & ACC_NATIVE))
844                                         continue;
845
846                                 if (m->name == m2->name) {
847                                         m2->isleafmethod = true;
848                                         nativelyoverloaded = true;
849                                 }
850                         }
851                 }
852
853                 m->isleafmethod = nativelyoverloaded;
854         }
855
856         for (i = 0; i < c->methodscount; i++) {
857                 m = &(c->methods[i]);
858
859                 if (m->flags & ACC_NATIVE)
860                         printmethod(m);
861         }
862
863         chain_free(ident_chain);
864
865         fprintf(file, "#endif\n\n");
866
867         fclose(file);
868 }
869
870
871 /******** print classname, '$' used to seperate inner-class name ***********/
872
873 void print_classname(classinfo *clazz)
874 {
875         utf *u = clazz->name;
876     char *endpos  = u->text + u->blength;
877     char *utf_ptr = u->text; 
878         u2 c;
879
880     while (utf_ptr < endpos) {
881                 if ((c = utf_nextu2(&utf_ptr)) == '_')
882                         putc('$', file);
883                 else
884                         putc(c, file);
885         }
886
887
888
889 /*
890  * These are local overrides for various environment variables in Emacs.
891  * Please do not remove this and leave it at the end of the file, where
892  * Emacs will automagically detect them.
893  * ---------------------------------------------------------------------
894  * Local variables:
895  * mode: c
896  * indent-tabs-mode: t
897  * c-basic-offset: 4
898  * tab-width: 4
899  * End:
900  */