Ejemplo n.º 1
0
/*
 * Read some data from socket fd, break on '\n' and add
 * to buffer. If couldn't break on newline hold leftover
 * characters and append in next iteration.
 */
int
preadin(int fd, struct buffer *bp)
{
	int len;
	char buf[BUFSIZ], *p, *q;

	if ((len = read(fd, buf, BUFSIZ - 1)) == 0)
		return (FALSE);

	buf[len] = '\0';
	p = q = buf;
	if (leftover[0] != '\0' && ((q = strchr(p, '\n')) != NULL)) {
		*q++ = '\0';
		if (strlcat(leftover, p, sizeof(leftover)) >=
		    sizeof(leftover)) {
			dobeep();
			ewprintf("line too long");
			return (FALSE);
		}
		addline(bp, leftover);
		leftover[0] = '\0';
		p = q;
	}
	while ((q = strchr(p, '\n')) != NULL) {
		*q++ = '\0';
		addline(bp, p);
		p = q;
	}
	if (strlcpy(leftover, p, sizeof(leftover)) >= sizeof(leftover)) {
		dobeep();
		ewprintf("line too long");
		return (FALSE);
	}
	return (TRUE);
}
Ejemplo n.º 2
0
struct tref *addref(struct tref *node, char *key, int linenumber)
{
    /* Add key to the node tree.
     *
     * If a key already exists in the node tree, add the line on which
     *     it occurs to the occurrences tree for the given key.
     *
     * Returns: pointer to the node which was passed as an input argument.
     */

    int cmp;

    if(!node) {
        node = (struct tref *)malloc(sizeof(struct tref));
        node->key = strdup(key);
        node->left = node->right = NULL;
        node->lines = NULL;
        node->lines = addline(node->lines, linenumber);
    }
    else if((cmp = strcmp(key, node->key)) < 0) {
        node->left = addref(node->left, key, linenumber);
    }
    else if(cmp > 0) {
        node->right = addref(node->right, key, linenumber);
    }
    else {
        addline(node->lines, linenumber);
    }

    return node;
}
Ejemplo n.º 3
0
struct tnode *addtree(struct tnode *p, char *w) {
    int cond;
    if (p == NULL) {
        p = talloc();
        p->word = Strdup(w);
        p->firstline = NULL;
        p->firstline = addline(p->firstline, line);
        p->left = p->right = NULL;
    } else if ((cond = strcmp(w, p->word)) == 0)
        addline(p->firstline, line);
    else if (cond < 0)
        p->left = addtree(p->left, w);
    else p->right = addtree(p->right, w);
    return p;
}
Ejemplo n.º 4
0
static int
showall(struct buffer *bp, KEYMAP *map, char *prefix)
{
	KEYMAP	*newmap;
	char	 buf[80], keybuf[16];
	PF	 fun;
	int	 c;

	if (addline(bp, "") == FALSE)
		return (FALSE);

	/* XXX - 256 ? */
	for (c = 0; c < 256; c++) {
		fun = doscan(map, c, &newmap);
		if (fun == rescan || fun == selfinsert)
			continue;
		getkeyname(buf, sizeof(buf), c);
		(void)snprintf(keybuf, sizeof(keybuf), "%s%s ", prefix, buf);
		if (fun == NULL) {
			if (showall(bp, newmap, keybuf) == FALSE)
				return (FALSE);
		} else {
			if (addlinef(bp, "%-16s%s", keybuf,
				    function_name(fun)) == FALSE)
				return (FALSE);
		}
	}
	return (TRUE);
}
Ejemplo n.º 5
0
Archivo: new.c Proyecto: vocho/openqnx
int zap_restore(int laddr)
	{
	register struct line *p1, *p2;
	int status = OK, i;

	if(nladdrs == 2)
		return(ERROR5);

	curln = laddr;
	for(p1 = purge_ptr->next, i = npurge_lns; i ; --i, p1 = p1->next) {
		strcpy(rbuff, (p2 = getptr(curln))->textp);
		zchar_change(curin, strlen(rbuff), p1->textp, strlen(p1->textp), curln);

		if(curln == 0) {		/* Add after last line */
			curln = lastln;
			status = addline(rbuff, 0, 0);
			}
		else
			status = replace(curln, rbuff, p2->textp);

		if(status != OK)
			break;

		curln = nextln(curln);	/* Set to zero after last line */
		}

	curln = laddr;
	return(status);
	}
Ejemplo n.º 6
0
static struct tnode *treeadd(struct tnode *p, char *w, char *uw, int line) {

    int cond;

    if (p == NULL) {
        // Create new tnode
        p = talloc();
        p->word  = mystrdup(w);
        p->words = lwalloc();
        p->words->word = mystrdup(uw);
        p->words->next = NULL;
        p->wordcount = 1;
        p->lines = lalloc();
        p->lines->linenum = line;
        p->lines->next = NULL;
        p->right = NULL;
        p->left  = NULL;
    } else if ((cond = strncmp(w, p->word, MAXWORDSIZE)) == 0) {
        // Update existing tnode
        addword(p, uw);
        addline(p, line);
    } else if (cond < 0)
        // Traverse left-hand side of tree
        p->left  = treeadd(p->left, w, uw, line);
    else
        // Traverse right-hand side of tree
        p->right = treeadd(p->right, w, uw, line);

    return p;
}
Ejemplo n.º 7
0
EXPORT BOOL WINAPI xnoteadd( HSPEXINFO *hei, int p1, int p2, int p3 )
{
	//
	//		xnoteadd "strings" (type$202)
	//
	char *buf, *p, *str_to_add;
	int size;
	int line;

	str_to_add = hei->HspFunc_prm_gets();
	if (xn_pval->flag!=HSPVAR_FLAG_STR) return -1;
	buf = (char *)Hsp3GetBlockSize( hei, xn_pval, xn_aptr, &size );
	p = buf;
	line=0;
	while (*p != '\0') {
		if (lineeq(p, str_to_add) ) {
			DataInc(line);
			return -line;
		}
		p = skipline(p);
		line ++;
	}

	addline( hei, xn_pval, xn_aptr, p - buf, str_to_add );
	DataInc(line);
	return -line;
}
Ejemplo n.º 8
0
void processline(bc *bc, char *line)
{
char token[64], *lp;
struct cmd *cmd;

	lp=line;
	gettoken(token, sizeof(token), &lp);
	skipwhite(&lp);

	cmd=commandlist;
	while(cmd->name)
	{
		if(!strncmp(token, cmd->name, strlen(token)))
		{
			cmd->func(bc, lp);
			return;
		}
		++cmd;
	}
	if(line[0]>='0' && line[0]<='9') // line number
	{
		bc->flags |= BF_NOPROMPT;
		lp=line;
		while(*lp>='0' && *lp<='9') ++lp;
		if(*lp)
			addline(bc, line);
		else
			deleteline(bc, atoi(line));
	} else if(*line)
	{
		parseline(bc, line);
	} else
		bc->flags |= BF_NOPROMPT;
}
Ejemplo n.º 9
0
int append(int laddr, char under_glob)
	{
	register int status;

	if(*lp != '\n'  &&  *lp++ != ' ') {
		if(*(lp + -1) == 'd')
			return(undelete(laddr));
		return(ERROR9);
		}

	curln = laddr;
	if((status = addline(esc_line(lp), 0, 0)) == OK) {
		curcol = left_margin;
		change_state(TEXT);
		if(!under_glob)
			opt.opt_n = TRUE;
		if(opt.opt_s  &&  ++auto_save_cnt >= SAVE_THRESHOLD) {
			_write("auto_save", 1, lastln, 0, 0);
			auto_save_cnt = 0;
			}
		}

	lp = "\n";  /* forces main to fetch a new line */
	return( status );
	}
Ejemplo n.º 10
0
int
shellcmdoutput(char* const argv[], char* const text, int len)
{

	struct buffer *bp;
	char	*shellp;
	int	 ret;

	bp = bfind("*Shell Command Output*", TRUE);
	bp->b_flag |= BFREADONLY;
	if (bclear(bp) != TRUE) {
		free(text);
		return (FALSE);
	}

	shellp = getenv("SHELL");

	ret = pipeio(shellp, argv, text, len, bp);

	if (ret == TRUE) {
		eerase();
		if (lforw(bp->b_headp) == bp->b_headp)
			addline(bp, "(Shell command succeeded with no output)");
	}

	free(text);
	return (ret);
}
Ejemplo n.º 11
0
/* Draw the board, the help, and the two wordlists at the end of a
 * round. Returns zero if the end of screen was reached before the end
 * of the wordlist.
 */
int doendgameoutput(int y, int x, int offset, int highlighted)
{
    int f = TRUE;

    drawgridletters(highlighted);
    movetowords(TRUE);
    listwords("Your words:", getfound(), 0);
    if (!ego)
	f = listwords("Other words that were present:", getfindable(), offset);
    move(y, x);
    if (!offset && f)
	addline("^D: quit  &: new game  ?: find word");
    else
	addline("^D: quit  &: new game  ?: find word  -+: scroll");
    clrtoeol();
    return f;
}
Ejemplo n.º 12
0
struct linelist *addline(struct linelist *p, int l) {
    if (p == NULL) {
        p = lalloc();
        p->next = NULL;
        p->line = l;
    } else p->next = addline(p->next, l);
    return p;
}
Ejemplo n.º 13
0
struct tlist *addline(struct tlist *node, int linenumber)
{
    if(!node) {
        node = (struct tlist *)malloc(sizeof(struct tlist));
        node->key = linenumber;
        node->left = node->right = NULL;
    }
    else if(linenumber < node->key) {
        node->left = addline(node->left, linenumber);
    }
    else if(linenumber > node->key) {
        node->right = addline(node->right, linenumber);
    }
    /* if linenumber == node->key, do nothing since the line already shows up
     *     and we aren't keeping any sort of count.
     */

    return node;
}
Ejemplo n.º 14
0
struct tnode *addtree(struct tnode *p, char *w)
{
    int cond;
    if (p == NULL) {
	p = talloc();
	p->word = mystrdup(w);
	p->line = NULL;
	p->line = addline(p->line);
	p->left = NULL;
	p->right = NULL;
	return p;
    }
    if ((cond = strcmp(w, p->word)) < 0)
	p->left = addtree(p->left, w);
    else if (cond > 0)
	p->right = addtree(p->right, w);
    else 
	p->line = addline(p->line);
    return p;
}
Ejemplo n.º 15
0
void proccess_move_down(mpGame *g) {

	int i,z;

	for(i = 0; i < TILE_W; i++) {
		for(z = 0; z < TILE_H; z++) {
			int c = g->Tiles[i][z];
			if(c != 0) {
				if(c == g->Tiles[i][z+1] && c == g->Tiles[i][z+2]) {
					g->Tiles[i][z] = 0;
					g->Tiles[i][z+1] = 0;
					g->Tiles[i][z+2] = 0;
					addline(g);
					return;
				}

				if(c == g->Tiles[i+1][z] && c == g->Tiles[i+2][z]) {
					g->Tiles[i][z] = 0;
					g->Tiles[i+1][z] = 0;
					g->Tiles[i+2][z] = 0;
					addline(g);
					return;
				}
				if(c == g->Tiles[i+1][z+1] && c == g->Tiles[i+2][z+2]) {
					g->Tiles[i][z] = 0;
					g->Tiles[i+1][z+1] = 0;
					g->Tiles[i+2][z+2] = 0;
					addline(g);
					return;
				}

				if(bounds(i-2,z-2) && c == g->Tiles[i-1][z-1] && c == g->Tiles[i-2][z-2]) {
					g->Tiles[i][z] = 0;
					g->Tiles[i-1][z-1] = 0;
					g->Tiles[i-2][z-2] = 0;
					addline(g);
					return ;
				}

				if(bounds(i-2,z) && c == g->Tiles[i-1][z+1] && g->Tiles[i-2][z+2] == c) {

					g->Tiles[i][z] = 0;
					g->Tiles[i-1][z+1] = 0;
					g->Tiles[i-2][z+2] = 0;
					addline(g);
					return;
				}

				if(bounds(i,z-2) && c == g->Tiles[i+1][z-1] == c && g->Tiles[i+2][z-2] == c) {
					g->Tiles[i][z] = 0;
					g->Tiles[i+1][z-1] = 0;
					g->Tiles[i+2][z-2] = 0;
					addline(g);
					return;
				}
			}
		}
	}
	proc_blocks(g);
}
Ejemplo n.º 16
0
/*
 * Multiplex read, write on socket fd passed. Put output in outbp
 * Poll on the fd for both read and write readiness.
 */
int
iomux(int fd, char* const text, int len, struct buffer *outbp)
{
	struct pollfd pfd[1];
	int nfds;
	char *textcopy;

	textcopy = text;
	fcntl(fd, F_SETFL, O_NONBLOCK);
	pfd[0].fd = fd;

	/* There is nothing to write if len is zero
	 * but the cmd's output should be read so shutdown 
	 * the socket for writing only and don't wait for POLLOUT
	 */
	if (len == 0) {
		shutdown(fd, SHUT_WR);
		pfd[0].events = POLLIN;
	} else
		pfd[0].events = POLLIN | POLLOUT;

	while ((nfds = poll(pfd, 1, TIMEOUT)) != -1 ||
	    (pfd[0].revents & (POLLERR | POLLHUP | POLLNVAL))) {
		if (pfd[0].revents & POLLOUT && len > 0)
			pwriteout(fd, &textcopy, &len);
		else if (pfd[0].revents & POLLIN)
			if (preadin(fd, outbp) == FALSE)
				break;
		if (len == 0 && pfd[0].events & POLLOUT)
			pfd[0].events = POLLIN;
	}
	close(fd);

	/* In case if last line doesn't have a '\n' add the leftover 
	 * characters to buffer.
	 */
	if (leftover[0] != '\0') {
		addline(outbp, leftover);
		leftover[0] = '\0';
	}
	if (nfds == 0) {
		dobeep();
		ewprintf("poll timed out");
		return (FALSE);
	} else if (nfds == -1) {
		dobeep();
		ewprintf("poll error");
		return (FALSE);
	}
	return (popbuftop(outbp, WNONE));
}
Ejemplo n.º 17
0
/* ARGSUSED */
int
wallchart(int f, int n)
{
	int		 m;
	struct buffer		*bp;

	bp = bfind("*help*", TRUE);
	if (bclear(bp) != TRUE)
		/* clear it out */
		return (FALSE);
	bp->b_flag |= BFREADONLY;
	for (m = curbp->b_nmodes; m > 0; m--) {
		if ((addlinef(bp, "Local keybindings for mode %s:",
				curbp->b_modes[m]->p_name) == FALSE) ||
		    (showall(bp, curbp->b_modes[m]->p_map, "") == FALSE) ||
		    (addline(bp, "") == FALSE))
			return (FALSE);
	}
	if ((addline(bp, "Global bindings:") == FALSE) ||
	    (showall(bp, fundamental_map, "") == FALSE))
		return (FALSE);
	return (popbuftop(bp, WNONE));
}
Ejemplo n.º 18
0
/* Lists words in the given array. The current cursor location gives
 * the upper left of the area to use, which is assumed to extend to
 * the edges of the screen. The supplied heading is displayed first,
 * then the words are displayed in a column; if the bottom of the
 * screen is reached, then another column is begun.  (The longest word
 * in the list sets the width of the columns.) If the right edge of
 * the screen is reached, an ellipsis is displayed in the bottom right
 * corner. The offset argument indicates how many columns to skip
 * before displaying.
 */
static int listwords(char const *heading, char const **list, int offset)
{
    char const **word;
    int y, x, ymin, ymax, xmax, ycol;
    int lenmax, minextend, n;
    int finished = TRUE;

    getyx(stdscr, ymin, x);
    ++ymin;
    getmaxyx(stdscr, ymax, xmax);
    ycol = ymax - ywords - 1;

    minextend = strlen(heading) + 2;
    if (offset) {
	minextend += 4;
	addstr("... ");
    }
    addline(heading);

    for (word = list + offset * ycol ; *word ; x += lenmax + 1) {
	lenmax = 0;
	for (y = 0 ; y < ycol ; ++y) {
	    if (!word[y])
		break;
	    n = strlen(word[y]);
	    if (n > lenmax)
		lenmax = n;
	}
	if (x + lenmax > xmax) {
	    finished = FALSE;
	    mvaddstr(ymin - 1, xmax - 3, "...");
	    break;
	}

	for (y = ymin ; y < ymax && *word ; ++y, ++word)
	    mvaddstr(y, x, *word);
    }

    if (minextend > x)
	x = minextend;
    if (x >= xmax)
	x = xmax - 1;
    move(ymin - 1, x);

    return finished;
}
Ejemplo n.º 19
0
Archivo: echo.c Proyecto: mbkulik/mg
/*
 * Do completion on a list of objects, listing instead of completing.
 */
static int
complt_list(int flags, char *buf, int cpos)
{
	struct list	*lh, *lh2, *lh3;
	struct list	*wholelist = NULL;
	struct buffer	*bp;
	int	 i, maxwidth, width;
	int	 preflen = 0;
	int	 oldrow = ttrow;
	int	 oldcol = ttcol;
	int	 oldhue = tthue;
	char	 *linebuf;
	size_t	 linesize, len;
	char *cp;

	lh = NULL;

	ttflush();

	/* The results are put into a completion buffer. */
	bp = bfind("*Completions*", TRUE);
	if (bclear(bp) == FALSE)
		return (FALSE);

	/*
	 * First get the list of objects.  This list may contain only
	 * the ones that complete what has been typed, or may be the
	 * whole list of all objects of this type.  They are filtered
	 * later in any case.  Set wholelist if the list has been
	 * cons'ed up just for us, so we can free it later.  We have
	 * to copy the buffer list for this function even though we
	 * didn't for complt.  The sorting code does destructive
	 * changes to the list, which we don't want to happen to the
	 * main buffer list!
	 */
	if ((flags & EFBUF) != 0)
		wholelist = lh = copy_list(&(bheadp->b_list));
	else if ((flags & EFFUNC) != 0) {
		buf[cpos] = '\0';
		wholelist = lh = complete_function_list(buf);
	} else if ((flags & EFFILE) != 0) {
		buf[cpos] = '\0';
		wholelist = lh = make_file_list(buf);
		/*
		 * We don't want to display stuff up to the / for file
		 * names preflen is the list of a prefix of what the
		 * user typed that should not be displayed.
		 */
		cp = strrchr(buf, '/');
		if (cp)
			preflen = cp - buf + 1;
	} else
		panic("broken complt call: flags");

	/*
	 * Sort the list, since users expect to see it in alphabetic
	 * order.
	 */
	lh2 = lh;
	while (lh2 != NULL) {
		lh3 = lh2->l_next;
		while (lh3 != NULL) {
			if (strcmp(lh2->l_name, lh3->l_name) > 0) {
				cp = lh2->l_name;
				lh2->l_name = lh3->l_name;
				lh3->l_name = cp;
			}
			lh3 = lh3->l_next;
		}
		lh2 = lh2->l_next;
	}

	/*
	 * First find max width of object to be displayed, so we can
	 * put several on a line.
	 */
	maxwidth = 0;
	lh2 = lh;
	while (lh2 != NULL) {
		for (i = 0; i < cpos; ++i) {
			if (buf[i] != lh2->l_name[i])
				break;
		}
		if (i == cpos) {
			width = strlen(lh2->l_name);
			if (width > maxwidth)
				maxwidth = width;
		}
		lh2 = lh2->l_next;
	}
	maxwidth += 1 - preflen;

	/*
	 * Now do the display.  Objects are written into linebuf until
	 * it fills, and then put into the help buffer.
	 */
	linesize = MAX(ncol, maxwidth) + 1;
	if ((linebuf = malloc(linesize)) == NULL) {
		free_file_list(wholelist);
		return (FALSE);
	}
	width = 0;

	/*
	 * We're going to strlcat() into the buffer, so it has to be
	 * NUL terminated.
	 */
	linebuf[0] = '\0';
	for (lh2 = lh; lh2 != NULL; lh2 = lh2->l_next) {
		for (i = 0; i < cpos; ++i) {
			if (buf[i] != lh2->l_name[i])
				break;
		}
		/* if we have a match */
		if (i == cpos) {
			/* if it wraps */
			if ((width + maxwidth) > ncol) {
				addline(bp, linebuf);
				linebuf[0] = '\0';
				width = 0;
			}
			len = strlcat(linebuf, lh2->l_name + preflen,
			    linesize);
			width += maxwidth;
			if (len < width && width < linesize) {
				/* pad so the objects nicely line up */
				memset(linebuf + len, ' ',
				    maxwidth - strlen(lh2->l_name + preflen));
				linebuf[width] = '\0';
			}
		}
	}
	if (width > 0)
		addline(bp, linebuf);
	free(linebuf);

	/*
	 * Note that we free lists only if they are put in wholelist lists
	 * that were built just for us should be freed.  However when we use
	 * the buffer list, obviously we don't want it freed.
	 */
	free_file_list(wholelist);
	popbuftop(bp, WEPHEM);	/* split the screen and put up the help
				 * buffer */
	update(CMODE);		/* needed to make the new stuff actually
				 * appear */
	ttmove(oldrow, oldcol);	/* update leaves cursor in arbitrary place */
	ttcolor(oldhue);	/* with arbitrary color */
	ttflush();
	return (0);
}
Ejemplo n.º 20
0
void T3DObjectStarMap::calculate()
{
	double x0,y0,z0,gr,fc;
	double hx,hy,hz,vx,vy,vz;
	T4color col2,col2L,col2R;

	double sx=sizex->G_val();
	double sy=sizey->G_val();
	double ssize=starsize->G_val();

	if (calculated) return;

	Tdoublearray &stars_MAG=G_3DCosmos().stars_MAG;
	Tdoublearray &stars_E1=G_3DCosmos().stars_E1;
	Tdoublearray &stars_E2=G_3DCosmos().stars_E2;

	Tarray<QString> &const_code=G_3DCosmos().const_code;
	Tdoublearray &const_E1_1=G_3DCosmos().const_E1_1;
	Tdoublearray &const_E1_2=G_3DCosmos().const_E1_2;
	Tdoublearray &const_E2_1=G_3DCosmos().const_E2_1;
	Tdoublearray &const_E2_2=G_3DCosmos().const_E2_2;

	//for stars

	starvertexbuffer.reset();starcolorbufferL.reset();starcolorbufferR.reset();startexturebuffer.reset();
	if (ssize>0)
	{
		for (int i=0; i<stars_E1.G_count(); i++)
		{
			x0=mapx(stars_E1[i]);
			y0=mapy(stars_E2[i]);
			z0=0;
			gr=(7-stars_MAG[i])/7;
			gr=sqrt(gr);
			if (gr<0.15) gr=0.15;
			if (gr>1.0) gr=1.0;
			fc=ssize*gr;
			hx=fc;hy=0;hz=0;
			vx=0;vy=fc;vz=0;

			col2.r=gr*color->G_R();
			col2.g=gr*color->G_G();
			col2.b=gr*color->G_B();
			col2.a=1*color->G_A();
			col2L=col2;col2L.ColMapL();
			col2R=col2;col2R.ColMapR();

			startexturebuffer.add(T2textureidx(0,0));
			starvertexbuffer.add(Tvec3d(x0-hx-vx,y0-hy-vy,z0-hz-vz));

			startexturebuffer.add(T2textureidx(0,1));
			starvertexbuffer.add(Tvec3d(x0-hx+vx,y0-hy+vy,z0-hz+vz));

			startexturebuffer.add(T2textureidx(1,1));
			starvertexbuffer.add(Tvec3d(x0+hx+vx,y0+hy+vy,z0+hz+vz));

			startexturebuffer.add(T2textureidx(1,0));
			starvertexbuffer.add(Tvec3d(x0+hx-vx,y0+hy-vy,z0+hz-vz));


			starcolorbufferL.add(col2L);starcolorbufferL.add(col2L);starcolorbufferL.add(col2L);starcolorbufferL.add(col2L);
			starcolorbufferR.add(col2R);starcolorbufferR.add(col2R);starcolorbufferR.add(col2R);starcolorbufferR.add(col2R);
		}
	}

	//for constellation lines
	conlinesvertexbuffer.reset();
	conlinestexturebuffer.reset();

	QString constname=singleconstellationname->G_string();

	double linesize=conlinesize->G_val();
	if (linesize>1.0e-9)
	{
		for (int i=0; i<const_E1_1.G_count(); i++)
			if ((qstrlen(constname)==0)||(issame(*const_code[i],constname)))
		{
			double xx1=mapx(const_E1_1[i]);
			double xx2=mapx(const_E1_2[i]);
			double yy1=mapy(const_E2_1[i]);
			double yy2=mapy(const_E2_2[i]);
			if (xx1>xx2)
			{
				double tmp=xx1; xx1=xx2; xx2=tmp;
				tmp=yy1; yy1=yy2; yy2=tmp;
			}
			if (fabs(xx1-xx2)<sx/2)
			{
				addline(xx1,yy1,xx2,yy2);
			}
			else
			{
				addline(xx2-sx,yy1,xx1,yy2);
				addline(xx2,yy1,xx1+sx,yy2);
			}
		}
	}
	calculated=true;
}
Ejemplo n.º 21
0
/*
 * XXX dname needs to have enough place to store an additional '/'.
 */
