Exemplo n.º 1
0
bool Lng::read()
{
  char fname1[120];
  char fname2[120];
  pwr_tStatus sts;

  if ( tree)
    tree_DeleteTable( &sts, tree);

  tree = tree_CreateTable( &sts, sizeof(lang_sKey), offsetof(lang_sRecord, key),
			   sizeof(lang_sRecord), 100, compKey);

  // Read base files
  strcpy( fname1, "$pwr_exe/en_us/xtt_lng.dat");
  strcpy( fname2, "$pwr_exe/%s/xtt_lng.dat");

  if ( !read_files( fname1, fname2, true,  &sts))
    return false;

  // Read project files
  strcpy( fname1, "$pwrp_exe/xtt_lng_en_us.dat");
  strcpy( fname2, "$pwrp_exe/xtt_lng_%s.dat");

  if ( !read_files( fname1, fname2, false, &sts))
    return false;

  return true;
}
Exemplo n.º 2
0
TEST(GTestHarness, SanityCheck) {
  NameMap games, sources, others;
  read_files(kDrivenTestDirectory, &games, &sources, &others);

  for (auto &game : games) {
    auto match = sources.find(game.second + ".cpp");
    if (match == sources.end()) match = sources.find(game.second + ".cc");
    if (match == sources.end()) {
      FAIL() << "Game \"" << game.first
             << "\" does not appear to have a matching test driver.";
    } else {
      sources.erase(match);
    }
  }
  if (sources.size()) {
    if (sources.size() == 1) {
      FAIL() << "Extra source file \"" << sources.begin()->first << '"';
    } else {
      FAIL() << "Found " << sources.size() << " extra source files, including "
             << '"' << sources.begin()->first << '"';
    }
  }
  if (others.size()) {
    if (others.size() == 1) {
      FAIL() << "Junk file \"" << others.begin()->first << '"';
    } else {
      FAIL() << "Found " << others.size() << " junk files, including "
             << '"' << others.begin()->first << '"';
    }
  }
}
Exemplo n.º 3
0
int read_flags_config(void)
{
  if (read_line("/flags",&oldflags) != 0)
    return 0;
  read_files();
  return 1;
}
Exemplo n.º 4
0
int read_file_config(void)
{
  stralloc_copys(&oldflags,"-ABCDEFGHIJKLMNOPqRSTUVWXYZ");
  oldflags.s[1] = "Aa"[exists("/archived")];
  oldflags.s[2] = "Bb"[exists("/modgetonly")];
  //oldflags.s[3] = "Cc"[exists("/ezmlmrc")]; /* Should always end up set */
  oldflags.s[4] = "Dd"[exists("/digested")];
  /* -e is not applicable */
  oldflags.s[6] = "Ff"[exists("/prefix")];
  oldflags.s[7] = "Gg"[exists("/subgetonly")];
  oldflags.s[8] = "Hh"[exists("/nosubconfirm")];
  oldflags.s[9] = "Ii"[exists("/threaded")];
  oldflags.s[10] = "Jj"[exists("/nounsubconfirm")];
  oldflags.s[11] = 'k';		/* -k is always enabled */
  oldflags.s[12] = "Ll"[exists("/modcanlist")];
  oldflags.s[13] = "Mm"[exists("/modpost")];
  oldflags.s[14] = "Nn"[exists("/modcanedit")];
  oldflags.s[15] = "Oo"[exists("/modpostonly")];
  oldflags.s[16] = "Pp"[exists("/public")];
  oldflags.s[17] = 'q';		/* -q is always enabled */
  oldflags.s[18] = "Rr"[exists("/remote")];
  oldflags.s[19] = "Ss"[exists("/modsub")];
  oldflags.s[20] = "Tt"[exists("/addtrailer")];
  oldflags.s[21] = "Uu"[exists("/subpostonly")];
  /* -v is not applicable */
  oldflags.s[23] = "Ww"[exists("/nowarn")];
  oldflags.s[24] = "Xx"[exists("/mimeremove")];
  oldflags.s[25] = "Yy"[exists("/confirmpost")];
  /* -z is unused */
  read_files();
  return 1;
}
Exemplo n.º 5
0
char	explorer_on_enter(t_tekpaint *tekpaint,
			  t_explorer *explorer,
			  int *i)
{
  char	*path;
  char	*file_name;
  DIR	*dirp;

  if ((file_name = get_focused_file_name(explorer, *i)))
    {
      path = concat_path(explorer->current_path, file_name);
      if (NULL == (dirp = opendir(path)))
	{
	  closedir(dirp);
	  if (explorer_on_enter_file(file_name, path, explorer))
	    return (1);
	}
      else
	{
	  closedir(dirp);
	  explorer->current_path = path;
	  *i = 0;
	  read_files(explorer);
	  display_files(tekpaint, explorer, *i);
	}
  }
  else
    my_putstr("Ce fichier est incorrect !\n");
  return (0);
}
Exemplo n.º 6
0
Arquivo: mlmi.c Projeto: mytchel/mlm
int main(int argc, char **argv) {
	symbol *symbols;

	symbols = init_built_in_functions(symbols);
	symbols = init_functions(symbols, io_functions, IO_FUNCTIONS_N);

	char **defaults = malloc(sizeof(char*) * 3);
	defaults[0] = NULL;
	defaults[1] = "/usr/lib/mlm/funcs.l";
	defaults[2] = NULL;

	read_files(symbols, 2, defaults);

	if (argc > 1) read_files(symbols, argc, argv);
	repl(symbols, stdin, 1);
	return 0;
}
InitEditorWidget::InitEditorWidget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::InitEditorWidget)
{
    ui->setupUi(this);
    read_files();
    new ConfigSyntaxHighlighter(ui->initEdit->document());
    new ConfigSyntaxHighlighter(ui->dinitEdit->document());
}
Exemplo n.º 8
0
vector<string> enumerate_simple_games() {
  NameMap games, others;
  read_files(kSimpleTestDirectory, &games, nullptr, &others);
  bitch_about_junk_files(others);
  vector<string> result;
  for (auto &kv : games) {
    result.push_back(string(kSimpleTestDirectory) + "/" + kv.first);
  }
  return result;
}
Exemplo n.º 9
0
WORD rvrt_files(VOID)
{
	if (!open_files(TRUE))
		return(FALSE);
	else if (!read_files())
		return(FALSE);
	else
	{
		redo_trees();
		return(TRUE);
	}	
}
Exemplo n.º 10
0
dns_map* create_dns_map(FILE* h_domain2token, FILE* h_token2ip) {
    dns_map* map = (dns_map*) malloc(sizeof(dns_map));

    map->domain_to_token = create_hash_map(str_cmp);
    map->token_to_ip = create_hash_map(str_cmp);
    map->tokens = create_hash_map(str_cmp);

    map->h_domain2token = h_domain2token;
    map->h_token2ip = h_token2ip;

    // Read data from files
    read_files(map, h_domain2token, h_token2ip);

    return map;
}
Exemplo n.º 11
0
/*
 * FUNCAO PRINCIPAL
 */
