예제 #1
0
void	three_params_second(int i, t_data *data, t_instruc *inst, int *order)
{
	if (g_op[i].param_type[*order] == T_REG)
	{
		if (is_register(inst->trim, data, inst, order) == 1)
			return ;
		else
			error_line(data, "Incorrect input parameters");
	}
	else if (g_op[i].param_type[*order] == (T_REG | T_DIR | T_IND))
	{
		if (three_params_second_cut(data, inst, order) == 1)
			return ;
	}
	else if (g_op[i].param_type[*order] == (T_DIR | T_REG))
	{
		if (is_direct(inst->trim, data, inst, order) == 1)
			return ;
		else if (is_register(inst->trim, data, inst, order) == 1)
			return ;
		else
			error_line(data, "Incorrect input parameters");
	}
	else
		error_line(data, "Incorrect input parameters");
}
예제 #2
0
void		inst_three_params(char **inst_line, char *trim, t_data *data)
{
	t_instruc	*new_elem;
	t_label		*tmp_lbl;
	char		**inst_params;
	int			order;

	new_elem = NULL;
	inst_params = NULL;
	order = 0;
	new_elem = inst_new_elem(ft_strdup(inst_line[0]));
	check_opcode(inst_line[0], new_elem);
	check_params(inst_line[1], new_elem, data, &order);
	new_elem->param_1 = no_comma(inst_line[1]);
	if ((inst_params = ft_strsplit(trim, SEPARATOR_CHAR)) == NULL)
		error("Malloc error");
	if (inst_params[1] == NULL || inst_params[2] == NULL)
		error_line(data, "Incorrect input parameters");
	check_params(inst_params[1], new_elem, data, &order);
	new_elem->param_2 = ft_strdup(ft_pass_space_tab(inst_params[1]));
	check_params(inst_params[2], new_elem, data, &order);
	new_elem->param_3 = ft_strdup(ft_pass_space_tab(inst_params[2]));
	tmp_lbl = last_label(data);
	addend_inst_lst(&tmp_lbl->insts, new_elem);
	free_strsplit(inst_params);
}
예제 #3
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);
}
예제 #4
0
int		three_params_second_cut(t_data *data, t_instruc *inst, int *order)
{
	if (is_register(inst->trim, data, inst, order) == 1)
		return (1);
	else if (is_direct(inst->trim, data, inst, order) == 1)
		return (1);
	else if (is_indirect(inst->trim, data, inst, order) == 1)
		return (1);
	else
		error_line(data, "Incorrect input parameters");
	return (0);
}
예제 #5
0
char	*check_comm(char *str, t_data *data)
{
	char	**comm;

	comm = NULL;
	if (is_in_str(COMMENT_CHAR, str) > 0)
	{
		if ((comm = ft_strsplit(str, COMMENT_CHAR)) == NULL)
			error_line(data, "Malloc error");
		return (comm[0]);
	}
	return (str);
}
예제 #6
0
void error_sxc(int e, FILE *fp) { // 出错处理
    long int n; // 错误位置偏移量
    ErrorLine el; // 错误信息
    int i;

    n = ftell(fp); // 得到错误位置偏移量
    el = malloc(sizeof(struct errorLineInfo));
    error_line(n, el); // 得到错误信息

    // 错误分类处理
    /* v1.0
    switch(e) {
    case PRETREATMENT_ERROR :
    printf("Error! PRETREATMENT Error!\nLine: %3d  %s\n", el -> line_no, el -> line_info);
    break;
    case IF_ERROR :
    printf("Error! IF Error!\nLine: %3d  %s\n", el -> line_no, el -> line_info);
    break;
    case WHILE_ERROR :
    printf("Error! WHILE Error!\nLine: %3d  %s\n", el -> line_no, el -> line_info);
    break;
    case IN_ERROR :
    printf("Error! IN Error!\nLine: %3d  %s\n", el -> line_no, el -> line_info);
    break;
    case OUT_ERROR:
    printf("Error! OUT Error!\nLine: %3d  %s\n", el -> line_no, el -> line_info);
    break;
    case VALUE_ERROR:
    printf("Error! VALUE Error!\nLine: %3d  %s\n", el -> line_no, el -> line_info);
    break;
    default :
    printf("Error! UNKNOWN Error!\nLine: %3d  %s\n", el -> line_no, el -> line_info);
    }
    */

    // v1.1
    for (i = 1; i < ERROR_NUM; i++) {
        if (e == eo[i].errorcode) {
            printf("ERROR! %s\nLine: %3d\n%s\n", eo[i].str, el->line_no, el->line_info);
            break;
        }
    }
    if (i == ERROR_NUM) {
        printf("ERROR! %s\nLine: %3d:\n%s\n", eo[0].str, el->line_no, el->line_info);
    }

    DeleteList(var_l); // 销毁变量列表

    exit(1); // 异常退出

}
예제 #7
0
파일: bits.c 프로젝트: ftk/XXLDDRace
static void *del_ptr (void *ptr)
{
    int i;

    for (i = 0; i < 512; ++i)
        if (vptrs [i] == ptr) {
            vptrs [i] = NULL;
            break;
        }

    if (i == 512)
        error_line ("free invalid ptr!");

    return ptr;
}
예제 #8
0
파일: bits.c 프로젝트: ftk/XXLDDRace
static void *add_ptr (void *ptr)
{
    int i;

    for (i = 0; i < 512; ++i)
        if (!vptrs [i]) {
            vptrs [i] = ptr;
            break;
        }

    if (i == 512)
        error_line ("too many mallocs!");

    return ptr;
}
예제 #9
0
void		check_all_params(char *trim, char **inst_line, t_data *data,
		int *ret)
{
	if (is_in_str(SEPARATOR_CHAR, trim) == 0 && check_opcode_name(
				inst_line[0]) == 1)
		inst_one_param(inst_line, data);
	else if (is_in_str(SEPARATOR_CHAR, trim) == 1 && check_opcode_name(
				inst_line[0]) == 1)
		inst_two_params(inst_line, trim, data);
	else if (is_in_str(SEPARATOR_CHAR, trim) == 2 && check_opcode_name(
				inst_line[0]) == 1)
		inst_three_params(inst_line, trim, data);
	else if (is_in_str(SEPARATOR_CHAR, trim) > 3 && ft_strchr(trim,
				COMMENT_CHAR) == NULL)
		error_line(data, "Incorrect number of params");
	else
		*ret = 0;
}
예제 #10
0
void		inst_one_param(char **inst_line, t_data *data)
{
	t_instruc	*new_elem;
	t_label		*tmp_lbl;
	int			order;
	int			i;

	new_elem = NULL;
	order = 0;
	i = 0;
	while (inst_line[i])
		i++;
	if (i > 2)
		error_line(data, "Incorrect number of params");
	new_elem = inst_new_elem(ft_strdup(inst_line[0]));
	check_opcode(inst_line[0], new_elem);
	check_params(inst_line[1], new_elem, data, &order);
	new_elem->param_1 = no_comma(inst_line[1]);
	tmp_lbl = last_label(data);
	addend_inst_lst(&tmp_lbl->insts, new_elem);
}
예제 #11
0
파일: http_active.c 프로젝트: soohyunc/TFWC
void main (int argc, char* argv[])
{
  int i;

  char input_name[256] = "";
  char output_name[256] = "";
  long idle_limit = 2000;  /* default threshold for idleness in millisec. */ 
  long elapsed;

  char parse_line[500];
  char discard[50];

  char *cursor;
  char *vp;

  /* Parse the command line */
  i = 1;
  while (i < argc) {
    if (strcmp (argv[i], "-r") == 0) {
      if (++i >= argc) Usage (argv[0]);
      strcpy (input_name, argv[i]);
    }
    else if (strcmp (argv[i], "-w") == 0) {
      if (++i >= argc) Usage (argv[0]);
      strcpy (output_name, argv[i]);
    }
    else if (strcmp (argv[i], "-I") == 0) {
      if (++i >= argc) Usage (argv[0]);
      idle_limit = (long)atoi(argv[i]);
    }
    else 
      Usage (argv[0]);
    i++;
  }

  /* Open files */
  if (strcmp(output_name, "") == 0)
     outFP = stdout;
  else 
     {
      strcat(output_name, ".activity");
      if ((outFP = fopen (output_name, "w")) == NULL) {
          fprintf (stderr, "error opening %s\n", output_name);
          exit (-1);
          }
     }

  if (strcmp(input_name, "") == 0)
     dumpFP = stdin;
  else 
     {
      if ((dumpFP = fopen (input_name, "r")) == NULL) {
          fprintf (stderr, "error opening %s\n", input_name);
          exit (-1);
         }
     }

  /* Read each record in the input file.  Look for a change in the 
     source IP address (which indicates a new client).  If a new
     client, log the end of an idle period (if any) for the old
     client and initialize the connection table for the new client.
     If a record for the current client has been read, classify the
     type of event it represent and process it to update the client
     and connection state.
  */

  while (!feof (dumpFP)) {
    /* Get and parse line of data */
    if (fgets (new_line, sizeof(new_line), dumpFP) == NULL)
       break;
    /* get first line pieces */

    sscanf (new_line, "%s %s %s %s %s %s %s",
                      &ts, &sh, &sp, &gt, &dh, &dp, &fl);

    /* if an ERR line, just show it */
    if (strcmp(fl, "ERR:") == 0)
       {
        error_line(new_line);
        continue;
       }

    /* now get variable part starting with the ":" considering that */
    /* interpretation of the remaining fields depends on the flag value */ 
    /* This is necessary to find the ending timestamp for FIN, RST, and 
       TRM events.
    */

    strcpy(parse_line, new_line);
    cursor = parse_line;
    vp = (char *)strsep(&cursor, ":" );
    if ((cursor == (char *)NULL) ||
        (vp == (char *)NULL))
        {
         error_line(new_line);
         continue;
        }

    /* Classify the event type by looking at the flag field from input
       records */

    if ((strcmp(fl, "REQ") == 0) || 
        (strcmp(fl, "REQ-") == 0))
       event_type = REQ;
    else
      {
       if ((strcmp(fl, "RSP") == 0) ||
           (strcmp(fl, "RSP-") == 0))
          event_type = RSP;
       else
	 {
          if ((strcmp(fl, "FIN") == 0) ||
              (strcmp(fl, "TRM") == 0) ||
              (strcmp(fl, "RST") == 0))
	     {
	       /* need the ending timestamp from these record types */
              sscanf(cursor, "%s %s", &discard, &earliest_end);
              event_type = END;
             }
           else 
             {
              if (strcmp(fl, "SYN") == 0)
                 event_type = SYN;
              else
		{
                 if (strcmp(fl, "ACT-REQ") == 0)
                    event_type = ACT_REQ;
                 else
                     if (strcmp(fl, "ACT-RSP") == 0)
                        event_type = ACT_RSP;
                }
             }
	 }
      }

   /* now use data from new trace record to update status */  
   /* first check to see if this is the same client host */
   if (strcmp(current_src, sh) != 0)
       {
        if (client_state == IDLE)
            log_IDLE(last_client_ts);  
        ClearConnections();
        client_state = PENDING_ACTIVE;
        strcpy(current_src, sh);
       }


   /* update the connection status for this client's connection */

   set_connection(sp, dh, dp, event_type);

   
   /* The main processing for idle periods is done by maintaining a state
      variable (client_status) for the client and looking for specific input 
      record types at different values of the state variable.  The 
      values of client_state and their implications are:
      PENDING_ACTIVE   - A new client is started and remains PENDING_ACTIVE
                         until an activity indication such as ACT-REQ,
                         ACT-RSP, or REQ is seen in which case it enters
                         the ACTIVE state.  If there is an initial response,
                         PENDING_IDLE is entered.
      ACTIVE           - At least one request is outstanding and the state
                         can only change if there is a response completion
                         or connection termination.
      PENDING_IDLE     - There are no requests outstanding but the idle
                         period threshold has not elapsed since it entered
                         the PENDING_IDLE state.
      IDLE             - No outstanding requests for a period greater than
                         the idle threshold.  The IDLE (and PENDING_IDLE)
                         states are exited on activity indication such as 
                         ACT-REQ, ACT-RSP, or REQ
   */

   switch (client_state)
      {
       case PENDING_ACTIVE:
            switch (event_type)
	       {
	        case SYN:
                    break;
	        case ACT_REQ:
	        case ACT_RSP:
                    client_state = ACTIVE;
                    break;
	        case REQ:
                    client_state = ACTIVE;
                    log_REQ();
                    break;
	        case RSP:
                    client_state = PENDING_IDLE;
                    strcpy(idle_begin, ts);
                    log_RSP();
                    break;
	        case END:
                    break;
               }
            break;

       case ACTIVE:
            switch (event_type)
	       {
	        case SYN:
	        case ACT_REQ:
	        case ACT_RSP:
                    break;
	        case REQ:
                    log_REQ();
                    break;
	        case RSP:
                    log_RSP(); 
                    if (ConnectionsActive() == 0) /* Any active connections?*/
		       {
                        client_state = PENDING_IDLE;
                        strcpy(idle_begin, ts);
                       }
                    break;
	        case END:
                    if (ConnectionsActive() == 0) /* Any active connections?*/
		       {
                        client_state = PENDING_IDLE;
                        strcpy(idle_begin, earliest_end);
                       }
                    break;
               }
            break;

       case PENDING_IDLE:
	    /* must start checking time, if > n seconds elapse since
               entering PENDING_IDLE state, enter IDLE state */
            elapsed = elapsed_ms(ts, idle_begin);
            if (elapsed < idle_limit)
	       {
                switch (event_type)
		   {
		    case SYN:
		    case END:
                        break;
	            case ACT_REQ:
	            case ACT_RSP:
                        client_state = ACTIVE;
                        break;
		    case REQ:
                        client_state = ACTIVE;
                        log_REQ();
                        break;
		    case RSP:
                        log_RSP();
                        break;
                   }
                break;  /* ends case PENDING_IDLE */
               }
            else          /* it has crossed the idle threshold */ 
                client_state = IDLE;
       /* NOTE: drop through to IDLE to handle the current event */

       case IDLE:
            switch (event_type)
	       {
		case SYN:
		case END:
                    break;
	        case ACT_REQ:
	        case ACT_RSP:
                    client_state = ACTIVE;
                    log_IDLE(ts);
                    break;
		case REQ:
                    client_state = ACTIVE;
                    log_IDLE(ts);
                    log_REQ();
                    break;
		case RSP:
                    log_RSP();
                    break;
                break;  /* ends case PENDING_IDLE */
               }
             break;

       default:
             break;
      } /* end switch */

    strcpy(last_client_ts, ts);

   } /* end while (!feof ....) */ 
  close (dumpFP);
  close (outFP);
}