Debian Codegraph @

libs/sraxf/rna-flag-common.c

raw symbols SCIP
1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26 #include <vdb/extern.h>cxx . . $ `<file>/interfaces/vdb/extern.h`/
27
28 #include <klib/rc.h>cxx . . $ `<file>/interfaces/klib/rc.h`/
29 #include <kdb/meta.h>cxx . . $ `<file>/interfaces/kdb/meta.h`/
30 #include <string.h>
31
32 #define NODE_NAMEcxx . . $ `libs/sraxf/rna-flag-common.c:32:9`! "RNA_FLAG"
33
34 struct Selfcxx . . $ Self#;
35 typedef rc_tcxx . . $ rc_t# (*copy_fcxx . . $ copy_f#)(struct Selfcxx . . $ Self# *, uint8_tcxx . . $ uint8_t# *, uint8_tcxx . . $ uint8_t# const *, size_t);
36 struct Selfcxx . . $ Self# {
37 KMetadatacxx . . $ KMetadata# const *metacxx . . $ Self#meta.;
38 copy_fcxx . . $ copy_f# functioncxx . . $ Self#function.;
39 };
40
41 static void whackcxx . . $ whack(5d22bdacc48458e8).(void *const vp)
42 {
43 struct Selfcxx . . $ Self# *self = vp;
44 KMetadataReleasecxx . . $ KMetadataRelease(42a68de8c58e7f8b).(self->metacxx . . $ Self#meta.);
45 freecxx . . $ free(5d22bdacc48458e8).(self);
46 }
47
48 static rc_tcxx . . $ rc_t# copyDNA_to_DNAcxx . . $ copyDNA_to_DNA(45311c63ac233ccf).(struct Selfcxx . . $ Self# *const self
49 , uint8_tcxx . . $ uint8_t# *const dst
50 , uint8_tcxx . . $ uint8_t# const *const src
51 , size_t const length)
52 {
53 ((void)(self));
54 memmovecxx . . $ memmove(cc817cb175f282d).(dst, src, length);
55 return 0;
56 }
57
58 static rc_tcxx . . $ rc_t# copyRNA_to_DNAcxx . . $ copyRNA_to_DNA(45311c63ac233ccf).(struct Selfcxx . . $ Self# *const self
59 , uint8_tcxx . . $ uint8_t# *const dst
60 , uint8_tcxx . . $ uint8_t# const *const src
61 , size_t const length)
62 {
63 size_t i;
64
65 ((void)(self));
66 for (i = 0; i < length; ++i) {
67 int const base = src[i];
68 dst[i] = (base != 'U') ? (uint8_tcxx . . $ uint8_t#)base : (uint8_tcxx . . $ uint8_t#)'T';
69 }
70 return 0;
71 }
72
73 static rc_tcxx . . $ rc_t# copyDNA_to_RNAcxx . . $ copyDNA_to_RNA(45311c63ac233ccf).(struct Selfcxx . . $ Self# *const self
74 , uint8_tcxx . . $ uint8_t# *const dst
75 , uint8_tcxx . . $ uint8_t# const *const src
76 , size_t const length)
77 {
78 size_t i;
79
80 ((void)(self));
81 for (i = 0; i < length; ++i) {
82 int const base = src[i];
83 dst[i] = (base != 'T') ? (uint8_tcxx . . $ uint8_t#)base : (uint8_tcxx . . $ uint8_t#)'U';
84 }
85 return 0;
86 }
87
88 #if WRITE_SIDEcxx . . $ `libs/sraxf/use-rna-flag.c:34:9`!
89
90 static rc_t setFlag(KMetadata const *const cmeta, char const value)
91 {
92 KMetadata *const meta = (KMetadata *)cmeta;
93 KMDataNode *node = NULL;
94 rc_t rc = KMetadataOpenNodeUpdate(meta, &node, NODE_NAME);
95 if (rc == 0) {
96 rc = KMDataNodeWrite(node, &value, 1);
97 KMDataNodeRelease(node);
98 }
99 return rc;
100 }
101
102 static rc_t checkAndCopy(struct Self *const self
103 , uint8_t *const dst
104 , uint8_t const *const src
105 , size_t const length)
106 {
107 // Note: the FIRST T or U wins.
108 void const *const T = memchr(src, 'T', length);
109 void const *const U = memchr(src, 'U', length);
110
111 if (T != NULL && (U == NULL || T < U)) {
112 rc_t rc = setFlag(self->meta, '0');
113 if (rc) return rc;
114 self->function = &copyDNA_to_DNA;
115 return copyDNA_to_DNA(self, dst, src, length);
116 }
117 if (U != NULL && (T == NULL || U < T)) {
118 rc_t rc = setFlag(self->meta, '1');
119 if (rc) return rc;
120 self->function = &copyRNA_to_DNA;
121 return copyRNA_to_DNA(self, dst, src, length);
122 }
123 return copyDNA_to_DNA(self, dst, src, length);
124 }
125
126 #else
127
128 static rc_tcxx . . $ rc_t# getFlagcxx . . $ getFlag(3d27b2e2d61570bd).(KMetadatacxx . . $ KMetadata# const *const meta, char *const result)
129 {
130 KMDataNodecxx . . $ KMDataNode# const *node = NULLcxx . . $ `<external>/15298297234472979974/stddef.h:419:9`!;
131 rc_tcxx . . $ rc_t# rc = KMetadataOpenNodeReadcxx . . $ KMetadataOpenNodeRead(5f99d365c95dd08).(meta, &node, NODE_NAMEcxx . . $ `libs/sraxf/rna-flag-common.c:32:9`!);
132 if (rc == 0) {
133 size_t num_read = 0;
134 size_t remains = 0;
135
136 rc = KMDataNodeReadcxx . . $ KMDataNodeRead(5e1d632dbc2682e9).(node, 0, result, 1, &num_read, &remains);
137 KMDataNodeReleasecxx . . $ KMDataNodeRelease(706d8ad95cdbe72c).(node);
138 }
139 return rc;
140 }
141
142 static rc_tcxx . . $ rc_t# checkAndCopycxx . . $ checkAndCopy(45311c63ac233ccf).(struct Selfcxx . . $ Self# *const self
143 , uint8_tcxx . . $ uint8_t# *const dst
144 , uint8_tcxx . . $ uint8_t# const *const src
145 , size_t const length)
146 {
147 char rna = '\0';
148 rc_tcxx . . $ rc_t# rc = getFlagcxx . . $ getFlag(3d27b2e2d61570bd).(self->metacxx . . $ Self#meta., &rna);
149 if (rc == 0 && rna == '0') {
150 self->functioncxx . . $ Self#function. = &copyDNA_to_DNAcxx . . $ copyDNA_to_DNA(45311c63ac233ccf).;
151 return copyDNA_to_DNAcxx . . $ copyDNA_to_DNA(45311c63ac233ccf).(self, dst, src, length);
152 }
153 if (rc == 0 && rna == '1') {
154 self->functioncxx . . $ Self#function. = &copyDNA_to_RNAcxx . . $ copyDNA_to_RNA(45311c63ac233ccf).;
155 return copyDNA_to_RNAcxx . . $ copyDNA_to_RNA(45311c63ac233ccf).(self, dst, src, length);
156 }
157 return copyDNA_to_DNAcxx . . $ copyDNA_to_DNA(45311c63ac233ccf).(self, dst, src, length);
158 }
159
160 #endif
161
162 static rc_tcxx . . $ rc_t# makeSelfcxx . . $ makeSelf(9a89feca3d415c13).(VFuncDesccxx . . $ VFuncDesc# *rslt, KMetadatacxx . . $ KMetadata# const *meta)
163 {
164 struct Selfcxx . . $ Self# *self = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(sizeof(*self));
165 if (self) {
166 self->metacxx . . $ Self#meta. = meta;
167 self->functioncxx . . $ Self#function. = &checkAndCopycxx . . $ checkAndCopy(45311c63ac233ccf).;
168
169 rslt->variantcxx . . $ VFuncDesc#variant. = vftRowcxx . . $ vftRow.;
170 rslt->selfcxx . . $ VFuncDesc#self. = self;
171 rslt->whackcxx . . $ VFuncDesc#whack. = whackcxx . . $ whack(5d22bdacc48458e8).;
172 return 0;
173 }
174 return RCcxx . . $ `interfaces/klib/rc.h:111:9`!(rcXF, rcFunction, rcCreating, rcMemory, rcExhausted);
175 }