home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 287.lha / TY_v1.3 / src / system.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-07  |  2.8 KB  |  93 lines

  1. /*************************************************************************
  2.  ***                        system.c                     (JJB TEMPLAR) ***
  3.  *** Date begun: 27/8/89.                                              ***
  4.  *** Last modified: 27/8/89.                                           ***
  5.  *************************************************************************/
  6. /*** Some routines to handle Execute() stuff.                          ***
  7.  *************************************************************************/
  8.  
  9. #include <exec/types.h>
  10. #include <libraries/dos.h>
  11. #include <libraries/dosextens.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/dos.h>
  15.  
  16. #include <string.h>
  17.  
  18. extern char              current_file[];
  19. extern struct DosLibrary *DOSBase;
  20. extern BPTR              file; /* Have to close file so editor can write */
  21.  
  22. extern void error(char *,int);
  23. extern void bell();
  24. extern void edit(int);         /* To get back, hopefully */
  25. extern void clear();           /* So use real function! */
  26.  
  27. static char *title = "CON:0/11/640/80/CON: ty1.3 :D/c";
  28.  
  29. void    newcli();
  30. void    editor();
  31. int     gotenv();
  32.  
  33. void    newcli() /*======================================================*/
  34. {
  35. register BPTR   con;
  36.     if (!(con = Open(title,MODE_NEWFILE))) {
  37.         error("Failed to open console!",0);
  38.         bell();
  39.     }
  40.     else {
  41.         Execute("",con,0L);
  42.         Close(con);
  43.         error("Welcome back...",0);
  44.     }
  45. }
  46.  
  47. void    editor() /*======================================================*/
  48. {
  49. register BPTR   con;    /* Also used to open ENV:EDITOR */
  50. register int    len;
  51. char    buf[256];
  52.     if (!gotenv()) goto BADENV;
  53.     if (!(con = Open("ENV:EDITOR",MODE_OLDFILE))) goto BADENV;
  54.  
  55.     if ((len = Read(con,buf,80)) <= 0) goto BADENV;
  56.     Close(con);
  57.     buf[len] = ' ';     buf[len+1] = 0;
  58.     strcat(buf,current_file);
  59.     if (!(con = Open(title,MODE_NEWFILE))) {
  60.         error("Failed to open console!",0);
  61.         bell();
  62.     }
  63.     else {
  64.         Close(file);    file = NULL;    /* So edit won't try to re-Close */
  65.         clear();    flush();
  66.         Execute(buf,con,con);
  67.         Close(con);
  68.         edit(0);                        /* Zero means current file */
  69.         error("Welcome back...",0);
  70.     }
  71.     return;
  72. BADENV:
  73.     if (con) Close(con);
  74.     error("There's something wrong with ENV:EDITOR!",0);
  75.     bell();
  76. }
  77.  
  78. int     gotenv() /*======================================================*/
  79. {
  80. register struct DosInfo *di;
  81. register struct DosList *dl;
  82. register char           *name;
  83.  
  84.     di = (struct DosInfo *)(((struct RootNode *)(DOSBase->dl_Root))->rn_Info << 2);
  85.     dl = (struct DosList *)(di->di_DevInfo << 2);
  86.     while (dl) {
  87.         name = (char *)(dl->dol_Name << 2);
  88.         if (!strnicmp(name+1,"env",3)) break;
  89.         dl = (struct DosList *)(dl->dol_Next << 2);
  90.     }
  91.     return((dl)? 1:0);
  92. }
  93.