Esempio n. 1
0
void Interpret(char expr[])
{
  SetIntSignal(True);
  if(commandline(expr))
    ;
  else if(seterror()==0)
  {
    initstack();
    restoretemplates();
    CloseAllIOFiles();
    interrupted = False;
    if(parseinput(expr))
      checkexpression(top(), True);
    else
    {
      checkexpression(top(), False);
      settop(modify_expression(top()));
      starttiming();
      toplevel();
      stoptiming();
    }
  }
  SetIntSignal(False);
  initstack();
  restoretemplates();
  CloseAllIOFiles();
  interrupted = False;
  Write("\n");
}
Esempio n. 2
0
int main(int argc, char * argv[])
{
	if(commandline(argc, argv))
		process(argv[2]);
	else
		process(NULL);

    return(0);
}
Esempio n. 3
0
		void createCommandLineDescription() {
			Kicker::createCommandLineDescription();

			commandline().addOption(
				"Generic", "script0",
				"path to the script called when configurable button0 is pressed; "
				"EventID, arrival count, magnitude and the additional location information string are passed as parameters $1, $2, $3 and $4",
				&_script0);

			commandline().addOption(
				"Generic", "script1",
				"path to the script called when configurable button1 is pressed; "
				"EventID, arrival count, magnitude and the additional location information string are passed as parameters $1, $2, $3 and $4",
				&_script1);

			commandline().addOption(
				"Generic", "load-event-db",
				"Number of days to load from database",
				&_preloadDays);
		}
