home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-01 | 98.2 KB | 4,419 lines |
-
- MUL INTERPRETER INTRINSIC FUNCTIONS REFERENCE
-
- ----------------------------------------------------------------------
-
- NAME
- About
-
- DESCRIPTION
- Opens an about window that lists the current MUL version and
- Copyright notice.
-
- SYNOPSIS
- void About (int row_offset)
-
- INPUTS
- row_offset - Optional screen offset for window display.
-
- RETURN VALUE
- None
-
- ALSO SEE
- IDENT VERSN
-
- EXAMPLE
- main ()
- {
- About (); // Open the about window
- Hidecur (); // Hide the cursor
- while (!kbhit()) ; // Wait until key hit
- getch (); // Clear the key
- Wclose (); // Close the about window
- Showcur (); // Show the cursor
- }
-
- ----------------------------------------------------------------------
-
- NAME
- And
-
- DESCRIPTION
- Returns the bitwise AND of the two arguments. At the bit level,
- that is for each bit in the two arguments, a bitwise AND results
- in "only two one's make a one".
-
- SYNOPSIS
- long And (long arg1, long arg2)
-
- INPUTS
- arg1 - First value.
- arg2 - Second value.
-
- RETURN VALUE
- Value of the bitwise AND.
-
- ALSO SEE
- Or Xor Invert ShiftLeft ShiftRight
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- if (BaseRead (1)) { // Read first (sysop) record
- if (And (USRxpflag,XP_DATE))
- printf ("Sysop expiry by date is Active\n");
- else
- printf ("Sysop expiry by date is Inactive\n");
- }
- else printf ("Base open failed!\n");
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- atoi
-
- DESCRIPTION
- Convert a decimal character string to an integer value.
-
- SYNOPSIS
- int atoi (char *str)
-
- INPUTS
- str - Decimal character string.
-
- RETURN VALUE
- Integer value of str.
-
- ALSO SEE
- sign itoa ltoa atol
-
- EXAMPLE
- main ()
- {
- int var;
-
- var = atoi ("42");
- printf ("Value is %d\n",var);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- atol
-
- DESCRIPTION
- Convert a decimal character string to a long value.
-
- SYNOPSIS
- long atoi (char *str)
-
- INPUTS
- str - Decimal character string.
-
- RETURN VALUE
- Long value of str.
-
- ALSO SEE
- sign itoa ltoa atoi
-
- EXAMPLE
- main ()
- {
- long var;
-
- var = atol ("42");
- printf ("Value is %ld\n",var);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Attr
-
- DESCRIPTION
- Return a foreground/background colour attribute.
-
- SYNOPSIS
- int Attr (int foreground, int background)
-
- INPUTS
- foreground - Foreground colour attribute.
- background - Optional background colour attribute.
-
- RETURN VALUE
- Colour attribute value.
-
- ALSO SEE
- Avt
-
- EXAMPLE
- main ()
- {
- char colour;
-
- colour = Attr (WHITE,RED);
-
- if (Wopen (16,21,20,59,0,colour,colour)) {
- Wxyputs (1,1,colour," Press any key to continue ..");
- Hidecur (); // Hide the cursor
- while (!kbhit()) ; // Wait until key hit
- getch (); // Clear the key
- Wclose (); // Close the window
- Showcur (); // Show the cursor
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Avt
-
- DESCRIPTION
- Return character pointer to an avatar colour string.
-
- SYNOPSIS
- char * Avt (int foreground, int background)
-
- INPUTS
- foreground - foreground colour attribute.
- background - optional background colour attribute.
-
- RETURN VALUE
- Avatar colour string.
-
- ALSO SEE
- Attr
-
- EXAMPLE
- main ()
- {
- long fp;
- char colour[5];
- char MENTER=0x01; // Maximus 'press enter'
-
- strcpy (colour,Avt (WHITE,BLACK));
- fp = fopen ("ONLINE.BBS","wb");
-
- if (fp != NULL) {
- fprintf (fp,"%s%c",colour,MENTER);
- fclose (fp);
- }
- else printf ("File open failed!\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseAppend
-
- DESCRIPTION
- Append a new record to the Maximus user file.
-
- SYNOPSIS
- int BaseAppend (void)
-
- INPUTS
- None
-
- RETURN VALUE
- TRUE on success, FALSE on failure.
-
- ALSO SEE
- BaseOpen BaseOpenR BaseClose BaseRead BaseWrite
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseClear (); // Clear record buffer
- BaseAppend (); // Append new record
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseClear
-
- DESCRIPTION
- Clears the Maximus user record buffer. Places correct default
- values in the record fields as required for a blank appended
- record.
-
- SYNOPSIS
- int BaseClear (void)
-
- INPUTS
- None
-
- RETURN VALUE
- None
-
- ALSO SEE
- BaseAppend
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseClear (); // Clear record buffer
- BaseAppend (); // Append new record
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseClose
-
- DESCRIPTION
- Close the Maximus user file.
-
- SYNOPSIS
- int BaseClose (void)
-
- INPUTS
- None
-
- RETURN VALUE
- TRUE on success, FALSE on failure.
-
- ALSO SEE
- BaseOpen
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- printf("Sysop name is %s\n",USRname);
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseCount
-
- DESCRIPTION
- Return the number of records in the Maximus user file. Only
- applicable when the user file is open.
-
- SYNOPSIS
- int BaseCount (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The number of records in the user file.
-
- ALSO SEE
- BaseOpen BaseClose
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- printf("Record count is %d\n",BaseCount ());
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseDaysLCall
-
- DESCRIPTION
- Return the number of days since last call for the current Maximus
- user record, read with BaseRead. Only applicable when the user file
- is open.
-
- SYNOPSIS
- int BaseDaysLCall (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The number of days since last call.
-
- ALSO SEE
- BaseRead BaseDaysXpry
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- printf("The sysop last called %d days ago\n",BaseDaysLCall ());
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseDaysXpry
-
- DESCRIPTION
- Return the number of days until expiry for the current Maximus
- user record, read with BaseRead. Only applicable when the user file
- is open, and the record is set to expire by date.
-
- SYNOPSIS
- int BaseDaysXpry (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The number of days until expiry.
-
- ALSO SEE
- BaseRead BaseDaysLCall
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- if (And (USRxpflag,XP_DATE))
- printf("The sysop expires in %d days\n",BaseDaysXpry ());
- else
- printf("The sysop has no expiry date\n");
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseHelpStr
-
- DESCRIPTION
- Return character string description of Maximus user record help setting.
-
- SYNOPSIS
- char * BaseHelpStr (char help_value)
-
- INPUTS
- Help value.
-
- RETURN VALUE
- Help value string.
-
- ALSO SEE
- BaseVideoStr BasePrivStr BaseKeyStr BaseProtStr BaseXpTypStr
- BaseXpActStr
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- printf("The sysop help level is %s\n",BaseHelpStr (USRhelp));
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseIdx
-
- DESCRIPTION
- Returns the base index number for a record number. All MUL Maximus
- user record numbers reference the base via an internal base index.
- This index is preset to reflect file record order. The BaseSort
- function sorts the base index, so that subsequent record access via
- BaseRead(rec) and other access functions, result in a sorted output.
- BaseIdx returns the actual record number from the base index array.
-
- SYNOPSIS
- int BaseIdx (int rec)
-
- INPUTS
- rec - Maximus base record number, valid range of 1 to BaseCount()
- inclusive.
-
- RETURN VALUE
- Base index number (zero based).
-
- ALSO SEE
- BaseSort
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseSort (IDX_FNAME); // Sort by first name
- printf("First sorted user record number is %d\n",BaseIdx (2));
- BaseClose ();
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseKeyOff
-
- DESCRIPTION
- Sets user record buffer key value OFF.
-
- SYNOPSIS
- void BaseKeyOff (long keybit)
-
- INPUTS
- long keybit - Bit value of key to turn off.
-
- RETURN VALUE
- None
-
- ALSO SEE
- BaseKeyOn KEY1 - KEYX
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- BaseKeyOff (KEY1); // Turn off key one
- BaseWrite (1); // Write sysop record
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseKeyOn
-
- DESCRIPTION
- Sets user record buffer key value ON.
-
- SYNOPSIS
- void BaseKeyOn (long keybit)
-
- INPUTS
- long keybit - Bit value of key to turn on.
-
- RETURN VALUE
- None
-
- ALSO SEE
- BaseKeyOff KEY1 - KEYX
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- BaseKeyOn (KEY1); // Turn on key one
- BaseWrite (1); // Write sysop record
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseKeyStr
-
- DESCRIPTION
- Return character string representation of Maximus user record keys
- setting.
-
- SYNOPSIS
- char * BaseKeyStr (long keys, int pad)
-
- INPUTS
- keys - Keys value.
- pad - Pad flag. If true, generate fixed length string, padded
- with '.' characters representating missing keys.
-
- RETURN VALUE
- Character string keys representation.
-
- ALSO SEE
- BaseHelpStr BaseVideoStr BasePrivStr BaseProtStr BaseXpTypStr
- BaseXpActStr
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- printf("Sysop keys: %s\n",BaseKeyStr (USRkeys));
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseOpen
-
- DESCRIPTION
- Open User file for read/write access.
-
- SYNOPSIS
- int BaseOpen (char * filename)
-
- INPUTS
- filename - User file path and name string.
-
- RETURN VALUE
- TRUE on success, FALSE on failure.
-
- ALSO SEE
- BaseOpenR BaseClose
-
- EXAMPLE
- main ()
- {
- char fname[80];
-
- strcpy (fname,"USER.BBS");
-
- if (BaseOpen (fname)) { // Open user base
- printf("%s open for read/write access, with %d records\n",
- fname,BaseCount ());
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseOpenR
-
- DESCRIPTION
- Open User file for read access. Same as BaseOpen except that write
- access is blocked (BaseWrite calls will always fail).
-
- SYNOPSIS
- int BaseOpenR (char * filename)
-
- INPUTS
- filename - User file path and name string.
-
- RETURN VALUE
- TRUE on success, FALSE on failure.
-
- ALSO SEE
- BaseOpen BaseClose
-
- EXAMPLE
- main ()
- {
- char fname[80];
-
- strcpy (fname,"USER.BBS");
-
- if (BaseOpenR (fname)) { // Open user base
- printf("%s open for read access, with %d records\n",
- fname,BaseCount ());
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BasePack
-
- DESCRIPTION
- Pack the user file. BasePack rewrites an open user file, removing
- non-permanent records that have the delete flag set. BasePack also
- renumbers any ###.BBS custom welcome files found in the user file
- directory (which is assumed to be the Maximus home directory). This
- can be disabled via a MUL.INI entry. BasePack writes the user file
- records using the internal index array, so that if the BaseSort
- function has been called after the base was opened and prior to the
- BasePack call, the new user file will be written in sorted order.
-
- SYNOPSIS
- int BasePack (char * filename)
-
- INPUTS
- filename - User file path and name string.
-
- RETURN VALUE
- The count of records purged plus one on success, 0 on failure.
-
- ALSO SEE
- BaseSort
-
- EXAMPLE
- main ()
- {
- int count;
-
- BaseOpen ("USER.BBS"); // Open the user base
- BaseSort (IDX_FNAME); // Sort by first name
- count=BasePack ("USER.BBS"); // Rewrite the user base
- BaseClose (); // Close the user base
- if (count) printf("Pack successful, %d records deleted\n",count-1);
- else printf("Pack failed!\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BasePrivStr
-
- DESCRIPTION
- Return character pointer to priviledge level string.
-
- SYNOPSIS
- char * BasePrivStr (int priv)
-
- INPUTS
- priv - Maximus user base priviledge level
-
- RETURN VALUE
- Priviledge level description string.
-
- ALSO SEE
- BaseHelpStr BaseVideoStr BaseKeyStr BaseProtStr BaseXpTypStr
- BaseXpActStr
-
- EXAMPLE
- main ()
- {
- int rec=1;
-
- if (BaseOpen ("USER.BBS")) { // Open the user base
- while (BaseRead (rec++)) // For all records
- // List name and priviledge
- printf("%4d %-35s %s\n",rec-1,USRname,BasePrivStr (USRpriv));
-
- BaseClose (); // Close the user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseProtStr
-
- DESCRIPTION
- Return character pointer to default transfer protocol string.
-
- SYNOPSIS
- char * BaseProtStr (int protocol)
-
- INPUTS
- protocol - Maximus user base default protocol setting
-
- RETURN VALUE
- Default transfer protocol description string.
-
- ALSO SEE
- BaseHelpStr BaseVideoStr BasePrivStr BaseKeyStr BaseXpTypStr
- BaseXpActStr
-
- EXAMPLE
- main ()
- {
- int rec=1;
-
- if (BaseOpen ("USER.BBS")) { // Open the user base
- while (BaseRead (rec++)) // For all records
- // List name and default protocol
- printf("%4d %-35s %s\n",rec-1,USRname,BaseProtStr (USRdefprot));
-
- BaseClose (); // Close the user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseRead
-
- DESCRIPTION
- Read a User file record. Applicable only after a successful
- BaseOpen call. BaseRead copies the specified user record from
- the user file into the user record buffer. All user record field
- variables (USRname, etc) reference this buffer.
-
- SYNOPSIS
- int BaseRead (int rec)
-
- INPUTS
- rec - Record number to read, range 1 to BaseCount () inclusive.
-
- RETURN VALUE
- TRUE on success, FALSE on failure.
-
- ALSO SEE
- BaseWrite BaseOpen BaseClose
-
- EXAMPLE
- main ()
- {
- int rec=1;
-
- if (BaseOpen ("USER.BBS")) { // Open the user base
- while (BaseRead (rec++)) // For all records
- printf("%s\n",USRname); // List names
- BaseClose (); // Close the user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseSort
-
- DESCRIPTION
- Sort the user record index array. Only valid after a successful BaseOpen
- function call. BaseSort sorts the internal record access array, so that
- subsequent record access function calls (BaseRead, etc) result in an
- apparent sorted output. BaseSort does NOT modify the on disk user file.
-
- SYNOPSIS
- int BaseSort (int sort_method)
-
- INPUTS
- sort_method - Sort method to use. There are eleven sort methods,
- including the default file order. See the IDX_* set
- of inbuild interpreter constants, listed below.
- IDX_DEFAULT, IDX_FNAME, IDX_LNAME, IDX_CITY
- IDX_PWD, IDX_DATE, IDX_PRIV, IDX_CALL, IDX_DNLD
- IDX_UPLD, IDX_PHONE.
-
- RETURN VALUE
- TRUE on success, FALSE on failure.
-
- ALSO SEE
- BasePack BaseIdx
-
- EXAMPLE
- main ()
- {
- int rec=1;
-
- if (BaseOpen ("USER.BBS")) { // Open the user file
- BaseSort (IDX_LNAME); // Sort by last name
- while (BaseRead (rec++)) { // For all records
- printf ("%s\n",USRname); // Display names
- }
- BaseClose (); // Close the user file
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseVideoStr
-
- DESCRIPTION
- Return character string description of Maximus user record video
- setting.
-
- SYNOPSIS
- BaseVideoStr (char video_setting)
-
- INPUTS
- video_setting - Maximus user record video value.
-
- RETURN VALUE
- Video setting string.
-
- ALSO SEE
- BaseHelpStr BasePrivStr BaseKeyStr BaseProtStr BaseXpTypStr
- BaseXpActStr
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- printf("Sysop video setting: %s\n",BaseVideoStr (USRvideo));
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseWrite
-
- DESCRIPTION
- Write a User file record. Applicable only after a successful
- BaseOpen call. BaseWrite copies the user record buffer to the
- specified user record. This overwrites the existing on disk file
- record. BaseWrite is normally always preceeded by a BaseRead
- function call.
-
- SYNOPSIS
- int BaseWrite (int rec)
-
- INPUTS
- rec - Record number to write, range 1 to BaseCount () inclusive.
-
- RETURN VALUE
- TRUE on success, FALSE on failure.
-
- ALSO SEE
- BaseRead BaseOpen BaseClose
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open the user base
- if (BaseRead (1)) { // Read sysop record
- USRcredit = 10000; // Give the sysop some credit
- BaseWrite (1); // Write sysop record
- }
- BaseClose (); // Close the user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseXpActStr
-
- DESCRIPTION
- Returns the string representation of a Maximus user record expiry
- action setting.
-
- SYNOPSIS
- char * BaseXpActStr (char expiry_flag)
-
- INPUTS
- expiry_flag - Maximus user base expiry setting.
-
- RETURN VALUE
- String representatioon of expiry action setting.
-
- ALSO SEE
- BaseHelpStr BaseVideoStr BasePrivStr BaseKeyStr BaseProtStr
- BaseXpTypStr
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- printf("Sysop expiry action: %s\n",BaseXpActStr (USRxpflag));
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- BaseXpTypStr
-
- DESCRIPTION
- Returns the string representation of a Maximus user record expiry
- type setting.
-
- SYNOPSIS
- char * BaseXpTypStr (char expiry_flag)
-
- INPUTS
- expiry_flag - Maximus user base expiry setting.
-
- RETURN VALUE
- String representatioon of expiry type setting.
-
- ALSO SEE
- BaseHelpStr BaseVideoStr BasePrivStr BaseKeyStr BaseProtStr
- BaseXpActStr
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
- printf("Sysop expiry type: %s\n",BaseXpTypStr (USRxpflag));
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- DateToStr
-
- DESCRIPTION
- Returns string representation of the date parameter.
-
- SYNOPSIS
- char * DateToStr (int date)
- INPUTS
- date - integer date value.
-
- RETURN VALUE
- String representation of an integer date value.
-
- ALSO SEE
- TimeToStr USRludate SysDate SysTime
-
- EXAMPLE
- main ()
- {
- int date;
-
- date = SysDate ();
- printf ("Today's date: %s\n",DateToStr (date));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- exit
-
- DESCRIPTION
- Exit the MUL script, return to the operating system.
-
- SYNOPSIS
- void exit (int return_value)
-
- INPUTS
- return_value - Value to return to the operating system.
-
- RETURN VALUE
- None
-
- ALSO SEE
- return
-
- EXAMPLE
- main ()
- {
- int i = 42;
-
- printf ("Exiting to the operating system with a value of %d\n",i);
- exit (i);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fclose
-
- DESCRIPTION
- Close a disk file.
-
- SYNOPSIS
- int fclose (long file_handle)
-
- INPUTS
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- zero on success, TRUE on failure.
-
- ALSO SEE
- fopen
-
- EXAMPLE
- main ()
- {
- long fp;
-
- fp = fopen ("TEST.TMP","w"); // Open a disk file
- if (fp!=NULL) {
- // Write some text to the file
- fprintf (fp,"I'll buy that for a doller!\n");
- fclose (fp); // Close the disk file
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- feof
-
- DESCRIPTION
- Returns end of file status.
-
- SYNOPSIS
- int feof (long file_handle)
-
- INPUTS
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- TRUE for end of file reached, else zero.
-
- ALSO SEE
- ferror fopen fclose
-
- EXAMPLE
- main ()
- {
- long fp;
- char line[132];
-
- fp = fopen ("MULFNREF.DOC","r"); // Open a disk file
- if (fp!=NULL) {
- while (!feof (fp)) {
- // Read and display text line
- if (fgets (line,132,fp)) puts (line);
- }
- fclose (fp); // Close the disk file
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- ferror
-
- DESCRIPTION
- Check for error on the given file.
-
- SYNOPSIS
- int ferror (long file_handle)
-
- INPUTS
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- TRUE for an error condition, zero for no error.
-
- ALSO SEE
- feof fopen fclose
-
- EXAMPLE
- main ()
- {
- long fp;
- char line[132];
-
- fp = fopen ("MULFNREF.DOC","r"); // Open a disk file
- if (fp!=NULL) {
- // Read and display text lines
- while (!feof (fp)) if (fgets (line,132,fp)) puts (line);
-
- if (ferror (fp)) printf("File error encountered!\n");
- fclose (fp); // Close the disk file
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fgetc
-
- DESCRIPTION
- Read a character from a file.
-
- SYNOPSIS
- int fgetc (long file_handle)
-
- INPUTS
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- The character read, or -1 on error.
-
- ALSO SEE
- fgets fread fopen fclose
-
- EXAMPLE
- main ()
- {
- long fp;
- char ch;
-
- fp = fopen ("MULFNREF.DOC","r"); // Open a disk file
- if (fp!=NULL) {
- while (!feof (fp)) {
- ch = fgetc (fp);
- if (ch != -1) putch (ch);
- }
- fclose (fp); // Close the disk file
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fgets
-
- DESCRIPTION
- Reads up to number-1 characters from a file. Characters are read
- until either a newline or the end of file is received, or until
- the specified limit is reached.
-
- SYNOPSIS
- char * fgets (char * str, int number, long file_handle)
-
- INPUTS
- str - Character array received characters are placed into.
- number - Maximum number of characters to receive.
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- str is returned on success, or NULL on failure.
-
- ALSO SEE
- fgetc fread fopen fclose
-
- EXAMPLE
- main ()
- {
- long fp;
- char line[132];
-
- fp = fopen ("MULFNREF.DOC","r"); // Open a disk file
- if (fp!=NULL) {
- // Read and display text lines
- while (!feof (fp)) {
- if (fgets (line,132,fp)) puts (line);
- }
- fclose (fp); // Close the disk file
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fopen
-
- DESCRIPTION
- Open a disk file.
-
- SYNOPSIS
- long fopen (char *fname, char *mode)
-
- INPUTS
- fname - File path and name.
- mode - Access mode.
-
- Mode Meaning
- "r" Open text file for reading
- "w" Create a text file for writing
- "a" Append to text file
- "rb" Open binary file for reading
- "wb" Create binary file for writing
- "ab" Append to a binary file
- "r+" Open text file for read/write
- "w+" Create text file for read/write
- "a+" Open text file for read/write
- "r+b" Open binary file for read/write
- "w+b" Create binary file for read/write
- "a+b" Open binary file for read/write
-
- RETURN VALUE
- The file handle, or NULL on failure.
-
- ALSO SEE
- fclose
-
- EXAMPLE
- main ()
- {
- long fp;
- char line[132];
-
- fp = fopen ("MULFNREF.DOC","r"); // Open a disk file
- if (fp!=NULL) {
- // Read and display text lines
- while (!feof (fp)) if (fgets (line,132,fp)) puts (line);
-
- fclose (fp); // Close the disk file
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fprintf
-
- DESCRIPTION
- Formated print to file.
-
- SYNOPSIS
- int fprintf (long file_handle, char *format_string, ... )
-
- INPUTS
- file_handle - The file handle returned by fopen.
- format_string - Format character string.
- ... - Variable number of additional parameters.
-
- Format type Meaning
- ----------- -------
- %d - display an integer as a signed decimal string
- %u - display an integer as an unsigned decimal string
- %x - display an integer as a hexidecimal string
- %o - display an integer as an octal string
- %b - display an integer as a binary string
- %c - display a character
- %s - display a character string
-
- Format modifiers
- ----------------
- - - left justify e.g. %-10s
- digits - numeric field width. e.g. %10s
- l - long value. e.g. %ld
-
- Note that all MUL function calls have a maximum parameter count
- of sixteen values.
-
- Escape sequences
- ----------------
- \n - newline character
- \t - tab character
- \f - formfeed character
- \a - bell character
- \b - backspace character
- \r - return character
- \0 - null character
- \? - all other values print the literal character.
- e.g. \" \' \\
-
- RETURN VALUE
- Number of characters written.
-
- ALSO SEE
- printf sprintf
-
- EXAMPLE
- main ()
- {
- int i = 42;
- long fp;
-
- fp = fopen ("TEST.TMP","w"); // Open a disk file
- if (fp==NULL) exit (1); // If fopen failed, exit
-
- // Write to the file
- fprintf (fp,"The answer is %d\n",i);
-
- fclose (fp); // Close the disk file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fputc
-
- DESCRIPTION
- Write the specified character to a file.
-
- SYNOPSIS
- int fputc (int ch, long file_handle)
-
- INPUTS
- ch - The character to write.
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- The character written, or -1 on error.
-
- ALSO SEE
- fputs fwrite
-
- EXAMPLE
- main ()
- {
- long fp;
-
- fp = fopen ("TEST.TMP","w"); // Open a disk file
- if (fp==NULL) exit (1); // If fopen failed, exit
- fputc ('B',fp); // Write a character to the file
- fclose (fp); // Close the disk file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fputs
-
- DESCRIPTION
- Write the specified character string to a file. The null terminator
- is not written.
-
- SYNOPSIS
- int fputs (char * str, long file_handle)
-
- INPUTS
- str - The character string to write.
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- The last character written, or -1 on error.
-
- ALSO SEE
- fputc fwrite
-
- EXAMPLE
- main ()
- {
- long fp;
-
- fp = fopen ("TEST.TMP","w"); // Open a disk file
- if (fp==NULL) exit (1); // If fopen failed, exit
- fputs ("Blueberry Muffin",fp); // Write the string to the file
- fclose (fp); // Close the disk file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fread
-
- DESCRIPTION
- Read count number of objects from a file.
-
- SYNOPSIS
- int fread (char * buf, int size, int count, long file_handle)
-
- INPUTS
- buf - Buffer to place the read data.
- size - Size of each object.
- count - Number of objects.
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- The number of items actually read.
-
- ALSO SEE
- fgetc fgets fwrite
-
- EXAMPLE
- main ()
- {
- long fp;
- int count;
- char buf[4096];
-
- fp = fopen ("MULFNREF.DOC","rb"); // Open a disk file for binary read
- if (fp==NULL) exit (1); // If fopen failed, exit
-
- do {
- count = fread (buf,1,4096,fp); // Read a data block
-
- fwrite (buf,1,count,stdout); // Display block to console
- } while (count); // While characters are read
-
- fclose (fp); // Close the disk file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- free
-
- DESCRIPTION
- Deallocate a memory block allocated with malloc.
-
- SYNOPSIS
- void free (char *ptr)
-
- INPUTS
- ptr - The pointer to the memory block.
-
- RETURN VALUE
- None
-
- ALSO SEE
- malloc
-
- EXAMPLE
- main ()
- {
- char *ptr; // Declare a character pointer
-
- ptr = malloc (256); // Allocate some storage
- if(ptr == NULL) exit (); // Abort if allocation failed
-
- strcpy (ptr,"This Product Warps Space and Time in Its Vicinity.");
- printf ("%s\n",ptr);
-
- free (ptr); // Free the storage
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fseek
-
- DESCRIPTION
- Moved the file position indicator for a file.
-
- SYNOPSIS
- int fseek (long file_handle, long offset, int origin)
-
- INPUTS
- file_handle - The file handle returned by fopen.
- offset - The number of bytes from origin to make the new position.
- origin - 0 = file start, 1 = current position, or 2 = end of file.
-
- RETURN VALUE
- Zero on success, non-zero on error.
-
- ALSO SEE
- ftell fread fwrite
-
- EXAMPLE
- main ()
- {
- long fp;
- int count;
- char buf[256];
-
- fp = fopen ("MULFNREF.DOC","rb"); // Open a disk file for binary read
- if (fp==NULL) exit (1); // If fopen failed, exit
-
- fseek (fp,4096,0); // Move forward in the file
- count = fread (buf,1,256,fp); // Read a data block
- fwrite (buf,1,count,stdout); // Display block to console
- putch ('\n'); // Display newline character
- fclose (fp); // Close the disk file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- ftell
-
- DESCRIPTION
- Return the current position of the file position indicator.
-
- SYNOPSIS
- long ftell (long file_handle)
-
- INPUTS
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- The current file position, or -1 on error.
-
- ALSO SEE
- fseek
-
- EXAMPLE
- main ()
- {
- long fp, pos;
-
- fp = fopen ("MULFNREF.DOC","rb"); // Open a disk file for binary read
- if (fp==NULL) exit (1); // If fopen failed, exit
-
- fseek (fp,4096,0); // Move forward in the file
-
- pos = ftell (fp);
- printf ("File position: %ld\n",pos);
-
- fclose (fp); // Close the disk file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- fwrite
-
- DESCRIPTION
- Write count number of objects to a file.
-
- SYNOPSIS
- int fwrite (char * buf, int size, int count, long file_handle)
-
- INPUTS
- buf - Buffer containing objects to write.
- size - Size of each object.
- count - Number of objects.
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- The number of items actually written.
-
- ALSO SEE
- fread fgetc fgets
-
- EXAMPLE
- main ()
- {
- long fp;
- char *buf = "Maximus-CBCS\r\n";
-
- fp = fopen ("TEST.TMP","wb"); // Open a disk file for binary write
- if (fp==NULL) exit (1); // If fopen failed, exit
-
- fwrite (buf,14,1,fp); // Write the data block
-
- fclose (fp); // Close the disk file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- GenDate
-
- DESCRIPTION
- Returns integer date version of date plus mths.
-
- SYNOPSIS
- int GenDate (int date, int mths)
-
- INPUTS
- date - Integer date, as returned by SysDate or USRludate.
- mths - Number of months for the addition.
-
- RETURN VALUE
- Integer date.
-
- ALSO SEE
- SysDate DateToStr GenTime
-
- EXAMPLE
- main ()
- {
- int date, newdate, advance;
-
- advance = 6;
- date = SysDate (); // Get the system date
-
- newdate = GenDate (date,advance);
-
- printf ("The date %d months from now: %s\n",
- advance,DateToStr (newdate));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- GenTime
-
- DESCRIPTION
- Returns integer time version of parameter time plus parameter mins.
-
- SYNOPSIS
- int GenTime (int time, int mins)
-
- INPUTS
- time - Integer time, as returned by SysTime or USRlutime.
- mins - Number of minutes for the addition.
-
- RETURN VALUE
- Integer time.
-
- ALSO SEE
- SysTime TimeToStr GenDate
-
- EXAMPLE
- main ()
- {
- int time, newtime, advance;
-
- advance = 30;
- time = SysTime (); // Get the system time
-
- newtime = GenTime (time,advance);
-
- printf ("The time %d minutes from now: %s\n",
- advance,TimeToStr (newtime));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- getch
-
- DESCRIPTION
- Get a character from the console, wait for character, no echo.
- Includes time slice release when operating under DESQview.
-
- SYNOPSIS
- int getch (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The console character.
-
- ALSO SEE
- getche getxch
-
- EXAMPLE
- main ()
- {
- int ch;
-
- puts ("Hit a key.. "); // Prompt
- ch = getch (); // Get a character
-
- printf ("\nKey code %d was hit\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- getche
-
- DESCRIPTION
- Get a character from the console, wait for character, with echo.
- Includes time slice release when operating under DESQview.
-
- SYNOPSIS
- int getche (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The console character.
-
- ALSO SEE
- getch getxch
-
- EXAMPLE
- main ()
- {
- int ch;
-
- puts ("Hit a key.. "); // Prompt
- ch = getche (); // Get a character
-
- printf ("\nKey code %d was hit\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- getns
-
- DESCRIPTION
- Read console string with maximum characters limit. Includes
- backspace support, return exits, ECS aborts. Includes time
- slice release when operating under DESQview.
-
- SYNOPSIS
- int getns (char *str, int maxchars)
-
- INPUTS
- str - Buffer into which to place the received characters.
- maxchars - Maximum characters limit.
-
- RETURN VALUE
- Zero on success, non-zero if ESC pressed.
-
- ALSO SEE
- getxch getch
-
- EXAMPLE
- main ()
- {
- char buf[40];
-
- puts ("Enter your name-------------------|\n"); // Prompt
- getns (buf,35); // Get the string
-
- printf ("\n\nHi %s\n",buf);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- getxch
-
- DESCRIPTION
- Get an extended character code from the console, wait for character,
- no echo. Includes time slice release when operating under DESQview.
-
- SYNOPSIS
- int getxch (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The extended console character.
-
- ALSO SEE
- getch getche
-
- EXAMPLE
- main ()
- {
- int ch;
-
- puts ("Hit a key.. "); // Prompt
- ch = getxch (); // Get a character
-
- printf ("\nKey code %4x was hit\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Hidecur
-
- DESCRIPTION
- Hide the console cursor.
-
- SYNOPSIS
- void Hidecur (void)
- INPUTS
- None
-
- RETURN VALUE
- None
-
- ALSO SEE
- Showcur
-
- EXAMPLE
- main ()
- {
- Hidecur ();
-
- puts ("Cursor hidden, press as key.. ");
- getxch ();
-
- Showcur ();
-
- puts ("\nCursor restored.\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Invert
-
- DESCRIPTION
- Bitwise inversion.
-
- SYNOPSIS
- long Invert (long value)
-
- INPUTS
- value - Value to invert.
-
- RETURN VALUE
- Inverted value.
-
- ALSO SEE
- And Or Xor
-
- EXAMPLE
- main ()
- {
- int value = 42;
-
- printf ("Value in binary = %016b\n",value);
-
- value = Invert (value); // Invert the value
- printf ("Inverted value = %016b\n",value);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isalnum
-
- DESCRIPTION
- Tests if a character is either a letter of the alphabet or a digit.
-
- SYNOPSIS
- int isalnum (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalpha isascii iscntrl isdigit isgraph islower isprint
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isalnum (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isalpha
-
- DESCRIPTION
- Tests if a character is a letter of the alphabet.
-
- SYNOPSIS
- int isalpha (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isascii iscntrl isdigit isgraph islower isprint
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isalpha (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isascii
-
- DESCRIPTION
- Tests if a character is an ascii character (less than or equal to 127).
-
- SYNOPSIS
- int isascii (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha iscntrl isdigit isgraph islower isprint
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isascii (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- iscntrl
-
- DESCRIPTION
- Tests if a character is a control character.
-
- SYNOPSIS
- int iscntrl (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii isdigit isgraph islower isprint
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (iscntrl (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isdigit
-
- DESCRIPTION
- Tests if a character is a digit (0 - 9).
-
- SYNOPSIS
- int isdigit (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isgraph islower isprint
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isdigit (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isgraph
-
- DESCRIPTION
- Tests if a character is a printable character, other than a space.
-
- SYNOPSIS
- int isgraph (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isdigit islower isprint
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isgraph (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- islower
-
- DESCRIPTION
- Tests if a character is a lower case letter.
-
- SYNOPSIS
- int islower (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isdigit isgraph isprint
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (islower (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isprint
-
- DESCRIPTION
- Tests if a character is a printable character, including space.
-
- SYNOPSIS
- int isprint (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isdigit isgraph islower
- ispunct isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isprint (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- ispunct
-
- DESCRIPTION
- Tests if a character is a punctuation character, excluding space.
-
- SYNOPSIS
- int ispunct (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isdigit isgraph islower
- isprint isspace isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (ispunct (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isspace
-
- DESCRIPTION
- Tests if a character is a tab, newline, or space.
-
- SYNOPSIS
- int isspace (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isdigit isgraph islower
- isprint ispunct isupper isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isspace (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isupper
-
- DESCRIPTION
- Tests if a character is an upper case letter.
-
- SYNOPSIS
- int isupper (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isdigit isgraph islower
- isprint ispunct isspace isxdigit
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isupper (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- isxdigit
-
- DESCRIPTION
- Tests if a character is a hexadecimal digit (0 - 9, A - F, or a - f).
-
- SYNOPSIS
- int isxdigit (int ch)
-
- INPUTS
- ch - The character to test.
-
- RETURN VALUE
- Non-zero on success, zero on failure.
-
- ALSO SEE
- isalnum isalpha isascii iscntrl isdigit isgraph islower
- isprint ispunct isspace isupper
-
- EXAMPLE
- main ()
- {
- char ch = 'A';
-
- if (isxdigit (ch)) printf ("Character %c passed\n",ch);
- else printf ("Character %c failed\n",ch);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- itoa
-
- DESCRIPTION
- Convert an integer to a string.
-
- SYNOPSIS
- char * itoa (int num, char *buf, int radix)
-
- INPUTS
- num - Integer to convert.
- buf - Buffer into which to place the output string.
- radix - The base of the output string, range 2 to 36.
-
- RETURN VALUE
- The output string.
-
- ALSO SEE
- ltoa atoi
-
- EXAMPLE
- main ()
- {
- int i = 42;
- char buf[20];
-
- itoa (i,buf,10); // Convert to a base 10 string.
-
- printf ("And the answer is: %s\n",buf);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- kbhit
-
- DESCRIPTION
- Console key hit status.
-
- SYNOPSIS
- int kbhit (void)
-
- INPUTS
- None
-
- RETURN VALUE
- Non-zero if a key press is waiting, else zero.
-
- ALSO SEE
- getch getche getxch
-
- EXAMPLE
- main ()
- {
- printf ("Hit any key to exit .. ");
-
- while (!kbhit ()) ; // Wait for a key press
- getxch (); // Get the key
- putch ('\n'); // Display newline character
- }
-
- ----------------------------------------------------------------------
-
- NAME
- ltoa
-
- DESCRIPTION
- Convert a long to a string.
-
- SYNOPSIS
- char * ltoa (long num, char *buf, int radix)
-
- INPUTS
- num - Long value to convert.
- buf - Buffer into which to place the output string.
- radix - The base of the output string, range 2 to 36.
-
- RETURN VALUE
- The output string.
-
- ALSO SEE
- itoa atol
-
- EXAMPLE
- main ()
- {
- long var = 42;
- char buf[20];
-
- ltoa (var,buf,10); // Convert to a base 10 string.
-
- printf ("And the answer is: %s\n",buf);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- malloc
-
- DESCRIPTION
- Allocate a memory block.
-
- SYNOPSIS
- char * malloc (int size)
-
- INPUTS
- size - The size of the memory bloac to allocate in bytes.
-
- RETURN VALUE
- The address of the memory block, or NULL on error.
-
- ALSO SEE
- free
-
- EXAMPLE
- main ()
- {
- char *ptr; // Declare a character pointer
-
- ptr = malloc (256); // Allocate some storage
- if(ptr == NULL) exit (); // Abort if allocation failed
-
- strcpy (ptr,"This Product Warps Space and Time in Its Vicinity.");
- printf ("%s\n",ptr);
-
- free (ptr); // Free the storage
- }
-
- ----------------------------------------------------------------------
-
- NAME
- NumCols
-
- DESCRIPTION
- Returns the number of display columns on the system console.
-
- SYNOPSIS
- int NumCols (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The width of the video display.
-
- ALSO SEE
- NumRows
-
- EXAMPLE
- main ()
- {
- printf ("Video screen is currently %d x %d\n",NumRows (),NumCols ());
- }
-
- ----------------------------------------------------------------------
-
- NAME
- NumRows
-
- DESCRIPTION
- Returns the number of display rows on the system console.
-
- SYNOPSIS
- int NumRows (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The height of the video display.
-
- ALSO SEE
- NumCols
-
- EXAMPLE
- main ()
- {
- printf ("Video screen is currently %d x %d\n",NumRows (),NumCols ());
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Or
-
- DESCRIPTION
- Returns the bitwise OR of the two arguments. At the bit level,
- that is for each bit in the two arguments, a bitwise OR results
- in "only two zero's make a zero".
-
- SYNOPSIS
- long Or (long arg1, long arg2)
-
- INPUTS
- arg1 - First value.
- arg2 - Second value.
-
- RETURN VALUE
- Value of the bitwise OR.
-
- ALSO SEE
- And Xor Invert ShiftLeft ShiftRight
-
- EXAMPLE
- main ()
- {
- int val = 0;
-
- val = Or (val,0x80); // Turn on bit seven
-
- printf ("val = %u\n",val);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Pause
-
- DESCRIPTION
- Suspends execution for specified duration in timerticks. The usual
- system timer tick rate is 18.2 ticks per second. Includes time slice
- release when operating under DESQview.
-
- SYNOPSIS
- void Pause (int ticks)
-
- INPUTS
- ticks - Pause duration in timer ticks.
-
- RETURN VALUE
- None
-
- ALSO SEE
- Play
-
- EXAMPLE
- main ()
- {
- printf ("Pausing for a second\n");
- Pause (18);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Play
-
- DESCRIPTION
- Plays a tone for a specified frequency and duration. A frequency of
- zero produces no sound for the duration.
-
- SYNOPSIS
- void Play (int hertz, int hsec)
-
- INPUTS
- hertz - Note frequency.
- hsec - Note duration.
-
- RETURN VALUE
- None
-
- ALSO SEE
- Pause
-
- EXAMPLE
- main ()
- {
- // Play the theme From "The Pink Panther"
- Play (271,160); Play (287,330); Play (304,160); Play (322,830);
- Play ( 0, 50); Play (362,160); Play (383,830); Play ( 0, 50);
- Play (304,160); Play (322,330); Play (362,160); Play (383,330);
- Play (512,160); Play (483,330); Play (322,160); Play (383,270);
- Play (483,200); Play (456, 60); Play (512, 60); Play (456, 60);
- Play (512, 60); Play (456, 60); Play (512, 60); Play (456, 60);
- Play (512, 60); Play (456, 60); Play (512, 60); Play (456,570);
- Play (430,140); Play (383,140); Play (322,140); Play (287,140);
- Play (322,770);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- printf
-
- DESCRIPTION
- Formated print to the console.
-
- SYNOPSIS
- int printf (char *format_string, ... )
-
- INPUTS
- format_string - Format character string.
- ... - Variable number of additional parameters.
-
- Format type Meaning
- ----------- -------
- %d - display an integer as a signed decimal string
- %u - display an integer as an unsigned decimal string
- %x - display an integer as a hexidecimal string
- %o - display an integer as an octal string
- %b - display an integer as a binary string
- %c - display a character
- %s - display a character string
-
- Format modifiers
- ----------------
- - - left justify e.g. %-10s
- digits - numeric field width. e.g. %10s
- l - long value. e.g. %ld
-
- Note that all MUL function calls have a maximum parameter count
- of sixteen values.
-
- Escape sequences
- ----------------
- \n - newline character
- \t - tab character
- \f - formfeed character
- \a - bell character
- \b - backspace character
- \r - return character
- \0 - null character
- \? - all other values print the literal character.
- e.g. \" \' \\
-
- RETURN VALUE
- Number of characters written.
-
- ALSO SEE
- fprintf sprintf
-
- EXAMPLE
- main ()
- {
- int i = 42;
- printf ("The answer is %d\n",i);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- putch
-
- DESCRIPTION
- Write a character to the console.
-
- SYNOPSIS
- int putch (char ch)
-
- INPUTS
- ch - The character to write.
-
- RETURN VALUE
- The character written, or -1 on error.
-
- ALSO SEE
- puts printf getch
-
- EXAMPLE
- main ()
- {
- putch ('M'); putch ('U'); putch ('L');
- putch ('\n');
- }
-
- ----------------------------------------------------------------------
-
- NAME
- puts
-
- DESCRIPTION
- Write a character string to the console. The null terminator is not
- written. A slight difference from the standard C language puts
- function is that a newline character is NOT appended to the output.
-
- SYNOPSIS
- int puts (char * str)
-
- INPUTS
- str - The character string to write.
-
- RETURN VALUE
- The last character written, or -1 on error.
-
- ALSO SEE
- putch printf getns
-
- EXAMPLE
- main ()
- {
- puts ("MUL\n"); // Display a string with a newline.
- }
-
- ----------------------------------------------------------------------
-
- NAME
- rand
-
- DESCRIPTION
- Return a pseudo-random number. Range is from 0 to 32767 inclusive.
-
- SYNOPSIS
- int rand (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The random number.
-
- ALSO SEE
- srand
-
- EXAMPLE
- main ()
- {
- int r;
-
- srand (SysTime ()); // Setup the random generator
-
- // Generate a random number between 1 and 10 inclusive
- r = rand () % 10 + 1;
-
- printf ("Today's number is the number %d\n",r);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- remove
-
- DESCRIPTION
- Delete a disk file.
-
- SYNOPSIS
- int remove (char *fname)
-
- INPUTS
- fname - The file path and name to delete.
-
- RETURN VALUE
- Zero on success, -1 on failure.
-
- ALSO SEE
- rename
-
- EXAMPLE
- main ()
- {
- long fp;
- char * fname = "DEL_ME.TMP";
-
- // Create a file to delete
- fp = fopen (fname,"wb"); // Open temporary file
- if (fp == NULL) exit (1); // Abort if fopen failed
- fclose (fp); // Close the file
-
- remove (fname); // Delete the temporary file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- rename
-
- DESCRIPTION
- Rename a disk file.
-
- SYNOPSIS
- int rename (char * oldfname, char * newfname)
-
- INPUTS
- oldfname - Existing file name.
- newfname - New name for the file.
-
- RETURN VALUE
- Zero on success, -1 on failure.
-
- ALSO SEE
- remove
-
- EXAMPLE
- main ()
- {
- long fp;
- char * fname = "DEL_ME.TMP";
-
- // Create a file to rename
- fp = fopen (fname,"wb"); // Open temporary file
- if (fp == NULL) exit (1); // Abort if fopen failed
- fclose (fp); // Close the file
-
- rename (fname,"RENAMED.TMP"); // Rename the temporary file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- reverse
-
- DESCRIPTION
- Reverse a character string in place.
-
- SYNOPSIS
- void reverse (char * str)
-
- INPUTS
- str - The string to reverse.
-
- RETURN VALUE
- None
-
- ALSO SEE
- strcat strcpy strdup strlen
-
- EXAMPLE
- main ()
- {
- long fp;
- char * str = "egaugnaL resU sumixaM ehT";
-
- reverse (str);
- printf("%s\n",str);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- rewind
-
- DESCRIPTION
- Move the file position indicator to the beginning of the file.
-
- SYNOPSIS
- void rewind (long file_handle)
-
- INPUTS
- file_handle - The file handle returned by fopen.
-
- RETURN VALUE
- None
-
- ALSO SEE
- fseek
-
- EXAMPLE
- main ()
- {
- long fp;
- char buf[256];
-
- fp=fopen ("MULFNREF.DOC","rb"); // Open a file
- if (fp == NULL) exit (1); // Abort if fopen failed
- fread (buf,1,256,fp); // Read some data
-
- rewind (fp); // Return to file start
-
- fread (buf,1,256,fp); // Read some more data
- fwrite (buf,1,256,stdout); // Write the data to the console
- putch ('\n'); // Write a newline to the console
- fclose (fp); // Close the file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- ShiftLeft
-
- DESCRIPTION
- Returns the value bitwise shifted left count number of bits.
-
- SYNOPSIS
- long ShiftLeft (long value, int count)
-
- INPUTS
- value - The value to shift left.
- count - The number of shifts to perform.
-
- RETURN VALUE
- The shifted value.
-
- ALSO SEE
- ShiftRight
-
- EXAMPLE
- main ()
- {
- int val = 1;
-
- val = ShiftLeft (val,4); // Shift left 4 bits
-
- printf ("val = %u\n",val);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- ShiftRight
-
- DESCRIPTION
- Returns the value bitwise shifted right count number of bits.
-
- SYNOPSIS
- long ShiftRight (long value, int count)
-
- INPUTS
- value - The value to shift right.
- count - The number of shifts to perform.
-
- RETURN VALUE
- The shifted value.
-
- ALSO SEE
- ShiftLeft
-
- EXAMPLE
- main ()
- {
- int val = 256;
-
- val = ShiftRight (val,1); // Shift right 1 bit
-
- printf ("val = %u\n",val);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Showcur
-
- DESCRIPTION
- Show the console cursor.
-
- SYNOPSIS
- void Showcur (void)
-
- INPUTS
- None
-
- RETURN VALUE
- None
-
- ALSO SEE
- Hidecur
-
- EXAMPLE
- main ()
- {
- Hidecur ();
-
- puts ("Cursor hidden, press as key.. ");
- getxch ();
-
- Showcur ();
-
- puts ("\nCursor restored.\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- sprintf
-
- DESCRIPTION
- Formated print to a character string.
-
- SYNOPSIS
- int sprintf (char *str, char *format_string, ... )
-
- INPUTS
- str - The character string to print to.
- format_string - Format character string.
- ... - Variable number of additional parameters.
-
- Format type Meaning
- ----------- -------
- %d - display an integer as a signed decimal string
- %u - display an integer as an unsigned decimal string
- %x - display an integer as a hexidecimal string
- %o - display an integer as an octal string
- %b - display an integer as a binary string
- %c - display a character
- %s - display a character string
-
- Format modifiers
- ----------------
- - - left justify e.g. %-10s
- digits - numeric field width. e.g. %10s
- l - long value. e.g. %ld
-
- Note that all MUL function calls have a maximum parameter count
- of sixteen values.
-
- Escape sequences
- ----------------
- \n - newline character
- \t - tab character
- \f - formfeed character
- \a - bell character
- \b - backspace character
- \r - return character
- \0 - null character
- \? - all other values print the literal character.
- e.g. \" \' \\
-
- RETURN VALUE
- Number of characters written.
-
- ALSO SEE
- fprintf printf
-
- EXAMPLE
- main ()
- {
- int i = 42;
- char buf[64];
-
- sprintf (buf,"The answer is %d\n",i);
- puts (buf);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- srand
-
- DESCRIPTION
- Set a starting point for the random number generator.
-
- SYNOPSIS
- void srand (int seed)
-
- INPUTS
- seed - The staring value.
-
- RETURN VALUE
- None
-
- ALSO SEE
- rand
-
- EXAMPLE
- main ()
- {
- int r;
-
- srand (SysTime ()); // Setup the random generator
-
- // Generate a random number between 1 and 10 inclusive
- r = rand () % 10 + 1;
-
- printf ("Today's number is the number %d\n",r);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strcat
-
- DESCRIPTION
- Concatenates a copy of str2 to str1 and terminates str1.
-
- SYNOPSIS
- char * strcat (char * str1, char * str2)
-
- INPUTS
- str1 - The string to append to.
- str2 - The string to append.
-
- RETURN VALUE
- str1
-
- ALSO SEE
- strncat
-
- EXAMPLE
- main ()
- {
- char str1[80], str2[80];
-
- strcpy (str1,"This is a ");
- strcpy (str2,"sentance.\n");
-
- strcat (str1,str2);
-
- printf ("%s",str1);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strchr
-
- DESCRIPTION
- Returns the first occurance of ch in string str, NULL if not found.
-
- SYNOPSIS
- char * strchr (char * str, int ch)
-
- INPUTS
- str - The string to search.
- ch - The character to search for.
-
- RETURN VALUE
- Pointer to the found character, or NULL if not found.
-
- ALSO SEE
- strrchr strstr
-
- EXAMPLE
- main ()
- {
- char *p, str[80];
-
- strcpy (str,"This is a sentance.\n");
-
- p = strchr (str,'a');
-
- if (p) printf ("%s",p);
- else printf ("Character not found\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strcmp
-
- DESCRIPTION
- Lexicographically compares two null terminated strings and returns
- an integer based on the outcome.
-
- SYNOPSIS
- int strcmp (char * str1, char * str2)
-
- INPUTS
- str1 - The first string to compare.
- str2 - The second string to compare.
-
- RETURN VALUE
- Less than 0 - str1 is less than str2.
- 0 - str1 equals str2.
- Greater than 0 - str1 is greater than str2.
-
- ALSO SEE
- strncmp
-
- EXAMPLE
- main ()
- {
- int result;
- char str1[80], str2[80];
-
- strcpy (str1,"Green"); strcpy (str2,"Peace");
-
- result = strcmp (str1,str2);
-
- if (result) {
- if (result>0) printf ("str1 is greater than str2\n");
- else printf ("str1 is less than str2\n");
- }
- else printf ("str1 equals str2\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strcpy
-
- DESCRIPTION
- Copies the contents of a null terminated string into a string.
-
- SYNOPSIS
- char * strcpy (char * str1, char * str2)
-
- INPUTS
- str1 - The destination string.
- str2 - The string to be copied.
-
- RETURN VALUE
- str1
-
- ALSO SEE
- strncpy
-
- EXAMPLE
- main ()
- {
- int result;
- char str1[80], str2[80];
-
- strcpy (str1,"Difficult is relative");
-
- strcpy (str2,str1);
-
- printf ("%s\n",str2);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strdup
-
- DESCRIPTION
- Returns a pointer to a duplicate of a string.
-
- SYNOPSIS
- char * strdup (char * str)
-
- INPUTS
- str - The string to duplicate.
-
- RETURN VALUE
- The duplicated string, or NULL on error.
-
- ALSO SEE
- strcpy malloc
-
- EXAMPLE
- main ()
- {
- int result;
- char *p, str[80];
-
- strcpy (str,"Difficult is relative");
-
- p = strdup (str); // Duplicate the string
-
- if (p) {
- printf ("%s\n",p);
- free (p); // Free the storage
- }
- else printf ("strdup failed, out of memory?\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- stricmp
-
- DESCRIPTION
- Lexicographically compare two null terminated strings ignoring
- case and return an integer based on the outcome.
-
- SYNOPSIS
- int stricmp (char * str1, char * str2)
-
- INPUTS
- str1 - The first string to compare.
- str2 - The second string to compare.
-
- RETURN VALUE
- Less than 0 - str1 is less than str2.
- 0 - str1 equals str2.
- Greater than 0 - str1 is greater than str2.
-
- ALSO SEE
- strcmp
-
- EXAMPLE
- main ()
- {
- int result;
- char str1[80], str2[80];
-
- strcpy (str1,"Green"); strcpy (str2,"Peace");
-
- result = stricmp (str1,str2);
-
- if (result) {
- if (result>0) printf ("str1 is greater than str2\n");
- else printf ("str1 is less than str2\n");
- }
- else printf ("str1 equals str2\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strisocc
-
- DESCRIPTION
- Count occurances of one string within another. Ignores case of
- the letters.
-
- SYNOPSIS
- int strisocc (char * str1, char * str2)
- INPUTS
- str1 - String to search for.
- str2 - String to search.
-
- RETURN VALUE
- The number of times str1 occurs within str2.
-
- ALSO SEE
- strcmp
-
- EXAMPLE
- main ()
- {
- int result;
- char str[80];
-
- strcpy (str,"Green Peace");
-
- result = strisocc ("ee",str);
-
- printf ("Occurances: %d\n",result);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strlen
-
- DESCRIPTION
- Returns the length of a null terminated string.
-
- SYNOPSIS
- int strlen (char * str)
-
- INPUTS
- str - The string to measure.
-
- RETURN VALUE
- The length of str.
-
- ALSO SEE
- strcpy
-
- EXAMPLE
- main ()
- {
- int result;
- char str[80];
-
- strcpy (str,"Green Peace");
-
- result = strlen (str);
-
- printf ("Length: %d\n",result);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strncat
-
- DESCRIPTION
- Concatenates up to count characters from str2 to str1. The addition is
- NOT null terminated.
-
- SYNOPSIS
- char * strncat (char * str1, char * str2, int count)
-
- INPUTS
- str1 - The string to append to.
- str2 - The string to append.
- count - Maximum characters to copy.
-
- RETURN VALUE
- str1
-
- ALSO SEE
- strcat
-
- EXAMPLE
- main ()
- {
- int len;
- char str1[80], str2[80];
-
- strcpy (str1,"This is a ");
- strcpy (str2,"sentance.");
-
- len = strlen (str1); // Save original length
- strncat (str1,str2,4); // Append up to 4 characters
- str1[len+4] = '\0'; // Terminate the string with null
-
- printf ("%s\n",str1);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strncmp
-
- DESCRIPTION
- Lexicographically compares two null terminated strings up to
- count characters and returns an integer based on the outcome.
-
- SYNOPSIS
- int strncmp (char * str1, char * str2, int count)
-
- INPUTS
- str1 - The first string to compare.
- str2 - The second string to compare.
- count - Maximum characters to compare.
-
- RETURN VALUE
- Less than 0 - str1 is less than str2.
- 0 - str1 equals str2.
- Greater than 0 - str1 is greater than str2.
-
- ALSO SEE
- strcmp
-
- EXAMPLE
- main ()
- {
- int result;
- char str1[80], str2[80];
-
- strcpy (str1,"Green"); strcpy (str2,"GreenPeace");
-
- result = strncmp (str1,str2,4);
-
- if (result) {
- if (result>0) printf ("str1 is greater than str2\n");
- else printf ("str1 is less than str2\n");
- }
- else printf ("str1 equals str2\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strncpy
-
- DESCRIPTION
- Copies up to count characters from null terminated string str1 to str2.
-
- SYNOPSIS
- char * strncpy (char * str1, char * str2, int count)
-
- INPUTS
- str1 - The destination string.
- str2 - The string to be copied.
- count - Maximum characters to copy.
-
- RETURN VALUE
- str1
-
- ALSO SEE
- strcpy
-
- EXAMPLE
- main ()
- {
- int result;
- char str1[80], str2[80];
-
- strcpy (str1,"Difficult is relative");
-
- strncpy (str2,str1,9); // Copy 9 characters
- str2[9] = '\0'; // Terminate the string with null
-
- printf ("%s\n",str2);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strnicmp
-
- DESCRIPTION
- Lexicographically compare two null terminated strings up to
- count characters ignoring case and return an integer based
- on the outcome.
-
- SYNOPSIS
- int strnicmp (char * str1, char * str2, int count)
-
- INPUTS
- str1 - The first string to compare.
- str2 - The second string to compare.
- count - Maximum characters to compare.
-
- RETURN VALUE
- Less than 0 - str1 is less than str2.
- 0 - str1 equals str2.
- Greater than 0 - str1 is greater than str2.
-
- ALSO SEE
- strcmp
-
- EXAMPLE
- main ()
- {
- int result;
- char str1[80], str2[80];
-
- strcpy (str1,"Green"); strcpy (str2,"greenpeace");
-
- result = strnicmp (str1,str2,4);
-
- if (result) {
- if (result>0) printf ("str1 is greater than str2\n");
- else printf ("str1 is less than str2\n");
- }
- else printf ("str1 equals str2\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strrchr
-
- DESCRIPTION
- Returns the last occurance of ch in string str, NULL if not found.
-
- SYNOPSIS
- char * strrchr (char * str, int ch)
-
- INPUTS
- str - The string to search.
- ch - The character to search for.
-
- RETURN VALUE
- Pointer to the character, or NULL if not found.
-
- ALSO SEE
- strchr strstr
-
- EXAMPLE
- main ()
- {
- char *p, str[80];
-
- strcpy (str,"This is a sentance.\n");
-
- p = strrchr (str,'a');
-
- if (p) printf ("%s",p);
- else printf ("Character not found\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strstr
-
- DESCRIPTION
- Returns the first occurance of str2 in string str1, NULL if not found.
- This is a case sensitive search, see strisocc for a similar
- non-case sensitive function.
-
- SYNOPSIS
- char * strstr (char * str1, char * str2)
-
- INPUTS
- str1 - The string to search.
- str2 - The string to search for.
-
- RETURN VALUE
- The found string, or NULL if not found.
-
- ALSO SEE
- strchr strrchr strisocc
-
- EXAMPLE
- main ()
- {
- char *p, str[80];
-
- strcpy (str,"Green Peace");
-
- p = strstr (str,"ee");
-
- if (p) printf ("Found: %s\n",p);
- else printf ("String not found\n");
- }
-
- ----------------------------------------------------------------------
-
- NAME
- StrToDate
-
- DESCRIPTION
- Returns the integer date version of a character string.
-
- SYNOPSIS
- int StrToDate (char * date)
-
- INPUTS
- date - The date string to convert to integer format.
-
- RETURN VALUE
- The integer form of the string date.
-
- ALSO SEE
- DateToStr
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
-
- // Set sysop last call date to 01-01-80
- USRludate = StrToDate ("01-01-80");
-
- BaseWrite (1); // Write the sysop record
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- strtok
-
- DESCRIPTION
- Returns a pointer to the next token in string str1. The characters
- contained in str2 are the delimiters that determine the token. A
- NULL pointer is returned when there is no token to return. The first
- time strtok is used str1 is actually used in the call. Subsequent
- calls use a null pointer for the first argument. In this way the
- entire string can be reduced to tokens. strtok DOES modify the
- string pointed to by str1. Each time strtok is called a null is
- placed where the delimiter was found.
-
- SYNOPSIS
- char * strtok (char * str1, char * str2)
-
- INPUTS
- str1 - Token source string.
- str2 - Delimiter string.
-
- RETURN VALUE
- The next token, or NULL if none available.
-
- ALSO SEE
- strstr
-
- EXAMPLE
- main ()
- {
- char *p, str[80];
-
- strcpy (str,"This is a text string.");
-
- if ((p = strtok (str," \t\n\r")) != NULL) {
- do {
- printf ("Token: %s\n",p);
- } while ((p = strtok (NULL," \t\n\r")) != NULL);
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- StrToTime
-
- DESCRIPTION
- Returns the integer time version of a character string.
-
- SYNOPSIS
- int StrToTime (char * date)
-
- INPUTS
- date - The time string to convert to integer format.
-
- RETURN VALUE
- The integer form of the string time.
-
- ALSO SEE
- TimeToStr
-
- EXAMPLE
- main ()
- {
- if (BaseOpen ("USER.BBS")) { // Open user base
- BaseRead (1); // Read sysop record
-
- // Set sysop last call time to 00:00:00
- USRlutime = StrToTime ("00:00:00");
-
- BaseWrite (1); // Write the sysop record
- BaseClose (); // Close user base
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- SysDate
-
- DESCRIPTION
- Return the integer form of the current system date.
-
- SYNOPSIS
- int SysDate (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The integer system date.
-
- ALSO SEE
- SysTime DateToStr
-
- EXAMPLE
- main ()
- {
- int date;
-
- date = SysDate ();
- printf ("Today's date: %s\n",DateToStr (date));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- SysLog
-
- DESCRIPTION
- Write a system log entry. The Maximus / Binkley / Opus log format
- is used. If logfile exists str is appended, else the file is
- created.
-
- SYNOPSIS
- int SysLog (char * logfile, char * str)
-
- INPUTS
- logfile - The log file path and name.
- str - The character string to log.
-
- RETURN VALUE
- Zero on failure, non-zero on success.
-
- ALSO SEE
-
- EXAMPLE
- main ()
- {
- SysLog ("TEMP.LOG","Run begin"); // Post a log entry
- }
-
- ----------------------------------------------------------------------
-
- NAME
- system
-
- DESCRIPTION
- Execute a system command. Standard output from the command is
- redirected to nul.
-
- SYNOPSIS
- void system (char *cmd)
-
- INPUTS
- cmd - The command to execute.
-
- RETURN VALUE
- None
-
- ALSO SEE
-
- EXAMPLE
- main ()
- {
- long fp;
-
- // Create a temporary file
- fp = fopen ("TEMP.TMP","wb");
- if (fp == NULL) exit (1);
- fclose (fp);
-
- system ("del TEMP.TMP"); // Delete the file
- }
-
- ----------------------------------------------------------------------
-
- NAME
- SysTime
-
- DESCRIPTION
- Return the integer form of the current system time.
-
- SYNOPSIS
- int SysTime (void)
-
- INPUTS
- None
-
- RETURN VALUE
- The integer system time.
-
- ALSO SEE
- SysDate TimeToStr
-
- EXAMPLE
- main ()
- {
- int time;
-
- time = SysTime ();
- printf ("Current time: %s\n",TimeToStr (time));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- TimeToStr
-
- DESCRIPTION
- Returns string representation of the integer time parameter.
-
- SYNOPSIS
- char * TimeToStr (int time)
- INPUTS
- time - integer time value.
-
- RETURN VALUE
- String representation of an integer time value.
-
- ALSO SEE
- DateToStr USRlutime SysTime SysDate
-
- EXAMPLE
- main ()
- {
- int time;
-
- time = SysTime ();
- printf ("Current time: %s\n",TimeToStr (time));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- tolower
-
- DESCRIPTION
- Returns the lower case equivalent of ch if ch is a character, else
- ch is returned.
-
- SYNOPSIS
- int tolower (int ch)
-
- INPUTS
- ch - The character to convert to lower caser.
-
- RETURN VALUE
- The lower case equivalent of the character.
-
- ALSO SEE
- toupper
-
- EXAMPLE
- main ()
- {
- int ch = 'C';
-
- printf ("%c\n",tolower (ch));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- toupper
-
- DESCRIPTION
- Returns the upper case equivalent of ch if ch is a character, else
- ch is returned.
-
- SYNOPSIS
- int toupper (int ch)
-
- INPUTS
- ch - The character to convert to upper caser.
-
- RETURN VALUE
- The upper case equivalent of the character.
-
- ALSO SEE
- tolower
-
- EXAMPLE
- main ()
- {
- int ch = 'c';
-
- printf ("%c\n",toupper (ch));
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wclose
-
- DESCRIPTION
- Close a screen window.
-
- SYNOPSIS
- int Wclose (void)
-
- INPUTS
- None
-
- RETURN VALUE
- Zero on success, non-zero on error.
-
- ALSO SEE
- Wopen
-
- EXAMPLE
- main ()
- {
- int colour = Attr (WHITE,BLUE);
-
- if (Wopen (16,21,20,59,0,colour,colour)) {
- Wxyputs (1,1,colour," Press any key to continue ..");
- Hidecur (); // Hide the cursor
- while (!kbhit()) ; // Wait until key hit
- getch (); // Clear the key
- Wclose (); // Close the window
- Showcur (); // Show the cursor
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wfillch
-
- DESCRIPTION
- Specifies the character the windowing system will fill windows with.
- The default is the space character.
-
- SYNOPSIS
- void Wfillch (int ch)
-
- INPUTS
- ch - The fill character.
-
- RETURN VALUE
- None
-
- ALSO SEE
- Wopen
-
- EXAMPLE
- main ()
- {
- int colour = Attr (WHITE,CYAN);
-
- Wfillch (0xB0); // Set a graphics fill character
- if (Wopen (0,0,24,79,0,colour,colour)) {
- Hidecur (); // Hide the cursor
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- Showcur (); // Show the cursor
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wgotoxy
-
- DESCRIPTION
- Sets cursor coordinates within the active window.
-
- SYNOPSIS
- int Wgotoxy (int wrow, int wcol)
-
- INPUTS
- wrow - Window row (Y coordinate).
- wcol - Window column (X coordinate).
-
- RETURN VALUE
- Zero on no error, non-zero on error.
-
- ALSO SEE
-
- EXAMPLE
- main ()
- {
- int colour = Attr (WHITE,MAGENTA);
-
- if (Wopen (0,0,24,79,1,Attr (YELLOW,MAGENTA),colour)) {
- Hidecur (); // Hide the cursor
- Wgotoxy (11,21);
- Wputs ("Welcome to the Maximus User Language");
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- Showcur (); // Show the cursor
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Whline
-
- DESCRIPTION
- "Draws" a horizontal text line in active window using characters
- defined by given box type. If horizontal line crosses a vertical
- line of the same box type, an appropriate intersection or corner
- will be used.
-
- SYNOPSIS
- int whline (int wsrow, int wscol, int count, int btype, int attr)
-
- INPUTS
- wsrow - Window start row.
- wscol - Window start column.
- count - Number of line characters to display.
- btype - Box type. Can be one of the following:
- 0 - single line
- 1 - double line
- 2 - single horz, double vert line
- 3 - double horz, single vert line
- 4 - thick line
- 5 - uses spaces for line chars
- attr - Text attribute to use for the line.
-
- RETURN VALUE
- Zero on no error, non-zero on error.
-
- ALSO SEE
- Wvline
-
- EXAMPLE
- main ()
- {
- int colour = Attr (YELLOW,BROWN);
-
- if (Wopen (0,0,24,79,3,colour,Attr (WHITE,BROWN))) {
- Hidecur (); // Hide the cursor
- Whline (10,0,79,3,colour);
- Wgotoxy (11,21);
- Wputs ("Welcome to the Maximus User Language");
- Whline (12,0,79,3,colour);
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- Showcur (); // Show the cursor
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wopen
-
- DESCRIPTION
- Opens a screen window and makes it active. The cursor location will
- be initialized to window row 0, column 0. The text attribute will be
- initialized to the same attribute as the window. You can open as
- many windows as memory permits.
-
- SYNOPSIS
- int wopen (int srow, int scol, int erow, int ecol, int btype,
- int battr, int wattr)
-
- INPUTS
- srow - Starting row.
- scol - Starting column.
- erow - Ending row.
- ecol - Ending column.
- btype - Box type. Can be one of the following:
- 0 - single line border
- 1 - double line border
- 2 - single horz, double vert line border
- 3 - double horz, single vert line border
- 4 - thick line border
- 5 - no border (uses spaces for border chars). A
- borderless window has a greater effective window
- area than a window with a border.
- battr - Attribute of window's border.
- wattr - Attribute of window (and initially the text).
-
- RETURN VALUE
- Non-zero on success, zero on error.
-
- ALSO SEE
- Wclose
-
- EXAMPLE
- main ()
- {
- int i, colour, fc, bc, srow, scol, erow, ecol;
-
- srand (SysTime ()); // Setup the random generator
- Hidecur (); // Hide the cursor
-
- for (i=0;i<100;++i) { // Open 100 windows
- srow = rand () % 23;
- erow = rand () % (23 - srow) + srow + 2;
- scol = rand () % 78;
- ecol = rand () % (78 - scol) + scol + 2;
- fc = rand () % 16; bc = rand () % 7;
- if (fc == bc) { fc = WHITE; bc = BLUE; }
- colour = Attr (fc,bc);
- if (!Wopen (srow,scol,erow,ecol,0,colour,colour)) break;
- }
-
- Pause (54); // Wait for 3 seconds
-
- for (;i>0;--i) Wclose (); // Close the windows
- Showcur (); // Show the cursor
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wprintf
-
- DESCRIPTION
- Formated print to the active window.
-
- SYNOPSIS
- int Wprintf (char *format_string, ... )
-
- INPUTS
- format_string - Format character string.
- ... - Variable number of additional parameters.
-
- Format type Meaning
- ----------- -------
- %d - display an integer as a signed decimal string
- %u - display an integer as an unsigned decimal string
- %x - display an integer as a hexidecimal string
- %o - display an integer as an octal string
- %b - display an integer as a binary string
- %c - display a character
- %s - display a character string
-
- Format modifiers
- ----------------
- - - left justify e.g. %-10s
- digits - numeric field width. e.g. %10s
- l - long value. e.g. %ld
-
- Note that all MUL function calls have a maximum parameter count
- of sixteen values.
-
- Escape sequences
- ----------------
- \n - newline character
- \t - tab character
- \f - formfeed character
- \a - bell character
- \b - backspace character
- \r - return character
- \0 - null character
- \? - all other values print the literal character.
- e.g. \" \' \\
-
- RETURN VALUE
- Number of characters written.
-
- ALSO SEE
- printf fprintf sprintf
-
- EXAMPLE
- main ()
- {
- int i = 42, colour = Attr (BLACK,LGREY);
-
- if (Wopen (0,0,24,79,3,colour,colour)) {
- Wprintf ("The answer is %d",i);
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wputch
-
- DESCRIPTION
- Display a character in the active window at the current cursor
- position.
-
- SYNOPSIS
- int Wputch (int ch)
-
- INPUTS
- ch - The character to be displayed.
-
- RETURN VALUE
- Zero on success, non-zero on error.
-
- ALSO SEE
- Wputs Wprintf
-
- EXAMPLE
- main ()
- {
- int colour = Attr (BLUE,LGREY);
-
- if (Wopen (0,0,24,79,3,colour,colour)) {
- Wputch ('M');
- Wputch ('U');
- Wputch ('L');
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wputs
-
- DESCRIPTION
- Display a string in the active window at the current cursor
- location.
-
- SYNOPSIS
- int Wputs (char * str)
-
- INPUTS
- str - The string to display.
-
- RETURN VALUE
- Zero on success, non-zero on error.
-
- ALSO SEE
- Wputch Wprintf
-
- EXAMPLE
- main ()
- {
- int colour = Attr (RED,LGREY);
-
- if (Wopen (0,0,24,79,3,colour,colour)) {
- Wputs ("MUL");
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wshadow
-
- DESCRIPTION
- Add a shadow to the active window. The Wclose function will
- automatically remove the shadow when the window is closed.
-
- SYNOPSIS
- int Wshadow (int attr)
-
- INPUTS
- attr - The attribute to use for the shadow. (LGREY,BLACK) is
- the usual attribute used.
-
- RETURN VALUE
- Zero on success, non-zero on error.
-
- ALSO SEE
-
- EXAMPLE
- main ()
- {
- int colour1 = Attr (RED,LGREY);
- int colour2 = Attr (WHITE,BLUE);
-
- Hidecur (); // Hide the cursor
-
- // Open a background window
- if (Wopen (0,0,24,79,3,colour1,colour1)) {
-
- // Open a window to shadow
- if (Wopen (16,21,20,59,0,colour2,colour2)) {
- Wshadow (Attr (LGREY,BLACK));
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- }
-
- Wclose (); // Close the background window
- }
-
- Showcur (); // Show the cursor
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wvline
-
- DESCRIPTION
- "Draws" a vertical text line in active window using characters
- defined by given box type. If vertical line crosses a horizontal
- line of the same box type, an appropriate intersection or corner
- will be used.
-
- SYNOPSIS
- int wvline (int wsrow, int wscol, int count, int btype, int attr)
-
- INPUTS
- wsrow - Window start row.
- wscol - Window start column.
- count - Number of line characters to display.
- btype - Box type. Can be one of the following:
- 0 - single line
- 1 - double line
- 2 - single horz, double vert line
- 3 - double horz, single vert line
- 4 - thick line
- 5 - uses spaces for line chars
- attr - Text attribute to use for the line.
-
- RETURN VALUE
- Zero on no error, non-zero on error.
-
- ALSO SEE
- Whline
-
- EXAMPLE
- main ()
- {
- int colour = Attr (YELLOW,BROWN);
-
- if (Wopen (0,0,24,79,3,colour,Attr (WHITE,BROWN))) {
- Hidecur (); // Hide the cursor
- Wvline (0,19,25,3,colour);
- Wgotoxy (11,21);
- Wputs ("Welcome to the Maximus User Language");
- Wvline (0,58,25,3,colour);
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- Showcur (); // Show the cursor
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wxyprintf
-
- DESCRIPTION
- Formated print to the active window at srow and scol, using
- colour attribute attr.
-
- SYNOPSIS
- int Wxyprintf (int srow, int scol, int attr, char *format_string, ... )
-
- INPUTS
- srow - Starting row.
- scol - Starting column.
- attr - The colour attribute to use.
- format_string - Format character string.
- ... - Variable number of additional parameters.
-
- Format type Meaning
- ----------- -------
- %d - display an integer as a signed decimal string
- %u - display an integer as an unsigned decimal string
- %x - display an integer as a hexidecimal string
- %o - display an integer as an octal string
- %b - display an integer as a binary string
- %c - display a character
- %s - display a character string
-
- Format modifiers
- ----------------
- - - left justify e.g. %-10s
- digits - numeric field width. e.g. %10s
- l - long value. e.g. %ld
-
- Note that all MUL function calls have a maximum parameter count
- of sixteen values.
-
- Escape sequences
- ----------------
- \n - newline character
- \t - tab character
- \f - formfeed character
- \a - bell character
- \b - backspace character
- \r - return character
- \0 - null character
- \? - all other values print the literal character.
- e.g. \" \' \\
-
- RETURN VALUE
- Number of characters written.
-
- ALSO SEE
- Wprintf printf
-
- EXAMPLE
- main ()
- {
- int i = 42, colour = Attr (BLACK,LGREY);
-
- if (Wopen (0,0,24,79,3,colour,colour)) {
- Hidecur (); // Hide the cursor
- Wxyprintf (11,30,colour,"The answer is %d",i);
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- Showcur (); // Show the cursor
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wxyputch
-
- DESCRIPTION
- Display a character in the active window at position row and col,
- using colour attribute attr.
-
- SYNOPSIS
- int Wxyputch (int row, int col, int attr, int ch)
-
- INPUTS
- row - Starting row.
- col - Starting column.
- attr - The colour attribute to use.
- ch - The character to be displayed.
-
- RETURN VALUE
- Zero on success, non-zero on error.
-
- ALSO SEE
- Wxyputs Wxyprintf
-
- EXAMPLE
- main ()
- {
- int colour = Attr (BLUE,LGREY);
-
- if (Wopen (0,0,24,79,3,colour,colour)) {
- Wxyputch (11,36,colour,'M');
- Wxyputch (11,38,colour,'U');
- Wxyputch (11,40,colour,'L');
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Wxyputs
-
- DESCRIPTION
- Display a string in the active window at position row and col,
- using colour attribute attr.
-
- SYNOPSIS
- int Wxyputs (int row, int col, int attr, char * str)
-
- INPUTS
- row - Starting row.
- col - Starting column.
- attr - The colour attribute to use.
- str - The string to display.
-
- RETURN VALUE
- Zero on success, non-zero on error.
-
- ALSO SEE
- Wxyputch Wxyprintf
-
- EXAMPLE
- main ()
- {
- int colour = Attr (LBLUE,LGREY);
-
- if (Wopen (0,0,24,79,3,colour,colour)) {
- Wxyputs (11,36,colour,"M U L");
- Pause (54); // Wait for 3 seconds
- Wclose (); // Close the window
- }
- }
-
- ----------------------------------------------------------------------
-
- NAME
- Xor
-
- DESCRIPTION
- Returns the bitwise XOR of the two arguments.
-
- SYNOPSIS
- long Xor (long arg1, long arg2)
-
- INPUTS
- arg1 - First value.
- arg2 - Second value.
-
- RETURN VALUE
- Value of the bitwise XOR.
-
- ALSO SEE
- And Or Invert ShiftLeft ShiftRight
-
- EXAMPLE
- main ()
- {
- int value = 1;
-
- value = Xor (value,1);
- printf ("Xored value: %d\n",value);
- value = Xor (value,1);
- printf ("Xored value: %d\n",value);
- }
-
- ----------------------------------------------------------------------
-
- NAME
- YesNo
-
- DESCRIPTION
- Returns a "YES" or " NO" string to indicate the logical value
- of the argument.
-
- SYNOPSIS
- char * YesNo (long value)
-
- INPUTS
- value - The value to test.
-
- RETURN VALUE
- String representating the logical value of the value.
-
- ALSO SEE
-
- EXAMPLE
- main ()
- {
- int value = 1;
-
- printf ("Is the value logically true?: %s\n",YesNo (value));
- }
-
- ----------------------------------------------------------------------
-
-