示例#1
0
int main(int argc, char **argv)
{
	if (argc == 5 && !strcmp(argv[1], "split")) {
		struct string_list list = STRING_LIST_INIT_DUP;
		int i;
		const char *s = argv[2];
		int delim = *argv[3];
		int maxsplit = atoi(argv[4]);

		i = string_list_split(&list, s, delim, maxsplit);
		printf("%d\n", i);
		write_list(&list);
		string_list_clear(&list, 0);
		return 0;
	}

	if (argc == 5 && !strcmp(argv[1], "split_in_place")) {
		struct string_list list = STRING_LIST_INIT_NODUP;
		int i;
		char *s = xstrdup(argv[2]);
		int delim = *argv[3];
		int maxsplit = atoi(argv[4]);

		i = string_list_split_in_place(&list, s, delim, maxsplit);
		printf("%d\n", i);
		write_list(&list);
		string_list_clear(&list, 0);
		free(s);
		return 0;
	}

	if (argc == 4 && !strcmp(argv[1], "filter")) {
		/*
		 * Retain only the items that have the specified prefix.
		 * Arguments: list|- prefix
		 */
		struct string_list list = STRING_LIST_INIT_DUP;
		const char *prefix = argv[3];

		parse_string_list(&list, argv[2]);
		filter_string_list(&list, 0, prefix_cb, (void *)prefix);
		write_list_compact(&list);
		string_list_clear(&list, 0);
		return 0;
	}

	if (argc == 3 && !strcmp(argv[1], "remove_duplicates")) {
		struct string_list list = STRING_LIST_INIT_DUP;

		parse_string_list(&list, argv[2]);
		string_list_remove_duplicates(&list, 0);
		write_list_compact(&list);
		string_list_clear(&list, 0);
		return 0;
	}

	fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
		argv[1] ? argv[1] : "(there was none)");
	return 1;
}
示例#2
0
文件: collect2.c 项目: npe9/sprite
write_hooks (FILE *inf, FILE *outf)
{
  char *p, buf[1024];
  struct id *newid;

  struct id *constructors = 0;
  struct id *destructors = 0;

  while (! feof (inf)) {

    /* Read a line of nm output and strip the trailing newline. */

    fgets (buf, sizeof buf, inf);
    p = buf + strlen (buf) - 1;
    if (*p == '\n')
      *p = '\0';

    /* If it contains a constructor or destructor name, add the name
       to the appropriate list. */

    for (p = buf; *p; p++)
      {
	while (*p && *p != '_')
	  p++;
	if (! strncmp (p, "_GLOBAL_$I$", 11))
	  {
	    newid = alloca (sizeof *newid);
	    newid->name = alloca (strlen (p) + 1);
	    strcpy (newid->name, p);
	    newid->next = constructors;
	    constructors = newid;
	    break;
	  }
	else if (! strncmp (p, "_GLOBAL_$D$", 11))
	  {
	    newid = alloca (sizeof *newid);
	    newid->name = alloca (strlen (p) + 1);
	    strcpy (newid->name, p);
	    newid->next = destructors;
	    destructors = newid;
	    break;
	  }
      }
  }

  /* Write the tables. */

  fprintf (outf, "%s\n", TEXT_SECTION_ASM_OP);
  ASM_GLOBALIZE_LABEL (outf, "__CTOR_LIST__");
  ASM_OUTPUT_LABEL (outf, "__CTOR_LIST__");
  ASM_OUTPUT_INT (outf, count_list (constructors));
  write_list (outf, constructors);
  
  fprintf (outf, "%s\n", DATA_SECTION_ASM_OP);
  ASM_GLOBALIZE_LABEL (outf, "__DTOR_LIST__");
  ASM_OUTPUT_LABEL (outf, "__DTOR_LIST__");
  ASM_OUTPUT_INT (outf, count_list (destructors));
  write_list (outf, destructors);
  ASM_OUTPUT_INT (outf, 0);
}
示例#3
0
/* Save the histories for Search and Replace and Execute Command. */
void save_history(void)
{
	char *histname;
	FILE *hisfile;

	/* If the histories are unchanged, don't bother saving them. */
	if (!history_changed)
		return;

	histname = concatenate(statedir, SEARCH_HISTORY);
	hisfile = fopen(histname, "wb");

	if (hisfile == NULL)
		fprintf(stderr, _("Error writing %s: %s\n"), histname,
						strerror(errno));
	else {
		/* Don't allow others to read or write the history file. */
		chmod(histname, S_IRUSR | S_IWUSR);

		if (!write_list(searchtop, hisfile) ||
						!write_list(replacetop, hisfile) ||
						!write_list(executetop, hisfile))
			fprintf(stderr, _("Error writing %s: %s\n"), histname,
						strerror(errno));

		fclose(hisfile);
	}

	free(histname);
}
示例#4
0
void explain_keypad_mode( FILE *fp )
{
  write_list( fp, gettext( "If keypad_mode is set to \"NUMBERS_AS_ARROWS\", then the numbers on\nyour keypad when the numlock is on will act as arrow keys:\n            8 = Up Arrow\n  4 = Left Arrow    6 = Right Arrow\n            2 = Down Arrow\nand the corresponding keyboard numbers will act as arrow keys,\nregardless of whether numlock is on.\n" ) );
  write_list( fp, gettext( "If keypad_mode is set to \"LINKS_ARE_NUMBERED\", then numbers will\nappear next to each link and numbers are used to select links.\n" ) );
  write_list( fp, gettext( "If keypad_mode is set to \"LINKS_AND_FORM_FIELDS_ARE_NUMBERED\", then\nnumbers will appear next to each link and visible form input field.\nNumbers are used to select links, or to move the \"current link\" to a\nform input field or button.  In addition, options in popup menus are\nindexed so that the user may type an option number to select an option in\na popup menu, even if the option isn't visible on the screen.  Reference\nlists and output from the list command also enumerate form inputs.\n" ) );
  write_list( fp, gettext( "NOTE: Some fixed format documents may look disfigured when\n\"LINKS_ARE_NUMBERED\" or \"LINKS_AND_FORM_FIELDS_ARE_NUMBERED\" are\nenabled.\n" ) );
  return;
}
示例#5
0
文件: dump.hpp 项目: actuariat/stan
 void write_structure(std::vector<T> xs,
                      std::vector<size_t> dims) {
   out_ << "structure(";
   write_list(xs);
   out_ << ',' << '\n';
   out_ << ".Dim = ";
   write_list(dims);
   out_ << ")";
 }
示例#6
0
文件: collect2.c 项目: npe9/sprite
write_list (FILE *outf, struct id *list)
{
  if (! list)
    return;
  write_list (outf, list->next);
  ASM_OUTPUT_LABELREF (outf, list->name);
}
示例#7
0
文件: write.c 项目: gphalkes/t3config
/** Write a single value out to file. */
static void write_value(t3_config_t *config, FILE *file, int indent) {
  switch (config->type) {
    case T3_CONFIG_BOOL:
      fputs(config->value.boolean ? "true" : "false", file);
      break;
    case T3_CONFIG_INT:
      write_int(file, config->value.integer);
      break;
    case T3_CONFIG_NUMBER:
      write_number(file, config->value.number);
      break;
    case T3_CONFIG_STRING:
      write_string(file, config->value.string);
      break;
    case T3_CONFIG_LIST:
    case T3_CONFIG_PLIST:
      fputs("( ", file);
      write_list(config->value.list, file, indent + 1);
      fputs(" )", file);
      break;
    case T3_CONFIG_SECTION:
      fputs("{\n", file);
      write_section(config->value.list, file, indent + 1);
      write_indent(file, indent);
      fputc('}', file);
      break;
    default:
      /* This can only happen if the client screws up the list. */
      break;
  }
}
int main (void)
{
    struct node *list = NULL, *n;

    list = create_person (1, "Dave Neary");

    n = create_person (2, "Thomas Perl");
    add_person (list, n);

    n = create_person (3, "Alison Chaiken");
    add_person (list, n);
    
    n = create_person (4, "Andrea Grandi");
    add_person (list, n);
    
    n = create_person (5, "Kevin Ottens");
    add_person (list, n);
    
    for (n=list; n; ) {
        struct node *next = n->next;
        if (n->p->id % 2 == 0) {
            delete_person(n);
        }
        n = next;
    }
    n = create_person (6, "Bob Spencer");
    add_person (list, n);
    
    write_list (list);

    return EXIT_SUCCESS;
}
示例#9
0
文件: move_ant.c 项目: avw1987/Lem_in
void	move_ant(t_glob *g)
{
	int i;
	int j;

	j = 1;
	i = -1;
	g->tmp1[0] = strdup(g->start->room_name);
	while (i < g->num_links)
	{
		i++;
		if (g->start->links[i]->flag == 1)
		{
			g->tmp1[j] = strdup(g->start->links[i]->room_name);
			if (g->start->links[i] != NULL)
			{
				g->start = g->start->links[i];
				j++;
				i = -1;
			}
			if (ft_strcmp(g->start->room_name, g->end->room_name) == 0)
				i = g->num_links;
		}
	}
	write_list(g);
	march_ants(g);
}
示例#10
0
文件: serial.c 项目: jmhal/parallel
int main(int argc, char *argv[]){
    struct node *head = NULL;
    struct node *shead = NULL;

    /* Abrir cada um dos arquivos e colocar os valores na lista. */
    int i;
    for (i = 0; i < 10; i++) {
        FILE *fp;
          
        char filename[100];
        snprintf(filename, 100, "%s%d%s", "arquivos/arquivo", i, ".bin");
 
        fp = fopen(filename,"r");
        while (!feof(fp)) {
            int number;
            fread(&number, sizeof(number), 1, fp);
            insert_node(&head, number);
        }
        fclose(fp);
    }
    
    shead = Sort_linkedlist(head);
    write_list(shead, "output.bin");
    
    return 0;
}
示例#11
0
bool setup_test(size_t object_size) {
    object_t* object = benchmark_object_create(object_size);
    binn root;
    bool ok;
    if (object->type == type_map) {
        binn_create_object(&root);
        ok = write_object(&root, object);
    } else {
        binn_create_list(&root);
        ok = write_list(&root, object);
    }
    object_destroy(object);

    if (!ok) {
        fprintf(stderr, "binn error writing data!\n");
        binn_free(&root);
        return false;
    }

    char filename[64];
    benchmark_filename(filename, sizeof(filename), object_size, BENCHMARK_FORMAT_BINN, NULL);
    FILE* file = fopen(filename, "wb");
    fwrite(binn_ptr(&root), binn_size(&root), 1, file);
    fclose(file);

    // like libbson, we call binn_free() regardless of whether
    // we placed it on the stack or the heap; it stores a flag
    // to say whether it should be freed. this apparently doesn't
    // cause warnings since GCC chooses not to inline binn_free().
    binn_free(&root);
    return true;
}
示例#12
0
void decl_attributes::write(serializer & s) const {
    s << m_is_abbrev << m_persistent << m_is_instance << m_is_trans_instance << m_is_coercion
      << m_is_reducible << m_is_irreducible << m_is_semireducible << m_is_quasireducible
      << m_is_class << m_is_parsing_only << m_has_multiple_instances << m_unfold_full_hint
      << m_constructor_hint << m_symm << m_trans << m_refl << m_subst << m_recursor
      << m_rewrite << m_recursor_major_pos << m_priority;
    write_list(s, m_unfold_hint);
}
示例#13
0
bytecode JavaInstruction::toBytecode() {
	bytecode b;
	write_u1(b, name);
	for (shared_ptr<JavaReference> jr: args) {
		write_list(b, jr->toByteCode());
	}
	return b;
}
示例#14
0
文件: database.c 项目: buhman/repose
static void compile_files_entry(repo_t *repo, const alpm_pkg_meta_t *pkg, struct buffer *buf)
{
    if (pkg->files) {
        write_list(buf, "FILES", pkg->files);
    } else {
        int pkgfd = openat(repo->dirfd, pkg->filename, O_RDONLY);
        if (pkgfd < 0 && errno != ENOENT) {
            err(EXIT_FAILURE, "failed to open %s", pkg->filename);
        }

        alpm_list_t *files = alpm_pkg_files(pkgfd);
        close(pkgfd);

        write_list(buf, "FILES", files);
        alpm_list_free_inner(files, free);
        alpm_list_free(files);
    }
}
示例#15
0
/**
 * Show stats about a file. If the file is a directory show stats about its content.
 */
