[abcp commit] r101 - no log message

0 views
Skip to first unread message

codesite...@google.com

unread,
Apr 4, 2009, 3:48:05 AM4/4/09
to abcp-...@googlegroups.com
Author: rdentato
Date: Sat Apr 4 00:34:52 2009
New Revision: 101

Added:
trunk/examples/abcndx/
trunk/examples/abcndx/abcndx.c
trunk/examples/abcndx/makefile
trunk/test/b1.txt
trunk/test/b2.txt
Modified:
trunk/abcp.ppr
trunk/examples/abcdump/abcdump.c
trunk/src/abcp.h
trunk/src/abcpfield.pmx
trunk/src/abcpscan.pmx

Log:


Modified: trunk/abcp.ppr
==============================================================================
--- trunk/abcp.ppr (original)
+++ trunk/abcp.ppr Sat Apr 4 00:34:52 2009
@@ -17,19 +17,19 @@
[Project tree]
abcp
+abcp
- +examples
- +crdnotes
+ -examples
+ -crdnotes
examples\crdnotes\makefile
examples\crdnotes\crdnotes.c
- +crdlyr
+ -crdlyr
examples\crdlyr\crdlyr.c
examples\crdlyr\marcha.txt
- +explicit
+ -explicit
examples\explicit\explicit.c
- +nousym
+ -nousym
examples\explicit\makefile
examples\nousym\nousym.c
- +abcdump
+ -abcdump
examples\nousym\makefile.mk
examples\abcdump\abcdump.c
examples\makefile
@@ -48,7 +48,7 @@
makefile
mk.bat
README.txt
- +test
+ -test
+bytoken
test\bytoken\annotation.txt
test\bytoken\bars.txt
@@ -88,18 +88,19 @@
11=..\abcm2ps-5.9.3\features.txt
12=test\a7.txt
13=test\b7.txt
+14=doc\tech\readln.gv
[Selected Project Files]
Main=
-Selected=examples\abcdump\abcdump.c
+Selected=src\abcpscan.pmx
[src\abcpscan.pmx]
-TopLine=1
-Caret=23,10
+TopLine=1032
+Caret=1,124
[examples\abcdump\abcdump.c]
-TopLine=276
-Caret=21,319
+TopLine=262
+Caret=55,283
[src\abcp.h]
-TopLine=344
-Caret=23,385
+TopLine=353
+Caret=38,394
[src\abcpcommon.c]
TopLine=1
Caret=2,23
@@ -107,8 +108,8 @@
TopLine=319
Caret=17,333
[src\abcpfield.pmx]
-TopLine=87
-Caret=17,129
+TopLine=124
+Caret=1,132
[test\a11.txt]
TopLine=1
Caret=13,13
@@ -133,3 +134,6 @@
[test\b7.txt]
TopLine=1
Caret=1,25
+[doc\tech\readln.gv]
+TopLine=1
+Caret=1,31

