Example #1
0
static long parserr(B *b)
{
	P *p = pdup(b->bof, USTR "parserr");
	P *q = pdup(p, USTR "parserr");
	long nerrs = 0;

	if (b->scratch && b->name[0] == '*') {
		/* "* Build Log *", "* Grep Log *" */
	 	b->changed = 0;
	}
	freeall();
	if (errbuf != b) {
		if (errp != NULL) {
			prm(errp);
			errp = NULL;
		}
		errbuf = b;
	}
	do {
		unsigned char *s;

		pset(q, p);
		p_goto_eol(p);
		s = brvs(q, (int) (p->byte - q->byte));
		if (s) {
			nerrs += parseit(b->o.charmap, s, q->line, (b->parseone ? b->parseone : parseone));
			vsrm(s);
		}
	} while (pgetc(p) != NO_MORE_DATA);
	prm(p);
	prm(q);
	return nerrs;
}
Example #2
0
int utag(BW *bw)
{
	BW *pbw;

	pbw = wmkpw(bw->parent, joe_gettext(_("Tag search: ")), &taghist, dotag, NULL, NULL, tag_cmplt, NULL, NULL, locale_map, 0);
	if (pbw && joe_isalnum_(bw->b->o.charmap,brch(bw->cursor))) {
		P *p = pdup(bw->cursor, "utag");
		P *q = pdup(p, "utag");
		int c;

		while (joe_isalnum_(bw->b->o.charmap,(c = prgetc(p))))
			/* do nothing */;
		if (c != NO_MORE_DATA) {
			pgetc(p);
		}
		pset(q, p);
		while (joe_isalnum_(bw->b->o.charmap,(c = pgetc(q))))
			/* do nothing */;
		if (c != NO_MORE_DATA) {
			prgetc(q);
		}
		binsb(pbw->cursor, bcpy(p, q));
		pset(pbw->cursor, pbw->b->eof);
		pbw->cursor->xcol = piscol(pbw->cursor);
		prm(p);
		prm(q);
	}
	if (pbw) {
		return 0;
	} else {
		return -1;
	}
}
Example #3
0
int ujump(BW *bw)
{
	int rtn = -1;
	P *p = pdup(bw->cursor, USTR "ujump");
	P *q = pdup(p, USTR "ujump");
	unsigned char *s;
	p_goto_bol(p);
	p_goto_eol(q);
	s = brvs(p, (int) (q->byte - p->byte));
	prm(p);
	prm(q);
	if (s) {
		unsigned char *name = NULL;
		long line = -1;
		if (bw->b->parseone)
			bw->b->parseone(bw->b->o.charmap,s,&name,&line);
		else
			parseone(bw->b->o.charmap,s,&name,&line);
		if (name && line != -1) {
			ERROR *p = srcherr(name, line);
			if (p != NULL) {
				errptr = p;
				setline(errbuf, errptr->src);
				name = p->file;
				line = p->line;
			}
			uprevvw((BASE *)bw);
			rtn = jump_to_file_line(maint->curwin->object, name, line, NULL /* errptr->msg */);
			vsrm(name);
		}
		vsrm(s);
	}
	return rtn;
}
Example #4
0
static void cdata(B *b, unsigned char *dat, int siz)
{
	P *q = pdup(b->eof, USTR "cdata");
	P *r = pdup(b->eof, USTR "cdata");
	long byte = q->byte;
	unsigned char bf[1024];
	int x, y;

	for (x = y = 0; x != siz; ++x) {
		if (dat[x] == 13 || dat[x] == 0) {
			;
		} else if (dat[x] == 8 || dat[x] == 127) {
			if (y) {
				--y;
			} else {
				pset(q, r);
				prgetc(q);
				bdel(q, r);
				--byte;
			}
		} else if (dat[x] == 7) {
			ttputc(7);
		} else {
			bf[y++] = dat[x];
		}
	}
	if (y) {
		binsm(r, bf, y);
	}
	prm(r);
	prm(q);

	cfollow(b,byte);
	undomark();
}
Example #5
0
static void cdata(B *b, unsigned char *dat, int siz)
{
	if (b->vt) { /* ANSI terminal emulator */
		MACRO *m;
		do {
			cready(b, b->vt->vtcur->byte);

			m = vt_data(b->vt, &dat, &siz);

			cfollow(b, b->vt, b->vt->vtcur->byte);
			undomark();
			if (m) {
				/* only do this if cursor is on window */
				if ((maint->curwin->watom->what & TYPETW) && ((BW *)maint->curwin->object)->b == b) {
					exmacro(m, 1);
					edupd(1);
				}
				rmmacro(m);
			}
		} while (m);
	} else { /* Dumb terminal */
		P *q = pdup(b->eof, USTR "cdata");
		P *r = pdup(b->eof, USTR "cdata");
		off_t byte = q->byte;
		unsigned char bf[1024];
		int x, y;
		cready(b, byte);
		for (x = y = 0; x != siz; ++x) {
			if (dat[x] == 13 || dat[x] == 0) {
				;
			} else if (dat[x] == 8 || dat[x] == 127) {
				if (y) {
					--y;
				} else {
					pset(q, r);
					prgetc(q);
					bdel(q, r);
					--byte;
				}
			} else if (dat[x] == 7) {
				ttputc(7);
			} else {
				bf[y++] = dat[x];
			}
		}
		if (y) {
			binsm(r, bf, y);
		}
		prm(r);
		prm(q);
		cfollow(b, NULL, b->eof->byte);
		undomark();
	}
}
Example #6
0
static long prefix(BW *bw, P *p,int up)
{
	long len;
	P *q = pdup(p, USTR "prefix");

	p_goto_bol(q);
	while (cpara(bw, brch(q)))
		pgetc(q);
	while (!pisbol(q)) {
		/* int c; */
		if (!joe_isblank(p->b->o.charmap, ( /* c = */ prgetc(q)))) {
		/*
			if (up && (c == '*' || c == '-')) {
				if (!pisbol(q)) {
					c = prgetc(q);
					pgetc(q);
					if (c == ' ' || c == '\t')
						goto skip;
				} else
					goto skip;
			}
			pgetc(q);
		*/
			break;
		/* 	skip:; */
		}
	}
	len = piscol(q);
	prm(q);
	return len;
}
Example #7
0
File: pw.c Project: Distrotech/joe
void promote_history(B *hist, long line)
{
	P *q = pdup(hist->bof, USTR "promote_history");
	P *r;
	P *t;

	pline(q, line);
	r = pdup(q, USTR "promote_history");
	pnextl(r);
	t = pdup(hist->eof, USTR "promote_history");
	binsb(t, bcpy(q, r));
	bdel(q, r);
	prm(q);
	prm(r);
	prm(t);
}
Example #8
0
static void doundo(BW *bw, UNDOREC *ptr)
{
	dostaupd = 1;

	if (ptr->del) {
		if (ptr->len < SMALL)
			binsm(bw->cursor, ptr->small, (int) ptr->len);
		else {
			B *b = ptr->big;

			bonline(b);
			binsb(bw->cursor, bcpy(b->bof, b->eof));
			boffline(b);
		}
	} else {
		P *q = pdup(bw->cursor, "doundo");

		pfwrd(q, ptr->len);
		bdel(bw->cursor, q);
		prm(q);
	}
	if (bw->b->changed && !ptr->changed)
		bw_unlock(bw);
	bw->b->changed = ptr->changed;
}
Example #9
0
//******************************************************************************************
//function: doUpdate
//params: const QHash<QString, QString> &params
//return: QJsonObject
//Description:
//******************************************************************************************
QJsonObject WSClient::doUpdate(const QHash<QString, QString> &params)
{
    if (!this->getCheckLogin()) {
        throw WSClientException( this->jsLoginError );
    }

    if (params.count() >= 1)
    {
        QJsonObject item;

        QHashIterator<QString, QString> prm(params);
        while(prm.hasNext()) {
            prm.next();
            item[prm.key()] = prm.value();
        }

        QJsonDocument doc_item(item);

        QHash<QString, QString> parameters;
        parameters.insert("element", QString( doc_item.toJson() ));

        QJsonObject response = Post("update", parameters);
        return response;
    }
    else
    {
        throw "Datos incorrectos";
    }
}
Example #10
0
P *pbop(BW *bw, P *p)
{
	long indent;
	long prelen;
	P *last;

	p_goto_bol(p);
	indent = nindent(bw, p, 0);
	prelen = prefix(bw, p, 0);
	last = pdup(p, USTR "pbop");
	while (!pisbof(p) && (!within || !markb || p->byte > markb->byte)) {
		long ind;
		long len;

		pprevl(p);
		p_goto_bol(p);
		ind = nindent(bw, p, 0);
		len = prefix(bw, p, 0);
		if (pisnpara(bw, p) || len != prelen) {
			pset(p, last);
			break;
		}
		if (ind > indent) {
/*
			int ok = 1;
			P *q = pdup(p, USTR "pbop");
			if (pprevl(q)) {
				p_goto_bol(q);
				if (nindent(bw, q, 0) == ind)
					ok = 0;
			}
			prm(q);
			if (!ok)
				pnextl(p);
*/
			break;
		}
		if (ind < indent) {
			pset(p, last);
			break;
			/* if (pisbof(p)) {
				break;
			}
			pprevl(p);
			p_goto_bol(p);
			if (pisnpara(bw, p)) {
				pnextl(p);
				break;
			} else {
				pnextl(p);
				pnextl(p);
				break;
			} */
		}
		pset(last, p);
	}
	prm(last);
	return p;
}
Example #11
0
File: pw.c Project: Distrotech/joe
void append_history(B *hist,unsigned char *s,int len)
{
	P *q = pdup(hist->eof, USTR "append_history");
	binsm(q, s, len);
	p_goto_eof(q);
	binsc(q, '\n');
	prm(q);
}
Example #12
0
int main(int argc, char *argv[])
{
	ProgMPIRun prm(argc, argv);
    prm.read(argc, argv);
    int result = prm.tryRun();
    MPI_Finalize();
    return result;
}
Example #13
0
static char *get_context(BW *bw)
{
	P *p = pdup(bw->cursor, "get_context");
	static char buf1[stdsiz];
	int i, j, spc;


	buf1[0] = 0;
	/* Find first line with 0 indentation which is not a comment line */
	do {
		p_goto_bol(p);
		if (!pisindent(p) && !pisblank(p)) {
			/* next: */
			brzs(p,stdbuf,stdsiz/8); /* To avoid buffer overruns with my_iconv */
			/* Ignore comment and block structuring lines */
			if (!(stdbuf[0]=='{' ||
			    (stdbuf[0]=='/' && stdbuf[1]=='*') ||
			    stdbuf[0]=='\f' ||
			    (stdbuf[0]=='/' && stdbuf[1]=='/') ||
			    stdbuf[0]=='#' ||
			    (stdbuf[0]=='b' && stdbuf[1]=='e' && stdbuf[2]=='g' && stdbuf[3]=='i' && stdbuf[4]=='n') ||
			    (stdbuf[0]=='B' && stdbuf[1]=='E' && stdbuf[2]=='G' && stdbuf[3]=='I' && stdbuf[4]=='N') ||
			    (stdbuf[0]=='-' && stdbuf[1]=='-') ||
			    stdbuf[0]==';')) {
			    	/* zlcpy(buf1, SIZEOF(buf1), stdbuf); */
 				/* replace tabs to spaces and remove adjoining spaces */
 				for (i=0,j=0,spc=0; stdbuf[i]; i++) {
 					if (stdbuf[i]=='\t' || stdbuf[i]==' ') {
 						if (spc) continue;
 						spc = 1;
 					}
 					else spc = 0;
 					if (stdbuf[i]=='\t')
 						buf1[j++] = ' ';
					else if (stdbuf[i]=='\\') {
						buf1[j++] = '\\';
						buf1[j++] = '\\';
					} else
						buf1[j++] = stdbuf[i];
 				}
 				buf1[j]= '\0';
				/* Uncomment to get the last line instead of the first line (see above)
			    	if (pprevl(p)) {
			    		p_goto_bol(p);
			    		if (!pisindent(p) && !pisblank(p))
			    			goto next;
			    	}
			    	*/
			    	break;
			}
			
		}
	} while (!buf1[0] && pprevl(p));

	prm(p);

	return buf1;
}
Example #14
0
int ubop(BW *bw)
{
	P *q = pdup(bw->cursor, USTR "ubop");

      up:
	while (pisnpara(bw, q) && !pisbof(q) && (!within || !markb || q->byte > markb->byte))
		pprevl(q);
	pbop(bw, q);
	if (q->byte != bw->cursor->byte) {
		pset(bw->cursor, q);
		prm(q);
		return 0;
	} else if (!pisbof(q)) {
		prgetc(q);
		goto up;
	} else {
		prm(q);
		return -1;
	}
}
Example #15
0
bool SIPAccount::Call(std::string Receiver) {
	_SIP_CurrentCall = new SIPCall(*this, PJSUA_INVALID_ID, this);
	CallOpParam prm(true); // Use default call settings
	try {
		_SIP_CurrentCall->makeCall(Receiver, prm);
		return true;
	} catch(Error& err) {
		cout << err.info() << "\n" << endl;
	}
	return false;
}
Example #16
0
int ueop(BW *bw)
{
	P *q = pdup(bw->cursor, USTR "ueop");

      up:
	while (pisnpara(bw, q) && !piseof(q))
		pnextl(q);
	pbop(bw, q);
	peop(bw, q);
	if (q->byte != bw->cursor->byte) {
		pset(bw->cursor, q);
		prm(q);
		return 0;
	} else if (!piseof(q)) {
		pnextl(q);
		goto up;
	} else {
		prm(q);
		return -1;
	}
}
Example #17
0
bool SIPAccount::HangUp() {

	CallOpParam prm(true);

	try {
		_SIP_CurrentCall->hangup(prm);
		return true;
	} catch (Error &Err) {

	}

	return false;
}
Example #18
0
int ucenter(BW *bw)
{
	P *p = bw->cursor, *q;
	long endcol, begcol, x;
	int c;

	p_goto_eol(p);
	while (joe_isblank(bw->b->o.charmap, (c = prgetc(p))))
		/* do nothing */;
	if (c == '\n') {
		pgetc(p);
		goto done;
	}
	if (c == NO_MORE_DATA)
		goto done;
	pgetc(p);
	endcol = piscol(p);

	p_goto_bol(p);
	while (joe_isblank(bw->b->o.charmap, (c = pgetc(p))))
		/* do nothing */;
	if (c == '\n') {
		prgetc(p);
		goto done;
	}
	if (c == NO_MORE_DATA)
		goto done;
	prgetc(p);
	begcol = piscol(p);

	if (endcol - begcol > bw->o.rmargin + bw->o.lmargin)
		goto done;

	q = pdup(p, USTR "ucenter");
	p_goto_bol(q);
	bdel(q, p);
	prm(q);

	for (x = 0; x != (bw->o.lmargin + bw->o.rmargin) / 2 - (endcol - begcol) / 2; ++x)
		binsc(p, ' ');

      done:
	if (!pnextl(p)) {
		binsc(p, '\n');
		pgetc(p);
		return -1;
	} else
		return 0;
}
Example #19
0
static int pisnpara(BW *bw, P *p)
{
	P *q;
	int c;

	q = pdup(p, USTR "pisnpara");
	p_goto_bol(q);
	while (cpara(bw, c = pgetc(q)))
		/* do nothing */;
	prm(q);
	if (c == '.' || c == '\r' || c == '\n')
		return 1;
	else
		return 0;
}
Example #20
0
static void markpos(W *w, P *p)
{
	POS *newpos = (POS *)alitem(&frpos, SIZEOF(POS));

	newpos->p = NULL;
	pdupown(p, &newpos->p, "markpos");
	poffline(newpos->p);
	newpos->w = w;
	enqueb(POS, link, &pos, newpos);
	if (npos == 20) {
		newpos = pos.link.next;
		prm(newpos->p);
		demote(POS, link, &frpos, newpos);
	} else {
		++npos;
	}
}
Example #21
0
// [[Rcpp::export]]
VectorXd bootR2(const MatrixXd X, const VectorXd y, int nBoot){
    RNGScope scope;
    const int n(X.rows());
    // const int p(X.cols());
    VectorXd R2s(nBoot);
    MatrixXd Xi(X);
    VectorXd yi(y);
    IntegerVector prm(n);
    // double R2i(R2(Xi, yi));
    for(int i = 0; i < nBoot; ++i) {
	prm = bootPerm(n);
	Xi = shuffleMatrix(X, prm);
	yi = shuffleVector(y, prm);
	R2s(i) = R2(Xi, yi);
    }
    return R2s;
}
Example #22
0
int uyankpop(BW *bw)
{
	if (bw->b == yankbuf && bw->cursor->byte == yankwhere) {
		P *q;
		UNDOREC *ptr = yanked.link.prev;

		deque(UNDOREC, link, &yanked);
		enqueb(UNDOREC, link, ptr, &yanked);
		q = pdup(bw->cursor, "uyankpop");
		pbkwd(q, ptr->len);
		inyank = 1;
		bdel(q, bw->cursor);
		inyank = 0;
		prm(q);
		return uyank(bw);
	} else
		return uyank(bw);
}
Example #23
0
static void iappend(BW *bw, struct isrch *isrch, char *s, ptrdiff_t len)
{				/* Append text and search */
	/* Append char and search */
	IREC *i = alirec();
	SRCH *srch;

	i->what = len;
	i->disp = bw->cursor->byte;
	isrch->pattern = vsncpy(sv(isrch->pattern), s, len);
	if (!qempty(IREC, link, &isrch->irecs)) {
		pgoto(bw->cursor, isrch->irecs.link.prev->start);
		if (globalsrch)
			globalsrch->wrap_flag = isrch->irecs.link.prev->wrap_flag;
	}
	i->start = bw->cursor->byte;

	if (!globalsrch)
		srch = mksrch(NULL,NULL,opt_icase,isrch->dir,-1,0,0,0,0);
	else {
		srch = globalsrch;
		globalsrch = 0;
	}

	srch->addr = bw->cursor->byte;

	if (!srch->wrap_p || srch->wrap_p->b!=bw->b) {
		prm(srch->wrap_p);
		srch->wrap_p = pdup(bw->cursor, "iappend");
		srch->wrap_p->owner = &srch->wrap_p;
		srch->wrap_flag = 0;
	}

	i->wrap_flag = srch->wrap_flag;

	setpat(srch, vsncpy(NULL, 0, isrch->pattern, sLen(isrch->pattern)));
	srch->backwards = isrch->dir;

	if (dopfnext(bw, srch, NULL)) {
		if(joe_beep)
			ttputc(7);
	}
	enqueb(IREC, link, &isrch->irecs, i);
}
Example #24
0
static long nindent(BW *bw, P *p, int first)
{
	P *q = pdup(p, USTR "nindent");
	long col;
	int c;

	p_goto_bol(q);
	do {
		col = q->col;
	} while (cpara(bw, (c = pgetc(q))));
	if (first && (c == '-' || c == '*')) {
		c = pgetc(q);
		if (c == ' ') {
			col = q->col;
		}
	}
	prm(q);
	return col;
}
Example #25
0
// [[Rcpp::export]]
MatrixXd bootCoef(const MatrixXd X, const VectorXd y, int nBoot){
    RNGScope scope;
    const int n(X.rows());
    const int p(X.cols());
    MatrixXd bootBeta(nBoot, p);
    MatrixXd Xi(X);
    VectorXd yi(y);
    IntegerVector prm(n);
    VectorXd betaHati(p);
    for(int i = 0; i < nBoot; ++i) {
	prm = bootPerm(n);
	Xi = shuffleMatrix(X, prm);
	yi = shuffleVector(y, prm);
	betaHati = betaHat(Xi, yi);
	for(int j = 0; j < p; ++j) {
	    bootBeta(i, j) = betaHati[j];
	}
    }
    return bootBeta;
}
Example #26
0
STDMETHODIMP CElement::Call(BSTR name, SAFEARRAY * params, /*[out,retval]*/ VARIANT *rv)
{
  HRESULT hr; 
  long lbound = 0, ubound = -1;
  bool r = false;

	hr = SafeArrayGetLBound(params, 0, &lbound); 
  hr = SafeArrayGetUBound(params, 0, &ubound); 
  
  aux::w2a aname(name);
  XCALL_PARAMS prm(aname);

  if( lbound <= ubound )
  {
    json::value *argv = new json::value[ubound - lbound + 1];
    int argc = 0;
    for(long n = lbound; n <= ubound; ++n)
    {
      CComVariant var;
      hr = SafeArrayGetElement(params,&n, &var); 
      if(FAILED(hr))
        break;
      argv[argc++] = cvt_VARIANT_to_json_value(var);
    }
    prm.argv = argv;
    prm.argc = argc;
    r = self.call_behavior_method(&prm);
    *rv = cvt_json_value_to_VARIANT(prm.retval);
    delete [] argv;
  }  
  else
  {
    prm.argv = 0;
    prm.argc = 0;
    r = self.call_behavior_method(&prm);
    *rv = cvt_json_value_to_VARIANT(prm.retval);
  }
  return r? S_OK : S_FALSE;
}
Example #27
0
int main(int argc,char *argv[])	{
	if(argc!=3)	{
		printf("[USAGE] %s [string] [int]\n",argv[0]);
		printf("[string]:CONVERSION STRING\n");
		printf("[int]:PRIME LOWER LIMIT\n");
		exit(-1);
	}
	int l=atoi(argv[2]);
	lint *prime=inttolint(prm(l));
	lint *strint=stringtolint(argv[1]);
	lint **split=_splitI(strint,(strint->length)/2);
	lint *sum=_additionI(*(split+1),*(split));
	lint **rem=_divisionI(sum,prime);
	printf("STR_INT[");
	printI(strint);
	printf("]\n");
	printf("PRIME[");
	printI(prime);
	printf("]\n");
	printf("SPLIT_LOW[");
	printI(*(split));
	printf("]\n");
	printf("SPLIT_HIGH[");
	printI(*(split+1));
	printf("]\n");
	printf("SUM[");
	printI(sum);
	printf("]\n");
	printf("REMAINDER[");
	printI(*(rem+1));
	printf("]\n");
	deleteI(prime);
	deleteI(strint);
	destroyI(split,2);
	deleteI(sum);
	destroyI(rem,2);
	return 0;
}
Example #28
0
int main(int argc,char *argv[])	{
	if(argc!=4)	{
		printf("[USAGE] %s [int1] [int2] [int3]\n",argv[0]);
		printf("[int1]:PRIME LOWER LIMIT\n");
		printf("[int2]:LIST SIZE LIMIT\n");
		printf("[int3]:LOG(10) NUMBER UPPER LIMIT\n");
		exit(-1);
	}
	int i,l=atoi(argv[1]),m=atoi(argv[2]),n=atoi(argv[3]);
	lint *prime=inttolint(prm(l)),**list=randlistI(m,n),**tmp;
	printf("[");
	printI(prime);
	printf("]\n");
	for(i=0;i<m;++i) {
		printI(*(list+i));
		printf(":\t");
		tmp=divisionI(*(list+i),prime);
		printI(*(tmp+1));
		printf("\n");
		destroyI(tmp,2);
	}
	destroyI(list,m);
	return 0;
}
Example #29
0
/* When called with c==-1, it just creates the prompt */
static int itype(W *w, int c, void *obj, int *notify)
{
	IREC *i;
	int omid;
	BW *bw;
	struct isrch *isrch = (struct isrch *)obj;
	WIND_BW(bw,w);

	if (isrch->quote) {
		goto in;
	}
	if (c == 8 || c == 127) {	/* Backup */
		if ((i = isrch->irecs.link.prev) != &isrch->irecs) {
			pgoto(bw->cursor, i->disp);
			if (globalsrch)
				globalsrch->wrap_flag = i->wrap_flag;
			omid = opt_mid;
			opt_mid = 1;
			dofollows();
			opt_mid = omid;
			isrch->pattern = vstrunc(isrch->pattern, sLEN(isrch->pattern) - i->what);
			frirec(deque_f(IREC, link, i));
		} else {
			if(joe_beep)
				ttputc(7);
		}
	} else if (c == 'Q' - '@' /* || c == '`' */) {
		isrch->quote = 1;
	} else if (c == 'S' - '@' || c == '\\' - '@' || c == 'L' - '@' || c == 'R' - '@') {
		/* Repeat */
		if (c == 'R' - '@') {
			isrch->dir = 1;
		} else {
			isrch->dir = 0;
		}
		if (qempty(IREC, link, &isrch->irecs)) {
			if (lastpat && lastpat[0]) {
				iappend(bw, isrch, sv(lastpat));
			}
		} else {
			SRCH *srch;
			i = alirec();
			i->disp = i->start = bw->cursor->byte;
			i->what = 0;

			if (!globalsrch)
				srch = mksrch(NULL,NULL,opt_icase,isrch->dir,-1,0,0,0,0);
			else {
				srch = globalsrch;
				globalsrch = 0;
			}

			srch->addr = bw->cursor->byte;

			if (!srch->wrap_p || srch->wrap_p->b!=bw->b) {
				prm(srch->wrap_p);
				srch->wrap_p = pdup(bw->cursor, "itype");
				srch->wrap_p->owner = &srch->wrap_p;
				srch->wrap_flag = 0;
			}

			i->wrap_flag = srch->wrap_flag;

			setpat(srch, vsncpy(NULL, 0, isrch->pattern, sLen(isrch->pattern)));
			srch->backwards = isrch->dir;

			if (dopfnext(bw, srch, NULL)) {
				if(joe_beep)
					ttputc(7);
				frirec(i);
			} else {
				enqueb(IREC, link, &isrch->irecs, i);
			}
		}
	} else if (c >= 0 && c < 32) {
		/* Done when a control character is received */
		nungetc(c);
		if (notify) {
			*notify = 1;
		}
		smode = 2;
		if (lastisrch) {
			lastpat = vstrunc(lastpat, 0);
			lastpat = vsncpy(lastpat, 0, lastisrch->pattern, sLen(lastisrch->pattern));
			rmisrch(lastisrch);
		}
		lastisrch = isrch;
		return 0;
	} else if (c != -1) {
		char buf[16];
		ptrdiff_t buf_len;
		/* Search */

		in:

		if (bw->b->o.charmap->type) {
			buf_len = utf8_encode(buf, c);
		} else {
			buf[0] = TO_CHAR_OK(from_uni(bw->b->o.charmap, c));
			buf_len = 1;
		}		

		isrch->quote = 0;
		iappend(bw, isrch, buf, buf_len);
	}
	omid = opt_mid;
	opt_mid = 1;
	bw->cursor->xcol = piscol(bw->cursor);
	dofollows();
	opt_mid = omid;

	isrch->prompt = vstrunc(isrch->prompt, isrch->ofst);

	if (locale_map->type && !bw->b->o.charmap->type) {
		/* Translate bytes to utf-8 */
		char buf[16];
		int x;
		for (x=0; x!=sLEN(isrch->pattern); ++x) {
			int tc = to_uni(bw->b->o.charmap, isrch->pattern[x]);
			utf8_encode(buf, tc);
			isrch->prompt = vsncpy(sv(isrch->prompt),sz(buf));
		}
	} else if (!locale_map->type && bw->b->o.charmap->type) {
		/* Translate utf-8 to bytes */
		const char *p = isrch->pattern;
		ptrdiff_t len = sLEN(isrch->pattern);
		while (len) {
			int tc = utf8_decode_fwrd(&p, &len);
			if (tc >= 0) {
				tc = from_uni(locale_map, tc);
				isrch->prompt = vsadd(isrch->prompt, TO_CHAR_OK(tc));
			}
		}
	} else {
		/* FIXME: translate when charmaps do not match */
		isrch->prompt = vsncpy(sv(isrch->prompt),sv(isrch->pattern));
	}

	if (mkqwnsr(bw->parent, sv(isrch->prompt), itype, iabrt, isrch, notify)) {
		return 0;
	} else {
		rmisrch(isrch);
		return -1;
	}
}
Example #30
0
int uformat(BW *bw)
{
	long indent;
	unsigned char *indents;
	B *buf;
	P *b;
	long curoff;
	int c;
	P *p, *q;

	p = pdup(bw->cursor, USTR "uformat");
	p_goto_bol(p);

	/* Do nothing if we're not on a paragraph line */
	if (pisnpara(bw, p)) {
		prm(p);
		return 0;
	}

	/* Move p to beginning of paragraph, bw->cursor to end of paragraph and
	 * set curoff to original cursor offset within the paragraph */
	pbop(bw, p);
	curoff = bw->cursor->byte - p->byte;
	pset(bw->cursor, p);
	peop(bw, bw->cursor);

	/* Ensure that paragraph ends on a beginning of a line */
	if (!pisbol(bw->cursor))
		binsc(bw->cursor, '\n'), pgetc(bw->cursor);

	/* Record indentation of second line of paragraph, of first line if there
	 * is only one line */
	q = pdup(p, USTR "uformat");
	pnextl(q);
	if (q->line != bw->cursor->line) {
		P *r = pdup(q, USTR "uformat");

		indent = nindent(bw, q, 0);
		pcol(r, indent);
		indents = brs(q, r->byte - q->byte);
		prm(r);
	} else {
		P *r = pdup(p, USTR "uformat");
		int x, y;
		indent = nindent(bw, p, 1); /* allowing * and - here */
		pcol(r, indent);
		indents = brs(p, r->byte - p->byte);
		prm(r);
		if (!bw->o.autoindent) {
			/* Don't indent second line of single-line paragraphs if autoindent is off */
			int x = zlen(indents);
			while (x && (indents[x - 1] == ' ' || indents[x - 1] == '\t'))
				indents[--x] = 0;
			if (x) {
				indents[x++] = ' ';
				indents[x] = 0;
			}
			indent = txtwidth1(bw->o.charmap, bw->o.tab, indents, x);
		}
		for (x = 0; indents[x] && (indents[x] == ' ' || indents[x] == '\t'); ++x);
		y = zlen(indents);
		while (y && (indents[y - 1] == ' ' || indents[y - 1] == '\t'))
			--y;
		/* Don't duplicate if it looks like a bullet */
/*		if (y && (indents[y - 1] == '*' || indents[y - 1] == '-') &&
		    (y == 1 || indents[y - 2] == ' ' || indents[y - 2] == '\t'))
			indents[y - 1] = ' '; */
		/* Fix C comment */
		if (indents[x] == '/' && indents[x + 1] == '*')
			indents[x] = ' ';
	}
	prm(q);

	/* But if the left margin is greater, we use that instead */
	if (bw->o.lmargin > indent) {
		int x;
		for (x = 0; indents[x] == ' ' || indents[x] == '\t'; ++x);
		if (!indents[x]) {
			joe_free(indents);
			indent = bw->o.lmargin;
			indents = joe_malloc(indent+1);
			for (x = 0; x != indent; ++x)
				indents[x] = ' ';
			indents[x] = 0;
		}
	}

	/* Cut paragraph into new buffer */
	
	/* New buffer needs to inherit UTF-8 and CR-LF options */
	buf = bcpy(p, bw->cursor);
	buf->o.crlf = p->b->o.crlf;
	buf->o.charmap = p->b->o.charmap;
	bdel(p, bw->cursor);

	/* text is in buffer.  insert it at cursor */

	/* Do first line */
	b = pdup(buf->bof, USTR "uformat");

	while (!piseof(b)) {
		/* Set cursor position if we're at original offset */
		if (b->byte == curoff)
			pset(bw->cursor, p);

		/* Get character from buffer */
		c = pgetc(b);

		/* Stop if we found end of line */
		if (c == '\n') {
			prgetc(b);
			break;
		}

		/* Stop if we found white-space followed by end of line */
		if (joe_isblank(b->b->o.charmap, c) && piseolblank(b)) {
			prgetc(b);
			break;
		}

		/* Insert character, advance pointer */
		binsc(p, c);
		pgetc(p);

		/* Do word wrap if we reach right margin */
		if (piscol(p) > bw->o.rmargin && !joe_isblank(p->b->o.charmap,c)) {
			wrapword(bw, p, indent, bw->o.french, 1, indents);
			break;
		}
	}

	/* Do rest */

	while (!piseof(b)) {
		c = brch(b);
		if (joe_isblank(b->b->o.charmap,c) || c == '\n') {
			int f = 0;
			P *d;
			int g;

			/* Set f if there are two spaces after . ? or ! instead of one */
			/* (What is c was '\n'?) */
			d=pdup(b, USTR "uformat");
			g=prgetc(d);
			if (g=='.' || g=='?' || g=='!') {
				f = 1;
/*				pset(d,b);
				pgetc(d);
				if (c == '\n' || piseol(d) || joe_isspace(bw->b->o.charmap,brch(d))) {
					f = 1;
				}
*/
			}
			prm(d);
			
			/* Skip past the whitespace.  Skip over indentations */
		      loop:
			
			c = brch(b);
			if (c == '\n') {
				if (b->byte == curoff)
					pset(bw->cursor, p);

				pgetc(b);
				while (cpara(bw, (c=brch(b)))) {
					if (b->byte == curoff)
						pset(bw->cursor, p);
					pgetc(b);
				}
			}

			if (joe_isblank(b->b->o.charmap,c)) {
				if(b->byte == curoff)
					pset(bw->cursor, p);
				pgetc(b);
				goto loop;
			}

			/* Insert proper amount of whitespace */
			if (!piseof(b)) {
				if (f && !bw->o.french)
					binsc(p, ' '), pgetc(p);
				binsc(p, ' ');
				pgetc(p);
			}
		} else {
			/* Insert characters of word and wrap if necessary */
			if (b->byte == curoff)
				pset(bw->cursor, p);

			binsc(p, pgetc(b));
			pgetc(p);
			if (piscol(p) > bw->o.rmargin)
				wrapword(bw, p, indent, bw->o.french, 1, indents);
		}
	}

	binsc(p, '\n');
	prm(p);
	brm(buf);
	joe_free(indents);
	return 0;
}