* Copyright -C- 1982 Barry S. Roitblat
* This is the main routine for the gremlin picture editor.
/* imports from config.c */
extern ELT
*DBInit(), *DBRead();
extern POINT
*PTInit(), *PTMakePoint();
/* imports from menu.c */
extern MNInterpretCursor();
extern MNIcon(), MNInitMenu(), MNDisplayMenu();
extern GRInit(), GRClose();
extern GRSetGrid(), GRDisplayGrid(), GRBlankGrid();
extern GRDisableTablet(), GREnableTablet();
extern GRSetMap(), GRsetwmask();
/* imports from undodb.c */
extern UNELT
*unlist
, *unback
;
/* imports from long.c */
extern CP(), LGCommand();
/* imports from short.c */
/* Forward references within this file: */
extern OnStop(), OnCommand();
/* Imports from textio.c: */
extern TxInit(), TxRedisplay(), TxClose(), TxPutMsg(), TxMsgOK();
extern TxLine(), TxPutString();
extern TXFIELD TAlign
, TAdjust
, TBrush
, TFont
, TGravity
, TCSize
;
extern TXFIELD TEdit
, TJustmode
;
extern char *malloc(), *sprintf(), *strcat(), *strcpy();
static int lintrup
= LINTRUP
; /* Constant for local mode bit */
/* Declaration of Globals */
ELT
*PICTURE
, *cset
, arhead
;
int CBRUSH
, CFONT
, CSIZE
, CJUST
, Gridsize
, Gridon
, Orientation
;
int Alignment
, SEQ
, Adjustment
, GravityOn
, Consume
, CHANGED
;
float PX
, PY
, Lastx
, Lasty
;
POINT
*POINTLIST
, *BACKPOINT
, MENPOINT
[NUSER
];
char *textpos
[] = {"bl", "bc", "br", "cl", "cc", "cr", "tl", "tc", "tr",
"lb", "cb", "rb", "lc", "rc", "lt", "ct", "rt" };
char *dispmode
[] = {"BL", "BR", "CC", "XX", "XX", "XX", "XX", "XX",
"XX", "XX", "TL", "TC", "TR", "CL", "CR", "BC" };
int textmode
[] = { 0, 15, 1, 13, 2, 14, 10, 11, 12,
0, 15, 1, 13, 14, 10, 11, 12 };
/* symbolic types, brushes, etc. */
char *lines
[] = { "broken", "dashed", "dotted",
"medium", "narrow", "thick", NULL
};
int lnum
[] = { 2, 4, 1, 6, 5, 3 };
char types
[] = { 'l', 'r', 'c', 'v', 'a', 'u', '\0' };
char *fonts
[] = { "Bold", "Italics", "Roman", "Special",
"bold", "italics", "roman", "special", NULL
};
int fnum
[] = { 3, 2, 1, 4, 3, 2, 1, 4 };
* This routine prints an error message and sets the Consume flag
* so that points are not cleared.
FILE *fp
, *POpen(), *fopen(),*grtty
, *tablet
, *map
, *startup
;
int x1
, y1
, x2
, y2
, i
, j
;
char colours
[768], msg
[50], sw
, *arg
, *file
;
char *ptr
, *display
, *type
, *getenv(), home
[100];
if (display
== NULL
) display
= "/dev/null";
/* Parse the command line. */
argc
-= 1; argv
++; /* Skip program name. */
if (arg
[0] != '-') file
= arg
;
if (argc
-- > 0) arg
= *argv
++;
if (argc
< 0) error("usage: gremlin -g <display name>");
if (*display
!= '/') display
= strcat("/dev/", arg
);
if (argc
-- > 0) arg
= *argv
++;
if (argc
< 0) error("usage: gremlin -g <path>");
(void) sprintf(msg
, "unknown switch: %c", sw
);
map
= fopen(GMapFile
, "r");
for (i
=0; i
<768; ++i
) /* read in color map */
(void) fscanf(map
,"%o",&j
);
/* Open the display, and call all of the initialization routines.
* Initialize all of the globals defined in this file.
/* Ignore quit signals, catch interrupts and stops. */
sigset(SIGTINT
, OnCommand
);
grtty
= fopen(display
,"w");
error("couldn't open display");
tablet
= fopen(display
,"r");
if (tablet
== NULL
) tablet
= fopen("/dev/null", "r");
(void) ioctl(fileno(stdin
), TIOCLBIS
, (char *) &lintrup
);
TxRedisplay(); /* display text screen */
unlist
= unback
= nullun
;
p1
= PTInit(); /* initialize arrowhead template */
(void) PTMakePoint(0.0, 0.0, &p1
);
(void) PTMakePoint(-5.0, 3.0, &p1
);
(void) PTMakePoint(-3.0, 0.0, &p1
);
(void) PTMakePoint(-5.0, -3.0, &p1
);
(void) PTMakePoint(0.0, 0.0, &p1
);
arhead
.brushf
= 0; /* brush filled in when used */
arhead
.textpt
= malloc(1);
PICTURE
= DBInit(); /* initialize picture databse */
cset
= DBInit(); /* and current set */
for (i
=0; i
<4; ++i
) /* and user symbols */
(void) strcpy(Editfile
, file
);
fp
= POpen(Editfile
, (char **) NULL
, SEARCH
);
if (fp
== NULL
) error("(creating new file)");
else PICTURE
= DBRead(Editfile
,&Orientation
, &pos
);
unlist
= unback
= nullun
;
TxPutString(&TEdit
, Editfile
);
TxPutMsg(" Gremlin - Version 2.3 (1982)");
MNInitMenu(Orientation
); /* Initialize Menu */
SHUpdate(); /* Display menu and picture, if any */
if (Orientation
== 0) /* initialize grid */
GRSetGrid(x1
, y1
, x2
, y2
, Gridsize
);
/* look in home directory */
sprintf(home
,"%s/.gremlinrc",getenv("HOME"));
startup
= fopen(home
, "r");
ptr
= fgets(cmdbuf
, 400, startup
);
for (i
=0; (cmdbuf
[i
] != '\n'); ++i
)
cmdbuf
[i
] = '\0'; /* remove trailing carriage return */
if (cmdbuf
[0] == ':') LGCommand(&(cmdbuf
[1]));
else SHCommand(&(cmdbuf
[0]));
ptr
= fgets(cmdbuf
, 400, startup
);
/* look in current directory */
startup
= fopen(".gremlinrc", "r");
if (buf
.st_ino
!= inode
) /* This isn't the same file as above */
ptr
= fgets(cmdbuf
, 400, startup
);
for (i
=0; (cmdbuf
[i
] != '\n'); ++i
)
cmdbuf
[i
] = '\0'; /* remove trailing carriage return */
if (cmdbuf
[0] == ':') LGCommand(&(cmdbuf
[1]));
else SHCommand(&(cmdbuf
[0]));
ptr
= fgets(cmdbuf
, 400, startup
);
while ( TRUE
) /* Exits through the 'quit' command */
/* Allow keyboard interrupts while waiting
button
= GRGetButton(tablet
, &cux
, &cuy
);
/* Ignore keyboard interrupts while processing commands.
MNInterpretCursor(button
, cux
, cuy
);
i
|= (1 << fileno(tablet
));
(void) select(20, &i
, 0, 10000000);
if (i
& (1 << fileno(stdin
)))
if ((button
= GRGetButton(tablet
, &cux
, &cuy
)) != -4)
MNInterpretCursor(button
, cux
, cuy
);
/*-----------------------------------------------------------------------------
* This procedure handles stop signals.
* The text display is reset, we wait to get restarted, then
*-----------------------------------------------------------------------------
/*-----------------------------------------------------------------------------
* This routine responds to interrupts from the command terminal and
* then processes commands as long as there is input.
* Whatever is done by the commands.
*-----------------------------------------------------------------------------
static char cmd
, lastcmd
;
(void) ioctl(fileno(stdin
), TIOCLBIC
, (char *) &lintrup
);
/* If there is no more input, then reenable the signal and return */
(void) ioctl(fileno(stdin
), FIONREAD
, (char *) &charcount
);
(void) ioctl(fileno(stdin
), TIOCLBIS
, (char *) &lintrup
);
if (select(20, &i
, 0, 0) <= 0)
/* Read the command and call the long or short command routine */
if (!repeat
) TxGetLine(":",cmdbuf
,400);
if (cmd
!= '\') putchar(cmd);