/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>

#define MAXURL 50
#define MAXURLLEN 100

static char *retbuf[MAXURL];

static char ahref[] = "<A HREF";

char **parse(char *s)
{
   int i;
   int ix;
   int len;
   char *p;
   char *s2;
   len = strlen(s);
   s2 = (char *)malloc(len+1);
   for(i=0;i<len;i++) s2[i] = toupper(s[i]);
   s2[len] = '\0';
   ix = 0;
   p = s2;
   while((p = strstr(p,ahref)) != NULL)
   {
       retbuf[ix] = (char *)malloc(MAXURLLEN);
       p += sizeof(ahref);
       p++;
       len = strcspn(p,"\"'");
       strncpy(retbuf[ix],s+(p-s2),len);
       retbuf[ix][len] = '\0';
       p += (len + 2);
       ix++;
   }
   retbuf[ix] = NULL;
   free(s2);
   return retbuf;
}

int main()
{
   char *s = "...<A HREF=\"http://www.aaa.dk\">...<a href='http://www.bbb.dk'>...";
   char **p = parse(s);
   while(*p)
   {
      printf("%s\n",*p);
      p++;
   }
   return 0;
}
