示例#1
0
void flash_hw_initUnbuffered(Flash *fls, UNUSED_ARG(int, flags))
{
	common_init(fls);
	fls->blk.priv.vt = &flash_lm3s_unbuffered_vt;
}
示例#2
0
文件: main.c 项目: UlricE/SiagOffice
/* ---
*/
void realmain(int argc, char **argv)
{
	char b[256];
	struct stat statbuf;

	buffer *buf = NULL;
	char path[1024];
	int i;

	setlocale(LC_NUMERIC, "C");
	common_init("Pathetic Writer %s. No Warranty");

	sprintf(b, "%s/%ld", siag_basedir, (long)getpid());
	mkdir(b, 0700);
	sprintf(b, "%s/pw.scm", siag_basedir);
	pwrc = MwStrdup(b);

	init_interpreters();
	siod_interpreter = init_parser(argc, argv);
	init_python_parser();
	init_guile_parser();
	init_ruby_parser();
	waitforchild(0);
	MwMallocInit(NULL, 0);

	init_position();
	init_cmds();

	buf = new_buffer("noname.pw", "noname.pw");

	sprintf(path, "%s/pw/pw.scm", datadir);
	if (stat(path, &statbuf)) {
		fprintf(stderr, "Can't find the runtime library (pw.scm).\n");
		fprintf(stderr, "Expected it in %s\n", path);
		fprintf(stderr, "SIAGHOME (if set) is '%s'\n", datadir);
		fprintf(stderr, "Please read installation instructions.\n");
		exit(EXIT_FAILURE);
	}

	setvar(cintern("libdir"), strcons(-1, libdir), NIL);
	setvar(cintern("datadir"), strcons(-1, datadir), NIL);
	setvar(cintern("docdir"), strcons(-1, docdir), NIL);

	/* load runtime library */
	sprintf(b, "(load \"%s/pw/pw.scm\")", datadir);
	execute(b);

	init_windows(buf, &argc, argv);
	setlocale(LC_NUMERIC, "C");	/* again, because X hosed it */

	/* load user customizations, if any */
	if (!stat(pwrc, &statbuf)) {
		sprintf(b, "(load \"%s\")", pwrc);
		execute(b);
	}

	execute("(init-windows)");
	execute("(create-menus)");

	fileio_init();
	for (i = 1; i < argc; i++) {
		if (argv[i][0] != '-') {
			strcpy(path, argv[i]);
			buf = new_buffer(buffer_name(argv[i]), path);
			loadmatrix(path, buf, guess_file_format(path));
			w_list->buf = buf;
		}
	}
	pr_scr_flag = TRUE;

	/* this works, for reasons beyond my comprehension */
	execute("(print-version)");
	execute("(print-version)");
	activate_window(w_list);
#ifdef HAVE_LIBTCL
	Tcl_Main(argc, argv, Tcl_AppInit);
#else
	mainloop();
#endif
}
Adafruit_GPS::Adafruit_GPS(NewSoftSerial *ser) 
#endif
{
  common_init();     // Set everything to common state, then...
  gpsSwSerial = ser; // ...override gpsSwSerial with value passed.
}
示例#4
0
GPS_5Hz::GPS_5Hz(NewSoftSerial *ser) 
#endif
{
  common_init();     // inicializa todo comunmente, y luego...
  gpsSwSerial = ser; // ...se modifica gpsSwSerial con el valor pasado.
}
示例#5
0
文件: srpc.c 项目: fergul/SRPC
/*
 * important note - this routine should only be called if the RPC system has
 * been suspended via a call to rpc_suspend(); it is here primarily to enable
 * the rapid snapshot capability required by the Homework cache.
 *
 * normal mode of use
 *
 *     rpc_suspend();
 *     pid = fork();
 *     if (pid != 0) {			// parent branch
 *         if (pid == -1) {		// error
 *             rpc_resume();
 *             // note error
 *         } else {			// wait for child to terminate
 *             int status;
 *             (void) wait(&status);
 *             rpc_resume();
 *             // success or error depending upon value of status
 *         }
 *     } else {                         // child branch
 *         pid_t pid = fork();		// zombie-free zone
 *         if (pid == -1)
 *             exit(1);
 *         else if (pid != 0)
 *             exit(0);
 *         rpc_reinit(new port number);
 *     }
 *
 */
int rpc_reinit(unsigned short port) {

    ctable_purge();
    close(my_sock);
    return common_init(port);
}
camera_VC0706::camera_VC0706(NewSoftSerial *ser) {
#endif
	common_init();  // Set everything to common state, then...
	swSerial = ser; // ...override swSerial with value passed.
}
示例#7
0
/*******************************************************************************
Name: utm_common_init

Purpose: Initialization routine for initializing the UTM projection information
    that is common to both the forward and inverse transformations.

Returns:
    GCTP_SUCCESS or GCTP_ERROR

*******************************************************************************/
static int utm_common_init
(
    TRANSFORMATION *trans   /* I/O: transformation to initialize */
)
{
    double r_major;         /* major axis */
    double r_minor;         /* minor axis */
    double radius;          /* earth radius */
    double scale_factor;    /* scale factor */
    double center_long;
    double lat_origin;
    double false_easting;
    double false_northing;
    int zone;               /* zone number */
    const GCTP_PROJECTION *proj = &trans->proj;
    int spheroid = proj->spheroid;


    /* set Clarke 1866 spheroid if negative spheroid code */
    if (spheroid < 0)
        spheroid = 0;

    gctp_get_spheroid(spheroid, proj->parameters, &r_major, &r_minor, &radius);

    zone = proj->zone;
    if (zone == 0)
    {
        /* The zone is zero, so calculate it from the first two projection
           parameters */
        double lon1;
        double lat1;

        /* Convert the longitude and latitude from DMS to degrees */
        if (gctp_dms2degrees(proj->parameters[0], &lon1) != GCTP_SUCCESS)
        {
            GCTP_PRINT_ERROR("Error converting longitude in parameter 0 from "
                             "DMS to degrees: %f", proj->parameters[0]);
            return GCTP_ERROR;
        }
        lon1 *= 3600 * S2R;

        if (gctp_dms2degrees(proj->parameters[1], &lat1) != GCTP_SUCCESS)
        {
            GCTP_PRINT_ERROR("Error converting latitude in parameter 1 from "
                             "DMS to degrees: %f", proj->parameters[1]);
            return GCTP_ERROR;
        }
        lat1 *= 3600 * S2R;

        /* Calculate the zone from the longitude */
        zone = gctp_calc_utm_zone(lon1 * R2D);

        /* Use the convention of a negative zone for the southern hemisphere */
        if (lat1 < 0)
            zone = -zone;
    }
    scale_factor = .9996;

    /* Verify the zone is a legal value */
    if ((abs(zone) < 1) || (abs(zone) > 60))
    {
        GCTP_PRINT_ERROR("Illegal zone number: %d", zone);
        return GCTP_ERROR;
    }

    lat_origin = 0.0;
    center_long = ((6 * abs(zone)) - 183) * D2R;
    false_easting = 500000.0;
    false_northing = (zone < 0) ? 10000000.0 : 0.0;

    trans->print_info = utm_print_info;

    return common_init(trans, r_major, r_minor, scale_factor, center_long,
                       lat_origin, false_easting, false_northing);
}
示例#8
0
 AsyncConnection::AsyncConnection(const boost::shared_ptr<boost::asio::ip::tcp::socket>& socket)
   :io_service_(&socket->get_io_service()), socket_(socket)
 {
   common_init();
 }
