int check_printer_status(){ struct stat buf; //printf("%s\n", printer); int r = stat(printer, &buf); if (r<0) { if (printer_ready != 0) { printf("Printer offline\n"); } printer_ready = 0; if (errno == ENOENT) { printf("Printer not detected\n"); } else { perror("stat"); return -1; } } else { if (printer_ready != 1) { printf("Printer online\n"); print_loop(printer, queue_dir); } printer_ready = 1; } return 0; }
/* ------------------------------------------------------------------ * Given a string to a file or path, first determines the full 'real' path. * * If the filename is a symlink, we resolve the link and call this function * again, with the from_link flag set. This is used in deciding which * parameter (filename or fullpath) to use when calling lstat, and in * determining whether it is necessary to check for loops in the directory * hierarchy. * * If the filename is actually a directory, (and is not already open), * explore_dir is called to take care of its entries. If the directory is * found within the visited_dir list, then we have found a loop, and the * directory is not explored. * * Otherwise, it's a regular ol' file and we just call read_file on it. * * list: Linked list of visited directories. Loops are detected * by comparing absolute pathnames. * filename: Name of entity being examined (directory or file). * fullpath: Buffer to hold the full pathname of a file. * dir_d: Maxmimum allowed depth of directory recursion to perform. * from_link: Flag denoting whether this function has been called from * a symbolic link or not. * ------------------------------------------------------------------ */ int process_entry(params *P, visited_dir *list, char *filename, char *path, int dir_d, int from_link) { struct stat statbuf; dev_t dev; ino_t ino; char *absolute_filename; int myerrno; if ((absolute_filename = malloc(path_size)) == NULL) { fprintf(stderr, "Malloc failed in process_entry.\n"); return -1; } pthread_mutex_lock(&chdir_mutex); chdir(path); if (lstat(filename, &statbuf) < 0) { myerrno = errno; pthread_mutex_unlock(&chdir_mutex); if (filename[0] == '/') { snprintf(absolute_filename,path_size, "%s", filename); } else { snprintf(absolute_filename,path_size, "%s/%s", path, filename); } if (!enabled(P, NO_SYMLINKS) || (myerrno != ELOOP)) print_file_error(P, myerrno, absolute_filename); free(absolute_filename); return 0; } if (realpath(filename, absolute_filename) == 0) { myerrno = errno; pthread_mutex_unlock(&chdir_mutex); if (filename[0] == '/') { snprintf(absolute_filename,path_size, "%s", filename); } else { snprintf(absolute_filename,path_size, "%s/%s", path, filename); } if (!enabled(P, NO_SYMLINKS) || (myerrno != ELOOP)) print_file_error(P, myerrno, absolute_filename); free(absolute_filename); return 0; } if ( S_ISLNK(statbuf.st_mode)) { /* symbolic link: could be either file or dir, so resolve & process */ if (!enabled(P, NO_SYMLINKS)) { if (lstat(absolute_filename, &statbuf) < 0) { myerrno = errno; pthread_mutex_unlock(&chdir_mutex); /*snprintf(absolute_filename,path_size, "%s/%s", path, filename);*/ print_file_error(P, myerrno, absolute_filename); free(absolute_filename); return 0; } } else { free(absolute_filename); return 0; } } pthread_mutex_unlock(&chdir_mutex); dev = statbuf.st_dev; ino = statbuf.st_ino; myerrno = 0; if (S_ISREG(statbuf.st_mode) || S_ISCHR(statbuf.st_mode)) { /* regular, readable file */ read_file(P, absolute_filename); inc_stat(P, t_infiles, 1); free(absolute_filename); } else if (!S_ISDIR(statbuf.st_mode)) { /* if not link, file, or dir, error (if appropriate) */ print_file_error(P, 0, absolute_filename); free(absolute_filename); return 0; } else if (S_ISDIR(statbuf.st_mode) && dir_d != 0) { /* directory, and dir_depth allows us to explore it */ if(have_visited(list, dev, ino)) { /* if loop found, print it, but don't explore */ inc_stat(P, t_dloops, 1); if (!enabled(P, QUIET_FILENAME)) { print_loop(P, filename, path, absolute_filename, list, dev, ino); } free(absolute_filename); } else { /* add a list node, explore the dir, then free the node */ handle_directory(P, list, absolute_filename, dev, ino, path, (dir_d - 1)); } } else if (S_ISDIR(statbuf.st_mode) && dir_d == 0) { inc_stat(P, t_dskips, 1); free(absolute_filename); } return 0; }
static int outputSeq() { int dev; SRC_NODE *node, *brnode; COMMON_NODE *comnode; FILE *fd; if (start_node == NULL) return(0); if (open_fds() < 1) return (0); node = start_node; while (node != NULL) { dev = node->device; if (dev < 1) dev = 1; fd = fds[dev]; if (fd == NULL) { node = node->dnext; continue; } comnode = (COMMON_NODE *) &node->node.common_node; switch (node->type) { case ACQUIRE: case SAMPLE: // sample case JFID: case FIDNODE: acquire(node); break; case DELAY: case INCDLY: // incdelay case VDELAY: // vdelay case VDLST: // vdelay_list break; case PULSE: case SMPUL: // simpulse, sim3pulse pulse(node); break; case SHPUL: case SHVPUL: case SMSHP: case APSHPUL: // apshaped_pulse, apshaped_decpulse,apshaped_dec2pulse case OFFSHP: // shapedpulselist, genRFShapedPulseWithOffset shapepulse(node); break; case GRPPULSE: // GroupPulse, TGroupPulse shapepulse(node); break; case SHACQ: // ShapedXmtNAcquire case SPACQ: // SweepNOffsetAcquire, SweepNAcquire acquire(node); break; case HLOOP: // starthardloop print_loop(node, 1); break; case ENDHP: print_loop(node, 0); break; case SLOOP: // loop case GLOOP: // gemini loop case MSLOOP: // msloop case PELOOP: // peloop case PELOOP2: // peloop2 case NWLOOP: // nwloop print_loop(node, 1); break; case ENDSP: // endloop case ENDSISLP: // endpeloop, endmsloop, endpeloop2 case NWLOOPEND: // endnwloop print_loop(node, 0); break; case STATUS: case SETST: break; case GRAD: case RGRAD: gradient(node, 0); break; case MGPUL: // magradpulse, vagradpulse, simgradpulse, oblique_gradpulse pulse(node); break; case MGRAD: // magradient, vagradient,simgradient gradient(node, 0); break; case OBLGRAD: // obl_gradient,oblique_gradient,pe_oblshapedgradient gradient(node, 0); break; case PEGRAD: // pe_gradient,pe2_gradient,phase_encode_gradient gradient(node, 1); break; case OBLSHGR: // obl_shapedgradient,obl_shaped3gradient,oblique_shapedgradient case SHGRAD: // shapedgradient,shaped2Dgradient,mashapedgradient shapepulse(node); break; case PEOBLG: // deprecated break; case PESHGR: // pe_shaped3gradient,pe3_shaped3gradient,pe2_shaped3gradient case SHVGRAD: // shapedvgradient case SHINCGRAD: // shapedincgradient,shaped_INC_gradient case PEOBLVG: shapepulse(node); break; case DPESHGR: // pe3_shaped3gradient_dual shapepulse(node); brnode = node->bnode; if (brnode != NULL) { brnode->xstime = node->xstime; brnode->xetime = node->xetime; brnode->ptime = node->ptime; shapepulse(brnode); } break; case PRGON: // obsprgon,decprgon,dec2prgon break; case XPRGON: break; case VPRGON: // obsprgonOffset,decprgonOffset break; case PRGMARK: case VPRGMARK: break; case VGRAD: // vgradient,Pvgradient,S_vgradient gradient(node, 0); break; case INCGRAD: // incgradient,Sincgradient,Wincgradient break; case ZGRAD: // zgradpulse pulse(node); break; case DEVON: // xmtron,rfon,decon, rfoff,decoff,xmtroff update_height(node); break; case VDEVON: update_height(node); break; case RFONOFF: update_height(node); break; case PWRF: case PWRM: case RLPWRF: case VRLPWRF: case RLPWRM: break; case DECLVL: // declvlon, declvloff break; case RLPWR: case DECPWR: case POWER: break; case OFFSET: // offset,ioffset,decoffset,obsoffset case POFFSET: // poffset_list,position_offset,position_offset_list break; case LOFFSET: break; case VFREQ: // vfreq case VOFFSET: // voffset break; case LKHLD: // lk_hold break; case LKSMP: // lk_sample break; case AMPBLK: // decblankon,obsunblank,decunblank,blankingon break; case SPINLK: // spinlock, decspinlock,genspinlock print_item(dev, ITEM, node->type, node->fname); if (comnode->vlabel[0] != NULL) print_item(dev, PATTERN, 0, comnode->vlabel[0]); print_size(dev, 1); // time, duration, cycles fprintf(fd, "%.3f %g %g 0 0 1\n", node->xstime,comnode->fval[0], (double)comnode->val[2] ); break; case XGATE: print_item(dev, ITEM, node->type, node->fname); print_size(dev, 1); fprintf(fd, "%.3f %g 0 0 0 1\n", node->xstime,comnode->fval[0]); break; case ROTORP: // rotorperiod case ROTORS: // rotorsync case BGSHIM: break; case SHSELECT: case GRADANG: break; case ROTATEANGLE: // rot_angle_list case EXECANGLE: // exe_grad_rotation break; case SETRCV: // setreceiver break; case SPHASE: // xmtrphase, dcplrphase, dcplr2phase, dcplr3phase break; case PSHIFT: // phaseshift break; case PHASE: // txphase, decphase break; case SPON: // sp1on, sp2on break; case RCVRON: // rcvron, recon, recoff, rcvroff break; case PRGOFF: // prg_dec_off,obsprgoff,decprgoff,dec2prgoff case XPRGOFF: break; case HDSHIMINIT: // hdwshiminit break; case ROTATE: // rotate, rotate_angle break; case DCPLON: break; case DCPLOFF: case XDEVON: break; case XTUNE: // set4Tune break; case XMACQ: // XmtNAcquire acquire(node); break; case ACQ1: // startacq break; case TRIGGER: // triggerSelect case SETGATE: // setMRIUserGates break; case RDBYTE: // readMRIUserByte read_MRIByte(node); break; case WRBYTE: // writeMRIUserByte write_MRIByte(node); break; case SETANGLE: // set_angle_list break; case ACTIVERCVR: // setactivercvrs break; case PARALLELSTART: break; case PARALLELEND: break; case XEND: break; case XDOCK: break; case PARALLELSYNC: break; case RLLOOP: // rlloop case KZLOOP: // kzloop print_loop(node, 1); break; case RLLOOPEND: // rlendloop case KZLOOPEND: // kzendloop print_loop(node, 0); break; default: // Wprintf("dps draw: unknown code %d \n", node->type); break; } node = node->dnext; } end_channels(); return (1); }
/* Walk through intermediate tree and generate code. */ void im_codegen (inst_t * head) { /* Handle threads */ static int thread_cnt = 0; if (bfthreads) { fprintf (bfout, "void *bf%d (void *x) {\n", thread_cnt); fprintf (bfout, " int ptri = %d;\n\n", thread_cnt); thread_cnt++; } indent = 1; int returned = 0; inst_t *inst = head; while (inst != NULL) { lineno = inst->lineno; if (inst->comment && pass_comments) { fprintf (bfout, "/*\n %s \n*/\n", inst->comment); } switch (inst->inst * !returned) { case IM_CINC: /* Cell increment */ print_incdec ('+', inst->src); break; case IM_CDEC: /* Cell decrement */ print_incdec ('-', inst->src); break; case IM_PRGHT: /* Move pointer right */ print_move ('>', inst->src); break; case IM_PLEFT: /* Move pointer left */ print_move ('<', inst->src); break; case IM_IN: /* Input */ print_input (); break; case IM_OUT: /* Output */ print_output (); break; case IM_CADD: /* Cell copy */ print_ccpy (inst->dst, inst->src); break; case IM_CCLR: /* Cell clear */ print_cclr (); break; } /* Select next instruction. First from loop, then from next, then from ret. */ if (inst->loop && !returned) { print_loop (); inst = inst->loop; returned = 0; indent++; } else if (inst->next) { inst = inst->next; returned = 0; } else if (inst->ret) { print_end (); inst = inst->ret; returned = 1; indent--; } else inst = NULL; } if (bfthreads) { fprintf (bfout, "\n"); fprintf (bfout, " pthread_exit (NULL);\n"); fprintf (bfout, "} /* thread %d */\n\n", thread_cnt - 1); } }
int main(int argc, const char * argv[]) { int fd, fq, kq, nev; struct kevent change; struct kevent event; int len; if (argc != 4) { fprintf(stderr, "usage: %s printer queue_dir trigger\n", argv[0]); return -1; } printer = strdup(argv[1]); queue_dir = strdup(argv[2]); trigger = strdup(argv[3]); len = snprintf(trigger_cmd, BUFLEN, "%s %s %s", trigger, printer, queue_dir); if (len >= BUFLEN - 1) { printf("Buffer too small\n"); return -1; } len = snprintf(queue_dir_new, BUFLEN, "%s/new", queue_dir); if (len >= BUFLEN - 1) { printf("Buffer too small\n"); return -1; } printer_ready = 0; kq = kqueue(); if (kq == -1) perror("kqueue"); fq = open_and_subscribe(&change, queue_dir_new); struct timespec timeout; timeout.tv_sec = 5; timeout.tv_nsec = 0; check_printer_status(); for (;;) { nev = kevent(kq, &change, 1, &event, 1, &timeout); if (nev == -1) perror("kevent"); if (nev == 0) { // timeout check_printer_status(); } else if (nev > 0) { if (event.fflags & NOTE_DELETE) { continue; } printf("Got event for %d\n", event.ident); if (printer_ready) { print_loop(printer, queue_dir, trigger); } } } close(kq); close(fq); close(fd); return EXIT_SUCCESS; }
void display( void ) { int i; /* * Clear window */ glClearColor( 1.0, 1.0, 1.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT ); /* * Set the viewWindow */ glMatrixMode( GL_PROJECTION ); glLoadIdentity( ); gluOrtho2D( 0, 300, 0, 300 ); /* * Set the viewport to match the viewWindow */ glViewport( 0, 0, 299, 299 ); /* * first polygon: entirely within region */ wl = 0; clipPolygon( 4, quad1x, quad1y, &wl, wx, wy, 10, 10, 50, 50 ); glColor3f( 1.0, 0.0, 0.0 ); /* red */ print_loop( 4, quad1x, quad1y ); print_poly( wl, wx, wy ); /* * second polygon: entirely outside region */ wl = 0; clipPolygon( 4, quad2x, quad2y, &wl, wx, wy, 10, 10, 50, 50 ); /* shouldn't draw anything! */ if( wl > 0 ) { glColor3f( 0.0, 1.0, 0.0 ); /* green */ print_loop( 4, quad2x, quad2y ); print_poly( wl, wx, wy ); } /* * third polygon: halfway outside on left */ wl = 0; clipPolygon( 4, quad3x, quad3y, &wl, wx, wy, 30, 10, 70, 80 ); glColor3f( 0.0, 0.0, 1.0 ); /* blue */ print_loop( 4, quad3x, quad3y ); print_poly( wl, wx, wy ); /* * fourth polygon: part outside on right */ wl = 0; clipPolygon( 4, quad4x, quad4y, &wl, wx, wy, 10, 10, 50, 50 ); glColor3f( 1.0, 0.0, 1.0 ); /* magenta */ print_loop( 4, quad4x, quad4y ); print_poly( wl, wx, wy ); /* * fifth polygon: enclosing */ wl = 0; clipPolygon( 5, pent1x, pent1y, &wl, wx, wy, 90, 20, 100, 30 ); glColor3f( 0.5, 0.5, 1.0 ); /* reddish-greenish-blue ? */ print_loop( 5, pent1x, pent1y ); print_poly( wl, wx, wy ); /* * sixth polygon: outside on left and bottom */ wl = 0; clipPolygon( 5, pent1x, pent1y, &wl, wx, wy, 90, 34, 120, 60 ); glColor3f( 1.0, 0.5, 1.0 ); /* red-greenish-blue ? */ print_loop( 5, pent1x, pent1y ); print_poly( wl, wx, wy ); /* * seventh polygon: outside on top, right, and bottom */ wl = 0; clipPolygon( 7, hept1x, hept1y, &wl, wx, wy, 90, 80, 130, 110 ); glColor3f( 0.0, 0.0, 0.0 ); /* black */ print_loop( 7, hept1x, hept1y ); print_poly( wl, wx, wy ); /* * Flushs OpenGL commands to display */ glFlush(); }