Example #1
0
Oligo * read_oligo_list ( char *fname)
    {
    Oligo *O;
    FILE *fp;
    int a, b;
    

    
    O=vcalloc (1, sizeof (Oligo));
    O->ALPHABET=vcalloc ( 100, sizeof (char));
    O->EALPHABET=vcalloc ( 100, sizeof (char));
    O->AMBIGUITIES=vcalloc ( 100, sizeof (char));
    
    fp=vfopen ( fname, "r");
    fscanf ( fp, "ALPHABET %s\n", O->ALPHABET);
    fscanf ( fp, "AMBIG_ALPHABET %s\n", O->AMBIGUITIES);
    if ( O->AMBIGUITIES[0]=='@')O->AMBIGUITIES[0]='\0';
    fscanf ( fp, "WORD_SIZE %d\n", &O->WSIZE);
    fscanf ( fp, "NSEQ %d\n", &O->NSEQ);
    fscanf ( fp, "LEN %d\n", &O->LEN);
    fscanf ( fp, "SCORE %d", &a);
    sprintf ( O->EALPHABET, "%s%s", O->ALPHABET, O->AMBIGUITIES);
   
    O->seq=declare_char ( O->NSEQ, O->LEN+1);
    for ( a=0; a< O->NSEQ; a++)
	{
	fscanf ( fp, "%*s\n%s\n",O->seq[a]);
	}
    vfclose (fp);
    return O;
    }
Example #2
0
int main (int argc, char const * argv []) 

{ 
	static char const * optv [] = 
	{ 
		"c:w:x", 
		PUTOPTV_S_FILTER, 
		"extend FORTRAN style comment bars", 
		"c c\tcomments start with character c [" LITERAL (FBAR_START) "]", 
		"w n\tbar width is (n) [" LITERAL (FBAR_WIDTH) "]", 
		"x\tmake file executable", 
		(char const *) (0)
	}; 
	flag_t flags = (flag_t) (0); 
	size_t length = _LINESIZE; 
	size_t width = FBAR_WIDTH; 
	char start = FBAR_START; 
	char space = FBAR_SPACE; 
	signed c; 
	while (~ (c = getoptv (argc, argv, optv))) 
	{ 
		switch (c) 
		{ 
		case 'c': 
			start = (char) (* optarg); 
			break; 
		case 'x': 
			_setbits (flags, FBAR_EXECUTE); 
			break; 
		case 'w': 
			width = uintspec (optarg, 0, length); 
			break; 
		default: 
			break; 
		} 
	} 
	argc -= optind; 
	argv += optind; 
	if (!argc) 
	{ 
		function (start, space, width, length, flags); 
	} 
	while ((argc) && (* argv)) 
	{ 
		if (vfopen (* argv)) 
		{ 
			function (start, space, width, length, flags); 
			if (_anyset (flags, FBAR_EXECUTE)) 
			{ 
				if (chmod (* argv, 0755)) 
				{ 
					error (0, errno, "can't chmod %s", * argv); 
				} 
			} 
		} 
		argc--; 
		argv++; 
	} 
	exit (0); 
} 
Example #3
0
void identify_operating_system ( Parameter *PARAM)
	{
	char command[1000];
	FILE *fp;
	char os[100];
	char fname[100];
	int a;
	
	a=addrand((unsigned long)10000);
	
	sprintf ( fname, "os_%d", a);
	sprintf ( command, "echo $OSTYPE>%s", fname);
	system ( command);
	fp=vfopen ( fname, "r");
	fscanf ( fp, "%s", os);
	fclose ( fp);
	sprintf ( command , "rm %s", fname);
	system ( command);
	
	if ( (strcmp (os, "irix")==0) || (strcmp (os, "IRIX")==0)) 
		sprintf ( PARAM->OS, "_sgi");
	else if ( (strcmp (os, "osf1")==0) || (strcmp (os, "OSF1")==0)) 
		sprintf ( PARAM->OS, "_osf");
	else 
		{
		crash("COULD NOT GET OS");
		}
	fprintf ( stderr, "\nOPERATING_SYSTEM: %s\n",PARAM->OS); 
	}	
