/* ** For any Writing of text files */ struct TXTFILE *TXTopenW(const char *file) { /*open, and init if needed */ struct TXTFILE *TXT; size_t pathname_len; /*characters */ if (!TXTok) TXTinit(); pathname_len = strlen(file); TXT = (struct TXTFILE *) Malloc(sizeof(struct TXTFILE) + pathname_len); /*some inits */ strcpy(TXT->pathname, file); TXT->Lines = 1; /*start in line 1 */ TXT->SectionStart = 0; TXT->SectionEnd = 0; TXT->fp = fopen(file, FOPEN_RT); if (TXT->fp == NULL) { TXT->fp = fopen(file, FOPEN_WT); } else { fclose(TXT->fp); TXT->fp = fopen(file, FOPEN_AT); Warning("TW03", "%s: already exists, appending to it", fname(file)); } if (TXT->fp == NULL) ProgError("TW05", "%s: %s", fname(file), strerror(errno)); return TXT; }
struct TXTFILE *TXTopenR(const char *file, int silent) { struct TXTFILE *TXT; size_t pathname_len; /*characters */ if (!TXTok) TXTinit(); pathname_len = strlen(file); TXT = (struct TXTFILE *) Malloc(sizeof(struct TXTFILE) + pathname_len); /*some inits */ strcpy(TXT->pathname, file); TXT->Lines = 1; /*start in line 1 */ TXT->SectionStart = 0; TXT->SectionEnd = 0; TXT->fp = fopen(file, FOPEN_RT); if (TXT->fp == NULL) { if (silent) { free(TXT); return NULL; } ProgError("TR03", "%s: %s", fname(file), strerror(errno)); } return TXT; }
int main (int argc, char **argv) { Tobj co; Psrc_t src; #ifdef MTRACE extern int Mt_certify; Mt_certify = 1; #endif #ifdef STATS stime = time (NULL); #endif idlerunmode = 0; exprstr = NULL; fp = NULL; init (argv[0]); Minit (GFXprune); Ginit (); FD_SET (Gxfd, &inputfds); Eerrlevel = 1; Estackdepth = 2; Eshowbody = 1; Eshowcalls = 1; processstr (leftyoptions); argv++, argc--; processargs (argc, argv); if (setjmp (exitljbuf)) goto eop; Cinit (); IOinit (); Tinit (); Pinit (); Einit (); Sinit (); Dinit (); Iinit (); TXTinit (txtcoords); GFXinit (); #ifdef FEATURE_GMAP gmapon = TRUE, G2Linit (); #endif if (exprstr) { src.flag = CHARSRC, src.s = exprstr, src.fp = NULL; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (fp) { src.flag = FILESRC, src.s = NULL, src.fp = fp; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (endflag) goto eop; TXTupdate (); Gneedredraw = FALSE; for (;;) { if (Gneedredraw) GFXredraw (), Gneedredraw = FALSE; if (Gbuttonsdown > 0) { GFXmove (), Gprocessevents (FALSE, G_ONEEVENT); processinput (FALSE); } else { if (Mcouldgc) { if (!processinput (FALSE)) Mdogc (M_GCINCR); } if (idlerunmode) { if (!processinput (FALSE)) GFXidle (); #ifdef FEATURE_GMAP } else if (GMAPneedupdate) { processinput (FALSE); #endif } else processinput (TRUE); } #ifdef FEATURE_GMAP if (gmapon) GMAPupdate (); #endif if (Erun) TXTupdate (), Erun = FALSE; } eop: #ifdef PARANOID #ifdef FEATURE_GMAP if (gmapon) G2Lterm (); #endif GFXterm (); TXTterm (); Iterm (); Dterm (); Sterm (); Eterm (); Pterm (); Tterm (); IOterm (); Cterm (); Gterm (); Mterm (); FD_CLR (Gxfd, &inputfds); term (); #endif printusage (); return 0; }
int APIENTRY WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { Tobj co; Psrc_t src; hinstance = hInstance; hprevinstance = hPrevInstance; idlerunmode = 0; exprstr = NULL; fp = NULL; init (NULL); Ginit (); #ifndef FEATURE_MS FD_SET (Gxfd, &inputfds); #endif Eerrlevel = 1; Estackdepth = 2; Eshowbody = 1; Eshowcalls = 1; processstr (leftyoptions); __argv++, __argc--; processargs (__argc, __argv); if (setjmp (exitljbuf)) goto eop; Cinit (); IOinit (); Minit (GFXprune); Tinit (); Pinit (); Einit (); Sinit (); Dinit (); Iinit (); TXTinit (txtcoords); GFXinit (); if (exprstr) { src.flag = CHARSRC, src.s = exprstr, src.fp = NULL; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (fp) { src.flag = FILESRC, src.s = NULL, src.fp = fp; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (endflag) goto eop; TXTupdate (); Gneedredraw = FALSE; for (;;) { if (Gneedredraw) GFXredraw (), Gneedredraw = FALSE; if (Gbuttonsdown > 0) GFXmove (), Gprocessevents (FALSE, G_ONEEVENT); else { if (Mcouldgc) { if (!processinput (FALSE)) Mdogc (M_GCINCR); } else if (idlerunmode) { if (!processinput (FALSE)) GFXidle (); } else processinput (TRUE); } if (Erun) TXTupdate (), Erun = FALSE; } eop: #ifdef PARANOID GFXterm (); TXTterm (); Iterm (); Dterm (); Sterm (); Eterm (); Pterm (); Tterm (); Mterm (); IOterm (); Cterm (); Gterm (); term (); #endif printusage (); exit (0); }