| 1540 | */ |
| 1541 | |
| 1542 | int x2sys_path_init (struct GMT_CTRL *GMT, struct X2SYS_INFO *S) { |
| 1543 | char file[PATH_MAX] = {""}, line[GMT_BUFSIZ] = {""}; |
| 1544 | FILE *fp = NULL; |
| 1545 | |
| 1546 | if (x2sys_set_home (GMT)) |
| 1547 | return (GMT_RUNTIME_ERROR); |
| 1548 | |
| 1549 | sprintf (file, "%s/%s/%s_paths.txt", X2SYS_HOME, S->TAG, S->TAG); |
| 1550 | |
| 1551 | n_x2sys_paths = 0; |
| 1552 | |
| 1553 | if ((fp = fopen (file, "r")) == NULL) { |
| 1554 | if (gmt_M_is_verbose (GMT, GMT_MSG_WARNING)) { |
| 1555 | GMT_Report (GMT->parent, GMT_MSG_WARNING, "Path file %s for %s files not found\n", file, S->TAG); |
| 1556 | GMT_Report (GMT->parent, GMT_MSG_WARNING, "(Will only look in current directory for such files)\n"); |
| 1557 | GMT_Report (GMT->parent, GMT_MSG_WARNING, "(mgd77[+] also looks in MGD77_HOME and mgg looks in GMT_SHAREDIR/mgg)\n"); |
| 1558 | } |
| 1559 | return GMT_NOERROR; |
| 1560 | } |
| 1561 | |
| 1562 | while (fgets (line, GMT_BUFSIZ, fp) && n_x2sys_paths < MAX_DATA_PATHS) { |
| 1563 | if (line[0] == '#') continue; /* Comments */ |
| 1564 | if (line[0] == ' ' || line[0] == '\0') continue; /* Blank line */ |
| 1565 | gmt_chop (line); /* Remove trailing CR or LF */ |
| 1566 | #ifdef WIN32 |
| 1567 | gmt_dos_path_fix (line); |
| 1568 | #endif |
| 1569 | x2sys_datadir[n_x2sys_paths] = gmt_M_memory (GMT, NULL, strlen (line)+1, char); |
| 1570 | strcpy (x2sys_datadir[n_x2sys_paths], line); |
| 1571 | n_x2sys_paths++; |
| 1572 | if (n_x2sys_paths == MAX_DATA_PATHS) { |
| 1573 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "Reached maximum directory (%d) count in %s!\n", MAX_DATA_PATHS, file); |
| 1574 | return GMT_DIM_TOO_LARGE; |
| 1575 | } |
| 1576 | } |
| 1577 | fclose (fp); |
| 1578 | |
| 1579 | /* Add cache dir, if set */ |
| 1580 | |
| 1581 | if (GMT->session.CACHEDIR && n_x2sys_paths < MAX_DATA_PATHS) { |
| 1582 | x2sys_datadir[n_x2sys_paths] = gmt_M_memory (GMT, NULL, strlen (GMT->session.CACHEDIR)+1, char); |
| 1583 | strcpy (x2sys_datadir[n_x2sys_paths], GMT->session.CACHEDIR); |
| 1584 | n_x2sys_paths++; |
| 1585 | if (n_x2sys_paths == MAX_DATA_PATHS) { |
| 1586 | GMT_Report (GMT->parent, GMT_MSG_ERROR, "Reached maximum directory (%d) count by adding cache dir!\n", MAX_DATA_PATHS); |
| 1587 | return GMT_DIM_TOO_LARGE; |
| 1588 | } |
| 1589 | } |
| 1590 | return GMT_NOERROR; |
| 1591 | } |
| 1592 | |
| 1593 | /* x2sys_get_data_path takes a track name as argument and returns the full path |
| 1594 | * to where this data file can be found. x2sys_path_init must be called first. |
no test coverage detected