int main(){
	char* buffer;
	double pi = 3.14159;

	strCpy(buffer,salutation);
	// Some other stuff
	return 0;
}
Ejemplo n.º 2
0
Archivo: lstring.c Proyecto: ddakhane/c
/* foldcmp: fold upper and lower case together */
int foldcmp(const char *s1, const char *s2)
{
	char *x, *y;
	int i;

	x = alloc(strLen(s1) + 1);
	y = alloc(strLen(s2) + 1);
	strCpy(x, s1);
	strCpy(y, s2);

	upperstring(x);
	upperstring(y);
	i = strCmp(x, y);

	afree(x);
	afree(y);
	return i;
}
Ejemplo n.º 3
0
/*
 * MSDOSparse()
 *
 * This parses a string designating a file.
 */
void MSDOSparse(char *theDir, char *drive)
{
    if (theDir[1] == ':') {
	*drive = toUpper(theDir[0]);
	strCpy(theDir, theDir+2);
    }
    else {
	*drive = locDisk;
    }
}
Ejemplo n.º 4
0
/*
 * sysSendFiles()
 *
 * This is the system dep stuff for sending files.
 */
void sysSendFiles(struct fl_send *sendWhat)
{
    char   temp[100], *last;
    label  mask;

    strCpy(temp, sendWhat->snArea.naDirname);
    switch (fileType(sendWhat->snArea.naDirname, sendWhat->snArea.naDisk)) {
	case IS_DIR:
	    strCpy(mask, ALL_FILES);
	    break;
	case SINGLE_FILE:
	case AMB_FILE:
	    if ((last = strrchr(temp, '\\')) == NULL) {
		strCpy(mask, temp);
		temp[0] = 0;
	    }
	    else {
		strCpy(mask, last + 1);
		if (last != temp)
		    *last = 0;
		else
		    *(last + 1) = 0;
	    }
	    break;
	case NO_IDEA:
	default:
	    sprintf(temp, "Send File: Couldn't do anything with '%s'.",
					sendWhat->snArea.naDirname);
	    netResult(temp);
	    return;
    }
    if (!realSetSpace(toUpper(sendWhat->snArea.naDisk)-'A', temp)) {
	sprintf(msgBuf.mbtext, "Send file: Don't know what to do with %c:%s.",
				sendWhat->snArea.naDisk, temp);
	netResult(msgBuf.mbtext);
    }
    else
	wildCard(netSendFile, mask, "", WC_NO_COMMENTS);
    homeSpace();
}
Ejemplo n.º 5
0
int main(){
	str_t *s = strNew("Testing");
	str_t *s2 = strNew(" this thing \n");
	str_t *s3 = strNew(NULL);

	strCat(s, s2);
	strCpy(s3, s);
	strAppend(s3, "aaaaa");
	printf("%lu, %lu, %lu %s\n", s->len, s->size, strlen(s->str), s->str);
	printf("%lu, %lu, %lu %s\n", s3->len, s3->size, strlen(s3->str), s3->str);

	str_t *c = strNew("testing");

	strCpy(s, c);
//	strCpy(s2, c);
	printf("compare: %d\n", strCmp(s, s2));

	strDel(s);
	strDel(s2);
	strDel(s3);
	return 0;
}
Ejemplo n.º 6
0
/*
 * sysGetSendFilesV2()
 *
 * This function figures out where to find files to send to another system.
 */
char sysGetSendFilesV2(MenuId id, char *name, struct fl_send *sendWhat)
{
    strCpy(sendWhat->snArea.naDirname, name);

    MSDOSparse(sendWhat->snArea.naDirname, &sendWhat->snArea.naDisk);
    if (fileType(sendWhat->snArea.naDirname,
		sendWhat->snArea.naDisk) == NO_IDEA) {
	if (SysopGetYesNo(id, "",
			"Neither file nor directory found. Send anyways"))
	    return TRUE;
	return FALSE;
    }
    return TRUE;
}
Ejemplo n.º 7
0
/*
 * updFiletag()
 *
 * This function updates a file tag.
 */
void updFiletag(char *fileName, char *desc)
{
    FILE	*updFd, *temp;
    char	*line, *c, *l2, abort = FALSE;
    static char *tmpName = "a45u8a7.$$$",
		*format  = "%s %s\n";

    if ((updFd = fopen(flDir, READ_TEXT)) == NULL) {
	if ((updFd = fopen(flDir, WRITE_TEXT)) == NULL)
	    mPrintf("Unknown problem with filetagging!\n ");
	else {
	    fprintf(updFd, format, fileName, desc);
	    fclose(updFd);
	}
	return;
    }
    else {
	line = strdup(msgBuf.mbtext);
	l2 = strdup(desc);		/* necessary -- desc == mbtext! */
	temp = fopen(tmpName, WRITE_TEXT);
	msgBuf.mbtext[0] = 0;
	while ((c=fgets(msgBuf.mbtext, MAXTEXT, updFd)) != NULL) {
	    if (msgBuf.mbtext[0] != ';')
		if (specCmpU(fileName, msgBuf.mbtext) <= SAMESTRING) break;
	    if (fprintf(temp, "%s", msgBuf.mbtext) == EOF)
		abort = TRUE;
	}
	if (fprintf(temp, format, fileName, l2) == EOF)
	    abort = TRUE;

	if (c != NULL && specCmpU(fileName, msgBuf.mbtext) != SAMESTRING)
	    if (fprintf(temp, "%s", msgBuf.mbtext) == EOF)
		abort = TRUE;

	while ((c=fgets(msgBuf.mbtext, MAXTEXT, updFd)) != NULL)
	    if (fprintf(temp, "%s", msgBuf.mbtext) == EOF)
		abort = TRUE;

	fclose(updFd);
	fclose(temp);
	if (!abort) {
	    unlink(flDir);
	    rename(tmpName, flDir);
	}
	strCpy(msgBuf.mbtext, line);
	free(line);
	free(l2);
    }
}
Ejemplo n.º 8
0
/*
 * PersonExists()
 *
 * This function will check to see if the given name is valid for mail.
 *
 * This includes special processing for "Sysop" and "Citadel".
 */
int PersonExists(char *name)
{
	int result;
	logBuffer temp;

	if ((strCmpU("Citadel", name) == SAMESTRING && HalfSysop()) ||
		             strCmpU("sysop", name) == SAMESTRING)
		return cfg.MAXLOGTAB;       /* signals special string */

	initLogBuf(&temp);
	result = findPerson(name, &temp);
	if (result != ERROR) strCpy(name, temp.lbname);
	killLogBuf(&temp);
	return result;
}
Ejemplo n.º 9
0
main(){
       char ori[100];
       
       printf("Digite um letra: ");
       scanf("%s",&ori);
       
       char des[100];
       printf("Digite um letra: ");
       scanf("%s",&des);
       
       strCpy(des,ori);
       printf("%s , %s",des,ori);
        
       
       getch();
       }
Ejemplo n.º 10
0
/*
 * RoomLeft()
 *
 * Just how much room left in this area, anyways?
 * NB: Returns in K, not bytes!
 */
long RoomLeft(int room)
{
    char *temp, dir[150], drive;
    long temp3, temp2;
    long toReturn;

    /* this should never happen, but just in case ... */
    if ((temp = FindDirName(room)) == NULL)
	return 0;

    strCpy(dir, temp);
    MSDOSparse(dir, &drive);
    diskSpaceLeft(drive, &temp3, &temp2);
    toReturn = temp2 / 1024l;
    return toReturn;
}
Ejemplo n.º 11
0
Archivo: lines.c Proyecto: ddakhane/c
/* readlines: read input lines */
int readlines(char *lineptr[], int maxlines)
{
	int len, nlines;
	char *p, line[MAXLEN];

	nlines = 0;
	while ((len = getLine(line, MAXLEN)) > 0)
		if (nlines >= maxlines || (p = alloc(len)) == NULL)
			return -1;
		else {
			line[len-1]	= '\0';	/* delete newline */
			strCpy(p, line);
			lineptr[nlines++] = p;
		}
	return nlines;
}
Ejemplo n.º 12
0
/*
 * SetSpace()
 *
 * This moves us to an area associated with the specified room.
 */
char SetSpace(char *area)
{
    char   dir[150], drive;

    if (area == NULL) {
	mPrintf("?Directory not present! (internal error)\n ");
	return FALSE;
    }
    strCpy(dir, area);
    MSDOSparse(dir, &drive);
    if (!realSetSpace(toUpper(drive) - 'A', dir)) {
	mPrintf("?Directory not present!\n ");
	return FALSE;
    }
    return TRUE;
}
Ejemplo n.º 13
0
main()
{
	char a1[] = "hello";
	char b1[] = "goodbye";

	e(a1,b1);

	printf("a1=%s.\n", a1);
	printf("b1=%s.\n", b1);

	char a2[] = "hello";
	char b2[] = "goodbye";

	strCpy(a2,b2);

	printf("a2=%s.\n", a2);
	printf("b2=%s.\n", b2);
}
Ejemplo n.º 14
0
char * rplCatch( char * newStr, const char * rplStr, const int id ){
  char *oNewStr = newStr;
  const char *last = Catch.ptr[ 0 ];

  for( int index = 1, rpLen = strLen( rplStr ); index < Catch.index; index++ )
    if( id == Catch.id[ index ] ){
      if( last > Catch.ptr[index] ) last = Catch.ptr[index];

      strnCpy( newStr, last, Catch.ptr[index] - last );
      newStr += Catch.ptr[index] - last;
      strCpy( newStr, rplStr );
      newStr += rpLen;
      last    = Catch.ptr[index] + Catch.len[index];
    }

  strnCpy( newStr, last, Catch.ptr[0] + Catch.len[0] - last );
  return oNewStr;
}
Ejemplo n.º 15
0
int main() {
	static char message[20] = "Salut";
	static char ch2[] = "hello";
	static char ch1[] = "hi";
	printf("\nEntrez un message\n");
	getS(message,25);
	printf("\nAffichage message : ");
	putS(message);
	strCpy(ch2,ch1);
	printf("\nAffichage message apres copy de hi dans hello: ");
	putS(ch2);
	printf("%d",strLen("Plop8"));
	printf("\nstrCmp1 : %d",strCmp("plop","plop"));
	printf("\nstrCmp2 : %d",strCmp("ABCD","ABEFG"));
	printf("\nstrCmp3 : %d",strCmp("plop","plo"));
	printf("\nstrCat : ");
	strCat(message," Denis");
	putS(message);
}
Ejemplo n.º 16
0
int main() {
   char str[80];
   char str1[80];
   char *ptr;
   int len;
   printf("input string: ");
   gets(str);
   printf("原始字串: \"%s\"\n", str);
   len = strLen(str);
   printf("字串\"%s\"的長度為: %d\n", str, len);
   printf("複製字串: \"%s\"\n", strCpy(str1, str));
   printf("請輸入欲連接的字串: ");
   gets(str1);
   printf("欲連接字串: \"%s\"\n", str1); 
   ptr = strCat(str, str1);       
   printf("連接結果的字串: \"%s\"\n", ptr);
   printf("請輸入欲比較的字串: ");
   gets(str1);
   printf("欲比較的字串: \"%s\"\n", str1);
   printf("字串比較結果: %d\n", strCmp(str, str1));
}
boolean esp8266GetIP(char *buf)
{
	INT8U err;
	char *str;
	boolean result;
	
	result = FALSE;
	esp8266RxBufferFlash();
	usart0Print("AT+CIFSR\r\n");
	while (1) {
		err = usart0Read(&str, ESP8266_SHORT_TIMEOUT);
		if (err == OS_ERR_TIMEOUT || strCmp(str, "OK")) {
			break;
		} else if (*str >= '0' && *str <= '9') {
			if (!strCmp(str, "192.168.4.1")) {
				strCpy(str, buf);
				result = TRUE;
			}
		}
	}
	return result;
}
Ejemplo n.º 18
0
int main(){
	FILE *fp;
	fp = NULL;
	int count = 0, i;
	char line[100];
	int n;
	char lines[100][150];
	fp = fopen("Readme.txt", "r");
	if (fp != NULL){
		printf("Enter no. of line to be printed\n");
		scanf("%d", &n);
		while (fgets(line, 150, fp) != NULL){
			strCpy(lines[count],&line);
			count++;
		}
		fclose(fp);
		for (i = count - n ; i < count; i++){
			printf("%s", lines[i]);
		}
	}

	getchar();
}
Ejemplo n.º 19
0
/*
 * goodArea()
 *
 * This will get a valid path from the sysop. Drive should be set already.
 */
