1 /* 2 * Copyright 2008, Haiku. 3 * Distributed under the terms of the MIT license. 4 * 5 * Authors: 6 * Michael Pfeiffer <laplace@users.sourceforge.net> 7 */ 8 9 #include "CharacterClasses.h" 10 #include "Scanner.h" 11 12 #include <stdio.h> 13 14 void Print(Scanner* scanner) 15 { 16 Position position = scanner->GetPosition(); 17 const char* filename = scanner->GetFileName(); 18 int ch = scanner->GetCurrentChar(); 19 printf("[%d, %d] (%s) %c\n", position.x, position.y, filename, ch); 20 } 21 22 void TestScanner() 23 { 24 Scanner scanner("main.ppd"); 25 if (scanner.InitCheck() != B_OK) { 26 fprintf(stderr, "Could not open file main.ppd\n"); 27 return; 28 } 29 30 scanner.NextChar(); 31 for (int i = 0; i < 10; i ++) { 32 int ch = scanner.GetCurrentChar(); 33 if (ch == kEof) { 34 fprintf(stderr, "Unexpected end of file!\n"); 35 return; 36 } 37 Print(&scanner); 38 scanner.NextChar(); 39 } 40 41 if (!scanner.Include("include.ppd")) { 42 fprintf(stderr, "Could not include file include.ppd\n"); 43 return; 44 } 45 46 while (scanner.GetCurrentChar() != kEof) { 47 Print(&scanner); 48 scanner.NextChar(); 49 } 50 51 BString string; 52 string.Append('a', 1); 53 printf("%d\n", (int)string.Length()); 54 string.Append((char)0, 1); 55 string.Append('b', 1); 56 printf("%d\n", (int)string.Length()); 57 for (int i = 0; i < string.Length(); i ++) { 58 printf("%c ", string.String()[i]); 59 } 60 61 printf("%d\n", '"'); 62 } 63