[net.sources] Shorter version of pnews...

taylor@sdccsu3.UUCP (06/04/84)

	Included herein for your edification and enjoyment (and perhaps
use) is a shorter version of the pnews program that does essentially the
same thing as the recent posting by Mark Horton, but in much less space.

	The reason that it keeps asking if you want to save the file is that I 
have a tendancy to use the wrong newsgroup name and I have many times lost a 
long article due to the fact that I just gave it the wrong name...hence the 
RESUBMIT too!

	It should be self-documenting...and can be compiled (after pulling
off the news header and this) by 'cc pnews.c'


			Enjoy!

					Dave Taylor

------- source to pnews.c ----------- should have a bar at the end too ----

/**  New version of 'pnews' **/

/**  Succinctly written by Dave Taylor.  **/

/**   final output of the program is a line to the system:

	inews -t "$title" -n $newsgroup < $file  **/

 
#include <stdio.h>
#include <strings.h>

#define MAX_CHARS 132
#define temp_file ".pnews.article"
#define get_line(string) fgets(string, MAX_CHARS, stdin);clear_return(string)

main()
{

	int i;
	char subject[MAX_CHARS], groups[MAX_CHARS], filename[MAX_CHARS],
	     buffer[MAX_CHARS], answer[MAX_CHARS];

	printf("\n\t\tPost News\tVersion 1.0\n\n");

	printf("Subject: ");

	get_line(subject);

	printf("Newsgroup(s): ");

	get_line(groups);

	printf("\nType <Return> for a new file,\n");
	printf(  "     <Delete> to quit the program,\n");
	printf(  "     RESUBMIT to use the last typed in article,\n");
	printf(  "  or the name of a file to submit news from  : ");

	get_line(filename);

	if (strcmp(filename,"RESUBMIT")==0)          /** <resubmit> **/
	{
	   if (fopen(temp_file, "r") == 0)  /** no file TO resubmit! **/
	     exit(
		  printf("\n\t*** no file to resubmit! ***\n\n"));

	   strcpy(filename, temp_file);	    /** else make new name **/
	}
	else
	if (filename[1] == '\0')   		  /** <Return> **/
	{
	   strcpy(filename, temp_file);  /** get new name **/

	   sprintf(buffer, "rm -f %s", filename);  /** ensure no garbage **/
	   system(buffer);			   /** by removing file  **/

	   sprintf(buffer, "vi %s", filename);
	   system(buffer);  /** edit new file.. **/

	   printf("\n\nWould you like to save this as another file? (Y/N) ");
	   get_line(answer);

	   if (answer[1] == 'Y' | answer[1] == 'y')
	   {
		printf("Name of new file? ");
		get_line(answer);

		if (fopen(answer,"r") != 0) 
		{  /** file exists! **/
		  printf("\nFile '%s' exists!  Appending.");
		  close(answer);
		  sprintf(buffer, "cat %s >> %s", temp_file, answer);
		  system(buffer);
		}
		else /** new file **/
		{
		  sprintf(buffer, "cp %s %s",temp_file, filename);
		  system(buffer);
		  printf("saved.");
		}
		printf("\n");
	    }
	}
	else
	{
	    clear_return(filename);
	    if (fopen(filename, "r") ==  0)   /** file not found **/
	      exit(
	        printf("\n***File not found: '%s' ***\n", filename));
	    else /** all okay **/
	      close(filename);
	}

	if (fopen(filename,"r")==0)  /** somehow got to here with NO file! **/
	  exit(
	       printf("\n\n\t*** No file! ***\n\n"));

        sprintf(buffer, "inews -t \"%s\" -n %s < %s", subject, groups, 
		filename); 

	    printf("\n\n");
	    system(buffer);
	    printf("\n");

}
	
clear_return(string)
char string[];		/** removes EOLN char from string **/
{
	int i;

	for (i=0; string[i] != '\n' & string[i] != '\0'; i++)
		;

	string[i] = '\0';

}

--- end of program ---