Exemple #1
0
int main(int argc, char **argv) {
char optchar, *exec = NULL, server[512] = "", *username = NULL, *password = NULL;
int s, retval = -1, port, target = 0;

if (argc < 2) {
helpme(argc, argv);
} else {
while ( (optchar = getopt(argc, argv, "h:t:u:p:e:")) != EOF ) {
switch(optchar) {
case 'h': sscanf(optarg, "%[^:]:%d", server, &port);
break;
case 'u': username = optarg;
break;
case 'p': password = optarg;
break;
case 't': target = atoi(optarg);
break;
case 'e': exec = optarg;
break;
}
}

if (!strcmp(server, "")) {
strcpy(server, "127.0.0.1");
port = 21;
}

if (!username) {
username = "******";
}

if (!password) {
password = "******";
}

if (!exec) {
exec = "id; killall msg; ";
}

fprintf(stderr, "[*] connecting %s:%d (%s/%s)...\n", server, port, username, password);
if (!connectserver(&s, server, port)) {
retval = attack(s, username, password, target, exec);
close(s);
}
}

return retval;
}
int c3b_main(int argc, char *argv[])
#endif
{
  char ch='0';

  do
    {
      helpme();
      stkmon_disp();

      ch = getchar();

    }
  while (execute(ch) == 0);

  return 0;
}
Exemple #3
0
static void makemoves(void) {
	int i, hitme;
	char ch;
	while (TRUE) { /* command loop */
		hitme = FALSE;
		justin = 0;
		Time = 0.0;
		i = -1;
		while (TRUE)  { /* get a command */
			chew();
			skip(1);
			proutn("COMMAND> ");
			if (scan() == IHEOL) continue;
			for (i=0; i < 29; i++) // Abbreviations allowed for the first 29 commands, only.
				if (isit(commands[i]))
					break;
			if (i < 29) break;
			for (; i < NUMCOMMANDS; i++)
				if (strcmp(commands[i], citem) == 0) break;
			if (i < NUMCOMMANDS
#ifndef CLOAKING
			    && i != 26 // ignore the CLOAK command
#endif
#ifndef CAPTURE
			    && i != 27 // ignore the CAPTURE command
#endif
#ifndef SCORE
			    && i != 28 // ignore the SCORE command
#endif
#ifndef DEBUG
			    && i != 33 // ignore the DEBUG command
#endif
			   ) break;

			if (skill <= SFAIR)  {
				prout("UNRECOGNIZED COMMAND. LEGAL COMMANDS ARE:");
				listCommands(TRUE);
			}
			else prout("UNRECOGNIZED COMMAND.");
		}
		switch (i) { /* command switch */
			case 0:			// srscan
				srscan(1);
				break;
			case 1:			// lrscan
				lrscan();
				break;
			case 2:			// phasers
				phasers();
                if (ididit) {
#ifdef CLOAKING
                    if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
                        prout("The Romulan ship discovers you are breaking the Treaty of Algeron!");
                        ncviol++;
                        isviolreported = TRUE;
                    }
#endif
                    hitme = TRUE;
                }
				break;
			case 3:			// photons
				photon();
                if (ididit) {
#ifdef CLOAKING
                    if (irhere && d.date >= ALGERON && !isviolreported && iscloaked) {
                        prout("The Romulan ship discovers you are breaking the Treaty of Algeron!");
                        ncviol++;
                        isviolreported = TRUE;
                    }
#endif
                    hitme = TRUE;
                }
				break;
			case 4:			// move
				warp(1);
				break;
			case 5:			// shields
				sheild(1);
				if (ididit) {
					attack(2);
					shldchg = 0;
				}
				break;
			case 6:			// dock
				dock();
				break;
			case 7:			// damages
				dreprt();
				break;
			case 8:			// chart
				chart(0);
				break;
			case 9:			// impulse
				impuls();
				break;
			case 10:		// rest
				waiting();
				if (ididit) hitme = TRUE;
				break;
			case 11:		// warp
				setwrp();
				break;
			case 12:		// status
				srscan(3);
				break;
			case 13:			// sensors
				sensor();
				break;
			case 14:			// orbit
				orbit();
				if (ididit) hitme = TRUE;
				break;
			case 15:			// transport "beam"
				beam();
				break;
			case 16:			// mine
				mine();
				if (ididit) hitme = TRUE;
				break;
			case 17:			// crystals
				usecrystals();
				break;
			case 18:			// shuttle
				shuttle();
				if (ididit) hitme = TRUE;
				break;
			case 19:			// Planet list
				preport();
				break;
			case 20:			// Status information
				srscan(2);
				break;
			case 21:			// Game Report 
				report(0);
				break;
			case 22:			// use COMPUTER!
				eta();
				break;
			case 23:
				listCommands(TRUE);
				break;
			case 24:		// Emergency exit
				clearscreen();	// Hide screen
				freeze(TRUE);	// forced save
				exit(1);		// And quick exit
				break;
			case 25:
				probe();		// Launch probe
				break;
#ifdef CLOAKING
			case 26:
				cloak();        // turn on/off cloaking
				if (iscloaking) {
					attack(2); // We will be seen while we cloak
					iscloaking = FALSE;
					iscloaked = TRUE;
				}
				break;
#endif
#ifdef CAPTURE
			case 27:
				capture();      // Attempt to get Klingon ship to surrender
				if (ididit) hitme = TRUE;
				break;
#endif
#ifdef SCORE
			case 28:
				score(1);    // get the score
				break;
#endif
			case 29:			// Abandon Ship
				abandn();
				break;
			case 30:			// Self Destruct
				dstrct();
				break;
			case 31:			// Save Game
				freeze(FALSE);
				if (skill > SGOOD)
					prout("WARNING--Frozen games produce no plaques!");
				break;
			case 32:			// Try a desparation measure
				deathray();
				if (ididit) hitme = TRUE;
				break;
#ifdef DEBUG
			case 33:			// What do we want for debug???
				debugme();
				break;
#endif
			case 34:		// Call for help
				help();
				break;
			case 35:
				alldone = 1;	// quit the game
#ifdef DEBUG
				if (idebug) score(0);
#endif
				break;
			case 36:
				helpme();	// get help
				break;
		}
		for (;;) {
			if (alldone) break;		// Game has ended
#ifdef DEBUG
			if (idebug) prout("2500");
#endif
			if (Time != 0.0) {
				events();
				if (alldone) break;		// Events did us in
			}
			if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova!
				atover(0);
				continue;
			}
			if (nenhere == 0) movetho();
			if (hitme && justin==0) {
				attack(2);
				if (alldone) break;
				if (d.galaxy[quadx][quady] == 1000) {	// went NOVA! 
					atover(0);
					hitme = TRUE;
					continue;
				}
			}
			break;
		}
		if (alldone) break;
	}
}
int main(int argc, char **argv) {
  int v_opt;
  int v_set1404 = 0;
  int v_set1003 = 0;
  int v_show = 0;
  extern int optind, optopt;
  extern char *optarg;

  while((v_opt = getopt(argc, argv, "edbvskn:")) != -1) { 
    switch(v_opt) {
      case 'e':
        v_set1404 = 1;
        break;
      case 'd':
        v_set1003 = 1;
        break;
      case 'b':
        g_daemon = 1;
        break;
      case 'v':
        g_verbose = 1;
        break;
      case 's':
        v_show = 1;
        break;
      case 'k':
        g_kill = 1;
        break;
      case 'n':
        g_svc = optarg;
        break;
      case ':':
      case '?':
        helpme();
    }
  }

  if((v_set1404 + v_set1003 + g_daemon + v_show > 1) ||
     (v_set1404 + v_set1003 + g_daemon + v_show == 0)) {
    helpme();
  }
  if(g_kill == 1 && g_svc != '\0') {
    helpme();
  }

  if(v_set1404 == 1) {
    set_1404();
    exit(0);
  }
  if(v_set1003 == 1) {
    set_1003();
    exit(0);
  }
  if(v_show == 1) {
    show_mode();
    exit(0);
  }
  if(g_daemon == 1) {
    daemonize();
  }
  helpme();
}
Exemple #5
0
int main(int argc, char **argv)
{
  _comm_header *comm;
  _path *path;
  _services *services;
  _backplane_data *backplane;
  _rack *rack;
  _tag_data *configtags, *detailtags;
  _tag_data *program_tags[64];
  _tag_list *list;
  _prog_list *progs;
  _struct_list *structs;
  int x, y, z, debug, program_count, quiet, result;
  int c1 = 0, c68 = 0, c69 = 0;
#ifdef WIN32
  int optind = 1;
  debug = DEBUG_DATA;
#endif

#ifndef WIN32
  debug = 0;
#endif

  program_count = 0;
  quiet = FALSE;
  if (argc == 1)
  {
    helpme();
    exit(1);
  }
#ifndef WIN32
  while ((x = getopt(argc, argv, "dhq?")) != -1)
  {
    switch (x)
    {
    case 'd':
      debug++;
      break;
    case 'q':
      quiet = TRUE;
      break;
    case 'h':
    case '?':
      helpme();
      exit(1);
    }
  }

#endif

  if (argv[optind] == NULL)
  {
    printf("Can not connect - need a host name to connect to.\n");
    exit(-1);
  }

  rack = malloc(sizeof(_rack));
  if (rack == NULL)
  {
    printf("Could not allocate memory for rack structure.\n");
    exit(-1);
  }

  comm = malloc(sizeof(_comm_header));
  if (comm == NULL)
  {
    printf("Could not allocate memory for comm header.\n");
    exit(-1);
  }
  services = malloc(sizeof(_services));
  if (services == NULL)
  {
    printf("Could not allocate memory for services structure.\n");
    free(comm);
    exit(-1);
  }

  backplane = malloc(sizeof(_backplane_data));
  if (backplane == NULL)
  {
    printf("Could not allocate memory for backplane structure.\n");
    free(comm);
    free(services);
    exit(-1);
  }
  path = malloc(sizeof(_path));
  if (path == NULL)
  {
    printf("Could not allocate memory for path structure.\n");
    free(backplane);
    free(comm);
    free(services);
    exit(-1);
  }
  configtags = malloc(sizeof(_tag_data));
  if (configtags == NULL)
  {
    printf("Could not allocate memory for configtags structure.\n");
    free(path);
    free(backplane);
    free(comm);
    free(services);
    exit(-1);
  }
  detailtags = malloc(sizeof(_tag_data));
  if (detailtags == NULL)
  {
    printf("Could not allocate memory for detailtags structure.\n");
    free(path);
    free(backplane);
    free(comm);
    free(services);
    exit(-1);
  }
  progs = malloc(sizeof(_prog_list));
  if (progs == NULL)
  {
    printf("Could not allocate memory for program list structure.\n");
    free(detailtags);
    free(path);
    free(backplane);
    free(comm);
    free(services);
    exit(-1);
  }
  structs = malloc(sizeof(_struct_list));
  if (structs == NULL)
  {
    printf("Could not allocate memory for structure list.\n");
    exit(-1);
  }
  list = malloc(sizeof(_tag_list));
  if (list == NULL)
  {
    printf ("Could not allocate memory for tag list.\n");
    exit(-1);
  }



  memset(services, 0, sizeof(_services));
  memset(comm, 0, sizeof(_comm_header));
  memset(backplane, 0, sizeof(_backplane_data));
  memset(rack, 0, sizeof(_rack));
  memset(configtags, 0, sizeof(_tag_data));
  memset(detailtags, 0, sizeof(_tag_data));
  memset(progs, 0, sizeof(_prog_list));
  memset(structs, 0, sizeof(_struct_list));
  memset(list, 0, sizeof(_tag_list));

  comm->hostname = argv[optind];
  if (quiet == FALSE)
    printf("Connecting to host %s\n", comm->hostname);
  establish_connection(comm, services, debug);
  if (comm->error != OK)
  {
    printf("An Error occured while connecting to host %s.\n", comm->hostname);
    exit(-1);
  }

  path->device1 = -1;
  path->device2 = -1;
  path->device3 = -1;
  path->device4 = -1;
  path->device5 = -1;
  path->device6 = -1;
  path->device7 = -1;
  path->device8 = -1;

  if (quiet == FALSE)
    printf("Got Session_ID = %ld\n", comm->session_id);
  get_backplane_data(comm, backplane, rack, path, debug);
  if (debug != DEBUG_NIL)
  {
    dprint(DEBUG_VALUES, "RX_Bad_m :%02X     ", backplane->rx_bad_m);
    dprint(DEBUG_VALUES, "ERR+Threshold: %02X     ",
	   backplane->err_threshold);
    dprint(DEBUG_VALUES, "RX_Bad_CRC :%02X    ", backplane->rx_bad_crc);
    dprint(DEBUG_VALUES, "RX_Bus_Timeout :%02X\n", backplane->rx_bus_timeout);
    dprint(DEBUG_VALUES, "TX_Bad_CRC :%02X   ", backplane->tx_bad_crc);
    dprint(DEBUG_VALUES, "TX_Bus_Timeout :%02X   ",
	   backplane->tx_bus_timeout);
    dprint(DEBUG_VALUES, "TX_Retry :%02X\n", backplane->tx_retry);
    dprint(DEBUG_VALUES, "Status :%02X    ", backplane->status);
    dprint(DEBUG_VALUES, "Address :%04X\n", backplane->address);
    dprint(DEBUG_VALUES, "Major Rev :%02X  ", backplane->rev_major);
    dprint(DEBUG_VALUES, "Minor Rev :%02X  ", backplane->rev_minor);
    dprint(DEBUG_VALUES, "Serial Number :%08lX  ", backplane->serial_number);
    dprint(DEBUG_VALUES, "Backplane size :%d\n", backplane->rack_size);
  }
  who(comm, rack, NULL, debug);
  path->device1 = 1;
  path->device2 = rack->cpulocation;
  path->device3 = -1;
  path->device4 = -1;
  path->device5 = -1;
  path->device6 = -1;
  path->device7 = -1;
  path->device8 = -1;

  get_object_config_list(comm, path, 0, configtags, debug);
  get_object_details_list(comm, path, 0, detailtags, debug);
  get_program_list(comm, path, progs, debug);
/*  get_struct_list(comm, path, structs, debug);


printf ("Got %d structs in the program.\n",structs->count);
for (x=0;x<structs->count; x++)
	{
	printf ("Struct #%02d, type id = %08lX\n",x,structs->base[x]->base);
	get_struct_config (comm, path, structs->base[x], debug);
	get_struct_details (comm, path, structs->base[x], debug);
	printf ("Element count = %d    Detail size = %d\n",structs->base[x]->count, structs->base[x]->detailsize);
	printf ("Element link-id = %04X\n",structs->base[x]->linkid);
	printf ("Structure base name = %s\n",structs->base[x]->name);
	for (y=0;y<structs->base[x]->count;y++)
		{
		printf ("Element #%d, type = %04X, arraysize = %d name = %s\n",y,structs->base[x]->data[y]->type, structs->base[x]->data[y]->arraysize, structs->base[x]->data[y]->name);
		}
	printf ("----------------------------------------\n");
	}

exit;
*/

  y = detailtags->count;
  if (configtags->count > y)
    y = configtags->count;

  printf("Reading tags from ControlLogix...\n");
  for (z = 0; z < y; z++)
  {
    if (z < detailtags->count)
      get_object_details(comm, path, detailtags->tag[z], debug);
    if (z < configtags->count)
      get_object_config(comm, path, configtags->tag[z], debug);
    printf
      ("%08lX - %08lX - %08lX - %08lX - %04X - %04X - %04X - %s - %ld - %ld - %ld - %ld\n",
       detailtags->tag[z]->topbase, detailtags->tag[z]->base,
       detailtags->tag[z]->id, detailtags->tag[z]->linkid,
       detailtags->tag[z]->size, detailtags->tag[z]->type,
       detailtags->tag[z]->alias_type, detailtags->tag[z]->name,
       detailtags->tag[z]->alias_linkid - detailtags->tag[z]->linkid,
       detailtags->tag[z]->arraysize1, detailtags->tag[z]->arraysize2,
       detailtags->tag[z]->arraysize3);

  }
  printf("Checking for aliases...\n");

  for (z = 0; z < detailtags->count; z++)
    aliascheck(detailtags->tag[z], NULL, detailtags, DEBUG_VALUES);

  for (z = 0; z < y; z++)
  {
    if (z < detailtags->count)
    {
    switch (detailtags->tag[z]->type & 255)
      {
      case 0x68:
      case 0x69:
	break;
      default:
	read_object_value(comm, path, detailtags->tag[z], debug);
      }

      if (detailtags->tag[z]->topbase != 0)
	c1++;
      if (z < detailtags->count)
      {
	printf
	  ("%08lX - %08lX - %08lX - %08lX - %08lX - %08lX - %04lX - %04X - %04X - %s - %ld - %ld - %ld - %ld\n",
	   detailtags->tag[z]->topbase, detailtags->tag[z]->base,
	   detailtags->tag[z]->id, detailtags->tag[z]->linkid,
	   detailtags->tag[z]->alias_topbase, detailtags->tag[z]->alias_base,
	   detailtags->tag[z]->alias_id, detailtags->tag[z]->type,
	   detailtags->tag[z]->alias_type, detailtags->tag[z]->name,
	   detailtags->tag[z]->alias_linkid - detailtags->tag[z]->linkid,
	   detailtags->tag[z]->arraysize1, detailtags->tag[z]->arraysize2,
	   detailtags->tag[z]->arraysize3);
      }
      if (z < configtags->count)
      {
	printf("%08lX - %08lX - %04X\n", configtags->tag[z]->topbase,
	       configtags->tag[z]->linkid, configtags->tag[z]->type);
      }

/*

		if (strncmp ( detailtags->tag[z]->name, "IntArray",strlen(detailtags->tag[z]->name)))
			{
			read_object_value(comm, path, detailtags->tag[z], debug);
			printf ("Old:\n");
			for (x=0;x<detailtags->tag[z]->datalen;x++)
				printf ("%02X ",detailtags->tag[z]->data[x]);
			printf ("\n"); 
			for (x=0;x<detailtags->tag[z]->datalen; x++)
				detailtags->tag[z]->data[x]++;
			write_object_value(comm, path, detailtags->tag[z], 4);
			read_object_value(comm, path, detailtags->tag[z], debug);
			printf ("New:\n");
			for (x=0;x<detailtags->tag[z]->datalen;x++)
				printf ("%02X ",detailtags->tag[z]->data[x]);
			printf ("\n"); 
			}			
*/

    }
  }
/*
  for (z = 0; z < y; z+=5)
  {
    if (z < detailtags->count)
    {
    switch (detailtags->tag[z]->type & 255)
      {
      case 0x68:
      case 0x69:
	break;
      default:
	list->count = 1;
	list->tag[0] = detailtags->tag[z];
	if (z+1 < y)
		list->tag[list->count++] = detailtags->tag[z+1];
	if (z+2 < y)
		list->tag[list->count++] = detailtags->tag[z+2];
	if (z+3 < y)
		list->tag[list->count++] = detailtags->tag[z+3];
	if (z+4 < y)
		list->tag[list->count++] = detailtags->tag[z+4];
	read_multi_object_value(comm, path, list, debug);
      }

    }
  }

*/
for (z=0; z<detailtags->count; z++)
	{
	printf ("%s : ",detailtags->tag[z]->name);
	for (x=0;x<detailtags->tag[z]->datalen;x++)
		printf ("%02X ",detailtags->tag[z]->data[x]);
	printf ("\n"); 
	}


//exit(0);
  printf("%d objects with topbase != 0.\n", c1);
  printf("%d objects type 0x68, %d objects type 0x69.\n", c68, c69);
  printf("configtags count = %d    detailtags count = %d\n",
	 configtags->count, detailtags->count);
  printf("Got %d programs...\n", progs->count);

  for (x = 0; x < progs->count; x++)
  {
    program_tags[x] = malloc(sizeof(_tag_data));



    if (program_tags[x] == NULL)
    {
      printf("Could not allocate memory for program tag structure.\n");
      exit(-1);
    }

    get_program_details(comm, path, progs->prog[x], debug);
    for (y = 0; y < detailtags->count; y++)
    {
      if (detailtags->tag[y]->linkid == progs->prog[x]->linkid)
      {
	strcpy(progs->prog[x]->name, detailtags->tag[y]->name);
      }
    }
    printf("id for program #%d is %08lX   link ID = %08lX - %s\n", x,
	   progs->prog[x]->base, progs->prog[x]->linkid,
	   progs->prog[x]->name);
  }




  for (x = 0; x < progs->count; x++)
  {
    if (quiet == FALSE)
      printf("Tag list for %s\n", progs->prog[x]->name);
    get_object_details_list(comm, path, progs->prog[x]->base, program_tags[x],
			    debug);
    printf("tag count = %d\n\n", program_tags[x]->count);

    for (y = 0; y < program_tags[x]->count; y++)
    {
      get_object_details(comm, path, program_tags[x]->tag[y], debug);
/*      aliascheck(program_tags[x]->tag[y], program_tags[x], detailtags,
		 DEBUG_VALUES);
      if (quiet == FALSE)
	printf("%08lX  %08lX  %08lX  %08lX   ",
	       program_tags[x]->tag[y]->topbase,
	       program_tags[x]->tag[y]->base, program_tags[x]->tag[y]->id,
	       program_tags[x]->tag[y]->linkid);
      if (quiet == FALSE)
      {
	printf("type = %04X   Name = %s\n", program_tags[x]->tag[y]->type,
	       program_tags[x]->tag[y]->name);
	printf("arraysize1 = %ld    arraysize2 = %ld    arraysize3 = %ld\n",
	       program_tags[x]->tag[y]->arraysize1,
	       program_tags[x]->tag[y]->arraysize2,
	       program_tags[x]->tag[y]->arraysize3);
      }
*/
    }
    if (quiet == FALSE)
      printf("-----------------------------------\n");
  }

  for (x = 0; x < detailtags->count; x++)
  {
    if ((detailtags->tag[x]->size != 0)
	|| (detailtags->tag[x]->alias_size != 0))
    {
      result = read_object_value(comm, path, detailtags->tag[x], debug);
      if (result != 0)
      {
	printf("Got non-zero return from read_object_value - %02X\n", result);
	printf
	  ("%08lX - %08lX - %08lX - %08lX - %08lX - %08lX - %08lX - %04X - %s - %ld - %ld - %ld\n",
	   detailtags->tag[x]->topbase, detailtags->tag[x]->base,
	   detailtags->tag[x]->id, detailtags->tag[x]->linkid,
	   detailtags->tag[x]->alias_topbase, detailtags->tag[x]->alias_base,
	   detailtags->tag[x]->alias_id, detailtags->tag[x]->type,
	   detailtags->tag[x]->name, detailtags->tag[x]->arraysize1,
	   detailtags->tag[x]->arraysize2, detailtags->tag[x]->arraysize3);
      }

      if (quiet == FALSE)
      {
	printf("Value(s) for %s: ", detailtags->tag[x]->name);
	for (y = 0; y < detailtags->tag[x]->size; y++)
	  printf("%02X ", detailtags->tag[x]->data[y]);
	printf("\n");
      }

    }
  }

  for (x = 0; x < progs->count; x++)
  {
    if (quiet == FALSE)
      printf("Reading %d Data Values for program %s tags...\n",
	     program_tags[x]->count, progs->prog[x]->name);
    for (y = 0; y < program_tags[x]->count; y++)
    {
      if ((program_tags[x]->tag[y]->type & 255) > 0xbf)
      {
	read_object_value(comm, path, program_tags[x]->tag[y], debug);
	if (quiet == FALSE)
	{
	  printf("Value(s) for %s: ", program_tags[x]->tag[y]->name);
	  for (z = 0; z < program_tags[x]->tag[y]->datalen; z++)
	    printf("%02X ", program_tags[x]->tag[y]->data[z]);
	  printf("\n");
	}
      }
      if (quiet == FALSE)
	printf("---------------------------------\n");
    }
  }
  closesocket(comm->file_handle);
  exit(0);
}
Exemple #6
0
Fichier : sst.c Projet : aichao/sst
static void makemoves(void) {
	int i, hitme;
	char ch;
	while (TRUE) { /* command loop */
		hitme = FALSE;
		justin = 0;
		Time = 0.0;
		i = -1;
		while (TRUE)  { /* get a command */
			chew();
			skip(1);
			proutn("COMMAND> ");
      // Use of scan() here (after chew) will get a new line of input
      // and will return IHEOL iff new line of input contains nothing
      // or a numeric input is detected but conversion fails.
			if (scan() == IHEOL) continue;
			for (i=0; i < 26; i++)
				if (isit(commands[i]))
					break;
			if (i < 26) break;
			for (; i < NUMCOMMANDS; i++)
				if (strcmp(commands[i], citem) == 0) break;
			if (i < NUMCOMMANDS) break;
      // we get here iff the first parsed input from the line does not 
      // match one of the commands. In this case, the rest of the line
      // is discarded, the below message is printed, and we go back to 
      // get a new command.
			if (skill <= 2)  {
				prout("UNRECOGNIZED COMMAND. LEGAL COMMANDS ARE:");
				listCommands(TRUE);
			}
			else prout("UNRECOGNIZED COMMAND.");
		} // end get command loop
    // we get here iff the first parsed input from the line matches one
    // of the commands (i.e., command i). We use i to dispatch the 
    // handling of the command. The line may still contain additional
    // inputs (i.e., parameters of the command) that is to be parsed by
    // the dispatched command handler. If the line does not contain
    // all the necessary parameters, the dispatched command handler is 
    // responsible to get additional input(s) interactively using scan().
    // The dispatched command handler is also responsible to handle any 
    // input errors.
		switch (i) { /* command switch */
			case 0:			// srscan
				srscan(1);
				break;
			case 1:			// lrscan
				lrscan();
				break;
			case 2:			// phasers
				phasers();
				if (ididit) hitme = TRUE;
				break;
			case 3:			// photons
				photon();
				if (ididit) hitme = TRUE;
				break;
			case 4:			// move
				warp(1);
				break;
			case 5:			// shields
				sheild(1);
				if (ididit) {
					attack(2);
					shldchg = 0;
				}
				break;
			case 6:			// dock
				dock();
				break;
			case 7:			// damages
				dreprt();
				break;
			case 8:			// chart
				chart(0);
				break;
			case 9:			// impulse
				impuls();
				break;
			case 10:		// rest
				waiting();
				if (ididit) hitme = TRUE;
				break;
			case 11:		// warp
				setwrp();
				break;
			case 12:		// status
				srscan(3);
				break;
			case 13:			// sensors
				sensor();
				break;
			case 14:			// orbit
				orbit();
				if (ididit) hitme = TRUE;
				break;
			case 15:			// transport "beam"
				beam();
				break;
			case 16:			// mine
				mine();
				if (ididit) hitme = TRUE;
				break;
			case 17:			// crystals
				usecrystals();
				break;
			case 18:			// shuttle
				shuttle();
				if (ididit) hitme = TRUE;
				break;
			case 19:			// Planet list
				preport();
				break;
			case 20:			// Status information
				srscan(2);
				break;
			case 21:			// Game Report 
				report(0);
				break;
			case 22:			// use COMPUTER!
				eta();
				break;
			case 23:
				listCommands(TRUE);
				break;
			case 24:		// Emergency exit
				clearscreen();	// Hide screen
				freeze(TRUE);	// forced save
				exit(1);		// And quick exit
				break;
			case 25:
				probe();		// Launch probe
				break;
			case 26:			// Abandon Ship
				abandn();
				break;
			case 27:			// Self Destruct
				dstrct();
				break;
			case 28:			// Save Game
				freeze(FALSE);
				if (skill > 3)
					prout("WARNING--Frozen games produce no plaques!");
				break;
			case 29:			// Try a desparation measure
				deathray();
				if (ididit) hitme = TRUE;
				break;
			case 30:			// What do we want for debug???
#ifdef DEBUG
				debugme();
#endif
				break;
			case 31:		// Call for help
				help();
				break;
			case 32:
				alldone = 1;	// quit the game
#ifdef DEBUG
				if (idebug) score();
#endif
				break;
			case 33:
				helpme();	// get help
				break;
		} // end command switch
		for (;;) {
			if (alldone) break;		// Game has ended
#ifdef DEBUG
			if (idebug) prout("2500");
#endif
			if (Time != 0.0) {
				events();
				if (alldone) break;		// Events did us in
			}
			if (d.galaxy[quadx][quady] == 1000) { // Galaxy went Nova!
				atover(0);
				continue;
			}
			if (nenhere == 0) movetho();
			if (hitme && justin==0) {
				attack(2);
				if (alldone) break;
				if (d.galaxy[quadx][quady] == 1000) {	// went NOVA! 
					atover(0);
					hitme = TRUE;
					continue;
				}
			}
			break;
		} // end event loop
		if (alldone) break;
	} // end command loop
}
Exemple #7
0
int main(int argc, char **argv)
{
_comm_header *comm;
_tag_detail *tag;
_path *path;
_rack *rack;
_services *services;
//_backplane_data *backplane;
int result,x,debug=0;

result = 0;

  while ((x = getopt(argc, argv, "dh?")) != -1)
  {
    switch (x)
    {
    case 'd':
      debug++;
      break;
    case 'h':
    case '?':
      helpme();
      exit(1);
    }
  }


	
// Note that this is quick and dirty - no error checking...

tag = malloc(sizeof(_tag_detail));
memset(tag,0,sizeof(_tag_detail));

rack = malloc(sizeof(_rack));
memset (rack,0,sizeof(_rack));

//backplane = malloc(sizeof(_backplane_data));
//memset (backplane,0,sizeof(_backplane_data));

path = malloc(sizeof(_path));
memset (path,0,sizeof(_path));

services = malloc(sizeof(_services));
memset (services,0,sizeof(_services));

comm = malloc(sizeof(_comm_header));
memset (comm,0,sizeof(_comm_header));

dprint (DEBUG_TRACE,"setting plc name %d %s.\n",strlen(argv[1]), argv[1]);
comm->hostname = argv[1];
dprint (DEBUG_TRACE,"attaching to plc\n");

establish_connection (comm, services, 0);
if (comm->error != 0)
	{
	printf ("Could not attach to %s\n",argv[1]);
	exit(-1);
	}
path->device1 = -1;
path->device2 = -1;
path->device3 = -1;
path->device4 = -1;
path->device5 = -1;
path->device6 = -1;
path->device7 = -1;
path->device8 = -1;

//get_backplane_data(comm, backplane, rack, path, 0);
dprint (DEBUG_TRACE,"polling PLC rack layout\n");
who(comm, rack, NULL, 0);
path->device1 =1;
path->device2 = rack->cpulocation;
dprint (DEBUG_TRACE,"reading tag\n");
if (argc == 3)
	result = read_tag(comm, path, NULL, argv[2], tag, 0);
if (argc == 4)
	result = read_tag(comm, path, argv[3], argv[2], tag, 0);

if (result != 0)
	{
	printf ("reading tag %s failed - does it exist?\n\n",argv[2]);
	exit(-1);
	}
for (x=0; x<tag->datalen; x++)
	printf ("%02X ",tag->data[x]);
printf ("\n\n");
exit(0);
}
int main(int argc, char *argv[])
{

    FILE *in=NULL, *wikiout=NULL,*htmlout=NULL;
    char * ptrch;
    char header[MAX_BUFFER][MAX_STRING];
    char col[MAX_BUFFER][MAX_STRING];
    char buffer[4096];
    int c,index, option_index = 0;
    char *param_wiki_output=NULL;
    char *param_html_output=NULL;
    char *param_file_input=NULL;
    int  linecounter=0;
    static struct option long_options[] = {
            {"wiki", 1, 0, 0},
            {"html", 1, 0, 0},
            {"i", 1, 0, 0}
     };

    int j=0,i=0;
    char separator[5];
    separator[0]=',';
    separator[1]='"';
    separator[2]='\0';


    prog_desc(argv);  //program descripton and title
    while(1) {
        c = getopt_long (argc, argv,"",long_options, &option_index);

        if (c == -1)
            break;

        switch (c) {
            case 0:
                index=option_index;
                switch (index) {
                   case 0:  //wiki
                        param_wiki_output = optarg;
                        break;
                   case 1:  // html
                        param_html_output = optarg;
                        break;
                    case 2:  // input
                        param_file_input = optarg;
                        break;
                    default:
                        printf("Unknown Parameter: %i\n",index);
                        helpme(argv);

                }
                break;
            default:
                        printf("Invalid Parameter: %i\n",c);
                        helpme(argv);

        }
    }

    if (optind < argc) {
        printf (" Ignored no option parameter(s): ");
        while (optind < argc)
            printf ("%s ", argv[optind++]);
        printf ("\n");
    }


    if ((param_wiki_output==NULL) &&( param_html_output==NULL)) {

         printf(" Error:  No output file specified:  use --wiki fname or --html fname\n\n");
         helpme(argv);

    }
    else {
		if (param_wiki_output !=NULL){
            wikiout=fopen(param_wiki_output,"w");
            if(wikiout==NULL ){
                printf("Can't create wiki output file %s\n",param_wiki_output);
                exit(1);
            }
		}
		if (param_html_output !=NULL) {
            htmlout=fopen(param_html_output,"w");
            if(htmlout==NULL ){
                printf("Can't create html output file %s\n",param_html_output);
                exit(1);
            }
        }
    }
    if (param_file_input ==NULL){
        printf("input text file required\n");
        helpme(argv);
    }
    else {
       in =fopen(param_file_input,"r");
       if(in==NULL ){
             printf("Can't open input file %s\n",param_file_input);
             exit(1);
       }
    }

	linecounter=0;
	while(!feof(in)) {
		if(fgets(buffer, MAX_STRING, in)) {
			//buflen=strlen(buffer);
			if (linecounter==0){
				// linecounter==0 means we are dealing with a header
				//remove double quotes("), replace comman (,) with !
				// do the column header first

				ptrch = strtok (buffer,",");  //tokens are delimited with pairs of quote comma
				i=0;
				while (ptrch != NULL) {
					   strcpy(header[i],ptrch);
					   removeQuotes(header[i]);
					   i++;
					   ptrch = strtok (NULL, ",");
				}

				if (htmlout!=NULL){
					 fprintf(htmlout,"<table class='wikitable' border='1'>\n");
					 fprintf(htmlout,"<tr>\n");
					 for (j=0; j < i;j++) {
						fprintf(htmlout,"<th scope='col'>%s</th>\n",header[j]);
					 }
					 fprintf(htmlout,"</tr>\n");
				}
				if (wikiout!=NULL){
					 fprintf(wikiout,"== Partlist ==\n\n");
					 fprintf(wikiout,"{| border='1' class='wikitable'\n");
					 fprintf(wikiout,"!%s",header[0]);
					 for(j=1;j < i;j++) {
						fprintf(wikiout,"!!%s",header[j]);
					 }
					// fprintf(wikiout,"\n");
				}



			}   // linecounter =0 only
            else {
                // tokens are separated by pair of quotes

				ptrch = strtok (buffer,"\"");  //tokens are delimited with quotes
				i=0;
				while (ptrch != NULL) {
				       if(*ptrch !=','){
                           strcpy(col[i],ptrch);
                           removeQuotes(col[i]);
                           i++;
                        }
					    ptrch = strtok (NULL, "\"");
				}


				 if (htmlout!=NULL){
					 fprintf(htmlout,"<tr>");
					 for (j=0;j < i-1;j++) {
						fprintf(htmlout,"<td>%s</td> ",col[j]);
					 }
					 fprintf(htmlout,"</tr>\n");

				 }
				  if (wikiout!=NULL){
					 fprintf(wikiout,"|-\n");
					 fprintf(wikiout,"|%s",col[0]);
					 for (j=1;j<i-1;j++) {
						fprintf(wikiout,"||%s",col[j]);
					 }
					  fprintf(wikiout,"\n");

				 }
            }

		}  //if (fgets(
         linecounter++;
	} //while !feof

	if (htmlout!=NULL){
	fprintf(htmlout,"</table>\n\n");
	printf("\n HTML FIle created: %s\n",param_html_output);
	}

   if (wikiout!=NULL){
        fprintf(wikiout,"|}\n\n");
        printf("\n Wiki FIle created: %s\n",param_wiki_output);
   }


   fclose(in);

   if(htmlout!=NULL ){
         fclose(htmlout);
   }
   if(wikiout!=NULL ) {
         fclose(wikiout);
   }
   return 0;
}