当前位置: 首页>>代码示例>>C++>>正文


C++ rindex函数代码示例

本文整理汇总了C++中rindex函数的典型用法代码示例。如果您正苦于以下问题:C++ rindex函数的具体用法?C++ rindex怎么用?C++ rindex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了rindex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main (int argc, char *argv[])
   {
      stat   *a,*b;
      hit     h;
      int     p[FIELDS];
      char    str[256], str_last[256];
      char   *s;

      int     i, j, w, c, len = 0;
      idtype     id, threshold, sizelog = SIZELOG;
      

      a = (stat *) malloc ( sizeof (stat) * 1 << sizelog );
      b = (stat *) malloc ( sizeof (stat) * 1 << sizelog );

      threshold = atol ( argv[1] );

      while ( gets (str) )
	 {
	    s = rindex (str, ' ') + 1;
	    
	    str [ s - str - 1 ] = '\0';

	    readhit (str, &h);
	    c = atol (s);

	    if ( c < threshold ) lcheck (&h);

	    id = getid ( &h );

	    if ( !len ) 
	       { 
		  a[0].n = id; 
		  a[0].c = c; 

		  len++; 
	       }
	    else 
	       {
		  w = bfind (a, id, len);

		  if ( w == len )
		    {
		      a[w].n = id;
		      a[w].c = c;

		      len++;
		    }
		  else if ( a[w].n == id ) a[w].c+=c;
		  else 
		    {
		      memcpy ((char *)b, (char *)a + w * sizeof(stat), (len - w) * sizeof(stat));
		      a[w].n = id;
		      a[w].c = c;

		      memcpy ((char *)a + (w + 1) * sizeof(stat), (char *)b, (len - w) * sizeof(stat)); 

		      len++;
		      /*fprintf (stderr, "%d\n", len);*/
/*
		      if ( len == 2 << sizelog )
			{
			  sizelog++;
			  a = (stat *) realloc ( a, sizeof (stat) * 1 << sizelog );
			  b = (stat *) realloc ( b, sizeof (stat) * 1 << sizelog );
			}
 */
		    }
		}
	  }


      for ( i = 0; i < len; i++ )
	 {
	    unpackid (a[i].n, &h);

	    printf ("%d", h.i[0]);

	    for ( j = 1; j < FIELDS; j++ )
	       printf ("_%d", h.i[j]);

	    printf (" %d\n", a[i].c);
	 }

      return 0;

   }
开发者ID:ffzg,项目名称:PhiloLogic3,代码行数:87,代码来源:optimizer.c

示例2: newsyntax

