Devuan fork of gpsd
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1065 lines
45 KiB

  1. #!/usr/bin/env python
  2. #
  3. # This file is Copyright (c) 2010 by the GPSD project
  4. # SPDX-License-Identifier: BSD-2-clause
  5. #
  6. # Never hand-hack what you can generate...
  7. #
  8. # This code generates template declarations for AIS-JSON parsing from a
  9. # declarative specification of a JSON structure.
  10. #
  11. # This code runs compatibly under Python 2 and 3.x for x >= 2.
  12. # Preserve this property!
  13. from __future__ import absolute_import, print_function, division
  14. import getopt
  15. import sys
  16. #
  17. # Here is the information that makes it all work - attribute, type, and
  18. # defult information for all fields. We generate a JSON
  19. # parser template spec. Doing it this way guarantees consistency.
  20. #
  21. # Notes on the fields:
  22. # initname: becomes the name of the generated structure initializer
  23. # header: common header to include in front of the structure template
  24. # structname: gets prepended to all fieldnames in the generated C
  25. # fieldmap: each member fills an initializer slot
  26. # stringbuffered: list strings that should be buffered rather than copied
  27. # directly into the structure.
  28. ais_specs = (
  29. {
  30. "initname": "json_ais1",
  31. "headers": ("AIS_HEADER",),
  32. "structname": "ais->type1",
  33. "fieldmap": (
  34. # fieldname type default
  35. ('status', 'uinteger', '0'),
  36. ('status_text', 'ignore', None),
  37. ('turn', 'integer', 'AIS_TURN_NOT_AVAILABLE'),
  38. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  39. ('accuracy', 'boolean', 'false'),
  40. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  41. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  42. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  43. ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'),
  44. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  45. ('maneuver', 'uinteger', 'AIS_SEC_INOPERATIVE'),
  46. ('raim', 'boolean', 'false'),
  47. ('radio', 'uinteger', '0'),
  48. ),
  49. },
  50. # Message types 2 and 3 duplicate 1
  51. {
  52. "initname": "json_ais4",
  53. "headers": ("AIS_HEADER",),
  54. "structname": "ais->type4",
  55. "fieldmap": (
  56. # fieldname type default
  57. ('timestamp', 'string', None),
  58. ('accuracy', 'boolean', "true"),
  59. ('lon', 'integer', "AIS_LON_NOT_AVAILABLE"),
  60. ('lat', 'integer', "AIS_LAT_NOT_AVAILABLE"),
  61. ('epfd', 'uinteger', "0"),
  62. ('epfd_text', 'ignore', None),
  63. ('raim', 'boolean', "false"),
  64. ('radio', 'uinteger', "0"),
  65. ),
  66. "stringbuffered": ("timestamp",),
  67. },
  68. {
  69. "initname": "json_ais5",
  70. "headers": ("AIS_HEADER",),
  71. "structname": "ais->type5",
  72. "fieldmap": (
  73. # fieldname type default
  74. ('imo', 'uinteger', '0'),
  75. ('ais_version', 'uinteger', '0'),
  76. ('callsign', 'string', None),
  77. ('shipname', 'string', None),
  78. ('shiptype', 'uinteger', '0'),
  79. ('shiptype_text', 'ignore', None),
  80. ('to_bow', 'uinteger', '0'),
  81. ('to_stern', 'uinteger', '0'),
  82. ('to_port', 'uinteger', '0'),
  83. ('to_starboard', 'uinteger', '0'),
  84. ('epfd', 'uinteger', '0'),
  85. ('epfd_text', 'ignore', None),
  86. ('eta', 'string', None),
  87. ('draught', 'uinteger', '0'),
  88. ('destination', 'string', None),
  89. ('dte', 'uinteger', '1'),
  90. ),
  91. "stringbuffered": ("eta",),
  92. },
  93. {
  94. "initname": "json_ais6",
  95. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  96. "structname": "ais->type6",
  97. "fieldmap": (
  98. # fieldname type default
  99. ('data', 'string', None),
  100. ),
  101. "stringbuffered": ("data",),
  102. },
  103. {
  104. "initname": "json_ais6_fid10",
  105. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  106. "structname": "ais->type6.dac235fid10",
  107. "fieldmap": (
  108. # fieldname type default
  109. ('ana_int', 'uinteger', '0'),
  110. ('ana_ext1', 'uinteger', '0'),
  111. ('ana_ext2', 'uinteger', '0'),
  112. ('racon', 'uinteger', '0'),
  113. ('racon_text', 'ignore', None),
  114. ('light', 'uinteger', '0'),
  115. ('light_text', 'ignore', None),
  116. ('alarm', 'boolean', 'false'),
  117. ('stat_ext', 'uinteger', '0'),
  118. ('off_pos', 'boolean', 'false'),
  119. ),
  120. },
  121. {
  122. "initname": "json_ais6_fid12",
  123. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  124. "structname": "ais->type6.dac1fid12",
  125. "fieldmap": (
  126. # fieldname type default
  127. ('lastport', 'string', None),
  128. ('departure', 'string', None),
  129. ('nextport', 'string', None),
  130. ('eta', 'string', None),
  131. ('dangerous', 'string', None),
  132. ('imdcat', 'string', None),
  133. ('unid', 'uinteger', '0'),
  134. ('amount', 'uinteger', '0'),
  135. ('unit', 'uinteger', '0'),
  136. ),
  137. "stringbuffered": ("departure", "eta",),
  138. },
  139. {
  140. "initname": "json_ais6_fid15",
  141. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  142. "structname": "ais->type6.dac1fid15",
  143. "fieldmap": (
  144. # fieldname type default
  145. ('airdraught', 'uinteger', '0'),
  146. ),
  147. },
  148. {
  149. "initname": "json_ais6_fid16",
  150. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  151. "structname": "ais->type6.dac1fid16",
  152. "fieldmap": (
  153. # fieldname type default
  154. ('persons', 'uinteger', '0'),
  155. ),
  156. },
  157. {
  158. "initname": "json_ais6_fid18",
  159. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  160. "structname": "ais->type6.dac1fid18",
  161. "fieldmap": (
  162. # fieldname type default
  163. ('linkage', 'uinteger', '0'),
  164. ('arrival', 'string', None),
  165. ('portname', 'string', None),
  166. ('destination', 'string', None),
  167. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  168. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  169. ),
  170. 'stringbuffered': ('arrival',),
  171. },
  172. {
  173. "initname": "json_ais6_fid20",
  174. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  175. "structname": "ais->type6.dac1fid20",
  176. "fieldmap": (
  177. # fieldname type default
  178. ('linkage', 'uinteger', '0'),
  179. ('berth_length', 'uinteger', '0'),
  180. ('berth_depth', 'uinteger', '0'),
  181. ('position', 'uinteger', '0'),
  182. ('position_text', 'ignore', None),
  183. ('arrival', 'string', None),
  184. ('availability', 'uinteger', '0'),
  185. ('agent', 'uinteger', '0'),
  186. ('fuel', 'uinteger', '0'),
  187. ('chandler', 'uinteger', '0'),
  188. ('stevedore', 'uinteger', '0'),
  189. ('electrical', 'uinteger', '0'),
  190. ('water', 'uinteger', '0'),
  191. ('customs', 'uinteger', '0'),
  192. ('cartage', 'uinteger', '0'),
  193. ('crane', 'uinteger', '0'),
  194. ('lift', 'uinteger', '0'),
  195. ('medical', 'uinteger', '0'),
  196. ('navrepair', 'uinteger', '0'),
  197. ('provisions', 'uinteger', '0'),
  198. ('shiprepair', 'uinteger', '0'),
  199. ('surveyor', 'uinteger', '0'),
  200. ('steam', 'uinteger', '0'),
  201. ('tugs', 'uinteger', '0'),
  202. ('solidwaste', 'uinteger', '0'),
  203. ('liquidwaste', 'uinteger', '0'),
  204. ('hazardouswaste', 'uinteger', '0'),
  205. ('ballast', 'uinteger', '0'),
  206. ('additional', 'uinteger', '0'),
  207. ('regional1', 'uinteger', '0'),
  208. ('regional2', 'uinteger', '0'),
  209. ('future1', 'uinteger', '0'),
  210. ('future2', 'uinteger', '0'),
  211. ('berth_name', 'string', None),
  212. ('berth_lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  213. ('berth_lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  214. ),
  215. 'stringbuffered': ('arrival', 'berth_name',),
  216. },
  217. {
  218. "initname": "json_ais6_fid21",
  219. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  220. "structname": "ais->type6.dac200fid21",
  221. "fieldmap": (
  222. # fieldname type default
  223. ('country', 'string', None),
  224. ('locode', 'string', None),
  225. ('section', 'string', None),
  226. ('terminal', 'string', None),
  227. ('hectometre', 'string', None),
  228. ('eta', 'string', None),
  229. ('tugs', 'uinteger', '0'),
  230. ('airdraught', 'uinteger', '0'),
  231. ),
  232. "stringbuffered": ("eta",),
  233. },
  234. {
  235. "initname": "json_ais6_fid22",
  236. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  237. "structname": "ais->type6.dac200fid22",
  238. "fieldmap": (
  239. # fieldname type default
  240. ('country', 'string', None),
  241. ('locode', 'string', None),
  242. ('section', 'string', None),
  243. ('terminal', 'string', None),
  244. ('hectometre', 'string', None),
  245. ('rta', 'string', None),
  246. ('status', 'uinteger', 'DAC200FID22_STATUS_NOT_AVAILABLE'),
  247. ),
  248. "stringbuffered": ("rta",),
  249. },
  250. {
  251. "initname": "json_ais6_fid25",
  252. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  253. "structname": "ais->type6.dac1fid25",
  254. "fieldmap": (
  255. # fieldname type default
  256. ('unit', 'uinteger', '0'),
  257. ('amount', 'uinteger', '0'),
  258. ('cargos', 'array', (
  259. ('cargo_t', 'ncargos', (
  260. ('code', 'uinteger', '0'),
  261. ('subtype', 'uinteger', '0'),
  262. )))),
  263. ),
  264. },
  265. {
  266. "initname": "json_ais6_fid28",
  267. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  268. "structname": "ais->type6.dac1fid28",
  269. "fieldmap": (
  270. # fieldname type default
  271. ('linkage', 'uinteger', '0'),
  272. ('sender', 'uinteger', '0'),
  273. ('rtype', 'uinteger', '0'),
  274. ('rtype_text', 'ignore', None),
  275. ('start', 'string', None),
  276. ('duration', 'uinteger', '0'),
  277. ('waypoints', 'array', (
  278. ('waypoint_t', 'waycount', (
  279. ('lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  280. ('lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  281. )))),
  282. ),
  283. 'stringbuffered': ('start',),
  284. },
  285. {
  286. "initname": "json_ais6_fid30",
  287. "headers": ("AIS_HEADER", "AIS_TYPE6",),
  288. "structname": "ais->type6.dac1fid30",
  289. "fieldmap": (
  290. # fieldname type default
  291. ('linkage', 'uinteger', '0'),
  292. ('text', 'string', '0'),
  293. ),
  294. },
  295. {
  296. "initname": "json_ais6_fid32",
  297. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  298. "structname": "ais->type6.dac1fid32",
  299. "fieldmap": (
  300. # fieldname type default
  301. ('month', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  302. ('day', 'uinteger', 'AIS_DAY_NOT_AVAILABLE'),
  303. ('tidals', 'array', (
  304. ('tidal_t', 'ntidals', (
  305. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  306. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  307. ('from_hour', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  308. ('from_min', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  309. ('to_hour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  310. ('to_min', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  311. ('cdir', 'uinteger', 'DAC1FID32_CDIR_NOT_AVAILABLE'),
  312. ('cspeed', 'uinteger', 'DAC1FID32_CSPEED_NOT_AVAILABLE'),
  313. )))),
  314. ),
  315. },
  316. {
  317. "initname": "json_ais6_fid55",
  318. "headers": ("AIS_HEADER", "AIS_TYPE6"),
  319. "structname": "ais->type6.dac200fid55",
  320. "fieldmap": (
  321. # fieldname type default
  322. ('crew', 'uinteger', 'DAC200FID55_COUNT_NOT_AVAILABLE'),
  323. ('passengers', 'uinteger', 'DAC200FID55_COUNT_NOT_AVAILABLE'),
  324. ('personnel', 'uinteger', 'DAC200FID55_COUNT_NOT_AVAILABLE'),
  325. ),
  326. },
  327. {
  328. "initname": "json_ais7",
  329. "headers": ("AIS_HEADER",),
  330. "structname": "ais->type7",
  331. "fieldmap": (
  332. # fieldname type default
  333. ('mmsi1', 'uinteger', '0'),
  334. ('mmsi2', 'uinteger', '0'),
  335. ('mmsi3', 'uinteger', '0'),
  336. ('mmsi4', 'uinteger', '0'),
  337. ('seqno1', 'uinteger', '0'),
  338. ('seqno2', 'uinteger', '0'),
  339. ('seqno3', 'uinteger', '0'),
  340. ('seqno4', 'uinteger', '0'),
  341. ),
  342. },
  343. {
  344. "initname": "json_ais8",
  345. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  346. "structname": "ais->type8",
  347. "fieldmap": (
  348. # fieldname type default
  349. ('data', 'string', None),
  350. ),
  351. "stringbuffered": ("data",),
  352. },
  353. {
  354. "initname": "json_ais8_fid10",
  355. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  356. "structname": "ais->type8.dac200fid10",
  357. "fieldmap": (
  358. # fieldname type default
  359. ('vin', 'string', None),
  360. ('length', 'uinteger', '0'),
  361. ('beam', 'uinteger', '0'),
  362. ('shiptype', 'uinteger', '0'),
  363. ('shiptype_text', 'ignore', None),
  364. ('hazard', 'uinteger', '0'),
  365. ('hazard_text', 'ignore', None),
  366. ('draught', 'uinteger', '0'),
  367. ('loaded', 'uinteger', '0'),
  368. ('loaded_text', 'ignore', None),
  369. ('speed_q', 'boolean', 'false'),
  370. ('course_q', 'boolean', 'false'),
  371. ('heading_q', 'boolean', 'false'),
  372. ),
  373. },
  374. {
  375. "initname": "json_ais8_fid11",
  376. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  377. "structname": "ais->type8.dac1fid11",
  378. "fieldmap": (
  379. # fieldname type default
  380. ('lat', 'integer', 'DAC1FID11_LAT_NOT_AVAILABLE'),
  381. ('lon', 'integer', 'DAC1FID11_LON_NOT_AVAILABLE'),
  382. ('timestamp', 'string', None),
  383. ('wspeed', 'uinteger', 'DAC1FID11_WSPEED_NOT_AVAILABLE'),
  384. ('wgust', 'uinteger', 'DAC1FID11_WSPEED_NOT_AVAILABLE'),
  385. ('wdir', 'uinteger', 'DAC1FID11_WDIR_NOT_AVAILABLE'),
  386. ('wgustdir', 'uinteger', 'DAC1FID11_WDIR_NOT_AVAILABLE'),
  387. ('airtemp', 'uinteger', 'DAC1FID11_AIRTEMP_NOT_AVAILABLE'),
  388. ('humidity', 'uinteger', 'DAC1FID11_HUMIDITY_NOT_AVAILABLE'),
  389. ('dewpoint', 'uinteger', 'DAC1FID11_DEWPOINT_NOT_AVAILABLE'),
  390. ('pressure', 'uinteger', 'DAC1FID11_PRESSURE_NOT_AVAILABLE'),
  391. ('pressuretend', 'uinteger',
  392. 'DAC1FID11_PRESSURETREND_NOT_AVAILABLE'),
  393. ('visibility', 'uinteger', 'DAC1FID11_VISIBILITY_NOT_AVAILABLE'),
  394. ('waterlevel', 'integer', 'DAC1FID11_WATERLEVEL_NOT_AVAILABLE'),
  395. ('leveltrend', 'uinteger',
  396. 'DAC1FID11_WATERLEVELTREND_NOT_AVAILABLE'),
  397. ('cspeed', 'uinteger', 'DAC1FID11_CSPEED_NOT_AVAILABLE'),
  398. ('cdir', 'uinteger', 'DAC1FID11_CDIR_NOT_AVAILABLE'),
  399. ('cspeed2', 'uinteger', 'DAC1FID11_CSPEED_NOT_AVAILABLE'),
  400. ('cdir2', 'uinteger', 'DAC1FID11_CDIR_NOT_AVAILABLE'),
  401. ('cdepth2', 'uinteger', 'DAC1FID11_CDEPTH_NOT_AVAILABLE'),
  402. ('cspeed3', 'uinteger', 'DAC1FID11_CSPEED_NOT_AVAILABLE'),
  403. ('cdir3', 'uinteger', 'DAC1FID11_CDIR_NOT_AVAILABLE'),
  404. ('cdepth3', 'uinteger', 'DAC1FID11_CDEPTH_NOT_AVAILABLE'),
  405. ('waveheight', 'uinteger', 'DAC1FID11_WAVEHEIGHT_NOT_AVAILABLE'),
  406. ('waveperiod', 'uinteger', 'DAC1FID11_WAVEPERIOD_NOT_AVAILABLE'),
  407. ('wavedir', 'uinteger', 'DAC1FID11_WAVEDIR_NOT_AVAILABLE'),
  408. ('swellheight', 'uinteger', 'DAC1FID11_WAVEHEIGHT_NOT_AVAILABLE'),
  409. ('swellperiod', 'uinteger', 'DAC1FID11_WAVEPERIOD_NOT_AVAILABLE'),
  410. ('swelldir', 'uinteger', 'DAC1FID11_WAVEDIR_NOT_AVAILABLE'),
  411. ('seastate', 'uinteger', 'DAC1FID11_SEASTATE_NOT_AVAILABLE'),
  412. ('watertemp', 'uinteger', 'DAC1FID11_WATERTEMP_NOT_AVAILABLE'),
  413. ('preciptype', 'uinteger', 'DAC1FID11_PRECIPTYPE_NOT_AVAILABLE'),
  414. ('preciptype_text', 'ignore', None),
  415. ('salinity', 'uinteger', 'DAC1FID11_SALINITY_NOT_AVAILABLE'),
  416. ('ice', 'uinteger', 'DAC1FID11_ICE_NOT_AVAILABLE'),
  417. ('ice_text', 'ignore', None),
  418. ),
  419. "stringbuffered": ("timestamp",),
  420. },
  421. {
  422. "initname": "json_ais8_fid13",
  423. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  424. "structname": "ais->type8.dac1fid13",
  425. "fieldmap": (
  426. # fieldname type default
  427. ('reason', 'string', None),
  428. ('closefrom', 'string', None),
  429. ('closeto', 'string', None),
  430. ('radius', 'uinteger', 'AIS_DAC1FID13_RADIUS_NOT_AVAILABLE'),
  431. ('extunit', 'uinteger', 'AIS_DAC1FID13_EXTUNIT_NOT_AVAILABLE'),
  432. ('fday', 'uinteger', 'AIS_DAY_NOT_AVAILABLE'),
  433. ('fmonth', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  434. ('fhour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  435. ('fminute', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  436. ('tday', 'uinteger', 'AIS_DAY_NOT_AVAILABLE'),
  437. ('tmonth', 'uinteger', 'AIS_MONTH_NOT_AVAILABLE'),
  438. ('thour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  439. ('tminute', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  440. ),
  441. 'stringbuffered': ('closefrom', 'closeto'),
  442. },
  443. {
  444. "initname": "json_ais8_fid15",
  445. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  446. "structname": "ais->type8.dac1fid15",
  447. "fieldmap": (
  448. # fieldname type default
  449. ('airdraught', 'uinteger', '0'),
  450. ),
  451. },
  452. {
  453. "initname": "json_ais8_fid16",
  454. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  455. "structname": "ais->type8.dac1fid16",
  456. "fieldmap": (
  457. # fieldname type default
  458. ('persons', 'uinteger', '0'),
  459. ),
  460. },
  461. {
  462. "initname": "json_ais8_fid17",
  463. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  464. "structname": "ais->type8.dac1fid17",
  465. "fieldmap": (
  466. # fieldname type default
  467. ('targets', 'array', (
  468. ('target_t', 'ntargets', (
  469. ('idtype', 'uinteger', 'DAC1FID17_IDTYPE_OTHER'),
  470. ("id.mmsi", 'uinteger', '0'),
  471. ("id.imo", 'uinteger', '0'),
  472. ("id.callsign", 'string', 'DAC1FID17_ID_LENGTH'),
  473. ("id.other", 'string', 'DAC1FID17_ID_LENGTH'),
  474. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  475. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  476. ('course', 'uinteger', 'DAC1FID17_COURSE_NOT_AVAILABLE'),
  477. ('second', 'uinteger', 'AIS_SECOND_NOT_AVAILABLE'),
  478. ('speed', 'uinteger', 'DAC1FID17_SPEED_NOT_AVAILABLE'),
  479. )))),
  480. ),
  481. },
  482. {
  483. "initname": "json_ais8_fid19",
  484. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  485. "structname": "ais->type8.dac1fid19",
  486. "fieldmap": (
  487. # fieldname type default
  488. ('linkage', 'uinteger', '0'),
  489. ('station', 'string', None),
  490. ('lon', 'integer', 'AIS_LON3_NOT_AVAILABLE'),
  491. ('lat', 'integer', 'AIS_LAT3_NOT_AVAILABLE'),
  492. ('status', 'uinteger', '0'),
  493. ('signal', 'uinteger', '0'),
  494. ('signal_text', 'ignore', None),
  495. ('hour', 'uinteger', 'AIS_HOUR_NOT_AVAILABLE'),
  496. ('minute', 'uinteger', 'AIS_MINUTE_NOT_AVAILABLE'),
  497. ('nextsignal', 'uinteger', '0'),
  498. ('nextsignal_type', 'ignore', None),
  499. ),
  500. },
  501. {
  502. "initname": "json_ais8_fid23",
  503. "headers": ("AIS_HEADER", "AIS_TYPE8"),
  504. "structname": "ais->type8.dac200fid23",
  505. "fieldmap": (
  506. # fieldname type default
  507. ('start', 'string', None),
  508. ('end', 'string', None),
  509. ('start_lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  510. ('start_lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  511. ('end_lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  512. ('end_lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  513. ('type', 'uinteger', 'DAC200FID23_TYPE_UNKNOWN'),
  514. ('type_text', 'ignore', None),
  515. ('min', 'integer', 'DAC200FID23_MIN_UNKNOWN'),
  516. ('max', 'integer', 'DAC200FID23_MAX_UNKNOWN'),
  517. ('intensity', 'uinteger', 'DAC200FID23_CLASS_UNKNOWN'),
  518. ('intensity_text', 'ignore', None),
  519. ('wind', 'uinteger', 'DAC200FID23_WIND_UNKNOWN'),
  520. ('wind_text', 'ignore', None),
  521. ),
  522. 'stringbuffered': ('start', 'end'),
  523. },
  524. {
  525. "initname": "json_ais8_fid24",
  526. "headers": ("AIS_HEADER", "AIS_TYPE8"),
  527. "structname": "ais->type8.dac200fid24",
  528. "fieldmap": (
  529. # fieldname type default
  530. ('country', 'string', None),
  531. ('gauges', 'array', (
  532. ('gauge_t', 'ngauges', (
  533. ('id', 'uinteger', 'DAC200FID24_GAUGE_ID_UNKNOWN'),
  534. ('level', 'integer', 'DAC200FID24_GAUGE_LEVEL_UNKNOWN'),
  535. )))),
  536. ),
  537. },
  538. {
  539. "initname": "json_ais8_fid27",
  540. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  541. "structname": "ais->type8.dac1fid27",
  542. "fieldmap": (
  543. # fieldname type default
  544. ('linkage', 'uinteger', '0'),
  545. ('sender', 'uinteger', '0'),
  546. ('rtype', 'uinteger', '0'),
  547. ('rtype_text', 'ignore', None),
  548. ('start', 'string', None),
  549. ('duration', 'uinteger', '0'),
  550. ('waypoints', 'array', (
  551. ('waypoint_t', 'waycount', (
  552. ('lon', 'integer', 'AIS_LON4_NOT_AVAILABLE'),
  553. ('lat', 'integer', 'AIS_LAT4_NOT_AVAILABLE'),
  554. )))),
  555. ),
  556. 'stringbuffered': ('start',),
  557. },
  558. {
  559. "initname": "json_ais8_fid29",
  560. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  561. "structname": "ais->type8.dac1fid29",
  562. "fieldmap": (
  563. # fieldname type default
  564. ('linkage', 'uinteger', '0'),
  565. ('text', 'string', '0'),
  566. ),
  567. },
  568. {
  569. "initname": "json_ais8_fid31",
  570. "headers": ("AIS_HEADER", "AIS_TYPE8",),
  571. "structname": "ais->type8.dac1fid31",
  572. "fieldmap": (
  573. # fieldname type default
  574. ('lon', 'integer', 'DAC1FID31_LON_NOT_AVAILABLE'),
  575. ('lat', 'integer', 'DAC1FID31_LAT_NOT_AVAILABLE'),
  576. ('accuracy', 'boolean', 'false'),
  577. ('timestamp', 'string', None),
  578. ('wspeed', 'uinteger', 'DAC1FID31_WIND_NOT_AVAILABLE'),
  579. ('wgust', 'uinteger', 'DAC1FID31_WIND_NOT_AVAILABLE'),
  580. ('wdir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  581. ('wgustdir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  582. ('airtemp', 'integer', 'DAC1FID31_AIRTEMP_NOT_AVAILABLE'),
  583. ('humidity', 'uinteger', 'DAC1FID31_HUMIDITY_NOT_AVAILABLE'),
  584. ('dewpoint', 'integer', 'DAC1FID31_DEWPOINT_NOT_AVAILABLE'),
  585. ('pressure', 'uinteger', 'DAC1FID31_PRESSURE_NOT_AVAILABLE'),
  586. ('pressuretend', 'uinteger',
  587. 'DAC1FID31_PRESSURETEND_NOT_AVAILABLE'),
  588. ('visgreater', 'boolean', 'false'),
  589. ('visibility', 'uinteger', 'DAC1FID31_VISIBILITY_NOT_AVAILABLE'),
  590. ('waterlevel', 'integer', 'DAC1FID31_WATERLEVEL_NOT_AVAILABLE'),
  591. ('leveltrend', 'uinteger',
  592. 'DAC1FID31_WATERLEVELTREND_NOT_AVAILABLE'),
  593. ('cspeed', 'uinteger', 'DAC1FID31_CSPEED_NOT_AVAILABLE'),
  594. ('cdir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  595. ('cspeed2', 'uinteger', 'DAC1FID31_CSPEED_NOT_AVAILABLE'),
  596. ('cdir2', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  597. ('cdepth2', 'uinteger', 'DAC1FID31_CDEPTH_NOT_AVAILABLE'),
  598. ('cspeed3', 'uinteger', 'DAC1FID31_CSPEED_NOT_AVAILABLE'),
  599. ('cdir3', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  600. ('cdepth3', 'uinteger', 'DAC1FID31_CDEPTH_NOT_AVAILABLE'),
  601. ('waveheight', 'uinteger', 'DAC1FID31_HEIGHT_NOT_AVAILABLE'),
  602. ('waveperiod', 'uinteger', 'DAC1FID31_PERIOD_NOT_AVAILABLE'),
  603. ('wavedir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  604. ('swellheight', 'uinteger', 'DAC1FID31_HEIGHT_NOT_AVAILABLE'),
  605. ('swellperiod', 'uinteger', 'DAC1FID31_PERIOD_NOT_AVAILABLE'),
  606. ('swelldir', 'uinteger', 'DAC1FID31_DIR_NOT_AVAILABLE'),
  607. ('seastate', 'uinteger', 'DAC1FID31_SEASTATE_NOT_AVAILABLE'),
  608. ('watertemp', 'integer', 'DAC1FID31_WATERTEMP_NOT_AVAILABLE'),
  609. ('preciptype', 'uinteger', 'DAC1FID31_PRECIPTYPE_NOT_AVAILABLE'),
  610. ('preciptype_text', 'ignore', None),
  611. ('salinity', 'uinteger', 'DAC1FID31_SALINITY_NOT_AVAILABLE'),
  612. ('ice', 'uinteger', 'DAC1FID31_ICE_NOT_AVAILABLE'),
  613. ),
  614. "stringbuffered": ("timestamp",),
  615. },
  616. {
  617. "initname": "json_ais8_fid40",
  618. "headers": ("AIS_HEADER", "AIS_TYPE8"),
  619. "structname": "ais->type8.dac200fid40",
  620. "fieldmap": (
  621. # fieldname type default
  622. ('form', 'uinteger', 'DAC200FID40_FORM_UNKNOWN'),
  623. ('facing', 'uinteger', 'DAC200FID40_FACING_UNKNOWN'),
  624. ('direction', 'uinteger', 'DAC200FID40_DIRECTION_UNKNOWN'),
  625. ('direction_text', 'ignore', None),
  626. ('status', 'uinteger', 'DAC200FID40_STATUS_UNKNOWN'),
  627. ('status_text', 'ignore', None),
  628. ),
  629. },
  630. {
  631. "initname": "json_ais9",
  632. "headers": ("AIS_HEADER",),
  633. "structname": "ais->type9",
  634. "fieldmap": (
  635. # fieldname type default
  636. ('alt', 'uinteger', 'AIS_ALT_NOT_AVAILABLE'),
  637. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  638. ('accuracy', 'boolean', 'false'),
  639. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  640. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  641. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  642. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  643. ('regional', 'uinteger', '0'),
  644. ('dte', 'uinteger', '1'),
  645. ('raim', 'boolean', 'false'),
  646. ('radio', 'uinteger', '0'),
  647. ),
  648. },
  649. {
  650. "initname": "json_ais10",
  651. "headers": ("AIS_HEADER",),
  652. "structname": "ais->type10",
  653. "fieldmap": (
  654. # fieldname type default
  655. ('dest_mmsi', 'uinteger', '0'),
  656. ),
  657. },
  658. # Message type 11 duplicates 4
  659. {
  660. "initname": "json_ais12",
  661. "headers": ("AIS_HEADER",),
  662. "structname": "ais->type12",
  663. "fieldmap": (
  664. # fieldname type default
  665. ('seqno', 'uinteger', '0'),
  666. ('dest_mmsi', 'uinteger', '0'),
  667. ('retransmit', 'boolean', '0'),
  668. ('text', 'string', None),
  669. ),
  670. },
  671. # Message type 13 duplicates 7
  672. {
  673. "initname": "json_ais14",
  674. "headers": ("AIS_HEADER",),
  675. "structname": "ais->type14",
  676. "fieldmap": (
  677. # fieldname type default
  678. ('text', 'string', None),
  679. ),
  680. },
  681. {
  682. "initname": "json_ais15",
  683. "headers": ("AIS_HEADER",),
  684. "structname": "ais->type15",
  685. "fieldmap": (
  686. # fieldname type default
  687. ('mmsi1', 'uinteger', '0'),
  688. ('type1_1', 'uinteger', '0'),
  689. ('offset1_1', 'uinteger', '0'),
  690. ('type1_2', 'uinteger', '0'),
  691. ('offset1_2', 'uinteger', '0'),
  692. ('mmsi2', 'uinteger', '0'),
  693. ('type2_1', 'uinteger', '0'),
  694. ('offset2_1', 'uinteger', '0'),
  695. ),
  696. },
  697. {
  698. "initname": "json_ais16",
  699. "headers": ("AIS_HEADER",),
  700. "structname": "ais->type16",
  701. "fieldmap": (
  702. # fieldname type default
  703. ('mmsi1', 'uinteger', '0'),
  704. ('offset1', 'uinteger', '0'),
  705. ('increment1', 'uinteger', '0'),
  706. ('mmsi2', 'uinteger', '0'),
  707. ('offset2', 'uinteger', '0'),
  708. ('increment2', 'uinteger', '0'),
  709. ),
  710. },
  711. {
  712. "initname": "json_ais17",
  713. "headers": ("AIS_HEADER",),
  714. "structname": "ais->type17",
  715. "fieldmap": (
  716. # fieldname type default
  717. ('lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  718. ('lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  719. ('data', 'string', None),
  720. ),
  721. "stringbuffered": ("data",),
  722. },
  723. {
  724. "initname": "json_ais18",
  725. "headers": ("AIS_HEADER",),
  726. "structname": "ais->type18",
  727. "fieldmap": (
  728. # fieldname type default
  729. ('reserved', 'uinteger', '0'),
  730. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  731. ('accuracy', 'boolean', 'false'),
  732. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  733. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  734. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  735. ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'),
  736. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  737. ('regional', 'uinteger', '0'),
  738. ('cs', 'boolean', 'false'),
  739. ('display', 'boolean', 'false'),
  740. ('dsc', 'boolean', 'false'),
  741. ('band', 'boolean', 'false'),
  742. ('msg22', 'boolean', 'false'),
  743. ('raim', 'boolean', 'false'),
  744. ('radio', 'uinteger', '0'),
  745. ),
  746. },
  747. {
  748. "initname": "json_ais19",
  749. "headers": ("AIS_HEADER",),
  750. "structname": "ais->type19",
  751. "fieldmap": (
  752. # fieldname type default
  753. ('reserved', 'uinteger', '0'),
  754. ('speed', 'uinteger', 'AIS_SPEED_NOT_AVAILABLE'),
  755. ('accuracy', 'boolean', 'false'),
  756. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  757. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  758. ('course', 'uinteger', 'AIS_COURSE_NOT_AVAILABLE'),
  759. ('heading', 'uinteger', 'AIS_HEADING_NOT_AVAILABLE'),
  760. ('second', 'uinteger', 'AIS_SEC_NOT_AVAILABLE'),
  761. ('regional', 'uinteger', '0'),
  762. ('shipname', 'string', None),
  763. ('shiptype', 'uinteger', '0'),
  764. ('shiptype_text', 'ignore', None),
  765. ('to_bow', 'uinteger', '0'),
  766. ('to_stern', 'uinteger', '0'),
  767. ('to_port', 'uinteger', '0'),
  768. ('to_starboard', 'uinteger', '0'),
  769. ('epfd', 'uinteger', '0'),
  770. ('epfd_text', 'ignore', None),
  771. ('raim', 'boolean', 'false'),
  772. ('dte', 'uinteger', '1'),
  773. ('assigned', 'boolean', 'false'),
  774. ),
  775. },
  776. {
  777. "initname": "json_ais20",
  778. "headers": ("AIS_HEADER",),
  779. "structname": "ais->type20",
  780. "fieldmap": (
  781. # fieldname type default
  782. ('offset1', 'uinteger', '0'),
  783. ('number1', 'uinteger', '0'),
  784. ('timeout1', 'uinteger', '0'),
  785. ('increment1', 'uinteger', '0'),
  786. ('offset2', 'uinteger', '0'),
  787. ('number2', 'uinteger', '0'),
  788. ('timeout2', 'uinteger', '0'),
  789. ('increment2', 'uinteger', '0'),
  790. ('offset3', 'uinteger', '0'),
  791. ('number3', 'uinteger', '0'),
  792. ('timeout3', 'uinteger', '0'),
  793. ('increment3', 'uinteger', '0'),
  794. ('offset4', 'uinteger', '0'),
  795. ('number4', 'uinteger', '0'),
  796. ('timeout4', 'uinteger', '0'),
  797. ('increment4', 'uinteger', '0'),
  798. ),
  799. },
  800. {
  801. "initname": "json_ais21",
  802. "headers": ("AIS_HEADER",),
  803. "structname": "ais->type21",
  804. "fieldmap": (
  805. # fieldname type default
  806. ('aid_type', 'uinteger', '0'),
  807. ('aid_type_text', 'ignore', None),
  808. ('name', 'string', None),
  809. ('accuracy', 'boolean', 'false'),
  810. ('lon', 'integer', 'AIS_LON_NOT_AVAILABLE'),
  811. ('lat', 'integer', 'AIS_LAT_NOT_AVAILABLE'),
  812. ('to_bow', 'uinteger', '0'),
  813. ('to_stern', 'uinteger', '0'),
  814. ('to_port', 'uinteger', '0'),
  815. ('to_starboard', 'uinteger', '0'),
  816. ('epfd', 'uinteger', '0'),
  817. ('epfd_text', 'ignore', None),
  818. ('second', 'uinteger', '0'),
  819. ('regional', 'uinteger', '0'),
  820. ('off_position', 'boolean', 'false'),
  821. ('raim', 'boolean', 'false'),
  822. ('virtual_aid', 'boolean', 'false'),
  823. ),
  824. },
  825. {
  826. "initname": "json_ais22",
  827. "headers": ("AIS_HEADER",),
  828. "structname": "ais->type22",
  829. "fieldmap": (
  830. # fieldname type default
  831. ('channel_a', 'uinteger', '0'),
  832. ('channel_b', 'uinteger', '0'),
  833. ('txrx', 'uinteger', '0'),
  834. ('power', 'boolean', 'false'),
  835. ('area.ne_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  836. ('area.ne_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  837. ('area.sw_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  838. ('area.sw_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  839. ('mmsi.dest1', 'uinteger', '0'),
  840. ('mmsi.dest2', 'uinteger', '0'),
  841. ('addressed', 'boolean', 'false'),
  842. ('band_a', 'boolean', 'false'),
  843. ('band_b', 'boolean', 'false'),
  844. ('zonesize', 'uinteger', '0'),
  845. ),
  846. },
  847. {
  848. "initname": "json_ais23",
  849. "headers": ("AIS_HEADER",),
  850. "structname": "ais->type23",
  851. "fieldmap": (
  852. # fieldname type default
  853. ('ne_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  854. ('ne_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  855. ('sw_lon', 'integer', 'AIS_GNS_LON_NOT_AVAILABLE'),
  856. ('sw_lat', 'integer', 'AIS_GNS_LAT_NOT_AVAILABLE'),
  857. ('stationtype', 'uinteger', '0'),
  858. ('stationtype_text', 'ignore', None),
  859. ('shiptype', 'uinteger', '0'),
  860. ('shiptype_text', 'ignore', None),
  861. ('txrx', 'uinteger', '0'),
  862. ('interval', 'uinteger', '0'),
  863. ('quiet', 'uinteger', '0'),
  864. ),
  865. },
  866. {
  867. "initname": "json_ais24",
  868. "headers": ("AIS_HEADER",),
  869. "structname": "ais->type24",
  870. "fieldmap": (
  871. # fieldname type default
  872. ('shipname', 'string', None), # Part A
  873. ('shiptype', 'uinteger', '0'), # Part B
  874. ('shiptype_text', 'ignore', None),
  875. ('vendorid', 'string', None), # Part B
  876. ('model', 'uinteger', '0'), # Part B
  877. ('serial', 'uinteger', '0'), # Part B
  878. ('callsign', 'string', None), # Part B
  879. ('mothership_mmsi', 'uinteger', '0'), # Part B
  880. ('dim.to_bow', 'uinteger', '0'), # Part B
  881. ('dim.to_stern', 'uinteger', '0'), # Part B
  882. ('dim.to_port', 'uinteger', '0'), # Part B
  883. ('dim.to_starboard', 'uinteger', '0'), # Part B
  884. ),
  885. },
  886. {
  887. "initname": "json_ais25",
  888. "headers": ("AIS_HEADER",),
  889. "structname": "ais->type25",
  890. "fieldmap": (
  891. # fieldname type default
  892. ('addressed', 'boolean', 'false'),
  893. ('structured', 'boolean', 'false'),
  894. ('dest_mmsi', 'uinteger', '0'),
  895. ('app_id', 'uinteger', '0'),
  896. ('data', 'string', None),
  897. ),
  898. "stringbuffered": ("data",),
  899. },
  900. {
  901. "initname": "json_ais26",
  902. "headers": ("AIS_HEADER",),
  903. "structname": "ais->type26",
  904. "fieldmap": (
  905. # fieldname type default
  906. ('addressed', 'boolean', 'false'),
  907. ('structured', 'boolean', 'false'),
  908. ('dest_mmsi', 'uinteger', '0'),
  909. ('app_id', 'uinteger', '0'),
  910. ('data', 'string', None),
  911. ('radio', 'uinteger', '0'),
  912. ),
  913. "stringbuffered": ("data",),
  914. },
  915. {
  916. "initname": "json_ais27",
  917. "headers": ("AIS_HEADER",),
  918. "structname": "ais->type27",
  919. "fieldmap": (
  920. # fieldname type default
  921. ('status', 'uinteger', '0'),
  922. ('speed', 'uinteger', 'AIS_LONGRANGE_SPEED_NOT_AVAILABLE'),
  923. ('accuracy', 'boolean', 'false'),
  924. ('lon', 'integer', 'AIS_LONGRANGE_LON_NOT_AVAILABLE'),
  925. ('lat', 'integer', 'AIS_LONGRANGE_LAT_NOT_AVAILABLE'),
  926. ('course', 'uinteger', 'AIS_LONGRANGE_COURSE_NOT_AVAILABLE'),
  927. ('raim', 'boolean', 'false'),
  928. ('gnss', 'boolean', 'true'),
  929. ),
  930. },
  931. )
  932. # You should not need to modify anything below this line.
  933. def generate(spec):
  934. report = ""
  935. leader = " " * 39
  936. initname = spec["initname"]
  937. # Utter storage declarations for any fields that are declared to be
  938. # stringbuffered. These will need to be postprocessed in json_ais_read().
  939. attributes = [t[0] for t in spec["fieldmap"]]
  940. for attr in spec.get("stringbuffered", []):
  941. if attr not in attributes:
  942. sys.stderr.write("buffered %s is not in base attributes of %s\n"
  943. % (attr, initname))
  944. raise SystemExit(1)
  945. if attr not in outboard:
  946. report += " char %s[JSON_VAL_MAX+1];\n" % attr
  947. outboard.append(attr)
  948. structname = spec["structname"]
  949. # If there are structarrays describing array subobjects, we need
  950. # to make a separate parse control initializer for each one. The
  951. # attribute name is the name of the array; substructure and length
  952. # fieldnames must be given in the defaults part.
  953. for (attr, itype, arrayparts) in spec["fieldmap"]:
  954. if itype == 'array':
  955. (innerstruct, lengthfield, elements) = arrayparts
  956. report += (" const struct json_attr_t %s_%s_subtype[] = {\n"
  957. % (initname, attr))
  958. for (subattr, subitype, default) in elements:
  959. report += ('\t{"%s",%st_%s,%sSTRUCTOBJECT(struct %s, %s),\n'
  960. % (subattr, " " * (14 - len(subattr)), subitype,
  961. " " * (8 - len(subitype)), innerstruct, subattr))
  962. if subitype != "string":
  963. report += (leader + ".dflt.%s = %s},\n"
  964. % (subitype, default))
  965. elif default:
  966. report += leader + ".len = %s},\n" % (default,)
  967. else:
  968. sys.stderr.write(
  969. "explicit length specification required\n")
  970. raise SystemExit(1)
  971. report += """\
  972. {NULL}
  973. };
  974. """
  975. # Generate the main structure definition describing this parse.
  976. # It may have object subarrays.
  977. report += " const struct json_attr_t %s[] = {\n" % initname
  978. if "headers" in spec:
  979. for header in spec["headers"]:
  980. report += '\t' + header + "\n"
  981. for (attr, itype, default) in spec["fieldmap"]:
  982. if itype == 'array':
  983. (innerstruct, lengthfield, elements) = default
  984. report += ('\t{"%s",%st_array, '
  985. 'STRUCTARRAY(%s.%s, %s_%s_subtype, &%s.%s)},\n'
  986. % (attr, " " * (14 - len(attr)), structname, attr,
  987. initname, attr, structname, lengthfield))
  988. else:
  989. if itype == "string":
  990. deref = ""
  991. else:
  992. deref = "&"
  993. if attr in spec.get("stringbuffered", []):
  994. target = attr
  995. else:
  996. target = structname + "." + attr
  997. if "." in attr:
  998. attr = attr[attr.rfind(".") + 1:]
  999. if itype == 'ignore':
  1000. report += '\t{"%s", t_ignore},\n' % attr
  1001. continue
  1002. report += '\t{"%s",%st_%s,%s.addr.%s = %s%s,\n' % \
  1003. (attr, " " * (14 - len(attr)), itype, " " * (10 - len(itype)),
  1004. itype, deref, target)
  1005. if itype == "string":
  1006. report += leader + ".len = sizeof(%s)},\n" % target
  1007. else:
  1008. report += leader + ".dflt.%s = %s},\n" % (itype, default)
  1009. report += """\
  1010. {NULL}
  1011. };
  1012. """
  1013. print(report)
  1014. if __name__ == '__main__':
  1015. try:
  1016. # The --ais and --target= options are (required) placeholders.
  1017. # In the future, this script will generate more different kinds
  1018. # of code.
  1019. (options, arguments) = getopt.getopt(sys.argv[1:], "",
  1020. ["ais", "target="])
  1021. except getopt.GetoptError as msg:
  1022. print("jsongen.py: " + str(msg))
  1023. raise SystemExit(1)
  1024. spec = None
  1025. target = None
  1026. for (switch, val) in options:
  1027. if switch == '--ais':
  1028. spec = ais_specs
  1029. elif switch == '--target':
  1030. target = val
  1031. if not target or not spec:
  1032. print("jsongen.py: must specify type and target.")
  1033. raise SystemExit(1)
  1034. if target == 'parser':
  1035. print("""/*
  1036. * This is code generated by jsongen.py. Do not hand-hack it!
  1037. */
  1038. #define NITEMS(x) (int)(sizeof(x)/sizeof(x[0]))
  1039. """)
  1040. outboard = []
  1041. for description in spec:
  1042. generate(description)
  1043. print("""
  1044. /* Generated code ends. */
  1045. """)
  1046. # The following sets edit modes for GNU EMACS
  1047. # Local Variables:
  1048. # mode:python
  1049. # End: