#include "../constants.h"

int fetchsms (char *pdu, int sim)
{
  char answer[ANSWERSIZE];
  int position;
  int beginning;
  int end;
  int  foo,err;

  /* Input magically appears */
  answer[ANSWERSIZE-1] = EOS;

  /* Don't skip anything */
  position = 0;
  if (position==-1)
    return 0;
  beginning = position + NEEDLE_SZ + 1;

  /* Find (something)\r(something)\r, where each (something) is at
   * least MIN_DIFF characters
   *
   * If we don't find anything satisfying that, abort
   */
  for( end=beginning ; answer[end] != EOS && answer[end] != '\r' ; end++ );
  if ( answer[end] == EOS || end-beginning < MIN_DIFF)
    return 0;
  for( end=end+1 ; answer[end] != EOS && answer[end] !='\r' ; end++ );
  if ( answer[end] == EOS || end-beginning < MIN_DIFF )
    return 0;

  /* Change the last '\r' to an EOS */
  answer[end] = EOS;

  /* OK */
  r_strcpy(pdu,answer+beginning);
  
  return sim;
}

int main ()
{
  char pdu [ANSWERSIZE];
  int sim = 0;

  fetchsms (pdu, sim);

  return 0;
}