Example #4
0
int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		"prepend/append prefix/suffix to multiple files",
		PUTOPTV_S_FILTER,
		"p:qs:v",
		"p s\tprefix file is (s)",
		"q\tquiet mode",
		"s s\tsuffix file is (s)",
		"v\tverbose mode",
		(char const *) (0)
	};
	flag_t flags = (flag_t) (0);
	signed length = 1024;
	signed prefix = -1;
	signed suffix = -1;
	signed c;
	while (~ (c = getoptv (argc, argv, optv)))
	{
		switch (c)
		{
		case 'h':
			if ((prefix = open (optarg, O_RDONLY)) == -1)
			{
				error (1, errno, "%s", optarg);
			}
			break;
		case 'f':
			if ((suffix = open (optarg, O_RDONLY)) == -1)
			{
				error (1, errno, "%s", optarg);
			}
			break;
		case 'q':
			_setbits (flags, PREAMBLE_SILENCE);
			break;
		case 'v':
			_setbits (flags, PREAMBLE_VERBOSE);
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (! argc)
	{
		function (prefix, suffix, length);
	}
	while ((argc) && (* argv))
	{
		if (vfopen (* argv))
		{
			function (prefix, suffix, length);
		}
		argc--;
		argv++;
	}
	exit (0);
}
Mixture * read_dirichlet ( char *name)
	{
	FILE *fp;
	int a,b, c;
	float f;	
	Mixture *D;


	D=vcalloc ( 1, sizeof (Mixture));
	
	
	D->N_COMPONENT=9;
	D->ALPHA=vcalloc (9, sizeof (double*));
	for ( a=0; a< 9; a++)
		D->ALPHA[a]=vcalloc (20, sizeof (double));
	D->DM_Q=vcalloc (9, sizeof (double));
	
	if (name!=NULL)
	  {
	    fp=vfopen ( name, "r");
	    for ( a=0; a< 9; a++)
		{
		fscanf(fp, "%f\n", &f);
		D->DM_Q[a]=(double)f;
		fscanf(fp, "%f", &f);
		
		for ( b=0; b<20; b++)
			{
			fscanf(fp, "%f", &f);
			D->ALPHA[a][b]=(double)f;
			}
		fscanf(fp, "\n");
		}
	    for ( a=0; a< 9; a++)
	      {
		fprintf(stderr, "\n%f\n",(float)D->DM_Q[a] );
		
		for ( b=0; b<20; b++)
		  {
		    fprintf(stderr, "%f ", (float)D->ALPHA[a][b]);
		  }
		fprintf(stderr, "\n");
	      }
	    fprintf ( stderr, "\nN_C=%d",D->N_COMPONENT );	
	    vfclose ( fp);
	  }
	else
	  {
	    for (c=0, a=0; a< 9;a++)
	      {
		D->DM_Q[a]=dm[c++];	
		for (b=0; b<20; b++)
		  D->ALPHA[a][b]=dm[c++];
	      }
	  }
	
	return D;
	}
Example #6
0
/* FUNCTION: call_script_ctx()
 *
 * Execute commands from a script file.
 *   - A new GIO struct is pushed onto the GIO stack.
 *   - The input stream is set to the script file
 *   - The output stream is "null" of echo_out is FALSE.
 *   - Commands are parsed and executed until EOF is reached.
 *
 * PARAM1: CLI_CTX            current CLI context
 * PARAM2: void *             script name or memory address
 * PARAM3: int                input type: file or memory
 * PARAM4: bool_t             TRUE = echo commands to output stream
 * PARAM5: bool_t             FALSE = suppress command output
 * PARAM6: bool_t             TRUE = abort script on first error
 *
 * RETURN: int                0 or error code
 */
int
call_script_ctx(CLI_CTX ctx, void *cmdset, int type,
                bool_t echo_in, bool_t echo_out, bool_t halt)
{
   GIO   *gio = ctx->gio;
   VFILE *fd; 
   int   rtn;

   switch (type)
   {
   case CMDSFROMFILE:
      if ((fd = vfopen((char *)cmdset, "r")) == (VFILE *)NULL)
      {
/*       gio_printf(gio, "file not found: %s\n", cmdset); */
         return (ENP_NOFILE);
      }
      else
      {
         /* input = file */
         if ((rtn = GIO_PUSH_FILE(&ctx->gio, fd, GIO_RD)) != GIO_DONE)
         {
            vfclose(fd);
            return (rtn);
         }
         gio = ctx->gio;      /* update gio descriptor */

         /* if echo_out == FALSE, redirect output to "null" */
         if (!echo_out)
         {
            GIO_NULL(gio, GIO_WR);
         }

         /* set the GIO_F_ECHO flag if we are echoing commands */
         if (echo_in)
            gio->flags |= GIO_F_ECHO;
         else
            gio->flags &= ~GIO_F_ECHO;

         rtn = do_script(ctx, halt);

         vfclose(fd);         /* close the file */
         gio_pop(&ctx->gio);  /* destroy the script context */
      }   
      break;  
   
   case CMDSFROMMEM:
      /* not yet implemented */

   default:
      dtrap();                /* unknown script type */
      rtn = CLI_ERR_FATAL;
      break;
   }

   return (rtn);
}
Example #7
0
int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		"align character to column",
		PUTOPTV_S_FILTER,
		"a:b:c:t:",
		"a n\tafter column (n)",
		"b n\tbefore column (n)",
		"c c\talignment character (c)",
		"t n\talignment column (n)",
		(char const *) (0)
	};
	unsigned minimum = 0;
	unsigned maximum = -1;
	unsigned character = 0;
	unsigned column = 0;
	signed c;
	while (~ (c = getoptv (argc, argv, optv)))
	{
		switch (c)
		{
		case 'a':
			minimum = uintspec (optarg, 0, SHRT_MAX);
			break;
		case 'b':
			maximum = uintspec (optarg, 0, SHRT_MAX);
			break;
		case 'c':
			character = * optarg;
			break;
		case 't':
			column = uintspec (optarg, 0, SHRT_MAX);
			break;
		default: 
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (! argc)
	{
		function (minimum, maximum, column, character);
	}
	while ((argc) && (* argv))
	{
		if (vfopen (* argv))
		{
			function (minimum, maximum, column, character);
		}
		argc--;
		argv++;
	}
	exit (0);
}
Example #8
0
int main (int argc, char const * argv []) 

{ 
	extern signed order; 
	static char const * optv [] = 
	{ 
		"b:dl:", 
		PUTOPTV_S_FILTER, 
		"sort files", 
		"b n\tmaximum sort block is (n) lines [0x1000]", 
		"d\tarrange output in descending order", 
		"l n\tmaximum line length is (n) bytes [0x0400]", 
		(char const *) (0)
	}; 
	size_t heapsize = _HEAPSIZE; 
	size_t linesize = _LINESIZE; 
	signed c; 
	while (~ (c = getoptv (argc, argv, optv))) 
	{ 
		switch (c) 
		{ 
		case 'd': 
			order = - 1; 
			break; 
		case 'b': 
			heapsize = uintspec (optarg, 1, UINT_MAX); 
			break; 
		case 'l': 
			linesize = uintspec (optarg, 1, UINT_MAX); 
			break; 
		default: 
			break; 
		} 
	} 
	argc -= optind; 
	argv += optind; 
	if (!argc) 
	{ 
		function (heapsize, linesize); 
	} 
	while ((argc) && (* argv)) 
	{ 
		if (vfopen (* argv)) 
		{ 
			function (heapsize, linesize); 
		} 
		argc--; 
		argv++; 
	} 
	exit (0); 
} 
Example #9
0
int main(int argc, char *argv[])
{
#if VFS_USING_C_API // <- This will be defined if VFS_ENABLE_C_API is on and the ttvfs overrides are in use.
    ttvfs::Root vfs;
    vfs.AddLoader(new ttvfs::DiskLoader);

    ttvfs_setroot(&vfs); // The C-like API supports only one (global) root object.
                         // Must be set before calling any of the functions,
                         // and must stay alive and unchanged while any VFILEs are opened.
    puts("Using VFS");
#else
    puts("Not using VFS");
#endif

    VFILE *fh = vfopen("myfile.txt", "r");
    if(!fh)
    {
        puts("ERROR: File not found: myfile.txt");
        return 1;
    }

    char buf[513];
    size_t bytes = vfread(buf, 1, 512, fh);
    buf[bytes] = 0;
    puts(buf);

    vfclose(fh);

    //----------------------------------

    InStream strm("mydata.txt");
    if(strm)
    {
        // The below is mostly copied from example #3
        unsigned int i, line = 0;
        float f;
        std::string s;
        while(true)
        {
            ++line;
            strm >> s >> i >> f; // we may hit EOF, causing any of the reads to fail
            if(!strm) // after reading, check if line was read in completely
                break;
            std::cout << "Line " << line << ": String '" << s << "', int " << i <<  ", float " << f << std::endl;
        }
        strm.close();
    }

    return 0;
}
Example #10
0
void save_current_operator ( Parameter *PARAM, char *experience_name, int gen)
    {
    FILE *fp;
    static char *fname;
    int a;

    if ( (PARAM->BGA)->OUTPUT_CURRENT_OPERATOR_FILE==0)
	return;

    if ( fname==NULL)
	{
	fname=vmalloc ( sizeof(char)*100);
	sprintf ( fname, "current_operator_%s.saga", experience_name);
	fp=vfopen (fname, "w");
	fprintf ( fp, "#%d", (PARAM->DOS)->TOT_OPERATOR);
	fclose(fp);
	}

    fp=vfopen ( fname, "a");
    fprintf (fp, "\nG%d", gen);
    for ( a=0; a< (PARAM->DOS)->TOT_OPERATOR; a++)
	fprintf ( fp, "\n[%2d][%15s] : %d", a, (PARAM->DOS)->OP_NAME[a],(PARAM->DOS)->current_fitness[a][0]);
    fclose ( fp);
    }
Example #11
0
bool TiXmlDocument::LoadFile( const char* _filename, TiXmlEncoding encoding )
{
	TIXML_STRING filename( _filename );
	value = filename;

	// reading in binary mode so that tinyxml can normalize the EOL
	VFILE* file = vfopen( value.c_str (), "rb" );

	if ( file )
	{
		bool result = LoadFile( file, encoding );
		vfclose( file );
		return result;
	}
	else
	{
		SetError( TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN );
		return false;
	}
}
Example #12
0
int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		"C/C++ language blocker",
		PUTOPTV_S_FILTER,
		"p",
		"p\tinsert empty function preambles",
		(char const *) (0)
	};
	signed c;
	while (~ (c = getoptv (argc, argv, optv)))
	{
		switch (c)
		{
		case 'p':
			level = 0;
			break;
		default: 
			break;
		}
	}
	argc -= optind;
	argv += optind;
	if (! argc)
	{
		program (NUL, EOF);
	}
	while ((argc) && (* argv))
	{
		if (vfopen (* argv))
		{
			program (NUL, EOF);
		}
		argc--;
		argv++;
	}
	return (0);
}
Example #13
0
void save_analyse_operator ( int gen, Parameter *PARAM)
    {
    FILE *fp;
    static int instant;
    char fname1[200];
    char fname2[200];
    int a;
    int tot_op;
    int tot_similar_p;
    int	tot_better_p;
    int	tot_integrated;
    int	P_tot_similar_p;
    int	P_tot_better_p;
    int	P_tot_integrated;    
    
    
    sprintf ( fname1, "IOA_%s.saga", (PARAM->BGA)->experience_name);
    sprintf ( fname2, "TOA_%s.saga", (PARAM->BGA)->experience_name);

    if (instant==0)
	{
	instant=1;
	fp=vfopen ( fname1, "w");
	fprintf ( fp, "\n1-number times op used\n2-number times child=parent\n3-number times child better than parent\n4-number times child integrated");
	fprintf ( fp, "\nGEN 0:");
	}
    else 
	{
	fp=vfopen ( fname1, "a");
	fprintf ( fp, "\nGEN %d:", gen);
	}

    for ( a=0; a< (PARAM->DOS)->TOT_OPERATOR; a++)
	{
	tot_op=(PARAM->DOS)->IOPUSE[a][0];
	tot_similar_p=(PARAM->DOS)->IOPUSE[a][1];
	tot_better_p=(PARAM->DOS)->IOPUSE[a][2];
	tot_integrated=(PARAM->DOS)->IOPUSE[a][3];
	P_tot_similar_p= (tot_op>0)?((tot_similar_p*100)/tot_op):100;
	P_tot_better_p=(tot_op>0)?((tot_better_p*100)/tot_op):100;
	P_tot_integrated= (tot_op>0)?((tot_integrated*100)/tot_op):100;

	fprintf ( fp, "\n%-25s%4d:[100]**%4d:[%-3d]**4%d:[%-3d]**%4d:[%-3d]",(PARAM->DOS)->OP_NAME[a], tot_op, tot_similar_p,P_tot_similar_p, tot_better_p, P_tot_better_p,tot_integrated, P_tot_integrated);      
	}
    fclose ( fp);

    fp=vfopen ( fname2, "w");
    fprintf ( fp, "\n1-number times op used\n2-number times child=parent\n3-number times child better than parent\n4-number times child integratedn\nGEN %d:", gen);
    for ( a=0; a< (PARAM->DOS)->TOT_OPERATOR; a++)
	{
	tot_op=(PARAM->DOS)->OPUSE[a][0];
	tot_similar_p=(PARAM->DOS)->OPUSE[a][1];
	tot_better_p=(PARAM->DOS)->OPUSE[a][2];
	tot_integrated=(PARAM->DOS)->OPUSE[a][3];
	P_tot_similar_p= (tot_op>0)?((tot_similar_p*100)/tot_op):100;
	P_tot_better_p=(tot_op>0)?((tot_better_p*100)/tot_op):100;
	P_tot_integrated=(tot_op>0)?((tot_integrated*100)/tot_op):100;

	fprintf ( fp, "\n%-25s%4d:[100]**%4d:[%-3d]**%4d:[%-3d]**%4d:[%-3d]",(PARAM->DOS)->OP_NAME[a], tot_op, tot_similar_p,P_tot_similar_p, tot_better_p, P_tot_better_p,tot_integrated, P_tot_integrated);      
	}
    fclose ( fp);

    }
