Example #1
0
File: p67.c Project: ipeet/euler
int main() {
	read_f();
	
	unsigned int i, j;
	unsigned int lvls_dn = TRI_SZ;	
	unsigned int tri_max[TRI_SZ][TRI_SZ];
	
//	printf("\nPropagating maxima up tree...\n");
	//First pass, max known at leaves are leaves.
//	printf("%02d: ",(lvls_dn-1));
	for(i=0;i<lvls_dn;++i) {
		tri_max[lvls_dn-1][i] = tri[lvls_dn-1][i];
//		if(i<20) printf("%02d ",tri_max[lvls_dn-1][i]);
	}
//	printf("\n");
	
	//Now, propagate maxima back up to the top of the tree.
	for(i=lvls_dn-1;i-->0;) {
//		printf("%d: ",i);
		for(j=0;j<=i;++j) {
			if( tri_max[i+1][j] > tri_max[i+1][j+1] ) {
				tri_max[i][j] = tri[i][j] + tri_max[i+1][j];
			} else {
				tri_max[i][j] = tri[i][j] + tri_max[i+1][j+1];
			}
//			if(j<20) printf("%02d ",tri_max[i][j]);
//			else if(j==20) printf("...");
		}
//		printf("\n");
	}
	printf("Maximum: %d\n",tri_max[0][0]);
	
	return 0;
}
Example #2
0
File: main.c Project: SarginD/st211
int main(int argc, char *argv[])  // name of file with instruction // first string after name of program
{
	int *status; 
	char program[MAXLEN];
	float *delay = (float *)malloc(sizeof(float));

	FILE *input = fopen(argv[1], "r");  
	assert(input != NULL);
	

	

	while (read_f(input, program, delay) != 0)
	{
		int pid = fork();
		
		if (pid == -1) 
		{
			perror("Fork returned -1, process was not created\n");
		}
		else
		{
			if (pid == 0) //Doughter process
			{
				sleep(delay[0]);
//  FIXME: these is wrong use of execve! you should pass argvs to the program!
//  FIXME: commands in the list are not time sorted!
				execve(program, NULL, NULL);
				perror("Program was not executed\n");
			}
			else  //Parent process
			{
				//return to fork
			}
		}
	}
//	FIXME: you should use &status to tell the compiler where to put the result, it is not an array!!
//  FIXME: every process created should wait for child to finish. You have their pids, so move it to parent process
	waitpid(-1, status, 0);


	return 0;
}
Example #3
0
uint32_t access_ReadBlock(cad_access_module *self, FILE *f, char *blockName, 
				bool (* read_f)(cad_access_module *self, char *str, cad_scheme *s, cad_route_map *map), 
				cad_scheme *s, cad_route_map *map)
{
	int BUFFER_SIZE = cad_access_module_private::BUFFER_SIZE;
	char *buffer = self->sys->buffer;
	char *utf8Hack = buffer;

	do {
		if ( fgets(buffer, BUFFER_SIZE, f) == NULL )
			return E_NOT_FOUND;
		utf8Hack = ( *(unsigned short *)buffer) == 0xBBEF ? buffer + 3 : buffer; 
	} while( memcmp(utf8Hack, blockName, sizeof( blockName )) != 0 );
	
	while ( 1 ) 
	{
		if ( fgets(buffer, BUFFER_SIZE, f) == NULL ) return E_OK; // end of file
		if ( buffer[0] == '\n' ) return E_OK; // end of block
		if ( buffer[0] == '#') continue; // comment
		if (! read_f(self, buffer, s, map) ) return E_ERROR; 
	}
}
Example #4
0
static int read_obj(const char *filename, struct object *o)
{
    char L[MAXSTR];
    char W[MAXSTR];
    FILE *fin;

    int i, j, n = 0;

    /* Initialize the object element vectors. */

    vector_t vv = o->vv = vecnew(0, sizeof (struct object_vert));
    vector_t mv = o->mv = vecnew(0, sizeof (struct object_mesh));

    if (filename)
    {
        path_push(get_file_path(filename));

        /* Initialize the loader vector caches. */

        _uv = vecnew(1024, sizeof (struct vec2));
        _nv = vecnew(1024, sizeof (struct vec3));
        _vv = vecnew(1024, sizeof (struct vec3));

        uerr = nerr = verr = 0;

        if ((fin = open_file(get_file_name(filename), "r")))
        {
            /* Create a default catch-all group using the default material. */

            struct object_mesh *m = read_usemtl(mv, NULL, NULL);
            const char         *F = NULL;
        
            /* Process each line, invoking the handler for each keyword. */

            while (fgets(L, MAXSTR, fin))
                if (sscanf(L, "%s%n", W, &n) >= 1)
                {
                    char *V = L + n;

                    if      (!strcmp(W, "mtllib")) F = read_mtllib(mv, V);
                    else if (!strcmp(W, "usemtl")) m = read_usemtl(mv, V, F);

                    else if (!strcmp(W, "f"))  read_f(vv, m->fv, V);
                    else if (!strcmp(W, "l"))  read_l(vv, m->ev, V);

                    else if (!strcmp(W, "vt")) read_vt(V);
                    else if (!strcmp(W, "vn")) read_vn(V);
                    else if (!strcmp(W, "v" )) read_v (V);
                }
            
            fclose(fin);
        }
        else error("OBJ file '%s': %s", filename, system_error());

        /* Remove any empty meshes. */

        for (i = 0; i < vecnum(o->mv); )
            if (vecnum(((struct object_mesh *) vecget(o->mv, i))->fv) ||
                vecnum(((struct object_mesh *) vecget(o->mv, i))->ev))
                i++;
            else
            {
                memmove(vecget(o->mv, i),
                        vecget(o->mv, i + 1),
                       (vecnum(o->mv) - i - 1) * sizeof (struct object_mesh));
                vecpop(o->mv);
            }

        /* Compute tangent and bitangent vectors. */

        calc_tbn(o);

        /* Sort meshes such that transparent ones appear last. */

        for (i = 0; i < vecnum(o->mv); ++i)
            for (j = i + 1; j < vecnum(o->mv); ++j)
            {
                struct object_mesh *mi = vecget(o->mv, i);
                struct object_mesh *mj = vecget(o->mv, j);
                struct object_mesh  mt;

                if (get_brush_t(mi->brush) > get_brush_t(mj->brush))
                {
                     mt = *mi;
                    *mi = *mj;
                    *mj =  mt;
                }
            }

        /* Release the loader caches. */

        vecdel(_vv);
        vecdel(_nv);
        vecdel(_uv);

        /* Report index errors. */

        if (uerr > 0)
            error("OBJ file '%s' has %d bad texture indices", filename, uerr);
        if (nerr > 0)
            error("OBJ file '%s' has %d bad normal indices",  filename, nerr);
        if (verr > 0)
            error("OBJ file '%s' has %d bad vertex indices",  filename, verr);

        path_pop();
    }
    return 1;
}
Example #5
0
/*
 * process message
 */
