Example #1
0
int main(void) {
	int i, j;
	char s[MAXLEN], t[MAXLEN];		/* input strings */

	s[0] = t[0] = ' ';

	scanf("%s", &(s[1])); scanf("%s", &(t[1]));
	printf("matching cost = %d \n", string_compare(s, t));
	print_matrix(s, t, TRUE);	printf("\n");	print_matrix(s, t, FALSE);

	goal_cell(s, t, &i, &j); printf("%d %d\n", i, j);
	reconstruct_path(s,t, i ,j); printf("\n");
	
	return 0;
}
Example #2
0
struct inst *
funcname_to_pc(dbref program, const char *name)
{
    int i, siz;
    struct inst *code;
    code = DBFETCH(program)->sp.program.code;
    siz = DBFETCH(program)->sp.program.siz;
    for (i = 0; i < siz; i++) {
        if ((code[i].type == PROG_FUNCTION) &&
                !string_compare(name, code[i].data.string->data)) {
            return (code + i);
        }
    }
    return(NULL);
}
Example #3
0
void sort_strings (char** in, char** out) {
    int in_index = 0;
    while (in[in_index] != NULL) {
        char* in_string = in[in_index++];
        int out_index = 0;
        while (out[out_index] != NULL) {
            char* out_string = out[out_index];
            printf("%s, %s\n", in_string, out_string);
            if (string_compare(in_string, out_string))
                insert (out, in_string, out_index);
            else 
                out_index++;
        }
    }
}
Example #4
0
void
prim_cancallp(PRIM_PROTOTYPE)
{
	CHECKOP(2);
	oper2 = POP();				/* string: public function name */
	oper1 = POP();				/* dbref: Program dbref to check */
	if (oper1->type != PROG_OBJECT)
		abort_interp("Expected dbref argument. (1)");
	if (!valid_object(oper1))
		abort_interp("Invalid dbref (1)");
	if (Typeof(oper1->data.objref) != TYPE_PROGRAM)
		abort_interp("Object is not a MUF Program. (1)");
	if (oper2->type != PROG_STRING)
		abort_interp("Expected string argument. (2)");
	if (!oper2->data.string)
		abort_interp("Invalid Null string argument. (2)");

	if (!(PROGRAM_CODE(oper1->data.objref))) {
		struct line *tmpline;

		tmpline = PROGRAM_FIRST(oper1->data.objref);
		PROGRAM_SET_FIRST(oper1->data.objref,
						  (struct line *) read_program(oper1->data.objref));
		do_compile(-1, OWNER(oper1->data.objref), oper1->data.objref, 0);
		free_prog_text(PROGRAM_FIRST(oper1->data.objref));
		PROGRAM_SET_FIRST(oper1->data.objref, tmpline);
	}

	result = 0;
	if (ProgMLevel(oper1->data.objref) > 0 &&
		(mlev >= 4 || OWNER(oper1->data.objref) == ProgUID || Linkable(oper1->data.objref))
			) {
		struct publics *pbs;

		pbs = PROGRAM_PUBS(oper1->data.objref);
		while (pbs) {
			if (!string_compare(oper2->data.string->data, pbs->subname))
				break;
			pbs = pbs->next;
		}
		if (pbs && mlev >= pbs->mlev)
			result = 1;
	}
	CHECKOFLOW(1);
	CLEAR(oper1);
	CLEAR(oper2);
	PushInt(result);
}
Example #5
0
/* Probe_volfree */
uint32_t Probe_volfree(Probe * probe, AppServerClient * asc,
		String const * volume)
{
	unsigned int i;

	for(i = 0; i < probe->volinfo_cnt
			&& string_compare(probe->volinfo[i].name, volume) != 0;
			i++);
	if(i == probe->volinfo_cnt)
		return -1;
#if defined(DEBUG)
	fprintf(stderr, "%s() %s %lu\n", __func__, probe->volinfo[i].name,
			probe->volinfo[i].free);
#endif
	return probe->volinfo[i].free * (probe->volinfo[i].block_size / 1024);
}
Example #6
0
/*
 *  Given the name of a process, find its PCB entry 
 */
