Example #1
0
// line assumed not to have '\n' on end
void addline(bc *bc, char *line)
{
int lnum;
char *p;
int len;

	lnum = atoi(line);
	len = strlen(bc->program) + strlen(line) + 1;
	p=findline(bc, lnum);
	if(*p)
	{
		while(*p)
		{
			--len;
			if(*p++ == '\n')
				break;
		}
	}
	if(len > sizeof(bc->program)-1)
	{
		error(bc, "Not enough space to add line to program.");
		return;
	}
	deleteline(bc, lnum);
	p=findtextline(bc, lnum);
	len=strlen(line)+1;
	memmove(p+len, p, strlen(p)+1);
	memcpy(p, line, len-1);
	p[len-1] = '\n';
}
Example #2
0
static void
num_arg(char *arg, int md)
{
	offset_t repeat, toline;
	char rep[21];
	char *ptr;
	int		len;

	ptr = rep;
	for (++arg; *arg != '}'; arg += len) {
		if (*arg == NULL)
			fatal("%s: missing '}'\n", targ);
		if ((len = mblen(arg, MB_LEN_MAX)) <= 0)
			len = 1;
		if ((ptr + len) >= &rep[20])
			fatal("%s: Repeat count too large\n", targ);
		(void) memcpy(ptr, arg, len);
		ptr += len;
	}
	*ptr = NULL;
	if ((asc_to_ll(rep, &repeat) == ERR) || repeat < 0L)
		fatal("Illegal repeat count: %s\n", targ);
	if (md == LINMODE) {
		toline = offset = curline;
		for (; repeat > 0LL; repeat--) {
			toline += offset;
			to_line(toline);
		}
	} else	if (md == EXPMODE)
			for (; repeat > 0LL; repeat--)
				to_line(findline(expbuf, offset));
		else
			fatal("No operation for %s\n", targ);
}
Example #3
0
// if the point (x,y) is near a line, divides the line with it
Tvertex *insertvertex(coord3d x,coord3d y)
{
  Tline *l;
  Tsector *s;
  if (!findline(&l,&s,x,y)) return NULL;
  int v=addvertex(x,y);
  refvertex(v);
  Twall *w;
  for (w=*l->walls;w;w=w->next) {
    if (is_hole(w)) {
      Tsector *s=((Thole *)w)->sector;
      Tline *l1;
      for (l1=s->lines;l1;l1=l1->next)
        if (l1->v1==l->v2 && l1->v2==l->v1) {
          splitline(l1,v);
          refvertex(v);
          refvertex(v);
          s->linesnum++;
        }
    }
  }
  splitline(l,v);
  s->linesnum++;
  return verts+v;
}
Example #4
0
int Masek::findline(unsigned char* data, int rows, int cols, double **lines)
{
    int hsize0 = rows, hsize1 = cols;
    IMAGE image_obj;
    image_obj.data = data;
    image_obj.hsize[0] = hsize0;
    image_obj.hsize[1] = hsize1;
    return findline(&image_obj, lines);
}
Example #5
0
/*
 * Print lines in a specified range.
 * The last line printed becomes the current line.
 * If expandflag is TRUE, then the line is printed specially to
 * show magic characters.
 */
static BOOL printlines(NUM num1, NUM num2, BOOL expandflag)
{
    LINE *lp;
    unsigned char *cp;
    int ch;
    LEN count;

    if ((num1 < 1) || (num2 > lastnum) || (num1 > num2)) {
	fprintf(stderr, "Bad line range for print\n");
	return FALSE;
    }
    lp = findline(num1);
    if (lp == NULL)
	return FALSE;

    while (!intflag && (num1 <= num2)) {
	if (!expandflag) {
	    write(STDOUT, lp->data, lp->len);
	    setcurnum(num1++);
	    lp = lp->next;
	    continue;
	}
	/*
	 * Show control characters and characters with the
	 * high bit set specially.
	 */
	cp = lp->data;
	count = lp->len;
	if ((count > 0) && (cp[count - 1] == '\n'))
	    count--;

	while (count-- > 0) {
	    ch = *cp++;
	    if (ch & 0x80) {
		fputs("M-", stdout);
		ch &= 0x7f;
	    }
	    if (ch < ' ') {
		fputc('^', stdout);
		ch += '@';
	    }
	    if (ch == 0x7f) {
		fputc('^', stdout);
		ch = '?';
	    }
	    fputc(ch, stdout);
	}
	fputs("$\n", stdout);

	setcurnum(num1++);
	lp = lp->next;
    }

    return TRUE;
}
Example #6
0
// Print numlines of text starting from buf
void printtext(char*buf, int from)
{
  char *p,*f;
  char right,bot,nlines;

  // clear window to print
  right = getnumcols() - HELP_RIGHT_MARGIN;
  bot = getnumrows() - HELP_BOTTOM_MARGIN;
  nlines = bot-HELP_BODY_ROW+1;
  scrollupwindow(HELP_BODY_ROW,HELP_LEFT_MARGIN,bot,right,0x07,nlines);

  f  = findline(buf,from);
  if (!f) return; // nothing to print
  if (*f=='\n') f++; // start of from+1st line
  p = findline(f,nlines);
  if (p && (*p=='\n')) *p = '\0'; // change to NUL
  gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
  cswprint(f,0x07,HELP_LEFT_MARGIN);
  if (p) *p = '\n'; // set it back
}
Example #7
0
void deleteline(bc *bc, int lnum)
{
char *p, *p2;
	p=findline(bc, lnum);
	if(*p)
	{
		p2=p;
		while(*p2 && *p2++ != '\n');
		while((*p++ = *p2++));
	}
}
Example #8
0
/*
 * Set the current line number.
 * Returns TRUE if successful.
 */
static BOOL setcurnum(NUM num)
{
    LINE *lp;

    lp = findline(num);
    if (lp == NULL)
	return FALSE;

    curnum = num;
    curline = lp;

    return TRUE;
}
Example #9
0
/*
 * Write the specified lines out to the specified file.
 * Returns TRUE if successful, or FALSE on an error with a message output.
 */
