Esempio n. 1
0
bool CScanner::NextToken()
{
	SkipWhiteSpace();
	if (ErrorString != "")
		return false;
// 	if (Pos >= SourceLength)
// 		return false;
	_off_t OldPos = Pos;
	char c = cget();
	if (isdigit(c) || // Thinks a little, while reading this condition, it might be a bit unreadable.
			(
				(
					c == '.' && 
					(
						(IncPos(), isdigit(cget())) || (DecPos(), false)				
					)
				) &&
				(DecPos(), true)
			)
		)
		return ParseNumber() && OldPos != Pos;
	else if (isalpha(c) || c == '_')
		return ParseIdentifier() && OldPos != Pos;
	else if (MatchPrefix("'"))
		return ParseCharacterLiteral() && OldPos != Pos;
	else if (MatchPrefix("\""))
		return ParseStringLiteral() && OldPos != Pos;
	else if (SymbolicTokenMapping.find(string() += c))
		return ParseSymbol() && OldPos != Pos;
	else if (c == 0)
		return true;
	else
		ErrorString = "Unrecognized character at line: ";// + itoa(CurrentLine) + ", Column: " + itoa(CurrentColumn);
	return false;
}
Esempio n. 2
0
bool CScanner::ParseNumber()
{
	UpdateCurrentToken();
	string TempString = "";
	while (isalnum(cget()) || cget() == '.' || cget() == '+' || cget() == '-')
		TempString += cget(), IncPos();
	string ClearString = "uUlL";
	if	(
			TempString[1] != 'x' && TempString[1] != 'X'
// 			TempString.find('e') != string::npos ||
// 			TempString.find('E') != string::npos || 
// 			TempString.find('.') != string::npos ||
			
		)
		ClearString += "fF";
	while (ClearString.find(TempString[TempString.length() - 1]) != string::npos)
		TempString.erase(TempString.length()- 1);
	
	CurrentToken.Kind = DTM_TOKEN::LITERAL::NUMBER::INTEGER;
	if (TempString[1] == 'x' || TempString[1] == 'X')
		try
		{
			CurrentToken.Value = FromHexadecimalString(TempString);
			return true;
		}
		catch (...)
		{
			ErrorString = "Bad hexadecimal integral literal.";
			return false;
		}

	try
	{
		CurrentToken.Value = lexical_cast<int>(TempString);
		return true;
	}
	catch (...)
	{
	}

	try
	{
		CurrentToken.Value = lexical_cast<float>(TempString);
		CurrentToken.Kind = DTM_TOKEN::LITERAL::NUMBER::FLOAT;
		return true;
	}
	catch (...)
	{
		ErrorString = "Bad number literal.";
	}

	return true;
}
Esempio n. 3
0
bool CScanner::ParseIdentifier()
{
	UpdateCurrentToken();
	string TempString = "";
	while (isalnum(cget()) || cget() == '_')
		TempString += cget(), IncPos();
	if (isKeyword(TempString))
		CurrentToken.Kind = GetKeywordKind(TempString);
	else
		CurrentToken.Kind = DTM_TOKEN::IDENTIFIER;
	CurrentToken.Value = TempString;
	return true;
}
Esempio n. 4
0
bool CScanner::ParseSymbol()
{
	string TempString = "";
	UpdateCurrentToken();	
	while (isSymbol(cget()) && TempString.length() < 3)
		TempString += cget(), IncPos();
	while(!SymbolicTokenMapping.find(TempString))
	{
		TempString.erase(TempString.end() - 1), DecPos();
	}
	CurrentToken.Kind = SymbolicTokenMapping[TempString];
	CurrentToken.Value.reset();
	CurrentToken.Value = TempString;
	return true;
}
Esempio n. 5
0
sget (struct get_fnct *get, char *s)
{
int c;
	for (;;)
	{
		c = cget (get);
		if (c == EOF || c == '\n')
			break;
		*s++ = c;
	}
	*s = 0;
}
Esempio n. 6
0
bool CScanner::ParseStringLiteral()
{
	UpdateCurrentToken();
	string TempString = "";
	while (cget() != '"' && cget() != 0)
	{
		if (isNewline())
		{
			ErrorString = "Newline in string literal.";
			return false;
		}
		if (cget() == '\\')
		{
			IncPos();
			if (cget() == 'x')
			{
				IncPos();
				string VeryTempString = "x";
				while(isxdigit(cget()))
					VeryTempString += cget(), IncPos();
				try
				{
					TempString += EscapeSequenceToValue(VeryTempString);
					continue;
				}
				catch (positive_overflow &e)
				{
					ErrorString = "Hexadecimal constant is invalid (may be too large for character).";
					return false;
				}
			}
			else
			{
				TempString += EscapeSequenceToValue(string() += cget());
				IncPos();
				continue;
			}
		}
		TempString += cget();
		IncPos();
	}
	IncPos();
	CurrentToken.Kind = DTM_TOKEN::LITERAL::STRING;
	CurrentToken.Value = TempString;
	return true;
}
Esempio n. 7
0
/*
 * scan_white -- scan white space from input stream
 */
