Пример #1
0
bool TSIn::GetNextLn(TChA& LnChA){
  LnChA.Clr();
  while (!Eof()){
    const char Ch=GetCh();
    if (Ch=='\n'){return true;}
    if (Ch=='\r' && PeekCh()=='\n'){GetCh(); return true;}
    LnChA.AddCh(Ch);
  }
  return !LnChA.Empty();
}
Пример #2
0
Файл: SUB.C Проект: BigEd/Cores
void SearchForDefined()
{
   char *ptr, *id, *sptr;
   int c;
   SDef tdef, *p;

   ptr = inptr;
   while(1)
   {
      if (PeekCh() == 0)   // Stop at end of current input
         break;
      SkipSpaces();
      sptr = inptr;
      id = GetIdentifier();
      if (id)
      {
         if (strcmp(id, "defined") == 0)
         {
            c = NextNonSpace(0);
            if (c != '(') {
               err(20);
               break;
            }
            id = GetIdentifier();
            if (id == NULL) {
               err(21);
               break;
            }
            c = NextNonSpace(0);
            if (c != ')')
               err(22);
            tdef.name = id;
            p = (SDef *)htFind(&HashInfo, &tdef);
            SubMacro((char *)(p ? "1" : "0"), inptr-sptr);
         }
      }
      else
         NextCh();
   }
   inptr = ptr;
}
Пример #3
0
static int ProgramMode(int adx, int argc, FChS * argv[])
{
    FAssert(adx < argc);

    FObject nam = MakeStringS(argv[adx]);

    adx += 1;
    R.CommandLine = MakePair(MakeInvocation(adx, argv), MakeCommandLine(argc - adx, argv + adx));

    FObject port;
    {
        FDontWait dw;

        port = OpenInputFile(nam);
        if (TextualPortP(port) == 0)
        {
#ifdef FOMENT_WINDOWS
            printf("error: unable to open program: %S\n", argv[adx - 1]);
#endif // FOMENT_WINDOWS

#ifdef FOMENT_UNIX
            printf("error: unable to open program: %s\n", argv[adx - 1]);
#endif // FOMENT_UNIX
            return(Usage());
        }
    }

    FCh ch;

    // Skip #!/usr/local/bin/foment

    if (PeekCh(port, &ch) && ch == '#')
        ReadLine(port);

    FObject proc = CompileProgram(nam, port);

    ExecuteThunk(proc);
    ExitFoment();
    return(0);
}
Пример #4
0
Файл: SUB.C Проект: BigEd/Cores
void SearchAndSub()
{
	static int InComment = 0;
   int c, InComment2 = 0;
   int QuoteToggle = 0;
   char *id, *ptr, *optr;
   SDef *p, tdef;

   // Check if we hit the end of the current input line we do this because
   // NextCh would read another line

   optr = inptr;
   while (1)
   {
      if ((c = PeekCh()) == 0)
         break;

      if (c == '\n') {
         c = NextCh();
         QuoteToggle = 0;     // Quotes cannot cross newlines
         InComment2 = 0;
         continue;
      }

      if (c == '/' && *(inptr+1) == '/') {
         InComment2 = 1;
         inptr += 2;
         continue;
      }

      if (c == '/' && *(inptr+1) == '*') {
         InComment = 1;
         inptr += 2;
         continue;
      }

      if (c == '*' && *(inptr+1) == '/') {
         InComment = 0;
         inptr += 2;
         continue;
      }

      if (InComment || InComment2) {
         c = NextCh();
         continue;
      }

      if (c == '"') {         // Toggle quotation mode
         c = NextCh();
         QuoteToggle = !QuoteToggle;
         continue;
      }

      if (QuoteToggle) {      // Just keep getting characters as long as
         c = NextCh();        // we're inside quotes
         continue;         
      }

      ptr = inptr;            // record the position of the input pointer
      id = GetIdentifier();   // try and get an identifier

	  if (id)
      {
         tdef.name = _strdup(id);
         if (tdef.name == NULL)
            err(5);

		 // Search and see if the identifier corresponds to a macro
		 p = (SDef *)htFind(&HashInfo, &tdef);
         if (p != (SDef *)NULL)
         {
			 if (fdbg) fprintf(fdbg, "macro %s\r\n", p->name);
            //    If this isn't a macro with parameters, then just copy
            // the body directly to the input. Overwrite the identifier
            // string
			 if (p->nArgs >= 0) {
				 if (fdbg) fprintf(fdbg, "bef:%s", inbuf);
                 SubParmMacro(p);
				 if (fdbg) fprintf(fdbg, "aft:%s", inbuf);
			 }
			else {
                SubMacro(p->body, strlen(p->name));
			}
         }
         free(tdef.name);
         continue;
         // the identifier wasn't a macro so just let it be
      }
      // failed to get identifier, so just continue with the next character
      c = NextCh();
   }
   inptr = optr;
}