thorsson_cups 0.0.11 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/ext/cups.c +26 -36
  2. metadata +2 -2
data/ext/cups.c CHANGED
@@ -113,52 +113,42 @@ static VALUE cups_print(VALUE self)
113
113
 
114
114
  char *fname = RSTRING_PTR(file); // Filename
115
115
  char *target = RSTRING_PTR(printer); // Target printer string
116
-
117
- FILE *fp = fopen(fname,"r");
118
- // Check @filename actually exists...
119
- if( fp ) {
120
- fclose(fp);
121
-
122
- VALUE job_options = rb_iv_get(self, "@job_options");
123
-
124
- // Create an array of the keys from the job_options hash
125
- VALUE job_options_keys = rb_ary_new();
126
- rb_hash_foreach(job_options, cups_keys_i, job_options_keys);
127
116
 
128
- VALUE iter;
129
- int num_options = 0;
130
- cups_option_t *options = NULL;
117
+ VALUE job_options = rb_iv_get(self, "@job_options");
131
118
 
132
- // foreach option in the job options array
133
- while (! NIL_P(iter = rb_ary_pop(job_options_keys))) {
119
+ // Create an array of the keys from the job_options hash
120
+ VALUE job_options_keys = rb_ary_new();
121
+ rb_hash_foreach(job_options, cups_keys_i, job_options_keys);
122
+
123
+ VALUE iter;
124
+ int num_options = 0;
125
+ cups_option_t *options = NULL;
134
126
 
135
- VALUE value = rb_hash_aref(job_options, iter);
127
+ // foreach option in the job options array
128
+ while (! NIL_P(iter = rb_ary_pop(job_options_keys))) {
136
129
 
137
- // assert the key and value are strings
138
- if (NIL_P(rb_check_string_type(iter)) || NIL_P(rb_check_string_type(value))) {
139
- cupsFreeOptions(num_options, options);
140
- rb_raise(rb_eTypeError, "job options is not string => string hash");
141
- return Qfalse;
142
- }
130
+ VALUE value = rb_hash_aref(job_options, iter);
143
131
 
144
- // convert to char pointers and add to cups optoins
145
- char * iter_str = rb_string_value_ptr(&iter);
146
- char * value_str = rb_string_value_ptr(&value);
147
- cupsAddOption(iter_str, value_str, num_options++, &options);
132
+ // assert the key and value are strings
133
+ if (NIL_P(rb_check_string_type(iter)) || NIL_P(rb_check_string_type(value))) {
134
+ cupsFreeOptions(num_options, options);
135
+ rb_raise(rb_eTypeError, "job options is not string => string hash");
136
+ return Qfalse;
148
137
  }
149
138
 
150
- job_id = cupsPrintFile(target, fname, "rCUPS", num_options, options); // Do it. "rCups" should be the filename/path
139
+ // convert to char pointers and add to cups optoins
140
+ char * iter_str = rb_string_value_ptr(&iter);
141
+ char * value_str = rb_string_value_ptr(&value);
142
+ cupsAddOption(iter_str, value_str, num_options++, &options);
143
+ }
151
144
 
152
- cupsFreeOptions(num_options, options);
145
+ job_id = cupsPrintFile(target, fname, "rCUPS", num_options, options); // Do it. "rCups" should be the filename/path
153
146
 
154
- rb_iv_set(self, "@job_id", INT2NUM(job_id));
147
+ cupsFreeOptions(num_options, options);
155
148
 
156
- return Qtrue;
157
- } else {
158
- // and if it doesn't...
159
- rb_raise(rb_eRuntimeError, "Couldn't find file");
160
- return Qfalse;
161
- }
149
+ rb_iv_set(self, "@job_id", INT2NUM(job_id));
150
+
151
+ return Qtrue;
162
152
  }
163
153
 
164
154
  /*
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 11
9
- version: 0.0.11
8
+ - 12
9
+ version: 0.0.12
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ivan Turkovic