home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 171.lha / DME_v1.30 / Sources / cmd3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-04-28  |  2.8 KB  |  177 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.  */
  14.  
  15. #include "defs.h"
  16. #include <local/xmisc.h>
  17. #include <stdio.h>
  18.  
  19. #define nomemory()  { memoryfail = 1; }
  20.  
  21. extern FONT *GetFont();
  22.  
  23. /*
  24.  *  SETFONT font size
  25.  */
  26.  
  27. void
  28. do_setfont()
  29. {
  30.     register FONT *font = GetFont(av[1], 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. do_ignorecase()
  47. {
  48.     register ED *ep = Ep;
  49.  
  50.     if (av[1][0]) {
  51.     switch(av[1][1] & 0x1F) {
  52.     case 'n'&0x1F:
  53.         ep->IgnoreCase = 1;
  54.         break;
  55.     case 'f'&0x1F:
  56.         ep->IgnoreCase = 0;
  57.         break;
  58.     case 'o'&0x1F:
  59.         ep->IgnoreCase = 1 - ep->IgnoreCase;
  60.         break;
  61.     }
  62.     if (ep->IgnoreCase)
  63.         title("Case InSensitive");
  64.     else
  65.         title("Case Sensitive");
  66.     }
  67. }
  68.  
  69. /*
  70.  *  VARIABLE SUPPORT!
  71.  */
  72.  
  73. #define VARS    struct _VARS
  74. VARS {
  75.     MNODE   Node;
  76.     char    *Name;
  77.     char    *Str;
  78. };
  79.  
  80. static MLIST SList = { (MNODE *)&SList.mlh_Tail, NULL, (MNODE *)&SList.mlh_Head };
  81.  
  82. void
  83. do_set()
  84. {
  85.     register VARS *v;
  86.  
  87.     do_unset();
  88.     if (v = malloc(sizeof(VARS))) {
  89.     if (v->Name = malloc(strlen(av[1])+1)) {
  90.         if (v->Str = malloc(strlen(av[2])+1)) {
  91.         AddHead(&SList, v);
  92.         strcpy(v->Name, av[1]);
  93.         strcpy(v->Str , av[2]);
  94.         return;
  95.         }
  96.         free(v->Name);
  97.     }
  98.     free(v);
  99.     }
  100.     nomemory();
  101. }
  102.  
  103. do_setenv()
  104. {
  105.     SetDEnv(av[1], av[2]);
  106. }
  107.  
  108. do_unset()
  109. {
  110.     register VARS *v;
  111.  
  112.     for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
  113.     if (strcmp(v->Name, av[1]) == 0) {
  114.         Remove(v);
  115.         free(v);
  116.         free(v->Name);
  117.         free(v->Str);
  118.         break;
  119.     }
  120.     }
  121. }
  122.  
  123. do_unsetenv()
  124. {
  125.     register char *ptr = (char *)av[1];
  126.     register char *tmp = malloc(4+strlen(ptr)+1);
  127.  
  128.     if (tmp) {
  129.     strcpy(tmp, "ENV:");
  130.     strcat(tmp, ptr);
  131.     mountrequest(0);
  132.     DeleteFile(tmp);
  133.     mountrequest(1);
  134.     free(tmp);
  135.     }
  136. }
  137.  
  138. /*
  139.  *  Search (1) internal list, (2) enviroment, (3) macros.  The variable
  140.  *  is allocated with malloc().  NULL if not found.  ENV: need not exist.
  141.  */
  142.  
  143. char *
  144. getvar(find)
  145. char *find;
  146. {
  147.     register char *str = NULL;
  148.     {
  149.     register VARS *v;
  150.  
  151.     for (v = (VARS *)SList.mlh_Head; v->Node.mln_Succ; v = (VARS *)v->Node.mln_Succ) {
  152.         if (strcmp(v->Name, find) == 0) {
  153.         if (str = malloc(strlen(v->Str)+1)) {
  154.             strcpy(str, v->Str);
  155.             return(str);
  156.         }
  157.         }
  158.     }
  159.     }
  160.  
  161.     mountrequest(0);
  162.     str = GetDEnv(find);
  163.     mountrequest(1);
  164.     if (str)
  165.     return(str);
  166.  
  167.     if ((str = keyspectomacro(find)) || (str = menutomacro(find))) {
  168.     register char *ptr = malloc(strlen(str)+1);
  169.     if (ptr) {
  170.         strcpy(ptr, str);
  171.         return(ptr);
  172.     }
  173.     }
  174.     return(NULL);
  175. }
  176.  
  177.