示例#9
0
// Constructor when using USARTSerial
Adafruit_VC0706::Adafruit_VC0706(USARTSerial *ser) {
  common_init();  // Set everything to common state, then...
  serial = ser; // ...override serial with value passed.
}
示例#10
0
 AsyncConnection::AsyncConnection()
   :io_service_(0)
 {
   common_init();
 }
示例#11
0
 AsyncConnection::AsyncConnection(boost::asio::io_service& io_service)
   :io_service_(&io_service)
 {
   socket_.reset(new boost::asio::ip::tcp::socket(io_service));
   common_init();
 }
示例#12
0
static av_cold int decode_init(AVCodecContext *avctx)
{
    avctx->pix_fmt = AV_PIX_FMT_YUV411P;
    return common_init(avctx);
}
示例#13
0
int
main(int argc, char **argv)
{
	int			what_signal, i;
	char			*ent_pnt = "main";
	char			logname[20];
	char			*l_mess, *lc_mess;
	sigset_t		sigwait_set;
	struct sigaction	sig_action;
	dev_ptr_tbl_t		*dev_ptr_tbl;
	shm_ptr_tbl_t		*shm_ptr_tbl;
	sam_defaults_t		*defaults;

	if (argc != 4)
		exit(1);

	initialize_fatal_trap_processing(SOLARIS_THREADS, fatal_cleanup);

	CustmsgInit(1, NULL);

	library = (library_t *)malloc_wait(sizeof (library_t), 2, 0);
	(void) memset(library, 0, sizeof (library_t));

	/*
	 * Crack the arguments
	 */
	argv++;
	master_shm.shmid = atoi(*argv);
	argv++;
	preview_shm.shmid = atoi(*argv);
	argv++;
	library->eq = atoi(*argv);
	mypid = getpid();
	if ((master_shm.shared_memory = shmat(master_shm.shmid, NULL, 0774)) ==
	    (void *)-1)
		exit(2);

	shm_ptr_tbl = (shm_ptr_tbl_t *)master_shm.shared_memory;

	if ((preview_shm.shared_memory =
	    shmat(preview_shm.shmid, NULL, 0774)) == (void *)-1)
		exit(3);

	fifo_path = strdup(SHM_REF_ADDR(shm_ptr_tbl->fifo_path));

	sprintf(logname, "sony-%d", library->eq);
	defaults = GetDefaults();
	openlog(logname, LOG_PID | LOG_NOWAIT, defaults->log_facility);

	dev_ptr_tbl = (dev_ptr_tbl_t *)SHM_REF_ADDR(
	    ((shm_ptr_tbl_t *)master_shm.shared_memory)->dev_table);

	/* LINTED pointer cast may result in improper alignment */
	library->un = (dev_ent_t *)
	    SHM_REF_ADDR(dev_ptr_tbl->d_ent[library->eq]);
	/* LINTED pointer cast may result in improper alignment */
	library->help_msg = (sony_priv_mess_t *)
	    SHM_REF_ADDR(library->un->dt.rb.private);
	l_mess = library->un->dis_mes[DIS_MES_NORM];
	lc_mess = library->un->dis_mes[DIS_MES_CRIT];

	/* check if we should log sef data */
	(void) sef_status();

	if (DBG_LVL(SAM_DBG_RBDELAY)) {
		int ldk = 60;

		sam_syslog(LOG_DEBUG, "Waiting for 60 seconds.");
		while (ldk > 0 && DBG_LVL(SAM_DBG_RBDELAY)) {
			sprintf(lc_mess, "waiting for %d seconds pid %d",
			    ldk, mypid);
			sleep(10);
			ldk -= 10;
		}
		*lc_mess = '\0';
	}

	mutex_init(&library->mutex, USYNC_THREAD, NULL);

	/*
	 * Hold the lock until initialization is complete
	 */
	mutex_lock(&library->mutex);
	common_init(library->un);
	mutex_init(&library->help_msg->mutex, USYNC_PROCESS, NULL);
	cond_init(&library->help_msg->cond_i, USYNC_PROCESS, NULL);
	cond_init(&library->help_msg->cond_r, USYNC_PROCESS, NULL);
	library->help_msg->mtype = SONY_PRIV_VOID;

	/*
	 * Start the main threads
	 */
	if (thr_create(NULL, DF_THR_STK, monitor_msg, (void *)library,
	    (THR_BOUND | THR_NEW_LWP | THR_DETACHED),
	    &threads[SONY_MSG_THREAD])) {
		sam_syslog(LOG_ERR,
		    "Unable to start thread monitor_msg: %m.\n");
		thr_exit(NULL);
	}

	if (thr_create(NULL, MD_THR_STK, manage_list, (void *)library,
	    (THR_BOUND |THR_NEW_LWP | THR_DETACHED),
	    &threads[SONY_WORK_THREAD])) {
		sam_syslog(LOG_ERR,
		    "Unable to start thread manage_list: %m.\n");
		thr_kill(threads[SONY_MSG_THREAD], SIGINT);
		thr_exit(NULL);
	}

	mutex_lock(&library->un->mutex);
	library->un->dt.rb.process = getpid();
	library->un->status.b.ready = FALSE;
	library->un->status.b.present = FALSE;
	mutex_unlock(&library->un->mutex);

	/*
	 * Initialize the library. This will release the library mutex.
	 */
	memccpy(l_mess, catgets(catfd, SET, 9065, "initializing"),
	    '\0', DIS_MES_LEN);
	if (initialize(library, dev_ptr_tbl))
		thr_exit(NULL);

	/*
	 * Now let the other threads run
	 */
	thr_yield();

	mutex_lock(&library->mutex);
	i = 30;

	{
		char *MES_9155 = catgets(catfd, SET, 9155,
		    "waiting for %d drives to initialize");
		char *mes = (char *)malloc_wait(strlen(MES_9155) + 15, 5, 0);

		while (library->countdown && i-- > 0) {
			sprintf(mes, MES_9155, library->countdown);
			memccpy(l_mess, mes, '\0', DIS_MES_LEN);
			sam_syslog(LOG_INFO, catgets(catfd, SET, 9156,
			    "%s: Waiting for %d drives to initialize."),
			    ent_pnt, library->countdown);
			mutex_unlock(&library->mutex);
			sleep(10);
			mutex_lock(&library->mutex);
		}
		free(mes);
	}

	if (i <= 0)
		sam_syslog(LOG_INFO,
		    catgets(catfd, SET, 9157,
		    "%s: %d drive(s) did not initialize."),
		    ent_pnt, library->countdown);

	mutex_unlock(&library->mutex);
	memccpy(l_mess, "running", '\0', DIS_MES_LEN);
	mutex_lock(&library->un->mutex);
	library->un->status.b.audit = FALSE;
	library->un->status.b.requested = FALSE;
	library->un->status.b.mounted = TRUE;
	library->un->status.b.ready = TRUE;
	mutex_unlock(&library->un->mutex);

	/*
	 * Now that the daemon is fully initialized, the main thread is
	 * just used to monitor the thread state and an indication of shutdown.
	 * This is accomplished using the signals SIGALRM, SIGINT, and SIGTERM.
	 * This is not done with a signal handler, but using the sigwait() call.
	 */
	sigemptyset(&sigwait_set);
	sigaddset(&sigwait_set, SIGINT);
	sigaddset(&sigwait_set, SIGTERM);
	sigaddset(&sigwait_set, SIGALRM);

	/* want to restart system calls */
	sig_action.sa_handler = SIG_DFL;
	sigemptyset(&sig_action.sa_mask);
	sig_action.sa_flags = SA_RESTART;

	sigaction(SIGINT, &sig_action, NULL);
	sigaction(SIGTERM, &sig_action, NULL);
	sigaction(SIGALRM, &sig_action, NULL);
	for (;;) {
		alarm(20);
		what_signal = sigwait(&sigwait_set);
		switch (what_signal) {

			case SIGALRM:
				if ((threads[SONY_MSG_THREAD] ==
				    (thread_t)-1) ||
				    (threads[SONY_WORK_THREAD] ==
				    (thread_t)-1)) {
					/*
					 * If any of the processing threads
					 * have disappeared, log the
					 * fact, and take a core dump
					 */
					sam_syslog(LOG_INFO,
					    "%s: SIGALRM: Thread(s) gone.",
					    ent_pnt);
					abort();
				}
				break;

			/*
			 * For a normal shutdown of the robot daemon:
			 *  1) prevent the alarm from going off during
			 *    shutdown and causing a core dump
			 *  2) log the reason we are shutting down
			 *  3) kill the helper pid if there is one
			 *  4) terminate the connection to the catalog
			 *  5) terminate all of the processing threads
			 */
			case SIGINT:
			case SIGTERM:
				sigdelset(&sigwait_set, SIGALRM);
				sam_syslog(LOG_INFO,
				    "%s: Shutdown by signal %d",
				    ent_pnt, what_signal);
				if (library->helper_pid > 0) {
					kill(library->helper_pid, 9);
				}
				kill_off_threads(library);
				exit(0);
				break;

			default:
				break;
		}
	}
}
示例#14
0
文件: client.cpp 项目: felx/detritus
int main(int argc, char **argv) {
	int	command = -1;

	int	playing = 1;

	int	sock;

	unsigned int	addrlen = sizeof(struct sockaddr_in);
	unsigned int	port = 40642;

	sockaddr_in	addr;

	char	move = EOF;

	common_init(argc, argv, port, addr.sin_addr.s_addr);

	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);

	sock = Socket(PF_INET, SOCK_STREAM, 0);

	Connect(sock, (struct sockaddr *)&addr, addrlen);

	Read(sock, &player.x, sizeof(int));
	Read(sock, &player.y, sizeof(int));

	p_torpedo.x = p_torpedo.y = -1;
	s_torpedo.x = s_torpedo.y = -1;

	while (playing) {
		display();

		do {
			move = getchar();
		} while (move != EOF && !isalpha(move));

		switch(move) {
			case 'r':	player.x = (player.x + 1) % GRID_SZ;
					command = MOVE;
					break;

			case 'l':	player.x = (player.x + GRID_SZ - 1) % GRID_SZ;
					command = MOVE;
					break;

			case 'd':	player.y = (player.y + 1) % GRID_SZ;
					command = MOVE;
					break;

			case 'u':	player.y = (player.y + GRID_SZ - 1) % GRID_SZ;
					command = MOVE;
					break;

			case 'f':	printf("Enter target position (x y) => ");
					command = FIRE;
					scanf("%d %d", &p_torpedo.x, &p_torpedo.y);
					break;

			case 's':	printf("\n***** GAME OVER - You have surrendered! *****\n");
			case EOF:	command = SURRENDER;
					break;

			default:	printf("Sorry, I don't understand the command '%c'.\n", move);
					printf("Enter your move => ");
		}

		Write(sock, &command, sizeof(int));

		if (command == FIRE) {
			Write(sock, &p_torpedo, sizeof(pos));
		} else if (command == SURRENDER) {
			break;
		}

		Read(sock, &command, sizeof(int));

		if (command == HIT) {
			player_score++;
		}

		Read(sock, &command, sizeof(int));

		switch (command) {
			case	FIRE:	Read(sock, &s_torpedo, sizeof(pos));
					if (s_torpedo.x == player.x && s_torpedo.y == player.y) {
						command = HIT;
						server_score++;
					} else {
						command = MISS;
					}

					break;

			case	MOVE:	command = ACK;
		}

		Write(sock, &command, sizeof(int));

		if (player_score == max_score || server_score == max_score) {
			command = SURRENDER;
			Write(sock, &command, sizeof(int));
			playing = 0;
		}
	}


	if (player_score == max_score) {
		printf("You have won!\n");
	} else if (server_score == max_score) {
		printf("You have lost!\n");
	}

	return 0;
}
示例#15
0
void flash_hw_initUnbuffered(Flash *fls, int flags)
{
	common_init(fls);
	fls->blk.priv.vt = &flash_lm3s_unbuffered_vt;
	fls->blk.priv.flags |= flags;
}
示例#16
0
int main() 
{
  Scene &scene = fragmic.scene_get();
  Assets &assets = scene.assets_get();
  Physics &physics = fragmic.physics_get();

  {
    Node *camera_node = scene.node_camera_get();
    common_init(fragmic);
    common_fpcamera_use(camera_node);
    common_debug_use();
  }

  /*
  {
    Node &node = scene.model_load("data/game_assets/", "box.dae");
  }
  */

  /*
  {
    Node &node = *scene.node_create("box");
    node.mesh->cube_generate(3.0f);
    node.material->color_set(glm::vec3(1.f, 0.f, 0.f), 
        glm::vec3(0.f, 1.f, 0.f), glm::vec3(0.f, 0.f, 1.f), 40.f);
    scene.upload_queue_add(node);
  }
  */
 
  /*
  Node *light_node = scene.node_create("Light");
  Light *light = light_node->light_create(assets);
  light->properties_type_set(LIGHT_DIRECTIONAL);
  light->properties_direction_set(glm::vec3(0, -1, 0));
  light->properties_set(glm::vec3(0.2, 0.2, 0.2), glm::vec3(1, 1, 1), glm::vec3(1.0, 1.0, 1.0));
  
  Node &base_node = scene.model_load("data/", "base.dae", MODEL_IMPORT_OPTIMIZED);
  physics.collision_shape_add(base_node, PHYSICS_COLLISION_BOX, true, 0);

  std::unique_ptr<Material> material(new Material());
  material->cubemap_create(CUBEMAP_REFLECTION, "data/game_assets/skybox/SkyboxSet1/DarkStormy/", "DarkStormyFront2048.png",
    "DarkStormyBack2048.png", "bar.png", "foo.png", "DarkStormyLeft2048.png", "DarkStormyRight2048.png");

  {
    Node &node_root = scene.model_load("data/game_assets/", "sphere.dae");
    Node &sphere = *scene.node_find(&node_root, "Sphere");
    Node &cube = *scene.node_find(&node_root, "Cube");
    Node &suzanne= *scene.node_find(&node_root, "Suzanne");
    cube.material_set(material.get());
    sphere.material_set(material.get());
    suzanne.material_set(material.get());
    scene.state_update_recursive(sphere);
    scene.state_update_recursive(cube);
    scene.state_update_recursive(suzanne);
    physics.collision_shape_add(node_root, PHYSICS_COLLISION_CONVEX_HULL, true, 1.f);
    Light *point_light = cube.light_create(assets);
    point_light->properties_type_set(LIGHT_POINT);
    point_light->properties_set(glm::vec3(0.2, 0.2, 0.2), glm::vec3(1.0, 1.0, 1.0), glm::vec3(1.0, 1.0, 1.0));
    point_light->bias_set(glm::vec3(-1, 2.2, -1));
  }
  physics.pause();

  {

    Node &node = *scene.node_create("skybox");
    Mesh *mesh = node.mesh_create(assets);
    Material *material = node.material_create(assets);
    mesh->cube_generate(150.0f);
    material->cubemap_create(CUBEMAP_SKYBOX, "data/game_assets/skybox/SkyboxSet1/DarkStormy/", "DarkStormyFront2048.png",
        "DarkStormyBack2048.png", "bar.png", "foo.png", "DarkStormyLeft2048.png", "DarkStormyRight2048.png");
    scene.upload_queue_add(node);
  }
  */

  scene.scene_graph_print(true);

  fragmic.run();
  fragmic.term();

  return true;
}
示例#17
0
/*
 * server -- run server and process clients requests
 */
