[BACK]Return to plot.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gnuplot

Annotation of OpenXM_contrib/gnuplot/plot.c, Revision 1.1.1.3

1.1       maekawa     1: #ifndef lint
1.1.1.3 ! ohara       2: static char *RCSid = "$Id: plot.c,v 1.18.2.5 2002/03/11 16:10:44 lhecking Exp $";
1.1       maekawa     3: #endif
                      4:
                      5: /* GNUPLOT - plot.c */
                      6:
                      7: /*[
                      8:  * Copyright 1986 - 1993, 1998   Thomas Williams, Colin Kelley
                      9:  *
                     10:  * Permission to use, copy, and distribute this software and its
                     11:  * documentation for any purpose with or without fee is hereby granted,
                     12:  * provided that the above copyright notice appear in all copies and
                     13:  * that both that copyright notice and this permission notice appear
                     14:  * in supporting documentation.
                     15:  *
                     16:  * Permission to modify the software is granted, but not the right to
                     17:  * distribute the complete modified source code.  Modifications are to
                     18:  * be distributed as patches to the released version.  Permission to
                     19:  * distribute binaries produced by compiling modified sources is granted,
                     20:  * provided you
                     21:  *   1. distribute the corresponding source modifications from the
                     22:  *    released version in the form of a patch file along with the binaries,
                     23:  *   2. add special version identification to distinguish your version
                     24:  *    in addition to the base release version number,
                     25:  *   3. provide your name and address as the primary contact for the
                     26:  *    support of your modified version, and
                     27:  *   4. retain our contact information in regard to use of the base
                     28:  *    software.
                     29:  * Permission to distribute the released version of the source code along
                     30:  * with corresponding source modifications in the form of a patch file is
                     31:  * granted with same provisions 2 through 4 for binary distributions.
                     32:  *
                     33:  * This software is provided "as is" without express or implied warranty
                     34:  * to the extent permitted by applicable law.
                     35: ]*/
                     36:
1.1.1.3 ! ohara      37: #ifdef HAVE_CONFIG_H
        !            38: # include "config.h"
        !            39: #endif
        !            40:
1.1       maekawa    41: #include <signal.h>
1.1.1.3 ! ohara      42: #include <setjmp.h>
1.1       maekawa    43:
                     44: #include "plot.h"
                     45: #include "fit.h"
                     46: #include "setshow.h"
                     47: #include "fnproto.h"
1.1.1.3 ! ohara      48:
        !            49: #ifdef HAVE_SYS_UTSNAME_H
        !            50: # include <sys/utsname.h>
        !            51: #endif
1.1       maekawa    52:
                     53: #if defined(MSDOS) || defined(DOS386) || defined(__EMX__)
                     54: # include <io.h>
                     55: #endif
                     56:
                     57: /* HBB: for the control87 function, if used with DJGPP V1: */
                     58: #if defined(DJGPP) && (DJGPP!=2)
                     59: # include "ctrl87.h"
                     60: #endif
                     61:
                     62: #ifdef VMS
                     63: # ifndef __GNUC__
                     64: #  include <unixio.h>
                     65: # endif
                     66: # include <smgdef.h>
                     67: extern int vms_vkid;
                     68: extern smg$create_virtual_keyboard();
                     69: extern int vms_ktid;
                     70: extern smg$create_key_table();
                     71: #endif /* VMS */
                     72:
                     73: #ifdef AMIGA_SC_6_1
                     74: # include <proto/dos.h>
                     75: #endif
                     76:
                     77: #ifdef _Windows
                     78: # include <windows.h>
                     79: # ifndef SIGINT
                     80: #  define SIGINT 2             /* for MSC */
                     81: # endif
                     82: #endif /* _Windows */
                     83:
                     84: extern FILE *gpoutfile;
                     85:
                     86: TBOOLEAN interactive = TRUE;   /* FALSE if stdin not a terminal */
                     87: TBOOLEAN noinputfiles = TRUE;  /* FALSE if there are script files */
                     88:
                     89: /*  these 2 could be in misc.c, but are here with all the other globals */
                     90: TBOOLEAN do_load_arg_substitution = FALSE;
                     91: char *call_args[10] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL };
                     92:
                     93: char *infile_name = NULL;      /* name of command file; NULL if terminal */
                     94:
1.1.1.2   maekawa    95: #ifdef HAVE_LIBREADLINE
1.1       maekawa    96: extern char *rl_readline_name;
                     97: extern int rl_complete_with_tilde_expansion;
1.1.1.3 ! ohara      98: extern char *rl_terminal_name;
1.1       maekawa    99: #endif
                    100:
                    101: #ifdef X11
                    102: extern int X11_args __PROTO((int, char **));
                    103: #endif
                    104:
                    105: /* patch to get home dir, see command.c */
                    106: #if (defined (__TURBOC__) && (defined (MSDOS) || defined(DOS386))) || defined(DJGPP)
                    107: # include <dir.h>              /* MAXPATH */
                    108: char HelpFile[MAXPATH];
                    109: #endif /*   - DJL */
                    110:
                    111: #ifndef STDOUT
                    112: # define STDOUT 1
                    113: #endif
                    114:
                    115: /* a longjmp buffer to get back to the command line */
                    116: #ifdef _Windows
1.1.1.3 ! ohara     117: static JMP_BUF far command_line_env;
1.1       maekawa   118: #else
1.1.1.3 ! ohara     119: static JMP_BUF command_line_env;
1.1       maekawa   120: #endif
                    121:
                    122: static void load_rcfile __PROTO((void));
                    123: RETSIGTYPE inter __PROTO((int anint));
                    124:
                    125: /* built-in function table */
                    126: struct ft_entry GPFAR ft[] =
                    127: {
                    128:     /* internal functions: */
                    129:     {"push", (FUNC_PTR) f_push},
                    130:     {"pushc", (FUNC_PTR) f_pushc},
                    131:     {"pushd1", (FUNC_PTR) f_pushd1},
                    132:     {"pushd2", (FUNC_PTR) f_pushd2},
                    133:     {"pushd", (FUNC_PTR) f_pushd},
                    134:     {"call", (FUNC_PTR) f_call},
                    135:     {"calln", (FUNC_PTR) f_calln},
                    136:     {"lnot", (FUNC_PTR) f_lnot},
                    137:     {"bnot", (FUNC_PTR) f_bnot},
                    138:     {"uminus", (FUNC_PTR) f_uminus},
                    139:     {"lor", (FUNC_PTR) f_lor},
                    140:     {"land", (FUNC_PTR) f_land},
                    141:     {"bor", (FUNC_PTR) f_bor},
                    142:     {"xor", (FUNC_PTR) f_xor},
                    143:     {"band", (FUNC_PTR) f_band},
                    144:     {"eq", (FUNC_PTR) f_eq},
                    145:     {"ne", (FUNC_PTR) f_ne},
                    146:     {"gt", (FUNC_PTR) f_gt},
                    147:     {"lt", (FUNC_PTR) f_lt},
                    148:     {"ge", (FUNC_PTR) f_ge},
                    149:     {"le", (FUNC_PTR) f_le},
                    150:     {"plus", (FUNC_PTR) f_plus},
                    151:     {"minus", (FUNC_PTR) f_minus},
                    152:     {"mult", (FUNC_PTR) f_mult},
                    153:     {"div", (FUNC_PTR) f_div},
                    154:     {"mod", (FUNC_PTR) f_mod},
                    155:     {"power", (FUNC_PTR) f_power},
                    156:     {"factorial", (FUNC_PTR) f_factorial},
                    157:     {"bool", (FUNC_PTR) f_bool},
                    158:     {"dollars", (FUNC_PTR) f_dollars}, /* for using extension */
                    159:     {"jump", (FUNC_PTR) f_jump},
                    160:     {"jumpz", (FUNC_PTR) f_jumpz},
                    161:     {"jumpnz", (FUNC_PTR) f_jumpnz},
                    162:     {"jtern", (FUNC_PTR) f_jtern},
                    163:
                    164: /* standard functions: */
                    165:     {"real", (FUNC_PTR) f_real},
                    166:     {"imag", (FUNC_PTR) f_imag},
                    167:     {"arg", (FUNC_PTR) f_arg},
                    168:     {"conjg", (FUNC_PTR) f_conjg},
                    169:     {"sin", (FUNC_PTR) f_sin},
                    170:     {"cos", (FUNC_PTR) f_cos},
                    171:     {"tan", (FUNC_PTR) f_tan},
                    172:     {"asin", (FUNC_PTR) f_asin},
                    173:     {"acos", (FUNC_PTR) f_acos},
                    174:     {"atan", (FUNC_PTR) f_atan},
                    175:     {"atan2", (FUNC_PTR) f_atan2},
                    176:     {"sinh", (FUNC_PTR) f_sinh},
                    177:     {"cosh", (FUNC_PTR) f_cosh},
                    178:     {"tanh", (FUNC_PTR) f_tanh},
                    179:     {"int", (FUNC_PTR) f_int},
                    180:     {"abs", (FUNC_PTR) f_abs},
                    181:     {"sgn", (FUNC_PTR) f_sgn},
                    182:     {"sqrt", (FUNC_PTR) f_sqrt},
                    183:     {"exp", (FUNC_PTR) f_exp},
                    184:     {"log10", (FUNC_PTR) f_log10},
                    185:     {"log", (FUNC_PTR) f_log},
                    186:     {"besj0", (FUNC_PTR) f_besj0},
                    187:     {"besj1", (FUNC_PTR) f_besj1},
                    188:     {"besy0", (FUNC_PTR) f_besy0},
                    189:     {"besy1", (FUNC_PTR) f_besy1},
                    190:     {"erf", (FUNC_PTR) f_erf},
                    191:     {"erfc", (FUNC_PTR) f_erfc},
                    192:     {"gamma", (FUNC_PTR) f_gamma},
                    193:     {"lgamma", (FUNC_PTR) f_lgamma},
                    194:     {"ibeta", (FUNC_PTR) f_ibeta},
                    195:     {"igamma", (FUNC_PTR) f_igamma},
                    196:     {"rand", (FUNC_PTR) f_rand},
                    197:     {"floor", (FUNC_PTR) f_floor},
                    198:     {"ceil", (FUNC_PTR) f_ceil},
                    199:
                    200:     {"norm", (FUNC_PTR) f_normal},     /* XXX-JG */
                    201:     {"inverf", (FUNC_PTR) f_inverse_erf},      /* XXX-JG */
                    202:     {"invnorm", (FUNC_PTR) f_inverse_normal},  /* XXX-JG */
                    203:     {"asinh", (FUNC_PTR) f_asinh},
                    204:     {"acosh", (FUNC_PTR) f_acosh},
                    205:     {"atanh", (FUNC_PTR) f_atanh},
                    206:
                    207:     {"column", (FUNC_PTR) f_column},   /* for using */
                    208:     {"valid", (FUNC_PTR) f_valid},     /* for using */
                    209:     {"timecolumn", (FUNC_PTR) f_timecolumn},   /* for using */
                    210:
                    211:     {"tm_sec", (FUNC_PTR) f_tmsec},    /* for timeseries */
                    212:     {"tm_min", (FUNC_PTR) f_tmmin},    /* for timeseries */
                    213:     {"tm_hour", (FUNC_PTR) f_tmhour},  /* for timeseries */
                    214:     {"tm_mday", (FUNC_PTR) f_tmmday},  /* for timeseries */
                    215:     {"tm_mon", (FUNC_PTR) f_tmmon},    /* for timeseries */
                    216:     {"tm_year", (FUNC_PTR) f_tmyear},  /* for timeseries */
                    217:     {"tm_wday", (FUNC_PTR) f_tmwday},  /* for timeseries */
                    218:     {"tm_yday", (FUNC_PTR) f_tmyday},  /* for timeseries */
                    219:
                    220:     {NULL, NULL}
                    221: };
                    222:
                    223: static struct udvt_entry udv_pi = { NULL, "pi", FALSE };
                    224: /* first in linked list */
                    225: struct udvt_entry *first_udv = &udv_pi;
                    226: struct udft_entry *first_udf = NULL;
                    227:
