示例#1
0
bool FortranFormat::ProcessToken(String & field)
   {
   // This flag only gets set if we encounter the final bracket or a ':'
   endOfPattern = false;

   // Read input from file, if appropriate
   if (inputPos == -1)
      {
      inputLine.ReadLine(input);
      inputPos = 0;
      }

   // First read repeat count specifier
   if (repeatCount == 0)
      repeatCount = GetIntegerFromFormat();

   // By default, the repeat count should be 1
   if (repeatCount == 0)
      repeatCount = 1;

   int repeatPos = formatPos;

   // Check if this is a new bracketed grouping
   if (format[formatPos] == '(')
      {
      formatPos++;

      bracketStack.Push(formatPos);
      bracketCounter.Push(repeatCount);
      bracketCount.Push(repeatCount);

      repeatCount = 0;

      return false;
      }

   // Check if this an 'X' field
   if (format[formatPos] == 'X')
      {
      formatPos++;

      // No width specifier allowed for these fields
      RejectWidth('X');

      // Skip appropriate number of characters
      inputPos += repeatCount;

      // Reset repeat count
      repeatCount = 0;

      FinishField();

      return false;
      }

   // Check if this is a '/' (vertical tab field)
   if (format[formatPos] == '/')
      {
      formatPos++;

      // No width specifier allowed for these fields
      RejectWidth('/');

      // Skip the appropriate number of lines
      while (repeatCount--)
         inputLine.ReadLine(input);

      inputPos = 0;

      // Separators are optional, so we might already be at the next field
      if (format[formatPos] == ',' || format[formatPos] || ')')
         FinishField();

      return false;
      }

   // Check that we haven't encountered a rare, but unsupported input type
   if (format[formatPos] == 'Q' || format[formatPos] == 'P' || format[formatPos] == 'B')
      {
      formatPos++;

      int problemStart = formatPos;

      while (format[formatPos] != ',' && format[formatPos] != ')' && format[formatPos] != '/')
         formatPos++;

      error("Unsupported pattern in FORMAT statement\n\n"
            "Statement \"%s\" includes unsupporterd pattern '%s'\n",
            (const char *) format,
            (const char *) format.SubStr(problemStart, formatPos - problemStart));
      }

   if (format[formatPos] == ':')
      {
      formatPos++;

      if (format[formatPos] == ',' || format[formatPos] || ')')
         FinishField();

      repeatCount = 0;

      endOfPattern = true;

      return false;
      }

   // All the other types we recognize include a width specifier

   // Identify the location of the type specifier
   int typeStart = formatPos;

   while (CharacterFollows())
      formatPos++;

   int typeLen = formatPos - typeStart;

   // Retrieve the field width
   int width = GetIntegerFromFormat();

   if (width == 0)
      error("Unrecognized FORMAT statement\n\n"
            "Statement \"%s\" is missing a width specifier for a field of type '%s'\n",
            (const char *) format, (const char *) format.SubStr(typeStart, typeLen));

   // Check for horizontal tab character
   if (format[typeStart] == 'T')
      {
      // Move left by a specified number of characters
      if (format[typeStart + 1] == 'L')
         inputPos = width > inputPos ? 0 : inputPos - width;
      // Move right by a specified number of characters
      else if (format[typeStart + 1] == 'R')
         inputPos += width;
      // Or simply set the appropriate horizontal position
      else
         inputPos = width;

      repeatCount--;

      if (repeatCount)
         formatPos = repeatPos;
      else
         FinishField();

      return false;
      }

   // Assume that if we got here, we are looking at a data field!
   field.Copy(inputLine, inputPos, width);
   field.Trim();

   inputPos += width;

   repeatCount--;

   if (repeatCount)
      formatPos = repeatPos;
   else
      FinishField();

   return true;
   }
示例#2
0
void FortranFormat::FinishField(bool )
   {
   // Find the next field separator
   while (format[formatPos] != ',' && format[formatPos] != ')')
      {
      if (format[formatPos] == '/')
         return;

      formatPos++;
      }

   // Skip commas
   if (format[formatPos] == ',')
      {
      formatPos++;
      return;
      }

   // If we found a bracket, then it is either the end of the statement
   // (if bracketStack is empty) or we finish an internal grouping
   if (bracketStack.Length())
      {
      // Retrieve information about this grouping
      lastBracket = bracketStack.Pop();
      lastCount = bracketCount.Pop();
      int lastCounter = bracketCounter.Pop() - 1;

      // Loop if required
      if (lastCounter)
         {
         bracketStack.Push(lastBracket);
         bracketCount.Push(lastCount);
         bracketCounter.Push(lastCounter);

         formatPos = lastBracket;
         }
      else
      // Otherwise find the next separator
         {
         formatPos++;
         FinishField();
         return;
         }
      }
   else
      {
      // If we finished the input line, then activate reset input counter
      inputPos = -1;
      endOfPattern = true;

      // And re-use input tokens starting at the last bracket
      formatPos = lastBracket;

      if (lastBracket == 1)
         return;

      // With appropriate repeat counts
      bracketStack.Push(lastBracket);
      bracketCounter.Push(lastCount);
      bracketCount.Push(lastCount);
      }
   }
