Exemplo n.º 1
0
void
ScrollBarOn(XtermWidget xw, Bool init)
{
    TScreen *screen = TScreenOf(xw);

    if (screen->fullVwin.sb_info.width || IsIcon(screen))
	return;

    TRACE(("ScrollBarOn(init %s)\n", BtoS(init)));
    if (init) {			/* then create it only */
	if (screen->scrollWidget == 0) {
	    /* make it a dummy size and resize later */
	    screen->scrollWidget = CreateScrollBar(xw,
						   -ScrollBarBorder(xw),
						   -ScrollBarBorder(xw),
						   5);
	    if (screen->scrollWidget == NULL) {
		Bell(xw, XkbBI_MinorError, 0);
	    }
	}
    } else if (!screen->scrollWidget || !XtIsRealized((Widget) xw)) {
	Bell(xw, XkbBI_MinorError, 0);
	Bell(xw, XkbBI_MinorError, 0);
    } else {

	ResizeScrollBar(xw);
	xtermAddInput(screen->scrollWidget);
	XtRealizeWidget(screen->scrollWidget);
	TRACE_TRANS("scrollbar", screen->scrollWidget);

	screen->fullVwin.sb_info.rv_cached = False;

	screen->fullVwin.sb_info.width = (screen->scrollWidget->core.width
					  + BorderWidth(screen->scrollWidget));

	TRACE(("setting scrollbar width %d = %d + %d\n",
	       screen->fullVwin.sb_info.width,
	       screen->scrollWidget->core.width,
	       BorderWidth(screen->scrollWidget)));

	ScrollBarDrawThumb(screen->scrollWidget);
	DoResizeScreen(xw);

#ifdef SCROLLBAR_RIGHT
	updateRightScrollbar(xw);
#endif

	XtMapWidget(screen->scrollWidget);
	update_scrollbar();
	if (screen->visbuf) {
	    xtermClear(xw);
	    Redraw();
	}
    }
}
Exemplo n.º 2
0
void CGenericSerialConsole::InsertChar ( const uint8_t c )
{
  // If not printable...
  if ( !IsPrintableAscii( c ) )
  {
    Bell();
    return;
  }

  const uint32_t nextEndPos = ( m_cmdEndPos + 1 ) % BUF_LEN;

  // If command full...
  if ( GetCircularDistance( m_cmdBeginPos, nextEndPos, BUF_LEN ) > MAX_SINGLE_CMD_LEN )
  {
    Bell();
    return;
  }

  // If the command is empty or the cursor is at the end, append the new character.
  if ( m_cursorPos == m_cmdEndPos )
  {
    m_buffer[ m_cmdEndPos ] = c;

    PrintChar( c );

    m_cursorPos = nextEndPos;
    m_cmdEndPos = nextEndPos;

    return;
  }


  // NOTE: If the following logic changes much, remeber to update MAX_TX_BUFFER_SIZE_NEEDED.

  // Shift characters upwards one position.
  for ( uint32_t i = nextEndPos; i != m_cursorPos; i = GetCircularPosMinusOne( i, BUF_LEN  ) )
    m_buffer[ i ] = m_buffer[ GetCircularPosMinusOne( i, BUF_LEN  ) ];

  // Insert new character.
  m_buffer[ m_cursorPos ] = c;

  // Print all characters.
  for ( uint32_t i = m_cursorPos; i != nextEndPos; i = ( i + 1 ) % BUF_LEN )
    PrintChar( m_buffer[ i ] );

  // Move the terminal cursor left to match our current cursor position.
  const uint32_t distanceToEnd = GetCircularDistance( m_cursorPos, m_cmdEndPos, BUF_LEN );
  assert( distanceToEnd > 0 );
  Printf( "\x1B[%uD", unsigned( distanceToEnd ) );  // Move left n positions.

  m_cursorPos = (m_cursorPos + 1) % BUF_LEN;
  m_cmdEndPos = nextEndPos;
}
Exemplo n.º 3
0
void  SaveField(void)
{
   int         key;

   OwDisplay(ReadLine);
   OwPutString(2,1,"Enter file name for saving the field",UPAL+0);
   OwDrawFrame(FULL,SINGLE,UPAL+0);

   CursorType(C_NORMAL);
   key=OwGetString(2,2,UW-4,filename,sizeof(filename)-1,UPAL+1);
   OwClose();

   if(key!=K_ESC)
   {
      FILE  *f;

      f=fopen(filename,"w");
      if(f==NULL)
      {
         Bell();
         return;
      }
      Print(f);
      fclose(f);
   }
}
Exemplo n.º 4
0
void CGenericSerialConsole::LeftArrow ( void )
{
  if ( m_cursorPos == m_cmdBeginPos )
  {
    Bell();
    return;
  }

  m_cursorPos = GetCircularPosMinusOne( m_cursorPos, BUF_LEN );

  PrintStr( "\x1B[D" );  // Move left.
}
Exemplo n.º 5
0
void CGenericSerialConsole::RightArrow ( void )
{
  if ( m_cursorPos == m_cmdEndPos )
  {
    Bell();
    return;
  }

  m_cursorPos = ( m_cursorPos + 1 ) % BUF_LEN;

  PrintStr( "\x1B[C" );  // Move right.
}
Exemplo n.º 6
0
void GTerm::pc_cmd( void )
{
    pc_curcmd = * input_data;

    //printf("pc_cmd: pc_curcmd = %d...\n", pc_curcmd);
    pc_argcount = 0;

    switch (pc_curcmd)
    {
        case GTERM_PC_CMD_CURONOFF: // <on/off>
            pc_numargs = 1;
            break;

        case GTERM_PC_CMD_MOVECURSOR: // <x> <y>
            pc_numargs = 2;
            break;

        case GTERM_PC_CMD_PUTTEXT: // <x> <y> <wid> <len>
            pc_numargs = 4;
            break;

        case GTERM_PC_CMD_WRITE: // <x> <y> <wid> <attr>
            pc_numargs = 4;
            break;

        case GTERM_PC_CMD_MOVETEXT: // <sx> <sy> <wid> <len> <dx> <dy>
            pc_numargs = 6;
            break;

        case GTERM_PC_CMD_BEEP:
            Bell();
            break;

        case GTERM_PC_CMD_SELECTPRINTER:
            pc_numargs = 1;
            break;

        case GTERM_PC_CMD_PRINTCHAR:
            pc_numargs = 1;
            break;

        case GTERM_PC_CMD_PRINTCHARS:
            pc_numargs = 2;
            break;

        default:
            current_state = pc_cmd_state;
            break;
    }
}
Exemplo n.º 7
0
void _SnacRemesher_TestCondFunc( Index node_dI, Variable_Index var_I, void* _context, void* result ) {
	Snac_Context*			context = (Snac_Context*)_context;
	MeshLayout*			meshLayout = (MeshLayout*)context->meshLayout;
	HexaMD*				decomp = (HexaMD*)meshLayout->decomp;

	double*				velComponent = (double*)result;
	IJK				ijk;
	double				x;
	Node_GlobalIndex		node_gI = _MeshDecomp_Node_LocalToGlobal1D( decomp, node_dI );
	
	RegularMeshUtils_Node_1DTo3D( decomp, node_gI, &ijk[0], &ijk[1], &ijk[2] );
	x = 1.0f / decomp->nodeGlobal3DCounts[0] * ijk[0] - 0.5;
	(*velComponent) = Bell( x ) * 5e-7;
}
Exemplo n.º 8
0
void main()
{	
	uchar *p;
	p="by Jasper";	
	Init();
	IsReset=0;
	IsReset=eeprom_read(100);
	
	if(!IsReset)										//首次进入输入密码和显示欢迎界面
	{
		Confirm();
		LCD_clear();
		delay_ms(200);
		LCD_write_str(5,0,"welcome");
	
		while(*p)									
		{
			LCD_write_char(i,1,*p);
			p++;
			i++;
			delay_ms(100);
		}
	}
	
													
	LCD_clear();										//正式进入系统
	LCD_write_str(0,0,"1bell2led3motor");				
	LCD_write_str(0,1,"4fix_password");
	
	while(1)
	{
		eeprom_write(100,0);
		if(select=='1')  								//蜂鸣器模式
		{
			LCD_clear();
			LCD_write_str(0,0,"buzz..send * or");
			LCD_write_str(0,1,"shutdown to exit");
			Bell();
		}
		
		if(select=='2')  LED(); 						//led模式
		
		if(select=='3')  Motor();						//电机模式
		
		if(select=='4')  Write_password();				//修改密码模式
		
	}
		
}
Exemplo n.º 9
0
/*
 * Toggle the visibility of the scrollbars.
 */
