Skip to content

Commit db4a406

Browse files
committed
some wide-char support
Rev: src/cpp.c:1.29 Rev: src/lex.c:1.56 Rev: src/opcodes.c:1.30 Rev: src/pike_memory.c:1.25 Rev: src/pike_memory.h:1.5 Rev: src/stralloc.c:1.39 Rev: src/stralloc.h:1.18 Rev: src/svalue.c:1.38
1 parent 7dd1977 commit db4a406

File tree

8 files changed

+859
-121
lines changed

8 files changed

+859
-121
lines changed

src/cpp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
\*/
66

77
/*
8-
* $Id: cpp.c,v 1.28 1998/08/12 05:19:30 hubbe Exp $
8+
* $Id: cpp.c,v 1.29 1998/10/09 17:56:31 hubbe Exp $
99
*/
1010
#include "global.h"
1111
#include "dynamic_buffer.h"
@@ -233,7 +233,7 @@ static void simple_add_define(struct cpp *this,
233233
break; \
234234
} \
235235
\
236-
if(e++>16) \
236+
if(e++>32) \
237237
{ \
238238
cpp_error(this,"Too long character constant."); \
239239
break; \

src/lex.c

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
||| See the files COPYING and DISCLAIMER for more information.
55
\*/
66
#include "global.h"
7-
RCSID("$Id: lex.c,v 1.55 1998/06/07 12:26:51 grubba Exp $");
7+
RCSID("$Id: lex.c,v 1.56 1998/10/09 17:56:32 hubbe Exp $");
88
#include "language.h"
99
#include "array.h"
1010
#include "lex.h"
@@ -362,10 +362,8 @@ static int char_const(void)
362362
case '0': case '1': case '2': case '3':
363363
case '4': case '5': case '6': case '7':
364364
c-='0';
365-
if(LOOK()<'0' || LOOK()>'8') return c;
366-
c=c*8+(GETC()-'0');
367-
if(LOOK()<'0' || LOOK()>'8') return c;
368-
c=c*8+(GETC()-'0');
365+
while(LOOK()>='0' && LOOK()<='8')
366+
c=c*8+(GETC()-'0');
369367
return c;
370368

371369
case 'r': return '\r';
@@ -377,53 +375,52 @@ static int char_const(void)
377375
lex.current_line++;
378376
return '\n';
379377

380-
381378
case 'x':
382-
switch(LOOK())
379+
c=0;
380+
while(1)
383381
{
384-
default: return c;
385-
case '0': case '1': case '2': case '3':
386-
case '4': case '5': case '6': case '7':
387-
case '8': case '9':
388-
c=GETC()-'0';
389-
break;
390-
391-
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
392-
c=GETC()-'a'+10;
393-
break;
394-
395-
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
396-
c=GETC()-'A'+10;
397-
break;
382+
switch(LOOK())
383+
{
384+
default: return c;
385+
case '0': case '1': case '2': case '3':
386+
case '4': case '5': case '6': case '7':
387+
case '8': case '9':
388+
c=c*16+GETC()-'0';
389+
break;
390+
391+
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
392+
c=c*16+GETC()-'a'+10;
393+
break;
394+
395+
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
396+
c=c*16+GETC()-'A'+10;
397+
break;
398+
}
398399
}
399-
switch(LOOK())
400+
401+
case 'd':
402+
c=0;
403+
while(1)
400404
{
401-
default: return c;
402-
case '0': case '1': case '2': case '3':
403-
case '4': case '5': case '6': case '7':
404-
case '8': case '9':
405-
c=c*16+GETC()-'0';
406-
break;
407-
408-
case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
409-
c=c*16+GETC()-'a'+10;
410-
break;
411-
412-
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
413-
c=c*16+GETC()-'A'+10;
414-
break;
405+
switch(LOOK())
406+
{
407+
default: return c;
408+
case '0': case '1': case '2': case '3':
409+
case '4': case '5': case '6': case '7':
410+
case '8': case '9':
411+
c=c*10+GETC()-'0';
412+
break;
413+
}
415414
}
416-
return c;
417-
418415
}
419416
return c;
420417
}
421418

422419
static struct pike_string *readstring(void)
423420
{
424421
int c;
425-
dynamic_buffer tmp;
426-
initialize_buf(&tmp);
422+
struct string_builder tmp;
423+
init_string_builder(&tmp,0);
427424

428425
while(1)
429426
{
@@ -440,19 +437,19 @@ static struct pike_string *readstring(void)
440437
break;
441438

442439
case '\\':
443-
low_my_putchar(char_const(),&tmp);
440+
string_builder_putchar(&tmp,char_const());
444441
continue;
445442

446443
case '"':
447444
break;
448445

449446
default:
450-
low_my_putchar(c,&tmp);
447+
string_builder_putchar(&tmp,c);
451448
continue;
452449
}
453450
break;
454451
}
455-
return low_free_buf(&tmp);
452+
return finish_string_builder(&tmp);
456453
}
457454

458455
int yylex(YYSTYPE *yylval)

src/opcodes.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "builtin_functions.h"
2323
#include "module_support.h"
2424

25-
RCSID("$Id: opcodes.c,v 1.29 1998/07/04 16:56:14 grubba Exp $");
25+
RCSID("$Id: opcodes.c,v 1.30 1998/10/09 17:56:32 hubbe Exp $");
2626

2727
void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)
2828
{
@@ -57,7 +57,7 @@ void index_no_free(struct svalue *to,struct svalue *what,struct svalue *ind)
5757
if(i<0 || i>=what->u.string->len)
5858
error("Index %d is out of range 0 - %d.\n", i, what->u.string->len-1);
5959
else
60-
i=EXTRACT_UCHAR(what->u.string->str + i);
60+
i=index_shared_string(what->u.string,i);
6161
to->type=T_INT;
6262
to->subtype=NUMBER_NUMBER;
6363
to->u.integer=i;

src/pike_memory.c

Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "pike_macros.h"
1010
#include "gc.h"
1111

12-
RCSID("$Id: pike_memory.c,v 1.24 1998/04/24 00:02:45 hubbe Exp $");
12+
RCSID("$Id: pike_memory.c,v 1.25 1998/10/09 17:56:32 hubbe Exp $");
1313

1414
/* strdup() is used by several modules, so let's provide it */
1515
#ifndef HAVE_STRDUP
@@ -28,6 +28,20 @@ char *strdup(const char *str)
2828
}
2929
#endif /* !HAVE_STRDUP */
3030

31+
INLINE p_wchar1 *MEMCHR1(p_wchar1 *p,p_wchar1 c,INT32 e)
32+
{
33+
e++;
34+
while(--e >= 0) if(*(p++)==c) return p-1;
35+
return (p_wchar1 *)0;
36+
}
37+
38+
INLINE p_wchar2 *MEMCHR2(p_wchar2 *p,p_wchar2 c,INT32 e)
39+
{
40+
e++;
41+
while(--e >= 0) if(*(p++)==c) return p-1;
42+
return (p_wchar2 *)0;
43+
}
44+
3145
void swap(char *a, char *b, INT32 size)
3246
{
3347
int tmp;
@@ -308,7 +322,6 @@ void init_memsearch(struct mem_searcher *s,
308322
}
309323
}
310324
}
311-
312325

313326
char *memory_search(struct mem_searcher *s,
314327
char *haystack,
@@ -318,6 +331,8 @@ char *memory_search(struct mem_searcher *s,
318331

319332
switch(s->method)
320333
{
334+
default:
335+
fatal("Don't know how to search like that!\n");
321336
case no_search:
322337
return haystack;
323338

@@ -379,6 +394,100 @@ char *memory_search(struct mem_searcher *s,
379394
return 0;
380395
}
381396

397+
398+
void init_generic_memsearcher(struct generic_mem_searcher *s,
399+
void *needle,
400+
SIZE_T needlelen,
401+
char needle_shift,
402+
SIZE_T estimated_haystack,
403+
char haystack_shift)
404+
{
405+
s->needle_shift=needle_shift;
406+
s->haystack_shift=haystack_shift;
407+
408+
if(needle_shift ==1 && haystack_shift ==1)
409+
{
410+
init_memsearch(& s->data.eightbit, (char *)needle, estimated_haystack,estimated_haystack);
411+
return;
412+
}
413+
414+
switch(needlelen)
415+
{
416+
case 0: s->data.other.method=no_search; break;
417+
case 1:
418+
s->data.other.method=use_memchr;
419+
switch(s->needle_shift)
420+
{
421+
case 0: s->data.other.first_char=*(p_wchar0 *)needle; break;
422+
case 1: s->data.other.first_char=*(p_wchar1 *)needle; break;
423+
case 2: s->data.other.first_char=*(p_wchar2 *)needle; break;
424+
}
425+
break;
426+
427+
default:
428+
s->data.other.method=memchr_and_memcmp;
429+
switch(s->needle_shift)
430+
{
431+
case 0: s->data.other.first_char=*(p_wchar0 *)needle; break;
432+
case 1: s->data.other.first_char=*(p_wchar1 *)needle; break;
433+
case 2: s->data.other.first_char=*(p_wchar2 *)needle; break;
434+
}
435+
break;
436+
}
437+
}
438+
439+
void *generic_memory_search(struct generic_mem_searcher *s,
440+
void *haystack,
441+
SIZE_T haystacklen,
442+
char haystack_shift)
443+
{
444+
if(s->needle_shift==1 && s->haystack_shift==1)
445+
{
446+
return memory_search(& s->data.eightbit, (char *)haystack, haystacklen);
447+
}
448+
switch((s->data.other.method<<2) + haystack_shift)
449+
{
450+
451+
#define GENERIC(X) \
452+
case (no_search << 2) + X: \
453+
return haystack; \
454+
\
455+
case (use_memchr << 2) + X: \
456+
return PIKE_CONCAT(MEMCHR,X)((PIKE_CONCAT(p_wchar,X) *)haystack, \
457+
s->data.other.first_char, \
458+
haystacklen); \
459+
\
460+
case (memchr_and_memcmp << 2) + X: \
461+
{ \
462+
PIKE_CONCAT(p_wchar,X) *end,c,*needle,*hay; \
463+
SIZE_T needlelen; \
464+
\
465+
needle=(PIKE_CONCAT(p_wchar,X) *)s->data.other.needle; \
466+
hay=(PIKE_CONCAT(p_wchar,X) *)haystack; \
467+
needlelen=s->data.other.needlelen; \
468+
\
469+
end=hay + haystacklen - needlelen+1; \
470+
needle++; \
471+
needlelen--; \
472+
while((hay=PIKE_CONCAT(MEMCHR,X)(hay, \
473+
s->data.other.first_char, \
474+
end-hay))) \
475+
if(!MEMCMP(++hay,needle,needlelen)) \
476+
return (void *)(hay-1); \
477+
\
478+
return 0; \
479+
}
480+
481+
482+
GENERIC(0)
483+
GENERIC(1)
484+
GENERIC(2)
485+
486+
#undef GENERIC
487+
}
488+
}
489+
490+
382491
char *my_memmem(char *needle,
383492
SIZE_T needlelen,
384493
char *haystack,

0 commit comments

Comments
 (0)