#!/usr/lib/scadalisp/bin/phlisp

;;;
;;; Test the cpu monitor from inside another program
;;;

(defvar __USAGE "
#ifdef __USAGE
#%C	[-i integration] [-u update] [-1|-2] [-c color1 color2]
#    -i    Set the integration rate in seconds, default 3
#    -l    Set the CPU level to watch, 0 for all combined, default 0
#    -u    Set the update rate in seconds, default 0.1
#    -1    Display both traces on a single graph, default on
#    -2    Display each trace on its own graph, default off
#    -c    Set the colors for the two traces, default 0xff 0xffff
#endif
")

(require "usage")

(setq cpm-Subprocess t)

(do ((arglist (cdr argv) (cdr arglist)))
    ((not arglist))
    (cond
     ((equal (car arglist) "-i")
      (setq cpm-Integration (number (car (setq arglist (cdr arglist))))))
     ((equal (car arglist) "-l")
      (setq cpm-CPULevel (number (car (setq arglist (cdr arglist))))))
     ((equal (car arglist) "-u")
      (setq cpm-UpdateRate (number (car (setq arglist (cdr arglist))))))
     ((equal (car arglist) "-1")
      (setq cpm-OneTrend t))
     ((equal (car arglist) "-2")
      (setq cpm-OneTrend nil))
     ((equal (car arglist) "-c")
      (setq cpm-Colors (array (number (cadr arglist))
			      (number (caddr arglist))))
      (setq arglist (cddr arglist)))
     (t (Usage) (exit-program 1))
     )
    )

(if (not (undefined-p init-ipc))
    (init-ipc "cpumem" nil))
(PtInit nil)
(require "cpumem")
(cpm-build-window)
(PtMainLoop)
