Exemple #1
0
int main(int argc, char *argv[])
{
  char *cmdline, **arglist;
  char *prompt;
  char **single_cmds;
  int i, cmd_number;
  int rv;

  prompt = DEL_PROMPT;
  setup();

  exec_cmds = malloc(sizeof(char*) * MAXEXECCMDS);

  while((cmdline = next_command(prompt, stdin)) != NULL)
  {
    single_cmds = split_command(cmdline);

    for (i = 0; single_cmds[i] != '\0'; ++i)
    {
      if ((arglist = splitline(single_cmds[i])) != NULL)
      {
        // for those arglist executed later, we don't free it.
        // we free later arglists in do_control_command's fi.
        if ((rv = process(arglist)) != -1)
          freelist(arglist);
      }
    }

    freelist(single_cmds);
    free(cmdline);
  }

  free(exec_cmds);
  return 0;
}
Exemple #2
0
int main(int ac,char *av[])
{
    char	*cmdline, *prompt, **arglist;
    int	result, process(char **);
    void	setup();

    FILE 	*fp;
    prompt = DFL_PROMPT ;
    setup();

    int ii = 1;   //test

    if(ac == 2)
    {
        if(strcmp(av[1],"-v")==0)
        {
            Vopendebug();
        }
        else if((fp = fopen(av[1],"r"))!=NULL)
        {
            while ( (cmdline = next_cmd(prompt, fp)) != NULL ) {
                if ( (arglist = splitline(cmdline)) != NULL  ) {
                    if(arglist[0]==NULL)
                    {
                        fclose(fp);
                        return 0;
                    }
                    //printf("      %d: %s\n",ii++,arglist[0]);
                    result = process(arglist);
                    printf("\n");
                    freelist(arglist);
                    fflush(fp);
                }
                free(cmdline);
            }
            fclose(fp);
            return 0;
        }
        else
        {
            perror("open file");
            exit(1);
        }
    }

    while ( (cmdline = next_cmd(prompt, stdin)) != NULL ) {
        if ( (arglist = splitline(cmdline)) != NULL  ) {
            result = process(arglist);
            freelist(arglist);
        }
        free(cmdline);
    }
    return 0;
}
Exemple #3
0
QMutexPrivate *QMutexPrivate::allocate()
{
    int i = freelist()->next();
    QMutexPrivate *d = &(*freelist())[i];
    d->id = i;
    Q_ASSERT(d->refCount.load() == 0);
    Q_ASSERT(!d->recursive);
    Q_ASSERT(!d->possiblyUnlocked.load());
    Q_ASSERT(d->waiters.load() == 0);
    d->refCount.store(1);
    return d;
}
Exemple #4
0
static int region_subrect(lua_State *L)
{
	struct Region *region = luaL_checkudata(L, 1, TEK_CLASS_UI_REGION_NAME);
	TAPTR exec = region->rg_ExecBase;
	struct TNode *next, *node;
	TBOOL success;
	struct TList r1;
	TINT s[4];

	s[0] = luaL_checkinteger(L, 2);
	s[1] = luaL_checkinteger(L, 3);
	s[2] = luaL_checkinteger(L, 4);
	s[3] = luaL_checkinteger(L, 5);

	TINITLIST(&r1);

	success = TTRUE;
	node = region->rg_List.tlh_Head;
	for (; success && (next = node->tln_Succ); node = next)
	{
		struct TNode *next2, *node2;
		struct RectNode *rn = (struct RectNode *) node;
		struct TList temp;

		TINITLIST(&temp);
		success = cutrect(exec, &temp, rn->rn_Rect, s);

		node2 = temp.tlh_Head;
		for (; success && (next2 = node2->tln_Succ); node2 = next2)
		{
			struct RectNode *rn2 = (struct RectNode *) node2;
			success = insertrect(exec, &r1, rn2->rn_Rect[0],
				rn2->rn_Rect[1], rn2->rn_Rect[2], rn2->rn_Rect[3]);
		}

		freelist(exec, &temp);
	}

	if (success)
	{
		freelist(exec, &region->rg_List);
		relinklist(&region->rg_List, &r1);
	}
	else
	{
		freelist(exec, &r1);
		luaL_error(L, "out of memory");
	}

	return 0;
}
Exemple #5
0
void freexlat(struct var *var)
{
   freelist(var->firstreadxlat);
   freelist(var->firstpostxlat);
   freelist(var->firstreadalias);
   freelist(var->firstpostalias);
   freelist(var->firstxlattab);

   var->firstreadxlat=NULL;
   var->firstpostxlat=NULL;
   var->firstreadalias=NULL;
   var->firstpostalias=NULL;
   var->firstxlattab=NULL;
}
void hdestroy_r(struct hsearch_data* htab) {
  size_t i;
  for (i=0; i<htab->size; ++i) {
    freelist(htab->table[i]);
    htab->table[i]=0;
  }
}
Exemple #7
0
Fichier : main.c Projet : Rubusch/c
/*
  allocate elements for the list
//*/
void alloclist(void* start, void* end)
{
  element_t **first = (element_t**) start;
  element_t **last = (element_t**) end;
  element_t *tmp = NULL;

  unsigned int idx=0;
  for(idx = 0; idx < MAX_LIST_SIZE; ++idx){ 
    if(NULL == (tmp = malloc(sizeof(*tmp)))){
      perror("malloc failed!");
      freelist((void*) first);
      exit(EXIT_FAILURE);
    }
    ++global_list_size;

    // limit to values up to 100
    tmp->data = random() % 100; // XXX
    if(0 == idx){
      tmp->prev = NULL;
      tmp->next = NULL;
      *first = tmp;
    }else{
      tmp->prev = *last;
      tmp->next = NULL;
      (*last)->next = tmp;
    }
    *last = tmp; // XXX
    tmp = NULL;
  }
  tmp = NULL;
}
Exemple #8
0
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
	DIR* dir;
	struct dirent *entry;
	char buf[p_max_size];
	int length, totallength = 0;
	struct ll_string* files_front = NULL;
	struct ll_string* files_back = NULL;

	dir = opendir(obj->data.s);
	if(dir != NULL) {
		while ((entry = readdir(dir))) {
			if(entry->d_name[0] != '.') {
				snprintf(buf, p_max_size, "%d/%s", strtopid(obj->data.s), entry->d_name);
				length = readlink(buf, buf, p_max_size);
				buf[length] = 0;
				if(inlist(files_front, buf) == 0) {
					files_back = addnode(files_back, buf);
					snprintf(p + totallength, p_max_size - totallength, "%s; " , buf);
					totallength += length + strlen("; ");
				}
				if(files_front == NULL) {
					files_front = files_back;
				}
			}
		}
		closedir(dir);
		freelist(files_front);
		p[totallength - strlen("; ")] = 0;
	} else {
		p[0] = 0;
	}
}
int main( ) {

    int number = 0, choice;
    struct node *pList=NULL;

    // Let the user add values until they enter -1.
    while(number!= -1) {

        // Get the operation.
        printf("Do you want to (1)insert, (2)delete, (3)quit.\n");
        scanf("%d", &choice);

        // Done.
        if (choice >= 3) break;

        // Get the number.
        printf("Enter the value to insert or delete.\n");
        scanf("%d", &number);

        // Execute the operation.
        if (choice == 1)
            pList = insert(pList, number);
        else
            pList = del(pList, number);

        // Look at the list.
        printf("Items in linked list: ");
        print(pList);
        printf("\n");
    }

    // Free this memory.
    freelist(pList);
    return 0;
}
Exemple #10
0
void		delete_chan(t_server *serv, t_channel *chan)
{
  t_list	*current;
  t_list	*previous;

  current = serv->channel;
  previous = current;
  while (current)
    {
      if (((t_channel *)current->data) == chan)
	{
	  if (previous == current)
	    serv->channel = current->next;
	  else
	    previous->next = current->next;
	  printf("Chan [%s] is empty, deleted\n",
		 ((t_channel *)current->data)->name);
	  freelist(((t_channel *)current->data)->client);
	  free(((t_channel *)current->data)->banmask);
	  free(((t_channel *)current->data)->key);
	  free(((t_channel *)current->data)->topic);
	  free(current);
	  break;
	}
      previous = current;
      current = current->next;
    }
}
Exemple #11
0
Fichier : main.c Projet : Rubusch/c
/*
  application's main
//*/
int main()
{
  element_t* first = NULL;
  element_t* last = first;
  global_list_size = 0;

  // alloc
  puts("alloc");
  alloclist((void*) &first, (void*) &last);
  printf("\n");

  // output
  puts("elements - before");
  printlist(first);
  printf("\n");

  puts("sorting");
  sort((void*) &first);
  printf("\n");

  puts("elements - after");
  printlist(first);
  printf("\n");

  // free
  puts("free");
  freelist((void*) &first);
  printf("\n");

  // exit
  puts("READY.");
  exit(EXIT_SUCCESS);
}
Exemple #12
0
static TBOOL orrect(TAPTR exec, struct TList *list, TINT s[4])
{
	struct TList temp;
	TINITLIST(&temp);
	if (cutrectlist(exec, list, &temp, s))
	{
		if (insertrect(exec, &temp, s[0], s[1], s[2], s[3]))
		{
			freelist(exec, list);
			relinklist(list, &temp);
			return TTRUE;
		}
	}
	freelist(exec, &temp);
	return TFALSE;
}
Exemple #13
0
static TBOOL cutrectlist(TAPTR exec, struct TList *inlist,
	struct TList *outlist, const TINT s[4])
{
	TBOOL success = TTRUE;
	struct TNode *next, *node = inlist->tlh_Head;
	for (; success && (next = node->tln_Succ); node = next)
	{
		struct RectNode *rn = (struct RectNode *) node;
		struct TList temp;

		TINITLIST(&temp);

		success = cutrect(exec, &temp, rn->rn_Rect, s);
		if (success)
		{
			struct TNode *next2, *node2 = temp.tlh_Head;
			for (; success && (next2 = node2->tln_Succ); node2 = next2)
			{
				struct RectNode *rn2 = (struct RectNode *) node2;
				success = insertrect(exec, outlist, rn2->rn_Rect[0],
					rn2->rn_Rect[1], rn2->rn_Rect[2], rn2->rn_Rect[3]);
				/* note that if unsuccessful, outlist is unusable as well */
			}
		}

		freelist(exec, &temp);
	}
	return success;
}
void main()
{
	int T[300][300];
	int i,j,m;
	for(i=0;i<30;i++)
	{
		for(j=0;j<30;j++)
		{
			T[i][j]=0;
		}
	}
	
	int x,y;
	x=0;
	y=0;
	T[0][1]=0;
	int x2, y2;
	
	T[0][0]=2;


	x=6;
	y=15;
	T[x][y]=2;

	
	Couleur* Full=NULL;
	Full=Mouv(T,6,15);
	
	
	printf("\n LA SOL pour 6 15 \n");
	afficherCo(Full);	
	freelist(Full);
}
Exemple #15
0
void freelistpnt(void *n) {
    struct listpoint *lp = n;


    freelist(&lp->c, NULL);
    FREE(lp);
}
Exemple #16
0
void freedoor(void *n) {
    struct door *d = n;


    freelist(&d->sdoors, NULL);
    FREE(d);
}
Exemple #17
0
void QMutexPrivate::release()
{
    Q_ASSERT(!recursive);
    Q_ASSERT(refCount.load() == 0);
    Q_ASSERT(!possiblyUnlocked.load());
    Q_ASSERT(waiters.load() == 0);
    freelist()->release(id);
}
Exemple #18
0
void test_typed_alloc(void) {
    char *tmp_gc;

    Managed mem_gc = (Managed) iMalloc(1 Mb, GCD + ASCENDING_SIZE);
    Priv_mem priv_mem_gc = style_to_priv((Memory) mem_gc);

    // Test allocating 10 pointers, 5 ints and 8 chars
    tmp_gc = mem_gc->gc.alloc((Memory) mem_gc, "10*5i8c");
    CU_ASSERT(alloclist(priv_mem_gc) != NULL);
    CU_ASSERT(alloclist(priv_mem_gc)->size == 10 * sizeof(void*) + 5 * sizeof(int) + 8 * sizeof(char));
    CU_ASSERT(freelist(priv_mem_gc) != NULL);
    CU_ASSERT(freelist(priv_mem_gc)->size == (1 Mb - (10 * sizeof(void*) + 5 * sizeof(int) + 8 * sizeof(char))));

    free_lists(priv_mem_gc->lists);
    free(priv_mem_gc->as->start);
    free(priv_mem_gc);
}
Exemple #19
0
void freelist(struct ll_string* front) {
	if(front != NULL) {
		free(front->string);
		if(front->next != NULL) {
			freelist(front->next);
		}
		free(front);
	}
}
Exemple #20
0
void test_freelist(void) {
    Manual mem = (Manual) priv_imalloc(1 Mb, MANUAL + ASCENDING_SIZE);
    Priv_mem new_mem = style_to_priv((Memory) mem);
    CU_ASSERT(freelist(new_mem) == new_mem->lists->freelist);

    free_lists(new_mem->lists);
    free(new_mem->as->start);
    free(new_mem);
}
Exemple #21
0
int main(){
	struct list ll;
	struct list* l = &ll;
	newlist(l);
	list_add(l,200);
	printf("%lf\n",l->head->next->score);
	freelist(l);
	return 0;
}
Exemple #22
0
int main()
{
	int  ch, val,pos;
	printf("\nEnter to the world of Link List:");
	getch();
	while(1)
	{
		system("cls");
		printf("\n0 >Eixt\n1 >AddFirst \n2 >Insert \n3 >AddLast \n4 >DeleteFirst \n5 >DeleteNode \n6 >DeleteLast\n7 >Display \n9 >Print Reversly \n10 >Freelist \n");
		scanf("%d", &ch);
		switch(ch)
		{
			case 0:
					exit(0);
			case 1:
					printf("\nEnter the number : ");
					scanf("%d", &val);
					addfirst(val);
					break;
			case 2:
					printf("\nEnter the number and position :");
					scanf("%d%d", &val,&pos);
					insert(val,pos);
					break;
			case 3:
					printf("\nEnter the number : ");
					scanf("%d", &val);
					addlast(val);
					break;
			case 4:
					delfirst();
					break;
			case 5:
					printf("\nEnter the position :");
					scanf("%d",&pos);
					deletenode(pos);
					break;
			case 6:
					dellast();
					break;
			case 7:
					display();
					break;
			case 9:
					printrev(head);
					break;
			case 10:
					freelist();
					break;
			default :
					printf("\nEnter the correct choice ");
		}
		getch();
	}
	return 0;
}
void main()
{
	int T[30][150];
	int i,j,m;
	for(i=0;i<30;i++)
	{
		for(j=0;j<30;j++)
		{
			T[i][j]=0;
		}
	}
	
	
	for(i=0;i<29;i++)
	{
		T[i][6]=1;
	}
	int x,y;
	x=0;
	y=0;
	T[0][1]=2;
	int x2, y2;
	
	
	x=28;
	y=28;
	T[x][y]=2;
	
	
	
	x=15;
	y=22;
	T[x][y]=2;


	x=6;
	y=15;
	T[x][y]=2;
	
	x=7;
	y=15;
	T[x][y]=1;

	Couleur* Full=NULL;
	Full=NULL;
	Full=Mouv(T,6,15); 
	printf("\n LA SOL pour 6 15 \n");
	afficherCo(Full);
	printf("Pouet de fin !\n");	
	if( T[Full->x][Full->y] != 0)
	{
		printf("\n SUCH A FAIL %d\n", T[Full->x][Full->y]);
	}
	freelist(Full);

}
void	delete_client(t_server *serv, int fd)
{
  close(fd);
  free(serv->client[fd].realname);
  free(serv->client[fd].username);
  freelist(serv->client[fd].channel);
  printf("Client deleted: %s, socket %d closed\n", serv->client[fd].nick, fd);
  init_client(serv, fd);
  serv->fd_type[fd] = FD_FREE;
}
Exemple #25
0
void
poplist(void)
{
	list *p = runq->argv;
	if(p==0)
		panic("poplist but no argv", 0);
	freelist(p->words);
	runq->argv = p->next;
	efree((char *)p);
}
Exemple #26
0
/** remove the faction from memory.
 * this frees all memory that's only accessible through the faction,
 * but you should still call funhash and remove the faction from the
 * global list.
 */
