home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 007.lha / xicon / xicon.c < prev   
C/C++ Source or Header  |  1986-11-09  |  4KB  |  133 lines

  1. /****************************************************************
  2.  *                                                              *
  3.  *    XICON                                                     *
  4.  *                                                              *
  5.  *   Runs Command Script Files from an Icon                     *
  6.  *                                                              *
  7.  *   copyright 1986 by Pete Goodeve -- All Rights Reserved      *
  8.  *                                                              *
  9.  *    Compile with pass2 -v option (Lattice)                    *
  10.  *    Link with lstartup.obj, amiga.lib, lc.lib                 *
  11.  *                                                              *
  12.  * vers 86:8:11                                                 *
  13.  ****************************************************************/
  14.  
  15. #include "exec/types.h"
  16. #include "workbench/startup.h"
  17. #include "workbench/workbench.h"
  18. #include "workbench/icon.h"
  19.  
  20. LONG IconBase;
  21.  
  22. extern struct WBStartup *WBenchMsg;
  23.  
  24. struct WBArg *argptr;
  25. int nargs;
  26. int autoclose=FALSE, usescript=TRUE;
  27.  
  28. LONG outfile;
  29.  
  30. _main() /* bypasses standard C startup code */
  31. {
  32.  
  33.    if (!WBenchMsg)
  34.       return 0;
  35.  
  36.    IconBase = OpenLibrary(ICONNAME,1); /* doesn't matter much if not there */
  37.  
  38.    if (!(outfile = Open("CON:0/10/640/185/XICON 1.05", MODE_OLDFILE)))
  39.       return 0;
  40.  
  41.    argptr = WBenchMsg->sm_ArgList;
  42.    nargs = WBenchMsg->sm_NumArgs;
  43.    /* Skip the first arg (the program itself) and process the rest */
  44.    for(argptr++, nargs--; nargs; argptr++, nargs--)
  45.       doito(argptr);
  46.  
  47.    if (!autoclose) {
  48.       display("\n\n<<type ctrl-C to close window>>");
  49.       Wait(SIGBREAKF_CTRL_C | SIGBREAKF_CTRL_D);
  50.    }
  51.    Close(outfile);
  52.    if (IconBase) CloseLibrary(IconBase);
  53. }
  54. /*** end main ***/
  55.  
  56. /************************************************************
  57.  * In the code below, I don't follow the usual method of    *
  58.  * passing each command string in turn to Execute.  Instead *
  59.  * I pass the entire command file as the new input stream,  *
  60.  * which Execute accepts after processing the null string   *
  61.  * it gets as a "command".  This avoids the system having   *
  62.  * to reload the DOS "RUN" module for every line of the     *
  63.  * command file, though on the other hand it does lock out  *
  64.  * the possibility of redirecting keyboard input through    *
  65.  * the "current window" to the command.  I thought the      *
  66.  * trade-off was worth it.                                  *
  67.  ************************************************************/
  68.  
  69. doito(argp) struct WBArg *argp;
  70. {
  71.    LONG oldir;
  72.    LONG infile;
  73.  
  74.    usescript = TRUE; /* assume icon refers to a script file
  75.                         unless told otherwise (by ToolTypes) */
  76.    oldir = CurrentDir(argp->wa_Lock);
  77.    readtt(argp);
  78.    if (usescript) {
  79.       infile = Open(argp->wa_Name, MODE_OLDFILE);
  80.       Execute("", infile, outfile);
  81.       Close(infile);
  82.    }
  83.    CurrentDir(oldir);
  84. }
  85.  
  86. /* Read ToolTypes of current icon */
  87.  
  88. readtt(argp) struct WBArg *argp;
  89. {
  90.    struct DiskObject *iconobj=NULL, *GetDiskObject();
  91.    char **toolarray, *FindToolType();
  92.    char *modes;
  93.  
  94.    if (!IconBase) {
  95.       display("Icon Library not found -- ignoring ToolTypes\n");
  96.       return 0;
  97.    }
  98.    /* we don't do any checks here for icon type -- probably should...*/
  99.    if (!(iconobj = GetDiskObject(argp->wa_Name))) {
  100.       display("COULDN'T GET INFO FOR ICON!!\n");
  101.       return 0;
  102.    }
  103.    toolarray = iconobj->do_ToolTypes;
  104.    modes = FindToolType(toolarray,"MODE");
  105.    autoclose = MatchToolValue(modes,"closewindow");
  106.    usescript = !MatchToolValue(modes,"noscript");
  107.    dotoolcmds(toolarray); /* some tooltypes may be commands */
  108.    FreeDiskObject(iconobj);
  109. }
  110.  
  111.  
  112. /* Execute any commands specified in the ToolTypes */
  113.  
  114. dotoolcmds(toolarray) char **toolarray;
  115. {
  116.    char *holdnext, *cmdstr, *FindToolType();
  117.    while (*toolarray) {
  118.       holdnext = toolarray[1];
  119.       toolarray[1] = NULL;
  120.       if (cmdstr=FindToolType(toolarray,"CMD"))
  121.          Execute(cmdstr,0,outfile);
  122.       *++toolarray = holdnext; /* restore next item & move to it */
  123.    }
  124. }
  125.  
  126.  
  127. display(msg) char *msg;
  128. {
  129.    Write(outfile, msg, strlen(msg));
  130. }
  131. /**************************************/
  132.  
  133.