static BOOL writelines(char *file, NUM num1, NUM num2)
{
    int fd;
    LINE *lp;
    LEN linecount;
    LEN charcount;

    if ((num1 < 1) || (num2 > lastnum) || (num1 > num2)) {
	fprintf(stderr, "Bad line range for write\n");
	return FALSE;
    }
    linecount = 0;
    charcount = 0;

    unlink(file);		/* if CREAT resets file size/data, remove this line */
    fd = creat(file, 0666);
    if (fd < 0) {
	perror(file);
	return FALSE;
    }
    printf("\"%s\", ", file);
    fflush(stdout);

    lp = findline(num1);
    if (lp == NULL) {
	close(fd);
	return FALSE;
    }
    while (num1++ <= num2) {
	if (write(fd, lp->data, lp->len) != lp->len) {
	    perror(file);
	    close(fd);
	    return FALSE;
	}
	charcount += lp->len;
	linecount++;
	lp = lp->next;
    }

    if (close(fd) < 0) {
	perror(file);
	return FALSE;
    }
    printf("%d lines, %d chars\n", linecount, charcount);

    return TRUE;
}
Example #10
0
/*
 * Delete lines from the given range.
 */
static BOOL deletelines(NUM num1, NUM num2)
{
    LINE *lp;
    LINE *nlp;
    LINE *plp;
    NUM count;

    if ((num1 < 1) || (num2 > lastnum) || (num1 > num2)) {
	fprintf(stderr, "Bad line numbers for delete\n");
	return FALSE;
    }
    lp = findline(num1);
    if (lp == NULL)
	return FALSE;

    if ((curnum >= num1) && (curnum <= num2)) {
	if (num2 < lastnum)
	    setcurnum(num2 + 1);
	else if (num1 > 1)
	    setcurnum(num1 - 1);
	else
	    curnum = 0;
    }
    count = num2 - num1 + 1;

    if (curnum > num2)
	curnum -= count;

    lastnum -= count;

    while (count-- > 0) {
	nlp = lp->next;
	plp = lp->prev;
	plp->next = nlp;
	nlp->prev = plp;
	lp->next = NULL;
	lp->prev = NULL;
	lp->len = 0;
	free(lp);
	lp = nlp;
    }

    dirty = TRUE;

    return TRUE;
}
Example #11
0
void
vigotocolumn(void)
{
    int x, y;

    if (zmult > 0)
	zmult--;
    findline(&x, &y);
    if (zmult >= 0)
	cs = x + zmult;
    else
	cs = y + zmult;
    if (cs > y)
	cs = y;
    if (cs < x)
	cs = x;
}
Example #12
0
static void
re_arg(char *string)
{
	char *ptr;
	char ch;
	int		len;

	ch = *string;
	ptr = string;
	ptr++;
	while (*ptr != ch) {
		if (*ptr == '\\')
			++ptr;

		if (*ptr == NULL)
			fatal("%s: missing delimiter\n", targ);

		if ((len = mblen(ptr, MB_LEN_MAX)) <= 0)
			len = 1;
		ptr += len;
	}

	/*
	 * The line below was added because compile no longer supports
	 * the fourth argument being passed.  The fourth argument used
	 * to be '/' or '%'.
	 */

	*ptr = NULL;
	if (asc_to_ll(++ptr, &offset) == ERR)
		fatal("%s: illegal offset\n", string);

	/*
	 * The line below was added because INIT which did this for us
	 * was removed from compile in regexp.h
	 */

	string++;
	expbuf = compile(string, (char *)0, (char *)0);
	if (regerrno)
		PERROR(regerrno);
	to_line(findline(expbuf, offset));
}
Example #13
0
int
dodeliv(char *in, char *out, char *arg, int outlen)
{
	char *mout;
	int mlen;
# if D1
	fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:"");
