Example #1
0
static void
LoadChecklist()
{
  nLists = 0;

  free(ChecklistText[0]);
  ChecklistText[0] = NULL;

  free(ChecklistTitle[0]);
  ChecklistTitle[0] = NULL;

  TLineReader *reader = OpenDataTextFile(_T(XCSCHKLIST));
  if (reader == NULL) {
    addChecklist(_("No checklist loaded"),_("Create xcsoar-checklist.txt\n"));
    return;
  }

  TCHAR Details[MAXDETAILS];
  TCHAR Name[100];
  bool inDetails = false;
  int i;

  Details[0] = 0;
  Name[0] = 0;

  TCHAR *TempString;
  while ((TempString = reader->read()) != NULL) {
    // Look for start
    if (TempString[0] == '[') {
      if (inDetails) {
        addChecklist(Name, Details);
        Details[0] = 0;
        Name[0] = 0;
      }

      // extract name
      for (i = 1; i < MAXTITLE; i++) {
        if (TempString[i] == ']')
          break;

        Name[i - 1] = TempString[i];
      }
      Name[i - 1] = 0;

      inDetails = true;
    } else {
      // append text to details string
      _tcsncat(Details, TempString, MAXDETAILS - 2);
      _tcscat(Details, _T("\n"));
      // TODO code: check the string is not too long
    }
  }

  delete reader;

  if (inDetails) {
    addChecklist(Name, Details);
  }
}
Example #2
0
static void
LoadChecklist()
{
  nLists = 0;

  free(ChecklistText[0]);
  ChecklistText[0] = NULL;

  free(ChecklistTitle[0]);
  ChecklistTitle[0] = NULL;

  TLineReader *reader = OpenDataTextFile(_T(XCSCHKLIST));
  if (reader == NULL) {
    addChecklist(_("No checklist loaded"), _("Create xcsoar-checklist.txt"));
    return;
  }

  StaticString<MAXDETAILS> Details;
  TCHAR Name[100];
  bool inDetails = false;
  int i;

  Details.clear();
  Name[0] = 0;

  TCHAR *TempString;
  while ((TempString = reader->ReadLine()) != NULL) {
    // Look for start
    if (TempString[0] == '[') {
      if (inDetails) {
        addChecklist(Name, Details);
        Details.clear();
        Name[0] = 0;
      }

      // extract name
      for (i = 1; i < MAXTITLE; i++) {
        if (TempString[i] == ']')
          break;

        Name[i - 1] = TempString[i];
      }
      Name[i - 1] = 0;

      inDetails = true;
    } else {
      // append text to details string
      Details.append(TempString);
      Details.Append(_T('\n'));
    }
  }

  delete reader;

  if (inDetails) {
    addChecklist(Name, Details);
  }
}
Example #3
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Reads checklist from file encoded in UTF-8.
///
/// @retval true  data loaded 
/// @retval false data load error
///
static bool LoadUtfChecklist(const TCHAR* fileName) {
  Utf8File file;
  if (!file.Open(fileName, Utf8File::io_read)) {
    StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE);
    return(false);
  }

  #if TESTBENCH
  StartupStore(_T(". Loading notes <%s>%s"),fileName,NEWLINE);
  #endif

  TCHAR TempString[MAXNOTETITLE];
  TCHAR Details[MAXNOTEDETAILS+1];
  TCHAR Name[MAXNOTETITLE+1];
  bool inDetails = false;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;

  while (file.ReadLn(TempString, MAXNOTETITLE)) {
    // skip comment lines
    if (TempString[0] == _T('#'))
      continue;
    
    AddChecklistLine(TempString, Details, Name, inDetails);
  } // while
  
  if (inDetails) {
    _tcscat(Details,TEXT("\r\n"));
    addChecklist(Name, Details);
  }
 
  return(true);
} // LoadUtfChecklist 
Example #4
0
void
dlgChecklistShowModal()
{
  static unsigned int current_page = 0;
  static bool first = true;
  if (first) {
    LoadChecklist();
    if (nLists == 0)
      addChecklist(_("No checklist loaded"), _("Create xcsoar-checklist.txt"));
    first = false;
  }

  const DialogLook &look = UIGlobals::GetDialogLook();

  WidgetDialog dialog(look);

  ArrowPagerWidget widget(dialog, look.button);
  for (int i = 0; i < nLists; ++i)
    widget.Add(new LargeTextWidget(look, ChecklistText[i]));
  widget.SetCurrent(current_page);

  dialog.CreateFull(UIGlobals::GetMainWindow(), _("Checklist"), &widget);

  widget.SetPageFlippedCallback([&dialog, &widget](){
      UpdateCaption(dialog, widget.GetCurrentIndex());
    });
  UpdateCaption(dialog, widget.GetCurrentIndex());

  dialog.ShowModal();
  dialog.StealWidget();
  current_page = widget.GetCurrentIndex();
}
Example #5
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Reads checklist from file encoded in UTF-8.
///
/// @retval true  data loaded
/// @retval false data load error
///
static bool LoadUtfChecklist(const TCHAR* fileName, bool warn) {
  Utf8File file;
  if (!file.Open(fileName, Utf8File::io_read)) {
    if (warn) StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE);
    return(false);
  }

  #if TESTBENCH
  StartupStore(_T(". Loading UTF notes <%s>%s"),fileName,NEWLINE);
  #endif

  TCHAR TempString[MAXNOTETITLE];
  TCHAR Details[MAXNOTEDETAILS+1];
  TCHAR Name[MAXNOTETITLE+1];
  bool inDetails = false;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;
  bool firstline=true;

  while (file.ReadLn(TempString, MAXNOTETITLE)) {
    // skip comment lines
    if (TempString[0] == _T('#')) {
      firstline=false;
      continue;
    }

    // Skip BOMs, if existing. Just to be sure, we only check the very first line of the file.
    // UTF8 BOM: 0xef 0xbb 0xbf
    // Unicode l.e. BOM: 0xff 0xfe (not supported)
    // Unicode b.e. BOM: 0xfe 0xff (not supported)

    if (firstline && (byte)TempString[0]==0xef && (byte)TempString[1]==0xbb && (byte)TempString[2]==0xbf) {
       #ifdef TESTBENCH
       StartupStore(_T("... LoadUtfChecklist, ignoring UTF8 BOM%s\n"),NEWLINE);
       #endif
       AddChecklistLine(&TempString[3], Details, Name, inDetails);
    } else {
       if (firstline && ((unsigned)TempString[0]==0xffef || (unsigned)TempString[0]==0xfeff)) {
          #ifdef TESTBENCH
          StartupStore(_T("... LoadUtfChecklist, ignoring UNICODE BOM%s\n"),NEWLINE);
          #endif
          AddChecklistLine(&TempString[1], Details, Name, inDetails);
       } else {
          AddChecklistLine(TempString, Details, Name, inDetails);
       }
    }
    firstline=false;
  } // while

  if (inDetails) {
    _tcscat(Details,TEXT(ENDOFLINE));
    addChecklist(Name, Details);
  }

  return(true);
} // LoadUtfChecklist
Example #6
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Add a line pointed to by TempString into checklist.
static void AddChecklistLine(const TCHAR* TempString, TCHAR* Details, TCHAR* Name, bool& inDetails) {
  size_t len = _tcslen(TempString);

  // check that we are not over the limit of the note details size
  if ((_tcslen(Details) + len) > (MAXNOTEDETAILS-MAXNOTELIMITER-1)) {
    // unfortunately, yes. So we need to split the note right now.
    // And we keep the same Name also for next splitted note.
    _tcscat(Details, TEXT(NOTECONTINUED));

    if (_tcslen(Name)>0 && _tcslen(Details)>0) {
         addChecklist(Name, Details);
    }
    Details[0]= 0;
    inDetails=true;
  }

  if (TempString[0]=='[') { // Look for start
    // we found the beginning of a new note, so we may save the last one, if not empty
    if (inDetails) {
      _tcscat(Details,TEXT(ENDOFLINE));
      addChecklist(Name, Details);
      Details[0]= 0;
      Name[0]= 0;
    }

    // extract name
    size_t i;
    for (i=1; i<MAXNOTETITLE; i++) {
      if (TempString[i]==']') {
        break;
      }
      Name[i-1]= TempString[i];
    }
    Name[i-1]= 0;

    inDetails = true;

  } else {
    // append text to details string
    // we already know we have enough space
    _tcsncat(Details,TempString,MAXNOTEDETAILS-2);
    _tcscat(Details,TEXT(ENDOFLINE));
  } // not a new start line
} // AddChecklistLine
Example #7
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Reads checklist from file encoded in system code page.
///
/// @retval true  data loaded
/// @retval false data load error
///
static bool LoadAsciiChecklist(const TCHAR* fileName) {
  FILE * stream = _tfopen(fileName, _T("rt"));
  if(!stream) {
    StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE);
    return(false);
  }

  #if TESTBENCH
  StartupStore(_T(". Loading Ascii notes <%s>%s"),fileName,NEWLINE);
  #endif

  TCHAR TempString[MAXNOTEDETAILS+1];
  TCHAR Details[MAXNOTEDETAILS+1];
  TCHAR Name[MAXNOTETITLE+1];
  bool inDetails = false;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;

  charset cs = charset::unknown;
  while (ReadStringX(stream, MAXNOTETITLE, TempString, cs)) {
/*
    size_t len = _tcslen(TempString);
    if (len > 0) {
      if (TempString[len - 1] == '\r') {
        TempString[len - 1]= 0;
        len--;
      }
    }
    // On PNA we may have TWO trailing CR
    if (len > 0) {
      if (TempString[len - 1] == '\r') {
        TempString[len - 1]= 0;
      }
    }
*/

    AddChecklistLine(TempString, Details, Name, inDetails);
  } // while

  if (inDetails) {
    _tcscat(Details,TEXT(ENDOFLINE));
    addChecklist(Name, Details);
  }

  fclose(stream);

  return(true);
} // LoadAsciiChecklist
Example #8
0
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/// Reads checklist from file encoded in system code page.
///
/// @retval true  data loaded 
/// @retval false data load error
///
static bool LoadAsciiChecklist(const TCHAR* fileName) {
  HANDLE hChecklist = CreateFile(
    fileName, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  
  if( hChecklist == INVALID_HANDLE_VALUE) {
    StartupStore(_T("... Not found notes <%s>%s"),fileName,NEWLINE);
    return(false);
  }

  #if TESTBENCH
  StartupStore(_T(". Loading notes <%s>%s"),fileName,NEWLINE);
  #endif

  TCHAR TempString[MAXNOTETITLE+1];
  TCHAR Details[MAXNOTEDETAILS+1];
  TCHAR Name[MAXNOTETITLE+1];
  bool inDetails = false;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;

  while (ReadString(hChecklist, MAXNOTETITLE, TempString)) {
    size_t len = _tcslen(TempString);
    if (len > 0) {
      if (TempString[len - 1] == '\r') {
        TempString[len - 1]= 0;
        len--;
      }
    }
    // On PNA we may have TWO trailing CR
    if (len > 0) {
      if (TempString[len - 1] == '\r') {
        TempString[len - 1]= 0;
      }
    }
    
    AddChecklistLine(TempString, Details, Name, inDetails);
  } // while
  
  if (inDetails) {
    wcscat(Details,TEXT("\r\n"));
    addChecklist(Name, Details);
  }
  
  CloseHandle(hChecklist);
  
  return(true);
} // LoadAsciiChecklist 
Example #9
0
void LoadChecklist(void) {
  HANDLE hChecklist;
  nLists = 0;
  if (ChecklistText[0]) {
    free(ChecklistText[0]);
    ChecklistText[0]= NULL;
  }
  if (ChecklistTitle[0]) {
    free(ChecklistTitle[0]);
    ChecklistTitle[0]= NULL;
  }

  TCHAR filename[MAX_PATH];
  LocalPath(filename, TEXT(LKD_CONF));
  _tcscat(filename,_T("\\"));
  _tcscat(filename,_T(LKF_CHECKLIST));

  hChecklist = INVALID_HANDLE_VALUE;
  hChecklist = CreateFile(filename,
			  GENERIC_READ,0,NULL,
			  OPEN_EXISTING,
			  FILE_ATTRIBUTE_NORMAL,NULL);
  if( hChecklist == INVALID_HANDLE_VALUE)
    {
	StartupStore(_T(". No Notepad file <%s>%s"),filename,NEWLINE);
	return;
    }

  StartupStore(_T(". Found Notepad file <%s>%s"),filename,NEWLINE);

  TCHAR TempString[MAXTITLE];
  TCHAR Details[MAXDETAILS];
  TCHAR Name[100];
  BOOL inDetails = FALSE;
  int i;
//  int k=0;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;

  while(ReadString(hChecklist,MAXTITLE,TempString))
    {
      int len = _tcslen(TempString);
      if (len>0) {
	// JMW strip extra \r if it exists
	if (TempString[len-1]=='\r') {
	  TempString[len-1]= 0;
	}
      }

      if(TempString[0]=='[') { // Look for start

	if (inDetails) {
	  wcscat(Details,TEXT("\r\n"));
	  addChecklist(Name, Details);
	  Details[0]= 0;
	  Name[0]= 0;
	}

	// extract name
	for (i=1; i<MAXTITLE; i++) {
	  if (TempString[i]==']') {
	    break;
	  }
	  Name[i-1]= TempString[i];
	}
	Name[i-1]= 0;

	inDetails = TRUE;

      } else {
	// append text to details string
	wcsncat(Details,TempString,MAXDETAILS-2);
	wcscat(Details,TEXT("\r\n"));
	// TODO code: check the string is not too long
      }
    }

  if (inDetails) {
    wcscat(Details,TEXT("\r\n"));
    addChecklist(Name, Details);
  }

  CloseHandle(hChecklist);
  hChecklist = NULL;

}
Example #10
0
void LoadChecklist(void) {
  nLists = 0;
  if (ChecklistText[0]) {
    free(ChecklistText[0]);
    ChecklistText[0]= NULL;
  }
  if (ChecklistTitle[0]) {
    free(ChecklistTitle[0]);
    ChecklistTitle[0]= NULL;
  }

  TCHAR filename[MAX_PATH];
  LocalPath(filename, TEXT(XCSCHKLIST));

  FILE *file = _tfopen(filename, TEXT("rt"));
  if (file == NULL)
    {
      return;
    }
  /////
  TCHAR TempString[MAXTITLE];
  TCHAR Details[MAXDETAILS];
  TCHAR Name[100];
  BOOL inDetails = FALSE;
  int i;
//  int k=0;

  Details[0]= 0;
  Name[0]= 0;
  TempString[0]=0;

  while (ReadStringX(file, MAXTITLE, TempString))
    {
      int len = _tcslen(TempString);
      if (len>0) {
	// JMW strip extra \r if it exists
	if (TempString[len-1]=='\r') {
	  TempString[len-1]= 0;
	}
      }

      if(TempString[0]=='[') { // Look for start

	if (inDetails) {
	  _tcscat(Details,TEXT("\r\n"));
	  addChecklist(Name, Details);
	  Details[0]= 0;
	  Name[0]= 0;
	}

	// extract name
	for (i=1; i<MAXTITLE; i++) {
	  if (TempString[i]==']') {
	    break;
	  }
	  Name[i-1]= TempString[i];
	}
	Name[i-1]= 0;

	inDetails = TRUE;

      } else {
	// append text to details string
	_tcsncat(Details,TempString,MAXDETAILS-2);
	_tcscat(Details,TEXT("\r\n"));
	// TODO code: check the string is not too long
      }
    }

  if (inDetails) {
    _tcscat(Details,TEXT("\r\n"));
    addChecklist(Name, Details);
  }

  /////
  fclose(file);

}