1.1.1.2   maekawa   228: static int exit_status = EXIT_SUCCESS;
                    229:
1.1       maekawa   230: #ifdef OS2
                    231: # define INCL_DOS
                    232: # define INCL_REXXSAA
                    233: # include <os2.h>
                    234: # include <process.h>
                    235: ULONG RexxInterface(PRXSTRING, PUSHORT, PRXSTRING);
                    236: int ExecuteMacro(char *, int);
                    237: void PM_intc_cleanup();
                    238: void PM_setup();
                    239: #endif /* OS2 */
                    240:
                    241: #if defined(ATARI) || defined(MTOS)
                    242: /* For findfile () (?) */
                    243: # include <support.h>
                    244: void appl_exit(void);
                    245: void MTOS_open_pipe(void);
                    246: extern int aesid;
                    247: #endif
                    248:
                    249: RETSIGTYPE inter(anint)
                    250: int anint;
                    251: {
                    252: #ifdef OS2
                    253:     (void) signal(anint, SIG_ACK);
                    254: #else
                    255:     (void) signal(SIGINT, (sigfunc) inter);
                    256: #endif
                    257:
                    258: #ifndef DOSX286
                    259:     (void) signal(SIGFPE, SIG_DFL);    /* turn off FPE trapping */
                    260: #endif
                    261: #ifdef OS2
                    262:     PM_intc_cleanup();
                    263: #else
                    264:     term_reset();
                    265:     (void) putc('\n', stderr);
1.1.1.3 ! ohara     266:     LONGJMP(command_line_env, TRUE);   /* return to prompt */
1.1       maekawa   267: #endif
                    268: }
                    269:
