Exemple #1
0
void testpop()
{
	struct node* node = NULL;
	node = buildlistattailbyref(10);
	printlist(node, "at tail by local ref ");
	listlen(node);
	pop(&node);
	printlist(node, "after popping a node");
	listlen(node);
}
Exemple #2
0
void testattailbyref()
{
	struct node* node = NULL;
	node = buildlistattailbyref(10);
	printlist(node, "at tail by local ref ");
	listlen(node);
}
Exemple #3
0
int 
listMatchingOrgs (char *cstr, char *ostr, struct namelist **olistp)
{
	VFP * filtarray;
	VFP filterfunc;
	int filtnumber;

	if (index(ostr, '*') != NULLCP) { /* contains at least one asterisk */
		filtarray = explicitOrg;
		filtnumber = -1;
	} else {
		filtarray = normalOrg;
		filtnumber = 0;
	}
	sarg = * fillMostOrgSearchArgs(cstr, SRA_ONELEVEL);
	while ((filterfunc = *filtarray++) != NULLVFP) {
		filtnumber++;
		filterfunc(ostr, &sarg.sra_filter);
		if (makeListOrganisations(olistp) != OK) {
			freeOrgSearchArgs();
			logSearchSuccess(SEARCH_ERROR, "org", ostr, filtnumber, 0);
			alarmCleanUp();
			return NOTOK;
		}
		if (*olistp != NULLLIST)
			break;
	}
	if (*olistp != NULLLIST)
		logSearchSuccess(SEARCH_OK, "org", ostr, filtnumber, listlen(*olistp));
	else
		logSearchSuccess(SEARCH_FAIL, "org", ostr, filtnumber, 0);
	freeOrgSearchArgs();
	alarmCleanUp();
	return OK;
}
Exemple #4
0
int ExportCRIMAPPar(individual *indlist)
{
  int nLoci, i;
  

  nLoci = listlen(indlist->marker);

  cfopen ("crimap.par", "w");
  fprintf(F, "dat_file crimap.dat *\n");
  fprintf(F, "gen_file crimap.gen *\n");
  fprintf(F, "ord_file crimap.ord *\n");
  fprintf(F, "nb_our_alloc 3000000 *\n");
  fprintf(F, "SEX_EQ  1 *\n");
  fprintf(F, "TOL .010000 *\n");
  fprintf(F, "PUK_NUM_ORDERS_TOL  6 *\n");
  fprintf(F, "PK_NUM_ORDERS_TOL  8 *\n");
  fprintf(F, "PUK_LIKE_TOL 3.000 *\n");
  fprintf(F, "PK_LIKE_TOL 3.000 *\n");
  fprintf(F, "use_ord_file  0 *\n");
  fprintf(F, "write_ord_file  1 *\n");
  fprintf(F, "use_haps  1 *\n");
  fprintf(F, "ordered_loci 0 1  *\n");

  fprintf(F, "inserted_loci ");
  for (i=2; i<nLoci; i++)
    fprintf(F, "%d ",i);
  fprintf(F, "  *\n");

  fprintf(F, "END\n");
  fclose(F);

  printf("Created crimap parameter file\n");
  return 0;

}
Exemple #5
0
int ExportSolarPedigree (individual *indlist)
{
  individual *ind;
  

  // Checks that data exists
  if (!listlen(indlist))
  {
    // XXX Should create a proper output rutine for warnings
    //    WriteWarning("No pedigree data avaliable for creating SOLAR file\n");
    return -1;
  }

  // Makes pedigree file
  cfopen ("solar.ped", "w");
  fprintf(F, "id,fa,mo,sex\n");  // The first line
  for (ind = indlist; ind; ind = ind->next)
  {
    if (founder(ind))
      fprintf(F, "%s,0,0,%d\n",ind->id, ind->sex);
    else
      fprintf(F, "%s,%s,%s,%d\n",ind->id, ind->father->id, ind->mother->id,ind->sex);
  }
  fclose(F);
  return 0;
}
Exemple #6
0
static void autopickup_rules_help(void)
{
    struct nh_menuitem items[] = {
	{0, MI_TEXT, "自动拾取规则只有当开启自动拾取功能时生效。"},
	{0, MI_TEXT, "当自动拾取功能开启时,你走到一件物品上方,这件物品"},
	{0, MI_TEXT, "将与每个规则相比较,直到有一个规则满足。"},
	{0, MI_TEXT, "如果存在一个满足的规则,与此规则相对应的动作将被执"},
	{0, MI_TEXT, "行,然后其他的规矩将被忽略。"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "每个规则都可以匹配物体名称、类型或祝福状态的任意组"},
	{0, MI_TEXT, "何(包括未知的情况)。"},
	{0, MI_TEXT, "可以设置一个规则来匹配任意的情况。"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "加入你的匹配规则像这样:"},
	{0, MI_TEXT, " 1. IF name matches \"*lizard*\" AND type is \"food\": < GRAB"},
	{0, MI_TEXT, " 2. IF name matches \"*corpse*\" AND type is \"food\":   LEAVE >"},
	{0, MI_TEXT, " 3. IF type is \"food\":                             < GRAB"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "“newt corpse”将不满足规则1,但是会满足规则2。"},
	{0, MI_TEXT, "它将不会被拾取,规则3也将被忽略。"},
	{0, MI_TEXT, "(严格地说,\"type is food\"这条规则并不是必须"},
	{0, MI_TEXT, "的;它在这只是为了让例子更有趣一些。)"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "“dagger”将不会匹配上述任何一种情况,所有它将不会"},
	{0, MI_TEXT, "被自动拾取。"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "你可以在列表中选择一个已存在的规则来编辑它,修改它"},
	{0, MI_TEXT, "的条件,或者删除它。"},
    };
    curses_display_menu(items, listlen(items), "自动拾取规则帮助:", PICK_NONE, NULL);
}
Exemple #7
0
CELL * sublist(CELL * list, ssize_t offset, ssize_t length)
{
CELL * subList;
CELL * cell;

if(offset < 0) 
	offset = convertNegativeOffset(offset, list);

if(length < 0)
	{
	length = listlen(list) - offset + length;
	if(length < 0) length = 0;
	}

subList = getCell(CELL_EXPRESSION);
if(length == 0) return(subList);

while(offset-- && list != nilCell)
	list = list->next;

if(list == nilCell) return(subList);

cell = copyCell(list);
subList->contents = (UINT)cell;
--length;
while(length--) 
	{
	list = list->next;
	if(list == nilCell) break;
	cell->next = copyCell(list);
	cell = cell->next;
	}

return(subList);
}
Exemple #8
0
int skill_limit(faction * f, skill_t sk)
{
    int m = INT_MAX;
    int al = allied_skilllimit(f, sk);
    if (al > 0) {
        if (sk != SK_ALCHEMY && sk != SK_MAGIC)
            return INT_MAX;
        if (f_get_alliance(f)) {
            int sc, fl, ac = listlen(f->alliance->members);   /* number of factions */

            assert(ac > 0);
            fl = (al + ac - 1) / ac;      /* faction limit, rounded up */
            /* the faction limit may not be achievable because it would break the alliance-limit */
            sc = al - allied_skillcount(f, sk);
            if (sc <= 0)
                return 0;
            return fl;
        }
    }
    if (sk == SK_MAGIC) {
        m = max_magicians(f);
    }
    else if (sk == SK_ALCHEMY) {
        m = config_get_int("rules.maxskills.alchemy", 3);
    }
    return m;
}
Exemple #9
0
CELL * p_length(CELL * params)
{
size_t length;
SYMBOL * symbol;

params = evaluateExpression(params);
length = 0;
switch(params->type)
	{
	case CELL_LONG:
		length = sizeof(UINT); break;
#ifndef NEWLISP64
	case CELL_INT64:
		length = sizeof(INT64); break;
#endif
	case CELL_FLOAT:
		length = sizeof(double); break;
	case CELL_STRING:
		length = params->aux - 1; break;
	case CELL_CONTEXT:
		symbol = translateCreateSymbol( ((SYMBOL*)params->contents)->name, CELL_NIL,
			(SYMBOL*)params->contents, TRUE);
		params = (CELL *)symbol->contents;
		if(params->type == CELL_STRING)
			length = params->aux - 1;
		else if(isList(params->type))
			length = listlen((CELL *)params->contents);
		break;
	case CELL_SYMBOL:
		symbol = (SYMBOL *)params->contents;
		length = strlen(symbol->name);
		break;
	case CELL_DYN_SYMBOL:
		length = strlen((char *)params->contents);
		break;
	case CELL_EXPRESSION:
	case CELL_LAMBDA:
	case CELL_MACRO:
	        length = listlen((CELL *)params->contents);
		break;
	case CELL_ARRAY:
		length = (params->aux - 1) / sizeof(UINT);
	default:
		break;
	}
return(stuffInteger(length));
}
static void dbg_msg(const char *action, HWND hwnd, UINT msg)
{
    char buffer[100];
    struct MsgMap *mm = (struct MsgMap *)assoc(msgs, (void*)msg);
    if (0 == GetClassName(hwnd, buffer, sizeof buffer))
        strcpy(buffer, "(invalid)");
    dbg_printf("%s: %s %s (%d/%d)",
        action,
        buffer,
        bb_str(msg, -1, -1),
        listlen(msgs), mm ? mm->count : 0
        );
}
Exemple #11
0
Errcode save_tween(char *name, Tween_state *ts)
{
	Errcode err;
	XFILE *f;
	Errcode cerr;
	Tween_file_header tfh;
	Tween_link *link, *next;

	err = xffopen(name, &f, XWRITEONLY);
	if (err < Success)
		return err;

	clear_struct(&tfh);
	tfh.magic = TWEEN_MAGIC;
	tfh.tcount = 2;
	tfh.link_count = listlen(&ts->links);

	err = xffwrite(f, &tfh, sizeof(tfh));
	if (err < Success)
		goto cleanup;

	for (link = (Tween_link *)(ts->links.head);
			NULL != (next = (Tween_link *)(link->node.next));
			link = next) {
		err = xffwrite(f, &link->start, 2*sizeof(link->start));
		if (err < Success)
			goto cleanup;
	}

	err = s_poly(f, &ts->p0);
	if (err < Success)
		goto cleanup;

	err = s_poly(f, &ts->p1);
	if (err < Success)
		goto cleanup;

cleanup:
	cerr = xffclose(&f);
	if (cerr < Success) { /* return primary error, not close error */
		if (err >= Success) /* but if close is 1st error return it... */
			err = cerr;
	}

	if (err < Success)
		pj_delete(name);
	return err;
}
Exemple #12
0
int 
listAllOrgs (char *cstr, struct namelist **olistp)
{
	int ret;

	sarg = * fillMostOrgSearchArgs(cstr, SRA_ONELEVEL);
	makeAllOrgFilter(&sarg.sra_filter);
	ret = makeListOrganisations(olistp);
	if (ret != OK)
		logListSuccess(LIST_ERROR, "org", 0);
	else
		logListSuccess(LIST_OK, "org", listlen(*olistp));
	freeOrgSearchArgs();
	alarmCleanUp();
	return ret;
}
Exemple #13
0
static enum msgtype_action get_msgtype_action(enum msgtype_action current)
{
    struct nh_menuitem items[] = {
	{MSGTYPE_DEFAULT + 1,	MI_NORMAL, "DEFAULT", 'd'},
	{MSGTYPE_MORE + 1,	MI_NORMAL, "MORE", 'm'},
	{MSGTYPE_NO_REPEAT + 1,	MI_NORMAL, "NO REPEAT", 'r'},
	{MSGTYPE_HIDE + 1,	MI_NORMAL, "HIDE", 'h'},
    };
    int n, selected[1];
    char query[QBUFSZ];
    sprintf(query, "Message type action: (currently %s)",
	    msgtype_action_string(current));
    n = curses_display_menu(items, listlen(items), query, PICK_ONE, selected);
    if (n <= 0)
	return current;
    return selected[0] - 1;
}
Exemple #14
0
void NEWpreprocessfma(Sfma *f,int qdepth) {
  Sfmalist *l;
  switch(Sfmatypeof(f)) {
  case STRUE:
  case SFALSE:
    break;
  case Spatom: 
  case Snatom: 
    NEWpreprocessatom(f->a,qdepth);
    break;
  case Sdisj:
  case Sconj:
#ifdef CFMA
    f->cnt = listlen(f->juncts);
#endif
    l = f->juncts;
    while(l != NULL) {
      NEWpreprocessfma(l->hd,qdepth);
      l = l->tl;
    }
    break;
  case Sforall:
  case Sforsome:
    if(f->ss->tl) { /* Split multiple quantification. */
      Sfma *f1 = (Sfma*)malloc(sizeof(Sfma));
      f1->t = f->t;
      f1->ss = f->ss->tl;
      f1->f = f->f;

      f->ss->tl = NULL;
      f->f = f1;
    }
    scope[qdepth] = f->ss->v;
#ifdef DEBUG
    printf("scope[%i] = %s\n",qdepth,symbol(f->ss->v));
#endif
    f->ss->v = -1-qdepth;
    NEWpreprocessfma(f->f,qdepth+1);
    break;
  case Seq:
  case Sneq:
    if(isvar(f->p1)) f->p1 = NEWparamindex(f->p1,qdepth);
    if(isvar(f->p2)) f->p2 = NEWparamindex(f->p2,qdepth);
    break;
  }
}
expr *
makearray(expr e)
{
	esp *epp, ep = e;
	int i, size = listlen(e);
	
	if(size < 0) {
		printf("::Bad list structure\n");
		exit(0);
	}
	epp = malloc(size * sizeof (struct expression *));
	
	for(i=size-1; i>=0; i--) {
		epp[i] = ep->values[0].ep;
		ep = ep->values[1].ep;
	}

	return (expr *)epp;
}
Exemple #16
0
CELL * p_chop(CELL * params)
{
size_t number = 1;
size_t length = 0;
CELL * next;
#ifdef SUPPORT_UTF8
char * ptr;
#endif

next = getEvalDefault(params, &params);

if(next != nilCell)
	getInteger(next, (UINT *)&number);

if(params->type == CELL_STRING)
	{
#ifndef SUPPORT_UTF8
	length = params->aux - 1;
	if(number > length) number = length;
	length = length - number;
	return stuffStringN((char *)params->contents, length);
#else
	length = utf8_wlen((char *)params->contents);
	if(number > length) number = length;
	length = length - number;
	ptr = (char *)params->contents;
	while(length--)
		ptr += utf8_1st_len(ptr);
	return stuffStringN((char *)params->contents, ptr - (char *)params->contents);
#endif
	}

if(!isList(params->type))
    return(errorProc(ERR_LIST_OR_STRING_EXPECTED));	

length = listlen((CELL *)params->contents);
if(number > length) number = length;

return(sublist((CELL *)params->contents, 0, length - number));
}
Exemple #17
0
extern List *flatten(List *s) {
	List *r;
	size_t step;
	char *f;
	if (s == NULL || s->n == NULL)
		return s;
	r = nnew(List);
	f = r->w = nalloc(listlen(s) + 1);
	r->m = NULL; /* flattened lists come from variables, so no meta */
	r->n = NULL;
	strcpy(f, s->w);
	f += strlen(s->w);
	do {
		*f++ = ' ';
		s = s->n;
		step = strlen(s->w);
		memcpy(f, s->w, step);
		f += step;
	} while (s->n != NULL);
	*f = '\0';
	return r;
}
Exemple #18
0
static void msgtype_help(void)
{
    struct nh_menuitem items[] = {
	{0, MI_TEXT, "消息类型能让你将某些消息在游戏中以不同的方式"},
	{0, MI_TEXT, "显示出来,像暂停等待输入 --More--,"},
	{0, MI_TEXT, "重复崩溃的消息或者隐藏的消息入口。"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "一个匹配的消息可能的动作:"},
	{0, MI_TEXT, "    DEFAULT    视为一条普通的消息"},
	{0, MI_TEXT, "    MORE       在这条消息之后用 --More-- 暂停"},
	{0, MI_TEXT, "    NO REPEAT  隐藏这条消息的重复部分"},
	{0, MI_TEXT, "    HIDE       完全隐藏这条消息"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "被匹配的消息的排序模式:"},
	{0, MI_TEXT, "    ?                    匹配任何单个字符"},
	{0, MI_TEXT, "    *                    匹配任何长度的字符串"},
	{0, MI_TEXT, "    所有其他的字符匹配它自己"},
	{0, MI_TEXT, ""},
	{0, MI_TEXT, "选择一个已有的项来编辑,重排或者删除它。"},
    };
    curses_display_menu(items, listlen(items), "消息类型帮助:",
			PICK_NONE, NULL);
}
Exemple #19
0
CELL * p_select(CELL * params)
{
size_t n = 0, idx  = 0; 
ssize_t index;
CELL * list, * cell;
CELL * result = NULL;
CELL * head;
int evalFlag = TRUE;
char * str, * newStr;
#ifdef SUPPORT_UTF8
int * wstr;
int * wnewStr;
size_t len;
#endif

params = getEvalDefault(params, &head);
cell = evaluateExpression(params);
if(isList(cell->type))
	{
	evalFlag = FALSE;
	cell = params = (CELL *)cell->contents;
	}

if(head->type == CELL_STRING)
	{
	if((n = listlen(params)) == 0) return(stuffString(""));
	
	str = (char *)head->contents;
#ifndef SUPPORT_UTF8
	newStr = (char *)allocMemory(n + 1);
	idx = 0;
	while(params->type != CELL_NIL)
		{
		if(idx == 0)
			{
			getIntegerExt(cell, (UINT *)&index, FALSE);
			params = params->next;
			}
		else
			params = getIntegerExt(params, (UINT *)&index, evalFlag);
		index = adjustNegativeIndex(index, head->aux -1);
		*(newStr + idx++) = *(str + index);
		}
	*(newStr + n) = 0;
#else
	wstr = allocMemory(head->aux * sizeof(int));
	len = utf8_wstr(wstr, str, head->aux - 1);
	wnewStr = allocMemory((n + 1) * sizeof(int));
	idx = 0;
	while(params->type != CELL_NIL)
		{
		if(idx == 0)
			{
			getIntegerExt(cell, (UINT *)&index, FALSE);
			params = params->next;
			}
		else
			params = getIntegerExt(params, (UINT *)&index, evalFlag);
		index = adjustNegativeIndex(index, len);
		*(wnewStr + idx++) = *(wstr + index);
		}
	*(wnewStr + n) = 0;
	newStr = allocMemory(UTF8_MAX_BYTES * n + 1);
	n = wstr_utf8(newStr, wnewStr, UTF8_MAX_BYTES * n);
	newStr = reallocMemory(newStr, n + 1);
	free(wstr); free(wnewStr);
#endif
	result = getCell(CELL_STRING);
	result->aux = n + 1;
	result->contents = (UINT)newStr;	
	return(result);
	}

if(!isList(head->type))
	return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, head));
