} /* stop rtk server -----------------------------------------------------------*/ static void stopsvr(vt_t *vt) { char s[3][MAXRCVCMD]={"","",""},*cmds[]={NULL,NULL,NULL}; int i,ret; trace(3,"stopsvr:\n"); if (!svr.state) return; /* read stop commads from command files */ for (i=0;i<3;i++) { if (!*rcvcmds[i]) continue; if (!readcmd(rcvcmds[i],s[i],1)) { printvt(vt,"no command file: %s\n",rcvcmds[i]); } else cmds[i]=s[i]; } /* stop rtk server */ rtksvrstop(&svr,cmds); /* execute stop command */ if (*stopcmd&&(ret=system(stopcmd))) { trace(2,"command exec error: %s (%d)\n",stopcmd,ret); printvt(vt,"command exec error: %s (%d)\n",stopcmd,ret); }
// USB device main loop static void* devmain(usbdevice* kb){ // dmutex should still be locked when this is called int kbfifo = kb->infifo - 1; readlines_ctx linectx; readlines_ctx_init(&linectx); while(1){ pthread_mutex_unlock(dmutex(kb)); // Read from FIFO const char* line; int lines = readlines(kbfifo, linectx, &line); pthread_mutex_lock(dmutex(kb)); // End thread when the handle is removed if(!IS_CONNECTED(kb)) break; if(lines){ if(readcmd(kb, line)){ // USB transfer failed; destroy device closeusb(kb); break; } } } pthread_mutex_unlock(dmutex(kb)); readlines_ctx_free(linectx); return 0; }
/* * Command parser. */ static __dead void command(void) { struct cmd *c; for (;;) { printf("%s> ", prompt); if (readcmd(line, LBUFLEN, stdin) < 1) continue; if ((line[0] == 0) || (line[0] == '\n')) continue; if (makeargv()) continue; if (margc == 0) continue; c = getcmd(margv[0]); if (c == (struct cmd *) - 1) { printf("?Ambiguous command\n"); continue; } if (c == 0) { printf("?Invalid command\n"); continue; } (*c->handler)(margc, margv); } }
// USB device main loop static void* devmain(usbdevice* kb){ readlines_ctx linectx; readlines_ctx_init(&linectx); while(1){ pthread_mutex_lock(dmutex(kb)); // End thread when the handle is removed if(!IS_CONNECTED(kb)) break; // Read from FIFO const char* line; euid_guard_start; int lines = readlines(kb->infifo - 1, linectx, &line); euid_guard_stop; if(lines){ if(readcmd(kb, line)){ // USB transfer failed; destroy device closeusb(kb); break; } } // Update indicator LEDs for this keyboard. These are polled rather than processed during events because they don't update // immediately and may be changed externally by the OS. // (also, they can lock the keyboard if they're sent at the wrong time, at least on some firmwares) kb->vtable->updateindicators(kb, 0); // Wait a little bit and then read again pthread_mutex_unlock(dmutex(kb)); DELAY_SHORT(kb); } pthread_mutex_unlock(dmutex(kb)); readlines_ctx_free(linectx); return 0; }
void setblksize(int argc, char *argv[]) { int t; const char *errstr; if (argc < 2) { strlcpy(line, "Blocksize ", sizeof(line)); printf("(value) "); readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin); if (makeargv()) return; argc = margc; argv = margv; } if (argc != 2) { printf("usage: %s value\n", argv[0]); return; } t = strtonum(argv[1], SEGSIZE_MIN, SEGSIZE_MAX, &errstr); if (errstr) printf("%s: value is %s\n", argv[1], errstr); else { if (opt_blksize == 0) has_options++; opt_blksize = t; } }
void settimeout(int argc, char *argv[]) { int t; const char *errstr; if (argc < 2) { strlcpy(line, "Maximum-timeout ", sizeof(line)); printf("(value) "); readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin); if (makeargv()) return; argc = margc; argv = margv; } if (argc != 2) { printf("usage: %s value\n", argv[0]); return; } t = strtonum(argv[1], TIMEOUT_MIN, TIMEOUT_MAX, &errstr); if (errstr) printf("%s: value is %s\n", argv[1], errstr); else maxtimeout = t; }
int main() { char* buff; while((buff = readcmd()) != NULL) { char** args = parse_cmdline(buff); pid_t child, end; int status; /*Start a child process*/ if ((child = fork()) == -1) { fprintf(stderr, "%s\n", "Failed to execute!"); } /*This is the child*/ else if (child == 0) { int err = execv(args[0], args); if(err != -1) { exit(EXIT_SUCCESS); } else { fprintf(stderr, "%s\n", strerror(errno)); exit(EXIT_FAILURE); } }/* This is the parent.*/ else { end = waitpid(child, &status, WNOHANG|WUNTRACED); /* child ended*/ if (end == child) { if (WIFSIGNALED(status)) fprintf(stderr, "%s\n", "Command ended because of an uncaught signal"); else if (WIFSTOPPED(status)) fprintf(stderr, "%s\n", "Command has unexpectedly stopped"); } } } return 0; }
static bool neteng_cmd_exec(pid_t child, int read_fd, int write_fd, enum netcmds nc) { sendcmd(write_fd, nc); enum netcmds ncr = readcmd(read_fd, log_state->debug ? 1000 : 60); if (ncr != NC_OK) return false; return true; }
int ldiskfs_read_ldd(char *dev, struct lustre_disk_data *mo_ldd) { char tmpdir[] = "/tmp/dirXXXXXX"; char cmd[PATH_MAX]; char filepnm[128]; FILE *filep; int ret = 0; int cmdsz = sizeof(cmd); /* Make a temporary directory to hold Lustre data files. */ if (!mkdtemp(tmpdir)) { fprintf(stderr, "%s: Can't create temporary directory %s: %s\n", progname, tmpdir, strerror(errno)); return errno; } /* TODO: it's worth observing the get_mountdata() function that is in mount_utils.c for getting the mountdata out of the filesystem */ /* Construct debugfs command line. */ snprintf(cmd, cmdsz, "%s -c -R 'dump /%s %s/mountdata' '%s'", DEBUGFS, MOUNT_DATA_FILE, tmpdir, dev); ret = run_command(cmd, cmdsz); if (ret) verrprint("%s: Unable to dump %s dir (%d)\n", progname, MOUNT_CONFIGS_DIR, ret); sprintf(filepnm, "%s/mountdata", tmpdir); filep = fopen(filepnm, "r"); if (filep) { size_t num_read; vprint("Reading %s\n", MOUNT_DATA_FILE); num_read = fread(mo_ldd, sizeof(*mo_ldd), 1, filep); if (num_read < 1 && ferror(filep)) { fprintf(stderr, "%s: Unable to read from file %s: %s\n", progname, filepnm, strerror(errno)); } fclose(filep); } snprintf(cmd, cmdsz, "rm -rf %s", tmpdir); run_command(cmd, cmdsz); if (ret) verrprint("Failed to read old data (%d)\n", ret); /* As long as we at least have the label, we're good to go */ snprintf(cmd, sizeof(cmd), E2LABEL" %s", dev); ret = readcmd(cmd, mo_ldd->ldd_svname, sizeof(mo_ldd->ldd_svname) - 1); return ret; }
void dv_buy() { do { printf("What thing do you want to buy?\n" " [1] - Knife\n" /* weapon +1 */ " [2] - Sword\n"); /* weapon +5 */ cmd = readcmd(); switch (cmd) { case '1': weapon = 1; break; case '2': weapon = 5; break; default: unknowncmd(); break; } } while (cmd == '\0'); }
void setpeer(int argc, char *argv[]) { struct hostent *host; const char *errstr; if (argc < 2) { strlcpy(line, "Connect ", sizeof(line)); printf("(to) "); readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin); if (makeargv()) return; argc = margc; argv = margv; } if ((argc < 2) || (argc > 3)) { printf("usage: %s [host [port]]\n", argv[0]); return; } if (inet_aton(argv[1], &peeraddr.sin_addr) != 0) { peeraddr.sin_family = AF_INET; (void)strncpy(hostname, argv[1], sizeof(hostname)); hostname[sizeof(hostname) - 1] = '\0'; } else { host = gethostbyname(argv[1]); if (host == 0) { connected = 0; printf("%s: unknown host\n", argv[1]); return; } peeraddr.sin_family = host->h_addrtype; bcopy(host->h_addr, &peeraddr.sin_addr, host->h_length); (void)strlcpy(hostname, host->h_name, sizeof(hostname)); } port = sp->s_port; if (argc == 3) { port = strtonum(argv[2], 1, 65535, &errstr); if (errstr) { printf("%s: port number is %s\n", argv[2], errstr); connected = 0; return; } port = htons(port); } connected = 1; }
void dv() { do { printf("Welcome to Digital Village!\n" " [l] - Leave this village\n" " [s] - Go shopping\n" " [h] - Return to home\n"); cmd = readcmd(); switch (cmd) { case 'l': break; case 's': dv_shop(); loop = 1; break; case 'h': dv_home(); loop = 1; break; default: unknowncmd(); } } while (loop == 1); }
void dv_shop() { char cmd; do { printf("Welcome to the shop of digital village!\n" "Want to buy or sell?\n" " [b] - I want to buy somthing please\n" " [s] - Sell\n" " [q] - Bye!\n"); cmd = readcmd(); switch (cmd) { case 'b': dv_buy(); break; case 's': break; case 'q': printf("Tux leave the shop...\n\n"); loop = 0; break; default: unknowncmd(); } } while (loop == 1); }
void dv_home() /* Tux's Home */ { do { printf("You are now in your home, enjoy!\n"); printf(" [e] - Go outdoor\n" " [s] - Sleep\n" " [l] - List your state\n"); cmd = readcmd(); switch (cmd) { case 'e': printf("You Leave your home...\n\n"); loop = 0; break; case 's': dv_sleep(); break; case 'l': state(); break; default: unknowncmd(); } } while (loop == 1); }
int main(int argc, char *argv[]) { char buf[256] = {0}; char *cmd = NULL; char **args = NULL; int pid = 0; while (1) { newline(); write (1, "$ ", 2); args = readcmd (buf, &cmd); // parse user input if ((pid = fork ()) == 0) { // child? execv (cmd, args); } else if (pid > 0) { // parent? wait (0); // wait for child to terminate } else { perror ("fork"); sleep(1000); } } return 0; }
void parsearg(int argc, char *argv[]) { if (argc < 2) { strlcpy(line, "Connect ", sizeof(line)); printf("(to) "); readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin); if (makeargv()) return; argc = margc; argv = margv; } if ((argc < 2) || (argc > 3)) { printf("usage: %s [host [port]]\n", argv[0]); return; } if (argc == 2) setpeer(argv[1], NULL); else setpeer(argv[1], argv[2]); }
void nc_pipe_evt(int fd, short events, void *priv) { struct net_child_info *nci = priv; enum netcmds nc = readcmd(nci->read_fd, 0); switch (nc) { case NC_START: nci->running = true; event_base_loopbreak(nci->eb); sendcmd(nci->write_fd, NC_OK); break; case NC_STOP: nci->running = false; event_base_loopbreak(nci->eb); sendcmd(nci->write_fd, NC_OK); break; default: exit(1); } }
int main() { printf("Variante %d: %s\n", VARIANTE, VARIANTE_STRING); while (1) { struct cmdline *l; int i, j; char *prompt = "ensishell>"; l = readcmd(prompt); /* If input stream closed, normal termination */ if (!l) { printf("exit\n"); exit(0); } if (l->err) { /* Syntax error, read another command */ printf("error: %s\n", l->err); continue; } if (l->in) printf("in: %s\n", l->in); if (l->out) printf("out: %s\n", l->out); if (l->bg) printf("background (&)\n"); /* Display each command of the pipe */ for (i=0; l->seq[i]!=0; i++) { char **cmd = l->seq[i]; printf("seq[%d]: ", i); for (j=0; cmd[j]!=0; j++) { printf("'%s' ", cmd[j]); } printf("\n"); } } }
int main(void) { int res,ret; char cmd[MAXCMD]; struct cmdlist cmds; struct rlimit r; r.rlim_cur = 50; r.rlim_max = 10000; setrlimit(RLIMIT_FSIZE,&r); /* setting up the initial values of the structure */ /* this should be done every time when new object is created */ setupnewcommand(&cmds); /* Setting up file size limit for this process and for the child processes */ /* main loop of the shell */ /* this loop proceses command wirtten by user in the following steps: */ /* 1. Displaying command prompt 2. Reading command from the std input 3. Parsing this command 4. Executing parsed commands 5. Dealocating used memory */ while(1){ printprompt(); if(readcmd(cmd, MAXCMD) == RESERROR) continue; res = parsecmd(cmd, MAXCMD, &cmds); printparsedcmds(&cmds); ret = executecmds(&cmds); dealocate(&cmds); } return 0; }
void *Command(void *argument) { // int recID, varID, levelID; // int nmiss; double s_utime, s_stime; double e_utime, e_stime; double c_cputime = 0, c_usertime = 0, c_systime = 0; char line[MAX_LINE]; char *s; cdoInitialize(argument); processStartTime(&s_utime, &s_stime); gl_streamID = streamOpenRead(cdoStreamName(0)->args); command_init(); /* Loop reading and executing lines until the user quits. */ while ( !Done ) { readcmd("cdo cmd> ", line, MAX_LINE); /* Remove leading and trailing whitespace from the line. Then, if there is anything left, add it to the history list and execute it. */ s = stripwhite(line); if ( *s ) execute_line(s); } /* while ( readline(stdin, line, MAX_LINE) ) { linep = line; if ( strcmp(linep, "exit") == 0 ) break; else if ( strcmp(linep, "vars") == 0 ) { int varID; int nvars = vlistNvars(gl_vlistID); for ( varID = 0; varID < nvars; ++nvars ) { fprintf(stdout,"varID %d\n", varID); } } } */ streamClose(gl_streamID); if ( gl_data ) free(gl_data); if ( all_vars ) free(all_vars); cdoProcessTime(&e_utime, &e_stime); c_usertime = e_utime - s_utime; c_systime = e_stime - s_stime; c_cputime = c_usertime + c_systime; s_utime = e_utime; s_stime = e_stime; cdoPrint("%.2fs %.2fs %.2fs", c_usertime, c_systime, c_cputime); cdoFinish(); return (0); }
int main(int argc,char** argv) { struct termios tio; struct termios stdio; int tty_fd; FILE *file; fd_set rdset; char cmd[100]; char buf[100]; int s, c; socklen_t addr_len; struct sockaddr_in addr; if(argc < 3){ printf("usage: %s device [read|write file|cal|home|clear|start|lbl num|D mot1 mot2 mot3 mot4 mot5 mot6]\r\n",argv[0]); exit(EXIT_FAILURE); } memset(&tio,0,sizeof(tio)); tio.c_iflag=0; tio.c_oflag=0; tio.c_cflag=CS8|CREAD|CLOCAL|CSTOPB;//8n2 tio.c_lflag=0; tio.c_cc[VMIN]=1; tio.c_cc[VTIME]=5; tty_fd=open(argv[1], O_RDWR | O_NONBLOCK); if(tty_fd == -1){ printf("cannot open device\r\n"); exit(EXIT_FAILURE); } cfsetospeed(&tio,B4800); cfsetispeed(&tio,B4800); tcsetattr(tty_fd,TCSANOW,&tio); if(strcmp(argv[2],"read") == 0){ writecmd("C",tty_fd);//set program counter to 0 while(cmd[0] != '*'){ readcmd(cmd,tty_fd); if(cmd[0] != '*'){ printf("%s",cmd); } } } else if(strcmp(argv[2],"cal") == 0){ writecmd("N",tty_fd); } else if(strcmp(argv[2],"home") == 0){ writecmd("H",tty_fd); } else if(strcmp(argv[2],"clear") == 0){ writecmd("R",tty_fd); } else if(strcmp(argv[2],"start") == 0){ writecmd("C",tty_fd);//set program counter to 0 writecmd("E",tty_fd);//start } else if(argv[2][0] == 'D' && argc == 9){ strcpy(cmd,"D "); strcat(cmd,argv[3]); strcat(cmd," "); strcat(cmd,argv[4]); strcat(cmd," "); strcat(cmd,argv[5]); strcat(cmd," "); strcat(cmd,argv[6]); strcat(cmd," "); strcat(cmd,argv[7]); strcat(cmd," "); strcat(cmd,argv[8]); writecmd(cmd,tty_fd);//send command } else if(strcmp(argv[2],"write") == 0 && argc == 4){ file = fopen(argv[3],"r"); if(!file){ printf("cannot open file\r\n"); exit(EXIT_FAILURE); } writecmd("R",tty_fd);//clear writecmd("C",tty_fd);//set program counter to 0 while (fgets(buf, 50, file)){ strcpy(cmd,"S"); strcat(cmd,buf); writecmd(cmd,tty_fd); } fclose(file); } else if(strcmp(argv[2],"lbl") == 0 && argc == 4){ strcpy(cmd,"E "); strcat(cmd,argv[3]); writecmd(cmd,tty_fd);//start } else if(strcmp(argv[2],"-d") == 0){ printf("Starting Server...\n"); s = socket(PF_INET, SOCK_STREAM, 0); if (s == -1){ perror("socket() failed"); return 1; } addr.sin_addr.s_addr = INADDR_ANY; addr.sin_port = htons(PORT); addr.sin_family = AF_INET; if (bind(s, (struct sockaddr*)&addr, sizeof(addr)) == -1){ perror("bind() failed"); return 2; } if (listen(s, 3) == -1){ perror("listen() failed"); return 3; } printf("Listening...\n"); for(;;){ addr_len = sizeof(addr); c = accept(s, (struct sockaddr*)&addr, &addr_len); if (c == -1){ perror("accept() failed"); continue; } printf("Client %s connected\n", inet_ntoa(addr.sin_addr)); handle_client(c,tty_fd); printf("Client %s quit\n", inet_ntoa(addr.sin_addr)); close(c); } } close(tty_fd); exit(EXIT_SUCCESS); }
} /* start rtk server ----------------------------------------------------------*/ static int startsvr(vt_t *vt) { double pos[3],npos[3]; char s[3][MAXRCVCMD]={"","",""},*cmds[]={NULL,NULL,NULL}; char *ropts[]={"","",""}; char *paths[]={ strpath[0],strpath[1],strpath[2],strpath[3],strpath[4],strpath[5], strpath[6],strpath[7] }; int i,ret,stropt[8]={0}; trace(3,"startsvr:\n"); /* read start commads from command files */ for (i=0;i<3;i++) { if (!*rcvcmds[i]) continue; if (!readcmd(rcvcmds[i],s[i],0)) { printvt(vt,"no command file: %s\n",rcvcmds[i]); } else cmds[i]=s[i]; } /* confirm overwrite */ for (i=3;i<8;i++) { if (strtype[i]==STR_FILE&&!confwrite(vt,strpath[i])) return 0; } if (prcopt.refpos==4) { /* rtcm */ for (i=0;i<3;i++) prcopt.rb[i]=0.0; } pos[0]=nmeapos[0]*D2R; pos[1]=nmeapos[1]*D2R; pos[2]=0.0; pos2ecef(pos,npos); /* read antenna file */ readant(vt,&prcopt,&svr.nav); /* open geoid data file */ if (solopt[0].geoid>0&&!opengeoid(solopt[0].geoid,filopt.geoid)) { trace(2,"geoid data open error: %s\n",filopt.geoid); printvt(vt,"geoid data open error: %s\n",filopt.geoid); } for (i=0;*rcvopts[i].name;i++) modflgr[i]=0; for (i=0;*sysopts[i].name;i++) modflgs[i]=0; /* set stream options */ stropt[0]=timeout; stropt[1]=reconnect; stropt[2]=1000; stropt[3]=buffsize; stropt[4]=fswapmargin; strsetopt(stropt); if (strfmt[2]==8) strfmt[2]=STRFMT_SP3; /* set ftp/http directory and proxy */ strsetdir(filopt.tempdir); strsetproxy(proxyaddr); /* execute start command */ if (*startcmd&&(ret=system(startcmd))) { trace(2,"command exec error: %s (%d)\n",startcmd,ret); printvt(vt,"command exec error: %s (%d)\n",startcmd,ret); } solopt[0].posf=strfmt[3]; solopt[1].posf=strfmt[4]; /* start rtk server */ if (!rtksvrstart(&svr,svrcycle,buffsize,strtype,paths,strfmt,navmsgsel, cmds,ropts,nmeacycle,nmeareq,npos,&prcopt,solopt,&moni)) { trace(2,"rtk server start error\n"); printvt(vt,"rtk server start error\n"); return 0; }
/* str2str -------------------------------------------------------------------*/ int main(int argc, char **argv) { static char cmd[MAXRCVCMD]=""; const char ss[]={'E','-','W','C','C'}; strconv_t *conv[MAXSTR]={NULL}; double pos[3],stapos[3]={0}; char *paths[MAXSTR],s[MAXSTR][MAXSTRPATH]={{0}},*cmdfile=""; char *local="",*proxy="",*msg="1004,1019",*opt="",buff[256],*p; char strmsg[MAXSTRMSG]=""; int i,n=0,dispint=5000,trlevel=0,opts[]={10000,10000,2000,32768,10,0,30}; int types[MAXSTR]={0},stat[MAXSTR]={0},byte[MAXSTR]={0},bps[MAXSTR]={0}; int fmts[MAXSTR],sta=0; for (i=0;i<MAXSTR;i++) paths[i]=s[i]; for (i=1;i<argc;i++) { if (!strcmp(argv[i],"-in")&&i+1<argc) { if (!decodepath(argv[++i],types,paths[0],fmts)) return -1; } else if (!strcmp(argv[i],"-out")&&i+1<argc&&n<MAXSTR-1) { if (!decodepath(argv[++i],types+n+1,paths[n+1],fmts+n+1)) return -1; n++; } else if (!strcmp(argv[i],"-p")&&i+3<argc) { pos[0]=atof(argv[++i])*D2R; pos[1]=atof(argv[++i])*D2R; pos[2]=atof(argv[++i]); pos2ecef(pos,stapos); } else if (!strcmp(argv[i],"-msg")&&i+1<argc) msg=argv[++i]; else if (!strcmp(argv[i],"-opt")&&i+1<argc) opt=argv[++i]; else if (!strcmp(argv[i],"-sta")&&i+1<argc) sta=atoi(argv[++i]); else if (!strcmp(argv[i],"-d" )&&i+1<argc) dispint=atoi(argv[++i]); else if (!strcmp(argv[i],"-s" )&&i+1<argc) opts[0]=atoi(argv[++i]); else if (!strcmp(argv[i],"-r" )&&i+1<argc) opts[1]=atoi(argv[++i]); else if (!strcmp(argv[i],"-n" )&&i+1<argc) opts[5]=atoi(argv[++i]); else if (!strcmp(argv[i],"-f" )&&i+1<argc) opts[6]=atoi(argv[++i]); else if (!strcmp(argv[i],"-c" )&&i+1<argc) cmdfile=argv[++i]; else if (!strcmp(argv[i],"-l" )&&i+1<argc) local=argv[++i]; else if (!strcmp(argv[i],"-x" )&&i+1<argc) proxy=argv[++i]; else if (!strcmp(argv[i],"-t" )&&i+1<argc) trlevel=atoi(argv[++i]); else if (*argv[i]=='-') printhelp(); } if (!*paths[0]) { fprintf(stderr,"specify input stream\n"); return -1; } if (n<=0) { fprintf(stderr,"specify output stream(s)\n"); return -1; } for (i=0;i<n;i++) { if (fmts[i+1]<0) continue; if (fmts[i+1]!=STRFMT_RTCM3) { fprintf(stderr,"unsupported output format\n"); return -1; } if (fmts[0]<0) { fprintf(stderr,"specify input format\n"); return -1; } if (!(conv[i]=strconvnew(fmts[0],fmts[i+1],msg,sta,sta!=0,opt))) { fprintf(stderr,"stream conversion error\n"); return -1; } } signal(SIGTERM,sigfunc); signal(SIGINT ,sigfunc); signal(SIGHUP ,SIG_IGN); signal(SIGPIPE,SIG_IGN); strsvrinit(&strsvr,n+1); if (trlevel>0) { traceopen(TRFILE); tracelevel(trlevel); } fprintf(stderr,"stream server start\n"); strsetdir(local); strsetproxy(proxy); if (*cmdfile) readcmd(cmdfile,cmd,0); /* start stream server */ if (!strsvrstart(&strsvr,opts,types,paths,conv,*cmd?cmd:NULL,stapos)) { fprintf(stderr,"stream server start error\n"); return -1; } for (intrflg=0;!intrflg;) { /* get stream server status */ strsvrstat(&strsvr,stat,byte,bps,strmsg); /* show stream server status */ for (i=0,p=buff;i<MAXSTR;i++) p+=sprintf(p,"%c",ss[stat[i]+1]); fprintf(stderr,"%s [%s] %10d B %7d bps %s\n", time_str(utc2gpst(timeget()),0),buff,byte[0],bps[0],strmsg); sleepms(dispint); } if (*cmdfile) readcmd(cmdfile,cmd,1); /* stop stream server */ strsvrstop(&strsvr,*cmd?cmd:NULL); for (i=0;i<n;i++) { strconvfree(conv[i]); } if (trlevel>0) { traceclose(); } fprintf(stderr,"stream server stop\n"); return 0; }
int main() { int i; char* argv[8]; int argc; printf_register(serial_putchar); printf("waiting..."); // Wait a short while for(i = 0; i < 10000; ++i) asm volatile ("nop"); printf("configuring..."); i2c_init(); argv[0] = "1"; argc = 1; doConfig(argv, argc); printf("done.\n"); while (1) { printf("\n> "); argc = readcmd(argv, 8); printf("\r\n> "); if(argc > 0) { switch(argv[0][0]) { case 'S': doSet(argv, argc); break; case 'G': doGet(argv, argc); break; case 'R': doResult(argv, argc); break; case 'W': doWrite(argv, argc); break; case 'X': doRead(argv, argc); break; case 'Z': doStatus(argv, argc); break; case 'I': switch(argv[0][1]) { case 'I': i2c_init(); break; case 'W': doI2CWrite(argv, argc); break; case 'R': doI2CRead(argv, argc); break; case 'C': doConfig(argv, argc); break; } break; } } } }
int sysbef (char *befbuf) //************************************************************************* // //************************************************************************* { static char shutdown_reason[23]; char xbuf[20]; static char *beftab[] = { "CONNECT", "LOGIN", "CALL", "OSHELL", #ifdef __DOS16__ #ifdef _TNC "TNC", #endif "W2", "UWIN", "TWIN", #ifdef _AUTOTRCWIN "TRWIN", #endif #endif "RTEXT", "CAT", "RPRG", "WTEXT", "WPRG", "RBIN", "WBIN", "SLR", "CLOG", "REORG", "LIFETIME", "MKBOARD", "RMBOARD", "MVBOARD", "SHUTDOWN", "NEW", "KILL", "TEST", "IMPORT", "DISABLE", "ENABLE", #ifdef DIEBOX_UIMPORT "UIMPORT", #endif #ifdef OLDMAILIMPORT "OLDMAILIMPORT", #endif "SETUSER", "BEACON", "GREP", "TGREP", "TAIL", "BEGIN", "BATCH", "EXPORT", "PWGEN", "POSTFWD", "MONITOR", "NOTE", "MACRO", "CFGFLEX", "ORM", "OMV", "OCP", "OMD", "APPEND", #ifdef DF3VI_EXTRACT "EXTRACT", #endif "HOLD", "SETPW", #ifdef FEATURE_YAPP "WYAPP", "RYAPP", #endif #ifdef FEATURE_DIDADIT "WDIDADIT", "RDIDADIT", #endif #if defined FEATURE_SERIAL || defined _TELEPHONE "TTYINIT", #endif #ifdef _TELEPHONE // JJ "TTYCMD", "TTYDIAL", "TTYHANGUP", "TTYSTATUS", "TTYWIN", "TTYCOUNTERRESET", #endif #ifdef _AUTOFWD "AFWDLIST", #endif #ifdef FEATURE_MDPW "MD2SUM", "MD5SUM", #endif #ifdef FEATURE_EDITOR "EDIT", "FEDIT", "REDIT", #else #ifdef DF3VI_FWD_EDIT "FEDIT", "FWDEDIT", #endif #ifdef DF3VI_REJ_EDIT "REDIT", "REJECTEDIT", #endif #ifdef DF3VI_CONV_EDIT "CEDIT", "CONVEDIT", #endif #endif #ifdef _FILEFWD "FWDIMPORT", "FWDEXPORT", #endif "YMBTEST", "SCMDLIST", // Dies ist immer das letzte Kommando! NULL }; enum befnum { unsinn, connect_, login, call_, oshell_, #ifdef __DOS16__ #ifdef _TNC tnc, #endif w2, uwin, twin, #ifdef _AUTOTRCWIN trwin, #endif #endif rtext, rtext_, rprg, wtext, wprg, rbin, wbin, slr, clog, reorg, life_, mkb, rmb, mvb, shutdown_, new_, kill_, test, import, disable_, enable_, #ifdef DIEBOX_UIMPORT uimport_, #endif #ifdef OLDMAILIMPORT oldmailimport_, #endif setuser, beacon, grep_, tgrep, tail, begin, batch, export_, pwgen, postfwd_, monitor_, note, macro, cfgflex_, orm, omv, ocp, omd, _append, #ifdef DF3VI_EXTRACT extract_, #endif hold, setpw, #ifdef FEATURE_YAPP wyapp, ryapp, #endif #ifdef FEATURE_DIDADIT wdidadit, rdidadit, #endif #if defined FEATURE_SERIAL || defined _TELEPHONE ttyinit, #endif #ifdef _TELEPHONE // JJ ttycmd, ttydial, ttyhangup, ttystatus, ttywin_, ttycounterreset, #endif #ifdef _AUTOFWD afwdlist_, #endif #ifdef FEATURE_MDPW md2sum, md5sum, #endif #ifdef FEATURE_EDITOR edit, fedit, redit, #else #ifdef DF3VI_FWD_EDIT fedit, fwdedit, #endif #ifdef DF3VI_REJ_EDIT redit, rejectedit, #endif #ifdef DF3VI_CONV_EDIT cedit, convedit_, #endif #endif #ifdef _FILEFWD fwdimport, fwdexport, #endif ymbtest, scmdlist // Dies ist immer das letzte Kommando! } cmd = unsinn; befbuf += blkill(befbuf); cmd = (befnum) readcmd(beftab, &befbuf, 0); switch (cmd) { #ifdef FEATURE_YAPP case ryapp: #endif #ifdef FEATURE_DIDADIT case rdidadit: #endif #if defined(FEATURE_YAPP) || defined(FEATURE_DIDADIT) break; #endif default: if (u->lf != 6) putv(LF); leerzeile(); // Sends the number of CRs stored in "ALTER LF" } switch (cmd) { case unsinn: if ( mbinitbef(befbuf, 0) #ifdef _TELEPHONE // JJ || ttyinitbef(befbuf, 0) #endif ) { strcpy(xbuf, "^"); mbparsave(); #ifdef _TELEPHONE // JJ ttyparsave(); #endif strncpy(xbuf + 1, befbuf, 18); xbuf[19] = 0; subst1(xbuf, ' ', 0); subst1(xbuf, '=', 0); grep(MBINITNAME, xbuf, o_i); #ifdef _TELEPHONE // JJ grep(INITTTYNAME, xbuf, o_i); #endif return OK; } else return NO; case note: trace(replog, "note", "%s", befbuf); break; #ifdef DF3VI_EXTRACT case extract_: mbchange(befbuf, w_extract, 1); break; #endif case hold: mbchange(befbuf, w_hold, 1); break; case omv: { char f1[50], f2[50]; befbuf = nexttoken(befbuf, f1, 49); befbuf = nexttoken(befbuf, f2, 49); if (! *f1 || ! *f2 || xrename(f1, f2)) putf(ms(m_error)); else { putf(ms(m_moving)); putf(ms(m_nach), f1, f2); } break; } case ocp: { char f1[50], f2[50]; befbuf = nexttoken(befbuf, f1, 49); befbuf = nexttoken(befbuf, f2, 49); if (! *f1 || ! *f2 || filecopy(f1, f2)) putf(ms(m_error)); else { putf(ms(m_copying)); putf(ms(m_nach), f1, f2); } break; } case orm: { char f1[50]; befbuf = nexttoken(befbuf, f1, 49); if (! *f1 || xunlink(f1)) putf(ms(m_filecantdeleted), f1); else putf(ms(m_filedeleted), f1); break; } case omd: { char f1[50]; befbuf = nexttoken(befbuf, f1, 49); killbackslash(f1); if (! *f1 || xmkdir(f1)) putf(ms(m_directorycantcreated), f1); else putf(ms(m_directorycreated), f1); break; } case _append: { char textline[LINELEN+1]; befbuf = nexttoken(befbuf, textline, LINELEN); if (! *befbuf) { putf("Syntax: APPEND <textline> <filename>\n"); break; } FILE *f = s_fopen(befbuf, "sat"); if (f) { fprintf(f, "%s\n", textline); s_fclose(f); } else putf(ms(m_filenotfound), befbuf); } break; case macro: { mk_start(befbuf); } break; case setuser: { char call[CALLEN+1]; befbuf = nexttoken(befbuf, call, CALLEN+1); strupr(call); if (mbcallok(call) && *befbuf) { trace(report, "setuser", "%s", befbuf); { if (! mbalter(NULL, befbuf, call)) putf(ms(m_isunknown), call); b->msg_loadnum = 0; //reload msg loaduser(b->logincall, u, 1); } } else putf("Syntax: SETUSER <call> <option> <value>\n"); } break; case setpw: //automatisierte Passwort-Vergabe { char call[CALLEN+1]; char passwd[40]; int i, pwline = 0; FILE *upwf; befbuf = nexttoken(befbuf, call, CALLEN+1); strupr(call); pwline = atoi(befbuf); if (! mbcallok(call) || ! pwline) { putf("Syntax: SETPW <call> <number>\n"); break; } if (! loaduser(call, u, 0)) { putf(ms(m_isunknown), call); break; } upwf = s_fopen("userpw.bcm", "sr"); if (! upwf) { putf(ms(m_filenotfound), "userpw.bcm"); break; } for (i = 0; i < pwline && ! feof(upwf); i++) fgets(passwd, sizeof(passwd) - 1, upwf); s_fclose(upwf); if (i < pwline) { putf(ms(m_userpwlines), i - 1); break; } strcpy(u->password, passwd); saveuser(u); pwline = strlen(u->password); putf(ms(m_loginpw), pwtypestr(u->loginpwtype), pwtypestr(u->sfpwtype)); putf(" "); putf(ms(m_pwdlength), pwline); sprintf(passwd, "pw set to %i char", pwline); pwlog(call, b->logincall, passwd); b->msg_loadnum = 0; //reload msg loaduser(b->logincall, u, 1); } break; #ifdef DIEBOX_UIMPORT case uimport_: { putf(ms(m_dieboximport)); uimport(); } break; #endif #ifdef OLDMAILIMPORT case oldmailimport_: { scanoptions(befbuf); formoptions(); befbuf += blkill(befbuf); if (isdir(befbuf)) { putf(ms(m_omi_started), befbuf); putflush(); oldmailimport(befbuf); } else putf(ms(m_dirunknown), befbuf); } break; #endif case disable_: { putf(ms(m_boxdisabled)); m.disable = 1; mbparsave(); } break; case enable_: { putf(ms(m_boxenabled)); m.disable = 0; mbparsave(); } break; case test: { if (*befbuf == 'W') { while (1); } // for testing watchdog else if (*befbuf == 'S') { trace(fatal, "test", "abort"); } else if (*befbuf == 'V') { *(char *)0 = 1; } else mk_start(befbuf); } break; case batch: { runbatch(befbuf); } break; case rtext: case rtext_: { fileio_text fio; fio.usefile(befbuf); fio.tx(); putf("\032\n"); // CTRL-Z } break; case wtext: { fileio_text fio; fio.usefile(befbuf); fio.rx(); } break; case rbin: case rprg: { fileio_abin fio; fio.usefile(befbuf); fio.tx(); } break; case wbin: case wprg: { fileio_abin fio; fio.usefile(befbuf); fio.rx(); } break; #ifdef FEATURE_YAPP case ryapp: { fileio_yapp fio; fio.usefile(befbuf); fio.tx(); } break; case wyapp: { fileio_yapp fio; fio.usefile(befbuf); fio.rx(); } break; #endif // FEATURE_YAPP #ifdef FEATURE_DIDADIT case rdidadit: { fileio_dida fio; fio.usefile(befbuf); fio.tx(); } break; case wdidadit: { fileio_dida fio; if (! *befbuf) fio.usefile("dummy"); else { if (befbuf[strlen(befbuf) - 1] != '/') strcat(befbuf, "/"); strcat(befbuf, "dummy"); fio.usefile(befbuf); } fio.rx(); } break; #endif // FEATURE_DIDADIT case slr: { scanoptions(befbuf); putlog(TRACEPATH "/" SYSLOGRNAME, befbuf); } break; case clog: { scanoptions(befbuf); putlog(TRACEPATH "/" CMDLOGNAME, befbuf); } break; case tail: { scanoptions(befbuf); befbuf += blkill(befbuf); if (b->optplus&o_f && *befbuf) { int a; FILE *f = s_fopen(befbuf, "lrt"); if (f) { fseek(f, 0, SEEK_END); do { while ((a = fgetc(f)) != EOF) putv(a); wdelay(349); } while (! testabbruch()); s_fclose(f); } } else { fileio_text fio; fio.usefile(befbuf); fio.settail(-2000); fio.tx(); } } break; case begin: { fileio_text fio; fio.usefile(befbuf); fio.settail(2000); fio.tx(); } break; case monitor_: { if (*befbuf) { scanoptions(befbuf); b->continous = 1; monitor(atoi(befbuf), b->optplus); } else putf("Syntax: MONITOR [-iords] <task-id>\n"); } break; case tgrep: { char string[61]; char name[40]; scanoptions(befbuf); if (b->optminus & o_i) b->optplus |= o_i; //wenn nicht explizit "-i-", ist "-i" default b->usermail = 0; if (! *befbuf) { putf("Syntax: TGREP [pattern] <fwd-bbs>\n"); break; } befbuf = nexttoken(befbuf, string, 60); if (*befbuf) { sprintf(name, TRACEPATH "/t_%s.bcm", befbuf); grep(name, string, b->optplus); } else { sprintf(name, TRACEPATH "/t_%s.bcm", string); putlog(name, ""); } } break; case grep_: { char string[61]; scanoptions(befbuf); if (b->optminus & o_i) b->optplus |= o_i; //wenn nicht explizit "-i-", ist "-i" default b->usermail = 0; befbuf = nexttoken(befbuf, string, 60); grep(befbuf, string, b->optplus); } break; #ifdef _AUTOFWD case afwdlist_: { afwdlist(befbuf); } break; #endif case life_: { if (*befbuf) { strupr(befbuf); char *life = skip(befbuf); int board = finddir(befbuf, b->sysop); if (board > 0) { board -= 1; if (life && *life) { tree[board].lifetime_max = atoi(life); tree[board].lifetime_min = 1; if (tree[board].lifetime_max > 999) tree[board].lifetime_max = 999; if (tree[board].lifetime_max < 1) tree[board].lifetime_max = 1; char *life_min = skip(life); if (life_min && *life_min) { tree[board].lifetime_min = atoi(life_min); if (tree[board].lifetime_min > 999) tree[board].lifetime_min = 999; if (tree[board].lifetime_min < 1) tree[board].lifetime_min = 1; } mbtreesave(); } putf(ms(m_lifetimestat), b->boardfullname, tree[board].lifetime_max, tree[board].lifetime_min); } else putf(ms(m_notfound), befbuf); } else putf("Syntax: LIFETIME <board> <days_maximum> [<days_minimum>]\n" " (with 1 <= days_maximum/days_minimum <= 999)\n\n"); } break; #ifdef _TNC case tnc: { control_tnc(befbuf); } break; #endif case connect_: { termqso(befbuf); } break; case login: { if (mbcallok(befbuf)) { mblogin(befbuf, login_standard, b->uplink); cmdlog("login changed"); putf(ms(m_loginchanged)); } else putf("Syntax: LOGIN <new logincall>\n"); } break; case call_: { if (mbcallok(befbuf)) { mblogin(befbuf, login_silent, b->uplink); b->msg_loadnum--; //Sonst wird falsche Sprache benutzt cmdlog("call changed"); } else putf("Syntax: CALL <new logincall>\n"); } break; case oshell_: { if (t->input == io_file || t->output == io_file) oshell(befbuf, sh_noinput); else oshell(befbuf, m.dosinput ? sh_forceinput : sh_ifmultitask); } break; case reorg: { if (sema_test("purgereorg") == 1) putf(ms(m_purgeallstarted)); else { putf(ms(m_reorginvoked)); fork(P_BACK | P_MAIL, 0, mbreorg, befbuf); } } break; case postfwd_: { putf(ms(m_postfwdinvoked)); fork(P_BACK | P_MAIL, 0, postfwd, "Postfwd"); } break; #ifdef FEATURE_EDITOR case edit: { fork(P_WIND | P_KEYB, 0, editfile, befbuf); } break; case fedit: { fork(P_WIND | P_KEYB, 0, editfile, FWDLISTNAME); } break; case redit: { fork(P_WIND | P_KEYB, 0, editfile, REJECTNAME); } break; #else #ifdef DF3VI_FWD_EDIT case fedit: //wenn kein editor vorhanden remote-editor aufrufen case fwdedit: { fwdlistedit(befbuf); } break; #endif #ifdef DF3VI_REJ_EDIT case redit: case rejectedit: { rejectlistedit(befbuf); } break; #endif #ifdef DF3VI_CONV_EDIT case cedit: case convedit_: { convedit(befbuf); } break; #endif #endif case new_: { scanoptions(befbuf); mbinit(); initfwdlist(); #ifdef _AUTOFWD initafwdlist(); #endif if (! (b->optplus & o_q)) // skip statistics on "new -q" { b->optplus = o_s | o_f | o_c; putf(ms(m_hadrstat)); browse_hadr(""); } mbcvtload(); #ifdef RUNUTILS read_runfile(); #endif msg_dealloc(1); mk_read_jobs(); } break; case kill_: { if (atoi(befbuf)) { while (atoi(befbuf)) { if (! killtask(nextdez(&befbuf), 1)) putf(ms(m_cantkilltask)); } } else putf("Syntax: KILL <task-id>\n"); } break; #ifdef __DOS16__ case w2: { fork(P_WIND | P_KEYB|P_MAIL, 0, mbwin2, m.sysopcall); } break; case uwin: { fork(P_WIND | P_KEYB|P_MAIL, 0, userwin, "Users"); } break; case twin: { fork(P_WIND | P_MAIL, 0, taskwin, befbuf); } break; #ifdef _AUTOTRCWIN case trwin: { if (*befbuf) fork(P_WIND | P_MAIL, 0, trcwin, befbuf); else putf("Syntax: TRWIN [-iords] <task-id>\n"); } break; #endif #endif //__DOS16__ case mkb: { char mainboard[30]; char newboard[20]; char *slash; befbuf = nexttoken(befbuf, mainboard, 29); befbuf = nexttoken(befbuf, newboard, 19); slash = strchr(mainboard + 1, '/'); if (slash && (! *newboard)) { *slash = 0; strcpy(newboard, slash + 1); } if (! *newboard && *mainboard == '/') { strcpy(newboard, mainboard + 1); mainboard[1] = 0; } if (*mainboard && *newboard) { switch (mkboard(mainboard, newboard, 0)) { case 0: putf(ms(m_boardcreated)); break; case 1: putf(ms(m_mainboardnotfound)); break; case 2: putf(ms(m_toomanyboards)); break; case 3: putf(ms(m_boardnameexist)); break; case 4: putf(ms(m_invalidboardname)); break; } } else putf("Syntax: MKBOARD <mainboard> <subboard>\n"); } break; case rmb: { if (*befbuf) { subst1(befbuf, ' ', '/'); if (*befbuf == '/' && befbuf[1] == '/') befbuf++; switch (rmboard(befbuf)) { case 0: putf(ms(m_boardremoved)); break; case 1: putf(ms(m_boardnotfound)); break; case 2: putf(ms(m_boardnotempty)); break; } } else putf("Syntax: RMBOARD <mainboard> <subboard>\n"); } break; case mvb: { char oldboard[20]; char subboard[20]; char neuboard[20]; befbuf = nexttoken(befbuf, oldboard, 19); befbuf = nexttoken(befbuf, subboard, 19); befbuf = nexttoken(befbuf, neuboard, 19); if (*oldboard && *subboard && *neuboard) { switch (mvboard(oldboard, subboard, neuboard)) { case 0: putf(ms(m_boardmoved)); break; case 1: putf(ms(m_newboardnotfound)); break; case 2: putf(ms(m_toomanyboards)); break; case 4: putf(ms(m_oldboardnotfound)); break; } } else putf("Syntax: MVBOARD <oldboard> <subboard> <newboard>\n"); } break; case shutdown_: { scanoptions(befbuf); #ifdef __DOS16__ if (b->optplus & o_r) atexit((void(*)()) MK_FP(0xffff, 0x0000)); #endif runterfahren = 1; sprintf(shutdown_reason, "shutdown by %s", b->logincall); stopreason = shutdown_reason; } break; case cfgflex_: { if (*befbuf && file_isreg("cfgflex.bcm")) { putf(ms(m_flexstarted)); fork(P_BACK | P_MAIL, 0, cfgflex, befbuf); } else putf("Syntax: CFGFLEX <flexcall> (cfgflex.bcm must exist)\n"); } break; case import: { sysimport(befbuf); } break; case export_: { if (*befbuf) { if ((t->input != io_file || t->output == io_dummy) && t->output != io_file) { char fname[51]; scanoptions(befbuf); befbuf = nexttoken(befbuf, fname, 50); if (b->optplus & o_a) // neue Option -b fuer binaer { if (b->optplus & o_b) b->outputfile = s_fopen(fname, "sab"); else b->outputfile = s_fopen(fname, "sat"); } else { if (b->optplus & o_b) b->outputfile = s_fopen(fname, "swb"); else b->outputfile = s_fopen(fname, "swt"); } if (b->outputfile) { s_fsetopt(b->outputfile, 1); b->oldinput = t->input; b->oldoutput = t->output; t->input = io_dummy; t->output = io_file; b->continous = 1; if (b->optplus & o_u) b->sysop = 0; if (*befbuf) mailbef(befbuf, 0); b->sysop = 1; } else putf(ms(m_filenotopen), fname); } } else putf("Syntax: EXPORT <filename> <box-command>\n"); } break; case beacon: { if (*befbuf) { FILE *f = s_fopen(BEACONNAME, "srt"); unsigned int i = 0; char s[LINELEN+1]; if (f) { while (fgets(s, LINELEN, f)) { if (*s) { s[strlen(s) - 1] = 0; putbeacon_tnc(s, befbuf); i++; } } s_fclose(f); } putf(ms(m_beaconframes), i); } else { fork(P_BACK | P_MAIL, 0, sendmailbake, "Beacon"); putf(ms(m_beaconstarted)); } } break; case pwgen: { FILE *f; if (*befbuf && (f = s_fopen(befbuf, "swt")) != 0) { unsigned int i; int upw; upw = ! stricmp(befbuf, "userpw.bcm"); // file fuer setpw for (i = 0; i < 1620; i++) { char c = 0; while (! isalnum(c)) c = random_max('z'); fputc(c, f); //pw-file fuer setpw erzeugen (81 Zeilen mit je 20 Zeichen) if (upw && (i % 20) == 19) fputc(LF, f); } trace(report, "pwgen", "%s created", befbuf); s_fclose(f); } else //ohne Parameter immer userpw.bcm erzeugen if (! *befbuf && (f = s_fopen("userpw.bcm", "swt")) != 0) { unsigned int i; for (i = 0; i < 1620; i++) { char c = 0; while (! isalnum(c)) c = random_max('z'); fputc(c, f); //pw-file fuer setpw erzeugen (81 Zeilen mit je 20 Zeichen) if ((i % 20) == 19) fputc(LF, f); } trace(report, "pwgen", "userpw.bcm created"); s_fclose(f); } } break; case scmdlist: // DH3MB { unsigned int i = 0; while (beftab[i]) putf("(%02d) %s\n", ++i, beftab[i]); } break; #ifdef FEATURE_MDPW case md2sum: { if (! *befbuf) { putf("Syntax: MD2SUM <filename>\n"); break; } if (! file_isreg(befbuf)) putf(ms(m_filenotfound), befbuf); else { MD2 md2; md2.readfile(befbuf, 0L); md2.gethexdigest(b->line); putf("%s %s\n", b->line, befbuf); } } break; case md5sum: { if (! *befbuf) { putf("Syntax: MD5SUM <filename>\n"); break; } if (! file_isreg(befbuf)) putf(ms(m_filenotfound), befbuf); else { MD5 md5; md5.readfile(befbuf, 0L); md5.gethexdigest(b->line); putf("%s %s\n", b->line, befbuf); } } break; #endif #if defined FEATURE_SERIAL || defined _TELEPHONE case ttyinit: { if (eingelogt("getty", 0, 0)) putf(ms(m_ttyactive)); else init_tty(); } break; #endif #ifdef _TELEPHONE // JJ case ttycmd: { if (*befbuf) { if (m.ttydevice > 1) putf_tty("%s\r", befbuf); else putf(ms(m_nomodem)); } else putf("Syntax: TTYCMD <command>\n"); } break; case ttydial: { strupr(befbuf); char *nummer; char call[8]; nummer = nexttoken(befbuf, call, 8); if (*befbuf && mbcallok(call)) { if (m.ttydevice && (get_ufwd(call)[0] || isforwardpartner(call) >= 0)) { putf(ms(m_startphonefwd), call, nummer); sprintf(befbuf, "%s TTY %s", call, nummer); fork(P_BACK | P_MAIL, 0, fwdsend, befbuf); } else putf(ms(m_nottyactive)); } else putf("Syntax: TTYDIAL <call> <number>\n"); } break; case ttyhangup: { tty_hangup(); putf(ms(m_hangupmodem)); } break; case ttystatus: { tty_statustext(); putv(LF); } break; case ttywin_: { fork(P_WIND | P_MAIL, 0, tty_win, befbuf); } break; case ttycounterreset: { tty_counterreset(); putv(LF); } break; #endif #ifdef _FILEFWD case fwdimport: { if (*befbuf) fwd_import(befbuf); } break; case fwdexport: { if (*befbuf) fwd_export(befbuf); } break; #endif case ymbtest: { #ifdef _USERCOMP if (u->comp == 1) { /* char output[256] = { 0 }; char output2[256] = { 0 }; int i, il = 0; */ putf("//COMP 1\n\n"); putflush(); /* il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); // printf("il: %d strlen: %d\n",il,strlen(befbuf)); // printf("befbuf:\n-%s-\nOut:\n-%s-\n",befbuf,output); //putflush(); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); output[0] = '\0'; strcpy(befbuf, "dies ist noch ein laengerer text 2"); il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); output[0] = '\0'; strcpy(befbuf, "dies ist ein noch laengerer text 3"); il = comp_sp_stat_huff(befbuf, strlen(befbuf), output); for (i = 1; i < il ; i++) bputv(output[i]); putv(LF); putflush(); putf("\n"); il = decomp_sp_stat_huff(output, strlen(output), output2); printf("il: %d strlen: %d\n",il,strlen(output)); printf("Out2:\n-%s-\n",output2); */ /* #include "ahuf.h" // TOP-Huffman class AHUF; AHUF *ahuf; ahuf = new AHUF(); il = ahuf->Komprimieren(true, befbuf, output, strlen(befbuf) ); printf("il: %d strlen: %d\n",il,strlen(befbuf)); printf("befbuf:\n-%s-\nOut:\n-%s-\n",befbuf,output); putflush(); putf("%s",output); putflush(); putf("\n"); */ } #endif } break; } return OK;
void run() { XEvent ev; KeySym keysym; char buf[256]; char errbuf[256] = {"ERROR: "}; char *errmsg = NULL; /*struct timeval t1, t2;*/ struct config *c; XSync(dpy, False); while(!XNextEvent(dpy, &ev)) { if(ev.type == ButtonPress) { if(ev.xbutton.window == win && is_mapped) { XUnmapWindow(dpy, win); XFlush(dpy); is_mapped = False; } continue; } if(ev.type != KeyPress) continue; keysym = XkbKeycodeToKeysym(dpy, (KeyCode)ev.xkey.keycode, 0, 0); for(c=config; c; c=c->next) { if(c->key == keysym && CLEANMASK(c->mod) == CLEANMASK(ev.xkey.state)) { break; } } if(!c) continue; if(!is_mapped) { updategeom(); moveresizeclear(ww, wh); XMapRaised(dpy, win); /* Wait for window to be mapped */ while(1) { XMaskEvent(dpy, SubstructureNotifyMask, &ev); if ((ev.type == CreateNotify || ev.type == MapNotify) && ev.xcreatewindow.window == win) { break; } } is_mapped = True; } /* gettimeofday(&t1, NULL); */ readcmd(c->cmd, buf, sizeof buf, errbuf+7/*skip the 'ERROR: ' part of the buffer */, sizeof(errbuf)-7); /* gettimeofday(&t2, NULL); printf("cmd finished after %li ms\n", ((t2.tv_sec-t1.tv_sec)*1000) + ((t2.tv_usec-t1.tv_usec)/1000)); */ if(buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0'; if(errbuf[strlen(errbuf)-1] == '\n') errbuf[strlen(errbuf)-1] = '\0'; if(strlen(buf)) errmsg = NULL; else if(strlen(errbuf+7)) errmsg = errbuf; else errmsg = "ERROR: Command failed"; start_timer(); c->disp(c, errmsg ? errmsg : buf, errmsg ? True : False); XSync(dpy, False); } }
/* * Send file(s). */ void put(int argc, char *argv[]) { int fd; int n; char *cp, *targ; if (argc < 2) { strlcpy(line, "put ", sizeof(line)); printf("(file) "); readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin); if (makeargv()) return; argc = margc; argv = margv; } if (argc < 2) { putusage(argv[0]); return; } targ = argv[argc - 1]; if (strrchr(argv[argc - 1], ':')) { for (n = 1; n < argc - 1; n++) if (strchr(argv[n], ':')) { putusage(argv[0]); return; } cp = argv[argc - 1]; targ = strrchr(cp, ':'); *targ++ = 0; if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') { cp[strlen(cp) - 1] = '\0'; cp++; } setpeer(cp, NULL); } if (!connected) { printf("No target machine specified.\n"); return; } if (argc < 4) { cp = argc == 2 ? tail(targ) : argv[1]; fd = open(cp, O_RDONLY); if (fd < 0) { warn("open: %s", cp); return; } if (verbose) printf("putting %s to %s:%s [%s]\n", cp, hostname, targ, mode); sendfile(fd, targ, mode); return; } /* * this assumes the target is a directory on * on a remote unix system. hmmmm. */ for (n = 1; n < argc - 1; n++) { if (asprintf(&cp, "%s/%s", targ, tail(argv[n])) == -1) err(1, "asprintf"); fd = open(argv[n], O_RDONLY); if (fd < 0) { warn("open: %s", argv[n]); free(cp); continue; } if (verbose) printf("putting %s to %s:%s [%s]\n", argv[n], hostname, cp, mode); sendfile(fd, cp, mode); free(cp); } }
void wx::mbwxcmd (char *befbuf) //************************************************************************* // WX command interpreter //************************************************************************* { static char *beftab[] = {"ALL", "TEMPERATURE", "DRUCK", "PRESSURE", "WINDSPEED", "FEUCHTIGKEIT", "HUMIDITY", "DC4FS", "INFO", "LOOP", NULL}; enum befnum {unsinn, _all, temperatur, luftdruck, luftdruck_, wind, humidity, humidity_, dc4fs, info, _loop } cmd = unsinn; befbuf += blkill(befbuf); cmd = (befnum) readcmd(beftab, &befbuf, 0); switch(cmd) { case unsinn: show_wx(&m.wx, 1); break; case _all: if (befbuf[0]) { char oneline[80]; wxdata_t wxt; time_t t1 = atol(befbuf); //simple but works for _any_ date if (t1 && read_wx_data(oneline, t1) && orgdata(&wxt, oneline)) show_wx(&wxt, 2); else putf("No data available.\n"); } else show_wx(&m.wx, 2); break; case _loop: while (1) { show_wx(&m.wx, 1); putflush(); wdelay(2000); } case temperatur: show_diags(0, ad_time()); break; case wind: show_diags(1, ad_time()); break; case luftdruck: case luftdruck_: show_diags(2, ad_time()); break; case humidity: case humidity_: show_diags(3, ad_time()); break; case dc4fs: show_wx(&m.wx, 3); break; case info: readtext("wxinfo"); break; } }
int main() { struct jobs_ls *jobs = NULL; printf("Variante %d: %s\n", VARIANTE, VARIANTE_STRING); while (1) { struct cmdline *l; char *prompt = "ensishell>"; l = readcmd(prompt); /* If input stream closed, normal termination */ if (!l) { printf("exit\n"); exit(EXIT_SUCCESS); } if (l->err) { /* Syntax error, read another command */ printf("error: %s\n", l->err); continue; } /*print_cmd(l);*/ get_finish_jobs(&jobs); // execute command if (l->seq[0] != 0) { // jobs if (!strcmp(l->seq[0][0], "jobs")) { jobs_print(jobs); } // exit if (!strcmp(l->seq[0][0], "exit")) { printf("exit\n"); exit(EXIT_SUCCESS); } // other commands else { int nb_cmd; for(nb_cmd = 0; l->seq[nb_cmd] != 0; nb_cmd++) { ;} int last_pipe[2] = {0,1}; pid_t pid; for(int i = 0; i < nb_cmd; i++) { int crnt_pipe[2]; if (i < nb_cmd - 1) { pipe(crnt_pipe); } pid = fork(); if (!pid) { if ((l->in) && (i == 0)) { freopen(l->in, "r", stdin); } if ((l->out) && (i == nb_cmd -1)) { freopen(l->out, "w", stdout); } if (i < nb_cmd -1) { dup2(crnt_pipe[1], 1); close(crnt_pipe[0]); close(crnt_pipe[1]); } if (i > 0) { dup2(last_pipe[0], 0); close(last_pipe[1]); close(last_pipe[0]); close(crnt_pipe[1]); close(crnt_pipe[0]); } char **cmd = l->seq[i]; if (l->seq[i][1] != 0) { // expand jockers glob_t globbuf; int flags = GLOB_DOOFFS | GLOB_NOCHECK | GLOB_MARK | GLOB_BRACE | GLOB_TILDE; globbuf.gl_offs = 1; glob(l->seq[i][1], flags, NULL, &globbuf); for(int j = 2; l->seq[i][j] != 0; j++) { fprintf(stderr, "%s\n", l->seq[i][j]); glob(l->seq[i][j], flags | GLOB_APPEND, NULL, &globbuf); } globbuf.gl_pathv[0] = l->seq[i][0]; cmd = globbuf.gl_pathv; } int err; err = execvp(l->seq[i][0], cmd); fprintf(stderr, "error %d\n", err); exit(EXIT_FAILURE); } if (pid < 0) { perror("Cannot fork\n"); } if (i > 0) { close(last_pipe[1]); close(last_pipe[0]); } last_pipe[0] = crnt_pipe[0]; last_pipe[1] = crnt_pipe[1]; } if (nb_cmd > 1) { close(last_pipe[1]); close(last_pipe[0]); } father(l->seq[0], l->bg, &jobs, pid); } } } }
/* * Receive file(s). */ void get(int argc, char *argv[]) { int fd; int n; char *cp; char *src; if (argc < 2) { strlcpy(line, "get ", sizeof(line)); printf("(files) "); readcmd(&line[strlen(line)], LBUFLEN - strlen(line), stdin); if (makeargv()) return; argc = margc; argv = margv; } if (argc < 2) { getusage(argv[0]); return; } if (!connected) { for (n = 1; n < argc; n++) if (strrchr(argv[n], ':') == 0) { getusage(argv[0]); return; } } for (n = 1; n < argc; n++) { src = strrchr(argv[n], ':'); if (src == NULL) src = argv[n]; else { char *cp; *src++ = 0; cp = argv[n]; if (cp[0] == '[' && cp[strlen(cp) - 1] == ']') { cp[strlen(cp) - 1] = '\0'; cp++; } setpeer(cp, NULL); if (!connected) continue; } if (argc < 4) { cp = argc == 3 ? argv[2] : tail(src); fd = open(cp, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd < 0) { warn("create: %s", cp); return; } if (verbose) printf("getting from %s:%s to %s [%s]\n", hostname, src, cp, mode); recvfile(fd, src, mode); break; } cp = tail(src); /* new .. jdg */ fd = open(cp, O_CREAT | O_TRUNC | O_WRONLY, 0644); if (fd < 0) { warn("create: %s", cp); continue; } if (verbose) printf("getting from %s:%s to %s [%s]\n", hostname, src, cp, mode); recvfile(fd, src, mode); } }