mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
not yet, committed too much
This commit is contained in:
parent
456f9fcb4d
commit
8008022cde
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: extern.h,v 1.46 2008/08/16 12:21:46 espie Exp $ */
|
||||
/* $OpenBSD: extern.h,v 1.47 2008/08/16 12:23:50 espie Exp $ */
|
||||
/* $NetBSD: extern.h,v 1.3 1996/01/13 23:25:24 pk Exp $ */
|
||||
|
||||
/*-
|
||||
@ -109,7 +109,7 @@ extern void usage(void);
|
||||
extern void resizedivs(int);
|
||||
extern size_t buffer_mark(void);
|
||||
extern void dump_buffer(FILE *, size_t);
|
||||
extern void __dead m4errx(int, const char *, ...);
|
||||
extern void m4errx(int, const char *, ...);
|
||||
|
||||
extern int obtain_char(struct input_file *);
|
||||
extern void set_input(struct input_file *, FILE *, const char *);
|
||||
@ -133,7 +133,7 @@ extern void release_input(struct input_file *);
|
||||
/* and corresponding exposure for local symbols */
|
||||
extern void enlarge_bufspace(void);
|
||||
extern void enlarge_strspace(void);
|
||||
extern unsigned char *endpbb;
|
||||
extern char *endpbb;
|
||||
extern char *endest;
|
||||
|
||||
/* trace.c */
|
||||
@ -156,10 +156,10 @@ extern int fp; /* m4 call frame pointer */
|
||||
extern int ilevel; /* input file stack pointer */
|
||||
extern int oindex; /* diversion index. */
|
||||
extern int sp; /* current m4 stack pointer */
|
||||
extern unsigned char *bp; /* first available character */
|
||||
extern unsigned char *buf; /* push-back buffer */
|
||||
extern unsigned char *bufbase; /* buffer base for this ilevel */
|
||||
extern unsigned char *bbase[]; /* buffer base per ilevel */
|
||||
extern char *bp; /* first available character */
|
||||
extern char *buf; /* push-back buffer */
|
||||
extern char *bufbase; /* buffer base for this ilevel */
|
||||
extern char *bbase[]; /* buffer base per ilevel */
|
||||
extern char ecommt[MAXCCHARS+1];/* end character for comment */
|
||||
extern char *ep; /* first free char in strspace */
|
||||
extern char lquote[MAXCCHARS+1];/* left quote character (`) */
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: gnum4.c,v 1.37 2008/08/16 12:21:46 espie Exp $ */
|
||||
/* $OpenBSD: gnum4.c,v 1.38 2008/08/16 12:23:50 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999 Marc Espie
|
||||
@ -508,85 +508,43 @@ doformat(const char *argv[], int argc)
|
||||
{
|
||||
const char *format = argv[2];
|
||||
int pos = 3;
|
||||
int left_padded;
|
||||
long width;
|
||||
size_t l;
|
||||
const char *thisarg;
|
||||
char temp[2];
|
||||
long extra;
|
||||
|
||||
while (*format != 0) {
|
||||
if (*format != '%') {
|
||||
addchar(*format++);
|
||||
continue;
|
||||
}
|
||||
|
||||
format++;
|
||||
if (*format == '%') {
|
||||
addchar(*format++);
|
||||
continue;
|
||||
}
|
||||
if (*format == 0) {
|
||||
addchar('%');
|
||||
break;
|
||||
}
|
||||
|
||||
if (*format == '*') {
|
||||
format++;
|
||||
if (pos >= argc)
|
||||
m4errx(1,
|
||||
"Format with too many format specifiers.");
|
||||
width = strtol(argv[pos++], NULL, 10);
|
||||
} else {
|
||||
width = strtol(format, (char **)&format, 10);
|
||||
}
|
||||
if (width < 0) {
|
||||
left_padded = 1;
|
||||
width = -width;
|
||||
} else {
|
||||
left_padded = 0;
|
||||
}
|
||||
if (*format == '.') {
|
||||
format++;
|
||||
if (*format == '*') {
|
||||
format++;
|
||||
if (pos >= argc)
|
||||
m4errx(1,
|
||||
"Format with too many format specifiers.");
|
||||
extra = strtol(argv[pos++], NULL, 10);
|
||||
if (*format == '%' || *format == 0) {
|
||||
addchar('%');
|
||||
if (*format == '%')
|
||||
format++;
|
||||
} else {
|
||||
extra = strtol(format, (char **)&format, 10);
|
||||
int left_padded = 0;
|
||||
unsigned long width;
|
||||
size_t l;
|
||||
|
||||
if (*format == '-') {
|
||||
left_padded = 1;
|
||||
format++;
|
||||
}
|
||||
width = strtoul(format, (char **)&format, 10);
|
||||
if (*format != 's') {
|
||||
m4errx(1, "Unsupported format specification: %s.", argv[2]);
|
||||
}
|
||||
format++;
|
||||
if (pos >= argc)
|
||||
m4errx(1, "Format with too many values.");
|
||||
l = strlen(argv[pos]);
|
||||
if (!left_padded) {
|
||||
while (l < width--)
|
||||
addchar(' ');
|
||||
}
|
||||
addchars(argv[pos++], l);
|
||||
if (left_padded) {
|
||||
while (l < width--)
|
||||
addchar(' ');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
extra = LONG_MAX;
|
||||
}
|
||||
if (pos >= argc)
|
||||
m4errx(1, "Format with too many format specifiers.");
|
||||
switch(*format) {
|
||||
case 's':
|
||||
thisarg = argv[pos++];
|
||||
break;
|
||||
case 'c':
|
||||
temp[0] = strtoul(argv[pos++], NULL, 10);
|
||||
temp[1] = 0;
|
||||
thisarg = temp;
|
||||
break;
|
||||
default:
|
||||
m4errx(1, "Unsupported format specification: %s.",
|
||||
argv[2]);
|
||||
}
|
||||
format++;
|
||||
l = strlen(thisarg);
|
||||
if (l > extra)
|
||||
l = extra;
|
||||
if (!left_padded) {
|
||||
while (l < width--)
|
||||
addchar(' ');
|
||||
}
|
||||
addchars(thisarg, l);
|
||||
if (left_padded) {
|
||||
while (l < width--)
|
||||
addchar(' ');
|
||||
}
|
||||
}
|
||||
pbstr(getstring());
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: misc.c,v 1.38 2008/08/16 12:21:46 espie Exp $ */
|
||||
/* $OpenBSD: misc.c,v 1.39 2008/08/16 12:23:50 espie Exp $ */
|
||||
/* $NetBSD: misc.c,v 1.6 1995/09/28 05:37:41 tls Exp $ */
|
||||
|
||||
/*
|
||||
@ -54,11 +54,11 @@ char *endest; /* end of string space */
|
||||
static size_t strsize = STRSPMAX;
|
||||
static size_t bufsize = BUFSIZE;
|
||||
|
||||
unsigned char *buf; /* push-back buffer */
|
||||
unsigned char *bufbase; /* the base for current ilevel */
|
||||
unsigned char *bbase[MAXINP]; /* the base for each ilevel */
|
||||
unsigned char *bp; /* first available character */
|
||||
unsigned char *endpbb; /* end of push-back buffer */
|
||||
char *buf; /* push-back buffer */
|
||||
char *bufbase; /* the base for current ilevel */
|
||||
char *bbase[MAXINP]; /* the base for each ilevel */
|
||||
char *bp; /* first available character */
|
||||
char *endpbb; /* end of push-back buffer */
|
||||
|
||||
|
||||
/*
|
||||
@ -163,7 +163,7 @@ initspaces()
|
||||
strspace = xalloc(strsize+1, NULL);
|
||||
ep = strspace;
|
||||
endest = strspace+strsize;
|
||||
buf = (unsigned char *)xalloc(bufsize, NULL);
|
||||
buf = (char *)xalloc(bufsize, NULL);
|
||||
bufbase = buf;
|
||||
bp = buf;
|
||||
endpbb = buf + bufsize;
|
||||
@ -195,7 +195,7 @@ enlarge_strspace()
|
||||
void
|
||||
enlarge_bufspace()
|
||||
{
|
||||
unsigned char *newbuf;
|
||||
char *newbuf;
|
||||
int i;
|
||||
|
||||
bufsize += bufsize/2;
|
||||
@ -418,7 +418,7 @@ buffer_mark()
|
||||
void
|
||||
dump_buffer(FILE *f, size_t m)
|
||||
{
|
||||
unsigned char *s;
|
||||
char *s;
|
||||
|
||||
for (s = bp; s-buf > m;)
|
||||
fputc(*--s, f);
|
||||
|
@ -1,5 +1,5 @@
|
||||
%{
|
||||
/* $OpenBSD: parser.y,v 1.4 2008/08/16 12:21:46 espie Exp $ */
|
||||
/* $OpenBSD: parser.y,v 1.5 2008/08/16 12:23:50 espie Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
|
||||
*
|
||||
@ -22,7 +22,6 @@ extern int yylex(void);
|
||||
extern int yyerror(const char *);
|
||||
%}
|
||||
%token NUMBER
|
||||
%token ERROR
|
||||
%left LOR
|
||||
%left LAND
|
||||
%left '|'
|
||||
|
@ -1,5 +1,5 @@
|
||||
%{
|
||||
/* $OpenBSD: tokenizer.l,v 1.4 2008/08/16 12:21:46 espie Exp $ */
|
||||
/* $OpenBSD: tokenizer.l,v 1.5 2008/08/16 12:23:50 espie Exp $ */
|
||||
/*
|
||||
* Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
|
||||
*
|
||||
@ -21,11 +21,9 @@
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
extern int mimic_gnu;
|
||||
extern int32_t yylval;
|
||||
|
||||
int32_t number(void);
|
||||
int32_t parse_radix(void);
|
||||
%}
|
||||
|
||||
delim [ \t\n]
|
||||
@ -33,17 +31,10 @@ ws {delim}+
|
||||
hex 0[xX][0-9a-fA-F]+
|
||||
oct 0[0-7]*
|
||||
dec [1-9][0-9]*
|
||||
radix 0[rR][0-9]+:[0-9a-zA-Z]+
|
||||
|
||||
%%
|
||||
{ws} {/* just skip it */}
|
||||
{hex}|{oct}|{dec} { yylval = number(); return(NUMBER); }
|
||||
{radix} { if (mimic_gnu) {
|
||||
yylval = parse_radix(); return(NUMBER);
|
||||
} else {
|
||||
return(ERROR);
|
||||
}
|
||||
}
|
||||
"<=" { return(LE); }
|
||||
">=" { return(GE); }
|
||||
"<<" { return(LSHIFT); }
|
||||
@ -67,31 +58,5 @@ number()
|
||||
fprintf(stderr, "m4: numeric overflow in expr: %s\n", yytext);
|
||||
}
|
||||
return l;
|
||||
|
||||
}
|
||||
|
||||
int32_t
|
||||
parse_radix()
|
||||
{
|
||||
long base;
|
||||
char *next;
|
||||
long l;
|
||||
|
||||
l = 0;
|
||||
base = strtol(yytext+2, &next, 0);
|
||||
if (base > 36 || next == NULL) {
|
||||
fprintf(stderr, "m4: error in number %s\n", yytext);
|
||||
} else {
|
||||
next++;
|
||||
while (*next != 0) {
|
||||
if (*next >= '0' && *next <= '9')
|
||||
l = base * l + *next - '0';
|
||||
else if (*next >= 'a' && *next <= 'z')
|
||||
l = base * l + *next - 'a' + 10;
|
||||
else if (*next >= 'A' && *next <= 'Z')
|
||||
l = base * l + *next - 'A' + 10;
|
||||
next++;
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user