예제 #1
0
void make_entry()
{
static int i=0, b[9]={0}, x=0;
int k=0, flag =0;

	scanf("%d", &a[i]);

	/****************************** checking for valid entry from 1 to 9 *****************************/

	//if(a[i]==1 || a[i]==2 || a[i]==3 || a[i]==4 || a[i]==5 || a[i]==6 || a[i]==7 || a[i]==8 || a[i]==9) 
	if(a[i] > 0 && a[i] < 10)
	{
	x= a[i];
	printf("Move number: %d\n", count);
if((count%2) == 0)
	z[x-1] = 1;

if((count%2) == 1)
	z[x-1] = -1;



	for(k=0;k<9;k++)
	{
		 if((a[i])==(b[k]) && flag ==0)
		 {
		 	printf("That block is already filled. Enter again: ");
			flag = 1;
			break;	
		}
	}

	if(flag==1 && count!=9)
	{
		
		make_entry();

	}

	if(flag==0 && count!=9)
	{

	b[i]= a[i];
	i++;
}
}

else
{
	printf("\n\nEnter numbers only from 1 to 9!!!\n");
	make_entry();
}


}
예제 #2
0
data_t *_dalloc(const size_t size, const char *file, const int line) {
	data_t *memory;
	size_t newsize = mem_allocated + size;
	alloclist_t *newentry;

	if(newsize > mem_lim_hard) {
		if(thread_running)
			for(;;);
		return NULL;
	} else if(!warned && (newsize > mem_lim_soft)) {
		if(mem_verbosity == MEM_VERBOSE)
			fprintf(stderr, "-- WARNING: Soft memory limit reached.\n");
		warned = 1;
	} else if(warned && (newsize < mem_lim_soft))
		warned = 0;

	memory = (data_t*)malloc(size);

	if(memory) {
		if((newentry = make_entry(memory, file, line, size))) {
			addtolist(newentry);

			mem_allocated += size;
			if(mem_allocated > n_bytes_peak)
				n_bytes_peak = mem_allocated;

			n_allocs++;
		} else {
			fprintf(stderr, "ERROR: malloc() failed for new memory list entry.\n");
			free(memory);
			return NULL;
		}
	}
	return memory;
}
예제 #3
0
파일: mem.c 프로젝트: peterwankman/libisp
lisp_data_t *lisp_dalloc(const size_t size, const char *file, const int line, lisp_ctx_t *context) {
	lisp_data_t *memory;
	size_t newsize = context->mem_allocated + size;
	alloclist_t *newentry;

	if(newsize > context->mem_lim_hard) {
		if(context->thread_running)
			for(;;);
		return NULL;
	} else if(!(context->warned) && (newsize > context->mem_lim_soft)) {
		if(context->mem_verbosity == LISP_GC_VERBOSE)
			fprintf(stderr, "-- WARNING: Soft memory limit reached.\n");
		context->warned = 1;
	} else if((context->warned) && (newsize < context->mem_lim_soft))
		context->warned = 0;

	memory = malloc(size);

	if(memory) {
		if((newentry = make_entry(memory, file, line, size))) {
			addtolist(newentry, context);

			context->mem_allocated += size;
			if(context->mem_allocated > context->n_bytes_peak)
				context->n_bytes_peak = context->mem_allocated;

			context->n_allocs++;
		} else {
			fprintf(stderr, "ERROR: malloc() failed for new memory list entry.\n");
			free(memory);
			return NULL;
		}
	}
	return memory;
}
예제 #4
0
/* Wrapper around make_entry to check that filename exists and entry
   is in correct form. */
struct entry *read_entry(char *filename) {
  struct stat buf;

  if (!is_entry(filename) || kukka_stat(filename, &buf) < 0) {
    return NULL;
  }
  return make_entry(&buf, filename);
}
예제 #5
0
/* add new name into a directory. If it exists in a directory - do
   nothing */
int reiserfs_add_entry (reiserfs_filsys_t fs, struct key * dir, char * name,
			 struct key * key, int fsck_need)
{
    struct item_head entry_ih = {{0,}, };
    char * entry;
    int retval;
    INITIALIZE_PATH(path);
    int gen_counter;
    int item_len;
    __u32 hash;

    if (reiserfs_find_entry (fs, dir, name, &gen_counter))
	return 0;

    /* compose entry key to look for its place in the tree */
    entry_ih.ih_key.k_dir_id = cpu_to_le32 (dir->k_dir_id);
    entry_ih.ih_key.k_objectid = cpu_to_le32 (dir->k_objectid);
    hash = hash_value (fs, name) + gen_counter;
    if (!strcmp (name, "."))
	hash = DOT_OFFSET;
    if (!strcmp (name, ".."))
	hash = DOT_DOT_OFFSET;
    set_type_and_offset (KEY_FORMAT_1, &(entry_ih.ih_key),
			 hash, TYPE_DIRENTRY);
    set_ih_key_format (&entry_ih, KEY_FORMAT_1);
    set_entry_count (&entry_ih, 1);
    if (SB_VERSION (fs) == REISERFS_VERSION_2)
	item_len = DEH_SIZE + ROUND_UP (strlen (name));
    else
	item_len = DEH_SIZE + strlen (name);
    set_ih_item_len (&entry_ih, item_len);

    /* fsck may need to insert item which was not reached yet */
    set_ih_fsck_need( &entry_ih, fsck_need );

    entry = make_entry (0, name, key, get_offset (&(entry_ih.ih_key)));

