int main ()
{
	// create a linked list
	//struct node_t * head_node = NULL;
	struct node_t * curr_node = NULL;

	head = create_list(8);
	print_list();
	//printf("head node var= %d\n",head->var);
	printf("length of the list= %d\n",length_list());
	// append a list
	curr_node = append_list(10);
	print_list();
	//printf("variable appended = %d\n",curr_node->var);
	printf("variable appended = %d\n",head->next->var);
	printf("length of the list= %d\n",length_list());

	// insert a list
	//curr_node = insert_list(9);
	print_list();

	printf("length of the list= %d\n",length_list());

	// delete a list



	return 1;
}
示例#2
0
/*=============================================+
 * disp_list -- Display list contents
 *  used for drilldown in variable debugger
 *  list:  list to display
 *============================================*/
static void
disp_list (LIST list)
{
	struct dbgsymtab_s sdata;
	INT nels = length_list(list);
	if (!nels) {
		msg_info(_("list is empty"));
		return;
	}
	init_dbgsymtab_arrays(&sdata, nels);

	/* loop thru list building display array */
	{
		LIST_ITER listit = begin_list(list);
		VPTR ptr = 0;
		while (next_list_ptr(listit, &ptr)) {
			PVALUE val = ptr;
			char key[10];
			snprintf(key, sizeof(key), "%d", sdata.current+1);
			format_dbgsymtab_val(key, val, &sdata);
		}
		end_list_iter(&listit);
	}

	disp_dbgsymtab(_("LIST contents"), &sdata);

	free_dbgsymtab_arrays(&sdata);
}
示例#3
0
/*===================================================
 * get_proparray_of_files_in_path -- get array of property tables of files in path
 * Created: 2002/10/19, Perry Rapp
 *=================================================*/
TABLE *
get_proparray_of_files_in_path (CNSTRING path, SELECT_FNC selectfnc, INT * nfiles)
{
	/* get array of file property tables */
	LIST list = create_list();
	add_path_files_to_proplist(path, selectfnc, list);
	*nfiles = length_list(list);
	return convert_proplist_to_proparray(list);
}
示例#4
0
/*
Get item by index. If the index is out of range
it returns the first item in the list.
*/
int getitem_list(int index, NODE **Head) {
  if (index > length_list(Head) || index == 0)
    return (*Head)->num;
  int current = 0;
  NODE *p = *Head;
  while (p) {
    if (index == current)
      return p->num;
    p = p->next;
    current++;
  }
}
示例#5
0
/*===================================================
 * convert_proplist_to_proparray -- 
 *  Convert a list of property tables to an array of same
 *  Consumes the list (actually removes it at end)
 *  Output array is one larger than list, and last entry is NULL
 * Created: 2002/10/19, Perry Rapp
 *=================================================*/
TABLE *
convert_proplist_to_proparray (LIST list)
{
	TABLE * props;
	INT i;
	props = (TABLE *)malloc((length_list(list)+1)*sizeof(props[0]));
	i = 0;
	FORLIST(list, el)
		props[i++] = (TABLE)el;
	ENDLIST
	props[i] = NULL; /* null marker at end of array */
	destroy_list(list);
	return props;
}
示例#6
0
文件: main.c 项目: Lu511/-
// 排序链表
void sort_list(PNODE pHead)
{
    int i,j,t;
    int len = length_list(pHead);
    PNODE p,q;
    for (i = 0,p = pHead->pNext;i < len - 1 ; ++i,p = p->pNext) {
        for (j = i + 1,q = p->pNext; j < len; ++j,q = q->pNext) {
            if (p->data > q->data) {
                t = p->data;
                p->data = q->data;
                q->data = t;
            }
        }
    }
}
示例#7
0
void debug_list(){
  P list;
  list = P(3, P(1, P(4, P(1, P(5, P(9, 0))))));
  debug(list);
  debug(read_list(list,0));
  debug(read_list(list,1));
  debug(read_list(list,2));
  debug(read_list(list,3));
  debug(read_list(list,4));
  debug(read_list(list,5));
  list = reverse_list(list);
  debug(list);
  debug(length_list(list));
  debug(replicate_list(3,-1));
}
示例#8
0
/***************************************************************************
 * Function: void flush_output()
 *
 * Description:
 *   Use select() to determine which connections that have output pending
 * are capable of accepting output at the moment, and send as much data to
 * those connections as they will accept.
 **************************************************************************/
void flush_output() {
  conn_data *conn;
  fd_set fd_outset;
  struct timeval sel_timeout;
  iterator *conn_iter = create_iter(conn_list);;

/*
 * Clear out the fd_set and add to it the fds of all connections with
 * output pending.
 */
  FD_ZERO(&fd_outset);
  for (init_iter(conn_iter); (conn = peek_iter(conn_iter));
       iterate_iter(conn_iter)) {
    if (length_list(conn->output) != 0) FD_SET(conn->fd, &fd_outset);
  }

/*
 * Use select to determine which fds actually belong in the set.
 * (NOFILE is the maximum number of open files per process, as described
 * previously)
 */
  bzero(&sel_timeout, sizeof(struct timeval));
  if (select(NOFILE, NULL, &fd_outset, NULL, &sel_timeout) <0 ) {
    fprintf(stderr, "Error: Selection of ready file descriptors failed.\n");
    perror("  flush_output(select)");
    exit(ERROR);
  }

/*
 * Process connections with pending output.  Note that it is necessary to
 * iterate the iterator _before_ executing the loop in case the connection
 * we're currently working on gets disconnected.
 */
  for (init_iter(conn_iter); (conn = peek_iter(conn_iter)); ) {
    iterate_iter(conn_iter);

    if (FD_ISSET(conn->fd, &fd_outset)) {
      if (send_text(conn) <= 0) {
        disconnect(conn);
        continue;
      }
    }
  }

  destroy_iter(conn_iter);
}
示例#9
0
/*
Inserts an element 'elem' in the place index of
the list. Returns 1 if it inserted it ,
0 if it did not insert it and -1 if there was
a problem with the memory allocation.
WARNING: It will not insert an element in the
last place of the list unless the list is empty.
*/
int insert_list(TYPE_ elem, int index, NODE **Head) {
  // If the list is empty and index > 0
  if (*Head == NULL && index > 0) {
    return -1;
  }
  if (*Head == NULL && index == 0) {
    *Head = malloc(sizeof(NODE));
    if (*Head == NULL)
      return -1;
    (*Head)->num = elem;
    (*Head)->next = NULL;
    return 1;
  }
  NODE *p;
  if (index == 0) {
    p = malloc(sizeof(NODE));
    if (p == NULL)
      return -1;
    p->next = *Head;
    p->num = elem;
    (*Head) = p;
    return 1;
  }
  //	Search to find the correct place to insert 'elem'
  if (index == length_list(Head)) {
    append_list(elem, Head);
    return 1;
  }
  NODE *p1;
  p = (*Head)->next;
  int place = 1;
  while (p != NULL) {
    if (place == index - 1) {
      p1 = malloc(sizeof(NODE));
      p1->next = p->next;
      p->next = p1;
      p1->num = elem;
      return 1;
    }
    place++;
    p = p->next;
  }
  return -1;
}
示例#10
0
文件: tests.c 项目: UCL-INGI/SINF1252
// @mysem_post:test_post_take_first => [mysem_post ne retire pas le premier processus de la liste]
void test_post_take_first(void){
	mysem_t *sem=(mysem_t *)malloc(sizeof(mysem_t));
	mysem_init(sem,1);
	working_mysem_wait(sem);
	pthread_t th[3];

	/* On réutilise la fonction auxiliaire du test précédent */
	int i;
	for(i=0;i<3;i++)
		pthread_create(&(th[i]),NULL,&auxi_test_post_count,(void *)sem);
	usleep(200);

    sem_process_t *following = sem->blocked_procs->next;
    mysem_post(sem);
    CU_ASSERT_PTR_EQUAL(sem->blocked_procs,following);
	CU_ASSERT_EQUAL(length_list(sem->blocked_procs),2);

	//mysem_close(sem);
}
示例#11
0
/*链表大小排序*/
void sort_list(PNODE pHead)
{
	int i, j, t;
	int len = length_list(pHead);
	PNODE p, q;
/*理解泛型的概念,用p=p->pNext代替了p++*/
	for (i = 0, p = pHead->pNext; i < len-1; i++, p = p->pNext)   
	{
		for (j = i+1,  q = p->pNext; j < len; j++, q = q->pNext)
		{
			if (p->data > q->data)
			{
				t = p->data;
				p->data = q->data;
				q->data = t;
			}
		}
	}
}
int main(void)
{
	int len;
	int data_del;
	PNODE pHead = NULL;

	//创建链表并遍历输出
 	pHead = create_list();
	traverse_list(pHead);

	//求链表长度,并输出
	len = length_list(pHead);
	if(!is_empty(pHead))
		printf("the length of the list is:%d\n",len);
	
	//向链表中插入数据,并重新遍历输出
	if(insert_list(pHead,3,78))
		printf("insert succeed,");
	else
		printf("insert failed,");
	traverse_list(pHead);

	//从链表中删除数据,并重新遍历输出
	if(delete_list(pHead,3,&data_del))
		{
		  printf("delete succeed,the deleted data is:%d\n",data_del);
		}
	else
		printf("delete failed,");
	traverse_list(pHead);
	
	//对链表排序,重新遍历输出
	sort_list(pHead);
	printf("After sorted,");
	traverse_list(pHead);	
	
	//清空链表,遍历输出(无数据输出)
	clear_list(pHead);
	printf("After cleared,");
	traverse_list(pHead);	
	return 0;
}
示例#13
0
/***************************************************************************
 * Function: int send_text(conn_data *conn)
 *
 * Description:
 *   Write any data waiting in the connection's output string list to its
 * file descriptor.  All of the text in the list should have been through
 * any relevant processing already.  If a write to the connection's file
 * descriptor returns -1 and errno is set to something other than EWOULDBLOCK,
 * assume the connection has broken and return ERROR.  Otherwise return the
 * number of bytes successfully sent.  Note that this is BSD specific.  The
 * man page for write says that Sys V returns 0 if the write would block,
 * not -1.  However, since a write that returns 0 will end up being treated
 * the same as one that returns -1 and sets errno to EWOULDBLOCK in the long
 * run, the difference is irrelevant.
 **************************************************************************/