void
ToggleScrollBar(XtermWidget xw)
{
    TScreen *screen = TScreenOf(xw);

    if (IsIcon(screen)) {
	Bell(xw, XkbBI_MinorError, 0);
    } else {
	TRACE(("ToggleScrollBar{{\n"));
	if (screen->fullVwin.sb_info.width) {
	    ScrollBarOff(xw);
	} else {
	    ScrollBarOn(xw, False);
	}
	update_scrollbar();
	TRACE(("...ToggleScrollBar}}\n"));
    }
}
Exemplo n.º 10
0
void CGenericSerialConsole::Backspace ( void )
{
  // If at the beginning, or if the command is empty...
  if ( m_cursorPos == m_cmdBeginPos )
  {
    Bell();
    return;
  }

  // If at the end...
  if ( m_cursorPos == m_cmdEndPos )
  {
    m_buffer[ m_cmdEndPos ] = 0;
    PrintStr( "\x08 \x08" ); // Go left one character, space (deletes the character), go left one character again.
    m_cmdEndPos = GetCircularPosMinusOne( m_cmdEndPos, BUF_LEN  );
    m_cursorPos = m_cmdEndPos;
    return;
  }


  // NOTE: If the following logic changes much, remeber to update MAX_TX_BUFFER_SIZE_NEEDED.

  // Move the cursor left one position.
  m_cursorPos = GetCircularPosMinusOne( m_cursorPos, BUF_LEN );
  PrintStr( "\x1B[D" );

  // Shift characters downwards one position, and print each one.
  for ( uint32_t i = m_cursorPos; i != GetCircularPosMinusOne( m_cmdEndPos, BUF_LEN ); i = ( i + 1 ) % BUF_LEN )
  {
    m_buffer[ i ] = m_buffer[ (i + 1) % BUF_LEN ];
    PrintChar( m_buffer[ i ] );
  }

  // Delete the last character by writing a space.
  PrintChar( ' ' );

  // Move the terminal cursor left to match our current cursor position.
  const uint32_t distanceToEnd = GetCircularDistance( m_cursorPos, m_cmdEndPos, BUF_LEN );
  if ( distanceToEnd > 0 )
    Printf( "\x1B[%uD", unsigned( distanceToEnd ) );  // Move left n positions.

  m_cmdEndPos = GetCircularPosMinusOne( m_cmdEndPos, BUF_LEN );
}
Exemplo n.º 11
0
Arquivo: input.c Projeto: aosm/X11
static void
AdjustAfterInput(TScreen * screen)
{
    if (screen->scrollkey && screen->topline != 0)
	WindowScroll(screen, 0);
    if (screen->marginbell) {
	int col = screen->max_col - screen->nmarginbell;
	if (screen->bellarmed >= 0) {
	    if (screen->bellarmed == screen->cur_row) {
		if (screen->cur_col >= col) {
		    Bell(XkbBI_MarginBell, 0);
		    screen->bellarmed = -1;
		}
	    } else
		screen->bellarmed =
		    screen->cur_col < col ? screen->cur_row : -1;
	} else if (screen->cur_col < col)
	    screen->bellarmed = screen->cur_row;
    }
}
Exemplo n.º 12
0
    std::vector<std::string> TermFactory::available() const {
        std::vector<std::string> result;
        result.push_back(Discrete().className());
        result.push_back(Bell().className());
        result.push_back(Gaussian().className());
        result.push_back(GaussianProduct().className());

        result.push_back(PiShape().className());
        result.push_back(Ramp().className());
        result.push_back(Rectangle().className());
        result.push_back(SShape().className());
        result.push_back(Sigmoid().className());

        result.push_back(SigmoidDifference().className());
        result.push_back(SigmoidProduct().className());
        result.push_back(Trapezoid().className());
        result.push_back(Triangle().className());
        result.push_back(ZShape().className());
        return result;
    }
