Skip to content

Commit

Permalink
Updated to build and limp along somewhat on Unix.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Apr 22, 2006
1 parent 8baf7e6 commit f388e64
Show file tree
Hide file tree
Showing 8 changed files with 643 additions and 23 deletions.
17 changes: 13 additions & 4 deletions README
@@ -1,18 +1,27 @@
This is the original version of Toby. It was written for a senior high-school
exit project over the first couple months of 1995.

I wrote in C, with very little understanding of the language; I was a
I wrote this in C, with very little understanding of the language; I was a
QuickBASIC 4.5 fan at the time. This is a CRAPPY bit of code.

This is a DOS program, which was built with Microsoft C 7.0 for DOS. I don't
even know if it compiles under that environment anymore, but apparently there's
a binary here, too, which also may or may not work.
This is a DOS program, which was built with Microsoft C 7.0 for DOS. I have
spent some effort reimplementing the Microsoft graphics library with SDL so
you can build this on modern systems, but the work isn't nearly complete, and
I didn't want to alter the original code too much, so you still get all the
fun memory corruptions and crashes. Subversion revision #3 is the unmolested
source as I found it several years ago...I think I probably patched it a
little after the end of the project, probably in a failed attempt to make it
a native, 16-bit OS/2 app, but I can't remember. Anything after revision #3
are just simple tweaks, more than a decade later, probably to reduce my shame.

The language syntax is almost entirely LOGO, as the goal was to produce a free
implementation of LOGO, even before I understood the GNU definition of "free",
or that there were GPL'd LOGO packages available. At least this was a DOS one,
since nobody I knew could have used a Unix-based version at the time. :)

I hadn't conceived of designing my own programming language at this point. I
probably thought I wasn't allowed...not by the high school, just generally.

Also, as far LOGOs go, this was just a tiny subset of the language.

History is always ugly.
Expand Down
4 changes: 4 additions & 0 deletions maketoby.sh
@@ -0,0 +1,4 @@
#!/bin/sh

gcc -Wall -O0 -g -o toby -lm toby.c tobygrfx.c tobydata.c unixbits.c `sdl-config --cflags --libs`

21 changes: 13 additions & 8 deletions toby.c
Expand Up @@ -22,14 +22,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <graph.h>
#include <string.h>
#include <memory.h>
#include <conio.h>
#include <malloc.h>
#include <time.h>
#include "toby.h"

#ifdef __GNUC__
#include "unixbits.h"
#else
#include <graph.h>
#include <conio.h>
#include <memory.h>
#include <malloc.h>
#endif

/* Global Variables... */
linkedlist *procedures = NULL; /* user-defined LOGO procedures. */
Expand All @@ -38,19 +42,20 @@ errortype runtime = RT_NOERROR; /* Runtime status. */
boolean shouldsave = FALSE; /* Should we prompt to save procedures? */

/* move these? */
char graphic_flags; /* Bitmap of graphic-related flags. */
char graphic_flags = 0; /* Bitmap of graphic-related flags. */
short turtle_x, turtle_y; /* The Turtle's X and Y coordinates. */
short pen_color; /* Current pen color. */
short turtle_heading = 0; /* the Turtle's heading : 0-360 deg. */

void main(int argc, char *argv[])
int main(int argc, char *argv[])
/*
* Short, but sweet; it's the mainline.
*/
{
logoinit(argv[1]);
logostart();
logofinish(NULL, ERLV_GOOD);
return(0);
} /*main*/


Expand Down Expand Up @@ -91,7 +96,7 @@ void logostart(void)

runtime = RT_NOERROR; /* reset runtime error variable. */

getline(NULL, instruction, "? ", MAXCOMMAND);
_getline(NULL, instruction, "? ", MAXCOMMAND);

if (strnicmp(instruction, "to ", 3) == 0)
define_proc(NULL, instruction + 3);
Expand Down Expand Up @@ -575,7 +580,7 @@ char *primitives(char *instructions, linkedlist **scalars)
{
returns = parse_args(parameters, *scalars, 2);
looper!!!
} /*else if (QUOTIENT)*/
} */ /*else if (QUOTIENT)*/

