Beispiel #1
0
/*
 * tick_wstat()
 *	Allow writing of supported stat messages
 */
void
tick_wstat(struct msg *m, struct file *f)
{
	char *field, *val;

	/*
	 * See if common handling code can do it
	 */
	if (do_wstat(m, NULL, ACC_CHMOD, &field, &val) == 0)
		return;

	/*
	 * Start perhaps participating in the select() protocol.
	 */
	if (sc_wstat(m, &f->f_selfs, field, val) == 0) {
		if (f->f_selfs.sc_mask && !f->f_sentry) {
			f->f_sentry = ll_insert(&selectors, f);
		}
		return;
	}

	/*
	 * Not a field we support
	 */
	msg_err(m->m_sender, EINVAL);
}
Beispiel #2
0
    int
permitted_create( struct exp_addr *e_addr, char **permitted )
{
    int                                 idx;
    char                                *namedup;

    if (( permitted != NULL ) && (( *permitted ) != NULL )) {
        /*
        ** Normalize the permitted group list
        ** normalization happens "in-place"
        */
        for ( idx = 0; permitted[idx] != NULL; idx++ ) {
            dn_normalize_case( permitted[idx] );

            namedup = strdup( permitted[idx] );

            if ( ll_insert( &e_addr->e_addr_ok, namedup, namedup,
                    NULL ) != 0 ) {
                return( 1 );
            }
        }
    }

    return( 0 );
}
Beispiel #3
0
int main(void) {
  LinkedList* list = ll_new(0);
  for(size_t i =1;i<=5;i++)
    ll_insert(list,i,i-1);
  ll_print(list);
  
  list = ll_reverse(list);
  ll_print(list);

  ll_free(list);
  return EXIT_SUCCESS;
}
Beispiel #4
0
int cache_add_element(cache_t *c, struct ce_t *obj, int locked)
{
	accessed_cache(c);
	if(!locked) rwlock_acquire(c->rwl, RWL_WRITER);
	
	chash_add(c->hash, obj->id, obj->key, obj);
	obj->list_node = ll_insert(&c->primary_ll, obj);
	c->count++;
	obj->acount=1;
	if(!locked) rwlock_release(c->rwl, RWL_WRITER);
	return 0;
}
Beispiel #5
0
int main( int argc, char** argv){
  int d = 0, quit = 1, commandNum, numRead;
  char *input, command;
  Line l = line_init(stdin);
  Ll ll = ll_init();

  gen_parse_args( argc, argv, &d);

  while( quit){
    printf("Command: ");
    line_read_line( l);
    input = get_line( l);
    sscanf(input, " %c%n", &command, &numRead);
    switch( command){
      case 'q': quit = 0; break;
      case 'i': if( gen_exists_num( input+numRead) ){
                sscanf(input+numRead, "%d", &commandNum);
                ll_insert( ll, commandNum , d);
              }
              else printf("Sorry, you didn't enter a number!\n");
              break;
      case 'd': if( gen_exists_num( input+numRead) ){
                sscanf( input+numRead, "%d", &commandNum);
                ll_delete( ll, commandNum, d);
              }
              else printf("Sorry, you didn't enter a number!\n");
              break;
      case 'c': if( gen_exists_num( input+numRead) ){
                  sscanf( input+numRead, "%d", &commandNum);
                  if( ll_contains( ll, commandNum, d) )
                    printf("LIST DOES CONTAIN %d\n", commandNum);
                  else printf("LIST DOES NOT CONATAIN %d\n", commandNum);
                }
                else printf("Sorry, you didn't enter a number!\n");
                break;
      case 'e': ll_empty( ll, d); break;
      case 'l': ll_print( ll, d); break;
      case 'r': ll_print_rev( ll, d); break;
      case '?': gen_print_help(); break;
      case 'h': gen_print_help(); break;
      case '\n': break;
      default: printf("Invalid Command\n");
    }
    free( input);    
  }

  ll_free( ll, d);
  line_free( l);
  return 0;
}
main() {
    int n = 0, i = 0, data = 0;
    node *head = NULL;

    printf("Enter the number of elements to insert: ");
    scanf("%d", &n);
    for(i = 0; i < n; i++) {
        scanf("%d", &data);
        ll_insert(&head, data);
    }

    ll_print(head);
    ll_recursive_reverse(&head);
    ll_print(head);
}
Beispiel #7
0
llist * ll_filter(llist * list, ll_filter_f * f){
    llist * iter 	= NULL;
    llist * result 	= NULL;
    
    assert(f != NULL);
    
    if (list == NULL || f == NULL)
		return NULL;

    for (iter = list; iter != NULL; iter = ll_next(iter))
        if ((*f)(iter->val, iter->size))
            result = result ? result : ll_insert(result, iter->val, iter->size);

    return result;
}
Beispiel #8
0
void exit(int code)
{
	if(!current_task || current_task->pid == 0) 
		panic(PANIC_NOSYNC, "kernel tried to exit");
	task_t *t = (task_t *)current_task;
	/* Get ready to exit */
	assert(t->thread->magic == THREAD_MAGIC);
	ll_insert(kill_queue, (void *)t);
	raise_flag(TF_EXITING);
	if(code != -9) 
		t->exit_reason.cause = 0;
	t->exit_reason.ret = code;
	t->exit_reason.pid = t->pid;
	/* Clear out system resources */
	free_thread_specific_directory();
	/* tell our parent that we're dead */
	if(t->parent)
		do_send_signal(t->parent->pid, SIGCHILD, 1);
	if(!sub_atomic(&t->thread->count, 1))
	{
		/* we're the last thread to share this data. Clean it up */
		close_all_files(t);
		if(t->thread->root)iput(t->thread->root);
		if(t->thread->pwd) iput(t->thread->pwd);
		mutex_destroy(&t->thread->files_lock);
		void *addr = t->thread;
		t->thread = 0;
		kfree(addr);
	}
	/* don't do this while the state is dead, as we may step on the toes of waitpid.
	 * this fixes all tasks that are children of current_task, or are waiting
	 * on current_task. For those waiting, it signals the task. For those that
	 * are children, it fixes the 'parent' pointer. */
	search_tqueue(primary_queue, TSEARCH_EXIT_PARENT | TSEARCH_EXIT_WAITING, 0, 0, 0, 0);
	char flag_last_page_dir_task;
	/* is this the last task to use this pd_info? */
	flag_last_page_dir_task = (sub_atomic(&pd_cur_data->count, 1) == 0) ? 1 : 0;
	if(flag_last_page_dir_task) {
		/* no one else is referencing this directory. Clean it up... */
		free_thread_shared_directory();
		vm_unmap(PDIR_DATA);
		raise_flag(TF_LAST_PDIR);
	}
	set_as_dead(t);
	for(;;) schedule();
}
Beispiel #9
0
cache_t *get_empty_cache(int (*sync)(struct ce_t *), char *name)
{
	cache_t *c = (void *)kmalloc(sizeof(cache_t));
	c->sync = sync;
	c->syncing=0;
	c->dirty=0;
	c->rwl = rwlock_create(0);
	c->count=0;
	c->slow=1000;
	c->hash = chash_create(100000);
	strncpy(c->name, name, 32);
	ll_create(&c->dirty_ll);
	ll_create(&c->primary_ll);
	ll_insert(cache_list, c);
	
	printk(0, "[cache]: Allocated new cache '%s'\n", name);
	return c;
}
Beispiel #10
0
int ht_insert(struct hash_table *ht, void *key, void *value){
	unsigned int hash;
	int ret;

	hash = ht->hash(key, ht->keysz) % ht->size;

	if(ht->table[hash] == NULL){ /* Nothing at this index */
		ht->table[hash] = ll_create(ht->keysz, ht->valsz, ht->key_compare);
		if(ht->table[hash] == NULL)
            return -1;
	}

	ret = ll_insert(ht->table[hash], key, value, 0);
	if(ret)
        return -1;

	return 0;
}
Beispiel #11
0
ext2_fs_t *get_new_fsvol()
{
	ext2_fs_t *fs = (ext2_fs_t *)kmalloc(sizeof(ext2_fs_t));
	fs->flag=add_atomic(&fs_num, 1);
	fs->sb = (ext2_superblock_t *)kmalloc(1024);
	fs->block_prev_alloc=0;
	fs->read_only=0;
	fs->m_node = mutex_create(0, 0);
	fs->m_block = mutex_create(0, 0);
	mutex_create(&fs->bg_lock, 0);
	mutex_create(&fs->fs_lock, 0);
	mutex_create(&fs->ac_lock, 0);
	char tm[32];
	sprintf(tm, "ext2-%d", fs_num);
	fs->cache = get_empty_cache(0, tm);
	fs->llnode = ll_insert(fslist, fs);
	return fs;
}
Beispiel #12
0
void ll_prepend(lnklist* ll, void* data)
    { ll_insert(ll, 0, data); }
