Example #1
0
int same_array(mixed *x, mixed *y) {
    if (!arrayp(x) || !arrayp(y)) return 0;
    if (sizeof(x) != sizeof(y)) return 0;
    for (int i = 0; i < sizeof(x); i++) {
	if (arrayp(x[i])) {
	    if (!same_array(x[i], y[i]))
		return 0;
	} else if (x[i] != y[i])
	    return 0;
    }
    return 1;
}
Example #2
0
static int main(string arg) {
    object ply, island;
    string file, *map;
    if (!objectp(ply = this_player())) {
	return 0;
    }
    if (!stringp(arg) || !strlen(arg = getopts("ac", arg))) {
        if (!stringp(file = environment(ply)->query_island())) {
            return notify_fail("Usage: " + query_verb() + " <island>");
        }
        sscanf(file, EMP_DIR_ISLANDS + "%s/island", arg);
    } else {
        file = EMP_DIR_ISLANDS + arg + "/island";
    }
    if (file_size(file + ".c") < 0 ||
        !objectp(island = file->__bootstrap()) ||
	!arrayp(map = island->create_island_view()))
    {
        return notify_fail("Island '" + file + "' not found.");
    }
    if (opts['a']) {
	map = island->format_view(map, 1);
    } else if (opts['c']) {
	map = island->format_view(map, store_fp("do_unload"), arg);
    } else {
	map = island->format_view(map, store_fp("is_loaded"), arg);
    }
    tell_ansi(ply, "\n" + implode(map, "\n"));
    return 1;
}
Example #3
0
static void obtainPairCounts (GfrEntry *currGE)
{
	GfrPairCount *currPC;
	GfrInterRead *currGIR,*nextGIR;
	int i,j;

	currGE->pairCounts = arrayCreate (100,GfrPairCount);
	arraySort (currGE->interReads,(ARRAYORDERF)sortGfrInterReads);
	i = 0;
	while (i < arrayMax (currGE->interReads)) {
		currGIR = arrp (currGE->interReads,i,GfrInterRead);
		currPC = arrayp (currGE->pairCounts,arrayMax (currGE->pairCounts),GfrPairCount);
		currPC->number1 = currGIR->number1;
		currPC->number2 = currGIR->number2;
		currPC->pairType = currGIR->pairType;
		currPC->count = 1;
		j = i + 1;
		while (j < arrayMax (currGE->interReads)) {
			nextGIR = arrp (currGE->interReads,j,GfrInterRead);
			if (currGIR->pairType == nextGIR->pairType && currGIR->number1==nextGIR->number1 && currGIR->number2==nextGIR->number2) {
				currPC->count++;
			}
			else {
				break;
			}
			j++;
		}
		i = j;
	}
}
Example #4
0
string print_vars(mixed *vars) {
    string *result = allocate(sizeof(vars));
    int i;

    for (i=0; i<sizeof(vars); i++) {
	if (mapp(vars[i]))
	    result[i] = "([ ... ])";
	else if (functionp(vars[i]))
	    result[i] = "(: ... :)";
	else if (intp(vars[i]))
	{
	    if (vars[i]) result[i]=vars[i]+"";
	    else if (nullp(vars[i])) result[i]="NULL";
	    else if (undefinedp(vars[i])) result[i]="UNDEFINED";
	    else result[i]="0";
	}
	else if (stringp(vars[i]))
	    result[i] = "\""+vars[i]+"\"";
	else if (arrayp(vars[i]))
	    result[i] = "({ ... })";
	else if (floatp(vars[i]))
	    result[i] = vars[i]+"";
	else if (bufferp(vars[i]))
	    result[i] = "<BUFFER>";
    }
    return implode(result, ", ");
}
Example #5
0
File: types.c Project: Elohim/FGmud
varargs int cmd(string str){
    int err, i;
    string s1, s2;
    string file = "/open/typecheck.c";
    mixed ret, tmpret;
    if(!str){
        write("Try: help types");
        return 1;
    }
    i = sscanf(str,"%s %s", s1, s2);
    if(i != 2 || member_array(s1, types) == -1){
        write("Try: help types");
        return 1;
    }
    contents = header+program;
    contents = replace_string(contents,"$S",s2);
    unguarded((: write_file($(file), contents,1) :));
    reload(file,0,1);
    err = catch( tmpret = file->typecheck() );
    if(err || (stringp(tmpret) && !strsrch(tmpret,"DEFINED_D:"))){
        write("\n"+ tmpret +" appears to be an invalid integer value.");
        return 1;
    }
    else ret = TYPES_D->eventCalculateTypes(s1, tmpret);
    if(arrayp(ret)) ret = implode(ret," ");
    write("The value "+tmpret+" for "+s1+" is: "+ret);
    return 1;
}
Example #6
0
varargs mixed eventManipulate(object who, string component){
    mixed val;

    if( !component ){
        val = Manipulate["default"];
    }
    else {
        val = Manipulate[component];
    }
    if( arrayp(val) ){
        val = val[query_night()];
    }
    if( stringp(val) ){
        object env;

        env = environment(who);
        who->eventPrint(val);
        if( component ){
            env->eventPrint(who->GetName() + " moves the " + component +
                    " on " + GetDefiniteShort() + ".", who);
        }
        else {
            env->eventPrint(who->GetName() + " moves " +
                    GetDefiniteShort() + ".", who);
        }
        return 1;
    }
    else {
        if( functionp(val) & FP_OWNER_DESTED ){
            return "Error in evaluating functional.";
        }
        return evaluate(val, who, component);
    }
}
Example #7
0
static string print_object(mixed ob)
{
  write(to_string(ob));

  if (intp(ob)) 
  {
    return "int";
  }
  else if (stringp(ob)) 
  {
    return "string";
  }
  else if (objectp(ob)) 
  {
    if (interactive(ob)) 
      return "user object";

    return "object";
  }
  else if (mappingp(ob))
  {
    return "mapping";
  }
  else if (arrayp(ob)) 
  {
    return "array";
  }
  else if (undefinedp(ob))
  {
    return "nil";
  }

  return "oh dear";
}
Example #8
0
static mixed *map_array(mixed * arr, mixed fun, varargs mixed arg...) { 
   mixed *extra;
   mixed *result;
   object obj;
   int i, sz;

   argcheck(arrayp(arr), 1, "array");
#ifdef CLOSURES_EXTENSION
   argcheck(stringp(fun) || functionp(fun), 2, "function or string");
#else
   argcheck(stringp(fun), 2, "string");
#endif

   if (sizeof(arg)) {
#ifdef CLOSURES_EXTENSION
      if (functionp(fun)) {
         extra = arg;
      } else
#endif
      if (objectp(arg[0])) {
         obj = arg[0];
      } else if (stringp(arg[0])) {
         obj = find_object(arg[0]);
      }
      if (!extra) {
         argcheck(objectp(obj), 3, "object or string");
         extra = arg[1..];
      }
   } else {
Example #9
0
void set_IDNAME(mixed m)
{
        if (! arrayp(m) || sizeof(m) < 1)
                return;

        id_name = m;
}
Example #10
0
mixed query_IDNAME()
{
        if (! arrayp(id_name) || sizeof(id_name) < 1)
                return 0;
        
        return id_name;
}
Example #11
0
    foreach(key, val in mp) {
        if( arrayp(key) ) {
            string elem;

            foreach(elem in key) tmp[elem] = val;
        }
        else tmp[key] = val;
    }
Example #12
0
// by Lonely
varargs string query_idname(int raw)
{
        if (! arrayp(id_name) || sizeof(id_name) < 1)
                return query("name") + "(" + (raw ? capitalize(query("id")) : query("id")) + ")";
                
        return (id_name[NAME] ? id_name[NAME] : query("name")) + "(" + 
               (raw ? color_capitalize(id_name[ID] ? id_name[ID] : query("id")) : 
               (id_name[ID] ? id_name[ID] : query("id"))) + ")"; 
}
Example #13
0
    foreach( key, val in carte){
        if(arrayp(key)){
            if(!sizeof(key)) retkey = "BLANK ARRAY";
            else retkey = "ARRAY ("+implode(key,", ")+")";
        }
        else if(objectp(key)) retkey = "OBJECT ("+file_name(key)+")";
        else if(intp(key)) retkey = ""+key;
        else retkey = key;
        if(arrayp(val)){
            if(!sizeof(val)) retval = "BLANK ARRAY";
            else retval = "ARRAY ("+implode(val,", ")+")";
        }
        else if(objectp(val)) retval = "OBJECT ("+file_name(val)+")";
        else if(intp(val)) retval = ""+val;
        else retval = val;

        if(!retstring || retstring == "") retstring = retkey+":"+retval;
        else retstring += ", "+retkey+":"+retval;
    }
Example #14
0
File: lin.c Project: teardemon/fy4
object offensive_target(object me)
{
        int sz;
        object *enemy; 
        enemy = me->query_enemy();
        if( !enemy || !arrayp(enemy) ) return 0; 
        sz = sizeof(enemy);
        if( sz > 4 ) sz = 4; 
        if( sz > 0 ) return enemy[random(sz)];
        else return 0;
}  
Example #15
0
string is_vendor_good(string arg)
{
	string *goods;
	object ob;
	int i;

	if (arrayp(goods = query("vendor_goods"))) 
		for (i = 0; i < sizeof(goods); i++) 
			if (goods[i]->id(arg))
				return goods[i];
	return "";
}
Example #16
0
void create()
{
        ::create();
        set("gender",query("gender"));
	set("age", 30 + random(30));
        if (arrayp(query("from")) && sizeof(query("from")))
                set("long",query("from")[random(sizeof(query("form")))] + "\n");
        else
                set("long","");
	set("attitude", "friendly");
        set("chat_chance", 30);
        set("chat_msg", ({ (: random_move :) }));
Example #17
0
mixed *filter_array(mixed * arr, string fun, varargs object obj,
   mixed extra ...) {
   mixed *res;
   int i, sz;

   argcheck(arrayp(arr), 1, "array");
   argcheck(stringp(fun), 2, "string");

   if (!objectp(obj)) {
      obj = this_object();
   }

   res = ( { } );
Example #18
0
void conf_printUnits (FILE *fp, Array regions, Chrdata_t *chromosomes, int scale)
{
  int i;
  SRegion_t *tmp;
  char *chrname;
  int sflag = 1;
  Stringa chrshow = stringCreate (50);

  tmp = arrayp (regions, 0, SRegion_t);
  if (tmp->chromosome == 0) {
    fprintf (fp, "chromosomes_display_default = yes\n");
    fprintf (fp, "chromosomes_units = 1000000\n");
  }
  else {
    stringPrintf (chrshow, "chromosomes = ");

    fprintf (fp, "chromosomes_units = %i\n", scale);
    fprintf (fp, "chromosomes_display_default = no\n");

    for (i = 0; i < arrayMax (regions); i++) {
      tmp = arrayp (regions, i, SRegion_t);
      if (chromosomes[tmp->chromosome].show && tmp->show) {
        chrname = getHchrname (tmp->chromosome);

        if (sflag == 0) {
          stringAppendf (chrshow, ";");
        }
        stringAppendf (chrshow, "%s:%i-%i", chrname, tmp->start/scale, tmp->end/scale);
        sflag = 0;

        free (chrname);
      }
    }
    fprintf (fp, "%s\n", string (chrshow));
  }

  stringDestroy (chrshow);
}
Example #19
0
static mixed * map_array(mixed * arr, string fun, object ob, varargs mixed extra ) {
  mixed * result;
  int i, sz;

  argcheck( arrayp( arr ), 1, "array" );
  argcheck( stringp( fun ), 2, "string" );

  sz = sizeof( arr );
  result = allocate(sz);

  for( i = 0; i < sz; i++ ) {
    result[i] = call_other( ob, fun, arr[i] );
  }
  return result;
}
Example #20
0
string GetInternalDesc(){
    mixed val = InternalDesc;

    if( arrayp(val) ){
        val = val[query_night()];
    }
    if( stringp(val) ){
        return val;
    }
    else if( functionp(val) ){
        if( functionp(val) & FP_OWNER_DESTED ){
            return "Error evaluating internal description.";
        }
        return evaluate(val, this_player());
    }
}
Example #21
0
string std_rank_title(object student)
{
    int exp,i,gen;
    string* ranks;
    int * rank_levels;
    string title;

    ranks=query("ranks");
    rank_levels=query("rank_levels");
    if(!arrayp(rank_levels))
//        	rank_levels= ({76000,466000,1305000,2224000,3788000,
//                       4945000,10000000});
        rank_levels = ({ 16000, 32000,64000, 128000,
                         256000,512000,1024000,1536000,2048000,
                         3064000,4096000, 5120000,6144000,8192000,
                         9999999
                       });
Example #22
0
static void createGffEntry( Array gffEntries, MrfRead *currRead, int groupNumber ) {
  int i;
  MrfBlock *currBlock;
  GffEntry *currGffEntry;
  static Stringa buffer = NULL;
  stringCreateClear (buffer,100);
  for (i = 0; i < arrayMax (currRead->blocks); i++) {
    currBlock = arrp (currRead->blocks,i,MrfBlock);
    currGffEntry = arrayp (gffEntries,arrayMax (gffEntries),GffEntry);
    stringPrintf (buffer,"%s\tMRF\texon\t%d\t%d\t.\t.\t.\tTG%d",
                  currBlock->targetName,
                  currBlock->targetStart,
                  currBlock->targetEnd,
                  //currBlock->strand,
                  groupNumber);
    currGffEntry->targetName = hlr_strdup (currBlock->targetName);
    currGffEntry->line = hlr_strdup (string (buffer));
  }
}
Example #23
0
// This function selects a random target for offensive spells/functions.
object offensive_target(object me)
{
    int sz,k;
	object *enemy;

	enemy = me->query_enemy();
	if( !enemy || !arrayp(enemy) ) return 0;

	sz = sizeof(enemy);
    if( sz > 0 ) {
    k=random(sz);
if(!me || !enemy[k]) return 0;
if(environment(me)!=environment(enemy[k])) {
return 0; } else {
    return enemy[k];
}
}
	else return 0;
}
Example #24
0
int update_files(object me, string *files, string parent, int count){
	
	int i, size;
	string *files2;
	
	reset_eval_cost();
	for(i=0; i<sizeof(files); i++) {
		if (parent + files[i] == "/cmds/adm/updatepartner3.c") continue;
		size=sizeof(files[i]);
		if(files[i][(size-2)..size]==".c") {
	  	       	update_single_file(me, parent+files[i]);
//	  	       	me->ccommand(sprintf("update %s%s",parent,files[i]));
	        } else if (arrayp(get_dir(files[i]))) {
			if (count>1) {
				files2 = get_dir(parent+files[i]+"/");
				update_files(me, files2, parent+files[i]+"/",count-1);	
			}
		}
	}
Example #25
0
static void blastParser_processLine (char* line, BlastQuery* currBlastQuery)
{
    WordIter w;
    BlastEntry *currEntry;

    currEntry = arrayp (currBlastQuery->entries,arrayMax (currBlastQuery->entries),BlastEntry);
    w = wordIterCreate (line,"\t",0);
    currEntry->tName = hlr_strdup (wordNext (w));
    currEntry->percentIdentity = atof (wordNext (w));
    currEntry->alignmentLength = atoi (wordNext (w));
    currEntry->misMatches = atoi (wordNext (w));
    currEntry->gapOpenings = atoi (wordNext (w));
    currEntry->qStart = atoi (wordNext (w));
    currEntry->qEnd = atoi (wordNext (w));
    currEntry->tStart = atoi (wordNext (w));
    currEntry->tEnd = atoi (wordNext (w));
    currEntry->evalue = atof (wordNext (w));
    currEntry->bitScore = atof (wordNext (w));
    wordIterDestroy (w);
}
Example #26
0
// This is the chat function dispatcher. If you use function type chat
// message, you can either define your own functions or use the default
// ones.
int chat()
{
	string *msg;
	int chance, rnd;

	if( !environment() ) return 0;

	if( !chance = (int)query(is_fighting()? "chat_chance_combat": "chat_chance") )
		return 0;
	if( random(100) > chance ) return 0;

	if( arrayp(msg = query(is_fighting()? "chat_msg_combat": "chat_msg"))) {
		if (sizeof(msg) == 0) return 0;
		rnd = random(sizeof(msg));
		if( stringp(msg[rnd]) )
			say(msg[rnd]);
		else if( functionp(msg[rnd]) )
			return evaluate(msg[rnd]);
		return 1;
	}
}
Example #27
0
void performSegmentation (Array tars, Array wigs, char* targetName, double threshold, int maxGap, int minRun)
{
  Tar *currTar;
  Wig *currWig,*nextWig;
  int i,j,endPosition;
  int countBelowThreshold;

  i = 0; 
  while (i < arrayMax (wigs)) {
    currWig = arrp (wigs,i,Wig);
    if (currWig->value < threshold) {
      i++;
      continue;
    }
    j = i + 1;
    endPosition = j;
    countBelowThreshold = 0;
    while (j < arrayMax (wigs)) {
      nextWig = arrp (wigs,j,Wig);
      if (nextWig->value < threshold) {
        countBelowThreshold++;
        if (countBelowThreshold >= maxGap) {
          break;
        }
      }
      else {
        countBelowThreshold = 0;
        endPosition = j;
      }
      j++;
    }
    if ((endPosition - 1 - currWig->position + 1) >= minRun) {
      currTar = arrayp (tars,arrayMax (tars),Tar);
      currTar->start = currWig->position;
      currTar->end = endPosition + 1;
      currTar->targetName = hlr_strdup (targetName);
     }
    i = j;
  }
}
Example #28
0
int do_list(string arg)
{
	string *goods;
	object *inv;
	int i;

	inv = all_inventory(this_object());

	if( arg=="" ) return 0;

	if (!sizeof(inv) && !arrayp(goods = query("vendor_goods")))
		return notify_fail("目前没有可以买的东西。\n");
	
	if(! arg){
	if (arrayp(goods = query("vendor_goods"))){
                for (i = 0; i < sizeof(goods); i++)
                        printf("%30-s:%s\n", goods[i]->short(),
                        MONEY_D->price_str(goods[i]->query("value")));
        return 1;
	}
	else
	printf("你想看哪一柜?(armor、weapon、drug、book or misc)\n");	
	return 1;
	}
Example #29
0
int chat()
{
        string *msg;
        int chance, rnd; 
        if( !environment() ) return 0;
        if( query_temp("is_unconcious") ) return 0;
        if(query("intellgent")) intellgent_behavor();
        if( !chance = (int)query(is_fighting()? "chat_chance_combat":
                                                         "chat_chance") )
                return 0; 
        if(arrayp(msg = query(is_fighting()? "chat_msg_combat": "chat_msg")) 
                        && sizeof(msg) != 0) {
                if( random(100) < chance ) {
                        rnd = random(sizeof(msg));
                        if(stringp(msg[rnd])) {
                                say(msg[rnd]);
                        } else if(functionp(msg[rnd])) {
                                return evaluate(msg[rnd]);
                        }
                }
           return 1;
        }
        return 0;
} 
Example #30
0
/*
 * 'compile' the shape and len of a variable
 *  Formerly
NC_var_shape(var, dims)
 */
int
NC_var_shape(NC_var *varp, const NC_dimarray *dims)
{
	size_t *shp, *op;
	off_t *dsp;
	int *ip;
	const NC_dim *dimp;
	off_t product = 1;
	
	varp->xsz = ncx_szof(varp->type);

	if(varp->ndims == 0)
	{
		goto out;
	}

	/*
	 * use the user supplied dimension indices
	 * to determine the shape
	 */
	for(ip = varp->dimids, op = varp->shape
		; ip < &varp->dimids[varp->ndims]; ip++, op++)
	{
		if(*ip < 0 || (size_t) (*ip) >= ((dims != NULL) ? dims->nelems : 1) )
			return NC_EBADDIM;
		
		dimp = elem_NC_dimarray(dims, (size_t)*ip);
		*op = dimp->size;
		if(*op == NC_UNLIMITED && ip != varp->dimids)
			return NC_EUNLIMPOS;
	}

	/* 
	 * Compute the dsizes
	 */
				/* ndims is > 0 here */
	for(shp = varp->shape + varp->ndims -1,
				dsp = varp->dsizes + varp->ndims -1;
 			shp >= varp->shape;
			shp--, dsp--)
	{
		if(!(shp == varp->shape && IS_RECVAR(varp)))
		{
		    if( (off_t)(*shp) <= OFF_T_MAX / product ) 
			{
				product *= *shp;
			} else 
			{
				product = OFF_T_MAX ;
			}
		}
		*dsp = product;
	}


out :
    if( varp->xsz <= (X_UINT_MAX - 1) / product ) /* if integer multiply will not overflow */
	{
	        varp->len = product * varp->xsz;
		switch(varp->type) {
		case NC_BYTE :
		case NC_CHAR :
		case NC_SHORT :
		        if( varp->len%4 != 0 )
			{
			        varp->len += 4 - varp->len%4; /* round up */
		/*		*dsp += 4 - *dsp%4; */
		    }
		    break;
		default:
			/* already aligned */
			break;
		}
        } else
	{	/* OK for last var to be "too big", indicated by this special len */
	        varp->len = X_UINT_MAX;
        }
#if 0
	arrayp("\tshape", varp->ndims, varp->shape);
	arrayp("\tdsizes", varp->ndims, varp->dsizes);
#endif
	return NC_NOERR;
}