Esempio n. 1
0
int do_grid(void)
{
    double g, e1, e2;
    int j;

    if (PS.grid <= 0)
	return 1;

    /* set color and set line width to 1 */
    set_ps_color(&PS.grid_color);
    set_line_width(PS.grid_width);

    /* draw horizontal lines in 3 pieces -- lat-lon lines must not
     * extend more than half the globe
     * start with first grid line just south of the window north
     */
    e1 = (PS.w.east * 2 + PS.w.west) / 3;
    e2 = (PS.w.west * 2 + PS.w.east) / 3;

    g = floor(PS.w.north / PS.grid) * PS.grid;
    for (j = 0; g >= PS.w.south; j++, g -= PS.grid) {
	if (g == PS.w.north || g == PS.w.south)
	    continue;

	start_line(PS.w.east, g);
	sec_draw = 0;
	G_plot_line(PS.w.east, g, e1, g);
	fprintf(PS.fp, " D ");

	start_line(e1, g);
	sec_draw = 0;
	G_plot_line(e1, g, e2, g);
	fprintf(PS.fp, " D ");

	start_line(e2, g);
	sec_draw = 0;
	G_plot_line(e2, g, PS.w.west, g);
	fprintf(PS.fp, " D\n");
    }

    /* vertical lines */
    /* start with first grid line just west of the window east */
    g = floor(PS.w.east / PS.grid) * PS.grid;
    for (j = 0; g > PS.w.west; j++, g -= PS.grid) {
	if (g == PS.w.east || g == PS.w.west)
	    continue;
	start_line(g, PS.w.north);
	sec_draw = 0;
	G_plot_line(g, PS.w.north, g, PS.w.south);
	if (j & 1)
	    fprintf(PS.fp, " D\n");
	else
	    fprintf(PS.fp, " D ");
    }

    return 0;
}
Esempio n. 2
0
static void print_trailer(struct print_state *state)
{
	start_line(state, 0);
	fprintf(state->out,
"};\n"
		);

}
            void print(const T& value) {
                if (m_verbose) {
                    start_line();
                    std::cerr << value;

                    // check if there was a newline a the end and remember that
                    std::ostringstream output_buffer;
                    output_buffer << value;
                    if (!output_buffer.str().empty() && output_buffer.str().back() == '\n') {
                        m_newline = true;
                    }
                }
            }