    retval = _search_by_entry_key (fs, &(entry_ih.ih_key), &path);
    switch (retval) {
    case POSITION_NOT_FOUND:
	reiserfs_paste_into_item (fs, &path, entry, item_len);
	break;

    case DIRECTORY_NOT_FOUND:
        set_deh_location( (struct reiserfs_de_head *)entry, DEH_SIZE );
	reiserfs_insert_item (fs, &path, &entry_ih, entry);
	break;

    default:
	reiserfs_panic ("reiserfs_add_entry: looking for %k (inserting name \"%s\") "
			"search_by_entry_key returned %d",
			&(entry_ih.ih_key), name, retval);
    }

    freemem (entry);
    return item_len;
}
예제 #6
0
파일: dag.c 프로젝트: geofft/subversion
svn_error_t *
svn_fs_x__dag_make_dir(dag_node_t **child_p,
                       dag_node_t *parent,
                       const char *parent_path,
                       const char *name,
                       const svn_fs_x__id_part_t *txn_id,
                       apr_pool_t *pool)
{
  /* Call our little helper function */
  return make_entry(child_p, parent, parent_path, name, TRUE, txn_id, pool);
}
예제 #7
0
// short test function to 
HEMI_KERNEL(testCuckooInsert)(unsigned key, unsigned item, CuckooTable hf)
{
  bool test;
  unsigned long long testEntry;
  unsigned long long origEntry = make_entry(key, item);
  test = hf.insert_hash(key, item);
  testEntry = hf.retrieve_hash(key, item);
  //printf("Insert of (%d, %d): %s\n", key, item, (test == true ? "Success" : "Failure"));
  //printf("Hash value retrieved: %lx - (%x, %x) -- %lx\n", testEntry, get_key(testEntry), get_value(testEntry), origEntry);
  assert(testEntry == origEntry);
}
예제 #8
0
파일: dbintlog.cpp 프로젝트: CapelliC/IL
///////////////////////////////////
// get a local procedure reference
//
DbEntry *DbIntlog::GetEntryRef(Term t)
{
    DbEntry *e = make_entry(t.get_funct(), t.get_arity());

#ifdef _DEBUG
    CCP tstring = t.get_funct();
#endif

    check_inherited_entries(e);
    return e;
}
예제 #9
0
LOCAL_CACHE_TEMPLATE
typename LOCAL_CACHE_CLASS::result
LOCAL_CACHE_CLASS::put_if_absent(const KeyT &key, const ValueT &val, ValueT &curtVal) {
    if (capacity < 1) {
        return MISS;
    }
    result res = MISS;
    // lock
    tbsys::CThreadGuard guard(&mutex);

    entry_cache_iterator iter = cache.find(&key);
    internal_entry *entry = NULL;
    if (iter == cache.end()) {
        res = MISS;
        // not found
        // evict entry
        while (cache.size() >= capacity) {
            assert(capacity >= 1);
            const internal_entry *evict = evict_one();
            assert(evict != NULL);
            // free entry
            drop_entry(evict);
        }

        // insert new one
        // allocate internal_entry, relase after evict or in clear()
        entry = make_entry(key, val);
        if (entry == NULL) {
            return SETERROR;
        }
        lru.push_front(entry);
        cache[entry->get_key()] = lru.begin();
        curtVal = val;
    } else {
        res = HIT;
        // found, already exists
        // adjust lru list
        lru.splice(lru.begin(), lru, iter->second);
        // update entry value and utime
        // update first, some meta info
        fill_value(iter, curtVal);
        uint64_t now = tbutil::Time::now().toMilliSeconds();
        assert(expire != 0);
        if (now - entry_utime(iter) > expire) {
            // expired
            set_entry_utime(iter->second, now);
            res = EXPIRED;
        }
    }
    return res;
}
예제 #10
0
void VGA_Text_Buffer::put(char c) {
  if (c == '\n') {
    col = -1; // The column get incremented at the end, need to counteract that
    ++row;
  } else if (c == '\t') {
    col = col - (col % tab_width) + tab_width - 1;
  } else {
    at(row,col) = make_entry(c);
  }
  if (++col >= cols) {
    ++row;
    col = 0;
  }
  if (row >= rows) scroll();
}
예제 #11
0
파일: dbintlog.cpp 프로젝트: CapelliC/IL
//////////////////////////////////////////////////////
// make an entry, changing her properties as required
//
int DbIntlog::ChangeEntryProperty(kstring sym, int arity, DbEntry::scopemode prop)
{
    DbEntry *e = make_entry(sym, arity);
    if (e)
    {
        check_inherited_entries(e);
        if (e->vProp == DbEntry::local)
        {
            e->vProp = prop;
            if (prop == DbEntry::dynamic)
                e->addVTbl(0);
            return 1;
        }
    }
    return 0;
}
예제 #12
0
LOCAL_CACHE_TEMPLATE
void LOCAL_CACHE_CLASS::put(const KeyT& key, const ValueT& val) 
{
  if (capacity < 1) {
      return ;
  }
  // lock 
  tbsys::CThreadGuard guard(&mutex);

  entry_cache_iterator iter = cache.find(&key);
  internal_entry *entry = NULL;
  if (iter == cache.end()) {
    // not found
    // evict entry
    while (cache.size() >= capacity) {
      assert(capacity >= 1);
      const internal_entry *evict = evict_one();
      assert(evict != NULL);
      // free entry
      drop_entry(evict);
    }

    // insert new one 
    // allocate internal_entry, relase after evict or in clear()
    entry = make_entry(key, val);
    if (entry == NULL) {
      return ;
    }
    lru.push_front(entry);   
  } else {
    // found, already exists
    // adjust lru list
    lru.splice(lru.begin(), lru, iter->second); 
    // update entry value and utime
    // update first, some meta info
    cache.erase(iter);
    entry_list_iterator elem = lru.begin();
    set_entry_key(elem, key);
    set_entry_value(elem, val);
    set_entry_utime_now(elem);
    entry = *elem;
  }
  cache[&(entry->key)] = lru.begin();
}
예제 #13
0
Status BTIndexPage::insertKey (const void *key,
		AttrType key_type,
		PageId pageNo,
		RID& rid)
{
	KeyDataEntry entry;
	int entry_len;

	Datatype d;
	d.pageNo = pageNo;
	make_entry(&entry, key_type, key, (nodetype) type, d, &entry_len);

	if (SortedPage::insertRecord(key_type, (char*)&entry,
				entry_len, rid ) != OK) {
		return MINIBASE_FIRST_ERROR(BTINDEXPAGE, INDEXINSERTRECFAILED);
	}

	return OK;
}
예제 #14
0
파일: dbintlog.cpp 프로젝트: CapelliC/IL
///////////////////////////////
// open an inherited interface
//
int DbIntlog::InheritInterface(DbIntlog *db)
{
    if (db == this)
        return 0;

    m_inherited.append(db);

    // check dynamic data
    hashtable_iter id(db);
    DbEntry *dbe;
    while ((dbe = (DbEntry*)id.next()) != 0)
        if (dbe->vProp == DbEntry::dynamic)
        {
            // make a local copy of data
            DbEntry *dbes = make_entry(dbe->funct, dbe->arity);
            dbes->vProp = DbEntry::dynamic;

            // make base class entries point to copied data
            dbe->addVTbl(0)->add(this, dbes);

            const e_DbList *pEntry = dbe->get_first();
            while (pEntry)
            {
                if (	pEntry->type == e_DbList::tClause ||
                        pEntry->type == e_DbList::tShared)
                {
                    // a copy (but avoid deleted clause)
                    e_DbList *pNew = new e_DbList(pEntry->clause);
                    pNew->type = e_DbList::tShared;

                    // tail to copied entries
                    dbes->entries.append(pNew);
                }

                pEntry = pEntry->next();
            }
        }

    return 1;
}
예제 #15
0
// Shift the text several lines up the screen
void VGA_Text_Buffer::scroll(size_t lines, vga_color fill) {
  for (size_t row = 0; row + lines < rows; ++row) {
    for (size_t col = 0; col < cols; ++ col) {
      at(row,col) = at(row+lines,col);
    }
  }

  // Save the color
  vga_color bg = get_bg();
  vga_color fg = get_fg();
  // Make the foreground and background the same color
  set_color(fill,fill);
  for (size_t row = rows > lines ? rows - lines : 0;
       row < rows;
       ++row) {
    for (size_t col = 0; col < cols; ++col) {
      at(row,col) = make_entry(' ');
    }
  }
  // Restore the color
  set_color(fg,bg);
  row = row >= lines ? row - lines : 0;
}
예제 #16
0
void
edit_process_rep::generate_index (string idx) {
  system_wait ("Generating index, ", "please wait");
  if (DEBUG_AUTO)
    debug_automatic << "Generating index [" << idx << "]\n";
  tree I= copy (buf->data->aux[idx]);
  if (buf->prj != NULL) I= copy (buf->prj->data->aux[idx]);
  if (N(I)>0) {
    followup= hashmap<string,tree> (TUPLE);
    int i, n= N(I);
    array<string> entry (n);
    for (i=0; i<n; i++)
      entry[i]= index_name (I[i]);
    merge_sort (entry);

    hashmap<string,tree> h (TUPLE);
    for (i=0; i<n; i++) {
      string name = index_name  (I[i]);
      tree   value= index_value (I[i]);
      if (!h->contains (name)) h (name)= tuple (value);
      else h (name) << value;
    }

    array<string> new_entry;
    for (i=0; i<n; i++) {
      if ((i>0) && (entry[i] == entry[i-1])) continue;
      insert_recursively (new_entry, entry[i], h);
    }
    entry= new_entry;
    n= N(entry);

    tree D (DOCUMENT);
    for (i=0; i<n; i++)
      make_entry (D, h (entry[i]));
    insert_tree (remove_labels (D));
  }
}
예제 #17
0
static int app_exec(struct ast_channel *chan, void *data)
{
	struct ast_module_user *lu;
	struct playlist_entry *entry;
	const char *args = data;
	int child_stdin[2] = { 0,0 };
	int child_stdout[2] = { 0,0 };
	int child_stderr[2] = { 0,0 };
	int res = -1;
	int test_available_fd = -1;
	int gen_active = 0;
	int pid;
	char *argv[32];
	int argc = 1;
	char *buf, *command;
	FILE *child_commands = NULL;
	FILE *child_errors = NULL;
	FILE *child_events = NULL;
	struct ivr_localuser foo = {
		.playlist = AST_LIST_HEAD_INIT_VALUE,
		.finishlist = AST_LIST_HEAD_INIT_VALUE,
	};
	struct ivr_localuser *u = &foo;
	sigset_t fullset, oldset;

	lu = ast_module_user_add(chan);

	sigfillset(&fullset);
	pthread_sigmask(SIG_BLOCK, &fullset, &oldset);

	u->abort_current_sound = 0;
	u->chan = chan;
	
	if (ast_strlen_zero(args)) {
		ast_log(LOG_WARNING, "ExternalIVR requires a command to execute\n");
		ast_module_user_remove(lu);
		return -1;	
	}

	buf = ast_strdupa(data);

	argc = ast_app_separate_args(buf, '|', argv, sizeof(argv) / sizeof(argv[0]));

	if (pipe(child_stdin)) {
		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child input: %s\n", strerror(errno));
		goto exit;
	}

	if (pipe(child_stdout)) {
		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child output: %s\n", strerror(errno));
		goto exit;
	}

	if (pipe(child_stderr)) {
		ast_chan_log(LOG_WARNING, chan, "Could not create pipe for child errors: %s\n", strerror(errno));
		goto exit;
	}

	if (chan->_state != AST_STATE_UP) {
		ast_answer(chan);
	}

	if (ast_activate_generator(chan, &gen, u) < 0) {
		ast_chan_log(LOG_WARNING, chan, "Failed to activate generator\n");
		goto exit;
	} else
		gen_active = 1;

	pid = fork();
	if (pid < 0) {
		ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno));
		goto exit;
	}

	if (!pid) {
		/* child process */
		int i;

		signal(SIGPIPE, SIG_DFL);
		pthread_sigmask(SIG_UNBLOCK, &fullset, NULL);

		if (ast_opt_high_priority)
			ast_set_priority(0);

		dup2(child_stdin[0], STDIN_FILENO);
		dup2(child_stdout[1], STDOUT_FILENO);
		dup2(child_stderr[1], STDERR_FILENO);
		for (i = STDERR_FILENO + 1; i < 1024; i++)
			close(i);
		execv(argv[0], argv);
		fprintf(stderr, "Failed to execute '%s': %s\n", argv[0], strerror(errno));
		_exit(1);
	} else {
		/* parent process */
		int child_events_fd = child_stdin[1];
		int child_commands_fd = child_stdout[0];
		int child_errors_fd = child_stderr[0];
		struct ast_frame *f;
		int ms;
		int exception;
		int ready_fd;
		int waitfds[2] = { child_errors_fd, child_commands_fd };
		struct ast_channel *rchan;

		pthread_sigmask(SIG_SETMASK, &oldset, NULL);

		close(child_stdin[0]);
		child_stdin[0] = 0;
		close(child_stdout[1]);
		child_stdout[1] = 0;
		close(child_stderr[1]);
		child_stderr[1] = 0;

		if (!(child_events = fdopen(child_events_fd, "w"))) {
			ast_chan_log(LOG_WARNING, chan, "Could not open stream for child events\n");
			goto exit;
		}

		if (!(child_commands = fdopen(child_commands_fd, "r"))) {
			ast_chan_log(LOG_WARNING, chan, "Could not open stream for child commands\n");
			goto exit;
		}

		if (!(child_errors = fdopen(child_errors_fd, "r"))) {
			ast_chan_log(LOG_WARNING, chan, "Could not open stream for child errors\n");
			goto exit;
		}

		test_available_fd = open("/dev/null", O_RDONLY);

		setvbuf(child_events, NULL, _IONBF, 0);
		setvbuf(child_commands, NULL, _IONBF, 0);
		setvbuf(child_errors, NULL, _IONBF, 0);

		res = 0;

		while (1) {
			if (ast_test_flag(chan, AST_FLAG_ZOMBIE)) {
				ast_chan_log(LOG_NOTICE, chan, "Is a zombie\n");
				res = -1;
				break;
			}

			if (ast_check_hangup(chan)) {
				ast_chan_log(LOG_NOTICE, chan, "Got check_hangup\n");
				send_child_event(child_events, 'H', NULL, chan);
				res = -1;
				break;
			}

			ready_fd = 0;
			ms = 100;
			errno = 0;
			exception = 0;

			rchan = ast_waitfor_nandfds(&chan, 1, waitfds, 2, &exception, &ready_fd, &ms);

			if (!AST_LIST_EMPTY(&u->finishlist)) {
				AST_LIST_LOCK(&u->finishlist);
				while ((entry = AST_LIST_REMOVE_HEAD(&u->finishlist, list))) {
					send_child_event(child_events, 'F', entry->filename, chan);
					free(entry);
				}
				AST_LIST_UNLOCK(&u->finishlist);
			}

			if (rchan) {
				/* the channel has something */
				f = ast_read(chan);
				if (!f) {
					ast_chan_log(LOG_NOTICE, chan, "Returned no frame\n");
					send_child_event(child_events, 'H', NULL, chan);
					res = -1;
					break;
				}

				if (f->frametype == AST_FRAME_DTMF) {
					send_child_event(child_events, f->subclass, NULL, chan);
					if (u->option_autoclear) {
						if (!u->abort_current_sound && !u->playing_silence)
							send_child_event(child_events, 'T', NULL, chan);
						AST_LIST_LOCK(&u->playlist);
						while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) {
							send_child_event(child_events, 'D', entry->filename, chan);
							free(entry);
						}
						if (!u->playing_silence)
							u->abort_current_sound = 1;
						AST_LIST_UNLOCK(&u->playlist);
					}
				} else if ((f->frametype == AST_FRAME_CONTROL) && (f->subclass == AST_CONTROL_HANGUP)) {
					ast_chan_log(LOG_NOTICE, chan, "Got AST_CONTROL_HANGUP\n");
					send_child_event(child_events, 'H', NULL, chan);
					ast_frfree(f);
					res = -1;
					break;
				}
				ast_frfree(f);
			} else if (ready_fd == child_commands_fd) {
				char input[1024];

				if (exception || feof(child_commands)) {
					ast_chan_log(LOG_WARNING, chan, "Child process went away\n");
					res = -1;
					break;
				}

				if (!fgets(input, sizeof(input), child_commands))
					continue;

				command = ast_strip(input);

				ast_chan_log(LOG_DEBUG, chan, "got command '%s'\n", input);

				if (strlen(input) < 4)
					continue;

				if (input[0] == 'S') {
					if (ast_fileexists(&input[2], NULL, u->chan->language) == -1) {
						ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]);
						send_child_event(child_events, 'Z', NULL, chan);
						strcpy(&input[2], "exception");
					}
					if (!u->abort_current_sound && !u->playing_silence)
						send_child_event(child_events, 'T', NULL, chan);
					AST_LIST_LOCK(&u->playlist);
					while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list))) {
						send_child_event(child_events, 'D', entry->filename, chan);
						free(entry);
					}
					if (!u->playing_silence)
						u->abort_current_sound = 1;
					entry = make_entry(&input[2]);
					if (entry)
						AST_LIST_INSERT_TAIL(&u->playlist, entry, list);
					AST_LIST_UNLOCK(&u->playlist);
				} else if (input[0] == 'A') {
					if (ast_fileexists(&input[2], NULL, u->chan->language) == -1) {
						ast_chan_log(LOG_WARNING, chan, "Unknown file requested '%s'\n", &input[2]);
						send_child_event(child_events, 'Z', NULL, chan);
						strcpy(&input[2], "exception");
					}
					entry = make_entry(&input[2]);
					if (entry) {
						AST_LIST_LOCK(&u->playlist);
						AST_LIST_INSERT_TAIL(&u->playlist, entry, list);
						AST_LIST_UNLOCK(&u->playlist);
					}
				} else if (input[0] == 'H') {
					ast_chan_log(LOG_NOTICE, chan, "Hanging up: %s\n", &input[2]);
					send_child_event(child_events, 'H', NULL, chan);
					break;
				} else if (input[0] == 'O') {
					if (!strcasecmp(&input[2], "autoclear"))
						u->option_autoclear = 1;
					else if (!strcasecmp(&input[2], "noautoclear"))
						u->option_autoclear = 0;
					else
						ast_chan_log(LOG_WARNING, chan, "Unknown option requested '%s'\n", &input[2]);
				}
			} else if (ready_fd == child_errors_fd) {
				char input[1024];

				if (exception || (dup2(child_commands_fd, test_available_fd) == -1) || feof(child_errors)) {
					ast_chan_log(LOG_WARNING, chan, "Child process went away\n");
					res = -1;
					break;
				}

				if (fgets(input, sizeof(input), child_errors)) {
					command = ast_strip(input);
					ast_chan_log(LOG_NOTICE, chan, "stderr: %s\n", command);
				}
			} else if ((ready_fd < 0) && ms) { 
				if (errno == 0 || errno == EINTR)
					continue;

				ast_chan_log(LOG_WARNING, chan, "Wait failed (%s)\n", strerror(errno));
				break;
			}
		}
	}

 exit:
	if (gen_active)
		ast_deactivate_generator(chan);

	if (child_events)
		fclose(child_events);

	if (child_commands)
		fclose(child_commands);

	if (child_errors)
		fclose(child_errors);

	if (test_available_fd > -1) {
		close(test_available_fd);
	}

	if (child_stdin[0])
		close(child_stdin[0]);

	if (child_stdin[1])
		close(child_stdin[1]);

	if (child_stdout[0])
		close(child_stdout[0]);

	if (child_stdout[1])
		close(child_stdout[1]);

	if (child_stderr[0])
		close(child_stderr[0]);

	if (child_stderr[1])
		close(child_stderr[1]);

	while ((entry = AST_LIST_REMOVE_HEAD(&u->playlist, list)))
		free(entry);

	ast_module_user_remove(lu);

	return res;
}
예제 #18
0
파일: session.c 프로젝트: caidongyun/fbbs
void session_set_web_cache(user_id_t user_id, const char *session_key,
		session_id_t session_id, const char *ip_addr)
{
	make_entry(user_id, session_key, ip_addr);
	mdb_cmd("HSET", SESSION_WEB_HASH_KEY" %s %"PRIdSID, entry, session_id);
}
예제 #19
0
void main()
{
	int  i=0, j=0, winner=2; 
	char isContinue = '0' ;

	while(1)
	{
		count = 0;
		for(i=0;i<9;i++){
			z[i]= 0 ;
			a[i]= 0 ; 
		}
	printf("\n\n\tWelcome to the game of Tic-Tac-Toe\n");
	printf("\tPlease enter numbers only from 1 to 9\n\n");
	printf("\n\tThe Blocks are numbered as below, for reference");
	printf("\n\t\t   |   |  \n\t\t 1 | 2 | 3 \n\t\t___|___|___  \n\t\t 4 | 5 | 6 \n\t\t___|___|___  \n\t\t 7 | 8 | 9 \n\t\t   |   |  \n\n");
	while(count<9)
	{
		if((count%2) == 0)
		{
		printf("   Player 1 make your move:\t");
		make_entry();

		winner = check_for_win();
		
		}

		if((count%2)==1)
		{
		 	printf("   Player 2 make your move:\t");
		 	make_entry();
		 winner = check_for_win();
		}
		count++;

		if(winner == 1) // if winner is Player1
		{
			printf("\n Player 1 wins!!! Congratulations\n");

		/*
			for(j=0;j<9;j++)
			printf("%d\t", z[j]);  */
			break;
		}

		if(winner == -1) // if winner is Player2
		{
			printf("\n Player 2 wins!!! Congratulations\n");

		/*
			for(j=0;j<9;j++)
			printf("%d\t", z[j]); */
			break;
		}

		if(winner == 3) // Draw :(
		{
			printf("\n Match Drawn\n");

		/*	for(j=0;j<9;j++)
			printf("%d\t", z[j]); */
			break;
		}
		DisplayBoard();
	}
	printf("Do you wish to continue[y/n]\n" );
	scanf("%c",&isContinue);
	if(isContinue == 'n'){
		printf("Exiting the game\nThanks for playing see you soon!!!!\n");
		break;
	}
}



}
예제 #20
0
void TextModeVGA_putentry(char c, VGA_color foreground,  VGA_color background, size_t x, size_t y) { 
	TextModeVGA_Buffer[(((TextModeVGA_Width) * y) + x)] = make_entry(c, generate_color(foreground, background)); 
}; 	
예제 #21
0
파일: myre.c 프로젝트: vobiscum/myre
/*------------------------------main-----------------------------------*/
int main(int argc, char const *argv[])
{
    debug("main");
    /*command line args*/
    if(argc > 1) {
        if(!strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
            printf("%s\n", HELPMSG);
            return 0;
        }
        if(!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version")) {
            printf("%s\n", VERSION);
            return 0;
        }
        printf("Unknown args [%s], continue to GUI...\n", argv[1]);
    }

    /*gtk start*/
    gtk_init(NULL, NULL);
    debug("gtk init");

    /*init char*/
    mark = malloc(2);
    word = malloc(MAX_LENGTH);

    /* init curl */
    curl_global_init(CURL_GLOBAL_ALL);
    debug("curl init");

    /*window*/
    window = (GtkWidget *)gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_decorated(GTK_WINDOW(window), FALSE);
    gtk_window_set_icon_name(GTK_WINDOW(window),"accessories-dictionary");
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
    gtk_window_set_gravity(GTK_WINDOW(window), GDK_GRAVITY_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    g_signal_connect(window, "key_press_event", G_CALLBACK(checkEsc), NULL);
    debug("window");

    /* entry */
    make_entry();

    /*button*/
    make_button1();

    /*assemble*/
    vbox1 = gtk_vbox_new(FALSE, 2); /*h**o, pad*/
    hbox1 = gtk_hbox_new(FALSE, 2);
    hboxmain = gtk_hbox_new(FALSE, 5);
    gtk_widget_set_no_show_all(hboxmain, TRUE);

    gtk_container_add((GtkContainer *)window, vbox1);
    gtk_container_add((GtkContainer *)vbox1, hbox1);
    gtk_container_add((GtkContainer *)vbox1, hboxmain);
    gtk_container_add((GtkContainer *)hbox1, entry);
    gtk_container_add((GtkContainer *)hbox1, button1);

    gtk_box_set_child_packing(GTK_BOX(hbox1), GTK_WIDGET(entry),
                              1,/*expand*/
                              1,/*fill*/
                              2,/*pad*/
                              GTK_PACK_START/*pack type*/
                             );

    gtk_box_set_child_packing(GTK_BOX(vbox1), hbox1,
                              0, 0, 1, GTK_PACK_START);

    gtk_box_set_child_packing(GTK_BOX(hbox1), button1,
                              0, 0, 1, GTK_PACK_START);
    debug("assemble initial view");


    gtk_widget_show_all(window);
    debug("start the show");

#ifdef MinGW
    /*volatino*/
    volatino = (GtkWidget *) gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_decorated(GTK_WINDOW(volatino), FALSE);
    gtk_widget_set_size_request(volatino, 450, 24);
    gtk_window_set_icon_name(GTK_WINDOW(volatino),"accessories-dictionary");
    gtk_window_set_position(GTK_WINDOW(volatino), GTK_WIN_POS_CENTER_ALWAYS);
    gtk_window_set_gravity(GTK_WINDOW(volatino), GDK_GRAVITY_CENTER);
    gtk_widget_show(volatino);
    gtk_widget_destroy(volatino);

#endif

    /*auto-completion*/
    store = gtk_list_store_new(1, G_TYPE_STRING);
    model = GTK_TREE_MODEL(store);

    /*completion model*/
    completion = gtk_entry_completion_new();
    gtk_entry_completion_set_model(completion, model);
    gtk_entry_completion_set_text_column(completion, 0);
    /*completion style*/
    gtk_entry_completion_set_inline_completion(completion, TRUE);
    gtk_entry_completion_set_inline_selection(completion, TRUE);

    /*commands*/
    append_list(store, ":about");
    append_list(store, ":help");

    /*connect completion*/
    gtk_entry_set_completion(GTK_ENTRY(entry), completion);

    debug("completion");
    debug("gtk main entering");
    gtk_main();

    /*gtk end*/
    debug("Sure.");

    /*clean up*/
    if(curl_handle)
        curl_easy_cleanup(curl_handle);
    curl_global_cleanup();

    free(s);
    free(rslt);
    free(mark);
    free(word);
    if(searchStr)
        free(searchStr);
    return 0;
}
예제 #22
0
Status BTreeFile::_insert (const void *key, const RID rid,
		KeyDataEntry **goingUp, int *goingUpSize, PageId currentPageId)

{
	Status st;
	SortedPage* rpPtr;

	assert(currentPageId != INVALID_PAGE);
	assert(*goingUp != NULL);

	st = MINIBASE_BM->pinPage(currentPageId,(Page *&) rpPtr);
	if (st != OK)
		return MINIBASE_FIRST_ERROR(BTREE, CANT_PIN_PAGE);


	NodeType pageType = rpPtr->get_type();
	
	cerr<< "currentPageId IN _INSERT "<< currentPageId<<" pageType "<< pageType<<endl;
	// TWO CASES:
	// - pageType == INDEX:
	//   recurse and then split if necessary
	// - pageType == LEAF:
	//   try to insert pair (key, rid), maybe split

	switch (pageType)
	{
		case INDEX:
		{
			// two cases:
			// - *goingUp == NULL: one level lower no split has occurred:
			//                     we are done.
			// - *goingUp != NULL: one of the children has split and
			//                     **goingUp is the new data entry which has
			//                    to be inserted on this index page

			
			// TODO: fill the body
			BTIndexPage* indexPage = (BTIndexPage*) rpPtr;
			RID myRid;
			KeyDataEntry* newEntry = new KeyDataEntry();
			int newEntrySize;
			PageId pageId;
			indexPage->get_page_no( key, headerPage->key_type, pageId);
			
			printf("in index page insert to %d\n", pageId);
			fflush(stdout);
			Status returnStatus = _insert(key, rid, &newEntry , &newEntrySize, pageId);
			
			if (returnStatus != OK)
				MINIBASE_FIRST_ERROR(BTREE, INSERT_FAILED);
			
			if( newEntry != NULL){
				if( indexPage->available_space() >= newEntrySize){
					st = indexPage->insertKey( (void*)(&newEntry->key), headerPage->key_type, newEntry->data.pageNo, myRid);
					if(st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
				}
				else{
					//pageFUll:
					//new a Indexpage "RightSibling"
					cout<<"*************************index_split"<<endl;
					BTIndexPage* rightSiblingIndexPage;
					
					PageId rightPageId;
					Status st;
					st = MINIBASE_BM->newPage( rightPageId, (Page*&)rightSiblingIndexPage );
					rightSiblingIndexPage->init( rightPageId);
					if( st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
					assert( st == OK);
					//chose a mediate_key to push up
					int numLeft = (indexPage->numberOfRecords()+1)/2;
					int numRight = indexPage->numberOfRecords()+1-numLeft;
					RID metaRid;
					Keytype iterKey;
					PageId iterPage;
					st = indexPage->get_first( metaRid, &iterKey, iterPage);
					if( st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
					assert( st == OK);
					RID dummyRid;
					RID leftLastRid;
					Keytype medKey;
					PageId medPage;
					bool entryInserted = false;
					for( int i = 0 ; i < numLeft-1 ; i++){
						st = indexPage->get_next( metaRid, &iterKey, iterPage);
					}
					if(  !entryInserted && keyCompare( &(newEntry->key), &iterKey, headerPage->key_type) <=0){
						//newEntry is in the left half
						st = indexPage->insertKey( (void*)(&newEntry->key), headerPage->key_type, newEntry->data.pageNo, dummyRid );
						if( st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
						medKey = iterKey;
						medPage = iterPage;
						st = indexPage->deleteKey( &iterKey, headerPage->key_type, dummyRid);
						if( st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
						st = indexPage->get_next( metaRid, &iterKey, iterPage);
						entryInserted = true;
					}
					else{
						// this is the middle key
						st = indexPage->get_next( metaRid, &iterKey, iterPage);
						if(  !entryInserted && keyCompare( &(newEntry->key), &iterKey, headerPage->key_type) <=0){
							medKey = newEntry->key;
							medPage = newEntry->data.pageNo;
						}
						else{
							medKey = iterKey;
							medPage = iterPage;
							rightSiblingIndexPage->insertKey( (void*)&(newEntry->key), headerPage->key_type, newEntry->data.pageNo, dummyRid );
							indexPage->deleteKey( &iterKey, headerPage->key_type, dummyRid);
							st = indexPage->get_next( metaRid, &iterKey, iterPage);
							entryInserted = true;
						}
					}
					while( st == OK){
						st = indexPage->deleteKey( &iterKey, headerPage->key_type, dummyRid);
						if( st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
						st = rightSiblingIndexPage->insertKey( (void*)&iterKey, headerPage->key_type, iterPage, dummyRid );
						if( st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
						st = indexPage->get_next( metaRid, &iterKey, iterPage);
					}
					rightSiblingIndexPage->setLeftLink( medPage);
					KeyDataEntry newEntry;
					Datatype entryData;
					entryData.pageNo = rightSiblingIndexPage->page_no();
					int entryLen;
					make_entry( &newEntry, headerPage->key_type, (void*)&medKey,INDEX, entryData, &entryLen);
					**goingUp = newEntry;
					*goingUpSize = entryLen;
					st = MINIBASE_BM->unpinPage( rightPageId, TRUE );
					if( st != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
				}
			}
			else{
				*goingUp = NULL;
				printf("index do not split\n");
			}
			break;
		}

		case LEAF:
		{
			BTLeafPage* leafPage = (BTLeafPage*) rpPtr;
			RID myRid;
			if( leafPage->available_space() >= sizeof(KeyDataEntry)){
				Status myst = leafPage->insertRec(key, headerPage->key_type, rid, myRid);
				if(myst != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				*goingUp = NULL;
			}
			else{
				//split
				fprintf(stderr, "leaf split start >>>>>>>>");
				cout<<"**************************leaf_split"<<endl;
				printPage(currentPageId);

				int numberRec = leafPage->numberOfRecords();

				BTLeafPage* newRight;
//				BTIndexPage* newRoot;
				Status myst;
				PageId newRightID;

				void* currentKey;
				RID currentDataRID;
				if((myst = MINIBASE_BM->newPage(newRightID, (Page*&)newRight)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				newRight->init(newRightID);	
				RID firstRID;
				RID tmp;

				void* middleKey;
				RID middleDataRID;

				if((myst = leafPage->get_first(firstRID, currentKey, currentDataRID)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				int board = (numberRec)/2;
				

				for(int i = 1; i < board; i++){
					if(myst != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
					if((myst = leafPage->get_next(firstRID, currentKey, currentDataRID)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				}
				
				int k = 0;
				for(int j = board; j < numberRec; j++){
					void* tmpKey = (void*) malloc(sizeof(currentKey));
					memcpy(tmpKey, currentKey, sizeof(currentKey));
					if(myst != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
					if(j == board){
						if((myst = leafPage->get_next(firstRID, currentKey, currentDataRID)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
					}
					else{
						leafPage->delUserRid(tmpKey, headerPage->key_type, currentDataRID);
						if((myst = leafPage->get_current(firstRID, currentKey, currentDataRID)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
					}
					myst = newRight->insertRec(currentKey, headerPage->key_type, currentDataRID, tmp);
					if(myst != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				}
				leafPage->delUserRid(currentKey, headerPage->key_type, currentDataRID);
				if((myst = newRight->get_first(firstRID, currentKey, currentDataRID)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);

				middleKey = currentKey;
				middleDataRID = currentDataRID;
				
				if(keyCompare(key, middleKey, headerPage->key_type)>0){
					myst = newRight->insertRec(key, headerPage->key_type, rid, tmp);
					if(myst != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				}
				else if(keyCompare(key, currentKey, headerPage->key_type) == 0){
					assert("key values equal!!");
				}
				else{
					myst = leafPage->insertRec(key, headerPage->key_type, rid, tmp);
					if(myst != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				}


				PageId pre = leafPage->getPrevPage();
				PageId nex = leafPage->getNextPage();
				fprintf(stdout, "pre = %d\nnex = %d\n", pre, nex);
				newRight->setPrevPage(currentPageId);
				leafPage->setNextPage(newRightID);
//				fprintf(stdout, "c = %d\nn = %d\n", currentPageId, newRightID);
				BTLeafPage* tmpPage;
				if(nex >= 0){
					if((myst = MINIBASE_BM->pinPage(nex,(Page *&) tmpPage)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
//				tmpPage->init(newRightID);	
					((BTLeafPage*)tmpPage)->setPrevPage(newRightID);
					newRight->setNextPage(nex);
				
					fprintf(stdout, "before unpin\n");
					if((myst = MINIBASE_BM->unpinPage(nex, TRUE)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);

					fprintf(stdout, "afterpin\n");
				}
				fflush(stdout);
				if((myst = newRight->get_first(firstRID, currentKey, currentDataRID)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				fprintf(stderr, "\nysysys\n");

				middleKey = currentKey;
				middleDataRID = currentDataRID;

//				KeyDataEntry* newEntry = (KeyDataEntry*)malloc(sizeof(KeyDataEntry));
				KeyDataEntry newEntry;
				Datatype entryData;
				Keytype entryKey;
				entryData.pageNo = newRightID;
				fprintf(stderr, "sure:[%d]\n", entryData.pageNo);
				int entryLen;
				make_entry( &newEntry, headerPage->key_type, middleKey,INDEX,entryData, &entryLen);
//				make_entry( &newEntry, headerPage->key_type, middleKey,INDEX, newRightID, &entryLen);
//				(newEntry->key).intkey = *(int*)middleKey;
//				(newEntry->data).pageNo = newRightId;
			
				newEntry.data.pageNo=newRightID;	
			//	fprintf(stderr, "in leaf dataentry:should be [%d] [%d] but: [%d] [%d]\n",*((int*)middleKey), newRightID , newEntry.key.intkey, newEntry.data.pageNo);
				**goingUp = newEntry;
			//	newEntry.data.pageNo = 1;
				*goingUpSize = entryLen;
				if((myst = MINIBASE_BM->unpinPage(newRightID, TRUE)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, myst);
				fprintf(stderr,"\t leaf split end\n");
				printPage(currentPageId);
				printPage(newRightID);

			}
			break;
		}

		default:        // in case memory is scribbled upon & type is hosed
			fprintf(stderr, "currentPageId = (%d) pagetype%d\n", currentPageId, pageType );
			assert(false);
	}
	if((st = MINIBASE_BM->unpinPage(currentPageId, TRUE)) != OK) return MINIBASE_CHAIN_ERROR(BTREE, st);
	return OK;
}
예제 #23
0
파일: session.c 프로젝트: caidongyun/fbbs
static session_id_t session_get_web_cache(user_id_t user_id,
		const char *session_key, const char *ip_addr)
{
	make_entry(user_id, session_key, ip_addr);
	return mdb_integer(0, "HGET", SESSION_WEB_HASH_KEY" %s", entry);
}