1.1.1.2   maekawa   270: #ifdef LINUXVGA
                    271: /* utility functions to ensure that setuid gnuplot
                    272:  * assumes root privileges only for those parts
                    273:  * of the code which require root rights.
                    274:  *
                    275:  * By "Dr. Werner Fink" <werner@suse.de>
                    276:  */
                    277: static uid_t euid, ruid;
                    278: static gid_t egid, rgid;
                    279: static int asked_privi = 0;
                    280:
                    281: void
                    282: drop_privilege()
                    283: {
                    284:     if (!asked_privi) {
                    285:        euid = geteuid();
                    286:        egid = getegid();
                    287:        ruid = getuid();
                    288:        rgid = getgid();
                    289:        asked_privi = 1;
                    290:     }
                    291:     if (setegid(rgid) == -1)
                    292:        (void) fprintf(stderr, "setegid(%d): %s\n",
                    293:                       (int) rgid, strerror(errno));
                    294:     if (seteuid(ruid) == -1)
                    295:        (void) fprintf(stderr, "seteuid(%d): %s\n",
                    296:                       (int) ruid, strerror(errno));
                    297: }
                    298:
                    299: void
                    300: take_privilege()
                    301: {
                    302:     if (!asked_privi) {
                    303:        euid = geteuid();
                    304:        egid = getegid();
                    305:        ruid = getuid();
                    306:        rgid = getgid();
                    307:        asked_privi = 1;
                    308:     }
                    309:     if (setegid(egid) == -1)
                    310:        (void) fprintf(stderr, "setegid(%d): %s\n",
                    311:                       (int) egid, strerror(errno));
                    312:     if (seteuid(euid) == -1)
                    313:        (void) fprintf(stderr, "seteuid(%d): %s\n",
                    314:                       (int) euid, strerror(errno));
                    315: }
                    316: #endif /* LINUXVGA */
                    317:
