246 # if STDC_HEADERS || HAVE_STRING_H 249 # include <strings.h> 257 # include <strings.h> 260 extern int strlen(), strncmp();
295 # define HAVE_ISASCII 1 298 #if STDC_HEADERS || !HAVE_ISASCII 299 # define is_ascii(c) 1 301 # define is_ascii(c) isascii(c) 304 #define is_space(c) (is_ascii(c) && isspace(c)) 305 #define is_alpha(c) (is_ascii(c) && isalpha(c)) 306 #define is_alnum(c) (is_ascii(c) && isalnum(c)) 309 #define isidchar(ch) (is_alnum(ch) || (ch) == '_') 310 #define isidfirstchar(ch) (is_alpha(ch) || (ch) == '_') 336 int convert_varargs = 1;
338 if ( argc > 1 && argv[1][0] ==
'-' )
339 {
if ( !strcmp(argv[1],
"--varargs") )
340 { convert_varargs = 1;
345 { fprintf(stderr,
"Unrecognized switch: %s\n", argv[1]);
352 printf(
"Usage: ansi2knr input_file [output_file]\n");
358 out = fopen(argv[2],
"w");
360 { fprintf(stderr,
"Cannot open output file %s\n", argv[2]);
364 in = fopen(argv[1],
"r");
366 { fprintf(stderr,
"Cannot open input file %s\n", argv[1]);
369 fprintf(out,
"#line 1 \"%s\"\n", argv[1]);
372 while ( fgets(line, (
unsigned)(buf +
bufsize - line), in) !=
NULL )
374 test: line += strlen(line);
375 switch (
test1(buf) )
378 convert1(buf, out, 1, convert_varargs);
383 f:
if ( line >= buf + (
bufsize - 1) )
385 if ( fgets(line, (
unsigned)(buf +
bufsize - line), in) ==
NULL )
391 convert1(buf, out, 0, convert_varargs);
397 line += strlen(line);
409 if ( line != buf + (
bufsize - 1) )
434 if ( !(*
p ==
'/' &&
p[dir] ==
'*') )
437 while ( !(*
p ==
'*' &&
p[dir] ==
'/') )
457 if ( *p !=
'\r' && *p !=
'\n' )
478 {
register char *
p =
buf;
488 case ';': contin = 0 ;
break;
489 case ')': contin = 1;
break;
492 default: contin = -1;
506 {
static char *words[] =
507 {
"asm",
"auto",
"case",
"char",
"const",
"double",
508 "extern",
"float",
"for",
"if",
"int",
"long",
509 "register",
"return",
"short",
"signed",
"sizeof",
510 "static",
"switch",
"typedef",
"unsigned",
511 "void",
"volatile",
"while", 0
517 while ( (kp = *key) != 0 )
518 {
if ( strlen(kp) == len && !strncmp(kp, buf, len) )
536 unsigned num_breaks = 2;
544 for ( endfn =
buf; *(endfn++) !=
'('; )
547 breaks = (
char **)
malloc(
sizeof(
char *) * num_breaks * 2);
550 fprintf(stderr,
"Unable to allocate break table!\n");
554 btop = breaks + num_breaks * 2 - 2;
566 free((
char *)breaks);
572 for ( ; end ==
NULL; p++ )
576 if ( !level ) end =
p;
579 if ( !level ) lp =
p;
583 if ( --level < 0 ) end =
p;
610 case ']':
case ')': level++;
break;
611 case '[':
case '(': level--;
break;
612 case '/': p =
skipspace(p, -1) + 1;
break;
616 if ( *p ==
'(' && *
skipspace(p + 1, 1) ==
'*' )
627 found:
if ( *p ==
'.' && p[-1] ==
'.' && p[-2] ==
'.' )
628 {
if ( convert_varargs )
629 { *bp++ =
"va_alist";
634 if ( bp == breaks + 1 )
647 while ( *p++ ==
',' );
650 if ( bp == breaks+2 )
652 if ( !strncmp(p,
"void", 4) )
654 if ( p == breaks[2] - 1 )
662 while ( p != endfn ) putc(*p,
out), p++;
666 for ( p = breaks[0]; *
p; p++ )
667 if ( *p ==
'\r' || *p ==
'\n' )
671 {
for ( ap = breaks+1; ap < bp; ap += 2 )
680 for ( ap = breaks+2; ap <= bp; ap += 2 )
684 fputs(breaks[0],
out);
685 fputs(
"va_dcl",
out);
689 fputs(breaks[0],
out);
691 free((
char *)breaks);
GLenum GLuint GLsizei bufsize
GLenum GLuint GLenum GLsizei const GLchar * buf
local int out(void *out_desc, unsigned char *buf, unsigned len)
GLdouble GLdouble GLdouble GLdouble top
#define isidfirstchar(ch)