Ejemplo n.º 1
0
boolvec * cntr_read(const char * filename, const char * cntrname,
	       int col1, int col2, int col3,
	       const char* delimiter, int skip_lines, int grow_by)
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {

		d_cntr * contour = _cntr_read(fname, cntrname,
			col1, col2, col3, skip_lines,
			grow_by, delimiter);

		if (contour != NULL) {
			surfit_cntrs->push_back(contour);
			res->push_back(true);
			
		} else
			res->push_back(false);

		fname = find_next();
	}

	find_close();
	return res;
};
Ejemplo n.º 2
0
boolvec * area_load(const char * filename, const char * areaname)
{
    boolvec * res = create_boolvec();
    const char * fname = find_first(filename);

    while (fname != NULL) {
        d_area * area = _area_load(fname, areaname);
        if (area) {
            surfit_areas->push_back(area);
            res->push_back(true);
        } else {
            res->push_back(false);
            fname = find_next();
            continue;
        }
        if (areaname == NULL)
        {
            char * name = get_name(fname);
            area->setName( name );
            sstuff_free_char(name);
        }

        fname = find_next();
    }

    find_close();
    return res;
};
Ejemplo n.º 3
0
Archivo: bp.cpp Proyecto: rkonow/topk
///////////////////////////////////////////
//  deepest_node(bp *b,i64 s)
//    returns the first node with the largest depth in the subtree of s
///////////////////////////////////////////
i64 deepest_node(bp *b,i64 s)
{
    i64 t,m;
    t = find_close(b,s);
    m = rmq(b,s,t, OPT_MAX);
    return m;
}
Ejemplo n.º 4
0
Archivo: bp.cpp Proyecto: rkonow/topk
///////////////////////////////////////////
//  is_ancestor(bp *b, i64 s, i64 t)
//     returns 1 if s is an ancestor of t
//             0 otherwise
///////////////////////////////////////////
i64 is_ancestor(bp *b, i64 s, i64 t)
{
    i64 v;
    v = find_close(b,s);
    if (s <= t && t <= v) return 1;
    return 0;
}
Ejemplo n.º 5
0
Archivo: bp.cpp Proyecto: rkonow/topk
///////////////////////////////////////////
//  postorder_rank(bp *b,i64 s)
//    returns the postorder (>= 1) of node s (s >= 0)
//            -1 if s-th bit is not OP
///////////////////////////////////////////
i64 postorder_rank(bp *b,i64 s)
{
    i64 t;
    if (inspect(b,s) == CP) return -1;
    t = find_close(b,s);
    //  return t+1 - darray_rank(b->da,t);
    return rank_close(b,t);
}
Ejemplo n.º 6
0
Archivo: bp.cpp Proyecto: rkonow/topk
///////////////////////////////////////////
//  next_sibling(bp *b,i64 s)
//    returns the next sibling of parent(s)
//            -1 if s is the last child
//////////////////////////////////////////
i64 next_sibling(bp *b, i64 s)
{
    i64 t;
    t = find_close(b,s)+1;
    if (t >= b->n) {
        printf("next_sibling: error s=%d t=%d\n",(int)s,(int)t);
    }
    if (inspect(b,t) == CP) return -1;
    return t;
}
Ejemplo n.º 7
0
Archivo: bp.cpp Proyecto: rkonow/topk
///////////////////////////////////////////
//  rightmost_leaf(bp *b, i64 s)
///////////////////////////////////////////
i64 rightmost_leaf(bp *b, i64 s)
{
    i64 t;
    if ((b->opt & OPT_LEAF) == 0) {
        printf("leftmost_leaf: error!!!   not supported\n");
        return -1;
    }
    t = find_close(b,s);
    return leaf_select(b,leaf_rank(b,t));
}
Ejemplo n.º 8
0
Archivo: bp.cpp Proyecto: rkonow/topk
///////////////////////////////////////////
//  leaf_size(bp *b, i64 s)
///////////////////////////////////////////
i64 leaf_size(bp *b, i64 s)
{
    i64 t;
    if ((b->opt & OPT_LEAF) == 0) {
        printf("leaf_size: error!!!   not supported\n");
        return -1;
    }
    t = find_close(b,s);
    return leaf_rank(b,t) - leaf_rank(b,s);
}
Ejemplo n.º 9
0
boolvec * area_load_shp(const char * filename, const char * areaname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		res->push_back(_area_load_shp(fname, areaname));
		fname = find_next();	
	}
	find_close();
	return res;
};
Ejemplo n.º 10
0
boolvec * area_load_bln(const char * filename, const char * areaname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		d_area * area = _area_load_bln(fname, areaname);
		if (area)
			surfit_areas->push_back(area);
		res->push_back( area != NULL );
		fname = find_next();	
	}
	find_close();
	return res;
};
Ejemplo n.º 11
0
boolvec * cntr_load(const char * filename, const char * cntrname) 
{
	boolvec * res = create_boolvec();
	const char * fname = find_first(filename);

	while (fname) {
		d_cntr * contour = _cntr_load(fname, cntrname);
		if (contour) {
			surfit_cntrs->push_back(contour);
			res->push_back(true);
		} else
			res->push_back(false);

		fname = find_next();
	}

	find_close();
	return res;
};
Ejemplo n.º 12
0
boolvec * area_read(const char * filename, const char * areaname,
                    int col1, int col2,
                    const char* delimiter, int skip_lines, int grow_by)
{

    boolvec * res = create_boolvec();
    const char * fname = find_first(filename);

    while (fname != NULL) {

        d_area * area = _area_read(fname, areaname,
                                   col1, col2, skip_lines,
                                   grow_by, delimiter);

        if (area != NULL)
            surfit_areas->push_back(area);
        else {
            writelog(LOG_WARNING,"failed to read area from file %s", fname);
            res->push_back(false);
            fname = find_next();
            continue;
        }

        if (areaname == NULL)
        {
            char * name = get_name(fname);
            area->setName( name );
            sstuff_free_char(name);
        }

        res->push_back(true);
        fname = find_next();

    }

    find_close();
    return res;

};
Ejemplo n.º 13
0
int ScanFile(HXCFLOPPYEMULATOR* floppycontext,struct Volume * adfvolume,char * folder,char * file)
{
	long hfindfile;
	filefoundinfo FindFileData;
	int bbool;
	int byte_written;
	FILE * ftemp;
	unsigned char  tempbuffer[512];
	struct File* adffile;
	unsigned char * fullpath;//,*fileimg;
	int size,filesize;
	RETCODE  rc;
	
	hfindfile=find_first_file(folder,file, &FindFileData); 
	if(hfindfile!=-1)
	{
		bbool=TRUE;
		while(hfindfile!=-1 && bbool)
		{
			if(FindFileData.isdirectory)
			{
				if(strcmp(".",FindFileData.filename)!=0 && strcmp("..",FindFileData.filename)!=0)
				{
					if(adfCountFreeBlocks(adfvolume)>4)
					{
						floppycontext->hxc_printf(MSG_INFO_1,"Adding directory %s",FindFileData.filename);
						rc=adfCreateDir(adfvolume,adfvolume->curDirPtr,FindFileData.filename); 
						if(rc==RC_OK)
						{
							floppycontext->hxc_printf(MSG_INFO_1,"entering directory %s",FindFileData.filename);
							rc=adfChangeDir(adfvolume, FindFileData.filename);
							if(rc==RC_OK)
							{
								
								fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2);
								sprintf(fullpath,"%s\\%s",folder,FindFileData.filename);

								if(ScanFile(floppycontext,adfvolume,fullpath,file))
								{
									adfParentDir(adfvolume);
									free(fullpath);
									return 1;
								}
								floppycontext->hxc_printf(MSG_INFO_1,"Leaving directory %s",FindFileData.filename);
								free(fullpath);
								adfParentDir( adfvolume);
							}
							else
							{
								floppycontext->hxc_printf(MSG_ERROR,"Cannot enter to the directory %s !",FindFileData.filename);
								return 1;
							}
						}
						else
						{
							floppycontext->hxc_printf(MSG_ERROR,"Cannot Add the directory %s !",FindFileData.filename);
							return 1;
						}
					}
					else
					{
						floppycontext->hxc_printf(MSG_ERROR,"Cannot Add a directory ! : no more free block!!!");
					    return 1;
					}
					
				}
			}
			else
			{
				if(adfCountFreeBlocks(adfvolume)>4)
				{
						floppycontext->hxc_printf(MSG_INFO_1,"Adding file %s, %dB",FindFileData.filename,FindFileData.size);
						adffile = adfOpenFile(adfvolume, FindFileData.filename, "w");
						if(adffile)
						{
							if(FindFileData.size)
							{
								fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2);
								sprintf(fullpath,"%s\\%s",folder,FindFileData.filename);

								ftemp=fopen(fullpath,"rb");
								if(ftemp)
								{
									fseek(ftemp,0,SEEK_END);
									filesize=ftell(ftemp);
									fseek(ftemp,0,SEEK_SET);
									do
									{					
										if(filesize>=512)
										{
											size=512;		
										}
										else
										{
                                            size=filesize;
										}
										fread(&tempbuffer,size,1,ftemp);

										byte_written=adfWriteFile(adffile, size, tempbuffer);
										if((byte_written!=size) || (adfCountFreeBlocks(adfvolume)<2) )
										{
											floppycontext->hxc_printf(MSG_ERROR,"Error while writting the file %s. No more free block ?",FindFileData.filename);
											adfCloseFile(adffile);
											fclose(ftemp);
											free(fullpath);
											return 1;
										}
										filesize=filesize-512;

									}while( (filesize>0) && (byte_written==size));
								

									/*fileimg=(unsigned char*)malloc(filesize);
									memset(fileimg,0,filesize);
									fread(fileimg,filesize,1,ftemp);
									adfWriteFile(adffile, filesize, fileimg);
									free(fileimg);*/

									adfCloseFile(adffile);
									fclose(ftemp);
									free(fullpath);
								}
								else
								{
										floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot open %s !!!",fullpath);
										free(fullpath);
										return 1;
								}
							}
						}
						else
						{
                             floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot create %s, %dB!!!",FindFileData.filename,FindFileData.size);
							 return 1;
						}
				}
				else
				{
					floppycontext->hxc_printf(MSG_ERROR,"Error : Cannot add a file : no more free block");
					return 1;
				}
			}
			bbool=find_next_file(hfindfile,folder,file,&FindFileData);
		}
		
	}
	else printf("Error FindFirstFile\n");

	find_close(hfindfile);
	return 0;
}
Ejemplo n.º 14
0
Archivo: bp.cpp Proyecto: rkonow/topk
///////////////////////////////////////////
//  subtree_size(bp *b, i64 s)
//    returns the number of nodes in the subtree of s
///////////////////////////////////////////
i64 subtree_size(bp *b, i64 s)
{
    return (find_close(b,s) - s + 1) / 2;
}
Ejemplo n.º 15
0
int ScanFileAndAddToFAT(HXCFLOPPYEMULATOR* floppycontext,char * folder,char * file, char * fattable,char *entriestable,char *datatable,int parentcluster,FATCONFIG * fatconfig,int numberofcluster)
{
	long hfindfile;
	filefoundinfo FindFileData;
	int bbool;
	int tii;
	FILE * ftemp;
	char * newentry;
	char * subnewentry;
	char tempstr[256];
	int lefttoread;
	int fatclusternb;
	unsigned char * fullpath;
	fat_directory_entry *entry;
	fat_directory_entry *subentry;
	int i,j;
	struct stat repstate;
	struct tm * ts;

	tii=0;
	hfindfile=find_first_file(folder,file, &FindFileData); 
	if(hfindfile!=-1)
	{
		bbool=1;
		while(hfindfile!=-1 && bbool)
		{
			if(FindFileData.isdirectory)
			{
				if(strcmp(".",FindFileData.filename)!=0 && strcmp("..",FindFileData.filename)!=0)
				{
					newentry=findfreeentry(entriestable);
					entry=(fat_directory_entry *)newentry;
					
					memset(entry->DIR_Name,0x20,8+3);
					sprintf((char*)tempstr,"%s",FindFileData.filename);
					
					floppycontext->hxc_printf(MSG_INFO_1,"Adding directory %s",FindFileData.filename);
					
					strupper(tempstr);
					if(strchr(tempstr,'.'))
					{
						memcpy(&entry->DIR_Name[8],strchr(tempstr,'.')+1,strlen(strchr(tempstr,'.')+1));
						*strchr(tempstr,'.')=0;
					}
					memcpy(entry->DIR_Name,tempstr,strlen(tempstr));
					entry->DIR_Attr=entry->DIR_Attr|0x10;
					entry->DIR_FileSize=FindFileData.size;


					fatclusternb=findfreecluster(fattable,numberofcluster);
					if(fatclusternb==-1)
					{
						floppycontext->hxc_printf(MSG_ERROR,"Cannot add this directory ! : No more cluster free !");
						find_close(hfindfile);
						return 1;
					}
					memset(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],0,fatconfig->sectorsize*fatconfig->clustersize);
					
					entry->DIR_FstClusLO=fatclusternb;
					//*( (unsigned short*) &newentry[0x1A])=fatclusternb;
					setclusterptr(fattable,fatclusternb,0xFFF);
					
					subnewentry=findfreeentry(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize]);
					subentry=(fat_directory_entry *)subnewentry;

					sprintf(subentry->DIR_Name,".          ");

					//memcpy(subnewentry,".          ",strlen(".          "));
					subentry->DIR_Attr=0x10;
					subentry->DIR_FstClusLO=fatclusternb;
					
					subnewentry=findfreeentry(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize]);
					subentry=(fat_directory_entry *)subnewentry;
					sprintf(subentry->DIR_Name,"..         ");
					subentry->DIR_Attr=0x10;
					subentry->DIR_FstClusLO=parentcluster;
					//*( (unsigned short*) &subnewentry[0x1A])=parentcluster;
					
					floppycontext->hxc_printf(MSG_INFO_1,"Entering directory %s",FindFileData.filename);

					fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2);
					sprintf(fullpath,"%s\\%s",folder,FindFileData.filename);

					if(ScanFileAndAddToFAT(floppycontext,fullpath,file,fattable,&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],datatable,fatclusternb,fatconfig,numberofcluster))
					{
						free(fullpath);
						find_close(hfindfile);
						return 1;
					}
					free(fullpath);

					floppycontext->hxc_printf(MSG_INFO_1,"Leaving directory %s",FindFileData.filename);
					
				}
			}
			else
			{
				floppycontext->hxc_printf(MSG_INFO_1,"Adding file %s, %dB",FindFileData.filename,FindFileData.size);

				sprintf(tempstr,"%s",FindFileData.filename);
				strupper(tempstr);

				newentry=findfreeentry(entriestable);
				entry=(fat_directory_entry *)newentry;
				memset(entry->DIR_Name,0x20,8+3);

				i=0;
				while(tempstr[i]  && (i<8) && tempstr[i]!='.')
				{

					if(tempstr[i]==' ')
					{
						newentry[i]='_';
					}
					else
					{
						newentry[i]=tempstr[i];
					}
					i++;
				}
					
				if(strchr(tempstr,'.'))
				{

					i=0;
					while(tempstr[i]!='.')
					{
						i++;
					}

					j=0;
					i++;
					while(tempstr[i]  && (j<3))
					{

						if(tempstr[i]==' ')
						{
							newentry[8+j]='_';
						}
						else
						{
							newentry[8+j]=tempstr[i];
						}
						i++;
						j++;
					}


					memcpy(newentry+8,strchr(tempstr,'.')+1,strlen(strchr(tempstr,'.')+1));
					*strchr(tempstr,'.')=0;
				}


				entry->DIR_FileSize=FindFileData.size;
				if(FindFileData.size)
				{
					lefttoread=FindFileData.size;
					fatclusternb=findfreecluster(fattable,numberofcluster);
					memset(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],0,fatconfig->sectorsize*fatconfig->clustersize);
					
					if(fatclusternb==-1)
					{
						floppycontext->hxc_printf(MSG_ERROR,"Cannot add this file ! : No more cluster free !");
						find_close(hfindfile);
						return 1;
					}
					entry->DIR_FstClusLO=fatclusternb;
					
					if(file)
					{
						fullpath=malloc(strlen(FindFileData.filename)+strlen(folder)+2);
						sprintf(fullpath,"%s\\%s",folder,FindFileData.filename);
					}
					else
					{
						fullpath=malloc(strlen(folder)+1);
						sprintf(fullpath,"%s",folder);
					}


					
					stat(fullpath,&repstate);
					ts=localtime(&repstate.st_ctime);
					if(ts)
					{
						entry->DIR_CrtDate=  (((ts->tm_year-80) &0x7F)<<9) | ((ts->tm_mon+1 &0xF)<<5) | (ts->tm_mday &0x1F);
						entry->DIR_CrtTime= ((ts->tm_hour&0x1F)<<11) | ((ts->tm_min  &0x3F)<<5) | ((ts->tm_sec/2)&0x1F);
					}
					else
					{
						entry->DIR_CrtDate= 0;
						entry->DIR_CrtTime= 0;
					}

					stat(fullpath,&repstate);
					ts=localtime(&repstate.st_mtime);
					if(ts)
					{
						entry->DIR_WrtDate=  (((ts->tm_year-80) &0x7F)<<9) | ((ts->tm_mon+1 &0xF)<<5) | (ts->tm_mday &0x1F);
						entry->DIR_WrtTime= ((ts->tm_hour&0x1F)<<11) | ((ts->tm_min  &0x3F)<<5) | ((ts->tm_sec/2)&0x1F);
					}
					else
					{
						entry->DIR_WrtDate= 0;
						entry->DIR_WrtTime= 0;
					}

					ftemp=fopen(fullpath,"rb");
					if(ftemp)
					{
						do
						{
							fatclusternb=findfreecluster(fattable,numberofcluster);
							if(fatclusternb==-1)
							{
								floppycontext->hxc_printf(MSG_ERROR,"Error while adding this file ! : No more cluster free !");
								free(fullpath);
								find_close(hfindfile);
								fclose(ftemp);
								return 1;
							}
							memset(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],0x00,fatconfig->sectorsize*fatconfig->clustersize);
							fread(&datatable[(fatclusternb-2)*fatconfig->sectorsize*fatconfig->clustersize],fatconfig->sectorsize*fatconfig->clustersize,1,ftemp);
							setclusterptr(fattable,fatclusternb,0xFFF);
							if(lefttoread>(fatconfig->sectorsize*fatconfig->clustersize))
							{
								setclusterptr(fattable,fatclusternb,findfreecluster(fattable,numberofcluster));
							}
							lefttoread=lefttoread-(fatconfig->sectorsize*fatconfig->clustersize);
						}while(lefttoread>0);
						
						fclose(ftemp);
					}
					else
					{
						floppycontext->hxc_printf(MSG_ERROR,"Error while adding this file ! : Access error !");
					}
					free(fullpath);
					
				}	
			}
			
			bbool=find_next_file(hfindfile,folder,file,&FindFileData);	
		}
		
	}
	else printf("Error FindFirstFile\n");
	
	find_close(hfindfile);
	
	return 0;
}
Ejemplo n.º 16
0
/*
 * createtags: create tags file
 *
 *	i)	dbpath	dbpath directory
 *	i)	root	root directory of source tree
 */
