Пример #1
0
//android bionic glibc
int main()
{
	char data[1024];
	my_strcpy(data, "hehe");
	printf("%s\n", data);
	my_strcat(data, "来自中国1024");
	printf("%s\n", data);
	char hehe[1024];
	my_memset(hehe, 0, sizeof(hehe));
	my_memccpy(hehe, data, '1', my_strlen(data));
	printf("%s\n", hehe);
	printf("%d\n", my_strlen(hehe));

	char s[] = "-abc-=-def";
	char *x = my_strtok(s, "-");		// x = "abc"
	printf("%s\n", x);
	x = my_strtok(NULL, "-=");		// x = "def"
	printf("%s\n", x);
	x = my_strtok(NULL, "=");		// x = NULL
	printf("%s\n", x);

	printf("%f %d %ld\n", my_atof("1.245"), my_atoi("1024"), my_atol("152.63"));

	return 0;
}
Пример #2
0
int	config_alias(char *str, t_config *config)
{
  char	**tab;
  char	**spec;
  char	*base;

  base = DELIM_ALIAS_STRING;
  if ((tab = my_strtok(str, base, TOK_DELIM)) == NULL ||
      my_tablen(tab) != ALIAS_STRING_NUMBER)
    {
      (tab) ? my_free_tab(tab) : (tab = NULL);
      return (EXIT_FAILURE);
    }
  base = DELIM_SPACE_STRING;
  if ((spec = my_strtok(tab[0], base, TOK_DELIM)) == NULL ||
      my_tablen(spec) != ALIAS_STRING_NUMBER)
    {
      (tab) ? my_free_tab(tab) : (tab = NULL);
      (spec) ? my_free_tab(spec) : (spec = NULL);
      return (EXIT_FAILURE);
    }
  my_putalias(&config->alias, spec[1], tab[1]);
  (tab) ? my_free_tab(tab) : (tab = NULL);
  (spec) ? my_free_tab(spec) : (spec = NULL);
  return (EXIT_SUCCESS);
}
Пример #3
0
struct pathnode *
strtopath(char *pathstr)
{
	struct pathnode *root;
	struct pathnode *p;
	char *w;
	char *aux;	
	
	initpath(root);

	for (p = root; p != NULL; p = p->next) {
		my_strtok(pathstr,aux,w);
		p->next = NULL;
		while (w != NULL && !(strcmp(".",w) && strcmp("..",w)) ) {
			if (strcmp("..",w) == 0) {
				p = p->prev;
				if (p->next != NULL)
					freenode(p->next);
			}
			free(w);
			my_strtok(pathstr,aux,w);
		}
	
		if (w != NULL) {
			p->next = palloc();
			(p->next)->name = w;
			(p->next)->prev = p; 
		}		
	}
	
	return root;
}
Пример #4
0
static void load_subblock_array (int doall, FILE *fp_net,
           char *temp_buf, int num_subblocks, int bnum) {

/* Parses one subblock line and, if doall is 1, loads the proper   *
 * arrays.  Each subblock line is of the format:                   *
 * subblock: <name> <ipin0> <ipin1> .. <ipin[subblock_lut_size-1]> *
 *          <opin> <clockpin>                                      */
 
 int ipin, len, connect_to;
 char *ptr;

 ipin = 0;
 ptr = my_strtok(NULL,TOKENS,fp_net,temp_buf);

 if (ptr == NULL) {
    printf("Error in load_subblock_array on line %d of netlist file.\n",
             linenum);
    printf("Subblock name is missing.\nAborting.\n\n");
    exit (1);
 }
    
/* Load subblock name if this is the load pass. */
 if (doall == 1) {
    len = strlen (ptr);
    subblock_inf[bnum][num_subblocks-1].name = my_chunk_malloc ((len+1) *
             sizeof(char), &ch_subblock_head_ptr, &ch_subblock_bytes_avail,
             &ch_subblock_next_avail_mem);
    strcpy (subblock_inf[bnum][num_subblocks-1].name, ptr);
 }

 ptr = my_strtok(NULL,TOKENS,fp_net,temp_buf);

 while (ptr != NULL) {    /* For each subblock pin. */
    if (doall == 1) {
       connect_to = get_pin_number (ptr);
       if (ipin < subblock_lut_size) {      /* LUT input. */
          subblock_inf[bnum][num_subblocks-1].inputs[ipin] = connect_to;
       }
       else if (ipin == subblock_lut_size) {   /* LUT output. */
          subblock_inf[bnum][num_subblocks-1].output = connect_to;
       }
       else if (ipin == subblock_lut_size+1) {   /* Clock input. */
          subblock_inf[bnum][num_subblocks-1].clock = connect_to;
       }
    }
    ipin++;
    ptr = my_strtok(NULL,TOKENS,fp_net,temp_buf);
 }

 if (ipin != subblock_lut_size + 2) {
    printf("Error in load_subblock_array at line %d of netlist file.\n",
            linenum); 
    printf("Subblock had %d pins, expected %d.\n", ipin, 
            subblock_lut_size+2);
    printf("Aborting.\n\n");
    exit (1);
 }
}
Пример #5
0
static char *add_clb (int doall, FILE *fp_net, char *buf) {

/* Adds the clb (.clb) currently being parsed to the block array.  Adds *
 * its pins to the nets data structure by calling add_net.  If doall is *
 * zero this is a counting pass; if it is 1 this is the final (loading) *
 * pass.                                                                */

 char *ptr;
 int pin_index, iclass, inet;
 enum e_pin_type type;

 num_blocks++;
 parse_name_and_pinlist (doall, fp_net, buf);
 num_clbs++;

 if (doall) 
    block[num_blocks - 1].type = CLB;

 pin_index = -1;
 ptr = my_strtok(NULL,TOKENS,fp_net,buf);

 while (ptr != NULL) {
    pin_index++;
    if (pin_index >= pins_per_clb) {
       printf("Error in add_clb on line %d of netlist file.\n",linenum);
       printf("Too many pins on this clb.  Expected %d.\n",pins_per_clb);
       exit (1);
    }
    
    iclass = clb_pin_class[pin_index];
    type = class_inf[iclass].type;      /* DRIVER or RECEIVER */

    if (strcmp(ptr,"open") != 0) {     /* Pin is connected. */
       inet = add_net (ptr, type, num_blocks-1, pin_index, doall);

       if (doall)                      /* Loading pass only */
          block[num_blocks - 1].nets[pin_index] = inet; 
    }
    else {                             /* Pin is unconnected (open) */
       if (doall) 
          block[num_blocks - 1].nets[pin_index] = OPEN;
    }

    ptr = my_strtok(NULL,TOKENS,fp_net,buf);
 }

 if (pin_index != pins_per_clb - 1) {
    printf("Error in add_clb on line %d of netlist file.\n",linenum);
    printf("Expected %d pins on clb, got %d.\n", pins_per_clb, pin_index + 1);
    exit (1);
 }

 ptr = parse_subblocks (doall, fp_net, buf, num_blocks-1);
 return (ptr);
}
Пример #6
0
int main()
{
	char * str = "- This, a sample string.";
	char *del = " ,.-";
	char *s = my_strtok(str, del);
	while(s) {
		printf("%s\n", s);
		s = my_strtok(NULL, del);
	}
	return 0;
}
int main(void)
{
	char str[] = "root::::x::0:root:/root:/bin/bash";
	char *token;

	token = my_strtok(str, ":");
	printf("token:%s\n", token);

	while((token = my_strtok(NULL, ":")))
		printf("token:%s\n", token);
	return 0;
}
void		*server_client_receive_plage(void *arg)
{
  int		i;
  int		x;
  char		**tab;
  char		*buffer;
  t_normal_info	*normal_info;

  i = 3;
  buffer = (char *)arg;
  normal_info = (t_normal_info *)global_thread->info.arg;
  if ((tab = my_strtok(buffer, "-", 0)) == NULL)
    return (NULL);
  x = my_getnbr(tab[0]);
   while (tab[i])
    {
      if ((server_client_receive_plage_x(tab[i], x, i - 3)) == EXIT_FAILURE)
	return (NULL);
      i++;
    }
   if (normal_info->mute == 0)
     {
       pthread_mutex_lock(&mutex_server);
       mlx_put_image_to_window(global_thread->window->mlx_ptr,	\
			       global_thread->window->win_ptr,	      \
			       global_thread->thread[0].thread_image->ptr, \
			       0, 0);
       pthread_mutex_unlock(&mutex_server);
     }
  return (NULL);
}
Пример #9
0
void rev_text_1(char *text)
{
    char *pos = NULL;
    char *next = NULL;
    struct list *tmp = NULL;
    struct list *rev = NULL;

    pos = text;
    do {
        tmp = calloc(1, sizeof(struct list));
        next = my_strtok(pos, ' ');
        tmp->word = pos;
        tmp->word_len = (unsigned) (next - pos) -1;
        tmp->next = rev;
        rev = tmp;
        pos = next;
    } while( pos != NULL );

    while( rev != '\0' ) {
        print_word( rev->word, 0, rev->word_len);
        tmp = rev;
        rev = rev->next;
        free(tmp);
    }
    print_word("\n", 0, 1);
}
Пример #10
0
int	get_coord(char *path, t_vertice **v, t_vertice_n **vn, t_face **f)
{
  int	fd;
  char	*buff;
  char	**sep;

  fd = open(path, O_RDONLY);
  if (fd == -1)
    exit(1);
  while ((buff = get_next_line(fd)))
    {
      sep = my_strtok(buff, " ", TOK_DELIM);
      if (sep && size_tab(sep) == 4)
	{
	  if (!my_strcmp("v", sep[0]))
	    add_vertice(v, atof(sep[1]), atof(sep[2]),
			atof(sep[3]));
	  else if (!my_strcmp("f", sep[0]))
	    add_face(f, sep[1], sep[2], sep[3]);
	  else if (!my_strcmp("vn", sep[0]))
	    add_vertice_norme(vn, atof(sep[1]), atof(sep[2]),
			      atof(sep[3]));
	}
    }
  close(fd);
 return (1);
}
Пример #11
0
t_xtree	*xml_find_in_tree(t_xtree *tree, char *find)
{
  char	**tab;
  int	i;
  t_xtree	*tmp;
  t_xtree	*tmp2;

  tab = my_strtok(find, "/ \n\t", TOK_DELIM);
  i = 0;
  tmp = NULL;
  while (tree && tab && tab[i])
    {
      if (tmp == NULL)
	tmp = tree;
      tmp2 = tmp;
      tmp = NULL;
      while (tmp2 && !tmp)
	{
	  if (!tab[i + 1] && my_strcmp(tmp2->name, tab[i]) == 0)
	    {
	      my_free_tab(tab);
	      return (tmp2);
	    }
	  tmp = xml_find_one_node(tmp2->sun, tab[i]);
	  if (tmp == NULL)
	    tmp2 = tmp2->next;
	}
      i++;
    }
  my_free_tab(tab);
  return (tmp);
}
Пример #12
0
t_glob		*parser_main()
{
  int		i;
  int		rtrn;
  char		delim[2];
  t_glob	*global;
  char		**tab;
  char		buff[SIZE_BUFFER];

  i = 0;
  if ((global = malloc(sizeof(*global))) == NULL)
    return (NULL);
  delim[0] = DELIM_BUFFER;
  delim[1] = '\0';
  if ((rtrn = read(0, buff, SIZE_BUFFER)) == -1)
    return (NULL);
  buff[rtrn] = '\0';
  if (my_strlen(buff) <= 1)
    return (NULL);
  (buff[rtrn - 1] == '\n') ? my_printf("%s", buff) : my_printf("%s\n", buff);
  if ((tab = my_strtok(buff, delim, TOK_DELIM)) == NULL)
    return (NULL);
  while (tab[i][0] == '#' && tab[i][1] != '#')
    i++;
  global->nb_ant = my_getnbr(tab[i]);
  return (((parser_main_room_link(global, tab, i)) == EXIT_FAILURE) ? \
	  (NULL) : (global));
}
Пример #13
0
static void
aff_rch(char **tab, t_global *global, t_line *line)
{
  char	**tmp;
  int	i;

  i = -1;
  termcap_action(1, CURSER_OFF, NULL, 0);
  termcap_action((edit_listlen(line) - edit_cp(line)),
		 RIGHT_MOVE_STRING, global, 1);
  termcap_action(1, DOWN_MOVE_STRING, NULL, 0);
  termcap_action(global->dom[X], LEFT_MOVE_STRING, NULL, 0);
  while (tab && tab[++i])
    {
      termcap_action(1, UNDERLINE_ON, NULL, 0);
      if ((tmp = my_strtok(tab[i], "/", TOK_DELIM)) != NULL)
	{
	  printf("%s\n", tmp[my_tablen(tmp) - 1]);
	  my_free_tab(tmp);
	}
      termcap_action(1, UNDERLINE_OFF, NULL, 0);
    }
  my_putstr(global->prompt);
  edit_global(global, 1);
  termcap_action(edit_cp(line), RIGHT_MOVE_STRING, global, 1);
  termcap_action(1, CURSER_ON, NULL, 0);
}
void		*server_client_receive_plage(void *arg)
{
  int		i;
  int		x;
  char		**tab;
  char		*buffer;
  t_normal_info	*normal_info;

  i = 3;
  buffer = (char *)arg;
  normal_info = (t_normal_info *)global_thread->info.arg;
  if ((tab = my_strtok(buffer, "-", 0)) == NULL)
    return (NULL);
  x = my_getnbr(tab[0]);
  if (x > global_thread->window->x_win || x < 0)
    return (NULL);
  while (tab[i])
    {
      if ((server_client_receive_plage_x(tab[i], x, i - 3)) == EXIT_FAILURE)
	return (NULL);
      i++;
    }
  server_client_receive_global(normal_info);
  return (NULL);
}
Пример #15
0
static t_line
*edit_autocomplete(char *str, char *path, t_global *global, t_line *line)
{
  t_line	*complete;
  char	**tab;
  int	len;

  complete = NULL;
  if ((tab = my_strtok(str, " \t", TOK_DELIM)) == NULL)
    return (NULL);
  len = my_tablen(tab);
  if (len == 1)
    {
      if (tab[0][my_strlen(tab[0]) - 1] == '*')
	complete = NULL;
      else
	complete = edit_convertstr(&tab[0][my_strlen(path) - 1]);
    }
  else
    {
      complete = edit_recurrence(tab, my_strlen(path) - 1);
      aff_rch(tab, global, line);
    }
  my_free_tab(tab);
  return (complete);
}
int	server_client_receive_analize(t_trame **list_trame, \
				      char *buffer)
{
  int	i;
  char	**tab;

  i = 0;
  if ((tab = my_strtok(buffer, " ", 0)) == NULL)
    return (EXIT_FAILURE);
  while (tab[i])
    {
      if (is_number(tab[i]) == 1)
	{
	  if ((server_client_add_trame(list_trame, my_getnbr(tab[i]),
				       tab[i + 1])) == EXIT_FAILURE)
	    return (EXIT_FAILURE);
	  i++;
	}
      else
	(*list_trame)->buffer = my_strconcat((*list_trame)->buffer, tab[i]);
      if (tab[i] != NULL)
	i++;
    }
  return (EXIT_SUCCESS);
}
Пример #17
0
int	config_prompt(char *str, t_config *config)
{
  char	**tab;
  char	*base;
  char	*prompt;

  base = DELIM_PROMPT_STRING;
  if (str == NULL || config == NULL)
    return (EXIT_FAILURE);
  prompt = NULL;
  if ((tab = my_strtok(str, base, TOK_DELIM)) == NULL ||
      my_tablen(tab) != PROMPT_STRING_NUMBER ||
      (prompt = xmalloc(sizeof(*prompt) * (my_strlen(tab[1]) + 1))) == NULL ||
      fill_prompt(prompt, tab[1]) == EXIT_FAILURE)
    {
      (tab) ? my_free_tab(tab) : (tab = NULL);
      (prompt) ? free(prompt) : (prompt = NULL);
      return (EXIT_FAILURE);
    }
  if (config->prompt != NULL)
    free(config->prompt);
  my_free_tab(tab);
  config->prompt = prompt;
  return (EXIT_SUCCESS);
}
Пример #18
0
static void
dum_parse(char *buf)
{

/* Continue parsing to the end of this (possibly continued) line. */

    while(my_strtok(NULL, TOKENS, blif, buf) != NULL)
		;
}
Пример #19
0
// parse a tile file into memory
// (this function is ugly due to the error checking)
static float *malloc_tile_data(char *tile_filename)
{
	int fsize;
	char *f = malloc_file_contents(tile_filename, &fsize);
	if (!f)
		return NULL;
	int finc, ncols, nrows, xllcorner, yllcorner;
	double cellsize, nodatavalue;
	cellsize=nodatavalue=finc=ncols=nrows=xllcorner=yllcorner=-42;

	int r = sscanf(f, "ncols %d\nnrows %d\nxllcorner %d\nyllcorner %d\n"
			"cellsize %lf\nNODATA_value %lf\n%n", &ncols, &nrows,
			&xllcorner, &yllcorner, &cellsize, &nodatavalue, &finc);

	if (r != 6) {
		fprintf(stderr, "strange tile file format on \"%s\" (%d)\n",
				tile_filename, r);
		exit(2);
	}
	if (ncols != 6000 || nrows != 6000) {
		fprintf(stderr,"ncols,nrows = %d,%d != 6000,6000",ncols,nrows);
		exit(2);
	}
	int n = 6000*6000;
	float *t = malloc(n*sizeof*t);
	if (!t) {
		fprintf(stderr, "out of memory!\n");
		exit(2);
	}
	int cx = 0;
	char *fp = f + finc;
	char *tok = my_strtok(fp);
	while (tok && cx < n) {
		int x = my_atoi(tok);
		t[cx++] = x > -1000 ? x : NAN;
		tok = my_strtok(NULL);
	}
	free(f);
	if (cx != n) {
		fprintf(stderr, "could only read %d numbers from file \n", cx);
		exit(2);
	}
	return t;
}
Пример #20
0
static void add_latch(int doall, int lut_size)
{
    /* Adds the flipflop (.latch) currently being parsed to the block array.  *
     * Adds its pins to the nets data structure by calling add_net.  If doall *
     * is zero this is a counting pass; if it is 1 this is the final          *
     * (loading) pass.  Blif format for a latch is:                           *
     * .latch <input> <output> <type (latch on)> <control (clock)> <init_val> *
     * The latch pins are in .nets 0 to 2 in the order: Q D CLOCK.            */
    char* ptr, buf[BUFSIZE], saved_names[6][BUFSIZE];
    int i, len;
    num_blocks++;

    /* Count # parameters, making sure we don't go over 6 (avoids memory corr.) */
    /* Note that we can't rely on the tokens being around unless we copy them.  */

    for (i = 0; i < 6; i++) {
        ptr = my_strtok(NULL, TOKENS, blif, buf);

        if (ptr == NULL) {
            break;
        }

        strcpy(saved_names[i], ptr);
    }

    if (i != 5) {
        fprintf(stderr, "Error:  .latch does not have 5 parameters.\n"
                "check the netlist, line %d.\n", linenum);
        exit(1);
    }

    if (!doall) {   /* If only a counting pass ... */
        add_net(saved_names[0], RECEIVER, num_blocks - 1, doall); /* D */
        add_net(saved_names[1], DRIVER, num_blocks - 1, doall); /* Q */
        add_net(saved_names[3], RECEIVER, num_blocks - 1, doall); /* Clock */
        return;
    }

    block[num_blocks - 1].num_nets = 3;
    block[num_blocks - 1].type = LATCH;
    block[num_blocks - 1].nets[0] = add_net(saved_names[1], DRIVER, num_blocks - 1,
                                            doall);                                                        /* Q */
    block[num_blocks - 1].nets[1] = add_net(saved_names[0], RECEIVER, num_blocks - 1,
                                            doall);                                                        /* D */
    block[num_blocks - 1].nets[lut_size + 1] = add_net(saved_names[3], RECEIVER,
                                                       num_blocks - 1, doall);                                        /* Clock */

    for (i = 2; i < lut_size + 1; i++) {
        block[num_blocks - 1].nets[i] = OPEN;
    }

    len = strlen(saved_names[1]);
    block[num_blocks - 1].name = (char*) my_malloc((len + 1) * sizeof(char));
    strcpy(block[num_blocks - 1].name, saved_names[1]);
    num_latches++;
}
Пример #21
0
int parse_cmdline_to_arg_array(char* argv[MAX_ARGS], char* cmdline)
{
   char seps[] = " \t\n";
   char* token;
   int argc = 0;
   char* lasts;

   token = my_strtok(cmdline, seps, &lasts);
   while ((token != NULL) && (argc < MAX_ARGS))
   {
      if ((argv[argc] = malloc(strlen(token)+1)) == NULL)
      {
         error("internal error - out of memory");
      }
      strcpy(argv[argc++],token);
      token = my_strtok(NULL,seps,&lasts);
   }
   if (argc >= MAX_ARGS)
      error("too many arguments on commandline\n%s",cmdline);
   return argc;
}
Пример #22
0
static void io_line(int in_or_out, int doall)
{
    /* Adds an input or output block to the block data structures.           *
     * in_or_out:  DRIVER for input, RECEIVER for output.                    *
     * doall:  1 for final pass when structures are loaded.  0 for           *
     * first pass when hash table is built and pins, nets, etc. are counted. */
    char* ptr;
    char buf2[BUFSIZE];
    int nindex, len;

    while (1) {
        ptr = my_strtok(NULL, TOKENS, blif, buf2);

        if (ptr == NULL) {
            return;
        }

        num_blocks++;
        nindex = add_net(ptr, in_or_out, num_blocks - 1, doall);

        /* zero offset indexing */
        if (!doall) {
            continue;    /* Just counting things when doall == 0 */
        }

        len = strlen(ptr);

        if (in_or_out == RECEIVER) {
            /* output pads need out: prefix
                                             to make names unique from LUTs */
            block[num_blocks - 1].name = (char*) my_malloc((len + 1 + 4) *
                                                           sizeof(char));           /* Space for out: at start */
            strcpy(block[num_blocks - 1].name, "out:");
            strcat(block[num_blocks - 1].name, ptr);
        } else {
            block[num_blocks - 1].name = (char*) my_malloc((len + 1) *
                                                           sizeof(char));
            strcpy(block[num_blocks - 1].name, ptr);
        }

        block[num_blocks - 1].num_nets = 1;
        block[num_blocks - 1].nets[0] = nindex; /* Put in driver position for */
        /*  OUTPAD, since it has only one pin (even though it's a receiver */

        if (in_or_out == DRIVER) {             /* processing .inputs line */
            num_p_inputs++;
            block[num_blocks - 1].type = INPAD;
        } else {                               /* processing .outputs line */
            num_p_outputs++;
            block[num_blocks - 1].type = OUTPAD;
        }
    }
}
Пример #23
0
static void add_global (int doall, FILE *fp_net, char *buf) {

/* Doall is 0 for the first (counting) pass and 1 for the second           *
 * (loading) pass.  fp_net is a pointer to the netlist file.  This         *
 * routine sets the proper entry(ies) in is_global to TRUE during the      *
 * loading pass.  The routine does nothing during the counting pass. If    *
 * is_global = TRUE for a net, it will not be considered in the placement  *
 * cost function, nor will it be routed.  This is useful for global        *
 * signals like clocks that generally have dedicated routing in FPGAs.     */

 char *ptr;
 struct s_hash *h_ptr;
 int nindex;

/* Do nothing if this is the counting pass. */

 if (doall == 0) 
    return; 

 ptr = my_strtok(NULL,TOKENS,fp_net,buf);

 while (ptr != NULL) {     /* For each .global signal */
    num_globals++;

    h_ptr = get_hash_entry (hash_table, ptr);

    if (h_ptr == NULL) {        /* Net was not found in list! */
       printf("Error in add_global on netlist file line %d.\n",linenum);
       printf("Global signal %s does not exist.\n",ptr);
       exit(1);
    }
   
    nindex = h_ptr->index;
    is_global[nindex] = TRUE;    /* Flagged as global net */

    ptr = my_strtok(NULL,TOKENS,fp_net,buf);
 }
}
Пример #24
0
static void add_lut(int doall, int lut_size)
{
    /* Adds a LUT (.names) currently being parsed to the block array.  Adds *
     * its pins to the nets data structure by calling add_net.  If doall is *
     * zero this is a counting pass; if it is 1 this is the final (loading) *
     * pass.                                                                */
    char* ptr, saved_names[MAXLUT + 2][BUFSIZE], buf[BUFSIZE];
    int i, j, len;
    num_blocks++;
    /* Count # nets connecting */
    i = 0;

    while ((ptr = my_strtok(NULL, TOKENS, blif, buf)) != NULL)  {
        if (i == MAXLUT + 1) {
            fprintf(stderr, "Error:  LUT #%d has %d inputs.  Increase MAXLUT or"
                    " check the netlist, line %d.\n", num_blocks - 1, i - 1, linenum);
            exit(1);
        }

        strcpy(saved_names[i], ptr);
        i++;
    }

    if (!doall) {          /* Counting pass only ... */
        for (j = 0; j < i; j++) {
            add_net(saved_names[j], RECEIVER, num_blocks - 1, doall);
        }

        return;
    }

    block[num_blocks - 1].num_nets = i;
    block[num_blocks - 1].type = LUT;

    for (i = 0; i < block[num_blocks - 1].num_nets - 1; i++) /* Do inputs */
        block[num_blocks - 1].nets[i + 1] = add_net(saved_names[i], RECEIVER,
                                                    num_blocks - 1, doall);

    block[num_blocks - 1].nets[0] = add_net(
                                        saved_names[block[num_blocks - 1].num_nets - 1], DRIVER, num_blocks - 1, doall);

    for (i = block[num_blocks - 1].num_nets; i < lut_size + 2; i++) {
        block[num_blocks - 1].nets[i] = OPEN;
    }

    len = strlen(saved_names[block[num_blocks - 1].num_nets - 1]);
    block[num_blocks - 1].name = (char*) my_malloc((len + 1) * sizeof(char));
    strcpy(block[num_blocks - 1].name, saved_names[block[num_blocks - 1].num_nets - 1]);
    num_luts++;
}
int		server_client_receive_plage_x(char *buffer,
					      int x, int y)
{
  char		**tab;
  t_color	color;

  if ((tab = my_strtok(buffer, "/", 0)) == NULL)
    return (EXIT_FAILURE);
  color.red = my_getnbr(tab[0]);
  color.green = my_getnbr(tab[1]);
  color.blue = my_getnbr(tab[2]);
  mlx_ppti(global_thread->thread[0].thread_image, &color, x, y);
  return (EXIT_SUCCESS);
}
Пример #26
0
/* processes a single directive */
int xsddefault_grab_config_directives(char *input) {
	char *temp_ptr = NULL;
	char *varname = NULL;
	char *varvalue = NULL;

	/* get the variable name */
	if((temp_ptr = my_strtok(input, "=")) == NULL)
		return ERROR;
	if((varname = (char *)strdup(temp_ptr)) == NULL)
		return ERROR;

	/* get the variable value */
	if((temp_ptr = my_strtok(NULL, "\n")) == NULL) {
		my_free(varname);
		return ERROR;
		}
	if((varvalue = (char *)strdup(temp_ptr)) == NULL) {
		my_free(varname);
		return ERROR;
		}

	/* status log definition */
	if(!strcmp(varname, "status_file") || !strcmp(varname, "xsddefault_status_log")) {
		xsddefault_status_log = nspath_absolute(temp_ptr, config_file_dir);
		}

	/* temp file definition */
	else if(!strcmp(varname, "temp_file")) {
		xsddefault_temp_file = nspath_absolute(temp_ptr, config_file_dir);
		}

	/* free memory */
	my_free(varname);
	my_free(varvalue);

	return OK;
	}
