Пример #1
0
int find_page(char *name, char *sect)
{
static char defpath[] = "/usr/local/man:/usr/man";
static char defsect[] = "1:2:3:4:5:6:7:8:9";
static char defsuff[] = ":.gz:.Z";
static char manorcat[] = "man:cat";

   char fbuf[256];
   char *manpath;
   char *mansect = sect;
   char *mansuff;
   char *mc, *mp, *ms, *su, *nmc, *nmp, *nms, *nsu;
   int rv = -1;

                  manpath = getenv("MANPATH");
   if (!manpath) manpath = defpath;
   if (!mansect) mansect = getenv("MANSECT");
   if (!mansect) mansect = defsect;
                  mansuff = defsuff;

   if (strchr(name, '/')) {
      for (su=nsu=mansuff,step(&su,&nsu); su; step(&su, &nsu)) {
         strcpy(fbuf, name);
	 strcat(fbuf, su);
         if ((rv=open_page(fbuf)) >= 0) break;
      }
      *man_file = 0;
      return rv;
   }

   /* SEARCH!! */
   for(mc=nmc=manorcat,step(&mc,&nmc); mc; step(&mc, &nmc))
      for(ms=nms=mansect,step(&ms,&nms); ms; step(&ms, &nms))
	 for(mp=nmp=manpath,step(&mp,&nmp); mp; step(&mp, &nmp))
	    for(su=nsu=mansuff,step(&su,&nsu); su; step(&su, &nsu)) {
	       sprintf(fbuf, "%s/%s%s/%s.%s%s", mp, mc, ms, name, ms, su);

	       /* Got it ? */
	       if (access(fbuf, 0) < 0) continue;
	       if (flg_w)
	       {
		  printf("%s\n", fbuf);
		  rv = 0;
		  continue;
	       }

	       /* Try it ! */
	       if ((rv=open_page(fbuf)) >= 0)
	       {
		  char * p;
		  strcpy(man_file, fbuf);
		  p = strrchr(man_file, '/'); if(p) *p = 0;
		  p = strrchr(man_file, '/'); if(p) p[1] = 0;
		  return 0;
	       }
	    }

   return rv;
}
Пример #2
0
/*	Search the list of link title for a match
*/
static void find_page(const char *search_title, void *data)
{
	size_t i;

	/* find matches where the search string is a substring of the title */
	num_found_links = 0;
	for (i=0; i<num_page_links && num_found_links<MAX_FOUND_LINKS; ++i)
		if(xmlStrcasestr((xmlChar*)page_links[i].title,(xmlChar*)search_title)!=NULL)
			found_links[num_found_links++] = i;

	/* ignore if no matches, open if one match, or display a list of the first few matches */
	if (num_found_links < 1)
		return;
	else if (num_found_links == 1)
		open_page(found_links[0]);
	else
	{
		if (cm_valid(cm_encycl_res))
			cm_destroy(cm_encycl_res);
		cm_encycl_res = cm_create(page_links[found_links[0]].title, cm_encycl_res_handler);
		cm_set_pre_show_handler(cm_encycl_res, cm_encycl_res_pre_show_handler);
		for (i=1; i<num_found_links; i++)
			cm_add(cm_encycl_res, page_links[found_links[i]].title, NULL);
		cm_show_direct(cm_encycl_res, -1, -1);
	}
}
Пример #3
0
/*	Handle options selected from the main context menu
*/
static int cm_encycl_handler(window_info *win, int widget_id, int mx, int my, int option)
{
	switch (option)
	{
		case CM_ENCYCL_INDEX:
			currentpage = page_index[ENCYCLT_ENCYC];
			vscrollbar_set_pos(encyclopedia_win, encyclopedia_scroll_id, 0);
			vscrollbar_set_bar_len(encyclopedia_win, encyclopedia_scroll_id, Page[currentpage].max_y);
			break;
		case CM_ENCYCL_SEARCH:
			close_ipu(&ipu_encycl);
			init_ipu(&ipu_encycl, encyclopedia_win, DEFAULT_FONT_X_LEN * 20, -1, 40, 1, NULL, find_page_callback);
			ipu_encycl.x = mx; ipu_encycl.y = my;
			display_popup_win(&ipu_encycl, encycl_search_propmt);
			if (ipu_encycl.popup_win >=0 && ipu_encycl.popup_win<windows_list.num_windows)
				windows_list.window[ipu_encycl.popup_win].opaque = 1;
			break;
		case CM_ENCYCL_REPSEARCH:
			if (last_search != NULL)
				repeat_search = 1;
			break;
		case CM_ENCYCL_BOOKMARK:
			if (num_bookmarks < MAX_BOOKMARKS)
			{
				size_t i;
				for (i=0; i<num_page_links; i++)
					if(!xmlStrcasecmp((xmlChar*)Page[currentpage].Name,(xmlChar*)page_links[i].link))
					{
						book_marks[num_bookmarks++] = i;
						rebuild_cm_encycl();
						break;
					}
			}
			break;
		case CM_ENCYCL_UNBOOKMARK:
			{
				size_t i;
				size_t index = get_page_bookmark_index();
				if (index < MAX_BOOKMARKS)
				{
					for (i=index+1; i<num_bookmarks; i++)
						book_marks[i-1] = book_marks[i];
					num_bookmarks--;
					rebuild_cm_encycl();
				}
				break;
			}
		case CM_ENCYCL_CLEARBOOKMARKS:
			num_bookmarks = 0;
			rebuild_cm_encycl();
			break;
		default:
			open_page(book_marks[option-CM_ENCYCL_THEBOOKMARKS]);
	}
	return 1;
}
Пример #4
0
static uint32_t write_to_page(MXFFileSysData *sysData, const uint8_t *data, uint32_t count)
{
    uint32_t numWrite;
    Page *page;

    page = open_page(sysData, sysData->position);
    if (page == 0)
    {
        return 0;
    }

    if (sysData->position > sysData->pageSize * page->index + page->size)
    {
        /* can't write from beyond the end of the data in the page */
        /* TODO: assertion here? */
        return 0;
    }

    /* set the file at the current position */
    if (page->offset < 0 ||
        sysData->position != sysData->pageSize * page->index + page->offset)
    {
        int64_t offset = sysData->position - sysData->pageSize * page->index;
        if (!disk_file_seek(page->fileDescriptor, offset, SEEK_SET))
        {
            page->offset = -1; /* invalidate the position within the page */
            return 0;
        }
        page->offset = offset;
        page->size = (page->offset > page->size) ? page->offset : page->size;
    }

    /* write count bytes or 'till the end of the page */
    numWrite = (count > (uint32_t)(sysData->pageSize - page->offset)) ?
        (uint32_t)(sysData->pageSize - page->offset) : count;
    numWrite = disk_file_write(page->fileDescriptor, data, numWrite);

    page->offset += numWrite;
    page->size = (page->offset > page->size) ? page->offset : page->size;


    sysData->position += numWrite;

    return numWrite;
}
Пример #5
0
/*	Open the page selected from the multi-match list.
*/
static int cm_encycl_res_handler(window_info *win, int widget_id, int mx, int my, int option)
{
	if (option>=0 && option<num_found_links)
		open_page(found_links[option]);
	return 1;
}