Exemple #1
0
/*=================================================
 * set_generic_string_shared -- populate gen with shared string generic
 * This routine does not dup the string, and does not free it
 * Caller is reponsible for the string outliving this generic
 *===============================================*/
void
set_generic_string_shared (GENERIC *gen, STRING sval)
{
	/* check for self-assignment */
	if (gen->selector == GENERIC_STRING_SHARED
		&& eqstr(gen->data.sval, sval)) {
		return;
	}
	/* clear old value, freeing any associated memory as appropriate */
	clear_generic(gen);
	/* set new value */
	gen->selector = GENERIC_STRING_SHARED;
	gen->data.sval = sval;
}
Exemple #2
0
/*=============================================
 * remove_refn -- Remove entry from refn record
 *===========================================*/
BOOLEAN
remove_refn (CNSTRING refn,       /* record's refn */
             CNSTRING key)        /* record's GEDCOM key */
{
	STRING rec, p;
	INT i, len, off;
	BOOLEAN found;
	RKEY rkey;
	rkey = str2rkey(key);
	(void) getrefnrec(refn);
	found = FALSE;
	for (i = 0; i < RRcount; i++) {
		if (!ll_strncmp(rkey.r_rkey, RRkeys[i].r_rkey, 8) &&
		    eqstr(refn, RRrefns[i])) {
			found = TRUE;
			break;
		}
	}
	if (!found) return FALSE;
	RRcount--;
	for ( ; i < RRcount; i++) {
		RRkeys[i] = RRkeys[i+1];
		RRrefns[i] = RRrefns[i+1];
	}
	p = rec = (STRING) stdalloc(RRsize);
	len = 0;
	memcpy(p, &RRcount, sizeof(INT));
	p += sizeof(INT);
	len += sizeof(INT);
	for (i = 0; i < RRcount; i++) {
		memcpy(p, &RRkeys[i], sizeof(RKEY));
		p += sizeof(RKEY);
		len += sizeof(RKEY);
	}
	off = 0;
	for (i = 0; i < RRcount; i++) {
		memcpy(p, &off, sizeof(INT));
		p += sizeof(INT);
		len += sizeof(INT);
		off += strlen(RRrefns[i]) + 1;
	}
	for (i = 0; i < RRcount; i++) {
		memcpy(p, RRrefns[i], strlen(RRrefns[i]) + 1);
		p += strlen(RRrefns[i]) + 1;
		len += strlen(RRrefns[i]) + 1;
	}
	bt_addrecord(BTR, RRkey, rec, len);
	stdfree(rec);
	return TRUE;
}
Exemple #3
0
static void
parse_line (char **v)
{
  bool need_answer_chars = false;
  bool need_question = false;
  size_t i;

  for (i = 1; v[i]; ++i)
  {
    if (eqstr (v[i], "-h") || eqstr (v[i], "--help"))
    {
      print_help ();
      exit (EXIT_SUCCESS);
    }
    else if (eqstr (v[i], "-v") || eqstr (v[i], "--version"))
    {
      print_version ();
      exit (EXIT_SUCCESS);
    }
    else if (eqstr (v[i], "-n") || eqstr (v[i], "--newline"))
      newline = true;
    else if (eqstr (v[i], "-a"))
      need_answer_chars = true;
    else if (startswith (v[i], "--answer-chars="))
      answer_chars = get_longopt_value (v[i]);
    else if (eqstr (v[i], "-q"))
      need_question = true;
    else if (startswith (v[i], "--question="))
      question = get_longopt_value (v[i]);
    else
    {
      if (need_answer_chars)
      {
        answer_chars = v[i];
        need_answer_chars = false;
      }
      else if (need_question)
      {
        question = v[i];
        need_question = false;
      }
      else
        fprintf (stderr, "%s: warning: `%s' unrecognized\n",
            program_name, v[i]);
    }
  }
}
Exemple #4
0
/*===============================
 * eqstr_ex -- Are two strings equal (case-sensitive)?
 *  This is just eqstr extended to handle empty or null strings
 *  Like eqstr, this is byte-by-byte comparison, no locale, no UTF-8
 *=============================*/
BOOLEAN
eqstr_ex (CNSTRING s1, CNSTRING s2)
{
	if (!s1 || !s1[0]) {
		if (!s2 || !s2[0])
			return TRUE;
		else
			return FALSE;
	} else {
		if (!s2 || !s2[0])
			return FALSE;
		else
			return eqstr(s1, s2);
	}
}
Exemple #5
0
/*====================================================
 * get_refns -- Find all records who match refn or key
 *==================================================*/