Пример #27
0
int	exec_ins(t_dtf *map, char *str)
{
  char	**tab;

  if (get_crtreturn(NULL))
    return (0);
  if (map == NULL || str == NULL || (tab = my_strtok(str, UNITOK)) == NULL ||
      (tab[0] == NULL))
    return (dbgerr("Error: exec_ins: NULL or invalid parameter"));
  if (tab[1] == NULL)
    return (exec_simpleins(map, tab[0]));
  else
    return (exec_complexins(map, tab));
  return (1);
}
Пример #28
0
static char *parse_subblocks (int doall, FILE *fp_net, char *buf,
               int bnum) {

/* Loads the subblock arrays with the proper values. */

 char temp_buf[BUFSIZE], *ptr;
 int num_subblocks;

 num_subblocks = 0;

 while (1) {
    ptr = my_fgets (temp_buf, BUFSIZE, fp_net);
    if (ptr == NULL)   
       break;          /* EOF */

  /* Save line in case it's not a sublock */
    strcpy (buf, temp_buf);

    ptr = my_strtok(temp_buf,TOKENS,fp_net,temp_buf);
    if (ptr == NULL) 
       continue;       /* Blank or comment line.  Skip. */

    if (strcmp("subblock:", ptr) == 0) {
       num_subblocks++; 
       load_subblock_array (doall, fp_net, temp_buf, num_subblocks,
               bnum);
    }
    else {
       break;  /* Subblock list has ended.  Buf contains next line. */
    }
 }   /* End infinite while */

 if (num_subblocks < 1 || num_subblocks > max_subblocks_per_block) {
    printf("Error in parse_subblocks on line %d of netlist file.\n",
         linenum);
    printf("Block #%d has %d subblocks.  Out of range.\n",
         bnum, num_subblocks);
    printf("Aborting.\n\n");
    exit (1);
 }

 if (doall == 0)
    set_subblock_count (bnum, num_subblocks);
 else 
    assert (num_subblocks == num_subblocks_per_block[bnum]);

 return (ptr);
}
Пример #29
0
int	xml_check_presence(char *s, char *check, char *base)
{
  char	**tab;
  int	i;

  tab = my_strtok(s, base, TOK_BASE);
  if (!tab)
    return (EXIT_FAILURE);
  i = 0;
  while (tab[i])
    {
      if (my_strcmp(check, tab[i]) == 0)
	return (EXIT_SUCCESS);
      i++;
    }
  return (EXIT_FAILURE);
}
Пример #30
0
int	createpipe(t_lid *data)
{
  t_pip	*pipe;
  char	**tab;
  char	*line;

  if (data == NULL || (line = get_last_line(data->file)) == NULL)
    return (FALSE);
  if (line[0] == '#')
    return (TRUE);
  if ((tab = my_strtok(line, "-")) == NULL || tab_length(tab) != 2 ||
      (pipe = create_pipe(tab[0], tab[1])) == NULL ||
      data->existPipe(data, pipe))
    return (FALSE);
  data->addPipe(data, pipe);
  gbgc_free(NULL, line);
  free_strtab(tab);
  return (TRUE);
}