摘要:如何向控制台输出彩色打印信息呢?如何订制自己的输出格式呢?下面将告诉你……import os"""0 All attributes off 默认值1 Bold (or Bright) 粗体 or 高亮4 Underline 下划线5 Blink 闪烁7 Reverse 反显30 Black text31 Red text32 Green text33 Yellow text34 Blue text35 Purple text36 Cyan text37 White text40 Black background41 Red background42 Green b
阅读全文
随笔分类 - python/lex/shell
脚本语言
摘要:from ctypes import *TenIntArrayType = c_int * 10 #相当于定义了一个int[10]类型arr = TenIntArrayType()#访问方法for ii in arr: print (ii)#或者for ii in range(10): print (arr[ii])lib = cdll.LoadLibrary("dll.so")#取指针lib.PrintData(pointer(arr), 10)ctypes基本数据类型:定义了对应于C内置类型的相应类型http://docs.python.org/release/2.5/
阅读全文
摘要:如何传递一个数组给动态库中的函数,并通过传递的数组返回字符串呢?这里演示一种间接的方法。不知道有没有更直接的方法?1 动态库中的函数定义:struct ss { char name[10]; int age; };void GetString(struct ss *p){ strcpy(p->name, "Hello dll."); p->age = 25;}编译生成dll.so: gcc -fPIC -O2 -shared dll.c -o dll.so2 python中调用实例:from ctypes import *class ss(Structure):
阅读全文
摘要:首先,创建一个简单的动态库编程生成dll.so: gcc -fPIC -O2 -shared dll.c -o dll.soC文件:dll.c 如下#include <stdio.h>struct param { int a; int b; char c; float f; int arr[3]; }; void print0(struct param arg){ printf("in print:\n"); printf("a: %d\n", arg.a); printf("b: %d\n", arg.b); print
阅读全文
摘要:1 检查可用IP#!/bin/shi=0while [ "$i" -le "255" ]do str="10.200.28.$i" ping -c 4 $str | awk '{if ($1=="PING") {ip=$2} else if ($5=="received,") {if ($4==0) {print ip,"/tFree"} else {print ip, "/t/tIn use"}}}' i=`expr $i + 1`don
阅读全文
摘要:遵循最长匹配规则C风格注释:1 cmark \/\*([^\*]|(\*)*[^\*/])*\*\/2 cmark \/\*([^\*]|(\*)+[^\/])*\*\/3 cmark \/\*([^\*]|(\*)+[^/])*\*\/1 不包含*或则有0到多个*并且后面没有*和/。(这样中间就不会匹配掉注释结尾的*/)2 不包含*或则有1到多个*并且后面没有/。(这样当遇到结尾*/时,因为前面是一个*,然后跟着一个/ -- 不满足匹配)匹配空行:null_line ^[ \t]*[ \n]匹配单词:words [^ \t\n]+chars [A-Za-z\_\'\.\"]
阅读全文
摘要:lex可以辅助生成词法分析程序,我们要做的仅仅是写好相应的正则表达式。简介:http://www.ibm.com/developerworks/cn/linux/sdk/lex/一个lex source file由三部分组成。%{C变量、函数声明%}lex标记声明%%lex的模式匹配规则%%C代码下面是一个统计字数与行数的小程序%{int word_cnt=0;int rows = 0;%}words [^ \t\n]+%%{words} word_cnt++;.\n rows++;%%void main(){ yylex(); printf("%d words, %d line\n
阅读全文

浙公网安备 33010602011771号