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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239
|
/*============================================================================
* Command line option parser and tracking.
*============================================================================*/
/*
This file is part of Code_Saturne, a general-purpose CFD tool.
Copyright (C) 1998-2014 EDF S.A.
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*----------------------------------------------------------------------------*/
#include "cs_config.h"
/*----------------------------------------------------------------------------
* Standard C library headers
*----------------------------------------------------------------------------*/
#include <assert.h>
#include <ctype.h> /* isdigit() */
#include <math.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h> /* atoi() */
#include <string.h> /* strlen() */
#include <time.h> /* time(), strftime() */
#if defined(HAVE_MKDIR)
#include <sys/stat.h>
#include <sys/types.h>
#endif
#if defined(HAVE_DUP2)
#include <unistd.h>
#endif
#if defined(HAVE_STAT)
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#endif
#if defined(HAVE_GETCWD)
#include <unistd.h>
#endif
#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
#include <pwd.h>
#endif
#if defined(HAVE_UNAME) || defined(HAVE_SYS_UTSNAME_H)
#include <sys/utsname.h>
#endif
#if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
# if defined(__uxpv__) && defined(HAVE_SYS_TYPES_H)
# include <sys/types.h> /* Workaround: missing include on VPP500 */
# endif
#include <sys/sysinfo.h>
#endif
/*----------------------------------------------------------------------------
* Local headers
*----------------------------------------------------------------------------*/
#include "ecs_file.h"
#include "ecs_mem.h"
#include "ecs_pre.h"
#if defined(HAVE_CGNS)
#include <cgnslib.h>
#endif
#if defined(HAVE_MED)
#include "ecs_med.h"
#endif
/*----------------------------------------------------------------------------
* Headers for the current file
*----------------------------------------------------------------------------*/
#include "ecs_cmd.h"
/*=============================================================================
* Macro definitions
*============================================================================*/
/*============================================================================
* Static global variables
*============================================================================*/
static char _sys_info_cpu_string[81] = "";
/*============================================================================
* Private function definitions
*============================================================================*/
/*!
* \brief Return basic available CPU info depending on system.
*
* \return Pointer to static string containing CPU info.
*/
#if defined(__linux__) || defined(__linux) || defined(linux)
static const char *
_sys_info_cpu(void)
{
FILE *fp;
char buf[81] ; /* Should be large enough for the
/proc/cpuinfo line we use */
int i;
char *s = NULL;
_sys_info_cpu_string[0] = '\0';
fp = fopen("/proc/cpuinfo", "r");
if (fp != NULL) {
s = fgets(buf, 80, fp);
while (s != NULL && strncmp(s, "model name", 10) != 0)
s = fgets(buf, 80, fp);
fclose (fp);
}
if (s != NULL) {
for ( ; *s != '\0' && *s != ':' ; s++);
if (*s == ':')
s++;
for ( ; *s != '\0' && *s == ' ' ; s++);
for (i = strlen(s) - 1;
i > 0 && (s[i] == ' ' || s[i] == '\n' || s[i] == '\r');
s[i--] = '\0');
strcpy(_sys_info_cpu_string, s);
}
return _sys_info_cpu_string;
}
#else
static const char *
_sys_info_cpu(void)
{
_sys_info_cpu_string[0] = '\0';
#if defined HAVE_SYS_UTSNAME_H
struct utsname sys_config;
if (uname(&sys_config) != -1)
strncpy(_sys_info_cpu_string, sys_config.machine, 80);
else
strcpy(_sys_info_cpu_string, "");
#else /* HAVE_SYS_UTSNAME_H */
strcpy(_sys_info_cpu_string, "");
#endif /* HAVE_SYS_UTSNAME_H */
return _sys_info_cpu_string;
}
#endif /* ECS_ARCH */
/*----------------------------------------------------------------------------
* Print version number
*----------------------------------------------------------------------------*/
static void
_print_version(void)
{
char str_date [ECS_STR_SIZE];
int ind_mois;
int nb_extensions = 0;
struct tm time_cnv;
const char nom_mois[12][4]
= {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
strcpy(str_date, ecs_glob_build_date);
/* Date de compilation */
for (ind_mois = 0; ind_mois < 12; ind_mois++) {
if (strncmp(str_date, nom_mois[ind_mois], 3) == 0) {
time_cnv.tm_mon = ind_mois;
break;
}
}
sscanf(str_date + 3, "%d", &(time_cnv.tm_mday));
sscanf(str_date + 6, "%d", &(time_cnv.tm_year));
time_cnv.tm_year -= 1900;
strcpy(str_date, __TIME__);
sscanf(str_date, "%d", &(time_cnv.tm_hour));
sscanf(str_date + 3, "%d", &(time_cnv.tm_min));
sscanf(str_date + 6, "%d", &(time_cnv.tm_sec));
time_cnv.tm_isdst = -1;
/* Recomputed and internationalized build date */
mktime(&time_cnv);
strftime(str_date, ECS_STR_SIZE - 1, "%c", &time_cnv);
#if defined (PACKAGE_VERSION)
printf(_("\n %s version %s (built %s)\n\n"),
PACKAGE_NAME, PACKAGE_VERSION, str_date);
#else
printf(_("\n (built %s)\n\n"), str_date);
#endif
#if defined(HAVE_CCM)
printf(_(" STAR-CCM+ file format support\n"));
nb_extensions++;
#endif
#if defined(HAVE_CGNS)
# if defined(CGNS_VERSION)
int cgns_ver_maj = CGNS_VERSION/1000;
int cgns_ver_min = (CGNS_VERSION % 1000) / 100;
int cgns_ver_rel = (CGNS_VERSION % 100) / 10;
printf(_(" CGNS %d.%d.%d file format support\n"),
cgns_ver_maj, cgns_ver_min, cgns_ver_rel);
# elif defined(NofValidAreaTypes)
printf(_(" CGNS %d.%d file format support\n"), 2, 2);
# else
printf(_(" CGNS %d.%d file format support\n"), 2, 1);
# endif
nb_extensions++;
#endif
#if defined(HAVE_MED)
ecs_med__version_shlib();
if (ecs_glob_med_ver_rel < 0)
printf(_(" MED %d.%d (HDF5 %d.%d.%d) file format support\n"),
ecs_glob_med_ver_maj, ecs_glob_med_ver_min,
ecs_glob_hdf5_ver_maj, ecs_glob_hdf5_ver_min,
ecs_glob_hdf5_ver_rel);
else
printf(_(" MED %d.%d.%d (HDF5 %d.%d.%d) file format support\n"),
ecs_glob_med_ver_maj, ecs_glob_med_ver_min,
ecs_glob_med_ver_rel, ecs_glob_hdf5_ver_maj,
ecs_glob_hdf5_ver_min, ecs_glob_hdf5_ver_rel);
nb_extensions++;
#endif
if (ecs_file_version_zlib() != NULL) {
printf(_(" Reading of compressed files ('.gz') with Zlib %s\n"),
ecs_file_version_zlib());
if (strcmp(ecs_file_version_zlib(),
ecs_file_version_build_zlib()) != 0)
printf(_(" (compiled with Zlib %s)\n"),
ecs_file_version_build_zlib());
nb_extensions++;
}
if (nb_extensions > 0)
printf("\n");
}
/*----------------------------------------------------------------------------
* Print command line, title, and version
*----------------------------------------------------------------------------*/
static void
_print_preamble(int argc,
char *argv[])
{
int iarg, ltot;
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
ltot = 0;
for (iarg = 0; iarg < argc; iarg++) {
ltot += strlen(argv[iarg]) + 1;
if (ltot > 80) {
printf("\n");
ltot = strlen(argv[iarg]) + 1;
}
printf("%s ", argv[iarg]);
}
printf(_("\n\n"
" .------------------------------.\n"
" | |\n"
" | Code_Saturne Preprocessor |\n"
" | |\n"
" `------------------------------'\n"));
_print_version();
}
/*----------------------------------------------------------------------------
* Utilitarian function for printing
*----------------------------------------------------------------------------*/
static void
_fct_prt(const char *opt,
const char *arg,
const char *texte)
{
size_t l = strlen(opt);
size_t pad = (l > 12) ? 16+12-l :16;
printf(" %-12s ", opt);
ecs_print_padded_str(arg, pad);
printf(" %s\n", texte);
}
/*----------------------------------------------------------------------------
* Print usage
*----------------------------------------------------------------------------*/
static void
_print_help(void)
{
char opt_str[81];
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
printf(_("\n\nUsage: %s [<options>] <file>\n"),
"cs_preprocess");
/* General options */
/*-----------------*/
printf(_("\n\nGeneral options:\n\n"));
_fct_prt("-h", "", _(": this help message"));
_fct_prt("--help", "", _(": same"));
printf("\n");
_fct_prt("--log", _("[file]"),
_(": redirect terminal output to a file"));
sprintf(opt_str, _(" (default file: \"%s\")"),
"preprocessor.log");
_fct_prt("", "", opt_str);
printf("\n");
_fct_prt("--no-write", "",
_(": do not write preprocessor output"));
printf("\n");
_fct_prt("-o", _("<file>"),
_(": output file name"));
sprintf(opt_str, _(" (default file: \"%s\")"),
"mesh_input");
_fct_prt("", "", opt_str);
_fct_prt("--out", _("<file>"), _(": same"));
printf("\n");
_fct_prt("--reorient", "",
_(": if necessary, correct orientation of"));
_fct_prt("", "", _(" cells and faces"));
printf("\n");
_fct_prt("--version", "",
_(": print version number"));
/* Mesh selection options */
/*------------------------*/
printf(_("\n\nMesh selection options:\n\n"));
_fct_prt("--format", _("<keyword>"),
_(": selection of mesh file format"));
_fct_prt("--num", "<n> [...]",
_(": selection of mesh numbers in file"));
_fct_prt("", "",
_(" (if the format allows it)"));
_fct_prt("--grp-cel", _("<keyword>"),
_(": add groups of cells"));
_fct_prt("", "", _(" * based on sections: keyword \"section\""));
_fct_prt("", "", _(" * based on zones: keyword \"zone\""));
_fct_prt("", "", _(" (based on format features/conventions)"));
_fct_prt("--grp-fac", _("<keyword>"),
_(": add groups of faces"));
_fct_prt("", "", _(" * based on sections: keyword \"section""\""));
_fct_prt("", "", _(" * based on zones: keyword \"zone""\""));
_fct_prt("", "", _(" (based on format features/conventions)"));
printf(_("\n\nAvailable mesh formats:\n"));
printf(_(" extension: keyword:\n"));
ecs_pre__aff_formats();
/* Post-processing options */
/*-------------------------*/
printf(_("\n\nPostprocessing options:\n\n"));
_fct_prt("--case",
_("<name>"),
_(": case name (without this option,"));
sprintf(opt_str,
_(" the default name is: \"%s\""),
"preprocess");
_fct_prt("", "", opt_str);
printf("\n");
_fct_prt("--post-error", _("[format]"),
_(": select output format of error meshes"));
_fct_prt("--post-volume", _("[format]"),
_(": activate output of volume meshes"));
printf(_("\n\nAvailable output formats:\n"));
printf(_(" keyword:\n"));
#if defined(HAVE_CGNS)
printf(" CGNS cgns\n");
#endif
printf(" EnSight Gold ensight\n");
#if defined(HAVE_MED)
printf(" MED med\n");
#endif
/* Environment variables */
/*-----------------------*/
printf("\n\n%s:\n\n",
_("Environment variables"));
printf(_(" CS_PREPROCESS_MIN_EDGE_LEN : "
"length under which an edge is considered\n"
" "
"degenerate (default: 1.e-15)\n\n"));
printf(_(" CS_PREPROCESS_MEM_LOG : "
"name of memory operations trace file\n\n"));
printf(_(" CS_PREPROCESS_IGNORE_IDEAS_COO_SYS : "
"ignore I-deas coordinate systems\n\n"));
}
/*----------------------------------------------------------------------------
* Fonction qui affiche un message indiquant
* qu'une meme option est mentionnee au moins 2 fois
*----------------------------------------------------------------------------*/
static void
ecs_loc_cmd__aff_opt_en_double(int argc,
char *argv[],
const char *opt)
{
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
_print_preamble(argc, argv);
_print_help();
ecs_error(__FILE__, __LINE__, 0,
_("Error in command line specification.\n\n"
"Option \"%s\" is set at least twice."), opt);
}
/*----------------------------------------------------------------------------
* Fonction qui affiche un message indiquant
* qu'il manque un argument a une option de la ligne de commande
*----------------------------------------------------------------------------*/
static void
ecs_loc_cmd__aff_manque_arg(int argc,
char *argv[],
const char *opt)
{
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
_print_preamble(argc, argv);
_print_help();
ecs_error(__FILE__, __LINE__, 0,
_("Error in command line specification.\n\n"
"Option \"%s\" requires an argument."), opt);
}
/*----------------------------------------------------------------------------
* Fonction qui lit les sous-options d'un post traitement
*----------------------------------------------------------------------------*/
static void
_read_post_opt(int argc,
char *argv[],
char post_type[8],
int *argpos)
{
int iarg = *argpos + 1;
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
strcpy(post_type, "ens"); /* default */
if (iarg < argc) {
if (!strcmp ("ensight", argv[iarg]))
*argpos += 1;
if (!strcmp ("cgns", argv[iarg])) {
#if defined(HAVE_CGNS)
strcpy(post_type, "cgns");
*argpos += 1;
#else
ecs_error(__FILE__, __LINE__, 0,
_("CGNS output format not available in this build."));
#endif
}
if (!strcmp ("med", argv[iarg])) {
#if defined(HAVE_MED)
strcpy(post_type, "med");
*argpos += 1;
#else
ecs_error(__FILE__, __LINE__, 0,
_("MED output format not available in this build."));
#endif
}
}
}
/*----------------------------------------------------------------------------
* Initialize command-line options
*----------------------------------------------------------------------------*/
static ecs_cmd_t *
_cmd_initialize(void)
{
size_t i, lng;
ecs_cmd_t *cmd;
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
ECS_MALLOC(cmd, 1, ecs_cmd_t);
/* Initialisations */
/*=================*/
cmd->fic_maillage = NULL;
lng = strlen("preprocess") + 1;
ECS_MALLOC(cmd->nom_cas, lng, char);
strcpy(cmd->nom_cas, "preprocess");
cmd->nom_out = NULL;
cmd->nbr_dump = 0;
cmd->n_num_maillage = 0;
cmd->num_maillage = NULL;
cmd->fmt_maillage = ECS_PRE_FORMAT_NUL;
cmd->grp_cel_section = false;
cmd->grp_cel_zone = false;
cmd->grp_fac_section = false;
cmd->grp_fac_zone = false;
for (i = 0; i < 8; i++) {
cmd->post_err[i] = '\0';
cmd->post_vol[i] = '\0';
}
strcpy(cmd->post_err, "ens"); /* default */
cmd->correct_orient = false;
return cmd;
}
/*----------------------------------------------------------------------------
* Fonction qui affiche la configuration du cas de lancement
*----------------------------------------------------------------------------*/
static void
ecs_loc_cmd__aff_config(ecs_cmd_t *cmd)
{
time_t date;
#if !defined(PATH_MAX)
#define PATH_MAX 1024
#endif
char str_date [ECS_STR_SIZE] = "";
char str_system [ECS_STR_SIZE] = "";
char str_machine [ECS_STR_SIZE] = "";
char str_ram [ECS_STR_SIZE] = "";
char str_user [ECS_STR_SIZE] = "";
char str_directory[PATH_MAX] = "";
size_t ram = 0;
int l_user;
#if defined(HAVE_UNAME)
struct utsname sys_config;
#endif
#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
struct passwd *pwd_user = NULL;
#endif
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/* Determination de la configuration du cas de lancement */
/*-------------------------------------------------------*/
/* Date */
if (time(&date) == -1 ||
strftime(str_date, ECS_STR_SIZE - 1, "%c", localtime(&date)) == 0)
strcpy(str_date, "");
/* Systeme et machine */
#if defined(HAVE_UNAME)
if (uname(&sys_config) != -1) {
strcpy(str_system, sys_config.sysname);
strcat(str_system, " ");
strcat(str_system, sys_config.release);
strcpy(str_machine, sys_config.nodename);
}
#endif
/* Nom de login */
#if defined(HAVE_GETPWUID) && defined(HAVE_GETEUID)
int l_info;
pwd_user = NULL;
pwd_user = getpwuid(geteuid());
if (pwd_user != NULL) {
str_user[ECS_STR_SIZE - 1] = '\0';
strncpy(str_user, pwd_user->pw_name, ECS_STR_SIZE - 1);
if (pwd_user->pw_gecos != NULL) {
l_user = strlen(str_user);
for (l_info = 0;
( pwd_user->pw_gecos[l_info] != '\0'
&& pwd_user->pw_gecos[l_info] != ',');
l_info++);
if (l_user + l_info + 3 < ECS_STR_SIZE) {
strcat(str_user, " (");
strncpy(str_user + l_user + 2, pwd_user->pw_gecos, l_info);
str_user[l_user + 2 + l_info] = ')';
str_user[l_user + 2 + l_info + 1] = '\0';
}
}
}
#endif /* defined(HAVE_GETPWUID) && defined(HAVE_GETEUID) */
/* Mémoire vive */
#if defined(HAVE_SYS_SYSINFO_H) && defined(HAVE_SYSINFO)
{
struct sysinfo info;
sysinfo(&info);
ram = info.totalram / 1024;
if (ram > 1)
sprintf(str_ram, "%lu", (unsigned long)ram);
}
#endif
/* Repertoire courant */
str_directory[0] = '\0';
#if defined(HAVE_GETCWD)
if (getcwd(str_directory, PATH_MAX) == NULL)
str_directory[0] = '\0';
#endif
/* Affichage de la configuration du cas de lancement */
/*---------------------------------------------------*/
printf("\n\n%s\n", _("Case configuration\n"
"------------------\n"));
if (strlen(str_date) > 0) {
printf(" ");
ecs_print_padded_str(_("Date"), 19);
printf(" : %s\n", str_date);
}
if (strlen(str_system) > 0) {
printf(" ");
ecs_print_padded_str(_("System"), 19);
printf(" : %s\n", str_system);
}
if (strlen(str_machine) > 0) {
printf(" ");
ecs_print_padded_str(_("Machine"), 19);
printf(" : %s\n", str_machine);
}
printf(" ");
ecs_print_padded_str(_("Processor"), 19);
printf(" : %s\n", _sys_info_cpu());
if (ram > 0) {
printf(" ");
ecs_print_padded_str(_("Memory"), 19);
printf(" : %s\n", str_ram);
}
if (strlen(str_user) > 0) {
printf(" ");
ecs_print_padded_str(_("User"), 19);
printf(" : %s\n", str_user);
}
if (strlen(str_directory) > 0) {
printf(" ");
ecs_print_padded_str(_("Directory"), 19);
printf(" : %s\n", str_directory);
}
printf("\n");
printf(" ");
ecs_print_padded_str(_("Case name"), 19);
printf(" : %s\n", cmd->nom_cas);
printf(" ");
ecs_print_padded_str(_("Mesh file"), 19);
printf(" : %s\n", cmd->fic_maillage);
printf("\n");
}
/*----------------------------------------------------------------------------
* Fonction qui diagnostique l'erreur de non accessibilite
* du fichier dont le nom est donne
*----------------------------------------------------------------------------*/
static void
ecs_loc_cmd__diagnost_non_acces(const char *fic_name,
const char *msg_cmd_err)
{
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
#if defined(ENOENT)
if (errno == ENOENT)
ecs_error(__FILE__, __LINE__, 0,
msg_cmd_err, fic_name, _("The file does not exist."));
#endif
#if defined(EACCES)
if (errno == EACCES)
ecs_error(__FILE__, __LINE__, 0,
msg_cmd_err, fic_name,
_("Read permission on this file is refused."));
#endif
#if defined(ENAMETOOLONG)
if (errno == ENAMETOOLONG)
ecs_error(__FILE__, __LINE__, 0,
msg_cmd_err, fic_name,
_("The filename is too long (system limit)."));
#endif
ecs_error(__FILE__, __LINE__, errno,
msg_cmd_err, fic_name, "");
}
/*----------------------------------------------------------------------------
* Fonction qui verifie que le nom du fichier donne
* correspond bien a un fichier physiquement existant
*----------------------------------------------------------------------------*/
static void
ecs_loc_cmd__teste_exist_fic(const char *fic_name,
const char *msg_cmd_err)
{
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
#if defined(HAVE_STAT)
struct stat buf;
if (stat(fic_name, &buf) != 0) {
ecs_loc_cmd__diagnost_non_acces(fic_name,
msg_cmd_err);
}
else {
if (S_ISREG(buf.st_mode) != true) {
ecs_error(__FILE__, __LINE__, 0,
msg_cmd_err,
fic_name, _("The file is not a regular file."));
}
}
#else /* HAVE_STAT */
FILE * fic;
if ((fic = fopen(fic_name, "r")) == NULL) {
ecs_loc_cmd__diagnost_non_acces(fic_name,
msg_cmd_err);
}
else {
fclose(fic);
}
#endif /* HAVE_STAT */
}
/*============================================================================
* Fonctions publiques
*============================================================================*/
/*----------------------------------------------------------------------------
* Fonction qui lit la ligne de commande
*----------------------------------------------------------------------------*/
ecs_cmd_t *
ecs_cmd__lit_arg(int argc,
char *argv[])
{
int iarg;
size_t lng;
bool bool_cmd_option_case = false;
bool bool_cmd_option_help = false;
bool bool_cmd_option_output_file = false;
bool bool_cmd_option_version = false;
bool bool_no_write = false;
bool bool_num = false;
ecs_cmd_t *cmd;
const char *cle_fmt = NULL;
const char arg_err_keyword[]
= N_("Error in command line specification.\n\n"
"Keyword \"%s\" of option \"%s\" is not recognized.\n");
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
/*----------------------------------------*/
/* Initialisation des options de commande */
/*----------------------------------------*/
cmd = _cmd_initialize();
/*---------------------------------------------*/
/* Lecture des options de la ligne de commande */
/*---------------------------------------------*/
for (iarg = 1; iarg < argc; iarg++) {
if (!strcmp ("--case", argv[iarg])) {
if (bool_cmd_option_case == false)
bool_cmd_option_case = true;
else
ecs_loc_cmd__aff_opt_en_double(argc, argv, argv[iarg]);
if (argc - 1 > iarg && strncmp(argv[iarg + 1], "-", 1)) {
lng = strlen(argv[++iarg]) + 1;
ECS_REALLOC(cmd->nom_cas, lng, char);
strcpy(cmd->nom_cas, argv[iarg]);
}
else {
ecs_loc_cmd__aff_manque_arg(argc, argv, argv[iarg]);
}
}
else if (!strcmp ("--dump", argv[iarg])) {
/* Option non documentee */
cmd->nbr_dump = 1;
/* 1 argument optionnel : nombre n d'elements affiches en echo */
if (argc -1 > iarg && strncmp(argv[iarg + 1], "-", 1))
cmd->nbr_dump = (ecs_int_t) atoi(argv[++iarg]);
}
else if (!strcmp ("--no-write", argv[iarg]))
bool_no_write = true;
else if (!strcmp("-h", argv[iarg]) ||
!strcmp("--help", argv[iarg]))
bool_cmd_option_help = true;
else if (!strcmp ("--post-error", argv[iarg]))
_read_post_opt(argc, argv, cmd->post_err, &iarg);
else if (!strcmp ("--post-volume", argv[iarg]))
_read_post_opt(argc, argv, cmd->post_vol, &iarg);
else if (!strcmp ("--log", argv[iarg])) {
int have_error = 0;
const char *outfic;
char *outfic_err;
FILE *ptrfic;
if (bool_cmd_option_output_file == false)
bool_cmd_option_output_file = true;
else
ecs_loc_cmd__aff_opt_en_double(argc, argv, argv[iarg]);
if (argc - 1 > iarg && strncmp(argv[iarg + 1], "-", 1))
outfic = argv[++iarg];
else
outfic = "preprocessor.log";
ECS_MALLOC(outfic_err, strlen(outfic) + strlen(".err") + 1, char);
sprintf(outfic_err, "%s.err", outfic);
#if defined(HAVE_DUP2)
if ((ptrfic = freopen(outfic, "w", stdout)) == NULL ||
dup2(fileno(ptrfic), fileno(stderr)) == -1)
have_error = 1;
#else
if (freopen(outfic, "w", stdout) == NULL ||
freopen(outfic_err, "w", stderr) == NULL)
have_error = 1;
#endif
if (have_error) {
_print_preamble(argc, argv);
ecs_error(__FILE__, __LINE__, errno,
_("It is impossible to redirect the standard output "
"to file:\n%s"), outfic);
}
ECS_FREE(outfic_err);
}
else if ( !strcmp ("-o", argv[iarg])
|| !strcmp ("--out", argv[iarg])) {
const char *outfic;
if (cmd->nom_out != NULL)
ecs_loc_cmd__aff_opt_en_double(argc, argv, argv[iarg]);
if (argc - 1 > iarg && strncmp(argv[iarg + 1], "-", 1))
outfic = argv[++iarg];
else
outfic = "mesh_input";
ECS_MALLOC(cmd->nom_out, strlen(outfic) + 1, char);
strcpy(cmd->nom_out, outfic);
}
else if (!strcmp ("--reorient", argv[iarg]))
cmd->correct_orient = true;
else if (!strcmp ("--version", argv[iarg]))
bool_cmd_option_version = true;
/* Option de choix de format */
else if (!strcmp ("--format", argv[iarg])) {
if (cle_fmt == NULL)
cle_fmt = argv[iarg + 1];
else
ecs_loc_cmd__aff_opt_en_double(argc, argv, argv[iarg]);
iarg++; /* Un argument lu -> avancer iarg */
}
/* Numéros de maillage */
else if (!strcmp ("--num", argv[iarg])) {
int iarg_num;
cmd->n_num_maillage = 0;
cmd->num_maillage = NULL;
if (bool_num == false)
bool_num = true;
else
ecs_loc_cmd__aff_opt_en_double(argc, argv, argv[iarg]);
for (iarg_num = iarg+1; iarg_num < argc; iarg_num++) {
if (! (isdigit(argv[iarg_num][0]) && atoi(argv[iarg + 1]) > 0))
break;
}
cmd->n_num_maillage = iarg_num - (iarg+1);
if (cmd->n_num_maillage == 0) {
_print_preamble(argc, argv);
_print_help();
ecs_error(__FILE__, __LINE__, 0,
_(arg_err_keyword), argv[iarg + 1], argv[iarg]);
}
ECS_MALLOC(cmd->num_maillage, cmd->n_num_maillage, int);
for (iarg_num = 0; iarg_num < cmd->n_num_maillage; iarg_num++)
cmd->num_maillage[iarg_num] = atoi(argv[++iarg]);
}
/* Sous-options de création de groupes de cellules */
else if (!strcmp ("--grp-cel", argv[iarg])) {
if ( iarg + 1 < argc
&& !strcmp("section", argv[iarg + 1]))
cmd->grp_cel_section = true;
else if ( iarg + 1 < argc
&& !strcmp("zone", argv[iarg + 1]))
cmd->grp_cel_zone = true;
else {
_print_preamble(argc, argv);
_print_help();
ecs_error(__FILE__, __LINE__, 0,
_(arg_err_keyword), argv[iarg + 1], argv[iarg]);
}
iarg++; /* Un sous-argument lu -> avancer iarg */
}
/* Création de groupes de faces */
else if (!strcmp ("--grp-fac", argv[iarg])) {
if (iarg + 1 < argc && !strcmp("section", argv[iarg + 1]))
cmd->grp_fac_section = true;
else if (iarg + 1 < argc && !strcmp("zone", argv[iarg + 1]))
cmd->grp_fac_zone = true;
else {
_print_preamble(argc, argv);
_print_help();
ecs_error(__FILE__, __LINE__, 0,
_(arg_err_keyword), argv[iarg + 1], argv[iarg]);
}
iarg++; /* Un sous-argument lu -> avancer iarg */
}
/* Nom de fichier */
else if (argv[iarg][0] != '-') {
ECS_MALLOC(cmd->fic_maillage, strlen(argv[iarg]) + 1, char);
strcpy(cmd->fic_maillage, argv[iarg]);
}
else {
_print_preamble(argc, argv);
_print_help();
ecs_error(__FILE__, __LINE__, 0,
_("Option \"%s\" is not recognized.\n"), argv[iarg]);
}
} /* Fin : boucle sur les arguments */
/*---------------------------------------------------------------*/
/* Affichage de la ligne de commande, du titre et de la version */
/*---------------------------------------------------------------*/
_print_preamble(argc, argv);
if (cmd->nom_out == NULL && bool_no_write == false) {
ECS_MALLOC(cmd->nom_out,
strlen("mesh_input") + 1,
char);
strcpy(cmd->nom_out, "mesh_input");
}
/*-----------------------------------------*/
/* Options devant etre traitees en premier */
/*-----------------------------------------*/
if (bool_cmd_option_help == true)
_print_help();
/*-------------------------------------------*/
/* Options provoquant l'arret de l'execution */
/*-------------------------------------------*/
if ( (argc <= 1)
|| ( bool_cmd_option_help == true)
|| (argc == 2 && bool_cmd_option_version == true)
|| (argc == 3 && bool_cmd_option_help == true
&& bool_cmd_option_version == true)) {
ecs_cmd__detruit(cmd);
ecs_exit(EXIT_SUCCESS);
}
/*-----------------------------------------------------------*/
/* Verification que les donnees necessaires ont ete fournies */
/*-----------------------------------------------------------*/
if (cmd->n_num_maillage == 0) {
cmd->n_num_maillage = 1;
ECS_MALLOC(cmd->num_maillage, 1, int);
cmd->num_maillage[0] = 0;
}
cmd->fmt_maillage = ecs_pre__type_format(cmd->fic_maillage, cle_fmt);
if (cmd->fic_maillage == NULL) {
_print_help();
ecs_error(__FILE__, __LINE__, 0,
_("Error in command line specification:\n\n"
"Missing input mesh file name."));
}
/*--------------------------*/
/* Verification des donnees */
/*--------------------------*/
/* Verification que le fichier de maillage existe */
/*------------------------------------------------*/
ecs_loc_cmd__teste_exist_fic(cmd->fic_maillage,
_("Mesh file \"%s\" "
"is not accessible.\n%s"));
/*---------------------------------------------------*/
/* Affichage de la configuration du cas de lancement */
/*---------------------------------------------------*/
ecs_loc_cmd__aff_config(cmd);
return cmd;
}
/*----------------------------------------------------------------------------
* Fonction liberant une structure `ecs_cmd_t' donnee en argument
* Elle renvoie un pointeur NULL
*----------------------------------------------------------------------------*/
ecs_cmd_t *
ecs_cmd__detruit(ecs_cmd_t *cmd)
{
/*xxxxxxxxxxxxxxxxxxxxxxxxxxx Instructions xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx*/
assert(cmd != NULL);
/* Liberation du contenu de la structure `ecs_cmd_t' */
/*===============================================*/
if (cmd->nom_cas != NULL)
ECS_FREE(cmd->nom_cas);
if (cmd->nom_out != NULL)
ECS_FREE(cmd->nom_out);
ECS_FREE(cmd->fic_maillage);
if (cmd->n_num_maillage > 0)
ECS_FREE(cmd->num_maillage);
/* Liberation de la structure `ecs_cmd_t' */
/*====================================*/
ECS_FREE(cmd);
return cmd;
}
/*----------------------------------------------------------------------------*/
|