Beispiel #13
0
int main(int argc, char *argv[]) {
    char buf[1024];
    char *p;
    LinkedList *ll;
    long i, n;
    FILE *fd;
    char **array;
    Iterator *it;

    if (argc != 2) {
        fprintf(stderr, "usage: ./lltest file\n");
        return -1;
    }
    if ((ll = ll_create()) == NULL) {
        fprintf(stderr, "Error creating linked list of strings\n");
        return -1;
    }
    if ((fd = fopen(argv[1], "r")) == NULL) {
        fprintf(stderr, "Unable to open %s to read\n", argv[1]);
        return -1;
    }
    /*
     * test of add()
     */
    printf("===== test of add\n");
    while (fgets(buf, 1024, fd) != NULL) {
        if ((p = strdup(buf)) == NULL) {
            fprintf(stderr, "Error duplicating string\n");
            return -1;
        }
        if (!ll_add(ll, p)) {
            fprintf(stderr, "Error adding string to linked list\n");
            return -1;
        }
    }
    fclose(fd);
    n = ll_size(ll);
    /*
     * test of get()
     */
    printf("===== test of get\n");
    for (i = 0; i < n; i++) {
        if (!ll_get(ll, i, (void **)&p)) {
            fprintf(stderr, "Error retrieving %ld'th element\n", i);
            return -1;
        }
        printf("%s", p);
    }
    /*
     * test of remove
     */
    printf("===== test of remove\n");
    for (i = n - 1; i >= 0; i--) {
        if (!ll_remove(ll, i, (void **)&p)) {
            fprintf(stderr, "Error removing string from linked list\n");
            return -1;
        }
        free(p);
    }
    /*
     * test of destroy with NULL userFunction
     */
    printf("===== test of destroy(NULL)\n");
    ll_destroy(ll, NULL);
    /*
     * test of insert
     */
    if ((ll = ll_create()) == NULL) {
        fprintf(stderr, "Error creating linked list of strings\n");
        return -1;
    }
    fd = fopen(argv[1], "r");		/* we know we can open it */
    printf("===== test of insert\n");
    while (fgets(buf, 1024, fd) != NULL) {
        if ((p = strdup(buf)) == NULL) {
            fprintf(stderr, "Error duplicating string\n");
            return -1;
        }
        if (!ll_insert(ll, 0, p)) {
            fprintf(stderr, "Error adding string to linked list\n");
            return -1;
        }
    }
    fclose(fd);
    for (i = 0; i < n; i++) {
        if (!ll_get(ll, i, (void **)&p)) {
            fprintf(stderr, "Error retrieving %ld'th element\n", i);
            return -1;
        }
        printf("%s", p);
    }
    /*
     * test of set
     */
    printf("===== test of set\n");
    for (i = 0; i < n; i++) {
        char bf[1024], *q;
        sprintf(bf, "line %ld\n", i);
        if ((p = strdup(bf)) == NULL) {
            fprintf(stderr, "Error duplicating string\n");
            return -1;
        }
        if (!ll_set(ll, i, p, (void **)&q)) {
            fprintf(stderr, "Error replacing %ld'th element\n", i);
            return -1;
        }
        free(q);
    }
    /*
     * test of toArray
     */
    printf("===== test of toArray\n");
    if ((array = (char **)ll_toArray(ll, &n)) == NULL) {
        fprintf(stderr, "Error in invoking ll_toArray()\n");
        return -1;
    }
    for (i = 0; i < n; i++) {
        printf("%s", array[i]);
    }
    free(array);
    /*
     * test of iterator
     */
    printf("===== test of iterator\n");
    if ((it = ll_it_create(ll)) == NULL) {
        fprintf(stderr, "Error in creating iterator\n");
        return -1;
    }
    while (it_hasNext(it)) {
        char *p;
        (void) it_next(it, (void **)&p);
        printf("%s", p);
    }
    it_destroy(it);
    /*
     * test of destroy with free() as userFunction
     */
    printf("===== test of destroy(free)\n");
    ll_destroy(ll, free);

    return 0;
}
Beispiel #14
0
/*************************************************************************
 *
 *N  parse_expression
 *
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *     This function returns a list of selection expression clause
 *     structures.  This list forms the internal structure of the query
 *     expression.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    expression   <input>==(char *) selection expression string.
 *    table        <input>==(vpf_table_type) VPF table structure.
 *    return      <output>==(linked_list_type) list of expression clauses.
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels    May 1991                          DOS Turbo C
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   External Variables:
 *X
 *    None
 *E
 *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Functions Called:
 *F
 *    char *get_token( char *expression, char *token, int *token_type,
 *    int *token_value) VPFQUERY.C
 *    void display_message( char *input) USER DEFINED
 *    linked_list_type ll_init() LINKLIST.C
 *    void ll_reset( linked_list_type list ) LINKLIST.C
 *    void ll_insert( void *element, unsigned size,
 *    position_type position ) LINKLIST.C
 *E
 *************************************************************************/
static linked_list_type parse_expression( char *expression, vpf_table_type table )
{
   linked_list_type exprlist;
   position_type pos;
   expr_type expr;
   int i, token_type, token_value;
   char token[260];

   exprlist = ll_init();
   pos = exprlist;

   /* Set up static globals */

   nfields = table.nfields;

   fieldname = (char **)memalloc( (nfields+2) * sizeof(char *) );
   fieldcol = (int *)memalloc( (nfields+2) * sizeof(int) );

   for (i=0;i<table.nfields;i++) {
      fieldname[i] = (char *)memalloc(40*sizeof(char));
      strcpy(fieldname[i], table.header[i].name);
      fieldcol[i] = i;
   }

   /*****/

   expression = get_token( expression, token, &token_type, &token_value );
   while (token_type != FINISHED) {
      if (token_type != FIELD) {
	 display_message("Expression syntax error -- Invalid field name");
	 ll_reset(exprlist);
	 exprlist = NULL;
	 break;
      }
      expr.field = token_value;

      expression = get_token( expression, token, &token_type, &token_value );
      if (token_type != LOP) {
	 display_message("Expression syntax error");
	 ll_reset(exprlist);
	 exprlist = NULL;
	 break;
      }
      expr.op = (char)token_value;

      expression = get_token( expression, token, &token_type, &token_value );
      if (token_type == ERROR) {
	 display_message("Expression syntax error");
	 ll_reset(exprlist);
	 exprlist = NULL;
	 break;
      }
      strcpy(expr.value,token);

      expression = get_token( expression, token, &token_type, &token_value );
      if (token_type == JOIN) {
	 expr.join = (char)token_value;
	 ll_insert( &expr, sizeof(expr), pos );
	 pos = pos->next;
	 expression = get_token( expression, token, &token_type,
				 &token_value );
      } else if (token_type == FINISHED) {
	 expr.join = '\0';
	 ll_insert( &expr, sizeof(expr), pos );
      } else {
	 display_message("Expression syntax error");
	 ll_reset(exprlist);
	 exprlist = NULL;
	 break;
      }
   }

   for (i=0;i<nfields;i++) free(fieldname[i]);
   free(fieldname);
   free(fieldcol);

   return exprlist;
}
Beispiel #15
0
/**************************************************************************
 *
 *N  fc_row_numbers
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Given the starting row of a feature class relationship, return the
 *    list of row numbers of the table at the end of the feature class
 *    relate chain.
 *    If your relate goes from the feature to the primitive, this will
 *    return the primitive ids for the given feature row.
 *    If your relate goes from the primitive to the feature, this will
 *    return the feature ids of the given primitive row.
 *
 *    Currently only supports relates on 'I' or 'K' fields.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type fc_row_numbers( row_type row,
				 fcrel_type fcrel,
				 long int tile,
				 ThematicIndex *idx )
{
   row_type relrow;
   long int count;
   long int n, rownum, keyval;
   id_triplet_type triplet_keyval;
   int KEY1_, KEY_;
   position_type p, prow, pkey;
   vpf_relate_struct rcell;
   linked_list_type rowlist, keylist, templist;

   p = ll_first(fcrel.relate_list);
   ll_element(p,&rcell);
   KEY1_ = table_pos(rcell.key1,fcrel.table[0]);

   get_table_element(0,row,fcrel.table[0],&rownum,&count);

   if (KEY1_ == 0) {     /* "ID" */
      keyval = rownum;
   } else {
      switch (fcrel.table[0].header[KEY1_].type) {
	 case 'I':
	    get_table_element(KEY1_,row,fcrel.table[0],&keyval,&count);
	    break;
	 case 'K':
	    get_table_element(KEY1_,row,fcrel.table[0],&triplet_keyval,
			      &count);
	    keyval = triplet_keyval.exid;
	    if (tile != triplet_keyval.tile) {
	       keyval = -2;
	    }
	    break;
	 default:
	    keyval = 0;
	    break;
      }
   }

   keylist = ll_init();
   ll_insert(&keyval,sizeof(keyval),keylist);

   n = 0;

   p = ll_first(fcrel.relate_list);
   for (n=1;n<(fcrel.nchain-1);n++) {

      /* Relate through Join table(s) */

      rowlist = ll_init();
      pkey = ll_first(keylist);
      while (!ll_end(pkey)) {
	 ll_element(pkey,&keyval);
	 templist = related_rows(&keyval,fcrel.table[n],rcell.key2,0,NULL);
	 prow = ll_first(templist);
	 while (!ll_end(prow)) {
	    ll_element(prow,&rownum);
	    if (!ll_locate(&rownum,rowlist))
	       ll_insert(&rownum,sizeof(rownum),ll_last(rowlist));
	    prow = ll_next(prow);
	 }
	 ll_reset(templist);
	 pkey = ll_next(pkey);
      }
      ll_reset(keylist);

      p = ll_next(p);
      ll_element(p,&rcell);
      KEY_ = table_pos(rcell.key1,fcrel.table[n]);

      keylist = ll_init();
      prow = ll_first(rowlist);
      while (!ll_end(prow)) {
	 ll_element(prow,&rownum);
	 relrow = get_row(rownum,fcrel.table[n]);

	 if (KEY_ == 0) {     /* "ID" */
	    keyval = rownum;
	 } else {
	    switch (fcrel.table[n].header[KEY_].type) {
	    case 'I':
	       get_table_element(KEY_,relrow,fcrel.table[n],&keyval,&count);
	       break;
	    case 'K':
	       get_table_element(KEY_,relrow,fcrel.table[n],&triplet_keyval,
				 &count);
	       keyval = triplet_keyval.exid;
	       if (tile != triplet_keyval.tile) {
		  keyval = -2;
	       }
	       break;
	    default:
	       keyval = 0;
	       break;
	    }
	 }
	 if (keyval > 0)
	    ll_insert(&keyval,sizeof(keyval),ll_last(keylist));
	 prow = ll_next(prow);
	 free_row(relrow,fcrel.table[n]);
      }
      ll_reset(rowlist);
   }

   rowlist = ll_init();
   p = ll_first(keylist);
   while (!ll_end(p)) {
      ll_element(p,&keyval);
      templist = related_rows(&keyval,fcrel.table[n],rcell.key2,0,idx);
      prow = ll_first(templist);
      while (!ll_end(prow)) {
	 ll_element(prow,&rownum);
	 if (!ll_locate(&rownum,rowlist))
	    ll_insert(&rownum,sizeof(rownum),ll_last(rowlist));
	 prow = ll_next(prow);
      }
      ll_reset(templist);
      p = ll_next(p);
   }
   ll_reset(keylist);

   return rowlist;
}
Beispiel #16
0
/**************************************************************************
 *
 *N  related_rows
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Return the list of related rows of table2 based upon the value of
 *    table 1's key.
 *    Supported data types - I and T<n>.
 *    Binary search supported only for data type I. (column must be sorted)
 *    Thematic index used, if present on key column.
 *    NOTE: A sequential search operation will search the entire
 *          table ...zzz...
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type related_rows( void *keyval1,
		       vpf_table_type table2, char *key2,
		       int sort_flag,
		       ThematicIndex *idx )
{
   linked_list_type rowlist;
   set_type rowset;
   long int rowid, i, ival, kval, n, start,end;
   row_type row = 0;
   int KEY2_;
   char cval, *tval;

   rowlist = ll_init();

   if (ossim_strcasecmp(key2,"ID")==0) {
      memcpy( &rowid, keyval1, sizeof(rowid) );
      ll_insert(&rowid,sizeof(rowid),rowlist);
      return rowlist;
   }

   KEY2_ = table_pos(key2,table2);

   if ((table2.header[KEY2_].type != 'I')&&
       (table2.header[KEY2_].type != 'T')) return rowlist;

   if ((table2.header[KEY2_].type == 'I')&&
       (table2.header[KEY2_].count != 1)) return rowlist;

   if ((table2.header[KEY2_].type == 'T')&&(sort_flag)) sort_flag = 0;

   if (idx) {
      if (idx->fp) {
	 rowset = search_thematic_index(idx,(char *)keyval1);
	 start = set_min(rowset);
	 end = set_max(rowset);
	 for (i=start;i<=end;i++)
	    if (set_member(i,rowset)) {
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    }
	 set_nuke(&rowset);
	 return rowlist;
      }
   }

   if (!sort_flag) {   /* Sequential search */

      for (i=1;i<=table2.nrows;i++) {
	 row = get_row(i,table2);
	 if (table2.header[KEY2_].type == 'I') {
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (memcmp(&ival,keyval1,sizeof(ival))==0)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	 } else {
	    if (table2.header[KEY2_].count==1) {
	       get_table_element(KEY2_,row,table2,&cval,&n);
	       if (memcmp(&cval,keyval1,sizeof(ival))==0)
		  ll_insert(&i,sizeof(i),ll_last(rowlist));
	    } else {
	       tval = (char*)get_table_element(KEY2_,row,table2,NULL,&n);
	       if (strcmp(tval,(char *)keyval1)==0)
		  ll_insert(&i,sizeof(i),ll_last(rowlist));
	    }
	 }
	 free_row(row,table2);
      }

   } else {   /* Binary search */

      memcpy(&kval,keyval1,sizeof(kval));
      rowid = vpf_binary_search( kval, KEY2_, table2 );

      if (rowid > 0) {
	 ll_insert(&rowid,sizeof(rowid),ll_last(rowlist));
	 i = rowid-1L;
	 do {
	    get_row(i,table2);
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (ival == kval)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    i--;
	 } while ((ival==kval)&&(i>0));
	 i = rowid+1L;
	 do {
	    get_row(i,table2);
	    get_table_element(KEY2_,row,table2,&ival,&n);
	    if (ival == kval)
	       ll_insert(&i,sizeof(i),ll_last(rowlist));
	    i++;
	 } while ((ival==kval)&&(i<=table2.nrows));
      }

   }

   return rowlist;
}
Beispiel #17
0
/**************************************************************************
 *
 *N  fcs_relate_list
 *
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Purpose:
 *P
 *    Read the feature class schema table and create the list of
 *    tables to chain through.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   Parameters:
 *A
 *    fcname       <input> == (char *) feature class name.
 *    start_table  <input> == (char *) table to start from.
 *    end_table    <input> == (char *) table to end with.
 *    fcs          <input> == (vpf_table_type) feature class schema table.
 *    fcs_relate_list <output> == (linked_list_type) list of tables to
 *                                chain through.
 *E
 *:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 *
 *   History:
 *H
 *    Barry Michaels  DOS Turbo C
 *E
 *************************************************************************/
