Pharos 0.7.23
Modern Web Framework & Web App Hosting Service.
Loading...
Searching...
No Matches
native_barcode_runtime_ops.c
Go to the documentation of this file.
2
4#include "native_support.h"
5
6#include <stdio.h>
7#include <stdlib.h>
8
9int handle_native_barcode_command(int argc, char **argv) {
10 char *decoded_text = NULL;
11 int code = 0;
12
13 if (argc < 2 || argv == NULL || argv[0] == NULL || argv[1] == NULL) {
14 return 78;
15 }
16 if (!streq(argv[0], "barcode") || !streq(argv[1], "decode")) {
17 return 78;
18 }
19 if (argc != 3 || argv[2] == NULL || argv[2][0] == '\0') {
20 fprintf(stderr, "usage: pharos barcode decode IMAGE_PATH\n");
21 return 64;
22 }
23 if (!path_exists(argv[2])) {
24 fprintf(stderr, "image file not found: %s\n", argv[2]);
25 return 66;
26 }
27
28 code = native_barcode_decode_image_path(argv[2], &decoded_text);
29 if (code == 0) {
30 if (decoded_text == NULL) {
31 return 69;
32 }
33 printf("%s", decoded_text);
34 free(decoded_text);
35 return 0;
36 }
37
38 if (code == 69 && !native_barcode_decoder_is_direct_linked()) {
39 fprintf(stderr, "native barcode decode unavailable: rebuild with PHAROS_ENABLE_NATIVE_ZXING=1 for a host-supported target\n");
40 }
41 free(decoded_text);
42 return code;
43}
int native_barcode_decode_image_path(const char *image_path, char **decoded_text_out)
int native_barcode_decoder_is_direct_linked(void)
int handle_native_barcode_command(int argc, char **argv)
int streq(const char *a, const char *b)
Tests whether two strings are exactly equal.
int path_exists(const char *path)
Tests whether a filesystem path currently exists.
Declares shared low-level support helpers used across the Pharos native runtime.