使用m4将字符串转换为ASCII码点 [英] Using m4 to convert a string to ASCII codepoints

查看:216
本文介绍了使用m4将字符串转换为ASCII码点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是可能的,但因为我是一个新手与m4,我不知道如何去,或如何编写一个算法这样做(在m4)。

This should be possible, but as I am a novice with m4, I'm not sure how to go about it, or how to write an algorithm to do so (in m4).

编辑:

只是解决了,无论如何,为了将来参考,我有一系列字符,他们需要翻译成等效的ASCII代码例如

Just solved it, anyway for future reference, I have a series of characters, they need to be translated to their equivalent ASCII code points, e.g.

ascii(-{COLON}-, -{:}-) => #define TKN_COLON 58


推荐答案

divert(-1)
changequote(-{,}-)
changecom(/*,*/)
define(-{ascii}-,-{#define TKN_-{}-$1 esyscmd(-{python -c "import sys; sys.stdout.write('%d'%ord('$2'))"}-)}-)
divert(0)dnl

如果有人知道更好的方法(例如native m4或更便携的shell命令),我将非常感谢。

I would greatly appreciate if anyone knows of a better way to do this (e.g. native m4, or more portable shell command).

这篇关于使用m4将字符串转换为ASCII码点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