Example #14
0
void save_individual (Chromosome *A,char *name, int generation, Parameter *PARAM)
       {
	 FILE *fp;
	 char best_file[100];
	 int a,c,b,d;
	 int line=60;
	 struct tms time_buf[1];
	 int tot;
	 int sec;
	 int min;
	 int hour;
	 char buf[100];
	 int tot_sec;
	 char fname[100];
	 char text [2000];
         char btext [2000];
	 
	 times (time_buf);
	 tot=(time_buf->tms_cutime+time_buf->tms_utime)+-(PARAM->BGA)->ref_time;

	 tot_sec=sec= tot/100;
	 min= sec/60;
	 sec= sec- min*60;
	 hour= min/60;
	 min= min - hour*60;
	
	 if ((PARAM->BGA)->OUTPUT_CPU_FILE==1 && name!=NULL)
	 	{
	 	sprintf ( fname, "%s_cpu.saga", name);
	 	fp=vfopen ( fname, "w");
	 	fprintf ( fp, "%d", tot_sec);
	 	fclose ( fp);
	 	}
	 if ((PARAM->BGA)->OUTPUT_SCORE_FILE==1 && name!=NULL)
	 	{	
	 	sprintf ( fname, "%s_score.saga", name);
	 	fp=vfopen ( fname, "w");
	 	fprintf( fp, "%d", (int)A->score);
	 	fclose ( fp);
		}
	 if ((PARAM->BGA)->OUTPUT_GENERATION_FILE==1 && name!=NULL)
	 	{ 
	 	sprintf ( fname, "%s_generation.saga", name);
	 	fp=vfopen ( fname, "w");
	 	fprintf( fp, "%d", generation);
	 	fclose ( fp);
   		}
   		
	
	 
	 sprintf ( text, "Total time : %d hour %d min %d sec\n", hour, min, sec);
	 sprintf (btext, "Random Seed= %d\n", (PARAM->BGA)->RANDOM_SEED);
	 strcat ( text, btext);
	 sprintf (btext, "Reference score=%d\n",((PARAM->BGA)->REFERENCE)?(int)((PARAM->BGA)->REFERENCE)->score:-1);
	 strcat ( text, btext);
	 sprintf (btext, "Score=%d\n", (int)A->score);
	 strcat ( text, btext);
	 sprintf (btext, "Generation=%d\n", generation);
	 	 
	 make_ga_output ( name, text,NULL,A, PARAM);
	 }
