Esempio n. 1
0
int WriteCodePage(
    PCODEPAGE pCP)
{
    char pszFile[FILE_NAME_LEN];       // file name storage
    FILE *pOutputFile;                 // ptr to output file


    //
    //  Make sure all tables are present.
    //
    if (!((pCP->WriteFlags & F_CPINFO) &&
          (pCP->WriteFlags & F_MB) &&
          (pCP->WriteFlags & F_WC)))
    {
        printf("Write Error: All tables must be present -\n");
        printf("             CPInfo, MultiByte, and WideChar Translation Tables.\n");
        return (1);
    }

    //
    //  Get the name of the output file.
    //
    memset(pszFile, 0, FILE_NAME_LEN * sizeof(char));
    strcpy(pszFile, CP_PREFIX);
    strcat(pszFile, pCP->pszName);
    strcat(pszFile, DATA_FILE_SUFFIX);

    //
    //  Make sure output file can be opened for writing.
    //
    if ((pOutputFile = fopen(pszFile, "w+b")) == 0)
    {
        printf("Error opening output file %s.\n", pszFile);
        return (1);
    }

    if (Verbose)
        printf("\n\nWriting output file %s...\n", pszFile);

    //
    //  Write the CPINFO.
    //
    if (WriteCPInfo(pCP, pOutputFile))
    {
        fclose(pOutputFile);
        return (1);
    }


    //
    //  Write MB Table, Glyph Table (if any) and DBCS Table (if any) to
    //  output file.
    //
    if (WriteMB(pCP, pOutputFile))
    {
        fclose(pOutputFile);
        return (1);
    }

    //
    //  Free MB table structures.
    //
    FreeMB(pCP);


    //
    //  Write WC Table to output file.
    //
    if (WriteWC( pCP,
                 (pCP->WriteFlags & F_DBCS),
                 pOutputFile ))
    {
        fclose(pOutputFile);
        return (1);
    }

    //
    //  Free WC table structures.
    //
    free(pCP->pWC);


    //
    //  Close the output file.
    //
    fclose(pOutputFile);

    //
    //  Return success.
    //
    printf("\nSuccessfully wrote output file %s\n", pszFile);
    return (0);
}
Esempio n. 2
0
// calculates which video dir to use
bool cVideoDirectory::GetPreferedVideoDir(void)
{
  cVideoDirectory d;
  int nDirs = 1,
  vidUse = Setup.nVidPrefer;
  int i, top, topFree, x;

  if (name == NULL)
     return(false);

  // count available video dirs
  while (d.Next() == true)
        nDirs++;

  if (vidUse > nDirs)
     vidUse = nDirs;

  // check for prefered video dir
  for (i = 0, top = -1, topFree = 0; i < vidUse; i++) {
      if (IsVidDirOK(i, &x) == true) {
         if (top == -1) {
            // nothing set yet, use first 'ok' dir
            top = i;
            topFree = x;
            }
         else {
            // check if we got a higher priority
            if (Setup.VidPreferPrio[ i ] >= Setup.VidPreferPrio[ top ]) {
               top = i;
               topFree = x;
               }
            // check if we got same priority but more space
            else if (Setup.VidPreferPrio[ i ] == Setup.VidPreferPrio[ top ] && x >= topFree) {
               top = i;
               topFree = x;
               }
            }
         }
      }

  if (top == -1) {
     isyslog("VidPrefer: no prefered video directory could be determined!");

     // something went wrong here...
     // let VDR determine the video directory
     int MaxFree = FreeMB();

     while (Next()) {
           int Free = FreeDiskSpaceMB(Name());

           if (Free > MaxFree) {
              Store();
              MaxFree = Free;
              }
           }
     }
  else {
     isyslog("VidPrefer: prefered video directory '%d' set.", top);
     if (stored != NULL)
        free(stored);
     stored = GetVidPath(top);
     }

  return true;
}