⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 map3270.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
	    lex = Get();	}    }    UnGet(lex);}static voidFreeState(pState)state *pState;{    extern int free();    free((char *)pState);}static state *GetState(){    state *pState;    extern char *malloc();    pState = (state *) malloc(sizeof (state));    pState->result = STATE_NULL;    pState->next = 0;    return(pState);}static state *FindMatchAtThisLevel(pState, character)state	*pState;int	character;{    while (pState) {	if (pState->match == character) {	    return(pState);	}	pState = pState->next;    }    return(0);}static state *PasteEntry(head, string, count, identifier)state			*head;		/* points to who should point here... */char			*string;	/* which characters to paste */int			count;		/* number of character to do */char			*identifier;	/* for error messages */{    state *pState, *other;    if (!doPaste) {		/* flag to not have any side effects */	return((state *)1);    }    if (!count) {	return(head);	/* return pointer to the parent */    }    if ((head->result != STATE_NULL) && (head->result != STATE_GOTO)) {	/* this means that a previously defined sequence is an initial	 * part of this one.	 */	fprintf(stderr, "Conflicting entries found when scanning %s\n",		identifier);	return(0);    }#   ifdef	DEBUG	if (debug) {	    fprintf(stderr, "%s", uncontrol(*string));	}#   endif	/* DEBUG */    pState = GetState();    pState->match = *string;    if (head->result == STATE_NULL) {	head->result = STATE_GOTO;	head->address = pState;	other = pState;    } else {		/* search for same character */	if ((other = FindMatchAtThisLevel(head->address, *string)) != 0) {	    FreeState(pState);	} else {	    pState->next = head->address;	    head->address = pState;	    other = pState;	}    }    return(PasteEntry(other, string+1, count-1, identifier));}staticGetInput(tc, identifier)int tc;char *identifier;		/* entry being parsed (for error messages) */{    stringWithLength *outputString;    state *head;    state fakeQueue;    if (doPaste) {	head = headOfQueue;	/* always points to level above this one */    } else {	head = &fakeQueue;	/* don't have any side effects... */    }    if ((outputString = GetQuotedString()) == 0) {	return(0);    } else if (IsPrint(outputString->array[0])) {	fprintf(stderr,	 "first character of sequence for %s is not a control type character\n",		identifier);	return(0);    } else {	if ((head = PasteEntry(head, outputString->array,				outputString->length, identifier)) == 0) {	    return(0);	}	GetWS();	while ((outputString = GetQuotedString()) != 0) {	    if ((head = PasteEntry(head, outputString->array,				outputString->length, identifier)) == 0) {		return(0);	    }	    GetWS();	}    }    if (!doPaste) {	return(1);    }    if ((head->result != STATE_NULL) && (head->result != tc)) {	/* this means that this sequence is an initial part	 * of a previously defined one.	 */	fprintf(stderr, "Conflicting entries found when scanning %s\n",		identifier);	return(0);    } else {	head->result = tc;	return(1);		/* done */    }}staticGetDefinition(){    stringWithLength *string;    int Tc;    GetWS();    if ((string = GetAlphaMericString()) == 0) {	return(0);    }    string->array[string->length] = 0;    if (doPaste) {	if ((Tc = (*GetTc)(string->array)) == -1) {	    if (picky) {		fprintf(stderr, "%s: unknown 3270 key identifier\n",							string->array);	    }	    Tc = STATE_NULL;	}    } else {	Tc = STATE_NULL;		/* XXX ? */    }    GetWS();    if (!GetCharacter('=')) {	fprintf(stderr,		"Required equal sign after 3270 key identifier %s missing\n",			string->array);	return(0);    }    GetWS();    if (!GetInput(Tc, string->array)) {	fprintf(stderr, "Missing definition part for 3270 key %s\n",				string->array);	return(0);    } else {	GetWS();	while (GetCharacter('|')) {#	    ifdef	DEBUG		if (debug) {		    fprintf(stderr, " or ");		}#	    endif	/* DEBUG */	    GetWS();	    if (!GetInput(Tc, string->array)) {		fprintf(stderr, "Missing definition part for 3270 key %s\n",					string->array);		return(0);	    }	    GetWS();	}    }    GetWS();    if (!GetCharacter(';')) {	fprintf(stderr, "Missing semi-colon for 3270 key %s\n", string->array);	return(0);    }#   ifdef	DEBUG	if (debug) {	    fprintf(stderr, ";\n");	}#   endif	/* DEBUG */    return(1);}staticGetDefinitions(){    if (!GetDefinition()) {	return(0);    } else {	while (GetDefinition()) {	    ;	}    }    return(1);}staticGetBegin(){    GetWS();    if (!GetCharacter('{')) {	return(0);    }    return(1);}staticGetEnd(){    GetWS();    if (!GetCharacter('}')) {	return(0);    }    return(1);}staticGetName(){    if (!GetAlphaMericString()) {	return(0);    }    GetWS();    while (GetAlphaMericString()) {	GetWS();    }    return(1);}staticGetNames(){    GetWS();    if (!GetName()) {	return(0);    } else {	GetWS();	while (GetCharacter('|')) {	    GetWS();	    if (!GetName()) {		return(0);	    }	}    }    return(1);}staticGetEntry0(){    if (!GetBegin()) {	fprintf(stderr, "no '{'\n");	return(0);    } else if (!GetDefinitions()) {	fprintf(stderr, "unable to parse the definitions\n");	return(0);    } else if (!GetEnd()) {	fprintf(stderr, "No '}' or scanning stopped early due to error.\n");	return(0);    } else {	/* done */	return(1);    }}staticGetEntry(){    if (!GetNames()) {	fprintf(stderr, "Invalid name field in entry.\n");	return(0);    } else {	return(GetEntry0());    }}/* position ourselves within a given filename to the entry for the current *	KEYBD (or TERM) variable */Position(filename, keybdPointer)char *filename;char *keybdPointer;{    lexicon lex;    stringWithLength *name = 0;    stringWithLength *oldName;#   define	Return(x) {doPaste = 1; return(x);}    doPaste = 0;    if ((ourFile = fopen(filename, "r")) == NULL) {#   if !defined(MSDOS)	fprintf(stderr, "Unable to open file %s\n", filename);#   endif /* !defined(MSDOS) */	Return(0);    }    lex = Get();    while (lex.type != LEX_END_OF_FILE) {	UnGet(lex);	/* now, find an entry that is our type. */	GetWS();	oldName = name;	if ((name = GetAlphaMericString()) != 0) {	    if (!ustrcmp(name->array, keybdPointer)) {		/* need to make sure there is a name here... */		lex.type = LEX_CHAR;		lex.value = 'a';		UnGet(lex);		Return(1);	    }	} else if (GetCharacter('|')) {	    ;		/* more names coming */	} else {	    lex = Get();	    UnGet(lex);	    if (lex.type != LEX_END_OF_FILE) {		    if (!GetEntry0()) {	/* start of an entry */			fprintf(stderr,			    "error was in entry for %s in file %s\n",			    (oldName)? oldName->array:"(unknown)", filename);		    Return(0);		}	    }	}	lex = Get();    }#if !defined(MSDOS)    fprintf(stderr, "Unable to find entry for %s in file %s\n", keybdPointer,		    filename);#endif	/* !defined(MSDOS) */    Return(0);}char *strsave(string)char *string;{    char *p;    extern char *malloc();    p = malloc((unsigned int)strlen(string)+1);    if (p != 0) {	strcpy(p, string);    }    return(p);}/* * InitControl - our interface to the outside.  What we should *  do is figure out keyboard (or terminal) type, set up file pointer *  (or string pointer), etc. */state *InitControl(keybdPointer, pickyarg, translator)char	*keybdPointer;int	pickyarg;		/* Should we be picky? */int	(*translator)();	/* Translates ascii string to integer */{    extern char *getenv();    int GotIt;    picky = pickyarg;    GetTc = translator;    if (keybdPointer == 0) {        keybdPointer = getenv("KEYBD");    }    if (keybdPointer == 0) {       keybdPointer = getenv("TERM");    }		    /*		     * Some environments have getenv() return		     * out of a static area.  So, save the keyboard name.		     */    if (keybdPointer) {        keybdPointer = strsave(keybdPointer);    }    environPointer = getenv("MAP3270");    if (environPointer	    && (environPointer[0] != '/')#if	defined(MSDOS)	    && (environPointer[0] != '\\')#endif	/* defined(MSDOS) */	    && (strncmp(keybdPointer, environPointer,			strlen(keybdPointer) != 0)		|| (environPointer[strlen(keybdPointer)] != '{'))) /* } */    {	environPointer = 0;    }    if ((!environPointer)#if	defined(MSDOS)		|| (*environPointer == '\\')#endif	/* defined(MSDOS) */		|| (*environPointer == '/')) {	usePointer = 0;	GotIt = 0;	if (!keybdPointer) {#if !defined(MSDOS)	    fprintf(stderr, "%s%s%s%s",		"Neither the KEYBD environment variable nor the TERM ",		"environment variable\n(one of which is needed to determine ",		"the type of keyboard you are using)\n",		"is set.  To set it, say 'setenv KEYBD <type>'\n");#endif	/* !defined(MSDOS) */	} else {	    if (environPointer) {		GotIt = Position(environPointer, keybdPointer);	    }	    if (!GotIt) {		GotIt = Position("/etc/map3270", keybdPointer);	    }	}	if (!GotIt) {	    if (environPointer) {		GotIt = Position(environPointer, "unknown");	    }	    if (!GotIt) {		GotIt = Position("/etc/map3270", keybdPointer);	    }	}	if (!GotIt) {#if !defined(MSDOS)	    fprintf(stderr, "Using default key mappings.\n");#endif	/* !defined(MSDOS) */	    usePointer = 1;		/* flag use of non-file */	    whichkey = keysgeneric;	    environPointer = *whichkey;	/* use default table */	}    } else {	usePointer = 1;    }    (void) GetEntry();    return(firstentry.address);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -