Develop and Download Open Source Software

Browse Subversion Repository

Diff of /trunk/teraterm/ttpset/ttset.c

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

revision 8106 by yutakapon, Tue Sep 10 14:42:39 2019 UTC revision 8205 by yutakapon, Fri Sep 20 14:16:59 2019 UTC
# Line 60  static PCHAR far RussList[] = Line 60  static PCHAR far RussList[] =
60          { "Windows", "KOI8-R", "CP-866", "ISO-8859-5", NULL };          { "Windows", "KOI8-R", "CP-866", "ISO-8859-5", NULL };
61  static PCHAR far RussList2[] = { "Windows", "KOI8-R", NULL };  static PCHAR far RussList2[] = { "Windows", "KOI8-R", NULL };
62    
63    
64    /*
65     * シリアルポート関連の設定定義
66     */
67    #define IDENDMARK 0xFFFF
68    
69    typedef struct id_str_pair {
70            WORD id;
71            char *str;
72    } id_str_pair_t;
73    
74    static id_str_pair_t serial_conf_databit[] = {
75            {IdDataBit7, "7"},
76            {IdDataBit8, "8"},
77            {IDENDMARK, NULL},
78    };
79    
80    static id_str_pair_t serial_conf_parity[] = {
81            {IdParityNone, "none"},
82            {IdParityOdd, "odd"},
83            {IdParityEven, "even"},
84            {IdParityMark, "mark"},
85            {IdParitySpace, "space"},
86            {IDENDMARK, NULL},
87    };
88    
89    static id_str_pair_t serial_conf_stopbit[] = {
90            {IdStopBit1, "1"},
91            {IdStopBit15, "1.5"},
92            {IdStopBit2, "2"},
93            {IDENDMARK, NULL},
94    };
95    
96    static id_str_pair_t serial_conf_flowctrl[] = {
97            {IdFlowX, "x"},
98            {IdFlowHard, "hard"},
99            {IdFlowHard, "rtscts"},
100            {IdFlowNone, "none"},
101            {IdFlowHardDsrDtr, "dsrdtr"},
102            {IDENDMARK, NULL},
103    };
104    
105    
106    /*
107     * シリアルポート関連の設定
108     * Idから文字列に変換する。
109     *
110     * return
111     *    TRUE: 変換成功
112     *    FALSE: 変換失敗
113     */
114    int PASCAL SerialPortConfconvertId2Str(enum serial_port_conf type, WORD id, PCHAR str, int strlen)
115    {
116            id_str_pair_t *conf;
117            int ret = FALSE;
118            int i;
119    
120            switch (type) {
121                    case COM_DATABIT:
122                            conf = serial_conf_databit;
123                            break;
124                    case COM_PARITY:
125                            conf = serial_conf_parity;
126                            break;
127                    case COM_STOPBIT:
128                            conf = serial_conf_stopbit;
129                            break;
130                    case COM_FLOWCTRL:
131                            conf = serial_conf_flowctrl;
132                            break;
133                    default:
134                            conf = NULL;
135                            break;
136            }
137            if (conf == NULL)
138                    goto error;
139    
140            for (i = 0 ;  ; i++) {
141                    if (conf[i].id == IDENDMARK)
142                            goto error;
143                    if (conf[i].id == id) {
144                            strncpy_s(str, strlen, conf[i].str, _TRUNCATE);
145                            break;
146                    }
147            }
148    
149            ret = TRUE;
150    
151    error:
152            return (ret);
153    }
154    
155    /*
156     * シリアルポート関連の設定
157     * 文字列からIdに変換する。
158     *
159     * return
160     *    TRUE: 変換成功
161     *    FALSE: 変換失敗
162     */
163    static int SerialPortConfconvertStr2Id(enum serial_port_conf type, PCHAR str, WORD *id)
164    {
165            id_str_pair_t *conf;
166            int ret = FALSE;
167            int i;
168    
169            switch (type) {
170                    case COM_DATABIT:
171                            conf = serial_conf_databit;
172                            break;
173                    case COM_PARITY:
174                            conf = serial_conf_parity;
175                            break;
176                    case COM_STOPBIT:
177                            conf = serial_conf_stopbit;
178                            break;
179                    case COM_FLOWCTRL:
180                            conf = serial_conf_flowctrl;
181                            break;
182                    default:
183                            conf = NULL;
184                            break;
185            }
186            if (conf == NULL)
187                    goto error;
188    
189            for (i = 0 ;  ; i++) {
190                    if (conf[i].id == IDENDMARK)
191                            goto error;
192                    if (_stricmp(conf[i].str, str) == 0) {
193                            *id = conf[i].id;
194                            break;
195                    }
196            }
197    
198            ret = TRUE;
199    
200    error:
201            return (ret);
202    }
203    
204    
205  WORD str2id(PCHAR far * List, PCHAR str, WORD DefId)  WORD str2id(PCHAR far * List, PCHAR str, WORD DefId)
206  {  {
207          WORD i;          WORD i;
# Line 1034  void PASCAL ReadIniFile(PCHAR FName, PTT Line 1176  void PASCAL ReadIniFile(PCHAR FName, PTT
1176          /* Parity */          /* Parity */
1177          GetPrivateProfileString(Section, "Parity", "",          GetPrivateProfileString(Section, "Parity", "",
1178                                  Temp, sizeof(Temp), FName);                                  Temp, sizeof(Temp), FName);
1179          if (_stricmp(Temp, "even") == 0)          if (!SerialPortConfconvertStr2Id(COM_PARITY, Temp, &ts->Parity)) {
                 ts->Parity = IdParityEven;  
         else if (_stricmp(Temp, "odd") == 0)  
                 ts->Parity = IdParityOdd;  
         else if (_stricmp(Temp, "mark") == 0)  
                 ts->Parity = IdParityMark;  
         else if (_stricmp(Temp, "space") == 0)  
                 ts->Parity = IdParitySpace;  
         else  
1180                  ts->Parity = IdParityNone;                  ts->Parity = IdParityNone;
1181            }
1182    
1183          /* Data bit */          /* Data bit */
1184          GetPrivateProfileString(Section, "DataBit", "",          GetPrivateProfileString(Section, "DataBit", "",
1185                                  Temp, sizeof(Temp), FName);                                  Temp, sizeof(Temp), FName);
1186          if (_stricmp(Temp, "7") == 0)          if (!SerialPortConfconvertStr2Id(COM_DATABIT, Temp, &ts->DataBit)) {
                 ts->DataBit = IdDataBit7;  
         else  
1187                  ts->DataBit = IdDataBit8;                  ts->DataBit = IdDataBit8;
1188            }
1189    
1190          /* Stop bit */          /* Stop bit */
1191          GetPrivateProfileString(Section, "StopBit", "",          GetPrivateProfileString(Section, "StopBit", "",
1192                                  Temp, sizeof(Temp), FName);                                  Temp, sizeof(Temp), FName);
1193          if (_stricmp(Temp, "2") == 0)          if (!SerialPortConfconvertStr2Id(COM_STOPBIT, Temp, &ts->StopBit)) {
                 ts->StopBit = IdStopBit2;  
         else if (_stricmp(Temp, "1.5") == 0)  
                 ts->StopBit = IdStopBit15;  
         else  
1194                  ts->StopBit = IdStopBit1;                  ts->StopBit = IdStopBit1;
1195            }
1196    
1197          /* Flow control */          /* Flow control */
1198          GetPrivateProfileString(Section, "FlowCtrl", "",          GetPrivateProfileString(Section, "FlowCtrl", "",
1199                                  Temp, sizeof(Temp), FName);                                  Temp, sizeof(Temp), FName);
1200          if (_stricmp(Temp, "x") == 0)          if (!SerialPortConfconvertStr2Id(COM_FLOWCTRL, Temp, &ts->Flow)) {
                 ts->Flow = IdFlowX;  
         else if (_stricmp(Temp, "hard") == 0)  
                 ts->Flow = IdFlowHard;  
         else if (_stricmp(Temp, "rtscts") == 0)  // hardとrtsctsは同じ意味  
                 ts->Flow = IdFlowHard;  
         else if (_stricmp(Temp, "dsrdtr") == 0)  
                 ts->Flow = IdFlowHardDsrDtr;  
         else  
1201                  ts->Flow = IdFlowNone;                  ts->Flow = IdFlowNone;
1202            }
1203    
1204          /* Delay per character */          /* Delay per character */
1205          ts->DelayPerChar =          ts->DelayPerChar =
# Line 2593  void PASCAL WriteIniFile(PCHAR FName, PT Line 2717  void PASCAL WriteIniFile(PCHAR FName, PT
2717          WritePrivateProfileString(Section, "BaudRate", Temp, FName);          WritePrivateProfileString(Section, "BaudRate", Temp, FName);
2718    
2719          /* Parity */          /* Parity */
2720          switch (ts->Parity) {          if (!SerialPortConfconvertId2Str(COM_PARITY, ts->Parity, Temp, sizeof(Temp))) {
         case IdParityEven:  
                 strncpy_s(Temp, sizeof(Temp), "even", _TRUNCATE);  
                 break;  
         case IdParityOdd:  
                 strncpy_s(Temp, sizeof(Temp), "odd", _TRUNCATE);  
                 break;  
         case IdParityMark:  
                 strncpy_s(Temp, sizeof(Temp), "mark", _TRUNCATE);  
                 break;  
         case IdParitySpace:  
                 strncpy_s(Temp, sizeof(Temp), "space", _TRUNCATE);  
                 break;  
         default:  
2721                  strncpy_s(Temp, sizeof(Temp), "none", _TRUNCATE);                  strncpy_s(Temp, sizeof(Temp), "none", _TRUNCATE);
2722          }          }
2723          WritePrivateProfileString(Section, "Parity", Temp, FName);          WritePrivateProfileString(Section, "Parity", Temp, FName);
2724    
2725          /* Data bit */          /* Data bit */
2726          if (ts->DataBit == IdDataBit7)          if (!SerialPortConfconvertId2Str(COM_DATABIT, ts->DataBit, Temp, sizeof(Temp))) {
                 strncpy_s(Temp, sizeof(Temp), "7", _TRUNCATE);  
         else  
2727                  strncpy_s(Temp, sizeof(Temp), "8", _TRUNCATE);                  strncpy_s(Temp, sizeof(Temp), "8", _TRUNCATE);
2728            }
2729          WritePrivateProfileString(Section, "DataBit", Temp, FName);          WritePrivateProfileString(Section, "DataBit", Temp, FName);
2730    
2731          /* Stop bit */          /* Stop bit */
2732          switch (ts->StopBit) {          if (!SerialPortConfconvertId2Str(COM_STOPBIT, ts->StopBit, Temp, sizeof(Temp))) {
         case IdStopBit2:  
                 strncpy_s(Temp, sizeof(Temp), "2", _TRUNCATE);  
                 break;  
         case IdStopBit15:  
                 strncpy_s(Temp, sizeof(Temp), "1.5", _TRUNCATE);  
                 break;  
         default:  
2733                  strncpy_s(Temp, sizeof(Temp), "1", _TRUNCATE);                  strncpy_s(Temp, sizeof(Temp), "1", _TRUNCATE);
                 break;  
2734          }          }
   
2735          WritePrivateProfileString(Section, "StopBit", Temp, FName);          WritePrivateProfileString(Section, "StopBit", Temp, FName);
2736    
2737          /* Flow control */          /* Flow control */
2738          switch (ts->Flow) {          if (!SerialPortConfconvertId2Str(COM_FLOWCTRL, ts->Flow, Temp, sizeof(Temp))) {
         case IdFlowX:  
                 strncpy_s(Temp, sizeof(Temp), "x", _TRUNCATE);  
                 break;  
         case IdFlowHard:  
                 strncpy_s(Temp, sizeof(Temp), "hard", _TRUNCATE);  
                 break;  
         case IdFlowHardDsrDtr:  
                 strncpy_s(Temp, sizeof(Temp), "dsrdtr", _TRUNCATE);  
                 break;  
         default:  
2739                  strncpy_s(Temp, sizeof(Temp), "none", _TRUNCATE);                  strncpy_s(Temp, sizeof(Temp), "none", _TRUNCATE);
2740          }          }
2741          WritePrivateProfileString(Section, "FlowCtrl", Temp, FName);          WritePrivateProfileString(Section, "FlowCtrl", Temp, FName);
# Line 4047  void PASCAL ParseParam(PCHAR Param, PTTS Line 4137  void PASCAL ParseParam(PCHAR Param, PTTS
4137                          if ((ParamCom < 1) || (ParamCom > ts->MaxComPort))                          if ((ParamCom < 1) || (ParamCom > ts->MaxComPort))
4138                                  ParamCom = 0;                                  ParamCom = 0;
4139                  }                  }
4140                    else if (_strnicmp(Temp, "/CDATABIT=", 10) == 0) {      /* COM data bit */
4141                            ParamPort = IdSerial;
4142                            SerialPortConfconvertStr2Id(COM_DATABIT, &Temp[10], &ts->DataBit);
4143                    }
4144                    else if (_strnicmp(Temp, "/CPARITY=", 9) == 0) {        /* COM Parity */
4145                            ParamPort = IdSerial;
4146                            SerialPortConfconvertStr2Id(COM_PARITY, &Temp[9], &ts->Parity);
4147                    }
4148                    else if (_strnicmp(Temp, "/CSTOPBIT=", 10) == 0) {      /* COM Stop bit */
4149                            ParamPort = IdSerial;
4150                            SerialPortConfconvertStr2Id(COM_STOPBIT, &Temp[10], &ts->StopBit);
4151                    }
4152                    else if (_strnicmp(Temp, "/CFLOWCTRL=", 11) == 0) {     /* COM Flow control */
4153                            ParamPort = IdSerial;
4154                            SerialPortConfconvertStr2Id(COM_FLOWCTRL, &Temp[11], &ts->Flow);
4155                    }
4156                    else if (_strnicmp(Temp, "/CDELAYPERCHAR=", 15) == 0) { /* COM Transmit delay per character (in msec) */
4157                            WORD val = 0;
4158    
4159                            ParamPort = IdSerial;
4160                            val = atoi(&Temp[15]);
4161                            ts->DelayPerChar = val;
4162                    }
4163                    else if (_strnicmp(Temp, "/CDELAYPERLINE=", 15) == 0) { /* COM Transmit delay per line (in msec) */
4164                            WORD val = 0;
4165    
4166                            ParamPort = IdSerial;
4167                            val = atoi(&Temp[15]);
4168                            ts->DelayPerLine = val;
4169                    }
4170                  else if (_stricmp(Temp, "/WAITCOM") == 0) {     /* wait COM arrival */                  else if (_stricmp(Temp, "/WAITCOM") == 0) {     /* wait COM arrival */
4171                          ts->WaitCom = 1;                          ts->WaitCom = 1;
4172                  }                  }

Legend:
Removed from v.8106  
changed lines
  Added in v.8205

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26