1.1       maekawa   318:
                    319: /* a wrapper for longjmp so we can keep everything local */
                    320: void bail_to_command_line()
                    321: {
1.1.1.3 ! ohara     322:     LONGJMP(command_line_env, TRUE);
1.1       maekawa   323: }
                    324:
                    325: #if defined(_Windows) || defined(_Macintosh)
                    326: int gnu_main(argc, argv)
                    327: #else
                    328: int main(argc, argv)
                    329: #endif
                    330: int argc;
                    331: char **argv;
                    332: {
                    333: #ifdef LINUXVGA
                    334:     LINUX_setup();
                    335: #endif
                    336: /* make sure that we really have revoked root access, this might happen if
                    337:    gnuplot is compiled without vga support but is installed suid by mistake */
                    338: #ifdef __linux__
                    339:     setuid(getuid());
                    340: #endif
                    341: #if defined(MSDOS) && !defined(_Windows) && !defined(__GNUC__)
                    342:     PC_setup();
                    343: #endif /* MSDOS !Windows */
                    344: /* HBB: Seems this isn't needed any more for DJGPP V2? */
                    345: /* HBB: disable all floating point exceptions, just keep running... */
                    346: #if defined(DJGPP) && (DJGPP!=2)
                    347:     _control87(MCW_EM, MCW_EM);
                    348: #endif
                    349:
                    350: #if defined(OS2)
                    351:     int rc;
                    352:     if (_osmode == OS2_MODE) {
                    353:        PM_setup();
                    354:        rc = RexxRegisterSubcomExe("GNUPLOT", (PFN) RexxInterface, NULL);
                    355:     }
                    356: #endif
                    357:
                    358: /* malloc large blocks, otherwise problems with fragmented mem */
                    359: #ifdef OSK
                    360:     _mallocmin(102400);
                    361: #endif
                    362:
                    363: #ifdef MALLOCDEBUG
                    364:     malloc_debug(7);
                    365: #endif
                    366:
                    367: /* get helpfile from home directory */
                    368: #ifndef DOSX286
                    369: # ifndef _Windows
                    370: #  if defined (__TURBOC__) && (defined (MSDOS) || defined(DOS386))
                    371:     strcpy(HelpFile, argv[0]);
                    372:     strcpy(strrchr(HelpFile, DIRSEP1), "\\gnuplot.gih");
                    373: #  endif                       /*   - DJL */
                    374: # endif                                /* !_Windows */
                    375: #endif /* !DOSX286 */
                    376: #ifdef __DJGPP__
                    377:     {
                    378:        char *s;
                    379:        strcpy(HelpFile, argv[0]);
                    380:        for (s = HelpFile; *s; s++)
                    381:            if (*s == DIRSEP1)
                    382:                *s = DIRSEP2;   /* '\\' to '/' */
                    383:        strcpy(strrchr(HelpFile, DIRSEP2), "/gnuplot.gih");
                    384:     }          /* Add also some "paranoid" tests for '\\':  AP */
                    385: #endif /* DJGPP */
                    386:
                    387: #ifdef VMS
                    388:     unsigned int status[2] = { 1, 0 };
                    389: #endif
                    390:
1.1.1.2   maekawa   391: #ifdef HAVE_LIBREADLINE
1.1       maekawa   392:     rl_readline_name = argv[0];
                    393:     rl_complete_with_tilde_expansion = 1;
1.1.1.3 ! ohara     394:     rl_terminal_name = getenv("TERM");
1.1       maekawa   395: #endif
                    396:
                    397: #ifdef X11
                    398:     {
                    399:        int n = X11_args(argc, argv);
                    400:        argv += n;
                    401:        argc -= n;
                    402:     }
                    403: #endif
                    404:
                    405: #ifdef apollo
                    406:     apollo_pfm_catch();
                    407: #endif
                    408:
                    409: /* moved to ATARI_init in atariaes.trm */
                    410: /* #ifdef ATARI
                    411:    void application_init(void);
                    412:    application_init();
                    413:    #endif */
                    414:
                    415: #ifdef MTOS
                    416:     MTOS_open_pipe();
                    417: #endif
                    418:
                    419:     setbuf(stderr, (char *) NULL);
                    420:
                    421: #ifndef NO_SETVBUF
                    422:     /* this was once setlinebuf(). Docs say this is
                    423:      * identical to setvbuf(,NULL,_IOLBF,0), but MS C
                    424:      * faults this (size out of range), so we try with
                    425:      * size of 1024 instead. [SAS/C does that, too. -lh]
                    426:      * Failing this, I propose we just make the call and
                    427:      * ignore the return : its probably not a big deal
                    428:      */
                    429:     if (setvbuf(stdout, (char *) NULL, _IOLBF, (size_t) 1024) != 0)
                    430:        fputs("Could not linebuffer stdout\n", stderr);
                    431: #endif
                    432:
                    433:     gpoutfile = stdout;
1.1.1.3 ! ohara     434:     (void) Gcomplex(&udv_pi.udv_value, M_PI, 0.0);
1.1       maekawa   435:
                    436:     init_memory();
                    437:
                    438:     interactive = FALSE;
                    439:     init_terminal();           /* can set term type if it likes */
                    440:
                    441: #ifdef AMIGA_SC_6_1
                    442:     if (IsInteractive(Input()) == DOSTRUE)
                    443:        interactive = TRUE;
                    444:     else
                    445:        interactive = FALSE;
                    446: #else
                    447: # if (defined(__MSC__) && defined(_Windows)) || defined(__WIN32__)
                    448:     interactive = TRUE;
                    449: # else
                    450:     interactive = isatty(fileno(stdin));
                    451: # endif
                    452: #endif /* !AMIGA_SC_6_1 */
                    453:
                    454:     if (argc > 1)
                    455:        interactive = noinputfiles = FALSE;
                    456:     else
                    457:        noinputfiles = TRUE;
                    458:
1.1.1.3 ! ohara     459:     /* Need this before show_version is called for the first time */
        !           460:
        !           461: #ifdef HAVE_SYS_UTSNAME_H
        !           462:     {
        !           463:        struct utsname uts;
        !           464:
        !           465:        /* something is fundamentally wrong if this fails ... */
        !           466:        if (uname(&uts) > -1) {
        !           467: # ifdef _AIX
        !           468:            strcpy(os_name, uts.sysname);
        !           469:            sprintf(os_name, "%s.%s", uts.version, uts.release);
        !           470: # elif defined(SCO)
        !           471:            strcpy(os_name, "SCO");
        !           472:            strcpy(os_rel, uts.release);
        !           473: # else
        !           474:            strcpy(os_name, uts.sysname);
        !           475:            strcpy(os_rel, uts.release);
        !           476: # endif
        !           477:        }
        !           478:     }
        !           479: #else /* ! HAVE_SYS_UTSNAME_H */
        !           480:
        !           481:     strcpy(os_name, OS);
        !           482:     strcpy(os_rel, "");
        !           483:
        !           484: #endif /* HAVE_SYS_UTSNAME_H */
        !           485:
1.1       maekawa   486:     if (interactive)
                    487:        show_version(stderr);
                    488:
                    489: #ifdef VMS
                    490:     /* initialise screen management routines for command recall */
                    491:     if (status[1] = smg$create_virtual_keyboard(&vms_vkid) != SS$_NORMAL)
                    492:        done(status[1]);
                    493:     if (status[1] = smg$create_key_table(&vms_ktid) != SS$_NORMAL)
                    494:        done(status[1]);
                    495: #endif /* VMS */
                    496:
1.1.1.3 ! ohara     497:     if (!SETJMP(command_line_env, 1)) {
1.1       maekawa   498:        /* first time */
                    499:        interrupt_setup();
                    500:        load_rcfile();
                    501:        init_fit();             /* Initialization of fitting module */
                    502:
                    503:        if (interactive && term != 0)   /* not unknown */
                    504:            fprintf(stderr, "\nTerminal type set to '%s'\n", term->name);
                    505:     } else {
                    506:        /* come back here from int_error() */
1.1.1.2   maekawa   507:        if (interactive == FALSE)
                    508:            exit_status = EXIT_FAILURE;
                    509:
1.1       maekawa   510: #ifdef AMIGA_SC_6_1
                    511:        (void) rawcon(0);
                    512: #endif
                    513:        load_file_error();      /* if we were in load_file(), cleanup */
                    514: #ifdef _Windows
                    515:        SetCursor(LoadCursor((HINSTANCE) NULL, IDC_ARROW));
                    516: #endif
                    517:
                    518: #ifdef VMS
                    519:        /* after catching interrupt */
                    520:        /* VAX stuffs up stdout on SIGINT while writing to stdout,
                    521:           so reopen stdout. */
                    522:        if (gpoutfile == stdout) {
                    523:            if ((stdout = freopen("SYS$OUTPUT", "w", stdout)) == NULL) {
                    524:                /* couldn't reopen it so try opening it instead */
                    525:                if ((stdout = fopen("SYS$OUTPUT", "w")) == NULL) {
                    526:                    /* don't use int_error here - causes infinite loop! */
                    527:                    fputs("Error opening SYS$OUTPUT as stdout\n", stderr);
                    528:                }
                    529:            }
                    530:            gpoutfile = stdout;
                    531:        }
                    532: #endif /* VMS */
                    533:        if (!interactive && !noinputfiles) {
                    534:            term_reset();
                    535: #if defined(ATARI) || defined(MTOS)
                    536:            if (aesid > -1)
                    537:                atexit(appl_exit);
                    538: #endif
                    539:            return (IO_ERROR);  /* exit on non-interactive error */
                    540:        }
                    541:     }
                    542:
                    543:     if (argc > 1) {
                    544: #ifdef _Windows
                    545:        int noend = 0;
                    546: #endif
                    547:
                    548:        /* load filenames given as arguments */
                    549:        while (--argc > 0) {
                    550:            ++argv;
                    551:            c_token = NO_CARET; /* in case of file not found */
                    552: #ifdef _Windows
                    553:            if (stricmp(*argv, "-noend") == 0 || stricmp(*argv, "/noend") == 0)
                    554:                noend = 1;
                    555:            else
                    556: #endif
                    557:            if (strcmp(*argv, "-") == 0) {
                    558:                /* DBT 10-7-98  go interactive if "-" on command line */
                    559:
                    560:                interactive = TRUE;
                    561:                /* will this work on all platforms? */
                    562:
                    563:                while (!com_line());
                    564:
1.1.1.2   maekawa   565:                /* interactive = FALSE; */ /* should this be here? */
1.1       maekawa   566:
                    567:            } else
                    568:                load_file(fopen(*argv, "r"), *argv, FALSE);
                    569:        }
                    570: #ifdef _Windows
                    571:        if (noend) {
                    572:            interactive = TRUE;
                    573:            while (!com_line());
                    574:        }
                    575: #endif
                    576:     } else {
                    577:        /* take commands from stdin */
                    578:        while (!com_line());
                    579:     }
                    580:
                    581:     term_reset();
                    582:
                    583: #ifdef OS2
                    584:     if (_osmode == OS2_MODE)
                    585:        RexxDeregisterSubcom("GNUPLOT", NULL);
                    586: #endif
                    587:
                    588: #if defined(ATARI) || defined(MTOS)
                    589:     if (aesid > -1)
                    590:        atexit(appl_exit);
                    591: #endif
1.1.1.2   maekawa   592:     return (exit_status);
1.1       maekawa   593: }
                    594:
                    595: #if (defined(ATARI) || defined(MTOS)) && defined(__PUREC__)
                    596: int purec_matherr(struct exception *e)
                    597: {
                    598:     char *c;
                    599:     switch (e->type) {
                    600:     case DOMAIN:
                    601:        c = "domain error";
                    602:        break;
                    603:     case SING:
                    604:        c = "argument singularity";
                    605:        break;
                    606:     case OVERFLOW:
                    607:        c = "overflow range";
                    608:        break;
                    609:     case UNDERFLOW:
                    610:        c = "underflow range";
                    611:        break;
                    612:     default:
                    613:        c = "(unknown error";
                    614:        break;
                    615:     }
                    616:     fprintf(stderr, "\
                    617: math exception : %s\n\
                    618:     name : %s\n\
                    619:     arg 1: %e\n\
                    620:     arg 2: %e\n\
                    621:     ret  : %e\n",
                    622:            c,
                    623:            e->name,
                    624:            e->arg1,
                    625:            e->arg2,
                    626:            e->retval);
                    627:
                    628:     return 1;
                    629: }
                    630: #endif /* (ATARI || MTOS) && PUREC */
                    631:
                    632:
                    633: /* Set up to catch interrupts */
                    634: void interrupt_setup()
                    635: {
                    636: #ifdef __PUREC__
                    637:     setmatherr(purec_matherr);
                    638: #endif
                    639:
                    640:     (void) signal(SIGINT, (sigfunc) inter);
                    641:
                    642: #ifdef SIGPIPE
                    643:     /* ignore pipe errors, this might happen with set output "|head" */
                    644:     (void) signal(SIGPIPE, SIG_IGN);
                    645: #endif /* SIGPIPE */
                    646: }
                    647:
                    648:
                    649: /* Look for a gnuplot init file in . or home directory */
                    650: static void load_rcfile()
                    651: {
                    652:     FILE *plotrc = NULL;
                    653:     char home[80];
                    654:     char rcfile[sizeof(PLOTRC) + 80];
                    655:     char *tmp_home = NULL;
                    656: #ifndef VMS
                    657:     char *p;   /* points to last char in home path, or to \0, if none */
                    658:
                    659:     tmp_home = getenv(HOME);
                    660:     if (tmp_home) {
                    661:        safe_strncpy(home, tmp_home, sizeof(home));
                    662:        if (strlen(home))
                    663:            p = &home[strlen(home) - 1];
                    664:        else
                    665:            p = home;
                    666:        if ((*p != DIRSEP1) && (*p != DIRSEP2) && (*p != NUL)) {
                    667:            assert(p >= home && p <= (home + sizeof(home) - 1 - 2));
                    668:            if (*p)
                    669:                p++;
                    670:            *p++ = DIRSEP1;
                    671:            *p = NUL;
                    672:        }
                    673:     }
                    674: #else /* VMS */
                    675:     safe_strncpy(home, HOME, sizeof(home));
                    676:     tmp_home = home;
                    677: #endif /* VMS */
                    678:
                    679: #ifdef NOCWDRC
                    680:     /* inhibit check of init file in current directory for security reasons */
                    681: #else
                    682:     (void) strcpy(rcfile, PLOTRC);
                    683:     plotrc = fopen(rcfile, "r");
                    684: #endif /* !NOCWDRC */
                    685:
                    686:     if (plotrc == NULL) {
                    687:        if (tmp_home) {
                    688:            (void) sprintf(rcfile, "%s%s", home, PLOTRC);
                    689:            plotrc = fopen(rcfile, "r");
                    690: #if defined(ATARI) || defined(MTOS)
                    691:            if (plotrc == NULL) {
                    692:                char const *const ext[] = { NULL };
                    693:                char *ini_ptr = findfile(PLOTRC, getenv("GNUPLOTPATH"), ext);
                    694:
                    695:                if (ini_ptr)
                    696:                    plotrc = fopen(ini_ptr, "r");
                    697:            }
                    698: #endif /* ATARI || MTOS */
                    699:        }
                    700:     }
                    701:     if (plotrc)
                    702:        load_file(plotrc, rcfile, FALSE);
                    703: }
                    704:
                    705: #ifdef OS2
                    706:
                    707: int ExecuteMacro(char *argv, int namelength)
                    708: {
                    709:     RXSTRING rxRc;
                    710:     RXSTRING rxArg;
                    711:     char pszName[CCHMAXPATH];
                    712:     short sRc;
                    713:     int rc;
                    714:
                    715:     safe_strncpy(pszName, argv, sizeof(pszName));
                    716:     MAKERXSTRING(rxArg, argv, strlen(argv));
                    717:     rc = RexxStart(1,
                    718:                   &rxArg,
                    719:                   pszName,
                    720:                   NULL,
                    721:                   "GNUPLOT",
                    722:                   RXCOMMAND,
                    723:                   NULL,
                    724:                   &sRc,
                    725:                   &rxRc);
                    726:     if (rc == -4)
                    727:        rc = 0;                 /* run was cancelled-don't give error message */
                    728:
                    729: /* We don't use this value ?
                    730:    BTW, don't use free() instead since it's allocated inside RexxStart() */
                    731:     DosFreeMem(rxRc.strptr);
                    732:     return rc;
                    733: }
                    734:
                    735: ULONG RexxInterface(PRXSTRING rxCmd, PUSHORT pusErr, PRXSTRING rxRc)
                    736: /*
                    737:    ** Rexx command line interface
                    738:  */
                    739: {
                    740:     int rc;
1.1.1.3 ! ohara     741:     static JMP_BUF keepenv;
1.1       maekawa   742:     int cmdlen;
                    743:
1.1.1.3 ! ohara     744:     memcpy(keepenv, command_line_env, sizeof(JMP_BUF));
        !           745:     if (!SETJMP(command_line_env, 1)) {
1.1       maekawa   746:        /* set variable input_line.
                    747:         * Watch out for line length of NOT_ZERO_TERMINATED strings ! */
                    748:        cmdlen = rxCmd->strlength + 1;
                    749:        safe_strncpy(input_line, rxCmd->strptr, cmdlen);
                    750:        input_line[cmdlen] = NUL;
                    751:
                    752:        rc = do_line();
                    753:        *pusErr = RXSUBCOM_OK;
                    754:        rxRc->strptr[0] = rc + '0';
                    755:        rxRc->strptr[1] = NUL;
                    756:        rxRc->strlength = strlen(rxRc->strptr);
                    757:     } else {
                    758:        *pusErr = RXSUBCOM_ERROR;
                    759:        RexxSetHalt(getpid(), 1);
                    760:     }
1.1.1.3 ! ohara     761:     memcpy(command_line_env, keepenv, sizeof(JMP_BUF));
1.1       maekawa   762:     return 0;
                    763: }
                    764: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>