Annotation of embedaddon/php/build/order_by_dep.awk, revision 1.1.1.1

1.1       misho       1: BEGIN {
                      2:        orig_rs = RS;
                      3:        orig_fs = FS;
                      4:        RS=" ";
                      5:        mod_count = 0;
                      6:        SUBSEP=":";
                      7: }
                      8: 
                      9: function get_deps(module_name,       depline, cmd)
                     10: {
                     11:        # this could probably be made *much* better
                     12:        RS=orig_rs;
                     13:        FS="[(,) \t]+"
                     14:        cmd = "grep PHP_ADD_EXTENSION_DEP ext/" module_name "/config*.m4"
                     15:        while (cmd | getline) {
                     16: #              printf("GOT: %s,%s,%s,%s,%s\n", $1, $2, $3, $4, $5);
                     17:                if (!length($5)) {
                     18:                        $5 = 0;
                     19:                }
                     20:                mod_deps[module_name, $4] = $5;
                     21:        }
                     22:        close(cmd)
                     23:        RS=" ";
                     24:        FS=orig_fs;
                     25: }
                     26: 
                     27: function get_module_index(name,  i)
                     28: {
                     29:        for (i in mods) {
                     30:                if (mods[i] == name) {
                     31:                        return i;
                     32:                }
                     33:        }
                     34:        return -1;
                     35: }
                     36: 
                     37: function do_deps(mod_idx,        module_name, mod_name_len, dep, ext, val, depidx)
                     38: {
                     39:        module_name = mods[mod_idx];
                     40:        mod_name_len = length(module_name);
                     41: 
                     42:        for (ext in mod_deps) {
                     43:                if (substr(ext, 0, mod_name_len+1) != module_name SUBSEP) {
                     44:                        continue;
                     45:                }
                     46:                val = mod_deps[ext];
                     47:                ext = substr(ext, mod_name_len+2, length(ext)-mod_name_len);
                     48: 
                     49:                depidx = get_module_index(ext);
                     50:                if (depidx >= 0) {
                     51:                        do_deps(depidx);
                     52:                }
                     53:        }
                     54:        printf("        phpext_%s_ptr,@NEWLINE@", module_name);
                     55:        delete mods[mod_idx];
                     56: }
                     57: 
                     58: function count(arr,       n, i)
                     59: {
                     60:        n = 0;
                     61:        for (i in arr)
                     62:                n++;
                     63:        return n;
                     64: }
                     65: 
                     66: /^[a-zA-Z0-9_-]+/ {
                     67:        # mini hack for pedantic awk
                     68:        gsub("[^a-zA-Z0-9_-]", "", $1)
                     69:        # add each item to array
                     70:        mods[mod_count++] = $1
                     71: 
                     72:        # see if it has any module deps
                     73:        get_deps($1);
                     74: }
                     75: END {
                     76:        # order it correctly
                     77:        out_count = 0;
                     78:        
                     79:        while (count(mods)) {
                     80:                for (i = 0; i <= mod_count - 1; i++) {
                     81:                        if (i in mods) {
                     82:                                do_deps(i);
                     83:                        }
                     84:                }
                     85:        }
                     86: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>