int parse_line(char * in_line){ int i = 0; int initial_length = strlen(in_line); printf("initial_length = %d\n", initial_length); char * token = strtok_single(in_line, " "); printf("%s ",token); /* walk through other tokens */ //The first call you use a char array which has the elements you want parsed. //The second time you call it you pass it NULL as the first parameter to tell function //to resume from the last spot in the string. Once the first call is made your char //array receives the parsed string. If you don't put NULL you would lose your place //and effectivly the last part of your string. if (initial_length > 2){ while(token) { if (initial_length >= 200){ i++; token = strtok_single(NULL, " "); //if (i < 100) printf( "%d, %s\n", i, token); if (i < 100) printf("%s ",token); } else{ i++; token = strtok_single(NULL, " "); //if (i < 6) printf( "%d, %s\n", i, token); if (i < 6) printf("%s ",token); } } } printf("\n"); return 0; }
//Parse the NMEA String int parse_nmea(char *in_sent){ int i = 0; char* token; //Error case for string. Check sentence token if (!tag_check(in_sent)){ printf("Error, no appropriate NMEA tag.\n"); return -1; } else{ //Begin parsing in full // get the first token token = strtok_single(in_sent, ","); gps_data[0] = token; /* walk through other tokens */ //The first call you use a char array which has the elements you want parsed. //The second time you call it you pass it NULL as the first parameter to tell function //to resume from the last spot in the string. Once the first call is made your char //array receives the parsed string. If you don't put NULL you would lose your place //and effectivly the last part of your string. while(token) { i++; token = strtok_single(NULL, ","); //printf( "%d, %s\n", i, token); gps_data[i] = token; } for(i =0; i<13;i++) printf("%d: %s\n", i, gps_data[i]); } return 0; }
int parse_line(char * in_line){ int i = 0; int initial_length = strlen(in_line); printf("chars parsed: %d\n", initial_length); char * token = strtok_single(in_line, " "); /* walk through other tokens */ //The first call you use a char array which has the elements you want parsed. //The second time you call it you pass it NULL as the first parameter to tell function //to resume from the last spot in the string. Once the first call is made your char //array receives the parsed string. If you don't put NULL you would lose your place //and effectivly the last part of your string. if (initial_length > 10){ if (initial_length >= 200){ //grid population send_byte((uint8_t)*(token)); printf("%s ", token); while(token){ i++; token = strtok_single(NULL, " "); if (i < 100) { send_byte((uint8_t)*(token)); printf("%s ",token); } usleep(200000); } printf("\n"); } else{ //Station line //printf("callsign:%s\n", token); send_string(token); if (strlen(token) < 8) { int k=0; for (k=0; k< 8-strlen(token); k++) { send_string(" "); } } while(token){ i++; token = strtok_single(NULL, " "); if (i < 6) send_float(token); //if (i < 6) printf("float:%s ",token); usleep(200000); } } } else{ send_float(token); //printf("num_stations: %s\n",token); } printf("\n"); return 0; }
int64_t load_table (mongoc_database_t *db, const char *table_name, bson_t *bson_schema) { int64_t ret = true; column_map_t *column_map, *column_map_p; int column_map_size, i; double start_time, end_time, delta_time; FILE *fp; mongoc_collection_t *collection; mongoc_bulk_operation_t *bulk; size_t n_docs = 0; char *token; bson_t bson, reply; int64_t count = 0; bson_error_t error; fprintf (stderr, "load_table table_name: \"%s\"\n", table_name); get_column_map (bson_schema, table_name, &column_map, &column_map_size) || DIE; snprintf (mbdump_file, MAXPATHLEN, "%s/%s", mbdump_dir, table_name); /* fprintf (stderr, "mbdump_file: \"%s\"\n", mbdump_file); */ start_time = dtimeofday (); fp = fopen (mbdump_file, "r"); if (!fp) DIE; collection = mongoc_database_get_collection (db, table_name); bulk = mongoc_collection_create_bulk_operation (collection, true, NULL); bson_init (&bson); while (ret && fgets (buf, BUFSIZ, fp)) { /* fputs (buf, stdout); */ chomp (buf); for (i = 0, column_map_p = column_map, token = strtok_single (buf, "\t"); i < column_map_size; i++, column_map_p++, token = strtok_single (NULL, "\t")) { bool ret; /* fprintf (stderr, "%s: \"%s\" [%d/%d](%s)\n", column_map_p->column_name, token, i, column_map_size, column_map_p->data_type); fflush (stdout); */ ret = (*column_map_p->bson_append_from_s) (&bson, column_map_p->column_name, token); ret || fprintf (stderr, "WARNING: column_map_p->bson_append_from_s failed column %s: \"%s\" [%d/%d](%s)\n", column_map_p->column_name, token, i, column_map_size, column_map_p->data_type); } /* bson_printf ("bson: %s\n", &bson); */ mongoc_bulk_operation_insert (bulk, &bson); bson_reinit (&bson); if (++n_docs == BULK_OPS_SIZE) { ret = mongoc_bulk_operation_execute (bulk, &reply, &error); if (ret) { count += n_docs; if (count % PROGRESS_SIZE == 0) { fputc('.', stdout); fflush(stdout); } } else fprintf (stderr, "mongoc_cursor_bulk_insert execute failure: %s\n", error.message); n_docs = 0; mongoc_bulk_operation_destroy (bulk); bulk = mongoc_collection_create_bulk_operation (collection, true, NULL); } } if (ret && n_docs > 0) { ret = mongoc_bulk_operation_execute (bulk, &reply, &error); if (ret) count += n_docs; else fprintf (stderr, "mongoc_cursor_bulk_insert execute failure: %s\n", error.message); } fputc('.', stdout); fputc('\n', stdout); fflush(stdout); bson_destroy (&bson); mongoc_bulk_operation_destroy (bulk); mongoc_collection_destroy (collection); fclose (fp); end_time = dtimeofday (); delta_time = end_time - start_time + 0.0000001; fprintf (stderr, "info: real: %.2f, count: %"PRId64", %"PRId64" docs/sec\n", delta_time, count, (int64_t)round (count/delta_time)); fflush (stderr); free (column_map); return ret ? count : -1; }