void
createtags(const char *dbpath, const char *root)
{
	STATISTICS_TIME *tim;
	STRBUF *sb = strbuf_open(0);
	struct put_func_data data;
	int openflags, flags, seqno;
	const char *path;

	tim = statistics_time_start("Time of creating %s and %s.", dbname(GTAGS), dbname(GRTAGS));
	if (vflag)
		fprintf(stderr, "[%s] Creating '%s' and '%s'.\n", now(), dbname(GTAGS), dbname(GRTAGS));
	openflags = cflag ? GTAGS_COMPACT : 0;
	data.gtop[GTAGS] = gtags_open(dbpath, root, GTAGS, GTAGS_CREATE, openflags);
	data.gtop[GTAGS]->flags = 0;
	if (extractmethod)
		data.gtop[GTAGS]->flags |= GTAGS_EXTRACTMETHOD;
	data.gtop[GRTAGS] = gtags_open(dbpath, root, GRTAGS, GTAGS_CREATE, openflags);
	data.gtop[GRTAGS]->flags = data.gtop[GTAGS]->flags;
	flags = 0;
	if (debug)
		flags |= PARSER_DEBUG;
	if (wflag)
		flags |= PARSER_WARNING;
	/*
	 * Add tags to GTAGS and GRTAGS.
	 */
	if (file_list)
		find_open_filelist(file_list, root);
	else
		find_open(NULL);
	seqno = 0;
	while ((path = find_read()) != NULL) {
		if (*path == ' ') {
			path++;
			if (!test("b", path))
				gpath_put(path, GPATH_OTHER);
			continue;
		}
		gpath_put(path, GPATH_SOURCE);
		data.fid = gpath_path2fid(path, NULL);
		if (data.fid == NULL)
			die("GPATH is corrupted.('%s' not found)", path);
		seqno++;
		if (vflag)
			fprintf(stderr, " [%d] extracting tags of %s\n", seqno, path + 2);
		if (debug)
			fprintf(stderr, "[%s]\n", path + 2);
		parse_file(path, flags, put_syms, &data);
		gtags_flush(data.gtop[GTAGS], data.fid);
		gtags_flush(data.gtop[GRTAGS], data.fid);
	}
	total = seqno;
	parser_exit();
	find_close();
	statistics_time_end(tim);
	tim = statistics_time_start("Time of flushing B-tree cache");
	gtags_close(data.gtop[GTAGS]);
	gtags_close(data.gtop[GRTAGS]);
	statistics_time_end(tim);
	strbuf_reset(sb);
	if (getconfs("GTAGS_extra", sb)) {
		tim = statistics_time_start("Time of executing GTAGS_extra command");
		if (system(strbuf_value(sb)))
			fprintf(stderr, "GTAGS_extra command failed: %s\n", strbuf_value(sb));
		statistics_time_end(tim);
	}
	strbuf_reset(sb);
	if (getconfs("GRTAGS_extra", sb)) {
		tim = statistics_time_start("Time of executing GRTAGS_extra command");
		if (system(strbuf_value(sb)))
			fprintf(stderr, "GRTAGS_extra command failed: %s\n", strbuf_value(sb));
		statistics_time_end(tim);
	}
	strbuf_close(sb);
}
Ejemplo n.º 17
0
/*
 * incremental: incremental update
 *
 *	i)	dbpath	dbpath directory
 *	i)	root	root directory of source tree
 *	r)		0: not updated, 1: updated
 */