static goodArea(MenuId id, char *prompt, char *dir, char *drive)
{
    int  c;
    char dir_x[150], *dft;

    while (TRUE) {
	if (roomBuf.rbflags.ISDIR)
	    dft = FindDirName(thisRoom);
	else
	    dft = ourHomeSpace;

	if (!getXInternal(id, prompt, dir_x, 149, dft, dft))
	    return FALSE;

	MSDOSparse(dir_x, drive);
	c = fileType(dir_x, *drive);

	if (CheckArea(id, c, drive, dir_x)) {
	    strCpy(dir, dir_x);
	    return TRUE;
	}
    }
}
Ejemplo n.º 20
0
/*
 * logMessage()
 *
 * This function puts messages in the CALLLOG.SYS file depending on a number
 * of different events and conditions.
 */
void logMessage(int typemessage, UNS_32 val, int flags)
{
    static int oldDay = 0;
    FILE *fd;
    int  yr, dy, hr, mn, rover;
    char *mon, buf[100];
    char *format = "%s %s @ %d:%02d%s";
    char *SaveName = "callsave.sys";

    if (CallCrash) return;

    if (typemessage == BAUD || typemessage == DOOR_RETURN) {
	BaudRate = val;
    }

    if (cfg.Audit == 0) return;

    makeAuditName(CallFn, "calllog.sys");

    getCdate(&yr, &mon, &dy, &hr, &mn);
    switch (typemessage) {
	case SET_FLAG:
		lgin.flags |= flags;
		break;
	case FIRST_IN:
		oldDay = dy;
		sprintf(buf, format, "System brought up", formDate(), hr, mn,
									"");
		CallMsg(CallFn, buf);
		break;
#ifndef NO_DOORS
	case DOOR_RETURN:
		oldDay  = dy;
		if ((fd = fopen(SaveName, READ_ANY)) != NULL) {
		    fread(&lgin, sizeof lgin, 1, fd);
		    fclose(fd);
		    unlink(SaveName);
		}
		else printf("No luck with %s.", SaveName);
		break;
#endif
	case CRASH_OUT:
	case LAST_OUT:
		sprintf(buf, format, "System brought down", formDate(), hr, mn,
			(typemessage == CRASH_OUT) ? " (crash exit!)" : "");
		CallMsg(CallFn, buf);
		return;
#ifndef NO_DOORS
	case DOOR_OUT:
		if ((fd = fopen(SaveName, WRITE_ANY)) != NULL) {
		    fwrite(&lgin, sizeof lgin, 1, fd);
		    fclose(fd);
		}
		else printf("No luck with %s.", SaveName);
		break;
#endif
	case BAUD:
		lgin.person[0] = 0;
		lgin.flags = 0;
		goto datestuff;		/* ACK!  ACK!  ACK! */
	case L_IN: 
		strCpy(lgin.person, logBuf.lbname);
		lgin.flags = flags;
	case INTO_NET:
datestuff:
		lgin.year = yr;
		lgin.day = dy;
		lgin.hour = hr;
		lgin.minute = mn;
		strcpy(lgin.month, mon);
		break;
	case CARRLOSS:
		homeSpace();	/* back to our regular lair, don't break! */
	case L_OUT:
		lgin.flags |= flags;
		/*
		 * BaudRate > 0 means the user is on the system console.
		 * So this code means "If no person is logged in and
		 * Anonymous session logging is off OR the anonymous user
		 * was at the system console ..."
		 */
		if (!lgin.person[0] &&
			!(cfg.BoolFlags.AnonSessions && BaudRate > 0)) {
		    break;
		}

		if (lgin.lastuserday != dy && lgin.lastuserday != 0)
		    CallMsg(CallFn, "");

		lgin.lastuserday = dy;

		sprintf(buf,
			"%-22s: %2d%s%02d %2d:%02d - %2d:%02d ",
			(strLen(lgin.person)) ? lgin.person : "<No Login>",
			lgin.year, lgin.month, lgin.day, lgin.hour, lgin.minute,
			hr, mn);

		switch (BaudRate) {
		case (UNS_32) 0:
			strcat(buf, "(sysConsole)");
			break;
		case (UNS_32) -1:
			strcat(buf, "(Unknown)");
			break;
		default:
			sprintf(lbyte(buf), "(%ld)", BaudRate);
		}

		for (rover = 0; rover < NumElems(Flags); rover++) {
			if (lgin.flags & Flags[rover].flag)
				sprintf(lbyte(buf), " %c", Flags[rover].val);
		}

		CallMsg(CallFn, buf);

		lgin.person[0] = 0;
		oldDay = dy;
		if (typemessage == CARRLOSS) BaudRate = 0l;
		goto datestuff;
	case OUTOF_NET:
		if (cfg.Audit == 1) {
		    sprintf(buf,
			"System in network mode: %d%s%02d %2d:%02d - %2d:%02d",
			lgin.year, lgin.month, lgin.day, lgin.hour,
			lgin.minute, hr, mn);
		    CallMsg(CallFn, buf);
		}
		break;

	default: printf("crashout: unknown case in switch statement");
    }
}
Ejemplo n.º 21
0
void traiterDataGPS(void){
	int i,j,chk;

	i = 0;
	while(i<lengthWaitBuffer){
		//avencée vers le premier $
		while(i<lengthWaitBuffer && waitBuffer[i]!='$') i++;
		// waitBuffer[i+1] contient le début des données de la trames

		//calcul du checksum
		j = i+1;
		chk = 0;
		while(j<lengthWaitBuffer && waitBuffer[j]!='*'){
			chk ^= waitBuffer[j];
			j++;
		}

		//trame valide ?
		if((j+3 < lengthWaitBuffer) && (chk == hexToInt(waitBuffer+j+1,2))){
			waitBuffer[j+3] = 0;
			if(!strCmp(waitBuffer+i,"$GPGGA")){
				i += 7;
				i += strCpy(gps_UTCPos, waitBuffer+i, 10) + 1;

				i += strCpy(gps_Latitude, waitBuffer+i, 9) + 1;
				i += strCpy(gps_NSind, waitBuffer+i, 1) + 1;
				i += strCpy(gps_Longitude, waitBuffer+i, 10) + 1;
				i += strCpy(gps_EWind, waitBuffer+i, 1) + 1;

				i += strCpy(gps_PosFixInd, waitBuffer+i, 1) + 1;
				i += strCpy(gps_SatUsed, waitBuffer+i, 2) + 1;
				i += strCpy(gps_HDOP, waitBuffer+i, 16) + 1;

				i += strCpy(gps_Altitude, waitBuffer+i, 16) + 1;
				i += strCpy(gps_AltUnit, waitBuffer+i, 16) + 1;
			}
			else if(!strCmp(waitBuffer+i,"$GPRMC")){
				i += 7;
				i += strCpy(gps_UTCPos, waitBuffer+i, 10) + 1;
				i += strCpy(gps_Status, waitBuffer+i, 1) + 1;

				i += strCpy(gps_Latitude, waitBuffer+i, 9) + 1;
				i += strCpy(gps_NSind, waitBuffer+i, 1) + 1;
				i += strCpy(gps_Longitude, waitBuffer+i, 10) + 1;
				i += strCpy(gps_EWind, waitBuffer+i, 1) + 1;

				i += strCpy(gps_SpeedOverGround, waitBuffer+i, 16) + 1;
				i += strCpy(gps_CourseOverGround, waitBuffer+i, 16) + 1;
				i += strCpy(gps_Date, waitBuffer+i, 6) + 1;
			}
		}
		i++;
	}

	lengthWaitBuffer = 0;
}
Ejemplo n.º 22
0
void initGPS(void){
	float x=0;
	float dist = 0;

	strCpy(gps_UTCPos,"-",10);
	strCpy(gps_Latitude,"-",9);
	strCpy(gps_NSind,"-",1);
	strCpy(gps_Longitude,"-",10);
	strCpy(gps_EWind,"-",1);
	strCpy(gps_PosFixInd,"-",1);
	strCpy(gps_SatUsed,"-",2);
	strCpy(gps_HDOP,"-",16);
	strCpy(gps_Altitude,"-",16);
	strCpy(gps_AltUnit,"-",16);

	strCpy(gps_Status,"-",1);
	strCpy(gps_SpeedOverGround,"-",16);
	strCpy(gps_CourseOverGround,"-",16);
	strCpy(gps_Date,"-",6);

	iBuff0 = 0;
	iBuff1 = 0;
	useBuffer = 0;
	lengthWaitBuffer = 0;

	destination = 0;
	coordConv(destCoord,"4713,0000","N","00133,0000","W");   // Nantes
	coordConv(destCoord+1,"4313,9450","N","00526,6233","E"); // Polytech luminy
/*	coordConv(destCoord+2,"4314,9500","N","00526,9633","E"); // Vaufrege*/
	coordConv(destCoord+2,"4422,0000","N","00856,0000","E"); // Genova
/*	coordConv(destCoord+3,"4313,6316","N","00526,3333","E"); // Crous*/
	coordConv(destCoord+3,"4122,0000","N","00211,0000","E"); // Barcelone

	setENABLE_GPS(1);
	initTimer_A();
	setFuncTimer_A(&vidageBuffer);
	setTimer_A(1);

	setFuncRx0(&RxBuff0);
	connectGPS(1);

/*	dist = distance(destCoord+1, destCoord+1);

	// Nantes -> Marseille 		128
	dist = distance(destCoord, destCoord+1);
	x = cap2(destCoord, destCoord+1,dist);
	
	// Genova -> Marseille		246
	dist = distance(destCoord+2, destCoord+1);
	x = cap2(destCoord+2, destCoord+1,dist);

	// Barcelone -> Marseille	51
	dist = distance(destCoord+3, destCoord+1);
	x = cap2(destCoord+3, destCoord+1,dist);

	// Marseille -> Nantes		311
	dist = distance(destCoord+1, destCoord);
	x = cap2(destCoord+1, destCoord,dist);

	x++;*/
}
Ejemplo n.º 23
0
int main(){
	char **a;
	char **userNo;
	char **textContent;
	int textContentCounter = 0;
	int userNoCounter;

	DDRB = 0xFF;
	DDRD = 0b11111100;
	DDRC = 0xFF;
	DDRA = 0x00;
	PORTA = 0x00;

	initLCD();
	USART_Init(78);
	sei();
	/************************* display Init message ********************/
	LCDClear();
	LCDPrint ("uC working");
	_delay_ms(1000);
	/*******************************************************************/

	/****************************** GSM INIT ***************************/
	okComplete = 0;
	sendATCommand("at");
	while (okComplete == 0);

	if (okComplete == 1) {
		/************** GSM initilization success ******************/
		LCDClear();
		LCDPrintLines ("GSM init.:", "successful");
		/***********************************************************/

		/****** Check for EEPROM value and reset it ****************/
		/***********************************************************/
	}else {
		/************ GSM unsuccessful in initilization *************/
		LCDClear();
		LCDPrintLines ("GSM init.:", "failure");
		_delay_ms(1000);
		LCDClear();
		LCDPrint ("System Halting...");
		while (1);
		/************************************************************/
	}
	_delay_ms(1000);
	okComplete = 0;
	sendATCommand("at+cmgda=\"DEL ALL\"");
	while (okComplete == 0);
	if (okComplete == 1){
		LCDPrintLines ("message Delete",  "successful");
	} else if (okComplete == 2) {
		LCDPrintLines ("can't del. msg.", "system halting...");
		while (1);
	}
	_delay_ms(1000);
	okComplete = 1;
	/*******************************************************************/

	whatIsGoingOn = NOTHING;
	bufferCount = 0;
	while (1){
		if (okComplete == 1){
			//OK received
			LCDClear();
			if (whatIsGoingOn == NOTHING){
				LCDPrintLines("Vending Machine", "Code: vm001");
			} else if (whatIsGoingOn == MESSAGE_SEND_SUCCESSFULLY){
				LCDPrintLines("Product Dropped", "Thank You");
			} else if (whatIsGoingOn == ERRORV){
				LCDPrintLines ("Last Message:", "vmCode invalid");
			} else if (whatIsGoingOn == ERRORP){
				LCDPrintLines ("Last Message:", "itemCode invalid");
			} else if (whatIsGoingOn == ERRORR){
				LCDPrintLines ("Last Message:", "5 Retries Error");
			} else if (whatIsGoingOn == ERRORO){
				LCDPrintLines ("Last Message:", "Overfall");
			} else if (whatIsGoingOn == ERRORA){
				LCDPrintLines ("Last Message:", "unavail. product");
			} else if (whatIsGoingOn == ERRORPA){
				LCDPrintLines ("Last Message:", "und. pinCode len");
			}
			_delay_ms(1000);
			if (whatIsGoingOn != NOTHING){
				whatIsGoingOn = NOTHING;
				okComplete = 1;
			} else {
				okComplete = 0;
			}
		} else if (okComplete == 2){
			//ERROR Received
			LCDClear();
			LCDPrint ("Error Received");
			_delay_ms(1000);

			okComplete = 1;
		}else if (msgReceived == 1){
			//=CMTI Received
			LCDClear();
			LCDPrint ("msg rec @: ");

			if (msgNumber1 == 255){
				LCDData ((char)msgNumber);
			} else {
				LCDData ((char)msgNumber);
				LCDData ((char)msgNumber1);
			}

			/******** read message and process on it **************/

			//@1 set EEPROM
			//@1 (set EEPROM) complete

			okComplete = 0;
			/************** try 5 times to read SMS ***************/
			char repeatCounter = 2;
			while (repeatCounter <= 5){

				if (msgNumber1 == 255){
					sendATCommand1("at+cmgr=", msgNumber);
				} else {
					sendATCommand2("at+cmgr=", msgNumber, msgNumber1);
				}

				while ((okComplete == 0)){
					_delay_ms(200);
				}

				repeatCounter ++;
				if (okComplete == 1 || repeatCounter > 5){
					break;
				} else {
					okComplete = 0;
				}
			}
			/******************************************************/

			if (okComplete == 1){
				/*********** AT+CMGR value received in buffer *********/

				/*********** check for user number ********************/
				if (authCheck){
				userNo = split((char *) buffer, "\"", &userNoCounter);
				if (equals(userNo[3], AUTH_PHONENO) == 0){
					freeSplitedString(userNo, userNoCounter);
					sendMessage1 (phoneNo, "Unknown number detected: ", userNo[3], 2);
					msgReceived = 0;
					msgNumber = -1;
					msgNumber1 = -1;
					continue;
				}
				freeSplitedString(userNo, userNoCounter);
				}
				/******************************************************/

				/********** Check for message format ******************/
				//@1 Spliting message
				char *tempA2Lower;
				a = split((char*) buffer, checkPattern, (int *)&counter);

				tempA2Lower = toLower(a[2]);
				free(a[2]);
				a[2] = tempA2Lower;
				textContent = split (a[2], " ", &textContentCounter);

				pinCode = textContent[0];
				vmCode = textContent[1];
				productCode = textContent[2];
				//@1 Complete

				//@2 Check for 6 digit pinCode
				if (length(pinCode) == 6){
					//@3 check for vmMachine code
					if (equals(vmCode, "vm001") == 1){
						//@4 check for itemcode
						char *subSubString;
						subSubString = subString(productCode, 0, 1);
						if (equals(subSubString, "a")){
							char *subSubString2;

							//@5 check for productValue
							int productValue;
							subSubString2 = subString(productCode, 1, 2);
							productValue = toInteger(subSubString2);
							if (productValue > 6 || productValue < 1){
								/**** unavailable product ***********/
								sendMessage1 (phoneNo, pinCode, "unavailable product", 2);
								LCDPrintLines("Error: ", "unavailable product");
								whatIsGoingOn = ERRORA;
								/************************************/
							} else {
								/******** Every thing is correct drop the product *****/
								//@6 drop the product and display in LCD
								PORTC = (1 << (5 - (productValue - 1)));
								LCDPrintLines("Dropping", "Product: ");
								LCDPrint(subSubString2);
								//@6 (drop the product and display in LCD) complete

								//@7 start motor and count for 2 sec
								unsigned int fallCounter = 0;
								while ((!(bit_is_set(PINA, PA6))) && (!(bit_is_set(PINA, PA7)))) {
									/******* find out time take here *******/
									_delay_ms(1);
									if (fallCounter > 2000){
										break;
									}
									fallCounter++;
									/****************************************/
								}
								//@8 stop the motor and check for time
								PORTC = 0x00;
								if (fallCounter >= 2000) {
									/*********** overFall error **************/
									sendMessage1 (phoneNo, pinCode, "Overfall error", 2);
									LCDPrintLines("Error: ", "Overfall");
									whatIsGoingOn = ERRORO;
									/*****************************************/
								} else {
									/*********** success **************/
									sendMessage (phoneNo, pinCode, 1);
									LCDPrintLines("Drop: ", "successful");
									whatIsGoingOn = MESSAGE_SEND_SUCCESSFULLY;
									/*****************************************/
								}
								//@7 () Complete
								/******************************************************/
							}
							free (subSubString2);
							//@5 (Product value check) complete
						} else {
							/****** invalid vmCode *******/
							sendMessage1 (phoneNo, pinCode, "productCode invalid", 2);
							LCDPrintLines("Error: ", "productCode invalid");
							whatIsGoingOn = ERRORP;
							/*****************************/
						}
						free (subSubString);
						//@4 (check for itemcode) complete
					} else {
						/****** invalid vmCode *******/
						sendMessage1 (phoneNo, pinCode, "vmCode invalid", 2);
						LCDPrintLines("Error: ", "vmCode invalid");
						whatIsGoingOn = ERRORV;
						/*****************************/
					}
					//@3 (check for vmMachine code) completed
				} else {
					/******* invalid pinCode *******/
					sendMessage1 (phoneNo, pinCode, "pinCode invalid", 2);
					LCDPrintLines("Error: und.", "pinCode length");
					whatIsGoingOn = ERRORPA;
					/*******************************/
				}
				//@2 (check for 6 digit pinCode) complete
				freeSplitedString (a, counter);
				freeSplitedString (textContent, textContentCounter);
				/******************************************************/

				/******************************************************/
			} else if (okComplete == 2){
				/**************** error reading sms *******************/
				sendMessage (phoneNo, "couldn't read message from GSM modem", 2);
				LCDPrintLines("Err Reading SMS", "5 Retries Error");
				whatIsGoingOn = ERRORR;
				/******************************************************/
			}

			/*********** delete the message **************/
			if (msgNumber1 == 255) {
				sendATCommand1("at+cmgd=", msgNumber);
			} else {
				sendATCommand2("at+cmgd=", msgNumber, msgNumber1);
			}
			/*********************************************/

			//@2 reset EEPROM
			//@2 (reset EEPROM) complete

			_delay_ms(1000);

			msgNumber = -1;
			msgNumber1 = -1;
			msgReceived = 0;
		} else if (ringReceived == 1){
			//RING received
			LCDClear();
			LCDPrintLines("Message Received:","dummy message");
			_delay_ms(200);
			/******** read message and process on it **************/

			//@1 set EEPROM
			//@1 (set EEPROM) complete

			okComplete = 1;
			strCpy((char*)newBuffer, (char*)buffer);
			if (okComplete == 1){
				/*********** AT+CMGR value received in buffer *********/

				/*********** check for user number ********************/
				if (authCheck){
				userNo = split((char *) buffer, "\"", &userNoCounter);
				if (equals(userNo[3], AUTH_PHONENO) == 0){
					freeSplitedString(userNo, userNoCounter);
					sendMessage1 (phoneNo, "Unknown number detected: ", userNo[3], 2);
					msgReceived = 0;
					msgNumber = -1;
					msgNumber1 = -1;
					continue;
				}
				freeSplitedString(userNo, userNoCounter);
				}
				/******************************************************/

				/********** Check for message format ******************/
				//@1 Spliting message
				char *tempA2Lower;
				a = split((char*) buffer, checkPattern, (int *)&counter);

				tempA2Lower = toLower(a[2]);
				free(a[2]);
				a[2] = tempA2Lower;

				textContent = split (a[2], " ", &textContentCounter);

				pinCode = textContent[0];
				vmCode = textContent[1];
				productCode = textContent[2];
				//@1 Complete

				//@2 Check for 6 digit pinCode
				if (length(pinCode) == 6){
					//@3 check for vmMachine code
					if (equals(vmCode, "vm001") == 1){
						//@4 check for itemcode
						char *subSubString;
						subSubString = subString(productCode, 0, 1);
						if (equals(subSubString, "a")){
							char *subSubString2;

							//@5 check for productValue
							int productValue;
							subSubString2 = subString(productCode, 1, 2);
							productValue = toInteger(subSubString2);
							if (productValue > 6 || productValue < 1){
								/**** unavailable product ***********/
								LCDPrintLines("Error: ", "unavailable product");
								whatIsGoingOn = ERRORA;
								/************************************/
							} else {
								/******** Every thing is correct drop the product *****/
								//@6 drop the product and display in LCD
								PORTC = (1 << (5 - (productValue - 1)));
								LCDPrintLines("Dropping", "Product: ");
								LCDPrint(subSubString2);
								//@6 (drop the product and display in LCD) complete

								//@7 start motor and count for 2 sec
								unsigned int fallCounter = 0;
								while ((!(bit_is_set(PINA, PA6))) && (!(bit_is_set(PINA, PA7)))) {
									/******* find out time take here *******/
									_delay_ms(1);
									if (fallCounter > 2000){
										break;
									}
									fallCounter++;
									/****************************************/
								}
								//@8 stop the motor and check for time
								PORTC = 0x00;
								if (fallCounter >= 2000) {
									/*********** overFall error **************/
									LCDPrintLines("Error: ", "Overfall");
									whatIsGoingOn = ERRORO;
									/*****************************************/
								} else {
									/*********** success **************/
									LCDPrint("Drop success");
									whatIsGoingOn = MESSAGE_SEND_SUCCESSFULLY;
									/*****************************************/
								}
								//@7 () Complete
								/******************************************************/
							}
							free (subSubString2);
							//@5 (Product value check) complete
						} else {
							/****** invalid vmCode *******/
							LCDPrintLines("Error: ", "productCode invalid");
							whatIsGoingOn = ERRORP;
							/*****************************/
						}
						free (subSubString);
						//@4 (check for itemcode) complete
					} else {
						/****** invalid vmCode *******/
						LCDPrintLines("Error: ", "vmCode invalid");
						whatIsGoingOn = ERRORV;
						/*****************************/
					}
					//@3 (check for vmMachine code) completed
				} else {
					/******* invalid pinCode *******/
					LCDPrintLines("Error: und.", "pinCode length");
					whatIsGoingOn = ERRORPA;
					/*******************************/
				}
				//@2 (check for 6 digit pinCode) complete
				freeSplitedString (a, counter);
				freeSplitedString (textContent, textContentCounter);
				/******************************************************/

				/******************************************************/
			} else if (okComplete == 2){
				/**************** error reading sms *******************/
				LCDPrintLines("Err Reading SMS", "5 Retries Error");
				whatIsGoingOn = ERRORR;
				/******************************************************/
			}

			//@2 reset EEPROM
			//@2 (reset EEPROM) complete

			_delay_ms(1000);

			msgNumber = -1;
			msgNumber1 = -1;
			msgReceived = 0;
			/***********************************************************************/

			ringReceived = 0;
		}
	}
	return 0;
}
Ejemplo n.º 24
0
void CitGetFileList(char *mask, SListBase *list, long before, long after,
								char *phrase)
{
    struct ffblk   FlBlock;
    extern char    *monthTab[13];
    char	   *w, *work, *sp, again, buf[10];
    DirEntry       *fp;
    int		   done;
    struct stat    buff;
    long	   time;

    w = work = strdup(mask);

    do {
	again = (sp = strchr(work, ' ')) != NULL;      /* space is separator */
	if (again) {
	    *sp = 0;
	}
	/* Do all scanning for illegal requests here */
	if (!ValidDirFileName(work))
	    continue;

	/* this checks for illegal file names like CON:, PRN:, etc. */
	if (stat(work, &buff) == 0)
	    if (buff.st_mode & S_IFCHR)
		continue;

	for (done = findfirst(work, &FlBlock, 0); !done; 
						done = findnext(&FlBlock)) {
	    /* format date to our standards */
	    DosToNormal(buf, FlBlock.ff_fdate);

	    /* now read it so we can handle date specs */
	    ReadDate(buf, &time);

	    /* add to list iff dates inactive or we meet the specs */
	    if ((before != -1l && time > before) ||
				(after  != -1l && time < after))
		continue;

	    fp = (DirEntry *) GetDynamic(sizeof *fp);

	    fp->unambig = strdup(FlBlock.ff_name);

	    strCpy(fp->FileDate, buf);
	    fp->FileSize = FlBlock.ff_fsize;

	    AddData(list, fp, NULL, TRUE);
	}
	if (again) work = sp+1;
    } while (again);
    free(w);

    if (strLen(phrase) != 0) {
	Phrase = phrase;
	StFileComSearch();      /* so's we can do phrase searches */
	list->CheckIt = ChPhrase;   /* COVER YOUR EYES I'M CHEATING! */
	KillData(list, list);
	list->CheckIt = DirCheck;   /* COVER YOUR EYES I'M CHEATING! */
	EndFileComment();
    }
}
Ejemplo n.º 25
0
/*
 * fileMessage()
 *
 * This function handles the upload/download file log.
 */
