/* Reads arguments from CLI or Workbench, and loads the specified puzzle. Martin J. Round January 1990 */ char line[MAXLINE]; extern struct WBStartup *WBenchMsg; extern void message (UBYTE *); extern void print (char *); extern struct Screen *ReadILBM(BPTR); extern int runningfromcli; extern struct IntuiText instrtext[6]; extern int sqrsacross,sqrsdown; extern unsigned char start [MAXACROSS] [MAXDOWN]; extern unsigned char goal [MAXACROSS] [MAXDOWN]; extern int topleftx,toplefty; extern int sqrwidth,sqrheight; extern int slide; extern int scorex,scorey,scoreapen,scorebpen; int readline(BPTR fp, char *p, int max) /* returns # chars. -1 = fail */ { int i = 0; char c; --max; if (Read(fp,&c,1) <=0) return (-1); while ((c != '\n') && (i < max)) { *p++ = c; i++; if (Read(fp,&c,1) <=0) return (-1); } *p = 0; return(i); } int value(char *p) { return (atoi(strtok(stpblk(p)," ;"))); } int readfi(BPTR fp) /* 1 = not a puzz, 2 = wrong ver. 3 = bad */ { int i,j; char *p; if ((i = readline(fp,line,MAXLINE)) < 8) return (1); if (strncmp(line,"PUZZ ",5)) return (1); if (strncmp(line,"PUZZ 1.0",8)) return (2); for (i=0; i<6; i++) { if (readline(fp,line,MAXLINE) < 0) return(3); strncpy((instrtext[i]).IText,line,26); } if (readline(fp,line,MAXLINE) < 0) return(3); sqrsacross = value(line); if (readline(fp,line,MAXLINE) < 0) return(3); sqrsdown = value(line); for (j=0; jsm_NumArgs < 2))) { message ("You must click on a puzzle icon - try '15.puzzle'."); return(NULL); } if (runningfromcli) { if ((fp=Open(argv[1],MODE_OLDFILE))==NULL) { sprintf(line,"Can't open file: %s\n",argv[1]); print(line); return(NULL); } else { screen = readfile(fp,argv[1]); } } else { /* running from Workbench */ olddir = CurrentDir (WBenchMsg->sm_ArgList[1].wa_Lock); if ( (fp = Open(WBenchMsg->sm_ArgList[1].wa_Name,MODE_OLDFILE)) == NULL ) { sprintf ( line, "Can't open file: %s", WBenchMsg->sm_ArgList[1].wa_Name ); message(line); if (olddir) CurrentDir(olddir); return(NULL); } else { screen = readfile(fp,WBenchMsg->sm_ArgList[1].wa_Name); } if (olddir) CurrentDir(olddir); } return (screen); }