Esempio n. 4
0
static void print_header(struct print_state *state)
{
	start_line(state, 0);
	fprintf(state->out,
"#include \"translate/keysym_attributes.h\"\n"
"\n"
"/* automatically generated do not touch */\n "
"unsigned char keysym_attributes[] = \n"
"{\n"
		);
	state->line += 4;
	state->chars = 0;
}
Esempio n. 5
0
int do_grid_cross(void)
{
    double g_north, g_east;
    int j, k;

    if (PS.grid <= 0)
	return 1;

    /* set color and set line width to 1 */
    set_ps_color(&PS.grid_color);
    set_line_width(PS.grid_width);

    g_north = floor(PS.w.north / PS.grid) * PS.grid;
    g_east = floor(PS.w.east / PS.grid) * PS.grid;
    for (j = 0; g_north >= PS.w.south; j++, g_north -= PS.grid) {
	for (k = 0; g_east > PS.w.west; k++, g_east -= PS.grid) {

	    if (g_north == PS.w.north || g_north == PS.w.south)
		continue;
	    if (g_east == PS.w.east || g_east == PS.w.west)
		continue;

	    start_line(g_east - PS.grid_cross, g_north);
	    G_plot_line(g_east - PS.grid_cross, g_north,
			g_east + PS.grid_cross, g_north);
	    fprintf(PS.fp, " D ");
	    start_line(g_east, g_north - PS.grid_cross);
	    G_plot_line(g_east, g_north - PS.grid_cross, g_east,
			g_north + PS.grid_cross);
	    fprintf(PS.fp, " D ");
	}
	g_east = floor(PS.w.east / PS.grid) * PS.grid;
    }

    return 0;
}
Esempio n. 6
0
static void print_entry(struct print_state *state, int letter, int attrib)
{
	int amount;
#if 0
	fprintf(state->out, "/* 0x%04X */ 0x%02X,\n", letter, attrib);
	state->line++;
	state->chars = 0;
#else
	start_line(state, 75);
	amount = fprintf(state->out, "%d,", attrib);
	if (amount > 0) {
		state->chars += amount;
	}
#endif
}
Esempio n. 7
0
File: jeff.c Progetto: rdebath/sgt
void do_file(FILE *fp, int unjeff, int (*start_line)(char *line))
{
    if (unjeff) {
	/*
	 * Unjeffing does not depend on the start_line function. We
	 * destroy all \n, and replace all \r with \n.
	 */
	char buf[4096];
	int len;
	int i, j;

	while ((len = fread(buf, 1, sizeof(buf), stdin)) > 0) {
	    for (i = j = 0; i < len; i++) {
		if (buf[i] == '\r')
		    buf[j++] = '\n';
		else if (buf[i] != '\n')
		    buf[j++] = buf[i];
	    }
	    fwrite(buf, 1, j, stdout);
	}
    } else {
	/*
	 * To jeff, we read each line of the file and translate its
	 * trailing \r into a \n. Then we write a \n before output
	 * if the line matches the start_line() criterion and we're
	 * not right at the start of the file; finally, we write a
	 * trailing \n if we've output anything at all.
	 */
	int firstline = TRUE;

	while (1) {
	    char *p = fgetline(fp);
	    char *q;

	    if (!firstline && (!p || start_line(p)))
		fputc('\n', stdout);
	    if (!p)
		break;
	    for (q = p; *q; q++)
		if (*q == '\n')
		    *q = '\r';
	    fputs(p, stdout);
	    firstline = FALSE;

	    free(p);
	}
    }
}
Esempio n. 8
0
int draw_bot(void)
/*    *--*--*    */
/*    |     |    */
/*    *  |  *    */
/*    |  |  |    */
/*    *--*--*    */
{
    start_line(e2, n2);
    sec_draw = 0;
    G_plot_line(e2, n2, e2, n3);
    if (++k == 3)
	fprintf(PS.fp, " D\n");
    else
	fprintf(PS.fp, " D ");

    return 0;
}
Esempio n. 9
0
static int extend_line(struct COOR *p, struct COOR *q)
{
    while (p == NULL) {
	G_warning(_("extend line:  p is NULL"));
	/* should never happen by the logic of algorithm */
	p = start_line(1);
    }

    G_debug(3, "extend_line: p: row:%d, col:%d; q: row:%d, col:%d",
	    p->row, p->col, q->row, q->col);

    p->row = row;
    p->col = col - 1;

    switch (data_type) {
    case CELL_TYPE:
	p->val = ((CELL *) middle)[col];
	break;
    case FCELL_TYPE:
	p->dval = ((FCELL *) middle)[col];
	break;
    case DCELL_TYPE:
	p->dval = ((DCELL *) middle)[col];
	break;
    default:
	break;
    }

    if (p->fptr != NULL) {
	G_warning(_("extend_lines: p front pointer not NULL!"));
	/* should never happen by the logic of algorithm */
	/* exit(EXIT_FAILURE); */
    }

    p->fptr = q;
    if (q->bptr != NULL) {
	G_warning(_("extend_lines: q back pointer not NULL!"));
	/* should never happen by the logic of algorithm */
	/* exit(EXIT_FAILURE); */
    }
    q->bptr = p;

    return 0;
}
Esempio n. 10
0
/* This is plain crap, really, however there is no good support for
 * this all in my lib yet (there is no support for such things in
 * nearly no language, either.  Python is best in this regard).
 */
static void
dump_line(const char *ptr, size_t n, int lineend)
{
  const char		*p;

  start_line(0, lineend);
  p = tino_buf_get_sN(&prefix);

  if (flag_hexdump)
    tino_xd(&out, p, 8, byte_pos, (const unsigned char *)ptr, n+lineend);
  else
    {
      if (p && *p)
	tino_data_putsA(&out, p);
#ifdef HAVE_ESCAPE_XML
      if (flag_xml)
	tino_data_write_xmlA(&out, ptr, n, flag_xml-1);
      else
#endif
#ifdef HAVE_ESCAPE_JSON
      if (flag_xml)
	tino_data_write_jsonA(&out, ptr, n);
      else
#endif
        tino_data_writeA(&out, ptr, n);
    }

  byte_pos	+= n+lineend;

  in_line	= !lineend;
  p		= in_line ? line_cont_suffix : line_suffix;
  if (!p && !flag_hexdump)
    p		= "\n";
  if (p && *p)
    tino_data_putsA(&out, p);
}
Esempio n. 11
0
int main(int argc,char** argv) {

    if (argc != 3) {
        fprintf(stderr,"usage: RE216_CLIENT hostname port\n");
        return 1;
    }
    
	// -----------------------------------------------------------------
	// ------------------------ Variables ------------------------------
	
	// Buffer
	char *input = NULL;		// Taille d'entrée dynamique
	char output[TAILLE_MSG];// Taille de réception fixée
    
	// Liste chaînée pour l'envoi de fichiers
	struct file fichiers;
		memset(&fichiers, 0, sizeof(struct file));

	// Récupération de la structure sockaddr_in6 pour l'adresse du serveur
	struct sockaddr_in6* server_add = get_addr_info(atoi(argv[2]), argv[1]);

	// Création de la socket
	int sckt = do_socket();  

	// Connexion de la socket à l'adresse server_add
	int conn = do_connect(sckt, *server_add);

	// Initialisation des tableaux pour utliser select ------------------
    
    fd_set fd_set_read; // Ici seront stockés les descripteurs de fichier
    
    int i, select_ret_val;
    
    // Socket du serveur quand elle existe
    int socket_fichier = -1;
    
    // Eventuellement : timeout du select
	//~ struct timeval tv;
	//~ tv.tv_sec = 5;
	//~ tv.tv_usec = 0;
	
	init_reg();
	// -----------------------------------------------------------------
	// -----------------------------------------------------------------
	
	start_line();

	// Boucle jusqu'à recevoir le "/quit" final
	do {
		
		// ------------------------ R.A.Z ------------------------------
		// clean the set before adding file descriptors
		FD_ZERO(&fd_set_read);
		
		// add the fd for server connection
		FD_SET(sckt, &fd_set_read);

		// add the fd for user-input
		FD_SET(fileno(stdin), &fd_set_read);
		// -------------------------------------------------------------
		 
		// we now wait for any file descriptor to be available for reading
        select_ret_val = select(sckt + 1, &fd_set_read, NULL, NULL, NULL);//&tv);
        
        if (select_ret_val == -1) {
			error("Erreur concernant le select ");
		}
        
        //printf("Le retour de la fonction select est : %i", select_ret_val);
		
		for (i = 0; i < (sckt+1) && select_ret_val > 0; i++) {
	
            // Le buffer est nettoyé avec memset directement dans les fonctions
            
            //printf("Bonjour je suis le i n°%i. Retour => %i\n", i, select_ret_val);

            // Si le file descripteur i est dans le set mis en écoute, c'est qu'il y a une activité
            if (FD_ISSET(i, &fd_set_read)) {
				
				// printf("Descripteur trouvé : %i\n", i);

                if (i == fileno(stdin)) // C'est une entrée utilisateur
					client_write(&input, sckt, &fichiers);
				
				else // Les données viennent du serveur
					if (!client_read(sckt, output, &fichiers, &socket_fichier))
						break;

                // Select_ret_val est le nombre de descripteurs où il y 
                // a eu une activité, on diminue donc sa valeur au fur
                // et à mesure.
                select_ret_val--;

            }
        }

	} while(notquit(input) && notquit(output));

	//printf("Extinction.\n");

	free(input);
	
	free_file(&fichiers);

	free_reg();

	// Fermeture de la socket
    close_socket(sckt);
    
	printf("Fin du tchat\n");
	
    return 0;
}
Esempio n. 12
0
static void
unbuffered(const char *arg0, int argc, char **argv)
{
  TINO_BUF	buf;

  if (!line_cont_suffix && !flag_hexdump)
    if (flag_localtime || flag_linecount || flag_utc || flag_verbose)
      line_cont_suffix = "\n";
  producer = 0;
  if (argc)
    {
      int	fds[2], redir[TINO_OPEN_MAX], fdmax, i;

      if (tino_file_pipeE(fds))
	tino_exit("cannot create pipe");

      fdmax = fd_in<3 ? 3 : fd_in+1;

      for (i=fdmax; --i>=0; )
        redir[i] = -1;				/* preserve all FDs	*/

      if (fd_in<0)
        fd_in = 1;

      redir[2] = flag_both ? fds[1] : 2;	/* catch stderr on -d, too	*/
      if (fd_in==2)
        redir[1] = redir[2];			/* swap stdin/stderr on -i2	*/
      redir[fd_in] = fds[1];			/* catch the given FD */

      /* catch the child's output for preprocessing
       */
      producer = tino_fork_execO(redir, fdmax, argv, NULL, 0, NULL);
      tino_file_closeE(fds[1]);

      fd_in = fds[0];

#if 0
      /* Following is a mess.  It is only needed for a consumer, though.
       * With a producer we see EOF on the pipe.
       * Shall be handled implicitely by a library somehow:
       */
      tino_sigset(SIGCHLD, terminate);
      terminate();	/* catch early terminated childs	*/
#endif
    }

  tino_buf_initO(&buf);
  if (producer && flag_verbose)
    {
      start_line(1, 1);
      add_prefix("start");
      for (; *argv; argv++)
	add_prefix(" '%s'", *argv);	/* XXX TODO sadly, escape is implemented in tino_io, not in tino_buf	*/
      add_prefix("\n");
      out_open();
      tino_data_putsA(&out, tino_buf_get_sN(&prefix));
    }

  if (fd_in<0)
    fd_in = 0;
  while (tino_buf_readE(&buf, fd_in, -1))
    {
      size_t		n;

      out_open();
      /* XXX TODO MISSING:
       * for flag_buffer==1 or flag_buffer==2
       * immediately write STDOUT(1),
       * but buffer STDERR(dump_line)
       */
      while ((n=tino_buf_get_lenO(&buf))>0)
	{
	  const char	*ptr;
	  size_t	k, p;

	  ptr	= tino_buf_getN(&buf);
	  p	= 0;
	  for (k=0; k<n; k++)
	    if (ptr[k]==line_terminator)
	      {
		dump_line(ptr+p, k-p, 1);
		p	= k+1;
	      }
	  /* k=n	*/
	  if (flag_buffer && p)
	    n = p;	/* do not output incomplete line	*/
	  else if ((flag_buffer>1 && n<=99999) || flag_buffer>2)
	    break;		/* buffer fragments	*/

	  /* We shall, nonblockingly, read additional input data here,
	   * if available.  Leave this to future.
	   */
	  TINO_XXX;

	  if (p<n)
	    dump_line(ptr+p, n-p, 0);
	  if (flag_cat)
	    tino_buf_advanceO(&buf, n);
	  else if (tino_buf_write_away_allE(&buf, 1, n))
	    {
	      /* silently drop out	*/
	      *tino_main_errflag	= 1;
	      break;
	    }
	  if (flag_buffer)
	    break;
	}
      out_flush();
    }
  {
      size_t		n;

      /* in case of flag_buffer: send the rest	*/
      if ((n=tino_buf_get_lenO(&buf))>0)
	{
	  const char	*ptr;

	  out_open();
	  ptr	= tino_buf_getN(&buf);
	  dump_line(ptr, n, 0);
	  if (!flag_cat && tino_buf_write_away_allE(&buf, 1, n))
	    *tino_main_errflag	= 1;
	}
  }
  if (producer)
    {
      char *cause;

#if 0
      tino_sigdummy(SIGCHLD);	/* prevent reentrance of waitpid()	*/
#endif
      /* wait for child to finish after the pipe was closed,
       * so give the child the chance to terminate.
       */
      tino_file_closeE(0);
      *tino_main_errflag	= tino_wait_child_exact(producer, &cause);
      if (flag_verbose)
	{
	  start_line(1, 1);
	  add_prefix("end %s\n", cause);
	  out_open();
	  tino_data_putsA(&out, tino_buf_get_sN(&prefix));
	}
    }
  out_close();			/* close(2)	*/
}
Esempio n. 13
0
 int CompiledCode::start_line(STATE) {
   return start_line();
 }