int main(int argc, char** argv) {
    //FILE *arquivo;
    //long tamanho;
    int i;

    if (argc > 1) {
        //fprintf(stderr, "nome do arquivo: %s\n", argv[i] );
        //ler uma palavra e passar para a funcao de hasing
        read_files(argc, argv);
        read_phrases();
    }

    //que retornara o indice a ser inserido 

    return (EXIT_SUCCESS);
}
Exemplo n.º 12
0
void Lng::read_include( ifstream& fp1, ifstream& fp2, bool global, pwr_tStatus *sts) 
{
  char line1[200];
  char line2[200];
  streampos pos1;
  pwr_tFileName fname1, fname2;
  
  for(;;) {
    pos1 = fp1.tellg();
    for (;;) {
      if ( !fp1.getline( line1, sizeof( line1))) {
	*sts = LNG__EOF;
	return;
      }
      if ( line1[0] != '#')
	break;
    }

    if ( strncmp( line1, "Include:", 8) == 0) {
      for (;;) {
	if ( !fp2.getline( line2, sizeof( line2))) {
	  *sts = LNG__EOF;
	  return;
	}
	if ( line2[0] != '#')
	  break;
      }

      if ( strncmp( line2, "Include:", 8) != 0) {
	*sts = LNG__INCLUDEMISMATCH;
	return;
      }
      
      dcli_trim( fname1, &line1[8]);
      dcli_trim( fname2, &line2[8]);
      if ( !read_files( fname1, fname2, global, sts))
	return;
    }
    else {
      fp1.seekg( pos1);
      break;
    }
  }
  *sts = LNG__SUCCESS;
}
Exemplo n.º 13
0
void InitEditorWidget::on_buttonBox_clicked(QAbstractButton *button)
{
   const QDialogButtonBox::ButtonRole role = ui->buttonBox->buttonRole(button);
   if( role == QDialogButtonBox::ResetRole ) {
       //reset / reload
       read_files();
   } else if( role == QDialogButtonBox::AcceptRole ) {
       QFile initfile(DwarfFortress::instance().getInitPath()), dinitfile(DwarfFortress::instance().getDInitPath());
       initfile.open(QFile::WriteOnly | QFile::Truncate | QFile::Text);
       initfile.write(ui->initEdit->toPlainText().toAscii());
       dinitfile.open(QFile::WriteOnly | QFile::Truncate | QFile::Text);
       dinitfile.write(ui->dinitEdit->toPlainText().toAscii());

       dinitfile.close();
       initfile.close();

   }
}
Exemplo n.º 14
0
int main(int argc, char *argv[]) {
    if(argc > 1){
      FILE * fp;
      fp = fopen(argv[1], "r");
      if(fp == NULL) {
          printf("File does not exist!\n");
          exit(EXIT_FAILURE);
      }
      read_files(fp);
      print_file_data();
      extract_files();
      fclose(fp);
      exit(EXIT_SUCCESS);
    } else {
        printf("Usage: ./tar filename\n");
        exit(EXIT_FAILURE);
    }
}
Exemplo n.º 15
0
/*Menu is the method for showing some interface for the end user to interact with*/
void menu()
{
    int option = 0;
    /*We Print the Menu navigation chart*/
    print_menu();
    scanf("%i",&option);
    /*If for selecting where we go in the program*/
    if (option ==1)
    {
        /*Call are function for reading in the files*/
        read_files();
    }
    else if (option == 2)
    {
        /*Debug method for printing out the text files left it in as it can be useful later*/
        print_linkedlists();
    }
    else if (option == 3)
    {
        /*This method is used to print out the finished, unfinished and not started competitors*/
        entrants_pos(e_times,e_entrants,e_courses,e_nodes);
    }
    else if (option == 4)
    {
        /*The function below is for getting the progress of 1 specific competitor*/
        printf("Please enter the competitor number of the competitor you would like to query\n\n");
        int i = 0;
        scanf("%i",&i);
        queary_entrant(i,e_courses,c_competitors);
    }
    else if (option == 5)
    {
        /*Sort method for the list of competitors*/
        queary_entrant(-1,e_courses,c_competitors);
        comp_sort(c_competitors);
    }
    else if (option == 6)
    {
        /*Add another time for the components to be taken into account*/
        add_time();
    }
    menu();
}
Exemplo n.º 16
0
LOCAL WORD opn_rsc(VOID)
{
	mouse_form(HGLASS);
	if (open_files(FALSE))
	{
		if (read_files())
		{  
			new_state(FILE_STATE);
			rsc_title();
		}
	}
	else 
	{
		mouse_form(ARROW);
		return(FALSE);	   
	}
	rcs_trpan = 0;
	redo_trees();
	mouse_form(ARROW);
	return(TRUE);
}
Exemplo n.º 17
0
char			explorer(t_tekpaint *tekpaint, t_explorer *explorer)
{
  tekpaint->tool.explorer = explorer;
  explorer->current_path = "./";
  explorer->img = NULL;
  explorer->win = bunny_start_style(EXPLORER_WIDTH,
			  EXPLORER_HEIGHT, TITLEBAR | CLOSE_BUTTON,
			  explorer->win_name);
  explorer->buffer = bunny_new_pixelarray(EXPLORER_WIDTH, EXPLORER_HEIGHT);
  if (explorer->buffer == NULL)
    return (0);
  fill_buffer(explorer->buffer, BLACK);
  read_files(explorer);
  display_files(tekpaint, explorer, 0);
  bunny_set_key_response(explorer_on_key);
  bunny_set_click_response(NULL);
  bunny_set_loop_main_function((t_bunny_loop)main_loop_explorer);
  bunny_loop(explorer->win, 50, tekpaint);
  explorer_reset(tekpaint, explorer);
  return (1);
}
Exemplo n.º 18
0
int files_work()
{
	FILE* f1 = 0;
	FILE* f2 = 0;
	char* buffer = 0;
	int s = 1024;
	int r = 0;
	TRY
	{
		f1 = fopen("./file_to_read", "r");
		if (!f1) 
			THROW;
		f2 = fopen("file_to_write", "w");
		if (!f2) 
			THROW;
		
		buffer = (char*)malloc(s);
		r = read_files(f1, buffer, s, EXCEPTION);
		if (r > 0)
		{
			write_files(f2, buffer, r, EXCEPTION);
		}
		THROW;
	}
	CATCH
	{
		if (f1) 
			fclose(f1);

		if (f2)
			fclose(f2);

		if (buffer)
			free(buffer);
	}

	return 0;
}
Exemplo n.º 19
0
t_bunny_response	explorer_on_key(t_bunny_event_state state,
					t_bunny_keysym key,
					void *data)
{
  t_tekpaint		*tekpaint;
  t_explorer		*explorer;
  static int		i;
  char			*file_name;

  tekpaint = (t_tekpaint*) data;
  explorer = tekpaint->tool.explorer;
  read_files(explorer);
  if (key == BKS_UP && state == GO_UP && i > 0)
    i--;
  else if (key == BKS_DOWN && state == GO_UP)
    i++;
  else if (key == BKS_RETURN && state == GO_UP)
    {
      if (explorer_on_enter(tekpaint, explorer, &i))
	return (EXIT_ON_SUCCESS);
    }
  display_files(tekpaint, explorer, i);
  return (GO_ON);
}
Exemplo n.º 20
0
int main(int argc, char *argv[]) {
    int j;
    int n;
    int status;
    char directory[256],outputdir[256];



    if (argc > 4) {
        printf("Too many arguments.Only using first 3.\n");
    }
    n = atoi(argv[1]);
    time_step = atof(argv[2]);
    strcpy(directory,argv[3]);

    nb = 2;

    sprintf(outputdir,"%stemp_files/",directory);
    status = mkdir(outputdir,S_IRWXU | S_IRWXG | S_IRWXO);
    if (status == -33)  {
        printf("Status is -33 for some reason.\n");
    }
    //sprintf(param_fname,"%sparam_file.txt",directory);


    
    read_param_file(directory);
    nx = params.nx;
    ny = params.ny;
    nz = params.nz;
    CFL = params.cfl;
    IndirectTerm = params.indirect;

    size_x = nx;
    size_y = ny+2*NGHY;
    size_z = nz;
    stride = size_x*size_y;
    pitch = size_x;
    pitch2d = 0;
    //size_t double_to_int = sizeof(double)/sizeof(int);
    pitch2d_int = 0 ;//pitch*(int)double_to_int;
    dx = 2*M_PI/nx;

    if (size_x % 2 == 0) NEVEN = TRUE;
    else NEVEN = FALSE;

    num_threads = 1;

#ifdef _OPENMP
    //omp_set_num_threads(8);
    num_threads = omp_get_max_threads();
    printf("Using %d threads\n",num_threads);
#endif
    allocate_all();
#ifdef _FFTW
    allocate_conv();
#endif
    read_domain(directory);
    
    
    read_files(n,directory);
    //read_single_file(n,1,directory);
    /*
    if (cfl_dt < dt) {
        printf("Using cfl limited timestep of %.4e instead of %.4e\n",cfl_dt,dt);
        dt = cfl_dt;
    }
    */

    
    //move_to_com();


    read_stockholm(directory);
/*
    for(j=0;j<size_y;j++) {
        dens0[j] = params.mdot/(3*M_PI*Nu(ymed(j)));
        vy0[j] = -1.5*Nu(ymin(j))/ymin(j);
        vx0[j] = pow(ymed(j),-.5);
	    vx0[j] *= sqrt(1.0+pow(params.h,2)*pow(ymed(j),2*params.flaringindex)*
			  (2.0*params.flaringindex - 1.5));
        vx0[j] -= omf*ymed(j);

    }
*/
    omf0 = omf;

    output_stock(outputdir);

    output_init(outputdir);
   
    init_rk5();
    nsteps = 0;
    double tstart = psys[0].t;
    double tend = psys[0].t + time_step;
    double time = tstart;


#ifdef _FFTW
    printf("Using FFTW to compute fourier transforms\n");
#endif
#ifdef ARTIFICIALVISCOSITY
    printf("Using ARTIFICIAL VISCOSITY\n");
#endif
#ifdef FARGO
    printf("Using FARGO TRANSPORT\n");
#endif
#ifdef STOCKHOLMACC
    printf("Damping to current average in stockholm boundaries.\n");
#endif
#ifdef NOWAVEKILLRHO
    printf("Not damping the density.\n");
#endif
#ifdef FIXEDPSYS
    printf("Planetary system is FIXED.\n");
#endif
    printf("Starting time = %.3f\nEnding time = %.3f\n",tstart,tend);
    set_bc();

    set_dtLt(-1.0);

    while ((time < tend) && nsteps<MAXSTEPS) {
#ifdef FARGO
        compute_vmed(vx);
#endif
        dt = cfl();
        if (dt <= MINDT) {
            printf("Timestep has fallen below minimum!\n");
            break;
        }
        if (time + dt > tend) {
            dt = tend-time;
        }
        printf("\r t=%.3f, dt = %.8f,  %02d%% complete...",time,dt,(int)(100*(time-tstart)/(tend-tstart)));
        fflush(stdout);
        set_avg(0);
    
        potential();
        
#ifndef FIXEDPSYS
        move_planet();
#endif
    
       
        source_step();
       
        set_Lamex();
        viscosity();
#ifdef ARTIFICIALVISCOSITY
        
        artificial_visc();
#endif
    
        temp_to_vel();
        set_bc();
        
        vel_to_temp();
       
#ifdef FARGO
        compute_vmed(vx_temp);
#endif        
        transport_step();
        
        time += dt;
      
        set_avg(1);

        set_Lamdep();

        set_bc();
        stockholm();
        //output_psys(outputdir,nsteps);
        nsteps++;
    }
//    temp_to_vel();   

    set_dtLt(1.0);

    
    dt = tend - tstart;
    for(j=0;j<size_y;j++) {
        dbart[j]/=dt;
        //Lt[j]/=dt;
        //Lt[j+size_y]/=dt;
        //Ld[j]/=dt;
        //Ld[j+size_y]/=dt;
        //Lw[j]/=dt;
        //Lw[j+size_y]/=dt;
        Lw[j] = Lt[j] - Ld[j];
        Lw[j+size_y] = Lt[j+size_y] - Ld[j+size_y];
        drFt[j]/=dt;
        drFd[j]/=dt;
        drFdB[j]/=dt;
        mdotl[j]/=dt;
        drFnu[j]/=dt;
        drFw[j]/=dt;
        drFwB[j]/=dt;
        Lamex[j]/=dt;
        //Lamex[j+size_y]/=dt;
        Lamdep[j]/=dt;
        LamdepB[j]/=dt;
        dtLt[j]/=dt;
        dtLd[j]/=dt;
        dtLw[j]/=dt;
        dtLd_rhs[j]/=dt;
        mdotavg[j] /= dt;
        LamdepS[j + size_y*0] /= dt;
        LamdepS[j + size_y*1] /= dt;
        LamdepS[j + size_y*2] /= dt;
        LamdepS[j + size_y*3] /= dt;
        LamdepS[j + size_y*4] /= dt;
        LamdepS[j + size_y*5] /= dt;
        LamdepS[j + size_y*6] /= dt;
    }
    int mi;
    for(mi=1;mi<MMAX+2;mi++) {
        for(j=0;j<size_y;j++) {
            Lamex[j + size_y*mi] /= dt;
            drFd[j + size_y*mi] /= dt;
            dtLt[j + size_y*mi] /= dt;

        }
    }

    output(outputdir);
    output_torque(directory,n);
    output_torque(outputdir,n);
    free_rk5();
#ifdef _FFTW
    free_conv();
#endif
    //free_all();
    return 0;
}
Exemplo n.º 21
0
/*
 * Build the makefile from the skeleton
 */
void
makefile(void)
{
	FILE *ifp, *ofp;
	FILE *dfp;
	char pname[BUFSIZ];
	char line[BUFSIZ];
	struct opt *op;
	struct users *up;

	read_files();
	(void) sprintf(line, "%s/Makefile.template", config_directory);
	ifp = fopenp(VPATH, line, pname, "r");
	if (ifp == 0) {
		perror(line);
		exit(1);
	}
	dfp = fopen(path("Makefile"), "r");
	rename(path("Makefile"), path("Makefile.old"));
	unlink(path("Makefile.old"));
	unlink(path("M.d"));
	if ((ofp = fopen(path("M.d"), "w")) == NULL) {
		perror(path("M.d"));
		/* We'll let this error go */
	}
	else
	 	fclose(ofp);
	ofp = fopen(path("Makefile"), "w");
	if (ofp == 0) {
		perror(path("Makefile"));
		exit(1);
	}
	fprintf(ofp, "SOURCE_DIR=%s\n", source_directory);

	if (machine == MACHINE_SUN || machine == MACHINE_SUN2 
	    || machine == MACHINE_SUN3 || machine == MACHINE_SUN4)
		fprintf(ofp, "IDENT=-D%s -D%s", machinename, allCaps(ident));
	else
		fprintf(ofp, "IDENT=-D%s", allCaps(ident));
	if (profiling)
		fprintf(ofp, " -DGPROF");
	if (cputype == 0) {
		printf("cpu type must be specified\n");
		exit(1);
	}
	do_build("cputypes.h", build_cputypes);

	for (op = opt; op; op = op->op_next)
		if (op->op_value)
			fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
		else
			fprintf(ofp, " -D%s", op->op_name);
	fprintf(ofp, "\n");
	if ((unsigned)machine > NUSERS) {
		printf("maxusers config info isn't present, using vax\n");
		up = &users[MACHINE_VAX-1];
	} else
		up = &users[machine-1];
	if (maxusers < up->u_min) {
		maxusers = up->u_min;
	} else if (maxusers > up->u_max)
		printf("warning: maxusers > %d (%d)\n", up->u_max, maxusers);
	if (maxusers) {
		do_build("confdep.h", build_confdep);
	}
	for (op = mkopt; op; op = op->op_next)
		if (op->op_value)
			fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
		else
			fprintf(ofp, "%s\n", op->op_name);

	while (fgets(line, BUFSIZ, ifp) != 0) {
		if (*line == '%')
			goto percent;
		if (profiling && strncmp(line, "COPTS=", 6) == 0) {
			register char *cp;
			if (machine != MACHINE_MMAX)
			    fprintf(ofp,
				"GPROF.EX=$(SOURCE_DIR)/machdep/%s/gmon.ex\n", machinename);
			cp = index(line, '\n');
			if (cp)
				*cp = 0;
			cp = line + 6;
			while (*cp && (*cp == ' ' || *cp == '\t'))
				cp++;
			COPTS = malloc((unsigned)(strlen(cp) + 1));
			if (COPTS == 0) {
				printf("config: out of memory\n");
				exit(1);
			}
			strcpy(COPTS, cp);
			if (machine == MACHINE_MIPSY || machine == MACHINE_MIPS) {
				fprintf(ofp, "%s ${CCPROFOPT}\n", line);
				fprintf(ofp, "PCOPTS=%s\n", cp);
			} else if (machine == MACHINE_MMAX)
				fprintf(ofp, "%s -p\n",line);
			else
				fprintf(ofp, "%s -pg\n", line);
			continue;
		}
		fprintf(ofp, "%s", line);
		continue;
	percent:
		if (eq(line, "%OBJS\n")) {
			do_objs(ofp, "OBJS=", -1);
		} else if (eq(line, "%CFILES\n")) {
			do_files(ofp, "CFILES=", 'c');
			do_objs(ofp, "COBJS=", 'c');
		} else if (eq(line, "%MFILES\n")) {
			do_files(ofp, "MFILES=", 'm');
			do_objs(ofp, "MOBJS=", 'm');
		} else if (eq(line, "%SFILES\n")) {
			do_files(ofp, "SFILES=", 's');
			do_objs(ofp, "SOBJS=", 's');
		} else if (eq(line, "%BFILES\n"))
			do_files(ofp, "BFILES=", 'b');
		else if (eq(line, "%MACHDEP\n")) {
			/*
			 * Move do_machdep() after the mkopt stuff.
			 */
			for (op = mkopt; op; op = op->op_next)
				fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
			do_machdep(ofp);
		} else if (eq(line, "%ORDERED\n"))
			do_ordered(ofp);
		else if (eq(line, "%RULES\n"))
			do_rules(ofp);
		else if (eq(line, "%LOAD\n"))
			do_load(ofp);
		else
			fprintf(stderr,
			    "Unknown %% construct in generic makefile: %s",
			    line);
	}
	if (dfp != NULL)
	{
		copy_dependencies(dfp, ofp);
		(void) fclose(dfp);
	}
	(void) fclose(ifp);
	(void) fclose(ofp);
}
Exemplo n.º 22
0
EXPORT unsigned char *make_hash(metafile_t *m)
{
	queue_t q = {
		NULL, NULL, 0, 0,
		PTHREAD_MUTEX_INITIALIZER,
		PTHREAD_MUTEX_INITIALIZER,
		PTHREAD_COND_INITIALIZER,
		PTHREAD_COND_INITIALIZER,
		0, 0, 0
	};
	pthread_t print_progress_thread;	/* progress printer thread */
	pthread_t *workers;
	unsigned char *hash_string;		/* the hash string */
	unsigned int i;
	int err;

	workers = malloc(m->threads * sizeof(pthread_t));
	hash_string = malloc(m->pieces * SHA_DIGEST_LENGTH);
	if (workers == NULL || hash_string == NULL) {
		fprintf(stderr, "Out of memory.\n");
		exit(EXIT_FAILURE);
	}

	q.pieces = m->pieces;
	q.buffers_max = 3*m->threads;

	/* create worker threads */
	for (i = 0; i < m->threads; i++) {
		err = pthread_create(&workers[i], NULL, worker, &q);
		if (err) {
			fprintf(stderr, "Error creating thread: %s\n",
					strerror(err));
			exit(EXIT_FAILURE);
		}
	}

	/* now set off the progress printer */
	err = pthread_create(&print_progress_thread, NULL, print_progress, &q);
	if (err) {
		fprintf(stderr, "Error creating thread: %s\n",
				strerror(err));
		exit(EXIT_FAILURE);
	}

	/* read files and feed pieces to the workers */
	read_files(m, &q, hash_string);

	/* we're done so stop printing our progress. */
	err = pthread_cancel(print_progress_thread);
	if (err) {
		fprintf(stderr, "Error cancelling thread: %s\n",
				strerror(err));
		exit(EXIT_FAILURE);
	}

	/* inform workers we're done */
	set_done(&q);

	/* wait for workers to finish */
	for (i = 0; i < m->threads; i++) {
		err = pthread_join(workers[i], NULL);
		if (err) {
			fprintf(stderr, "Error joining thread: %s\n",
					strerror(err));
			exit(EXIT_FAILURE);
		}
	}

	free(workers);

	/* the progress printer should be done by now too */
	err = pthread_join(print_progress_thread, NULL);
	if (err) {
		fprintf(stderr, "Error joining thread: %s\n",
				strerror(err));
		exit(EXIT_FAILURE);
	}

	/* destroy mutexes and condition variables */
	pthread_mutex_destroy(&q.mutex_full);
	pthread_mutex_destroy(&q.mutex_free);
	pthread_cond_destroy(&q.cond_empty);
	pthread_cond_destroy(&q.cond_full);

	/* free buffers */
	free_buffers(&q);

	/* ok, let the user know we're done too */
	printf("\rHashed %u of %u pieces.\n", q.pieces_hashed, q.pieces);

	return hash_string;
}
Exemplo n.º 23
0
/*
 * Build the makefile from the skeleton
 */
