Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / programs / dtterm / tests / Rlogin / Rlogin.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: Rlogin.c /main/3 1995/10/31 11:52:58 rswiston $ */
24 #include <stdio.h>
25 #include <math.h>
26 #include  "synvar.h"
27 #include  "common.h"
28
29 #ifdef LOG
30 FILE *TermLog;
31 #define SAVELOG  fclose(TermLog); TermLog = fopen("term.log", "a");
32 #endif
33
34 char LogStr[200];
35
36
37 static char *LogAction[] = { 
38 /*0*/ "Testing Resource Option: loginShell True",
39 /*1*/ "Testing Resource Option: loginShell False",
40 /*2*/ "Testing Resource Option: loginShell on",
41 /*3*/ "Testing Resource Option: loginShell off",
42 };
43
44
45 static char *ResourceArr[] = {
46 /*0*/ "loginShell True",
47 /*1*/ "loginShell False",
48 /*2*/ "loginShell on",
49 /*2*/ "loginShell off",
50 };
51
52 int MakeResourceFile(ResArr)
53 char *ResArr;
54 {
55   FILE *ResFile;
56   int i, j, Len;
57   char Resource[50], Value[50];
58     
59     if ((ResFile = fopen("res", "w")) == NULL)
60        {LogError("Resource File Creation fail"); return(-1);}
61     for (i=0; i < 50; i++) Resource[i] = BLANK;
62     for (i=0; i < 50; i++) Value[i] = BLANK;
63     Len = strlen(ResArr); i=0;
64     while (i < Len) {
65       j = 0;
66       while (ResArr[i] != BLANK) Resource[j++] = ResArr[i++];
67       Resource[j] = NULLCHAR;
68       i++; j = 0;
69       while ((ResArr[i] != BLANK) && (ResArr[i] != NULLCHAR))
70             Value[j++] = ResArr[i++];
71       Value[j] = NULLCHAR;
72       i++;
73       fprintf(ResFile, "%s*%s: %s\n", TERM_EMU, Resource, Value);
74     }
75     fclose(ResFile);
76 }
77
78
79 #define ArrCount    (int) (sizeof(ResourceArr) / sizeof(char *))
80
81 main(argc, argv)
82 int argc;
83 char *argv[];
84 {
85    SynStatus Result;
86    char Command[NEED_LEN], *Shell, *Path, *CurDir;
87    int i;
88      
89 #ifdef LOG
90 if ((TermLog = fopen("term.log", "a")) == NULL) {
91    if ((TermLog = fopen("term.log", "w")) == NULL)
92       {printf("Logfile could not be opened \n"); exit(-1);}
93 }
94 LogError("****************************************************************************");
95 LogTime();
96 sprintf(Command, "TestName: <%s> STARTS\n", argv[0]);
97 LogError(Command);
98 #endif 
99      InitTest(argc, argv);
100      CheckCapsLock();
101      Path = getenv("PATH");
102      CurDir = getenv("PWD");
103      ExecCommand("PATH=.:../bin:../util:/usr/bin/X11:/bin:/opt/dt/bin"); 
104      for (i=0; i < ArrCount; i++) {
105        CheckCapsLock();
106        ExecCommand("xrdb -load xrdb.out");
107        MakeResourceFile(ResourceArr[i]);
108        CheckCapsLock();
109        LogError(LogAction[i]);
110        strcpy(Command, "xrdb -merge res; ");
111        strcat(Command, TERM_EMU);
112        ExecCommand(Command); sleep(2);
113        if (WaitWinMap("TermWin") < 0) continue;
114        strcpy(Command, CurDir); strcat(Command, "/../util/");
115        switch (i) {
116          case 0: 
117            strcat(Command, "test-ls");
118            ExecCommand(Command); break;
119          case 1: 
120            strcat(Command, "test+ls");
121            ExecCommand(Command); break;
122          case 2: 
123            strcat(Command, "test-ls");
124            ExecCommand(Command); break;
125          case 3: 
126            strcat(Command, "test+ls");
127            ExecCommand(Command); break;
128        }
129        CloseTerm("TermWin");
130        WaitWinUnMap("TermWin", 10L);
131 sleep(2);
132      }
133      strcpy(Command, "PATH="); 
134      strcat(Command, Path);
135      ExecCommand(Command);
136      CheckCapsLock();
137      ExecCommand("xrdb -load xrdb.out");
138      CloseTest(False);
139 #ifdef LOG
140 sprintf(Command, "TestName: <%s> ENDS\n", argv[0]);
141 LogError(Command);
142 LogError("****************************************************************************");
143 fclose(TermLog);
144 #endif
145 }
146