int
incremental(const char *dbpath, const char *root)
{
	STATISTICS_TIME *tim;
	struct stat statp;
	STRBUF *addlist = strbuf_open(0);
	STRBUF *deletelist = strbuf_open(0);
	STRBUF *addlist_other = strbuf_open(0);
	IDSET *deleteset, *findset;
	int updated = 0;
	const char *path;
	unsigned int id, limit;

	tim = statistics_time_start("Time of inspecting %s and %s.", dbname(GTAGS), dbname(GRTAGS));
	if (vflag) {
		fprintf(stderr, " Tag found in '%s'.\n", dbpath);
		fprintf(stderr, " Incremental updating.\n");
	}
	/*
	 * get modified time of GTAGS.
	 */
	path = makepath(dbpath, dbname(GTAGS), NULL);

	if (gpath_open(dbpath, 0) < 0)
		die("GPATH not found.");
	/*
	 * deleteset:
	 *	The list of the path name which should be deleted from GPATH.
	 * findset:
	 *	The list of the path name which exists in the current project.
	 *	A project is limited by the --file option.
	 */
	deleteset = idset_open(gpath_nextkey());
	findset = idset_open(gpath_nextkey());
	total = 0;
	/*
	 * Make add list and delete list for update.
	 */
	if (single_update) {
		int type;
		const char *fid = gpath_path2fid(single_update, &type);
		/*
		 * The --single-update=file supports only updating.
		 * If it is new file, this option is ignored, and the processing is
		 * automatically switched to the normal procedure.
		 */
		if (fid == NULL) {
			if (vflag)
				fprintf(stderr, " --single-update option ignored, because '%s' is new file.\n", single_update);
			goto normal_update;
		}
		/*
		 * If type != GPATH_SOURCE then we have nothing to do, and you will see
		 * a message 'Global databases are up to date.'.
		 */
		if (type == GPATH_SOURCE) {
			strbuf_puts0(addlist, single_update);
			idset_add(deleteset, atoi(fid));
			total++;
		}
	} else {
normal_update:
		if (file_list)
			find_open_filelist(file_list, root);
		else
			find_open(NULL);
		while ((path = find_read()) != NULL) {
			const char *fid;
			int n_fid = 0;
			int other = 0;

			/* a blank at the head of path means 'NOT SOURCE'. */
			if (*path == ' ') {
				if (test("b", ++path))
					continue;
				other = 1;
			}
			if (stat(path, &statp) < 0)
				die("stat failed '%s'.", path);
			fid = gpath_path2fid(path, NULL);
			if (fid) { 
				n_fid = atoi(fid);
				idset_add(findset, n_fid);
			}
			if (other) {
				if (fid == NULL)
					strbuf_puts0(addlist_other, path);
			} else {
				if (fid == NULL) {
					strbuf_puts0(addlist, path);
					total++;
				} else if (gpath_mtime(NULL, fid) < statp.st_mtime) {
					if (uflag) {
						printf("%s\n", path);
					} else {
						strbuf_puts0(addlist, path);
						total++;
						idset_add(deleteset, n_fid);
					}
				}
			}
		}
		find_close();
		/*
		 * make delete list.
		 */
		if (remove_lost) {
			limit = gpath_nextkey();
		} else {
			limit = 0;
		}
		for (id = 1; id < limit; id++) {
			char fid[MAXFIDLEN];
			int type;

			snprintf(fid, sizeof(fid), "%d", id);
			/*
			 * This is a hole of GPATH. The hole increases if the deletion
			 * and the addition are repeated.
			 */
			if ((path = gpath_fid2path(fid, &type)) == NULL)
				continue;
			/*
			 * The file which does not exist in the findset is treated
			 * assuming that it does not exist in the file system.
			 */
			if (type == GPATH_OTHER) {
				if (!idset_contains(findset, id) || !test("f", path) || test("b", path))
					strbuf_puts0(deletelist, path);
			} else {
				if (!idset_contains(findset, id) || !test("f", path)) {
					strbuf_puts0(deletelist, path);
					idset_add(deleteset, id);
				}
			}
		}
	}
	gpath_close();
	statistics_time_end(tim);
	/*
	 * execute updating.
	 */
	if ((!idset_empty(deleteset) || strbuf_getlen(addlist) > 0) ||
	    (strbuf_getlen(deletelist) + strbuf_getlen(addlist_other) > 0))
	{
		int db;

		updated = 1;
		tim = statistics_time_start("Time of updating %s and %s.", dbname(GTAGS), dbname(GRTAGS));
		if (!idset_empty(deleteset) || strbuf_getlen(addlist) > 0)
			updatetags(dbpath, root, deleteset, addlist);
		if (strbuf_getlen(deletelist) + strbuf_getlen(addlist_other) > 0) {
			const char *start, *end, *p;

			if (vflag)
				fprintf(stderr, "[%s] Updating '%s'.\n", now(), dbname(GPATH));
			gpath_open(dbpath, 2);
			if (strbuf_getlen(deletelist) > 0) {
				start = strbuf_value(deletelist);
				end = start + strbuf_getlen(deletelist);

				for (p = start; p < end; p += strlen(p) + 1)
					gpath_delete(p);
			}
			if (strbuf_getlen(addlist_other) > 0) {
				start = strbuf_value(addlist_other);
				end = start + strbuf_getlen(addlist_other);

				for (p = start; p < end; p += strlen(p) + 1)
					gpath_put(p, GPATH_OTHER);
			}
			gpath_close();
		}
		/*
		 * Update modification time of tag files
		 * because they may have no definitions.
		 */
		for (db = GTAGS; db < GTAGLIM; db++)
			utime(makepath(dbpath, dbname(db), NULL), NULL);
		statistics_time_end(tim);
	}
	if (vflag) {
		if (updated)
			fprintf(stderr, " Global databases have been modified.\n");
		else
			fprintf(stderr, " Global databases are up to date.\n");
		fprintf(stderr, "[%s] Done.\n", now());
	}
	strbuf_close(addlist);
	strbuf_close(deletelist);
	strbuf_close(addlist_other);
	idset_close(deleteset);
	idset_close(findset);

	return updated;
}