Exemplo n.º 13
0
void
ScrollBarOff(XtermWidget xw)
{
    TScreen *screen = TScreenOf(xw);

    if (!screen->fullVwin.sb_info.width || IsIcon(screen))
	return;

    TRACE(("ScrollBarOff\n"));
    if (XtIsRealized((Widget) xw)) {
	XtUnmapWidget(screen->scrollWidget);
	screen->fullVwin.sb_info.width = 0;
	DoResizeScreen(xw);
	update_scrollbar();
	if (screen->visbuf) {
	    xtermClear(xw);
	    Redraw();
	}
    } else {
	Bell(xw, XkbBI_MinorError, 0);
    }
}
Exemplo n.º 14
0
bool CGenericSerialConsole::ProcessCharAfterEscapeBracket ( const uint8_t c )
{
  switch (c)
  {
  case 'D':  LeftArrow ();  break;
  case 'C':  RightArrow();  break;

  // In order to implement the 'delete' key here, we need to process here sequence "ESC [ 3 ~",
  // which is made of these bytes:
  // 27  - ESC
  // 91  - [
  // 51  - 3
  // 126 - ~

  default:
    Bell();
    break;
  }

  m_state = stIdle;

  return false;
}
Exemplo n.º 15
0
 TermFactory::TermFactory() : ConstructionFactory<Term*>("Term") {
     registerConstructor("", fl::null);
     registerConstructor(Bell().className(), &(Bell::constructor));
     registerConstructor(Binary().className(), &(Binary::constructor));
     registerConstructor(Concave().className(), &(Concave::constructor));
     registerConstructor(Constant().className(), &(Constant::constructor));
     registerConstructor(Cosine().className(), &(Cosine::constructor));
     registerConstructor(Discrete().className(), &(Discrete::constructor));
     registerConstructor(Function().className(), &(Function::constructor));
     registerConstructor(Gaussian().className(), &(Gaussian::constructor));
     registerConstructor(GaussianProduct().className(), &(GaussianProduct::constructor));
     registerConstructor(Linear().className(), &(Linear::constructor));
     registerConstructor(PiShape().className(), &(PiShape::constructor));
     registerConstructor(Ramp().className(), &(Ramp::constructor));
     registerConstructor(Rectangle().className(), &(Rectangle::constructor));
     registerConstructor(SShape().className(), &(SShape::constructor));
     registerConstructor(Sigmoid().className(), &(Sigmoid::constructor));
     registerConstructor(SigmoidDifference().className(), &(SigmoidDifference::constructor));
     registerConstructor(SigmoidProduct().className(), &(SigmoidProduct::constructor));
     registerConstructor(Spike().className(), &(Spike::constructor));
     registerConstructor(Trapezoid().className(), &(Trapezoid::constructor));
     registerConstructor(Triangle().className(), &(Triangle::constructor));
     registerConstructor(ZShape().className(), &(ZShape::constructor));
 }
