Beispiel #1
0
static void
show_help(bool * keyhelp)
{
    werase(helpwin);
    if (*keyhelp) {
	help1();
	*keyhelp = FALSE;
    } else {
	help2();
	*keyhelp = TRUE;
    }
    wrefresh(helpwin);
}
Beispiel #2
0
static void do_extension_pdf(int immediate)
{
int i;

if(scan_keyword("literal")){
new_whatsit(pdf_literal_node);
if(scan_keyword("direct"))
set_pdf_literal_mode(tail,direct_always);
else if(scan_keyword("page"))
set_pdf_literal_mode(tail,direct_page);
else
set_pdf_literal_mode(tail,set_origin);
scan_toks(false,true);
set_pdf_literal_type(tail,normal);
set_pdf_literal_data(tail,def_ref);
}else if(scan_keyword("dest")){
scan_pdfdest(static_pdf);
}else if(scan_keyword("annot")){
scan_annot(static_pdf);
}else if(scan_keyword("save")){
new_whatsit(pdf_save_node);
}else if(scan_keyword("restore")){
new_whatsit(pdf_restore_node);
}else if(scan_keyword("setmatrix")){
new_whatsit(pdf_setmatrix_node);
scan_toks(false,true);
set_pdf_setmatrix_data(tail,def_ref);
}else if(scan_keyword("obj")){
scan_obj(static_pdf);
if(immediate){
if(obj_data_ptr(static_pdf,pdf_last_obj)==0)
normal_error("pdf backend","\\pdfextension obj 'reserveobjnum' cannot be used with \\immediate");
pdf_write_obj(static_pdf,pdf_last_obj);
}
}else if(scan_keyword("refobj")){
scan_refobj(static_pdf);
}else if(scan_keyword("colorstack")){
scan_int();
if(cur_val>=colorstackused()){
print_err("Unknown color stack number ");
print_int(cur_val);
help3
("Allocate and initialize a color stack with \\pdfextension colorstackinit.",
"I'll use default color stack 0 here.",
"Proceed, with fingers crossed.");
error();
cur_val= 0;
}
if(cur_val<0){
print_err("Invalid negative color stack number");
help2("I'll use default color stack 0 here.",
"Proceed, with fingers crossed.");
error();
cur_val= 0;
}
if(scan_keyword("set"))
i= colorstack_set;
else if(scan_keyword("push"))
i= colorstack_push;
else if(scan_keyword("pop"))
i= colorstack_pop;
else if(scan_keyword("current"))
i= colorstack_current;
else
i= -1;
if(i>=0){
new_whatsit(pdf_colorstack_node);
set_pdf_colorstack_stack(tail,cur_val);
set_pdf_colorstack_cmd(tail,i);
set_pdf_colorstack_data(tail,null);
if(i<=colorstack_data){
scan_toks(false,true);
set_pdf_colorstack_data(tail,def_ref);
}
}else{
print_err("Color stack action is missing");
help3("The expected actions for \\pdfextension colorstack:",
"    set, push, pop, current",
"I'll ignore the color stack command.");
error();
}
}else if(scan_keyword("startlink")){
scan_startlink(static_pdf);
}else if(scan_keyword("endlink")){
if(abs(mode)==vmode)
normal_error("pdf backend","\\pdfextension endlink cannot be used in vertical mode");
new_whatsit(pdf_end_link_node);
}else if(scan_keyword("startthread")){
new_annot_whatsit(pdf_start_thread_node);
scan_thread_id();
}else if(scan_keyword("endthread")){
new_whatsit(pdf_end_thread_node);
}else if(scan_keyword("thread")){
new_annot_whatsit(pdf_thread_node);
scan_thread_id();
}else if(scan_keyword("outline")){
scan_pdfoutline(static_pdf);
}else if(scan_keyword("glyphtounicode")){
glyph_to_unicode();
}else if(scan_keyword("catalog")){
scan_pdfcatalog(static_pdf);
}else if(scan_keyword("fontattr")){





scan_font_ident();
i= cur_val;
if(i==null_font)
normal_error("pdf backend","invalid font identifier");
scan_toks(false,true);
set_pdf_font_attr(i,tokens_to_string(def_ref));
if(str_length(pdf_font_attr(i))==0){
flush_str((str_ptr-1));
set_pdf_font_attr(i,0);
}
}else if(scan_keyword("mapfile")){
scan_toks(false,true);
pdfmapfile(def_ref);
delete_token_ref(def_ref);
}else if(scan_keyword("mapline")){
scan_toks(false,true);
pdfmapline(def_ref);
delete_token_ref(def_ref);
}else if(scan_keyword("includechars")){
pdf_include_chars(static_pdf);
}else if(scan_keyword("info")){
scan_toks(false,true);
pdf_info_toks= concat_tokens(pdf_info_toks,def_ref);
}else if(scan_keyword("names")){
scan_toks(false,true);
pdf_names_toks= concat_tokens(pdf_names_toks,def_ref);
}else if(scan_keyword("trailer")){
scan_toks(false,true);
pdf_trailer_toks= concat_tokens(pdf_trailer_toks,def_ref);
}else{
tex_error("unexpected use of \\pdfextension",null);
}
}
Beispiel #3
0
void pdf_ship_out (pointer p)
{
  integer page_loc;
  char j, k;

  if (tracing_output > 0)
  {
    print_nl("");
    print_ln();
    prints("Completed box being shipped out");
  }

  if (term_offset > max_print_line - 9)
    print_ln();
  else if ((term_offset > 0) || (file_offset > 0))
    print_char(' ');

  print_char('[');
  j = 9;

  while ((count(j) == 0) && (j > 0))
    decr(j);

  for (k = 0; k <= j; k++)
  {
    print_int(count(k));

    if (k < j)
      print_char('.');
  }

  update_terminal();

  if (tracing_output > 0)
  {
    print_char(']');
    begin_diagnostic();
    show_box(p);
    end_diagnostic(true);
  }

  if ((height(p) > max_dimen) || (depth(p) > max_dimen) ||
      (height(p) + depth(p) + v_offset > max_dimen) ||
      (width(p) + h_offset > max_dimen))
  {
    print_err("Huge page cannot be shipped out");
    help2("The page just created is more than 18 feet tall or",
      "more than 18 feet wide, so I suspect something went wrong.");
    error();

    if (tracing_output <= 0)
    {
      begin_diagnostic();
      print_nl("The following box has been deleted:");
      show_box(p);
      end_diagnostic(true);
    }

    goto done;
  }

  if (height(p) + depth(p) + v_offset > max_v)
    max_v = height(p) + depth(p) + v_offset;

  if (width(p) + h_offset > max_h)
    max_h = width(p) + h_offset;

  dvi_h = 0;
  dvi_v = 0;
  cur_h = h_offset;
  dvi_f = null_font;
  ensure_pdf_open();

  if (total_pages == 0)
  {
    pdf_set_version(5);
    pdf_set_compression(9);
    pdf_init_fontmaps();
    read_config_file("dvipdfmx.cfg");
    pdf_doc_set_producer("Y&YTeX 2.3.0");
    pdf_doc_set_creator("TeX");
    pdf_files_init();
    pdf_init_device(0.000015202, 2, 0);
    // TODO: pdfTeX's page width and height.
    // page_width  = pdf_page_width  != 0 ? <- : width(p)             + 2 * (pdf_h_origin + h_offset);
    // page_height = pdf_page_height != 0 ? <- : height(p) + depth(p) + 2 * (pdf_v_origin + v_offset);
    pdf_open_document(pdf_file_name, 0, 595.0, 842.0, 0, 0, (1 << 4));
    spc_exec_at_begin_document();
  }

  page_loc = dvi_offset + dvi_ptr;
  pdf_doc_begin_page(1.0, 72.0, 770.0);
  spc_exec_at_begin_page();

  last_bop = page_loc;
  cur_v = height(p) + v_offset;
  temp_ptr = p;

  if (type(p) == vlist_node)
    pdf_vlist_out();
  else
    pdf_hlist_out();

  spc_exec_at_end_page();
  pdf_doc_end_page();
  incr(total_pages);
  cur_s = -1;

done:
  if (tracing_output <= 0)
    print_char(']');

  dead_cycles = 0;
  update_terminal();

#ifdef STAT
  if (tracing_stats > 1)
  {
    print_nl("Memory usage before: ");
    print_int(var_used);
    print_char('&');
    print_int(dyn_used);
    print_char(';');
  }
#endif

  flush_node_list(p);

#ifdef STAT
  if (tracing_stats > 1)
  {
    prints(" after: ");
    print_int(var_used);
    print_char('&');
    print_int(dyn_used);
    prints("; still utouched: ");
    print_int(hi_mem_min - lo_mem_max - 1);
    print_ln();
  }
#endif
}
void iterative_matrix_inverse(double *matptr, double *invmatptr, int n,
			      _Bool prev, double epsilon, double *work1,
			      double *work2, int *error,
			      cublasHandle_t cublas_handle, int *nit_out)
{
  INIT_ERROR(error);

  mat<double> matr(n, matptr, cublas_handle);
  mat<double> invmat(n, invmatptr, cublas_handle);
  /* Will allocate and release upon destruction if work1, work2 == NULL */
  mat<double> help1(n, work1, cublas_handle);
  mat<double> help2(n, work2, cublas_handle);

  /*
   * - Initialize inverse matrix if previous not used
   *   The starting invmat has to be small enough so that the iteration
   *   won't start running to infinity
   */

#if 0
  mat<double> dummy(n);
  dummy = matr;

  printf("dummy.data() = %p\n", dummy.data());
  printf("matr.data() = %p\n", matr.data());
  printf("dummy.on_host() = %i\n", dummy.on_host(error));
  PASS_ERROR(error);
  printf("matr.on_host() = %i\n", matr.on_host(error));
  PASS_ERROR(error);
  printf("sum = %f %f\n", dummy.sum(), matr.sum());
  printf("max = %f %f\n", dummy.max(), matr.max());
  printf("min = %f %f\n", dummy.min(), matr.min());
  printf("amax = %f %f\n", dummy.amax(), matr.amax());
  printf("amin = %f %f\n", dummy.amin(), matr.amin());
#endif

  if (!prev) {
    double smin, smax;
    ev_bounds(n, matptr, &smin, &smax, error);
    PASS_ERROR(error);
    mat_mul_sca(1.0/(n*MAX(fabs(smin), fabs(smax))), matr, invmat, error);
    PASS_ERROR(error);
  }

  /*
   * Find inverse via S^-1 = 2 S^1 - S^-1 S S^-1
   */

  double sigma = epsilon + 1.0;
  int i = 0;
  while (sigma > epsilon) {

    /*
     * help1 = matr.invmat
     */

    gemm(OP_N, OP_N, 1.0, matr, invmat, 0.0, help1, error);
    PASS_ERROR(error);

    help2 = invmat;

    /*
     * invmat = -help2.help1 + 2*invmat
     */

    gemm(OP_N, OP_N, -1.0, help2, help1, 2.0, invmat, error);
    PASS_ERROR(error);

    mat_mul_sca(1.0, help2, -1.0, invmat, help1, error);
    PASS_ERROR(error);

    sigma = help1.amax(error);
    PASS_ERROR(error);
    i = i+1;

    if (i % 100 == 0) {
      prscrlog("iterative_matrix_inverse: No convergence after %i iterations.",
	       i);
    }

  }

  if (nit_out) {
    *nit_out = i;
  }
}
Beispiel #5
0
void scope4() {
  help1();
  help2();
}
Beispiel #6
0
void scope2() {
  B();
  help2();
}
Beispiel #7
0
void tex::help_box_255()
	{
	help2("You shouldn't use \\box255 except in \\output routines.",
	"Proceed, and I'll discard its present contents.");
	}
