summaryrefslogtreecommitdiffstats
path: root/mpeglib/example/yaf/yafcore/lineStack.cpp
blob: 871665ed4507da1ba7a7e4c451eee6339ef7cb8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
  a class which scans a string and converts it into commandLines
  Copyright (C) 1998  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */



#include "lineStack.h"
#include <iostream>

using namespace std;


LineStack::LineStack() {
  stack=new Buffer(1);
}


LineStack::~LineStack() {
  delete stack;
}


int LineStack::hasLine() {
  int nPos;
  nPos=stack->find('\n');
  if (nPos == -1) return false;
  return true;

}



void LineStack::nextLine(Buffer* nextLine) {
  int nPos;
  char* retPos;
  int restLen;
  char* data=stack->getData();
  int nSize=stack->getSize();

  nPos=stack->find('\n');
  if (nPos == -1) {
    nextLine->clear();
    return;
  }
  retPos=&(data[nPos]);
  (*retPos)='\0';
  nextLine->clear();
  nextLine->setData(data);
  retPos++;
  restLen=nSize+1-(nPos+1);
  if (strlen(retPos) > 0) {
    strncpy(data,retPos,restLen);
  } else{
    stack->clear();
  }
}


void LineStack::appendBottom(char* buffer) {
  int n=strlen(buffer);
  appendBottom(buffer,n);
}



void LineStack::appendBottom(char* buffer, int buflen) {

  stack->append(buffer,buflen);

}

void LineStack::appendBottom(LineStack* lStack) {
  char* data;
  int len;
  data=lStack->stack->getData();
  len=lStack->stack->len();
  appendBottom(data,len); 
}

  
  
void LineStack::print(char* name) {
  cout << "LineStack:"<<name<<endl;
  stack->print();
}