Example #15
0
int
ftp_log(void * pio)
{

   FC_MENULOG();
   if (log_flag==TRUE)
   {
      /* Logging is enabled. Disable it */
      log_flag=FALSE;
#ifdef FC_LOGFILE
      if (ftplog)
      {
         ns_printf(pio, "Logging to file disabled\n");
         vfclose((VFILE *)fc_file_io.id);
      }
      else
#endif   /*FC_LOGFILE */
      ns_printf(pio, "Logging to STDIO disabled\n");
   }
   else
   {
      /* Logging is disabled. Enable it. If an argument is passed, 
       * then it is name of logfile. Hence enable logging to file. If 
       * no argument is passed, then enable logging to stdio. 
       */
#ifdef FC_LOGFILE
      char *   filename=NULL;
      GEN_IO   io= (GEN_IO) pio ;
      VFILE *  fp;
#endif   /*FC_LOGFILE */

      log_flag=TRUE;
      ftplog   =NULL;   /* By default log to stdio */     

#ifdef FC_LOGFILE
      /* extract args from command buffer */
      if ( io != NULL )
      {
         filename = nextarg(io->inbuf);
         if(*filename != 0)   /* user passed file name */
         {
            fp=vfopen(filename, "w");
            if (fp==NULL)
            {
               ns_printf(pio, "Can't open file %s.", filename);
            }
            else
            {
               fc_file_io.id  = (long)fp;
               ftplog   =  &fc_file_io;
            }
         }
      }

      if (ftplog)
         ns_printf(pio, "Logging to file %s enabled\n", filename);
      else
#endif   /*FC_LOGFILE */
      ns_printf(pio, "Logging to STDIO enabled\n");
   }

   return   0;
}
Example #16
0
int main (int argc, char const * argv []) 