Esempio n. 4
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
void Import::createCommandLineDescription() {
	Application::createCommandLineDescription();
	Client::CommandLine& cl = commandline();
	std::string clGroupName = "scimport";
	cl.addGroup(clGroupName.c_str());
	cl.addOption(clGroupName.c_str(), "sink,o", "Sink master", static_cast<std::string*>(NULL));
	cl.addOption(clGroupName.c_str(), "import,i", "Switch to import mode (default is relay)\n"
		             "import mode: You have your own routing table specified\n"
		             "relay mode: The routing table will be calculated automatically");
	cl.addOption(clGroupName.c_str(), "no-filter", "Don't filter messages");
	cl.addOption(clGroupName.c_str(), "routeunknowngroup", "Route unknown groups to the default group IMPORT_GROUP");
	cl.addOption(clGroupName.c_str(), "ignore-groups", "Ignore user specified groups");
	cl.addOption(clGroupName.c_str(), "test", "Do not send any messages");
}
Esempio n. 5
0
int main(int argc, char **argv)
{
   set_defaults();

   if(!commandline(argc,argv))      return 1;

   if(!read_config(opts.cconfig))   return 1;

   /* creates a fork() */
   if(!mice_handler())              return 1;

   /* listen to messages: exits only on failure or shutdown */
//   listen_ipc();

//   shutdown_gpm2();

   return 0;
}
Esempio n. 6
0
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
bool Import::init() {
	if (!Application::init())
		return false;

	if ( !Filter::Init(*this) ) return false;

	if (commandline().hasOption("test"))
		_test = true;

	if (commandline().hasOption("no-filter"))
		_filter = false;

	if (commandline().hasOption("import"))
		_mode = IMPORT;

	if (commandline().hasOption("routeunknowngroup"))
		_routeUnknownGroup = true;

	if (commandline().hasOption("ignore-groups"))
		_useSpecifiedGroups = false;

	try {
		configGetString("routingtable");
		_mode = IMPORT;
	}
	catch ( ... ) {}

	std::string sinkName = "localhost";
	if (commandline().hasOption("sink")) {
		sinkName = commandline().option<std::string>("sink");
	}
	else {
		try {
		sinkName = configGetString("sink");
		}
		catch (Config::Exception& ) {}
	}

	if (connectToSink(sinkName) != Core::Status::SEISCOMP_SUCCESS)
		return false;

	return true;
}
Esempio n. 7
0
bool Console::_on_input_validation(CEGUI::EventArgs const& e)
{
    std::string commandline(m_input->getText().c_str());

    // We know the window is m_input so it is of no use
    (void)e;

    // If the user was using the history, erase the previous "current" input
    if (m_history_cur != m_history.end())
    {
        m_history.pop_back();
        m_history_cur = m_history.end();
    }

    // Never make the history repeat itself, as my history teacher told me (also, ignore empty strings)
    if (commandline != m_history.back() && commandline.find_first_not_of(' ') != std::string::npos)
        _history_add(m_input->getText().c_str());

    execute(std::string(m_input->getText().c_str()));
    m_input->setText("");
    return true;
}
Esempio n. 8
0
void 
print_channel(struct deviceinfo *unit)
{
	int i = 0, option = EOF, scr_opt = 0;

	int rc;
	fd_set rfds;
	struct timeval tv;
	int max_fd;

	struct digi_node node;
	struct digi_chan chan;
	int port = 0;
	char ttyname[100];


	int d_invokes_capture = 1;   /* 0 if 'D' should invoke "exam_panel" */
	                             /* 1 if 'D' should invoke "scope_panel" */


	WINDOW *chanwin = GetWin(ChanWin);

	/* 
	 * scr_opt is just used to determine which field to 
	 * highlight.
	 */

	show_panel (GetPan(ChanWin));
	update_panels ();
	doupdate ();

	DPAOpenDevice(unit);

	while ((option != 'Q') && (option != 'q') && (option != ESC))
	{

		/* Get port info for current port */
		DPAGetNode(unit, &node);
		DPAGetChannel(unit, &chan, port);

		if (DPAGetPortName(unit, &node, &chan, port, ttyname) == NULL) {
			ttyname[0] = '\0';
		}

		max_fd = 0;
		FD_ZERO(&rfds);
		FD_SET(0, &rfds);

		mvwprintw (chanwin, 1, 2, "Device Description: %-54.54s", node.nd_ps_desc);

		mvwprintw (chanwin, 5, 35, "Name: %-10.10s", ttyname);

		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));

		mvwprintw (chanwin, 5, 56, "Status: %-10.10s",
		           chan.ch_open ? "Open" : "Closed");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));

		if (scr_opt == 1)
		{
			wattrset (chanwin, make_attr (A_REVERSE | A_STANDOUT, WHITE, BLACK));
			mvwprintw (chanwin, 3, 5, "Unit IP Address: %-15.15s", unit->host);
			wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
			mvwprintw (chanwin, 5, 8, "Port Number : %-2d", port + 1);
		}
		else if (scr_opt == 2)
		{
			wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
			mvwprintw (chanwin, 3, 5, "Unit IP Address: %-15.15s", unit->host);
			wattrset (chanwin, make_attr (A_REVERSE | A_STANDOUT, WHITE, BLACK));
			mvwprintw (chanwin, 5, 8, "Port Number : %-2d", port + 1);
			wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		}
		else
		{
			mvwprintw (chanwin, 3, 5, "Unit IP Address: %-15.15s", unit->host);
			mvwprintw (chanwin, 5, 8, "Port Number : %-2d", port + 1);
		}

		if (!vanilla) wattrset (chanwin, make_attr (A_ALTCHARSET, GREEN, BLACK));
		else wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));

		for (i = 0; i < 62; i++)
			mvwaddch (chanwin, 6, 8 + i, mapchar(ACS_HLINE));
		mvwaddch (chanwin, 6, 7, mapchar(ACS_ULCORNER));
		mvwaddch (chanwin, 6, 70, mapchar(ACS_URCORNER));
		mvwaddch (chanwin, 7, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 7, 70, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 8, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 8, 70, mapchar(ACS_VLINE));

		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		mvwprintw (chanwin, 12, 24, "Signal Active = ");
		wattrset (chanwin, make_attr (A_STANDOUT, WHITE, GREEN));
		waddstr (chanwin, "X");

		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		mvwaddstr (chanwin, 12, 46, "Inactive =");
		wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));
		mvwaddstr (chanwin, 12, 57, "_");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));

		mvwaddstr (chanwin, 8, 13,
				   "Tx:             RTS  CTS  DSR  DCD  DTR  RI  OFC  IFC");
		mvwaddstr (chanwin, 9, 13,
				   "Rx:                                                  ");

		if (!vanilla)
			wattrset (chanwin, make_attr (A_ALTCHARSET, GREEN, BLACK));
		else
			wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));

		mvwaddch (chanwin, 9, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 9, 70, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 10, 7, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 10, 70, mapchar(ACS_VLINE));
		mvwaddch (chanwin, 11, 7, mapchar(ACS_LLCORNER));
		mvwaddch (chanwin, 11, 70, mapchar(ACS_LRCORNER));

		for (i = 0; i < 62; i++)
			mvwaddch (chanwin, 11, 8 + i, mapchar(ACS_HLINE));

		wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));

		mvwprintw (chanwin, 8, 17, "%-10d", chan.ch_txcount);
		mvwprintw (chanwin, 9, 17, "%-10d", chan.ch_rxcount);

		{
			int msigs=6;
			int   mbits[] = { MS_RTS, MS_CTS, MS_DSR, MS_DCD, MS_DTR, MS_RI };
			char *mhstr[] = { "X",    "X",    "X",    "X",    "X",    "X"   };
			char *mlstr[] = { "_",    "_",    "_",    "_",    "_",    "_"   };
			int   mpos[]  = { 30,     35,     40,     45,     50,     55    };
			int sig=0;

			for(sig = 0; sig < msigs; sig++)
			{
				if (chan.ch_s_mstat & mbits[sig])
				{
					wattrset (chanwin, make_attr (A_STANDOUT, WHITE, GREEN));
					mvwprintw (chanwin, 9, mpos[sig], mhstr[sig]);
				}
				else
				{
					wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));
					mvwprintw (chanwin, 9, mpos[sig], mlstr[sig]);
				}
			}
		}
		{
			int events=2;
			int   ebits[] = { EV_OPALL, EV_IPALL };
			char *ehstr[] = { "X",      "X"      };
			char *elstr[] = { "_",      "_"      };
			int   epos[]  = { 59,       64       };
			int ev=0;

			for(ev=0; ev<events; ev++)
			{
				if (chan.ch_s_estat & ebits[ev])
				{
					wattrset (chanwin, make_attr (A_STANDOUT, WHITE, GREEN));
					mvwprintw (chanwin, 9, epos[ev], ehstr[ev]);
				}
				else
				{
					wattrset (chanwin, make_attr (A_NORMAL, GREEN, BLACK));
					mvwprintw (chanwin, 9, epos[ev], elstr[ev]);
				}
			}
		}

		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));
		mvwaddstr (chanwin, 14, 1, "  Input Modes ");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		wprintw (chanwin, "                                                           ");
		wmove (chanwin, 14, 15);

		if (chan.ch_s_iflag & IF_IGNBRK)
			wprintw (chanwin, ":IGNBRK");
		if (chan.ch_s_iflag & IF_BRKINT)
			wprintw (chanwin, ":BRKINT");
		if (chan.ch_s_iflag & IF_IGNPAR)
			wprintw (chanwin, ":IGNPAR");
		if (chan.ch_s_iflag & IF_PARMRK)
			wprintw (chanwin, ":PARMRK");
		if (chan.ch_s_iflag & IF_INPCK)
			wprintw (chanwin, ":INPCK");
		if (chan.ch_s_iflag & IF_ISTRIP)
			wprintw (chanwin, ":ISTRIP");
		if (chan.ch_s_iflag & IF_IXON)
			wprintw (chanwin, ":IXON");
		if (chan.ch_s_iflag & IF_IXANY)
			wprintw (chanwin, ":IXANY");
		if (chan.ch_s_iflag & IF_IXOFF)
			wprintw (chanwin, ":IXOFF");
		if (chan.ch_s_xflag & XF_XIXON)
			wprintw (chanwin, ":IXONA");
		if (chan.ch_s_xflag & XF_XTOSS)
			wprintw (chanwin, ":ITOSS");
		if (chan.ch_s_iflag & IF_DOSMODE)
			wprintw (chanwin, ":DOSMODE");

		wprintw (chanwin, ":");
		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));
		mvwprintw (chanwin, 15, 1, " Output Modes ");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		wprintw (chanwin, "                                                           ");
		wmove (chanwin, 15, 15);

		if (chan.ch_s_xflag & XF_XCASE)
			wprintw (chanwin, ":XCASE");
		if (chan.ch_s_oflag & OF_OLCUC)
			wprintw (chanwin, ":OLCUC");
		if (chan.ch_s_oflag & OF_ONLCR)
			wprintw (chanwin, ":ONLCR");
		if (chan.ch_s_oflag & OF_OCRNL)
			wprintw (chanwin, ":OCRNL");
		if (chan.ch_s_oflag & OF_ONOCR)
			wprintw (chanwin, ":ONOCR");
		if (chan.ch_s_oflag & OF_ONLRET)
			wprintw (chanwin, ":ONLRET");

		/* TODO -- tab expansion / TABDLY interpretation */

		wprintw (chanwin, ":");
		wattrset (chanwin, make_attr (A_BOLD, WHITE, BLACK));
		mvwprintw (chanwin, 16, 1, "Control Modes ");
		wattrset (chanwin, make_attr (A_NORMAL, WHITE, BLACK));
		/*
		 * clear the field, then write the new one
		 */
		wprintw (chanwin, "                                                              ");
		wmove (chanwin, 16, 15);

		if (chan.ch_open) {
/* Jira RP-77: In early stages of a port open, ch_open is set before ch_s_brate
 * is initialized, which, undetected, causes an arithmetic exception here.
 */
                	if (chan.ch_s_brate)
                		wprintw (chanwin, ":%d Baud", PDIVIDEND / chan.ch_s_brate);
			else
                		wprintw (chanwin, ":?? Baud");

			switch (chan.ch_s_cflag & CF_CSIZE)
			{
			case CF_CS5:
				wprintw (chanwin, ":5 Char Bits");
				break;
			case CF_CS6:
				wprintw (chanwin, ":6 Char Bits");
				break;
			case CF_CS7:
				wprintw (chanwin, ":7 Char Bits");
				break;
			case CF_CS8:
				wprintw (chanwin, ":8 Char Bits");
				break;
			default:
				wprintw (chanwin, ":No Char Bits");
				break;
			}

			if (chan.ch_s_cflag & CF_CSTOPB)
				wprintw (chanwin, ":2 Stop Bits");
			else
				wprintw (chanwin, ":1 Stop Bits");

			if (chan.ch_s_cflag & CF_PARENB)
			{
				if (chan.ch_s_xflag & XF_XPAR)
				{
					if (chan.ch_s_cflag & CF_PARODD)
						wprintw (chanwin, ":Parity Odd");
					else
						wprintw (chanwin, ":Parity Even");
				}
				else
				{
					if (chan.ch_s_cflag & CF_PARODD)
						wprintw (chanwin, ":Parity Space");
					else
						wprintw (chanwin, ":Parity Mark");
				}
			}
			else
			{
				wprintw (chanwin, ":No Parity");
			}
		}
		else {
                	wprintw (chanwin, ":");
		}

		wattrset (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));

		commandline (clbuf, helpstr, "ESC=Quit", lrudstr,
		             "T=LoopBack", "D=DataMonitor", "^P=Print", NULL);
		mvwprintw (GetWin(MainWin), KEY_LINE, 0, clbuf);

		wattroff (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		wrefresh (GetWin(MainWin));
		wrefresh (chanwin);

		change_term (0, TIMEOUT);

		option = EOF;

		tv.tv_sec = 0;  tv.tv_usec = 500000;
		rc = select( max_fd + 1, &rfds, NULL, NULL, &tv );

		if (rc < 0)
		{
			fprintf (stderr, "FATAL ERROR: select failure.\n");
			EndCurses (-13);
			/* FIXME: This code will not be executed as 
			   EndCurses() calls exit(). */
			exit (-2);
		}
		else if (rc > 0)
		{
			if (FD_ISSET(0, &rfds))
			{
				option = getch();
			}

		}
		else
		{
			scr_opt = 0;
		}

		/*
		 * If the user hasn't selected anything keep doing the 
		 * original screen. 
		 */

		switch (option)
		{
		case EOF:
			break;

		case '':
			scr_opt = 0;
			refresh_screen ();
			break;

#ifdef KEY_LEFT
		case KEY_LEFT:
#endif
		case 'H':
		case 'h':

			port--;
			if (port < 0)
				port = unit->nports - 1;

			scr_opt = 2;
			break;

#ifdef KEY_RIGHT
		case KEY_RIGHT:
#endif
		case 'L':
		case 'l':

			port++;
			if (port >= (int) unit->nports)
				port = 0;

			scr_opt = 2;
			break;

#ifdef KEY_UP
		case KEY_UP:
#endif
		case 'K':
		case 'k':
			{
				int curr_unit = unit->unit_number;
				do {
					curr_unit--;
					if (curr_unit < 0)
						curr_unit = num_devices - 1;
				}
				while (device_info[curr_unit].status != UP);

				unit = &device_info[curr_unit];

				if (port >= (int) unit->nports)
					port = unit->nports - 1;
			}

			scr_opt = 1;
			break;

#ifdef KEY_DOWN
		case KEY_DOWN:
#endif
		case 'J':
		case 'j':
			{
				int curr_unit = unit->unit_number;
				do {
					if (curr_unit < num_devices - 1)
						curr_unit++;
					else
						curr_unit = 0;
				}
				while (device_info[curr_unit].status != UP);

				unit = &device_info[curr_unit];

				if (port >= (int) unit->nports)
					port = unit->nports - 1;

			}

			scr_opt = 1;
			break;

		case 'q':
		case 'Q':
		case ESC:
			hide_panel (GetPan(ChanWin));
			erase_win (ChanWin);
			update_panels ();
			doupdate ();
			scr_opt = 0;
			break;

		case 'T':
		case 't':
			scr_opt = 0;

			hide_panel (GetPan(ChanWin));
			update_panels ();
			doupdate ();

			handle_loopback(unit, &node, &chan, port);

			change_term (0, TIMEOUT);

			show_panel (GetPan(ChanWin));
			update_panels ();
			doupdate ();
			wrefresh (chanwin);
			break;

		case 'D':
		case 'd':
			scr_opt = 0;

			{
				int invoke_one = 1;

				while (invoke_one)
				{
					if (d_invokes_capture)
					{
						invoke_one = handle_scope (unit, &node,  &chan, port);
					}
					else
					{
						invoke_one = handle_exam (unit, &node, port);
					}

					if (invoke_one)
						d_invokes_capture = 1 - d_invokes_capture;
				}
			}

			touchwin (chanwin);
			wrefresh (chanwin);
			update_panels ();
			doupdate ();
			break;


#ifdef KEY_PRINT
		case KEY_PRINT:
#endif
		case '':
			scr_opt = 0;

			screen_save (ChanWin, logfile);
			touchwin (chanwin);
			wrefresh (chanwin);
			update_panels ();
			doupdate ();
			break;

		case KEY_F (1):		   /*  Help info  */
		case '?':
			scr_opt = 0;
			info_screen (dpa_info2, dpa_info2_len, NULL);
			update_panels ();
			doupdate ();
			break;

		default:
			scr_opt = 0;
			mvwprintw (chanwin, 16, 60, "Invalid key");
			wrefresh (chanwin);
			sleep (1);
			mvwprintw (chanwin, 16, 60, "           ");
			wrefresh (chanwin);
			break;
		}						   /* End Case */
	}							   /* End While */
}
Esempio n. 9
0
//static
void VolumeManager::InitConfig()
{
  MOZ_ASSERT(MessageLoop::current() == XRE_GetIOMessageLoop());

  // This function uses /system/etc/volume.cfg to add additional volumes
  // to the Volume Manager.
  //
  // This is useful on devices like the Nexus 4, which have no physical sd card
  // or dedicated partition.
  //
  // The format of the volume.cfg file is as follows:
  // create volume-name mount-point
  // configure volume-name preference preference-value
  // Blank lines and lines starting with the hash character "#" will be ignored.

  ScopedCloseFile fp;
  int n = 0;
  char line[255];
  const char *filename = "/system/etc/volume.cfg";
  if (!(fp = fopen(filename, "r"))) {
    LOG("Unable to open volume configuration file '%s' - ignoring", filename);
    return;
  }
  while(fgets(line, sizeof(line), fp)) {
    n++;

    if (line[0] == '#')
      continue;

    nsCString commandline(line);
    nsCWhitespaceTokenizer tokenizer(commandline);
    if (!tokenizer.hasMoreTokens()) {
      // Blank line - ignore
      continue;
    }

    nsCString command(tokenizer.nextToken());
    if (command.EqualsLiteral("create")) {
      if (!tokenizer.hasMoreTokens()) {
        ERR("No vol_name in %s line %d",  filename, n);
        continue;
      }
      nsCString volName(tokenizer.nextToken());
      if (!tokenizer.hasMoreTokens()) {
        ERR("No mount point for volume '%s'. %s line %d",
             volName.get(), filename, n);
        continue;
      }
      nsCString mountPoint(tokenizer.nextToken());
      RefPtr<Volume> vol = FindAddVolumeByName(volName);
      vol->SetFakeVolume(mountPoint);
      continue;
    }
    if (command.EqualsLiteral("configure")) {
      if (!tokenizer.hasMoreTokens()) {
        ERR("No vol_name in %s line %d", filename, n);
        continue;
      }
      nsCString volName(tokenizer.nextToken());
      if (!tokenizer.hasMoreTokens()) {
        ERR("No configuration name specified for volume '%s'. %s line %d",
             volName.get(), filename, n);
        continue;
      }
      nsCString configName(tokenizer.nextToken());
      if (!tokenizer.hasMoreTokens()) {
        ERR("No value for configuration name '%s'. %s line %d",
            configName.get(), filename, n);
        continue;
      }
      nsCString configValue(tokenizer.nextToken());
      RefPtr<Volume> vol = FindVolumeByName(volName);
      if (vol) {
        vol->SetConfig(configName, configValue);
      } else {
        ERR("Invalid volume name '%s'.", volName.get());
      }
      continue;
    }
    if (command.EqualsLiteral("ignore")) {
      // This command is useful to remove volumes which are being tracked by
      // vold, but for which we have no interest.
      if (!tokenizer.hasMoreTokens()) {
        ERR("No vol_name in %s line %d", filename, n);
        continue;
      }
      nsCString volName(tokenizer.nextToken());
      RemoveVolumeByName(volName);
      continue;
    }
    ERR("Unrecognized command: '%s'", command.get());
  }
}
Esempio n. 10
0
void 
handle_loopback (struct deviceinfo *unit, struct digi_node *node, struct digi_chan *chan, int port)
{
	char full_line[81];

	int i = 0, option = EOF;

	struct termios sv_tios;
	char test_data[TBUFSIZ + 1];
	char read_data[TBUFSIZ + 1];
	char string[200], ttyname[200];

	int r = 3;
	int rwfd;

	WINDOW *lbwin = GetWin(LBWin);

#define TITLE_LINE  1
#define DESC_LINE   2
#define DESC2_LINE  3
#define SEP_LINE    4
#define FIRST_DATA  5
#define SEP2_LINE   15
#define RESULT_LINE 16

	show_panel (GetPan(LBWin));
	update_panels ();
	doupdate ();

	next_result = 0;
	test_cases = 0;
	test_passes = 0;

	if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) {
		ttyname[0] ='\0';
	}

	while (option == EOF)
	{
		erase_win (LBWin);
		wattrset (lbwin, make_attr (A_BOLD, WHITE, BLUE));
		mvwprintw (lbwin, TITLE_LINE,  1, "%-*.*s", 76, 76, " ");
		mvwprintw (lbwin, RESULT_LINE, 1, "%-*.*s", 76, 76, " ");
		mvwprintw (lbwin, TITLE_LINE, 32, " Loop Back Test ");
		sprintf (full_line, "Tests Executed: %-12d Passed: %-12d Failed: %d",
		         test_cases, test_passes, test_cases - test_passes);
		mvwprintw (lbwin, RESULT_LINE,
		           center(LBWin, strlen(full_line)), full_line);

		sprintf (clbuf, "Unit IP Address: %s       Port #: %d            Name: %s",
		         unit->host, port + 1, ttyname);
		i = strlen (clbuf);
		mvwprintw (GetWin(LBWin), DESC_LINE, 1, "%*s",
		           GetWidth(LBWin) - 2, " ");

		mvwprintw (GetWin(LBWin), DESC2_LINE, 1, "%*s",
		           GetWidth(LBWin) - 2, " ");

		mvwprintw (lbwin, DESC2_LINE, 2, clbuf);

		mvwprintw (lbwin, DESC_LINE, 2, "Device Description: %-*.*s",
		           GetWidth(LBWin) - 2 - 2 - 2 - 20,
		           GetWidth(LBWin) - 2 - 2 - 2 - 20,
		           node->nd_ps_desc);

		if (!vanilla)
			wattrset (lbwin, make_attr (A_ALTCHARSET, CYAN, BLACK));
		else
			wattrset (lbwin, make_attr (A_NORMAL, CYAN, BLACK));

		wmove (lbwin, SEP_LINE, 1);
		for (i = 0; i < 77; i++)
			waddch (lbwin, mapchar(ACS_HLINE));
		mvwaddch (lbwin, SEP_LINE, 0, mapchar(ACS_LTEE));
		mvwaddch (lbwin, SEP_LINE, 77, mapchar(ACS_RTEE));

		wmove (lbwin, SEP2_LINE, 1);
		for (i = 0; i < 77; i++)
			waddch (lbwin, mapchar(ACS_HLINE));
		mvwaddch (lbwin, SEP2_LINE, 0, mapchar(ACS_LTEE));
		mvwaddch (lbwin, SEP2_LINE, 77, mapchar(ACS_RTEE));

		wattrset (lbwin, make_attr (A_NORMAL, WHITE, BLACK));

		wrefresh (lbwin);

		wattrset (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		commandline (clbuf, "Press ANY key to Halt the test", NULL);
		mvwprintw (GetWin(MainWin), KEY_LINE, 0, clbuf);
		wattroff (GetWin(MainWin), make_attr (A_NORMAL, WHITE, BLUE));
		wrefresh (GetWin(MainWin));

		change_term (0, 10);

		option = EOF;
		r = 5;

		if (chan->ch_open) {
			mvwprintw (lbwin, r++, 2, "***** Port is Busy.");
                        wrefresh(lbwin);
			test_cases++;
			sleep(1);
			goto user_input;
		}

		for (i = 0; i < 256; i++) {
			test_data[i] = (char) i;
		}

		test_data[TBUFSIZ]='\0';

		/* Get port name.  Can't run the test without it. */
		if (DPAGetPortName(unit, node, chan, port, ttyname) == NULL) {
                        mvwprintw (lbwin, r++, 2,
                        "***** Loop Back Test Failure. Port has no known tty name");
			test_cases++;
                        wrefresh (lbwin);
			sleep(1);
			goto user_input;
                }

		sprintf(string, "/dev/%s", ttyname);

		if( (rwfd = tty_open(string, &sv_tios )) < 0 ) {
			test_cases++;
			goto user_input;
		}

		tcflush(rwfd, TCIOFLUSH);

                if ((i = test_send (test_data, TBUFSIZ, rwfd)) != 0)
                {
                        mvwprintw (lbwin, r++, 2,
                        "***** Loop Back Test Failure=%d, Sending %d Bytes", i, TBUFSIZ);
                        wrefresh (lbwin);
                        tty_close (rwfd, &sv_tios);
                        test_cases++;
			goto user_input;
                }

                mvwprintw (lbwin, r++, 2, "Loop Back: %d Bytes Sent.", TBUFSIZ);
                wrefresh (lbwin);
                mvwprintw (lbwin, r++, 2, "Loop Back: Receiving %d Bytes.", TBUFSIZ);
                wrefresh (lbwin);

                if ((i = test_recv (read_data, TBUFSIZ, 5, rwfd)) != TBUFSIZ)
                {
                        mvwprintw (lbwin, r++, 2,
                                "***** Loop Back Failure=%d Receiving %d bytes.", i, TBUFSIZ);
                        wrefresh (lbwin);  
                        tty_close (rwfd, &sv_tios);
                        test_cases++;
			goto user_input;
                }


                /* Reset termios as before and close channel */
                tty_close (rwfd, &sv_tios);

                mvwprintw (lbwin, r++, 2, "Loop Back: Verifying %d bytes.", TBUFSIZ);
                wrefresh (lbwin);

                if (memcmp (test_data, read_data, TBUFSIZ))
                {
                        mvwprintw (lbwin, r++, 2,
                                "***** Loop Back Failure Verifying %d Bytes.", TBUFSIZ);
                        mvwprintw (lbwin, r++, 2, "***** Data Incorrectly Transferred.");
                        wrefresh (lbwin);
                        test_cases++;
			goto user_input;
                }
                else
                {
                        mvwprintw (lbwin, r++, 2, "Loop Back: Test Passed.");
                        wrefresh (lbwin);
                        test_cases++;
                        test_passes++;
                }


user_input:

		option = getch();


		/*
		 * If the user hasn't selected anything, loop.
		 * Otherwise, break.
		 */

		switch (option)
		{
		case EOF:
			break;

		case '':
			refresh_screen ();
			option = EOF;
			break;

#ifdef KEY_PRINT
		case KEY_PRINT:
#endif
		case '':
			screen_save (LBWin, logfile);
			touchwin (lbwin);
			wrefresh (lbwin);
			update_panels ();
			doupdate ();
			option = EOF;
			break;

		default:
			break;
		}						   /* End Case */
	}							   /* End While */

	hide_panel (GetPan(LBWin));
	update_panels ();
	doupdate ();
	return;
}
Esempio n. 11
0
int main(int argc, char *argv[])
#endif
{
#if WANT_CONCURRENT
    tbb::task_scheduler_init init(tbb::task_scheduler_init::deferred);
#endif

#ifdef _MSC_VER
  // Memory leak checking
  _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_ALLOC_MEM_DF | /*_CRTDBG_CHECK_CRT_DF | */_CRTDBG_DELAY_FREE_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#endif

  // Parse the command line
  std::auto_ptr<CommandLine> commandline(new CommandLine);

  Result result = eInvalidCommandLineArguments;
  
  if (!commandline->Parse(argc, argv))
  {
    banner();
    CommandLine::usage();
  }
  else
  {
    if (commandline->GetNoiseLevel() > CommandLine::nlSilent)
      banner();
      
#if WANT_CONCURRENT
    int p = commandline->GetNumThreads();
    if (p > 0)
    {
      cout << "Number of threads: " << p << endl;
      init.initialize(p);
    }
    else
      init.initialize();
#endif

    // Which operation was selected
    switch (commandline->GetOperation())
    {
    case CommandLine::opCreate:
      {
        // Create recovery data

        Par2Creator *creator = new Par2Creator;
        result = creator->Process(*commandline);
        delete creator;
      }
      break;
    case CommandLine::opVerify:
      {
        // Verify damaged files
        switch (commandline->GetVersion())
        {
        case CommandLine::verPar1:
          {
            Par1Repairer *repairer = new Par1Repairer;
            result = repairer->Process(*commandline, false);
            delete repairer;
          }
          break;
        case CommandLine::verPar2:
          {
            Par2Repairer *repairer = new Par2Repairer;
            result = repairer->Process(*commandline, false);
            delete repairer;
          }
          break;
        case CommandLine::opNone:
          break;
        }
      }
      break;
    case CommandLine::opRepair:
      {
        // Repair damaged files
        switch (commandline->GetVersion())
        {
        case CommandLine::verPar1:
          {
            Par1Repairer *repairer = new Par1Repairer;
            result = repairer->Process(*commandline, true);
            delete repairer;
          }
          break;
        case CommandLine::verPar2:
          {
            Par2Repairer *repairer = new Par2Repairer;
            result = repairer->Process(*commandline, true);
            delete repairer;
          }
          break;
        case CommandLine::opNone:
          break;
        }
      }
      break;
    case CommandLine::opNone:
      break;
    }
  }

  return result;
}
Esempio n. 12
0
int main(int argc, char *argv[]) {
	int k, i, n, c;
	int firstarg=1;
	FILE *input, *output;
/*	char destination[FILENAME_MAX]; */
	char infilecivil[FILENAME_MAX], outfilecivil[FILENAME_MAX];
	time_t infiletime, outfiletime;
	char *s;
	time_t timenow;
/*	time_t targettime, sourcetime; */

/*	First lay in background of current date and time */
	timenow = time (NULL);
	if (timenow == -1) fprintf(stderr, "Time does not exist!\n");
	tm = localtime (&timenow);
	year = tm->tm_year + 1900;
	month = tm->tm_mon;
	day = tm->tm_mday;
	hour = tm->tm_hour;
	minute = tm->tm_min;
	second = tm->tm_sec;

	defyear = year;				/* remember current year */
	defmonth = month;			/* remember current month */
	defday = day;				/* remember current day */

/*	if (argc < firstarg + 2) { */
	if (argc < firstarg + 1) showusage (argc, argv);

	firstarg = commandline(argc, argv, firstarg);

/*	if (argc < firstarg + 2) { */
	if (argc < firstarg + 1) showusage(argc, argv);

/*	if (verboseflag != 0)  */
	if (verboseflag != 0 && (startchar != 0 || endchar != 255)) 
		printf("Start %d (%c) end %d (%c)\n", 
			startchar, startchar, endchar, endchar);

	if (strcmp(destination, "") == 0) {	/* last arg is destination direct ? */
/*		strcpy(destination, argv[argc-1]); */
		destination = argv[argc-1];		/* the old way of doing this */
		argc--;
		printf("WARNING: destination not specified, using %s\n", destination);
	}

	if (verboseflag) printf("Destination is %s\n", destination);

/*	for (k = firstarg; k < argc-1; k++) { */
	for (k = firstarg; k < argc; k++) {

		strcpy(infilename, argv[k]);
		s = stripfilename(infilename);
		c = *s;										/* 1992/Oct/ 11 */
		if (c >= 'a' && c <= 'z') c = c  + 'A' - 'a';
		if (c < startchar || c > endchar) continue;

		strcpy(outfilename, destination);
		strcat(outfilename, "\\");
		strcat(outfilename, s);
	
		if (getinfo(infilename, 0) < 0) continue;
/*		infiletime = statbuf.st_atime; */
		infiletime = statbuf[0].st_atime;
		strcpy(infilecivil, timeptr);

		if (traceflag != 0) printf("Considering file %s\n", infilename);

		if (thresholdflag) {
			if (infiletime < newtime){
				if (verboseflag)
					printf("%s not younger than threshold\n", infilename);
				continue;
			}
		}

		if (getinfo(outfilename, 1) < 0) {
			outfiletime = 0;
			strcpy(outfilecivil, "");			
		} 
		else {
/*			outfiletime = statbuf.st_atime; */
			outfiletime = statbuf[1].st_atime;
			strcpy(outfilecivil, timeptr);
		}

/*		if (outfiletime == 0 || outfiletime < infiletime) { */
		if (outfiletime != 0 && outfiletime >= infiletime) {
			if (traceflag) printf("Not younger than destination\n");
			continue;
		}
		
/*		printf("Copying %s ", infilename); */
		printf("Copying %s ", s);
/*		if (strcmp(outfilecivil, "") != 0) { */
		n = strlen(s);
		for (i = n; i < 14; i++) putc(' ', stdout);
		printf("new: %s   ", infilecivil);
		if (strcmp(outfilecivil, "") != 0) 
			printf("old: %s", outfilecivil);
/*		} */
		printf("\n");
		if ((input = fopen(infilename, "rb")) == NULL) {
			perror(infilename);
			continue;
		}
		if (outputflag == 0) {
			printf("Skipping %s\n", outfilename);
			fclose(input);
			continue;
		}
		if (safeflag != 0) { /* temporary, until debugged */
			if ((output = fopen(outfilename, "rb")) != NULL) {
				fclose(output);
				printf("%s already exist\n", outfilename);
				fclose(input);
				continue;
			}
		}
		if ((output = fopen(outfilename, "wb")) == NULL) {
			fclose(input);
			perror(outfilename);
			exit(3);
		}
/*		while ((c = getc(input)) != EOF) putc(c, output); */
		copyfile(output, input);
		if (ferror(input) != 0) {
			perror(infilename);
		}
		fclose(input);
		if (ferror(output) != 0) {
			perror(outfilename);
			exit(5);
		}
		fclose(output);
		if (copydate != 0) {
			timebuf.actime = statbuf[0].st_atime; 
			timebuf.modtime = statbuf[0].st_atime; 
/*			if (utime(argv[k], &timebuf) != 0) {  */
/*			if (utime(outfilename, &timebuf) != 0) {  */
			if (_utime(outfilename, &timebuf) != 0) { 
				fprintf(stderr, "Unable to modify date/time\n");
				perror(argv[1]);
				exit(3);
			} 
		}
/*		} */

/*		if (traceflag != 0) {
			if (getinfo(argv[1]) < 0) exit(1);
		} */
	}
	return 0;
}
void main(void) {
	commandline();
	system("pause");
}