示例#1
0
文件: pager.c 项目: FredrIQ/nethack4
int
dolicense(const struct nh_cmd_arg *arg)
{
    (void) arg;
    display_file(LICENSE, TRUE);
    return 0;
}
示例#2
0
文件: pager.c 项目: FredrIQ/nethack4
int
doverhistory(const struct nh_cmd_arg *arg)
{
    (void) arg;
    display_file(HISTORY, TRUE);
    return 0;
}
示例#3
0
void	do_ls_dir2(t_opt arg, t_elem *dirlist, int multidir)
{
	DIR		*dir;
	t_elem	*files;
	int		first;

	first = 0;
	files = NULL;
	while (dirlist)
	{
		dir = opendir(dirlist->name);
		while (elemget(&files, readdir(dir), \
			ft_strjoin(dirlist->path, "/"), arg) != 0)
			;
		closedir(dir);
		if (files)
		{
			first == 1 ? ft_putchar('\n') : NULL;
			multidir ? ft_putendl(ft_strjoin(dirlist->name, ":")) : NULL;
			first = 1;
			display_file(arg, files, 1);
		}
		files = NULL;
		dirlist = dirlist->next;
	}
}
示例#4
0
/** display directory content **/
void display_dir(const char* dirname, char buf[])
{
    DIR* dir;
    struct dirent* mydirent;
    char tmp_buf[BUF_SIZE];

    if ((dir = opendir(dirname)) == NULL)
    {
        strcat(buf, "ls: ");
        strcat(buf, sys_errlist[errno]);
        strcat(buf, "\n");
        return;
    }

    while ((mydirent = readdir((dir))) != NULL)
    {
        /** hide . and .. directory **/
        if (strcmp(mydirent->d_name, ".") == 0 || strcmp(mydirent->d_name, "..") == 0)
            continue;

        sprintf(tmp_buf, "%s/%s", dirname, mydirent->d_name);
        display_file(tmp_buf, mydirent->d_name, buf);
    }

    closedir(dir);
}
示例#5
0
void			ls_one(char *file, char *option)
{
	DIR			*dir;
	t_dirent	*folder;
	char		**tab;
	int			folder_len;
	int			j;

	j = 0;
	folder = NULL;
	if ((folder_len = count_nb_file(file)) == -1)
		display_eacces(file);
	else
	{
		(!(dir = opendir(file))) ? perror_opendir() : 0;
		if (!(tab = (char**)malloc(sizeof(*tab) * (folder_len + 1))))
			perror_malloc();
		while ((folder = readdir(dir)))
			tab[j++] = ft_strjoin_path(file, folder->d_name);
		tab[j] = NULL;
		(closedir(dir) == -1) ? perror_closedir() : 0;
		(IS_T && !(IS_F)) ? mod_time_sort(tab) : 0;
		(!(IS_F) && !(IS_T)) ? ascii_sort(tab) : 0;
		(IS_R_2 && !(IS_F)) ? rev_sort(tab) : 0;
		display_file(tab, option);
		free_string_array(&tab);
	}
}
示例#6
0
文件: main.c 项目: DBarthe/Elfparse
int			main(int ac, char **av)
{
  int			idx;
  int			ret;

  ret = 0;
  idx = 1;
  if (ac == 1)
    ret = display_file("a.out");
  else
    while (idx < ac)
      {
	ret |= display_file(av[idx]);
	idx++;
      }
  return (ret);
}
示例#7
0
/* Display action */
static int
display (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
{
  if (!wh->msg)
    mu_error (_("no alternate message to display"));
  else
    display_file (wh->msg);
  return 0;
}
示例#8
0
/* List action */
static int
list (struct mh_whatnow_env *wh, int argc, char **argv, int *status)
{
  if (!wh->file)
    mu_error (_("no draft file to display"));
  else
    display_file (wh->file);
  return 0;
}
示例#9
0
  void	connectAll() {
    CaptureHandler::connect(filters_window, SIGNAL(refresh()),
			    this, SLOT(displayPacketList()));
    CaptureHandler::connect(filters, SIGNAL(clicked()), this, SLOT(exec()));
    CaptureHandler::connect(open, SIGNAL(clicked()), this, SLOT(display_file()));
    CaptureHandler::connect(start, SIGNAL(clicked()), this, SLOT(start_capture()));
    CaptureHandler::connect(stop, SIGNAL(clicked()), this, SLOT(stop_capture()));
    CaptureHandler::connect(modify, SIGNAL(clicked()),
			    forge, SLOT(setPacketToModify()));
  }
示例#10
0
文件: allmain.c 项目: saihack/NetHack
void
newgame()
{

	fobj = invent = level.buriedobjlist = migrating_objs = (struct obj *)0;
	fmon = migrating_mons = (struct monst *)0;
	ftrap = 0;
	flags.ident = 1;

	if(wiz1_level.dlevel == 0) init_dungeons();
	init_objects();		/* must be before u_init() */
	u_init();
	init_artifacts();	/* must be after u_init() */

#ifndef NO_SIGNAL
	(void) signal(SIGINT, (SIG_RET_TYPE) done1);
#endif
#ifdef NEWS
	if(flags.news) display_file(NEWS, FALSE);
#endif
#ifdef MULDGN
	load_qtlist();	/* load up the quest text info */
	quest_init();
	if(flags.legacy && moves == 1) com_pager(1);
#endif
	mklev();
	u_on_upstairs();
	check_special_room(FALSE);
	vision_reset();		/* set up internals for level (after mklev) */

	flags.botlx = 1;

	/* Move the monster from under you or else
	 * makedog() will fail when it calls makemon().
	 * 			- ucsfcgl!kneller
	 */
	if(MON_AT(u.ux, u.uy)) mnexto(m_at(u.ux, u.uy));

#ifdef CLIPPING
	cliparound(u.ux, u.uy);
#endif
	(void) makedog();
	docrt();

#ifdef INSURANCE
	save_currentstate();
#endif
	return;
}
示例#11
0
void	do_ls_file(t_opt arg, t_list *path)
{
	t_list	*cur;
	t_elem	*files;

	cur = path;
	files = NULL;
	arg.a = 1;
	while (cur)
	{
		elemgetfiles(&files, cur->content, "", arg);
		cur = cur->next;
	}
	if (files)
		display_file(arg, files, 0);
}
示例#12
0
int judge_file_type(char *path_name)
{
	struct file *fp = NULL;

	/*判断是否为目录*/	
	fp = filp_open(path_name, O_DIRECTORY, 0);
	if (IS_ERR(fp)) {
		/*判断是否为文件*/
		fp = filp_open(path_name, O_RDONLY, 0644);
		if (IS_ERR(fp)) {
			printk("%s is not a file or a directory\n", path_name);
			return -1;
		}
		display_file(fp);
		filp_close(fp, NULL);
	} else {
		display_dir(fp);
		filp_close(fp, NULL);
	}
	
	return 0;
}
示例#13
0
void	do_recursion(t_opt arg, char *path)
{
	t_elem	*files;
	DIR		*dir;

	files = NULL;
	ft_putchar('\n');
	ft_putstr(path);
	ft_putstr(":\n");
	if ((dir = opendir(path)) != NULL)
	{
		while (elemget(&files, readdir(dir), \
					ft_strjoin(path, "/"), arg) != 0)
			;
		closedir(dir);
		if (files)
			display_file(arg, files, 1);
		files = NULL;
	}
	else
		basicerror("ft_ls: ", path, 0);
}
示例#14
0
int more_string(mixed str) {

  last_search = "";
 
  if (!pointerp(str)) 
    the_bit = explode(str,"\n");
  fsize = sizeof(the_bit);
  if (fsize == 0) {
    notify_fail("Empty String.\n");
    return 0;
  }
  topl = 0;
  if (fsize < ROWS)
    botl = fsize;
  else
    botl = ROWS;
  display_file();
  if (fsize >= ROWS) {
    more_status_line();
    input_to("next_page");
  }
  return 1;
}
示例#15
0
LRESULT
onWMCommand(HWND hWnd, WPARAM wParam, LPARAM lParam)
{
    int wmId, wmEvent;
    PNHMainWindow data;

    data = (PNHMainWindow) GetWindowLong(hWnd, GWL_USERDATA);
    wmId = LOWORD(wParam);
    wmEvent = HIWORD(wParam);

    // process the menu selections:
    switch (wmId) {
    case IDM_ABOUT:
        DialogBox(GetNHApp()->hApp, (LPCTSTR) IDD_ABOUTBOX, hWnd,
                  (DLGPROC) About);
        break;

    case IDM_EXIT:
        done2();
        break;

    case IDM_SAVE:
        dosave();
        break;

    case IDM_MAP_TILES:
    case IDM_MAP_ASCII4X6:
    case IDM_MAP_ASCII6X8:
    case IDM_MAP_ASCII8X8:
    case IDM_MAP_ASCII16X8:
    case IDM_MAP_ASCII7X12:
    case IDM_MAP_ASCII8X12:
    case IDM_MAP_ASCII12X16:
    case IDM_MAP_ASCII16X12:
    case IDM_MAP_ASCII10X18:
        mswin_select_map_mode(menuid2mapmode(wmId));
        break;

    case IDM_MAP_FIT_TO_SCREEN:
        if (IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) {
            mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode)
                                      ? data->mapAcsiiModeSave
                                      : MAP_MODE_TILES);
        } else {
            mswin_select_map_mode(IS_MAP_ASCII(iflags.wc_map_mode)
                                      ? MAP_MODE_ASCII_FIT_TO_SCREEN
                                      : MAP_MODE_TILES_FIT_TO_SCREEN);
        }
        break;

    case IDM_VIEW_KEYPAD:
        GetNHApp()->bCmdPad = !GetNHApp()->bCmdPad;
        CheckMenuItem(
            _get_main_menu(ID_VIEW), IDM_VIEW_KEYPAD,
            MF_BYCOMMAND | (GetNHApp()->bCmdPad ? MF_CHECKED : MF_UNCHECKED));
        mswin_layout_main_window(GetNHApp()->hCmdWnd);
        break;

    case IDM_VIEW_OPTIONS:
        doset();
        break;

    case IDM_DIRECT_COMMAND: /* SmartPhone: display dialog to type in arbitary
                                command text */
        mswin_direct_command();
        break;

    case IDM_HELP_LONG:
        display_file(HELP, TRUE);
        break;

    case IDM_HELP_COMMANDS:
        display_file(SHELP, TRUE);
        break;

    case IDM_HELP_HISTORY:
        (void) dohistory();
        break;

    case IDM_HELP_INFO_CHAR:
        (void) dowhatis();
        break;

    case IDM_HELP_INFO_KEY:
        (void) dowhatdoes();
        break;

    case IDM_HELP_OPTIONS:
        option_help();
        break;

    case IDM_HELP_OPTIONS_LONG:
        display_file(OPTIONFILE, TRUE);
        break;

    case IDM_HELP_EXTCMD:
        (void) doextlist();
        break;

    case IDM_HELP_LICENSE:
        display_file(LICENSE, TRUE);
        break;

    case IDM_HELP_MENU:
        dohelp();
        break;

    default:
        return 1;
    }
    return 0;
}
示例#16
0
int
main (int argc, char *argv[], char **envp)
{
  int index;

  set_program_name (argv[0]);

#ifdef HAVE_TZSET
  tzset ();			/* In case no timezone database in ~ftp.  */
#endif

#ifdef HAVE_INITSETPROCTITLE
  /* Save start and extent of argv for setproctitle.  */
  initsetproctitle (argc, argv, envp);
#endif /* HAVE_INITSETPROCTITLE */

  /* Parse the command line */
  iu_argp_init ("ftpd", default_program_authors);
  argp_parse (&argp, argc, argv, 0, &index, NULL);
  
  /* Bail out, wrong usage */
  argc -= index;
  if (argc != 0)
    error (1, 0, "surplus arguments; try `%s --help' for more info",
	   program_name);

  /* LOG_NDELAY sets up the logging connection immediately,
     necessary for anonymous ftp's that chroot and can't do it later.  */
  openlog ("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
  freopen (PATH_DEVNULL, "w", stderr);

  /* If not running via inetd, we detach and dup(fd, 0), dup(fd, 1) the
     fd = accept(). tcpd is check if compile with the support  */
  if (daemon_mode)
    {
      if (server_mode (pid_file, &his_addr) < 0)
	exit (1);
    }
  else
    {
      socklen_t addrlen = sizeof (his_addr);
      if (getpeername (STDIN_FILENO, (struct sockaddr *) &his_addr,
		       &addrlen) < 0)
	{
	  syslog (LOG_ERR, "getpeername (%s): %m", program_name);
	  exit (1);
	}
    }

  signal (SIGHUP, sigquit);
  signal (SIGINT, sigquit);
  signal (SIGQUIT, sigquit);
  signal (SIGTERM, sigquit);
  signal (SIGPIPE, lostconn);
  signal (SIGCHLD, SIG_IGN);
  if (signal (SIGURG, myoob) == SIG_ERR)
    syslog (LOG_ERR, "signal: %m");

  /* Get info on the ctrl connection.  */
  {
    socklen_t addrlen = sizeof (ctrl_addr);
    if (getsockname (STDIN_FILENO, (struct sockaddr *) &ctrl_addr,
		     &addrlen) < 0)
      {
	syslog (LOG_ERR, "getsockname (%s): %m", program_name);
	exit (1);
      }
  }

#if defined (IP_TOS) && defined (IPTOS_LOWDELAY) && defined (IPPROTO_IP)
  /* To  minimize delays for interactive traffic.  */
  {
    int tos = IPTOS_LOWDELAY;
    if (setsockopt (STDIN_FILENO, IPPROTO_IP, IP_TOS,
		    (char *) &tos, sizeof (int)) < 0)
      syslog (LOG_WARNING, "setsockopt (IP_TOS): %m");
  }
#endif

#ifdef SO_OOBINLINE
  /* Try to handle urgent data inline.  */
  {
    int on = 1;
    if (setsockopt (STDIN_FILENO, SOL_SOCKET, SO_OOBINLINE,
		    (char *) &on, sizeof (on)) < 0)
      syslog (LOG_ERR, "setsockopt: %m");
  }
#endif

#ifdef SO_KEEPALIVE
  /* Set keepalives on the socket to detect dropped connections.  */
  {
    int keepalive = 1;
    if (setsockopt (STDIN_FILENO, SOL_SOCKET, SO_KEEPALIVE,
		    (char *) &keepalive, sizeof (keepalive)) < 0)
      syslog (LOG_WARNING, "setsockopt (SO_KEEPALIVE): %m");
  }
#endif

#ifdef	F_SETOWN
  if (fcntl (STDIN_FILENO, F_SETOWN, getpid ()) == -1)
    syslog (LOG_ERR, "fcntl F_SETOWN: %m");
#endif

  dolog (&his_addr, &cred);

  /* Deal with login disable.  */
  if (display_file (PATH_NOLOGIN, 530) == 0)
    {
      reply (530, "System not available.");
      exit (0);
    }

  /* Display a Welcome message if exists,
     N.B. reply(220,) must follow.  */
  display_file (PATH_FTPWELCOME, 220);

  hostname = localhost ();
  if (!hostname)
    perror_reply (550, "Local resource failure: malloc");

  /* Tell them we're ready to roll.  */
  if (!no_version)
    reply (220, "%s FTP server (%s %s) ready.",
	   hostname, PACKAGE_NAME, PACKAGE_VERSION);
  else
    reply (220, "%s FTP server ready.", hostname);

  /* Set the jump, if we have an error parsing,
     come here and start fresh.  */
  setjmp (errcatch);

  /* Roll.  */
  for (;;)
    yyparse ();
}
示例#17
0
static void
complete_login (struct credentials *pcred)
{
  if (setegid ((gid_t) pcred->gid) < 0)
    {
      reply (550, "Can't set gid.");
      return;
    }

#ifdef HAVE_INITGROUPS
  initgroups (pcred->name, pcred->gid);
#endif

  /* open wtmp before chroot */
  snprintf (ttyline, sizeof (ttyline), "ftp%d", getpid ());
  logwtmp_keep_open (ttyline, pcred->name, pcred->remotehost);

  if (pcred->guest)
    {
      /* We MUST do a chdir () after the chroot. Otherwise
         the old current directory will be accessible as "."
         outside the new root!  */
      if (chroot (pcred->rootdir) < 0 || chdir (pcred->homedir) < 0)
	{
	  reply (550, "Can't set guest privileges.");
	  goto bad;
	}
    }
  else if (pcred->dochroot)
    {
      if (chroot (pcred->rootdir) < 0 || chdir (pcred->homedir) < 0)
	{
	  reply (550, "Can't change root.");
	  goto bad;
	}
      setenv ("HOME", pcred->homedir, 1);
    }
  else if (chdir (pcred->rootdir) < 0)
    {
      if (chdir ("/") < 0)
	{
	  reply (530, "User %s: can't change directory to %s.",
		 pcred->name, pcred->homedir);
	  goto bad;
	}
      else
	lreply (230, "No directory! Logging in with home=/");
    }

  if (seteuid ((uid_t) pcred->uid) < 0)
    {
      reply (550, "Can't set uid.");
      goto bad;
    }

  /* Display a login message, if it exists.
     N.B. reply(230,) must follow the message.  */
  display_file (PATH_FTPLOGINMESG, 230);

  if (pcred->guest)
    {
      reply (230, "Guest login ok, access restrictions apply.");
#ifdef HAVE_SETPROCTITLE
      snprintf (proctitle, sizeof (proctitle), "%s: anonymous",
		pcred->remotehost);
      setproctitle ("%s", proctitle);
#endif /* HAVE_SETPROCTITLE */
      if (logging)
	syslog (LOG_INFO, "ANONYMOUS FTP LOGIN FROM %s", pcred->remotehost);
    }
  else
    {
      reply (230, "User %s logged in.", pcred->name);
#ifdef HAVE_SETPROCTITLE
      snprintf (proctitle, sizeof (proctitle),
		"%s: %s", pcred->remotehost, pcred->name);
      setproctitle ("%s", proctitle);
#endif /* HAVE_SETPROCTITLE */
      if (logging)
	syslog (LOG_INFO, "FTP LOGIN FROM %s as %s",
		pcred->remotehost, pcred->name);
    }
  umask (defumask);
  return;
bad:
  /* Forget all about it... */
  end_login (pcred);
}
示例#18
0
void
newgame()
{
	int i;

#ifdef MFLOPPY
	gameDiskPrompt();
#endif

	flags.ident = 1;

	for (i = 0; i < NUMMONS; i++)
		mvitals[i].mvflags = mons[i].geno & G_NOCORPSE;

	init_objects();		/* must be before u_init() */

	flags.pantheon = -1;	/* role_init() will reset this */
	role_init();		/* must be before init_dungeons(), u_init(),
				 * and init_artifacts() */

	init_dungeons();	/* must be before u_init() to avoid rndmonst()
				 * creating odd monsters for any tins and eggs
				 * in hero's initial inventory */
	init_artifacts();	/* before u_init() in case $WIZKIT specifies
				 * any artifacts */
	u_init();

#ifndef NO_SIGNAL
	(void) signal(SIGINT, (SIG_RET_TYPE) done1);
#endif
#ifdef NEWS
	if(iflags.news) display_file(NEWS, FALSE);
#endif
	load_qtlist();	/* load up the quest text info */
/*	quest_init();*/	/* Now part of role_init() */

	mklev();
	u_on_upstairs();
	vision_reset();		/* set up internals for level (after mklev) */
	check_special_room(FALSE);

	flags.botlx = 1;

	/* Move the monster from under you or else
	 * makedog() will fail when it calls makemon().
	 *			- ucsfcgl!kneller
	 */
	if(MON_AT(u.ux, u.uy)) mnexto(m_at(u.ux, u.uy));
	(void) makedog();
	docrt();

	if (flags.legacy) {
		flush_screen(1);
		com_pager(1);
	}

#ifdef INSURANCE
	save_currentstate();
#endif
	program_state.something_worth_saving++;	/* useful data now exists */

#if defined(RECORD_REALTIME) || defined(REALTIME_ON_BOTL)

        /* Start the timer here */
        realtime_data.realtime = (time_t)0L;

#if defined(BSD) && !defined(POSIX_TYPES)
        (void) time((long *)&realtime_data.restoretime);
#else
        (void) time(&realtime_data.restoretime);
#endif

#endif /* RECORD_REALTIME || REALTIME_ON_BOTL */

	/* Success! */
	welcome(TRUE);
	return;
}
示例#19
0
int main(int argc, char *argv[])
{
    // TEST
    //test_linked_list();

    if(argc != 2) {
        printf("Please give file name!");
        return 0;
    }

    FILE *file = fopen(argv[1], "r");
    if(NULL == file) {
        fprintf(stderr, "Can't open %s for reading!", argv[1]);
        return 0;
    }

    // General list to be used while reading file
    struct linked_list *list = NULL;
    char fname[65];
    char fowner[33];
    int fsize;
    struct file f;
    struct node *node;

    // One line from commands file
    char *line;

    // One of the operations (0 -10)
    int op;

    // Rest of line
    char rline[256];

    while((line = read_line(file)) != NULL) {
        sscanf(line, "%d %255[^\n]", &op, rline);

        switch(op) {
            case 0:
                if(list == NULL) {
                    fprintf(stderr, "There is no list to delete!");
                } else {
                    delete_list(list);
                }
                break;
            case 1:
                list = new_list();
                break;
            case 2:
                display_list(list);
                break;
            case 3:
                printf("List empty: %d\n", list_empty(list));
                break;
            case 4:
                printf("List size: %d\n", list_size(list));
                break;
            case 5:
                sscanf(rline, "%s %s %d", fname, fowner, &fsize);

                strncpy(f.fname, fname, 65);
                strncpy(f.owner, fowner, 33);
                f.size = fsize;

                node = new_node(f);

                push_front(node, list);
                break;
            case 6:
                sscanf(rline, "%s %s %d", fname, fowner, &fsize);

                strncpy(f.fname, fname, 65);
                strncpy(f.owner, fowner, 33);
                f.size = fsize;

                node = new_node(f);

                push_back(node, list);
                break;
            case 7:
                pop_front(list);
                break;
            case 8:
                pop_back(list);
                break;
            case 9:
                node = front(list);
                printf("Front: ");
                display_file(node->data);
                break;
            case 10:
                node = back(list);
                printf("Back: ");
                display_file(node->data);
                break;
            default:
                break;
        }
    }

    return 0;
}
示例#20
0
gboolean
activate_file (GFile* file, const char* content_type,
               gboolean is_executable, GFile* _file_arg)
{
    char* file_name = g_file_get_basename (file);
    gboolean is_bin = g_str_has_suffix(file_name, ".bin");
    gboolean result = TRUE;

    g_debug ("activate_file: %s", file_name);
    g_free (file_name);
    g_debug ("content_type: %s", content_type);

    if (is_executable &&
        (g_content_type_can_be_executable (content_type) || is_bin))
    {
        g_debug("is_executable && g_content_type_can_be_executable || is_bin");
        //1. an executable text file. or an shell script
        if (g_content_type_is_a (content_type, "text/plain"))
        {
            g_debug("g_content_type_is_a");
            GtkWidget* dialog;
            int response;
            char* file_name;
            char* prompt;
            char* detail;

            file_name = g_file_get_basename (file);
            prompt = g_strdup_printf (_("Do you want to run \"%s\", or display its contents?"), file_name);
            detail = g_strdup_printf (_("\"%s\" is an executable text file."), file_name);
            g_free (file_name);
            //create prompt dialog
            dialog = gtk_message_dialog_new (NULL,
                                             GTK_DIALOG_MODAL,
                                             GTK_MESSAGE_QUESTION,
                                             GTK_BUTTONS_NONE,
                                             NULL);
            g_object_set (dialog, "text", prompt, "secondary-text", detail, NULL);
            g_free (prompt);
            g_free (detail);
            gtk_dialog_add_button (GTK_DIALOG(dialog), _("Run in _Terminal"), RESPONSE_RUN_IN_TERMINAL);
            gtk_dialog_add_button (GTK_DIALOG(dialog), _("_Display"), RESPONSE_DISPLAY);
            gtk_dialog_add_button (GTK_DIALOG(dialog), "_Cancel", GTK_RESPONSE_CANCEL);
            gtk_dialog_add_button (GTK_DIALOG(dialog), _("_Run"), RESPONSE_RUN);
            gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);

            gtk_widget_show (GTK_WIDGET (dialog));

            response = gtk_dialog_run (GTK_DIALOG(dialog));
            gtk_widget_destroy (GTK_WIDGET (dialog));

            g_message("response:%d",response);
            switch (response)
            {
            case RESPONSE_RUN_IN_TERMINAL:
                run_file_in_terminal (file);
                break;
            case RESPONSE_DISPLAY:
                result = display_file (file, content_type);
                break;
            case RESPONSE_RUN:
                run_file (file, NULL);
                break;
            case GTK_RESPONSE_CANCEL:
                break;
            default:
                break;
            }
        }
        //2. an executable binary file
        else
        {
            g_debug("run_file");
            run_file (file, _file_arg);
        }
    }
    //for non-executables just open it.
    else
    {
        g_debug("for non-executables just open it.");
        result = display_file (file, content_type);
    }

    return result;
}
示例#21
0
void next_page(string str) {
  int num,
      noargs,
      i,j,k,
      redraw;
  string s1, s2, *s3, s4, s5;

  if (!str)
    str = "";

  if (sscanf(str,"%d%s", num, str)!=2)
    noargs = 1;
  s1 = extract(str,1);
  str = extract(str,0,1);
/* case statements WEEEEEE */
  switch(str) {
  case "q" :
	     if (finish_func)
               call_other(this_object(),finish_func);
             return;
  case "" :
  case "f" :
/* go on a number of pages... */
    topl += ROWS-2;
    redraw = 1;
   break;
  case "/" :
/* sigh */
    i = topl+4;
    if (s1=="")
      s1 = last_search;
    for (i=topl+4;i<fsize;i++)
      if (sscanf(the_bit[k],"%s"+s1+"%s",s4,s5)==2)
        if (num--<=0)
          break;
    if (i==fsize)
      write("Sorry "+s1+" not found.\n");
    else
      topl = i-3;
    redraw = 1;
    break;
  case "?" :
    for (i=topl+2;i>0;i--)
      if (sscanf(the_bit[k],"%s"+s1+"%s",s4,s5)==2)
        if (num--<=0)
          break;
    if (i==fsize)
      write("Sorry "+s1+" not found.\n");
    else
      topl = i-3;
    redraw = 1;
    break;
  case "b" :
    if (topl>0) {
      topl -= ROWS-2;
      redraw = 1;
      if (topl<0)
        topl = 0;
    }
    break;
  case "g" :
    topl = num;
    if (topl>=fsize)
      topl = fsize-2;
    redraw = 1;
    break;
  case "G" :
    redraw = 1;
    if (noargs)
      topl = fsize - ROWS;
    else
      topl = num;
      if (topl>fsize)
        topl = fsize-2;
    break;
  }
  if (redraw)
    display_file();
  if (topl<fsize) {
    more_status_line();
    input_to("next_page");
  } else
    if (finish_func)
      call_other(this_object(),finish_func);
}
示例#22
0
文件: pager.c 项目: DanielT/NitroHack
int doverhistory(void)
{
	display_file(HISTORY, TRUE);
	return 0;
}
示例#23
0
文件: pager.c 项目: DanielT/NitroHack
int dolicense(void)
{
	display_file(LICENSE, TRUE);
	return 0;
}
示例#24
0
/* 
*	根据命令行参数和完整路径名显示目标文件	
*	参数 flag: 命令行参数
*       参数 pathname : 包含了文件名的路径名
*/
void display(int flag, char *pathname)
{
	int i, j;
	struct stat buf;
	char name[1000];
	
	/*从路径中解析出文件名*/
	for(i=0,j=0; i<strlen(pathname); i++)
	{
		if(pathname[i] == '/')
		{
			j = 0;
			continue;
		}
		name[j++] = pathname[i];
	}
	name[j] = '\0';
	
	if (lstat(pathname, &buf) == -1)
	{
		my_err("stat", __LINE__);
	}
	
	switch (flag)
	{
	case PARAM_NONE:                            //没有-a 和-l选项
		if (name[0] != '.')
		{
			display_single(name);
		}
		break;
	
	case PARAM_A:                               //-a 选项
			display_single(name);
			break;

	case PARAM_L:                               //-l 选项
		if (name[0] != '.')
		{
			display_file(buf, name);
		}	
		break;

	case PARAM_A + PARAM_L:                     //-a和-l 选项
			display_file(buf, name);
			break;
	
	case PARAM_I:				   //-i选项
		if (name[0] != '.')
		{
			display_sangle(name,buf);
		}
		break;
	
	case PARAM_R:				    //-r选项
		if ( name[0] != '.')
		{
			display_single(name);
		}
		break;

	default:
			break;
	}
	
}
int main(int argc,char *argv[])
{
//-----------------------------------------------------
  //initialization of main variables
  char outfile[20];//output file
  const int max = 100;   // max. number of stations
  
  int n;             // number of stations
  float dDD;         // detector/detector distance [mm]
  float dAD;         // absorber/detector distance [mm]  
  
  int type[max];     // detector type
  float z[max];         // z position from target [mm]
  float d[max];         // detector thickness [mm]
  char material[256][max];//material
//-----------------------------------------------------
  //reading and checking input arguments
  if(argc<6)
  {
    printf("not enough arguments\n");
    printf("You gave %d argumenst.\n",argc-1);
    printf("At least 5 arguments are needed:\n");
    printf("outfile,n,dDD,dAD,absorber thickness(es)...\n");
    exit(-1);
  }
  
  strcpy(outfile,argv[1]);
  n=atoi(argv[2]);
  dDD=atof(argv[3]);
  dAD=atof(argv[4]);
  
  if((n/4)*4!=n || n>max)
  {
    printf("Unacceptable number of stations. Must be a multiple of 4 and less than %d.\n",max);
    exit(-1);
  }
  
  int given=argc-5;
  int needed=n/4;
  
  if(given!=needed)
  {
    printf("You gave %d absorber thickness(es), but %d are needed.\n",given,needed);
    exit(-1);
  }
  
  //N_absorbers=argc-5;
  int N_absorbers=n/4;
  int *absorbers=new int[N_absorbers];
  
  for(int i=0;i<N_absorbers;i++)
  {
    absorbers[i]=atoi(argv[i+5]);
  }  
//-----------------------------------------------------
  //input verification
  cout<<"outfile="<<outfile<<endl;
  cout<<"n="<<n<<endl;
  cout<<"dDD="<<dDD<<endl;
  cout<<"dAD="<<dAD<<endl;
  for(int i=0;i<N_absorbers;i++)
  {
    cout<<"absorbers["<<i<<"]="<<absorbers[i]<<endl;
  }  
//-----------------------------------------------------
  //MUCH_large.geo:
  /*n=24;
  dDD=50;
  dAD=25;
  int absorbers[6]={200,200,200,300,350,1000};*/  
//-----------------------------------------------------
  //creating filenames with extensions
  char datfile[256];       // geometry data file - input
  char logfile[256];      // log file for the conversion
  char geofile[256];      // geometry data file for CBMROOT - output
  sprintf(datfile,"%s.dat",outfile);
  sprintf(logfile,"%s.log",outfile);
  sprintf(geofile,"%s.geo",outfile);  
//-----------------------------------------------------
  //create .dat file
  FILE *out=fopen(datfile,"w");
  
  fprintf(out,"stations\n");
  fprintf(out,"%d\n",n);
  fprintf(out,"distance1\n");
  fprintf(out,"%f\n",dDD);
  fprintf(out,"distance2\n");
  fprintf(out,"%f\n",dAD);
  
  fprintf(out,"parameters\n");
  for(int i=0; i<n; i++)
  {
    if(i%4==0)
    {
      type[i]=0;
      sprintf(material[i],"MUCHiron");
      d[i]=absorbers[i/4];
    }
    else
    {
      type[i]=1;
      sprintf(material[i],"MUCHargon");
      d[i]=10;
    }
    if(i==0) z[i]=1025;
    else z[i]=0;    
    fprintf(out,"%d\t%d\t%f\t%f\t%s\n",i+1,type[i],z[i],d[i],material[i]);
  }
  
  fclose(out);
//-----------------------------------------------------
  //freeing memory
  delete(absorbers);
//-----------------------------------------------------
  //create .log and .geo file from .dat file
  create_MUCHnew_geo_file(outfile);
//-----------------------------------------------------
  //display generated files
  cout<<"==="<<datfile<<"==="<<endl;
  display_file(datfile);
  cout<<"==="<<logfile<<"==="<<endl;
  display_file(logfile);
  cout<<"==="<<geofile<<"==="<<endl;
  display_file(geofile);
}