linked_list_type fcs_relate_list( char *fcname, char *start_table,
				  char *end_table, vpf_table_type fcs )
{
   linked_list_type rlist;
   vpf_relate_struct rstruct;
   set_type fcset, set1, set2;
   char tablename[255], *buf, expr[255];
   row_type row;
   long int rownum,n;
   int TABLE1_, KEY1_, TABLE2_, KEY2_;

   rlist = ll_init();

   sprintf(expr,"FEATURE_CLASS = %s",fcname);

   fcset = query_table(expr,fcs);

   if (set_empty(fcset)) {
      set_nuke(&fcset);
      return rlist;
   }

   TABLE1_ = table_pos("TABLE1",fcs);
   KEY1_ = table_pos("FOREIGN_KEY",fcs);
   if (KEY1_ < 0) KEY1_ = table_pos("TABLE1_KEY",fcs);
   TABLE2_ = table_pos("TABLE2",fcs);
   KEY2_ = table_pos("PRIMARY_KEY",fcs);
   if (KEY2_ < 0) KEY2_ = table_pos("TABLE2_KEY",fcs);

   strcpy( tablename, start_table );
   while (1) {
      sprintf(expr,"TABLE1 = %s",tablename);

      set1 = query_table(expr,fcs);
      set2 = set_intersection(set1,fcset);
      set_nuke(&set1);
      if (set_empty(set2)) {
	 set_nuke(&fcset);
	 set_nuke(&set2);
	 return rlist;
      }
      rownum = set_min(set2);

      set_nuke(&set2);

      row = get_row(rownum,fcs);

      buf = (char *)get_table_element(TABLE1_,row,fcs,NULL,&n);
      strcpy(rstruct.table1,buf);
      rightjust(rstruct.table1);
      free(buf);

      buf = (char *)get_table_element(KEY1_,row,fcs,NULL,&n);
      strcpy(rstruct.key1,buf);
      rightjust(rstruct.key1);
      free(buf);

      buf = (char *)get_table_element(TABLE2_,row,fcs,NULL,&n);
      strcpy(rstruct.table2,buf);
      rightjust(rstruct.table2);
      free(buf);

      buf = (char *)get_table_element(KEY2_,row,fcs,NULL,&n);
      strcpy(rstruct.key2,buf);
      rightjust(rstruct.key2);
      free(buf);

      rstruct.degree = R_ONE;  /* Default */

      free_row( row, fcs );

      if (table_in_list(rstruct.table1, rlist)) break;

      ll_insert( &rstruct, sizeof(rstruct), ll_last(rlist) );

      strcpy( tablename, rstruct.table2 );

      if (ossim_strcasecmp(tablename,end_table)==0) break;
   }

   set_nuke(&fcset);

   return rlist;
}
Beispiel #18
0
/*
 * find_buf()
 *	Given starting sector #, return pointer to buf
 */
