示例#1
0
static void local_file_rcv_add_span(struct htrace_rcv *r,
                                    struct htrace_span *span)
{
    int len, res, err;
    char *buf;
    struct local_file_rcv *rcv = (struct local_file_rcv *)r;

    span->prid = rcv->tracer->prid;
    len = span_json_size(span);
    buf = malloc(len + 1);
    if (!buf) {
        span->prid = NULL;
        htrace_log(rcv->tracer->lg, "local_file_rcv_add_span: OOM\n");
        return;
    }
    span_json_sprintf(span, len, buf);
    span->prid = NULL;
    buf[len - 1] = '\n';
    buf[len] = '\0';
    pthread_mutex_lock(&rcv->lock);
    res = fwrite(buf, 1, len, rcv->fp);
    err = errno;
    pthread_mutex_unlock(&rcv->lock);
    if (res < len) {
        htrace_log(rcv->tracer->lg, "local_file_rcv_add_span(%s): fwrite error: "
                   "%d (%s)\n", rcv->path, err, terror(err));
    }
    free(buf);
}
示例#2
0
static int convert_u64(struct htrace_log *log, const char *key,
                   const char *in, uint64_t *out)
{
    char *endptr = NULL;
    int err;
    uint64_t ret;

    errno = 0;
    ret = strtoull(in, &endptr, 10);
    if (errno) {
        err = errno;
        htrace_log(log, "error parsing %s for %s: %d (%s)\n",
                   in, key, err, terror(err));
        return 0;
    }
    while (1) {
        char c = *endptr;
        if (c == '\0') {
            break;
        }
        if ((c != ' ') || (c != '\t')) {
            htrace_log(log, "error parsing %s for %s: garbage at end "
                       "of string.\n", in, key);
            return 0;
        }
    }
    *out = ret;
    return 1;
}
示例#3
0
static void refill_rand_cache(struct random_src *rnd)
{
    size_t total = 0;

    while (1) {
        ssize_t res;
        ssize_t rem = (PSAMP_THREAD_LOCAL_BUF_LEN * sizeof(uint32_t)) - total;
        if (rem == 0) {
            break;
        }
        res = read(rnd->urandom_fd, ((uint8_t*)&g_rnd_cache) + total, rem);
        if (res < 0) {
            int err = errno;
            if (err == EINTR) {
                continue;
            }
            htrace_log(rnd->lg, "refill_rand_cache: error refilling "
                       "random cache: %d (%s)\n", err,
                       terror(err));
            return;
        }
        total += res;
    }
    g_rnd_cache_idx = 0;
}
示例#4
0
static void delete_tdb(char *keyname, size_t keylen)
{
	TDB_DATA key;

	if ((keyname == NULL) || (keylen == 0)) {
		terror("need key");
		return;
	}

	key.dptr = (unsigned char *)keyname;
	key.dsize = keylen;

	if (tdb_delete(tdb, key) != 0) {
		terror("delete failed");
	}
}
示例#5
0
文件: hostname.c 项目: bproctor/utils
int command_hostname (int argc, char **argv)
{
   char hostname[MAXHOSTNAMELEN];

   progname = argv[0];
   
   if (argc == 1)
   {
      if (gethostname (hostname, MAXHOSTNAMELEN) < 0)
         error ("cannot get hostname: %s", strerror (errno));
      puts (hostname);
      return (EXIT_SUCCESS);
   }
   else if (argc == 2)
   {
      if (!strcmp (argv[1], "--help"))
         puts (help_text);
      else if (!strcmp (argv[1], "--version"))
         puts ("hostname: version "VERSION);
      else
      {
         if (sethostname (argv[1], strlen (argv[1])) < 0)
            error ("cannot set hostname: %s", strerror (errno));
      }
   }
   else
      terror ("too many arguments");
      
   return (EXIT_SUCCESS);
}
static int
ZeroNwrite(int fd, int count, struct Ipcom_cmd_ttcp_data *context)
#endif
{
    register int cnt;
    int start;
    void *buf;
    void *aligned_buf;

    start = ipcom_pkt_hdrspace(fd);
    buf = ipcom_pkt_buffer_malloc(start + count + 15);
    aligned_buf = (void *) (((unsigned long) buf + 15u) & ~0xf);

#ifdef IPCOM_TTCP_REENTRANT
    cnt = ipcom_pkt_sendto(fd, aligned_buf, start, count, ZeroNwriteFreeFunc, buf, 0, (struct Ip_sockaddr *)addrhimp, context->addrsize);
#else
    cnt = ipcom_pkt_sendto(fd, aligned_buf, start, count, ZeroNwriteFreeFunc, buf, 0, (struct Ip_sockaddr *)&addrhim, context->addrsize);
#endif
    context->numCalls++;
    if (cnt == ERR)
    {
        terror(context, "Nwrite");
        return -1;
    }

    return (cnt);
}
示例#7
0
static void* worker(void* arg)
{
	int		i, j, k;
	Worker_t	*w = (Worker_t*)arg;

	if(w->object)
		free(w->object);

	for(i = 0; i < w->iterations; ++i)
	{	char	*obj;

		if(!(obj = (char*)malloc(w->objsize)) )
			terror("malloc failed");

		/* write into obj a bunch of times */
		for(j = 0; j < w->repetitions; ++j)
		{	for(k = 0; k < w->objsize; ++k)
			{	volatile char	ch;
				obj[k] = (char)k;
				ch = obj[k];
				ch += 1;
			}
		}

		free(obj);
	}

	free(w);

	return (void*)0;
}
示例#8
0
static void show_tdb(void)
{
	char *k = get_token(1);
	TDB_DATA key, dbuf;

	if (!k) {
		help();
		return;
	}

	key.dptr = k;
	key.dsize = strlen(k)+1;

	dbuf = tdb_fetch(tdb, key);
	if (!dbuf.dptr) {
		/* maybe it is non-NULL terminated key? */
		key.dsize = strlen(k); 
		dbuf = tdb_fetch(tdb, key);
		
		if ( !dbuf.dptr ) {
			terror("fetch failed");
			return;
		}
	}
	
	/* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */
	print_rec(tdb, key, dbuf, NULL);
	
	free( dbuf.dptr );
	
	return;
}
示例#9
0
文件: mknod.c 项目: bproctor/utils
int command_mknod (int argc, char **argv)
{
   int i = 1, mode = 0775;

   progname = argv[0];
   
   if (argc > 1)
   {
      if (argv[1][0] == '-')
      {
         if (!strcmp(argv[1], "--help"))
         {
            puts (help_text);
            return (EXIT_SUCCESS);
         }
         else if (!strcmp (argv[1], "--version"))
         {
            puts ("mknod: version "VERSION);
            return (EXIT_SUCCESS);
         }
         else if (!strcmp (argv[1], "-m"))
         {
            if (argv[2] == NULL)
               terror ("missing operand to `-m' option");
            mode = getnum_octal (argv[2]);
            i = 3;
         }
      }
      for (; i < argc; ++i)
         if (mknod (argv[i], mode, 0))
            error ("cannot create `%s': %s",
               argv[i], strerror (errno));
   }
   return (EXIT_SUCCESS);
}
示例#10
0
static struct htrace_rcv *local_file_rcv_create(struct htracer *tracer,
                                             const struct htrace_conf *conf)
{
    struct local_file_rcv *rcv;
    const char *path;
    int ret;

    path = htrace_conf_get(conf, HTRACE_LOCAL_FILE_RCV_PATH_KEY);
    if (!path) {
        htrace_log(tracer->lg, "local_file_rcv_create: no value found for %s. "
                   "You must set this configuration key to the path you wish "
                   "to write spans to.\n", HTRACE_LOCAL_FILE_RCV_PATH_KEY);
        return NULL;
    }
    rcv = calloc(1, sizeof(*rcv));
    if (!rcv) {
        htrace_log(tracer->lg, "local_file_rcv_create: OOM while "
                   "allocating local_file_rcv.\n");
        return NULL;
    }
    ret = pthread_mutex_init(&rcv->lock, NULL);
    if (ret) {
        htrace_log(tracer->lg, "local_file_rcv_create: failed to "
                   "create mutex while setting up local_file_rcv: "
                   "error %d (%s)\n", ret, terror(ret));
        free(rcv);
        return NULL;
    }
    rcv->base.ty = &g_local_file_rcv_ty;
    rcv->path = strdup(path);
    if (!rcv->path) {
        local_file_rcv_free((struct htrace_rcv*)rcv);
        return NULL;
    }
    rcv->tracer = tracer;
    rcv->fp = fopen(path, "a");
    if (!rcv->fp) {
        ret = errno;
        htrace_log(tracer->lg, "local_file_rcv_create: failed to "
                   "open '%s' for write: error %d (%s)\n",
                   path, ret, terror(ret));
        local_file_rcv_free((struct htrace_rcv*)rcv);
    }
    htrace_log(tracer->lg, "Initialized local_file receiver with path=%s.\n",
               rcv->path);
    return (struct htrace_rcv*)rcv;
}
示例#11
0
文件: texcept.c 项目: att/ast
static ssize_t readfunc(Sfio_t *f, void *buf, size_t n, Sfdisc_t *disc) {
    UNUSED(buf);
    UNUSED(n);
    UNUSED(disc);

    if (sfgetc(f) >= 0) terror("Can't access stream here!");
    return 0;
}
示例#12
0
文件: Qfunc.c 项目: ots/qnorm
struct params *CommandLine(int argc, char *argv[])
{
  int i;
  char c;
  struct params *p;
  p=(struct params*)malloc(sizeof(struct params));

  /* default values-------------------------------------*/
  strcpy(p->fListName,"qInput.txt");
  strcpy(p->fOutName, "qOut.bin");
  p->Traspose= 0;
  p->MemIndex= 1;
  p->nP      = MAXnP;
  p->nG      = NGEN;
  p->nE      = NEXP;
  p->Verbose = 0;

  /*----------------------------------------------------------*/

  for (i=1; i<argc; i++)  {
    if (!strcmp(argv[i],argv[0])) continue;
    if (argv[i][0] != '-') terror("dash needed at argument (sintx error)");

    c = toupper(argv[i][1]);

    // On-Off flags----------------
    if (c == 'T') {p->Traspose=1; continue;}
    if (c == 'D') {p->MemIndex=0; continue;}
    if (c == 'V') {p->Verbose =1; continue;}

    // -argum=value
    if (argv[i][2]!='=') terror("equal symbol needed at argument (sintx error)");

    switch(c)
    {
      case 'I': strcpy(p->fListName,&argv[i][3]);  break;
      case 'O': strcpy(p->fOutName, &argv[i][3]);  break;
      case 'E': p->nE    = atoi(&argv[i][3]);      break;
      case 'G': p->nG    = atof(&argv[i][3]);      break;
      case 'M': 1;                                 break;
      case 'P': p->nP   = atoi(&argv[i][3]);       break;
      default: terror("Unknown parameter (see syntax)");
    }
  }
  return p;
}
示例#13
0
文件: pQnorm1-v0.c 项目: ots/qnorm
int main(int ac, char **av){

	double** aux=(double **)malloc(sizeof(double *)*10);
	int i,j;

        if (ac!=4) terror("Usage pQnorm1 fMatrix.in  nRows  nCOls");

        /* it has non sense to load the full matrix in memory	for (i=0; i<10;i++){
示例#14
0
文件: tstack.c 项目: att/ast
ssize_t writef(Sfio_t *f, const void *buf, size_t n, Sfdisc_t *disc) {
    UNUSED(disc);
    UNUSED(buf);
    UNUSED(n);

    if ((f->mode & SF_RDWR) == f->mode) terror("Stream mode should be inaccessible in writef");
    return 0;
}
示例#15
0
文件: tinit.c 项目: smaclennan/zedit
static void tlinit(void)
{
	static const char * const names[] = {
		"cm", "ce", "cl", "me", "so", "vb", "md"
	};
	char *key, *was = area, *end = area, *term = getenv("TERM");
	int i;

	if (term == NULL) {
		terror("ERROR: environment variable TERM not set.\n");
		exit(1);
	}
	if (tgetent(bp, term) != 1) {
		terror("ERROR: Unable to get termcap entry.\n");
		exit(1);
	}

	/* get the initialization string and send to stdout */
	tgetstr("is", &end);
	if (end != was)
		TPUTS(was);

	/* get the termcap strings needed - must be done last */
	for (i = 0; i < NUMCM; ++i) {
		cm[i] = end;
		tgetstr(names[i], &end);
		if (cm[i] == end) {
			if (i < MUST) {
				Dbg("Missing termcap entry for %s\n", names[i]);
				exit(1);
			} else
				cm[i] = "";
		}
	}

	termcap_end = end;

	/* get the cursor and function key defines */
	for (i = 0; i < 22; ++i) {
		key = termcap_end;
		tgetstr(key_names[i], &termcap_end);
		if (key != termcap_end)
			set_tkey(i, key);
	}
}
示例#16
0
static void insert_tdb(char *keyname, size_t keylen, char* data, size_t datalen)
{
	TDB_DATA key, dbuf;

	if ((keyname == NULL) || (keylen == 0)) {
		terror("need key");
		return;
	}

	key.dptr = (unsigned char *)keyname;
	key.dsize = keylen;
	dbuf.dptr = (unsigned char *)data;
	dbuf.dsize = datalen;

	if (tdb_store(tdb, key, dbuf, TDB_INSERT) != 0) {
		terror("insert failed");
	}
}
示例#17
0
static void local_file_rcv_flush(struct htrace_rcv *r)
{
    struct local_file_rcv *rcv = (struct local_file_rcv *)r;
    if (fflush(rcv->fp) < 0) {
        int e = errno;
        htrace_log(rcv->tracer->lg, "local_file_rcv_flush(path=%s): fflush "
                   "error: %s\n", rcv->path, terror(e));
    }
}
示例#18
0
文件: tdb2tool.c 项目: burito/ccan
static void delete_tdb(char *keyname, size_t keylen)
{
	TDB_DATA key;
	enum TDB_ERROR ecode;

	if ((keyname == NULL) || (keylen == 0)) {
		terror(TDB_SUCCESS, "need key");
		return;
	}

	key.dptr = (unsigned char *)keyname;
	key.dsize = keylen;

	ecode = tdb_delete(tdb, key);
	if (ecode) {
		terror(ecode, "delete failed");
	}
}
示例#19
0
文件: pwd.c 项目: bproctor/utils
int command_pwd (int argc, char **argv)
{
   int i;
   char *ptr, *d;

   progname = argv[0];

   for (i = 1; i < argc; ++i)
   {
      ptr = argv[i];
      if (*ptr == '-')
      {
         while (*++ptr)
         switch (*ptr)
         {
            case '-':   
               if (!strcmp (ptr, "-help"))
                  puts (help_text);
               else if (!strcmp (ptr, "-version"))
                  puts ("pwd: version "VERSION);
               else
                  terror ("invalid option `%s'", argv[i]);
               return (EXIT_SUCCESS);
            case 'L':
               flag_L = 1, flag_P = 0;
               continue;
            case 'P':
               flag_P = 1, flag_L = 0;
               continue;
            default:
               terror ("invalid option `%s'", argv[i]);
         }
      }
   }
   if (!flag_L && !flag_P)
      flag_L = 1;
      
   d = getcwd (NULL, 0);
   if (d == NULL)
      error ("cannot get directory: %s", strerror (errno));
   puts (d);

   return (EXIT_SUCCESS);
}
示例#20
0
tmain()
{
	Vmalloc_t	*vm;
	Void_t		*addr[10];
	Void_t		*mem;
	int		i;

	Vmdcheap->round = 64;
	if(!(vm = vmopen(Vmdcheap, Vmbest, 0)) )
		terror("Open failed");

	for(i = 0; i < 10; ++i)
		if(!(addr[i] = vmalloc(vm,15)) )
			terror("vmalloc failed");
	for(i = 0; i < 10; ++i)
		if(vmfree(vm,addr[i]) < 0)
			terror("vmfree failed");
	for(i = 0; i < 10; ++i)
		if(!(addr[i] = vmalloc(vm,15)) )
			terror("vmalloc failed");
#ifdef DEBUG
	for(i = 0; i < 10; ++i)
		printf("size[%d]=%d\n",i,vmsize(vm,addr[i]));
	printf("Extent=%d\n",vmsize(vm,NIL(Void_t*)));
#endif

	mem = 0;
	if(posix_memalign(&mem, 3, 128) != EINVAL)
		terror("Bad return value from posix_memalign()");
	if(mem)
		terror("Bad memory");

	if(posix_memalign(&mem, 3*sizeof(Void_t*), 128) != EINVAL)
		terror("Bad return value from posix_memalign()");
	if(mem)
		terror("Bad memory");

	if(posix_memalign(&mem, (sizeof(Void_t*)<<4), 128) != 0 )
		terror("posix_memalign() failed");
	if(!mem)
		terror("Bad memory");

	texit(0);
}
示例#21
0
// Load to memory a list of files
// datafile format: fileName[tab]nGenes[tab][format][newLINE]
InfoFile* load_input_files(Params *p) {

    FILE *fileInput;
    InfoFile*info=NULL;
    char line[MAX_SIZE_LINE],line2[MAX_SIZE_LINE],t;
    int index=0,j,g;

    if ((fileInput=fopen(p->file_list_experiments,"rt"))==NULL) terror("opening input file");

    if ((info=(InfoFile*)calloc(p->num_experiments,sizeof(InfoFile)))==NULL)
        terror("memory for list of files");

    fgets(line,MAX_SIZE_LINE,fileInput);
    j=3;
    while (!feof(fileInput) && j==3) {

        if (line[0]!='@') {
            j=sscanf(line,"%s\t%d\t%c\n",line2,&g,&t);
            if (index==p->num_experiments) {
                fprintf(stderr,"[WARNING] more than %d lines... using firts %d as filenames\n",index,index);
                p->num_experiments=index;
                return info;
            }

            if (line2[strlen(line2)-1]=='\t'||line2[strlen(line2)-1]==' ') line2[strlen(line2)-1]=0;

            if (strlen(line2)>0) {
                info[index].file_name=(char*)strdup(line2);
                info[index].num_genes   =g;
                info[index].file_type=t;
                index++;
            }
        }
        fgets(line,MAX_SIZE_LINE,fileInput);

    }
    fclose(fileInput);
    if (index!=p->num_experiments) {
        fprintf(stderr,"[WARNING] only %d files.. nExp=%d\n",index,index);
        p->num_experiments = index;
    }

    return info;
}
示例#22
0
/**
 * Get the "best" IP address for this node.
 *
 * This is complicated since nodes can have multiple network interfaces,
 * and each network interface can have multiple IP addresses.  What we're
 * looking for here is an IP address that will serve to identify this node
 * to HTrace.  So we prefer site-local addresess (i.e. private ones on the
 * LAN) to publicly routable interfaces.  If there are multiple addresses
 * to choose from, we select the one which comes first in textual sort
 * order.  This should ensure that we at least consistently call each node
 * by a single name.
 */
