Esempio n. 1
0
krb5_error_code KRB5_CALLCONV
krb5_get_fallback_host_realm(krb5_context context, krb5_data *hdata,
                             char ***realms_out)
{
    krb5_error_code ret;
    struct hostrealm_module_handle **hp;
    char **realms, *defrealm, *host, cleanname[1024];

    *realms_out = NULL;

    /* Convert hdata into a string and clean it. */
    host = k5memdup0(hdata->data, hdata->length, &ret);
    if (host == NULL)
        return ret;
    ret = k5_clean_hostname(context, host, cleanname, sizeof(cleanname));
    free(host);
    if (ret)
        return ret;

    if (context->hostrealm_handles == NULL) {
        ret = load_hostrealm_modules(context);
        if (ret)
            return ret;
    }

    /* Give each module a chance to determine the fallback realms. */
    for (hp = context->hostrealm_handles; *hp != NULL; hp++) {
        ret = fallback_realm(context, *hp, cleanname, &realms);
        if (ret == 0) {
            ret = copy_list(realms, realms_out);
            free_list(context, *hp, realms);
            return ret;
        } else if (ret != KRB5_PLUGIN_NO_HANDLE) {
            return ret;
        }
    }

    /* Return a list containing the default realm. */
    ret = krb5_get_default_realm(context, &defrealm);
    if (ret)
        return ret;
    ret = k5_make_realmlist(defrealm, realms_out);
    krb5_free_default_realm(context, defrealm);
    return ret;
}
Esempio n. 2
0
static void coerce_arg(rtype type, rtype ftype, int l, string code,
		       string *buf, int *i, int *lbuf,
		       int int_allowed, frame name)
{
    frame f = make_frame(type, NULL, l, code, "");

    if ((type == T_INTNUM || type == T_INTLNG) && !int_allowed)
	f = coerce_frame(f, T_NUMBER);

    f = coerce_frame(f, ftype);
    if (f->decls)
	name->decls = nconc(name->decls, copy_list(f->decls, 0));

    NORET(f->code);
    *buf = copy_into_buf(*buf, f->code, i, lbuf, strlen(f->code));

    mcfree(f->code);
    mcfree(f);
}
Esempio n. 3
0
NODE *lsetwrite(NODE *arg) {
    FILE *tmp;
    NODE *margs;

    if (writestream == NULL) {
	/* Any setwrite finishes earlier write to string */
	*print_stringptr = '\0';
	writestream = stdout;
	if (find_file(writer_name, FALSE) == NULL) {
	    /* pre-5.4 compatibility mode, implicitly close string */
	    margs = cons(car(writer_name),
			 cons(make_strnode(write_buf, NULL, strlen(write_buf),
					   STRING, strnzcpy),
			      NIL));
	    lmake(margs);
	    free(write_buf);
	}
	writer_name = NIL;
    }
    if (car(arg) == NIL) {
	writestream = stdout;
	writer_name = NIL;
    } else if (is_list(car(arg))) { /* print to string */
	FIXNUM i = int_arg(cdar(arg));
	if ((tmp = find_file(car(arg), FALSE)) != NULL) {
	    writestream = NULL;
	    writer_name = car(arg);
	    print_stringptr = (char *)tmp + strlen((char *)tmp);
	    print_stringlen = i - strlen((char *)tmp);
	} else if (NOT_THROWING && i > 0 && cddr(car(arg)) == NIL) {
	    writestream = NULL;
	    writer_name = copy_list(car(arg));
	    print_stringptr = write_buf = (char *)malloc(i);
	    print_stringlen = i;
	} else err_logo(BAD_DATA_UNREC, car(arg));
    } else if ((tmp = find_file(car(arg), FALSE)) != NULL) {
	writestream = tmp;
	writer_name = car(arg);
    } else
	err_logo(NOT_OPEN_ERROR, car(arg));
    return(UNBOUND);
}
struct slInt * seeded_shuffle_indices(struct slInt *list, int seed)
{
int length = 0, currIx = 0, swapIx = 0, i = 0,j=0;
struct slInt * tmp, * currPrev,  * curr, *swapPrev, *swap, *result = copy_list(list);
length=count_indices(result);
srand(seed);
for(currIx = 0; currIx < length; currIx++)
	{
	currPrev = swapPrev = NULL;
	curr = swap = result;

	//iterate a pointer to the node to be swapped
	for(i = 0; i < (currIx-1); i++)
		{
		currPrev = curr;
		curr = curr->next;
		}
		
	//pick an index to swap this node with and iterate a pointer to the node before it
    swapIx = (rand() % length + 1);
	for(j = 0; j < (swapIx - 1); j++)
		{
		swapPrev = swap;	
		swap = swap->next;
		}

	//swap nodes
	if(currPrev)
		currPrev->next = swap;
	else
		result = swap;
	if(swapPrev)
		swapPrev->next = curr;
	else
		result = curr;
	tmp = curr->next;
	curr->next = swap->next;
	swap->next = tmp;
	}	
return result;
}
Esempio n. 5
0
list *chunk_words(list *words, size_t chunk_size)
{
    size_t num_words = len_list(words);
    list *chunks = NULL;

    if (num_words <= chunk_size)
        return NULL;

    size_t num_chunks = num_words - chunk_size;
    if (num_chunks > num_words)
        return NULL;

    for (size_t i = 0; i < num_chunks; i++) {
        list *chunk = copy_list(words, i, i + chunk_size + 1);
        if (!chunk)
            error(EALLOC);
        append_list(&chunks, chunk, 1);
    }

    return chunks;
}
Esempio n. 6
0
Hand::Hand(const Hand & ref_hand)
{
    tiles_in_hand = new Tile *[7+1];
    for (int i = 0; i < 7; ++i)
    {
        tiles_in_hand[i] = ref_hand.tiles_in_hand[i];
    }
    tiles_in_hand[7] = NULL;
    copy_list(head, ref_hand.head);
    score = ref_hand.score;
    if(!(ref_hand.player_name == NULL))
    {
        player_name = new char[(strlen(ref_hand.player_name) + 1)];
        strcpy(player_name, ref_hand.player_name);
    }
   else 
   {
       player_name = NULL;
   }
    return;
}
Esempio n. 7
0
tree
make_alias_for (tree target, tree newid)
{
  tree alias = build_decl (DECL_SOURCE_LOCATION (target),
			   TREE_CODE (target), newid, TREE_TYPE (target));
  DECL_LANG_SPECIFIC (alias) = DECL_LANG_SPECIFIC (target);
  cxx_dup_lang_specific_decl (alias);
  DECL_CONTEXT (alias) = NULL;
  TREE_READONLY (alias) = TREE_READONLY (target);
  TREE_THIS_VOLATILE (alias) = TREE_THIS_VOLATILE (target);
  TREE_PUBLIC (alias) = 0;
  DECL_INTERFACE_KNOWN (alias) = 1;
  if (DECL_LANG_SPECIFIC (alias))
    {
      DECL_NOT_REALLY_EXTERN (alias) = 1;
      DECL_USE_TEMPLATE (alias) = 0;
      DECL_TEMPLATE_INFO (alias) = NULL;
    }
  DECL_EXTERNAL (alias) = 0;
  DECL_ARTIFICIAL (alias) = 1;
  DECL_TEMPLATE_INSTANTIATED (alias) = 0;
  if (TREE_CODE (alias) == FUNCTION_DECL)
    {
      DECL_SAVED_FUNCTION_DATA (alias) = NULL;
      DECL_DESTRUCTOR_P (alias) = 0;
      DECL_CONSTRUCTOR_P (alias) = 0;
      DECL_PENDING_INLINE_P (alias) = 0;
      DECL_DECLARED_INLINE_P (alias) = 0;
      DECL_INITIAL (alias) = error_mark_node;
      DECL_ARGUMENTS (alias) = copy_list (DECL_ARGUMENTS (target));
    }
  else
    TREE_STATIC (alias) = 1;
  TREE_ADDRESSABLE (alias) = 1;
  TREE_USED (alias) = 1;
  SET_DECL_ASSEMBLER_NAME (alias, DECL_NAME (alias));
  TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (alias)) = 1;
  return alias;
}
Esempio n. 8
0
Obj append_function (Obj lists)
{
  Obj new_list, cons_in_new_listP, list_holder, next_list_holder, old_list, 
        new_copy;

  if (lists==NULL) 
    return (Obj)NULL;
  else {
    new_list = (Obj)NULL;
    cons_in_new_listP = (Obj)NULL;
    list_holder = lists;
    next_list_holder = CDR(lists);
    old_list = CAR(list_holder);
    while (IMMED_TAG(next_list_holder)==2) {    /* Consp */
      if (old_list!=NULL) {
        new_copy = copy_list(old_list);
        if (cons_in_new_listP!=NULL) {
          CDR(last(cons_in_new_listP)) = new_copy;
          cons_in_new_listP = new_copy;
        }
        else {
          new_list = new_copy;
          cons_in_new_listP = new_copy;
        }
      }
      list_holder = next_list_holder;
      next_list_holder = CDR(list_holder);
      old_list = CAR(list_holder);
    }

    if (cons_in_new_listP!=NULL) 
      CDR(last(cons_in_new_listP)) = old_list;
    else 
      new_list = old_list;
    goto exit_nil;
   exit_nil:
    return new_list;
  }
}
Esempio n. 9
0
static struct lp_value *copy_value(struct lp_value *v) {
  struct lp_value *result = calloc(1, sizeof(struct lp_value));
  memcpy(result, v, sizeof(struct lp_value));
  switch(v->t) {
  case S:
    result->v.s = strdup(v->v.s);
    break;

  case LIST:
    result->v.l = copy_list(v->v.l);
    break;

  case BLOCK:
    result->v.b = copy_block(v->v.b);
    break;

  default:
    break;
  }
  