Exemplo n.º 16
0
void
ScrollBarOn (XtermWidget xw, int init, int doalloc)
{
#ifdef MOTIF
    Cursor arrowCursor;
#endif /* MOTIF */
    register TScreen *screen = &xw->screen;
    register int i, j, k;

    if(screen->fullVwin.scrollbar)
        return;

    if (init) {			/* then create it only */
        if (screen->scrollWidget) return;

        /* make it a dummy size and resize later */
        if ((screen->scrollWidget = CreateScrollBar (xw, -1, -1, 5))
                == NULL) {
            Bell(XkbBI_MinorError,0);
            return;
        }

        return;

    }

    if (!screen->scrollWidget) {
        Bell (XkbBI_MinorError,0);
        Bell (XkbBI_MinorError,0);
        return;
    }

    if (doalloc && screen->allbuf) {
        /* FIXME: this is not integrated well with Allocate */
        if((screen->allbuf =
                    (ScrnBuf) realloc((char *) screen->visbuf,
                                      (unsigned) MAX_PTRS*(screen->max_row + 2 +
                                              screen->savelines) *
                                      sizeof(char *)))
                == NULL)
            Error (ERROR_SBRALLOC);
        screen->visbuf = &screen->allbuf[MAX_PTRS * screen->savelines];
        memmove( (char *)screen->visbuf, (char *)screen->allbuf,
                 MAX_PTRS * (screen->max_row + 2) * sizeof (char *));
        for (i = k = 0; i < screen->savelines; i++) {
            k += BUF_HEAD;
            for (j = BUF_HEAD; j < MAX_PTRS; j++) {
                if((screen->allbuf[k++] =
                            (Char *)calloc((unsigned) screen->max_col + 1, sizeof(Char))) ==
                        NULL)
                    Error (ERROR_SBRALLOC2);
            }
        }
    }

    ResizeScrollBar (screen);
    XtRealizeWidget (screen->scrollWidget);
#ifdef MOTIF
    /* define pointer cursor for it */
    arrowCursor = XCreateFontCursor(XtDisplay(screen->scrollWidget), XC_left_ptr);
    XDefineCursor(XtDisplay(screen->scrollWidget), XtWindow(screen->scrollWidget), arrowCursor);
    XFreeCursor(XtDisplay(screen->scrollWidget), arrowCursor);
#endif /* MOTIF */
    screen->fullVwin.scrollbar = screen->scrollWidget->core.width +
                                 screen->scrollWidget->core.border_width;

    ScrollBarDrawThumb(screen->scrollWidget);
    DoResizeScreen (xw);

#ifdef SCROLLBAR_RIGHT
    /*
     * Adjust the scrollbar position if we're asked to turn on scrollbars
     * for the first time after the xterm is already running.  That makes
     * the window grow after we've initially configured the scrollbar's
     * position.  (There must be a better way).
     */
    if (term->misc.useRight
            && screen->fullVwin.fullwidth < term->core.width)
        XtVaSetValues(screen->scrollWidget,
                      XtNx, screen->fullVwin.fullwidth - screen->scrollWidget->core.border_width,
                      NULL);
#endif

    XtMapWidget(screen->scrollWidget);
    update_scrollbar ();
    if (screen->visbuf) {
        XClearWindow (screen->display, XtWindow (term));
        Redraw ();
    }
}
Exemplo n.º 17
0
void ScrollBarOn (XtermWidget xw,int init,int  doalloc)
{
    register TScreen *screen = &xw->screen;
    register int border = 2 * screen->border;
    register int i,j,k;

    /*
    if(screen->scrollbar)
        return;
    */
    if(screen->fullVwin.sb_info.width)
        return;



    if (init)
    {   /* then create it only */
        if (screen->scrollWidget)
            return;

        /* make it a dummy size and resize later */
        if ((screen->scrollWidget = CreateScrollBar (xw, -1, - 1, 5))
                == NULL)
        {
            Bell(XkbBI_MinorError,0);
            return;
        }

        return;

    }

    if (!screen->scrollWidget)
    {
        Bell (XkbBI_MinorError,0);
        Bell (XkbBI_MinorError,0);
        return;
    }

    if (doalloc && screen->allbuf)
    {
        /* FIXME: this is not integrated well with Allocate */
        if((screen->allbuf =
                    (ScrnBuf) realloc((char *) screen->visbuf,
                                      (unsigned) MAX_PTRS*(screen->max_row + 2 +
                                                           screen->savelines) *
                                      sizeof(char *)))
                == NULL)
            SysError(ERROR_SBRALLOC);
        screen->visbuf = &screen->allbuf[MAX_PTRS * screen->savelines];
        memmove( (char *)screen->visbuf, (char *)screen->allbuf,
                 MAX_PTRS * (screen->max_row + 2) * sizeof (char *));
        for (i = k = 0; i < screen->savelines; i++)
        {
            k += BUF_HEAD;
            for (j = BUF_HEAD; j < MAX_PTRS; j++)
            {
                if((screen->allbuf[k++] =
                            (Char *)calloc((unsigned) screen->max_col + 1, sizeof(Char))) ==
                        NULL)
                    SysError(ERROR_SBRALLOC2);
            }
        }
    }


    ResizeScrollBar (screen);
    xtermAddInput(screen->scrollWidget);

    XtRealizeWidget (screen->scrollWidget);

    /* Now set the left ptr cursor for the scrollbar [email protected] */
    XDefineCursor(XtDisplay(screen->scrollWidget),
            XtWindow(screen->scrollWidget),
            screen->arrow);


    screen->fullVwin.sb_info.rv_cached = False;
    screen->fullVwin.sb_info.width = screen->scrollWidget->core.width +
                                     screen->scrollWidget->core.border_width;
    ScrollBarDrawThumb(screen->scrollWidget);
    DoResizeScreen (xw);
    XtMapWidget(screen->scrollWidget);
    update_scrollbar ();
    if (screen->visbuf)
    {
        XClearWindow (screen->display, XtWindow (term));
        Redraw ();
    }

    /* XXX TODO if scrollbar is on right [email protected] */
}
Exemplo n.º 18
0
int com_match(int p, param_list param)
{
  struct player *pp = &player_globals.parray[p];
  int adjourned;                /* adjourned game? */
  int g;                        /* more adjourned game junk */
  int p1;
  int bh = 0, partner = 0, pp1 = 0;
  struct pending* pendfrom;
  struct pending* pendto;
  struct pending* pend;
  int wt = -1;                  /* white start time */
  int winc = -1;                /* white increment */
  int bt = -1;                  /* black start time */
  int binc = -1;                /* black increment */
  int rated = -1;               /* 1 = rated, 0 = unrated */
  int white = -1;               /* 1 = want white, 0 = want black */
  char category[100], board[100];
  textlist *clauses = NULL;
  int type = 0;

  category[0] ='\0';
  board[0] ='\0';

  if ((pp->game >= 0) && ((game_globals.garray[pp->game].status == GAME_EXAMINE)
|| (game_globals.garray[pp->game].status == GAME_SETUP))) {

    pprintf(p, "You can't challenge while you are examining a game.\n");
    return COM_OK;
  }

  if (pp->game >= 0) {
    pprintf(p, "You can't challenge while you are playing a game.\n");
    return COM_OK;
  }

  /* Makes sure that the user has not been ratebanned - Added by johnthegreat*/
  if (in_list(p, L_RATEBAN, player_globals.parray[p].name))
  {
  	pprintf_prompt(p,"You are banned from playing rated games.");
   	return COM_OK;
  }

  stolower(param[0].val.word);
  p1 = player_find_part_login(param[0].val.word);
  if (p1 < 0) {
    pprintf(p, "No user named \"%s\" is logged in.\n", param[0].val.word);
    return COM_OK;
  }

  if (p1 == p) {                /* Allowing to match yourself to enter
                                   analysis mode */
    //ExamineScratch (p, param, 0);
    	pprintf(p, "Your can not match yourself.\n");
	return COM_OK;
  }

  if (!CheckPFlag(p1, PFLAG_OPEN)) {
    pprintf(p, "Player \"%s\" is not open to match requests.\n", player_globals.parray[p1].name);
    return COM_OK;
  }

  if (player_globals.parray[p1].game >= 0) {
    pprintf(p, "Player \"%s\" is playing a game.\n", player_globals.parray[p1].name);    return COM_OK;
  }

  if (CheckPFlag(p, PFLAG_TOURNEY) && !CheckPFlag(p1, PFLAG_TOURNEY)) {
    pprintf(p, "You may only match players with their tournament variable set.\n");
    return COM_OK;
  }

  if (!CheckPFlag(p, PFLAG_TOURNEY) && CheckPFlag(p1, PFLAG_TOURNEY)) {
    pprintf(p, "%s is in a tournament, and cannot accept other challenges.\n", player_globals.parray[p1].name);
    return COM_OK;
  }

	if (!net_globals.con[pp->socket]->timeseal)
	{
		return COM_OK;

	}
  if (!CheckPFlag(p, PFLAG_OPEN)) {
    PFlagON(p, PFLAG_OPEN);
    pprintf(p, "Setting you open for matches.\n");
  }


/* look for an adjourned game between p and p1 */
  g = game_new();
  adjourned = (game_read(g, p, p1) >= 0) || (game_read(g, p1, p) >= 0);
  if (adjourned) {
    type = game_globals.garray[g].type;
    wt = game_globals.garray[g].wInitTime / 60000;
    bt = game_globals.garray[g].bInitTime / 60000;
    winc = game_globals.garray[g].wIncrement / 1000;
    binc = game_globals.garray[g].bIncrement / 1000;
    rated = game_globals.garray[g].rated;
  }
  game_remove(g);

  pendto = find_pend(p, p1, PEND_MATCH);

  pendfrom = find_pend(p1, p, PEND_MATCH);

  if (!adjourned) {
      if (player_censored(p1, p))
        {
          pprintf(p, "Player \"%s\" is censoring you.\n",
              player_globals.parray[p1].name);
          return COM_OK;
        }
      if (player_censored(p, p1))
        {
          pprintf(p, "You are censoring \"%s\".\n",
              player_globals.parray[p1].name);
          return COM_OK;
        }
    if (in_list(p1, L_NOPLAY, pp->name)) {
      pprintf(p, "You are on %s's noplay list.\n", player_globals.parray[p1].name);
      return COM_OK;
    }
    if (in_list(p, L_NOPLAY, player_globals.parray[p1].name)) {
      pprintf(p, "You have %s on your noplay list.\n", player_globals.parray[p1].name);
      return COM_OK;
    }

    /* Makes sure that the opponent has not been ratebanned - Added by johnthegreat*/
    if (in_list(p1, L_RATEBAN, player_globals.parray[p1].name))
    {
    	pprintf(p,"%s has been banned from playing rated games.",player_globals.parray[p1].name);
    	return COM_OK;
    }

    if (CheckPFlag(p1, PFLAG_WHITELIST) && !player_isAllowedPlay(p1, p)) {
        struct player *pp2 = player_getStruct(p1);
        pprintf(p, "%s is not allowing requests from you.\n", pp2->name);
        return COM_OK;
    }

    if (param[1].type != TYPE_NULL) {
      if (!parse_match_string(p, &wt,&bt,&winc,&binc,&white,&rated,category,
                                                  board,param[1].val.string))

	  return COM_OK; /* couldn't parse */
    }

    if (rated == -1)
      rated = BoolCheckPFlag(p, PFLAG_RATED);
    if (!CheckPFlag(p, PFLAG_REG) || !CheckPFlag(p1, PFLAG_REG))
      rated = 0;

    if (winc == -1)
      winc = (wt == -1) ? pp->d_inc : 0;  /* match 5 == match 5 0 */

    if (wt == -1)
      wt = pp->d_time;

    if (bt == -1)
      bt = wt;

    if (binc == -1)
      binc = winc;

    if (category[0])
	{
			if (!board[0] && strcmp(category,"bughouse") && strcmp(category,"zh"))
			{
				pprintf(p, "You must specify a board and a category.\n");
				return COM_OK;
			} else if (board[0])
			{
				char fname[MAX_FILENAME_SIZE];

				if (!strcmp(board,"FR"))
					sprintf(fname, "%s/%s", BOARD_DIR, board);
				else
					sprintf(fname, "%s/%s/%s", BOARD_DIR, category, board);

				if (!file_exists(fname))
				{
					pprintf(p, "No such category/board: %s/%s\n", category, board);
					return COM_OK;
				}
			}
    }
    type = game_isblitz(category,board);

    if (type == TYPE_BUGHOUSE) {
      if (rated && pp->partner >= 0 && player_globals.parray[p1].partner >= 0) {
        if (!CheckPFlag(pp->partner, PFLAG_REG)
              || !CheckPFlag(player_globals.parray[p1].partner, PFLAG_REG))
          rated = 0;
      }
    }
    if (rated && (type == TYPE_NONSTANDARD)) {
      pprintf(p, "Game is non-standard - reverting to unrated\n");
      rated = 0;
    }
    if (rated && (type == TYPE_UNTIMED)) {
      pprintf(p, "Game is untimed - reverting to unrated\n");
      rated = 0;
    }
    if ((pendfrom == NULL) && !CheckPFlag(p1, PFLAG_ROPEN)
        && (rated != BoolCheckPFlag(p1, PFLAG_RATED))) {
      pprintf(p, "%s only wants to play %s games.\n", player_globals.parray[p1].name,
              rstr[!rated]);
      pprintf_highlight(p1, "Ignoring");
      pprintf(p1, " %srated match request from %s.\n",
              (rated ? "" : "un"), pp->name);
      return COM_OK;
    }

    /* Now check formula. */
    if (!adjourned
        && !GameMatchesFormula(p,p1, wt,winc,bt,binc, rated, type, &clauses)) {
      pprintf(p, "Match request does not fit formula for %s:\n",
              player_globals.parray[p1].name);
      pprintf(p, "%s's formula: %s\n", player_globals.parray[p1].name, player_globals.parray[p1].formula);
      ShowClauses (p, p1, clauses);
      ClearTextList(clauses);
      pprintf_highlight(p1, "Ignoring");
      pprintf_prompt(p1, " (formula): %s (%d) %s (%d) %s.\n",
                     pp->name,
                     GetRating(&player_globals.parray[p], type),
                     player_globals.parray[p1].name,
                     GetRating(&player_globals.parray[p1], type),
            game_str(rated, wt * 60, winc, bt * 60, binc, category, board));
      return COM_OK;
    }

    if (type == TYPE_BUGHOUSE) {
      bh = 1;
      partner = pp->partner;
      pp1 = player_globals.parray[p1].partner;

      if (pp < 0) {
        pprintf(p, "You have no partner for bughouse.\n");
        return COM_OK;
      }
      if (pp1 < 0) {
        pprintf(p, "Your opponent has no partner for bughouse.\n");
        return COM_OK;
      }
      if (partner == pp1) { /* should be an impossible case - DAV */
        pprintf(p, "You and your opponent both chose the same partner!\n");
        return COM_OK;
      }
      if (partner == p1 || pp1 == p) {
        pprintf(p, "You and your opponent can't choose each other as partners!\n");
        return COM_OK;
      }
      if (player_globals.parray[partner].partner != p) { /* another impossible case - DAV */
        pprintf(p, "Your partner hasn't chosen you as his partner!\n");
        return COM_OK;
      }
      if (player_globals.parray[pp1].partner != p1) { /* another impossible case - DAV */
        pprintf(p, "Your opponent's partner hasn't chosen your opponent as his partner!\n");
        return COM_OK;
      }
      if (!CheckPFlag(partner, PFLAG_OPEN) || player_globals.parray[partner].game >= 0) {
        pprintf(p, "Your partner isn't open to play right now.\n");
        return COM_OK;
      }
      if (!CheckPFlag(pp1, PFLAG_OPEN) || player_globals.parray[pp1].game >= 0) {
        pprintf(p, "Your opponent's partner isn't open to play right now.\n");
        return COM_OK;
      }

      /* Bypass NOPLAY lists, censored lists, ratedness, privacy, and formula for now */
      /*  Active challenger/ee will determine these. */
    }
    /* Ok match offer will be made */

  }                             /* adjourned games shouldn't have to worry
                                   about that junk? */
				/* keep incase of adjourned bughouse in future*/

  if (pendto != NULL) {
    pprintf(p, "Updating offer already made to \"%s\".\n", player_globals.parray[p1].name);
  }

  if (pendfrom != NULL) {
    if (pendto != NULL) {
      pprintf(p, "Pending list error!.\n");
      d_printf( "CHESSD: This shouldn't happen. You can't have a match pending from and to the same person.\n");
      return COM_OK;
    }

    if (adjourned || ((wt == pendfrom->btime) &&
                      (winc == pendfrom->binc) &&
                      (bt == pendfrom->wtime) &&
                      (binc == pendfrom->winc) &&
                      (rated == pendfrom->rated) &&
                      ((white == -1) || (white + pendfrom->seek_color == 1)) &&
               (!strcmp(category, pendfrom->category)) &&
                 (!strcmp(board, pendfrom->board_type)))) {
      /* Identical match, should accept! */
      accept_match(pendfrom,p, p1);
      return COM_OK;

    } else {
      delete_pending(pendfrom);
    }
  }

  if (pendto == NULL)
    pend = add_pending(p,p1,PEND_MATCH);
  else
    pend = pendto;

  pend->wtime = wt;
  pend->winc = winc;
  pend->btime = bt;
  pend->binc = binc;
  pend->rated = rated;
  pend->seek_color = white;
  pend->game_type = type;
  pend->category = strdup(category);
  pend->board_type = strdup (board);

  if (pendfrom != NULL) {
    pprintf(p, "Declining offer from %s and offering new match parameters.\n", player_globals.parray[p1].name);
    pprintf(p1, "\n%s declines your match offer a match with these parameters:", pp->name);
  }

  if (pendto != NULL) {
    pprintf(p, "Updating match request to: ");
    pprintf(p1, "\n%s updates the match request.\n", pp->name);
  } else {
    pprintf(p, "Issuing: ");
    pprintf(p1, "\n");
  }

  pprintf(p, "%s (%s) %s", pp->name,
          ratstrii(GetRating(&player_globals.parray[p], type), p),
          colorstr[white + 1]);
  pprintf_highlight(p, "%s", player_globals.parray[p1].name);
  pprintf(p, " (%s) %s%s.\n",
          ratstrii(GetRating(&player_globals.parray[p1], type), p1),
          game_str(rated, wt , winc, bt , binc, category, board),
          adjustr[adjourned]);
  pprintf(p1, "Challenge: ");
  pprintf_highlight(p1, "%s", pp->name);
  pprintf(p1, " (%s) %s",
          ratstrii(GetRating(&player_globals.parray[p], type), p),
          colorstr[white + 1]);
  pprintf(p1, "%s (%s) %s%s.\n", player_globals.parray[p1].name,
          ratstrii(GetRating(&player_globals.parray[p1], type), p1),
          game_str(rated, wt , winc, bt , binc, category, board),
          adjustr[adjourned]);
  Bell (p1);

  if (bh) {

    pprintf(partner, "\nYour bughouse partner issuing %s (%s) %s",
            pp->name, ratstrii(GetRating(&player_globals.parray[p], type), p),
            colorstr[white + 1]);
    pprintf_highlight(partner, "%s", player_globals.parray[p1].name);
    pprintf(partner, " (%s) %s.\n",
            ratstrii(GetRating(&player_globals.parray[p1], type), p1),
            game_str(rated, wt , winc, bt , binc, category, board));
    pprintf(partner, "Your game would be ");
    pprintf_highlight(partner, "%s", player_globals.parray[pp1].name);
    pprintf_prompt(partner, " (%s) %s%s (%s) %s.\n",
          ratstrii(GetRating(&player_globals.parray[pp1], type), pp1),
          colorstr[white + 1], player_globals.parray[partner].name,
          ratstrii(GetRating(&player_globals.parray[partner], type), partner),
          game_str(rated, wt , winc, bt , binc, category, board));
    Bell (partner);

    pprintf(pp1, "\nYour bughouse partner was challenged ");
    pprintf_highlight(pp1, "%s", pp->name);
    pprintf(pp1, " (%s) %s", ratstrii(GetRating(&player_globals.parray[p], type), p),
                             colorstr[white + 1]);
    pprintf(pp1, "%s (%s) %s.\n", player_globals.parray[p1].name,
            ratstrii(GetRating(&player_globals.parray[p1], type), p1),
            game_str(rated, wt , winc, bt , binc, category, board));
    pprintf(pp1, "Your game would be %s (%s) %s", player_globals.parray[pp1].name,
          ratstrii(GetRating(&player_globals.parray[pp1], type), pp1),
          colorstr[white + 1]);
    pprintf_highlight(pp1, "%s", player_globals.parray[partner].name);
    pprintf_prompt(pp1, " (%s) %s.\n",
          ratstrii(GetRating(&player_globals.parray[partner], type), partner),
          game_str(rated, wt , winc, bt , binc, category, board));
    Bell(pp1);
  }

  check_lists_match (p,p1);

  print_match_rating_info (p,p1,type,rated);

  pprintf_prompt(p1, "You can \"accept\" or \"decline\", or propose different parameters.\n");

  return COM_OK;
}
Exemplo n.º 19
0
    Term* TermFactory::create(const std::string& className,
            const std::vector<scalar>& params) const {
        int requiredParams = -1;
        if (className == Discrete().className()) {
            if ((int)params.size() % 2 == 0) {
                Discrete* term = new Discrete();
                for (int i = 0; i < (int)params.size() - 1; i += 2) {
                    term->x.push_back(params.at(i));
                    term->y.push_back(params.at(i+1));
                }
                return term;
            } else {
                std::ostringstream ex;
                ex << "[syntax error] a discrete term requires an even list of values, "
                        "but found <" << params.size() << "> values";
                throw fl::Exception(ex.str(), FL_AT);
            }
        }

        if (className == Bell().className()) {
            if ((int)params.size() >= (requiredParams = 3)) {
                return new Bell("", params.at(0), params.at(1), params.at(2));
            }
        }

        if (className == Gaussian().className()) {
            if ((int)params.size() >= (requiredParams = 2)) {
                return new Gaussian("", params.at(0), params.at(1));
            }
        }

        if (className == GaussianProduct().className()) {
            if ((int)params.size() >= (requiredParams = 4)) {
                return new GaussianProduct("", params.at(0), params.at(1), params.at(2), params.at(3));
            }
        }

        if (className == PiShape().className()) {
            if ((int)params.size() >= (requiredParams = 4)) {
                return new PiShape("", params.at(0), params.at(1), params.at(2), params.at(3));
            }
        }

        if (className == Ramp().className()) {
            if ((int)params.size() >= (requiredParams = 2)) {
                return new Ramp("", params.at(0), params.at(1));
            }
        }


        if (className == Rectangle().className()) {
            if ((int)params.size() >= (requiredParams = 2)) {
                return new Rectangle("", params.at(0), params.at(1));
            }
        }

        if (className == SShape().className()) {
            if ((int)params.size() >= (requiredParams = 2)) {
                return new SShape("", params.at(0), params.at(1));
            }
        }

        if (className == Sigmoid().className()) {
            if ((int)params.size() >= (requiredParams = 2)) {
                return new Sigmoid("", params.at(0), params.at(1));
            }
        }

        if (className == SigmoidDifference().className()) {
            if ((int)params.size() >= (requiredParams = 4)) {
                return new SigmoidDifference("", params.at(0), params.at(1), params.at(2), params.at(3));
            }
        }

        if (className == SigmoidProduct().className()) {
            if ((int)params.size() >= (requiredParams = 4)) {
                return new SigmoidProduct("", params.at(0), params.at(1), params.at(2), params.at(3));
            }
        }

        if (className == Trapezoid().className()) {
            if ((int)params.size() >= (requiredParams = 4))
                return new Trapezoid("", params.at(0), params.at(1), params.at(2), params.at(3));
        }

        if (className == Triangle().className()) {
            if ((int)params.size() >= (requiredParams = 3))
                return new Triangle("", params.at(0), params.at(1), params.at(2));
        }

        if (className == ZShape().className()) {
            if ((int)params.size() >= (requiredParams = 2)) {
                return new ZShape("", params.at(0), params.at(1));
            }
        }

        if (requiredParams >= 0) {
            std::ostringstream ex;
            ex << "[factory error] Term of class<" + className + "> "
                    "requires " << requiredParams << " parameters";
            throw fl::Exception(ex.str(), FL_AT);
        }
        throw fl::Exception("[factory error] Term of class <" + className + "> not recognized", FL_AT);
    }
