headers/bsd: Add sys/queue.h.
[haiku.git] / src / tests / add-ons / print / ppd / test / TestScanner.cpp
blobfea56e6fb7d485ea78109a29d01197c6db1ae873
1 /*
2 * Copyright 2008, Haiku.
3 * Distributed under the terms of the MIT license.
5 * Authors:
6 * Michael Pfeiffer <laplace@users.sourceforge.net>
7 */
9 #include "CharacterClasses.h"
10 #include "Scanner.h"
12 #include <stdio.h>
14 void Print(Scanner* scanner)
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);
22 void TestScanner()
24 Scanner scanner("main.ppd");
25 if (scanner.InitCheck() != B_OK) {
26 fprintf(stderr, "Could not open file main.ppd\n");
27 return;
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;
37 Print(&scanner);
38 scanner.NextChar();
41 if (!scanner.Include("include.ppd")) {
42 fprintf(stderr, "Could not include file include.ppd\n");
43 return;
46 while (scanner.GetCurrentChar() != kEof) {
47 Print(&scanner);
48 scanner.NextChar();
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]);
61 printf("%d\n", '"');