1 自定义命令
(1)编写自定义命令
1 编写自定义命令内容
2 注册指定命令
/*
*set up numbers sort command
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <tcl.h>
// numbers sort
int NumSort(ClientData ClientData, Tcl_Interp *Interp,
int objc, Tcl_Obj *const objv[]) {
double arr[objc], tmp;
char *pstr, *pstr2;
char buf[100];
int cnt = 1, cnt2 = 0, i = 0;
//1. string convert number,numbers sort
for(cnt = 1; cnt < objc; ++cnt) {
//1.1 string convert number
tmp = atof(Tcl_GetString(objv[cnt]));
//1.2 numbers sort
if(cnt == 1) arr[0] = tmp;
else {
for(cnt2 = cnt-1; cnt2 > 0; --cnt2) {
if(tmp >= arr[cnt2 -1]) {
arr[cnt2] = tmp;
break;
}
else arr[cnt2] = arr[cnt2 -1];
}
}
}
//2. numbers convert string and return
for(cnt2 = 0