Beispiel #1
0
/// Parses a single test case and writes it to the output.
///
/// This has to be called after the ident property has been read, and takes care
/// of reading the rest of the test case and printing the parsed result.
///
/// Be aware that this consumes the newline after the test case.  The caller
/// should not look for it.
///
/// \param [in,out] input File from which to read the header.
/// \param [in,out] output File to which to write the parsed test case.
/// \param [in,out] name The name of the test case.  This is a non-const pointer
///     and the input string is modified to simplify tokenization.
///
/// \return OK if the parsing succeeds; an error otherwise.
static kyua_error_t
parse_test_case(FILE* input, FILE* output, char* name)
{
    kyua_error_t error;
    char line[1024];  // It's ugly to have a limit, but it's easier this way.

    fprintf(output, "test_case{name=");
    print_quoted(name, output, true);

    error = kyua_error_ok();
    while (!kyua_error_is_set(error) &&
           fgets_no_newline(line, sizeof(line), input) != NULL &&
           strcmp(line, "") != 0) {
        char* key = NULL; char* value = NULL;
        error = parse_property(line, &key, &value);
        if (!kyua_error_is_set(error)) {
            const char* out_key = rewrite_property(key);
            if (out_key == rewrite_error) {
                error = kyua_generic_error_new("Unknown ATF property %s", key);
            } else if (out_key == NULL) {
                fprintf(output, ", ['custom.");
                print_quoted(key, output, false);
                fprintf(output, "']=");
                print_quoted(value, output, true);
            } else {
                fprintf(output, ", %s=", out_key);
                print_quoted(value, output, true);
            }
        }
    }

    fprintf(output, "}\n");

    return error;
}
Beispiel #2
0
local int stats_print_stats(DBT *key, DBT *val)
{
    struct player_record_key *k = key->data;
    struct
    {
        unsigned short stat;
        int val;
    } *v = val->data;
    int c = val->size / sizeof(*v), cur;

    if (!stats_match(key, val))
        return FALSE;

    print_quoted((unsigned char *)k->name);
    cur = 0;
    for (; c--; v++)
    {
        int pos = stats_args.statmap[v->stat];
        /* if we didn't see it before, just skip it */
        if (pos == 0)
            continue;
        /* fill in commas until the right spot */
        for (; cur < pos; cur++)
            putchar(',');
        printf("%d", v->val);
    }
    while (cur < stats_args.statmap[MAX_STAT])
        putchar(','), cur++;
    putchar('\n');

    return FALSE;
}
Beispiel #3
0
static void
checked_print_quoted (struct format_val *dest,
                           const char *format, const char *s)
{
  int rv = print_quoted (dest->stream, dest->quote_opts, dest->dest_is_tty,
                         format, s);
  if (rv < 0)
    nonfatal_nontarget_file_error (errno, dest->filename);
}
Beispiel #4
0
void
dump_to_file(void) {
        FILE *file = fopen("atom.dump","w");
        for(int i = 0; i < HASHSIZE*CUCKOO_HASHES; i++) {
                atom_t a = htable[i].atom;
                if(ATOM_VALID(a)) {
                        fprintf(file,"%u:",ATOM_LEN(a));
                        print_quoted(file, ATOM_PTR(a),ATOM_LEN(a));
                        fwrite("\n",1,1,file);
                }
        }
}
Beispiel #5
0
/*
 * TODO - sort output
 */
