コード例 #1
0
ファイル: parse_oper.c プロジェクト: colinet/sqlix
/*
 * find_opr_cache_ent
 *
 * Look for a cache entry matching the given key.  If found, return the
 * contained operator OID, else return INVALID_OID.
 */
static oid_t
find_opr_cache_ent(struct opr_cache_key *key)
{
	struct opr_cache_ent *oprentry;

	if (OprCacheHash == NULL) {
		/* First time through: initialize the hash table */
		struct hash_ctl	ctl;

		pg_memset(&ctl, 0, sizeof(ctl));
		ctl.keysize = sizeof(struct opr_cache_key);
		ctl.entrysize = sizeof(struct opr_cache_ent);
		ctl.hash = tag_hash;
		OprCacheHash = hcreate("Operator lookup cache", 256, &ctl, H_ELEM | H_FUNC);

		/* Arrange to flush cache on pg_operator and pg_cast changes */
		register_syscache_cb(OPER_NS, inval_opr_cache_cb, (datum_t) 0);
		register_syscache_cb(CASTSOURCETARGET, inval_opr_cache_cb, (datum_t) 0);
	}

	/* Look for an existing entry */
	oprentry = (struct opr_cache_ent *) hsearch(OprCacheHash, (void *) key, H_FIND, NULL);
	if (oprentry == NULL)
		return INVALID_OID;

	return oprentry->opr_oid;
}
コード例 #2
0
static void create_hash (void)
{
	if (!hcreate (hash_size)){
		perror ("hcreate(3) failed");
		exit (2);
	}
}
コード例 #3
0
ファイル: bug-hsearch1.c プロジェクト: AdvancedC/glibc
static int
do_test (void)
{
  if (hcreate (1) == 0)
    {
      puts ("hcreate failed");
      return 1;
    }
  ENTRY e;
  e.key = (char *) "a";
  e.data = (char *) "b";
  if (hsearch (e, ENTER) == NULL)
    {
      puts ("ENTER failed");
      return 1;
    }
  ENTRY s;
  s.key = (char *) "c";
  if (hsearch (s, FIND) != NULL)
    {
      puts ("FIND succeeded");
      return 1;
    }
  return 0;
}
コード例 #4
0
ファイル: gd_cache.c プロジェクト: Evaliya/fuse-google-drive
/** Creates the hash table for speeding up file finding.
 *
 *  @size the size we want to make this hash table
 *  @head the first gd_fs_entry_t in the list of files
 *
 *  @returns 0 on success, 1 on failure
 */
int create_hash_table(size_t size, const struct gd_fs_entry_t* head)
{
	int ret = hcreate(size);
	if(!ret)
	{
		fprintf(stderr, "hcreate failed\n");
		return 1;
	}

	ENTRY entry;
	struct gd_fs_entry_t *iter = head;
	while(iter != NULL)
	{
		entry.key = iter->filename.str;
		entry.data = iter;

		ENTRY* entered = hsearch(entry, ENTER);
		if(0 && !entered)
		{
			fprintf(stderr, "hsearch: %s\n", strerror(errno));
			destroy_hash_table();
			return 1;
		}

		iter = iter->next;
	}

	return 0;
}
コード例 #5
0
ファイル: svadm.c プロジェクト: 0xffea/illumos-gate
/*
 * Read all sets from the libdscfg configuration file, and store everything in
 * the hashfile.
 *
 * We assume that the config file has been opened & rewound for us.  We store
 * the volume name as the key, and the setnumber where we found it as the data.
 *
 * The caller can pass in a pointer to the maximum number of volumes, or
 * a pointer to NULL, specifying we want 'all' the volumes.  The table is
 * searched using find_in_hash.
 */
