1 /* @(#)findaed.c 1.3 05/05/83 2 * 3 * Copyright -C- 1982 Barry S. Roitblat 4 * 5 * This file contains a single routine which will find the correct 6 * AED display to use from the current terminal. 7 * 8 * (Modified from software written by John Ousterhout for the caesar 9 * program) 10 */ 11 12 #include "gremlin.h" 13 14 /* Imports from library routines: */ 15 16 extern FILE *fopen(); 17 extern char *ttyname(); 18 19 /* imports from config.c */ 20 21 extern char GDisplays[]; 22 23 char * 24 FindAED() 25 26 /*--------------------------------------------------------- 27 * This routine reads out the name of the terminal associated 28 * with the standard input, then selects an AED display to be 29 * used, based on that terminal name. 30 * 31 * Results: 32 * The return value is a pointer to a string that is the device 33 * name of the AED display to use. This name is found by searching 34 * in the file "displays" in the current search path. The file 35 * consists of pairs of strings. If the first string of a pair 36 * matches the name of our input terminal, then the second string 37 * of the pair is used as the AED device name. If no match occurs 38 * then /dev/null is used. 39 * 40 * Side Effects: None. 41 *--------------------------------------------------------- 42 */ 43 44 { 45 char name1[100], *tty; 46 static char name2[100]; 47 FILE *f; 48 tty = ttyname(fileno(stderr)); 49 if (tty == NULL) return NULL; 50 f = fopen(GDisplays, "r"); 51 if (f == NULL) return NULL; 52 while (TRUE) 53 { 54 if (fscanf(f, "%99s %99s", name1, name2) < 2) 55 { 56 (void) fclose(f); 57 return NULL; 58 } 59 if (strcmp(name1, tty) == 0) 60 { 61 (void) fclose(f); 62 return name2; 63 } 64 while (getc (f) > 10); /* ignore extra characters on a line */ 65 } 66 } 67