PROCESS find_process_by_name (char* name) 
{
   PROCESS this_process = NULL; 

   //find the process in the PCB array
   int i;
   for (i = 0; i < MAX_PROCS; i++) 
   {
      if (string_compare(pcb[i].name, name) )
      {
         this_process = &pcb[i];
         break; 
      }
   }
   return this_process; 
}
Example #7
0
static int do_debug(char *arg)
{
	int result;

	arg = wdog_get_loglevel();
	if (string_compare("notice", arg))
		arg = "debug";
	else
		arg = "notice";

	result = wdog_set_loglevel(arg);
	if (verbose)
		printf("loglevel: %s\n", wdog_get_loglevel());

	return result;
}
Example #8
0
char *
macro_expansion(struct macrotable *node, const char *match)
{
	if (!node)
		return NULL;
	else {
		register int value = string_compare(match, node->name);

		if (value < 0)
			return macro_expansion(node->left, match);
		else if (value > 0)
			return macro_expansion(node->right, match);
		else
			return alloc_string(node->definition);
	}
}
Example #9
0
static int atomic_hash_table_update_one_file(english_word *word){
  uint64_t hashv=fnv_hash(word->str,word->len);
  uint64_t index=hashv%global_hash_table_size;
  //this next line results in a lot of cache misses
  //for obvious reasons
  if(!global_hash_table[index]){//word isn't in the hash table, add it
    uint8_t *mem=xmalloc(word->len);
    word->str=(char*)my_strcpy(mem,(uint8_t*)word->str,word->len);
    void *prev=global_hash_table[index];
    int test=atomic_compare_exchange_n(global_hash_table+index,&prev,word);
    if(test){
      //we added the word
      //this needs to be atomic to prevent two threads writing different
      //values to the same index of indices
      uint64_t old_indices_index=atomic_fetch_add(&indices_index,1);
      //this doesn't need to be atomic, since indices_index will never be
      //decremented, so no one else will change this
      hash_table_indices[old_indices_index]=index;
      goto end1;
    }
    //else, someone else changed the value of global_hash_table[index] before us
  }
  while(1){
    do {
      //see if the value in the table is the same as our value
      //if so update the value already in the table
      if(string_compare(global_hash_table[index],word)){
        //atomically increment word count
        atomic_add(&global_hash_table[index]->count,1);
        goto end0;
      }
    } while(global_hash_table[++index]);
    //not in the table use next free index (if we can)
    void *prev=global_hash_table[index];
    int test=atomic_compare_exchange_n(global_hash_table+index,&prev,word);
    if(test){
      uint64_t old_indices_index=atomic_fetch_add(&indices_index,1);
      hash_table_indices[old_indices_index]=index;
      goto end1;
    }
    //if !test the compare exchange failed and we need to keep looping
  }
 end0:
  return 0;
 end1:
  return 1;
}
Example #10
0
static int tuple_compare_string (const Tuple * a, const Tuple * b, int field)
{
    char * string_a = tuple_get_str (a, field, NULL);
    char * string_b = tuple_get_str (b, field, NULL);
    int ret;

    if (string_a == NULL)
        ret = (string_b == NULL) ? 0 : -1;
    else if (string_b == NULL)
        ret = 1;
    else
        ret = string_compare (string_a, string_b);

    str_unref (string_a);
    str_unref (string_b);
    return ret;
}
Example #11
0
int skill_lookup(char *skill) {
	if (string_is_numeric(skill)) {
		int d;
		sscanf(skill, "%i", &d);

		return d;
	} else {
		int i;
		for (i = 0; i < n_skills; i++) {
			if (string_compare((char *) skills[i], skill, FALSE)) {
				return i;
			}
		}

		return -1;
	}
}
Example #12
0
static struct word *__search_cat_word(const struct cat_node *node, const struct string *word)
{
	struct rbtree_node *n;
	struct word *w;
	int res;
	for (n = node->words.node; n != NULL; ) {
		w = get_word(n);
		if ((res = string_compare(word, &w->name)) < 0) {
			n = n->left;
		} else if (res > 0) {
			n = n->right;
		} else {
			return w;
		}
	}
	return NULL;
}
Example #13
0
static void
req_forward_all_local_racks(struct context *ctx, struct conn *c_conn,
                            struct msg *msg, struct mbuf *orig_mbuf,
                            uint8_t *key, uint32_t keylen, struct datacenter *dc)
{
    //log_debug(LOG_DEBUG, "dc name  '%.*s'",
    //            dc->name->len, dc->name->data);
    uint8_t rack_cnt = (uint8_t)array_n(&dc->racks);
    uint8_t rack_index;
    msg->rsp_handler = msg_get_rsp_handler(msg);
    init_response_mgr(&msg->rspmgr, msg, msg->is_read, rack_cnt, c_conn);
    log_info("msg %d:%d same DC racks:%d expect replies %d",
             msg->id, msg->parent_id, rack_cnt, msg->rspmgr.max_responses);
    for(rack_index = 0; rack_index < rack_cnt; rack_index++) {
        struct rack *rack = array_get(&dc->racks, rack_index);
        //log_debug(LOG_DEBUG, "rack name '%.*s'",
        //            rack->name->len, rack->name->data);
        struct msg *rack_msg;
        // clone message even for local node
        struct server_pool *pool = c_conn->owner;
        if (string_compare(rack->name, &pool->rack) == 0 ) {
            rack_msg = msg;
        } else {
            rack_msg = msg_get(c_conn, msg->request, __FUNCTION__);
            if (rack_msg == NULL) {
                log_debug(LOG_VERB, "whelp, looks like yer screwed "
                        "now, buddy. no inter-rack messages for "
                        "you!");
                continue;
            }

            msg_clone(msg, orig_mbuf, rack_msg);
            log_info("msg (%d:%d) clone to rack msg (%d:%d)",
                     msg->id, msg->parent_id, rack_msg->id, rack_msg->parent_id);
            rack_msg->swallow = true;
        }

        if (log_loggable(LOG_DEBUG)) {
            log_debug(LOG_DEBUG, "forwarding request to conn '%s' on rack '%.*s'",
                    dn_unresolve_peer_desc(c_conn->sd), rack->name->len, rack->name->data);
        }
        log_debug(LOG_VERB, "c_conn: %p forwarding (%d:%d)",
                c_conn, rack_msg->id, rack_msg->parent_id);
        remote_req_forward(ctx, c_conn, rack_msg, rack, key, keylen);
    }
}
Example #14
0
void
muf_dlog_remove(struct frame *fr, const char *dlogid)
{
	struct dlogidlist **prev = &fr->dlogids;

	while (*prev) {
		if (!string_compare(dlogid, (*prev)->dlogid)) {
			struct dlogidlist *tmp = *prev;

			*prev = (*prev)->next;
			free(tmp);
		} else {
			prev = &((*prev)->next);
		}
	}
	GuiFree(dlogid);
}
/* this function will return the value of an indexed hash */
char *ht_get(HashTable *hashtable, const char *key)
{
        List *list_ptr;
        unsigned int index;
        /* retrieve the index using the hash function */
        index = hash(key, hashtable->size);
        /* affect the pointer to the first node in the list with the given index of the hash table array */
        list_ptr = hashtable->array[index];
        /* while the node in the list is not NULL traverse the list till we find the requested key */
        while(list_ptr != NULL) {
                if(string_compare(list_ptr->key, key) == 0) {
                        return (strdup(list_ptr->value));
                }
                list_ptr = list_ptr->next;
        }
        return "NULL";
}
Example #16
0
/* add a function to a context */
int context_add_function(context_t *cont, function_t *func)
{
	function_t *check_func = NULL;

	context_lock(cont);

	if (func->name != NULL) {
		/* this is a function with a name */
		check_func = LIST_TO_STRUCT(function_t, list, cont->funcs.next);

		/* check that we don't have this function's name already */
		while (check_func != NULL) {
			if (!string_compare(check_func->name, func->name)) {
				context_unlock(cont);
				ERROR(-ERROR_FEXIST);
			}
			check_func = LIST_TO_STRUCT(function_t, list, check_func->list.next);
		}

		/* add the function to the funcs list */
		func->list.next = cont->funcs.next;
		func->list.prev = &cont->funcs;

		if (cont->funcs.next != NULL) {
			cont->funcs.next->prev = &func->list;
		}
		cont->funcs.next = &func->list;

	} else {
		/* this is a anonymous function */

		/* add the function to the anonym list */
		func->list.next = cont->anonym.next;
		func->list.prev = &cont->anonym;

		if (cont->anonym.next != NULL) {
			cont->anonym.next->prev = &func->list;
		}
		cont->anonym.next = &func->list;
	}

	func->cont = cont;

	context_unlock(cont);
	return 0;
}
Example #17
0
gint graph_tree_model_compare_name(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer user_data)
{
  scene::Node* first;
  gtk_tree_model_get(model, a, 0, (gpointer*)&first, -1);
  scene::Node* second;
  gtk_tree_model_get(model, b, 0, (gpointer*)&second, -1);
  int result = 0;
  if(first != 0 && second != 0)
  {
    result = string_compare(node_get_name(*first), node_get_name(*second));
  }
  if(result == 0)
  {
    return (first < second) ? -1 : (second < first) ? 1 : 0;
  }
  return result;
}
Example #18
0
void match_me(void)
{
    if (md.confidence >= CON_DBREF) {
	return;
    }

    if (Good_obj(md.absolute_form) && (md.absolute_form == md.player)) {
	promote_match(md.player, CON_DBREF | CON_LOCAL);
	return;
    }

    if (!string_compare(md.string, "me")) {
	promote_match(md.player, CON_TOKEN | CON_LOCAL);
    }

    return;
}
Example #19
0
struct rack *
server_get_rack(struct datacenter *dc, struct string *rackname)
{
	ASSERT(dc != NULL);
	ASSERT(dc->dict_rack != NULL);
	ASSERT(dc->name != NULL);

	if (log_loggable(LOG_DEBUG)) {
		log_debug(LOG_DEBUG, "server_get_rack   '%.*s'", rackname->len, rackname->data);
	}
	/*
   struct rack *rack = dictFetchValue(dc->dict_rack, rackname);
   if (rack == NULL) {
      rack = array_push(&dc->racks);
      rack_init(rack);
      string_copy(rack->name, rackname->data, rackname->len);
      string_copy(rack->dc, dc->name->data, dc->name->len);
      rack->continuum = dn_alloc(sizeof(struct continuum));

   	dictAdd(dc->dict_rack, rackname, rack);
   }
	 */

	struct rack *rack;
	uint32_t i, len;
	for (i = 0, len = array_n(&dc->racks); i < len; i++) {
		rack = (struct rack *) array_get(&dc->racks, i);

		if (string_compare(rack->name, rackname) == 0) {
			return rack;
		}
	}

	rack = array_push(&dc->racks);
	rack_init(rack);
	string_copy(rack->name, rackname->data, rackname->len);
	string_copy(rack->dc, dc->name->data, dc->name->len);

	if (log_loggable(LOG_DEBUG)) {
		log_debug(LOG_DEBUG, "server_get_rack exiting  '%.*s'",
				rack->name->len, rack->name->data);
	}

	return rack;
}
Example #20
0
void
_nsdbtput(const ns_dbt *dbt)
{
	unsigned int	 i;
	ns_dbt		*p;

	for (i = 0; i < _nsmapsize; i++) {
		p = vector_ref(i, _nsmap, _nsmapsize, sizeof(*_nsmap));
		if (string_compare(&dbt->name, &p->name) == 0) {
			/* overwrite existing entry */
			if (p->srclist != NULL)
				ns_src_free(&p->srclist, p->srclistsize);
			memmove(p, dbt, sizeof(*dbt));
			return;
		}
	}
	_nsmap = vector_append(dbt, _nsmap, &_nsmapsize, sizeof(*_nsmap));
}
Example #21
0
static int _channels_get(MixerControlPlugin * channels, va_list properties)
{
	String const * p;
	gboolean * b;
	double * value;
	size_t i;
	unsigned int * u;

#ifdef DEBUG
	fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
	while((p = va_arg(properties, String const *)) != NULL)
		if(string_compare(p, "bind") == 0)
		{
			b = va_arg(properties, gboolean *);
			*b = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
						channels->bind));
		}
