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