struct buffer *
dired_(char *dname)
{
	struct buffer	*bp;
	FILE	*dirpipe;
	char	 line[256];
	int	 len, ret;
#ifdef MONA
	DIR		*dirp;
	struct dirent	*dent;
    char* month_names[] = {"Jan", "Feb" ,"Mar" ,"Apr" ,"May" ,"Jun",
                           "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
#endif

	if ((dname = adjustname(dname, FALSE)) == NULL) {
		ewprintf("Bad directory name");
		return (NULL);
	}
	/* this should not be done, instead adjustname() should get a flag */
	len = strlen(dname);
	if (dname[len - 1] != '/') {
		dname[len++] = '/';
		dname[len] = '\0';
	}
	if ((bp = findbuffer(dname)) == NULL) {
		ewprintf("Could not create buffer");
		return (NULL);
	}
	if (bclear(bp) != TRUE)
		return (NULL);
	bp->b_flag |= BFREADONLY;

#ifdef MONA
	dirp = opendir(dname);
    assert(dirp);

	while ((dent = readdir(dirp)) != NULL) {
      snprintf(line, sizeof(line), "%s/%s", dname, dent->d_name);
      int year, month, day, hour, min, sec, size;
      mona_get_file_datetime_size(line, &year, &month, &day, &hour, &min, &sec, &size);
      char* month_name;
      if (month <= 12 && month >= 1) {
        month_name = month_names[month - 1];
      } else {
        //        assert(0);
        month_name = "---";
      }
      snprintf(line, sizeof(line), "  %crwxrwxrwx 1 mona mona   %d %s %02d %02d:%02d %s", fisdir(line) ? 'd' : '-', size, month_name, day, hour, min, dent->d_name);
      addline(bp, line);
    }
    closedir(dirp);
#else
#ifdef GNU_LS
# ifdef __CYGWIN__
	/* On Windows platforms the user or group name can be two
	 * words, such as "Domain Users" or "First Last." So, we must
	 * use the --numeric-uid-gid option of ls, or else we don't
	 * know where the filename starts.
	 */
	ret = snprintf(line, sizeof(line),
	    "ls -aln --time-style='+%%b %%d %%H:%%M' '%s'", dname);
# else
	ret = snprintf(line, sizeof(line),
	    "ls -al --time-style='+%%b %%d %%H:%%M' '%s'", dname);
# endif
#else
	ret = snprintf(line, sizeof(line), "ls -al '%s'", dname);
#endif /* GNU_LS */

	if (ret < 0 || ret  >= sizeof(line)) {
		ewprintf("Path too long");
		return (NULL);
	}
	if ((dirpipe = popen(line, "r")) == NULL) {
		ewprintf("Problem opening pipe to ls");
		return (NULL);
	}
	line[0] = line[1] = ' ';
	while (fgets(&line[2], sizeof(line) - 2, dirpipe) != NULL) {
		line[strcspn(line, "\n")] = '\0'; /* remove ^J	 */
		(void) addline(bp, line);
	}
	if (pclose(dirpipe) == -1) {
		ewprintf("Problem closing pipe to ls : %s",
		    strerror(errno));
		return (NULL);
	}
#endif
	bp->b_dotp = bfirstlp(bp);
	(void)strlcpy(bp->b_fname, dname, sizeof(bp->b_fname));
	(void)strlcpy(bp->b_cwd, dname, sizeof(bp->b_cwd));
	if ((bp->b_modes[1] = name_mode("dired")) == NULL) {
		bp->b_modes[0] = name_mode("fundamental");
		ewprintf("Could not find mode dired");
		return (NULL);
	}
	bp->b_nmodes = 1;
	return (bp);
}
Ejemplo n.º 22
0
/*ARGSUSED */
int
diffbuffer(int f, int n)
{
	struct buffer	*bp;
	struct line	*lp, *lpend;
	size_t		 len;
	int		 ret;
	char		*text, *ttext;
	char		* const argv[] =
	    {DIFFTOOL, "-u", "-p", curbp->b_fname, "-", (char *)NULL};

	len = 0;

	/* C-u is not supported */
	if (n > 1)
		return (ABORT);

	if (access(DIFFTOOL, X_OK) != 0) {
		dobeep();
		ewprintf("%s not found or not executable.", DIFFTOOL);
		return (FALSE);
	}

	if (curbp->b_fname[0] == 0) {
		dobeep();
		ewprintf("Cannot diff buffer not associated with any files.");
		return (FALSE);
	}

	lpend = curbp->b_headp;
	for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) {
		len+=llength(lp);
		if (lforw(lp) != lpend)		/* no implied \n on last line */
			len++;
	}
	if ((text = calloc(len + 1, sizeof(char))) == NULL) {
		dobeep();
		ewprintf("Cannot allocate memory.");
		return (FALSE);
	}
	ttext = text;

	for (lp = lforw(lpend); lp != lpend; lp = lforw(lp)) {
		if (llength(lp) != 0) {
			memcpy(ttext, ltext(lp), llength(lp));
			ttext += llength(lp);
		}
		if (lforw(lp) != lpend)		/* no implied \n on last line */
			*ttext++ = '\n';
	}

	bp = bfind("*Diff*", TRUE);
	bp->b_flag |= BFREADONLY;
	if (bclear(bp) != TRUE) {
		free(text);
		return (FALSE);
	}

	ret = pipeio(DIFFTOOL, argv, text, len, bp);

	if (ret == TRUE) {
		eerase();
		if (lforw(bp->b_headp) == bp->b_headp)
			addline(bp, "Diff finished (no differences).");
	}

	free(text);
	return (ret);
}
Ejemplo n.º 23
0
// {
//   account: <account>|<account_public_key>
//   account_index: <number>        // optional, defaults to 0.
//   ledger_hash : <ledger>
//   ledger_index : <ledger_index>
//   limit: integer                 // optional
//   marker: opaque                 // optional, resume previous query
// }
json::value doaccountlines (rpc::context& context)
{
    auto const& params (context.params);
    if (! params.ismember (jss::account))
        return rpc::missing_field_error ("account");

    ledger::pointer ledger;
    json::value result (rpc::lookupledger (params, ledger, context.netops));
    if (! ledger)
        return result;

    std::string strident (params[jss::account].asstring ());
    bool bindex (params.ismember (jss::account_index));
    int iindex (bindex ? params[jss::account_index].asuint () : 0);
    rippleaddress rippleaddress;

    json::value const jv (rpc::accountfromstring (ledger, rippleaddress, bindex,
        strident, iindex, false, context.netops));
    if (! jv.empty ())
    {
        for (json::value::const_iterator it (jv.begin ()); it != jv.end (); ++it)
            result[it.membername ()] = it.key ();

        return result;
    }

    if (! ledger->hasaccount (rippleaddress))
        return rpcerror (rpcact_not_found);

    std::string strpeer (params.ismember (jss::peer)
        ? params[jss::peer].asstring () : "");
    bool bpeerindex (params.ismember (jss::peer_index));
    int ipeerindex (bindex ? params[jss::peer_index].asuint () : 0);

    rippleaddress rippleaddresspeer;

    if (! strpeer.empty ())
    {
        result[jss::peer] = rippleaddress.humanaccountid ();

        if (bpeerindex)
            result[jss::peer_index] = ipeerindex;

        result = rpc::accountfromstring (ledger, rippleaddresspeer, bpeerindex,
            strpeer, ipeerindex, false, context.netops);

        if (! result.empty ())
            return result;
    }

    account rapeeraccount;
    if (rippleaddresspeer.isvalid ())
        rapeeraccount = rippleaddresspeer.getaccountid ();

    unsigned int limit;
    if (params.ismember (jss::limit))
    {
        auto const& jvlimit (params[jss::limit]);
        if (! jvlimit.isintegral ())
            return rpc::expected_field_error ("limit", "unsigned integer");

        limit = jvlimit.isuint () ? jvlimit.asuint () :
            std::max (0, jvlimit.asint ());

        if (context.role != role::admin)
        {
            limit = std::max (rpc::tuning::minlinesperrequest,
                std::min (limit, rpc::tuning::maxlinesperrequest));
        }
    }
    else
    {
        limit = rpc::tuning::defaultlinesperrequest;
    }

    json::value& jsonlines (result[jss::lines] = json::arrayvalue);
    account const& raaccount(rippleaddress.getaccountid ());
    visitdata visitdata = { {}, raaccount, rippleaddresspeer, rapeeraccount };
    unsigned int reserve (limit);
    uint256 startafter;
    std::uint64_t starthint;

    if (params.ismember (jss::marker))
    {
        // we have a start point. use limit - 1 from the result and use the
        // very last one for the resume.
        json::value const& marker (params[jss::marker]);

        if (! marker.isstring ())
            return rpc::expected_field_error ("marker", "string");

        startafter.sethex (marker.asstring ());
        sle::pointer sleline (ledger->getslei (startafter));

        if (sleline == nullptr || sleline->gettype () != ltripple_state)
            return rpcerror (rpcinvalid_params);

        if (sleline->getfieldamount (sflowlimit).getissuer () == raaccount)
            starthint = sleline->getfieldu64 (sflownode);
        else if (sleline->getfieldamount (sfhighlimit).getissuer () == raaccount)
            starthint = sleline->getfieldu64 (sfhighnode);
        else
            return rpcerror (rpcinvalid_params);

        // caller provided the first line (startafter), add it as first result
        auto const line (ripplestate::makeitem (raaccount, sleline));
        if (line == nullptr)
            return rpcerror (rpcinvalid_params);

        addline (jsonlines, *line, ledger);
        visitdata.items.reserve (reserve);
    }
    else
    {
        starthint = 0;
        // we have no start point, limit should be one higher than requested.
        visitdata.items.reserve (++reserve);
    }

    if (! ledger->visitaccountitems (raaccount, startafter, starthint, reserve,
        [&visitdata](sle::ref slecur)
        {
            auto const line (ripplestate::makeitem (visitdata.accountid, slecur));
            if (line != nullptr &&
                (! visitdata.rippleaddresspeer.isvalid () ||
                visitdata.rapeeraccount == line->getaccountidpeer ()))
            {
                visitdata.items.emplace_back (line);
                return true;
            }

            return false;
        }))
    {
        return rpcerror (rpcinvalid_params);
    }

    if (visitdata.items.size () == reserve)
    {
        result[jss::limit] = limit;

        ripplestate::pointer line (visitdata.items.back ());
        result[jss::marker] = to_string (line->peeksle ().getindex ());
        visitdata.items.pop_back ();
    }

    result[jss::account] = rippleaddress.humanaccountid ();

    for (auto const& item : visitdata.items)
        addline (jsonlines, *item.get (), ledger);

    context.loadtype = resource::feemediumburdenrpc;
    return result;
}
int main(int argc, char *argv[])
{
unsigned int repeat=0;
char **tags;
int i;
int a;
int b;
float gdivide_a;
float gdivide_b;


char are_you_sure[100];

#ifdef NAJI_DEBUG

 fprintf(stderr, "\n\n");
 fprintf(stderr, "NAJI_DEBUG - check if two commands are displayed as one joined string,\n");
 fprintf(stderr, "             you might have missed a , in najitool_valid_commands[]\n\n");

 for (i=0; i<NAJITOOL_MAX_COMMANDS; i++)               
 fprintf(stderr, "%s ", najitool_valid_commands[i]);
 fgetc(stdin);

#endif /* NAJI_DEBUG */



#ifdef NAJI_DEBUG
    fprintf(stderr, "\n\nNAJI_DEBUG - YOUR PARAMETERS/ARGUMENTS:\n\n");
    
    for (i=0; i<argc; i++)
    fprintf(stderr, "%s ", argv[i]);
    
    fprintf(stderr, "\n\n");

    fgetc(stdin);
#endif /* NAJI_DEBUG */



    if (argc >= 2)
    {
    tolowers(argv[1]);
    najitool_check_command(argv[1]);
    }


    if (argc == 1)
    {
    printf("\n\n");


/*
printf("           __    |         \n");
printf("          /  \\   |        \n");
printf("     /   _____|  | o \\    \n");
printf("    |    \\  o    |___|    \n");
printf("     \\____\\              \n");
printf("      o o    T O O L       \n");
*/


printf("           __    |          ********************************************\n");
printf("          /  \\   |               najitool 0.8.4 using libnaji 0.6.4     \n");
printf("     /   _____|  | o \\            both written by NECDET COKYAZICI      \n");
printf("    |    \\  o    |___|                   and contributors              \n");
printf("     \\____\\                 ********************************************\n");
printf("      o o    T O O L         No warranty, to view the license type:     \n");
printf("                                         najitool license               \n");
printf("  http://najitool.sf.net/   ********************************************\n");
printf("                             To view the credits type: najitool credits \n");
printf("  Public Domain, 2003-2011  ********************************************\n");
printf("\n");


forhelp();


    return 0;
    }



    if (argc >= 2)
    {


        if (!strcmp(argv[1], "mp3taged"))
        {

            if ((argc % 2 != 1) | (argc == 3))
            {
            printf("mp3taged: too few arguments '%s'\n", argv[1]);
            return 1;
            }

            /*
             * we save the tags' options:
             * tags[i] = <tag name>
             * tags[i+1] = <user content>
             * ..
             */

            tags = (char**) malloc (sizeof(char*)*(argc-3)*2);

            for (i=0; i<(argc-3)*2; i+=2)
            tags[i] = (char*) malloc(7*sizeof(char));

            for (i=1; i<(argc-3)*2; i+=2)
            tags[i] = argv[i+2];

            for (i=0; i<(argc-3)*2; i+=2)
            memcpy (tags[i], argv[i+2], 7);

            mp3editag (argv[argc-1], tags, argc-3);

            for (i=0; i<(argc-3)*2; i+=2)
            free(tags[i]);

            free(tags);

        return 0;
        }

        if (!strcmp(argv[1], "credits"))
        {

            if (argc > 2)
            tooparam("credits");

            naji_credits();

            return 0;
        }

        if (!strcmp(argv[1], "asctable"))
        {

            if (argc > 2)
            tooparam("asctable");

            asctable();
            return 0;
        }

        if (!strcmp(argv[1], "engnum"))
        {

            if (argc > 2)
            tooparam("engnum");

            engnum();
            return 0;
        }

        if (!strcmp(argv[1], "turnum"))
        {

            if (argc > 2)
            tooparam("turnum");
     
            turnum();
            return 0;
        }

        if (!strcmp(argv[1], "najcrypt"))
        {

            if (argc > 2)
            tooparam("najcrypt");

            najcrypt();
            return 0;
        }

        if (!strcmp(argv[1], "database"))
        {

            if (argc > 2)
            tooparam("database");
    
            naji_database();
            return 0;
        }

        if (!strcmp(argv[1], "html_db"))
        {

            if (argc > 2)
            tooparam("html_db");

            naji_html_database();
            return 0;
        }

        if (!strcmp(argv[1], "calc"))
        {

            if (argc > 2)
            tooparam("calc");

            naji_calc();
            return 0;
        }

        if (!strcmp(argv[1], "length"))
        {

            if (argc > 2)
            tooparam("length");

            length();
            return 0;
        }

        if (!strcmp(argv[1], "mathgame"))
        {

            if (argc > 2)
            tooparam("mathgame");

            mathgame();
            return 0;
        }

        if (!strcmp(argv[1], "license"))
        {

            if (argc > 2)
            tooparam("license");

            naji_license();
            return 0;
        }

        if (!strcmp(argv[1], "ttt"))
        {

            if (argc > 2)
            tooparam("ttt");

            ttt();
            return 0;
        }

        if (!strcmp(argv[1], "naji_bmp"))
        {
            if (argc > 2)
            tooparam("naji_bmp");

            naji_bmp();
            return 0;
        }

        if (!strcmp(argv[1], "unihtml"))
        {

            if (argc > 2)
            tooparam("unihtml");

            naji_gen_unicode_html_pages();
            return 0;
        }
    
        if (!strcmp(argv[1], "rmunihtm"))
        {

            if (argc > 2)
            tooparam("rmunihtm");
    
            naji_del_gen_unicode_html_pages();
            return 0;
        }
    
        if (!strcmp(argv[1], "cat_text"))
        {

            if (argc == 2)
            {
            naji_stdin_msg();
            cat_text_stdin();
            return 0;
            }

            if (argc == 3)
            {
            cat_text(argv[2]);
            return 0;
            }

            if (argc > 3)
            tooparam("cat_text");

            return 0;
        }

        if (!strcmp(argv[1], "kitten"))
        {

            if (argc == 2)
            {
            naji_stdin_msg();
            kitten_stdin();
            return 0;
            }

            if (argc == 3)
            {
            kitten(argv[2]);
            return 0;
            }

            if (argc > 3)
            tooparam("kitten");

        return 0;
        }

        if (!strcmp(argv[1], "genlic"))
        {

            if (argc > 2)
            tooparam("genlic");

            naji_genlic();
            return 0;
        }

        if (!strcmp(argv[1], "genhelp"))
        {

            if (argc > 2)
            tooparam("genhelp");

            najitool_generate_help();
            return 0;
        }

        if (!strcmp(argv[1], "htmlhelp"))
        {
            if (argc > 2)
            tooparam("htmlhelp");

            najitool_generate_help_html();
            return 0;
        }

        if (!strcmp(argv[1], "systemdt"))
        {
            if (argc > 2)
            tooparam("systemdt");
        
            systemdt();
            return 0;
        }


        if (!strcmp(argv[1], "datetime"))
        {

            if (argc > 2)
            tooparam("datetime");

            datetime();
            return 0;
        }

        if (!strcmp(argv[1], "telltime"))
        {

            if (argc > 2)
            tooparam("telltime");

            printf("\n\n");
            telltime();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "today"))
        {

            if (argc > 2)
            tooparam("today");

            printf("\n\n");
            today();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "dayofmon"))
        {

            if (argc > 2)
            tooparam("dayofmon");
    
            printf("\n\n");
            dayofmon();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "month"))
        {

            if (argc > 2)
            tooparam("month");

            printf("\n\n");
            month();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "year"))
        {

            if (argc > 2)
            tooparam("year");

            printf("\n\n");
            year();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "saatarih"))
        {

            if (argc > 2)
            tooparam("saatarih");

            saatarih();
            return 0;
        }

        if (!strcmp(argv[1], "saat"))
        {

            if (argc > 2)
            tooparam("saat");

            printf("\n\n");
            saat();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "bugun"))
        {
            if (argc > 2)
            tooparam("bugun");

            printf("\n\n");
            bugun();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "ayinkaci"))
        {

            if (argc > 2)
            tooparam("ayinkaci");

            printf("\n\n");
            ayinkaci();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "ay"))
        {

            if (argc > 2)
            tooparam("ay");

            printf("\n\n");
            ay();
            printf("\n\n");

            return 0;
        }

        if (!strcmp(argv[1], "yil"))
        {
            if (argc > 2)
            tooparam("yil");

            printf("\n\n");
            yil();
            printf("\n\n");

            return 0;
        }


        if (!strcmp(argv[1], "allbmp16"))
        {
            if (argc > 2)
            tooparam("allbmp16");

            printf("\n\n");
            allbmp16();
            printf("\n\n");

            return 0;
        }


        if (!strcmp(argv[1], "help"))
        {

            if (argc == 2)
            {
            printf("\n\nAvailable help catagories:\n\n");
            printf("commands\n");
            printf("\n\n");
            forhelp();
            return 0;
            }


            if (argc == 3)
            {

                  if (!strcmp(argv[2], "commands"))
                  najitool_help_commands();

                  else najitool_command_help(argv[2]);

                  return 0;
            }


            if (argc > 3)
            tooparam("help");

            return 0;
        }



