/*------------------------------------------------------------------------
       Name: bbscarea.c
   Comments: Display file areas and select one
  ------------------------------------------------------------------------*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "packdef.h"


char            f_lines[99][81];
char            foo[99];
int             dir_priv[99];
int             set_yet_m = FALSE;
int             user_priv = 32767;


int
	change_msga(numx) int numx;
{
	FILE           *fpt, *fopen();
	char           *fgets(), *getenv();
	char            choice[94];
	char            dir_priv_ascii[7];
	char           *buf_ptr;
	int             line_cnt, ret, i;
	int             index_value, ptr;
	int             length;


	strcpy(buf128, MSGS);

	if ((fpt = fopen(buf128, "r")) == NULL) {
		printf("\n\rError Opening File Area List: Notify Sysop!\n\r");
		return (-1);
	}
	line_cnt = 0;
	while (fpt) {
		if ((fgets(f_lines[line_cnt], 80, fpt)) == NULL) {
			if (line_cnt == 0) {
				printf("\n\rEOF Unexpected in Message Area List: Notify Sysop!\n\r");
				return (-1);
			}
			break;	/* if not 1st line */
		}		/* end of if ((fgets)) */
		if (line_cnt > 0) {
			length = strlen(f_lines[line_cnt]);
			length -= 57;
			substr(f_lines[line_cnt], dir_priv_ascii, 57, length);
			dir_priv[line_cnt] = atoi(dir_priv_ascii);
			if (dir_priv[line_cnt] > user_priv)
				goto next_read;
			strcpy(foo, f_lines[line_cnt]);
			buf_ptr = foo;
			buf_ptr += 56;
		}
next_read:
		++line_cnt;
	}			/* end of while (fpt) */
	fclose(fpt);

	index_value = numx;
	if (index_value > 0 && index_value < line_cnt) {
		if (dir_priv[index_value] <= user_priv) {
			parse_arg(f_lines[index_value]);
			set_yet_m = TRUE;
			return (1);
		}
	}
	return (0);
}
parse_arg(string)
	char           *string;
{

	register char  *file_ptr;
	register int    i;

	strcpy(m_pathname, ORGPATH);
	file_ptr = (m_pathname + strlen(m_pathname));

	i = 0;
	while (string[i] != ' ') {
		*file_ptr = string[i];
		++file_ptr;
		++i;
	}
	*file_ptr = '/';
	++file_ptr;
	*file_ptr = '\0';
	printf("Packing %s\n", m_pathname);

}
