home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff284.lzh / Dme / src / cmd3.c < prev    next >
C/C++ Source or Header  |  1989-11-27  |  4KB  |  220 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.  */
  15.  
  16. #include "defs.h"
  17. #include <local/xmisc.h>
  18. #include <stdio.h>
  19.  
  20.  
  21. #define nomemory()  { memoryfail = 1; }
  22.  
  23. /*
  24.  *  SETFONT font size
  25.  */
  26.  
  27. void
  28. do_setfont()
  29. {
  30.     register FONT *font = GetFont(av[1], (short)atoi(av[2]));
  31.     register ED *ep = Ep;
  32.     if (font) {
  33.     if (ep->Font)
  34.         CloseFont(ep->Font);
  35.     ep->Font = font;
  36.     SetFont(ep->Win->RPort, font);
  37.     SetRast(ep->Win->RPort, 0);
  38.     RefreshWindowFrame(ep->Win);
  39.     set_window_params();
  40.     text_redisplay();
  41.     } else {
  42.     title("Unable to find font");
  43.     }
  44. }
  45.  
  46. void
  47. do_ignorecase()
  48. {
  49.     register ED *ep = Ep;
  50.  
  51.     if (av[1][0]) {
  52.     switch(av[1][1] & 0x1F) {
  53.     case 'n'&0x1F:
  54.         ep->IgnoreCase = 1;
  55.         break;
  56.     case 'f'&0x1F:
  57.         ep->IgnoreCase = 0;
  58.         break;
  59.     case 'o'&0x1F:
  60.         ep->IgnoreCase = 1 - ep->IgnoreCase;
  61.         break;
  62.     }
  63.     if (ep->IgnoreCase)
  64.         title("Case InSensitive");
  65.     else
  66.         title("Case Sensitive");
  67.     }
  68. }
  69.  
  70. /*
  71.  *  av[1]
  72.  */
  73.  
  74. void
  75. do_cd()
  76. {
  77.     long oldlock;
  78.     long lock;
  79.  
  80.     oldlock = CurrentDir(Ep->dirlock);
  81.     if (lock = Lock(av[1], SHARED_LOCK)) {
  82.     UnLock(CurrentDir(oldlock));
  83.     Ep->dirlock = lock;
  84.     } else {
  85.     CurrentDir(oldlock);
  86.     Abortcommand = 1;
  87.     title("Unable to CD");
  88.     }
  89. }
  90.  
  91. /*
  92.  *  VARIABLE SUPPORT!
  93.  */
  94.  
  95. #define VARS    struct _VARS
  96. VARS {
  97.     MNODE   Node;
  98.     char    *Name;
  99.     char    *Str;
  100. };
  101.  
  102. static MLIST SList = { (MNODE *)&SList.mlh_Tail, NULL, (MNODE *)&SList.mlh_Head };
  103.  
  104. void
  105. do_set()
  106. {
  107.     register VARS *v;
  108.     void do_unset();
  109.  
  110.     do_unset();
  111.     if (v = malloc(sizeof(VARS))) {
  112.     if (v->Name = malloc(strlen(av[1])+1)) {
  113.         if (v->Str = malloc(strlen(av[2])+1)) {
  114.         AddHead((LIST *)&SList, (NODE *)v);
  115.         strcpy(v->Name, av[1]);
  116.         strcpy(v->Str , av[2]);
  117.         return;
  118.         }
  119.         free(v->Name);
  120.     }
  121.     free(v);
  122.     }
  123.     nomemory();
  124. }
  125.  
  126. void
  127. do_setenv()
  128. {
  129.     SetDEnv(av[1], av[2]);
  130. }
  131.  
  132. void
  133. do_unset()
  134. {
  135.     register VARS *v;
  136.  
  137.     for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
  138.     if (strcmp(v->Name, av[1]) == 0) {
  139.         Remove((NODE *)v);
  140.         free(v);
  141.         free(v->Name);
  142.         free(v->Str);
  143.         break;
  144.     }
  145.     }
  146. }
  147.  
  148. void
  149. do_unsetenv()
  150. {
  151.     register char *ptr = (char *)av[1];
  152.     register char *tmp = malloc(4+strlen(ptr)+1);
  153.  
  154.     if (tmp) {
  155.     strcpy(tmp, "ENV:");
  156.     strcat(tmp, ptr);
  157.     mountrequest(0);
  158.     DeleteFile(tmp);
  159.     mountrequest(1);
  160.     free(tmp);
  161.     }
  162. }
  163.  
  164. /*
  165.  *  Search (1) internal list, (2) enviroment, (3) macros.  The variable
  166.  *  is allocated with malloc().  NULL if not found.  ENV: need not exist.
  167.  */
  168.  
  169. char *
  170. getvar(find)
  171. char *find;
  172. {
  173.     register char *str = NULL;
  174.     {
  175.     register VARS *v;
  176.  
  177.     for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
  178.         if (strcmp(v->Name, find) == 0) {
  179.         if (str = malloc(strlen(v->Str)+1)) {
  180.             strcpy(str, v->Str);
  181.             return(str);
  182.         }
  183.         }
  184.     }
  185.     }
  186.  
  187.     mountrequest(0);
  188.     str = GetDEnv(find);
  189.     mountrequest(1);
  190.     if (str)
  191.     return(str);
  192.  
  193.     if ((str = keyspectomacro(find)) || (str = menutomacro(find))) {
  194.     register char *ptr = malloc(strlen(str)+1);
  195.     if (ptr) {
  196.         strcpy(ptr, str);
  197.         return(ptr);
  198.     }
  199.     }
  200.     return(NULL);
  201. }
  202.  
  203. void
  204. do_col()
  205. {
  206.     int col = atoi(av[1]) - 1;
  207.     short i;
  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.