Beispiel #8
0
void tex::help_vsplit_vbox()
	{
	help2("The box you are trying to split is an \\hbox.",
	"I can't split such a box, so I'll leave it alone.");
	}
Beispiel #9
0
void tex::help_doldol()
	{
	help2("The `$' that I just saw supposedly matches a previous `$$'.",
	"So I shall assume that you typed `$$' both times.");
	}
Beispiel #10
0
void tex::help_math_accent()
	{
	help2("I'm changing \\accent to \\mathaccent here; wish me luck.",
	"(Accents are not the same in formulas as they are in text.)" );
	}
Beispiel #11
0
int main(int argc, char* argv[])
{
	printf("[i] Make fimware.\n");

	if(argc < 5){
		// не задано имя файла прошивки
		printf("[!] Set file names!\n");
		help2();
		return -1;
	}

	bool isDlink = false;

	size_t size_result=0, size_bcm=0, size_cfe=0, size_sqsh=0, size_kernel=0, size_name=0;

	FILE* fresult=0, *fbcm=0, *fcfe=0, *fsqsh=0, *fkernel=0, *fname=0;

	// имя файла задаётся первым параметром
	char* file_bcm = argv[1];
	printf("[i] bcm file: %s\n", file_bcm);
	fbcm = fopen(file_bcm, "rb");
	if(fbcm){
		size_bcm = getFileSize(fbcm);
	}
	// проверим длину заголовка
	if(size_bcm!=BCM_LENGTH){
		printf("[!] Error: wrong bcm file size: %s (%d bytes)\n", file_bcm, size_bcm);
		help2();
		return -1;
	}

	char* file_cfe = argv[2];
	printf("[i] cfe file: %s\n", file_cfe);
	fcfe = fopen(file_cfe, "rb");
	if(fcfe){
		size_cfe = getFileSize(fcfe);
	}

	char* file_sqsh = argv[3];
	printf("[i] sqsh file: %s\n", file_sqsh);
	fsqsh = fopen(file_sqsh, "rb");
	if(fsqsh){
		size_sqsh = getFileSize(fsqsh);
	}
	
	char* file_kernel = argv[4];
	printf("[i] kernel file: %s\n", file_kernel);
	fkernel = fopen(file_kernel, "rb");
	if(fkernel){
		size_kernel = getFileSize(fkernel);
	}

	char* file_name = 0;
	// для прошивки от D-link-а
	if(argc>5){
		isDlink = true;
		file_name = argv[5];
		printf("[i] name file: %s\n", file_name);
		fname = fopen(file_name, "rb");
		if(fname){
			size_name = getFileSize(fname);
		}
		// проверим длину названия
		if(size_name!=NAME_LENGTH){
			printf("[!] Error: wrong name file size: %s (%d bytes)\n", file_name, size_name);
			help2();
			return -1;
		}
	}


	size_result = size_bcm + size_cfe + size_sqsh + size_kernel + size_name;

	if(!fbcm || !fcfe || !fsqsh || !fkernel){
		printf("[!] Error: cant open files!\n");
		return -2;
	}
	if(isDlink && !fname){
		printf("[!] Error: cant open name-file!\n");
		return -2;
	}

	printf("[i] result size: %d\n", size_result);

	fresult = fopen(result_file, "wb+");
	if(!fresult){
		printf("[!] Error: cant open file for writing: %s!\n", result_file);
		return -2;
	}

	//
	// буфер для сохранения
	//
	uchar* buf = new uchar [size_result];
	if(!buf){
		printf("[!] Error: cant allocate memory!\n");
		return -4;
	}

	//
	// считываем файлы в общий буфер
	//

	// bcm
	fread(buf, size_bcm, 1, fbcm);
	// cfe
	fread((uint8_t *) (buf + size_bcm), size_cfe, 1, fcfe);
	// sqsh
	fread((uint8_t *) (buf + size_bcm + size_cfe), size_sqsh, 1, fsqsh);
	// kernel
	fread((uint8_t *) (buf + size_bcm + size_cfe + size_sqsh), size_kernel, 1, fkernel);
	// name
	if(isDlink){
		fread((uint8_t *) (buf + size_bcm + size_cfe + size_sqsh + size_kernel), size_name, 1, fname);	
	}

	//
	// рассчёт CRC
	//
	uint32_t crc=CRC32_INIT_VALUE, crc_bcm=CRC32_INIT_VALUE, crc_image=CRC32_INIT_VALUE, crc_rootfs=CRC32_INIT_VALUE, crc_kernel=CRC32_INIT_VALUE;
	char file_crc[16], header_crc[16], image_crc[16], rootfs_crc[16], kernel_crc[16];

	// CRC образа cfe+sqsh+kernel
	crc_image = getCRC32String((uint8_t *) (buf + size_bcm), size_cfe+size_sqsh+size_kernel, image_crc);
	printf("[i] CRC image\t\t: 0x%s\n", image_crc);
	if(isDlink){
		// CRC образа cfe+sqsh+kernel+name
		crc_image = getCRC32String((uint8_t *) (buf + size_bcm), size_cfe+size_sqsh+size_kernel+size_name, image_crc);
		printf("[i] D-link CRC image\t\t: 0x%s\n", image_crc);
	}

	// CRC корневой файловой системы
	crc_rootfs = getCRC32String((uint8_t *) (buf + size_bcm + size_cfe), size_sqsh, rootfs_crc);
	printf("[i] CRC sqsh\t\t: 0x%s\n", rootfs_crc);

	// CRC ядра
	crc_kernel = getCRC32String((uint8_t *) (buf + size_bcm + size_cfe + size_sqsh), size_kernel, kernel_crc);
	printf("[i] CRC kernel\t\t: 0x%s\n", kernel_crc);

	//
	// запись размеров
	//
	printf("[i] update size...\n");

	// totalImageLen  = cfe+sqsh+kernel
	uint32_t place = TAG_VER_LEN+SIG_LEN+SIG_LEN_2+CHIP_ID_LEN+BOARD_ID_LEN+FLAG_LEN;
	updateLength(buf, place, size_cfe + size_sqsh + size_kernel);
	if(isDlink){
		// totalImageLen = cfe+sqsh+kernel+name
		updateLength(buf, place, size_cfe + size_sqsh + size_kernel + size_name);
	}
	// cfe
	place += IMAGE_LEN + ADDRESS_LEN;
	updateLength(buf, place, size_cfe);
	// rootFS
	place += IMAGE_LEN + ADDRESS_LEN;
	updateLength(buf, place, size_sqsh);
	// kernel
	place += IMAGE_LEN + ADDRESS_LEN;
	updateLength(buf, place, size_kernel);

	
	//
	// запись CRC 
	//

	// образа (cfe+sqsh+kernel)
	printf("[i] update image CRC...\n");
	updateCRC(buf, TAG_LEN - 2*TOKEN_LEN, crc_image);
	// файловой системы
	printf("[i] update sqsh CRC...\n");
	updateCRC(buf, TAG_LEN - 2*TOKEN_LEN + 4, crc_rootfs);
	// ядра
	printf("[i] update kernel CRC...\n");
	updateCRC(buf, TAG_LEN - 2*TOKEN_LEN + 8, crc_kernel);

	//
	// теперь, с новыми CRC в заголовке - нужно
	// пересчитать CRC самого заголовка
	//

	// рассчёт CRC заголовка
	crc_bcm = getCRC32String((uint8_t *) (buf), size_bcm-TOKEN_LEN, header_crc);
	printf("[i] CRC header\t\t: 0x%s\n", header_crc);
	// обновляем
	printf("[i] update header CRC...\n");
	updateCRC(buf, TAG_LEN - TOKEN_LEN, crc_bcm);

	printf("[i] write file: %s\n", result_file);
	//
	// записываем результат в файл
	//
	fwrite(buf, size_result, 1, fresult);

	// закрытие файлов
	fclose(fbcm);
	fclose(fcfe);
	fclose(fsqsh);
	fclose(fkernel);

	fclose(fresult);

	printf("[i] Done.\n");
	info();
	return 0;
}
Beispiel #12
0
void tex::help_dollar()
	{
	help2("I've inserted a begin-math/end-math symbol since I think",
	"you left one out. Proceed, with fingers crossed.");
	}