Ejemplo n.º 1
0
void CRScanner::NextCh()
{
  BuffPos++;
  Ch = CurrentCh(BuffPos);
  if (IgnoreCase) Ch = Upcase(Ch);
  if (Ch == TAB_CHAR) CurrCol += TAB_SIZE - (CurrCol % TAB_SIZE);
  else if (Ch == LF_CHAR) {
    CurrLine++; CurrCol = 0;
    LineStart = BuffPos + 1;
  }
  CurrCol++;
};
Ejemplo n.º 2
0
int CRScanner::EqualStr(char *s)
{
  long pos; char c;
  if (NextSym.Len != strlen(s)) return 0;
  pos = NextSym.Pos;
  while (*s) {
    c = CurrentCh(pos); pos++;
    if (IgnoreCase) c = Upcase(c);
    if (c != *s++) return 0;
  }
  return 1;
}
Ejemplo n.º 3
0
void CRScanner::GetName(AbsToken *Sym, char *Buffer, int Max)
{
  int  Len = Sym->Len;
  long Pos = Sym->Pos;

  while (Len-- && Max--) {
    *Buffer = CurrentCh(Pos); Pos++;
    if (IgnoreCase) *Buffer = Upcase(*Buffer);
    Buffer++;
  }
  *Buffer = '\0';
}
Ejemplo n.º 4
0
/*-----------------------------------------------------------------------
input: nothing
output: nothing
called by: shell
description:
  This is the main program of the simulator. It displays the prompt, reads
  and parses the user command, and calls the corresponding routines.
  Commands not reconized by the parser are passed along to the shell.
  The command is executed according to some pre-determined sequence.
  For example, we have to read in the circuit description file before any
  action commands.  The code uses "Gstate" to check the execution
  sequence.
  Pointers to functions are used to make function calls which makes the
  code short and clean.
-----------------------------------------------------------------------*/
main()
{
   enum e_com com;
   char cline[MAXLINE], wstr[MAXLINE], *cp;

   while(!Done) {
      printf("\nCommand>");
      fgets(cline, MAXLINE, stdin);
      if(sscanf(cline, "%s", wstr) != 1) continue;
      cp = wstr;
      while(*cp){
	*cp= Upcase(*cp);
	cp++;
      }
      cp = cline + strlen(wstr);
      com = READ;
      while(com < NUMFUNCS && strcmp(wstr, command[com].name)) com++;
      if(com < NUMFUNCS) {
         if(command[com].state <= Gstate) (*command[com].fptr)(cp);
         else printf("Execution out of sequence!\n");
      }
      else system(cline);
   }
}
Ejemplo n.º 5
0
void process_record(char *inseed)
{

  int i;
  time_t curr;
  FILE *outputfile;
  ITEMLIST *taglist=NULL;

  outputfile = stdout;

  if (pidfile)
    watchdog(pidfile);

  if (select_file) {
    int interesting;
    char n[10],s[10],l[10],c[10];

    SH_Get_Idents((SEED_DATA *) inseed,n,s,l,c);
    TrimString(n);
    Upcase(n);
    TrimString(s);
    Upcase(s);
    TrimString(l);
    Upcase(l);
    TrimString(c);
    Upcase(c);

    interesting = SelectDateInteresting(&dumproot,
					SH_Start_Time((SEED_DATA *) inseed),
					SH_End_Time((SEED_DATA *) inseed),
					n,s,l,c,
					&taglist);

    if (!interesting) return;

  }

  /* Are we capturing? */

  if (capture) {

    /* See if flush interval is over - if so, we start new file */

    curr = time(NULL);
    if (curr>now+flushint) {

      /* Close old file and rename it - if any */

      if (outf) {
	fclose(outf);
	
	/* mv temp name to permanent name */

	unlink(outf_dest);
	i = link(outf_name, outf_dest);
	if (i!=0) 
	  fprintf(stderr,"Couldn't link new file %s - %s\n",
		  outf_dest, strerror(errno));
	else
	  unlink(outf_name);

	outf = NULL;
      }

      /* Open new file */

      sprintf(outf_dest, capture, startint++);
      strcpy(outf_name, outf_dest);
      strcat(outf_name, "_live");

      outf = fopen(outf_name,"w");
      if (outf==NULL) {
	printf("Couldn't write file %s\n",outf_name);
	exit(20);
      }
      if (verbose) 
	fprintf(stderr,"[Open capture file %s]\n",
		outf_dest);

    now = curr; /* When did we open the file? */

    }

    outputfile = outf;

  }

  if (!extendedoutput) {
    i = write(fileno(outputfile), inseed, seed_size);
    if (i!=seed_size) {
      fprintf(stderr,"Cannot write to output\n");
      exit(30);
    }
    fflush(outputfile);
    return;
  }

}
void ShowCommands()
{
	//acciones de palabras simples
	std::string action = stackCommands.Consult().c_str();
	int i = 0;
	char result = 's';
	switch (Hashit(Upcase(action)))
	{
	case	ayuda:

			printf(HELP_LIST);
			colortext(WHITE); printf(LEAVE); colortext(LIGHTGREY); printf(HELP_LEAVE);
			colortext(WHITE); printf(OPEN_DOOR); colortext(LIGHTGREY); printf(HELP_OPEN_DOOR);
			colortext(WHITE); printf(CLEAR_SCREEN); colortext(LIGHTGREY); printf(HELP_CLEAR_SCREEN);
			colortext(WHITE); printf(PICKUP); colortext(LIGHTGREY); printf(HELP_PICKUP);
			colortext(WHITE); printf(EAST); colortext(LIGHTGREY); printf(HELP_EAST);
			colortext(WHITE); printf(PUT_IN_BAG); colortext(LIGHTGREY); printf(HELP_PUT_IN_BAG);
			colortext(WHITE); printf(INV); colortext(LIGHTGREY); printf(HELP_INV);
			colortext(WHITE); printf(LOOK); colortext(LIGHTGREY); printf(HELP_LOOK);
			colortext(WHITE); printf(NORTH); colortext(LIGHTGREY); printf(HELP_NORTH);
			colortext(WHITE); printf(WEST); colortext(LIGHTGREY); printf(HELP_WEST);
			colortext(WHITE); printf(EXITS); colortext(LIGHTGREY); printf(HELP_EXITS);
			colortext(WHITE); printf(DROP); colortext(LIGHTGREY); printf(HELP_DROP);
			colortext(WHITE); printf(GET_FROM_BAG); colortext(LIGHTGREY); printf(GET_FROM_BAG);
			colortext(WHITE); printf(SOUTH); colortext(LIGHTGREY); printf(HELP_SOUTH);
			
			break;
	case	mirar:
		NewRoom();
		break;
	case	norte:
		if (myMap.CheckN(myPlayer.GetLatitude(), myPlayer.GetLongitude()) > 0 && myMap.CheckN(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLatitude(myPlayer.GetLatitude() - 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	sur:
		if (myMap.CheckS(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckS(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLatitude(myPlayer.GetLatitude() + 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	este:
		if (myMap.CheckE(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckE(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLongitude(myPlayer.GetLongitude() + 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	oeste:

		if (myMap.CheckW(myPlayer.GetLatitude(), myPlayer.GetLongitude())> 0 && myMap.CheckW(myPlayer.GetLatitude(), myPlayer.GetLongitude()) < 100)
		{
			myPlayer.SetLongitude(myPlayer.GetLongitude() - 1);
			NewRoom();
		}
		else printf(NO_EXITS);
		break;
	case	salidas:
		myMap.ShowExits(myPlayer.GetLatitude(), myPlayer.GetLongitude());
		break;
	case	cls:
		system("cls");
		break;
	case	inventario:
		printf(INVENTORY);
		if (bag.GetState() == 's')
			printf(Show_Item(bag.GetDescription().c_str()));

		if (myPlayer.inventory.Size() > 0)
		{
				for (int i = 0; i < myPlayer.inventory.Size(); ++i)
					printf(Show_Item(myPlayer.inventory.GetDescPosN(i).c_str()));
		}
			else
				if ( bag.GetState() != 's' ) printf( NOTHING_TO_SHOW );
		break;
	default:
		result = 'n';
		break;
	}
	//acciones de 2 palabras
	action = GetWord(stackCommands.Consult().c_str());
	Item::Node *tmp;
	switch (Hashit(Upcase(action)))
	{
	case	coger:
		action = CutFirstWord(stackCommands.Consult().c_str());
		action = GetWord(action.c_str());
	
		if (action == BAG)
		{
			bag.ToInventory(myPlayer.GetLatitude(), myPlayer.GetLongitude());
		}
		else
		{
			tmp = myMap.GetFromMap(myPlayer.GetLatitude(), myPlayer.GetLongitude(), action);
			if (tmp != nullptr)
			{
				printf(Pick(action.c_str()));
				myPlayer.inventory.Push(tmp->name, tmp->description);
				if (tmp->name == "espada") // habitacion - El burladero de la esquina sur este.
				{
					colortext(YELLOW);
					printf(GAME_OVER);
					gameState = endLoop;
					return;
				}
				delete tmp;
			}
			else
			{
				printf(Not_found(action.c_str()));
			}
		}
		break;
	case	tirar:
		action = CutFirstWord(stackCommands.Consult().c_str());
		action = GetWord(action.c_str());

		if (action == BAG)
		{
			bag.DropItem(myPlayer.GetLatitude(), myPlayer.GetLongitude());
	
		}
		else
		{
			tmp = myPlayer.GetInventory(action);
			if (tmp != nullptr)
			{
				printf(Drop_Item(action.c_str()));
				myMap.DropToMap(myPlayer.GetLatitude(), myPlayer.GetLongitude(), tmp);
				delete tmp;
			}
			else
			{
				printf(Inventory_void(action.c_str()));
			}
		}
		break;
	case guardar:

		if (bag.GetState() != 's')
			printf(NO_BAG);
		else
		{
			action = CutFirstWord(stackCommands.Consult().c_str());
			action = GetWord(action.c_str());

			tmp = myPlayer.GetInventory(action);
			if (tmp != nullptr)
			{
				printf(Put_in_bag(action.c_str()));
				bag.ilist.Push(tmp->name, tmp->description);
				delete tmp;
			}
			else
			{
				if (action == BAG) printf(BAG_IN_BAG);
				else printf(Inventory_void(action.c_str()));
			}
		}
		break; case sacar:

			if (bag.GetState() != 's')
				printf(NO_BAG);
			else
			{
				action = CutFirstWord(stackCommands.Consult().c_str());
				action = GetWord(action.c_str());
				tmp = bag.GetFromContainer(action);
				if (tmp != nullptr)
				{
					printf(Pick(action.c_str()));
					myPlayer.inventory.Push(tmp->name, tmp->description);
					delete tmp;
				}
				else
				{
					printf(Not_In_bag(action.c_str()));
				}
			}
			break;
		case abrir:
			if (myPlayer.inventory.Size() > 0)
				if (myPlayer.inventory.HaveItem("llave"))
				{
					action = CutFirstWord(stackCommands.Consult().c_str());
					action = GetWord(action.c_str());
					switch ((Hashit(Upcase(action))))
					{
					case sur:
						myMap.OpenDoor(myPlayer.GetLatitude() + 1 , myPlayer.GetLongitude());
						break;
					case norte:
						myMap.OpenDoor(myPlayer.GetLatitude() - 1, myPlayer.GetLongitude());
						break;
					case este:
						myMap.OpenDoor(myPlayer.GetLatitude(), myPlayer.GetLongitude() + 1);
						break;
					case oeste:
						myMap.OpenDoor(myPlayer.GetLatitude(), myPlayer.GetLongitude() - 1);
						break;
					default:
						break;
					}
				}
				else
					printf(Inventory_void("llave"));
			else
					printf(Inventory_void("llave"));
				break;
		default:
			if (result == 'n')
				printf(NO_ACTION);
		break;
	}

	Prompt();
	stackCommands.Pop();
}
void Update(clock_t &tLast, short &charIndex, bool &newWord, char(&command)[MAX_CHARATERS_PER_LINE])
{

	command[charIndex] = GetCharacter(newWord);					//escuchamos la entrada de datos con un timeout para poder dedicar tiempo a los calculos posteriores

																//verificamos que tenemos caracter leido o nueva palabra empezada
	if (command[charIndex] != NULL || newWord != 0)
	{
		if (newWord == 0) { newWord = 1; }						//ponemos a true el boleano de palabra

																//cuando pulse enter el jugador, almacenamos la palabra en el stack y reseteamos el indice de nuestra palabra asi como el boleano 
																//en caso contrario aumentamos el indice para obtener una nueva letra

		if (command[charIndex] == '\n')
		{
			command[charIndex] = 0;
			if (charIndex > 0)					//si tan solo pulsa enter no necesitamos almacenarlo en la pila
			{
				newWord = 0;
				stackCommands.Push((std::string) command);
				command[0] = 0;
			}
			else
			{
				Prompt();
			}
			charIndex = 0;
		}
		else
		{
			++charIndex;
		}
	}

	//tratamiento acciones o comandos
	//Si la pila no esta vacia y el delay se cumple ejecutamos una nueva instruccion
	if (!stackCommands.Empty() && (clock() - tLast) > DELAY_BETWEEN_COMMANDS)
	{
		//La palabra reservada para ejecutar 'salir del juego' es especial ya que requiere de verificación. 
		if (LEAVE == Upcase(stackCommands.Consult()))
		{
			char a[MAX_CHARATERS_PER_LINE];	//para no obtener datos de la pila definios una nueva variable
			a[0] = 0;
			do				//para salir hay que verificar antes
			{
				printf(LEAVE_Q);
				scanf_s("%s", a, _countof(a));
			} while (!Compare(YES, Upcase(a)) && !Compare(NO, Upcase(a)));

			if (Compare(YES, Upcase(a)))  gameState = endLoop;
			else
			{
				Prompt();
				stackCommands.Pop();
			}
		}
		else
		ShowCommands();
		tLast = clock();
	}
}
Ejemplo n.º 8
0
Archivo: cs.c Proyecto: daoopp/mse
int cScanner::CheckLiteral(int id)
{ char c;
  c =  CurrentCh(NextSym.Pos);
  if (IgnoreCase) c = Upcase(c);
  switch (c) {
  	case 'b':
  		if (EqualStr("break")) return breakSym;
  		break;
  	case 'c':
  		if (EqualStr("class")) return classSym;
  		if (EqualStr("char")) return charSym;
  		if (EqualStr("case")) return caseSym;
  		if (EqualStr("continue")) return continueSym;
  		break;
  	case 'd':
  		if (EqualStr("double")) return doubleSym;
  		if (EqualStr("default")) return defaultSym;
  		if (EqualStr("do")) return doSym;
  		break;
  	case 'e':
  		if (EqualStr("else")) return elseSym;
  		break;
  	case 'f':
  		if (EqualStr("function")) return functionSym;
  		if (EqualStr("float")) return floatSym;
  		if (EqualStr("for")) return forSym;
  		break;
  	case 'i':
  		if (EqualStr("inherit")) return inheritSym;
  		if (EqualStr("int")) return intSym;
  		if (EqualStr("if")) return ifSym;
  		break;
  	case 'l':
  		if (EqualStr("load")) return loadSym;
  		if (EqualStr("long")) return longSym;
  		break;
  	case 'm':
  		if (EqualStr("my")) return mySym;
  		if (EqualStr("mixed")) return mixedSym;
  		break;
  	case 'n':
  		if (EqualStr("new")) return newSym;
  		break;
  	case 'o':
  		if (EqualStr("object")) return objectSym;
  		break;
  	case 'r':
  		if (EqualStr("return")) return returnSym;
  		break;
  	case 's':
  		if (EqualStr("static")) return staticSym;
  		if (EqualStr("short")) return shortSym;
  		if (EqualStr("string")) return stringSym;
  		if (EqualStr("switch")) return switchSym;
  		break;
  	case 'u':
  		if (EqualStr("use")) return useSym;
  		if (EqualStr("unsigned")) return unsignedSym;
  		break;
  	case 'v':
  		if (EqualStr("var")) return varSym;
  		if (EqualStr("void")) return voidSym;
  		break;
  	case 'w':
  		if (EqualStr("while")) return whileSym;
  		break;
  
  }
  return id;
}