{ 
	static char const * optv [] = 
	{ 
		"c:mw:x", 
		PUTOPTV_S_FILTER, 
		"extend script style comment bars", 
		"c c\tcomments start with character (c) [" LITERAL (FBAR_START) "]", 
		"m\tshift comments to left margin", 
		"w n\tmake bars n characters wide [" LITERAL (FBAR_WIDTH) "]", 
		"x\tmake files executable", 
		(char const *) (0)
	}; 
	flag_t flags = (flag_t) (0); 
	size_t width = SBAR_WIDTH; 
	char start = SBAR_START; 
	char space = SBAR_SPACE; 
	signed c; 
	while (~ (c = getoptv (argc, argv, optv))) 
	{ 
		switch (c) 
		{ 
		case 'c': 
			start = (char) (* optarg); 
			break; 
		case 'm': 
			_setbits (flags, SBAR_B_SHIFT); 
			break; 
		case 'x': 
			_setbits (flags, SBAR_B_EXECUTE); 
			break; 
		case 'w': 
			width = uintspec (optarg, 0, 255); 
			break; 
		default: 
			break; 
		} 
	} 
	argc -= optind; 
	argv += optind; 
	if (!argc) 
	{ 
		function (start, space, width, flags); 
	} 
	while ((argc) && (* argv)) 
	{ 
		if (vfopen (* argv)) 
		{ 
			if (flags & SBAR_B_EXECUTE) 
			{ 
				if (chmod (* argv, 0755)) 
				{ 
					error (0, errno, "can't chmod %s", * argv); 
				} 
			} 
			function (start, space, width, flags); 
		} 
		argc--; 
		argv++; 
	} 
	exit (0); 
} 
Example #17
0
int main (int argc, char const * argv [])

