int dump(char *bfile) { FILE *fin, *fout; char buf[1025], xx[80], *filename, *dir; int locked = 0, size; fin = fopen(bfile, "r"); if (fin == NULL) return 1; locked = 1; while (fgets(buf, 1024, fin) != NULL) { if (buf[0] == '>' && buf[strlen(buf) - 3] == '<' && buf[strlen(buf) - 2] == '\37') { if (locked == 1) { locked = 2; getit(buf, &dir, &filename); sprintf(xx, "mkdir -p %s", dir); system(xx); sprintf(xx, "%s/%s", dir, filename); size = 0; fout = fopen(xx, "w"); } else { fclose(fout); #ifdef _DEBUG printf("%s dumped, size: %d bytes\n", filename, size); #endif locked = 2; getit(buf, &dir, &filename); sprintf(xx, "mkdir -p %s", dir); system(xx); sprintf(xx, "%s/%s", dir, filename); size = 0; fout = fopen(xx, "w"); } continue; } fputs(buf, fout); size += (int) strlen(buf); } fclose(fin); if (fout != NULL) { fclose(fout); #ifdef _DEBUG printf("%s dumped, size: %d bytes\n", filename, size); #endif } printf("all file dumped.\n"); }
Parse_stat parse(MCScriptPoint &p_sp) { Parse_stat t_stat; t_stat = PS_NORMAL; // Fetch a reference to 'it' getit(p_sp, m_it); // Parse the optional 'id' token m_is_id = (PS_NORMAL == p_sp . skip_token(SP_FACTOR, TT_PROPERTY, P_ID)); // Parse the id_or_name expression if (t_stat == PS_NORMAL) t_stat = p_sp . parseexp(False, True, &m_id_or_name); // Parse the 'relative to' tokens if (t_stat == PS_NORMAL) t_stat = p_sp . skip_token(SP_FACTOR, TT_TO, PT_RELATIVE); if (t_stat == PS_NORMAL) t_stat = p_sp . skip_token(SP_FACTOR, TT_TO, PT_TO); // Parse the target object clause if (t_stat == PS_NORMAL) { m_relative_object = new MCChunk(false); t_stat = m_relative_object -> parse(p_sp, False); } return t_stat; }
int list_princs(struct list_options *opt, int argc, char **argv) { if(sizeof(struct get_options) != sizeof(struct list_options)) { krb5_warnx(context, "programmer error: sizeof(struct get_options) != sizeof(struct list_options)"); return 0; } return getit((struct get_options*)opt, "list", argc, argv); }
/* * Wait "n" microseconds. * Relies on timer 1 counting down from (i8254_freq / hz) * Note: timer had better have been programmed before this is first used! */ void DELAY(int n) { int delta, prev_tick, tick, ticks_left; #ifdef DELAYDEBUG int getit_calls = 1; int n1; static int state = 0; if (state == 0) { state = 1; for (n1 = 1; n1 <= 10000000; n1 *= 10) DELAY(n1); state = 2; } if (state == 1) printf("DELAY(%d)...", n); #else if (delay_tc(n)) return; #endif /* * Read the counter first, so that the rest of the setup overhead is * counted. Guess the initial overhead is 20 usec (on most systems it * takes about 1.5 usec for each of the i/o's in getit(). The loop * takes about 6 usec on a 486/33 and 13 usec on a 386/20. The * multiplications and divisions to scale the count take a while). * * However, if ddb is active then use a fake counter since reading * the i8254 counter involves acquiring a lock. ddb must not do * locking for many reasons, but it calls here for at least atkbd * input. */ #ifdef KDB if (kdb_active) prev_tick = 1; else #endif prev_tick = getit(); n -= 0; /* XXX actually guess no initial overhead */ /* * Calculate (n * (i8254_freq / 1e6)) without using floating point * and without any avoidable overflows. */ if (n <= 0) ticks_left = 0; else if (n < 256) /* * Use fixed point to avoid a slow division by 1000000. * 39099 = 1193182 * 2^15 / 10^6 rounded to nearest. * 2^15 is the first power of 2 that gives exact results * for n between 0 and 256. */ ticks_left = ((u_int)n * 39099 + (1 << 15) - 1) >> 15; else
Parse_stat MCGet::parse(MCScriptPoint &sp) { initpoint(sp); if (sp.parseexp(False, True, &value) != PS_NORMAL) { MCperror->add (PE_GET_BADEXP, sp); return PS_ERROR; } getit(sp, it); return PS_NORMAL; }
// _internal extract x y from z Parse_stat MCIdeExtract::parse(MCScriptPoint& sp) { if (sp . parseexp(False, True, &m_segment_name) != PS_NORMAL) return PS_ERROR; if (sp . parseexp(False, True, &m_section_name) != PS_NORMAL) return PS_ERROR; if (sp . skip_token(SP_FACTOR, TT_FROM, PT_FROM) != PS_NORMAL) return PS_ERROR; if (sp . parseexp(False, True, &m_filename) != PS_NORMAL) return PS_ERROR; getit(sp, m_it); return PS_NORMAL; }
int list_princs(struct list_options *opt, int argc, char **argv) { struct get_options get_opt; if(sizeof(struct get_options) != sizeof(struct list_options)) { krb5_warnx(context, "programmer error: sizeof(struct get_options) != sizeof(struct list_options)"); return 0; } get_opt.long_flag = opt->long_flag; get_opt.short_flag = opt->short_flag; get_opt.terse_flag = opt->terse_flag; get_opt.column_info_string = opt->column_info_string; return getit(&get_opt, "list", argc, argv); }
Parse_stat MCConvert::parse(MCScriptPoint &sp) { initpoint(sp); MCerrorlock++; container = new MCChunk(True); MCScriptPoint tsp(sp); if (container->parse(sp, False) != PS_NORMAL) { sp = tsp; MCerrorlock--; delete container; container = NULL; if (sp.parseexp(False, True, &source) != PS_NORMAL) { MCperror->add (PE_CONVERT_NOCONTAINER, sp); return PS_ERROR; } getit(sp, it); } else MCerrorlock--; if (sp.skip_token(SP_FACTOR, TT_FROM) == PS_NORMAL) { if (parsedtformat(sp, fform, fsform) != PS_NORMAL) return PS_ERROR; } if (sp.skip_token(SP_FACTOR, TT_TO) != PS_NORMAL) { MCperror->add (PE_CONVERT_NOTO, sp); return PS_ERROR; } if (parsedtformat(sp, pform, sform) != PS_NORMAL) return PS_ERROR; return PS_NORMAL; }
int main (int argc, char const *const *argv) { PROG = "s6-clock" ; return (argc < 2) ? getit() : setit(argv[1]) ; }
/* * get file if modtime is more recent than current file */ void Connection::newer(int argc, char *argv[]) { PROC(("newer","%d [%s,%s,%s]",argc,(argc>=1)?argv[0]:"nil",(argc>=2)?argv[1]:"nil",(argc>=3)?argv[2]:"nil")); getit(argc, argv, -1, "w"); }
void Connection::get(int argc, char *argv[]) { PROC(("get","%d [%s,%s,%s]",argc,(argc>=1)?argv[0]:"nil",(argc>=2)?argv[1]:"nil",(argc>=3)?argv[2]:"nil")); getit(argc, argv, 0, restart_point ? "r+" : "w"); }
void test() { Point p; (void)(p = getit()).x; }
Parse_stat MCAnswer::parse(MCScriptPoint &sp) { Parse_errors t_error = PE_UNDEFINED; Symbol_type t_type; const LT *t_literal; initpoint(sp); getit(sp, it); if (sp . skip_token(SP_ASK, TT_UNDEFINED, AT_PAGE) == PS_NORMAL) { if (sp . skip_token(SP_ASK, TT_UNDEFINED, AT_SETUP) == PS_NORMAL) mode = AT_PAGESETUP; else t_error = PE_ANSWER_BADQUESTION; } else if (sp . next(t_type) == PS_NORMAL) { if (sp . lookup(SP_ASK, t_literal) == PS_NORMAL) mode = (Ask_type)t_literal -> which; else sp . backup(); } if (t_error == PE_UNDEFINED) switch(mode) { case AT_PAGESETUP: // MJ: adding support for "answer pagesetup" syntax, following existing code t_error = parse_pagesetup(sp); break; case AT_PRINTER: t_error = parse_printer(sp); break; case AT_EFFECT: t_error = parse_effect(sp); break; case AT_RECORD: t_error = parse_record(sp); break; case AT_COLOR: t_error = parse_colour(sp); break; case AT_FILE: case AT_FILES: t_error = parse_file(sp); break; case AT_FOLDER: case AT_FOLDERS: t_error = parse_folder(sp); break; default: t_error = parse_notify(sp); break; } if (t_error == PE_UNDEFINED && sp . skip_token(SP_ASK, TT_UNDEFINED, AT_TITLED) == PS_NORMAL) if (sp . parseexp(False, True, &title) != PS_NORMAL) t_error = PE_ANSWER_BADTITLE; if (t_error == PE_UNDEFINED && sp . skip_token(SP_FACTOR, TT_PREP, PT_AS) == PS_NORMAL) if (sp . skip_token(SP_ASK, TT_UNDEFINED, AT_SHEET) == PS_NORMAL) sheet = True; else t_error = PE_ANSWER_BADRESPONSE; if (t_error != PE_UNDEFINED) { MCperror -> add(t_error, sp); return PS_ERROR; } return PS_NORMAL; }
int get_entry(struct get_options *opt, int argc, char **argv) { return getit(opt, "get", argc, argv); }
void Connection::reget(int argc, char *argv[]) { PROC(("reget","%d [%s,%s,%s]",argc,(argc>=1)?argv[0]:"nil",(argc>=2)?argv[1]:"nil",(argc>=3)?argv[2]:"nil")); getit(argc, argv, 1, "a+"); }
// Find the device, and set up to read it periodically, then send // the data out stdout so another process can pick it up and do // something reasonable with it. // int main(int argc, char **argv) { char *usage = {"usage: %s -u -n\n"}; int libusbDebug = 0; //This will turn on the DEBUG for libusb int noisy = 0; //This will print the packets as they come in libusb_device **devs; int r, err, c; ssize_t cnt; while ((c = getopt (argc, argv, "unh")) != -1) switch (c){ case 'u': libusbDebug = 1; break; case 'n': noisy = 1; break; case 'h': fprintf(stderr, usage, argv[0]); case '?': exit(1); default: exit(1); } fprintf(stderr,"%s Starting ... ",argv[0]); fprintf(stderr,"libusbDebug = %d, noisy = %d\n", libusbDebug, noisy); // The Pi linker can give you fits. If you get a linker error on // the next line, set LD_LIBRARY_PATH to /usr/local/lib fprintf(stderr,"This is not an error!! Checking linker, %s\n", libusb_strerror(0)); if (signal(SIGINT, sig_handler) == SIG_ERR) fprintf(stderr,"Couldn't set up signal handler\n"); err = libusb_init(NULL); if (err < 0){ fprintf(stderr,"Couldn't init usblib, %s\n", libusb_strerror(err)); exit(1); } // This is where you can get debug output from libusb. // just set it to LIBUSB_LOG_LEVEL_DEBUG if (libusbDebug) libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_DEBUG); else libusb_set_debug(NULL, LIBUSB_LOG_LEVEL_INFO); cnt = libusb_get_device_list(NULL, &devs); if (cnt < 0){ fprintf(stderr,"Couldn't get device list, %s\n", libusb_strerror(err)); exit(1); } // go get the device; the device handle is saved in weatherStation struct. if (!findDevice(devs)){ fprintf(stderr,"Couldn't find the device\n"); exit(1); } // Now I've found the weather station and can start to try stuff // So, I'll get the device descriptor struct libusb_device_descriptor deviceDesc; err = libusb_get_device_descriptor(weatherStation.device, &deviceDesc); if (err){ fprintf(stderr,"Couldn't get device descriptor, %s\n", libusb_strerror(err)); exit(1); } fprintf(stderr,"got the device descriptor back\n"); // Open the device and save the handle in the weatherStation struct err = libusb_open(weatherStation.device, &weatherStation.handle); if (err){ fprintf(stderr,"Open failed, %s\n", libusb_strerror(err)); closeUpAndLeave(); } fprintf(stderr,"I was able to open it\n"); // Now that it's opened, I can free the list of all devices libusb_free_device_list(devs, 1); // Documentation says to get rid of the list // Once I have the device I need fprintf(stderr,"Released the device list\n"); err = libusb_set_auto_detach_kernel_driver(weatherStation.handle, 1); if(err){ fprintf(stderr,"Some problem with detach %s\n", libusb_strerror(err)); closeUpAndLeave(); } int activeConfig; err =libusb_get_configuration(weatherStation.handle, &activeConfig); if (err){ fprintf(stderr,"Can't get current active configuration, %s\n", libusb_strerror(err));; closeUpAndLeave(); } fprintf(stderr,"Currently active configuration is %d\n", activeConfig); if(activeConfig != 1){ err = libusb_set_configuration (weatherStation.handle, 1); if (err){ fprintf(stderr,"Cannot set configuration, %s\n", libusb_strerror(err));; closeUpAndLeave(); } fprintf(stderr,"Just did the set configuration\n"); } err = libusb_claim_interface(weatherStation.handle, 0); //claim interface 0 (the first) of device (mine had just 1) if(err) { fprintf(stderr,"Cannot claim interface, %s\n", libusb_strerror(err)); closeUpAndLeave(); } fprintf(stderr,"Claimed Interface\n"); // I don't want to just hang up and read the reports as fast as I can, so // I'll space them out a bit. It's weather, and it doesn't change very fast. sleep(1); fprintf(stderr,"Setting the device 'idle' before starting reads\n"); err = libusb_control_transfer(weatherStation.handle, 0x21, 0x0a, 0, 0, 0, 0, 1000); sleep(1); int tickcounter= 0; fprintf(stderr,"Starting reads\n"); while(1){ sleep(1); if(tickcounter++ % 10 == 0){ getit(1, noisy); } if(tickcounter % 30 == 0){ getit(2, noisy); } if (tickcounter % 15 == 0){ showit(); } } }
Parse_stat MCAsk::parse(MCScriptPoint &sp) { Parse_errors t_error = PE_UNDEFINED; Symbol_type t_type; const LT *t_literal; initpoint(sp); getit(sp, it); if (sp . next(t_type) == PS_NORMAL) if (sp . lookup(SP_ASK, t_literal) == PS_NORMAL) mode = (Ask_type)t_literal -> which; else sp . backup(); // MW-2008-07-23: [[ Bug 6821 ]] ask files "foo" crashes. // This is because the mode check is not strict enough. If the given ask // mode is not known, we backup and then parse it as a question form. switch(mode) { case AT_PASSWORD: t_error = parse_password(sp); break; case AT_FILE: t_error = parse_file(sp); break; case AT_INFORMATION: case AT_QUESTION: case AT_ERROR: case AT_WARNING: case AT_UNDEFINED: t_error = parse_question(sp); break; default: sp . backup(); t_error = parse_question(sp); break; } if (t_error == PE_UNDEFINED && sp . skip_token(SP_ASK, TT_UNDEFINED, AT_TITLED) == PS_NORMAL) if (sp . parseexp(False, True, &title) != PS_NORMAL) t_error = PE_ANSWER_BADTITLE; if (t_error == PE_UNDEFINED && sp . skip_token(SP_FACTOR, TT_PREP, PT_AS) == PS_NORMAL) if (sp . skip_token(SP_ASK, TT_UNDEFINED, AT_SHEET) == PS_NORMAL) sheet = True; else t_error = PE_ANSWER_BADRESPONSE; if (t_error != PE_UNDEFINED) { MCperror -> add(t_error, sp); return PS_ERROR; } return PS_NORMAL; }