Mercurial > hg > octave-avbm
comparison src/utils.cc @ 287:6027a905fc06
[project @ 1994-01-13 01:41:00 by jwe]
author | jwe |
---|---|
date | Thu, 13 Jan 1994 01:42:10 +0000 |
parents | c2189d67a05c |
children | 3c23b8ea9099 |
comparison
equal
deleted
inserted
replaced
286:9c74d7d76f3d | 287:6027a905fc06 |
---|---|
55 #include <iostream.h> | 55 #include <iostream.h> |
56 #include <strstream.h> | 56 #include <strstream.h> |
57 #include <fstream.h> | 57 #include <fstream.h> |
58 #include <dirent.h> | 58 #include <dirent.h> |
59 | 59 |
60 #ifndef HAVE_STRCASECMP | |
61 extern "C" | |
62 { | |
63 extern int strcasecmp (const char*, const char*); | |
64 } | |
65 #endif | |
66 | |
67 #ifndef HAVE_STRNCASECMP | |
68 extern "C" | |
69 { | |
70 extern int strncasecmp (const char*, const char*, size_t); | |
71 } | |
72 #endif | |
73 | |
60 #define NLENGTH(dirent) (strlen((dirent)->d_name)) | 74 #define NLENGTH(dirent) (strlen((dirent)->d_name)) |
61 | 75 |
62 extern "C" | 76 extern "C" |
63 { | 77 { |
64 #if defined (HAVE_TERMIOS_H) | 78 #if defined (HAVE_TERMIOS_H) |
215 static int curr_on = 0; | 229 static int curr_on = 0; |
216 | 230 |
217 int tty_fd = STDIN_FILENO; | 231 int tty_fd = STDIN_FILENO; |
218 if (! isatty (tty_fd)) | 232 if (! isatty (tty_fd)) |
219 { | 233 { |
220 if (interactive || forced_interactive) | 234 if (interactive) |
221 error ("stdin is not a tty!"); | 235 error ("stdin is not a tty!"); |
222 return; | 236 return; |
223 } | 237 } |
224 | 238 |
225 if (on == curr_on) | 239 if (on == curr_on) |
1269 if (plot_stream.is_open ()) | 1283 if (plot_stream.is_open ()) |
1270 plot_stream.close (); | 1284 plot_stream.close (); |
1271 } | 1285 } |
1272 | 1286 |
1273 int | 1287 int |
1274 almost_match (const char *std, const char *s, int min_match_len = 1) | 1288 almost_match (const char *std, const char *s, |
1289 int min_match_len = 1, int case_sens = 1) | |
1275 { | 1290 { |
1276 int stdlen = strlen (std); | 1291 int stdlen = strlen (std); |
1277 int slen = strlen (s); | 1292 int slen = strlen (s); |
1278 | 1293 |
1279 return (slen <= stdlen | 1294 return (slen <= stdlen |
1280 && slen >= min_match_len | 1295 && slen >= min_match_len |
1281 && strncmp (std, s, slen) == 0); | 1296 && (case_sens |
1297 ? (strncmp (std, s, slen) == 0) | |
1298 : (strncasecmp (std, s, slen) == 0))); | |
1299 } | |
1300 | |
1301 /* | |
1302 * Ugh. | |
1303 */ | |
1304 int | |
1305 keyword_almost_match (const char **std, int *min_len, const char *s, | |
1306 int min_toks_to_match, int max_toks) | |
1307 { | |
1308 int status = 0; | |
1309 int tok_count = 0; | |
1310 int toks_matched = 0; | |
1311 | |
1312 if (s == NULL || *s == '\0' || max_toks < 1) | |
1313 return status; | |
1314 | |
1315 char *kw = strsave (s); | |
1316 | |
1317 char *t = kw; | |
1318 while (*t != '\0') | |
1319 { | |
1320 if (*t == '\t') | |
1321 *t = ' '; | |
1322 t++; | |
1323 } | |
1324 | |
1325 char *beg = kw; | |
1326 while (*beg == ' ') | |
1327 beg++; | |
1328 | |
1329 if (*beg == '\0') | |
1330 return status; | |
1331 | |
1332 | |
1333 char **to_match = new char * [max_toks + 1]; | |
1334 char **s1 = std; | |
1335 char **s2 = to_match; | |
1336 | |
1337 if (s1 == NULL || s2 == NULL) | |
1338 goto done; | |
1339 | |
1340 s2[tok_count] = beg; | |
1341 char *end; | |
1342 while ((end = strchr (beg, ' ')) != NULL) | |
1343 { | |
1344 *end = '\0'; | |
1345 beg = end + 1; | |
1346 | |
1347 while (*beg == ' ') | |
1348 beg++; | |
1349 | |
1350 if (*beg == '\0') | |
1351 break; | |
1352 | |
1353 tok_count++; | |
1354 if (tok_count >= max_toks) | |
1355 goto done; | |
1356 | |
1357 s2[tok_count] = beg; | |
1358 } | |
1359 s2[tok_count+1] = NULL; | |
1360 | |
1361 s2 = to_match; | |
1362 | |
1363 for (;;) | |
1364 { | |
1365 if (! almost_match (*s1, *s2, min_len[toks_matched], 0)) | |
1366 goto done; | |
1367 | |
1368 toks_matched++; | |
1369 | |
1370 s1++; | |
1371 s2++; | |
1372 | |
1373 if (! *s2) | |
1374 { | |
1375 status = (toks_matched >= min_toks_to_match); | |
1376 goto done; | |
1377 } | |
1378 | |
1379 if (! *s1) | |
1380 goto done; | |
1381 } | |
1382 | |
1383 done: | |
1384 | |
1385 delete [] kw; | |
1386 delete [] to_match; | |
1387 | |
1388 return status; | |
1282 } | 1389 } |
1283 | 1390 |
1284 char ** | 1391 char ** |
1285 get_m_file_names (int& num, const char *dir, int no_suffix) | 1392 get_m_file_names (int& num, const char *dir, int no_suffix) |
1286 { | 1393 { |