Example #1
0
/* ggDarwinDLOpen implements a "dlopen" wrapper
 */
gg_dlhand ggDarwinDLOpen(const char *filename, int flags)
{
	gg_dlhand ret = NULL;
	struct gg_dlhand_darwin_t *darwin_ret = NULL;
	NSLinkEditErrorHandlers error_handlers;
	const char *pathname, *modulename;

	darwin_ret = (struct gg_dlhand_darwin_t *)malloc(sizeof(struct gg_dlhand_darwin_t));
	if (darwin_ret == NULL) return ret;

	ret = (void *)darwin_ret;

	if (flags & GG_MODULE_GLOBAL) {
		darwin_ret->nsmodule_flags = NSLINKMODULE_OPTION_NONE;
	} else {
		darwin_ret->nsmodule_flags = NSLINKMODULE_OPTION_PRIVATE;
	}	/* if */

	splitstring(filename, &pathname, &modulename);

	dlerror_code = NSCreateObjectFileImageFromFile(pathname, &darwin_ret->objectFileImage);
	ggstrlcpy(dlerror_filename, filename, sizeof(dlerror_filename));

	switch (dlerror_code) {
	case NSObjectFileImageSuccess:
		break;

	case NSObjectFileImageFailure:
	case NSObjectFileImageInappropriateFile:
	case NSObjectFileImageArch:
	case NSObjectFileImageFormat:
	case NSObjectFileImageAccess:
		goto err0;
	}	/* switch */

	/* Install our own error handlers */
	error_handlers.undefined = ggDarwinErrorUndefined;
	error_handlers.multiple = ggDarwinErrorMultiple;
	error_handlers.linkEdit = ggDarwinErrorLinkEdit;

#if 0
	/* Let the default handlers do their work
	 * as long as our own error handlers are stubs.
	 */
	NSInstallLinkEditErrorHandlers(&error_handlers);
#endif

	/* try to load the module now */
	darwin_ret->nsmodule = NSLinkModule(darwin_ret->objectFileImage,
					modulename, darwin_ret->nsmodule_flags);

	/* Either we return successful here or the error handlers
	 * already aborted/exited the app before.
	 */
	return ret;

err0:
	free(ret);
	return NULL;
}	/* ggDarwinDLOpen */
Example #2
0
 size_t tokenize(std::string const & input, char separator, tokenlist_t & output) {
   std::string head;
   std::string tail(input);
   while (splitstring(tail, separator, head, tail))
     output.push_back(head);
   output.push_back(head);
   return output.size();
 }
Example #3
0
extern List *fsplit(const char *sep, List *list, Boolean coalesce) {
    Ref(List *, lp, list);
    startsplit(sep, coalesce);
    for (; lp != NULL; lp = lp->next) {
        char *s = getstr(lp->term);
        splitstring(s, strlen(s), TRUE);
    }
    RefEnd(lp);
    return endsplit();
}
Example #4
0
int readFile(string& filename)
{
  float stime[8][1024];
  float wave[8][1024];
  int nsample=0;
  string dir("data/");
  //filename=dir+filename;
  printf("Reading file:%s \n ",filename.c_str());
  ifstream file;
  file.open(filename.c_str());
  if(!file){
    printf("%s : cannot be opened.\n",filename.c_str());
    return 1;
  }else{
    printf("%s : opened successfully.\n",filename.c_str());
  }
  //anal.SetWaveTime(0,stime[0],wave[0]);
  //anal.SetWaveTime(1,stime[1],wave[1]);
  //anal.SetWaveTime((float**) stime,(float**) wave);
  string line;
  bool dflag=0,eflag=0;
  int nlines=0,ndat=0;
  int nmaxsample=NDIM;
  if(nsample>0) nmaxsample=nsample;
  nsample=0;
  while (getline(file,line)) {
       //if(nlines<10)printf("%s \n", line.c_str()); 
       //printf("%s \n", line.c_str()); 
       if(line.find("Event") != string::npos){
          printf("%s \n", line.c_str()); 
          eflag=1;
          continue;
       }
       if(line.find("t1[ns]") != string::npos){
          if(!eflag){
            printf("Error: unexpected line sequence.\n");
            return 1;
          }
          eflag=0;
          if(dflag){
            printf("close sample %i \n",ndat);
            if(ndat != NDIM){
             printf("ErrorL ndat= %i \n",ndat);
             return 1;
            }
    	    anal.Compare2Waves(0,1);
            ndat=0;
            nsample++;
            if(nsample>=nmaxsample){
             printf("Warning:  nsample=%i \n",nsample);
             return 0;
            }
          }
          printf("open sample \n");
          dflag=1;
          continue;
       }
       // take data
       vector<string> items;
       splitstring(line,items," ");
       int nitems=items.size();
       if((nitems != 4) && (nitems != 8)){
         printf("Expexted number of items in line != 4 : %i \n",nitems);
         return 1;
       }
       double t1,t2;
       //cout << atof(items[0].c_str()) << endl;
       t1=atof(items[0].c_str());
       wave[0][ndat]=atof(items[1].c_str());
       t2=atof(items[2].c_str());
       wave[1][ndat]=atof(items[3].c_str());
       stime[0][ndat]=t1;
       stime[1][ndat]=t2;
       //if(t1 != t2){
       //  printf("Warning: t1 != t2 %f %f \n",t1,t2);
       //}
       if(ndat >= NDIM){
         printf("Error: unexpected size of data %i \n",ndat);
         return 1;
       }
       nlines++;
       ndat++;
  }
  if(dflag){
    printf("close sample %i \n",ndat);
    if(ndat != NDIM){
       printf("ErrorL ndat= %i \n",ndat);
       return 1;
    }
    //anal.Compare2Waves(0,1);
    nsample++;
  }
  Float_t* tt1=stime[0];
  Float_t* tt2=stime[1];
  Float_t* w1=wave[0];
  Float_t* w2=wave[1];
  DrawWaves(tt1,tt2,w1,w2);
  printf("All samples read nsample: %i \n",nsample);
  return 0;

}