Esempio n. 1
0
/* ------------------------------------------------------------------------
@NAME       : bt_free_name()
@INPUT      : name
@OUTPUT     : 
@RETURNS    : 
@DESCRIPTION: Frees up any memory allocated for a bt_name structure
              (namely, the `tokens' field [a bt_stringlist structure,
              this freed with bt_free_list()] and the structure itself.)
@CALLS      : bt_free_list()
@CALLERS    : anyone (exported)
@CREATED    : 1997/11/14, GPW
@MODIFIED   : 
-------------------------------------------------------------------------- */
void
bt_free_name (bt_name * name)
{
   DBG_ACTION (2, printf ("bt_free_name(): freeing name %p "
                          "(%d tokens, string=%p (%s), last[0]=%s)\n",
                          name, 
                          name->tokens->num_items,
                          name->tokens->string,
                          name->tokens->string,
                          name->parts[BTN_LAST][0]));
   bt_free_list (name->tokens);
   free (name);
   DBG_ACTION (2, printf ("bt_free_name(): done, everything freed\n"));
}
Esempio n. 2
0
int
main (void)
{
   char   line[1024];
   int    line_num;
   int    len;
   bt_stringlist * names;
   int    i;

   while (! feof (stdin))
   {
      if (fgets (line, 1024, stdin) == NULL)
         break;

      len = strlen (line);
      if (line[len-1] == '\n') line[len-1] = '\0';
      line_num++;

      names = bt_split_list (line, "and", "stdin", line_num, "name");
      if (names == NULL)
         printf ("empty or invalid string\n");
      else
      {
         if (names->num_items > 1)
            printf ("%d names in string\n", names->num_items);

         for (i = 0; i < names->num_items; i++)
         {
            if (names->items[i])
               process_name (names->items[i], line_num, i+1);
         }
         bt_free_list (names);
      }
   }
   return 0;
}