/[global]/global/libutil/langmap.c
ViewVC logotype

Diff of /global/libutil/langmap.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by h-iwamoto, Wed Sep 1 14:44:33 2004 UTC revision 1.2 by shigio, Thu Feb 24 01:33:48 2005 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2002, 2004 Tama Communications Corporation   * Copyright (c) 2002, 2004, 2005
3     *      Tama Communications Corporation
4   *   *
5   * This file is part of GNU GLOBAL.   * This file is part of GNU GLOBAL.
6   *   *
# Line 38  static STRBUF *active_map; Line 39  static STRBUF *active_map;
39    
40  /*  /*
41   * construct language map.   * construct language map.
42     *
43     * copy string langmap and convert it to language map like this:
44     *
45     * langmap (string)     "c:.c.h,java:.java,cpp:.C.H"
46     *      |
47     *      v
48     * language map         c\0.c.h\0java\0.java\0cpp\0.C.H\0
49   */   */
50  void  void
51  setup_langmap(map)  setup_langmap(map)
52          const char *map;          const char *map;
53  {  {
54          char *p;          char *p;
55          int flag;          int onsuffix = 0;               /* not on suffix string */
56    
57          active_map = strbuf_open(0);          active_map = strbuf_open(0);
58          strbuf_puts(active_map, map);          strbuf_puts(active_map, map);
         flag = 0;  
59          for (p = strbuf_value(active_map); *p; p++) {          for (p = strbuf_value(active_map); *p; p++) {
60                  /*                  /*
61                   * "c:.c.h,java:.java,cpp:.C.H"                   * "c:.c.h,java:.java,cpp:.C.H"
62                   */                   */
63                  if ((flag == 0 && *p == ',') || (flag == 1 && *p == ':'))                  if ((onsuffix == 0 && *p == ',') || (onsuffix == 1 && *p == ':'))
64                          die_with_code(2, "syntax error in langmap '%s'.", map);                          die_with_code(2, "syntax error in langmap '%s'.", map);
65                  if (*p == ':' || *p == ',') {                  if (*p == ':' || *p == ',') {
66                          flag ^= 1;                          onsuffix ^= 1;
67                          *p = '\0';                          *p = '\0';
68                  }                  }
69          }          }
70          if (flag == 0)          if (onsuffix == 0)
71                  die_with_code(2, "syntax error in langmap '%s'.", map);                  die_with_code(2, "syntax error in langmap '%s'.", map);
72            /* strbuf_close(active_map); */
73  }  }
74    
75    /*
76     * decide the language of the suffix.
77     */
78  const char *  const char *
79  decide_lang(suffix)  decide_lang(suffix)
80          const char *suffix;          const char *suffix;
# Line 101  match_suffix_list(suffix, list) Line 112  match_suffix_list(suffix, list)
112          }          }
113          return 0;          return 0;
114  }  }
115    
116    /*
117     * make the suffixes value from langmap value.
118     */
119    void
120    make_suffixes(langmap, sb)
121            char *langmap;
122            STRBUF *sb;
123    {
124            char *p;
125            int onsuffix = 0;               /* not on suffix string */
126            int first_dot = 1;
127    
128            for (p = langmap; *p; p++) {
129                    /*
130                     * "c:.c.h,java:.java,cpp:.C.H"
131                     */
132                    if ((onsuffix == 0 && *p == ',') || (onsuffix == 1 && *p == ':'))
133                            die_with_code(2, "syntax error in langmap '%s'.", langmap);
134                    if (*p == ':')
135                            onsuffix = 1;
136                    else if (*p == ',')
137                            onsuffix = 0;
138                    else if (onsuffix) {
139                            if (*p == '.') {
140                                    if (first_dot)
141                                            first_dot = 0;
142                                    else
143                                            strbuf_putc(sb, ',');
144                            } else
145                                    strbuf_putc(sb, *p);
146                    }
147            }
148            if (onsuffix == 0)
149                    die_with_code(2, "syntax error in langmap '%s'.", langmap);
150    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26