]> sigrok.org Git - sigrok-cli.git/blobdiff - sigrok-cli.c
srd: extra module path can now optionally be passed to srd_init()
[sigrok-cli.git] / sigrok-cli.c
index d51c893ebbc10fe58e6f28aebc06da4fe35a1ff7..4502da40482ad53c3aa4f7a8598fcc96a40a6541 100644 (file)
@@ -114,7 +114,7 @@ static void show_version(void)
        printf("\n");
 
        /* TODO: Error handling. */
-       srd_init();
+       srd_init(NULL);
 
        printf("Supported protocol decoders:\n");
        for (l = srd_list_decoders(); l; l = l->next) {
@@ -130,7 +130,7 @@ static void print_device_line(const struct sr_device *device)
 {
        const struct sr_device_instance *sdi;
 
-       sr_device_get_info(device, SR_DI_INSTANCE, (const void **) &sdi);
+       sr_device_get_info(device, SR_DI_INSTANCE, (const void **)&sdi);
 
        if (sdi->vendor && sdi->vendor[0])
                printf("%s ", sdi->vendor);
@@ -190,7 +190,7 @@ static void show_device_detail(void)
        print_device_line(device);
 
        if (sr_device_get_info(device, SR_DI_TRIGGER_TYPES,
-                                                  (const void **) &charopts) == SR_OK) {
+                                       (const void **)&charopts) == SR_OK) {
                printf("Supported triggers: ");
                while (*charopts) {
                        printf("%c ", *charopts);
@@ -213,7 +213,7 @@ static void show_device_detail(void)
                if (hwo->capability == SR_HWCAP_PATTERN_MODE) {
                        printf("    %s", hwo->shortname);
                        if (sr_device_get_info(device, SR_DI_PATTERNMODES,
-                                                                  (const void **) &stropts) == SR_OK) {
+                                       (const void **)&stropts) == SR_OK) {
                                printf(" - supported modes:\n");
                                for (i = 0; stropts[i]; i++)
                                        printf("      %s\n", stropts[i]);
@@ -224,7 +224,7 @@ static void show_device_detail(void)
                        printf("    %s", hwo->shortname);
                        /* Supported samplerates */
                        if (sr_device_get_info(device, SR_DI_SAMPLERATES,
-                                                                  (const void **) &samplerates) != SR_OK) {
+                                       (const void **)&samplerates) != SR_OK) {
                                printf("\n");
                                continue;
                        }
@@ -234,17 +234,17 @@ static void show_device_detail(void)
                                if (!(s = sr_samplerate_string(samplerates->low)))
                                        continue;
                                printf(" (%s", s);
-                               free(s);
+                               g_free(s);
                                /* high */
                                if (!(s = sr_samplerate_string(samplerates->high)))
                                        continue;
                                printf(" - %s", s);
-                               free(s);
+                               g_free(s);
                                /* step */
                                if (!(s = sr_samplerate_string(samplerates->step)))
                                        continue;
                                printf(" in steps of %s)\n", s);
-                               free(s);
+                               g_free(s);
                        } else {
                                printf(" - supported samplerates:\n");
                                for (i = 0; samplerates->list[i]; i++) {
@@ -313,7 +313,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac
        case SR_DF_HEADER:
                g_message("cli: Received SR_DF_HEADER");
                /* Initialize the output module. */
-               if (!(o = malloc(sizeof(struct sr_output)))) {
+               if (!(o = g_try_malloc(sizeof(struct sr_output)))) {
                        printf("Output module malloc failed.\n");
                        exit(1);
                }
@@ -370,7 +370,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac
                        if (output_len) {
                                if (outfile)
                                        fwrite(output_buf, 1, output_len, outfile);
-                               free(output_buf);
+                               g_free(output_buf);
                                output_len = 0;
                        }
                }
@@ -383,7 +383,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac
                sr_session_halt();
                if (outfile && outfile != stdout)
                        fclose(outfile);
-               free(o);
+               g_free(o);
                o = NULL;
                break;
        case SR_DF_TRIGGER:
@@ -447,7 +447,7 @@ static void datafeed_in(struct sr_device *device, struct sr_datafeed_packet *pac
                        o->format->data(o, filter_out, filter_out_len, &output_buf, &output_len);
                if (output_len) {
                        fwrite(output_buf, 1, output_len, outfile);
-                       free(output_buf);
+                       g_free(output_buf);
                }
        }
 
@@ -510,11 +510,14 @@ err_out:
        return 0;
 }
 
-void show_pd_annotation(struct srd_proto_data *pdata)
+void show_pd_annotation(struct srd_proto_data *pdata, void *user_data)
 {
        int i;
        char **annotations;
 
+       /* 'user_data' is not used in this specific callback. */
+       (void)user_data;
+
        if (pdata->ann_format != 0) {
                /* CLI only shows the default annotation format. */
                return;
@@ -646,7 +649,7 @@ static void load_input_file_format(void)
        }
 
        /* Initialize the input module. */
-       if (!(in = malloc(sizeof(struct sr_input)))) {
+       if (!(in = g_try_malloc(sizeof(struct sr_input)))) {
                printf("Failed to allocate input module.\n");
                exit(1);
        }
@@ -880,8 +883,8 @@ static void run_session(void)
                                const uint64_t *samplerate;
 
                                sr_device_get_info(device, SR_DI_CUR_SAMPLERATE,
-                                                                  (const void **) &samplerate);
-                               limit_samples = (*samplerate) * time_msec / (uint64_t) 1000;
+                                               (const void **)&samplerate);
+                               limit_samples = (*samplerate) * time_msec / (uint64_t)1000;
                        }
                        if (limit_samples == 0) {
                                printf("Not enough time at this samplerate.\n");
@@ -1003,7 +1006,7 @@ int main(int argc, char **argv)
                return 1;
 
        if (opt_pds) {
-               if (srd_init() != SRD_OK) {
+               if (srd_init(NULL) != SRD_OK) {
                        printf("Failed to initialize sigrokdecode\n");
                        return 1;
                }
@@ -1012,7 +1015,7 @@ int main(int argc, char **argv)
                        return 1;
                }
                if (srd_register_callback(SRD_OUTPUT_ANN,
-                               show_pd_annotation) != SRD_OK) {
+                               show_pd_annotation, NULL) != SRD_OK) {
                        printf("Failed to register protocol decoder callback\n");
                        return 1;
                }