head = (CELL *)head->contents;
list = head;
n = 0;
while(params->type != CELL_NIL)
	{
	if(n++ == 0)
		{
		getIntegerExt(cell, (UINT *)&index, FALSE);
		params = params->next;
		}
	else
		params = getIntegerExt(params, (UINT *)&index, evalFlag);
	if(index < 0) index = convertNegativeOffset(index, head);
	if(index < idx) list = head, idx = 0;
	while(idx < index  && list != nilCell) list = list->next, idx++; 
	if(list == nilCell) 
		errorProc(ERR_LIST_INDEX_OUTOF_BOUNDS);
	if(result == NULL)
		{
		result = getCell(CELL_EXPRESSION);
		cell = copyCell(list);
		result->contents = (UINT)cell;
		}
	else
		{
		cell->next = copyCell(list);
		cell = cell->next;
		}
	}

return((result == NULL) ? getCell(CELL_EXPRESSION) : result);
}	
Exemple #20
0
int get_username() {

	struct namelist * clp  = NULLLIST;
	struct namelist * olp  = NULLLIST;
	struct namelist * oulp = NULLLIST;
	struct namelist * plp  = NULLLIST;

	FILE * dn_file;

	int noCos;
	int noOrgs;
	int noOUs;
	int noPersons;
	int objectType;
	int status;
	void de_exit();
	char * add_org_ids;
	char * already_in;
	char * confirm_out;
	char * cp;
	char * full_c;
	char * mapCoName();
	char * str;
	char * tmp_search;
	char addthisorg[LINESIZE];
	char buffer[LINESIZE];
	char posdit_user[LINESIZE];
	char username_save[LINESIZE];
	char save_addorg_posdit[LINESIZE];
	extern char have_department[];
	extern char just_dn[];
	void searchFail();
	void onint1();
	void exit();
	Attr_Sequence at;

	add_org_ids = malloc(LINESIZE);
	already_in	= malloc(LINESIZE);
	confirm_out = malloc(LINESIZE);
	cp		= malloc(LINESIZE);
	full_c	= malloc(LINESIZE);
	str         = malloc(LINESIZE);
	tmp_search	= malloc(LINESIZE);
	orgEntered  = FALSE;
	tmp_org_found = FALSE;

	 printf(enter_country);

	 strcpy(username_save, username);

prompt_country:
	enterString(COUNTRY, co, clp);
	if (strlen(co) == 0) {
		if (!(strcmp(default_country, ""))) {
			 printf("%s %s %s\n", reenter_c, quit_String, to_quit);
			goto prompt_country;
		} else {
			 strcpy(co, default_country);
		}
	} else if (!(strcmp(co, quit_String))) {
		de_prompt_yesno(ask_ifout, confirm_out, no_string);
		if (!(strcmp(confirm_out, yes_string))) {
			de_exit(-1);
		} else {
			highNumber = 0;
			goto prompt_country;
		}
	}

	if (listCos(co, &clp) != OK) {
		 searchFail(co);
		 de_exit(-1);
	}
	noCos = listlen(clp);
	if (noCos <= 0) {
		 printf("%s `%s' \n\n", no_cMatch, co);
		goto prompt_country;
	} else if (noCos == 1) {
		 sprintf(posdit_user, "@%s", clp->name);
		str = copy_string(lastComponent(clp->name, COUNTRY));
		 strcpy(default_country, str);
		 sprintf(full_c, "%s -- %s", default_country, mapCoName(default_country));
		 printf("\n%s\n", full_c);
		for (at = clp->ats; at != NULLATTR; at = at->attr_link) {
			if (strcmp(attr2name(at->attr_type, OIDPART), "masterDSA") == 0) {
				quipuMastersCo = TRUE;
				break;
			}
		}
		highNumber = 0;
		pagerOn(NUMBER_NOT_ALLOWED);
	} else {
		 printf(got_match);
		 printf(type_number);
		pagerOn(NUMBER_ALLOWED);
		printListCos(clp);
		goto prompt_country;
	}
prompt_org:
	 printf("\n");
	enterString(ORG, org, olp);
	if (strlen(org) == 0) {
		if (!(strcmp(default_organisation, ""))) {
			if ((strcmp(org_compel, no_string))) {
				 printf("%s %s %s\n", enter_org, quit_String, to_quit);
				goto prompt_org;
			} else {
				goto prompt_person;
			}
		} else {
			 strcpy(org, default_organisation);
		}
	} else {
		if (!(strcmp(org, quit_String))) {
			de_prompt_yesno(ask_ifout, confirm_out, no_string);
			if (!(strcmp(confirm_out, yes_string))) {
				de_exit(-1);
			} else {
				highNumber = 0;
				pagerOn(NUMBER_NOT_ALLOWED);
				goto prompt_country;
			}
		}
	}
	if (listOrgs(posdit_user, org, &olp) != OK) {
		 searchFail(org);
		 de_exit(-1);
	}
	noOrgs = listlen(olp);
	if (noOrgs <= 0) {
		 printf("%s `%s' \n\n", no_orgMatch, org);
		if (!(strcmp(addorg, yes_string))) {
			 printf("%s   %s", srch_newOrg, please_wait);
			 fflush(stdout);
			 sprintf(save_addorg_posdit, "%s", addorg_posdit);
			 sprintf(addorg_posdit, "%s@%s", addorg_posdit, clp->name);
			if (listOrgs(addorg_posdit, org, &olp) != OK) {
				 printf("%s `%s'\n", unbl_newOrgC, full_c);
				 printf(cntct_hlpdsk);
				de_exit(-1);
			} else {
				 printf(done);
			}
			noOrgs = listlen(olp);
			if ( noOrgs <= 0 ) {
				 sprintf(addthisorg, "%s`%s'?", ask_ifaddorg, org);
				 printf("\n%s `%s' \n\n", no_orgMatch, org);
				de_prompt_yesno(addthisorg, add_org_ids, no_string);
				if (!(strcmp(add_org_ids, yes_string))) {
					displayFile("neworg_confirm", FALSE);
					 sprintf(posdit, "%s", addorg_posdit);
prompt_name_org:
					 sprintf(buffer, newOrgName1);
					 printf(buffer);
					 sprintf(buffer, "%s %s %s\n[%s]  : ", newOrgName2,
								   quit_String, to_quit, org);
					 printf(buffer);
					if (gets(cp) == NULLCP) {
						/* behave as for an interrupt */
						clearerr(stdin);
						onint1();
					}
					if (!(strcmp(cp, quit_String))) {
						de_exit(-1);
					} else if (strlen(cp) > 0) {
						 sprintf(org, "%s", cp);
						 printf("%s   ", check_notAlrIn);
						 fflush(stdout);
						 sprintf(addorg_posdit, "%s@%s", save_addorg_posdit, clp->name);
						if (listOrgs(addorg_posdit, org, &olp) != OK) {
							 printf("%s `%s'\n", unbl_newOrgC, full_c);
							 printf(cntct_hlpdsk);
							de_exit(-1);
						} else {
							 printf(done);
						}
						noOrgs = listlen(olp);
						if ( noOrgs <= 0 ) {
							/* Everything OK */
						} else {
							 printf("\n");
							printListOrgs(org, olp);
							de_prompt_yesno(ask_ifNotAlrIn, already_in, no_string);
							if (!strcmp(already_in, no_string)) {
								freeOrgs(&olp);
								goto prompt_org;
							}
						}
					}
					status = dm_Add_org();
					if (status != OK) {
						goto prompt_name_org;
					}
					tmp_org = TRUE;
					de_prompt_yesno(ask_ifaddent, add_entries, yes_string);
					if (!(strcmp(add_entries, yes_string))) {
						 sprintf(change_posdit, "%s", no_string);
						 sprintf(change_posdn, "%s", no_string);
						 sprintf(username, "%s@cn=%s", posdit, dir_Mngr);
						orgEntered = TRUE;
						return OK;
					} else {
						 displayFile("neworg_added", FALSE);
						 de_exit(-1);
					}
				} else {
					 sprintf(addorg_posdit, "%s", save_addorg_posdit);
					goto prompt_org;
				}
			} else if (noOrgs == 1) {
				str = copy_string(lastComponent(olp->name, ORG));
				 sprintf(default_organisation, str);
				 printf("\n%s\n", default_organisation);
				 sprintf(posdit_user, "%s", olp->name);
				 sprintf(org, "%s", str);
				orgEntered = TRUE;
				 sprintf(posdit, "%s", addorg_posdit);
				 sprintf(posdit, "%s@o=%s", posdit, str);
				 sprintf(change_posdit, "%s", no_string);
				 sprintf(change_posdn, "%s", no_string);
				 sprintf(search_mgr, "%s", yes_string);
				tmp_org = TRUE;
				 sprintf(add_entries, "%s", yes_string);
				highNumber = 0;
				pagerOn(NUMBER_NOT_ALLOWED);
				freeOrgs(&olp);
				tmp_org_found = TRUE;
				orgEntered = TRUE;
				goto prompt_person;
			} else {
				 printf(got_match);
				 printf(type_number);
				pagerOn(NUMBER_ALLOWED);
				printListOrgs(org, olp);
				goto prompt_org;
			}
		} else {
			goto prompt_org;
		}
	} else if (noOrgs == 1) {
		 sprintf(posdit_user, "@%s", olp->name);
		str = copy_string(lastComponent(olp->name, ORG));
		 sprintf(default_organisation, str);
		 printf("\n%s\n", default_organisation);
		orgEntered = TRUE;
		highNumber = 0;
		pagerOn(NUMBER_NOT_ALLOWED);
	} else {
		 printf(got_match);
		 printf(type_number);
		pagerOn(NUMBER_ALLOWED);
		printListOrgs(org, olp);
		goto prompt_org;
	}
	pagerOn(NUMBER_NOT_ALLOWED);

	if (!(strcmp(have_department, no_string))) {
		goto prompt_person;
	} else if ((strcmp(have_department, yes_string))) {
		 sprintf(ou, "%s", "*");
		if (listOUs(posdit_user, ou, &oulp) != OK) {
			 searchFail(ou);
			 de_exit(-1);
		}
		highNumber = 0;  /* disable entering a number, without displaying list */
		noOUs = listlen(oulp);
		if (noOUs <= 0) {
			goto prompt_person;
		} else {
			/*             sprintf(have_department, "%s", yes_string); */
			 sprintf(change_posdit, "%s", yes_string);
		}
	}
prompt_ou:
	 printf("\n");
	enterString(ORGUNIT, ou, oulp);
	if (strlen(ou) == 0) {
		if (!(strcmp(default_department, ""))) {
			goto prompt_person;
		} else {
			 strcpy(ou, default_department);
		}
	} else {
		if (!(strcmp(ou, quit_String))) {
			highNumber = 0;
			pagerOn(NUMBER_NOT_ALLOWED);
			goto prompt_country;
		}
	}
	if (listOUs(posdit_user, ou, &oulp) != OK) {
		 searchFail(ou);
		 de_exit(-1);
	}
	noOUs = listlen(oulp);
	if (noOUs <= 0) {
		 printf("%s `%s' \n\n", no_ouMatch, ou);
		goto prompt_ou;
	} else if (noOUs == 1) {
		 sprintf(posdit_user, "@%s", oulp->name);
		str = copy_string(lastComponent(oulp->name, ORGUNIT));
		 strcpy(default_department, str);
		 printf("\n%s\n", default_department);
		highNumber = 0;
		pagerOn(NUMBER_NOT_ALLOWED);
	} else {
		 printf(got_match);
		 printf(type_number);
		pagerOn(NUMBER_ALLOWED);
		printListOUs(ou, oulp);
		goto prompt_ou;
	}

prompt_person:
	/* Copy to posdit, if not defined */

	if (strlen(posdit) <= 0) {
		 sprintf(posdit, "%s", posdit_user);
		 determine_posdit(&objectType);
		posdit_oc = objectType;
	}
	if (!(strcmp(search_mgr, no_string))) {
		goto prompt_individual;
	}

	 sprintf(person, dir_Mngr);
	 sprintf(tmp_search, "%s@cn=%s", posdit_user,person);
	if (listExactPRRcn(tmp_search, &plp) != OK) {
		 searchFail(person);
		 de_exit(-1);
	}
	noPersons = listlen(plp);
	if (noPersons <= 0) {
		goto prompt_individual;
	} else if (noPersons == 1) {
		 sprintf(username, "@%s", plp->name);
		str = copy_string(lastComponent(plp->name, PERSON));
		free(confirm_out);
		free(full_c);
		free(str);
		highNumber = 0;
		if (!(strcmp(just_dn, yes_string))) {
			dn_file = fopen("/tmp/dn_user", "w");
			 fprintf(dn_file, username);
			 de_unbind();
			 fclose(dn_file);
			exit(0);
		}
		return OK;
	} else {
		 printf(got_match);
		 printf(type_number);
		pagerOn(NUMBER_ALLOWED);
		printListPRRs(person, plp, PERSON, FALSE);
		goto prompt_person;
	}


prompt_individual:
	enterString(USER, person, plp);
	if (strlen(person) == 0) {
		if (!(strcmp(default_person, ""))) {
			 printf("%s %s %s\n", enter_pName, quit_String, to_quit);
			goto prompt_individual;
		} else {
			 strcpy(person, default_person);
		}
	} else if (!(strcmp(person, quit_String))) {
		de_prompt_yesno(ask_ifout, confirm_out, no_string);
		if (!(strcmp(confirm_out, yes_string))) {
			de_exit(-1);
		} else {
			highNumber = 0;
			goto prompt_country;
		}
	}
	if (orgEntered == FALSE) {
		 sprintf(tmp_search, "%s@cn=%s", posdit_user,person);
		if (listExactPRRcn(tmp_search, &plp) != OK) {
			 searchFail(person);
			 de_exit(-1);
		}
	} else {
		if (listPRRs(posdit_user, person, &plp) != OK) {
			 searchFail(person);
			 de_exit(-1);
		}
	}
	noPersons = listlen(plp);
	if (noPersons <= 0) {
		 printf("%s `%s' \n\n", no_pMatch, person);
		goto prompt_individual;
	} else if (noPersons == 1) {
		 sprintf(username, "@%s", plp->name);
		str = copy_string(lastComponent(plp->name, PERSON));
		highNumber = 0;
		if (!(strcmp(just_dn, yes_string))) {
			dn_file = fopen("/tmp/dn_user", "w");
			 fprintf(dn_file, username);
			 de_unbind();
			 fclose(dn_file);
			 exit(0);
		}
	} else {
		 printf(got_match);
		 printf(type_number);
		pagerOn(NUMBER_ALLOWED);
		printListPRRs(person, plp, PERSON, FALSE);
		goto prompt_individual;
	}
	 printf(user_identified);
	 display_posdit(strlen(user_identified), username);
	free(confirm_out);
	free(full_c);
	free(str);
	free(already_in);
	return OK;
}
Exemple #21
0
summary *make_summary(void)
{
    faction *f;
    region *r;
    unit *u;
    summary *s = calloc(1, sizeof(summary));
    const struct resource_type *rhorse = get_resourcetype(R_HORSE);

  for (f = factions; f; f = f->next) {
    const struct locale *lang = f->locale;
    struct language *plang = s->languages;
    while (plang && plang->locale != lang)
      plang = plang->next;
    if (!plang) {
      plang = calloc(sizeof(struct language), 1);
      plang->next = s->languages;
      s->languages = plang;
      plang->locale = lang;
    }
    ++plang->number;
    f->nregions = 0;
    f->num_total = 0;
    f->money = 0;
    if (f->alive && f->units) {
      s->factions++;
      /* Problem mit Monsterpartei ... */
      if (!is_monsters(f)) {
        s->factionrace[old_race(f->race)]++;
      }
    }
  }

  /* count everything */

  for (r = regions; r; r = r->next) {
    s->pferde += rhorses(r);
    s->schiffe += listlen(r->ships);
    s->gebaeude += listlen(r->buildings);
    if (!fval(r->terrain, SEA_REGION)) {
      s->landregionen++;
      if (r->units) {
        s->landregionen_mit_spielern++;
      }
      if (fval(r, RF_ORCIFIED)) {
        s->orkifizierte_regionen++;
      }
      if (r->terrain == newterrain(T_VOLCANO)) {
        s->inactive_volcanos++;
      } else if (r->terrain == newterrain(T_VOLCANO_SMOKING)) {
        s->active_volcanos++;
      }
    }
    if (r->units) {
      s->regionen_mit_spielern++;
    }
    if (rpeasants(r) || r->units) {
      s->inhabitedregions++;
      s->peasants += rpeasants(r);
      s->peasantmoney += rmoney(r);

      /* Einheiten Info. nregions darf nur einmal pro Partei
       * incrementiert werden. */

      for (u = r->units; u; u = u->next)
        freset(u->faction, FFL_SELECT);
      for (u = r->units; u; u = u->next) {
        f = u->faction;
        if (!is_monsters(u->faction)) {
          skill *sv;
          item *itm;

          s->nunits++;
          s->playerpop += u->number;
          if (u->flags & UFL_HERO) {
            s->heroes += u->number;
          }
          s->spielerpferde += i_get(u->items, rhorse->itype);
          s->playermoney += get_money(u);
          s->armed_men += armedmen(u, true);
          for (itm = u->items; itm; itm = itm->next) {
            if (itm->type->rtype->wtype) {
              s->waffen += itm->number;
            }
            if (itm->type->rtype->atype) {
              s->ruestungen += itm->number;
            }
          }

          s->spielerpferde += i_get(u->items, rhorse->itype);

          for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
            skill_t sk = sv->id;
            int aktskill = eff_skill(u, sk, r);
            if (aktskill > s->maxskill)
              s->maxskill = aktskill;
          }
          if (!fval(f, FFL_SELECT)) {
            f->nregions++;
            fset(f, FFL_SELECT);
          }
        }

        f->num_total += u->number;
        f->money += get_money(u);
        s->poprace[old_race(u_race(u))] += u->number;
      }
    }
  }

  return s;
}
Exemple #22
0
void report_summary(summary * s, summary * o, bool full)
{
  FILE *F = NULL;
  int i, newplayers = 0;
  faction *f;
  char zText[MAX_PATH];

  if (full) {
    sprintf(zText, "%s/parteien.full", basepath());
  } else {
    sprintf(zText, "%s/parteien", basepath());
  }
  F = fopen(zText, "w");
  if (!F) {
    perror(zText);
    return;
  }
#ifdef SUMMARY_BOM
  else {
    const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 };
    fwrite(utf8_bom, 1, 3, F);
  }
