Beispiel #1
0
/* if the added stuff does not fit on current page, write it out
   after page break and change buffer handling mode to pass though */
void buffer_eob(int eot)
{
	block_put();
	if (epsf) {
		if (epsf == 3)
			write_eps();		/* close the image */
		return;
	}
	if (remy + bposy >= 0
	 || multicol_start != 0)
		return;

	// page full
	if (!in_page) {
		if ((cfmt.splittune == 2 && !(nbpages & 1))
		 || (cfmt.splittune == 3 && (nbpages & 1))) { // wrong odd/even page
			if (remy + maxy + bposy < 0) {	// 2nd overflow
				init_page();
				close_page();
				write_buffer();
				return;
			}
			if (eot)
				write_buffer();
			return;
		}
	} else {
		close_page();
	}
	if ((cfmt.splittune == 2 && !(nbpages & 1))
	 || (cfmt.splittune == 3 && (nbpages & 1)))
		use_buffer = 1;			// if wrong odd/even page
	else
		write_buffer();
#if 0
--- old
		if (use_buffer
		 && !eot
		 && ((cfmt.splittune == 2 && !(nbpages & 1))
		   || (cfmt.splittune == 3 && (nbpages & 1)))) {
			init_page();
// 8.7.4
			use_buffer = 1;
		} else {
// 8.7.5 - required to avoid buffer overflow
			write_buffer();
		}
//8.7.0
//		write_buffer();
//8.6.2
//		use_buffer = 0;
#endif
}
Beispiel #2
0
static PangoLayout *
show_text_with_page_feed (cairo_t *cr, const gchar *utf8)
{
    PangoLayout *layout;
    double x, y;
    int width, height;

    if (!utf8)
        return NULL;

    layout = cut_cairo_create_pango_layout(cr, utf8, 10);
    if (!layout)
        return NULL;

    cairo_get_current_point(cr, &x, &y);
    pango_layout_get_pixel_size(layout, &width, &height);

    if (A4_HEIGHT < y + height) {
        cairo_show_page(cr);
        init_page(cr);
        cairo_get_current_point(cr, NULL, &y);
        cairo_move_to(cr, x, y);
    }

    pango_cairo_show_layout(cr, layout);
    return layout;
}
Beispiel #3
0
static int
add_page( struct cache *c ) {
  int new_page_index;
  char **new_pages;
  char *new_page;

  new_pages = realloc_mem( c->pages, sizeof( char * ) * ( c->page_count + 1 ) );
  if( !new_pages ) {
    return -1;
  }

  new_page = alloc_mem( c->page_size );
  if( !new_page ) {
    return -1;
  }

  new_page_index = c->page_count;
  c->page_count++;

  c->pages = new_pages;
  c->pages[new_page_index] = new_page;
  init_page( c, new_page_index );

  return new_page_index;
}
Beispiel #4
0
/*
void* change_entry(void* entry, int offset, int size)
{
}
*/
void* first_fit(kma_size_t size) 
{
  int min_size = sizeof(entry_t*);
  page_t* first_page = (page_t*)(gpage_entry->ptr);
  entry_t* entry = (entry_t*)(first_page->first);
  if(size < min_size)
    size = min_size;
  while(entry)
    {
       if(size > entry->size)
	{
	  entry = entry->next;
	  continue;
	}
      else if(size >=  entry->size - min_size)
	{
	  delete_entry(entry);
	  return (void*)entry;
	}
      else
	{
	  add_entry((void*)(entry + size), entry->size - size);
	  delete_entry(entry);
	  return (void*)entry;
	}
    }
  kma_page_t* new_page = get_page();
  init_page(new_page);
  return first_fit(size);
}
Beispiel #5
0
extern void start_kernel(void)
{
    // char	*ptr = 0x2000001;
    init_memory();
    init_page();
    init_sched();
    init_tasks();
    init_itc();
    init_clocks();
    spark_registerSysCallHandler(&system_call, 0x90);
    //spark_print(" ========== Guest 1 :: STARTED\n");


    while(1) {
        int	i,j,k, dummy =0;

        for (k=0; k< 5; k++)
        {
            for( i = 0 ; i < 10000; i++) {
                for(j = 0 ; j < 1000; j++) {

                    //				dummy += 5;
                    //				if(dummy > 500)
                    //					dummy = 0;
                }
            }
        }
    }
}
Beispiel #6
0
static int
init_object(struct deluge_object *obj, char *filename, unsigned version)
{
  static struct deluge_page *page;
  int i;

  obj->cfs_fd = cfs_open(filename, CFS_READ | CFS_WRITE);
  if(obj->cfs_fd < 0) {
    return -1;
  }

  obj->filename = filename;
  obj->object_id = next_object_id++;
  obj->size = file_size(filename);
  obj->version = obj->update_version = version;
  obj->current_rx_page = 0;
  obj->nrequests = 0;
  obj->tx_set = 0;

  obj->pages = malloc(OBJECT_PAGE_COUNT(*obj) * sizeof(*obj->pages));
  if(obj->pages == NULL) {
    cfs_close(obj->cfs_fd);
    return -1; 
  }

  for(i = 0; i < OBJECT_PAGE_COUNT(current_object); i++) {
    page = &current_object.pages[i];
    init_page(&current_object, i, 1);
  }

  memset(obj->current_page, 0, sizeof(obj->current_page));

  return 0;
}
Beispiel #7
0
int main(int argc, const char * argv[]) {
    
    /* Mandatory HTML info and navbar, etc. */
    init_page("blog");
    
    /* Google analytics script */
    include_google_analytics();
    
    /* Print Blog entries */
    char *env_string = getenv("QUERY_STRING");
    
    // Get the variables we want from env variable
    char *start = get_variable(env_string, "start=");
    char *end = get_variable(env_string, "end=");
    char *search = get_variable(env_string, "search=");
    char *month = get_variable(env_string, "month=");
    char *year = get_variable(env_string, "year=");
    
    printf("<div class=\"container\">"); // Start container that holds posts
    
    printf("<div class=\"row\"><div class=\"col-sm-8 blog-main\">");
    
    if (search != NULL) {
        print_search_notification(search);
        print_blog_posts(0, 10000, search);
    } else if (month != NULL && year != NULL) {
        print_posts_by_monthyear(atoi(month), atoi(year));
    } else if (start != NULL && end != NULL) {
        int int_start = atoi(start);
        int int_end = atoi(end);
        print_blog_posts(int_start, int_end, NULL);
    } else {
        print_blog_posts(0, 4, NULL);
    }
    // Free the variables we got
    free(start); free(end); free(search);
    
    printf("</div>"); // Close Blog
    
    // Blog sidebar
    printf("<div class=\"col-sm-3 col-sm-offset-1 blog-sidebar\">");
    
    print_about_box();
    print_archives();
    
    printf("</div>"); // Close sidebar
    
    printf("</div>"); // Close row
    
    printf("</div>"); // Close container
    
    printf("</body>"); // End HTML body, is opened in init_page()
    
    /* Print page footer, copyright, name, etc. */
    print_footer();
    
    printf("</html>");
    
    return 0;
}
Beispiel #8
0
/* Enter the command-line interface. HEAP is used for the command-line
   buffer. Return only if FOREVER is nonzero and get_cmdline returns
   nonzero (ESC is pushed).  */
