CVS diff for mime.c between 1.2 and 1.1:

Revision 1.1 Revision 1.2
Line 15 Line 15
// char* mime_tab[3]; 
char default_type[16]; 
 
// char* mime_tab[3]; 
char default_type[16]; 
 
void
void add_mime_type(FILE * fp, char *media_type) 
add_mime_type (FILE * fp, char *media_type)
 
{
{
  int h;
  int j;
  int k;
  int flg = 0;
  char sux[16];
  for (;;)
  {
    j = 0;
    k = 1;
    flg = 0;
    h = eat_ws (fp);
    if ('\n' == h || '\r' == h || '\0' == h)
      return;
    mime[mime_idx].types[0] = '\0';
    strncat (mime[mime_idx].types, media_type, strlen (media_type));
    sux[0] = h;
    sux[1] = '\0';
    for (;;)
    {
      h = getc (fp);
      if (' ' == h || '\t' == h)
	break;
      if ('\n' == h || '\r' == h)
      {
	flg = 1;
	break;
      }
      sux[k++] = h;
      sux[k] = '\0'; 
    int h;
    int j;
    int k;
    int flg = 0;
    char sux[16];
    for (;;) {
	j = 0;
	k = 1;
	flg = 0;
	h = eat_ws(fp);
	if ('\n' == h || '\r' == h || '\0' == h)
	    return;
	mime[mime_idx].types[0] = '\0';
	strncat(mime[mime_idx].types, media_type, strlen(media_type));
	sux[0] = h;
	sux[1] = '\0';
	for (;;) {
	    h = getc(fp);
	    if (' ' == h || '\t' == h)
		break;
	    if ('\n' == h || '\r' == h) {
		flg = 1;
		break;
	    }
	    sux[k++] = h;
	    sux[k] = '\0';
	}
	mime[mime_idx].suffix[0] = '\0';
	strncat(mime[mime_idx].suffix, sux, strlen(sux));
 
	mime_idx++;
	if (flg)
	    return;
    }
    }
    mime[mime_idx].suffix[0] = '\0';
    strncat (mime[mime_idx].suffix, sux, strlen (sux));
    mime_idx++;
    if (flg)
      return;
  } 
 


int
int mime_init(FILE * fp) 
mime_init (FILE * fp)
 
{
{
  int h;
  char mt_buf[128]; 
    int h;
    char mt_buf[128]; 

            

            
  default_type[0] = '\0';
  strcat (default_type, "text/html"); 
    default_type[0] = '\0';
    strcat(default_type, "text/html"); 

            

            
  mime_idx = 0;
  for (;;)
  {
    h = eat_ws (fp);
    if (EOF == h)
    {
      return 0; 
    mime_idx = 0;
    for (;;) {
	h = eat_ws(fp);
	if (EOF == h) {
	    return 0;
	}
	else if ('#' == h) {
 
	    eat_line(fp);
	}
	else {
	    int j = 0;
	    /* media type */
	    mt_buf[j++] = h;
	    for (;;) {
		h = getc(fp);
		if (' ' == h || '\t' == h) {
		    mt_buf[j++] = '\0';
		    add_mime_type(fp, mt_buf);
		    j = 0;
		    break;
		}
		else if (h == '\0')
		    return 0;
		else if (h == '\n' || h == '\r')
		    break;
		else
		    mt_buf[j++] = h;
	    }
	}
    }
    }
    else if ('#' == h)
    {
      eat_line (fp);
    }
    else
    {
      int j = 0;
      /* media type */
      mt_buf[j++] = h;
      for (;;)
      {
	h = getc (fp);
	if (' ' == h || '\t' == h)
	{
	  mt_buf[j++] = '\0';
	  add_mime_type (fp, mt_buf);
	  j = 0;
	  break;
	}
	else if (h == '\0')
	  return 0;
	else if (h == '\n' || h == '\r')
	  break;
	else
	  mt_buf[j++] = h;
      }
    }
  } 
 


char *
char *get_mime_type(char *filename) 
get_mime_type (char *filename)
 
{
{
  char *suffix;
  int i = 0; 
    char *suffix;
    int i = 0; 

            

            
  suffix = strrchr (filename, '.'); 
    suffix = strrchr(filename, '.'); 

            

            
  if (!suffix || '\0' == *suffix) 
    if (!suffix || '\0' == *suffix)
 
	return default_type;

    suffix++;			// don't want '.'

    for (; i < mime_idx; i++) {
	if (!strcmp(mime[i].suffix, suffix))
	    return mime[i].types;
    }
    return default_type;
    return default_type;
  suffix++;			// don't want '.'

  for (; i < mime_idx; i++)
  {
    if (!strcmp (mime[i].suffix, suffix))
      return mime[i].types;
  }

  return default_type; 
 




Legend
Lines deleted from 1.2  
Lines Modified
  Lines added in revision 1.1