# # initially generated by c2l # match(name: array of byte, template: array of byte, stem: array of byte): int { r: int; n: int; while(int name[0] && int template[0]){ (r, n, nil) = sys->byte2char(template, 0); if(r == '%' || r == '&') break; while(n--) if(name[0] != template[0]) return 0; name = name[1: ]; template = template[1: ]; } if(!(template[0] == byte '%' || template[0] == byte '&')) return 0; n = libc0->strlen(name)-libc0->strlen(template[1: ]); if(n < 0 || libc0->strcmp(template[1: ], name[n: ])) return 0; libc0->strncpy(stem, name, n); stem[n] = byte 0; if(template[0] == byte '&') return charin(stem, libc0->s2ab("./")) == nil; return 1; } subst(stem: array of byte, template: array of byte, dest: array of byte) { r: int; s: array of byte; n: int; while(int template[0]){ (r, n, nil) = sys->byte2char(template, 0); if(r == '%' || r == '&'){ template = template[n: ]; for(s = stem; int s[0]; s = s[1: ]){ dest[0] = s[0]; dest = dest[1: ]; } } else while(n--){ dest[0] = template[0]; dest = dest[1: ]; template = template[1: ]; } } dest[0] = byte 0; }