void get_best_ip(struct htrace_log *lg, char *ip_str, size_t ip_str_len)
{
    struct ifaddrs *head, *ifa;
    enum ip_addr_type ty = ADDR_TYPE_IPV4_LOOPBACK, nty;
    char temp_ip_str[128];

    snprintf(ip_str, ip_str_len, "%s", "127.0.0.1");
    if (getifaddrs(&head) < 0) {
        int res = errno;
        htrace_log(lg, "get_best_ip: getifaddrs failed: %s\n", terror(res));
        return;
    }
    for (ifa = head; ifa; ifa = ifa->ifa_next){
        if (!ifa->ifa_addr) {
            continue;
        }
        if (ifa->ifa_addr->sa_family == AF_INET) {
            struct sockaddr_in *addr =
                (struct sockaddr_in *)ifa->ifa_addr;
            nty = get_ipv4_addr_type(addr);
            if (nty < ty) {
                continue;
            }
            if (!inet_ntop(AF_INET, &addr->sin_addr, temp_ip_str,
                           sizeof(temp_ip_str))) {
                htrace_log(lg, "get_best_ip_impl: inet_ntop(%s, AF_INET) "
                           "failed\n", ifa->ifa_name);
                continue;
            }
            if ((nty == ty) && (strcmp(temp_ip_str, ip_str) > 0)) {
                continue;
            }
            snprintf(ip_str, ip_str_len, "%s", temp_ip_str);
            ty = nty;
        } else if (ifa->ifa_addr->sa_family == AF_INET6) {
            struct sockaddr_in6 *addr =
                (struct sockaddr_in6 *)ifa->ifa_addr;
            nty = get_ipv6_addr_type(addr);
            if (nty < ty) {
                continue;
            }
            if (!inet_ntop(AF_INET6, &addr->sin6_addr, temp_ip_str,
                           sizeof(temp_ip_str))) {
                htrace_log(lg, "get_best_ip_impl: inet_ntop(%s, AF_INET6) "
                           "failed\n", ifa->ifa_name);
                continue;
            }
            if ((nty == ty) && (strcmp(temp_ip_str, ip_str) > 0)) {
                continue;
            }
            snprintf(ip_str, ip_str_len, "%s", temp_ip_str);
            ty = nty;
        }
    }
    freeifaddrs(head);
}
示例#23
0
// Load a text-tab-2cols file ans store a bin file
int text_to_bin(struct params *parameters, char** probe_id, struct files *file_list) {

  FILE *f;
  FILE *f2;
  float*mat;
  int i;
  char new_name[MAX_SIZE_LINE];
  int num_gene=parameters->num_genes;
  int num_experiment=parameters->num_experiments;


  // probeID file
  if (parameters->verbose)fprintf(stderr,"probesID fileout...%s\n",parameters->file_out);
  if ((f=fopen(parameters->file_out,"wt"))==NULL)
    terror("[Bin2Text] opening probeID file");
  for (i=0;i<num_gene; i++) fprintf(f,"%s\n",probe_id[i]);
  fclose(f);

  if ((mat=(float *)calloc(num_gene,sizeof(float)))==NULL)
    terror("[Txt2Bin] memory for probeID array");
  if ((f2=fopen("qInBIN.txt","wt"))==NULL)
    terror("[Text2Bin] opening qInBIN file");

  if (parameters->verbose) fprintf(stderr,"kickoff..%d files.\n",num_experiment);
  for (i=0; i< num_experiment; i++) { // Qnorm for each datafile: STEP 1
    load_file(file_list, i, mat);

    if (parameters->verbose) fprintf(stderr,"%4d file: %s\n",i, file_list[i].fname);

//          sprintf(NewName,"%s.bin",fList[i].fname);
    file_list[i].fname[24]=0;
    sprintf(new_name,"../files/bin/%s.bin",&file_list[i].fname[15]);
    fprintf(f2,"%s\t6553600\tb\n",new_name);
    fflush(f2);
    if ((f=fopen(new_name,"wb"))==NULL)
      terror("[Bin2Text] opening bin file");
    fwrite(mat, sizeof(float), num_gene, f);
    fclose(f);
  }
  free(mat);
  fclose(f2);
  return 1;
}
示例#24
0
static void first_record(TDB_CONTEXT *context, TDB_DATA *pkey)
{
  TDB_DATA dbuf;
  *pkey = tdb_firstkey(context);
  
  dbuf = tdb_fetch(context, *pkey);
  if (!dbuf.dptr) terror("fetch failed");
  /* printf("%s : %*.*s\n", k, (int)dbuf.dsize, (int)dbuf.dsize, dbuf.dptr); */
  print_rec(context, *pkey, dbuf, NULL);
}
示例#25
0
tmain()
{	Sfio_t	*f;
	int	i, c;

	if(!(f = sftmp(8)))
		terror("Can't open temp file");

	for(i = 0; i < 10000; ++i)
		if(sfputc(f,(i%26)+'a') < 0)
			terror("Writing %c",(i%26)+'a');

	sfseek(f,(Sfoff_t)0,0);

	for(i = 0; i < 10000; ++i)
		if((c = sfgetc(f)) != ((i%26)+'a'))
			terror("Input=%#o, Expect=%c",c,(i%26)+'a');

	texit(0);
}
示例#26
0
tmain()
{
#if _lib_locale
	char		buf[128], cmp[128];
	float		d;
	int		n, decimal, thousand;
	struct lconv*	lv;

	setlocale(LC_ALL, "");

	if(!(lv = localeconv()))
		texit(0);

	decimal = '.';
	if(lv->decimal_point && lv->decimal_point[0])
		decimal = lv->decimal_point[0];

	thousand = 0;
	if(lv->thousands_sep && lv->thousands_sep[0])
		thousand = lv->thousands_sep[0];
		
	if(thousand)
		sfsprintf(cmp, sizeof(cmp), "1%c000", thousand);
	else	sfsprintf(cmp, sizeof(cmp), "1000");
	sfsprintf(buf, sizeof(buf), "%'d", 1000);
	if(strcmp(buf, cmp) != 0)
		terror("Bad printing");
	
	if(thousand)
		sfsprintf(cmp, sizeof(cmp), "1%c000%c10", thousand, decimal);
	else	sfsprintf(cmp, sizeof(cmp), "1000%c10", decimal);
	d = 0.;
	if((n = sfsscanf(cmp, "%'f", &d)) != 1)
		terror("Scan error %d", n);
	if(d < 1000.099 || d > 1000.101)
		terror("Bad scanning");
	sfsprintf(buf, sizeof(buf), "%.2f", d);
	if(strcmp(buf, "1000.10") != 0)
		terror("Deep formatting error");
#endif

	texit(0);
}
示例#27
0
static void move_rec(char *keyname, size_t keylen, char* tdbname)
{
	TDB_DATA key, dbuf;
	TDB_CONTEXT *dst_tdb;

	if ((keyname == NULL) || (keylen == 0)) {
		terror("need key");
		return;
	}

	if ( !tdbname ) {
		terror("need destination tdb name");
		return;
	}

	key.dptr = (unsigned char *)keyname;
	key.dsize = keylen;

	dbuf = tdb_fetch(tdb, key);
	if (!dbuf.dptr) {
		terror("fetch failed");
		return;
	}

	print_rec(tdb, key, dbuf, NULL);

	dst_tdb = tdb_open(tdbname, 0, 0, O_RDWR, 0600);
	if ( !dst_tdb ) {
		terror("unable to open destination tdb");
		return;
	}

	if (tdb_store( dst_tdb, key, dbuf, TDB_REPLACE ) != 0) {
		terror("failed to move record");
	}
	else
		printf("record moved\n");

	tdb_close( dst_tdb );

	return;
}
示例#28
0
// Transpose from Disk to Disk the binary matrix into a tab delimited text file
int transpose_matrix(Params *p) {
    FILE *file_out;
    double value, **matrix;
    int i,j;
    char new_name[MAX_SIZE_LINE];
    const int num_genes=p->num_genes;
    const int num_experiments=p->num_experiments;

    if ((file_out=fopen(p->file_out,"rb"))==NULL)
        terror("[Bin2Text] opening binary output file");

    if ((matrix=(double **)calloc(num_genes,sizeof(double*)))==NULL) terror("[Bin2Text] memory for index1");
    for (i=0; i<num_genes; i++)
        if ((matrix[i]=(double *)calloc(num_experiments,sizeof(double)))==NULL) terror("[Bin2Text] memory for index2 full matrix");

    for (i=0; i<num_experiments; i++) {
        for (j=0; j<num_genes; j++) {
            fread(&value, 1, sizeof(double), file_out);
            matrix[j][i]=value;
        }
    }
    fclose(file_out);

    // Save trasposed text tabulated

    sprintf(new_name,"%s.txt",p->file_out);
    if ((file_out=fopen(new_name,"wt"))==NULL)
        terror("[Bin2Text] opening tabulated text file out");

    for (i=0; i<num_genes; i++) {
        fprintf(file_out,"%i\t",i);
        for (j=0; j<num_experiments; j++) {
            if (j) fprintf(file_out,"\t");
            fprintf(file_out,"%lf",matrix[i][j]);
        }
        fprintf(file_out,"\n");
    }

    fclose(file_out);

    return 1;
}
示例#29
0
static void next_record(TDB_CONTEXT *the_tdb, TDB_DATA *pkey)
{
	TDB_DATA dbuf;
	*pkey = tdb_nextkey(the_tdb, *pkey);

	dbuf = tdb_fetch(the_tdb, *pkey);
	if (!dbuf.dptr)
		terror("fetch failed");
	else
		print_rec(the_tdb, *pkey, dbuf, NULL);
}
示例#30
0
tmain()
{
	int	i, r;
	Sfio_t	*fp;

	if(!(fp = sftmp(8)))
		terror("Can't open temp file");

	for(i = -5448; i <= 5448; i += 101)
		if(sfputl(fp,(long)i) < 0)
			terror("Writing %d",i);

	sfseek(fp,(Sfoff_t)0,0);

	for(i = -5448; i <= 5448; i += 101)
		if((r = (int)sfgetl(fp)) != i)
			terror("Input=%d, Expect=%d",r,i);

	texit(0);
}