home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / max / max130 / sample.max < prev    next >
Text File  |  1988-10-30  |  4KB  |  145 lines

  1. ;
  2. ; If you don't want this file to be loaded as part of Max's
  3. ; initialization, remove it from config.max.
  4. ;
  5. ; The structured preprocessor definitions such as:
  6. ;
  7. ;           Function <name> Begin <body> EndFunction    and
  8. ;           For <body> EndFor
  9. ;
  10. ; are located in block.max. This file is specified in config.max
  11. ; and is loaded during Max initialization.
  12.  
  13.  
  14. ; Function to print a directory listing
  15.  
  16. Function dir
  17.     Begin
  18.  
  19.         ; If no name specified then display a list of all regular
  20.         ; files in the current directory.
  21.  
  22.         If eq (argc() 0)
  23.             Then
  24.                 set (name "*.*")
  25.             EndThen
  26.  
  27.         ; Otherwise use the pathname and wildcard string supplied
  28.         ; by the user.
  29.  
  30.             Else
  31.                 set (name argv (1))
  32.             EndElse
  33.         EndIf
  34.  
  35.         ; Allocate a list and read the directory into it and sort it.
  36.  
  37.         set (ld dirlst (name))
  38.         lstsort (ld)
  39.  
  40.         ; Display each filename in the list
  41.  
  42.         For lsthead (ld) lstcval (ld) lstnext (ld)
  43.             put (lstcget (ld))
  44.         EndFor
  45.  
  46.         ; Free the list.
  47.  
  48.         lstfre (ld)
  49.  
  50. EndFunction
  51.  
  52. ; Function to type a file
  53.  
  54. Function type
  55.     Begin
  56.  
  57.         ; Print usage message if no pathname specified
  58.  
  59.         If ne (argc() "1")
  60.             Then
  61.                 put ("Usage: type <pathname>")
  62.                 exit ()
  63.             EndThen
  64.         EndIf
  65.  
  66.         ; Get pathname and open file
  67.  
  68.         set (path argv(1))
  69.         set (path_fd open (path "r"))
  70.  
  71.         ; Print error message if file cannot be opened
  72.  
  73.         If lt (path_fd 0)
  74.             Then
  75.                 put ("Cannot open " path)
  76.                 exit ()
  77.             EndThen
  78.         EndIf
  79.  
  80.         ; Read and display each line of the file
  81.  
  82.         While gt (read (path_fd buf) "0")
  83.             put (buf)
  84.         EndWhile
  85.  
  86.         ; Close the file and exit
  87.  
  88.         close (path_fd)
  89.  
  90. EndFunction
  91.  
  92. ; The windef.max file contains command definitions used in the calls
  93. ; to the window builtin function.
  94.  
  95. Function showsine
  96.     Begin
  97.  
  98.         ; Allocate new transient level so windef's can be freed
  99.  
  100.         tpush ()
  101.         tset ()
  102.         $include ("windef.max")
  103.  
  104.         ; Define a new window for sine wave
  105.  
  106.         window (WLocation 5 10 19 70)   ; top=5 left=10 bottom=10 right=70
  107.         window (WBorder 2)              ; double line border
  108.         window (WText fmhex (0x0c))     ; bright red text on black background
  109.         window (WTitle " Sine Wave ")   ; give window a title
  110.         set (wd window (WOpen))         ; open window and save descriptor (wd)
  111.  
  112.         ; Plot sine wave from 0 to 2*pi
  113.  
  114.         set (two_pi mul (3.14 2))
  115.  
  116.         For set (x 0) lt (x two_pi) set (x add (x 0.2))
  117.  
  118.             set (y sin (x))             ; set y to sine of x
  119.             set (y mul (y 20))          ; scale for display
  120.             set (y add (y 30))          ; in center of window
  121.             set (buf strcat (strcpy (" " y) "*\n")) ; format string
  122.             window (WSend wd buf)                   ; write to window
  123.  
  124.         EndFor
  125.  
  126.         window (WSend wd "\nUse arrow keys to view sine wave. Press return when done.")
  127.         window (WReceive wd buf)
  128.  
  129.         window (WClose wd)
  130.         window (WRefresh 0)
  131.         window (WRefresh 1)
  132.  
  133.         ; Clear the storage for this function and windef replacement text
  134.  
  135.         tclear ()
  136.         tpop ()
  137.  
  138. EndFunction
  139.  
  140. ; Display a directory of user defined functions at startup
  141.  
  142. udfdir ()
  143.  
  144. print ("The sample programs have been loaded. Try dir(), type() or showsine().")
  145.