void
enter_cmdline (char *heap, int forever)
{
  /* Initialize the data and print a message.  */
  init_cmdline ();
  grub_setjmp (restart_cmdline_env);
  init_page ();
#ifdef SUPPORT_DISKLESS
  print_network_configuration ();
  grub_putchar ('\n');
#endif
  print_cmdline_message (forever);

  while (1)
    {
      struct builtin *builtin;
      char *arg;

      *heap = 0;
      print_error ();
      errnum = ERR_NONE;

      /* Get the command-line with the minimal BASH-like interface.  */
      if (get_cmdline (PACKAGE "> ", heap, 2048, 0, 1))
	return;

      /* If there was no command, grab a new one. */
      if (! heap[0])
	continue;

      /* Find a builtin.  */
      builtin = find_command (heap);
      if (! builtin)
	continue;

      /* If BUILTIN cannot be run in the command-line, skip it.  */
      if (! (builtin->flags & BUILTIN_CMDLINE))
	{
	  errnum = ERR_UNRECOGNIZED;
	  continue;
	}

      /* Invalidate the cache, because the user may exchange removable
	 disks.  */
      buf_drive = -1;

      /* Start to count lines, only if the internal pager is in use.  */
      if (use_pager)
	count_lines = 0;
      
      /* Run BUILTIN->FUNC.  */
      arg = skip_to (1, heap);
      (builtin->func) (arg, BUILTIN_CMDLINE);

      /* Finish the line count.  */
      count_lines = -1;
    }
}
Beispiel #9
0
static void
handle_profile(struct deluge_msg_profile *msg)
{
  int i;
  int npages;
  struct deluge_object *obj;
  char *p;

  obj = &current_object;
  if(msg->version <= current_object.update_version) {
    return;
  }

  PRINTF("Received profile of version %u with a vector of %u pages.\n",
	msg->version, msg->npages);

  leds_off(LEDS_RED);
  current_object.tx_set = 0;

  npages = OBJECT_PAGE_COUNT(*obj);
  obj->size = msg->npages * S_PAGE;

  p = malloc(OBJECT_PAGE_COUNT(*obj) * sizeof(*obj->pages));
  if(p == NULL) {
    PRINTF("Failed to reallocate memory for pages!\n");
    return;
  }

  memcpy(p, obj->pages, npages * sizeof(*obj->pages));
  free(obj->pages);
  obj->pages = (struct deluge_page *)p;

  if(msg->npages < npages) {
    npages = msg->npages;
  }

  for(i = 0; i < npages; i++) {
    if(msg->version_vector[i] > obj->pages[i].version) {
      obj->pages[i].packet_set = 0;
      obj->pages[i].flags &= ~PAGE_COMPLETE;
      obj->pages[i].version = msg->version_vector[i];
    }
  }

  for(; i < msg->npages; i++) {
    init_page(obj, i, 0);
  }

  obj->current_rx_page = highest_available_page(obj);
  obj->update_version = msg->version;

  transition(DELUGE_STATE_RX);

  ctimer_set(&rx_timer,
	CONST_OMEGA * ESTIMATED_TX_TIME + ((unsigned)random_rand() % T_R),
	send_request, obj);
}
Beispiel #10
0
/* ----- write_pagebreak ----- */
void write_pagebreak (FILE *fp)
{

  close_page (fp);
  init_page  (fp);
  if (strlen(page_init)>0) fprintf(fp,"%s\n", page_init);
  posy=cfmt.pageheight-cfmt.topmargin;

}
//initialize a frame/node of a pool with all default values
void create_dummy_page_Frame(page_Frame* frame)
{
	// Dirty must be false
	frame->dirty_Flag=FALSE;
	// fix counts is zero
	frame->fix_Count=0;
	// default page details
	init_page(frame);
	// replaceable flag
	frame->replace_Flag = -1;
	// Set next node pointer to null
	frame->next_Node=NULL;
}
Beispiel #12
0
int page_sim_init(unsigned page_size, unsigned mem_size,
                  unsigned addr_space_size, unsigned max_concurrent_operations,
                  pagesim_callback callback)
/* Description in header. */
{
  
  int i;
  sprintf(data.file_name, "tmppagesimXXXXXX");
  data.page_size = page_size;
  data.mem_size = mem_size;
  data.addr_space_size = addr_space_size;
  data.max_concurrent_operations = max_concurrent_operations;
  data.callback = callback;
  data.frames_repo = NULL;
  data.data_pool = NULL;
  data.pages = NULL;
  data.file = -1;
  data.first_page = NULL;
  data.last_page = NULL;
 
  if((data.frames_repo = malloc(sizeof(frame_content) * data.mem_size)) == NULL)
    FULL_CLEANUP_DIE_WITH(PSIM_EBALL);
  if((data.data_pool =
      malloc(sizeof(uint8_t) * data.addr_space_size * data.page_size)) == NULL)
    FULL_CLEANUP_DIE_WITH(PSIM_EBALL);
  if((data.pages = malloc(sizeof(page) * addr_space_size)) == NULL)
    FULL_CLEANUP_DIE_WITH(PSIM_EBALL);
  
  data.frames_num = 0;
  for(i = 0; i < data.mem_size; i++)
  {
    data.frames_repo[i].num = i;
    data.frames_repo[i].bytes = &data.data_pool[i * data.page_size];
  }
  if((data.file = mkstemp(data.file_name)) == -1)
    FULL_CLEANUP_DIE_WITH(PSIM_EIO);
  if(pthread_cond_init(&data.create_page_cond, NULL) != 0)
    FULL_CLEANUP_DIE_WITH(PSIM_ETHRE);
  if(pthread_cond_init(&data.max_operations_cond, NULL) != 0)
    FULL_CLEANUP_DIE_WITH(PSIM_ETHRE);
  if(pthread_mutex_init(&data.mutex, NULL) != 0)
    FULL_CLEANUP_DIE_WITH(PSIM_ETHRE);
  for(i = 0; i < addr_space_size; i++)
    if(init_page(&data.pages[i], i) != 0)
      FULL_CLEANUP_DIE_WITH(PSIM_ETHRE);
  if(clear_disk_data() != 0)
    FULL_CLEANUP_DIE_WITH(PSIM_EIO);
  
  data.state = PSIM_READY;
  return 0;
}
Beispiel #13
0
static void
cb_complete_run (CutRunContext *run_context, gboolean success,
                 CutPDFReport *report)
{
#ifdef HAVE_GOFFICE
    cairo_save(report->context);
    draw_chart(report, run_context);
    cairo_restore(report->context);
    cairo_show_page(report->context);
#endif

    init_page(report->context);
    show_summary(report, run_context);
}
Beispiel #14
0
/* 1. Split: choose a new frame other than the one containing parent page. Write
      it out if it's used and then load it with a new page. Update the index accordingly.
   2. Redistributes records in the parent page. Overflow page may exist. Mind it!
   3. The insert the record again. If insertion fails, add an overflow page and insert
      it into the overflow page. */