void
get_refns (STRING refn,
           INT *pnum,
           STRING **pkeys,
           INT letr)
{
	INT i, n;

	*pnum = 0;
	if (!refn) return;

/* Clean up allocated memory from last call */

	if (RMcount) {
		for (i = 0; i < RMcount; i++)
			stdfree(RMkeys[i]);
	}
	RMcount = 0;

/* Load static refn buffers; return if no match */

	if (!getrefnrec(refn)) return;

/* Compare user's refn with all refns in record; the refn
      record data structures are modified */

	n = 0;
	for (i = 0; i < RRcount; i++) {
		if (eqstr(refn, RRrefns[i])) {
			if (letr == 0 || *(rkey2str(RRkeys[i])) == letr) {
				if (i != n) {
					RRrefns[n] = RRrefns[i];
					RRkeys[n] = RRkeys[i];
				}
				n++;
			}
		}
	}
	*pnum = RRcount = n;
	if (RRcount > RMmax) {
		if (RMmax) stdfree(RMkeys);
		RMkeys = (STRING *) stdalloc(RRcount*sizeof(STRING));
		RMmax = RRcount;
	}
	for (i = 0; i < RRcount; i++)
		RMkeys[i] = strsave(rkey2str(RRkeys[i]));
	*pkeys = RMkeys;
}
Exemple #6
0
/*================================================================
 * convert_first_fp_to_node -- Convert first GEDCOM record in file to tree
 *
 * fp:   [IN]  file that holds GEDCOM record/s
 * list: [IN]  can be list at level 0?
 * ttm:  [IN]  character translation table
 * pmsg: [OUT] possible error message
 * peof: [OUT] set true if file is at end of file
 * TODO: revise import (restore_record) so can delete this
 *==============================================================*/
NODE
convert_first_fp_to_node (FILE *fp, BOOLEAN list, XLAT ttm,
	STRING *pmsg,  BOOLEAN *peof)
{
	STRING unitype = check_file_for_unicode(fp);
	NODE node=0;
	if (unitype && !eqstr(unitype, "UTF-8")) {
		char msg[120];
		llstrncpyf(msg, sizeof(msg), uu8, _(qSunsupuniv), unitype);
		*pmsg = _(qSunsupunix);
		return NULL;
	}
	node = do_first_fp_to_node(fp, list, ttm, pmsg, peof);
	nodechk(node, "convert_first_fp_to_node");
	return node;
}
Exemple #7
0
static void closegoto (LexState *ls, int g, Labeldesc *label) {
  int i;
  FuncState *fs = ls->fs;
  Labellist *gl = &ls->dyd->gt;
  Labeldesc *gt = &gl->arr[g];
  lua_assert(eqstr(gt->name, label->name));
  if (gt->nactvar < label->nactvar) {
    const char *msg = luaO_pushfstring(ls->L,
      "<goto %s> at line %d jumps into the scope of local " LUA_QS,
      getstr(gt->name), gt->line, getstr(getlocvar(fs, gt->nactvar)->varname));
    semerror(ls, msg);
  }
  luaK_patchlist(fs, gt->pc, label->pc);
  /* remove goto from pending list */
  for (i = g; i < gl->n - 1; i++)
    gl->arr[i] = gl->arr[i + 1];
  gl->n--;
}
Exemple #8
0
/*
** try to close a goto with existing labels; this solves backward jumps
*/
static int findlabel (LexState *ls, int g) {
  int i;
  BlockCnt *bl = ls->fs->bl;
  Dyndata *dyd = ls->dyd;
  Labeldesc *gt = &dyd->gt.arr[g];
  /* check labels in current block for a match */
  for (i = bl->firstlabel; i < dyd->label.n; i++) {
    Labeldesc *lb = &dyd->label.arr[i];
    if (eqstr(lb->name, gt->name)) {  /* correct label? */
      if (gt->nactvar > lb->nactvar &&
          (bl->upval || dyd->label.n > bl->firstlabel))
        luaK_patchclose(ls->fs, gt->pc, lb->nactvar);
      closegoto(ls, g, lb);  /* close it */
      return 1;
    }
  }
  return 0;  /* label not found; cannot close goto */
}
Exemple #9
0
/*=========================================
 * add_refn -- Add new entry to refn record
 *  refn: [IN]  record's user refn key
 *  key:  [IN]  record's GEDCOM key
 *=======================================*/
BOOLEAN
add_refn (CNSTRING refn, CNSTRING key)
{
	STRING rec, p;
	INT i, len, off;
	RKEY rkey;

	rkey = str2rkey(key);
	(void) getrefnrec(refn);
	for (i = 0; i < RRcount; i++) {
		if (!ll_strncmp(rkey.r_rkey, RRkeys[i].r_rkey, 8) &&
		    eqstr(refn, RRrefns[i]))
			return TRUE;
	}
	RRkeys[RRcount] = rkey;
	RRrefns[RRcount] = refn;
	RRcount++;
	p = rec = (STRING) stdalloc(RRsize + sizeof(RKEY) +
	    sizeof(INT) + strlen(refn) + 10);
	len = 0;
	memcpy(p, &RRcount, sizeof(INT));
	p += sizeof(INT);
	len += sizeof(INT);
	for (i = 0; i < RRcount; i++) {
		memcpy(p, &RRkeys[i], sizeof(RKEY));
		p += sizeof(RKEY);
		len += sizeof(RKEY);
	}
	off = 0;
	for (i = 0; i < RRcount; i++) {
		memcpy(p, &off, sizeof(INT));
		p += sizeof(INT);
		len += sizeof(INT);
		off += strlen(RRrefns[i]) + 1;
	}
	for (i = 0; i < RRcount; i++) {
		memcpy(p, RRrefns[i], strlen(RRrefns[i]) + 1);
		p += strlen(RRrefns[i]) + 1;
		len += strlen(RRrefns[i]) + 1;
	}
	bt_addrecord(BTR, RRkey, rec, len);
	stdfree(rec);
	return TRUE;
}
Exemple #10
0
/*static*/ void LexState::closegoto (/*LexState *ls,*/ int g, Labeldesc *label) {
	int i;
	//FuncState *fs = fs;
	Labellist *gl = &dyd->gt;
	Labeldesc *gt = &gl->arr[g];
	lua_assert(eqstr(gt->name, label->name));
	if (gt->nactvar < label->nactvar) {
		TString *vname = fs->getlocvar(gt->nactvar)->varname;
		const char *msg = luaO_pushfstring(L,
			"<goto %s> at line %d jumps into the scope of local '%s'",
			getstr(gt->name), gt->line, getstr(vname));
		semerror(msg);
	}
	fs->luaK_patchlist(gt->pc, label->pc);
	/* remove goto from pending list */
	for (i = g; i < gl->n - 1; i++)
		gl->arr[i] = gl->arr[i + 1];
	gl->n--;
}
/*If name is in names (names appears to be basic language keywords) return 0
  If its not do some other stuff...*/
