Exemple #1
0
int check_for_mp (FILE *image_file)
{
    rewind (image_file);
    mfgets (work_buffer, WORK_BUFFER_SIZE, image_file);
    if (strncmp (work_buffer, "%!PS", 4))
        return 0;
    mfgets (work_buffer, WORK_BUFFER_SIZE, image_file);
    if (strncmp (work_buffer, "%%BoundingBox:", 14))
        return 0;
    mfgets (work_buffer, WORK_BUFFER_SIZE, image_file);
    if (strncmp (work_buffer, "%%Creator: MetaPost", 19))
        return 0;
    return 1;
}
Exemple #2
0
/* Each lines describes character code mapping for each
 * subfonts. '#' is start of comment.
 * SFD file format uses a '\' before newline sequence
 * for line-continuation.
 */
static char *
readline (char *buf, int buf_len, FILE *fp)
{
  char  *r, *q, *p = buf;
  int    n = 0, c = 0;

  while (buf_len - n > 0 && (q = mfgets(p, buf_len - n, fp))) {
    c++;
    r = strchr(q, '#');
    /* Comment is converted to single wsp (followed by a newline). */
    if (r) {
      *r = ' ';
      *(r + 1) = '\0';
    }
    if (strlen(q) == 0)
      break; /* empty line */
    n += strlen(q);
    q += strlen(q) - 1;
    if (*q != '\\')
      break;
    else { /* line continued */
      n -= 1;
      p  = buf + n;
    }
  }
  if (n >= buf_len - 1) {
    WARN("Possible buffer overflow in reading SFD file (buffer full, size=%d bytes)",
         buf_len - 1);
  }

  return  (c > 0 ? buf : NULL);
}
char *pc_readasm(void *handle, char *string, int maxchars)
{
  #if defined __MSDOS__ || defined PAWN_LIGHT
    return fgets(string,maxchars,(FILE*)handle);
  #else
    return mfgets((MEMFILE*)handle,string,maxchars);
  #endif
}
Exemple #4
0
//reads a line, returns ptr to value of passed parm.  returns NULL if none
char *get_parm_value(char *parm,FILE *f)
{
	static char buf[80];
	
	if (!mfgets(buf,80,f))
		return NULL;

	if (istok(buf,parm))
		return get_value(buf);
	else
		return NULL;
}
static int Connect2Wifi(char *ssid, char *psk)
{
	char buff[512];
	FILE *fstream;
	vsystem("wpa_cli add_n | tail -n +2 > /mnt/sdcard/nid");
	
	if (NULL == (fstream = fopen("/mnt/sdcard/nid", "r")))
	{
		perror("fopen");
		return;
	}
	while (NULL != mfgets(buff, sizeof(buff), fstream))
	{
		
	}
	fclose(fstream);
}
void LoadScriptFile(pzllst *lst,FManNode *filename, bool control, MList *controlst)
{
#ifdef TRACE
    printf("Loading script file %s\n",filename->File);
#endif

    if (control)
    {
        Rend_SetRenderer(RENDER_FLAT);
    }

    mfile *fl=mfopen(filename);
    if (fl == NULL)
    {
        printf("Error opening file %s\n",filename->File);
        exit(1);
        return;
    }

    char buf[FILE_LN_BUF];

    while(!mfeof(fl))
    {
        mfgets(buf,FILE_LN_BUF,fl);

        char *str=PrepareString(buf);


        if (strCMP(str,"puzzle")==0)
        {
            Parse_Puzzle(lst,fl,str);
        }
        else if (strCMP(str,"control")==0 && control )
        {
            Parse_Control(controlst,fl,str);
        }
    }

    mfclose(fl);
}
Exemple #7
0
Fichier : xkey.c Projet : 8l/ted
LoadTedrc(char *tedname, int depth, int kdefmapno)
{
FILE *fp;
char ss[8192],ibuf[2048],*tt,*uu,*vv,*ww,*xx;
int len,i,j,lno;
int hdef[128];
extern int X_inited;
KEYDEF *kdef=kdefmap[kdefmapno];
int kdefno=kdefno_m[kdefmapno];

if ((fp=init_tedrc_fname(tedname, depth))==NULL)
	return 1;

if (kdefno && !depth) {
	for(j=0;j<kdefno;j++) free(kdef[j].cmd);
	if (!kdefmapno) free_lang();
	free(kdef);
	kdefmap[kdefmapno]=NULL;
	if (kdefmapno) {
		free(mode_str_m[kdefmapno]);
		mode_str_m[kdefmapno]=NULL;
	}
	kdef=NULL;
}
#if	0
printf("-- %d %d %s\n",depth, kdefmapno, ftedrc);
#endif
if (kdef==NULL) {
	MAX_KEY_DEF=280;
	if ((kdef=mmalloc(sizeof(KEYDEF)*MAX_KEY_DEF,"LoadTedrc"))==NULL)
		exit(1);
	kdefmap[kdefmapno]=kdef;
	kdefno_m[kdefmapno]=kdefno=0;
}


if (!depth) qsort(kmap,kname_no,sizeof(KEYMAP),qcmpxk);
tedrcfname=tedname;
lno=0;
while (!feof(fp)) {
	int next_l;

	ss[0]=0;
	next_l=0;
	for(;;) {
		lno++;
		len=mfgets(ibuf,sizeof(ibuf),fp);
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\n') ibuf[--len]=0;
		if (!len) {
			next_l=1;
			break;
		}
		while (len && (ibuf[len-1]==' '||ibuf[len-1]==9)) len--;
		if (!len) {
			next_l=1;
			break;
		}
		if (ibuf[len-1]=='\\') {
			ibuf[len-1]=0;
			strcat(ss,ibuf);
		} else {
			strcat(ss,ibuf);
			break;
		}
	}
	if (next_l) continue;

	tt=skip_spc(ss);
	uu=to_spc(tt);
	vv=skip_spc(uu);
	*uu=0;
	if (tt[0]=='#')	continue;
	if (!strcmp(tt,"d")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		kdef[i].cmd=strdup(parse_Cstr(tedname, lno,xx,&uu));
		kdef[i].type=0;
		if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		continue;
	} else
	if (!strcmp(tt,"f")) {
		ww=to_spc(vv);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		kdef[kdefno].klen=parse_key(tedname, lno,vv,ww,kdef[kdefno].kcode);
		if ((i=kcode_exist(kdefno,kdef,kdefno))<kdefno)
			free(kdef[i].cmd);
		xx=skip_spc(ww);
		if (parse_stmt(tedname, lno,xx,&kdef[i].cmd,&kdef[i].type)) {
			if (i==kdefno) incr_kdefno(&kdef,kdefmapno,&kdefno);
		}
		continue;
	}
	if (kdefmapno)
		lper(tedname,lno,"%s for LoadKeyDefInto can accept 'f' and 'd' command only", tedname);
	if (!strcmp(tt,"s")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		*ww=0;
		for(i=0;i<sizeof(locolor)/sizeof(locolor[0]);i++)
			if (!strcmp(vv,locolor[i].cname)) break;
		if (i==sizeof(locolor)/sizeof(locolor[0]))
			lper(tedname,lno,"Unknown Def color %s",vv);
		ww=to_spc(xx);
		*ww=0;
		strcpy(locolor[i].caddr,xx);
	} else
	if (!strcmp(tt,"set")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		tt=to_spc(xx);
		if (!(*ww)) lper(tedname,lno,"argument expected");
		*ww=0;
		for(i=0;i<sizeof(sets)/sizeof(sets[0]);i++)
		if (!strcmp(sets[i].sname,vv)) break;
		if (i==sizeof(sets)/sizeof(sets[0]))
			lper2(tedname,lno,"Unknown set %s",vv);
		else {
		  *tt=0;
		  *(sets[i].saddr)=atoi(xx);
		}
	} else
	if (!strcmp(tt,"lang") && !depth) {
		extern char DirectCommentChars[];
		int keywcnt=3,LangIdx,ColIdx,AllocN=32,kwidx, MaxKeywordLen=0;
		char *ff;
		KW *kw;

		if (depth)
			p_err("cannot define 'lang' in include %s", tedname);


		tt=parse_Cstr(tedname, lno,vv,&uu);
		i=strlen(tt)+2;
		if ((vv=mmalloc(i,"LoadTedrc"))==NULL) exit(1);
		if ((kw=mmalloc(AllocN*sizeof(KW),"LoadTedrc 2"))==NULL) exit(1);

		LangExt[LangN]=strcat(strcpy(vv,tt)," ");
		kw[0].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		uu=skip_spc(uu);
		DirectCommentChars[LangN]=*uu;
		kw[1].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		kw[2].coloridx=ColorCnt;
		strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
		strcpy(pc_color[ColorCnt++].bg_str,getstr(vv,&uu));
		for(;;) {
			if (!*uu) break;
			strcpy(pc_color[ColorCnt].fg_str,getstr(uu+1,&vv));
			strcpy(pc_color[ColorCnt].bg_str,getstr(vv,&uu));
			uu=skip_spc(uu);
			ww=tt=parse_Cstr(tedname, lno,uu,&vv);
			uu=vv;
			xx=tt+strlen(tt);
			for(;;) {
				char *pstr;

				tt=to_spc(ww);
				vv=skip_spc(tt);
				*(tt)=0;
				if (pstr=strchr(ww,'(')) {
					kw[keywcnt].arg=strdup(pstr);
					*pstr=0;
				} else kw[keywcnt].arg=0;
				kw[keywcnt].keyword=strdup(ww);
				if (strlen(ww) > MaxKeywordLen) MaxKeywordLen=strlen(ww);
				kw[keywcnt].coloridx=ColorCnt;
#if	0
				printf("%d %d   %d %s\n",LangN,keywcnt, ColorCnt,
				kw[keywcnt].keyword);
#endif
				keywcnt++;
				if (keywcnt+3>=AllocN) {
					AllocN+=32;
					if ((kw=mrealloc(kw,AllocN*sizeof(KW),"LoadTedrc 3"))==NULL) exit(1);
				}
				ww=vv;
				if (ww==xx) break;
			}
			ColorCnt++;
		}
		qsort(kw+3,keywcnt-3,sizeof(KW), kwcmp);
		LangKw[LangN]=kw;
		LangMaxKeywordLen[LangN]=MaxKeywordLen;
		LangKwN[LangN++]=keywcnt;
		if (LangN>=MaxLang) {
			error("Too many languages defined");
			error("Remove unused language in tedrc or modify ted.h and recompile");
			exit(1);
		}
	} else
	if (!strcmp(tt,"include")) {
		if (depth > 10) {
			error("include too many level ??");
			continue;
		}
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		*ww=0;
		LoadTedrc(vv,depth+1,kdefmapno);
		tedrcfname=tedname;
	} else
	if (!strcmp(tt,"filebrowser")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		init_reg_exp(vv);
	} else
	if (!strcmp(tt,"fontlist")) {
		ww=to_spc(vv);
		xx=skip_spc(ww);
		if (!(*vv)) lper(tedname,lno,"argument expected");
		setFontList(vv);
	} else
	if (!strcmp(tt,"LoadKeyDefInto")) {
		int no;
		char mstr[16], *p;
		tt=parse_Cstr(tedname, lno,vv,&uu);
		if (!(*tt)) lper(tedname,lno,"file name expected");
		ww=skip_spc(uu);
		if (!*ww) lper(tedname,lno,"Bind number expected");
		no=*ww-'0';
		if (no<=0 || no>=4)
			lper(tedname,lno,"Bind number must be less than 4 and greater than 0");
		if ((p=strchr(tt,'.'))==NULL) {
			mode_str_m[no]="      ";
		} else {
			p++;
			if (! *p)
				mode_str_m[no]=strdup("      ");
			else
				mode_str_m[no]=strdup(p);
		}
		LoadTedrc(tt,0,no);
	}
}
fclose(fp);

if (!depth) {
kdefno=kdefno_m[kdefmapno];
qsort(kdef,kdefno,sizeof(kdef[0]),qcmp);
bzero(hdef,sizeof(hdef));
bzero(kdefhash[kdefmapno],128*sizeof(int));
for(i=0;i<kdefno;i++) {
	j=KEYHASH(kdef[i].kcode[0]);
	if (hdef[j]) continue;
	hdef[j]=1;
	kdefhash[kdefmapno][j]=i;
}
kdefhash[kdefmapno][127]=kdefno;
for(i=126;i>=0;i--)
if (!hdef[i]) kdefhash[kdefmapno][i]=kdefhash[kdefmapno][i+1];
ReLoadTed=1;
if (X_inited) alloc_pc_colors();
}
return 0;
}
Exemple #8
0
//loads the specfied mission from the mission list.  build_mission_list()
//must have been called.  If build_mission_list() returns 0, this function
//does not need to be called.  Returns true if mission loaded ok, else false.
int load_mission(int mission_num)
{
	Current_mission_num = mission_num;

	mprintf(( 0, "Loading mission %d\n", mission_num ));

#ifndef DEST_SAT
	if (mission_num == 0) {		//built-in mission
		int i;

#ifdef ROCKWELL_CODE
		Last_level = 7;
		Last_secret_level = 0;

		//build level names
		for (i=0;i<Last_level;i++)
			sprintf(Level_names[i], "LEVEL%02d.RDL", i+1);
#else
		Last_level = BIM_LAST_LEVEL;
		Last_secret_level = BIM_LAST_SECRET_LEVEL;

		//build level names
		for (i=0;i<Last_level;i++)
			sprintf(Level_names[i], "LEVEL%02d.RDL", i+1);
		for (i=0;i<-Last_secret_level;i++)
			sprintf(Secret_level_names[i], "LEVELS%1d.RDL", i+1);

		Secret_level_table[0] = 10;
		Secret_level_table[1] = 21;
		Secret_level_table[2] = 24;
#endif
		strcpy(Briefing_text_filename,BIM_BRIEFING_FILE);
		strcpy(Ending_text_filename,BIM_ENDING_FILE);
		cfile_use_alternate_hogfile(NULL);		//disable alternate
	} else 
#endif
	{		 //NOTE LINK TO ABOVE IF!!!!!
			//read mission from file 
		FILE *mfile;
		char buf[80], tmp[80], *v;

		strcpy(buf,Mission_list[mission_num].filename);
		strcat(buf,".MSN");

		strcpy(tmp,Mission_list[mission_num].filename);
		strcat(tmp,".HOG");
		cfile_use_alternate_hogfile(tmp);

		mfile = fopen(buf,"rt");
#ifdef USE_CD
		if (mfile == NULL) {
			if ( strlen(destsat_cdpath) )	{
				char temp_spec[128];
				strcpy( temp_spec, destsat_cdpath );
				strcat( temp_spec, buf );
				mfile = fopen( temp_spec, "rt" );
			}
		}
#endif
		if (mfile == NULL) {
			Current_mission_num = -1;
			return 0;		//error!
		}

		//init vars
		Last_level = 		0;
		Last_secret_level = 0;
		Briefing_text_filename[0] = 0;
		Ending_text_filename[0] = 0;
	
#ifdef DEST_SAT
		if (!stricmp(Mission_list[mission_num].filename, "DESTSAT")) {		//	Destination Saturn.
			strcpy(Briefing_text_filename,"briefsat.tex");
			strcpy(Ending_text_filename,"endsat.tex");
		}
#endif

		while (mfgets(buf,80,mfile)) {

			if (istok(buf,"name"))
				continue;						//already have name, go to next line
			else if (istok(buf,"type"))
				continue;						//already have name, go to next line				
			else if (istok(buf,"hog")) {
				char	*bufp = buf;

				while (*(bufp++) != '=')
					;

				if (*bufp == ' ')
					while (*(++bufp) == ' ')
						;

				cfile_use_alternate_hogfile(bufp);
				mprintf((0, "Hog file override = [%s]\n", bufp));
			} else if (istok(buf,"briefing")) {
				if ((v = get_value(buf)) != NULL) {
					add_term(v);
					if (strlen(v) < 13)
						strcpy(Briefing_text_filename,v);
				}
			}
			else if (istok(buf,"ending")) {
				if ((v = get_value(buf)) != NULL) {
					add_term(v);
					if (strlen(v) < 13)
						strcpy(Ending_text_filename,v);
				}
			}
			else if (istok(buf,"num_levels")) {

				if ((v=get_value(buf))!=NULL) {
					int n_levels,i;

					n_levels = atoi(v);

					for (i=0;i<n_levels && mfgets(buf,80,mfile);i++) {

						add_term(buf);
						if (strlen(buf) <= 12) {
							strcpy(Level_names[i],buf);
							Last_level++;
						}
						else
							break;
					}

				}
			}
			else if (istok(buf,"num_secrets")) {
				if ((v=get_value(buf))!=NULL) {
					int n_secret_levels,i;

					n_secret_levels = atoi(v);

					for (i=0;i<n_secret_levels && mfgets(buf,80,mfile);i++) {
						char *t;

						
						if ((t=strchr(buf,','))!=NULL) *t++=0;
						else
							break;

						add_term(buf);
						if (strlen(buf) <= 12) {
							strcpy(Secret_level_names[i],buf);
							Secret_level_table[i] = atoi(t);
							if (Secret_level_table[i]<1 || Secret_level_table[i]>Last_level)
								break;
							Last_secret_level--;
						}
						else
							break;
					}

				}
			}

		}

		fclose(mfile);

		if (Last_level <= 0) {
			Current_mission_num = -1;		//no valid mission loaded 
			return 0;
		}
	}

	Current_mission_filename = Mission_list[Current_mission_num].filename;
	Current_mission_longname = Mission_list[Current_mission_num].mission_name;

	return 1;
}
Exemple #9
0
char *pc_readasm(void *handle, char *string, int maxchars)
{
  return mfgets((MEMFILE*)handle,string,maxchars);
}
Exemple #10
0
static char *
m_getpass(const char *prompt)
{
    static char passwd[PASS_MAX];
    struct termios our_termios;
    struct termios saved_termios;
    struct termios *p_saved_termios;
    int ttyfd;
    FILE *ttyf;
    int saved_errno;
    char *p_passwd;

    /* ttyfd == -1 indicates ttyfd is closed. */
    ttyfd = -1;
    /* ttyf == NULL indicates ttyf is closed. */
    ttyf = NULL;
    /* p_saved_termios == NULL indicates TTY is on user settings. */
    p_saved_termios = NULL;

    /* p_passwd == NULL indicates this functions fails. */
    p_passwd = NULL;

    ttyfd = open("/dev/tty", O_RDWR);
    if (ttyfd == -1) {
        goto FAIL;
    }
    ttyf = fdopen(ttyfd, "rw");
    if (ttyf == NULL) {
        goto FAIL;
    }

    if (write(ttyfd, prompt, strlen(prompt)) == -1) {
        goto FAIL;
    }

    /* Save user tty settings, then echo off */
    p_saved_termios = &saved_termios;
    if (tcgetattr(ttyfd, p_saved_termios) == -1) {
        p_saved_termios = NULL;
        goto FAIL;
    }
    our_termios = saved_termios;
    our_termios.c_lflag &= ~ECHO;
    if (tcsetattr(ttyfd, TCSAFLUSH, &our_termios) == -1) {
        goto FAIL;
    }

    /* Read password */
    if (mfgets(passwd, PASS_MAX, ttyf) == NULL) {
        goto FAIL;
    }

    /* Restore user tty settings */
    if (tcsetattr(ttyfd, TCSAFLUSH, p_saved_termios) == -1) {
        goto FAIL;
    }

    if (write(ttyfd, "\n", 1) == -1) {
        goto FAIL;
    }

    errno = 0;
    p_passwd = passwd;
    /* go through */

FAIL:
    saved_errno = errno;
    if (ttyfd != -1) {
        (void) close(ttyfd);
    }
    if (ttyf != NULL) {
        (void) fclose(ttyf);
    }
    if (p_saved_termios != NULL) {
        (void) tcsetattr(ttyfd, TCSAFLUSH, p_saved_termios);
    }
    errno = saved_errno;
    return p_passwd;
}
static void WifiScan_r()
{
	FILE *fstream;
    char buffer[512] = {0};
    char buffer1[512] = {0};
	
	vsystem("wpa_cli scan_r > /mnt/sdcard/wifi/list.txt");
	MsecSleep(1000);

	vsystem("awk '{print $5}' /mnt/sdcard/wifi/list.txt | tail -n +3 > /mnt/sdcard/scan");
		
	MutexLock(&pWifiMutex);
    if (NULL == (fstream = fopen("/mnt/sdcard/scan", "r")))
    {
        perror("fopen");
        return;
    }
	int index = 0;
    while (NULL != mfgets(buffer, sizeof(buffer), fstream))
    {
        if (index >= MAX_SIGNUM)
        {
            break;
        }
        strncpy(stWifi[index].ssid, buffer, sizeof(stWifi[index].ssid) - 1);
        index++;
    }
    fclose(fstream);

	vsystem("awk '{print $3}' /mnt/sdcard/wifi/list.txt | tail -n +3 > /mnt/sdcard/scan");
		
    if (NULL == (fstream = fopen("/mnt/sdcard/scan", "r")))
    {
        perror("fopen");
        return;
    }
	index = 0;
    while (NULL != mfgets(buffer, sizeof(buffer), fstream))
    {
        if (index >= MAX_SIGNUM)
        {
            break;
        }
		stWifi[index].iLevel = atoi(buffer);
		stWifi[index].iCell = CalcWifiCell(stWifi[index].iLevel);
        index++;
    }
    fclose(fstream);
	
	SortByLevel(index);
	
	int i;
	for(i = 0; i < index; i++)
	{
		if(i < WIFIITEM)
		{
			snprintf(buffer1, sizeof(buffer1), "%s", stWifi[i].ssid);
			if(NULL == pWiFiStrItem[i])
			{
				free(pWiFiStrItem[i]);
				pWiFiStrItem[i] = NULL;
			}
			pWiFiStrItem[i] = TransString(buffer1);
			SetLabelText(pWiFiStrItem[i], pWiFiLblItem[i]);
			DisplayPicture(pWiFiItem[i]);
			DisplayLabel(pWiFiLblItem[i]);
		}
		printf("sig%d %s  %d %d\n", i, stWifi[i].ssid, stWifi[i].iCell, stWifi[i].iLevel);
	}
	
	MutexUnlock(&pWifiMutex);
	
	WriteWifiMsgQueue(ENUM_SCAN);
}
Exemple #12
0
Exp_info *exp_read_staden_info(mFILE *fp, char *filename)
/*
 * Read a staden file into an Exp_info data structure
 */
{
    Exp_info *e;
    char *seq;
    char *fn;

    /* find last / in filename */
    for(fn=filename+strlen(filename)-1;fn>filename && *fn!='/';fn--);
    if (*fn=='/') fn++;
    
    
    if ( (e = exp_create_info()) != NULL ) {
	char line[128];
	/* an upper limit for the file size */
	int max_seq_size = file_size(filename);
	int left, right, len, i;
	int lineno;
	int formatIsBap;
	int CS_from, CS_to;
	int SR;

	CS_from = CS_to = SR = 0;

	/*ID*/
	(void)ArrayRef(e->entries[EFLT_ID],e->Nentries[EFLT_ID]++);
	exp_get_entry(e,EFLT_ID) = (char *)strdup(fn);

	/*EN*/
	(void)ArrayRef(e->entries[EFLT_EN],e->Nentries[EFLT_EN]++);
	exp_get_entry(e,EFLT_EN) = (char *)strdup(fn);

	/*CC*/
	(void)ArrayRef(e->entries[EFLT_CC],e->Nentries[EFLT_CC]++);
	exp_get_entry(e,EFLT_CC) = (char *)strdup("Created from a staden format sequence assembly file");

	seq = (char *) xmalloc(max_seq_size+1);
	if (!seq)
	    return NULL;

	left = 0;
	right = 0;
	len = 0;
	    
	lineno = 0;
	formatIsBap = 1;
	while (mfgets(line,sizeof(line),fp)!=NULL) {
	    char *s;
	    lineno++;
	    if (lineno == 1) {
		int pos, ret;
		char *cp;
		/*
		 * This maybe a fasta format file.
		 */
		if (line[0] == '>') {
		    if (cp = strchr(line, ' '))
			*cp = 0;
		    if (cp = strchr(line, '\t'))
			*cp = 0;
		    if (cp = strchr(line, '\n'))
			*cp = 0;
		    exp_set_entry(e, EFLT_ID, strdup(line+1));
		    exp_set_entry(e, EFLT_EN, strdup(line+1));
		    continue;
		}

		/*
		 * This maybe a file created from 'output consensus',
		 * in which case it'll have the Staden format style of:
		 * " <-----T2.00047----->" header on the first line.
		 *
		 * We strip this off. Argh - why don't Suns have the
		 * ANSI function memmove() ?
		 */
		ret = sscanf(line, " <%*18s>%n", &pos);
		if (ret && pos == 21) {
		    int i, e = sizeof(line)-21;

		    for (i=0; i < e; i++)
			line[i] = line[i+21];
		    /* memmove((void *)line,
		     *	(void *)(line + 21),
		     *	sizeof(line)-21); 
		     */
		}
	    }
	    if (line[0] == ';') {
		/********************************************
		 * Title line parsing
		 *******************************************/
		if (lineno==1 &&
		    !(line[1] == ';' || line[1] == '<' || line[1] == '>')
		    ) {
		    /* format of line is:
		     * <ln> ::= ;<i6><i6><i6><c4><c+>
		     * <i6> ::= <s><s><s><s><s><d> | ... <d><d><d><d><d><d>
		     * <c4> ::= <C><C><C><s>
		     * <c+> ::= <a><c+> | <a>
		     * <a> is [a-zA-Z0-9.]
		     * <s> is ' '
		     * <d> is [0-9]
		     * <C> is [A-Z]
		     */
		    int d;
		    if (sscanf(line,";%6d%6d%6d",&d,&d,&d)==3 &&
			strlen(line)>23) {
			/* trim off trailing white space */
			trim_white_space(line+23);
			/*LN*/
			(void)ArrayRef(e->entries[EFLT_LN],e->Nentries[EFLT_LN]++);
			exp_get_entry(e,EFLT_LN) = (char *)strdup(line+23); line[23]='\0';
			/*LT*/
			(void)ArrayRef(e->entries[EFLT_LT],e->Nentries[EFLT_LT]++);
			/* trim off trace type white space */
			trim_white_space(line+19);
			exp_get_entry(e,EFLT_LT) = (char *)strdup(line+19);
		    }
		} else if (formatIsBap) {
		    switch (line[1]) {
		    case '<':
			for(s=&line[2];*s;s++) {
			    if(!isspace(*s) && isprint(*s))
				seq[left++] = *s;
			}
			break;
		    case '>':
			for(s=&line[2];*s;s++) {
			    if(!isspace(*s) && isprint(*s))
				seq[max_seq_size-right++] = *s;
			}
			break;
		    case ';':
			/*TG*/
#if 0
			trim_white_space(line);
			(void)ArrayRef(e->entries[EFLT_TG],e->Nentries[EFLT_TG]++);
			/* convert format from Staden format to
			 * Experiment file format
			 */
			{
			    char *cp;
			    int pos, len;
			    char type[5];

			    cp = (char *)xmalloc(strlen(line)+20);
			    if (cp == NULL)
				break;

			    sscanf(line, ";;%4s %6d %6d",
				   type, &pos, &len);
			    /*
			     * Need to add 'left' to each start position
			     * in tag. ASSUMPTION: 'left' has already been
			     * defined. Ie that the ;< lines are before
			     * any ;; lines.
			     */
			    pos += left;
			    values2tag(cp, type, pos, pos + len - 1,
				       2, &line[20]);

			    exp_get_entry(e,EFLT_TG) = cp;
			}

			if (strncmp(line+2,"IGNC",4)==0 ||
			    strncmp(line+2,"CVEC",4)==0) {
			    CS_from = atoi(&line[2+4+1]);
			} else if (strncmp(line+2,"IGNS",4)== 0 ||
				   strncmp(line+2,"SVEC",4)== 0) {
			    SR = 1;
			}
#endif
			break;

		    default:
			break;
		    }
		}
	    } else {
		/********************************************
		 * The actual sequence bit
		 *******************************************/
		formatIsBap = 0; /* turn off title line parsing stuff */
		for (s=line;*s;s++) {
		    if(!isspace(*s) && isprint(*s))
			seq[left+len++] = *s;
		}
		    
	    }
	}

	/*
	 * The right cutoff has been stashed into the end of the array
	 * Move to correct place
	 */
	for(i=(max_seq_size-(left+len))/2;i>=0;i--) {
	    char temp;
	    /* swap */
	    temp = seq[left+len+i];
	    seq[left+len+i] = seq[max_seq_size-i];
	    seq[max_seq_size-i] = temp;
	}
	/* null terminate */
	seq[left+len+right] = '\0';

	/*SQ*/
	(void)ArrayRef(e->entries[EFLT_SQ],e->Nentries[EFLT_SQ]++);
	exp_get_entry(e,EFLT_SQ) = seq;

	/*SL*/
	sprintf(line,"%d",left);
	(void)ArrayRef(e->entries[EFLT_SL],e->Nentries[EFLT_SL]++);
	exp_get_entry(e,EFLT_SL) = (char *)strdup(line);

	/*SR*/
	if (SR) {
	    sprintf(line,"%d",left+len+1);
	    (void)ArrayRef(e->entries[EFLT_SR],e->Nentries[EFLT_SR]++);
	    exp_get_entry(e,EFLT_SR) = (char *)strdup(line);
	}

	/*CS*/
	if (CS_from) {
	    if (CS_from == 1) {
		CS_to = left;
	    } else {
		CS_from = left + len + 1;
		CS_to = left + len + right;
	    }
	    sprintf(line,"%d..%d",CS_from,CS_to);
	    (void)ArrayRef(e->entries[EFLT_CS],e->Nentries[EFLT_CS]++);
	    exp_get_entry(e,EFLT_CS) = (char *)strdup(line);
	}

	/*QR*/
	if (!SR && !CS_from) {
	    sprintf(line,"%d",left+len+1);
	    (void)ArrayRef(e->entries[EFLT_QR],e->Nentries[EFLT_QR]++);
	    exp_get_entry(e,EFLT_QR) = (char *)strdup(line);
	}

#if 0
	/*TG*/
	{
	    int i;
	    /* need to add LEFT to each start position in tag */
	    for(i=0;i<e->Nentries[EFLT_TG];i++) {
		sprintf(line,"%4.4s %6d%s",
			arr(char *,e->entries[EFLT_TG],i),
			atoi(arr(char *,e->entries[EFLT_TG],i)+5)+left,
			arr(char *,e->entries[EFLT_TG],i)+11);
		xfree(arr(char *,e->entries[EFLT_TG],i));
		arr(char *,e->entries[EFLT_TG],i) = (char *)strdup(line);

	    }
	}
#endif
    }