static int scan_white( PTR_SCNF_SPECS specs )
{
    int     c, len;

    len = 0;
    for( ;; ) {
        c = cget( specs );
        if( !__F_NAME(isspace,iswspace)( c ) )
            break;
        ++len;
    }
    if( !specs->eoinp )
        uncget( c, specs );
    return( len );
}
Esempio n. 8
0
bool CScanner::SkipWhiteSpace()
{
	enum EScannerState
	{
		SEARCH_FOR_WHITE_SPACE,
		NEXT_TOKEN,
		BEGIN_COMMENT,
		C_COMMENT_BODY,
		CPP_COMMENT_BODY,
		CPP_COMMENT_GOING_NEWLINE,
		PREPARE_TO_EXIT_C_COMMENT_BLOCK,
		PREPARE_TO_EXIT_CPP_COMMENT_BLOCK,
		BEGIN_PP,
		PP_GOING_NEW_LINE,	
		BEGIN_SYMBOL,
		BEGIN_IDENTIFIER,
		BEGIN_NUMBER,
		END_SCAN,
	};
	char c;
	EScannerState State = SEARCH_FOR_WHITE_SPACE;
	while (cget() != 0)
	{
		c = cget();
		if (c == '\n')
			IncLineCounter();
		switch (State)
		{
		case SEARCH_FOR_WHITE_SPACE:
			switch(c)
			{
			case '\t': case'\n': case '\v': case '\r': case ' ': case '\f':
				break;
			case '/':
				State = BEGIN_COMMENT;
				break;
			case '#':
				State = BEGIN_PP;
				break;
			default:
				return true;
			}
			break;
		case BEGIN_COMMENT:
			if (c == '*')
				State = C_COMMENT_BODY;
			else if (c == '/')
				State = CPP_COMMENT_BODY;
			else
			{
				State = BEGIN_SYMBOL;
				Pos--;
				return true;
			}
			break;
		case C_COMMENT_BODY:
			if (c != '*')
				break;
			else
				State = PREPARE_TO_EXIT_C_COMMENT_BLOCK;
			break;
		case PREPARE_TO_EXIT_C_COMMENT_BLOCK:
			switch (c)
			{
			case '*':
				break;
			case '/':
				State = SEARCH_FOR_WHITE_SPACE;				
				break;
			default:
				State = C_COMMENT_BODY;
				break;
			}
			break;
		case CPP_COMMENT_BODY:
			if (c == '\\')
				State = CPP_COMMENT_GOING_NEWLINE;
			else if (c != '\r' && c != '\n')
				break;
			else if (c == '\n')
				State = SEARCH_FOR_WHITE_SPACE;
			break;
		case CPP_COMMENT_GOING_NEWLINE:
			if (c == '\r' || c == '\\')
				break;
			State = CPP_COMMENT_BODY;
			break;
		case BEGIN_PP:
			switch(c)
			{
			case '\\':
				State = PP_GOING_NEW_LINE;
				break;
			case '\n':
				State = SEARCH_FOR_WHITE_SPACE;
				break;
			default:
				break;
			}
			break;
		case PP_GOING_NEW_LINE:
			if (c == '\r' || c == '\\')
				break;
			State = BEGIN_PP;
			break;
		default:
			assert(false);
			break;
		}
		IncPos();
	}
	if (State == C_COMMENT_BODY || State == PREPARE_TO_EXIT_C_COMMENT_BLOCK)
	{
		ErrorString = "Unclosed multi-line comment.";
		return false;
	}
	return true;
}
Esempio n. 9
0
File: combo.c Progetto: zdia/gnocl
static int comboFunc ( ClientData data, Tcl_Interp *interp,
					   int objc, Tcl_Obj * const objv[] )
{
	static const char *cmds[] = { "delete", "configure", "cget",
								  "onChanged", NULL
								};
	enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx,
				  OnChangedIdx
				};

	ComboParams *para = ( ComboParams * ) data;
	GtkWidget *widget = GTK_WIDGET ( para->combo );
	int idx;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "command" );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command",
							   TCL_EXACT, &idx ) != TCL_OK )
		return TCL_ERROR;

	switch ( idx )
	{
		case DeleteIdx:
			return gnoclDelete ( interp, widget, objc, objv );

		case ConfigureIdx:
			{
				int ret = TCL_ERROR;

				if ( gnoclParseAndSetOptions ( interp, objc - 1, objv + 1,
											   comboOptions, G_OBJECT ( widget ) ) == TCL_OK )
				{
					ret = configure ( interp, para, comboOptions );
				}

				gnoclClearOptions ( comboOptions );

				return ret;
			}

			break;

		case CgetIdx:
			{
				int     idx;

				switch ( gnoclCget ( interp, objc, objv, G_OBJECT ( para->combo ),
									 comboOptions, &idx ) )
				{
					case GNOCL_CGET_ERROR:
						return TCL_ERROR;
					case GNOCL_CGET_HANDLED:
						return TCL_OK;
					case GNOCL_CGET_NOTHANDLED:
						return cget ( interp, para, comboOptions, idx );
				}
			}

		case OnChangedIdx:
			{
				GtkEntry *entry = GTK_ENTRY ( para->combo->entry );
				const char *txt = gtk_entry_get_text ( entry );

				if ( objc != 2 )
				{
					Tcl_WrongNumArgs ( interp, 2, objv, NULL );
					return TCL_ERROR;
				}

				return doCommand ( para, txt, 0 );
			}
	}

	return TCL_OK;
}
Esempio n. 10
0
File: entry.c Progetto: zdia/gnocl
/**
\brief
    Function associated with the widget.
*/
int entryFunc (
	ClientData data,
	Tcl_Interp *interp,
	int objc,
	Tcl_Obj * const objv[] )
{

#ifdef DEBUG_ENTRY  g_print ( "entryFunc\n" );
#endif


	static const char *cmds[] = { "delete", "configure", "cget", "onChanged", "class", "get", "clear", "set",  "setPosition", NULL };
	enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, OnChangedIdx, ClassIdx, GetIdx, ClearIdx, SetIdx, SetPositionIdx };

	EntryParams *para = ( EntryParams * ) data;
	//GtkWidget *widget = GTK_WIDGET ( para->entry );

	int idx;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "command" );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command",
							   TCL_EXACT, &idx ) != TCL_OK )
		return TCL_ERROR;

	switch ( idx )
	{
		case SetPositionIdx:
			{


				if ( 1 )
				{
					gtk_entry_set_position ( GTK_WIDGET ( para->entry ) , Tcl_GetString ( objv[2] ) );
				}

				else
				{
					gtk_editable_set_position ( GTK_EDITABLE ( GTK_WIDGET ( para->entry ) ) , Tcl_GetString ( objv[2] ) );
				}
			}

			break;
		case SetIdx:
			{
				/* simply set the text to nothing */
				gtk_entry_set_text ( para->entry, Tcl_GetString ( objv[2] ) );
			}

			break;
		case GetIdx:
			{
				/* equivalent to widget cget -value */
				Tcl_Obj *obj = NULL;

				obj = Tcl_NewStringObj ( gtk_entry_get_text ( para->entry  ), -1 );

				if ( obj != NULL )
				{
					Tcl_SetObjResult ( interp, obj );
					return TCL_OK;
				}
			}

			break;
		case ClearIdx:
			{
				/* simply set the text to nothing */
				gtk_entry_set_text ( para->entry, "" );
			}

			break;
		case ClassIdx:
			{

				Tcl_SetObjResult ( interp, Tcl_NewStringObj ( "entry", -1 ) );
			}
			break;
		case DeleteIdx:
			{
				return gnoclDelete ( interp, GTK_WIDGET ( para->entry ), objc, objv );
			}
		case ConfigureIdx:
			{
#ifdef DEBUG_ENTRY
				g_print ( "entryFunc ConfigureIdx\n" );
#endif
				int ret = TCL_ERROR;

				if ( gnoclParseAndSetOptions ( interp, objc - 1, objv + 1,
											   entryOptions, G_OBJECT ( para->entry ) ) == TCL_OK )
				{
					ret = configure ( interp, para, entryOptions );
				}

				gnoclClearOptions ( entryOptions );

				return ret;
			}

			break;

		case CgetIdx:
			{
				int     idx;

				switch ( gnoclCget ( interp, objc, objv, G_OBJECT ( para->entry ), entryOptions, &idx ) )
				{
					case GNOCL_CGET_ERROR:
						return TCL_ERROR;
					case GNOCL_CGET_HANDLED:
						return TCL_OK;
					case GNOCL_CGET_NOTHANDLED:
						return cget ( interp, para, entryOptions, idx );
				}
			}

		case OnChangedIdx:
			{
				const char *txt = gtk_entry_get_text ( para->entry );

				if ( objc != 2 )
				{
					Tcl_WrongNumArgs ( interp, 2, objv, NULL );
					return TCL_ERROR;
				}

				return doCommand ( para, txt, 0 );
			}
	}

	return TCL_OK;
}
Esempio n. 11
0
/****f* widget/linkButtonFunc
 * AUTHOR
 *  PGB
 * SOURCE
 */
