Exemple #1
0
int op_fnzsearch (mval *file, mint indx, mval *ret)
{
	struct stat	statbuf;
	int		stat_res;
	parse_blk	pblk;
	plength		*plen, pret;
	char		buf1[MAX_FBUFF + 1]; /* buffer to hold translated name */
	mval		sub;
	mstr		tn;
	lv_val		*ind_tmp;
	error_def(ERR_INVSTRLEN);

	MV_FORCE_STR(file);
	if (file->str.len > MAX_FBUFF)
		rts_error(VARLSTCNT(4) ERR_INVSTRLEN, 2, file->str.len, MAX_FBUFF);

	MV_FORCE_MVAL(&ind_val, indx);
	ind_var = op_srchindx(VARLSTCNT(2) zsrch_var, &ind_val);
	if (ind_var)
	{
		assert(ind_var->v.mvtype & MV_STR);
		if (file->str.len != ind_var->v.str.len  ||  memcmp(file->str.addr, ind_var->v.str.addr, file->str.len))
		{
			op_kill(ind_var);
			ind_var = (lv_val*) 0;
		}
	}
	if (ind_var)
	{
		for (;;)
		{
			pret.p.pint = pop_top(ind_var, ret);	/* get next element off the top */
			if (!ret->str.len)
				break;

			memcpy(buf1, ret->str.addr, ret->str.len);
			buf1[ret->str.len] = 0;
			STAT_FILE(buf1, &statbuf, stat_res);
			if (-1 == stat_res)
			{
				if (errno == ENOENT)
					continue;
				rts_error(VARLSTCNT(1) errno);
			}
			break;
		}
	} else
	{
		memset(&pblk, 0, sizeof(pblk));
		pblk.buffer = buf1;
		pblk.buff_size = MAX_FBUFF;
		if (!(parse_file(&file->str, &pblk) & 1))
		{
			ret->mvtype = MV_STR;
			ret->str.len = 0;
		} else
		{
			assert(!ind_var);
			buf1[pblk.b_esl] = 0;
			/* establish new search context */
			ind_var = op_putindx(VARLSTCNT(2) zsrch_var, &ind_val);
			ind_var->v = *file;	/* zsrch_var(indx)=original spec */
			if (!(pblk.fnb & F_WILD))
			{
				sub.mvtype = MV_STR;
				sub.str.len = pblk.b_esl;
				sub.str.addr =  buf1;
				s2pool(&sub.str);
				ind_tmp = op_putindx(VARLSTCNT(2) ind_var, &sub);
				ind_tmp->v.mvtype = MV_STR; ind_tmp->v.str.len = 0;
				plen = (plength *)&ind_tmp->v.m[1];
				plen->p.pblk.b_esl = pblk.b_esl;
				plen->p.pblk.b_dir = pblk.b_dir;
				plen->p.pblk.b_name = pblk.b_name;
				plen->p.pblk.b_ext = pblk.b_ext;
			} else
				dir_srch(&pblk);

			for (;;)
			{
				pret.p.pint = pop_top(ind_var, ret);	/* get next element off the top */
				if (!ret->str.len)
					break;

				memcpy(buf1, ret->str.addr, ret->str.len);
				buf1[ret->str.len] = 0;
				STAT_FILE(buf1, &statbuf, stat_res);
				if (-1 == stat_res)
				{
					if (errno == ENOENT)
						continue;
					rts_error(VARLSTCNT(1) errno);
				}
				break;
			}
		}
	}
	assert(pret.p.pblk.b_esl == ret->str.len);
	return pret.p.pint;
}
Exemple #2
0
void dir_srch (parse_blk *pfil)
{
	struct stat	statbuf;
	int		stat_res;
	lv_val		*dir1, *dir2, *tmp;
	mstr		tn;
	short		p2_len;
	char		filb[MAX_FBUFF + 1], patb[sizeof(ptstr)], *c, *lastd, *top, *p2, *c1, ch;
	mval		pat_mval, sub, compare;
	bool		wildname, seen_wd;
	struct dirent 	*dent;
	DIR		*dp;
	plength		*plen;
	int		closedir_res;

	op_kill(zsrch_dir1);
	op_kill(zsrch_dir2);

	if (!pfil->b_name)
		return;		/* nothing to search for */

	ESTABLISH(dir_ch);
	pat_mval.mvtype = MV_STR;
	pat_mval.str.addr = patb;	/* patb should be sizeof(ptstr.buff) but instead is sizeof(ptstr) since the C compiler
					 * complains about the former and the latter is just 4 bytes more */
	pat_mval.str.len = 0;
	sub.mvtype = MV_STR;
	sub.str.len = 0;
	compare.mvtype = MV_STR;
	compare.str.len = 0;
	wildname = (pfil->fnb & F_WILD_NAME) != 0;
	dir1 = zsrch_dir1;
	dir2 = zsrch_dir2;

	if (pfil->fnb & F_WILD_DIR)
	{
		seen_wd = FALSE;
		for (c = pfil->l_dir, lastd = c, top = c + pfil->b_dir; c < top;)
		{
			ch = *c++;
			if (ch == '/')	/* note the start of each directory segment */
			{
				if (seen_wd)
					break;
				lastd = c;
			}
			if (ch == '?' || ch == '*')
				seen_wd = TRUE;
		}
		assert(c <= top);
		sub.str.addr = pfil->l_dir;
		sub.str.len = lastd - sub.str.addr;
		tmp = op_putindx(VARLSTCNT(2) dir1, &sub);
		tmp->v.mvtype = MV_STR; tmp->v.str.len = 0;
		for(;;)
		{
			tn.addr = lastd;	/* wildcard segment */
			tn.len = c - lastd - 1;
			lastd = c;
			genpat(&tn, &pat_mval);
			seen_wd = FALSE;
			p2 = c - 1;
			for (; c < top;)
			{
				ch = *c++;
				if (ch == '/')	/* note the start of each directory segment */
				{
					if (seen_wd)
						break;
					lastd = c;
				}
				if (ch == '?' || ch == '*')
					seen_wd = TRUE;
			}
			p2_len = lastd - p2;	/* length of non-wild segment after wild section */
			for (;;)
			{
				pop_top(dir1, &sub);	/* get next item off the top */
				if (!sub.str.len)
					break;

				memcpy(filb, sub.str.addr, sub.str.len);
				filb[sub.str.len] = 0;
				sub.str.addr = filb;
				dp = OPENDIR(filb);
				if (!dp)
					continue;
				while(READDIR(dp, dent))
				{
					compare.str.addr = &dent->d_name[0];
					compare.str.len = strlen(&dent->d_name[0]);
					assert(compare.str.len);
					if (   dent->d_name[0] == '.'
					    && (compare.str.len == 1  ||  (compare.str.len == 2  &&  dent->d_name[1] == '.'))   )
					{
						continue;	/* don't want to read . and .. */
					}

					if (compare.str.len + sub.str.len + p2_len > MAX_FBUFF)
						continue;

					if (do_pattern(&compare, &pat_mval))
					{	/* got a hit */
						if (stringpool.free + compare.str.len + sub.str.len + p2_len + 1 > stringpool.top)
							stp_gcol(compare.str.len + sub.str.len + p2_len + 1);

						/* concatenate directory and name */
						c1 = (char *)stringpool.free;
						tn = sub.str;
						s2pool(&tn);
						tn = compare.str;
						s2pool(&tn);
						tn.addr = p2;
						tn.len = p2_len;
						s2pool(&tn);
						*stringpool.free++ = 0;
						compare.str.addr = c1;
						compare.str.len += sub.str.len + p2_len;
						STAT_FILE(compare.str.addr, &statbuf, stat_res);
						if (-1 == stat_res)
							continue;
						if (!(statbuf.st_mode & S_IFDIR))
							continue;
						/* put in results tree */
						tmp = op_putindx(VARLSTCNT(2) dir2, &compare);
						tmp->v.mvtype = MV_STR;
						tmp->v.str.len = 0;
					}
				}
				CLOSEDIR(dp, closedir_res);
			}
			tmp = dir1; dir1 = dir2; dir2 = tmp;
			if (c >= top)
				break;
		}
	} else
	{
		sub.str.addr = pfil->l_dir;
		sub.str.len = pfil->b_dir;
		tmp = op_putindx(VARLSTCNT(2) dir1, &sub);
		tmp->v.mvtype = MV_STR; tmp->v.str.len = 0;
	}

	if (wildname)
	{
		tn.addr = pfil->l_name;
		tn.len = pfil->b_name + pfil->b_ext;
		genpat(&tn, &pat_mval);
	}

	for (;;)
	{
		pop_top(dir1, &sub);	/* get next item off the top */
		if (!sub.str.len)
			break;

		if (wildname)
		{
			memcpy(filb, sub.str.addr, sub.str.len);
			filb[sub.str.len] = 0;
			sub.str.addr = filb;
			dp = OPENDIR(filb);
			if (!dp)
				continue;
			while(READDIR(dp, dent))
			{
				compare.str.addr = &dent->d_name[0];
				compare.str.len = strlen(&dent->d_name[0]);
				if (   dent->d_name[0] == '.'
				    && (compare.str.len == 1  ||  (compare.str.len == 2  &&  dent->d_name[1] == '.')))
				{
					continue;	/* don't want to read . and .. */
				}
				if (compare.str.len + sub.str.len > MAX_FBUFF)
					continue;

				if (do_pattern(&compare, &pat_mval))
				{	/* got a hit */
					if (stringpool.free + compare.str.len + sub.str.len > stringpool.top)
						stp_gcol(compare.str.len + sub.str.len);

					/* concatenate directory and name */
					c = (char *)stringpool.free;
					tn = sub.str;
					s2pool(&tn);
					tn = compare.str;
					s2pool(&tn);
					compare.str.addr = c;
					compare.str.len += sub.str.len;

					/* put in results tree */
					tmp = op_putindx(VARLSTCNT(2) ind_var, &compare);
					tmp->v.mvtype = MV_STR;
					tmp->v.str.len = 0;
					plen = (plength *)&tmp->v.m[1];
					plen->p.pblk.b_esl = compare.str.len;
					plen->p.pblk.b_dir = sub.str.len;
					for (c = &compare.str.addr[sub.str.len], c1 = top = &compare.str.addr[compare.str.len];
					     c < top;
					    )
					{
						if (*c++ != '.')
							break;
					}
					for (; c < top;)
					{
						if (*c++ == '.')
							c1 = c - 1;
					}
					plen->p.pblk.b_ext = top - c1;
					plen->p.pblk.b_name = plen->p.pblk.b_esl - plen->p.pblk.b_dir - plen->p.pblk.b_ext;
				}
			}
			CLOSEDIR(dp, closedir_res);
		} else
		{
			assert(pfil->fnb & F_WILD_DIR);
			compare.str.addr = pfil->l_name;
			compare.str.len = pfil->b_name + pfil->b_ext;

			if (compare.str.len + sub.str.len > MAX_FBUFF)
				continue;

			memcpy(filb, sub.str.addr, sub.str.len);
			filb[sub.str.len] = 0;
			sub.str.addr = filb;

			if (stringpool.free + compare.str.len + sub.str.len > stringpool.top)
				stp_gcol(compare.str.len + sub.str.len);

			/* concatenate directory and name */
			c1 = (char *)stringpool.free;
			tn = sub.str;
			s2pool(&tn);
			tn = compare.str;
			s2pool(&tn);
			compare.str.addr = c1;
			compare.str.len += sub.str.len;

			/* put in results tree */
			tmp = op_putindx(VARLSTCNT(2) ind_var, &compare);
			tmp->v.mvtype = MV_STR; tmp->v.str.len = 0;
			plen = (plength *)&tmp->v.m[1];
			plen->p.pblk.b_esl = compare.str.len;
			plen->p.pblk.b_dir = sub.str.len;
			plen->p.pblk.b_name = pfil->b_name;
			plen->p.pblk.b_ext = pfil->b_ext;
		}
	}
	op_kill(zsrch_dir1);
	op_kill(zsrch_dir2);
	REVERT;
}
Exemple #3
0
int op_fnzsearch(mval *file, mint indx, mval *ret)
{
	struct stat	statbuf;
	int		stat_res;
	parse_blk	pblk;
	plength		*plen, pret;
	char		buf1[MAX_FBUFF + 1]; /* buffer to hold translated name */
	mval		sub;
	mstr		tn;
	lv_val		*ind_tmp;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	ESTABLISH_RET(fnzsrch_ch, -1);
	TREF(fnzsearch_nullsubs_sav) = TREF(lv_null_subs);
	TREF(lv_null_subs) = LVNULLSUBS_OK;	/* $ZSearch processing depends on this */
	MV_FORCE_STR(file);
	if (file->str.len > MAX_FBUFF)
		rts_error(VARLSTCNT(4) ERR_INVSTRLEN, 2, file->str.len, MAX_FBUFF);
	MV_FORCE_MVAL(((mval *)TADR(fnzsearch_sub_mval)), indx);
	TREF(fnzsearch_lv_vars) = op_srchindx(VARLSTCNT(2) TREF(zsearch_var), (mval *)TADR(fnzsearch_sub_mval));
	if (TREF(fnzsearch_lv_vars))
	{
		assert((TREF(fnzsearch_lv_vars))->v.mvtype & MV_STR);
		if ((file->str.len != (TREF(fnzsearch_lv_vars))->v.str.len)
			|| memcmp(file->str.addr, (TREF(fnzsearch_lv_vars))->v.str.addr, file->str.len))
		{
			op_kill(TREF(fnzsearch_lv_vars));
			TREF(fnzsearch_lv_vars) = NULL;
		}
	}
	if (TREF(fnzsearch_lv_vars))
	{
		for (;;)
		{
			pret.p.pint = pop_top(TREF(fnzsearch_lv_vars), ret);	/* get next element off the top */
			if (!ret->str.len)
				break;
			memcpy(buf1, ret->str.addr, ret->str.len);
			buf1[ret->str.len] = 0;
			STAT_FILE(buf1, &statbuf, stat_res);
			if (-1 == stat_res)
			{
				if (errno == ENOENT)
					continue;
				rts_error(VARLSTCNT(1) errno);
			}
			break;
		}
	} else
	{
		memset(&pblk, 0, SIZEOF(pblk));
		pblk.buffer = buf1;
		pblk.buff_size = MAX_FBUFF;
		if (!(parse_file(&file->str, &pblk) & 1))
		{
			ret->mvtype = MV_STR;
			ret->str.len = 0;
		} else
		{
			assert(!TREF(fnzsearch_lv_vars));
			buf1[pblk.b_esl] = 0;
			/* establish new search context */
			TREF(fnzsearch_lv_vars) = op_putindx(VARLSTCNT(2) TREF(zsearch_var), TADR(fnzsearch_sub_mval));
			(TREF(fnzsearch_lv_vars))->v = *file;	/* zsearch_var(indx)=original spec */
			if (!(pblk.fnb & F_WILD))
			{
				sub.mvtype = MV_STR;
				sub.str.len = pblk.b_esl;
				sub.str.addr =  buf1;
				s2pool(&sub.str);
				ind_tmp = op_putindx(VARLSTCNT(2) TREF(fnzsearch_lv_vars), &sub);
				ind_tmp->v.mvtype = MV_STR; ind_tmp->v.str.len = 0;
				plen = (plength *)&ind_tmp->v.m[1];
				plen->p.pblk.b_esl = pblk.b_esl;
				plen->p.pblk.b_dir = pblk.b_dir;
				plen->p.pblk.b_name = pblk.b_name;
				plen->p.pblk.b_ext = pblk.b_ext;
			} else
				dir_srch(&pblk);
			for (;;)
			{
				pret.p.pint = pop_top(TREF(fnzsearch_lv_vars), ret);	/* get next element off the top */
				if (!ret->str.len)
					break;
				memcpy(buf1, ret->str.addr, ret->str.len);
				buf1[ret->str.len] = 0;
				STAT_FILE(buf1, &statbuf, stat_res);
				if (-1 == stat_res)
				{
					if (errno == ENOENT)
						continue;
					rts_error(VARLSTCNT(1) errno);
				}
				break;
			}
		}
	}
	assert((0 == ret->str.len) || (pret.p.pblk.b_esl == ret->str.len));
	TREF(lv_null_subs) = TREF(fnzsearch_nullsubs_sav);
	REVERT;
	return pret.p.pint;
}
Exemple #4
0
void fix_lines_and_remove(image_t* img,params* parameters, uint32_t** last_STAFFLINES, uint32_t *previous_start, uint32_t cutNum){
/*function [result,new_start,STAFFLINES] = fix_lines_and_remove(img,params,last_STAFFLINES,previous_start,cutNum)*/
/*remvoe lines from small portion of staff. also straightens staff.*/
	flex_array_t *stafflines_tmp;	
	uint32_t *yprojection, line_thickness, line_spacing, line_w, *last_STAFFLINES_avg, max_project, sum, h, w,
		i, j, ii, count, **STAFFLINES, dummy, loc, shift, findLine, match, lineBegin,
		lineEnd, found_thickness, middle, tooThick, tooHigh, any_stafflines_zero, now_avg, last_avg, goodLine,
		tooLow, curr, extend, lastDelete, cW, cH, topStop, botStop, thickness, paramThickness, thickness_th,
		topLine, shift_loop,k;
	int16_t *tempData,*temp_array;
	int32_t lineY;
	uint8_t pixelData;
	linked_list *staffLines, *allLINES, *temp;
		
	STAFFLINES=multialloc(sizeof(uint32_t),2,5,2);

	h = img->height;
	w = img->width;
	line_thickness = (uint32_t)(parameters->thickness);
	line_spacing = (uint32_t)(parameters->spacing);
	line_w = (uint32_t)(parameters->thickness + parameters->spacing);
	
	last_STAFFLINES_avg = (uint32_t *)malloc(sizeof(uint32_t)*5);/*mget_spc((uint32_t)5, sizeof(uint32_t));*/
	for(i=0; i<5; i++){
		last_STAFFLINES_avg[i] = (uint32_t)((last_STAFFLINES[i][0] + last_STAFFLINES[i][1] + 1)/2);
	}
	yprojection= (uint32_t *)mget_spc((uint32_t)h, sizeof(uint32_t));
	max_project = 0;
	for(i=0;i<h;i++){
		sum = 0;
		for(j=0;j<w;j++){
			sum += getPixel(img,i,j);
		}
		yprojection[i] = sum;
		if(yprojection[i] > max_project){
			max_project = yprojection[i];		
		}
	}
	count = 0;
	for(i=0;i<h;i++){
    		if (yprojection[i] >= (9*max_project)/10){    /*delete staff line, twiddle with the 80% later (90%)*/
       			count++;
    		}
	}
	stafflines_tmp=make_flex_array(count);
	count = 0;
	for(i=0;i<h;i++){
    		if (yprojection[i] >= (9*max_project)/10){    /*delete staff line, twiddle with the 80% later (90%)*/
			stafflines_tmp->data[count] = i;       			
			count++;
    		}
	}
	free(yprojection);
	staffLines = group(stafflines_tmp, 3);
/*CHANGE: CUTNUM = 1 TO 0*/
	if (cutNum == 0 && staffLines->length == 5 ){
/*END CHANGE*/
		i=0;
	    	while(is_list_empty(staffLines)==0){
			tempData=(int16_t*)pop_top(staffLines);
			STAFFLINES[i][0] = tempData[0];
			STAFFLINES[i][1] = tempData[1];
			i++;
			free(tempData);
		}
	}
	else if ((staffLines->length) == 0){		
		for(i=0;i<5;i++){
			STAFFLINES[i][0] = last_STAFFLINES[i][0];
			STAFFLINES[i][1] = last_STAFFLINES[i][1];
		}
	}
/*CHANGE: CUTNUM = 1 TO 0*/
	else if (cutNum == 0 && (staffLines->length) < 5){
/*END CHANGE*/
	    	/*choose one line, then find closest line in last_STAFFLINES*/
		tempData = (int16_t*)(getIndexData(staffLines, 0));
	    	goodLine = (uint32_t)((tempData[0]+tempData[1]+1)/2);
		
		dummy = abs(last_STAFFLINES_avg[0] - goodLine);
		loc = 0;		
		for(i=1;i<5;i++){
			curr = abs(last_STAFFLINES_avg[i] - goodLine);
			if(curr<dummy){
				dummy = curr;				
				loc = i;
			}
		}
	    	shift = goodLine - last_STAFFLINES_avg[loc];
	    
	    	for(i=0;i<5;i++){
			STAFFLINES[i][0] = last_STAFFLINES[i][0]+shift;
			STAFFLINES[i][1] = last_STAFFLINES[i][1]+shift;
		}
	}
	

	else{
		count = 0;
		for(findLine=0;findLine<5;findLine++){

			match = 0;
			for(i=0;i<(staffLines->length);i++){
				tempData = (int16_t*)(getIndexData(staffLines, i));
			    	lineBegin = (uint32_t)tempData[0];
			    	lineEnd = (uint32_t)tempData[1];
				/*lineBegin is top of line, lineEnd is bottom*/

			    	found_thickness = lineEnd-lineBegin+1;
/*CHANGED: 0.5 TO 1/2*/
			    	middle = (uint32_t)((lineBegin + lineEnd+1)/2);
/*END CHANGED*/

			    	/*determine if the line is of expected location/size*/
				tooThick = 0;
				tooHigh = 0;
				tooLow = 0;
			    	if(found_thickness > (line_thickness+2)) tooThick=1;
				if(middle < (last_STAFFLINES_avg[findLine] - 3)) tooHigh=1;
				if(middle > (last_STAFFLINES_avg[findLine] + 3)) tooLow=1;
/*CHANGED: 1 TO 0*/
			    	if (cutNum == 0){
/*END CHANGED*/
					tooHigh = 0;
					tooLow = 0;
					if(middle < (last_STAFFLINES_avg[0] - 2*line_spacing)){tooHigh=1;}
/*CHANGED + TO - ALSO, avg[5] -> avg[4] */
					if(middle > (last_STAFFLINES_avg[4] + 2*line_spacing)){tooLow=1;}
/*END CHANGED*/
			    	}

			    	if (tooThick || tooHigh || tooLow){
					continue;
			    	}
			    	else{ /*we found good match for staffline*/
					match = 1;
					/*SAVE STAFF LINE LOCATIONS*/
					STAFFLINES[count][0] = lineBegin;
					STAFFLINES[count][1] = lineEnd;
					count++;
					deleteIndexData(staffLines,i);
					break;
			    	}        



			} /*end looping thru found lines*/

			if(!match){ /*CHANGED*/
		    		/*flag that no match was found*/
		    		STAFFLINES[count][0] = 0;
				STAFFLINES[count][1] = 0;
				count++;
			} 

	    	} /*end looping through matching staff lines*/
	    
	    	/*CHANGED BELOW*/
	    
	    	/*check for lines that did not get match*/
		any_stafflines_zero = 0;
		for(i=0;i<5;i++){
			if(STAFFLINES[i][0] == 0){
				any_stafflines_zero = 1;
				break;
			}
		}
	    	if (any_stafflines_zero){
			/*find shift value first*/
			shift = 100; /*big value*/
			for (findLine = 0; findLine<5;findLine++){
			/*loop to find nonzero entry in STAFFLINES, then calculate shift*/
			    if (STAFFLINES[findLine][0]){ /*if nonzero*/
				now_avg = (uint32_t)((STAFFLINES[findLine][0]+STAFFLINES[findLine][1]+1)/2);
				last_avg = last_STAFFLINES_avg[findLine];
				shift = now_avg - last_avg;
				break;
			    }
			}
			if (shift==100){ shift = 0;}
			/*replace any flagged (with 0) entries in STAFFLINES*/
			for(findLine=0;findLine<5;findLine++){
			    	if (STAFFLINES[findLine][0] == 0){
					STAFFLINES[findLine][0] = last_STAFFLINES[findLine][0]+shift;
					STAFFLINES[findLine][1] = last_STAFFLINES[findLine][1]+shift;
			    	}
			}
		}
	}

	extend = (uint32_t)((line_w+2)/4)+1;
	/*create stafflines above*/
	allLINES=create_linked_list();
	lineY = (int32_t)(((STAFFLINES[0][0] + STAFFLINES[0][1]+1)/2) - line_w); /*first above line*/
	while (1){
   		if (lineY < (int32_t)(extend + 2)){
       			break;
		}   		
		else{
			temp_array=malloc(sizeof(int16_t)*2);
			temp_array[0]=(int16_t)lineY;
			temp_array[1]=(int16_t)lineY;
			push_top(allLINES,temp_array);
       			lineY = (int32_t)(lineY - (int32_t)line_w );
   		}
	}
	for(i=0;i<5;i++){
		temp_array=malloc(sizeof(uint32_t)*2);
		temp_array[0]=(int16_t)STAFFLINES[i][0];
		temp_array[1]=(int16_t)STAFFLINES[i][1];
		push_bottom(allLINES,temp_array);
	}
	/*create stafflines below*/
	lineY = (uint32_t)(((STAFFLINES[4][0] + STAFFLINES[4][1]+1)/2) + line_w); /*first above line*/
	while (1){
   		if (lineY > (h - extend - 3)){
       			break;
		}   		
		else{
			temp_array=malloc(sizeof(int16_t)*2);
			temp_array[0]=(int16_t)lineY;
			temp_array[1]=(int16_t)lineY;
			push_bottom(allLINES,temp_array);
			lineY = (uint32_t)(lineY + (int32_t)line_w);
   		}
	}
	/*REMOVE STAFF LINES*/

	while( is_list_empty(allLINES)==0){
		tempData = (int16_t*)pop_top(allLINES);
		lineBegin = tempData[0];
		lineEnd = tempData[1];
		middle = (lineBegin + lineEnd + 1)/2;
		lastDelete = 0;
		free(tempData);
    
    
    		for(j=0;j<w;j++){
        
        		/*top of staff line*/
        		topStop = 0;
/*CHANGED*/
        		for(ii = (lineBegin-1); ii>=(lineBegin-extend); ii--){
/*END CHANGED*/
            			if (ii < 0){
                			break;
            			}
            			if (getPixel(img,ii,j)==0){ /*then erase*/
                			topStop = ii+1;
                			break;
            			}
        		}
    
			/*bottom of staff line*/
			botStop = h-1;
/*CHANGED*/
			for(ii = lineEnd+1; ii<=(lineEnd+extend); ii++){
/*END CHANGED*/
	     	      	 	if (ii > h-1){
	      	          		break;
		    		}
		    		if(getPixel(img,ii,j)==0){
		        		botStop = ii-1;              
		        		break;
		    		}
			}
	    
		
			/*check thickness of line, delete if skinny*/
	       	 	thickness = botStop - topStop + 1;
	       	 	if (parameters->thickness < 3){
		    		paramThickness = parameters->thickness + 1;
			}
			else{
		    		paramThickness = parameters->thickness;
			}
			if (lastDelete){ /*there was a line deletion last iteration*/
		    		thickness_th = paramThickness*2; /*higher threshold*/
			}
			else{
		    		thickness_th = paramThickness*2-2;
			}
			if (thickness <= thickness_th){
				for(ii=topStop; ii<=botStop; ii++){ 
		    			setPixel(img,ii,j,0);
				}
		    		lastDelete = 1;
			}
			else{
		    		lastDelete = 0;
			}
    
    		}
        
	} /*end staff line*/
	topLine = STAFFLINES[0][0];
	if(*previous_start){
    		if(*previous_start<topLine){
        		shift=topLine-(*previous_start);
/*CHANGED H-SHIFT-1 TO H-SHIFT*/
			for(shift_loop=0; shift_loop<(h-shift); shift_loop++){
/*END CHANGED*/
				for(cW=0; cW<w; cW++){
					pixelData=getPixel(img,shift_loop+shift,cW);
		    			setPixel(img,shift_loop,cW,pixelData);
				}
			}
			for(cH=h-shift-1; cH<h; cH++){
				for(cW=0; cW<w; cW++){
		    			setPixel(img,cH,cW,0);
				}
			}      	
		}
    		else if(*previous_start>topLine){
        		shift=*previous_start-topLine;
		
			for(shift_loop=h-1; shift_loop>=shift; shift_loop--){
				for(cW=0; cW<w; cW++){
					pixelData=getPixel(img,shift_loop-shift,cW);
		    			setPixel(img,shift_loop,cW, pixelData);
				}
			}
/*CHANGED: SHIFT-1 TO SHIFT*/
			for(cH=0; cH<shift; cH++){
/*END CHANGED*/
				for(cW=0; cW<w; cW++){
		    			setPixel(img,cH,cW,0);
				}
			}
		}	
	}
	else{
	    	*previous_start=topLine;
	}

	for(i=0; i<5;i++){
		last_STAFFLINES[i][0] = STAFFLINES[i][0];
		last_STAFFLINES[i][1] = STAFFLINES[i][1];
	}
	delete_list(staffLines);
	delete_list(allLINES);
	multifree(STAFFLINES,2);
}
Exemple #5
0
void dir_srch(parse_blk *pfil)
{
	struct stat	statbuf;
	int		stat_res;
	lv_val		*dir1, *dir2, *tmp;
	mstr		tn;
	short		p2_len;
	char		filb[MAX_FBUFF + 1], patb[SIZEOF(ptstr)], *c, *lastd, *top, *p2, *c1, ch;
	mval		pat_mval, sub, compare;
	boolean_t	wildname, seen_wd;
	struct dirent 	*dent;
	DIR		*dp;
	plength		*plen;
	int		closedir_res;
	DCL_THREADGBL_ACCESS;

	SETUP_THREADGBL_ACCESS;
	op_kill(TREF(zsearch_dir1));
	op_kill(TREF(zsearch_dir2));
	if (!pfil->b_name)
		return;		/* nothing to search for */
	ESTABLISH(dir_ch);
	pat_mval.mvtype = MV_STR;
	pat_mval.str.addr = patb;	/* patb should be SIZEOF(ptstr.buff) but instead is SIZEOF(ptstr) since the C compiler
					 * complains about the former and the latter is just 4 bytes more */
	pat_mval.str.len = 0;
	sub.mvtype = MV_STR;
	sub.str.len = 0;
	compare.mvtype = MV_STR;
	compare.str.len = 0;
	wildname = (pfil->fnb & F_WILD_NAME) != 0;
	dir1 = TREF(zsearch_dir1);
	dir2 = TREF(zsearch_dir2);
	if (pfil->fnb & F_WILD_DIR)
	{
		seen_wd = FALSE;
		for (c = pfil->l_dir, lastd = c, top = c + pfil->b_dir; c < top;)
		{
			ch = *c++;
			if (ch == '/')	/* note the start of each directory segment */
			{
				if (seen_wd)
					break;
				lastd = c;
			}
			if (ch == '?' || ch == '*')
				seen_wd = TRUE;
		}
		assert(c <= top);
		sub.str.addr = pfil->l_dir;
		sub.str.len = INTCAST(lastd - sub.str.addr);
		tmp = op_putindx(VARLSTCNT(2) dir1, &sub);
		tmp->v.mvtype = MV_STR; tmp->v.str.len = 0;
		for (;;)
		{
			tn.addr = lastd;	/* wildcard segment */
			tn.len = INTCAST(c - lastd - 1);
			lastd = c;
			genpat(&tn, &pat_mval);
			seen_wd = FALSE;
			p2 = c - 1;
			for (; c < top;)
			{
				ch = *c++;
				if (ch == '/')	/* note the start of each directory segment */
				{
					if (seen_wd)
						break;
					lastd = c;
				}
				if (ch == '?' || ch == '*')
					seen_wd = TRUE;
			}
			p2_len = lastd - p2;	/* length of non-wild segment after wild section */
			for (;;)
			{
				pop_top(dir1, &sub);	/* get next item off the top */
				if (!sub.str.len)
					break;
				memcpy(filb, sub.str.addr, sub.str.len);
				filb[sub.str.len] = 0;
				sub.str.addr = filb;
				dp = OPENDIR(filb);
				if (!dp)
					continue;
				while (READDIR(dp, dent))
				{
					compare.str.addr = &dent->d_name[0];
					compare.str.len = STRLEN(&dent->d_name[0]);
					UNICODE_ONLY(
						if (gtm_utf8_mode)
							compare.mvtype &= ~MV_UTF_LEN;	/* to force "char_len" to be recomputed
											 * in do_pattern */
					)
					assert(compare.str.len);
					if (('.' == dent->d_name[0])
					    && ((1 == compare.str.len) || ((2 == compare.str.len) && ('.' == dent->d_name[1]))))
						continue;	/* don't want to read . and .. */
					if (compare.str.len + sub.str.len + p2_len > MAX_FBUFF)
						continue;
					if (do_pattern(&compare, &pat_mval))
					{	/* got a hit */
						ENSURE_STP_FREE_SPACE(compare.str.len + sub.str.len + p2_len + 1);
						/* concatenate directory and name */
						c1 = (char *)stringpool.free;
						tn = sub.str;
						s2pool(&tn);
						tn = compare.str;
						s2pool(&tn);
						tn.addr = p2;
						tn.len = p2_len;
						s2pool(&tn);
						*stringpool.free++ = 0;
						compare.str.addr = c1;
						compare.str.len += sub.str.len + p2_len;
						STAT_FILE(compare.str.addr, &statbuf, stat_res);
						if (-1 == stat_res)
							continue;
						if (!(statbuf.st_mode & S_IFDIR))
							continue;
						/* put in results tree */
						tmp = op_putindx(VARLSTCNT(2) dir2, &compare);
						tmp->v.mvtype = MV_STR;
						tmp->v.str.len = 0;
					}
				}
				CLOSEDIR(dp, closedir_res);
			}
			tmp = dir1; dir1 = dir2; dir2 = tmp;
			if (c >= top)
				break;
		}