begin_cmd("mergline", 7)
mergline(argv[2], argv[3], argv[4], argv[5], argv[6]);
end_cmd()

begin_cmd("mp3split", 6)
mp3split(argv[4], argv[5], atoi(argv[2]), atoi(argv[3]));
end_cmd()

begin_cmd("rrrchars", 6)
rrrchars(argv[2], argv[3], atoi(argv[4]), atoi(argv[5]));
end_cmd()

begin_cmd("chstr", 6)
chstr(argv[2], argv[3], argv[4], argv[5]);
end_cmd()

begin_cmd("chchars", 6)
chchars(argv[2], argv[3], argv[4], argv[5]);
end_cmd()

begin_cmd("chchar", 6)
chchar(argv[2], argv[3], argv[4][0], argv[5][0]);
end_cmd()

begin_cmd("filechop", 6)
filechop( (strtol(argv[2], NULL, 0)), argv[3], argv[4], argv[5]);
end_cmd()
        
begin_cmd("putlines", 6)
putlines(argv[2], argv[3], argv[4], argv[5]);
end_cmd()

begin_cmd("copyoffs", 6)
copyoffs(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0), argv[5]);
end_cmd()

begin_cmd("istrael", 6)
istrael(argv[2], atoi(argv[3]), argv[4], argv[5]);
end_cmd()

begin_cmd("addline", 6)
addline(argv[2], argv[3], argv[4], strtoul(argv[5], NULL, 0));
end_cmd()

begin_cmd("replacel", 6)
replacel(argv[2], argv[3], argv[4], strtoul(argv[5], NULL, 0));
end_cmd()


