main() { char c; // ウィンドウを準備する。以下の3行でcursesライブラリを呼び出す // cursesプログラムの標準的な初期化手順である scrn = initscr(); noecho(); // キー入力をエコーしない cbreak(); // キー入力は即時有効になる。Enterキー入力を必要としない // 'ps ax' を実行し出力を処理する runpsax(); // ウィンドウに表示する showlastpart(); // ユーザコマンドループ while (1) { // ユーザコマンドを受け取る c = getch(); if (c == 'u') updown(-1); else if (c == 'd') updown(1); else if (c == 'r') rerun(); else if (c == 'k') prockill(); else break; // 終了する } // 元の設定を復元する endwin(); }
int main() { char c; // window setup, next 3 lines are curses library calls, a standard // initializing sequence for curses programs scrn = initscr(); noecho(); // don’t echo keystrokes cbreak(); // keyboard input valid immediately, not after hit Enter // run ’ps ax’ and process the output runpsax(); // display in the window showlastpart(); // user command loop while (1) { // get user command c = getch(); if (c == ’u’) updown(-1); else if (c == ’d’) updown(1); 6 else if (c == ’r’) rerun(); else if (c == ’k’) prockill(); else break; // quit } // restore original settings and leave endwin(); return 0; }
int main() { char str[MAX]; printf("Unesite string:\n"); scanf("%s", str); updown(str); printf("Obrnut string: %s\n", str); }
int main() { char string[MAX_SIZE]; puts("Unesite string:"); __fpurge(stdin); gets(string); updown(string); puts(string); return 0; }
void QUA_helicopter::Adelante(void) { if((acl==0) & (aclup==0) & (acldown==0)) { SetAbsVelocity(vec3_origin); m_vImpulso=GetAbsVelocity(); return; } // Aqui esto no tira, abra que mirarlo bien despues; Vector dir; float fl_updown; fl_updown=(500*(aclup/1))-(500*(acldown/1)); Vector updown(0,0,fl_updown); AngleVectors(this->GetAbsAngles(),&dir); dir.z=0; if (m_bPressed) { //ApplyAbsVelocityImpulse(dir*5.0f+updown); SetAbsVelocity((dir*600*(acl/1))+updown); m_vImpulso=dir; } else { SetAbsVelocity((m_vImpulso*600*(acl/1))+updown); } //SetAbsVelocity(250*(acl/1)); }
/* * The main terminal loop: * - If there are characters received send them * to the screen via the appropriate translate function. */ int do_terminal(void) { char buf[128]; int buf_offset = 0; int c; int x; int blen; int zauto = 0; static const char zsig[] = "**\030B00"; int zpos = 0; const char *s; dirflush = 0; WIN *error_on_open_window = NULL; dirty_goto: /* Show off or online time */ update_status_time(); /* If the status line was shown temporarily, delete it again. */ if (tempst) { tempst = 0; mc_wclose(st, 1); st = NULL; } /* Auto Zmodem? */ if (P_PAUTO[0] >= 'A' && P_PAUTO[0] <= 'Z') zauto = P_PAUTO[0]; /* Set the terminal modes */ setcbreak(2); /* Raw, no echo */ keyboard(KSTART, 0); /* Main loop */ while (1) { /* See if window size changed */ if (size_changed) { size_changed = 0; wrapln = us->wrap; /* I got the resize code going again! Yeah! */ mc_wclose(us, 0); us = NULL; if (st) mc_wclose(st, 0); st = NULL; mc_wclose(stdwin, 0); if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0) leave(_("Could not re-initialize window system.")); /* Set the terminal modes */ setcbreak(2); /* Raw, no echo */ init_emul(terminal, 0); } /* Update the timer. */ timer_update(); /* check if device is ok, if not, try to open it */ if (!get_device_status(portfd_connected)) { /* Ok, it's gone, most probably someone unplugged the USB-serial, we * need to free the FD so that a replug can get the same device * filename, open it again and be back */ int reopen = portfd == -1; close(portfd); lockfile_remove(); portfd = -1; if (open_term(reopen, reopen, 1) < 0) { if (!error_on_open_window) error_on_open_window = mc_tell(_("Cannot open %s!"), dial_tty); } else { if (error_on_open_window) { mc_wclose(error_on_open_window, 1); error_on_open_window = NULL; } } } /* Check for I/O or timer. */ x = check_io(portfd_connected, 0, 1000, buf + buf_offset, sizeof(buf) - buf_offset, &blen); blen += buf_offset; buf_offset = 0; /* Data from the modem to the screen. */ if ((x & 1) == 1) { char obuf[sizeof(buf)]; char *ptr; if (using_iconv()) { char *otmp = obuf; size_t output_len = sizeof(obuf); size_t input_len = blen; ptr = buf; do_iconv(&ptr, &input_len, &otmp, &output_len); // something happened at all? if (output_len < sizeof(obuf)) { if (input_len) { // something remained, we need to adapt buf accordingly memmove(buf, ptr, input_len); buf_offset = input_len; } blen = sizeof(obuf) - output_len; ptr = obuf; } else ptr = buf; } else { ptr = buf; } while (blen-- > 0) { /* Auto zmodem detect */ if (zauto) { if (zsig[zpos] == *ptr) zpos++; else zpos = 0; } if (P_PARITY[0] == 'M' || P_PARITY[0] == 'S') *ptr &= 0x7f; if (display_hex) { unsigned char c = *ptr++; unsigned char u = c >> 4; c &= 0xf; vt_out(u > 9 ? 'a' + (u - 10) : '0' + u); vt_out(c > 9 ? 'a' + (c - 10) : '0' + c); vt_out(' '); } else vt_out(*ptr++); if (zauto && zsig[zpos] == 0) { dirflush = 1; keyboard(KSTOP, 0); updown('D', zauto - 'A'); dirflush = 0; zpos = 0; blen = 0; goto dirty_goto; } } mc_wflush(); }
int main(int argc, char **argv) { int c; /* Command character */ int quit = 0; /* 'q' or 'x' pressed */ char *s, *bufp; /* Scratch pointers */ int doinit = 1; /* -o option */ char capname[128]; /* Name of capture file */ struct passwd *pwd; /* To look up user name */ char *use_port; /* Name of initialization file */ char *args[20]; /* New argv pointer */ int argk = 1; /* New argc */ char *mc; /* For 'MINICOM' env. variable */ int env_args; /* Number of args in env. variable */ char *cmd_dial; /* Entry from the command line. */ int alt_code = 0; /* Type of alt key */ char *cmdline_baudrate = NULL;/* Baudrate given on the command line via -b */ char *cmdline_device = NULL; /* Device/Port given on the command line via -D */ char *remote_charset = NULL; /* Remote charset given on the command line via -R */ char pseudo[64]; /* char* console_encoding = getenv ("LC_CTYPE"); */ static struct option long_options[] = { { "setup", no_argument, NULL, 's' }, { "help", no_argument, NULL, 'h' }, { "ptty", required_argument, NULL, 'p' }, { "metakey", no_argument, NULL, 'm' }, { "metakey8", no_argument, NULL, 'M' }, { "ansi", no_argument, NULL, 'l' }, { "iso", no_argument, NULL, 'L' }, { "term", required_argument, NULL, 't' }, { "noinit", no_argument, NULL, 'o' }, { "color", required_argument, NULL, 'c' }, { "attrib", required_argument, NULL, 'a' }, { "dial", required_argument, NULL, 'd' }, { "statline", no_argument, NULL, 'z' }, { "capturefile", required_argument, NULL, 'C' }, { "script", required_argument, NULL, 'S' }, { "7bit", no_argument, NULL, '7' }, { "8bit", no_argument, NULL, '8' }, { "version", no_argument, NULL, 'v' }, { "wrap", no_argument, NULL, 'w' }, { "displayhex", no_argument, NULL, 'H' }, { "disabletime", no_argument, NULL, 'T' }, // obsolete { "baudrate", required_argument, NULL, 'b' }, { "device", required_argument, NULL, 'D' }, { "remotecharset", required_argument, NULL, 'R' }, { "statlinefmt", required_argument, NULL, 'F' }, { NULL, 0, NULL, 0 } }; /* initialize locale support */ setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); /* Initialize global variables */ portfd = -1; capfp = NULL; docap = 0; online = -1; linespd = 0; stdattr = XA_NORMAL; us = NULL; addlf = 0; addcr = 0; line_timestamp = 0; wrapln = 0; display_hex = 0; option_T_used = 0; local_echo = 0; strcpy(capname, "minicom.cap"); lockfile[0] = 0; tempst = 0; st = NULL; us = NULL; bogus_dcd = 0; usecolor = 0; screen_ibmpc = screen_iso = 1; useattr = 1; strncpy(termtype, getenv("TERM") ? getenv("TERM") : "dumb", sizeof(termtype)); stdattr = XA_NORMAL; use_port = "dfl"; alt_override = 0; scr_name[0] = 0; scr_user[0] = 0; scr_passwd[0] = 0; dial_name = (char *)NULL; dial_number = (char *)NULL; dial_user = (char *)NULL; dial_pass = (char *)NULL; size_changed = 0; escape = 1; cmd_dial = NULL; /* fmg 1/11/94 colors (set defaults) */ /* MARK updated 02/17/95 to be more similiar to TELIX */ mfcolor = YELLOW; mbcolor = BLUE; tfcolor = WHITE; tbcolor = BLACK; sfcolor = WHITE; sbcolor = RED; st_attr = XA_NORMAL; /* If no LANG or LC_ALL is set, fall back to 7bit mode * since in 8bit mode we can't have fancy window borders... */ { char *e1 = getenv("LANG"), *e2 = getenv("LC_ALL"); if ((!e1 || !strcmp("C", e1) || !strcmp("POSIX", e1)) && (!e2 || !strcmp("C", e2) || !strcmp("POSIX", e2))) screen_ibmpc = screen_iso = 0; } /* MARK updated 02/17/95 default history buffer size */ num_hist_lines = 256; /* fmg - but we reset these to F=WHITE, B=BLACK if -b flag found */ /* Before processing the options, first add options * from the environment variable 'MINICOM'. */ args[0] = "minicom"; if ((mc = getenv("MINICOM")) != NULL) { char buf[80]; strncpy(buf, mc, 80); bufp = buf; buf[79] = 0; while (isspace(*bufp)) bufp++; while (*bufp && argk < 19) { for (s = bufp; !isspace(*bufp) && *bufp; bufp++) ; args[argk++] = s; while (isspace(*bufp)) *bufp++ = 0; } } env_args = argk; /* Add command - line options */ for(c = 1; c < argc && argk < 19; c++) args[argk++] = argv[c]; args[argk] = NULL; do { /* Process options with getopt */ while ((c = getopt_long(argk, args, "v78zhlLsomMHb:wTc:a:t:d:p:C:S:D:R:F:", long_options, NULL)) != EOF) switch(c) { case 'v': printf(_("%s version %s"), PACKAGE, VERSION); #ifdef __DATE__ printf(_(" (compiled %s)"), __DATE__); #endif printf("\n"); printf(_("Copyright (C) Miquel van Smoorenburg.\n\n")); printf("This program is free software; you can redistribute it and/or\n" "modify it under the terms of the GNU General Public License\n" "as published by the Free Software Foundation; either version\n" "2 of the License, or (at your option) any later version.\n\n"); exit(1); break; case 's': /* setup mode */ dosetup = 1; break; case 'h': helpthem(); exit(1); break; case 'p': /* Pseudo terminal to use. */ if (strncmp(optarg, "/dev/", 5) == 0) optarg += 5; if (((strncmp(optarg, "tty", 3) != 0) /* /dev/pts support --misiek. */ && (strncmp(optarg, "pts", 3) != 0) /* /dev/pty support --jl. */ && (strncmp(optarg, "pty", 3) != 0)) || !strchr("pqrstuvwxyz/", optarg[3])) { fprintf(stderr, _("minicom: argument to -p must be a pty\n")); exit(1); } snprintf(pseudo, sizeof(pseudo), "/dev/%s", optarg); dial_tty = pseudo; break; case 'm': /* ESC prefix metakey */ alt_override++; alt_code = 27; break; case 'M': /* 8th bit metakey. */ alt_override++; alt_code = 128; break; case 'l': /* Don't assume literal ANSI chars */ screen_ibmpc = 0; break; case 'L': /* Don't assume literal ISO8859 chars */ screen_iso = 0; break; case 't': /* Terminal type */ strncpy(termtype, optarg, sizeof(termtype)); #ifdef __GLIBC__ /* Bug in older libc's (< 4.5.26 I think) */ if ((s = getenv("TERMCAP")) != NULL && *s != '/') unsetenv("TERMCAP"); #endif break; case 'o': /* DON'T initialize */ doinit = 0; break; case 'c': /* Color on/off */ if (strcmp("on", optarg) == 0) { usecolor = 1; stdattr = XA_BOLD; break; } if (strcmp("off", optarg) == 0) { usecolor = 0; stdattr = XA_NORMAL; break; } usage(env_args, optind - 1, mc); break; case 'a': /* Attributes on/off */ if (strcmp("on", optarg) == 0) { useattr = 1; break; } if (strcmp("off", optarg) == 0) { useattr = 0; break; } usage(env_args, optind - 1, mc); break; case 'd': /* Dial from the command line. */ cmd_dial = optarg; break; case 'z': /* Enable status line. */ use_status = 1; break; case 'C': /* Capturing */ capfp = fopen(optarg, "a"); if (capfp == NULL) { werror(_("Cannot open capture file")); exit(1); } docap = 1; vt_set(addlf, -1, docap, -1, -1, -1, -1, -1, addcr); break; case 'S': /* start Script */ strncpy(scr_name, optarg, 33); break; case '7': /* 7bit fallback mode */ screen_ibmpc = screen_iso = 0; break; case '8': /* force 8bit mode */ screen_ibmpc = screen_iso = 1; break; case 'w': /* Linewrap on */ wrapln = 1; break; case 'H': /* Display in hex */ display_hex = 1; break; case 'T': option_T_used = 1; break; case 'F': /* format of status line */ set_status_line_format(optarg); break; case 'b': cmdline_baudrate = optarg; break; case 'D': cmdline_device = optarg; break; case 'R': remote_charset = optarg; break; default: usage(env_args, optind, mc); break; } /* Now, get portname if mentioned. Stop at end or '-'. */ while (optind < argk && args[optind][0] != '-') use_port = args[optind++]; /* Loop again if more options */ } while (optind < argk); init_iconv(remote_charset); if (screen_iso && screen_ibmpc) /* init VT */ vt_set(-1, -1, -1, -1, -1, -1, 1, -1, -1); /* Avoid fraude ! */ for (s = use_port; *s; s++) if (*s == '/') *s = '_'; snprintf(parfile, sizeof(parfile), "%s/minirc.%s", CONFDIR, use_port); /* Get password file information of this user. */ if ((pwd = getpwuid(getuid())) == NULL) { fputs(_("You don't exist. Go away.\n"), stderr); exit(1); } /* Remember home directory and username. */ if ((s = getenv("HOME")) == NULL) strncpy(homedir, pwd->pw_dir, sizeof(homedir)); else strncpy(homedir, s, sizeof(homedir)); strncpy(username, pwd->pw_name, sizeof(username)); /* Get personal parameter file */ snprintf(pparfile, sizeof(pparfile), "%s/.minirc.%s", homedir, use_port); read_parms(); num_hist_lines = atoi(P_HISTSIZE); strcpy(logfname,P_LOGFNAME); /* Set default terminal behaviour */ addlf = strcasecmp(P_ADDLINEFEED, "yes") == 0; local_echo = strcasecmp(P_LOCALECHO, "yes") == 0; addcr = strcasecmp(P_ADDCARRIAGERETURN, "yes") == 0; /* -w overrides config file */ if (!wrapln) wrapln = strcasecmp(P_LINEWRAP, "yes") == 0; /* -H overrides config file */ if (!display_hex) display_hex = strcasecmp(P_DISPLAYHEX, "yes") == 0; /* After reading in the config via read_parms we can possibly overwrite * the baudrate with a value given at the cmdline */ if (cmdline_baudrate) { unsigned int b = strtol(cmdline_baudrate, (char **)NULL, 0); if (speed_valid(b)) { snprintf(P_BAUDRATE, sizeof(P_BAUDRATE), "%d", b); P_BAUDRATE[sizeof(P_BAUDRATE) - 1] = 0; } } /* Now we can also overwrite the device name, if one was given */ if (cmdline_device) { strncpy(P_PORT, cmdline_device, sizeof(P_PORT)); P_PORT[sizeof(P_PORT) - 1] = 0; } stdwin = NULL; /* It better be! */ /* Reset colors if we don't use 'em. */ if (!usecolor) { mfcolor = tfcolor = sfcolor = WHITE; mbcolor = tbcolor = sbcolor = BLACK; st_attr = XA_REVERSE; } if (dial_tty == NULL) { if (!dosetup) { while ((dial_tty = get_port(P_PORT)) != NULL && open_term(doinit, 1, 0) < 0) ; if (dial_tty == NULL) exit(1); } } else { if (!dosetup && open_term(doinit, 1, 0) < 0) exit(1); } mc_setenv("TERM", termtype); if (win_init(tfcolor, tbcolor, XA_NORMAL) < 0) leave(""); if (COLS < 40 || LINES < 10) leave(_("Sorry. Your screen is too small.\n")); if (dosetup) { if (config(1)) { mc_wclose(stdwin, 1); exit(0); } while ((dial_tty = get_port(P_PORT)) != NULL && open_term(doinit, 1, 0) < 0) ; if (dial_tty == NULL) exit(1); } /* Signal handling */ signal(SIGTERM, hangsig); signal(SIGHUP, hangsig); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGPIPE, SIG_IGN); #ifdef SIGTSTP signal(SIGTSTP, shjump); signal(SIGTTIN, SIG_IGN); signal(SIGTTOU, SIG_IGN); #endif #ifdef SIGTINT signal(SIGTINT, SIG_IGN); #endif #ifdef SIGWINCH signal(SIGWINCH, change_size); #endif #ifdef DEBUG for(c = 1; c < _NSIG; c++) { if (c == SIGTERM) continue; /* Saviour when hung */ signal(c, signore); } #endif keyboard(KINSTALL, 0); if (strcmp(P_BACKSPACE, "BS") != 0) keyboard(KSETBS, P_BACKSPACE[0] == 'B' ? 8 : 127); if (alt_override) keyboard(KSETESC, alt_code); else if (strcmp(P_ESCAPE, "^A") != 0) { switch (P_ESCAPE[0]) { case '^': c = P_ESCAPE[1] & 31; break; case 'E': c = 27; break; default: c = 128; break; } keyboard(KSETESC, c); } st = NULL; us = NULL; init_emul(VT100, 1); if (doinit) modeminit(); if (option_T_used) mc_wprintf(us, "WARNING: Option -T ignored, use -F now\n\n"); mc_wprintf(us, "\n%s %s\r\n", _("Welcome to minicom"), VERSION); mc_wprintf(us, "\n%s: %s\r\n", _("OPTIONS"), option_string); #if defined (__DATE__) && defined (__TIME__) mc_wprintf(us, "%s %s, %s.\r\n",_("Compiled on"), __DATE__,__TIME__); #endif { struct stat st; char port_date[20] = ""; if (stat(P_PORT, &st) == 0) { time_t t = time(NULL); struct tm tm; if ( st.st_mtime + 20 * 60 * 60 > t && localtime_r(&st.st_mtime, &tm)) { strftime(port_date, sizeof(port_date), ", %T", &tm); port_date[sizeof(port_date) - 1] = 0; } } mc_wprintf(us, "%s %s%s\r\n", _("Port"), P_PORT, port_date); } if (using_iconv()) mc_wprintf(us, "%s\r\n", _("Using character set conversion")); mc_wprintf(us, _("\nPress %sZ for help on special keys%c\n\n"),esc_key(),'\r'); readdialdir(); if (scr_name[0]) runscript (0, scr_name, "", ""); if (cmd_dial) dialone(cmd_dial); set_local_echo(local_echo); set_addlf(addlf); set_line_timestamp(line_timestamp); /* The main loop calls do_terminal and gets a function key back. */ while (!quit) { c = do_terminal(); dirty_goto: switch (c + 32 *(c >= 'A' && c <= 'Z')) { case 'a': /* Add line feed */ toggle_addlf(); s = addlf ? _("Add linefeed ON") : _("Add linefeed OFF"); status_set_display(s, 0); break; case 'u': /* Add carriage return */ toggle_addcr(); s = addcr ? _("Add carriage return ON") : _("Add carriage return OFF"); status_set_display(s, 0); break; case 'e': /* Local echo on/off. */ toggle_local_echo(); s = local_echo ? _("Local echo ON") : _("Local echo OFF"); status_set_display(s, 0); break; case 'z': /* Help */ c = help(); if (c != 'z') goto dirty_goto; break; case 'c': /* Clear screen */ mc_winclr(us); break; case 'f': /* Send break */ sendbreak(); break; case 'b': /* Scroll back */ scrollback(); break; case 'm': /* Initialize modem */ if (P_HASDCD[0]=='Y' && online >= 0) { c = ask(_("You are online. Really initialize?"), c1); if (c != 0) break; } modeminit(); break; case 'q': /* Exit without resetting */ c = ask(_("Leave without reset?"), c1); if (c == 0) quit = NORESET; if (!strcmp(P_MACCHG,"CHANGED")) { c = ask (_("Save macros?"),c1); if (c == 0) if (dodflsave() < 0) { /* fmg - error */ c = 'O'; /* hehe */ quit = 0; goto dirty_goto; } } break; case 'x': /* Exit Minicom */ c = ask(_("Leave Minicom?"), c1); if (c == 0) { quit = RESET; if(online >= 0) do_hang(0); modemreset(); } if (!strcmp(P_MACCHG,"CHANGED")) { c = ask (_("Save macros?"), c1); if (c == 0) if (dodflsave() < 0) { /* fmg - error */ c = 'O'; /* hehe */ quit = 0; goto dirty_goto; } } break; case 'l': /* Capture file */ if (capfp == (FILE *)0 && !docap) { s = input(_("Capture to which file? "), capname); if (s == NULL || *s == 0) break; if ((capfp = fopen(s, "a")) == (FILE *)NULL) { werror(_("Cannot open capture file")); break; } docap = 1; } else if (capfp != (FILE *)0 && !docap) { c = ask(_("Capture file"), c3); if (c == 0) { fclose(capfp); capfp = (FILE *)NULL; docap = 0; } if (c == 1) docap = 1; } else if (capfp != (FILE *)0 && docap) { c = ask(_("Capture file"), c2); if (c == 0) { fclose(capfp); capfp = (FILE *)NULL; docap = 0; } if (c == 1) docap = 0; } vt_set(addlf, -1, docap, -1, -1, -1, -1, -1, addcr); break; case 'p': /* Set parameters */ get_bbp(P_BAUDRATE, P_BITS, P_PARITY, P_STOPB, 0); port_init(); show_status(); quit = 0; break; case 'k': /* Run kermit */ kermit(); break; case 'h': /* Hang up */ do_hang(1); break; case 'd': /* Dial */ dialdir(); break; case 't': /* Terminal emulation */ c = dotermmenu(); if (c > 0) init_emul(c, 1); break; case 'w': /* Line wrap on-off */ c = !us->wrap; vt_set(addlf, c, docap, -1, -1, -1, -1, -1, addcr); s = c ? _("Linewrap ON") : _("Linewrap OFF"); status_set_display(s, 0); break; case 'n': /* Line timestamp */ toggle_line_timestamp(); switch (line_timestamp) { default: case TIMESTAMP_LINE_OFF: s = _("Timestamp OFF"); break; case TIMESTAMP_LINE_SIMPLE: s = _("Timestamp every line (simple)"); break; case TIMESTAMP_LINE_EXTENDED: s = _("Timestamp every line (extended)"); break; case TIMESTAMP_LINE_PER_SECOND: s = _("Timestamp lines every second"); break; } status_set_display(s, 0); break; case 'o': /* Configure Minicom */ (void) config(0); break; case 's': /* Upload */ updown('U', 0); break; case 'r': /* Download */ updown('D', 0); break; case 'j': /* Jump to a shell */ shjump(0); break; case 'g': /* Run script */ runscript(1, "", "", ""); break; case 'i': /* Re-init, re-open portfd. */ cursormode = (cursormode == NORMAL) ? APPL : NORMAL; keyboard(cursormode == NORMAL ? KCURST : KCURAPP, 0); show_status(); break; case 'y': /* Paste file */ paste_file(); break; case EOF: /* Cannot read from stdin anymore, exit silently */ quit = NORESET; break; default: break; } }; /* Reset parameters */ if (quit != NORESET) m_restorestate(portfd); else { if (P_LOGCONN[0] == 'Y' && online > 0) do_log("%s", _("Quit without reset while online.")); m_hupcl(portfd, 0); } signal(SIGTERM, SIG_IGN); signal(SIGHUP, SIG_IGN); #ifdef SIGTSTP signal(SIGTSTP, SIG_DFL); #endif signal(SIGQUIT, SIG_DFL); if (capfp != (FILE *)0) fclose(capfp); mc_wclose(us, 0); mc_wclose(st, 0); mc_wclose(stdwin, 1); keyboard(KUNINSTALL, 0); lockfile_remove(); close(portfd); if (quit != NORESET && P_CALLIN[0]) fastsystem(P_CALLIN, NULL, NULL, NULL); close_iconv(); return 0; }
int main(int argc, const char *argv[]) // return values: // 1 == error init dpmi / couldn't lock // 2 == error initing log buffers // 3 == error installing lammcall rmcode // 4 == useipxlink requested, but couldn't install // 5 == error while linking // 6 == error loading gp2.exe { char *fullname = NULL; DWORD *pULongCfg = NULL; char *pStrCfg = NULL; char cfgnamebuf[_MAX_PATH]; char *cfgname = NULL; char *gp2exename = GP2_EXE_FILENAME; char *gp2logname = GP2LOG_DEBUG_FILENAME; DWORD dpmicode; ubyte log_flags = 0, i /* count var */; char tmpbuf[128]; #ifndef TEST //----- invoked by our own stub? -------- // ACHTUNG: "GP2LINT" muss ungerade Anzahl Buchstaben haben (wegen updown & gamma) if (strcmp(getenv(updown("GP2LINT")), updown("GAMMA")) != 0) { //--- it's not defined, so leave quiet --- #ifdef TEST fprintf(stderr, "GP2LINT not defined!\n"); #endif return 140; } #endif printf(GP2LAP_BANNER_STR); #ifdef SOCKCLNT printf("This version of GP2Lap was compiled as a socket client.\n"); #endif #ifndef AUTH printf("This version of GP2Lap cannot be used for online leagues that require authentication.\n"); #endif //------- Init configuration if (GetConfigFileNameOpt(cfgnamebuf, _MAX_PATH, argc, (void*)argv)) { cfgname = cfgnamebuf; if (!strchr(cfgname, '.')) strcat(cfgname, ".cfg"); } else cfgname = GP2LAP_CFG_FILENAME; switch (InitCfgValues(cfgname, &paths_to_check, &items, &fullname)) { case 0: printf("- Configuration read from: %s\n", fullname); break; case 1: fprintf(stderr, "*** can't open %s\n", fullname); break; case 2: fprintf(stderr, "*** can't locate %s\n", fullname); break; } pULongCfg = GetCfgULong("logDebug"); if (pULongCfg) setbits(log_flags, BLF_DISABLED, !*pULongCfg); pULongCfg = GetCfgULong("logDebugFlush"); if (pULongCfg) setbits(log_flags, BLF_FLUSHALWAYS, *pULongCfg); pStrCfg = GetCfgString("logDebugName"); if (pStrCfg && strlen(pStrCfg) > 0) // strlen doesn't seem to do nullptr chk gp2logname = pStrCfg; if (isoff(log_flags, BLF_DISABLED)) printf("- Logging debug output to: %s\n", gp2logname); pULongCfg = GetCfgULong("hof25Enable"); if (pULongCfg) opt_hof25 = *pULongCfg; if (opt_hof25) printf("- HOF2.5 mode enabled\n"); pULongCfg = GetCfgULong("logPerf"); if (pULongCfg) opt_log_perf = *pULongCfg; if (opt_log_perf) printf("- Extended perfing enabled\n"); pULongCfg = GetCfgULong("logGLX"); if (pULongCfg) opt_log_glx = *pULongCfg; if (opt_log_glx) { printf("- GLX log file enabled\n"); // only enable opt_log_cc if opt_log_glx is TRUE pULongCfg = GetCfgULong("logCC"); if (pULongCfg) opt_log_cc = *pULongCfg; if (opt_log_cc) printf("- Computer car logging enabled\n"); } pULongCfg = GetCfgULong("Spa98"); if (pULongCfg) opt_spa98 = *pULongCfg; if (opt_spa98) printf("- Spa '98 enabled\n"); if (!LogStart(log_flags, gp2logname) && isoff(log_flags, BLF_DISABLED)) fprintf(stderr, "*** error opening logfile '%s'\n", gp2logname); atexit(LogEnd); #ifdef SOCKCLNT sockInit(); atexit(sockExit); #endif //--- init Frank's stuff ------ init_new_gp2strings(); // init our strings FrankSoftInit(); // atexit'ed //---- init dpmi before all other stuff now ------ dpmicode = dpmi_init(0 /* no verbose */); // atexit'ed if (dpmicode) { fprintf(stderr, "*** dpmi: error %04u\n", dpmicode); return 1; } initvesa(); //---- lock my int9 handler ------ if (!dpmi_lock_region((void near *)(MyInt9), 4096)) { // should be enough if (GetLogDpmiInfo()) LogLine("- dpmi: error: MI9 can't be locked!\n"); } else { if (GetLogDpmiInfo()) LogLine("- dpmis: MI9 locked\n"); } //============================================ //======== the complete logging stuff ======== //============================================ // Warning: don't change options after starting the log system! if (!Log_Create()) { fprintf(stderr, "*** error initing log buffers\n"); return 2; } atexit(Log_Kill); if (!PrfLog_Create()) { fprintf(stderr, "*** error initing perf log buffers\n"); return 2; } atexit(PrfLog_Kill); //================================================= //======== RM-Code fuer int21h vorbereiten ========= //================================================= if ( !install_int21_hook() ) { // atexit'ed fprintf(stderr, "*** lowp: error e004"); return 3; } //============================================ //======== the complete network stuff ======== //============================================ if ( UseIpxLink ) { if ( !ipx_basic_init(0) ) // init the ipx // atexit'ed return 4; if ( !start_ipx_link() ) // init the link return 5; } CloserInit(); // atexit'ed // the very last //---- ok, send alive to logfile ----------- _strdate(&tmpbuf); sprintf(strbuf,"\n"GP2LAP_NAME" started on %s ", tmpbuf); _strtime(&tmpbuf); strcat(strbuf, tmpbuf); strcat(strbuf, "\n"); LogLine(strbuf); sprintf(strbuf, "- Code start at 0x%08x\n", &__begtext); LogLine(strbuf); //----- 08/99 for solving the int2F prob--------------- InitFixInt2F(); //----- Fremdapplikation starten ------- putenv("DOS4G=QUIET"); sprintf(strbuf, "Loading %s...\n", gp2exename); LogLine(strbuf); printf(strbuf); argv[0] = gp2exename; if (spawnv(P_WAIT, gp2exename, (void*)argv) < 0) { // cast to void* to avoid warning about double indirection constness sprintf(strbuf, "*** error loading %s: %s\n", gp2exename, strerror(errno)); LogLine(strbuf); fprintf(stderr, strbuf); } #ifdef TEST sprintf(strbuf, "flagfield = 0x%08x\n", flagfield); LogLine(strbuf); if (GP2_Found && ((flagfield & 0xFFF) != 0x7)) printf("\nflags == 0x%08X\n*** error flag field incorrect\n", flagfield); #endif //--- saying bye now ------ _strdate(&tmpbuf); sprintf(strbuf, GP2LAP_NAME" exiting on %s ", tmpbuf); _strtime(&tmpbuf); strcat(strbuf, tmpbuf); strcat(strbuf, "\n"); LogLine(strbuf); return 0; }
void rotate(vector<vector<int>>& matrix) { if (matrix.size() == 0) return; updown(matrix); diagonal(matrix); }