bool stat_file(int sock, const char *file_path,char *reply) {
	char line[300];
	struct stat s_buff;
	int status = stat(file_path,&s_buff);
	if(status==0) {
		reply[0]='\0';
		int len = sprintf(reply,REPL_211_STATUS,file_path);
		send_repl_len(sock,reply,len);
		int b_mask = s_buff.st_mode & S_IFMT;
		if(b_mask == S_IFDIR) {
			if(getcwd(line,300)!=NULL) {	
				int status = chdir(file_path);
				if(status != 0) {
					send_repl(sock,REPL_450);
					//free(line);
					return FALSE;
				}
				else {
					if(!write_list(sock, sock, file_path)) {
						send_repl(sock,REPL_450);
						return FALSE;
					}
					int status = chdir(line);
					if(status!=0) {
						send_repl(sock,REPL_450);
						//free(line);
						return FALSE;
					}
				}
			} else {
				send_repl(sock,REPL_450);
				//free(line);
				return FALSE;
					
			}
		} else if(b_mask == S_IFREG){
			if(get_file_info_stat(file_path,line,&s_buff)) {
				if(send_repl_client(sock,line)) {
					send_repl(sock,REPL_450);
					//free(line);
					return FALSE;
				}
			}
		} 
		send_repl(sock,REPL_211_END);
	}
	else {
		send_repl(sock,REPL_450);
		return FALSE;
	}
	free(line);
	return TRUE;
}
示例#16
0
int
main(int argc, char *argv[])
{
    static const char *prefix[] =
    {
	"#ifndef NCU_KEYS_H",
	"#define NCU_KEYS_H 1",
	"",
	"/* This file was generated by MAKE_KEYS */",
	"",
	"#if BROKEN_LINKER",
	"static",
	"#endif",
	"const struct tinfo_fkeys _nc_tinfo_fkeys[] = {",
	0
    };
    static const char *suffix[] =
    {
	"\t{ 0, 0} };",
	"",
	"#endif /* NCU_KEYS_H */",
	0
    };

    write_list(stdout, prefix);
    if (argc > 1) {
	int n;
	for (n = 1; n < argc; n++) {
	    FILE *fp = fopen(argv[n], "r");
	    if (fp != 0) {
		make_keys(fp, stdout);
		fclose(fp);
	    }
	}
    } else {
	make_keys(stdin, stdout);
    }
    write_list(stdout, suffix);
    return EXIT_SUCCESS;
}
示例#17
0
int main(int argc, char **argv)
{
    Node *head = NULL;
    char **filenames = init_filenames();
    char ch;
    char *indexfile = "index";
    char *namefile = "filenames";

    while((ch = getopt(argc, argv, "i:n:")) != -1) {
        switch (ch) {
        case 'i':
            indexfile = optarg;
            break;
        case 'n':
            namefile = optarg;
            break;
        default:
            fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n");
            exit(1);
        }
    }
      
    while(optind < argc) {
		FILE *fname;
		if((fname = fopen(argv[optind], "r")) == NULL) {
			perror("Name file");
			exit(1);
		}

		char line[MAXLINE];
		char splitBy[] = " \t\n";
		char *token;
		char *cleaned_token;

		while ((fgets(line, MAXLINE, fname)) != NULL){
			token = strtok(line, splitBy);
			while (token != NULL) {
				cleaned_token = clean_word(token);
				//only add_word if not empty string
				if (strcmp(cleaned_token, "") != 0)	
				{
					head = add_word(head, filenames, cleaned_token, argv[optind]);
				}
				token = strtok(NULL, splitBy);}
		}

	optind++;
	}
	write_list(namefile, indexfile, head, filenames);
	display_list(head, filenames);
	return 0;
}
示例#18
0
文件: dump.hpp 项目: actuariat/stan
 void write_stan(const std::vector<T>& x) {
   std::vector<size_t> dims = dims(x);
   out_ << "structure(c(";
   std::vector<size_t> idx(dims.size(),0U);
   for (size_t count = 0; true; ++count) {
     if (count > 0) out_ << ", ";
     write_stan_val(x,idx);
     if (!increment(dims,idx)) break;
   }
   out_ << "), .Dim = ";
   write_list(dims);
   out_ << ")";
 }
