void init() { // extern long time(); int i /* = 0 */; NODE *proc = NIL, *pname = NIL, *cnd = NIL; fill_reserve_tank(); Unbound = newnode(PUNBOUND); #ifdef bsd srandom((int) time((long *) NULL)); #else // srand((int)time((long *)NULL)); // srand((int)12345); #endif #ifdef ecma for (i = 0; i < 128; i++) ecma_array[i] = i; for (i = 0; i < ecma_size; i++) ecma_array[special_chars[i]] = ecma_begin+i; #endif // logolib = getenv("LOGOLIB"); // if (logolib == NULL) logolib = libloc; // editor = getenv("EDITOR"); // if (editor == NULL) editor = "jove"; editor = "jove"; editorname = strrchr(editor, (int) '/'); editorname = (editorname ? editorname + 1 : editor); i = 0; while (prims[i].name) { if (prims[i].priority == MACRO_PRIORITY) proc = reref(proc, newnode(MACRO)); else if (prims[i].priority == TAIL_PRIORITY) proc = reref(proc, newnode(TAILFORM)); else if ((prims[i].priority & ~4) == PREFIX_PRIORITY) proc = reref(proc, newnode(PRIM));/* incl. -- */ else proc = reref(proc, newnode(INFIX)); if (prims[i].priority < PREFIX_PRIORITY) setprimpri(proc, PREFIX_PRIORITY); else setprimpri(proc, prims[i].priority); setprimfun(proc, (lexzer) prims[i].prim); setprimdflt(proc, prims[i].defargs); setprimmax(proc, prims[i].maxargs); setprimmin(proc, prims[i].minargs); pname = reref(pname, make_static_strnode(prims[i].name)); cnd = reref(cnd, make_instance(pname, pname)); setprocnode__caseobj(cnd, proc); if (nodetype(proc) == MACRO) setflag__caseobj(cnd, PROC_MACRO); i++; } deref(proc); deref(cnd); deref(pname); Truex = intern(make_static_strnode("true")); Falsex = intern(make_static_strnode("false")); Left_Paren = intern(make_static_strnode("(")); Right_Paren = intern(make_static_strnode(")")); Minus_Sign = intern(make_static_strnode("-")); Minus_Tight = intern(make_static_strnode("--")); Query = intern(make_static_strnode("?")); Null_Word = intern(make_static_strnode("\0")); To = intern(make_static_strnode("to")); Macro = intern(make_static_strnode(".macro")); Toplevel = intern(make_static_strnode("toplevel")); System = intern(make_static_strnode("system")); Error = intern(make_static_strnode("error")); End = intern(make_static_strnode("end")); If = intern(make_static_strnode("if")); Ifelse = intern(make_static_strnode("ifelse")); Redefp = intern(make_static_strnode("redefp")); Caseignoredp = intern(make_static_strnode("caseignoredp")); setvalnode__caseobj(Caseignoredp, Truex); setflag__caseobj(Caseignoredp, VAL_BURIED); Erract = intern(make_static_strnode("erract")); Printdepthlimit = intern(make_static_strnode("printdepthlimit")); Printwidthlimit = intern(make_static_strnode("printwidthlimit")); Pause = intern(make_static_strnode("pause")); Startup = intern(make_static_strnode("startup")); Output = intern(make_static_strnode("output")); Op = intern(make_static_strnode("op")); Stop = intern(make_static_strnode("stop")); Goto = intern(make_static_strnode("goto")); Tag = intern(make_static_strnode("Tag")); the_generation = valref(cons(NIL, NIL)); Not_Enough_Node = valref(cons(NIL, NIL)); }
int main(int argc, char *argv[]) { NODE *exec_list = NIL; NODE *cl_tail = NIL; int argc2; char **argv2; bottom_stack = &exec_list; /*GC*/ (void) addseg(); term_init(); init(); math_init(); my_init(); signal(SIGINT, logo_stop); if (argc < 2) { if (1 || isatty(1)) // fix this. for interactive from menu bar. { char version[20]; lcleartext(NIL); strcpy(version, "5.6"); ndprintf(stdout, message_texts[WELCOME_TO], version); new_line(stdout); } } setvalnode__caseobj(LogoVersion, make_floatnode(5.6)); setflag__caseobj(LogoVersion, VAL_BURIED); argv2 = argv; argc2 = argc; if (!strcmp(*argv + strlen(*argv) - 4, "logo")) { argv++; while (--argc > 0 && strcmp(*argv, "-") && NOT_THROWING) { argv++; } } argv++; while (--argc > 0) { if (command_line == NIL) cl_tail = command_line = cons(make_static_strnode(*argv++), NIL); else { setcdr(cl_tail, cons(make_static_strnode(*argv++), NIL)); cl_tail = cdr(cl_tail); } } setvalnode__caseobj(CommandLine, command_line); silent_load(Startuplg, logolib); silent_load(Startup, NULL); /* load startup.lg */ if (!strcmp(*argv2 + strlen(*argv2) - 4, "logo")) { argv2++; while (--argc2 > 0 && strcmp(*argv2, "-") && NOT_THROWING) { silent_load(NIL, *argv2++); } } for (;;) { if (NOT_THROWING) { check_reserve_tank(); current_line = reader(stdin, "? "); if (feof(stdin) && !isatty(0)) lbye(NIL); if (NOT_THROWING) { exec_list = parser(current_line, TRUE); if (exec_list != NIL) eval_driver(exec_list); } } if (stopping_flag == THROWING) { if (isName(throw_node, Name_error)) { err_print(NULL); } else if (isName(throw_node, Name_system)) break; else if (!isName(throw_node, Name_toplevel)) { err_logo(NO_CATCH_TAG, throw_node); err_print(NULL); } stopping_flag = RUN; } if (stopping_flag == STOP || stopping_flag == OUTPUT) { /* ndprintf(stdout, "%t\n", message_texts[CANT_STOP]); */ stopping_flag = RUN; } } //prepare_to_exit(TRUE); my_finish(); exit(0); return 0; }
NODE *intern_p(NODE *caseobj) { NODE *result = intern(caseobj); setflag__caseobj(result, PERMANENT); return result; }
void init(void) { int i = 0; NODE *iproc = NIL, *pname = NIL, *cnd = NIL; FILE *fp; char linebuf[100]; char *sugar; static char sugarlib[100], sugarhelp[100], sugarcsls[100]; #ifdef WIN32 HKEY regKey1, regKey2, regKey3; int got_hklm = 0; char buf[200]; unsigned long int bufsiz; char *envp; #endif readstream = stdin; writestream = stdout; loadstream = stdin; fill_reserve_tank(); oldyoungs = Unbound = newnode(PUNBOUND); #ifdef HAVE_SRANDOM srandom((int)time((time_t *)NULL)); #else srand((int)time((time_t *)NULL)); #endif #ifdef ecma for (i=0; i<128; i++) ecma_array[i] = i; for (i=0; i<ecma_size; i++) ecma_array[(int)special_chars[i]] = ecma_begin+i; i = 0; #endif sugar = getenv("SUGAR_BUNDLE_PATH"); if (sugar != NULL) { strcpy(sugarlib,sugar); strcat(sugarlib,"/logolib"); logolib = sugarlib; fp = fopen(logolib,"r"); if (fp == NULL) goto nosugar; fclose(fp); chdir(getenv("SUGAR_ACTIVITY_ROOT")); chdir("data"); strcpy(sugarhelp,sugar); strcat(sugarhelp,"/helpfiles"); helpfiles = sugarhelp; strcpy(sugarcsls,sugar); strcat(sugarcsls,"/csls"); csls = sugarcsls; } else { nosugar: logolib = getenv("LOGOLIB"); helpfiles = getenv("LOGOHELP"); csls = getenv("CSLS"); } editor = getenv("EDITOR"); #ifdef WIN32 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ, ®Key1) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey1, "UCB", 0, KEY_READ, ®Key2) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey2, "UCBLogo", 0, KEY_READ, ®Key3) == ERROR_SUCCESS) { got_hklm = 1; /* logolib = getenv("LOGOLIB"); */ if (logolib == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "LOGOLIB", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { logolib = malloc(bufsiz); strcpy(logolib, buf); } } /* helpfiles = getenv("LOGOHELP"); */ if (helpfiles == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "HELPFILE", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { helpfiles = malloc(bufsiz); strcpy(helpfiles, buf); } } /* csls = getenv("CSLS"); */ if (csls == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "CSLS", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { csls = malloc(bufsiz); strcpy(csls, buf); } } /* editor = getenv("EDITOR"); */ if (editor == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "EDITOR", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { editor = malloc(bufsiz); strcpy(editor, buf); } } RegCloseKey(regKey3); } RegCloseKey(regKey2); } RegCloseKey(regKey1); } if (!got_hklm && RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_READ, ®Key1) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey1, "UCB", 0, KEY_READ, ®Key2) == ERROR_SUCCESS) { if (RegOpenKeyEx(regKey2, "UCBLogo", 0, KEY_READ, ®Key3) == ERROR_SUCCESS) { got_hklm = 1; /* logolib = getenv("LOGOLIB"); */ if (logolib == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "LOGOLIB", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { logolib = malloc(bufsiz); strcpy(logolib, buf); } } /* helpfiles = getenv("LOGOHELP"); */ if (helpfiles == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "HELPFILE", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { helpfiles = malloc(bufsiz); strcpy(helpfiles, buf); } } /* csls = getenv("CSLS"); */ if (csls == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "CSLS", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { csls = malloc(bufsiz); strcpy(csls, buf); } } /* editor = getenv("EDITOR"); */ if (editor == NULL) { bufsiz=200; if (RegQueryValueEx(regKey3, "EDITOR", NULL, NULL, buf, &bufsiz) == ERROR_SUCCESS) { editor = malloc(bufsiz); strcpy(editor, buf); } } RegCloseKey(regKey3); } RegCloseKey(regKey2); } RegCloseKey(regKey1); } #endif if (logolib == NULL) logolib = libloc; if (helpfiles == NULL) helpfiles = helploc; if (csls == NULL) csls = cslsloc; #ifdef HAVE_WX #ifndef __WXMSW__ // have to do this because we don't have __WXMAC__ in C const char* wxMacGetCslsloc(); const char* wxMacGetHelploc(); const char* wxMacGetLibloc(); char* newlib; char* newcsls; char* newhelp; // check if we are running wxMac newlib = wxMacGetLibloc(); if(newlib) logolib=newlib; //if (helpfiles == NULL) helpfiles = wxMacGetHelploc(); newcsls = wxMacGetCslsloc(); if(newcsls) csls = newcsls; newhelp = wxMacGetHelploc(); if(newhelp) helpfiles = newhelp; #endif #endif #ifdef unix if (editor == NULL) editor = "emacs"; #else if (editor == NULL) editor = "jove"; #endif editorname = strrchr(editor, (int)'/'); if (editorname == NULL) editorname = strrchr(editor, (int)'\\'); #ifdef WIN32 if (editorname == NULL) { putenv("DESCRIBE=CMDS.DOC"); putenv("JOVERC=JOVE.RC"); } else { bufsiz = sprintf(buf, "DESCRIBE=%.*s\\CMDS.DOC", editorname-editor, editor); envp = malloc(bufsiz+1); strcpy(envp, buf); putenv(envp); bufsiz = sprintf(buf, "JOVERC=%.*s\\JOVE.RC", editorname-editor, editor); envp = malloc(bufsiz+1); strcpy(envp, buf); putenv(envp); } #endif if (editorname == NULL) editorname = strrchr(editor, (int)':'); editorname = (editorname ? editorname+1 : editor); tempdir = getenv("TEMP"); if (tempdir == NULL) tempdir = temploc; while (prims[i].name) { if (prims[i].priority == MACRO_PRIORITY) iproc = newnode(MACRO); else if (prims[i].priority <= TAIL_PRIORITY) iproc = newnode(TAILFORM); else if ((prims[i].priority & ~4) == (PREFIX_PRIORITY & ~4)) iproc = newnode(PRIM); /* incl. -- */ else iproc = newnode(INFIX); setprimpri(iproc, prims[i].priority); setprimfun(iproc, prims[i].prim); setprimdflt(iproc, prims[i].defargs); setprimmax(iproc, prims[i].maxargs); setprimmin(iproc, prims[i].minargs); pname = make_static_strnode(prims[i].name); cnd = make_instance(pname, pname); setprocnode__caseobj(cnd, iproc); if (nodetype(iproc) == MACRO) setflag__caseobj(cnd, PROC_MACRO); if (prims[i].minargs < 0) setflag__caseobj(cnd, PROC_SPECFORM); setflag__caseobj(cnd, PERMANENT); i++; } Left_Paren = intern_p(make_static_strnode("(")); Right_Paren = intern_p(make_static_strnode(")")); Minus_Sign = intern_p(make_static_strnode("-")); Minus_Tight = intern_p(make_static_strnode("--")); Query = intern_p(make_static_strnode("?")); Null_Word = intern_p(make_static_strnode("\0")); Redefp = intern_p(make_static_strnode("redefp")); Caseignoredp = intern_p(make_static_strnode("caseignoredp")); Erract = intern_p(make_static_strnode("erract")); Buttonact = intern_p(make_static_strnode("buttonact")); Keyact = intern_p(make_static_strnode("Keyact")); Printdepthlimit = intern_p(make_static_strnode("printdepthlimit")); Printwidthlimit = intern_p(make_static_strnode("printwidthlimit")); LoadNoisily = intern_p(make_static_strnode("loadnoisily")); AllowGetSet = intern_p(make_static_strnode("allowgetset")); Fullprintp = intern_p(make_static_strnode("fullprintp")); UnburyOnEdit = intern_p(make_static_strnode("unburyonedit")); UseAlternateNames = intern_p(make_static_strnode("usealternatenames")); Make = intern_p(make_static_strnode("make")); Listvalue = cons(intern_p(make_static_strnode("value")),NIL); Dotsvalue = make_colon(car(Listvalue)); Pause = intern_p(make_static_strnode("pause")); Startup = intern_p(make_static_strnode("startup")); Startuplg = intern_p(make_static_strnode("startup.lg")); LogoVersion = intern_p(make_static_strnode("logoversion")); LogoPlatform = intern_p(make_static_strnode("logoplatform")); LogoLogo = intern_p(make_static_strnode("logo-logo")); CommandLine = intern_p(make_static_strnode("command.line")); setflag__caseobj(CommandLine, VAL_BURIED); the_generation = cons(NIL, NIL); Not_Enough_Node = cons(NIL, NIL); sprintf(linebuf,"%s%sMessages", logolib, separator); fp = fopen("Messages", "r"); if (fp == NULL) fp = fopen(linebuf, "r"); if (fp == NULL) fp = fopen("C:\\cygwin\\usr\\local\\lib\\logo\\logolib\\Messages", "r"); if (fp == NULL) { printf("Error -- Can't read Messages file.\n"); exit(1); } for (i=0; i<(MAX_MESSAGE+NUM_WORDS); i++) { while (fgets(linebuf, 99, fp) != NULL && linebuf[0] == ';') ; linebuf[strlen(linebuf)-1] = '\0'; message_texts[i] = (char *) malloc(1+strlen(linebuf)); strcpy(message_texts[i], linebuf); } fclose(fp); #define wd_copy(x) \ translations[Name_ ## x].English = intern_p(make_static_strnode(#x)); \ translations[Name_ ## x].Alt = \ intern_p(make_static_strnode(message_texts[MAX_MESSAGE + Name_ ## x])); do_trans(wd_copy); translations[Name_macro].English = intern_p(make_static_strnode(".macro")); #define True translations[Name_true].English #define False translations[Name_false].English setvalnode__caseobj(Caseignoredp, True); setflag__caseobj(Caseignoredp, VAL_BURIED); setvalnode__caseobj(AllowGetSet, True); setflag__caseobj(AllowGetSet, VAL_BURIED); setvalnode__caseobj(Fullprintp, False); setflag__caseobj(Fullprintp, VAL_BURIED); setvalnode__caseobj(UnburyOnEdit, True); setflag__caseobj(UnburyOnEdit, VAL_BURIED); setvalnode__caseobj(UseAlternateNames, False); setflag__caseobj(UseAlternateNames, VAL_BURIED); setvalnode__caseobj(LogoPlatform, make_static_strnode(LogoPlatformName)); setflag__caseobj(LogoPlatform, VAL_BURIED); user_repcount = -1; ift_iff_flag = -1; num_saved_nodes = (NODE **)(&(val_status)) - (NODE **)(&(proc)); Regs_Node = newnode(STACK); Regs_Node->n_car = (NODE *)®s; //hist_inptr = hist_outptr = cmdHistory; #ifdef OBJECTS obj_init(); #endif /* Uncomment these to print debugging messages right away! */ /* setvalnode__caseobj(Redefp, True); setflag__caseobj(Redefp, VAL_BURIED); */ }
int start (int argc,char ** argv) { #else int main(int argc, char *argv[]) { #endif NODE *exec_list = NIL; NODE *cl_tail = NIL; int argc2; char **argv2; #ifdef SYMANTEC_C extern void (*openproc)(void); extern void __open_std(void); openproc = &__open_std; #endif #ifdef mac init_mac_memory(); #endif bottom_stack = &exec_list; /*GC*/ #ifndef HAVE_WX #ifdef x_window x_window_init(argc, argv); #endif #endif (void)addseg(); term_init(); init(); math_init(); #ifdef ibm signal(SIGINT, SIG_IGN); #if defined(__RZTC__) && !defined(WIN32) /* sowings */ _controlc_handler = do_ctrl_c; controlc_open(); #endif #else /* !ibm */ signal(SIGINT, logo_stop); #endif /* ibm */ #ifdef mac signal(SIGQUIT, SIG_IGN); #else /* !mac */ //signal(SIGQUIT, logo_pause); #endif /* SIGQUITs never happen on the IBM */ if (argc < 2) { #ifndef WIN32 if (1 || isatty(1)) // fix this. for interactive from menu bar. #endif { #ifdef HAVE_WX extern char *SVN; #endif char version[20]; lcleartext(NIL); #ifdef HAVE_WX strcpy(version,"6.0"); strcat(version,SVN); #else strcpy(version,"5.6"); #endif ndprintf(stdout, message_texts[WELCOME_TO], version); new_line(stdout); } } #ifdef HAVE_WX setvalnode__caseobj(LogoVersion, make_floatnode(6.0)); #else setvalnode__caseobj(LogoVersion, make_floatnode(5.6)); #endif setflag__caseobj(LogoVersion, VAL_BURIED); argv2 = argv; argc2 = argc; if (!strcmp(*argv+strlen(*argv)-4, "logo")) { argv++; while (--argc > 0 && strcmp(*argv, "-") && NOT_THROWING) { argv++; } } argv++; while (--argc > 0) { if (command_line == NIL) cl_tail = command_line = cons(make_static_strnode(*argv++), NIL); else { setcdr(cl_tail, cons(make_static_strnode(*argv++), NIL)); cl_tail = cdr(cl_tail); } } setvalnode__caseobj(CommandLine, command_line); silent_load(Startuplg, logolib); silent_load(Startup, NULL); /* load startup.lg */ if (!strcmp(*argv2+strlen(*argv2)-4, "logo")) { argv2++; while (--argc2 > 0 && strcmp(*argv2, "-") && NOT_THROWING) { silent_load(NIL,*argv2++); } } for (;;) { if (NOT_THROWING) { check_reserve_tank(); current_line = reader(stdin,"? "); #ifdef __RZTC__ (void)feof(stdin); if (!in_graphics_mode) printf(" \b"); fflush(stdout); #endif #ifndef WIN32 if (feof(stdin) && !isatty(0)) lbye(NIL); #endif #ifdef __RZTC__ if (feof(stdin)) clearerr(stdin); #endif if (NOT_THROWING) { exec_list = parser(current_line, TRUE); if (exec_list != NIL) eval_driver(exec_list); } } #ifdef HAVE_WX if (wx_leave_mainloop) { break; } #endif if (stopping_flag == THROWING) { if (isName(throw_node, Name_error)) { err_print(NULL); } else if (isName(throw_node, Name_system)) break; else if (!isName(throw_node, Name_toplevel)) { err_logo(NO_CATCH_TAG, throw_node); err_print(NULL); } stopping_flag = RUN; } if (stopping_flag == STOP || stopping_flag == OUTPUT) { /* ndprintf(stdout, "%t\n", message_texts[CANT_STOP]); */ stopping_flag = RUN; } } //prepare_to_exit(TRUE); exit(0); return 0; }