void split_page_insert_again (struct page *target_page, char *depot, int *pos,
								bool *finished, bool *split, FILE *out_stream)
{
	int new_page_fnum;
	unsigned int pid_again;
	int ovp_pid;
	struct page *new_page, *overflow_page;
	char s_key[20];

	target_page->pin_cnt++;
	new_page_fnum = choose ();
	new_page = &buffer[new_page_fnum];
	target_page->pin_cnt--;

	if (used[new_page_fnum])
	{
		fseek (out_stream, sizeof (struct page) * new_page->pid, SEEK_SET);
		fwrite (new_page, sizeof (struct page), 1, out_stream);
	}
	used[new_page_fnum] = true;

	//prepare_page (target_page, tmp);
	init_page (new_page, target_page->local_depth + 1);
	update_index (target_page->pid, new_page->pid, target_page->local_depth + 1,
					power (2, target_page->local_depth), out_stream);

	unsigned int pid1 = target_page->pid, pid2 = new_page->pid; // debug
	redistribute (target_page, new_page, out_stream);
	assert (pid1 == target_page->pid && pid2 == new_page->pid); // debug
	*split = false;

	get_search_key (s_key, depot, *pos);
	pid_again = *index (hash_func(s_key), out_stream);
	if (pid_again == target_page->pid)
		ovp_pid = insert_record (target_page, depot, pos, finished, split, out_stream, true);
	else if (pid_again == new_page->pid)
		ovp_pid = insert_record (new_page, depot, pos, finished, split, out_stream, true);
	else
	{
		printf ("Page number panic!\n");
		exit (1);
	}

	if (*split)		// add overflow page.
	{
		assert (ovp_pid != -2 && ovp_pid != -3); // debug
		overflow_page = add_overflow_page (ovp_pid, out_stream);
		insert_record (overflow_page, depot, pos, finished, split, out_stream);
	}
}
Beispiel #15
0
/* malloc function. Initializes the first page if needed, then
   returns the appropriate allocated space. */
void* kma_malloc(kma_size_t size)
{
  if (REALSIZE(size)+sizeof(pageheaderT) > PAGESIZE)
    return NULL;

  if (first_page == NULL)
  {
    first_page = init_page();
    kma_malloc(sizeof(pageheaderT));    // mallocs the page header so it isn't overwritten.
    PAGE_HEADER(first_page)->used = 0;  // resets the allocation counter because the page
                                        // header doesn't count.
  }

  return get_free_buffer(size);
}
Beispiel #16
0
void buffer_init (void)
{
	int bound = power (2, GLOBAL_DEPTH);
	for (int i = 0; i < BUFFER_NUM; i++)
	{
		if (i < bound)
		{
			init_page (&buffer[i], GLOBAL_DEPTH);
			used[i] = true;
		}
		else
			used[i] = false;
	}
	for (int i = 0; i < INDEX_BUFFER_NUM; i++)
		ibuff_used[i] = false;
}
Beispiel #17
0
void
os_init(void) {
    /* Notice that when we are here, IF is always 0 (see bootloader) */

    /* We must set up kernel virtual memory first because our kernel
       thinks it is located in 0xC0100000.
       Before setting up correct paging, no global variable can be used. */
    // Before it, the address is physical address
    init_page();

    /* After paging is enabled, we can jump to the high address to keep
     * consistent with virtual memory, although it is not necessary. */
    asm volatile (" addl %0, %%esp\n\t\
                    jmp *%1": : "r"(KOFFSET), "r"(os_init_cont));

    assert(0);    // should not reach here
}
Beispiel #18
0
void*
kma_malloc(kma_size_t size)
{
  int malloc_size = size + sizeof(void*);
  if(malloc_size > PAGESIZE)
    return NULL;
  if(!gpage_entry)
    {
      gpage_entry = get_page();
      *((kma_page_t**)gpage_entry->ptr) = gpage_entry;      
      init_page(gpage_entry);
      printf("init success\n");
      gflag = 1;
    } 
  void* _first_fit = first_fit(size);
  printf("first_fit success\n");
  return _first_fit;
}
Beispiel #19
0
void init_block(struct nand_block *p_block)
{
	int i;

	p_block->bad_block = 0;
	p_block->last_programmed_page = 0;
	p_block->pecycle = 0;
	p_block->block_access_mode = MLC_MODE;
	p_block->pages = &nand_mem_pointer.page[nand_mem_pointer.blocks * PAGES_PER_BLOCK];
	nand_mem_pointer.page_cell = (char *)malloc(SIZE_OF_PAGE * PAGES_PER_BLOCK);
	nand_mem_pointer.pages = 0;
	nand_mem_pointer.blocks++;

	for (i = 0; i < PAGES_PER_BLOCK; i++)
	{
		init_page(&p_block->pages[i]);
	}
}
Beispiel #20
0
// creates a new entry in the page table
// If RAM is full. an entry is evicted to 
// make room for the current.
vAddr create_page(void){
	if(printing == 2){
		printf("Creating new page\n");
	}
	

	// Get the address of the next available empty non-locked page
	// Once a page is found, it is returned in the locked state
	vAddr new_vAddr = get_new_page_address();

	// If the page table is full, return an error
	if(new_vAddr == -1){
		if(printing){
			printf("Page Table full\n");
		}

		return -1;
	}


	// Initialize the new page
	init_page(&(page_table[new_vAddr]));

	// Find a pageframe in ram to give to it
	int temp = evict_page(ram);

	// Add the new page to this location
	// add_to_lowest(&(page_table[new_vAddr]),ram);

	page_table[new_vAddr].location = temp;
	page_table[new_vAddr].memlev = ram;
	page_table[new_vAddr].empty = 0;

	if(printing == 2){
		printf("Successfully created new page at %i\n", new_vAddr);
		printf("\n");
	}

	// Unlock page
	pthread_mutex_unlock(&(page_table[new_vAddr].lock));

	return new_vAddr;

}
Beispiel #21
0
/* Apply for a new overflow page and return its handle. */
struct page *add_overflow_page (int parent_pid, FILE *out_stream)
{
	int parent_fnum, ovp_fnum;

	parent_fnum = find_target_frame (parent_pid, out_stream);
	buffer[parent_fnum].pin_cnt++;

