/* Prepare tree display for inclusion in the article header.
*/
void
init_tree()
{
    ARTICLE *thread;
    SUBJECT *sp;
    int num;

    while (max_line >= 0)		/* free any previous tree data */
	free(tree_lines[max_line--]);

    if (!(tree_article = curr_artp) || !tree_article->subj)
	return;
    if (!(thread = tree_article->subj->thread))
	return;
    /* Enumerate our subjects for display */
    sp = thread->subj;
    num = 0;
    do {
	sp->misc = num++;
	sp = sp->thread_link;
    } while (sp != thread->subj);

    max_depth = max_line = my_depth = my_line = node_line_cnt = 0;
    find_depth(thread, 0);

    if (max_depth <= 5) {
	first_depth = 0;
    } else {
	if (my_depth+2 > max_depth) {
	    first_depth = max_depth - 5;
	} else if ((first_depth = my_depth - 3) < 0) {
	    first_depth = 0;
	}
	max_depth = first_depth + 5;
    }
    if (--max_line < max_tree_lines) {
	first_line = 0;
    } else {
	if (my_line + max_tree_lines/2 > max_line) {
	    first_line = max_line - (max_tree_lines-1);
	} else if ((first_line = my_line - (max_tree_lines-1)/2) < 0) {
	    first_line = 0;
	}
	max_line = first_line + max_tree_lines-1;
    }

    str = tree_buff;		/* initialize first line's data */
    *str++ = ' ';
    node_on_line = FALSE;
    line_num = 0;
    /* cache our portion of the tree */
    cache_tree(thread, 0, tree_indent);

    max_depth = (max_depth-first_depth) * 5;	/* turn depth into char width */
    max_line -= first_line;			/* turn max_line into count */
    /* shorten tree if lower lines aren't visible */
    if (node_line_cnt < max_line) {
	max_line = node_line_cnt + 1;
    }
}
int find_depth(BTree *tree, depth)
{
	int left_depth;
	int right_depth;

	if (tree->left == NULL && tree->right == NULL)
		return depth;
	else if (tree->right == NULL)
		return find_depth(tree->left, depth++);
	else if (tree->left == NULL)
		return find_depth(tree->right, depth++);
	left_depth = find_depth(tree->left, depth + 1);
	right_depth = find_depth(tree->right, depth + 1);
	if (left_depth <= right_depth)
		return right_depth;
	return left_depth;
}
int btree_depth(BTree *tree)
{
	int depth = 0;

	if (tree == NULL)
		return -1;
	return find_depth(tree, depth);
}
void Dectree_class::find_depth(dectree_node* ptr)
{
	if(ptr != NULL)
	{
		find_depth(ptr->f);

		if(!((ptr->type).compare("terminal")))
		{
			if(ptr->depth > max_depth)
				max_depth = ptr->depth;
			if(ptr->depth < min_depth)
				min_depth = ptr->depth;
		}
		
		find_depth(ptr->t);
	}
	
}
示例#5
0
static cairo_surface_t *
create_source_surface (int size)
{
#if CAIRO_HAS_XCB_SURFACE
    xcb_render_pictforminfo_t *render_format;
    struct closure *data;
    cairo_surface_t *surface;
    xcb_screen_t *root;
    xcb_void_cookie_t cookie;
    void *formats;

    data = xmalloc (sizeof (struct closure));

    data->connection = xcb_connect (NULL, NULL);
    render_format = find_depth (data->connection, 32, &formats);
    if (render_format == NULL) {
	xcb_disconnect (data->connection);
	free (data);
	return NULL;
    }

    root = xcb_setup_roots_iterator (xcb_get_setup (data->connection)).data;

    data->pixmap = xcb_generate_id (data->connection);
    cookie = xcb_create_pixmap_checked (data->connection, 32,
					data->pixmap, root->root, size, size);
    /* slow, but sure */
    if (xcb_request_check (data->connection, cookie) != NULL) {
	free (formats);
	xcb_disconnect (data->connection);
	free (data);
	return NULL;
    }

    surface = cairo_xcb_surface_create_with_xrender_format (data->connection,
							    root,
							    data->pixmap,
							    render_format,
							    size, size);
    free (formats);

    data->device = cairo_device_reference (cairo_surface_get_device (surface));
    cairo_surface_set_user_data (surface, &closure_key, data, cleanup);

    return surface;
#else
    return NULL;
#endif
}
void Dectree_class::train(const cv::Mat& training_data, const cv::Mat& labels, int depth_thresh, unsigned int samples_thresh)
{
	//determine the number of classes based on the training data
	get_classes(labels);
	//std::cout << "Classes:\n" << classes << std::endl;
	//make a vector giving an id to each attribute
	set_attributes(training_data);
	//for debbugging
	/*
	for(std::vector<int>::iterator it = attributes.begin(); it != attributes.end(); ++it)
		std::cout << *it << " ";
	std::cout << std::endl;
	*/
	//compute the initial impurity just fot debugging
	//double hgoal = compute_entropy(labels);
	//std::cout << "Initial entropy: " << hgoal << std::endl;
	//grow a decision tree
	depth_limit = depth_thresh;
	min_samples = samples_thresh;
	int depth = 1;
	dbst.set_root(learn_dectree(cv::Mat(),labels, training_data, attributes, depth));
	find_depth(dbst.get_root());
	std::cout << "min depth: " << min_depth << std::endl;
	//for debugging
	//print the obtained tree
	/*
	std::cout<< "\ninOrder traversal: " << std::endl;
	dbst.inOrder(dbst.get_root());
	std::cout << std::endl;
	std::cout<< "\npostOrder traversal: " << std::endl;
	dbst.postOrder(dbst.get_root());	
	std::cout << std::endl;
	*/

	//only for testing
	/*
	int a = plurality(labels);
	std::cout << "Best class: " << a << std::endl;
	bool b = check_classif(labels);
	std::cout << "All same class?: " << b << std::endl;
	dectree_split* t = best_split(attributes, training_data, labels);
	std::cout << "Best attr: " << t->attr_name << " Pos: " << t->attr_idx << std::endl;
	std::cout << t->neg_attr_labels << std::endl;
	std::cout << t->neg_attr_data << std::endl;
	std::cout << t->pos_attr_labels << std::endl;
	std::cout << t->pos_attr_data << std::endl;
	*/
}
//main method to train the decision treee
void Dectree_class::train(const cv::Mat& training_data, const cv::Mat& labels, int depth_thresh, unsigned int samples_thresh, int vars_per_node)
{
	//---(1)initialize random generator if no external is given---//
	if(!is_ext_rng)
	{
		rng = cv::RNG(time(NULL));
		//std::cout << "No ext rng" << std::endl;
	}

	//---(2)determine the number of classes based on the training data---//
	set_classes(labels);
	//std::cout << "Classes:\n" << classes << std::endl;

	//---(3)make a vector giving an id to each attribute---//
	set_attributes(training_data);
	//for debbugging
	/*
	for(std::vector<int>::iterator it = attributes.begin(); it != attributes.end(); ++it)
		std::cout << *it << " ";
	std::cout << std::endl;
	*/

	//---(4)verify constraints---//
	//maximum depth
	if(depth_thresh < 0)
		depth_limit = std::numeric_limits<int>::max();
	else
		depth_limit = depth_thresh;
	//minimum samples
	min_samples = samples_thresh;
	//active variables
	if(attributes.size() < (unsigned)vars_per_node)
		active_vars = attributes.size();
	else
		active_vars = vars_per_node;
	//maximum number of split fails
	max_split_fail = attributes.size();

	//---(5)train the tree---//
	int depth = 1;
	int no_split_fail = 0;
	dbst.set_root(learn_dectree(cv::Mat(),labels, training_data, depth, no_split_fail));
	find_depth(dbst.get_root()); //to find the real-true depth of the created tree

}
示例#8
0
int
main (int argc, char ** argv)
{
  int numloops = 0;
  int fpstimer;
  double a1, a2;
  tolerance_file_t * tol = get_tolerance ("colors.tol");
  memset (tol, '\0', sizeof (tolerance_file_t));
  int do_blob = -1;
  int do_text = -1;
  Uint8 mouse_button;
  SDL_Surface * image;
  SDL_Surface * image_2;
  SDL_Surface * screen;
  SDL_Surface * back = IMG_Load ("back.png");
  SDL_Color white = {255, 255, 255};
  SDL_Event event;
  char * jpeg_buff;
  char * jpeg_buff_2;
  int jpeg_buff_size;
  int jpeg_buff_size_2;
  int x, y;
  FILE * log_fp;
  blob * cam1_green;
  blob * cam1_red;
  blob * cam2_green;
  blob * cam2_red;
  blob * vision_targets = NULL;
  CvCapture * capture;
  CvCapture * capture_2;
  IplImage * cam_img;
  IplImage * cam_img_2;
  FILE * color_fp;
  if (SDL_Init (SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) {
    SDL_Quit ();
    printf ("SDL Initialization failed\n");
    exit (1);
  }
  if ((screen = SDL_SetVideoMode (800, 600, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_FULLSCREEN )) == NULL) {
    SDL_Quit ();
    printf ("Could not create output surface\n");
    exit (1);
  }
  if (TTF_Init () == -1) {
    SDL_Quit ();
    printf ("TTF_Init: %s\n", TTF_GetError());
    exit (1);
  }
  if (!(capture = cvCaptureFromCAM (0))) {
    SDL_Quit ();
    printf ("Failed to start capture\n");
    exit (1);
  }
  if (!(capture_2 = cvCaptureFromCAM (1))) {
    SDL_Quit ();
    printf ("Failed to start capture\n");
    exit (1);
  }
  int start = SDL_GetTicks ();
  int lastfps;
  TTF_Font * arial = TTF_OpenFont ("arial.ttf", 12);
  while (1) {
    fpstimer = SDL_GetTicks ();
    numloops++;
    if (fpstimer - start > 1000) {
      start = SDL_GetTicks ();
      lastfps = numloops;
      numloops = 0;
    }
    while (SDL_PollEvent (&event)) {
      switch (event.type) {
        case SDL_KEYDOWN:
          switch (event.key.keysym.sym) {
            case 'q':
              TTF_Quit ();
              SDL_Quit ();
              exit (0);
            break;
            case 'b':
              do_blob = -do_blob;
            break;
            case 'v':
              do_text = -do_text;
            break;
            case 'i':
              tol->cam1_green.blob_minlength++;
            break;
            case 'k':
              tol->cam1_green.blob_minlength--;
            break;
            case 'o':
              tol->cam1_green.blob_tolerance++;
            break;
            case 'l':
              tol->cam1_green.blob_tolerance--;
            break;
            case 'y':
              tol->cam1_red.blob_minlength++;
            break;
            case 'h':
              tol->cam1_red.blob_minlength--;
            break;
            case 'u':
              tol->cam1_red.blob_tolerance++;
            break;
            case 'j':
              tol->cam1_red.blob_tolerance--;
            break;
            case 'w':
              tol->cam2_green.blob_minlength++;
            break;
            case 's':
              tol->cam2_green.blob_minlength--;
            break;
            case 'e':
              tol->cam2_green.blob_tolerance++;
            break;
            case 'd':
              tol->cam2_green.blob_tolerance--;
            break;
            case 'r':
              tol->cam2_red.blob_minlength++;
            break;
            case 'f':
              tol->cam2_red.blob_minlength--;
            break;
            case 't':
              tol->cam2_red.blob_tolerance++;
            break;
            case 'g':
              tol->cam2_red.blob_tolerance--;
            break;
            case 'z':
              color_fp = fopen ("colors.tol", "wb");
              fwrite (tol, sizeof (tolerance_file_t), 1, color_fp);
              fclose (color_fp);
            break;
          }
        break;
        case SDL_MOUSEBUTTONDOWN:
          mouse_button = SDL_GetMouseState (&x,&y);
          if (mouse_button & SDL_BUTTON(1)) {
            if (x > 352) {
              set_tracking (x, y, screen, &(tol->cam2_green));
            }
            else {
              set_tracking (x, y, screen, &(tol->cam1_green)); 
            }
          }
          else {
            if (x > 352) {
              set_tracking (x, y, screen, &(tol->cam2_red));
            }
            else {
              set_tracking (x, y, screen, &(tol->cam1_red)); 
            }
          }
        break;
      }
    }
    cam_img = cvQueryFrame (capture);
    image = ipl_to_surface (cam_img);
    cam_img_2 = cvQueryFrame (capture_2);
    image_2 = ipl_to_surface (cam_img_2);
    easy_blit (0, 0, back, screen);
    if (do_blob == 1) {
      cam1_green = find (image, &(tol->cam1_green));
      cam1_red = find (image, &(tol->cam1_red));
      cam2_green = find (image_2, &(tol->cam2_green));
      cam2_red = find (image_2, &(tol->cam2_red));
      vision_targets = target (cam1_red, cam1_green, ALLIANCE_BLUE);
      print_blobs_lighter (image, cam1_green, 0, 150, 0);
      print_blobs_lighter (image, cam1_red, 150, 0, 0);
      print_blobs_lighter (image_2, cam2_green, 0, 150, 0);
      print_blobs_lighter (image_2, cam2_red, 150, 0, 0);
      if (vision_targets != NULL) {
        render_text (screen, arial, 100, 490, "Found target!");
        print_blobs (image, vision_targets, 0, 0, 0);
        free_blobs (vision_targets);
      }
    }
    if (do_text == 1) {
      render_text (screen, arial, 600, 308, "FPS: %d", (lastfps));
      //print_blobs (image_2, cam2_red, 0, 0, 0);
      render_text (screen, arial, 10, 308, "Hotkey list:");
      render_text (screen, arial, 20, 328, "i - increase left green blob minimum length: %d", tol->cam1_green.blob_minlength);
      render_text (screen, arial, 20, 348, "k - decrease left green blob minimum length");
      render_text (screen, arial, 20, 368, "o - increase left green check tolerance: %d", tol->cam1_green.blob_tolerance);
      render_text (screen, arial, 20, 388, "l - decrease left green check tolerance");
      render_text (screen, arial, 20, 408, "y - increase left red blob minimum length: %d", tol->cam1_red.blob_minlength);
      render_text (screen, arial, 20, 428, "h - decrease left red blob minimum length");
      render_text (screen, arial, 20, 448, "u - increase left red check tolerance: %d", tol->cam1_red.blob_tolerance);
      render_text (screen, arial, 20, 468, "j - decrease left red check tolerance");
      render_text (screen, arial, 50, 508, "Green check color: %d, %d, %d", tol->cam1_green.r, tol->cam1_green.g, tol->cam1_green.b);
      SPG_RectFilled (screen, 20, 500, 40, 520, SDL_MapRGB (screen->format, tol->cam1_green.r, tol->cam1_green.g, tol->cam1_green.b));
      render_text (screen, arial, 50, 548, "Red check color: %d, %d, %d", tol->cam1_red.r, tol->cam1_red.g, tol->cam1_red.b);
      SPG_RectFilled (screen, 20, 540, 40, 560, SDL_MapRGB (screen->format, tol->cam1_red.r, tol->cam1_red.g, tol->cam1_red.b));
      render_text (screen, arial, 320, 328, "w - increase right green blob minimum length: %d", tol->cam2_green.blob_minlength);
      render_text (screen, arial, 320, 348, "s - decrease right green blob minimum length");
      render_text (screen, arial, 320, 368, "e - increase right green check tolerance: %d", tol->cam2_green.blob_tolerance);
      render_text (screen, arial, 320, 388, "d - decrease right green check tolerance");
      render_text (screen, arial, 320, 408, "r - increase right red blob minimum length: %d", tol->cam2_red.blob_minlength);
      render_text (screen, arial, 320, 428, "f - decrease right red blob minimum length");
      render_text (screen, arial, 320, 448, "t - increase right red check tolerance: %d", tol->cam2_red.blob_tolerance);
      render_text (screen, arial, 320, 468, "g - decrease right red check tolerance");
      render_text (screen, arial, 350, 508, "Green check color: %d, %d, %d", tol->cam2_green.r, tol->cam2_green.g, tol->cam2_green.b);
      SPG_RectFilled (screen, 320, 500, 340, 520, SDL_MapRGB (screen->format, tol->cam2_green.r, tol->cam2_green.g, tol->cam2_green.b));
      render_text (screen, arial, 350, 548, "Red check color: %d, %d, %d", tol->cam2_red.r, tol->cam2_red.g, tol->cam2_red.b);
      SPG_RectFilled (screen, 320, 540, 340, 560, SDL_MapRGB (screen->format, tol->cam2_red.r, tol->cam2_red.g, tol->cam2_red.b));
      if ((cam1_green != NULL) && (cam2_green != NULL)) {
        a1 = image_angle (cam1_green->center_x);
        a2 = image_angle (cam2_green->center_x);
        render_text (screen, arial, 580, 348, "Image 1 centroid: %d, %d", cam1_green->center_x, cam1_green->center_y);
        render_text (screen, arial, 580, 368, "Image 2 centroid: %d, %d", cam2_green->center_x, cam2_green->center_y);
        render_text (screen, arial, 580, 388, "Depth, Method 1: %f", find_depth (a1, a2, 0));
        render_text (screen, arial, 580, 408, "Depth, Method 2: %f", find_depth (a1, a2, 1));
        render_text (screen, arial, 580, 428, "Depth, Method 3: %f", find_depth (a1, a2, 2));
        render_text (screen, arial, 580, 448, "Angle, Left: %f", a1 * (180/PI));
        render_text (screen, arial, 580, 468, "Angle, Right: %f", a2 * (180/PI));
        SPG_RectFilled (screen, 780, (int)(35 * find_depth (a1, a2, 2)) - 300, 800, 20 + (int)(35 * find_depth (a1, a2, 1)) - 300, SDL_MapRGB (screen->format, tol->cam2_green.r, tol->cam2_green.g, tol->cam2_green.b));
      }
    }
    if (do_blob == 1) {
      free_blobs (cam1_green);
      free_blobs (cam1_red);
      free_blobs (cam2_green);
      free_blobs (cam2_red);
    }
    easy_blit (0, 0, image, screen);
    easy_blit (352, 0, image_2, screen);
    SDL_FreeSurface (image);
    SDL_FreeSurface (image_2);
    SDL_Flip (screen);
    log_fp = fopen ("colors.tol", "wb");
    fwrite (&tol, sizeof (tolerance_file_t), 1, log_fp);
    fclose (log_fp);
  }
  return 0;
}
示例#9
0
static cairo_surface_t *
_cairo_boilerplate_xcb_create_render_0_0 (const char		    *name,
					  cairo_content_t	     content,
					  double		     width,
					  double		     height,
					  double		     max_width,
					  double		     max_height,
					  cairo_boilerplate_mode_t   mode,
					  int			     id,
					  void			   **closure)
{
    xcb_screen_t *root;
    xcb_target_closure_t *xtc;
    xcb_connection_t *c;
    xcb_render_pictforminfo_t *render_format;
    int depth;
    xcb_void_cookie_t cookie;
    cairo_surface_t *surface, *tmp;
    cairo_status_t status;
    void *formats;

    *closure = xtc = xmalloc (sizeof (xcb_target_closure_t));

    if (width == 0)
	width = 1;
    if (height == 0)
	height = 1;

    xtc->c = c = xcb_connect(NULL,NULL);
    if (xcb_connection_has_error(c)) {
	free (xtc);
	return NULL;
    }

    root = xcb_setup_roots_iterator(xcb_get_setup(c)).data;

    xtc->surface = NULL;
    xtc->is_pixmap = TRUE;
    xtc->drawable = xcb_generate_id (c);
    switch (content) {
    case CAIRO_CONTENT_COLOR:
	depth = 24;
	cookie = xcb_create_pixmap_checked (c, depth,
					    xtc->drawable, root->root,
					    width, height);
	break;

    case CAIRO_CONTENT_COLOR_ALPHA:
	depth = 32;
	cookie = xcb_create_pixmap_checked (c, depth,
					    xtc->drawable, root->root,
					    width, height);
	break;

    case CAIRO_CONTENT_ALPHA:  /* would be XCB_PICT_STANDARD_A_8 */
    default:
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    /* slow, but sure */
    if (xcb_request_check (c, cookie) != NULL) {
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    render_format = find_depth (c, depth, &formats);
    if (render_format == NULL) {
	xcb_disconnect (c);
	free (xtc);
	return NULL;
    }

    tmp = cairo_xcb_surface_create_with_xrender_format (c, root,
							xtc->drawable,
							render_format,
							width, height);
    if (cairo_surface_status (tmp)) {
	free (formats);
	xcb_disconnect (c);
	free (xtc);
	return tmp;
    }

    xtc->device = cairo_device_reference (cairo_surface_get_device (tmp));
    cairo_xcb_device_debug_cap_xrender_version (xtc->device, 0, 0);

    /* recreate with impaired connection */
    surface = cairo_xcb_surface_create_with_xrender_format (c, root,
							    xtc->drawable,
							    render_format,
							    width, height);
    free (formats);
    cairo_surface_destroy (tmp);

    assert (cairo_surface_get_device (surface) == xtc->device);

    status = cairo_surface_set_user_data (surface, &xcb_closure_key, xtc, NULL);
    if (status == CAIRO_STATUS_SUCCESS)
	return surface;

    cairo_surface_destroy (surface);

    _cairo_boilerplate_xcb_cleanup (xtc);
    return cairo_boilerplate_surface_create_in_error (status);
}
示例#10
0
/**
* @brief 
*	Function to open a specific file mentioned in the path 
*	based on the incoming modes
* @param file_path
*	Pointer to the location of the file path string
* @param flags
*	Flags indicating the modes in which the file is to be opened
*
* @return Non-zero:File descriptor of the opened file
	  Zero    :File open is unsuccessful
*/
int file_open(const char *file_path,int flags)
{
	const char *path = file_path;
	const char *temp_path,*delim_strt;
	char shrt_file_name[SHRT_FILE_NAME_LEN];
	char long_file_name[LONG_FILE_NAME_LEN];
	int len = 0,fl_des = 0,crt_flag,i;
	int delim_cnt = 0;
	int mode;
        int extn_len_cnt = 0;
	int seq_num = 1;
	bool is_file_found;
	dir_entry *entry = NULL;
	file_info *info;
	u8 *pwd = root_directory;
	u32 strt_cluster = rt_dir_strt_clus;
	bool is_long_file_name = false;	

	sw_memset(long_file_name,SPACE_VAL,LONG_FILE_NAME_LEN);
	delim_cnt = find_depth(file_path);
	
	path = file_path;
	for(i=0;i<delim_cnt;i++){
		if(*path == DELIMITER){
			delim_strt = path;
			path++;
		}
		while((*path != EXTN_DELIMITER) && (*path != '\0') 
			&& (*path != DELIMITER) && (len < LONG_FILE_NAME_LEN)){
			long_file_name[len] = *path; 
			path++; 
			len++;
		}
		temp_path = path;
		if(*temp_path == EXTN_DELIMITER){
			temp_path++;
			while(*temp_path != DELIMITER && *temp_path != '\0'){
				extn_len_cnt++;
				temp_path++;
			}
		}
		if(len > FILE_NAME_SHRT_LEN || extn_len_cnt > FILE_NAME_EXTN_LEN)
			is_long_file_name = true;

		if(is_long_file_name){
			path = delim_strt;
			len = 0;
			if(*path == DELIMITER)
				path++;
			while(len < LONG_FILE_NAME_LEN  && *path != '\0'
                              && *path != DELIMITER){
                             	long_file_name[len] = *path;
                                path++;
                                len++;
                        }
			long_file_name[len] = '\0';
			if(entry){
				sw_free(entry);
				entry = NULL;
			}
			is_file_found = get_dir_entry(long_file_name,&entry,
										  pwd,strt_cluster,true);				
		}
		else{
			len = FILE_NAME_SHRT_LEN;
			while(len < SHRT_FILE_NAME_LEN  && *path != '\0' 
			      && *path != DELIMITER){ 
				if(*path == EXTN_DELIMITER)
					path++;
				long_file_name[len] = *path;
				path++;
				len++;
			}
			convert_to_uppercase(long_file_name); 
			if(entry){
				sw_free(entry);
				entry = NULL;
			}
			is_file_found = get_dir_entry(long_file_name,&entry,
										  pwd,strt_cluster,false);
		}
		if((is_file_found) & (i != delim_cnt - 1)){ 
			strt_cluster = (entry->strt_clus_hword)<<16 | 
				       (entry->strt_clus_lword);
			pwd = cluster_to_memory_addr(strt_cluster);
			len = 0;
			extn_len_cnt = 0;
			sw_memset(shrt_file_name,SPACE_VAL,SHRT_FILE_NAME_LEN);
			sw_memset(long_file_name,SPACE_VAL,LONG_FILE_NAME_LEN);
			is_long_file_name = false;
		}		
	}
	if(is_file_found){
		if(flags & FILE_WRITE){
			if(chk_file_lock(file_path) == -1)
				flags = FILE_READ;				
			if(entry->attr & ATTR_READ){
				sw_printf("Cannot open the file in write mode\n");
				return -1;
			}
		}
		info = (file_info*)sw_malloc(sizeof(file_info));
                fl_des = retrieve_file_info(info,entry,flags,
											dir_file_offset,file_path);
	}  
	else{
              	if((flags & FILE_CREATE_NEW) || (flags & FILE_CREATE_ALWAYS)
                   || (flags & FILE_WRITE)){
                	if(is_long_file_name){
				get_short_file_name(long_file_name,shrt_file_name,
									(char)seq_num);
				if(get_dir_entry(shrt_file_name,NULL,
								 pwd,strt_cluster,false) == true){
					while(get_dir_entry(shrt_file_name,NULL,
										pwd,strt_cluster,false)){
						seq_num++;
						get_short_file_name(long_file_name,
											shrt_file_name,'seq_num');
					}
				}
				convert_to_uppercase(shrt_file_name);
				crt_flag = create_file(long_file_name,
									   shrt_file_name,strt_cluster,&entry);
			}
			else
				crt_flag = create_file(NULL,long_file_name,strt_cluster,&entry);
                        if(crt_flag == 0)
				sw_printf("File creation success\n");
			info = (file_info*)sw_malloc(sizeof(file_info));
			fl_des = retrieve_file_info(info,entry,flags,
										dir_file_offset,file_path);
                }
	  	else
			return -1;
        }
	return fl_des;  
}