recipes

packages recipes for the <noname> package manager
Log | Files | Refs

build (1113B)


      1 #!/bin/sh -ex
      2 
      3 cat <<'EOF' >filetype.c
      4 #include "filetype.h"
      5 #include "str.h"
      6 #include "case.h"
      7 
      8 int filetype(const char *fn,stralloc *contenttype)
      9 {
     10   const char *x;
     11   const char *result;
     12   long long i;
     13   char ch;
     14 
     15   if (!stralloc_copys(contenttype,"Content-Type: ")) return 0;
     16 
     17   x = fn + str_rchr(fn,'.');
     18   if (x[str_chr(x,'=')])
     19     for (i = 0;(i < 100) && (ch = x[i]);++i) {
     20       if ((ch != '=') && (ch != '-') && (ch != ':'))
     21 	if ((ch < 'a') || (ch > 'z'))
     22 	  if ((ch < '0') || (ch > '9'))
     23 	    continue;
     24       if (ch == '=') ch = '/';
     25       if (ch == ':') ch = '.';
     26       if (!stralloc_append(contenttype,&ch)) return 0;
     27     }
     28   else {
     29     result = "text/plain";
     30 
     31     /* web content */
     32     if (case_equals(x,".html")) result = "text/html";
     33 EOF
     34 
     35 while read ext mime; do
     36 	printf '    else if (case_equals(x,".%s")) result = "%s";\n' "${ext}" "${mime}"
     37 done <filetype.txt >>filetype.c
     38 
     39 cat <<'EOF' >>filetype.c
     40 
     41     if (!stralloc_cats(contenttype,result)) return 0;
     42   }
     43 
     44   if (!stralloc_cats(contenttype,"\r\n")) return 0;
     45   return 1;
     46 }
     47 EOF
     48 
     49 make
     50 mkdir -p "$PREFIX/bin"
     51 cp httpfile-*[!.][!.]? "$PREFIX/bin"