Modified: trunk/examples/abcdump/abcdump.c
==============================================================================
--- trunk/examples/abcdump/abcdump.c (original)
+++ trunk/examples/abcdump/abcdump.c Sat Apr 4 00:34:52 2009
@@ -25,7 +25,7 @@
k = atoi(argv[1]+1);
argn++;
}
-
+
f = stdin;
if (argn < argc) {
f = fopen(argv[argn],"rb");
@@ -34,7 +34,7 @@
exit(1);
}
}
-
+
abctext = chsRead(abctext,f,'w');
if (f!=stdin) fclose(f);
if (abctext && *abctext) {

Added: trunk/examples/abcndx/abcndx.c
==============================================================================
--- (empty file)
+++ trunk/examples/abcndx/abcndx.c Sat Apr 4 00:34:52 2009
@@ -0,0 +1,80 @@
+/*
+** (C) by Remo Dentato (rden...@gmail.com)
+**
+** This software is distributed under the terms of the BSD license:
+** http://creativecommons.org/licenses/BSD/
+*/
+
+/* .% Overview
+==============
+
+ This is an example of use for ABCp. It extracts guitar
+chords and prints the corresponding MIDI notes.
+
+*/
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <ctype.h>
+#include "abcp.h"
+
+#define MAXTITLELEN 512
+
+char title[MAXTITLELEN];
+
+int main(int argc, char *argv[])
+{
+ abcScanner *scn;
+ abcToken tok;
+ int k;
+ int n=-1;
+ int state = S_LIMBO;
+
+ if (argc < 2) {
+ fprintf(stderr,"Usage: abcndx filename\n");
+ exit (1);
+ }
+
+ scn = abcScannerNew(file,argv[1]);
+ if (scn == NULL) {
+ fprintf(stderr,"Unable to create an ABC scanner for
file: '%s'\n",argv[1]);
+ exit (1);
+ }
+
+ *title = 0;
+ while ((tok = abcNextToken(scn)) != T_EOF) {
+ switch(tok) {
+ case T_FIELD :
+ switch (abcField(scn)) {
+ case 'T' :
+ k = abcFieldLen(scn);
+ if (k == 0) strcpy(title,"Untitled");
+ else {
+ if (k>=MAXTITLELEN) k=MAXTITLELEN;
+ strncpy(title,abcFieldStart(scn),k);
+ title[k] = '\0';
+ }
+ break;
+
+ case 'X' :
+ n = atoi(abcFieldStart(scn));
+ break;
+
+ case 'K' :
+ if (*title == '\0' && n <0) break;
+ if (*title == '\0') strcpy(title,"Untitled");
+ if (n<0) n = 0;
+ printf("%d\t%s\t%s\n",n,title,argv[1]);
+ n=-1; *title = '\0';
+ break;
+ }
+ break;
+ }
+ }
+
+ abcScannerFree(scn);
+
+ return (0);
+}

Added: trunk/examples/abcndx/makefile
==============================================================================
--- (empty file)
+++ trunk/examples/abcndx/makefile Sat Apr 4 00:34:52 2009
@@ -0,0 +1,22 @@
+#
+# (C) by Remo Dentato (rden...@gmail.com)
+#
+# This software is distributed under the terms of the BSD license:
+# http://creativecommons.org/licenses/BSD/
+# http://opensource.org/licenses/bsd-license.php
+#
+
+TOP=../../
+PROG=abcndx
+
+include $(TOP)config.mk
+
+$(PROG)$(_EXE): $(CHKLIB) $(PROG)$(_OBJ)
+ $(LN)$@ $(PROG)$(_OBJ) -labcp $(MLIB)
+
+clean:
+ $(RM) $(PROG)$(_EXE)
+ $(RM) $(PROG)$(_OBJ)
+ $(RM) gmon.out
+
+include $(TOP)targets.mk

Modified: trunk/src/abcp.h
==============================================================================
--- trunk/src/abcp.h (original)
+++ trunk/src/abcp.h Sat Apr 4 00:34:52 2009
@@ -369,7 +369,6 @@


/********* */
-/* in abcpfield.pmx */

int abcMeterBeatsNth(abcScanner *scn,int k);
int abcMeterBeats(abcScanner *scn);
@@ -383,6 +382,16 @@
int abcMeterExplicitBeatsLen(abcScanner *scn);
char *abcMeterExplicitUnitsStart(abcScanner *scn);
int abcMeterExplicitUnitsLen(abcScanner *scn);
+
+/* in abcpfield.pmx */
+
+long abcTempoDenNth(abcScanner *scn,int n);
+long abcTempoNumNth(abcScanner *scn,int n);
+int abcTempoDen(abcScanner *scn);
+int abcTempoNum(abcScanner *scn);
+int abcTempoBeats(abcScanner *scn);
+int abcTempoLen(abcScanner *scn);
+char *abcTempoStart(abcScanner *scn);


#endif

Modified: trunk/src/abcpfield.pmx
==============================================================================
--- trunk/src/abcpfield.pmx (original)
+++ trunk/src/abcpfield.pmx Sat Apr 4 00:34:52 2009
@@ -180,10 +180,26 @@
}


-int abcTempoNumNth(abcScanner *scn,int n)
+long abcTempoNumNth(abcScanner *scn,int n)
{
+ if (abcToken(scn) != T_FIELD || abcField(scn) != 'Q') return 0;
+
+ if (!abcTestFlag(scn,ABC_F_FIELDSCANNED))
+ abc_tempo(scn);
+
+ if (n < 0 || 4 <= n) return 0;
+
+ return abc_numnth[n];
}

-int abcTempoDenNth(abcScanner *scn,int n)
+long abcTempoDenNth(abcScanner *scn,int n)
{
+ if (abcToken(scn) != T_FIELD || abcField(scn) != 'Q') return 0;
+
+ if (!abcTestFlag(scn,ABC_F_FIELDSCANNED))
+ abc_tempo(scn);
+
+ if (n < 0 || 4 <= n) return 0;
+
+ return abc_dennth[n];
}

Modified: trunk/src/abcpscan.pmx
==============================================================================
--- trunk/src/abcpscan.pmx (original)
+++ trunk/src/abcpscan.pmx Sat Apr 4 00:34:52 2009
@@ -59,124 +59,6 @@
return NULL;
}

-
-static int nextline(abcScanner *scn)
-{
- char *t;
- int l = 0;;
-
- if (scn->file != NULL) {
- l = chsLen(scn->line);
- scn->line = chsReadln(scn->line,scn->file,'a');
- l = chsLen(scn->line) - l;
- }
- else {
- t = scn->pos;
- l = 1;
- while (l && *t) {
- switch pmx(t) {
- case "&n" : l = 0;
- case "&l" : break;
- default : assert(0);
- }
- }
- l = t - scn->pos;
- if (l > 0) {
- _dbgmsg("LEN: %d\n",l);
- scn->line = chsAddStrL(scn->line,scn->pos,l);
- scn->pos = t;
- }
- }
- if (l > 0) scn->lnumber++;
- return l;
-}
-
-static int chk_tocontinue(char *s)
-{
- if (*s == '\b') s++;
- while (*s && isspace(*s)) s++;
- if (*s == '%' || *s == '#') return 1;
- if (!isalpha(*s) || *s=='w' || *s=='s') return 0;
- return (s[1] == ':');
-}
-
-/* Handling line continuation is rather messy in ABC. Here are the rules
-** that have been implemented.
-**
-** - Backslash and % in quoted strings are preserved
-** - Escaped backslash and % are preserved
-** - If a line ends with "\ %..." it's transformed in "[r:...]\"
-** - If line starts with a field (X: or %%) or a comment is to be
continued
-** - In state LIMBO any lines is to be continued
-** - In any other state the \ at the end is reported as T_CONTINUE token
-**
-*/
-
-static void _getnewline(abcScanner *scn)
-{
- char *t,*q;
- int len;
- int k;
- chs_t tmp = NULL;
- int tocontinue = -1;
-
- scn->line = chsCpy(scn->line,"\b");
- scn->ln_logical = scn->lnumber+1;
-
- for (;;) {
- len = chsLen(scn->line);
- nextline(scn);
- k = chsLen(scn->line);
- if (len == k) break;
-
- if (tocontinue < 0)
- tocontinue = chk_tocontinue(scn->line);
-
- if (chsChrAt(scn->line,-1) != '\n')
- scn->line = chsAddChr(scn->line,'\n');
-
- q = scn->line + len;
- t = NULL;
- while (*q && !t) {
- switch pmx(q) {
- case "&e\\&q" : break; /* skip quoted strings */
- case "&K%" : tocontinue = 1; /* comments are always
continued */
- break;
- case "\\&K&n" :
- case "\\&K%&K(&L)&n" : /* got a ending remark */
- len = pmx(Len,1);
- if (len>0) {
- tmp = chsCpy(tmp,"[r:");
- tmp = chsAddStrL(tmp, pmx(Start,1),len);
- tmp = chsAddStr(tmp, "]");
- }
- else {
- tmp = chsCpy(tmp,"");
- }
- scn->line =
chsDel(scn->line,-pmx(Len,0),-1);
- scn->line = chsAddStr(scn->line, tmp);
- scn->line = chsAddStr(scn->line, "\f");
- t = scn->line;
- break;
- case "\\<.>" :
- case "<!\\\">" : break;
- }
- }
- if (t == NULL) break; /* didn't continue at all */
- if (scn->state == S_LIMBO) continue;
- if (!tocontinue) break;
- }
-
- if (chsLen(scn->line) < 2)
- scn->line = chsCpy(scn->line,"");
- else if (chsChrAt(scn->line,-1) != '\n')
- scn->line = chsAddChr(scn->line,'\n');
-
- scn->cur = scn->line;
- dbgmsg("line: <<%s>>\n",scn->line);
- if (tmp) chsFree(tmp);
-}
-
static int oldchar = '\0';
static int nextchar(abcScanner *scn)
{
@@ -197,7 +79,7 @@
if (c != EOF) {
scn->line = chsAddChr(scn->line,c);
}
- _dbgmsg("%c",c);
+ _dbgmsg("'%c'",c);
return c;
}