int
server(const struct test_case *tc, int argc, char *argv[])
{
	int ret;

	struct req_arg arg = {
		.resp = RESP_ATTR_INIT,
		.pool_attr = POOL_ATTR_INIT,
		.closing = 0,
	};

	struct rpmemd_obc *obc;

	obc = rpmemd_obc_init(0, 1);
	UT_ASSERTne(obc, NULL);

	ret = rpmemd_obc_status(obc, 0);
	UT_ASSERTeq(ret, 0);


	while (1) {
		ret = rpmemd_obc_process(obc, &REQ, &arg);
		if (arg.closing) {
			break;
		} else {
			UT_ASSERTeq(ret, 0);
		}
	}

	ret = rpmemd_obc_process(obc, &REQ, &arg);
	UT_ASSERTeq(ret, 1);

	rpmemd_obc_fini(obc);

	return 0;
}

/*
 * test_cases -- available test cases
 */
static struct test_case test_cases[] = {
	TEST_CASE(server),
	TEST_CASE(client_create),
	TEST_CASE(client_open),
};

#define NTESTS	(sizeof(test_cases) / sizeof(test_cases[0]))

int
main(int argc, char *argv[])
{
	START(argc, argv, "rpmem_obc");
	common_init("rpmem_fip",
		"RPMEM_LOG_LEVEL",
		"RPMEM_LOG_FILE", 0, 0);
	rpmemd_log_init("rpmemd", getenv("RPMEMD_LOG_FILE"), 0);
	rpmemd_log_level = rpmemd_log_level_from_str(
			getenv("RPMEMD_LOG_LEVEL"));

	TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS);

	common_fini();
	rpmemd_log_close();
	DONE(NULL);
}
示例#18
0
static void john_init(char *name, int argc, char **argv)
{
	int show_usage = 0;
	int make_check = (argc == 2 && !strcmp(argv[1], "--make_check"));
	if (make_check)
		argv[1] = "--test=0";

	CPU_detect_or_fallback(argv, make_check);

	status_init(NULL, 1);
	if (argc < 2 ||
            (argc == 2 &&
             (!strcasecmp(argv[1], "--help") ||
              !strcasecmp(argv[1], "-h") ||
              !strcasecmp(argv[1], "-help"))))
	{
		john_register_all(); /* for printing by opt_init() */
		show_usage = 1;
	}
	opt_init(name, argc, argv, show_usage);

	/*
	 * --list=? needs to be supported, because it has been supported in the released
	 * john-1.7.9-jumbo-6 version, and it is used by the bash completion script.
	 * --list=? is, however, not longer mentioned in doc/OPTIONS and in the usage
	 * output. Instead, --list=help is.
	 */
	if (options.listconf &&
	    (!strcasecmp(options.listconf, "help") ||
	     !strcmp(options.listconf, "?")))
	{
		john_list_options();
		exit(0);
	}
	if (options.listconf &&
	    (!strcasecmp(options.listconf, "help:help") ||
	     !strcasecmp(options.listconf, "help:")))
	{
		john_list_help_options();
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "help:format-methods"))
	{
		john_list_method_names();
		exit(0);
	}
	if (options.listconf && !strncasecmp(options.listconf, "help:", 5))
	{
		if (strcasecmp(options.listconf, "help:parameters") &&
		    strcasecmp(options.listconf, "help:list-data"))
		{
			fprintf(stderr,
			        "%s is not a --list option that supports additional values.\nSupported options:\n",
			        options.listconf+5);
			john_list_help_options();
			exit(1);
		}
	}
	if (options.listconf && !strcasecmp(options.listconf, "hidden-options"))
	{
		puts("--help                    print usage summary, just like running the command");
		puts("                          without any parameters");
		puts("--subformat=FORMAT        pick a benchmark format for --format=crypt");
		puts("--mkpc=N                  force a lower max. keys per crypt");
		puts("--length=N                force a lower max. length");
		puts("--field-separator-char=C  use 'C' instead of the ':' in input and pot files");
		puts("--fix-state-delay=N       performance tweak, see documentation");
		puts("--log-stderr              log to screen instead of file\n");
		exit(0);
	}

	if (!make_check) {
#if defined(_OPENMP) && OMP_FALLBACK
#if defined(__DJGPP__) || defined(__CYGWIN32__)
#error OMP_FALLBACK is incompatible with the current DOS and Win32 code
#endif
		if (!getenv("JOHN_NO_OMP_FALLBACK") &&
		    omp_get_max_threads() <= 1) {
#define OMP_FALLBACK_PATHNAME JOHN_SYSTEMWIDE_EXEC "/" OMP_FALLBACK_BINARY
			execv(OMP_FALLBACK_PATHNAME, argv);
			perror("execv: " OMP_FALLBACK_PATHNAME);
		}
#endif

		path_init(argv);

		if (options.listconf && !strcasecmp(options.listconf,
		                                    "build-info"))
		{
			puts("Version: " JOHN_VERSION);
			puts("Build: " JOHN_BLD _MP_VERSION);
			printf("Arch: %d-bit %s\n", ARCH_BITS,
			       ARCH_LITTLE_ENDIAN ? "LE" : "BE");
#if JOHN_SYSTEMWIDE
			puts("System-wide exec: " JOHN_SYSTEMWIDE_EXEC);
			puts("System-wide home: " JOHN_SYSTEMWIDE_HOME);
			puts("Private home: " JOHN_PRIVATE_HOME);
#endif
			printf("$JOHN is %s\n", path_expand("$JOHN/"));
			printf("Format interface version: %d\n", FMT_MAIN_VERSION);
			puts("Rec file version: " RECOVERY_V);
			puts("Charset file version: " CHARSET_V);
			printf("CHARSET_MIN: %d (0x%02x)\n", CHARSET_MIN,
			       CHARSET_MIN);
			printf("CHARSET_MAX: %d (0x%02x)\n", CHARSET_MAX,
			       CHARSET_MAX);
			printf("CHARSET_LENGTH: %d\n", CHARSET_LENGTH);
			printf("Max. Markov mode level: %d\n", MAX_MKV_LVL);
			printf("Max. Markov mode password length: %d\n", MAX_MKV_LEN);
#ifdef __VERSION__
		printf("Compiler version: %s\n", __VERSION__);
#endif
#ifdef __GNUC__
			printf("gcc version: %d.%d.%d\n", __GNUC__,
			       __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
#endif
#ifdef __ICC
			printf("icc version: %d\n", __ICC);
#endif
#ifdef __clang_version__
			printf("clang version: %s\n", __clang_version__);
#endif
#ifdef OPENSSL_VERSION_NUMBER
			// The man page suggests the type of OPENSSL_VERSION_NUMBER is long,
			// gcc insists it is int.
			printf("OpenSSL library version: %lx", (unsigned long)OPENSSL_VERSION_NUMBER);
			// FIXME: How do I detect a missing library?
			// Even if if is extremely unlikely that openssl is missing,
			// at least flush all output buffers...
			fflush(NULL);
			if ((unsigned long)OPENSSL_VERSION_NUMBER != (unsigned long)SSLeay())
				printf("\t(loaded: %lx)", (unsigned long)SSLeay());
			printf("\n");
#endif
			exit(0);
		}
	}

	if (options.listconf && !strcasecmp(options.listconf, "encodings"))
	{
		listEncodings();
		exit(0);
	}
#ifdef CL_VERSION_1_0
	if (options.listconf && !strcasecmp(options.listconf, "opencl-devices"))
	{
		listOpenCLdevices();
		exit(0);
	}
#endif
#ifdef HAVE_CUDA
	if (options.listconf && !strcasecmp(options.listconf, "cuda-devices"))
	{
		cuda_device_list();
		exit(0);
	}
#endif

	if (!make_check) {
		if (options.config)
		{
			path_init_ex(options.config);
			cfg_init(options.config, 1);
			cfg_init(CFG_FULL_NAME, 1);
			cfg_init(CFG_ALT_NAME, 0);
		}
		else
		{
#if JOHN_SYSTEMWIDE
			cfg_init(CFG_PRIVATE_FULL_NAME, 1);
			cfg_init(CFG_PRIVATE_ALT_NAME, 1);
#endif
			cfg_init(CFG_FULL_NAME, 1);
			cfg_init(CFG_ALT_NAME, 0);
		}
	}

	/* This is --crack-status. We toggle here, so if it's enabled in
	   john.conf, we can disable it using the command line option */
	if (cfg_get_bool(SECTION_OPTIONS, NULL, "CrackStatus", 0))
		options.flags ^= FLG_CRKSTAT;

	initUnicode(UNICODE_UNICODE); /* Init the unicode system */

	john_register_all(); /* maybe restricted to one format by options */
	if ((options.subformat && !strcasecmp(options.subformat, "list")) ||
	    (options.listconf && !strcasecmp(options.listconf, "subformats")))
	{
		dynamic_DISPLAY_ALL_FORMATS();
		/* NOTE if we have other 'generics', like sha1, sha2, rc4, ...
		 * then EACH of them should have a DISPLAY_ALL_FORMATS()
		 * function and we can call them here. */
		exit(0);
	}

	if (options.listconf && !strcasecmp(options.listconf, "inc-modes"))
	{
		cfg_print_subsections("Incremental", NULL, NULL, 0);
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "rules"))
	{
		cfg_print_subsections("List.Rules", NULL, NULL, 0);
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "externals"))
	{
		cfg_print_subsections("List.External", NULL, NULL, 0);
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "sections"))
	{
		cfg_print_section_names(0);
		exit(0);
	}
	if (options.listconf &&
	    !strncasecmp(options.listconf, "parameters", 10) &&
	    (options.listconf[10] == '=' || options.listconf[10] == ':') &&
	    options.listconf[11] != '\0')
	{
		cfg_print_section_params(&options.listconf[11], NULL);
		exit(0);
	}
	if (options.listconf &&
	    !strncasecmp(options.listconf, "list-data", 9) &&
	    (options.listconf[9] == '=' || options.listconf[9] == ':') &&
	    options.listconf[10] != '\0')
	{
		cfg_print_section_list_lines(&options.listconf[10], NULL);
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "ext-filters"))
	{
		cfg_print_subsections("List.External", "filter", NULL, 0);
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "ext-filters-only"))
	{
		cfg_print_subsections("List.External", "filter", "generate", 0);
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "ext-modes"))
	{
		cfg_print_subsections("List.External", "generate", NULL, 0);
		exit(0);
	}

	if (options.listconf &&
	    !strcasecmp(options.listconf, "formats")) {
		int column;
		struct fmt_main *format;
		int i, dynamics = 0;
		char **formats_list;

		i = 0;
		format = fmt_list;
		while ((format = format->next))
			i++;

		formats_list = malloc(sizeof(char*) * i);

		i = 0;
		format = fmt_list;
		do {
			char *label = format->params.label;
			if (!strncmp(label, "dynamic", 7)) {
				if (dynamics++)
					continue;
				else
					label = "dynamic_n";
			}
			formats_list[i++] = label;
		} while ((format = format->next));
		formats_list[i] = NULL;

		column = 0;
		i = 0;
		do {
			int length;
			char *label = formats_list[i++];
			length = strlen(label) + 2;
			column += length;
			if (column > 78) {
				printf("\n");
				column = length;
			}
			printf("%s%s", label, formats_list[i] ? ", " : "\n");
		} while (formats_list[i]);
		free(formats_list);
		exit(0);
	}
	if (options.listconf &&
	    !strcasecmp(options.listconf, "format-details")) {
		struct fmt_main *format;
		format = fmt_list;
		do {
			int ntests = 0;

			if(format->params.tests) {
				while (format->params.tests[ntests++].ciphertext);
				ntests--;
			}
			printf("%s\t%d\t%d\t%d\t%08x\t%d\t%s\t%s\t%s\t%d\t%d\t%d\n",
			       format->params.label,
			       format->params.plaintext_length,
			       format->params.min_keys_per_crypt,
			       format->params.max_keys_per_crypt,
			       format->params.flags,
			       ntests,
			       format->params.algorithm_name,
			       format->params.format_name,
			       format->params.benchmark_comment,
			       format->params.benchmark_length,
			       format->params.binary_size,
			       ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ?
			       // salts are handled internally within the format. We want to know the 'real' salt size
			       // dynamic will alway set params.salt_size to 0 or sizeof a pointer.
			       dynamic_real_salt_length(format) : format->params.salt_size);
		} while ((format = format->next));
		exit(0);
	}
	if (options.listconf &&
	    !strcasecmp(options.listconf, "format-all-details")) {
		struct fmt_main *format;
		format = fmt_list;
		do {
			int ntests = 0;

			if(format->params.tests) {
				while (format->params.tests[ntests++].ciphertext);
				ntests--;
			}
			/*
			 * attributes should be printed in the same sequence
			 * as with format-details, but human-readable
			 */
			printf("Format label                    \t%s\n", format->params.label);
			printf("Max. password length in bytes   \t%d\n", format->params.plaintext_length);
			printf("Min. keys per crypt             \t%d\n", format->params.min_keys_per_crypt);
			printf("Max. keys per crypt             \t%d\n", format->params.max_keys_per_crypt);
			printf("Flags\n");
			printf(" Case sensitive                 \t%s\n", (format->params.flags & FMT_CASE) ? "yes" : "no");
			printf(" Supports 8-bit characters      \t%s\n", (format->params.flags & FMT_8_BIT) ? "yes" : "no");
			printf(" Converts 8859-1 to UTF-16/UCS-2\t%s\n", (format->params.flags & FMT_UNICODE) ? "yes" : "no");
			printf(" Honours --encoding=NAME        \t%s\n", (format->params.flags & FMT_UTF8) ? "yes" : "no");
			printf(" False positives possible       \t%s\n", (format->params.flags & FMT_NOT_EXACT) ? "yes" : "no");
			printf(" Uses a bitslice implementation \t%s\n", (format->params.flags & FMT_BS) ? "yes" : "no");
			printf(" The split() method unifies case\t%s\n", (format->params.flags & FMT_SPLIT_UNIFIES_CASE) ? "yes" : "no");
			printf(" A $dynamic$ format             \t%s\n", (format->params.flags & FMT_DYNAMIC) ? "yes" : "no");
#ifdef _OPENMP
			printf(" Parallelized with OpenMP       \t%s\n", (format->params.flags & FMT_OMP) ? "yes" : "no");
#endif
			printf("Number of test cases for --test \t%d\n", ntests);
			printf("Algorithm name                  \t%s\n", format->params.algorithm_name);
			printf("Format name                     \t%s\n", format->params.format_name);
			printf("Benchmark comment               \t%s\n", format->params.benchmark_comment);
			printf("Benchmark length                \t%d\n", format->params.benchmark_length);
			printf("Binary size                     \t%d\n", format->params.binary_size);
			printf("Salt size                       \t%d\n",
			       ((format->params.flags & FMT_DYNAMIC) && format->params.salt_size) ?
			       // salts are handled internally within the format. We want to know the 'real' salt size/
			       // dynamic will alway set params.salt_size to 0 or sizeof a pointer.
			       dynamic_real_salt_length(format) : format->params.salt_size);
			printf("\n");
		} while ((format = format->next));
		exit(0);
	}
	if (options.listconf &&
	    !strncasecmp(options.listconf, "format-methods", 14)) {
		struct fmt_main *format;
		format = fmt_list;
		do {
			int ShowIt = 1, i;
			if (options.listconf[14] == '=' || options.listconf[14] == ':') {
				ShowIt = 0;
				if (!strcasecmp(&options.listconf[15], "set_key")   ||
					!strcasecmp(&options.listconf[15], "get_key")   ||
					!strcasecmp(&options.listconf[15], "crypt_all") ||
					!strcasecmp(&options.listconf[15], "cmp_all")   ||
					!strcasecmp(&options.listconf[15], "cmp_one")  ||
					!strcasecmp(&options.listconf[15], "cmp_exact"))
					ShowIt = 1;
				else if (strcasecmp(&options.listconf[15], "init") && strcasecmp(&options.listconf[15], "prepare") &&
					strcasecmp(&options.listconf[15], "valid") && strcasecmp(&options.listconf[15], "split") &&
					strcasecmp(&options.listconf[15], "binary") && strcasecmp(&options.listconf[15], "clear_keys") &&
					strcasecmp(&options.listconf[15], "salt") && strcasecmp(&options.listconf[15], "get_hash") &&
					strcasecmp(&options.listconf[15], "get_hash[0]") && strcasecmp(&options.listconf[15], "get_hash[1]") &&
					strcasecmp(&options.listconf[15], "get_hash[2]") && strcasecmp(&options.listconf[15], "get_hash[3]") &&
					strcasecmp(&options.listconf[15], "get_hash[4]") && strcasecmp(&options.listconf[15], "get_hash[5]") &&
					strcasecmp(&options.listconf[15], "set_salt") && strcasecmp(&options.listconf[15], "binary_hash") &&
					strcasecmp(&options.listconf[15], "binary_hash[0]") && strcasecmp(&options.listconf[15], "binary_hash[1]") &&
					strcasecmp(&options.listconf[15], "binary_hash[2]") && strcasecmp(&options.listconf[15], "binary_hash[3]") &&
					strcasecmp(&options.listconf[15], "binary_hash[3]") && strcasecmp(&options.listconf[15], "binary_hash[5]") &&
					strcasecmp(&options.listconf[15], "salt_hash"))
				{
					fprintf(stderr, "Error, invalid option (invalid method name) %s\n", options.listconf);
					fprintf(stderr, "Valid method names are:\n");
					john_list_method_names();
					exit(1);
				}
				if (format->methods.init != fmt_default_init && !strcasecmp(&options.listconf[15], "init"))
					ShowIt = 1;
				if (format->methods.prepare != fmt_default_prepare && !strcasecmp(&options.listconf[15], "prepare"))
					ShowIt = 1;
				if (format->methods.valid != fmt_default_valid && !strcasecmp(&options.listconf[15], "valid"))
					ShowIt = 1;
				if (format->methods.split != fmt_default_split && !strcasecmp(&options.listconf[15], "split"))
					ShowIt = 1;
				if (format->methods.binary != fmt_default_binary && !strcasecmp(&options.listconf[15], "binary"))
					ShowIt = 1;
				if (format->methods.salt != fmt_default_salt && !strcasecmp(&options.listconf[15], "salt"))
					ShowIt = 1;
				if (format->methods.clear_keys != fmt_default_clear_keys && !strcasecmp(&options.listconf[15], "clear_keys"))
					ShowIt = 1;
				for (i = 0; i < 6; ++i) {
					char Buf[20];
					sprintf(Buf, "get_hash[%d]", i);
					if (format->methods.get_hash[i] && format->methods.get_hash[i] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], Buf))
						ShowIt = 1;
				}
				if (format->methods.get_hash[0] && format->methods.get_hash[0] != fmt_default_get_hash && !strcasecmp(&options.listconf[15], "get_hash"))
					ShowIt = 1;

				for (i = 0; i < 6; ++i) {
					char Buf[20];
					sprintf(Buf, "binary_hash[%d]", i);
					if (format->methods.binary_hash[i] && format->methods.binary_hash[i] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], Buf))
						ShowIt = 1;
				}
				if (format->methods.binary_hash[0] && format->methods.binary_hash[0] != fmt_default_binary_hash && !strcasecmp(&options.listconf[15], "binary_hash"))
					ShowIt = 1;
				if (format->methods.salt_hash != fmt_default_salt_hash && !strcasecmp(&options.listconf[15], "salt_hash"))
					ShowIt = 1;
				if (format->methods.set_salt != fmt_default_set_salt && !strcasecmp(&options.listconf[15], "set_salt"))
					ShowIt = 1;
			}
			if (ShowIt) {
				int i;
				printf("Methods overridden for:   %s [%s] %s\n", format->params.label, format->params.algorithm_name, format->params.format_name);
				if (format->methods.init != fmt_default_init)
					printf("\tinit()\n");
				if (format->methods.prepare != fmt_default_prepare)
					printf("\tprepare()\n");
				if (format->methods.valid != fmt_default_valid)
					printf("\tvalid()\n");
				if (format->methods.split != fmt_default_split)
					printf("\tsplit()\n");
				if (format->methods.binary != fmt_default_binary)
					printf("\tbinary()\n");
				if (format->methods.salt != fmt_default_salt)
					printf("\tsalt()\n");
				for (i = 0; i < 6; ++i)
					if (format->methods.binary_hash[i] != fmt_default_binary_hash) {
						if (format->methods.binary_hash[i])
							printf("\t\tbinary_hash[%d]()\n", i);
						else
							printf("\t\tbinary_hash[%d]()  (NULL pointer)\n", i);
					}
				if (format->methods.salt_hash != fmt_default_salt_hash)
					printf("\tsalt_hash()\n");
				if (format->methods.set_salt != fmt_default_set_salt)
					printf("\tset_salt()\n");
				// there is no default for set_key() it must be defined.
				printf("\tset_key()\n");
				// there is no default for get_key() it must be defined.
				printf("\tget_key()\n");
				if (format->methods.clear_keys != fmt_default_clear_keys)
					printf("\tclear_keys()\n");
				for (i = 0; i < 6; ++i)
					if (format->methods.get_hash[i] != fmt_default_get_hash) {
						if (format->methods.get_hash[i])
							printf("\t\tget_hash[%d]()\n", i);
						else
							printf("\t\tget_hash[%d]()  (NULL pointer)\n", i);
					}
				// there is no default for crypt_all() it must be defined.
				printf("\tcrypt_all()\n");
				// there is no default for cmp_all() it must be defined.
				printf("\tcmp_all()\n");
				// there is no default for cmp_one() it must be defined.
				printf("\tcmp_one()\n");
				// there is no default for cmp_exact() it must be defined.
				printf("\tcmp_exact()\n");
				printf("\n\n");
			}
		} while ((format = format->next));
		exit(0);
	}
	/*
	 * Other --list=help:WHAT are processed earlier, but these require
	 * a valid config:
	 */
	if (options.listconf && !strcasecmp(options.listconf, "help:parameters"))
	{
		cfg_print_section_names(1);
		exit(0);
	}
	if (options.listconf && !strcasecmp(options.listconf, "help:list-data"))
	{
		cfg_print_section_names(2);
		exit(0);
	}

	/* --list last resort: list subsections of any john.conf section name */
	if (options.listconf)
	{
		//printf("Subsections of [%s]:\n", options.listconf);
		if (cfg_print_subsections(options.listconf, NULL, NULL, 1))
			exit(0);
		else {
			fprintf(stderr, "Section [%s] not found.\n", options.listconf);
			/* Just in case the user specified an invalid value
			 * like help or list...
			 * print the same list as with --list=?, but exit(1)
			 */
			john_list_options();
			exit(1);
		}
	}

