home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 389.lha / dme_v1.40 / src / cmd3.c < prev    next >
C/C++ Source or Header  |  1990-07-03  |  4KB  |  276 lines

  1.  
  2. /*
  3.  * CMD3.C
  4.  *
  5.  *    (C)Copyright 1988 by Matthew Dillon, All Rights Reserved
  6.  *
  7.  *  SETFONT
  8.  *  IGNORECASE
  9.  *  SET
  10.  *  SETENV
  11.  *  UNSET
  12.  *  UNSETENV
  13.  *  CD
  14.  *  SAVECONFIG
  15.  *  FGPEN
  16.  *  BGPEN
  17.  */
  18.  
  19. #include "defs.h"
  20. #include <libraries/dos.h>
  21.  
  22. #define nomemory()  { memoryfail = 1; }
  23.  
  24. /*
  25.  *  SETFONT font size
  26.  */
  27.  
  28. void
  29. do_setfont()
  30. {
  31.     FONT *font = (FONT *)GetFont(av[1], (short)atoi(av[2]));
  32.     ED *ep = Ep;
  33.     if (font) {
  34.     if (ep->Font)
  35.         CloseFont(ep->Font);
  36.     ep->Font = font;
  37.     SetFont(ep->Win->RPort, font);
  38.     SetRast(ep->Win->RPort, 0);
  39.     RefreshWindowFrame(ep->Win);
  40.     set_window_params();
  41.     text_redisplay();
  42.     } else {
  43.     title("Unable to find font");
  44.     }
  45. }
  46.  
  47. void
  48. do_ignorecase()
  49. {
  50.     ED *ep = Ep;
  51.  
  52.     if (av[1][0]) {
  53.     switch(av[1][1] & 0x1F) {
  54.     case 'n'&0x1F:
  55.         ep->IgnoreCase = 1;
  56.         break;
  57.     case 'f'&0x1F:
  58.         ep->IgnoreCase = 0;
  59.         break;
  60.     case 'o'&0x1F:
  61.         ep->IgnoreCase = 1 - ep->IgnoreCase;
  62.         break;
  63.     }
  64.     if (ep->IgnoreCase)
  65.         title("Case InSensitive");
  66.     else
  67.         title("Case Sensitive");
  68.     }
  69. }
  70.  
  71. /*
  72.  *  av[1]
  73.  */
  74.  
  75. void
  76. do_cd()
  77. {
  78.     BPTR oldlock;
  79.     BPTR lock;
  80.  
  81.     oldlock = CurrentDir((BPTR)Ep->dirlock);
  82.     if (lock = Lock(av[1], SHARED_LOCK)) {
  83.     UnLock(CurrentDir(oldlock));
  84.     Ep->dirlock = (long)lock;
  85.     } else {
  86.     CurrentDir(oldlock);
  87.     Abortcommand = 1;
  88.     title("Unable to CD");
  89.     }
  90. }
  91.  
  92. /*
  93.  *  VARIABLE SUPPORT!
  94.  */
  95.  
  96. #define VARS    struct _VARS
  97. VARS {
  98.     MNODE   Node;
  99.     char    *Name;
  100.     char    *Str;
  101. };
  102.  
  103. static MLIST SList = { (MNODE *)&SList.mlh_Tail, NULL, (MNODE *)&SList.mlh_Head };
  104.  
  105. void
  106. do_set()
  107. {
  108.     VARS *v;
  109.     void do_unset();
  110.  
  111.     do_unset();
  112.     if (v = malloc(sizeof(VARS))) {
  113.     if (v->Name = malloc(strlen(av[1])+1)) {
  114.         if (v->Str = malloc(strlen(av[2])+1)) {
  115.         AddHead((LIST *)&SList, (NODE *)v);
  116.         strcpy(v->Name, av[1]);
  117.         strcpy(v->Str , av[2]);
  118.         return;
  119.         }
  120.         free(v->Name);
  121.     }
  122.     free(v);
  123.     }
  124.     nomemory();
  125. }
  126.  
  127. void
  128. do_setenv()
  129. {
  130.     SetDEnv(av[1], av[2]);
  131. }
  132.  
  133. void
  134. do_unset()
  135. {
  136.     VARS *v;
  137.  
  138.     for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
  139.     if (strcmp(v->Name, av[1]) == 0) {
  140.         Remove((NODE *)v);
  141.         free(v);
  142.         free(v->Name);
  143.         free(v->Str);
  144.         break;
  145.     }
  146.     }
  147. }
  148.  
  149. void
  150. do_unsetenv()
  151. {
  152.     char *ptr = (char *)av[1];
  153.     char *tmp = malloc(4+strlen(ptr)+1);
  154.  
  155.     if (tmp) {
  156.     strcpy(tmp, "ENV:");
  157.     strcat(tmp, ptr);
  158.     mountrequest(0);
  159.     DeleteFile(tmp);
  160.     mountrequest(1);
  161.     free(tmp);
  162.     }
  163. }
  164.  
  165. /*
  166.  *  Search (1) internal list, (2) enviroment, (3) macros.  The variable
  167.  *  is allocated with malloc().  NULL if not found.  ENV: need not exist.
  168.  */
  169.  
  170. char *
  171. getvar(find)
  172. char *find;
  173. {
  174.     char *str = NULL;
  175.     {
  176.     VARS *v;
  177.  
  178.     for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
  179.         if (strcmp(v->Name, find) == 0) {
  180.         if (str = malloc(strlen(v->Str)+1)) {
  181.             strcpy(str, v->Str);
  182.             return(str);
  183.         }
  184.         }
  185.     }
  186.     }
  187.  
  188.     mountrequest(0);
  189.     str = (char *)GetDEnv(find);
  190.     mountrequest(1);
  191.     if (str)
  192.     return(str);
  193.  
  194.     if ((str = keyspectomacro(find)) || (str = menutomacro(find))) {
  195.     char *ptr = malloc(strlen(str)+1);
  196.     if (ptr) {
  197.         strcpy(ptr, str);
  198.         return(ptr);
  199.     }
  200.     }
  201.     return(NULL);
  202. }
  203.  
  204. void
  205. do_col()
  206. {
  207.     int col = atoi(av[1]) - 1;
  208.  
  209.     if (col > 254 || col < 0) {
  210.     Abortcommand = 1;
  211.     return;
  212.     }
  213.     while (Clen < col)
  214.     Current[Clen++] = ' ';
  215.     Ep->Column = col;
  216.     if (Ep->Column - Ep->Topcolumn >= Columns || Ep->Column < Ep->Topcolumn)
  217.     text_sync();
  218. }
  219.  
  220. void
  221. do_saveconfig()
  222. {
  223.     ED *ep = Ep;
  224.     FILE *fi;
  225.  
  226.     if (ep->iconmode == 0) {
  227.     WIN *win = ep->Win;
  228.     ep->Winx      = win->LeftEdge;
  229.     ep->Winy      = win->TopEdge;
  230.     ep->Winwidth  = win->Width;
  231.     ep->Winheight = win->Height;
  232.     }
  233.  
  234.     if (fi = fopen("s:dme.config", "w")) {
  235.     fwrite(&ep->BeginConfig, (char *)&ep->EndConfig - (char *)&ep->BeginConfig, 1, fi);
  236.     fclose(fi);
  237.     }
  238. }
  239.  
  240. void
  241. loadconfig(ep)
  242. ED *ep;
  243. {
  244.     FILE *fi;
  245.  
  246.     if (fi = fopen("s:dme.config", "r")) {
  247.     fread(&ep->BeginConfig, (char *)&ep->EndConfig - (char *)&ep->BeginConfig, 1, fi);
  248.     fclose(fi);
  249.     }
  250. }
  251.  
  252. void
  253. do_fgpen()
  254. {
  255.     ED *ep = Ep;
  256.  
  257.     ep->FGPen = atoi(av[1]);
  258. }
  259.  
  260. void
  261. do_bgpen()
  262. {
  263.     ED *ep = Ep;
  264.  
  265.     ep->BGPen = atoi(av[1]);
  266. }
  267.  
  268. void
  269. do_hgpen()
  270. {
  271.     ED *ep = Ep;
  272.  
  273.     ep->HGPen = atoi(av[1]);
  274. }
  275.  
  276.