link cfunc
April 9, 1996; Gregg M. Townsend
Requires: Dynamic loading
This file is in the public domain.
bitcount(i) returns the number of bits that are set in the integer i. It works only for "normal" integers, not large integers.
[ Summary entry | Source code ]
link cfunc
May 29, 2013; Gregg M. Townsend
Requires: Dynamic loading
This file is in the public domain.
These functions demonstrate the use of external values. extxmin() creates a minimal external type extxstr(s) creates an external hold a string and trivial checksum extxreal(r) creates a fully customized external type holding a real value
[ Summary entry | Source code ]
link cfunc
November 17, 2004; Gregg M. Townsend
Requires: UNIX, dynamic loading
This file is in the public domain.
chmod(filename, mode) changes the file permission modes of a file to those specified. umask(mask) sets the process "umask" to the specified value. If mask is omitted, the current process mask is returned.
[ Summary entry | Source code ]
link cfunc
October 27, 2009; Gregg M. Townsend
Contributor: Cheyenne Wills
Requires: UNIX, dynamic loading
This file is in the public domain.
fpoll(f, msec) waits until data is available for input from file f, and then returns. It also returns when end-of-file is reached. If msec is specified, and no data is available after waiting that many milliseconds, then fpoll fails. If msec is omitted, fpoll waits indefinitely.
[ Summary entry | Source code ]
link cfunc
April 26, 2002; Kostas Oikonomou
This file is in the public domain.
This file provides three procedures for translating homogeneous lists of integers, reals, or strings to C arrays: IListVal(d) returns an array of C ints. RListVal(d) returns an array of C doubles. SListVal(d) returns an array of C char pointers (char *). ____________________________________________________________ Here is an example of using this interface: 1. gcc -I/opt/icon/ipl/cfuncs -shared -fPIC -o llib.so l.c where "l.c" is the C fragment below. #include "ilists.c" int example(int argc, descriptor argv[]) { int *ia; double *ra; char *(*sa); int n; int i; ArgList(1); n = ListLen(argv[1]); ia = IListVal(argv[1]); for (i=0; i<n; i++) printf("%i ", ia[i]); printf("\n"); ArgList(2); n = ListLen(argv[2]); ra = RListVal(argv[2]); for (i=0; i<n; i++) printf("%f ", ra[i]); printf("\n"); ArgList(3); n = ListLen(argv[3]); printf("n = %i\n", n); sa = SListVal(argv[3]); for (i=0; i<n; i++) printf("%s ", sa[i]); printf("\n"); Return; } 2. The Icon program that loads "example" from the library llib.so: procedure main() local e, L1, L2, L3 e := loadfunc("./llib.so", "example") L1 := [] every i := 1 to 5 do put(L1,10*i) L3 := ["abcd","/a/b/c","%&*()","","|"] e(L1,[1.1,2.2,-3.3,5.5555],L3) end
[ Summary entry | Source code ]
link cfunc
October 3, 1995; Gregg M. Townsend
Requires: Dynamic loading
This file is in the public domain.
These functions provide some access to the internal machinery of the Icon interpreter. Some knowledge of the interpreter is needed to use these profitably; misuse can lead to memory violations. dword(x) return d-word of descriptor vword(x) return v-word of descriptor descriptor(d,v) construct descriptor from d-word and v-word peek(addr,n) return contents of memory as n-character string (if n is omitted, return Icon integer at addr) spy(addr,n) return string pointer to memory, without copying
[ Summary entry | Source code ]
link cfunc
September 2, 2012; Gregg M. Townsend
Requires: Dynamic loading
This file is in the public domain.
lgconv(I) converts a large integer into a string using a series of BCD adds. (In contrast, the Icon built-in string() function accomplishes the same conversion using a series of divisions by 10.) lgconv is typically 50% to 75% faster than string() on a Sun or Alpha. For some reason it is as much as 125% SLOWER on a SGI 4/380. lgconv(I) works for all integer values of I. Small integers are simply passed to string() for conversion.
[ Summary entry | Source code ]
link cfunc
November 17, 1997; Gregg M. Townsend
Requires: OSF or Digital UNIX, dynamic loading
This file is in the public domain.
osftable(id, index, len) returns one element from an OSF table() call. This function is for the OSF operating system, and fails on other systems. See "man table" for a detailed description of the "table" system call and the formats of the structures returned; see /usr/include/table.h for a list of allowed ID values. Defaults: index 0 len 100
[ Summary entry | Source code ]
link cfunc
November 17, 1997; Gregg M. Townsend
Requires: Dynamic loading
This file is in the public domain.
s := pack(value, flags, width) x := unpack(string, flags) Flag characters are as follows: l -- little-endian [default] b -- big-endian n -- host platform's native packing order i -- integer [default] u -- unsigned integer r -- real (host platform's native float or double format) The default width is 4. Integer values must fit in a standard Icon integer (not large integer). Consequently, a word-sized value cannot have the high bit set if unsigned. Floating values can only be converted to/from a string width matching sizeof(float) or sizeof(double). Size/type combinations that can't be handled produce errors. Valid combinations produce failure if the value overflows. Some of this code assumes a twos-complement architecture with 8-bit bytes.
[ Summary entry | Source code ]
link cfunc
November 17, 1997; Gregg M. Townsend
Requires: Dynamic loading
This file is in the public domain.
These functions manipulate raw (P6) PPM image files in memory. The images must not contain comment strings. ppmwidth(s) -- return width of PPM image. ppmheight(s) -- return height of PPM image. ppmmax(s) -- return maximum value in PPM header. ppmdata(s) -- return data portion of PPM image. ppmimage(s,p,f) -- quantify image s using palette p, with flags f. Returns an Icon image string. Flag "o" selects ordered dithering. Defaults: p="c6", f="o" ppmstretch(s,lo,hi,max) -- apply contrast stretch operation Returns a PPM string image that results from setting all values <= lo to zero, all values >= hi to max, with values between scaling linearly. If hi = lo + 1, this becomes a simple threshold operation. If lo=0 and hi=ppmmax(s), this simply scales an image to a new maximum. Requirements: 0 <= lo < hi <= ppmmax(s), 1 <= max <= 255. Defaults: lo=0, hi=ppmmax(s), max=255. ppm3x3(s,a,b,c,d,e,f,g,h,i) -- apply 3x3 convolution to PPM image. The matrix of real numbers [[a,b,c],[d,e,f],[g,h,i]] is used as a transformation matrix applied independently to the three color components of the image.
[ Summary entry | Source code ]
link cfunc
November 17, 2004; Gregg M. Townsend
Requires: UNIX, dynamic loading
This file is in the public domain.
kill(pid, signal) kill process (defaults: pid=0, signal=SIGTERM) getpid() return process ID getuid() return user ID getgid() return group ID
[ Summary entry | Source code ]
link cfunc
October 3, 1995; Gregg M. Townsend
Requires: Unix, dynamic loading
See also: fpoll.c
This file is in the public domain.
tconnect(hostname, portnum) establishes a TCP connection to the given host and port, returning an Icon file f. Note that seek(f) must be called when switching between input and output on this bidirectional file. Additionally, the DEC Alpha requires a call to flush(f), after the seek, when switching from input to output.
[ Summary entry | Source code ]