void
newsyntax(rtems_shell_hexdump_globals* globals, int argc, char ***argvp)
{
	int ch;
	char *p, **argv;

  struct getopt_data getopt_reent;
  memset(&getopt_reent, 0, sizeof(getopt_data));

	argv = *argvp;
	if ((p = rindex(argv[0], 'h')) != NULL &&
	    strcmp(p, "hd") == 0) {
		/* "Canonical" format, implies -C. */
		add(globals, "\"%08.8_Ax\n\"");
		add(globals, "\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
		add(globals, "\"  |\" 16/1 \"%_p\" \"|\\n\"");
	}
	while ((ch = getopt_r(argc, argv, "bcCde:f:n:os:vx", &getopt_reent)) != -1)
		switch (ch) {
		case 'b':
			add(globals, "\"%07.7_Ax\n\"");
			add(globals, "\"%07.7_ax \" 16/1 \"%03o \" \"\\n\"");
			break;
		case 'c':
			add(globals, "\"%07.7_Ax\n\"");
			add(globals, "\"%07.7_ax \" 16/1 \"%3_c \" \"\\n\"");
			break;
		case 'C':
			add(globals, "\"%08.8_Ax\n\"");
			add(globals, "\"%08.8_ax  \" 8/1 \"%02x \" \"  \" 8/1 \"%02x \" ");
			add(globals, "\"  |\" 16/1 \"%_p\" \"|\\n\"");
			break;
		case 'd':
			add(globals, "\"%07.7_Ax\n\"");
			add(globals, "\"%07.7_ax \" 8/2 \"  %05u \" \"\\n\"");
			break;
		case 'e':
			add(globals, getopt_reent.optarg);
			break;
		case 'f':
			addfile(globals, getopt_reent.optarg);
			break;
		case 'n':
			if ((length = atoi(getopt_reent.optarg)) < 0)
				errx(exit_jump, 1, "%s: bad length value", getopt_reent.optarg);
			break;
		case 'o':
			add(globals, "\"%07.7_Ax\n\"");
			add(globals, "\"%07.7_ax \" 8/2 \" %06o \" \"\\n\"");
			break;
		case 's':
			if ((skip = strtoll(getopt_reent.optarg, &p, 0)) < 0)
				errx(exit_jump, 1, "%s: bad skip value", getopt_reent.optarg);
			switch(*p) {
			case 'b':
				skip *= 512;
				break;
			case 'k':
				skip *= 1024;
				break;
			case 'm':
				skip *= 1048576;
				break;
			}
			break;
		case 'v':
			vflag = ALL;
			break;
		case 'x':
			add(globals, "\"%07.7_Ax\n\"");
			add(globals, "\"%07.7_ax \" 8/2 \"   %04x \" \"\\n\"");
			break;
		case '?':
			usage(globals);
		}

	if (!fshead) {
		add(globals, "\"%07.7_Ax\n\"");
		add(globals, "\"%07.7_ax \" 8/2 \"%04x \" \"\\n\"");
	}

	*argvp += getopt_reent.optind;
}
开发者ID:FullMentalPanic,项目名称:RTEMS_NEW_TOOL_CHAIN,代码行数:83,代码来源:hexsyntax.c

示例3: _xcgroup_cpuset_init

/* when cgroups are configured with cpuset, at least
 * cpuset.cpus and cpuset.mems must be set or the cgroup
 * will not be available at all.
 * we duplicate the ancestor configuration in the init step */
static int _xcgroup_cpuset_init(xcgroup_t* cg)
{
	int fstatus,i;

	char* cpuset_metafiles[] = {
		"cpus",
		"mems"
	};
	char cpuset_meta[PATH_MAX];
	char* cpuset_conf;
	size_t csize;

	xcgroup_t acg;
	char* acg_name;
	char* p;

	fstatus = XCGROUP_ERROR;

	/* load ancestor cg */
	acg_name = (char*) xstrdup(cg->name);
	p = rindex(acg_name,'/');
	if (p == NULL) {
		debug2("task/cgroup: unable to get ancestor path for "
		       "cpuset cg '%s' : %m",cg->path);
		return fstatus;
	} else
		*p = '\0';
	if (xcgroup_load(cg->ns,&acg, acg_name) != XCGROUP_SUCCESS) {
		debug2("task/cgroup: unable to load ancestor for "
		       "cpuset cg '%s' : %m",cg->path);
		return fstatus;
	}

	/* inherits ancestor params */
	for (i = 0 ; i < 2 ; i++) {
	again:
		snprintf(cpuset_meta, sizeof(cpuset_meta), "%s%s",
			 cpuset_prefix, cpuset_metafiles[i]);
		if (xcgroup_get_param(&acg,cpuset_meta,
				      &cpuset_conf,&csize)
		    != XCGROUP_SUCCESS) {
			if (!cpuset_prefix_set) {
				cpuset_prefix_set = 1;
				cpuset_prefix = "cpuset.";
				goto again;
			}

			debug("task/cgroup: assuming no cpuset cg "
			       "support for '%s'",acg.path);
			xcgroup_destroy(&acg);
			return fstatus;
		}
		if (csize > 0)
			cpuset_conf[csize-1]='\0';
		if (xcgroup_set_param(cg,cpuset_meta,cpuset_conf)
		    != XCGROUP_SUCCESS) {
			debug("task/cgroup: unable to write %s configuration "
			       "(%s) for cpuset cg '%s'",cpuset_meta,
			       cpuset_conf,cg->path);
			xcgroup_destroy(&acg);
			xfree(cpuset_conf);
			return fstatus;
		}
		xfree(cpuset_conf);
	}

	xcgroup_destroy(&acg);
	return XCGROUP_SUCCESS;
}
开发者ID:kwangiit,项目名称:SLURMPP,代码行数:73,代码来源:task_cgroup_cpuset.c

示例4: si_emu_libopencl_redirect

/* If 'fullpath' points to the original OpenCL library, redirect it to 'm2s-opencl.so'
 * in the same path. */
void si_emu_libopencl_redirect(struct x86_ctx_t *ctx, char *full_path, int size)
{
	char fullpath_original[MAX_PATH_SIZE];
	char buf[MAX_PATH_SIZE];
	char *relpath, *filename;
	int length;
	FILE *f;

	/* Get path length */
	snprintf(fullpath_original, sizeof fullpath_original, "%s", full_path);
	length = strlen(full_path);
	relpath = rindex(full_path, '/');
	assert(relpath && *relpath == '/');
	filename = relpath + 1;

	/* Detect an attempt to open 'libm2s-opencl' and record it */
	if (!strcmp(filename, "libm2s-opencl.so"))
	{
		/* Attempt to open original location */
		f = fopen(full_path, "r");
		if (f)
		{
			fclose(f);
			ctx->libopencl_open_attempt = 0;
		}
		else
		{
			/* Attempt to open 'libm2s-openc.so' in current directory */
			if (!getcwd(buf, MAX_PATH_SIZE))
				fatal("%s: cannot get current directory", __FUNCTION__);
			sprintf(full_path, "%s/libm2s-opencl.so", buf);
			f = fopen(full_path, "r");
			if (f)
			{
				fclose(f);
				warning("path '%s' has been redirected to '%s'\n"
					"\tYour application is trying to access the Multi2Sim OpenCL library. A copy of\n"
					"\tthis library has been found in the current working directory, and this copy\n"
					"\twill be used in the linker. To avoid this message, please link your program\n"
					"\tstatically. See the Multi2Sim Guide for further details (www.multi2sim.org).\n",
					fullpath_original, full_path);
				ctx->libopencl_open_attempt = 0;
			}
			else
			{
				/* Attemps failed, record this. */
				ctx->libopencl_open_attempt = 1;
			}
		}
	}

	/* Translate libOpenCL -> libm2s-opencl */
	if (!strcmp(filename, "libOpenCL.so") || !strncmp(filename, "libOpenCL.so.", 13))
	{
		/* Translate name in same path */
		full_path[length - 13] = '\0';
		snprintf(buf, MAX_STRING_SIZE, "%s/libm2s-opencl.so", full_path);
		strncpy(full_path, buf, size);
		f = fopen(full_path, "r");

		/* If attempt failed, translate name into current working directory */
		if (!f)
		{
			if (!getcwd(buf, MAX_PATH_SIZE))
				fatal("%s: cannot get current directory", __FUNCTION__);
			sprintf(full_path, "%s/libm2s-opencl.so", buf);
			f = fopen(full_path, "r");
		}

		/* End of attempts */
		if (f)
		{
			fclose(f);
			warning("path '%s' has been redirected to '%s'\n"
				"\tYour application is trying to access the default OpenCL library, which is being\n"
				"\tredirected by Multi2Sim to its own provided library. Though this should work,\n"
				"\tthe safest way to simulate an OpenCL program is by linking it initially with\n"
				"\t'libm2s-opencl.so'. See the Multi2Sim Guide for further details (www.multi2sim.org).\n",
				fullpath_original, full_path);
			ctx->libopencl_open_attempt = 0;
		}
		else
		{
			ctx->libopencl_open_attempt = 1;
		}
	}
}
开发者ID:filippo-ceid,项目名称:multi2sim,代码行数:89,代码来源:emu.c

示例5: mb_create

/*******************************************
 * API - create a new service mailbox
 * A mailbox is created in SRV_INIT state
 *
 * IN:
 *  name - tag name of the mailbox
 *  size - size of the mailbox
 *******************************************/
mb_id_t
mb_create(const char* tag,
          size_t size)
{
    mb_handle_t* mbhdl;
    mb_hdr_t*    mbhdr;
    char         mbname[MAXPATHLEN];
    char*        ptag;
    const char   c = 0;

    /*
     * bad tag name length 
    */
    if (strlen(tag) >= MAILBOX_TAG_MAXLEN) {
        return (MB_INVALID_ID);
    }

    /*
     * Try to allocate the mailbox handle
     */
    mbhdl = (mb_handle_t*) malloc(sizeof(mb_handle_t));
    if (mbhdl == NULL) {
        return (MB_INVALID_ID);
    }

    /*
     * Create the corresponding tmpfs file
     */
 
    /* Create the mailbox file */
    
    snprintf(mbname, sizeof(mbname), "%s/%s",
             MAILBOX_PATH, tag);
    mbhdl->fd = open(mbname, O_RDWR | O_CREAT | O_TRUNC, MAILBOX_MODE);
    if (mbhdl->fd == -1) {
        free(mbhdl);
        return(MB_INVALID_ID);
    }
    size += sizeof(mb_hdr_t);
    lseek(mbhdl->fd, size - 1, SEEK_SET);
    write(mbhdl->fd, &c, 1);

    /*
     * Map the mailbox in caller address space
     */
    mbhdl->maddr = mmap(NULL,
                        size,
                        PROT_READ | PROT_WRITE,
                        MAP_SHARED,
                        mbhdl->fd,
                        0);

    if (mbhdl->maddr == MAP_FAILED) {
        close(mbhdl->fd);
        free(mbhdl);
        (void) unlink(mbname);
        return (MB_INVALID_ID);
    }

    /*
     * Initialize mailbox header
     */
    mbhdr = (mb_hdr_t*) mbhdl->maddr;
    mbhdl->valid     = MB_VALID;
    mbhdl->flags     = MB_CREATOR;
    mbhdr->version   = MAILBOX_VER;
    mbhdr->ttSize    = size;
    mbhdr->usrClbk   = NULL;
    mbhdr->curState  = SRV_INIT;
    mbhdr->rqstState = SRV_INVALID;

    ptag = rindex(mbname, '/');
    if (ptag == NULL) {
        ptag = mbname;
    }
    strncpy(mbhdr->mboxTag, ptag, sizeof(mbhdr->mboxTag));

    /* multicast this mailbox */
    _mb_net_send(mbhdr);

    return (mb_id_t) (mbhdl);
}
开发者ID:elambert,项目名称:honeycomb,代码行数:90,代码来源:mbox.c

示例6: main


//.........这里部分代码省略.........
    /* Note: Could potentially handle input from stdin, but currently just deal with value_matches */

    ndivs = IIT_ndivs(iit);
    for (i = 0; i < n_value_matches; i++) {
      debug(printf("\nindex = %d\n",matches[i]));
      print_interval(&lastcoord,/*total*/0,/*divstring*/NULL,/*coordstart*/0,/*coordend*/0,
		     value_matches[i],iit,ndivs,fieldint);
    }
    
    FREE(value_matches);
    IIT_free(&iit);
    return 0;

  } else if (argc == 2) {
    debug(printf("Running under argc 2\n"));
    /* Expecting input from stdin */
      
    if ((iit = IIT_read(filename,NULL,true,/*divread*/READ_ALL,/*divstring*/NULL,/*add_iit_p*/true,
			/*labels_read_p*/true)) == NULL) {
      if (Access_file_exists_p(filename) == false) {
	fprintf(stderr,"Cannot read file %s\n",filename);
      } else {
	fprintf(stderr,"File %s appears to be an invalid IIT file\n",filename);
      }
      exit(9);
    } else if (fieldstring != NULL) {
      if ((fieldint = IIT_fieldint(iit,fieldstring)) < 0) {
	fprintf(stderr,"No field %s defined in iit file.\n",fieldstring);
	exit(9);
      }
    }
	
    while (fgets(Buffer,BUFLEN,stdin) != NULL) {
      if ((ptr = rindex(Buffer,'\n')) != NULL) {
	*ptr = '\0';
      }
      strcpy(nocomment,Buffer);
      if ((ptr = rindex(nocomment,'#')) != NULL) {
	*ptr = '\0';
      }

      skipp = false;

      if ((nargs = sscanf(nocomment,"%s %s",query,typestring)) == 2) {
	debug(printf("typestring is %s\n",typestring));
	matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			      &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			      query,typestring,&iit,filename);
	coordstart = (Chrpos_T) univ_coordstart;
	coordend = (Chrpos_T) univ_coordend;

      } else if (nargs == 1) {
	debug(printf("typestring is NULL\n"));
	matches = get_matches(&nmatches,&divstring,&univ_coordstart,&univ_coordend,
			      &leftflanks,&nleftflanks,&rightflanks,&nrightflanks,
			      query,/*typestring*/NULL,&iit,filename);
	coordstart = (Chrpos_T) univ_coordstart;
	coordend = (Chrpos_T) univ_coordend;

      } else {
	fprintf(stderr,"Can't parse line %s.  Ignoring.\n",nocomment);
	skipp = true;
      }
	
      total = 0;
      if (skipp == false) {
开发者ID:djinnome,项目名称:JAMg-1,代码行数:67,代码来源:iit_get.c

示例7: printf

//
// Save()
//
// Save values from cache to file
//
void
CPreferenceFile::Save()
{
#ifdef DEBUG
   printf("CPreferenceFile::Save() %s\n", fModified?"Modified":"Not Modified");
   dumpList(m_list);
#endif

   if (fModified)
   {
      FILE *in;
      FILE *out;
      char msg[MAXLEN];
      char *p;
      int count = 0;
      bool bQuoted = FALSE;
      bool bSaved = FALSE;
 
      // Open source and destination files
      char *outfilename = NULL;
      const char *infilename = fFileName;

      outfilename = (char *) malloc(strlen(infilename) + 64);
      sprintf(outfilename, "%s%s", fFileName, ".new");
      in = fopen (infilename, "r");
      out = fopen (outfilename, "w+");
      if (in == 0)
      {
         fprintf (stderr, "Couldn't open current config file. '%s' - %s\n",
           infilename, strerror(errno));
      }
      if (out == 0)
      {
         fprintf (stderr, "Couldn't open new config file. '%s' - %s\n",
           outfilename, strerror(errno));
      }
      else
      {
         char *sType = NULL;

         // build a copy of all the args we want to save
         CPreferenceList *pTempList = new QList<CPrefItem>;
         CPrefItem *pref;
         for( pref = m_list->first(); pref != 0; pref=m_list->next() )
         {
            if (pref->Persistent())
              pTempList->append(pref);
         }
#ifdef DEBUGSAVE
printf("CPreferenceFile::Save() Saving list:\n");
dumpList(pTempList);
#endif

         if (in)
         {
           // Parse source file
           while (fgets (msg, sizeof(msg), in) != NULL)
           {
              // terminate on CF or LF 
              p = index (msg, '\n');
              if (p)
                *p = 0;
              p = index (msg, '\r');
              if (p)
                *p = 0;
                                       
              // end of section - dump all items left in list that belong here
              if (sType && !msg[0])
              {
                bool bRemoved;
                do
                {
                  bRemoved = FALSE;
                  // done copying filters that existed in file already
                  // dump whatever is left in list
                  for( pref = pTempList->first(); pref != 0; pref = pTempList->next() )
                  {
                     char *tempStr = strdup(pref->Identifier());
//                     p = index(tempStr, '_');
                     p = rindex(tempStr, '_');
                     if (p)
                       *p++ = 0;
                     if (!strcasecmp(sType, tempStr))
                     {
                        struct timeval tv;
                        if (!gettimeofday(&tv, NULL))
                           fprintf(out, "%s\t%s\t# Added %s", p, pref->Text(), 
                               ctime(&tv.tv_sec));
                        else
                           fprintf(out, "%s\t%s\t# Added\n", p,pref->Text());
#ifdef DEBUGSAVE
  fprintf(stdout, "CPreferenceFile::Save(): '%s\t%s' - added\n", 
         pref->Identifier(), pref->Text());
#endif
                        count++;
//.........这里部分代码省略.........
开发者ID:xbackupx,项目名称:showeqx,代码行数:101,代码来源:cpreferences.cpp

示例8: main

int 
main (int argc, char **argv, char **envp)
{
	char  *cp,
			 *sp;

	 fprintf (stderr, "%s\n", rosyversion);

	sysout[0] = sysdef[0] = systbl[0] = systub[0] = NULL;
	for (argc--, argv++; argc > 0; argc--, argv++) {
		cp = *argv;

		if (strcmp (cp, "-pepsy") == 0) {
			Pepsyflag++;
			continue;
		}
		if (strcmp (cp, "-defs") == 0) {
			Defsflag++;
			continue;
		}
		if (strcmp (cp, "-d") == 0) {
			dflag++;
			continue;
		}
		if (strcmp (cp, "-m") == 0) {
			mflag++;
			continue;
		}
		if (strcmp (cp, "-o") == 0) {
			if (sysout[0]) {
				 fprintf (stderr, "too many output files\n");
				exit (1);
			}
			argc--, argv++;
			if ((cp = *argv) == NULL || (*cp == '-' && cp[1] != NULL))
				goto usage;
			 strcpy (sysout, cp);

			continue;
		}
		if (strcmp (cp, "-b") == 0) {
			if (bflag) {
				 fprintf (stderr, "too many prefixes\n");
				exit (1);
			}
			argc--, argv++;
			if ((bflag = *argv) == NULL || *bflag == '-')
				goto usage;
			continue;
		}
		if (strcmp (cp, "-s") == 0) {
			sflag++;
			continue;
		}
		if (strcmp (cp, "-T") == 0) {
			if (mymodulename) {
				 fprintf (stderr, "too many table names\n");
				exit (1);
			}
			argc --;
			argv ++;
			if ((mymodulename = *argv) == NULL || *mymodulename == '-')
				goto usage;
			continue;
		}
		if (strcmp (cp, "-O") == 0) {
			argc --;
			argv ++;
			if ((cp = *argv) == NULL || (*cp == '-'))
				goto usage;
			if (oplistorig[0])
				 strcat (oplistorig, cp);
			else
				 strcpy (oplistorig, cp);
			continue;
		}

		if (sysin) {
usage:
			;
			 fprintf (stderr,
							"usage: rosy [-pepsy] [-d] [-o module.py] [-s] module.ry\n");
			exit (1);
		}

		if (*cp == '-') {
			if (*++cp != NULL)
				goto usage;
			sysin = "";
		}
		sysin = cp;

		if (sysout[0])
			continue;
		if (sp = rindex (cp, '/'))
			sp++;
		if (sp == NULL || *sp == NULL)
			sp = cp;
		sp += strlen (cp = sp) - 3;
		if (sp > cp && strcmp (sp, ".ry") == 0)
//.........这里部分代码省略.........
开发者ID:Kampbell,项目名称:isode-8.0,代码行数:101,代码来源:rosy.c

示例9: is_llvm_bitcode_from_memory

/*
 * is_llvm_bitcode_from_memory() is passed a pointer and size of a memory
 * buffer, a pointer to an arch_flag struct and an pointer to return the lto
 * module if not NULL.  If it the memory is an llvm bit code it returns 1 and
 * sets the fields in the arch flag.  If pmod is not NULL it stores the lto
 * module in their, if not it frees the lto module.  If the memory buffer is
 * not an llvm bit code it returns 0.
 */
__private_extern__ int is_llvm_bitcode_from_memory(
char *addr,
uint32_t size,
struct arch_flag *arch_flag,
void **pmod) /* maybe NULL */
{

   uint32_t bufsize;
   char *p, *prefix, *lto_path, buf[MAXPATHLEN], resolved_name[PATH_MAX];
   int i;
   void *mod;

	/*
	 * The libLTO API's can't handle empty files.  So return 0 to indicate
	 * this is not a bitcode file if it has a zero size.
	 */
	if(size == 0)
	    return(0);

	if(tried_to_load_lto == 0){
	    tried_to_load_lto = 1;
	    /*
	     * Construct the prefix to this executable assuming it is in a bin
	     * directory relative to a lib directory of the matching lto library
	     * and first try to load that.  If not then fall back to trying
	     * "/Applications/Xcode.app/Contents/Developer/Toolchains/
	     * XcodeDefault.xctoolchain/usr/lib/libLTO.dylib".
	     */
	    bufsize = MAXPATHLEN;
	    p = buf;
	    i = _NSGetExecutablePath(p, &bufsize);
	    if(i == -1){
		p = allocate(bufsize);
		_NSGetExecutablePath(p, &bufsize);
	    }
	    prefix = realpath(p, resolved_name);
	    p = rindex(prefix, '/');
	    if(p != NULL)
		p[1] = '\0';
	    lto_path = makestr(prefix, "../lib/libLTO.dylib", NULL);

	    lto_handle = dlopen(lto_path, RTLD_NOW);
	    if(lto_handle == NULL){
		free(lto_path);
		lto_path = NULL;
		lto_handle = dlopen("/Applications/Xcode.app/Contents/"
				    "Developer/Toolchains/XcodeDefault."
				    "xctoolchain/usr/lib/libLTO.dylib",
				    RTLD_NOW);
	    }
	    if(lto_handle == NULL)
		return(0);

	    lto_is_object = dlsym(lto_handle,
				  "lto_module_is_object_file_in_memory");
	    lto_create = dlsym(lto_handle, "lto_module_create_from_memory");
	    lto_create_local = dlsym(lto_handle,
				     "lto_module_create_in_local_context");
	    lto_dispose = dlsym(lto_handle, "lto_module_dispose");
	    lto_get_target = dlsym(lto_handle, "lto_module_get_target_triple");
	    lto_get_num_symbols = dlsym(lto_handle,
					"lto_module_get_num_symbols");
	    lto_get_sym_attr = dlsym(lto_handle,
				     "lto_module_get_symbol_attribute");
	    lto_get_sym_name = dlsym(lto_handle, "lto_module_get_symbol_name");

	    if(lto_is_object == NULL ||
	       lto_create == NULL ||
	       lto_dispose == NULL ||
	       lto_get_target == NULL ||
	       lto_get_num_symbols == NULL ||
	       lto_get_sym_attr == NULL ||
	       lto_get_sym_name == NULL){
		dlclose(lto_handle);
		if(lto_path != NULL)
		    free(lto_path);
		return(0);
	    }
	}
	if(lto_handle == NULL)
	    return(0);
	    
	if(!lto_is_object(addr, size))
	    return(0);
	
	if(lto_create_local)
	    mod = lto_create_local(addr, size, "is_llvm_bitcode_from_memory");
	else
	    mod = lto_create(addr, size);
	if(mod == NULL)
	    return(0);

//.........这里部分代码省略.........
开发者ID:KubaKaszycki,项目名称:cctools,代码行数:101,代码来源:lto.c

示例10: os_process_arguments


//.........这里部分代码省略.........
    if (optind != argc - 1) {
	printf("FROTZ V%s\t", VERSION);
#ifdef OSS_SOUND
	printf("oss sound driver, ");
#endif

#ifdef USE_NCURSES
	printf("ncurses interface.");
#else
	printf("curses interface.");
#endif
	putchar('\n');

	puts (INFORMATION);
	printf ("\t-Z # error checking mode (default = %d)\n"
	    "\t     %d = don't report errors   %d = report first error\n"
	    "\t     %d = report all errors     %d = exit after any error\n\n",
	    ERR_DEFAULT_REPORT_MODE, ERR_REPORT_NEVER,
	    ERR_REPORT_ONCE, ERR_REPORT_ALWAYS,
	    ERR_REPORT_FATAL);
	exit (1);
    }

    /* This section is exceedingly messy and really can't be fixed
       without major changes all over the place.
     */

    /* Save the story file name */

    f_setup.story_file = strdup(argv[optind]);
    f_setup.story_name = strdup(basename(argv[optind]));

    /* Now strip off the extension. */
    p = rindex(f_setup.story_name, '.');
    if ((p != NULL) &&
        ((strcmp(p,EXT_BLORB2) == 0) ||
         (strcmp(p,EXT_BLORB3) == 0) ||
         (strcmp(p,EXT_BLORB4) == 0) ) )
    {
        blorb_ext = strdup(p);
    }
    else
    {
        blorb_ext = strdup(EXT_BLORB);
    }

    /* Get rid of extensions with 1 to 6 character extensions. */
    /* This will take care of an extension like ".zblorb". */
    /* More than that, there might be something weird going on */
    /* which is not our concern. */
    if (p != NULL) {
        if (strlen(p) >= 2 && strlen(p) <= 7) {
                *p = '\0';      /* extension removed */
        }
    }

    f_setup.story_path = strdup(dirname(argv[optind]));

    /* Create nice default file names */

    u_setup.blorb_name = malloc(FILENAME_MAX * sizeof(char));
    strncpy(u_setup.blorb_name, f_setup.story_name,
	strlen(f_setup.story_name) +1);
    strncat(u_setup.blorb_name, blorb_ext, strlen(blorb_ext));

    u_setup.blorb_file = malloc(strlen(f_setup.story_path) *
开发者ID:ZoeB,项目名称:frotz,代码行数:67,代码来源:ux_init.c

示例11: main

int main(void)
{
	int lfd, cfd, i, n;
	struct sockaddr_in serv_addr;

	lfd = socket(AF_INET, SOCK_STREAM, 0);

	memset(&serv_addr, 0, sizeof(serv_addr));
	serv_addr.sin_family = AF_INET;
	serv_addr.sin_port = htons(SERV_PORT);
	inet_pton(AF_INET, SERV_IP, &serv_addr.sin_addr.s_addr);

	bind(lfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr));
	if(n == -1)
		sys_err("bind error");
	listen(lfd, 20);

	while(1){
		cfd = accept(lfd, NULL, NULL);
		if(cfd ==-1)
			sys_err("accept error");
		char buf[1024], path[1024],tmp[1024];
		int fd;
		char *p,*q;
		char *filename;

		n = read(cfd, buf, 1024);
		buf[n] = '\0';
		strcpy(tmp,buf);
#if 1
		p = strstr(buf,":");
		if(p != NULL)
		{      /*download file from server*/
			filename = p+2;
#endif
			sprintf(path, "/%s",filename);

			fd = open(path, O_RDONLY);
			if(fd == -1)
				exit(1);
			while(n = read(fd, buf, 1024))
				write(cfd, buf, n);
			close(cfd);
		}
		else
		{      /*upload file to server*/
			write(cfd,"ok",3);
			q = rindex(tmp,'/');

			n = read(cfd,buf,1024);
			buf[n] = '\0';
			sprintf(path,"%s%s",buf,q);
		//	printf("path:%s\n",path);

			write(cfd,"ok",3);

			fd = open(path,O_WRONLY | O_CREAT | O_TRUNC ,0644);
			if(fd == -1)
			{
				sys_err("open error");
			}
			while(n = read(cfd,buf,1024))
				write(fd,buf,n);

			close(cfd);
			close(fd);
		}
	}
	return 0;
}
开发者ID:wxiaodong0829,项目名称:aka_edu_learned,代码行数:70,代码来源:server.c

示例12: do_get

int do_get(const char *src, const char *dst, int sock_fd)
{
	char *dst_file; 
	char *p;
	struct stat statbuf; 
	int n, fd;
	char buf[MAX_LINE]; 
	int len;
	int res = -1; 
	
	if(src == NULL || dst == NULL){ 
		printf("wrong command\n"); 
		return -1;
	}
	
	if(src[strlen(src)-1]=='/'){
		printf("source file should be a regular file\n");
		return -1;
	}
	
   	if( (dst_file = (char *)malloc(strlen(dst) + strlen(src))) == NULL){ 
		perror("fail to malloc");
		return -1; 
	}
    
	strcpy(dst_file, dst); 
	if(dst_file[strlen(dst_file) - 1] != '/')
		strcat(dst_file, "/");
	p = rindex(src, '/'); 
    	strcat(dst_file, p + 1);  
	    	
	if((fd = open(dst_file, O_WRONLY | O_CREAT | O_TRUNC, 0644)) == -1){
	  	perror("fail to open dst-file");
	  	goto end2;
    	}
 
    	if(fstat(fd, &statbuf) == -1){ /* 取目标文件的文件状态 */
		perror("fail to stat dst-file");
	  	goto end1;
	}
	
	if(!S_ISREG(statbuf.st_mode)){
	  	printf("dst-file should be a regular file");
	  	goto end1;
	}

    	sprintf(buf, "GET %s", src); 
    	
	if(my_write(sock_fd, buf, strlen(buf)+1) == -1) 
		goto end1;
    	
	if( (n = my_read(sock_fd, buf, MAX_LINE)) <= 0){ 
		goto end1;
    	}
    	
	if(buf[0] == 'E'){ 
		write(STDOUT_FILENO, buf, n); 
	  	res = 0;
		goto end1;
    	}
    
    	len = atoi(&buf[3]);

	if(my_write(sock_fd, "RDY", 3) == -1)
		goto end1;
   
	while(1){
	 	n = my_read(sock_fd, buf, MAX_LINE);
	  	
		if(n > 0){
	    		write(fd, buf, n);
	       	len -= n;
	  	}else if(len == 0){
			printf("OK\n"); 
	       		break;
	  	}else 
			goto end1;
	}

	res = 0; 
end1:
    	free(dst_file); 
end2:       
	close(fd); 

	return res;
}
开发者ID:Jiangxumin,项目名称:linux_C_program_design,代码行数:87,代码来源:command.c

示例13: do_put

int do_put(const char *src, const char *dst, int sock_fd)
{
	char *dst_file; 
	struct stat statbuf;
    	int n, fd; 
	int res = -1; 
	char buf[MAX_LINE];
	char *p;

	if(src == NULL || dst == NULL){ 
		printf("wrong command\n");
		return -1;
	}

	if(src[strlen(src)-1]=='/'){ 
	  	printf("source file should be a regular file\n");
	  	return -1;
    	}
     
	if((dst_file = malloc(strlen(dst)+strlen(src)+2)) == NULL){
		perror("fail to malloc");
		return -1;
	}
	
	strcpy(dst_file, dst);
    	if(dst_file[strlen(dst_file)-1] != '/')
		strcat(dst_file, "/");
	p = rindex(src, '/');
    	strcat(dst_file, p + 1);

	if((fd = open(src, O_RDONLY)) == -1){
	  	perror("fail to open src-file");
	  	goto end1;
    	}

 	if(fstat(fd, &statbuf) == -1){
	  	perror("fail to stat src-file");
	  	goto end2;
    	}
    
	if(!S_ISREG(statbuf.st_mode)){ 
		fputs("src-file should be a regular file\n", stderr);
	  	goto end2;
    	}
    
	sprintf(buf, "PUT %d %s", statbuf.st_size, dst_file);
	if(my_write(sock_fd, buf, strlen(buf)+1) == -1) 
		goto end2;
    
	if((my_read(sock_fd, buf, MAX_LINE)) <= 0) 
	  	goto end2;
     
     	if(buf[0]=='E'){ 
	  	write(STDOUT_FILENO, buf, n);
	 	goto end2;
     	}
     
     	while(1){ 
	  	n = read(fd, buf, MAX_LINE);
	  	
		if(n > 0)
	       		if(my_write(sock_fd, buf, n) == -1)
				goto end2;
	  	else if(n == 0){
	       		printf("OK\n");
	      		break;
	  	}else{ 
	       		perror("fail to read\n");
	       		goto end2;
	  	}
	}
    
	res = 0; 
end1:
	close(fd); 
end2:
	free(dst_file); 

	return res; 
}
开发者ID:Jiangxumin,项目名称:linux_C_program_design,代码行数:80,代码来源:command.c

示例14: pf_init

void
pf_init (global_t *gp, char *file, char *prog)
{
  FILE *pf;                     /* personal file */
  char buf[100];
  char buf2[100];
  char buf3[100];
  char *p;
  int v;

  gp->ext[0] = (pf_global_t *) malloc (sizeof (pf_global_t));
  bzero (gp->ext[0], sizeof (pf_global_t));

  pf = 0;
  if (p = getenv ("NETMAJ_LIB"))
    {
      strcpy (personal_file, p);
      strcat (personal_file, "/");
      strcat (personal_file, file);
      strcat (personal_file, ".pf");
      pf = fopen (personal_file, "r");
    }
  if (!pf)
    {
      strcpy (personal_file, NETMAJ_LIB);
      strcat (personal_file, "/");
      strcat (personal_file, file);
      strcat (personal_file, ".pf");
      pf = fopen (personal_file, "r");
    }
  if (!pf)
    {
      strcpy (personal_file, prog);
      if (p = rindex (personal_file, '/'))
        {
          p[1] = 0;
        }
      else
        {
          personal_file[0] = 0;
        }
      strcat (personal_file, file);
      strcat (personal_file, ".pf");
      pf = fopen (personal_file, "r");
    }
  if (!pf)
    {
      personal_file[0] = 0;
    }
  else
    {
      for (;;)
        {
          if (fgets (buf, 100, pf))
            {
              if (!strcmp (buf, PF_PREIDENT))
                continue;
              if (!strcmp (buf, PF_IDENT))
                break;
            }
          fclose (pf);
          personal_file[0] = 0;
          return;
        }

      while (fgets (buf, 100, pf))
        {
          if (buf[0] < 'a' || buf[0] > 'z')
            continue;
          if (sscanf (buf, PF_PARAM, buf2, buf3) == 2)
            {
              v = 0;
              sscanf (buf3, "%d", &v);
              pf_add_param (gp, buf2, v, buf3);
            }
        }
      fclose (pf);
    }
}
开发者ID:CecilHarvey,项目名称:netmaj,代码行数:79,代码来源:pf.c

示例15: main

int main(int argc, char *argv[])
{
  char *data_filename, *deref_filename;
  double train_pct, prune_pct, test_pct;
  double train_accuracy, test_accuracy;
  DTNODE *tree;
  uchar *test_members, *train_members, *prune_members;
  int multiple_input_files;
  char *train_filename, *prune_filename, *test_filename;
  int num_test, num_train, num_prune, num_features, num_data;
  int depth, count, prev_count;
  int num_negatives, num_false_negatives;
  int num_positives, num_false_positives;
  void **data;
  struct timeval tv;
  unsigned int random_seed;
  SSVINFO ssvinfo;

  ssvinfo.batch = 0;

  progname = (char *) rindex(argv[0], '/');
  argv[0] = progname = (progname != NULL) ? (progname + 1) : argv[0];

  multiple_input_files = 0;
  if (argc>2){
    if (!strcmp(argv[1],"-tpt") && (argc==5)){
      train_filename = argv[2];
      prune_filename = argv[3];
      test_filename = argv[4];
      data = ReadTPT(train_filename, prune_filename, test_filename,
                     &train_members, &prune_members, &test_members,
                     &num_train, &num_prune, &num_test,
                     &num_data, &num_features, &ssvinfo);
      multiple_input_files = 1;
    } else if (!strcmp(argv[1],"-tp") && (argc==4)){
      train_filename = argv[2];
      prune_filename = argv[3];
      data = ReadTwo(train_filename, prune_filename,
		     &train_members, &prune_members,
                     &num_train, &num_prune,
                     &num_data, &num_features, &ssvinfo);
      num_test = 0;
      test_members = CREATE_BITARRAY(num_data);
      ZERO_BITARRAY(test_members,num_data);
      multiple_input_files = 1;
    } else if (!strcmp(argv[1],"-tt")&& (argc==4)){
      train_filename = argv[2];
      test_filename = argv[3];
      data = ReadTwo(train_filename, test_filename,
		     &train_members, &test_members,
                     &num_train, &num_test,
                     &num_data, &num_features, &ssvinfo);
      num_prune = 0;
      prune_members = CREATE_BITARRAY(num_data);
      ZERO_BITARRAY(prune_members,num_data);
      multiple_input_files = 1;
    }
  }

  if (!multiple_input_files){
    if (argc != 5 && argc != 7) {
      fprintf(stderr, USAGE, progname);
      exit(1);
    }
    switch (argc) {
    case 5:
      if (gettimeofday(&tv, NULL) == -1)
	SYS_ERROR1("gettimeofday(%s)", "");
      random_seed = (unsigned int) tv.tv_usec;
      train_pct = atof(argv[1]);
      prune_pct = atof(argv[2]);
      test_pct = atof(argv[3]);
      data_filename = argv[4];
      break;
    case 7:
      if ((argv[1][1] == 's') || (argv[1][1] == 'S')) {
	random_seed = atoi(argv[2]);
      } else if ((argv[1][1] == 'b') || (argv[1][1] == 'B')) {
	if (gettimeofday(&tv, NULL) == -1)
	  SYS_ERROR1("gettimeofday(%s)", "");
	random_seed = (unsigned int) tv.tv_usec;
	ssvinfo.batch = atoi(argv[2]);
      } else {
	fprintf(stderr, USAGE, progname);
	exit(1);
      }
      train_pct = atof(argv[3]);
      prune_pct = atof(argv[4]);
      test_pct = atof(argv[5]);
      data_filename = argv[6];
      break;
    default:
      fprintf(stderr, USAGE, progname);
      exit(1);
    }
    if ((random_seed < 0) ||
	(train_pct <= 0.0) || (train_pct > 1.0) ||
	(prune_pct < 0.0) || (prune_pct > 1.0) ||
	(test_pct < 0.0) || (test_pct > 1.0) ||
	(train_pct + prune_pct + test_pct > 1.00000001)) {
//.........这里部分代码省略.........
开发者ID:pengli1123,项目名称:machine_learning_algorithm,代码行数:101,代码来源:main.c


注:本文中的rindex函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。