begin_cmd("bremline", 5)
bremline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("eremline", 5)
eremline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("remline", 5)
remline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("skipstr", 5)
skipstr(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("makarray", 5)
makarray(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("streline", 5)
streline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("strbline", 5)
strbline(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("swapfeb", 5)
swapfeb(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("filbreed", 5)
filbreed(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("skipchar", 5)
skipchar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("onlychar", 5)
onlychar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("repchar", 5)
repeat = (unsigned int) atoi(argv[4]);
repchar(argv[2], argv[3], repeat);
end_cmd()

begin_cmd("linesnip", 5)
repeat = (unsigned int) atoi(argv[2]);
linesnip(repeat, argv[3], argv[4]);
end_cmd()

begin_cmd("charwarp", 5)
repeat = (unsigned int) atoi(argv[4]);
charwrap(repeat, argv[2], argv[3]);
end_cmd()

begin_cmd("repcharp", 5)
repeat = (unsigned int) atoi(argv[4]);
repcharp(argv[2], argv[3], repeat);
end_cmd()

begin_cmd("coffset", 5)
coffset(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0));
end_cmd()

begin_cmd("dumpoffs", 5)
dumpoffs(argv[2], strtoul(argv[3], NULL, 0), strtoul(argv[4], NULL, 0));
end_cmd()

begin_cmd("bin2c", 5)
bin2c(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("filejoin", 5)
filejoin(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("mkpatch", 5)
mkpatch(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("charfile", 5)
repeat = (unsigned int) atoi(argv[3]);
charfile(argv[2], repeat, argv[4][0]);
end_cmd()

begin_cmd("strfile", 5)
repeat = (unsigned int) atoi(argv[3]);
strfile(argv[2], repeat, argv[4]);
end_cmd()

begin_cmd("tabspace", 5)
repeat = atoi(argv[2]);
tabspace(repeat, argv[3], argv[4]);
end_cmd()

begin_cmd("charaftr", 5)
charaftr(argv[2], argv[3], argv[4][0]);
end_cmd()

begin_cmd("charbefr", 5)
charbefr(argv[2], argv[3], argv[4][0]);
end_cmd()

begin_cmd("strachar", 5)
strachar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("strbchar", 5)
strbchar(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("rstrach", 5)
rstrach(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("rstrbch", 5)
rstrbch(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("cpfroml", 5)
cpfroml(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("cptiline", 5)
cptiline(atoi(argv[2]), argv[3], argv[4]);
end_cmd()

begin_cmd("n2ch", 5)
n2ch(argv[2][0], argv[3], argv[4]);
end_cmd()

begin_cmd("n2str", 5)
n2str(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("weakrypt", 5)
weakrypt(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("sp2ce2sp", 5)
sp2ce2sp(argv[2][0], argv[3], argv[4]);
end_cmd()

begin_cmd("istreml", 5)
istreml(argv[2], argv[3], argv[4]);
end_cmd()

begin_cmd("removel", 5)
removel(argv[2], argv[3], strtoul(argv[4], NULL, 0));
end_cmd()




begin_cmd("printftx", 4)
printftx(argv[2], argv[3]);
end_cmd()

begin_cmd("lensorts", 4)
lensorts(argv[2], argv[3]);
end_cmd()

begin_cmd("lensortl", 4)
lensortl(argv[2], argv[3]);
end_cmd()

begin_cmd("find", 4)
find(argv[2], argv[3]);
end_cmd()

begin_cmd("findi", 4)
findi(argv[2], argv[3]);
end_cmd()

begin_cmd("cfind", 4)
cfind(argv[2], argv[3]);
end_cmd()

begin_cmd("cfindi", 4)
cfindi(argv[2], argv[3]);
end_cmd()

begin_cmd("showline", 4)
showline(argv[2], atoi(argv[3]));
end_cmd()

begin_cmd("cat_tail", 4)
cat_tail(argv[2], atoi(argv[3]));
end_cmd()

begin_cmd("cat_head", 4)
cat_head(argv[2], atoi(argv[3]));
end_cmd()

begin_cmd("getlinks", 4)
getlinks(argv[2], argv[3]);
end_cmd()

begin_cmd("f2upper", 4)
f2upper(argv[2], argv[3]);
end_cmd()

begin_cmd("f2lower", 4)
f2lower(argv[2], argv[3]);
end_cmd()

begin_cmd("fswpcase", 4)
fswpcase(argv[2], argv[3]);
end_cmd()

begin_cmd("downlist", 4)
downlist(argv[2], argv[3]);
end_cmd()

begin_cmd("hilist", 4)
hilist(argv[2], argv[3]);
end_cmd()

begin_cmd("rtcafter", 4)
rtcafter(argv[2], argv[3]);
end_cmd()

begin_cmd("rtcbefor", 4)
rtcbefor(argv[2], argv[3]);
end_cmd()

begin_cmd("rbcafter", 4)
rbcafter(argv[2], argv[3]);
end_cmd()

begin_cmd("rbcbefor", 4)
rbcbefor(argv[2], argv[3]);
end_cmd()

begin_cmd("numlines", 4)
numlines(argv[2], argv[3]);
end_cmd()

begin_cmd("file2dec", 4)
file2dec(argv[2], argv[3]);
end_cmd()

begin_cmd("file2hex", 4)
file2hex(argv[2], argv[3]);
end_cmd()

begin_cmd("file2bin", 4)
file2bin(argv[2], argv[3]);
end_cmd()

begin_cmd("wordline", 4)
wordline(argv[2], argv[3]);
end_cmd()

begin_cmd("8bit256", 4)
repeat = (unsigned int) atoi(argv[3]);
_8bit256(argv[2], repeat);
end_cmd()

begin_cmd("eng2arab", 4)
eng2arab(argv[2], argv[3]);
end_cmd()

begin_cmd("arab2eng", 4)
arab2eng(argv[2], argv[3]);
end_cmd()

begin_cmd("e2ahtml", 4)
e2ahtml(argv[2], argv[3]);
end_cmd()

begin_cmd("freverse", 4)
freverse(argv[2], argv[3]);
end_cmd()

begin_cmd("repcat", 4)
repeat = (unsigned int) atoi(argv[3]);
repcat(argv[2], repeat);
end_cmd()

begin_cmd("repcatpp", 4)
repeat = (unsigned int) atoi(argv[3]);
repcatpp(argv[2], repeat);
end_cmd()

begin_cmd("copyfile", 4)
copyfile(argv[2], argv[3]);
end_cmd()

begin_cmd("qpatch", 4)
qpatch(argv[2], argv[3]);
end_cmd()

begin_cmd("flipcopy", 4)
flipcopy(argv[2], argv[3]);
end_cmd()

begin_cmd("fillfile", 4)
fillfile(argv[2], argv[3][0]);
end_cmd()

begin_cmd("bin2text", 4)
bin2text(argv[2], argv[3]);
end_cmd()

begin_cmd("bin2hexi", 4)
bin2hexi(argv[2], argv[3]);
end_cmd()

begin_cmd("rndbfile", 4)
rndbfile(argv[2], strtoul(argv[3], NULL, 0));
end_cmd()

begin_cmd("rndtfile", 4)
rndtfile(argv[2], strtoul(argv[3], NULL, 0));
end_cmd()

begin_cmd("skipcat", 4)
skipcat(argv[2], argv[3]);
end_cmd()

begin_cmd("onlycat", 4)
onlycat(argv[2], argv[3]);
end_cmd()

begin_cmd("bigascif", 4)
bigascif(argv[2], argv[3]);
end_cmd()

begin_cmd("leetfile", 4)
leetfile(argv[2], argv[3]);
end_cmd()

begin_cmd("asc2ebc", 4)
asc2ebc(argv[2], argv[3]);
end_cmd()

begin_cmd("ebc2asc", 4)
ebc2asc(argv[2], argv[3]);
end_cmd()

begin_cmd("unix2dos", 4)
unix2dos(argv[2], argv[3]);
end_cmd()

begin_cmd("dos2unix", 4)
dos2unix(argv[2], argv[3]);
end_cmd()

begin_cmd("uuencode", 4)
uuencode(argv[2], argv[3]);
end_cmd()

begin_cmd("uudecode", 4)
uudecode(argv[2], argv[3]);
end_cmd()

begin_cmd("wordwrap", 4)
wordwrap(argv[2], argv[3]);
end_cmd()

begin_cmd("compare", 4)
compare(argv[2], argv[3]);
end_cmd()

begin_cmd("ccompare", 4)
ccompare(argv[2], argv[3]);
end_cmd()

begin_cmd("hmakerf", 4)
hmakerf(argv[2], argv[3]);
end_cmd()

begin_cmd("qcrypt", 4)
qcrypt(argv[2], argv[3]);
end_cmd()

begin_cmd("revlines", 4)
revlines(argv[2], argv[3]);
end_cmd()

begin_cmd("html2txt", 4)
html2txt(argv[2], argv[3]);
end_cmd()

begin_cmd("txt2html", 4)
txt2html(argv[2], argv[3]);
end_cmd()

begin_cmd("htmlfast", 4)
htmlfast(argv[2], argv[3]);
end_cmd()

begin_cmd("onlalnum", 4)
onlalnum(argv[2], argv[3]);
end_cmd()

begin_cmd("onlalpha", 4)
onlalpha(argv[2], argv[3]);
end_cmd()

begin_cmd("onlcntrl", 4)
onlcntrl(argv[2], argv[3]);
end_cmd()

begin_cmd("onldigit", 4)
onldigit(argv[2], argv[3]);
end_cmd()

begin_cmd("onlgraph", 4)
onlgraph(argv[2], argv[3]);
end_cmd()

begin_cmd("onllower", 4)
onllower(argv[2], argv[3]);
end_cmd()

begin_cmd("onlprint", 4)
onlprint(argv[2], argv[3]);
end_cmd()

begin_cmd("onlpunct", 4)
onlpunct(argv[2], argv[3]);
end_cmd()

begin_cmd("onlspace", 4)
onlspace(argv[2], argv[3]);
end_cmd()

begin_cmd("onlupper", 4)
onlupper(argv[2], argv[3]);
end_cmd()

begin_cmd("onlxdigt", 4)
onlxdigt(argv[2], argv[3]);
end_cmd()

begin_cmd("skpalnum", 4)
skpalnum(argv[2], argv[3]);
end_cmd()

begin_cmd("skpalpha", 4)
skpalpha(argv[2], argv[3]);
end_cmd()

begin_cmd("skpcntrl", 4)
skpcntrl(argv[2], argv[3]);
end_cmd()

begin_cmd("skpdigit", 4)
skpdigit(argv[2], argv[3]);
end_cmd()

begin_cmd("skpgraph", 4)
skpgraph(argv[2], argv[3]);
end_cmd()

begin_cmd("skplower", 4)
skplower(argv[2], argv[3]);
end_cmd()

begin_cmd("skpprint", 4)
skpprint(argv[2], argv[3]);
end_cmd()

begin_cmd("skppunct", 4)
skppunct(argv[2], argv[3]);
end_cmd()

begin_cmd("skpspace", 4)
skpspace(argv[2], argv[3]);
end_cmd()

begin_cmd("skpupper", 4)
skpupper(argv[2], argv[3]);
end_cmd()

begin_cmd("skpxdigt", 4)
skpxdigt(argv[2], argv[3]);
end_cmd()

begin_cmd("ftothe", 4)
ftothe(argv[2], argv[3]);
end_cmd()

begin_cmd("blanka", 4)
blanka(argv[2], argv[3]);
end_cmd()

begin_cmd("unblanka", 4)
unblanka(argv[2], argv[3]);
end_cmd()

begin_cmd("najirle", 4)
najirle(argv[2], argv[3]);
end_cmd()

begin_cmd("unajirle", 4)
unajirle(argv[2], argv[3]);
end_cmd()


begin_cmd("gplus", 4)
a = atoi(argv[2]);
b = atoi(argv[3]);
gplus(a, b);
end_cmd()


begin_cmd("gminus", 4)
a = atoi(argv[2]);
b = atoi(argv[3]);
gminus(a, b);
end_cmd()


begin_cmd("gtimes", 4)
a = atoi(argv[2]);
b = atoi(argv[3]);
gtimes(a, b);
end_cmd()


begin_cmd("gdivide", 4)
gdivide_a = atof(argv[2]);
gdivide_b = atof(argv[3]);
gdivide(gdivide_a, gdivide_b);
end_cmd()


begin_cmd("bytsplit", 4)
bytsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("kbsplit", 4)
kbsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("mbsplit", 4)
mbsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("gbsplit", 4)
gbsplit(argv[2], atol(argv[3]));
end_cmd()

begin_cmd("mjoin", 4)
mjoin(argv[2], argv[3]);
end_cmd()


begin_cmd("listdigt", 4)
listdigt(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("listlowr", 4)
listlowr(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("listprnt", 4)
listprnt(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("listuppr", 4)
listuppr(atoi(argv[2]), argv[3]);
end_cmd()

begin_cmd("charsort", 4)
charsort(argv[2], argv[3]);
end_cmd()

begin_cmd("sp2re2sp", 4)
sp2re2sp(argv[2], argv[3]);
end_cmd()









begin_cmd("lcvfiles", 3)
lcvfiles(argv[2]);
end_cmd()

begin_cmd("rcvfiles", 3)
rcvfiles(argv[2]);
end_cmd()


begin_cmd("mp3tagnf", 3)
mp3info(argv[2]);
end_cmd()

begin_cmd("catrandl", 3)
catrandl(argv[2]);
end_cmd()

begin_cmd("leetstr", 3)
printf("\n\n");
leetstr(argv[2]);
printf("\n\n");
end_cmd()

begin_cmd("lcharvar", 3)
lcharvar(argv[2]);
end_cmd()

begin_cmd("rcharvar", 3)
rcharvar(argv[2]);
end_cmd()

begin_cmd("hexicat", 3)
hexicat(argv[2]);
end_cmd()

begin_cmd("rndffill", 3)
rndffill(argv[2]);
end_cmd()

begin_cmd("zerokill", 3)
zerokill(argv[2]);
end_cmd()

begin_cmd("randkill", 3)
randkill(argv[2]);
end_cmd()

begin_cmd("najisum", 3)
najisum(argv[2]);
end_cmd()


begin_cmd("rndbsout", 3)
rndbsout(strtoul(argv[2], NULL, 0));
end_cmd()

begin_cmd("rndtsout", 3)
rndtsout(strtoul(argv[2], NULL, 0));
end_cmd()

begin_cmd("patch", 3)
patch(argv[2]);
end_cmd()

begin_cmd("revcat", 3)
revcat(argv[2]);
end_cmd()

begin_cmd("copyself", 3)
copyfile(argv[0], argv[2]);
end_cmd()

begin_cmd("bigascii", 3)
bigascii(argv[2]);
end_cmd()

begin_cmd("hmaker", 3)
hmaker(argv[2]);
end_cmd()

begin_cmd("wrdcount", 3)
printf("\n\n%i\n\n", wrdcount(argv[2]));
end_cmd()

begin_cmd("addim", 3)
addim(atoi(argv[2]));
end_cmd()

begin_cmd("allfiles", 3)

fprintf(stderr, 
"\n"
"NOTE: On most systems you can stop with Ctrl+C\n"
"WARNING: This will make a lot of files.\n"
"Are you sure? type YES to continue\n"
"or anything else to quit.\n"
);
safegets(are_you_sure, 80);
            
if (!strcmp(are_you_sure, "YES"))
allfiles(atol(argv[2]));
end_cmd();        

begin_cmd("tothe", 3)
tothe(argv[2]);
end_cmd()

begin_cmd("vowelwrd", 3)
vowelwrd(argv[2]);
end_cmd()

begin_cmd("gigabyte", 3)
gigabyte(strtoul(argv[2], NULL, 0));
end_cmd()

begin_cmd("sort", 3)
sort(argv[2]);
end_cmd()

begin_cmd("sortlast", 3)
sortlast(argv[2]);
end_cmd()

begin_cmd("lineback", 3)
lineback(argv[2]);
end_cmd()

begin_cmd("longline", 3)
longline(argv[2]);
end_cmd()

begin_cmd("howline", 3)
howline(argv[2]);
end_cmd()

begin_cmd("rndlines", 3)
rndlines(argv[2]);
end_cmd()

begin_cmd("spyramid", 3)
spyramid(argv[2]);
end_cmd()


    } /* if (argc >= 2) */

return 0;         
}
Ejemplo n.º 25
0
/*
 * This routine rebuilds the text in the special secret buffer that holds the
 * buffer list. It is called by the list buffers command. Return TRUE if
 * everything works. Return FALSE if there is an error (if there is no
 * memory).
 */
int makelist ()
{
  BUFFER *bp;
  LINE *lp;
  char *cp1, *cp2;
  char b[8], line[128];
  int nbytes, s, c;

  blistp->b_flag &= ~BFCHG;	/* Don't complain! */
  if ((s = bclear (blistp)) != TRUE) /* Blow old text away */
    return (s);
  strncpy (blistp->b_fname, "", 1);
  if (addline ("ACV    Size Buffer           File") == FALSE ||
      addline ("--- ------- ------           ----") == FALSE)
    return (FALSE);
  bp = bheadp;

  /* build line to report global mode settings */
  cp1 = &line[0];
  *cp1++ = ' ';
  *cp1++ = ' ';
  *cp1++ = ' ';
  *cp1++ = ' ';

  /* output the list of buffers */
  while (bp != 0)
    {
      if ((bp->b_flag & BFTEMP) != 0)
	{				/* Skip magic ones */
	  bp = bp->b_bufp;
	  continue;
	}
      cp1 = &line[0];		/* Start at left edge */

      /* output status of ACTIVE flag (has the file been read in? */
      if (bp->b_active == TRUE)	 /* "@" if activated */
	*cp1++ = '@';
      else
	*cp1++ = ' ';

      /* output status of changed flag */
      if ((bp->b_flag & BFCHG) != 0) /* "*" if changed */
	*cp1++ = '*';
      else
	*cp1++ = ' ';

      /* output status of readonly flag */
      if ((bp->b_flag & BFRO) != 0) /* "%" if view mode */
	*cp1++ = '%';
      else
	*cp1++ = ' ';
      *cp1++ = ' ';		/* Gap */

      nbytes = 0;			/* Count bytes in buf */
      lp = lforw (bp->b_linep);
      while (lp != bp->b_linep)
	{
	  nbytes += llength (lp) + 1;
	  lp = lforw (lp);
	}
      itoa (b, 7, nbytes);	/* 7 digit buffer size */
      cp2 = &b[0];
      while ((c = *cp2++) != 0)
	*cp1++ = (char)c;
      *cp1++ = ' ';		/* Gap */
      cp2 = &bp->b_bname[0];	/* Buffer name */
      while ((c = *cp2++) != 0)
	*cp1++ = (char)c;
      cp2 = &bp->b_fname[0];	/* File name */
      if (*cp2 != 0)
	{
	  while (cp1 < &line[3 + 1 + 7 + 1 + NBUFN + 1]) /* ACV, space, size, space, bufname, space */
	    *cp1++ = ' ';
	  while ((c = *cp2++) != 0)
	    {
	      if (cp1 < &line[128 - 1])
		*cp1++ = (char)c;
	    }
	}
      *cp1 = 0;			/* Add to the buffer */
      if (addline (line) == FALSE)
	return (FALSE);
      bp = bp->b_bufp;
    }
  return (TRUE);		/* All done */
}
Ejemplo n.º 26
0
Archivo: grep.c Proyecto: WizardGed/mg
struct buffer *
compile_mode(const char *name, const char *command)
{
	struct buffer	*bp;
	FILE	*fpipe;
	char	*buf;
	size_t	 len;
	int	 ret, n;
	char	 cwd[NFILEN], qcmd[NFILEN];
	char	 timestr[NTIME];
	time_t	 t;

	n = snprintf(qcmd, sizeof(qcmd), "%s 2>&1", command);
	if (n < 0 || n >= sizeof(qcmd))
		return (NULL);

	bp = bfind(name, TRUE);
	if (bclear(bp) != TRUE)
		return (NULL);

	if (getbufcwd(bp->b_cwd, sizeof(bp->b_cwd)) != TRUE)
		return (NULL);
	addlinef(bp, "cd %s", bp->b_cwd);
	addline(bp, qcmd);
	addline(bp, "");

	if (getcwd(cwd, sizeof(cwd)) == NULL)
		panic("Can't get current directory!");
	if (chdir(bp->b_cwd) == -1) {
		dobeep();
		ewprintf("Can't change dir to %s", bp->b_cwd);
		return (NULL);
	}
	if ((fpipe = popen(qcmd, "r")) == NULL) {
		dobeep();
		ewprintf("Problem opening pipe");
		return (NULL);
	}
	/*
	 * We know that our commands are nice and the last line will end with
	 * a \n, so we don't need to try to deal with the last line problem
	 * in fgetln.
	 */
	while ((buf = fgetln(fpipe, &len)) != NULL) {
		buf[len - 1] = '\0';
		addline(bp, buf);
	}
	ret = pclose(fpipe);
	t = time(NULL);
	strftime(timestr, sizeof(timestr), "%a %b %e %T %Y", localtime(&t));
	addline(bp, "");
	if (ret != 0)
		addlinef(bp, "Command exited abnormally with code %d"
		    " at %s", ret, timestr);
	else
		addlinef(bp, "Command finished at %s", timestr);

	bp->b_dotp = bfirstlp(bp);
	bp->b_modes[0] = name_mode("fundamental");
	bp->b_modes[1] = name_mode("compile");
	bp->b_nmodes = 1;

	compile_buffer = bp;

	if (chdir(cwd) == -1) {
		dobeep();
		ewprintf("Can't change dir back to %s", cwd);
		return (NULL);
	}
	return (bp);
}
Ejemplo n.º 27
0
// {
//   account: [<account>|<account_public_key>]
//   peer: [<account>|<account_public_key>]
//   currency: <currency>
//   ledger_hash : <ledger>
//   ledger_index : <ledger_index>
// }
json::value doaccountasset (rpc::context& context)
{
    auto const& params(context.params);
    if (!params.ismember(jss::account))
        return rpc::missing_field_error("account");
    if (!params.ismember(jss::peer))
        return rpc::missing_field_error("peer");
    if (!params.ismember(jss::currency))
        return rpc::missing_field_error("currency");

    ledger::pointer ledger;
    json::value result(rpc::lookupledger(params, ledger, context.netops));
    if (!ledger)
        return result;

    std::string strident(params[jss::account].asstring());
    bool bindex(params.ismember(jss::account_index));
    int iindex(bindex ? params[jss::account_index].asuint() : 0);
    rippleaddress rippleaddress;

    json::value const jv(rpc::accountfromstring(ledger, rippleaddress, bindex,
                                                strident, iindex, false, context.netops));
    if (!jv.empty()) {
        for (json::value::const_iterator it(jv.begin()); it != jv.end(); ++it)
            result[it.membername()] = it.key();

        return result;
    }

    if (!ledger->hasaccount(rippleaddress))
        return rpcerror(rpcact_not_found);

    std::string strpeer(params.ismember(jss::peer) ? params[jss::peer].asstring() : "");
    bool bpeerindex(params.ismember(jss::peer_index));
    int ipeerindex(bindex ? params[jss::peer_index].asuint() : 0);
    rippleaddress rippleaddresspeer;

    json::value const jvpeer(rpc::accountfromstring(ledger, rippleaddresspeer, bpeerindex,
                                                    strpeer, ipeerindex, false, context.netops));
    if (!jvpeer.empty()) {
        return result;
    }

    if (!ledger->hasaccount(rippleaddresspeer))
        return rpcerror(rpcact_not_found);

    currency ucurrency;
    if (!to_currency(ucurrency, params[jss::currency].asstring()))
        return rpc::make_error(rpcsrc_cur_malformed, "invalid field 'currency', bad currency.");

    account const& raaccount(rippleaddress.getaccountid());
    account const& rapeeraccount(rippleaddresspeer.getaccountid());

    uint256 unodeindex = getripplestateindex(raaccount, rapeeraccount, ucurrency);
    auto slenode = context.netops.getslei(ledger, unodeindex);
    auto const line(ripplestate::makeitem(raaccount, slenode));

    if (line == nullptr ||
        raaccount != line->getaccountid() ||
        rapeeraccount != line->getaccountidpeer())
        return result;

    json::value jsonlines(json::arrayvalue);
    addline(jsonlines, *line, ledger);
    result[jss::lines] = jsonlines[0u];
    
    json::value& jsonassetstates(result[jss::states] = json::arrayvalue);
    
    // get asset_states for currency asset.
    if (assetcurrency() == line->getbalance().getcurrency()) {
        auto lpledger = std::make_shared<ledger> (std::ref (*ledger), false);
        ledgerentryset les(lpledger, tapnone);
        auto sleripplestate = les.entrycache(ltripple_state, getripplestateindex(raaccount, rapeeraccount, assetcurrency()));
        les.assetrelease(raaccount, rapeeraccount, assetcurrency(), sleripplestate);

        uint256 baseindex = getassetstateindex(line->getaccountid(), line->getaccountidpeer(), assetcurrency());
        uint256 assetstateindex = getqualityindex(baseindex);
        uint256 assetstateend = getqualitynext(assetstateindex);

        for (;;) {
            auto const& sle = les.entrycache(ltasset_state, assetstateindex);
            if (sle) {
                stamount amount = sle->getfieldamount(sfamount);
                stamount released = sle->getfieldamount(sfdeliveredamount);

                if (sle->getfieldaccount160(sfaccount) == line->getaccountidpeer()) {
                    amount.negate();
                    released.negate();
                }

                auto reserved = released ? amount - released : amount;

                json::value& state(jsonassetstates.append(json::objectvalue));
                state[jss::date] = static_cast<json::uint>(getquality(assetstateindex));
                state[jss::amount] = amount.gettext();
                state[jss::reserve] = reserved.gettext();
            }

            auto const nextassetstate(
                les.getnextledgerindex(assetstateindex, assetstateend));

            if (nextassetstate.iszero())
                break;

            assetstateindex = nextassetstate;
        }
    }

    context.loadtype = resource::feemediumburdenrpc;
    return result;
}
Ejemplo n.º 28
0
int makelist(int iflag)
{
	char *cp1;
	char *cp2;
	int c;
	struct buffer *bp;
	struct line *lp;
	int s;
	int i;
	long nbytes;		/* # of bytes in current buffer */
	char b[7 + 1];
	char line[MAXLINE];

	blistp->b_flag &= ~BFCHG;	/* Don't complain!      */
	if ((s = bclear(blistp)) != TRUE)	/* Blow old text away   */
		return s;
	strcpy(blistp->b_fname, "");
	if (addline("ACT MODES        Size Buffer        File") == FALSE
	    || addline("--- -----        ---- ------        ----") ==
	    FALSE)
		return FALSE;
	bp = bheadp;		/* For all buffers      */

	/* build line to report global mode settings */
	cp1 = &line[0];
	*cp1++ = ' ';
	*cp1++ = ' ';
	*cp1++ = ' ';
	*cp1++ = ' ';

	/* output the mode codes */
	for (i = 0; i < NUMMODES; i++)
		if (gmode & (1 << i))
			*cp1++ = modecode[i];
		else
			*cp1++ = '.';
	strcpy(cp1, "         Global Modes");
	if (addline(line) == FALSE)
		return FALSE;

	/* output the list of buffers */
	while (bp != NULL) {
		/* skip invisable buffers if iflag is false */
		if (((bp->b_flag & BFINVS) != 0) && (iflag != TRUE)) {
			bp = bp->b_bufp;
			continue;
		}
		cp1 = &line[0];	/* Start at left edge   */

		/* output status of ACTIVE flag (has the file been read in? */
		if (bp->b_active == TRUE)	/* "@" if activated       */
			*cp1++ = '@';
		else
			*cp1++ = ' ';

		/* output status of changed flag */
		if ((bp->b_flag & BFCHG) != 0)	/* "*" if changed       */
			*cp1++ = '*';
		else
			*cp1++ = ' ';

		/* report if the file is truncated */
		if ((bp->b_flag & BFTRUNC) != 0)
			*cp1++ = '#';
		else
			*cp1++ = ' ';

		*cp1++ = ' ';	/* space */

		/* output the mode codes */
		for (i = 0; i < NUMMODES; i++) {
			if (bp->b_mode & (1 << i))
				*cp1++ = modecode[i];
			else
				*cp1++ = '.';
		}
		*cp1++ = ' ';	/* Gap.                 */
		nbytes = 0L;	/* Count bytes in buf.  */
		lp = lforw(bp->b_linep);
		while (lp != bp->b_linep) {
			nbytes += (long) llength(lp) + 1L;
			lp = lforw(lp);
		}
		ltoa(b, 7, nbytes);	/* 6 digit buffer size. */
		cp2 = &b[0];
		while ((c = *cp2++) != 0)
			*cp1++ = c;
		*cp1++ = ' ';	/* Gap.                 */
		cp2 = &bp->b_bname[0];	/* Buffer name          */
		while ((c = *cp2++) != 0)
			*cp1++ = c;
		cp2 = &bp->b_fname[0];	/* File name            */
		if (*cp2 != 0) {
			while (cp1 < &line[3 + 1 + 5 + 1 + 6 + 4 + NBUFN])
				*cp1++ = ' ';
			while ((c = *cp2++) != 0) {
				if (cp1 < &line[MAXLINE - 1])
					*cp1++ = c;
			}
		}
		*cp1 = 0;	/* Add to the buffer.   */
		if (addline(line) == FALSE)
			return FALSE;
		bp = bp->b_bufp;
	}
	return TRUE;		/* All done             */
}
Ejemplo n.º 29
0
void send_email2(void)
{
    char s[81],scratch[81],log[81];
    int f, i;
    long len,len2;
    char *b;
    long thetime,dat;
    int len3;
    mailrec m,m1;
    userrec ur;
    messagerec msg;
    struct date dt;
    struct time tm;
    char *month[] = {"Bug","Jan","Feb","Mar","Apr","May","Jun",
		     "Jul","Aug","Sep","Oct","Nov","Dec"};

    m.touser=user_to_num;

    time(&thetime);

    len=(unsigned) strlen(buffer);
    len2=len;
    b=((char *)malloc(len+1024));
    len=0;
    sprintf(log,"þ Incoming mail for %s from %s (%s)\n",fido_to_user,fido_from_user,origi_node);
    write_log(log);
    sprintf(s,"%s (%s)",fido_from_user,origi_node);
    addline(b,s,&len);

    /* Get date/time of Email creation. */
    /* Ditto the \015 for the time/date string. */

    strncpy(scratch,fido_date_line,20);
    scratch[20]='\0';

    /* Build the date - cumbersome, but it needs to be done */
	/* Build tblock as we go along so we can have a pretty date */
	scratch[2] = '\0';	/* make day a string */
	dt.da_day = atoi(scratch);
	for (i=1;i<13;i++)
	if (strncmpi(month[i],&scratch[3],3) == 0)
	{
	    dt.da_mon = i;
	    break;
        }
	scratch[9] = '\0';	/* make year a string */
    dt.da_year = atoi(&scratch[7]);
    if (dt.da_year>90)
        dt.da_year += 1900;
    else
        dt.da_year += 2000;
	scratch[13] = '\0'; /* make hour a string */
	tm.ti_hour = atoi(&scratch[11]);
	scratch[16] = '\0'; /* make minute a string */
	tm.ti_min = atoi(&scratch[14]);
	scratch[19] = '\0'; /* make second a string */
	tm.ti_sec = atoi(&scratch[17]);
	tm.ti_hund = 0;
	dat = dostounix(&dt,&tm);
	strncpy(scratch,ctime(&(time_t)dat),24);
	scratch[24]='\0';
    strcat(scratch,"\r\n");
    strcpy(s,scratch);
    addline(b,s,&len);

    strcat(b,buffer);
    len += len2;
    len=(unsigned) strlen(b);

    if (b[len-1]!=26)
        b[len++]=26;

    m.msg.storage_type=2;
    msg.stored_as=0L;
    msg.storage_type=2;
    savefile(b,len,&msg,"EMAIL");
    m.msg=msg;

    i=0;
    strcpy(m.title,fido_title);
//    i=strlen(m.title);
//    m.title[i+1]=net_num;
//    m.title[i+2]=0;
    m.title[80]=net_num;
    m.title[81]=0;
//    i=0;
    read_user(user_to_num,&ur);
    ++ur.waiting;
    write_user(user_to_num,&ur);
    lock_status();
    save_status();

    m.anony=i;
    m.fromsys=atoi(wwiv_node);
    m.fromuser=0;
    m.tosys=0;
    m.status=status_new_net;
    time((long *)&(m.daten));

    f=open_email(1);
    len3=(int) filelength(f)/sizeof(mailrec);
    if (len3==0)
	i=0;
    else
    {
        i=len3-1;
        sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
        sh_read(f,(void *)&m1,sizeof(mailrec));
        while ((i>0) && (m1.tosys==0) && (m1.touser==0))
        {
            --i;
            sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
	    sh_read(f,(void *)&m1,sizeof(mailrec));
	}
        if ((m1.tosys) || (m1.touser))
            ++i;
    }
    sh_lseek(f,((long) (i))*(sizeof(mailrec)), SEEK_SET);
    sh_write(f,(void *)&m,sizeof(mailrec));
    sh_close(f);

    free(buffer);
}
Ejemplo n.º 30
0
void show_mechs_damage(dbref player, void *data, char *buffer)
{
    MECH *mech = data;
    coolmenu *c = NULL;
    int i, j, v1, v2;
    char buf[MBUF_SIZE];
    char buf2[MBUF_SIZE];
    int isds;

    TECHCOMMANDD;
    if (unit_is_fixable(mech))
	make_damage_table(mech);
    else
	make_scrap_table(mech);
    DOCHECK(!damage_last &&
	MechType(mech) == CLASS_MECH,
	"The 'mech is in pristine condition!");
    DOCHECK(!damage_last, "It's in pristine condition!");
    addline();
    cent(tprintf("Damage for %s", GetMechID(mech)));
    addline();
    for (i = 0; i < damage_last; i++) {
	v1 = damage_table[i][1];
	v2 = damage_table[i][2];
	switch (damage_table[i][0]) {
	case REATTACH:
	case DETACH:
	case RESEAL:
	case REPLACESUIT:
	    strcpy(buf, repair_need_msgs[(int) damage_table[i][0]]);
	    break;
	case REPAIRP:
	case REPAIRP_T:
	case REPAIRG:
	case ENHCRIT_MISC:
	case ENHCRIT_FOCUS:
	case ENHCRIT_CRYSTAL:
	case ENHCRIT_BARREL:
	case ENHCRIT_AMMOB:
	case ENHCRIT_RANGING:
	case ENHCRIT_AMMOM:
	case SCRAPP:
	case SCRAPG:
	    sprintf(buf, repair_need_msgs[(int) damage_table[i][0]],
		pos_part_name(mech, v1, v2));
	    break;
	case RELOAD:
	    sprintf(buf, repair_need_msgs[(int) damage_table[i][0]],
		pos_part_name(mech, v1, v2), FullAmmo(mech, v1,
		    v2) - GetPartData(mech, v1, v2));
	    break;
	case UNLOAD:
	    sprintf(buf, repair_need_msgs[(int) damage_table[i][0]],
		pos_part_name(mech, v1, v2), GetPartData(mech, v1, v2));
	    break;
	case FIXARMOR:
	case FIXARMOR_R:
	case FIXINTERNAL:
	    sprintf(buf, repair_need_msgs[(int) damage_table[i][0]],
		damage_table[i][2]);
	    break;
	}
	j = is_under_repair(mech, i);
	sprintf(buf2, "%%ch%s%-2d:%s %%cn%s%s", j ? "%cg" : "%cy", i + 1,
	    ShortArmorSectionString(MechType(mech), MechMove(mech), v1),
	    buf, j ? " (*)" : "");
	vsi(buf2);
    }
    addline();
    vsi("(*) / %ch%cgGreen%cn = Job already done. %ch%cyYellow%cn = To be done.");
    addline();
    ShowCoolMenu(player, c);
    KillCoolMenu(c);
}