int writeanypic(PICTURE *pic, char *filename, int magic) { FILE *fp; switch (magic) { /* data is written always unswapped (same endian as processor) */ case VIS_SWMAGIC: magic = VIS_MAGIC; break; case VISA_SWMAGIC: magic = VISA_MAGIC; break; } if (filename == NULL) { filename = (char *)"stdout"; fp = stdout; } else if ((fp = fopen(filename,"wb")) == NULL ) { (void)fprintf(stderr, "%s: writeanypic: wrong output file %s\n",PROGNAME,filename); return(-1); } (void)fprintf(stderr,"\nWriting %s to disk: ",filename); printhead(pic, magic); if ((magic > 1) && (magic < 7)) /* is a portable pixel map file */ { (void)fprintf(fp,"P%c\n#Created by LVL\n",magic+48); /* ascii 2-6 */ (void)fprintf(fp,"%d %d\n%d\n", pic->x, pic->y, GMAX); } else { if (fwrite(&magic,sizeof(int),1,fp) == 0) { (void)fprintf(stderr,"writeanypic: failed to write magic\n"); return(-1); } if (fwrite(pic,HEADSZ,1,fp) == 0) { (void)fprintf(stderr,"writeanypic: failed to write header\n"); return(-1); } } /* now wrote all headers */ if ((magic == VISA_MAGIC) || (magic == PGM_ASCI_MAGIC) || (magic == PPM_ASCI_MAGIC)) write_asci(pic,0,0,pic->x,pic->y,fp); else if (fwrite(pic->data,sizeofdata(pic),1,fp) == 0) { (void)fprintf(stderr,"writeanypic: failed to write data\n"); return(-1); } fclose(fp); return(0); }
int headers(int *msgvec) { int n, mesg, flag, size; struct message *mp; size = screensize(); n = msgvec[0]; if (n != 0) screen = (n-1)/size; if (screen < 0) screen = 0; mp = &message[screen * size]; if (mp >= &message[msgCount]) mp = &message[msgCount - size]; if (mp < &message[0]) mp = &message[0]; flag = 0; mesg = mp - &message[0]; if (dot != &message[n-1]) dot = mp; for (; mp < &message[msgCount]; mp++) { mesg++; if (mp->m_flag & MDELETED) continue; if (flag++ >= size) break; printhead(mesg); } if (flag == 0) { printf("No more mail.\n"); return (1); } return (0); }
int32_t load_huffman_table(uint32_t *cpt, FILE *f, huff_table_t *ht) { printhead("%5u : nb codes : ",*cpt); uint32_t init = *cpt; uint32_t tabnb[16]; for (uint32_t i = 0; i < 16; i++) { uint8_t oct = read_byte(cpt,f); printhead("%x ",oct); tabnb[i] = oct; } printhead("\n%5u : symboles : ┌─────────────────────────┐\n",*cpt); uint8_t **tabsym = create_huffman_table(tabnb,cpt,f); create_huffman_tree(tabnb,tabsym,ht); for (uint32_t i = 0; i < 16; i++) { free(tabsym[i]); } free(tabsym); return *cpt - init; }
/* * Print out the headlines for each message * in the passed message list. */ int from(int *msgvec) { int *ip; for (ip = msgvec; *ip != 0; ip++) printhead(*ip); if (--ip >= msgvec) dot = &message[*ip - 1]; return (0); }
void printfile(FILE *fp, char *fname){ char line[MAXLINE]; int pageno = 1; int lineno = printhead(fname, pageno); while(fgets(line, MAXLINE, fp) != NULL){ if(lineno >= MAXPAGE - PAD_BOTTOM){ printfoot(pageno); lineno = printhead(fname, ++pageno); } printf("%s", line); if(line[strlen(line)-1] != '\n'){ printf("\n"); } lineno++; } while(lineno++ < MAXPAGE - PAD_BOTTOM){ printf("\n"); } printfoot(pageno); }
/* * Print out the headlines for each message * in the passed message list. */ PUBLIC int from(void *v) { int *msgvec; int *ip; msgvec = v; for (ip = msgvec; *ip != 0; ip++) printhead(*ip); if (--ip >= msgvec) dot = get_message(*ip); return 0; }
/* * Print the current active headings. * Don't change dot if invoker didn't give an argument. */ PUBLIC int headers(void *v) { int *msgvec; int n; int flag; struct message *mp; int size; msgvec = v; size = screensize(); n = msgvec[0]; if (n != 0) screen = (n - 1)/size; if (screen < 0) screen = 0; if ((mp = get_message(screen * size + 1)) == NULL) { int msgCount; msgCount = get_msgCount(); if (screen * size + 1 > msgCount) mp = get_message(msgCount - size + 1); if (mp == NULL) mp = get_message(1); } flag = 0; if (dot != get_message(n)) dot = mp; for (/*EMPTY*/; mp; mp = next_message(mp)) { if (mp->m_flag & MDELETED) continue; if (flag++ >= size) break; printhead(get_msgnum(mp)); } if (flag == 0) { (void)printf("No more mail.\n"); return 1; } return 0; }
/* * Print out the headlines for each message * in the passed message list. */ int from(void *v) { int *msgvec = v; int *ip, n; FILE *obuf = stdout; char *cp; (void)&obuf; (void)&cp; if (is_a_tty[0] && is_a_tty[1] && (cp = value("crt")) != NULL) { for (n = 0, ip = msgvec; *ip; ip++) n++; if (n > (*cp == '\0' ? screensize() : atoi(cp)) + 3) { cp = get_pager(); if (sigsetjmp(pipejmp, 1)) goto endpipe; if ((obuf = Popen(cp, "w", NULL, 1)) == NULL) { perror(cp); obuf = stdout; } else safe_signal(SIGPIPE, onpipe); } } for (ip = msgvec; *ip != 0; ip++) printhead(*ip, obuf, mb.mb_threaded); if (--ip >= msgvec) setdot(&message[*ip - 1]); endpipe: if (obuf != stdout) { safe_signal(SIGPIPE, SIG_IGN); Pclose(obuf); safe_signal(SIGPIPE, dflpipe); } return(0); }
int readhead(PICTURE *pic, FILE *fp) /* architecture independent binary reader. Reads (and prints) header into the *PICTURE structure with *data untouched */ { unsigned char firstmagic, secondmagic; char pline[132]; union { unsigned char charform[4]; int intform; } magic; int x,y,gmax; vmessage(); firstmagic = fgetc(fp); if ( firstmagic == 'P' ) { secondmagic = fgetc(fp); fgetc(fp); /* skips linefeed */ fgets(pline, 132, fp); if ( (pline[0] < 48) || (pline[0] > 57) ) { (void)fprintf(stderr,"Pixelmap Comment: %s",pline); fscanf(fp,"%d %d",&x,&y); } else sscanf(pline,"%d %d",&x,&y); fscanf(fp,"%d",&gmax); if (gmax != GMAX) { (void)fprintf(stderr,"Unexpected Pixelmap Greylevels: %d\n",gmax); return(-1); } fgetc(fp); /* skips linefeed */ switch (secondmagic) { case '2': /* call read asci ? */ magic.intform = PGM_ASCI_MAGIC; fillhead(pic,IMAGE_ID,x,y,0.f,0.f,x*y,1,"PGM ascii"); break; case '3': /* call read asci ? */ magic.intform = PPM_ASCI_MAGIC; fillhead(pic,IMAGE_ID,x,y,0.f,0.f,x*y,3,"PPM ascii"); break; case '5': /* .pgm file */ magic.intform = PGM_MAGIC; fillhead(pic,IMAGE_ID,x,y,0.f,0.f,x*y,1,"PGM"); break; case '6': /* .ppm file */ magic.intform = PPM_MAGIC; fillhead(pic,IMAGE_ID,x,y,0.f,0.f,x*y,3,"PPM"); break; case '7': /* .pam file */ magic.intform = PAM_MAGIC; fillhead(pic,IMAGE_ID,x,y,0.f,0.f,x*y,3,"PAM"); break; default: (void)fprintf(stderr, "Unexpected magic P%c: supported pixel maps are: P2,P3,P5,P6\n",secondmagic); return(-1); } } else /* .lvl format */ { magic.charform[0] = firstmagic; magic.charform[1] = fgetc(fp); magic.charform[2] = fgetc(fp); magic.charform[3] = fgetc(fp); fread(pic,HEADSZ,1,fp); switch (magic.intform) { case VIS_MAGIC: case VISA_MAGIC: break; case VIS_SWMAGIC: case VISA_SWMAGIC: swaphead(pic); break; default: (void)fprintf(stderr,"readhead: unrecognised magic int\n"); return(-1); } } strcat(pic->history,"|"); strcat(pic->history,PROGNAME); pic->magic = magic.intform; printhead(pic, pic->magic); return(0); /* success */ }
int headers(void *v) { int *msgvec = v; int g, k, n, mesg, flag = 0, lastg = 1; struct message *mp, *mq, *lastmq = NULL; int size; enum mflag fl = MNEW|MFLAGGED; size = screensize(); n = msgvec[0]; /* n == {-2, -1, 0}: called from scroll() */ if (screen < 0) screen = 0; k = screen * size; if (k >= msgCount) k = msgCount - size; if (k < 0) k = 0; if (mb.mb_threaded == 0) { g = 0; mq = &message[0]; for (mp = &message[0]; mp < &message[msgCount]; mp++) if (visible(mp)) { if (g % size == 0) mq = mp; if (mp->m_flag&fl) { lastg = g; lastmq = mq; } if (n>0 && mp==&message[n-1] || n==0 && g==k || n==-2 && g==k+size && lastmq || n<0 && g>=k && mp->m_flag&fl) break; g++; } if (lastmq && (n==-2 || n==-1 && mp==&message[msgCount])) { g = lastg; mq = lastmq; } screen = g / size; mp = mq; mesg = mp - &message[0]; if (dot != &message[n-1]) { for (mq = mp; mq < &message[msgCount]; mq++) if (visible(mq)) { setdot(mq); break; } } if (mb.mb_type == MB_IMAP) imap_getheaders(mesg+1, mesg + size); for (; mp < &message[msgCount]; mp++) { mesg++; if (!visible(mp)) continue; if (flag++ >= size) break; printhead(mesg, stdout, 0); } } else { /* threaded */ g = 0; mq = threadroot; for (mp = threadroot; mp; mp = next_in_thread(mp)) if (visible(mp) && (mp->m_collapsed <= 0 || mp == &message[n-1])) { if (g % size == 0) mq = mp; if (mp->m_flag&fl) { lastg = g; lastmq = mq; } if (n>0 && mp==&message[n-1] || n==0 && g==k || n==-2 && g==k+size && lastmq || n<0 && g>=k && mp->m_flag&fl) break; g++; } if (lastmq && (n==-2 || n==-1 && mp==&message[msgCount])) { g = lastg; mq = lastmq; } screen = g / size; mp = mq; if (dot != &message[n-1]) { for (mq = mp; mq; mq = next_in_thread(mq)) if (visible(mq) && mq->m_collapsed <= 0) { setdot(mq); break; } } while (mp) { if (visible(mp) && (mp->m_collapsed <= 0 || mp == &message[n-1])) { if (flag++ >= size) break; printhead(mp - &message[0] + 1, stdout, mb.mb_threaded); } mp = next_in_thread(mp); } } if (flag == 0) { printf(catgets(catd, CATSET, 6, "No more mail.\n")); return(1); } return(0); }
int main(int argc, char **argv) { int i; char errmsg[128]; // time stuff double simJD; // Julian day, simulated struct ln_date date; // date structure struct ln_zonedate zdate; // date structure, includes gmtoff (seconds east of UTC) int year,month,day; double hour; // location stuff struct ln_lnlat_posn observer; int got_meridian = 0; double s_meridian = 0.0; // astronomy stuff float sunPos[3]; int tsolar; int isSun = FALSE; int isSky = FALSE; int isMoon = FALSE; int isStars = FALSE; // atmosphere stuff float turbidity = 2.45; // gensky default, also near europe average double gprefl = 0.2; // deciduous forest // set defaults --------------------------------------- // set to my house in Newton Center observer.lat = 42.36; observer.lng = -71.06; // note: east longitude (use west for cli) // set the julian date to right now simJD = ln_get_julian_from_sys(); //(void) ln_get_local_date (simJD, &date); //fprintf(stdout,"# %4d-%02d-%02d %2d:%02d:%02d\n", // date.years,date.months,date.days, // date.hours,date.minutes,(int)date.seconds); // create the time string for the current date (void) ln_get_date (simJD, &date); //fprintf(stdout,"# UTC now: %4d-%02d-%02d %2d:%02d:%02d\n", // date.years,date.months,date.days, // date.hours,date.minutes,(int)date.seconds); // 14400 for 4 hours behind UTC //(void) ln_date_to_zonedate (&date, &zdate, -14400); //fprintf(stdout,"# Local time now: %4d-%02d-%02d %2d:%02d:%02d\n", // zdate.years,zdate.months,zdate.days, // zdate.hours,zdate.minutes,(int)zdate.seconds); // and use those as defaults (really only to set the year) year = date.years; month = date.months; day = date.days; hour = date.hours + date.minutes/60. + date.seconds/3600.; // parse command-line arguments ----------------------- // 1st arg is month number // 2nd arg is day // 3rd arg is 24-hour decimal hours (can add "EST" or other time zone to string!) // -a latitude (North assumed) // -o longitude (West assumed) // use code from gensky.c progname = argv[0]; if (argc < 4) userror("arg count"); month = atoi(argv[1]); if (month < 1 || month > 12) userror("bad month"); day = atoi(argv[2]); if (day < 1 || day > 31) userror("bad day"); got_meridian = cvthour(argv[3], &hour, &tsolar, &s_meridian); for (i = 4; i < argc; i++) if (argv[i][0] == '-' || argv[i][0] == '+') switch (argv[i][1]) { case 'y': year = atoi(argv[++i]); break; case 't': turbidity = atof(argv[++i]); break; case 'g': gprefl = atof(argv[++i]); break; case 'a': // keep in degrees! //observer.lat = atof(argv[++i]) * (PI/180); observer.lat = atof(argv[++i]); break; case 'o': // note negative to match gensky behavior! //observer.lng = -atof(argv[++i]) * (PI/180); observer.lng = -atof(argv[++i]); break; case 'm': if (got_meridian) { ++i; break; /* time overrides */ } // keep in degrees //s_meridian = atof(argv[++i]) * (PI/180); s_meridian = atof(argv[++i]); break; default: sprintf(errmsg, "unknown option: %s", argv[i]); userror(errmsg); } else userror("bad option"); // if no meridian, assume local time? if (!got_meridian) s_meridian = -observer.lng; // check for meridian far away from observer location if (fabs(s_meridian+observer.lng) > 45.) fprintf(stderr, "%s: warning: %.1f hours btwn. standard meridian and longitude\n", progname, (-observer.lng-s_meridian)/15.); printhead(argc, argv); //fprintf(stdout,"tsolar %d\n",tsolar); //fprintf(stdout,"got_meridian %d\n",got_meridian); //fprintf(stdout,"s_meridian %g\n",s_meridian); //fprintf(stdout,"observer.lng %g\n",observer.lng); // convert the time ----------------------------------- // change date to match input //date.years = year; //date.months = month; //date.days = day; //date.hours = floor(hour); //simJD = ln_get_julian_day(&date); //fprintf(stdout,"# jd %15.10e\n",simJD); zdate.years = year; zdate.months = month; zdate.days = day; zdate.hours = floor(hour); zdate.minutes = floor(60.*(hour-(double)(zdate.hours))); zdate.seconds = 3600.*(hour-(double)(zdate.hours)-(double)(zdate.minutes)/60.); zdate.gmtoff = 86400 - (long)(240.*s_meridian); fprintf(stdout,"# Using time: %4d-%02d-%02d %2d:%02d:%02d\n", zdate.years,zdate.months,zdate.days, zdate.hours,zdate.minutes,(int)zdate.seconds); simJD = ln_get_julian_local_date(&zdate); fprintf(stdout,"# Julian day: %15.10e\n",simJD); // write output --------------------------------------- // compute and write the sun "light" and "source" descriptions isSun = writeSun (simJD, observer, turbidity, sunPos); // always write the sky dome isSky = writeSky (turbidity, sunPos); // place the moon if it is above the horizon isMoon = writeMoon (simJD, observer); // place the three brightest planets if they are above the horizon writePlanets (simJD, observer); // if the sky is dim enough, place stars isStars = writeStars (simJD, sunPos[2], observer); (void) writeSkyStarMix (sunPos[2]); // if there is cloud geometry available, place it //writeClouds (); // create a material for the ground haze writeHaze (isSun,isSky,isMoon,isStars); // ANSI C requires main to return int return 0; }
int main(int argc, char **argv) { struct rnndb *db; int i, j; if (argc < 2) { fprintf(stderr, "Usage:\n\theadergen database-file\n"); exit(1); } rnn_init(); db = rnn_newdb(); rnn_parsefile (db, argv[1]); rnn_prepdb (db); for(i = 0; i < db->filesnum; ++i) { char *dstname = malloc(strlen(db->files[i]) + 3); char *pretty; strcpy(dstname, db->files[i]); strcat(dstname, ".h"); struct fout f = { db->files[i], fopen(dstname, "w") }; if (!f.file) { perror(dstname); exit(1); } free(dstname); pretty = strrchr(f.name, '/'); if (pretty) pretty += 1; else pretty = f.name; f.guard = strdup(pretty); for (j = 0; j < strlen(f.guard); j++) if (isalnum(f.guard[j])) f.guard[j] = toupper(f.guard[j]); else f.guard[j] = '_'; ADDARRAY(fouts, f); printhead(f, db); } for (i = 0; i < db->enumsnum; i++) { if (db->enums[i]->isinline) continue; int j; for (j = 0; j < db->enums[i]->valsnum; j++) printvalue (db->enums[i]->vals[j], 0); } for (i = 0; i < db->bitsetsnum; i++) { if (db->bitsets[i]->isinline) continue; int j; for (j = 0; j < db->bitsets[i]->bitfieldsnum; j++) printbitfield (db->bitsets[i]->bitfields[j], 0); } for (i = 0; i < db->domainsnum; i++) { if (db->domains[i]->size) printdef (db->domains[i]->fullname, "SIZE", 0, db->domains[i]->size, db->domains[i]->file); int j; for (j = 0; j < db->domains[i]->subelemsnum; j++) { printdelem(db->domains[i]->subelems[j], 0); } } for(i = 0; i < foutsnum; ++i) { fprintf (fouts[i].file, "\n#endif /* %s */\n", fouts[i].guard); } return db->estatus; }