home *** CD-ROM | disk | FTP | other *** search
- /*
- * This code is copyright ADE Muffett, September 1991, and is distributed as
- * part of the ASP .plan description language compiler. This code is freely
- * redistributable as long as this copyright notice remains intact. No
- * responsibility is assumed by the author for any situation which arises
- * from the use of this code, including insanity, late nights, or disk
- * storage problems.
- */
-
- /* Unix is a Bellmark of Lab Tradeoratories */
-
- #include "asp.h"
- #undef TESTING
-
- /* GLOBAL DATA */
- int speed;
- int smooth;
- char stdline[SCREENWIDTH + 1];
- char anim_buffer[SCREENWIDTH + 1];
- char foreground[SCREENWIDTH + 1];
- char background[SCREENWIDTH + 1];
- struct anim_object aobjects[MAX_ANIM_OBJS];
- /* END OF GLOBAL DATA */
-
- struct command_structure
- {
- char *codeword;
- void (*fn) ();
- char has_args;
- };
-
- struct command_call
- {
- int c_index;
- char *invocation;
- };
-
- static FILE *fp;
- static char version[] = "asp3.2(c)aem@aber";
- static struct command_call command_calls[COMMAND_COUNT];
- static struct command_structure command_name[COMMAND_COUNT];
-
- void
- Smooth (command)
- char *command;
- {
- sscanf (command, "%*s %d", &smooth);
- }
-
- void
- Speed (command)
- char *command;
- {
- sscanf (command, "%*s %d", &speed);
- }
-
- void
- Flush ()
- {
- command_calls[0].c_index = 0;
- }
-
- char *
- BuildArgs (commstring, name_index)
- char *commstring;
- int name_index;
- {
- char cbuf[255];
-
- if (!strcmp (command_name[name_index].codeword, ".object") ||
- !strcmp (command_name[name_index].codeword, ".speed") ||
- !strcmp (command_name[name_index].codeword, ".smooth"))
- {
- return (CopyString (commstring));
- }
- if (!strcmp (command_name[name_index].codeword, ".foreground"))
- {
- fgets (cbuf, 255, fp);
- NullSet (foreground, sizeof (foreground));
- strncpy (foreground, cbuf, SCREENWIDTH);
- return ((char *) NULL);
- }
- if (!strcmp (command_name[name_index].codeword, ".background"))
- {
- fgets (cbuf, 255, fp);
- NullSet (background, sizeof (background));
- strncpy (background, cbuf, SCREENWIDTH);
- return ((char *) NULL);
- }
- fprintf (stderr, "%s: NYI\n", commstring);
- return ((char *) 0);
- }
-
- void
- NewFunction (cw, fn, args)
- char *cw;
- void (*fn) ();
- char args;
- {
- static int command_count = 1; /* load commands from 1st element */
-
- command_name[command_count].codeword = cw;
- command_name[command_count].fn = fn;
- command_name[command_count].has_args = args;
- command_count++;
- command_name[command_count].codeword = NULL;
- }
-
- void
- ParseCommands (cstring)
- register char *cstring;
- {
- int i;
- int comm_number;
- char *ptr;
- int get_next_line;
- char otherbuffer[255];
- static char dot = '.';
-
- comm_number = 0;
- command_calls[comm_number].c_index = 0;
-
- start_parsing:
- i = strlen (cstring) - 1;
- if (cstring[i] == '\\')
- {
- get_next_line = 1;
- cstring[i] = '\0';
- } else
- {
- get_next_line = 0;
- }
-
- for (ptr = (char *) strchr (cstring, dot);
- ptr;
- ptr = (char *) strchr (ptr, dot))
- {
- if (!*ptr) /* no more commands */
- {
- break;
- }
- for (i = 1; command_name[i].codeword; i++)
- {
- if (!strncmp (ptr, command_name[i].codeword,
- strlen (command_name[i].codeword)))
- {
- command_calls[comm_number].c_index = i;
-
- if (command_name[i].has_args != 'Y')
- {
- command_calls[comm_number].invocation = (char *) 0;
- comm_number++;
- break;
- } else
- {
- command_calls[comm_number].invocation = BuildArgs (ptr, i);
- comm_number++;
- break;
- }
- }
- }
-
- if (!command_name[i].codeword)
- {
- fprintf (stderr, "Error: unknown command '%s'\n", ptr);
- }
- ptr++; /* make this neater */
- }
- if (get_next_line)
- {
- fgets (otherbuffer, 255, fp);
- Trim (otherbuffer);
- cstring = otherbuffer;
- goto start_parsing;
- }
- command_calls[comm_number++].c_index = 0;
- }
-
- void
- ExecuteCommandsOn (dstring)
- register char *dstring;
- {
- register int i;
- register int j;
-
- for (i = 0; command_calls[i].c_index; i++)
- {
- j = command_calls[i].c_index;
- #ifdef TESTING
- printf ("executing '%s' as '%s' on \n'%s'\n", command_name[j].codeword,
- command_calls[i].invocation, dstring);
- #else
- (*command_name[j].fn) (command_calls[i].invocation, dstring);
- #endif
- }
- }
-
- int
- main (argc, argv)
- int argc;
- char *argv[];
- {
- char command_buffer[255];
- char line_buffer[255];
- register char *ptr;
- register int i;
- static char dot = '.';
-
- srand (time (0));
-
- NewFunction (".wspatter", WordSpatter, 'N');
- NewFunction (".wipe", Wipe, 'N');
- NewFunction (".tshow", TShow, 'N');
- NewFunction (".speed", Speed, 'Y');
- NewFunction (".spatter", Spatter, 'N');
- NewFunction (".smooth", Smooth, 'Y');
- NewFunction (".show", Show, 'N');
- NewFunction (".scrollof", ScrollOffForward, 'N');
- NewFunction (".scrollob", ScrollOffBackward, 'N');
- NewFunction (".scrollf", ScrollForward, 'N');
- NewFunction (".scrollb", ScrollBackward, 'N');
- NewFunction (".reset", ResetAnim, 'N');
- NewFunction (".p", Pause, 'N');
- NewFunction (".object", AddObject, 'Y');
- NewFunction (".noop", Noop, 'N');
- NewFunction (".nl", LineFeed, 'N');
- NewFunction (".macro", NULL, 'N');
- NewFunction (".letter3", Letter3, 'N');
- NewFunction (".letter2", Letter2, 'N');
- NewFunction (".letter1", Letter1, 'N');
- NewFunction (".laymte", LayMiddleToEnds, 'N');
- NewFunction (".layf", LayForward, 'N');
- NewFunction (".layetm", LayEndsToMiddle, 'N');
- NewFunction (".layb", LayBackward, 'N');
- NewFunction (".foreground", Noop, 'Y');
- NewFunction (".flush", Flush, 'N');
- NewFunction (".flash", Flash, 'N');
- NewFunction (".fade", Fade, 'N');
- NewFunction (".clear", Clear, 'N');
- NewFunction (".background", Noop, 'Y');
- NewFunction (".anim", Animate, 'N');
-
- if (isatty (fileno (stdin)))
- {
- if (argc == 1)
- {
- fprintf (stderr, "Usage:\t%s <filename>\n", argv[0]);
- exit (1);
- }
- fp = fopen (argv[1], "r");
- if (!fp)
- {
- perror (argv[1]);
- exit (1);
- }
- } else
- {
- fp = stdin;
- }
-
- for (*line_buffer = '\0'; !feof (fp); *line_buffer = '\0')
- {
- fgets (line_buffer, 255, fp);
-
- if (!*line_buffer || *line_buffer == '\n') /* allow blank lines */
- {
- if (!command_calls[0].c_index)
- {
- putchar ('\n');
- }
- continue;
- }
- Trim (line_buffer); /* trim w/s */
-
- if (*line_buffer == dot)
- {
- ParseCommands (line_buffer);
- continue;
- }
- if (!command_calls[0].c_index) /* don't faff around... */
- {
- printf ("%s\n", line_buffer);
- continue;
- }
- ExecuteCommandsOn (line_buffer);
- }
- fclose (fp);
-
- printf ("\n\r%s\r", version);
- i = strlen (version);
- while (i--)
- {
- putchar (' ');
- }
- putchar ('\r');
-
- return (0);
- }
-