#ifdef CL_VERSION_1_0
	if (!options.ocl_platform) {
		if ((options.ocl_platform =
		     cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Platform")))
			platform_id = atoi(options.ocl_platform);
		else
			platform_id = -1;
	}
	if (!options.gpu_device) {
		if ((options.gpu_device =
		     cfg_get_param(SECTION_OPTIONS, SUBSECTION_OPENCL, "Device")))
			ocl_gpu_id = atoi(options.gpu_device);
		else
			ocl_gpu_id = -1;
	}
	if (platform_id == -1 || ocl_gpu_id == -1)
		opencl_find_gpu(&ocl_gpu_id, &platform_id);
#endif

	common_init();
	sig_init();

	john_load();

	if (options.encodingStr && options.encodingStr[0])
		log_event("- %s input encoding enabled", options.encodingStr);
}
// 硬件串口构造函数
camera_VC0706::camera_VC0706(HardwareSerial *ser) {
	common_init();  // Set everything to common state, then...
	hwSerial = ser; // ...override hwSerial with value passed.
}
示例#20
0
文件: cli.c 项目: mhfan/stoken
int main(int argc, char **argv)
{
	char *cmd = parse_cmdline(argc, argv, NOT_GUI);
	int rc;
	char buf[BUFLEN];
	struct securid_token *t;

	rc = common_init(cmd);
	if (rc != ERR_NONE)
		die("can't initialize: %s\n", stoken_errstr[rc]);

	t = current_token;
	if (!t)
		die("error: no token present.  Use 'stoken import' to add one.\n");

	terminal_init();

	if (!strcmp(cmd, "tokencode")) {
		int days_left = securid_check_exp(t, adjusted_time());

		if (days_left < 0 && !opt_force)
			die("error: token has expired; use --force to override\n");

		unlock_token(t, 1, NULL);
		securid_compute_tokencode(t, adjusted_time(), buf);
		puts(buf);

		if (days_left < 14 && !opt_force)
			warn("warning: token expires in %d day%s\n", days_left,
				days_left == 1 ? "" : "s");
	} else if (!strcmp(cmd, "import")) {
		char *pass;

		unlock_token(t, 0, &pass);
		if (!opt_keep_password) {
			pass = xmalloc(BUFLEN);
			request_new_pass(pass);
		}

		t->is_smartphone = 0;
		securid_encode_token(t, pass, opt_new_devid, buf);
		rc = write_token_and_pin(buf, NULL, pass);
		if (rc != ERR_NONE)
			die("rcfile: error writing new token: %s\n",
				stoken_errstr[rc]);
	} else if (!strcmp(cmd, "export")) {
		char *pass;

		unlock_token(t, 0, &pass);
		if (opt_new_password)
			pass = opt_new_password;
		else if (!opt_keep_password)
			pass = NULL;

		t->is_smartphone = opt_iphone || opt_android;
		securid_encode_token(t, pass, opt_new_devid, buf);
		print_formatted(buf);
	} else if (!strcmp(cmd, "show")) {
		unlock_token(t, 0, NULL);
		securid_token_info(t, &print_token_info_line);
	} else if (!strcmp(cmd, "setpin")) {
		char *pass = NULL, pin[BUFLEN], confirm_pin[BUFLEN];
		int len;

		if (opt_file || opt_token)
			die("error: setpin only operates on the rcfile token\n");

		unlock_token(t, 0, &pass);

		if (opt_new_pin) {
			if (securid_pin_format_ok(opt_new_pin) != ERR_NONE)
				die("error: invalid --new-pin format\n");
			strncpy(pin, opt_new_pin, BUFLEN);
			len = strlen(pin);
		} else {
			prompt("Enter new PIN: ");
			len = read_user_input(pin, BUFLEN, 1);
			if (len > 0 && securid_pin_format_ok(pin) != ERR_NONE)
				die("error: PIN must be 4-8 digits\n");

			prompt("Confirm new PIN: ");
			read_user_input(confirm_pin, BUFLEN, 1);
			if (strcmp(pin, confirm_pin) != 0)
				die("error: PINs do not match\n");
		}

		securid_encode_token(t, pass, NULL, buf);
		rc = write_token_and_pin(buf, len ? pin : NULL, pass);
		free(pass);

		if (rc != ERR_NONE)
			die("error: can't set PIN: %s\n", stoken_errstr[rc]);
	} else if (!strcmp(cmd, "setpass")) {
		char pass[BUFLEN];

		unlock_token(t, 0, NULL);
		request_new_pass(pass);
		securid_encode_token(t, pass, NULL, buf);

		/* just print to stdout if it didn't come from the rcfile */
		if (opt_file || opt_token)
			print_formatted(buf);
		else {
			rc = write_token_and_pin(buf,
						 strlen(t->pin) ? t->pin : NULL,
						 strlen(pass) ? pass : NULL);
			if (rc != ERR_NONE)
				die("error: can't set password: %s\n",
				    stoken_errstr[rc]);
		}
	} else
		die("error: invalid command '%s'\n", cmd);

	return 0;
}
示例#21
0
int main P2C(int,ac,char**,av)
#line 95 "./cwebdir/ctangle.w"
{
argc= ac;argv= av;
program= ctangle;
/*17:*/
#line 167 "./cwebdir/ctangle.w"

text_info->tok_start= tok_ptr= tok_mem;
text_ptr= text_info+1;text_ptr->tok_start= tok_mem;


/*:17*//*19:*/
#line 177 "./cwebdir/ctangle.w"

name_dir->equiv= (char*)text_info;

/*:19*//*23:*/
#line 230 "./cwebdir/ctangle.w"
last_unnamed= text_info;text_info->text_link= 0;

/*:23*//*38:*/
#line 512 "./cwebdir/ctangle.w"

cur_out_file= end_output_files= output_files+max_files;

/*:38*//*51:*/
#line 713 "./cwebdir/ctangle.w"

{
int i;
for(i= 0;i<128;i++)sprintf(translit[i],"X%02X",(unsigned)(128+i));
}

/*:51*//*56:*/
#line 792 "./cwebdir/ctangle.w"
{
int c;
for(c= 0;c<256;c++)ccode[c]= ignore;
ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']
= ccode['*']= new_section;
ccode['@']= '@';ccode['=']= string;
ccode['d']= ccode['D']= definition;
ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;
ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;
ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']= 
ccode['q']= ccode['Q']= control_text;
ccode['h']= ccode['H']= output_defs_code;
ccode['l']= ccode['L']= translit_code;
ccode['&']= join;
ccode['<']= ccode['(']= section_name;
ccode['\'']= ord;
}

/*:56*//*70:*/
#line 1116 "./cwebdir/ctangle.w"
section_text[0]= ' ';

/*:70*/
#line 98 "./cwebdir/ctangle.w"
;
common_init();
#line 76 "./cwebdir/ctang-w2c.ch"
if(show_banner){
printf("%s%s\n",banner,versionstring);
}
#line 101 "./cwebdir/ctangle.w"
phase_one();
phase_two();
return wrap_up();
}
示例#22
0
GameAsset::GameAsset() {
  common_init();
  this->v_shader = "shaders/hello-gl.v.glsl";
  this->f_shader = "shaders/hello-gl.f.glsl";
}
示例#23
0
// Constructor cuando se usa HardwareSerial
GPS_5Hz::GPS_5Hz(HardwareSerial *ser) {
  common_init();  // inicializa todo comunmente, y luego...
  gpsHwSerial = ser; // ...se modifica gpsHwSerial con el valor pasado.
}
示例#24
0
GameAsset::GameAsset(const string & v_shader, const string & f_shader) {
  common_init();
  this->v_shader = v_shader;
  this->f_shader = f_shader;
}
示例#25
0
/**
 * Initialize the driver.
 * \param drvthis  Pointer to driver structure.
 * \retval 0       Success.
 * \retval -1      Error opening device.
 * \retval -2      Error reading or unsupported driver version.
 * \retval -3      Error reading or unsupported hardware version.
 */
int
hd_init_usblcd(Driver *drvthis)
{
	PrivateData *p = (PrivateData *) drvthis->private_data;

	char device[256] = DEFAULT_DEVICE;
	char buf[128];
	int major, minor;

	/* Get device to use */
	strncpy(device, drvthis->config_get_string(drvthis->name, "device", 0, DEFAULT_DEVICE), sizeof(device));
	device[sizeof(device) - 1] = '\0';
	report(RPT_INFO, "HD44780: USBLCD: using device: %s", device);

	/* Set up io port correctly, and open it... */
	p->fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY);
	if (p->fd == -1) {
		report(RPT_ERR, "HD44780: USBLCD: could not open device %s (%s)", device, strerror(errno));
		return -1;
	}

	/* Read and check kernel driver version */
	memset(buf, 0, 128);
	if (ioctl(p->fd, IOCTL_GET_DRV_VERSION, buf) != 0) {
		report(RPT_ERR, "IOCTL failed, could not get Driver Version");
		return -2;
	}
	report(RPT_INFO, "Driver Version: %s", buf);

	if (sscanf(buf, "USBLCD Driver Version %d.%d", &major, &minor) != 2) {
		report(RPT_ERR, "Could not read Driver Version");
		return -2;
	}
	if (major != 1) {
		report(RPT_ERR, "Driver Version not supported");
		return -2;
	}

	/* Read and check hardware version */
	memset(buf, 0, 128);
	if (ioctl(p->fd, IOCTL_GET_HARD_VERSION, buf) != 0) {
		report(RPT_ERR, "IOCTL failed, could not get Hardware Version");
		return -3;
	};
	report(RPT_INFO, "Hardware Version: %s", buf);
	if (sscanf(buf, "%d.%d", &major, &minor) != 2) {
		report(RPT_ERR, "Could not read Hardware Version");
		return -3;
	};
	if (major != 1) {
		report(RPT_ERR, "Hardware Version not supported");
		return -3;
	}

	/* Set local functions */
	p->hd44780_functions->senddata = usblcd_HD44780_senddata;
	p->hd44780_functions->backlight = usblcd_HD44780_backlight;
	p->hd44780_functions->close = usblcd_HD44780_close;

	common_init(p, IF_8BIT);
	return 0;
}
示例#26
0
Camera::Camera(HardwareSerial *ser) {
	common_init();
	hwSerial = ser;
}
示例#27
0
static int encode_init(AVCodecContext *avctx){

    common_init(avctx);

    return 0;
}
示例#28
0
// Constructor when using HardwareSerial
SPK_GPS::SPK_GPS(HardwareSerial *ser) {
  common_init();  // Set everything to common state, then...
  gpsHwSerial = ser; // ...override gpsHwSerial with value passed.
}
// Constructor when using HardwareSerial
Adafruit_GPS::Adafruit_GPS() {
  common_init();  // Set everything to common state, then...
  //gpsHwSerial = ser; // ...override gpsHwSerial with value passed.
}
示例#30
0
void Adafruit_GPS::setup(HardwareSerial *ser) {
    common_init();
    gpsHwSerial = ser;
}