static int proc_args(int argc, char *argv[]) { unsigned short n, ass, n_timed; unsigned short *toogle; unsigned short argnr; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "scan", strlen("scan")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of kbd_test_scan() \n"); return 1; } if( (ass = parse_ushort(argv[2], 10)) == USHRT_MAX ) return 1; printf("timer: kbd_test_scan\n"); kbd_test_scan(ass); return 0; } else if (strncmp(argv[1], "leds", strlen("leds")) == 0) { argnr = (argc - 2); n = argnr; unsigned short * leds = (unsigned short *) malloc (n); unsigned short a = 2; unsigned short l = 0; for (; a<argc; a++, l++) { if (parse_ushort(argv[a], 10) > 2 || parse_ushort(argv[a], 10) < 0) { printf("error : non valid value for LEDS"); free(leds); return 1; } else leds[l] = parse_ushort(argv[a], 10); } printf("timer: kbs_test_leds\n"); kbd_test_leds(n, leds); free(leds); return 0; } else if (strncmp(argv[1], "timed_scan", strlen("timed_scan")) == 0) { if( argc != 3 ) { printf("timer: wrong no of arguments for test of timer_test_int() \n"); return 1; } if( (n_timed = parse_ushort(argv[2], 10)) == USHRT_MAX ) return 1; printf("timer: kbd_test_time_scan\n"); kbd_test_timed_scan(n_timed); return 0; } else { printf("timer: non valid function \"%s\" to test\n", argv[1]); return 1; } }
static int proc_args(int argc, char *argv[]) { unsigned short cnt, tolerance, i_time; short length = 0; /* check the function to test: if the first characters match, accept it */ if (strncmp(argv[1], "packet", strlen("packet")) == 0) { if( argc != 3 ) { printf("mouse: wrong no of arguments for test of test_packet() \n"); return 1; } if( (cnt = parse_ushort(argv[2], 10)) == USHRT_MAX ) return 1; printf("mouse: test_packet()\n"); test_packet(cnt); return 0; } else if (strncmp(argv[1], "async", strlen("async")) == 0) { if( argc != 3 ) { printf("mouse: wrong no of arguments for test of test_async() \n"); return 1; } if( (i_time = parse_ushort(argv[2], 10)) == USHRT_MAX ) return 1; printf("mouse: test_async()\n"); test_async(i_time); return 0; } else if (strncmp(argv[1], "config", strlen("config")) == 0) { if( argc != 2 ) { printf("mouse: wrong no of arguments for test of test_config() \n"); return 1; } printf("mouse: test_config\n"); test_config(); return 0; } else if (strncmp(argv[1], "gesture", strlen("gesture")) == 0) { if( argc != 4 ) { printf("mouse: wrong no of arguments for test of test_gesture() \n"); return 1; } length = parse_ushort(argv[2], 10); if( (tolerance = parse_ushort(argv[3], 10)) == USHRT_MAX ) return 1; printf("mouse: test_gesture()\n"); test_gesture(length, tolerance); return 0; } else { printf("mouse: non valid function \"%s\" to test\n", argv[1]); return 1; } }
static int proc_args(int argc, char *argv[]) { unsigned short base_addr; unsigned long bits, stop, parity, rate; unsigned char tx; int i, stringc = 1; char **strings; char *temp; /* check the function to test: if the first characters match, accept it */ if (argc == 1) { print_usage(argv); return 1; } else if (strncmp(argv[1], "conf", strlen("conf")) == 0) { if (argc != 3) { printf("VBE: wrong no of arguments for conf() \n"); return 1; } if ((base_addr = parse_ushort(argv[2], 16)) == USHRT_MAX) return 1; printf("lab7:: conf(%d)\n", base_addr); ser_test_conf(base_addr); return 0; } else if (strncmp(argv[1], "set", strlen("set")) == 0) { if (argc != 7) { printf("lab7: wrong no of arguments for set() \n"); return 1; } if ((base_addr = parse_ushort(argv[2], 10)) == USHRT_MAX) return 1; if ((bits = parse_ulong(argv[3], 10)) == ULONG_MAX) return 1; if ((stop = parse_ulong(argv[4], 10)) == ULONG_MAX) return 1; if(strncmp(argv[5],"even",strlen("even")) == 0) parity = 2; else if(strncmp(argv[5], "odd",strlen("odd")) == 0) parity = 1; else if(strncmp(argv[5],"none",strlen("none")) == 0) parity = 0; if((rate = parse_ulong(argv[6],10)) == ULONG_MAX) return 1; printf("lab7::set(%d, %d, %d, %d, %d)\n", base_addr, bits, stop, parity, rate); return ser_test_set(base_addr, bits, stop, parity, rate); } else if (strncmp(argv[1], "com", strlen("com")) == 0) { if (argc != 8) { printf("lab7::wrong num of args for com() \n"); return 1; } if (base_addr = parse_ushort(argv[2], 10) == USHRT_MAX) return 1; if ((tx = parse_uchar(argv[3],10)) == UCHAR_MAX) return 1; if((bits = parse_ulong(argv[4],10)) == ULONG_MAX) return 1; if((stop = parse_ulong(argv[5],10)) == ULONG_MAX) return 1; if((rate = parse_ulong(argv[7],10)) == ULONG_MAX) return 1; if(strncmp(argv[6],"even",strlen("even")) == 0) parity = 2; else if(strncmp(argv[6], "odd",strlen("odd")) == 0) parity = 1; else if(strncmp(argv[6],"none",strlen("none")) == 0) parity = 0; /*strings = (char **)malloc(0); for(i = 8; i < argc; i++){ strings = realloc(strings,stringc * sizeof(char*)); strings[stringc - 1] =(char *) malloc(sizeof(argv[i])); strings[stringc - 1] = argv[i]; printf("%s ", strings[stringc - 1]); stringc++; }*/ printf("lab7::set(%d, %d, %d, %d, %d, %d)\n", base_addr, tx, bits, stop, parity, rate, stringc); return ser_test_poll(1, tx, bits, stop, parity, rate); } else { printf("lab7: non valid function \"%s\" to test\n", argv[1]); return 1; } }
/* FIXME: This function does not handle LONG_LONG */ int _pSLang_sscanf (void) { int num; unsigned int num_refs; char *format; char *input_string, *input_string_max; SLFUTURE_CONST char *f, *s; unsigned char map8[256], map10[256], map16[256]; if (SLang_Num_Function_Args < 2) { _pSLang_verror (SL_INVALID_PARM, "Int_Type sscanf (str, format, ...)"); return -1; } num_refs = (unsigned int) SLang_Num_Function_Args; if (-1 == SLreverse_stack (num_refs)) return -1; num_refs -= 2; if (-1 == SLang_pop_slstring (&input_string)) return -1; if (-1 == SLang_pop_slstring (&format)) { SLang_free_slstring (input_string); return -1; } f = format; s = input_string; input_string_max = input_string + strlen (input_string); init_map (map8, 8); init_map (map10, 10); init_map (map16, 16); num = 0; while (num_refs != 0) { SLang_Object_Type obj; SLang_Ref_Type *ref; SLFUTURE_CONST char *smax; unsigned char *map; int base; int no_assign; int is_short; int is_long; int status; char chf; unsigned int width; int has_width; chf = *f++; if (chf == 0) { /* Hmmm.... what is the most useful thing to do?? */ #if 1 break; #else _pSLang_verror (SL_INVALID_PARM, "sscanf: format not big enough for output list"); goto return_error; #endif } if (isspace (chf)) { char *s1 = _pSLskip_whitespace (s); if (s1 == s) break; s = s1; continue; } if ((chf != '%') || ((chf = *f++) == '%')) { if (*s != chf) break; s++; continue; } no_assign = 0; is_short = 0; is_long = 0; width = 0; smax = input_string_max; /* Look for the flag character */ if (chf == '*') { no_assign = 1; chf = *f++; } /* Width */ has_width = isdigit (chf); if (has_width) { f--; (void) parse_uint (&f, f + strlen(f), &width, 10, map10); chf = *f++; } /* Now the type modifier */ switch (chf) { case 'h': is_short = 1; chf = *f++; break; case 'L': /* not implemented */ case 'l': is_long = 1; chf = *f++; break; } status = -1; if ((chf != 'c') && (chf != '[')) { s = _pSLskip_whitespace (s); if (*s == 0) break; } if (has_width) { if (width > (unsigned int) (input_string_max - s)) width = (unsigned int) (input_string_max - s); smax = s + width; } /* Now the format descriptor */ map = map10; base = 10; try_again: /* used by i, x, and o, conversions */ switch (chf) { case 0: _pSLang_verror (SL_INVALID_PARM, "sscanf: Unexpected end of format"); goto return_error; case 'D': is_long = 1; case 'd': if (is_short) { obj.o_data_type = SLANG_SHORT_TYPE; status = parse_short (&s, smax, &obj.v.short_val, base, map); } else if (is_long) { obj.o_data_type = SLANG_LONG_TYPE; status = parse_long (&s, smax, &obj.v.long_val, base, map); } else { obj.o_data_type = SLANG_INT_TYPE; status = parse_int (&s, smax, &obj.v.int_val, base, map); } break; case 'U': is_long = 1; case 'u': if (is_short) { obj.o_data_type = SLANG_USHORT_TYPE; status = parse_ushort (&s, smax, &obj.v.ushort_val, base, map); } else if (is_long) { obj.o_data_type = SLANG_ULONG_TYPE; status = parse_ulong (&s, smax, &obj.v.ulong_val, base, map); } else { obj.o_data_type = SLANG_INT_TYPE; status = parse_uint (&s, smax, &obj.v.uint_val, base, map); } break; case 'I': is_long = 1; case 'i': if ((s + 1 >= smax) || (*s != 0)) chf = 'd'; else if (((s[1] == 'x') || (s[1] == 'X')) && (s + 2 < smax)) { s += 2; chf = 'x'; } else chf = 'o'; goto try_again; case 'O': is_long = 1; case 'o': map = map8; base = 8; chf = 'd'; goto try_again; case 'X': is_long = 1; case 'x': base = 16; map = map16; chf = 'd'; goto try_again; case 'E': case 'F': is_long = 1; case 'e': case 'f': case 'g': #if SLANG_HAS_FLOAT if (is_long) { obj.o_data_type = SLANG_DOUBLE_TYPE; status = parse_double (&s, smax, &obj.v.double_val); } else { obj.o_data_type = SLANG_FLOAT_TYPE; status = parse_float (&s, smax, &obj.v.float_val); } #else _pSLang_verror (SL_NOT_IMPLEMENTED, "This version of the S-Lang does not support floating point"); status = -1; #endif break; case 's': obj.o_data_type = SLANG_STRING_TYPE; status = parse_string (&s, smax, &obj.v.s_val); break; case 'c': if (has_width == 0) { obj.o_data_type = SLANG_UCHAR_TYPE; obj.v.uchar_val = *s++; status = 1; break; } obj.o_data_type = SLANG_STRING_TYPE; status = parse_bstring (&s, smax, &obj.v.s_val); break; case '[': obj.o_data_type = SLANG_STRING_TYPE; status = parse_range (&s, smax, &f, &obj.v.s_val); break; case 'n': obj.o_data_type = SLANG_UINT_TYPE; obj.v.uint_val = (unsigned int) (s - input_string); status = 1; break; default: status = -1; _pSLang_verror (SL_NOT_IMPLEMENTED, "format specifier '%c' is not supported", chf); break; } if (status == 0) break; if (status == -1) goto return_error; if (no_assign) { SLang_free_object (&obj); continue; } if (-1 == SLang_pop_ref (&ref)) { SLang_free_object (&obj); goto return_error; } if (-1 == SLang_push (&obj)) { SLang_free_object (&obj); SLang_free_ref (ref); goto return_error; } if (-1 == _pSLang_deref_assign (ref)) { SLang_free_ref (ref); goto return_error; } SLang_free_ref (ref); num++; num_refs--; } if (-1 == SLdo_pop_n (num_refs)) goto return_error; SLang_free_slstring (format); SLang_free_slstring (input_string); return num; return_error: /* NULLS ok */ SLang_free_slstring (format); SLang_free_slstring (input_string); return -1; }
bool read_info (const interface_t *iface, dhcp_t *dhcp) { FILE *fp; char buffer[1024]; char *var; char *value; char *p; struct stat sb; if (stat (iface->infofile, &sb) != 0) { logger (LOG_ERR, "lease information file `%s' does not exist", iface->infofile); return (false); } if (! (fp = fopen (iface->infofile, "r"))) { logger (LOG_ERR, "fopen `%s': %s", iface->infofile, strerror (errno)); return (false); } dhcp->frominfo = true; memset (buffer, 0, sizeof (buffer)); while ((fgets (buffer, sizeof (buffer), fp))) { var = buffer; /* Strip leading spaces/tabs */ while ((*var == ' ') || (*var == '\t')) var++; /* Trim trailing \n */ p = var + strlen (var) - 1; if (*p == '\n') *p = 0; /* Skip comments */ if (*var == '#') continue; /* If we don't have an equals sign then skip it */ if (! (p = strchr (var, '='))) continue; /* Terminate the = so we have two strings */ *p = 0; value = p + 1; /* Strip leading and trailing quotes if present */ if (*value == '\'' || *value == '"') value++; p = value + strlen (value) - 1; if (*p == '\'' || *p == '"') *p = 0; /* Don't process null vars or values */ if (! *var || ! *value) continue; if (strcmp (var, "IPADDR") == 0) parse_address (&dhcp->address, value, "IPADDR"); else if (strcmp (var, "NETMASK") == 0) parse_address (&dhcp->netmask, value, "NETMASK"); else if (strcmp (var, "BROADCAST") == 0) parse_address (&dhcp->broadcast, value, "BROADCAST"); else if (strcmp (var, "MTU") == 0) parse_ushort (&dhcp->mtu, value, "MTU"); else if (strcmp (var, "ROUTES") == 0) { p = value; while ((value = strsep (&p, " "))) { char *pp = value; char *dest = strsep (&pp, ","); char *net = strsep (&pp, ","); char *gate = strsep (&pp, ","); route_t *route; if (! dest || ! net || ! gate) { logger (LOG_ERR, "read_info ROUTES `%s,%s,%s': invalid route", dest, net, gate); continue; } /* See if we can create a route */ route = xmalloc (sizeof (route_t)); memset (route, 0, sizeof (route_t)); if (inet_aton (dest, &route->destination) == 0) { logger (LOG_ERR, "read_info ROUTES `%s': not a valid destination address", dest); free (route); continue; } if (inet_aton (dest, &route->netmask) == 0) { logger (LOG_ERR, "read_info ROUTES `%s': not a valid netmask address", net); free (route); continue; } if (inet_aton (dest, &route->gateway) == 0) { logger (LOG_ERR, "read_info ROUTES `%s': not a valid gateway address", gate); free (route); continue; } /* OK, now add our route */ if (dhcp->routes) { route_t *r = dhcp->routes; while (r->next) r = r->next; r->next = route; } else dhcp->routes = route; } } else if (strcmp (var, "GATEWAYS") == 0) { p = value; while ((value = strsep (&p, " "))) { route_t *route = xmalloc (sizeof (route_t)); memset (route, 0, sizeof (route_t)); if (parse_address (&route->gateway, value, "GATEWAYS")) { if (dhcp->routes) { route_t *r = dhcp->routes; while (r->next) r = r->next; r->next = route; } else dhcp->routes = route; } else free (route); } } else if (strcmp (var, "HOSTNAME") == 0) dhcp->hostname = xstrdup (value); else if (strcmp (var, "DNSDOMAIN") == 0) dhcp->dnsdomain = xstrdup (value); else if (strcmp (var, "DNSSEARCH") == 0) dhcp->dnssearch = xstrdup (value); else if (strcmp (var, "DNSSERVERS") == 0) parse_addresses (&dhcp->dnsservers, value, "DNSSERVERS"); else if (strcmp (var, "NTPSERVERS") == 0) parse_addresses (&dhcp->ntpservers, value, "NTPSERVERS"); else if (strcmp (var, "NISDOMAIN") == 0) dhcp->nisdomain = xstrdup (value); else if (strcmp (var, "NISSERVERS") == 0) parse_addresses (&dhcp->nisservers, value, "NISSERVERS"); else if (strcmp (var, "ROOTPATH") == 0) dhcp->rootpath = xstrdup (value); else if (strcmp (var, "DHCPSID") == 0) parse_address (&dhcp->serveraddress, value, "DHCPSID"); else if (strcmp (var, "DHCPSNAME") == 0) strlcpy (dhcp->servername, value, sizeof (dhcp->servername)); else if (strcmp (var, "LEASEDFROM") == 0) parse_uint (&dhcp->leasedfrom, value, "LEASEDFROM"); else if (strcmp (var, "LEASETIME") == 0) parse_uint (&dhcp->leasetime, value, "LEASETIME"); else if (strcmp (var, "RENEWALTIME") == 0) parse_uint (&dhcp->renewaltime, value, "RENEWALTIME"); else if (strcmp (var, "REBINDTIME") == 0) parse_uint (&dhcp->rebindtime, value, "REBINDTIME"); } fclose (fp); return (true); }