Example #1
0
void expand_macros_in_tokenlist(halfword p)
{
int old_mode;
pointer q= get_avail();
pointer r= get_avail();
token_info(q)= right_brace_token+'}';
token_link(q)= r;
token_info(r)= end_write_token;
begin_token_list(q,inserted);
begin_token_list(write_tokens(p),write_text);
q= get_avail();
token_info(q)= left_brace_token+'{';
begin_token_list(q,inserted);


old_mode= mode;
mode= 0;

cur_cs= write_loc;
q= scan_toks(false,true);
get_token();
if(cur_tok!=end_write_token){

const char*hlp[]= {
"On this page there's a \\write with fewer real {'s than }'s.",
"I can't handle that very well; good luck.",NULL
};
tex_error("Unbalanced write command",hlp);
do{
get_token();
}while(cur_tok!=end_write_token);
}
mode= old_mode;
end_token_list();
}
Example #2
0
static void do_extension_dvi(int immediate)
{
if(scan_keyword("literal")){
new_whatsit(special_node);
write_stream(tail)= null;
scan_toks(false,true);
write_tokens(tail)= def_ref;
}else{
tex_error("unexpected use of \\dviextension",null);
}
}
Example #3
0
void do_extension(int immediate)
{
halfword p;
if(cur_cmd==extension_cmd){

switch(cur_chr){
case open_code:
p= tail;
new_write_whatsit(open_node_size,1);
scan_optional_equals();
scan_file_name();
open_name(tail)= cur_name;
open_area(tail)= cur_area;
open_ext(tail)= cur_ext;
if(immediate){
out_what(static_pdf,tail);
flush_node_list(tail);
tail= p;
vlink(p)= null;
}
break;
case write_code:





p= tail;
new_write_whatsit(write_node_size,0);
cur_cs= write_stream(tail);
scan_toks(false,false);
write_tokens(tail)= def_ref;
if(immediate){
out_what(static_pdf,tail);
flush_node_list(tail);
tail= p;
vlink(p)= null;
}
break;
case close_code:
p= tail;
new_write_whatsit(close_node_size,1);
write_tokens(tail)= null;
if(immediate){
out_what(static_pdf,tail);
flush_node_list(tail);
tail= p;
vlink(p)= null;
}
break;
case special_code:




new_whatsit(special_node);
write_stream(tail)= null;
p= scan_toks(false,true);
write_tokens(tail)= def_ref;
break;
case immediate_code:
get_x_token();
do_extension(1);
break;
case use_box_resource_code:
case use_image_resource_code:
case save_box_resource_code:
case save_image_resource_code:
switch(get_o_mode()){
case OMODE_DVI:
do_resource_dvi(immediate,cur_chr);
break;
case OMODE_PDF:
do_resource_pdf(immediate,cur_chr);
break;
default:
break;
}
break;

case dvi_extension_code:
if(get_o_mode()==OMODE_DVI)
do_extension_dvi(immediate);
break;
case pdf_extension_code:
if(get_o_mode()==OMODE_PDF)
do_extension_pdf(immediate);
break;

default:
if(immediate){
back_input();
}else{
confusion("invalid extension");
}
break;
}
}else{

back_input();
}
}
Example #4
0
int main(int argc, char *argv[])
{
	f = fopen("debug.txt", "w+");

	WINDOW *win;
	int ch;
	int batch = 0;
	int endflag = 0;
	int no_chain_eval = 0;
	int i;
	for(i = 0; i < argc; i++)
	{
		if(strcmp(argv[i], "--batch") == 0)
			batch = 1;

		if(strcmp(argv[i], "--no-chain-eval") == 0)
			no_chain_eval = 1;
	}

	pthread_mutexattr_t ops;

	pthread_mutexattr_init(&ops);

	pthread_mutexattr_settype(&ops, PTHREAD_MUTEX_RECURSIVE);

	if(0 != pthread_mutex_init(&stack_mutex, &ops))
	{
		fprintf(stderr, "Error initializing stack semaphore!\n");
		abort();
	}

	if(!batch)
	{
	initscr();
	raw();
	keypad(stdscr, TRUE);
	noecho();

	refresh();

	win = newwin(LINES / 3, COLS - 2, LINES - LINES / 3, 1);
	//win = newwin(10, 10, 10, 10);
	box(win, 0, 0);

	wrefresh(win);

	printw("%4d > ", curbuf_len());

	mvwprintw(win, 0, 2, "Tokens...");
	}

	while((!batch && ch != 27) || (batch && ch != 13 && ch != 10 && !endflag ) ) {

		if(!batch)
			ch = getch();
		else
		{
			int val = fgetc(stdin);
			if(val == EOF) endflag = 1;
			ch = (char)val;
		}
		
		if(ch == 27) break;
		
		if(ch == 10 || ch == 13) {
			free(lastbuf);
			lastbuf = 0;
			if(curbuf)
				lastbuf = strdup(curbuf);
			free(curbuf);
			curbuf = 0;
			if(!batch)
			{
				int x, y;
				getyx(stdscr, y, x);
				move(y+1, 0);
				printw("[%d] %4d > ", ch, curbuf_len());
			}

			continue;
		}
		else
		if(!batch && ch == KEY_BACKSPACE)
		{
			if(curbuf_len() > 0)
			{
				int x, y;

				if(!batch)
				{
					getyx(stdscr, y, x);
					move(y, x-1);
					printw(" ");
					move(y, x-1);

						{int y,x; getyx(stdscr, y, x);
						mvprintw(14, 15, "curbuf_len(): %d", curbuf_len()); mvprintw(y,x, "");}
				}

				if(curbuf_len() - 1 < wait_pos)
				{
					current_task.state = TS_CANCEL;
					pthread_join( current_task.thread, NULL );
					memset(&current_task, 0, sizeof(current_task));
					current_task.state = TS_NONE;
				}
			}
			curbuf_delete_char();
			tokenize();
			if(!batch) write_tokens(win);
		}
		else if((!batch && ch == KEY_F(2)) || (batch && endflag) || ch == ' ')
		{
			char *tok = get_token_from_end(0);

			if(tok)
			{
			if(current_task.state == TS_NONE)
			{
				void (*op)(thread_state_t *) = get_op(tok);
				if(op)
				{
					current_task.state = TS_NONE;
					current_task.parent = NULL;

					pthread_create( &current_task, NULL, op, &current_task );
					while( current_task.state == TS_NONE) nanosleep(&sleep_interval, NULL);
					if( current_task.state == TS_OK)
					{
						pthread_join( current_task.thread, NULL );
						memset(&current_task, 0, sizeof(current_task));
						//current_task.state = TS_NONE;
					}
					else if( current_task.state == TS_WAITING)
					{
						// to restore on cancel
						wait_pos = curbuf_len();

						if(!batch)
						{
							int y,x; getyx(stdscr, y, x);
							mvprintw(15, 15, "wait_pos: %d", wait_pos); mvprintw(y,x, "");
						}
					}

					rebuildstr();
				}

			}
			else /*TS_WAITING */
			{
				current_task.state = TS_RESPONSE;
				while( current_task.state == TS_RESPONSE) nanosleep(&sleep_interval, NULL);
				if( current_task.state == TS_OK)
				{
					pthread_join( current_task.thread, NULL );
					memset(&current_task, 0, sizeof(current_task));
					current_task.state = TS_NONE;
				}

				rebuildstr();
			}
			}
				
			if(!batch)
			{
				int x, y;
				getyx(stdscr, y, x);

				mvprintw(y, 0, "%50s", " ");
				mvprintw(y, 0, "[%d] %4d > %s", ch, curbuf_len(), curbuf);

				write_tokens(win);
			}

			if(ch == ' ')
			{
				curbuf_append_char(ch);
				tokenize();
				if(!batch) write_tokens(win);
			}
			else
			{
			}
		}
		else
		{
			//printw("%c", ch);
			curbuf_append_char(ch);
			tokenize();
			if(!batch) write_tokens(win);
		}

		if(!batch)
		{		
			int x, y;
			getyx(stdscr, y, x);
			move(y, 0);
			printw("[%d] %4d > %s", ch, curbuf_len(), curbuf);
		}
	}
	
	if(!batch) endwin();
	
	if(lastbuf)
		printf("lastbuf: %s\n", lastbuf);

	if(curbuf)
		printf("curbuf: %s\n", curbuf);

	if(!lastbuf && !curbuf)
		printf("lastbuf and curbuf empty\n");

	fclose(f);

	return 0;
}