示例#1
0
int			write_instructions(int fd, int fdwrite)

{
  char			*tmp;
  int			size;
  int			i;
  char			*ins;
  char			*param;
  t_asm			*my_asm;

  i = 2;
  my_asm = NULL;
  while ((tmp = get_next_line(fd)))
    {
      i++;
      if (tmp != NULL && tmp[0] != '.' && all_space(tmp) != 0)
	{
	  tmp = remove_space(tmp);
	  ins = parse_action(tmp, 0);
	  param = parse_action(tmp, 1);
	  ins = remove_all_space(ins);
	  param = remove_all_space(param);
	  if (check_arg(ins) != 1 ||
	      check_param(ins, param) != 1)
	    return (error_line(i));
	  my_asm = add_action(my_asm, ins, param);
	}
    }
  my_asm = my_asm->next;
  if ((size = instructions_file(fdwrite, my_asm)) == -1
      || write_size(fdwrite, size) == -1)
    return (-1);
  return (0);
}
示例#2
0
static int get_key(char *begin, char *end, char *key)
{
	int i = 0;
	while (begin != end && (*begin == ' '|| *begin  == '\t')) {
		begin++;
	}
	if(begin == end)
		goto error;
	for(; begin != end; begin++)
	{
		if(*begin != ' ' && *begin != '\t')
			key[i++] = *begin;
		else
			break;
	}
	if(!all_space(begin,end))
		goto error;
	key[i] = '\0';
	return 1;
error:
	printf("line : %d , %s key formate error!\n",linenum,key);
	return 0;
}
示例#3
0
static int parse_conf_per_scope(FILE *stream)
{
	int scope = 0;
    char scopekey[MAXVALUELEN]={0};
    char line[MAXLINELEN]={0};
    char *p = NULL;
    FILE *fp = stream;

	while(1) {
        char *ret;
        ret = fgets(line, MAXLINELEN, fp);
        
        if (ret == NULL) {
            assert(feof(fp));
            if(feof(fp)){
                printf(" end of file,read configure file completed !\n");
                break;
            }else {
                perror(" read file error!");
                return 0;
            }
        }
        linenum++;

	    if((p = strstr(line,"#")) != NULL){
            char *tvl = line;
            for( ; tvl != p ; tvl++ ){
                if (*tvl != ' '&& *tvl != '\n' && *tvl != '\t' && *tvl != '\r') {
                    goto error1;
                }
            }
            p = NULL;
            continue;
            

	    } else if((p = strstr(line,"{"))!= NULL){
            assert(scope == 0);
            if (scope) {
                goto error1;
            }
            scope = 1;
            char *tvl = p+1;
            for ( ; tvl != line + strlen(line); tvl++) {
                if (*tvl != ' '&& *tvl != '\n' && *tvl != '\t' && *tvl != '\r') {
                    goto error1;
                }
            }
            if(!get_key(line, p, scopekey))
                return 0;
            p = NULL;

			if(strcmp(scopekey,"log") == 0 ){
				continue;
			}else if(strcmp(scopekey,"nba") == 0 ){
				continue;
            }else {
                printf("line: %d, %s is unknown scope key word!\n",linenum,scopekey);
                return 0;
            }
        }else if ((p = strstr(line,"}")) != NULL){
            assert(scope);
            if (!scope)
                goto error1;
            if(!all_space(line, p) || !all_space(p+1, line+strlen(line)))
                goto error1;
            scope = 0;
            p = NULL;
        }else if((p = strstr(line,";")) != NULL){
            if(!scope){
                goto error1;
            }
            if(!all_space(p+1, line+strlen(line))){
                goto error1;
            }
            char key[MAXVALUELEN];
			if(strcmp(scopekey,"log") == 0 ){
                char *m = NULL;
                if((m = strstr(line,":")) != NULL){
                    if(!get_key(line, m, key))
                        goto error1;
					if (strcmp(key, "baby") == 0) {
						if(!get_key(m+1, line+strlen(line)-2,BABY))
							goto error1;
					}else if (strcmp(key, "main") == 0) {
						if(!get_key(m+1, line+strlen(line)-2,MAIN))
							goto error1;
					}else if (strcmp(key, "book") == 0) {
						if(!get_key(m+1, line+strlen(line)-2,BOOK))
							goto error1;
                    }else {
                        printf("line: %d, %s is unknown key word!\n",linenum,key);
                        return 0;
                    }
                }
			}else if(strcmp(scopekey,"nba") == 0 ){
                char *m = NULL;
                if((m = strstr(line,":")) != NULL){
                    if(!get_key(line, m, key))
                    goto error1;
					if (strcmp(key, "jodan") == 0) {
						if(!get_key(m+1, line+strlen(line)-2,JODAN))
							goto error1;
					}else if (strcmp(key, "kobe") == 0) {
						if(!get_key(m+1, line+strlen(line)-2,KOBE))
							goto error1;
					}else if (strcmp(key, "yao") == 0) {
						if(!get_key(m+1, line+strlen(line)-2,YAO))
							goto error1;
                    }else {
                        printf("line: %d, %s is unknown key word!\n",linenum,key);
                        return 0;
                    }
                }
			}
        }else {
            if(!all_space(line, line + strlen(line)))
                goto error1;
        }
    }
    if(scope)
        goto error1;
    return 1;
error1:
    printf("line : %d ,configure formate error!\n",linenum);
    return 0;
}