else if (strcmp(instructions, "REMAINDER") == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion toby.h
Expand Up @@ -96,7 +96,7 @@ char *rtrim(char *str);
boolean twostrcmp(char *cmpthis, char *checkone, char *checktwo);
void preprocess(char *unprocessed);
char charinput(FILE *charstream);
char *getline(FILE *fromhere, char *tohere, char *prompt, int maxline);
char *_getline(FILE *fromhere, char *tohere, char *prompt, int maxline);
boolean getyn(char *prompt);
boolean define_proc(FILE *fromhere, char *declaration);
void codeload(char *filename);
Expand Down
24 changes: 16 additions & 8 deletions tobydata.c
Expand Up @@ -7,10 +7,17 @@

#include <stdio.h>
#include <string.h>
#include "toby.h"

#ifdef __GNUC__
#include "unixbits.h"
#else
#include <graph.h>
#include <memory.h>
#include <malloc.h>
#include "toby.h"
/* (this is probably a leftover from EMX...) */
#define access(x,y) (-1)
#endif

extern boolean shouldsave;
extern linkedlist *procedures;
Expand Down Expand Up @@ -255,6 +262,7 @@ char *rtrim(char *str)
char *trimpoint;
for (trimpoint = str + strlen(str) - 1; *trimpoint == ' '; trimpoint--);
trimpoint[1] = '\0';
return(str);
} /*rtrim*/


Expand Down Expand Up @@ -330,7 +338,7 @@ char charinput(FILE *charstream)



char *getline(FILE *fromhere, char *tohere, char *prompt, int maxline)
char *_getline(FILE *fromhere, char *tohere, char *prompt, int maxline)
/*
* Reads a line of input, ending with an endline char. Allows input from a
* a file or keyboard, a maximum input size, and string editing.
Expand Down Expand Up @@ -442,7 +450,7 @@ char *getline(FILE *fromhere, char *tohere, char *prompt, int maxline)

return(tohere);

} /*getline*/
} /*_getline*/


boolean getyn(char *prompt)
Expand Down Expand Up @@ -586,7 +594,7 @@ boolean define_proc(FILE *fromhere, char *declaration)
getout = TRUE;
} /*if*/

getline(fromhere, procedureline, "> ", MAXCOMMAND - 1);
_getline(fromhere, procedureline, "> ", MAXCOMMAND - 1);

if (stricmp(procedureline, "END") == 0)
getout = TRUE;
Expand Down Expand Up @@ -658,7 +666,7 @@ void codeload(char *filename)

while (!feof(logostream))
{
getline(logostream, bytebucket, "", MAXCOMMAND);
_getline(logostream, bytebucket, "", MAXCOMMAND);
if (strnicmp(bytebucket, "to ", 3) == 0)
define_proc(logostream, bytebucket + 3);
} /*while*/
Expand Down Expand Up @@ -696,14 +704,14 @@ boolean codesave(char *fname)
return(FALSE);

if (fname == NULL)
getline(NULL, filename, "Filename to save : ", MAXCOMMAND);
_getline(NULL, filename, "Filename to save : ", MAXCOMMAND);
else
strcpy(filename, fname);

if (*filename != '\0')
{

/*if (access(filename, 00) == 0) /* Does file exist? */
if (access(filename, 00) == 0) /* Does file exist? */
{
if (!getyn("That file already exists. Overwrite it?"))
return(FALSE);
Expand All @@ -717,7 +725,7 @@ boolean codesave(char *fname)
_outtext("Could not open file! Aborted.\n");
return(FALSE);
} /*if*/
/*} /*else*/
/*}*/ /*else*/

for (listloop = procedures; listloop != NULL; listloop = listloop->next)
{
Expand Down
9 changes: 7 additions & 2 deletions tobygrfx.c
Expand Up @@ -7,11 +7,16 @@

#include <stdio.h>
#include <stdlib.h>
#include <graph.h>
#include <math.h>
#include "toby.h"

extern char graphic_flags = FALSE; /* Bitmap of flags for graphics. */
#ifdef __GNUC__
#include "unixbits.h"
#else
#include <graph.h>
#endif

extern char graphic_flags; /* Bitmap of flags for graphics. */
extern short turtle_x; /* Turtle's X coordinate. */
extern short turtle_y; /* Turtle's Y coordinate. */
extern short pen_color; /* Current pen color. */
Expand Down

0 comments on commit f388e64

Please sign in to comment.