int
aliascmd(int argc, char **argv)
{
	char *n, *v;
	int ret = 0;
	struct alias *ap;

	if (argc == 1) {
		int i;

		for (i = 0; i < ATABSIZE; i++)
			for (ap = atab[i]; ap; ap = ap->next) {
				if (*ap->name != '\0') {
					out1fmt("alias %s=", ap->name);
					print_quoted(ap->val);
					out1c('\n');
				}
			}
		return (0);
	}
	while ((n = *++argv) != NULL) {
		if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
			if ((ap = lookupalias(n, 0)) == NULL) {
				outfmt(out2, "alias: %s not found\n", n);
				ret = 1;
			} else {
				out1fmt("alias %s=", n);
				print_quoted(ap->val);
				out1c('\n');
			}
		} else {
			*v++ = '\0';
			setalias(n, v);
		}
	}

	return (ret);
}
Beispiel #6
0
int
showvars(shinstance *psh, const char *name, int flag, int show_value)
{
    struct var **vpp;
    struct var *vp;
    const char *p;

    static struct var **list;	/* static in case we are interrupted */
    static int list_len;
    int count = 0;

    if (!list) {
        list_len = 32;
        list = ckmalloc(psh, list_len * sizeof(*list));
    }

    for (vpp = psh->vartab ; vpp < psh->vartab + VTABSIZE ; vpp++) {
        for (vp = *vpp ; vp ; vp = vp->next) {
            if (flag && !(vp->flags & flag))
                continue;
            if (vp->flags & VUNSET && !(show_value & 2))
                continue;
            if (count >= list_len) {
                list = ckrealloc(psh, list,
                                 (list_len << 1) * sizeof(*list));
                list_len <<= 1;
            }
            list[count++] = vp;
        }
    }

    qsort(list, count, sizeof(*list), sort_var);

    for (vpp = list; count--; vpp++) {
        vp = *vpp;
        if (name)
            out1fmt(psh, "%s ", name);
        for (p = vp->text ; *p != '=' ; p++)
            out1c(psh, *p);
        if (!(vp->flags & VUNSET) && show_value) {
            out1fmt(psh, "=");
            print_quoted(psh, ++p);
        }
        out1c(psh, '\n');
    }
    return 0;
}
Beispiel #7
0
void
addr(char *file)
{
	while (*file == ' ' || *file == '\t')
		file++;

	struct message *msg = blaze822(file);
	if (!msg)
		return;

	char *h = hflag;
	char *v;
	while (*h) {
		char *n = strchr(h, ':');
		if (n)
			*n = 0;
		v = blaze822_chdr(msg, h);
		if (v) {
			char *disp, *addr;
			char vdec[16384];
			blaze822_decode_rfc2047(vdec, v, sizeof vdec - 1, "UTF-8");
			vdec[sizeof vdec - 1] = 0;
			v = vdec;

			while ((v = blaze822_addr(v, &disp, &addr))) {
				if (disp && addr && strcmp(disp, addr) == 0)
					disp = 0;
				if (disp && addr) {
					if (aflag) {
						printf("%s\n", addr);
					} else {
						print_quoted(disp);
						printf(" <%s>\n", addr);
					}
				} else if (addr) {
					printf("%s\n", addr);
				}
			}
		}
		if (n) {
			*n = ':';
			h = n + 1;
		} else {
			break;
		}
	}
}
Beispiel #8
0
void
print_addresses(char *s)
{
	char *disp, *addr;
	char sdec[4096];

	if (dflag) {
		blaze822_decode_rfc2047(sdec, s, sizeof sdec, "UTF-8");
		sdec[sizeof sdec - 1] = 0;
		s = sdec;
	}

	while ((s = blaze822_addr(s, &disp, &addr))) {
		if (Hflag && addr)
			printf("%s\t", curfile);

		if (disp && addr) {
			print_quoted(disp);
			printf(" <%s>\n", addr);
		} else if (addr) {
			printf("%s\n", addr);
		}
	}
}
Beispiel #9
0
int
trapcmd(int argc, char **argv)
{
	char *action;
	char **ap;
	int signo;

	if (argc <= 1) {
		for (signo = 0 ; signo <= NSIG ; signo++)
			if (trap[signo] != NULL) {
				out1fmt("trap -- ");
				print_quoted(trap[signo]);
				out1fmt(" %s\n",
				    (signo) ? sys_signame[signo] : "EXIT");
			}
		return 0;
	}
	ap = argv + 1;

	action = NULL;

	if (strcmp(*ap, "--") == 0)
		if (*++ap == NULL)
			return 0;

	if (signame_to_signum(*ap) == -1) {
		if ((*ap)[0] == '-') {
			if ((*ap)[1] == '\0')
				ap++;
			else if ((*ap)[1] == 'l' && (*ap)[2] == '\0') {
				printsignals();
				return 0;
			}
			else
				error("bad option %s\n", *ap);
		}
		else
			action = *ap++;
	}

	while (*ap) {
		if (is_number(*ap))
			signo = number(*ap);
		else
			signo = signame_to_signum(*ap);

		if (signo < 0 || signo > NSIG)
			error("%s: bad trap", *ap);

		INTOFF;
		if (action)
			action = savestr(action);

		if (trap[signo])
			ckfree(trap[signo]);

		trap[signo] = action;

		if (signo != 0)
			setsignal(signo, 0);
		INTON;
		ap++;
	}
	return 0;
}
Beispiel #10
0
void
DOMWriter::writeDocString(String * name)
{
  print_quoted(out, name);
}
Beispiel #11
0
void
DOMWriter::writeAttrText(String * name)
{
  print_quoted(out, name);
}
Beispiel #12
0
int
trapcmd(int argc, char **argv)
{
	char *action;
	char **ap;
	int signo;
	int errs = 0;
	int printonly = 0;

	ap = argv + 1;

	if (argc == 2 && strcmp(*ap, "-l") == 0) {
		printsignals();
		return 0;
	}
	if (argc == 2 && strcmp(*ap, "-") == 0) {
		for (signo = 0; signo < NSIG; signo++) {
			if (trap[signo] == NULL)
				continue;
			INTOFF;
			ckfree(trap[signo]);
			trap[signo] = NULL;
			if (signo != 0)
				setsignal(signo, 0);
			INTON;
		}
		return 0;
	}
	if (argc >= 2 && strcmp(*ap, "-p") == 0) {
		printonly = 1;
		ap++;
		argc--;
	}

	if (argc > 1 && strcmp(*ap, "--") == 0) {
		argc--;
		ap++;
	}

	if (argc <= 1) {
		int count;

		if (printonly) {
			for (count = 0, signo = 0 ; signo < NSIG ; signo++)
				if (trap[signo] == NULL) {
					if (count == 0)
						out1str("trap -- -");
					out1fmt(" %s", trap_signame(signo));
					/* oh! unlucky 13 */
					if (++count >= 13) {
						out1str("\n");
						count = 0;
					}
				}
			if (count)
				out1str("\n");
		}

		for (count = 0, signo = 0 ; signo < NSIG ; signo++)
			if (trap[signo] != NULL && trap[signo][0] == '\0') {
				if (count == 0)
					out1str("trap -- ''");
				out1fmt(" %s", trap_signame(signo));
				/*
				 * the prefix is 10 bytes, with 4 byte
				 * signal names (common) we have room in
				 * the 70 bytes left on a normal line for
				 * 70/(4+1) signals, that's 14, but to
				 * allow for the occasional longer sig name
				 * we output one less...
				 */
				if (++count >= 13) {
					out1str("\n");
					count = 0;
				}
			}
		if (count)
			out1str("\n");

		for (signo = 0 ; signo < NSIG ; signo++)
			if (trap[signo] != NULL && trap[signo][0] != '\0') {
				out1str("trap -- ");
				print_quoted(trap[signo]);
				out1fmt(" %s\n", trap_signame(signo));
			}

		return 0;
	}

	action = NULL;

	if (!printonly && !is_number(*ap)) {
		if ((*ap)[0] == '-' && (*ap)[1] == '\0')
			ap++;			/* reset to default */
		else
			action = *ap++;		/* can be '' for "ignore" */
		argc--;
	}

	if (argc < 2) {		/* there must be at least 1 condition */
		out2str("Usage: trap [-l]\n"
			"       trap -p [condition ...]\n"
			"       trap action condition ...\n"
			"       trap N condition ...\n");
		return 2;
	}


	while (*ap) {
		signo = signame_to_signum(*ap);

		if (signo < 0 || signo >= NSIG) {
			/* This is not a fatal error, so sayeth posix */
			outfmt(out2, "trap: '%s' bad condition\n", *ap);
			errs = 1;
			ap++;
			continue;
		}
		ap++;

		if (printonly) {
			out1str("trap -- ");
			if (trap[signo] == NULL)
				out1str("-");
			else
				print_quoted(trap[signo]);
			out1fmt(" %s\n", trap_signame(signo));
			continue;
		}

		INTOFF;
		if (action)
			action = savestr(action);

		if (trap[signo])
			ckfree(trap[signo]);

		trap[signo] = action;

		if (signo != 0)
			setsignal(signo, 0);
		INTON;
	}
	return errs;
}
Beispiel #13
0
int
trapcmd(shinstance *psh, int argc, char **argv)
{
	char *action;
	char **ap;
	int signo;
#ifndef HAVE_SYS_SIGNAME
	init_sys_signame();
#endif

	if (argc <= 1) {
		for (signo = 0 ; signo <= NSIG ; signo++)
			if (psh->trap[signo] != NULL) {
				out1fmt(psh, "trap -- ");
				print_quoted(psh, psh->trap[signo]);
				out1fmt(psh, " %s\n",
				    (signo) ? sys_signame[signo] : "EXIT");
			}
		return 0;
	}
	ap = argv + 1;

	action = NULL;

	if (strcmp(*ap, "--") == 0)
		if (*++ap == NULL)
			return 0;

	if (signame_to_signum(psh, *ap) == -1) {
		if ((*ap)[0] == '-') {
			if ((*ap)[1] == '\0')
				ap++;
			else if ((*ap)[1] == 'l' && (*ap)[2] == '\0') {
				printsignals(psh);
				return 0;
			}
			else
				error(psh, "bad option %s\n", *ap);
		}
		else
			action = *ap++;
	}

	while (*ap) {
		if (is_number(*ap))
			signo = number(psh, *ap);
		else
			signo = signame_to_signum(psh, *ap);

		if (signo < 0 || signo > NSIG)
			error(psh, "%s: bad trap", *ap);

		INTOFF;
		if (action)
			action = savestr(psh, action);

		if (psh->trap[signo])
			ckfree(psh, psh->trap[signo]);

		psh->trap[signo] = action;

		if (signo != 0)
			setsignal(psh, signo, 0);
		INTON;
		ap++;
	}
	return 0;
}