struct buf *
find_buf(daddr_t d, uint nsec, int flags)
{
	struct buf *b;

	ASSERT_DEBUG(nsec > 0, "find_buf: zero");
	ASSERT_DEBUG(nsec <= EXTSIZ, "find_buf: too big");

	/*
	 * If we can find it, this is easy
	 */
	b = hash_lookup(bufpool, d);
	if (b) {
		return(b);
	}

	/*
	 * Get a buf struct
	 */
	b = malloc(sizeof(struct buf));
	if (b == 0) {
		return(0);
	}

	/*
	 * Make room in our buffer cache if needed
	 */
	while ((bufsize+nsec) > coresec) {
		age_buf();
	}

	/*
	 * Get the buffer space
	 */
	b->b_data = malloc(stob(nsec));
	if (b->b_data == 0) {
		free(b);
		return(0);
	}

	/*
	 * Add us to pool, and mark us very new
	 */
	b->b_list = ll_insert(&allbufs, b);
	if (b->b_list == 0) {
		free(b->b_data);
		free(b);
		return(0);
	}
	if (hash_insert(bufpool, d, b)) {
		ll_delete(b->b_list);
		free(b->b_data);
		free(b);
		return(0);
	}

	/*
	 * Fill in the rest & return
	 */
	init_lock(&b->b_lock);
	b->b_start = d;
	b->b_nsec = nsec;
	b->b_locks = 0;
	b->b_handles = 0;
	b->b_nhandle = 0;
	if (flags & ABC_FILL) {
		b->b_flags = 0;
	} else {
		b->b_flags = B_SEC0 | B_SECS;
	}
	bufsize += nsec;

	/*
	 * If ABC_BG, initiate fill now
	 */
	if (flags & ABC_BG) {
		qio(b, Q_FILLBUF);
	}

	return(b);
}
Beispiel #19
0
int main(int argc, char** argv) {
    llist *l = malloc(sizeof(llist));
    
    const int reference[11] = {20, 19, 18, 14, 12, 10, 8, 6, 4, 2, -1};
    const int size = sizeof(reference) / sizeof(int);
    
    int error = 1;
    
    // Add numbers 20, 18, 16, 14, ... 2, 0 to the list.
    {
        int i;
        for (i = 20; i >= 0; i -= 2) {
            ll_push(l, i);
        }
    }
    if (ll_size(l) != 11) {
        return error;
    }
    ll_print(l);
    error++;
    
    ll_pop(l);
    ll_push(l, -1);
    ll_insert(l, 1, 19);
    ll_remove(l, 3);
    printf("Phase 2 complete (pop, push, insert, remove).\n");
    
    // Check first and last index.
    if (l -> first -> value != reference[0]) {
        return error;
    }
    printf("Phase 3A complete (check first value).\n");
    error++;
    
    if (l -> last -> value != reference[size - 1]) {
        return error;
    }
    printf("Phase 3B complete (check last value).\n");
    error++;
    
    // Check by traversing.
    {
        node *n = l -> first;
        int index = 0;
        while (n != NULL) {
            if (n -> value == reference[index++]) {
                n = n -> next;
            } else {
                return error;
            }
        }
    }
    printf("Phase 4A complete (traverse forward).\n");
    error++;
    
    // Check by backward traversing.
    {
        node *n = l -> last;
        int index = size - 1;
        while (n != NULL) {
            if (n -> value == reference[index--]) {
                n = n -> prev;
            } else {
                return error;
            }
        }
    }
    printf("Phase 4B complete (traverse backward).\n");
    error++;
    
    // Check by indexing.
    {
        int i;
        for (i = 0; i < ll_size(l); i++) {
            if (reference[i] != ll_get(l, i)) {
                return error;
            }
        }
    }
    printf("Phase 5 complete (iterate).\n");
    error++;
    
    printf("Completed without error.\n");
    return 0;
}
Beispiel #20
0
llist * ll_append(llist * list, const void * val, size_t size){
    return ll_insert(ll_tail(list), val, size);
}
Beispiel #21
0
/* Add and remove items from the list of dirty items */
void add_dlist(cache_t *c, struct ce_t *e)
{
	e->dirty_node = ll_insert(&c->dirty_ll, e);
}