This commit is contained in:
Oliver Lehmann 1990-01-03 10:51:19 +00:00
parent e36a55301a
commit 62f1f47075
4 changed files with 648 additions and 0 deletions

View File

@ -0,0 +1,157 @@
# include <stdio.h>
# ifdef MSDOS
# include "../h/gen.h"
# include <fcntl.h>
# define AA_atoi v6_atoi
# else
# include "../conf/gen.h"
# endif
# define LINES 32
# define CNTR 1000
static char cntr[CNTR];
main(argc, argv)
int argc;
char **argv;
{
register char *p;
register int i;
register int cnt;
amxfile(argv[1]);
if (argc == 2)
return (0);
cnt = 0;
p = cntr;
for (i = CNTR; i; --i)
{
if (*p)
{
cnt = i;
*p++ = '*';
}
else
*p++ = ' ';
}
cnt = CNTR - cnt;
cnt = ((cnt + 9) / 10) * 10;
p = cntr;
for (i = 0; i < cnt; i += 10, p += 10)
{
if (!(i % 100))
{
printf("------------------\n");
printf(" | 0123456789 |\n");
printf("------------------\n");
}
printf("%3d | %.10s |\n", i / 10, p);
}
return (0);
}
amxfile(output)
char *output;
{
register char *p;
register int c;
register int i;
register int f;
int iff;
short ix;
long off;
char buf[2 * LINES];
# ifdef SETBUF
char inbuf[BUFSIZ];
# endif
extern long lseek();
# ifdef SETBUF
setbuf(stdin, inbuf);
# endif
if ((f = creat(output, 0644)) < 0)
{
printf("cannot open output '%s'\n", output);
exit(1);
}
# ifdef MSDOS
setmode(f, O_BINARY);
# endif
/* read in the code and check for correct */
for ( ; ; )
{
p = buf;
while ((c = getchar()) != '\t')
{
if (c <= 0)
return;
*p++ = c;
}
*p = 0;
if (AA_atoi(buf, &ix))
{
printf("bad msg file '%s'\n", buf);
return;
}
iff = ix;
off = LINES * iff;
lseek(f, off, 0);
for (p = buf; p < &buf[2 * LINES]; p++)
*p = 0;
p = buf;
i = 0;
/* get the correct line */
for ( ; ; )
{
c = getchar();
i++;
if (c <= 0 || c == ERRDELIM)
{
if (iff > CNTR)
{
printf("msg no to '%d' too big\n", iff);
return;
}
if (cntr[iff]++)
{
printf("dup msg %d\n", iff);
return;
}
if (i > 2 * LINES)
{
printf("too long msg '%s'\n", buf);
return;
}
if (i > LINES)
{
iff++;
if (cntr[iff]++)
{
printf("dup msg %d\n", iff);
return;
}
i = 2 * LINES;
}
else
i = LINES;
write(f, buf, i);
if (c <= 0)
return;
if ((c = getchar()) != '\n')
{
printf("format error\n");
return;
}
break;
}
*p++ = c;
}
}
}

View File