int linkButtonFunc ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	static const char *cmds[] = { "delete", "configure", "cget", "onClicked", "class", NULL };
	enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, OnClickedIdx, ClassIdx };
#ifdef DEBUG
	printf ( "linkButtonFunc 1\n" );
#endif
	GtkWidget *button = GTK_LINK_BUTTON ( data );
#ifdef DEBUG
	printf ( "linkButtonFunc 2\n" );
#endif
	int idx;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "command" );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command",
							   TCL_EXACT, &idx ) != TCL_OK )
		return TCL_ERROR;

	switch ( idx )
	{
		case ClassIdx:
			Tcl_SetObjResult ( interp, Tcl_NewStringObj ( "linkButton", -1 ) );
			break;
		case DeleteIdx:
			{
				return gnoclDelete ( interp, GTK_WIDGET ( button ), objc, objv );
			}

		case ConfigureIdx:
			{
#ifdef DEBUG
				printf ( "linkButtonFunc ConfigureIdx\n" );
#endif
				int ret = TCL_ERROR;

				if ( gnoclParseAndSetOptions ( interp, objc - 1, objv + 1, linkButtonOptions, button ) == TCL_OK )
				{
					ret = configure ( interp, button, linkButtonOptions );
				}

				gnoclClearOptions ( linkButtonOptions );

				return ret;
			}

			break;
		case OnClickedIdx:

			if ( objc != 2 )
			{
				Tcl_WrongNumArgs ( interp, 2, objv, NULL );
				return TCL_ERROR;
			}

			if ( GTK_WIDGET_IS_SENSITIVE ( GTK_WIDGET ( button ) ) )
			{
				gtk_button_clicked ( button );
			}

			break;

		case CgetIdx:
			{
				int     idx;

				switch ( gnoclCget ( interp, objc, objv, G_OBJECT ( button ), linkButtonOptions, &idx ) )
				{
					case GNOCL_CGET_ERROR:
						return TCL_ERROR;
					case GNOCL_CGET_HANDLED:
						return TCL_OK;
					case GNOCL_CGET_NOTHANDLED:
						return cget ( interp, button, linkButtonOptions, idx );
				}
			}
	}

	return TCL_OK;
}
Esempio n. 12
0
File: cpp4.c Progetto: Akaito/bgfx
INLINE FILE_LOCAL
ReturnCode expcollect(struct Global *global)
{
  /*
   * Collect the actual parameters for this macro.
   */

  int c;
  int paren;		    /* For embedded ()'s    */
  ReturnCode ret;
      
  for (;;) {
    paren = 0;			    /* Collect next arg.    */
    while ((c = skipws(global)) == '\n')/* Skip over whitespace */
      global->wrongline = TRUE;		/* and newlines.	*/
    if (c == ')') {                     /* At end of all args?  */
      /*
       * Note that there is a guard byte in parm[]
       * so we don't have to check for overflow here.
       */
      *global->parmp = EOS;	    /* Make sure terminated */
      break;			    /* Exit collection loop */
    }
    else if (global->nargs >= LASTPARM) {
      cfatal(global, FATAL_TOO_MANY_ARGUMENTS_EXPANSION);
      return(FPP_TOO_MANY_ARGUMENTS);
    }
    global->parlist[global->nargs++] = global->parmp; /* At start of new arg */
    for (;; c = cget(global)) {               /* Collect arg's bytes  */
      if (c == EOF_CHAR) {
	cerror(global, ERROR_EOF_IN_ARGUMENT);
	return(FPP_EOF_IN_MACRO); /* Sorry.               */
      }
      else if (c == '\\') {             /* Quote next character */
	charput(global, c);             /* Save the \ for later */
	charput(global, cget(global));  /* Save the next char.  */
	continue;			/* And go get another   */
      }
      else if (type[c] == QUO) {        /* Start of string?     */
	ret=scanstring(global, c, (ReturnCode (*)(struct Global *, int))charput); /* Scan it off    */
	if(ret)
	  return(ret);
	continue;			    /* Go get next char     */
      }
      else if (c == '(')                /* Worry about balance  */
	paren++;			/* To know about commas */
      else if (c == ')') {              /* Other side too       */
	if (paren == 0) {               /* At the end?          */
	  unget(global);                /* Look at it later     */
	  break;			/* Exit arg getter.     */
	}
	paren--;			/* More to come.        */
      }
      else if (c == ',' && paren == 0)  /* Comma delimits args  */
	break;
      else if (c == '\n')               /* Newline inside arg?  */
	global->wrongline = TRUE;	/* We'll need a #line   */
      charput(global, c);               /* Store this one       */
    }				        /* Collect an argument  */
    charput(global, EOS);               /* Terminate argument   */
  }				        /* Collect all args.    */
  return(FPP_OK);                       /* Normal return        */
}
Esempio n. 13
0
/*
 * Collect the actual parameters for this macro.  TRUE if ok.
 */
