/** * @internal Given an existing file, figure out its format and return * that format value (NC_FORMATX_XXX) in model arg. Assume any path * conversion was already performed at a higher level. * * @param path File name. * @param flags * @param use_parallel * @param parameters * @param model Pointer that gets the model to use for the dispatch table. * @param version Pointer that gets version of the file. * * @return ::NC_NOERR No error. * @author Dennis Heimbigner */ static int check_file_type(const char *path, int flags, int use_parallel, void *parameters, NCmodel* model, NCURI* uri) { char magic[NC_MAX_MAGIC_NUMBER_LEN]; int status = NC_NOERR; struct MagicFile magicinfo; memset((void*)&magicinfo,0,sizeof(magicinfo)); magicinfo.path = path; /* do not free */ magicinfo.uri = uri; /* do not free */ magicinfo.model = model; /* do not free */ magicinfo.parameters = parameters; /* do not free */ #ifdef USE_STDIO magicinfo.use_parallel = 0; #else magicinfo.use_parallel = use_parallel; #endif if((status = openmagic(&magicinfo))) goto done; /* Verify we have a large enough file */ if(magicinfo.filelen < MAGIC_NUMBER_LEN) {status = NC_ENOTNC; goto done;} if((status = readmagic(&magicinfo,0L,magic)) != NC_NOERR) { status = NC_ENOTNC; goto done; } /* Look at the magic number */ if(NC_interpret_magic_number(magic,model) == NC_NOERR && model->format != 0) { if (model->format == NC_FORMAT_NC3 && use_parallel) /* this is called from nc_open_par() and file is classic */ model->impl = NC_FORMATX_PNETCDF; goto done; /* found something */ } /* Remaining case when implementation is an HDF5 file; search forward at starting at 512 and doubling to see if we have HDF5 magic number */ { long pos = 512L; for(;;) { if((pos+MAGIC_NUMBER_LEN) > magicinfo.filelen) {status = NC_ENOTNC; goto done;} if((status = readmagic(&magicinfo,pos,magic)) != NC_NOERR) {status = NC_ENOTNC; goto done; } NC_interpret_magic_number(magic,model); if(model->impl == NC_FORMATX_NC4) break; /* double and try again */ pos = 2*pos; } } done: closemagic(&magicinfo); return check(status); }
static void readfont(CString strName) { #define MAXFIRSTLINELEN 1000 int i,row,numsread; inchr theord; int maxlen,cmtlines,ffright2left; int smush,smush2; char *fileline,magicnum[5]; CStdioFile fontfile (strName, CFile::modeRead|CFile::shareDenyNone|CFile::typeText); readmagic(fontfile,magicnum); fileline = (char*)myalloc(sizeof(char)*(MAXFIRSTLINELEN+1)); if (fontfile.ReadString(fileline,MAXFIRSTLINELEN+1)==NULL) { fileline[0] = '\0'; } if (MYSTRLEN(fileline)>0 ? fileline[MYSTRLEN(fileline)-1]!='\n' : 0) { skiptoeol(fontfile); } numsread = sscanf(fileline,"%*c%c %d %*d %d %d %d %d %d", &hardblank,&charheight,&maxlen,&smush,&cmtlines, &ffright2left,&smush2); myfree(fileline); if (strcmp(magicnum,FONTFILEMAGICNUMBER) || numsread<5) ThrowErrorException ("Not a FIGlet 2 font file"); for (i=1;i<=cmtlines;i++) { skiptoeol(fontfile); } if (numsread<6) { ffright2left = 0; } if (numsread<7) { /* if no smush2, decode smush into smush2 */ if (smush == 0) smush2 = SM_KERN; else if (smush < 0) smush2 = 0; else smush2 = (smush & 31) | SM_SMUSH; } if (charheight<1) { charheight = 1; } if (maxlen<1) { maxlen = 1; } maxlen += 100; /* Give ourselves some extra room */ if (smushoverride == SMO_NO) smushmode = smush2; else if (smushoverride == SMO_FORCE) smushmode |= smush2; if (right2left<0) { right2left = ffright2left; } if (justification<0) { justification = 2*right2left; } fileline = (char*)myalloc(sizeof(char)*(maxlen+1)); /* Allocate "missing" character */ fcharlist = (fcharnode*)myalloc(sizeof(fcharnode)); fcharlist->ord = 0; fcharlist->thechar = (char**)myalloc(sizeof(char*)*charheight); fcharlist->next = NULL; for (row=0;row<charheight;row++) { fcharlist->thechar[row] = (char*)myalloc(sizeof(char)); fcharlist->thechar[row][0] = '\0'; } for (theord=' ';theord<='~';theord++) { readfontchar(fontfile,theord,fileline,maxlen); } for (theord=0;theord<=6;theord++) { readfontchar(fontfile,deutsch[theord],fileline,maxlen); } while (fontfile.ReadString(fileline,maxlen+1)==NULL?0: sscanf(fileline,"%li",&theord)==1) { readfontchar(fontfile,theord,fileline,maxlen); } myfree(fileline); }