int ReadScreen( void ) { char name[FNSIZE], directory[FMSIZE]; short button; int f, status; status = 0; getcd( 0, directory); strcat( directory, "\\*.NEO"); *name = 0; fsel_exinput( directory, name, &button, "L„s NEO-sk„rm"); if (button == 1) { *(strrchr( directory, '\\')+1) = 0; strcat( directory, name); f = open( directory, O_RDONLY | O_RAW, 0); if (f >= 0) { if (filelength( f) == 32128) { read( f, Physbase(), 128); read( f, Physbase(), 32000); status = 1; } else form_alert( 1, "[3][Ej NeoChrome fil][Ok]"); close( f); } else form_alert( 1, "[3][Filen finns inte][Ok]"); } return status; }
void initialize(void) { int c; if (appl_init()<0) exit(EXIT_FAILURE); getcd( 0, program_path ); for (c=0;c<10000;c++) { email[c]='\0'; } wind_get(DESK,WF_WORKXYWH,&screenx,&screeny,&screenw,&screenh); graf_mouse(ARROW,NULL); }
void SaveMap( void ) { int f; char directory[ FMSIZE]; getcd( 0, directory); strcat( directory, "\\WORLD.MGS"); f = creat( directory, S_IWRITE | S_IREAD | O_RAW); if (f >= 0) { write( f, gWorld, sizeof( gWorld)); write( f, &gateX, sizeof( gateX)); write( f, &gateY, sizeof( gateY)); close( f); } }
/* wcmd function fills the datastructure rw */ char * wcmd (struct cmd *pcmd, struct wthio *rw) { int ndat = 0; /* length of array containing the data frame */ int err; /* return value of functions, useful for errorhandling */ int retval = 0; long snum = 0; /* current dataset number */ int command; int argcm; unsigned char data[MAXBUFF]; /* data array to store the raw dataframe and the message datagram */ char *clk; /* display time in reasonable format */ char *rbuf; /* return buffer */ syslog(LOG_DEBUG, "wcmd: called for command request: %d\n",pcmd->command); rw->wstat.ndats = 0; command = pcmd->command; argcm = pcmd->argcmd; /* first get status of weatherstation needed to fill sens.status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } pcmd->command = command; syslog(LOG_DEBUG, "wcmd : check status OK\n"); /* status weatherstation */ if ( ( rbuf = wstat(data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } /* command 0 : poll DCF time */ if (command == 0) { tzset(); /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* calculate seconds since EPOCH if DCF synchronized */ rw->DCF.time = dcftime(data, ndat); if (rw->DCF.time == -1) { rbuf = mkmsg("DCF not synchronized\n"); } else { clk = ctime(&rw->DCF.time); rbuf = mkmsg("%s", clk); } } /* command 1 : Request Dataset */ else if (command == 1) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ rw->DCF.time = dcftime(data, ndat); /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { rbuf = mkmsg("no data available (<DLE> received)\n"); } /* fill data structure sens */ else { /* get one dataset */ err = datex(data, ndat, rw); syslog(LOG_DEBUG, "wcmd : returncode datex : %d\n", err); rw->wstat.ndats = rw->wstat.ndats + 1; snum++; } /* echo sensor data */ if ( rw->wstat.ndats > 0 ) rbuf = pdata(rw); } /* command 2 : Select next dataset */ else if (command == 2) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* if DLE no data available */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { rbuf = mkmsg("no data available(<DLE> received)\n"); retval = 16; } else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { /* if ACK next dataset is available */ rbuf = mkmsg("next dataset available (<ACK> received)\n"); retval = 6; } /* exit if unknown response */ else { rbuf = mkmsg("error next dataset : \"unknown response\"\n"); retval = -1; } } /* command 3 : Activate 8 temperature sensors */ else if (command == 3) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { rbuf = mkmsg("set 9 temperature sensors (<ACK> received)\n"); } /* update status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } if ( ( wstat(data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } } /* command 4 : Activate 16 temperature sensors */ else if (command == 4) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { rbuf = mkmsg("set 16 temperature sensors(<ACK> received)\n"); } /* update status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } if ( ( wstat(data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } } /* command 5 : Request status of weatherstation */ else if ( command == 5 ) { ; /* status known, drive thru */ } /* command 6 : Set logging intervall of weatherstation */ else if (command == 6) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { rbuf = mkmsg("set logging interval to %d [min] (<ACK> received)\n", pcmd->argcmd); } /* update status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } if ( ( wstat( data, ndat, rw)) == NULL) { rbuf = mkmsg("wcmd: error in subroutine wstat\n"); return (rbuf); } } /* command 12 : Recursively, request dataset and select next dataset, recursive combination of command 1 and 2 */ else if ( ( command == 12) || ( command == 7) ) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ rw->DCF.time = dcftime(data, ndat); while (retval != 16) { /* write command and retrieve data */ pcmd->command = 1; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* extract dataset from raw dataframe */ /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { rbuf = mkmsg("no data available (<DLE> received)\n"); retval = 16; } /* do extraction */ else { if ( ( err = datex(data, ndat, rw)) == -1) { rbuf = mkmsg("wcmd: error extracting data frame"); return (rbuf); } rw->wstat.ndats = rw->wstat.ndats + 1; } /* write the command word to select next dataset and retrieve response*/ pcmd->command = 2; if ( ( err = getcd( data, &ndat, pcmd)) == -1) { rbuf = mkmsg("wcmd: error data reception\n"); return (rbuf); } /* stop if DLE no data available, */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { /* rbuf = mkmsg( "<DLE> received :\"no data available\"!"); */ retval = 16; } /* if ACK next dataset is available */ else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_DEBUG, \ "wcmd: next dataset available (<ACK> received)!\n"); retval = 6; } /* return if unknown response */ /* no data is returned, maybe too strict? */ else { rbuf = mkmsg( "wcmd: error request next dataset : unknown response\n"); return (rbuf); } syslog(LOG_DEBUG, "wcmd: retval : %d\n", retval); } /* echo sensor data */ if ( rw->wstat.ndats > 0 ) { rbuf = pdata(rw); #if defined POSTGRES if ( command == 7 ) { if ( ( err = pg_data(rw)) == -1 ) { rbuf = mkmsg("wmcd: postgres error\n") ; return (rbuf); } } #endif } }//command 12 || command 7 else { rbuf = mkmsg("unknown command\n"); } syslog(LOG_DEBUG, "wcmd: exit OK\n"); return(rbuf); }//wcmd()
/* * Parse an address. * Just about any sequence of address characters is legal. * * If you are tricky you can use this routine and the = command * to do simple addition and subtraction of cardinals less * than the number of lines in the file. */ line * address(char *inputline) { register line *addr; register int offset, c; short lastsign; bigmove = 0; lastsign = 0; offset = 0; addr = 0; for (;;) { if (isdigit(peekcd())) { if (addr == 0) { addr = zero; bigmove = 1; } loc1 = 0; addr += offset; offset = getnum(); if (lastsign >= 0) addr += offset; else addr -= offset; lastsign = 0; offset = 0; } switch (c = getcd()) { case '?': case '/': case '$': case '\'': case '\\': bigmove++; case '.': if (addr || offset) error("Badly formed address"); } offset += lastsign; lastsign = 0; switch (c) { case ' ': case '\t': continue; case '+': lastsign = 1; if (addr == 0) addr = dot; continue; case '^': case '-': lastsign = -1; if (addr == 0) addr = dot; continue; case '\\': case '?': case '/': c = compile(c, 1); notempty(); savere(scanre); addr = dot; if (inputline && execute(0, dot)) { if (c == '/') { while (loc1 <= inputline) { if (loc1 == loc2) loc2++; if (!execute(1, NULL)) goto nope; } break; } else if (loc1 < inputline) { char *last; doques: do { last = loc1; if (loc1 == loc2) loc2++; if (!execute(1, NULL)) break; } while (loc1 < inputline); loc1 = last; break; } } nope: for (;;) { if (c == '/') { addr++; if (addr > dol) { if (value(WRAPSCAN) == 0) error("No match to BOTTOM|Address search hit BOTTOM without matching pattern"); addr = zero; } } else { addr--; if (addr < zero) { if (value(WRAPSCAN) == 0) error("No match to TOP|Address search hit TOP without matching pattern"); addr = dol; } } if (execute(0, addr)) { if (inputline && c == '?') { inputline = &linebuf[LBSIZE]; goto doques; } break; } if (addr == dot) error("Fail|Pattern not found"); } continue; case '$': addr = dol; continue; case '.': addr = dot; continue; case '\'': c = markreg(ex_getchar()); if (c == 0) error("Marks are ' and a-z"); addr = getmark(c); if (addr == 0) error("Undefined mark@referenced"); break; default: ungetchar(c); if (offset) { if (addr == 0) addr = dot; addr += offset; loc1 = 0; } if (addr == 0) { bigmove = 0; return (0); } if (addr != zero) notempty(); addr += lastsign; if (addr < zero) error("Negative address@- first buffer line is 1"); if (addr > dol) error("Not that many lines@in buffer"); return (addr); } } }
/* * Main loop for command mode command decoding. * A few commands are executed here, but main function * is to strip command addresses, do a little address oriented * processing and call command routines to do the real work. */ void commands(bool noprompt, bool exitoneof) { register line *addr; register int c; register int lchng; int given; int seensemi; int cnt; bool hadpr; resetflav(); nochng(); for (;;) { /* * If dot at last command * ended up at zero, advance to one if there is a such. */ if (dot <= zero) { dot = zero; if (dol > zero) dot = one; } shudclob = 0; /* * If autoprint or trailing print flags, * print the line at the specified offset * before the next command. */ if (pflag || (lchng != chng && value(AUTOPRINT) && !inglobal && !inopen && endline)) { pflag = 0; nochng(); if (dol != zero) { addr1 = addr2 = dot + poffset; if (addr1 < one || addr1 > dol) error("Offset out-of-bounds|Offset after command too large"); setdot1(); goto print; } } nochng(); /* * Print prompt if appropriate. * If not in global flush output first to prevent * going into pfast mode unreasonably. */ if (inglobal == 0) { flush(); if (!hush && value(PROMPT) && !globp && !noprompt && endline) { ex_putchar(':'); hadpr = 1; } TSYNC(); } /* * Gobble up the address. * Degenerate addresses yield ".". */ addr2 = 0; given = seensemi = 0; do { addr1 = addr2; addr = address(0); c = getcd(); if (addr == 0) { if (c == ',') addr = dot; else if (addr1 != 0) { addr2 = dot; break; } else break; } addr2 = addr; given++; if (c == ';') { c = ','; dot = addr; seensemi = 1; } } while (c == ','); if (c == '%') { /* %: same as 1,$ */ addr1 = one; addr2 = dol; given = 2; c = ex_getchar(); } if (addr1 == 0) addr1 = addr2; if (c == ':') c = ex_getchar(); /* * Set command name for special character commands. */ tailspec(c); /* * If called via : escape from open or visual, limit * the set of available commands here to save work below. */ if (inopen) { if (c=='\n' || c=='\r' || c==CTRL('d') || c==EOF) { if (addr2) dot = addr2; if (c == EOF) return; continue; } if (any(c, "o")) notinvis: tailprim(Command, 1, 1); } switch (c) { case 'a': switch(peekchar()) { case 'b': /* abbreviate */ tail("abbreviate"); setnoaddr(); mapcmd(0, 1); anyabbrs = 1; continue; case 'r': /* args */ tail("args"); setnoaddr(); eol(); pargs(); continue; } /* append */ if (inopen) goto notinvis; tail("append"); setdot(); aiflag = exclam(); ex_newline(); vmacchng(0); deletenone(); setin(addr2); inappend = 1; ignore(append(gettty, addr2)); inappend = 0; nochng(); continue; case 'c': switch (peekchar()) { /* copy */ case 'o': tail("copy"); vmacchng(0); move(); continue; #ifdef CHDIR /* cd */ case 'd': tail("cd"); goto changdir; /* chdir */ case 'h': ignchar(); if (peekchar() == 'd') { register char *p; tail2of("chdir"); changdir: if (savedfile[0] == '/' || !value(WARN)) ignore(exclam()); else ignore(quickly()); if (skipend()) { p = getenv("HOME"); if (p == NULL) error("Home directory unknown"); } else getone(), p = file; eol(); if (chdir(p) < 0) filioerr(p); if (savedfile[0] != '/') edited = 0; continue; } if (inopen) tailprim("change", 2, 1); tail2of("change"); break; #endif default: if (inopen) goto notinvis; tail("change"); break; } /* change */ aiflag = exclam(); setCNL(); vmacchng(0); setin(addr1); delete(0); inappend = 1; ignore(append(gettty, addr1 - 1)); inappend = 0; nochng(); continue; /* delete */ case 'd': /* * Caution: dp and dl have special meaning already. */ tail("delete"); c = cmdreg(); setCNL(); vmacchng(0); if (c) YANKreg(c); delete(0); appendnone(); continue; /* edit */ /* ex */ case 'e': tail(peekchar() == 'x' ? "ex" : "edit"); editcmd: if (!exclam() && chng) c = 'E'; filename(c); if (c == 'E') { ungetchar(lastchar()); ignore(quickly()); } setnoaddr(); doecmd: init(); addr2 = zero; laste++; ex_sync(); rop(c); nochng(); continue; /* file */ case 'f': tail("file"); setnoaddr(); filename(c); noonl(); /* synctmp(); */ continue; /* global */ case 'g': tail("global"); global(!exclam()); nochng(); continue; /* insert */ case 'i': if (inopen) goto notinvis; tail("insert"); setdot(); nonzero(); aiflag = exclam(); ex_newline(); vmacchng(0); deletenone(); setin(addr2); inappend = 1; ignore(append(gettty, addr2 - 1)); inappend = 0; if (dot == zero && dol > zero) dot = one; nochng(); continue; /* join */ case 'j': tail("join"); c = exclam(); setcount(); nonzero(); ex_newline(); vmacchng(0); if (given < 2 && addr2 != dol) addr2++; join(c); continue; /* k */ case 'k': casek: pastwh(); c = ex_getchar(); if (endcmd(c)) serror("Mark what?|%s requires following letter", Command); ex_newline(); if (!islower(c)) error("Bad mark|Mark must specify a letter"); setdot(); nonzero(); names[c - 'a'] = *addr2 &~ 01; anymarks = 1; continue; /* list */ case 'l': tail("list"); setCNL(); ignorf(setlist(1)); pflag = 0; goto print; case 'm': if (peekchar() == 'a') { ignchar(); if (peekchar() == 'p') { /* map */ tail2of("map"); setnoaddr(); mapcmd(0, 0); continue; } /* mark */ tail2of("mark"); goto casek; } /* move */ tail("move"); vmacchng(0); move(); continue; case 'n': if (peekchar() == 'u') { tail("number"); goto numberit; } /* next */ tail("next"); setnoaddr(); ckaw(); ignore(quickly()); if (getargs()) makargs(); next(); c = 'e'; filename(c); goto doecmd; /* open */ case 'o': tail("open"); oop(); pflag = 0; nochng(); continue; case 'p': case 'P': switch (peekchar()) { /* put */ case 'u': tail("put"); setdot(); c = cmdreg(); eol(); vmacchng(0); if (c) putreg(c); else put(); continue; case 'r': ignchar(); if (peekchar() == 'e') { /* preserve */ tail2of("preserve"); eol(); if (preserve() == 0) error("Preserve failed!"); else error("File preserved."); } tail2of("print"); break; default: tail("print"); break; } /* print */ setCNL(); pflag = 0; print: nonzero(); if (CL && span() > EX_LINES) { flush1(); vclear(); } plines(addr1, addr2, 1); continue; /* quit */ case 'q': tail("quit"); setnoaddr(); c = quickly(); eol(); if (!c) quit: nomore(); if (inopen) { vgoto(WECHO, 0); if (!ateopr()) vnfl(); else { tostop(); } flush(); setty(normf); } cleanup(1); ex_exit(0); case 'r': if (peekchar() == 'e') { ignchar(); switch (peekchar()) { /* rewind */ case 'w': tail2of("rewind"); setnoaddr(); if (!exclam()) { ckaw(); if (chng && dol > zero) error("No write@since last chage (:rewind! overrides)"); } eol(); erewind(); next(); c = 'e'; ungetchar(lastchar()); filename(c); goto doecmd; /* recover */ case 'c': tail2of("recover"); setnoaddr(); c = 'e'; if (!exclam() && chng) c = 'E'; filename(c); if (c == 'E') { ungetchar(lastchar()); ignore(quickly()); } init(); addr2 = zero; laste++; ex_sync(); recover(); rop2(); revocer(); if (status == 0) rop3(c); if (dol != zero) change(); nochng(); continue; } tail2of("read"); } else tail("read"); /* read */ if (savedfile[0] == 0 && dol == zero) c = 'e'; pastwh(); vmacchng(0); if (peekchar() == '!') { setdot(); ignchar(); unix0(0); filter(0); continue; } filename(c); rop(c); nochng(); if (inopen && endline && addr1 > zero && addr1 < dol) dot = addr1 + 1; continue; case 's': switch (peekchar()) { /* * Caution: 2nd char cannot be c, g, or r * because these have meaning to substitute. */ /* set */ case 'e': tail("set"); setnoaddr(); set(); continue; /* shell */ case 'h': tail("shell"); setNAEOL(); vnfl(); putpad(TE); flush(); unixwt(1, unixex("-i", (char *) 0, 0, 0)); vcontin(0); continue; /* source */ case 'o': #ifdef notdef if (inopen) goto notinvis; #endif tail("source"); setnoaddr(); getone(); eol(); source(file, 0); continue; #ifdef SIGTSTP /* stop, suspend */ case 't': tail("stop"); goto suspend; case 'u': tail("suspend"); suspend: if (!dosusp) error("Old tty driver|Not using new tty driver/shell"); c = exclam(); eol(); if (!c) ckaw(); onsusp(0); continue; #endif } /* fall into ... */ /* & */ /* ~ */ /* substitute */ case '&': case '~': Command = "substitute"; if (c == 's') tail(Command); vmacchng(0); if (!substitute(c)) pflag = 0; continue; /* t */ case 't': if (peekchar() == 'a') { tail("tag"); tagfind(exclam()); if (!inopen) lchng = chng - 1; else nochng(); continue; } tail("t"); vmacchng(0); move(); continue; case 'u': if (peekchar() == 'n') { ignchar(); switch(peekchar()) { /* unmap */ case 'm': tail2of("unmap"); setnoaddr(); mapcmd(1, 0); continue; /* unabbreviate */ case 'a': tail2of("unabbreviate"); setnoaddr(); mapcmd(1, 1); anyabbrs = 1; continue; } /* undo */ tail2of("undo"); } else tail("undo"); setnoaddr(); markDOT(); c = exclam(); ex_newline(); undo(c); continue; case 'v': switch (peekchar()) { case 'e': /* version */ tail("version"); setNAEOL(); ex_printf("@(#) Version 3.6, 11/3/80" " (4.0BSD). git " "160803 14:24" +5); noonl(); continue; /* visual */ case 'i': tail("visual"); if (inopen) { c = 'e'; goto editcmd; } vop(); pflag = 0; nochng(); continue; } /* v */ tail("v"); global(0); nochng(); continue; /* write */ case 'w': c = peekchar(); tail(c == 'q' ? "wq" : "write"); wq: if (skipwh() && peekchar() == '!') { pofix(); ignchar(); setall(); unix0(0); filter(1); } else { setall(); wop(1); nochng(); } if (c == 'q') goto quit; continue; /* xit */ case 'x': tail("xit"); if (!chng) goto quit; c = 'q'; goto wq; /* yank */ case 'y': tail("yank"); c = cmdreg(); setcount(); eol(); vmacchng(0); if (c) YANKreg(c); else yank(); continue; /* z */ case 'z': zop(0); pflag = 0; continue; /* * */ /* @ */ case '*': case '@': c = ex_getchar(); if (c=='\n' || c=='\r') ungetchar(c); if (any(c, "@*\n\r")) c = lastmac; if (isupper(c)) c = tolower(c); if (!islower(c)) error("Bad register"); ex_newline(); setdot(); cmdmac(c); continue; /* | */ case '|': endline = 0; goto caseline; /* \n */ case '\n': endline = 1; caseline: notempty(); if (addr2 == 0) { if (UP != NOSTR && c == '\n' && !inglobal) c = CTRL('k'); if (inglobal) addr1 = addr2 = dot; else { if (dot == dol) error("At EOF|At end-of-file"); addr1 = addr2 = dot + 1; } } setdot(); nonzero(); if (seensemi) addr1 = addr2; ex_getline(*addr1); if (c == CTRL('k')) { flush1(); destline--; if (hadpr) shudclob = 1; } plines(addr1, addr2, 1); continue; /* " */ case '"': comment(); continue; /* # */ case '#': numberit: setCNL(); ignorf(setnumb(1)); pflag = 0; goto print; /* = */ case '=': ex_newline(); setall(); if (inglobal == 2) pofix(); ex_printf("%d", lineno(addr2)); noonl(); continue; /* ! */ case '!': if (addr2 != 0) { vmacchng(0); unix0(0); setdot(); filter(2); } else { unix0(1); pofix(); putpad(TE); flush(); unixwt(1, unixex("-c", uxb, 0, 0)); vclrech(1); /* vcontin(0); */ nochng(); } continue; /* < */ /* > */ case '<': case '>': for (cnt = 1; peekchar() == c; cnt++) ignchar(); setCNL(); vmacchng(0); shift(c, cnt); continue; /* ^D */ /* EOF */ case CTRL('d'): case EOF: if (exitoneof) { if (addr2 != 0) dot = addr2; return; } if (!isatty(0)) { if (intty) /* * Chtty sys call at UCB may cause a * input which was a tty to suddenly be * turned into /dev/null. */ onhup(0); return; } if (addr2 != 0) { setlastchar('\n'); putnl(); } if (dol == zero) { if (addr2 == 0) putnl(); notempty(); } ungetchar(EOF); zop(hadpr); continue; default: if (!isalpha(c)) break; ungetchar(c); tailprim("", 0, 0); } ierror("What?|Unknown command character '%c'", c); } }
/* wcmd function fills the datastructure sens */ int wcmd (struct sensor sens[], struct cmd *pcmd, int *setno) { int i; /* for array subscription */ int ndat = 0; /* length of array containing the data frame */ int err; /* return value of functions, useful for errorhandling */ int retval = 0; /* return values for this function */ /* 0 : everythings fine */ /* 1 : no data available */ /* -1 : unknown response of weatherstation */ int snum = 0; /* number of data sets */ int command; int argcm; struct DCFstruct DCF; /* DCF status and synchronous */ struct wstatus setting; u_char data[MAXBUFF]; /* data array to store the raw dataframe and the message datagram */ char *clk; /* display time in reasonable format */ command = pcmd->command; argcm = pcmd->argcmd; /* first get status of weatherstation needed to fill sens.status */ pcmd->command = 5; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); pcmd->command = command; syslog(LOG_INFO, "wcmd : check status OK\n"); /* status weatherstation */ err = wstat(data, ndat, &DCF, sens, &setting); syslog(LOG_INFO, "wcmd : DCF.stat : %d\n", DCF.stat); syslog(LOG_INFO, "wcmd : DCF.sync : %d\n", DCF.sync); syslog(LOG_INFO, "wcmd : number sensors : %d\n", setting.numsens); syslog(LOG_INFO, "wcmd : version : %x\n", setting.version); for ( i = 0; i < MAXSENSORS; i++ ) { syslog(LOG_DEBUG, "wcmd : sens[%d].status: %d, type: %s\n", i, sens[i].status, sens[i].type); } /* command 0 : poll DCF time */ if (command == 0) { /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* calculate seconds since EPOCH if DCF synchronized */ DCF.time = dcftime(data, ndat); if (DCF.time == -1) printf("Weatherstation not synchronized\n"); else { clk = ctime(&DCF.time); printf("%s", clk); } } /* command 1 : Request Dataset */ else if (command == 1) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ DCF.time = dcftime(data, ndat); /* write command and retrieve data */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, "wcmd : DLE received : weather station :\"no data available\": exit!\n"); retval = 16; } /* fill data structure sens */ else { /* get one dataset */ err = getone(data, ndat, sens, snum, DCF); syslog(LOG_INFO, "wcmd : returncode getone : %d\n", err); snum++; } /* echo sensor data */ err = pdata(sens, snum); } /* command 2 : Select next dataset */ else if (command == 2) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* if DLE no data available */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, \ "wcmd : DLE received : weather station :\"no data available\"!\n"); retval = 16; } else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) /* if ACK next dataset is available */ { syslog(LOG_INFO, \ "wcmd : ACK received : weather station :\"next dataset available\": exit!\n"); retval = 6; } /* exit if unknown response */ else { syslog(LOG_EMERG, "wcmd : error request next dataset : unknown response: exit \n"); retval = -1; } } /* command 3 : Activate 8 temperature sensors */ else if (command == 3) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, "wcmd : ACK received\n"); printf("Weatherstation response : <ACK>\n"); } } /* command 4 : Activate 16 temperature sensors */ else if (command == 4) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, "wcmd : ACK received\n"); printf("Weatherstation response : <ACK>\n"); } } /* command 5 : Request status of weatherstation */ else if ( command == 5 ) { /* check status - this is done at every call of wcmd*/ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* status weatherstation */ err = wstat(data, ndat, &DCF, sens, &setting); syslog(LOG_INFO, "wcmd : DCF.stat : %d\n", DCF.stat); syslog(LOG_INFO, "wcmd : DCF.sync : %d\n", DCF.sync); syslog(LOG_INFO, "wcmd : number sensors : %d\n", setting.numsens); syslog(LOG_INFO, "wcmd : version : %x\n", setting.version); for ( i = 0; i < MAXSENSORS; i++ ) { syslog(LOG_DEBUG, "wcmd : sens[%d].status: %d, type: %s\n", i, sens[i].status, sens[i].type); } printf("Status weatherstation\n"); printf("Version : %x\n", setting.version); printf("Interval : %d\n", setting.intv); printf("Numsens : %d\n", setting.numsens); printf("DCF.stat : %d\n", DCF.stat); printf("DCF.sync : %d\n", DCF.sync); } /* command 6 : Set logging intervall of weatherstation */ else if (command == 6) { /* write the command word to the weather station */ /* extract message datagram */ if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : <ACK> */ if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, "wcmd : ACK received\n"); printf("Weatherstation response : <ACK>\n"); } } /* command 12 : Recursively, request dataset and select next dataset, recursive combination of command 1 and 2 */ else if (command == 12) { /* first get DCF time if possible */ pcmd->command = 0; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); pcmd->command = command; /* calculate seconds since EPOCH if DCF synchronized */ DCF.time = dcftime(data, ndat); while (retval != 16) { /* write command and retrieve data */ pcmd->command = 1; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* weather station response : no data available: <DLE> */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, \ "wcmd : DLE received : weather station :\"no data available\"!\n"); retval = 16; } /* fill data structure sens */ else { /* get one dataset */ err = getone(data, ndat, sens, snum, DCF); syslog(LOG_INFO, "wcmd : returncode getone : %d\n", err); /* increase dataset number index */ snum++; } /* write the command word to select next dataset and retrieve response*/ pcmd->command = 2; if ( ( err = getcd( data, &ndat, pcmd)) == -1) return(-1); /* if DLE no data available */ if ( ( ndat == 1 ) && ( data[0] == DLE ) ) { syslog(LOG_INFO, \ "wcmd : DLE received : weather station :\"no data available\"!\n"); printf("DLE received : weather station :\"no data available\"!\n"); retval = 16; } /* if ACK next dataset is available */ else if ( ( ndat == 1 ) && ( data[0] == ACK ) ) { syslog(LOG_INFO, \ "wcmd : ACK received : weather station :\"next dataset available\"!\n"); retval = 6; } /* exit if unknown response */ else { syslog(LOG_EMERG, \ "wcmd : error request next dataset : unknown response: exit \n"); retval = -2; } syslog(LOG_INFO, "wcmd : retval : %d\n", retval); } /* echo sensor data */ err = pdata(sens, snum); } else { printf("Unknown command: exit!\n"); exit(1); } *setno = snum; syslog(LOG_INFO, "wcmd : returncode wcmd : %d, number of sets : %d\n", retval, *setno); return(retval); }