Exemple #1
0
    off_t
loadsetsize( FILE *tran )
{
    char	tline[ LINE_MAX ], line[ LINE_MAX ];
    char	**targv;
    int		tac, linenum = 0;
    off_t	size = 0;

    while ( fgets( tline, LINE_MAX, tran ) != NULL ) {
	linenum++;
	strcpy( line, tline );
	if (( tac = argcargv( tline, &targv )) == 0 ) {
	    continue;
	}

    	switch ( *targv[ 0 ] ) {
	case 'a':
	case 'f':
	    break;

	default:
	    continue;
	}

	linecheck( line, tac, linenum );
	size += strtoofft( targv[ 6 ], NULL, 10 );
    }

    rewind( tran );

    return( size );
}
Exemple #2
0
    off_t
lcksum_loadsetsize( FILE *tran, char *prefix )
{
    char	tline[ LINE_MAX ], line[ LINE_MAX ];
    char	*d_path = NULL;
    char	**targv;
    int		tac, linenum = 0;
    off_t	size = 0;

    while ( fgets( tline, LINE_MAX, tran ) != NULL ) {
	linenum++;
	strcpy( line, tline );
	if (( tac = argcargv( tline, &targv )) <= 1 ) {
	    continue;
	}

	if ( prefix != NULL ) {
	    if (( d_path = decode( targv[ 1 ] )) == NULL ) {
		fprintf( stderr, "%d: path too long\n", linenum );
		exit( 2 );
	    }
	    if ( strncmp( d_path, prefix, strlen( prefix )) != 0 ) {
		continue;
	    }
	}

	switch ( *targv[ 0 ] ) {
	case 'a':
	case 'f':
	    linecheck( line, tac, linenum );
	    size += strtoofft( targv[ 6 ], NULL, 10 );

	default:
	    size += PROGRESSUNIT;
	    break;
	}
    }
	
    rewind( tran );
    return( size );
}
Exemple #3
0
    off_t
applyloadsetsize( FILE *tran )
{
    char	tline[ LINE_MAX ], line[ LINE_MAX ];
    char	**targv;
    int		tac, linenum = 0;
    off_t	size = 0;

    while ( fgets( tline, LINE_MAX, tran ) != NULL ) {
	linenum++;
	strcpy( line, tline );
	/* skip empty lines and transcript marker lines */
	if (( tac = argcargv( tline, &targv )) <= 1 ) {
	    continue;
	}

	switch ( *targv[ 0 ] ) {
	case '+':
	    switch ( *targv[ 1 ] ) {
	    case 'a':
	    case 'f':
		linecheck( line, tac, linenum );
		size += strtoofft( targv[ 7 ], NULL, 10 );

	    default:
		break;
	    }

	default:
	    break;
	}

	size += PROGRESSUNIT;
    }

    rewind( tran );

    return( size );
}
Exemple #4
0
static int range_check(struct index ind, int count, char *lbuff)
{
	int i,j,k,cc1,cc2,start,force=0;
	char tmpbuff[BUFFERLEN],errbuff[BUFFERLEN];

	for (i=count;i<ind.num+1;i++) {
		if (ind.p[i].enc[0]==range_close) {
			SPRINTF(errbuff,"Warning: Unmatched range closing operator \'%c\',",range_close);
			SAPPENDF(errbuff,"%s.",ind.idx[0]);
			warn_printf(efp, "%s\n", errbuff);
			ind.p[i].enc++;
		}
		if (ind.p[i].enc[0]==range_open) {
			start=i;
			ind.p[i].enc++;
			for (j=i;j<ind.num+1;j++) {
				if (strcmp(ind.p[start].enc,ind.p[j].enc)) {
					if (ind.p[j].enc[0]==range_close) {
						ind.p[j].enc++;
						ind.p[j].enc[0]='\0';
						force=1;
						break;
					}
					else if (j!=i && ind.p[j].enc[0]==range_open) {
						SPRINTF(errbuff,"Warning: Unmatched range opening operator \'%c\',",range_open);
						for (k=0;k<ind.words;k++) SAPPENDF(errbuff,"%s.",ind.idx[k]);
						warn_printf(efp, "%s\n", errbuff);
						ind.p[j].enc++;
					}
					if (strlen(ind.p[j].enc)>0) {
						SPRINTF(tmpbuff,"%s%s%s",encap_prefix,ind.p[j].enc,encap_infix);
						SAPPENDF(tmpbuff,"%s%s%s",ind.p[j].page,encap_suffix,delim_n);
						linecheck(lbuff,tmpbuff);
					}
				}
			}
			if (j==ind.num+1) {
					SPRINTF(errbuff,"Warning: Unmatched range opening operator \'%c\',",range_open);
					for (k=0;k<ind.words;k++) SAPPENDF(errbuff,"%s.",ind.idx[k]);
					warn_printf(efp, "%s\n", errbuff);
			}
			i=j-1;
		}
		else if (prange && i<ind.num) {
			if (chkcontinue(ind.p,i)
				&& (!strcmp(ind.p[i].enc,ind.p[i+1].enc)
				|| ind.p[i+1].enc[0]==range_open))
				continue;
			else {
				i++;
				break;
			}
		}
		else {
			i++;
			break;
		}
	}
	cc1=pnumconv(ind.p[i-1].page,ind.p[i-1].attr[0]);
	cc2=pnumconv(ind.p[count].page,ind.p[count].attr[0]);
	if (cc1>=cc2+2 || (cc1>=cc2+1 && strlen(suffix_2p)) || force) {
		return i-1;
	}
	else return count;
}
Exemple #5
0
/*   write page block   */
static void printpage(struct index *ind, FILE *fp, int num, char *lbuff)
{
	int i,j,k,cc;
	char buff[BUFFERLEN],tmpbuff[BUFFERLEN],errbuff[BUFFERLEN];

	buff[0]=tmpbuff[0]='\0';

	crcheck(lbuff,fp);
	line_length=strlen(lbuff);

	for(j=0;j<ind[num].num;j++) {
		cc=range_check(ind[num],j,lbuff);
		if (cc>j) {
			if (pnumconv(ind[num].p[j].page,ind[num].p[j].attr[0])==pnumconv(ind[num].p[cc].page,ind[num].p[cc].attr[0])) {
				j=cc-1;
				continue;
			}
/* range process */
			if (ind[num].p[j].enc[0]==range_open
				|| ind[num].p[j].enc[0]==range_close)
				ind[num].p[j].enc++;
			if (strlen(ind[num].p[j].enc)>0) {
				SPRINTF(buff,"%s%s%s",encap_prefix,ind[num].p[j].enc,encap_infix);
			}
			if (strlen(suffix_3p)>0 && (pnumconv(ind[num].p[cc].page,ind[num].p[cc].attr[0])-pnumconv(ind[num].p[j].page,ind[num].p[j].attr[0]))==2) {
				SAPPENDF(buff,"%s%s",ind[num].p[j].page,suffix_3p);
			}
			else if (strlen(suffix_mp)>0 && (pnumconv(ind[num].p[cc].page,ind[num].p[cc].attr[0])-pnumconv(ind[num].p[j].page,ind[num].p[j].attr[0]))>=2) {
				SAPPENDF(buff,"%s%s",ind[num].p[j].page,suffix_mp);
			}
			else if (strlen(suffix_2p)>0 && (pnumconv(ind[num].p[cc].page,ind[num].p[cc].attr[0])-pnumconv(ind[num].p[j].page,ind[num].p[j].attr[0]))==1) {
				SAPPENDF(buff,"%s%s",ind[num].p[j].page,suffix_2p);
			}
			else {
				SAPPENDF(buff,"%s%s",ind[num].p[j].page,delim_r);
				SAPPENDF(buff,"%s",ind[num].p[cc].page);
			}
			SAPPENDF(tmpbuff,"%s",buff);
			buff[0]='\0';
			if (strlen(ind[num].p[j].enc)>0) {
				SAPPENDF(tmpbuff,"%s",encap_suffix);
			}
			linecheck(lbuff,tmpbuff);
			j=cc;
			if (j==ind[num].num) {
				goto PRINT;
			}
			else {
				SAPPENDF(tmpbuff,"%s",delim_n);
				linecheck(lbuff,tmpbuff);
			}
		}
		else if (strlen(ind[num].p[j].enc)>0) {
/* normal encap */
			if (ind[num].p[j].enc[0]==range_close) {
				SPRINTF(errbuff,"Warning: Unmatched range closing operator \'%c\',",range_close);
				for (i=0;i<ind[num].words;i++) SAPPENDF(errbuff,"%s.",ind[num].idx[i]);
				warn_printf(efp, "%s\n", errbuff);
				ind[num].p[j].enc++;
			}
			if (strlen(ind[num].p[j].enc)>0) {
				SAPPENDF(tmpbuff,"%s%s%s",encap_prefix,ind[num].p[j].enc,encap_infix);
				SAPPENDF(tmpbuff,"%s%s%s",ind[num].p[j].page,encap_suffix,delim_n);
				linecheck(lbuff,tmpbuff);
			}
			else {
				SAPPENDF(tmpbuff,"%s%s",ind[num].p[j].page,delim_n);
				linecheck(lbuff,tmpbuff);
			}
		}
		else {
/* no encap */
			SAPPENDF(tmpbuff,"%s%s",ind[num].p[j].page,delim_n);
			linecheck(lbuff,tmpbuff);
		}
	}

	if (ind[num].p[j].enc[0]==range_open) {
		SPRINTF(errbuff,"Warning: Unmatched range opening operator \'%c\',",range_open);
		for (k=0;k<ind[num].words;k++) SAPPENDF(errbuff,"%s.",ind[num].idx[k]);
		warn_printf(efp, "%s\n", errbuff);
		ind[num].p[j].enc++;
	}
	else if (ind[num].p[j].enc[0]==range_close) {
		SPRINTF(errbuff,"Warning: Unmatched range closing operator \'%c\',",range_close);
		for (k=0;k<ind[num].words;k++) SAPPENDF(errbuff,"%s.",ind[num].idx[k]);
		warn_printf(efp, "%s\n", errbuff);
		ind[num].p[j].enc++;
	}
	if (strlen(ind[num].p[j].enc)>0) {
		SAPPENDF(tmpbuff,"%s%s%s",encap_prefix,ind[num].p[j].enc,encap_infix);
		SAPPENDF(tmpbuff,"%s%s",ind[num].p[j].page,encap_suffix);
	}
	else {
		SAPPENDF(tmpbuff,"%s",ind[num].p[j].page);
	}
	linecheck(lbuff,tmpbuff);

PRINT:
	fputs(lbuff,fp);
	fputs(delim_t,fp);
	lbuff[0]='\0';
}
Exemple #6
0
main(){
	int ch;
	while(ch!=EOF)
		ch=linecheck();
}
Exemple #7
0
int filecheck(const char *check_fname, instream_t check_in,
              const char *in_fname, instream_t in,
              outstream_t out, outstream_t err) {

  char checkbuf[BUFSZ];
  char inbuf[BUFSZ];
  char check_not_buf[BUFSZ];

  unsigned check_linum = 0;
  unsigned in_linum = 0;

  /* For every line in 'check_in', attempt to find a matching line in 'in'. */
  while (check_in(checkbuf, BUFSZ) != -1) {
    const char *checkbuf2 = strip_whitespace(checkbuf);
    ++check_linum;
    checkbuf[BUFSZ-1] = '\0';

    if (!strncmp(checkbuf2, CHECK_NOT_STR, strlen(CHECK_NOT_STR))) {

      strcpy(check_not_buf, strip_whitespace(checkbuf2 + strlen(CHECK_NOT_STR)));
      continue;

    } else if (!strncmp(checkbuf2, CHECK_STR, strlen(CHECK_STR))) {
      
      const char *check = strip_whitespace(checkbuf2 + strlen(CHECK_STR));

      unsigned saved_in_linum = in_linum;
      int col = 0, not_col = 0;
      while (in(inbuf, BUFSZ) != -1) {
        ++in_linum;
        inbuf[BUFSZ-1] = '\0';

        col = linecheck(check, inbuf);
        if (col > 0)
          break;

        if (check_not_buf[0] != '\0') {
          not_col = linecheck(check_not_buf, inbuf);
          if (not_col > 0)
            break;
        }
      }

      if (col == 0 && not_col == 0) {
        diag(err,
             "%s:%d: expected string not found in input: %s",
             check_fname, check_linum, check);
        diag(err,
             "%s:%d:%d: scanning from here",
             in_fname, saved_in_linum, col);
        return 1;
      } else if (not_col > 0) {
        diag(err,
             "%s:%d: CHECK-NOT string found",
             check_fname, check_linum);
        diag(err,
             "%s:%d:%d: here",
             in_fname, saved_in_linum, not_col);
        return 1;
      }

      check_not_buf[0] = '\0';
    }
  }

  return 0;
}
Exemple #8
0
/* Functions */
void Robot_drive_task(void)
{
	Robot_PWM_init();											// Initialize motors
	int32_t pid_coeff[3];										// PID Coefficients
	int8_t e[3];
	int8_t e2[3];
	int32_t u;
	int32_t u2;
	pid_terms_calc(KP, KI, KD, F_SAMP, pid_coeff);
	uint8_t blk_cnt[4];											// Consecutive BLK read counters
	uint8_t num_iterations = 0;

	fw_motors(5, 60); //Test :)
	while(TRUE)
	{
		// Pend on semaphore - Light Sensor values updated
		Semaphore_pend(Sema_lightsense, BIOS_WAIT_FOREVER);
		switch(drivestate)
		{
		case DRIVESTATE_IDLE:
			// Do nothing :)
			break;
		case DRIVESTATE_FWD:
			linedetection(lightsnsr_val, blk_cnt, 0, 1, &num_iterations);
			linecheck(&u, &u2, &num_iterations, num_moves);
			error_calc(lightsnsr_val[0], e);
			error_calc(lightsnsr_val[1], e2);
			u = findu(e, u, pid_coeff);
			u2 = findu(e2, u2, pid_coeff);
			fwd_pid(u, u2, dutycycle);
			break;
		case DRIVESTATE_REV:
			linedetection(lightsnsr_val, blk_cnt, 1, 0, &num_iterations);
			linecheck(&u, &u2, &num_iterations, num_moves);
			error_calc(lightsnsr_val[0], e);
			error_calc(lightsnsr_val[1], e2);
			u = findu(e, u, pid_coeff);
			u2 = findu(e2, u2, pid_coeff);
			rev_pid(u, u2, dutycycle);
			break;
		case DRIVESTATE_STRAFELEFT:
			linedetection(lightsnsr_val, blk_cnt, 2, 3, &num_iterations);
			linecheck(&u, &u2, &num_iterations, num_moves);
			error_calc(lightsnsr_val[0], e);
			error_calc(lightsnsr_val[1], e2);
			u = findu(e, u, pid_coeff);
			u2 = findu(e2, u2, pid_coeff);
			tl_pid(u, u2, dutycycle);
			break;
		case DRIVESTATE_STRAFERIGHT:
			linedetection(lightsnsr_val, blk_cnt, 3, 2, &num_iterations);
			linecheck(&u, &u2, &num_iterations, num_moves);
			error_calc(lightsnsr_val[0], e);
			error_calc(lightsnsr_val[1], e2);
			u = findu(e, u, pid_coeff);
			u2 = findu(e2, u2, pid_coeff);
			tl_pid(u, u2, dutycycle);
			break;
		case DRIVESTATE_TURNCW:
			intersectiondetect(lightsnsr_val, blk_cnt, &num_iterations);
			linecheck(&u, &u2, &num_iterations, num_moves);
			break;
		case DRIVESTATE_TURNCCW:
			intersectiondetect(lightsnsr_val, blk_cnt, &num_iterations);
			linecheck(&u, &u2, &num_iterations, num_moves);
			break;
		}
	}
}