Esempio n. 14
0
static int update_list(int count)
{
    struct COOR *new_ptr1, *new_ptr2, *new_ptr3;

    G_debug(3, "update_list: count:%d row:%d col:%d", count, row, col - 1);

    switch (count) {
    case 0:
	G_debug(1, "Isolated cell (%d,%d)", row, col);
	break;
    case 1:			/* begin or end line */
	if (ml)
	    h_ptr = end_line(h_ptr, 0);
	if (tl)
	    v_list[col].left = end_line(v_list[col].left, 0);
	if (tc)
	    v_list[col].center = end_line(v_list[col].center, 0);
	if (tr)
	    v_list[col].right = end_line(v_list[col].right, 0);
	if (mr)
	    h_ptr = start_line(0);
	if (br)
	    v_list[col + 1].left = start_line(0);
	if (bc)
	    v_list[col].center = start_line(0);
	if (bl)
	    v_list[col - 1].right = start_line(0);
	break;
    case 2:			/* straight or bent line */
	if (tl != 0 && br != 0) {	/* slanted line (\) */
	    v_list[col + 1].left = v_list[col].left;
	    v_list[col].left = NULL;
	}
	else if (tr != 0 && bl != 0) {	/* slanted line (/) */
	    v_list[col - 1].right = v_list[col].right;
	    v_list[col].right = NULL;
	}

	/* first take care of the cases where both non-zero
	   neighbours are in a upper-left corner (cw from ml to tr) */
	else if (ml != 0 && tc != 0) {	/* bend (_|) */
	    join_lines(h_ptr, v_list[col].center);
	    h_ptr = v_list[col].center = NULL;
	}
	else if (ml != 0 && tr != 0) {	/* bend (_/) */
	    join_lines(h_ptr, v_list[col].right);
	    h_ptr = v_list[col].left = NULL;
	}
	else if (tl != 0 && tr != 0) {	/* bend (\/) */
	    join_lines(v_list[col].left, v_list[col].right);
	    v_list[col].left = v_list[col].right = NULL;
	}
	else if (tl != 0 && tc != 0)	/* bend (\|) */
	    v_list[col].center = end_line(v_list[col].center, 1);
	else if (tr != 0 && tc != 0)	/* bend |/ */
	    v_list[col].center = end_line(v_list[col].center, 1);
	else if (tl != 0 && ml != 0)
	    h_ptr = end_line(h_ptr, 1);

	/* now take care of the cases when non-zero neighbours
	   are next to nonzero neighbours in a top-left corner */
	else if (bl != 0 && ml != 0)
	    v_list[col].center = start_line(1);
	else if (tr != 0 && mr != 0)
	    h_ptr = start_line(1);
	else if (!((tc != 0 && bc != 0) || (ml != 0 && mr != 0)))
	    /* if not horiz or vertical line */
	{
	    /* one of the non zero neighbours is in the top left corner,
	       and the other one is one of bl - mr, not next to the first one */
	    if (ml || tl || tc || tr) {	/* old line bends toward *//*   new area */
		new_ptr1 = get_ptr();

		if (ml) {	/* join new to where came from */
		    if (h_ptr == NULL)
			G_debug(1, "h_ptr is NULL!");

		    /* this should never happen by the logic of algorithm */
		    extend_line(h_ptr, new_ptr1);
		    h_ptr = NULL;
		}
		else if (tl) {
		    if (v_list[col].left == NULL)
			G_debug(1, "v_list[col].left is NULL!");

		    /* this should never happen by the logic of algorithm */
		    extend_line(v_list[col].left, new_ptr1);
		    v_list[col].left = NULL;
		}
		else if (tc) {
		    if (v_list[col].center == NULL)
			G_debug(1, "v_list[col].center is NULL!");

		    /* this should never happen by the logic of algorithm */
		    extend_line(v_list[col].center, new_ptr1);
		    v_list[col].center = NULL;
		}
		else {		/* tr */

		    if (v_list[col].right == NULL)
			G_debug(1, "v_list[col].right is NULL!");

		    /* this should never happen by the logic of algorithm */
		    extend_line(v_list[col].right, new_ptr1);
		    v_list[col].right = NULL;
		}

		if (mr)
		    /* find out where going */
		    /* tr is 0 here */
		    h_ptr = new_ptr1;
		else if (br)
		    v_list[col + 1].left = new_ptr1;
		else if (bc)
		    v_list[col].center = new_ptr1;
		else		/* bl, ml is 0 here */
		    v_list[col - 1].right = new_ptr1;
	    }
	    else {		/* lower-left */
		/* if the non-zero neigbours are adjacent */
		if (mr && br)
		    h_ptr = start_line(1);
		else if ((br && bc) || (bl && bc))
		    v_list[col].center = start_line(1);
		else
		    /* the non-zero neigbours are not adjacent */
		{		/* starting in middle of line */
		    new_ptr1 = get_ptr();
		    new_ptr2 = get_ptr();
		    new_ptr3 = get_ptr();
		    new_ptr1->fptr = new_ptr2;
		    new_ptr1->bptr = new_ptr3;
		    new_ptr3->bptr = new_ptr2->bptr = new_ptr1;

		    if (mr && bc) {
			h_ptr = new_ptr2;
			v_list[col].center = new_ptr3;
		    }
		    else if (mr && bl) {
			h_ptr = new_ptr2;
			v_list[col - 1].right = new_ptr3;
		    }
		    else if (bl && br) {
			v_list[col - 1].right = new_ptr3;
			v_list[col + 1].left = new_ptr2;
		    }
		}		/* starting in the middle of the line */
	    }
	}
	else if (value_flag) {	/* horizontal or vertical line */
	    int ml_val, mc_val, mr_val;	/* horiz */
	    int tc_val, bc_val;	/* vert */

	    ml_val = mc_val = mr_val = tc_val = bc_val = 0;
	    /* only CELL supported */
	    if (data_type == CELL_TYPE) {
		ml_val = ((CELL *) middle)[col - 1];
		mc_val = ((CELL *) middle)[col];
		mr_val = ((CELL *) middle)[col + 1];

		tc_val = ((CELL *) top)[col];
		bc_val = ((CELL *) bottom)[col];
	    }

	    if ((mc && mr) && mc_val != mr_val) {	/* break the horizontal line */
		h_ptr = end_line(h_ptr, 1);
		h_ptr = start_line(1);
	    }
	    else if ((mc && bc) && mc_val != bc_val) {	/* break the vertical line */
		v_list[col].center = end_line(v_list[col].center, 1);
		v_list[col].center = start_line(1);
	    }

	    if ((mc && ml) && mc_val != ml_val) {
		h_ptr->bptr->val = mc_val;
	    }
	    else if ((mc && tc) && mc_val != tc_val) {
		v_list[col].center->bptr->val = mc_val;
	    }
	}
	break;
    case 3:
	if (ml || tl || tc || (tr && !mr)) {
	    if (ml)		/* stop horz. and vert. lines */
		h_ptr = end_line(h_ptr, 1);

	    if (tc)
		v_list[col].center = end_line(v_list[col].center, 1);

	    /* stop diag lines if no horz,vert */
	    if ((tl) && (!ml) && (!tc))
		v_list[col].left = end_line(v_list[col].left, 1);
	    if ((tr) && (!mr) && (!tc))
		v_list[col].right = end_line(v_list[col].right, 1);
	}

	if (mr)			/* start horz. and vert */
	    h_ptr = start_line(1);
	if (bc)
	    v_list[col].center = start_line(1);

	/* start diag if no horz,vert */
	if ((br) && (!mr) && (!bc))
	    v_list[col + 1].left = start_line(1);
	if ((bl) && (!ml) && (!bc))
	    v_list[col - 1].right = start_line(1);
	break;
    case 4:
	if (ml)			/* end horz. and vert lines */
	    h_ptr = end_line(h_ptr, 1);

	if (tc)
	    v_list[col].center = end_line(v_list[col].center, 1);

	/* end diag lines only if no horz,vert */
	if ((tl) && (!ml) && (!tc))
	    v_list[col].left = end_line(v_list[col].left, 1);
	if ((tr) && (!mr) && (!tc))
	    v_list[col].right = end_line(v_list[col].right, 1);

	if (mr)			/* start horz. and vert */
	    h_ptr = start_line(1);
	if (bc)
	    v_list[col].center = start_line(1);

	/* start diag if no horz,vert */
	if ((br) && (!mr) && (!bc))
	    v_list[col + 1].left = start_line(1);
	if ((bl) && (!ml) && (!bc))
	    if (bl)
		v_list[col - 1].right = start_line(1);
	break;
    case 5:
	/* G_message(_("crowded cell %xH (%d,%d) -continuing"),count,row,col); */
	/* I think 5 neighbours is nor crowded, so we shouldn't worry the user
	   Olga */
	if (ml)			/* end horz. and vert lines */
	    h_ptr = end_line(h_ptr, 1);

	if (tc)
	    v_list[col].center = end_line(v_list[col].center, 1);

	/* end diag lines only if no horz,vert */
	if ((tl) && (!ml) && (!tc))
	    v_list[col].left = end_line(v_list[col].left, 1);
	if ((tr) && (!mr) && (!tc))
	    v_list[col].right = end_line(v_list[col].right, 1);

	if (mr)			/* start horz. and vert */
	    h_ptr = start_line(1);
	if (bc)
	    v_list[col].center = start_line(1);

	/* start diag if no horz,vert */
	if ((br) && (!mr) && (!bc))
	    v_list[col + 1].left = start_line(1);
	if ((bl) && (!ml) && (!bc))
	    v_list[col - 1].right = start_line(1);
	break;
    case 6:
	/* the same as case 5 */
	G_debug(1, "Crowded cell %xH (%d,%d), continuing", count, row, col);

	if (ml)			/* end horz. and vert lines */
	    h_ptr = end_line(h_ptr, 1);

	if (tc)
	    v_list[col].center = end_line(v_list[col].center, 1);

	/* end diag lines only if no horz,vert */
	if ((tl) && (!ml) && (!tc))
	    v_list[col].left = end_line(v_list[col].left, 1);
	if ((tr) && (!mr) && (!tc))
	    v_list[col].right = end_line(v_list[col].right, 1);

	if (mr)			/* start horz. and vert */
	    h_ptr = start_line(1);
	if (bc)
	    v_list[col].center = start_line(1);

	/* start diag if no horz,vert */
	if ((br) && (!mr) && (!bc))
	    v_list[col + 1].left = start_line(1);
	if ((bl) && (!ml) && (!bc))
	    v_list[col - 1].right = start_line(1);
	break;
    default:
	G_message(_("Crowded cell at (%f, %f): row %d, col %d, count %d"),
		  Rast_col_to_easting((double)col - .5, &cell_head),
		  Rast_row_to_northing((double)row + .5, &cell_head),
		  row, col - 1, count);
	G_fatal_error(_("Raster map is not thinned properly.\nPlease run r.thin."));
    }				/* switch count */

    return 0;
}
Esempio n. 15
0
 std::string status_line() const
 {
     return start_line();
 }
