static void show_proto(char *proto) /***************************************************************************** * put up a Qtext() display box with the full function prototype in it. ****************************************************************************/ { int len; int indent_count; char formatted_proto[1024]; char *pfmt = formatted_proto; char *ptmp; static Popot prompt = {"Syntax is: \n\n%s\n"}; /* ^^ this whitespace ^^ is intentional */ /* * pretty up the proto for display... * - copy the first word (the return value type, one presumes). * - insert a single space. * - skip additional spaces between the return type and function name. * - copy the function name, up thru the opening paren. * - if the function has 1 or 2 args, copy the rest of the line as is. * - if the function has more than 2 args, format them 1-per-line, * indented under the name of the function. * * while formatting, we put a gutter of 2 spaces before and after each * line of formatted text, to keep the display from jamming up against * the sides of the box, since that can be kinda ugly. */ pfmt = add_spaces(pfmt, 2); /* nice white gutter. */ while (*proto && *proto != ' ' && *proto != '\t') *pfmt++ = *proto++; /* copy return type. */ *pfmt++ = ' '; /* add one space. */ indent_count = 1 + (pfmt - formatted_proto); /* remember indent. */ while (*proto && (*proto == ' ' || *proto == '\t')) ++proto; /* skip other spaces. */ if (NULL != (ptmp = strchr(proto, ','))) { /* if multiple args... */ if (NULL == strchr(ptmp+1, ',')) /* if only two args, */ goto COPY_FULLINE; /* do it as one line. */ len = copy_thruchar(pfmt, proto, '('); /* copy function name */ pfmt += len; /* up thru opening paren. */ proto += len; pfmt = add_spaces(pfmt,2); /* add trailing gutter. */ *pfmt++ = '\n'; /* args go on later lines.*/ *pfmt++ = ' '; /* extra space looks good.*/ while (NULL != strchr(proto, ',')) { /* while more args left...*/ pfmt = add_spaces(pfmt, indent_count); /* indent the arg. */ len = copy_thruchar(pfmt, proto, ','); /* copy arg thru comma. */ pfmt += len; proto += len; pfmt = add_spaces(pfmt,2); /* add trailing gutter. */ *pfmt++ = '\n'; /* next arg on next line. */ } pfmt = add_spaces(pfmt, indent_count); /* indent last arg line. */ } COPY_FULLINE: while (*proto) /* copy rest of line. */ *pfmt++ = *proto++; pfmt = add_spaces(pfmt,2); /* add trailing gutter. */ *pfmt = '\0'; /* nullterm display str. */ /* * display string is all formatted, show it to the user... * * note that our callers will check the status of builtin_err; we don't * check it here because the only thing we could do is return, which * we do right after the Qtext call anyway. */ poeQtext(1,sizeof(char *), prompt, formatted_proto); }
/* Program extracts from Chapter 13 of
void process_realtime_stream(FILE *tty_file) { int forever = TRUE; char line[BUFSIZ]; char spaced_line[BUFSIZ]; char callsign[8]; int ilat, ilon; int itas, igps_alt, ipres_alt; int itdry, ilwjw, idewpt; int ice_count; int left_burn, right_burn, flare_state, snowmax_state; int igps_var, igps_err, iarnav_warn; date_time_t gps_time, wall_time; time_t last_store = 0; while (forever) { /* * wait for data, registering once per second while waiting */ while (ta_read_select(tty_file, 1000) != 1) { PMU_auto_register("Waiting for data"); } PMU_auto_register("Got data"); if (fgets(line, BUFSIZ, tty_file) == NULL) { fprintf(stderr, "ERROR - %s:process_stream\n", Glob->prog_name); perror(Glob->params.input_device); return; } add_spaces(line, spaced_line); if (Glob->params.debug) { fprintf(stderr, "Input line:\n%s", line); fprintf(stderr, "Spaced line:\n%s\n", spaced_line); } if (sscanf(spaced_line, "%s %d %d %d %d %d %d %d %d %d" "%d %d %d %d %2d %2d %2d %d %d %d", callsign, &ilat, &ilon, &itas, &igps_alt, &ipres_alt, &itdry, &ilwjw, &idewpt, &ice_count, &left_burn, &right_burn, &flare_state, &snowmax_state, &gps_time.hour, &gps_time.min, &gps_time.sec, &igps_var, &igps_err, &iarnav_warn) == 20) { if (Glob->params.debug) { fprintf(stderr, "Decoding : %s", line); fprintf(stderr, "Callsign : %s\n", callsign); fprintf(stderr, "lat : %g\n", ilat / 10000.0); fprintf(stderr, "lon : %g\n", ilon / 10000.0); fprintf(stderr, "tas : %d\n", itas); fprintf(stderr, "gps_alt : %g\n", igps_alt / 100.0); fprintf(stderr, "pres_alt : %g\n", ipres_alt / 100.0); fprintf(stderr, "tdry : %g\n", itdry / 10.0); fprintf(stderr, "lwJW : %g\n", ilwjw / 100.0); fprintf(stderr, "dewpt : %g\n", idewpt / 10.0); fprintf(stderr, "left burn : %d\n", left_burn); fprintf(stderr, "right burn : %d\n", right_burn); fprintf(stderr, "flare state: %d\n", flare_state); fprintf(stderr, "snow state : %d\n", snowmax_state); fprintf(stderr, "time : %.2d:%.2d:%.2d\n", gps_time.hour, gps_time.min, gps_time.sec); fprintf(stderr, "gps var : %d\n", igps_var); fprintf(stderr, "gps err : %d\n", igps_err); fprintf(stderr, "arnav code : %d\n", iarnav_warn); } /* * substitute wall clock time for gps time */ wall_time.unix_time = time(NULL); uconvert_from_utime(&wall_time); if((wall_time.unix_time - last_store) >= Glob->params.data_interval) { store_line(&wall_time, (double) ilat / 10000.0, (double) ilon / 10000.0, (double) ipres_alt / 100.0, callsign, itas, (double) itdry / 10.0, (double) ilwjw / 100.0, (double) idewpt / 10.0, left_burn, right_burn, flare_state, snowmax_state); if (Glob->params.use_spdb) { if (Glob->params.single_database) { store_single_spdb(&wall_time, (double) ilat / 10000.0, (double) ilon / 10000.0, (double) ipres_alt / 100.0, callsign); } else { store_mult_spdb(&wall_time, (double) ilat / 10000.0, (double) ilon / 10000.0, (double) ipres_alt / 100.0, callsign); } } /* if (Glob->params.use_spdb) */ last_store = wall_time.unix_time; } /* if((wall_time.unix_time - last_store) ... */ } else { if (Glob->params.debug) { fprintf(stderr, "WARNING - %s:process_stream\n", Glob->prog_name); fprintf(stderr, "Cannot decode: %s\n", (char *) spaced_line); } } } /* while (forever) */ }
static krb5_error_code decode_ad_policy_info(const krb5_data *data, char **msg_out) { struct ad_policy_info policy; uint64_t password_days; const char *p; char *msg; struct k5buf buf; *msg_out = NULL; if (data->length != AD_POLICY_INFO_LENGTH) return 0; p = data->data; policy.zero_bytes = load_16_be(p); p += 2; /* first two bytes are zeros */ if (policy.zero_bytes != 0) return 0; /* Read in the rest of structure */ policy.min_length_password = load_32_be(p); p += 4; policy.password_history = load_32_be(p); p += 4; policy.password_properties = load_32_be(p); p += 4; policy.expire = load_64_be(p); p += 8; policy.min_passwordage = load_64_be(p); p += 8; /* Check that we processed exactly the expected number of bytes. */ assert(p == data->data + AD_POLICY_INFO_LENGTH); krb5int_buf_init_dynamic(&buf); /* * Update src/tests/misc/test_chpw_message.c if changing these strings! */ if (policy.password_properties & AD_POLICY_COMPLEX) { krb5int_buf_add(&buf, _("The password must include numbers or symbols. " "Don't include any part of your name in the " "password.")); } if (policy.min_length_password > 0) { add_spaces(&buf); krb5int_buf_add_fmt(&buf, ngettext("The password must contain at least %d " "character.", "The password must contain at least %d " "characters.", policy.min_length_password), policy.min_length_password); } if (policy.password_history) { add_spaces(&buf); krb5int_buf_add_fmt(&buf, ngettext("The password must be different from the " "previous password.", "The password must be different from the " "previous %d passwords.", policy.password_history), policy.password_history); } if (policy.min_passwordage) { password_days = policy.min_passwordage / AD_POLICY_TIME_TO_DAYS; if (password_days == 0) password_days = 1; add_spaces(&buf); krb5int_buf_add_fmt(&buf, ngettext("The password can only be changed once a " "day.", "The password can only be changed every " "%d days.", (int)password_days), (int)password_days); } msg = krb5int_buf_data(&buf); if (msg == NULL) return ENOMEM; if (*msg != '\0') *msg_out = msg; else free(msg); return 0; }
std::string Function::spaces(const std::string str) { std::string result = add_spaces(str); return del_spaces(result); }