Skip to content

Commit

Permalink
fix RS='\0' and support fixed length record like RS=42
Browse files Browse the repository at this point in the history
  • Loading branch information
noyesno committed Mar 29, 2021
1 parent 8569b0a commit f3fda02
Show file tree
Hide file tree
Showing 23 changed files with 5,691 additions and 48 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,11 @@ _*
*.o
*.so
*.a
lib/libawka.h
awka/awka
/config.*
test/xx
test/x.c
lib/Makefile
config.cache
config.log
18 changes: 11 additions & 7 deletions awka/awka.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
#include "awka_exe.h"
#include "mem.h"

#define strdup_cat(s, suffix) strcat(strcpy(malloc(strlen(s)+strlen(suffix))+1, s), suffix)
#define strdup_cat(s, suffix) strcat(strcpy(malloc(strlen(s)+strlen(suffix)+1), s), suffix)

char ** _arraylist = NULL;
int _array_no = 0, _array_allc = 0;
Expand Down Expand Up @@ -149,10 +149,18 @@ isarray(char *var)
-----------------------------------------------------------------------------
*/

static char* tmpfile_prefix(const char *pattern){
char tmp_file[512];
strcpy(tmp_file, pattern);
int fd = mkstemp(tmp_file);
char *file_path = strdup_cat(tmp_file, "");
close(fd);
return file_path;
}

static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **outfile){
char *outfile_prefix = NULL;
char *outfile_suffix;
char tmp_file[512] = "./awka-XXXXXX.c";

#if defined(__CYGWIN32__) || defined(__DJGPP__)
outfile_suffix = ".exe";
Expand All @@ -161,10 +169,7 @@ static int awka_output_file(int awka_tmp, char *uoutfile, char **c_file, char **
#endif

if (awka_tmp) {
strcat(tmp_file, "./awka-XXXXXX");
int fd = mkstemp(tmp_file);
outfile_prefix = strdup_cat(tmp_file, "");
close(fd);
outfile_prefix = tmpfile_prefix("./awka-XXXXXX");
} if (!uoutfile) {
outfile_prefix = strdup_cat("./awka-app", "");
} else {
Expand Down Expand Up @@ -305,7 +310,6 @@ int main(int argc, char *argv[])
return -1;
}
}

translate(); //% -- transtate Awk script to C code
fclose(outfp);
}
Expand Down
1 change: 1 addition & 0 deletions awka/awka.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include <stdio.h>
#include <string.h>
#include "types.h"
#include "../lib/debug.h"

#ifndef TRUE
# define TRUE 1
Expand Down
7 changes: 6 additions & 1 deletion awka/da.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ set_bslash()
bslash['r'] |= 2;
bslash['t'] |= 2;
bslash['n'] |= 2;

bslash['0'] |= 2;

/* bslash['"'] |= 2; */
/* bslash['\\'] |= 2; */

Expand Down Expand Up @@ -214,7 +217,7 @@ fixbackslashes(char *str, int which)
else if (*q == '\\')
p++;
}
else if (*p == '\n')
else if (*p == '\n') /* unescape '\n' */
{
q = p+1;
while (*(q++))
Expand Down Expand Up @@ -451,7 +454,9 @@ awka_insertop(int op, char *cval, char *carg, int minst, char *file, int line)

if (val && op == _PUSHS)
{
AWKA_DEBUG("1 progcode[prog_no].val=\"%s\" %ld\n", progcode[prog_no].val, strlen(progcode[prog_no].val));
progcode[prog_no].val = fixbackslashes(progcode[prog_no].val, op);
AWKA_DEBUG("2 progcode[prog_no].val=\"%s\" %ld\n", progcode[prog_no].val, strlen(progcode[prog_no].val));
/* double_backslashes(progcode[prog_no].val); */
}

Expand Down
15 changes: 12 additions & 3 deletions awka/scan.c
Original file line number Diff line number Diff line change
Expand Up @@ -1050,8 +1050,14 @@ rm_escape(s)
else if (isoctal(*p))
{
t = p ;
*q++ = octal(&t) ;
p = t ;
int c = octal(&t) ;
if( c==0 && (t-p)==1 ){
*q++ = *(p-1) ;
*q++ = *p++ ;
} else {
*q++ = c;
p = t ;
}
}
else if (*p == 'x' && ishex(*(unsigned char *) (p + 1)))
{
Expand Down Expand Up @@ -1118,7 +1124,10 @@ collect_string()
}

out:
yylval.ptr = (PTR) new_STRING( e_flag ? rm_escape(string_buff) : string_buff) ;
AWKA_DEBUG("token string 1 = \"%s\"\n", string_buff);
unsigned char *s = e_flag ? rm_escape(string_buff) : string_buff ;
AWKA_DEBUG("token string 2 = \"%s\"\n", s);
yylval.ptr = (PTR) new_STRING(s);
return STRING_ ;
}