@ -0,0 +1,240 @@
# include "amx.h"
# ifdef MSDOS
# include <fcntl.h>
# endif
# define OUT_FLAG "-o"
extern char *AMX;
extern char AMXF;
extern char *A_out;
extern int Argc;
extern char **Argv;
extern int Xargc;
extern char **Xargv;
extern int Xerrors;
# ifndef MSDOS
/*
** GETPATH -- initialize the AApath variable
**
** Sets AApath to the home directory of the USERDBS
** [bs.h] user.
*/
getpath()
{
char line[MAXLINE + 1];
static char path[41];
static int reenter;
register int i;
register char *lp;
register FILE *iop;
char *field[UF_NFIELDS];
if (reenter)
return;
else
reenter++;
if (!(iop = fopen(AA_PASSWD, "r")))
{
printf("Passwordfile %s nicht lesbar\n", AA_PASSWD);
exit(1);
}
AApath = path;
do
{
/* get a line from the AA_PASSWD */
i = 0;
for (lp = line; (*lp = getc(iop)) != '\n'; lp++)
{
if (*lp == (char) -1)
{
printf("Nutzer %s im Passwordfile %s nicht verzeichnet\n", USERDBS, AA_PASSWD);
exit(1);
}
if (++i > sizeof line - 1)
{
*lp = '\0';
printf("Zeilenpufferueberlauf bei \"%s\"\n", line);
exit(1);
}
}
*lp = '\0';
for (i = 0, lp = line; *lp; lp++)
{
if (*lp == ':')
{
*lp = '\0';
field[++i] = lp + 1;
}
}
} while (!AAsequal(line, USERDBS));
fclose(iop);
/* check for enough fields for valid entry */
if (i < PF_HOME)
{
printf("Zu wenig Felder in dem Eintrag \"%s\"\n", line);
exit(1);
}
/* check that pathname won't overflow static buffer */
if ((i = AAlength(field[PF_HOME]) + 1) > sizeof path)
{
printf("DBS-Pfadname \"%s\" ist zu lang\n", field[PF_HOME]);
exit(1);
}
/* move pathname into buffer */
AAbmove(field[PF_HOME], AApath, i);
}
# endif
get_next_file()
{
register char *file;
register int extension;
register int i;
extern int end_amx();
extern char *AAcustomer();
extern char **talloc();
while (file = Argv[++Argc])
{
if (AAsequal(file, OUT_FLAG))
{
A_out = Argv[++Argc];
continue;
}
i = AAlength(file);
extension = --i;
if (--i < 0 || (!(AAsequal(file + i, ".x"))
# ifdef MSDOS
&& !AAsequal(file + i, ".X")
# endif
))
continue;
# ifdef MSDOS
printf("%s:\n", file);
# else
printf("%s -- %s/%c %s:\n",
AAcustomer(end_amx), AMX, AMXF, file);
# endif
if (!(FILE_inp = fopen(file, "r")))
{
amxerror(188, file);
continue;
}
# ifdef SETBUF
setbuf(FILE_inp, BUF_inp);
# endif
/* save source file name */
File_src = (char *) talloc(extension + 2);
AAbmove(file, File_src, extension + 2);
/* create amx file */
file[extension] = 'c';
if (!(FILE_amx = fopen(file, "w")))
yyexit(185, file);
# ifdef SETBUF
setbuf(FILE_amx, BUF_amx);
# endif
Xargv[Xargc++] = file;
/* create desc stream */
*Filespec = 'r';
close(creat(Filename, 0600));
if ((FILE_rel = open(Filename, 2)) < 0)
yyexit(1);
/* create tmp stream */
*Filespec = 'c';
if (!(FILE_tmp = fopen(Filename, "w")))
yyexit(1);
# ifdef SETBUF
setbuf(FILE_tmp, BUF_tmp);
# endif
return (1);
}
return (0);
}
end_file()
{
extern int AAcc_init;
/* close files and unlink temps */
if (FILE_inp)
{
fclose(FILE_inp);
FILE_inp = (FILE *) 0;
}
if (FILE_amx)
{
fclose(FILE_amx);
FILE_amx = (FILE *) 0;
}
if (FILE_tmp)
{
fclose(FILE_tmp);
FILE_tmp = (FILE *) 0;
}
if (FILE_scn)
{
fclose(FILE_scn);
FILE_scn = (FILE *) 0;
}
if (FILE_rel)
{
close(FILE_rel);
FILE_rel = -1;
}
*Filespec = 'r';
unlink(Filename);
*Filespec = 'c';
unlink(Filename);
*Filespec = 's';
unlink(Filename);
if (AAcc_init)
{
AAinpclose(&Indes);
AAunlall();
AAam_exit();
}
# ifdef MSDOS
fcloseall();
# endif
}
end_amx(stat)
register int stat;
{
# ifndef MSDOS
register char **argv;
register char *file;
argv = Xargv;
argv[Xargc] = (char *) 0;
while (file = *argv++)
unlink(file);
close(FILE_msg);
fflush(stdout);
# else
fcloseall();
# endif
exit(stat? stat: Xerrors);
}
AAndxsearch(d)
register DESC *d;
{
yyexit(207, d->reldum.relid);
}

View File

