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