Example #1
0
static Errcode build_function_list(void)
/*****************************************************************************
 * build the lists of all lib function names and protos, sort the lists.
 ****************************************************************************/
{
	Lib_proto *lib;
	int 	   libcount;

	/*
	 * init the global 'cur' vars to indicate empty lists...
	 */

	curfullptr	  = fullnameptrs;
	curfullstr	  = namestrs;
	curfullproto  = fullprotoptrs;
	fullnamecount = 0;

	/*
	 * build the name and proto lists for the builtin library functions...
	 */

	libcount = FindPoe("poco$builtin", &lib);   /* get first builtin lib */
	if (libcount < Success)
		return libcount;

	do	{										/* loop thru builtin libs... */
		add_library(lib, libcount);
		if (builtin_err)
			return builtin_err;
		libcount = FindPoe(NULL, &lib); 		/* get next builtin lib */
	} while (libcount > 0);

	/*
	 * build the name and proto lists for the loaded library functions...
	 * (note that we filter ourselves out of the loaded library listing.)
	 */

	libcount = FindPoe("poco$loaded", &lib);    /* get first loaded lib */
	if (libcount < Success)
		return libcount;

	do {
		if (lib != calls) { 					/* as long as it's not us...*/
			add_library(lib, libcount);
			if (builtin_err)
				return builtin_err;
		}
		libcount = FindPoe(NULL, &lib); 		/* get next loaded lib */
	} while (libcount > 0);

	/*
	 * go sort the names (and associated proto pointers)...
	 */

	sort_namelist();

	return Success;
}
void 
JB2Dict::JB2Codec::Encode::encode_libonly_shape(
  const GP<JB2Image> &gjim, int shapeno )
{
  if(!gjim)
  {
    G_THROW( ERR_MSG("JB2Image.bad_number") );
  }
  JB2Image &jim=*gjim;
  // Recursively encode parent shape
  JB2Shape &jshp = jim.get_shape(shapeno);
  if (jshp.parent>=0 && shape2lib[jshp.parent]<0)
    encode_libonly_shape(gjim, jshp.parent);
  // Test that library shape must be encoded
  if (shape2lib[shapeno] < 0)
    {
      // Code library entry
      int rectype=(jshp.parent >= 0)
            ?NEW_MARK_LIBRARY_ONLY:MATCHED_REFINE_LIBRARY_ONLY;
      code_record(rectype, gjim, &jshp, 0);      
      // Add shape to library
      add_library(shapeno, jshp);
      // Check numcoder status
      if (cur_ncell > CELLCHUNK) 
	{
	  rectype = REQUIRED_DICT_OR_RESET;
	  code_record(rectype, 0, 0);
	}
    }
}
Example #3
0
void add_cprover_library(
  const std::set<irep_idt> &functions,
  symbol_tablet &symbol_table,
  message_handlert &message_handler)
{
  if(config.ansi_c.lib==configt::ansi_ct::libt::LIB_NONE)
    return;
    
  std::string library_text;

  library_text=get_cprover_library_text(functions, symbol_table);
  
  add_library(library_text, symbol_table, message_handler);
}
void 
JB2Dict::JB2Codec::Encode::code(const GP<JB2Dict> &gjim)
{
  if(!gjim)
  {
    G_THROW( ERR_MSG("JB2Image.bad_number") );
  }
  JB2Dict &jim=*gjim;
      // -------------------------
      // THIS IS THE ENCODING PART
      // -------------------------
      int firstshape = jim.get_inherited_shape_count();
      int nshape = jim.get_shape_count();
      init_library(jim);
      // Code headers.
      int rectype = REQUIRED_DICT_OR_RESET;
      if (jim.get_inherited_shape_count() > 0)
        code_record(rectype, gjim, 0);
      rectype = START_OF_DATA;
      code_record(rectype, gjim, 0);
      // Code Comment.
      rectype = PRESERVED_COMMENT;
      if (!! jim.comment)
        code_record(rectype, gjim, 0);
      // Encode every shape
      int shapeno;
      DJVU_PROGRESS_TASK(jb2code,"jb2 encode", nshape-firstshape);
      for (shapeno=firstshape; shapeno<nshape; shapeno++)
        {
          DJVU_PROGRESS_RUN(jb2code, (shapeno-firstshape)|0xff);
          // Code shape
          JB2Shape &jshp = jim.get_shape(shapeno);
          rectype=(jshp.parent >= 0)
            ?MATCHED_REFINE_LIBRARY_ONLY:NEW_MARK_LIBRARY_ONLY;
          code_record(rectype, gjim, &jshp);
          add_library(shapeno, jshp);
	  // Check numcoder status
	  if (cur_ncell > CELLCHUNK) 
	    {
	      rectype = REQUIRED_DICT_OR_RESET;
	      code_record(rectype, 0, 0);	      
	    }
        }
      // Code end of data record
      rectype = END_OF_DATA;
      code_record(rectype, gjim, 0); 
      gzp=0;
}
Example #5
0
void add_cegis_library(symbol_tablet &st, goto_functionst &gf,
    message_handlert &msg, const size_t num_vars, const size_t num_consts,
    const size_t max_solution_size, const std::string &func_name)
{
  add_execute_placeholder(st, func_name, cegis_execute_type());
  std::set<irep_idt> functions;
  functions.insert(func_name);
  const std::string library_src(
      get_cegis_library_text(num_vars, num_consts, max_solution_size,
          func_name));

  add_library(library_src, st, msg);
  goto_convert(func_name, st, gf, msg);
  gf.compute_loop_numbers();
  gf.update();
  set_init_values(st, gf);
}
Example #6
0
int main(int argc, char *argv[])
{
	char **p = argv;
	signal(SIGCHLD, SIG_DFL);

	while (*++p) {
		/* filename or option ? */
		if (**p != '-') {
			add_file(*p);
			continue;
		}
		switch ((*p)[1]) {
			/* Don't link */
		case 'c':
			uniopt(*p);
			last_phase = 3;
			break;
			/* Don't assemble */
		case 'S':
			uniopt(*p);
			last_phase = 2;
			break;
			/* Only pre-process */
		case 'E':
			uniopt(*p);
			last_phase = 1;
			only_one_input = 1;
			break;
		case 'l':
			p = add_library(p);
			break;
		case 'I':
			p = add_includes(p);
			break;
		case 'L':
			p = add_library_path(p);
			break;
		case 'D':
			p = add_macro(p);
			break;
		case 'i':
/*                    split_id();*/
			uniopt(*p);
			break;
		case 'o':
			if (target != NULL) {
				fprintf(stderr,
					"-o can only be used once.\n");
				fatal();
			}
			if ((*p)[2])
				target = *p + 2;
			else
				target = *++p;
			break;
		case 'X':
			uniopt(*p);
			keep_temp = 1;
			break;
		default:
			usage();
		}
	}

	if (target == NULL)
		target = "a.out";
	if (only_one_input && c_files > 1)
		one_input();
	processing_loop();
	unused_files();
	return 0;
}
Example #7
0
static void build(struct options* opts)
{
    static const char *stdlibpath[] = { DLLDIR, LIBDIR, "/usr/lib", "/usr/local/lib", "/lib" };
    strarray *lib_dirs, *files;
    strarray *spec_args, *link_args;
    char *output_file;
    const char *spec_o_name;
    const char *output_name, *spec_file, *lang;
    const char* winebuild = getenv("WINEBUILD");
    int generate_app_loader = 1;
    unsigned int j;

    /* NOTE: for the files array we'll use the following convention:
     *    -axxx:  xxx is an archive (.a)
     *    -dxxx:  xxx is a DLL (.def)
     *    -lxxx:  xxx is an unsorted library
     *    -oxxx:  xxx is an object (.o)
     *    -rxxx:  xxx is a resource (.res)
     *    -sxxx:  xxx is a shared lib (.so)
     *    -xlll:  lll is the language (c, c++, etc.)
     */

    if (!winebuild) winebuild = "winebuild";

    output_file = strdup( opts->output_name ? opts->output_name : "a.out" );

    /* 'winegcc -o app xxx.exe.so' only creates the load script */
    if (opts->files->size == 1 && strendswith(opts->files->base[0], ".exe.so"))
    {
	create_file(output_file, 0755, app_loader_template, opts->files->base[0]);
	return;
    }

    /* generate app loader only for .exe */
    if (opts->shared || strendswith(output_file, ".exe.so"))
	generate_app_loader = 0;

    /* normalize the filename a bit: strip .so, ensure it has proper ext */
    if (strendswith(output_file, ".so")) 
	output_file[strlen(output_file) - 3] = 0;
    if (opts->shared)
    {
	if ((output_name = strrchr(output_file, '/'))) output_name++;
	else output_name = output_file;
	if (!strchr(output_name, '.'))
	    output_file = strmake("%s.dll", output_file);
    }
    else if (!strendswith(output_file, ".exe"))
	output_file = strmake("%s.exe", output_file);

    /* get the filename from the path */
    if ((output_name = strrchr(output_file, '/'))) output_name++;
    else output_name = output_file;

    /* prepare the linking path */
    if (!opts->wine_objdir)
    {
        lib_dirs = strarray_dup(opts->lib_dirs);
	for ( j = 0; j < sizeof(stdlibpath)/sizeof(stdlibpath[0]); j++ )
	    strarray_add(lib_dirs, stdlibpath[j]);
    }
    else
    {
        lib_dirs = strarray_alloc();
        strarray_add(lib_dirs, strmake("%s/dlls", opts->wine_objdir));
        strarray_add(lib_dirs, strmake("%s/libs/wine", opts->wine_objdir));
        strarray_addall(lib_dirs, opts->lib_dirs);
    }

    /* mark the files with their appropriate type */
    spec_file = lang = 0;
    files = strarray_alloc();
    for ( j = 0; j < opts->files->size; j++ )
    {
	const char* file = opts->files->base[j];
	if (file[0] != '-')
	{
	    switch(get_file_type(file))
	    {
		case file_def:
		case file_spec:
		    if (spec_file)
			error("Only one spec file can be specified\n");
		    spec_file = file;
		    break;
		case file_rc:
		    /* FIXME: invoke wrc to build it */
		    error("Can't compile .rc file at the moment: %s\n", file);
	            break;
	    	case file_res:
		    strarray_add(files, strmake("-r%s", file));
		    break;
		case file_obj:
		    strarray_add(files, strmake("-o%s", file));
		    break;
		case file_arh:
		    strarray_add(files, strmake("-a%s", file));
		    break;
		case file_so:
		    strarray_add(files, strmake("-s%s", file));
		    break;
	    	case file_na:
		    error("File does not exist: %s\n", file);
		    break;
	        default:
		    file = compile_to_object(opts, file, lang);
		    strarray_add(files, strmake("-o%s", file));
		    break;
	    }
	}
	else if (file[1] == 'l')
            add_library( lib_dirs, files, file + 2 );
	else if (file[1] == 'x')
	    lang = file;
    }
    if (opts->shared && !spec_file)
	error("A spec file is currently needed in shared mode\n");

    /* add the default libraries, if needed */
    if (!opts->nostdlib && opts->use_msvcrt) add_library(lib_dirs, files, "msvcrt");

    if (!opts->wine_objdir && !opts->nodefaultlibs) 
    {
        if (opts->gui_app) 
	{
	    add_library(lib_dirs, files, "shell32");
	    add_library(lib_dirs, files, "comdlg32");
	    add_library(lib_dirs, files, "gdi32");
	}
        add_library(lib_dirs, files, "advapi32");
        add_library(lib_dirs, files, "user32");
        add_library(lib_dirs, files, "kernel32");
    }

    if (!opts->nostartfiles) add_library(lib_dirs, files, "winecrt0");
    if (!opts->nostdlib) add_library(lib_dirs, files, "wine");

    /* run winebuild to generate the .spec.o file */
    spec_args = strarray_alloc();
    spec_o_name = get_temp_file(output_name, ".spec.o");
    strarray_add(spec_args, winebuild);
    if (verbose) strarray_add(spec_args, "-v");
    if (keep_generated) strarray_add(spec_args, "--save-temps");
    strarray_add(spec_args, "--as-cmd");
    strarray_add(spec_args, AS);
    strarray_add(spec_args, "--ld-cmd");
    strarray_add(spec_args, LD);
    strarray_addall(spec_args, strarray_fromstring(DLLFLAGS, " "));
    strarray_add(spec_args, opts->shared ? "--dll" : "--exe");
    strarray_add(spec_args, "-o");
    strarray_add(spec_args, spec_o_name);
    if (spec_file)
    {
        strarray_add(spec_args, "-E");
        strarray_add(spec_args, spec_file);
    }

    if (!opts->shared)
    {
        strarray_add(spec_args, "-F");
        strarray_add(spec_args, output_name);
        strarray_add(spec_args, "--subsystem");
        strarray_add(spec_args, opts->gui_app ? "windows" : "console");
        if (opts->unicode_app)
        {
            strarray_add(spec_args, "--entry");
            strarray_add(spec_args, "__wine_spec_exe_wentry");
        }
    }

    for ( j = 0; j < lib_dirs->size; j++ )
	strarray_add(spec_args, strmake("-L%s", lib_dirs->base[j]));

    for ( j = 0 ; j < opts->winebuild_args->size ; j++ )
        strarray_add(spec_args, opts->winebuild_args->base[j]);

    for ( j = 0; j < files->size; j++ )
    {
	const char* name = files->base[j] + 2;
	switch(files->base[j][1])
	{
	    case 'r':
		strarray_add(spec_args, files->base[j]);
		break;
	    case 'd':
	    case 'a':
	    case 'o':
		strarray_add(spec_args, name);
		break;
	}
    }

    spawn(opts->prefix, spec_args, 0);

    /* link everything together now */
    link_args = strarray_alloc();
    strarray_addall(link_args, get_translator(opts->processor));
    strarray_addall(link_args, strarray_fromstring(LDDLLFLAGS, " "));

    strarray_add(link_args, "-o");
    strarray_add(link_args, strmake("%s.so", output_file));

    for ( j = 0 ; j < opts->linker_args->size ; j++ ) 
        strarray_add(link_args, opts->linker_args->base[j]);

#ifdef __APPLE__
    if (opts->image_base)
    {
        strarray_add(link_args, "-image_base");
        strarray_add(link_args, opts->image_base);
    }
#endif

    for ( j = 0; j < lib_dirs->size; j++ )
	strarray_add(link_args, strmake("-L%s", lib_dirs->base[j]));

    strarray_add(link_args, spec_o_name);

    for ( j = 0; j < files->size; j++ )
    {
	const char* name = files->base[j] + 2;
	switch(files->base[j][1])
	{
	    case 'l':
	    case 's':
		strarray_add(link_args, strmake("-l%s", name));
		break;
	    case 'a':
	    case 'o':
		strarray_add(link_args, name);
		break;
	}
    }

    if (!opts->nostdlib) 
    {
	strarray_add(link_args, "-lm");
	strarray_add(link_args, "-lc");
    }

    spawn(opts->prefix, link_args, 0);

    /* set the base address */
    if (opts->image_base)
    {
        const char *prelink = PRELINK;
        if (prelink[0] && strcmp(prelink,"false"))
        {
            strarray *prelink_args = strarray_alloc();
            strarray_add(prelink_args, prelink);
            strarray_add(prelink_args, "--reloc-only");
            strarray_add(prelink_args, opts->image_base);
            strarray_add(prelink_args, strmake("%s.so", output_file));
            spawn(opts->prefix, prelink_args, 1);
            strarray_free(prelink_args);
        }
    }

    /* create the loader script */
    if (generate_app_loader)
    {
        if (strendswith(output_file, ".exe")) output_file[strlen(output_file) - 4] = 0;
        create_file(output_file, 0755, app_loader_template, strmake("%s.exe.so", output_name));
    }
}
void 
JB2Dict::JB2Codec::Encode::code(const GP<JB2Image> &gjim)
{
  if(!gjim)
  {
    G_THROW( ERR_MSG("JB2Image.bad_number") );
  }
  JB2Image &jim=*gjim;
      // -------------------------
      // THIS IS THE ENCODING PART
      // -------------------------
      int i;
      init_library(jim);
      int firstshape = jim.get_inherited_shape_count();
      int nshape = jim.get_shape_count();
      int nblit = jim.get_blit_count();
      // Initialize shape2lib 
      shape2lib.resize(0,nshape-1);
      for (i=firstshape; i<nshape; i++)
        shape2lib[i] = -1;
      // Determine shapes that go into library (shapeno>=firstshape)
      //  shape2lib is -2 if used by one blit
      //  shape2lib is -3 if used by more than one blit
      //  shape2lib is -4 if used as a parent
      for (i=0; i<nblit; i++)
        {
          JB2Blit *jblt = jim.get_blit(i);
          int shapeno = jblt->shapeno;
          if (shapeno < firstshape)
            continue;
          if (shape2lib[shapeno] >= -2) 
            shape2lib[shapeno] -= 1;
          shapeno = jim.get_shape(shapeno).parent;
          while (shapeno>=firstshape && shape2lib[shapeno]>=-3)
            {
              shape2lib[shapeno] = -4;
              shapeno = jim.get_shape(shapeno).parent;
            }
        }
      // Code headers.
      int rectype = REQUIRED_DICT_OR_RESET;
      if (jim.get_inherited_shape_count() > 0)
        code_record(rectype, gjim, 0, 0);
      rectype = START_OF_DATA;
      code_record(rectype, gjim, 0, 0);
      // Code Comment.
      rectype = PRESERVED_COMMENT;
      if (!! jim.comment)
        code_record(rectype, gjim, 0, 0);
      // Encode every blit
      int blitno;
      DJVU_PROGRESS_TASK(jb2code,"jb2 encode", nblit);
      for (blitno=0; blitno<nblit; blitno++)
        {
          DJVU_PROGRESS_RUN(jb2code, blitno|0xff);
          JB2Blit *jblt = jim.get_blit(blitno);
          int shapeno = jblt->shapeno;
          JB2Shape &jshp = jim.get_shape(shapeno);
          // Tests if shape exists in library
          if (shape2lib[shapeno] >= 0)
            {
              int rectype = MATCHED_COPY;
              code_record(rectype, gjim, 0, jblt);
            }
          // Avoid coding null shapes/blits
          else if (jshp.bits) 
            {
              // Make sure all parents have been coded
              if (jshp.parent>=0 && shape2lib[jshp.parent]<0)
                encode_libonly_shape(gjim, jshp.parent);
              // Allocate library entry when needed
#define LIBRARY_CONTAINS_ALL
              int libraryp = 0;
#ifdef LIBRARY_CONTAINS_MARKS // baseline
              if (jshp.parent >= -1)
                libraryp = 1;
#endif
#ifdef LIBRARY_CONTAINS_SHARED // worse             
              if (shape2lib[shapeno] <= -3)
                libraryp = 1;
#endif
#ifdef LIBRARY_CONTAINS_ALL // better
              libraryp = 1;
#endif
              // Test all blit cases
              if (jshp.parent<-1 && !libraryp)
                {
                  int rectype = NON_MARK_DATA;
                  code_record(rectype, gjim, &jshp, jblt);
                }
              else if (jshp.parent < 0)
                {
                  int rectype = (libraryp ? NEW_MARK : NEW_MARK_IMAGE_ONLY);
                  code_record(rectype, gjim, &jshp, jblt);
                }
              else 
                {
                  int rectype = (libraryp ? MATCHED_REFINE : MATCHED_REFINE_IMAGE_ONLY);
                  code_record(rectype, gjim, &jshp, jblt);
                }
              // Add shape to library
              if (libraryp) 
                add_library(shapeno, jshp);
            }
	  // Check numcoder status
	  if (cur_ncell > CELLCHUNK) 
	    {
	      rectype = REQUIRED_DICT_OR_RESET;
	      code_record(rectype, 0, 0);
	    }
        }
      // Code end of data record
      rectype = END_OF_DATA;
      code_record(rectype, gjim, 0, 0); 
      gzp=0;
}
Example #9
0
File: ldrdf.c Project: aosm/nasm
int main(int argc, char **argv)
{
    char *outname = "aout.rdf";
    int moduleloaded = 0;
    char *respstrings[128] = { 0, };

    options.verbose = 0;
    options.align = 16;
    options.dynalink = 0;
    options.strip = 0;

    error_file = stderr;

    argc--, argv++;
    if (argc == 0)
        usage();
    while (argc && *argv && **argv == '-' && argv[0][1] != 'l') {
        switch (argv[0][1]) {
        case 'r':
            printf("ldrdf (linker for RDF files) version " LDRDF_VERSION
                   "\n");
            printf("RDOFF2 revision %s\n", RDOFF2_REVISION);
            exit(0);
        case 'v':
            if (argv[0][2] == '=') {
                options.verbose = argv[0][3] - '0';
                if (options.verbose < 0 || options.verbose > 9) {
                    fprintf(stderr,
                            "ldrdf: verbosity level must be a number"
                            " between 0 and 9\n");
                    exit(1);
                }
            } else
                options.verbose++;
            break;
        case 'a':
            options.align = atoi(argv[1]);
            if (options.align <= 0) {
                fprintf(stderr,
                        "ldrdf: -a expects a positive number argument\n");
                exit(1);
            }
            argv++, argc--;
            break;
        case 's':
            options.strip = 1;
            break;
        case 'd':
            if (argv[0][2] == 'y')
                options.dynalink = 1;
            break;
        case 'o':
            outname = argv[1];
            argv++, argc--;
            break;
        case 'j':
            if (!objpath) {
                options.objpath = 1;
                objpath = argv[1];
                argv++, argc--;
                break;
            } else {
                fprintf(stderr,
                        "ldrdf: more than one objects search path specified\n");
                exit(1);
            }
        case 'L':
            if (!libpath) {
                options.libpath = 1;
                libpath = argv[1];
                argv++, argc--;
                break;
            } else {
                fprintf(stderr,
                        "ldrdf: more than one libraries search path specified\n");
                exit(1);
            }
        case '@':{
                int i = 0;
                char buf[256];
                FILE *f;

                options.respfile = 1;
                if (argv[1] != NULL)
                    f = fopen(argv[1], "r");
                else {
                    fprintf(stderr,
                            "ldrdf: no response file name specified\n");
                    exit(1);
                }

                if (f == NULL) {
                    fprintf(stderr,
                            "ldrdf: unable to open response file\n");
                    exit(1);
                }

                argv++, argc--;
                while (fgets(buf, sizeof(buf), f) != NULL) {
                    char *p;
                    if (buf[0] == '\n')
                        continue;
                    if ((p = strchr(buf, '\n')) != NULL)
                        *p = '\0';
                    if (i >= 128) {
                        fprintf(stderr, "ldrdf: too many input files\n");
                        exit(1);
                    }
                    *(respstrings + i) = newstr(buf);
                    argc++, i++;
                }
                break;
            }
        case '2':
            options.stderr_redir = 1;
            error_file = stdout;
            break;
        case 'g':
            generic_rec_file = argv[1];
            argv++, argc--;
            break;
        default:
            usage();
        }
        argv++, argc--;
    }

    if (options.verbose > 4) {
        printf("ldrdf invoked with options:\n");
        printf("    section alignment: %d bytes\n", options.align);
        printf("    output name: `%s'\n", outname);
        if (options.strip)
            printf("    strip symbols\n");
        if (options.dynalink)
            printf("    Unix-style dynamic linking\n");
        if (options.objpath)
            printf("    objects search path: %s\n", objpath);
        if (options.libpath)
            printf("    libraries search path: %s\n", libpath);
        printf("\n");
    }

    symtab = symtabNew();
    initsegments();

    if (!symtab) {
        fprintf(stderr, "ldrdf: out of memory\n");
        exit(1);
    }

    while (argc) {
        if (!*argv)
            argv = respstrings;
        if (!*argv)
            break;
        if (!strncmp(*argv, "-l", 2)) {
            if (libpath && (argv[0][2] != '/'))
                add_library(newstrcat(libpath, *argv + 2));
            else
                add_library(*argv + 2);
        } else {
            if (objpath && (argv[0][0] != '/'))
                loadmodule(newstrcat(objpath, *argv));
            else
                loadmodule(*argv);
            moduleloaded = 1;
        }
        argv++, argc--;
    }

    if (!moduleloaded) {
        printf("ldrdf: nothing to do. ldrdf -h for usage\n");
        return 0;
    }

    search_libraries();

    if (options.verbose > 2) {
        printf("symbol table:\n");
        symtabDump(symtab, stdout);
    }

    write_output(outname);

    if (errorcount > 0)
        exit(1);
    return 0;
}
Example #10
0
static void parse_process(int pid)
{
	FILE *file;
	FILE *cmd;
	int len;

	char filename[PATH_MAX];
	char cmdfile[PATH_MAX];
	char program_name[PATH_MAX];

	char line[4096];
	char lib[4096];
	struct program *program;
	uint64_t pss = 0;
	uint64_t this_pss = 0;

	memset(program_name, 0, sizeof(program_name));
	sprintf(cmdfile, "/proc/%i/cmdline", pid);
	cmd = fopen(cmdfile, "r");
	if (!cmd)
		return;

	len = fread(program_name, 1, sizeof(program_name), cmd);
	if (len <= 0) {
		fclose(cmd);
		return;
	}

	int i = 0;
	while (i++ < len) {
		if (program_name[i] == 0)
			program_name[i] = 32;
	}
	program_name[len] = '\0';

	program = malloc(sizeof(struct program));
	assert(program != NULL);
	program->name = strdup(program_name);
	programs = g_list_append(programs, program);

	sprintf(filename, "/proc/%i/smaps", pid);
	file = fopen(filename, "r");
	if (!file) {
		fclose(cmd);
		return;
	}
	while (!feof(file)) {
		char *c;
		memset(line, 0, sizeof(line));
		if (!fgets(line, sizeof(line) - 1, file))
			break;

		if (line[0] < 'A' || line[0] > 'Z') {
			c = strchr(line, '/');
			if (c)
				strcpy(lib, c);
		}

		if (strstr(line, "Pss:")) {
			uint64_t val = 0;
			c = line;
			c += 5;
			val = strtoull(c, NULL, 10);
			pss += val;
			this_pss += val;
		}

		if (daem == 0) {
			if (strstr(line, "Swap:")) {
				add_library(lib, this_pss, pid);
				this_pss = 0;
				lib[0] = 0;
			}
		}

	}
	program->kb = pss;
	fclose(file);
	fclose(cmd);
}
Example #11
0
void
JB2Dict::JB2Codec::code_record(
  int &rectype, const GP<JB2Dict> &gjim, JB2Shape *xjshp)
{
  GP<GBitmap> cbm;
  GP<GBitmap> bm;
  int shapeno = -1;

  // Code record type
  code_record_type(rectype);
  
  // Pre-coding actions
  switch(rectype)
    {
    case NEW_MARK_LIBRARY_ONLY:
    case MATCHED_REFINE_LIBRARY_ONLY:
      {
        if(!xjshp)
        {
          G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Shape &jshp=*xjshp;
        if (!encoding) 
        {
          jshp.bits = GBitmap::create();
          jshp.parent = -1;
        }
        bm = jshp.bits;
        break;
      }
    }
  // Coding actions
  switch (rectype)
    {
    case START_OF_DATA:
      {
        if(!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Dict &jim=*gjim;
        code_image_size (jim);
        code_eventual_lossless_refinement ();
        if (! encoding)
          init_library(jim);
        break;
      }
    case NEW_MARK_LIBRARY_ONLY:
      {
        code_absolute_mark_size (*bm, 4);
        code_bitmap_directly (*bm);
        break;
      }
    case MATCHED_REFINE_LIBRARY_ONLY:
      {
        if(!xjshp||!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Dict &jim=*gjim;
        JB2Shape &jshp=*xjshp;
        int match = code_match_index (jshp.parent, jim);
        cbm = jim.get_shape(jshp.parent).bits;
        LibRect &l = libinfo[match];
        code_relative_mark_size (*bm, l.right-l.left+1, l.top-l.bottom+1, 4);
        code_bitmap_by_cross_coding (*bm, cbm, jshp.parent);
        break;
      }
    case PRESERVED_COMMENT:
      {
        if(!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Dict &jim=*gjim;
        code_comment(jim.comment);
        break;
      }
    case REQUIRED_DICT_OR_RESET:
      {
        if (! gotstartrecordp)
        {
	  // Indicates need for a shape dictionary
          if(!gjim)
          {
             G_THROW( ERR_MSG("JB2Image.bad_number") );
          }
	  code_inherited_shape_count(*gjim);
        }else
	  // Reset all numerical contexts to zero
	  reset_numcoder();
        break;
      }
    case END_OF_DATA:
      {
        break;
      }
    default:
      {
        G_THROW( ERR_MSG("JB2Image.bad_type") );
      }
    }
  // Post-coding action
  if (!encoding)
    {
      // add shape to dictionary
      switch(rectype)
        {
        case NEW_MARK_LIBRARY_ONLY:
        case MATCHED_REFINE_LIBRARY_ONLY:
          {
            if(!xjshp||!gjim)
            {
               G_THROW( ERR_MSG("JB2Image.bad_number") );
            }
            JB2Shape &jshp=*xjshp;
            shapeno = gjim->add_shape(jshp);
            add_library(shapeno, jshp);
            break;
          }
        }
      // make sure everything is compacted
      // decompaction will occur automatically when needed
      if (bm)
        bm->compress();
    }
}
Example #12
0
void
JB2Dict::JB2Codec::code_record(
  int &rectype, const GP<JB2Image> &gjim, JB2Shape *xjshp, JB2Blit *jblt)
{
  GP<GBitmap> bm;
  GP<GBitmap> cbm;
  int shapeno = -1;
  int match;

  // Code record type
  code_record_type(rectype);
  
  // Pre-coding actions
  switch(rectype)
    {
    case NEW_MARK:
    case NEW_MARK_LIBRARY_ONLY:
    case NEW_MARK_IMAGE_ONLY:
    case MATCHED_REFINE:
    case MATCHED_REFINE_LIBRARY_ONLY:
    case MATCHED_REFINE_IMAGE_ONLY:
    case NON_MARK_DATA:
      {
        if(!xjshp)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Shape &jshp=*xjshp;
        if (!encoding) 
        {
          jshp.bits = GBitmap::create();
          jshp.parent = -1;
          if (rectype == NON_MARK_DATA)
            jshp.parent = -2;
        }
        bm = jshp.bits;
        break;
      }
    }
  // Coding actions
  switch (rectype)
    {
    case START_OF_DATA:
      {
        if(!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Image &jim=*gjim;
        code_image_size (jim);
        code_eventual_lossless_refinement ();
        if (! encoding)
          init_library(jim);
        break;
      }
    case NEW_MARK:
      {
        code_absolute_mark_size (*bm, 4);
        code_bitmap_directly (*bm);
        code_relative_location (jblt, bm->rows(), bm->columns() );
        break;
      }
    case NEW_MARK_LIBRARY_ONLY:
      {
        code_absolute_mark_size (*bm, 4);
        code_bitmap_directly (*bm);
        break;
      }
    case NEW_MARK_IMAGE_ONLY:
      {
        code_absolute_mark_size (*bm, 3);
        code_bitmap_directly (*bm);
        code_relative_location (jblt, bm->rows(), bm->columns() );
        break;
      }
    case MATCHED_REFINE:
      {
        if(!xjshp || !gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Shape &jshp=*xjshp;
        JB2Image &jim=*gjim;
        match = code_match_index (jshp.parent, jim);
        cbm = jim.get_shape(jshp.parent).bits;
        LibRect &l = libinfo[match];
        code_relative_mark_size (*bm, l.right-l.left+1, l.top-l.bottom+1, 4); 
        code_bitmap_by_cross_coding (*bm, cbm, match);
        code_relative_location (jblt, bm->rows(), bm->columns() );
        break;
      }
    case MATCHED_REFINE_LIBRARY_ONLY:
      {
        if(!xjshp||!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Image &jim=*gjim;
        JB2Shape &jshp=*xjshp;
        match = code_match_index (jshp.parent, jim);
        cbm = jim.get_shape(jshp.parent).bits;
        LibRect &l = libinfo[match];
        code_relative_mark_size (*bm, l.right-l.left+1, l.top-l.bottom+1, 4);
        break;
      }
    case MATCHED_REFINE_IMAGE_ONLY:
      {
        if(!xjshp||!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Image &jim=*gjim;
        JB2Shape &jshp=*xjshp;
        match = code_match_index (jshp.parent, jim);
        cbm = jim.get_shape(jshp.parent).bits;
        LibRect &l = libinfo[match];
        code_relative_mark_size (*bm, l.right-l.left+1, l.top-l.bottom+1, 4);
        code_bitmap_by_cross_coding (*bm, cbm, match);
        code_relative_location (jblt, bm->rows(), bm->columns() );
        break;
      }
    case MATCHED_COPY:
      {
        int temp;
        if (encoding) temp = jblt->shapeno;
        if(!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Image &jim=*gjim;
        match = code_match_index (temp, jim);
        if (!encoding) jblt->shapeno = temp;
        bm = jim.get_shape(jblt->shapeno).bits;
        LibRect &l = libinfo[match];
        jblt->left += l.left;
        jblt->bottom += l.bottom;
        if (jim.reproduce_old_bug)
          code_relative_location (jblt, bm->rows(), bm->columns() );
        else
          code_relative_location (jblt, l.top-l.bottom+1, l.right-l.left+1 );
        jblt->left -= l.left;
        jblt->bottom -= l.bottom; 
        break;
      }
    case NON_MARK_DATA:
      {
        code_absolute_mark_size (*bm, 3);
        code_bitmap_directly (*bm);
        code_absolute_location (jblt, bm->rows(), bm->columns() );
        break;
      }
    case PRESERVED_COMMENT:
      {
        if(!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Image &jim=*gjim;
        code_comment(jim.comment);
        break;
      }
    case REQUIRED_DICT_OR_RESET:
      {
        if(!gjim)
        {
           G_THROW( ERR_MSG("JB2Image.bad_number") );
        }
        JB2Image &jim=*gjim;
        if (! gotstartrecordp)
	  // Indicates need for a shape dictionary
	  code_inherited_shape_count(jim);
	else
	  // Reset all numerical contexts to zero
	  reset_numcoder();
        break;
      }
    case END_OF_DATA:
      {
        break;
      }
    default:
      {
        G_THROW( ERR_MSG("JB2Image.unknown_type") );
      }
    }
  
  // Post-coding action
  if (!encoding)
    {
      // add shape to image
      switch(rectype)
        {
        case NEW_MARK:
        case NEW_MARK_LIBRARY_ONLY:
        case NEW_MARK_IMAGE_ONLY:
        case MATCHED_REFINE:
        case MATCHED_REFINE_LIBRARY_ONLY:
        case MATCHED_REFINE_IMAGE_ONLY:
        case NON_MARK_DATA:
          {
            if(!xjshp||!gjim)
            {
              G_THROW( ERR_MSG("JB2Image.bad_number") );
            }
            JB2Shape &jshp=*xjshp;
            shapeno = gjim->add_shape(jshp);
            shape2lib.touch(shapeno);
            shape2lib[shapeno] = -1;
            break;
          }
        }
      // add shape to library
      switch(rectype)
        {
        case NEW_MARK:
        case NEW_MARK_LIBRARY_ONLY:
        case MATCHED_REFINE:
        case MATCHED_REFINE_LIBRARY_ONLY:
          if(!xjshp)
          {
            G_THROW( ERR_MSG("JB2Image.bad_number") );
          }
          add_library(shapeno, *xjshp);
          break;
        }
      // make sure everything is compacted
      // decompaction will occur automatically on cross-coding bitmaps
      if (bm)
        bm->compress();
      // add blit to image
      switch (rectype)
        {
        case NEW_MARK:
        case NEW_MARK_IMAGE_ONLY:
        case MATCHED_REFINE:
        case MATCHED_REFINE_IMAGE_ONLY:
        case NON_MARK_DATA:
          jblt->shapeno = shapeno;
        case MATCHED_COPY:
          if(!gjim)
          {
            G_THROW( ERR_MSG("JB2Image.bad_number") );
          }
          gjim->add_blit(* jblt);
          break;
        }
    }
}
Example #13
0
File: fcc.c Project: 8l/FUZIX
int main(int argc, const char *argv[]) {
  const char *p;
  char *t;
  int i;
  int ret;
  char buf[128];
  
  for(i = 1; i < argc; i++) {
    p = argv[i];
    if (*p != '-')
      add_source(p);
    else {
      switch(p[1]) {
        case 'V':
          verbose = 1;
          break;
        /* What are we doing */
        case 'c':
          mode = MODE_OBJ;
          break;
        case 'E':
          mode = MODE_CPP;
          break;
        case 'S':
          mode = MODE_ASM;
          break;
        case 'v':
          printf("fcc: front end to sdcc\n");
          add_argument("sdcc");
          add_argument("-v");
          do_command();
          exit(0);
        case 'D':
          add_macro(p);
          break;
        case 'l':
          add_library(p+2);
          break;
        case 'L':
          if (p[2] == 0)
            add_library_path(argv[++i]);
          else
            add_library_path(p+2);
          break;
        case 'I':
          if (p[2] == 0)
            add_include_path(argv[++i]);
          else
            add_include_path(p+2);
          break;
        case 'o':
          if (p[2] == 0)
            set_target(argv[++i]);
          else
            set_target(p + 2);
          break;
        case 'O':
          set_optimize(p + 2);
          break;
        case 'm':
          if (p[2] == 0)
            set_cpu(argv[++i]);
          else
            set_cpu(p + 2);
          break;
        case 'M':
          if (p[2] == 0)
            set_map(argv[++i]);
          else
            set_map(p + 2);
          break;
        case 't':
          if (p[2] == 0)
            set_platform(argv[++i]);
          else
            set_platform(p + 2);
          break;
        case 'g':
          debug = 1;
          break;
        default:
          if (strcmp(p, "-Werror") == 0)
            werror = 1;
          else if (strcmp(p, "-funsigned-char") == 0)
            unschar = 1;
          else if (strcmp(p, "--pedantic") == 0)
            pedantic = 1;
          else if (strcmp(p, "--nostdio") == 0)
            nostdio = 1;
          else {
            fprintf(stderr, "fcc: Unknown option '%s'.\n", p);
            exit(1);
          }
      }
    }
  }
  add_include_path(FCC_DIR "/include/");
  add_library_path(FCC_DIR "/lib/");
  snprintf(buf, sizeof(buf), "c%s", platform);
  add_library(buf);

  if (mode == MODE_OBJ) {
    while (srchead) {
      build_command();
      ret = do_command();
      if (ret)
        break;
      if (mode == MODE_OBJ && target) {
        char *orel = filebasename(rebuildname("", srchead->p, "rel"));
        if (rename(orel, target) == -1) {
          fprintf(stderr, "Unable to rename %s to %s.\n", orel, target);
          perror(srchead->p);
          exit(1);
        }
      }
      srchead = srchead->next;
      argp = 0;
    }
  } else {
      build_command();
      ret = do_command();
  }  
  if (mode != MODE_LINK || ret)
    exit(ret);
  argp = 0;
  add_argument("makebin");
  add_argument("-p");
  add_argument("-s");
  add_argument("65535");
  add_argument(target);
  add_argument(t = rebuildname("", target, "bin"));
  ret = do_command();
  if (ret)
    exit(ret);
  argp = 0;
  add_argument(FCC_DIR "/bin/binman");
  snprintf(buf, sizeof(buf), "%x", progbase);
  add_argument(buf);
  add_argument(t);
  add_argument(rebuildname("", target, "map"));
  add_argument(target);
  ret = do_command();
  exit(ret);
}
Example #14
0
int main(int argc, char **argv) {
#define FIND_LONG_OPTION(ARRAY) \
	{															\
		for(i = 0; i < sizeof (ARRAY) / sizeof(struct option); i++) {							\
			struct option *o = (ARRAY) + i;										\
			if(o->arg < 2) {											\
				if(strcmp(arg, o->opt) == 0) {									\
					const char *a = o->arg ? *++v : argv[0];						\
					if(o->arg && !a) {									\
						fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v);		\
						return 1;									\
					}											\
					if(o->act) o->act(a);									\
					goto first_loop;									\
				}												\
			} else {												\
				size_t len = strlen(o->opt);									\
				if(strncmp(arg, o->opt, len) == 0) {								\
					if(arg[len] && arg[len] != '=') continue;						\
					if(!arg[len] || !arg[len + 1]) {							\
						fprintf(stderr, "%s: option '%s' need an argument\n", argv[0], *v);		\
						return 1;									\
					}											\
					const char *a = arg + len + 1;								\
					if(o->act) o->act(a);									\
					goto first_loop;									\
				}												\
			}													\
		}														\
	}

#define UNRECOGNIZED_OPTION(O) \
	do {									\
		fprintf(stderr, "%s: error: unrecognized option '%s'\n",	\
			argv[0], (O));						\
		return 1;							\
	} while(0)


	int verbose = 0;
	int no_link = 0;
	int preprocess_only = -1;
	int no_warning = -1;
	int end_of_options = 0;
	const char *output_file = NULL;
	char **v = argv;
	init_argv();

	const char *vs_path = getenv("VS_PATH");
	if(!vs_path) vs_path = getenv("VSINSTALLDIR");
	if(!getenv("INCLUDE")) {
		if(vs_path) {
			size_t len = strlen(vs_path);
			if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; 
			char buffer[len + 12 + len + 24 + 1];
			memcpy(buffer, vs_path, len);
			memcpy(buffer + len, "/VC/include;", 12);
			memcpy(buffer + len + 12, vs_path, len);
			strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/include;");
			setenv("INCLUDE", buffer, 0);
		} else {
			no_warning = find_argv(argv, "-w");
			if(!no_warning) fprintf(stderr, "%s: warning: no system include path set\n", argv[0]);
		}
	}
	if(!getenv("LIB")) {
		if(vs_path) {
			size_t len = strlen(vs_path);
			if(vs_path[len - 1] == '/' || vs_path[len - 1] == '\\') len--; 
			char buffer[len + 8 + len + 20 + 1];
			memcpy(buffer, vs_path, len);
			memcpy(buffer + len, "/VC/lib;", 8);
			memcpy(buffer + len + 12, vs_path, len);
			strcpy(buffer + len + 12 + len, "/VC/PlatformSDK/lib;");
			setenv("LIB", buffer, 0);
		} else {
			if(no_warning == -1) no_warning = find_argv(argv, "-w");
			if(!no_warning) fprintf(stderr, "%s: warning: no system library path set\n", argv[0]);
		}
	}

first_loop:
	while(*++v) {
		if(!end_of_options && **v == '-') {
			int i;
			if((*v)[1] == '-') {
				const char *arg = *v + 2;
				if(!*arg) {
					end_of_options = 1;
					continue;
				}
				FIND_LONG_OPTION(double_dash_long_options);
				if(strcmp(arg, "verbose") == 0) {
					verbose = 1;
				} else UNRECOGNIZED_OPTION(*v);
			} else {
				const char *arg = *v + 1;
				FIND_LONG_OPTION(singal_dash_long_options);
				switch(*arg) {
					case 0:
						goto not_an_option;
					case 'c':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-c");
						no_link = 1;
						break;
					case 'D':
						if(arg[1]) add_to_argv(*v);
						else {
							const char *d = *++v;
							if(!d) {
								fprintf(stderr, "%s: error: macro name missing after '-D'\n",
									argv[0]);
								return 1;
							}
							define(d);
						}
						break;
					case 'E':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-E");
						preprocess_only = 1;						
						break;
					case 'f':
						if(arg[1]) set_feature(arg + 1);
						else {
							const char *feature = *++v;
							if(!feature) {
								fprintf(stderr, "%s: error: option '-f' need an argument\n",
									argv[0]);
								return -1;
							}
							set_feature(feature);
						}
						break;
					case 'g':
						// -g[coff][<level>] (level: 0~3)
						if(arg[1]) {
							const char *level = arg + 1;
							if(strncmp(level, "coff", 4) == 0) level += 4;
							if(*level && *level != '-') {
								int i = 0;
								do {
									if(!isdigit(level[i])) {
										fprintf(stderr, "%s: error: unrecognized debug output level \"%s\"\n",
											argv[0], level);
										return 1;
									}
								} while(level[++i]);
								/*
								if(i > 1 || *level > '3') {
									fprintf(stderr, "%s: error: debug output level %s is too high\n",
										argv[0], level);
									return 1;
								}
								if(*level == '0') break;
								*/
								int l = atoi(level);
								if(!l) break;
								if(l > 3) {
									fprintf(stderr, "%s: error: debug output level %s is too high\n",
										argv[0], level);
									return 1;
								}
							}
						}
						add_to_argv("-Zi");
						break;
					case 'I':
						if(no_warning == -1) no_warning = find_argv(argv, "-w");
						//if(arg[1]) add_to_argv(*v);
						if(arg[1]) add_include_path(arg + 1, no_warning);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-I' need an argument\n",
									argv[0]);
								return 1;
							}
							add_include_path(path, no_warning);
						}
						break;
					case 'L':
						if(no_warning == -1) no_warning = find_argv(argv, "-w");
						if(arg[1]) add_library_path(arg + 1, no_warning);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-L' need an argument\n",
									argv[0]);
								return 1;
							}
							add_library_path(path, no_warning);
						}
						break;
					case 'l':
						if(arg[1]) add_library(arg + 1);
						else {
							const char *path = *++v;
							if(!path) {
								fprintf(stderr, "%s: error: option '-l' need an argument\n",
									argv[0]);
								return 1;
							}
							add_library(path);
						}
						break;
					case 'M':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-showIncludes");
						break;
					case 'm':
						if(arg[1]) set_machine(arg + 1);
						else {
							const char *machine = *++v;
							if(!machine) {
								fprintf(stderr, "%s: argument to `-m' is missing\n",
									argv[0]);
								return 1;
							}
							set_machine(machine);
						}
						break;
					case 'O':
						if(arg[1]) {
							const char *o = arg + 1;
							if(strcmp(o, "0") == 0) add_to_argv("-Od");
							else if(strcmp(o, "1") == 0) add_to_argv("-O2");
							else if(strcmp(o, "3") == 0) add_to_argv("-Ox");
							else if(strcmp(o, "s") == 0) add_to_argv("-O1");
							else if(strcmp(o, "fast") == 0) add_to_argv("-O2");
							else add_to_argv(*v);
						} else add_to_argv("-O2");
						break;
					case 'o':
						if(arg[1]) output_file = arg + 1;
						else {
							output_file = *++v;
							if(!output_file) {
								fprintf(stderr, "%s: error: option '-o' need an argument\n",
									argv[0]);
								return 1;
							}
						}
						break;
					case 'P':
						if(preprocess_only == -1) preprocess_only = find_argv(argv, "-E");
						if(preprocess_only) add_to_argv("-EP");
						break;
					case 's':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						break;
					case 'U':
						if(arg[1]) add_to_argv(*v);
						else {
							const char *u = *++v;
							if(!u) {
								fprintf(stderr, "%s: error: macro name missing after '-U'\n",
									argv[0]);
								return 1;
							}
							undefine(u);
						}
						break;
					case 'v':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						verbose = 1;
						break;
					case 'W':
						if(!arg[1]) {
							if(no_warning == -1) no_warning = find_argv(argv, "-w");
							if(!no_warning) {
								fprintf(stderr, "%s: warning: option '-W' is deprecated; use '-Wextra' instead\n",
									argv[0]);
							}
							add_to_argv("-Wall");
							break;
						}
						if(strncmp(arg, "Wa,", 3) == 0 || strncmp(arg, "Wp,", 3) == 0 || strncmp(arg, "Wl,", 3) == 0) {
							(*v)[3] = 0;		// XXX
							fprintf(stderr, "%s: warning: option '%s' is not supported\n", argv[0], *v);
							break;
						} 
						if(set_warning(arg + 1)) break;
						add_to_argv(*v);
						break;
					case 'w':
						if(arg[1]) UNRECOGNIZED_OPTION(*v);
						add_to_argv("-w");
						no_warning = 1;
						break;
					case 'x':
						if(arg[1]) set_language(arg + 1);
						else {
							const char *lang = *++v;
							if(!lang) {
								fprintf(stderr, "%s: error: missing argument to ‘-x’",
									argv[0]);
								return 4;
							}
							set_language(lang);
						}
						break;
					default:
						fprintf(stderr, "%s: error: unrecognized option '%s'\n", argv[0], *v);
						return 1;
				}
			}
		} else {
not_an_option:
#if defined __INTERIX && !defined _NO_CONV_PATH
			if(**v == '/') {
				char buffer[PATH_MAX + 1];
				if(unixpath2win(*v, 0, buffer, sizeof buffer) == 0) {
					add_input_file(buffer);
				} else {
					if(no_warning == -1) no_warning = find_argv(argv, "-w");
					if(!no_warning) {
						fprintf(stderr, "%s: warning: cannot convert '%s' to Windows path name, %s\n",
							argv[0], *v, strerror(errno));
					}
					add_input_file(*v);
				}
			} else
#endif
			add_input_file(*v);
		}
	}
	setvbuf(stdout, NULL, _IOLBF, 0);
	if(preprocess_only == -1) preprocess_only = 0;
	if(no_warning == -1) no_warning = 0;
	if(last_language && last_language_unused && !no_warning) {
		fprintf(stderr, "%s: warning: '-x %s' after last input file has no effect\n", argv[0], last_language);
	}
	if(!first_input_file) {
		if(verbose) {
			if(!no_link) add_to_argv("-c");
			start_cl();
			return 0;
		}
		fprintf(stderr, "%s: no input files\n", argv[0]);
		return 1;
	}
	if(multiple_input_files && (preprocess_only || no_link)) {
		if(output_file) {
			fprintf(stderr, "%s: error: cannot specify -o with -c or -E with multiple files\n", argv[0]);
			return 4;
		} else if(no_link) {
			fprintf(stderr, "%s: error: '-c' with multiple files is currently not supported\n", argv[0]);
			return -1;
		}
	}
	if(!output_file && !preprocess_only) {
		if(no_link) {
			size_t len = strlen(first_input_file);
			int n = get_last_dot(first_input_file, len);
			if(n >= 0) len = n;
			char *p = malloc(len + 3);
			if(!p) {
				perror(argv[0]);
				return 1;
			}
			memcpy(p, first_input_file, len);
			strcpy(p + len, ".o");
			output_file = p;
		} else output_file = DEFAULT_OUTPUT_FILENAME;
	}
	if(!verbose) add_to_argv("-nologo");
	if(preprocess_only) {
		if(output_file) target.name = output_file;
		target.type = PREPROCESSED_SOURCE;
	} else set_output_file(output_file, no_link, no_warning);
	//if(no_static_link) add_to_argv("-MD");
	add_to_argv(no_static_link ? "-MD" : "-MT");
	add_libraries_to_argv();
	if(verbose) print_argv();
	return start_cl();
}
Example #15
0
int main(int argc, char ** argv)
{
    char * outname = "aout.rdf";
    int  moduleloaded = 0;

    options.verbose = 0;
    options.align = 16;
    options.warnUnresolved = 0;
    options.strip = 0;
    
    argc --, argv ++;
    if (argc == 0) usage();
    while (argc && **argv == '-' && argv[0][1] != 'l')
    {
	switch(argv[0][1]) {
	case 'r':
	    printf("ldrdf (linker for RDF files) version " LDRDF_VERSION "\n");
	    printf( _RDOFF_H "\n");
	    exit(0);
	case 'v':
	    if (argv[0][2] == '=') {
		options.verbose = argv[0][3] - '0';
		if (options.verbose < 0 || options.verbose > 9) {
		    fprintf(stderr, "ldrdf: verbosity level must be a number"
			    " between 0 and 9\n");
		    exit(1);
		}
	    }
	    else
		options.verbose++;
	    break;
	case 'a':
	    options.align = atoi(argv[1]);
	    if (options.align <= 0) {
		fprintf(stderr, 
			"ldrdf: -a expects a positive number argument\n");
		exit(1);
	    }
	    argv++, argc--;
	    break;
	case 's':
	    options.strip = 1;
	    break;
	case 'x':
	    options.warnUnresolved = 1;
	    break;
	case 'o':
	    outname = argv[1];
	    argv++, argc--;
	    break;
	default:
	    usage();
	}
	argv++, argc--;
    }

    if (options.verbose > 4) {
	printf("ldrdf invoked with options:\n");
	printf("    section alignment: %d bytes\n", options.align);
	printf("    output name: `%s'\n", outname);
	if (options.strip)
	    printf("    strip symbols\n");
	if (options.warnUnresolved)
	    printf("    warn about unresolved symbols\n");
	printf("\n");
    }

    symtab = symtabNew();
    initsegments();

    if (!symtab) {
	fprintf(stderr, "ldrdf: out of memory\n");
	exit(1);
    }

    while (argc)
    {
	if (!strncmp(*argv, "-l", 2)) /* library */
	    add_library(*argv + 2);
	else {
	    loadmodule(*argv);
	    moduleloaded = 1;
	}
	argv++, argc--;
    }

    if (! moduleloaded) {
	printf("ldrdf: nothing to do. ldrdf -h for usage\n");
	return 0;
    }

    
    search_libraries();

    if (options.verbose > 2)
    {
	printf ("symbol table:\n");
	symtabDump(symtab, stdout);
    }

    write_output(outname);

    if (errorcount > 0)
	exit(1);

    return 0;
}