home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / text / jed / src / jed.lha / main.c < prev    next >
C/C++ Source or Header  |  1993-01-09  |  7KB  |  312 lines

  1.  
  2. /*
  3.  * MAIN.C
  4.  * (c) 1992-3 J.Harper
  5.  */
  6.  
  7. #include "jed.h"
  8. #include "jed_protos.h"
  9.  
  10. Local        BOOL    parseargs   (VOID);
  11. Prototype   VALUE *    cmd_ilock   (LONG, VALUE *);
  12. Prototype   VOID    doconmsg    (STRPTR);
  13. __stkargs   VOID    _exit        (LONG);
  14.  
  15. Prototype   const UBYTE NoMemMsg[];
  16.         const UBYTE NoMemMsg[]     = "panic: no memory!";
  17. Prototype      UBYTE RexxName[];
  18.           UBYTE RexxName[]     = "JED.XXXX";
  19. Local        const UBYTE NoStartupBdy[]     = "Can't find a startup script, this means no keybindings or menus.\nAre you sure you want to go on? (I'd read the docs if I was you)";
  20. Local        const UBYTE NoStartupGad[]     = "OK|Exit";
  21. Local        BOOL    ILock;
  22. extern    struct Library *DOSBase;
  23. extern        APTR    _WBMsg;
  24.  
  25. /*
  26.  * This function has to be stack based since c.o doesn't like a registered
  27.  * _main().
  28.  */
  29. __stkargs VOID
  30. _main(LONG cmdLen, STRPTR cmdLine)
  31. {
  32.     LONG rc = 5;
  33.     if(DOSBase->lib_Version < 36)
  34.     {
  35.     doconmsg("error: need system 2.0+\n");
  36.     _exit(20);
  37.     }
  38.     NewMList(&TXList);
  39.     if(_WBMsg ? newfile(NULL) : parseargs())
  40.     {
  41.     initpath();
  42.     if(initcommands())
  43.     {
  44.         LONG rexxsig;
  45.         WORD i;
  46.         BOOL donerexx = FALSE;
  47.         Forbid();
  48.         for(i = 1;; i++)
  49.         {
  50.         sprintf(RexxName, "JED.%ld", i);
  51.         if(!FindPort(RexxName))
  52.         {
  53.             rexxsig = upRexxPort(RexxName, "jed");
  54.             break;
  55.         }
  56.         }
  57.         Permit();
  58.         if(scriptfile("jed-startup") || scriptfile("s:jed/jed-startup") || scriptfile("s:jed-startup") || ezreq(NoStartupBdy, NoStartupGad, NULL))
  59.         {
  60.         rc = 0;
  61.         while(CurrVW)
  62.         {
  63.             ULONG signals;
  64.             struct IntuiMessage *imsg;
  65.  
  66.             stdtitle();
  67.             if(ILock && rexxsig)
  68.             signals = Wait(rexxsig);
  69.             else
  70.             signals = Wait((1 << CurrVW->vw_Window->UserPort->mp_SigBit) | rexxsig);
  71.             if(rexxsig && (signals & rexxsig))
  72.             dispRexxPort();
  73.             while(CurrVW && (imsg = GetMsg(CurrVW->vw_Window->UserPort)))
  74.             {
  75.             struct IntuiMessage imsgcopy = *imsg;
  76.             ReplyMsg((struct Message *)imsg);
  77.  
  78.             CurrVW = (VW *)imsgcopy.IDCMPWindow->UserData;
  79.             if(((imsgcopy.Class != IDCMP_RAWKEY) || (!(imsgcopy.Code & IECODE_UP_PREFIX))) && ((imsgcopy.Class != IDCMP_MENUPICK) || (imsgcopy.Code != MENUNULL)))
  80.             {
  81.                 switch(imsgcopy.Class)
  82.                 {
  83.                 case IDCMP_NEWSIZE:
  84.                     updatedimensions(CurrVW);
  85.                     resyncxy();
  86.                     CurrVW->vw_RefreshType |= RFF_ALL;
  87.                     refresh();
  88.                     cursor(ON);
  89.                     break;
  90.                 case IDCMP_MOUSEBUTTONS:
  91.                     if(imsgcopy.Code == IECODE_LBUTTON)
  92.                     {
  93.                     resettitle();
  94.                     cursor(OFF);
  95.                     positioncursorfine(imsgcopy.MouseX, imsgcopy.MouseY);
  96.                     if(DoubleClick(CurrVW->vw_ClickSecs, CurrVW->vw_ClickMics, imsgcopy.Seconds, imsgcopy.Micros))
  97.                     {
  98.                         switch(CurrVW->vw_BlockStatus)
  99.                         {
  100.                         case 0:
  101.                             CurrVW->vw_BlockStatus = -1;
  102.                             setblockrefresh();
  103.                             break;
  104.                         case 1:
  105.                             CurrVW->vw_Block[1] = CurrVW->vw_CursorPos;
  106.                             CurrVW->vw_BlockStatus = 0;
  107.                             orderblock();
  108.                             setblockrefresh();
  109.                             break;
  110.                         case 2:
  111.                             CurrVW->vw_Block[0] = CurrVW->vw_CursorPos;
  112.                             CurrVW->vw_BlockStatus = 0;
  113.                             orderblock();
  114.                             setblockrefresh();
  115.                             break;
  116.                         case -1:
  117.                             CurrVW->vw_Block[0] = CurrVW->vw_CursorPos;
  118.                             CurrVW->vw_BlockStatus = 1;
  119.                             break;
  120.                         }
  121.                     }
  122.                     resyncxy();
  123.                     refresh();
  124.                     cursor(ON);
  125.                     CurrVW->vw_ClickSecs = imsgcopy.Seconds;
  126.                     CurrVW->vw_ClickMics = imsgcopy.Micros;
  127.                     }
  128.                     else if(imsgcopy.Code == IECODE_RBUTTON)
  129.                     {
  130.                     if(CurrVW->vw_Sleeping)
  131.                     {
  132.                         unsleep();
  133.                         refresh();
  134.                         cursor(ON);
  135.                     }
  136.                     }
  137.                     break;
  138.                 case IDCMP_MOUSEMOVE:
  139.                     if(imsgcopy.Qualifier & IEQUALIFIER_LEFTBUTTON)
  140.                     {
  141.                     resettitle();
  142.                     cursor(OFF);
  143.                     positioncursorfine(imsgcopy.MouseX, imsgcopy.MouseY);
  144.                     resyncxy();
  145.                     refresh();
  146.                     cursor(ON);
  147.                     }
  148.                     break;
  149.                 case IDCMP_MENUPICK:
  150.                     resettitle();
  151.                     evalmenu(imsgcopy.Code, imsgcopy.Qualifier);
  152.                     break;
  153.                 case IDCMP_CLOSEWINDOW:
  154.                     TX *tx = CurrVW->vw_Tx;
  155.                     if((numviews(tx) > 1) || (!tx->tx_Changes) || (ezreq("OK to lose %ld changes\nto file %s", "Yeah|Cancel", tx->tx_Changes, tx->tx_TitleName)))
  156.                     {
  157.                     cursor(OFF);
  158.                     killwindow();
  159.                     if(CurrVW)
  160.                     {
  161.                         refresh();
  162.                         cursor(ON);
  163.                     }
  164.                     }
  165.                     break;
  166.                 case IDCMP_RAWKEY:
  167.                     usekey(&imsgcopy);
  168.                     break;
  169.                 case IDCMP_ACTIVEWINDOW:
  170.                     updatedimensions(CurrVW);
  171.                     cursor(OFF);
  172.                     resyncxy();
  173.                     if(CurrVW->vw_LastRefresh != CurrVW->vw_Tx->tx_Changes)
  174.                     CurrVW->vw_RefreshType |= RFF_ALL;
  175.                     refresh();
  176.                     cursor(ON);
  177.                     break;
  178.                 }
  179.             }
  180.             }
  181.             if(CurrVW)
  182.             stdtitle();
  183.         }
  184.         killclipstuff();
  185.         killfilereq();
  186.         killprompthist();
  187.         killmenu();
  188.         killbindings();
  189.         }
  190.         else
  191.         killwindow();
  192.         dnRexxPort();
  193.         killsymbols();
  194.     }
  195.     else
  196.     {
  197.         killwindow();
  198.         doconmsg("error: no memory to initialize symbol table\n");
  199.     }
  200.     killpath();
  201.     }
  202.     else
  203.     doconmsg("error: can't open window\n");
  204.     _exit(rc);
  205. }
  206.  
  207. /*
  208.  * CLI only.
  209.  */
  210. const UBYTE ArgTemplate[] = "FILES/M,PUBSCREEN/K,DTAB/N/K,CD/K";
  211. enum ArgRef
  212. {
  213.     ARG_FILES,
  214.     ARG_PUB,
  215.     ARG_DT,
  216.     ARG_CD,
  217.     NUM_ARGS
  218. };
  219. LONG ArgVals[NUM_ARGS];
  220. BOOL
  221. parseargs(VOID)
  222. {
  223.     BOOL rc = FALSE;
  224.     struct RDArgs *rd;
  225.     if(rd = ReadArgs(ArgTemplate, ArgVals, NULL))
  226.     {
  227.     if(ArgVals[ARG_PUB])
  228.         strncpy(DefPrefs.prf_ScreenName, (STRPTR)ArgVals[ARG_PUB], 100);
  229.     if(ArgVals[ARG_DT])
  230.         DefPrefs.prf_DiskTab = *((ULONG *)ArgVals[ARG_DT]);
  231.     if(ArgVals[ARG_CD])
  232.     {
  233.         BPTR dlck;
  234.         if(dlck = Lock((STRPTR)ArgVals[ARG_CD], SHARED_LOCK))
  235.         {
  236.         dlck = CurrentDir(dlck);
  237.         UnLock(dlck);
  238.         }
  239.         else
  240.         PutStr("can't lock specified CD\n");
  241.     }
  242.     if(ArgVals[ARG_FILES])
  243.     {
  244.         STRPTR *thisfi = (STRPTR *)ArgVals[ARG_FILES];
  245.         while(*thisfi)
  246.         {
  247.         if(!newfile(*thisfi++))
  248.             Printf("warning: can't open file %s\n", (LONG)(*thisfi));
  249.         else
  250.         {
  251.             rc = TRUE;
  252.             refresh();
  253.             cursor(ON);
  254.         }
  255.         }
  256.     }
  257.     if(!rc)
  258.     {
  259.         if(rc = newfile(NULL))
  260.         {
  261.         refresh();
  262.         cursor(ON);
  263.         }
  264.     }
  265.     FreeArgs(rd);
  266.     }
  267.     else
  268.     PutStr("error: bad argument specification\n");
  269.     return(rc);
  270. }
  271.  
  272. /*
  273.  * Input lock, when this is on only ARexx messages can get through.
  274.  */
  275. VALUE *
  276. cmd_ilock(LONG argc, VALUE *argv)
  277. {
  278.     if(TPLATE1(VTF_NUMBER))
  279.     {
  280.     setnumres(ILock);
  281.     ILock = ARG1.val_Value.Number;
  282.     }
  283.     return(&RES);
  284. }
  285.  
  286. /*
  287.  * CLI/WB & 1.3/2.0 compatible
  288.  */
  289. VOID
  290. doconmsg(STRPTR msg)
  291. {
  292.     if(_WBMsg)
  293.     {
  294.     BPTR fh = Open("CON:///80/JEd output/WAIT/CLOSE", MODE_NEWFILE);
  295.     if(fh)
  296.         Write(fh, msg, strlen(msg));
  297.     Close(fh);
  298.     }
  299.     else
  300.     Write(Output(), msg, strlen(msg));
  301. }
  302.  
  303. /*
  304.  * reference to pull in WB startup
  305.  */
  306. VOID _waitwbmsg(VOID);
  307. Local VOID
  308. dummy(VOID)
  309. {
  310.     _waitwbmsg();
  311. }
  312.