Example #1
0
void		uncode_args(unsigned char *field, t_process *proc, int op_num,
					uint32_t *ar)
{
	size_t		i;
	size_t		curr;
	short		ind;

	curr = check_pc(proc->pc + 1 + (g_op[op_num].coding_byte));
	i = 0;
	while (i < g_op[op_num].nbr_arg)
	{
		if (ar[i] == T_REG)
		{
			ar[i] = (uint32_t)field[curr];
			curr = check_pc(curr + 1);
		}
		else if (ar[i] == T_DIR)
			ar[i] = convert_arg(field, &curr, g_op[op_num].flag_direct_size);
		else if (ar[i] == T_IND)
		{
			ind = (short)convert_arg(field, &curr, IND_READ);
			if (op_num != 12)
				ind = ind % IDX_MOD;
			ar[i] = ((op_num != 2) ? get_ind(field, (proc->pc + ind)) : ind);
		}
		i++;
	}
}
Example #2
0
static PyObject *entity_setstate(PyObject *self, PyObject *state)
{
  PyObject *dict, *public_id, *system_id, *unparsed_entities, *children, *temp;
  Py_ssize_t i, n;

  if (!PyArg_UnpackTuple(state, NULL, 5, 5,
                         &dict, &public_id, &system_id, &unparsed_entities,
                         &children))
    return NULL;

  if (!convert_arg(0, &PyDict_Type, &dict))
    return NULL;
  if (!convert_arg(3, &PyDict_Type, &unparsed_entities))
    return NULL;
  if (!convert_arg(4, &PyTuple_Type, &children))
    return NULL;

  if (dict) {
    if (PyType_HasFeature(self->ob_type, Py_TPFLAGS_HEAPTYPE)) {
      temp = PyObject_GetAttrString(self, "__dict__");
      if (temp == NULL)
        return NULL;
      if (PyDict_Update(temp, dict) < 0) {
        Py_DECREF(temp);
        return NULL;
      }
      Py_DECREF(temp);
    }
  }
  temp = Entity_GET_PUBLIC_ID(self);
  Entity_SET_PUBLIC_ID(self, public_id);
  Py_INCREF(public_id);
  Py_DECREF(temp);

  temp = Entity_GET_SYSTEM_ID(self);
  Entity_SET_SYSTEM_ID(self, system_id);
  Py_INCREF(system_id);
  Py_DECREF(temp);

  if (unparsed_entities) {
    temp = Entity_GET_UNPARSED_ENTITIES(self);
    PyDict_Clear(temp);
    if (PyDict_Update(temp, unparsed_entities) < 0)
      return NULL;
  }
  if (children) {
    for (i = 0, n = PyTuple_GET_SIZE(children); i < n; i++) {
      NodeObject *node = (NodeObject *)PyTuple_GET_ITEM(children, i);
      if (Container_Append((NodeObject *)self, node) < 0)
        return NULL;
    }
  }
  Py_RETURN_NONE;
}
Example #3
0
static void			get_result(t_ullong arg, t_format *f)
{
	t_uchar			*tmp;

	if (f->precision < (int)ft_strlen(f->buf))
		f->precision = ft_strlen(f->buf);
	if (f->width > f->precision && !f->flag_minus
		&& !f->flag_zero && f->precision != -1)
		f->res += print_char(f->width - f->precision, ' ');
	if (f->flag_zero)
		f->res += print_char(f->width - ft_strlen(f->buf), '0');
	f->res += print_char(f->precision - ft_strlen(f->buf), '0');
	if (arg != 0 || f->precision || f->flag_minus)
	{
		if (f->mod_l)
		{
			tmp = convert_arg(arg);
			tmp--;
			while (*(++tmp))
				f->res = print_char(ft_strlen((char *)tmp), *tmp);
		}
		else
			f->res = print_char(1, arg);
	}
	if (f->flag_minus)
		f->res += print_char(f->width - f->precision, ' ');
}
Example #4
0
uint32_t	get_ind(unsigned char *field, size_t curr)
{
	uint32_t		arg;

	arg = convert_arg(field, &curr, IND_SIZE);
	return (arg);
}
Example #5
0
void			ft_print_u(va_list *ap, t_format *f)
{
	t_ullong	arg;

	arg = va_arg(*ap, t_ullong);
	update_format(f);
	convert_arg(arg, f);
	get_result(arg, f);
	init_f(f);
}
Example #6
0
File: rrd_mod.c Project: adh/dfsch
static void build_args(dfsch_object_t* list, int* pargc, char*** pargv){
  int alloc = 16;
  char** argv = GC_MALLOC(sizeof(char*) * alloc);
  int argc = 0;
  
  while (DFSCH_PAIR_P(list)){
    if (alloc <= argc){
      alloc *= 2;
      argv = GC_REALLOC(argv, sizeof(char*) * alloc);
    }

    argv[argc] = convert_arg(DFSCH_FAST_CAR(list));

    argc++;
    list = DFSCH_FAST_CDR(list);
  }
  *pargc = argc;
  *pargv = argv;
}
Example #7
0
static void
convert_line (void)
{
        char *c, *cc;
        char xbuf[BUFSZ];

        cc = out_line;
        for (c = xcrypt(in_line, xbuf); *c; c++) {

            *cc = 0;
            switch(*c) {

                case '\r':
                case '\n':
                        *(++cc) = 0;
                        return;

                case '%':
                        if (*(c+1)) {
                            convert_arg(*(++c));
                            switch (*(++c)) {

                                        /* insert "a"/"an" prefix */
                                case 'A': strcat(cc, An(cvt_buf));
                                    cc += strlen(cc);
                                    continue; /* for */
                                case 'a': strcat(cc, an(cvt_buf));
                                    cc += strlen(cc);
                                    continue; /* for */

                                        /* capitalize */
                                case 'C': cvt_buf[0] = highc(cvt_buf[0]);
                                    break;

                                        /* pluralize */
                                case 'P': cvt_buf[0] = highc(cvt_buf[0]);
                                case 'p': strcpy(cvt_buf, makeplural(cvt_buf));
                                    break;

                                        /* append possessive suffix */
                                case 'S': cvt_buf[0] = highc(cvt_buf[0]);
                                case 's': strcpy(cvt_buf, "TODO: s_suffix(cvt_buf)");
                                    break;

                                        /* strip any "the" prefix */
                                case 't': if (!strncmpi(cvt_buf, "the ", 4)) {
                                        strcat(cc, &cvt_buf[4]);
                                        cc += strlen(cc);
                                        continue; /* for */
                                    }
                                    break;

                                default: --c;   /* undo switch increment */
                                    break;
                            }
                            strcat(cc, cvt_buf);
                            cc += strlen(cvt_buf);
                            break;
                        }       /* else fall through */

                default:
                        *cc++ = *c;
                        break;
            }
        }
        if (cc >= out_line + sizeof out_line)
            panic("convert_line: overflow");
        *cc = 0;
        return;
}
Example #8
0
/**
 * We have a complete line from the user, lookup the commands and execute them
 *
 * Commands are tokenised based on white space and then the first
 * word is checked againts the cmds table. If a match is found the
 * second word is compared to the different options for that command.
 *
 * Commands may also take up to 3 additional arguments, these are all
 * assumed to the numeric values and will be converted before being passed
 * to the handler function for the command.
 *
 * @param cli		The CLI_SESSION
 * @return	Returns 0 if the interpreter should exit
 */
int
execute_cmd(CLI_SESSION *cli)
{
DCB		*dcb = cli->session->client;
int		argc, i, j, found = 0;
char		*args[MAXARGS];
char		*saveptr, *delim = " \t\r\n";
unsigned long	arg1, arg2, arg3;

	/* Tokenize the input string */
	args[0] = strtok_r(cli->cmdbuf, delim, &saveptr);
	i = 0;
	do {
		i++;
		args[i] = strtok_r(NULL, delim, &saveptr);
	} while (args[i] != NULL && i < MAXARGS);

	if (args[0] == NULL)
		return 1;
	argc = i - 2;	/* The number of extra arguments to commands */
	

	if (!strcasecmp(args[0], "help"))
	{
		if (args[1] == NULL)
		{
			found = 1;
			dcb_printf(dcb, "Available commands:\n");
			for (i = 0; cmds[i].cmd; i++)
			{
				for (j = 0; cmds[i].options[j].arg1; j++)
				{
					dcb_printf(dcb, "    %s %s\n", cmds[i].cmd, cmds[i].options[j].arg1);
				}
			}
		}
		else
		{
			for (i = 0; cmds[i].cmd; i++)
			{
				if (!strcasecmp(args[1], cmds[i].cmd))
				{
					found = 1;
					dcb_printf(dcb, "Available options to the %s command:\n", args[1]);
					for (j = 0; cmds[i].options[j].arg1; j++)
					{
						dcb_printf(dcb, "    %-10s %s\n", cmds[i].options[j].arg1,
										cmds[i].options[j].help);
					}
				}
			}
			if (found == 0)
			{
				dcb_printf(dcb, "No command %s to offer help with\n", args[1]);
			}
		}
		found = 1;
	}
	else if (!strcasecmp(args[0], "quit"))
	{
		return 0;
	}
	else if (argc >= 0)
	{
		for (i = 0; cmds[i].cmd; i++)
		{
			if (strcasecmp(args[0], cmds[i].cmd) == 0)
			{
				for (j = 0; cmds[i].options[j].arg1; j++)
				{
                                        found = 1; /**< command and sub-command match */
					if (strcasecmp(args[1], cmds[i].options[j].arg1) == 0)
					{
						if (argc != cmds[i].options[j].n_args)
						{
							dcb_printf(dcb, "Incorrect number of arguments: %s %s expects %d arguments\n",
								cmds[i].cmd, cmds[i].options[j].arg1,
								cmds[i].options[j].n_args);
							
						}
						else
						{
							switch (cmds[i].options[j].n_args)
							{
							case 0:
								cmds[i].options[j].fn(dcb);
								break;
							case 1:
								arg1 = convert_arg(args[2],cmds[i].options[j].arg_types[0]);
								if (arg1)
									cmds[i].options[j].fn(dcb, arg1);
								else
									dcb_printf(dcb, "Invalid argument: %s\n",
										args[2]);
								break;
							case 2:
								arg1 = convert_arg(args[2],cmds[i].options[j].arg_types[0]);
								arg2 = convert_arg(args[3],cmds[i].options[j].arg_types[1]);
								if (arg1 && arg2)
									cmds[i].options[j].fn(dcb, arg1, arg2);
								else if (arg1 == 0)
									dcb_printf(dcb, "Invalid argument: %s\n",
										args[2]);
								else
									dcb_printf(dcb, "Invalid argument: %s\n",
										args[3]);
								break;
							case 3:
								arg1 = convert_arg(args[2],cmds[i].options[j].arg_types[0]);
								arg2 = convert_arg(args[3],cmds[i].options[j].arg_types[1]);
								arg3 = convert_arg(args[4],cmds[i].options[j].arg_types[2]);
								if (arg1 && arg2 && arg3)
									cmds[i].options[j].fn(dcb, arg1, arg2, arg3);
								else if (arg1 == 0)
									dcb_printf(dcb, "Invalid argument: %s\n",
										args[2]);
								else if (arg2 == 0)
									dcb_printf(dcb, "Invalid argument: %s\n",
										args[3]);
								else if (arg3 == 0)
									dcb_printf(dcb, "Invalid argument: %s\n",
										args[4]);
							}
						}
					}
				}
				if (!found)
				{
					dcb_printf(dcb,
						"Unknown or missing option for the %s command. Valid sub-commands are:\n",
							cmds[i].cmd);
					for (j = 0; cmds[i].options[j].arg1; j++)
					{
						dcb_printf(dcb, "    %-10s %s\n", cmds[i].options[j].arg1,
										cmds[i].options[j].help);
					}
					found = 1;
				}
			}
		}
	}
	else if (argc == -1)
	{
		dcb_printf(dcb,
			"Commands must consist of at least two words. Type help for a list of commands\n");
		found = 1;
	}
	if (!found)
		dcb_printf(dcb,
			"Command '%s' not known, type help for a list of available commands\n", args[0]);
	memset(cli->cmdbuf, 0, 80);

	return 1;
}
static const char *
convert_line(const char *in_line)
{
    /* xcrypt needs us to allocate a buffer for it */
    char decrypted_line[strlen(in_line)+1];
    xcrypt(in_line, decrypted_line);
    const char *rv = "";
    char *c;

    /* Tokenize the decrypted line; we stop at \r, \n, or \0, and do
       special handling of "%" characters.

       The algorithm used here is quadratic (when linear is possible), but
       given that the lines are only 80 characters long, I feel that a clear
       algorithm is superior to a low computational complexity algorithm. */

    for (c = xcrypt(in_line, decrypted_line);; c++) {

        switch (*c) {

        case '\r':
        case '\n':
        case '\0':
            return rv;

        case '%':
            if (c[1]) {
                const char *conversion = convert_arg(*(++c));
                switch (*(++c)) {

                    /* insert "a"/"an" prefix */
                case 'A':
                    rv = msgcat(rv, An(conversion));
                    break;
                case 'a':
                    rv = msgcat(rv, an(conversion));
                    break;

                    /* capitalize */
                case 'C':
                    rv = msgcat(rv, msgupcasefirst(conversion));
                    break;

                    /* pluralize */
                case 'P':
                    /* Note: makeplural doesn't work on arbitrarily capitalized
                       strings */
                    rv = msgcat(rv, msgupcasefirst(makeplural(conversion)));
                    break;
                case 'p':
                    rv = msgcat(rv, makeplural(conversion));
                    break;

                    /* append possessive suffix */
                case 'S':
                    conversion = msgupcasefirst(conversion);
                    /* fall through */
                case 's':
                    rv = msgcat(rv, s_suffix(conversion));
                    break;

                    /* strip any "the" prefix */
                case 't':
                    if (!strncmpi(conversion, "the ", 4))
                        rv = msgcat(rv, conversion + 4);
                    else
                        rv = msgcat(rv, conversion);
                    break;

                default:
                    --c;        /* undo switch increment */
                    rv = msgcat(rv, conversion);
                    break;
                }
                break;
            }
            /* else fall through */
        default:
            rv = msgkitten(rv, *c);
            break;
        }
    }
}