/*
 * Copyright 2013 Yuichiro Moriguchi
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.morilib.awk.nano.builtin;

import net.morilib.awk.nano.misc.OSInfo;
import net.morilib.awk.nano.namespace.AwkNamespace;
import net.morilib.awk.nano.value.AwkString;

/**
 * 関数をロードするためのクラスです。
 *
 *
 * @author MORIGUCHI, Yuichiro 2013/03
 */
public class AwkBuiltInLoader {

	/**
	 * 関数を名前空間にロードします。
	 * 
	 * @param ns 名前空間
	 */
	public static void load(AwkNamespace ns) {
		ns.assign("FS", AwkString.valueOf(" "));
		ns.assign("RS", AwkString.valueOf("\n"));
		ns.assign("OFS", AwkString.valueOf(" "));
//		ns.assign("ORS", AwkString.valueOf("\n"));
		ns.assign("ORS", AwkString.valueOf(OSInfo.OS.getNewline()));
		ns.assign("SUBSEP", AwkString.valueOf("\u001d"));
		ns.assign("OFMT", AwkString.valueOf("%.6g"));

		ns.bindFunction("gsub", new AwkGsub());
		ns.bindFunction("index", new AwkIndex());
		ns.bindFunction("length", new AwkLength());
		ns.bindFunction("match", new AwkMatch());
		ns.bindFunction("sprintf", new AwkSprintf());
		ns.bindFunction("sub", new AwkSub());
		ns.bindFunction("substr", new AwkSubstr());

		ns.bindFunction("atan2", new AwkAtan2());
		ns.bindFunction("cos", new AwkCos());
		ns.bindFunction("exp", new AwkExp());
		ns.bindFunction("int", new AwkInt());
		ns.bindFunction("log", new AwkLog());
		ns.bindFunction("rand", new AwkRand());
		ns.bindFunction("sin", new AwkSin());
		ns.bindFunction("sqrt", new AwkSqrt());
		ns.bindFunction("srand", new AwkSrand());
		ns.bindFunction("tan", new AwkTan());

		ns.bindFunction("system", new AwkSystem());

		ns.bindFunction("tolower", new STolower());
		ns.bindFunction("toupper", new SToupper());
		ns.bindFunction("systime", new AwkSystime());
		ns.bindFunction("strftime", new AwkStrftime());
		ns.bindFunction("gensub", new AwkGensub());
	}

}