static void free_faction(faction * f)
{
    funhash(f);
    if (f->msgs) {
        free_messagelist(f->msgs->begin);
        free(f->msgs);
    }
    while (f->battles) {
        struct bmsg *bm = f->battles;
        f->battles = bm->next;
        if (bm->msgs) {
            free_messagelist(bm->msgs->begin);
            free(bm->msgs);
        }
        free(bm);
    }

    if (f->spellbook) {
        free_spellbook(f->spellbook);
    }

    while (f->groups) {
        group *g = f->groups;
        f->groups = g->next;
        free_group(g);
    }
    freelist(f->allies);

    free(f->email);
    free(f->name);
    if (f->seen_factions) {
        selist_free(f->seen_factions);
        f->seen_factions = 0;
    }

    while (f->attribs) {
        a_remove(&f->attribs, f->attribs);
    }

    i_freeall(&f->items);

    freelist(f->origin);
}
Exemple #27
0
/*FUNCTION*/
LVAL c_freelist(tpLspObject pLSP,
              LVAL p
  ){
/*noverbatim
CUT*/
   if( null(p) || freep(p) )return NIL;
   if(consp(p) )
   {
      settype(p,NTYPE_FRE);
      freelist(car(p));
      freelist(cdr(p));
   }
   if( stringp(p) )
      FREE(getstring(p));
   else if( symbolp(p) )
      FREE(getsymbol(p));
   FREE(p);
   return NIL;
}
Exemple #28
0
/*FUNCTION*/
LVAL c_skipexpr(tpLspObject pLSP,
                FILE *f
  ){
/*noverbatim
CUT*/
  LVAL p;

  p = readexpr(f);
  freelist(p);
  return NIL;
  }