Example #22
0
void
find_empty_place(void)
{
  /* @@@ while (z3 == 0) this is a nasty one.*/
  do
    {
      r1 = function_r();
      r2 = function_r();

      strcpy(sA, "   ");

      z1 = r1;
      z2 = r2;

      string_compare();
    } while (z3 == 0);

  z3 = 0;
}
Example #23
0
PmReturn_t
mod_import(pPmObj_t pstr, pPmObj_t *pmod)
{
    pPmImgInfo_t pii = C_NULL;
    uint8_t const *imgaddr = C_NULL;
    pPmCo_t pco = C_NULL;
    PmReturn_t retval = PM_RET_OK;
    pPmObj_t pobj;

    /* If it's not a string obj, raise SyntaxError */
    if (OBJ_GET_TYPE(pstr) != OBJ_TYPE_STR)
    {
        PM_RAISE(retval, PM_RET_EX_SYNTAX);
        return retval;
    }

    /* Iterate through the global img list */
    pii = gVmGlobal.pimglist;

    /* Scan until end of list or string matches */
    while ((pii != C_NULL)
           && (string_compare((pPmString_t)pstr, pii->ii_name) == C_DIFFER))
    {
        pii = pii->next;
    }

    /* If img was not found, raise ImportError */
    if (pii == C_NULL)
    {
        PM_RAISE(retval, PM_RET_EX_IMPRT);
        return retval;
    }

    /* Make copy of addr so image list pointer isn't modified */
    imgaddr = pii->ii_addr;

    /* Load img into code obj */
    retval = obj_loadFromImg(pii->ii_memspace, &imgaddr, &pobj);
    PM_RETURN_IF_ERROR(retval);
    pco = (pPmCo_t)pobj;

    return mod_new((pPmObj_t)pco, pmod);
}
Example #24
0
/* gserverplatform_get_driver */
String const * gserverplatform_get_driver(GServerPlatform * platform,
		String const * subsystem)
{
	struct
	{
		String const * subsystem;
		String const * fallback;
	} fallback[] =
	{
		{ "video",	"glx"	}
	};
	size_t i;

	for(i = 0; i < sizeof(fallback) / sizeof(*fallback); i++)
		if(string_compare(fallback[i].subsystem, subsystem) == 0)
			return _gserverplatform_get_string(platform, "drivers",
					subsystem, fallback[i].fallback);
	return _gserverplatform_get_string(platform, "drivers", subsystem,
			NULL);
}
Example #25
0
/* find a function by name */
void *context_find_function(context_t *cont, byte *name)
{
	function_t *func;

	context_lock(cont);

	func = LIST_TO_STRUCT(function_t, list, cont->funcs.next);
	while (func != NULL) {
		if (!string_compare(func->name, (char *)name)) {
			function_get(func);

			context_unlock(cont);
			return func;
		}
		func = LIST_TO_STRUCT(function_t, list, func->list.next);
	}

	context_unlock(cont);

	return NULL;
}
bool object_remove_symbol(memptr object, memptr symbol) {

	memptr previous_node = object, current_node, next_node =
			cons_pool[object].cdr, current_data;
	if (next_node != nil) {
		do {
			current_node = next_node;
			current_data = cons_pool[current_node].car;
			if (string_compare(get_string(cons_pool[current_data].car, 0),
					get_string(cons_pool[symbol].car, 0))) {
				cons_pool[previous_node].cdr = cons_pool[current_node].cdr;
				cons_pool[previous_node].cdrKind =
						cons_pool[current_node].cdrKind;
				return true;
			}
			previous_node = current_node;
			next_node = cons_pool[current_node].cdr;
		} while (cons_pool[current_node].cdrKind != NIL);
	}
	return false;
}
Example #27
0
int string_sort(void){
   int i, j, k, arraySize;
   char temp[20];
   arraySize = sizeof(names)/sizeof(names[0]);
   for(k=0; k < (arraySize - 1); k++){         //bubble sort
      for(i=0; i < (arraySize - k - 1); i++){
          if(string_compare(i,i+1) == 1){      //if string[i] > string[i+1], swap
              for(j=0; names[i][j]!='\0'; j++)
                  temp[j] = names[i][j];      //copy to temp
              temp[j] = '\0';
              for(j=0; names[i+1][j] != '\0'; j++)
                   names[i][j] = names[i+1][j];
              names[i][j] = '\0';
              for(j=0; temp[j] != '\0'; j++)
                  names[i+1][j] = temp[j];
              names[i+1][j] = '\0';
            }
      }
   }
   return arraySize;
}
Example #28
0
static rstatus_t
conf_handler(struct conf *cf, void *data)
{
    struct command *cmd;
    struct string *key, *value;
    uint32_t narg;

    if (array_n(&cf->arg) == 1) {
        value = array_top(&cf->arg);
        log_debug(LOG_VVERB, "conf handler on '%.*s'", value->len, value->data);
        return conf_pool_init(data, value);
    }

    narg = array_n(&cf->arg);
    value = array_get(&cf->arg, narg - 1);
    key = array_get(&cf->arg, narg - 2);

    log_debug(LOG_VVERB, "conf handler on %.*s: %.*s", key->len, key->data,
              value->len, value->data);

    for (cmd = conf_commands; cmd->name.len != 0; cmd++) {
        char *rv;

        if (string_compare(key, &cmd->name) != 0) {
            continue;
        }

        rv = cmd->set(cf, cmd, data);
        if (rv != CONF_OK) {
            log_error("conf: directive \"%.*s\" %s", key->len, key->data, rv);
            return NC_ERROR;
        }

        return NC_OK;
    }

    log_error("conf: directive \"%.*s\" is unknown", key->len, key->data);

    return NC_ERROR;
}
Example #29
0
/*
 * This function is used to check if a process is created correctly.
 * It checks for the PCB entry and process stack
 */
