/*================================================================= * finish_and_delete_refnset -- check for dups in a set of one refn * soundexseq is sequence of REFNs all in the same block (equivalent * names as far as REFN storage goes) * Created: 2001/01/13, Perry Rapp *===============================================================*/ static void finish_and_delete_refnset (void) { char prevkey[8]; CNSTRING refn=""; CNSTRING skey=""; TABLE table = create_table_int(); prevkey[0]=0; canonkeysort_indiseq(soundexseq); FORINDISEQ(soundexseq, el, num) refn = element_sval(el); skey = element_skey(el); if (!eqstr(skey, prevkey)) { /* new person, start over */ destroy_table(table); table = create_table_int(); } if (in_table(table, refn)) { report_error(ERR_DUPREFN, _("Duplicate refn for %s (%s)") , skey, refn); } else { insert_table_int(table, refn, 1); } strcpy(prevkey, skey); ENDINDISEQ remove_indiseq(soundexseq); soundexseq = NULL; destroy_table(table); }
/*================================================================= * finish_and_delete_nameset -- check for dups in a set of one name * soundexseq is sequence of NAMEs all in the same block (equivalent * names as far as NAME storage goes) * Created: 2001/01/13, Perry Rapp *===============================================================*/ static void finish_and_delete_nameset (void) { char prevkey[8]; CNSTRING name=""; CNSTRING skey=""; TABLE table = create_table_int(); prevkey[0]=0; calc_indiseq_names(soundexseq); keysort_indiseq(soundexseq); /* We go thru the list of equivalent names, sorted by person, and for each person, table all their names, watching for duplicates */ FORINDISEQ(soundexseq, el, num) name = element_sval(el); skey = element_skey(el); if (!eqstr(skey, prevkey)) { /* new person, start over */ destroy_table(table); table = create_table_int(); } if (in_table(table, name)) { report_error(ERR_DUPNAME, _("Duplicate name for %s (%s)") , skey, name); } else { insert_table_int(table, name, 1); } strcpy(prevkey, skey); ENDINDISEQ remove_indiseq(soundexseq); soundexseq = NULL; destroy_table(table); }
void process_dest_unreach(struct tcptable *table, char *packet, char *ifname, int *nomem) { struct iphdr *ip; struct tcphdr *tcp; struct tcptableent *tcpentry; ip = (struct iphdr *) (packet + 8); if (ip->protocol != IPPROTO_TCP) return; tcp = (struct tcphdr *) (packet + 8 + (ip->ihl * 4)); /* * We really won't be making use of nomem here. Timeout checking * won't be performed either, so we just pass NULL as the pointer * to the configuration structure. in_table() will recognize this * and set its internal timeout variable to 0. */ tcpentry = in_table(table, ip->saddr, ip->daddr, ntohs(tcp->source), ntohs(tcp->dest), ifname, 0, NULL, nomem, NULL); if (tcpentry != NULL) { tcpentry->stat = tcpentry->oth_connection->stat = FLAG_RST; addtoclosedlist(table, tcpentry, nomem); } }
void process_dest_unreach(struct tcptable *table, char *packet, char *ifname) { struct iphdr *ip; struct ip6_hdr *ip6; struct tcphdr *tcp; struct tcptableent *tcpentry; ip = (struct iphdr *) (packet + 8); /* * Timeout checking won't be performed either, so we just pass 0 * as timeout variable. */ if (ip->version == 6) { ip6 = (struct ip6_hdr *) (packet + 8); if (ip6->ip6_nxt != IPPROTO_TCP) return; tcp = (struct tcphdr *) (packet + 48); struct sockaddr_storage saddr, daddr; sockaddr_make_ipv6(&saddr, &ip6->ip6_src); sockaddr_set_port(&saddr, ntohs(tcp->source)); sockaddr_make_ipv6(&daddr, &ip6->ip6_dst); sockaddr_set_port(&daddr, ntohs(tcp->dest)); tcpentry = in_table(table, &saddr, &daddr, ifname, 0, NULL, 0); } else { if (ip->protocol != IPPROTO_TCP) return; tcp = (struct tcphdr *) (packet + 8 + (ip->ihl * 4)); struct sockaddr_storage saddr, daddr; sockaddr_make_ipv4(&saddr, ip->saddr); sockaddr_set_port(&saddr, ntohs(tcp->source)); sockaddr_make_ipv4(&daddr, ip->daddr); sockaddr_set_port(&daddr, ntohs(tcp->dest)); tcpentry = in_table(table, &saddr, &daddr, ifname, 0, NULL, 0); } if (tcpentry != NULL) { tcpentry->stat = tcpentry->oth_connection->stat = FLAG_RST; addtoclosedlist(table, tcpentry); } }
void add_pairs(const sp_table *ss) { sp_table *sp=ss; while(sp!=NULL){ if(is_pair(sp->str_one) && !in_table(sp->str_one, SP_STR)) sp=sp->next; } }
inline int in_punct(char c, chinput_symbol *chinput_corner, int nchinput_corner) { if(ispunct(c) || isspace(c)) { int item; item = in_table(c, chinput_corner, nchinput_corner); return item; } else return -1; }
inline int in_alnum(char c, chinput_symbol *chinput_corner, int nchinput_corner) { if(isalnum(c)) { int item; item = in_table(c, chinput_corner, nchinput_corner); return item; } else return -1; }
int main() { int buf_len = BUFLEN; //char buf[buf_len], *wordptr; char *wordptr; //buf[0] = '\0'; char * buffer = calloc(BUFLEN, sizeof(char)); /* ... set up word filing module ... */ init_table(); /* ... read words and store them ... */ /* was: scanf("%s", buf) */ while ( (buffer = read_word(buffer, &buf_len)) != NULL ){ if (DEBUG) printf("buf = %s, buf_len: %d\n", buffer, buf_len); convert_to_lower_case( buffer ); if ( in_table( buffer ) == YES ) { if (DEBUG) printf("main: found %s in table with a value of %d ", buffer, lookup( buffer )); update( buffer, 1 + lookup( buffer ) ); } else if ( insert( buffer, 1 ) == NO ){ fprintf(stderr,"wordfreq: out of memory\n"); exit(1); } } /* ... move cursor down the table printing out results */ if (DEBUG) printf("printing the results starting with %s \n", firstword()); for( wordptr = firstword() ; wordptr != NULL; wordptr = nextword() ) printf("%5d\t%s\n", lookup( wordptr ), wordptr ); //char hello[] = "hello"; //word_delete(hello); return 0; }
inline char* chinput_get_reply_corner_punct(char c, chinput_symbol *chinput_corner, int nchinput_corner) { if(!chinput_corner || nchinput_corner <= 0) return NULL; int item; item = in_table(c, chinput_corner, nchinput_corner); if(item != -1) { if(chinput_corner[item].num == 1) return Sstrdup(chinput_corner[item].s); else { char* tmp_utf8 = NULL; const char *tmp1 = chinput_corner[item].s; const char *tmp2 = NULL; if(chinput_corner[item].cur < 0 || chinput_corner[item].cur >= chinput_corner[item].num) chinput_corner[item].cur = 0; for(int i = 0; i <= chinput_corner[item].cur; i++) { uint len; tmp2 = __utf8_next_char(tmp1); if(!*tmp2) len = strlen(tmp1); else len = strlen(tmp1) - strlen(tmp2); if(tmp_utf8) delete[] tmp_utf8; tmp_utf8 = Sstrdup(tmp1, len); tmp1 += len; if(!tmp_utf8) break; if(!*tmp2) break; } chinput_corner[item].cur ++; if(chinput_corner[item].cur >= chinput_corner[item].num) chinput_corner[item].cur = 0; return tmp_utf8; } } else return NULL; }
void split_1234(const char *s, int n,sp_table **sp) { //split to 1, class A char s1[20]; sp_table *snew; int i; for(i=0;i<strlen(s)-n+1;i++){ strncpy(s1,s+i,n); *(s1+n)='\0'; if(!in_table(s1,*sp)){ snew=(sp_table *)malloc(sizeof(sp_table)); snew->next=*sp; strcpy(snew->str_one,s1); *sp=snew; } //printf("%s\n",s1); } }
/*========================================= * check_index -- Validate one index node of btree * Created: 2003/09/05, Perry Rapp *=======================================*/ static BOOLEAN check_index (BTREE btr, INDEX index, TABLE fkeytab, RKEY * lo, RKEY * hi) { INT n = nkeys(index); INT i; if (!check_keys((BLOCK)index, lo, hi)) return FALSE; for (i = 0; i <= n; i++) { INDEX newix=0; char scratch[200]; FKEY fkey = fkeys(index, i); RKEY *lox, *hix; get_index_file(scratch, btr, fkey); if (in_table(fkeytab, scratch)) { printf(_("Cycle in indexes, file %s found again!\n"), scratch); return FALSE; } else { insert_table_int(fkeytab, scratch, 1); } newix = readindex(btr, fkey, TRUE); if (!newix) { printf(_("Error loading index at key")); printf("%ld\n", i); printblock((BLOCK)index); } /* figure upper & lower bounds of what keys should be in the child */ lox = (i==0 ? lo : &rkeys(index, i)); hix = (i==n ? hi : &rkeys(index, i+1)); if (ixtype(newix) == BTINDEXTYPE) { if (!check_index(btr, newix, fkeytab, lox, hix)) return FALSE; } else { if (!check_block((BLOCK)newix, lox, hix)) return FALSE; } } /* TODO: use fkeytab */ return TRUE; }