void
makefile(void)
{
	FILE *ifp, *ofp;
	char line[BUFSIZ];
	struct opt *op;
	int versreq;

	read_files();
	snprintf(line, sizeof(line), "../platform/%s/conf/Makefile",
		 platformname);
	ifp = fopen(line, "r");
	if (ifp == NULL) {
		snprintf(line, sizeof(line), "Makefile.%s", platformname);
		ifp = fopen(line, "r");
	}
	if (ifp == NULL)
		err(1, "%s", line);
	ofp = fopen(path("Makefile.new"), "w");
	if (ofp == NULL)
		err(1, "%s", path("Makefile.new"));
	fprintf(ofp, "KERN_IDENT=%s\n", raisestr(ident));
	fprintf(ofp, "MACHINE_PLATFORM=%s\n", platformname);
	fprintf(ofp, "MACHINE=%s\n", machinename);
	fprintf(ofp, "MACHINE_ARCH=%s\n", machinearchname);
	fprintf(ofp, ".makeenv MACHINE_PLATFORM\n");
	fprintf(ofp, ".makeenv MACHINE\n");
	fprintf(ofp, ".makeenv MACHINE_ARCH\n");
	fprintf(ofp, "IDENT=");
	if (profiling)
		fprintf(ofp, " -DGPROF");

	if (cputype == 0) {
		printf("cpu type must be specified\n");
		exit(1);
	}
	fprintf(ofp, "\n");
	for (op = mkopt; op != NULL; op = op->op_next)
		fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
	if (debugging)
		fprintf(ofp, "DEBUG=-g\n");
	if (profiling) {
		fprintf(ofp, "PROF=-pg\n");
		fprintf(ofp, "PROFLEVEL=%d\n", profiling);
	}
	if (*srcdir != '\0')
		fprintf(ofp,"S=%s\n", srcdir);
	while (fgets(line, BUFSIZ, ifp) != 0) {
		if (*line != '%') {
			fprintf(ofp, "%s", line);
			continue;
		}
		if (strcmp(line, "%BEFORE_DEPEND\n") == 0)
			do_before_depend(ofp);
		else if (strcmp(line, "%OBJS\n") == 0)
			do_objs(ofp);
		else if (strcmp(line, "%MFILES\n") == 0)
			do_mfiles(ofp);
		else if (strcmp(line, "%CFILES\n") == 0)
			do_cfiles(ofp);
		else if (strcmp(line, "%SFILES\n") == 0)
			do_sfiles(ofp);
		else if (strcmp(line, "%RULES\n") == 0)
			do_rules(ofp);
		else if (strcmp(line, "%CLEAN\n") == 0)
			do_clean(ofp);
		else if (strncmp(line, "%VERSREQ=", sizeof("%VERSREQ=") - 1) == 0) {
			versreq = atoi(line + sizeof("%VERSREQ=") - 1);
			if (versreq != CONFIGVERS) {
				fprintf(stderr, "ERROR: version of config(8) does not match kernel!\n");
				fprintf(stderr, "config version = %d, ", CONFIGVERS);
				fprintf(stderr, "version required = %d\n\n", versreq);
				fprintf(stderr, "Make sure that /usr/src/usr.sbin/config is in sync\n");
				fprintf(stderr, "with your /usr/src/sys and install a new config binary\n");
				fprintf(stderr, "before trying this again.\n\n");
				fprintf(stderr, "If running the new config fails check your config\n");
				fprintf(stderr, "file against the GENERIC or LINT config files for\n");
				fprintf(stderr, "changes in config syntax, or option/device naming\n");
				fprintf(stderr, "conventions\n\n");
				exit(1);
			}
		} else
			fprintf(stderr,
			    "Unknown %% construct in generic makefile: %s",
			    line);
	}
	fclose(ifp);
	fclose(ofp);
	moveifchanged(path("Makefile.new"), path("Makefile"));
}
Exemplo n.º 24
0
/*
 * Build the makefile from the skeleton
 */