FILE_LOCAL int expcollect()
{
    int c;
    int paren;                  /* For embedded ()'s    */
    for (;;)
    {
        paren = 0;                          /* Collect next arg.    */
        while ((c = skipws()) == '\n')      /* Skip over whitespace */
            wrongline = TRUE;               /* and newlines.        */
        if (c == ')')                       /* At end of all args?  */
        {
            /*
             * Note that there is a guard byte in parm[]
             * so we don't have to check for overflow here.
             */
            *parmp = EOS;                   /* Make sure terminated */
            break;                          /* Exit collection loop */
        }
        else if (nargs >= LASTPARM)
            cfatal("Too many arguments in macro expansion", NULLST);
        parlist[nargs++] = parmp;           /* At start of new arg  */
        for (;; c = cget())                 /* Collect arg's bytes  */
        {
            if (c == EOF_CHAR)
            {
                cerror("end of file within macro argument", NULLST);
                return FALSE;             /* Sorry.               */
            }
            else if (c == '\\')             /* Quote next character */
            {
                charput(c);                 /* Save the \ for later */
                charput(cget());            /* Save the next char.  */
                continue;                   /* And go get another   */
            }
            else if (type[c] == QUO)        /* Start of string?     */
            {
                scanstring(c, charput);     /* Scan it off          */
                continue;                   /* Go get next char     */
            }
            else if (c == '(')              /* Worry about balance  */
                paren++;                    /* To know about commas */
            else if (c == ')')              /* Other side too       */
            {
                if (paren == 0)             /* At the end?          */
                {
                    unget();                /* Look at it later     */
                    break;                  /* Exit arg getter.     */
                }
                paren--;                    /* More to come.        */
            }
            else if (c == ',' && paren == 0) /* Comma delimits args */
                break;
            else if (c == '\n')             /* Newline inside arg?  */
                wrongline = TRUE;           /* We'll need a #line   */
            charput(c);                     /* Store this one       */
        }                                   /* Collect an argument  */
        charput(EOS);                       /* Terminate argument   */
#if OSL_DEBUG_LEVEL > 1
        if (debug)
            fprintf( pCppOut, "parm[%d] = \"%s\"\n", nargs, parlist[nargs - 1]);
#endif
    }                                       /* Collect all args.    */
    return TRUE;                            /* Normal return        */
}
Esempio n. 14
0
static int canvasFunc( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   const char *cmds[] = { "delete", "configure", "cget", "isMapped",
         "getCurrentSize", "update", "raise", "lower", 
         "create", "itemDelete", "itemShow",
         "itemConfigure", "itemCget", "itemCommand", 
         "affine", "scale", "move", "rotate",
         "windowToCanvas", "canvasToWindow",
         "findItemAt", "getBounds", "findWithTag",
         NULL };
   enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, IsMappedIdx,
         GetCurSizeIdx, UpdateIdx, RaiseIdx, LowerIdx,
         CreateIdx, ItemDeleteIdx, ItemShowIdx,
         ItemConfigureIdx, ItemCgetIdx, ItemCommandIdx, 
         AffineIdx, ScaleIdx, MoveIdx, RotateIdx,
         WindowToCanvasIdx, CanvasToWindowIdx,
         FindItemAtIdx, GetBoundsIdx, GetIDsFromTagIdx };
   CanvasParams *para = (CanvasParams *)data;
   GtkWidget    *widget = GTK_WIDGET( para->canvas );
   int idx;

   if( objc < 2 )
   {
      Tcl_WrongNumArgs( interp, 1, objv, "command" );
      return TCL_ERROR;
   }

   if( Tcl_GetIndexFromObj( interp, objv[1], cmds, "command", 
         TCL_EXACT, &idx ) != TCL_OK )
      return TCL_ERROR;

   switch( idx )
   {
      case DeleteIdx:
            return gnoclDelete( interp, widget, objc, objv );

      case ConfigureIdx:
            {
               int ret = TCL_ERROR;
               if( gnoclParseAndSetOptions( interp, objc - 1, objv + 1, 
                     canvasOptions, G_OBJECT( widget ) ) == TCL_OK )
               {

                  if( canvasOptions[antialiasedIdx].status 
                        == GNOCL_STATUS_CHANGED )
                  {
                     Tcl_SetResult( interp, "antialiasing cannot be changed "
                           "after creation", TCL_STATIC );
                  }
                  else
                     ret = configure( interp, para, canvasOptions );
               }
               gnoclClearOptions( canvasOptions );
               return ret;
            }
            break;
      case CgetIdx:
            {
               int     idx;
               switch( gnoclCget( interp, objc, objv, G_OBJECT( widget ), 
                     canvasOptions, &idx ) )
               {
                  case GNOCL_CGET_ERROR:  
                           return TCL_ERROR;
                  case GNOCL_CGET_HANDLED:
                           return TCL_OK;
                  case GNOCL_CGET_NOTHANDLED:
                           return cget( interp, para->canvas, 
                                 canvasOptions, idx );
               }
               break;
            }
      case IsMappedIdx:
            return isMapped( interp, widget, objc, objv );
      case GetCurSizeIdx:
            return getCurSize( interp, widget, objc, objv );
      case UpdateIdx:
            if( objc != 2 )
            {
               Tcl_WrongNumArgs( interp, 2, objv, NULL );
               return TCL_ERROR;
            }
            gnome_canvas_update_now( para->canvas );
            break;
      case CreateIdx:
            return canvasCreateItem( interp, objc, objv, para );
      case RaiseIdx:
      case LowerIdx:
      case ItemDeleteIdx:
      case ItemShowIdx:
      case ItemConfigureIdx:
      case ItemCgetIdx:
      case ItemCommandIdx:
      case AffineIdx:
      case ScaleIdx:
      case MoveIdx:
      case RotateIdx:
      case GetBoundsIdx:
      case GetIDsFromTagIdx:
            {
               GPtrArray *items;
               int       ret;

               if( objc < 3 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, 
                        "tag-or-id ?option val ...?" );
                  return TCL_ERROR;
               }
               if( gnoclCanvasItemsFromTagOrId( interp, para, 
                     Tcl_GetString( objv[2] ), &items ) != TCL_OK )
                  return TCL_ERROR;

               switch( idx )
               {
                  case RaiseIdx:
                  case LowerIdx:
                     ret = itemRaise( interp, objc, objv, para, items,
                           idx == RaiseIdx );
                     break;
                  case ItemDeleteIdx:
                     ret = itemDelete( interp, objc, objv, para, items );
                     break;
                  case ItemShowIdx:
                     ret = itemShow( interp, objc, objv, para, items );
                     break;
                  case ItemConfigureIdx:
                     ret = itemConfigure( interp, objc, objv, para, items );
                     break;
                  case ItemCgetIdx:
                     ret = itemCget( interp, objc, objv, para, items );
                     break;
                  case ItemCommandIdx:
                     ret = itemCommand( interp, objc, objv, para, items );
                     break;
                  case AffineIdx:
                     ret = affine( interp, objc, objv, para, items, Affine );
                     break;
                  case ScaleIdx:
                     ret = affine( interp, objc, objv, para, items, Scale );
                     break;
                  case MoveIdx:
                     ret = affine( interp, objc, objv, para, items, Move );
                     break;
                  case RotateIdx:
                     ret = affine( interp, objc, objv, para, items, Rotate );
                     break;
                  case GetBoundsIdx:
                     ret = itemBounds( interp, objc, objv, para, items );
                     break;
                  case GetIDsFromTagIdx:
                     ret = getIDs( interp, objc, objv, para, items );
                     break;
                  default:
                     assert( 0 );
               }
               if( items )
                  g_ptr_array_free( items, 0 );
               return ret;
            }
            break; 
      case WindowToCanvasIdx:
            return windowToCanvas( interp, objc, objv, para, 0 );
      case CanvasToWindowIdx:
            return windowToCanvas( interp, objc, objv, para, 1 );
      case FindItemAtIdx:
            return findItemAt( interp, objc, objv, para );
   }

   return TCL_OK;
}
Esempio n. 15
0
/* do_cmd: Send a command to a SCSI device
 */
