Exemplo n.º 1
0
int main()
{
	int is_quit=0;
	/*程序主循环*/
	while(!is_quit)
	{
		int choice;
		char* retstr;
		print_main_menu();
		printf("选择[0~8]:");
		retstr=fgets(keybuf,MAX_KEY_BUF,stdin);
		choice=atoi(keybuf);
		/*根据选择执行相应功能*/
		switch(choice)
		{
			/*退出*/
			case 0:
				is_quit=1;
				break;
			case 1:
				print_date();
				if(0==query_user("进行修改?",q_opt,Q_OPT_NUM,1))
					modify_date();
				break;
			case 2:
				print_time();
				if(0==query_user("进行修改?",q_opt,Q_OPT_NUM,1))
					modify_time();
				break;
			case 3:
				print_alarm();	
				if(0==query_user("进行修改?",q_opt,Q_OPT_NUM,1))
					modify_alarm();
				break;
			case 4:
				print_cmos_content();
				if(0==query_user("进行修改?",q_opt,Q_OPT_NUM,1))
					modify_cmos_content();
				break;
			case 5:
				backup_cmos();
				break;
			case 6:
				restore_cmos();
				break;
			default:
				is_quit=0;
		}

	}
	
	return EXIT_SUCCESS;
}
Exemplo n.º 2
0
void begin()
{
	int i;

	ACCESS_CHECK(previous_object() == query_user());

	::begin();

	speed = 5.0;
	send_out("\033[1;1H\033[2J");

	particles = allocate(NPARTICLES);

	for (i = 0; i < NPARTICLES; i++) {
		float *particle;
		particle = particles[i] = allocate_float(3);

		do {
			particle[2] = (1.0 - pow(MATHD->rnd(), 2.0)) * 11.0;
		} while (particle[2] < 1.0);

		particle[0] = (MATHD->rnd() * 80.0 - 40.0) * particle[2];
		particle[1] = (MATHD->rnd() * 27.5 - 15.0) * particle[2];
	}
}
Exemplo n.º 3
0
void action(mapping roles)
{
	object exit;
	object target;
	object actor;
	object retexit;

	actor = roles["actor"];
	exit = roles["dob"];

	retexit = exit->query_property("exit_return");

	if (retexit) {
		target = retexit->query_environment();

		if (!target) {
			send_out("Oops, " + TEXT_SUBD->generate_brief_definite(exit) + "'s return exit is lost in the void.\n");
			return;
		}
	} else {
		target = exit->query_property("exit_destination");
	}

	if (!target) {
		send_out("Oops, " + TEXT_SUBD->generate_brief_definite(exit) + " doesn't have a destination.\n");
		return;
	}

	if (actor->query_property("is_immobile")) {
		send_out("You're stuck like glue and can't move.\n");
		return;
	}

	if (query_user()->query_class() >= 2) {
		emit_from(actor, actor, " ", ({ "leave", "leaves" }), " through ", exit, ".");
Exemplo n.º 4
0
/*恢复CMOS*/
void restore_cmos()
{
	FILE* fp;
	char* ret_str;
	unsigned char buf[CMOS_BUF_SIZE]={0};
	int rc;
	size_t rdsz;
	/*获取备份文件路径*/
	printf("\n备份文件路径:");
	ret_str=fgets(keybuf,MAX_KEY_BUF,stdin);
	keybuf_convert(keybuf);
	/*尝试打开文件*/
	fp=fopen(keybuf,"r");
	if(NULL==fp)
	{
		printf("文件%s打开失败!\n",keybuf);
		return;
	}
	/*读取文件*/
	rdsz=fread((void*)buf,sizeof(unsigned char),CMOS_BUF_SIZE,fp);
	printf("从%s读入%lu字节,完成。\n",keybuf,rdsz);
	/*确认恢复*/
	if(0==query_user("确定要恢复备份至CMOS内存?",q_opt,Q_OPT_NUM,1))
	{
		/*写入*/
		printf("写入中,请稍候...\n");
		rc=cmos_setalldata(buf);
		if(rc)
		{
			printf("出现错误,错误代码%d,请联系[email protected]\n",rc);
			return;
		}
	}
	return;
}
Exemplo n.º 5
0
Arquivo: chat.c Projeto: wyat/kbs
void call_query_ByChatid(chatcontext * pthis, const char *arg)
{                               /* add by dong, 1998.9.12 */
    char uident[32];
    char tmpstr[40];
    int res;

    if (!*arg) {
        printchatline(pthis, "*** 请输入要查询的chat ID ***");
        return;
    }
    strncpy(uident, arg, 32);
    uident[31] = '\0';
    /* get user id from the chat id */
    sprintf(tmpstr, "/qc %s", uident);
    chat_send(pthis, tmpstr);
    res = chat_recv(pthis, tmpstr, 40);
    if (res <= 0)
        return;
    tmpstr[res] = '\0';
    if (tmpstr[0] == '1') {
        sprintf(uident, "%s", tmpstr + 1);
    } else {
        sprintf(genbuf, "\033[32m这个chat ID不存在!\033[m");
        printchatline(pthis, genbuf);
        return;
    }
    query_user(pthis, uident);
}
Exemplo n.º 6
0
int datagram(string str)
{
	ACCESS_CHECK(previous_object() == query_user()
		|| calling_object() == this_object());

	return user::datagram(str);
}
Exemplo n.º 7
0
void datagram_challenge(string str)
{
	ACCESS_CHECK(previous_object() == query_user()
		|| calling_object() == this_object());

	user::datagram_challenge(str);
}
Exemplo n.º 8
0
void disconnect()
{
	ACCESS_CHECK(previous_object() == query_user()
		|| calling_object() == this_object());

	user::disconnect();
}
Exemplo n.º 9
0
int message(string str)
{
	ACCESS_CHECK(previous_object() == query_user()
		|| calling_object() == this_object());

	return user::message(str);
}
Exemplo n.º 10
0
Arquivo: chat.c Projeto: wyat/kbs
void call_query(chatcontext * pthis, const char *arg)
/* by alex, 1996.9.5 */
/* by Luzi, 1997.11.30 */
{
    if (!*arg) {
        printchatline(pthis, "*** 请输入要查询的ID ***");
    } else {
        query_user(pthis, arg);
    }
}
Exemplo n.º 11
0
bool 
AudioProcessor::set_user(Speakers new_user_spk)
{
  if (user_spk == new_user_spk)
    return true;

  if (!query_user(new_user_spk))
    return false;

  user_spk = new_user_spk;
  rebuild = true;
  return true;
}
Exemplo n.º 12
0
bool
DVDGraph::set_user(Speakers _user_spk)
{
  if (!query_user(_user_spk))
    return false;

  if (user_spk != _user_spk)
  {
    user_spk = _user_spk;
    rebuild_node(state_proc);
    rebuild_node(state_proc_enc);
    rebuild_node(state_detector);
  }

  return true;
}
Exemplo n.º 13
0
void begin()
{
	int i;

	ACCESS_CHECK(previous_object() == query_user());

	::begin();

	send_out("\033[1;1H\033[2J");

	particles = allocate(NPARTICLES);

	for (i = 0; i < NPARTICLES; i++) {
		particles[i] = allocate_float(4);
		particles[i][1] = 25.0;
	}
}
Exemplo n.º 14
0
Speakers 
AudioProcessor::user2output(Speakers in_spk_, Speakers user_spk_) const
{
  if (!can_open(in_spk_) || !query_user(user_spk_))
    return spk_unknown;

  Speakers result = in_spk_;
  if (user_spk_.format != FORMAT_UNKNOWN)
  {
    result.format = user_spk_.format;
    result.level = user_spk_.level;
  }

  if (user_spk_.mask)
    result.mask = user_spk_.mask;

  if (user_spk_.sample_rate)
    result.sample_rate = user_spk_.sample_rate;

  result.relation = user_spk_.relation;

  return result;
}
Exemplo n.º 15
0
bool ro_gui_download_window_destroy(struct gui_download_window *dw, bool quit)
{
	bool safe = dw->saved && !dw->ctx;
	os_error *error;

	if (!safe && !dw->close_confirmed)
	{
		query_reason rsn = quit ? QueryRsn_Quit : QueryRsn_Abort;

		if (dw->query != QUERY_INVALID) {

			/* can we just reuse the existing query? */
			if (rsn == dw->query_rsn) {
				ro_gui_query_window_bring_to_front(dw->query);
				return false;
			}

			query_close(dw->query);
			dw->query = QUERY_INVALID;
		}

		if (quit) {
			/* bring all download windows to the front of the desktop as
			   a convenience if there are lots of windows open */

			struct gui_download_window *d = download_window_list;
			while (d) {
				ro_gui_dialog_open_top(d->window, NULL, 0, 0);
				d = d->next;
			}
		}

		dw->query_rsn = rsn;
		dw->query = query_user(quit ? "QuitDownload" : "AbortDownload",
				NULL, &close_funcs, dw, NULL, NULL);

		return false;
	}

	schedule_remove(ro_gui_download_update_status_wrapper, dw);
	schedule_remove(ro_gui_download_window_destroy_wrapper, dw);

	/* remove from list */
	if (dw->prev)
		dw->prev->next = dw->next;
	else
		download_window_list = dw->next;
	if (dw->next)
		dw->next->prev = dw->prev;

	/* delete window */
	error = xwimp_delete_window(dw->window);
	if (error) {
		LOG(("xwimp_delete_window: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
	}
	ro_gui_wimp_event_finalise(dw->window);

	/* close download file */
	if (dw->file) {
		error = xosfind_closew(dw->file);
		if (error) {
			LOG(("xosfind_closew: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("SaveError", error->errmess);
		}
	}

	/* delete temporary file */
	if (!dw->saved) {
		const char *temp_name = ro_gui_download_temp_name(dw);

		error = xosfile_delete(temp_name, 0, 0, 0, 0, 0);
		if (error) {
			LOG(("xosfile_delete: 0x%x: %s",
					error->errnum, error->errmess));
			warn_user("SaveError", error->errmess);
		}
	}

	if (dw->ctx) {
		download_context_abort(dw->ctx);
		download_context_destroy(dw->ctx);
	}

	free(dw);

	return true;
}
Exemplo n.º 16
0
bool ro_gui_download_save(struct gui_download_window *dw,
		const char *file_name, bool force_overwrite)
{
	fileswitch_object_type obj_type;
	const char *temp_name;
	os_error *error;

	if (dw->saved || dw->error)
		return true;

	temp_name = ro_gui_download_temp_name(dw);

	/* does the user want to check for collisions when saving? */
	if (!force_overwrite) {
		/* check whether the destination file/dir already exists */
		error = xosfile_read_stamped(file_name, &obj_type,
				NULL, NULL, NULL, NULL, NULL);
		if (error) {
			LOG(("xosfile_read_stamped: 0x%x:%s", error->errnum, error->errmess));
			return false;
		}

		switch (obj_type) {
			case osfile_NOT_FOUND:
				break;

			case osfile_IS_FILE:
				dw->query = query_user("OverwriteFile", NULL, &overwrite_funcs, dw,
							messages_get("Replace"), messages_get("DontReplace"));
				dw->query_rsn = QueryRsn_Overwrite;
				return false;

			default:
				error = xosfile_make_error(file_name, obj_type);
				assert(error);
				warn_user("SaveError", error->errmess);
				return false;
		}
	}

	if (!ro_gui_download_check_space(dw, file_name, temp_name)) {
		warn_user("SaveError", messages_get("NoDiscSpace"));
		return false;
	}

	error = ro_gui_download_move(dw, file_name, temp_name);
	if (error) {
		warn_user("SaveError", error->errmess);

		/* try to reopen at old location so that the download can continue
		   to the temporary file */
		error = xosfind_openupw(osfind_NO_PATH | osfind_ERROR_IF_DIR,
				temp_name, 0, &dw->file);
		if (error) {
			LOG(("xosfind_openupw: 0x%x: %s",
					error->errnum, error->errmess));

		} else {
			error = xosargs_set_ptrw(dw->file, dw->received);
			if (error) {
				LOG(("xosargs_set_ptrw: 0x%x: %s",
						error->errnum, error->errmess));
			}
		}

		if (error) {
			if (dw->ctx)
				download_context_abort(dw->ctx);
			gui_download_window_error(dw, error->errmess);
		}
		return false;
	}

	dw->saved = true;
	strncpy(dw->path, file_name, sizeof dw->path);

	if (!dw->send_dataload || dw->save_message.data.data_xfer.est_size != -1)
		ro_gui_download_remember_dir(file_name);

	/* grey out file icon */
	error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_ICON,
			wimp_ICON_SHADED, wimp_ICON_SHADED);
	if (error) {
		LOG(("xwimp_set_icon_state: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
	}

	/* hide writeable path icon and show destination icon
	   Note: must redraw icon bounding box because the destination icon
		has rounded edges on RISC OS Select/Adjust and doesn't
		completely cover the writeable icon */

	ro_gui_force_redraw_icon(dw->window, ICON_DOWNLOAD_PATH);
	error = xwimp_set_icon_state(dw->window, ICON_DOWNLOAD_PATH,
			wimp_ICON_DELETED, wimp_ICON_DELETED);
	if (error) {
		LOG(("xwimp_set_icon_state: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
	}
	error = xwimp_set_icon_state(dw->window,
			ICON_DOWNLOAD_DESTINATION, wimp_ICON_DELETED, 0);
	if (error) {
		LOG(("xwimp_set_icon_state: 0x%x: %s",
				error->errnum, error->errmess));
		warn_user("WimpError", error->errmess);
	}

	ro_gui_download_window_hide_caret(dw);

	return true;
}
Exemplo n.º 17
0
/* Callback used to ask for the PIN which shall be written into BUF.
   The buf has been allocated by the caller and is of size MAXBUF
   which includes the terminating null.  The function should return an
   UTF-8 string with the passphrase/PIN, the buffer may optionally be
   padded with arbitrary characters.

   INFO gets displayed as part of a generic string.  However if the
   first character of INFO is a vertical bar all up to the next
   verical bar are considered flags and only everything after the
   second vertical bar gets displayed as the full prompt.

   We don't need/implement the N/A flags.  When they occur, we signal
   an error.  */
int 
getpin_cb (void *opaque, const char *info, char *buf, size_t maxbuf)
{
  struct getpin_cb_data *cb_data = opaque;
  poldi_ctx_t ctx = cb_data->poldi_ctx;
  char *info_frobbed;
  int err;

  info_frobbed = NULL;
  err = 0;

#if 0
  /* FIXME: why "< 2"? -mo */
  if (buf && maxbuf < 2)
    return gpg_error (GPG_ERR_INV_VALUE);
#endif

  /* Older SCDaemons simply send "PIN" as prompt. We do not process
     this prompt here but use a special case later. */
  if (info && (strcmp (info, "PIN") != 0))
    {
      if (info[0] == '|')
	{
	  if (info[1] == '|')
	    /* Skip "||" at the beginning.  */
	    info += 2;
	  else
	    {
	      /* Weird that we received flags - they are neither expected nor
		 implemented here.  */
	      log_msg_error (ctx->loghandle,
			     _("getpin_cb called with flags set in info string `%s'\n"),
			     info);
	      err = gpg_error (GPG_ERR_INV_VALUE); /* FIXME? */
	      goto out;
	    }
	}
      err = frob_info_msg (info, &info_frobbed);
      if (err)
	{
	  log_msg_error (ctx->loghandle,
			 _("frob_info_msg failed for info msg of size %u\n"),
			 (unsigned int) strlen (info));
	  goto out;
	}
    }

  if (buf)
    {
      /* BUF being non-zero means we are not using a keypad.  */

      if (info_frobbed)
	err = query_user (ctx, info_frobbed, buf, maxbuf);
      else
	/* Use string which is more user friendly. */
	err = query_user (ctx, _("Please enter the PIN:"), buf, maxbuf);
    }
  else
    {
      /* Special handling for keypad mode hack. */

      /* If BUF has been passed as NULL, we are in keypad mode: the
	 callback notifies the user and immediately returns.  */
      if (maxbuf == 0)
	{
	  /* Close the "pinentry". */
	  err = keypad_mode_leave (ctx);
	}
      else if (maxbuf == 1)
	{
	  /* Open the "pinentry". */
	  if (info_frobbed)
	    err = keypad_mode_enter (ctx, info_frobbed);
	  else
	    err = keypad_mode_enter (ctx, _("Please enter the PIN:"));
	}
      else
        err = gpg_error (GPG_ERR_INV_VALUE); /* FIXME: must signal
						internal error(!)?
						-mo */
    }

 out:

  xfree (info_frobbed);

  return err;
}