  return result;
}
Esempio n. 10
0
node *quicksort(node *list)
{
  node *first_node; /* first node */
  node *list_sorted, *list_sorted_final; /* copied list */
  node *list_left, *list_right, *sorted_list_left, *sorted_list_right; /* left and right side of original list */
  node *item; /* variable used in for loop condition */
  list_left = NULL;
  list_right = NULL;
  if (list == NULL || list->next == NULL)
  {
    list_sorted = copy_list(list);
    return list_sorted;
  }
  first_node = create_node(list->data, NULL); /* Copy the first node of list */
  for (item = list->next; item != NULL; item = item->next)
  {
    if (item->data < first_node->data)
    {
      list_left = create_node(item->data, list_left);
    }
    else /* item >= first_node */
    {
      list_right =  create_node(item->data, list_right);
    }
  }
  sorted_list_left = quicksort(list_left);
  sorted_list_right = quicksort(list_right);
  list_sorted = append_lists(sorted_list_left, first_node);
  list_sorted_final = append_lists(list_sorted, sorted_list_right);
  free_list(list_left);
  free_list(list_right);
  free_list(sorted_list_left);
  free_list(sorted_list_right);
  free_list(list_sorted);
  free_list(first_node);
  assert(is_sorted(list_sorted_final));
  return list_sorted_final;
}
Esempio n. 11
0
/* Copies a linear list, sharing the list elements.  */
KeywordExt_List *
copy_list (KeywordExt_List *list)
{
  return static_cast<KeywordExt_List *> (copy_list (static_cast<Keyword_List *> (list)));
}
Esempio n. 12
0
int main()
{
  ssize_t *a0, *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8, *a9, *a10, *a11, *a12, *a13, *a14, *a15, *a16, *a17, *a18, *a19, *a20, *a21, *a22, *a23, *a24, *a25, *a26, *a27, *a28, *a29, *a30, *a31, *a32, *a33, *a34, *a35, *a36, *a37, *a38, *a39, *a40, *a41, *a42, *a43, *a44, *a45, *a46, *a47, *a48, *a49, *a50, *a51, *a52, *a53, *a54, *a55, *a56, *a57, *a58, *a59, *a60, *a61, *a62, *a63, *a64, *a65, *a66, *a67, *a68, *a69, *a70, *a71, *a72, *a73, *a74, *a75, *a76, *a77, *a78, *a79, *a80, *a81, *a82, *a83, *a84, *a85, *a86, *a87, *a88, *a89, *a90, *a91, *a92, *a93, *a94, *a95, *a96, *a97, *a98, *a99, *a100, *a101, *a102, *a103, *a104, *a105, *a106, *a107, *a108, *a109, *a110, *a111, *a112, *a113, *a114, *a115, *a116, *a117, *a118, *a119, *a120, *a121, *a122, *a123, *a124, *a125, *a126, *a127, *a128, *a129, *a130, *a131, *a132, *a133, *a134, *a135, *a136, *a137, *a138, *a139, *a140, *a141, *a142, *a143, *a144, *a145, *a146, *a147, *a148, *a149, *a150, *a151, *a152, *a153, *a154, *a155, *a156, *a157, *a158, *a159, *a160, *a161, *a162, *a163, *a164, *a165, *a166, *a167, *a168, *a169, *a170, *a171, *a172, *a173, *a174, *a175, *a176, *a177, *a178, *a179, *a180, *a181, *a182, *a183, *a184, *a185, *a186, *a187, *a188, *a189, *a190, *a191, *a192, *a193, *a194, *a195, *a196, *a197, *a198, *a199, *a200;

 	uint64_t *a201, *a202;

        sNode *temp;


	a0 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a0 = 0;

	a1 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a1 = 1;

	a2 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a2 = 2;

	a3 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a3 = 3;

	a4 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a4 = 4;

	a5 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a5 = 5;

	a6 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a6 = 6;

	a7 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a7 = 7;

	a8 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a8 = 8;

	a9 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a9 = 9;

	a10 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a10 = 10;

	a11 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a11 = 11;

	a12 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a12 = 12;

	a13 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a13 = 13;

	a14 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a14 = 14;

	a15 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a15 = 15;

	a16 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a16 = 16;

	a17 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a17 = 17;

	a18 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a18 = 18;

	a19 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a19 = 19;

	a20 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a20 = 20;

	a21 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a21 = 21;

	a22 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a22 = 22;

	a23 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a23 = 23;

	a24 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a24 = 24;

	a25 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a25 = 25;

	a26 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a26 = 26;

	a27 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a27 = 27;

	a28 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a28 = 28;

	a29 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a29 = 29;

	a30 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a30 = 30;

	a31 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a31 = 31;

	a32 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a32 = 32;

	a33 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a33 = 33;

	a34 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a34 = 34;

	a35 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a35 = 35;

	a36 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a36 = 36;

	a37 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a37 = 37;

	a38 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a38 = 38;

	a39 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a39 = 39;

	a40 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a40 = 40;

	a41 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a41 = 41;

	a42 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a42 = 42;

	a43 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a43 = 43;

	a44 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a44 = 44;

	a45 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a45 = 45;

	a46 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a46 = 46;

	a47 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a47 = 47;

	a48 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a48 = 48;

	a49 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a49 = 49;

	a50 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a50 = 50;

	a51 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a51 = 51;

	a52 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a52 = 52;

	a53 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a53 = 53;

	a54 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a54 = 54;

	a55 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a55 = 55;

	a56 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a56 = 56;

	a57 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a57 = 57;

	a58 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a58 = 58;

	a59 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a59 = 59;

	a60 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a60 = 60;

	a61 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a61 = 61;

	a62 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a62 = 62;

	a63 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a63 = 63;

	a64 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a64 = 64;

	a65 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a65 = 65;

	a66 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a66 = 66;

	a67 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a67 = 67;

	a68 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a68 = 68;

	a69 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a69 = 69;

	a70 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a70 = 70;

	a71 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a71 = 71;

	a72 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a72 = 72;

	a73 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a73 = 73;

	a74 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a74 = 74;

	a75 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a75 = 75;

	a76 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a76 = 76;

	a77 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a77 = 77;

	a78 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a78 = 78;

	a79 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a79 = 79;

	a80 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a80 = 80;

	a81 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a81 = 81;

	a82 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a82 = 82;

	a83 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a83 = 83;

	a84 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a84 = 84;

	a85 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a85 = 85;

	a86 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a86 = 86;

	a87 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a87 = 87;

	a88 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a88 = 88;

	a89 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a89 = 89;

	a90 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a90 = 90;

	a91 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a91 = 91;

	a92 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a92 = 92;

	a93 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a93 = 93;

	a94 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a94 = 94;

	a95 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a95 = 95;

	a96 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a96 = 96;

	a97 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a97 = 97;

	a98 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a98 = 98;

	a99 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a99 = 99;

	a100 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a100 = 100;

	a101 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a101 = 101;

	a102 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a102 = 102;

	a103 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a103 = 103;

	a104 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a104 = 104;

	a105 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a105 = 105;

	a106 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a106 = 106;

	a107 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a107 = 107;

	a108 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a108 = 108;

	a109 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a109 = 109;

	a110 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a110 = 110;

	a111 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a111 = 111;

	a112 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a112 = 112;

	a113 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a113 = 113;

	a114 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a114 = 114;

	a115 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a115 = 115;

	a116 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a116 = 116;

	a117 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a117 = 117;

	a118 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a118 = 118;

	a119 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a119 = 119;

	a120 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a120 = 120;

	a121 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a121 = 121;

	a122 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a122 = 122;

	a123 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a123 = 123;

	a124 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a124 = 124;

	a125 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a125 = 125;

	a126 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a126 = 126;

	a127 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a127 = 127;

	a128 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a128 = 128;

	a129 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a129 = 129;

	a130 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a130 = 130;

	a131 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a131 = 131;

	a132 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a132 = 132;

	a133 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a133 = 133;

	a134 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a134 = 134;

	a135 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a135 = 135;

	a136 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a136 = 136;

	a137 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a137 = 137;

	a138 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a138 = 138;

	a139 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a139 = 139;

	a140 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a140 = 140;

	a141 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a141 = 141;

	a142 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a142 = 142;

	a143 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a143 = 143;

	a144 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a144 = 144;

	a145 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a145 = 145;

	a146 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a146 = 146;

	a147 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a147 = 147;

	a148 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a148 = 148;

	a149 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a149 = 149;

	a150 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a150 = 150;

	a151 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a151 = 151;

	a152 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a152 = 152;

	a153 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a153 = 153;

	a154 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a154 = 154;

	a155 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a155 = 155;

	a156 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a156 = 156;

	a157 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a157 = 157;

	a158 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a158 = 158;

	a159 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a159 = 159;

	a160 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a160 = 160;

	a161 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a161 = 161;

	a162 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a162 = 162;

	a163 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a163 = 163;

	a164 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a164 = 164;

	a165 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a165 = 165;

	a166 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a166 = 166;

	a167 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a167 = 167;

	a168 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a168 = 168;

	a169 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a169 = 169;

	a170 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a170 = 170;

	a171 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a171 = 171;

	a172 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a172 = 172;

	a173 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a173 = 173;

	a174 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a174 = 174;

	a175 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a175 = 175;

	a176 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a176 = 176;

	a177 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a177 = 177;

	a178 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a178 = 178;

	a179 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a179 = 179;

	a180 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a180 = 180;

	a181 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a181 = 181;

	a182 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a182 = 182;

	a183 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a183 = 183;

	a184 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a184 = 184;

	a185 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a185 = 185;

	a186 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a186 = 186;

	a187 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a187 = 187;

	a188 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a188 = 188;

	a189 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a189 = 189;

	a190 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a190 = 190;

	a191 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a191 = 191;

	a192 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a192 = 192;

	a193 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a193 = 193;

	a194 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a194 = 194;

	a195 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a195 = 195;

	a196 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a196 = 196;

	a197 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a197 = 197;

	a198 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a198 = 198;

	a199 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a199 = 199;

	a200 =  (ssize_t *) salmalloc(sizeof(ssize_t));
	*a200 = 200;

	a201 =  (uint64_t *) salmalloc(sizeof(uint64_t));
	*a201 = 201;

	a202 =  (uint64_t *) salmalloc(sizeof(uint64_t));
	*a202 = 202;

	temp = (sNode *) copy_list(4);

	if (testList() != TRUE) {
	  return FALSE;
	}

	/* printf("Test part 1 was successful.\n"); */

	if (testSkipNodes() != TRUE) {
	  return FALSE;
	}

	/* printf("Test part 2 was successful.\n"); */

	printf("Test_300_Node.c passed.\n");

	return TRUE;
}
Esempio n. 13
0
static P xy(B **xyf, B **freevm)
{
  P retc; 
  B *xf, *yf;

  if (o_1 < FLOORopds) return OPDS_UNF;
  if (CLASS(o_1) == ARRAY) { 
    if (o_2 < FLOORopds) goto do_one_array;
    if (CLASS(o_2) == ARRAY) goto do_array_array;
    if (CLASS(o_2) == LIST) goto do_array_list;
    goto do_one_array;
  }
  else if (CLASS(o_1) == LIST) { 
    if (o_2 < FLOORopds) goto do_one_list;
    if (CLASS(o_2) == ARRAY) goto do_list_array;
    if (CLASS(o_2) == LIST) goto do_list_list;
    goto do_one_list;
  }
  else return OPD_CLA;

 do_one_array:
  if (ARRAY_SIZE(o_1) & 1) return RNG_CHK;
  if ((retc = copy_array(o_1,xyf,freevm)) != OK) return retc;
  FREEopds = o_1; 
  return OK;

 do_array_array:
  if ((retc = copy_array(o_2,&xf,freevm)) != OK) return retc;
  if ((retc = copy_array(o_1,&yf,freevm)) != OK) return retc;
  if (ARRAY_SIZE(xf) != ARRAY_SIZE(yf)) return RNG_CHK;
  if ((retc = merge(xf,yf,xyf,freevm)) != OK) return retc;
  FREEopds = o_2; 
  return OK;

 do_array_list:
  if ((retc = copy_list(o_2,&xf,freevm)) != OK) return retc;
  if ((retc = copy_array(o_1,&yf,freevm)) != OK) return retc;
  if (ARRAY_SIZE(xf) != ARRAY_SIZE(yf)) return RNG_CHK;
  if ((retc = merge(xf,yf,xyf,freevm)) != OK) return retc;
  FREEopds = o_2; 
  return OK;

 do_one_list:
  if (((LIST_CEIL(o_1) - VALUE_BASE(o_1)) / FRAMEBYTES) & 1) return RNG_CHK;
  if ((retc = copy_list(o_1,xyf,freevm)) != OK) return retc;
  FREEopds = o_1; 
  return OK;

 do_list_array:
  if ((retc = copy_array(o_2,&xf,freevm)) != OK) return retc;
  if ((retc = copy_list(o_1,&yf,freevm)) != OK) return retc;
  if (ARRAY_SIZE(xf) != ARRAY_SIZE(yf)) return RNG_CHK;
  if ((retc = merge(xf,yf,xyf,freevm)) != OK) return retc;
  FREEopds = o_2; 
  return OK;

 do_list_list:
  if ((retc = copy_list(o_2,&xf,freevm)) != OK) return retc;
  if ((retc = copy_list(o_1,&yf,freevm)) != OK) return retc;
  if (ARRAY_SIZE(xf) != ARRAY_SIZE(yf)) return RNG_CHK;
  if ((retc = merge(xf,yf,xyf,freevm)) != OK) return retc;
  FREEopds = o_2; 
  return OK;
}
Esempio n. 14
0
/* This main function does a little testing
   Like all good CS Majors you should test
   your code here. There is no substitute for testing
   and you should be sure to test for all edge cases
   e.g., calling remove_front on an empty list.
*/
int main(void)
{
	/* Now to make use of all of this stuff */
	list* llist = create_list();

  /* What does an empty list contain?  Lets use our handy traversal function */
  printf("TEST CASE 1\nAn Empty list should print nothing here:\n");
  traverse(llist, print_person);
	printf("\n");

 	/* Lets add a person from front and then print */
 	push_front(llist, create_person("Andrew", 24));
 	printf("TEST CASE 2\nA List with one person should print that person:\n");
 	traverse(llist, print_person);
 	printf("\n");

  
  /* Lets remove two persons from front and then print */
  remove_front(llist, free_person); // remove a list with more than 1 elements
 	remove_front(llist, free_person); // remove a list with only 1 element
 	printf("TEST CASE 3\nAnother Empty list should print nothing here:\n");
 	traverse(llist, print_person);
 	printf("\n");

 	/* Lets add two people and then print */
 	push_front(llist, create_person("Nick", 22));
 	push_front(llist, create_person("Randal", 21));
 	printf("TEST CASE 4\nA List with two people should print those two people:\n");
 	traverse(llist, print_person);
 	printf("\n");

	/* Lets copy this list */
	list* llist2 = copy_list(llist, copy_person);
	printf("TEST CASE 5\nA copied list should print out the same two people:\n");
 	traverse(llist2, print_person);
 	printf("\n");

  /* Lets kill the list */
  empty_list(llist, free_person);
 	printf("TEST CASE 6\nAfter freeing all nodes the list should be empty:\n");
 	traverse(llist, print_person);
	printf("\n");

	/* Let's make a list of people, and remove certain ones! */
	/* Should remove anyone whose name is 8+ characters long */
	push_front(llist, create_person("Josephine", 27));
	push_front(llist, create_person("Dave", 34));
	push_front(llist, create_person("Benjamin", 23));
	push_front(llist, create_person("Lisa", 41));
	push_front(llist, create_person("Maximilian", 24));
	remove_if(llist, long_name, free_person);
	printf("TEST CASE 7\nShould only print 2 people with short names:\n");
	traverse(llist, print_person);
  printf("\n");
  
  /* Testing over clean up*/
  empty_list(llist, free_person);
  free(llist);
  empty_list(llist2, free_person);
  free(llist2);


  // MY TESTS!!!

  // Test case 8 -- create_list(); is_empty() and size() when the list is empty
  list* myList = create_list();
  printf("TEST CASE 8\nShould print 1 and then 0:\n");
  printf("%d\t", is_empty(myList));
  printf("%d\n", size(myList));
  printf("\n");

  // Test case 9 -- front() and back() when the list is empty
  printf("TEST CASE 9\nShould print nothing:\n");
  print_person(front(myList));
  print_person(back(myList));
  printf("\n");

  // Test case 10 -- push_front() and push_back() and traverse()
  push_front(myList, create_person("Dan", 24));
  push_back(myList, create_person("Sun", 24));
  push_front(myList, create_person("Someone", 100));
  push_back(myList, create_person("Somebody", 1));
  printf("TEST CASE 10\nShould print 4 people in the order of Someone-Dan-Sun-Somebody:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 11 -- size() and is_empty() when the list is not empty
  printf("TEST CASE 11\nShould return 0 and then 4:\n");
  printf("%d\t", is_empty(myList));
  printf("%d\n", size(myList));
  printf("\n");

  // Test case 12 -- front() and back() when the list is not empty
  printf("TEST CASE 12\nShould print Someone then Somebody:\n");
  print_person(front(myList));
  print_person(back(myList));
  printf("\n");

  // Test case 13 -- copy_list()
  list* myListCopy = copy_list(myList, copy_person);
  printf("TEST CASE 13\nA copied list should print 4 people in the order of Someone-Dan-Sun-Somebody:\n");
  traverse(myListCopy, print_person);
  printf("\n");

  // Test case 14 -- remove_front() and remove_back() when the list is not empty
  remove_front(myList, free_person);
  remove_back(myList, free_person);
  printf("TEST CASE 13\nShould print 2 people in the order of Dan-Sun:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 15 -- remove_if()
  push_front(myList, create_person("LLLLLLLLLLLLL", 1));
  push_front(myList, create_person("MMMMMMMMM", 1));
  push_front(myList, create_person("AAA", 3));
  push_back(myList, create_person("DDD", 5));
  push_back(myList, create_person("T", 10));
  push_back(myList, create_person("VVVVVVVVVV", 1));
  remove_if(myList, long_name, free_person);
  printf("TEST CASE 13\nShould print 5 people:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 16 -- empty_list()
  empty_list(myList, free_person);
  printf("TEST CASE 16\nShould print nothing:\n");
  traverse(myList, print_person);
  printf("\n");

  // Test case 17 -- remove_front() and remove_back() when the list is empty
  remove_front(myList, free_person);
  remove_back(myList, free_person);
  printf("TEST CASE 17\nNo error should occur: \n");
  printf("\n");

  // Test case 18 -- push big data into the copied list to test push_front() and copy_list()
  for (int i = 0; i < 1000000; i++) {
    push_front(myListCopy, create_person("BIG", 1));
  }
  printf("TEST CASE 18\nShould print 1000004 (add a large number of data): \n");
  printf("%d\n", size(myListCopy));
  printf("\n");

  empty_list(myList, free_person);
  free(myList);

  empty_list(myListCopy, free_person);
  free(myListCopy);

  return 0;
}
Esempio n. 15
0
static int dreg_insert (dreg_entry *r)
{
	vma_t *i = &vma_list, **v;
	unsigned long begin = DREG_BEGIN (r), end = DREG_END (r);

	v = avlfindex (vma_compare_closest, (void*)begin, vma_tree);

	if (v)
		i = *v;

	while (begin <= end)
	{
		vma_t *vma;

		if (i == &vma_list)
		{
			vma = vma_new (begin, end);

			if (!vma)
				goto remove;

			vma->next = i;
			vma->prev = i->prev;
			i->prev->next = vma;
			i->prev = vma;

			begin = vma->end + 1;

			add_entry (vma, r);
		} 
		else if (i->start > begin)
		{
			vma = vma_new (begin, 
					(i->start <= end)?(i->start - 1):end);

			if (!vma)
				goto remove;

			/* insert before */
			vma->next = i;
			vma->prev = i->prev;
			i->prev->next = vma;
			i->prev = vma;

			i = vma;

			begin = vma->end + 1;

			add_entry (vma, r);
		}
		else if (i->start == begin)
		{
			if (i->end > end)
			{
				vma = vma_new (end+1, i->end);
				
				if (!vma)
					goto remove;

				i->end = end;

				copy_list (vma, i);

				/* add after */
				vma->next = i->next;
				vma->prev = i;
				i->next->prev = vma;
				i->next = vma;

				add_entry (i, r);
				begin = end + 1;
			}
			else
			{
				add_entry (i, r);
				begin = i->end + 1;
			}
		}
		else
		{
			vma = vma_new (begin, i->end);

			if (!vma)
				goto remove;

			i->end = begin - 1;

			copy_list (vma, i);

			/* add after */
			vma->next = i->next;
			vma->prev = i;
			i->next->prev = vma;
			i->next = vma;
		}

		i = i->next;
	}
	return 0;

remove:
	dreg_remove (r);
	return -1;
}
Esempio n. 16
0
tree
decl_attributes (tree *node, tree attributes, int flags)
{
  tree a;
  tree returned_attrs = NULL_TREE;

  if (TREE_TYPE (*node) == error_mark_node)
    return NULL_TREE;

  if (!attributes_initialized)
    init_attributes ();

  /* If this is a function and the user used #pragma GCC optimize, add the
     options to the attribute((optimize(...))) list.  */
  if (TREE_CODE (*node) == FUNCTION_DECL && current_optimize_pragma)
    {
      tree cur_attr = lookup_attribute ("optimize", attributes);
      tree opts = copy_list (current_optimize_pragma);

      if (! cur_attr)
	attributes
	  = tree_cons (get_identifier ("optimize"), opts, attributes);
      else
	TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
    }

  if (TREE_CODE (*node) == FUNCTION_DECL
      && optimization_current_node != optimization_default_node
      && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node))
    DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node;

  /* If this is a function and the user used #pragma GCC target, add the
     options to the attribute((target(...))) list.  */
  if (TREE_CODE (*node) == FUNCTION_DECL
      && current_target_pragma
      && targetm.target_option.valid_attribute_p (*node, NULL_TREE,
						  current_target_pragma, 0))
    {
      tree cur_attr = lookup_attribute ("target", attributes);
      tree opts = copy_list (current_target_pragma);

      if (! cur_attr)
	attributes = tree_cons (get_identifier ("target"), opts, attributes);
      else
	TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
    }

  targetm.insert_attributes (*node, &attributes);

  for (a = attributes; a; a = TREE_CHAIN (a))
    {
      tree name = TREE_PURPOSE (a);
      tree args = TREE_VALUE (a);
      tree *anode = node;
      const struct attribute_spec *spec = lookup_attribute_spec (name);
      bool no_add_attrs = 0;
      tree fn_ptr_tmp = NULL_TREE;

      if (spec == NULL)
	{
	  warning (OPT_Wattributes, "%qs attribute directive ignored",
		   IDENTIFIER_POINTER (name));
	  continue;
	}
      else if (list_length (args) < spec->min_length
	       || (spec->max_length >= 0
		   && list_length (args) > spec->max_length))
	{
	  error ("wrong number of arguments specified for %qs attribute",
		 IDENTIFIER_POINTER (name));
	  continue;
	}
      gcc_assert (is_attribute_p (spec->name, name));

      /* If this is a lock attribute and the purpose field of the args is
         an error_mark_node, the attribute arguments have not been parsed yet
         (as we delay the parsing of the attribute arguments until after the
         whole class has been parsed). So don't handle this attribute now
         but simply replace the error_mark_node with the current decl node
         (which we will need when we call this routine again later).  */
      if (args
          && TREE_PURPOSE (args) == error_mark_node
          && is_lock_attribute_with_args (name))
        {
          TREE_PURPOSE (args) = *node;
          continue;
        }

      if (spec->decl_required && !DECL_P (*anode))
	{
	  if (flags & ((int) ATTR_FLAG_DECL_NEXT
		       | (int) ATTR_FLAG_FUNCTION_NEXT
		       | (int) ATTR_FLAG_ARRAY_NEXT))
	    {
	      /* Pass on this attribute to be tried again.  */
	      returned_attrs = tree_cons (name, args, returned_attrs);
	      continue;
	    }
	  else
	    {
	      warning (OPT_Wattributes, "%qs attribute does not apply to types",
		       IDENTIFIER_POINTER (name));
	      continue;
	    }
	}

      /* If we require a type, but were passed a decl, set up to make a
	 new type and update the one in the decl.  ATTR_FLAG_TYPE_IN_PLACE
	 would have applied if we'd been passed a type, but we cannot modify
	 the decl's type in place here.  */
      if (spec->type_required && DECL_P (*anode))
	{
	  anode = &TREE_TYPE (*anode);
	  /* Allow ATTR_FLAG_TYPE_IN_PLACE for the type's naming decl.  */
	  if (!(TREE_CODE (*anode) == TYPE_DECL
		&& *anode == TYPE_NAME (TYPE_MAIN_VARIANT
					(TREE_TYPE (*anode)))))
	    flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
	}

      if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
	  && TREE_CODE (*anode) != METHOD_TYPE)
	{
	  if (TREE_CODE (*anode) == POINTER_TYPE
	      && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
		  || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
	    {
	      /* OK, this is a bit convoluted.  We can't just make a copy
		 of the pointer type and modify its TREE_TYPE, because if
		 we change the attributes of the target type the pointer
		 type needs to have a different TYPE_MAIN_VARIANT.  So we
		 pull out the target type now, frob it as appropriate, and
		 rebuild the pointer type later.

		 This would all be simpler if attributes were part of the
		 declarator, grumble grumble.  */
	      fn_ptr_tmp = TREE_TYPE (*anode);
	      anode = &fn_ptr_tmp;
	      flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
	    }
	  else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
	    {
	      /* Pass on this attribute to be tried again.  */
	      returned_attrs = tree_cons (name, args, returned_attrs);
	      continue;
	    }

	  if (TREE_CODE (*anode) != FUNCTION_TYPE
	      && TREE_CODE (*anode) != METHOD_TYPE)
	    {
	      warning (OPT_Wattributes,
		       "%qs attribute only applies to function types",
		       IDENTIFIER_POINTER (name));
	      continue;
	    }
	}

      if (TYPE_P (*anode)
	  && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
	  && TYPE_SIZE (*anode) != NULL_TREE)
	{
	  warning (OPT_Wattributes, "type attributes ignored after type is already defined");
	  continue;
	}

      if (spec->handler != NULL)
        {
          tree ret_attr = (*spec->handler) (anode, name, args,
                                            flags, &no_add_attrs);
          if (ret_attr)
            {
              /* For the lock attributes whose arguments (i.e. locks) are not
                 supported or the names are not in scope, we would demote the
                 attributes. For example, if 'foo' is not in scope in the
                 attribute "guarded_by(foo->lock), the attribute would be
                 downgraded to a "guarded" attribute. And in this case, the
                 handler would return the new, demoted attribute which is
                 appended to the current one so that it is handled in the next
                 iteration.  */
              if (is_lock_attribute_with_args (name))
                {
                  gcc_assert (no_add_attrs);
                  TREE_CHAIN (ret_attr) = TREE_CHAIN (a);
                  TREE_CHAIN (a) = ret_attr;
                  continue;
                }
              else
                returned_attrs = chainon (ret_attr, returned_attrs);
            }
        }

      /* Layout the decl in case anything changed.  */
      if (spec->type_required && DECL_P (*node)
	  && (TREE_CODE (*node) == VAR_DECL
	      || TREE_CODE (*node) == PARM_DECL
	      || TREE_CODE (*node) == RESULT_DECL))
	relayout_decl (*node);

      if (!no_add_attrs)
	{
	  tree old_attrs;
	  tree a;

	  if (DECL_P (*anode))
	    old_attrs = DECL_ATTRIBUTES (*anode);
	  else
	    old_attrs = TYPE_ATTRIBUTES (*anode);

	  for (a = lookup_attribute (spec->name, old_attrs);
	       a != NULL_TREE;
	       a = lookup_attribute (spec->name, TREE_CHAIN (a)))
	    {
	      if (simple_cst_equal (TREE_VALUE (a), args) == 1)
		break;
              /* If a lock attribute of the same kind is already on the decl,
                 don't add this one again. Instead, merge the arguments.  */
              if (is_lock_attribute_with_args (name))
                {
                  merge_lock_attr_args (a, args);
                  break;
                }
	    }

	  if (a == NULL_TREE)
	    {
	      /* This attribute isn't already in the list.  */
	      if (DECL_P (*anode))
		DECL_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
	      else if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
		{
		  TYPE_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
		  /* If this is the main variant, also push the attributes
		     out to the other variants.  */
		  if (*anode == TYPE_MAIN_VARIANT (*anode))
		    {
		      tree variant;
		      for (variant = *anode; variant;
			   variant = TYPE_NEXT_VARIANT (variant))
			{
			  if (TYPE_ATTRIBUTES (variant) == old_attrs)
			    TYPE_ATTRIBUTES (variant)
			      = TYPE_ATTRIBUTES (*anode);
			  else if (!lookup_attribute
				   (spec->name, TYPE_ATTRIBUTES (variant)))
			    TYPE_ATTRIBUTES (variant) = tree_cons
			      (name, args, TYPE_ATTRIBUTES (variant));
			}
		    }
		}
	      else
		*anode = build_type_attribute_variant (*anode,
						       tree_cons (name, args,
								  old_attrs));
	    }
	}

      if (fn_ptr_tmp)
	{
	  /* Rebuild the function pointer type and put it in the
	     appropriate place.  */
	  fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);
	  if (DECL_P (*node))
	    TREE_TYPE (*node) = fn_ptr_tmp;
	  else
	    {
	      gcc_assert (TREE_CODE (*node) == POINTER_TYPE);
	      *node = fn_ptr_tmp;
	    }
	}
    }

  return returned_attrs;
}
Esempio n. 17
0
File: echo.c Progetto: mbkulik/mg
/*
 * Do completion on a list of objects, listing instead of completing.
 */
static int
complt_list(int flags, char *buf, int cpos)
{
	struct list	*lh, *lh2, *lh3;
	struct list	*wholelist = NULL;
	struct buffer	*bp;
	int	 i, maxwidth, width;
	int	 preflen = 0;
	int	 oldrow = ttrow;
	int	 oldcol = ttcol;
	int	 oldhue = tthue;
	char	 *linebuf;
	size_t	 linesize, len;
	char *cp;

	lh = NULL;

	ttflush();

	/* The results are put into a completion buffer. */
	bp = bfind("*Completions*", TRUE);
	if (bclear(bp) == FALSE)
		return (FALSE);

	/*
	 * First get the list of objects.  This list may contain only
	 * the ones that complete what has been typed, or may be the
	 * whole list of all objects of this type.  They are filtered
	 * later in any case.  Set wholelist if the list has been
	 * cons'ed up just for us, so we can free it later.  We have
	 * to copy the buffer list for this function even though we
	 * didn't for complt.  The sorting code does destructive
	 * changes to the list, which we don't want to happen to the
	 * main buffer list!
	 */
	if ((flags & EFBUF) != 0)
		wholelist = lh = copy_list(&(bheadp->b_list));
	else if ((flags & EFFUNC) != 0) {
		buf[cpos] = '\0';
		wholelist = lh = complete_function_list(buf);
	} else if ((flags & EFFILE) != 0) {
		buf[cpos] = '\0';
		wholelist = lh = make_file_list(buf);
		/*
		 * We don't want to display stuff up to the / for file
		 * names preflen is the list of a prefix of what the
		 * user typed that should not be displayed.
		 */
		cp = strrchr(buf, '/');
		if (cp)
			preflen = cp - buf + 1;
	} else
		panic("broken complt call: flags");

	/*
	 * Sort the list, since users expect to see it in alphabetic
	 * order.
	 */
	lh2 = lh;
	while (lh2 != NULL) {
		lh3 = lh2->l_next;
		while (lh3 != NULL) {
			if (strcmp(lh2->l_name, lh3->l_name) > 0) {
				cp = lh2->l_name;
				lh2->l_name = lh3->l_name;
				lh3->l_name = cp;
			}
			lh3 = lh3->l_next;
		}
		lh2 = lh2->l_next;
	}

	/*
	 * First find max width of object to be displayed, so we can
	 * put several on a line.
	 */
	maxwidth = 0;
	lh2 = lh;
	while (lh2 != NULL) {
		for (i = 0; i < cpos; ++i) {
			if (buf[i] != lh2->l_name[i])
				break;
		}
		if (i == cpos) {
			width = strlen(lh2->l_name);
			if (width > maxwidth)
				maxwidth = width;
		}
		lh2 = lh2->l_next;
	}
	maxwidth += 1 - preflen;

	/*
	 * Now do the display.  Objects are written into linebuf until
	 * it fills, and then put into the help buffer.
	 */
	linesize = MAX(ncol, maxwidth) + 1;
	if ((linebuf = malloc(linesize)) == NULL) {
		free_file_list(wholelist);
		return (FALSE);
	}
	width = 0;

	/*
	 * We're going to strlcat() into the buffer, so it has to be
	 * NUL terminated.
	 */
	linebuf[0] = '\0';
	for (lh2 = lh; lh2 != NULL; lh2 = lh2->l_next) {
		for (i = 0; i < cpos; ++i) {
			if (buf[i] != lh2->l_name[i])
				break;
		}
		/* if we have a match */
		if (i == cpos) {
			/* if it wraps */
			if ((width + maxwidth) > ncol) {
				addline(bp, linebuf);
				linebuf[0] = '\0';
				width = 0;
			}
			len = strlcat(linebuf, lh2->l_name + preflen,
			    linesize);
			width += maxwidth;
			if (len < width && width < linesize) {
				/* pad so the objects nicely line up */
				memset(linebuf + len, ' ',
				    maxwidth - strlen(lh2->l_name + preflen));
				linebuf[width] = '\0';
			}
		}
	}
	if (width > 0)
		addline(bp, linebuf);
	free(linebuf);

	/*
	 * Note that we free lists only if they are put in wholelist lists
	 * that were built just for us should be freed.  However when we use
	 * the buffer list, obviously we don't want it freed.
	 */
	free_file_list(wholelist);
	popbuftop(bp, WEPHEM);	/* split the screen and put up the help
				 * buffer */
	update(CMODE);		/* needed to make the new stuff actually
				 * appear */
	ttmove(oldrow, oldcol);	/* update leaves cursor in arbitrary place */
	ttcolor(oldhue);	/* with arbitrary color */
	ttflush();
	return (0);
}
Esempio n. 18
0
// ================================================================================
// This program stress tests the templated MultiLL container class
int main() {


  // The test data (stored in STL lists)
  std::list<std::string> songs;
  songs.push_back("hound dog");
  songs.push_back("poker face");
  songs.push_back("brown eyed girl");
  songs.push_back("let it be");
  songs.push_back("walk like an egyptian");
  songs.push_back("man in the mirror");
  songs.push_back("stairway to heaven");
  songs.push_back("dancing in the street");
  songs.push_back("every breath you take");
  songs.push_back("hotel california");
  // the same data, sorted!
  std::list<std::string> sorted_songs(songs);
  sorted_songs.sort();


  // create an empty multi-linked list and fill it with the test data
  MultiLL<std::string> my_list;
  for (std::list<std::string>::iterator itr = songs.begin(); itr != songs.end(); itr++) {
    my_list.add(*itr);
    my_print(my_list);
  }
  assert (songs.size() == my_list.size());



  // -------------------
  // iterator tests

  // test the chronological iterator (forwards)
  std::cout << "chronological order" << std::endl;
  std::list<std::string> chrono_order;
  MultiLL<std::string>::iterator itr = my_list.begin_chronological();
  while (itr != my_list.end_chronological()) {
    std::cout << "  " << *itr << std::endl;
    chrono_order.push_back(*itr);
    itr++;
  }
  std::cout << std::endl;
  assert (same(songs,chrono_order));


  // test the sorted order iterator (forwards)
  std::cout << "sorted order" << std::endl;
  std::list<std::string> sorted_order;
  itr = my_list.begin_sorted();
  while (itr != my_list.end_sorted()) {
    std::cout << "  " << *itr << std::endl;
    sorted_order.push_back(*itr);
    itr++;
  }
  std::cout << std::endl;
  assert (same(sorted_songs,sorted_order));


  // test the random order iterator
  std::cout << "random order" << std::endl;
  std::list<std::string> random_order;
  itr = my_list.begin_random();
  for (int i = 0; i < my_list.size(); i++,itr++) {
    std::cout << "  " << *itr << std::endl;
    random_order.push_back(*itr);
  }
  std::cout << std::endl;
  // loop through the elements a second time (the order should be the same!)
  std::list<std::string>::iterator itr2 = random_order.begin();
  for (int i = 0; i < my_list.size(); i++,itr++,itr2++) {
    // verify that the elements repeat the order
    assert (*itr == *itr2);
  }
  std::list<std::string> random_order_check(random_order);
  random_order_check.sort();
  // verify that all of the elements appeared in the initial loop
  assert (same(sorted_songs,random_order_check));



  // test the re-randomization by creating a new random iterator
  std::cout << "random order 2" << std::endl;
  std::list<std::string> random_order2;
  itr = my_list.begin_random();
  for (int i = 0; i < my_list.size(); i++,itr++) {
    std::cout << "  " << *itr << std::endl;
    random_order2.push_back(*itr);
  }
  std::cout << std::endl;
  // with over 3 million different possible permutations of 10
  // elements, it is highly unlikely they will be the same!
  assert (!same(random_order,random_order2));


  
  /*
  // -------------------
  // erase tests

  // erase the first element inserted
  itr = my_list.begin_chronological();
  assert (*itr == "hound dog");
  itr = my_list.erase(itr);
  assert (*itr == "poker face");
  assert (my_list.size() == 9);
  std::cout << "erased: hound dog" << std::endl;

  // erase the second to last element in sorted order
  itr = my_list.begin_sorted();
  for (int i = 0; i < 7; i++) { itr++; }
  assert (*itr == "stairway to heaven");
  itr = my_list.erase(itr);
  assert (*itr == "walk like an egyptian");
  assert (my_list.size() == 8);  
  std::cout << "erased: stairway to heaven" << std::endl;

  // erase the third element in the random order
  itr = my_list.begin_random();
  itr++;
  itr++;
  std::string tmp = *itr;
  // note that the return value of erase with a random iterator is undefined
  my_list.erase(itr);
  std::cout << "erased: " << tmp << std::endl;
  assert (my_list.size() == 7);
  assert (!my_list.empty());

  my_list.clear();
  assert (my_list.empty());
  assert (my_list.size() == 0);
  std::cout << "cleared the whole list!" << std::endl << std::endl;
  */



  // ---------------------------
  // ADD YOUR OWN TEST CASES BELOW
  
  // be sure to test:
  //   copy constructor
  //   assignment operator
  //   destructor
  //   all corner cases of erase
  //   decrement operator for the chronological & sorted iterators
  //   pre vs. post increment & decrement operations for iterators
  //   MultiLL containing types other than std::string
  //   anything else that is necessary




  std::cout << " ***  OUTPUT FROM YOUR TEST CASES ***" << std::endl;

  // copy constructor
  MultiLL<std::string> copy_list(my_list);

  std::cout << "Old list:" << std::endl;
  my_print(my_list);
  /*
  std::cout << "Copy of old list:" << std::endl;
  my_print(copy_list);
  */




}
Esempio n. 19
0
/**
* Main program execution
*/
int main (int argc, char *argv[]) {
	TOKENIZER *tokenizer;
	char string[1024] = "";
	char *tok;
	int br;

	int most_recent_job = 0;

	ProcessMap *jobs = new_map();

	//Set up signal handling
	signal(SIGINT, SIG_IGN);
	signal(SIGTSTP, SIG_IGN);
	signal(SIGTTOU, SIG_IGN);
	signal(SIGTTIN, SIG_IGN);
	signal(SIGTERM, SIG_IGN);


	string[1023] = '\0';	   /* ensure that string is always null-terminated */
	printf("\nEnter a command or type ctrl-d to end session.\n" );
	write(1, "\nmy-sh$ ", 8);

	//Input loop
	while ((br = read( STDIN_FILENO, string, 1023 )) > 0) {

		if (br <= 1) {
			write(1, "my-sh$ ", 8);
			continue;
		}

		string[br-1] = '\0';
		tokenizer = init_tokenizer(string);

		//Create linked list of tokens
		LinkedList *input_command = new_list(256);
		while( (tok = get_next_token( tokenizer )) != NULL ) {
			push_back(input_command, tok);
			free(tok);
		}
		free_tokenizer(tokenizer);


		int executed = 0;
		int error = 0;
		//Checks for fg or bg
		if (get_length(input_command) == 1) {
			char *only_token = pop_back(input_command);

			if (compare_strings(only_token, "fg")) {
				if (move_to_foreground(jobs, &most_recent_job) == -1)
					error = 1;
				executed = 1;
					
			} else if (compare_strings(only_token, "bg")) {
				if (move_to_background(jobs, &most_recent_job) == -1)
					error = 1;
				executed = 1;
			} else {
				push_back(input_command, only_token);
			}
			free(only_token);
		}


		//Process input for pipes or background if an error has already been detected, go to the next command
		if (!executed && !error) {

			//Sees if a background ampersand is detected
			bool is_background = determine_background(input_command);

			LinkedList *full_command = copy_list(input_command);

			if (is_background) {
				printf("Running: ");
				print_list(input_command);
			}

			//Test for pipes
			bool is_pipe = false;
			LinkedList *first_command_list = new_list(50);
			LinkedList *second_command_list = new_list(50);
			int valid_pipe = find_piping(input_command, &is_pipe, first_command_list, second_command_list);

			//Command blocks are created from the command lists
			CommandBlock *first_command = new_command_block(first_command_list);
			CommandBlock *second_command = new_command_block(second_command_list);

			//Runs a function to check that there are no invalid redirections in the case of a piping
			if (is_pipe) {
				valid_pipe = valid_pipe && check_pipe(first_command, second_command);
			}

			//Notifies user of any incorrect pipe commands
			if (!is_pipe && !first_command->valid) {
				printf("Invalid command structure\n");
			} else if (is_pipe && (!first_command->valid || !second_command->valid || !valid_pipe) ) {
				printf("Invalid command structure\n");
			}


			//If it is a pipe and all necessary conditions are valid, then the piping occurs
			if (is_pipe && first_command->valid && second_command->valid && valid_pipe) {
				
				if (pipe_job (first_command, second_command, is_background, full_command, jobs, &most_recent_job) 
					== -1)
					error = 1;

			} 
			// No piping
			else if (!is_pipe && first_command->valid) {

				if (job (first_command, is_background, full_command, jobs, &most_recent_job) == -1)
					error = 1;
			}

			destroy_list(first_command_list);
			destroy_list(second_command_list);
			destroy_block(first_command);
			destroy_block(second_command);
			destroy_list(full_command);
		}

		destroy_list(input_command);

		
		monitor_background_jobs (jobs, &most_recent_job);

		if (error)
			perror("ERROR ");

		write(1, "my-sh$ ", 8);
	}

	destroy_map(jobs);

	
	
	printf( "\nSession ended\n" );
	return 0;
}
Esempio n. 20
0
int main(int argc, char *argv[]){
    long start_t = time(NULL);
    long end_t = 0;
    int generations = 0;
    struct Node *cur_gen = NULL;
    struct Node *mate_pool = NULL;
    struct Node *next_gen = NULL;
    int i;
    /* Seed of random */
    srandom(time(NULL));

    /* Initialize the first generation */
    for (i = 0; i < POPULATION; i++){
        push(&cur_gen, initialize());
    }

    struct Node *list_index = cur_gen;
    while (list_index != NULL){
        /* Compute fitness */
        comp_fitness(&(list_index->organism));
        list_index = list_index->next;
    }

    /* Sort descending the initial population */
    sort(&cur_gen);
    generations++;
    float biggest_fit = 0;
    do{

        list_index = cur_gen;
        /* First next generation */
        int new_gen_pop = POPULATION * POP_RATE;
        /* Sort descenting the current population */
        sort(&cur_gen);
        list_index = cur_gen;
        /* Copy POP_RATE best primitive organisms to mating pool */
        for (i = 0; i < new_gen_pop; i++){
            push(&mate_pool, list_index->organism);
            list_index = list_index->next;
        }

        /* Mate organisms */
        for (i = 0; i < size(mate_pool); i++){
            mate(&next_gen, mate_pool);
        }

        /* Mutate the first organisms */
        int mutated = POPULATION * MUT_RATE;
        list_index = next_gen;
        for(i = 0; i < mutated; i++){
            mutate(&list_index);
            list_index = list_index->next;
        }
        /* Sort descending the next generation */
        sort(&next_gen);
        /* The organism with the biggest fitness is the first one */
        biggest_fit = next_gen->organism.fitness;
        /* Print the organism with fitness = 1 (aka final) */
        if (biggest_fit == 1)
            print_gene(next_gen->organism);
        printf("Biggest fitness in generation %d:  %f\n", generations, biggest_fit);

        /* Delete current generation */
        delete(&cur_gen);
        cur_gen = NULL;
        /* Copy next generation to current */
        copy_list(&next_gen, &cur_gen);
        /* Delete next generation and mating pool */
        delete(&next_gen);
        delete(&mate_pool);
        next_gen = NULL;
        mate_pool = NULL;
        generations++;
    }while(biggest_fit < 1);
    end_t = time(NULL);
    printf("Computed after %d generations and after %d seconds.\n", generations - 1,
        (int)(end_t - start_t));
    exit(EXIT_SUCCESS);
}
Esempio n. 21
0
/* This main function does a little testing
   Like all good CS Majors you should test
   your code here. There is no substitute for testing
   and you should be sure to test for all edge cases
   e.g., calling remove_front on an empty list.
*/
int main(void)
{
	/* Now to make use of all of this stuff */
	list* llist = create_list();

  	/* What does an empty list contain?  Lets use our handy traversal function */
  	printf("TEST CASE 1\nAn Empty list should print nothing here:\n");
  	traverse(llist, print_student);
	printf("\n");

 	/* Lets add a student and then print */
 	push_front(llist, create_student("Mahmoud", "Joudeh", 20));
 	printf("TEST CASE 2\nA List with one student should print that student:\n");
	
	traverse(llist, print_student);
 	printf("\n");

 	/* Lets remove that student and then print */
 	remove_front(llist, free_student);
 	printf("TEST CASE 3\nAnother Empty list should print nothing here:\n");
 	
	traverse(llist, print_student);
 	printf("\n");

 	/* Lets add two elements and then print */
 	push_front(llist, create_student("Alex", "Ikonomidis", 19));
 	push_front(llist, create_student("Andrew", "Kim", 21));
 	printf("TEST CASE 4\nA List with two students should print those two students:\n");
 	traverse(llist, print_student);
 	printf("\n");

	/* Lets copy this list */
	list* llist2 = copy_list(llist, copy_student);
	
	printf("TEST CASE 5\nA copied list should print out the same two students:\n");
 	traverse(llist, print_student);
 	printf("\n");

  	/* Lets kill the list */
  	empty_list(llist, free_student);
 	printf("TEST CASE 6\nAfter freeing all nodes the list should be empty:\n");
 	traverse(llist, print_student);
	printf("\n");
	empty_list(llist2, free_student);
	free(llist);
	free(llist2);
 	/* YOU ARE REQUIRED TO MAKE MORE TEST CASES THAN THE ONES PROVIDED HERE */
 	/* You will get points off if you do not you should at least test each function here */

	/*Sample Tests*/
	llist = create_list();
	printf("\n4 Elements added\n ");
	push_front(llist, create_student("Abra", "Cadabra",14));
	push_front(llist, create_student("bing", "google", 10));
	push_front(llist, create_student("costa", "rica", 10));
	push_front(llist, create_student("Delta", " ", 17));
	//push_front(llist, NULL);
	traverse(llist, print_student);
	printf("\n");
		
	
	printf("Removed %d elements of age 10\n", remove_if(llist, age_is_ten, free_student));
	traverse(llist, print_student);
	remove_front(llist, free_student);
	list* list2 = copy_list(llist, copy_student);
	remove_front(llist, free_student);
	remove_back(list2, free_student);
	printf("\nEmptying list \n");
	traverse(llist, print_student_simple);
	
	i = 0;
	printf("\n500 elements being added\n");
	while(i++ < 500)
	{
			
			push_front(llist, create_student("sdflj", "sdlfs", rand()%10));

	}

	printf("\nis Empty? %d\n", is_empty(llist));
	printf("\n");
	//traverse(llist, print_student);
	
	
	
	i = 0;
	
	printf("\nRemoving 500 elements until empty\n");
	while(!is_empty(llist)){

		remove_front(llist, free_student);
	
		//practice(llist);
	}
	printf("\nis Empty? %d\n", is_empty(llist));
	
	empty_list(llist, free_student);

	remove_if(llist, trueVal, free_student);
	
	traverse(llist, print_student);	
	
	printf("\n");
	printf("\nEmptiness\n");
	remove_back(llist, free_student);
	
	traverse(llist, print_student);
	
	traverse(list2, print_student);
	
	
 	/* Testing over clean up*/
	empty_list(llist, free_student);
	empty_list(list2, free_student);
 	free(llist);
	free(list2);
	
	printf("\nAdding random numbers to the list\n");
	llist = create_list();
	i = 0;
	while (i < sizeof(numeros)/sizeof(numeros[0]))
		push_back(llist, create_student("a", "ab", numeros[i++]));

	traverse(llist, print_student_simple);
	printf("\n");

	printf("\nRemoving numbers in a random order\n");
	i = 0;
	while( i < sizeof(_numeros)/sizeof(_numeros[0]))
	{
		int total = remove_if(llist, randomizer, free_student);
		printf("size is %d after %d removes of %d: ", size(llist),  total, _numeros[i]);
		traverse(llist, print_student_simple);
		printf("\n");
		i++;
	}
	printf("\nEmpty size: \n");
	printf("list of size %d: ", size(llist));traverse(llist, print_student_simple);

	printf("\nTesting push_back and remove_if\n");
	push_back(llist, create_student("a", "b", 9));
	traverse(llist, print_student_simple); printf("\n");
	remove_if(llist, age_is_ten, free_student);
	traverse(llist, print_student_simple); printf("\n");
	empty_list(llist, free_student);
	traverse(llist, print_student_simple); printf("\n");
	printf("\nTesting push_front and remove_if\n");
	push_front(llist, create_student("a", "b", 9));
	traverse(llist, print_student_simple); printf("\n");
	remove_if(llist, age_is_ten, free_student);
	traverse(llist, print_student_simple); printf("\n");
	empty_list(llist, free_student);
	traverse(llist, print_student_simple); printf("\n");
	
	printf("\nTesting push_back and remove_if\n");
	push_back(llist, create_student("a", "b", 10));
	traverse(llist, print_student_simple); printf("\n");
	remove_if(llist, age_is_ten, free_student);
	traverse(llist, print_student_simple); printf("\n");
		
	printf("\nTesting push_front and remove_if\n");
	push_front(llist, create_student("a", "b", 10));
	traverse(llist, print_student_simple); printf("\n");
	remove_if(llist, age_is_ten, free_student);
	traverse(llist, print_student_simple); printf("\n");
	
	
	printf("\nTesting push_back and remove_front\n");
	push_back(llist, create_student("a", "b", 9));
	traverse(llist, print_student_simple); printf("\n");
	remove_front(llist, free_student);
	traverse(llist, print_student_simple); printf("\n");
	
	printf("\nTesting push_back and remove_back\n");
	push_back(llist, create_student("a", "b", 9));
	traverse(llist, print_student_simple); printf("\n");
	remove_back(llist, free_student);
	traverse(llist, print_student_simple); printf("\n");

	printf("\nTesting push_front and remove_front\n");
	push_front(llist, create_student("a", "b", 9));
	traverse(llist, print_student_simple); printf("\n");
	remove_front(llist, free_student);
	traverse(llist, print_student_simple); printf("\n");

	printf("\nTesting push_front and remove_back\n");
	push_front(llist, create_student("a", "b", 9));
	traverse(llist, print_student_simple); printf("\n");
	remove_back(llist, free_student);
	traverse(llist, print_student_simple); printf("\n");
	
	printf("\nEVERYTHING WORKS!!!\n");
	
	i = 0;
	printf("\n Testing return value of remove_if on empty list\n");
	while(i++ < 6)
		printf("%d ",remove_if(llist, trueVal, free_student));

	printf("\n Testing return value of remove_front on empty list\n");
	i = 0;
	while(i++ < 6)
		printf("%d ", remove_front(llist, free_student));

	printf("\n Testing return value of remove_back on empty list\n");
	i = 0;
	while(i++ < 6)
		printf("%d ", remove_back(llist, free_student));

	printf("\n Testing return value of remove_if on filled list\n");
	i = 0;
	while(i++ < 6)
		push_back(llist, create_student("a", "b", 3));
	i = 0;
	while(i++ < 6)
		printf("%d ",remove_if(llist, trueVal, free_student));
	
	printf("\n Testing return value of remove_front on filled list\n");
	i = 0;
	while(i++ < 6)
		push_back(llist, create_student("a", "b", 3));
	i = 0;
	while(i++ < 6)
		printf("%d ",remove_front(llist,free_student));

	printf("\n Testing return value of remove_back on filled list\n");
	i = 0;
	while(i++ < 6)
		push_back(llist, create_student("a", "b", 3));
	i = 0;
	while(i++ < 6)
		printf("%d ",remove_back(llist,free_student));
	
	printf("\nTesting size: ");
	i = 0;
	while(i++ < 6)
		push_back(llist, create_student("a", "b", 3));
	
	printf("\nsize %d: ", size(llist));
	printf("\nEmptying it: ");
	empty_list(llist, free_student);
	printf("\tsize %d: ", size(llist));

	i = 0;
	while(i++ < 6)
		push_back(llist, create_student("a", "b", numeros[i]));
	printf("\nTesting copy method, values getting squared\n");
	printf("\n");
	list2 = copy_list(llist, copy_student0);
	traverse(llist, print_student_simple);
	printf("\n");
	traverse(list2, print_student_simple);
	printf("\n");

	printf("\nTesting front and back methods:\n");
	printf("Front: ");print_student(front(llist));
	printf("\nBack: ");print_student(back(llist));
	printf("\n_Front: ");print_student(front(list2));
	printf("\n_Back: ");print_student(back(list2));

	printf("\nTesting remove_front and remove_back together\n");
	i = 0;
	while (i++ < 6)
	{
		remove_back(llist, free_student);
		printf("\n");
		traverse(llist, print_student_simple);
		remove_front(list2, free_student);
		printf("\n");
		traverse(list2, print_student_simple);
	}

	printf("\nEmptying the list\n");
	while(i++ < 9)
		empty_list(llist, free_student);

	printf("\nAdding a null element\n");
	push_back(llist, NULL);
	traverse(llist, print_student_simple);

	list *list3 = create_list();
	empty_list(list3, free_student_nulls);
	
	print_student_simple(front(list3));
	traverse(list3, print_student_simple);

	empty_list(llist, free_student_nulls);
	empty_list(list2, free_student);
	push_back(llist, create_student("one", "two", 5));
	push_back(list2, create_student("one", "two", 10));
	
	printf("\nTesting front and back methods with one element\n");
	printf("Front: ");print_student_simple(front(llist));
	printf("\nBack: ");print_student_simple(back(llist));
	printf("\n_Front: ");print_student_simple(front(list2));
	printf("\n_Back: ");print_student_simple(back(list2));
	
	empty_list(llist, free_student_nulls);
	empty_list(list2, free_student_nulls);
	printf("\nTesting front and back methods with empty list\n");
	printf("Front: ");print_student_simple(front(llist));
	printf("\nBack: ");print_student_simple(back(llist));
	printf("\n_Front: ");print_student_simple(front(list2));
	printf("\n_Back: ");print_student_simple(back(list2));
	printf("\nAll Empty List : \"");
	traverse(llist, print_student_simple);
	traverse(list2, print_student_simple);
	printf("\"\n");
	empty_list(list3, free_student);
	printf("\nYAY\n");
	free(llist);
	free(list2);
	
	free(list3);
	//cd /mnt/hgfs/B/Current\ Projects/HW\ 11\ \(2110\)/
  	return 0;
}
Esempio n. 22
0
/*
 * Does: Sorts a linked list using the quicksort algorithm.
 * Arguments:
 * -- list: A pointer to the first node of the linked list to
 *          be sorted.
 * Returns: A pointer to the first node of the sorted linked list.
 */
node *
quicksort(node *list)
{
    node *first_node;
    node *left_half = NULL;
    node *sorted_left_half = NULL;
    node *right_half = NULL;
    node *sorted_right_half = NULL;
    node *head;
    node *sorted_list;
    node *sorted_list2;
    int pivot;
    int head_data;

    /* If a null list or single node, return a copy of it */
    if (list == NULL || list->next == NULL)
    {
        return copy_list(list);
    }
    else /* Else, partition the list into left and right lists */
    {
        first_node = copy_list(list);
        free_list(first_node->next);
        first_node->next = NULL;

        /* Value with which data fields are compared against */
        pivot = first_node->data;
        head = list->next;
        while (head != NULL)
        {
            head_data = head->data;
            if (head_data < pivot)
            {
                /* Add nodes to left_half, creating the left_half list */
                left_half = create_node(head_data, left_half);
            }
            else
            {
                /* Add nodes to right_half, creating the right_half list */
                right_half = create_node(head_data, right_half);
            }
            head = head->next;
        }
        /* Sort the left_half recursively using quicksort */
        sorted_left_half = quicksort(left_half);
        free_list(left_half);
        left_half = sorted_left_half;

        /* Sort the right_half recursively using quicksort */
        sorted_right_half = quicksort(right_half);
        free_list(right_half);
        right_half = sorted_right_half;

        /*
         * Append the left and right halves with the first node in the
         * middle to create a sorted list.
         */
        sorted_list = append_lists(left_half, first_node);
        sorted_list2 = append_lists(sorted_list, right_half);

        /* Free memory */
        free_list(sorted_list);
        free_list(first_node);
        free_list(left_half);
        free_list(right_half);

        assert(is_sorted(sorted_list2));
        return sorted_list2;
    }
}
Esempio n. 23
0
list & list::operator=(const list & l)
{
    delete_list();
    copy_list(l.first, l.last);
    return *this;
}
Esempio n. 24
0
struct session *new_session(struct session *ses, char *name, char *arg, int desc)
{
	int cnt = 0;
	char host[BUFFER_SIZE], port[BUFFER_SIZE], file[BUFFER_SIZE];
	struct session *newsession;

	push_call("new_session(%p,%p,%p,%d)",ses,name,arg,desc);

	if (HAS_BIT(gtd->flags, TINTIN_FLAG_TERMINATE))
	{
		pop_call();
		return ses;
	}

	arg = sub_arg_in_braces(ses, arg, host, GET_ONE, SUB_VAR|SUB_FUN);
	arg = sub_arg_in_braces(ses, arg, port, GET_ONE, SUB_VAR|SUB_FUN);
	arg = sub_arg_in_braces(ses, arg, file, GET_ONE, SUB_VAR|SUB_FUN);

	if (desc == 0)
	{
		if (*host == 0)
		{
			tintin_puts(ses, "#HEY! SPECIFY AN ADDRESS WILL YOU?");

			pop_call();
			return ses;
		}

		if (*port == 0)
		{
			tintin_puts(ses, "#HEY! SPECIFY A PORT NUMBER WILL YOU?");

			pop_call();
			return ses;
		}
	}

	for (newsession = gts ; newsession ; newsession = newsession->next)
	{
		if (!strcmp(newsession->name, name))
		{
			tintin_puts(ses, "THERE'S A SESSION WITH THAT NAME ALREADY.");

			pop_call();
			return ses;
		}
	}

	newsession                = (struct session *) calloc(1, sizeof(struct session));

	newsession->name          = strdup(name);
	newsession->host          = strdup(host);
	newsession->ip            = strdup("");
	newsession->port          = strdup(port);

	newsession->group         = strdup(gts->group);
	newsession->flags         = gts->flags;
	newsession->telopts       = gts->telopts;
	newsession->auto_tab      = gts->auto_tab;

	newsession->cmd_color     = strdup(gts->cmd_color);

	newsession->read_max      = gts->read_max;
	newsession->read_buf      = (unsigned char *) calloc(1, gts->read_max);

	LINK(newsession, gts->next, gts->prev);

	for (cnt = 0 ; cnt < LIST_MAX ; cnt++)
	{
		newsession->list[cnt] = copy_list(newsession, gts->list[cnt], cnt);
	}

	newsession->rows          = gts->rows;
	newsession->cols          = gts->cols;
	newsession->top_row       = gts->top_row;
	newsession->bot_row       = gts->bot_row;

	init_buffer(newsession, gts->scroll_max);

	if (desc)
	{
		tintin_printf(ses, "#TRYING TO LAUNCH '%s' RUNNING '%s'.", newsession->name, newsession->host);
	}
	else
	{
		tintin_printf(ses, "#TRYING TO CONNECT '%s' TO '%s' PORT '%s'.", newsession->name, newsession->host, newsession->port);
	}

	gtd->ses = newsession;

	dirty_screen(newsession);

	if (desc == 0)
	{
		newsession = connect_session(newsession);
	}
	else
	{
		SET_BIT(newsession->flags, SES_FLAG_CONNECTED|SES_FLAG_RUN);

		SET_BIT(newsession->telopts, TELOPT_FLAG_SGA);
		DEL_BIT(newsession->telopts, TELOPT_FLAG_ECHO);

		gtd->ses = newsession;

		gtd->ses->socket = desc;
	}

	if (newsession)
	{
		if (*file)
		{
			do_read(newsession, file);
		}
	}

	pop_call();
	return gtd->ses;
}
Esempio n. 25
0
list::list(const list & l)
{
    copy_list(l.first, l.last);
}
Esempio n. 26
0
static int
_XTextPropertyToTextList(
    XLCd lcd,
    Display *dpy,
    const XTextProperty *text_prop,
    const char *to_type,
    XPointer **list_ret,
    int *count_ret)
{
    XlcConv conv = NULL;
    const char *from_type;
    XPointer from, to, buf;
    char *str_ptr, *last_ptr;
    Atom encoding;
    int from_left, to_left, buf_len, ret, len;
    int unconv_num, nitems = text_prop->nitems;
    Bool is_wide_char = False, do_strcpy = False;

    if (strcmp(XlcNWideChar, to_type) == 0)
	is_wide_char = True;

    if (nitems <= 0) {
	*list_ret = NULL;
	*count_ret = 0;
	return Success;
    }

    if (text_prop->format != 8)
	return XConverterNotFound;

    encoding = text_prop->encoding;
    if (encoding == XA_STRING)
	from_type = XlcNString;
    else if (encoding == XInternAtom(dpy, "UTF8_STRING", False))
	from_type = XlcNUtf8String;
    else if (encoding == XInternAtom(dpy, "COMPOUND_TEXT", False))
	from_type = XlcNCompoundText;
    else if (encoding == XInternAtom(dpy, XLC_PUBLIC(lcd, encoding_name), False))
	from_type = XlcNMultiByte;
    else
	return XConverterNotFound;

    if (is_wide_char) {
	buf_len = (text_prop->nitems + 1) * sizeof(wchar_t);
    } else {
	if (strcmp(to_type, XlcNUtf8String) == 0)
	    buf_len = text_prop->nitems * 6 + 1;
	else
	    buf_len = text_prop->nitems * XLC_PUBLIC(lcd, mb_cur_max) + 1;
    }
    buf = Xmalloc(buf_len);
    if (buf == NULL)
	return XNoMemory;
    to = buf;
    to_left = buf_len;

    /* can be XlcNMultiByte to XlcNMultiByte,
       or XlcNUtf8String to XlcNUtf8String */
    if (!strcmp(from_type, to_type)) {
        do_strcpy = True;
    } else {
        conv = _XlcOpenConverter(lcd, from_type, lcd, to_type);
        if (conv == NULL) {
	    Xfree(buf);
	    return XConverterNotFound;
        }
    }

    last_ptr = str_ptr = (char *) text_prop->value;
    unconv_num = *count_ret = 0;

    while (1) {
	if (nitems == 0 || *str_ptr == 0) {
	    from = (XPointer) last_ptr;
	    from_left = str_ptr - last_ptr;
	    last_ptr = str_ptr;

            if (do_strcpy) {
            	len = min(from_left, to_left);
                strncpy(to, from, len);
                from += len;
                to += len;
                from_left -= len;
                to_left -= len;
                ret = 0;
            } else {
	        ret = _XlcConvert(conv, &from, &from_left, &to, &to_left, NULL, 0);
            }

	    if (ret < 0)
		continue;

	    unconv_num += ret;
	    (*count_ret)++;

	    if (nitems == 0)
		break;
 	    last_ptr = ++str_ptr;
	    if (is_wide_char) {
		*((wchar_t *)to) = (wchar_t) 0;
		to += sizeof(wchar_t);
		to_left -= sizeof(wchar_t);
	    } else {
		*((char *)to) = '\0';
		to++;
		to_left--;
	    }
	    if (! do_strcpy)
	        _XlcResetConverter(conv);
	} else
	    str_ptr++;

	nitems--;
    }

    if (! do_strcpy)
        _XlcCloseConverter(conv);

    if (is_wide_char) {
	*((wchar_t *) to) = (wchar_t) 0;
	to_left -= sizeof(wchar_t);
    } else {
	*((char *) to) = '\0';
	to_left--;
    }

    *list_ret = alloc_list(is_wide_char, *count_ret, buf_len - to_left);
    if (*list_ret)
	copy_list(is_wide_char, buf, *list_ret, *count_ret);

    Xfree(buf);

    return unconv_num;
}
Esempio n. 27
0
krb5_error_code
pkinit_dup_identity_opts(pkinit_identity_opts *src_opts,
                         pkinit_identity_opts **dest_opts)
{
    pkinit_identity_opts *newopts;
    krb5_error_code retval;

    *dest_opts = NULL;
    retval = pkinit_init_identity_opts(&newopts);
    if (retval)
        return retval;

    retval = ENOMEM;

    if (src_opts->identity != NULL) {
        newopts->identity = strdup(src_opts->identity);
        if (newopts->identity == NULL)
            goto cleanup;
    }

    retval = copy_list(&newopts->anchors, src_opts->anchors);
    if (retval)
        goto cleanup;

    retval = copy_list(&newopts->intermediates,src_opts->intermediates);
    if (retval)
        goto cleanup;

    retval = copy_list(&newopts->crls, src_opts->crls);
    if (retval)
        goto cleanup;

    if (src_opts->ocsp != NULL) {
        newopts->ocsp = strdup(src_opts->ocsp);
        if (newopts->ocsp == NULL)
            goto cleanup;
    }

    if (src_opts->cert_filename != NULL) {
        newopts->cert_filename = strdup(src_opts->cert_filename);
        if (newopts->cert_filename == NULL)
            goto cleanup;
    }

    if (src_opts->key_filename != NULL) {
        newopts->key_filename = strdup(src_opts->key_filename);
        if (newopts->key_filename == NULL)
            goto cleanup;
    }

#ifndef WITHOUT_PKCS11
    if (src_opts->p11_module_name != NULL) {
        newopts->p11_module_name = strdup(src_opts->p11_module_name);
        if (newopts->p11_module_name == NULL)
            goto cleanup;
    }

    newopts->slotid = src_opts->slotid;

    if (src_opts->token_label != NULL) {
        newopts->token_label = strdup(src_opts->token_label);
        if (newopts->token_label == NULL)
            goto cleanup;
    }

    if (src_opts->cert_id_string != NULL) {
        newopts->cert_id_string = strdup(src_opts->cert_id_string);
        if (newopts->cert_id_string == NULL)
            goto cleanup;
    }

    if (src_opts->cert_label != NULL) {
        newopts->cert_label = strdup(src_opts->cert_label);
        if (newopts->cert_label == NULL)
            goto cleanup;
    }
#endif


    *dest_opts = newopts;
    return 0;
cleanup:
    pkinit_fini_identity_opts(newopts);
    return retval;
}
Esempio n. 28
0
tree
decl_attributes (tree *node, tree attributes, int flags)
{
  tree a;
  tree returned_attrs = NULL_TREE;

  if (TREE_TYPE (*node) == error_mark_node || attributes == error_mark_node)
    return NULL_TREE;

  if (!attributes_initialized)
    init_attributes ();

  /* If this is a function and the user used #pragma GCC optimize, add the
     options to the attribute((optimize(...))) list.  */
  if (TREE_CODE (*node) == FUNCTION_DECL && current_optimize_pragma)
    {
      tree cur_attr = lookup_attribute ("optimize", attributes);
      tree opts = copy_list (current_optimize_pragma);

      if (! cur_attr)
	attributes
	  = tree_cons (get_identifier ("optimize"), opts, attributes);
      else
	TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
    }

  if (TREE_CODE (*node) == FUNCTION_DECL
      && optimization_current_node != optimization_default_node
      && !DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node))
    DECL_FUNCTION_SPECIFIC_OPTIMIZATION (*node) = optimization_current_node;

  /* If this is a function and the user used #pragma GCC target, add the
     options to the attribute((target(...))) list.  */
  if (TREE_CODE (*node) == FUNCTION_DECL
      && current_target_pragma
      && targetm.target_option.valid_attribute_p (*node, NULL_TREE,
						  current_target_pragma, 0))
    {
      tree cur_attr = lookup_attribute ("target", attributes);
      tree opts = copy_list (current_target_pragma);

      if (! cur_attr)
	attributes = tree_cons (get_identifier ("target"), opts, attributes);
      else
	TREE_VALUE (cur_attr) = chainon (opts, TREE_VALUE (cur_attr));
    }

  /* A "naked" function attribute implies "noinline" and "noclone" for
     those targets that support it.  */
  if (TREE_CODE (*node) == FUNCTION_DECL
      && attributes
      && lookup_attribute_spec (get_identifier ("naked"))
      && lookup_attribute ("naked", attributes) != NULL)
    {
      if (lookup_attribute ("noinline", attributes) == NULL)
	attributes = tree_cons (get_identifier ("noinline"), NULL, attributes);

      if (lookup_attribute ("noclone", attributes) == NULL)
	attributes = tree_cons (get_identifier ("noclone"),  NULL, attributes);
    }

  targetm.insert_attributes (*node, &attributes);

  for (a = attributes; a; a = TREE_CHAIN (a))
    {
      tree ns = get_attribute_namespace (a);
      tree name = get_attribute_name (a);
      tree args = TREE_VALUE (a);
      tree *anode = node;
      const struct attribute_spec *spec =
	lookup_scoped_attribute_spec (ns, name);
      bool no_add_attrs = 0;
      int fn_ptr_quals = 0;
      tree fn_ptr_tmp = NULL_TREE;

      if (spec == NULL)
	{
	  if (!(flags & (int) ATTR_FLAG_BUILT_IN))
	    {
	      if (ns == NULL_TREE || !cxx11_attribute_p (a))
		warning (OPT_Wattributes, "%qE attribute directive ignored",
			 name);
	      else
		warning (OPT_Wattributes,
			 "%<%E::%E%> scoped attribute directive ignored",
			 ns, name);
	    }
	  continue;
	}
      else if (list_length (args) < spec->min_length
	       || (spec->max_length >= 0
		   && list_length (args) > spec->max_length))
	{
	  error ("wrong number of arguments specified for %qE attribute",
		 name);
	  continue;
	}
      gcc_assert (is_attribute_p (spec->name, name));

      if (TYPE_P (*node)
	  && cxx11_attribute_p (a)
	  && !(flags & ATTR_FLAG_TYPE_IN_PLACE))
	{
	  /* This is a c++11 attribute that appertains to a
	     type-specifier, outside of the definition of, a class
	     type.  Ignore it.  */
	  warning (OPT_Wattributes, "attribute ignored");
	  inform (input_location,
		  "an attribute that appertains to a type-specifier "
		  "is ignored");
	  continue;
	}

      if (spec->decl_required && !DECL_P (*anode))
	{
	  if (flags & ((int) ATTR_FLAG_DECL_NEXT
		       | (int) ATTR_FLAG_FUNCTION_NEXT
		       | (int) ATTR_FLAG_ARRAY_NEXT))
	    {
	      /* Pass on this attribute to be tried again.  */
	      returned_attrs = tree_cons (name, args, returned_attrs);
	      continue;
	    }
	  else
	    {
	      warning (OPT_Wattributes, "%qE attribute does not apply to types",
		       name);
	      continue;
	    }
	}

      /* If we require a type, but were passed a decl, set up to make a
	 new type and update the one in the decl.  ATTR_FLAG_TYPE_IN_PLACE
	 would have applied if we'd been passed a type, but we cannot modify
	 the decl's type in place here.  */
      if (spec->type_required && DECL_P (*anode))
	{
	  anode = &TREE_TYPE (*anode);
	  flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
	}

      if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE
	  && TREE_CODE (*anode) != METHOD_TYPE)
	{
	  if (TREE_CODE (*anode) == POINTER_TYPE
	      && (TREE_CODE (TREE_TYPE (*anode)) == FUNCTION_TYPE
		  || TREE_CODE (TREE_TYPE (*anode)) == METHOD_TYPE))
	    {
	      /* OK, this is a bit convoluted.  We can't just make a copy
		 of the pointer type and modify its TREE_TYPE, because if
		 we change the attributes of the target type the pointer
		 type needs to have a different TYPE_MAIN_VARIANT.  So we
		 pull out the target type now, frob it as appropriate, and
		 rebuild the pointer type later.

		 This would all be simpler if attributes were part of the
		 declarator, grumble grumble.  */
	      fn_ptr_tmp = TREE_TYPE (*anode);
	      fn_ptr_quals = TYPE_QUALS (*anode);
	      anode = &fn_ptr_tmp;
	      flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
	    }
	  else if (flags & (int) ATTR_FLAG_FUNCTION_NEXT)
	    {
	      /* Pass on this attribute to be tried again.  */
	      returned_attrs = tree_cons (name, args, returned_attrs);
	      continue;
	    }

	  if (TREE_CODE (*anode) != FUNCTION_TYPE
	      && TREE_CODE (*anode) != METHOD_TYPE)
	    {
	      warning (OPT_Wattributes,
		       "%qE attribute only applies to function types",
		       name);
	      continue;
	    }
	}

      if (TYPE_P (*anode)
	  && (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
	  && TYPE_SIZE (*anode) != NULL_TREE)
	{
	  warning (OPT_Wattributes, "type attributes ignored after type is already defined");
	  continue;
	}

      if (spec->handler != NULL)
	{
	  int cxx11_flag =
	    cxx11_attribute_p (a) ? ATTR_FLAG_CXX11 : 0;

	  returned_attrs = chainon ((*spec->handler) (anode, name, args,
						      flags|cxx11_flag,
						      &no_add_attrs),
				    returned_attrs);
	}

      /* Layout the decl in case anything changed.  */
      if (spec->type_required && DECL_P (*node)
	  && (TREE_CODE (*node) == VAR_DECL
	      || TREE_CODE (*node) == PARM_DECL
	      || TREE_CODE (*node) == RESULT_DECL))
	relayout_decl (*node);

      if (!no_add_attrs)
	{
	  tree old_attrs;
	  tree a;

	  if (DECL_P (*anode))
	    old_attrs = DECL_ATTRIBUTES (*anode);
	  else
	    old_attrs = TYPE_ATTRIBUTES (*anode);

	  for (a = lookup_attribute (spec->name, old_attrs);
	       a != NULL_TREE;
	       a = lookup_attribute (spec->name, TREE_CHAIN (a)))
	    {
	      if (simple_cst_equal (TREE_VALUE (a), args) == 1)
		break;
	    }

	  if (a == NULL_TREE)
	    {
	      /* This attribute isn't already in the list.  */
	      if (DECL_P (*anode))
		DECL_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
	      else if (flags & (int) ATTR_FLAG_TYPE_IN_PLACE)
		{
		  TYPE_ATTRIBUTES (*anode) = tree_cons (name, args, old_attrs);
		  /* If this is the main variant, also push the attributes
		     out to the other variants.  */
		  if (*anode == TYPE_MAIN_VARIANT (*anode))
		    {
		      tree variant;
		      for (variant = *anode; variant;
			   variant = TYPE_NEXT_VARIANT (variant))
			{
			  if (TYPE_ATTRIBUTES (variant) == old_attrs)
			    TYPE_ATTRIBUTES (variant)
			      = TYPE_ATTRIBUTES (*anode);
			  else if (!lookup_attribute
				   (spec->name, TYPE_ATTRIBUTES (variant)))
			    TYPE_ATTRIBUTES (variant) = tree_cons
			      (name, args, TYPE_ATTRIBUTES (variant));
			}
		    }
		}
	      else
		*anode = build_type_attribute_variant (*anode,
						       tree_cons (name, args,
								  old_attrs));
	    }
	}

      if (fn_ptr_tmp)
	{
	  /* Rebuild the function pointer type and put it in the
	     appropriate place.  */
	  fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);
	  if (fn_ptr_quals)
	    fn_ptr_tmp = build_qualified_type (fn_ptr_tmp, fn_ptr_quals);
	  if (DECL_P (*node))
	    TREE_TYPE (*node) = fn_ptr_tmp;
	  else
	    {
	      gcc_assert (TREE_CODE (*node) == POINTER_TYPE);
	      *node = fn_ptr_tmp;
	    }
	}
    }

  return returned_attrs;
}
Esempio n. 29
0
struct session *new_session(struct session *ses, char *name, char *command, int pid, int socket)
{
	int cnt = 0;
	struct session *newsession;

