home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / fed0217s.zip / source / fed.cpp < prev    next >
C/C++ Source or Header  |  2001-11-07  |  6KB  |  231 lines

  1. /*
  2. ** Module   :FED.CPP
  3. ** Abstract :Fast Editor Main module
  4. **
  5. ** Copyright (C) Sergey I. Yevtushenko
  6. **
  7. ** Log: Sun  11/05/1997       Created from 'RC.CPP'
  8. **      Sun  09/11/1997       This is first comment written in FED! Version 0.1.5a
  9. **      Wed  12/11/1997       Updated to V0.1.6
  10. **      Sun  16/11/1997       Updated to V0.1.7
  11. **      Tue  18/11/1997       Updated to V0.1.8
  12. **      Tue  17/03/1998     Updated to V0.1.9l (first fully functional version)
  13. **      Mon  03/08/1998     Updated to V0.2.0n
  14. **      Sat  09/01/1999     Updated to V0.2.0p
  15. **      Thu  03/06/1999     Updated to V0.2.5 (FED Open Source)
  16. */
  17.  
  18. /*
  19. TODO:
  20.  
  21.  Implement smart indent (C/C++ and REXX modes)     - part (C/C++)
  22.  Bracket matching                                  - first quick&dirty version
  23.  
  24. */
  25.  
  26. #include <string.h>
  27.  
  28. #include <stddlg.h>
  29. #include <keynames.h>
  30. #include <pmproc.h>
  31. #include <version.h>
  32. #include <fio.h>
  33.  
  34. #define MK_CLR(clr)     (app_pal[CL_APPLICATION_START+(clr)])
  35.  
  36.  
  37. EditBoxCollection Editor;
  38. JumpList JList[10];
  39.  
  40. //---------------------------------------------------
  41.  
  42. #define RESERVED_SIZE       16000
  43.  
  44. static char *mem_reserved = 0;
  45.  
  46. ULONG APIENTRY XHandler(PEXCEPTIONREPORTRECORD,
  47.                         PEXCEPTIONREGISTRATIONRECORD,
  48.                         PCONTEXTRECORD,
  49.                         PVOID);
  50.  
  51. int main(int argc, char **argv)
  52. {
  53.     EXCEPTIONREGISTRATIONRECORD RegRec = {0};
  54.     APIRET rc = 0;
  55.     int i = 0;
  56.  
  57.     if(Editor.isDown())
  58.     {
  59.         MessageBox("ERROR:\nCan't open INI file");
  60.         return -1;
  61.     }
  62.  
  63.     if(iForce)
  64.         init_pm(iForce);
  65.  
  66.     Editor.doCopyright();
  67.  
  68. #ifndef __FED_DEBUG__
  69.     RegRec.ExceptionHandler = (ERR) XHandler;
  70.     rc = DosSetExceptionHandler(&RegRec);
  71.  
  72.     if (rc)
  73.     {
  74.         MessageBox("ERROR:\nCan't install exception handler");
  75.         return -1;
  76.     }
  77. #endif
  78.  
  79.     if(argc > 1)
  80.     {
  81.         int rc = 1;
  82.  
  83.         for(i = 1; i < argc; i++)
  84.         {
  85.             if(argv[i][0]=='-' && __isdd(argv[i][1]))
  86.             {
  87.                 Editor.set_xy(&argv[i][1]);
  88.                 continue;
  89.             }
  90.  
  91.             if(argv[i][0]=='-' && __to_lower(argv[i][1]) == 'p')
  92.             {
  93.                 i++;
  94.  
  95.                 if(i >= argc)
  96.                     break;
  97.  
  98.                 //Note: opening via pipe have sense only if our pipe is
  99.                 //      not open, and therefore other instance uses it
  100.                 if(!Editor.npFED.IsValid())
  101.                 {
  102.                     int handle = _lopen("\\PIPE\\FED", OP_PIPE);
  103.  
  104.                     _lwrite(handle, "open ", 5);
  105.                     _lwrite(handle, argv[i], strlen(argv[i]));
  106.                     _lclose(handle);
  107.  
  108.                     //Make sure that editor will go down after opening files
  109.                     Editor.doAbort();
  110.                     continue;
  111.                 }
  112.                 //Note: if pipe is open, we just fall through here
  113.                 //      and open file as usual
  114.             }
  115.  
  116.             if(strchr(argv[i], '*') || strchr(argv[i], '?'))
  117.             {
  118.                 int frc = FileDialog(2, 2, cName, 0);
  119.  
  120.                 if(!frc)
  121.                     Editor.doOpenFile(cName);
  122.  
  123.                 continue;
  124.             }
  125.  
  126.             if(!rc)
  127.                 Editor.select(Editor.open());
  128.  
  129.             rc = Editor.current()->load(argv[i]);
  130.             Editor.SendKey("kbOpen");
  131.         }
  132.         Editor.select(0);
  133.     }
  134.  
  135.     /* Send pseudo key kbStart */
  136.  
  137.     Editor.SendKey("kbInit");
  138.  
  139.     KeyInfo k;
  140.  
  141.     while(!Editor.isDown())
  142.     {
  143.         Editor.draw();
  144.  
  145.         vio_read_key(&k);
  146.  
  147.         while(k.rep_count--)
  148.             Editor.Dispatcher(k,1);
  149.     }
  150.  
  151.     Editor.SendKey("kbDone");
  152.  
  153. #ifndef __FED_DEBUG__
  154.  
  155.     rc = DosUnsetExceptionHandler(&RegRec);
  156.  
  157. #endif
  158.  
  159.     Editor.Done();
  160.  
  161.     return 0;
  162. }
  163.  
  164. ULONG APIENTRY XHandler(PEXCEPTIONREPORTRECORD p1,
  165.                         PEXCEPTIONREGISTRATIONRECORD,
  166.                         PCONTEXTRECORD,
  167.                         PVOID)
  168. {
  169.     int i;
  170.     extern HAB hab;
  171.     extern HMQ hmq;
  172.     static int single = 0;
  173.  
  174.     //delete mem_reserved;
  175.  
  176.     if(single)
  177.         return XCPT_CONTINUE_SEARCH;
  178.  
  179.     if(p1->ExceptionNum == XCPT_SIGNAL)
  180.     {
  181.         if(iCtrlBrk == 1)
  182.         {
  183.             //Silently die
  184.             single++;
  185.             return XCPT_CONTINUE_SEARCH;
  186.         }
  187.  
  188.         if(iCtrlBrk == 2)
  189.         {
  190.             //Save all and exit
  191.             single++;
  192.             Editor.doSaveAll();
  193.             return XCPT_CONTINUE_SEARCH;
  194.         }
  195.  
  196.         if(iCtrlBrk == 3)
  197.         {
  198.             //Ignore
  199.             return XCPT_CONTINUE_EXECUTION;
  200.         }
  201.  
  202.         MessageBox("Ctrl-Break received.\nTerminating.");
  203.     }
  204.     else
  205.         MessageBox("  WARNING!!!\n"
  206.                    "FED will be terminated \n"
  207.                    "due to unrecoverable error!\n"
  208.                    "All opened files will be saved\n"
  209.                    "with names DEADFED.xxx\n"
  210.                    "Where xxx is number starting from 000.");
  211.  
  212.     for(i = 0; i < Editor.Count(); i++)
  213.     {
  214.         static char savename[16];
  215.         strcpy(savename,"DEADFED.");
  216.         strcat(savename, cvt_num(i,3));
  217.         Editor.current()->set_changed(1);
  218.         Editor.current()->save_as(savename);
  219.         Editor.next();
  220.     }
  221.  
  222.     if(hab)
  223.     {
  224.         _inCloseClipbrd(hab);
  225.         deinit_pm();
  226.     }
  227.     single = 1;
  228.     return XCPT_CONTINUE_SEARCH;
  229. }
  230.  
  231.