#endif
  log_info("writing summary to file: parteien.\n");
  fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale));
  fprintf(F, "Auswertung Nr:         %d\n\n", turn);
  fprintf(F, "Parteien:              %s\n", pcomp(s->factions, o->factions));
  fprintf(F, "Einheiten:             %s\n", pcomp(s->nunits, o->nunits));
  fprintf(F, "Spielerpopulation:     %s\n", pcomp(s->playerpop, o->playerpop));
  fprintf(F, " davon bewaffnet:      %s\n", pcomp(s->armed_men, o->armed_men));
  fprintf(F, " Helden:               %s\n", pcomp(s->heroes, o->heroes));

  if (full) {
    fprintf(F, "Regionen:              %d\n", listlen(regions));
    fprintf(F, "Bewohnte Regionen:     %d\n", s->inhabitedregions);
    fprintf(F, "Landregionen:          %d\n", s->landregionen);
    fprintf(F, "Spielerregionen:       %d\n", s->regionen_mit_spielern);
    fprintf(F, "Landspielerregionen:   %d\n", s->landregionen_mit_spielern);
    fprintf(F, "Orkifizierte Regionen: %d\n", s->orkifizierte_regionen);
    fprintf(F, "Inaktive Vulkane:      %d\n", s->inactive_volcanos);
    fprintf(F, "Aktive Vulkane:        %d\n\n", s->active_volcanos);
  }

  for (i = 0; i < MAXRACES; i++) {
      if (i != RC_TEMPLATE && i != RC_CLONE && s->factionrace[i]) {
          const race *rc = get_race(i);
          if (rc && playerrace(rc)) {
              fprintf(F, "%13s%s: %s\n", LOC(default_locale, rc_name(rc, NAME_CATEGORY)),
                  LOC(default_locale, "stat_tribe_p"), pcomp(s->factionrace[i],
                  o->factionrace[i]));
          }
      }
  }

  if (full) {
    fprintf(F, "\n");
    {
      struct language *plang = s->languages;
      while (plang != NULL) {
        struct language *olang = o->languages;
        int nold = 0;
        while (olang && olang->locale != plang->locale)
          olang = olang->next;
        if (olang)
          nold = olang->number;
        fprintf(F, "Sprache %12s: %s\n", locale_name(plang->locale),
          rcomp(plang->number, nold));
        plang = plang->next;
      }
    }
  }

  fprintf(F, "\n");
  if (full) {
    for (i = 0; i < MAXRACES; i++) {
      if (s->poprace[i]) {
          const race *rc = get_race(i);
          fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)),
          rcomp(s->poprace[i], o->poprace[i]));
      }
    }
  } else {
      for (i = 0; i < MAXRACES; i++) {
          if (i != RC_TEMPLATE && i != RC_CLONE && s->poprace[i]) {
              const race *rc = get_race(i);
              if (playerrace(rc)) {
                  fprintf(F, "%20s: %s\n", LOC(default_locale, rc_name(rc, NAME_PLURAL)),
                      rcomp(s->poprace[i], o->poprace[i]));
              }
          }
      }
    }

  if (full) {
    fprintf(F, "\nWaffen:               %s\n", pcomp(s->waffen, o->waffen));
    fprintf(F, "Ruestungen:           %s\n",
      pcomp(s->ruestungen, o->ruestungen));
    fprintf(F, "ungezaehmte Pferde:   %s\n", pcomp(s->pferde, o->pferde));
    fprintf(F, "gezaehmte Pferde:     %s\n",
      pcomp(s->spielerpferde, o->spielerpferde));
    fprintf(F, "Schiffe:              %s\n", pcomp(s->schiffe, o->schiffe));
    fprintf(F, "Gebaeude:             %s\n", pcomp(s->gebaeude, o->gebaeude));

    fprintf(F, "\nBauernpopulation:     %s\n", pcomp(s->peasants, o->peasants));

    fprintf(F, "Population gesamt:    %d\n\n", s->playerpop + s->peasants);

    fprintf(F, "Reichtum Spieler:     %s Silber\n",
      pcomp(s->playermoney, o->playermoney));
    fprintf(F, "Reichtum Bauern:      %s Silber\n",
      pcomp(s->peasantmoney, o->peasantmoney));
    fprintf(F, "Reichtum gesamt:      %s Silber\n\n",
      pcomp(s->playermoney + s->peasantmoney,
        o->playermoney + o->peasantmoney));
  }

  fprintf(F, "\n\n");

  newplayers = update_nmrs();

  for (i = 0; i <= NMRTimeout(); ++i) {
    if (i == NMRTimeout()) {
      fprintf(F, "+ NMR:\t\t %d\n", nmrs[i]);
    } else {
      fprintf(F, "%d NMR:\t\t %d\n", i, nmrs[i]);
    }
  }
  if (age) {
    if (age[2] != 0) {
      fprintf(F, "Erstabgaben:\t %d%%\n", 100 - (dropouts[0] * 100 / age[2]));
    }
    if (age[3] != 0) {
      fprintf(F, "Zweitabgaben:\t %d%%\n", 100 - (dropouts[1] * 100 / age[3]));
    }
  }
  fprintf(F, "Neue Spieler:\t %d\n", newplayers);

  if (full) {
    if (factions)
      fprintf(F, "\nParteien:\n\n");

    for (f = factions; f; f = f->next) {
      out_faction(F, f);
    }

    if (NMRTimeout() && full) {
      fprintf(F, "\n\nFactions with NMRs:\n");
      for (i = NMRTimeout(); i > 0; --i) {
        for (f = factions; f; f = f->next) {
          if (i == NMRTimeout()) {
            if (turn - f->lastorders >= i) {
              out_faction(F, f);
            }
          } else {
            if (turn - f->lastorders == i) {
              out_faction(F, f);
            }
          }
        }
      }
    }
  }

  fclose(F);

  if (full) {
    log_info("writing date & turn\n");
    writeturn();
  }
  free(nmrs);
  nmrs = NULL;
}
Exemple #23
0
# define should_write_config() (1)
#endif