static int send_text(conn_data *conn) {
  int     result, length, total;
  string  *str;
  list    *output;

  result = length = total = 0;
  output = conn->output;

  while (TRUE) {
    str = get_data(output, FALSE);
    if (conn->out_pos == NULL) conn->out_pos = str->text;
    length = strlen(conn->out_pos);
    if ((result = write(conn->fd, conn->out_pos, length)) < 0) {
#ifdef BSD
      if (errno == EWOULDBLOCK) return(total);
#endif
      return(ERROR);
    }

    total += result;

/*
 * If the entire text of the current string was successfully sent, remove
 * it from the connection's output list, dereference it, and leave the
 * output loop if there are no more strings on the output list.  If the
 * entire text was _not_ output, set the connection's out_pos pointer to
 * indicate the location where future output should resume.
 */
    if (result == length) {
      get_data(output, TRUE);
      deref_string(str);
      conn->out_pos = NULL;
      if (length_list(output) == 0) break;
    } else {
      conn->out_pos += result;
      break;
    }
  }
  return(total);
}
示例#14
0
int main()
{
        /* linked list with a loop */
        slist *loop_list = NULL;
        int i;
        
        srand(time(NULL));
        for (i = 0; i < 7; i++) {
                loop_list = insert(loop_list, myrand());
        }
        //print(loop_list);

        slist *node = loop_list;
        while (node && node->next) {
                node = node->next;
        }
        //print(node);
        node->next = loop_list->next->next;

        printf("%d\n", length_list(loop_list));

        return 0;
}
示例#15
0
t_list_single find_on_web(const char *filepath, t_websearch search_engine, 
        int nbr_words, int skip_words, int *nbr_seq)
{
    t_list_single single;
    t_list_words l;
    t_list_single sites;

    INFO("Découpage du fichier");
    l = analyse_file(filepath, nbr_words, skip_words, &single, 0);

    *nbr_seq = length_list(l);

    INFO("Récupération des sites");
    sites = find_aux(l, search_engine, EMPTY_SL);

    INFO("Tri les sites trouvés");
    sort_single_list_by_weight(&sites);

    DEBUG("Libération de la mémoire");
    free_list(&l);
    free_single_list(&single);

    return sites;
}
示例#16
0
/* Extrait d'un fichier une liste de séquences */
t_list_words analyse_file(const char *filepath, int nbr_words, int skip_words,
        t_list_single *allwords, char sorted)
{
    FILE *f;
    t_list_words l;
    char **buffer_words;
    int posbuff;
    int i;
    int count;
    int offset;

    INFO("Analyse du fichier <%s> longueur séquence = %d, décalage = %d", 
            filepath, nbr_words, skip_words);

    /* Ouverture du fichier */
    INFO("Ouverture du fichier %s", filepath);
    f = fopen(filepath, "r");
    if (f==NULL) {
        ERROR("Erreur d'ouverture du fichier %s : %s", filepath, 
                strerror(errno));
        return EMPTY_LIST;
    }

    /* Initialisation d'un buffer contenant les N derniers mots */
    DEBUG("Initialisation d'un buffer pour %d mots", nbr_words);
    buffer_words = malloc(nbr_words*sizeof(char*));
    if (buffer_words == NULL) {
        ERROR("Erreur d'allocation mémoire : %s", strerror(errno));
        exit(100);
    }
    posbuff = nbr_words - 1;

    INFO("Construction de la liste de mots");
    l = EMPTY_LIST;
    *allwords = EMPTY_SL;

    INFO("Amorçage");
    for(i=0;i<nbr_words-1;i++) {
        buffer_words[i] = extract_word(f, &islatin1, &latin1_to_ascii, &offset);
        *allwords = cons_single(buffer_words[i], *allwords);
    }

    INFO("Itération");
    count = 0;
    while((buffer_words[posbuff] = extract_word(f, &islatin1, &latin1_to_ascii,
                    &offset))) {
        *allwords = cons_single(buffer_words[posbuff], *allwords);

        if (count == 0) {
            char **words = malloc(nbr_words*sizeof(char *));
            if (words == NULL) {
                FATAL("Erreur d'allocation mémoire : %s",strerror(errno));
                exit(100);
            }

            for(i = 0; i < nbr_words; i++) {
                words[i] = buffer_words[(posbuff+1+i)%nbr_words];
            }

            if (sorted) {
                add_sorted(build_words(nbr_words, words), &l);
            } else {
                l = cons_new_words(nbr_words, words, l);
            }

            count = skip_words;
        }

        posbuff = (posbuff+1)%nbr_words;
        count -= 1;
    }
    INFO("Fin de la construction de la liste de mots");

    /* Libération de la mémoire */
    DEBUG("Libération du buffer de mots");
    free(buffer_words);

    /* Fermeture du fichier */
    INFO("Fermeture du fichier %s", filepath);
    fclose(f);

    DEBUG("Nombre de séquences : %d", length_list(l));

    return l;
}
示例#17
0
void gui_RestrictWindow( PA_PluginParameters params )
{
	LONG_PTR				action = 0, returnValue = 0, styleChg = 0, numDeleted = 0;
	HWND				hWnd = NULL;
	HMENU				hSysMenu;
	WNDPROC			wpProc = NULL;
	pLL					thisLink = NULL, previousLink = NULL;


	// subClass procedure must be in place
	if (processHandles.wpProToolsOrigProc == NULL) {
			PA_ReturnLong( params, -2 );
			return;
	}

	hWnd  = (HWND) PA_GetLongParameter( params, 1 );
	action = PA_GetLongParameter( params, 2);

	if (IsWindow(hWnd)) {  // 09/09/02 more action values now so removed restriction
		returnValue = GetWindowLong(hWnd, GWL_STYLE);

		// eliminate sizing cursor and Window's sizing border
		switch (action)
		{
			case (RW_NO_MIN) :
				if ((returnValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) {
					styleChg = returnValue ^ WS_MINIMIZEBOX;
					returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg);
				}
				break;

			case (RW_NO_MAX) :
				if ((returnValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) {
					styleChg = returnValue ^ WS_MAXIMIZEBOX;
					returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg);
				}
				break;

			case (RW_NO_CLOSE) :
				hSysMenu = GetSystemMenu(hWnd,0);
				if (hSysMenu != NULL) {
					EnableMenuItem (hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
				}
				break;

			case (RW_RESTORE_CLOSE) :
				hSysMenu = GetSystemMenu(hWnd,0);
				if (hSysMenu != NULL) {
					EnableMenuItem (hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
				}
				break;
		}

		if (startOfList == NULL) {
			init_list(&startOfList);
		}
		// insert item in linked list -- if not already there
		if (!search_list( &startOfList, &thisLink, &previousLink, LL_hWnd, LL_Restrict, (LONG_PTR *) &hWnd)) {
			thisLink = (pLL) insert_list(&startOfList);
			if (thisLink == NULL) {
				PA_ReturnLong( params, -1 ); // could not add to list - get out
				return;
			}
		} else {
			PA_ReturnLong( params, (LONG_PTR)hWnd ); // return window handle if already in list
			return;
		}

		thisLink->hWnd = hWnd;
		thisLink->dataLong1 = action;
		thisLink->type = LL_Restrict;
		thisLink->wpProc = processHandles.wpProToolsOrigProc;
		returnValue = length_list(startOfList);

	}

	PA_ReturnLong( params, returnValue );
}
示例#18
0
void gui_RestrictWindow(PA_PluginParameters params, BOOL isEx)
{
	LONG				action = 0, returnValue = 0, styleChg = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG
	HWND				hWnd = NULL;
	HMENU				hSysMenu;
	pLL					thisLink = NULL, previousLink = NULL;
	LONG				hWndIndex = 0; // WJF 6/30/16 Win-21 LONG_PTR -> LONG

	// subClass procedure must be in place
	if (processHandles.wpProToolsOrigProc == NULL) {
		PA_ReturnLong(params, -2);
		return;
	}

	hWndIndex = PA_GetLongParameter(params, 1); // WJF 9/1/15 #43731 We are now getting an index to an internal array
	action = PA_GetLongParameter(params, 2);

	if (isEx){ // WJF 9/16/15 #43731
		hWnd = handleArray_retrieve((DWORD)hWndIndex);
	}
	else {
		hWnd = (HWND)hWndIndex;
	}

	if (IsWindow(hWnd)) {  // 09/09/02 more action values now so removed restriction
		returnValue = GetWindowLong(hWnd, GWL_STYLE);

		// eliminate sizing cursor and Window's sizing border
		switch (action)
		{
		case (RW_NO_MIN) :
			if ((returnValue & WS_MINIMIZEBOX) == WS_MINIMIZEBOX) {
				styleChg = returnValue ^ WS_MINIMIZEBOX;
				returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg);
			}
			break;

		case (RW_NO_MAX) :
			if ((returnValue & WS_MAXIMIZEBOX) == WS_MAXIMIZEBOX) {
				styleChg = returnValue ^ WS_MAXIMIZEBOX;
				returnValue = SetWindowLong(hWnd, GWL_STYLE, styleChg);
			}
			break;

		case (RW_NO_CLOSE) :
			hSysMenu = GetSystemMenu(hWnd, 0);
			if (hSysMenu != NULL) {
				EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_GRAYED);
			}
			break;

		case (RW_RESTORE_CLOSE) :
			hSysMenu = GetSystemMenu(hWnd, 0);
			if (hSysMenu != NULL) {
				EnableMenuItem(hSysMenu, SC_CLOSE, MF_BYCOMMAND | MF_ENABLED);
			}
			break;
		}

		if (startOfList == NULL) {
			init_list(&startOfList);
		}
		// insert item in linked list -- if not already there
		if (!search_list(&startOfList, &thisLink, &previousLink, LL_hWnd, LL_Restrict, (LONG_PTR *)&hWnd)) {
			thisLink = (pLL)insert_list(&startOfList);
			if (thisLink == NULL) {
				PA_ReturnLong(params, -1); // could not add to list - get out
				return;
			}
		}
		else {
			PA_ReturnLong(params, (LONG)hWnd); // return window handle if already in list // WJF 6/30/16 Win-21 Changed cast from LONG_PTR -> LONG
			return;
		}

		thisLink->hWnd = hWnd;
		thisLink->dataLong1 = action;
		thisLink->type = LL_Restrict;
		thisLink->wpProc = processHandles.wpProToolsOrigProc;
		returnValue = length_list(startOfList);
	}

	PA_ReturnLong(params, returnValue);
}