	push_call("new_session(%p,%p,%p,%d,%d)",ses,name,command,pid,socket);

	for (newsession = gts ; newsession ; newsession = newsession->next)
	{
		if (!strcmp(newsession->name, name))
		{
			display_puts(ses, "THERE'S A SESSION WITH THAT NAME ALREADY.");

			if (close(socket) == -1)
			{
				syserr("close in new_session");
			}

			kill(pid, SIGKILL);

			pop_call();
			return ses;
		}
	}

	newsession                = (struct session *) calloc(1, sizeof(struct session));

	newsession->name          = strdup(name);
	newsession->command       = strdup(command);
	newsession->pid           = pid;

	newsession->group         = strdup(gts->group);
	newsession->flags         = gts->flags;

	LINK(newsession, gts->next, gts->prev);

	for (cnt = 0 ; cnt < LIST_MAX ; cnt++)
	{
		newsession->list[cnt] = copy_list(newsession, gts->list[cnt], cnt);
	}

	newsession->rows          = gts->rows;
	newsession->cols          = gts->cols;

	display_printf(ses, "#TRYING TO LAUNCH '%s' RUNNING '%s'.", newsession->name, newsession->command);

	gtd->ses = newsession;

	SET_BIT(newsession->flags, SES_FLAG_CONNECTED|SES_FLAG_RUN);

	DEL_BIT(newsession->flags, SES_FLAG_LOCALECHO);

	gtd->ses = newsession;

	gtd->ses->socket = socket;

	check_all_events(ses, SUB_ARG|SUB_SEC, 0, 3, "SESSION CONNECTED", ses->name, ses->command, ntos(ses->pid));

	pop_call();
	return gtd->ses;
}