本文整理汇总了C++中parse_pattern函数的典型用法代码示例。如果您正苦于以下问题:C++ parse_pattern函数的具体用法?C++ parse_pattern怎么用?C++ parse_pattern使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse_pattern函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: add
static const response* add(const char* l)
{
struct rule* r;
if (*l != 'k' && *l != 'd' && *l != 'z' && *l != 'p' && *l != 'n') return 0;
r = alloc_rule();
r->code = *l++;
if ((l = parse_pattern(l, ':', &r->sender)) != 0 && *l == ':')
if ((l = parse_pattern(l+1, ':', &r->recipient)) != 0 && *l == ':')
if ((l = parse_str(l+1, ':', &r->response)) != 0 && *l == ':')
if ((l = parse_uint(l+1, ':', &r->databytes)) != 0)
if (*l == ':'
&& (l = parse_str(l+1, ':', &r->relayclient)) != 0
&& *l == ':')
parse_env(l+1, &r->environment);
if (l == 0) return &resp_syntax;
append_rule(r);
/* Pre-load text files and pre-open CDB files */
if (!try_load(&r->sender)) return &resp_erropenref;
if (!try_load(&r->recipient)) return &resp_erropenref;
return 0;
}
开发者ID:cweimann,项目名称:mailfront,代码行数:25,代码来源:plugin-mailrules.c
示例2: print_playing_song_default
static void
print_playing_song_default (DBusGProxy *shell_proxy, DBusGProxy *player_proxy)
{
gboolean errored;
GHashTable *properties;
char *string;
GError *error = NULL;
properties = get_playing_song_info (shell_proxy, player_proxy, &error);
if (annoy (&error)) {
return;
}
if (properties == NULL) {
g_print ("%s\n", _("Not playing"));
return;
}
if (g_hash_table_lookup (properties, "rb:stream-song-title") != NULL) {
string = parse_pattern ("%st (%tt)", properties, 0);
} else {
string = parse_pattern ("%ta - %tt", properties, 0);
}
g_print ("%s\n", string);
g_hash_table_destroy (properties);
g_free (string);
}
开发者ID:ivankelly,项目名称:Rhythmbox-Spotify-Plugin,代码行数:27,代码来源:rb-client.c
示例3: print_playing_song
static void
print_playing_song (GDBusProxy *mpris, const char *format)
{
GHashTable *properties;
GVariant *v;
gint64 elapsed = 0;
char *string;
properties = get_playing_song_info (mpris);
if (properties == NULL) {
g_print ("%s\n", _("Not playing"));
return;
}
v = g_dbus_proxy_get_cached_property (mpris, "Position");
if (v != NULL) {
elapsed = g_variant_get_int64 (v);
g_variant_unref (v);
}
string = parse_pattern (format, properties, elapsed);
g_print ("%s\n", string);
g_hash_table_destroy (properties);
g_free (string);
}
开发者ID:dardevelin,项目名称:rhythmbox-shuffle,代码行数:25,代码来源:rb-client.c
示例4: print_playing_song
static void
print_playing_song (DBusGProxy *shell_proxy, DBusGProxy *player_proxy, const char *format)
{
gboolean errored;
GHashTable *properties;
guint elapsed = 0;
GError *error = NULL;
char *string;
properties = get_playing_song_info (shell_proxy, player_proxy, &error);
if (annoy (&error)) {
return;
}
if (properties == NULL) {
g_print ("%s\n", _("Not playing"));
return;
}
org_gnome_Rhythmbox_Player_get_elapsed (player_proxy, &elapsed, &error);
annoy (&error);
string = parse_pattern (format, properties, elapsed);
g_print ("%s\n", string);
g_hash_table_destroy (properties);
g_free (string);
}
开发者ID:ivankelly,项目名称:Rhythmbox-Spotify-Plugin,代码行数:26,代码来源:rb-client.c
示例5: aio_write_f
static int aio_write_f(int argc, char **argv)
{
int nr_iov, c;
int pattern = 0xcd;
struct aio_ctx *ctx = g_new0(struct aio_ctx, 1);
while ((c = getopt(argc, argv, "CqP:")) != EOF) {
switch (c) {
case 'C':
ctx->Cflag = 1;
break;
case 'q':
ctx->qflag = 1;
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0) {
g_free(ctx);
return 0;
}
break;
default:
g_free(ctx);
return command_usage(&aio_write_cmd);
}
}
if (optind > argc - 2) {
g_free(ctx);
return command_usage(&aio_write_cmd);
}
ctx->offset = cvtnum(argv[optind]);
if (ctx->offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
g_free(ctx);
return 0;
}
optind++;
if (ctx->offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
ctx->offset);
g_free(ctx);
return 0;
}
nr_iov = argc - optind;
ctx->buf = create_iovec(&ctx->qiov, &argv[optind], nr_iov, pattern);
if (ctx->buf == NULL) {
g_free(ctx);
return 0;
}
gettimeofday(&ctx->t1, NULL);
bdrv_aio_writev(bs, ctx->offset >> 9, &ctx->qiov,
ctx->qiov.size >> 9, aio_write_done, ctx);
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:59,代码来源:qemu-io.c
示例6: main
int main(int argc, char *argv[]){
if (argc < 2){
printf("No pattern\n");
return -1;
}
struct RL* rl = rl_open(0,MAX_LEN);
int i;
char** patterns = malloc((argc-1)*sizeof(char*));
char** repls = malloc((argc-1)*sizeof(char*));
int* greeds = malloc((argc-1)*sizeof(int));
char* str;
for (i = 1; i < argc; i++){
//get pattern
strtok(argv[i], "/");
char* pattern_tmp = strtok(NULL, "/");//skip s/
patterns[i-1] = malloc(strlen(pattern_tmp)+1);
strcpy(patterns[i-1], pattern_tmp);
pattern_tmp = strtok(NULL, "/");
repls[i-1] = malloc(strlen(pattern_tmp)+1);
strcpy(repls[i-1], pattern_tmp);
greeds[i-1] = (strtok(NULL, "/") != NULL);
//printf("%s\n%s\n%d\n", patterns[i-1], repls[i-1], greeds[i-1]);
}
//test
int res = rl_readline(rl, rl->buf, rl->buf_size);
while (res!=0){
if (res > 0){
//do shit and write
//printf("%s",rl->buf);
str = malloc((res+1)*sizeof(char));
strcpy(str,rl->buf);
//printf("%s+%s\n", str,repls[i]);
for (i = 0; i < argc-1; i++){
//if (parse_pattern(str,patterns[i],repls[i],greeds[i]) == NULL){
// printf("NO FUCK YOU");
//}
str = parse_pattern(str,patterns[i],repls[i],greeds[i]);
}
write(1,str,strlen(str));
write(1,"\n",1);
free(str);
} else {
break;
}
res = rl_readline(rl, rl->buf,rl->buf_size);
}
for (i = 0; i < argc -1; i++){
free(patterns[i]);
free(repls[i]);
}
free(patterns);
free(repls);
free(greeds);
return 0;
}
开发者ID:NinerLP,项目名称:OS-2012,代码行数:56,代码来源:unsed.c
示例7: parse_nf
int
parse_nf (char *string, List *list)
{
newts_nfref *ref = nfref_alloc ();
char *copy;
if (string == NULL || list == NULL)
return -1;
copy = newts_strdup (string);
if (!pattern_flag)
sense = PARSE_ADD;
if (*copy == ':')
{
return parse_file (copy + 1, list);
}
if (*copy == '!')
{
char *change = newts_strdup (copy + 1);
newts_free (copy);
copy = change;
sense = PARSE_DELETE;
}
if (!pattern_flag &&
(strchr (copy, '?') || strchr (copy, '[') || strchr (copy, '*') ||
strchr (copy, ' ')))
{
/* Pattern matching. */
int result;
pattern_flag = TRUE;
result = parse_pattern (copy, list);
pattern_flag = FALSE;
return result;
}
parse_single_nf (copy, ref);
if (sense == PARSE_ADD)
list_insert_next (list, list_tail (list), (void *) ref);
else
{
list_remove_match (list, (void *) ref);
nfref_free (ref);
}
newts_free (copy);
return 0;
}
开发者ID:tylerberry,项目名称:newts,代码行数:55,代码来源:parse.c
示例8: while
static inline struct simple_pattern *parse_pattern(char *str, SIMPLE_PREFIX_MODE default_mode) {
// fprintf(stderr, "PARSING PATTERN: '%s'\n", str);
SIMPLE_PREFIX_MODE mode;
struct simple_pattern *child = NULL;
char *s = str, *c = str;
// skip asterisks in front
while(*c == '*') c++;
// find the next asterisk
while(*c && *c != '*') c++;
// do we have an asterisk in the middle?
if(*c == '*' && c[1] != '\0') {
// yes, we have
child = parse_pattern(c, default_mode);
c[1] = '\0';
}
// check what this one matches
size_t len = strlen(s);
if(len >= 2 && *s == '*' && s[len - 1] == '*') {
s[len - 1] = '\0';
s++;
mode = SIMPLE_PATTERN_SUBSTRING;
}
else if(len >= 1 && *s == '*') {
s++;
mode = SIMPLE_PATTERN_SUFFIX;
}
else if(len >= 1 && s[len - 1] == '*') {
s[len - 1] = '\0';
mode = SIMPLE_PATTERN_PREFIX;
}
else
mode = default_mode;
// allocate the structure
struct simple_pattern *m = callocz(1, sizeof(struct simple_pattern));
if(*s) {
m->match = strdupz(s);
m->len = strlen(m->match);
m->mode = mode;
}
else {
m->mode = SIMPLE_PATTERN_SUBSTRING;
}
m->child = child;
return m;
}
开发者ID:FedericoCeratto,项目名称:netdata,代码行数:55,代码来源:simple_pattern.c
示例9: print_playing_song_default
static void
print_playing_song_default (GDBusProxy *mpris)
{
GHashTable *properties;
char *string;
properties = get_playing_song_info (mpris);
if (properties == NULL) {
g_print ("%s\n", _("Not playing"));
return;
}
if (g_hash_table_lookup (properties, "rhythmbox:streamTitle") != NULL) {
string = parse_pattern ("%st (%tt)", properties, 0);
} else {
string = parse_pattern ("%ta - %tt", properties, 0);
}
g_print ("%s\n", string);
g_hash_table_destroy (properties);
g_free (string);
}
开发者ID:dardevelin,项目名称:rhythmbox-shuffle,代码行数:22,代码来源:rb-client.c
示例10: TRACE1
bregonig *recompile_onig(bregonig *rxold, pattern_type type,
const TCHAR *ptn, TCHAR *msg)
{
const TCHAR *patternp;
const TCHAR *patternendp;
const TCHAR *prerepp;
const TCHAR *prerependp;
const TCHAR *optionp;
const TCHAR *optionendp;
TRACE1(_T("recompile_onig(): %s\n"), ptn);
type = parse_pattern(ptn, type, &patternp, &patternendp,
&prerepp, &prerependp, &optionp, &optionendp, msg);
if (type == PTN_ERROR) {
return NULL;
}
return recompile_onig_ex(rxold, type, ptn, patternp, patternendp,
prerepp, prerependp, optionp, optionendp, msg);
}
开发者ID:k-takata,项目名称:bregonig,代码行数:19,代码来源:bregonig.cpp
示例11: read_f
static int read_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, pflag = 0, qflag = 0, vflag = 0;
int Pflag = 0, sflag = 0, lflag = 0, bflag = 0;
int c, cnt;
char *buf;
int64_t offset;
int count;
/* Some compilers get confused and warn if this is not initialized. */
int total = 0;
int pattern = 0, pattern_offset = 0, pattern_count = 0;
while ((c = getopt(argc, argv, "bCl:pP:qs:v")) != EOF) {
switch (c) {
case 'b':
bflag = 1;
break;
case 'C':
Cflag = 1;
break;
case 'l':
lflag = 1;
pattern_count = cvtnum(optarg);
if (pattern_count < 0) {
printf("non-numeric length argument -- %s\n", optarg);
return 0;
}
break;
case 'p':
pflag = 1;
break;
case 'P':
Pflag = 1;
pattern = parse_pattern(optarg);
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
break;
case 's':
sflag = 1;
pattern_offset = cvtnum(optarg);
if (pattern_offset < 0) {
printf("non-numeric length argument -- %s\n", optarg);
return 0;
}
break;
case 'v':
vflag = 1;
break;
default:
return command_usage(&read_cmd);
}
}
if (optind != argc - 2) {
return command_usage(&read_cmd);
}
if (bflag && pflag) {
printf("-b and -p cannot be specified at the same time\n");
return 0;
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
count = cvtnum(argv[optind]);
if (count < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
if (!Pflag && (lflag || sflag)) {
return command_usage(&read_cmd);
}
if (!lflag) {
pattern_count = count - pattern_offset;
}
if ((pattern_count < 0) || (pattern_count + pattern_offset > count)) {
printf("pattern verification range exceeds end of read data\n");
return 0;
}
if (!pflag) {
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
if (count & 0x1ff) {
//.........这里部分代码省略.........
开发者ID:AjayMashi,项目名称:x-tier,代码行数:101,代码来源:qemu-io.c
示例12: aio_read_f
static int
aio_read_f(int argc, char **argv)
{
int nr_iov, c;
struct aio_ctx *ctx = calloc(1, sizeof(struct aio_ctx));
BlockDriverAIOCB *acb;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
ctx->Cflag = 1;
break;
case 'P':
ctx->Pflag = 1;
ctx->pattern = parse_pattern(optarg);
if (ctx->pattern < 0)
return 0;
break;
case 'q':
ctx->qflag = 1;
break;
case 'v':
ctx->vflag = 1;
break;
default:
free(ctx);
return command_usage(&aio_read_cmd);
}
}
if (optind > argc - 2) {
free(ctx);
return command_usage(&aio_read_cmd);
}
ctx->offset = cvtnum(argv[optind]);
if (ctx->offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
free(ctx);
return 0;
}
optind++;
if (ctx->offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
ctx->offset);
free(ctx);
return 0;
}
nr_iov = argc - optind;
ctx->buf = create_iovec(&ctx->qiov, &argv[optind], nr_iov, 0xab);
gettimeofday(&ctx->t1, NULL);
acb = bdrv_aio_readv(bs, ctx->offset >> 9, &ctx->qiov,
ctx->qiov.size >> 9, aio_read_done, ctx);
if (!acb) {
free(ctx->buf);
free(ctx);
return -EIO;
}
return 0;
}
开发者ID:ChengyuSong,项目名称:ATrace,代码行数:64,代码来源:qemu-io.c
示例13: parse_cmatcher
mod_export Cmatcher
parse_cmatcher(char *name, char *s)
{
Cmatcher ret = NULL, r = NULL, n;
Cpattern line, word, left, right;
int fl, fl2, ll, wl, lal, ral, err, both;
if (!*s)
return NULL;
while (*s) {
lal = ral = both = fl2 = 0;
left = right = NULL;
while (*s && inblank(*s)) s++;
if (!*s) break;
switch (*s) {
case 'b': fl2 = CMF_INTER;
case 'l': fl = CMF_LEFT; break;
case 'e': fl2 = CMF_INTER;
case 'r': fl = CMF_RIGHT; break;
case 'm': fl = 0; break;
case 'B': fl2 = CMF_INTER;
case 'L': fl = CMF_LEFT | CMF_LINE; break;
case 'E': fl2 = CMF_INTER;
case 'R': fl = CMF_RIGHT | CMF_LINE; break;
case 'M': fl = CMF_LINE; break;
default:
if (name)
zwarnnam(name, "unknown match specification character `%c'",
*s);
return pcm_err;
}
if (s[1] != ':') {
if (name)
zwarnnam(name, "missing `:'");
return pcm_err;
}
s += 2;
if (!*s) {
if (name)
zwarnnam(name, "missing patterns");
return pcm_err;
}
if ((fl & CMF_LEFT) && !fl2) {
left = parse_pattern(name, &s, &lal, '|', &err);
if (err)
return pcm_err;
if ((both = (*s && s[1] == '|')))
s++;
if (!*s || !*++s) {
if (name)
zwarnnam(name, "missing line pattern");
return pcm_err;
}
} else
left = NULL;
line = parse_pattern(name, &s, &ll,
(((fl & CMF_RIGHT) && !fl2) ? '|' : '='),
&err);
if (err)
return pcm_err;
if (both) {
right = line;
ral = ll;
line = NULL;
ll = 0;
}
if ((fl & CMF_RIGHT) && !fl2 && (!*s || !*++s)) {
if (name)
zwarnnam(name, "missing right anchor");
} else if (!(fl & CMF_RIGHT) || fl2) {
if (!*s) {
if (name)
zwarnnam(name, "missing word pattern");
return pcm_err;
}
s++;
}
if ((fl & CMF_RIGHT) && !fl2) {
if (*s == '|') {
left = line;
lal = ll;
line = NULL;
ll = 0;
s++;
}
right = parse_pattern(name, &s, &ral, '=', &err);
if (err)
return pcm_err;
if (!*s) {
if (name)
zwarnnam(name, "missing word pattern");
return pcm_err;
}
//.........这里部分代码省略.........
开发者ID:Jaharmi,项目名称:zsh,代码行数:101,代码来源:complete.c
示例14: writev_f
static int writev_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
int c, cnt;
char *buf;
int64_t offset;
/* Some compilers get confused and warn if this is not initialized. */
int total = 0;
int nr_iov;
int pattern = 0xcd;
QEMUIOVector qiov;
while ((c = getopt(argc, argv, "CqP:")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'q':
qflag = 1;
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0) {
return 0;
}
break;
default:
return command_usage(&writev_cmd);
}
}
if (optind > argc - 2) {
return command_usage(&writev_cmd);
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(&qiov, &argv[optind], nr_iov, pattern);
if (buf == NULL) {
return 0;
}
gettimeofday(&t1, NULL);
cnt = do_aio_writev(&qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("writev failed: %s\n", strerror(-cnt));
goto out;
}
if (qflag) {
goto out;
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
print_report("wrote", &t2, offset, qiov.size, total, cnt, Cflag);
out:
qemu_iovec_destroy(&qiov);
qemu_io_free(buf);
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:76,代码来源:qemu-io.c
示例15: multiwrite_f
static int
multiwrite_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0;
int c, cnt;
char **buf;
int64_t offset, first_offset = 0;
int total = 0;
int nr_iov;
int nr_reqs;
int pattern = 0xcd;
QEMUIOVector *qiovs;
int i;
BlockRequest *reqs;
while ((c = getopt(argc, argv, "CqP:")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'q':
qflag = 1;
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0)
return 0;
break;
default:
return command_usage(&writev_cmd);
}
}
if (optind > argc - 2)
return command_usage(&writev_cmd);
nr_reqs = 1;
for (i = optind; i < argc; i++) {
if (!strcmp(argv[i], ";")) {
nr_reqs++;
}
}
reqs = qemu_malloc(nr_reqs * sizeof(*reqs));
buf = qemu_malloc(nr_reqs * sizeof(*buf));
qiovs = qemu_malloc(nr_reqs * sizeof(*qiovs));
for (i = 0; i < nr_reqs; i++) {
int j;
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric offset argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %lld is not sector aligned\n",
(long long)offset);
return 0;
}
if (i == 0) {
first_offset = offset;
}
for (j = optind; j < argc; j++) {
if (!strcmp(argv[j], ";")) {
break;
}
}
nr_iov = j - optind;
reqs[i].qiov = &qiovs[i];
buf[i] = create_iovec(reqs[i].qiov, &argv[optind], nr_iov, pattern);
reqs[i].sector = offset >> 9;
reqs[i].nb_sectors = reqs[i].qiov->size >> 9;
optind = j + 1;
offset += reqs[i].qiov->size;
pattern++;
}
gettimeofday(&t1, NULL);
cnt = do_aio_multiwrite(reqs, nr_reqs, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("aio_multiwrite failed: %s\n", strerror(-cnt));
goto out;
}
//.........这里部分代码省略.........
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:101,代码来源:qemu-io.c
示例16: write_f
static int
write_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, pflag = 0, qflag = 0, bflag = 0;
int c, cnt;
char *buf;
int64_t offset;
int count;
int total = 0;
int pattern = 0xcd;
while ((c = getopt(argc, argv, "bCpP:q")) != EOF) {
switch (c) {
case 'b':
bflag = 1;
break;
case 'C':
Cflag = 1;
break;
case 'p':
pflag = 1;
break;
case 'P':
pattern = parse_pattern(optarg);
if (pattern < 0)
return 0;
break;
case 'q':
qflag = 1;
break;
default:
return command_usage(&write_cmd);
}
}
if (optind != argc - 2)
return command_usage(&write_cmd);
if (bflag && pflag) {
printf("-b and -p cannot be specified at the same time\n");
return 0;
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
count = cvtnum(argv[optind]);
if (count < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
if (!pflag) {
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
if (count & 0x1ff) {
printf("count %d is not sector aligned\n",
count);
return 0;
}
}
buf = qemu_io_alloc(count, pattern);
gettimeofday(&t1, NULL);
if (pflag)
cnt = do_pwrite(buf, offset, count, &total);
else if (bflag)
cnt = do_save_vmstate(buf, offset, count, &total);
else
cnt = do_write(buf, offset, count, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("write failed: %s\n", strerror(-cnt));
goto out;
}
if (qflag)
goto out;
t2 = tsub(t2, t1);
print_report("wrote", &t2, offset, count, total, cnt, Cflag);
out:
qemu_io_free(buf);
return 0;
}
开发者ID:qtekfun,项目名称:htcDesire820Kernel,代码行数:100,代码来源:qemu-io.c
示例17: memset
SIMPLE_PATTERN *simple_pattern_create(const char *list, const char *separators, SIMPLE_PREFIX_MODE default_mode) {
struct simple_pattern *root = NULL, *last = NULL;
if(unlikely(!list || !*list)) return root;
int isseparator[256] = {
[' '] = 1 // space
, ['\t'] = 1 // tab
, ['\r'] = 1 // carriage return
, ['\n'] = 1 // new line
, ['\f'] = 1 // form feed
, ['\v'] = 1 // vertical tab
};
if (unlikely(separators && *separators)) {
memset(&isseparator[0], 0, sizeof(isseparator));
while(*separators) isseparator[(unsigned char)*separators++] = 1;
}
char *buf = mallocz(strlen(list) + 1);
const char *s = list;
while(s && *s) {
buf[0] = '\0';
char *c = buf;
char negative = 0;
// skip all spaces
while(isseparator[(unsigned char)*s])
s++;
if(*s == '!') {
negative = 1;
s++;
}
// empty string
if(unlikely(!*s))
break;
// find the next space
char escape = 0;
while(*s) {
if(*s == '\\' && !escape) {
escape = 1;
s++;
}
else {
if (isseparator[(unsigned char)*s] && !escape) {
s++;
break;
}
*c++ = *s++;
escape = 0;
}
}
// terminate our string
*c = '\0';
// if we matched the empty string, skip it
if(unlikely(!*buf))
continue;
// fprintf(stderr, "FOUND PATTERN: '%s'\n", buf);
struct simple_pattern *m = parse_pattern(buf, default_mode);
m->negative = negative;
// link it at the end
if(unlikely(!root))
root = last = m;
else {
last->next = m;
last = m;
}
}
freez(buf);
return (SIMPLE_PATTERN *)root;
}
开发者ID:FedericoCeratto,项目名称:netdata,代码行数:82,代码来源:simple_pattern.c
示例18: readv_f
static int readv_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, qflag = 0, vflag = 0;
int c, cnt;
char *buf;
int64_t offset;
/* Some compilers get confused and warn if this is not initialized. */
int total = 0;
int nr_iov;
QEMUIOVector qiov;
int pattern = 0;
int Pflag = 0;
while ((c = getopt(argc, argv, "CP:qv")) != EOF) {
switch (c) {
case 'C':
Cflag = 1;
break;
case 'P':
Pflag = 1;
pattern = parse_pattern(optarg);
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
break;
case 'v':
vflag = 1;
break;
default:
return command_usage(&readv_cmd);
}
}
if (optind > argc - 2) {
return command_usage(&readv_cmd);
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
nr_iov = argc - optind;
buf = create_iovec(&qiov, &argv[optind], nr_iov, 0xab);
if (buf == NULL) {
return 0;
}
gettimeofday(&t1, NULL);
cnt = do_aio_readv(&qiov, offset, &total);
gettimeofday(&t2, NULL);
if (cnt < 0) {
printf("readv failed: %s\n", strerror(-cnt));
goto out;
}
if (Pflag) {
void *cmp_buf = g_malloc(qiov.size);
memset(cmp_buf, pattern, qiov.size);
if (memcmp(buf, cmp_buf, qiov.size)) {
printf("Pattern verification failed at offset %"
PRId64 ", %zd bytes\n", offset, qiov.size);
}
g_free(cmp_buf);
}
if (qflag) {
goto out;
}
if (vflag) {
dump_buffer(buf, offset, qiov.size);
}
/* Finally, report back -- -C gives a parsable format */
t2 = tsub(t2, t1);
print_report("read", &t2, offset, qiov.size, total, cnt, Cflag);
out:
qemu_iovec_destroy(&qiov);
qemu_io_free(buf);
return 0;
}
开发者ID:AjayMashi,项目名称:x-tier,代码行数:97,代码来源:qemu-io.c
示例19: main
int main(int argc, char *argv[])
{
int leadin = 0, leadout = 0;
const char *avifile = NULL;
pattern_data *pattern = NULL;
int patcount = 0;
int arg;
int i;
/* iterate over arguments */
for (arg = 1; arg < argc; arg++)
{
/* assume anything without a - is a filename */
if (argv[arg][0] != '-')
{
if (avifile != NULL || pattern != NULL)
return usage();
avifile = argv[arg];
}
/* look for options */
else if (strcmp(argv[arg], "-leadin") == 0)
{
if (++arg >= argc)
return usage();
leadin = atoi(argv[arg]);
}
else if (strcmp(argv[arg], "-leadout") == 0)
{
if (++arg >= argc)
return usage();
leadout = atoi(argv[arg]);
}
else if (strcmp(argv[arg], "-pattern") == 0)
{
if (avifile != NULL || pattern != NULL)
return usage();
if (++arg >= argc)
return usage();
pattern = parse_pattern(argv[arg], &patcount);
if (pattern == NULL)
return usage();
}
}
/* must have an AVI file or a pattern */
if (avifile == NULL && pattern == NULL)
return usage();
/* output header and leadin */
printf("chdmeta 12\n");
for (i = 0; i < leadin; i++)
{
int flags = (i == 0) ? 0x02 : (i == leadin - 1) ? 0x01 : 0x03;
printf("02%02X%02X00000088FFFF88FFFF\n", flags, (i % 2));
}
/* if we got a file, output it */
if (avifile != NULL)
generate_from_avi(avifile);
else if (pattern != NULL)
generate_from_pattern(pattern, patcount);
/* output leadout */
for (i = 0; i < leadout; i++)
{
int flags = (i == 0) ? 0x02 : (i == leadout - 1) ? 0x01 : 0x03;
printf("02%02X%02X00000080EEEE80EEEE\n", flags, (i % 2));
}
return 0;
}
开发者ID:broftkd,项目名称:historic-mame,代码行数:72,代码来源:makemeta.c
示例20: write_f
static int write_f(int argc, char **argv)
{
struct timeval t1, t2;
int Cflag = 0, pflag = 0, qflag = 0, bflag = 0, Pflag = 0, zflag = 0;
int cflag = 0;
int c, cnt;
char *buf = NULL;
int64_t offset;
int count;
/* Some compilers get confused and warn if this is not initialized. */
int total = 0;
int pattern = 0xcd;
while ((c = getopt(argc, argv, "bcCpP:qz")) != EOF) {
switch (c) {
case 'b':
bflag = 1;
break;
case 'c':
cflag = 1;
break;
case 'C':
Cflag = 1;
break;
case 'p':
pflag = 1;
break;
case 'P':
Pflag = 1;
pattern = parse_pattern(optarg);
if (pattern < 0) {
return 0;
}
break;
case 'q':
qflag = 1;
break;
case 'z':
zflag = 1;
break;
default:
return command_usage(&write_cmd);
}
}
if (optind != argc - 2) {
return command_usage(&write_cmd);
}
if (bflag + pflag + zflag > 1) {
printf("-b, -p, or -z cannot be specified at the same time\n");
return 0;
}
if (zflag && Pflag) {
printf("-z and -P cannot be specified at the same time\n");
return 0;
}
offset = cvtnum(argv[optind]);
if (offset < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
optind++;
count = cvtnum(argv[optind]);
if (count < 0) {
printf("non-numeric length argument -- %s\n", argv[optind]);
return 0;
}
if (!pflag) {
if (offset & 0x1ff) {
printf("offset %" PRId64 " is not sector aligned\n",
offset);
return 0;
}
if (count & 0x1ff) {
printf("count %d is not sector aligned\n",
count);
return 0;
}
}
if (!zflag) {
buf = qemu_io_alloc(count, pattern);
}
gettimeofday(&t1, NULL);
if (pflag) {
cnt = do_pwrite(buf, offset, count, &total);
} else if (bflag) {
cnt = do_save_vmstate(buf, offset, count, &total);
} else if (zflag) {
cnt = do_co_write_zeroes(offset, count, &total);
} else if (cflag) {
cnt = do_write_compressed(buf, offset, count, &total);
} else {
//.........这里部分代码省略.........
开发者ID:AjayMashi,项目名称:x-tier,代码行数:101,代码来源:qemu-io.c
注:本文中的parse_pattern函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论