{
	static char const * optv [] =
	{
		"rename a C Language variable or constant",
		PUTOPTV_S_FILTER,
		"co:n:",
		"c\treport changes",
		"o s\told token is s",
		"n s\tnew token is s",
		(char const *) (0)
	};
	flag_t flags = (flag_t) (0);
	char const * oldname = "";
	char const * newname = "";
	char const * sp;
	signed c;
	while (~ (c = getoptv (argc, argv, optv)))
	{
		switch (c)
		{
		case 'c':
			_setbits (flags, CEDIT_COUNT);
			break;
		case 'o':
			oldname = optarg;
			break;
		case 'n':
			newname = optarg;
			break;
		default: 
			break;
		}
	}
	if (! oldname)
	{
		error (1, EINVAL, "No old name given");
	}
	for (sp = oldname; * sp; sp++)
	{
		if (! isalnum (* sp) && (* sp != '_'))
		{
			error (1, EINVAL, "%s is not a variable or constant name", oldname);
		}
	}
	if (sp == oldname)
	{
		error (1, EINVAL, "Old name is empty");
	}
	if (! newname)
	{
		error (1, EINVAL, "No new name given");
	}
	for (sp = newname; * sp; sp++)
	{
		if (! isalnum (* sp) && (* sp != '_'))
		{
			error (1, EINVAL, "%s is not a variable or constant name", newname);
		}
	}
	if (sp == newname)
	{
		error (1, EINVAL, "New name  is empty");
	}
	argc -= optind;
	argv += optind;
	if (! argc)
	{
		if ((c = function (oldname, newname)))
		{
			if (_anyset (flags, CEDIT_COUNT))
			{
				fprintf (stderr, "stdin %d\n", c);
			}
		}
	}
	while ((argc) && (* argv))
	{
		if (vfopen (* argv))
		{
			if ((c = function (oldname, newname)))
			{
				if (_anyset (flags, CEDIT_COUNT))
				{
					fprintf (stderr, "%s %d\n", * argv, c);
				}
			}
		}
		argc--;
		argv++;
	}
	exit (0);
}
Example #18
0
void print_result_ga ( Population *L_POP,int G, Statistic * L_STAT, int generation, Parameter *PARAM)    
     {
     static Chromosome *A;
     Decoded_chromosome *DA;
     static previous_score;
     static N_GEN;
     static int first;		
     FILE *fp;
     char fname[1000];
     static io_pld_score;
     static static_x;
     
     DA=get_mem_free_decoded_chrom(PARAM);
     if ( A==NULL)
	{A=(PARAM->MEM)->C1;
	 sprintf ( fname,"bilan_%s.saga",(PARAM->BGA)->experience_name);
	 if ( (PARAM->BGA)->OUTPUT_BILAN_FILE==1)
	 	{
	 	fp=vfopen ( fname, "w");
	 	fclose ( fp);
		}
	}
 
     sprintf (fname, "gbest_%s",(PARAM->BGA)->experience_name);
     
    
	
    first=1;
	   
    extract_chrom (L_POP,G,L_STAT->best_gen_chrom,A, PARAM);
    decode_chromosome(A, DA, PARAM);		    		    
    copy_chromosome ( A, L_STAT->BEST_GEN_CHROMOSOME, PARAM);
    copy_decoded_chromosome ( DA, L_STAT->BEST_GEN_DECODED_CHROMOSOME, PARAM);
	    				
    if ( (PARAM->BGA)->OUTPUT_GEN_BEST_FILE==1)save_individual (A,fname,generation, PARAM);
		
    if (a_better_than_b(L_STAT->score_gen_best,previous_score,(PARAM->BGA)->GA_MAXIMISE )|| previous_score==0 || ((PARAM->BGA)->EVALUATE_ONLY==1))
		{
		save_individual (A,NULL,generation, PARAM);
		copy_decoded_chromosome ( DA, L_STAT->BEST_DECODED_CHROMOSOME, PARAM);
		copy_chromosome ( A, L_STAT->BEST_CHROMOSOME, PARAM);
		}	 	 
    previous_score= L_STAT->score_gen_best;
    N_GEN=0;

     sprintf ( fname,"bilan_%s.saga",(PARAM->BGA)->experience_name );
     if ( ((PARAM->BGA)->OUTPUT_BILAN_FILE)==1)
	{
	fp=vfopen (fname,"a");
	fprintf ( fp,"\nGEN=%d\tBEST=%d\tMEAN=%d\tSD=%d", generation,L_STAT->score_gen_best,L_STAT->mean, L_STAT->SD);
	fclose ( fp);
	}	
     
     fprintf ((PARAM->std2),"\nGEN=%d\tBEST=%d\tMEAN=%d\tSD=%d", generation,L_STAT->score_gen_best,L_STAT->mean, L_STAT->SD);    
     
     fprintf ((PARAM->std1),"%c", (io_pld_score==L_STAT->score_gen_best)?'=':'*');
     io_pld_score=L_STAT->score_gen_best;
     if ( static_x==30)
     	{
     	fprintf ((PARAM->std1),"[G%d %d]\n",generation,L_STAT->score_gen_best);
     	static_x=0;
     	}
     static_x++;
     
     free_mem_dc(DA, PARAM);
     }
