home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / utilities / dirutils / visualshell / src / main_segment.c < prev    next >
C/C++ Source or Header  |  1992-10-28  |  9KB  |  262 lines

  1.             /*********************************
  2.          *                               *
  3.          *   Visual Shell v1.17  10/92   *
  4.          *                               *
  5.          *     by Torsten Jürgeleit      *
  6.          *                               *
  7.          *       segment main part       *
  8.          *                               *
  9.          *********************************/
  10.  
  11.     /* Includes */
  12.  
  13. #include "includes.h"
  14. #include "imports.h"
  15. #include "protos.h"
  16.  
  17.     /* Structures */
  18.  
  19. struct StartupMsg {
  20.     struct Message  sm_Message;
  21.     struct Process  *sm_CLIProcess;
  22.     struct Window   *sm_ConWindow;
  23.     struct Device   *sm_ConDevice;
  24.     struct ConUnit  *sm_ConUnit;
  25.     BYTE    *sm_LeftPath;    /* path for left file requester */
  26.     BYTE    *sm_RightPath;    /* path for right file requester */
  27.     USHORT    sm_Flags;    /* used for HIDE flag */
  28. };
  29.     /* Main - waits for startup msg and installs input event handler */
  30.  
  31.    VOID
  32. _main(VOID)
  33. {
  34.    struct MsgPort     *mp;
  35.    struct StartupMsg  *sm;
  36.    BYTE *path;
  37.  
  38.    /* Wait for startup msg */
  39.    main_task = FindTask(NULL);
  40.    mp        = &((struct Process *)main_task)->pr_MsgPort;
  41.    WaitPort(mp);
  42.    if (sm = (struct StartupMsg *)GetMsg(mp)) {
  43.  
  44.       /* Get data from startup msg and return it */
  45.       _parent_proc       = sm->sm_CLIProcess;
  46.       save_cli           = BTOC(_parent_proc->pr_CLI);
  47.       con_input_fhandle  = BTOC(_parent_proc->pr_CIS);
  48.       con_output_fhandle = BTOC(_parent_proc->pr_COS);
  49.       con_window         = sm->sm_ConWindow;
  50.       con_rport          = con_window->RPort;
  51.       con_device         = sm->sm_ConDevice;
  52.       con_unit           = sm->sm_ConUnit;
  53.       show_flag          = (sm->sm_Flags == 1 ? 0 : 1);
  54.  
  55.       /* Copy given path names to allocated buffer */
  56.       if (!(path = sm->sm_LeftPath)) {
  57.      dir_arg[0] = NULL;
  58.       } else {
  59.      if (dir_arg[0] = AllocMem((LONG)(strlen(path) + 1), (LONG)
  60.                                  MEMF_PUBLIC)) {
  61.         strcpy(dir_arg[0], path);
  62.      }
  63.       }
  64.       if (!(path = sm->sm_RightPath)) {
  65.      dir_arg[1] = NULL;
  66.       } else {
  67.      if (dir_arg[1] = AllocMem((LONG)(strlen(path) + 1), (LONG)
  68.                                  MEMF_PUBLIC)) {
  69.         strcpy(dir_arg[1], path);
  70.      }
  71.       }
  72.  
  73.       /* Send startup message back to VSh */
  74.       ReplyMsg(&sm->sm_Message);
  75.  
  76.       /* Alloc respources */
  77.       if (ArpBase = OpenLibrary(ArpName, ArpVersion)) {
  78.  
  79.      /* Use libraries arp.library has already opened for us */
  80.      GfxBase       = (struct GfxBase *)ArpBase->GfxBase;
  81.      IntuitionBase = (struct IntuitionBase *)ArpBase->IntuiBase;
  82.  
  83.      /* Check if started from WShell */
  84.      SPrintf(&line1_buffer[0], "WSH_%ld", _parent_proc->pr_TaskNum);
  85.      wshell_flag = (FindPort(&line1_buffer[0]) ? 1 : 0);
  86.  
  87.      /* Build process name */
  88.      SPrintf(&process_name[0], PROCESS_NAME, _parent_proc->pr_TaskNum);
  89.  
  90.      /* Install input event handler */
  91.      if (vsh_port = CreatePort(&process_name[0], 0L)) {
  92.         if (input_req = CreateStdIO(vsh_port)) {
  93.            if (!OpenDevice("input.device", 0L, (struct IORequest *)
  94.                                input_req, 0L)) {
  95.           /* Init interrupt struct */
  96.           interrupt.is_Node.ln_Name = &process_name[0];
  97.           interrupt.is_Node.ln_Pri  = 51;   /* above Intuition */
  98.           interrupt.is_Code         = (VOID (*)())
  99.                                &input_event_handler;
  100. #asm
  101.     move.l    a4,_interrupt+14    ; use our data segment ptr as data for interrupt
  102. #endasm
  103.           /* Init IOStdReq */
  104.           input_req->io_Command     = IND_ADDHANDLER;
  105.           input_req->io_Data        = (APTR)&interrupt;
  106.           input_req->io_Length      = sizeof(struct Interrupt);
  107.           if (DoIO((struct IORequest *)input_req)) {
  108.              Printf("Can't install input event handler !\n");
  109.           } else {
  110.              if (nil_handle = (BPTR)Open(nil, (LONG)MODE_NEWFILE)) {
  111.             if (con_handle = (BPTR)Open(star, (LONG)
  112.                                 MODE_NEWFILE)) {
  113.                alloc_buffers();
  114.                Close(con_handle);
  115.             }
  116.             Close(nil_handle);
  117.              }
  118.              input_req->io_Command = IND_REMHANDLER;
  119.              DoIO((struct IORequest *)input_req);
  120.           }
  121.           CloseDevice((struct IORequest *)input_req);
  122.            }
  123.            DeleteStdIO(input_req);
  124.         }
  125.         DeletePort(vsh_port);
  126.      }
  127.      CloseLibrary(ArpBase);
  128.       }
  129.  
  130.       /* Free path name buffer */
  131.       if (path = dir_arg[0]) {
  132.      FreeMem(path, (LONG)(strlen(path) + 1));
  133.       }
  134.       if (path = dir_arg[1]) {
  135.      FreeMem(path, (LONG)(strlen(path) + 1));
  136.       }
  137.    }
  138. }
  139.     /* Allocate and initialize buffers */
  140.  
  141.    VOID
  142. alloc_buffers(VOID)
  143. {
  144.    struct Screen    *wb_screen = con_window->WScreen;
  145.    struct TextFont  *text_font;
  146.    USHORT i;
  147.    BYTE   *data_buffer, *ptr;
  148.  
  149.    /* Get current workbench dimension */
  150.    wb_width    = wb_screen->Width;
  151.    wb_height   = wb_screen->Height;
  152.    wb_line_len = wb_width / 8;
  153.  
  154.    /* Need even line len for BltTemplate() -> EVEN source modulo!!! */
  155.    if (wb_line_len & 1) {
  156.       wb_line_len++;
  157.    }
  158.  
  159.    /* Initialize max values in config entry array */
  160.    config_entry[CONFIG_ENTRY_LEFT_EDGE].ce_MaxValue = wb_width -
  161.                                   MIN_VSH_WIDTH;
  162.    config_entry[CONFIG_ENTRY_TOP_EDGE].ce_MaxValue  = wb_width -
  163.                                  MIN_VSH_HEIGHT;
  164.    config_entry[CONFIG_ENTRY_WIDTH].ce_MaxValue     = wb_width;
  165.    config_entry[CONFIG_ENTRY_HEIGHT].ce_MaxValue    = wb_height;
  166.    config_entry[CONFIG_ENTRY_CLI_LINES].ce_MaxValue = (wb_height -
  167.                     MIN_VSH_HEIGHT) / 8 + DEFAULT_CLI_LINES;
  168.    if (data_buffer = AllocMem((LONG)((MAX_EDITOR_NAME_LEN + 1) +
  169.        (MAX_EDITOR_OPTS_LEN + 1) + MAX_FKEYS * ((MAX_USER_FUNCTION_LEN +
  170.              1) + (MAX_FKEY_LEN + 1))), MEMF_PUBLIC | MEMF_CLEAR)) {
  171.       if (fib = (struct FileInfoBlock *)AllocMem((LONG)
  172.           sizeof(struct FileInfoBlock), MEMF_PUBLIC | MEMF_CLEAR)) {
  173.      if (idata = (struct InfoData *)AllocMem((LONG)
  174.                sizeof(struct InfoData), MEMF_PUBLIC | MEMF_CLEAR)) {
  175.         if (template_buffer = (UBYTE *)AllocMem((LONG)(wb_line_len * 8),
  176.                          MEMF_PUBLIC | MEMF_CHIP)) {
  177.            if (font_data = (UBYTE *)AllocMem((LONG)(MAX_FONT_CHARS * 8),
  178.                                  MEMF_PUBLIC)) {
  179.           /* Clone console 8x8 font attr struct and open this font */
  180.           text_font              = con_rport->Font;
  181.           con_font_attr.ta_Name  = (STRPTR)
  182.                       text_font->tf_Message.mn_Node.ln_Name;
  183.           con_font_attr.ta_YSize = text_font->tf_YSize;
  184.           con_font_attr.ta_Style = text_font->tf_Style;
  185.           con_font_attr.ta_Flags = text_font->tf_Flags;
  186.           if (con_font = OpenFont(&con_font_attr)) {
  187. /*
  188. Printf("font: name='%s'   XSize=%d   YSize=%d   Style=%d   Flags=%d\n",
  189.    con_font->tf_Message.mn_Node.ln_Name, con_font->tf_XSize, con_font->tf_YSize, con_font->tf_Style, con_font->tf_Flags);
  190. Printf("BaseLine=%d   Accessors=%d   Modulo=%d   LoChar=%d   HiChar=%d\n",
  191.    con_font->tf_Baseline, con_font->tf_Accessors, con_font->tf_Modulo, con_font->tf_LoChar, con_font->tf_HiChar);
  192. Printf("CharData=$%lx   CharLoc=$%lx   CharSpace=$%lx   CharKern=$%lx   Extension=$%lx\n",
  193.    con_font->tf_CharData, con_font->tf_CharLoc, con_font->tf_CharSpace, con_font->tf_CharKern, con_font->tf_Message.mn_ReplyPort);
  194. Delay(400L);
  195. */
  196.              /* Init font data */
  197.              unpack_font(con_font, font_data);
  198.              CopyMem((BYTE *)&special_chars[0][0],
  199.                         (BYTE *)font_data + 128 * 8,
  200.                          (LONG)(MAX_SPECIAL_CHARS * 8));
  201.              /* Init string buffer ptrs */
  202.              vsh_editor_name = ptr  = data_buffer;
  203.              vsh_editor_opts = ptr += MAX_EDITOR_NAME_LEN + 1;
  204.  
  205.              /* Init user func fkey text and buffer ptrs */
  206.              for (i = 0, ptr += MAX_EDITOR_OPTS_LEN + 1;
  207.                              i < MAX_FKEYS; i++,
  208.                      ptr += MAX_USER_FUNCTION_LEN + 1) {
  209.             user_fkey_text[i] = ptr;
  210.             user_function[i]  = ptr += MAX_FKEY_LEN + 1;
  211.              }
  212.  
  213.              /* Save old window dimensions */
  214.              old_left        = con_window->LeftEdge;
  215.              old_top         = con_window->TopEdge;
  216.              old_width       = con_window->Width;
  217.              old_height      = con_window->Height;
  218.              old_min_width   = con_window->MinWidth,
  219.              old_min_height  = con_window->MinHeight,
  220.              old_max_width   = con_window->MaxWidth,
  221.              old_max_height  = con_window->MaxHeight,
  222.              old_flags       = con_window->Flags;
  223.              old_idcmp_flags = con_window->IDCMPFlags;
  224.              old_bleft       = con_window->BorderLeft;
  225.              old_btop        = con_window->BorderTop;
  226.              old_bright      = con_window->BorderRight;
  227.              old_bbottom     = con_window->BorderBottom;
  228.              old_wb_font     = wb_screen->RastPort.Font;
  229.  
  230.              /* Turn on window border and refresh events (2nd used for Kick 2.0 simple refresh console windows !!!) */
  231.              con_window->Flags = old_flags & ~(BORDERLESS |
  232.                                  NOCAREREFRESH);
  233.              RefreshWindowFrame(con_window);
  234.              if (read_config_file() == FALSE) {
  235.             set_default_config();
  236.              }
  237.              prepare_con_window();
  238.  
  239.              /* Get refresh and timing events from intuition */
  240.              ModifyIDCMP(con_window, (ULONG)REFRESHWINDOW | INTUITICKS);
  241.              start_vsh();
  242.  
  243.              /* Restore old IDCMP flags */
  244.              ModifyIDCMP(con_window, old_idcmp_flags);
  245.  
  246.              restore_con_window();
  247.              CloseFont(con_font);
  248.           }
  249.           FreeMem(font_data, (LONG)(MAX_FONT_CHARS * 8));
  250.            }
  251.            FreeMem(template_buffer, (LONG)(wb_line_len * 8));
  252.         }
  253.         FreeMem(idata, (LONG)sizeof(struct InfoData));
  254.      }
  255.          FreeMem(fib, (LONG)sizeof(struct FileInfoBlock));
  256.       }
  257.       FreeMem(data_buffer, (LONG)((MAX_EDITOR_NAME_LEN + 1) +
  258.        (MAX_EDITOR_OPTS_LEN + 1) + MAX_FKEYS * ((MAX_USER_FUNCTION_LEN +
  259.                          1) + (MAX_FKEY_LEN + 1))));
  260.    }
  261. }
  262.