Пример #1
0
struct boot_info *dt_from_source(const char *fname)
{
	the_boot_info = NULL;

	push_input_file(fname);

	if (yyparse() != 0)
		return NULL;

	fill_fullpaths(the_boot_info->dt, "");

	return the_boot_info;
}
Пример #2
0
local boolean get_web_line(void)
{ do
    if (++cur_line,input_ln(cur_file)) /* then a line has been found */
      if (!compatibility_mode
       && limit>&buffer[1] && buffer[0]=='@' && buffer[1]=='i')
      { loc=&buffer[2]; print_where=true;
        if (locate_file_name()) /* expand \:i */
         push_input_file(false,false);
      }
      else return true; /* return the line without further action */
    else if (include_depth==0) /* then end of input has been reached */
    { input_has_ended=true; web_file_open=false; return false; }
    else
    { fclose(cur_file); print_where=true;
      if (include_depth--==saved_include_depth) /* then restore |changing| */
      { changing=saved_changing; change_limit=saved_change_limit;
	saved_include_depth=0; including_header_file=false;
	if (changing) return false; /* fall back into change file */
      }
    }
  while (true);
}
Пример #3
0
int main (int argc, char *argv[])
{
#ifdef WIN32
    char *callname = argv[0];
#endif
    char linecopy[MAXLINE];
    DATASET *dset = NULL;
    MODEL *model = NULL;
    ExecState state;
    char *line = NULL;
    int quiet = 0;
    int makepkg = 0;
    int load_datafile = 1;
    char filearg[MAXLEN];
    char runfile[MAXLEN];
    double scriptval = NADBL;
    CMD cmd;
    PRN *prn = NULL;
    PRN *cmdprn = NULL;
    int err = 0;

#ifdef G_OS_WIN32
    win32_set_gretldir(callname);
#endif

    nls_init();

#ifdef HAVE_READLINE
    rl_bind_key(0x18, ctrl_x);
#endif

    dset = datainfo_new();
    if (dset == NULL) {
	noalloc();
    }

    if (argc < 2) {
	load_datafile = 0;
    } else {
	gretlopt opt = 0;

	err = parse_options(&argc, &argv, &opt, &scriptval, filearg);

	if (!err && (opt & (OPT_DBOPEN | OPT_WEBDB))) {
	    /* catch GUI-only options */
	    err = E_BADOPT;
	}

	if (err) {
	    /* bad option */
	    usage(1);
	} else if (opt & (OPT_HELP | OPT_VERSION)) {
	    /* we'll exit in these cases */
	    if (opt & OPT_HELP) {
		usage(0);
	    } else {
		logo(0);
		exit(EXIT_SUCCESS);
	    }
	}
	    
	if (opt & (OPT_BATCH | OPT_RUNIT | OPT_MAKEPKG)) {
	    if (*filearg == '\0') {
		/* we're missing a filename argument */
		usage(1);
	    } else {
		/* record argument (not a datafile) */
		strcpy(runfile, filearg);
		load_datafile = 0;
		if (opt & OPT_BATCH) {
		    batch = 1;
		} else if (opt & OPT_MAKEPKG) {
		    batch = 1;
		    makepkg = 1;
		} else {
		    runit = 1;
		}
	    }
	} else if (*filearg == '\0') {
	    load_datafile = 0;
	}

	if (opt & OPT_QUIET) {
	    quiet = 1;
	}

	if (opt & OPT_ENGLISH) {
	    force_language(LANG_C);
	}
    }

    libgretl_init();

    logo(quiet);
    if (!quiet) {
	session_time(NULL);
    }

    prn = gretl_print_new(GRETL_PRINT_STDOUT, &err);
    if (err) {
	noalloc();
    }

    line = malloc(MAXLINE);
    if (line == NULL) {
	noalloc();
    }

#ifdef WIN32
    win32_cli_read_rc(callname);
#else
    cli_read_rc();
#endif /* WIN32 */

    if (!batch) {
	strcpy(cmdfile, gretl_workdir());
	strcat(cmdfile, "session.inp");
	cmdprn = gretl_print_new_with_filename(cmdfile, &err);
	if (err) {
	    errmsg(err, prn);
	    return EXIT_FAILURE;
	}
    }

    if (load_datafile) {
	handle_datafile(filearg, runfile, dset, prn, cmdprn);
    }

    /* allocate memory for model */
    model = allocate_working_model();
    if (model == NULL) {
	noalloc(); 
    }

    gretl_cmd_init(&cmd);
    gretl_exec_state_init(&state, 0, line, &cmd, model, prn);
    set_debug_read_func(get_interactive_line);

    /* print list of variables */
    if (data_status) {
	varlist(dset, prn);
    }

    if (!na(scriptval)) {
	/* define "scriptopt" */
	gretl_scalar_add("scriptopt", scriptval);
    }

    /* misc. interactive-mode setup */
    if (!batch) {
	check_help_file();
	fb = stdin;
	push_input_file(fb);
	if (!runit && !data_status) {
	    fputs(_("Type \"open filename\" to open a data set\n"), stdout);
	}
    }

#ifdef HAVE_READLINE
    initialize_readline();
#endif
    
    if (batch || runit) {
	/* re-initialize: will be incremented by "run" cmd */
	runit = 0;
	if (makepkg) {
	    set_gretl_echo(0);
	}
	if (strchr(runfile, ' ')) {
	    sprintf(line, "run \"%s\"", runfile);
	} else {
	    sprintf(line, "run %s", runfile);
	}
	err = cli_exec_line(&state, dset, cmdprn);
	if (err && fb == NULL) {
	    exit(EXIT_FAILURE);
	}
    }

    *linecopy = '\0';

    /* main command loop */
    while (cmd.ci != QUIT && fb != NULL && !xout) {
	if (err && gretl_error_is_fatal()) {
	    gretl_abort(linecopy);
	}

	if (gretl_execute_loop()) { 
	    if (gretl_loop_exec(&state, dset, NULL)) {
		return 1;
	    }
	} else {
	    err = cli_get_input_line(&state);
	    if (err) {
		errmsg(err, prn);
		break;
	    }
	}

	if (!state.in_comment) {
	    if (cmd.context == FOREIGN || cmd.context == MPI ||
		gretl_compiling_python(line)) {
		tailstrip(line);
	    } else {
		err = maybe_get_input_line_continuation(line); 
		if (err) {
		    errmsg(err, prn);
		    break;
		}
	    }
	} 

	strcpy(linecopy, line);
	tailstrip(linecopy);
	err = cli_exec_line(&state, dset, cmdprn);
    } /* end of get commands loop */

    if (!err) {
	err = gretl_if_state_check(0);
	if (err) {
	    errmsg(err, prn);
	}
    }

    if (makepkg && !err) {
	switch_ext(filearg, runfile, "gfn");
	sprintf(line, "makepkg %s\n", filearg);
	cli_exec_line(&state, dset, cmdprn);
    }

    /* leak check -- try explicitly freeing all memory allocated */

    destroy_working_model(model);
    destroy_dataset(dset);

    if (fb != stdin && fb != NULL) {
	fclose(fb);
    }

    free(line);

    gretl_print_destroy(prn);
    gretl_cmd_free(&cmd);
    libgretl_cleanup();

    return 0;
}
Пример #4
0
boolean get_line (void) /* inputs the next line */
{
restart:
  if (changing) mark_section_as_changed(section_count);
  else 
       { if (get_web_line()
          && change_limit>change_buffer
          && limit-buffer==change_limit-change_buffer
          && buffer[0]==change_buffer[0]
            ) check_change();
       }
  if (changing)
  { 
    { if (++change_line,!input_ln (change_file))
      { err_print("! Change file ended without @z"); 
      buffer[0]='@'; buffer[1]='z'; limit=&buffer[2];
      }
      if (limit>&buffer[1] && buffer[0]=='@') /* check if the change has ended */
        if (buffer[1]=='z')
        { prime_the_change_buffer(); changing=false; print_where=true; }
        else if (buffer[1]=='x' || buffer[1]=='y')
        { loc=&buffer[2]; err_print("! Where is the matching @z?"); }
    				     
        else 
             { if (buffer[1]=='i' && !compatibility_mode)
               { loc=&buffer[2]; err_print ("! No includes allowed in change file"); }
             }				    
    }
    if (!changing)
    { mark_section_as_changed(section_count); goto restart; }
  }
  loc=&buffer[0]; *limit= ' '; /* place sentinel space */
  if (compatibility_mode && buffer[0]=='@' && buffer[1]=='i')
  { loc+=2; print_where=true;
    if (locate_file_name())
      push_input_file(false,changing);
    goto restart;
  }
  if (limit-buffer>5
   && strncmp(buffer,"#line",5)==0 && isspace((eight_bits)buffer[5]))
    
    { sixteen_bits line=0;
      print_where=true; /* output a \&{\#line} directive soon */
      loc=&buffer[6];  while (loc<limit && isspace((eight_bits)*loc)) ++loc;
      if (isdigit((eight_bits)*loc))
      { do line=10*line + *loc++ -'0'; while (isdigit((eight_bits)*loc));
        while (loc<limit && isspace((eight_bits)*loc)) ++loc;
        if (*loc++=='"')
        { int i=0;  while (&loc[i]<limit && loc[i]!='"') ++i;
          if (loc[i]=='"' && i<max_file_name_length)
          { struct f* cur_f= changing ? &change : &file[include_depth];
            cur_f->line=line-1; /* directive applies to next line, not this one */
            strncpy(cur_f->name,loc,i); cur_f->name[i]='\0';
    	goto restart;
          }
        }
      }
      err_print("! Improper #line directive"); goto restart;
    	    
    }
  return !input_has_ended;
}