if (keyremaps != NULL) {  keyremap_t *next_remap, *curr_remap = keyremaps; while (curr_remap != NULL) { next_remap = curr_remap->next; free(curr_remap); curr_remap = next_remap; } keyremaps = NULL; } if (infile == NULL || *infile == '\0') {  return; }
void initialize_remap(char *infile) {	FILE *in;	char *p, *q, line[256], str1[256], str2[256];	int i;	KeySym ksym1, ksym2;	keyremap_t *remap, *current;	in = fopen(infile, "r"); 	if (in == NULL) {		/* assume cmd line key1-key2,key3-key4 */		if (! strchr(infile, '-') || (in = tmpfile()) == NULL) {			rfbLog("remap: cannot open: %s\n", infile);			rfbLogPerror("fopen");			clean_up_exit(1);		}		p = infile;		while (*p) {			if (*p == '-') {				fprintf(in, " ");			} else if (*p == ',' || *p == ' ' ||  *p == '\t') {				fprintf(in, "\n");			} else {				fprintf(in, "%c", *p);			}			p++;		}		fprintf(in, "\n");		fflush(in);			rewind(in);	}	while (fgets(line, 256, in) != NULL) {		int blank = 1, isbtn = 0;		p = line;		while (*p) {			if (! isspace(*p)) {				blank = 0;				break;			}			p++;		}		if (blank) {			continue;		}		if (strchr(line, '#')) {			continue;		}		if ( (q = strchr(line, '-')) != NULL)   {			/* allow Keysym1-Keysym2 notation */			*q = ' ';			}				if (sscanf(line, "%s %s", str1, str2) != 2) {			rfbLog("remap: bad line: %s\n", line);			fclose(in);			clean_up_exit(1);		}		if (sscanf(str1, "0x%x", &i) == 1) {			ksym1 = (KeySym) i;		} else {			ksym1 = XStringToKeysym(str1);		}		if (sscanf(str2, "0x%x", &i) == 1) {			ksym2 = (KeySym) i;		} else {			ksym2 = XStringToKeysym(str2);		}		if (ksym2 == NoSymbol) {			int i;			if (sscanf(str2, "Button%d", &i) == 1) {				ksym2 = (KeySym) i;				isbtn = 1; 			}		}		if (ksym1 == NoSymbol || ksym2 == NoSymbol) {			rfbLog("warning: skipping bad remap line: %s", line);			continue;		}		remap = (keyremap_t *) malloc((size_t) sizeof(keyremap_t));		remap->before = ksym1;		remap->after  = ksym2;		remap->isbutton = isbtn;		remap->next   = NULL;		rfbLog("remapping: (%s, 0x%x) -> (%s, 0x%x) isbtn=%d\n", str1,		    ksym1, str2, ksym2, isbtn);		if (keyremaps == NULL) {			keyremaps = remap;		} else {			current->next = remap;		}		current = remap;	}	fclose(in);}