#!/usr/bin/env omake #---------------------------------------------------------------------------- # Project: Horizon # File: utildefs.om # # Copyright 2007-2009 Nintendo. All rights reserved. # # These coded instructions, statements, and computer programs contain # proprietary information of Nintendo of America Inc. and/or Nintendo # Company Ltd., and are protected by Federal copyright law. They may # not be disclosed to third parties or copied or duplicated in any form, # in whole or in part, without the prior written consent of Nintendo. # # $Date:: 2011-01-21#$ # $Rev: 33681 $ # $Author: okubata_ryoma $ #---------------------------------------------------------------------------- public.gsub(str1, pattern, str2) = FS=__XYZ RS=__XYZ stdout = $(open-out-string) fsubst($(open-in-string $(str1))) case $(pattern) g value $(str2) result = $(out-contents $(stdout)) close($(stdout)) return $(result) public.findstring(str1, pattern) = return $(grep q, $(pattern), $(open-in-string $(str1))) public.compileToRegex(filterstrings) = regex_result = foreach(fs, $(filterstrings)) stdout = $(open-out-string) fsubst($(open-in-string $(fs))) case $'\*(\.\*)+' g value $'*' case $'\.' g value $'\.' case $'\*' g value $'.*' case $'[()]' g value $'\'$1 regex = $(out-contents $(stdout)) close($(stdout)) regex_result += $"\($(regex)\)" export return $(concat $'|', $(regex_result)) public.isFilterMatch(regex, fullname) = match $(fullname) case $(regex) return true default return false public.exist-dirs(dirs) = return $(filter $(dirs),$(glob D,*)) public.ls_(options, dir) = files = .SUBDIRS: $(dir) files = $(ls $(options), .) export return $(files) public.subdirs_(options, dir) = dirs = .SUBDIRS: $(dir) dirs = $(subdirs $(options), .) export return $(dirs) public.ls_relative(options, dir) = dir = $(absname $(dir)) return $(removeprefix $(dir)$(DIRSEP), $(filter-out $(dir), $(ls_ $(options), $(dir)))) public.files(options, path) = result = export result .SUBDIRS: $(path) foreach(filename, $(ls $(options), .)) if $(test -f $(filename)) result += $(string $(filename)) return $(result) public.filter-dirs(filenames) = result = export result foreach(filename, $(filenames)) if $(test -d $(filename)) result += $(filename) return $(result) public.filter-files(filenames) = result = export result foreach(filename, $(filenames)) if $(test -f $(filename)) result += $(filename) return $(result) public.CheckProg_(prog) = WHERE = $(where $(prog)) if $(WHERE) return true else return false public.readfile(filename) = result = try channel = $(fopen $(filename), r) result += $(input-line $(channel)) close($(channel)) export catch RuntimeException(e) return return $(result) public.makeDirectory(path) = section $(path): mkdir -p $@ return $(dir $(path)) public.getMtimeIfLarge(filename) = file_stat = $`(stat $(filename)) return $(if $(and $(file-exists $(filename)), $(ge $(file_stat.size), 8000000)), $(file_stat.mtime))