#include <string.h>
#include <ctype.h>
#include "gpklib.h"




int chomp_newline(char *s)
{
 if(!s)
	return -1;

 char *c = 0, *s0 = s;
 while(*s)	{
	if(*s=='\r' || *s=='\n')	{
		if(!c)
			c = s;
		}
	else
		c = 0;
	s++;
	}
 if(c)
	*c = '\0';

 return (c?c:s) - s0;
}



/* Removes whitespace from the end of a string. */

int chomp_whitespace(char *s)
{
 if(!s)
	return -1;

 char *c = 0, *s0 = s;
 while(*s)	{
	if(isspace(*s)) {
		if(!c)
			c = s;
		}
	else
		c = 0;
	s++;
	}
 if(c)
	*c = '\0';

 return (c?c:s) - s0;
}




BOOL is_blank_line(C char *line)
{
 for(; *line; line++)
	if(!isspace(*line))
		return FALSE;
 return TRUE;
}



BOOL is_error_line(C char *line)
{
 return strncmp("ERR:", line, 4) == 0;
}




void trim_comments(char *line)
{		/* # comments. */

 if(line[0] == '#')
	line[0] = '\0';

 char *m;
 for(m=line; m[0] && m[1]; m++)
	if(m[1]=='#' && isspace(m[0]))
		m[0] = '\0';
}