int
lookup(char *name)
{
    int i;
    char *ns;

    ns = names;
    i = 0;
    while(i < nsym) {
	   if (eqstr(ns, name)) { //No idea why this check is in a loop
	    return i;
	}
	while(*ns++)
	    ;
	i++;
    }
    while(*ns++ = *name++)
	;
    return nsym++;
}
Exemple #12
0
/*=====================================
 * check_fam -- check family record
 *  and record any records needing fixing
 *  in tofix list
 *===================================*/
static BOOLEAN
check_fam (CNSTRING key, RECORD rec)
{
    static char prevkey[MAXKEYWIDTH+1]="";
    CACHEEL fcel1=0;
    RECORD recx=0;

    if (eqstr(key, prevkey)) {
        report_error(ERR_DUPFAM, _("Duplicate family for %s"), key);
    }

    fcel1 = fam_to_cacheel(rec);
    lock_cache(fcel1);

    recx = get_record_for_cel(fcel1);
    ASSERT(todo.pass == 1);
    process_fam(recx);

    unlock_cache(fcel1);
    check_pointers(key, rec);
    append_indiseq_null(seq_fams, strsave(key), NULL, TRUE, TRUE);
    return TRUE;
}
Exemple #13
0
/*=====================================
 * check_indi -- check indi record
 *  and record any records needing fixing
 *  in tofix list
 *===================================*/
static BOOLEAN
check_indi (CNSTRING key, RECORD rec)
{
    static char prevkey[MAXKEYWIDTH+1];
    CACHEEL icel1=0;
    RECORD recx=0;

    if (eqstr(key, prevkey)) {
        report_error(ERR_DUPINDI, _("Duplicate individual for %s"), key);
    }
    icel1 = indi_to_cacheel(rec);
    lock_cache(icel1);

    recx = get_record_for_cel(icel1);
    ASSERT(todo.pass == 1);
    process_indi(recx);

    unlock_cache(icel1);
    check_pointers(key, rec);
    append_indiseq_null(seq_indis, strsave(key), NULL, TRUE, TRUE);
    release_record(recx);
    return TRUE;
}
Exemple #14
0
/*======================
 * insert_hashtab -- Add new value to hash table
 * return previous value for this key, if any
 *====================*/
HVALUE
insert_hashtab (HASHTAB tab, CNSTRING key, HVALUE val)
{
	HASHENT entry=0;
	INT hval=0;

	ASSERT(tab);
	ASSERT(tab->magic == hashtab_magic);

	/* find appropriate has chain */
	hval = hash(tab, key);
	if (!tab->entries[hval]) {
		/* table lacks entry for this key, create it */
		entry = create_entry(key, val);
		tab->entries[hval] = entry;
		++tab->count;
		return 0; /* no old value */
	}
	entry = tab->entries[hval];
	while (TRUE) {
		ASSERT(entry->magic == hashent_magic);
		if (eqstr(key, entry->ekey)) {
			/* table already has entry for this key, replace it */
			HVALUE old = entry->val;
			entry->val = val;
			return old;
		}
		if (!entry->enext) {
			/* table lacks entry for this key, create it */
			HASHENT newent = create_entry(key, val);
			entry->enext = newent;
			++tab->count;
			return 0; /* no old value */
		}
		entry = entry->enext;
	}
}
Exemple #15
0
/*=================================================================
 * advedit_expand_traverse -- Traverse routine called when expanding record
 *===============================================================*/
static BOOLEAN
advedit_expand_traverse (NODE node, VPTR param)
{
	LIST subs = (LIST)param;
	STRING key = value_to_xref(nval(node));
	if (!key) return TRUE;
	key = strsave(key);
#ifdef DEBUG
	llwprintf("expand_traverse: %s %s\n", ntag(node), nval(node));
#endif /* DEBUG */
	FORLIST(subs, el)
#ifdef DEBUG
	llwprintf("expand_traverse: %s %s\n", key, rmvat(nval((NODE) el)));
#endif /* DEBUG */
		if (eqstr(key, rmvat(nval((NODE) el)))) {
			STOPLIST
			stdfree(key);
			return TRUE;
		}
	ENDLIST
	enqueue_list(subs, node);
	stdfree(key);
	return TRUE;
}
Exemple #16
0
/*===================================================
 * iconv_trans -- Translate string via iconv
 *  src:     [IN]  source codeset
 *  dest:    [IN]  string to translate (& delete)
 *  sin:     [IN]  source string to be converted
 *  zout:    [I/O] converted result
 *  illegal: [IN]  character to use as placeholder for unconvertible input
 *=================================================*/
BOOLEAN
iconv_trans (CNSTRING src, CNSTRING dest, CNSTRING sin, ZSTR zout, char illegal)
{
#ifdef HAVE_ICONV
	iconv_t ict;
	const char * inptr;
	char * outptr;
	size_t inleft;
	size_t outleft;
	size_t cvted;
#ifdef ICONV_SET_TRANSLITERATE
	int transliterate=2; 
#endif
	double expand=1.3;
	int chwidth=1;
	int badchars=0; /* count # illegal placeholders inserted */
	int inlen = sin ? strlen(sin) : 0;

	ASSERT(src);
	ASSERT(dest);

	ict = iconv_open(dest, src);

	if (ict == (iconv_t)-1) {
		return FALSE;
	}
	if (!strncmp(src, "UCS-2", strlen("UCS-2"))) {
		/* assume MS-Windows makenarrow call */
		inlen = 2 * wcslen((const wchar_t *)sin);
	}
	if (!strncmp(src, "UCS-4", strlen("UCS-4"))) {
		/* assume UNIX makenarrow call */
		inlen = 4 * wcslen((const wchar_t *)sin);
	}
	if (!strncmp(dest, "UCS-2", strlen("UCS-2"))) {
		chwidth = expand = 2;
	}
	if (!strncmp(dest, "UCS-4", strlen("UCS-4"))) {
		chwidth = expand = 4;
	}
	if (eqstr(dest, "wchar_t")) {
		chwidth = expand = sizeof(wchar_t);

	}
	/* TODO: What about UTF-16 or UTF-32 ? */

	zs_reserve(zout, (unsigned int)(inlen*expand+6));

	if (!inlen) {
		outptr = zs_str(zout);
		goto icvt_terminate_and_exit;
	}

	/* testing recursive transliteration in my private iconv, Perry, 2002.07.11 */
#ifdef ICONV_SET_TRANSLITERATE
	iconvctl(ict, ICONV_SET_TRANSLITERATE, &transliterate);
#endif


	inptr = sin;
	outptr = zs_str(zout);
	inleft = inlen;
	/* we are terminating with 4 zero bytes just in case dest is UCS-4 */
	outleft = zs_allocsize(zout)-zs_len(zout)-4;
	cvted = 0;

cvting:
	/* main convert */
	cvted = iconv (ict, &inptr, &inleft, &outptr, &outleft);

	/* zero terminate & fix output zstring */
	/* there may be embedded nulls, if UCS-2/4 is target! */
	*outptr=0;
	zs_set_len(zout, outptr-zs_str(zout));

	/* handle error cases */
	if (cvted == (size_t)-1) {
		/* errno is not reliable, because on MS-Windows we called
		iconv in a dll & didn't get errno */
		if (outleft<3) {
			/* may be out of space, so grow & retry */
			zs_reserve(zout, (unsigned int)(inleft * expand + 6 + zs_allocsize(zout)));
		} else {
			/* unconvertible input character */
			/* append placeholder & skip over */
			size_t wid = 1;
			if (eqstr(src, "UTF-8")) {
				wid = utf8len(*inptr);
			}
			if (wid > inleft)
				wid = inleft;
			inptr += wid;
			inleft -= wid;
			/* Following code is only correct for UCS-2LE, UCS-4LE */
			if (chwidth == 2)
			{
				unsigned short * u = (unsigned short *)outptr;
				*u = illegal;
				outptr += sizeof(u);
			}
			else if (chwidth == 4)
			{
				unsigned int * u = (unsigned int *)outptr;
				*u = illegal;
				outptr += sizeof(u);
			}
			else
			{
				*outptr++ = illegal;
			}
			++badchars;
			zs_set_len(zout, outptr-zs_str(zout));
		}
		/* update output variables */
		/* (may have reallocated, plus need to point to end */
		outptr = zs_str(zout)+zs_len(zout);
		outleft = zs_allocsize(zout)-zs_len(zout)-4;
		if (inleft)
			goto cvting;
	}

icvt_terminate_and_exit:
	/* zero-terminate with appropriately wide zero */
	if (chwidth > 1) {
		*outptr++=0;
		if (chwidth > 2) {
			*outptr++=0;
			*outptr++=0;
		}
	}
	*outptr=0;
	zs_set_len(zout, outptr-zs_str(zout));

	iconv_close(ict);
	return TRUE;
#else
	src=src; /* unused */
	dest=dest; /* unused */
	sin=sin; /* unused */
	zout=zout; /* unused */
	illegal=illegal; /* unused */
	return FALSE;
#endif /* HAVE_ICONV */
}
Exemple #17
0
int searchname() { int i; int j;
  i=LStart;while(i<LTop) {j=adrofname(i);if(eqstr(symbol,j))return i; i++;}
  i=0;     while(i<GTop) {j=adrofname(i);if(eqstr(symbol,j))return i; i++;}
  error1("Variable unbekannt"); }
Exemple #18
0
/*=================================================
 * add_dnodes -- add dnodes to dnode tree
 *  recursively, traversing NODE tree & building corresponding
 *  dnode tree
 * if a line overflows, give it succeeding sibling dnodes
 * also, check for subordinate CONT & CONC dnodes to be assimilated
 *===============================================*/