void
makefile(void)
{
	FILE *ifp, *ofp;
	FILE *dfp;
	char pname[BUFSIZ];
	char line[BUFSIZ];
	struct opt *op;

	read_files();
	(void) sprintf(line, "%s/Makefile.template", config_directory);
	ifp = fopenp(VPATH, line, pname, "r");
	if (ifp == 0) {
		perror(line);
		exit(1);
	}
	dfp = fopen(path("Makefile"), "r");
	rename(path("Makefile"), path("Makefile.old"));
	unlink(path("Makefile.old"));
	ofp = fopen(path("Makefile"), "w");
	if (ofp == 0) {
		perror(path("Makefile"));
		exit(1);
	}
	fprintf(ofp, "SOURCE_DIR=%s\n", source_directory);

	fprintf(ofp, "export CONFIG_DEFINES =");
	if (profiling)
		fprintf(ofp, " -DGPROF");

	for (op = opt; op; op = op->op_next)
		if (op->op_value)
			fprintf(ofp, " -D%s=\"%s\"", op->op_name, op->op_value);
		else
			fprintf(ofp, " -D%s", op->op_name);
	fprintf(ofp, "\n");
	for (op = mkopt; op; op = op->op_next)
		if (op->op_value)
			fprintf(ofp, "%s=%s\n", op->op_name, op->op_value);
		else
			fprintf(ofp, "%s\n", op->op_name);

	while (fgets(line, BUFSIZ, ifp) != 0) {
		if (*line == '%')
			goto percent;
		if (profiling && strncmp(line, "COPTS=", 6) == 0) {
			register char *cp;
			fprintf(ofp,
				"GPROF.EX=$(SOURCE_DIR)/machdep/%s/gmon.ex\n", machinename);
			cp = index(line, '\n');
			if (cp)
				*cp = 0;
			cp = line + 6;
			while (*cp && (*cp == ' ' || *cp == '\t'))
				cp++;
			COPTS = malloc((unsigned)(strlen(cp) + 1));
			if (COPTS == 0) {
				printf("config: out of memory\n");
				exit(1);
			}
			strcpy(COPTS, cp);
			fprintf(ofp, "%s -pg\n", line);
			continue;
		}
		fprintf(ofp, "%s", line);
		continue;
	percent:
		if (eq(line, "%OBJS\n")) {
			do_objs(ofp, "OBJS=", -1);
		} else if (eq(line, "%CFILES\n")) {
			do_files(ofp, "CFILES=", 'c');
			do_objs(ofp, "COBJS=", 'c');
		} else if (eq(line, "%CXXFILES\n")) {
			do_files(ofp, "CXXFILES=", 'p');
			do_objs(ofp, "CXXOBJS=", 'p');
		} else if (eq(line, "%SFILES\n")) {
			do_files(ofp, "SFILES=", 's');
			do_objs(ofp, "SOBJS=", 's');
		} else if (eq(line, "%MACHDEP\n")) {
			do_machdep(ofp);
		} else if (eq(line, "%RULES\n"))
			do_rules(ofp);
		else
			fprintf(stderr,
			    "Unknown %% construct in generic makefile: %s",
			    line);
	}
	if (dfp != NULL)
	{
		copy_dependencies(dfp, ofp);
		(void) fclose(dfp);
	}
	(void) fclose(ifp);
	(void) fclose(ofp);
}