Exemplo n.º 20
0
int init (int argc, char *argv[])
{
    char    *p;
    int     rc = 0, oldmode, i;
    url_t   u;
    int     x0=-1, y0=-1, r=-1, c=-1;
    struct hostent     *remote;
    char    buffer[MAX_PATH];

    if (action == ACTION_TESTONLY) exit (0);
    if (action == ACTION_BADARGS)
    {
        usage ();
        exit (1);
    }

    if (options.keep_winsize)
    {
        r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows");
        c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols");
        if (r == 0 && c == 0) r = -1, c = -1;
    }

    if (options.keep_winpos)
    {
        x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0");
        y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0");
        if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1;
    }

    p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font");
    if (p[0] == '\0') p = NULL;

    fly_init (x0, y0, r, c, p);
    fly_mouse (options.mouse);
    wintitle = get_window_name ();

    if (fl_opt.platform == PLATFORM_OS2_VIO)
    {
        strcpy (buffer, paths.system_libpath);
        str_cats (buffer, "nftp.ico");
        if (access (buffer, R_OK) == 0)
            set_icon (buffer);
    }

    if (main_menu != NULL)
    {
        menu_activate (main_menu);
    }

    display.rshift = 0;
    display.lshift = 0;
    display.tabsize = 8;
    display.view[V_LEFT] = -1;
    display.view[V_RIGHT] = -1;
    display.cursor = V_LEFT;
    display.parsed = TRUE;

    for (i=0; i<MAX_SITE; i++)
    {
        site[i].set_up = FALSE;
        site[i].CC.na = 0;
        site[i].CC.n = 0;
    }

    // ignore "broken PIPE" signals
    signal (SIGPIPE, SIG_IGN);

    set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION);

    lcache.lda = 0;
    lcache.ld  = 0;
    lcache.L   = NULL;

    local[V_LEFT].dir.name = NULL;
    local[V_LEFT].dir.files = NULL;
    local[V_LEFT].dir.nfiles = 0;
    local[V_LEFT].sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local[V_LEFT].sortdirection = 1;
    else
        local[V_LEFT].sortdirection = -1;
    l_chdir (V_LEFT, NULL);

    local[V_RIGHT].dir.name = NULL;
    local[V_RIGHT].dir.files = NULL;
    local[V_RIGHT].dir.nfiles = 0;
    local[V_RIGHT].sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local[V_RIGHT].sortdirection = 1;
    else
        local[V_RIGHT].sortdirection = -1;
    l_chdir (V_RIGHT, NULL);


    PutLineIntoResp (RT_COMM, 0, "NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name);
    PutLineIntoResp (RT_RESP, 0, "Copyright (C) 1994--2000 Sergey Ayukov <*****@*****.**>");
    PutLineIntoResp (RT_RESP, 0, "Portions Copyright (C) Eric Young <*****@*****.**>");
    status.usage_interval = 0;
    if (!fl_opt.has_osmenu)
        PutLineIntoResp (RT_RESP, 0, MSG(M_RESP_F9_FOR_MENU));
    update (1);

    if (options.firewall_type != 0)
    {
        if (options.fire_server[0] == '\0')
        {
            fly_ask_ok (ASK_WARN, MSG(M_PROXY_ISNT_SPECIFIED));
            options.firewall_type = 0;
        }
        else
        {
            if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server))
            {
                firewall.fwip = inet_addr (options.fire_server);
            }
            else
            {
                PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_LOOKING_UP), options.fire_server);
                remote = gethostbyname (options.fire_server);
                if (remote == NULL)
                {
                    PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_CANNOT_RESOLVE), options.fire_server);
                    options.firewall_type = 0;
                }
                else
                {
                    firewall.fwip = *((unsigned long *)(remote->h_addr));
                    PutLineIntoResp (RT_COMM,0, MSG(M_RESP_FOUND), remote->h_name);
                }
            }
        }
    }

    // read password cache
    psw_read ();

    // analyze arguments
    switch (action)
    {
    case ACTION_NONE:
        if (options.download_path != NULL)
        {
            l_chdir (V_RIGHT, options.download_path);
        }
        else
        {
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory-left");
            if (p[0] != '\0')
            {
                l_chdir (V_LEFT, p);
            }
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory-right");
            if (p[0] != '\0')
            {
                l_chdir (V_RIGHT, p);
            }
        }
        switch (options.start_prompt)
        {
        case 1:  return FMSG_BASE_MENU + KEY_GEN_LOGIN;
        case 2:  return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        case 3:  return FMSG_BASE_MENU + KEY_GEN_HISTORY;
        case 5:  return FMSG_BASE_MENU + KEY_MENU;
        }
        return 0;

    case ACTION_DOWNLOAD:
    case ACTION_UPLOAD:
        oldmode = status.batch_mode;
        status.batch_mode = TRUE;
        if (action == ACTION_DOWNLOAD) rc = do_get (optarg1);
        if (action == ACTION_UPLOAD) rc = do_put (optarg1);
        //set_view_mode (VIEW_CONTROL);
        //update (1);
        if (rc && !cmdline.batchmode) fly_ask_ok (0, MSG(M_TRANSFER_FAILED), optarg1);
        if ((disc_after && rc == 0) || cmdline.batchmode)
        {
            Logoff (0);
            terminate ();
            exit (0);
        }
        status.batch_mode = oldmode;
        return 0;

    //case ACTION_CMDLIST:
    //    rc = runscript (optarg1);
    //    return 0;

    case ACTION_NICK_BOOK:
    case ACTION_NICK_HIST:
        if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0;
        if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0;
        rc = Login (-1, &u, V_LEFT);
        if (rc) return 0;
        if ((action == ACTION_NICK_BOOK && MAX_SITE > 1 && optarg2 != NULL &&
             bookmark_nickname (optarg2, &u) == 1) ||
            (action == ACTION_NICK_HIST && MAX_SITE > 1 && optarg2 != NULL &&
             history_nickname (optarg2, &u) == 1))
        {
            rc = Login (-1, &u, V_RIGHT);
        }
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_OPEN_BOOKMARKS:
        return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;

    case ACTION_OPEN_HISTORY:
        return FMSG_BASE_MENU + KEY_GEN_HISTORY;

    case ACTION_LOGIN:
        // if download_path was specified in nftp.ini, set it now
        if (options.download_path != NULL)
        {
            l_chdir (V_LEFT, options.download_path);
            l_chdir (V_RIGHT, options.download_path);
        }
        dmsg ("optarg1 is [%s]\n", optarg1);
        parse_url (optarg1, &u);
        rc = Login (-1, &u, V_LEFT);
        if (MAX_SITE > 1 && optarg2 != NULL)
        {
            parse_url (optarg2, &u);
            rc = Login (-1, &u, V_RIGHT);
        }
        // attempt to download file if chdir failed
        /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0)
        {
            rc = do_get (optarg1);
        }
        if (rc) return 0;
        */
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_TESTONLY:
        terminate ();
        exit (0);
    }
    fly_error ("internal error in init()");
    return 0;
}
Exemplo n.º 21
0
int init (int argc, char *argv[])
{
    char    *p;
    int     rc = 0, oldmode;
    url_t   u;
    int     x0=-1, y0=-1, r=-1, c=-1;
    struct hostent     *remote;
    char    buffer[MAX_PATH];

    if (action == ACTION_TESTONLY) exit (0);
    if (action == ACTION_BADAGS)
    {
        usage ();
        exit (1);
    }

    if (options.keep_winsize)
    {
        r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows");
        c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols");
        if (r == 0 && c == 0) r = -1, c = -1;
    }

    if (options.keep_winpos)
    {
        x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0");
        y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0");
        if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1;
    }

    p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font");
    if (p[0] == '\0') p = NULL;

    fly_init (x0, y0, r, c, p);
    if (options.show_hw_cursor) video_cursor_state (1);
    fly_mouse (options.mouse);
    wintitle = get_window_name ();

    if (fl_opt.platform == PLATFORM_OS2_VIO)
    {
        strcpy (buffer, paths.system_libpath);
        str_cats (buffer, "nftp.ico");
        if (access (buffer, R_OK) == 0)
            set_icon (buffer);
    }

    if (main_menu != NULL)
    {
        menu_activate (main_menu);
        adjust_menu_status ();
    }
    
    display.dir_mode = options.defaultdirmode;
    display.view_mode = VIEW_CONTROL;
    
    display.rshift = 0;
    display.lshift = 0;
    display.tabsize = 8;
    if (options.slowlink)
        set_view_mode (VIEW_REMOTE);
    else
        set_view_mode (VIEW_CONTROL);
    site.maxndir = 1024;
    site.dir = malloc (sizeof(directory)*site.maxndir);

    // ignore "broken PIPE" signals
    signal (SIGPIPE, SIG_IGN);

    set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION);

    local.dir.files = NULL;
    local.sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local.sortdirection = 1;
    else
        local.sortdirection = -1;
    build_local_filelist (NULL);

    site.batch_mode = FALSE;
    site.chunks = NULL;

    PutLineIntoResp2 ("NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name);
    PutLineIntoResp1 ("Copyright (C) 1994-2003 Sergey Ayukov <*****@*****.**>");
    PutLineIntoResp1 ("Portions Copyright (C) Eric Young <*****@*****.**>");
    //PutLineIntoResp1 ("Portions Copyright (C) Martin Nicolay <*****@*****.**>");
    status.usage_interval = 0;
    if (!fl_opt.has_osmenu)
        PutLineIntoResp1 (M("Press F9 or Ctrl-F for menu"));
    update (1);

    if (options.firewall_type != 0)
    {
        if (options.fire_server[0] == '\0')
        {
            fly_ask_ok (ASK_WARN, M("Firewall proxy host isn't specified in NFTP.INI"));
            options.firewall_type = 0;
        }
        else
        {
            if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server))
            {
                firewall.fwip = inet_addr (options.fire_server);
            }
            else
            {
                PutLineIntoResp2 (M("Looking up '%s'"), options.fire_server);
                remote = gethostbyname (options.fire_server);
                if (remote == NULL)
                {
                    PutLineIntoResp2 (M("Cannot find '%s'"), options.fire_server);
                    options.firewall_type = 0;
                }
                else
                {
                    firewall.fwip = *((unsigned long *)(remote->h_addr));
                    PutLineIntoResp2 (M("Found '%s'"), remote->h_name);
                }
            }
        }
    }

    // read password cache
    psw_read ();
        
    // analyze arguments
    switch (action)
    {
    case 0:
        if (options.download_path != NULL)
        {
            set_local_path (options.download_path);
        }
        else
        {
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory");
            if (p[0] != '\0')
                set_local_path (p);
        }
        build_local_filelist (NULL);
        switch (options.start_prompt)
        {
        case 1:  return FMSG_BASE_MENU + KEY_GEN_LOGIN;
        case 2:  return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        case 3:  return FMSG_BASE_MENU + KEY_GEN_HISTORY;
        case 5:  return FMSG_BASE_MENU + KEY_MENU;
        }
        return 0;
        
    case ACTION_DOWNLOAD:
    case ACTION_UPLOAD:
        oldmode = site.batch_mode;
        site.batch_mode = TRUE;
        if (action == ACTION_DOWNLOAD) rc = do_get (optarg1);
        if (action == ACTION_UPLOAD) rc = do_put (optarg1);
        //set_view_mode (VIEW_CONTROL);
        //update (1);
        if (rc && !cmdline.batchmode)
            fly_ask_ok (0, M("Transfer of '%s' has failed"), optarg1);
        if ((disc_after && rc == 0) || cmdline.batchmode)
        {
            Logoff ();
            terminate ();
            exit (0);
        }
        site.batch_mode = oldmode;
        return 0;

    case ACTION_CMDLIST:
        rc = runscript (optarg1);
        return 0;

    case ACTION_NICK_BOOK:
    case ACTION_NICK_HIST:
        if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0;
        if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0;
        rc = Login (&u);
        if (rc) return 0;
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_OPEN_BOOKMARKS:
        return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        
    case ACTION_OPEN_HISTORY:
        return FMSG_BASE_MENU + KEY_GEN_HISTORY;

    case ACTION_LOGIN:
        // if download_path was specified in nftp.ini, set it now
        if (options.download_path != NULL)
            set_local_path (options.download_path);
        build_local_filelist (NULL);
        parse_url (optarg1, &u);
        rc = Login (&u);
        // attempt to download file if chdir failed
        /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0)
        {
            rc = do_get (optarg1);
        }
        if (rc) return 0;
        */
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_TESTONLY:
        terminate ();
        exit (0);
    }
    fly_error ("internal error in init()");
    return 0;
}
Exemplo n.º 22
0
const char * CGenericSerialConsole::AddChar ( const uint8_t c,
                                       uint32_t * const retCmdLen )
{
  // Trace the incoming characters.
  if ( false )
  {
    if ( IsPrintableAscii(c) )
      SerialPrintf( "0x%02X (%3u, %c)" DBG_EOL, c, c, c  );
    else
      SerialPrintf( "0x%02X (%3u)" DBG_EOL, c, c );
  }

  bool isCmdReady = false;

  switch ( m_state )
  {
  case stIdle:
    isCmdReady = ProcessChar( c );
    break;

  case stEscapeReceived:
    if ( c == '[' )  // CSI (0x5B)
    {
      m_state = stEscapeBracketReceived;
    }
    else
    {
      Bell();
      m_state = stIdle;
    }
    break;

  case stEscapeBracketReceived:
    ProcessCharAfterEscapeBracket( c );
    break;

  default:
    assert( false );
    break;
  }

  if ( false )
  {
    SerialPrintf( "Char: 0x%02X, cmd begin: %u, end: %u, len: %u, pos: %u" DBG_EOL,
                  c,
                  unsigned( m_cmdBeginPos ),
                  unsigned( m_cmdEndPos ),
                  unsigned( GetCircularDistance( m_cmdBeginPos, m_cmdEndPos, BUF_LEN ) ),
                  unsigned( m_cursorPos ) );
  }

  if ( isCmdReady )
  {
    assert( m_cmdBeginPos < BUF_LEN );
    assert( m_cmdEndPos   < BUF_LEN );

    m_buffer[ m_cmdEndPos ] = 0;
    const uint32_t cmdLen = GetCircularDistance( m_cmdBeginPos, m_cmdEndPos, BUF_LEN );

    char * const first  = &m_buffer[0];
    char * const last   = &m_buffer[BUF_LEN];
    char * const middle = &m_buffer[m_cmdBeginPos];

    std::rotate( first, middle, last );

    assert( cmdLen < BUF_LEN );

    m_cmdBeginPos = cmdLen;
    m_cmdEndPos   = cmdLen;
    m_cursorPos   = cmdLen;

    // SerialPrint( "Command ready." DBG_EOL );

    assert( strlen( m_buffer ) == cmdLen );

    *retCmdLen = cmdLen;
    return m_buffer;
  }
  else
  {
    *retCmdLen = 0;
    return NULL;
  }
}
Exemplo n.º 23
0
void GTerm::bell() { Bell();
}