static DISPNODE
add_dnodes (NODE node, INT gen, INT indent, INT maxgen, INT * count, CANVASDATA canvas)
{
	DISPNODE tn;
	DISPNODE tn0, tn1, tn2;
	NODE child, anode;
	INT width = (canvas->rect->right - canvas->rect->left) - 2 - gen*indent;
	static char line[MAXLINELEN], output[MAXLINELEN]; /* must be same size */
	STRING ptr=output;
	INT leader;
	LIST list=NULL;
	INT mylen=sizeof(output), mylenorig;
	if (mylen>width)
		mylen = width;
	mylenorig = mylen;

	/* build xref & tag into line */
	line[0] = 0;
	ptr = line;
	mylen = sizeof(line);

	if (nxref(node)) {
		llstrcatn(&ptr, nxref(node), &mylen);
		llstrcatn(&ptr, " ", &mylen);
	}
	if (ntag(node)) {
		llstrcatn(&ptr, ntag(node), &mylen);
		llstrcatn(&ptr, " ", &mylen);
	}
	leader = ptr-line;
	width -= leader;
	if (width < 10) {
		/* insufficient space */
		return NULL;
	}

	/* output is available as scratch */

	list = text_to_list("", width, LISTDOFREE);
	if (nval(node)) {
		STRING valtxt = nval(node);
		append_to_text_list(list, valtxt, width, FALSE); 
	}

	/* anode is first child */
	anode = nchild(node);
	/* check for text continuation nodes to assimilate */
	if (nchild(node)) {
		for ( ; anode && !nchild(anode); anode = nsibling(anode)) {
			BOOLEAN newline=FALSE;
			STRING valtxt=NULL;
			if (eqstr(ntag(anode), "CONC")) {
				append_to_text_list(list, " ", width, FALSE);
				newline = FALSE;
			} else if (eqstr(ntag(anode), "CONT")) {
				newline = TRUE;
			} else {
				break;
			}
			valtxt = nval(anode);
			append_to_text_list(list, valtxt, width, newline); 
		}
	}
	/* anode is now first non-assimilated child */
	/*
	now add all list elements to tree as siblings
	first one will be tn, which we return as our result
	tn0 refers to previous one, for the nsibling links
	*/
	tn = tn0 = tn1 = 0;
	FORLIST(list, el)
		tn1 = alloc_displaynode();
		if (!tn) {
			INT i;
			tn = tn1;
			/* ptr & mylen still point after leader */
			llstrcatn(&ptr, el, &mylen);
			/* put original line */
			tn1->str = strsave(line);
			/* now build leader we will keep reusing */
			for (i=0; i<leader; i++)
				line[i] = '.';
			line[leader-1] = ' ';
		} else {
			llstrcatn(&ptr, el, &mylen);
			tn1->str = strsave(line);
		}
		/* now we keep resetting ptr & mylen to after blank leader */
		/* so we keep reusing that leader we built in line earlier */
		ptr=line+leader;
		mylen=mylenorig-leader;
		tn1->firstchild = 0;
		tn1->nextsib = 0;
		if (tn0)
			tn0->nextsib = tn1;
		tn0 = tn1;
		(*count)++;
	ENDLIST
	/* special handling for empty list, which didn't get its leader */
	if (is_empty_list(list)) {
		tn1 = alloc_displaynode();
		tn = tn1;
		tn1->str = strsave(line);
		tn1->firstchild = 0;
		tn1->nextsib = 0;
		tn0 = tn1;
		(*count)++;
	}
	destroy_list(list);
	list=0;

	if (gen < maxgen) {
		/* our children hang off of tn2, which is last node of our
		sibling tree; tn0 is previously added child */
		tn2 = tn1;
		tn0 = 0;
		/* anode was last unassimilated child */
		for (child = anode; child; child = nsibling(child)) {
			tn1 = add_dnodes(child, gen+1, indent, maxgen, count, canvas);
			if (!tn1)
				continue; /* child was skipped */
			/* link new displaynode into tree we're building */
			if (tn0)
				tn0 = tn0->nextsib = tn1;
			else /* first child - first time thru loop */
				tn0 = tn2->firstchild = tn1;
			/* child displaynode might have (overflow or assimilated) siblings */
			while (tn0->nextsib)
				tn0 = tn0->nextsib;
		}
	}
	return tn;
}
Exemple #19
0
Fichier : kblib.c Projet : 8l/bcpl
char *getenv(char *name) {
 if(eqstr(name, "BCPLPATH")) return "\\BCPL\\cintcode\\cin";
 if(eqstr(name, "BCPLROOT")) return "\\BCPL\\cintcode";
 if(eqstr(name, "BCPLHDRS")) return "\\BCPL\\cintcode\\g";
 return "";
}
Exemple #20
0
int isreg() {
  if (eqstr(symbol,"_AH")) {doreg("ah"); goto r1;}
  if (eqstr(symbol,"_AL")) {doreg("al"); goto r1;}  
  if (eqstr(symbol,"_AX")) {doreg("ax"); goto r1;}
  if (eqstr(symbol,"_BH")) {doreg("bh"); goto r1;}
  if (eqstr(symbol,"_BL")) {doreg("bl"); goto r1;}
  if (eqstr(symbol,"_BX")) {doreg("bx"); goto r1;}    
  if (eqstr(symbol,"_CH")) {doreg("ch"); goto r1;}
  if (eqstr(symbol,"_CL")) {doreg("cl"); goto r1;}
  if (eqstr(symbol,"_CX")) {doreg("cx"); goto r1;}    
  if (eqstr(symbol,"_DH")) {doreg("dh"); goto r1;}
  if (eqstr(symbol,"_DL")) {doreg("dl"); goto r1;}
  if (eqstr(symbol,"_DX")) {doreg("dx"); goto r1;}  
  if (eqstr(symbol,"_FLAGS")) {doreg("flags"); goto r1;}  
  return 0;   r1: return 1; 
}
Exemple #21
0
int pexpr() {expect('('); iscmp=0; 
  if (token==T_NAME) {if (eqstr(symbol, "_")) {constantexpr(); return;}}   
  expr(); if (iscmp==0) prs("\n or  al, al\n je @@"); 
  expect(')'); }