void process_message( void )
{
  unsigned long type, length, body[sizeof(struct ConfigWinPacket)];

  read_f( Fdr, (char*)&type, SOL);
  read_f( Fdr, (char*)&length, SOL);
  read_f( Fdr, (char*)body, length );

  if( type==M_ERROR )
  {
    fprintf( stderr,"%s", (char *)&body[3] );
  }
  else if( Opt_info >= 1 )
  {
    switch( type )
    {

    case M_WINDOW_NAME:
      list( body, "window");
      break;
    case M_ICON_NAME:
      list(body, "icon");
      break;
    case M_RES_CLASS:
      list(body, "class" );
      break;
    case M_RES_NAME:
      list(body, "resource");
      break;

    case M_END_WINDOWLIST:
      list_string("end windowlist");
      break;

    case M_ICON_FILE:
      list(body, "icon file");
      break;
    case M_ICON_LOCATION:
      list_icon_loc(body);
      break;

    case M_END_CONFIG_INFO:
      list_string("end configinfo");
      break;

    case M_DEFAULTICON:
      list(body, "default icon");
      break;

    case M_MINI_ICON:
      list_mini_icon( body );
      break;

    case M_CONFIG_INFO:
      printf( "%s\n", (char *)&body[3] );
      break;

    case MX_REPLY:
      list(body, "reply");
      break;

    default:
      if( Opt_info >=2 )
      {
	switch(type)
	{

	case M_CONFIGURE_WINDOW:
	  list_configure( body);
	  break;
	case M_STRING:
	  list(body, "string");
	  break;

	default:
	  if( Opt_info >= 3 )
	  {
	    switch( type )
	    {
	    case M_NEW_PAGE:
	      list_new_page(body);
	      break;
	    case M_NEW_DESK:
	      list_new_desk(body);
	      break;
	    case M_ADD_WINDOW:
	      list_header(body, "add");
	      list_configure( body);
	      break;
	    case M_RAISE_WINDOW:
	      list_header(body, "raise");
	      break;
	    case M_LOWER_WINDOW:
	      list_header(body, "lower");
	      break;
	    case M_FOCUS_CHANGE:
	      list_focus_change( body );
	      break;
	    case M_DESTROY_WINDOW:
	      list_header(body, "destroy");
	      break;
	    case M_ICONIFY:
	      list_iconify( body );
	      break;
	    case M_DEICONIFY:
	      list_header(body, "deiconify");
	      break;
	    case M_MAP:
	      list_header(body, "map");
	      break;
	    case M_WINDOWSHADE:
	      list_header(body, "windowshade");
	      break;
	    case M_DEWINDOWSHADE:
	      list_header(body, "dewindowshade");
	      break;
	    default:
	      printf("0x%lx type 0x%lx\n", body[0], type );
	    }
	  }
	}
      }
    }
  }
}