	ovp_fnum = choose ();
	if (used[ovp_fnum])
	{
		fseek (out_stream, sizeof (struct page) * buffer[ovp_fnum].pid, SEEK_SET);
		fwrite (&buffer[ovp_fnum], sizeof (struct page), 1, out_stream);
	}
	used[ovp_fnum] = true;
	init_page (&buffer[ovp_fnum], buffer[parent_fnum].local_depth);
	buffer[parent_fnum].opid = buffer[ovp_fnum].pid;
	buffer[parent_fnum].pin_cnt--;
	
	return &buffer[ovp_fnum];
}
Beispiel #22
0
void run_test (FILE *data_stream, FILE *test_in, FILE *test_out)
{
	int num_of_request;
	unsigned short ordered_rids[100];
	char num_of_request_str[10];
	char target_key[20];
	struct page result;

	num_of_request = atoi (fget_num (num_of_request_str, 10, test_in));
	while (num_of_request--)
	{
		init_page (&result, true);
		fget_num (target_key, 20, test_in);	// Get a request.
		if (search_by_key (target_key, &result, data_stream))  // sth worng here!!!
		{
			sort_record_in_page (&result, 2, ordered_rids);
			put_result (&result, ordered_rids, test_out);
		}
		else
			fprintf (test_out, "%d\r\n", -1);
	}
}
Beispiel #23
0
static void
cb_ready_test_suite (CutRunContext *run_context, CutTestSuite *test_suite,
                     guint n_test_cases, guint n_tests,
                     CutPDFReport *report)
{
    const gchar *filename;
    cairo_surface_t *surface;

    filename = cut_report_get_filename(CUT_REPORT(report));
    if (!filename)
        return;

    if (report->context) {
        cairo_destroy(report->context);
        report->context = NULL;
    }

    surface = cairo_pdf_surface_create(filename, A4_WIDTH, A4_HEIGHT);
    report->context = cairo_create(surface);
    cairo_surface_destroy(surface);

    init_page(report->context);
}
Beispiel #24
0
/* Enter the command-line interface. HEAP is used for the command-line
   buffer. Return only if FOREVER is nonzero and get_cmdline returns
   nonzero (ESC is pushed).  */