static void
create_cfg_hash()
{
	char key[CFG_MAX_KEY], buf[CFG_MAX_BUF];
	char vol[CFG_MAX_BUF], cnode[CFG_MAX_BUF];
	int setnumber;
	ENTRY item;

	if (hcreate((size_t)sv_max_devices) == 0)
		error(NULL, gettext("unable to create hash table"));

	for (setnumber = 1; /* CSTYLED */; setnumber++) {
		(void) snprintf(key, sizeof (key), "sv.set%d", setnumber);
		if (cfg_get_cstring(cfg, key, buf, sizeof (buf)) < 0)
			break;

		if (sscanf(buf, "%s - %s", vol, cnode) != 2) {
			continue;
		}

		item.key = strdup(vol);
		item.data = (void *)setnumber;
		if (hsearch(item, ENTER) == NULL) {
			error(NULL,
			    gettext("unable to add entry to hash table"));
		}
	}
}
コード例 #6
0
ファイル: inc.c プロジェクト: fritzo/inet
int main(int argc, char *argv[])
{
	extern int yyparse();

	const char incname[] = "in.tab.c";
	const char inhname[] = "in.tab.h";

	int error;

	setlocale(LC_ALL, "");

	inh = chkptr(fopen(inhname, "w"), inhname);
	inc = chkptr(fopen(incname, "w"), incname);

	fputs(INBASE "\n", inc);
	fputs(INYANK "\n", inc);
	fputs(INQUEUE "\n", inc);
	fputs(INWIRE "\n", inc);
	fputs(INDETERM "\n", inc);

	chkptr((void *)(intptr_t)hcreate(HASHNEL), "hcreate");
	amb = getagent("amb");
	error = yyparse();

	fputs(INSIM, inc);

	fclose(inh);
	fclose(inc);
	return error;
}
コード例 #7
0
ファイル: hash.c プロジェクト: 1411385476/craft
int
main(void)
{
    ENTRY e, *ep;
    int i;

   hcreate(30);

   for (i = 0; i < 24; i++) {
        e.key = data[i];
        /* data is just an integer, instead of a
           pointer to something */
        e.data = (void *) i;
        ep = hsearch(e, ENTER);
        /* there should be no failures */
        if (ep == NULL) {
            fprintf(stderr, "entry failed\n");
            exit(EXIT_FAILURE);
        }
    }

   for (i = 22; i < 26; i++) {
        /* print two entries from the table, and
           show that two are not in the table */
        e.key = data[i];
        ep = hsearch(e, FIND);
        printf("%9.9s -> %9.9s:%d\n", e.key,
               ep ? ep->key : "NULL", ep ? (int)(ep->data) : 0);
    }
    hdestroy();
    exit(EXIT_SUCCESS);
}
コード例 #8
0
static bool checkPermissions(EntityManager *entityManager) {
  int16_t res;
  char userName[EXP_MAX_USER_NAME];
  const char *resourceName=NULL, *permission=NULL;
  AclPermissionsS *permissionsVec=NULL;
  htab *whoUses=NULL;
  const char *haveStr[] = {"doesn't have", "has"};

  snprintf(userName, sizeof(userName), USER_NAME_FMT, 1);
  resourceName = resourcesList[0];
  Acl_NewPermissionsList("", &permissionsVec);
  Acl_GetAllPermissions(entityManager, resourceName, permissionsVec);
  printf("The permissions for resource '%s' are:\n", resourceName);
  Acl_PrintPermissionsList(stdout, "", permissionsVec);
  Acl_FreePermissionsList(permissionsVec);
  resourceName = resourcesList[1];
  Acl_NewPermissionsList("", &permissionsVec);
  Acl_GetUserPermissions(entityManager, resourceName, userName, &permissionsVec);
  printf("User '%s' has for resource '%s' ", userName, resourceName);
  Acl_PrintPermissionsList(stdout, "", permissionsVec);
  Acl_FreePermissionsList(permissionsVec);
  permission = permissionsList[0];
  res = Acl_CheckEntityPermission(entityManager, resourceName, userName, permission);
  printf("User '%s' %s permission '%s' for resource '%s'\n", userName, haveStr[res], permission, resourceName);
  permission = permissionsList[1];
  res = Acl_CheckEntityPermission(entityManager, resourceName, userName, permission);
  printf("User '%s' %s permission '%s' for resource '%s'\n", userName, haveStr[res], permission, resourceName);
  whoUses = hcreate(H_TAB_SIZE);
  Acl_WhoUseAPermission(entityManager, allPermission, whoUses);
  printf("Users that have permission '%s':\n", allPermission);
  Utils_PrintHashKeys("", "  -", whoUses);
  hdestroy(whoUses);
  return true;
}
コード例 #9
0
ファイル: color.c プロジェクト: sudoman/SpaceDolphin
// create the hashtable that holds color lookup info.
// also set the colors for various objects used in the game.
void initcolors(void)
{
    if (hcreate(HSIZE) == 0) {
	fprintf(stderr, "*** error: failed to create hash table with "
		"max elems: %d\n", HSIZE);
	exit(6);
    }
    // values:          r,g,b,a,            r,g,b,a
    // the first set of colors is for the fill, the second for the border.
    savecs(makecolorset(0,0,0,0,	    1,1,1,1), COLOR_SHIP, P_NONE);
    savecs(makecolorset(0.5,0,1,1,	    1,0,0,1), COLOR_SHIP, P_ONE);
    savecs(makecolorset(1,0.5,0,1,	    1,1,1,1), COLOR_SHIP, P_TWO);

    savecs(makecolorset(0.5,0.5,0.5,1,	    1,1,1,1), COLOR_LARGE, P_NONE);
    savecs(makecolorset(0.5,0,1,1,	    1,1,1,1), COLOR_LARGE, P_ONE);
    savecs(makecolorset(1,0.5,0,1,	    1,1,1,1), COLOR_LARGE, P_TWO);

    savecs(makecolorset(0,0,0,1,	    1,0,0,1), COLOR_SMALL, P_NONE);
    savecs(makecolorset(0,0,1,1,	    1,1,1,1), COLOR_SMALL, P_ONE);
    savecs(makecolorset(1,0,0,1,	    1,1,0,1), COLOR_SMALL, P_TWO);

    savecs(makecolorset(0.10,0.10,0.10,1,
			0.75,0.75,0.75,1), COLOR_BHOLE, P_NONE);
    savecs(makecolorset(1,0,0,1,	    1,1,1,1), COLOR_LINE, P_NONE);


}
コード例 #10
0
ファイル: asn.c プロジェクト: bzruk/mtr
void asn_open(void) {
    if (!hash) {
        IIDEBUG_MSG((LOG_INFO, "hcreate(%d)", maxTTL));
        if (!(hash = hcreate(maxTTL)))
            perror("ipinfo hash");
    }
}
コード例 #11
0
ファイル: pkg_cleanup.c プロジェクト: freenas/ports
/*
 * The hash table is to keep track of leaves which have already been displayed
 * to the user.
 */
