153 *
154 * Global variables used:
155 * funny The vector of semantic tags for characters
156 * hashtab The hashtable used for the nametable
157 */
158 Name
159 getname_fn(wchar_t *name, register int len, register Boolean dont_enter, register Boolean * foundp)
160 {
161 register int length;
162 register wchar_t *cap = name;
163 register Name np;
164 static Name_rec empty_Name;
165 char *tmp_mbs_buffer = NULL;
166 char *mbs_name = mbs_buffer;
167
168 /*
169 * First figure out how long the string is.
170 * If the len argument is -1 we count the chars here.
171 */
172 if (len == FIND_LENGTH) {
173 length = wslen(name);
174 } else {
175 length = len;
176 }
177
178 Wstring ws;
179 ws.init(name, length);
180 if (length >= MAXPATHLEN) {
181 mbs_name = tmp_mbs_buffer = getmem((length * MB_LEN_MAX) + 1);
182 }
183 (void) wcstombs(mbs_name, ws.get_string(), (length * MB_LEN_MAX) + 1);
184
185 /* Look for the string */
186 if (dont_enter || (foundp != 0)) {
187 np = hashtab.lookup(mbs_name);
188 if (foundp != 0) {
189 *foundp = (np != 0) ? true : false;
190 }
191 if ((np != 0) || dont_enter) {
192 if(tmp_mbs_buffer != NULL) {
193 retmem_mb(tmp_mbs_buffer);
664 }
665 return NULL;
666 }
667
668 /*
669 * append_string(from, to, length)
670 *
671 * Append a C string to a make string expanding it if nessecary
672 *
673 * Parameters:
674 * from The source (C style) string
675 * to The destination (make style) string
676 * length The length of the from string
677 *
678 * Global variables used:
679 */
680 void
681 append_string(register wchar_t *from, register String to, register int length)
682 {
683 if (length == FIND_LENGTH) {
684 length = wslen(from);
685 }
686 if (to->buffer.start == NULL) {
687 expand_string(to, 32 + length);
688 }
689 if (to->buffer.end - to->text.p <= length) {
690 expand_string(to,
691 (to->buffer.end - to->buffer.start) * 2 +
692 length);
693 }
694 if (length > 0) {
695 (void) wsncpy(to->text.p, from, length);
696 to->text.p += length;
697 }
698 *(to->text.p) = (int) nul_char;
699 }
700
701 wchar_t * get_wstring(char *from) {
702 if(from == NULL) {
703 return NULL;
704 }
705 getwstring_count++;
706 wchar_t * wcbuf = ALLOC_WC(strlen(from) + 1);
707 mbstowcs(wcbuf, from, strlen(from)+1);
708 return wcbuf;
709 }
710
711 void
712 append_string(register char *from, register String to, register int length)
713 {
714 if (length == FIND_LENGTH) {
715 length = strlen(from);
750 string->buffer.start =
751 string->text.p =
752 string->text.end =
753 ALLOC_WC(length);
754 string->buffer.end = string->buffer.start + length;
755 string->text.p[0] = (int) nul_char;
756 string->free_after_use = true;
757 expandstring_count++;
758 return;
759 }
760 if (string->buffer.end - string->buffer.start >= length) {
761 /* If we really don't need more memory. */
762 return;
763 }
764 /*
765 * Get more memory, copy the string and free the old buffer if
766 * it is was malloc()'ed.
767 */
768 expandstring_count++;
769 p = ALLOC_WC(length);
770 (void) wscpy(p, string->buffer.start);
771 string->text.p = p + (string->text.p - string->buffer.start);
772 string->text.end = p + (string->text.end - string->buffer.start);
773 string->buffer.end = p + length;
774 if (string->free_after_use) {
775 retmem(string->buffer.start);
776 }
777 string->buffer.start = p;
778 string->free_after_use = true;
779 }
780
781 /*
782 * append_char(from, to)
783 *
784 * Append one char to a make string expanding it if nessecary
785 *
786 * Parameters:
787 * from Single character to append to string
788 * to The destination (make style) string
789 *
790 * Global variables used:
|
153 *
154 * Global variables used:
155 * funny The vector of semantic tags for characters
156 * hashtab The hashtable used for the nametable
157 */
158 Name
159 getname_fn(wchar_t *name, register int len, register Boolean dont_enter, register Boolean * foundp)
160 {
161 register int length;
162 register wchar_t *cap = name;
163 register Name np;
164 static Name_rec empty_Name;
165 char *tmp_mbs_buffer = NULL;
166 char *mbs_name = mbs_buffer;
167
168 /*
169 * First figure out how long the string is.
170 * If the len argument is -1 we count the chars here.
171 */
172 if (len == FIND_LENGTH) {
173 length = wcslen(name);
174 } else {
175 length = len;
176 }
177
178 Wstring ws;
179 ws.init(name, length);
180 if (length >= MAXPATHLEN) {
181 mbs_name = tmp_mbs_buffer = getmem((length * MB_LEN_MAX) + 1);
182 }
183 (void) wcstombs(mbs_name, ws.get_string(), (length * MB_LEN_MAX) + 1);
184
185 /* Look for the string */
186 if (dont_enter || (foundp != 0)) {
187 np = hashtab.lookup(mbs_name);
188 if (foundp != 0) {
189 *foundp = (np != 0) ? true : false;
190 }
191 if ((np != 0) || dont_enter) {
192 if(tmp_mbs_buffer != NULL) {
193 retmem_mb(tmp_mbs_buffer);
664 }
665 return NULL;
666 }
667
668 /*
669 * append_string(from, to, length)
670 *
671 * Append a C string to a make string expanding it if nessecary
672 *
673 * Parameters:
674 * from The source (C style) string
675 * to The destination (make style) string
676 * length The length of the from string
677 *
678 * Global variables used:
679 */
680 void
681 append_string(register wchar_t *from, register String to, register int length)
682 {
683 if (length == FIND_LENGTH) {
684 length = wcslen(from);
685 }
686 if (to->buffer.start == NULL) {
687 expand_string(to, 32 + length);
688 }
689 if (to->buffer.end - to->text.p <= length) {
690 expand_string(to,
691 (to->buffer.end - to->buffer.start) * 2 +
692 length);
693 }
694 if (length > 0) {
695 (void) wcsncpy(to->text.p, from, length);
696 to->text.p += length;
697 }
698 *(to->text.p) = (int) nul_char;
699 }
700
701 wchar_t * get_wstring(char *from) {
702 if(from == NULL) {
703 return NULL;
704 }
705 getwstring_count++;
706 wchar_t * wcbuf = ALLOC_WC(strlen(from) + 1);
707 mbstowcs(wcbuf, from, strlen(from)+1);
708 return wcbuf;
709 }
710
711 void
712 append_string(register char *from, register String to, register int length)
713 {
714 if (length == FIND_LENGTH) {
715 length = strlen(from);
750 string->buffer.start =
751 string->text.p =
752 string->text.end =
753 ALLOC_WC(length);
754 string->buffer.end = string->buffer.start + length;
755 string->text.p[0] = (int) nul_char;
756 string->free_after_use = true;
757 expandstring_count++;
758 return;
759 }
760 if (string->buffer.end - string->buffer.start >= length) {
761 /* If we really don't need more memory. */
762 return;
763 }
764 /*
765 * Get more memory, copy the string and free the old buffer if
766 * it is was malloc()'ed.
767 */
768 expandstring_count++;
769 p = ALLOC_WC(length);
770 (void) wcscpy(p, string->buffer.start);
771 string->text.p = p + (string->text.p - string->buffer.start);
772 string->text.end = p + (string->text.end - string->buffer.start);
773 string->buffer.end = p + length;
774 if (string->free_after_use) {
775 retmem(string->buffer.start);
776 }
777 string->buffer.start = p;
778 string->free_after_use = true;
779 }
780
781 /*
782 * append_char(from, to)
783 *
784 * Append one char to a make string expanding it if nessecary
785 *
786 * Parameters:
787 * from Single character to append to string
788 * to The destination (make style) string
789 *
790 * Global variables used:
|