Skip to content

Instantly share code, notes, and snippets.

@inao
Created June 18, 2018 04:20
Show Gist options
  • Save inao/d22de6b0a10202a7d2b4aa1de33c1b28 to your computer and use it in GitHub Desktop.
Save inao/d22de6b0a10202a7d2b4aa1de33c1b28 to your computer and use it in GitHub Desktop.
#!/usr/bin/awk -f
######################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015 AOYAMA Koji
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
######################################################################################
BEGIN{
TITLEHIGHT=18;
PAGEWITH=69
if ( 0 < index(LANG=ENVIRON["LANG"],"UTF-8") ) {
PAGEWITH=PAGEWITH/3;
}
PAGEHIGHT=84;
FIGUREHIGHT=12;
w=0;
h=0;
}
{
printf("(%d,%d)%s",h,w,$0);
l=$0;
if ( substr($0,0,4) == " " ) {
h=h+1;
w=0;
l="";
printf( ":4spaces" );
}
if ( substr($0,0,1) == "-" ) {
h=h+1;
w=0;
l="";
printf( ":listitem" );
}
if ( substr($0,0,1) == "*" ) {
h=h+1;
w=0;
l="";
printf( ":listitem" );
}
if ( $0 == "" ) {
if ( 0 < w ) {
h=h+1;
printf( ":nullline" );
}
w=0;
l="";
}
if ( substr($0,0,2) == "![" ) {
h=h+FIGUREHIGHT;
w=0;
l="";
printf( ":figure" );
}
if ( substr($0,0,1) == "#" ) {
h=h+3;
w=0;
l="";
printf( ":section1" );
}
if ( substr($0,0,2) == "##" ) {
h=h-1;
w=0;
l="";
printf( ":section2" );
}
w=w+length(l);
while ( PAGEWITH < w ) {
h=h+1;
w=w-PAGEWITH;
printf(":pagewith%d",w+PAGEWITH);
}
printf("->(%d,%d)\n",h,w);
}
END{
printf("----- RESULT -----\nline=%d, page=%4.2f\n", h, (h+TITLEHIGHT)/PAGEHIGHT);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment