main.c

来自「GPRS打电话」· C语言 代码 · 共 130 行

C
130
字号
#include<stdio.h>
#include<stdlib.h>
#include<pthread.h>
#include<unistd.h>

#include "sem.h"
#include "term.h"
#include "option.h"

gprs_status=1;
int calling=0;
void introduce()
{
	printf("s----send a message\n");
	printf("r----read a unread message \n");
	printf("o----open a message\n");
	printf("c----take a call\n");
	if(calling)
		printf("h----halt the call\n");
	printf("q----quit \n");
	printf("Plesase Input You action:");
}

int get_answer(char *answer)
{
	introduce();
	fgets(answer,sizeof(answer),stdin);
	return answer[0];
}

int *SMSthread(void *arg)
{
	int fd;
	printf("SMSthread is running...\n");
	do
	{
		fprintf(stderr,"SMSthread:\n");
		receSMS(fd);
		sleep(1);
	}while(gprs_status);
	return 0;
}

int *CGQthread(void *arg)
{
	return 0;
}

int main(int argc,char *argv[])
{
	pthread_t SMSthid,CGQthid;
	int status;
	char *telno="13403167149";
//	char *telno="10086";
	char *sm="Hello";
	int fd;

	char answer[100];
	char a;
	int number;

	int opt;
	int err=0;

	gprsid=semget((key_t)1234,1,0666|IPC_CREAT);
	if(!set_semvalue(gprsid,1))
	{
		fprintf(stderr,"%s","set_semvalue gprsid failed\n");
	}

	while((opt = getopt(argc,argv,"dh")) != -1)
	{
		switch (opt) 
		{
			case 'd':
				gprs_debug_on = 1;
				break;
			default:
				err = 1;
				break;
		}
		if(err)
		{
			exit(-1);
		}
	}

	pthread_create(&SMSthid,NULL,SMSthread,NULL);
	pthread_join(SMSthid,(void *) &status);
	printf("Main is exit!!!\n");
/*
	while((a=get_answer(answer))!='q'||a!='Q')
	{
		switch (a)
		{
			case 's':
			case 'S':
				sendSMS(fd,telno,sm);
				break;
			case 'r':
			case 'R':
				receSMS(fd);
				break;
			case 'o':
			case 'O':
				printf("plese input the number of the message:");
				scanf("%d",&number);
				readSMS(fd,number);
				break;
			case 'c':
			case 'C':
				callph(fd,telno);
				calling=1;
				break;
			case 'h':
			case 'H':
				calling=0;
				haltph(fd);
				break;
			case 'q':
			case 'Q':
				return 0;
			default:
				printf("wrong!!!\n");
		}
	}
*/
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?