All pastes #623150 Raw Edit

Anonymous

public c v1 · immutable
·published 2007-07-17 11:47 UTC
rendered paste body
#define LineMax 601#define FileDelimiter ' '#define CFileDelimiter " " char *ptr;  char *realval = malloc(LineMax);  //MODIFIED  if(filename[0] == '\\') //If true, active multidirectory mode  {	FILE *fsys;	char *mounted = ((char*)(FILE_SYSTEM));	char *buf = malloc(LineMax);	char *final;	unsigned short isDiscovered = 0;	//First we look for the file system config file	fsys = fopen(mounted, "r+");	if(!fsys)		return error(ERR_FILE);	//Get each line, one by one and wheck if it does correspond to filename	//rewind(fsys);	while(fgets(buf, LineMax, fsys))	{		isDiscovered = 2; //If !isDiscovered, file will be empty		if(buf[strspn(buf, filename)] == FileDelimiter) //If filename found, exit of the loop		{			isDiscovered = 1;			break;		}		if(fgetc(fsys) == EOF)			break;	}	//rewind(fsys);	if(isDiscovered)	{		buf[strcspn(buf, "\n")] = '\0'; //Delete new line character for more safety		strtok(buf, CFileDelimiter);		realval = strtok(NULL, CFileDelimiter);	}	if(!isDiscovered) //File empty	{		//Fill the file		final = malloc(strlen(filename)+3);		realval = ((char*)("a0")); //a before the number to have a valid path name		sprintf(final, "%s%s%s\n", filename, CFileDelimiter, realval);		final[strcspn(final, "\n")+1] = '\0';		if(fputs(final, fsys) == EOF)			return error(ERR_FILE);	}	if(isDiscovered == 2) //File def not found	{		memmove(realval + 0, realval + 0 + 1, strlen(realval + 0 + 1) + 1);  //a before the number to have a valid path name		short b = atoi(realval);		b++;		final = malloc(strlen(filename)+strlen(realval)+3);		sprintf(final, "%s%sa%u\n", filename, CFileDelimiter, b);  //a before the number to have a valid path name		final[strcspn(final, "\n")+1] = '\0';		if(fputs(final, fsys) == EOF)			return error(ERR_FILE);		sprintf(realval, "a%u", b);	}	fclose(fsys);	free(buf);	sprintf(filename, "sidetext\\%s\n", realval); //finally we set up the value	filename[strcspn(filename, "\n")] = '\0';  }  //MODFIFIED