int main(int argc, char **argv)
{
	int			i;

	/* Initialize space for blacklist hash table */
	if(hcreate(10000)==0) {
		fputs("Cannot create hash table.\n",stderr);
		return(EX_UNAVAILABLE);
	}

	i=0;
	do {
		if(read_pkglist(i++))
			break;
		if(display_menu())
			break;
		if(remove_packages())
			break;
		free_menu();
	} while(keep_going());
	hdestroy();

	fputs("\nProgram Terminated Successfully\n",stderr);
	return(0);
}
コード例 #12
0
ファイル: lz4.c プロジェクト: raedwulf/dillsocks
int lz4_start(int s) {
    int err;
    /* Check whether underlying socket is message-based. */
    if(dsock_slow(!hquery(s, msock_type))) {err = errno; goto error1;}
    /* Create the object. */
    struct lz4_sock *obj = malloc(sizeof(struct lz4_sock));
    if(dsock_slow(!obj)) {errno = ENOMEM; goto error1;}
    obj->hvfs.query = lz4_hquery;
    obj->hvfs.close = lz4_hclose;
    obj->mvfs.msendv = lz4_msendv;
    obj->mvfs.mrecvv = lz4_mrecvv;
    obj->s = s;
    obj->outbuf = NULL;
    obj->outlen = 0;
    obj->inbuf = NULL;
    obj->inlen = 0;        
    size_t ec = LZ4F_createDecompressionContext(&obj->dctx, LZ4F_VERSION);
    if(dsock_slow(LZ4F_isError(ec))) {err = EFAULT; goto error2;}
    /* Create the handle. */
    int h = hcreate(&obj->hvfs);
    if(dsock_slow(h < 0)) {err = errno; goto error3;}
    return h;
error3:
    ec = LZ4F_freeDecompressionContext(obj->dctx);
    dsock_assert(!LZ4F_isError(ec));
error2:
    free(obj);
error1:
    errno = err;
    return -1;
}
コード例 #13
0
ファイル: main.c プロジェクト: toriumi0118/sandbox
int
main(int argc, char *argv[])
{
    FILE *fp;
    char *mode, *file;
    char *w;
    char buf[MAXLEN];
    struct wordcnt wordcnt[2048];
    int wcount = 0;
    int i;

    if (argc < 3) {
        printf("Usage: %s [123] inputfile\n", argv[0]);
        return 1;
    }

    mode = argv[1];
    file = argv[2];

    if ((fp = fopen(file, "r")) == NULL) {
        printf("file open error: file=%s\n", file);
        return 1;
    }

    hcreate(4096);

    while (getword(fp, buf, MAXLEN) != NULL) {
        ENTRY item, *ip;
        struct wordcnt *wc = &wordcnt[wcount];

        item.key = buf;
        item.data = &wc->cnt;
        if ((ip = hsearch(item, FIND)) == NULL) {
            int len = strnlen(buf, MAXLEN);
            char *key = (char *) malloc(sizeof (char) * len);

            strncpy(key, buf, MAXLEN);
            item.key = key;
            wc->word = key;
            wc->cnt = 1;

            hsearch(item, ENTER);
            wcount++;
        } else {
            *((int *) ip->data) += 1;
        }
    }

    qsort(wordcnt, wcount, sizeof (struct wordcnt), wccmp);
    for (i = 0; i < wcount; i++) {
        struct wordcnt *wc = &wordcnt[i];
        printf("% 4d: %s\n", wc->cnt, wc->word);
    }

    hdestroy();

    fclose(fp);

    return 0;
}
コード例 #14
0
ファイル: util_dp_fasta_nw.c プロジェクト: cbcrg/tcoffee
HaschT* hasch_sequence ( char *seq1, int ktup)
{
  char c;
  int key, offset=0, ls;
  HaschT *H;
  Hasch_entry *e;

  H=hcreate ( strlen (seq1), declare_ktup_hasch_data, free_ktup_hasch_data);
  ls=strlen (seq1);
  while (ls>=(ktup))
    {
      c=seq1[ktup];seq1[ktup]='\0';
      key=string2key (seq1, NULL);
      e=hsearch (H,key,FIND, declare_ktup_hasch_data, free_ktup_hasch_data);

      if (e==NULL)
	{
	 e=hsearch (H,key,ADD,declare_ktup_hasch_data,free_ktup_hasch_data);
	 (e->data)->list[++(e->data)->list[1]+1]=offset;
	}
      else
	{
	  if ((e->data)->list[0]==((e->data)->list[1]+2)){(e->data)->list[0]+=10;(e->data)->list=(int*)vrealloc ((e->data)->list,(e->data)->list[0]*sizeof (int));}
	  (e->data)->list[++(e->data)->list[1]+1]=offset;
	}
       seq1[ktup]=c;seq1++;ls--;
       offset++;
    }
  return H;
}
コード例 #15
0
ファイル: asn.c プロジェクト: russor/mtr
void asn_open(
    struct mtr_ctl *ctl)
{
    if (ctl->ipinfo_no >= 0) {
        DEB_syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI);
        if (!(iihash = hcreate(IIHASH_HI)))
            error(0, errno, "ipinfo hash");
    }
}
コード例 #16
0
ファイル: asn.c プロジェクト: RichiH/mtr
void asn_open(void) {
    if (ipinfo_no >= 0) {
#ifdef IIDEBUG
        syslog(LOG_INFO, "hcreate(%d)", IIHASH_HI);
#endif
        if (!(iihash = hcreate(IIHASH_HI)))
            perror("ipinfo hash");
    }
}
コード例 #17
0
ファイル: utree.c プロジェクト: xflouris/newick-tools
static utree_t * find_outgroup_mrca(utree_t ** node_list,
                                    utree_t * root,
                                    char * outgroup_list,
                                    int tip_count)
{
  int i;
  utree_t * outgroup;

  char * taxon;
  size_t taxon_len;

  ENTRY * found = NULL;

  /* create a hashtable of tip labels */
  hcreate(2 * tip_count);
  for (i = 0; i < tip_count; ++i)
  {
    ENTRY entry;
    entry.key  = node_list[i]->label;
    entry.data = node_list[i];
    hsearch(entry,ENTER);
  }

  while (*outgroup_list)
  {
    taxon_len = strcspn(outgroup_list, ",");
    if (!taxon_len)
      fatal("Erroneous outgroup format (double comma)/taxon missing");

    taxon = strndup(outgroup_list, taxon_len);

    /* find the taxon in the hash table */
    ENTRY query;
    query.key = taxon;
    found = NULL;
    found = hsearch(query,FIND);
    
    if (!found)
      fatal("Taxon %s in --outgroup does not appear in the tree", taxon);

    ((utree_t *)(found->data))->mark = 1;
    printf("\t%s\n", taxon);

    free(taxon);
    outgroup_list += taxon_len;
    if (*outgroup_list == ',') 
      outgroup_list += 1;
  }

  printf("Label: %s\n", ((utree_t *)(found->data))->label);
  outgroup = outgroup_node(((utree_t *)(found->data))->back);

  hdestroy();
  
  return outgroup;
}
コード例 #18
0
void testValues() {
    f = 2;
    ENTRY* result;
    if (!hcreate(anysize())) {return;}
    
    result = hsearch(anyentry(), FIND);
    //@ assert result == \null || \valid(result);
    
    //@ assert f == 2;
    //@ assert vacuous: \false;
}
コード例 #19
0
ファイル: xlog_utils.c プロジェクト: colinet/sqlix
/* Log a reference to an invalid page */
static void
log_invalid_page(struct fnode node,
	enum fork forkno,
	block_t blkno,
	bool present)
{
	xl_invalid_page_key key;
	xl_invalid_page *hentry;
	bool found;

	/*
	 * Log references to invalid pages at DEBUG1 level.  This allows some
	 * tracing of the cause (note the elog context mechanism will tell us
	 * something about the XLOG record that generated the reference).
	 */
	if (log_min_messages <= DEBUG1 || client_min_messages <= DEBUG1) {
		char *path = relpathperm(node, forkno);

		if (present)
			elog(DEBUG1, "page %u of relation %s is uninitialized", blkno, path);
		else
			elog(DEBUG1, "page %u of relation %s does not exist", blkno, path);

		pfree(path);
	}

	if (invalid_page_tab == NULL) {
		/* create hash table when first needed */
		struct hash_ctl	ctl;

		memset(&ctl, 0, sizeof(ctl));
		ctl.keysize = sizeof(xl_invalid_page_key);
		ctl.entrysize = sizeof(xl_invalid_page);
		ctl.hash = tag_hash;

		invalid_page_tab = hcreate("XLOG invalid-page table", 100, &ctl, H_ELEM | H_FUNC);
	}

	/* we currently assume xl_invalid_page_key contains no padding */
	key.node = node;
	key.forkno = forkno;
	key.blkno = blkno;
	hentry = (xl_invalid_page *)
		hsearch(invalid_page_tab, (void *) &key, H_ENTER, &found);

	if (!found) {
		/* hsearch already filled in the key */
		hentry->present = present;
	} else {
		/* repeat reference ... leave "present" as it was */
	}
}
コード例 #20
0
ファイル: pgtz.c プロジェクト: colinet/sqlix
static bool
init_timezone_hashtable(void)
{
	struct hash_ctl	hash_ctl;

	pg_memset(&hash_ctl, 0, sizeof(hash_ctl));
	hash_ctl.keysize = TZ_STRLEN_MAX + 1;
	hash_ctl.entrysize = sizeof(pg_tz_cache);
	timezone_cache = hcreate("Timezones", 4, &hash_ctl, H_ELEM);
	if (!timezone_cache)
		return false;

	return true;
}
コード例 #21
0
ファイル: io.c プロジェクト: seeslab/rgraph
int
AssignNodesToModulesFromFile(FILE *inF,
                             Partition *part,
                             char **labels) {
    char label[MAX_LABEL_LENGTH];
    char sep[2];
    int j = 0, nfields = 0, nnode = part->N;
    hcreate(part->N);
    int i;
    ENTRY e, *ep;

    for (i=0; i<nnode; i++) {
        e.key = labels[i];
        e.data = (void *) i;
        ep = hsearch(e, ENTER);
    }

    while (!feof(inF)) {
        nfields=fscanf(inF,"%[^\t\n]%[\t\n]",&label,&sep);
        if (nfields) {
            e.key = label;
            ep = hsearch(e, FIND);
            i = (int) ep->data;
            nnode--;

            if (!part->modules[j]->size) {
                part->nempty --;
                part->nodes[i]->module = j;
                part->modules[j]->size = 1;
                part->modules[j]->strength = part->nodes[i]->strength;
                part->modules[j]->first = part->nodes[i];
                part->modules[j]->last = part->nodes[i];
            }
            else {
                part->nodes[i]->module = j;
                part->modules[j]->size++;
                part->modules[j]->strength += part->nodes[i]->strength;
                part->modules[j]->last->next = part->nodes[i];
                part->nodes[i]->prev = part->modules[j]->last;
                part->modules[j]->last = part->nodes[i];
            }
            if(sep[0]=='\n')
                j++;
        }
    }

    CompressPartition(part);
    hdestroy();
    return nnode;
}
コード例 #22
0
int main (int argc, char * argv[])
{
	int		i;
	ENTRY	entree;
	ENTRY *	trouve;

	if (argc < 2) {
		fprintf(stderr, "Syntaxe : %s [mois | jour]\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	/* 12 mois + 7 jours */
	if (hcreate(19) == 0) { 
		perror("hcreate");
		exit(EXIT_FAILURE);
	}
	ajoute_entree("janvier",   "january");
	ajoute_entree("fevrier",   "february");
	ajoute_entree("mars",      "march");
	ajoute_entree("avril",     "april");
	ajoute_entree("mai",       "may");
	ajoute_entree("juin",      "june");
	ajoute_entree("juillet",   "july");
	ajoute_entree("aout",      "august");
	ajoute_entree("septembre", "september");
	ajoute_entree("octobre",   "october");
	ajoute_entree("novembre",  "november");
	ajoute_entree("decembre",  "december");
	ajoute_entree("lundi",     "monday");
	ajoute_entree("mardi",     "tuesday");
	ajoute_entree("mercredi",  "wednesday");
	ajoute_entree("jeudi",     "thursday");
	ajoute_entree("vendredi",  "friday");
	ajoute_entree("samedi",    "satursday");
	ajoute_entree("dimanche",  "sunday");

	for (i = 1; i < argc; i ++) {
		entree.key = argv[i];
		fprintf(stdout, "%s -> ", argv[i]);
		trouve = hsearch(entree, FIND);
		if (trouve == NULL)
			fprintf(stdout, "pas dans la liste \n");
		else
			fprintf(stdout, "%s\n", (char *)trouve->data);
	}
	hdestroy();

	return EXIT_SUCCESS;
}
コード例 #23
0
static int hashTableInit(void)
{
    if (!hashTableInited) {
        LOCK_HASH_TABLE();
        if (!hashTableInited) {
            if (hcreate(MAX_HASH_TABLE_ELEM) == 0) {
                fprintf(stderr, "error creating hashtable, <%d>: %s\n",
                        errno, strerror(errno));
                return 0;
            } 
            hashTableInited = 1;
        }
        UNLOCK_HASH_TABLE();
    }
    return 1;
}
コード例 #24
0
ファイル: hash.c プロジェクト: bsdcpp/mylib
int main(int argc, char* argv[])
{
    int i = 0;
    ENTRY e, *ep, *ep2;
    FILE *fp;
    char buf[MAXBUF];
    char num[15];

    hcreate(1);

    fp = Fopen("/home/jervis/csapp/tinyweb/data/kj20100602.txt", "r");

    memset(buf, 0, MAXBUF);
    while (Fgets(buf, 50, fp))
    {
        i++;
        if (i >100)
            break;
        memset(num, 0, sizeof(num));
        strncpy(num, buf, 3);
        e.key = num;
        printf("[%s][%d]\n", e.key, strlen(e.key));
        e.data = (void *)i;
        if ((ep = hsearch(e, FIND)) != NULL) {
            printf("第%d个[%s]与%d个[%s]重复\n", i, e.key, (int)(ep->data), ep->key);
        } else {
            printf("------------------------\n");
            printf("[%s][%d]\n\n", e.key, strlen(e.key));
            if ((ep2 = hsearch(e, ENTER)) != NULL) {
                /* printf("插入%s=>%d\n", ep2->key, (int)(ep2->data)); */
            } else {
                perror("table full");
                exit(EXIT_FAILURE);
            }
        }
    }
    printf("===================\n");
    e.key = "677";
    printf("[%s][%d]\n", e.key, strlen(e.key));
    if ((ep = hsearch(e, FIND)) != NULL) {
        printf("find %d => %s\n", (int)(ep->data), ep->key);
    }
    hdestroy();
    Fclose(fp);
    return 0;
}
コード例 #25
0
ファイル: rtvarcmds.c プロジェクト: DanIverson/OpenVnmrJ
int init_rtvars(char *filename, int number)
{
   int i,rtvar_value;
   ENTRY item;
   char *str_ptr;

   /* Initialize data areas */
   rtvarname_ptr = (char *)malloc(number*20);
   if (rtvarname_ptr == NULL) return (0);
   memset(rtvarname_ptr, 0, (number*20));

   info_ptr = (struct info *)malloc(sizeof(struct info)*number);

   /* Open rtvar info file */
   rtvarfile = fopen(filename,"r");
   if (rtvarfile == NULL)
   {  fprintf(stderr,"init_rtvars: cannot open %s\n",filename);
      return(0);			/* return failure */
   }

   /* create table */
   i = 0;
   str_ptr = rtvarname_ptr;
   hdestroy();			/* first destroy any previous table */
   (void) hcreate(number);
   while (fscanf(rtvarfile,"%s%d%d", str_ptr, &rtvar_value,
           &info_ptr->index) != EOF && i++ < number) {
              /* put info in structure, and structure in item */
         item.key = str_ptr;
         item.data = (void *)info_ptr;
         str_ptr += strlen(str_ptr) + 1;
         info_ptr++;
   	 /* put item into table */
         (void) hsearch(item, ENTER);
   }
   fclose(rtvarfile);
   if (i < number){
	 max_rtvars = i;
   }
   else {
	hdestroy();
	return(-1);
   }
   rtvarinfo_exist = 1;
   return(i);
}
コード例 #26
0
ファイル: rpp.c プロジェクト: andrew-m-h/rpeANUt-C
int main(int argc, char* argv[]){
    hcreate(100);
    ++argv, --argc;  /* skip over program name */

    if ( argc > 0 )
        yyin = fopen( argv[0], "r" );
    else
        yyin = stdin;
    do {
        yyparse();
    } while (!feof(yyin));

    printf("%s", outputFile);

    hdestroy();

    return EXIT_SUCCESS;
}
コード例 #27
0
int main(int argc, char **argv)
{
        char *corrected_word;
        ENTRY dict;
        
        hcreate(DICT_SZ);
        
        if (!read_file(dict))
                return -1;
        
        corrected_word = correct(argv[1]);
        if (strcmp(corrected_word, argv[1])) {
                printf("Did you mean \"%s\"?\n", corrected_word);
        } else {
                printf("\"%s\" is correct!\n", argv[1]);
        }
        
        return 0;
}
コード例 #28
0
ファイル: pssvg.c プロジェクト: collinanderson/cptutils
static int pssvg_convert_all(grd5_t *grd5,
			     svgset_t *svgset,
			     gstack_t *gstack,
			     pssvg_opt_t opt)
{
  size_t n = grd5->n;

  if (opt.title == NULL)
    {
      /*
	In the case that titles are not autogenerated then we
	need to fix mutiple titles in the grd input (which is
	common) so that the output SVG titles are unique.  We
	do this by appending _2, _3, ... to repeated titles.
	So we need to keep track of how many occurenced of
	each title we have seen so far.  The appropriate data
	structure is an associative array or hashmap, but
	we don't really want to add another dependancy to the
	package; so we use the limited features of the POSIX
	hsearch(3).

	Note that we do not call hdestroy() since that calls
	free() on the keys on some Unixes (BSD for example)
	and we only have at worst a few kB of keys, it does
	not seem worth the while to set up the conditional
	compilation.
      */

      if (hcreate((size_t)ceil(1.25*n)) == 0)
	{
	  btrace("error in hcreate: %s", strerror(errno));
	  return 1;
	}
    }

  for (size_t i = 0 ; i < n ; i++)
    {
      if (pssvg_convert_ith(grd5, i, gstack, opt) != 0)
	return 1;
    }

  return 0;
}
コード例 #29
0
ファイル: nagle.c プロジェクト: raedwulf/dillsocks
int nagle_start(int s, size_t batch, int64_t interval) {
    int rc;
    int err;
    /* Check whether underlying socket is a bytestream. */
    if(dsock_slow(!hquery(s, bsock_type))) {err = errno; goto error1;}
    /* Create the object. */
    struct nagle_sock *obj = malloc(sizeof(struct nagle_sock));
    if(dsock_slow(!obj)) {err = ENOMEM; goto error1;}
    obj->hvfs.query = nagle_hquery;
    obj->hvfs.close = nagle_hclose;
    obj->bvfs.bsendv = nagle_bsendv;
    obj->bvfs.brecvv = nagle_brecvv;
    obj->s = s;
    obj->buf = malloc(batch);
    if(dsock_slow(!obj->buf)) {errno = ENOMEM; goto error2;}
    obj->sendch = channel(sizeof(struct nagle_vec), 0);
    if(dsock_slow(obj->sendch < 0)) {err = errno; goto error3;}
    obj->ackch = channel(sizeof(int), 0);
    if(dsock_slow(obj->ackch < 0)) {err = errno; goto error4;}
    obj->sender = go(nagle_sender(s, batch, interval,
        obj->buf, obj->sendch, obj->ackch));
    if(dsock_slow(obj->sender < 0)) {err = errno; goto error5;}
    /* Create the handle. */
    int h = hcreate(&obj->hvfs);
    if(dsock_slow(h < 0)) {err = errno; goto error6;}
    return h;
error6:
    rc = hclose(obj->sender);
    dsock_assert(rc == 0);
error5:
    rc = hclose(obj->ackch);
    dsock_assert(rc == 0);
error4:
    rc = hclose(obj->sendch);
    dsock_assert(rc == 0);
error3:
    free(obj->buf);
error2:
    free(obj);
error1:
    errno = err;
    return -1;
}
コード例 #30
0
ファイル: mthrottler.c プロジェクト: raedwulf/dillsocks
int mthrottler_start(int s,
      uint64_t send_throughput, int64_t send_interval,
      uint64_t recv_throughput, int64_t recv_interval) {
    if(dsock_slow(send_throughput != 0 && send_interval <= 0 )) {
        errno = EINVAL; return -1;}
    if(dsock_slow(recv_throughput != 0 && recv_interval <= 0 )) {
        errno = EINVAL; return -1;}
    /* Check whether underlying socket is message-based. */
    if(dsock_slow(!hquery(s, msock_type))) return -1;
    /* Create the object. */
    struct mthrottler_sock *obj = malloc(sizeof(struct mthrottler_sock));
    if(dsock_slow(!obj)) {errno = ENOMEM; return -1;}
    obj->hvfs.query = mthrottler_hquery;
    obj->hvfs.close = mthrottler_hclose;
    obj->mvfs.msendv = mthrottler_msendv;
    obj->mvfs.mrecvv = mthrottler_mrecvv;
    obj->s = s;
    obj->send_full = 0;
    if(send_throughput > 0) {
        obj->send_full = send_throughput * send_interval / 1000;
        obj->send_remaining = obj->send_full;
        obj->send_interval = send_interval;
        obj->send_last = now();
    }
    obj->recv_full = 0;
    if(recv_throughput > 0) {
        obj->recv_full = recv_throughput * recv_interval / 1000;
        obj->recv_remaining = obj->recv_full;
        obj->recv_interval = recv_interval;
        obj->recv_last = now();
    }
    /* Create the handle. */
    int h = hcreate(&obj->hvfs);
    if(dsock_slow(h < 0)) {
        int err = errno;
        free(obj);
        errno = err;
        return -1;
    }
    return h;
}