Exemplo n.º 1
0
void do_conect(const char *fn,int n,rvec x[])
{
  FILE     *fp;
  int      i,j;
  t_conect *c;
  rvec     dx;
  real     d2;
  
  fprintf(stderr,"Building CONECT records\n");
  snew(c,n);
  for(i=0; (i<n); i++) 
    c[i].aa = c[i].ab = NO_ATID;
  
  for(i=0; (i<n); i++) {
    for(j=i+1; (j<n); j++) {
      rvec_sub(x[i],x[j],dx);
      d2 = iprod(dx,dx);
      add_rec(c,i,j,d2);
      add_rec(c,j,i,d2);
    }
  }
  fp = ffopen(fn,"a");
  for(i=0; (i<n); i++) {
    if ((c[i].aa == NO_ATID) || (c[i].ab == NO_ATID))
      fprintf(stderr,"Warning dot %d has no conections\n",i+1);
    fprintf(fp,"CONECT%5d%5d%5d\n",i+1,c[i].aa+1,c[i].ab+1);
  }
  ffclose(fp);
  sfree(c);
}
Exemplo n.º 2
0
int main(void)
{
    int x, y;
    my_callback = some_callback;
    x = add_rec(40, 2);
    y = add_rec(100, -5);
    printf("got: %d %d\n", x, y);
    return 0;
}
Exemplo n.º 3
0
static void add_rec( hcell **cc, int size, hcell *c ) {
	int k;
	if( c == NULL )
		return;
	add_rec(cc,size,c->next);
	k = c->hkey % size;
	c->next = cc[k];
	cc[k] = c;
}
Exemplo n.º 4
0
int main(int argc, char **argv)
{
    int ret, op, cnt, i;
    extern char *optarg;
    extern int optind;
    DBT value;
    char **keys, **values;

    if (argc < 2 || argc > 4) {
        //usage();
        puts("BLAH");
    }

    op = getopt(argc, argv, "a:d:f:g:l");

    if (open_db(NULL) == 1) {
        puts("Error opening database");
    }

    switch(op) {
        case 'a':
            if (argc == 4 && (optarg != NULL) &&
                    (strlen(optarg) >= 1) &&
                    (argv[optind] != NULL)) {
                ret = add_rec(optarg, argv[optind]);
                if (ret == 1) {
                    printf("Key '%s' exists\n", optarg);
                    exit(EXIT_FAILURE);
                }
                else if (ret < 0) {
                    perror("mcdcli.c: add_rec");
                    exit(EXIT_FAILURE);
                }
                else if (ret > 0) {
                    printf("%i\n", ret);
                    perror("mcdcli.c: add_rec");
                }
                break;
            }
            else {
                //usage();
                puts("BLAH");
            }
    }
}
Exemplo n.º 5
0
/**
	$hresize : 'hash -> int -> void
	<doc>Resize an hashtable</doc>
**/
static value builtin_hresize( value vh, value size ) {
	vhash *h;
	hcell **cc;
	int nsize;
	int i;
	val_check_kind(vh,k_hash);
	val_check(size,int);
	h = val_hdata(vh);
	nsize = val_int(size);
	if( nsize <= 0 )
		nsize = HASH_DEF_SIZE;
	cc = (hcell**)alloc(sizeof(hcell*)*nsize);
	memset(cc,0,sizeof(hcell*)*nsize);
	for(i=0;i<h->ncells;i++)
		add_rec(cc,nsize,h->cells[i]);
	h->cells = cc;
	h->ncells = nsize;
	return val_null;
}
Exemplo n.º 6
0
static int parse_buffer(int fdin, int fdout)
{
	struct dbg_line		*line;
	struct ptldebug_header	*hdr;
	char			 buf[4097];
	char			*ptr;
	unsigned long		 dropped = 0;
	unsigned long		 kept = 0;
	unsigned long		 bad = 0;
	struct dbg_line		**linev = NULL;
	int			 linev_len = 0;
	int			 rc;

	hdr = (void *)buf;

	while (1) {
		int first_bad = 1;
		int count;

		count = HDR_SIZE;
		ptr = buf;
readhdr:
		rc = read(fdin, ptr, count);
		if (rc <= 0)
			goto print;

		ptr += rc;
		count -= rc;
		if (count > 0)
			goto readhdr;

		if (hdr->ph_len > 4094 ||       /* is this header bogus? */
		    hdr->ph_stack > 65536 ||
		    hdr->ph_sec < (1 << 30) ||
		    hdr->ph_usec > 1000000000 ||
		    hdr->ph_line_num > 65536) {
			if (first_bad)
				dump_hdr(lseek(fdin, 0, SEEK_CUR), hdr);
			bad += first_bad;
			first_bad = 0;

			/* try to restart on next line */
			while (count < HDR_SIZE && buf[count] != '\n')
				count++;
			if (buf[count] == '\n')
				count++; /* move past '\n' */
			if (HDR_SIZE - count > 0) {
				int left = HDR_SIZE - count;

				memmove(buf, buf + count, left);
				ptr = buf + left;

				goto readhdr;
			}

			continue;
		}

		if (hdr->ph_len == 0)
			continue;

		count = hdr->ph_len - HDR_SIZE;
readmore:
		rc = read(fdin, ptr, count);
		if (rc <= 0)
			break;

		ptr += rc;
		count -= rc;
		if (count > 0)
			goto readmore;

		first_bad = 1;

		if ((hdr->ph_subsys && !(subsystem_mask & hdr->ph_subsys)) ||
		    (hdr->ph_mask && !(debug_mask & hdr->ph_mask))) {
			dropped++;
			continue;
		}

retry_alloc:
		line = malloc(sizeof(*line));
		if (line == NULL) {
			if (linev) {
				fprintf(stderr, "error: line malloc(%u): "
					"printing accumulated records\n",
					(unsigned int)sizeof(*line));
				print_rec(&linev, kept, fdout);

				goto retry_alloc;
			}
			fprintf(stderr, "error: line malloc(%u): exiting\n",
				(unsigned int)sizeof(*line));
			break;
		}

		line->hdr = malloc(hdr->ph_len + 1);
		if (line->hdr == NULL) {
			free(line);
			if (linev) {
				fprintf(stderr, "error: hdr malloc(%u): "
					"printing accumulated records\n",
					hdr->ph_len + 1);
				print_rec(&linev, kept, fdout);

				goto retry_alloc;
			}
			fprintf(stderr, "error: hdr malloc(%u): exiting\n",
					hdr->ph_len + 1);
			break;
		}

		ptr = (void *)line->hdr;
		memcpy(line->hdr, buf, hdr->ph_len);
		ptr[hdr->ph_len] = '\0';

		ptr += sizeof(*hdr);
		line->file = ptr;
		ptr += strlen(line->file) + 1;
		line->fn = ptr;
		ptr += strlen(line->fn) + 1;
		line->text = ptr;

retry_add:
		if (add_rec(line, &linev, &linev_len, kept) < 0) {
			if (linev) {
				fprintf(stderr, "error: add_rec[%u] failed; "
					"print accumulated records\n",
					linev_len);
				print_rec(&linev, kept, fdout);

				goto retry_add;
			}
			fprintf(stderr, "error: add_rec[0] failed; exiting\n");
			break;
		}
		kept++;
	}

print:
	if (linev)
		print_rec(&linev, kept, fdout);

	printf("Debug log: %lu lines, %lu kept, %lu dropped, %lu bad.\n",
		dropped + kept + bad, kept, dropped, bad);

	return 0;
}
Exemplo n.º 7
0
static int some_callback(int x)
{
    printf("some_callback(%d)\n", x);
    fflush(stdout);
    return add_rec(x, 9);
}