libgeda

s_papersizes.c

Go to the documentation of this file.
00001 /* gEDA - GPL Electronic Design Automation
00002  * libgeda - gEDA's library
00003  * Copyright (C) 1998-2010 Ales Hvezda
00004  * Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00019  */
00020 #include <config.h>
00021 
00022 #include <stdio.h>
00023 #include <sys/types.h>
00024 #ifdef HAVE_STDLIB_H
00025 #include <stdlib.h> 
00026 #endif
00027 #ifdef HAVE_STRING_H
00028 #include <string.h>
00029 #endif
00030 
00031 #include "libgeda_priv.h"
00032 
00033 #ifdef HAVE_LIBDMALLOC
00034 #include <dmalloc.h>
00035 #endif
00036 
00038 struct st_papersizes_names {
00039     char *papersize_name;
00040     int width, height;
00041 };
00042 
00044 static int papersizes_index=0;
00045 
00047 #define MAX_PAGESIZES   60
00048 
00053 static struct st_papersizes_names papersizes[MAX_PAGESIZES];
00054 
00060 int s_papersizes_add_entry(char *new_papersize, int width, int height) 
00061 {
00062   if (new_papersize == NULL) {
00063     return(-1); 
00064   }
00065 
00066   if (papersizes_index >= MAX_PAGESIZES) {
00067     return(-1); 
00068   }
00069     
00070   papersizes[papersizes_index].papersize_name = g_strdup (new_papersize);
00071 
00072   papersizes[papersizes_index].width = width;
00073   papersizes[papersizes_index].height = height;
00074 
00075   papersizes_index++;
00076   return(papersizes_index);
00077 }
00078 
00084 void s_papersizes_print()
00085 {
00086   int i;
00087 
00088   for (i = 0; i < papersizes_index; i++) {
00089     printf("%s\n", papersizes[i].papersize_name);
00090   }
00091 }
00092 
00098 int s_papersizes_uniq(char *name)
00099 {
00100   int i;
00101 
00102   for (i = 0; i < papersizes_index; i++) {
00103     if (strcmp(papersizes[i].papersize_name, name) == 0) {
00104       return(0);
00105     }
00106   }
00107 
00108   return(1);
00109 }
00110 
00116 void s_papersizes_free()
00117 {
00118   int i;
00119 
00120   for (i = 0; i < papersizes_index; i++) {
00121     g_free(papersizes[i].papersize_name);
00122   }
00123 
00124   papersizes_index=0;
00125 }
00126 
00132 void s_papersizes_init()
00133 {
00134   int i;
00135   for (i = 0; i < MAX_PAGESIZES; i++) {
00136     papersizes[i].papersize_name = NULL;    
00137   } 
00138 }
00139 
00145 char *s_papersizes_get(int counter)
00146 {
00147   if (counter < papersizes_index) {
00148     return(papersizes[counter].papersize_name);
00149   }
00150 
00151   return(NULL);
00152 }
00153 
00159 void s_papersizes_get_size(char *string, int *width, int *height) 
00160 {
00161   int i;
00162 
00163   for (i = 0; i < papersizes_index; i++) {
00164     if (strcmp(papersizes[i].papersize_name, string) == 0) {
00165       *width = papersizes[i].width;
00166       *height = papersizes[i].height;
00167       return;
00168     }
00169   }
00170 
00171   *width = 0;
00172   *height = 0;
00173 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines