home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 402.lha / AddTools_v1.0 / AddTools.C < prev    next >
C/C++ Source or Header  |  1990-07-31  |  4KB  |  140 lines

  1. /**********************************************************************/
  2. /*                                                                    */
  3. /*      AddTools - Adds menu items to the Workbench Tools menu.       */
  4. /*                                                                    */
  5. /*         Takes one argument, an input file, which contains          */
  6. /*         a line of menu item and a line of command for each         */
  7. /*                         menu item desired.                         */
  8. /*                                                                    */
  9. /*                          by Steve Tibbett                          */
  10. /*                                                                    */
  11. /**********************************************************************/
  12.  
  13. #include "exec/types.h"
  14. #include "exec/ports.h"
  15. #include "include:/compiler_headers_2.0/workbench/workbench.h"
  16. #include "include:/compiler_headers_2.0/pragmas/wb.h"
  17. #include "include:/compiler_headers_2.0/pragmas/dos.h"
  18. #include "include:/compiler_headers_2.0/pragmas/intuition.h"
  19. #include "intuition/intuition.h"
  20. #include <libraries/dos.h>
  21. #include <exec/memory.h>
  22. #include <string.h>
  23. #include "proto/exec.h"
  24.  
  25. struct Library *WorkbenchBase;
  26. struct Library *IntuitionBase;
  27.  
  28. struct AppMenuItem *AppList[32];
  29. char *AppListNames[32];
  30. char *AppListCommands[32];
  31. struct Remember *Remember=0;
  32. struct MsgPort *port;
  33. int NumApps=0;
  34. struct DOSBase *DOSBase;
  35.  
  36. void MemCleanup(void) { }
  37. void __fpinit(void) { }
  38. void __fpterm(void) { }
  39.  
  40. #define BREAK (SetSignal(0,0) & SIGBREAKF_CTRL_C)
  41.  
  42. /**********************************************************************/
  43. /*                     Lattice C Cleanup Routine                      */
  44. /**********************************************************************/
  45.  
  46. extern void *_ONEXIT;
  47.  
  48. void
  49. CleanupRoutine(void)
  50. {
  51. while (NumApps>=0)
  52.     RemoveAppMenuItem(AppList[--NumApps]);
  53.  
  54. if (Remember) FreeRemember(&Remember, TRUE);
  55. if (port) DeletePort(port);
  56. if (WorkbenchBase) CloseLibrary(WorkbenchBase);
  57. if (IntuitionBase) CloseLibrary(IntuitionBase);
  58. if (DOSBase) CloseLibrary(DOSBase);
  59. }
  60.  
  61. int
  62. fgets(LONG FP, char *buff)
  63. {
  64. int c;
  65.  
  66. while (TRUE)
  67.     {
  68.     c=fgetc(FP);
  69.     if (c=='\r'||c=='\n'||c==-1)
  70.         {
  71.         *buff=0;
  72.         if (c==-1) return(FALSE);
  73.             else return(TRUE);
  74.         };
  75.     *buff++=c;
  76.     }
  77. }
  78.  
  79. /**********************************************************************/
  80. /*                        It all happens here                         */
  81. /**********************************************************************/
  82. int
  83. _main(void)
  84. {
  85. LONG fp;
  86. struct AppMessage *msg;
  87.  
  88. DOSBase=OpenLibrary("dos.library", 0L);
  89.  
  90. _ONEXIT=CleanupRoutine;
  91.  
  92. if ((WorkbenchBase = OpenLibrary("workbench.library",36))==0)
  93.     return(0);
  94.  
  95. if ((IntuitionBase = OpenLibrary("intuition.library", 33))==0)
  96.     return(0);
  97.  
  98. if ((port = CreatePort("AddTools by Steve Tibbett",0L))==0)
  99.     return(0);
  100.  
  101. if ((fp=(LONG)Open("S:ToolsList", MODE_OLDFILE))==0)
  102.     return(0);
  103.  
  104. while (TRUE)
  105.     {
  106.     char buff[255];
  107.     char otherbuff[255];
  108.     if (fgets(fp, buff)==0) break;
  109.     if (fgets(fp, otherbuff)==0) break;
  110.     AppListNames[NumApps]=(char *)AllocRemember(&Remember, strlen(buff)+1, MEMF_CLEAR);
  111.     AppListCommands[NumApps]=(char *)AllocRemember(&Remember, strlen(otherbuff)+1, MEMF_CLEAR);
  112.     if (AppListCommands[NumApps]==0 || AppListNames[NumApps]==0)
  113.         return(0);
  114.     strcpy(AppListCommands[NumApps], otherbuff);
  115.     strcpy(AppListNames[NumApps], buff);
  116.     AppList[NumApps] = (struct AppMenuItem *)AddAppMenuItemA(NumApps,NumApps,AppListNames[NumApps],port,NULL);
  117.     NumApps++;
  118.     }
  119.  
  120. fclose(fp);
  121.  
  122. while (TRUE)
  123.     {
  124.     ULONG ID;
  125.  
  126.     Wait(1<<port->mp_SigBit|SIGBREAKF_CTRL_C);
  127.     msg = (struct AppMessage *) GetMsg(port);
  128.     if (msg==0)            /* If Msg=NULL then SIGBREAKF_CTRL_C */
  129.         break;
  130.  
  131.     ID=msg->am_ID;
  132.     ReplyMsg((struct Message *) msg);
  133.  
  134.     if (ID==99)
  135.         return(0);
  136.  
  137.     System(AppListCommands[ID], 0L);
  138.     }
  139. }
  140.