yast2-core
Macros | Functions | Variables
YCPBuiltinMisc.cc File Reference
#include <unistd.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <errno.h>
#include "ycp/YCPBuiltinMisc.h"
#include "ycp/YCPBoolean.h"
#include "ycp/YCPInteger.h"
#include "ycp/YCPVoid.h"
#include "ycp/YCPString.h"
#include "ycp/YCPCode.h"
#include "ycp/StaticDeclaration.h"
#include "ycp/y2log.h"
#include "y2util/y2changes.h"
#include "ycp/ExecutionEnvironment.h"

Macros

#define ETC   0, NULL, constTypePtr(), NULL
 
#define ETCf   NULL, constTypePtr(), NULL
 

Functions

static YCPInteger Time ()
 Checks whether a value is of a certain type. More...
 
static YCPValue Sleep (const YCPInteger &ms)
 
static YCPInteger Random (const YCPInteger &max)
 
static YCPInteger Srandom1 ()
 
static YCPValue Srandom2 (const YCPInteger &seed)
 
static YCPBoolean Setenv2 (const YCPString &name, const YCPString &value, const YCPBoolean &overwrite)
 
static YCPBoolean Setenv1 (const YCPString &name, const YCPString &value)
 
static YCPString Getenv (const YCPString &name)
 
static YCPValue Eval (const YCPValue &v)
 
static YCPString s_sformat (const YCPValue &format, const YCPValue &_argv)
 
static YCPValue Y2Log (loglevel_t level, const YCPString &format, const YCPList &args)
 
static YCPValue Y2Debug (const YCPString &format, const YCPList &args)
 
static YCPValue Y2Milestone (const YCPString &format, const YCPList &args)
 
static YCPValue Y2Warning (const YCPString &format, const YCPList &args)
 
static YCPValue Y2Error (const YCPString &format, const YCPList &args)
 
static YCPValue Y2Security (const YCPString &format, const YCPList &args)
 
static YCPValue Y2Internal (const YCPString &format, const YCPList &args)
 
static YCPValue Y2FDebug (const YCPInteger &f, const YCPString &format, const YCPList &args)
 
static YCPValue Y2FMilestone (const YCPInteger &f, const YCPString &format, const YCPList &args)
 
static YCPValue Y2FWarning (const YCPInteger &f, const YCPString &format, const YCPList &args)
 
static YCPValue Y2FError (const YCPInteger &f, const YCPString &format, const YCPList &args)
 
static YCPValue Y2FSecurity (const YCPInteger &f, const YCPString &format, const YCPList &args)
 
static YCPValue Y2FInternal (const YCPInteger &f, const YCPString &format, const YCPList &args)
 
static YCPValue Y2UserItem (const YCPString &format, const YCPList &args)
 
static YCPValue Y2UserNote (const YCPString &format, const YCPList &args)
 

Variables

StaticDeclaration static_declarations
 

Macro Definition Documentation

#define ETC   0, NULL, constTypePtr(), NULL
#define ETCf   NULL, constTypePtr(), NULL

Function Documentation

static YCPValue Eval ( const YCPValue v)
static

eval Evaluate a YCP value. See also the builtin ``, which is kind of the counterpart to eval.

eval (``(1+2)) -> 3

References YCPElement::isNull().

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPString Getenv ( const YCPString name)
static

getenv Change or add an environment variable The getenv(variable) function returns the value of variable from environment. If variable doesn't exist the value is NULL.

Parameters
stringname
Returns
string value getenv ("USER") -> "root" getenv ("LC_CTYPE") -> "en_US.UTF-8"

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPInteger Random ( const YCPInteger max)
static

random Random number generator. Returns a random integer in the interval [0,MAX). srandom must be activated to get really random numbers.

Parameters
integerMAX
Returns
integer Returns integer in the interval [0,MAX). random(100) -> 82 random(100) -> 36

References YCPElement::isNull().

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPString s_sformat ( const YCPValue format,
const YCPValue _argv 
)
static

sformat Format a String FORM is a string that may contains placeholders %1, %2, ... Each placeholder is substituted with the argument converted to string whose number is after the %. Only 1-9 are allowed by now. The percentage sign is donated with %%.

Parameters
stringFORM
anyPAR1
anyPAR2
any...
Returns
string sformat ("%2 is greater %% than %1", 3, "five") -> "five is greater % than 3"

References YCPElement::isNull(), YCPList::size(), YCPList::value(), and y2warning.

Referenced by Y2Log(), Y2UserItem(), Y2UserNote(), and YCPBuiltinMisc::YCPBuiltinMisc().

static YCPBoolean Setenv1 ( const YCPString name,
const YCPString value 
)
static

setenv Change or add an environment variable The setenv() function adds the variable to the environment with the value. If variable exist the value is changed.

Parameters
stringvariable
stringvalue
Returns
boolean setenv-always setenv("PATH", "/home/user")

References Setenv2().

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPBoolean Setenv2 ( const YCPString name,
const YCPString value,
const YCPBoolean overwrite 
)
static

setenv Change or add an environment variable The setenv() function adds the variable to the environment with the value. If variable exist the value is changed.

Parameters
stringvariable
stringvalue
booleanoverwrite
Returns
boolean setenv-choose setenv("PATH", "/home/user", true)

References ycp2error.

Referenced by Setenv1(), and YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Sleep ( const YCPInteger ms)
static

sleep Sleeps a number of milliseconds.

Parameters
integerMILLISECONDS Time in milliseconds
Returns
void sleep(3000) -> sleeps 3 sec.

References YCPElement::isNull().

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPInteger Srandom1 ( )
static

srandom Initialize random number generator Initialize random number generator with current date and time and returns the seed.

Returns
integer srandom-time srandom()

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Srandom2 ( const YCPInteger seed)
static

srandom Initialize random number generator.

Parameters
integerSEED
Returns
void srandom-integer srandom(3355)

References YCPElement::isNull(), and ycp2error.

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPInteger Time ( )
static

Checks whether a value is of a certain type.

is

Parameters
anyvalue a value whose type is checked
typetype type to check
Returns
boolean any ui = UI::UserInput(); if (is (ui, string)) { foo ("Hello, " + (string) ui); } else if (is (ui, symbol)) { bar ((symbol) ui); }

time Return the number of seconds since 1.1.1970.

Returns
integer time() -> 1111207439

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2Debug ( const YCPString format,
const YCPList args 
)
static

y2debug Log a message to the y2log.

Arguments are same as for sformat() builtin. The y2log component is "YCP", so you can control these messages the same way as other y2log messages.

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2debug ("%1 is smaller than %2", 7, "13");

References LOG_DEBUG, and Y2Log().

Referenced by Y2FDebug(), and YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2Error ( const YCPString format,
const YCPList args 
)
static

y2error Log an error to the y2log.

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2error ("Invalid format of IPv4 '%1'.", "333.10.20.1") -> "Invalid format of IPv4 '333.10.20.1'"

References LOG_ERROR, and Y2Log().

Referenced by Y2FError(), and YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2FDebug ( const YCPInteger f,
const YCPString format,
const YCPList args 
)
static
static YCPValue Y2FError ( const YCPInteger f,
const YCPString format,
const YCPList args 
)
static
static YCPValue Y2FInternal ( const YCPInteger f,
const YCPString format,
const YCPList args 
)
static
static YCPValue Y2FMilestone ( const YCPInteger f,
const YCPString format,
const YCPList args 
)
static
static YCPValue Y2FSecurity ( const YCPInteger f,
const YCPString format,
const YCPList args 
)
static
static YCPValue Y2FWarning ( const YCPInteger f,
const YCPString format,
const YCPList args 
)
static
static YCPValue Y2Internal ( const YCPString format,
const YCPList args 
)
static

y2internal Log an internal message to the y2log.

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2internal("This is a robbery!") -> "This is a robbery!"

References LOG_INTERNAL, and Y2Log().

Referenced by Y2FInternal(), and YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2Log ( loglevel_t  level,
const YCPString format,
const YCPList args 
)
static
static YCPValue Y2Milestone ( const YCPString format,
const YCPList args 
)
static

y2milestone Log a milestone to the y2log.

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2milestone("%1 - Humans detected!", "2038-02-12") -> "2038-02-12 - Humans detected!"

References LOG_MILESTONE, and Y2Log().

Referenced by Y2FMilestone(), and YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2Security ( const YCPString format,
const YCPList args 
)
static

y2security Log a security message to the y2log.

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2security ("Users on vacations: %1", ["josh", "joe", "pete"]) -> "Users on vacations: ["josh", "joe", "pete"]"

References LOG_SECURITY, and Y2Log().

Referenced by Y2FSecurity(), and YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2UserItem ( const YCPString format,
const YCPList args 
)
static

y2useritem Log an user-level system message to the y2changes

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2useritem("Executing reboot")

References YCPElement::isNull(), s_sformat(), and y2useritem.

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2UserNote ( const YCPString format,
const YCPList args 
)
static

y2usernote Log an user-level addional message to the y2changes

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2usernote("Starting module Bee")

References YCPElement::isNull(), s_sformat(), and y2usernote.

Referenced by YCPBuiltinMisc::YCPBuiltinMisc().

static YCPValue Y2Warning ( const YCPString format,
const YCPList args 
)
static

y2warning Log a warning to the y2log.

Parameters
stringFORMAT
anyPAR1
anyPAR2
any...
Returns
void
See also
sformat

y2warning ("Breakers don't work!") -> "Breakers don't work!" y2warning ("%1 %2 packets have been lost", 12, "UDP") -> "12 UDP packets have been lost"

References LOG_WARNING, and Y2Log().

Referenced by Y2FWarning(), and YCPBuiltinMisc::YCPBuiltinMisc().

Variable Documentation

StaticDeclaration static_declarations

Generated on a sunny day for yast2-core by doxygen 1.8.8