icmscript(7)
π icmscript(7) β The icmake scripting language π
okay so bestie, welcome to The icmake scripting language β literally the whole vibe of this page π
Icmake(1) is a generic tool that handles program maintenance, and yes, it can be used as an alternative for make(1). Itβs βgenericβ because icmake-scripts are written in a language that closely resembles the C programming language, and those scripts can do tasks that are traditionally the domain of scripting languages. slay β¨
Icmake lets programmers use a programming language β again, closely resembling C β to define the actions required for (complex) program maintenance. For this, icmake offers various special operators plus a set of support functions that have shown their usefulness in program maintenance. iconic behavior, honestly π
This man-page covers the icmake scripting language in the following sections:
- DATA TYPES β
int,list,string, andvoid(for functions); - OUTLINE β outline of icmake scripts: what their requirements are, the structure and organization of their main-functions.
- PREPROCESSOR DIRECTIVES β supported preprocessor directives, like
#includeand#define; - PREDEFINED CONSTANTS β like
O_FILE,OFF, andS_IFREG; - OPERATORS β like
+,younger, and casts - FLOW CONTROL β
if,for,while, etc. (theswitchis not available); - PREDEFINED FUNCTIONS β executing programs, changing directories, operations on string and list type variables, etc. Functions are marked as INT FUNCTIONS, LIST FUNCTIONS, STRING FUNCTIONS
- USER DEFINED FUNCTIONS β at least
main, with or without its common parametersargc,argv, andenvp.
πΈ DATA TYPES πΈ
Icmake supports the following five data and value types:
- ASCII character constants β ASCII character constants are ascii-characters surrounded by single or double quotes. Single characters (e.g.,
βaβ) represent the character itself. Standard escape sequences (e.g.,β\nβ) are supported and are converted to their well-known values (e.g.,β\nβrepresents ascii value 10 (decimal)). Non-standard escape sequences (e.g.,β\xβ) are converted to the ascii character following the escape character (soβ\xβequalsβxβ). Escaped sequences consisting of three octal digits represent the ascii character corresponding to the octal value, modulo 256 (e.g.,β\113βrepresentsβKβ). Escape sequences consisting of an x followed by two hexadecimal digits represent the ascii character corresponding to the hexadecimal value (e.g.,β\x4bβ, also representingβKβ); intβ integral values, ranging from-0x8000through0x7fff.intconstants may be specified as decimal numbers (starting with digits 1 through 9), octal numbers (starting with 0, followed by one or more octal digits), hexadecimal numbers (starting with0x, followed by one or more hexadecimal digits), or as ASCII character constants;stringβ text values: text (orstring) constants are delimited by double or single quotes. Multiple string constants may be concatenated, but a single string constant may not span multiple lines. Multiple string constants, only separated by white space (i.e., blanks, newlines, comment) are concatenated and are considered one single string constant. To indicate an end-of-line in a string constant use the\nescape sequence;
If arithmetic expressions use at least one int operand then those expressions may also contain single character ASCII constants using double or single quotes. In those cases they represent the ascii-values of their characters.
Conversely, ASCII character constants using single quotes may be used in situations where string operands are expected;
listβ a list is a data structure containing a series of individually accessible string values. When a list contains elements, its first element has index 0;
Lists may be written to the standard output stream or to file (using printf or fprintf). Lists can also be inserted into string variables using the function strformat. In these cases all (space delimited) elements of the lists are inserted into their destinations;
Lists can also be defined as constants. They consist of an optional series of comma separated string constants surrounded by a pair of square brackets. E.g.,
list words = ["a", "list", "constant"];
voidβ the typevoidis used when defining functions which do not return values. Alternatively, functions may returnint,stringorlistvalues (cf. section USER DEFINED FUNCTIONS).
Variables can be defined at the global level and inside functions (not only at the top of compound statements but also between statements and in the initialization section of for- and if-statements). When defined inside functions, the standard C scoping and visibility rules apply. Variables are strongly typed, and cannot have type void.
Variables may be initialized when they are defined. Initializations are expressions which may use predefined or user-defined functions, constant values, and values of variables. Functions or variables that are used for initialization must be visible at the initialization point.
π¦ OUTLINE π¦
Icmake scripts require a user-defined function main. The function main has three optional parameters, which may be omitted from the last one (envp) to the first one (argc), like in C. Its full prototype is:
void main(int argc, list argv, list envp)
or
int main(int argc, list argv, list envp)
When a void main function ends (using a return; statement or when its execution reaches its bodyβs closing curly) the value 0 is returned to the operating system. When int main functions end using return statements then those statements must be provided with int-expressions. Itβs OK when the execution of an int main function reaches its bodyβs closing curly, in which case 0 is automatically returned to the operating system.
In main the parameter
argcrepresents the number of elements inargv;argvcontains the arguments, with element 0 being equal to the name of the.bimfile, that were passed to the.bimfile. The OPTIONS section of theicmake(1)manpage covers how these arguments are forwarded to the icmake script using options-e,-s, and-t.envpcontains theenvironmentvariables. The functionlistlencan be used to determine the number of its elements. Elements inenvpuse the formatvariable=value. Alternatively, the (predefined) functiongetenvcan be used to retrieve a specific environment variable immediately.
Example (the implementations of the user-defined functions usage, modified, and compile are left as an exercise for the reader):
void main(int argc, list argv)
{
if (argc == 1)
usage(argv[0]);
if (list toCompile = modified("*.cc"))
{
for (int idx = listlen(toCompile); idx--; )
compile(toCompile[idx]);
}
}
When executing an icmake script icmakeβs run-time support system first initializes all all global variables in the order of their definitions. Following this the function main is called. The script ends when main returns or when the function exit is called by the script.
β¨ PREPROCESSOR DIRECTIVES β¨
okay bestie, before your icmake script even gets actually compiled, it first goes through the icmake pre-processor. That little stage removes comments, includes files specified by include-directives, and processes #define and comparable directives. Basically itβs the backstage crew fixing your fit before the main-character compilation walks out. π
The following preprocessor directives are recognized:
- comment β standard C comment (everything from
/*through*/) as well as comment-to-end-of-line (starting at//, continuing to the end of the line) is ignored. poof, gone π«₯ - Shell startup β the first line of the icmake-script may start with
#!path, wherepathdefines the (usually absolute) location of theicmakeprogram. By making the script executable, it can be called without explicitly callingicmake.
E.g., if the first line of an (executable) icmake script icm (without extension) contains
#!/usr/bin/icmake -t.
then icm can be issued as a command, interpreting the remaining lines of the script as an icmake source which is compiled and then executed by icmake. The icmake(1) man-pageβs section EXECUTING ICMAKE SCRIPTS covers the elements of the first line of icmake scripts. β¨
#include "filename"β the filefilenameis included at the location of the directive. drop it right there π#include <filename>β the filefilenameis included at the location of the#includedirective;filenameis searched in the colon-separated directories specified by theIMenvironment variable. The first occurrence offilenamein the directories specified by theIMenvironment variable is used. first one wins, periodt π#define identifier [definition]β the textidentifieris replaced bydefinition. The definition may contain references to already defined identifiers, using the syntax${identifier}. If the${identifier}hasnβt been defined (yet), the literal text${identifier}is used. To prevent infinite recursion at most 100${identifier}replacements are accepted. no infinite-loop era π
If the last character on a line is a backslash (\) then definitions continue at the next line. (the backslash is not included in the definition). The preprocessor concatenates double-quoted strings. Double quoted strings themselves may not span multiple lines. Multiple blanks (outside of double quoted strings) in definitions are contracted to a single space character.
Following the #defineβs identifier a definition may optional be provided. If omitted, the macro is defined, so it can be used in #if(n)def directives (see below), but in those cases these identifiers are simply removed from icmake code statements.
#ifdef identifierβ if theidentifiermacro was defined the next block of code (until a matching#elseor#endifdirective was read) is byte-compiled. Otherwise, the code block is ignored. π§#ifndef identifierβ if theidentifiermacro was not defined the next block of code (until a matching#elseor#endifdirective was detected) is byte-compiled. Otherwise, the code block is ignored. same vibe, opposite check π¦#elseβ terminates#ifdefand#ifndefcode blocks, reversing the acceptance decision about the following code block. Only one#elsedirective can be associated with#if(n)defdirectives. one and done πΈ#endifβ terminates the code block starting beyond the matching#ifdef,#ifndefor#elsedirective. Associated#if(n)def,#else, and#endifdirectives must be specified in the same file. keep the whole little family in the same file, okay? π«Ά#undef identifierβ removeidentifierfrom the set of defined symbols. This does not affect the specification of any previously defined symbols usingidentifierβs definition. Ifidentifierhasnβt been defined a warning is issued. heads up, not drama π
β¨ PREDEFINED CONSTANTS β¨
The following predefined int constants are available (the functions listed in the intended for column are described in the upcoming sections covering the predefined functions):
O_ALLβ value8, intended formakelistO_DIRβ value2, intended formakelistO_FILEβ value1, intended formakelistO_SUBDIRβ value4, intended formakelistOFFβ value0, intended forechoONβ value1, intended forechoP_CHECKβ value0, intended for system callsP_NOCHECKβ value1, intended for system callsS_IEXECβ value32, intended forstatS_IFCHRβ value1, intended forstatS_IFDIRβ value2, intended forstatS_IFREGβ value4, intended forstatS_IREADβ value8, intended forstatS_IWRITEβ value16, intended forstat
The following constants are architecture dependent β each one is 1 when defined on the platform, otherwise 0:
unixβ Unix, usually with GNUβsgcccompilerUNIXβ may alternatively be availablelinuxβ x86 running Linux (usually withgcc)LINUXβ may alternatively be availableM_SYSV,M_UNIXβ x86 running SCO/Unix_POSIX_SOURCEβ Unix with Posix compliant compiler__hpuxβ HP-UX, with the native HP compiler
π OPERATORS π
Okay so real talk β since icmake version 10.00.00 the << operator can be used like the C++ insertion operator. Like, literally the same vibe. Peep the description of the functions printf and fprintf below for the full tea. π₯
int-operators
Every single C operator is available (yes, including the ternary operator), except for pointer operators β because icmake does not support pointers, periodt. They all operate exactly like their C-programming-language counterparts. Comparison operators return 1 if the comparison is true, otherwise 0 is returned. Simple as that, bestie. β¨
string-operators
For string variables and/or constants the following operators are available, where lhs and rhs are string variables or constants:
lhs + rhsβ returns a new string value containing the concatenation of stringslhsandrhs. And ngl, string constants can also be directly concatenated without the+operator, like the following two lines both define the string"hello world":
"hello " "world"
"hello " + "world"
lhs += rhsβlhsmust be a string variable, to which the string variable or valuerhsis appended. π«Ά- string comparisons β operators
==!=<=>=<>!=and==return1if the comparison is true, otherwise0. The ordering operators (like<and>=) use the (case sensitive) character ordering defined by the ASCII character set. iykyk π !lhsβ the boolean!(not) operator returns1if the stringlhsis empty, otherwise0is returned. Strings merely containing white-space characters are not empty. Sneaky little things.lhs younger rhs,lhs newer rhsβ returns1if filelhsis more recent than filerhs. E.g.,"source.cc" newer "source.o". The fileslhsandrhsdo not have to exist, which is kind of iconic of them:- if both don't exist
0is returned, - if
lhsdoesn't exist0is returned, - if
rhsdoesn't exist,1is returned, - if they are equally old
0is returned.
- if both don't exist
The function exists() (see below, section PREDEFINED FUNCTIONS) can be used to test whether a file exists. π¦
lhs older rhsβ returns1if filelhsis older than filerhs. E.g.,"libprog.a" older "source.o". Same deal, the fileslhsandrhsdo not have to exist:- if both don't exist
0is returned, - if
lhsdoesn't exist1is returned, - if
rhsdoesn't exist,0is returned, - if they are equally old
0is returned.
- if both don't exist
[]β the index operator returns a character from a string variable or constant. A string is returned as an rvalue. So the following statement compiles OK:
lhs = rhs[3];
but the following statement won't compile (as lhs[3] is an rvalue):
lhs[3] = "a";
If an invalid (out of bounds) index value is specified an empty string is returned. No crash, no drama, just emptiness. π
- The backtick operator (
string cmd) β a string placed between two backticks is executed as a separate command. Different from theexecandsystemcalls, the backtick operator collects the standard output produced bycmdand returns this output as a list. π
The elements of the list contain the subsequent lines of output (including a final newline, if present) produced by cmd. A command that could be executed but that did not produce any output returns a list containing one string element, which is empty.
An empty list indicates that the command could not be executed. π
The command's standard error stream output is ignored by the backtick operator. However, standard shell redirection may be used to collect the standard error stream's output. Clever, right?
Example:
printf << `"ls"`; // prints the elements in
// the current directory
Note that the backtick operator requires a string argument: either a string constant or a string variable.
The function eval(string cmd) behaves exactly like the backtick operator: they are synonyms. Two names, one queen. π
list-operators
For list variables and/or values the following operators are available:
lhs + rhsβ returns a new list value containing the concatenation of the values of listslhsandrhs. Heads up: this is not a set operation β if an element appears both inlhsand inrhs, then both will appear in the resulting list (set-addition is provided by the functionlistunion). So yes, duplicates, we love that for us. β¨lhs - rhsβ returns a new list value containing the elements inlhsthat are not present inrhs. This is a set-difference operation. The ordering of the remaining elements in the returned list is equal to the ordering of those elements inlhs. π§lhs += rhsβ elements inrhsare added to the elements inlhs, which must be a list variable. This is not a set operation.lhs -= rhsβ elements inrhsare removed from the elements inlhs. This is a set operation: all elements oflhsthat are found inrhsare removed fromlhs. The ordering of the remaining elements inlhsis not altered. Ship intact, no notes. π«Ά- list equality comparisons β operators
!=and==may be applied to list values or variables. Operator==returns1if both lists have element-by-element identical elements, otherwise0is returned. Operator!=reverses the result of==. !lhsβ the boolean!operator returns1if the listlhsis empty, otherwise0is returned.[]β the index operator retrieves an element from a list variable: it returns a string as an rvalue. So the following statement compiles OK:
// assume lst is a list, str is a string
str = lst[3];
but the following statement won't compile (as lst[3] is an rvalue):
lst[3] = str;
If an invalid (out of bounds) index value is specified an empty string is returned. Again: no drama, just vibes and an empty string. πΈ
casting
Type-casts using the standard C-style cast-operator can be used to cast:
- strings to ints and vice versa (
(int)"123",(string)55) β if the content of a string does not represent a (decimal) int value0the cast returns0. Rude but fair. π - Strings to lists (
list lst = (list)"hello") β this returns a list having one element (hello). Note that casting a string to a list as shown is overkill, aslist lst = ["hello"]performs the same initialization. Lowkey the longer way around, but it works. π
π FLOW CONTROL π
Icmake offers a subset of C's flow control statements. They can be used as in the C programming language. No surprises, no plot twists. β¨
expression ;β the plain expression statement.
Insert-expression statements are defined for the functions fprintf and printf. Expression statements may start with printf << or fprintf << filename <<. The values of all subsequent expressions, separated by << operators (which in this context are called insertion operators) are written to the standard output stream (when using printf <<), or to the file whose name is provided in the string filename (when using fprintf << filename <<). Examples:
printf << "hello" << ' ' << "world" << '\n';
fprintf << "out.txt" << "hello" << ' ' << "world" << '\n';
- The compound statement β variables may be defined and initialized inside compound statements at locations where expression statements can also be used. The visibility of variables starts at their points of definition. Main character energy: they exist from the moment they're introduced. π
if ([definition;] condition) statementβ the[definition;]phrase is optional. If used it defines a type followed by a comma-separated list of variables which may be provided with initialization expressions.
The condition phrase is required, and may define and initialize a variable. E.g,
if (string str = getText())
process(str);
In this example, process is not called if getText() returns an empty string.
Variables defined in the definition and condition phrases do not exist either before or after the if statement. They said "right place, right time" and dipped. π
if ([definition;] condition) statement1 else statement2β acts like the previous statement. If the condition is truestatement1is executed; if the condition is falsestatement2is executed.for (init; condition; increment) statementβ variables (of a single type) may be initialized (and optionally defined) in theinitsection. The condition phrase may define and initialize a variable. Theinit,conditionandincrementsections may remain empty. An empty condition section is interpreted asalways true. So yeah, an empty condition is just infinite confidence. π₯while (condition) statementβ inside the condition a variable may be defined and initialized.
A complementary do ... while() statement is not available. Sad, but we cope.
Note that when a variable is defined and initialized in the condition section the initialization expression is executed at each iteration of the while statement. Thus the following statement never ends, and displays a never ending stream of values 10:
while (int x = 10)
printf(x--, "\n");
That one's a trap, bestie β it literally never ends. π
return;, andreturn expression;β plainreturnstatements can be used invoidfunctions, andreturn expressionstatements are used in other type of functions.breakβbreak;statements can only be used inforandwhilestatements, ending those statements. Exit the chat. πͺcontinueβcontinue;statements can only be used inforandwhilestatements, continuing their next iteration. Not leaving, just skipping ahead. π¦
π PREDEFINED FUNCTIONS π
Icmake provides the following predefined functions, which can be used anywhere in icmake scripts. In the following overview the functions are ordered by categories, and within categories they are ordered alphabetically by function name. Organized, alphabetical, aesthetically flawless. π
Five categories are distinguished:
- Functions operating on ints (see INT FUNCTIONS below) β these functions receive int arguments, processing those arguments;
- Functions operating on strings (see STRING FUNCTIONS below) β these functions operate on the strings which are passed to these functions as arguments;
- Functions operating on lists (see LIST FUNCTIONS below) β these functions operate on the lists which are passed to these functions as arguments;
- Functions manipulating file system entries (see FILESYSTEM FUNCTIONS below) β these functions receive the names of file-system entries (files, directories, etc.) as their string arguments. π
okay so real quick heads-up bestie β these functions are not listed in the STRING FUNCTIONS section, and that's on purpose π they don't actually operate on the string arguments you hand them, they just use those arguments to point at entries in the file system. no cap.
meanwhile stuff like change_base doesn't touch file-system entries at all, which is exactly why that one is an entry in the STRING FUNCTIONS section. the way that logic just... works π¦
- system-related functions (peep SYSTEM FUNCTIONS below π): these interface to facilities provided by the operating system β like executing programs, or changing the script's environment variables. some of these functions use specialized support functions, and those are hanging out in this section too π«Ά
π INT FUNCTIONS π
string ascii(int value)β returnsvalueas a string:ascii(65)returns the string"A"β¨echo(int opt)β controls echoing of called programs (and their arguments). specifyOFFif echoing is not requested. by defaultecho(ON)is active π
πΈ STRING FUNCTIONS πΈ
int ascii(string str)β returns the first character ofstras an int:ascii("A")returns65;string change_base(string file, string base)β returnsfilewhose base name is changed intobase:change_base("/path/demo.im", "out")returns"/path/out.im";string change_ext(string file, string ext)β returnsfilewhose extension is changed intoext:change_ext("source.cc", "o")returns"source.o". the extension of the returned string is separated from the file's base name by a single dot (e.g.,change_ext("source.", ".cc")returns"source.cc");string change_path(string file, string path)β returnfilewhose path is changed intopath:change_path("tmp/binary", "/usr/bin")returns"/usr/bin/binary". to remove the path, specifypathas an empty string πstring element(int index, string var)β acts identically to the index operator: refer to the index ([]) operator in section OPERATORS;string get_base(string file)β returns the base name offile. the base name is the file without its path prefix and without its extension. the extension is all information starting at the final dot in the filename. if no final dot is found, the file name is the base name. e.g., the base name ofa.bequalsa, the base name ofa.b.cequalsa.b, the base name ofa/b/cequalscπstring get_dext(string file)β returns the extension offile, including the separating dot (hence thedindext). the extension is all information starting at the filename's final dot. iffiledoesn't have a final dot then an empty string is returned;string get_ext(string file)β returns the extension offile, without the separating dot. the extension is all characters infilestarting atfile's final dot. if no final dot is found, an empty string is returned;string get_path(string file)β returnsfile's path-prefix. the path prefix is all information up to (and including) the final directory separator (which is, depending on the operating system, a forward slash or a backslash). iffiledoes not contain a path-element, then an empty string is returned;string resize(string str, int newlength)β returns a copy of stringstr, resized tonewlengthcharacters. ifnewlengthis negative then an empty string is returned; ifnewlengthexceedsstr's length then the newly added characters are initialized to blank spaces πint strchr(string str, string chars)β returns the first index instrwhere any of the characters incharsis found, or-1ifstrdoes not contain any of the characters inchars;int strfind(string haystack, string needle)β returns index inhaystackwhereneedleis found, or-1ifneedleis not found inhaystack;string strformat(string format, argument(s))β returns a string constructed from the format string containing placeholders%1..%2to refer to arguments following the format string. the specification%1refers to the first argument following the format string. if fewer arguments thannare provided then additional0arguments are provided by icmake. example π«Ά:
void main()
{
string s2 = = strformat("%1 %2 %1\n", 10, 20);
printf("s2 = ", s2); // shows: s2 = 10 20 10
}
int strlen(string str)β returns the number of characters instr(not counting the terminating NUL-character);string strlwr(string str)β returns a lower-case duplicate ofstr;list strtok(string str, string separators)β returns a list containing all substrings ofstrseparated by one or more (consecutive) characters inseparators:strtok("hello icmake's+world", " +")returns a list containing the three strings"hello","icmake's", and"world"π¦string strupr(string str)β returns an upper-case duplicate ofstr.string substr(string text, int offset, int count)β returns a substring oftext, starting atoffset, consisting ofcountcharacters. ifoffsetexceeds (or equals) the string's length, or ifcount <= 0, then an empty string is returned. ifoffsetis less than0thenoffset = 0is used. ifoffset + countexceedstext's length then the available substring starting attext[offset]is returned (which may be empty);string trim(string str)β returns a copy ofstrwithout leading and trailing white spaces;string trimleft(string str)β returns a copy ofstrwithout leading white spaces;string trimright(string str)β returns a copy ofstrwithout trailing white spaces.
π§ LIST FUNCTIONS π§
string element(int index, list var)β acts identically to the index operator: refer to the index ([]) operator in section OPERATORS;int listfind(list lst, string str)β returns the smallest index inlstwhere the stringstris found, or-1iflstdoes not containstr;int listlen(list l)β returns the number of elements in list;list listunion(list lhs, list rhs)β returns a list containing the union of the elements inlhsand the elements ofrhs. the original order of the elements inlhsis kept. subsequent elements inrhsthat are not available inlhsare added to the end oflhsβlist listunion(list lst, string str)β returns a list containing the union of the elements inlstandstr. the original order of the elements inlhsis kept. ifrhsis not available inlhsthen it is added to the end oflhs.
π FILESYSTEM FUNCTIONS π
string chdir([int check,] string dir)β changes the script's working directory todir(which may be specified as absolute or relative to the script's current working directory). the first argument is optional: if it's omitted and changing the working directory fails then the icmake-script ends with exit value1π; by specifyingP_NOCHECKthe function won't terminate the script, it merely returns the script's current working directory. the script's working directory after completing the change-dir request is returned as an absolute path, ending in a/directory separator π
use chdir(".") to merely obtain the current working directory; use chdir("") to change-dir to the script's startup working directory;
int exists(string file)β iffileexists,1is returned, otherwise0is returned;list fgets(string file, list offset)β the next line found at offset valueoffset[3]is read fromfile. pass an empty list tofgetsto readfilefrom its beginning.
the returned list has four elements:
- its first element (
[0]) contains the read line (without the line's\nline terminator); - its second element (
[1]) contains the line's\nline terminator (or an empty string if the line was not terminated by a\n); - its third element (
[2]) contains the stringOKif the line was successfully read andFAILif reading fromfilefailed; - its fourth element (
[3]) contains the offset beyond the last read byte.
to read multiple lines, pass the returned list as argument to fgets:
list ret;
while (ret = fgets("filename", ret))
process(ret);
be careful not to definelist retinwhile's condition, bestie, because that will resetretto an empty list at each iteration π
int fprintf(string filename, argument(s))β appends all (comma or left-shift (insertion) operator separated) arguments to the filefilename. returns the number of printed arguments π₯
if the first argument (following filename) contains placeholders (%1, %2, ... %n) then that argument is considered a format string (see also the function strformat in the string functions section for additional information about format strings). some examples:
fprintf("out", "hello", "world", '\n');
fprintf << "out" << "hello" << "world" << '\n';
fprintf("out", "%1 %2\n", "hello", "world"); // 1
fprintf << "out" << "hello" << ' ' << "world" << '\n'; // 2
fprintf << "out" << "%1 %2\n" << "hello" << "world"; // 3
when writing statement 1 using insertion operators (cf. the expression statement description in section FLOW CONTROL) statement 2 would normally be encountered, although statement 3, using the format string, would still be accepted;
string getch()β returns the next pressed key as a string (pressing theEnter-key is not required). the pressed key is not echoed. if the key should be echoed use, e.g.,printf(getch());πstring gets()β returns the next line read from the keyboard as a string. the line contains all entered characters until theEnter-key was pressed. theEnter-key's value itself is not stored in the returned string;list makelist([int type = O_FILE], string mask)β okay so thetypeargument is optional, and if you skip it,O_FILEis what gets used.makelistreturns a list of all type file-system entries matchingmask. Example:makelist("*.c")gives you a list containing every file ending in.c. Fortype, you can use one of these values to get a more specific selection of directory entries:O_ALLβ obtain all directory entriesO_DIRβ obtain all directories, including.and..O_FILEβ obtain a list of regular filesO_SUBDIRβ obtain all directories except for.and..
In Unix-type operating systems the pattern*does not match entries starting with a dot (hidden entries). To obtain a list of such entries use the pattern.*.
list makelist([int type = O_FILE,] string mask, {newer,older,younger}, string comparefile)β thetypeparameter is optional and works like the previous variant. The third parameter must be eithernewer(oryounger) orolder. You get a list of all file-system entries matchingmaskwhich are, respectively, newer or older than a providedcomparefile. Note thatnewerandyoungerare operators, not strings πΈ.int printf(argument(s))β the functionβs arguments (separated by commas or by the left-shift (insertion) operator) are written to the standard output file (cf. the expression statement description in section FLOW CONTROL and this sectionβs description of thefprintffunction). If the first argument contains%1,%2, ...%nspecifications then itβs considered a format string (see also the functionstrformatin the STRING FUNCTIONS section for additional information about format strings). Likefprintf,printfreturns the number of printed arguments π.list stat([int check,] string entry)β returnsstat(2)information of directory entryentryas a list. The first argument is optional: if omitted and calling the systemstatfunction fails then the icmake-script ends with exit value1; by specifyingP_NOCHECKthe function wonβt terminate the script but returns the return value (-1) of the systemstatfunction.
The returned list has two elements:
[0]holds the entryβs attributes. Attributes are returned as the file type and mode of the specified file (cf.stat(2)andinode(7)). E.g.,S_IRUSRβ owner has read permissionS_IWUSRβ owner has write permissionS_IXUSRβ owner has execute permissionS_IFSOCKβ socketS_IFLNKβ symbolic linkS_IFREGβ regular fileS_IFBLKβ block deviceS_IFDIRβ directoryS_IFCHRβ character deviceS_IFIFOβ FIFO
[1]contains the entryβs size in bytes. IfP_NOCHECKwas specified and'entry'doesnβt exists then a list having one element is returned containing-1.
π SYSTEM FUNCTIONS: π
void arghead(string str)β support function ofexec()(see also below atexec()): defines theargument headthat is used withexec(). By default, theargument headis an empty string. The argument head is text that is prefixed to all exec arguments, like a directory in which provided arguments are found π.void argtail (string str)β support function ofexec()(see also below atexec()): defines theargument tailthat is used withexec(). By default, theargument tailis an empty string. The argument tail is text that is appended to all exec arguments, like the extensions of files that are passed as arguments to exec β¨.cmdhead(string str)β support function ofexec()(see also below atexec()). Defines acommand headthat is used withexec(). By default it is an empty string. It can be used to specify, e.g., compiler options when the arguments themselves are modified byargheadandargtail. Thecmdheadargument itself is not modified byargheadorargtailπcmdtail(string str)β support function ofexec()(see also below atexec()). Defines acommand tailthat is used withexec(). By default it is an empty string. It can be used to specify a final argument (not modified byargheadandargtail) π .list eval(string str)β this function can be used instead of the backtick operator (cf. section OPERATORS). The example provided with the backtick operator could therefore also have been written like this:
printf << eval("ls"); // prints the elements in the current
// directory
As mentioned at the backtick operator: the elements of the list contain the subsequent lines of output (including a final newline, if present) produced by cmd. A command that could be executed but that did not produce any output returns a list containing one string element, which is empty.
An empty list indicates that the command could not be executed π¦.
int exec([int check,] string cmd, argument(s))β executes the commandcmdwith (optional) arguments. Each argument is prefixed byargheadand postfixed byargtail. Note that no blanks are inserted betweenarghead,argument(s), andargtail. The thus modified arguments are concatenated, separated by single blanks.cmdheadis inserted betweencmdand the first argument (delimited by single blanks) andcmdtailis appended to the arguments, separated by a single blank.PATHis searched to locatecmd.0is returned.
The first argument is optional: if omitted and the command does not return 0 the icmake script terminates. By specifying P_NOCHECK exec wonβt terminate the script but returns the called commandβs exit status, or 0x7f00 if the command wasnβt found.
The remaining arguments may be ints, strings or lists. Int and list arguments are cast to strings. Their string representations are then appended to cmd β.
int execute([int checking,] string cmd, string cmdhead, string arghead, argument(s), string argtail, string cmdtail)β same functionality as the previous function, but thecmdhead,arghead,argtail, andcmdtailare explicitly specified (and are reset to empty strings after executingcmd) π«Ά.exit(expression)β ends the execution of an icmake-script. The expression must evaluate to anintvalue, which is used as the scriptβs exit value π.list getenv(string envvar)β returns the value of environment variableenvvarin a list containing two elements:- if the first element (
[0]) is"1"then the environment variable was defined; - environment variables are of the form
variable=value. If element[0]is"1"then the returned listβs second element ([1]) holds the value part of the environment variable, which is empty if the environment variable is merely defined;
- if the first element (
int getpid()β returns the process-id of the icmake byte code interpretericm-execπ.int putenv(string envvar)β adds or modifiesenvvarto the current icmake-script environment. Use the format:"VAR=value". Use"VAR"to remove"VAR"from the environment. The function returns0unlessenvvaris empty, in which case1is returned π.int system([int check,] string command)β executescommandusing thesystem(3)function. The first argument is optional: if omitted and calling thesystem(3)function does not return0then the icmake-script ends with exit value1; by specifyingP_NOCHECKicmakeβs system function wonβt terminate the script but returns the return value of thesystem(3)function (normally the executed commandβs exit value). The stringcommandmay use redirection and/or piping π₯.
π USER DEFINED FUNCTIONS π
In addition to main, additional functions can be defined. Once defined, they can be called. Forward referencing of either variables or functions is not supported, but calling functions recursively is. As function declarations are not supported indirect recursion cannot be used.
Function overloading (based on differently typed parameters) is supported π.
User-defined functions must have the following elements:
- The functionβs return type, which must be
void,int,stringorlist. There is no default type; - The functionβs name, e.g.,
compile; - A parameter list, defining zero or more comma-separated parameters. The parameters themselves consist of a type name (
int,string, orlist) followed by the parameterβs identifier. E.g.,(string outfile, string source); - A body surrounded by a pair of curly braces (
{and}).
Function bodies may contain variable definitions (optionally initialized at their definitions). Variable definitions start with a type name, followed by one or more comma separated and optionally initialized variable identifiers.
If a variable is not explicitly initialized it is initialized by default: int variables are initialized to 0, string variables are initialized to empty strings ("") and list variables are initialized to empty lists.
Function bodies may also contain zero or more statements (cf. section FLOW CONTROL). Note that variables may be defined (and optionally initialized) anywhere inside functions where expression statements can be used, and also in the condition sections of if, for, and while statements and in the initialization sections of if andd for statements πΈ.
π EXAMPLE π
okay so bestie, here's the whole vibe in action. In this example, every C++ source file in the current directory gets compiled β unless its object file is more recent (because why redo work you already slayed at, right?). The main function builds a list of source files and then hands each one over to a function called inspect. That function checks whether the source file is younger than its object file, and if it is, it calls compile. And compile uses exec to call the compiler. If a compilation fails, the script just stops β periodt β so you can actually go fix the error. π
void compile(string src)
{
exec("g++ -c " + src); // compile βsrcβ
}
void inspect(string src)
{ // get the obj-fileβs name:
// only compile if necessary
if (src younger change_ext(src, ".o"))
compile(src);
}
int main()
{ // find all .cc source files
list sources = makelist("*.cc");
for ( // visit all source files
int idx = 0, end = listlen(sources);
idx != end;
++idx
)
inspect(sources[idx]); // compile if needed
}
like, it's giving "minimal makefile but make it a whole language" and honestly? obsessed. β¨
π¦ SEE ALSO π¦
go read these too, iykwyk:
π BUGS π
ngl, there are exactly two things to watch out for, and they're both real:
- Standard comments that start on lines containing preprocessor directives may not extend over multiple lines. so like, keep those comments contained, bestie.
- Path names containing blanks are not supported. fr fr, no spaces in your paths.
π COPYRIGHT π
This is free software, distributed under the terms of the GNU General Public License (GPL). π
πΈ AUTHOR πΈ
Frank B. Brokken (f.b.brokken@rug.nl).
and that's the whole page, bestie β you made it to the end of the icmscript(7) saga π«Ά This gorgeous thing ships as icmake 13.07.00, and the page is dated 1992β2026 β literal decades of main character energy. go compile something iconic. πβπ§
π¦ where this page comes from
- arch rolling: icmake 13.07.00-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms