2008-04-29

【转】越看越不错的海报~~~~~~~

转自网络蚯蚓~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




2008-04-22

迷你小词典~

原创小词典~~~~~~~~~使用了海词的提供的API~~~~~~~~在此感谢啦~~~~~~~~
import org.eclipse.swt.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.events.*;
import org.eclipse.swt.browser.*;
import org.eclipse.swt.browser.Browser;

public class Dict {

private Text express;

private Text searchWord;

public Dict() {

final Display display = Display.getDefault();

final Shell shell = new Shell(display);
shell.setSize(500, 380);
shell.setText("Dict --by stonestrange");

final Browser browser = new Browser(shell, SWT.NONE);
browser.setBounds(116, 66, 363, 282);

searchWord = new Text(shell, SWT.BORDER);
searchWord.setBounds(91, 19, 268, 22);

final Button search = new Button(shell, SWT.NONE);
search.setText("search");
search.setBounds(385, 19, 94, 22);
search.setImage(searchImage);
search.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
String word = searchWord.getText();
String url = "http://dict.cn/mini.php?q=";
url = url + word;
browser.setUrl(url);
}
});


express = new Text(shell, SWT.BORDER);
express.setBounds(116, 66, 363, 282);

shell.open();
shell.layout();

while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

public static void main(String[] args) {
new Dict();
}
}

2008-04-15

[转]如何判断真假性近视

假性近视是真性近视眼之前的一种疲劳状态,如果这种状态不能及时缓解,眼睛发生器质性改变就会形成真性近视。判断真假近视眼需要做散瞳验光,散瞳的目的是解除眼睛疲劳,让紧张的肌肉放松,这样验出的屈光度才是准确的。如果散瞳后裸眼视力能够达到1.0,那就是“假性近视”,在短期内能治愈,比如药物、针灸及理疗仪器等,都可放松肌肉,缓解疲劳,使视力恢复到正常状态。如不想治疗,只要经常眺望远方,注意休息,视力也有可能恢复。但是如果散瞳后裸眼视力低于0.8,就是“真性近视”了。真性近视眼一旦形成就不可逆转,它是眼球发生的器质性改变。眼球的前后轴变长,外界物象通过眼睛的屈光系统成像在视网膜前,视网膜上没有清晰的物象,当然就不会有良好的视力了。这种器质性改变除了手术外,任何方法都不能使眼球缩短、屈光度改变,这就是近视眼难以治愈的原因。目前屈光手术是唯一可治疗近视眼、降低屈光度的方法。

[转自http://bbs.hefei.cc/viewthread.php?tid=1109460]

2008-04-07

[转]10个世界著名的卡通形象

一、小熊维尼


喜爱这个憨态可掬的小熊,喜欢它的笨拙,喜欢嗜食蜂蜜,喜欢它的朋友--胆小的猪和同样胆小的虎。A·A·米那是英国著名的小说家,他以儿子克里斯多夫和玩具熊为主角出了两本童话书《Winnie-the Pooh(1926)Welcome the Pooh Comer(1928)其中出色的文字和插图,令小读者们一下爱上了小熊维尼。

小熊维尼档案:

●Pooh和朋友的历险故事发生在百亩林(hundred Acre Wood)

●Pooh的电视动画赢过奥斯卡奖(1968)和艾美奖(19891990)。

二、芭比


她是永远的大明星;她青春永驻;她有无数种身份和无数套衣服(当然价值不菲);她有经专家精心设计的三围和五官,她是所有女性的梦想。1959年,美国汉德尔太太制成第一个芭比娃娃,灵感来自女儿芭芭拉(小名芭比)的纸制洋娃娃,一经上市立即卖得火热。40多年来小女孩们通过玩芭比了解成人世界,竖立偶像。

芭比档案:

全名是Barbie Millicent Roberts

3姊妹,Skipper1964年出世)、Stacie(1992),男朋友是Ken1961年已相识,至今情比金坚,Ken有弟弟Tommy

1959年至今,Barbie拥有达10亿套时装及10亿双鞋。

共穿过45个国家或民族的服装。

三、巴特·辛普森


在美国,最受欢迎的电视动画片《辛普森一家》(港译《阿森一族》)已经播到了第10季。10年来,春田镇上的这个五口之家用他们荒诞的经历讽刺着当代美国社会的生活和文化。辛普森一家的形象随着电视剧的走红而成为世界性的流行符号,其中爱捣乱的长子巴特?辛普森已经成为一个大众偶像,连《时代》周刊也将他选为“20世纪演艺界最重要的人物之一。

其实巴特在动画片里只能算是令人头痛,捣个乱撒个谎,没事爱跟大人对着干,祸闯大了一样傻眼,这样的小孩世界上何止千千万万,不过当他被推到潮流前线,注册商标就变成了春田镇的坏男孩(Bad boy of Springfield)”,因为他的坏已经等同于的一面也被特别放大、突出,大家爱就爱他身上一股天不怕地不怕、我是小孩我怕谁的气质。

四、加菲猫


没有一只猫像它一样好吃、自私、贪婪、胆怯、市侩……它的生命中最大的乐趣就是吃和戏弄奥多狗和自己的主人,它就是个有缺点的普通人。

吉姆·戴维斯只为以狗为主角的漫画太多而不平,便创造了加菲。他将头脑中猫的特性结合祖父詹姆斯·加菲?戴维斯的个性,结果加菲因为漫画形象前所未有的人性化大受欢迎。

加菲猫档案:

出生日期:1978619

出生地点:Mama Leone 意大利餐厅厨房

出生体重:56安士

喜爱食物:意大利面条

喜爱饮品:咖啡

玩偶:啤啤熊Pooky

玩伴:Odie

最讨厌:蜘蛛、邮差

五、机器猫


这是藤子不二雄最经典的漫画,从1969年到1996年,机器猫红了整整27年。来自22世纪,它有一个四维空间袋和无数高科技法宝;它没有耳朵,全身发蓝;最怕老鼠,最爱红豆饼;它有一个比白痴稍强一丁点的主人、自己也不太聪明……可是,我爱机器猫,因为他代表了有难时能全心帮助你的朋友--不论它有没有这本事。

机器猫档案:

出生日期:公元211293

身高:129.3cm

体重:129.3kg

四围:上中下和头围均是129.3cm

马力:129.3

遇见老鼠时跳跃力:129.3cm

时速:每小时129.3公里

亲戚朋友:大雄、静宜、技安、牙擦仔、妹妹叮铃。

六、Kitty


Kitty是个很女性化的猫(就像加菲的男性化)她干净、温顺、乖巧、无害。

1974年,Sanrio设计师为小钱包设计了一只小白猫,她绑着一条红丝带,名叫Hello Kitty,天生一副明星相。一经出世,她就被印得哪儿都是,各种小文具、儿童用品、服装配饰上都有她的身影。

Kitty档案:

性格:又cute又温柔、上进有活力

出生:111,天蝎座

体重:3个苹果般重

身高:3个苹果直排

喜爱食物:苹果派

专长:火局 曲奇、运动和弹钢琴

嘴巴:没有,因为可以分享别人的感受

七、米老鼠


1928年,米奇诞生于火车上,这源于沃特?迪斯尼的一次心血来潮。刚出道时的米奇顽劣成性。可是随着时间的推移,米奇变成了一个形象可爱、性格温驯的绅士。而迪斯尼王国也由它开始了辉煌的历史。

如今,米奇的乐观善良已影响了整个美国乃至整个世界。人们都爱煞了这个整天傻笑的胖老鼠。

米老鼠档案:

米奇老鼠是于19281118初登银幕,电影名《Steamboat Willie》。

米奇老鼠是第一只商品化的卡通角色,时为1929年。同年,米奇老鼠拥有了Mickey Mouse Club

●1955年开始,米奇老鼠移居迪斯尼乐园做亲善大使,接待

中外名人不计其数。

八、史努比


10个世界著名的卡通形象

去年,史努比的创造者查尔斯·M·舒尔兹离开人世。而由于没有合适的继承者,伴随人们50年的史努比的故事也落了幕,令人不胜唏嘘。是呀,谁还能接手为这个有思想、有内涵的小狗注入新的生命,继续它的冷静,多愁善感,善解人意,而且从不认为自己是只狗?

史努比档案:

史努比的父亲曾于1989618连载的《花生》中出现过,提及它有8名子女,但至今只出现6名史努比家族成员,包括哥哥Spike、妹妹Belle、弟弟MarblesOlafAndy

●1970年,史努比雇用了一只季候鸟当秘书,便是胡士托。

史努比最讨厌的就是邻居的小猫WWLL

九、芝麻街

它们挑战着人类的传统美学。玩具设计大师Jim HensonFrankOz一同制作了《芝麻街》。60年代,泛世界观念的人们将一切人为界限打破,支持美的形式多种多样。1969年,一个义务教育团体Children's TelevisionWorkshopCTW)制作播出了《芝麻街》寓教于乐。一大帮怪兽通过不同人物的故事,藉唱歌、讲故事向孩子们软说教,形象自然深入人心。

十、泰迪熊


它的名字和走红得多谢一位总统--老罗斯福。1902年这位总统拒绝用枪射杀一只被当成靶子绑在树上的小熊,而成为有爱心的代表。而布鲁克林的一位文具店的老板因而触发灵感,将太太制作的两只小熊命名为Teddy(这是总统的昵称,当然毫无讽刺之意)并展示在橱窗内,谁知,这一下红了近百年。

泰迪熊自然粗糙的质感和呆板的眼神,可能是它惹人怜爱的原因。

泰迪熊档案:

三大名厂:德国Steiff、英国MerrythoughtHermann三大厂限量生产的Teddy Bear最富炒卖价值。

一世熊友:欧洲有在婴儿出生时送他一只小熊的传统,陪伴他成长,是他一生的朋友。



转自:网络蚯蚓~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

java解析xml

在这段代码中~~~~我解析的是海词提供的xml~~~~~~~~~~~~~运行环境是Eclipse~~~~~~~~~~不过在编码部分还存在一定的问题~~~~~~~~~有待努力~~~~~~~继续提高~~~~~~~~~~嘿嘿~~~~~~~~~~~~~~~

import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;

public class MyXMLReader extends DefaultHandler {

java.util.Stack tags = new java.util.Stack();

private String currentName;

private StringBuffer currentValue = new StringBuffer();

public MyXMLReader() {
super();
}

public void startElement(String uri, String localName, String qName,
Attributes attributes)

throws SAXException {

}

public void characters(char ch[], int start, int length)
throws SAXException {
System.out.println(new String(ch,start,length));
}

public void endElement(String uri, String localName, String qName) throws SAXException {

//props.put(qName.toLowerCase(), currentValue.toString().trim());

}



public static void main(String args[]) {
try {
SAXParserFactory sf = SAXParserFactory.newInstance();
SAXParser sp = sf.newSAXParser();
MyXMLReader reader = new MyXMLReader();
sp.parse(new InputSource("http://dict.cn/ws.php?q=stone"), reader);
} catch (Exception e) {
//e.printStackTrace();
}
}
}

[转]在Java中调用C语言生成的DLL文件

一、JAVA中所需要做的工作

在JAVA程序中,首先需要在类中声明所调用的库名称,如下:

static {

System.loadLibrary(“goodluck”);

}

在这里,库的扩展名字可以不用写出来,究竟是DLL还是SO,由系统自己判断。

还需要对将要调用的方法做本地声明,关键字为native。并且只需要声明,而不需要具体实现。如下:

public native static void set(int i);

public native static int get();

然后编译该JAVA程序文件,生成CLASS,再用JAVAH命令,JNI就会生成C/C++的头文件。

例如程序testdll.java,内容为:

public class testdll

{

static

{

System.loadLibrary("goodluck");

}

public native static int get();

public native static void set(int i);

public static void main(String[] args)

{

testdll test = new testdll();

test.set(10);

System.out.println(test.get());

}

}

用javac testdll.java编译它,会生成testdll.class。

再用javah testdll,则会在当前目录下生成testdll.h文件,这个文件需要被C/C++程序调用来生成所需的库文件。

二、C/C++中所需要做的工作

对于已生成的.h头文件,C/C++所需要做的,就是把它的各个方法具体的实现。然后编译连接成库文件即可。再把库文件拷贝到JAVA程序的路径下面,就可以用JAVA调用C/C++所实现的功能了。

接上例子。我们先看一下testdll.h文件的内容:

/* DO NOT EDIT THIS FILE - it is machine generated */

#include

/* Header for class testdll */

#ifndef _Included_testdll

#define _Included_testdll

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class: testdll

* Method: get

* Signature: ()I

*/

JNIEXPORT jint JNICALL Java_testdll_get

(JNIEnv *, jclass);

/*

* Class: testdll

* Method: set

* Signature: (I)V

*/

JNIEXPORT void JNICALL Java_testdll_set

(JNIEnv *, jclass, jint);

#ifdef __cplusplus

}

#endif

#endif

在具体实现的时候,我们只关心两个函数原型

JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass);

JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint);

这里JNIEXPORT和JNICALL都是JNI的关键字,表示此函数是要被JNI调用 的。而jint是以JNI为中介使JAVA的int类型与本地的int沟通的一种类型,我们可以视而不见,就当做int使用。函数的名称是JAVA_再加 上java程序的package路径再加函数名组成的。参数中,我们也只需要关心在JAVA程序中存在的参数,至于JNIEnv*和jclass我们一般没有必要去碰它。

好,下面我们用testdll.cpp文件具体实现这两个函数:

#include "testdll.h"

int i = 0;

JNIEXPORT jint JNICALL Java_testdll_get (JNIEnv *, jclass)

{

return i;

}

JNIEXPORT void JNICALL Java_testdll_set (JNIEnv *, jclass, jint j)

{

i = j;

}

编译连接成库文件,本例是在WINDOWS下做的,生成的是DLL文件。并且名称要与JAVA中需要调用的一致,这里就是goodluck.dll

把goodluck.dll拷贝到testdll.class的目录下,java testdll运行它,就可以观察到结果了。


转自:http://buttom2008.blog.163.com/blog/static/71449844200837511649/

缓冲区管理

//假设系统中有两个分别名为P1、P2的进程
//两台均可进行输入、输出操作的设备d1、d2
//两个进程可以从两台设备中的任何一台输入数据,并可以向其中的任何一台设备输出数据。

#include
#include
#include
#include
#include


#define NUMOFBUFFER 10
#define SIZEOFBUFFER 100
#define NO -1
#define MAX 200


struct buffer{ //系统中的缓冲区
int count; //缓冲区中现在的字符个数
char databuffer[SIZEOFBUFFER]; //数据区
struct buffer *p; //用作队列指针
}buf[NUMOFBUFFER];


typedef struct queue{ //队列
int buf[NUMOFBUFFER]; //保存队列中的元素
int front; //头指针
int rear; //尾指针
int currentSize; //当前长度
int maxSize; //最大长度
}SqQueue;


SqQueue emptyBuffer;
SqQueue outputOfDevice1;
SqQueue outputOfDevice2;
SqQueue inputOfDevice1;
SqQueue inputOfDevice2;


int mutex = 1;
int od1,od2,id1,id2;

int mistake = 0;