示例#3
0
/* ARGSUSED */
static void
InsertChar (
    Widget	ctxw,
    XEvent	*event,
    String	*params,
    Cardinal	*num_params)
{
    LoginWidget ctx = (LoginWidget)ctxw;

    char strbuf[128];
#ifndef XPM
    int  len;
#else
    int  len,pixels;
#endif /* XPM */
    KeySym  keysym = 0;

    if (ctx->login.xic) {
	static Status status;
	len = XmbLookupString(ctx->login.xic, &event->xkey, strbuf,
			      sizeof (strbuf), &keysym, &status);
    } else {
	static XComposeStatus compose_status = {NULL, 0};
	len = XLookupString (&event->xkey, strbuf, sizeof (strbuf),
			     &keysym, &compose_status);
    }
    strbuf[len] = '\0';

#ifdef XPM
    pixels = 3 + ctx->login.font->max_bounds.width * len +
    	     XTextWidth(ctx->login.font,
    	     		ctx->login.data.name,
    	     		strlen(ctx->login.data.name));
    	     	/* pixels to be added */
#endif /* XPM */

    /*
     * Note: You can override this default key handling
     * by the settings in the translation table
     * loginActionsTable at the end of this file.
     */
    switch (keysym) {
    case XK_Return:
    case XK_KP_Enter:
    case XK_Linefeed:
    case XK_Execute:
	FinishField(ctxw, event, params, num_params);
	return;
    case XK_BackSpace:
	DeleteBackwardChar(ctxw, event, params, num_params);
	return;
    case XK_Delete:
    case XK_KP_Delete:
    case DXK_Remove:
	/* Sorry, it's not a telex machine, it's a terminal */
	DeleteForwardChar(ctxw, event, params, num_params);
	return;
    case XK_Left:
    case XK_KP_Left:
	MoveBackwardChar(ctxw, event, params, num_params);
	return;
    case XK_Right:
    case XK_KP_Right:
	MoveForwardChar(ctxw, event, params, num_params);
	return;
    case XK_End:
    case XK_KP_End:
	MoveToEnd(ctxw, event, params, num_params);
	return;
    case XK_Home:
    case XK_KP_Home:
	MoveToBegining(ctxw, event, params, num_params);
	return;
    default:
	if (len == 0) {
	    if (!IsModifierKey(keysym))  /* it's not a modifier */
		XBell(XtDisplay(ctxw), 60);
	    return;
	} else
	    break;
    }

    switch (ctx->login.state) {
    case GET_NAME:
#ifndef XPM
	if (len + (int)strlen(ctx->login.data.name) >= NAME_LEN - 1)
#else
	if (
	        (len + (int)strlen(ctx->login.data.name) >= NAME_LEN - 1)/* &&
		(pixels <= LOGIN_W(ctx) - PROMPT_W(ctx))*/
	   )
#endif /* XPM */
	    len = NAME_LEN - strlen(ctx->login.data.name) - 2;
    case GET_PASSWD:
	if (len + (int)strlen(ctx->login.data.passwd) >= PASSWORD_LEN - 1)
	    len = PASSWORD_LEN - strlen(ctx->login.data.passwd) - 2;
    }
#ifndef XPM
    if (len == 0)
#else
    if (len == 0 || pixels >= LOGIN_W(ctx) - PROMPT_W(ctx))
#endif /* XPM */
	return;
    XorCursor (ctx);
    RemoveFail (ctx);
    switch (ctx->login.state) {
    case GET_NAME:
	EraseName (ctx, ctx->login.cursor);
	memmove( ctx->login.data.name + ctx->login.cursor + len,
	       ctx->login.data.name + ctx->login.cursor,
	       strlen (ctx->login.data.name + ctx->login.cursor) + 1);
	memmove( ctx->login.data.name + ctx->login.cursor, strbuf, len);
	DrawName (ctx, ctx->login.cursor);
	ctx->login.cursor += len;
	break;
    case GET_PASSWD:
	memmove( ctx->login.data.passwd + ctx->login.cursor + len,
	       ctx->login.data.passwd + ctx->login.cursor,
	       strlen (ctx->login.data.passwd + ctx->login.cursor) + 1);
	memmove( ctx->login.data.passwd + ctx->login.cursor, strbuf, len);
	ctx->login.cursor += len;

#ifdef XPM
	/*as good a place as any Caolan begin*/
	ctx->login.lastEventTime = time(NULL);
	/*as good a place as any Caolan end*/
#endif /* XPM */
	break;
    }
    XorCursor (ctx);
}