mirror of
https://github.com/postgres/postgres.git
synced 2025-10-16 17:07:43 +03:00
Postgres95 1.01 Distribution - Virgin Sources
This commit is contained in:
63
src/backend/bootstrap/Makefile.inc
Normal file
63
src/backend/bootstrap/Makefile.inc
Normal file
@@ -0,0 +1,63 @@
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Makefile.inc--
|
||||
# Makefile for the bootstrap module
|
||||
#
|
||||
# Copyright (c) 1994, Regents of the University of California
|
||||
#
|
||||
#
|
||||
# IDENTIFICATION
|
||||
# $Header: /cvsroot/pgsql/src/backend/bootstrap/Attic/Makefile.inc,v 1.1.1.1 1996/07/09 06:21:14 scrappy Exp $
|
||||
#
|
||||
#
|
||||
# Another kinda weird Makefile.inc cause we need two
|
||||
# scanner/parsers in the backend and most yaccs and lexs
|
||||
# don't have the prefix option.
|
||||
#
|
||||
# sed files are HACK CITY! - redo...
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
bootdir= $(CURDIR)/bootstrap
|
||||
VPATH:= $(VPATH):$(bootdir)
|
||||
|
||||
#BOOTYACCS= bootstrap_tokens.h bootparse.c
|
||||
BOOTYACCS= bootparse.c
|
||||
|
||||
SRCS_BOOTSTRAP= bootparse.c bootscanner.c bootstrap.c
|
||||
|
||||
$(BOOTYACCS): bootparse.y
|
||||
cd $(objdir); \
|
||||
$(YACC) $(YFLAGS) $<; \
|
||||
sed -f $(bootdir)/boot.sed < y.tab.c > bootparse.c; \
|
||||
mv y.tab.h bootstrap_tokens.h; \
|
||||
rm -f y.tab.c
|
||||
|
||||
$(objdir)/bootparse.o: bootparse.c
|
||||
$(cc_inobjdir)
|
||||
|
||||
|
||||
bootscanner.c: bootscanner.l
|
||||
cd $(objdir); \
|
||||
$(LEX) $<; \
|
||||
sed -f $(bootdir)/boot.sed < lex.yy.c > bootscanner.c; \
|
||||
rm -f lex.yy.c
|
||||
|
||||
$(objdir)/bootscanner.o: bootscanner.c
|
||||
$(cc_inobjdir)
|
||||
|
||||
|
||||
|
||||
#
|
||||
# The following insures that y.tab.h gets made as bootstrap.c
|
||||
# includes it
|
||||
#
|
||||
bootstrap.o: $(BOOTYACCS)
|
||||
|
||||
POSTGRES_DEPEND+= $(BOOTYACCS) bootscanner.c
|
||||
|
||||
|
||||
CLEANFILES+= bootscanner.c $(BOOTYACCS) y.tab.h y.output
|
||||
|
||||
HEADERS+= bootstrap.h
|
||||
|
9
src/backend/bootstrap/boot.sed
Normal file
9
src/backend/bootstrap/boot.sed
Normal file
@@ -0,0 +1,9 @@
|
||||
#
|
||||
# lex.sed - sed rules to remove conflicts between the
|
||||
# bootstrap backend interface LEX scanner and the
|
||||
# normal backend SQL LEX scanner
|
||||
#
|
||||
# $Header: /cvsroot/pgsql/src/backend/bootstrap/Attic/boot.sed,v 1.1.1.1 1996/07/09 06:21:14 scrappy Exp $
|
||||
#
|
||||
s/^yy/Int_yy/g
|
||||
s/\([^a-zA-Z0-9_]\)yy/\1Int_yy/g
|
293
src/backend/bootstrap/bootparse.y
Normal file
293
src/backend/bootstrap/bootparse.y
Normal file
@@ -0,0 +1,293 @@
|
||||
%{
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* backendparse.y--
|
||||
* yacc parser grammer for the "backend" initialization program.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootparse.y,v 1.1.1.1 1996/07/09 06:21:14 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "access/heapam.h"
|
||||
#include "access/tupdesc.h"
|
||||
#include "bootstrap/bootstrap.h"
|
||||
#include "utils/portal.h"
|
||||
#include "storage/smgr.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "catalog/catalog.h"
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/heap.h"
|
||||
#include "catalog/index.h"
|
||||
#include "commands/rename.h"
|
||||
#include "commands/defrem.h"
|
||||
#include "access/transam.h"
|
||||
#include "access/xact.h"
|
||||
|
||||
#define DO_START { StartTransactionCommand();\
|
||||
}
|
||||
|
||||
#define DO_END { CommitTransactionCommand();\
|
||||
if (!Quiet) { EMITPROMPT; }\
|
||||
fflush(stdout); \
|
||||
}
|
||||
|
||||
int num_tuples_read = 0;
|
||||
static Oid objectid;
|
||||
|
||||
%}
|
||||
|
||||
%union {
|
||||
List *list;
|
||||
IndexElem *ielem;
|
||||
char *str;
|
||||
int ival;
|
||||
}
|
||||
|
||||
%type <list> arg_list
|
||||
%type <ielem> index_params index_on
|
||||
%type <ival> const ident
|
||||
%type <ival> optbootstrap optoideq tuple tuplelist
|
||||
|
||||
%token <ival> CONST ID
|
||||
%token OPEN XCLOSE XCREATE INSERT_TUPLE
|
||||
%token STRING XDEFINE
|
||||
%token XDECLARE INDEX ON USING XBUILD INDICES
|
||||
%token COMMA EQUALS LPAREN RPAREN
|
||||
%token OBJ_ID XBOOTSTRAP NULLVAL
|
||||
%start TopLevel
|
||||
|
||||
%nonassoc low
|
||||
%nonassoc high
|
||||
|
||||
%%
|
||||
|
||||
TopLevel:
|
||||
Queries
|
||||
|
|
||||
;
|
||||
|
||||
Queries:
|
||||
Query
|
||||
| Queries Query
|
||||
;
|
||||
|
||||
Query :
|
||||
OpenStmt
|
||||
| CloseStmt
|
||||
| CreateStmt
|
||||
| InsertStmt
|
||||
| DeclareIndexStmt
|
||||
| BuildIndsStmt
|
||||
;
|
||||
|
||||
OpenStmt:
|
||||
OPEN ident
|
||||
{
|
||||
DO_START;
|
||||
boot_openrel(LexIDStr($2));
|
||||
DO_END;
|
||||
}
|
||||
;
|
||||
|
||||
CloseStmt:
|
||||
XCLOSE ident %prec low
|
||||
{
|
||||
DO_START;
|
||||
closerel(LexIDStr($2));
|
||||
DO_END;
|
||||
}
|
||||
| XCLOSE %prec high
|
||||
{
|
||||
DO_START;
|
||||
closerel(NULL);
|
||||
DO_END;
|
||||
}
|
||||
;
|
||||
|
||||
CreateStmt:
|
||||
XCREATE optbootstrap ident LPAREN
|
||||
{
|
||||
DO_START;
|
||||
numattr=(int)0;
|
||||
}
|
||||
typelist
|
||||
{
|
||||
if (!Quiet) putchar('\n');
|
||||
DO_END;
|
||||
}
|
||||
RPAREN
|
||||
{
|
||||
DO_START;
|
||||
|
||||
if ($2) {
|
||||
extern Relation reldesc;
|
||||
TupleDesc tupdesc;
|
||||
|
||||
if (reldesc) {
|
||||
puts("create bootstrap: Warning, open relation");
|
||||
puts("exists, closing first");
|
||||
closerel(NULL);
|
||||
}
|
||||
if (DebugMode)
|
||||
puts("creating bootstrap relation");
|
||||
tupdesc = CreateTupleDesc(numattr,attrtypes);
|
||||
reldesc = heap_creatr(LexIDStr($3),
|
||||
DEFAULT_SMGR,
|
||||
tupdesc);
|
||||
if (DebugMode)
|
||||
puts("bootstrap relation created ok");
|
||||
} else {
|
||||
Oid id;
|
||||
TupleDesc tupdesc;
|
||||
/* extern Oid heap_create();*/
|
||||
|
||||
tupdesc = CreateTupleDesc(numattr,attrtypes);
|
||||
id = heap_create(LexIDStr($3),
|
||||
NULL,
|
||||
'n',
|
||||
DEFAULT_SMGR,
|
||||
tupdesc);
|
||||
if (!Quiet)
|
||||
printf("CREATED relation %s with OID %d\n",
|
||||
LexIDStr($3), id);
|
||||
}
|
||||
DO_END;
|
||||
if (DebugMode)
|
||||
puts("Commit End");
|
||||
}
|
||||
;
|
||||
|
||||
InsertStmt:
|
||||
INSERT_TUPLE optoideq
|
||||
{
|
||||
DO_START;
|
||||
if (DebugMode)
|
||||
printf("tuple %d<", $2);
|
||||
num_tuples_read = 0;
|
||||
}
|
||||
LPAREN tuplelist RPAREN
|
||||
{
|
||||
if (num_tuples_read != numattr)
|
||||
elog(WARN,"incorrect number of values for tuple");
|
||||
if (reldesc == (Relation)NULL) {
|
||||
elog(WARN,"must OPEN RELATION before INSERT\n");
|
||||
err();
|
||||
}
|
||||
if (DebugMode)
|
||||
puts("Insert Begin");
|
||||
objectid = $2;
|
||||
InsertOneTuple(objectid);
|
||||
if (DebugMode)
|
||||
puts("Insert End");
|
||||
if (!Quiet) { putchar('\n'); }
|
||||
DO_END;
|
||||
if (DebugMode)
|
||||
puts("Transaction End");
|
||||
}
|
||||
;
|
||||
|
||||
DeclareIndexStmt:
|
||||
XDECLARE INDEX ident ON ident USING ident LPAREN index_params RPAREN
|
||||
{
|
||||
List *params;
|
||||
|
||||
DO_START;
|
||||
|
||||
params = lappend(NIL, (List*)$9);
|
||||
DefineIndex(LexIDStr($5),
|
||||
LexIDStr($3),
|
||||
LexIDStr($7),
|
||||
params, NIL, 0, NIL);
|
||||
DO_END;
|
||||
}
|
||||
;
|
||||
|
||||
BuildIndsStmt:
|
||||
XBUILD INDICES { build_indices(); }
|
||||
|
||||
index_params:
|
||||
index_on ident
|
||||
{
|
||||
IndexElem *n = (IndexElem*)$1;
|
||||
n->class = LexIDStr($2);
|
||||
$$ = n;
|
||||
}
|
||||
|
||||
index_on:
|
||||
ident
|
||||
{
|
||||
IndexElem *n = makeNode(IndexElem);
|
||||
n->name = LexIDStr($1);
|
||||
$$ = n;
|
||||
}
|
||||
| ident LPAREN arg_list RPAREN
|
||||
{
|
||||
IndexElem *n = makeNode(IndexElem);
|
||||
n->name = LexIDStr($1);
|
||||
n->args = (List*)$3;
|
||||
$$ = n;
|
||||
}
|
||||
|
||||
arg_list:
|
||||
ident
|
||||
{
|
||||
$$ = lappend(NIL, makeString(LexIDStr($1)));
|
||||
}
|
||||
| arg_list COMMA ident
|
||||
{
|
||||
$$ = lappend((List*)$1, makeString(LexIDStr($3)));
|
||||
}
|
||||
|
||||
optbootstrap:
|
||||
XBOOTSTRAP { $$ = 1; }
|
||||
| { $$ = 0; }
|
||||
;
|
||||
|
||||
typelist:
|
||||
typething
|
||||
| typelist COMMA typething
|
||||
;
|
||||
|
||||
typething:
|
||||
ident EQUALS ident
|
||||
{
|
||||
if(++numattr > MAXATTR)
|
||||
elog(FATAL,"Too many attributes\n");
|
||||
DefineAttr(LexIDStr($1),LexIDStr($3),numattr-1);
|
||||
if (DebugMode)
|
||||
printf("\n");
|
||||
}
|
||||
;
|
||||
|
||||
optoideq:
|
||||
OBJ_ID EQUALS ident { $$ = atol(LexIDStr($3)); }
|
||||
| { extern Oid newoid(); $$ = newoid(); }
|
||||
;
|
||||
|
||||
tuplelist:
|
||||
tuple
|
||||
| tuplelist tuple
|
||||
| tuplelist COMMA tuple
|
||||
;
|
||||
|
||||
tuple:
|
||||
ident {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
|
||||
| const {InsertOneValue(objectid, LexIDStr($1), num_tuples_read++); }
|
||||
| NULLVAL
|
||||
{ InsertOneNull(num_tuples_read++); }
|
||||
;
|
||||
|
||||
const :
|
||||
CONST { $$=yylval.ival; }
|
||||
;
|
||||
|
||||
ident :
|
||||
ID { $$=yylval.ival; }
|
||||
;
|
||||
%%
|
||||
|
||||
|
108
src/backend/bootstrap/bootscanner.l
Normal file
108
src/backend/bootstrap/bootscanner.l
Normal file
@@ -0,0 +1,108 @@
|
||||
%{
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* bootscanner.lex--
|
||||
* a lexical scanner for the bootstrap parser
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootscanner.l,v 1.1.1.1 1996/07/09 06:21:14 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include "bootstrap/bootstrap.h"
|
||||
#include "utils/portal.h"
|
||||
#include "access/xact.h"
|
||||
#include "parser/scansup.h"
|
||||
|
||||
#include "bootstrap_tokens.h"
|
||||
|
||||
/* some versions of lex define this as a macro */
|
||||
#if defined(yywrap)
|
||||
#undef yywrap
|
||||
#endif /* yywrap */
|
||||
|
||||
YYSTYPE yylval;
|
||||
int yyline; /* keep track of the line number for error reporting */
|
||||
|
||||
%}
|
||||
|
||||
D [0-9]
|
||||
oct \\{D}{D}{D}
|
||||
Exp [Ee][-+]?{D}+
|
||||
id ([A-Za-z0-9_]|{oct}|\-)+
|
||||
sid \"([^\"])*\"
|
||||
arrayid [A-Za-z0-9_]+\[{D}*\]
|
||||
|
||||
%%
|
||||
|
||||
open { return(OPEN); }
|
||||
|
||||
close { return(XCLOSE); }
|
||||
|
||||
create { return(XCREATE); }
|
||||
|
||||
OID { return(OBJ_ID); }
|
||||
bootstrap { return(XBOOTSTRAP); }
|
||||
_null_ { return(NULLVAL); }
|
||||
|
||||
insert { return(INSERT_TUPLE); }
|
||||
|
||||
"," { return(COMMA); }
|
||||
"=" { return(EQUALS); }
|
||||
"(" { return(LPAREN); }
|
||||
")" { return(RPAREN); }
|
||||
|
||||
[\n] { yyline++; }
|
||||
[\t] ;
|
||||
" " ;
|
||||
|
||||
^\#[^\n]* ; /* drop everything after "#" for comments */
|
||||
|
||||
|
||||
"declare" { return(XDECLARE); }
|
||||
"build" { return(XBUILD); }
|
||||
"indices" { return(INDICES); }
|
||||
"index" { return(INDEX); }
|
||||
"on" { return(ON); }
|
||||
"using" { return(USING); }
|
||||
{arrayid} {
|
||||
yylval.ival = EnterString(MapArrayTypeName((char*)yytext));
|
||||
return(ID);
|
||||
}
|
||||
{id} {
|
||||
yylval.ival = EnterString(scanstr((char*)yytext));
|
||||
return(ID);
|
||||
}
|
||||
{sid} {
|
||||
yylval.ival = EnterString(scanstr((char*)yytext));
|
||||
return(ID);
|
||||
}
|
||||
|
||||
(-)?{D}+"."{D}*({Exp})? |
|
||||
(-)?{D}*"."{D}+({Exp})? |
|
||||
(-)?{D}+{Exp} {
|
||||
yylval.ival = EnterString((char*)yytext);
|
||||
return(CONST);
|
||||
}
|
||||
|
||||
. {
|
||||
printf("syntax error %d : -> %s\n", yyline, yytext);
|
||||
}
|
||||
|
||||
|
||||
|
||||
%%
|
||||
|
||||
yywrap()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
yyerror(str)
|
||||
char *str;
|
||||
{
|
||||
fprintf(stderr,"\tsyntax error %d : %s",yyline, str);
|
||||
}
|
1049
src/backend/bootstrap/bootstrap.c
Normal file
1049
src/backend/bootstrap/bootstrap.c
Normal file
File diff suppressed because it is too large
Load Diff
78
src/backend/bootstrap/bootstrap.h
Normal file
78
src/backend/bootstrap/bootstrap.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* bootstrap.h--
|
||||
* include file for the bootstrapping code
|
||||
*
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: bootstrap.h,v 1.1.1.1 1996/07/09 06:21:14 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#ifndef BOOTSTRAP_H
|
||||
#define BOOTSTRAP_H
|
||||
|
||||
#include <sys/file.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "access/htup.h"
|
||||
#include "access/itup.h"
|
||||
#include "access/relscan.h"
|
||||
#include "access/skey.h"
|
||||
#include "utils/tqual.h"
|
||||
#include "storage/buf.h"
|
||||
#include "storage/bufmgr.h" /* for BufferManagerFlush */
|
||||
#include "utils/portal.h"
|
||||
#include "utils/elog.h"
|
||||
#include "utils/rel.h"
|
||||
|
||||
#define MAXATTR 40 /* max. number of attributes in a relation */
|
||||
|
||||
typedef struct hashnode {
|
||||
int strnum; /* Index into string table */
|
||||
struct hashnode *next;
|
||||
} hashnode;
|
||||
|
||||
#define EMITPROMPT printf("> ")
|
||||
|
||||
extern Relation reldesc;
|
||||
extern AttributeTupleForm attrtypes[MAXATTR];
|
||||
extern int numattr;
|
||||
extern int DebugMode;
|
||||
|
||||
extern int BootstrapMain(int ac, char *av[]);
|
||||
extern void index_register(char *heap,
|
||||
char *ind,
|
||||
int natts,
|
||||
AttrNumber *attnos,
|
||||
uint16 nparams,
|
||||
Datum *params,
|
||||
FuncIndexInfo *finfo,
|
||||
PredInfo *predInfo);
|
||||
|
||||
extern void err(void);
|
||||
extern void InsertOneTuple(Oid objectid);
|
||||
extern void closerel(char *name);
|
||||
extern void boot_openrel(char *name);
|
||||
extern char *LexIDStr(int ident_num);
|
||||
|
||||
extern void DefineAttr(char *name, char *type, int attnum);
|
||||
extern void InsertOneValue(Oid objectid, char *value, int i);
|
||||
extern void InsertOneNull(int i);
|
||||
extern bool BootstrapAlreadySeen(Oid id);
|
||||
extern void cleanup(void);
|
||||
extern int gettype(char *type);
|
||||
extern AttributeTupleForm AllocateAttribute(void);
|
||||
extern char* MapArrayTypeName(char *s);
|
||||
extern char* CleanUpStr(char *s);
|
||||
extern int EnterString (char *str);
|
||||
extern int CompHash (char *str, int len);
|
||||
extern hashnode *FindStr (char *str, int length, hashnode *mderef);
|
||||
extern hashnode *AddStr(char *str, int strlength, int mderef);
|
||||
extern void build_indices(void);
|
||||
|
||||
#endif /* BOOTSTRAP_H */
|
Reference in New Issue
Block a user