File: macrokey.c

package info (click to toggle)
chdrv 1.0.13-0.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,204 kB
  • ctags: 1,069
  • sloc: ansic: 8,972; perl: 412; asm: 234; makefile: 195; sh: 36
file content (87 lines) | stat: -rw-r--r-- 1,683 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "chinese.h"
#include "input.h"
static char *macrostr[26];
void Init_macrokey()
{
    FILE *fp;
    char *macrofile = getenv("CHDRV_MACRO");
    char buf[256];
    int lineno,i;

    if (macrofile == NULL)
/*      macrofile = CHSYS"chdrv.mac"; */
      macrofile = "/etc/chdrv.mac";
    for(i=0;i<26;i++)
      macrostr[i] = NULL;

    fp = fopen(macrofile,"r");
    if (fp == NULL)
      {
	  printf("Can't open macro file\n");
	  return;
      }
    lineno = 1;
    while(fgets(buf,256,fp))
      {
	  char *ss,*str;
	  int no;

	  ss = buf;
	  while(*ss&&isspace(*ss)) ss++;
	  if (*ss == '#')
	    continue;
	  while(*ss&&(*ss!= ' ')&&(*ss!='\t')&&(*ss!='\n')) ss++;
	  *ss = 0;
	  ss++;
	  while(*ss&&((*ss==' ')||(*ss=='\t')||(*ss=='\n'))) ss++;
	  str = ss;
	  while(*ss&&(*ss!= ' ')&&(*ss!='\t')&&(*ss!='\n')) ss++;
	  *ss = 0;

	  if (buf[1] != 0)
	    {
		printf("line %d:index error,only allow one char\n",lineno);
	    }
	  else
	    if ((*buf <= 'z') && (*buf >= 'a'))
	      {
		  if (macrostr[*buf-'a'])
		    free(macrostr[*buf-'a']);
		  macrostr[*buf-'a'] = strdup(str);
	      }
	    else
	      printf("line %d:index %c is not valid\n",lineno,*buf);
	  lineno++;
      }
    fclose(fp);
}

char * add_macrokey(char *key,char *buf)
{
    int no;

    no = atoi(key);

    if ((no < 0 ) || (no > 26))
      SYSERR1("index %d too large",no);
    else
      {
	  SYSERR1("index %d",no);
	  if (macrostr[no])
	    {
		if (method!=0)
		  *buf++ = -1;
		strcpy(buf,macrostr[no]);
		buf += strlen(macrostr[no]);
		if (method!=0)
		  *buf++ = -1;
	    }
      }
    return buf;
}