示例#19
0
文件: database.c 项目: buhman/repose
static void compile_desc_entry(repo_t *repo, const alpm_pkg_meta_t *pkg, struct buffer *buf)
{
    write_string(buf, "FILENAME",  pkg->filename);
    write_string(buf, "NAME",      pkg->name);
    write_string(buf, "BASE",      pkg->base);
    write_string(buf, "VERSION",   pkg->version);
    write_string(buf, "DESC",      pkg->desc);
    write_list(buf,   "GROUPS",    pkg->groups);
    write_long(buf,   "CSIZE",     (long)pkg->size);
    write_long(buf,   "ISIZE",     (long)pkg->isize);

    if (pkg->md5sum) {
        write_string(buf, "MD5SUM", pkg->md5sum);
    } else {
        char *md5sum = _compute_md5sum(repo->dirfd, pkg->filename);
        write_string(buf, "MD5SUM", md5sum);
        free(md5sum);
    }

    if (pkg->sha256sum) {
        write_string(buf, "SHA256SUM", pkg->sha256sum);
    } else {
        char *sha256sum = _compute_sha256sum(repo->dirfd, pkg->filename);
        write_string(buf, "SHA256SUM", sha256sum);
        free(sha256sum);
    }

    if (pkg->base64_sig)
        write_string(buf, "PGPSIG", pkg->base64_sig);

    write_string(buf, "URL",       pkg->url);
    write_list(buf,   "LICENSE",   pkg->license);
    write_string(buf, "ARCH",      pkg->arch);
    write_long(buf,   "BUILDDATE", pkg->builddate);
    write_string(buf, "PACKAGER",  pkg->packager);
    write_list(buf,   "REPLACES",  pkg->replaces);
}
示例#20
0
文件: database.c 项目: buhman/repose
static void compile_depends_entry(const alpm_pkg_meta_t *pkg, struct buffer *buf)
{
    write_list(buf, "DEPENDS",      pkg->depends);
    write_list(buf, "CONFLICTS",    pkg->conflicts);
    write_list(buf, "PROVIDES",     pkg->provides);
    write_list(buf, "OPTDEPENDS",   pkg->optdepends);
    write_list(buf, "MAKEDEPENDS",  pkg->makedepends);
    write_list(buf, "CHECKDEPENDS", pkg->checkdepends);
}
示例#21
0
int main(int argc, char **argv) {

        Node *head = NULL;
        char **filenames = init_filenames();
        char ch;
        char *indexfile = "index";
        char *namefile = "filenames";
        char dirname[PATHLENGTH] = ".";
        char path[PATHLENGTH];

        while((ch = getopt(argc, argv, "i:n:d:")) != -1) {
                switch (ch) {
                        case 'i':
                        indexfile = optarg;
                        break;
                        case 'n':
                        namefile = optarg;
                        break;
                        case 'd':
                        strncpy(dirname, optarg, PATHLENGTH);
                        dirname[PATHLENGTH-1] = '\0'; 
                        break;
                        default:
                        fprintf(stderr, "Usage: indexer [-i FILE] [-n FILE ] [-d DIRECTORY_NAME]\n");
                        exit(1);
                }
        }
        DIR *dir;
        if((dir = opendir(dirname)) == NULL) {
                perror("opendir");
                exit(1);
        }
        struct dirent *dp;
        while((dp = readdir(dir)) != NULL) {
                if(strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0 ||
                    strcmp(dp->d_name, ".svn") == 0) {
                        continue;
                }
                path[0] = '\0';
                strncpy(path, dirname, PATHLENGTH);
                strncat(path, "/", PATHLENGTH-strlen(path));
                strncat(path, dp->d_name, PATHLENGTH-strlen(path));
                path[PATHLENGTH-1] = '\0';
                printf("Indexing: %s\n", path);
                head = index_file(head, path, filenames);
        }
        write_list(namefile, indexfile, head, filenames);
        return 0;
}
示例#22
0
int main(int argc, char **argv) {
    Node *head = create_node("", 0, 0);
    char **filenames = init_filenames();
    char ch, line[MAXLINE], *token;
    char *indexfile = "index";
    char *namefile = "filenames";
    FILE *fp;

    while((ch = getopt(argc, argv, "i:n:")) != -1) {
        switch (ch) {
        case 'i':
            indexfile = optarg;
            break;
        case 'n':
            namefile = optarg;
            break;
        default:
            fprintf(stderr, "Usage: indexfile [-i FILE] [-n FILE ] FILE...\n");
            exit(1);
        }
    }

    while (optind < argc) {
	if ( (fp = fopen(argv[optind], "r")) == NULL) {
    		fprintf(stderr, "Cannot open file %s.\n", argv[optind]);
    	}
    	else {	
		while ( fgets(line, MAXLINE, fp) != NULL ) { 
			token = strtok(line, DELIM);
     			for(; token != NULL ;) {
				add_word(head, filenames, convert_to_lower(token), argv[optind]);
				token = strtok(NULL, DELIM);
			}
		}	
    		fclose(fp);
	}
    	optind++;
    }
    
    write_list(namefile, indexfile, head, filenames);
   
    return 0;
}
示例#23
0
static bool write_object(binn* parent, object_t* object) {
    for (size_t i = 0; i < object->l; ++i) {
        char* key = CONST_CAST(object->children[i * 2].str);
        object_t* value = object->children + i * 2 + 1;
        switch (value->type) {
            case type_nil:     if (!binn_object_set_null(parent, key))                        return false;  break;
            case type_bool:    if (!binn_object_set_bool(parent, key, (BOOL)value->b))        return false;  break;
            case type_double:  if (!binn_object_set_double(parent, key, value->d))            return false;  break;
            case type_int:     if (!binn_object_set_int64(parent, key, value->i))             return false;  break;
            case type_uint:    if (!binn_object_set_uint64(parent, key, value->u))            return false;  break;
            case type_str:     if (!binn_object_set_str(parent, key, CONST_CAST(value->str))) return false;  break;

            case type_array: {
                binn child;
                binn_create_list(&child);
                bool ok = write_list(&child, value);
                if (ok)
                    ok = binn_object_set_object(parent, key, &child);
                binn_free(&child);
                if (!ok)
                    return false;
            } break;

            case type_map: {
                binn child;
                binn_create_object(&child);
                bool ok = write_object(&child, value);
                if (ok)
                    ok = binn_object_set_object(parent, key, &child);
                binn_free(&child);
                if (!ok)
                    return false;
            } break;

            default:
                return false;
        }
    }
    return true;
}
示例#24
0
int
main(int argc, char *argv[])
{
    config_t conf;
    char escape = '&';
    int i;

    /* Allocate string lists. */
    conf = init_config;
    memcpy(conf.lists.indexed, init_config_lists,
           sizeof(conf.lists.indexed));
    alloc_list(&conf.file_names);
    alloc_list(&conf.file_contents);
    alloc_list(&conf.replaces);
    for (i = 0; i < NUM_RESOURCE_LISTS; ++i)
        alloc_list(&conf.lists.indexed[i]);

    /* Initialize patterns. */
    conf.lib_p.upper_case = false;
    conf.lib_p.drop_extn = false;
    strcpy(conf.lib_p.pattern, "%s\n");
    conf.libpath_p = conf.lib_p;
    conf.obj_p = conf.lib_p;

    /* Process command line arguments. */
    for (i = 1; i < argc; i++) {
        const char *arg = argv[i];
        FILE *out;
        int lib = 0, obj = 0;

        if (*arg != '-') {
            read_dev(&conf, arg);
            continue;
        }
        if (i == argc - 1) {
            fprintf(stderr, "Missing argument after %s.\n",
                    arg);
            exit(1);
        }
        switch (arg[1]) {
            case 'C':		/* change directory, by analogy with make */
                conf.file_prefix =
                    (argv[i + 1][0] == '-' ? empty_str : argv[i + 1]);
                ++i;
                continue;
            case 'e':
                escape = argv[i + 1][0];
                ++i;
                continue;
            case 'n':
                conf.name_prefix =
                    (argv[i + 1][0] == '-' ? empty_str : argv[i + 1]);
                ++i;
                continue;
            case 'p':
                {
                    string_pattern_t *pat;

                    switch (*(arg += 2)) {
                        case 'l':
                            pat = &conf.lib_p;
                            break;
                        case 'L':
                            pat = &conf.libpath_p;
                            break;
                        default:
                            pat = &conf.obj_p;
                            arg--;
                    }
                    pat->upper_case = false;
                    pat->drop_extn = false;
                    if (argv[i + 1][0] == '-')
                        strcpy(pat->pattern, "%s\n");
                    else {
                        char *p, *q;

                        for (p = pat->pattern, q = argv[++i];
                             (*p++ = *q++) != 0;
                            )
                            if (p[-1] == escape)
                                switch (*q) {
                                    case 'p':
                                        p[-1] = '%'; q++; break;
                                    case 's':
                                        p[-1] = ' '; q++; break;
                                    case '-':
                                        p[-1] = '-'; q++; break;
                                    default:
                                        if (*q == escape) {
                                            p[-1] = '\\'; q++; break;
                                        }
                                        fprintf(stderr,
                                          "%c not followed by p|s|%c|-: &%c\n",
                                                escape, escape, *q);
                                        exit(1);
                                }
                        p[-1] = '\n';
                        *p = 0;
                    }
                    for (;;) {
                        switch (*++arg) {
                            case 'u':
                                pat->upper_case = true;
                                break;
                            case 'e':
                                pat->drop_extn = true;
                                break;
                            case 0:
                                goto pbreak;
                            default:
                                fprintf(stderr, "Unknown switch %s.\n", arg);
                                exit(1);
                        }
                    }
                  pbreak:if (pat == &conf.obj_p) {
                        conf.lib_p = *pat;
                        conf.libpath_p = *pat;
                    }
                    continue;
                }
            case 'Z':
                conf.debug = 1;
                continue;
        }
        /* Must be an output file. */
        out = fopen(argv[++i], "w");
        if (out == 0) {
            fprintf(stderr, "Can't open %s for output.\n",
                    argv[i]);
            exit(1);
        }
        switch (arg[1]) {
            case 'f':
                process_replaces(&conf);
                fputs("/* This file was generated automatically by genconf.c. */\n", out);
                fputs("/* For documentation, see gsconfig.c. */\n", out);
                {
                    char templat[MAX_TEMPLAT + 1];

                    sprintf(templat,
                            "font_(\"0.font_%%s\",%sf_%%s,zf_%%s)\n",
                            conf.name_prefix);
                    write_list(out, &conf.lists.named.fonts, templat);
                }
                break;
            case 'h':
                process_replaces(&conf);
                fputs("/* This file was generated automatically by genconf.c. */\n", out);
                write_list(out, &conf.lists.named.compositors, "%s\n");
                write_list(out, &conf.lists.named.devs, "%s\n");
                sort_uniq(&conf.lists.named.resources, true);
                write_list(out, &conf.lists.named.resources, "%s\n");
                sort_uniq(&conf.lists.named.sorted_resources, false);
                write_list(out, &conf.lists.named.sorted_resources, "%s\n");
                break;
            case 'l':
                lib = 1;
                obj = arg[2] == 'o';
                goto lo;
            case 'o':
                obj = 1;
                lib = arg[2] == 'l';
              lo:process_replaces(&conf);
                if (obj) {
                    sort_uniq(&conf.lists.named.objs, true);
                    write_list_pattern(out, &conf.lists.named.objs, &conf.obj_p);
                }
                if (lib) {
                    sort_uniq(&conf.lists.named.libs, true);
                    sort_uniq(&conf.lists.named.links, true);
                    write_list_pattern(out, &conf.lists.named.libpaths, &conf.libpath_p);
                    write_list_pattern(out, &conf.lists.named.links, &conf.obj_p);
                    write_list_pattern(out, &conf.lists.named.libs, &conf.lib_p);
                }
                break;
            default:
                fclose(out);
                fprintf(stderr, "Unknown switch %s.\n", argv[i]);
                exit(1);
        }
        fclose(out);
    }

    free_list(&conf.file_names);
    free_list(&conf.file_contents);
    free_list(&conf.replaces);
    for (i = 0; i < NUM_RESOURCE_LISTS; ++i)
        free_list(&conf.lists.indexed[i]);

    return 0;
}
示例#25
0
文件: dump.hpp 项目: actuariat/stan
 void write_stan(const Eigen::Matrix<double,Eigen::Dynamic,1>& x) {
   write_list(x);
 }
示例#26
0
文件: dump.hpp 项目: actuariat/stan
 void write_stan(const std::vector<int>& x) {
   write_list(x);
 }
示例#27
0
文件: dump.hpp 项目: actuariat/stan
 void write_stan(const std::vector<double>& x) {
   write_list(x);
 }
示例#28
0
serializer & operator<<(serializer & s, decl_attributes::entry const & e) {
    s << e.m_attr;
    write_list(s, e.m_params);
    return s;
}
示例#29
0
static void dump2(bytecode_input_t *d, int bc_len)
{
    int i;
    int version;
    const char *data;
    int len;

    if (!d) return;
    
    if (memcmp(d, BYTECODE_MAGIC, BYTECODE_MAGIC_LEN)) {
	printf("not a bytecode file [magic number test failed]\n");
	return;
    }

    i = BYTECODE_MAGIC_LEN / sizeof(bytecode_input_t);

    version = ntohl(d[i].op);
    printf("Sievecode version %d\n", version);
    
    for(i++; i<bc_len;) 
    {
	int copy = 0;

	printf("%d: ",i);

	switch(ntohl(d[i++].op)) {
	    
	case B_STOP:/*0*/
	    printf("STOP\n");
	    break;
	    
	case B_KEEP:/*1*/
	    printf("KEEP\n");
	    break;
	    
	case B_DISCARD:/*2*/
	    printf("DISCARD\n");
	    break;
	    
	case B_REJECT:/*3*/
	    i = unwrap_string(d, i, &data, &len);
	    printf("REJECT {%d}%s\n", len, data);
	    break;

	case B_FILEINTO: /*19*/
	    copy = ntohl(d[i++].value);
	    /* fall through */
	case B_FILEINTO_ORIG: /*4*/
	    i = unwrap_string(d, i, &data, &len);
	    printf("FILEINTO COPY(%d) FOLDER({%d}%s)\n",copy,len,data);
	    break;

	case B_REDIRECT: /*20*/
	    copy = ntohl(d[i++].value);
	    /* fall through */
	case B_REDIRECT_ORIG: /*5*/
	    i = unwrap_string(d, i, &data, &len);
	    printf("REDIRECT COPY(%d) ADDRESS({%d}%s)\n",copy,len,data);
	    break;
	     
	case B_IF:/*6*/
	    printf("IF (ends at %d)", ntohl(d[i].value));

            /* there is no short circuiting involved here*/
	    i = dump2_test(d,i+1);
	    printf("\n");

	    break;

	case B_MARK:/*7*/
	    printf("MARK\n");
	    break;

	case B_UNMARK:/*8*/
	    printf("UNMARK\n");
	    break;

	case B_ADDFLAG: /*9*/
	    printf("ADDFLAG  {%d}\n",ntohl(d[i].len));
	    i=write_list(ntohl(d[i].len),i+1,d);
	    break;

	case B_SETFLAG: /*10*/
	    printf("SETFLAG  {%d}\n",ntohl(d[i].len));
	    i=write_list(ntohl(d[i].len),i+1,d);
	    break;
	    
	case B_REMOVEFLAG: /*11*/
	    printf("REMOVEFLAG  {%d}\n",ntohl(d[i].len));
	    i=write_list(ntohl(d[i].len),i+1,d);
	    break;
	    
	case B_DENOTIFY:/*12*/
	    printf("DENOTIFY\n");
	    printf("            PRIORITY(%d) Comparison type %d (relat %d)\n",
		   ntohl(d[i].value), ntohl(d[i+1].value), ntohl(d[i+2].value));
	    i+=3;

	    i = unwrap_string(d, i+1, &data, &len);
	    
	    printf("           ({%d}%s)\n", len, (!data ? "[nil]" : data));
	    break;
	    
	case B_NOTIFY: /*13*/
	    i = unwrap_string(d, i, &data, &len);

	    printf("NOTIFY METHOD({%d}%s)\n",len,data);

	    i = unwrap_string(d, i, &data, &len);

	    printf("            ID({%d}%s) OPTIONS ", len,
		   (!data ? "[nil]" : data));

	    i=write_list(ntohl(d[i].len),i+1,d);
	    
	    printf("            PRIORITY(%d)\n", ntohl(d[i].value));
      	    i++;
		  
	    i = unwrap_string(d, i, &data, &len);

	    printf("            MESSAGE({%d}%s)\n", len, data);

	    break;

	case B_VACATION:/*14*/
	    printf("VACATION\n");
	    /*add address list here!*/
	    i=write_list(ntohl(d[i].len),i+1,d);

	    i = unwrap_string(d, i, &data, &len);
	  
	    printf("%d SUBJ({%d}%s) \n",i, len, (!data ? "[nil]" : data));
	    
	    i = unwrap_string(d, i, &data, &len);

	    printf("%d MESG({%d}%s) \n", i, len, (!data ? "[nil]" : data));

	    printf("DAYS(%d) MIME(%d)\n", ntohl(d[i].value), ntohl(d[i+1].value));
	    i+=2;

	    if (version >= 0x05) {
		i = unwrap_string(d, i, &data, &len);

		printf("%d FROM({%d}%s) \n",i, len, (!data ? "[nil]" : data));

		i = unwrap_string(d, i, &data, &len);

		printf("%d HANDLE({%d}%s) \n",i, len, (!data ? "[nil]" : data));
	    }

	    break;
	case B_NULL:/*15*/
	    printf("NULL\n");
	    break;
	case B_JUMP:/*16*/
	    printf("JUMP %d\n", ntohl(d[i].jump));
	    i+=1;
	    break;

	case B_INCLUDE:/*17*/
	    printf("INCLUDE ");
	    switch (ntohl(d[i].value)) {
	    case B_PERSONAL: printf("Personal"); break;
	    case B_GLOBAL: printf("Global"); break;
	    }
	    i = unwrap_string(d, i+1, &data, &len);
	    printf(" {%d}%s\n", len, data);
	    break;

	case B_RETURN:/*18*/
	    printf("RETURN\n");
	    break;
	    
	default:
	    printf("%d (NOT AN OP)\n",ntohl(d[i-1].op));
	    exit(1);
	}
    }
    printf("full len is: %d\n", bc_len);
}
示例#30
0
 virtual void write(serializer & s) const {
     s << *g_structure_instance_opcode << m_struct;
     write_list(s, m_fields);
 }