Esempio n. 16
0
int main(int argc, char **argv) {
  state.line_num = -1;

  int c;
  while ((c = getopt(argc, argv, "o:")) != -1) {
    switch (c) {
      case 'o':
        if (output_path != NULL) {
          error(ERROR_GENERAL, "An output path was already selected.");
        }
        output_path = optarg;
        trace(TRACE_GENERAL, "Loading an output path of %s", output_path);
        break;
    }
  }

  if (output_path == NULL) {
    error(ERROR_GENERAL, "An output path must be provided for the generated bindings");
  }

  state.line_num = 0;

  while (start_line()) {

    // identify line type
    if (state.token != NULL) {
      // we have input
      if (strcmp(state.token, keyword_comment) == 0) {
        while (next_token()) {}
        // nothing to do here, jump to the next line
      } else if (strcmp(state.token, keyword_include) == 0) {
        handle_header();
      } else if (strcmp (state.token, keyword_userdata) == 0){
        handle_userdata();
      } else if (strcmp (state.token, keyword_singleton) == 0){
        handle_singleton();
      } else {
        error(ERROR_UNKNOWN_KEYWORD, "Expected a keyword, got: %s", state.token);
      }

      if (next_token()) {
        error(ERROR_UNKNOWN_KEYWORD, "Extra token provided: %s", state.token);
      }
    }
  }

  state.line_num = -1;

  char *file_name = (char *)allocate(strlen(output_path) + 5);
  sprintf(file_name, "%s.cpp", output_path);
  source = fopen(file_name, "w");
  if (source == NULL) {
    error(ERROR_GENERAL, "Unable to open the output source file: %s", file_name);
  }

  fprintf(source, "// auto generated bindings, don't manually edit\n");
  
  trace(TRACE_GENERAL, "Sanity checking parsed input");

  sanity_check_userdata();

  fprintf(source, "#include \"lua_generated_bindings.h\"\n");

  trace(TRACE_GENERAL, "Starting emission");

  emit_headers(source);

  fprintf(source, "\n\n");

  emit_userdata_allocators();

  emit_userdata_checkers();

  emit_userdata_fields();

  emit_userdata_methods();

  emit_userdata_metatables();

  emit_singleton_methods();

  emit_singleton_metatables();

  emit_loaders();

  emit_sandbox();

  fclose(source);
  source = NULL;

  sprintf(file_name, "%s.h", output_path);
  header = fopen(file_name, "w");
  if (header == NULL) {
    error(ERROR_GENERAL, "Unable to open the output header file: %s", file_name);
  }
  free(file_name);
  fprintf(header, "#pragma once\n");
  fprintf(header, "// auto generated bindings, don't manually edit\n");
  emit_headers(header);
  fprintf(header, "#include \"lua/src/lua.hpp\"\n");
  fprintf(header, "#include <new>\n\n");

  emit_userdata_declarations();

  fprintf(header, "void load_generated_bindings(lua_State *L);\n");
  fprintf(header, "void load_generated_sandbox(lua_State *L);\n");

  fclose(header);
  header = NULL;

  return 0;
}