#---------------------------------------------------------------------------- # Project: Horizon # File: utildefs.om # # Copyright (C)2009-2011 Nintendo Co., Ltd. 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. # # $Rev: 35508 $ #---------------------------------------------------------------------------- # This file is only function definitions # Do not add anything other than function definitions #---------------------------------------------------------------------------- # Function definitions #---------------------------------------------------------------------------- #------------------------------------------------------- # gsub # # Overview # | # # Referenced global variables # FS, RS, stdout #------------------------------------------------------- public.gsub(str1, pattern, str2) = FS=__XYZ RS=__XYZ stdout = $(open-out-string) fsubst($(open-in-string $(str1))) case $(pattern) g value $(str2) private.result = $(out-contents $(stdout)) close($(stdout)) return $(result) #------------------------------------------------------- # findstring # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.findstring(str1, pattern) = return $(grep q, $(pattern), $(open-in-string $(str1))) #------------------------------------------------------- # compileToRegex # # Overview # | # # Referenced global variables # stdout #------------------------------------------------------- public.compileToRegex(filterstrings) = private.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 # ' private.regex = $(out-contents $(stdout)) close($(stdout)) value $"\($(regex)\)" return $(concat $'|', $(regex_result)) #------------------------------------------------------- # isFilterMatch # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.isFilterMatch(regex, fullname) = match $(fullname) case $(regex) return true default return false #------------------------------------------------------- # exist-dirs # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.exist-dirs(dirs) = return $(filter $(dirs),$(glob D,*)) #------------------------------------------------------- # ls_ # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.ls_(options, path) = private.files = $(EMPTY) .SUBDIRS: $(path) files = $(ls $(options), .) export files return $(files) #------------------------------------------------------- # subdirs_ # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.subdirs_(options, path) = private.dirs = $(EMPTY) .SUBDIRS: $(path) dirs = $(subdirs $(options), .) export dirs return $(dirs) #------------------------------------------------------- # ls_relative # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.ls_relative(options, rdir) = private.adir = $(absname $(rdir)) return $(removeprefix $(adir)$(DIRSEP), $(filter-out $(adir), $(ls_ $(options), $(adir)))) #------------------------------------------------------- # files # # Overview # | # # Referenced global variables # GLOBAL_TEMP_RESULT #------------------------------------------------------- public.files(options, path) = section GLOBAL_TEMP_RESULT = $(EMPTY) export GLOBAL_TEMP_RESULT .SUBDIRS: $(path) foreach(filename, $(ls $(options), .)) if $(test -f $(filename)) GLOBAL_TEMP_RESULT += $(string $(filename)) return $(GLOBAL_TEMP_RESULT) #------------------------------------------------------- # filter-dirs # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.filter-dirs(filenames) = private.result = $(EMPTY) section export result foreach(filename, $(filenames)) if $(test -d $(filename)) result += $(filename) return $(result) #------------------------------------------------------- # filter-files # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.filter-files(filenames) = private.result = $(EMPTY) section export result foreach(filename, $(filenames)) if $(test -f $(filename)) result += $(filename) return $(result) #------------------------------------------------------- # CheckProg_ # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.CheckProg_(prog) = private.where = $(where $(prog)) if $(where) return true else return false #------------------------------------------------------- # readfile # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.readfile(filename) = private.result = $(EMPTY) try channel = $(fopen $(filename), r) result += $(input-line $(channel)) close($(channel)) export result catch RuntimeException(e) return return $(result) #------------------------------------------------------- # makeDirectory # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.makeDirectory(path) = $(path): mkdir -p $@ return $(dir $(path)) #------------------------------------------------------- # getMtimeIfLarge # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.getMtimeIfLarge(path_list) = private.result = foreach (path, $(path_list)) if $(file-exists $(path)) private.file_stat = $(stat $(path)) value $(if $(ge $(file_stat.size), 8000000),$(file_stat.mtime),1) else value 0 return $(result) #------------------------------------------------------- # makePath # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.makePath(a) = return $(concat $(DIRSEP),$(a)) #------------------------------------------------------- # stripEmpty # # Overview # | # # Referenced global variables # GLOBAL_TEMP_B #------------------------------------------------------- public.stripEmpty(a) = section GLOBAL_TEMP_B = $(EMPTY) export GLOBAL_TEMP_B foreach (e, $(a)) GLOBAL_TEMP_B += $(e) return $(GLOBAL_TEMP_B) #------------------------------------------------------- # isEmpty # # Overview # | # # Referenced global variables # None. #------------------------------------------------------- public.isEmpty(seq) = return $(eq 0, $(length $(seq))) #------------------------------------------------------- # digest-in-path-optional_internal # # Overview # Internal function for digest-in-path-optional # # Referenced global variables # None. #------------------------------------------------------- digest-in-path-optional_internal(path, file) = # Unnecessary to search for path if it is an absolute path if $(equal $(fullname $(file)), $(absname $(file))) private.path_digest = $(digest-optional $(file)) if $(not $(equal $(path_digest), false)) return $(file) $(path_digest) return # Relative path foreach(dir, $(path)) private.filepath = $(dir)$(DIRSEP)$(file) export filepath if $(equal ., $(dirof $(filepath))) filepath = $(basename $(file)) else filepath = $(dirof $(filepath))$(DIRSEP)$(basename $(filepath)) private.path_digest = $(digest-optional $(filepath)) if $(not $(equal $(path_digest), false)) return $(filepath) $(path_digest) return #------------------------------------------------------- # digest-in-path-optional_ # # Overview # Version of digest-in-path-optional that does not reference cache # # Referenced global variables # GLOBAL_TEMP_RESULT #------------------------------------------------------- public.digest-in-path-optional_(path, files) = # To test the current path first path = . $(path) GLOBAL_TEMP_RESULT = foreach(filename, $(files)) GLOBAL_TEMP_RESULT += $(digest-in-path-optional_internal $(path), $(filename)) export GLOBAL_TEMP_RESULT return $(GLOBAL_TEMP_RESULT) public.mapToArray(m, f) = GLOBAL_TEMP_RESULT = $(EMPTY_ARRAY) section export GLOBAL_TEMP_RESULT m.foreach(k,v) GLOBAL_TEMP_RESULT += $(apply $(f),$(k),$(v)) return $(GLOBAL_TEMP_RESULT)