Exemple #22
0
/*================================================
 * edit_add_record -- Add record to database by editing
 *  recstr:  [IN] default record
 *  redt:    [IN] re-edit message
 *  ntype,   [IN] S, E, or X
 *  cfrm:    [IN] confirm message
 *==============================================*/
static RECORD
edit_add_record (STRING recstr, STRING redt, STRING redtopt, char ntype, STRING cfrm)
{
	FILE *fp;
	NODE node=0, refn;
	STRING msg, key;
	BOOLEAN emp;
	XLAT ttmi = transl_get_predefined_xlat(MEDIN);
	STRING (*getreffnc)(void) = NULL; /* get next internal key */
	void (*todbasefnc)(NODE) = NULL;  /* write record to dbase */
	void (*tocachefnc)(NODE) = NULL;  /* write record to cache */
	
	/* set up functions according to type */
	if (ntype == 'S') {
		getreffnc = getsxref;
		todbasefnc = sour_to_dbase;
		tocachefnc = sour_to_cache;
	} else if (ntype == 'E') {
		getreffnc = getexref;
		todbasefnc = even_to_dbase;
		tocachefnc = even_to_cache;
	} else { /* X */
		getreffnc = getxxref;
		todbasefnc = othr_to_dbase;
		tocachefnc = othr_to_cache;
	}

/* Create template for user to edit */
	if (!(fp = fopen(editfile, LLWRITETEXT))) {
		msg_error(_(qSnofopn), editfile);
		return FALSE;
	}
	prefix_file_for_edit(fp);
	fprintf(fp, "%s\n", recstr);

/* Have user edit new record */
	fclose(fp);
	do_edit();
	while (TRUE) {
		INT cnt;
		node = file_to_node(editfile, ttmi, &msg, &emp);
		if (!node) {
			if (ask_yes_or_no_msg(msg, redt)) { /* yes, edit again */
				do_edit();
				continue;
			} 
			break;
		}
		cnt = resolve_refn_links(node);
		/* check validation & allow user to reedit if invalid */
		/* this is a showstopper, so alternative is to abort */
		if (!valid_node_type(node, ntype, &msg, NULL)) {
			if (ask_yes_or_no_msg(msg, redt)) {
				do_edit();
				continue;
			}
			free_nodes(node);
			node = NULL; /* fail out */
			break;
		}
		/* Allow user to reedit if desired if any refn links unresolved */
		/* this is not a showstopper, so alternative is to continue */
		if (cnt > 0) {
			char msgb[120];
			snprintf(msgb, sizeof(msgb)
				, get_unresolved_ref_error_string(cnt), cnt);
			if (ask_yes_or_no_msg(msgb, redtopt)) {
				write_node_to_editfile(node);
				do_edit();
				continue;
			}
		}
		break;
	}
	if (!node || !ask_yes_or_no(cfrm)) {
		if (node) free_nodes(node);
		return NULL;
	}
	nxref(node) = strsave((STRING)(*getreffnc)());
	key = rmvat(nxref(node));
	for (refn = nchild(node); refn; refn = nsibling(refn)) {
		if (eqstr("REFN", ntag(refn)) && nval(refn))
			add_refn(nval(refn), key);
	}
	(*todbasefnc)(node);
	(*tocachefnc)(node);
	return key_to_record(key);
}
Exemple #23
0
int getlex() { char c; char *p; 
g1: c=next(); if (c == 0) return 0; if (c <= ' ') goto g1;
  if (c=='=') {if(thechar=='=') {next(); return T_EQ; }}
  if (c=='!') {if(thechar=='=') {next(); return T_NE; }}
  if (c=='<') {if(thechar=='=') {next(); return T_LE; }}
  if (c=='>') {if(thechar=='=') {next(); return T_GE; }}
  if (c=='<') {if(thechar=='<') {next(); return T_LESSLESS;  }}
  if (c=='>') {if(thechar=='>') {next(); return T_GREATGREAT;}}
  if (c=='+') {if(thechar=='+') {next(); return T_PLUSPLUS;  }}
  if (c=='-') {if(thechar=='-') {next(); return T_MINUSMINUS;}}
  if (c=='+') {if(thechar=='=') {next(); return T_PLUSASS;   }}
  if (c=='-') {if(thechar=='=') {next(); return T_MINUSASS;  }}
  if (c=='&') {if(thechar=='=') {next(); return T_ANDASS;    }}
  if (c=='|') {if(thechar=='=') {next(); return T_ORASS;     }}    
  if (c=='*') {if(thechar=='=') {next(); return T_MULASS;    }}
  if (c=='/') {if(thechar=='=') {next(); return T_DIVASS;    }}        
  if (instr1("()[]{},;*:%-><=+!&|#", c)) return c ;
  if (c == '/') { if (thechar == '*') { 
      g2: c=next(); if (c != '*') goto g2; if (thechar != '/') goto g2;
      c=next(); return getlex(); } else  return '/'; }
  if (c == '"') {getstring(c); return T_STRING;}
  if (digit(c)) { getdigit(c); return T_CONST; }
  if (c==39) { lexval=next();
    if (lexval==92) {lexval=next();
      if (lexval=='n') lexval=10; if (lexval=='t') lexval= 9;
      if (lexval=='0') lexval= 0; } next(); return T_CONST; }
  if (letter(c)) { 
    strcpy1(symboltemp, symbol); p=&symbol;  *p=c;  p++;
    while(letter(thechar)) {c=next(); *p=c;  p++; } 
      *p=0;
    if (eqstr(symbol,"signed"  )) return T_SIGNED;
    if (eqstr(symbol,"unsigned")) return T_UNSIGNED;
    if (eqstr(symbol,"void"    )) return T_VOID;
    if (eqstr(symbol,"int"     )) return T_INT;
    if (eqstr(symbol,"char"    )) return T_CHAR;
    if (eqstr(symbol,"asm"     )) return T_ASM;
    if (eqstr(symbol,"__asm"   )) return T_ASMBLOCK;
    if (eqstr(symbol,"__emit__")) return T_EMIT;
    if (eqstr(symbol,"return"  )) return T_RETURN;
    if (eqstr(symbol,"if"      )) return T_IF;
    if (eqstr(symbol,"else"    )) return T_ELSE;
    if (eqstr(symbol,"while"   )) return T_WHILE;
    if (eqstr(symbol,"do"      )) return T_DO;
    if (eqstr(symbol,"goto"    )) return T_GOTO;
    if (eqstr(symbol,"define"  )) return T_DEFINE;   
    if (eqstr(symbol,"include" )) return T_INCLUDE;   
    if (convertdefine() ) {strcpy1(symbol, symboltemp); return T_CONST;}
    return T_NAME; } error1("Zeichen nicht erkannt"); }
