/* addnag.rexx - inserts requestored NAGPLUS event into current nag-year */

/*      copyright 1989 Richard Lee Stockton and Gramma Software.         */
/*    This code is freely distributable as long as this copyright        */
/*   notice remains, unchanged, at the start of the code. Thank you.     */

OPTIONS RESULTS
SIGNAL ON BREAK_C

IF(~EXISTS("libs:rexxsupport.library")|~EXISTS("libs:rexxarplib.library")) THEN
 DO
    SAY "Couldn't find needed library (rexxsupport and/or rexxarplib)."
    EXIT 20
 END
CALL ADDLIB('rexxsupport.library',0,-30,0)
CALL ADDLIB('rexxarplib.library',0,-30,0)

return_text = "0"
priport     = ""
success     = 0

nagport   = 'NagRexx1'
nagfront  = SUBSTR(DATE(S),5,4)
nagprompt = GETCLIP('nag_event')


/* a today !ACTION! event with 1 voice and sound nag */

IF nagprompt=="" THEN nagprompt=nagfront"0000ZI"


/* Where the 'pretty' stuff gets done. 'nagevent' is text to insert */

CALL SCREENTOFRONT()

nagevent = Request(50,50,,
"                ADD an Event to NAGPLUS\\
MM=Month, DD=Day, HH=Hours, NN=miNutes, ZI=sound/voice nag\\
MMDDHHNNZIYour event text (up to 48 characters) goes here.",,
nagprompt,"ADD","CANCEL")

CALL SCREENTOBACK()

/*  if the text less than 11 chars (no event text), quietly return */
/*  otherwise, insert in NAGPLUS, (assuming I can find it)  */

IF LENGTH(nagevent)>10 THEN
 DO
    ADDRESS VALUE nagport
    lock
    priport = RESULT
    IF(priport~="" & priport~="RESULT") THEN
     DO
        ADDRESS VALUE priport
        IF LENGTH(nagevent)>59 THEN nagevent=LEFT(nagevent,59)
        set 4   /* set to this year */
        edit nagevent
        unlock
        IF ~SETCLIP('nag_event',nagevent) THEN return_text = "CLIP_FAILURE"
     END
    ELSE return_text = "PORT_LOCK_FAILURE"
 END

EXIT return_text


BREAK_C:

IF SHOWLIST(p,priport) THEN unlock
EXIT 'ABORT'
