per page, with , order by , clip by
Results of 1 - 1 of about 1 for __); (0.000 sec.)
Fixing a hole where the rain gets in (wrimod.c)
#score: 9414
@digest: 4c2bc3a8d8050cb365860663f25a9730
@id: 1523
@lang: en
@size: 2896
@type: text/html
content-type: text/html; charset=UTF-8
viewport: width=device-width, initial-scale=1
#keywords: emulate (37194), logfile (30637), linebuf (29755), shorten (29295), mode (26384), strcmp (18816), fprintf (18756), progline (15630), rplus (15117), modified (15083), inode (14536), truncexp (13442), system (10295), include (10168), cat (9020), sfreview (8724), argc (8612), argv (8401), bytes (7927), break (7884), return (7845), 6dz (7815), wri (7558), fpi (7064), fpo (6892), char (6774), enum (6766), extract (6386), stderr (6235), loglines (6024), fclose (5958), stat (5926)
/* Copyright 2014 by R. Harmsen. For a full explanation see http://rudhar.com/sfreview/truncexp/en.htm */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> enum shorten_mode_e {MV, CAT, WRI, RPLUS}; int emulate (char *mode); int main (int argc, char **argv) { FILE *fpi, *fpo; enum shorten_mode_e mode = CAT; if (argc > 1 && strcmp(argv[1], "-m") == 0) { /* Shorten by means of mv */ mode = MV; } else if (argc > 1 && strcmp(argv[1], "-c") == 0) { /* Shorten by means of cat (normal write mode) */ mode = CAT; } else if (argc > 1 && strcmp(argv[1], "-w") == 0) { /* Emulate cat, open in write mode */ mode = WRI; } else if (argc > 1 && strcmp(argv[1], "-p") == 0) { /* Write in r+ mode */ mode = RPLUS; } // system("ls -lti"); system("stat -f \"Born %SB, modified %Sm, inode %6i, %6Dz bytes: %N\" *"); /* Extract last few hundred lines of logfile, meanwhile created by loglines, which writes 600 and then some */ system("tail -400 logfile > f"); sleep(23); switch (mode) { case MV: system("mv f logfile"); break; case CAT: system("cat f > logfile"); break; case WRI: emulate("w"); break; case RPLUS: emulate("r+"); break; } // system("ls -lti"); fprintf(stdout, "\nAfter:\n"); system("stat -f \"Born %SB, modified %Sm, inode %6i, %6Dz bytes: %N\" *"); sleep(12); fprintf(stdout, "\nLater still:\n"); system("stat -f \"Born %SB, modified %Sm, inode %6i, %6Dz bytes: %N\" *"); return 0; } int emulate (char *mode) { /* Nothing just yet */ char linebuf[129]; FILE *fpi = NULL, *fpo = NULL; fpi = fopen("f", "r"); if (!fpi) { fprintf(stderr, "Error in progline %d\n", __LINE__); return 1; } fpo = fopen("logfile", mode); if (!fpo) { fprintf(stderr, "Error in progline %d\n", __LINE__); return 2; } while (fgets(linebuf, sizeof linebuf, fpi) != NULL) { fputs(linebuf, fpo); } if (fpi) fclose(fpi); if (fpo) fclose(fpo); return 0; } /* Copyright 2014 by R. Harmsen. For a full explanation see http://rudhar.com/sfreview/truncexp/en.htm */ */ ...
https://rudhar.com/sfreview/truncexp/wrimod.htm - [detail] - [similar]
PREV NEXT
Powered by Hyper Estraier 1.4.13, with 1747 documents and 81086 words.