void fileMessage(char mode, char *fn, char IsDL, int protocol, long size)
{
    long	  hours, mins;
    static label  LastActive = "";
    char	  logfn[100];
    /* int	 	  yr, dy, hr, mn; */
    char	  *mon, *pr, buf[100];
    static struct timeData gData, fData, xData;
    struct timeData *pData;
    static long xwork;
    static char fin_done;

    if (protocol == ASCII || cfg.Audit == 0)
	return;

    makeAuditName(logfn, "filelog.sys");
/*  getCdate(&yr, &mon, &dy, &hr, &mn); */
    getCdate(&gData.year, &mon, &gData.day, &gData.hour, &gData.minute);
    strcpy(gData.month, mon);

    switch (mode) {
    case FL_START:
	startTimer(USER_TIMER);
	fin_done = FALSE;
	fData = gData;
	break;
    case FL_FIN:
	fin_done = TRUE;
	xData = gData;
	xwork = chkTimeSince(USER_TIMER);
	break;
    case FL_SUCCESS:
    case FL_FAIL:
    case FL_EX_END:
	if (strCmpU(LastActive, logBuf.lbname) != SAMESTRING) {
	    sprintf(buf, "\n%s on %d%s%02d @ ", logBuf.lbname, gData.year, mon,
								gData.day);
	    if (BaudRate > 0l) 
		sprintf(lbyte(buf), "%ld", BaudRate);
	    else
		strcat(buf, "Unknown");

	    strcat(buf, ":");

	    CallMsg(logfn, buf);
	    strCpy(LastActive, logBuf.lbname);
	}
	if (!fin_done) {
	    xwork = chkTimeSince(USER_TIMER);
	    pData = &gData;
	}
	else
	    pData = &xData;
	hours = xwork / 3600;
	xwork -= (hours * 3600);
	mins  = xwork / 60;
	xwork -= (mins * 60);
	if (protocol > TOP_PROTOCOL)
	    pr = FindProtoName(protocol);
	else
	    pr = Table[protocol].GenericName;
	if (mode == FL_EX_END) {
	    sprintf(buf,
    "%2cFollowing files %c %s via %s %d:%02d - %d:%02d (%ld:%02ld:%02ld):",
		' ', (IsDL) ? 'D' : 'U', roomBuf.rbname, 
		pr,
		fData.hour, fData.minute, pData->hour, pData->minute,
		hours, mins, xwork);
	    CallMsg(logfn, buf);
	    CallMsg(logfn, msgBuf.mbtext);
	}
	else {
	    if (!IsDL && mode == FL_FAIL)
		sprintf(buf, "%2c%s (FAILED) %c %s: %d:%02d - %d:%02d (%ld:%02ld:%02ld) %s.",
		' ', fn, (IsDL) ? 'D' : 'U', roomBuf.rbname,
		fData.hour, fData.minute, pData->hour, pData->minute,
		hours, mins, xwork, pr);
	    else
		sprintf(buf,
    		"%2c%s (%ld) %c %s: %d:%02d - %d:%02d (%ld:%02ld:%02ld) %s. %s",
		' ', fn, size, (IsDL) ? 'D' : 'U', roomBuf.rbname,
		fData.hour, fData.minute, pData->hour, pData->minute,
		hours, mins, xwork, pr,
		(mode == FL_FAIL) ? "(FAILED)" : "");
	    CallMsg(logfn, buf);
	}
	break;
    }
}