# endif
	if (arg && arg[0])
		chdir(arg);

	mlen = findline(in, &mout, outlen,0L);

	if (mlen>0)
	{
		strncpy(out, mout, outlen);
		free (mout);
	}
	restodir();
	return 0;
}
Example #14
0
void VDSymbolSourceLinkMap::Init(IVDStream *pStream) {
	VDTextStream textStream(pStream);

	mCodeSegments = 0;

	if (!findline(textStream, "Start         Length"))
		throw "can't find segment list";

	while(const char *line = textStream.GetNextLine()) {
		long grp, start, len;

		if (3!=sscanf(line, "%lx:%lx %lx", &grp, &start, &len))
			break;

		if (strstr(line+49, "CODE")) {
			printf("        %04x:%08lx %08lx type code (%dKB)\n", grp, start, len, (len+1023)>>10);

			mCodeSegments |= 1<<grp;

			mSections.push_back(VDSection(start, len, grp));
		}
	}
Example #15
0
void cmd_setpin(void) {
	int pin, value, line;

	getargs(&cmdline, 5, ",");
	if (argc%2 == 0 || argc == 0) error("Invalid syntax");
	pin = getinteger(argv[0]);
	if (pin < 0 || pin > NBRPINS) error("Invalid pin number");
	if (ExtCurrentConfig[pin] >= EXT_COM_RESERVED)  error("Pin is allocated to a communications function");
        Average[pin]=1; // set default average
        value = getinteger(argv[2]);
        if( argc==5 && value == EXT_ANA_IN ) Average[pin] = getinteger(argv[4]); //added KSD
        if (!ExtCfg(pin, value)) error( "Invalid configuration value" );
	if (value == EXT_INT_HI || value == EXT_INT_LO) {
		// we need to set up a software interrupt
		//if (pin == 0) error("Invalid pin number");
		if (argc != 5) error("Line number for the interrupt is not specified");
		line = getinteger(argv[4]);					// get the line number
		inttbl[pin].intp = findline(line, true);                        // and set
		ExtInp(pin, &inttbl[pin].last);					// save the current pin value for the first test
		inttbl[pin].lohi = (value == EXT_INT_HI);                       // and set trigger polarity
	} else if (argc > 3 && value !=EXT_ANA_IN) error("Line number is only used for interrupts");
}
Example #16
0
void doedit(bc *bc, char *text)
{
char *p;
int num;
int i;
	num=atoi(text);
	p=findline(bc, num);
	if(!*p)
	{
		error(bc, "Line %d does not exist.", num);
		return;
	}
	i=0;
	while(*p && *p!='\n')
	{
		if(i<sizeof(bc->workspace)-1)
			bc->workspace[i++] = *p;
		++p;
	}
	bc->workspace[i] = 0;
	bc->flags |= BF_EDIT;
}
Example #17
0
/*
 * Search for a line which contains the specified string.
 * If the string is NULL, then the previously searched for string
 * is used.  The currently searched for string is saved for future use.
 * Returns the line number which matches, or 0 if there was no match
 * with an error printed.
 */
static NUM searchlines(char *str, NUM num1, NUM num2)
{
    LINE *lp;
    int len;

    if ((num1 < 1) || (num2 > lastnum) || (num1 > num2)) {
	fprintf(stderr, "Bad line numbers for search\n");
	return 0;
    }
    if (*str == '\0') {
	if (searchstring[0] == '\0') {
	    fprintf(stderr, "No previous search string\n");
	    return 0;
	}
	str = searchstring;
    }
    if (str != searchstring)
	strcpy(searchstring, str);

    len = strlen(str);

    lp = findline(num1);
    if (lp == NULL)
	return 0;

    while (num1 <= num2) {
	if (findstring(lp, str, len, 0) >= 0)
	    return num1;

	num1++;
	lp = lp->next;
    }

    fprintf(stderr, "Cannot find string \"%s\"\n", str);

    return 0;
}
Example #18
0
/*
 * Insert a new line with the specified text.
 * The line is inserted so as to become the specified line,
 * thus pushing any existing and further lines down one.
 * The inserted line is also set to become the current line.
 * Returns TRUE if successful.
 */
static BOOL insertline(NUM num, char *data, LEN len)
{
    LINE *newlp;
    LINE *lp;

    if ((num < 1) || (num > lastnum + 1)) {
	fprintf(stderr, "Inserting at bad line number\n");
	return FALSE;
    }
    newlp = (LINE *) malloc(sizeof(LINE) + len - 1);
    if (newlp == NULL) {
	fprintf(stderr, "Failed to allocate memory for line\n");
	return FALSE;
    }
    memcpy(newlp->data, data, len);
    newlp->len = len;

    if (num > lastnum)
	lp = &lines;
    else {
	lp = findline(num);
	if (lp == NULL) {
	    free((char *) newlp);
	    return FALSE;
	}
    }

    newlp->next = lp;
    newlp->prev = lp->prev;
    lp->prev->next = newlp;
    lp->prev = newlp;

    lastnum++;
    dirty = TRUE;

    return setcurnum(num);
}
Example #19
0
void showhelp(const char *filename)
{
   char nc,nr,ph;
   char *title,*text;
   union { char *buffer; void *vbuf; } buf; // This is to avoild type-punning issues

   char line[512];
   size_t size;
   char scan;
   int rv,numlines,curr_line;

   nc = getnumcols();
   nr = getnumrows();
   ph = nr - HELP_BOTTOM_MARGIN - HELP_BODY_ROW - 1;
   cls();
   drawbox(0,0,nr,nc-1,HELPPAGE,0x07,HELPBOX);

   drawhorizline(2,0,nc-1,HELPPAGE,0x07,HELPBOX,0); // dumb==0
   if (filename == NULL) { // print file contents
     gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
     cswprint("Filename not given",0x07,HELP_LEFT_MARGIN);
     while (1) {
       inputc(&scan);
       if (scan == ESCAPE) break;
     }
     cls();
     return;
   }

   rv = loadfile(filename,(void **)&buf.vbuf, &size); // load entire file into memory
   if (rv < 0) { // Error reading file or no such file
      sprintf(line, "Error reading file or file not found\n file=%s",filename);
      gotoxy(HELP_BODY_ROW,HELP_LEFT_MARGIN,HELPPAGE);
      cswprint(line,0x07,HELP_LEFT_MARGIN);
      while (1) {
        inputc(&scan);
        if (scan == ESCAPE) break;
      }
      cls();
      return;
   }

   title = buf.buffer;
   text = findline(title,1); // end of first line
   *text++='\0'; // end the title string and increment text

   // Now we have a file just print it.
   gotoxy(1,(nc-strlen(title))/2,HELPPAGE);
   csprint(title,0x07);
   numlines = countlines(text);
   curr_line = 0;
   scan = ESCAPE+1; // anything except ESCAPE

   while(scan != ESCAPE) {
       printtext(text,curr_line);
       gotoxy(HELP_BODY_ROW-1,nc-HELP_RIGHT_MARGIN,HELPPAGE);
       if (curr_line > 0)
          putch(HELP_MORE_ABOVE,0x07,HELPPAGE);
       else putch(' ',0x07,HELPPAGE);
       gotoxy(nr-HELP_BOTTOM_MARGIN+1,nc-HELP_RIGHT_MARGIN,HELPPAGE);
       if (curr_line < numlines - ph)
          putch(HELP_MORE_BELOW,0x07,HELPPAGE);
       else putch(' ',0x07,HELPPAGE);

       inputc(&scan); // wait for user keypress

       switch(scan) {
         case HOMEKEY:
             curr_line = 0;
             break;
         case ENDKEY:
             curr_line = numlines;
             break;
         case UPARROW:
             curr_line--;
             break;
         case DNARROW:
             curr_line++;
             break;
         case PAGEUP:
             curr_line -= ph;
             break;
         case PAGEDN:
             curr_line += ph;
             break;
         default:
           break;
       }
       if (curr_line > numlines - ph) curr_line = numlines-ph;
       if (curr_line < 0) curr_line = 0;
   }
   cls();
   return;
}
Example #20
0
int Masek::segmentiris_iridian(Masek::IMAGE *eyeimage, char *gndfilename, int *circleiris, int *circlepupil, double *imagewithnoise, int eyelidon, int highlighton, int highlightvalue)
{
	int lpupilradius, upupilradius, lirisradius, uirisradius, reflecthres;
	double scaling;	
	int rowi, coli, ri, rowp, colp, rp, oldrowp;
	double rowid, colid, rid;//LEE: delete rowpd, colpd, rpd;
	int irl, iru, icl, icu;
	int imgsize[2];
	IMAGE* imagepupil, *topeyelid, *bottomeyelid;
	int i, j, k, m;
	int linecount;
	double *lines;
	int *xl, *yl;
	int *y2;
	int yla;
//	int iris_xpart[8], iris_ypart[8], iris_valid[8], pupil_xpart[8], pupil_ypart[8], pupil_valid[8];//LEE:
//	char buffer[100];//LEE:
	FILE *gndfile;
//	char tmpchar;//LEE:
//	int count;//LEE:
//	int tmpr;//LEE:
//	double a, b;
//	int left, right, hasnoise;//LEE:

//% define range of pupil & iris radii

 /* //LEE:Video Data
lpupilradius = 25;
upupilradius = 58;
lirisradius = 62;
uirisradius = 78;*/

/*  //LEE:Video Data
lpupilradius = 12;
upupilradius = 58;
lirisradius = 60;
uirisradius = 80;*/

//%CASIA
lpupilradius = 28;
upupilradius = 75;
lirisradius = 80;
uirisradius = 150;

/*%    %LIONS
%    lpupilradius = 32;
%    upupilradius = 85;
%    lirisradius = 145;
%    uirisradius = 169;
*/

//% define scaling factor to speed up Hough transform
scaling = 0.4;

reflecthres = 240;

//read in iris and pupil boundaries.
gndfile = fopen(gndfilename, "r");
if (gndfile==NULL)
{
	printf("could not open gndfile %s \n", gndfilename);
	return -1;
}
fscanf(gndfile, "%d %d %d %d %d %d",&rowi, &coli, &ri, &rowp, &colp, &rp);
fclose(gndfile);


//% find the iris boundary


circleiris[0] = rowi;
circleiris[1] = coli;
circleiris[2] = ri;

//printf("iris is %d %d %d\n", rowi, coli, ri);

rowid = (double)rowi;
colid = (double)coli;
rid = (double)ri;

irl = roundND(rowid-rid);
iru = roundND(rowid+rid);
icl = roundND(colid-rid);
icu = roundND(colid+rid);

imgsize[0] = eyeimage->hsize[0];
imgsize[1] = eyeimage->hsize[1];

if (irl < 1 )
    irl = 1;


if (icl < 1)
    icl = 1;


if (iru > imgsize[0])
    iru = imgsize[0];


if (icu > imgsize[1])
    icu = imgsize[1];
//printf("irl is %d, icl is %d iru is %d, icu is %d\n", irl , icl, iru, icu);

//% to find the inner pupil, use just the region within the previously
//% detected iris boundary
imagepupil = (IMAGE*) malloc (sizeof(IMAGE));

imagepupil->hsize[0] = iru-irl+1;
imagepupil->hsize[1] = icu-icl+1;
imagepupil->data = (unsigned char*)malloc(sizeof(unsigned char)*imagepupil->hsize[0]*imagepupil->hsize[1]);

for (i = irl-1, k=0; i<iru; i++,k++)
{
	for (j = icl-1, m=0; j<icu; j++, m++)
		imagepupil->data[k*imagepupil->hsize[1]+m] = eyeimage->data[i*eyeimage->hsize[1]+j];
}

//printimage(imagepupil, "imagepupil.txt");
//%find pupil boundary
//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.25,1.00,1.00, &rowp, &colp, &rp);
//printf("pupil is %d %d %d\n", rowp, colp, rp);

oldrowp = rowp-irl;
/*rowpd = (double)rowp;
colpd = (double)colp;
rpd = (double)rp;

rowpd = (double)irl + rowp;
colpd = (double)icl + colp;

rowp = roundND(rowpd);
colp = roundND(colpd);
 */
circlepupil[0] = rowp;
circlepupil[1] = colp;
circlepupil[2] = rp;

//printf("pupil is %d %d %d\n", rowp, colp, rp);

//% set up array for recording noise regions
//% noise pixels will have NaN values
for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
	imagewithnoise[i] = eyeimage->data[i];

if (eyelidon==1)
{
//%find top eyelid

	topeyelid = (IMAGE*)malloc(sizeof(IMAGE));
	topeyelid->hsize[0] = oldrowp-rp;
	topeyelid->hsize[1] = imagepupil->hsize[1];
	topeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*topeyelid->hsize[0]*topeyelid->hsize[1]);

	if (topeyelid->hsize[0]>0 && topeyelid->hsize[1]>0)
	{
		for (i = 0; i<(oldrowp-rp)*imagepupil->hsize[1]; i++)
			topeyelid->data[i] = imagepupil->data[i];

		linecount = findline(topeyelid, &lines);
	}
	else 
		linecount=0;

	if (linecount > 0)
	{
		xl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);
		yl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);

		linescoords(lines, topeyelid->hsize[0], topeyelid->hsize[1], xl, yl);

		yla = -1;
		for (i = 0; i<topeyelid->hsize[1]; i++)
		{
			yl[i] = yl[i]+irl-1;
			xl[i]=xl[i]+icl-1;
			if (yla<yl[i])
				yla = yl[i];

			imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
		}
		y2 = (int*)malloc(sizeof(int)*yla);
		for (i = 0; i<yla; i++)
		{
			y2[i] = i+1;
			for (j = 0; j<topeyelid->hsize[1]; j++)
				imagewithnoise[(y2[i]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
		}
		free (xl);
		free (yl);
		free(y2);
		free(lines);
	}


//%find bottom eyelid
	bottomeyelid = (IMAGE*)malloc(sizeof(IMAGE));

	bottomeyelid->hsize[0] = imagepupil->hsize[0]-(oldrowp+rp)+1;
	bottomeyelid->hsize[1] = imagepupil->hsize[1];
	bottomeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);

	if (bottomeyelid->hsize[0]>0 && bottomeyelid->hsize[1]>0)
	{
		memcpy(bottomeyelid->data, &imagepupil->data[(oldrowp+rp-1)*imagepupil->hsize[1]], bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);


		linecount = findline(bottomeyelid, &lines);
	}
	else
		linecount=0;


	if (linecount > 0)
	{
		xl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);
		yl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);

		linescoords(lines, bottomeyelid->hsize[0], bottomeyelid->hsize[1], xl, yl);

	/*fid = fopen("x1.txt", "w");
	for (i=0; i<bottomeyelid->hsize[1]; i++)
		fprintf(fid, "%d %d\n", i+1, xl[i]);
	fclose(fid);

	fid = fopen("y1.txt", "w");
	for (i=0; i<bottomeyelid->hsize[1]; i++)
		fprintf(fid, "%d %d\n", i+1, yl[i]);
	fclose(fid);*/

		yla = eyeimage->hsize[0];
	
		for (i = 0; i<bottomeyelid->hsize[1]; i++)
		{
			yl[i] = yl[i]+irl+oldrowp+rp-2;
			xl[i]=xl[i]+icl-1;
			if ( yla>yl[i])
				yla = yl[i];

			imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
		}
		y2 = (int*)malloc(sizeof(int)*(eyeimage->hsize[0]-yla+1));
		for (i = yla-1; i<eyeimage->hsize[0]; i++)
		{
			y2[i-yla+1] = i+1;
			for (j = 0; j<bottomeyelid->hsize[1]; j++)
				imagewithnoise[(y2[i-yla+1]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
		}
		free (xl);
		free (yl);
		free(y2);
		free(lines);
	}	   
	free(topeyelid->data);
	free(topeyelid);
	free(bottomeyelid->data);
	free(bottomeyelid);

}
/*fid = fopen("imagewithnoise.txt", "w");
for (i = 0; i<eyeimage->hsize[0]; i++)
	for (j = 0; j<eyeimage->hsize[1]; j++)
	{
		if (gccport::_isnan(imagewithnoise[i*eyeimage->hsize[1]+j]))
				fprintf(fid, "%d %d NaN\n", i+1, j+1);
		else
			fprintf(fid, "%d %d %f\n", i+1, j+1, imagewithnoise[i*eyeimage->hsize[1]+j]);
	}
fclose(fid);
*/

/*%For CASIA, eliminate eyelashes by thresholding
%ref = eyeimage < 100;
%coords = find(ref==1);
%imagewithnoise(coords) = NaN;
*/
	if (highlighton==1)
	{
		for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
			if (eyeimage->data[i]>highlightvalue)
				imagewithnoise[i] = sqrt((double)-1);
	}

	free(imagepupil->data);
	free(imagepupil);
	printf("leaving segmentiris\n");
	return 0;

}
Example #21
0
//LEE:: segmentation for video images
void Masek::segmentiris(Masek::IMAGE *eyeimage, int *circleiris, int *circlepupil, double *imagewithnoise, int eyelidon, int highlighton, int highlightvalue)
{
	int lpupilradius, upupilradius, lirisradius, uirisradius, reflecthres;
	double scaling;	
	int rowi, coli, ri, rowp, colp, rp, oldrowp;
	double rowid, colid, rid, rowpd, colpd, rpd;
	int irl, iru, icl, icu;
	int imgsize[2];
	IMAGE* imagepupil, *topeyelid, *bottomeyelid;
	int i, j, k, m;
	int linecount;
	double *lines;
	int *xl, *yl;
	int *y2;
	int yla;

	//% define range of pupil & iris radii
	//LEE:Video Data
	//lpupilradius = 25;
	//lpupilradius = 22;
	//in small pupil, 12, 20 works very well.
	//in big pupil, 20, 55
	//the best result 14, 42;
	lpupilradius = 14;//
	upupilradius = 42;
	lirisradius = 62;
	uirisradius = 78;

	 /* //%CASIA
	lpupilradius = 28;
	upupilradius = 75;
	lirisradius = 80;
	uirisradius = 150;*/


	/*%    %LIONS
	%    lpupilradius = 32;
	%    upupilradius = 85;
	%    lirisradius = 145;
	%    uirisradius = 169;
	*/

	//% define scaling factor to speed up Hough transform
	scaling = 0.4;

	reflecthres = 240;
	//reflecthres = 100;

	//% find the iris boundary
	findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.20, 0.19, 1.00, 0.00, &rowi, &coli,&ri);
	//LEE:
	//findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.19, 0.13, 1.00, 0.00, &rowi, &coli,&ri);
	//findcircle(eyeimage, lirisradius, uirisradius, scaling, 2, 0.19, 0.11, 1.00, 0.00, &rowi, &coli,&ri);
	/*rowi = 215;
	coli = 345;
	ri = 115;*/
	/*rowi = 235;
	coli = 275;
	ri = 117;*/

	circleiris[0] = rowi;
	circleiris[1] = coli;
	circleiris[2] = ri;

	printf("iris is %d %d %d\n", rowi, coli, ri);

	rowid = (double)rowi;
	colid = (double)coli;
	rid = (double)ri;

	irl = roundND(rowid-rid);
	iru = roundND(rowid+rid);
	icl = roundND(colid-rid);
	icu = roundND(colid+rid);

	imgsize[0] = eyeimage->hsize[0];
	imgsize[1] = eyeimage->hsize[1];

	if (irl < 1 )
		irl = 1;


	if (icl < 1)
		icl = 1;


	if (iru > imgsize[0])
		iru = imgsize[0];


	if (icu > imgsize[1])
		icu = imgsize[1];
	printf("irl is %d, icl is %d iru is %d, icu is %d\n", irl , icl, iru, icu);

	//% to find the inner pupil, use just the region within the previously
	//% detected iris boundary
	imagepupil = (IMAGE*) malloc (sizeof(IMAGE));

	imagepupil->hsize[0] = iru-irl+1;
	imagepupil->hsize[1] = icu-icl+1;

	imagepupil->data = (unsigned char*)malloc(sizeof(unsigned char)*imagepupil->hsize[0]*imagepupil->hsize[1]);

	for (i = irl-1, k=0; i<iru; i++,k++)
	{
		for (j = icl-1, m=0; j<icu; j++, m++)
			imagepupil->data[k*imagepupil->hsize[1]+m] = eyeimage->data[i*eyeimage->hsize[1]+j];
	}

	//printimage(imagepupil, "imagepupil.txt");
	//%find pupil boundary
	findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.25,1.00,1.00, &rowp, &colp, &rp);
	//LEE:
	//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.25,0.21,1.00,1.00, &rowp, &colp, &rp);
	//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.26,0.24,1.00,1.00, &rowp, &colp, &rp);//Best
	//findcircle(imagepupil, lpupilradius, upupilradius ,0.6,2,0.26,0.25,1.00,1.00, &rowp, &colp, &rp);//Best
	printf("1st: pupil is %d %d %d\n", rowp, colp, rp);

	oldrowp = rowp;
	rowpd = (double)rowp;
	colpd = (double)colp;
	rpd = (double)rp;

	rowpd = (double)irl + rowp;
	colpd = (double)icl + colp;

	rowp = roundND(rowpd);
	colp = roundND(colpd);
	 
	circlepupil[0] = rowp;
	circlepupil[1] = colp;
	circlepupil[2] = rp;
	printf("2nd: pupil is %d %d %d\n", rowp, colp, rp);

	//% set up array for recording noise regions
	//% noise pixels will have NaN values
	for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
		imagewithnoise[i] = eyeimage->data[i];

	if (eyelidon==1)
	{

		//%find top eyelid

		topeyelid = (IMAGE*)malloc(sizeof(IMAGE));
		topeyelid->hsize[0] = oldrowp-rp;
		topeyelid->hsize[1] = imagepupil->hsize[1];
		topeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*topeyelid->hsize[0]*topeyelid->hsize[1]);

		if (topeyelid->hsize[0]>0 && topeyelid->hsize[1]>0)
		{
			for (i = 0; i<(oldrowp-rp)*imagepupil->hsize[1]; i++)
				topeyelid->data[i] = imagepupil->data[i];

			linecount = findline(topeyelid, &lines);
		}
		else 
			linecount=0;

		if (linecount > 0)
		{
			xl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);
			yl = (int*)malloc(sizeof(int)*topeyelid->hsize[1]);

			linescoords(lines, topeyelid->hsize[0], topeyelid->hsize[1], xl, yl);

			yla = -1;
			for (i = 0; i<topeyelid->hsize[1]; i++)
			{
				yl[i] = yl[i]+irl-1;
				xl[i]=xl[i]+icl-1;
				if (yla<yl[i])
					yla = yl[i];

				imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
			}
			y2 = (int*)malloc(sizeof(int)*yla);
			for (i = 0; i<yla; i++)
			{
				y2[i] = i+1;
				for (j = 0; j<topeyelid->hsize[1]; j++)
					imagewithnoise[(y2[i]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
			}
			free (xl);
			free (yl);
			free(y2);
			free(lines);
		}

		
		//%find bottom eyelid
		bottomeyelid = (IMAGE*)malloc(sizeof(IMAGE));

		bottomeyelid->hsize[0] = imagepupil->hsize[0]-(oldrowp+rp)+1;
		bottomeyelid->hsize[1] = imagepupil->hsize[1];
		bottomeyelid->data = (unsigned char*) malloc(sizeof(unsigned char)*bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);


		if (bottomeyelid->hsize[0]>0 && bottomeyelid->hsize[1]>0)
		{	
			memcpy(bottomeyelid->data, &imagepupil->data[(oldrowp+rp-1)*imagepupil->hsize[1]], bottomeyelid->hsize[0]*bottomeyelid->hsize[1]);	
			linecount = findline(bottomeyelid, &lines);
		}
		else
			linecount=0;

		if (linecount > 0)
		{
			xl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);
			yl = (int*)malloc(sizeof(int)*bottomeyelid->hsize[1]);

			linescoords(lines, bottomeyelid->hsize[0], bottomeyelid->hsize[1], xl, yl);

			/*fid = fopen("x1.txt", "w");
			for (i=0; i<bottomeyelid->hsize[1]; i++)
				fprintf(fid, "%d %d\n", i+1, xl[i]);
			fclose(fid);

		fid = fopen("y1.txt", "w");
		for (i=0; i<bottomeyelid->hsize[1]; i++)
			fprintf(fid, "%d %d\n", i+1, yl[i]);
		fclose(fid);*/

			yla = eyeimage->hsize[0];
		
			for (i = 0; i<bottomeyelid->hsize[1]; i++)
			{
				yl[i] = yl[i]+irl+oldrowp+rp-2;
				xl[i]=xl[i]+icl-1;
				if ( yla>yl[i])
					yla = yl[i];

				imagewithnoise[(yl[i]-1)*eyeimage->hsize[1]+xl[i]-1] = sqrt((double)-1); // Lee: added cast
			}
			y2 = (int*)malloc(sizeof(int)*(eyeimage->hsize[0]-yla+1));
			for (i = yla-1; i<eyeimage->hsize[0]; i++)
			{
				y2[i-yla+1] = i+1;
				for (j = 0; j<bottomeyelid->hsize[1]; j++)
					imagewithnoise[(y2[i-yla+1]-1)*eyeimage->hsize[1]+xl[j]-1] = sqrt((double)-1); // Lee: added cast
			}
			free (xl);
			free (yl);
			free(y2);
			free(lines);
		}
		free(topeyelid->data);
		free(topeyelid);
		free(bottomeyelid->data);
		free(bottomeyelid);

	}
	/*fid = fopen("imagewithnoise.txt", "w");
	for (i = 0; i<eyeimage->hsize[0]; i++)
		for (j = 0; j<eyeimage->hsize[1]; j++)
		{
			if (gccport::_isnan(imagewithnoise[i*eyeimage->hsize[1]+j]))
					fprintf(fid, "%d %d NaN\n", i+1, j+1);
			else
				fprintf(fid, "%d %d %f\n", i+1, j+1, imagewithnoise[i*eyeimage->hsize[1]+j]);
		}
	fclose(fid);
	*/

	/*%For CASIA, eliminate eyelashes by thresholding
	%ref = eyeimage < 100;
	%coords = find(ref==1);
	%imagewithnoise(coords) = NaN;
	*/
	if (highlighton==1)
	{
		for (i = 0; i<eyeimage->hsize[0]*eyeimage->hsize[1]; i++)
			if (eyeimage->data[i]>highlightvalue)
				imagewithnoise[i] = sqrt((double)-1); // Lee: added cast
	}

	free(imagepupil->data);
	free(imagepupil);
}
Example #22
0
/*
 * Do the substitute command.
 * The current line is set to the last substitution done.
 */