static void
do_cmd(int fd, char *fmt, int argc, char **argv)
{
	struct get_hook h;
	scsireq_t *scsireq = scsireq_new();
	enum data_phase data_phase;
	int count, amount;
	char *data_fmt, *bp;

	h.argc = argc;
	h.argv = argv;
	h.got = 0;

	scsireq_reset(scsireq);

	scsireq_build_visit(scsireq, 0, 0, 0, fmt, iget, (void *)&h);

	/* Three choices here:
	 * 1. We've used up all the args and have no data phase.
	 * 2. We have input data ("-i")
	 * 3. We have output data ("-o")
	 */

	if (h.got >= h.argc)
	{
		data_phase = none;
		count = scsireq->datalen = 0;
	}
	else
	{
		char *flag = cget(&h, 0);

		if (strcmp(flag, "-o") == 0)
		{
			data_phase = out;
			scsireq->flags = SCCMD_WRITE;
		}
		else if (strcmp(flag, "-i") == 0)
		{
			data_phase = in;
			scsireq->flags = SCCMD_READ;
		}
		else
		{
			fprintf(stderr,
			"Need either \"-i\" or \"-o\" for data phase; not \"%s\".\n", flag);
			usage();
		}

		count = scsireq->datalen = iget(&h, 0);
		if (count) {
			data_fmt = cget(&h, 0);

			scsireq->databuf = malloc(count);

			if (data_phase == out) {
				if (strcmp(data_fmt, "-") == 0)	{
					bp = (char *)scsireq->databuf;
					while (count > 0 &&
					    (amount = read(STDIN_FILENO,
					    bp, count)) > 0) {
						count -= amount;
						bp += amount;
					}
					if (amount == -1)
						err(errno, "read");
					else if (amount == 0) {
						/* early EOF */
						fprintf(stderr,
							"Warning: only read %lu bytes out of %lu.\n",
							scsireq->datalen - (u_long)count,
							scsireq->datalen);
						scsireq->datalen -= (u_long)count;
					}
				}
				else
				{
					bzero(scsireq->databuf, count);
					scsireq_encode_visit(scsireq, data_fmt, iget, (void *)&h);
				}
			}
		}
	}


	scsireq->timeout = seconds * 1000;

	if (scsireq_enter(fd, scsireq) == -1)
	{
		scsi_debug(stderr, -1, scsireq);
		exit(errno);
	}

	if (SCSIREQ_ERROR(scsireq))
		scsi_debug(stderr, 0, scsireq);

	if (count && data_phase == in)
	{
		if (strcmp(data_fmt, "-") == 0)	/* stdout */
		{
			bp = (char *)scsireq->databuf;
			while (count > 0 && (amount = write(STDOUT_FILENO, bp, count)) > 0)
			{
				count -= amount;
				bp += amount;
			}
			if (amount < 0)
				err(errno, "write");
			else if (amount == 0)
				fprintf(stderr, "Warning: wrote only %lu bytes out of %lu.\n",
					scsireq->datalen - count,
					scsireq->datalen);

		}
		else
		{
			scsireq_decode_visit(scsireq, data_fmt, arg_put, 0);
			putchar('\n');
		}
	}
}
Esempio n. 16
0
 virtual const void* native_cget() {
     return cget();
 };
Esempio n. 17
0
 void const* get(int n) const { return cget(n); }
Esempio n. 18
0
 void* get(int n) { return const_cast<void*>(cget(n)); }