void check_create_process(char* name,
			  int priority,
			  void (*entry_point) (PROCESS, PARAM),
			  PARAM param) 
{
   //find the PCB entry for the process
   PROCESS this_process = find_process_by_name(name);
  
   //if the process is not in the pcb array, it is incorrect.
   if (this_process == NULL)
   {
      test_result = 10;
      return;
   }

   //check if the PCB entry is initialized correctly  
   if (this_process-> magic != MAGIC_PCB ||
       this_process -> used != TRUE ||
       this_process -> state != STATE_READY ||
       this_process-> priority != priority ) 
   {
      test_result = 11;
      return;
   } 

   //check new process's stack
   if(string_compare(name, boot_name))
   {
      //no need to check boot process's stack
      return;
   }

   unsigned stack_pointer = this_process->esp;

   if (peek_l(stack_pointer + 28 ) != (LONG) entry_point ) 
   {
      test_result = 12;
      return;
   }
}
Example #30
0
dbref
connect_player(const char *name, const char *password)
{
    dbref   player, i;

    if (*name == '#' && number(name+1) && atoi(name+1)) {
        player = (dbref) atoi(name + 1);
        if ((!OkObj(player)) || (Typeof(player) != TYPE_PLAYER))
            player = NOTHING;
    } else {
        player = lookup_player(name);
    }
    if (player == NOTHING) {
        /* Check for a player not in the hashtable */
        for(i = (db_top - 1); i > NOTHING; i--) {
            if(Typeof(i) == TYPE_PLAYER) {
                if(!string_compare(name, NAME(i))) {
                    /* Oooga, found a player that lookup didn't! */
                    log_status(HASH1_MSG);
                    wall_wizards(MARK HASH1_MSG);
                    refresh_players();
                    player = lookup_player(name);
                    if(player == NOTHING) {
                        log_status(HASH2_MSG);
                        wall_wizards(MARK HASH2_MSG);
                    }
                    break;
                }
            }
        }
        if(player == NOTHING)
            return NOTHING;
    }
    if (DBFETCH(player)->sp.player.password
            && *DBFETCH(player)->sp.player.password
            && strcmp(DBFETCH(player)->sp.player.password, password))
        return NOTHING;

    return player;
}