static void subcommand(char *cp, NUM num1, NUM num2)
{
    int delim;
    char *oldstr;
    char *newstr;
    LEN oldlen;
    LEN newlen;
    LEN deltalen;
    LEN offset;
    LINE *lp;
    LINE *nlp;
    BOOL globalflag;
    BOOL printflag;
    BOOL didsub;
    BOOL needprint;

    if ((num1 < 1) || (num2 > lastnum) || (num1 > num2)) {
	fprintf(stderr, "Bad line range for substitute\n");
	return;
    }
    globalflag = FALSE;
    printflag = FALSE;
    didsub = FALSE;
    needprint = FALSE;

    if (isblank(*cp) || (*cp == '\0')) {
	fprintf(stderr, "Bad delimiter for substitute\n");
	return;
    }
    delim = *cp++;
    oldstr = cp;

    cp = strchr(cp, delim);
    if (cp == NULL) {
	fprintf(stderr, "Missing 2nd delimiter for substitute\n");
	return;
    }
    *cp++ = '\0';

    newstr = cp;
    cp = strchr(cp, delim);
    if (cp)
	*cp++ = '\0';
    else
	cp = "";

    while (*cp)
	switch (*cp++) {
	case 'g':
	    globalflag = TRUE;
	    break;

	case 'p':
	    printflag = TRUE;
	    break;

	default:
	    fprintf(stderr, "Unknown option for substitute\n");
	    return;
	}

    if (*oldstr == '\0') {
	if (searchstring[0] == '\0') {
	    fprintf(stderr, "No previous search string\n");
	    return;
	}
	oldstr = searchstring;
    }
    if (oldstr != searchstring)
	strcpy(searchstring, oldstr);

    lp = findline(num1);
    if (lp == NULL)
	return;

    oldlen = strlen(oldstr);
    newlen = strlen(newstr);
    deltalen = newlen - oldlen;
    offset = 0;

    while (num1 <= num2) {
	offset = findstring(lp, oldstr, oldlen, offset);
	if (offset < 0) {
	    if (needprint) {
		printlines(num1, num1, FALSE);
		needprint = FALSE;
	    }
	    offset = 0;
	    lp = lp->next;
	    num1++;
	    continue;
	}
	needprint = printflag;
	didsub = TRUE;
	dirty = TRUE;

	/*
	 * If the replacement string is the same size or shorter
	 * than the old string, then the substitution is easy.
	 */
	if (deltalen <= 0) {
	    memcpy(&lp->data[offset], newstr, newlen);

	    if (deltalen) {
		memcpy(&lp->data[offset + newlen],
		       &lp->data[offset + oldlen],
		       lp->len - offset - oldlen);

		lp->len += deltalen;
	    }
	    offset += newlen;
	    if (globalflag)
		continue;

	    if (needprint) {
		printlines(num1, num1, FALSE);
		needprint = FALSE;
	    }
	    lp = nlp->next;
	    num1++;
	    continue;
	}
	/*
	 * The new string is larger, so allocate a new line
	 * structure and use that.  Link it in in place of
	 * the old line structure.
	 */
	nlp = (LINE *) malloc(sizeof(LINE) + lp->len + deltalen);
	if (nlp == NULL) {
	    fprintf(stderr, "Cannot get memory for line\n");
	    return;
	}
	nlp->len = lp->len + deltalen;

	memcpy(nlp->data, lp->data, offset);

	memcpy(&nlp->data[offset], newstr, newlen);

	memcpy(&nlp->data[offset + newlen],
	       &lp->data[offset + oldlen],
	       lp->len - offset - oldlen);

	nlp->next = lp->next;
	nlp->prev = lp->prev;
	nlp->prev->next = nlp;
	nlp->next->prev = nlp;

	if (curline == lp)
	    curline = nlp;

	free(lp);
	lp = nlp;

	offset += newlen;

	if (globalflag)
	    continue;

	if (needprint) {
	    printlines(num1, num1, FALSE);
	    needprint = FALSE;
	}
	lp = lp->next;
	num1++;
    }

    if (!didsub)
	fprintf(stderr, "No substitutions found for \"%s\"\n", oldstr);
}
Example #23
0
int
main(int argc,char **argv)
{
	/* read query from stdin, expect name of indexes in argv[1] */
	static FILE *fa, *fb, *fc;
	char nma[PATH_MAX], nmb[PATH_MAX], nmc[PATH_MAX],
	     *qitem[100], *rprog = NULL;
	char nmd[PATH_MAX], grepquery[256];
	static char oldname[30] ;
	static int was =0;
	/* these pointers are unions of pointer to int and pointer to long */
	long *hpt = 0;
	unsigned *master =0;
	int falseflg, nhash, nitem, nfound = 0, frtbl, kk;

	/* special wart for refpart: default is tags only */

	falseflg = 0;

	while (argc > 1 && argv[1][0] == '-')
	{
		switch(argv[1][1])
		{
		case 'a': /* all output, incl. false drops */
			falseflg = 1; 
			break;
		case 'r':
			argc--; 
			argv++;
			rprog = argv[1];
			break;
		case 'F': /* put out full text */
			full = setfrom(argv[1][2]);
			break;
		case 'T': /* put out tags */
			tags = setfrom(argv[1][2]);
			break;
		case 'i': /* input in argument string */
			argc--; 
			argv++;
			sinput = argv[1];
			break;
		case 's': /*text output to string */
		case 'o':
			argc--; 
			argv++;
			soutput = argv[1];
			if ((intptr_t) argv[2]<16000)
			{
				soutlen = (intptr_t)argv[2];
				argc--; 
				argv++;
			}
			break;
		case 't': /*tag output to string */
			argc--; 
			argv++;
			tagout = argv[1];
			break;
		case 'l': /* length of internal lists */
			argc--; 
			argv++;
			lmaster = atoi(argv[1]);
			break;
		case 'g': /* suppress fgrep search on old files */
			keepold = 0;
			break;
		case 'C': /* coordination level */
			colevel = atoi(argv[1]+2);
# if D1
			fprintf(stderr, "colevel set to %d\n",colevel);
# endif
			break;
		case 'P': /* print term freqs */
			prfreqs=1; 
			break;
		case 'm':
			measure=1; 
			break;
		}
		argc--; 
		argv++;
	}
	if(argc < 2)
		exit(1);
	strcpy (nma, todir(argv[1]));
	if (was == 0 || strcmp (oldname, nma) !=0)
	{
		strcpy (oldname,nma);
		strcpy (nmb, nma); 
		strcpy (nmc, nmb); 
		strcpy(nmd,nma);
		strcat (nma, ".ia");
		strcat (nmb, ".ib");
		strcat (nmc, ".ic");
		strcat (nmd, ".id");
		if (was)
		{
			fclose(fa); 
			fclose(fb); 
			fclose(fc);
		}

		fa = fopen(nma, "r");
		if (fa==NULL)
		{
			strcpy(*fgnamp++ = calloc(strlen(oldname)+2,1), oldname);
			fb=NULL;
			goto search;
		}
		fb = fopen(nmb, "r");
		fc = fopen(nmc, "r");
		was =1;
		if (fb== NULL || fc ==NULL)
		{
			err("Index incomplete %s", nmb);
			exit(1);
		}
		indexdate = gdate(fb);
		fd = fopen(nmd, "r");
	}
	fseek (fa, 0, SEEK_SET);
	fread (&nhash, sizeof(nhash), 1, fa);
	fread (&iflong, sizeof(iflong), 1, fa);
	if(master==0)
		master = calloc (lmaster, iflong? sizeof(long): sizeof(unsigned));
	hpt = calloc(nhash, sizeof(*hpt));
	kk=fread( hpt, sizeof(*hpt), nhash, fa);
# if D1
	fprintf(stderr,"read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash);
# endif
	assert (kk==nhash);
	hfreq = calloc(nhash, sizeof(*hfreq));
	assert (hfreq != NULL);
	frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa);
	hfrflg = (frtbl == nhash);
# if D1
	fprintf(stderr, "read freqs %d\n", frtbl);
# endif

search:
	while (1)
	{
		nitem = getq(qitem);
		if (measure) tick();
		if (nitem==0) continue;
		if (nitem < 0) break;
		if (tagout) tagout[0]=0;
		if (fb!=NULL)
		{
			nfound = doquery(hpt, nhash, fb, nitem, qitem, master);
# if D1
			fprintf(stderr,"after doquery nfound %d\n", nfound);
# endif
			fgnamp=fgnames;
			if (falseflg == 0)
				nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full);
# if D1
			fprintf(stderr,"after baddrop nfound %d\n", nfound);
# endif
		}
		if (fgnamp>fgnames)
		{
			char **fgp, tgbuff[100];
			int k;
# if D1
			fprintf(stderr, "were %d bad files\n", fgnamp-fgnames);
# endif
			memset(tgbuff, 0, sizeof (tgbuff));
			grepquery[0]=0;
			for(k=0; k<nitem; k++)
			{
				strcat(grepquery, " ");
				strcat(grepquery, qitem[k]);
			}
# if D1
			fprintf(stderr, "grepquery %s\n",grepquery);
# endif
			for(fgp=fgnames; fgp<fgnamp; fgp++)
			{
# if D1
				fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery);
# endif
				makefgrep(*fgp);
# if D1
				fprintf(stderr, "grepmade\n");
# endif
				if (tagout==0)
					tagout=tgbuff;
				grepcall(grepquery, tagout, *fgp);
# if D1
				fprintf(stderr, "tagout now /%s/\n", tagout);
# endif
				if (full)
				{
					int nout;
					char *bout;
					char *tagp;
					char *oldtagp;
					tagp = tagout;
					while (*tagp) {
						oldtagp = tagp;
						while (*tagp && (*tagp != '\n')) 
							tagp++;
						if (*tagp) 
							tagp++;
				                nout = findline(oldtagp, &bout, 1000, 0L);
						if (nout > 0)
						{
							fputs(bout, stdout);
							free(bout); 
						}
					}
				}
			}
		}
		if (tags)
			result (master, nfound >tags ? tags: nfound, fc);
		if (measure) tock();
	}
	/* NOTREACHED */
	return 0;
}