Exemple #24
0
/*===============================================
 * record_letter -- Return letter for record type
 *=============================================*/
INT
record_letter (CNSTRING tag)
{
	if (eqstr("FATH", tag)) return 'I';
	if (eqstr("MOTH", tag)) return 'I';
	if (eqstr("HUSB", tag)) return 'I';
	if (eqstr("WIFE", tag)) return 'I';
	if (eqstr("INDI", tag)) return 'I';
	if (eqstr("CHIL", tag)) return 'I';
	if (eqstr("FAMC", tag)) return 'F';
	if (eqstr("FAMS", tag)) return 'F';
	if (eqstr("FAM",  tag)) return 'F';
	if (eqstr("SOUR", tag)) return 'S';
	if (eqstr("EVEN", tag)) return 'E';
	if (eqstr("EVID", tag)) return 'E';
	return 0;
}
Exemple #25
0
/*=================================================
 * do_import -- Read GEDCOM file to database
 *  ifeed: [IN]  output methods
 *  fp:    [I/O] GEDCOM file whence to load data
 *===============================================*/
static BOOLEAN
do_import (IMPORT_FEEDBACK ifeed, FILE *fp)
{
	NODE node, conv;
	XLAT ttm = 0;
	STRING msg;
	BOOLEAN emp;
	INT nindi = 0, nfam = 0, neven = 0;
	INT nsour = 0, nothr = 0, type, num = 0;
	INT totkeys = 0, totused = 0;
	char msgbuf[80];
	BOOLEAN succeeded=FALSE;
	STRING str,unistr=0;
	ZSTR zerr=0;
	TABLE metadatatab = create_table_str();
	STRING gdcodeset=0;
	INT warnings=0;

	/* start by assuming default */
	strupdate(&gdcodeset, gedcom_codeset_in);

/*	rptui_init(); *//* clear ui time counter */

/* Open and validate GEDCOM file */
	if ((unistr=check_file_for_unicode(fp)) && !eqstr(unistr, "UTF-8")) {
		msg_error(_(qSunsupuniv), unistr);
		goto end_import;
	}
	if (eqstr_ex(unistr, "UTF-8")) {
		strupdate(&gdcodeset, "UTF-8");
	}

	if (!scan_header(fp, metadatatab, &zerr)) {
		msg_error(zs_str(zerr));
		goto end_import;
	}

	if ((str = valueof_str(metadatatab, "GEDC.FORM"))!= NULL) {
		if (!eqstr(str, "LINEAGE-LINKED")) {
			if (!ask_yes_or_no_msg(
				_("This is not a lineage linked GEDCOM file.")
				, _("Proceed anyway?")
				))
				goto end_import;
		}
	}
	if (!unistr && (str = valueof_str(metadatatab, "CHAR"))!= NULL) {
		/* if no BOM, use file's declared encoding if present */
		strupdate(&gdcodeset, str);
	}

	/* TODO: Push this codeset question down to after the validation, where we can know if
	the incoming file happened to really be all ASCII */

	if (!int_codeset[0]) {
		/* TODO: ask if user would like to adopt codeset of incoming file, if we found it */
		if (!ask_yes_or_no_msg(
			_("No current internal codeset, so no codeset conversion can be done")
			, _("Proceed without codeset conversion?")
			))
			goto end_import;
	}

	/* Warn if lossy code conversion likely */
	if (gdcodeset[0] && int_codeset[0]) {
		if (is_lossy_conversion(gdcodeset, int_codeset)) {
			ZSTR zstr=zs_new();
			zs_setf(zstr, _("Lossy codeset conversion (from <%s> to <%s>) likely")
				, gdcodeset, int_codeset);
			if (!ask_yes_or_no_msg(
				zs_str(zstr)
				, _("Proceed anyway?")
				))
				goto end_import;
		}
	}

	/* validate */
	if (ifeed && ifeed->validating_fnc)
		(*ifeed->validating_fnc)();

	if (!validate_gedcom(ifeed, fp)) {
		if (ifeed && ifeed->error_invalid_fnc)
			(*ifeed->error_invalid_fnc)(_(qSgdnadd));
		goto end_import;
	}
	warnings = validate_get_warning_count();
	if (warnings) {
		ZSTR zstr=zs_new();
		zs_setf(zstr, _pl("%d warning during import",
			"%d warnings during import", warnings), warnings);
		if (!ask_yes_or_no_msg(zs_str(zstr), _(qSproceed))) {
			goto end_import;
		}
	}

	if (gdcodeset[0] && int_codeset[0]) {
retry_input_codeset:
		ttm = transl_get_xlat(gdcodeset, int_codeset);
		if (!transl_is_xlat_valid(ttm)) {
			ZSTR zstr=zs_new();
			char csname[64];
			BOOLEAN b;
			transl_release_xlat(ttm);
			ttm = 0;
			zs_setf(zstr, _("Cannot convert codeset (from <%s> to <%s>)")
				, gdcodeset, int_codeset);
			b = ask_for_string(zs_str(zstr)
				, _("Enter codeset to assume (* for none)")
				, csname, sizeof(csname)) && csname[0];
			zs_free(&zstr);
			if (!b)
				goto end_import;
			if (!eqstr(csname, "*")) {
				strupdate(&gdcodeset, csname);
				goto retry_input_codeset;
			}
		}
	}
	
	if((num_indis() > 0)
		|| (num_fams() > 0)
		|| (num_sours() > 0)
		|| (num_evens() > 0)
		|| (num_othrs() > 0)) gd_reuse = FALSE;
	else if((gd_reuse = check_stdkeys())) {
		totused = gd_itot + gd_ftot + gd_stot + gd_etot + gd_xtot;
		totkeys = gd_imax + gd_fmax + gd_smax + gd_emax + gd_xmax;
		if((totkeys-totused) > 0) {
			INT delkeys = totkeys-totused;
			snprintf(msgbuf, sizeof(msgbuf)
				, _pl("Using original keys, %d deleted record will be in the database."
					, "Using original keys, %d deleted records will be in the database."
					, delkeys)
				, delkeys
				);
		}
		else strcpy(msgbuf, " ");
		gd_reuse = ask_yes_or_no_msg(msgbuf, _(qScfoldk));
/*
TODO: why were these here ?
		touchwin(uiw_win(stdout_win));
		wrefresh(uiw_win(stdout_win));
*/
	}

	/* start loading the file */
	rewind(fp);

	/* test for read-only database here */

	if(readonly) {
		if (ifeed && ifeed->error_readonly_fnc)
			(*ifeed->error_readonly_fnc)();
		goto end_import;
	}

	/* tell user we are beginning real part of import */
	if (ifeed && ifeed->beginning_import_fnc) {
		if(gd_reuse)
			(*ifeed->beginning_import_fnc)(_(qSdboldk));
		else
			(*ifeed->beginning_import_fnc)(_(qSdbnewk));
	}


/* Add records to database */
	node = convert_first_fp_to_node(fp, FALSE, ttm, &msg, &emp);
	while (node) {
		if (!(conv = node_to_node(node, &type))) {
			free_nodes(node);
			node = next_fp_to_node(fp, FALSE, ttm, &msg, &emp);
			continue;
		}
		switch (type) {
		case INDI_REC: num = ++nindi; break;
		case FAM_REC:  num = ++nfam;  break;
		case EVEN_REC: num = ++neven; break;
		case SOUR_REC: num = ++nsour; break;
		case OTHR_REC: num = ++nothr; break;
		default: FATAL();
		}
		restore_record(conv, type, num);
		if (ifeed && ifeed->added_rec_fnc)
			ifeed->added_rec_fnc(nxref(conv)[1], ntag(conv), num);
		free_nodes(node);
		node = next_fp_to_node(fp, FALSE, ttm, &msg, &emp);
	}
	if (msg) {
		msg_error(msg);
	}
	if(gd_reuse && ((totkeys - totused) > 0)) {
		if (ifeed && ifeed->adding_unused_keys_fnc)
			(*ifeed->adding_unused_keys_fnc)();
		addmissingkeys(INDI_REC);
		addmissingkeys(FAM_REC);
		addmissingkeys(EVEN_REC);
		addmissingkeys(SOUR_REC);
		addmissingkeys(OTHR_REC);
	}
	succeeded = TRUE;

end_import:
	validate_end_import();
	zs_free(&zerr);
	destroy_table(metadatatab);
	strfree(&gdcodeset);
	return succeeded;
}