void
enter_cmdline (char *heap, int forever)
{
  if (! debug)
      debug++;

  //grub_setjmp (restart_cmdline_env);

  /* Initialize the data and print a message.  */
  current_drive = GRUB_INVALID_DRIVE;
  count_lines = -1;
  kernel_type = KERNEL_TYPE_NONE;
  errnum = 0;
  errorcheck = 1;	/* errorcheck on */
  init_page ();
  grub_putchar ('\n');
#ifdef SUPPORT_DISKLESS
  print_network_configuration ();
  grub_putchar ('\n');
#endif
  print_cmdline_message (forever);
  
  while (1)
    {
      struct builtin *builtin;
      char *arg;
      grub_error_t errnum_old;

      errnum_old = errnum;
      *heap = 0;
      if (errnum && errorcheck)
	print_error ();
      errnum = ERR_NONE;

      /* Get the command-line with the minimal BASH-like interface.  */
      prompt = PACKAGE "> ";
      maxlen = 2048;
      echo_char = 0;
      readline = 1;
      if (get_cmdline (heap))
	{
	  kernel_type = KERNEL_TYPE_NONE;
	  return;
	}

      /* If there was no command, grab a new one. */
      if (! heap[0])
	continue;

      /* Find a builtin.  */
      builtin = find_command (heap);
      if (! builtin)
	continue;

      /* If BUILTIN cannot be run in the command-line, skip it.  */
      if (! (builtin->flags & BUILTIN_CMDLINE))
	{
	  errnum = ERR_UNRECOGNIZED;
	  continue;
	}

      /* Invalidate the cache, because the user may exchange removable
	 disks.  */
      buf_drive = -1;

      /* Start to count lines, only if the internal pager is in use.  */
      if (use_pager)
	count_lines = 0;
      
      if ((builtin->func) == errnum_func || (builtin->func) == checkrange_func)
	errnum = errnum_old;

      /* find && and || */

      for (arg = skip_to (0, heap); *arg != 0; arg = skip_to (0, arg))
      {
	struct builtin *builtin1;
	int ret;
	char *arg1;
	arg1 = arg;
        if (*arg == '&' && arg[1] == '&' && (arg[2] == ' ' || arg[2] == '\t'))
        {
		/* handle the AND operator */
		arg = skip_to (0, arg);
		builtin1 = find_command (arg);
		if (! builtin1 || ! (builtin1->flags & BUILTIN_CMDLINE))
		{
			errnum = ERR_UNRECOGNIZED;
			goto next;
		}

		*arg1 = 0;
		ret = (builtin->func) (skip_to (1, heap), BUILTIN_CMDLINE);
		*arg1 = '&';
		if (ret)
		{
			arg = skip_to (1, arg);
			if ((builtin1->func) != errnum_func && (builtin1->func) != checkrange_func)
				errnum = 0;
			(builtin1->func) (arg, BUILTIN_CMDLINE);
		} else
			errnum = 0;
		goto next;
	} else if (*arg == '|' && arg[1] == '|' && (arg[2] == ' ' || arg[2] == '\t'))
	{
		/* handle the OR operator */
		arg = skip_to (0, arg);
		builtin1 = find_command (arg);
		if (! builtin1 || ! (builtin1->flags & BUILTIN_CMDLINE))
		{
			errnum = ERR_UNRECOGNIZED;
			goto next;
		}

		*arg1 = 0;
		ret = (builtin->func) (skip_to (1, heap), BUILTIN_CMDLINE);
		*arg1 = '|';
		if (! ret)
		{
			arg = skip_to (1, arg);
			if ((builtin1->func) != errnum_func && (builtin1->func) != checkrange_func)
				errnum = 0;
			(builtin1->func) (arg, BUILTIN_CMDLINE);
		} else
			errnum = 0;
		goto next;
	}
      }

	/* Run BUILTIN->FUNC.  */
	arg = (builtin->func) == commandline_func ? heap : skip_to (1, heap);
	(builtin->func) (arg, BUILTIN_CMDLINE);
next:
      /* Finish the line count.  */
      count_lines = -1;
    }
}
Beispiel #25
0
/* Searches all of the free buffers across all pages for one that
   properly fits the requested size (adjusted for alloc header).
   This searches all pages for given buffer size before moving on
   to the bigger size, splitting the larger buffer down if necessary.

   If none of the pages can fit the requested size, a new page is
   allocated and a page header created and allocated. In the special
   case of the buffer request being > PAGESIZE/2 a new page is always
   allocated.
*/
void* get_free_buffer(int size)
{
  pageheaderT* page_header = PAGE_HEADER(first_page);
  pageheaderT* prev_page = NULL;

  int i = 0;
  int search_size = round_up(REALSIZE(size));
  allocheaderT* to_be_allocated;
  freelistL* buffer_size = get_required_buffer(search_size, page_header);

  // Loops through each buffer size
  while (search_size <= PAGESIZE)
  {
    // Loops through each page until it goes through all of them or
    // finds a free buffer.
    while (page_header != NULL && buffer_size->first_block == NULL)
    {
      prev_page = page_header;
      page_header = page_header->next;
      buffer_size = get_required_buffer(search_size, page_header);
    }

    // None found, increase size and repeat
    if (buffer_size == NULL)
    {
      i++;
      page_header = PAGE_HEADER(first_page);
      prev_page = NULL;
      search_size = search_size * 2;
      buffer_size = get_required_buffer(search_size, page_header);
    }
    // Found. Splits depending on the number of times through the loop,
    // removes the buffer from the free list, and returns it.
    else
    {
      to_be_allocated = buffer_size->first_block;
      if (i == 0)
      {
        buffer_size->first_block = to_be_allocated->next;
      }
      else
      {
        for(; i > 0; i--)
        {
          buffer_size = split_buffer(buffer_size, page_header);
        }
        to_be_allocated = buffer_size->first_block;
        buffer_size->first_block = to_be_allocated->next;
      }

      page_header->used += 1;

      return to_be_allocated;
    }
  }

  // No buffers found. Find the last page again.
  while (page_header != NULL)
  {
    prev_page = page_header;
    page_header = page_header->next;
  }

  // Create a new page, split it up to insert the header.
  kma_page_t* new_page = init_page();
  page_header = PAGE_HEADER(new_page);
  prev_page->next = page_header;

  buffer_size = get_required_buffer(sizeof(pageheaderT), page_header);
  to_be_allocated = buffer_size->first_block;

  i = 0;
  while (buffer_size != NULL && buffer_size->first_block == NULL)
  {
    buffer_size = buffer_size->bigger_size;
    i++;
  }
  for(; i > 0; i--)
  {
    buffer_size = split_buffer(buffer_size, page_header);
  }

  to_be_allocated = buffer_size->first_block;
  buffer_size->first_block = to_be_allocated->next;

  // If size > PAGESIZE/2, clears free headers and allocates the
  // whole page.
  if (round_up(REALSIZE(size)) == PAGESIZE)
  {
    page_header->free_headers.buffer32.first_block = NULL;
    page_header->free_headers.buffer64.first_block = NULL;
    page_header->free_headers.buffer128.first_block = NULL;
    page_header->free_headers.buffer256.first_block = NULL;
    page_header->free_headers.buffer512.first_block = NULL;
    page_header->free_headers.buffer1024.first_block = NULL;
    page_header->free_headers.buffer2048.first_block = NULL;
    page_header->free_headers.buffer4096.first_block = NULL;
    page_header->free_headers.buffer8192.first_block = NULL;
    page_header->used += 1;
    return (void*)((long int) page_header + sizeof(pageheaderT));
  }

  // Now that the page has been created, try allocating again.
  return get_free_buffer(size);
}
Beispiel #26
0
xymongen_page_t *load_layout(char *pgset)
{
	char	pagetag[100], subpagetag[100], subparenttag[100], 
		vpagetag[100], vsubpagetag[100], vsubparenttag[100], 
		grouptag[100], summarytag[100], titletag[100], hosttag[100];
	char 	*name, *link, *onlycols, *exceptcols;
	char 	hostname[MAX_LINE_LEN];
	xymongen_page_t 	*toppage, *curpage, *cursubpage, *cursubparent;
	group_t *curgroup;
	host_t	*curhost;
	char	*curtitle;
	int	ip1, ip2, ip3, ip4;
	char	*p;
	int	fqdn = get_fqdn();
	char	*cfgdata, *inbol, *ineol, insavchar = '\0';

	if (loadhostsfromxymond) {
		if (load_hostnames("@", NULL, fqdn) != 0) {
			errprintf("Cannot load host configuration from xymond\n");
			return NULL;
		}
	}
	else {
		if (load_hostnames(xgetenv("HOSTSCFG"), "dispinclude", fqdn) != 0) {
			errprintf("Cannot load host configuration from %s\n", xgetenv("HOSTSCFG"));
			return NULL;
		}
	}

	if (first_host() == NULL) {
		errprintf("Empty configuration from %s\n", (loadhostsfromxymond ? "xymond" : xgetenv("HOSTSCFG")));
		return NULL;
	}

	dbgprintf("load_layout(pgset=%s)\n", textornull(pgset));

	/*
	 * load_hostnames() picks up the hostname definitions, but not the page
	 * layout. So we will scan the file again, this time doing the layout.
	 */

	if (pgset == NULL) pgset = "";
	sprintf(pagetag, "%spage", pgset);
	sprintf(subpagetag, "%ssubpage", pgset);
	sprintf(subparenttag, "%ssubparent", pgset);
	sprintf(vpagetag, "v%spage", pgset);
	sprintf(vsubpagetag, "v%ssubpage", pgset);
	sprintf(vsubparenttag, "v%ssubparent", pgset);
	sprintf(grouptag, "%sgroup", pgset);
	sprintf(summarytag, "%ssummary", pgset);
	sprintf(titletag, "%stitle", pgset);
	sprintf(hosttag, "%s:", pgset); for (p=hosttag; (*p); p++) *p = toupper((int)*p);

	toppage = init_page("", "", 0);
	addtopagelist(toppage);
	curpage = NULL;
	cursubpage = NULL;
	curgroup = NULL;
	curhost = NULL;
	cursubparent = NULL;
	curtitle = NULL;

	inbol = cfgdata = hostscfg_content();
	while (inbol && *inbol) {
		inbol += strspn(inbol, " \t");
		ineol = strchr(inbol, '\n');
		if (ineol) {
			while ((ineol > inbol) && (isspace(*ineol) || (*ineol == '\n'))) ineol--;
			if (*ineol != '\n') ineol++;

			insavchar = *ineol;
			*ineol = '\0';
		}

		dbgprintf("load_layout: -- got line '%s'\n", inbol);

		if ((strncmp(inbol, pagetag, strlen(pagetag)) == 0) || (strncmp(inbol, vpagetag, strlen(vpagetag)) == 0)) {
			getnamelink(inbol, &name, &link);
			if (curpage == NULL) {
				/* First page - hook it on toppage as a subpage from there */
				curpage = toppage->subpages = init_page(name, link, (strncmp(inbol, vpagetag, strlen(vpagetag)) == 0));
			}
			else {
				curpage = curpage->next = init_page(name, link, (strncmp(inbol, vpagetag, strlen(vpagetag)) == 0));
			}

			curpage->parent = toppage;
			if (curtitle) { 
				curpage->pretitle = curtitle; 
				curtitle = NULL; 
			}
			cursubpage = NULL;
			cursubparent = NULL;
			curgroup = NULL;
			curhost = NULL;
			addtopagelist(curpage);
		}
		else if ( (strncmp(inbol, subpagetag, strlen(subpagetag)) == 0) || (strncmp(inbol, vsubpagetag, strlen(vsubpagetag)) == 0) ) {
			if (curpage == NULL) {
				errprintf("'subpage' ignored, no preceding 'page' tag : %s\n", inbol);
				goto nextline;
			}

			getnamelink(inbol, &name, &link);
			if (cursubpage == NULL) {
				cursubpage = curpage->subpages = init_page(name, link, (strncmp(inbol, vsubpagetag, strlen(vsubpagetag)) == 0));
			}
			else {
				cursubpage = cursubpage->next = init_page(name, link, (strncmp(inbol, vsubpagetag, strlen(vsubpagetag)) == 0));
			}
			cursubpage->parent = curpage;
			if (curtitle) { 
				cursubpage->pretitle = curtitle; 
				curtitle = NULL;
			}
			cursubparent = NULL;
			curgroup = NULL;
			curhost = NULL;
			addtopagelist(cursubpage);
		}
		else if ( (strncmp(inbol, subparenttag, strlen(subparenttag)) == 0) || (strncmp(inbol, vsubparenttag, strlen(vsubparenttag)) == 0) ) {
			xymongen_page_t *parentpage, *walk;

			getparentnamelink(inbol, toppage, &parentpage, &name, &link);
			if (parentpage == NULL) {
				errprintf("'subparent' ignored, unknown parent page: %s\n", inbol);
				goto nextline;
			}

			cursubparent = init_page(name, link, (strncmp(inbol, vsubparenttag, strlen(vsubparenttag)) == 0));
			if (parentpage->subpages == NULL) {
				parentpage->subpages = cursubparent;
			} 
			else {
				for (walk = parentpage->subpages; (walk->next); (walk = walk->next)) ;
				walk->next = cursubparent;
			}
			if (curtitle) { 
				cursubparent->pretitle = curtitle; 
				curtitle = NULL;
			}
			cursubparent->parent = parentpage;
			curgroup = NULL;
			curhost = NULL;
			addtopagelist(cursubparent);
		}
		else if (strncmp(inbol, grouptag, strlen(grouptag)) == 0) {
			int sorthosts = (strstr(inbol, "group-sorted") != NULL);

			getgrouptitle(inbol, pgset, &link, &onlycols, &exceptcols);
			if (curgroup == NULL) {
				curgroup = init_group(link, onlycols, exceptcols, sorthosts);
				if (cursubparent != NULL) {
					cursubparent->groups = curgroup;
				}
				else if (cursubpage != NULL) {
					/* We're in a subpage */
					cursubpage->groups = curgroup;
				}
				else if (curpage != NULL) {
					/* We're on a main page */
					curpage->groups = curgroup;
				}
				else {
					/* We're on the top page */
					toppage->groups = curgroup;
				}
			}
			else {
				curgroup->next = init_group(link, onlycols, exceptcols, sorthosts);
				curgroup = curgroup->next;
			}
			if (curtitle) { curgroup->pretitle = curtitle; curtitle = NULL; }
			curhost = NULL;
		}
		else if (sscanf(inbol, "%3d.%3d.%3d.%3d %s", &ip1, &ip2, &ip3, &ip4, hostname) == 5) {
			void *xymonhost = NULL;
			int dialup, nonongreen, crittime = 1;
			double warnpct = reportwarnlevel;
			int warnstops = reportwarnstops;
			char *displayname, *clientalias, *comment, *description;
			char *alertlist, *onwaplist, *reporttime;
			char *nopropyellowlist, *nopropredlist, *noproppurplelist, *nopropacklist;
			char *targetpagelist[MAX_TARGETPAGES_PER_HOST];
			int targetpagecount;
			char *hval;

			/* Check for ".default." hosts - they are ignored. */
			if (*hostname == '.') goto nextline;

			if (!fqdn) {
				/* Strip any domain from the hostname */
				char *p = strchr(hostname, '.');
				if (p) *p = '\0';
			}

			/* Get the info */
			xymonhost = hostinfo(hostname);
			if (xymonhost == NULL) {
				errprintf("Confused - hostname '%s' cannot be found. Ignored\n", hostname);
				goto nextline;
			}

			/* Check for no-display hosts - they are ignored. */
			/* But only when we're building the default pageset */
			if ((strlen(pgset) == 0) && (xmh_item(xymonhost, XMH_FLAG_NODISP) != NULL)) goto nextline;

			for (targetpagecount=0; (targetpagecount < MAX_TARGETPAGES_PER_HOST); targetpagecount++) 
				targetpagelist[targetpagecount] = NULL;
			targetpagecount = 0;

			dialup = (xmh_item(xymonhost, XMH_FLAG_DIALUP) != NULL);
			nonongreen = (xmh_item(xymonhost, XMH_FLAG_NONONGREEN) != NULL);

			alertlist = xmh_item(xymonhost, XMH_NK);
			hval = xmh_item(xymonhost, XMH_NKTIME); if (hval) crittime = within_sla(xmh_item(xymonhost, XMH_HOLIDAYS), hval, 0);

			onwaplist = xmh_item(xymonhost, XMH_WML);
			nopropyellowlist = xmh_item(xymonhost, XMH_NOPROPYELLOW);
			if (nopropyellowlist == NULL) nopropyellowlist = xmh_item(xymonhost, XMH_NOPROP);
			nopropredlist = xmh_item(xymonhost, XMH_NOPROPRED);
			noproppurplelist = xmh_item(xymonhost, XMH_NOPROPPURPLE);
			nopropacklist = xmh_item(xymonhost, XMH_NOPROPACK);
			displayname = xmh_item(xymonhost, XMH_DISPLAYNAME);
			comment = xmh_item(xymonhost, XMH_COMMENT);
			description = xmh_item(xymonhost, XMH_DESCRIPTION);
			hval = xmh_item(xymonhost, XMH_WARNPCT); if (hval) warnpct = atof(hval);
			hval = xmh_item(xymonhost, XMH_WARNSTOPS); if (hval) warnstops = atof(hval);
			reporttime = xmh_item(xymonhost, XMH_REPORTTIME);

			clientalias = xmh_item(xymonhost, XMH_CLIENTALIAS);
			if (xymonhost && (strcmp(xmh_item(xymonhost, XMH_HOSTNAME), clientalias) == 0)) clientalias = NULL;

			if (xymonhost && (strlen(pgset) > 0)) {
				/* Walk the clone-list and pick up the target pages for this host */
				void *cwalk = xymonhost;
				do {
					hval = xmh_item_walk(cwalk);
					while (hval) {
						if (strncasecmp(hval, hosttag, strlen(hosttag)) == 0)
							targetpagelist[targetpagecount++] = strdup(hval+strlen(hosttag));
						hval = xmh_item_walk(NULL);
					}

					cwalk = next_host(cwalk, 1);
				} while (cwalk && 
					 (strcmp(xmh_item(cwalk, XMH_HOSTNAME), xmh_item(xymonhost, XMH_HOSTNAME)) == 0) &&
					 (targetpagecount < MAX_TARGETPAGES_PER_HOST) );

				/*
				 * HACK: Check if the pageset tag is present at all in the host
				 * entry. If it isn't, then drop this incarnation of the host.
				 *
				 * Without this, the following hosts.cfg file will have the
				 * www.hswn.dk host listed twice on the alternate pageset:
				 *
				 * adminpage nyc NYC
				 *
				 * 127.0.0.1   localhost      # bbd http://localhost/ CLIENT:osiris
				 * 172.16.10.2 www.xymon.com  # http://www.xymon.com/ ADMIN:nyc ssh noinfo
				 *
				 * page superdome Superdome
				 * 172.16.10.2 www.xymon.com # noconn
				 *
				 */
				if (strstr(inbol, hosttag) == NULL) targetpagecount = 0;
			}

			if (strlen(pgset) == 0) {
				/*
				 * Default pageset generated. Put the host into
				 * whatever group or page is current.
				 */
				if (curhost == NULL) {
					curhost = init_host(hostname, 0, displayname, clientalias,
							    comment, description,
							    ip1, ip2, ip3, ip4, dialup, 
							    warnpct, warnstops, reporttime,
							    alertlist, crittime, onwaplist,
							    nopropyellowlist, nopropredlist, noproppurplelist, nopropacklist);
					if (curgroup != NULL) {
						curgroup->hosts = curhost;
					}
					else if (cursubparent != NULL) {
						cursubparent->hosts = curhost;
					}
					else if (cursubpage != NULL) {
						cursubpage->hosts = curhost;
					}
					else if (curpage != NULL) {
						curpage->hosts = curhost;
					}
					else {
						toppage->hosts = curhost;
					}
				}
				else {
					curhost = curhost->next = init_host(hostname, 0, displayname, clientalias,
									    comment, description,
									    ip1, ip2, ip3, ip4, dialup,
									    warnpct, warnstops, reporttime,
									    alertlist, crittime, onwaplist,
									    nopropyellowlist,nopropredlist, 
									    noproppurplelist, nopropacklist);
				}
				curhost->parent = (cursubparent ? cursubparent : (cursubpage ? cursubpage : curpage));
				if (curtitle) { curhost->pretitle = curtitle; curtitle = NULL; }
				curhost->nonongreen = nonongreen;
			}
			else if (targetpagecount) {

				int pgnum;

				for (pgnum=0; (pgnum < targetpagecount); pgnum++) {
					char *targetpagename = targetpagelist[pgnum];

					char savechar;
					int wantedgroup = 0;
					xymonpagelist_t *targetpage = NULL;

					/* Put the host into the page specified by the PGSET: tag */
					p = strchr(targetpagename, ',');
					if (p) {
						savechar = *p;
						*p = '\0';
						wantedgroup = atoi(p+1);
					}
					else {
						savechar = '\0';
						p = targetpagename + strlen(targetpagename);
					}

					/* Find the page */
					if (strcmp(targetpagename, "*") == 0) {
						*targetpagename = '\0';
					}
					for (targetpage = pagelisthead; (targetpage && (strcmp(targetpagename, targetpage->pageentry->name) != 0)); targetpage = targetpage->next) ;

					*p = savechar;
					if (targetpage == NULL) {
						errprintf("Warning: Cannot find any target page named '%s' in set '%s' - dropping host '%s'\n", 
							targetpagename, pgset, hostname);
					}
					else {
						host_t *newhost = init_host(hostname, 0, displayname, clientalias,
									    comment, description,
									    ip1, ip2, ip3, ip4, dialup,
									    warnpct, warnstops, reporttime,
									    alertlist, crittime, onwaplist,
									    nopropyellowlist,nopropredlist, 
									    noproppurplelist, nopropacklist);

						if (wantedgroup > 0) {
							group_t *gwalk;
							host_t  *hwalk;
							int i;

							for (gwalk = targetpage->pageentry->groups, i=1; (gwalk && (i < wantedgroup)); i++,gwalk=gwalk->next) ;
							if (gwalk) {
								if (gwalk->hosts == NULL)
									gwalk->hosts = newhost;
								else {
									for (hwalk = gwalk->hosts; (hwalk->next); hwalk = hwalk->next) ;
									hwalk->next = newhost;
								}
							}
							else {
								errprintf("Warning: Cannot find group %d for host %s - dropping host\n",
									wantedgroup, hostname);
							}
						}
						else {
							/* Just put in on the page's hostlist */
							host_t *walk;
	
							if (targetpage->pageentry->hosts == NULL)
								targetpage->pageentry->hosts = newhost;
							else {
								for (walk = targetpage->pageentry->hosts; (walk->next); walk = walk->next) ;
								walk->next = newhost;
							}
						}

						newhost->parent = targetpage->pageentry;
						if (curtitle) newhost->pretitle = curtitle;
					}

					curtitle = NULL;
				}
			}
		}
		else if (strncmp(inbol, summarytag, strlen(summarytag)) == 0) {
			/* summary row.column      IP-ADDRESS-OF-PARENT    http://xymon.com/ */
			char sumname[MAX_LINE_LEN];
			char receiver[MAX_LINE_LEN];
			char url[MAX_LINE_LEN];
			summary_t *newsum;

			if (sscanf(inbol, "summary %s %s %s", sumname, receiver, url) == 3) {
				newsum = init_summary(sumname, receiver, url);
				newsum->next = sumhead;
				sumhead = newsum;
			}
		}
		else if (strncmp(inbol, titletag, strlen(titletag)) == 0) {
			/* Save the title for the next entry */
			curtitle = strdup(skipwhitespace(skipword(inbol)));
		}

nextline:
		if (ineol) {
			*ineol = insavchar;
			if (*ineol != '\n') ineol = strchr(ineol, '\n');

			inbol = (ineol ? ineol+1 : NULL);
		}
		else
			inbol = NULL;
	}

	xfree(cfgdata);
	return toppage;
}
Beispiel #27
0
/* -- write buffer contents, break at full pages -- */
void write_buffer(void)
{
	char *p_buf;
	int l, np;
	float p1, dp;
	int outft_sav;

	if (mbf == outbuf || multicol_start != 0)
		return;
	if (!in_page && !epsf)
		init_page();
	outft_sav = outft;
	p1 = 0;
	p_buf = outbuf;
	for (l = 0; l < ln_num; l++) {
		if (ln_pos[l] > 0) {		/* if in multicol */
			int ll;
			float pos;

			for (ll = l + 1; ll < ln_num; ll++) {
				if (ln_pos[ll] <= 0) {
					pos = ln_pos[ll];
					while (--ll >= l)
						ln_pos[ll] = pos;
					break;
				}
			}
		}
		dp = ln_pos[l] - p1;
		np = remy + dp < 0 && !epsf;
		if (np) {
			close_page();
			init_page();
			if (ln_font[l] >= 0) {
				struct FONTSPEC *f;

				f = &cfmt.font_tb[ln_font[l]];
				output(fout, "%.1f F%d\n",
					f->size, f->fnum);
			}
		}
		if (ln_scale[l] != cur_scale) {
			output(fout, "%.3f dup scale\n",
				ln_scale[l] / cur_scale);
			cur_scale = ln_scale[l];
		}
		if (ln_lmarg[l] != cur_lmarg) {
			output(fout, "%.2f 0 T\n",
				(ln_lmarg[l] - cur_lmarg) / cur_scale);
			cur_lmarg = ln_lmarg[l];
		}
		if (np) {
			output(fout, "0 %.2f T\n", -cfmt.topspace);
			remy -= cfmt.topspace * cfmt.scale;
		}
		if (*p_buf != '\001') {
			if (epsf > 1 || svg)
				svg_write(p_buf, ln_buf[l] - p_buf);
			else
				fwrite(p_buf, 1, ln_buf[l] - p_buf, fout);
		} else {			/* %%EPS - see parse.c */
			FILE *f;
			char line[BSIZE], *p, *q;

			p = strchr(p_buf + 1, '\n');
			fwrite(p_buf + 1, 1, p - p_buf, fout);
			p_buf = p + 1;
			p = strchr(p_buf, '%');
			*p++ = '\0';
			q = strchr(p, '\n');
			*q = '\0';
			if ((f = fopen(p, "r")) == NULL) {
				error(1, NULL, "Cannot open EPS file '%s'", p);
			} else {
				if (epsf > 1 || svg) {
					fprintf(fout, "<!--Begin document %s-->\n",
							p);
					svg_output(fout, "gsave\n"
							"%s T\n",
							p_buf);
					while (fgets(line, sizeof line, f))	/* copy the file */
						svg_write(line, strlen(line));
					svg_output(fout, "grestore\n"
							"%s T\n",
							p_buf);
					fprintf(fout, "<!--End document %s-->\n",
							p);
				} else {
					fprintf(fout,
						"save\n"
						"/showpage{}def/setpagedevice{pop}def\n"
						"%s T\n"
						"%%%%BeginDocument: %s\n",
						p_buf, p);
					while (fgets(line, sizeof line, f))	/* copy the file */
						fwrite(line, 1, strlen(line), fout);
					fprintf(fout, "%%%%EndDocument\n"
							"restore\n");
				}
				fclose(f);
			}
		}
		p_buf = ln_buf[l];
		remy += dp;
		p1 = ln_pos[l];
	}
#if 1 //fixme:test
	if (*p_buf != '\0') {
//		fprintf(stderr, "??? bug - buffer not empty:\n%s\n", p_buf);
		memcpy(outbuf, p_buf, strlen(p_buf) + 1);
		mbf = &outbuf[strlen(outbuf)];
	} else {
		mbf = outbuf;
	}
#endif
	outft = outft_sav;
	bposy = 0;
	ln_num = 0;
	use_buffer = 0;
}
Beispiel #28
0
BOOL DviConfigImport(HWND hwnd)
{
  char szBuf[256], *p;
  int i;

  SendDlgItemMessage(hwnd, IDC_EDITBDPI, WM_GETTEXT, (WPARAM)sizeof(szBuf), (LPARAM)szBuf);
  if (resource._pixels_per_inch = atoi(szBuf))
    xputenv("BDPI", szBuf);

  SendDlgItemMessage(hwnd, IDC_EDITALTFONT, WM_GETTEXT, (WPARAM)sizeof(szBuf), (LPARAM)szBuf);
  if (resource._alt_font)
    free(resource._alt_font);
  resource._alt_font = strdup(szBuf);

  SendDlgItemMessage(hwnd, IDC_COMBOMFMODE, WM_GETTEXT, (WPARAM)sizeof(szBuf), (LPARAM)szBuf);
  if (resource.mfmode)
    free(resource.mfmode);

  for (i = 0; i < sizeof(avail_modes)/sizeof(mfmode) - 1; i++) {
    if (strcmp(szBuf, avail_modes[i].desc) == 0) {
      resource.mfmode = strdup(avail_modes[i].name);
      xputenv("MODE", resource.mfmode);
      break;
    }
  }
#if 0
  fprintf(stderr, "Dvi config import putenv MODE\n");
#endif
  SendDlgItemMessage(hwnd, IDC_COMBOPAPER, WM_GETTEXT, (WPARAM)sizeof(szBuf), (LPARAM)szBuf);
  if (resource.paper)
    free(resource.paper);

  if (*szBuf) {
    for (p = szBuf; *p && p < szBuf+sizeof(szBuf); p++)
      if (*p == ' ') {
	*p = '\0';
	break;
      }
    resource.paper = strdup(szBuf);
    set_paper_type();
    init_page();
  }

  resource.makepk = (SendDlgItemMessage(hwnd, IDC_CHECKMAKEPK, BM_GETCHECK, 
					(WPARAM) 0, (LPARAM)0) == BST_CHECKED);

  resource._list_fonts = (SendDlgItemMessage(hwnd, IDC_CHECKLISTFONTS, 
					     BM_GETCHECK, (WPARAM) 0, (LPARAM)0) == BST_CHECKED);
  resource.scan_flag = (SendDlgItemMessage(hwnd, IDC_CHECKSCAN, 
					   BM_GETCHECK, (WPARAM) 0, (LPARAM)0) == BST_CHECKED);
  resource.log_flag = (SendDlgItemMessage(hwnd, IDC_CHECKLOG, 
					   BM_GETCHECK, (WPARAM) 0, (LPARAM)0) == BST_CHECKED);
  resource.single_flag = (SendDlgItemMessage(hwnd, IDC_CHECKSINGLE, 
					     BM_GETCHECK, (WPARAM) 0, (LPARAM)0) == BST_CHECKED);
  resource._warn_spec = (SendDlgItemMessage(hwnd, IDC_CHECKHUSHSPECIALS, 
					    BM_GETCHECK, (WPARAM) 0, (LPARAM)0) == BST_CHECKED);
  resource._hush_chars = (SendDlgItemMessage(hwnd, IDC_CHECKHUSHCHARS,
					     BM_GETCHECK,(WPARAM) 0, (LPARAM)0) == BST_CHECKED);
  resource._hush_chk = (SendDlgItemMessage(hwnd, IDC_CHECKHUSHCHECKSUMS, 
					   BM_GETCHECK, (WPARAM) 0, (LPARAM)0) == BST_CHECKED);
  resource.allow_shell = (SendDlgItemMessage(hwnd, IDC_CHECKALLOWSHELL, 
					     BM_GETCHECK, (WPARAM) 0, (LPARAM)0) == BST_CHECKED);

  return TRUE;
}