small cleanups

This commit is contained in:
Vítor Santos Costa 2016-01-31 10:21:50 +00:00
parent 5c1c9a8570
commit 4ff7bdd340

View File

@ -19,6 +19,7 @@
#include "config.h"
#include "Yap.h"
#include "YapHeap.h"
#include "YapInterface.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
@ -44,9 +45,6 @@
#include <direct.h>
#endif
void YAP_SetOutputMessage(void);
int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap);
#if (DefTrailSpace < MinTrailSpace)
#undef DefTrailSpace
#define DefTrailSpace MinTrailSpace
@ -66,9 +64,7 @@ int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap);
#define DEFAULT_SCHEDULERLOOP 10
#define DEFAULT_DELAYEDRELEASELOAD 3
static void
print_usage(void)
{
static void print_usage(void) {
fprintf(stderr, "\n[ Valid switches for command line arguments: ]\n");
fprintf(stderr, " -? Shows this screen\n");
fprintf(stderr, " -b Boot file \n");
@ -82,12 +78,15 @@ print_usage(void)
fprintf(stderr, " -p extra path for file-search-path\n");
fprintf(stderr, " -hSize Heap area in Kbytes (default: %d, minimum: %d)\n",
DefHeapSpace, MinHeapSpace);
fprintf(stderr," -sSize Stack area in Kbytes (default: %d, minimum: %d)\n",
fprintf(stderr,
" -sSize Stack area in Kbytes (default: %d, minimum: %d)\n",
DefStackSpace, MinStackSpace);
fprintf(stderr," -tSize Trail area in Kbytes (default: %d, minimum: %d)\n",
fprintf(stderr,
" -tSize Trail area in Kbytes (default: %d, minimum: %d)\n",
DefTrailSpace, MinTrailSpace);
fprintf(stderr, " -GSize Max Area for Global Stack\n");
fprintf(stderr," -LSize Max Area for Local Stack (number must follow L)\n");
fprintf(stderr,
" -LSize Max Area for Local Stack (number must follow L)\n");
fprintf(stderr, " -TSize Max Area for Trail (number must follow L)\n");
fprintf(stderr, " -nosignals disable signal handling from Prolog\n");
fprintf(stderr, "\n[Execution Modes]\n");
@ -98,12 +97,15 @@ print_usage(void)
fprintf(stderr, " -J4 Compile all predicates\n");
#ifdef TABLING
fprintf(stderr," -ts Maximum table space area in Mbytes (default: unlimited)\n");
fprintf(stderr,
" -ts Maximum table space area in Mbytes (default: unlimited)\n");
#endif /* TABLING */
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS)
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
defined(YAPOR_THREADS)
fprintf(stderr, " -w Number of workers (default: %d)\n",
DEFAULT_NUMBERWORKERS);
fprintf(stderr," -sl Loop scheduler executions before look for hiden shared work (default: %d)\n",
fprintf(stderr, " -sl Loop scheduler executions before look for hiden "
"shared work (default: %d)\n",
DEFAULT_SCHEDULERLOOP);
fprintf(stderr, " -d Value of delayed release of load (default: %d)\n",
DEFAULT_DELAYEDRELEASELOAD);
@ -113,9 +115,7 @@ print_usage(void)
fprintf(stderr, "\n");
}
static int
myisblank(int c)
{
static int myisblank(int c) {
switch (c) {
case ' ':
case '\t':
@ -127,12 +127,11 @@ myisblank(int c)
}
}
static char *
add_end_dot(char arg[])
{
static char *add_end_dot(char arg[]) {
int sz = strlen(arg), i;
i = sz;
while (i && myisblank(arg[--i]));
while (i && myisblank(arg[--i]))
;
if (i && arg[i] != ',') {
char *p = (char *)malloc(sz + 2);
if (!p)
@ -145,9 +144,7 @@ add_end_dot(char arg[])
return arg;
}
static int
dump_runtime_variables(void)
{
static int dump_runtime_variables(void) {
fprintf(stdout, "CC=\"%s\"\n", C_CC);
fprintf(stdout, "YAP_ROOTDIR=\"%s\"\n", YAP_ROOTDIR);
fprintf(stdout, "YAP_LIBS=\"%s\"\n", C_LIBS);
@ -157,17 +154,7 @@ dump_runtime_variables(void)
return 1;
}
/*
* proccess command line arguments: valid switches are: -b boot -s
* stack area size (K) -h heap area size -a aux stack size -e
* emacs_mode -m -DVar=Value reserved memory for alloc IF DEBUG -p if you
* want to check out startup IF MAC -mpw if we are using the mpw
* shell
*/
int
YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
{
X_API int YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap) {
char *p;
int BootMode = YAP_BOOT_FROM_SAVED_CODE;
unsigned long int *ssize;
@ -204,12 +191,10 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
iap->ErrorCause = NULL;
iap->QuietMode = FALSE;
while (--argc > 0)
{
while (--argc > 0) {
p = *++argv;
if (*p == '-')
switch (*++p)
{
switch (*++p) {
case 'b':
BootMode = YAP_BOOT_FROM_PROLOG;
iap->YapPrologBootFile = *++argv;
@ -221,7 +206,8 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
case 'q':
iap->QuietMode = TRUE;
break;
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS)
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
defined(YAPOR_THREADS)
case 'w':
ssize = &(iap->NumberWorkers);
goto GetSize;
@ -270,7 +256,8 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
iap->ExecutionMode = YAPC_COMPILE_ALL;
break;
default:
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c%c ]\n", *p, p[1]);
fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c%c ]\n",
*p, p[1]);
exit(EXIT_FAILURE);
}
p++;
@ -282,7 +269,8 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
case 's':
case 'S':
ssize = &(iap->StackSize);
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || defined(YAPOR_THREADS)
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) || \
defined(YAPOR_THREADS)
if (p[1] == 'l') {
p++;
ssize = &(iap->SchedulerLoop);
@ -305,13 +293,13 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
}
#endif /* TABLING */
get_trail_size:
if (*++p == '\0')
{
if (*++p == '\0') {
if (argc > 1)
--argc, p = *++argv;
else
{
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]);
else {
fprintf(stderr,
"[ YAP unrecoverable error: missing size in flag %s ]",
argv[0]);
print_usage();
exit(EXIT_FAILURE);
}
@ -346,13 +334,13 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
case 'H':
ssize = &(iap->HeapSize);
GetSize:
if (*++p == '\0')
{
if (*++p == '\0') {
if (argc > 1)
--argc, p = *++argv;
else
{
fprintf(stderr,"[ YAP unrecoverable error: missing size in flag %s ]", argv[0]);
else {
fprintf(stderr,
"[ YAP unrecoverable error: missing size in flag %s ]",
argv[0]);
print_usage();
exit(EXIT_FAILURE);
}
@ -377,9 +365,11 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
ch = *p++;
break;
}
if (ch)
{
fprintf(stderr,"[ YAP unrecoverable error: illegal size specification %s ]", argv[-1]);
if (ch) {
fprintf(
stderr,
"[ YAP unrecoverable error: illegal size specification %s ]",
argv[-1]);
Yap_exit(1);
}
*ssize = i;
@ -400,7 +390,8 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
break;
#endif
case 'L':
if (p[1] && p[1] >= '0' && p[1] <= '9') /* hack to emulate SWI's L local option */
if (p[1] && p[1] >= '0' &&
p[1] <= '9') /* hack to emulate SWI's L local option */
{
ssize = &(iap->MaxStackSize);
goto GetSize;
@ -410,7 +401,8 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
case 'l':
p++;
if (!*++argv) {
fprintf(stderr,"%% YAP unrecoverable error: missing load file name\n");
fprintf(stderr,
"%% YAP unrecoverable error: missing load file name\n");
exit(1);
} else if (!strcmp("--", *argv)) {
/* shell script, the next entry should be the file itself */
@ -443,7 +435,8 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing initialization goal for option 'g' ]\n");
fprintf(stderr, " [ YAP unrecoverable error: missing "
"initialization goal for option 'g' ]\n");
exit(EXIT_FAILURE);
}
argv++;
@ -457,7 +450,9 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing goal for option 'z' ]\n");
fprintf(
stderr,
" [ YAP unrecoverable error: missing goal for option 'z' ]\n");
exit(EXIT_FAILURE);
}
argv++;
@ -482,7 +477,8 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
#else
if (chdir(p + strlen("-cwd=")) < 0) {
#endif
fprintf(stderr," [ YAP unrecoverable error in setting cwd: %s ]\n", strerror(errno));
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
strerror(errno));
}
} else if (!strncmp("-stack=", p, strlen("-stack="))) {
ssize = &(iap->StackSize);
@ -517,7 +513,9 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
else {
argc--;
if (argc == 0) {
fprintf(stderr," [ YAP unrecoverable error: missing paths for option 'p' ]\n");
fprintf(
stderr,
" [ YAP unrecoverable error: missing paths for option 'p' ]\n");
exit(EXIT_FAILURE);
}
argv++;
@ -525,19 +523,21 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
}
break;
/* nf: Begin preprocessor code */
case 'D':
{
case 'D': {
char *var, *value;
++p;
var = p;
if (var == NULL || *var == '\0')
break;
while(*p!='=' && *p!='\0') ++p;
if ( *p=='\0' ) break;
while (*p != '=' && *p != '\0')
++p;
if (*p == '\0')
break;
*p = '\0';
++p;
value = p;
if ( *value == '\0' ) break;
if (*value == '\0')
break;
if (iap->def_c == YAP_MAX_YPP_DEFS)
break;
iap->def_var[iap->def_c] = var;
@ -546,9 +546,9 @@ YAP_parse_yap_arguments(int argc, char *argv[], YAP_init_args *iap)
break;
}
/* End preprocessor code */
default:
{
fprintf(stderr,"[ YAP unrecoverable error: unknown switch -%c ]\n", *p);
default: {
fprintf(stderr, "[ YAP unrecoverable error: unknown switch -%c ]\n",
*p);
print_usage();
exit(EXIT_FAILURE);
}