version 1.6, 1998/05/22 05:15:12 |
version 1.7, 2001/01/08 07:14:42 |
|
|
/* $OpenBSD$ */ |
/* $OpenBSD$ */ |
|
|
/* |
/* |
* Copyright (c) 1985 Sun Microsystems, Inc. |
* Copyright (c) 1980, 1993 |
* Copyright (c) 1980 The Regents of the University of California. |
* The Regents of the University of California. |
* Copyright (c) 1976 Board of Trustees of the University of Illinois. |
* Copyright (c) 1976 Board of Trustees of the University of Illinois. |
|
* Copyright (c) 1985 Sun Microsystems, Inc. |
* All rights reserved. |
* All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
|
|
*/ |
*/ |
|
|
#ifndef lint |
#ifndef lint |
/*static char sccsid[] = "from: @(#)lexi.c 5.16 (Berkeley) 2/26/91";*/ |
/*static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93";*/ |
static char rcsid[] = "$OpenBSD$"; |
static char rcsid[] = "$OpenBSD$"; |
#endif /* not lint */ |
#endif /* not lint */ |
|
|
|
|
#include <ctype.h> |
#include <ctype.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
#include <err.h> |
#include "indent_globs.h" |
#include "indent_globs.h" |
#include "indent_codes.h" |
#include "indent_codes.h" |
|
|
|
|
lexi() |
lexi() |
{ |
{ |
int unary_delim; /* this is set to 1 if the current token |
int unary_delim; /* this is set to 1 if the current token |
* |
|
* forces a following operator to be unary */ |
* forces a following operator to be unary */ |
static int last_code; /* the last token type returned */ |
static int last_code; /* the last token type returned */ |
static int l_struct; /* set to 1 if the last token was 'struct' */ |
static int l_struct; /* set to 1 if the last token was 'struct' */ |
|
|
} |
} |
|
|
/* Scan an alphanumeric token */ |
/* Scan an alphanumeric token */ |
if (chartype[*buf_ptr] == alphanum || |
if (chartype[(int)*buf_ptr] == alphanum || |
(buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { |
(buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { |
/* |
/* |
* we have a character or number |
* we have a character or number |
*/ |
*/ |
register char *j; /* used for searching thru list of |
char *j; /* used for searching thru list of |
* |
* reserved words */ |
* reserved words */ |
|
if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { |
if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) { |
int seendot = 0, |
int seendot = 0, |
seenexp = 0, |
seenexp = 0, |
|
|
} |
} |
else |
else |
while (1) { |
while (1) { |
if (*buf_ptr == '.') |
if (*buf_ptr == '.') { |
if (seendot) |
if (seendot) |
break; |
break; |
else |
else |
seendot++; |
seendot++; |
|
} |
CHECK_SIZE_TOKEN; |
CHECK_SIZE_TOKEN; |
*e_token++ = *buf_ptr++; |
*e_token++ = *buf_ptr++; |
if (!isdigit(*buf_ptr) && *buf_ptr != '.') |
if (!isdigit(*buf_ptr) && *buf_ptr != '.') { |
if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp) |
if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp) |
break; |
break; |
else { |
else { |
|
|
if (*buf_ptr == '+' || *buf_ptr == '-') |
if (*buf_ptr == '+' || *buf_ptr == '-') |
*e_token++ = *buf_ptr++; |
*e_token++ = *buf_ptr++; |
} |
} |
|
} |
} |
} |
while (1) { |
while (1) { |
if (!(seensfx & 1) && |
if (!(seensfx & 1) && |
|
|
} |
} |
} |
} |
else |
else |
while (chartype[*buf_ptr] == alphanum) { /* copy it over */ |
while (chartype[(int)*buf_ptr] == alphanum) { /* copy it over */ |
CHECK_SIZE_TOKEN; |
CHECK_SIZE_TOKEN; |
*e_token++ = *buf_ptr++; |
*e_token++ = *buf_ptr++; |
if (buf_ptr >= buf_end) |
if (buf_ptr >= buf_end) |
|
|
* This loop will check if the token is a keyword. |
* This loop will check if the token is a keyword. |
*/ |
*/ |
for (i = 0; i < nspecials; i++) { |
for (i = 0; i < nspecials; i++) { |
register char *p = s_token; /* point at scanned token */ |
char *p = s_token; /* point at scanned token */ |
j = specials[i].rwd; |
j = specials[i].rwd; |
if (*j++ != *p++ || *j++ != *p++) |
if (*j++ != *p++ || *j++ != *p++) |
continue; /* This test depends on the fact that |
continue; /* This test depends on the fact that |
|
|
} /* end of switch */ |
} /* end of switch */ |
} /* end of if (found_it) */ |
} /* end of if (found_it) */ |
if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) { |
if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) { |
register char *tp = buf_ptr; |
char *tp = buf_ptr; |
while (tp < buf_end) |
while (tp < buf_end) |
if (*tp++ == ')' && (*tp == ';' || *tp == ',')) |
if (*tp++ == ')' && (*tp == ';' || *tp == ',')) |
goto not_proc; |
goto not_proc; |
strncpy(ps.procname, token, sizeof ps.procname - 1); |
strlcpy(ps.procname, token, sizeof ps.procname); |
ps.in_parameter_declaration = 1; |
ps.in_parameter_declaration = 1; |
rparen_count = 1; |
rparen_count = 1; |
not_proc:; |
not_proc:; |
|
|
char *key; |
char *key; |
int val; |
int val; |
{ |
{ |
register struct templ *p; |
struct templ *p; |
int i = 0; |
int i = 0; |
|
|
while (i < nspecials) { |
while (i < nspecials) { |
|
|
maxspecials += maxspecials >> 2; |
maxspecials += maxspecials >> 2; |
specials = (struct templ *)malloc(maxspecials * sizeof specials[0]); |
specials = (struct templ *)malloc(maxspecials * sizeof specials[0]); |
if (specials == NULL) |
if (specials == NULL) |
errx(1, "indent: out of memory"); |
errx(1, "out of memory"); |
memmove(specials, specialsinit, sizeof specialsinit); |
memmove(specials, specialsinit, sizeof specialsinit); |
} else if (nspecials >= maxspecials) { |
} else if (nspecials >= maxspecials) { |
maxspecials += maxspecials >> 2; |
maxspecials += maxspecials >> 2; |
specials = realloc(specials, maxspecials * sizeof specials[0]); |
specials = realloc(specials, maxspecials * sizeof specials[0]); |
if (specials == NULL) |
if (specials == NULL) |
errx(1, "indent: out of memory"); |
errx(1, "out of memory"); |
} |
} |
|
|
p = &specials[i]; |
p = &specials[i]; |
p->rwd = key; |
p->rwd = key; |
p->rwcode = val; |
p->rwcode = val; |