/*----------------------------------------------------------------------------*/

#define listlen(list) (sizeof(list)/sizeof(list[0]))

static struct nh_listitem dungeon_name_list[] = {
    {DGN_NAME_AUTO, "auto"},
    {DGN_NAME_DLVL, "dungeon level"},
    {DGN_NAME_SHORT, "short dungeon name"},
    {DGN_NAME_FULL, "full dungeon name"},
};
static struct nh_enum_option dungeon_name_spec =
{dungeon_name_list, listlen(dungeon_name_list)};

static struct nh_listitem menu_headings_list[] = {
    {A_NORMAL, "none"},
    {A_REVERSE, "inverse"},
    {A_BOLD, "bold"},
    {A_UNDERLINE, "underline"}
};
static struct nh_enum_option menu_headings_spec =
{menu_headings_list, listlen(menu_headings_list)};

static struct nh_listitem graphics_list[] = {
    {ASCII_GRAPHICS, "plain"},
    {UNICODE_GRAPHICS, "Unicode graphics"}
};
static struct nh_enum_option graphics_spec = {graphics_list, listlen(graphics_list)};
int CreateRecentItemMenu(char *pszFileName, char *pszCommand, char *pszTitle, char *pszIcon, int nKeep, int nSort, bool bBeginEnd){
	static ItemList *KeepItemList;
	static ItemList *SortItemList;
	char szFilePath[MAX_PATH];
	char buf[MAX_PATH];
	ItemList *iln = (ItemList*)m_alloc(sizeof(ItemList));

	// make path (compliant with relative-path)
	make_bb_path(szFilePath, pszFileName);

	// Newer Item
	if (pszIcon && *pszIcon)
		_snprintf(buf, MAX_PATH, "\t[exec] (%s) {%s} <%s>", pszTitle, pszCommand, pszIcon);
	else
		_snprintf(buf, MAX_PATH, "\t[exec] (%s) {%s}", pszTitle, pszCommand);
	_strcpy(iln->szItem, buf);
	iln->nFrequency = 1;
	append_node(&KeepItemList, iln);

	int cnt_k = 0; // keep items counter
	int cnt_s = 0; // sort items counter
	if (FILE *fp = fopen(szFilePath, "r")){ // read Recent-menu
		while(fgets(buf, MAX_PATH, fp)){
			if (strstr(buf, "[end]"))
				break;
			else if (strstr(buf, "[exec]")){
				if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
				char *p0 = strchr(buf, '{'); // command
				char *p1 = strchr(buf, '}'); // end of command
				if (p0 && p1){
					UINT nFrequency = 0;
					if (char *p = strrchr(buf, '#')){
						nFrequency = atoi(p+1);
						while(*(p--) == ' '); // delete space of eol
						*p = '\0';
					}
					if (0 != strnicmp(pszCommand, p0+1 , p1 - p0 - 1)){ // ignore duplicated item
						ItemList *il = (ItemList*)m_alloc(sizeof(ItemList));
						_strcpy(il->szItem, buf);
						il->nFrequency = imin(nFrequency, UINT_MAX);
						if (cnt_k++ < nKeep - 1)
							append_node(&KeepItemList, il);
						else if (cnt_s++ < nSort)
							append_node(&SortItemList, il);
						else
							m_free(il);
					}
					else{ // if duplicate, increment freq
						iln->nFrequency += imin(nFrequency, UINT_MAX - 1);
					}
				}
			}
		}
		fclose(fp);
	}

	bool isSortList = listlen(SortItemList) != 0;
	bool isKeepList = listlen(KeepItemList) != 0;

	if (isSortList)
		SortItemList = sortlist(SortItemList);

	if (FILE *fp = fopen(szFilePath, "w")){ // write Recent-menu
		if (bBeginEnd)
			fprintf(fp, "[begin] (Recent Item)\n");

		// most recent item
		ItemList *p;
		dolist (p, KeepItemList){
			fprintf(fp, "%s #%u\n", p->szItem, p->nFrequency);
		}
		if (isKeepList && isSortList)
			fprintf(fp, "\t[separator]\n");
		dolist (p, SortItemList){
			fprintf(fp, "%s #%u\n", p->szItem, p->nFrequency);
		}
Exemple #25
0
int main(int argc, char **argv)
{
	atexit(cleanup);
	options = calloc(sizeof(struct opts_t), 1);
	tableList = calloc(sizeof(*tableList), 1);
	options->mode = -1;
	options->rating = RATING_UNDEFINED;

	if (argc < 2)
		exitmsg(1, "Try -help for usage information\n");

	parseArgs(argv + 1, options);

	if (!options->backlog_path[0])
		snprintf(options->backlog_path, 256, "%s/.backlog", getenv("HOME"));

	if (!modified && readTables(tableList, options->backlog_path))
		printf("Couldn't open '%s': %s\nYou can force the creation of this file by passing -force\n\n", options->backlog_path, strerror(errno));

	struct entry_t *entry = 0;
	struct table_t *table = 0;

	if (options->mode == RATING_UNDEFINED && !options->searchMode && !modified)
		exitmsg(1, "Must specify a mode\n");

	if (options->rating != RATING_UNDEFINED && (options->rating < -1 || options->rating > 10))
		exitmsg(1, "Rating must be in the range of -1 to 10\n");

	char *entrystr = "Entry not found\n";
	char *tablestr = "Table not found\n";
	char *err_dupe = "An entry with that name already exists in that table\n";
	char *err_dupe_table = "A table with that name already exists\n";

	char help_msg[] =
		"Available options:\n"
		" -t\n"
		"\tSwitch to table mode\n"
		" -help\n"
		"\tPrint this message\n"
		" -insert\n"
		"\tAdd entry/table\n"
		" -rm\n"
		"\tRemove entry/table\n"
		" -mv\n"
		"\tMove entry between tables\n"
		" -ls\n"
		"\tList tables, can be used with -name to print specific table\n"
		" -find\n"
		"\tSearch for entry, can be used with -name to search within table\n"
		" -rate <INT>\n"
		"\tSet rating on entry\n"
		" -rename\n"
		"\tRename entry/table\n"
		" -name <STRING>\n"
		"\tSet name\n"
		" -new <STRING>\n"
		"\tSet new name\n"
		" -src <STRING>\n"
		"\tSet source name\n"
		" -dest <STRING>\n"
		"\tSet destination name\n"
		" -roll\n"
		"\tReturn random entry\n"
		" -mal\n"
		"\tSearch MAL for entry\n"
		" -nyaa\n"
		"\tSearch Nyaa for entry\n"
		" -baka\n"
		"\tSearch BakaBT for entry (through Google)\n"
		" -anidb\n"
		"\tSearch AniDB for entry\n"
		" -force\n"
		"\tForce write-out to backlog file\n"
		" -path\n"
		"\tOverride the default backlog path (~/.backlog)\n"
		" -nobak\n"
		"\tDon't backup backlog file";

	if (options->mode == MODE_LIST) {	//List tables.
		if (options->sourceName) {
			table = bklgGetTable(tableList, options->sourceName);
			if (!table)
				exitmsg(1, tablestr);
		}
		if (table) {
			bklgPrintTable(table, stdout);
		} else {
			char buffer[32];
			struct tm *tm;
			time_t utime = time(0);

			tm = localtime(&utime);
			strftime(buffer, 32, "%d/%m/%Y\n", tm);
			puts(buffer);
			bklgPrintAllTables(tableList, stdout);
		}
	}

	else if (options->mode == MODE_ENTRY_ADD && options->tableMode) {	//Add table.
		if (!options->entryName)
			exitmsg(1, "Name required\n");

		if (bklgGetTableExact(tableList, options->entryName))
			exitmsg(1, err_dupe_table);

		puts("Added table");
		bklgTableAdd(tableList, options->entryName);
		modified = 1;
	}

	else if (options->mode == MODE_ENTRY_REMOVE && options->tableMode) {	//Remove table.
		if (!options->entryName)
			exitmsg(1, "Name required\n");
		struct table_t *table = bklgGetTable(tableList, options->entryName);

		if (!table)
			exitmsg(1, tablestr);
		printf("Remove \"%s\"? [Y,n]: ", table->name);
		if (confirm()) {
			puts("Table removed");
			bklgLnodeDestroy(tableList, table->parent);
			bklgTableDestroy(table);
			modified = 1;
		}
	}

	else if (options->mode == MODE_ENTRY_ADD) {	//Add entry.
		if (!options->entryName || !options->destinationName)
			exitmsg(1, "Name and destination required, rating optional\n");

		table = bklgGetTable(tableList, options->destinationName);
		if (!table)
			exitmsg(1, tablestr);

		if (bklgGetEntryExact(table->entries, options->entryName))
			exitmsg(1, err_dupe);

		printf("Add entry to \"%s\"? [Y,n]: ", table->name);
		if (confirm()) {
			puts("Entry added");
			entry = bklgEntryAdd(table->entries, options->entryName, options->rating == -2 ? -1 : options->rating);
			modified = 1;
		}
	}

	else if (options->mode == MODE_ENTRY_REMOVE) {	//Remove entry.
		if (!options->entryName)
			exitmsg(1, "Name required, source optional\n");
		struct entry_t *entry = 0;

		if (!options->sourceName) {
			entry = bklgGetEntryAllTables(tableList, options->entryName, &table);
		} else {
			table = bklgGetTable(tableList, options->sourceName);
			if (!table)
				exitmsg(1, tablestr);
			entry = bklgGetEntry(table->entries, options->entryName);
		}
		if (!entry)
			exitmsg(1, entrystr);
		printf("Remove \"%s\" from \"%s\"? [Y,n]: ", entry->name, table->name);
		if (confirm()) {
			puts("Entry removed");
			bklgLnodeDestroy(table->entries, entry->parent);
			free(entry);
			modified = 1;
		}
	}

	else if (options->mode == MODE_ENTRY_MOVE) {	//Move entry to another table.
		if (!options->entryName || !options->destinationName)
			exitmsg(1, "Name and destination required, source optional\n");

		struct entry_t *oldEntry = 0;
		struct table_t *sourceTable = 0;

		if (!options->sourceName) {
			oldEntry = bklgGetEntryAllTables(tableList, options->entryName, &sourceTable);

		} else {
			sourceTable = bklgGetTable(tableList, options->sourceName);
			if (!sourceTable)
				exitmsg(1, "Source table not found\n");
			oldEntry = bklgGetEntry(sourceTable->entries, options->entryName);
		}
		if (!oldEntry)
			exitmsg(1, entrystr);

		struct table_t *destTable = bklgGetTable(tableList, options->destinationName);

		if (!destTable)
			exitmsg(1, "Destination table not found\n");

		if (bklgGetEntryExact(destTable->entries, oldEntry->name))
			exitmsg(1, err_dupe);

		printf("Move \"%s\" from \"%s\" to \"%s\"? [Y,n]: ", oldEntry->name, sourceTable->name, destTable->name);
		if (confirm()) {
			puts("Entry moved");
			entry = bklgEntryAdd(destTable->entries, oldEntry->name, (options->rating < -1 ? oldEntry->rating : options->rating));
			bklgLnodeDestroy(sourceTable->entries, oldEntry->parent);
			free(oldEntry);
			modified = 1;
		}
	}

	else if (options->mode == MODE_FIND) {	//Find entry.
		if (!options->entryName)
			exitmsg(1, "Name required, source optional\n");
		if (!options->sourceName) {
			entry = bklgGetEntryAllTables(tableList, options->entryName, &table);
		} else {
			table = bklgGetTable(tableList, options->sourceName);
			if (!table)
				exitmsg(1, tablestr);
			entry = bklgGetEntry(table->entries, options->entryName);
		}
		if (entry) {
			char rating[8];

			snprintf(rating, 8, "%i/10", entry->rating);
			printf("Best match:\n\tName: %s\n\tRating: %s\n\tParent table: %s\n", entry->name, entry->rating == -1 ? "none" : rating, table->name);
		} else {
			exitmsg(1, entrystr);
		}
	}

	else if (options->rating != RATING_UNDEFINED) {	//Set a rating.
		if (!options->entryName)
			exitmsg(1, "Name required, rating and source optional\n");
		if (!options->sourceName) {
			entry = bklgGetEntryAllTables(tableList, options->entryName, &table);
		} else {
			table = bklgGetTable(tableList, options->sourceName);
			if (!table)
				exitmsg(1, tablestr);
			entry = bklgGetEntry(table->entries, options->entryName);
		}
		if (!entry)
			exitmsg(1, entrystr);
		printf("Change rating of \"%s\"? [Y,n]: ", entry->name);
		if (confirm()) {
			puts("Changed rating");
			entry->rating = options->rating;
			modified = 1;
		}
	}

	else if (options->mode == MODE_ENTRY_RENAME && options->tableMode) {	//Rename table.
		if (!options->entryName || !options->entryNewName)
			exitmsg(1, "Name and new name required\n");

		table = bklgGetTable(tableList, options->entryName);
		if (!table)
			exitmsg(1, tablestr);

		if (bklgGetTableExact(tableList, options->entryNewName))
			exitmsg(1, err_dupe_table);

		printf("Rename \"%s\"? [Y,n]: ", table->name);
		if (confirm()) {
			puts("Renamed table");
			char tmp[64];
			char *tmpp = 0;

			strncpy(tmp, options->entryNewName, 64);
			tmpp = stripWhiteSpace(tmp);
			strncpy(table->name, tmpp, 64);
			modified = 1;
		}
	}

	else if (options->mode == MODE_ENTRY_RENAME) {	//Rename entry.
		if (!options->entryName || !options->entryNewName)
			exitmsg(1, "Name and new name required, source optional\n");

		if (!options->sourceName) {
			entry = bklgGetEntryAllTables(tableList, options->entryName, &table);
		} else {
			table = bklgGetTable(tableList, options->sourceName);
			if (!table)
				exitmsg(1, tablestr);
			entry = bklgGetEntry(table->entries, options->entryName);
		}

		if (!entry)
			exitmsg(1, entrystr);

		if (bklgGetEntryExact(table->entries, options->entryNewName))
			exitmsg(1, err_dupe);

		printf("Rename \"%s\"? [Y,n]: ", entry->name);
		if (confirm()) {
			puts("Renamed entry");
			char tmp[128];
			char *tmpp = 0;

			strncpy(tmp, options->entryNewName, 128);
			tmpp = stripWhiteSpace(tmp);
			strncpy(entry->name, tmpp, 128);
			modified = 1;
		}
	}

	else if (options->mode == MODE_RANDOM) {	//Choose random entry.
		if (!options->sourceName)
			exitmsg(1, "Source required\n");
		struct table_t *table = bklgGetTable(tableList, options->sourceName);

		if (!table)
			exitmsg(1, tablestr);
		srand(time(0) * getpid());
		size_t len = listlen(table->entries);
		int randomindex = rand() % len;
		struct lnode_t *current = table->entries->tail;

		for (int i = 0; i < randomindex; i++) {
			current = current->next;
		}
		entry = current->data;
		char rating[8];

		snprintf(rating, 8, "%i/10", entry->rating);
		printf("Random entry at index %i out of %zu:\n\tName: %s\n\tRating: %s\n\tParent table: %s\n", randomindex + 1, len, entry->name, entry->rating == -1 ? "none" : rating, table->name);
	}

	if (options->searchMode) {	//Search various sites for entry.
		if (!entry && !options->entryName) {
			exitmsg(1, "Name required, source optional\n");
		} else if (!entry) {
			struct table_t *table = 0;

			if (!options->sourceName) {
				entry = bklgGetEntryAllTables(tableList, options->entryName, &table);

			} else {
				if (!table) {
					table = bklgGetTable(tableList, options->sourceName);
					if (!table)
						exitmsg(1, tablestr);
				}
				entry = bklgGetEntry(table->entries, options->entryName);
			}
			if (!entry)
				exitmsg(1, entrystr);
		}
		printf("Searching web for \"%s\"\n", entry->name);
		webSearch(entry, options->searchMode);
	}

	else if (options->mode == MODE_HELP) {	//Print usage stuff.
		puts(help_msg);
	}

	if (modified) {
		if (backup) {
			char bakpath[256];

			snprintf(bakpath, 256, "%s.bak", options->backlog_path);
			if (rename(options->backlog_path, bakpath) == -1)
				exitmsg(1, "Failed to rename to '%s': %s\n", bakpath, strerror(errno));
		}
		if (writeTables(tableList, options->backlog_path))
			exitmsg(1, "Failed to open '%s' for writing: %s\n", options->backlog_path, strerror(errno));
	}
	exit(0);
}
Exemple #26
0
int de_Delete() {
	char * more;
	char * rdn;
	char * sure;
	char name[LINESIZE];

	int fillMostRmArg();
	int noEntries;
	int objectType;
	int status;

	noEntries = 0;

	more = malloc(LINESIZE);
	plp = (struct namelist *) malloc(sizeof(struct namelist));
	sure = malloc(LINESIZE);

	fillMostRmArg();

	(void) sprintf(default_person, ""); /* Clear default value */
	(void) sprintf(more, yes_string);  /* Enter loop */

	highNumber = 0;

	while (!(strcmp(more, yes_string))) {
		enterString(DELETE, person, plp);

		if (!(strcmp(person, quit_String))) {
			(void) sprintf(more, no_string);
			if (noEntries > 0) {
				freePRRs(&plp);
			}
			continue;
		}
		if (strlen(person) <= 0) {
			(void) printf("%s %s %s", enter_entry_name, quit_String, to_quit);
			continue;
		}
		(void) printf("\n");


		if (noEntries > 0) {
			freePRRs(&plp);
		}

		if (listPRRs(posdit, person, &plp) != OK) {
			searchFail(person);
			de_exit(-1);
		}

		noEntries = listlen(plp);

		if (noEntries == 0) {
			(void) printf(no_ent_found);
			freePRRs(&plp);
		} else if (noEntries == 1) {
			rdn = copy_string(lastComponent(plp->name, PERSON));
			status = get_objectClassPRR(plp, &objectType);
			if (status != OK) {
				(void) printf(no_p_rl_rm);
				continue;
			} else if (objectType == PERSON) {
				if (listPRRs(posdit, rdn, &plp) != OK) {
					searchFail(rdn);
				}
			} else if (objectType == ROLE) {
				if (listPRRRl(posdit, rdn, &plp) != OK) {
					searchFail(rdn);
				}
			} else if (objectType == ROOM) {
				if (listPRRRm(posdit, rdn, &plp) != OK) {
					searchFail(rdn);
				}
			}
			pagerOn(NUMBER_NOT_ALLOWED);
			printListPRRs(person, plp, COUNTRY, TRUE);
			highNumber = 0;
			de_prompt_yesno(sure_delete, sure, no_string);
			if (!(strcmp(sure, yes_string))) {
				/* Delete the entry */
				(void) dm_Delete_entry();
				freePRRs(&plp);
			} else {
				freePRRs(&plp);
			}
		} else {
			/* more than 1, select from list */
			pagerOn(NUMBER_ALLOWED);
			printListPRRs(name, plp, COUNTRY, FALSE);
		}
	}

	free(more);
	free(rdn);
	free(sure);
	return OK;
}
Exemple #27
0
static int change_inv_order(const char *op);
static struct nh_option_desc *new_opt_struct(void);

/* -------------------------------------------------------------------------- */

#define listlen(list) (sizeof(list)/sizeof(list[0]))

static const struct nh_listitem disclose_list[] = {
    {DISCLOSE_NO_WITHOUT_PROMPT, "no"},
    {DISCLOSE_PROMPT_DEFAULT_NO, "ask, default no"},
    {DISCLOSE_PROMPT_DEFAULT_YES, "ask, default yes"},
    {DISCLOSE_YES_WITHOUT_PROMPT, "yes"}
};
static const struct nh_enum_option disclose_spec =
{ disclose_list, listlen(disclose_list) };

static const struct nh_listitem menustyle_list[] = {
    {MENU_PARTIAL, "partial"},
    {MENU_FULL, "full"}
};
static const struct nh_enum_option menustyle_spec =
{ menustyle_list, listlen(menustyle_list) };

static const struct nh_listitem pickup_burden_list[] = {
    {UNENCUMBERED, "unencumbered"},
    {SLT_ENCUMBER, "burdened"},
    {MOD_ENCUMBER, "stressed"},
    {HVY_ENCUMBER, "strained"},
    {EXT_ENCUMBER, "overtaxed"},
    {OVERLOADED, "overloaded"}
Exemple #28
0
static void show_autopickup_menu(struct nh_option_desc *opt);



/*----------------------------------------------------------------------------*/

#define listlen(list) (sizeof(list)/sizeof(list[0]))

static struct nh_listitem menu_headings_list[] = {
    {A_NORMAL, "none"},
    {A_REVERSE, "inverse"},
    {A_BOLD, "bold"},
    {A_UNDERLINE, "underline"}
};
static struct nh_enum_option menu_headings_spec =
    { menu_headings_list, listlen(menu_headings_list) };

static struct nh_listitem palette_list[] = {
    {PALETTE_NONE,      "terminal default (may require new window)"},
    {PALETTE_DEFAULT,   "uncursed default"},
    {PALETTE_SATURATED, "saturated bold"},
    {PALETTE_TERTIARY,  "tertiary colors"},
    {PALETTE_EQUILUM,   "equiluminous"},
    {PALETTE_DKPASTELS, "dark pastels"},
    {PALETTE_TTERMINAL, "typical X11 terminal"},
    {PALETTE_LCONSOLE,  "Linux console"},
    {PALETTE_REDMOND,   "Windows console"},
    {PALETTE_ALT1,      "alternative 1"},
    {PALETTE_ALT2,      "alternative 2"},
    {PALETTE_ALT3,      "alternative 3"}
};
    TreeNode* sortedListToBST(ListNode* head) {
        int len = listlen(head);
        return createTree(head, 0, len - 1);

    }
Exemple #30
0
CELL * p_push(CELL * params)
{
CELL * newCell;
CELL * list;
CELL * cell = NULL;
CELL * listOrg;
SYMBOL * symbolRef;
int insert = 0, evalFlag = 0;
ssize_t index;

newCell = evaluateExpression(params);
params = getEvalDefault(params->next, &list);
listOrg = list;

if((symbolRef = symbolCheck))
	{
	if(isProtected(symbolCheck->flags))
		return(errorProcExt2(ERR_SYMBOL_PROTECTED, stuffSymbol(symbolCheck)));
	if(isNil((CELL *)symbolCheck->contents))
		{
        deleteList((CELL*)symbolCheck->contents);
		listOrg = makeCell(CELL_EXPRESSION, (UINT)copyCell(newCell));
        symbolCheck->contents = (UINT)listOrg;
        goto PUSH_RETURN;
	    }
	}                                   

if(!isList(list->type))
	{
	if(list->type == CELL_STRING)
		{
		pushOnString(newCell, list, params);
		goto PUSH_RETURN;
		}	
	else
		return(errorProcExt(ERR_LIST_OR_STRING_EXPECTED, list));
	}

if(params == nilCell) 
	index = 0;
else 
	{
	cell = (CELL*)params->next;
	params = evaluateExpression(params);
	if(isList(params->type))
		{
		evalFlag = FALSE;
		params = getIntegerExt((CELL*)params->contents, (UINT*)&index, FALSE);
		}
	else 
		{
		evalFlag = TRUE;
		getIntegerExt(params, (UINT*)&index, FALSE);
		params = cell;
		}
	}

if(index == -1) 
	{
	if(params == nilCell)
		{
		newCell = copyCell(newCell);
		cell = (CELL*)list->aux;	
		list->aux = (UINT)newCell;
		if(cell != nilCell && cell != trueCell)
			cell->next = newCell;
		else if(list->contents == (UINT)nilCell)
			list->contents = (UINT)newCell;
		else
			{
			cell = (CELL *)list->contents;
			while(cell->next != nilCell)
				cell = cell->next;
			cell->next = newCell;
			}
		goto PUSH_RETURN;
		}
	}
	
list->aux = (UINT)nilCell; /* undo last element optimization */

while(isList(list->type))
	{
	cell = list;
	list = (CELL *)list->contents;

	if(index < 0) 
		{
		index = listlen(list) + index;
		if(index == -1) 
			{
			index = 0;
			insert = INSERT_BEFORE;
			}
		else if(index >= 0) insert = INSERT_AFTER;
		else errorProc(ERR_LIST_INDEX_OUTOF_BOUNDS);
		}
	else insert = INSERT_BEFORE;

	while(index--) 
		{
		if(list == nilCell)
			{
			if(index >= 0) errorProc(ERR_LIST_INDEX_OUTOF_BOUNDS);
			insert = INSERT_END;
			break;
			}
		cell = list;
		list = list->next;
		}

	if(params == nilCell || !isList(list->type))  break;
	params = getIntegerExt(params, (UINT*)&index, evalFlag);
	}

newCell = copyCell(newCell);
if(insert == INSERT_BEFORE || list == nilCell)
	{
	if(list == (CELL*)cell->contents)
		{
		cell->contents = (UINT)newCell;
		newCell->next = list;
		}
	else
		{
		cell->next = newCell;
		newCell->next = list;
		}
	}

else if(insert == INSERT_AFTER || insert == INSERT_END)
    {
    cell = list->next;
    list->next = newCell;
    newCell->next = cell;
    }

PUSH_RETURN:
symbolCheck = symbolRef;
pushResultFlag = FALSE;
return(listOrg);
}