@ -0,0 +1,147 @@
# include "amx.h"
tmp(db, uflag)
register char *db;
char *uflag;
{
register char *p;
register int argc;
register char *id;
char *argv[4];
char arg[MAXNAME + 3];
char buf[MAXLINE + 1];
static char db_buf[MAXNAME + 1];
/* setup argvector for initucode */
AAbmove(db, db_buf, MAXNAME + 1);
*argv = db = db_buf;
argc = 1;
if (uflag)
{
argv[argc++] = p = arg;
*p++ = '-';
AAbmove(uflag, p, MAXNAME + 2);
}
argv[argc++] = db;
argv[argc] = (char *) 0;
switch (initucode(argc, argv, TRUE, (char *) 0, M_SHARE))
{
case 0: /* everything is ok */
case 5: /* ok, but there was an indirect token */
break;
case 1: /* the database does not exist */
case 6: /* dto., but there was an indirect token */
yyexit(9, db);
case 2: /* you are not authorisized to access this database */
yyexit(7, db);
case 3: /* you are not a valid DBS user */
yyexit(5, USERDBS);
case 4: /* no database name specified */
/* cannot happen */
break;
}
/* open data base */
# ifdef MSDOS
AAdatabase = Parmvect[0];
# endif
AAam_start();
if (AAdmin.adhdr.adflags & A_DBCONCUR)
setbit(A_DBCONCUR, Xlocks);
else
No_locks++;
if (AArelopen(&Indes, 0, AA_INDEX))
yyexit(8, AA_INDEX);
/* make believe catalog AA_REL is read only for concurrency */
/* that means, readed pages are not locked */
AAdmin.adreld.relopn = RELROPEN(AAdmin.adreld.relfp);
/* setup file name for scan temps */
*Filespec = 's';
/* write include files */
fprintf(FILE_amx, msg(49), AApath);
# ifdef AMX_SC
if (ExpImp < 0)
goto lookup;
# endif
/* write variables */
for (argc = 126; argc < 130; argc++)
fprintf(FILE_amx, msg(argc));
fprintf(FILE_amx, msg(30), AAusercode);
fprintf(FILE_amx, msg(31), AApath);
# ifdef MSDOS
fprintf(FILE_amx, msg(32));
for (argc = DBP_STD; argc < DBP_MAX; argc++)
fprintf(FILE_amx, msg(206), AAdbpath[argc]);
fprintf(FILE_amx, msg(201));
fprintf(FILE_amx, msg(204), AAdatabase);
if (Xbufs)
fprintf(FILE_amx, msg(35), (Xbufs * sizeof (ACCBUF)) / sizeof (int));
# else
fprintf(FILE_amx, msg(32), AAdbpath);
/* get user and group id of (alter ego) user */
getuser(AAusercode, p = buf);
getuser((char *) 0);
for (argc = -2; argc < 2; argc++)
{
id = p;
while (*p != ':')
p++;
*p++ = 0;
if (argc >= 0)
fprintf(FILE_amx, msg(28 + argc), id);
}
# endif
# ifdef AMX_SC
lookup:
# endif
/* lookup catalogs */
rel_lookup(AA_REL, AMX_INTERNAL); /* = AA_0 */
rel_lookup(AA_ATT, AMX_INTERNAL); /* = AA_1 */
rel_lookup(AA_INDEX, AMX_INTERNAL); /* = AA_2 */
}
# ifndef MSDOS
char *AArelpath(rel)
register char *rel;
{
extern char *AAztack();
return (AAztack(AAztack(AAdbpath, "/"), rel));
}
# endif
# ifdef AMX_SC
import(file)
register char *file;
{
register FILE *inp;
ExpImp = -1;
if (!(inp = fopen(file, "r")))
yyexit(188, file);
# ifdef SETBUF
setbuf(inp, (char *) 0);
# endif
FILE_exp = FILE_inp;
FILE_inp = inp;
Line_exp = Line;
Line = 1;
backup('\n');
}
# endif

View File

@ -0,0 +1,104 @@
# include <stdio.h>
# include "gen.h"
# include "constants.h"
# include "globals.h"
/*
** NAME -- Process an identifier or keyword token.
**
** Name gets the identifier that follows in the std.
** input, and checks if it is a keyword.
** An identifier is defined as a sequence of
** MAXNAME or fewer alphanumerics, starting with an
** alphabetic character.
**
** Parameters:
** chr - the first character of the identifier
**
** Returns:
** Tokens.sp_name - for a user-defined name
** Tokens.sp_struct_var -- if the name is declared
** a structurw variable
** other - lexical codes for keys
**
** Side Effects:
** Adds a token to the symbol space.
** yylval is set to the new node in the space.
** If the identifier is a keyword, sets Opcode to
** op_code from tokens.y.
**
*/
name(chr)
int chr;
{
register int i;
register char *cp;
register char c;
register struct optab *op;
register int lval;
char wbuf[MAXNAME + 1];
extern char *yylval;
extern char *addsym();
extern char *salloc();
extern struct optab *getkey();
extern char *getcvar();
c = chr;
cp = wbuf;
for (i = 0; i <= MAXNAME; i++)
{
lval = CMAP(c);
if (i < MAXNAME &&
(lval == ALPHA || lval == NUMBR))
{
*cp++ = c;
c = getch();
}
else if (lval == ALPHA || lval == NUMBR)
{
/* {i == MAXNAME && "c is legal" &&
* cp == &wbuf[MAXNAME]}
*/
*cp = '\0';
yysemerr("name too long", wbuf);
/* chomp to end of identifier */
do
{
c = getch();
lval = CMAP(c);
} while (lval == ALPHA || lval == NUMBR);
backup(c);
/* take first MAXNAME characters as IDENTIFIER
* (non-key)
*/
yylval = addsym(salloc(wbuf));
return (Tokens.sp_name);
}
else
{
/* {cp <= &wbuf[MAXNAME] && i <= MAXNAME
* && "c is not part of id"}
*/
backup(c);
*cp = '\0';
i = 0;
break;
}
}
op = getkey(wbuf);
/* Is it a keyword ? */
if (op)
{
yylval = addsym(op->op_term);
Opcode = op->op_code;
return (op->op_token);
}
/* user-defined name */
yylval = addsym(salloc(wbuf));
if ((cp = getcvar(wbuf)) && ((struct cvar *) cp)->c_type == opSTRUCT)
return (Tokens.sp_struct_var);
return (Tokens.sp_name);
}