@@ -236,7 +118,7 @@
static void getnewline(abcScanner *scn)
{
int c;
- int kk;
+
scn->line = chsCpy(scn->line,"\b");
scn->ln_logical = scn->lnumber+1;

@@ -244,6 +126,7 @@
STATE(BOL) : switch((c=nextchar(scn))) {
case EOF : GOTO(EOL);
case '\t': GOTO(BOL);
+ case '"' : GOTO(STR);
case ' ' : GOTO(BOL);
case '%' : GOTO(isREM);
case '\n': GOTO(EOL);
@@ -287,6 +170,7 @@
}

scn->cur = scn->line;
+
_dbgmsg("line: <<%s>>\n",scn->line);
}

@@ -812,7 +696,7 @@
case "(&K)&N\f" : settoken(scn,T_WHITESPACE);
break;

- case "()&K(<+!\n\r\f>)(&N)\f" :
+ case "()&K(<*!\n\r\f>)(&N)\f" :
settoken(scn,T_TEXT);
break;
}
@@ -1106,9 +990,9 @@

if (scn->state == S_EOF) return T_EOF;

- if (!scn->cur || !*scn->cur)
+ if (!scn->cur || *scn->cur == '\0' || *scn->cur =='\f')
getnewline(scn);
-
+ _dbgmsg("[[%s]]\n",scn->cur);
if (scn->cur && *scn->cur) {
switch (abcStateCurrent(scn)) {
case S_LIMBO : return abc_limbo(scn);

Added: trunk/test/b1.txt
==============================================================================
--- (empty file)
+++ trunk/test/b1.txt Sat Apr 4 00:34:52 2009
@@ -0,0 +1,31 @@
+X:1001
+T:Aiken Drum
+T:Willie Wood
+T:There's a Man Came to our Town
+R:Reel
+C:Trad. Before 1820
+O:Scotland
+M:4/4
+L:1/8
+Q:1/4=140
+K:D
+"D"f2 f2 gfed|"G"B4 d3 B|"A7"A2 A2 B2 c2|"D"d6:|
+|:de|"D"f2 f2 f2 ed|"G"g2 g2 b3 g|"D"f2 a2 f2 d2|"Em"f2 e2 "A7"e2 de|
+"D"f2 f2 gfed|"G"B4 d3 B|"A7"A2 A2 B2 c2|"D"d6:|
+
+X:1002
+T:Abbots Bromley Horn Dance
+R:Jig
+C:Trad.
+O:England (Thaxted)
+M:6/8
+L:1/8
+Q:1/8=150
+K:Em
+e|"Em"B2e G2e|B2e E2G|"B7"F>GA "Em"G>AB|"B7"A>GF "Em"G2 e|
+"Em"B2e G2e|B2e E2G|"B7"F>GA "Em"G>AB|"B7"A>GF "Em"E2 e||
+"Am"c2e cde|A2c ABc|"D"FGA "Em"GFE|"D"DEF "Em"B,2g|
+"C"e2g efg|c2e cde|"D"dcB "B7"AGF|"Em"E3 E2 A||
+|:"Em"B>cB "Am"c3|"Em"B>cB "Am"e3|"Em"B>cB "B7"A>GF|"Em"G2F E2 (3F/G/A/|
+"Em"B>cB "Am"c3|"Em"B>cB "Am"e3|"Em"B>cB "B7"A>GF|"Em"E3 E3:|
+f2 f2 gfed|"G"B4 d3 B|"A7"A2 A2 B2 c2|"D"d6:|
\ No newline at end of file

Added: trunk/test/b2.txt
==============================================================================
--- (empty file)
+++ trunk/test/b2.txt Sat Apr 4 00:34:52 2009
@@ -0,0 +1,2 @@
+"c"
+d

Reply all
Reply to author
Forward
0 new messages