//初始化空队列
void InitEmptyQueue(SqQueue &L){
int i;
for(i = 0;i <>
L.buf[i] = i;
L.front = 0;
L.rear = 9;
L.currentSize = 10;
L.maxSize = NUMOFBUFFER;
}


//初始化队列
void InitQueue(SqQueue &L){
int i;
for(i = 0;i <>
L.buf[i] = NO;
L.front = 0;
L.rear = L.front - 1;
L.currentSize = 0;
L.maxSize = NUMOFBUFFER;
}


//P操作
void Pprocess(int source){
source --;
if(source <>
printf("Sorry.There is no empty buffer.Please wait.:-(\n");
mistake = 1;
}
}


//V操作
void Vprocess(int source){
source ++;
if(source > 0)
mistake = 0;
}


//入队
void EnQueue(SqQueue &L,int buf){
Pprocess(mutex);

if(L.currentSize == 0){
L.front = 0;
L.rear = -1;
}

if(L.rear == 9) //队满的情况已经在主函数中做过处理
L.rear = fmod(L.rear + 1,10);
else
L.rear ++;
L.buf[L.rear] = buf;
L.currentSize ++;

Vprocess(mutex);
}


//出队
int DeQueue(SqQueue &L){ //队空的情况已经在主函数中做过处理
int e;

Pprocess(mutex);

e = L.buf[L.front];
L.buf[L.front] = NO;
L.front ++;
L.currentSize --;

Vprocess(mutex);

return e;
}


//完成缓冲区和各个队列的初始化操作
void init(){

//缓冲区初始化操作
int i,j;
for(i = 0;i <>
buf[i].count = 0;
for(j = 0;j <>
buf[i].databuffer[j] = ' ';
buf[i].p = &buf[i + 1];
}

//各个队列的初始化操作
InitEmptyQueue(emptyBuffer);
InitQueue(outputOfDevice1);
InitQueue(outputOfDevice2);
InitQueue(inputOfDevice1);
InitQueue(inputOfDevice2);
}


//从空队列中取出一个缓冲区
int getBuffer(){
int index;
int size = emptyBuffer.currentSize;

Pprocess(size);

if(mistake != 1){
Pprocess(mutex); //对空缓冲区队列进行互斥操作
index = DeQueue(emptyBuffer);
Vprocess(mutex);
}

return index;
}


//空队列中放入一个缓冲区
void putBuffer(int index){
int size = emptyBuffer.currentSize;

Pprocess(mutex); //对空缓冲区队列进行互斥操作
EnQueue(emptyBuffer,index);
Vprocess(mutex);

Vprocess(size);
}


//输出内容,格式控制函数
void print(){
int i = 0,k = 0,index;

printf("...........................................\n");
printf("...........................................\n");

//显示空缓冲区队列
printf("emptyBuffer : ");
if(emptyBuffer.currentSize == 0 || mistake == 1)
printf("NULL");
else{
i = emptyBuffer.front;
do{
index = fmod((i+k),10);
printf("%d ",emptyBuffer.buf[index]);
k ++;
}while(k <>
}
putchar('\n');

//显示设备一的输出队列
printf("outputOfDevice1 : ");
if(outputOfDevice1.currentSize == 0)
printf("NULL");
else{
i = outputOfDevice1.front;
k = 0;
do{
index = fmod((i+k),10);
printf("%d ",outputOfDevice1.buf[index]);
k ++;
}while(k <>
}
putchar('\n');

//显示设备二的输出队列
printf("outputOfDevice2 : ");
if(outputOfDevice2.currentSize == 0)
printf("NULL");
else{
i = outputOfDevice2.front;
k = 0;
do{
index = fmod((i+k),10);
printf("%d ",outputOfDevice2.buf[index]);
k ++;
}while(k <>
}
putchar('\n');

//显示设备一的输入队列
printf("inputOfDevice1 : ");
if(inputOfDevice1.currentSize == 0)
printf("NULL");
else{
i = inputOfDevice1.front;
k = 0;
do{
index = fmod((i+k),10);
printf("%d ",inputOfDevice1.buf[index]);
k ++;
}while(k <>
}
putchar('\n');

//显示设备二的输入队列
printf("inputOfDevice2 : ");
if(inputOfDevice2.currentSize == 0)
printf("NULL");
else{
i = inputOfDevice2.front;
k = 0;
do{
index = fmod((i+k),10);
printf("%d ",inputOfDevice2.buf[index]);
k ++;
}while(k <>
}
putchar('\n');

printf("...........................................\n");
}


//设备选择显示函数
int withTools(){
char dc = getch();
if(dc == '1')
printf("device1.");
else{
if(dc == '2')
printf("device2.");
else
printf("error.");
}
putchar('\n');
printf("...........................................\n");
int tool = (int)dc - 48;
return tool;
}


//线程选择显示函数
int withType(){
int dc = getch();
if(dc == '1')
printf("thread1.");
else{
if(dc == '2')
printf("thread2.");
else
printf("error.");
}
putchar('\n');
printf("...........................................\n");
int type = (int)dc - 48;
return type;
}


//完成进程的数据处理.
//按照inputdev指定的设备号从该设备的输入队列中取出一个缓冲区;
//按照procnum的序号对缓冲区中的数据进行指定的数据处理操作;
//按照outputdev指定的设备号将缓冲区放入该设备的输出队列。
void process(int procnum,int inputdev,int outputdev){
int index;

switch (inputdev){
case 1:
id1 = inputOfDevice1.currentSize;
Pprocess(id1);
index = DeQueue(inputOfDevice1);
break;
case 2:
id2 = inputOfDevice2.currentSize;
Pprocess(id2);
index = DeQueue(inputOfDevice2);
break;
}

strupr(buf[index].databuffer); //小写字母转换成大写字母

switch (outputdev){
case 1:
od1 = outputOfDevice1.currentSize;
EnQueue(outputOfDevice1,index);
Vprocess(od1);
break;
case 2:
od2 = outputOfDevice2.currentSize;
EnQueue(outputOfDevice2,index);
Vprocess(od2);
break;
}

printf("thread: %d---inputdevice: %d---outputdevice: %d\n",procnum,inputdev,outputdev);
print();
}


//完成设备的读写操作.其中参数devnum指出需要进行I/O操作的设备,flag为操作类型
void deviceReadAndWrite(int devnum,int flag){
int index;
char input[SIZEOFBUFFER];

if(flag == 1){ //读操作
index = getBuffer(); //从空队列中取出一个缓冲区
if(mistake == 1){
printf("You must make a full buffer empty.:-(\n");
goto lab;
}
else{
printf("Please input some letters : ");
scanf("%s",input);
strcpy(buf[index].databuffer,input); //从终端读入一行字符串,放入缓冲区的数据区
buf[index].count = strlen(input);
if(devnum == 1){ //按照指定的设备号将缓冲区放入相应的设备输入队列
id1 = inputOfDevice1.currentSize;
EnQueue(inputOfDevice1,index);
Vprocess(id1);
}
else{
id2 = inputOfDevice2.currentSize;
EnQueue(inputOfDevice2,index);
Vprocess(id2);
}
}
}
else{ //写操作
if(devnum == 1){
od1 = outputOfDevice1.currentSize;
Pprocess(od1); //p(od1)
index = DeQueue(outputOfDevice1); //按照指定的设备号,从设备的输出队列中取出一个装满数据的缓冲区
printf("The contents of this buffer is : ");
printf("%s\n",buf[index].databuffer); //将缓冲区中的数据在终端上显示
putBuffer(index); //将空缓冲区放入空缓冲区队列
}
if(devnum == 2){
od2 = outputOfDevice2.currentSize;
Pprocess(od2); //p(od2)
index = DeQueue(outputOfDevice2); //按照指定的设备号,从设备的输出队列中取出一个装满数据的缓冲区
printf("The contents of this buffer is : ");
printf("%s\n",buf[index].databuffer); //将缓冲区中的数据在终端上显示
putBuffer(index); //将空缓冲区放入空缓冲区队列
}
}

lab:
print();
}


//代码使用控制函数
void getIn(){
char password[7] = {'0','5','2','2','2','6'};
char input[10];
int i = 0;

printf("-------------------------------------------\n");
printf("-------------------------------------------\n");


printf("Password : ");
char c = getch();

while(c != '*'){
input[i] = c;
i ++;
putchar('*');
c = getch();
}
input[i] = '\0';
putchar('\n');

if(strcmp(password,input) != 0){
printf("You do not have the right to use this code. :-(\n");
exit(0);
}

printf("-------------------------------------------\n");
printf("-------------------------------------------\n");
}


//模式选择函数
int printTip(){
printf("This code support three work models : \n");
printf("A.input B.output C.deal D.exit \n");
printf("Please choose : ");
char c = getch();
int model;

switch(c){
case 'A':
printf("input.\n");
model = 1;
break;
case 'B':
printf("output.\n");
model = 2;
break;
case 'C':
printf("deal.\n");
model = 3;
break;
case 'D':
printf("exit.\n");
model = 4;
break;
}
printf("...........................................\n");
return model;
}


//判断输出队列是否为空
int judgeOutput(int tool){
int emp; //0非空1空

switch (tool){
case 1:
if(outputOfDevice1.currentSize == 0)
emp = 1;
else
emp = 0;
break;
case 2:
if(outputOfDevice2.currentSize == 0)
emp = 1;
else
emp = 0;
break;
}
return emp;
}


//判断输入队列是否为空
int judgeInput(int tool){
int emp; //0非空1空
switch (tool){
case 1:
if(inputOfDevice1.currentSize == 0)
emp = 1;
else
emp = 0;
break;
case 2:
if(inputOfDevice2.currentSize == 0)
emp = 1;
else
emp = 0;
break;
}
return emp;
}


//判断输入队列是否为满
int judgeInputFull(int tool){
int full; //0非满1满
switch (tool){
case 1:
if(inputOfDevice1.currentSize == 10)
full = 1;
else
full = 0;
break;
case 2:
if(inputOfDevice2.currentSize == 10)
full = 1;
else
full = 0;
break;
}
return full;
}


//判断输出队列是否为满
int judgeOutputFull(int tool){
int full; //0非满1满
switch (tool){
case 1:
if(outputOfDevice1.currentSize == 10)
full = 1;
else
full = 0;
break;
case 2:
if(outputOfDevice2.currentSize == 10)
full = 1;
else
full = 0;
break;
}
return full;
}


void main(){
void InitEmptyQueue(SqQueue &L);
void InitQueue(SqQueue &L);
void EnQueue(SqQueue &L,int buf);
int DeQueue(SqQueue &L);
void init();
int getBuffer();
void putBuffer(int index);
void print();
int withTools();
int withType();
void process(int procnum,int inputdev,int outputdev);
void Pprocess(int source);
void Vprocess(int source);
void deviceReadAndWrite(int devnum,int flag);
void getIn();
int printTip();
int judgeOutput(int tool);
int judgeInput(int tool);
int judgeInputFull(int tool);
int judgeOutputFull(int tool);

int tool,thrd,model,tools;

getIn();
printf("Initiate : \n");
init();
print();

do{
model = printTip();
switch(model){
case 1: //输入
do{
printf("1:device1 2:device2\nPlease choose : ");
tool = withTools();
if(judgeInputFull(tool) == 1){ //判断输入队列是否为满
printf("The list of inputDevice%d is full.:-(\n",tool);
printf("Please input again.\n");
}
}while(judgeInputFull(tool) == 1);
deviceReadAndWrite(tool,model);
break;
case 2: //输出
do{
printf("1:device1 2:device2\nPlease choose : ");
tool = withTools();
if(judgeOutput(tool) == 1){ //判断输出队列是否为空
printf("The list of outputOfDevice%d is empty.:-(\n",tool);
printf("Please input again.\n");
}
}while(judgeOutput(tool) == 1);
deviceReadAndWrite(tool,model);
break;
case 3: //数据处理
printf("1:thread1 2:thread2\nPlease choose : ");
thrd = withType();
do{
printf("1:device1 2:device2\nThe device of input : ");
tool = withTools();
if(judgeInput(tool) == 1){ //判断输入队列是否为空
printf("The list of input of device%d is empty.:-(\n",tool);
printf("Please input again.\n");
}
}while(judgeInput(tool) == 1);
do{
printf("1:device1 2:device2\nThe device of output : ");
tools = withTools();
if(judgeOutputFull(tool) == 1){ //判断输出队列是否为满
printf("The list of output of device%d is full.:-(\n",tool);
printf("Please input again.\n");
}
}while(judgeOutputFull(tool) == 1);
process(thrd,tool,tools);
break;
case 4: //退出
break;
}
}while(model != 4);

printf("...........................................\n");
printf("...........................................\n");
printf("Thank you for using by 052226.:-)\n");
}