#!/p/kd/fdc/bin/wermit + # # Updates the family history index chapter list with # current page counts and dates for each chapter. # Does nothing if index is newer than all chapters. # Putting anything (e.g. 'x') as command-line argument # forces the script to update the index anyway. # # fdc 29 March 2022 # # Chapter list (order doesn't matter). # This illustrates how to initialize an array with a lot of # members without having to use line-continuation syntax. # .chapters = { vivian.html dadchapter.html lenore.html portugal.html unclepete.html dennis.html chesterbrook.html arlington.html frankfurt.html cia.html uva.html army.html afterarmy.html newyorkcity.html columbia.html thescotts.html pam.html } # Populate the array - break characters are comma and space # void \fsplit(\m(chapters),&a,\44\32) def error exit 1 "Oops - unexpected table format, line \m(n): \m(line)" cd ~/public_html/family/ if fail exit .n := \fdim(&a) # Number of chapters .idate := \fdate(index.html) # index.html date echo echo Array size: \&a[0] / \m(n); Index date: \m(idate) echo if def \%1 forward START # If any args skip the following check .max = -1 # Check if any chapters have changed for i 1 n 1 { .tag = .pname := \&a[i] .pdate := \fdate(\m(pname)) .\%9 := \fcmpdates(\m(pdate),\m(idate)) if > \%9 \m(max) .max := \%9 if > \%9 0 .tag = " - NEWER" echo "\flpad(\m(i),2). \frpad(\m(pname),20) \m(pdate) \m(tag)" } show mac max if < \m(max) 1 exit 0 No updates since \m(pdate). :START fopen /read \%c index.html # Source file if fail exit fopen /write \%o newindex.html # Destination file if fail exit copy /preserve index.html index-backup.html # Backup file if fail exit 1 "FATAL: Backup failed" .datedone = 0 # index.html "last update" line .state = 0 # For state machine .n = 0 # HTML file line number while true { # Loop through all the file lines if not \m(datedone) .prev := \m(line) fread /line /trim \%c line if fail break incr n # Line counter if \findex(BEGIN:LIST,\m(line)) { # Look for chapter table markers echo ENTERING CHAPTERS TABLE .state = 1 .row = 0 fwrite /line \%o \m(line) continue } else if \findex(END:LIST,\m(line)) { echo EXITING CHAPTERS TABLE .state = 0 fwrite /line \%o \m(line) continue } switch \m(state) { # Handle file line according to state :0 if not \m(datedone) { # Update the "Last update" date if equ "\m(prev)" "Most recent update:" { .prev = .line := \fcvtdate(,1) .datedone = 1 } } fwrite /line \%o \m(line) continue :1 # In chapters table if not def line { # Blank line fwrite /line \%o \m(line) # Just copy it continue } switch \m(row) { # Table entry :0 # Row 0 =