Expand Down
27 changes: 24 additions & 3 deletions awka/translate.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ int func_no = 0;
int which_side = _a_RHS;
int max_base_gc = 1, max_fn_gc = 1, cur_base_gc = 1, cur_fn_gc = 1;

static int getstringsize(const char *p){
int n=0;
char c;
while(c = *p++){
if (c=='\\' && *p && (1 || *p=='0' || *p=='n' || *p=='r' || *p=='t' || *p=='\"' || *p=='\\')){
p++;
n++;
}else{
n++;
}
}
return n;
}

char *
codeptr(int inst, int len)
{
Expand Down Expand Up @@ -1310,7 +1324,12 @@ awka_assign(int inst, int *earliest, char *context)
if (0 && !strcmp(r2, "a_bivar[a_FS]")){
sprintf(ret, "awka_NFget(); awka_strcpy(%s, %s) /* 1 */", r2, getstringvalue(p));
} else {
sprintf(ret, "awka_strcpy(%s, %s) /* 1 */", r2, getstringvalue(p));
const char *string_value = getstringvalue(p);
if(string_value[0]=='\"'){
sprintf(ret, "awka_strncpy(%s, %s, %d) /* 1 */", r2, string_value, getstringsize(string_value)-2);
}else{
sprintf(ret, "awka_strcpy(%s, %s) /* 1 */", r2, string_value);
}
}
/* sprintf(ret, "awka_strcpy(%s, %s->ptr)", r2, p); */
setvaltype(r2, _VALTYPE_STR);
Expand Down Expand Up @@ -4590,8 +4609,10 @@ translate()
for (i=0; i<litd_used; i++)
fprintf(outfp," awka_varinit(_litd%d_awka); awka_setd(_litd%d_awka) = %s;\n",i,i,litd_val[i]);

for (i=0; i<lits_used; i++)
fprintf(outfp," awka_varinit(_lits%d_awka); awka_strcpy(_lits%d_awka, \"%s\");\n",i,i,lits_val[i]);
for (i=0; i<lits_used; i++){
const char *string_value = lits_val[i];
fprintf(outfp," awka_varinit(_lits%d_awka); awka_strncpy(_lits%d_awka, \"%s\", %d);\n",i, i, string_value, getstringsize(string_value));
}

for (i=0; i<litr_used; i++)
fprintf(outfp," awka_varinit(_litr%d_awka); awka_strcpy(_litr%d_awka, \"%s\"); awka_getre(_litr%d_awka);\n",i,i,litr_val[i],i);
Expand Down
145 changes: 145 additions & 0 deletions docs/markdeep-slides.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/* Request lanscape from the printer/browser */
@page {
size: landscape;
margin-bottom: 100px;
}

.md div.title {
margin-top: 250px;
margin-bottom: 40px;
font-size: 50px;
font-weight: bold;
counter-increment: page;
}

.md div.subtitle {
font-size: 30px;
}

.md hr {
page-break-before: always;
}

body#md {
width: 900px;
max-width: 100%;
font-size: 25px;
padding: 40px;
counter-reset: page;
--accent-color: #F61;
}

/* Disable section numbering */
.md h1:before {content: ""}
.md h2:before {content: ""}

.md svg.diagram {
zoom: 150%;
}

/* Sections become presentation sections */
.md h1, .md .nonumberh1 {
page-break-before: always;
width: 1100px;
text-align: center;
margin-top: 20px;
margin-bottom: 20px;
padding-top: 300px;
padding-bottom: 20px;
border: none;
color: var(--accent-color);
margin-left: -100px;
margin-right:-100px;
font-size: 50px;
counter-increment: page;
}

/* Subsections become slides */
.md h2, .md .nonumberh2 {
page-break-before: always;
width: 1100px;
text-align: center;
background: var(--accent-color);
color: #FFF;
margin-top: 100px;
margin-bottom: 50px;
padding-top: 20px;
padding-bottom: 20px;
border: none;
margin-left: -100px;
margin-right:-100px;
font-size: 34px;
counter-increment: page;
}

@media print{
footer {
position: fixed;
bottom: 0;
right: 0;
color: #AAA;
font-size: 50%;
}
}

@media screen {
footer { display: none }

.md h1, .md .nonumberh1 {
/* Show slide divisions */
border-top: 1px solid black;
}
}

/* Hide HR in printing */
@media print {
.md hr {
visibility: hidden;
}
}

.md hr {
counter-increment: page;
}

.md code {
font-size: 100%;
}

.md pre.listing {
font-size: 80%;
border: 1px solid #CCC;
}

.md strong, .md b {
color: var(--accent-color);
}

.md table {
font-size: 100%;
background-color: #eee;
}

.md table.table td {
border: none;
}

.md table.table th {
background-color: black;
color: white;
border: none;
font-family: Verdana,Helvetica,Arial,sans-serif;
}

.md table.table th + th {
border-left: 3px solid white;
}

.md table.table td + td {
border-left: 3px solid white;
}

.md table.table tr:nth-child(n) {
background-color: none;
}

Loading

0 comments on commit f3fda02

Please sign in to comment.