⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 Linux下VB解释器
💻 C
📖 第 1 页 / 共 4 页
字号:
	      if (ar >= argc)		{		  error (ERROR, "no commands specified (-h for help)");		  end_it ();		}	      explicit = my_strdup (argv[ar]);	    }	  else if (equal ("-librarypath", option, 4))	    {	      ar++;	      if (ar >= argc)		{		  error (ERROR, "no library path specified (-h for help)");		  end_it ();		}	      strcpy (library_path, argv[ar]);	    }	  else if (equal ("-display", option, 3))	    {	      ar++;	      if (ar >= argc)		{		  error (ERROR, "no display name specified (-h for help)");		  end_it ();		}	      displayname = my_strdup (argv[ar]);	    }	  else if (equal ("-font", option, 4))	    {	      ar++;	      if (ar >= argc)		{		  error (ERROR, "no font specified (-h for help)");		  end_it ();		}	      font = my_strdup (argv[ar]);	    }	  else if (!print_docu &&		   (!strcmp ("-doc", option)		    || !strncmp ("-doc_", option, 5)		    || !strcmp ("-docu", option)		    || !strncmp ("-docu_", option, 6)))	    {	      print_docu = TRUE;	      if (!strncmp ("-doc_", option, 5))		{		  ar--;		  hold_docu = TRUE;		  main_file_name = my_strdup (option + 5);		}	      else if (!strncmp ("-docu_", option, 6))		{		  ar--;		  hold_docu = TRUE;		  main_file_name = my_strdup (option + 6);		}	      else		{		  if (ar >= argc - 1)		    {		      error (ERROR, "no filename specified (-h for help)");		      end_it ();		    }		  hold_docu = FALSE;		  main_file_name = my_strdup (argv[ar + 1]);		}	    }	  else if (!print_docu && *option == '-')	    {	      sprintf (string,		       "unknown or ambigous option '%s' " YABFORHELP,		       option);	      error (ERROR, string);	      end_it ();	    }	  else if (!is_bound && !inputfile && !explicit)	    {			/* not an option */	      if (!main_file_name)		main_file_name = my_strdup (argv[ar]);	      inputfile = fopen (main_file_name, "r");	      if (inputfile == NULL)		{		  sprintf (string, "could not open '%s': %s",			   main_file_name, my_strerror (errno));		  error (ERROR, string);		  endreason = erERROR;		  exitcode = 1;		  end_it ();		}	      else		{		  progname = strrchr (main_file_name, '\\');		  if (!progname)		    progname = strrchr (main_file_name, '/');		  if (progname)		    progname++;		  else		    progname = main_file_name;		  if (!progname)		    progname = "Yabasic";		}	    }	  else	    {			/* option for yabasic program */	      yabargv[yabargc] = my_strdup (argv[ar]);	      yabargc++;	    }	}      else	{	  yabargv[yabargc] = my_strdup (argv[ar]);	  yabargc++;	}    }  interactive = FALSE;#ifdef WINDOWS  if (is_bound || !progname)    {      SetConsoleTitle ("");    }  else    {      SetConsoleTitle (progname);    }#endif  if (is_bound)    {      inputfile = bound_program;      main_file_name = my_strdup (interpreter_path);    }  else if (!inputfile && !explicit)    {      interactive = TRUE;      inputfile = stdin;      main_file_name = "standard input";    }  if (explicit)    main_file_name = "command line";  /* open a flex buffer for the initial file */  open_main (inputfile, explicit, main_file_name);  return;}voiddo_help (char *op)		/* process help option */{  char *ooop = op;  char *oop = op;  if (op[0] == '-' && op[1] == '-')    op++;  oop = op;  op = strchr (++op, '-');  if (!op)    {      if (equal ("-version", oop, 2))	{	  fprintf (stderr, "%s\n", BANNER_VERSION);	}      else if (equal ("-license", oop, 2) || equal ("-licence", oop, 2))	{	  fprintf (stderr, "\n%s\n", YABLICENSE);	}      else	{	  fprintf (stderr, "%s", BANNER);	  fprintf (stderr, "For more help try one of these options:\n");	  fprintf (stderr,		   "  -help-license : show license and conditions of copying\n");	  fprintf (stderr,		   "  -help-usage   : invoking yabasic and commandline options\n\n");#ifdef UNIX	  fprintf (stderr,		   "Type 'man yabasic' or see the file yabasic.htm for a description\n");#else	  fprintf (stderr,		   "See the file yabasic.htm (accessible from the start-menu) for a\ndescription");#endif	  fprintf (stderr,		   "of the language, or go to www.yabasic.de for the latest\n");	  fprintf (stderr, "information and other yabasic resources.\n\n");	}    }  else if (equal ("-license", op, 2) || equal ("-licence", op, 2))    {      fprintf (stderr, "\n%s\n", YABLICENSE);    }  else if (equal ("-usage", op, 2))    {      fprintf (stderr,	       "\nUsage:        yabasic [OPTIONS] [FILENAME [ARGUMENTS]]\n\n");      fprintf (stderr,	       "FILENAME  : file, which contains the yabasic program; omit it to type\n");      fprintf (stderr,	       "            in your program on the fly (terminated by a double newline)\n");      fprintf (stderr,	       "ARGUMENTS : strings, that are available from within the yabasic program\n\n");      fprintf (stderr, "available OPTIONS:\n");      fprintf (stderr,	       "   -help               : print help message and other help options\n");      fprintf (stderr,	       "   -version            : show version of yabasic\n");      fprintf (stderr,	       "   -infolevel [dnwefb] : set infolevel to debug,note,warning,error or fatal\n");      fprintf (stderr,	       "   -execute COMMANDS   : execute yabasic COMMANDS right away\n");      fprintf (stderr,	       "   -bind BOUND         : bind interpreter with FILENAME into BOUND\n");      fprintf (stderr,	       "   -geometry x+y       : position graphic window at x,y\n");#ifdef UNIX      fprintf (stderr,	       "   -fg,-bg COL         : specify fore/background color of graphic window\n");      fprintf (stderr,	       "   -display DISP       : display, where window will show up\n");      fprintf (stderr,	       "   -font FONT          : font for graphic window\n");#else      fprintf (stderr,	       "   -font FONT          : font for graphic, supply style (decorative,dontcare,\n");      fprintf (stderr,	       "                         modern,roman,script or swiss) and size, e.g. swiss10\n");#endif      fprintf (stderr,	       "   -docu NAME          : print embedded docu of program or library\n");      fprintf (stderr,	       "   -check              : check for possible compatibility problems\n");      fprintf (stderr,	       "   --                  : pass any subsequent words as arguments to yabasic\n");      fprintf (stderr,	       "   -librarypath PATH   : directory to search libraries not found in\n");      fprintf (stderr,	       "                         current dir (default %s)\n",	       library_default);      fprintf (stderr, "\n");    }  else    {      sprintf (string, "unknown or ambigous option '%s' " YABFORHELP,	       ooop);      error (ERROR, string);    }}intequal (char *a, char *b, int min)	/* helper for processing options */{  int len;  if (b[0] == '-' && b[1] == '-' && b[2])    b++;  if (min < 0)    {      min = -min;      len = min;    }  else    {      len = strlen (b);    }  return (!strncmp (a, b, len) && len >= min);}#ifdef WINDOWSstatic voidchop_command (char *command, int *argc, char ***argv)     /* chop the WIN95-commandline into seperate strings */{  int i, j, count;  int quote;  char c, last;  char *curr;  char **list;  /* count, how many arguments */  count = i = 0;  last = ' ';  quote = FALSE;  while ((c = *(command + i)) != '\0')    {      if (!quote && c != ' ' && last == ' ')	count++;      if (c == '\"')	quote = !quote;      last = c;      i++;    }  /* fill yabasic into argv[0] */  *argv = my_malloc ((count + 1) * sizeof (char *));  list = *argv;  *argc = count + 1;  *list = my_strdup ("yabasic");  /* fill in other strings */  i = 0;  count = 1;  last = ' ';  quote = FALSE;  do    {      c = *(command + i);      if (!quote && c != ' ' && last == ' ')	j = i;      if (c == '\"')	{	  quote = !quote;	  if (quote)	    j++;	}      if (((c == ' ' && !quote) || c == '\0') && last != ' ')	{	  *(list + count) = my_malloc ((i - j + 1) * sizeof (char));	  strncpy (*(list + count), command + j, i - j);	  curr = *(list + count) + i - j;	  *curr = '\0';	  if (*(curr - 1) == '\"')	    *(curr - 1) = '\0';	  count++;	}      last = c;      i++;    }  while (c != '\0');}#endifstatic voidend_it (void)			/* perform shutdown-operations */{  char l[2];#ifdef UNIX  int status;  if (winpid == 0 || termpid == 0 || backpid == 0)    exit (1);  if (backpid > 0)    {      kill (backpid, SIGTERM);      waitpid (backpid, &status, 0);      backpid = -1;    }  if ((curinized || winopened) && endreason != erREQUEST)    {#else  if (!Commandline && endreason != erREQUEST)    {#endif      myswitch (STDIO_STREAM);      onestring ("---Program done, press RETURN---\n");#ifdef WINDOWS      SetConsoleMode (ConsoleInput, InitialConsole & (~ENABLE_ECHO_INPUT));      FlushConsoleInputBuffer (ConsoleInput);#endif      fgets (l, 2, stdin);#ifdef WINDOWS      if (wthandle != INVALID_HANDLE_VALUE)	TerminateThread (wthandle, 0);#endif#ifdef UNIX    }#else    }#endif#ifdef UNIX  if (curinized)    endwin ();#else  if (printerfont)    DeleteObject (printerfont);  if (myfont)    DeleteObject (myfont);  if (printer)    DeleteDC (printer);#endif  exit (exitcode);}static voidinitialize (void)     /* give correct values to pointers etc ... */{  struct symbol *s;  struct stackentry *base;  int i;#ifdef UNIX#ifdef SETPGRP_VOID  setpgrp ();#else#endif#endif  /* install exception handler */  signal (SIGFPE, signal_handler);  signal (SIGSEGV, signal_handler);  signal (SIGINT, signal_handler);#ifdef SIGHUP  signal (SIGHUP, signal_handler);#endif#ifdef SIGQUIT  signal (SIGQUIT, signal_handler);#endif#ifdef SIGABRT  signal (SIGABRT, signal_handler);#endif  /* initialize error handling: no errors seen 'til now */  errorlevel = DEBUG;  debug_count = 0;  note_count = 0;  warning_count = 0;  error_count = 0;  /* initialize stack of symbol lists */  pushsymlist ();  /* initialize random number generator */  srand ((unsigned) time (NULL));  /* initialize numeric stack */  /* create first : */  stackroot = (struct stackentry *) my_malloc (sizeof (struct stackentry));  stackroot->next = NULL;  stackroot->prev = NULL;  stackhead = stackroot;	/* stack of double values */  /* initialize command stack */  /* create first: */  cmdroot = (struct command *) my_malloc (sizeof (struct command));  cmdroot->next = cmdroot->prev = NULL;  /* initialize random number generator */  srand ((unsigned int) time (NULL));  /* specify default text-alignement and window origin */  text_align = my_strdup ("lb");  winorigin = my_strdup ("lt");  /* initialize stack */  base = push ();  base->type = stROOT;		/* push nil, so that pop will not crash */  cmdhead = cmdroot; /* list of commands */ ;  commandcount = 0;  /* add internal string variables */  s = get_sym ("yabos$", sySTRING, amADD_GLOBAL);  if (s->pointer)    my_free (s->pointer);#ifdef UNIX  s->pointer = my_strdup ("unix");#else  s->pointer = my_strdup ("windows");#endif  /* set default-scales for grafics */  fontheight = 10;  winheight = 100;  winwidth = 100;#ifdef UNIX  calc_psscale ();#endif  /* file stuff */  for (i = 1; i <= 9; i++)    {      streams[i] = NULL;      stream_modes[i] = smCLOSED;    }  streams[0] = stdin;  stream_modes[0] = smREAD | smWRITE;#ifdef UNIX  printerfile = NULL;		/* no ps-file yet */#endif  /* array with explanation */  for (i = cFIRST_COMMAND; i <= cLAST_COMMAND; i++)    explanation[i] = "???";  explanation[cFIRST_COMMAND] = "FIRST_COMMAND";  explanation[cFINDNOP] = "FINDNOP";  explanation[cEXCEPTION] = "EXCEPTION";  explanation[cLABEL] = "LABEL";  explanation[cSUBLINK] = "cSUBLINK";  explanation[cTOKEN] = "TOKEN";  explanation[cTOKEN2] = "TOKEN2";  explanation[cTOKENALT] = "TOKENALT";  explanation[cTOKENALT2] = "TOKENALT2";  explanation[cSPLIT] = "SPLIT";  explanation[cSPLIT2] = "SPLIT2";  explanation[cSPLITALT] = "SPLITALT";  explanation[cSPLITALT2] = "SPLITALT2";  explanation[cGOTO] = "GOTO";  explanation[cQGOTO] = "QGOTO";  explanation[cGOSUB] = "GOSUB";  explanation[cQGOSUB] = "QGOSUB";  explanation[cCALL] = "CALL";  explanation[cQCALL] = "QCALL";  explanation[cRETURN] = "RETURN";  explanation[cRET_FROM_FUN] = "RET_FROM_FUN";  explanation[cRETVAL] = "RETVAL";  explanation[cSWAP] = "SWAP";  explanation[cDECIDE] = "DECIDE";  explanation[cANDSHORT] = "ANDSHORT";  explanation[cORSHORT] = "ORSHORT";  explanation[cSKIPPER] = "SKIPPER";  explanation[cSKIPONCE] = "SKIPONCE";  explanation[cRESETSKIPONCE] = "RESETSKIPONCE";  explanation[cNOP] = "NOP";  explanation[cEND_FUNCTION] = "END_FUNCTION";  explanation[cDIM] = "DIM";  explanation[cFUNCTION] = "FUNCTION";  explanation[cDOARRAY] = "DOARRAY";  explanation[cDBLADD] = "DBLADD";  explanation[cDBLMIN] = "DBLMIN";  explanation[cDBLMUL] = "DBLMUL";  explanation[cDBLDIV] = "DBLDIV";  explanation[cDBLPOW] = "DBLPOW";  explanation[cNEGATE] = "NEGATE";  explanation[cPUSHDBLSYM] = "PUSHDBLSYM";  explanation[cREQUIRE] = "REQUIRE";  explanation[cCLEARREFS] = "CLEARREFS";  explanation[cPUSHSYMLIST] = "PUSHSYMLIST";  explanation[cPOPSYMLIST] = "POPSYMLIST";  explanation[cMAKELOCAL] = "MAKELOCAL";  explanation[cNUMPARAM] = "NUMPARAM";  explanation[cMAKESTATIC] = "MAKESTATIC";  explanation[cARRAYLINK] = "ARRAYLINK";  explanation[cPUSHARRAYREF] = "PUSHARRAYREF";  explanation[cARDIM] = "ARRAYDIMENSION";  explanation[cARSIZE] = "ARRAYSIZE";  explanation[cUSER_FUNCTION] = "USER_FUNCTION";  explanation[cFUNCTION_OR_ARRAY] = "FUNCTION_OR_ARRAY";  explanation[cSTRINGFUNCTION_OR_ARRAY] = "STRINGFUNCTION_OR_ARRAY";  explanation[cPUSHFREE] = "PUSHFREE";  explanation[cPOPDBLSYM] = "POPDBLSYM";  explanation[cPOP] = "POP";  explanation[cPUSHDBL] = "PUSHDBL";  explanation[cPOKE] = "POKE";  explanation[cPOKEFILE] = "POKEFILE";  explanation[cAND] = "AND";  explanation[cOR] = "OR";  explanation[cNOT] = "NOT";  explanation[cLT] = "LT";  explanation[cGT] = "GT";  explanation[cLE] = "LE";  explanation[cGE] = "GE";  explanation[cEQ] = "EQ";  explanation[cNE] = "NE";  explanation[cSTREQ] = "STREQ";  explanation[cSTRNE] = "STRNE";  explanation[cPUSHSTRSYM] = "PUSHSTRSYM";  explanation[cPOPSTRSYM] = "POPSTRSYM";  explanation[cPUSHSTR] = "PUSHSTR";  explanation[cCONCAT] = "CONCAT";  explanation[cPUSHSTRPTR] = "PUSHSTRPTR";  explanation[cCHANGESTRING] = "CHANGESTRING";  explanation[cGLOB] = "GLOB";  explanation[cPRINT] = "PRINT";  explanation[cREAD] = "READ";  explanation[cRESTORE] = "RESTORE";  explanation[cQRESTORE] = "QRESTORE";  explanation[cREADDATA] = "READDATA";  explanation[cONESTRING] = "ONESTRING";  explanation[cDATA] = "DATA";  explanation[cOPEN] = "OPEN";  explanation[cCHECKOPEN] = "CHECKOPEN";  explanation[cCHECKSEEK] = "CHECKSEEK";  explanation[cCOMPILE] = "COMPILE";  explanation[cEXECUTE] = "EXECUTE";  explanation[cEXECUTE2] = "EXECUTE$";  explanation[cCLOSE] = "CLOSE";  explanation[cSEEK] = "SEEK";  explanation[cSEEK2] = "SEEK2";  explanation[cPUSHSTREAM] = "cPUSHSTREAM";  explanation[cPOPSTREAM] = "cPOPSTREAM";  explanation[cWAIT] = "WAIT";  explanation[cBELL] = "BELL";  explanation[cMOVE] = "MOVE";  explanation[cMOVEORIGIN] = "MOVEORIGIN";  explanation[cRECT] = "RECT";  explanation[cCLEARSCR] = "CLEARSCR";  explanation[cOPENWIN] = "OPENWIN";  explanation[cDOT] = "DOT";  explanation[cPUTBIT] = "PUTBIT";  explanation[cPUTCHAR] = "PUTCHAR";  explanation[cLINE] = "LINE";  explanation[cGCOLOUR] = "GCOLOUR";  explanation[cGCOLOUR2] = "GCOLOUR2";  explanation[cGBACKCOLOUR] = "GBACKCOLOUR";  explanation[cGBACKCOLOUR2] = "GBACKCOLOUR2";  explanation[cCIRCLE] = "CIRCLE";  explanation[cTRIANGLE] = "TRIANGLE";  explanation[cTEXT1] = "TEXT1";  explanation[cTEXT2] = "TEXT2";  explanation[cTEXT3] = "TEXT3";  explanation[cCLOSEWIN] = "CLOSEWIN";  explanation[cCLEARWIN] = "CLEARWIN";  explanation[cOPENPRN] = "OPENPRN";  explanation[cCLOSEPRN] = "CLOSEPRN";

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -