예제 #1
0
static void assemble (flag_t flags) 

{
	extern signed c;
	c = mygetc ();
	while (c != EOF) 
	{
		if (isspace (c)) 
		{
			do 
			{
				c = mygetc ();
			}
			while (isspace (c));
			continue;
		}
		if ((c == '#') || (c == ';')) 
		{
			do 
			{
				c = mygetc ();
			}
			while (nobreak (c));
			continue;
		}
		phy = integer (16);
		reg = integer (16);
		data = integer (16);
		mask = integer (16);
		instr = MDIO16_INSTR (1, 1, phy, reg, 2);
		write (STDOUT_FILENO, &instr, sizeof (instr));
		data = HTOLE16 (data & 0xFFFF);
		write (STDOUT_FILENO, &data, sizeof (data));
		mask = HTOLE16 (mask & 0xFFFF);
		write (STDOUT_FILENO, &mask, sizeof (mask));
		count++;
		if (_anyset (flags, MDIO_VERBOSE)) 
		{
			fprintf (stderr, "INSTR=0x%04X DATA=0x%04X MASK=0x%04X\n", instr, data, mask);
		}
		if ((c == ';') || (c == EOF)) 
		{
			c = mygetc ();
			continue;
		}
		if (_allclr (flags, MDIO_SILENCE)) 
		{
			error (1, 0, "Illegal character or missing terminator: line %d col %d", row, col);
		}
	}
	return;
}
예제 #2
0
파일: getnext.c 프로젝트: hss14/CUnix_hmk
void getnext( int abc, int nextstep[] )
{
	int a, b, c;
	a = mygeta(abc);
	b = mygetb(abc);
	c = mygetc(abc);
	if( (b < BROOM) && (a>0) )
		nextstep[0] = get_abc( fromcup(a,b,BROOM), tocup(a,b,BROOM), c );   //A to B
	if( (c < CROOM) && (a>0) )
		nextstep[1] = get_abc( fromcup(a,c,CROOM), b, tocup(a,c,CROOM) );   //A to C
	if( (a < AROOM) && (b>0) )
		nextstep[2] = get_abc( tocup(b,a,AROOM), fromcup(b,a,AROOM), c );   //B to A
	if( (c < CROOM) && (b>0) )
		nextstep[3] = get_abc( a, fromcup(b,c,CROOM), tocup(b,c,CROOM) );   //B to C
	if( (a < AROOM) && (c>0) )
		nextstep[4] = get_abc( tocup(c,a,AROOM), b, fromcup(c,a,AROOM) );   //C to A
	if( (b < BROOM) && (c>0) )
		nextstep[5] = get_abc( a, tocup(c,b,BROOM), fromcup(c,b,BROOM) );   //C to B
#ifdef HSSDEBUG
int i;
printf("%03d = %d %d %d,", abc, a, b, c);
for (i=0; i<6; i++)
	printf(" %03d,", nextstep[i] );
printf("\n");
#endif
	return;
}
예제 #3
0
파일: decomp16.c 프로젝트: Hooman3/minix
/* G e t b i t s
 *
 * Put curbits bits into index from stdin. Note: only copy 4 uses this.
 * The bits within a byte are in the correct order. But when the bits
 * cross a byte boundry, the lowest bits will be in the higher part of
 * the current byte, and the higher bits will be in the lower part of
 * the next byte.
 */
void getbits()
{
  int have;
  static unsigned curbyte;	/* byte having bits extracted from it */
  static int left;		/* how many bits are left in curbyte */

  inmod = (inmod + 1) & 7;	/* count input mod 8 */
  iindex = curbyte;
  have = left;
  if (curbits - have > 8) {
	iindex |= mygetc() << have;
	have += 8;
  }
  iindex |= ((curbyte = mygetc()) << have) & ~((unsigned) 0xFFFF << curbits);
  curbyte >>= curbits - have;
  left = 8 - (curbits - have);
}
예제 #4
0
static uint16_t integer (unsigned radix) 

{
	extern signed c;
	uint16_t value = 0;
	unsigned digit = 0;
	while ((digit = todigit (c)) < radix) 
	{
		value *= radix;
		value += digit;
		c = mygetc ();
	}
	while (isspace (c)) 
	{
		c = mygetc ();
	}
	return (value);
}
예제 #5
0
void    DemLex (FILE *fpin) {
   /* fpin est un fichier qui a été ouvert correctement */
   leFichier = fpin ;   
   nol       = 1 ;
    noc       = 0 ; 
    ptaschar  = taschar ;

    cc        = mygetc(leFichier) ;
   AvLex () ; 
}
예제 #6
0
static INLINE int
gobble(int c)
{
    int d;
    d = mygetc();
    if (c == d)
	return 1;
    *--outp = d;
    nbuf++;
    return 0;
}
예제 #7
0
static void
skip_comment2(void)
{
    int c;

    while ((c = mygetc()) != '\n' && c != EOF)
	;
    if (c == EOF) {
	lexerror("End of file in a // comment");
	return;
    }
    nexpands=0;
    store_line_number_info(current_incfile, current_line);
    current_line++;
}
예제 #8
0
static size_t myfgets(char* buf,size_t bufsize) {
  static int eof;
  int i;
  size_t j;
  if (eof) return 0;
  for (j=0; j<bufsize-1; ++j) {
    i=mygetc();
    if (i==-2) { eof=1; return j; }
    if (i==-1) return -1;
    if (i=='\n') break;
    buf[j]=i;
  }
  buf[j]=0;
  return j;
}
예제 #9
0
/* Greps the starting number */
int grepFirstNumber(int* ret,int c,FILE* datei,char* vname,char* str,int str_len,int* c_read){
  if(ret[0]!=77)  c = mygetc(str,str_len,datei,c_read); 
  else{
    ret[0]= 0;
    c = ret[1];
  }
  while(isspace(c)) c = mygetc(str,str_len,datei,c_read);
  while(1){
    if(c == '-') {
      *vname='\0';
      return 0;
    }
    else if (isspace(c)) c = mygetc(str,str_len,datei,c_read);
    else{
      if (isdigit(c)){
        *vname=c;
        vname++;
        c = mygetc(str,str_len,datei,c_read);
      }
      else return 1;
    }
  }
  return 2;
}
예제 #10
0
파일: params.c 프로젝트: pombredanne/cliffs
static int EatComment( myFILE *InFile )
  /* ------------------------------------------------------------------------ **
   * Scan to the end of a comment.
   *
   *  Input:  InFile  - Input source.
   *
   *  Output: The character that marks the end of the comment.  Normally,
   *          this will be a newline, but it *might* be an EOF.
   *
   *  Notes:  Because the config files use a line-oriented grammar, we
   *          explicitly exclude the newline character from the list of
   *          whitespace characters.
   *        - Note that both EOF (-1) and the nul character ('\0') are
   *          considered end-of-file markers.
   *
   * ------------------------------------------------------------------------ **
   */
  {
  int c;

  for( c = mygetc( InFile ); ('\n'!=c) && (EOF!=c) && (c>0); c = mygetc( InFile ) )
    ;
  return( c );
  } /* EatComment */
예제 #11
0
파일: params.c 프로젝트: pombredanne/cliffs
static int EatWhitespace( myFILE *InFile )
  /* ------------------------------------------------------------------------ **
   * Scan past whitespace (see ctype(3C)) and return the first non-whitespace
   * character, or newline, or EOF.
   *
   *  Input:  InFile  - Input source.
   *
   *  Output: The next non-whitespace character in the input stream.
   *
   *  Notes:  Because the config files use a line-oriented grammar, we
   *          explicitly exclude the newline character from the list of
   *          whitespace characters.
   *        - Note that both EOF (-1) and the nul character ('\0') are
   *          considered end-of-file markers.
   *
   * ------------------------------------------------------------------------ **
   */
  {
  int c;

  for( c = mygetc( InFile ); isspace( c ) && ('\n' != c); c = mygetc( InFile ) )
    ;
  return( c );
  } /* EatWhitespace */
예제 #12
0
static int
cmygetc(void)
{
    int c;

    for (;;)
    {
	c = mygetc();
	if (c == '/')
	{
	    if (gobble('*'))
		skip_comment();
	    else
		return c;
	} else
	    return c;
    }
}
예제 #13
0
파일: ex5-2.c 프로젝트: momo9/kr-code
// output the result in *pa, return the status
static int getint(double *pa) {
  int c;
  // skip the space
  for (c = mygetc(); isspace(c) && c != EOF; c = mygetc());
  if (c == EOF) return EOF;
  // not a number
  if (!isdigit(c) && c != '+' && c != '-') return 0;

  int sign;
  sign = 1;
  if (c == '+' || c == '-') {
    if (c == '-') sign = -1;
    // have '+' or '-', but not a number
    if (isspace(c = mygetc()) || c == EOF) {
      *pa = 0;
      if (c != EOF) myungetc(c);
      return c;
    }
  }
  // is a number
  *pa = 0;
  for (; isdigit(c) && c != EOF; c = mygetc()) {
    //printf("%c\n", c);
    //getchar();
    *pa = *pa * 10 + (c - '0');
    //printf("%d\n", *pa);
  }
  // the fraction
  if (c == '.') {
    double fac;
    for (fac = 0.1, c = mygetc(); isdigit(c) && c != EOF; c = mygetc(), fac /= 10.0) {
      *pa += (c - '0') * fac;
    }
  }
  *pa *= sign;
  if (c != EOF) myungetc(c);
  return c;
}
예제 #14
0
static void parse_token(struct token *t)
{
    int c;

    while (isspace(c = mygetc()) && (c != '\n'))
        continue;

retry:
    if (isdigit(c)) {
        t->type = NUM;
        t->u.num.start = c - '0';
        while (isdigit(c = mygetc()))
            t->u.num.start = t->u.num.start * 10 + c - '0';
        t->u.num.end = t->u.num.start;
        t->u.num.step = 1;
        if (c == '-') {
            t->u.num.end = 0;
            while (isdigit(c = mygetc()))
                t->u.num.end = t->u.num.end * 10 + c - '0';
            if (t->u.num.end < t->u.num.start)
                parse_err("bad range %u-%u", t->u.num.start, t->u.num.end);
        }
        if (c == '/') {
            t->u.num.step = 0;
            while (isdigit(c = mygetc()))
                t->u.num.step = t->u.num.step * 10 + c - '0';
        }
        myungetc(c);
    } else if (c == '"') {
        char *p = t->u.str;
        t->type = STR;
        while ((c = mygetc()) != '"') {
            if ((c == '\n') || (c == '\r') || (c == EOF))
                parse_err("unexpected newline or end-of-file in string");
            *p++ = c;
            if ((p - t->u.str) >= (sizeof(t->u.str)-1))
                parse_err("string too long");
        }
        *p = '\0';
    } else if (isalpha(c)) {
        char *p = t->u.str;
        t->type = STR;
        *p++ = c;
        while (isalnum(c = mygetc()) || (c == '_')) {
            *p++ = c;
            if ((p - t->u.str) >= (sizeof(t->u.str)-1))
                parse_err("string too long");
        }
        *p = '\0';
        myungetc(c);
    } else if (c == '\\') { /* ignore EOL at line break */
        while (isspace(c = mygetc()) && (c != '\n'))
            continue;
        if (c != '\n')
            parse_err("expected newline after backslash");
        while (isspace(c = mygetc()) && (c != '\n'))
            continue;
        goto retry;
    } else if (c == '#') { /* ignore until EOL */
        while (((c = mygetc()) != EOF) && (c != '\n'))
            continue;
        goto retry;
    } else if ((c == EOF) || (c == '\n')) {
        t->type = EOL;
        t->u.ch = c;
    } else {
        t->type = CHR;
        t->u.ch = c;
    }
}
예제 #15
0
static bool Parameter( DATA_BLOB *buf, myFILE *InFile, bool (*pfunc)(const char *, const char *, void *), int c, void *userdata )
{
	int   i       = 0;    /* Position within bufr. */
	int   end     = 0;    /* bufr[end] is current end-of-string. */
	int   vstart  = 0;    /* Starting position of the parameter value. */
	const char *func    = "params.c:Parameter() -";

	/* Read the parameter name. */
	while( 0 == vstart ) {
		/* Loop until we've found the start of the value. */
		if( i > (buf->length - 2) ) {
			/* Ensure there's space for next char.    */
			uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC );
			if (!tb) {
				DEBUG(0, ("%s Memory re-allocation failure.", func) );
				return False;
			}
			buf->data = tb;
			buf->length += BUFR_INC;
		}

		switch(c) {
			case '=': /* Equal sign marks end of param name. */
				if( 0 == end ) {
					/* Don't allow an empty name.      */
					DEBUG(0, ("%s Invalid parameter name in config. file.\n", func ));
					return False;
				}
				buf->data[end++] = '\0';         /* Mark end of string & advance.   */
				i       = end;              /* New string starts here.         */
				vstart  = end;              /* New string is parameter value.  */
				buf->data[i] = '\0';             /* New string is nul, for now.     */
				break;

			case '\n': /* Find continuation char, else error. */
				i = Continuation( buf->data, i );
				if( i < 0 ) {
					buf->data[end] = '\0';
					DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n", func, buf->data ));
					return True;
				}
				end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i);
				c = mygetc( InFile );       /* Read past eoln.                   */
				break;

			case '\0': /* Shouldn't have EOF within param name. */
			case EOF:
				buf->data[i] = '\0';
				DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, buf->data ));
				return True;

			default:
				if(isspace( c )) {
					/* One ' ' per whitespace region.       */
					buf->data[end] = ' ';
					i = end + 1;
					c = EatWhitespace( InFile );
				} else {
					buf->data[i++] = c;
					end = i;
					c = mygetc( InFile );
				}
		}
	}

	/* Now parse the value. */
	c = EatWhitespace( InFile );  /* Again, trim leading whitespace. */
	while( (EOF !=c) && (c > 0) ) {
		if( i > (buf->length - 2) ) {
			/* Make sure there's enough room. */
			uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR( buf->data, buf->length + BUFR_INC );
			if (!tb) {
				DEBUG(0, ("%s Memory re-allocation failure.", func));
				return False;
			}
			buf->data = tb;
			buf->length += BUFR_INC;
		}

		switch(c) {
			case '\r': /* Explicitly remove '\r' because the older */
				c = mygetc( InFile );   /* version called fgets_slash() which also  */
				break;                /* removes them.                            */

			case '\n': /* Marks end of value unless there's a '\'. */
				i = Continuation( buf->data, i );
				if( i < 0 ) {
					c = 0;
				} else {
					for( end = i; (end >= 0) && isspace((int)buf->data[end]); end-- )
						;
					c = mygetc( InFile );
				}
				break;

			default: /* All others verbatim.  Note that spaces do not advance <end>.  This allows trimming  */
				buf->data[i++] = c;
				if( !isspace( c ) )  /* of whitespace at the end of the line.     */
					end = i;
				c = mygetc( InFile );
				break;
		}
	}
	buf->data[end] = '\0';          /* End of value. */

	return( pfunc( (char *)buf->data, (char *)&buf->data[vstart], userdata ) );   /* Pass name & value to pfunc().  */
}
예제 #16
0
static bool Section( DATA_BLOB *buf, myFILE *InFile, bool (*sfunc)(const char *, void *), void *userdata )
{
	int   c;
	int   i;
	int   end;
	const char *func  = "params.c:Section() -";

	i = 0;      /* <i> is the offset of the next free byte in bufr[] and  */
	end = 0;    /* <end> is the current "end of string" offset.  In most  */
		    /* cases these will be the same, but if the last          */
		    /* character written to bufr[] is a space, then <end>     */
		    /* will be one less than <i>.                             */


	/* Find the end of the section. We must use mb functions for this. */
	if (!FindSectionEnd(InFile)) {
		DEBUG(0, ("%s No terminating ']' character in section.\n", func) );
		return False;
	}

	c = EatWhitespace( InFile );    /* We've already got the '['.  Scan */
					/* past initial white space.        */

	while( (EOF != c) && (c > 0) ) {
		/* Check that the buffer is big enough for the next character. */
		if( i > (buf->length - 2) ) {
			uint8_t *tb = (uint8_t *)SMB_REALLOC_KEEP_OLD_ON_ERROR(buf->data, buf->length+BUFR_INC );
			if(!tb) {
				DEBUG(0, ("%s Memory re-allocation failure.", func) );
				return False;
			}
			buf->data = tb;
			buf->length += BUFR_INC;
		}

		/* Handle a single character other than section end. */
		switch( c ) {
			case '\n': /* Got newline before closing ']'.    */
				i = Continuation( buf->data, i );    /* Check for line continuation.     */
				if( i < 0 ) {
					buf->data[end] = '\0';
					DEBUG(0, ("%s Badly formed line in configuration file: %s\n", func, buf->data ));
					return False;
				}
				end = ( (i > 0) && (' ' == buf->data[i - 1]) ) ? (i - 1) : (i);
					c = mygetc( InFile );             /* Continue with next line.         */
				break;

			default: /* All else are a valid name chars.   */
				if(isspace( c )) {
					/* One space per whitespace region. */
					buf->data[end] = ' ';
					i = end + 1;
					c = EatWhitespace( InFile );
				} else {
					buf->data[i++] = c;
					end = i;
					c = mygetc( InFile );
				}
		}

		if (AtSectionEnd(InFile)) {
			/* Got to the closing bracket. */
			buf->data[end] = '\0';
			if( 0 == end ) {
				/* Don't allow an empty name.       */
				DEBUG(0, ("%s Empty section name in configuration file.\n", func ));
				return False;
			}
			if( !sfunc((char *)buf->data, userdata) )            /* Got a valid name.  Deal with it. */
				return False;
			EatComment( InFile );     /* Finish off the line.             */
			return True;
		}

	}

	/* We arrive here if we've met the EOF before the closing bracket. */
	DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, buf->data ));
	return False;
}
예제 #17
0
파일: main.c 프로젝트: JAlwine/PiLabs
/* Main function starts */
int main()
{
    clock_t begin, end;
    int option, n, temp;
    const char *a="Writing byte by byte\n";
    const char *b="Writing using buffers\n";
    unsigned long i, bytes_to_write = BYTES_TO_READ_WRITE, bytes_to_read = BYTES_TO_READ_WRITE;
    char ch;

    while(1)
    {
        printf("\n 1 - Write without buffering \n 2 - Write with buffering");
        printf("\n 3 - Read without buffering \n 4 - Read with buffering");
        printf(("\n 5 - Exit \n Enter the option: "));
        scanf("%d", &option);
        switch(option)
        {
            case 1: /* Write without buffer */
                begin = clock();
                for (i=0;i<bytes_to_write;i++)
                {
                    ch = a[i%strlen(a)];
                    mywritec(ch);
                }
                end = clock();
                printf("\n Time to write without buffering: %f secs\n",(double)(end - begin)/CLOCKS_PER_SEC);
                break;

            case 2:  /* Write with buffer */
                printf("\n Enter the buffer size in bytes: ");
                scanf("%d", &n);
                mywritebufsetup(n);
                begin = clock();
                for (i=0;i<bytes_to_write;i++)
                {
                    ch = b[i%strlen(b)];
                    myputc(ch);
                }
                mywriteflush();
                end = clock();
                printf("\n Time to write with buffering: %f secs\n",(double)(end - begin)/CLOCKS_PER_SEC);
                break;

            case 3:  /* Read without buffer */
                fd_read = open(READABLE_FILE, O_RDONLY);
                if(fd_read < 0)
                {
                    printf("\n Error opening the readable file \n");
                    return 1;
                }
                begin = clock();
                for (i=0;i<bytes_to_read;i++)
                {  /* you may need to modify this slightly to print the character received and also check for end of file */
                    if(myreadc() == -1)
                    {
                        printf("\n End of file \n");
                        break;
                    }
                }
                end = clock();
                if(close(fd_read))
                {
                    printf("\n Error while closing the file \n ");
                }
                printf("\n Time to read without buffering: %f secs\n",(double)(end - begin)/CLOCKS_PER_SEC);
                break;

            case 4:  /* Read with buffer */
                printf("\n Enter the buffer size in bytes: ");
                scanf("%d", &n);
                myreadbufsetup(n);
                fd_read = open(READABLE_FILE, O_RDONLY);
                if(fd_read < 0)
                {
                    printf("\n Error opening the readable file \n");
                    return 1;
                }
                begin = clock();
                for (i=0;i<bytes_to_read;i++)
                { /* you may need to modify this slightly to print the character received and also check for end of file */
                    if(mygetc() == -1)
                    {
                        printf("\n End of file \n");
                        break;
                    }
                }
                end = clock();
                if(close(fd_read))
                {
                    printf("\n Error while closing the file \n ");
                }
                printf("\n Time to read with buffering: %f secs\n",(double)(end - begin)/CLOCKS_PER_SEC);
                break;

            default:
                return 0;
        }    
}
}
예제 #18
0
partition_t parse_partition(FILE* datei,int all,int paras){
  int i = 0;   /* loop variable */
  int j = 0;   /* loop variable */
  int c = 0;   /* Read Character */
  int current_pos = 0; /* Current Position for Start/End */
  int temp = 0;/* loop variable */
  int charset_flag = 0;/* Flag to check when charset starts */
  int charpart_flag = 0;/* Flag to check when charpartition starts */   
  size_t current_set_len = 0;  /* number of charsets currently read. */
  size_t partition_counter = 0; /* number of charpartitionlines currently read */
  size_t set_leng = SET_LENG; /* Maximum number of Charsets */
  size_t part_leng = PART_LENG; /*Maximum number of Charpartitionlines */
  int true_nexus = 0;   /* Flag to check if file is a Nexusfile */
  int set_start = 0;    
  int end_counter = 0;
  partition_t ret;   /* Returned struct */
  int part_var_names_str_len[2];
  int temp_summe; /* Current_pos + temp_sum = new starting point for partition */
  char vname[100]; /* String for a name */
  char first_number[100]; /* String for a name */
  char second_number[100]; /* String for a name */
  char step_number[100]; /* String for a name */
  char **lookup; /*Array of Strings for Charsets */
  char mod_name[100]; /* String for a name */
  char mod_v_name[100];/* String for a name */
  char pname[2000];/* String for a name */
  char **ppart_name; /* Array of Strings for Charpartitions */
  char **ppart_var_name; /* Array of Strings for Charpartitions */
  char **ppart_model_name; /* Array of Strings for Charpartitions */
  char **ppart_parameter_name; /* Array of Strings for Charpartitions */
  int fn,sn,st; /* Calculation of length */
  int name_right;
  int more_numbone;
  int more_mv_names[3];
  int* ind;
  int doto[2];
  size_t* pset_fn;
  size_t* pset_sn;
  size_t* pset_st;
  size_t* pset_leng;
  size_t* ppart_fn;
  size_t* ppart_sn;
  char * str;
  int str_len = STR_LEN;
  int c_read = -1;
  /* Allocate arrays */
  str = (char*) malloc(sizeof(char)*str_len);
  str = fgets(str,str_len,datei);
  pset_fn = (size_t*) malloc(sizeof(size_t)*set_leng);
  pset_sn = (size_t*) malloc(sizeof(size_t)*set_leng);
  pset_st = (size_t*) malloc(sizeof(size_t)*set_leng);
  pset_leng = (size_t*) malloc(sizeof(size_t)*set_leng);
  ppart_fn = (size_t*) malloc(sizeof(size_t)*part_leng);
  ppart_sn = (size_t*) malloc(sizeof(size_t)*part_leng);
  ppart_name = (char **) malloc(sizeof(char*)*part_leng);
  ppart_var_name = (char **) malloc(sizeof(char*)*part_leng);
  ppart_model_name = (char **) malloc(sizeof(char*)*part_leng);
  ppart_parameter_name = (char **) malloc(sizeof(char*)*part_leng);
  lookup = (char **) malloc(sizeof(char*)*set_leng);
  
  /* Here the fun begins */
  while( (c=mygetc(str,str_len,datei,&c_read)) != EOF && true_nexus != 6){
    while(isspace(c)) c = mygetc(str,str_len,datei,&c_read);
    if (c<91 && c>64) c+= 32;
    if(true_nexus == 0 && c=='#') true_nexus++;
    else if(true_nexus == 1 && c=='n') true_nexus++;
    else if(true_nexus == 2 && c=='e') true_nexus++;
    else if(true_nexus == 3 && c=='x') true_nexus++;
    else if(true_nexus == 4 && c=='u') true_nexus++;
    else if(true_nexus == 5 && c=='s') {
      true_nexus++;
      break;
    }
    else true_nexus = 0;
  }
  if(true_nexus != 6) {
    printf("No '#nexus' was found. Is this a nexus file?\n");
    exit(EXIT_FAILURE);
  }
  else {
    while( (c=mygetc(str,str_len,datei,&c_read)) != EOF){
      if(set_start == 0 && c=='b') set_start++;
      else if(set_start == 1 && c=='e') set_start++;
      else if(set_start == 2 && c=='g') set_start++;
      else if(set_start == 3 && c=='i') set_start++;
      else if(set_start == 4 && c=='n') set_start++;
      else if(set_start == 5 && c==' ') set_start++;
      else if(set_start == 6 && c=='s') set_start++;
      else if(set_start == 7 && c=='e') set_start++;
      else if(set_start == 8 && c=='t') set_start++;
      else if(set_start == 9 && c=='s') set_start++;
      else if(set_start == 10 && c==';') {
        set_start++;
        break;
      }
      else set_start = 0;
    }
  }
  if(set_start != 11) {
    printf("No sets have been found\n");
    exit(EXIT_FAILURE);
  }
  while( (c=mygetc(str,str_len,datei,&c_read)) != EOF){
    if(charset_flag == 0 && c=='e' && end_counter==0) end_counter++;
    else if(charset_flag == 0 && c=='n' && end_counter==1) end_counter++;
    else if(charset_flag == 0 && c=='d' && end_counter==2) end_counter++;
    else if(charset_flag == 0 && c==';' && end_counter==3) end_counter++;
    else end_counter=0;
    if(end_counter==4) break;
    if(charset_flag == 0 && c=='c') charset_flag++;
    else if(charset_flag == 1 && c=='h') charset_flag++;
    else if(charset_flag == 2 && c=='a') charset_flag++;
    else if(charset_flag == 3 && c=='r') charset_flag++;
    else if(charset_flag == 4 && c=='s') charset_flag++;
    else if(charset_flag == 5 && c=='e') charset_flag++;
    else if(charset_flag == 6 && c=='t') charset_flag++;
    else if(charset_flag == 7 && c==' ') charset_flag++;
    else if(charset_flag == 8){
/*      fseek(datei, -1L, SEEK_CUR); */
      name_right = grepName(c,datei,vname,str,str_len,&c_read);
      if( name_right == -1) exit(EXIT_FAILURE);
      lookup[i]=(char *) malloc(sizeof(char)*name_right);
      for(temp=0;vname[temp]!='\0';temp++){
        lookup[i][temp]=vname[temp];
      }
      lookup[i][temp]='\0';
      grepFirstNumber(doto,c,datei,first_number,str,str_len,&c_read);
      fn = charint(first_number);
      pset_fn[i]=charint(first_number);
      more_numbone = grepSecondNumber(c,datei,first_number,str,str_len,&c_read);
      pset_sn[i]=charint(first_number);
      sn = charint(first_number);
      grepSteps(doto,c,datei,first_number,str,str_len,&c_read);
      st = charint(first_number);
      pset_st[i]=charint(first_number);
      pset_leng[i]=(sn-fn)/st+1;
      i++;
      current_set_len++;
      /* Extend Array if needed */
      if(current_set_len==set_leng){
        set_leng=set_leng *2;
        expand_set_table( set_leng, current_set_len, &lookup, &pset_leng, &pset_fn, &pset_sn, &pset_st);
      }
      while(more_numbone == 77 || doto[0] == 77){
/*        fseek(datei, -1L, SEEK_CUR); */
        grepFirstNumber(doto,c,datei,first_number,str,str_len,&c_read);
        more_numbone = grepSecondNumber(c,datei,second_number,str,str_len,&c_read);
        grepSteps(doto,c,datei,step_number,str,str_len,&c_read);
        temp = 0;
        lookup[i]=(char *) malloc(sizeof(char)*name_right);
        for(temp=0;vname[temp]!='\0';temp++){
          lookup[i][temp]=vname[temp];
        }
        lookup[i][temp]='\0';
        pset_fn[i]=charint(first_number);
        pset_sn[i]=charint(second_number);
        pset_st[i]=charint(step_number);
        pset_leng[i]=(pset_sn[i]-pset_fn[i])/pset_st[i]+1;
        i++;
        current_set_len++;
        /* Extend Array if needed */
        if(current_set_len==set_leng){
          set_leng=set_leng *2;
          expand_set_table( set_leng, current_set_len, &lookup, &pset_leng, &pset_fn, &pset_sn, &pset_st);
        }
      }
      charset_flag = 0;
    }
    else
      charset_flag = 0;
    /* Looking for 'charpartition' */
    if(charpart_flag == 0 && c=='c') charpart_flag++;
    else if(charpart_flag == 1 && c=='h') charpart_flag++;
    else if(charpart_flag == 2 && c=='a') charpart_flag++;
    else if(charpart_flag == 3 && c=='r') charpart_flag++;
    else if(charpart_flag == 4 && c=='p') charpart_flag++;
    else if(charpart_flag == 5 && c=='a') charpart_flag++;
    else if(charpart_flag == 6 && c=='r') charpart_flag++;
    else if(charpart_flag == 7 && c=='t') charpart_flag++;
    else if(charpart_flag == 8 && c=='i') charpart_flag++;
    else if(charpart_flag == 9 && c=='t') charpart_flag++;
    else if(charpart_flag == 10 && c=='i') charpart_flag++;
    else if(charpart_flag == 11 && c=='o') charpart_flag++;
    else if(charpart_flag == 12 && c=='n') charpart_flag++;
    else if(charpart_flag == 13 && c==' '){
      if(all!=1)current_pos =0;
      temp = 0;
    /*  fseek(datei, -1L, SEEK_CUR); */
      name_right = grepName(c,datei,vname,str,str_len,&c_read);
      /* check if 'all' is set */
      if(all==1){
        vname[0] = 'a';
        vname[1] = 'l';
        vname[2] = 'l';
        vname[3] = '\0';
        name_right=4;
      }
      if( name_right == -1) exit(EXIT_FAILURE);
      grepModName(c,datei,mod_name, pname,part_var_names_str_len,str,str_len,&c_read);
      grepVName(c,datei,mod_v_name,more_mv_names,str,str_len,&c_read);
      while (more_mv_names[0] != 0){

        ppart_name[j]=(char*) malloc(sizeof(char)*name_right);
        for(temp=0;vname[temp]!='\0';temp++)ppart_name[j][temp] = vname[temp];
        ppart_name[j][temp]='\0';

        ppart_model_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[0]);
        for(temp=0;mod_name[temp]!='\0';temp++)ppart_model_name[j][temp] = mod_name[temp];
        ppart_model_name[j][temp]='\0';
        
        ppart_parameter_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[1]);
        for(temp=0;pname[temp]!='\0';temp++) ppart_parameter_name[j][temp]= pname[temp];
        ppart_parameter_name[j][temp]='\0';
        
        if( more_mv_names[0] == -1 ) exit(EXIT_FAILURE);
        else if( more_mv_names[0] == 66){
          
          ppart_var_name[j]=(char*) malloc(sizeof(char)*more_mv_names[1]);
          for(temp=0;mod_v_name[temp]!='\0';temp++) ppart_var_name[j][temp]=mod_v_name[temp];
          ppart_var_name[j][temp]='\0';
/*          fprintf(stderr,"COMPARE:\n......%s\n......%s\n",mod_v_name,lookup[0]); */
          ind = find_set(mod_v_name,lookup,current_set_len);
          temp_summe =0;
          for(temp=1;temp<ind[0]+1;temp++)temp_summe+= pset_leng[ind[temp]];
          free(ind);
          ppart_fn[j]=current_pos+1;
          current_pos += temp_summe;
          ppart_sn[j]=current_pos;
          partition_counter++;
          j++;
          /* Extend Array if needed */
          if(j==part_leng){
            part_leng = part_leng*2;
            expand_part_table(&ppart_name,&ppart_var_name,&ppart_model_name,&ppart_parameter_name,partition_counter,part_leng,&ppart_fn,&ppart_sn);
          }
          grepVName(more_mv_names[2],datei,mod_v_name,more_mv_names,str,str_len,&c_read);
        }
        else if( more_mv_names[0] == 77) {
          
          ppart_var_name[j]=(char*) malloc(sizeof(char)*more_mv_names[1]);
          for(temp=0;mod_v_name[temp]!='\0';temp++) ppart_var_name[j][temp]=mod_v_name[temp];
          ppart_var_name[j][temp]='\0';
          
/*          fprintf(stderr,"COMPARE:\n......%s\n......%s\n",mod_v_name,lookup[0]); */
          ind = find_set(mod_v_name,lookup,current_set_len);
          temp_summe =0;
          for(temp=1;temp<ind[0]+1;temp++)temp_summe+= pset_leng[ind[temp]];
          free(ind);
          ppart_fn[j]=current_pos+1;
          current_pos += temp_summe;
          ppart_sn[j]=current_pos;
          j++;
          partition_counter++;
          /* Extend Array if needed */
          if(j==part_leng){
            part_leng = part_leng *2;
/* fprintf(stderr,"(%s:%d)\n",__FILE__,__LINE__); */
            expand_part_table(&ppart_name,&ppart_var_name,&ppart_model_name,&ppart_parameter_name,partition_counter,part_leng,&ppart_fn,&ppart_sn);
          }
          grepModName(c,datei,mod_name, pname,part_var_names_str_len,str,str_len,&c_read);
          grepVName(c,datei,mod_v_name,more_mv_names,str,str_len,&c_read);
        }
      }
      /* Get new Memory and save char[] */
      ppart_var_name[j]=(char*) malloc(sizeof(char)*more_mv_names[1]);
      for(temp=0;mod_v_name[temp]!='\0';temp++) ppart_var_name[j][temp]=mod_v_name[temp];
      ppart_var_name[j][temp]='\0';
      
      ppart_name[j]=(char*) malloc(sizeof(char)*name_right);
      for(temp=0;vname[temp]!='\0';temp++)ppart_name[j][temp] = vname[temp];
      ppart_name[j][temp]='\0';

      ppart_model_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[0]);
      for(temp=0;mod_name[temp]!='\0';temp++)ppart_model_name[j][temp] = mod_name[temp];
      ppart_model_name[j][temp]='\0';
      
      ppart_parameter_name[j]=(char*) malloc(sizeof(char)*part_var_names_str_len[1]);
      for(temp=0;pname[temp]!='\0';temp++) ppart_parameter_name[j][temp]= pname[temp];
      ppart_parameter_name[j][temp]='\0';
      
/*           fprintf(stderr,"COMPARE:\n......%s\n......%s\n",mod_v_name,lookup[0]); */ 
      ind = find_set(mod_v_name,lookup,current_set_len);
      temp_summe =0;
      for(temp=1;temp<ind[0]+1;temp++)temp_summe+= pset_leng[ind[temp]];
      free(ind);
      ppart_fn[j]=current_pos+1;
      current_pos += temp_summe;
      ppart_sn[j]= current_pos;
      j++;
      partition_counter++;
      /* Extend Array if needed */
      if(j==part_leng){
        part_leng = part_leng *2;
/* fprintf(stderr,"(%s:%d)\n",__FILE__,__LINE__); */
        expand_part_table(&ppart_name,&ppart_var_name,&ppart_model_name,&ppart_parameter_name,partition_counter,part_leng,&ppart_fn,&ppart_sn);
      }
      charpart_flag = 0;
    }
    else
      charpart_flag = 0;
  }
  if(end_counter != 4) {
    printf("No 'end;' for 'begin sets;' was found.\n");
    exit(EXIT_FAILURE);
  }
  ret.start = ppart_fn;
  ret.end = ppart_sn;
  ret.model_names=ppart_model_name;
  if(paras)
    ret.parameter_names=ppart_parameter_name;
  else{
    ret.parameter_names=NULL;
    for(i=0;i<partition_counter;i++)
      free(ppart_parameter_name[i]);
    free(ppart_parameter_name);
/* fprintf(stderr,"ERROR %s:%d\n",__FILE__,__LINE__); */
  }
  ret.partition_names=ppart_name;
  ret.gene_names=ppart_var_name;
  ret.part_len=partition_counter;
  ret.max_part_len=part_leng;
  for(i=0;i<current_set_len;i++){
     printf("%s ",lookup[i]);
     printf("%lu...%lu...%lu...%lu",pset_fn[i],pset_sn[i],pset_st[i],pset_leng[i]);
     printf("\n");
  }
  for(i=0;i<current_set_len;i++)
    free(lookup[i]);
  free(lookup);
  free(pset_fn);
  free(pset_sn);
  free(pset_st);
  free(pset_leng);
  return ret;
} /* parse_partition */
예제 #19
0
void grepVName(int c,FILE* datei, char* vname, int* ret,char* str,int str_len,int* c_read){
  int empt = 1;
  ret[0]=0;
  ret[1]=0;
  ret[2]=0;
  while(isspace(c)) c = mygetc(str,str_len,datei,c_read);
  while(1){
    if(c == ';') {
      if(empt){
        printf("No text after ':' has been found");
        ret[0]=-1;
        exit(EXIT_FAILURE);
      }
      else {
        *vname = '\0';
        ret[1]++;
        return;
      }
    }
    if(isspace(c)) {
      while(isspace(c)) c = mygetc(str,str_len,datei,c_read);
      if(c == ';'){
        if(empt){
          printf("No text after ':' has been found");
          ret[0]=-1;
          exit(EXIT_FAILURE);
        }
        else{
          *vname = '\0';
          ret[1]++;
          return;
        }
      }
      else if(c == ','){
        if(empt){
          printf("No text after ':' has been found");
          ret[0]=-1;
          exit(EXIT_FAILURE);
        }
        c = mygetc(str,str_len,datei,c_read);
        *vname = '\0';
        ret[1]++;
        ret[0]=77;
        return;
      }
      else{
        *vname= '\0';
        ret[1]++;
        ret[0]=66;
        ret[2]=c;
        return;
      }
    }
    if(c == ','){
      if(empt){
        printf("No text after ':' has been found");
        ret[0]=-1;
        exit(EXIT_FAILURE);
      }
      c = mygetc(str,str_len,datei,c_read);
      *vname = '\0';
      ret[1]++;
      ret[0]=77;
      return;
    }
    else{
      *vname=c;
      ret[1]++;
      vname++;
      empt = 0;
      c = mygetc(str,str_len,datei,c_read);
    }
  }
return;
}
예제 #20
0
파일: params.c 프로젝트: pombredanne/cliffs
static BOOL Section( myFILE *InFile, BOOL (*sfunc)(char *) )
  /* ------------------------------------------------------------------------ **
   * Scan a section name, and pass the name to function sfunc().
   *
   *  Input:  InFile  - Input source.
   *          sfunc   - Pointer to the function to be called if the section
   *                    name is successfully read.
   *
   *  Output: True if the section name was read and True was returned from
   *          <sfunc>.  False if <sfunc> failed or if a lexical error was
   *          encountered.
   *
   * ------------------------------------------------------------------------ **
   */
  {
  int   c;
  int   i;
  int   end;
  char *func  = "params.c:Section() -";

  i = 0;      /* <i> is the offset of the next free byte in bufr[] and  */
  end = 0;    /* <end> is the current "end of string" offset.  In most  */
              /* cases these will be the same, but if the last          */
              /* character written to bufr[] is a space, then <end>     */
              /* will be one less than <i>.                             */

  c = EatWhitespace( InFile );    /* We've already got the '['.  Scan */
                                  /* past initial white space.        */

  while( (EOF != c) && (c > 0) )
    {

    /* Check that the buffer is big enough for the next character. */
    if( i > (bSize - 2) )
      {
      bSize += BUFR_INC;
      bufr   = Realloc( bufr, bSize );
      if( NULL == bufr )
        {
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
        return( False );
        }
      }

    /* Handle a single character. */
    switch( c )
      {
      case ']':                       /* Found the closing bracket.         */
        bufr[end] = '\0';
        if( 0 == end )                  /* Don't allow an empty name.       */
          {
          DEBUG(0, ("%s Empty section name in configuration file.\n", func ));
          return( False );
          }
        if( !sfunc( bufr ) )            /* Got a valid name.  Deal with it. */
          return( False );
        (void)EatComment( InFile );     /* Finish off the line.             */
        return( True );

      case '\n':                      /* Got newline before closing ']'.    */
        i = Continuation( bufr, i );    /* Check for line continuation.     */
        if( i < 0 )
          {
          bufr[end] = '\0';
          DEBUG(0, ("%s Badly formed line in configuration file: %s\n",
                   func, bufr ));
          return( False );
          }
        end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i);
        c = mygetc( InFile );             /* Continue with next line.         */
        break;

      default:                        /* All else are a valid name chars.   */
        if( isspace( c ) )              /* One space per whitespace region. */
          {
          bufr[end] = ' ';
          i = end + 1;
          c = EatWhitespace( InFile );
          }
        else                            /* All others copy verbatim.        */
          {
          bufr[i++] = c;
          end = i;
          c = mygetc( InFile );
          }
      }
    }

  /* We arrive here if we've met the EOF before the closing bracket. */
  DEBUG(0, ("%s Unexpected EOF in the configuration file: %s\n", func, bufr ));
  return( False );
  } /* Section */
예제 #21
0
static int
yylex1(void)
{
    register char *yyp;
    register int c;
    register int c1, c2;
    
    for (;;)
    {
	if (lex_fatal)
	{
	    return -1;
	}
	switch(c = mygetc())
	{
	case EOF:
	    if (inctop)
	    {
		struct incstate *p;
		p = inctop;
		(void)fclose(yyin);
		/*(void)fprintf(stderr, "popping to %s\n", p->file);*/
		free(current_file);
		nexpands = 0;
		current_file = p->file;
		current_line = p->line + 1;
		current_incfile = p->incfnum;
		pragma_strict_types = p->pragma_strict_types;
		yyin = p->yyin;
		slast = p->slast;
		lastchar = p->lastchar;
		inctop = p->next;
		
		if (p->nbuf)
		{
		    nbuf = p->nbuf;
		    outp = defbuf + DEFMAX - nbuf;
		    memcpy(outp, p->outp, nbuf);
		    free((char *)p->outp);
		}
		else
		{
		    nbuf = 0;
		    outp = defbuf + DEFMAX;
		}
		
		store_line_number_info(current_incfile, current_line);
		incdepth--;
		
		free((char *)p);
		break;
	    }
	    if (iftop)
	    {
		struct ifstate *p = iftop;
		lexerror(p->state == EXPECT_ENDIF ? "Missing #endif" : "Missing #else");
		while (iftop)
		{
		    p = iftop;
		    iftop = p->next;
		    free((char *)p);
		}
	    }
	    return -1;
	case '\n':
	{
	    nexpands=0;
	    store_line_number_info(current_incfile, current_line);
	    current_line++;
	    total_lines++;
	}
        /* FALLTHROUGH */
	case ' ':
	case '\t':
	case '\f':
	case '\v':
	    break;
	case '+':
	    TRY('+', F_INC);
	    TRY('=', F_ADD_EQ);
	    return c;
	case '-':
	    TRY('>', F_ARROW);
	    TRY('-', F_DEC);
	    TRY('=', F_SUB_EQ);
	    return c;
	case '&':
	    TRY('&', F_LAND);
	    TRY('=', F_AND_EQ);
	    return c;
	case '|':
	    TRY('|', F_LOR);
	    TRY('=', F_OR_EQ);
	    return c;
	case '^':
	    TRY('=', F_XOR_EQ);
	    return c;
	case '<':
	    if (gobble('<')) {
		TRY('=', F_LSH_EQ);
		return F_LSH;
	    }
	    TRY('=', F_LE);
	    return c;
	case '>':
	    if (gobble('>'))
	    {
		TRY('=', F_RSH_EQ);
		return F_RSH;
	    }
	    TRY('=', F_GE);
	    return c;
	case '*':
	    TRY('=', F_MULT_EQ);
	    return c;
	case '%':
	    TRY('=', F_MOD_EQ);
	    return F_MOD;
	case '/':
	    if (gobble('*'))
	    {
		skip_comment();
		break;
	    }
	    else if (gobble('/'))
	    {
		skip_comment2();
		break;
	    }
	    TRY('=', F_DIV_EQ);
	    return c;
	case '=':
	    TRY('=', F_EQ);
	    return c;
	case ';':
	case '(':
	case ')':
	case ',':
	case '{':
	case '}':
	case '~':
	case '[':
	case ']':
	case '?':
	case '@':
	    return c;
	case '!':
	    TRY('=', F_NE);
	    return F_NOT;
	case ':':
	    TRY(':', F_COLON_COLON);
	    return ':';
	case '.':
	    if (gobble('.'))
	    {
		if (gobble('.'))
		    return F_VARARG;
		else
		    return F_RANGE;
	    }
	    return c;
	case '#':
	    if (lastchar == '\n') 
	    {
		char *ssp = 0;
		int quote;
		
		yyp = yytext;
		do 
		{
		    c = mygetc();
		} while (isspace(c));
		
		for (quote = 0;;) 
		{
		    if (c == '"')
			quote ^= 1;
		    
		    /*gc - handle comments cpp-like! 1.6.91 @@@*/
		    while (!quote && c == '/')  
		    {
			if (gobble('*')) 
			{ 
			    skip_comment();
			    c = mygetc();
			}
			else 
			    break;
		    }
		    
		    if (!ssp && isspace(c))
			ssp = yyp;
		    if (c == '\n' || c == EOF)
			break;
		    SAVEC;
		    c = mygetc();
		}
		if (ssp) 
		{
		    *ssp++ = 0;
		    while (isspace(*ssp))
			ssp++;
		} 
		else 
		{
		    ssp = yyp;
		}
		*yyp = 0;
		if (strcmp("define", yytext) == 0) 
		{
		    handle_define(ssp);
		} 
		else if (strcmp("if", yytext) == 0) 
		{
#if 0
		    short int nega=0; /*@@@ allow #if !VAR gc 1.6.91*/
		    if (*ssp=='!'){ ssp++; nega=1;}
		    if (isdigit(*ssp))
		    {
			char *p;
			long l;
			l = strtol(ssp, &p, 10);
			while (isspace(*p))
			    p++;
			if (*p)
			    lexerror("Condition too complex in #if");
			else
			    handle_cond(nega ? !(int)l : (int)l);
		    }
		    else if (isalunum(*ssp))
		    {
			char *p = ssp;
			while (isalunum(*p))
			    p++;
			if (*p)
			{
			    *p++ = 0;
			    while (isspace(*p))
				p++;
			}
			if (*p)
			    lexerror("Condition too complex in #if");
			else
			{
			    struct defn *d;
			    d = lookup_define(ssp);
			    if (d)
			    {
				handle_cond(nega ? !atoi(d->exps) : atoi(d->exps));/* a hack! */
			    }
			    else
			    {
				handle_cond(nega?1:0); /* cpp-like gc*/
			    }
			}
		    }
		    else
			lexerror("Condition too complex in #if");
#else
		    int cond;
            
		    myungetc(0);
		    add_input(ssp);
		    cond = cond_get_exp(0);
		    if (mygetc()) 
		    {
			lexerror("Condition too complex in #if");
			while (mygetc())
			    ;
		    }
		    else
			handle_cond(cond);
#endif
		}
		else if (strcmp("ifdef", yytext) == 0) 
		{
		    deltrail(ssp);
		    handle_cond(lookup_define(ssp) != 0);
		}
		else if (strcmp("ifndef", yytext) == 0)
		{
		    deltrail(ssp);
		    handle_cond(lookup_define(ssp) == 0);
		} 
		else if (strcmp("else", yytext) == 0) 
		{
		    if (iftop && iftop->state == EXPECT_ELSE) 
		    {
			struct ifstate *p = iftop;
			
			/*(void)fprintf(stderr, "found else\n");*/
			iftop = p->next;
			free((char *)p);
			(void)skip_to("endif", (char *)0);
			store_line_number_info(current_incfile, current_line);
			current_line++;
			total_lines++;
		    }
		    else
		    {
			lexerror("Unexpected #else");
		    }
		} 
		else if (strcmp("endif", yytext) == 0) 
		{
		    if (iftop && (iftop->state == EXPECT_ENDIF ||
				  iftop->state == EXPECT_ELSE)) 
		    {
			struct ifstate *p = iftop;
			
			/*(void)fprintf(stderr, "found endif\n");*/
			iftop = p->next;
			free((char *)p);
		    } 
		    else 
		    {
			lexerror("Unexpected #endif");
		    }
		} 
		else if (strcmp("undef", yytext) == 0) 
		{
		    struct defn *d;
		    
		    deltrail(ssp);
		    if ((d = lookup_define(ssp)) != NULL )
			d->undef++;
		} 
		else if (strcmp("echo", yytext) == 0) 
		{
		    (void)fprintf(stderr, "%s\n", ssp);
		} 
		else if (strcmp("include", yytext) == 0) 
		{
		    /*(void)fprintf(stderr, "including %s\n", ssp);     */
		    handle_include(ssp, 0);
		}
		else if (strcmp("pragma", yytext) == 0)
		{
		    deltrail(ssp);
		    handle_pragma(ssp);
		} 
		else if (strcmp("error", yytext) == 0)
		{
		    handle_exception(ERROR, ssp);
		}
		else if (strcmp("warning", yytext) == 0)
		{
		    handle_exception(WARNING, ssp);
		}
		else 
		{
		    lexerror("Unrecognised # directive");
		}
		myungetc('\n');
		break;
	    }
	    else
		goto badlex;
	case '\'':
	    yylval.number = mygetc();
	    if (yylval.number == '\\')
	    {
		int tmp = mygetc();
		switch (tmp)
		{
		case 'n': yylval.number = '\n'; break;
		case 't': yylval.number = '\t'; break;
		case 'b': yylval.number = '\b'; break;
		case 'a': yylval.number = '\a'; break;
		case 'v': yylval.number = '\v'; break;
		case '\'':
		case '\\':
		case '"':
		    yylval.number = tmp; break;
		default:
		    lexwarning("Bad character escape sequence");
		    yylval.number = tmp;
		    break;
		}
	    }
	    if (!gobble('\''))
		lexerror("Illegal character constant");
	    return F_NUMBER;
	case '"':
	    yyp = yytext;
	    *yyp++ = c;
	    for (;;)
	    {
		c = mygetc();
		if (c == EOF)
		{
		    lexerror("End of file in string");
		    return string("\"\"");
		}
		else if (c == '\n')
		{
		    lexerror("Newline in string");
		    return string("\"\"");
		}
		SAVEC;
		if (c == '"')
		    break;
		if (c == '\\')
		{
		    c = mygetc();
		    if ( c == '\n' )
		    {
			yyp--;
			store_line_number_info(current_incfile, current_line);
			current_line++;
			total_lines++;
		    } 
		    else if ( c == EOF ) 
		    {
			/* some operating systems give EOF only once */
			myungetc(c); 
		    } 
		    else
			*yyp++ = c;
		}
	    }
	    *yyp = 0;
	    return string(yytext);

	case '0':
	    c = mygetc();
	    if ( c == 'X' || c == 'x' || c == 'o') 
	    {
                char *endptr;
                long long value;
                int base = 16;
                if (c == 'o')
                    base = 8;

                
		yyp = yytext;

		for (;;) 
		{
		    c = mygetc();
		    if (!isxdigit(c))
			break;
                    SAVEC;
		}
		myungetc(c);
                *yyp = '\0';
                
                value = strtoll(yytext, &endptr, base);
                if (*endptr != '\0')
                {
                    fprintf(stderr, "%s\n", yytext);
                    lexwarning("Invalid digits in octal number number");
                }
                
                return number(value);
	    }
	    myungetc(c);
	    c = '0';
	    /* FALLTHROUGH */
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
	    yyp = yytext;
	    *yyp++ = c;
	    for (;;)
	    {
		c = mygetc();
		if (!isdigit(c))
		    break;
		SAVEC;
	    }
	    if (c == '.')
	    {
		if (isdigit(c1 = mygetc()))
		{
		    SAVEC;
		    c = c1;
		    SAVEC;
		    for (c = mygetc(); isdigit(c); c = mygetc())
			SAVEC;
		    if (c == 'e' || c == 'E')
		    {
			c1 = mygetc();
			if (c1 == '-' || c1 == '+')
			{
			    c2 = mygetc();
			    if (isdigit(c2))
			    {
				SAVEC;
				c = c1;
				SAVEC;
				c = c2;
				SAVEC;
				for (c = mygetc(); isdigit(c); c = mygetc())
				    SAVEC;
			    }
			    else
			    {
				myungetc(c2);
				myungetc(c1);
			    }
			}
			else if (isdigit(c1))
			{
			    SAVEC;
			    c = c1;
			    SAVEC;
			    for (c = mygetc(); isdigit(c); c = mygetc())
				SAVEC;
			}
			else
			    myungetc(c1);
		    }
		    myungetc(c);
		    *yyp = 0;
		    return real(strtod(yytext, NULL));
		}
		myungetc(c1);
	    }
	    myungetc(c);
	    *yyp = 0;
	    if (*yytext == '0')
            {
                /* OCTALS */
                char *endptr;
                long long value;

                value = strtoll(yytext, &endptr, 010);

                if (*endptr != '\0')
                    lexwarning("Invalid digits in octal number");

                if (value != 0)
                    lexwarning("Obsolete octal format used. Use 0o111 syntax");
                
		return number(value);
            }
	    return number(atoll(yytext));
	default:
	    if (isalpha(c) || c == '_') {
		int r;
		
		yyp = yytext;
		*yyp++ = c;
		for (;;)
		{
		    c = mygetc();
		    if (!isalunum(c))
			break;
		    SAVEC;
		}
		*yyp = 0;
		
		myungetc(c);
		if (!expand_define())
		{
		    r = lookup_resword(yytext);
		    if (r >= 0)
		    {
			return r;
		    }
		    else
			return ident(yytext);
		}
		break;
	    }
	    goto badlex;
	}
    }
  badlex:
    {
	lexerror("Illegal character (hex %02x) '%c'", c, c);
        return ' '; 
    }
}
예제 #22
0
static int
skip_to(char *token, char *atoken)
{
    char b[20], *p;
    int c;
    int nest;

    for (nest = 0;;)
    {
        c = mygetc();
        if (c == '#')
        {
            do
            {
                c = mygetc();
            } while (isspace(c));
            for (p = b; c != '\n' && c != EOF; )
            {
                if (p < b+sizeof b-1)
                    *p++ = c;
                c = mygetc();
            }
            *p++ = 0;
            for (p = b; *p && !isspace(*p); p++)
                ;
            *p = 0;
            /*(void)fprintf(stderr, "skip checks %s\n", b);*/
            if (strcmp(b, "if") == 0 || strcmp(b, "ifdef") == 0 ||
                strcmp(b, "ifndef") == 0)
            {
                nest++;
            }
            else if (nest > 0)
            {
                if (strcmp(b, "endif") == 0)
                    nest--;
            }
            else
            {
                if (strcmp(b, token) == 0)
                    return 1;
                else if (atoken && strcmp(b, atoken) == 0)
                    return 0;
            }
        }
        else 
        {
            /*(void)fprintf(stderr, "skipping (%d) %c", c, c);*/
            while (c != '\n' && c != EOF) 
            {
                c = mygetc();
                /*(void)fprintf(stderr, "%c", c);*/
            } 
            if (c == EOF)
            {
                lexerror("Unexpected end of file while skipping");
                return 1;
            }
        }
        store_line_number_info(current_incfile, current_line);
        current_line++;
        total_lines++;
    }
}
예제 #23
0
static int 
cond_get_exp(int priority)
{
    int c;
    int value, value2, x;
    
    do
	c = exgetc();
    while (isspace(c));
    
    if (c == '(')
    {
	value = cond_get_exp(0);
	do
	    c = exgetc();
	while (isspace(c));
	if (c != ')')
	{
	    lexerror("bracket not paired in #if");
	    if (!c)
		myungetc('\0');
	}
    }
    else if (ispunct(c))
    {
	x = (_optab-' ')[c];
	if (!x)
	{
	    lexerror("illegal character in #if");
	    return 0;
	}
	value = cond_get_exp(12);
	switch ( optab2[x-1] )
	{
	case BNOT  : value = ~value; break;
	case LNOT  : value = !value; break;
	case UMINUS: value = -value; break;
	case UPLUS : value =  value; break;
	default :
	    lexerror("illegal unary operator in #if");
	    return 0;
	}
    }
    else
    {
	int base;
	
	if (!isdigit(c))
	{
	    if (!c)
	    {
		lexerror("missing expression in #if");
		myungetc('\0');
	    }
	    else
		lexerror("illegal character in #if");
	    return 0;
	}
	value = 0;
	if (c!='0')
	    base = 10;
	else
	{
	    c = mygetc();
	    if ( c == 'x' || c == 'X' )
	    {
		base = 16;
		c = mygetc();
	    }
	    else
		base=8;
	}
	for (;;)
	{
	    if ( isdigit(c) )
		x = -'0';
	    else if (isupper(c))
		x = -'A' + 10;
	    else if (islower(c))
		x = -'a' + 10;
	    else
		break;
	    x += c;
	    if (x > base)
		break;
	    value = value*base + x;
	    c = mygetc();
	}
	myungetc(c);
    }
    for (;;)
    {
	do
	    c = exgetc();
	while (isspace(c));
	
	if (!ispunct(c))
	    break;
	x = (_optab-' ')[c];
	if (!x)
	    break;
	value2 = mygetc();
	for (;;x += 3)
	{
	    if (!optab2[x])
	    {
		myungetc(value2);
		if (!optab2[x + 1])
		{
		    lexerror("illegal operator use in #if");
		    return 0;
		}
		break;
	    }
	    if (value2 == optab2[x])
		break;
	}
	if (priority >= optab2[x + 2])
	{
	    if (optab2[x])
		myungetc(value2);
	    break;
	}
	value2 = cond_get_exp(optab2[x + 2]);
	switch ( optab2[x + 1] )
	{
	case MULT   : value *=  value2;                    break;
	case DIV    : value /=  value2;                    break;
	case MOD    : value %=  value2;                    break;
	case BPLUS  : value +=  value2;                    break;
	case BMINUS : value -=  value2;                    break;
	case LSHIFT : value <<= value2;                    break;
	case RSHIFT : value =   (unsigned)value >> value2; break;
	case LESS   : value =   value <  value2;           break;
	case LEQ    : value =   value <= value2;           break;
	case GREAT  : value =   value >  value2;           break;
	case GEQ    : value =   value >= value2;           break;
	case EQ     : value =   value == value2;           break;
	case NEQ    : value =   value != value2;           break;
	case BAND   : value &=  value2;                    break;
	case XOR    : value ^=  value2;                    break;
	case BOR    : value |=  value2;                    break;
	case LAND   : value =  value && value2;            break;
	case LOR    : value =  value || value2;            break;
	case QMARK  :
	    do
		c = exgetc();
	    while (isspace(c));
            if (c != ':')
	    {
		lexerror("'?' without ':' in #if");
		myungetc(c);
		return 0;
	    }
	    if (value) 
	    {
		(void)cond_get_exp(1);
		value = value2;
	    }
	    else
		value = cond_get_exp(1);
	    break;
	}
    }
    myungetc(c);
    return value;
}
예제 #24
0
/* Stuff to evaluate expression.  I havn't really checked it. /LA
** Written by "J\"orn Rennecke" <*****@*****.**>
*/
static int
exgetc(void)
{
    register char c, *yyp;
    
    c = mygetc();
    while (isalpha(c) || c == '_')
    {
	yyp = yytext;
	do
	{
	    SAVEC;
	    c = mygetc();
	} while (isalunum(c));
	myungetc(c);
	*yyp = '\0';
	if (strcmp(yytext, "defined") == 0)
	{
	    /* handle the defined "function" in #if */
	    do
		c = mygetc();
	    while (isspace(c));
	    
	    if (c != '(')
	    {
		lexerror("Missing ( in defined");
		continue;
	    }
	    do
		c = mygetc();
	    while (isspace(c));
	    
	    yyp = yytext;
	    while (isalunum(c))
	    {
		SAVEC;
		c = mygetc();
	    }
	    *yyp = '\0';
	    while (isspace(c))
		c = mygetc();
	    if (c != ')')
	    {
		lexerror("Missing ) in defined");
		continue;
	    }

	    /* Skip whitespace */
	    do
		c = mygetc();
	    while (isspace(c)); 
	    myungetc(c);

	    if (lookup_define(yytext))
		add_input(" 1 ");
	    else
		add_input(" 0 ");
	}
	else
	{
	    if (!expand_define()) add_input(" 0 ");
	}
	c = mygetc();
    }
    return c;
}
예제 #25
0
void    AvLex () {
    Etat ee = E_INIT ; /* etat courant */
    int  a_consommer ; /* faut-il consommer le caractere ? */
   int  value       ; /* valeur entiere si lexeme INTEGER */

   while ((cc != EOF) && (ee != E_ERREUR) && (ee != E_TERM)) {
        a_consommer = 1 ; /* a priori, il faut consommer */
       switch (ee) {
         case E_INIT : 
            
{
if      (cc == '@')  ee = E_COMM;
else if ((cc == ' ') || (cc == '\t')) { ; } 
else if (isdigit(cc) && (cc != '0')) {
      ee         = E_INTEGER ; 
      leLex.nat  = INTEGER ;
      value      = char2int (cc) ;
      *ptaschar  = cc ;
      leLex.chaine = ptaschar ;
      leLex.nol    = nol ;
      leLex.noc    = noc ;
      ptaschar++;
}
else if (cc == '0') {
      ee           = E_VERIF_NOTA_HEXA ;
      leLex.nat    = INTEGER ;      
       value        = 0 ;
      leLex.chaine = ptaschar ;
      leLex.nol    = nol ;
      leLex.noc    = noc ;
}
else if (isalpha(cc) || (cc == '_') || (cc=='.') ) {
      ee    = E_IDF_KEYW ;
      *ptaschar = cc ;
       /* leLex.nat encore inconnu mais on met ETIQUETTE a priori */
      leLex.nat = ETIQUETTE ;
      leLex.chaine = ptaschar ;
      ptaschar++;
      leLex.nol    = nol ;
      leLex.noc    = noc ;
}
else if (cc =='"') {
   ee = E_CHAINE ;
   *ptaschar = cc ;
   leLex.chaine = ptaschar ;
   ptaschar++;
   leLex.nat    = CHAINE ;
   leLex.nol    = nol ;
   leLex.noc    = noc ;
}
else if ((cc == ',') || (cc == '!') || (cc == '{') || (cc == '}') ||
         (cc == '[') || (cc == ']') || (cc == '#') || (cc == '^') ||
         (cc == '-') || (cc == '(') || (cc == ')') ||
         (cc == '+') || (cc == '=') || (cc == ':') ||
         (cc == '\n'))  { 
      ee = E_TERM ;
      *ptaschar = cc ;
      leLex.chaine = ptaschar ;
      ptaschar++;
      leLex.nat = char2nat (cc) ;
      leLex.nol    = nol ;
      leLex.noc    = noc ;
}
else {
      leLex.nat = ERRLEX ;
       ee         = E_ERREUR ;
      leLex.nol    = nol ;
      leLex.noc    = noc ;
      *ptaschar = cc ;
      leLex.chaine = ptaschar ;
      ptaschar++;
}
}
            break ;
         case E_CHAINE :
            
*ptaschar = cc ;
ptaschar++;
if (cc == '"') ee = E_TERM ;   
            break ;
         case E_COMM :
            
if (cc == '\n') {
      ee = E_TERM ;
      *ptaschar = cc ;
      leLex.chaine = ptaschar ;
      ptaschar++;
      leLex.nat = char2nat (cc) ;
      leLex.nol    = nol ;
      leLex.noc    = noc ;
}
            break ;
         case E_INTEGER :
            
if (isdigit (cc) ) {
   value = 10*value + char2int (cc) ;
   *ptaschar = cc ; ptaschar++   ;
}
else {
   a_consommer = 0 ;
   ee = E_TERM ; 
   leLex.value = value ;
}
            break ;
         case E_IDF_KEYW :
            
if (isdigit(cc) || isalpha(cc) || (cc == '_') ) {
   *ptaschar = cc ; ptaschar++   ;
}
else {
   a_consommer = 0 ;
   ee = E_TERM ; 
}   
            break ;
         case E_VERIF_NOTA_HEXA :
            
if (cc == 'x') {
   ee = E_INTEGER_HEXA ;
}
else if (isdigit (cc)) {
   ee = E_INTEGER ;
   a_consommer = 0 ;
}
else {
   ee = E_TERM ; 
   a_consommer = 0 ;
   leLex.value = value ; /* 0, normalement */   
}
            break ; 
         case E_INTEGER_HEXA : 
            
if (isdigit (cc) || (cc == 'A') || (cc == 'B') || (cc == 'C') ||
                 (cc == 'D') || (cc == 'E') || (cc == 'F') ||
               (cc == 'a') || (cc == 'b') || (cc == 'c') ||
               (cc == 'd') || (cc == 'e') || (cc == 'f')) {
   value = 16*value + char2int (cc) ;
   *ptaschar = cc ; ptaschar++   ;
}
else {
   a_consommer = 0 ;
   ee = E_TERM ; 
   leLex.value = value ;
}
            break ; 
         default :
               printf ("Oups! Internal error in AvLex\n");
               exit (1) ;
        }
       if (a_consommer) cc = mygetc (leFichier) ; 
    }

   /* terminer la chaine lue */
   *ptaschar = '\0' ; ptaschar++ ;

   /* On a atteint un état terminal, ou l'état d'erreur, ou alors la
   fin de fichier. Une analyse par cas est nécessaire. 
   */ 
   
if (ee == E_ERREUR)  {
   /* rien a faire de plus.  */
}
else if (ee == E_TERM) {
   /* on a termine un lexeme proprement.
      il se peut qu'on vienne de reconnaitre un mot, il faut
      determiner de quelle espece de lexeme il s'agit.  */
   if (leLex.nat == ETIQUETTE) {
         /* finir le travail */
	ChercherMotCle(&leLex) ;
   }
   /* sinon le lexeme est entierement construit. */
}
else /* cad (cc == EOF) && (ee != E_ERREUR) & (ee != E_TERM) */ {
   /* on n'a pas le droit de finir le fichier dans n'importe quel etat :
    */
   if ((ee == E_COMM) || (ee == E_CHAINE)) {
      leLex.nat = ERRLEX ;
   }
   else {
      /* ici ee=E_INIT ou E_INTEGER ou E_IDF_KEYW
         si E_INIT, on avait des espaces avant la fin de fichier.
          si E_INTEGER, on a trouve EOF juste derriere un nb, finir le travail
           si E_IDF_KEYW, on a trouve EOF juste derriere un mot, finir le travail
      */
      if (ee == E_INIT)    leLex.nat = ENDLEX ;
      if (ee == E_INTEGER) leLex.value = value ;
      if (ee == E_IDF_KEYW) {
        ChercherMotCle(&leLex) ;
       }
   }
}

   
}
예제 #26
0
/* Check if yytext is a macro and expand if it is. */
static int
expand_define(void)
{
    struct defn *p;
    char expbuf[DEFMAX];
    char *args[NARGS];
    char buf[DEFMAX];
    char *q, *e, *b;

    if (nexpands++ > EXPANDMAX)
    {
	lexerror("Too many macro expansions");
	return 0;
    }
    p = lookup_define(yytext);
    if (!p)
    {
	return 0;
    }
    if (p->nargs == -1)
    {
	add_input(p->exps);
    }
    else
    {
	int c, parcnt = 0, dquote = 0, squote = 0;
	int n;
	SKIPW;
	if (c != '(')
	{
	    lexerror("Missing '(' in macro call");
	    return 0;
	}
	SKIPW;
	if (c == ')')
	    n = 0;
	else
	{
	    q = expbuf;
	    args[0] = q;
	    for (n = 0; n < NARGS; )
	    {
		switch(c)
		{
		case '"':
		    if (!squote)
			dquote ^= 1;
		    break;
		case '\'':
		    if (!dquote)
			squote ^= 1;
		    break;
		case '(':
		    if (!squote && !dquote)
			parcnt++;
		    break;
		case ')':
		    if (!squote && !dquote)
			parcnt--;
		    break;
		case '\\':
		    if (squote || dquote)
		    {
			*q++ = c;
			c = mygetc();}
		    break;
		case '\n':
		    if (squote || dquote)
		    {
			lexerror("Newline in string");
			return 0;
		    }
		    break;
		}
		if (c == ',' && !parcnt && !dquote && !squote)
		{
		    *q++ = 0;
		    args[++n] = q;
		}
		else if (parcnt < 0)
		{
		    *q++ = 0;
		    n++;
		    break;
		}
		else
		{
		    if (c == EOF)
		    {
			lexerror("Unexpected end of file");
			return 0;
		    }
		    if (q >= expbuf + DEFMAX - 5)
		    {
			lexerror("Macro argument overflow");
			return 0;
		    }
		    else
		    {
			*q++ = c;
		    }
		}
		if (!squote && ! dquote)
		    c = cmygetc();
		else
		    c = mygetc();
	    }
	    if (n == NARGS)
	    {
		lexerror("Maximum macro argument count exceeded");
		return 0;
	    }
	}
	if (n != p->nargs)
	{
	    lexerror("Wrong number of macro arguments");
	    return 0;
	}
	/* Do expansion */
	b = buf;
	e = p->exps;
	while (*e)
	{
	    if (*e == MARKS)
	    {
		if (*++e == MARKS)
		    *b++ = *e++;
		else
		{
		    for (q = args[*e++ - MARKS - 1]; *q; )
		    {
			*b++ = *q++;
			if (b >= buf+DEFMAX)
			{
			    lexerror("Macro expansion overflow");
			    return 0;
			}
		    }
		}
	    }
	    else
	    {
		*b++ = *e++;
		if (b >= buf+DEFMAX)
		{
		    lexerror("Macro expansion overflow");
		    return 0;
		}
	    }
	}
	*b++ = 0;
	add_input(buf);
    }
    return 1;
}
예제 #27
0
/* Greps the Stepnumber and tells if there are more start/end point */ 
void grepSteps(int* ret,int c,FILE* datei, char* vname,char* str,int str_len,int* c_read){
  int nothing;
  int onlyone;
  int spaces;
  c = str[*c_read];
  nothing = 1;
  onlyone = 0;
  ret[1]=0;
  spaces = 0;
  while(isspace(c)) c = mygetc(str,str_len,datei,c_read);
  if(c == '\\') c = mygetc(str,str_len,datei,c_read);
  else if(c == ';'){
    if(nothing==1){
      *vname='1';
      vname++;
    }
    *vname = '\0';
    ret[0]=0;
    return; 
  }
  else if (isdigit(c)){
    *vname='1';
    vname++;
    *vname='\0';
    ret[0]=77;
    ret[1]=c;
    return;
  }
  else{
    ret[0]=1;
    return;
  }
  while(1){
    if(c == ';') {
      if(nothing==1){
        *vname='1';
        vname++;
      }
      *vname = '\0';
      ret[0]=0;
      return;
    }
    else if (isspace(c)){
      if(onlyone){
        spaces =1;
        c = mygetc(str,str_len,datei,c_read);
      }
      else c= mygetc(str,str_len,datei,c_read);
    }
    else{
      if (isdigit(c)){
        if(spaces){
          *vname= '\0';
          ret[0]=77;
          ret[1]=c;
          return;
        }
        else{
          *vname=c;
          vname++;
          nothing = 0;
          onlyone = 1;
          c = mygetc(str,str_len,datei,c_read);
        }
      }
      else{
        ret[0]=1;
        return;
      }
    }
  }
  ret[0]=1;
  return;
}
예제 #28
0
/* return(VCOUNTER,PCOUNTER) */
void grepModName(int c,FILE* datei, char* vname, char* pname,int* ret,char* str,int str_len,int* c_read){
  int empt = 1;
  ret[0]=0;
  ret[1]=0;
  c = mygetc(str,str_len,datei,c_read);
  while(isspace(c)) c = mygetc(str,str_len,datei,c_read);
  while(1){
    if(isspace(c)) c = mygetc(str,str_len,datei,c_read);
    if(c == ';'){
      printf("The character ';' is not allowed in the name of a variable\n");
      exit(EXIT_FAILURE);
    }
    if(c == ':'){
      if(empt){
        printf("No Model has been found\n");
        exit(EXIT_FAILURE);
      }
      *pname = '{';
      pname++;
      ret[1]++;
      *pname = '}';
      pname++;
      ret[1]++;
      *pname = '\0';
      ret[1]++;
      *vname= '\0';
      ret[0]++;
      return;
    }
    if(c == '+'){
      *pname = '{';
      ret[1]++;
      pname++;
      *pname = '}';
      ret[1]++;
      pname++;
      *pname = c;
      ret[1]++;
      pname++;
      *vname = c;
      ret[0]++;
      vname++;
      c = mygetc(str,str_len,datei,c_read);
    }
    if(c == '{'){
      *pname= c;
      ret[1]++;
      pname++;
      while((c = mygetc(str,str_len,datei,c_read)) != '}'){
        if(!(isspace(c))){
          *pname = c;
          ret[1]++;
          pname++;
        }
      }
      *pname = '}';
      ret[1]++;
      pname++;
      c = mygetc(str,str_len,datei,c_read);
      while(isspace(c)) c = mygetc(str,str_len,datei,c_read);
      if(c == '+'){
        *pname = '+';
        ret[1]++;
        pname++;
        *vname = '+';
        ret[0]++;
        vname++;
        c = mygetc(str,str_len,datei,c_read);
      }
      else {
        *pname = '\0';
        ret[1]++;
        *vname= '\0';
        ret[0]++;
        return;
      }
    }
    else{
      *vname=c,
      ret[0]++;
      vname++;
      empt = 0;
      c = mygetc(str,str_len,datei,c_read);
    }
  }
  *pname = '\0';
  ret[1]++;
  *vname = '\0';
  ret[2]++;
  return;
}
예제 #29
0
파일: params.c 프로젝트: pombredanne/cliffs
static BOOL Parameter( myFILE *InFile, BOOL (*pfunc)(char *, char *), int c )
  /* ------------------------------------------------------------------------ **
   * Scan a parameter name and value, and pass these two fields to pfunc().
   *
   *  Input:  InFile  - The input source.
   *          pfunc   - A pointer to the function that will be called to
   *                    process the parameter, once it has been scanned.
   *          c       - The first character of the parameter name, which
   *                    would have been read by Parse().  Unlike a comment
   *                    line or a section header, there is no lead-in
   *                    character that can be discarded.
   *
   *  Output: True if the parameter name and value were scanned and processed
   *          successfully, else False.
   *
   *  Notes:  This function is in two parts.  The first loop scans the
   *          parameter name.  Internal whitespace is compressed, and an
   *          equal sign (=) terminates the token.  Leading and trailing
   *          whitespace is discarded.  The second loop scans the parameter
   *          value.  When both have been successfully identified, they are
   *          passed to pfunc() for processing.
   *
   * ------------------------------------------------------------------------ **
   */
  {
  int   i       = 0;    /* Position within bufr. */
  int   end     = 0;    /* bufr[end] is current end-of-string. */
  int   vstart  = 0;    /* Starting position of the parameter value. */
  char *func    = "params.c:Parameter() -";

  /* Read the parameter name. */
  while( 0 == vstart )  /* Loop until we've found the start of the value. */
    {

    if( i > (bSize - 2) )       /* Ensure there's space for next char.    */
      {
      bSize += BUFR_INC;
      bufr   = Realloc( bufr, bSize );
      if( NULL == bufr )
        {
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
        return( False );
        }
      }

    switch( c )
      {
      case '=':                 /* Equal sign marks end of param name. */
        if( 0 == end )              /* Don't allow an empty name.      */
          {
          DEBUG(0, ("%s Invalid parameter name in config. file.\n", func ));
          return( False );
          }
        bufr[end++] = '\0';         /* Mark end of string & advance.   */
        i       = end;              /* New string starts here.         */
        vstart  = end;              /* New string is parameter value.  */
        bufr[i] = '\0';             /* New string is nul, for now.     */
        break;

      case '\n':                /* Find continuation char, else error. */
        i = Continuation( bufr, i );
        if( i < 0 )
          {
          bufr[end] = '\0';
          DEBUG(1,("%s Ignoring badly formed line in configuration file: %s\n",
                   func, bufr ));
          return( True );
          }
        end = ( (i > 0) && (' ' == bufr[i - 1]) ) ? (i - 1) : (i);
        c = mygetc( InFile );       /* Read past eoln.                   */
        break;

      case '\0':                /* Shouldn't have EOF within param name. */
      case EOF:
        bufr[i] = '\0';
        DEBUG(1,("%s Unexpected end-of-file at: %s\n", func, bufr ));
        return( True );

      default:
        if( isspace( c ) )     /* One ' ' per whitespace region.       */
          {
          bufr[end] = ' ';
          i = end + 1;
          c = EatWhitespace( InFile );
          }
        else                   /* All others verbatim.                 */
          {
          bufr[i++] = c;
          end = i;
          c = mygetc( InFile );
          }
      }
    }

  /* Now parse the value. */
  c = EatWhitespace( InFile );  /* Again, trim leading whitespace. */
  while( (EOF !=c) && (c > 0) )
    {

    if( i > (bSize - 2) )       /* Make sure there's enough room. */
      {
      bSize += BUFR_INC;
      bufr   = Realloc( bufr, bSize );
      if( NULL == bufr )
        {
        DEBUG(0, ("%s Memory re-allocation failure.", func) );
        return( False );
        }
      }

    switch( c )
      {
      case '\r':              /* Explicitly remove '\r' because the older */
        c = mygetc( InFile );   /* version called fgets_slash() which also  */
        break;                /* removes them.                            */

      case '\n':              /* Marks end of value unless there's a '\'. */
        i = Continuation( bufr, i );
        if( i < 0 )
          c = 0;
        else
          {
          for( end = i; (end >= 0) && isspace(bufr[end]); end-- )
            ;
          c = mygetc( InFile );
          }
        break;

      default:               /* All others verbatim.  Note that spaces do */
        bufr[i++] = c;       /* not advance <end>.  This allows trimming  */
        if( !isspace( c ) )  /* of whitespace at the end of the line.     */
          end = i;
        c = mygetc( InFile );
        break;
      }
    }
  bufr[end] = '\0';          /* End of value. */

  return( pfunc( bufr, &bufr[vstart] ) );   /* Pass name & value to pfunc().  */
  } /* Parameter */
예제 #30
0
파일: decomp16.c 프로젝트: Hooman3/minix
int main(int argc, char **argv)
{
  char c, *cp;
  int j, k, fdtmp;
  unsigned int len;

  /* Find the program name */
  j = 0;
  while (argv[0][j] != '\0') j++;
  len = (unsigned int) j;
  while (j--)
	if (argv[0][j] == '/') break;
  if (argv[0][j] == '/') j++;
  cp = argv[0] + j;
  len -= j;

  /* Sort out the flags */
  for (k = 1; k < argc; k++) {
	if (argv[k][0] == '-') {
		c = argv[k][1];
		switch (c) {
		    case '0':	/* pass numbers */
		    case '1':
		    case '2':
		    case '3':
		    case '4':	pnum = c - '0';	break;
		    case 'd':	/* used by news */
			break;
		    default:
			(void) write(1, "Usage: ", 7);
			(void) write(1, cp, len);
			(void) write(1, " [-#] [in] [out]\n", 17);
			exit(0);
			break;
		}

		/* Once it's checked, lose it anyway */
		for (j = k; j < argc; j++) argv[j] = argv[j + 1];
		argc--;
		k--;
	}
  }

  /* Default i/o settings */
  fdin = 0;
  fdout = 1;
  fderr = 2;

  /* Try to open specific files and connect them to stdin/stdout */
  if (argc > 1) {
	if ((fdtmp = open(argv[1], 0)) == -1) die("input open failed");
	(void) close(0);
	if ((fdin = dup(fdtmp)) == -1) die("input dup failed\n");
	(void) close(fdtmp);
  }
  if (argc > 2) {
	(void) unlink(argv[2]);
	if ((fdtmp = creat(argv[2], 0666)) == -1) die("output creat failed");
	(void) close(1);
	if ((fdout = dup(fdtmp)) == -1) die("output dup failed\n");
	(void) close(fdtmp);
  }

  /* Sort out type of compression */
  if (pnum == -1 || pnum == 4) {/* if this is pass 4 */
	/* Check header of compressed file */
	if (mygetc() != 0x1F || mygetc() != 0x9D)      /* check magic number */
		die("not a compressed file\n");
	iindex = mygetc();	/* get compression style */
  } else
	getpipe();		/* get compression style */

  maxbits = iindex & 0x1F;
  clearflg = ((iindex & 0x80) != 0) ? TRUE : FALSE;
  if (maxbits < 9 || maxbits > 16)	/* check for valid maxbits */
	die("can't decompress\n");
  if (pnum != -1 && pnum != 0)
	putpipe(iindex, 0);	/* pass style to next copy */

  /* Fork off an ancestor if necessary - ffork() increments pnum */
  if (pnum == -1) {
	pnum = 0;
	if (pnum == 0) ffork();
	if (pnum == 1) ffork();
	if (pnum == 2) ffork();
	if (pnum == 3) ffork();
  }

  /* Preliminary inits. Note: end/maxend/curend are highest, not
   * highest + 1 */
  base = DICTSZ * pnum + 256;
  locend = base + DICTSZ - 1;
  maxend = (1 << maxbits) - 1;
  if (maxend > locend) maxend = locend;

  while (TRUE) {
	curend = 255 + (clearflg ? 1 : 0);	/* init dictionary */
	dcharp = DICTSZ;	/* flag for none needed */
	curbits = 9;		/* init curbits (for copy 0) */
	while (TRUE) {		/* for each index in input */
		if (pnum == 4) {/* get index using getbits() */
			if (curbits < maxbits && (1 << curbits) <= curend) {
				/* Curbits needs to be increased */
				/* Due to uglyness in compress, these
				 * indices in the compressed file are
				 * wasted */
				while (inmod) getbits();
				curbits++;
			}
			getbits();
		} else
			getpipe();	/* get next index */

		if (iindex == 256 && clearflg) {
			if (pnum > 0) putpipe(iindex, 0);
			/* Due to uglyness in compress, these indices
			 * in the compressed file are wasted */
			while (inmod) getbits();
			break;
		}
		tindex = iindex;
		/* Convert the index part, ignoring spawned chars */
		while (tindex >= base) tindex = dindex[tindex - base];
		/* Pass on the index */
		putpipe(tindex, 0);
		/* Save the char of the last added entry, if any */
		if (dcharp < DICTSZ) dchar[dcharp++] = tindex;
		if (curend < maxend && ++curend > (base - 1))
			dindex[dcharp = (curend - base)] = iindex;

		/* Do spawned chars. They are naturally produced in
		 * the wrong order. To get them in the right order
		 * without using memory, a series of passes,
		 * progressively less deep, are used */
		tbase = base;
		while ((tindex = iindex) >= tbase) {/* for each char to spawn*/
			while ((tindex2 = dindex[tindex - base]) >= tbase)
				tindex = tindex2;    /* scan to desired char */
			putpipe(dchar[tindex-base], 1); /* put it to the pipe*/
			tbase = tindex + 1;
			if (tbase == 0) break;	/* it's a wrap */
		}
	}
  }
}