home *** CD-ROM | disk | FTP | other *** search
- ;
- ; If you don't want this file to be loaded as part of Max's
- ; initialization, remove it from config.max.
- ;
- ; The structured preprocessor definitions such as:
- ;
- ; Function <name> Begin <body> EndFunction and
- ; For <body> EndFor
- ;
- ; are located in block.max. This file is specified in config.max
- ; and is loaded during Max initialization.
-
-
- ; Function to print a directory listing
-
- Function dir
- Begin
-
- ; If no name specified then display a list of all regular
- ; files in the current directory.
-
- If eq (argc() 0)
- Then
- set (name "*.*")
- EndThen
-
- ; Otherwise use the pathname and wildcard string supplied
- ; by the user.
-
- Else
- set (name argv (1))
- EndElse
- EndIf
-
- ; Allocate a list and read the directory into it and sort it.
-
- set (ld dirlst (name))
- lstsort (ld)
-
- ; Display each filename in the list
-
- For lsthead (ld) lstcval (ld) lstnext (ld)
- put (lstcget (ld))
- EndFor
-
- ; Free the list.
-
- lstfre (ld)
-
- EndFunction
-
- ; Function to type a file
-
- Function type
- Begin
-
- ; Print usage message if no pathname specified
-
- If ne (argc() "1")
- Then
- put ("Usage: type <pathname>")
- exit ()
- EndThen
- EndIf
-
- ; Get pathname and open file
-
- set (path argv(1))
- set (path_fd open (path "r"))
-
- ; Print error message if file cannot be opened
-
- If lt (path_fd 0)
- Then
- put ("Cannot open " path)
- exit ()
- EndThen
- EndIf
-
- ; Read and display each line of the file
-
- While gt (read (path_fd buf) "0")
- put (buf)
- EndWhile
-
- ; Close the file and exit
-
- close (path_fd)
-
- EndFunction
-
- ; The windef.max file contains command definitions used in the calls
- ; to the window builtin function.
-
- Function showsine
- Begin
-
- ; Allocate new transient level so windef's can be freed
-
- tpush ()
- tset ()
- $include ("windef.max")
-
- ; Define a new window for sine wave
-
- window (WLocation 5 10 19 70) ; top=5 left=10 bottom=10 right=70
- window (WBorder 2) ; double line border
- window (WText fmhex (0x0c)) ; bright red text on black background
- window (WTitle " Sine Wave ") ; give window a title
- set (wd window (WOpen)) ; open window and save descriptor (wd)
-
- ; Plot sine wave from 0 to 2*pi
-
- set (two_pi mul (3.14 2))
-
- For set (x 0) lt (x two_pi) set (x add (x 0.2))
-
- set (y sin (x)) ; set y to sine of x
- set (y mul (y 20)) ; scale for display
- set (y add (y 30)) ; in center of window
- set (buf strcat (strcpy (" " y) "*\n")) ; format string
- window (WSend wd buf) ; write to window
-
- EndFor
-
- window (WSend wd "\nUse arrow keys to view sine wave. Press return when done.")
- window (WReceive wd buf)
-
- window (WClose wd)
- window (WRefresh 0)
- window (WRefresh 1)
-
- ; Clear the storage for this function and windef replacement text
-
- tclear ()
- tpop ()
-
- EndFunction
-
- ; Display a directory of user defined functions at startup
-
- udfdir ()
-
- print ("The sample programs have been loaded. Try dir(), type() or showsine().")