Example #1
0
PPerson rfc822_parse_adrlist( PPerson Top, LPCSTR s )
{
  LPCSTR begin;
  LPCSTR ps;
  char comment[128], phrase[128];
  size_t phraselen = 0, commentlen = 0;

  PPerson Cur;
  PPerson Last = Top;

  while ( Last && Last->m_Next ) Last = Last->m_Next;

  SKIPWS( s );

  begin = s;
  while ( *s )
  {
    if ( *s == ',' )
    {
      if ( phraselen )
      {
        terminate_buffer( phrase, phraselen );
        add_addrspec( &Top, &Last, phrase, comment, &commentlen, sizeof( comment ) - 1 );
      }
      else if ( commentlen && Last && Last->Name.IsEmpty() )
      {
        terminate_buffer( comment, commentlen );
        Last->Name = comment;
      }

#ifdef EXACT_ADDRESS
      if ( Last && Last->val == NULL )
        Last->val = mutt_substrdup( begin, s );
#endif
      commentlen = 0;
      phraselen  = 0;
      s ++;
      begin = s;
      SKIPWS( begin );
    }
    else if ( *s == '(' )
    {
      if ( commentlen && commentlen < sizeof( comment ) - 1 )
        comment[ commentlen++ ] = ' ';
      if ( ( ps = next_token( s, comment, &commentlen, sizeof (comment) - 1)) == NULL )
      {
        delete Top;
        Top = NULL;
        return NULL;
      }
      s = ps;
    }
    else if ( *s == ':' )
    {
      terminate_buffer( phrase, phraselen );
      Cur = create CPerson;
      Cur->Addr = phrase;
      //Cur->group = 1;

      if ( Last )
        Last->m_Next = Cur;
      else
        Top = Cur;

      Last = Cur;

#ifdef EXACT_ADDRESS
      last->val = mutt_substrdup (begin, s);
#endif

      phraselen  = 0;
      commentlen = 0;
      s ++;
      begin = s;
      SKIPWS( begin );
    }
    else if ( *s == ';' )
    {
      if ( phraselen )
      {
        terminate_buffer (phrase, phraselen);
        add_addrspec( &Top, &Last, phrase, comment, &commentlen, sizeof( comment ) - 1 );
      }
      else if (commentlen && Last && Last->Name.IsEmpty() )
      {
        terminate_buffer (comment, commentlen);
        Last->Name = comment;
      }
#ifdef EXACT_ADDRESS
      if (last && !last->val)
        last->val = mutt_substrdup (begin, s);
#endif

      /* add group terminator */
      Cur = create CPerson;
      if ( Last )
      {
        Last->m_Next = Cur;
        Last = Cur;
      }

      phraselen  = 0;
      commentlen = 0;
      s ++;
      begin = s;
      SKIPWS( begin );
    }
    else if ( *s == '<' )
    {
      terminate_buffer( phrase, phraselen );
      Cur = create CPerson;
      if ( phraselen )
      {
        FarSF::Unquote( phrase );
        Cur->Name = phrase;
      }
      if ( ( ps = parse_route_addr( s + 1, comment, &commentlen, sizeof( comment ) - 1, Cur ) ) == NULL )
      {
        delete Top;
        delete Cur;
        Top = NULL;
        Cur = NULL;
        return NULL;
      }

      if ( Last )
        Last->m_Next = Cur;
      else
        Top = Cur;
      Last = Cur;

      phraselen  = 0;
      commentlen = 0;
      s = ps;
    }
    else
    {
      if ( phraselen && phraselen < sizeof( phrase ) - 1 && *s != '.' )
        phrase[phraselen++] = ' ';
      if ( ( ps = next_token( s, phrase, &phraselen, sizeof( phrase ) - 1 ) ) == NULL )
      {
        delete Top;
        Top = NULL;
        return NULL;
      }
      s = ps;
    }
    SKIPWS (s);
  }

  if (phraselen)
  {
    terminate_buffer (phrase, phraselen);
    terminate_buffer (comment, commentlen);
    add_addrspec( &Top, &Last, phrase, comment, &commentlen, sizeof( comment ) - 1 );
  }
  else if ( commentlen && Last && Last->Name.IsEmpty() )
  {
    terminate_buffer( comment, commentlen );
    Last->Name = comment;
  }
#ifdef EXACT_ADDRESS
  if ( Last )
    Last->val = mutt_substrdup( begin, s );
#endif

  return Top;
}
Example #2
0
ADDRESS *rfc822_parse_adrlist (ADDRESS *top, const char *s)
{
  int ws_pending, nl;
#ifdef EXACT_ADDRESS
  const char *begin;
#endif
  const char *ps;
  char comment[LONG_STRING], phrase[LONG_STRING];
  size_t phraselen = 0, commentlen = 0;
  ADDRESS *cur, *last = NULL;
  
  RFC822Error = 0;

  last = top;
  while (last && last->next)
    last = last->next;

  ws_pending = is_email_wsp (*s);
  if ((nl = mutt_strlen (s)))
    nl = s[nl - 1] == '\n';
  
  s = skip_email_wsp(s);
#ifdef EXACT_ADDRESS
  begin = s;
#endif
  while (*s)
  {
    if (*s == ',')
    {
      if (phraselen)
      {
	terminate_buffer (phrase, phraselen);
	add_addrspec (&top, &last, phrase, comment, &commentlen, sizeof (comment) - 1);
      }
      else if (commentlen && last && !last->personal)
      {
	terminate_buffer (comment, commentlen);
	last->personal = safe_strdup (comment);
      }

#ifdef EXACT_ADDRESS
      if (last && !last->val)
	last->val = mutt_substrdup (begin, s);
#endif
      commentlen = 0;
      phraselen = 0;
      s++;
#ifdef EXACT_ADDRESS
      begin = skip_email_wsp(s);
#endif
    }
    else if (*s == '(')
    {
      if (commentlen && commentlen < sizeof (comment) - 1)
	comment[commentlen++] = ' ';
      if ((ps = next_token (s, comment, &commentlen, sizeof (comment) - 1)) == NULL)
      {
	rfc822_free_address (&top);
	return NULL;
      }
      s = ps;
    }
    else if (*s == '"')
    {
      if (phraselen && phraselen < sizeof (phrase) - 1)
        phrase[phraselen++] = ' ';
      if ((ps = parse_quote (s + 1, phrase, &phraselen, sizeof (phrase) - 1)) == NULL)
      {
        rfc822_free_address (&top);
        return NULL;
      }
      s = ps;
    }
    else if (*s == ':')
    {
      cur = rfc822_new_address ();
      terminate_buffer (phrase, phraselen);
      cur->mailbox = safe_strdup (phrase);
      cur->group = 1;

      if (last)
	last->next = cur;
      else
	top = cur;
      last = cur;

#ifdef EXACT_ADDRESS
      last->val = mutt_substrdup (begin, s);
#endif

      phraselen = 0;
      commentlen = 0;
      s++;
#ifdef EXACT_ADDRESS
      begin = skip_email_wsp(s);
#endif
    }
    else if (*s == ';')
    {
      if (phraselen)
      {
	terminate_buffer (phrase, phraselen);
	add_addrspec (&top, &last, phrase, comment, &commentlen, sizeof (comment) - 1);
      }
      else if (commentlen && last && !last->personal)
      {
	terminate_buffer (comment, commentlen);
	last->personal = safe_strdup (comment);
      }
#ifdef EXACT_ADDRESS
      if (last && !last->val)
	last->val = mutt_substrdup (begin, s);
#endif

      /* add group terminator */
      cur = rfc822_new_address ();
      if (last)
      {
	last->next = cur;
	last = cur;
      }

      phraselen = 0;
      commentlen = 0;
      s++;
#ifdef EXACT_ADDRESS
      begin = skip_email_wsp(s);
#endif
    }
    else if (*s == '<')
    {
      terminate_buffer (phrase, phraselen);
      cur = rfc822_new_address ();
      if (phraselen)
	cur->personal = safe_strdup (phrase);
      if ((ps = parse_route_addr (s + 1, comment, &commentlen, sizeof (comment) - 1, cur)) == NULL)
      {
	rfc822_free_address (&top);
	rfc822_free_address (&cur);
	return NULL;
      }

      if (last)
	last->next = cur;
      else
	top = cur;
      last = cur;

      phraselen = 0;
      commentlen = 0;
      s = ps;
    }
    else
    {
      if (phraselen && phraselen < sizeof (phrase) - 1 && ws_pending)
	phrase[phraselen++] = ' ';
      if ((ps = next_token (s, phrase, &phraselen, sizeof (phrase) - 1)) == NULL)
      {
	rfc822_free_address (&top);
	return NULL;
      }
      s = ps;
    }
    ws_pending = is_email_wsp(*s);
    s = skip_email_wsp(s);
  }
  
  if (phraselen)
  {
    terminate_buffer (phrase, phraselen);
    terminate_buffer (comment, commentlen);
    add_addrspec (&top, &last, phrase, comment, &commentlen, sizeof (comment) - 1);
  }
  else if (commentlen && last && !last->personal)
  {
    terminate_buffer (comment, commentlen);
    last->personal = safe_strdup (comment);
  }
#ifdef EXACT_ADDRESS
  if (last)
    last->val = mutt_substrdup (begin, s - nl < begin ? begin : s - nl);
#endif

  return top;
}
Example #3
0
int main(int argc, char **argv)
{
    /* Must be called: ./main "Hello World" output_file.s */
    if (argc != 3) {
        printf("* Must supply a string to convert and an output file!\n");
        return EXIT_FAILURE;
    }

    char *str = argv[1];
    char *destination = argv[2];
    int len = strlen(str);

    /* Array of pointers to linked lists */
    linked_list_t **list_arr = malloc(sizeof(linked_list_t*) * NUM_TOTAL_CHARS);
    if (init_list_arr(list_arr)) {
        /* Couldn't initialise list_arr */
        printf("* Couldn't initialise the array of lists. Stopping.\n");
        return EXIT_FAILURE;
    }
    /* list_arr initialised and allocated on heap: now fill with morse data: */
    if (populate_list_arr(list_arr)) {
        /* Couldn't populate list_arr with alphabet morse data */
        printf("* Couldn't populate table with morse data. Stopping.\n");
        return EXIT_FAILURE;
    }

    output_buffer_t *buffer = malloc(sizeof(output_buffer_t));
    if (init_buffer(buffer, len)) {
        /* Error initialising the buffer */
        printf("* Couldn't initialise output buffer. Stopping.\n");
        return EXIT_FAILURE;
    }

    for (int i = 0; i < len; i++) {
        char c = str[i];

        if (isspace(c)) continue;

        int index = get_array_index(c);

        if (index == -1) {
            printf("* Encountered non-valid character. Stopping.\n");
            return EXIT_FAILURE;
        }

        linked_list_t *parts_list = list_arr[index];

        for (linked_list_elem_t *list_elem = parts_list->header->next;
             list_elem != NULL; list_elem = list_elem->next) {

            add_to_buffer(buffer, list_elem->type);

            if (list_elem->next != NULL)
                add_to_buffer(buffer, MORSE_END_OF_ELEM);
        }

        if (i + 1 < len && isspace(str[i + 1])) {
            /* Do stuff for end of word */
            add_to_buffer(buffer, MORSE_END_OF_WORD);

        } else {
            /* Do stuff for end of char */
            add_to_buffer(buffer, MORSE_END_OF_CHAR);
        }
    }

    if (!write_to_file(destination, buffer, str)) {
        print_raspberry();
        printf("* Successful. Find assembly file at: %s\n", destination);
    }

    terminate_buffer(buffer);
    terminate_list_arr(list_arr);

    return EXIT_SUCCESS;
}