Example #1
0
static int
command_read(int argc, char *argv[])
{
    char	*prompt;
    int		timeout;
    time_t	when;
    char	*cp;
    char	*name;
    char	buf[256];		/* XXX size? */
    int		c;
    
    timeout = -1;
    prompt = NULL;
    optind = 1;
    optreset = 1;
    while ((c = getopt(argc, argv, "p:t:")) != -1) {
	switch(c) {
	    
	case 'p':
	    prompt = optarg;
	    break;
	case 't':
	    timeout = strtol(optarg, &cp, 0);
	    if (cp == optarg) {
		snprintf(command_errbuf, sizeof(command_errbuf),
		    "bad timeout '%s'", optarg);
		return(CMD_ERROR);
	    }
	    break;
	default:
	    return(CMD_OK);
	}
    }

    argv += (optind);
    argc -= (optind);
    if (argc > 1) {
	command_errmsg = "wrong number of arguments";
	return(CMD_ERROR);
    }
    name = (argc > 0) ? argv[0]: NULL;
	
    if (prompt != NULL)
	printf("%s", prompt);
    if (timeout >= 0) {
	when = time(NULL) + timeout;
	while (!ischar())
	    if (time(NULL) >= when)
		return(CMD_OK);		/* is timeout an error? */
    }

    ngets(buf, sizeof(buf));

    if (name != NULL)
	setenv(name, buf, 1);
    return(CMD_OK);
}
Example #2
0
/*
 * Interactive mode
 */
void
interact(const char *rc)
{
    static char	input[256];			/* big enough? */
#ifndef BOOT_FORTH
    int		argc;
    char	**argv;
#endif

#ifdef BOOT_FORTH
    bf_init((rc) ? "" : NULL);
#endif

    if (rc == NULL) {
	/* Read our default configuration. */
	if (include("/boot/loader.rc") != CMD_OK)
	    include("/boot/boot.conf");
    } else if (*rc != '\0')
	include(rc);

    printf("\n");

    /*
     * Before interacting, we might want to autoboot.
     */
    autoboot_maybe();
    
    /*
     * Not autobooting, go manual
     */
    printf("\nType '?' for a list of commands, 'help' for more detailed help.\n");
    if (getenv("prompt") == NULL)
	setenv("prompt", "${interpret}", 1);
    if (getenv("interpret") == NULL)
        setenv("interpret", "OK", 1);
    

    for (;;) {
	input[0] = '\0';
	prompt();
	ngets(input, sizeof(input));
#ifdef BOOT_FORTH
	bf_vm->sourceID.i = 0;
	bf_run(input);
#else
	if (!parse(&argc, &argv, input)) {
	    if (perform(argc, argv))
		printf("%s: %s\n", argv[0], command_errmsg);
	    free(argv);
	} else {
	    printf("parse error\n");
	}
#endif
    }
}
Example #3
0
/*
 * Interactive mode
 */
void
interact(void)
{
    char	input[256];			/* big enough? */
    int		argc;
    char	**argv;

    /*
     * We may be booting from the boot partition, or we may be booting
     * from the root partition with a /boot sub-directory.  If the latter
     * chdir into /boot.  Ignore any error.  Only rel_open() uses the chdir
     * info.
     */
    chdir("/boot");
    setenv("base", DirBase, 1);

    /*
     * Read our default configuration
     */
    if (include("dloader.rc") != CMD_OK)
	include("boot.conf");
    printf("\n");
    /*
     * Before interacting, we might want to autoboot.
     */
    autoboot_maybe();

    dloader_init_cmds();

    /*
     * Not autobooting, go manual
     */
    printf("\nType '?' for a list of commands, 'help' for more detailed help.\n");
    if (getenv("prompt") == NULL)
	setenv("prompt", "OK", 1);

    for (;;) {
	input[0] = '\0';
	prompt();
	ngets(input, sizeof(input));
	if (!parse(&argc, &argv, input)) {
	    if (perform(argc, argv))
		printf("%s: %s\n", argv[0], command_errmsg);
	    free(argv);
	} else {
	    printf("parse error\n");
	}
    }
}
Example #4
0
void
sboot(void) 
{
	char buf[128], *ebuf;

	buf[0] = '0';
	consinit();
	printf("\nsboot: serial line bootstrap program (&end = %p) [%s]\n\n",
	    &end, bootprog_rev);
	if (reboot) {  /* global flag from AAstart.s */
		reboot = 0;
		printf("[rebooting...]\n");
		buf[0] = 'b';
		buf[1] = 0;
		do_cmd(buf, &buf[1]);
	}
	for (;;) {
		printf(">>> ");
		ebuf = ngets(buf, sizeof(buf));
		do_cmd(buf, ebuf);
	}
	/* not reached */
}
Example #5
0
File: in.c Project: mycoboco/beluga
/*
 *  reads the next line;
 *  in_limit points to one past the terminating null unless EOF;
 *  ASSUMPTION: '\n' is no part of multibyte characters and has no effect on the shift state;
 *  ASSUMPTION: charset in which source is written is same as that in which beluga is running
 */
static void nextline(void)
{
    int nul;
    char *p;
    const char *q;
    sz_t len;

    assert(fptr);

    if (bs > 0)
        in_py += bs, bs = 0;
    lmap_fline(++in_py, ftell(fptr));
    p = (char *)(in_limit = in_line = in_cp = buf);
    *p = '\0';
    len = 0;

    while (1) {
        assert(bufn-len > 1);
        nul = 0;
        q = ngets(p+len, bufn-len, fptr, &nul);
        if (ferror(fptr)) {
            err_dline(NULL, 1, ERR_INPUT_ERROR);
            in_nextline = eof;
            break;
        }
        if (nul)
            repnul(p+len, q);
        len += (q - (p+len));
        if (len == 0) {    /* real EOF */
            in_nextline = eof;
            break;
        }
        if (len > 1 && (p[len-2] == '\\' ||
                        (main_opt()->trigraph && len > 3 &&
                         p[len-4] == '?' && p[len-3] == '?' && p[len-2] == '/')) &&
            p[len-1] == '\n') {
            if (p[len-2] == '/')
                in_trigraph(&p[len-4]);    /* for warning */
            if (p[len-2] == '\\' || (main_opt()->trigraph & 1)) {    /* line splicing */
                int n = 1+1;
                int c;
                lmap_fline(in_py + ++bs, ftell(fptr));
                c = getc(fptr);
                if (p[len-2] == '/')
                    len -= 2, n = 3+1;
                if (c == EOF) {
                    err_dline(p+len-2, n, ERR_INPUT_BSNLEOF);
                    p[len-2] = '\n';
                    p[--len] = '\0';
                    bs--;    /* for better tracking of locus */
                } else {
                    ungetc(c, fptr);
                    p[--len-1] = '\n';
                    continue;
                }
            }
        }
        if (p[len-1] == '\n' || feof(fptr)) {    /* line completed */
#ifdef HAVE_ICONV
            if (main_iton) {
                ICONV_DECL(p, len + 1);    /* +1 to include NUL */
                olenv = olen = ibufn;
                obufv = obuf = ibuf;
                ICONV_DO(main_iton, 0, { err_dline(p + (ibufv-p+1), 1, ERR_INPUT_CONVFAIL); });
                ibuf = p = obuf;
                len = olen - olenv - 1;
            }
#endif    /* HAVE_ICONV */
            in_line = p;
            if (!feof(fptr))    /* newline read from input */
                p[--len] = '\0';
            else if (p[len-1] != '\n')    /* EOF without newline */
                err_dline(p+len, 1, ERR_INPUT_NOTENDNL);
            if (len > 1 && ISCH_SP(p[len-1]) && (q = rnsp(p, p+len)) != NULL &&
                (*q == '\\' || ((main_opt()->trigraph & 1) && q[0] == '/' && q > p+1 &&
                                q[-1] == '?' && q[-2] == '?')))
                err_dline(q+1, p+len-1-q, ERR_INPUT_BSSPACENL);
            in_limit = &p[len+1];
            in_cp = p;
            if (main_opt()->std) {
                sz_t c = in_cntchar(p, &p[len], TL_LINE_STD, &q);
                if (c >= TL_LINE_STD)
                    (void)(err_dline(q, 1, ERR_INPUT_LONGLINE) &&
                           err_dline(NULL, 1, ERR_INPUT_LONGLINESTD, (unsigned long)TL_LINE_STD));
            }
            return;
        } else {    /* expands buffer */
Example #6
0
void open_pfm_files (MISC *misc, NV_CHAR *file, NV_F64_XYMBR *bounds)
{
  FILE *fp;

  if ((fp = fopen (file, "r")) == NULL)
    {
      QMessageBox::warning (0, pfmView::tr ("pfmView Open PFM Structure"),
                            pfmView::tr ("The file ") + QDir::toNativeSeparators (QString (file)) + 
                            pfmView::tr (" cannot be opened or there was an error reading the file.") +
                            pfmView::tr ("  The error message returned was:\n\n") +
                            QString (strerror (errno)));
      exit (-1);
    }

  NV_CHAR string[512];
  NV_FLOAT64 mx[4], my[4];

  for (NV_INT32 i = 0 ; i < 4 ; i++)
    {
      fgets (string, sizeof (string), fp);
      sscanf (string, "%lf %lf", &my[i], &mx[i]);
    }

  bounds->min_x = 999999.0;
  bounds->min_y = 999999.0;
  bounds->max_x = -999999.0;
  bounds->max_y = -999999.0;
  for (NV_INT32 i = 0 ; i < 4 ; i++)
    {
      if (misc->dateline && mx[i] < 0.0) mx[i] += 360.0;

      if (mx[i] < bounds->min_x) bounds->min_x = mx[i];
      if (my[i] < bounds->min_y) bounds->min_y = my[i];
      if (mx[i] > bounds->max_x) bounds->max_x = mx[i];
      if (my[i] > bounds->max_y) bounds->max_y = my[i];
    }

  fgets (string, sizeof (string), fp);
  sscanf (string, "%d", &misc->abe_share->pfm_count);

  for (NV_INT32 pfm = 0 ; pfm < misc->abe_share->pfm_count ; pfm++)
    {
      ngets (misc->abe_share->open_args[pfm].list_path, sizeof (misc->abe_share->open_args[pfm].list_path), fp);


      //  Open the file and make sure it is a valid PFM file.

      misc->abe_share->open_args[pfm].checkpoint = 0;
      misc->pfm_handle[pfm] = open_existing_pfm_file (&misc->abe_share->open_args[pfm]);

      if (misc->pfm_handle[pfm] < 0)
        {
          if (QMessageBox::warning (0, pfmView::tr ("pfmView Open PFM Structure"), pfmView::tr ("The file ") + 
                                    QDir::toNativeSeparators (QString (misc->abe_share->open_args[pfm].list_path)) + 
                                    pfmView::tr (" is not a PFM structure or there was an error reading the file.") +
                                    pfmView::tr ("  The error message returned was:\n\n") + QString (pfm_error_str (pfm_error))))

            if (pfm_error == CHECKPOINT_FILE_EXISTS_ERROR)
              {
                fprintf (stderr, "\n\n%s\n", pfm_error_str (pfm_error));
                exit (-1);
              }

          exit (-1);
        }


      //  Compute cell sizes for sunshading.

      misc->ss_cell_size_x[pfm] = misc->abe_share->open_args[pfm].head.bin_size_xy;
      misc->ss_cell_size_y[pfm] = misc->abe_share->open_args[pfm].head.bin_size_xy;


      misc->average_type[pfm] = 0;


      //  Check to see if we're using something other than the standard AVERAGE EDITED DEPTH (MISP interpolated surface).

      if (strstr (misc->abe_share->open_args[pfm].head.average_filt_name, "MINIMUM MISP"))
        {
          misc->average_type[pfm] = 1;
        }
      else if (strstr (misc->abe_share->open_args[pfm].head.average_filt_name, "AVERAGE MISP"))
        {
          misc->average_type[pfm] = 2;
        }
      else if (strstr (misc->abe_share->open_args[pfm].head.average_filt_name, "MAXIMUM MISP"))
        {
          misc->average_type[pfm] = 3;
        }

      misc->abe_share->display_pfm[pfm] = NVTrue;
      misc->pfm_alpha[pfm] = 255;
    }
}
Example #7
0
NV_BOOL get_pos_file (NV_CHAR *htpi_file, NV_CHAR *pos_file)
{
  static NV_CHAR        prev_htpi[512], prev_pos[512];
  static NV_BOOL        prev_ret = NVFalse;
  NV_CHAR               kin_file[512], pos_dir[512], temp[512], string[512], pos_basename[512];
  FILE                  *fp;
  NV_INT32              i;


  /*  If we haven't changed HOF/TOF files we don't need to check again.  */

  if (!strcmp (htpi_file, prev_htpi))
    {
      if (prev_ret) strcpy (pos_file, prev_pos);
      return (prev_ret);
    }


  prev_ret = NVFalse;


  /*
      The SBET file name will be stored in the .kin file by GCS.  We will read that file first (if it exists)
      to get the correct filename.  It may still not match because Windoze doesn't care about upper/lower
      case but we can deal with that.  If the .kin file isn't there or we can't find the SBET file we'll
      revert to the .pos file.
  */


  strcpy (temp, htpi_file);
  strcpy (pos_basename, gen_basename (temp));


  /*  If the input filename is a .pgps file we can just use the basename of the file.  If it's a .hof, .tof, or.img
      we have to strip off some stuff and change DS to MD.  */

  if (!strstr (htpi_file, ".pgps"))
    {
      pos_basename[strlen (pos_basename) - 12] = 0;
      pos_basename[2] = 'M';
      pos_basename[3] = 'D';
    }


  /*  Strip off the HOF/TOF/PGPS extension.  */

  for (i = strlen (pos_basename) ; i > 0 ; i--)
    {
      if (pos_basename[i] == '.')
        {
          pos_basename[i] = 0;
          break;
        }
    }


  strcpy (pos_dir, gen_dirname (gen_dirname (temp)));


  /*  If you happen to be in the directory where the HOF/TOF/PGPS/IMG file is located you can't move up 
      to gen_dirname (gen_dirname (temp)).  That is, you can't go up a level since it's not in the
      htpi name.  In this case we set pos_dir to ..  */

  if (!strcmp (gen_dirname (temp), ".")) strcpy (pos_dir, "..");
  strcpy (temp, pos_dir);
  sprintf (kin_file, "%s%1cpos%1c%s.kin", pos_dir, separator, separator, pos_basename);

  if ((fp = fopen (kin_file, "r")) != NULL)
    {
      ngets (string, sizeof (string), fp);
      fclose (fp);


      /*  The file name in the .kin file may be correct - will miracles never cease?  */

      sprintf (pos_file, "%s%1cpos%1c%s", pos_dir, separator, separator, string);
      if ((fp = fopen (pos_file, "rb")) != NULL)
        {
          fclose (fp);
          prev_ret = NVTrue;
          strcpy (prev_htpi, htpi_file);
          strcpy (prev_pos, pos_file);
          return (prev_ret);
        }


      /*  The file name in the .kin file may be upper or lower case.  First try lower case.  */

      for (i = 0 ; i < strlen (string) ; i++) string[i] = tolower (string[i]);


      sprintf (pos_file, "%s%1cpos%1c%s", pos_dir, separator, separator, string);
      if ((fp = fopen (pos_file, "rb")) != NULL)
        {
          fclose (fp);
          prev_ret = NVTrue;
          strcpy (prev_htpi, htpi_file);
          strcpy (prev_pos, pos_file);
          return (prev_ret);
        }


      /*  Next try upper case.  */

      for (i = 0 ; i < strlen (string) ; i++) string[i] = toupper (string[i]);

      sprintf (pos_file, "%s%1cpos%1c%s", pos_dir, separator, separator, string);
      if ((fp = fopen (pos_file, "rb")) != NULL)
        {
          fclose (fp);
          prev_ret = NVTrue;
          strcpy (prev_htpi, htpi_file);
          strcpy (prev_pos, pos_file);
          return (prev_ret);
        }
    }


  /*  If we got here then there was either no .kin file or we couldn't find/open the file listed in the
      .kin file.  Now we fall back to the .pos file.  */

  strcpy (temp, pos_dir);
  sprintf (pos_file, "%s%1cpos%1c%s.pos", pos_dir, separator, separator, pos_basename);

  if ((fp = fopen (pos_file, "rb")) != NULL)
    {
      fclose (fp);
      prev_ret = NVTrue;
      strcpy (prev_htpi, htpi_file);
      strcpy (prev_pos, pos_file);
      return (prev_ret);
    }

  return (prev_ret);
}