Esempio n. 19
0
static int spinButtonFunc( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   static const char *cmds[] = { "delete", "configure", "cget",
         "onValueChanged", NULL };
   enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx,
         OnValueChangedIdx };
   SpinButtonParams *para = (SpinButtonParams *)data;
   GtkWidget *widget = GTK_WIDGET( para->spinButton );
   int idx;

   if( objc < 2 )
   {
      Tcl_WrongNumArgs( interp, 1, objv, "command" );
      return TCL_ERROR;
   }

   if( Tcl_GetIndexFromObj( interp, objv[1], cmds, "command", 
         TCL_EXACT, &idx ) != TCL_OK )
      return TCL_ERROR;

   switch( idx )
   {
      case DeleteIdx:
            return gnoclDelete( interp, widget, objc, objv );

      case ConfigureIdx:
            {
               int ret = TCL_ERROR;
               if( gnoclParseOptions( interp, objc - 1, objv + 1, 
                     spinButtonOptions ) == TCL_OK )
               {
                  ret = configure( interp, para, spinButtonOptions );
               }
               gnoclClearOptions( spinButtonOptions );
               return ret;
            }
            break;
      case CgetIdx:
            {
               int     idx;

               switch( gnoclCget( interp, objc, objv, 
                     G_OBJECT( para->spinButton ), spinButtonOptions, &idx ) )
               {
                  case GNOCL_CGET_ERROR:  
                           return TCL_ERROR;
                  case GNOCL_CGET_HANDLED:
                           return TCL_OK;
                  case GNOCL_CGET_NOTHANDLED:
                           return cget( interp, para, spinButtonOptions, idx );
               }
            }
      case OnValueChangedIdx:
            {
               if( objc != 2 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, NULL );
                  return TCL_ERROR;
               }
               return doCommand( para, getObjValue( para->spinButton ), 0 );
            }
   }

   return TCL_OK;
}
Esempio n. 20
0
/**
\brief
\author
\date
**/
static int fontSelFunc ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
    static const char *cmds[] = { "delete", "configure", "class", "cget", NULL };
    enum cmdIdx { DeleteIdx, ConfigureIdx, ClassIdx, CgetIdx };

    GtkWidget *widget = GTK_WIDGET ( data  );
    int idx;

    if ( objc < 2 )
    {
        Tcl_WrongNumArgs ( interp, 1, objv, "command" );
        return TCL_ERROR;
    }

    if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command",
                               TCL_EXACT, &idx ) != TCL_OK )
        return TCL_ERROR;

    switch ( idx )
    {
    case ClassIdx:
    {
        Tcl_SetObjResult ( interp, Tcl_NewStringObj ( "fontSelection", -1 ) );
    }
    break;
    case DeleteIdx:
    {
        return gnoclDelete ( interp, widget, objc, objv );
    }
    case ConfigureIdx:
    {

        int ret = TCL_ERROR;

        if ( gnoclParseAndSetOptions ( interp, objc - 1, objv + 1, fontSelectOptions, G_OBJECT ( widget ) ) == TCL_OK )
        {
            ret = configure ( interp, widget, fontSelectOptions );
        }

        gnoclClearOptions ( fontSelectOptions );

        return ret;
    }
    case CgetIdx:
    {
        int idx;

        switch ( gnoclCget ( interp, objc, objv, G_OBJECT ( widget ), fontSelectOptions, &idx ) )
        {
        case GNOCL_CGET_ERROR:
            return TCL_ERROR;
        case GNOCL_CGET_HANDLED:
            return TCL_OK;
        case GNOCL_CGET_NOTHANDLED:
            return cget ( interp, widget, fontSelectOptions, idx );
        }
    }
    }

    return TCL_OK;
}
Esempio n. 21
0
bool CScanner::ParseCharacterLiteral()
{
	enum
	{
		BEGIN,
		ESCAPE_SEQUENCE_FOUND,
		HEXADECIMAL_ESCAPE_SEQUENCE_FOUND,
		BEGIN_FINISHING,
		FINISHED,
	};
	enum
	{				// We discovered that between the ' ' is:
		R_SIMPLE,	//	just a c-character
		R_ESCHEX,	//	hexadecimal escape sequence
		R_ESCSEQ,	//	simple escape sequence
		R_NOTHIN,	//	<- Initial state.
	};
	int State = BEGIN;
	int ResultKind = R_NOTHIN;
	UpdateCurrentToken();
	CurrentToken.Kind = DTM_TOKEN::LITERAL::NUMBER::INTEGER;
	string TempString = "";
	bool ErrFlag = cget() == 0;
	while (State != FINISHED && !ErrFlag)
	{
		switch(State)
		{
		case BEGIN:
			ErrFlag = cget() == '\'';
			TempString = cget();
			if (cget() == '\\')
				State = ESCAPE_SEQUENCE_FOUND;
			else
				State = BEGIN_FINISHING, ResultKind = R_SIMPLE;
			break;
		case ESCAPE_SEQUENCE_FOUND:
			ErrFlag = cget() == '\'';
			TempString = cget();
			if (cget() == 'x')
				State = HEXADECIMAL_ESCAPE_SEQUENCE_FOUND, ResultKind = R_ESCHEX;
			else 
				State = BEGIN_FINISHING, ResultKind = R_ESCSEQ;
			break;
		case HEXADECIMAL_ESCAPE_SEQUENCE_FOUND:
			ErrFlag = cget() == '\'';
			while (isxdigit(cget()))
				TempString += cget(), IncPos();
			State = BEGIN_FINISHING, DecPos();
			break;
		case BEGIN_FINISHING:
			ErrFlag = cget() != '\'';
			State = FINISHED;
			break;
		}
		IncPos();
	}
	if (ErrFlag)
	{
		ErrorString = "Invalid character constant.";
		return false;
	}
	switch (ResultKind)
	{
	case R_SIMPLE:
		CurrentToken.Value = TempString[0];
		break;
	case R_ESCHEX: case R_ESCSEQ:
		try
		{
			CurrentToken.Value = EscapeSequenceToValue(TempString);
		}
		catch (...)	// positive_overflow ?
		{
			ErrFlag = true;
		}		
		break;
	case R_NOTHIN:
		break;
	}
	if (ErrFlag)
		ErrorString = "Hexadecimal constant is invalid (may be too large for character).";
	return !ErrFlag;
}
Esempio n. 22
0
static int comboBoxFunc( ClientData data, Tcl_Interp *interp,
      int objc, Tcl_Obj * const objv[] )
{
   static const char *cmds[] = { "delete", "configure", "cget",
         "add", "onChanged", NULL };
   enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx,
         AddIdx, DoOnChangedIdx };

   ComboParams *para = (ComboParams *)data;
   GtkWidget *widget = GTK_WIDGET( para->comboBox );
   int idx;

   if( objc < 2 )
   {
      Tcl_WrongNumArgs( interp, 1, objv, "command" );
      return TCL_ERROR;
   }

   if( Tcl_GetIndexFromObj( interp, objv[1], cmds, "command", 
         TCL_EXACT, &idx ) != TCL_OK )
      return TCL_ERROR;

   switch( idx )
   {
      case DeleteIdx:
            return gnoclDelete( interp, widget, objc, objv );

      case ConfigureIdx:
            {
               int ret = TCL_ERROR;
               if( gnoclParseAndSetOptions( interp, objc - 1, objv + 1, 
                     boxOptions, G_OBJECT( widget ) ) == TCL_OK )
               {
                  ret = configure( interp, para, boxOptions );
               }
               gnoclClearOptions( boxOptions );
               return ret;
            }
            break;
      case CgetIdx:
            {
               int     idx;

               switch( gnoclCget( interp, objc, objv, 
                     G_OBJECT( para->comboBox ), boxOptions, &idx ) )
               {
                  case GNOCL_CGET_ERROR:  
                           return TCL_ERROR;
                  case GNOCL_CGET_HANDLED:
                           return TCL_OK;
                  case GNOCL_CGET_NOTHANDLED:
                           return cget( interp, para, boxOptions, idx );
               }
            }

      case AddIdx:
            return addItemTcl( para, interp, objc, objv );
      case DoOnChangedIdx:
            {
               const char *val;
               if( objc != 2 )
               {
                  Tcl_WrongNumArgs( interp, 2, objv, NULL );
                  return TCL_ERROR;
               }
               val = getActiveValue( para->comboBox );
               if( val )
                  return doCommand( para, val, 0 );
               return TCL_OK;
            }
            break;
   }

   return TCL_OK;
}
Esempio n. 23
0
/**
\brief
\author     William J Giddings
**/
int recentChooserFunc ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	printf ( "widgetFunc\n" );

	static const char *cmds[] = { "delete", "configure", "cget", "onClicked", "class", NULL };
	enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, OnClickedIdx, ClassIdx };
	GtkWidget *widget = GTK_WIDGET ( data );
	int idx;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "command" );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command", TCL_EXACT, &idx ) != TCL_OK )
	{
		return TCL_ERROR;
	}

	switch ( idx )
	{
		case ClassIdx:
			Tcl_SetObjResult ( interp, Tcl_NewStringObj ( "recentChooser", -1 ) );
			break;
		case DeleteIdx:
			return gnoclDelete ( interp, GTK_WIDGET ( widget ), objc, objv );

		case ConfigureIdx:
			{
				int ret = TCL_ERROR;

				ret = configure ( interp, widget, recentChooserOptions );

				if ( 1 )
				{
					if ( gnoclParseAndSetOptions ( interp, objc - 1, objv + 1, recentChooserOptions, G_OBJECT ( widget ) ) == TCL_OK )
					{
						ret = configure ( interp, widget, recentChooserOptions );
					}
				}

				gnoclClearOptions ( recentChooserOptions );

				return ret;
			}

			break;
		case OnClickedIdx:

			if ( objc != 2 )
			{
				Tcl_WrongNumArgs ( interp, 2, objv, NULL );
				return TCL_ERROR;
			}

			if ( GTK_WIDGET_IS_SENSITIVE ( GTK_WIDGET ( widget ) ) )
			{
				gtk_button_clicked ( widget );
			}

			break;

		case CgetIdx:
			{
				int     idx;

				switch ( gnoclCget ( interp, objc, objv, G_OBJECT ( widget ), recentChooserOptions, &idx ) )
				{
					case GNOCL_CGET_ERROR:
						{
							return TCL_ERROR;
						}

					case GNOCL_CGET_HANDLED:
						{
							return TCL_OK;
						}

					case GNOCL_CGET_NOTHANDLED:
						{
							return cget ( interp, widget, recentChooserOptions, idx );
						}
				}
			}
	}

	return TCL_OK;
}
Esempio n. 24
0
File: label.c Progetto: zdia/gnocl
/**
\brief
\author     Peter G Baum, William J Giddings
\date
**/
int labelFunc (
	ClientData data,
	Tcl_Interp *interp,
	int objc,
	Tcl_Obj * const objv[] )
{
	static const char *cmds[] = { "delete", "configure", "cget", "onChanged", "class", NULL };
	enum cmdIdx { DeleteIdx, ConfigureIdx, CgetIdx, OnChangedIdx, ClassIdx};

	LabelParams *para = ( LabelParams * ) data;
	GtkWidget *widget = GTK_WIDGET ( para->label );
	int idx;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "command" );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command",
							   TCL_EXACT, &idx ) != TCL_OK )
		return TCL_ERROR;

	switch ( idx )
	{
		case ClassIdx:
			Tcl_SetObjResult ( interp, Tcl_NewStringObj ( "label", -1 ) );
			break;
		case DeleteIdx:
			return gnoclDelete ( interp, widget, objc, objv );

		case ConfigureIdx:
			{
				int ret = TCL_ERROR;

				if ( gnoclParseAndSetOptions ( interp, objc - 1, objv + 1,
											   labelOptions, G_OBJECT ( widget ) ) == TCL_OK )
				{
					ret = configure ( interp, para, labelOptions );
				}

				gnoclClearOptions ( labelOptions );

				return ret;
			}

			break;

		case CgetIdx:
			{
				int     idx;

				switch ( gnoclCget ( interp, objc, objv, G_OBJECT ( para->label ), labelOptions, &idx ) )
				{
					case GNOCL_CGET_ERROR:
						return TCL_ERROR;
					case GNOCL_CGET_HANDLED:
						return TCL_OK;
					case GNOCL_CGET_NOTHANDLED:
						return cget ( interp, para, labelOptions, idx );
				}
			}

		case OnChangedIdx:
			{
				const char *txt = gtk_label_get_text ( para->label );

				if ( objc != 2 )
				{
					Tcl_WrongNumArgs ( interp, 2, objv, NULL );
					return TCL_ERROR;
				}

				return doCommand ( para, txt, 0 );
			}
	}

	return TCL_OK;
}
Esempio n. 25
0
File: button.c Progetto: zdia/gnocl
/**
\brief  Function associated with the widget.
**/
int buttonFunc ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] )
{
	static const char *cmds[] =
	{
		"delete", "configure", "cget", "onClicked", "class", "parent", "geometry", "toplevel", NULL
	};

	enum cmdIdx
	{
		DeleteIdx, ConfigureIdx, CgetIdx, OnClickedIdx, ClassIdx, ParentIdx, GeometryIdx, ToplevelIdx
	};

	GtkButton *button = GTK_BUTTON ( data );
	int idx;

	if ( objc < 2 )
	{
		Tcl_WrongNumArgs ( interp, 1, objv, "command" );
		return TCL_ERROR;
	}

	if ( Tcl_GetIndexFromObj ( interp, objv[1], cmds, "command", TCL_EXACT, &idx ) != TCL_OK )
	{
		return TCL_ERROR;
	}

	switch ( idx )
	{
		case ToplevelIdx:
			{
				g_print ( "button ToplevelIdx\n" );
				GtkWidget *toplevel;
				Tcl_Obj *obj = NULL;
				toplevel = gtk_widget_get_toplevel ( button ) ;
				obj = Tcl_NewStringObj ( gnoclGetNameFromWidget ( toplevel ), -1 );
				Tcl_SetObjResult ( interp, obj );
				return TCL_OK;
			}

			break;
		case GeometryIdx:
			{
				g_print ( "button GeometryIdx\n" );
				char *txt = gnoclGetWidgetGeometry ( button ) ;
				Tcl_SetObjResult ( interp, Tcl_NewStringObj ( txt , -1 ) );
				return TCL_OK;
			}

			break;
		case ParentIdx:
			{

				GtkWidget * parent;
				Tcl_Obj *obj = NULL;
				parent = gtk_widget_get_parent ( GTK_WIDGET ( button ) );
				obj = Tcl_NewStringObj ( gnoclGetNameFromWidget ( parent ), -1 );
				Tcl_SetObjResult ( interp, obj );

				/* this function not working too well! */
				/* return gnoclGetParent ( interp, data ); */
				return TCL_OK;
			}

			break;
		case ClassIdx:
			{
				Tcl_SetObjResult ( interp, Tcl_NewStringObj ( "button", -1 ) );
				break;
			}

		case DeleteIdx:
			{
				return gnoclDelete ( interp, GTK_WIDGET ( button ), objc, objv );
			}

		case ConfigureIdx:
			{
				int ret = TCL_ERROR;

				if ( gnoclParseAndSetOptions ( interp, objc - 1, objv + 1, buttonOptions, G_OBJECT ( button ) ) == TCL_OK )
				{
					ret = configure ( interp, button, buttonOptions );
				}

				gnoclClearOptions ( buttonOptions );

				return ret;
			}

			break;

		case OnClickedIdx:

			if ( objc != 2 )
			{
				Tcl_WrongNumArgs ( interp, 2, objv, NULL );
				return TCL_ERROR;
			}

			if ( GTK_WIDGET_IS_SENSITIVE ( GTK_WIDGET ( button ) ) )
			{
				gtk_button_clicked ( button );
			}

			break;

		case CgetIdx:
			{
				int idx;

				switch ( gnoclCget ( interp, objc, objv, G_OBJECT ( button ), buttonOptions, &idx ) )
				{
					case GNOCL_CGET_ERROR:
						return TCL_ERROR;
					case GNOCL_CGET_HANDLED:
						return TCL_OK;
					case GNOCL_CGET_NOTHANDLED:
						return cget ( interp, button, buttonOptions, idx );
				}
			}
	}

	return TCL_OK;
}
Esempio n. 26
0
static void *
_readfont(const char *name, size_t *szp, int warn)	/* create fitab and width tab for font */
{
	struct mfile *mp;
	int i, nw = 0, spacewidth, n = 0, v;
	char *ch, *cmd;
	char *cpout;

	if ((mp = mopen(name)) == NULL) {
		if (warn)
			errprint("Can't load font %s", name);
		return NULL;
	}
	for (i = 0; i < NFITAB; i++)
		fitab[i] = 0;
	for (i = 0; i < FSIZE; i++)
		width[i] = kern[i] = code[i] = 0;
	font.specfont = font.ligfont = spacewidth = 0;
	while ((cmd = sget(mp)) != NULL) {
		if (cmd[0] == '#')
			skipline(mp);
		else if (strcmp(cmd, "name") == 0) {
			if ((ch = sget(mp)) != NULL)
				strncpy(font.namefont, ch,
						sizeof font.namefont - 1);
		} else if (strcmp(cmd, "internalname") == 0) {
			if ((ch = sget(mp)) != NULL)
				strncpy(font.intname, ch,
						sizeof font.intname - 1);
		} else if (strcmp(cmd, "special") == 0)
			font.specfont = 1;
		else if (strcmp(cmd, "spare1") == 0)
			cget(mp);
		else if (strcmp(cmd, "ligatures") == 0) {
			font.ligfont = getlig(mp, warn);
		} else if (strcmp(cmd, "spacewidth") == 0) {
			dget(mp, &spacewidth);
			width[0] = spacewidth;	/* width of space on this font */
		} else if (strcmp(cmd, "charset") == 0) {
			skipline(mp);
			nw = 0;
			/* widths are origin 1 so fitab==0 can mean "not there" */
			while ((ch = sget(mp)) != NULL) {
				if (peek(mp) != '"') {	/* it's a genuine new character */
					nw++;
					dget(mp, &i);
					width[nw] = i;
					dget(mp, &i);
					kern[nw] = i;
					iget(mp, &i, 0);
					code[nw] = i;
				}
				/* otherwise it's a synonym for previous character,
				* so leave previous values intact
				*/
				if (strlen(ch) == 1)	/* it's ascii */
					fitab[ch[0] - 32] = nw;	/* fitab origin omits non-graphics */
				else if (strcmp(ch, "---") != 0) {	/* it has a 2-char name */
					for (i = 0; i < dev.nchtab; i++)
						if (strcmp(&chname[chtab[i]], ch) == 0) {
							fitab[i + 128-32] = nw;	/* starts after the ascii */
							break;
						}
					if (i >= dev.nchtab && warn)
						errprint("font %s: %s not in charset\n", name, ch);
				}
				skipline(mp);
			}
			nw++;
			if (dev.biggestfont >= nw)
				n = dev.biggestfont;
			else {
				if (dev.biggestfont > 0 && warn)
					errprint("font %s too big\n", name);
				n = nw;
			}
			font.nwfont = n;
		}
	}
	if (spacewidth == 0)
		width[0] = dev.res * dev.unitwidth / 72 / 3;

	cpout = calloc(1, sizeof font +
			sizeof *width * (font.nwfont & BYTEMASK) +
			sizeof *kern * (font.nwfont & BYTEMASK) +
			sizeof *code * (font.nwfont & BYTEMASK) +
			sizeof *fitab * dev.nchtab+128-32);
	memcpy(cpout, &font, sizeof font);
	v = sizeof font;
	memcpy(&cpout[v], width, sizeof *width * (font.nwfont & BYTEMASK));
	v +=  sizeof *width * (font.nwfont & BYTEMASK);
	memcpy(&cpout[v], kern, sizeof *kern * (font.nwfont & BYTEMASK));
	v += sizeof *kern * (font.nwfont & BYTEMASK);
	memcpy(&cpout[v], code, sizeof *code * (font.nwfont & BYTEMASK));
	v += sizeof *code * (font.nwfont & BYTEMASK);
	memcpy(&cpout[v], fitab, sizeof *fitab * dev.nchtab+128-32);
	v += sizeof *fitab * dev.nchtab+128-32;
	if (szp)
		*szp = v;
	mclose(mp);
	return cpout;
}