Beispiel #1
0
/*
 * create_db - execute an editor to allow the person to create the
 *         index definition file.

 * The rules for creating the name of the database file, and the provider
 * of the new name resides in the function newlabelFilename that resides in
 * newlabelFilename 
 */
void
create_db(void)
{
	int pid;

	char *editor;

	register int row;

	char *fname=NULL; 
    set_modes() ;
	/* Clear the screen and move to the top. */
	clear();
	move(0, 0);

	/* Print out the explanatory message.  */
	for (row = 0; message[row].m_line != NULL; row++)
		printw(message[row].m_line, message[row].m_arg);

	/* Give the user a chance to read it.  Wait till they
	 * type a carriage return before proceeding.  */
	prompt_char(++row, 0, "Type RETURN to continue: ", "\n\r");

	/* Use the editor the user prefers, or EDITOR if
	 * he doesn't have anything set.  */
	if ((editor = getenv("EDITOR")) == NULL)
		editor = EDITOR;
	/* get the label file name.  */
    fname = getFullLabelFileName() ;

	/* Go back to normal tty modes.  */
	reset_modes();

	/* Spawn a child process.  */
	if ((pid = fork()) < 0) {
        yerror(YFORK_PROC_ERR,"create_db",editor,YX_EXTERNAL_CAUSE ) ;
	}
	/* Execute the editor. */
	if (pid == 0) {
		reset_modes();
		execl(editor, editor, fname, NULL);
		perror(editor);
		exit(1);
	}
	/* Wait for the editor to finish.  */
	while (wait((int *)0) != pid) ;
    /* loose the reference to the filename */
    fname = NULL; 
	/* Set the tty modes up again.  */
	set_modes();
}
Beispiel #2
0
/**
Редактировать атрибуты шрифта.
*/
void font::menu_Parametr ( void )
{
	int rez  = 0;
	int above = 0;
	int below = 0;
	int modes = 0;

	QString  attribute;

	do
	{
		print();
//  edit_menu::s_menu_font_parametr->run();
//  rez = edit_menu::s_menu_font_parametr->get_run_rez();

		switch ( rez )
		{

			case 0: //Above
				std_out << "Above (n>=1) <" << get_above () << "> =";
				std_out.flush();
				std_in >> above ;
				set_above ( above );
				break;

			case 1: //Below
				std_out << "Below (n>=1) <" << get_below() << "> =";
				std_out.flush();
				std_in >> below;
				set_below ( below );
				break;

			case 2: //Modes
				std_out << "Modes (0|2) <" << get_modes() << "> =";
				std_out.flush();
				std_in >> modes;
				set_modes ( modes );
				break;

			case 3: //Attribute
				std_out << "Attribute <" << get_attribute() << "> =";
				std_out.flush();
				attribute = std_in.readLine();
//    std_in >> attribute;
				set_attribute ( attribute );
				break;

			case 4: //Exit
				break;

			default:
				rez = 4;
				break;
		}
	}

	while ( rez >= 0 && rez < 4 );
}
Beispiel #3
0
font::font ( void ) :
		m_forma_l_list ( 0 )
{
	m_comment	= QString("");
	m_forma_l_list = new QList<forma_l *>;

	set_above ( 10 );
	set_below ( 5 );
	set_modes ( 2 );

	++s_font_main_count;
}
Beispiel #4
0
bool filter::Move_to(int next_node){

	int motor_one_status, motor_two_status, motor_one_steps, motor_two_steps;
	int dir = 1;

	int steps_to=distance_to[current_node][next_node]; //

	if(steps_to <=0) // checks the direction
	{
		 dir = 0;
		 steps_to= -1*steps_to;
	}

	std::cout<<steps_to<<" " << distance_to[current_node][next_node]<< std::endl;
	int time_interval=10; // time interval between ticks  the motor 10 ms


	int reply; //used to call  methods from stepper_bee_interface

	reply = init_controller(); // turns the board
	reply = set_modes(1,1,1,1); // allows the board to report back to use

	reply = move_motor(1, dir, steps_to, time_interval, 0, 0, 0); // moves motor stepper_bee_interface just change the first int from a  1 to a 0


	int wait=0; //built in for the delay that will occur on the usb

	do{

		reply = get_motor_status(&motor_one_status, &motor_two_status, &motor_one_steps, &motor_two_steps) ;
		std::cout<<"MOTOR - steps left = "<< motor_two_steps<< " \n"; //CTM: change to motor_one_steps if using other motor
		j++;
	}while(motor_one_status == 1 || motor_two_status == 1|| wait<5); //this how we wait for the motor
	std::cout<<"DONE !! \n";
	current_node=next_node; // so the class knows where it is at 
	reply=close_controller();  //prevent bad signals being sent to the motor



	return true;


}
Beispiel #5
0
int main(void)
{

	char *myLocale = setlocale(LC_ALL, "");

	char *selectedDB = NULL;

	printf("Hello World\n");
	wchar_t svar[256];

	char *meld = "Test åg ær av vide chørs";

	set_modes();
	prompt_str(4, 5, meld, svar);
	reset_modes();

	/* Set tty modes.                                           */
	reset_modes();
	return 0;
}
Beispiel #6
0
static int set_keydefine_key(struct _select_def *conf, int key)
{
    int oldmode;

    switch (key) {
        case KEY_TAB:
            ask_define();
            return SHOW_DIRCHANGE;
        case 'a':                  /* add new user */
            if (keymem_total < MAX_KEY_DEFINE) {
                int i,j;
                struct key_struct k;
                char buf[120];

                clear();
                move(1, 0);
                prints("请键入自定义键: ");
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) return SHOW_DIRCHANGE;
                prints("%s\n", buf);
                k.key = i;
                move(2, 0);
                prints("请输入替换序列(最多10个),按一次ESC结束: ");
                j=0;
                do {
                    do {
                        i = igetkey();
                        get_key_name(i, buf);
                    } while (!buf[0]&&i!=KEY_ESC);
                    if (i==KEY_ESC) break;
                    prints("%s ", buf);
                    k.mapped[j] = i;
                    j++;
                    if (j>=10) break;
                } while (1);
                if (j<10) k.mapped[j]=0;
                if (j==0) return SHOW_DIRCHANGE;

                k.status[0] = -1;
                add_key(&k);

                return SHOW_DIRCHANGE;
            }
            break;
        case 'e':
            set_modes(keymem[conf->pos-1].status);
            return SHOW_DIRCHANGE;
        case 's': {
            int i,j,x,y;
            struct key_struct k;
            char buf[120];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1, 0);
            prints("请键入自定义键: ");
            do {
                i = igetkey();
                get_key_name(i, buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC) return SHOW_DIRCHANGE;
            prints("%s\n", buf);
            k.key = i;
            move(2, 0);
            prints("请输入替换序列(最多10个),按一次ESC结束: ");
            j=0;
            do {
                do {
                    i = igetkey();
                    get_key_name(i, buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC) break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j] = i;
                j++;
                if (j>=10) break;
            } while (1);
            if (j<10) k.mapped[j]=0;
            if (j==0) return SHOW_DIRCHANGE;

            memcpy(keymem+conf->pos-1, &k, sizeof(struct key_struct));

            return SHOW_DIRCHANGE;
        }
        break;
        case 'x': {
            struct key_struct k;
            int i;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请键入自定义键: ");
            do {
                i=igetkey();
                get_key_name(i,buf);
            } while (!buf[0]&&i!=KEY_ESC);
            if (i==KEY_ESC)
                return SHOW_DIRCHANGE;
            k.key=i;
            prints("%s",buf);
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 't': {
            struct key_struct k;
            int i,j,x,y;
            char buf[128];
            memmove(&k,keymem+conf->pos-1,sizeof(struct key_struct));
            clear();
            move(1,0);
            prints("请输入替换序列(最多10个), 按一次ESC结束: ");
            for (j=0; j<10; j++) {
                do {
                    i=igetkey();
                    get_key_name(i,buf);
                } while (!buf[0]&&i!=KEY_ESC);
                if (i==KEY_ESC)
                    break;
                getyx(&y,&x);
                prints((x+strlen(buf)<t_columns-1)?"%s ":"\n%s ",buf);
                k.mapped[j]=i;
            }
            if (!j)
                return SHOW_DIRCHANGE;
            if (j<10)
                k.mapped[j]=0;
            memmove(keymem+conf->pos-1,&k,sizeof(struct key_struct));
            prints("\n\n\033[1;33m%s\033[0;33m<Enter>\033[m","已更新!");
            WAIT_RETURN;
            return SHOW_DIRCHANGE;
        }
        break;
        case 'd':                  /* delete existed user */
            if (keymem_total > 0) {
                char ans[3];

                getdata(t_lines - 1, 0, "确实要删除该定义键吗(Y/N)? [N]: ", ans, sizeof(ans), DOECHO, NULL, true);
                if (ans[0] == 'Y' || ans[0] == 'y') {
                    remove_key(conf->pos-1);
                    if (keymem_total==0) {
                        struct key_struct key;
                        key.key = 'A';
                        key.mapped[0] = 'A';
                        key.mapped[1] = 0;
                        key.status[0] = 0;
                        add_key(&key);
                    }
                }
                return SHOW_DIRCHANGE;
            }
            break;
        case 'L':
        case 'l':
            oldmode = uinfo.mode;
            show_allmsgs();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'W':
        case 'w':
            oldmode = uinfo.mode;
            if (!HAS_PERM(getCurrentUser(), PERM_PAGE))
                break;
            s_msg();
            modify_user_mode(oldmode);
            return SHOW_REFRESH;
        case 'u':
            oldmode = uinfo.mode;
            clear();
            modify_user_mode(QUERY);
            t_query(NULL);
            modify_user_mode(oldmode);
            clear();
            return SHOW_REFRESH;
    }

    return SHOW_CONTINUE;
}
Beispiel #7
0
void saldl(saldl_params *params_ptr) {
  /* Definitions */
  info_s info = DEF_INFO_S;
  info.params = params_ptr;

  /* Handle signals */
  info_global = &info;
  saldl_handle_signals();

  /* Need to be set as early as possible */
  set_color(&params_ptr->no_color);
  set_verbosity(&params_ptr->verbosity, &params_ptr->libcurl_verbosity);

  /* Check if loaded libcurl is recent enough */
  info.curl_info = curl_version_info(CURLVERSION_NOW);
  check_libcurl(info.curl_info);

  /* Library initializations, should run only once */
  SALDL_ASSERT(!curl_global_init(CURL_GLOBAL_ALL));
  SALDL_ASSERT(!evthread_use_pthreads());

  /* get/set initial info */
  main_msg("URL", "%s", params_ptr->start_url);
  check_url(params_ptr->start_url);
  get_info(&info);
  set_info(&info);
  check_remote_file_size(&info);

  /* initialize chunks early for extra_resume() */
  chunks_init(&info);

  if (params_ptr->resume) {
    check_resume(&info);
  }

  print_chunk_info(&info);
  global_progress_init(&info);

  /* exit here if dry_run was set */
  if ( params_ptr->dry_run  ) {
    saldl_free_all(&info);
    finish_msg_and_exit("Dry-run done.");
  }

  check_files_and_dirs(&info);

  /* Check if download was interrupted after all data was merged */
  if (info.already_finished) {
    goto saldl_all_data_merged;
  }

  /* threads, needed by set_modes() */
  info.threads = saldl_calloc(params_ptr->num_connections, sizeof(thread_s));
  set_modes(&info);

  /* 1st iteration */
  for (size_t counter = 0; counter < params_ptr->num_connections; counter++) {
    queue_next_chunk(&info, counter, 1);
  }

  /* Create event pthreads */
  saldl_pthread_create(&info.trigger_events_pth, NULL, events_trigger_thread, &info);

  if (!params_ptr->read_only && !params_ptr->to_stdout) {
    saldl_pthread_create(&info.sync_ctrl_pth, NULL, sync_ctrl, &info);
  }

  if (info.chunk_count != 1) {
    saldl_pthread_create(&info.status_display_pth, NULL, status_display, &info);
    saldl_pthread_create(&info.queue_next_pth, NULL, queue_next_thread, &info);
    saldl_pthread_create(&info.merger_pth, NULL, merger_thread, &info);
  }

  /* Now that everything is initialized */
  info.session_status = SESSION_IN_PROGRESS;

  /* Avoid race in joining event threads if the session was interrupted, or finishing without downloading if single_mode */
  do {
    usleep(100000);
  } while (params_ptr->single_mode ? info.chunks[0].progress != PRG_FINISHED : info.global_progress.complete_size != info.file_size);

  /* Join event pthreads */
  if (!params_ptr->read_only && !params_ptr->to_stdout) {
    join_event_pth(&info.ev_ctrl ,&info.sync_ctrl_pth);
  }

  if (info.chunk_count !=1) {
    join_event_pth(&info.ev_status, &info.status_display_pth);
    join_event_pth(&info.ev_queue, &info.queue_next_pth);
    join_event_pth(&info.ev_merge, &info.merger_pth);
  }

  info.events_queue_done = true;
  event_queue(&info.ev_trigger, NULL);
  join_event_pth(&info.ev_trigger ,&info.trigger_events_pth);

saldl_all_data_merged:

  /* Remove tmp_dirname */
  if (!params_ptr->read_only && !params_ptr->mem_bufs && !params_ptr->single_mode) {
    if ( rmdir(info.tmp_dirname) ) {
      err_msg(FN, "Failed to delete %s: %s", info.tmp_dirname, strerror(errno) );
    }
  }

  /*** Final Steps ***/

  /* One last check  */
  if (info.file_size && !params_ptr->no_remote_info &&
      !params_ptr->read_only && !params_ptr->to_stdout &&
      (!info.remote_info.content_encoded || params_ptr->no_decompress)) {
    off_t saved_file_size = saldl_fsizeo(info.part_filename, info.file);
    if (saved_file_size != info.file_size) {
      pre_fatal(FN, "Unexpected saved file size (%"SAL_JU"!=%"SAL_JU").", saved_file_size, info.file_size);
      pre_fatal(FN, "This could happen if you're downloading from a dynamic site.");
      pre_fatal(FN, "If that's the case and the download is small, retry with --no-remote-info");
      fatal(FN, "If you think that's a bug in saldl, report it: https://github.com/saldl/saldl/issues");
    }
  }
  else {
    debug_msg(FN, "Strict check for finished file size skipped.");
  }

  if (!params_ptr->read_only && !params_ptr->to_stdout) {
    saldl_fclose(info.part_filename, info.file);
    if (rename(info.part_filename, params_ptr->filename) ) {
      err_msg(FN, "Failed to rename now-complete %s to %s: %s", info.part_filename, params_ptr->filename, strerror(errno));
    }

    saldl_fclose(info.ctrl_filename, info.ctrl_file);
    if ( remove(info.ctrl_filename) ) {
      err_msg(FN, "Failed to remove %s: %s", info.ctrl_filename, strerror(errno));
    }
  }

  /* cleanups */
  curl_cleanup(&info);
  saldl_free_all(&info);

  finish_msg_and_exit("Download Finished.");
}