Exemple #29
0
int do_control_command(char** args)
{
  int rv;

  if (strcmp(args[0], "if") == 0)
  {
    if (if_state != NEUTRAL)
      err_ret("if error", "");

    last_result = process(args + 1);
    if_result = ((last_result == 0) ? SUCCESS : FAIL);
    if_state = WANT_THEN;
    rv = 0;
    printf("in do_control_command if, last_result = %d, if_result = %d, if_state = %d, arg + 1 = %s\n", last_result, if_result, if_state, *(args + 1));
  }
  else if (strcmp(args[0], "then") == 0)
  {
    if (if_state != WANT_THEN)
      err_ret("then error", "");

    if_state = THEN_BLOCK;
    rv = 0;
  }
  else if (strcmp(args[0], "else") == 0)
  {
    if (if_state != THEN_BLOCK)
      err_ret("else error", "");

    if_state = ELSE_BLOCK;
    rv = 0;
  }
  else if (strcmp(args[0], "fi") == 0)
  {
    if ((if_state != THEN_BLOCK) && (if_state != ELSE_BLOCK))
      err_ret("fi error", "");

    exec_cmd_ptr = exec_cmds;
    while(exec_number != 0)
    {
      if (!builtin_command(*exec_cmd_ptr))
        execute(*exec_cmd_ptr);

      freelist(*exec_cmd_ptr);

      ++exec_cmd_ptr;
      --exec_number;
    }

    if_state = NEUTRAL;
  }

  return rv;
}
// Frees each node in the LL pointed to by list.
void freelist(struct node* list) {

    // We can stop.
    if (list == NULL) return;

    // Free the rest of the list.
    if (list->next != NULL)
        freelist(list->next);

    // Free first node.
    free(list);
}