Example #19
0
/*
 *   Now our virtualfont routine.
 */
Boolean
virtualfont P1C(register fontdesctype *, curfnt)
{
#ifdef Omega
   register integer i ;
#else
   register shalfword i ;
#endif
   register shalfword cmd ;
   register integer k ;
   register integer length ;
#ifdef Omega
   register integer cc ;
#else
   register shalfword cc ;
#endif
   register chardesctype *cd ;
   integer scaledsize = curfnt->scaledsize ;
#ifdef Omega
   integer no_of_chars=256;
   integer maxcc=0;
   chardesctype *newchardesc;
#endif
   register quarterword *tempr ;
   fontmaptype *fm, *newf ;
#ifdef Omega
   integer kindfont;
   kindfont=vfopen(curfnt);  /* 1 for TeX, 2 for Omega */
   if (!kindfont)
      return (0) ;
#else
   if (!vfopen(curfnt))
      return (0) ;
#endif
#ifdef DEBUG
   if (dd(D_FONTS))
      (void)fprintf(stderr,"Loading virtual font %s at %.1fpt\n",
         name, (real)scaledsize/(alpha*0x100000)) ;
#endif /* DEBUG */

/*
 *   We clear out some pointers:
 */
#ifdef Omega
   if (kindfont==2) {
     no_of_chars = 65536;
     curfnt->maxchars=65536;
     free(curfnt->chardesc);
     curfnt->chardesc = (chardesctype *)
                        mymalloc(65536 * (integer)sizeof(chardesctype));
   }
   for (i=0; i<no_of_chars; i++) {
#else
   for (i=0; i<256; i++) {
#endif
      curfnt->chardesc[i].TFMwidth = 0 ;
      curfnt->chardesc[i].packptr = NULL ;
      curfnt->chardesc[i].pixelwidth = 0 ;
      curfnt->chardesc[i].flags = 0 ;
      curfnt->chardesc[i].flags2 = 0 ;
   }
   if (vfbyte()!=247)
      badvf("expected pre") ;
   if (vfbyte()!=202)
      badvf("wrong id byte") ;
   for(i=vfbyte(); i>0; i--)
      (void)vfbyte() ;
   k = vfquad() ;
   check_checksum (k, curfnt->checksum, curfnt->name);
   k = (integer)(alpha * (real)vfquad()) ;
   if (k > curfnt->designsize + 2 || k < curfnt->designsize - 2) {
      (void)sprintf(errbuf,"Design size mismatch in font %s", name) ;
      error(errbuf) ;
   }
/*
 * Now we look for font definitions.
 */
   fm = NULL ;
   while ((cmd=vfbyte())>=243) {
      if (cmd>246)
         badvf("unexpected command in preamble") ;
      newf = vfontdef(scaledsize, cmd-242) ;
      if (fm)
         fm->next = newf ;
      else curfnt->localfonts = newf ;
      fm = newf ;
      fm->next = NULL ; /* FIFO */
   }
/*
 *   Now we get down to the serious business of reading character definitions.
 */
   do {
      if (cmd==242) {
         length = vfquad() + 2 ;
         if (length<2) badvf("negative length packet") ;
         if (length>65535) badvf("packet too long") ;
         cc = vfquad() ;
#ifdef Omega
         if (cc<0 || cc>65535) badvf("character code out of range") ;
#else
         if (cc<0 || cc>255) badvf("character code out of range") ;
#endif
         cd = curfnt->chardesc + cc ;
         cd->TFMwidth = scalewidth(vfquad(), scaledsize) ;
      } else {
         length = cmd + 2;
         cc = vfbyte() ;
         cd = curfnt->chardesc + cc ;
         cd->TFMwidth = scalewidth(vftrio(), scaledsize) ;
      }
#ifdef Omega
      maxcc = (maxcc<cc) ? cc : maxcc;
#endif
      if (cd->TFMwidth >= 0)
         cd->pixelwidth = ((integer)(conv*cd->TFMwidth+0.5)) ;
      else
         cd->pixelwidth = -((integer)(conv*-cd->TFMwidth+0.5)) ;
      cd->flags = EXISTS ;
      cd->flags2 = EXISTS ;
      if (bytesleft < length) {
#ifdef DEBUG
          if (dd(D_MEM))
             (void)fprintf(stderr,
#ifdef SHORTINT
                   "Allocating new raster memory (%ld req, %ld left)\n",
#else
                   "Allocating new raster memory (%d req, %ld left)\n",
#endif
                                length, bytesleft) ;
#endif /* DEBUG */
          if (length > MINCHUNK) {
             tempr = (quarterword *)mymalloc((integer)length) ;
             bytesleft = 0 ;
          } else {
             raster = (quarterword *)mymalloc((integer)RASTERCHUNK) ;
             tempr = raster ;
             bytesleft = RASTERCHUNK - length ;
             raster += length ;
         }
      } else {
         tempr = raster ;
         bytesleft -= length ;
         raster += length ;
      }
      cd->packptr = tempr ;
      length -= 2 ;
      *tempr++ = length / 256 ;
      *tempr++ = length % 256 ;
         for (; length>0; length--)
            *tempr++ = vfbyte() ;
      cmd = vfbyte() ;
   } while (cmd < 243) ;
   if (cmd != 248)
      badvf("missing postamble") ;
   (void)fclose(vffile) ;
   curfnt->loaded = 2 ;
#ifdef Omega
   newchardesc = (chardesctype *)
                 mymalloc((maxcc+1) * (integer)sizeof(chardesctype));
   for (i=0; i<=maxcc; i++) {
     newchardesc[i] = curfnt->chardesc[i];
   }
   free(curfnt->chardesc);
   curfnt->chardesc = newchardesc;
   curfnt->maxchars=maxcc+1;
#endif
   return (1) ;
}
Example #20
0
int main (int argc, char const * argv []) 

{ 
	extern FIND find; 
	static char const * optv [] = 
	{ 
		"e:p:x", 
		PUTOPTV_S_FILTER, 
		"insert shell bang path header", 
		"e s\tpathname defined by environement variable s", 
		"p s\tpathname string is s", 
		"x\tmake file executable", 
		(char const *) (0)
	}; 
	char const * pathname = ""; 
	flag_t flags = (flag_t) (0); 
	size_t length = _LINESIZE; 
	signed c; 
	while (~ (c = getoptv (argc, argv, optv))) 
	{ 
		switch (c) 
		{ 
		case 'e': 
			if ((pathname = getenv (optarg)) == (char *)(0)) 
			{ 
				error (1, errno, "symbol %s not defined", optarg); 
			} 
			break; 
		case 't': 
			if ((pathname = getenv ("CMTOOLS")) == (char *)(0)) 
			{ 
				error (1, errno, "symbol CMTOOLS is undefined"); 
			} 
			break; 
		case 'p': 
			pathname = optarg; 
			break; 
		case 'x': 
			_setbits (flags, SHBANG_EXECUTE); 
			break; 
		default: 
			break; 
		} 
	} 
	argc -= optind; 
	argv += optind; 
	if (!argc) 
	{ 
		function (& find, length, flags); 
	} 
	while ((argc) && (* argv)) 
	{ 
		makefind (& find, * argv); 
		if (vfopen (find.fullname)) 
		{ 
			if ((!pathname) || (!* pathname)) 
			{ 
				strcpy (find.pathname, pathname); 
			} 
			strcat (find.pathname, PATH_S_EXTENDER); 
			strcat (find.pathname, find.filename); 
			function (& find, length, flags); 
			if (_anyset (flags, SHBANG_EXECUTE)) 
			{ 
				if (chmod (find.fullname, 0755)) 
				{ 
					error (0, errno, "can't chmod %s", find.fullname); 
				} 
			} 
		} 
		argc--; 
		argv++; 
	} 
	exit (0); 
}